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 */
11 #include "helperfuncs.h"
13 /* $ModDesc: Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel */
16 * This module supports the use of the +q and +a usermodes, but should work without them too.
17 * Usage of the command is restricted to +hoaq, and you cannot remove a user with a "higher" level than yourself.
18 * eg: +h can remove +hv and users with no modes. +a can remove +aohv and users with no modes.
23 /* This little function just converts a chanmode character (~ & @ & +) into an integer (5 4 3 2 1) */
24 /* XXX - this could be handy in the core, so it can be used elsewhere */
25 int chartolevel(std::string &privs)
27 const char* n = privs.c_str();
50 class cmd_remove : public command_t
53 cmd_remove () : command_t("REMOVE", 0, 2)
55 this->source = "m_remove.so";
58 void Handle (const char** parameters, int pcnt, userrec *user)
64 std::string tprivs, uprivs, reason;
67 /* Look up the user we're meant to be removing from the channel */
68 target = Srv->FindNick(parameters[0]);
70 /* And the channel we're meant to be removing them from */
71 channel = Srv->FindChannel(parameters[1]);
73 /* Fix by brain - someone needs to learn to validate their input! */
74 if (!target || !channel)
76 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, !target ? parameters[0] : parameters[1]);
80 if (!channel->HasUser(target))
82 Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** The user "+target->nick+" is not on channel "+channel->name);
86 /* And see if the person calling the command has access to use it on the channel */
87 uprivs = Srv->ChanMode(user, channel);
89 /* Check what privs the person being removed has */
90 tprivs = Srv->ChanMode(target, channel);
93 reason = "Removed by " + std::string(user->nick) + ":";
95 reason = "Removed by " + std::string(user->nick);
97 /* This turns all the parameters after the first two into a single string, so the part reason can be multi-word */
98 for (int n = 2; n < pcnt; n++)
101 reason += parameters[n];
104 /* This is adding support for the +q and +a channel modes, basically if they are enabled, and the remover has them set. */
105 /* Then we change the @|%|+ to & if they are +a, or ~ if they are +q */
107 std::string protect = "cm_protect_" + std::string(channel->name);
108 std::string founder = "cm_founder_"+std::string(channel->name);
110 if (user->GetExt(protect, dummy))
112 if (user->GetExt(founder, dummy))
115 /* Now it's the same idea, except for the target */
116 if (target->GetExt(protect, dummy))
118 if (target->GetExt(founder, dummy))
121 tlevel = chartolevel(tprivs);
122 ulevel = chartolevel(uprivs);
124 /* If the user calling the command is either an admin, owner, operator or a half-operator on the channel */
127 /* For now, we'll let everyone remove their level and below, eg ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1) */
128 if ((ulevel >= tlevel && tlevel != 5) && (!Srv->IsUlined(target->server)))
130 Srv->PartUserFromChannel(target, channel->name, reason);
131 WriteServ(user->fd, "NOTICE %s :%s removed %s from the channel", channel->name, user->nick, target->nick);
132 WriteServ(target->fd, "NOTICE %s :*** %s removed you from %s with the message:%s", target->nick, user->nick, channel->name, reason.c_str());
136 WriteServ(user->fd, "NOTICE %s :*** You do not have access to /remove %s from %s", user->nick, target->nick, channel->name);
141 WriteServ(user->fd, "NOTICE %s :*** You do not have access to use /remove on %s", user->nick, channel->name);
146 class ModuleRemove : public Module
148 cmd_remove* mycommand;
150 ModuleRemove(Server* Me)
154 mycommand = new cmd_remove();
155 Srv->AddCommand(mycommand);
158 void Implements(char* List)
160 List[I_On005Numeric] = 1;
163 virtual void On005Numeric(std::string &output)
165 output = output + std::string(" REMOVE");
168 virtual ~ModuleRemove()
172 virtual Version GetVersion()
174 return Version(1,0,0,1,VF_VENDOR);
179 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
181 class ModuleRemoveFactory : public ModuleFactory
184 ModuleRemoveFactory()
188 ~ModuleRemoveFactory()
192 virtual Module * CreateModule(Server* Me)
194 return new ModuleRemove(Me);
200 extern "C" void * init_module( void )
202 return new ModuleRemoveFactory;