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 (Module* Creator, LocalIntExt& ext) : Command(ServerInstance, Creator,"NICKLOCK", "o", 2),
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 (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
52 user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
56 user->WriteServ("947 %s %s :Nickname now locked.", user->nick.c_str(), parameters[1].c_str());
59 /* If we made it this far, extend the user */
60 if (target && IS_LOCAL(target))
62 locked.set(target, 1);
64 std::string oldnick = target->nick;
65 if (target->ForceNickChange(parameters[1].c_str()))
66 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+oldnick+" to "+parameters[1]);
69 std::string newnick = target->nick;
70 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK, but "+oldnick+" failed nick change to "+parameters[1]+" and was locked to "+newnick+" instead");
77 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
79 User* dest = ServerInstance->FindNick(parameters[0]);
81 return ROUTE_OPT_UCAST(dest->server);
82 return ROUTE_LOCALONLY;
86 /** Handle /NICKUNLOCK
88 class CommandNickunlock : public Command
92 CommandNickunlock (Module* Creator, LocalIntExt& ext) : Command(ServerInstance, Creator,"NICKUNLOCK", "o", 1),
95 syntax = "<locked-nick>";
96 TRANSLATE2(TR_NICK, TR_END);
99 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
101 User* target = ServerInstance->FindNick(parameters[0]);
103 /* Do local sanity checks and bails */
106 if (target && ServerInstance->ULine(target->server))
108 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an NICKUNLOCK command on a u-lined client",user->nick.c_str());
114 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
119 if (target && IS_LOCAL(target))
121 if (locked.set(target, 0))
123 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick)+" used NICKUNLOCK on "+parameters[0]);
124 user->WriteNumeric(945, "%s %s :Nickname now unlocked.",user->nick.c_str(),target->nick.c_str());
128 user->WriteNumeric(946, "%s %s :This user's nickname is not locked.",user->nick.c_str(),target->nick.c_str());
136 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
138 User* dest = ServerInstance->FindNick(parameters[0]);
140 return ROUTE_OPT_UCAST(dest->server);
141 return ROUTE_LOCALONLY;
146 class ModuleNickLock : public Module
149 CommandNicklock cmd1;
150 CommandNickunlock cmd2;
152 ModuleNickLock(InspIRCd* Me)
153 : Module(Me), locked("nick_locked", this), cmd1(this, locked), cmd2(this, locked)
155 ServerInstance->AddCommand(&cmd1);
156 ServerInstance->AddCommand(&cmd2);
157 Extensible::Register(&locked);
158 ServerInstance->Modules->Attach(I_OnUserPreNick, this);
167 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
171 ModResult OnUserPreNick(User* user, const std::string &newnick)
174 return MOD_RES_PASSTHRU;
176 if (isdigit(newnick[0])) /* Allow a switch to a UID */
177 return MOD_RES_PASSTHRU;
179 if (User::NICKForced.get(user)) /* Allow forced nick changes */
180 return MOD_RES_PASSTHRU;
182 if (locked.get(user))
184 user->WriteNumeric(447, "%s :You cannot change your nickname (your nick is locked)",user->nick.c_str());
187 return MOD_RES_PASSTHRU;
192 Module *nflood = ServerInstance->Modules->Find("m_nickflood.so");
193 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_BEFORE, &nflood);
197 MODULE_INIT(ModuleNickLock)