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