- added new headless server status check:

on the SAME box as the headless run:
./megaglest --headless-server-status
This commit is contained in:
Mark Vejvoda
2012-03-25 06:55:43 +00:00
parent bc3cc07aba
commit d356e5f5de
7 changed files with 201 additions and 40 deletions

View File

@@ -247,8 +247,10 @@ protected:
bool isBroadCastThreadRunning();
vector<string> blockIPList;
bool basicMode;
public:
ServerSocket();
ServerSocket(bool basicMode = false);
virtual ~ServerSocket();
void bind(int port);
void listen(int connectionQueueSize= SOMAXCONN);

View File

@@ -31,6 +31,7 @@ const char *GAME_ARGS[] = {
"--connecthost",
"--starthost",
"--headless-server-mode",
"--headless-server-status",
"--use-ports",
"--load-scenario",
@@ -84,6 +85,7 @@ enum GAME_ARG_TYPE {
GAME_ARG_CLIENT,
GAME_ARG_SERVER,
GAME_ARG_MASTERSERVER_MODE,
GAME_ARG_MASTERSERVER_STATUS,
GAME_ARG_USE_PORTS,
GAME_ARG_LOADSCENARIO,
@@ -168,6 +170,8 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
printf("\n \t\tvps - which does NOT read commands from the");
printf("\n \t local console (for some vps's).");
printf("\n%s\tCheck the current status of a headless server.",GAME_ARGS[GAME_ARG_MASTERSERVER_STATUS]);
printf("\n%s=x,y\t\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.");
printf("\n \t\tWhere x is the internal port # on the local");
@@ -425,7 +429,8 @@ int mainSetup(int argc, char **argv) {
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_HELP])) == true ||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VERSION])) == true ||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS])) == true ||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) {
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true ||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_STATUS]))) {
// Use this for masterserver mode for timers like Chrono
if(SDL_Init(SDL_INIT_TIMER) < 0) {
std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << "\n";

View File

@@ -2042,9 +2042,10 @@ void BroadCastClientSocketThread::execute() {
// class ServerSocket
// ===============================================
ServerSocket::ServerSocket() : Socket() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
ServerSocket::ServerSocket(bool basicMode) : Socket() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] basicMode = %d\n",__FILE__,__FUNCTION__,__LINE__,basicMode);
this->basicMode = basicMode;
//printf("SERVER SOCKET CONSTRUCTOR\n");
//MutexSafeWrapper safeMutexUPNP(&ServerSocket::mutexUpnpdiscoverThread,CODE_AT_LINE);
//ServerSocket::upnpdiscoverThread = NULL;
@@ -2052,7 +2053,9 @@ ServerSocket::ServerSocket() : Socket() {
portBound = false;
broadCastThread = NULL;
UPNP_Tools::enabledUPNP = false;
if(this->basicMode == false) {
UPNP_Tools::enabledUPNP = false;
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
@@ -2064,29 +2067,32 @@ ServerSocket::~ServerSocket() {
stopBroadCastThread();
//printf("In [%s::%s] Line: %d safeMutexUPNP\n",__FILE__,__FUNCTION__,__LINE__);
//printf("SERVER SOCKET DESTRUCTOR\n");
MutexSafeWrapper safeMutexUPNP(&ServerSocket::mutexUpnpdiscoverThread,CODE_AT_LINE);
if(ServerSocket::upnpdiscoverThread != NULL) {
SDL_WaitThread(ServerSocket::upnpdiscoverThread, NULL);
ServerSocket::upnpdiscoverThread = NULL;
}
safeMutexUPNP.ReleaseLock();
//printf("In [%s::%s] Line: %d safeMutexUPNP\n",__FILE__,__FUNCTION__,__LINE__);
if(this->basicMode == false) {
//printf("In [%s::%s] Line: %d safeMutexUPNP\n",__FILE__,__FUNCTION__,__LINE__);
//printf("SERVER SOCKET DESTRUCTOR\n");
MutexSafeWrapper safeMutexUPNP(&ServerSocket::mutexUpnpdiscoverThread,CODE_AT_LINE);
if(ServerSocket::upnpdiscoverThread != NULL) {
SDL_WaitThread(ServerSocket::upnpdiscoverThread, NULL);
ServerSocket::upnpdiscoverThread = NULL;
}
safeMutexUPNP.ReleaseLock();
//printf("In [%s::%s] Line: %d safeMutexUPNP\n",__FILE__,__FUNCTION__,__LINE__);
//printf("In [%s::%s] Line: %d UPNP_Tools::enabledUPNP = %d\n",__FILE__,__FUNCTION__,__LINE__,UPNP_Tools::enabledUPNP);
if (UPNP_Tools::enabledUPNP) {
UPNP_Tools::NETremRedirects(ServerSocket::externalPort);
//UPNP_Tools::enabledUPNP = false;
//printf("In [%s::%s] Line: %d UPNP_Tools::enabledUPNP = %d\n",__FILE__,__FUNCTION__,__LINE__,UPNP_Tools::enabledUPNP);
if (UPNP_Tools::enabledUPNP) {
UPNP_Tools::NETremRedirects(ServerSocket::externalPort);
//UPNP_Tools::enabledUPNP = false;
}
MutexSafeWrapper safeMutexUPNP1(&UPNP_Tools::mutexUPNP,CODE_AT_LINE);
if(urls.controlURL && urls.ipcondescURL && urls.controlURL_CIF) {
FreeUPNPUrls(&urls);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
safeMutexUPNP1.ReleaseLock();
}
MutexSafeWrapper safeMutexUPNP1(&UPNP_Tools::mutexUPNP,CODE_AT_LINE);
if(urls.controlURL && urls.ipcondescURL && urls.controlURL_CIF) {
FreeUPNPUrls(&urls);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
safeMutexUPNP1.ReleaseLock();
}
void ServerSocket::stopBroadCastThread() {
@@ -2184,8 +2190,7 @@ void ServerSocket::bind(int port) {
#endif
int err= ::bind(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
if(err < 0)
{
if(err < 0) {
char szBuf[1024]="";
sprintf(szBuf, "In [%s::%s] Error binding socket sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,err,getLastSocketErrorFormattedText().c_str());
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"%s",szBuf);
@@ -2233,17 +2238,19 @@ void ServerSocket::listen(int connectionQueueSize) {
disconnectSocket();
}
if(connectionQueueSize > 0) {
if(isBroadCastThreadRunning() == false) {
startBroadCastThread();
if(this->basicMode == false) {
if(connectionQueueSize > 0) {
if(isBroadCastThreadRunning() == false) {
startBroadCastThread();
}
else {
resumeBroadcast();
}
}
else {
resumeBroadcast();
pauseBroadcast();
}
}
else {
pauseBroadcast();
}
}
Socket *ServerSocket::accept(bool errorOnFail) {