- added new option to headless modedisable reading from local console:

--headless-server-mode=vps

can be comgined with exit option:

--headless-server-mode=exit,vps
This commit is contained in:
Mark Vejvoda
2011-11-16 05:20:35 +00:00
parent 3e3bcb6af8
commit 54e4d7604c
2 changed files with 61 additions and 35 deletions

View File

@@ -93,6 +93,7 @@ using namespace Shared;
namespace Glest{ namespace Game{ namespace Glest{ namespace Game{
bool disableheadless_console = false;
bool disableBacktrace = false; bool disableBacktrace = false;
bool gameInitialized = false; bool gameInitialized = false;
//static string application_binary=""; //static string application_binary="";
@@ -2457,10 +2458,23 @@ int glestMain(int argc, char** argv) {
vector<string> paramPartTokens; vector<string> paramPartTokens;
Tokenize(paramValue,paramPartTokens,"="); Tokenize(paramValue,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) { if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string exitHeadless = paramPartTokens[1]; string headless_command_list = paramPartTokens[1];
printf("Forcing quit after game has compelted [%s]\n",exitHeadless.c_str());
vector<string> paramHeadlessCommandList;
Tokenize(headless_command_list,paramHeadlessCommandList,",");
for(unsigned int i = 0; i < paramHeadlessCommandList.size(); ++i) {
string headless_command = paramHeadlessCommandList[i];
if(headless_command == "exit") {
printf("Forcing quit after game has compelted [%s]\n",headless_command.c_str());
Program::setWantShutdownApplicationAfterGame(true); Program::setWantShutdownApplicationAfterGame(true);
} }
else if(headless_command == "vps") {
printf("Disabled reading from console [%s]\n",headless_command.c_str());
disableheadless_console = true;
}
}
}
} }
//off_t fileSize = getFileSize(argv[0]); //off_t fileSize = getFileSize(argv[0]);
@@ -3424,15 +3438,22 @@ int glestMain(int argc, char** argv) {
// Check for commands being input from stdin // Check for commands being input from stdin
string command=""; string command="";
#ifndef WIN32 #ifndef WIN32
pollfd cinfd[1]; pollfd cinfd[1];
#else
HANDLE h = 0;
#endif
if(disableheadless_console == false) {
#ifndef WIN32
// Theoretically this should always be 0, but one fileno call isn't going to hurt, and if // Theoretically this should always be 0, but one fileno call isn't going to hurt, and if
// we try to run somewhere that stdin isn't fd 0 then it will still just work // we try to run somewhere that stdin isn't fd 0 then it will still just work
cinfd[0].fd = fileno(stdin); cinfd[0].fd = fileno(stdin);
cinfd[0].events = POLLIN; cinfd[0].events = POLLIN;
#else #else
HANDLE h = GetStdHandle(STD_INPUT_HANDLE); h = GetStdHandle(STD_INPUT_HANDLE);
#endif #endif
}
if(isMasterServerModeEnabled == true) { if(isMasterServerModeEnabled == true) {
printf("Headless server is now running...\n"); printf("Headless server is now running...\n");
@@ -3443,6 +3464,8 @@ int glestMain(int argc, char** argv) {
//main loop //main loop
while(program->isShutdownApplicationEnabled() == false && Window::handleEvent()) { while(program->isShutdownApplicationEnabled() == false && Window::handleEvent()) {
if(isMasterServerModeEnabled == true) { if(isMasterServerModeEnabled == true) {
if(disableheadless_console == false) {
#ifndef WIN32 #ifndef WIN32
int pollresult = poll(cinfd, 1, 0); int pollresult = poll(cinfd, 1, 0);
int pollerror = errno; int pollerror = errno;
@@ -3475,6 +3498,7 @@ int glestMain(int argc, char** argv) {
} }
#endif #endif
} }
}
//printf("looping\n"); //printf("looping\n");
} }

View File

@@ -124,8 +124,10 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
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=x\t\t\tRun as a headless server.",GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]); printf("\n%s=x,x\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 \t\tWhere x is an optional comma delimited command list of one or more of the following: ");
printf("\n \t\texit - which quits the application after a game has no more connected players.");
printf("\n \t\tvps - which does NOT read commands from the local console (required for some vps's).");
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]);