Ticket #3604: t3604_stop_rejoin_confusion_v3.patch

File t3604_stop_rejoin_confusion_v3.patch, 4.4 KB (added by elexis, 8 years ago)
  • binaries/data/mods/public/gui/common/network.js

    function getDisconnectReason(id)  
    1717    case 2: return translate("Incorrect network protocol version");
    1818    case 3: return translate("Game is loading, please try later");
    1919    case 4: return translate("Game has already started, no observers allowed");
    2020    case 5: return translate("You have been kicked");
    2121    case 6: return translate("You have been banned");
     22    case 7: return translate("Playername already in use");
    2223    default:
    2324        warn("Unknown disconnect-reason ID received: " + id);
    2425        return sprintf(translate("\\[Invalid value %(id)s]"), { "id": id });
    2526    }
    2627}
  • source/network/NetHost.h

    enum NetDisconnectReason  
    6363    NDR_UNEXPECTED_SHUTDOWN,
    6464    NDR_INCORRECT_PROTOCOL_VERSION,
    6565    NDR_SERVER_LOADING,
    6666    NDR_SERVER_ALREADY_IN_GAME,
    6767    NDR_KICKED,
    68     NDR_BANNED
     68    NDR_BANNED,
     69    NDR_PLAYERNAME_IN_USE
    6970};
    7071
    7172class CNetHost
    7273{
    7374public:
  • source/network/NetMessages.h

     
    2626#include "ps/CStr.h"
    2727#include "scriptinterface/ScriptVal.h"
    2828
    2929#define PS_PROTOCOL_MAGIC               0x5073013f      // 'P', 's', 0x01, '?'
    3030#define PS_PROTOCOL_MAGIC_RESPONSE      0x50630121      // 'P', 'c', 0x01, '!'
    31 #define PS_PROTOCOL_VERSION             0x01010008      // Arbitrary protocol
     31#define PS_PROTOCOL_VERSION             0x01010009      // Arbitrary protocol
    3232#define PS_DEFAULT_PORT                 0x5073          // 'P', 's'
    3333
    3434// Defines the list of message types. The order of the list must not change.
    3535// The message types having a negative value are used internally and not sent
    3636// over the network. The message types used for network communication have
  • source/network/NetServer.cpp

    bool CNetServerWorker::OnAuthenticate(vo  
    844844        session->Disconnect(NDR_SERVER_LOADING);
    845845        return true;
    846846    }
    847847
    848848    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    }
    850861
    851862    // Disconnect banned usernames
    852863    if (std::find(server.m_BannedPlayers.begin(), server.m_BannedPlayers.end(), username) != server.m_BannedPlayers.end())
    853864    {
    854865        session->Disconnect(NDR_BANNED);
    CStrW CNetServerWorker::SanitisePlayerNa  
    11741185        name = L"Anonymous";
    11751186
    11761187    return name;
    11771188}
    11781189
    1179 CStrW CNetServerWorker::DeduplicatePlayerName(const CStrW& original)
    1180 {
    1181     CStrW name = original;
    1182 
    1183     // Try names "Foo", "Foo (2)", "Foo (3)", etc
    1184     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 }
    12031190
    12041191
    12051192
    12061193
    12071194CNetServer::CNetServer(int autostartPlayers) :
  • source/network/NetServer.h

    private:  
    236236     * Make a player name 'nicer' by limiting the length and removing forbidden characters etc.
    237237     */
    238238    static CStrW SanitisePlayerName(const CStrW& original);
    239239
    240240    /**
    241      * Make a player name unique, if it matches any existing session's name.
    242      */
    243     CStrW DeduplicatePlayerName(const CStrW& original);
    244 
    245     /**
    246241     * Get the script context used for game attributes.
    247242     */
    248243    ScriptInterface& GetScriptInterface();
    249244
    250245    /**