- added option to quit headless server after game has completed:

./megaglest --headless-server-mode=exit
This commit is contained in:
Mark Vejvoda
2011-09-27 18:44:01 +00:00
parent 21005cc1e7
commit 0cf03a3562
6 changed files with 39 additions and 7 deletions

View File

@@ -78,6 +78,10 @@ void BattleEnd::update() {
mouse2d= (mouse2d+1) % Renderer::maxMouse2dAnim;
if(this->stats.getIsMasterserverMode() == true) {
if(program->getWantShutdownApplicationAfterGame() == true) {
program->setShutdownApplicationEnabled(true);
return;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//program->setState(new MainMenu(program));
program->initServer(program->getWindow(),false,true,true);

View File

@@ -40,6 +40,7 @@ private:
public:
BattleEnd(Program *program, const Stats *stats);
~BattleEnd();
virtual void update();
virtual void render();
virtual void keyDown(char key);

View File

@@ -2194,6 +2194,20 @@ int glestMain(int argc, char** argv) {
if( hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) {
isMasterServerModeEnabled = true;
Window::setMasterserverMode(isMasterServerModeEnabled);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]),&foundParamIndIndex);
}
string paramValue = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(paramValue,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string exitHeadless = paramPartTokens[1];
printf("Forcing quit after game has compelted [%s]\n",exitHeadless.c_str());
Program::setWantShutdownApplicationAfterGame(true);
}
}
//off_t fileSize = getFileSize(argv[0]);
@@ -3230,7 +3244,7 @@ int glestMain(int argc, char** argv) {
}
//main loop
while(Window::handleEvent()) {
while(program->isShutdownApplicationEnabled() == false && Window::handleEvent()) {
if(isMasterServerModeEnabled == true) {
#ifndef WIN32
if(poll(cinfd, 1, 0))

View File

@@ -43,6 +43,8 @@ const int Program::maxTimes= 10;
Program *Program::singleton = NULL;
const int SOUND_THREAD_UPDATE_MILLISECONDS = 25;
bool Program::wantShutdownApplicationAfterGame = false;
// =====================================================
// class Program::CrashProgramState
// =====================================================
@@ -161,10 +163,11 @@ void Program::ShowMessageProgramState::update() {
Program::Program() {
this->masterserverMode = false;
skipRenderFrameCount = 0;
programState= NULL;
singleton = this;
soundThreadManager = NULL;
this->shutdownApplicationEnabled = false;
this->skipRenderFrameCount = 0;
this->programState= NULL;
this->singleton = this;
this->soundThreadManager = NULL;
//mesage box
Lang &lang= Lang::getInstance();

View File

@@ -145,6 +145,8 @@ private:
int skipRenderFrameCount;
bool masterserverMode;
bool shutdownApplicationEnabled;
static bool wantShutdownApplicationAfterGame;
public:
Program();
@@ -152,7 +154,12 @@ public:
static Program *getInstance() {return singleton;}
static void setWantShutdownApplicationAfterGame(bool value) { wantShutdownApplicationAfterGame = value; }
static bool getWantShutdownApplicationAfterGame() { return wantShutdownApplicationAfterGame; }
bool isMasterserverMode() const;
bool isShutdownApplicationEnabled() const { return shutdownApplicationEnabled; }
void setShutdownApplicationEnabled(bool value) { shutdownApplicationEnabled = value; }
GraphicMessageBox * getMsgBox() { return &msgBox; }
void initNormal(WindowGl *window);

View File

@@ -119,7 +119,10 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
printf("\n%s\t\tAutomatically starts a game with the last game settings you played.",GAME_ARGS[GAME_ARG_AUTOSTART_LASTGAME]);
printf("\n%s=x\t\t\tAuto connects to a network server at IP or hostname x",GAME_ARGS[GAME_ARG_CLIENT]);
printf("\n%s\t\t\tAuto creates a network server.",GAME_ARGS[GAME_ARG_SERVER]);
printf("\n%s\t\t\tRun as a headless server.",GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]);
printf("\n%s=x\t\t\tRun as a headless server.",GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]);
printf("\n \t\tWhere x is an option command: exit which quits the application after a game has no more connected players.");
printf("\n%s=x\t\tAuto loads the specified scenario by scenario name.",GAME_ARGS[GAME_ARG_LOADSCENARIO]);
printf("\n%s=x\t\tAuto Preview the specified map by map name.",GAME_ARGS[GAME_ARG_PREVIEW_MAP]);
printf("\n%s\t\t\tdisplays the version string of this program.",GAME_ARGS[GAME_ARG_VERSION]);
@@ -265,7 +268,7 @@ bool hasCommandArgument(int argc, char** argv,const string argName, int *foundIn
#define MAIN_FUNCTION(X) int main(int argc, char **argv) \
{ \
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) { \
if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) { \
if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK) < 0) { \
std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << "\n"; \
return 1; \
} \