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/>.
27 class CommandNicklock : public Command
31 CommandNicklock (Module* Creator, LocalIntExt& ext) : Command(Creator,"NICKLOCK", 2),
35 syntax = "<oldnick> <newnick>";
36 TRANSLATE2(TR_NICK, TR_TEXT);
39 CmdResult Handle(const std::vector<std::string>& parameters, User *user)
41 User* target = ServerInstance->FindNick(parameters[0]);
43 if ((!target) || (target->registered != REG_ALL))
45 user->WriteNotice("*** No such nickname: '" + parameters[0] + "'");
49 /* Do local sanity checks and bails */
52 if (!ServerInstance->IsNick(parameters[1]))
54 user->WriteNotice("*** Invalid nickname '" + parameters[1] + "'");
58 user->WriteNumeric(947, "%s :Nickname now locked.", parameters[1].c_str());
61 /* If we made it this far, extend the user */
64 locked.set(target, 1);
66 std::string oldnick = target->nick;
67 if (target->ChangeNick(parameters[1]))
68 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+oldnick+" to "+parameters[1]);
71 std::string newnick = target->nick;
72 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK, but "+oldnick+" failed nick change to "+parameters[1]+" and was locked to "+newnick+" instead");
79 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
81 User* dest = ServerInstance->FindNick(parameters[0]);
83 return ROUTE_OPT_UCAST(dest->server);
84 return ROUTE_LOCALONLY;
88 /** Handle /NICKUNLOCK
90 class CommandNickunlock : public Command
94 CommandNickunlock (Module* Creator, LocalIntExt& ext) : Command(Creator,"NICKUNLOCK", 1),
98 syntax = "<locked-nick>";
102 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
104 User* target = ServerInstance->FindNick(parameters[0]);
108 user->WriteNotice("*** No such nickname: '" + parameters[0] + "'");
112 if (IS_LOCAL(target))
114 if (locked.set(target, 0))
116 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKUNLOCK on "+target->nick);
117 user->SendText(":%s 945 %s %s :Nickname now unlocked.",
118 ServerInstance->Config->ServerName.c_str(),user->nick.c_str(),target->nick.c_str());
122 user->SendText(":%s 946 %s %s :This user's nickname is not locked.",
123 ServerInstance->Config->ServerName.c_str(),user->nick.c_str(),target->nick.c_str());
131 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
133 User* dest = ServerInstance->FindNick(parameters[0]);
135 return ROUTE_OPT_UCAST(dest->server);
136 return ROUTE_LOCALONLY;
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;
170 Module *nflood = ServerInstance->Modules->Find("m_nickflood.so");
171 ServerInstance->Modules->SetPriority(this, I_OnUserPreNick, PRIORITY_BEFORE, nflood);
175 MODULE_INIT(ModuleNickLock)