mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-27 22:33:06 +00:00
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:
@@ -672,6 +672,8 @@ bool CNetClient::OnPlayerAssignment(void* context, CFsmEvent* event)
|
||||
return true;
|
||||
}
|
||||
|
||||
// This is called either when the host clicks the StartGame button or
|
||||
// if this client rejoins and finishes the download of the simstate.
|
||||
bool CNetClient::OnGameStart(void* context, CFsmEvent* event)
|
||||
{
|
||||
ENSURE(event->GetType() == (uint)NMT_GAME_START);
|
||||
@@ -680,6 +682,8 @@ bool CNetClient::OnGameStart(void* context, CFsmEvent* event)
|
||||
JSContext* cx = client->GetScriptInterface().GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
client->m_Session->SetLongTimeout(true);
|
||||
|
||||
// Find the player assigned to our GUID
|
||||
int player = -1;
|
||||
if (client->m_PlayerAssignments.find(client->m_GUID) != client->m_PlayerAssignments.end())
|
||||
@@ -820,15 +824,26 @@ bool CNetClient::OnClientsLoading(void *context, CFsmEvent *event)
|
||||
|
||||
CClientsLoadingMessage* message = (CClientsLoadingMessage*)event->GetParamRef();
|
||||
|
||||
std::vector<CStr> guids;
|
||||
guids.reserve(message->m_Clients.size());
|
||||
for (const CClientsLoadingMessage::S_m_Clients& client : message->m_Clients)
|
||||
guids.push_back(client.m_GUID);
|
||||
|
||||
CNetClient* client = (CNetClient*)context;
|
||||
JSContext* cx = client->GetScriptInterface().GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
bool finished = true;
|
||||
std::vector<CStr> guids;
|
||||
guids.reserve(message->m_Clients.size());
|
||||
for (const CClientsLoadingMessage::S_m_Clients& mClient : message->m_Clients)
|
||||
{
|
||||
if (client->m_GUID == mClient.m_GUID)
|
||||
finished = false;
|
||||
|
||||
guids.push_back(mClient.m_GUID);
|
||||
}
|
||||
|
||||
// Disable the timeout here after processing the enet message, so as to ensure that the connection isn't currently
|
||||
// timing out (as it is when just leaving the loading screen in LoadFinished).
|
||||
if (finished)
|
||||
client->m_Session->SetLongTimeout(false);
|
||||
|
||||
JS::RootedValue msg(cx);
|
||||
client->GetScriptInterface().Eval("({ 'type':'clients-loading' })", &msg);
|
||||
client->GetScriptInterface().SetProperty(msg, "guids", guids);
|
||||
@@ -875,6 +890,9 @@ bool CNetClient::OnLoadedGame(void* context, CFsmEvent* event)
|
||||
if (client->m_Rejoin)
|
||||
client->SendRejoinedMessage();
|
||||
|
||||
// The last client to leave the loading screen didn't receive the CClientsLoadingMessage, so disable here.
|
||||
client->m_Session->SetLongTimeout(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user