]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_invite.cpp
49296ca42d8864150866c52aa83e4b4ee23f9e1e
[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 char* const* parameters, int pcnt, User *user)
25 {
26         int MOD_RESULT = 0;
27
28         if (pcnt == 2 || pcnt == 3)
29         {
30                 User* u = ServerInstance->FindNick(parameters[0]);
31                 Channel* c = ServerInstance->FindChan(parameters[1]);
32                 time_t timeout = 0;
33                 if (pcnt == 3)
34                 {
35                         timeout = time(NULL) + ServerInstance->Duration(parameters[2]);
36                 }
37
38                 if ((!c) || (!u))
39                 {
40                         if (!c)
41                         {
42                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[1]);
43                         }
44                         else
45                         {
46                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
47                         }
48
49                         return CMD_FAILURE;
50                 }
51
52                 if ((c->IsModeSet('i')) && (IS_LOCAL(user)))
53                 {
54                         if (c->GetStatus(user) < STATUS_HOP)
55                         {
56                                 user->WriteServ("482 %s %s :You must be a channel %soperator", user->nick, c->name, c->GetStatus(u) == STATUS_HOP ? "" : "half-");
57                                 return CMD_FAILURE;
58                         }
59                 }
60
61                 if (c->HasUser(u))
62                 {
63                         user->WriteServ("443 %s %s %s :is already on channel",user->nick,u->nick,c->name);
64                         return CMD_FAILURE;
65                 }
66
67                 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
68                 {
69                         user->WriteServ("442 %s %s :You're not on that channel!",user->nick, c->name);
70                         return CMD_FAILURE;
71                 }
72
73                 FOREACH_RESULT(I_OnUserPreInvite,OnUserPreInvite(user,u,c,timeout));
74
75                 if (MOD_RESULT == 1)
76                 {
77                         return CMD_FAILURE;
78                 }
79
80                 u->InviteTo(c->name, timeout);
81                 u->WriteFrom(user,"INVITE %s :%s",u->nick,c->name);
82                 user->WriteServ("341 %s %s %s",user->nick,u->nick,c->name);
83                 switch (ServerInstance->Config->AnnounceInvites)
84                 {
85                         case ServerConfig::INVITE_ANNOUNCE_ALL:
86                                 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :*** %s invited %s into the channel", c->name, user->nick, u->nick);
87                         break;
88                         case ServerConfig::INVITE_ANNOUNCE_OPS:
89                                 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name, user->nick, u->nick);
90                         break;
91                         case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
92                                 if (c->IsModeSet('i'))
93                                         c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name, user->nick, u->nick);
94                                 else
95                                         c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :*** %s invited %s into the channel", c->name, user->nick, u->nick);
96                         break;
97                         default:
98                                 /* Nobody */
99                         break;
100                 }
101                 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout));
102         }
103         else
104         {
105                 // pinched from ircu - invite with not enough parameters shows channels
106                 // youve been invited to but haven't joined yet.
107                 InvitedList* il = user->GetInviteList();
108                 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
109                 {
110                         user->WriteServ("346 %s :%s",user->nick,i->first.c_str());
111                 }
112                 user->WriteServ("347 %s :End of INVITE list",user->nick);
113         }
114         return CMD_SUCCESS;
115 }
116