mirror of
https://github.com/glest/glest-source.git
synced 2025-09-30 17:39:02 +02:00
- added option to quit headless server after game has completed:
./megaglest --headless-server-mode=exit
This commit is contained in:
@@ -78,6 +78,10 @@ void BattleEnd::update() {
|
|||||||
mouse2d= (mouse2d+1) % Renderer::maxMouse2dAnim;
|
mouse2d= (mouse2d+1) % Renderer::maxMouse2dAnim;
|
||||||
|
|
||||||
if(this->stats.getIsMasterserverMode() == true) {
|
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__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
//program->setState(new MainMenu(program));
|
//program->setState(new MainMenu(program));
|
||||||
program->initServer(program->getWindow(),false,true,true);
|
program->initServer(program->getWindow(),false,true,true);
|
||||||
|
@@ -40,6 +40,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
BattleEnd(Program *program, const Stats *stats);
|
BattleEnd(Program *program, const Stats *stats);
|
||||||
~BattleEnd();
|
~BattleEnd();
|
||||||
|
|
||||||
virtual void update();
|
virtual void update();
|
||||||
virtual void render();
|
virtual void render();
|
||||||
virtual void keyDown(char key);
|
virtual void keyDown(char key);
|
||||||
|
@@ -2194,6 +2194,20 @@ int glestMain(int argc, char** argv) {
|
|||||||
if( hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) {
|
if( hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) {
|
||||||
isMasterServerModeEnabled = true;
|
isMasterServerModeEnabled = true;
|
||||||
Window::setMasterserverMode(isMasterServerModeEnabled);
|
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]);
|
//off_t fileSize = getFileSize(argv[0]);
|
||||||
@@ -3230,7 +3244,7 @@ int glestMain(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//main loop
|
//main loop
|
||||||
while(Window::handleEvent()) {
|
while(program->isShutdownApplicationEnabled() == false && Window::handleEvent()) {
|
||||||
if(isMasterServerModeEnabled == true) {
|
if(isMasterServerModeEnabled == true) {
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
if(poll(cinfd, 1, 0))
|
if(poll(cinfd, 1, 0))
|
||||||
|
@@ -43,6 +43,8 @@ const int Program::maxTimes= 10;
|
|||||||
Program *Program::singleton = NULL;
|
Program *Program::singleton = NULL;
|
||||||
const int SOUND_THREAD_UPDATE_MILLISECONDS = 25;
|
const int SOUND_THREAD_UPDATE_MILLISECONDS = 25;
|
||||||
|
|
||||||
|
bool Program::wantShutdownApplicationAfterGame = false;
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Program::CrashProgramState
|
// class Program::CrashProgramState
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -161,10 +163,11 @@ void Program::ShowMessageProgramState::update() {
|
|||||||
|
|
||||||
Program::Program() {
|
Program::Program() {
|
||||||
this->masterserverMode = false;
|
this->masterserverMode = false;
|
||||||
skipRenderFrameCount = 0;
|
this->shutdownApplicationEnabled = false;
|
||||||
programState= NULL;
|
this->skipRenderFrameCount = 0;
|
||||||
singleton = this;
|
this->programState= NULL;
|
||||||
soundThreadManager = NULL;
|
this->singleton = this;
|
||||||
|
this->soundThreadManager = NULL;
|
||||||
|
|
||||||
//mesage box
|
//mesage box
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
|
@@ -145,6 +145,8 @@ private:
|
|||||||
int skipRenderFrameCount;
|
int skipRenderFrameCount;
|
||||||
|
|
||||||
bool masterserverMode;
|
bool masterserverMode;
|
||||||
|
bool shutdownApplicationEnabled;
|
||||||
|
static bool wantShutdownApplicationAfterGame;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Program();
|
Program();
|
||||||
@@ -152,7 +154,12 @@ public:
|
|||||||
|
|
||||||
static Program *getInstance() {return singleton;}
|
static Program *getInstance() {return singleton;}
|
||||||
|
|
||||||
|
static void setWantShutdownApplicationAfterGame(bool value) { wantShutdownApplicationAfterGame = value; }
|
||||||
|
static bool getWantShutdownApplicationAfterGame() { return wantShutdownApplicationAfterGame; }
|
||||||
|
|
||||||
bool isMasterserverMode() const;
|
bool isMasterserverMode() const;
|
||||||
|
bool isShutdownApplicationEnabled() const { return shutdownApplicationEnabled; }
|
||||||
|
void setShutdownApplicationEnabled(bool value) { shutdownApplicationEnabled = value; }
|
||||||
|
|
||||||
GraphicMessageBox * getMsgBox() { return &msgBox; }
|
GraphicMessageBox * getMsgBox() { return &msgBox; }
|
||||||
void initNormal(WindowGl *window);
|
void initNormal(WindowGl *window);
|
||||||
|
@@ -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\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=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\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 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=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]);
|
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) \
|
#define MAIN_FUNCTION(X) int main(int argc, char **argv) \
|
||||||
{ \
|
{ \
|
||||||
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) { \
|
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"; \
|
std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << "\n"; \
|
||||||
return 1; \
|
return 1; \
|
||||||
} \
|
} \
|
||||||
|
Reference in New Issue
Block a user