From e135baba85d2b2e18ed6f4c753dec065e87b34e3 Mon Sep 17 00:00:00 2001 From: andy5995 Date: Fri, 2 Mar 2018 14:24:54 -0600 Subject: [PATCH] server_interface:lag:allow a greater grace period before dropping player --- source/glest_game/network/connection_slot.cpp | 28 ++++++++++++------ source/glest_game/network/connection_slot.h | 29 ++++++++++++++----- .../glest_game/network/server_interface.cpp | 13 +++++++-- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 6dc7ad346..dcaac4362 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -1,13 +1,22 @@ -// ============================================================== -// This file is part of Glest (www.glest.org) +// connection_slot.cpp: +// connected clients (not the host or user setting up the game) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2018 The ZetaGlest team // -// You can redistribute this code and/or modify it under -// the terms of the GNU General Public License as published -// by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version -// ============================================================== +// ZetaGlest is a fork of MegaGlest +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . #include "connection_slot.h" @@ -371,6 +380,7 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex this->platform = ""; this->currentFrameCount = 0; this->currentLagCount = 0; + this->graceLagCtr = 0; this->gotLagCountWarning = false; this->lastReceiveCommandListTime = 0; this->receivedNetworkGameStatus = false; @@ -1451,7 +1461,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { } void ConnectionSlot::validateConnection() { - if(this->isConnected() == true && + if(this->isConnected() == true && gotIntro == false && connectedTime > 0 && difftime((long int)time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) { diff --git a/source/glest_game/network/connection_slot.h b/source/glest_game/network/connection_slot.h index e4168da6e..b4165ed2e 100644 --- a/source/glest_game/network/connection_slot.h +++ b/source/glest_game/network/connection_slot.h @@ -1,13 +1,22 @@ -// ============================================================== -// This file is part of Glest (www.glest.org) +// connection_slot.h: +// connected clients (not the host or user setting up the game) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2018 The ZetaGlest team // -// You can redistribute this code and/or modify it under -// the terms of the GNU General Public License as published -// by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version -// ============================================================== +// ZetaGlest is a fork of MegaGlest +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . #ifndef _GLEST_GAME_CONNECTIONSLOT_H_ #define _GLEST_GAME_CONNECTIONSLOT_H_ @@ -145,6 +154,7 @@ private: ConnectionSlotThread* slotThreadWorker; int currentFrameCount; int currentLagCount; + int graceLagCtr; time_t lastReceiveCommandListTime; bool gotLagCountWarning; string versionString; @@ -187,6 +197,9 @@ public: bool getSkipLagCheck() const { return skipLagCheck; } bool getJoinGameInProgress() const { return joinGameInProgress; } + int getGraceLagCtr() { return graceLagCtr++; } + void resetGraceLagCtr() { graceLagCtr = 0; } + bool getSentSavedGameInfo() const { return sentSavedGameInfo; } void setSentSavedGameInfo(bool value) { sentSavedGameInfo = value; } diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index d8218ba43..42916dd3c 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -58,6 +58,7 @@ double maxClientLagTimeAllowedEver = 25; double warnFrameCountLagPercent = 0.50; double LAG_CHECK_GRACE_PERIOD = 15; double LAG_CHECK_INTERVAL_PERIOD = 4; +int GRACE_LAG_CTR_LIMIT = 5; const int MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE_MILLISECONDS = 15000; const int MAX_CLIENT_PAUSE_FOR_LAG_COUNT = 3; @@ -802,12 +803,16 @@ std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionS } } - if(gameSettings.getNetworkPauseGameForLaggedClients() == false || + if((gameSettings.getNetworkPauseGameForLaggedClients() == false || (maxFrameCountLagAllowedEver > 0 && clientLagCount > maxFrameCountLagAllowedEver) || - (maxClientLagTimeAllowedEver > 0 && clientLagTime > maxClientLagTimeAllowedEver)) { + (maxClientLagTimeAllowedEver > 0 && clientLagTime > maxClientLagTimeAllowedEver) && + connectionSlot->getGraceLagCtr() > GRACE_LAG_CTR_LIMIT)) { //printf("Closing connection slot lagged out!\n"); connectionSlot->close(); + // not needed now, but will be needed when in-game joins and rejoins + // are used + connectionSlot->resetGraceLagCtr(); } } @@ -1115,8 +1120,10 @@ void ServerInterface::checkForAutoPauseForLaggingClient(int index,ConnectionSlot connectionSlot->incrementAutoPauseGameCountForLag(); this->clientsAutoPausedDueToLag = true; - if (this->clientLagCallbackInterface->clientLagHandler(index, true) == false) { + if ((this->clientLagCallbackInterface->clientLagHandler(index, true) == false) && + connectionSlot->getGraceLagCtr() > GRACE_LAG_CTR_LIMIT) { connectionSlot->close(); + connectionSlot->resetGraceLagCtr(); } else { if (this->clientsAutoPausedDueToLagTimer.isStarted()== true) {