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/>.
25 /** Handle /INVITE. These command handlers can be reloaded by the core,
26 * and handle basic RFC1459 commands. Commands within modules work
27 * the same way, however, they can be fully unloaded, where these
30 class CommandInvite : public Command
33 /** Constructor for invite.
35 CommandInvite ( Module* parent) : Command(parent,"INVITE", 0, 0) { Penalty = 4; syntax = "[<nick> <channel>]"; }
37 * @param parameters The parameters to the comamnd
38 * @param pcnt The number of parameters passed to teh command
39 * @param user The user issuing the command
40 * @return A value from CmdResult to indicate command success or failure.
42 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
47 CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, User *user)
51 if (parameters.size() == 2 || parameters.size() == 3)
55 u = ServerInstance->FindNickOnly(parameters[0]);
57 u = ServerInstance->FindNick(parameters[0]);
59 Channel* c = ServerInstance->FindChan(parameters[1]);
61 if (parameters.size() == 3)
64 timeout = ServerInstance->Time() + ServerInstance->Duration(parameters[2]);
66 timeout = ConvToInt(parameters[2]);
71 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), c ? parameters[0].c_str() : parameters[1].c_str());
77 user->WriteNumeric(ERR_USERONCHANNEL, "%s %s %s :is already on channel",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
81 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
83 user->WriteNumeric(ERR_NOTONCHANNEL, "%s %s :You're not on that channel!",user->nick.c_str(), c->name.c_str());
87 FIRST_MOD_RESULT(OnUserPreInvite, MOD_RESULT, (user,u,c,timeout));
89 if (MOD_RESULT == MOD_RES_DENY)
93 else if (MOD_RESULT == MOD_RES_PASSTHRU)
97 int rank = c->GetPrefixValue(user);
98 if (rank < HALFOP_VALUE)
100 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",
101 user->nick.c_str(), c->name.c_str(), rank >= HALFOP_VALUE ? "" : "half-");
108 IS_LOCAL(u)->InviteTo(c->name.c_str(), timeout);
109 u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
110 user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
111 switch (ServerInstance->Config->AnnounceInvites)
113 case ServerConfig::INVITE_ANNOUNCE_ALL:
114 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
116 case ServerConfig::INVITE_ANNOUNCE_OPS:
117 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
119 case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
120 if (c->IsModeSet('i'))
121 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
123 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
129 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout));
131 else if (IS_LOCAL(user))
133 // pinched from ircu - invite with not enough parameters shows channels
134 // youve been invited to but haven't joined yet.
135 InviteList& il = IS_LOCAL(user)->GetInviteList();
136 for (InviteList::const_iterator i = il.begin(); i != il.end(); ++i)
138 user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(), (*i)->chan->name.c_str());
140 user->WriteNumeric(RPL_ENDOFINVITELIST, "%s :End of INVITE list",user->nick.c_str());
146 COMMAND_INIT(CommandInvite)