]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/commands/cmd_nick.cpp
Allow remote users to bypass Q:Line (why on earth wasn't this the case)
[user/henk/code/inspircd.git] / src / commands / cmd_nick.cpp
index 25bf858c860a80fea0e548979073813cbcae6e75..059a978060e06f9cc7f6deb61626637e5cd69db8 100644 (file)
@@ -25,14 +25,14 @@ extern "C" DllExport Command* init_command(InspIRCd* Instance)
  * for the client introduction code in here, youre in the wrong place.
  * You need to look in the spanningtree module for this!
  */
-CmdResult CommandNick::Handle (const char** parameters, int, User *user)
+CmdResult CommandNick::Handle (const char* const* parameters, int, User *user)
 {
        char oldnick[NICKMAX];
 
        if (!*parameters[0] || !*user->nick)
        {
                /* We cant put blanks in the parameters, so for this (extremely rare) issue we just put '*' here. */
-               user->WriteServ("432 %s * :Erroneous Nickname", *user->nick ? user->nick : "*");
+               user->WriteNumeric(432, "%s * :Erroneous Nickname", *user->nick ? user->nick : "*");
                return CMD_FAILURE;
        }
 
@@ -60,12 +60,23 @@ CmdResult CommandNick::Handle (const char** parameters, int, User *user)
        }
        else
        {
-               XLine* mq = ServerInstance->XLines->MatchesLine("Q",parameters[0]);
-               if (mq)
+               /*
+                * Don't check Q:Lines if it's a server-enforced change, just on the off-chance some fucking *moron*
+                * tries to Q:Line SIDs, also, this means we just get our way period, as it really should be.
+                * Thanks Kein for finding this. -- w00t
+                *
+                * Also don't check Q:Lines for remote nickchanges, they should have our Q:Lines anyway to enforce themselves.
+                *              -- w00t
+                */
+               if (!allowinvalid || !IS_LOCAL(user))
                {
-                       ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s", parameters[0], user->nick, user->ident, user->host, mq->reason);
-                       user->WriteServ("432 %s %s :Invalid nickname: %s",user->nick,parameters[0], mq->reason);
-                       return CMD_FAILURE;
+                       XLine* mq = ServerInstance->XLines->MatchesLine("Q",parameters[0]);
+                       if (mq)
+                       {
+                               ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s", parameters[0], user->nick, user->ident, user->host, mq->reason);
+                               user->WriteNumeric(432, "%s %s :Invalid nickname: %s",user->nick,parameters[0], mq->reason);
+                               return CMD_FAILURE;
+                       }
                }
 
                /*
@@ -84,7 +95,7 @@ CmdResult CommandNick::Handle (const char** parameters, int, User *user)
                        {
                                /* force the camper to their UUID, and ask them to re-send a NICK. */
                                InUse->WriteTo(InUse, "NICK %s", InUse->uuid);
-                               InUse->WriteServ("433 %s %s :Nickname overruled.", InUse->nick, InUse->nick);
+                               InUse->WriteNumeric(433, "%s %s :Nickname overruled.", InUse->nick, InUse->nick);
                                InUse->UpdateNickHash(InUse->uuid);
                                strlcpy(InUse->nick, InUse->uuid, NICKMAX - 1);
                                InUse->InvalidateCache();
@@ -93,7 +104,7 @@ CmdResult CommandNick::Handle (const char** parameters, int, User *user)
                        else
                        {
                                /* No camping, tell the incoming user  to stop trying to change nick ;p */
-                               user->WriteServ("433 %s %s :Nickname is already in use.", user->registered >= REG_NICK ? user->nick : "*", parameters[0]);
+                               user->WriteNumeric(433, "%s %s :Nickname is already in use.", user->registered >= REG_NICK ? user->nick : "*", parameters[0]);
                                return CMD_FAILURE;
                        }
                }
@@ -102,7 +113,7 @@ CmdResult CommandNick::Handle (const char** parameters, int, User *user)
        {
                if (!allowinvalid)
                {
-                       user->WriteServ("432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
+                       user->WriteNumeric(432, "%s %s :Erroneous Nickname",user->nick,parameters[0]);
                        return CMD_FAILURE;
                }
        }
@@ -144,15 +155,15 @@ CmdResult CommandNick::Handle (const char** parameters, int, User *user)
        {
                user->registered = (user->registered | REG_NICK);
        }
-       else if (user->registered == REG_NICKUSER)
+       if (user->registered == REG_NICKUSER)
        {
                /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
-               int MOD_RESULT = 0;
+               MOD_RESULT = 0;
                FOREACH_RESULT(I_OnUserRegister,OnUserRegister(user));
                if (MOD_RESULT > 0)
                        return CMD_FAILURE;
        }
-       else if (user->registered == REG_ALL)
+       if (user->registered == REG_ALL)
        {
                user->IncreasePenalty(10);
                FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));