Ticket #3604: t3604_stop_rejoin_confusion_v3.patch
File t3604_stop_rejoin_confusion_v3.patch, 4.4 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/common/network.js
function getDisconnectReason(id) 17 17 case 2: return translate("Incorrect network protocol version"); 18 18 case 3: return translate("Game is loading, please try later"); 19 19 case 4: return translate("Game has already started, no observers allowed"); 20 20 case 5: return translate("You have been kicked"); 21 21 case 6: return translate("You have been banned"); 22 case 7: return translate("Playername already in use"); 22 23 default: 23 24 warn("Unknown disconnect-reason ID received: " + id); 24 25 return sprintf(translate("\\[Invalid value %(id)s]"), { "id": id }); 25 26 } 26 27 } -
source/network/NetHost.h
enum NetDisconnectReason 63 63 NDR_UNEXPECTED_SHUTDOWN, 64 64 NDR_INCORRECT_PROTOCOL_VERSION, 65 65 NDR_SERVER_LOADING, 66 66 NDR_SERVER_ALREADY_IN_GAME, 67 67 NDR_KICKED, 68 NDR_BANNED 68 NDR_BANNED, 69 NDR_PLAYERNAME_IN_USE 69 70 }; 70 71 71 72 class CNetHost 72 73 { 73 74 public: -
source/network/NetMessages.h
26 26 #include "ps/CStr.h" 27 27 #include "scriptinterface/ScriptVal.h" 28 28 29 29 #define PS_PROTOCOL_MAGIC 0x5073013f // 'P', 's', 0x01, '?' 30 30 #define PS_PROTOCOL_MAGIC_RESPONSE 0x50630121 // 'P', 'c', 0x01, '!' 31 #define PS_PROTOCOL_VERSION 0x0101000 8// Arbitrary protocol31 #define PS_PROTOCOL_VERSION 0x01010009 // Arbitrary protocol 32 32 #define PS_DEFAULT_PORT 0x5073 // 'P', 's' 33 33 34 34 // Defines the list of message types. The order of the list must not change. 35 35 // The message types having a negative value are used internally and not sent 36 36 // over the network. The message types used for network communication have -
source/network/NetServer.cpp
bool CNetServerWorker::OnAuthenticate(vo 844 844 session->Disconnect(NDR_SERVER_LOADING); 845 845 return true; 846 846 } 847 847 848 848 CAuthenticateMessage* message = (CAuthenticateMessage*)event->GetParamRef(); 849 CStrW username = server.DeduplicatePlayerName(SanitisePlayerName(message->m_Name)); 849 CStrW username = SanitisePlayerName(message->m_Name); 850 851 // Prohibit joins if the same name exists 852 if (std::find_if( 853 server.m_Sessions.begin(), server.m_Sessions.end(), 854 [&username] (const CNetServerSession* session) 855 { return session->GetUserName() == username; }) 856 != server.m_Sessions.end()) 857 { 858 session->Disconnect(NDR_PLAYERNAME_IN_USE); 859 return true; 860 } 850 861 851 862 // Disconnect banned usernames 852 863 if (std::find(server.m_BannedPlayers.begin(), server.m_BannedPlayers.end(), username) != server.m_BannedPlayers.end()) 853 864 { 854 865 session->Disconnect(NDR_BANNED); … … CStrW CNetServerWorker::SanitisePlayerNa 1174 1185 name = L"Anonymous"; 1175 1186 1176 1187 return name; 1177 1188 } 1178 1189 1179 CStrW CNetServerWorker::DeduplicatePlayerName(const CStrW& original)1180 {1181 CStrW name = original;1182 1183 // Try names "Foo", "Foo (2)", "Foo (3)", etc1184 size_t id = 2;1185 while (true)1186 {1187 bool unique = true;1188 for (size_t i = 0; i < m_Sessions.size(); ++i)1189 {1190 if (m_Sessions[i]->GetUserName() == name)1191 {1192 unique = false;1193 break;1194 }1195 }1196 1197 if (unique)1198 return name;1199 1200 name = original + L" (" + CStrW::FromUInt(id++) + L")";1201 }1202 }1203 1190 1204 1191 1205 1192 1206 1193 1207 1194 CNetServer::CNetServer(int autostartPlayers) : -
source/network/NetServer.h
private: 236 236 * Make a player name 'nicer' by limiting the length and removing forbidden characters etc. 237 237 */ 238 238 static CStrW SanitisePlayerName(const CStrW& original); 239 239 240 240 /** 241 * Make a player name unique, if it matches any existing session's name.242 */243 CStrW DeduplicatePlayerName(const CStrW& original);244 245 /**246 241 * Get the script context used for game attributes. 247 242 */ 248 243 ScriptInterface& GetScriptInterface(); 249 244 250 245 /**