2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
7 * Copyright (C) 2013-2016, 2018 Attila Molnar <attilamolnar@hush.com>
8 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
9 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
10 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
11 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
12 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
13 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
14 * Copyright (C) 2006-2008 Craig Edwards <brain@inspircd.org>
16 * This file is part of InspIRCd. InspIRCd is free software: you can
17 * redistribute it and/or modify it under the terms of the GNU General Public
18 * License as published by the Free Software Foundation, version 2.
20 * This program is distributed in the hope that it will be useful, but WITHOUT
21 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "core_channel.h"
38 RPL_ENDOFINVITELIST = 337
41 CommandInvite::CommandInvite(Module* parent, Invite::APIImpl& invapiimpl)
42 : Command(parent, "INVITE", 0, 0)
46 syntax = "[<nick> <channel> [<time>]]";
51 CmdResult CommandInvite::Handle(User* user, const Params& parameters)
55 if (parameters.size() >= 2)
59 u = ServerInstance->FindNickOnly(parameters[0]);
61 u = ServerInstance->FindNick(parameters[0]);
63 Channel* c = ServerInstance->FindChan(parameters[1]);
65 if (parameters.size() >= 3)
69 unsigned long duration;
70 if (!InspIRCd::Duration(parameters[2], duration))
72 user->WriteNotice("*** Invalid duration for invite");
75 timeout = ServerInstance->Time() + duration;
77 else if (parameters.size() > 3)
78 timeout = ConvToNum<time_t>(parameters[3]);
83 user->WriteNumeric(Numerics::NoSuchChannel(parameters[1]));
86 if ((!u) || (u->registered != REG_ALL))
88 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
92 // Verify channel timestamp if the INVITE is coming from a remote server
95 // Remote INVITE commands must carry a channel timestamp
96 if (parameters.size() < 3)
99 // Drop the invite if our channel TS is lower
100 time_t RemoteTS = ConvToNum<time_t>(parameters[2]);
101 if (c->age < RemoteTS)
105 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
107 user->WriteNumeric(ERR_NOTONCHANNEL, c->name, "You're not on that channel!");
113 user->WriteNumeric(ERR_USERONCHANNEL, u->nick, c->name, "is already on channel");
117 FIRST_MOD_RESULT(OnUserPreInvite, MOD_RESULT, (user,u,c,timeout));
119 if (MOD_RESULT == MOD_RES_DENY)
123 else if (MOD_RESULT == MOD_RES_PASSTHRU)
127 unsigned int rank = c->GetPrefixValue(user);
128 if (rank < HALFOP_VALUE)
130 // Check whether halfop mode is available and phrase error message accordingly
131 ModeHandler* mh = ServerInstance->Modes->FindMode('h', MODETYPE_CHANNEL);
132 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, c->name, InspIRCd::Format("You must be a channel %soperator",
133 (mh && mh->name == "halfop" ? "half-" : "")));
139 LocalUser* const localtargetuser = IS_LOCAL(u);
142 invapi.Create(localtargetuser, c, timeout);
143 ClientProtocol::Messages::Invite invitemsg(user, localtargetuser, c);
144 localtargetuser->Send(ServerInstance->GetRFCEvents().invite, invitemsg);
149 user->WriteNumeric(RPL_INVITING, u->nick, c->name);
151 user->WriteNumeric(RPL_AWAY, u->nick, u->awaymsg);
155 unsigned int minrank = 0;
156 switch (announceinvites)
158 case Invite::ANNOUNCE_OPS:
164 case Invite::ANNOUNCE_DYNAMIC:
166 PrefixMode* mh = ServerInstance->Modes->FindPrefixMode('h');
167 if ((mh) && (mh->name == "halfop"))
169 prefix = mh->GetPrefix();
170 minrank = mh->GetPrefixRank();
180 FOREACH_MOD(OnUserInvite, (user, u, c, timeout, minrank, excepts));
182 if (announceinvites != Invite::ANNOUNCE_NONE)
184 excepts.insert(user);
185 ClientProtocol::Messages::Privmsg privmsg(ServerInstance->FakeClient, c, InspIRCd::Format("*** %s invited %s into the channel", user->nick.c_str(), u->nick.c_str()), MSG_NOTICE);
186 c->Write(ServerInstance->GetRFCEvents().privmsg, privmsg, prefix, excepts);
189 else if (IS_LOCAL(user))
191 // pinched from ircu - invite with not enough parameters shows channels
192 // youve been invited to but haven't joined yet.
193 const Invite::List* list = invapi.GetList(IS_LOCAL(user));
196 for (Invite::List::const_iterator i = list->begin(); i != list->end(); ++i)
197 user->WriteNumeric(RPL_INVITELIST, (*i)->chan->name);
199 user->WriteNumeric(RPL_ENDOFINVITELIST, "End of INVITE list");
204 RouteDescriptor CommandInvite::GetRouting(User* user, const Params& parameters)
206 return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST);