adding possibilities to connect directly with command-line options, adding console entry for the client server manager'
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/networking@13144 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
bd3ee05f10
commit
60e4a2bb5e
@ -487,13 +487,15 @@ namespace UserConfigParams
|
||||
// not saved to file
|
||||
|
||||
// ---- Networking
|
||||
PARAM_PREFIX StringUserConfigParam m_server_address
|
||||
PARAM_DEFAULT( StringUserConfigParam("localhost", "server_adress",
|
||||
"Information about last server used") );
|
||||
PARAM_PREFIX IntUserConfigParam m_server_port
|
||||
PARAM_DEFAULT( IntUserConfigParam(2305, "server_port",
|
||||
"Information about last server used") );
|
||||
|
||||
PARAM_DEFAULT( IntUserConfigParam(7321, "server_port",
|
||||
"Information about the port to listen on.") );
|
||||
|
||||
PARAM_PREFIX IntUserConfigParam m_server_max_players
|
||||
PARAM_DEFAULT( IntUserConfigParam(16, "server_max_players",
|
||||
"Maximum number of players on the server.") );
|
||||
|
||||
|
||||
// ---- Graphic Quality
|
||||
PARAM_PREFIX GroupUserConfigParam m_graphics_quality
|
||||
PARAM_DEFAULT( GroupUserConfigParam("GFX",
|
||||
|
28
src/main.cpp
28
src/main.cpp
@ -608,6 +608,9 @@ int handleCmdLine(int argc, char **argv)
|
||||
{
|
||||
int n;
|
||||
char s[1024];
|
||||
|
||||
bool try_login = false;
|
||||
irr::core::stringw login, password;
|
||||
|
||||
for(int i=1; i<argc; i++)
|
||||
{
|
||||
@ -685,9 +688,8 @@ int handleCmdLine(int argc, char **argv)
|
||||
{
|
||||
AIBaseController::enableDebug();
|
||||
}
|
||||
else if(sscanf(argv[i], "--server=%d",&n)==1)
|
||||
else if(sscanf(argv[i], "--port=%d",&n))
|
||||
{
|
||||
NetworkManager::getInstance<ServerNetworkManager>(); //create the server
|
||||
UserConfigParams::m_server_port = n;
|
||||
}
|
||||
else if( !strcmp(argv[i], "--server") )
|
||||
@ -695,9 +697,18 @@ int handleCmdLine(int argc, char **argv)
|
||||
NetworkManager::getInstance<ServerNetworkManager>();
|
||||
Log::info("main", "Creating a server network manager.");
|
||||
}
|
||||
else if( sscanf(argv[i], "--port=%d", &n) )
|
||||
else if( sscanf(argv[i], "--max-players=%d", &n) )
|
||||
{
|
||||
UserConfigParams::m_server_port=n;
|
||||
UserConfigParams::m_server_max_players=n;
|
||||
}
|
||||
else if( sscanf(argv[i], "--login=%1023s", s) )
|
||||
{
|
||||
login = s;
|
||||
try_login = true;
|
||||
}
|
||||
else if( sscanf(argv[i], "--password=%1023s", s) )
|
||||
{
|
||||
password = s;
|
||||
}
|
||||
else if ( sscanf(argv[i], "--gfx=%d", &n) )
|
||||
{
|
||||
@ -1095,6 +1106,12 @@ int handleCmdLine(int argc, char **argv)
|
||||
UserConfigParams::m_sfx = false; // Disable sound effects
|
||||
UserConfigParams::m_music = false;// and music when profiling
|
||||
}
|
||||
|
||||
if (try_login)
|
||||
{
|
||||
irr::core::stringw s;
|
||||
CurrentOnlineUser::get()->signIn(login, password, s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
} // handleCmdLine
|
||||
@ -1216,6 +1233,7 @@ void cleanSuperTuxKart()
|
||||
if(INetworkHttp::get())
|
||||
INetworkHttp::get()->stopNetworkThread();
|
||||
//delete in reverse order of what they were created in.
|
||||
//delete in reverse order of what they were created in.
|
||||
//see InitTuxkart()
|
||||
Referee::cleanup();
|
||||
if(ReplayPlay::get()) ReplayPlay::destroy();
|
||||
@ -1373,8 +1391,6 @@ int main(int argc, char *argv[] )
|
||||
NetworkManager::getInstance()->run();
|
||||
if (NetworkManager::getInstance()->isServer())
|
||||
{
|
||||
irr::core::stringw str;
|
||||
CurrentOnlineUser::get()->signIn("server", "serverpass", str);
|
||||
ProtocolManager::getInstance()->requestStart(new ServerLobbyRoomProtocol());
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,37 @@
|
||||
|
||||
#include "utils/log.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
void* waitInput(void* data)
|
||||
{
|
||||
std::string str = "";
|
||||
bool stop = false;
|
||||
while(!stop)
|
||||
{
|
||||
getline(std::cin, str);
|
||||
if (str == "connect=")
|
||||
{
|
||||
int id = 0;
|
||||
std::cin >> id;
|
||||
ProtocolManager::getInstance()->requestStart(new ConnectToServer(id));
|
||||
}
|
||||
if (str == "quit")
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ClientNetworkManager::ClientNetworkManager()
|
||||
{
|
||||
m_thread_keyboard = NULL;
|
||||
}
|
||||
|
||||
ClientNetworkManager::~ClientNetworkManager()
|
||||
@ -45,6 +74,10 @@ void ClientNetworkManager::run()
|
||||
m_localhost->setupClient(1, 2, 0, 0);
|
||||
m_localhost->startListening();
|
||||
|
||||
// listen keyboard console input
|
||||
m_thread_keyboard = (pthread_t*)(malloc(sizeof(pthread_t)));
|
||||
pthread_create(m_thread_keyboard, NULL, waitInput, NULL);
|
||||
|
||||
NetworkManager::run();
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,8 @@ class ClientNetworkManager : public NetworkManager
|
||||
protected:
|
||||
ClientNetworkManager();
|
||||
virtual ~ClientNetworkManager();
|
||||
|
||||
pthread_t* m_thread_keyboard;
|
||||
};
|
||||
|
||||
#endif // CLIENT_NETWORK_MANAGER_HPP
|
||||
|
@ -41,7 +41,7 @@ Event::Event(ENetEvent* event)
|
||||
}
|
||||
if (type == EVENT_TYPE_MESSAGE)
|
||||
{
|
||||
data = std::string((char*)(event->packet->data), event->packet->dataLength-1);;
|
||||
data = std::string((char*)(event->packet->data), event->packet->dataLength-1);
|
||||
}
|
||||
else if (event->data)
|
||||
{
|
||||
|
@ -94,6 +94,12 @@ void ConnectToServer::update()
|
||||
if (m_listener->getProtocolState(m_current_protocol_id)
|
||||
== PROTOCOL_STATE_TERMINATED) // now we have the server's address
|
||||
{
|
||||
if (m_server_address.ip == 0 || m_server_address.port == 0)
|
||||
{
|
||||
m_state = HIDING_ADDRESS;
|
||||
m_current_protocol_id = m_listener->requestStart(new HidePublicAddress());
|
||||
return;
|
||||
}
|
||||
m_state = PEER_ADDRESS_KNOWN;
|
||||
m_current_protocol_id = m_listener->requestStart(new ShowPublicAddress());
|
||||
}
|
||||
|
@ -71,7 +71,6 @@ void ServerLobbyRoomProtocol::setup()
|
||||
void ClientLobbyRoomProtocol::notifyEvent(Event* event)
|
||||
{
|
||||
assert(m_setup); // assert that the setup exists
|
||||
Log::setLogLevel(1);
|
||||
if (event->type == EVENT_TYPE_MESSAGE)
|
||||
{
|
||||
assert(event->data.size()); // assert that data isn't empty
|
||||
@ -152,7 +151,6 @@ void ClientLobbyRoomProtocol::notifyEvent(Event* event)
|
||||
else if (event->type == EVENT_TYPE_DISCONNECTED)
|
||||
{
|
||||
} // if (event->type == EVENT_TYPE_DISCONNECTED)
|
||||
Log::setLogLevel(3);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -160,7 +158,6 @@ void ClientLobbyRoomProtocol::notifyEvent(Event* event)
|
||||
void ServerLobbyRoomProtocol::notifyEvent(Event* event)
|
||||
{
|
||||
assert(m_setup); // assert that the setup exists
|
||||
Log::setLogLevel(1);
|
||||
if (event->type == EVENT_TYPE_MESSAGE)
|
||||
{
|
||||
assert(event->data.size()); // message not empty
|
||||
@ -224,7 +221,6 @@ void ServerLobbyRoomProtocol::notifyEvent(Event* event)
|
||||
{
|
||||
|
||||
} // if (event->type == EVENT_TYPE_DISCONNECTED)
|
||||
Log::setLogLevel(3);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
void* waitInput(void* data)
|
||||
void* waitInput2(void* data)
|
||||
{
|
||||
std::string str = "";
|
||||
bool stop = false;
|
||||
@ -83,7 +83,7 @@ void ServerNetworkManager::run()
|
||||
|
||||
// listen keyboard console input
|
||||
m_thread_keyboard = (pthread_t*)(malloc(sizeof(pthread_t)));
|
||||
pthread_create(m_thread_keyboard, NULL, waitInput, NULL);
|
||||
pthread_create(m_thread_keyboard, NULL, waitInput2, NULL);
|
||||
|
||||
NetworkManager::run();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user