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"
27 /* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */
31 class cmd_nicklock : public command_t
35 cmd_nicklock () : command_t("NICKLOCK", 'o', 2)
37 this->source = "m_nicklock.so";
38 syntax = "<oldnick> <newnick>";
41 void Handle(const char** parameters, int pcnt, userrec *user)
43 userrec* source = Srv->FindNick(std::string(parameters[0]));
49 if (source->GetExt("nick_locked", dummy))
51 WriteServ(user->fd,"946 %s %s :This user's nickname is already locked.",user->nick,source->nick);
54 if (Srv->IsNick(std::string(parameters[1])))
56 // give them a lock flag
57 Srv->SendOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+std::string(parameters[0])+" to "+parameters[1]);
58 Srv->ChangeUserNick(source,std::string(parameters[1]));
59 // only attempt to set their lockflag after we know the change succeeded
60 source = Srv->FindNick(std::string(parameters[1]));
62 source->Extend("nick_locked", "ON");
68 class cmd_nickunlock : public command_t
71 cmd_nickunlock () : command_t("NICKUNLOCK", 'o', 1)
73 this->source = "m_nickunlock.so";
74 syntax = "<locked-nick>";
77 void Handle (const char** parameters, int pcnt, userrec *user)
79 userrec* source = Srv->FindNick(std::string(parameters[0]));
82 source->Shrink("nick_locked");
83 WriteServ(user->fd,"945 %s %s :Nickname now unlocked.",user->nick,source->nick);
84 Srv->SendOpers(std::string(user->nick)+" used NICKUNLOCK on "+std::string(parameters[0]));
90 class ModuleNickLock : public Module
96 ModuleNickLock(Server* Me)
100 cmd1 = new cmd_nicklock();
101 cmd2 = new cmd_nickunlock();
102 Srv->AddCommand(cmd1);
103 Srv->AddCommand(cmd2);
106 virtual ~ModuleNickLock()
110 virtual Version GetVersion()
112 return Version(1,0,0,1,VF_VENDOR);
115 void Implements(char* List)
117 List[I_OnUserPreNick] = List[I_OnUserQuit] = List[I_OnCleanup] = 1;
120 virtual int OnUserPreNick(userrec* user, const std::string &newnick)
122 if (user->GetExt("nick_locked", n))
124 WriteServ(user->fd,"447 %s :You cannot change your nickname (your nick is locked)",user->nick);
130 virtual void OnUserQuit(userrec* user, const std::string &reason)
132 user->Shrink("nick_locked");
135 virtual void OnCleanup(int target_type, void* item)
137 if(target_type == TYPE_USER)
139 userrec* user = (userrec*)item;
140 user->Shrink("nick_locked");
145 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
147 class ModuleNickLockFactory : public ModuleFactory
150 ModuleNickLockFactory()
154 ~ModuleNickLockFactory()
158 virtual Module * CreateModule(Server* Me)
160 return new ModuleNickLock(Me);
166 extern "C" void * init_module( void )
168 return new ModuleNickLockFactory;