2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
7 * Copyright (C) 2005-2006 Craig Edwards <craigedwards@brainbox.cc>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 /* $ModDesc: Provides the NICKLOCK command, allows an oper to change a users nick and lock them to it until they quit */
29 class CommandNicklock : public Command
33 CommandNicklock (Module* Creator, LocalIntExt& ext) : Command(Creator,"NICKLOCK", 2),
37 syntax = "<oldnick> <newnick>";
38 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
41 CmdResult Handle(const std::vector<std::string>& parameters, User *user)
43 User* target = ServerInstance->FindNick(parameters[0]);
45 if ((!target) || (target->registered != REG_ALL))
47 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
51 /* Do local sanity checks and bails */
54 if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
56 user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
60 user->WriteServ("947 %s %s :Nickname now locked.", user->nick.c_str(), parameters[1].c_str());
63 /* If we made it this far, extend the user */
66 locked.set(target, 1);
68 std::string oldnick = target->nick;
69 if (target->ForceNickChange(parameters[1].c_str()))
70 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+oldnick+" to "+parameters[1]);
73 std::string newnick = target->nick;
74 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK, but "+oldnick+" failed nick change to "+parameters[1]+" and was locked to "+newnick+" instead");
81 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
83 User* dest = ServerInstance->FindNick(parameters[0]);
85 return ROUTE_OPT_UCAST(dest->server);
86 return ROUTE_LOCALONLY;
90 /** Handle /NICKUNLOCK
92 class CommandNickunlock : public Command
96 CommandNickunlock (Module* Creator, LocalIntExt& ext) : Command(Creator,"NICKUNLOCK", 1),
100 syntax = "<locked-nick>";
101 TRANSLATE2(TR_NICK, TR_END);
104 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
106 User* target = ServerInstance->FindNick(parameters[0]);
110 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
114 if (IS_LOCAL(target))
116 if (locked.set(target, 0))
118 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKUNLOCK on "+target->nick);
119 user->SendText(":%s 945 %s %s :Nickname now unlocked.",
120 ServerInstance->Config->ServerName.c_str(),user->nick.c_str(),target->nick.c_str());
124 user->SendText(":%s 946 %s %s :This user's nickname is not locked.",
125 ServerInstance->Config->ServerName.c_str(),user->nick.c_str(),target->nick.c_str());
133 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
135 User* dest = ServerInstance->FindNick(parameters[0]);
137 return ROUTE_OPT_UCAST(dest->server);
138 return ROUTE_LOCALONLY;
143 class ModuleNickLock : public Module
146 CommandNicklock cmd1;
147 CommandNickunlock cmd2;
150 : locked("nick_locked", this), cmd1(this, locked), cmd2(this, locked)
156 ServerInstance->Modules->AddService(cmd1);
157 ServerInstance->Modules->AddService(cmd2);
158 ServerInstance->Modules->AddService(locked);
159 ServerInstance->Modules->Attach(I_OnUserPreNick, this);
168 return Version("Provides the NICKLOCK command, allows an oper to change a users nick and lock them to it until they quit", VF_OPTCOMMON | VF_VENDOR);
171 ModResult OnUserPreNick(User* user, const std::string &newnick)
174 return MOD_RES_PASSTHRU;
176 if (ServerInstance->NICKForced.get(user)) /* Allow forced nick changes */
177 return MOD_RES_PASSTHRU;
179 if (locked.get(user))
181 user->WriteNumeric(447, "%s :You cannot change your nickname (your nick is locked)",user->nick.c_str());
184 return MOD_RES_PASSTHRU;
189 Module *nflood = ServerInstance->Modules->Find("m_nickflood.so");
190 ServerInstance->Modules->SetPriority(this, I_OnUserPreNick, PRIORITY_BEFORE, &nflood);
194 MODULE_INIT(ModuleNickLock)