- added new commandline option --connect=x:y format as requested
This commit is contained in:
parent
c7808dc021
commit
74cca86b3f
|
@ -4343,6 +4343,39 @@ int glestMain(int argc, char** argv) {
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
else if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CONNECT])) == true) {
|
||||
int foundParamIndIndex = -1;
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CONNECT]) + string("="),&foundParamIndIndex);
|
||||
if(foundParamIndIndex < 0) {
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CONNECT]),&foundParamIndIndex);
|
||||
}
|
||||
string serverToConnectTo = argv[foundParamIndIndex];
|
||||
vector<string> paramPartTokens;
|
||||
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,":");
|
||||
autoConnectServer = paramPartTokens2[0];
|
||||
if(paramPartTokens2.size() >= 2 && paramPartTokens2[1].length() > 0) {
|
||||
port = strToInt(paramPartTokens2[1]);
|
||||
}
|
||||
|
||||
printf("Connecting to host [%s] using port: %d\n",autoConnectServer.c_str(),port);
|
||||
program->initClient(mainWindow, autoConnectServer,port);
|
||||
gameInitialized = true;
|
||||
}
|
||||
else {
|
||||
|
||||
printf("\nInvalid host specified on commandline [%s] host [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
|
||||
printParameterHelp(argv[0],foundInvalidArgs);
|
||||
delete mainWindow;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
else if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CLIENT])) == true) {
|
||||
int foundParamIndIndex = -1;
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CLIENT]) + string("="),&foundParamIndIndex);
|
||||
|
|
|
@ -254,13 +254,13 @@ void Program::initServer(WindowGl *window, GameSettings *settings) {
|
|||
mainMenu->setState(new MenuStateCustomGame(this, mainMenu, false, pNewGame, true, settings));
|
||||
}
|
||||
|
||||
void Program::initClient(WindowGl *window, const Ip &serverIp) {
|
||||
void Program::initClient(WindowGl *window, const Ip &serverIp, int portNumber) {
|
||||
MainMenu* mainMenu= NULL;
|
||||
|
||||
init(window);
|
||||
mainMenu= new MainMenu(this);
|
||||
setState(mainMenu);
|
||||
mainMenu->setState(new MenuStateJoinGame(this, mainMenu, true, serverIp));
|
||||
mainMenu->setState(new MenuStateJoinGame(this, mainMenu, true, serverIp,portNumber));
|
||||
}
|
||||
|
||||
void Program::initScenario(WindowGl *window, string autoloadScenarioName) {
|
||||
|
|
|
@ -177,7 +177,7 @@ public:
|
|||
void initServer(WindowGl *window,bool autostart=false,bool openNetworkSlots=false,bool masterserverMode=false);
|
||||
void initServer(WindowGl *window, GameSettings *settings);
|
||||
void initSavedGame(WindowGl *window,bool masterserverMode=false,string saveGameFile="");
|
||||
void initClient(WindowGl *window, const Ip &serverIp);
|
||||
void initClient(WindowGl *window, const Ip &serverIp,int portNumber=-1);
|
||||
void initScenario(WindowGl *window, string autoloadScenarioName);
|
||||
|
||||
//main
|
||||
|
|
|
@ -43,7 +43,8 @@ const int MenuStateJoinGame::foundServersIndex= 2;
|
|||
|
||||
const string MenuStateJoinGame::serverFileName= "servers.ini";
|
||||
|
||||
MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool connect, Ip serverIp):
|
||||
MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu,
|
||||
bool connect, Ip serverIp,int portNumberOverride):
|
||||
MenuState(program, mainMenu, "join-game")
|
||||
{
|
||||
containerName = "JoinGame";
|
||||
|
@ -155,13 +156,23 @@ MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool
|
|||
playerIndex= -1;
|
||||
|
||||
//server ip
|
||||
if(connect) {
|
||||
labelServerIp.setText(serverIp.getString() + "_");
|
||||
if(connect == true) {
|
||||
string hostIP = serverIp.getString();
|
||||
if(portNumberOverride > 0) {
|
||||
hostIP += ":" + intToStr(portNumberOverride);
|
||||
}
|
||||
|
||||
labelServerIp.setText(hostIP + "_");
|
||||
|
||||
autoConnectToServer = true;
|
||||
}
|
||||
else {
|
||||
labelServerIp.setText(config.getString("ServerIp") + "_");
|
||||
string hostIP = config.getString("ServerIp");
|
||||
if(portNumberOverride > 0) {
|
||||
hostIP += ":" + intToStr(portNumberOverride);
|
||||
}
|
||||
|
||||
labelServerIp.setText(hostIP + "_");
|
||||
}
|
||||
|
||||
host = labelServerIp.getText();
|
||||
|
@ -562,7 +573,7 @@ void MenuStateJoinGame::update()
|
|||
}
|
||||
string saveHost = Ip(host).getString();
|
||||
if(hostPartsList.size() > 1) {
|
||||
saveHost += ";" + hostPartsList[1];
|
||||
saveHost += ":" + hostPartsList[1];
|
||||
}
|
||||
|
||||
servers.setString(clientInterface->getServerName(), saveHost);
|
||||
|
@ -738,7 +749,7 @@ void MenuStateJoinGame::connectToServer() {
|
|||
|
||||
string saveHost = Ip(host).getString();
|
||||
if(hostPartsList.size() > 1) {
|
||||
saveHost += ";" + hostPartsList[1];
|
||||
saveHost += ":" + hostPartsList[1];
|
||||
}
|
||||
servers.setString(clientInterface->getServerName(), saveHost);
|
||||
servers.save(serversSavedFile);
|
||||
|
|
|
@ -71,7 +71,7 @@ private:
|
|||
bool autoConnectToServer;
|
||||
|
||||
public:
|
||||
MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool connect= false, Ip serverIp= Ip());
|
||||
MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool connect= false, Ip serverIp= Ip(),int portNumberOverride=-1);
|
||||
virtual ~MenuStateJoinGame();
|
||||
|
||||
void mouseClick(int x, int y, MouseButton mouseButton);
|
||||
|
|
|
@ -28,6 +28,7 @@ const char *GAME_ARGS[] = {
|
|||
"--autostart-lastgame",
|
||||
"--load-saved-game",
|
||||
"--auto-test",
|
||||
"--connect",
|
||||
"--connecthost",
|
||||
"--starthost",
|
||||
"--headless-server-mode",
|
||||
|
@ -96,6 +97,7 @@ enum GAME_ARG_TYPE {
|
|||
GAME_ARG_AUTOSTART_LASTGAME,
|
||||
GAME_ARG_AUTOSTART_LAST_SAVED_GAME,
|
||||
GAME_ARG_AUTO_TEST,
|
||||
GAME_ARG_CONNECT,
|
||||
GAME_ARG_CLIENT,
|
||||
GAME_ARG_SERVER,
|
||||
GAME_ARG_MASTERSERVER_MODE,
|
||||
|
@ -187,6 +189,9 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
|||
printf("\n \t\tWhere z is the word exit indicating the game should exit after the game is finished or the time runs out.");
|
||||
printf("\n \t\tIf z is not specified (or is empty) then auto test continues to cycle.");
|
||||
|
||||
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%s=x\t\t\tAuto connect to host server at IP or hostname x",GAME_ARGS[GAME_ARG_CLIENT]);
|
||||
printf("\n%s\t\t\tAuto create a host server.",GAME_ARGS[GAME_ARG_SERVER]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user