]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_invite.cpp
Remove unused debug
[user/henk/code/inspircd.git] / src / cmd_invite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include "configreader.h"
18 #include "users.h"
19 #include "modules.h"
20 #include "commands/cmd_invite.h"
21
22 extern "C" command_t* init_command(InspIRCd* Instance)
23 {
24         return new cmd_invite(Instance);
25 }
26
27 /** Handle /INVITE
28  */
29 CmdResult cmd_invite::Handle (const char** parameters, int pcnt, userrec *user)
30 {
31         int MOD_RESULT = 0;
32
33         if (pcnt == 2)
34         {
35                 userrec* u = ServerInstance->FindNick(parameters[0]);
36                 chanrec* c = ServerInstance->FindChan(parameters[1]);
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->modes[CM_INVITEONLY]) && (IS_LOCAL(user)))
53                 {
54                         if (c->GetStatus(user) < STATUS_HOP)
55                         {
56                                 user->WriteServ("482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, c->name);
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));
74
75                 if (MOD_RESULT == 1)
76                 {
77                         return CMD_FAILURE;
78                 }
79
80                 irc::string xname(c->name);
81                 u->InviteTo(xname);
82                 u->WriteFrom(user,"INVITE %s :%s",u->nick,c->name);
83                 user->WriteServ("341 %s %s %s",user->nick,u->nick,c->name);
84                 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c));
85         }
86         else
87         {
88                 // pinched from ircu - invite with not enough parameters shows channels
89                 // youve been invited to but haven't joined yet.
90                 InvitedList* il = user->GetInviteList();
91                 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
92                 {
93                         user->WriteServ("346 %s :%s",user->nick,i->channel.c_str());
94                 }
95                 user->WriteServ("347 %s :End of INVITE list",user->nick);
96         }
97         return CMD_SUCCESS;
98 }
99