]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_nicklock.cpp
A few more I missed.
[user/henk/code/inspircd.git] / src / modules / m_nicklock.cpp
index ca0c030accd3e0d0978afcb89703cc86e0b88e98..26d5bfbd7f1c1c6f55d0f95c37de059bfe83fa88 100644 (file)
@@ -2,32 +2,23 @@
  *       | 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.
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
  *
  * ---------------------------------------------------
  */
 
-using namespace std;
-
-#include <stdio.h>
-#include <string>
+#include "inspircd.h"
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-
 #include "hashcomp.h"
-#include "inspircd.h"
 
 /* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */
 
-
 /** Handle /NICKLOCK
  */
 class cmd_nicklock : public command_t
@@ -46,31 +37,40 @@ class cmd_nicklock : public command_t
                irc::string server;
                irc::string me;
 
-               if (source)
+               // check user exists
+               if (!source)
                {
-                       if (source->GetExt("nick_locked", dummy))
-                       {
-                               user->WriteServ("946 %s %s :This user's nickname is already locked.",user->nick,source->nick);
-                               return CMD_FAILURE;
-                       }
-                       if (ServerInstance->IsNick(parameters[1]))
-                       {
-                               // give them a lock flag
-                               ServerInstance->WriteOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+parameters[0]+" to "+parameters[1]);
-                               if (!source->ForceNickChange(parameters[1]))
-                               {
-                                       userrec::QuitUser(ServerInstance, source, "Nickname collision");
-                                       return CMD_FAILURE;
-                               }
-                               source->Extend("nick_locked", "ON");
-
-                               return CMD_SUCCESS;
-                       }
+                       return CMD_FAILURE;
+               }
 
+               // check if user is locked
+               if (source->GetExt("nick_locked", dummy))
+               {
+                       user->WriteServ("946 %s %s :This user's nickname is already locked.",user->nick,source->nick);
                        return CMD_FAILURE;
                }
 
-               return CMD_FAILURE;
+               // check nick is valid
+               if (!ServerInstance->IsNick(parameters[1]))
+               {
+                       return CMD_FAILURE;
+               }
+
+               // let others know
+               ServerInstance->WriteOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+parameters[0]+" to "+parameters[1]);
+
+               if (!source->ForceNickChange(parameters[1]))
+               {
+                       // ugh, nickchange failed for some reason -- possibly existing nick?
+                       userrec::QuitUser(ServerInstance, source, "Nickname collision");
+                       return CMD_FAILURE;
+               }
+
+               // give them a lock flag
+               source->Extend("nick_locked", "ON");
+
+               /* route */
+               return CMD_SUCCESS;
        }
 };
 
@@ -108,7 +108,7 @@ class ModuleNickLock : public Module
        char* n;
  public:
        ModuleNickLock(InspIRCd* Me)
-               : Module::Module(Me)
+               : Module(Me)
        {
                
                cmd1 = new cmd_nicklock(ServerInstance);
@@ -123,7 +123,7 @@ class ModuleNickLock : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,1,VF_VENDOR,API_VERSION);
+               return Version(1,1,0,1,VF_VENDOR,API_VERSION);
        }
 
        void Implements(char* List)
@@ -141,7 +141,7 @@ class ModuleNickLock : public Module
                return 0;
        }
 
-       virtual void OnUserQuit(userrec* user, const std::string &reason)
+       virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
        {
                user->Shrink("nick_locked");
        }
@@ -156,29 +156,4 @@ class ModuleNickLock : public Module
        }
 };
 
-// stuff down here is the module-factory stuff. For basic modules you can ignore this.
-
-class ModuleNickLockFactory : public ModuleFactory
-{
- public:
-       ModuleNickLockFactory()
-       {
-       }
-       
-       ~ModuleNickLockFactory()
-       {
-       }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleNickLock(Me);
-       }
-       
-};
-
-
-extern "C" void * init_module( void )
-{
-       return new ModuleNickLockFactory;
-}
-
+MODULE_INIT(ModuleNickLock)