]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_nicklock.cpp
Works with the m_testclient test program/suite!
[user/henk/code/inspircd.git] / src / modules / m_nicklock.cpp
index 750b431cf66bc39f1a4e1c60abe95b46ed979c0b..df8a551dd2bd3b1ca2d29204f63d5b20f8204ba3 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -26,17 +26,18 @@ using namespace std;
 
 /* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */
 
-Server *Srv;
+static Server *Srv;
 
 class cmd_nicklock : public command_t
 {
+       char* dummy;
  public:
-        cmd_nicklock () : command_t("NICKLOCK", 'o', 2)
-        {
+       cmd_nicklock () : command_t("NICKLOCK", 'o', 2)
+       {
                this->source = "m_nicklock.so";
-        }
+       }
 
-       void Handle(char **parameters, int pcnt, userrec *user)
+       void Handle(const char** parameters, int pcnt, userrec *user)
        {
                userrec* source = Srv->FindNick(std::string(parameters[0]));
                irc::string server;
@@ -44,30 +45,20 @@ class cmd_nicklock : public command_t
 
                if (source)
                {
-                       if (source->GetExt("nick_locked"))
+                       if (source->GetExt("nick_locked", dummy))
                        {
                                WriteServ(user->fd,"946 %s %s :This user's nickname is already locked.",user->nick,source->nick);
                                return;
                        }
                        if (Srv->IsNick(std::string(parameters[1])))
                        {
-                               server = user->server;
-                               me = Srv->GetServerName().c_str();
-       
-                               if (server == me)
-                               {
-                                       // give them a lock flag
-                                       Srv->SendOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+std::string(parameters[0])+" to "+parameters[1]);
-                                       Srv->ChangeUserNick(source,std::string(parameters[1]));
-                                       // only attempt to set their lockflag after we know the change succeeded
-                                       source = Srv->FindNick(std::string(parameters[1]));
-                                       if (source)
-                                               source->Extend("nick_locked", "ON");
-                               }
-                               else
-                               {
-                                       WriteServ(user->fd,"947 %s %s :Can't lock the nickname of a non-local user",user->nick,source->nick);
-                               }
+                               // give them a lock flag
+                               Srv->SendOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+std::string(parameters[0])+" to "+parameters[1]);
+                               Srv->ChangeUserNick(source,std::string(parameters[1]));
+                               // only attempt to set their lockflag after we know the change succeeded
+                               source = Srv->FindNick(std::string(parameters[1]));
+                               if (source)
+                                       source->Extend("nick_locked", "ON");
                        }
                }
        }
@@ -81,7 +72,7 @@ class cmd_nickunlock : public command_t
                this->source = "m_nickunlock.so";
        }
 
-       void Handle (char **parameters, int pcnt, userrec *user)
+       void Handle (const char** parameters, int pcnt, userrec *user)
        {
                userrec* source = Srv->FindNick(std::string(parameters[0]));
                if (source)
@@ -98,6 +89,7 @@ class ModuleNickLock : public Module
 {
        cmd_nicklock*   cmd1;
        cmd_nickunlock* cmd2;
+       char* n;
  public:
        ModuleNickLock(Server* Me)
                : Module::Module(Me)
@@ -120,12 +112,12 @@ class ModuleNickLock : public Module
 
        void Implements(char* List)
        {
-               List[I_OnUserPreNick] = List[I_OnUserQuit] = 1;
+               List[I_OnUserPreNick] = List[I_OnUserQuit] = List[I_OnCleanup] = 1;
        }
 
-       virtual int OnUserPreNick(userrec* user, std::string newnick)
+       virtual int OnUserPreNick(userrec* user, const std::string &newnick)
        {
-               if (user->GetExt("nick_locked"))
+               if (user->GetExt("nick_locked", n))
                {
                        WriteServ(user->fd,"447 %s :You cannot change your nickname (your nick is locked)",user->nick);
                        return 1;
@@ -133,11 +125,19 @@ class ModuleNickLock : public Module
                return 0;
        }
 
-        virtual void OnUserQuit(userrec* user, std::string reason)
-        {
-                user->Shrink("nick_locked");
-        }
+       virtual void OnUserQuit(userrec* user, const std::string &reason)
+       {
+               user->Shrink("nick_locked");
+       }
 
+       virtual void OnCleanup(int target_type, void* item)
+       {
+               if(target_type == TYPE_USER)
+               {
+                       userrec* user = (userrec*)item;
+                       user->Shrink("nick_locked");
+               }
+       }
 };
 
 // stuff down here is the module-factory stuff. For basic modules you can ignore this.