- updates to join in progress game, and now allow for switching slots

This commit is contained in:
Mark Vejvoda 2013-02-16 19:11:36 +00:00
parent b38f6b20a1
commit 45dc4c0e5d
7 changed files with 61 additions and 32 deletions

View File

@ -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());

View File

@ -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;

View File

@ -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";

View File

@ -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<int,string>(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<int,string>(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);

View File

@ -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__);

View File

@ -254,6 +254,7 @@ private:
int64 getNextEventId();
void processTextMessageQueue();
void processBroadCastMessageQueue();
void checkListenerSlots();
protected:
void signalClientsToRecieveData(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList, std::map<int,ConnectionSlotEvent> & eventList, std::map<int,bool> & mapSlotSignalledList);

View File

@ -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<string,string> fileName) {
pair<FTP_Client_ResultType,string> FTPClientThread::getTempFileInternalFromServer(pair<string,string> 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<FTP_Client_ResultType,string> result = getFileFromServer(ftp_cct_TempFile,
fileName,remotePath, destFileSaveAs, FTP_TEMPFILES_USERNAME, FTP_COMMON_PASSWORD);
@ -950,6 +956,8 @@ pair<FTP_Client_ResultType,string> 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);