mirror of
https://github.com/glest/glest-source.git
synced 2025-08-17 21:51:17 +02:00
- some code cleanup and try to improve joining in progress game performance
This commit is contained in:
@@ -1949,18 +1949,27 @@ void Game::update() {
|
|||||||
//printf("#2 Data synch: lmap %u ltile: %d ltech: %u\n",server->gameSettings.getMapCRC(),server->gameSettings.getTilesetCRC(),server->gameSettings.getTechCRC());
|
//printf("#2 Data synch: lmap %u ltile: %d ltech: %u\n",server->gameSettings.getMapCRC(),server->gameSettings.getTilesetCRC(),server->gameSettings.getTechCRC());
|
||||||
server->broadcastGameSetup(&server->gameSettings,true);
|
server->broadcastGameSetup(&server->gameSettings,true);
|
||||||
|
|
||||||
server->setPauseForInGameConnection(false);
|
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||||
|
Faction *faction = world.getFaction(i);
|
||||||
|
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||||
|
if(slot != NULL && slot->getPauseForInGameConnection() == true) {
|
||||||
|
slot->setPauseForInGameConnection(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(server->getStartInGameConnectionLaunch() == true) {
|
else if(server->getStartInGameConnectionLaunch() == true) {
|
||||||
//printf("^^^ getStartInGameConnectionLaunch triggered!\n");
|
//printf("^^^ getStartInGameConnectionLaunch triggered!\n");
|
||||||
|
|
||||||
server->setStartInGameConnectionLaunch(false);
|
//server->setStartInGameConnectionLaunch(false);
|
||||||
|
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
bool pauseAndSaveGameForNewClient = false;
|
bool pauseAndSaveGameForNewClient = false;
|
||||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||||
Faction *faction = world.getFaction(i);
|
Faction *faction = world.getFaction(i);
|
||||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||||
|
if(slot != NULL && slot->getStartInGameConnectionLaunch() == true) {
|
||||||
|
slot->setStartInGameConnectionLaunch(false);
|
||||||
|
}
|
||||||
if(slot != NULL && slot->getJoinGameInProgress() == true) {
|
if(slot != NULL && slot->getJoinGameInProgress() == true) {
|
||||||
//printf("$$$ signalling client to start game [deleting AI player] factionIndex: %d slot: %d startlocation: %d!\n",i,slot->getPlayerIndex(),faction->getStartLocationIndex());
|
//printf("$$$ signalling client to start game [deleting AI player] factionIndex: %d slot: %d startlocation: %d!\n",i,slot->getPlayerIndex(),faction->getStartLocationIndex());
|
||||||
|
|
||||||
@@ -1996,47 +2005,47 @@ void Game::update() {
|
|||||||
else if(paused == true && pauseStateChanged == true) {
|
else if(paused == true && pauseStateChanged == true) {
|
||||||
pauseStateChanged = false;
|
pauseStateChanged = false;
|
||||||
|
|
||||||
//NetworkManager &networkManager= NetworkManager::getInstance();
|
bool saveNetworkGame = false;
|
||||||
//NetworkRole role = networkManager.getNetworkRole();
|
|
||||||
|
|
||||||
//if(role == nrServer) {
|
ServerInterface *server = NetworkManager::getInstance().getServerInterface();
|
||||||
bool saveNetworkGame = false;
|
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||||
|
Faction *faction = world.getFaction(i);
|
||||||
|
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||||
|
if(slot != NULL && slot->getJoinGameInProgress() == true) {
|
||||||
|
saveNetworkGame = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(saveNetworkGame == true) {
|
||||||
|
//printf("Saved network game to disk\n");
|
||||||
|
|
||||||
|
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());
|
||||||
|
console.addLine(szBuf);
|
||||||
|
|
||||||
ServerInterface *server = NetworkManager::getInstance().getServerInterface();
|
|
||||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||||
Faction *faction = world.getFaction(i);
|
Faction *faction = world.getFaction(i);
|
||||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||||
if(slot != NULL && slot->getJoinGameInProgress() == true) {
|
if(slot != NULL && slot->getJoinGameInProgress() == true) {
|
||||||
saveNetworkGame = true;
|
NetworkMessageReady networkMessageReady(0);
|
||||||
break;
|
slot->sendMessage(&networkMessageReady);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(saveNetworkGame == true) {
|
|
||||||
//printf("Saved network game to disk\n");
|
|
||||||
|
|
||||||
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());
|
|
||||||
console.addLine(szBuf);
|
|
||||||
|
|
||||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
|
||||||
Faction *faction = world.getFaction(i);
|
|
||||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
|
||||||
if(slot != NULL && slot->getJoinGameInProgress() == true) {
|
|
||||||
|
|
||||||
NetworkMessageReady networkMessageReady(0);
|
|
||||||
slot->sendMessage(&networkMessageReady);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
else if(server->getUnPauseForInGameConnection() == true && paused == true) {
|
else if(server->getUnPauseForInGameConnection() == true && paused == true) {
|
||||||
//printf("^^^ getUnPauseForInGameConnection triggered!\n");
|
//printf("^^^ getUnPauseForInGameConnection triggered!\n");
|
||||||
|
|
||||||
server->setUnPauseForInGameConnection(false);
|
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||||
|
Faction *faction = world.getFaction(i);
|
||||||
|
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||||
|
if(slot != NULL && slot->getUnPauseForInGameConnection() == true) {
|
||||||
|
slot->setUnPauseForInGameConnection(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
commander.tryResumeGame(false);
|
commander.tryResumeGame(false);
|
||||||
//return;
|
//return;
|
||||||
}
|
}
|
||||||
|
@@ -272,6 +272,7 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex
|
|||||||
this->lastReceiveCommandListTime = 0;
|
this->lastReceiveCommandListTime = 0;
|
||||||
this->receivedNetworkGameStatus = false;
|
this->receivedNetworkGameStatus = false;
|
||||||
this->canAcceptConnections = true;
|
this->canAcceptConnections = true;
|
||||||
|
this->startInGameConnectionLaunch = false;
|
||||||
this->skipLagCheck = false;
|
this->skipLagCheck = false;
|
||||||
this->joinGameInProgress = false;
|
this->joinGameInProgress = false;
|
||||||
|
|
||||||
@@ -861,7 +862,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
|||||||
//this->skipLagCheck = true;
|
//this->skipLagCheck = true;
|
||||||
//this->joinGameInProgress = true;
|
//this->joinGameInProgress = true;
|
||||||
setJoinGameInProgressFlags();
|
setJoinGameInProgressFlags();
|
||||||
serverInterface->setPauseForInGameConnection(true);
|
this->setPauseForInGameConnection(true);
|
||||||
|
|
||||||
//printf("Got intro from client sending game settings..\n");
|
//printf("Got intro from client sending game settings..\n");
|
||||||
}
|
}
|
||||||
@@ -962,7 +963,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
|||||||
this->serverInterface->gameSettings.setNetworkPlayerName(factionIndex,this->name);
|
this->serverInterface->gameSettings.setNetworkPlayerName(factionIndex,this->name);
|
||||||
this->serverInterface->broadcastGameSetup(&this->serverInterface->gameSettings, true);
|
this->serverInterface->broadcastGameSetup(&this->serverInterface->gameSettings, true);
|
||||||
|
|
||||||
this->serverInterface->setStartInGameConnectionLaunch(true);
|
this->setStartInGameConnectionLaunch(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1241,7 +1242,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
|||||||
}
|
}
|
||||||
// unpause the game
|
// unpause the game
|
||||||
else {
|
else {
|
||||||
serverInterface->setUnPauseForInGameConnection(true);
|
this->setUnPauseForInGameConnection(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -141,11 +141,23 @@ private:
|
|||||||
string playerLanguage;
|
string playerLanguage;
|
||||||
|
|
||||||
bool canAcceptConnections;
|
bool canAcceptConnections;
|
||||||
|
bool startInGameConnectionLaunch;
|
||||||
|
bool pauseForInGameConnection;
|
||||||
|
bool unPauseForInGameConnection;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ConnectionSlot(ServerInterface* serverInterface, int playerIndex);
|
ConnectionSlot(ServerInterface* serverInterface, int playerIndex);
|
||||||
~ConnectionSlot();
|
~ConnectionSlot();
|
||||||
|
|
||||||
|
bool getStartInGameConnectionLaunch() const { return startInGameConnectionLaunch; }
|
||||||
|
void setStartInGameConnectionLaunch(bool value) { startInGameConnectionLaunch = value; }
|
||||||
|
|
||||||
|
bool getPauseForInGameConnection() const { return pauseForInGameConnection; }
|
||||||
|
void setPauseForInGameConnection(bool value) { pauseForInGameConnection = value; }
|
||||||
|
|
||||||
|
bool getUnPauseForInGameConnection() const { return unPauseForInGameConnection; }
|
||||||
|
void setUnPauseForInGameConnection(bool value) { unPauseForInGameConnection = value; }
|
||||||
|
|
||||||
bool getSkipLagCheck() const { return skipLagCheck; }
|
bool getSkipLagCheck() const { return skipLagCheck; }
|
||||||
bool getJoinGameInProgress() const { return joinGameInProgress; }
|
bool getJoinGameInProgress() const { return joinGameInProgress; }
|
||||||
|
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
#include "server_interface.h"
|
#include "server_interface.h"
|
||||||
|
|
||||||
//#include <cassert>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "platform_util.h"
|
#include "platform_util.h"
|
||||||
@@ -52,9 +51,7 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
|
|||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
allowInGameConnections = false;
|
allowInGameConnections = false;
|
||||||
pauseForInGameConnection = false;
|
gameLaunched = false;
|
||||||
unPauseForInGameConnection = false;
|
|
||||||
gameStarted = false;
|
|
||||||
|
|
||||||
serverSynchAccessor = new Mutex();
|
serverSynchAccessor = new Mutex();
|
||||||
switchSetupRequestsSynchAccessor = new Mutex();
|
switchSetupRequestsSynchAccessor = new Mutex();
|
||||||
@@ -81,7 +78,6 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
|
|||||||
inBroadcastMessage = false;
|
inBroadcastMessage = false;
|
||||||
lastGlobalLagCheckTime = 0;
|
lastGlobalLagCheckTime = 0;
|
||||||
masterserverAdminRequestLaunch = false;
|
masterserverAdminRequestLaunch = false;
|
||||||
startInGameConnectionLaunch = false;
|
|
||||||
|
|
||||||
// This is an admin port listening only on the localhost intended to
|
// This is an admin port listening only on the localhost intended to
|
||||||
// give current connection status info
|
// give current connection status info
|
||||||
@@ -120,23 +116,6 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
|
|||||||
serverSocket.setBindPort(Config::getInstance().getInt("PortServer", intToStr(GameConstants::serverPort).c_str()));
|
serverSocket.setBindPort(Config::getInstance().getInt("PortServer", intToStr(GameConstants::serverPort).c_str()));
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
/*
|
|
||||||
Config &config = Config::getInstance();
|
|
||||||
vector<string> results;
|
|
||||||
set<string> allMaps;
|
|
||||||
findAll(config.getPathListForType(ptMaps), "*.gbm", results, true, false);
|
|
||||||
copy(results.begin(), results.end(), std::inserter(allMaps, allMaps.begin()));
|
|
||||||
results.clear();
|
|
||||||
findAll(config.getPathListForType(ptMaps), "*.mgm", results, true, false);
|
|
||||||
copy(results.begin(), results.end(), std::inserter(allMaps, allMaps.begin()));
|
|
||||||
results.clear();
|
|
||||||
if (allMaps.empty()) {
|
|
||||||
throw megaglest_runtime_error("No maps were found!");
|
|
||||||
}
|
|
||||||
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
|
|
||||||
mapFiles = results;
|
|
||||||
*/
|
|
||||||
|
|
||||||
Config &config = Config::getInstance();
|
Config &config = Config::getInstance();
|
||||||
vector<string> results;
|
vector<string> results;
|
||||||
string scenarioDir = "";
|
string scenarioDir = "";
|
||||||
@@ -151,8 +130,6 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
|
|||||||
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
|
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
|
||||||
mapFiles = results;
|
mapFiles = results;
|
||||||
|
|
||||||
|
|
||||||
//tileset listBox
|
|
||||||
results.clear();
|
results.clear();
|
||||||
findDirs(config.getPathListForType(ptTilesets), results);
|
findDirs(config.getPathListForType(ptTilesets), results);
|
||||||
if (results.empty()) {
|
if (results.empty()) {
|
||||||
@@ -160,7 +137,6 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
|
|||||||
}
|
}
|
||||||
tilesetFiles= results;
|
tilesetFiles= results;
|
||||||
|
|
||||||
//tech Tree listBox
|
|
||||||
results.clear();
|
results.clear();
|
||||||
findDirs(config.getPathListForType(ptTechs), results);
|
findDirs(config.getPathListForType(ptTechs), results);
|
||||||
if(results.empty()) {
|
if(results.empty()) {
|
||||||
@@ -569,14 +545,9 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) {
|
|||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
||||||
if(notifyDisconnect == true) {
|
if(notifyDisconnect == true) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
||||||
//string sMsg = szBuf;
|
|
||||||
//sendTextMessage(sMsg,-1, true, lockedSlotIndex);
|
|
||||||
//const vector<string> languageList = this->gameSettings.getUniqueNetworkPlayerLanguages();
|
|
||||||
for(unsigned int j = 0; j < languageList.size(); ++j) {
|
for(unsigned int j = 0; j < languageList.size(); ++j) {
|
||||||
bool localEcho = lang.isLanguageLocal(languageList[j]);
|
bool localEcho = lang.isLanguageLocal(languageList[j]);
|
||||||
queueTextMessage(msgList[j],-1, localEcho, languageList[j]);
|
queueTextMessage(msgList[j],-1, localEcho, languageList[j]);
|
||||||
|
|
||||||
//printf("j = %d [%s] localEcho = %d [%s]\n",j,msgList[j].c_str(),localEcho,languageList[j].c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
||||||
@@ -641,86 +612,6 @@ int64 ServerInterface::getNextEventId() {
|
|||||||
return nextEventId;
|
return nextEventId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::slotUpdateTask(ConnectionSlotEvent *event) {
|
|
||||||
// if(event != NULL) {
|
|
||||||
// if(event->eventType == eSendSocketData) {
|
|
||||||
// if(event->connectionSlot != NULL) {
|
|
||||||
// event->connectionSlot->sendMessage(event->networkMessage);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else if(event->eventType == eReceiveSocketData) {
|
|
||||||
// //updateSlot(event);
|
|
||||||
// if(event->connectionSlot != NULL) {
|
|
||||||
// event->connectionSlot->updateSlot(event);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
//void ServerInterface::updateSlot(ConnectionSlotEvent *event) {
|
|
||||||
// Chrono chrono;
|
|
||||||
// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
|
|
||||||
//
|
|
||||||
// if(event != NULL) {
|
|
||||||
// bool &socketTriggered = event->socketTriggered;
|
|
||||||
// bool checkForNewClients = true;
|
|
||||||
//
|
|
||||||
// // Safety check since we can experience a disconnect and the slot is NULL
|
|
||||||
// ConnectionSlot *connectionSlot = NULL;
|
|
||||||
// MutexSafeWrapper safeMutexSlot(NULL);
|
|
||||||
// if(event->triggerId >= 0 && event->triggerId < GameConstants::maxPlayers) {
|
|
||||||
//
|
|
||||||
// //printf("===> START slot %d [%d][%p] - About to updateSlot\n",event->triggerId,event->eventId,slots[event->triggerId]);
|
|
||||||
//
|
|
||||||
// safeMutexSlot.setMutex(slotAccessorMutexes[event->triggerId],CODE_AT_LINE_X(event->triggerId));
|
|
||||||
// connectionSlot = slots[event->triggerId];
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR CONDITION, event->triggerId = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,event->triggerId);
|
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] ERROR CONDITION, event->triggerId = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,event->triggerId);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
|
|
||||||
//
|
|
||||||
// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
|
||||||
//
|
|
||||||
// if(connectionSlot != NULL &&
|
|
||||||
// (gameHasBeenInitiated == false ||
|
|
||||||
// (connectionSlot->getSocket() != NULL && socketTriggered == true))) {
|
|
||||||
// if(connectionSlot->isConnected() == false || socketTriggered == true) {
|
|
||||||
// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
|
||||||
//
|
|
||||||
// //safeMutexSlot.ReleaseLock(true);
|
|
||||||
// connectionSlot->update(checkForNewClients,event->triggerId);
|
|
||||||
//
|
|
||||||
// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
|
|
||||||
//
|
|
||||||
// //chrono.start();
|
|
||||||
// //safeMutexSlot.Lock();
|
|
||||||
// //connectionSlot = slots[event->triggerId];
|
|
||||||
//
|
|
||||||
// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
|
||||||
//
|
|
||||||
// // This means no clients are trying to connect at the moment
|
|
||||||
// if(connectionSlot != NULL && connectionSlot->getSocket() == NULL) {
|
|
||||||
// checkForNewClients = false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
|
||||||
// }
|
|
||||||
// safeMutexSlot.ReleaseLock();
|
|
||||||
//
|
|
||||||
// if(event->triggerId >= 0 && event->triggerId < GameConstants::maxPlayers) {
|
|
||||||
// //printf("===> END slot %d - About to updateSlot\n",event->triggerId);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
|
||||||
// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
|
|
||||||
//}
|
|
||||||
|
|
||||||
std::pair<bool,bool> ServerInterface::clientLagCheck(ConnectionSlot *connectionSlot, bool skipNetworkBroadCast) {
|
std::pair<bool,bool> ServerInterface::clientLagCheck(ConnectionSlot *connectionSlot, bool skipNetworkBroadCast) {
|
||||||
Chrono chrono;
|
Chrono chrono;
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
|
||||||
@@ -728,16 +619,6 @@ std::pair<bool,bool> ServerInterface::clientLagCheck(ConnectionSlot *connectionS
|
|||||||
std::pair<bool,bool> clientLagExceededOrWarned = std::make_pair(false, false);
|
std::pair<bool,bool> clientLagExceededOrWarned = std::make_pair(false, false);
|
||||||
static bool alreadyInLagCheck = false;
|
static bool alreadyInLagCheck = false;
|
||||||
|
|
||||||
// {
|
|
||||||
// if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
|
||||||
// double clientLag = this->getCurrentFrameCount() - connectionSlot->getCurrentFrameCount();
|
|
||||||
// double clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0);
|
|
||||||
// double clientLagTime = difftime(time(NULL),connectionSlot->getLastReceiveCommandListTime());
|
|
||||||
//
|
|
||||||
// printf("\n\nmaxClientLagTimeAllowedEver [%f] - [%f] alreadyInLagCheck = %d\n\n",maxClientLagTimeAllowedEver,clientLagTime,alreadyInLagCheck);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if(alreadyInLagCheck == true ||
|
if(alreadyInLagCheck == true ||
|
||||||
(connectionSlot != NULL && (connectionSlot->getSkipLagCheck() == true ||
|
(connectionSlot != NULL && (connectionSlot->getSkipLagCheck() == true ||
|
||||||
connectionSlot->getConnectHasHandshaked() == false))) {
|
connectionSlot->getConnectHasHandshaked() == false))) {
|
||||||
@@ -1067,6 +948,7 @@ void ServerInterface::checkForCompletedClients(std::map<int,bool> & mapSlotSigna
|
|||||||
|
|
||||||
ConnectionSlot* connectionSlot = slots[i];
|
ConnectionSlot* connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL && mapSlotSignalledList[i] == true &&
|
if(connectionSlot != NULL && mapSlotSignalledList[i] == true &&
|
||||||
|
connectionSlot->getJoinGameInProgress() == false &&
|
||||||
slotsCompleted.find(i) == slotsCompleted.end()) {
|
slotsCompleted.find(i) == slotsCompleted.end()) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -2258,14 +2140,14 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gameStarted = true;
|
gameLaunched = true;
|
||||||
}
|
}
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
return bOkToStart;
|
return bOkToStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::checkListenerSlots() {
|
void ServerInterface::checkListenerSlots() {
|
||||||
if(gameStarted == true && allowInGameConnections == true) {
|
if(gameLaunched == true && allowInGameConnections == true) {
|
||||||
bool useInGameBlockingClientSockets = Config::getInstance().getBool("EnableInGameBlockingSockets","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__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
@@ -2277,16 +2159,22 @@ void ServerInterface::checkListenerSlots() {
|
|||||||
if(connectionSlot == NULL &&
|
if(connectionSlot == NULL &&
|
||||||
gameSettings.getFactionControl(factionIndex) != ctClosed &&
|
gameSettings.getFactionControl(factionIndex) != ctClosed &&
|
||||||
gameSettings.getFactionControl(factionIndex) != ctHuman) {
|
gameSettings.getFactionControl(factionIndex) != ctHuman) {
|
||||||
//printf("Opening slot for in game connections for slot: %d, faction: %d\n",i,factionIndex);
|
printf("Opening slot for in game connections, slot: %d, factionindex: %d name: %s\n",i,factionIndex,gameSettings.getFactionTypeName(factionIndex).c_str());
|
||||||
if(connectionSlot == NULL) {
|
|
||||||
addSlot(i);
|
addSlot(i);
|
||||||
connectionSlot = slots[i];
|
connectionSlot = slots[i];
|
||||||
if(useInGameBlockingClientSockets == true) {
|
if(useInGameBlockingClientSockets == true) {
|
||||||
connectionSlot->getSocket()->setBlock(true);
|
connectionSlot->getSocket()->setBlock(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
connectionSlot->setCanAcceptConnections(true);
|
connectionSlot->setCanAcceptConnections(true);
|
||||||
}
|
}
|
||||||
|
else if(connectionSlot != NULL &&
|
||||||
|
connectionSlot->getCanAcceptConnections() == false &&
|
||||||
|
connectionSlot->isConnected() == false &&
|
||||||
|
gameSettings.getFactionControl(factionIndex) != ctClosed &&
|
||||||
|
gameSettings.getFactionControl(factionIndex) != ctHuman) {
|
||||||
|
this->removeSlot(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
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);
|
||||||
@@ -2868,7 +2756,6 @@ std::string ServerInterface::DumpStatsToLog(bool dumpToStringOnly) const {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ServerInterface::notifyBadClientConnectAttempt(string ipAddress) {
|
void ServerInterface::notifyBadClientConnectAttempt(string ipAddress) {
|
||||||
//printf("In [%s::%s Line: %d] ipAddress [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ipAddress.c_str());
|
//printf("In [%s::%s Line: %d] ipAddress [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ipAddress.c_str());
|
||||||
|
|
||||||
@@ -2914,6 +2801,51 @@ void ServerInterface::notifyBadClientConnectAttempt(string ipAddress) {
|
|||||||
//printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
//printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ServerInterface::getStartInGameConnectionLaunch() {
|
||||||
|
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->getStartInGameConnectionLaunch() == true) {
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServerInterface::getPauseForInGameConnection() {
|
||||||
|
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->getPauseForInGameConnection() == true) {
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServerInterface::getUnPauseForInGameConnection() {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void ServerInterface::saveGame(XmlNode *rootNode) {
|
void ServerInterface::saveGame(XmlNode *rootNode) {
|
||||||
std::map<string,string> mapTagReplacements;
|
std::map<string,string> mapTagReplacements;
|
||||||
XmlNode *serverInterfaceNode = rootNode->addChild("ServerInterface");
|
XmlNode *serverInterfaceNode = rootNode->addChild("ServerInterface");
|
||||||
|
@@ -29,8 +29,6 @@ using Shared::Platform::ServerSocket;
|
|||||||
|
|
||||||
namespace Shared { namespace PlatformCommon { class FTPServerThread; }}
|
namespace Shared { namespace PlatformCommon { class FTPServerThread; }}
|
||||||
|
|
||||||
//using Shared::PlatformCommon::FTPServerThread;
|
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -56,8 +54,6 @@ private:
|
|||||||
Mutex *slotAccessorMutexes[GameConstants::maxPlayers];
|
Mutex *slotAccessorMutexes[GameConstants::maxPlayers];
|
||||||
|
|
||||||
ServerSocket serverSocket;
|
ServerSocket serverSocket;
|
||||||
bool gameHasBeenInitiated;
|
|
||||||
int gameSettingsUpdateCount;
|
|
||||||
|
|
||||||
Mutex *switchSetupRequestsSynchAccessor;
|
Mutex *switchSetupRequestsSynchAccessor;
|
||||||
SwitchSetupRequest* switchSetupRequests[GameConstants::maxPlayers];
|
SwitchSetupRequest* switchSetupRequests[GameConstants::maxPlayers];
|
||||||
@@ -98,11 +94,11 @@ private:
|
|||||||
ServerSocket *serverSocketAdmin;
|
ServerSocket *serverSocketAdmin;
|
||||||
MasterSlaveThreadController masterController;
|
MasterSlaveThreadController masterController;
|
||||||
|
|
||||||
|
bool gameHasBeenInitiated;
|
||||||
|
int gameSettingsUpdateCount;
|
||||||
|
|
||||||
bool allowInGameConnections;
|
bool allowInGameConnections;
|
||||||
bool pauseForInGameConnection;
|
bool gameLaunched;
|
||||||
bool startInGameConnectionLaunch;
|
|
||||||
bool unPauseForInGameConnection;
|
|
||||||
bool gameStarted;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ServerInterface(bool publishEnabled);
|
ServerInterface(bool publishEnabled);
|
||||||
@@ -110,23 +106,14 @@ public:
|
|||||||
|
|
||||||
virtual Socket* getSocket(bool mutexLock=true) {return &serverSocket;}
|
virtual Socket* getSocket(bool mutexLock=true) {return &serverSocket;}
|
||||||
|
|
||||||
//const virtual Socket *getSocket() const {
|
|
||||||
// return &serverSocket;
|
|
||||||
//}
|
|
||||||
|
|
||||||
time_t getGameStartTime() const { return gameStartTime; }
|
time_t getGameStartTime() const { return gameStartTime; }
|
||||||
|
|
||||||
bool getAllowInGameConnections() const { return allowInGameConnections; }
|
bool getAllowInGameConnections() const { return allowInGameConnections; }
|
||||||
void setAllowInGameConnections(bool value) { allowInGameConnections = value; }
|
void setAllowInGameConnections(bool value) { allowInGameConnections = value; }
|
||||||
|
|
||||||
bool getStartInGameConnectionLaunch() const { return startInGameConnectionLaunch; }
|
bool getStartInGameConnectionLaunch();
|
||||||
void setStartInGameConnectionLaunch(bool value) { startInGameConnectionLaunch = value; }
|
bool getPauseForInGameConnection();
|
||||||
|
bool getUnPauseForInGameConnection();
|
||||||
bool getPauseForInGameConnection() const { return pauseForInGameConnection; }
|
|
||||||
void setPauseForInGameConnection(bool value) { pauseForInGameConnection = value; }
|
|
||||||
|
|
||||||
bool getUnPauseForInGameConnection() const { return unPauseForInGameConnection; }
|
|
||||||
void setUnPauseForInGameConnection(bool value) { unPauseForInGameConnection = value; }
|
|
||||||
|
|
||||||
virtual void close();
|
virtual void close();
|
||||||
virtual void update();
|
virtual void update();
|
||||||
@@ -179,54 +166,49 @@ public:
|
|||||||
void setMasterserverAdminRequestLaunch(bool value) { masterserverAdminRequestLaunch = value; }
|
void setMasterserverAdminRequestLaunch(bool value) { masterserverAdminRequestLaunch = value; }
|
||||||
|
|
||||||
void updateListen();
|
void updateListen();
|
||||||
virtual bool getConnectHasHandshaked() const
|
virtual bool getConnectHasHandshaked() const {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void slotUpdateTask(ConnectionSlotEvent *event);
|
virtual void slotUpdateTask(ConnectionSlotEvent *event) { };
|
||||||
bool hasClientConnection();
|
bool hasClientConnection();
|
||||||
bool isClientConnected(int index);
|
bool isClientConnected(int index);
|
||||||
|
|
||||||
int getCurrentFrameCount() const
|
int getCurrentFrameCount() const {
|
||||||
{
|
|
||||||
return currentFrameCount;
|
return currentFrameCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<bool,bool> clientLagCheck(ConnectionSlot *connectionSlot, bool skipNetworkBroadCast = false);
|
std::pair<bool,bool> clientLagCheck(ConnectionSlot *connectionSlot, bool skipNetworkBroadCast = false);
|
||||||
bool signalClientReceiveCommands(ConnectionSlot *connectionSlot, int slotIndex, bool socketTriggered, ConnectionSlotEvent & event);
|
bool signalClientReceiveCommands(ConnectionSlot *connectionSlot, int slotIndex, bool socketTriggered, ConnectionSlotEvent & event);
|
||||||
void updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList);
|
void updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList);
|
||||||
bool isPortBound() const
|
bool isPortBound() const {
|
||||||
{
|
|
||||||
return serverSocket.isPortBound();
|
return serverSocket.isPortBound();
|
||||||
}
|
}
|
||||||
|
|
||||||
int getBindPort() const
|
int getBindPort() const {
|
||||||
{
|
|
||||||
return serverSocket.getBindPort();
|
return serverSocket.getBindPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcastPing(NetworkMessagePing *networkMessage, int excludeSlot = -1)
|
void broadcastPing(NetworkMessagePing *networkMessage, int excludeSlot = -1) {
|
||||||
{
|
|
||||||
this->broadcastMessage(networkMessage, excludeSlot);
|
this->broadcastMessage(networkMessage, excludeSlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void queueBroadcastMessage(NetworkMessage *networkMessage, int excludeSlot = -1);
|
void queueBroadcastMessage(NetworkMessage *networkMessage, int excludeSlot = -1);
|
||||||
virtual string getHumanPlayerName(int index = -1);
|
virtual string getHumanPlayerName(int index = -1);
|
||||||
virtual int getHumanPlayerIndex() const;
|
virtual int getHumanPlayerIndex() const;
|
||||||
bool getNeedToRepublishToMasterserver() const
|
bool getNeedToRepublishToMasterserver() const {
|
||||||
{
|
|
||||||
return needToRepublishToMasterserver;
|
return needToRepublishToMasterserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNeedToRepublishToMasterserver(bool value)
|
void setNeedToRepublishToMasterserver(bool value) {
|
||||||
{
|
|
||||||
needToRepublishToMasterserver = value;
|
needToRepublishToMasterserver = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPublishEnabled(bool value);
|
void setPublishEnabled(bool value);
|
||||||
|
|
||||||
bool getGameHasBeenInitiated() const { return gameHasBeenInitiated; }
|
bool getGameHasBeenInitiated() const {
|
||||||
|
return gameHasBeenInitiated;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Mutex *getServerSynchAccessor() {
|
Mutex *getServerSynchAccessor() {
|
||||||
|
Reference in New Issue
Block a user