]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_channel/cmd_invite.cpp
Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters
[user/henk/code/inspircd.git] / src / coremods / core_channel / cmd_invite.cpp
index ea4692d0459bddebe5255b4b46cbc34318bab9d8..a1319ebc049651d2099faf6149b33c960622128b 100644 (file)
 
 #include "inspircd.h"
 #include "core_channel.h"
+#include "invite.h"
 
-CommandInvite::CommandInvite(Module* parent)
+CommandInvite::CommandInvite(Module* parent, Invite::APIImpl& invapiimpl)
        : Command(parent, "INVITE", 0, 0)
+       , invapi(invapiimpl)
 {
        Penalty = 4;
        syntax = "[<nick> <channel>]";
@@ -56,7 +58,7 @@ CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, Use
 
                if ((!c) || (!u) || (u->registered != REG_ALL))
                {
-                       user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", c ? parameters[0].c_str() : parameters[1].c_str());
+                       user->WriteNumeric(Numerics::NoSuchNick(c ? parameters[0] : parameters[1]));
                        return CMD_FAILURE;
                }
 
@@ -75,13 +77,13 @@ CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, Use
 
                if ((IS_LOCAL(user)) && (!c->HasUser(user)))
                {
-                       user->WriteNumeric(ERR_NOTONCHANNEL, "%s :You're not on that channel!", c->name.c_str());
+                       user->WriteNumeric(ERR_NOTONCHANNEL, c->name, "You're not on that channel!");
                        return CMD_FAILURE;
                }
 
                if (c->HasUser(u))
                {
-                       user->WriteNumeric(ERR_USERONCHANNEL, "%s %s :is already on channel", u->nick.c_str(), c->name.c_str());
+                       user->WriteNumeric(ERR_USERONCHANNEL, u->nick, c->name, "is already on channel");
                        return CMD_FAILURE;
                }
 
@@ -100,8 +102,8 @@ CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, Use
                                {
                                        // Check whether halfop mode is available and phrase error message accordingly
                                        ModeHandler* mh = ServerInstance->Modes->FindMode('h', MODETYPE_CHANNEL);
-                                       user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s :You must be a channel %soperator",
-                                               c->name.c_str(), (mh && mh->name == "halfop" ? "half-" : ""));
+                                       user->WriteNumeric(ERR_CHANOPRIVSNEEDED, c->name, InspIRCd::Format("You must be a channel %soperator",
+                                               (mh && mh->name == "halfop" ? "half-" : "")));
                                        return CMD_FAILURE;
                                }
                        }
@@ -109,49 +111,59 @@ CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, Use
 
                if (IS_LOCAL(u))
                {
-                       Invitation::Create(c, IS_LOCAL(u), timeout);
+                       invapi.Create(IS_LOCAL(u), c, timeout);
                        u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
                }
 
                if (IS_LOCAL(user))
-                       user->WriteNumeric(RPL_INVITING, "%s %s", u->nick.c_str(),c->name.c_str());
+               {
+                       user->WriteNumeric(RPL_INVITING, u->nick, c->name);
+                       if (u->IsAway())
+                               user->WriteNumeric(RPL_AWAY, u->nick, u->awaymsg);
+               }
 
-               if (ServerInstance->Config->AnnounceInvites != ServerConfig::INVITE_ANNOUNCE_NONE)
+               char prefix = 0;
+               unsigned int minrank = 0;
+               switch (ServerInstance->Config->AnnounceInvites)
                {
-                       char prefix;
-                       switch (ServerInstance->Config->AnnounceInvites)
+                       case ServerConfig::INVITE_ANNOUNCE_OPS:
                        {
-                               case ServerConfig::INVITE_ANNOUNCE_OPS:
-                               {
-                                       prefix = '@';
-                                       break;
-                               }
-                               case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
-                               {
-                                       PrefixMode* mh = ServerInstance->Modes->FindPrefixMode('h');
-                                       prefix = (mh && mh->name == "halfop" ? mh->GetPrefix() : '@');
-                                       break;
-                               }
-                               default:
+                               prefix = '@';
+                               minrank = OP_VALUE;
+                               break;
+                       }
+                       case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
+                       {
+                               PrefixMode* mh = ServerInstance->Modes->FindPrefixMode('h');
+                               if ((mh) && (mh->name == "halfop"))
                                {
-                                       prefix = 0;
-                                       break;
+                                       prefix = mh->GetPrefix();
+                                       minrank = mh->GetPrefixRank();
                                }
+                               break;
+                       }
+                       default:
+                       {
                        }
-                       c->WriteAllExceptSender(user, true, prefix, "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
                }
-               FOREACH_MOD(OnUserInvite, (user,u,c,timeout));
+
+               CUList excepts;
+               FOREACH_MOD(OnUserInvite, (user, u, c, timeout, minrank, excepts));
+
+               if (ServerInstance->Config->AnnounceInvites != ServerConfig::INVITE_ANNOUNCE_NONE)
+                       c->WriteAllExcept(user, true, prefix, excepts, "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
        }
        else if (IS_LOCAL(user))
        {
                // pinched from ircu - invite with not enough parameters shows channels
                // youve been invited to but haven't joined yet.
-               InviteList& il = IS_LOCAL(user)->GetInviteList();
-               for (InviteList::const_iterator i = il.begin(); i != il.end(); ++i)
+               const Invite::List* list = invapi.GetList(IS_LOCAL(user));
+               if (list)
                {
-                       user->WriteNumeric(RPL_INVITELIST, ":%s", (*i)->chan->name.c_str());
+                       for (Invite::List::const_iterator i = list->begin(); i != list->end(); ++i)
+                               user->WriteNumeric(RPL_INVITELIST, (*i)->chan->name);
                }
-               user->WriteNumeric(RPL_ENDOFINVITELIST, ":End of INVITE list");
+               user->WriteNumeric(RPL_ENDOFINVITELIST, "End of INVITE list");
        }
        return CMD_SUCCESS;
 }