]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_channel/cmd_kick.cpp
Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters
[user/henk/code/inspircd.git] / src / coremods / core_channel / cmd_kick.cpp
index a9e7ee2cd57c8daf7c283297dca693f47fccce12..7f8a8a3291d28d0c445db47e8d34df945917c7b6 100644 (file)
@@ -31,7 +31,6 @@ CommandKick::CommandKick(Module* parent)
  */
 CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User *user)
 {
-       std::string reason;
        Channel* c = ServerInstance->FindChan(parameters[0]);
        User* u;
 
@@ -45,7 +44,7 @@ CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User
 
        if ((!u) || (!c) || (u->registered != REG_ALL))
        {
-               user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", c ? parameters[1].c_str() : parameters[0].c_str());
+               user->WriteNumeric(Numerics::NoSuchNick(c ? parameters[1] : parameters[0]));
                return CMD_FAILURE;
        }
 
@@ -55,33 +54,39 @@ CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User
                srcmemb = c->GetUser(user);
                if (!srcmemb)
                {
-                       user->WriteNumeric(ERR_NOTONCHANNEL, "%s :You're not on that channel!", parameters[0].c_str());
+                       user->WriteNumeric(ERR_NOTONCHANNEL, parameters[0], "You're not on that channel!");
                        return CMD_FAILURE;
                }
 
                if (u->server->IsULine())
                {
-                       user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s :You may not kick a u-lined client", c->name.c_str());
+                       user->WriteNumeric(ERR_CHANOPRIVSNEEDED, c->name, "You may not kick a u-lined client");
                        return CMD_FAILURE;
                }
        }
 
-       Membership* const memb = c->GetUser(u);
-       if (!memb)
+       const Channel::MemberMap::iterator victimiter = c->userlist.find(u);
+       if (victimiter == c->userlist.end())
        {
-               user->WriteNumeric(ERR_USERNOTINCHANNEL, "%s %s :They are not on that channel", u->nick.c_str(), c->name.c_str());
+               user->WriteNumeric(ERR_USERNOTINCHANNEL, u->nick, c->name, "They are not on that channel");
                return CMD_FAILURE;
        }
+       Membership* const memb = victimiter->second;
 
-       if (parameters.size() > 2)
+       // KICKs coming from servers can carry a membership id
+       if ((!IS_LOCAL(user)) && (parameters.size() > 3))
        {
-               reason.assign(parameters[2], 0, ServerInstance->Config->Limits.MaxKick);
-       }
-       else
-       {
-               reason.assign(user->nick, 0, ServerInstance->Config->Limits.MaxKick);
+               // If the current membership id is not equal to the one in the message then the user rejoined
+               if (memb->id != Membership::IdFromString(parameters[2]))
+               {
+                       ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Dropped KICK due to membership id mismatch: " + ConvToStr(memb->id) + " != " + parameters[2]);
+                       return CMD_FAILURE;
+               }
        }
 
+       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)
@@ -105,14 +110,14 @@ CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User
 
                        if (them < req)
                        {
-                               user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s :You must be a channel %soperator",
-                                       this->name.c_str(), req > HALFOP_VALUE ? "" : "half-");
+                               user->WriteNumeric(ERR_CHANOPRIVSNEEDED, c->name, InspIRCd::Format("You must be a channel %soperator",
+                                       req > HALFOP_VALUE ? "" : "half-"));
                                return CMD_FAILURE;
                        }
                }
        }
 
-       c->KickUser(user, u, reason, srcmemb);
+       c->KickUser(user, victimiter, reason);
 
        return CMD_SUCCESS;
 }