1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
19 #include "configreader.h"
21 /* $ModDesc: Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel */
24 * This module supports the use of the +q and +a usermodes, but should work without them too.
25 * Usage of the command is restricted to +hoaq, and you cannot remove a user with a "higher" level than yourself.
26 * eg: +h can remove +hv and users with no modes. +a can remove +aohv and users with no modes.
29 /** Base class for /FPART and /REMOVE
35 InspIRCd* ServerInstance;
38 RemoveBase(InspIRCd* Instance, bool& snk) : supportnokicks(snk), ServerInstance(Instance)
42 enum ModeLevel { PEON = 0, HALFOP = 1, OP = 2, ADMIN = 3, OWNER = 4, ULINE = 5 };
44 /* This little function just converts a chanmode character (U ~ & @ & +) into an integer (5 4 3 2 1 0) */
45 /* XXX - We should probably use the new mode prefix rank stuff
46 * for this instead now -- Brain */
47 ModeLevel chartolevel(const std::string &privs)
77 CmdResult Handle (const char** parameters, int pcnt, userrec *user, bool neworder)
86 std::string protectkey;
87 std::string founderkey;
90 /* Set these to the parameters needed, the new version of this module switches it's parameters around
91 * supplying a new command with the new order while keeping the old /remove with the older order.
92 * /remove <nick> <channel> [reason ...]
93 * /fpart <channel> <nick> [reason ...]
95 channame = parameters[ neworder ? 0 : 1];
96 username = parameters[ neworder ? 1 : 0];
98 /* Look up the user we're meant to be removing from the channel */
99 target = ServerInstance->FindNick(username);
101 /* And the channel we're meant to be removing them from */
102 channel = ServerInstance->FindChan(channame);
104 /* Fix by brain - someone needs to learn to validate their input! */
105 if (!target || !channel)
107 user->WriteServ("401 %s %s :No such nick/channel", user->nick, !target ? username : channame);
111 if (!channel->HasUser(target))
113 user->WriteServ( "NOTICE %s :*** The user %s is not on channel %s", user->nick, target->nick, channel->name);
117 /* This is adding support for the +q and +a channel modes, basically if they are enabled, and the remover has them set.
118 * Then we change the @|%|+ to & if they are +a, or ~ if they are +q */
119 protectkey = "cm_protect_" + std::string(channel->name);
120 founderkey = "cm_founder_" + std::string(channel->name);
122 if (ServerInstance->ULine(user->server) || ServerInstance->ULine(user->nick))
124 ulevel = chartolevel("U");
126 if (user->GetExt(founderkey))
128 ulevel = chartolevel("~");
130 else if (user->GetExt(protectkey))
132 ulevel = chartolevel("&");
136 ulevel = chartolevel(channel->GetPrefixChar(user));
139 /* Now it's the same idea, except for the target. If they're ulined make sure they get a higher level than the sender can */
140 if (ServerInstance->ULine(target->server) || ServerInstance->ULine(target->nick))
142 tlevel = chartolevel("U");
144 else if (target->GetExt(founderkey))
146 tlevel = chartolevel("~");
148 else if (target->GetExt(protectkey))
150 tlevel = chartolevel("&");
154 tlevel = chartolevel(channel->GetPrefixChar(target));
157 hasnokicks = (ServerInstance->FindModule("m_nokicks.so") && channel->IsModeSet('Q'));
159 /* 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 */
160 if ((!IS_LOCAL(user)) || (!supportnokicks || !hasnokicks || (ulevel == ULINE)))
162 /* We'll let everyone remove their level and below, eg:
163 * ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1)
164 * a ulined target will get a higher level than it's possible for a /remover to get..so they're safe.
165 * Nobody may remove a founder.
167 if ((!IS_LOCAL(user)) || ((ulevel > PEON) && (ulevel >= tlevel) && (tlevel != OWNER)))
169 // no you can't just go from a std::ostringstream to a std::string, Om. -nenolod
170 // but you can do this, nenolod -brain
172 std::string reasonparam("No reason given");
174 /* If a reason is given, use it */
177 /* Join params 2 ... pcnt - 1 (inclusive) into one */
178 irc::stringjoiner reason_join(" ", parameters, 2, pcnt - 1);
179 reasonparam = reason_join.GetJoined();
182 /* Build up the part reason string. */
183 reason = std::string("Removed by ") + user->nick + ": " + reasonparam;
185 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s removed %s from the channel", channel->name, user->nick, target->nick);
186 target->WriteServ("NOTICE %s :*** %s removed you from %s with the message: %s", target->nick, user->nick, channel->name, reasonparam.c_str());
188 if (!channel->PartUser(target, reason.c_str()))
193 user->WriteServ( "NOTICE %s :*** You do not have access to /remove %s from %s", user->nick, target->nick, channel->name);
199 /* m_nokicks.so was loaded and +Q was set, block! */
200 user->WriteServ( "484 %s %s :Can't remove user %s from channel (+Q set)", user->nick, channel->name, target->nick);
211 class cmd_remove : public command_t, public RemoveBase
214 cmd_remove(InspIRCd* Instance, bool& snk) : command_t(Instance, "REMOVE", 0, 2), RemoveBase(Instance, snk)
216 this->source = "m_remove.so";
217 syntax = "<nick> <channel> [<reason>]";
220 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
222 return RemoveBase::Handle(parameters, pcnt, user, false);
228 class cmd_fpart : public command_t, public RemoveBase
231 cmd_fpart(InspIRCd* Instance, bool& snk) : command_t(Instance, "FPART", 0, 2), RemoveBase(Instance, snk)
233 this->source = "m_remove.so";
234 syntax = "<channel> <nick> [<reason>]";
237 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
239 return RemoveBase::Handle(parameters, pcnt, user, true);
243 class ModuleRemove : public Module
245 cmd_remove* mycommand;
246 cmd_fpart* mycommand2;
251 ModuleRemove(InspIRCd* Me)
254 mycommand = new cmd_remove(ServerInstance, supportnokicks);
255 mycommand2 = new cmd_fpart(ServerInstance, supportnokicks);
256 ServerInstance->AddCommand(mycommand);
257 ServerInstance->AddCommand(mycommand2);
261 void Implements(char* List)
263 List[I_On005Numeric] = List[I_OnRehash] = 1;
266 virtual void On005Numeric(std::string &output)
268 output.append(" REMOVE");
271 virtual void OnRehash(userrec* user, const std::string&)
273 ConfigReader conf(ServerInstance);
274 supportnokicks = conf.ReadFlag("remove", "supportnokicks", 0);
277 virtual ~ModuleRemove()
281 virtual Version GetVersion()
283 return Version(1, 1, 1, 0, VF_COMMON | VF_VENDOR, API_VERSION);
288 MODULE_INIT(ModuleRemove)