1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */
20 class CommandNicklock : public Command
24 CommandNicklock (InspIRCd* Instance) : Command(Instance,"NICKLOCK", "o", 2)
26 this->source = "m_nicklock.so";
27 syntax = "<oldnick> <newnick>";
28 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
31 CmdResult Handle(const std::vector<std::string>& parameters, User *user)
33 User* target = ServerInstance->FindNick(parameters[0]);
35 /* Do local sanity checks and bails */
38 if (target && ServerInstance->ULine(target->server))
40 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an NICKLOCK command on a u-lined client",user->nick.c_str());
46 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
50 if (target->GetExt("nick_locked"))
52 user->WriteNumeric(946, "%s %s :This user's nickname is already locked.",user->nick.c_str(),target->nick.c_str());
56 if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
58 user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
63 /* If we made it this far, extend the user */
66 target->Extend("nick_locked", "ON");
67 ServerInstance->SNO->WriteToSnoMask('a', user->nick+" used NICKLOCK to change and hold "+target->nick+" to "+parameters[1]);
69 /* Only send out nick from local server */
72 std::string oldnick = user->nick;
73 std::string newnick = target->nick;
74 if (!target->ForceNickChange(parameters[1].c_str()))
76 /* XXX: We failed, this *should* not happen but if it does
77 * tell everybody. Note user is still nick locked on their old
80 ServerInstance->SNO->WriteToSnoMask('a', oldnick+" failed nickchange on NICKLOCK (from "+newnick+" to "+parameters[1]+") Locked to "+newnick+" instead");
81 ServerInstance->PI->SendSNONotice("A", oldnick+" failed nickchange on NICKLOCK (from "+newnick+" to "+parameters[1]+") Locked to "+newnick+" instead");
91 /** Handle /NICKUNLOCK
93 class CommandNickunlock : public Command
96 CommandNickunlock (InspIRCd* Instance) : Command(Instance,"NICKUNLOCK", "o", 1)
98 this->source = "m_nicklock.so";
99 syntax = "<locked-nick>";
102 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
104 User* target = ServerInstance->FindNick(parameters[0]);
106 /* Do local sanity checks and bails */
109 if (target && ServerInstance->ULine(target->server))
111 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an NICKUNLOCK command on a u-lined client",user->nick.c_str());
117 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
121 if (!target->GetExt("nick_locked"))
123 user->WriteNumeric(946, "%s %s :This user's nickname is not locked.",user->nick.c_str(),target->nick.c_str());
128 /* If we made it this far, the command is going out on the wire so send local snotice */
129 ServerInstance->SNO->WriteToSnoMask('a', std::string(user->nick)+" used NICKUNLOCK on "+parameters[0]);
133 target->Shrink("nick_locked");
135 user->WriteNumeric(945, "%s %s :Nickname now unlocked.",user->nick.c_str(),target->nick.c_str());
144 class ModuleNickLock : public Module
146 CommandNicklock* cmd1;
147 CommandNickunlock* cmd2;
150 ModuleNickLock(InspIRCd* Me)
154 cmd1 = new CommandNicklock(ServerInstance);
155 cmd2 = new CommandNickunlock(ServerInstance);
156 ServerInstance->AddCommand(cmd1);
157 ServerInstance->AddCommand(cmd2);
158 Implementation eventlist[] = { I_OnUserPreNick, I_OnUserQuit, I_OnCleanup };
159 ServerInstance->Modules->Attach(eventlist, this, 3);
162 virtual ~ModuleNickLock()
166 virtual Version GetVersion()
168 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
172 virtual int OnUserPreNick(User* user, const std::string &newnick)
177 if (isdigit(newnick[0])) /* Allow a switch to a UID */
180 if (user->GetExt("NICKForced")) /* Allow forced nick changes */
183 if (user->GetExt("nick_locked", n))
185 user->WriteNumeric(447, "%s :You cannot change your nickname (your nick is locked)",user->nick.c_str());
191 virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
193 user->Shrink("nick_locked");
198 Module *nflood = ServerInstance->Modules->Find("m_nickflood.so");
199 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_BEFORE, &nflood);
202 virtual void OnCleanup(int target_type, void* item)
204 if(target_type == TYPE_USER)
206 User* user = (User*)item;
207 user->Shrink("nick_locked");
212 MODULE_INIT(ModuleNickLock)