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/>.
28 ERR_NICKNOTLOCKED = 946,
35 class CommandNicklock : public Command
39 CommandNicklock (Module* Creator, LocalIntExt& ext) : Command(Creator,"NICKLOCK", 2),
43 syntax = "<oldnick> <newnick>";
44 TRANSLATE2(TR_NICK, TR_TEXT);
47 CmdResult Handle(const std::vector<std::string>& parameters, User *user)
49 User* target = ServerInstance->FindNick(parameters[0]);
51 if ((!target) || (target->registered != REG_ALL))
53 user->WriteNotice("*** No such nickname: '" + parameters[0] + "'");
57 /* Do local sanity checks and bails */
60 if (!ServerInstance->IsNick(parameters[1]))
62 user->WriteNotice("*** Invalid nickname '" + parameters[1] + "'");
66 user->WriteNumeric(RPL_NICKLOCKON, parameters[1], "Nickname now locked.");
69 /* If we made it this far, extend the user */
72 locked.set(target, 1);
74 std::string oldnick = target->nick;
75 if (target->ChangeNick(parameters[1]))
76 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+oldnick+" to "+parameters[1]);
79 std::string newnick = target->nick;
80 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK, but "+oldnick+" failed nick change to "+parameters[1]+" and was locked to "+newnick+" instead");
87 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
89 return ROUTE_OPT_UCAST(parameters[0]);
93 /** Handle /NICKUNLOCK
95 class CommandNickunlock : public Command
99 CommandNickunlock (Module* Creator, LocalIntExt& ext) : Command(Creator,"NICKUNLOCK", 1),
103 syntax = "<locked-nick>";
107 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
109 User* target = ServerInstance->FindNick(parameters[0]);
113 user->WriteNotice("*** No such nickname: '" + parameters[0] + "'");
117 if (IS_LOCAL(target))
119 if (locked.set(target, 0))
121 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKUNLOCK on "+target->nick);
122 user->WriteRemoteNumeric(RPL_NICKLOCKOFF, target->nick, "Nickname now unlocked.");
126 user->WriteRemoteNumeric(ERR_NICKNOTLOCKED, target->nick, "This user's nickname is not locked.");
134 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
136 return ROUTE_OPT_UCAST(parameters[0]);
140 class ModuleNickLock : public Module
143 CommandNicklock cmd1;
144 CommandNickunlock cmd2;
147 : locked("nick_locked", ExtensionItem::EXT_USER, this)
153 Version GetVersion() CXX11_OVERRIDE
155 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);
158 ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE
160 if (locked.get(user))
162 user->WriteNumeric(ERR_CANTCHANGENICK, "You cannot change your nickname (your nick is locked)");
165 return MOD_RES_PASSTHRU;
168 void Prioritize() CXX11_OVERRIDE
170 Module *nflood = ServerInstance->Modules->Find("m_nickflood.so");
171 ServerInstance->Modules->SetPriority(this, I_OnUserPreNick, PRIORITY_BEFORE, nflood);
175 MODULE_INIT(ModuleNickLock)