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 (InspIRCd* Instance, Module* Creator) : Command(Instance, Creator,"NICKLOCK", "o", 2)
26 syntax = "<oldnick> <newnick>";
27 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
30 CmdResult Handle(const std::vector<std::string>& parameters, User *user)
32 User* target = ServerInstance->FindNick(parameters[0]);
34 /* Do local sanity checks and bails */
37 if (target && ServerInstance->ULine(target->server))
39 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an NICKLOCK command on a u-lined client",user->nick.c_str());
45 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
49 if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
51 user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
55 user->WriteServ("947 %s %s :Nickname now locked.", user->nick.c_str(), parameters[1].c_str());
58 /* If we made it this far, extend the user */
59 if (target && IS_LOCAL(target))
61 // This has to be done *here*, because this metadata must be stored netwide.
62 target->Extend("nick_locked", "ON");
64 /* Only send out nick from local server */
65 target->Extend("nick_locked");
67 std::string oldnick = target->nick;
68 if (target->ForceNickChange(parameters[1].c_str()))
69 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+oldnick+" to "+parameters[1]);
72 std::string newnick = target->nick;
73 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK, but "+oldnick+" failed nick change to "+parameters[1]+" and was locked to "+newnick+" instead");
80 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
82 User* dest = ServerInstance->FindNick(parameters[0]);
84 return ROUTE_OPT_UCAST(dest->server);
85 return ROUTE_LOCALONLY;
89 /** Handle /NICKUNLOCK
91 class CommandNickunlock : public Command
94 CommandNickunlock (InspIRCd* Instance, Module* Creator) : Command(Instance, Creator,"NICKUNLOCK", "o", 1)
96 syntax = "<locked-nick>";
97 TRANSLATE2(TR_NICK, TR_END);
100 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
102 User* target = ServerInstance->FindNick(parameters[0]);
104 /* Do local sanity checks and bails */
107 if (target && ServerInstance->ULine(target->server))
109 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an NICKUNLOCK command on a u-lined client",user->nick.c_str());
115 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
120 if (target && IS_LOCAL(target))
122 if (target->Shrink("nick_locked"))
124 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick)+" used NICKUNLOCK on "+parameters[0]);
125 user->WriteNumeric(945, "%s %s :Nickname now unlocked.",user->nick.c_str(),target->nick.c_str());
129 user->WriteNumeric(946, "%s %s :This user's nickname is not locked.",user->nick.c_str(),target->nick.c_str());
137 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
139 User* dest = ServerInstance->FindNick(parameters[0]);
141 return ROUTE_OPT_UCAST(dest->server);
142 return ROUTE_LOCALONLY;
147 class ModuleNickLock : public Module
149 CommandNicklock cmd1;
150 CommandNickunlock cmd2;
152 ModuleNickLock(InspIRCd* Me)
153 : Module(Me), cmd1(Me, this), cmd2(Me, this)
155 ServerInstance->AddCommand(&cmd1);
156 ServerInstance->AddCommand(&cmd2);
157 Implementation eventlist[] = { I_OnUserPreNick, I_OnUserQuit, I_OnCleanup };
158 ServerInstance->Modules->Attach(eventlist, this, 3);
161 virtual ~ModuleNickLock()
165 virtual Version GetVersion()
167 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
171 virtual 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->GetExt("NICKForced")) /* Allow forced nick changes */
180 return MOD_RES_PASSTHRU;
182 if (user->GetExt("nick_locked"))
184 user->WriteNumeric(447, "%s :You cannot change your nickname (your nick is locked)",user->nick.c_str());
187 return MOD_RES_PASSTHRU;
190 virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
192 user->Shrink("nick_locked");
197 Module *nflood = ServerInstance->Modules->Find("m_nickflood.so");
198 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_BEFORE, &nflood);
201 virtual void OnCleanup(int target_type, void* item)
203 if(target_type == TYPE_USER)
205 User* user = (User*)item;
206 user->Shrink("nick_locked");
211 MODULE_INIT(ModuleNickLock)