1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel */
19 * This module supports the use of the +q and +a usermodes, but should work without them too.
20 * Usage of the command is restricted to +hoaq, and you cannot remove a user with a "higher" level than yourself.
21 * eg: +h can remove +hv and users with no modes. +a can remove +aohv and users with no modes.
24 /** Base class for /FPART and /REMOVE
30 InspIRCd* ServerInstance;
33 RemoveBase(InspIRCd* Instance, bool& snk) : supportnokicks(snk), ServerInstance(Instance)
37 enum ModeLevel { PEON = 0, HALFOP = 1, OP = 2, ADMIN = 3, OWNER = 4, ULINE = 5 };
39 /* This little function just converts a chanmode character (U ~ & @ & +) into an integer (5 4 3 2 1 0) */
40 /* XXX - We should probably use the new mode prefix rank stuff
41 * for this instead now -- Brain */
42 ModeLevel chartolevel(const std::string &privs)
72 CmdResult Handle (const std::vector<std::string>& parameters, User *user, bool neworder)
81 std::string protectkey;
82 std::string founderkey;
85 /* Set these to the parameters needed, the new version of this module switches it's parameters around
86 * supplying a new command with the new order while keeping the old /remove with the older order.
87 * /remove <nick> <channel> [reason ...]
88 * /fpart <channel> <nick> [reason ...]
90 channame = parameters[ neworder ? 0 : 1].c_str();
91 username = parameters[ neworder ? 1 : 0].c_str();
93 /* Look up the user we're meant to be removing from the channel */
94 target = ServerInstance->FindNick(username);
96 /* And the channel we're meant to be removing them from */
97 channel = ServerInstance->FindChan(channame);
99 /* Fix by brain - someone needs to learn to validate their input! */
100 if (!target || !channel)
102 user->WriteNumeric(401, "%s %s :No such nick/channel", user->nick.c_str(), !target ? username : channame);
106 if (!channel->HasUser(target))
108 user->WriteServ( "NOTICE %s :*** The user %s is not on channel %s", user->nick.c_str(), target->nick.c_str(), channel->name.c_str());
112 /* This is adding support for the +q and +a channel modes, basically if they are enabled, and the remover has them set.
113 * Then we change the @|%|+ to & if they are +a, or ~ if they are +q */
114 protectkey = "cm_protect_" + std::string(channel->name);
115 founderkey = "cm_founder_" + std::string(channel->name);
117 if (ServerInstance->ULine(user->server) || ServerInstance->ULine(user->nick.c_str()))
119 ulevel = chartolevel("U");
121 if (user->GetExt(founderkey))
123 ulevel = chartolevel("~");
125 else if (user->GetExt(protectkey))
127 ulevel = chartolevel("&");
131 ulevel = chartolevel(channel->GetPrefixChar(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 (ServerInstance->ULine(target->server) || ServerInstance->ULine(target->nick.c_str()))
137 tlevel = chartolevel("U");
139 else if (target->GetExt(founderkey))
141 tlevel = chartolevel("~");
143 else if (target->GetExt(protectkey))
145 tlevel = chartolevel("&");
149 tlevel = chartolevel(channel->GetPrefixChar(target));
152 hasnokicks = (ServerInstance->Modules->Find("m_nokicks.so") && channel->IsModeSet('Q'));
154 /* 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 */
155 if ((!IS_LOCAL(user)) || (!supportnokicks || !hasnokicks || (ulevel == ULINE)))
157 /* We'll let everyone remove their level and below, eg:
158 * ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1)
159 * a ulined target will get a higher level than it's possible for a /remover to get..so they're safe.
160 * Nobody may remove a founder.
162 if ((!IS_LOCAL(user)) || ((ulevel > PEON) && (ulevel >= tlevel) && (tlevel != OWNER)))
164 // no you can't just go from a std::ostringstream to a std::string, Om. -nenolod
165 // but you can do this, nenolod -brain
167 std::string reasonparam("No reason given");
169 /* If a reason is given, use it */
170 if(parameters.size() > 2)
172 /* Join params 2 ... pcnt - 1 (inclusive) into one */
173 irc::stringjoiner reason_join(" ", parameters, 2, parameters.size() - 1);
174 reasonparam = reason_join.GetJoined();
177 /* Build up the part reason string. */
178 reason = std::string("Removed by ") + user->nick + ": " + reasonparam;
180 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s removed %s from the channel", channel->name.c_str(), user->nick.c_str(), target->nick.c_str());
181 target->WriteServ("NOTICE %s :*** %s removed you from %s with the message: %s", target->nick.c_str(), user->nick.c_str(), channel->name.c_str(), reasonparam.c_str());
183 if (!channel->PartUser(target, reason.c_str()))
188 user->WriteServ( "NOTICE %s :*** You do not have access to /remove %s from %s", user->nick.c_str(), target->nick.c_str(), channel->name.c_str());
194 /* m_nokicks.so was loaded and +Q was set, block! */
195 user->WriteServ( "484 %s %s :Can't remove user %s from channel (+Q set)", user->nick.c_str(), channel->name.c_str(), target->nick.c_str());
206 class CommandRemove : public Command, public RemoveBase
209 CommandRemove(InspIRCd* Instance, bool& snk) : Command(Instance, "REMOVE", 0, 2), RemoveBase(Instance, snk)
211 this->source = "m_remove.so";
212 syntax = "<nick> <channel> [<reason>]";
213 TRANSLATE4(TR_NICK, TR_TEXT, TR_TEXT, TR_END);
216 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
218 return RemoveBase::Handle(parameters, user, false);
224 class CommandFpart : public Command, public RemoveBase
227 CommandFpart(InspIRCd* Instance, bool& snk) : Command(Instance, "FPART", 0, 2), RemoveBase(Instance, snk)
229 this->source = "m_remove.so";
230 syntax = "<channel> <nick> [<reason>]";
233 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
235 return RemoveBase::Handle(parameters, user, true);
239 class ModuleRemove : public Module
241 CommandRemove* mycommand;
242 CommandFpart* mycommand2;
247 ModuleRemove(InspIRCd* Me)
250 mycommand = new CommandRemove(ServerInstance, supportnokicks);
251 mycommand2 = new CommandFpart(ServerInstance, supportnokicks);
252 ServerInstance->AddCommand(mycommand);
253 ServerInstance->AddCommand(mycommand2);
255 Implementation eventlist[] = { I_On005Numeric, I_OnRehash };
256 ServerInstance->Modules->Attach(eventlist, this, 2);
260 virtual void On005Numeric(std::string &output)
262 output.append(" REMOVE");
265 virtual void OnRehash(User* user, const std::string&)
267 ConfigReader conf(ServerInstance);
268 supportnokicks = conf.ReadFlag("remove", "supportnokicks", 0);
271 virtual ~ModuleRemove()
275 virtual Version GetVersion()
277 return Version(1, 2, 1, 0, VF_COMMON | VF_VENDOR, API_VERSION);
282 MODULE_INIT(ModuleRemove)