mirror of
https://github.com/glest/glest-source.git
synced 2025-08-12 03:14:00 +02:00
- added new commandline option --connect=x:y format as requested
This commit is contained in:
@@ -4343,6 +4343,39 @@ int glestMain(int argc, char** argv) {
|
|||||||
return 1;
|
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) {
|
else if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CLIENT])) == true) {
|
||||||
int foundParamIndIndex = -1;
|
int foundParamIndIndex = -1;
|
||||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CLIENT]) + string("="),&foundParamIndIndex);
|
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));
|
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;
|
MainMenu* mainMenu= NULL;
|
||||||
|
|
||||||
init(window);
|
init(window);
|
||||||
mainMenu= new MainMenu(this);
|
mainMenu= new MainMenu(this);
|
||||||
setState(mainMenu);
|
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) {
|
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,bool autostart=false,bool openNetworkSlots=false,bool masterserverMode=false);
|
||||||
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);
|
void initClient(WindowGl *window, const Ip &serverIp,int portNumber=-1);
|
||||||
void initScenario(WindowGl *window, string autoloadScenarioName);
|
void initScenario(WindowGl *window, string autoloadScenarioName);
|
||||||
|
|
||||||
//main
|
//main
|
||||||
|
@@ -43,7 +43,8 @@ const int MenuStateJoinGame::foundServersIndex= 2;
|
|||||||
|
|
||||||
const string MenuStateJoinGame::serverFileName= "servers.ini";
|
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")
|
MenuState(program, mainMenu, "join-game")
|
||||||
{
|
{
|
||||||
containerName = "JoinGame";
|
containerName = "JoinGame";
|
||||||
@@ -155,13 +156,23 @@ MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool
|
|||||||
playerIndex= -1;
|
playerIndex= -1;
|
||||||
|
|
||||||
//server ip
|
//server ip
|
||||||
if(connect) {
|
if(connect == true) {
|
||||||
labelServerIp.setText(serverIp.getString() + "_");
|
string hostIP = serverIp.getString();
|
||||||
|
if(portNumberOverride > 0) {
|
||||||
|
hostIP += ":" + intToStr(portNumberOverride);
|
||||||
|
}
|
||||||
|
|
||||||
|
labelServerIp.setText(hostIP + "_");
|
||||||
|
|
||||||
autoConnectToServer = true;
|
autoConnectToServer = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
labelServerIp.setText(config.getString("ServerIp") + "_");
|
string hostIP = config.getString("ServerIp");
|
||||||
|
if(portNumberOverride > 0) {
|
||||||
|
hostIP += ":" + intToStr(portNumberOverride);
|
||||||
|
}
|
||||||
|
|
||||||
|
labelServerIp.setText(hostIP + "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
host = labelServerIp.getText();
|
host = labelServerIp.getText();
|
||||||
@@ -562,7 +573,7 @@ void MenuStateJoinGame::update()
|
|||||||
}
|
}
|
||||||
string saveHost = Ip(host).getString();
|
string saveHost = Ip(host).getString();
|
||||||
if(hostPartsList.size() > 1) {
|
if(hostPartsList.size() > 1) {
|
||||||
saveHost += ";" + hostPartsList[1];
|
saveHost += ":" + hostPartsList[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
servers.setString(clientInterface->getServerName(), saveHost);
|
servers.setString(clientInterface->getServerName(), saveHost);
|
||||||
@@ -738,7 +749,7 @@ void MenuStateJoinGame::connectToServer() {
|
|||||||
|
|
||||||
string saveHost = Ip(host).getString();
|
string saveHost = Ip(host).getString();
|
||||||
if(hostPartsList.size() > 1) {
|
if(hostPartsList.size() > 1) {
|
||||||
saveHost += ";" + hostPartsList[1];
|
saveHost += ":" + hostPartsList[1];
|
||||||
}
|
}
|
||||||
servers.setString(clientInterface->getServerName(), saveHost);
|
servers.setString(clientInterface->getServerName(), saveHost);
|
||||||
servers.save(serversSavedFile);
|
servers.save(serversSavedFile);
|
||||||
|
@@ -71,7 +71,7 @@ private:
|
|||||||
bool autoConnectToServer;
|
bool autoConnectToServer;
|
||||||
|
|
||||||
public:
|
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();
|
virtual ~MenuStateJoinGame();
|
||||||
|
|
||||||
void mouseClick(int x, int y, MouseButton mouseButton);
|
void mouseClick(int x, int y, MouseButton mouseButton);
|
||||||
|
@@ -28,6 +28,7 @@ const char *GAME_ARGS[] = {
|
|||||||
"--autostart-lastgame",
|
"--autostart-lastgame",
|
||||||
"--load-saved-game",
|
"--load-saved-game",
|
||||||
"--auto-test",
|
"--auto-test",
|
||||||
|
"--connect",
|
||||||
"--connecthost",
|
"--connecthost",
|
||||||
"--starthost",
|
"--starthost",
|
||||||
"--headless-server-mode",
|
"--headless-server-mode",
|
||||||
@@ -96,6 +97,7 @@ enum GAME_ARG_TYPE {
|
|||||||
GAME_ARG_AUTOSTART_LASTGAME,
|
GAME_ARG_AUTOSTART_LASTGAME,
|
||||||
GAME_ARG_AUTOSTART_LAST_SAVED_GAME,
|
GAME_ARG_AUTOSTART_LAST_SAVED_GAME,
|
||||||
GAME_ARG_AUTO_TEST,
|
GAME_ARG_AUTO_TEST,
|
||||||
|
GAME_ARG_CONNECT,
|
||||||
GAME_ARG_CLIENT,
|
GAME_ARG_CLIENT,
|
||||||
GAME_ARG_SERVER,
|
GAME_ARG_SERVER,
|
||||||
GAME_ARG_MASTERSERVER_MODE,
|
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\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 \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=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]);
|
printf("\n%s\t\t\tAuto create a host server.",GAME_ARGS[GAME_ARG_SERVER]);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user