- attempt to fix lag issue when resuming paused network game (also for resume joining in progress game)

This commit is contained in:
Mark Vejvoda 2013-03-01 06:52:33 +00:00
parent 5aaa023476
commit b6cefa3388
8 changed files with 238 additions and 112 deletions

View File

@ -110,6 +110,7 @@ Game::Game() : ProgramState(NULL) {
withRainEffect=false; withRainEffect=false;
program=NULL; program=NULL;
gameStarted=false; gameStarted=false;
this->initialResumeSpeedLoops=false;
highlightCellTexture=NULL; highlightCellTexture=NULL;
lastMasterServerGameStatsDump=0; lastMasterServerGameStatsDump=0;
@ -166,6 +167,7 @@ Game::Game() : ProgramState(NULL) {
void Game::resetMembers() { void Game::resetMembers() {
Unit::setGame(this); Unit::setGame(this);
gameStarted = false; gameStarted = false;
this->initialResumeSpeedLoops = false;
original_updateFps = GameConstants::updateFps; original_updateFps = GameConstants::updateFps;
original_cameraFps = GameConstants::cameraFps; original_cameraFps = GameConstants::cameraFps;
@ -1514,6 +1516,14 @@ void Game::init(bool initForPreviewOnly) {
perfList.push_back(perfBuf); perfList.push_back(perfBuf);
} }
if(role == nrClient) {
ClientInterface *clientInterface = dynamic_cast<ClientInterface *>(networkManager.getClientInterface());
if(clientInterface != NULL && clientInterface->getResumeInGameJoin() == true) {
clientInterface->sendResumeGameMessage();
//this->initialResumeSpeedLoops = true;
}
}
gameStarted = true; gameStarted = true;
if(this->masterserverMode == true) { if(this->masterserverMode == true) {
@ -1698,6 +1708,15 @@ void Game::update() {
// b) Updates depandant on speed // b) Updates depandant on speed
int updateLoops= getUpdateLoops(); int updateLoops= getUpdateLoops();
// Temp speed boost when player first joins an in progress game
//if(this->initialResumeSpeedLoops == true && updateLoops == 1) {
if(this->initialResumeSpeedLoops == true) {
printf("Resume #1\n");
this->initialResumeSpeedLoops = false;
updateLoops = 80;
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(showPerfStats) { if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
@ -2154,6 +2173,18 @@ void Game::update() {
} }
commander.tryResumeGame(false); commander.tryResumeGame(false);
resumeRequestSent = true; resumeRequestSent = true;
// server->setAllowInGameConnections(false);
// for(int i = 0; i < world.getFactionCount(); ++i) {
// Faction *faction = world.getFaction(i);
// ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
// if(slot != NULL && slot->isConnected() == false) {
// server->setAllowInGameConnections(false);
// server->removeSlot(faction->getStartLocationIndex());
// }
// }
//server->shutdownFTPServer();
//return; //return;
} }
else if(server->getStartInGameConnectionLaunch() == true) { else if(server->getStartInGameConnectionLaunch() == true) {
@ -2220,7 +2251,7 @@ void Game::update() {
// Make the server wait a bit for clients to start. // Make the server wait a bit for clients to start.
if(paused == false && resumeRequestSent == true) { if(paused == false && resumeRequestSent == true) {
resumeRequestSent = false; resumeRequestSent = false;
sleep(500); //sleep(500);
} }
} }
// END - Handle joining in progress games // END - Handle joining in progress games
@ -5406,6 +5437,15 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches
} }
} }
setupPopupMenus(false); setupPopupMenus(false);
//!!!
NetworkManager &networkManager= NetworkManager::getInstance();
if(networkManager.getNetworkRole() == nrClient) {
//ClientInterface *clientInterface = dynamic_cast<ClientInterface *>(networkManager.getClientInterface());
//if(clientInterface != NULL && clientInterface->getResumeInGameJoin() == true) {
initialResumeSpeedLoops = true;
//}
}
} }
else { else {
console.addLine(lang.get("GamePaused")); console.addLine(lang.get("GamePaused"));

View File

@ -198,6 +198,7 @@ private:
MasterSlaveThreadController masterController; MasterSlaveThreadController masterController;
bool inJoinGameLoading; bool inJoinGameLoading;
bool initialResumeSpeedLoops;
public: public:
Game(); Game();

View File

@ -52,8 +52,8 @@ ClientInterface::ClientInterface() : GameNetworkInterface() {
networkCommandListThread = NULL; networkCommandListThread = NULL;
cachedPendingCommandsIndex = 0; cachedPendingCommandsIndex = 0;
pausedForInGameJoin = false; this->pausedForInGameJoin = false;
readyForInGameJoin = false; this->readyForInGameJoin = false;
clientSocket= NULL; clientSocket= NULL;
sessionKey = 0; sessionKey = 0;
launchGame= false; launchGame= false;
@ -657,7 +657,7 @@ void ClientInterface::updateLobby() {
if(gotCmd == false) { if(gotCmd == false) {
throw megaglest_runtime_error("error retrieving nmtCommandList returned false!"); throw megaglest_runtime_error("error retrieving nmtCommandList returned false!");
} }
pausedForInGameJoin = true; this->pausedForInGameJoin = true;
} }
break; break;
@ -932,7 +932,8 @@ void ClientInterface::updateFrame(int *checkFrame) {
} }
else { else {
if(checkFrame == NULL) { if(checkFrame == NULL) {
sleep(15); //sleep(15);
sleep(0);
} }
} }
} }
@ -1014,9 +1015,9 @@ bool ClientInterface::isMasterServerAdminOverride() {
void ClientInterface::waitUntilReady(Checksum* checksum) { void ClientInterface::waitUntilReady(Checksum* checksum) {
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__);
bool signalServerWhenReadyToStartJoinedGame = readyForInGameJoin; bool signalServerWhenReadyToStartJoinedGame = this->readyForInGameJoin;
pausedForInGameJoin = false; this->pausedForInGameJoin = false;
readyForInGameJoin = false; this->readyForInGameJoin = false;
Logger &logger= Logger::getInstance(); Logger &logger= Logger::getInstance();
Chrono chrono; Chrono chrono;
@ -1260,7 +1261,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
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__);
//check checksum //check checksum
if(joinGameInProgress == false && networkMessageReady.getChecksum() != checksum->getSum()) { if(this->joinGameInProgress == false && networkMessageReady.getChecksum() != checksum->getSum()) {
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__);
Lang &lang= Lang::getInstance(); Lang &lang= Lang::getInstance();
@ -1342,8 +1343,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
//printf("Client signalServerWhenReadyToStartJoinedGame = %d\n",signalServerWhenReadyToStartJoinedGame); //printf("Client signalServerWhenReadyToStartJoinedGame = %d\n",signalServerWhenReadyToStartJoinedGame);
if(signalServerWhenReadyToStartJoinedGame == true) { if(signalServerWhenReadyToStartJoinedGame == true) {
NetworkMessageReady networkMessageReady; this->resumeInGameJoin = true;
sendMessage(&networkMessageReady);
} }
else { else {
// delay the start a bit, so clients have more room to get messages // delay the start a bit, so clients have more room to get messages
@ -1358,6 +1358,11 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__);
} }
void ClientInterface::sendResumeGameMessage() {
NetworkMessageReady networkMessageReady;
sendMessage(&networkMessageReady);
}
void ClientInterface::sendTextMessage(const string &text, int teamIndex, bool echoLocal, void ClientInterface::sendTextMessage(const string &text, int teamIndex, bool echoLocal,
string targetLanguage) { string targetLanguage) {

View File

@ -70,6 +70,7 @@ private:
bool joinGameInProgressLaunch; bool joinGameInProgressLaunch;
bool pausedForInGameJoin; bool pausedForInGameJoin;
bool readyForInGameJoin; bool readyForInGameJoin;
bool resumeInGameJoin;
public: public:
ClientInterface(); ClientInterface();
@ -85,6 +86,9 @@ public:
bool getPausedForInGameJoin() const { return pausedForInGameJoin; } bool getPausedForInGameJoin() const { return pausedForInGameJoin; }
bool getReadyForInGameJoin() const { return readyForInGameJoin; } bool getReadyForInGameJoin() const { return readyForInGameJoin; }
bool getResumeInGameJoin() const { return resumeInGameJoin; }
void sendResumeGameMessage();
//message processing //message processing
virtual void update(); virtual void update();
virtual void updateLobby(); virtual void updateLobby();

View File

@ -187,55 +187,98 @@ void ConnectionSlotThread::execute() {
break; break;
} }
semTaskSignalled.waitTillSignalled(); if(this->slotInterface->getAllowInGameConnections() == true &&
this->slotInterface->isClientConnected(slotIndex) == false) {
//printf("#1 Non connected slot: %d waiting for client connection..\n",slotIndex);
sleep(100);
static string masterSlaveOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); if(getQuitStatus() == true) {
MasterSlaveThreadControllerSafeWrapper safeMasterController(masterController,20000,masterSlaveOwnerId); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
break;
}
if(getQuitStatus() == true) { //printf("Slot thread slotIndex: %d eventCount: %d\n",slotIndex,eventCount);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Slot thread slotIndex: %d eventCount: %d\n",__FILE__,__FUNCTION__,__LINE__,slotIndex,eventCount);
break;
//if(eventCount > 0) {
ConnectionSlotEvent eventCopy;
eventCopy.eventType = eReceiveSocketData;
eventCopy.connectionSlot = this->slotInterface->getSlot(slotIndex);
eventCopy.eventId = -1;
if(getQuitStatus() == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
break;
}
//if(eventCopy.eventId > 0) {
ExecutingTaskSafeWrapper safeExecutingTaskMutex(this);
//if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Slot thread slotIndex: %d eventCount: %d eventCopy.eventId: %d\n",__FILE__,__FUNCTION__,__LINE__,slotIndex,eventCount,(int)eventCopy.eventId);
//printf("#1 Slot thread slotIndex: %d eventCount: %d eventCopy.eventId: %d\n",slotIndex,eventCount,(int)eventCopy.eventId);
//this->slotInterface->slotUpdateTask(&eventCopy);
//printf("#2 Non connected slot: %d waiting for client connection..\n",slotIndex);
this->slotUpdateTask(&eventCopy);
//setTaskCompleted(eventCopy.eventId);
//printf("#2 Slot thread slotIndex: %d eventCount: %d eventCopy.eventId: %d\n",slotIndex,eventCount,(int)eventCopy.eventId);
//}
//}
//else {
// safeMutex.ReleaseLock();
//}
} }
else {
semTaskSignalled.waitTillSignalled();
MutexSafeWrapper safeMutex(triggerIdMutex,CODE_AT_LINE); static string masterSlaveOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
int eventCount = eventList.size(); MasterSlaveThreadControllerSafeWrapper safeMasterController(masterController,20000,masterSlaveOwnerId);
//printf("Slot thread slotIndex: %d eventCount: %d\n",slotIndex,eventCount); if(getQuitStatus() == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Slot thread slotIndex: %d eventCount: %d\n",__FILE__,__FUNCTION__,__LINE__,slotIndex,eventCount); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
break;
}
if(eventCount > 0) { MutexSafeWrapper safeMutex(triggerIdMutex,CODE_AT_LINE);
ConnectionSlotEvent eventCopy; int eventCount = eventList.size();
eventCopy.eventId = -1;
for(int i = 0; i < eventList.size(); ++i) { //printf("Slot thread slotIndex: %d eventCount: %d\n",slotIndex,eventCount);
ConnectionSlotEvent &slotEvent = eventList[i]; if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Slot thread slotIndex: %d eventCount: %d\n",__FILE__,__FUNCTION__,__LINE__,slotIndex,eventCount);
if(slotEvent.eventCompleted == false) {
eventCopy = slotEvent;
break;
}
}
safeMutex.ReleaseLock(); if(eventCount > 0) {
ConnectionSlotEvent eventCopy;
eventCopy.eventId = -1;
if(getQuitStatus() == true) { for(int i = 0; i < eventList.size(); ++i) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); ConnectionSlotEvent &slotEvent = eventList[i];
break; if(slotEvent.eventCompleted == false) {
} eventCopy = slotEvent;
break;
}
}
if(eventCopy.eventId > 0) { safeMutex.ReleaseLock();
ExecutingTaskSafeWrapper safeExecutingTaskMutex(this);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Slot thread slotIndex: %d eventCount: %d eventCopy.eventId: %d\n",__FILE__,__FUNCTION__,__LINE__,slotIndex,eventCount,(int)eventCopy.eventId); if(getQuitStatus() == true) {
//printf("#1 Slot thread slotIndex: %d eventCount: %d eventCopy.eventId: %d\n",slotIndex,eventCount,(int)eventCopy.eventId); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//this->slotInterface->slotUpdateTask(&eventCopy); break;
this->slotUpdateTask(&eventCopy); }
setTaskCompleted(eventCopy.eventId);
//printf("#2 Slot thread slotIndex: %d eventCount: %d eventCopy.eventId: %d\n",slotIndex,eventCount,(int)eventCopy.eventId); if(eventCopy.eventId > 0) {
} ExecutingTaskSafeWrapper safeExecutingTaskMutex(this);
}
else { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Slot thread slotIndex: %d eventCount: %d eventCopy.eventId: %d\n",__FILE__,__FUNCTION__,__LINE__,slotIndex,eventCount,(int)eventCopy.eventId);
safeMutex.ReleaseLock(); //printf("#1 Slot thread slotIndex: %d eventCount: %d eventCopy.eventId: %d\n",slotIndex,eventCount,(int)eventCopy.eventId);
} //this->slotInterface->slotUpdateTask(&eventCopy);
this->slotUpdateTask(&eventCopy);
setTaskCompleted(eventCopy.eventId);
//printf("#2 Slot thread slotIndex: %d eventCount: %d eventCopy.eventId: %d\n",slotIndex,eventCount,(int)eventCopy.eventId);
}
}
else {
safeMutex.ReleaseLock();
}
}
if(getQuitStatus() == true) { if(getQuitStatus() == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -348,10 +391,10 @@ void ConnectionSlot::updateSlot(ConnectionSlotEvent *event) {
Chrono chrono; Chrono chrono;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
if(serverInterface->getGameHasBeenInitiated() == true && //if(serverInterface->getGameHasBeenInitiated() == true &&
serverInterface->getAllowInGameConnections() == true) { //serverInterface->getAllowInGameConnections() == true) {
//printf("Checking updateSlot event = %p\n",event); //printf("Checking updateSlot event = %p\n",event);
} //}
if(event != NULL) { if(event != NULL) {
bool &socketTriggered = event->socketTriggered; bool &socketTriggered = event->socketTriggered;
@ -363,13 +406,13 @@ void ConnectionSlot::updateSlot(ConnectionSlotEvent *event) {
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
if(serverInterface->getGameHasBeenInitiated() == true && //if(serverInterface->getGameHasBeenInitiated() == true &&
serverInterface->getAllowInGameConnections() == true) { //serverInterface->getAllowInGameConnections() == true) {
//printf("Checking for new client connection on slot, checkForNewClients: %d this->canAcceptConnections: %d\n",checkForNewClients,this->canAcceptConnections); //printf("Checking for new client connection on slot, checkForNewClients: %d this->canAcceptConnections: %d\n",checkForNewClients,this->canAcceptConnections);
} //}
if((serverInterface->getGameHasBeenInitiated() == false || if((serverInterface->getGameHasBeenInitiated() == false ||
serverInterface->getAllowInGameConnections() == true || (serverInterface->getAllowInGameConnections() == true && this->isConnected() == false) ||
//(this->getSocket() != NULL && socketTriggered == true))) { //(this->getSocket() != NULL && socketTriggered == true))) {
socketTriggered == true)) { socketTriggered == true)) {
if(socketTriggered == true || if(socketTriggered == true ||
@ -1289,7 +1332,8 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
double LAG_CHECK_GRACE_PERIOD = 15; double LAG_CHECK_GRACE_PERIOD = 15;
if(this->serverInterface->getGameStartTime() > 0 && if(this->serverInterface->getGameStartTime() > 0 &&
difftime((long int)time(NULL),this->serverInterface->getGameStartTime()) >= LAG_CHECK_GRACE_PERIOD) { difftime((long int)time(NULL),this->serverInterface->getGameStartTime()) >= LAG_CHECK_GRACE_PERIOD &&
difftime((long int)time(NULL),this->getConnectedTime()) >= LAG_CHECK_GRACE_PERIOD) {
if(this->isConnected() == true && this->gotIntro == true && this->skipLagCheck == false) { if(this->isConnected() == true && this->gotIntro == true && this->skipLagCheck == false) {
double clientLag = this->serverInterface->getCurrentFrameCount() - this->getCurrentFrameCount(); double clientLag = this->serverInterface->getCurrentFrameCount() - this->getCurrentFrameCount();
double clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0); double clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0);

View File

@ -66,6 +66,10 @@ public:
// //
class ConnectionSlotCallbackInterface { class ConnectionSlotCallbackInterface {
public: public:
virtual bool isClientConnected(int index) = 0;
virtual bool getAllowInGameConnections() const = 0;
virtual ConnectionSlot *getSlot(int index) = 0;
virtual void slotUpdateTask(ConnectionSlotEvent *event) = 0; virtual void slotUpdateTask(ConnectionSlotEvent *event) = 0;
virtual ~ConnectionSlotCallbackInterface() {} virtual ~ConnectionSlotCallbackInterface() {}
}; };

View File

@ -78,6 +78,7 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
inBroadcastMessage = false; inBroadcastMessage = false;
lastGlobalLagCheckTime = 0; lastGlobalLagCheckTime = 0;
masterserverAdminRequestLaunch = false; masterserverAdminRequestLaunch = false;
lastListenerSlotCheckTime = 0;
// 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
@ -260,11 +261,7 @@ ServerInterface::~ServerInterface() {
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__);
close(); close();
if(ftpServer != NULL) { shutdownFTPServer();
ftpServer->shutdownAndWait();
delete ftpServer;
ftpServer = NULL;
}
shutdownMasterserverPublishThread(); shutdownMasterserverPublishThread();
lastMasterserverHeartbeatTime = 0; lastMasterserverHeartbeatTime = 0;
@ -885,11 +882,12 @@ void ServerInterface::signalClientsToRecieveData(std::map<PLATFORM_SOCKET,bool>
//socketTriggeredList[clientSocket] = true; //socketTriggeredList[clientSocket] = true;
//socketTriggered = socketTriggeredList[clientSocket]; //socketTriggered = socketTriggeredList[clientSocket];
//} //}
}
ConnectionSlotEvent &event = eventList[i]; ConnectionSlotEvent &event = eventList[i];
bool socketSignalled = signalClientReceiveCommands(connectionSlot,i,socketTriggered,event); bool socketSignalled = signalClientReceiveCommands(connectionSlot,i,socketTriggered,event);
if(connectionSlot != NULL && socketTriggered == true) { if(connectionSlot != NULL && socketTriggered == true) {
mapSlotSignalledList[i] = socketSignalled; mapSlotSignalledList[i] = socketSignalled;
}
} }
} }
} }
@ -956,7 +954,8 @@ void ServerInterface::checkForCompletedClients(std::map<int,bool> & mapSlotSigna
//printf("===> IN slot %d - About to checkForCompletedClients\n",i); //printf("===> IN slot %d - About to checkForCompletedClients\n",i);
ConnectionSlot* connectionSlot = slots[i]; ConnectionSlot* connectionSlot = slots[i];
if(connectionSlot != NULL && mapSlotSignalledList[i] == true && if(connectionSlot != NULL && connectionSlot->isConnected() == true &&
mapSlotSignalledList[i] == true &&
connectionSlot->getJoinGameInProgress() == false && connectionSlot->getJoinGameInProgress() == false &&
slotsCompleted.find(i) == slotsCompleted.end()) { slotsCompleted.find(i) == slotsCompleted.end()) {
try { try {
@ -1017,7 +1016,8 @@ void ServerInterface::checkForLaggingClients(std::map<int,bool> &mapSlotSignalle
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));
ConnectionSlot* connectionSlot = slots[i]; ConnectionSlot* connectionSlot = slots[i];
if(connectionSlot != NULL && mapSlotSignalledList[i] == true && if(connectionSlot != NULL && connectionSlot->isConnected() == true &&
mapSlotSignalledList[i] == true &&
slotsCompleted.find(i) == slotsCompleted.end()) { slotsCompleted.find(i) == slotsCompleted.end()) {
try { try {
std::vector<std::string> errorList = connectionSlot->getThreadErrorList(); std::vector<std::string> errorList = connectionSlot->getThreadErrorList();
@ -1306,8 +1306,9 @@ void ServerInterface::dispatchPendingUnMarkCellMessages(std::vector <string> &er
} }
void ServerInterface::update() { void ServerInterface::update() {
bool miniDebugPerf = false;
Chrono chrono; Chrono chrono;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled || miniDebugPerf) chrono.start();
//printf("\nServerInterface::update -- A\n"); //printf("\nServerInterface::update -- A\n");
@ -1320,6 +1321,7 @@ void ServerInterface::update() {
//printf("\nServerInterface::update -- B\n"); //printf("\nServerInterface::update -- B\n");
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(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(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
processTextMessageQueue(); processTextMessageQueue();
processBroadCastMessageQueue(); processBroadCastMessageQueue();
@ -1327,6 +1329,7 @@ void ServerInterface::update() {
//printf("\nServerInterface::update -- C\n"); //printf("\nServerInterface::update -- C\n");
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(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(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
std::map<PLATFORM_SOCKET,bool> socketTriggeredList; std::map<PLATFORM_SOCKET,bool> socketTriggeredList;
//update all slots //update all slots
@ -1335,9 +1338,10 @@ void ServerInterface::update() {
//printf("\nServerInterface::update -- D\n"); //printf("\nServerInterface::update -- D\n");
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(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(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(gameHasBeenInitiated == false || if(gameHasBeenInitiated == false ||
this->getAllowInGameConnections() == true || //this->getAllowInGameConnections() == true ||
socketTriggeredList.empty() == false) { socketTriggeredList.empty() == false) {
//printf("\nServerInterface::update -- E\n"); //printf("\nServerInterface::update -- E\n");
@ -1352,8 +1356,10 @@ void ServerInterface::update() {
if(hasData) if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] hasData == true\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); if(hasData) if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] hasData == true\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__);
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(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(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(gameHasBeenInitiated == false || hasData == true || this->getAllowInGameConnections() == true) { //if(gameHasBeenInitiated == false || hasData == true || this->getAllowInGameConnections() == true) {
if(gameHasBeenInitiated == false || hasData == true) {
std::map<int,bool> mapSlotSignalledList; std::map<int,bool> mapSlotSignalledList;
// Step #1 tell all connection slot worker threads to receive socket data // Step #1 tell all connection slot worker threads to receive socket data
@ -1361,6 +1367,7 @@ void ServerInterface::update() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #2\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #2\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()); 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(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(gameHasBeenInitiated == false || hasData == true) { if(gameHasBeenInitiated == false || hasData == true) {
// Step #2 check all connection slot worker threads for completed status // Step #2 check all connection slot worker threads for completed status
@ -1368,6 +1375,7 @@ void ServerInterface::update() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #3\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #3\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()); 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(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
//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__);
// Step #3 check clients for any lagging scenarios and try to deal with them // Step #3 check clients for any lagging scenarios and try to deal with them
@ -1375,6 +1383,7 @@ void ServerInterface::update() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #4\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #4\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()); 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(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
//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__);
// Step #4 dispatch network commands to the pending list so that they are done in proper order // Step #4 dispatch network commands to the pending list so that they are done in proper order
@ -1382,6 +1391,7 @@ void ServerInterface::update() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #5\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #5\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()); 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(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
//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__);
// Step #5 dispatch pending chat messages // Step #5 dispatch pending chat messages
@ -1401,6 +1411,7 @@ void ServerInterface::update() {
} }
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(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(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
} }
else if(gameHasBeenInitiated == true && else if(gameHasBeenInitiated == true &&
difftime((long int)time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) { difftime((long int)time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) {
@ -1411,6 +1422,7 @@ void ServerInterface::update() {
} }
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(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(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
} }
else if(gameHasBeenInitiated == true && else if(gameHasBeenInitiated == true &&
difftime((long int)time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) { difftime((long int)time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) {
@ -1422,8 +1434,12 @@ void ServerInterface::update() {
checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList); checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
} }
if(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
// Check if we need to switch masterserver admin to a new player because original admin disconnected // Check if we need to switch masterserver admin to a new player because original admin disconnected
if(gameHasBeenInitiated == true && this->gameSettings.getMasterserver_admin() > 0) { if(gameHasBeenInitiated == true && this->gameSettings.getMasterserver_admin() > 0) {
if(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
//!!! //!!!
bool foundAdminSlot = false; bool foundAdminSlot = false;
int iFirstConnectedSlot = -1; int iFirstConnectedSlot = -1;
@ -1458,7 +1474,10 @@ void ServerInterface::update() {
} }
//printf("\nServerInterface::update -- G\n"); //printf("\nServerInterface::update -- G\n");
if(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
checkListenerSlots(); checkListenerSlots();
if(miniDebugPerf && chrono.getMillis() > 10) printf("In [%s::%s Line: %d] took " MG_I64_SPECIFIER " msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
} }
catch(const exception &ex) { catch(const exception &ex) {
//printf("\nServerInterface::update -- H\n"); //printf("\nServerInterface::update -- H\n");
@ -2089,7 +2108,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
if(connectionSlot != NULL && connectionSlot->isConnected()) { if(connectionSlot != NULL && connectionSlot->isConnected()) {
connectionSlot->getSocket()->setBlock(true); connectionSlot->getSocket()->setBlock(true);
} }
else if(allowInGameConnections == true) { else if(this->getAllowInGameConnections() == true) {
// Open slots for joining in progress game // Open slots for joining in progress game
if(gameSettings->getFactionControl(factionIndex) != ctClosed && if(gameSettings->getFactionControl(factionIndex) != ctClosed &&
gameSettings->getFactionControl(factionIndex) != ctHuman) { gameSettings->getFactionControl(factionIndex) != ctHuman) {
@ -2107,7 +2126,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
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);
if(allowInGameConnections == false) { if(this->getAllowInGameConnections() == false) {
serverSocket.stopBroadCastThread(); serverSocket.stopBroadCastThread();
} }
@ -2127,12 +2146,8 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ftpServer = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ftpServer); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ftpServer = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ftpServer);
if(allowInGameConnections == false) { if(this->getAllowInGameConnections() == false) {
if(ftpServer != NULL) { shutdownFTPServer();
ftpServer->shutdownAndWait();
delete ftpServer;
ftpServer = NULL;
}
} }
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);
@ -2148,12 +2163,8 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
} }
} }
if(allowInGameConnections == false) { if(this->getAllowInGameConnections() == false) {
if(ftpServer != NULL) { shutdownFTPServer();
ftpServer->shutdownAndWait();
delete ftpServer;
ftpServer = NULL;
}
} }
gameLaunched = true; gameLaunched = true;
@ -2162,35 +2173,46 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
return bOkToStart; return bOkToStart;
} }
void ServerInterface::shutdownFTPServer() {
if(ftpServer != NULL) {
ftpServer->shutdownAndWait();
delete ftpServer;
ftpServer = NULL;
}
}
void ServerInterface::checkListenerSlots() { void ServerInterface::checkListenerSlots() {
if(gameLaunched == true && allowInGameConnections == true) { if(gameLaunched == true && this->getAllowInGameConnections() == true) {
bool useInGameBlockingClientSockets = Config::getInstance().getBool("EnableInGameBlockingSockets","true"); if(difftime((long int)time(NULL),lastListenerSlotCheckTime) >= 7) {
lastListenerSlotCheckTime = time(NULL);
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__);
for(int i= 0; i < GameConstants::maxPlayers; ++i) { for(int i= 0; i < GameConstants::maxPlayers; ++i) {
int factionIndex = gameSettings.getFactionIndexForStartLocation(i); int factionIndex = gameSettings.getFactionIndexForStartLocation(i);
if(gameSettings.getFactionControl(factionIndex) != ctClosed && if(gameSettings.getFactionControl(factionIndex) != ctClosed &&
gameSettings.getFactionControl(factionIndex) != ctHuman) { gameSettings.getFactionControl(factionIndex) != ctHuman) {
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ConnectionSlot *connectionSlot= slots[i]; ConnectionSlot *connectionSlot= slots[i];
// Open slots for joining in progress game // Open slots for joining in progress game
if(connectionSlot == NULL) { if(connectionSlot == NULL) {
printf("Opening slot for in game connections, slot: %d, factionindex: %d name: %s\n",i,factionIndex,gameSettings.getFactionTypeName(factionIndex).c_str()); printf("Opening slot for in game connections, slot: %d, factionindex: %d name: %s\n",i,factionIndex,gameSettings.getFactionTypeName(factionIndex).c_str());
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 &&
else if(connectionSlot != NULL && connectionSlot->isConnected() == false) {
connectionSlot->getCanAcceptConnections() == false && printf("Removing slot for in game connections, slot: %d, factionindex: %d name: %s\n",i,factionIndex,gameSettings.getFactionTypeName(factionIndex).c_str());
connectionSlot->isConnected() == false) {
printf("Removing slot for in game connections, slot: %d, factionindex: %d name: %s\n",i,factionIndex,gameSettings.getFactionTypeName(factionIndex).c_str());
this->removeSlot(i); this->removeSlot(i);
}
} }
} }
} }
@ -2325,6 +2347,9 @@ void ServerInterface::updateListen() {
if(gameHasBeenInitiated == true && this->getAllowInGameConnections() == false) { if(gameHasBeenInitiated == true && this->getAllowInGameConnections() == false) {
return; return;
} }
//printf("updateListen() #1!\n");
int openSlotCount = 0; int openSlotCount = 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],intToStr(__LINE__) + "_" + intToStr(i)); //MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));

View File

@ -99,6 +99,7 @@ private:
bool allowInGameConnections; bool allowInGameConnections;
bool gameLaunched; bool gameLaunched;
time_t lastListenerSlotCheckTime;
public: public:
ServerInterface(bool publishEnabled); ServerInterface(bool publishEnabled);
@ -108,13 +109,15 @@ public:
time_t getGameStartTime() const { return gameStartTime; } time_t getGameStartTime() const { return gameStartTime; }
bool getAllowInGameConnections() const { return allowInGameConnections; } virtual bool getAllowInGameConnections() const { return allowInGameConnections; }
void setAllowInGameConnections(bool value) { allowInGameConnections = value; } void setAllowInGameConnections(bool value) { allowInGameConnections = value; }
bool getStartInGameConnectionLaunch(); bool getStartInGameConnectionLaunch();
bool getPauseForInGameConnection(); bool getPauseForInGameConnection();
bool getUnPauseForInGameConnection(); bool getUnPauseForInGameConnection();
void shutdownFTPServer();
virtual void close(); virtual void close();
virtual void update(); virtual void update();
virtual void updateLobby() { }; virtual void updateLobby() { };
@ -150,7 +153,7 @@ public:
void addSlot(int playerIndex); void addSlot(int playerIndex);
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); virtual ConnectionSlot *getSlot(int playerIndex);
int getSlotCount(); int getSlotCount();
int getConnectedSlotCount(bool authenticated); int getConnectedSlotCount(bool authenticated);
@ -172,7 +175,7 @@ public:
virtual void slotUpdateTask(ConnectionSlotEvent *event) { }; virtual void slotUpdateTask(ConnectionSlotEvent *event) { };
bool hasClientConnection(); bool hasClientConnection();
bool isClientConnected(int index); virtual bool isClientConnected(int index);
int getCurrentFrameCount() const { int getCurrentFrameCount() const {
return currentFrameCount; return currentFrameCount;