mirror of
https://github.com/glest/glest-source.git
synced 2025-08-12 03:14: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,"=");
|
Tokenize(serverToConnectTo,paramPartTokens,"=");
|
||||||
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
|
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
|
||||||
string autoConnectServer = paramPartTokens[1];
|
string autoConnectServer = paramPartTokens[1];
|
||||||
|
|
||||||
int port = config.getInt("ServerPort",intToStr(GameConstants::serverPort).c_str());
|
int port = config.getInt("ServerPort",intToStr(GameConstants::serverPort).c_str());
|
||||||
vector<string> paramPartTokens2;
|
vector<string> paramPartTokens2;
|
||||||
Tokenize(autoConnectServer,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);
|
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;
|
gameInitialized = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -4388,7 +4394,12 @@ int glestMain(int argc, char** argv) {
|
|||||||
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
|
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
|
||||||
string autoConnectServer = paramPartTokens[1];
|
string autoConnectServer = paramPartTokens[1];
|
||||||
|
|
||||||
program->initClient(mainWindow, autoConnectServer);
|
if(autoConnectServer == "auto-connect") {
|
||||||
|
program->initClientAutoFindHost(mainWindow);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
program->initClient(mainWindow, autoConnectServer);
|
||||||
|
}
|
||||||
gameInitialized = true;
|
gameInitialized = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@@ -263,6 +263,17 @@ void Program::initClient(WindowGl *window, const Ip &serverIp, int portNumber) {
|
|||||||
mainMenu->setState(new MenuStateJoinGame(this, mainMenu, true, serverIp,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) {
|
void Program::initScenario(WindowGl *window, string autoloadScenarioName) {
|
||||||
MainMenu* mainMenu= NULL;
|
MainMenu* mainMenu= NULL;
|
||||||
|
|
||||||
|
@@ -178,6 +178,7 @@ public:
|
|||||||
void initServer(WindowGl *window, GameSettings *settings);
|
void initServer(WindowGl *window, GameSettings *settings);
|
||||||
void initSavedGame(WindowGl *window,bool masterserverMode=false,string saveGameFile="");
|
void initSavedGame(WindowGl *window,bool masterserverMode=false,string saveGameFile="");
|
||||||
void initClient(WindowGl *window, const Ip &serverIp,int portNumber=-1);
|
void initClient(WindowGl *window, const Ip &serverIp,int portNumber=-1);
|
||||||
|
void initClientAutoFindHost(WindowGl *window);
|
||||||
void initScenario(WindowGl *window, string autoloadScenarioName);
|
void initScenario(WindowGl *window, string autoloadScenarioName);
|
||||||
|
|
||||||
//main
|
//main
|
||||||
|
@@ -43,10 +43,30 @@ const int MenuStateJoinGame::foundServersIndex= 2;
|
|||||||
|
|
||||||
const string MenuStateJoinGame::serverFileName= "servers.ini";
|
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,
|
MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu,
|
||||||
bool connect, Ip serverIp,int portNumberOverride):
|
bool connect, Ip serverIp,int portNumberOverride) :
|
||||||
MenuState(program, mainMenu, "join-game")
|
MenuState(program, mainMenu, "join-game") {
|
||||||
{
|
CommonInit(connect, serverIp,portNumberOverride);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuStateJoinGame::CommonInit(bool connect, Ip serverIp,int portNumberOverride) {
|
||||||
containerName = "JoinGame";
|
containerName = "JoinGame";
|
||||||
abortAutoFind = false;
|
abortAutoFind = false;
|
||||||
autoConnectToServer = false;
|
autoConnectToServer = false;
|
||||||
|
@@ -72,6 +72,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool connect= false, Ip serverIp= Ip(),int portNumberOverride=-1);
|
MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool connect= false, Ip serverIp= Ip(),int portNumberOverride=-1);
|
||||||
|
MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool *autoFindHost);
|
||||||
virtual ~MenuStateJoinGame();
|
virtual ~MenuStateJoinGame();
|
||||||
|
|
||||||
void mouseClick(int x, int y, MouseButton mouseButton);
|
void mouseClick(int x, int y, MouseButton mouseButton);
|
||||||
@@ -86,6 +87,8 @@ public:
|
|||||||
void reloadUI();
|
void reloadUI();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void CommonInit(bool connect, Ip serverIp,int portNumberOverride);
|
||||||
void connectToServer();
|
void connectToServer();
|
||||||
virtual void DiscoveredServers(std::vector<string> serverList);
|
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%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\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%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\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]);
|
printf("\n%s=x,x\tRun as a headless server.",GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]);
|
||||||
|
Reference in New Issue
Block a user