#include "inspircd.h"
+#include "core_channel.h"
-/** Handle /KICK.
- */
-class CommandKick : public Command
+CommandKick::CommandKick(Module* parent)
+ : Command(parent, "KICK", 2, 3)
{
- public:
- /** Constructor for kick.
- */
- CommandKick ( Module* parent) : Command(parent,"KICK",2,3) { syntax = "<channel> <nick>{,<nick>} [<reason>]"; }
- /** Handle command.
- * @param parameters The parameters to the command
- * @param user The user issuing the command
- * @return A value from CmdResult to indicate command success or failure.
- */
- CmdResult Handle(const std::vector<std::string>& parameters, User *user);
- RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
- {
- return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST);
- }
-};
+ syntax = "<channel> <nick>{,<nick>} [<reason>]";
+}
/** Handle /KICK
*/
CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User *user)
{
- std::string reason;
Channel* c = ServerInstance->FindChan(parameters[0]);
User* u;
else
u = ServerInstance->FindNick(parameters[1]);
- if (!u || !c)
+ if ((!u) || (!c) || (u->registered != REG_ALL))
{
- user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", u ? parameters[0].c_str() : parameters[1].c_str());
+ user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", c ? parameters[1].c_str() : parameters[0].c_str());
return CMD_FAILURE;
}
}
}
- if (parameters.size() > 2)
+ const UserMembIter victimiter = c->userlist.find(u);
+ if (victimiter == c->userlist.end())
{
- reason.assign(parameters[2], 0, ServerInstance->Config->Limits.MaxKick);
+ user->WriteNumeric(ERR_USERNOTINCHANNEL, "%s %s :They are not on that channel", u->nick.c_str(), c->name.c_str());
+ return CMD_FAILURE;
}
- else
+ Membership* const memb = victimiter->second;
+
+ const bool has_reason = (parameters.size() > 2);
+ const std::string reason((has_reason ? parameters.back() : user->nick), 0, ServerInstance->Config->Limits.MaxKick);
+
+ // Do the following checks only if the KICK is done by a local user;
+ // each server enforces its own rules.
+ if (srcmemb)
{
- reason.assign(user->nick, 0, ServerInstance->Config->Limits.MaxKick);
+ // Modules are allowed to explicitly allow or deny kicks done by local users
+ ModResult res;
+ FIRST_MOD_RESULT(OnUserPreKick, res, (user, memb, reason));
+ if (res == MOD_RES_DENY)
+ return CMD_FAILURE;
+
+ if (res == MOD_RES_PASSTHRU)
+ {
+ unsigned int them = srcmemb->getRank();
+ unsigned int req = HALFOP_VALUE;
+ for (std::string::size_type i = 0; i < memb->modes.length(); i++)
+ {
+ ModeHandler* mh = ServerInstance->Modes->FindMode(memb->modes[i], MODETYPE_CHANNEL);
+ if (mh && mh->GetLevelRequired() > req)
+ req = mh->GetLevelRequired();
+ }
+
+ if (them < req)
+ {
+ user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s :You must be a channel %soperator",
+ this->name.c_str(), req > HALFOP_VALUE ? "" : "half-");
+ return CMD_FAILURE;
+ }
+ }
}
- c->KickUser(user, u, reason, srcmemb);
+ c->KickUser(user, victimiter, reason);
return CMD_SUCCESS;
}
-COMMAND_INIT(CommandKick)
+RouteDescriptor CommandKick::GetRouting(User* user, const std::vector<std::string>& parameters)
+{
+ return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST);
+}