From f3e96a64c1058f84acea93ca99d425fc14b83221 Mon Sep 17 00:00:00 2001 From: titiger Date: Sun, 3 Jan 2016 16:31:05 +0100 Subject: [PATCH] new parameter --server-title see issue #95 --- source/glest_game/global/config.cpp | 1 + source/glest_game/global/config.h | 4 ++ source/glest_game/main/main.cpp | 23 ++++++++++++ .../menu/menu_state_custom_game.cpp | 37 +++++++++++-------- .../glest_game/menu/menu_state_custom_game.h | 1 + .../include/platform/sdl/platform_main.h | 6 ++- 6 files changed, 56 insertions(+), 16 deletions(-) diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index ea36da14..71b74140 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -113,6 +113,7 @@ Config::Config() { fileNameParameter.first = ""; fileNameParameter.second = ""; custom_path_parameter = ""; + serverTitle = ""; } bool Config::tryCustomPath(std::pair &type, std::pair &file, string custom_path) { diff --git a/source/glest_game/global/config.h b/source/glest_game/global/config.h index 21dea25e..db4a89de 100644 --- a/source/glest_game/global/config.h +++ b/source/glest_game/global/config.h @@ -52,6 +52,7 @@ private: std::pair fileName; std::pair fileLoaded; string custom_path_parameter; + string serverTitle; static map configList; @@ -118,6 +119,9 @@ public: string toString(); + string getServerTitle() {return serverTitle;} + void setServerTitle(string name) {serverTitle=name;} + static string getCustomRuntimeProperty(string key) { return customRuntimeProperties[key]; } static void setCustomRuntimeProperty(string key, string value) { customRuntimeProperties[key] = value; } diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 2bc41c4d..862a4fab 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -4107,6 +4107,29 @@ int glestMain(int argc, char** argv) { } } + if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SERVER_TITLE]) == true) { + int foundParamIndIndex = -1; + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_SERVER_TITLE]) + string("="),&foundParamIndIndex); + if(foundParamIndIndex < 0) { + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_SERVER_TITLE]),&foundParamIndIndex); + } + string paramValue = argv[foundParamIndIndex]; + vector paramPartTokens; + Tokenize(paramValue,paramPartTokens,"="); + if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) { + Config &config = Config::getInstance(); + string serverTitle = paramPartTokens[1]; + printf("Forcing serverTitle[%s]\n",serverTitle.c_str()); + + config.setServerTitle(serverTitle); + } + else { + printf("\nInvalid missing server title specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL)); + + return 1; + } + } + PlatformExceptionHandler::application_binary= executable_path(argv[0],true); mg_app_name = GameConstants::application_name; mailStringSupport = mailString; diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 64eaadd5..eb2e6935 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -461,12 +461,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, labelGameName.init(20+checkBoxPublishServer.getW()+5, networkPos,200); labelGameName.setFont(CoreData::getInstance().getMenuFontBig()); labelGameName.setFont3D(CoreData::getInstance().getMenuFontBig3D()); - if(this->headlessServerMode == false) { - labelGameName.setText(defaultPlayerName+"'s game"); - } - else { - labelGameName.setText("headless ("+defaultPlayerName+")"); - } + labelGameName.setText(createGameName()); labelGameName.setEditable(true); labelGameName.setMaxEditWidth(20); labelGameName.setMaxEditRenderWidth(200); @@ -735,6 +730,22 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, } } +string MenuStateCustomGame::createGameName(string controllingPlayer){ + Config &config = Config::getInstance(); + if(config.getServerTitle()!="" && controllingPlayer == ""){ + return config.getServerTitle(); + } + else if (this->headlessServerMode == true) { + if (controllingPlayer != "") { + return controllingPlayer + " controls"; + } else { + return "Headless (" + defaultPlayerName + ")"; + } + } else { + return defaultPlayerName+"'s game"; + } +} + void MenuStateCustomGame::reloadUI() { Lang &lang= Lang::getInstance(); Config &config = Config::getInstance(); @@ -809,12 +820,8 @@ void MenuStateCustomGame::reloadUI() { labelGameName.setFont(CoreData::getInstance().getMenuFontBig()); labelGameName.setFont3D(CoreData::getInstance().getMenuFontBig3D()); - if(this->headlessServerMode == false) { - labelGameName.setText(defaultPlayerName+"'s game"); - } - else { - labelGameName.setText("headless ("+defaultPlayerName+")"); - } + + labelGameName.setText(createGameName()); labelNetworkPauseGameForLaggedClients.setText(lang.getString("NetworkPauseGameForLaggedClients")); @@ -3854,7 +3861,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force clientConnectedTime = serverInterface->getSlot(i,true)->getConnectedTime(); gameSettings->setMasterserver_admin(serverInterface->getSlot(i,true)->getSessionKey()); gameSettings->setMasterserver_admin_faction_index(serverInterface->getSlot(i,true)->getPlayerIndex()); - labelGameName.setText(serverInterface->getSlot(i,true)->getName()+" controls"); + labelGameName.setText(createGameName(serverInterface->getSlot(i,true)->getName())); //printf("slot = %d, admin key [%d] slot connected time[" MG_SIZE_T_SPECIFIER "] clientConnectedTime [" MG_SIZE_T_SPECIFIER "]\n",i,gameSettings->getMasterserver_admin(),serverInterface->getSlot(i)->getConnectedTime(),clientConnectedTime); } if(serverInterface->getSlot(i,true)->getSessionKey() == gameSettings->getMasterserver_admin()){ @@ -3878,7 +3885,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force clientConnectedTime = serverInterface->getSlot(i,true)->getConnectedTime(); gameSettings->setMasterserver_admin(serverInterface->getSlot(i,true)->getSessionKey()); gameSettings->setMasterserver_admin_faction_index(serverInterface->getSlot(i,true)->getPlayerIndex()); - labelGameName.setText(serverInterface->getSlot(i,true)->getName()+" controls"); + labelGameName.setText(createGameName(serverInterface->getSlot(i,true)->getName())); //printf("slot = %d, admin key [%d] slot connected time[" MG_SIZE_T_SPECIFIER "] clientConnectedTime [" MG_SIZE_T_SPECIFIER "]\n",i,gameSettings->getMasterserver_admin(),serverInterface->getSlot(i)->getConnectedTime(),clientConnectedTime); } if(serverInterface->getSlot(i,true)->getSessionKey() == gameSettings->getMasterserver_admin()){ @@ -3890,7 +3897,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force if(masterserver_admin_found == false) { - labelGameName.setText("Headless: "+defaultPlayerName); + labelGameName.setText(createGameName()); } } diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index c6cd6241..bcc1ff2e 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -292,6 +292,7 @@ private: ServerInterface *& serverInterface, int startIndex, int endIndex, bool onlyNetworkUnassigned); + string createGameName(string controllingPlayer=""); void reloadUI(); void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo); void processScenario(); diff --git a/source/shared_lib/include/platform/sdl/platform_main.h b/source/shared_lib/include/platform/sdl/platform_main.h index edf1ba93..a1fa4d12 100644 --- a/source/shared_lib/include/platform/sdl/platform_main.h +++ b/source/shared_lib/include/platform/sdl/platform_main.h @@ -33,6 +33,7 @@ const char *GAME_ARGS[] = { "--starthost", "--headless-server-mode", "--headless-server-status", + "--server-title", "--use-ports", "--load-scenario", @@ -113,6 +114,7 @@ enum GAME_ARG_TYPE { GAME_ARG_SERVER, GAME_ARG_MASTERSERVER_MODE, GAME_ARG_MASTERSERVER_STATUS, + GAME_ARG_SERVER_TITLE, GAME_ARG_USE_PORTS, GAME_ARG_LOADSCENARIO, @@ -235,7 +237,7 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n%s\tCheck the current status of a headless server.",GAME_ARGS[GAME_ARG_MASTERSERVER_STATUS]); - printf("\n%s=x,y,z\t\t\tForce hosted games to listen internally on port",GAME_ARGS[GAME_ARG_USE_PORTS]); + printf("\n%s=x,y,z\t\tForce hosted games to listen internally on port",GAME_ARGS[GAME_ARG_USE_PORTS]); printf("\n\t\t\t\tx, externally on port y and game status on port z."); printf("\n \t\tWhere x is the internal port # on the local"); printf("\n \t\t machine to listen for connects"); @@ -247,6 +249,8 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n \t\t*NOTE: If enabled the FTP Server port #'s will"); printf("\n \t\t be set to x+1 to x+9"); + printf("\n%s=x\t\tSet server title.",GAME_ARGS[GAME_ARG_SERVER_TITLE]); + printf("\n%s=x\t\tAuto load a scenario by scenario name.",GAME_ARGS[GAME_ARG_LOADSCENARIO]); printf("\n%s=x\t\t\tAuto load a mod by mod pathname.",GAME_ARGS[GAME_ARG_MOD]);