1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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)
35 timeout = time(NULL) + ServerInstance->Duration(parameters[2]);
40 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), c ? parameters[0].c_str() : parameters[1].c_str());
46 user->WriteNumeric(ERR_USERONCHANNEL, "%s %s %s :is already on channel",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
50 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
52 user->WriteNumeric(ERR_NOTONCHANNEL, "%s %s :You're not on that channel!",user->nick.c_str(), c->name.c_str());
56 FOREACH_RESULT(I_OnUserPreInvite,OnUserPreInvite(user,u,c,timeout));
62 else if (MOD_RESULT == 0)
66 if (c->GetStatus(user) < STATUS_HOP)
68 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-");
74 u->InviteTo(c->name.c_str(), timeout);
75 u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
76 user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
77 switch (ServerInstance->Config->AnnounceInvites)
79 case ServerConfig::INVITE_ANNOUNCE_ALL:
80 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());
82 case ServerConfig::INVITE_ANNOUNCE_OPS:
83 c->WriteAllExceptSender(user, true, '@', "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_DYNAMIC:
86 if (c->IsModeSet('i'))
87 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
89 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());
95 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout));
99 // pinched from ircu - invite with not enough parameters shows channels
100 // youve been invited to but haven't joined yet.
101 InvitedList* il = user->GetInviteList();
102 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
104 user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(),i->first.c_str());
106 user->WriteNumeric(RPL_ENDOFINVITELIST, "%s :End of INVITE list",user->nick.c_str());