1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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]);
38 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
42 /* Do local sanity checks and bails */
45 if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
47 user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
51 user->WriteServ("947 %s %s :Nickname now locked.", user->nick.c_str(), parameters[1].c_str());
54 /* If we made it this far, extend the user */
57 locked.set(target, 1);
59 std::string oldnick = target->nick;
60 if (target->ForceNickChange(parameters[1].c_str()))
61 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+oldnick+" to "+parameters[1]);
64 std::string newnick = target->nick;
65 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK, but "+oldnick+" failed nick change to "+parameters[1]+" and was locked to "+newnick+" instead");
72 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
74 User* dest = ServerInstance->FindNick(parameters[0]);
76 return ROUTE_OPT_UCAST(dest->server);
77 return ROUTE_LOCALONLY;
81 /** Handle /NICKUNLOCK
83 class CommandNickunlock : public Command
87 CommandNickunlock (Module* Creator, LocalIntExt& ext) : Command(Creator,"NICKUNLOCK", 1),
91 syntax = "<locked-nick>";
92 TRANSLATE2(TR_NICK, TR_END);
95 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
97 User* target = ServerInstance->FindNick(parameters[0]);
101 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
105 if (IS_LOCAL(target))
107 if (locked.set(target, 0))
109 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKUNLOCK on "+target->nick);
110 user->SendText(":%s 945 %s %s :Nickname now unlocked.",
111 ServerInstance->Config->ServerName.c_str(),user->nick.c_str(),target->nick.c_str());
115 user->SendText(":%s 946 %s %s :This user's nickname is not locked.",
116 ServerInstance->Config->ServerName.c_str(),user->nick.c_str(),target->nick.c_str());
124 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
126 User* dest = ServerInstance->FindNick(parameters[0]);
128 return ROUTE_OPT_UCAST(dest->server);
129 return ROUTE_LOCALONLY;
134 class ModuleNickLock : public Module
137 CommandNicklock cmd1;
138 CommandNickunlock cmd2;
141 : locked("nick_locked", this), cmd1(this, locked), cmd2(this, locked)
143 ServerInstance->AddCommand(&cmd1);
144 ServerInstance->AddCommand(&cmd2);
145 ServerInstance->Extensions.Register(&locked);
146 ServerInstance->Modules->Attach(I_OnUserPreNick, this);
155 return Version("Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit", VF_OPTCOMMON | VF_VENDOR);
158 ModResult OnUserPreNick(User* user, const std::string &newnick)
161 return MOD_RES_PASSTHRU;
163 if (ServerInstance->NICKForced.get(user)) /* Allow forced nick changes */
164 return MOD_RES_PASSTHRU;
166 if (locked.get(user))
168 user->WriteNumeric(447, "%s :You cannot change your nickname (your nick is locked)",user->nick.c_str());
171 return MOD_RES_PASSTHRU;
176 Module *nflood = ServerInstance->Modules->Find("m_nickflood.so");
177 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_BEFORE, &nflood);
181 MODULE_INIT(ModuleNickLock)