forked from mirrors/0ad
Prevent players from disconnecting during the loading screen by increasing the timeout tolerance to 60 seconds for that period, fixes #5163.
The NetClient runs in the main thread, so any part of the loading screen consuming several seconds makes that client timeout. This is a workaround because threading the NetClient would have prevent these timeouts, refs #3700. Coutnerintuitively, since enet timeout tolerance is proportional to the latency, the better the connection of the player, the more likely it was to drop on gamestart. This problem became very frequent in Alpha 23, at least due to the Aura bugfix583b6ec625, AIInterface being particularly slow and that not having been disabled yet in the loading screen resulting in additional 10 second freezes during the loading screen, even on empty maps, refs #5200,8e168f85e6. Differential Revision: https://code.wildfiregames.com/D1513 Based on patch by: causative This was SVN commit r21842.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "NetStats.h"
|
||||
#include "lib/external_libraries/enet.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/ConfigDB.h"
|
||||
#include "ps/Profile.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
|
||||
@@ -32,6 +33,25 @@ const u32 MAXIMUM_HOST_TIMEOUT = std::numeric_limits<u32>::max();
|
||||
|
||||
static const int CHANNEL_COUNT = 1;
|
||||
|
||||
// Only disable long timeouts after a packet from the remote enet peer has been processed.
|
||||
// Otherwise a long timeout can still be in progress when disabling it here.
|
||||
void SetEnetLongTimeout(ENetPeer* peer, bool isLocalClient, bool enabled)
|
||||
{
|
||||
#if (ENET_VERSION >= ENET_VERSION_CREATE(1, 3, 4))
|
||||
if (!peer || isLocalClient)
|
||||
return;
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
u32 timeout;
|
||||
CFG_GET_VAL("network.gamestarttimeout", timeout);
|
||||
enet_peer_timeout(peer, 0, timeout, timeout);
|
||||
}
|
||||
else
|
||||
enet_peer_timeout(peer, 0, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
CNetClientSession::CNetClientSession(CNetClient& client) :
|
||||
m_Client(client), m_FileTransferer(this), m_Host(nullptr), m_Server(nullptr), m_Stats(nullptr), m_IsLocalClient(false)
|
||||
{
|
||||
@@ -201,6 +221,11 @@ u32 CNetClientSession::GetMeanRTT() const
|
||||
return m_Server->roundTripTime;
|
||||
}
|
||||
|
||||
void CNetClientSession::SetLongTimeout(bool enabled)
|
||||
{
|
||||
SetEnetLongTimeout(m_Server, m_IsLocalClient, enabled);
|
||||
}
|
||||
|
||||
CNetServerSession::CNetServerSession(CNetServerWorker& server, ENetPeer* peer) :
|
||||
m_Server(server), m_FileTransferer(this), m_Peer(peer), m_IsLocalClient(false), m_HostID(0), m_GUID(), m_UserName()
|
||||
{
|
||||
@@ -261,3 +286,8 @@ void CNetServerSession::SetLocalClient(bool isLocalClient)
|
||||
enet_peer_timeout(m_Peer, 0, MAXIMUM_HOST_TIMEOUT, MAXIMUM_HOST_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CNetServerSession::SetLongTimeout(bool enabled)
|
||||
{
|
||||
SetEnetLongTimeout(m_Peer, m_IsLocalClient, enabled);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user