From 056e596d5ab02c71124d40b9bfca2b098a76d3a8 Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 22 May 2018 02:06:16 +0800 Subject: [PATCH] Fix debug build and clean up --- src/network/stk_host.cpp | 19 ++++++++----------- src/network/stk_peer.cpp | 9 +++++++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/network/stk_host.cpp b/src/network/stk_host.cpp index 70321003a..76dd4e857 100644 --- a/src/network/stk_host.cpp +++ b/src/network/stk_host.cpp @@ -716,12 +716,15 @@ void STKHost::mainLoop() while (m_exit_timeout.load() > StkTime::getRealTime()) { - auto server_peer = getServerPeerForClient(); - if (!is_server && server_peer && - StkTime::getRealTime() - server_peer->getConnectedTime() > 3.0) + if (!is_server) { - // Back to default ping interval for client - server_peer->setPingInterval(0); + auto server_peer = getServerPeerForClient(); + if (server_peer && + StkTime::getRealTime() - server_peer->getConnectedTime() > 3.0) + { + // Back to default ping interval for client + server_peer->setPingInterval(0); + } } auto sl = LobbyProtocol::get(); @@ -793,12 +796,6 @@ void STKHost::mainLoop() { auto stk_peer = std::make_shared (event.peer, this, m_next_unique_host_id++); - if (!is_server) - { - // This allow client to get the correct ping as fast as - // possible - stk_peer->setPingInterval(10); - } std::unique_lock lock(m_peers_mutex); m_peers[event.peer] = stk_peer; lock.unlock(); diff --git a/src/network/stk_peer.cpp b/src/network/stk_peer.cpp index 37d5055d4..d274fc784 100644 --- a/src/network/stk_peer.cpp +++ b/src/network/stk_peer.cpp @@ -18,7 +18,7 @@ #include "network/stk_peer.hpp" #include "config/user_config.hpp" -#include "network/game_setup.hpp" +#include "network/network_config.hpp" #include "network/network_string.hpp" #include "network/network_player_profile.hpp" #include "network/stk_host.hpp" @@ -37,7 +37,12 @@ STKPeer::STKPeer(ENetPeer *enet_peer, STKHost* host, uint32_t host_id) m_host_id = host_id; m_connected_time = (float)StkTime::getRealTime(); m_token_set.store(false); - setPingInterval(10); + if (NetworkConfig::get()->isClient()) + { + // This allow client to get the correct ping as fast as possible + // reset to default (0) will be done in STKHost::mainloop after 3 sec + setPingInterval(10); + } m_client_server_token.store(0); } // STKPeer