From 159a273aa1a8112c6906668adbc05b901dfb6b79 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 21 Jul 2012 00:23:27 +0000 Subject: [PATCH] - bold change to see what this does for network play (CAUTION THIS is for testing only and may be reverted) --- source/glest_game/network/connection_slot.cpp | 29 +++++++++++++++++-- .../glest_game/network/server_interface.cpp | 3 +- source/glest_game/network/server_interface.h | 2 ++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 4c7b8633..a6d4ca07 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -497,8 +497,11 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { bool gotTextMsg = true; bool gotCellMarkerMsg = true; - for(;this->hasDataToRead() == true && - (gotTextMsg == true || gotCellMarkerMsg == true);) { + bool waitForLaggingClient = false; + for(;waitForLaggingClient == true || + (this->hasDataToRead() == true && + (gotTextMsg == true || gotCellMarkerMsg == true));) { + waitForLaggingClient = false; 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(); @@ -1128,6 +1131,28 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { } } } + + //!!! + double LAG_CHECK_GRACE_PERIOD = 15; + double maxFrameCountLagAllowed = 7; + double maxClientLagTimeAllowed = 7; + + if(this->serverInterface->getGameStartTime() > 0 && + difftime(time(NULL),this->serverInterface->getGameStartTime()) >= LAG_CHECK_GRACE_PERIOD) { + if(this->isConnected() == true) { + double clientLag = this->serverInterface->getCurrentFrameCount() - this->getCurrentFrameCount(); + double clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0); + double clientLagTime = difftime(time(NULL),this->getLastReceiveCommandListTime()); + + // New lag check + if((maxFrameCountLagAllowed > 0 && clientLagCount > maxFrameCountLagAllowed) || + (maxClientLagTimeAllowed > 0 && clientLagTime > maxClientLagTimeAllowed)) { + waitForLaggingClient = true; + + printf("*TESTING*: Waiting for lagging client playerIndex = %d clientLagCount = %f [%f]\n",playerIndex,clientLagCount,clientLagTime); + } + } + } } //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index b2508d6c..a0606881 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -657,7 +657,8 @@ std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionS try { alreadyInLagCheck = true; - if(difftime(time(NULL),gameStartTime) >= LAG_CHECK_GRACE_PERIOD) { + if(gameStartTime > 0 && + difftime(time(NULL),gameStartTime) >= LAG_CHECK_GRACE_PERIOD) { if(connectionSlot != NULL && connectionSlot->isConnected() == true) { double clientLag = this->getCurrentFrameCount() - connectionSlot->getCurrentFrameCount(); double clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0); diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index f3dd9767..1b79a148 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -104,6 +104,8 @@ public: // return &serverSocket; //} + time_t getGameStartTime() const { return gameStartTime; } + virtual void close(); virtual void update(); virtual void updateLobby() { };