]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sapart.cpp
Annotations
[user/henk/code/inspircd.git] / src / modules / m_sapart.cpp
index 266ed5a049266e4071bf82b6481989ead2f4e3ea..36078ab06c719667982cff89524657eff226729b 100644 (file)
@@ -1,4 +1,20 @@
-// Sapart and +g support module by C.J.Edwards
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  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.
+ *
+ * ---------------------------------------------------
+ */
+
+using namespace std;
 
 #include <stdio.h>
 #include <string>
 #include "channels.h"
 #include "modules.h"
 
+#include "inspircd.h"
+
 /* $ModDesc: Provides support for unreal-style SAPART command */
 
-Server *Srv;
-        
-void handle_sapart(char **parameters, int pcnt, userrec *user)
+
+
+
+class cmd_sapart : public command_t
 {
-       userrec* dest = Srv->FindNick(std::string(parameters[0]));
-       if (dest)
+ public:
+       cmd_sapart (InspIRCd* Instance) : command_t(Instance,"SAPART", 'o', 2)
        {
-               Srv->SendOpers(std::string(user->nick)+" used SAPART to make "+std::string(dest->nick)+" part "+parameters[1]);
-               Srv->PartUserFromChannel(dest,std::string(parameters[1]),std::string(dest->nick));
+               this->source = "m_sapart.so";
+               syntax = "<nick> <channel>";
        }
-}
+
+       CmdResult Handle (const char** parameters, int pcnt, userrec *user)
+       {
+               userrec* dest = ServerInstance->FindNick(parameters[0]);
+               chanrec* channel = ServerInstance->FindChan(parameters[1]);
+               if (dest && channel)
+               {
+                       if (ServerInstance->ULine(dest->server))
+                       {
+                               user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
+                               return CMD_FAILURE;
+                       }
+                       ServerInstance->WriteOpers(std::string(user->nick)+" used SAPART to make "+dest->nick+" part "+parameters[1]);
+                       if (!channel->PartUser(dest, dest->nick))
+                               delete channel;
+
+                       return CMD_SUCCESS;
+               }
+
+               return CMD_FAILURE;
+       }
+};
 
 
 class ModuleSapart : public Module
 {
+       cmd_sapart*     mycommand;
  public:
-       ModuleSapart()
+       ModuleSapart(InspIRCd* Me)
+               : Module::Module(Me)
        {
-               Srv = new Server;
-               Srv->AddCommand("SAPART",handle_sapart,'o',2);
+               
+               mycommand = new cmd_sapart(ServerInstance);
+               ServerInstance->AddCommand(mycommand);
        }
        
        virtual ~ModuleSapart()
        {
-               delete Srv;
        }
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,1);
+               return Version(1,0,0,1,VF_VENDOR);
        }
        
 };
@@ -55,9 +97,9 @@ class ModuleSapartFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(InspIRCd* Me)
        {
-               return new ModuleSapart;
+               return new ModuleSapart(Me);
        }
        
 };