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 * ---------------------------------------------------
15 #include "commands/cmd_invite.h"
17 extern "C" DllExport Command* init_command(InspIRCd* Instance)
19 return new CommandInvite(Instance);
24 CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, User *user)
28 if (parameters.size() == 2 || parameters.size() == 3)
30 User* u = ServerInstance->FindNick(parameters[0]);
31 Channel* c = ServerInstance->FindChan(parameters[1]);
33 if (parameters.size() == 3)
36 timeout = ServerInstance->Time() + ServerInstance->Duration(parameters[2]);
38 timeout = ConvToInt(parameters[2]);
43 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), c ? parameters[0].c_str() : parameters[1].c_str());
49 user->WriteNumeric(ERR_USERONCHANNEL, "%s %s %s :is already on channel",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
53 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
55 user->WriteNumeric(ERR_NOTONCHANNEL, "%s %s :You're not on that channel!",user->nick.c_str(), c->name.c_str());
59 FOREACH_RESULT(I_OnUserPreInvite,OnUserPreInvite(user,u,c,timeout));
65 else if (MOD_RESULT == 0)
69 if (c->GetStatus(user) < STATUS_HOP)
71 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator", user->nick.c_str(), c->name.c_str(), c->GetStatus(u) == STATUS_HOP ? "" : "half-");
77 u->InviteTo(c->name.c_str(), timeout);
78 u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
79 user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
80 switch (ServerInstance->Config->AnnounceInvites)
82 case ServerConfig::INVITE_ANNOUNCE_ALL:
83 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());
85 case ServerConfig::INVITE_ANNOUNCE_OPS:
86 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
88 case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
89 if (c->IsModeSet('i'))
90 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
92 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());
98 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout));
102 // pinched from ircu - invite with not enough parameters shows channels
103 // youve been invited to but haven't joined yet.
104 InvitedList* il = user->GetInviteList();
105 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
107 user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(),i->first.c_str());
109 user->WriteNumeric(RPL_ENDOFINVITELIST, "%s :End of INVITE list",user->nick.c_str());