diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index d9739ad1..9157e2e1 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -5201,7 +5201,7 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange) { if(saveNetworkGame == true) { //printf("Saved network game to disk\n"); - string file = this->saveGame(GameConstants::saveGameFileDefault,"temp/"); + string file = this->saveGame(GameConstants::saveNetworkGameFileServer,"temp/"); char szBuf[8096]=""; Lang &lang= Lang::getInstance(); snprintf(szBuf,8096,lang.get("GameSaved","",true).c_str(),file.c_str()); diff --git a/source/glest_game/game/game_constants.h b/source/glest_game/game/game_constants.h index 5d23cef9..8b5345d9 100644 --- a/source/glest_game/game/game_constants.h +++ b/source/glest_game/game/game_constants.h @@ -163,6 +163,8 @@ public: static const char *application_name; + static const char *saveNetworkGameFileServer; + static const char *saveNetworkGameFileClient; static const char *saveGameFileDefault; static const char *saveGameFileAutoTestDefault; static const char *saveGameFilePattern; diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index e743d7bb..d977fe29 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -69,6 +69,8 @@ const char *GameConstants::path_data_CacheLookupKey = "data"; const char *GameConstants::path_ini_CacheLookupKey = "ini"; const char *GameConstants::path_logs_CacheLookupKey = "logs"; +const char *GameConstants::saveNetworkGameFileServer = "megaglest-saved-server.xml"; +const char *GameConstants::saveNetworkGameFileClient = "megaglest-saved-client.xml"; const char *GameConstants::saveGameFileDefault = "megaglest-saved.xml"; const char *GameConstants::saveGameFileAutoTestDefault = "megaglest-auto-saved_%s.xml"; const char *GameConstants::saveGameFilePattern = "megaglest-saved_%s.xml"; diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 1b9e18b7..655fcf6f 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -1887,20 +1887,7 @@ void MenuStateConnectedGame::PlayNow(bool saveGame) { clientInterface->sendTextMessage(szMsg,-1, localEcho,languageList[i]); } -// string saveGameFile = "temp/" + string(GameConstants::saveGameFileDefault); -// if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") { -// saveGameFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + saveGameFile; -// } -// else { -// string userData = Config::getInstance().getString("UserData_Root",""); -// if(userData != "") { -// endPathWithSlash(userData); -// } -// saveGameFile = userData + saveGameFile; -// } - clientInterface->broadcastGameStart(&gameSettings); - //Game::loadGame(saveGameFile,program,false,&gameSettings); return; } else { @@ -3209,17 +3196,6 @@ void MenuStateConnectedGame::update() { //printf("Menu got new settings thisfactionindex = %d startlocation: %d control = %d\n",gameSettings->getThisFactionIndex(),clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()),gameSettings->getFactionControl(clientInterface->getGameSettings()->getThisFactionIndex())); setupUIFromGameSettings(gameSettings, errorOnMissingData); - -// // check if we are joining an in progress game -// if(clientInterface->getJoinGameInProgress() == true && -// clientInterface->getReadyForInGameJoin() == true && -// ftpClientThread != NULL) { -// -// if(ftpClientThread != NULL) ftpClientThread->addTempFileToRequests(GameConstants::saveGameFileDefault); -// MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); -// fileFTPProgressList[getInProgressSavedGameFromFTPServer] = pair(0,""); -// safeMutexFTPProgress.ReleaseLock(); -// } } // check if we are joining an in progress game @@ -3230,9 +3206,11 @@ void MenuStateConnectedGame::update() { MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); if(readyToJoinInProgressGame == false) { if(getInProgressSavedGameFromFTPServer == "") { - ftpClientThread->addTempFileToRequests(GameConstants::saveGameFileDefault); + //printf("Requesting saved game file\n"); - getInProgressSavedGameFromFTPServer = GameConstants::saveGameFileDefault; + ftpClientThread->addTempFileToRequests(GameConstants::saveNetworkGameFileClient,GameConstants::saveNetworkGameFileServer); + + getInProgressSavedGameFromFTPServer = GameConstants::saveNetworkGameFileClient; fileFTPProgressList[getInProgressSavedGameFromFTPServer] = pair(0,""); } safeMutexFTPProgress.ReleaseLock(); @@ -3240,7 +3218,7 @@ void MenuStateConnectedGame::update() { else { safeMutexFTPProgress.ReleaseLock(); - string saveGameFile = "temp/" + string(GameConstants::saveGameFileDefault); + string saveGameFile = "temp/" + string(GameConstants::saveNetworkGameFileClient); if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") { saveGameFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + saveGameFile; } @@ -3252,6 +3230,8 @@ void MenuStateConnectedGame::update() { saveGameFile = userData + saveGameFile; } + //printf("Loading saved game file [%s]\n",saveGameFile.c_str()); + //clientInterface->broadcastGameStart(&gameSettings); GameSettings gameSettings = *clientInterface->getGameSettings(); loadGameSettings(&gameSettings); @@ -4168,6 +4148,8 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, fileFTPProgressList.erase(itemName); safeMutexFTPProgress.ReleaseLock(); + //printf("Status update downloading saved game file: [%s]\n",itemName.c_str()); + NetworkManager &networkManager= NetworkManager::getInstance(); ClientInterface* clientInterface= networkManager.getClientInterface(); const GameSettings *gameSettings = clientInterface->getGameSettings(); @@ -4187,6 +4169,8 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, } readyToJoinInProgressGame = true; + + //printf("Success downloading saved game file: [%s]\n",itemName.c_str()); } else { curl_version_info_data *curlVersion= curl_version_info(CURLVERSION_NOW); diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index c0668462..1e0b0c8c 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -1558,6 +1558,8 @@ void ServerInterface::update() { } } //printf("\nServerInterface::update -- G\n"); + + checkListenerSlots(); } catch(const exception &ex) { //printf("\nServerInterface::update -- H\n"); @@ -2188,9 +2190,11 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) { if(connectionSlot != NULL && connectionSlot->isConnected()) { connectionSlot->getSocket()->setBlock(true); } - // Open slots for joining in progress game - else if(gameSettings->getFactionControl(factionIndex) != ctClosed && gameSettings->getFactionControl(factionIndex) != ctHuman) { - if(allowInGameConnections == true) { + else if(allowInGameConnections == true) { + // Open slots for joining in progress game + if(gameSettings->getFactionControl(factionIndex) != ctClosed && + gameSettings->getFactionControl(factionIndex) != ctHuman) { + //printf("Opening slot for in game connections for slot: %d, faction: %d\n",i,factionIndex); if(connectionSlot == NULL) { addSlot(i); @@ -2257,6 +2261,34 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) { return bOkToStart; } +void ServerInterface::checkListenerSlots() { + if(allowInGameConnections == true) { + bool useInGameBlockingClientSockets = Config::getInstance().getBool("EnableInGameBlockingSockets","true"); + + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + for(int i= 0; i < GameConstants::maxPlayers; ++i) { + int factionIndex = gameSettings.getFactionIndexForStartLocation(i); + MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); + ConnectionSlot *connectionSlot= slots[i]; + // Open slots for joining in progress game + if(connectionSlot == NULL && + gameSettings.getFactionControl(factionIndex) != ctClosed && + gameSettings.getFactionControl(factionIndex) != ctHuman) { + //printf("Opening slot for in game connections for slot: %d, faction: %d\n",i,factionIndex); + if(connectionSlot == NULL) { + addSlot(i); + connectionSlot = slots[i]; + if(useInGameBlockingClientSockets == true) { + connectionSlot->getSocket()->setBlock(true); + } + } + connectionSlot->setCanAcceptConnections(true); + } + } + } + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,needToRepublishToMasterserver); +} + void ServerInterface::broadcastGameSetup(GameSettings *gameSettingsBuffer, bool setGameSettingsBuffer) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index 87972155..618a1b14 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -254,6 +254,7 @@ private: int64 getNextEventId(); void processTextMessageQueue(); void processBroadCastMessageQueue(); + void checkListenerSlots(); protected: void signalClientsToRecieveData(std::map & socketTriggeredList, std::map & eventList, std::map & mapSlotSignalledList); diff --git a/source/shared_lib/sources/platform/posix/miniftpclient.cpp b/source/shared_lib/sources/platform/posix/miniftpclient.cpp index 260d04d2..f7c03246 100644 --- a/source/shared_lib/sources/platform/posix/miniftpclient.cpp +++ b/source/shared_lib/sources/platform/posix/miniftpclient.cpp @@ -66,6 +66,7 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) { } if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread writing to file [%s]\n",fullFilePath.c_str()); + //printf ("===> FTP Client thread writing to file [%s]\n",fullFilePath.c_str()); // Abort file xfer and delete partial file if(out && out->ftpServer && out->ftpServer->getQuitStatus() == true) { @@ -878,9 +879,14 @@ void FTPClientThread::getTempFileFromServer(pair fileName) { pair FTPClientThread::getTempFileInternalFromServer(pair fileName) { string destFile = fileName.first; - string destFileSaveAs = fileName.first; + //string destFileSaveAs = fileName.first; + string destFileSaveAs = tempFilesPath; + + endPathWithSlash(destFileSaveAs); + destFileSaveAs += fileName.first; string remotePath = fileName.second; + fileName.second = ""; pair result = getFileFromServer(ftp_cct_TempFile, fileName,remotePath, destFileSaveAs, FTP_TEMPFILES_USERNAME, FTP_COMMON_PASSWORD); @@ -950,6 +956,8 @@ pair FTPClientThread::getFileFromServer(FTP_Clien snprintf(szBuf,8096,"ftp://%s:%s@%s:%d/%s",ftpUser.c_str(),ftpUserPassword.c_str(),serverUrl.c_str(),portNumber,remotePath.c_str()); } + //printf("===> Getting ftp file: %s\n",szBuf); + curl_easy_setopt(curl, CURLOPT_URL,szBuf); curl_easy_setopt(curl, CURLOPT_FTP_USE_EPSV, 0L);