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"
12 /* $ModDesc: Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel */
15 * This module supports the use of the +q and +a usermodes, but should work without them too.
16 * Usage of the command is restricted to +hoaq, and you cannot remove a user with a "higher" level than yourself.
17 * eg: +h can remove +hv and users with no modes. +a can remove +aohv and users with no modes.
20 extern InspIRCd* ServerInstance;
29 RemoveBase(Server* Me, bool& snk)
30 : Srv(Me), supportnokicks(snk)
34 enum ModeLevel { PEON = 0, HALFOP = 1, OP = 2, ADMIN = 3, OWNER = 4, ULINE = 5 };
36 /* This little function just converts a chanmode character (U ~ & @ & +) into an integer (5 4 3 2 1 0) */
37 /* XXX - this could be handy in the core, so it can be used elsewhere */
38 ModeLevel chartolevel(const std::string &privs)
68 void Handle (const char** parameters, int pcnt, userrec *user, bool neworder)
76 std::ostringstream reason;
77 std::string protectkey;
78 std::string founderkey;
81 /* Set these to the parameters needed, the new version of this module switches it's parameters around
82 * supplying a new command with the new order while keeping the old /remove with the older order.
83 * /remove <nick> <channel> [reason ...]
84 * /fpart <channel> <nick> [reason ...]
86 channame = parameters[ neworder ? 0 : 1];
87 username = parameters[ neworder ? 1 : 0];
89 /* Look up the user we're meant to be removing from the channel */
90 target = ServerInstance->FindNick(username);
92 /* And the channel we're meant to be removing them from */
93 channel = ServerInstance->FindChan(channame);
95 /* Fix by brain - someone needs to learn to validate their input! */
96 if (!target || !channel)
98 user->WriteServ("401 %s %s :No such nick/channel", user->nick, !target ? username : channame);
102 if (!channel->HasUser(target))
104 user->WriteServ( "NOTICE %s :*** The user %s is not on channel %s", user->nick, target->nick, channel->name);
108 /* This is adding support for the +q and +a channel modes, basically if they are enabled, and the remover has them set.
109 * Then we change the @|%|+ to & if they are +a, or ~ if they are +q */
110 protectkey = "cm_protect_" + std::string(channel->name);
111 founderkey = "cm_founder_" + std::string(channel->name);
113 if (Srv->IsUlined(user->server) || Srv->IsUlined(user->nick))
115 log(DEBUG, "Setting ulevel to U");
116 ulevel = chartolevel("U");
118 if (user->GetExt(founderkey))
120 log(DEBUG, "Setting ulevel to ~");
121 ulevel = chartolevel("~");
123 else if (user->GetExt(protectkey))
125 log(DEBUG, "Setting ulevel to &");
126 ulevel = chartolevel("&");
130 log(DEBUG, "Setting ulevel to %s", channel->GetStatusChar(user));
131 ulevel = chartolevel(channel->GetStatusChar(user));
134 /* 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 */
135 if (Srv->IsUlined(target->server) || Srv->IsUlined(target->nick))
137 log(DEBUG, "Setting tlevel to U");
138 tlevel = chartolevel("U");
140 else if (target->GetExt(founderkey))
142 log(DEBUG, "Setting tlevel to ~");
143 tlevel = chartolevel("~");
145 else if (target->GetExt(protectkey))
147 log(DEBUG, "Setting tlevel to &");
148 tlevel = chartolevel("&");
152 log(DEBUG, "Setting tlevel to %s", channel->GetStatusChar(target));
153 tlevel = chartolevel(channel->GetStatusChar(target));
156 hasnokicks = (Srv->FindModule("m_nokicks.so") && channel->IsModeSet('Q'));
158 /* 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 */
159 if(!supportnokicks || !hasnokicks || (ulevel == ULINE))
161 /* We'll let everyone remove their level and below, eg:
162 * ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1)
163 * a ulined target will get a higher level than it's possible for a /remover to get..so they're safe.
164 * Nobody may remove a founder.
166 if ((ulevel > PEON) && (ulevel >= tlevel) && (tlevel != OWNER))
168 std::string reasonparam;
170 /* If a reason is given, use it */
175 /* Use all the remaining parameters as the reason */
176 for(int i = 2; i < pcnt; i++)
178 reason << " " << parameters[i];
181 reasonparam = reason.str();
185 /* Build up the part reason string. */
186 reason << "Removed by " << user->nick << reasonparam;
188 channel->WriteChannelWithServ(Srv->GetServerName().c_str(), "NOTICE %s :%s removed %s from the channel", channel->name, user->nick, target->nick);
189 target->WriteServ("NOTICE %s :*** %s removed you from %s with the message: %s", target->nick, user->nick, channel->name, reasonparam.c_str());
191 if (!channel->PartUser(target, reason.str().c_str()))
196 user->WriteServ( "NOTICE %s :*** You do not have access to /remove %s from %s", user->nick, target->nick, channel->name);
201 /* m_nokicks.so was loaded and +Q was set, block! */
202 user->WriteServ( "484 %s %s :Can't remove user %s from channel (+Q set)", user->nick, channel->name, target->nick);
207 class cmd_remove : public command_t, public RemoveBase
210 cmd_remove(Server* Srv, bool& snk) : command_t("REMOVE", 0, 2), RemoveBase(Srv, snk)
212 this->source = "m_remove.so";
213 syntax = "<nick> <channel> [<reason>]";
216 void Handle (const char** parameters, int pcnt, userrec *user)
218 RemoveBase::Handle(parameters, pcnt, user, false);
222 class cmd_fpart : public command_t, public RemoveBase
225 cmd_fpart(Server* Srv, bool snk) : command_t("FPART", 0, 2), RemoveBase(Srv, snk)
227 this->source = "m_remove.so";
228 syntax = "<channel> <nick> [<reason>]";
231 void Handle (const char** parameters, int pcnt, userrec *user)
233 RemoveBase::Handle(parameters, pcnt, user, true);
237 class ModuleRemove : public Module
239 cmd_remove* mycommand;
240 cmd_fpart* mycommand2;
244 ModuleRemove(Server* Me)
247 mycommand = new cmd_remove(Me, supportnokicks);
248 mycommand2 = new cmd_fpart(Me, supportnokicks);
249 Me->AddCommand(mycommand);
250 Me->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&)
268 supportnokicks = conf.ReadFlag("remove", "supportnokicks", 0);
271 virtual ~ModuleRemove()
277 virtual Version GetVersion()
279 return Version(1,0,1,0,VF_VENDOR);
284 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
286 class ModuleRemoveFactory : public ModuleFactory
289 ModuleRemoveFactory()
293 ~ModuleRemoveFactory()
297 virtual Module * CreateModule(Server* Me)
299 return new ModuleRemove(Me);
305 extern "C" void * init_module( void )
307 return new ModuleRemoveFactory;