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(Creator,"NICKLOCK", 2),
28 syntax = "<oldnick> <newnick>";
29 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
32 CmdResult Handle(const std::vector<std::string>& parameters, User *user)
34 User* target = ServerInstance->FindNick(parameters[0]);
36 /* Do local sanity checks and bails */
39 if (target && ServerInstance->ULine(target->server))
41 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an NICKLOCK command on a u-lined client",user->nick.c_str());
47 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
51 if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
53 user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
57 user->WriteServ("947 %s %s :Nickname now locked.", user->nick.c_str(), parameters[1].c_str());
60 /* If we made it this far, extend the user */
61 if (target && IS_LOCAL(target))
63 locked.set(target, 1);
65 std::string oldnick = target->nick;
66 if (target->ForceNickChange(parameters[1].c_str()))
67 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+oldnick+" to "+parameters[1]);
70 std::string newnick = target->nick;
71 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK, but "+oldnick+" failed nick change to "+parameters[1]+" and was locked to "+newnick+" instead");
78 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
80 User* dest = ServerInstance->FindNick(parameters[0]);
82 return ROUTE_OPT_UCAST(dest->server);
83 return ROUTE_LOCALONLY;
87 /** Handle /NICKUNLOCK
89 class CommandNickunlock : public Command
93 CommandNickunlock (Module* Creator, LocalIntExt& ext) : Command(Creator,"NICKUNLOCK", 1),
97 syntax = "<locked-nick>";
98 TRANSLATE2(TR_NICK, TR_END);
101 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
103 User* target = ServerInstance->FindNick(parameters[0]);
105 /* Do local sanity checks and bails */
108 if (target && ServerInstance->ULine(target->server))
110 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an NICKUNLOCK command on a u-lined client",user->nick.c_str());
116 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
121 if (target && IS_LOCAL(target))
123 if (locked.set(target, 0))
125 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick)+" used NICKUNLOCK on "+parameters[0]);
126 user->WriteNumeric(945, "%s %s :Nickname now unlocked.",user->nick.c_str(),target->nick.c_str());
130 user->WriteNumeric(946, "%s %s :This user's nickname is not locked.",user->nick.c_str(),target->nick.c_str());
138 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
140 User* dest = ServerInstance->FindNick(parameters[0]);
142 return ROUTE_OPT_UCAST(dest->server);
143 return ROUTE_LOCALONLY;
148 class ModuleNickLock : public Module
151 CommandNicklock cmd1;
152 CommandNickunlock cmd2;
155 : locked("nick_locked", this), cmd1(this, locked), cmd2(this, locked)
157 ServerInstance->AddCommand(&cmd1);
158 ServerInstance->AddCommand(&cmd2);
159 ServerInstance->Extensions.Register(&locked);
160 ServerInstance->Modules->Attach(I_OnUserPreNick, this);
169 return Version("Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit", VF_COMMON | VF_VENDOR);
173 ModResult OnUserPreNick(User* user, const std::string &newnick)
176 return MOD_RES_PASSTHRU;
178 if (isdigit(newnick[0])) /* Allow a switch to a UID */
179 return MOD_RES_PASSTHRU;
181 if (ServerInstance->NICKForced.get(user)) /* Allow forced nick changes */
182 return MOD_RES_PASSTHRU;
184 if (locked.get(user))
186 user->WriteNumeric(447, "%s :You cannot change your nickname (your nick is locked)",user->nick.c_str());
189 return MOD_RES_PASSTHRU;
194 Module *nflood = ServerInstance->Modules->Find("m_nickflood.so");
195 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_BEFORE, &nflood);
199 MODULE_INIT(ModuleNickLock)