diff options
Diffstat (limited to 'src/network/network_client.cpp')
-rw-r--r-- | src/network/network_client.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 7a7ec9f21..cd1904269 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -877,7 +877,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet bool load_success = SafeLoad({}, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf); /* Long savegame loads shouldn't affect the lag calculation! */ - this->last_packet = _realtime_tick; + this->last_packet = std::chrono::steady_clock::now(); if (!load_success) { DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); @@ -1178,27 +1178,23 @@ void ClientNetworkGameSocketHandler::CheckConnection() /* Only once we're authorized we can expect a steady stream of packets. */ if (this->status < STATUS_AUTHORIZED) return; - /* It might... sometimes occur that the realtime ticker overflows. */ - if (_realtime_tick < this->last_packet) this->last_packet = _realtime_tick; - - /* Lag is in milliseconds; 5 seconds are roughly twice the - * server's "you're slow" threshold (1 game day). */ - uint lag = (_realtime_tick - this->last_packet) / 1000; - if (lag < 5) return; + /* 5 seconds are roughly twice the server's "you're slow" threshold (1 game day). */ + std::chrono::steady_clock::duration lag = std::chrono::steady_clock::now() - this->last_packet; + if (lag < std::chrono::seconds(5)) return; /* 20 seconds are (way) more than 4 game days after which * the server will forcefully disconnect you. */ - if (lag > 20) { + if (lag > std::chrono::seconds(20)) { this->NetworkGameSocketHandler::CloseConnection(); return; } /* Prevent showing the lag message every tick; just update it when needed. */ - static uint last_lag = 0; - if (last_lag == lag) return; + static std::chrono::steady_clock::duration last_lag = {}; + if (std::chrono::duration_cast<std::chrono::seconds>(last_lag) == std::chrono::duration_cast<std::chrono::seconds>(lag)) return; last_lag = lag; - SetDParam(0, lag); + SetDParam(0, std::chrono::duration_cast<std::chrono::seconds>(lag).count()); ShowErrorMessage(STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION_CAPTION, STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION, WL_INFO); } |