attempt to fix resume game

This commit is contained in:
Mark Vejvoda 2013-05-26 03:35:31 +00:00
parent c932965d9e
commit f84cf5c216
3 changed files with 48 additions and 11 deletions

View File

@ -1178,8 +1178,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
Lang &lang= Lang::getInstance();
string advanceToItemStartingWith = "";
if(!mainMessageBox.getEnabled())
{
if(mainMessageBox.getEnabled() == false) {
if(Shared::Platform::Window::isKeyStateModPressed(KMOD_SHIFT) == true) {
wchar_t lastKey = Shared::Platform::Window::extractLastKeyPressed();
//printf("lastKey = %d [%c]\n",lastKey,lastKey);
@ -1443,9 +1442,11 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
return;
}
if (initialSettingsReceivedFromServer == false) return;
if (initialSettingsReceivedFromServer == false) {
return;
}
if(activeInputLabel!=NULL && !(activeInputLabel->mouseClick(x,y))){
if(activeInputLabel != NULL && activeInputLabel->mouseClick(x,y) == false){
setActiveInputLabel(NULL);
}
@ -1608,8 +1609,21 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
PlayNow(true);
return;
uint32 tilesetCRC = lastCheckedCRCTilesetValue;
uint32 techCRC = lastCheckedCRCTechtreeValue;
uint32 mapCRC = lastCheckedCRCMapValue;
const GameSettings *gameSettings = clientInterface->getGameSettings();
bool dataSynchMismatch = ((mapCRC != 0 && mapCRC != gameSettings->getMapCRC()) ||
(tilesetCRC != 0 && tilesetCRC != gameSettings->getTilesetCRC()) ||
(techCRC != 0 && techCRC != gameSettings->getTechCRC()));
if(dataSynchMismatch == false) {
PlayNow(true);
return;
}
else {
showMessageBox("You cannot start the game because\none or more clients do not have the same game data!", "Data Mismatch Error", false);
}
}
}
}
@ -1891,11 +1905,13 @@ void MenuStateConnectedGame::PlayNow(bool saveGame) {
clientInterface->sendTextMessage(szMsg,-1, localEcho,languageList[i]);
}
launchingNewGame = true;
clientInterface->broadcastGameStart(&gameSettings);
}
return;
}
else {
launchingNewGame = true;
broadCastGameSettingsToHeadlessServer(needToBroadcastServerSettings);
clientInterface->broadcastGameStart(&gameSettings);
}

View File

@ -71,6 +71,7 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
gameSettingsUpdateCount = 0;
currentFrameCount = 0;
gameStartTime = 0;
resumeGameStartTime = 0;
publishToMasterserverThread = NULL;
lastMasterserverHeartbeatTime = 0;
needToRepublishToMasterserver = false;
@ -633,8 +634,11 @@ std::pair<bool,bool> ServerInterface::clientLagCheck(ConnectionSlot *connectionS
try {
alreadyInLagCheck = true;
if(gameStartTime > 0 &&
difftime((long int)time(NULL),gameStartTime) >= LAG_CHECK_GRACE_PERIOD) {
if((gameStartTime > 0 &&
difftime((long int)time(NULL),gameStartTime) >= LAG_CHECK_GRACE_PERIOD) &&
(resumeGameStartTime == 0 ||
(resumeGameStartTime > 0 &&
difftime((long int)time(NULL),resumeGameStartTime) >= LAG_CHECK_GRACE_PERIOD))) {
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
double clientLag = this->getCurrentFrameCount() - connectionSlot->getCurrentFrameCount();
double clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0);
@ -2958,17 +2962,32 @@ bool ServerInterface::getPauseForInGameConnection() {
}
bool ServerInterface::getUnPauseForInGameConnection() {
bool allResumeClientsReady = false;
bool result = false;
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
if(slots[i] != NULL) {
MutexSafeWrapper safeMutex(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ConnectionSlot *slot = slots[i];
if(slot->getUnPauseForInGameConnection() == true) {
result = true;
break;
if(slot->isConnected() == true) {
if(slot->isReady() == true) {
result = true;
if(slot->getUnPauseForInGameConnection() == false) {
result = false;
break;
}
}
else {
result = false;
break;
}
}
}
}
if(allResumeClientsReady == true) {
resumeGameStartTime = time(NULL);
result = true;
}
return result;
}

View File

@ -101,6 +101,8 @@ private:
bool gameLaunched;
time_t lastListenerSlotCheckTime;
time_t resumeGameStartTime;
public:
ServerInterface(bool publishEnabled);
virtual ~ServerInterface();