1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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 /** Handle /INVITE. These command handlers can be reloaded by the core,
17 * and handle basic RFC1459 commands. Commands within modules work
18 * the same way, however, they can be fully unloaded, where these
21 class CommandInvite : public Command
24 /** Constructor for invite.
26 CommandInvite ( Module* parent) : Command(parent,"INVITE", 0, 0) { Penalty = 4; syntax = "[<nick> <channel>]"; }
28 * @param parameters The parameters to the comamnd
29 * @param pcnt The number of parameters passed to teh command
30 * @param user The user issuing the command
31 * @return A value from CmdResult to indicate command success or failure.
33 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
38 CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, User *user)
42 if (parameters.size() == 2 || parameters.size() == 3)
46 u = ServerInstance->FindNickOnly(parameters[0]);
48 u = ServerInstance->FindNick(parameters[0]);
50 Channel* c = ServerInstance->FindChan(parameters[1]);
52 if (parameters.size() == 3)
55 timeout = ServerInstance->Time() + ServerInstance->Duration(parameters[2]);
57 timeout = ConvToInt(parameters[2]);
62 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), c ? parameters[0].c_str() : parameters[1].c_str());
68 user->WriteNumeric(ERR_USERONCHANNEL, "%s %s %s :is already on channel",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
72 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
74 user->WriteNumeric(ERR_NOTONCHANNEL, "%s %s :You're not on that channel!",user->nick.c_str(), c->name.c_str());
78 FIRST_MOD_RESULT(OnUserPreInvite, MOD_RESULT, (user,u,c,timeout));
80 if (MOD_RESULT == MOD_RES_DENY)
84 else if (MOD_RESULT == MOD_RES_PASSTHRU)
88 int rank = c->GetPrefixValue(user);
89 if (rank < HALFOP_VALUE)
91 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",
92 user->nick.c_str(), c->name.c_str(), rank >= HALFOP_VALUE ? "" : "half-");
99 IS_LOCAL(u)->InviteTo(c->name.c_str(), timeout);
100 u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
101 user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
102 switch (ServerInstance->Config->AnnounceInvites)
104 case ServerConfig::INVITE_ANNOUNCE_ALL:
105 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());
107 case ServerConfig::INVITE_ANNOUNCE_OPS:
108 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
110 case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
111 if (c->IsModeSet('i'))
112 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
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());
120 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout));
122 else if (IS_LOCAL(user))
124 // pinched from ircu - invite with not enough parameters shows channels
125 // youve been invited to but haven't joined yet.
126 InvitedList* il = IS_LOCAL(user)->GetInviteList();
127 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
129 user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(),i->first.c_str());
131 user->WriteNumeric(RPL_ENDOFINVITELIST, "%s :End of INVITE list",user->nick.c_str());
137 COMMAND_INIT(CommandInvite)