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