Index: ps/trunk/binaries/data/mods/public/gui/common/network.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/common/network.js +++ ps/trunk/binaries/data/mods/public/gui/common/network.js @@ -73,6 +73,9 @@ 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 }); Index: ps/trunk/source/network/NetHost.h =================================================================== --- ps/trunk/source/network/NetHost.h +++ ps/trunk/source/network/NetHost.h @@ -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 @@ /** * 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 @@ 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 Index: ps/trunk/source/network/NetServer.cpp =================================================================== --- ps/trunk/source/network/NetServer.cpp +++ ps/trunk/source/network/NetServer.cpp @@ -923,7 +923,7 @@ { if (++count > 100) { - session->Disconnect(NDR_UNKNOWN); + session->Disconnect(NDR_GUID_FAILED); return true; } guid = ps_generate_guid(); Index: ps/trunk/source/network/NetServerTurnManager.cpp =================================================================== --- ps/trunk/source/network/NetServerTurnManager.cpp +++ ps/trunk/source/network/NetServerTurnManager.cpp @@ -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 @@ turn, m_ClientsReady[client] + 1); - session.Disconnect(NDR_UNKNOWN); + session.Disconnect(NDR_INCORRECT_READY_TURN_COMMANDS); } m_ClientsReady[client] = turn; @@ -106,7 +106,7 @@ turn, m_ClientsReady[client] + 1); - session.Disconnect(NDR_UNKNOWN); + session.Disconnect(NDR_INCORRECT_READY_TURN_SIMULATED); } m_ClientsSimulated[client] = turn; Index: ps/trunk/source/network/NetSession.h =================================================================== --- ps/trunk/source/network/NetSession.h +++ ps/trunk/source/network/NetSession.h @@ -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 @@ * 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 @@ * 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. Index: ps/trunk/source/network/NetSession.cpp =================================================================== --- ps/trunk/source/network/NetSession.cpp +++ ps/trunk/source/network/NetSession.cpp @@ -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 @@ 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(reason)); enet_host_destroy(m_Host); m_Host = NULL; @@ -252,16 +255,22 @@ 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(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(reason)); } bool CNetServerSession::SendMessage(const CNetMessage* message)