1
0
forked from 0ad/0ad

Always inform clients why the server chose to disconnect them, i.e. stop using NDR_UNKNOWN as a disconnect reason when the reason is known and add a LOGWARNING for future authors.

Differential Revision: https://code.wildfiregames.com/D1561
Tested on: clang 8.0.1, Jenkins

This was SVN commit r22996.
This commit is contained in:
elexis 2019-09-26 11:36:03 +00:00
parent 767c7f5856
commit 0817d5d715
6 changed files with 34 additions and 17 deletions

View File

@ -73,6 +73,9 @@ function getDisconnectReason(id, wasConnected)
case 7: return translate("Playername in use. If you were disconnected, retry in few seconds.");
case 8: return translate("Server full.");
case 9: return translate("Secure lobby authentication failed. Join via lobby.");
case 10: return translate("Error: Server failed to allocate a unique client identifier.");
case 11: return translate("Error: Client commands were ready for an unexpected game turn.");
case 12: return translate("Error: Client simulated an unexpected game turn.");
default:
warn("Unknown disconnect-reason ID received: " + id);
return sprintf(translate("\\[Invalid value %(id)s]"), { "id": id });

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -56,6 +56,8 @@ typedef std::map<CStr, PlayerAssignment> PlayerAssignmentMap; // map from GUID -
/**
* Reasons sent by server to clients in disconnection messages.
* Must be kept in sync with binaries/data/mods/public/gui/common/network.js
* To avoid ambiguity, use a distinct reason for each callstack leading to a disconnect.
* NDR_UNKNOWN should remain reserved to the case where it is actually not a known disconnect by the server.
*/
enum NetDisconnectReason
{
@ -68,7 +70,10 @@ enum NetDisconnectReason
NDR_BANNED,
NDR_PLAYERNAME_IN_USE,
NDR_SERVER_FULL,
NDR_LOBBY_AUTH_FAILED
NDR_LOBBY_AUTH_FAILED,
NDR_GUID_FAILED,
NDR_INCORRECT_READY_TURN_COMMANDS,
NDR_INCORRECT_READY_TURN_SIMULATED
};
class CNetHost

View File

@ -923,7 +923,7 @@ bool CNetServerWorker::OnClientHandshake(void* context, CFsmEvent* event)
{
if (++count > 100)
{
session->Disconnect(NDR_UNKNOWN);
session->Disconnect(NDR_GUID_FAILED);
return true;
}
guid = ps_generate_guid();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -58,7 +58,7 @@ void CNetServerTurnManager::NotifyFinishedClientCommands(CNetServerSession& sess
turn,
m_ClientsReady[client] + 1);
session.Disconnect(NDR_UNKNOWN);
session.Disconnect(NDR_INCORRECT_READY_TURN_COMMANDS);
}
m_ClientsReady[client] = turn;
@ -106,7 +106,7 @@ void CNetServerTurnManager::NotifyFinishedClientUpdate(CNetServerSession& sessio
turn,
m_ClientsReady[client] + 1);
session.Disconnect(NDR_UNKNOWN);
session.Disconnect(NDR_INCORRECT_READY_TURN_SIMULATED);
}
m_ClientsSimulated[client] = turn;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -115,12 +115,15 @@ bool CNetClientSession::Connect(const CStr& server, const u16 port, const bool i
return true;
}
void CNetClientSession::Disconnect(u32 reason)
void CNetClientSession::Disconnect(NetDisconnectReason reason)
{
if (reason == NDR_UNKNOWN)
LOGWARNING("Disconnecting from the server without communicating the disconnect reason!");
ENSURE(m_Host && m_Server);
// TODO: ought to do reliable async disconnects, probably
enet_peer_disconnect_now(m_Server, reason);
enet_peer_disconnect_now(m_Server, static_cast<enet_uint32>(reason));
enet_host_destroy(m_Host);
m_Host = NULL;
@ -252,16 +255,22 @@ u32 CNetServerSession::GetMeanRTT() const
return m_Peer->roundTripTime;
}
void CNetServerSession::Disconnect(u32 reason)
void CNetServerSession::Disconnect(NetDisconnectReason reason)
{
if (reason == NDR_UNKNOWN)
LOGWARNING("Disconnecting client without communicating the disconnect reason!");
Update((uint)NMT_CONNECTION_LOST, NULL);
enet_peer_disconnect(m_Peer, reason);
enet_peer_disconnect(m_Peer, static_cast<enet_uint32>(reason));
}
void CNetServerSession::DisconnectNow(u32 reason)
void CNetServerSession::DisconnectNow(NetDisconnectReason reason)
{
enet_peer_disconnect_now(m_Peer, reason);
if (reason == NDR_UNKNOWN)
LOGWARNING("Disconnecting client without communicating the disconnect reason!");
enet_peer_disconnect_now(m_Peer, static_cast<enet_uint32>(reason));
}
bool CNetServerSession::SendMessage(const CNetMessage* message)

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -88,7 +88,7 @@ public:
* Disconnect from the server.
* Sends a disconnection notification to the server.
*/
void Disconnect(u32 reason);
void Disconnect(NetDisconnectReason reason);
/**
* Send a message to the server.
@ -175,14 +175,14 @@ public:
* The server will receive a disconnection notification after a while.
* The server will not receive any further messages sent via this session.
*/
void Disconnect(u32 reason);
void Disconnect(NetDisconnectReason reason);
/**
* Sends an unreliable disconnection notification to the client.
* The server will not receive any disconnection notification.
* The server will not receive any further messages sent via this session.
*/
void DisconnectNow(u32 reason);
void DisconnectNow(NetDisconnectReason reason);
/**
* Prevent timeouts for the client running in the same process as the server.