- headless admin cannot launch a game unless there are at least two players connected

This commit is contained in:
Mark Vejvoda 2012-07-07 05:35:25 +00:00
parent b5b2c623fe
commit 490ba7e824
4 changed files with 49 additions and 10 deletions

View File

@ -781,6 +781,31 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
throw megaglest_runtime_error(szBuf);
}
int minHeadLessPlayersRequired = Config::getInstance().getInt("MinHeadlessPlayersRequired","2");
if(networkMessageLaunch.getMessageType() == nmtLaunch &&
this->serverInterface->getConnectedSlotCount() < minHeadLessPlayersRequired) {
Lang &lang= Lang::getInstance();
const vector<string> languageList = this->gameSettings.getUniqueNetworkPlayerLanguages();
for(unsigned int i = 0; i < languageList.size(); ++i) {
char szBuf[4096]="";
string msgTemplate = "You must have have at least %d player(s) connected to start this game!";
if(lang.hasString("HeadlessAdminRequiresMorePlayers") == true) {
msgTemplate = lang.get("HeadlessAdminRequiresMorePlayers",languageList[i]);
}
#ifdef WIN32
_snprintf(szBuf,4095,msgTemplate.c_str(),minHeadLessPlayersRequired);
#else
snprintf(szBuf,4095,msgTemplate.c_str(),minHeadLessPlayersRequired);
#endif
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,szBuf);
string sMsg = szBuf;
bool echoLocal = lang.isLanguageLocal(languageList[i]);
this->serverInterface->sendTextMessage(sMsg,-1, echoLocal, languageList[i], this->getPlayerIndex());
}
}
else {
GameSettings gameSettingsBuffer;
networkMessageLaunch.buildGameSettings(&gameSettingsBuffer);
@ -794,6 +819,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
this->serverInterface->setMasterserverAdminRequestLaunch(true);
}
}
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str());
this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress());

View File

@ -79,7 +79,7 @@ void NetworkManager::update() {
}
bool NetworkManager::isNetworkGame() {
return networkRole==nrClient || (networkRole==nrServer && getServerInterface()->getConnectedSlotCount()>0);
return networkRole==nrClient || (networkRole==nrServer && getServerInterface()->getSlotCount() > 0);
}
GameNetworkInterface* NetworkManager::getGameNetworkInterface(bool throwErrorOnNull) {

View File

@ -523,11 +523,22 @@ bool ServerInterface::hasClientConnection() {
return result;
}
int ServerInterface::getSlotCount() {
int slotCount = 0;
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
if(slots[i] != NULL) {
++slotCount;
}
}
return slotCount;
}
int ServerInterface::getConnectedSlotCount() {
int connectedSlotCount = 0;
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
if(slots[i] != NULL) {
if(slots[i] != NULL && slots[i]->isConnected() == true) {
++connectedSlotCount;
}
}

View File

@ -138,7 +138,9 @@ public:
bool switchSlot(int fromPlayerIndex, int toPlayerIndex);
void removeSlot(int playerIndex, int lockedSlotIndex = -1);
ConnectionSlot *getSlot(int playerIndex);
int getSlotCount();
int getConnectedSlotCount();
int getOpenSlotCount();
bool launchGame(const GameSettings *gameSettings);
void validateGameSettings(GameSettings *serverGameSettings);