1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_invite.c |
23 |
* \brief Includes required functions for processing the INVITE command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "channel.h" |
30 |
#include "channel_mode.h" |
31 |
#include "client.h" |
32 |
#include "hash.h" |
33 |
#include "irc_string.h" |
34 |
#include "ircd.h" |
35 |
#include "numeric.h" |
36 |
#include "send.h" |
37 |
#include "server.h" |
38 |
#include "parse.h" |
39 |
#include "modules.h" |
40 |
#include "packet.h" |
41 |
|
42 |
|
43 |
/*! \brief INVITE command handler |
44 |
* |
45 |
* \param source_p Pointer to allocated Client struct from which the message |
46 |
* originally comes from. This can be a local or remote client. |
47 |
* \param parc Integer holding the number of supplied arguments. |
48 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
49 |
* pointers. |
50 |
* \note Valid arguments for this command are: |
51 |
* - parv[0] = command |
52 |
* - parv[1] = user to invite |
53 |
* - parv[2] = channel name |
54 |
*/ |
55 |
static int |
56 |
m_invite(struct Client *source_p, int parc, char *parv[]) |
57 |
{ |
58 |
struct Client *target_p = NULL; |
59 |
struct Channel *chptr = NULL; |
60 |
struct Membership *ms = NULL; |
61 |
|
62 |
if (EmptyString(parv[2])) |
63 |
{ |
64 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "INVITE"); |
65 |
return 0; |
66 |
} |
67 |
|
68 |
if (IsFloodDone(source_p)) |
69 |
flood_endgrace(source_p); |
70 |
|
71 |
if ((target_p = find_person(source_p, parv[1])) == NULL) |
72 |
{ |
73 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, parv[1]); |
74 |
return 0; |
75 |
} |
76 |
|
77 |
if ((chptr = hash_find_channel(parv[2])) == NULL) |
78 |
{ |
79 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[2]); |
80 |
return 0; |
81 |
} |
82 |
|
83 |
if ((ms = find_channel_link(source_p, chptr)) == NULL) |
84 |
{ |
85 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname); |
86 |
return 0; |
87 |
} |
88 |
|
89 |
if (!has_member_flags(ms, CHFL_CHANOP)) |
90 |
{ |
91 |
sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->chname); |
92 |
return 0; |
93 |
} |
94 |
|
95 |
if (IsMember(target_p, chptr)) |
96 |
{ |
97 |
sendto_one_numeric(source_p, &me, ERR_USERONCHANNEL, target_p->name, chptr->chname); |
98 |
return 0; |
99 |
} |
100 |
|
101 |
sendto_one_numeric(source_p, &me, RPL_INVITING, target_p->name, chptr->chname); |
102 |
|
103 |
if (target_p->away[0]) |
104 |
sendto_one_numeric(source_p, &me, RPL_AWAY, target_p->name, target_p->away); |
105 |
|
106 |
if (MyConnect(target_p)) |
107 |
{ |
108 |
sendto_one(target_p, ":%s!%s@%s INVITE %s :%s", |
109 |
source_p->name, source_p->username, |
110 |
source_p->host, |
111 |
target_p->name, chptr->chname); |
112 |
|
113 |
if (chptr->mode.mode & MODE_INVITEONLY) |
114 |
{ |
115 |
sendto_channel_butone(NULL, &me, chptr, CHFL_CHANOP, |
116 |
"NOTICE @%s :%s is inviting %s to %s.", |
117 |
chptr->chname, source_p->name, |
118 |
target_p->name, chptr->chname); |
119 |
|
120 |
/* Add the invite if channel is +i */ |
121 |
add_invite(chptr, target_p); |
122 |
} |
123 |
} |
124 |
else if (target_p->from != source_p->from) |
125 |
sendto_one(target_p, ":%s INVITE %s %s %lu", |
126 |
source_p->id, target_p->id, |
127 |
chptr->chname, (unsigned long)chptr->channelts); |
128 |
return 0; |
129 |
} |
130 |
|
131 |
/*! \brief INVITE command handler |
132 |
* |
133 |
* \param source_p Pointer to allocated Client struct from which the message |
134 |
* originally comes from. This can be a local or remote client. |
135 |
* \param parc Integer holding the number of supplied arguments. |
136 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
137 |
* pointers. |
138 |
* \note Valid arguments for this command are: |
139 |
* - parv[0] = command |
140 |
* - parv[1] = user to invite |
141 |
* - parv[2] = channel name |
142 |
* - parv[3] = channel timestamp |
143 |
*/ |
144 |
static int |
145 |
ms_invite(struct Client *source_p, int parc, char *parv[]) |
146 |
{ |
147 |
struct Client *target_p = NULL; |
148 |
struct Channel *chptr = NULL; |
149 |
|
150 |
if (EmptyString(parv[2])) |
151 |
return 0; |
152 |
|
153 |
if ((target_p = find_person(source_p, parv[1])) == NULL) |
154 |
return 0; |
155 |
|
156 |
if ((chptr = hash_find_channel(parv[2])) == NULL) |
157 |
return 0; |
158 |
|
159 |
if (IsMember(target_p, chptr)) |
160 |
return 0; |
161 |
|
162 |
if (parc > 3 && IsDigit(*parv[3])) |
163 |
if (atoi(parv[3]) > chptr->channelts) |
164 |
return 0; |
165 |
|
166 |
if (MyConnect(target_p)) |
167 |
{ |
168 |
sendto_one(target_p, ":%s!%s@%s INVITE %s :%s", |
169 |
source_p->name, source_p->username, |
170 |
source_p->host, |
171 |
target_p->name, chptr->chname); |
172 |
|
173 |
if (chptr->mode.mode & MODE_INVITEONLY) |
174 |
{ |
175 |
sendto_channel_butone(NULL, &me, chptr, CHFL_CHANOP, |
176 |
"NOTICE @%s :%s is inviting %s to %s.", |
177 |
chptr->chname, source_p->name, |
178 |
target_p->name, chptr->chname); |
179 |
|
180 |
/* Add the invite if channel is +i */ |
181 |
add_invite(chptr, target_p); |
182 |
} |
183 |
} |
184 |
else if (target_p->from != source_p->from) |
185 |
sendto_one(target_p, ":%s INVITE %s %s %lu", |
186 |
source_p->id, target_p->id, |
187 |
chptr->chname, (unsigned long)chptr->channelts); |
188 |
return 0; |
189 |
} |
190 |
|
191 |
|
192 |
static struct Message invite_msgtab = |
193 |
{ |
194 |
"INVITE", 0, 0, 3, MAXPARA, MFLG_SLOW, 0, |
195 |
{ m_unregistered, m_invite, ms_invite, m_ignore, m_invite, m_ignore } |
196 |
}; |
197 |
|
198 |
static void |
199 |
module_init(void) |
200 |
{ |
201 |
mod_add_cmd(&invite_msgtab); |
202 |
} |
203 |
|
204 |
static void |
205 |
module_exit(void) |
206 |
{ |
207 |
mod_del_cmd(&invite_msgtab); |
208 |
} |
209 |
|
210 |
struct module module_entry = |
211 |
{ |
212 |
.node = { NULL, NULL, NULL }, |
213 |
.name = NULL, |
214 |
.version = "$Revision$", |
215 |
.handle = NULL, |
216 |
.modinit = module_init, |
217 |
.modexit = module_exit, |
218 |
.flags = 0 |
219 |
}; |