]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sanick.cpp
Wahhhhhhhhhhhh bwahahaha. Mass commit to tidy up tons of messy include lists
[user/henk/code/inspircd.git] / src / modules / m_sanick.cpp
index 6b874f2720bc8dda68842d77ed86d20dd1d19a0d..818672ce4897485b0934dbf64c3ec668dcb54c9c 100644 (file)
@@ -2,56 +2,82 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
- *                       E-mail:
- *                <brain@chatspike.net>
- *               <Craig@chatspike.net>
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
+ *                    E-mail:
+ *             <brain@chatspike.net>
+ *               <Craig@chatspike.net>
  *     
  * Written by Craig Edwards, Craig McLure, and others.
  * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ *         the file COPYING for details.
  *
  * ---------------------------------------------------
  */
 
+using namespace std;
+
 #include <stdio.h>
 #include <string>
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
+#include "inspircd.h"
 
 /* $ModDesc: Provides support for SANICK command */
 
-Server *Srv;
-        
-void handle_sanick(char **parameters, int pcnt, userrec *user)
+
+
+
+class cmd_sanick : public command_t
 {
-       userrec* source = Srv->FindNick(std::string(parameters[0]));
      if (source)
+ public:
cmd_sanick (InspIRCd* Instance) : command_t(Instance,"SANICK", 'o', 2)
        {
-               if (Srv->IsNick(std::string(parameters[1])))
+               this->source = "m_sanick.so";
+               syntax = "<nick> <new-nick>";
+       }
+
+       void Handle (const char** parameters, int pcnt, userrec *user)
+       {
+               userrec* source = ServerInstance->FindNick(parameters[0]);
+               if (source)
                {
-                       // FIX by brain: Cant use source->nick here because if it traverses a server link then
-                       // source->nick becomes invalid as the object data moves in memory.
-                       Srv->SendOpers(std::string(user->nick)+" used SANICK to change "+std::string(parameters[0])+" to "+parameters[1]);
-                       Srv->ChangeUserNick(source,std::string(parameters[1]));
+                       if (ServerInstance->ULine(source->server))
+                       {
+                               user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
+                               return;
+                       }
+                       if (ServerInstance->IsNick(parameters[1]))
+                       {
+                               // FIX by brain: Cant use source->nick here because if it traverses a server link then
+                               // source->nick becomes invalid as the object data moves in memory.
+                               ServerInstance->WriteOpers(std::string(user->nick)+" used SANICK to change "+std::string(parameters[0])+" to "+parameters[1]);
+                               if (!source->ForceNickChange(parameters[1]))
+                               {
+                                       /* We couldnt change the nick */
+                                       userrec::QuitUser(ServerInstance, source, "Nickname collision");
+                                       return;
+                               }
+                       }
                }
        }
-}
+};
 
 
 class ModuleSanick : public Module
 {
+       cmd_sanick*     mycommand;
  public:
-       ModuleSanick()
+       ModuleSanick(InspIRCd* Me)
+               : Module::Module(Me)
        {
-               Srv = new Server;
-               Srv->AddCommand("SANICK",handle_sanick,'o',2,"m_sanick.so");
+               
+               mycommand = new cmd_sanick(ServerInstance);
+               ServerInstance->AddCommand(mycommand);
        }
        
        virtual ~ModuleSanick()
        {
-               delete Srv;
        }
        
        virtual Version GetVersion()
@@ -74,9 +100,9 @@ class ModuleSanickFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(InspIRCd* Me)
        {
-               return new ModuleSanick;
+               return new ModuleSanick(Me);
        }
        
 };