]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_invite.cpp
Convert more modules
[user/henk/code/inspircd.git] / src / cmd_invite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 "configreader.h"
16 #include "users.h"
17 #include "modules.h"
18 #include "commands/cmd_invite.h"
19
20 extern "C" DllExport command_t* init_command(InspIRCd* Instance)
21 {
22         return new cmd_invite(Instance);
23 }
24
25 /** Handle /INVITE
26  */
27 CmdResult cmd_invite::Handle (const char** parameters, int pcnt, userrec *user)
28 {
29         int MOD_RESULT = 0;
30
31         if (pcnt == 2)
32         {
33                 userrec* u = ServerInstance->FindNick(parameters[0]);
34                 chanrec* c = ServerInstance->FindChan(parameters[1]);
35
36                 if ((!c) || (!u))
37                 {
38                         if (!c)
39                         {
40                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[1]);
41                         }
42                         else
43                         {
44                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
45                         }
46
47                         return CMD_FAILURE;
48                 }
49
50                 if ((c->modes[CM_INVITEONLY]) && (IS_LOCAL(user)))
51                 {
52                         if (c->GetStatus(user) < STATUS_HOP)
53                         {
54                                 user->WriteServ("482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, c->name);
55                                 return CMD_FAILURE;
56                         }
57                 }
58
59                 if (c->HasUser(u))
60                 {
61                         user->WriteServ("443 %s %s %s :is already on channel",user->nick,u->nick,c->name);
62                         return CMD_FAILURE;
63                 }
64
65                 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
66                 {
67                         user->WriteServ("442 %s %s :You're not on that channel!",user->nick, c->name);
68                         return CMD_FAILURE;
69                 }
70
71                 FOREACH_RESULT(I_OnUserPreInvite,OnUserPreInvite(user,u,c));
72
73                 if (MOD_RESULT == 1)
74                 {
75                         return CMD_FAILURE;
76                 }
77
78                 u->InviteTo(c->name);
79                 u->WriteFrom(user,"INVITE %s :%s",u->nick,c->name);
80                 user->WriteServ("341 %s %s %s",user->nick,u->nick,c->name);
81                 if (ServerInstance->Config->AnnounceInvites)
82                         c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :*** %s invited %s into the channel", c->name, user->nick, u->nick);
83                 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c));
84         }
85         else
86         {
87                 // pinched from ircu - invite with not enough parameters shows channels
88                 // youve been invited to but haven't joined yet.
89                 InvitedList* il = user->GetInviteList();
90                 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
91                 {
92                         user->WriteServ("346 %s :%s",user->nick,i->c_str());
93                 }
94                 user->WriteServ("347 %s :End of INVITE list",user->nick);
95         }
96         return CMD_SUCCESS;
97 }
98