1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
24 #include "helperfuncs.h"
28 /* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */
31 extern InspIRCd* ServerInstance;
33 class cmd_nicklock : public command_t
37 cmd_nicklock () : command_t("NICKLOCK", 'o', 2)
39 this->source = "m_nicklock.so";
40 syntax = "<oldnick> <newnick>";
43 void Handle(const char** parameters, int pcnt, userrec *user)
45 userrec* source = ServerInstance->FindNick(parameters[0]);
51 if (source->GetExt("nick_locked", dummy))
53 user->WriteServ("946 %s %s :This user's nickname is already locked.",user->nick,source->nick);
56 if (ServerInstance->IsNick(parameters[1]))
58 // give them a lock flag
59 ServerInstance->WriteOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+parameters[0]+" to "+parameters[1]);
60 if (!source->ForceNickChange(parameters[1]))
62 userrec::QuitUser(ServerInstance, source, "Nickname collision");
65 source->Extend("nick_locked", "ON");
71 class cmd_nickunlock : public command_t
74 cmd_nickunlock () : command_t("NICKUNLOCK", 'o', 1)
76 this->source = "m_nickunlock.so";
77 syntax = "<locked-nick>";
80 void Handle (const char** parameters, int pcnt, userrec *user)
82 userrec* source = ServerInstance->FindNick(parameters[0]);
85 source->Shrink("nick_locked");
86 user->WriteServ("945 %s %s :Nickname now unlocked.",user->nick,source->nick);
87 ServerInstance->WriteOpers(std::string(user->nick)+" used NICKUNLOCK on "+parameters[0]);
93 class ModuleNickLock : public Module
99 ModuleNickLock(Server* Me)
103 cmd1 = new cmd_nicklock();
104 cmd2 = new cmd_nickunlock();
105 Srv->AddCommand(cmd1);
106 Srv->AddCommand(cmd2);
109 virtual ~ModuleNickLock()
113 virtual Version GetVersion()
115 return Version(1,0,0,1,VF_VENDOR);
118 void Implements(char* List)
120 List[I_OnUserPreNick] = List[I_OnUserQuit] = List[I_OnCleanup] = 1;
123 virtual int OnUserPreNick(userrec* user, const std::string &newnick)
125 if (user->GetExt("nick_locked", n))
127 user->WriteServ("447 %s :You cannot change your nickname (your nick is locked)",user->nick);
133 virtual void OnUserQuit(userrec* user, const std::string &reason)
135 user->Shrink("nick_locked");
138 virtual void OnCleanup(int target_type, void* item)
140 if(target_type == TYPE_USER)
142 userrec* user = (userrec*)item;
143 user->Shrink("nick_locked");
148 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
150 class ModuleNickLockFactory : public ModuleFactory
153 ModuleNickLockFactory()
157 ~ModuleNickLockFactory()
161 virtual Module * CreateModule(Server* Me)
163 return new ModuleNickLock(Me);
169 extern "C" void * init_module( void )
171 return new ModuleNickLockFactory;