1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
20 /* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */
24 class cmd_nicklock : public command_t
28 cmd_nicklock (InspIRCd* Instance) : command_t(Instance,"NICKLOCK", 'o', 2)
30 this->source = "m_nicklock.so";
31 syntax = "<oldnick> <newnick>";
34 CmdResult Handle(const char** parameters, int pcnt, userrec *user)
36 userrec* source = ServerInstance->FindNick(parameters[0]);
46 // check if user is locked
47 if (source->GetExt("nick_locked", dummy))
49 user->WriteServ("946 %s %s :This user's nickname is already locked.",user->nick,source->nick);
53 // check nick is valid
54 if (!ServerInstance->IsNick(parameters[1]))
60 ServerInstance->WriteOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+parameters[0]+" to "+parameters[1]);
62 if (!source->ForceNickChange(parameters[1]))
64 // ugh, nickchange failed for some reason -- possibly existing nick?
65 userrec::QuitUser(ServerInstance, source, "Nickname collision");
69 // give them a lock flag
70 source->Extend("nick_locked", "ON");
77 /** Handle /NICKUNLOCK
79 class cmd_nickunlock : public command_t
82 cmd_nickunlock (InspIRCd* Instance) : command_t(Instance,"NICKUNLOCK", 'o', 1)
84 this->source = "m_nickunlock.so";
85 syntax = "<locked-nick>";
88 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
90 userrec* source = ServerInstance->FindNick(parameters[0]);
93 source->Shrink("nick_locked");
94 user->WriteServ("945 %s %s :Nickname now unlocked.",user->nick,source->nick);
95 ServerInstance->WriteOpers(std::string(user->nick)+" used NICKUNLOCK on "+parameters[0]);
104 class ModuleNickLock : public Module
107 cmd_nickunlock* cmd2;
110 ModuleNickLock(InspIRCd* Me)
114 cmd1 = new cmd_nicklock(ServerInstance);
115 cmd2 = new cmd_nickunlock(ServerInstance);
116 ServerInstance->AddCommand(cmd1);
117 ServerInstance->AddCommand(cmd2);
120 virtual ~ModuleNickLock()
124 virtual Version GetVersion()
126 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
129 void Implements(char* List)
131 List[I_OnUserPreNick] = List[I_OnUserQuit] = List[I_OnCleanup] = 1;
134 virtual int OnUserPreNick(userrec* user, const std::string &newnick)
136 if (user->GetExt("nick_locked", n))
138 user->WriteServ("447 %s :You cannot change your nickname (your nick is locked)",user->nick);
144 virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
146 user->Shrink("nick_locked");
149 virtual void OnCleanup(int target_type, void* item)
151 if(target_type == TYPE_USER)
153 userrec* user = (userrec*)item;
154 user->Shrink("nick_locked");
159 MODULE_INIT(ModuleNickLock);