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 (char **parameters, int pcnt, userrec *user)
60 /* Look up the user we're meant to be removing from the channel */
61 userrec* target = Srv->FindNick(std::string(parameters[0]));
62 /* And the channel we're meant to be removing them from */
63 chanrec* channel = Srv->FindChannel(std::string(parameters[1]));
65 /* Fix by brain - someone needs to learn to validate their input! */
66 if (!target || !channel)
68 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, !target ? parameters[0] : parameters[1]);
72 /* And see if the person calling the command has access to use it on the channel */
73 std::string privs = Srv->ChanMode(user, channel);
74 /* Check what privs the person being removed has */
75 std::string targetprivs = Srv->ChanMode(target, channel);
82 /* This turns all the parameters after the first two into a single string, so the part reason can be multi-word */
85 result=result + std::string(" ") + std::string(parameters[n]);
89 /* If the target nick exists... */
90 if (target && channel)
92 /* This is adding support for the +q and +a channel modes, basically if they are enabled, and the remover has them set. */
93 /* Then we change the @|%|+ to & if they are +a, or ~ if they are +q */
94 if (user->GetExt("cm_protect_"+std::string(channel->name)))
95 privs = std::string("&");
96 if (user->GetExt("cm_founder_"+std::string(channel->name)))
97 privs = std::string("~");
99 /* Now it's the same idea, except for the target */
100 if (target->GetExt("cm_protect_"+std::string(channel->name)))
101 targetprivs = std::string("&");
102 if (target->GetExt("cm_founder_"+std::string(channel->name)))
103 targetprivs = std::string("~");
105 tlevel = chartolevel(targetprivs);
106 ulevel = chartolevel(privs);
108 /* If the user calling the command is either an admin, owner, operator or a half-operator on the channel */
111 /* 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) */
112 if(ulevel >= tlevel && tlevel != 5)
114 Srv->PartUserFromChannel(target,std::string(parameters[1]), "Removed by "+std::string(user->nick)+":"+result);
115 Srv->SendTo(NULL,user,"NOTICE "+std::string(channel->name)+" : "+std::string(user->nick)+" removed "+std::string(target->nick)+ " from the channel");
116 Srv->SendTo(NULL,target,"NOTICE "+std::string(target->nick)+" :*** "+std::string(user->nick)+" removed you from "+std::string(channel->name)+" with the message:"+std::string(result));
120 Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** You do not have access to remove "+std::string(target->nick)+" from the "+std::string(channel->name));
125 Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** You do not have access to use /remove on "+std::string(channel->name));
131 class ModuleRemove : public Module
133 cmd_remove* mycommand;
135 ModuleRemove(Server* Me)
139 mycommand = new cmd_remove();
140 Srv->AddCommand(mycommand);
143 void Implements(char* List)
145 List[I_On005Numeric] = 1;
148 virtual void On005Numeric(std::string &output)
150 output = output + std::string(" REMOVE");
153 virtual ~ModuleRemove()
157 virtual Version GetVersion()
159 return Version(1,0,0,1,VF_VENDOR);
164 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
166 class ModuleRemoveFactory : public ModuleFactory
169 ModuleRemoveFactory()
173 ~ModuleRemoveFactory()
177 virtual Module * CreateModule(Server* Me)
179 return new ModuleRemove(Me);
185 extern "C" void * init_module( void )
187 return new ModuleRemoveFactory;