]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_nicklock.cpp
and a little tweak to remote MOTD too.
[user/henk/code/inspircd.git] / src / modules / m_nicklock.cpp
index 519aabe13937de5b2b8aa7816fb34d4c3cb0d826..071eda8ee29b34fc8d3800edafeefe6a3fa82d48 100644 (file)
  * ---------------------------------------------------
  */
 
-#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
@@ -41,33 +37,40 @@ class cmd_nicklock : public command_t
                irc::string server;
                irc::string me;
 
-               /* XXX - these ifs look damn ugly, note to myself to fix them -- w00t */
-               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");
-
-                               /* route */
-                               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;
        }
 };
 
@@ -105,7 +108,7 @@ class ModuleNickLock : public Module
        char* n;
  public:
        ModuleNickLock(InspIRCd* Me)
-               : Module::Module(Me)
+               : Module(Me)
        {
                
                cmd1 = new cmd_nicklock(ServerInstance);
@@ -174,7 +177,7 @@ class ModuleNickLockFactory : public ModuleFactory
 };
 
 
-extern "C" void * init_module( void )
+extern "C" DllExport void * init_module( void )
 {
        return new ModuleNickLockFactory;
 }