1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 #ifndef __CMD_INVITE_H__
17 #define __CMD_INVITE_H__
19 // include the common header files
24 /** Handle /INVITE. These command handlers can be reloaded by the core,
25 * and handle basic RFC1459 commands. Commands within modules work
26 * the same way, however, they can be fully unloaded, where these
29 class CommandInvite : public Command
32 /** Constructor for invite.
34 CommandInvite (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"INVITE", 0, 0, false, 4) { syntax = "[<nick> <channel>]"; }
36 * @param parameters The parameters to the comamnd
37 * @param pcnt The number of parameters passed to teh command
38 * @param user The user issuing the command
39 * @return A value from CmdResult to indicate command success or failure.
41 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
49 CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, User *user)
53 if (parameters.size() == 2 || parameters.size() == 3)
55 User* u = ServerInstance->FindNick(parameters[0]);
56 Channel* c = ServerInstance->FindChan(parameters[1]);
58 if (parameters.size() == 3)
61 timeout = ServerInstance->Time() + ServerInstance->Duration(parameters[2]);
63 timeout = ConvToInt(parameters[2]);
68 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), c ? parameters[0].c_str() : parameters[1].c_str());
74 user->WriteNumeric(ERR_USERONCHANNEL, "%s %s %s :is already on channel",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
78 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
80 user->WriteNumeric(ERR_NOTONCHANNEL, "%s %s :You're not on that channel!",user->nick.c_str(), c->name.c_str());
84 FIRST_MOD_RESULT(ServerInstance, OnUserPreInvite, MOD_RESULT, (user,u,c,timeout));
86 if (MOD_RESULT == MOD_RES_DENY)
90 else if (MOD_RESULT == MOD_RES_PASSTHRU)
94 int rank = c->GetPrefixValue(user);
95 if (rank < HALFOP_VALUE)
97 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",
98 user->nick.c_str(), c->name.c_str(), rank >= HALFOP_VALUE ? "" : "half-");
104 u->InviteTo(c->name.c_str(), timeout);
105 u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
106 user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
107 switch (ServerInstance->Config->AnnounceInvites)
109 case ServerConfig::INVITE_ANNOUNCE_ALL:
110 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());
112 case ServerConfig::INVITE_ANNOUNCE_OPS:
113 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
115 case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
116 if (c->IsModeSet('i'))
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 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());
125 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout));
129 // pinched from ircu - invite with not enough parameters shows channels
130 // youve been invited to but haven't joined yet.
131 InvitedList* il = user->GetInviteList();
132 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
134 user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(),i->first.c_str());
136 user->WriteNumeric(RPL_ENDOFINVITELIST, "%s :End of INVITE list",user->nick.c_str());
142 COMMAND_INIT(CommandInvite)