]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/svsnick.cpp
Merge branch 'insp20' into master.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / svsnick.cpp
index 43fa0f296ec6cb5811a9cd69a56b1e3e77c56720..2514dfd6f511fc9bc4ed17c035f80f040ad7711f 100644 (file)
 #include "main.h"
 #include "commands.h"
 
-CmdResult CommandSVSNick::Handle(User* user, std::vector<std::string>& parameters)
+CmdResult CommandSVSNick::Handle(User* user, Params& parameters)
 {
        User* u = ServerInstance->FindNick(parameters[0]);
 
        if (u && IS_LOCAL(u))
        {
+               // The 4th parameter is optional and it is the expected nick TS of the target user. If this parameter is
+               // present and it doesn't match the user's nick TS, the SVSNICK is not acted upon.
+               // This makes it possible to detect the case when services wants to change the nick of a user, but the
+               // user changes their nick before the SVSNICK arrives, making the SVSNICK nick change (usually to a guest nick)
+               // unnecessary. Consider the following for example:
+               //
+               // 1. test changes nick to Attila which is protected by services
+               // 2. Services SVSNICKs the user to Guest12345
+               // 3. Attila changes nick to Attila_ which isn't protected by services
+               // 4. SVSNICK arrives
+               // 5. Attila_ gets his nick changed to Guest12345 unnecessarily
+               //
+               // In this case when the SVSNICK is processed the target has already changed his nick to something
+               // which isn't protected, so changing the nick again to a Guest nick is not desired.
+               // However, if the expected nick TS parameter is present in the SVSNICK then the nick change in step 5
+               // won't happen because the timestamps won't match.
+               if (parameters.size() > 3)
+               {
+                       time_t ExpectedTS = ConvToInt(parameters[3]);
+                       if (u->age != ExpectedTS)
+                               return CMD_FAILURE; // Ignore SVSNICK
+               }
+
                std::string nick = parameters[1];
                if (isdigit(nick[0]))
                        nick = u->uuid;
@@ -37,23 +60,17 @@ CmdResult CommandSVSNick::Handle(User* user, std::vector<std::string>& parameter
                if (NickTS <= 0)
                        return CMD_FAILURE;
 
-               if (!u->ForceNickChange(nick, NickTS))
+               if (!u->ChangeNick(nick, NickTS))
                {
-                       /* buh. UID them */
-                       if (!u->ForceNickChange(u->uuid))
-                       {
-                               ServerInstance->Users->QuitUser(u, "Nickname collision");
-                       }
+                       // Changing to 'nick' failed (it may already be in use), change to the uuid
+                       u->ChangeNick(u->uuid);
                }
        }
 
        return CMD_SUCCESS;
 }
 
-RouteDescriptor CommandSVSNick::GetRouting(User* user, const std::vector<std::string>& parameters)
+RouteDescriptor CommandSVSNick::GetRouting(User* user, const Params& parameters)
 {
-       User* u = ServerInstance->FindNick(parameters[0]);
-       if (u)
-               return ROUTE_OPT_UCAST(u->server);
-       return ROUTE_LOCALONLY;
+       return ROUTE_OPT_UCAST(parameters[0]);
 }