]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sapart.cpp
Updates, should be able to safely unload client modules with queries in progress...
[user/henk/code/inspircd.git] / src / modules / m_sapart.cpp
index 177a77d9b1d1678215eabc98d449973bb4dee7f3..afbdbdc870d0fd0ab089f759f524bd843deb215b 100644 (file)
@@ -1,52 +1,82 @@
-// 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 "users.h"
 #include "channels.h"
 #include "modules.h"
+#include "helperfuncs.h"
 
 /* $ModDesc: Provides support for unreal-style SAPART command */
 
-Server *Srv;
-        
-void handle_sapart(char **parameters, int pcnt, userrec *user)
+static Server *Srv;
+
+class cmd_sapart : public command_t
 {
-       userrec* dest = Srv->FindNick(std::string(parameters[0]));
-       if (dest)
+ public:
+       cmd_sapart () : command_t("SAPART", 'o', 2)
        {
-               for (int x = 0; x < strlen(parameters[1]); x++)
+               this->source = "m_sapart.so";
+       }
+        
+       void Handle (const char** parameters, int pcnt, userrec *user)
+       {
+               userrec* dest = Srv->FindNick(std::string(parameters[0]));
+               if (dest)
                {
-                               if ((parameters[1][0] != '#') || (parameters[1][x] == ' ') || (parameters[1][x] == ','))
-                               {
-                                       Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name");
-                                       return;
-                               }
-               }
+                       if (Srv->IsUlined(dest->server))
+                       {
+                               WriteServ(user->fd,"990 %s :Cannot use an SA command on a u-lined client",user->nick);
+                               return;
+                       }
+                       if (!IsValidChannelName(parameters[1]))
+                       {
+                               Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name");
+                               return;
+                       }
 
-               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));
+                       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));
+               }
        }
-}
+};
 
 
 class ModuleSapart : public Module
 {
+       cmd_sapart*     mycommand;
  public:
-       ModuleSapart()
+       ModuleSapart(Server* Me)
+               : Module::Module(Me)
        {
-               Srv = new Server;
-               Srv->AddCommand("SAPART",handle_sapart,'o',2);
+               Srv = Me;
+               mycommand = new cmd_sapart();
+               Srv->AddCommand(mycommand);
        }
        
        virtual ~ModuleSapart()
        {
-               delete Srv;
        }
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,1);
+               return Version(1,0,0,1,VF_VENDOR);
        }
        
 };
@@ -64,9 +94,9 @@ class ModuleSapartFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleSapart;
+               return new ModuleSapart(Me);
        }
        
 };