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 /** 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)
44 User* u = ServerInstance->FindNick(parameters[0]);
45 Channel* c = ServerInstance->FindChan(parameters[1]);
47 if (parameters.size() == 3)
50 timeout = ServerInstance->Time() + ServerInstance->Duration(parameters[2]);
52 timeout = ConvToInt(parameters[2]);
57 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), c ? parameters[0].c_str() : parameters[1].c_str());
63 user->WriteNumeric(ERR_USERONCHANNEL, "%s %s %s :is already on channel",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
67 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
69 user->WriteNumeric(ERR_NOTONCHANNEL, "%s %s :You're not on that channel!",user->nick.c_str(), c->name.c_str());
73 FIRST_MOD_RESULT(OnUserPreInvite, MOD_RESULT, (user,u,c,timeout));
75 if (MOD_RESULT == MOD_RES_DENY)
79 else if (MOD_RESULT == MOD_RES_PASSTHRU)
83 int rank = c->GetPrefixValue(user);
84 if (rank < HALFOP_VALUE)
86 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",
87 user->nick.c_str(), c->name.c_str(), rank >= HALFOP_VALUE ? "" : "half-");
94 IS_LOCAL(u)->InviteTo(c->name.c_str(), timeout);
95 u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
96 user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
97 switch (ServerInstance->Config->AnnounceInvites)
99 case ServerConfig::INVITE_ANNOUNCE_ALL:
100 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());
102 case ServerConfig::INVITE_ANNOUNCE_OPS:
103 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
105 case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
106 if (c->IsModeSet('i'))
107 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
109 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());
115 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout));
117 else if (IS_LOCAL(user))
119 // pinched from ircu - invite with not enough parameters shows channels
120 // youve been invited to but haven't joined yet.
121 InvitedList* il = IS_LOCAL(user)->GetInviteList();
122 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
124 user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(),i->first.c_str());
126 user->WriteNumeric(RPL_ENDOFINVITELIST, "%s :End of INVITE list",user->nick.c_str());
132 COMMAND_INIT(CommandInvite)