- headless admin cannot launch a game unless there are at least two players connected
This commit is contained in:
parent
b5b2c623fe
commit
490ba7e824
|
@ -781,17 +781,43 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameSettings gameSettingsBuffer;
|
int minHeadLessPlayersRequired = Config::getInstance().getInt("MinHeadlessPlayersRequired","2");
|
||||||
networkMessageLaunch.buildGameSettings(&gameSettingsBuffer);
|
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]="";
|
||||||
|
|
||||||
//printf("Connection slot got networkMessageLaunch.getMessageType() = %d, got map [%s]\n",networkMessageLaunch.getMessageType(),gameSettings.getMap().c_str());
|
string msgTemplate = "You must have have at least %d player(s) connected to start this game!";
|
||||||
//printf("\n\n\n\n=====Connection slot got settings:\n%s\n",gameSettings.toString().c_str());
|
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);
|
||||||
|
|
||||||
//this->serverInterface->setGameSettings(&gameSettingsBuffer,false);
|
string sMsg = szBuf;
|
||||||
this->serverInterface->broadcastGameSetup(&gameSettingsBuffer, true);
|
bool echoLocal = lang.isLanguageLocal(languageList[i]);
|
||||||
|
this->serverInterface->sendTextMessage(sMsg,-1, echoLocal, languageList[i], this->getPlayerIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
GameSettings gameSettingsBuffer;
|
||||||
|
networkMessageLaunch.buildGameSettings(&gameSettingsBuffer);
|
||||||
|
|
||||||
if(networkMessageLaunch.getMessageType() == nmtLaunch) {
|
//printf("Connection slot got networkMessageLaunch.getMessageType() = %d, got map [%s]\n",networkMessageLaunch.getMessageType(),gameSettings.getMap().c_str());
|
||||||
this->serverInterface->setMasterserverAdminRequestLaunch(true);
|
//printf("\n\n\n\n=====Connection slot got settings:\n%s\n",gameSettings.toString().c_str());
|
||||||
|
|
||||||
|
//this->serverInterface->setGameSettings(&gameSettingsBuffer,false);
|
||||||
|
this->serverInterface->broadcastGameSetup(&gameSettingsBuffer, true);
|
||||||
|
|
||||||
|
if(networkMessageLaunch.getMessageType() == nmtLaunch) {
|
||||||
|
this->serverInterface->setMasterserverAdminRequestLaunch(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -79,7 +79,7 @@ void NetworkManager::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkManager::isNetworkGame() {
|
bool NetworkManager::isNetworkGame() {
|
||||||
return networkRole==nrClient || (networkRole==nrServer && getServerInterface()->getConnectedSlotCount()>0);
|
return networkRole==nrClient || (networkRole==nrServer && getServerInterface()->getSlotCount() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameNetworkInterface* NetworkManager::getGameNetworkInterface(bool throwErrorOnNull) {
|
GameNetworkInterface* NetworkManager::getGameNetworkInterface(bool throwErrorOnNull) {
|
||||||
|
|
|
@ -523,11 +523,22 @@ bool ServerInterface::hasClientConnection() {
|
||||||
return result;
|
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 ServerInterface::getConnectedSlotCount() {
|
||||||
int connectedSlotCount = 0;
|
int connectedSlotCount = 0;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
if(slots[i] != NULL) {
|
if(slots[i] != NULL && slots[i]->isConnected() == true) {
|
||||||
++connectedSlotCount;
|
++connectedSlotCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,9 @@ public:
|
||||||
bool switchSlot(int fromPlayerIndex, int toPlayerIndex);
|
bool switchSlot(int fromPlayerIndex, int toPlayerIndex);
|
||||||
void removeSlot(int playerIndex, int lockedSlotIndex = -1);
|
void removeSlot(int playerIndex, int lockedSlotIndex = -1);
|
||||||
ConnectionSlot *getSlot(int playerIndex);
|
ConnectionSlot *getSlot(int playerIndex);
|
||||||
|
int getSlotCount();
|
||||||
int getConnectedSlotCount();
|
int getConnectedSlotCount();
|
||||||
|
|
||||||
int getOpenSlotCount();
|
int getOpenSlotCount();
|
||||||
bool launchGame(const GameSettings *gameSettings);
|
bool launchGame(const GameSettings *gameSettings);
|
||||||
void validateGameSettings(GameSettings *serverGameSettings);
|
void validateGameSettings(GameSettings *serverGameSettings);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user