2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2017-2018 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012-2016 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9 * Copyright (C) 2007-2009 Robin Burchell <robin+git@viroteck.net>
10 * Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
11 * Copyright (C) 2006, 2008, 2010 Craig Edwards <brain@inspircd.org>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 ERR_NICKNOTLOCKED = 946,
39 class CommandNicklock : public Command
43 CommandNicklock (Module* Creator, LocalIntExt& ext) : Command(Creator,"NICKLOCK", 2),
47 syntax = "<nick> <newnick>";
48 TRANSLATE2(TR_NICK, TR_TEXT);
51 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
53 User* target = ServerInstance->FindNick(parameters[0]);
55 if ((!target) || (target->registered != REG_ALL))
57 user->WriteNotice("*** No such nickname: '" + parameters[0] + "'");
61 /* Do local sanity checks and bails */
64 if (!ServerInstance->IsNick(parameters[1]))
66 user->WriteNotice("*** Invalid nickname '" + parameters[1] + "'");
70 user->WriteNumeric(RPL_NICKLOCKON, parameters[1], "Nickname now locked.");
73 /* If we made it this far, extend the user */
76 locked.set(target, 1);
78 std::string oldnick = target->nick;
79 if (target->ChangeNick(parameters[1]))
80 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+oldnick+" to "+parameters[1]);
83 std::string newnick = target->nick;
84 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK, but "+oldnick+" failed nick change to "+parameters[1]+" and was locked to "+newnick+" instead");
91 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
93 return ROUTE_OPT_UCAST(parameters[0]);
97 /** Handle /NICKUNLOCK
99 class CommandNickunlock : public Command
103 CommandNickunlock (Module* Creator, LocalIntExt& ext) : Command(Creator,"NICKUNLOCK", 1),
111 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
113 User* target = ServerInstance->FindNick(parameters[0]);
117 user->WriteNotice("*** No such nickname: '" + parameters[0] + "'");
121 if (IS_LOCAL(target))
123 if (locked.set(target, 0))
125 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKUNLOCK on "+target->nick);
126 user->WriteRemoteNumeric(RPL_NICKLOCKOFF, target->nick, "Nickname now unlocked.");
130 user->WriteRemoteNumeric(ERR_NICKNOTLOCKED, target->nick, "This user's nickname is not locked.");
138 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
140 return ROUTE_OPT_UCAST(parameters[0]);
144 class ModuleNickLock : public Module
147 CommandNicklock cmd1;
148 CommandNickunlock cmd2;
151 : locked("nick_locked", ExtensionItem::EXT_USER, this)
157 Version GetVersion() CXX11_OVERRIDE
159 return Version("Adds the /NICKLOCK command which allows server operators to change a user's nickname and prevent them from changing it again until they disconnect.", VF_OPTCOMMON | VF_VENDOR);
162 ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE
164 if (locked.get(user))
166 user->WriteNumeric(ERR_CANTCHANGENICK, "You cannot change your nickname (your nick is locked)");
169 return MOD_RES_PASSTHRU;
172 void Prioritize() CXX11_OVERRIDE
174 Module *nflood = ServerInstance->Modules->Find("m_nickflood.so");
175 ServerInstance->Modules->SetPriority(this, I_OnUserPreNick, PRIORITY_BEFORE, nflood);
179 MODULE_INIT(ModuleNickLock)