1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 /* Support for a dancer-style /remove command, an alternative to /kick to try and avoid auto-rejoin-on-kick scripts */
18 /* Written by Om, 25-03-05 */
24 #include "configreader.h"
27 /* $ModDesc: Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel */
30 * This module supports the use of the +q and +a usermodes, but should work without them too.
31 * Usage of the command is restricted to +hoaq, and you cannot remove a user with a "higher" level than yourself.
32 * eg: +h can remove +hv and users with no modes. +a can remove +aohv and users with no modes.
35 /** Base class for /FPART and /REMOVE
41 InspIRCd* ServerInstance;
44 RemoveBase(InspIRCd* Instance, bool& snk) : supportnokicks(snk), ServerInstance(Instance)
48 enum ModeLevel { PEON = 0, HALFOP = 1, OP = 2, ADMIN = 3, OWNER = 4, ULINE = 5 };
50 /* This little function just converts a chanmode character (U ~ & @ & +) into an integer (5 4 3 2 1 0) */
51 /* XXX - this could be handy in the core, so it can be used elsewhere */
52 ModeLevel chartolevel(const std::string &privs)
82 CmdResult Handle (const char** parameters, int pcnt, userrec *user, bool neworder)
90 std::ostringstream reason;
91 std::string protectkey;
92 std::string founderkey;
95 /* Set these to the parameters needed, the new version of this module switches it's parameters around
96 * supplying a new command with the new order while keeping the old /remove with the older order.
97 * /remove <nick> <channel> [reason ...]
98 * /fpart <channel> <nick> [reason ...]
100 channame = parameters[ neworder ? 0 : 1];
101 username = parameters[ neworder ? 1 : 0];
103 /* Look up the user we're meant to be removing from the channel */
104 target = ServerInstance->FindNick(username);
106 /* And the channel we're meant to be removing them from */
107 channel = ServerInstance->FindChan(channame);
109 /* Fix by brain - someone needs to learn to validate their input! */
110 if (!target || !channel)
112 user->WriteServ("401 %s %s :No such nick/channel", user->nick, !target ? username : channame);
116 if (!channel->HasUser(target))
118 user->WriteServ( "NOTICE %s :*** The user %s is not on channel %s", user->nick, target->nick, channel->name);
122 /* This is adding support for the +q and +a channel modes, basically if they are enabled, and the remover has them set.
123 * Then we change the @|%|+ to & if they are +a, or ~ if they are +q */
124 protectkey = "cm_protect_" + std::string(channel->name);
125 founderkey = "cm_founder_" + std::string(channel->name);
127 if (ServerInstance->ULine(user->server) || ServerInstance->ULine(user->nick))
129 ServerInstance->Log(DEBUG, "Setting ulevel to U");
130 ulevel = chartolevel("U");
132 if (user->GetExt(founderkey))
134 ServerInstance->Log(DEBUG, "Setting ulevel to ~");
135 ulevel = chartolevel("~");
137 else if (user->GetExt(protectkey))
139 ServerInstance->Log(DEBUG, "Setting ulevel to &");
140 ulevel = chartolevel("&");
144 ServerInstance->Log(DEBUG, "Setting ulevel to %s", channel->GetPrefixChar(user));
145 ulevel = chartolevel(channel->GetPrefixChar(user));
148 /* 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 */
149 if (ServerInstance->ULine(target->server) || ServerInstance->ULine(target->nick))
151 ServerInstance->Log(DEBUG, "Setting tlevel to U");
152 tlevel = chartolevel("U");
154 else if (target->GetExt(founderkey))
156 ServerInstance->Log(DEBUG, "Setting tlevel to ~");
157 tlevel = chartolevel("~");
159 else if (target->GetExt(protectkey))
161 ServerInstance->Log(DEBUG, "Setting tlevel to &");
162 tlevel = chartolevel("&");
166 ServerInstance->Log(DEBUG, "Setting tlevel to %s", channel->GetPrefixChar(target));
167 tlevel = chartolevel(channel->GetPrefixChar(target));
170 hasnokicks = (ServerInstance->FindModule("m_nokicks.so") && channel->IsModeSet('Q'));
172 /* 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 */
173 if(!supportnokicks || !hasnokicks || (ulevel == ULINE))
175 /* We'll let everyone remove their level and below, eg:
176 * ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1)
177 * a ulined target will get a higher level than it's possible for a /remover to get..so they're safe.
178 * Nobody may remove a founder.
180 if ((ulevel > PEON) && (ulevel >= tlevel) && (tlevel != OWNER))
182 std::string reasonparam;
184 /* If a reason is given, use it */
189 /* Use all the remaining parameters as the reason */
190 for(int i = 2; i < pcnt; i++)
192 reason << " " << parameters[i];
195 reasonparam = reason.str();
199 /* Build up the part reason string. */
200 reason << "Removed by " << user->nick << reasonparam;
202 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s removed %s from the channel", channel->name, user->nick, target->nick);
203 target->WriteServ("NOTICE %s :*** %s removed you from %s with the message: %s", target->nick, user->nick, channel->name, reasonparam.c_str());
205 if (!channel->PartUser(target, reason.str().c_str()))
210 user->WriteServ( "NOTICE %s :*** You do not have access to /remove %s from %s", user->nick, target->nick, channel->name);
216 /* m_nokicks.so was loaded and +Q was set, block! */
217 user->WriteServ( "484 %s %s :Can't remove user %s from channel (+Q set)", user->nick, channel->name, target->nick);
227 class cmd_remove : public command_t, public RemoveBase
230 cmd_remove(InspIRCd* Instance, bool& snk) : command_t(Instance, "REMOVE", 0, 2), RemoveBase(Instance, snk)
232 this->source = "m_remove.so";
233 syntax = "<nick> <channel> [<reason>]";
236 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
238 return RemoveBase::Handle(parameters, pcnt, user, false);
244 class cmd_fpart : public command_t, public RemoveBase
247 cmd_fpart(InspIRCd* Instance, bool& snk) : command_t(Instance, "FPART", 0, 2), RemoveBase(Instance, snk)
249 this->source = "m_remove.so";
250 syntax = "<channel> <nick> [<reason>]";
253 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
255 return RemoveBase::Handle(parameters, pcnt, user, true);
259 class ModuleRemove : public Module
261 cmd_remove* mycommand;
262 cmd_fpart* mycommand2;
267 ModuleRemove(InspIRCd* Me)
270 mycommand = new cmd_remove(ServerInstance, supportnokicks);
271 mycommand2 = new cmd_fpart(ServerInstance, supportnokicks);
272 ServerInstance->AddCommand(mycommand);
273 ServerInstance->AddCommand(mycommand2);
277 void Implements(char* List)
279 List[I_On005Numeric] = List[I_OnRehash] = 1;
282 virtual void On005Numeric(std::string &output)
284 output.append(" REMOVE");
287 virtual void OnRehash(const std::string&)
289 ConfigReader conf(ServerInstance);
290 supportnokicks = conf.ReadFlag("remove", "supportnokicks", 0);
293 virtual ~ModuleRemove()
299 virtual Version GetVersion()
301 return Version(1,0,1,0,VF_VENDOR);
306 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
308 class ModuleRemoveFactory : public ModuleFactory
311 ModuleRemoveFactory()
315 ~ModuleRemoveFactory()
319 virtual Module * CreateModule(InspIRCd* Me)
321 return new ModuleRemove(Me);
327 extern "C" void * init_module( void )
329 return new ModuleRemoveFactory;