From f2ed0098eebe6e79faff7ac31f24e01e7cee13bd Mon Sep 17 00:00:00 2001 From: elexis Date: Wed, 9 Mar 2016 15:02:38 +0000 Subject: [PATCH] Make the playername-deduplication ("User" -> "User (2)") optional. Have it disabled by default to fix #3604. Prevents players from rejoining as late-observers in case they timed-out on the client-side but not on the server-side. This was SVN commit r17851. --- binaries/data/config/default.cfg | 3 +++ binaries/data/mods/public/gui/common/network.js | 1 + source/network/NetHost.h | 3 ++- source/network/NetMessages.h | 2 +- source/network/NetServer.cpp | 17 ++++++++++++++++- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index e1c48e7df4..dc4610bd5a 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -349,6 +349,9 @@ xpartamupp = "wfgbot20" ; Name of the server-side xmpp client that m [mod] enabledmods = "mod public" +[network] +duplicatePlayernames = false ; Rename joining player to "User (2)" if "User" is already connected, otherwise prohibit join. + [overlay] fps = "false" ; Show frames per second in top right corner realtime = "false" ; Show current system time in top right corner diff --git a/binaries/data/mods/public/gui/common/network.js b/binaries/data/mods/public/gui/common/network.js index 533a88c922..bf88125937 100644 --- a/binaries/data/mods/public/gui/common/network.js +++ b/binaries/data/mods/public/gui/common/network.js @@ -57,6 +57,7 @@ function getDisconnectReason(id) case 4: return translate("Game has already started, no observers allowed"); case 5: return translate("You have been kicked"); case 6: return translate("You have been banned"); + case 7: return translate("Playername in use. If you were disconnected, retry in few seconds"); default: warn("Unknown disconnect-reason ID received: " + id); return sprintf(translate("\\[Invalid value %(id)s]"), { "id": id }); diff --git a/source/network/NetHost.h b/source/network/NetHost.h index c57259941a..8b72d7dd1b 100644 --- a/source/network/NetHost.h +++ b/source/network/NetHost.h @@ -65,7 +65,8 @@ enum NetDisconnectReason NDR_SERVER_LOADING, NDR_SERVER_ALREADY_IN_GAME, NDR_KICKED, - NDR_BANNED + NDR_BANNED, + NDR_PLAYERNAME_IN_USE }; class CNetHost diff --git a/source/network/NetMessages.h b/source/network/NetMessages.h index b27f307d26..6c9d0136a2 100644 --- a/source/network/NetMessages.h +++ b/source/network/NetMessages.h @@ -28,7 +28,7 @@ #define PS_PROTOCOL_MAGIC 0x5073013f // 'P', 's', 0x01, '?' #define PS_PROTOCOL_MAGIC_RESPONSE 0x50630121 // 'P', 'c', 0x01, '!' -#define PS_PROTOCOL_VERSION 0x01010009 // Arbitrary protocol +#define PS_PROTOCOL_VERSION 0x01010010 // Arbitrary protocol #define PS_DEFAULT_PORT 0x5073 // 'P', 's' // Defines the list of message types. The order of the list must not change. diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp index 248277a1c1..d8d8d1c61d 100644 --- a/source/network/NetServer.cpp +++ b/source/network/NetServer.cpp @@ -901,7 +901,22 @@ bool CNetServerWorker::OnAuthenticate(void* context, CFsmEvent* event) } CAuthenticateMessage* message = (CAuthenticateMessage*)event->GetParamRef(); - CStrW username = server.DeduplicatePlayerName(SanitisePlayerName(message->m_Name)); + CStrW username = SanitisePlayerName(message->m_Name); + + // Either deduplicate or prohibit join if name is in use + bool duplicatePlayernames = false; + CFG_GET_VAL("network.duplicatePlayernames", duplicatePlayernames); + if (duplicatePlayernames) + username = server.DeduplicatePlayerName(username); + else if (std::find_if( + server.m_Sessions.begin(), server.m_Sessions.end(), + [&username] (const CNetServerSession* session) + { return session->GetUserName() == username; }) + != server.m_Sessions.end()) + { + session->Disconnect(NDR_PLAYERNAME_IN_USE); + return true; + } // Disconnect banned usernames if (std::find(server.m_BannedPlayers.begin(), server.m_BannedPlayers.end(), username) != server.m_BannedPlayers.end())