From fd9c9856cf81574b98cd4ec7af8c9f9c75511344 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 22 Sep 2012 05:37:43 +0000 Subject: [PATCH] - add a silent ini setting in case the auto lag code needs to be turned off down the road: AutoClientLagCorrection=true (hard coded, add and set as false in ini if required, this onhly affects game hosts) --- source/glest_game/network/connection_slot.cpp | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index ebd06a569..721de584b 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -1135,26 +1135,29 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { } } - //!!! - double LAG_CHECK_GRACE_PERIOD = 15; - double maxFrameCountLagAllowed = 10; - double maxClientLagTimeAllowed = 8; + // This may end up continuously lagging and not disconnecting players who have + // just the 'wrong' amount of lag (but not enough to be horrible for a disconnect) + if(Config::getInstance().getBool("AutoClientLagCorrection","true") == true) { + double LAG_CHECK_GRACE_PERIOD = 15; + double maxFrameCountLagAllowed = 10; + double maxClientLagTimeAllowed = 8; - 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()); + 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)) { + // New lag check + if((maxFrameCountLagAllowed > 0 && clientLagCount > maxFrameCountLagAllowed) || + (maxClientLagTimeAllowed > 0 && clientLagTime > maxClientLagTimeAllowed)) { - waitForLaggingClient = true; - if(waitedForLaggingClient == false) { - waitedForLaggingClient = true; - printf("*TESTING*: START Waiting for lagging client playerIndex = %d [%s] clientLagCount = %f [%f]\n",playerIndex,name.c_str(),clientLagCount,clientLagTime); + waitForLaggingClient = true; + if(waitedForLaggingClient == false) { + waitedForLaggingClient = true; + printf("*TESTING*: START Waiting for lagging client playerIndex = %d [%s] clientLagCount = %f [%f]\n",playerIndex,name.c_str(),clientLagCount,clientLagTime); + } } } }