mirror of
https://github.com/glest/glest-source.git
synced 2025-10-03 10:51:55 +02:00
- headless admin cannot launch a game unless there are at least two players connected
This commit is contained in:
@@ -781,6 +781,31 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
|||||||
throw megaglest_runtime_error(szBuf);
|
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;
|
GameSettings gameSettingsBuffer;
|
||||||
networkMessageLaunch.buildGameSettings(&gameSettingsBuffer);
|
networkMessageLaunch.buildGameSettings(&gameSettingsBuffer);
|
||||||
|
|
||||||
@@ -794,6 +819,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
|||||||
this->serverInterface->setMasterserverAdminRequestLaunch(true);
|
this->serverInterface->setMasterserverAdminRequestLaunch(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
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());
|
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());
|
this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress());
|
||||||
|
@@ -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);
|
||||||
|
Reference in New Issue
Block a user