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 * ---------------------------------------------------
18 #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 ServerInstance->Log(DEBUG, "Setting ulevel to U");
125 ulevel = chartolevel("U");
127 if (user->GetExt(founderkey))
129 ServerInstance->Log(DEBUG, "Setting ulevel to ~");
130 ulevel = chartolevel("~");
132 else if (user->GetExt(protectkey))
134 ServerInstance->Log(DEBUG, "Setting ulevel to &");
135 ulevel = chartolevel("&");
139 ServerInstance->Log(DEBUG, "Setting ulevel to %s", channel->GetPrefixChar(user));
140 ulevel = chartolevel(channel->GetPrefixChar(user));
143 /* 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 */
144 if (ServerInstance->ULine(target->server) || ServerInstance->ULine(target->nick))
146 ServerInstance->Log(DEBUG, "Setting tlevel to U");
147 tlevel = chartolevel("U");
149 else if (target->GetExt(founderkey))
151 ServerInstance->Log(DEBUG, "Setting tlevel to ~");
152 tlevel = chartolevel("~");
154 else if (target->GetExt(protectkey))
156 ServerInstance->Log(DEBUG, "Setting tlevel to &");
157 tlevel = chartolevel("&");
161 ServerInstance->Log(DEBUG, "Setting tlevel to %s", channel->GetPrefixChar(target));
162 tlevel = chartolevel(channel->GetPrefixChar(target));
165 hasnokicks = (ServerInstance->FindModule("m_nokicks.so") && channel->IsModeSet('Q'));
167 /* 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 */
168 if ((!IS_LOCAL(user)) || (!supportnokicks || !hasnokicks || (ulevel == ULINE)))
170 /* We'll let everyone remove their level and below, eg:
171 * ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1)
172 * a ulined target will get a higher level than it's possible for a /remover to get..so they're safe.
173 * Nobody may remove a founder.
175 if ((!IS_LOCAL(user)) || ((ulevel > PEON) && (ulevel >= tlevel) && (tlevel != OWNER)))
177 // no you can't just go from a std::ostringstream to a std::string, Om. -nenolod
178 // but you can do this, nenolod -brain
180 std::string reasonparam("No reason given");
182 /* If a reason is given, use it */
185 /* Join params 2 ... pcnt - 1 (inclusive) into one */
186 irc::stringjoiner reason_join(" ", parameters, 2, pcnt - 1);
187 reasonparam = reason_join.GetJoined();
190 /* Build up the part reason string. */
191 reason = std::string("Removed by ") + user->nick + ": " + reasonparam;
193 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s removed %s from the channel", channel->name, user->nick, target->nick);
194 target->WriteServ("NOTICE %s :*** %s removed you from %s with the message: %s", target->nick, user->nick, channel->name, reasonparam.c_str());
196 if (!channel->PartUser(target, reason.c_str()))
201 user->WriteServ( "NOTICE %s :*** You do not have access to /remove %s from %s", user->nick, target->nick, channel->name);
207 /* m_nokicks.so was loaded and +Q was set, block! */
208 user->WriteServ( "484 %s %s :Can't remove user %s from channel (+Q set)", user->nick, channel->name, target->nick);
218 class cmd_remove : public command_t, public RemoveBase
221 cmd_remove(InspIRCd* Instance, bool& snk) : command_t(Instance, "REMOVE", 0, 2), RemoveBase(Instance, snk)
223 this->source = "m_remove.so";
224 syntax = "<nick> <channel> [<reason>]";
227 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
229 return RemoveBase::Handle(parameters, pcnt, user, false);
235 class cmd_fpart : public command_t, public RemoveBase
238 cmd_fpart(InspIRCd* Instance, bool& snk) : command_t(Instance, "FPART", 0, 2), RemoveBase(Instance, snk)
240 this->source = "m_remove.so";
241 syntax = "<channel> <nick> [<reason>]";
244 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
246 return RemoveBase::Handle(parameters, pcnt, user, true);
250 class ModuleRemove : public Module
252 cmd_remove* mycommand;
253 cmd_fpart* mycommand2;
258 ModuleRemove(InspIRCd* Me)
261 mycommand = new cmd_remove(ServerInstance, supportnokicks);
262 mycommand2 = new cmd_fpart(ServerInstance, supportnokicks);
263 ServerInstance->AddCommand(mycommand);
264 ServerInstance->AddCommand(mycommand2);
268 void Implements(char* List)
270 List[I_On005Numeric] = List[I_OnRehash] = 1;
273 virtual void On005Numeric(std::string &output)
275 output.append(" REMOVE");
278 virtual void OnRehash(const std::string&)
280 ConfigReader conf(ServerInstance);
281 supportnokicks = conf.ReadFlag("remove", "supportnokicks", 0);
284 virtual ~ModuleRemove()
290 virtual Version GetVersion()
292 return Version(1,1,1,0,VF_VENDOR,API_VERSION);
297 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
299 class ModuleRemoveFactory : public ModuleFactory
302 ModuleRemoveFactory()
306 ~ModuleRemoveFactory()
310 virtual Module * CreateModule(InspIRCd* Me)
312 return new ModuleRemove(Me);
318 extern "C" void * init_module( void )
320 return new ModuleRemoveFactory;