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());
62 user->WriteServ("947 %s %s :Nickname now locked.", user->nick.c_str(), parameters[1].c_str());
65 /* If we made it this far, extend the user */
68 // This has to be done *here*, because this metadata must be stored netwide.
69 target->Extend("nick_locked", "ON");
70 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+target->nick+" to "+parameters[1]);
72 /* Only send out nick from local server */
75 std::string oldnick = user->nick;
76 std::string newnick = target->nick;
77 if (!target->ForceNickChange(parameters[1].c_str()))
79 /* XXX: We failed, this *should* not happen but if it does
80 * tell everybody. Note user is still nick locked on their old
83 ServerInstance->SNO->WriteToSnoMask('a', oldnick+" failed nickchange on NICKLOCK (from "+newnick+" to "+parameters[1]+") Locked to "+newnick+" instead");
84 ServerInstance->PI->SendSNONotice("A", oldnick+" failed nickchange on NICKLOCK (from "+newnick+" to "+parameters[1]+") Locked to "+newnick+" instead");
94 /** Handle /NICKUNLOCK
96 class CommandNickunlock : public Command
99 CommandNickunlock (InspIRCd* Instance) : Command(Instance,"NICKUNLOCK", "o", 1)
101 this->source = "m_nicklock.so";
102 syntax = "<locked-nick>";
105 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
107 User* target = ServerInstance->FindNick(parameters[0]);
109 /* Do local sanity checks and bails */
112 if (target && ServerInstance->ULine(target->server))
114 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an NICKUNLOCK command on a u-lined client",user->nick.c_str());
120 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
124 if (!target->GetExt("nick_locked"))
126 user->WriteNumeric(946, "%s %s :This user's nickname is not locked.",user->nick.c_str(),target->nick.c_str());
131 /* If we made it this far, the command is going out on the wire so send local snotice */
132 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick)+" used NICKUNLOCK on "+parameters[0]);
136 target->Shrink("nick_locked");
138 user->WriteNumeric(945, "%s %s :Nickname now unlocked.",user->nick.c_str(),target->nick.c_str());
147 class ModuleNickLock : public Module
149 CommandNicklock* cmd1;
150 CommandNickunlock* cmd2;
153 ModuleNickLock(InspIRCd* Me)
157 cmd1 = new CommandNicklock(ServerInstance);
158 cmd2 = new CommandNickunlock(ServerInstance);
159 ServerInstance->AddCommand(cmd1);
160 ServerInstance->AddCommand(cmd2);
161 Implementation eventlist[] = { I_OnUserPreNick, I_OnUserQuit, I_OnCleanup };
162 ServerInstance->Modules->Attach(eventlist, this, 3);
165 virtual ~ModuleNickLock()
169 virtual Version GetVersion()
171 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
175 virtual int OnUserPreNick(User* user, const std::string &newnick)
180 if (isdigit(newnick[0])) /* Allow a switch to a UID */
183 if (user->GetExt("NICKForced")) /* Allow forced nick changes */
186 if (user->GetExt("nick_locked", n))
188 user->WriteNumeric(447, "%s :You cannot change your nickname (your nick is locked)",user->nick.c_str());
194 virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
196 user->Shrink("nick_locked");
201 Module *nflood = ServerInstance->Modules->Find("m_nickflood.so");
202 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_BEFORE, &nflood);
205 virtual void OnCleanup(int target_type, void* item)
207 if(target_type == TYPE_USER)
209 User* user = (User*)item;
210 user->Shrink("nick_locked");
215 MODULE_INIT(ModuleNickLock)