]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sapart.cpp
(Bigger than it looks, i did this with perl inplace edit) -- commands now take an...
[user/henk/code/inspircd.git] / src / modules / m_sapart.cpp
index 026a3bd7d863e485757ed04778af317925dd8e1e..590c22c675b38a45bee247ae496539fbc880f143 100644 (file)
@@ -2,14 +2,14 @@
  *       | 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.
  *
  * ---------------------------------------------------
  */
@@ -21,35 +21,37 @@ using namespace std;
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
+#include "helperfuncs.h"
+#include "inspircd.h"
 
 /* $ModDesc: Provides support for unreal-style SAPART command */
 
-Server *Srv;
+
+extern InspIRCd* ServerInstance;
 
 class cmd_sapart : public command_t
 {
  public:
      cmd_sapart () : command_t("SAPART", 'o', 2)
cmd_sapart (InspIRCd* Instance) : command_t(Instance,"SAPART", 'o', 2)
        {
                this->source = "m_sapart.so";
+               syntax = "<nick> <channel>";
        }
         
-       void Handle (char **parameters, int pcnt, userrec *user)
+       void Handle (const char** parameters, int pcnt, userrec *user)
        {
-               userrec* dest = Srv->FindNick(std::string(parameters[0]));
-               if (dest)
+               userrec* dest = ServerInstance->FindNick(parameters[0]);
+               chanrec* channel = ServerInstance->FindChan(parameters[1]);
+               if (dest && channel)
                {
-                       for (unsigned int x = 0; x < strlen(parameters[1]); x++)
+                       if (ServerInstance->IsUlined(dest->server))
                        {
-                                       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;
-                                       }
+                               user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
+                               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));
+                       ServerInstance->WriteOpers(std::string(user->nick)+" used SAPART to make "+dest->nick+" part "+parameters[1]);
+                       if (!channel->PartUser(dest, dest->nick))
+                               delete channel;
                }
        }
 };
@@ -59,12 +61,12 @@ class ModuleSapart : public Module
 {
        cmd_sapart*     mycommand;
  public:
-       ModuleSapart(Server* Me)
+       ModuleSapart(InspIRCd* Me)
                : Module::Module(Me)
        {
-               Srv = Me;
-               mycommand = new cmd_sapart();
-               Srv->AddCommand(mycommand);
+               
+               mycommand = new cmd_sapart(ServerInstance);
+               ServerInstance->AddCommand(mycommand);
        }
        
        virtual ~ModuleSapart()
@@ -91,7 +93,7 @@ class ModuleSapartFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule(Server* Me)
+       virtual Module * CreateModule(InspIRCd* Me)
        {
                return new ModuleSapart(Me);
        }