]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_invite.cpp
More numerics.h conversion
[user/henk/code/inspircd.git] / src / commands / cmd_invite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "commands/cmd_invite.h"
16
17 extern "C" DllExport Command* init_command(InspIRCd* Instance)
18 {
19         return new CommandInvite(Instance);
20 }
21
22 /** Handle /INVITE
23  */
24 CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, User *user)
25 {
26         int MOD_RESULT = 0;
27
28         if (parameters.size() == 2 || parameters.size() == 3)
29         {
30                 User* u = ServerInstance->FindNick(parameters[0]);
31                 Channel* c = ServerInstance->FindChan(parameters[1]);
32                 time_t timeout = 0;
33                 if (parameters.size() == 3)
34                 {
35                         timeout = time(NULL) + ServerInstance->Duration(parameters[2]);
36                 }
37
38                 if ((!c) || (!u))
39                 {
40                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), c ? parameters[0].c_str() : parameters[1].c_str());
41                         return CMD_FAILURE;
42                 }
43
44                 if ((c->IsModeSet('i')) && (IS_LOCAL(user)))
45                 {
46                         if (c->GetStatus(user) < STATUS_HOP)
47                         {
48                                 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-");
49                                 return CMD_FAILURE;
50                         }
51                 }
52
53                 if (c->HasUser(u))
54                 {
55                         user->WriteNumeric(ERR_USERONCHANNEL, "%s %s %s :is already on channel",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
56                         return CMD_FAILURE;
57                 }
58
59                 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
60                 {
61                         user->WriteNumeric(ERR_NOTONCHANNEL, "%s %s :You're not on that channel!",user->nick.c_str(), c->name.c_str());
62                         return CMD_FAILURE;
63                 }
64                 {
65
66                 FOREACH_RESULT(I_OnUserPreInvite,OnUserPreInvite(user,u,c,timeout));
67
68                 if (MOD_RESULT == 1)
69                         return CMD_FAILURE;
70                 }
71
72                 u->InviteTo(c->name.c_str(), timeout);
73                 u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
74                 user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
75                 switch (ServerInstance->Config->AnnounceInvites)
76                 {
77                         case ServerConfig::INVITE_ANNOUNCE_ALL:
78                                 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());
79                         break;
80                         case ServerConfig::INVITE_ANNOUNCE_OPS:
81                                 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
82                         break;
83                         case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
84                                 if (c->IsModeSet('i'))
85                                         c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
86                                 else
87                                         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());
88                         break;
89                         default:
90                                 /* Nobody */
91                         break;
92                 }
93                 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout));
94         }
95         else
96         {
97                 // pinched from ircu - invite with not enough parameters shows channels
98                 // youve been invited to but haven't joined yet.
99                 InvitedList* il = user->GetInviteList();
100                 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
101                 {
102                         user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(),i->first.c_str());
103                 }
104                 user->WriteNumeric(RPL_ENDOFINVITELIST, "%s :End of INVITE list",user->nick.c_str());
105         }
106         return CMD_SUCCESS;
107 }
108