1 /* Support for a dancer-style /remove command, an alternative to /kick to try and avoid auto-rejoin-on-kick scripts */
2 /* Written by Om, 25-03-05 */
9 #include "helperfuncs.h"
10 #include "configreader.h"
14 /* $ModDesc: Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel */
17 * This module supports the use of the +q and +a usermodes, but should work without them too.
18 * Usage of the command is restricted to +hoaq, and you cannot remove a user with a "higher" level than yourself.
19 * eg: +h can remove +hv and users with no modes. +a can remove +aohv and users with no modes.
26 InspIRCd* ServerInstance;
29 RemoveBase(InspIRCd* Instance, bool& snk) : supportnokicks(snk), ServerInstance(Instance)
33 enum ModeLevel { PEON = 0, HALFOP = 1, OP = 2, ADMIN = 3, OWNER = 4, ULINE = 5 };
35 /* This little function just converts a chanmode character (U ~ & @ & +) into an integer (5 4 3 2 1 0) */
36 /* XXX - this could be handy in the core, so it can be used elsewhere */
37 ModeLevel chartolevel(const std::string &privs)
67 void Handle (const char** parameters, int pcnt, userrec *user, bool neworder)
75 std::ostringstream reason;
76 std::string protectkey;
77 std::string founderkey;
80 /* Set these to the parameters needed, the new version of this module switches it's parameters around
81 * supplying a new command with the new order while keeping the old /remove with the older order.
82 * /remove <nick> <channel> [reason ...]
83 * /fpart <channel> <nick> [reason ...]
85 channame = parameters[ neworder ? 0 : 1];
86 username = parameters[ neworder ? 1 : 0];
88 /* Look up the user we're meant to be removing from the channel */
89 target = ServerInstance->FindNick(username);
91 /* And the channel we're meant to be removing them from */
92 channel = ServerInstance->FindChan(channame);
94 /* Fix by brain - someone needs to learn to validate their input! */
95 if (!target || !channel)
97 user->WriteServ("401 %s %s :No such nick/channel", user->nick, !target ? username : channame);
101 if (!channel->HasUser(target))
103 user->WriteServ( "NOTICE %s :*** The user %s is not on channel %s", user->nick, target->nick, channel->name);
107 /* This is adding support for the +q and +a channel modes, basically if they are enabled, and the remover has them set.
108 * Then we change the @|%|+ to & if they are +a, or ~ if they are +q */
109 protectkey = "cm_protect_" + std::string(channel->name);
110 founderkey = "cm_founder_" + std::string(channel->name);
112 if (ServerInstance->ULine(user->server) || ServerInstance->ULine(user->nick))
114 ServerInstance->Log(DEBUG, "Setting ulevel to U");
115 ulevel = chartolevel("U");
117 if (user->GetExt(founderkey))
119 ServerInstance->Log(DEBUG, "Setting ulevel to ~");
120 ulevel = chartolevel("~");
122 else if (user->GetExt(protectkey))
124 ServerInstance->Log(DEBUG, "Setting ulevel to &");
125 ulevel = chartolevel("&");
129 ServerInstance->Log(DEBUG, "Setting ulevel to %s", channel->GetStatusChar(user));
130 ulevel = chartolevel(channel->GetStatusChar(user));
133 /* 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 */
134 if (ServerInstance->ULine(target->server) || ServerInstance->ULine(target->nick))
136 ServerInstance->Log(DEBUG, "Setting tlevel to U");
137 tlevel = chartolevel("U");
139 else if (target->GetExt(founderkey))
141 ServerInstance->Log(DEBUG, "Setting tlevel to ~");
142 tlevel = chartolevel("~");
144 else if (target->GetExt(protectkey))
146 ServerInstance->Log(DEBUG, "Setting tlevel to &");
147 tlevel = chartolevel("&");
151 ServerInstance->Log(DEBUG, "Setting tlevel to %s", channel->GetStatusChar(target));
152 tlevel = chartolevel(channel->GetStatusChar(target));
155 hasnokicks = (ServerInstance->FindModule("m_nokicks.so") && channel->IsModeSet('Q'));
157 /* 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 */
158 if(!supportnokicks || !hasnokicks || (ulevel == ULINE))
160 /* We'll let everyone remove their level and below, eg:
161 * ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1)
162 * a ulined target will get a higher level than it's possible for a /remover to get..so they're safe.
163 * Nobody may remove a founder.
165 if ((ulevel > PEON) && (ulevel >= tlevel) && (tlevel != OWNER))
167 std::string reasonparam;
169 /* If a reason is given, use it */
174 /* Use all the remaining parameters as the reason */
175 for(int i = 2; i < pcnt; i++)
177 reason << " " << parameters[i];
180 reasonparam = reason.str();
184 /* Build up the part reason string. */
185 reason << "Removed by " << user->nick << reasonparam;
187 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s removed %s from the channel", channel->name, user->nick, target->nick);
188 target->WriteServ("NOTICE %s :*** %s removed you from %s with the message: %s", target->nick, user->nick, channel->name, reasonparam.c_str());
190 if (!channel->PartUser(target, reason.str().c_str()))
195 user->WriteServ( "NOTICE %s :*** You do not have access to /remove %s from %s", user->nick, target->nick, channel->name);
200 /* m_nokicks.so was loaded and +Q was set, block! */
201 user->WriteServ( "484 %s %s :Can't remove user %s from channel (+Q set)", user->nick, channel->name, target->nick);
206 class cmd_remove : public command_t, public RemoveBase
209 cmd_remove(InspIRCd* Instance, bool& snk) : command_t(Instance, "REMOVE", 0, 2), RemoveBase(Instance, snk)
211 this->source = "m_remove.so";
212 syntax = "<nick> <channel> [<reason>]";
215 void Handle (const char** parameters, int pcnt, userrec *user)
217 RemoveBase::Handle(parameters, pcnt, user, false);
221 class cmd_fpart : public command_t, public RemoveBase
224 cmd_fpart(InspIRCd* Instance, bool& snk) : command_t(Instance, "FPART", 0, 2), RemoveBase(Instance, snk)
226 this->source = "m_remove.so";
227 syntax = "<channel> <nick> [<reason>]";
230 void Handle (const char** parameters, int pcnt, userrec *user)
232 RemoveBase::Handle(parameters, pcnt, user, true);
236 class ModuleRemove : public Module
238 cmd_remove* mycommand;
239 cmd_fpart* mycommand2;
244 ModuleRemove(InspIRCd* Me)
247 mycommand = new cmd_remove(ServerInstance, supportnokicks);
248 mycommand2 = new cmd_fpart(ServerInstance, supportnokicks);
249 ServerInstance->AddCommand(mycommand);
250 ServerInstance->AddCommand(mycommand2);
254 void Implements(char* List)
256 List[I_On005Numeric] = List[I_OnRehash] = 1;
259 virtual void On005Numeric(std::string &output)
261 output.append(" REMOVE");
264 virtual void OnRehash(const std::string&)
266 ConfigReader conf(ServerInstance);
267 supportnokicks = conf.ReadFlag("remove", "supportnokicks", 0);
270 virtual ~ModuleRemove()
276 virtual Version GetVersion()
278 return Version(1,0,1,0,VF_VENDOR);
283 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
285 class ModuleRemoveFactory : public ModuleFactory
288 ModuleRemoveFactory()
292 ~ModuleRemoveFactory()
296 virtual Module * CreateModule(InspIRCd* Me)
298 return new ModuleRemove(Me);
304 extern "C" void * init_module( void )
306 return new ModuleRemoveFactory;