mirror of
https://github.com/glest/glest-source.git
synced 2025-08-11 19:04:00 +02:00
- allow the --connecthost commandline to use:
--connecthost=auto-connect which will auto connect to the first found server on a lan
This commit is contained in:
@@ -4355,6 +4355,7 @@ int glestMain(int argc, char** argv) {
|
||||
Tokenize(serverToConnectTo,paramPartTokens,"=");
|
||||
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
|
||||
string autoConnectServer = paramPartTokens[1];
|
||||
|
||||
int port = config.getInt("ServerPort",intToStr(GameConstants::serverPort).c_str());
|
||||
vector<string> paramPartTokens2;
|
||||
Tokenize(autoConnectServer,paramPartTokens2,":");
|
||||
@@ -4364,7 +4365,12 @@ int glestMain(int argc, char** argv) {
|
||||
}
|
||||
|
||||
printf("Connecting to host [%s] using port: %d\n",autoConnectServer.c_str(),port);
|
||||
program->initClient(mainWindow, autoConnectServer,port);
|
||||
if(autoConnectServer == "auto-connect") {
|
||||
program->initClientAutoFindHost(mainWindow);
|
||||
}
|
||||
else {
|
||||
program->initClient(mainWindow, autoConnectServer,port);
|
||||
}
|
||||
gameInitialized = true;
|
||||
}
|
||||
else {
|
||||
@@ -4388,7 +4394,12 @@ int glestMain(int argc, char** argv) {
|
||||
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
|
||||
string autoConnectServer = paramPartTokens[1];
|
||||
|
||||
program->initClient(mainWindow, autoConnectServer);
|
||||
if(autoConnectServer == "auto-connect") {
|
||||
program->initClientAutoFindHost(mainWindow);
|
||||
}
|
||||
else {
|
||||
program->initClient(mainWindow, autoConnectServer);
|
||||
}
|
||||
gameInitialized = true;
|
||||
}
|
||||
else {
|
||||
|
@@ -263,6 +263,17 @@ void Program::initClient(WindowGl *window, const Ip &serverIp, int portNumber) {
|
||||
mainMenu->setState(new MenuStateJoinGame(this, mainMenu, true, serverIp,portNumber));
|
||||
}
|
||||
|
||||
void Program::initClientAutoFindHost(WindowGl *window) {
|
||||
MainMenu* mainMenu= NULL;
|
||||
|
||||
init(window);
|
||||
mainMenu= new MainMenu(this);
|
||||
setState(mainMenu);
|
||||
bool autoFindHost = true;
|
||||
mainMenu->setState(new MenuStateJoinGame(this, mainMenu, &autoFindHost));
|
||||
|
||||
}
|
||||
|
||||
void Program::initScenario(WindowGl *window, string autoloadScenarioName) {
|
||||
MainMenu* mainMenu= NULL;
|
||||
|
||||
|
@@ -178,6 +178,7 @@ public:
|
||||
void initServer(WindowGl *window, GameSettings *settings);
|
||||
void initSavedGame(WindowGl *window,bool masterserverMode=false,string saveGameFile="");
|
||||
void initClient(WindowGl *window, const Ip &serverIp,int portNumber=-1);
|
||||
void initClientAutoFindHost(WindowGl *window);
|
||||
void initScenario(WindowGl *window, string autoloadScenarioName);
|
||||
|
||||
//main
|
||||
|
@@ -43,10 +43,30 @@ const int MenuStateJoinGame::foundServersIndex= 2;
|
||||
|
||||
const string MenuStateJoinGame::serverFileName= "servers.ini";
|
||||
|
||||
MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool *autoFindHost) :
|
||||
MenuState(program, mainMenu, "join-game") {
|
||||
CommonInit(false,Ip(),-1);
|
||||
|
||||
if(autoFindHost != NULL && *autoFindHost == true) {
|
||||
//if(clientInterface->isConnected() == false) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
buttonAutoFindServers.setEnabled(false);
|
||||
buttonConnect.setEnabled(false);
|
||||
|
||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||
ClientInterface* clientInterface= networkManager.getClientInterface();
|
||||
clientInterface->discoverServers(this);
|
||||
//}
|
||||
}
|
||||
}
|
||||
MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu,
|
||||
bool connect, Ip serverIp,int portNumberOverride):
|
||||
MenuState(program, mainMenu, "join-game")
|
||||
{
|
||||
bool connect, Ip serverIp,int portNumberOverride) :
|
||||
MenuState(program, mainMenu, "join-game") {
|
||||
CommonInit(connect, serverIp,portNumberOverride);
|
||||
}
|
||||
|
||||
void MenuStateJoinGame::CommonInit(bool connect, Ip serverIp,int portNumberOverride) {
|
||||
containerName = "JoinGame";
|
||||
abortAutoFind = false;
|
||||
autoConnectToServer = false;
|
||||
|
@@ -72,6 +72,7 @@ private:
|
||||
|
||||
public:
|
||||
MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool connect= false, Ip serverIp= Ip(),int portNumberOverride=-1);
|
||||
MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool *autoFindHost);
|
||||
virtual ~MenuStateJoinGame();
|
||||
|
||||
void mouseClick(int x, int y, MouseButton mouseButton);
|
||||
@@ -86,6 +87,8 @@ public:
|
||||
void reloadUI();
|
||||
|
||||
private:
|
||||
|
||||
void CommonInit(bool connect, Ip serverIp,int portNumberOverride);
|
||||
void connectToServer();
|
||||
virtual void DiscoveredServers(std::vector<string> serverList);
|
||||
};
|
||||
|
@@ -191,8 +191,13 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
||||
|
||||
printf("\n%s=x:y\t\t\tAuto connect to host server at IP or hostname x using port y",GAME_ARGS[GAME_ARG_CONNECT]);
|
||||
printf("\n \t\tShortcut version of using %s and %s.",GAME_ARGS[GAME_ARG_CLIENT],GAME_ARGS[GAME_ARG_USE_PORTS]);
|
||||
printf("\n \t\t*NOTE: to automatically connect to the first LAN");
|
||||
printf("\n \t\t host you may use: %s=auto-connect",GAME_ARGS[GAME_ARG_CONNECT]);
|
||||
|
||||
printf("\n%s=x\t\t\tAuto connect to host server at IP or hostname x",GAME_ARGS[GAME_ARG_CLIENT]);
|
||||
printf("\n \t\t*NOTE: to automatically connect to the first LAN");
|
||||
printf("\n \t\t host you may use: %s=auto-connect",GAME_ARGS[GAME_ARG_CLIENT]);
|
||||
|
||||
printf("\n%s\t\t\tAuto create a host server.",GAME_ARGS[GAME_ARG_SERVER]);
|
||||
|
||||
printf("\n%s=x,x\tRun as a headless server.",GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]);
|
||||
|
Reference in New Issue
Block a user