2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
7 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "core_channel.h"
27 CommandInvite::CommandInvite(Module* parent, Invite::APIImpl& invapiimpl)
28 : Command(parent, "INVITE", 0, 0)
32 syntax = "[<nick> <channel>]";
37 CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, User *user)
41 if (parameters.size() >= 2)
45 u = ServerInstance->FindNickOnly(parameters[0]);
47 u = ServerInstance->FindNick(parameters[0]);
49 Channel* c = ServerInstance->FindChan(parameters[1]);
51 if (parameters.size() >= 3)
54 timeout = ServerInstance->Time() + InspIRCd::Duration(parameters[2]);
55 else if (parameters.size() > 3)
56 timeout = ConvToInt(parameters[3]);
59 if ((!c) || (!u) || (u->registered != REG_ALL))
61 user->WriteNumeric(Numerics::NoSuchNick(c ? parameters[0] : parameters[1]));
65 // Verify channel timestamp if the INVITE is coming from a remote server
68 // Remote INVITE commands must carry a channel timestamp
69 if (parameters.size() < 3)
72 // Drop the invite if our channel TS is lower
73 time_t RemoteTS = ConvToInt(parameters[2]);
74 if (c->age < RemoteTS)
78 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
80 user->WriteNumeric(ERR_NOTONCHANNEL, c->name, "You're not on that channel!");
86 user->WriteNumeric(ERR_USERONCHANNEL, u->nick, c->name, "is already on channel");
90 FIRST_MOD_RESULT(OnUserPreInvite, MOD_RESULT, (user,u,c,timeout));
92 if (MOD_RESULT == MOD_RES_DENY)
96 else if (MOD_RESULT == MOD_RES_PASSTHRU)
100 unsigned int rank = c->GetPrefixValue(user);
101 if (rank < HALFOP_VALUE)
103 // Check whether halfop mode is available and phrase error message accordingly
104 ModeHandler* mh = ServerInstance->Modes->FindMode('h', MODETYPE_CHANNEL);
105 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, c->name, InspIRCd::Format("You must be a channel %soperator",
106 (mh && mh->name == "halfop" ? "half-" : "")));
114 invapi.Create(IS_LOCAL(u), c, timeout);
115 u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
120 user->WriteNumeric(RPL_INVITING, u->nick, c->name);
122 user->WriteNumeric(RPL_AWAY, u->nick, u->awaymsg);
126 unsigned int minrank = 0;
127 switch (ServerInstance->Config->AnnounceInvites)
129 case ServerConfig::INVITE_ANNOUNCE_OPS:
135 case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
137 PrefixMode* mh = ServerInstance->Modes->FindPrefixMode('h');
138 if ((mh) && (mh->name == "halfop"))
140 prefix = mh->GetPrefix();
141 minrank = mh->GetPrefixRank();
151 FOREACH_MOD(OnUserInvite, (user, u, c, timeout, minrank, excepts));
153 if (ServerInstance->Config->AnnounceInvites != ServerConfig::INVITE_ANNOUNCE_NONE)
154 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());
156 else if (IS_LOCAL(user))
158 // pinched from ircu - invite with not enough parameters shows channels
159 // youve been invited to but haven't joined yet.
160 const Invite::List* list = invapi.GetList(IS_LOCAL(user));
163 for (Invite::List::const_iterator i = list->begin(); i != list->end(); ++i)
164 user->WriteNumeric(RPL_INVITELIST, (*i)->chan->name);
166 user->WriteNumeric(RPL_ENDOFINVITELIST, "End of INVITE list");
171 RouteDescriptor CommandInvite::GetRouting(User* user, const std::vector<std::string>& parameters)
173 return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST);