]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_channel/cmd_invite.cpp
Add SERVICE_CUSTOM for services managed by a module
[user/henk/code/inspircd.git] / src / coremods / core_channel / cmd_invite.cpp
index 25afc071318da79bd4e9d5845bbbd67640967c00..96f56058256658177e52ed8c9f0fb68d7e9ab18c 100644 (file)
 
 
 #include "inspircd.h"
+#include "core_channel.h"
+#include "invite.h"
 
-/** Handle /INVITE.
- */
-class CommandInvite : public Command
+CommandInvite::CommandInvite(Module* parent, Invite::APIImpl& invapiimpl)
+       : Command(parent, "INVITE", 0, 0)
+       , invapi(invapiimpl)
 {
- public:
-       /** Constructor for invite.
-        */
-       CommandInvite ( Module* parent) : Command(parent,"INVITE", 0, 0) { Penalty = 4; syntax = "[<nick> <channel>]"; }
-       /** 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);
-       }
-};
+       Penalty = 4;
+       syntax = "[<nick> <channel>]";
+}
 
 /** Handle /INVITE
  */
@@ -48,7 +38,7 @@ CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, Use
 {
        ModResult MOD_RESULT;
 
-       if (parameters.size() == 2 || parameters.size() == 3)
+       if (parameters.size() >= 2)
        {
                User* u;
                if (IS_LOCAL(user))
@@ -58,12 +48,12 @@ CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, Use
 
                Channel* c = ServerInstance->FindChan(parameters[1]);
                time_t timeout = 0;
-               if (parameters.size() == 3)
+               if (parameters.size() >= 3)
                {
                        if (IS_LOCAL(user))
                                timeout = ServerInstance->Time() + InspIRCd::Duration(parameters[2]);
-                       else
-                               timeout = ConvToInt(parameters[2]);
+                       else if (parameters.size() > 3)
+                               timeout = ConvToInt(parameters[3]);
                }
 
                if ((!c) || (!u) || (u->registered != REG_ALL))
@@ -72,6 +62,19 @@ CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, Use
                        return CMD_FAILURE;
                }
 
+               // Verify channel timestamp if the INVITE is coming from a remote server
+               if (!IS_LOCAL(user))
+               {
+                       // Remote INVITE commands must carry a channel timestamp
+                       if (parameters.size() < 3)
+                               return CMD_INVALID;
+
+                       // Drop the invite if our channel TS is lower
+                       time_t RemoteTS = ConvToInt(parameters[2]);
+                       if (c->age < RemoteTS)
+                               return CMD_FAILURE;
+               }
+
                if ((IS_LOCAL(user)) && (!c->HasUser(user)))
                {
                        user->WriteNumeric(ERR_NOTONCHANNEL, "%s :You're not on that channel!", c->name.c_str());
@@ -108,12 +111,16 @@ 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());
+                       if (u->IsAway())
+                               user->WriteNumeric(RPL_AWAY, "%s :%s", u->nick.c_str(), u->awaymsg.c_str());
+               }
 
                if (ServerInstance->Config->AnnounceInvites != ServerConfig::INVITE_ANNOUNCE_NONE)
                {
@@ -145,15 +152,18 @@ CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, Use
        {
                // 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, ":%s", (*i)->chan->name.c_str());
                }
                user->WriteNumeric(RPL_ENDOFINVITELIST, ":End of INVITE list");
        }
        return CMD_SUCCESS;
 }
 
-
-COMMAND_INIT(CommandInvite)
+RouteDescriptor CommandInvite::GetRouting(User* user, const std::vector<std::string>& parameters)
+{
+       return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST);
+}