From a8fdd98a0e90fec12c07f16ecad3d9d28c3703c3 Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 31 Oct 2019 11:36:03 +0800 Subject: [PATCH] Add a high ping workaround in server This will allow around ping with 400ms to have a playable game with the default values of max-ping and jitter-tolerance, as long as the internet connection is stable (no packet loss) --- NETWORKING.md | 3 +++ src/network/protocols/server_lobby.cpp | 7 +++++-- src/network/server_config.cpp | 2 ++ src/network/server_config.hpp | 7 +++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/NETWORKING.md b/NETWORKING.md index 3bed93262..615110274 100644 --- a/NETWORKING.md +++ b/NETWORKING.md @@ -144,6 +144,9 @@ The current server configuration xml looks like this: + + + diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index 1be3ad0b3..edd3840b1 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -4033,6 +4033,7 @@ void ServerLobby::configPeersStartTime() { uint32_t max_ping = 0; const unsigned max_ping_from_peers = ServerConfig::m_max_ping; + bool peer_exceeded_max_ping = false; for (auto p : m_peers_ready) { auto peer = p.first.lock(); @@ -4043,14 +4044,16 @@ void ServerLobby::configPeersStartTime() Log::warn("ServerLobby", "Peer %s cannot catch up with max ping %d.", peer->getRealAddress().c_str(), max_ping); + peer_exceeded_max_ping = true; continue; } max_ping = std::max(peer->getAveragePing(), max_ping); } - if (ServerConfig::m_live_players && race_manager->supportsLiveJoining()) + if ((ServerConfig::m_high_ping_workaround && peer_exceeded_max_ping) || + (ServerConfig::m_live_players && race_manager->supportsLiveJoining())) { Log::info("ServerLobby", "Max ping to ServerConfig::m_max_ping for " - "live joining."); + "live joining or high ping workaround."); max_ping = ServerConfig::m_max_ping; } // Start up time will be after 2500ms, so even if this packet is sent late diff --git a/src/network/server_config.cpp b/src/network/server_config.cpp index 3ee90276d..e7767c9af 100644 --- a/src/network/server_config.cpp +++ b/src/network/server_config.cpp @@ -330,6 +330,8 @@ void loadServerLobbyFromConfig() if (m_live_players) m_official_karts_threshold = 1.0f; + if (m_high_ping_workaround) + m_kick_high_ping_players = false; auto modes = getLocalGameModeFromConfig(); race_manager->setMinorMode(modes.first); race_manager->setMajorMode(modes.second); diff --git a/src/network/server_config.hpp b/src/network/server_config.hpp index 118d1221a..5623ec4f4 100644 --- a/src/network/server_config.hpp +++ b/src/network/server_config.hpp @@ -311,6 +311,13 @@ namespace ServerConfig "kick-high-ping-players", "Kick players whose ping is above max-ping.")); + SERVER_CFG_PREFIX BoolServerConfigParam m_high_ping_workaround + SERVER_CFG_DEFAULT(BoolServerConfigParam(true, + "high-ping-workaround", + "Allow players exceeding max-ping to have a playable game, if enabled " + "kick-high-ping-players will be disabled, please also use a default " + "value for max-ping and jitter-tolerance with it.")); + SERVER_CFG_PREFIX IntServerConfigParam m_kick_idle_player_seconds SERVER_CFG_DEFAULT(IntServerConfigParam(60, "kick-idle-player-seconds",