diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 2dc007b74..9f75a9d0a 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -175,7 +175,7 @@ std::string ClientInterface::getServerIpAddress() { } void ClientInterface::updateLobby() { - NetworkMessageType networkMessageType = getNextMessageType(0); + NetworkMessageType networkMessageType = getNextMessageType(); switch(networkMessageType) { case nmtInvalid: @@ -725,7 +725,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); return; } - NetworkMessageType networkMessageType = getNextMessageType(0); + NetworkMessageType networkMessageType = getNextMessageType(); // consume old messages from the lobby bool discarded = shouldDiscardNetworkMessage(networkMessageType); @@ -1038,7 +1038,7 @@ NetworkMessageType ClientInterface::waitForMessage() NetworkMessageType msg = nmtInvalid; //uint64 waitLoopCount = 0; while(msg == nmtInvalid) { - msg = getNextMessageType(5); + msg = getNextMessageType(); if(msg == nmtInvalid) { if(chrono.getMillis() % 250 == 0 && isConnected() == false) { if(quit == false) { diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 2c2ba75f6..8eef0b23a 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -32,18 +32,16 @@ namespace Glest{ namespace Game{ // class ConnectionSlotThread // ===================================================== -ConnectionSlotThread::ConnectionSlotThread(ConnectionSlot *slot) : BaseThread() { - this->slot = slot; - this->slotIndex = this->slot->getPlayerIndex(); +ConnectionSlotThread::ConnectionSlotThread(int slotIndex) : BaseThread() { + this->slotIndex = slotIndex; this->slotInterface = NULL; //this->event = NULL; eventList.clear(); eventList.reserve(100); } -ConnectionSlotThread::ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,ConnectionSlot *slot) : BaseThread() { - this->slot = slot; - this->slotIndex = this->slot->getPlayerIndex(); +ConnectionSlotThread::ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,int slotIndex) : BaseThread() { + this->slotIndex = slotIndex; this->slotInterface = slotInterface; //this->event = NULL; eventList.clear(); @@ -165,9 +163,6 @@ void ConnectionSlotThread::execute() { //setRunningStatus(true); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - Chrono chrono; - chrono.start(); - //unsigned int idx = 0; for(;this->slotInterface != NULL;) { if(getQuitStatus() == true) { @@ -175,14 +170,13 @@ void ConnectionSlotThread::execute() { break; } - //semTaskSignalled.waitTillSignalled(); + semTaskSignalled.waitTillSignalled(); - //if(getQuitStatus() == true) { - // if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - // break; - //} + if(getQuitStatus() == true) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + break; + } -/* MutexSafeWrapper safeMutex(&triggerIdMutex,CODE_AT_LINE); int eventCount = eventList.size(); if(eventCount > 0) { @@ -214,31 +208,11 @@ void ConnectionSlotThread::execute() { else { safeMutex.ReleaseLock(); } -*/ - bool slotconnected = false; - //if(this->slot != NULL) { - { - ConnectionSlotEvent event; - event.triggerId = this->slotIndex; - event.socketTriggered = true; - - ExecutingTaskSafeWrapper safeExecutingTaskMutex(this); - slotconnected = this->slot->updateSlot(&event); - } if(getQuitStatus() == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); break; } - - if(slotconnected == false) { - if(chrono.getMillis() % 10 == 0) { - sleep(100); - } - } - //else { - // this->slot->hasDataToReadWithWait(250); - //} } if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -276,8 +250,7 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex this->setSocket(NULL); this->slotThreadWorker = NULL; - //this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface,playerIndex); - this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface,this); + this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface,playerIndex); this->slotThreadWorker->setUniqueID(__FILE__); this->slotThreadWorker->start(); @@ -313,27 +286,27 @@ ConnectionSlot::~ConnectionSlot() { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } -bool ConnectionSlot::updateSlot(ConnectionSlotEvent *event) { +void ConnectionSlot::updateSlot(ConnectionSlotEvent *event) { Chrono chrono; if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); - //if(event != NULL) { - //bool &socketTriggered = event->socketTriggered; + if(event != NULL) { + bool &socketTriggered = event->socketTriggered; bool checkForNewClients = (serverInterface->getGameHasBeenInitiated() == false); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,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() == false || + if((serverInterface->getGameHasBeenInitiated() == false || //(this->getSocket() != NULL && socketTriggered == true))) { - // socketTriggered == true)) { - // if(socketTriggered == true || - // (serverInterface->getGameHasBeenInitiated() == false && this->isConnected() == false)) { + socketTriggered == true)) { + if(socketTriggered == true || + (serverInterface->getGameHasBeenInitiated() == false && this->isConnected() == false)) { //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()); - bool slotconnected = this->update(checkForNewClients,event->triggerId); + this->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",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); @@ -343,30 +316,27 @@ bool ConnectionSlot::updateSlot(ConnectionSlotEvent *event) { //if(this->getSocket() == NULL) { // checkForNewClients = false; //} - //} + } //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(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - - return slotconnected; } -bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { +void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { //Chrono chrono; //chrono.start(); - pair socketInfo; try { clearThreadErrorList(); - //if(slotThreadWorker != NULL) { - // slotThreadWorker->purgeCompletedEvents(); - //} + if(slotThreadWorker != NULL) { + slotThreadWorker->purgeCompletedEvents(); + } //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); - socketInfo = this->getSocketInfo(); + pair socketInfo = this->getSocketInfo(); if(socketInfo.second == NULL) { if(networkGameDataSynchCheckOkMap) networkGameDataSynchCheckOkMap = false; if(networkGameDataSynchCheckOkTile) networkGameDataSynchCheckOkTile = false; @@ -494,17 +464,17 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); - //this->clearChatInfo(); + this->clearChatInfo(); - //bool gotTextMsg = true; - //for(;this->hasDataToReadWithWait(100) == true && gotTextMsg == true;) { + bool gotTextMsg = true; + for(;this->hasDataToRead() == true && gotTextMsg == true;) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] polling for networkMessageType...\n",__FILE__,__FUNCTION__,__LINE__); - NetworkMessageType networkMessageType= getNextMessageType(100); + NetworkMessageType networkMessageType= getNextMessageType(); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] networkMessageType = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageType); - //gotTextMsg = false; + gotTextMsg = false; //process incoming commands switch(networkMessageType) { @@ -528,7 +498,7 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } //} } @@ -543,20 +513,20 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(receiveMessage(&networkMessageText)) { ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getTeamIndex(),networkMessageText.getPlayerIndex(),networkMessageText.getTargetLanguage()); this->addChatInfo(msg); - //gotTextMsg = true; + gotTextMsg = true; } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } break; @@ -585,14 +555,14 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } break; @@ -620,7 +590,7 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,sErr.c_str()); close(); - return false; + return; } else { //check consistency @@ -658,7 +628,7 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,sErr.c_str()); close(); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,sErr.c_str()); - return false; + return; } } @@ -679,7 +649,7 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } break; @@ -696,7 +666,7 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,sErr.c_str()); close(); - return false; + return; } NetworkMessageLaunch networkMessageLaunch; @@ -732,14 +702,14 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } break; @@ -857,14 +827,14 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } break; @@ -886,14 +856,14 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } break; @@ -919,14 +889,14 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } break; @@ -965,14 +935,14 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } break; @@ -995,7 +965,7 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { //sendTextMessage(sErr,-1); //DisplayErrorMessage(sErr); threadErrorList.push_back(sErr); - return socketInfo.first; + return; } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got invalid message type before intro, disconnecting socket.\n",__FILE__,__FUNCTION__,__LINE__); @@ -1003,11 +973,11 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str()); this->serverInterface->notifyBadClientConnectAttempt(this->getIpAddress()); close(); - return false; + return; } } } - //} + } //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); @@ -1035,7 +1005,6 @@ bool ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); } - return socketInfo.first; //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); } @@ -1208,14 +1177,4 @@ bool ConnectionSlot::hasDataToRead() { return result; } -bool ConnectionSlot::hasDataToReadWithWait(int waitMilliseconds) { - bool result = false; - MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE); - - if(socket != NULL && socket->hasDataToRead(waitMilliseconds) == true) { - result = true; - } - return result; -} - }}//end namespace diff --git a/source/glest_game/network/connection_slot.h b/source/glest_game/network/connection_slot.h index 5cc2a83bb..dfebcf820 100644 --- a/source/glest_game/network/connection_slot.h +++ b/source/glest_game/network/connection_slot.h @@ -78,7 +78,6 @@ protected: Mutex triggerIdMutex; vector eventList; int slotIndex; - ConnectionSlot *slot; virtual void setQuitStatus(bool value); virtual void setTaskCompleted(int eventId); @@ -87,8 +86,8 @@ protected: void slotUpdateTask(ConnectionSlotEvent *event); public: - ConnectionSlotThread(ConnectionSlot *slot); - ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,ConnectionSlot *slot); + ConnectionSlotThread(int slotIndex); + ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,int slotIndex); virtual void execute(); void signalUpdate(ConnectionSlotEvent *event); bool isSignalCompleted(ConnectionSlotEvent *event); @@ -136,7 +135,7 @@ public: ConnectionSlot(ServerInterface* serverInterface, int playerIndex); ~ConnectionSlot(); - bool update(bool checkForNewClients,int lockedSlotIndex); + void update(bool checkForNewClients,int lockedSlotIndex); void setPlayerIndex(int value) { playerIndex = value; } int getPlayerIndex() const {return playerIndex;} @@ -191,14 +190,11 @@ public: time_t getConnectedTime() const { return connectedTime; } int getSessionKey() const { return sessionKey; } - bool updateSlot(ConnectionSlotEvent *event); + void updateSlot(ConnectionSlotEvent *event); virtual bool isConnected(); PLATFORM_SOCKET getSocketId(); - bool hasDataToRead(); - bool hasDataToReadWithWait(int waitMilliseconds); - protected: Mutex * getServerSynchAccessor(); @@ -208,6 +204,8 @@ protected: void setSocket(Socket *newSocket); void deleteSocket(); virtual void update() {} + + bool hasDataToRead(); }; }}//end namespace diff --git a/source/glest_game/network/network_interface.cpp b/source/glest_game/network/network_interface.cpp index 2b5d6e9fe..8a2491256 100644 --- a/source/glest_game/network/network_interface.cpp +++ b/source/glest_game/network/network_interface.cpp @@ -44,26 +44,25 @@ void NetworkInterface::sendMessage(const NetworkMessage* networkMessage){ networkMessage->send(socket); } -NetworkMessageType NetworkInterface::getNextMessageType(int waitMilliseconds) +NetworkMessageType NetworkInterface::getNextMessageType() { Socket* socket= getSocket(false); int8 messageType= nmtInvalid; if(socket != NULL && - socket->hasDataToReadWithWait(waitMilliseconds) == true) { - + socket->hasDataToRead() == true) { //peek message type - //int dataSize = socket->getDataToRead(); - //if(dataSize >= sizeof(messageType)) { - //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,dataSize); + int dataSize = socket->getDataToRead(); + if(dataSize >= sizeof(messageType)) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,dataSize); int iPeek = socket->peek(&messageType, sizeof(messageType)); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() iPeek = %d, messageType = %d [size = %d]\n",__FILE__,__FUNCTION__,__LINE__,iPeek,messageType,sizeof(messageType)); - //} - //else { - // if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] PEEK WARNING, socket->getDataToRead() messageType = %d [size = %d], dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,messageType,sizeof(messageType),dataSize); - //} + } + else { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] PEEK WARNING, socket->getDataToRead() messageType = %d [size = %d], dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,messageType,sizeof(messageType),dataSize); + } //sanity check new message type if(messageType < 0 || messageType >= nmtCount) { @@ -109,24 +108,19 @@ void NetworkInterface::DisplayErrorMessage(string sErr, bool closeSocket) { } } -std::vector NetworkInterface::getChatTextList(bool clearAfterRetrieve) { +std::vector NetworkInterface::getChatTextList(bool clearList) { std::vector result; - MutexSafeWrapper safeMutex(&mutexChatTextList,CODE_AT_LINE); - result = chatTextList; - if(clearAfterRetrieve == true) { - chatTextList.clear(); - } + if(chatTextList.empty() == false) { + result = chatTextList; + if(clearList == true) { + chatTextList.clear(); + } + } return result; } -void NetworkInterface::addChatInfo(const ChatMsgInfo &msg) { - MutexSafeWrapper safeMutex(&mutexChatTextList,CODE_AT_LINE); - chatTextList.push_back(msg); -} - void NetworkInterface::clearChatInfo() { - MutexSafeWrapper safeMutex(&mutexChatTextList,CODE_AT_LINE); if(chatTextList.empty() == false) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] chatTextList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,chatTextList.size()); chatTextList.clear(); diff --git a/source/glest_game/network/network_interface.h b/source/glest_game/network/network_interface.h index 1b09893d4..6928582ef 100644 --- a/source/glest_game/network/network_interface.h +++ b/source/glest_game/network/network_interface.h @@ -93,7 +93,6 @@ protected: string networkGameDataSynchCheckTechMismatchReport; bool receivedDataSynchCheck; - Mutex mutexChatTextList; std::vector chatTextList; NetworkMessagePing lastPingInfo; @@ -121,7 +120,7 @@ public: string getHostName() const {return Socket::getHostName();} virtual void sendMessage(const NetworkMessage* networkMessage); - NetworkMessageType getNextMessageType(int waitMilliseconds=100); + NetworkMessageType getNextMessageType(); bool receiveMessage(NetworkMessage* networkMessage); virtual bool isConnected(); @@ -142,9 +141,9 @@ public: virtual bool getNetworkGameDataSynchCheckOkTile() { return networkGameDataSynchCheckOkTile; } virtual bool getNetworkGameDataSynchCheckOkTech() { return networkGameDataSynchCheckOkTech; } - std::vector getChatTextList(bool clearAfterRetrieve); + std::vector getChatTextList(bool clearList); void clearChatInfo(); - void addChatInfo(const ChatMsgInfo &msg); + void addChatInfo(const ChatMsgInfo &msg) { chatTextList.push_back(msg); } virtual bool getConnectHasHandshaked() const= 0; diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 4c743f13b..6cea747cb 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -882,110 +882,6 @@ void ServerInterface::checkForLaggingClients(std::map &mapSlotSignalle } } -void ServerInterface::checkForLaggingClients(std::vector &errorMsgList) { - bool lastGlobalLagCheckTimeUpdate = false; - time_t waitForClientsElapsed = time(NULL); - time_t waitForThreadElapsed = time(NULL); - std::map slotsWarnedList; - // Examine all threads for completion of delegation - for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { - MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i)); - ConnectionSlot* connectionSlot = slots[i]; - if(connectionSlot != NULL) { - try { - std::vector errorList = connectionSlot->getThreadErrorList(); - // Show any collected errors from threads - if(errorList.empty() == false) { - for(int iErrIdx = 0; iErrIdx < errorList.size(); ++iErrIdx) { - string &sErr = errorList[iErrIdx]; - if(sErr != "") { - errorMsgList.push_back(sErr); - } - } - connectionSlot->clearThreadErrorList(); - } - - // New lag check - std::pair clientLagExceededOrWarned = std::make_pair(false,false); - if( gameHasBeenInitiated == true && - connectionSlot->isConnected() == true) { - clientLagExceededOrWarned = clientLagCheck(connectionSlot,slotsWarnedList[i]); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, gameSettings.getNetworkPauseGameForLaggedClients() = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,gameSettings.getNetworkPauseGameForLaggedClients()); - - if(clientLagExceededOrWarned.first == true) { - slotsWarnedList[i] = true; - } - } - // If the client has exceeded lag and the server wants - // to pause while they catch up, re-trigger the - // client reader thread -// if((clientLagExceededOrWarned.first == true && gameSettings.getNetworkPauseGameForLaggedClients() == true)) { // || -// //(clientLagExceededOrWarned.second == true && slotsWarnedAndRetried[i] == false)) { -// -// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, difftime(time(NULL),waitForClientsElapsed) = %.2f, MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE = %.2f\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,difftime(time(NULL),waitForClientsElapsed),MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE); -// -// if(difftime(time(NULL),waitForClientsElapsed) < MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE) { -// if(connectionSlot != NULL) { -// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second); -// -// bool socketTriggered = false; -// PLATFORM_SOCKET clientSocket = connectionSlot->getSocketId(); -// if(clientSocket > 0) { -// socketTriggered = socketTriggeredList[clientSocket]; -// } -// ConnectionSlotEvent &event = eventList[i]; -// mapSlotSignalledList[i] = signalClientReceiveCommands(connectionSlot,i,socketTriggered,event); -// threadsDone = false; -// } -// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second); -// } -// } - } - catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - errorMsgList.push_back(ex.what()); - } - } - - if(connectionSlot != NULL && connectionSlot->isConnected() == true) { - try { - if(gameHasBeenInitiated == true && - difftime(time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) { - - //printf("\n\n\n^^^^^^^^^^^^^^ PART A\n\n\n"); - - // New lag check - std::pair clientLagExceededOrWarned = std::make_pair(false,false); - if( gameHasBeenInitiated == true && connectionSlot != NULL && - connectionSlot->isConnected() == true) { - //printf("\n\n\n^^^^^^^^^^^^^^ PART B\n\n\n"); - - lastGlobalLagCheckTimeUpdate = true; - clientLagExceededOrWarned = clientLagCheck(connectionSlot,slotsWarnedList[i]); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, gameSettings.getNetworkPauseGameForLaggedClients() = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,gameSettings.getNetworkPauseGameForLaggedClients()); - - if(clientLagExceededOrWarned.first == true) { - slotsWarnedList[i] = true; - } - } - } - } - catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - errorMsgList.push_back(ex.what()); - } - } - } - - if(lastGlobalLagCheckTimeUpdate == true) { - lastGlobalLagCheckTime = time(NULL); - } -} - void ServerInterface::executeNetworkCommandsFromClients() { if(gameHasBeenInitiated == true) { for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { @@ -1010,13 +906,13 @@ void ServerInterface::dispatchPendingChatMessages(std::vector &errorMsg ConnectionSlot* connectionSlot= slots[i]; if(connectionSlot != NULL && connectionSlot->getChatTextList(false).empty() == false) { + std::vector chatList = connectionSlot->getChatTextList(true); try { - std::vector chatList = connectionSlot->getChatTextList(true); for(int chatIdx = 0; - exitServer == false && + exitServer == false && slots[i] != NULL && chatIdx < chatList.size(); chatIdx++) { - //connectionSlot= slots[i]; - //if(connectionSlot != NULL) { + connectionSlot= slots[i]; + if(connectionSlot != NULL) { ChatMsgInfo msg(chatList[chatIdx]); this->addChatInfo(msg); @@ -1033,7 +929,7 @@ void ServerInterface::dispatchPendingChatMessages(std::vector &errorMsg } if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); - //} + } } if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d\n",__FILE__,__FUNCTION__,__LINE__,i); @@ -1075,44 +971,41 @@ 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",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - //std::map socketTriggeredList; + std::map socketTriggeredList; //update all slots - //updateSocketTriggeredList(socketTriggeredList); + updateSocketTriggeredList(socketTriggeredList); //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",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - //if(gameHasBeenInitiated == false || socketTriggeredList.empty() == false) { - { + if(gameHasBeenInitiated == false || socketTriggeredList.empty() == false) { //printf("\nServerInterface::update -- E\n"); - //std::map eventList; - //bool hasData = Socket::hasDataToRead(socketTriggeredList); + std::map eventList; + bool hasData = Socket::hasDataToRead(socketTriggeredList); - //if(hasData) if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] hasData == true\n",__FILE__,__FUNCTION__); + if(hasData) if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] hasData == true\n",__FILE__,__FUNCTION__); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - //if(gameHasBeenInitiated == false || hasData == true) { - { - //std::map mapSlotSignalledList; + if(gameHasBeenInitiated == false || hasData == true) { + std::map mapSlotSignalledList; // Step #1 tell all connection slot worker threads to receive socket data - //signalClientsToRecieveData(socketTriggeredList, eventList, mapSlotSignalledList); + signalClientsToRecieveData(socketTriggeredList, eventList, mapSlotSignalledList); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #2\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); // Step #2 check all connection slot worker threads for completed status - //checkForCompletedClients(mapSlotSignalledList,errorMsgList, eventList); + checkForCompletedClients(mapSlotSignalledList,errorMsgList, eventList); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #3\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); // Step #3 check clients for any lagging scenarios and try to deal with them - //checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList); - checkForLaggingClients(errorMsgList); + checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #4\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); @@ -1129,27 +1022,27 @@ 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",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } -// else if(gameHasBeenInitiated == true && -// difftime(time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) { -// //printf("\nServerInterface::update -- E1\n"); -// -// //std::map eventList; -// std::map mapSlotSignalledList; -// -// checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList); -// } + else if(gameHasBeenInitiated == true && + difftime(time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) { + //printf("\nServerInterface::update -- E1\n"); + + //std::map eventList; + std::map mapSlotSignalledList; + + checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList); + } if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } -// else if(gameHasBeenInitiated == true && -// difftime(time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) { -// //printf("\nServerInterface::update -- F\n"); -// -// std::map eventList; -// std::map mapSlotSignalledList; -// -// checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList); -// } + else if(gameHasBeenInitiated == true && + difftime(time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) { + //printf("\nServerInterface::update -- F\n"); + + std::map eventList; + std::map mapSlotSignalledList; + + checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList); + } //printf("\nServerInterface::update -- G\n"); } @@ -1343,7 +1236,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) { ConnectionSlot* connectionSlot= slots[i]; if(connectionSlot != NULL && connectionSlot->isConnected() == true) { if(connectionSlot->isReady() == false) { - NetworkMessageType networkMessageType= connectionSlot->getNextMessageType(0); + NetworkMessageType networkMessageType= connectionSlot->getNextMessageType(); // consume old messages from the lobby bool discarded = shouldDiscardNetworkMessage(networkMessageType,connectionSlot); diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index 2dc33692f..b79a2924a 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -207,7 +207,6 @@ protected: void signalClientsToRecieveData(std::map & socketTriggeredList, std::map & eventList, std::map & mapSlotSignalledList); void checkForCompletedClients(std::map & mapSlotSignalledList,std::vector &errorMsgList,std::map &eventList); void checkForLaggingClients(std::map &mapSlotSignalledList, std::map &eventList, std::map &socketTriggeredList,std::vector &errorMsgList); - void checkForLaggingClients(std::vector &errorMsgList); void executeNetworkCommandsFromClients(); void dispatchPendingChatMessages(std::vector &errorMsgList); };