]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_invite.cpp
931c684ce7fc985eb30e05390d6cb03e0319816f
[user/henk/code/inspircd.git] / src / cmd_invite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2005 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain.net>
8  *                <Craig.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 using namespace std;
18
19 #include "inspircd_config.h"
20 #include "inspircd.h"
21 #include "inspircd_io.h"
22 #include <string>
23 #include <vector>
24 #include <deque>
25 #include "users.h"
26 #include "ctables.h"
27 #include "globals.h"
28 #include "modules.h"
29 #include "dynamic.h"
30 #include "message.h"
31 #include "commands.h"
32 #include "inspstring.h"
33 #include "helperfuncs.h"
34 #include "hashcomp.h"
35 #include "typedefs.h"
36 #include "command_parse.h"
37 #include "cmd_invite.h"
38
39 extern int MODCOUNT;
40 extern std::vector<Module*> modules;
41 extern std::vector<ircd_module*> factory;
42
43 void cmd_invite::Handle (char **parameters, int pcnt, userrec *user)
44 {
45         if (pcnt == 2)
46         {
47                 userrec* u = Find(parameters[0]);
48                 chanrec* c = FindChan(parameters[1]);
49
50                 if ((!c) || (!u))
51                 {
52                         if (!c)
53                         {
54                                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[1]);
55                         }
56                         else
57                         {
58                                 if (c->binarymodes & CM_INVITEONLY)
59                                 {
60                                         WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
61                                 }
62                         }
63
64                         return;
65                 }
66
67                 if (c->binarymodes & CM_INVITEONLY)
68                 {
69                         if (cstatus(user,c) < STATUS_HOP)
70                         {
71                                 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, c->name);
72                                 return;
73                         }
74                 }
75                 if (has_channel(u,c))
76                 {
77                         WriteServ(user->fd,"443 %s %s %s :Is already on channel %s",user->nick,u->nick,c->name,c->name);
78                         return;
79                 }
80                 if (!has_channel(user,c))
81                 {
82                         WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, c->name);
83                         return;
84                 }
85
86                 int MOD_RESULT = 0;
87                 FOREACH_RESULT(OnUserPreInvite(user,u,c));
88                 if (MOD_RESULT == 1) {
89                         return;
90                 }
91
92                 irc::string xname(c->name);
93                 u->InviteTo(xname);
94                 WriteFrom(u->fd,user,"INVITE %s :%s",u->nick,c->name);
95                 WriteServ(user->fd,"341 %s %s %s",user->nick,u->nick,c->name);
96                 FOREACH_MOD OnUserInvite(user,u,c);
97         }
98         else
99         {
100                 // pinched from ircu - invite with not enough parameters shows channels
101                 // youve been invited to but haven't joined yet.
102                 InvitedList* il = user->GetInviteList();
103                 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
104                 {
105                         WriteServ(user->fd,"346 %s :%s",user->nick,i->channel.c_str());
106                 }
107                 WriteServ(user->fd,"347 %s :End of INVITE list",user->nick);
108         }
109 }
110
111