]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/cmd_nick.cpp
Tidy up strlens which are not required
[user/henk/code/inspircd.git] / src / cmd_nick.cpp
index 9313899f74573c93907086f817881c3782a25023..911c80bd8a966286444d842bd83a9b7bac220aeb 100644 (file)
  * ---------------------------------------------------
  */
 
-#include <string>
-#include <vector>
-#include "inspircd_config.h"
 #include "configreader.h"
-#include "hash_map.h"
 #include "users.h"
 #include "modules.h"
-#include "commands.h"
+#include "inspircd.h"
 #include "xline.h"
-#include "dns.h"
-#include "helperfuncs.h"
-#include "hashcomp.h"
 #include "commands/cmd_nick.h"
 
-extern InspIRCd* ServerInstance;
-extern int MODCOUNT;
-extern std::vector<Module*> modules;
-extern std::vector<ircd_module*> factory;
-extern time_t TIME;
 
-void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
+
+extern "C" command_t* init_command(InspIRCd* Instance)
+{
+       return new cmd_nick(Instance);
+}
+
+CmdResult cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
 {
        char oldnick[NICKMAX];
 
-       if (pcnt < 1) 
-       {
-               log(DEBUG,"not enough params for handle_nick");
-               return;
-       }
-       if (!parameters[0])
-       {
-               log(DEBUG,"invalid parameter passed to handle_nick");
-               return;
-       }
        if (!parameters[0][0])
        {
-               log(DEBUG,"zero length new nick passed to handle_nick");
-               return;
+               ServerInstance->Log(DEBUG,"zero length new nick passed to handle_nick");
+               return CMD_FAILURE;
        }
-       if (!user)
+       if (!*user->nick)
        {
-               log(DEBUG,"invalid user passed to handle_nick");
-               return;
-       }
-       if (!user->nick)
-       {
-               log(DEBUG,"invalid old nick passed to handle_nick");
-               return;
+               ServerInstance->Log(DEBUG,"invalid old nick passed to handle_nick");
+               return CMD_FAILURE;
        }
+       ServerInstance->Log(DEBUG,"Fall through");
        if (irc::string(user->nick) == irc::string(parameters[0]))
        {
                /* If its exactly the same, even case, dont do anything. */
                if (!strcmp(user->nick,parameters[0]))
-                       return;
+                       return CMD_SUCCESS;
+
                /* Its a change of case. People insisted that they should be
                 * able to do silly things like this even though the RFC says
                 * the nick AAA is the same as the nick aaa.
                 */
-               log(DEBUG,"old nick is new nick, not updating hash (case change only)");
+               ServerInstance->Log(DEBUG,"old nick is new nick, not updating hash (case change only)");
                strlcpy(oldnick, user->nick, NICKMAX - 1);
                int MOD_RESULT = 0;
                FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
                if (MOD_RESULT)
-                       return;
+                       return CMD_FAILURE;
                if (user->registered == REG_ALL)
                        user->WriteCommon("NICK %s",parameters[0]);
                strlcpy(user->nick, parameters[0], NICKMAX - 1);
                FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
-               return;
+               return CMD_SUCCESS;
        }
        else
        {
-               if ((*parameters[0] == ':') && (*(parameters[0]+1) != 0))
-               {
-                       parameters[0]++;
-               }
-               if (matches_qline(parameters[0]))
+               QLine* mq = ServerInstance->XLines->matches_qline(parameters[0]);
+               if (mq)
                {
-                       ServerInstance->WriteOpers("*** Q-Lined nickname %s from %s!%s@%s: %s",parameters[0],user->nick,user->ident,user->host,matches_qline(parameters[0]));
-                       user->WriteServ("432 %s %s :Invalid nickname: %s",user->nick,parameters[0],matches_qline(parameters[0]));
-                       return;
+                       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;
                }
-               if ((ServerInstance->FindNick(parameters[0])) && (ServerInstance->FindNick(parameters[0]) != user))
+               if ((ServerInstance->FindNick(parameters[0])) && (ServerInstance->FindNick(parameters[0]) != user) && (ServerInstance->IsNick(parameters[0])))
                {
-                       user->WriteServ("433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
-                       return;
+                       userrec* InUse = ServerInstance->FindNick(parameters[0]);
+                       if (InUse->registered != REG_ALL)
+                       {
+                               userrec::QuitUser(ServerInstance, InUse, "Nickname overruled");
+                       }
+                       else
+                       {
+                               user->WriteServ("433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
+                               return CMD_FAILURE;
+                       }
                }
        }
-       if ((isnick(parameters[0]) == 0) && (IS_LOCAL(user)))
+       if ((!ServerInstance->IsNick(parameters[0])) && (IS_LOCAL(user)))
        {
                user->WriteServ("432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
-               return;
+               return CMD_FAILURE;
        }
 
        if (user->registered == REG_ALL)
@@ -114,7 +100,7 @@ void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
                FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
                if (MOD_RESULT) {
                        // if a module returns true, the nick change is silently forbidden.
-                       return;
+                       return CMD_FAILURE;
                }
 
                user->WriteCommon("NICK %s",parameters[0]);
@@ -126,12 +112,12 @@ void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
        /* change the nick of the user in the users_hash */
        user = user->UpdateNickHash(parameters[0]);
        /* actually change the nick within the record */
-       if (!user) return;
-       if (!user->nick) return;
+       if (!user) return CMD_FAILURE;
+       if (!*user->nick) return CMD_FAILURE;
 
        strlcpy(user->nick, parameters[0], NICKMAX - 1);
 
-       log(DEBUG,"new nick set: %s",user->nick);
+       ServerInstance->Log(DEBUG,"new nick set: %s",user->nick);
        
        if (user->registered < REG_NICKUSER)
        {
@@ -140,7 +126,7 @@ void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
                // and unless we're lucky we'll get a duff one later on.
                //user->dns_done = (!lookup_dns(user->nick));
                //if (user->dns_done)
-               //      log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
+               //      ServerInstance->Log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
 
                if (ServerInstance->Config->NoUserDns)
                {
@@ -150,7 +136,7 @@ void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
                {
                        user->StartDNSLookup();
                        if (user->dns_done)
-                               log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
+                               ServerInstance->Log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
                }
        }
        if (user->registered == REG_NICKUSER)
@@ -163,4 +149,8 @@ void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
        {
                FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
        }
+
+       return CMD_SUCCESS;
+
 }
+