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.
39 InspIRCd* ServerInstance;
42 RemoveBase(InspIRCd* Instance, bool& snk) : supportnokicks(snk), ServerInstance(Instance)
46 enum ModeLevel { PEON = 0, HALFOP = 1, OP = 2, ADMIN = 3, OWNER = 4, ULINE = 5 };
48 /* This little function just converts a chanmode character (U ~ & @ & +) into an integer (5 4 3 2 1 0) */
49 /* XXX - this could be handy in the core, so it can be used elsewhere */
50 ModeLevel chartolevel(const std::string &privs)
80 void Handle (const char** parameters, int pcnt, userrec *user, bool neworder)
88 std::ostringstream reason;
89 std::string protectkey;
90 std::string founderkey;
93 /* Set these to the parameters needed, the new version of this module switches it's parameters around
94 * supplying a new command with the new order while keeping the old /remove with the older order.
95 * /remove <nick> <channel> [reason ...]
96 * /fpart <channel> <nick> [reason ...]
98 channame = parameters[ neworder ? 0 : 1];
99 username = parameters[ neworder ? 1 : 0];
101 /* Look up the user we're meant to be removing from the channel */
102 target = ServerInstance->FindNick(username);
104 /* And the channel we're meant to be removing them from */
105 channel = ServerInstance->FindChan(channame);
107 /* Fix by brain - someone needs to learn to validate their input! */
108 if (!target || !channel)
110 user->WriteServ("401 %s %s :No such nick/channel", user->nick, !target ? username : channame);
114 if (!channel->HasUser(target))
116 user->WriteServ( "NOTICE %s :*** The user %s is not on channel %s", user->nick, target->nick, channel->name);
120 /* This is adding support for the +q and +a channel modes, basically if they are enabled, and the remover has them set.
121 * Then we change the @|%|+ to & if they are +a, or ~ if they are +q */
122 protectkey = "cm_protect_" + std::string(channel->name);
123 founderkey = "cm_founder_" + std::string(channel->name);
125 if (ServerInstance->ULine(user->server) || ServerInstance->ULine(user->nick))
127 ServerInstance->Log(DEBUG, "Setting ulevel to U");
128 ulevel = chartolevel("U");
130 if (user->GetExt(founderkey))
132 ServerInstance->Log(DEBUG, "Setting ulevel to ~");
133 ulevel = chartolevel("~");
135 else if (user->GetExt(protectkey))
137 ServerInstance->Log(DEBUG, "Setting ulevel to &");
138 ulevel = chartolevel("&");
142 ServerInstance->Log(DEBUG, "Setting ulevel to %s", channel->GetPrefixChar(user));
143 ulevel = chartolevel(channel->GetPrefixChar(user));
146 /* 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 */
147 if (ServerInstance->ULine(target->server) || ServerInstance->ULine(target->nick))
149 ServerInstance->Log(DEBUG, "Setting tlevel to U");
150 tlevel = chartolevel("U");
152 else if (target->GetExt(founderkey))
154 ServerInstance->Log(DEBUG, "Setting tlevel to ~");
155 tlevel = chartolevel("~");
157 else if (target->GetExt(protectkey))
159 ServerInstance->Log(DEBUG, "Setting tlevel to &");
160 tlevel = chartolevel("&");
164 ServerInstance->Log(DEBUG, "Setting tlevel to %s", channel->GetPrefixChar(target));
165 tlevel = chartolevel(channel->GetPrefixChar(target));
168 hasnokicks = (ServerInstance->FindModule("m_nokicks.so") && channel->IsModeSet('Q'));
170 /* 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 */
171 if(!supportnokicks || !hasnokicks || (ulevel == ULINE))
173 /* We'll let everyone remove their level and below, eg:
174 * ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1)
175 * a ulined target will get a higher level than it's possible for a /remover to get..so they're safe.
176 * Nobody may remove a founder.
178 if ((ulevel > PEON) && (ulevel >= tlevel) && (tlevel != OWNER))
180 std::string reasonparam;
182 /* If a reason is given, use it */
187 /* Use all the remaining parameters as the reason */
188 for(int i = 2; i < pcnt; i++)
190 reason << " " << parameters[i];
193 reasonparam = reason.str();
197 /* Build up the part reason string. */
198 reason << "Removed by " << user->nick << reasonparam;
200 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s removed %s from the channel", channel->name, user->nick, target->nick);
201 target->WriteServ("NOTICE %s :*** %s removed you from %s with the message: %s", target->nick, user->nick, channel->name, reasonparam.c_str());
203 if (!channel->PartUser(target, reason.str().c_str()))
208 user->WriteServ( "NOTICE %s :*** You do not have access to /remove %s from %s", user->nick, target->nick, channel->name);
213 /* m_nokicks.so was loaded and +Q was set, block! */
214 user->WriteServ( "484 %s %s :Can't remove user %s from channel (+Q set)", user->nick, channel->name, target->nick);
219 class cmd_remove : public command_t, public RemoveBase
222 cmd_remove(InspIRCd* Instance, bool& snk) : command_t(Instance, "REMOVE", 0, 2), RemoveBase(Instance, snk)
224 this->source = "m_remove.so";
225 syntax = "<nick> <channel> [<reason>]";
228 void Handle (const char** parameters, int pcnt, userrec *user)
230 RemoveBase::Handle(parameters, pcnt, user, false);
234 class cmd_fpart : public command_t, public RemoveBase
237 cmd_fpart(InspIRCd* Instance, bool& snk) : command_t(Instance, "FPART", 0, 2), RemoveBase(Instance, snk)
239 this->source = "m_remove.so";
240 syntax = "<channel> <nick> [<reason>]";
243 void Handle (const char** parameters, int pcnt, userrec *user)
245 RemoveBase::Handle(parameters, pcnt, user, true);
249 class ModuleRemove : public Module
251 cmd_remove* mycommand;
252 cmd_fpart* mycommand2;
257 ModuleRemove(InspIRCd* Me)
260 mycommand = new cmd_remove(ServerInstance, supportnokicks);
261 mycommand2 = new cmd_fpart(ServerInstance, supportnokicks);
262 ServerInstance->AddCommand(mycommand);
263 ServerInstance->AddCommand(mycommand2);
267 void Implements(char* List)
269 List[I_On005Numeric] = List[I_OnRehash] = 1;
272 virtual void On005Numeric(std::string &output)
274 output.append(" REMOVE");
277 virtual void OnRehash(const std::string&)
279 ConfigReader conf(ServerInstance);
280 supportnokicks = conf.ReadFlag("remove", "supportnokicks", 0);
283 virtual ~ModuleRemove()
289 virtual Version GetVersion()
291 return Version(1,0,1,0,VF_VENDOR);
296 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
298 class ModuleRemoveFactory : public ModuleFactory
301 ModuleRemoveFactory()
305 ~ModuleRemoveFactory()
309 virtual Module * CreateModule(InspIRCd* Me)
311 return new ModuleRemove(Me);
317 extern "C" void * init_module( void )
319 return new ModuleRemoveFactory;