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