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 */
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.
22 /* This little function just converts a chanmode character (~ & @ & +) into an integer (5 4 3 2 1) */
23 /* XXX - this could be handy in the core, so it can be used elsewhere */
24 int chartolevel(std::string privs)
26 /* XXX - if we just passed this a char, we could do a switch. Look nicer, really. */
30 else if (privs == "&")
32 else if (privs == "@")
34 else if (privs == "%")
40 void handle_remove(char **parameters, int pcnt, userrec *user)
42 /* Look up the user we're meant to be removing from the channel */
43 userrec* target = Srv->FindNick(std::string(parameters[0]));
44 /* And the channel we're meant to be removing them from */
45 chanrec* channel = Srv->FindChannel(std::string(parameters[1]));
46 /* And see if the person calling the command has access to use it on the channel */
47 std::string privs = Srv->ChanMode(user, channel);
48 /* Check what privs the person being removed has */
49 std::string targetprivs = Srv->ChanMode(target, channel);
55 /* This turns all the parameters after the first two into a single string, so the part reason can be multi-word */
58 result=result + std::string(" ") + std::string(parameters[n]);
62 /* If the target nick exists... */
63 if (target && channel)
65 for (unsigned int x = 0; x < strlen(parameters[1]); x++)
67 if ((parameters[1][0] != '#') || (parameters[1][x] == ' ') || (parameters[1][x] == ','))
69 Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name");
74 /* This is adding support for the +q and +a channel modes, basically if they are enabled, and the remover has them set. */
75 /* Then we change the @|%|+ to & if they are +a, or ~ if they are +q */
76 if (user->GetExt("cm_protect_"+std::string(channel->name)))
77 privs = std::string("&");
78 if (user->GetExt("cm_founder_"+std::string(channel->name)))
79 privs = std::string("~");
81 /* Now it's the same idea, except for the target */
82 if (target->GetExt("cm_protect_"+std::string(channel->name)))
83 targetprivs = std::string("&");
84 if (target->GetExt("cm_founder_"+std::string(channel->name)))
85 targetprivs = std::string("~");
87 tlevel = chartolevel(targetprivs);
88 ulevel = chartolevel(privs);
90 /* If the user calling the command is either an admin, owner, operator or a half-operator on the channel */
93 /* 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) */
96 Srv->PartUserFromChannel(target,std::string(parameters[1]), "Remove by "+std::string(user->nick)+":"+result);
97 Srv->SendTo(NULL,user,"NOTICE "+std::string(channel->name)+" : "+std::string(user->nick)+" removed "+std::string(target->nick)+ " from the channel");
98 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));
102 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));
107 Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** You do not have access to use /remove on "+std::string(channel->name));
113 class ModuleRemove : public Module
116 ModuleRemove(Server* Me)
120 Srv->AddCommand("REMOVE", handle_remove, 0, 3, "m_remove.so");
123 virtual void On005Numeric(std::string &output)
125 output = output + std::string(" REMOVE");
128 virtual ~ModuleRemove()
132 virtual Version GetVersion()
134 return Version(1,0,0,1,VF_VENDOR);
139 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
141 class ModuleRemoveFactory : public ModuleFactory
144 ModuleRemoveFactory()
148 ~ModuleRemoveFactory()
152 virtual Module * CreateModule(Server* Me)
154 return new ModuleRemove(Me);
160 extern "C" void * init_module( void )
162 return new ModuleRemoveFactory;