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 a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel */
19 * This module supports the use of the +q and +a usermodes, but should work without them too.
20 * Usage of the command is restricted to +hoaq, and you cannot remove a user with a "higher" level than yourself.
21 * eg: +h can remove +hv and users with no modes. +a can remove +aohv and users with no modes.
24 /** Base class for /FPART and /REMOVE
26 class RemoveBase : public Command
32 RemoveBase(Module* Creator, bool& snk, const char* cmdn)
33 : Command(Creator, cmdn, 2, 3), supportnokicks(snk)
37 CmdResult HandleRMB(const std::vector<std::string>& parameters, User *user, bool neworder)
44 std::string protectkey;
45 std::string founderkey;
48 /* Set these to the parameters needed, the new version of this module switches it's parameters around
49 * supplying a new command with the new order while keeping the old /remove with the older order.
50 * /remove <nick> <channel> [reason ...]
51 * /fpart <channel> <nick> [reason ...]
53 channame = parameters[ neworder ? 0 : 1].c_str();
54 username = parameters[ neworder ? 1 : 0].c_str();
56 /* Look up the user we're meant to be removing from the channel */
57 target = ServerInstance->FindNick(username);
59 /* And the channel we're meant to be removing them from */
60 channel = ServerInstance->FindChan(channame);
62 /* Fix by brain - someone needs to learn to validate their input! */
63 if (!target || !channel)
65 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), !target ? username : channame);
69 if (!channel->HasUser(target))
71 user->WriteServ( "NOTICE %s :*** The user %s is not on channel %s", user->nick.c_str(), target->nick.c_str(), channel->name.c_str());
75 int ulevel = channel->GetPrefixValue(user);
76 int tlevel = channel->GetPrefixValue(target);
78 hasnokicks = (ServerInstance->Modules->Find("m_nokicks.so") && channel->IsModeSet('Q'));
80 /* We support the +Q channel mode via. the m_nokicks module, if the module is loaded and the mode is set then disallow the /remove */
81 if ((!IS_LOCAL(user)) || (!supportnokicks || !hasnokicks))
83 /* We'll let everyone remove their level and below, eg:
84 * ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1)
85 * a ulined target will get a higher level than it's possible for a /remover to get..so they're safe.
86 * Nobody may remove a founder.
88 if ((!IS_LOCAL(user)) || ((ulevel > VOICE_VALUE) && (ulevel >= tlevel) && (tlevel != 50000)))
90 // no you can't just go from a std::ostringstream to a std::string, Om. -nenolod
91 // but you can do this, nenolod -brain
93 std::string reasonparam("No reason given");
95 /* If a reason is given, use it */
96 if(parameters.size() > 2)
98 /* Join params 2 ... pcnt - 1 (inclusive) into one */
99 irc::stringjoiner reason_join(" ", parameters, 2, parameters.size() - 1);
100 reasonparam = reason_join.GetJoined();
103 /* Build up the part reason string. */
104 reason = std::string("Removed by ") + user->nick + ": " + reasonparam;
106 channel->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s removed %s from the channel", channel->name.c_str(), user->nick.c_str(), target->nick.c_str());
107 target->WriteServ("NOTICE %s :*** %s removed you from %s with the message: %s", target->nick.c_str(), user->nick.c_str(), channel->name.c_str(), reasonparam.c_str());
109 channel->PartUser(target, reason);
113 user->WriteServ( "NOTICE %s :*** You do not have access to /remove %s from %s", user->nick.c_str(), target->nick.c_str(), channel->name.c_str());
119 /* m_nokicks.so was loaded and +Q was set, block! */
120 user->WriteServ( "484 %s %s :Can't remove user %s from channel (+Q set)", user->nick.c_str(), channel->name.c_str(), target->nick.c_str());
126 virtual RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) = 0;
131 class CommandRemove : public RemoveBase
134 CommandRemove(Module* Creator, bool& snk)
135 : RemoveBase(Creator, snk, "REMOVE")
137 syntax = "<nick> <channel> [<reason>]";
138 TRANSLATE4(TR_NICK, TR_TEXT, TR_TEXT, TR_END);
141 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
143 return HandleRMB(parameters, user, false);
146 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
148 User* dest = ServerInstance->FindNick(parameters[0]);
150 return ROUTE_OPT_UCAST(dest->server);
151 return ROUTE_LOCALONLY;
157 class CommandFpart : public RemoveBase
160 CommandFpart(Module* Creator, bool& snk)
161 : RemoveBase(Creator, snk, "FPART")
163 syntax = "<channel> <nick> [<reason>]";
164 TRANSLATE4(TR_TEXT, TR_NICK, TR_TEXT, TR_END);
167 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
169 return HandleRMB(parameters, user, true);
172 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
174 User* dest = ServerInstance->FindNick(parameters[1]);
176 return ROUTE_OPT_UCAST(dest->server);
177 return ROUTE_LOCALONLY;
181 class ModuleRemove : public Module
189 ModuleRemove() : cmd1(this, supportnokicks), cmd2(this, supportnokicks)
191 ServerInstance->AddCommand(&cmd1);
192 ServerInstance->AddCommand(&cmd2);
194 Implementation eventlist[] = { I_On005Numeric, I_OnRehash };
195 ServerInstance->Modules->Attach(eventlist, this, 2);
199 virtual void On005Numeric(std::string &output)
201 output.append(" REMOVE");
204 virtual void OnRehash(User* user)
207 supportnokicks = conf.ReadFlag("remove", "supportnokicks", 0);
210 virtual ~ModuleRemove()
214 virtual Version GetVersion()
216 return Version("Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel", VF_OPTCOMMON | VF_VENDOR);
221 MODULE_INIT(ModuleRemove)