]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sanick.cpp
Strip SUPPORT_IP6LINKS #define
[user/henk/code/inspircd.git] / src / modules / m_sanick.cpp
index cd93377c8a2b99911c417586978c0d5ffa785fb3..e7496850051f955f42d03c495e37f3d280016c50 100644 (file)
@@ -2,8 +2,8 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
@@ -30,41 +30,50 @@ class CommandSanick : public Command
        CmdResult Handle (const std::vector<std::string>& parameters, User *user)
        {
                User* target = ServerInstance->FindNick(parameters[0]);
-               if (target)
+
+               /* Do local sanity checks and bails */
+               if (IS_LOCAL(user))
                {
-                       if (ServerInstance->ULine(target->server))
+                       if (target && ServerInstance->ULine(target->server))
                        {
-                               user->WriteNumeric(990, "%s :Cannot use an SA command on a u-lined client",user->nick.c_str());
+                               user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an SA command on a u-lined client",user->nick.c_str());
                                return CMD_FAILURE;
                        }
-                       std::string oldnick = user->nick;
-                       if (ServerInstance->IsNick(parameters[1].c_str()))
+
+                       if (!target)
                        {
-                               if (target->ForceNickChange(parameters[1].c_str()))
-                               {
-                                       ServerInstance->SNO->WriteToSnoMask('A', oldnick+" used SANICK to change "+parameters[0]+" to "+parameters[1]);
-                                       return CMD_SUCCESS;
-                               }
-                               else
-                               {
-                                       /* We couldnt change the nick */
-                                       ServerInstance->SNO->WriteToSnoMask('A', oldnick+" failed SANICK (from "+parameters[0]+" to "+parameters[1]+")");
-                                       return CMD_FAILURE;
-                               }
+                               user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
+                               return CMD_FAILURE;
                        }
-                       else
+
+                       if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
                        {
                                user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
+                               return CMD_FAILURE;
                        }
-
-                       return CMD_FAILURE;
                }
-               else
+
+               /* Have we hit target's server yet? */
+               if (target && IS_LOCAL(target))
                {
-                       user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
+                       std::string oldnick = user->nick;
+                       std::string newnick = target->nick;
+                       if (target->ForceNickChange(parameters[1].c_str()))
+                       {
+                               ServerInstance->SNO->WriteToSnoMask('a', oldnick+" used SANICK to change "+newnick+" to "+parameters[1]);
+                               ServerInstance->PI->SendSNONotice("A", oldnick+" used SANICK to change "+newnick+" to "+parameters[1]);
+                       }
+                       else
+                       {
+                               ServerInstance->SNO->WriteToSnoMask('a', oldnick+" failed SANICK (from "+newnick+" to "+parameters[1]+")");
+                               ServerInstance->PI->SendSNONotice("A", oldnick+" failed SANICK (from "+newnick+" to "+parameters[1]+")");
+                       }
+                       /* Yes, hit target and we have sent our NICK out, we can now bail */
+                       return CMD_LOCALONLY;
                }
 
-               return CMD_FAILURE;
+               /* No, route it on */
+               return CMD_SUCCESS;
        }
 };
 
@@ -76,21 +85,21 @@ class ModuleSanick : public Module
        ModuleSanick(InspIRCd* Me)
                : Module(Me)
        {
-               
+
                mycommand = new CommandSanick(ServerInstance);
                ServerInstance->AddCommand(mycommand);
 
        }
-       
+
        virtual ~ModuleSanick()
        {
        }
-       
+
        virtual Version GetVersion()
        {
-               return Version(1, 2, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
+               return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
        }
-       
+
 };
 
 MODULE_INIT(ModuleSanick)