1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
7007 |
* Copyright (c) 1997-2016 ircd-hybrid development team |
5 |
adx |
30 |
* |
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 |
michael |
4564 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
/*! \file channel.c |
23 |
|
|
* \brief Responsible for managing channels, members, bans and topics |
24 |
knight |
31 |
* \version $Id$ |
25 |
adx |
30 |
*/ |
26 |
|
|
|
27 |
|
|
#include "stdinc.h" |
28 |
michael |
1011 |
#include "list.h" |
29 |
adx |
30 |
#include "channel.h" |
30 |
|
|
#include "channel_mode.h" |
31 |
|
|
#include "client.h" |
32 |
|
|
#include "hash.h" |
33 |
michael |
1632 |
#include "conf.h" |
34 |
michael |
7235 |
#include "conf_resv.h" |
35 |
michael |
371 |
#include "hostmask.h" |
36 |
adx |
30 |
#include "irc_string.h" |
37 |
|
|
#include "ircd.h" |
38 |
|
|
#include "numeric.h" |
39 |
michael |
3347 |
#include "server.h" |
40 |
adx |
30 |
#include "send.h" |
41 |
|
|
#include "event.h" |
42 |
|
|
#include "memory.h" |
43 |
michael |
1654 |
#include "mempool.h" |
44 |
michael |
3347 |
#include "misc.h" |
45 |
adx |
30 |
|
46 |
michael |
3235 |
|
47 |
michael |
3945 |
dlink_list channel_list; |
48 |
michael |
1654 |
mp_pool_t *ban_pool; /*! \todo ban_pool shouldn't be a global var */ |
49 |
adx |
30 |
|
50 |
michael |
7548 |
static mp_pool_t *member_pool, *channel_pool, *invite_pool; |
51 |
adx |
30 |
|
52 |
|
|
|
53 |
|
|
/*! \brief Initializes the channel blockheap, adds known channel CAPAB |
54 |
|
|
*/ |
55 |
|
|
void |
56 |
michael |
1798 |
channel_init(void) |
57 |
adx |
30 |
{ |
58 |
michael |
6353 |
add_capability("EX", CAPAB_EX); |
59 |
|
|
add_capability("IE", CAPAB_IE); |
60 |
adx |
30 |
|
61 |
michael |
7548 |
invite_pool = mp_pool_new(sizeof(struct Invite), MP_CHUNK_SIZE_INVITE); |
62 |
michael |
1654 |
channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL); |
63 |
|
|
ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN); |
64 |
|
|
member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER); |
65 |
adx |
30 |
} |
66 |
|
|
|
67 |
michael |
3308 |
/*! \brief Adds a user to a channel by adding another link to the |
68 |
adx |
30 |
* channels member chain. |
69 |
michael |
3308 |
* \param chptr Pointer to channel to add client to |
70 |
michael |
6680 |
* \param client_p Pointer to client (who) to add |
71 |
michael |
3308 |
* \param flags Flags for chanops etc |
72 |
|
|
* \param flood_ctrl Whether to count this join in flood calculations |
73 |
adx |
30 |
*/ |
74 |
|
|
void |
75 |
michael |
6680 |
add_user_to_channel(struct Channel *chptr, struct Client *client_p, |
76 |
adx |
30 |
unsigned int flags, int flood_ctrl) |
77 |
|
|
{ |
78 |
michael |
6680 |
assert(IsClient(client_p)); |
79 |
michael |
5591 |
|
80 |
adx |
30 |
if (GlobalSetOptions.joinfloodtime > 0) |
81 |
|
|
{ |
82 |
|
|
if (flood_ctrl) |
83 |
michael |
3250 |
++chptr->number_joined; |
84 |
adx |
30 |
|
85 |
|
|
chptr->number_joined -= (CurrentTime - chptr->last_join_time) * |
86 |
|
|
(((float)GlobalSetOptions.joinfloodcount) / |
87 |
|
|
(float)GlobalSetOptions.joinfloodtime); |
88 |
|
|
|
89 |
|
|
if (chptr->number_joined <= 0) |
90 |
|
|
{ |
91 |
|
|
chptr->number_joined = 0; |
92 |
|
|
ClearJoinFloodNoticed(chptr); |
93 |
|
|
} |
94 |
|
|
else if (chptr->number_joined >= GlobalSetOptions.joinfloodcount) |
95 |
|
|
{ |
96 |
|
|
chptr->number_joined = GlobalSetOptions.joinfloodcount; |
97 |
|
|
|
98 |
|
|
if (!IsSetJoinFloodNoticed(chptr)) |
99 |
|
|
{ |
100 |
|
|
SetJoinFloodNoticed(chptr); |
101 |
michael |
1618 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
102 |
adx |
30 |
"Possible Join Flooder %s on %s target: %s", |
103 |
michael |
6680 |
get_client_name(client_p, HIDE_IP), |
104 |
|
|
client_p->servptr->name, chptr->name); |
105 |
adx |
30 |
} |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
chptr->last_join_time = CurrentTime; |
109 |
|
|
} |
110 |
|
|
|
111 |
michael |
7075 |
struct Membership *member = mp_pool_get(member_pool); |
112 |
michael |
6680 |
member->client_p = client_p; |
113 |
michael |
4816 |
member->chptr = chptr; |
114 |
|
|
member->flags = flags; |
115 |
adx |
30 |
|
116 |
michael |
4816 |
dlinkAdd(member, &member->channode, &chptr->members); |
117 |
michael |
4171 |
|
118 |
michael |
6680 |
if (MyConnect(client_p)) |
119 |
michael |
4816 |
dlinkAdd(member, &member->locchannode, &chptr->locmembers); |
120 |
michael |
4171 |
|
121 |
michael |
6680 |
dlinkAdd(member, &member->usernode, &client_p->channel); |
122 |
adx |
30 |
} |
123 |
|
|
|
124 |
michael |
3308 |
/*! \brief Deletes an user from a channel by removing a link in the |
125 |
adx |
30 |
* channels member chain. |
126 |
michael |
3308 |
* \param member Pointer to Membership struct |
127 |
adx |
30 |
*/ |
128 |
|
|
void |
129 |
|
|
remove_user_from_channel(struct Membership *member) |
130 |
|
|
{ |
131 |
michael |
4976 |
struct Client *const client_p = member->client_p; |
132 |
|
|
struct Channel *const chptr = member->chptr; |
133 |
adx |
30 |
|
134 |
|
|
dlinkDelete(&member->channode, &chptr->members); |
135 |
michael |
4171 |
|
136 |
|
|
if (MyConnect(client_p)) |
137 |
|
|
dlinkDelete(&member->locchannode, &chptr->locmembers); |
138 |
|
|
|
139 |
adx |
30 |
dlinkDelete(&member->usernode, &client_p->channel); |
140 |
|
|
|
141 |
michael |
1654 |
mp_pool_release(member); |
142 |
adx |
30 |
|
143 |
michael |
1011 |
if (chptr->members.head == NULL) |
144 |
michael |
6374 |
channel_free(chptr); |
145 |
adx |
30 |
} |
146 |
|
|
|
147 |
michael |
6374 |
/* channel_send_members() |
148 |
adx |
30 |
* |
149 |
|
|
* inputs - |
150 |
|
|
* output - NONE |
151 |
|
|
* side effects - |
152 |
|
|
*/ |
153 |
|
|
static void |
154 |
michael |
6374 |
channel_send_members(struct Client *client_p, const struct Channel *chptr, |
155 |
|
|
char *modebuf, char *parabuf) |
156 |
adx |
30 |
{ |
157 |
michael |
4389 |
char buf[IRCD_BUFSIZE] = ""; |
158 |
michael |
4801 |
const dlink_node *node = NULL; |
159 |
adx |
30 |
int tlen; /* length of text to append */ |
160 |
|
|
char *t, *start; /* temp char pointer */ |
161 |
|
|
|
162 |
michael |
6781 |
start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %ju %s %s %s:", |
163 |
|
|
me.id, chptr->creationtime, |
164 |
michael |
4617 |
chptr->name, modebuf, parabuf); |
165 |
adx |
30 |
|
166 |
michael |
4801 |
DLINK_FOREACH(node, chptr->members.head) |
167 |
adx |
30 |
{ |
168 |
michael |
4816 |
const struct Membership *member = node->data; |
169 |
adx |
30 |
|
170 |
michael |
4816 |
tlen = strlen(member->client_p->id) + 1; /* +1 for space */ |
171 |
adx |
30 |
|
172 |
michael |
4816 |
if (member->flags & CHFL_CHANOP) |
173 |
michael |
3250 |
++tlen; |
174 |
michael |
4816 |
if (member->flags & CHFL_HALFOP) |
175 |
michael |
3250 |
++tlen; |
176 |
michael |
4816 |
if (member->flags & CHFL_VOICE) |
177 |
michael |
3250 |
++tlen; |
178 |
adx |
30 |
|
179 |
michael |
3250 |
/* |
180 |
|
|
* Space will be converted into CR, but we also need space for LF.. |
181 |
michael |
3783 |
* That's why we use '- 1' here -adx |
182 |
michael |
3250 |
*/ |
183 |
michael |
1330 |
if (t + tlen - buf > IRCD_BUFSIZE - 1) |
184 |
adx |
30 |
{ |
185 |
michael |
3250 |
*(t - 1) = '\0'; /* Kill the space and terminate the string */ |
186 |
adx |
30 |
sendto_one(client_p, "%s", buf); |
187 |
|
|
t = start; |
188 |
|
|
} |
189 |
|
|
|
190 |
michael |
4816 |
if (member->flags & CHFL_CHANOP) |
191 |
michael |
3140 |
*t++ = '@'; |
192 |
michael |
4816 |
if (member->flags & CHFL_HALFOP) |
193 |
michael |
3140 |
*t++ = '%'; |
194 |
michael |
4816 |
if (member->flags & CHFL_VOICE) |
195 |
adx |
356 |
*t++ = '+'; |
196 |
adx |
30 |
|
197 |
michael |
4816 |
strcpy(t, member->client_p->id); |
198 |
michael |
3135 |
|
199 |
adx |
30 |
t += strlen(t); |
200 |
|
|
*t++ = ' '; |
201 |
|
|
} |
202 |
|
|
|
203 |
michael |
3250 |
/* Should always be non-NULL unless we have a kind of persistent channels */ |
204 |
michael |
3235 |
if (chptr->members.head) |
205 |
michael |
3250 |
t--; /* Take the space out */ |
206 |
adx |
30 |
*t = '\0'; |
207 |
|
|
sendto_one(client_p, "%s", buf); |
208 |
|
|
} |
209 |
|
|
|
210 |
michael |
3308 |
/*! \brief Sends +b/+e/+I |
211 |
|
|
* \param client_p Client pointer to server |
212 |
|
|
* \param chptr Pointer to channel |
213 |
michael |
3998 |
* \param list Pointer to list of modes to send |
214 |
michael |
3308 |
* \param flag Char flag flagging type of mode. Currently this can be 'b', e' or 'I' |
215 |
adx |
30 |
*/ |
216 |
|
|
static void |
217 |
michael |
6374 |
channel_send_mask_list(struct Client *client_p, const struct Channel *chptr, |
218 |
|
|
const dlink_list *list, const char flag) |
219 |
adx |
30 |
{ |
220 |
michael |
4801 |
const dlink_node *node = NULL; |
221 |
michael |
4389 |
char mbuf[IRCD_BUFSIZE] = ""; |
222 |
michael |
3215 |
char pbuf[IRCD_BUFSIZE] = ""; |
223 |
michael |
3524 |
int tlen, mlen, cur_len; |
224 |
michael |
3144 |
char *pp = pbuf; |
225 |
adx |
30 |
|
226 |
michael |
7011 |
if (!dlink_list_length(list)) |
227 |
adx |
30 |
return; |
228 |
|
|
|
229 |
michael |
6781 |
mlen = snprintf(mbuf, sizeof(mbuf), ":%s BMASK %ju %s %c :", me.id, |
230 |
|
|
chptr->creationtime, chptr->name, flag); |
231 |
michael |
3135 |
cur_len = mlen; |
232 |
adx |
30 |
|
233 |
michael |
4801 |
DLINK_FOREACH(node, list->head) |
234 |
adx |
30 |
{ |
235 |
michael |
4816 |
const struct Ban *ban = node->data; |
236 |
adx |
30 |
|
237 |
michael |
4816 |
tlen = ban->len + 3; /* +3 for ! + @ + space */ |
238 |
adx |
30 |
|
239 |
|
|
/* |
240 |
michael |
3995 |
* Send buffer and start over if we cannot fit another ban |
241 |
adx |
30 |
*/ |
242 |
michael |
3135 |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2) |
243 |
adx |
30 |
{ |
244 |
michael |
3250 |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
245 |
michael |
4389 |
sendto_one(client_p, "%s%s", mbuf, pbuf); |
246 |
adx |
30 |
|
247 |
michael |
3135 |
cur_len = mlen; |
248 |
adx |
30 |
pp = pbuf; |
249 |
|
|
} |
250 |
|
|
|
251 |
michael |
4816 |
pp += sprintf(pp, "%s!%s@%s ", ban->name, ban->user, ban->host); |
252 |
adx |
30 |
cur_len += tlen; |
253 |
|
|
} |
254 |
|
|
|
255 |
michael |
3250 |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
256 |
michael |
4389 |
sendto_one(client_p, "%s%s", mbuf, pbuf); |
257 |
adx |
30 |
} |
258 |
|
|
|
259 |
michael |
3308 |
/*! \brief Send "client_p" a full list of the modes for channel chptr |
260 |
|
|
* \param client_p Pointer to client client_p |
261 |
|
|
* \param chptr Pointer to channel pointer |
262 |
adx |
30 |
*/ |
263 |
|
|
void |
264 |
michael |
6374 |
channel_send_modes(struct Client *client_p, struct Channel *chptr) |
265 |
adx |
30 |
{ |
266 |
michael |
3145 |
char modebuf[MODEBUFLEN] = ""; |
267 |
|
|
char parabuf[MODEBUFLEN] = ""; |
268 |
|
|
|
269 |
adx |
30 |
channel_modes(chptr, client_p, modebuf, parabuf); |
270 |
michael |
6374 |
channel_send_members(client_p, chptr, modebuf, parabuf); |
271 |
adx |
30 |
|
272 |
michael |
6374 |
channel_send_mask_list(client_p, chptr, &chptr->banlist, 'b'); |
273 |
|
|
channel_send_mask_list(client_p, chptr, &chptr->exceptlist, 'e'); |
274 |
|
|
channel_send_mask_list(client_p, chptr, &chptr->invexlist, 'I'); |
275 |
adx |
30 |
} |
276 |
|
|
|
277 |
michael |
3308 |
/*! \brief Check channel name for invalid characters |
278 |
|
|
* \param name Pointer to channel name string |
279 |
|
|
* \param local Indicates whether it's a local or remote creation |
280 |
michael |
632 |
* \return 0 if invalid, 1 otherwise |
281 |
adx |
30 |
*/ |
282 |
|
|
int |
283 |
michael |
6374 |
channel_check_name(const char *name, const int local) |
284 |
adx |
30 |
{ |
285 |
michael |
632 |
const char *p = name; |
286 |
michael |
3422 |
|
287 |
michael |
5591 |
assert(!EmptyString(p)); |
288 |
adx |
30 |
|
289 |
michael |
632 |
if (!IsChanPrefix(*p)) |
290 |
|
|
return 0; |
291 |
adx |
30 |
|
292 |
db |
633 |
if (!local || !ConfigChannel.disable_fake_channels) |
293 |
michael |
632 |
{ |
294 |
|
|
while (*++p) |
295 |
db |
634 |
if (!IsChanChar(*p)) |
296 |
michael |
632 |
return 0; |
297 |
|
|
} |
298 |
|
|
else |
299 |
|
|
{ |
300 |
|
|
while (*++p) |
301 |
db |
634 |
if (!IsVisibleChanChar(*p)) |
302 |
michael |
632 |
return 0; |
303 |
|
|
} |
304 |
|
|
|
305 |
michael |
3422 |
return p - name <= CHANNELLEN; |
306 |
adx |
30 |
} |
307 |
|
|
|
308 |
|
|
void |
309 |
michael |
4816 |
remove_ban(struct Ban *ban, dlink_list *list) |
310 |
adx |
30 |
{ |
311 |
michael |
4816 |
dlinkDelete(&ban->node, list); |
312 |
|
|
mp_pool_release(ban); |
313 |
adx |
30 |
} |
314 |
|
|
|
315 |
michael |
6374 |
/* channel_free_mask_list() |
316 |
adx |
30 |
* |
317 |
|
|
* inputs - pointer to dlink_list |
318 |
|
|
* output - NONE |
319 |
|
|
* side effects - |
320 |
|
|
*/ |
321 |
michael |
6374 |
static void |
322 |
|
|
channel_free_mask_list(dlink_list *list) |
323 |
adx |
30 |
{ |
324 |
michael |
7265 |
while (list->head) |
325 |
|
|
{ |
326 |
|
|
struct Ban *ban = list->head->data; |
327 |
|
|
remove_ban(ban, list); |
328 |
|
|
} |
329 |
adx |
30 |
} |
330 |
|
|
|
331 |
michael |
4617 |
/*! \brief Get Channel block for name (and allocate a new channel |
332 |
adx |
30 |
* block, if it didn't exist before) |
333 |
michael |
4617 |
* \param name Channel name |
334 |
michael |
3308 |
* \return Channel block |
335 |
adx |
30 |
*/ |
336 |
|
|
struct Channel * |
337 |
michael |
6374 |
channel_make(const char *name) |
338 |
adx |
30 |
{ |
339 |
|
|
struct Channel *chptr = NULL; |
340 |
|
|
|
341 |
michael |
4617 |
assert(!EmptyString(name)); |
342 |
adx |
30 |
|
343 |
michael |
1654 |
chptr = mp_pool_get(channel_pool); |
344 |
adx |
30 |
|
345 |
michael |
3308 |
/* Doesn't hurt to set it here */ |
346 |
michael |
4817 |
chptr->creationtime = CurrentTime; |
347 |
michael |
632 |
chptr->last_join_time = CurrentTime; |
348 |
adx |
30 |
|
349 |
michael |
6981 |
chptr->name_len = strlcpy(chptr->name, name, sizeof(chptr->name)); |
350 |
|
|
if (chptr->name_len >= sizeof(chptr->name)) |
351 |
|
|
chptr->name_len = sizeof(chptr->name) - 1; |
352 |
michael |
6989 |
|
353 |
michael |
3945 |
dlinkAdd(chptr, &chptr->node, &channel_list); |
354 |
adx |
30 |
hash_add_channel(chptr); |
355 |
|
|
|
356 |
|
|
return chptr; |
357 |
|
|
} |
358 |
|
|
|
359 |
michael |
3308 |
/*! \brief Walk through this channel, and destroy it. |
360 |
|
|
* \param chptr Channel pointer |
361 |
adx |
30 |
*/ |
362 |
|
|
void |
363 |
michael |
6374 |
channel_free(struct Channel *chptr) |
364 |
adx |
30 |
{ |
365 |
michael |
5851 |
clear_invites_channel(chptr); |
366 |
adx |
30 |
|
367 |
michael |
3308 |
/* Free ban/exception/invex lists */ |
368 |
michael |
6374 |
channel_free_mask_list(&chptr->banlist); |
369 |
|
|
channel_free_mask_list(&chptr->exceptlist); |
370 |
|
|
channel_free_mask_list(&chptr->invexlist); |
371 |
adx |
30 |
|
372 |
michael |
3945 |
dlinkDelete(&chptr->node, &channel_list); |
373 |
adx |
30 |
hash_del_channel(chptr); |
374 |
|
|
|
375 |
michael |
1654 |
mp_pool_release(chptr); |
376 |
adx |
30 |
} |
377 |
|
|
|
378 |
|
|
/*! |
379 |
michael |
3308 |
* \param chptr Pointer to channel |
380 |
|
|
* \return String pointer "=" if public, "@" if secret else "*" |
381 |
adx |
30 |
*/ |
382 |
|
|
static const char * |
383 |
michael |
1013 |
channel_pub_or_secret(const struct Channel *chptr) |
384 |
adx |
30 |
{ |
385 |
|
|
if (SecretChannel(chptr)) |
386 |
|
|
return "@"; |
387 |
|
|
if (PrivateChannel(chptr)) |
388 |
|
|
return "*"; |
389 |
|
|
return "="; |
390 |
|
|
} |
391 |
|
|
|
392 |
|
|
/*! \brief lists all names on given channel |
393 |
michael |
6680 |
* \param client_p Pointer to client struct requesting names |
394 |
michael |
3308 |
* \param chptr Pointer to channel block |
395 |
|
|
* \param show_eon Show RPL_ENDOFNAMES numeric or not |
396 |
adx |
30 |
* (don't want it with /names with no params) |
397 |
|
|
*/ |
398 |
|
|
void |
399 |
michael |
6680 |
channel_member_names(struct Client *client_p, struct Channel *chptr, |
400 |
adx |
30 |
int show_eon) |
401 |
|
|
{ |
402 |
michael |
4801 |
const dlink_node *node = NULL; |
403 |
michael |
4389 |
char buf[IRCD_BUFSIZE + 1] = ""; |
404 |
adx |
30 |
char *t = NULL, *start = NULL; |
405 |
|
|
int tlen = 0; |
406 |
michael |
6680 |
const int is_member = IsMember(client_p, chptr); |
407 |
|
|
const int multi_prefix = HasCap(client_p, CAP_MULTI_PREFIX) != 0; |
408 |
|
|
const int uhnames = HasCap(client_p, CAP_UHNAMES) != 0; |
409 |
adx |
30 |
|
410 |
michael |
6680 |
assert(IsClient(client_p)); |
411 |
michael |
5591 |
|
412 |
adx |
30 |
if (PubChannel(chptr) || is_member) |
413 |
|
|
{ |
414 |
michael |
4389 |
t = buf + snprintf(buf, sizeof(buf), numeric_form(RPL_NAMREPLY), |
415 |
michael |
6680 |
me.name, client_p->name, |
416 |
michael |
4617 |
channel_pub_or_secret(chptr), chptr->name); |
417 |
adx |
30 |
start = t; |
418 |
|
|
|
419 |
michael |
4801 |
DLINK_FOREACH(node, chptr->members.head) |
420 |
adx |
30 |
{ |
421 |
michael |
4816 |
const struct Membership *member = node->data; |
422 |
adx |
30 |
|
423 |
michael |
4816 |
if (HasUMode(member->client_p, UMODE_INVISIBLE) && !is_member) |
424 |
adx |
30 |
continue; |
425 |
|
|
|
426 |
michael |
2910 |
if (!uhnames) |
427 |
michael |
4816 |
tlen = strlen(member->client_p->name) + 1; /* +1 for space */ |
428 |
michael |
2910 |
else |
429 |
michael |
4816 |
tlen = strlen(member->client_p->name) + strlen(member->client_p->username) + |
430 |
|
|
strlen(member->client_p->host) + 3; /* +3 for ! + @ + space */ |
431 |
adx |
30 |
|
432 |
michael |
506 |
if (!multi_prefix) |
433 |
|
|
{ |
434 |
michael |
4816 |
if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
435 |
michael |
506 |
++tlen; |
436 |
|
|
} |
437 |
|
|
else |
438 |
|
|
{ |
439 |
michael |
4816 |
if (member->flags & CHFL_CHANOP) |
440 |
michael |
506 |
++tlen; |
441 |
michael |
4816 |
if (member->flags & CHFL_HALFOP) |
442 |
michael |
506 |
++tlen; |
443 |
michael |
4816 |
if (member->flags & CHFL_VOICE) |
444 |
michael |
506 |
++tlen; |
445 |
|
|
} |
446 |
|
|
|
447 |
michael |
4389 |
if (t + tlen - buf > IRCD_BUFSIZE - 2) |
448 |
adx |
30 |
{ |
449 |
|
|
*(t - 1) = '\0'; |
450 |
michael |
6680 |
sendto_one(client_p, "%s", buf); |
451 |
adx |
30 |
t = start; |
452 |
|
|
} |
453 |
|
|
|
454 |
michael |
2910 |
if (!uhnames) |
455 |
michael |
4816 |
t += sprintf(t, "%s%s ", get_member_status(member, multi_prefix), |
456 |
|
|
member->client_p->name); |
457 |
michael |
2910 |
else |
458 |
michael |
4816 |
t += sprintf(t, "%s%s!%s@%s ", get_member_status(member, multi_prefix), |
459 |
|
|
member->client_p->name, member->client_p->username, |
460 |
|
|
member->client_p->host); |
461 |
adx |
30 |
} |
462 |
|
|
|
463 |
michael |
3215 |
if (tlen) |
464 |
adx |
30 |
{ |
465 |
|
|
*(t - 1) = '\0'; |
466 |
michael |
6680 |
sendto_one(client_p, "%s", buf); |
467 |
adx |
30 |
} |
468 |
|
|
} |
469 |
|
|
|
470 |
|
|
if (show_eon) |
471 |
michael |
6680 |
sendto_one_numeric(client_p, &me, RPL_ENDOFNAMES, chptr->name); |
472 |
adx |
30 |
} |
473 |
|
|
|
474 |
michael |
7548 |
static struct Invite * |
475 |
|
|
find_invite(struct Channel *chptr, struct Client *client_p) |
476 |
|
|
{ |
477 |
|
|
dlink_node *node, *node_next; |
478 |
|
|
dlink_list *list; |
479 |
|
|
|
480 |
|
|
if (dlink_list_length(&client_p->connection->invited) < dlink_list_length(&chptr->invites)) |
481 |
|
|
list = &client_p->connection->invited; |
482 |
|
|
else |
483 |
|
|
list = &chptr->invites; |
484 |
|
|
|
485 |
|
|
DLINK_FOREACH_SAFE(node, node_next, list->head) |
486 |
|
|
{ |
487 |
|
|
struct Invite *invite = node->data; |
488 |
|
|
|
489 |
|
|
if (invite->chptr == chptr && invite->client_p == client_p) |
490 |
|
|
return invite; |
491 |
|
|
} |
492 |
|
|
|
493 |
|
|
return NULL; |
494 |
|
|
} |
495 |
|
|
|
496 |
michael |
3308 |
/*! \brief Adds client to invite list |
497 |
michael |
6680 |
* \param chptr Pointer to channel block |
498 |
|
|
* \param client_p Pointer to client to add invite to |
499 |
adx |
30 |
*/ |
500 |
|
|
void |
501 |
michael |
6680 |
add_invite(struct Channel *chptr, struct Client *client_p) |
502 |
adx |
30 |
{ |
503 |
michael |
7548 |
struct Invite *invite; |
504 |
michael |
5591 |
|
505 |
michael |
7548 |
if ((invite = find_invite(chptr, client_p))) |
506 |
|
|
del_invite(invite); |
507 |
adx |
30 |
|
508 |
michael |
7548 |
invite = mp_pool_get(invite_pool); |
509 |
|
|
invite->client_p = client_p; |
510 |
|
|
invite->chptr = chptr; |
511 |
|
|
invite->when = CurrentTime; |
512 |
|
|
|
513 |
michael |
7541 |
/* Delete last link in chain if the list is max length */ |
514 |
|
|
while (dlink_list_length(&client_p->connection->invited) && |
515 |
|
|
dlink_list_length(&client_p->connection->invited) >= ConfigChannel.max_channels) |
516 |
michael |
7548 |
del_invite(client_p->connection->invited.tail->data); |
517 |
adx |
30 |
|
518 |
michael |
3308 |
/* Add client to channel invite list */ |
519 |
michael |
7548 |
dlinkAdd(invite, &invite->chan_node, &chptr->invites); |
520 |
adx |
30 |
|
521 |
michael |
3308 |
/* Add channel to the end of the client invite list */ |
522 |
michael |
7548 |
dlinkAdd(invite, &invite->user_node, &client_p->connection->invited); |
523 |
adx |
30 |
} |
524 |
|
|
|
525 |
|
|
/*! \brief Delete Invite block from channel invite list |
526 |
|
|
* and client invite list |
527 |
michael |
7548 |
* \param invite Pointer to Invite struct |
528 |
adx |
30 |
*/ |
529 |
|
|
void |
530 |
michael |
7548 |
del_invite(struct Invite *invite) |
531 |
adx |
30 |
{ |
532 |
michael |
7548 |
dlinkDelete(&invite->user_node, &invite->client_p->connection->invited); |
533 |
|
|
dlinkDelete(&invite->chan_node, &invite->chptr->invites); |
534 |
adx |
30 |
|
535 |
michael |
7548 |
/* Release memory pointed to by 'invite' */ |
536 |
|
|
mp_pool_release(invite); |
537 |
adx |
30 |
} |
538 |
|
|
|
539 |
michael |
4812 |
/*! \brief Removes all invites of a specific channel |
540 |
|
|
* \param chptr Pointer to Channel struct |
541 |
|
|
*/ |
542 |
|
|
void |
543 |
michael |
5851 |
clear_invites_channel(struct Channel *chptr) |
544 |
michael |
4812 |
{ |
545 |
michael |
7548 |
while (chptr->invites.head) |
546 |
|
|
del_invite(chptr->invites.head->data); |
547 |
michael |
4812 |
} |
548 |
|
|
|
549 |
michael |
5854 |
/*! \brief Removes all invites of a specific client |
550 |
michael |
6680 |
* \param client_p Pointer to Client struct |
551 |
michael |
5854 |
*/ |
552 |
michael |
5851 |
void |
553 |
michael |
6680 |
clear_invites_client(struct Client *client_p) |
554 |
michael |
5851 |
{ |
555 |
michael |
7548 |
while (client_p->connection->invited.head) |
556 |
|
|
del_invite(client_p->connection->invited.head->data); |
557 |
michael |
5851 |
} |
558 |
|
|
|
559 |
adx |
30 |
/* get_member_status() |
560 |
|
|
* |
561 |
|
|
* inputs - pointer to struct Membership |
562 |
|
|
* - YES if we can combine different flags |
563 |
|
|
* output - string either @, +, % or "" depending on whether |
564 |
|
|
* chanop, voiced or user |
565 |
|
|
* side effects - |
566 |
|
|
* |
567 |
|
|
* NOTE: Returned string is usually a static buffer |
568 |
|
|
* (like in get_client_name) |
569 |
|
|
*/ |
570 |
|
|
const char * |
571 |
michael |
4816 |
get_member_status(const struct Membership *member, const int combine) |
572 |
adx |
30 |
{ |
573 |
michael |
6902 |
static char buffer[CMEMBER_STATUS_FLAGS_LEN + 1]; /* +1 for \0 */ |
574 |
michael |
1902 |
char *p = buffer; |
575 |
adx |
30 |
|
576 |
michael |
4816 |
if (member->flags & CHFL_CHANOP) |
577 |
adx |
30 |
{ |
578 |
|
|
if (!combine) |
579 |
|
|
return "@"; |
580 |
|
|
*p++ = '@'; |
581 |
|
|
} |
582 |
|
|
|
583 |
michael |
4816 |
if (member->flags & CHFL_HALFOP) |
584 |
adx |
30 |
{ |
585 |
|
|
if (!combine) |
586 |
|
|
return "%"; |
587 |
|
|
*p++ = '%'; |
588 |
|
|
} |
589 |
|
|
|
590 |
michael |
4816 |
if (member->flags & CHFL_VOICE) |
591 |
adx |
30 |
*p++ = '+'; |
592 |
|
|
*p = '\0'; |
593 |
|
|
|
594 |
|
|
return buffer; |
595 |
|
|
} |
596 |
|
|
|
597 |
|
|
/*! |
598 |
michael |
6680 |
* \param client_p Pointer to Client to check |
599 |
|
|
* \param list Pointer to ban list to search |
600 |
adx |
30 |
* \return 1 if ban found for given n!u\@h mask, 0 otherwise |
601 |
|
|
*/ |
602 |
|
|
static int |
603 |
michael |
7346 |
find_bmask(const struct Client *client_p, const dlink_list *list) |
604 |
adx |
30 |
{ |
605 |
michael |
4801 |
const dlink_node *node = NULL; |
606 |
adx |
30 |
|
607 |
michael |
4801 |
DLINK_FOREACH(node, list->head) |
608 |
adx |
30 |
{ |
609 |
michael |
4816 |
const struct Ban *ban = node->data; |
610 |
adx |
30 |
|
611 |
michael |
6680 |
if (!match(ban->name, client_p->name) && !match(ban->user, client_p->username)) |
612 |
michael |
371 |
{ |
613 |
michael |
4816 |
switch (ban->type) |
614 |
michael |
371 |
{ |
615 |
|
|
case HM_HOST: |
616 |
michael |
6680 |
if (!match(ban->host, client_p->host) || !match(ban->host, client_p->sockhost)) |
617 |
michael |
371 |
return 1; |
618 |
|
|
break; |
619 |
|
|
case HM_IPV4: |
620 |
michael |
6680 |
if (client_p->connection->aftype == AF_INET) |
621 |
|
|
if (match_ipv4(&client_p->connection->ip, &ban->addr, ban->bits)) |
622 |
michael |
371 |
return 1; |
623 |
|
|
break; |
624 |
|
|
case HM_IPV6: |
625 |
michael |
6680 |
if (client_p->connection->aftype == AF_INET6) |
626 |
|
|
if (match_ipv6(&client_p->connection->ip, &ban->addr, ban->bits)) |
627 |
michael |
371 |
return 1; |
628 |
|
|
break; |
629 |
|
|
default: |
630 |
|
|
assert(0); |
631 |
|
|
} |
632 |
|
|
} |
633 |
adx |
30 |
} |
634 |
|
|
|
635 |
|
|
return 0; |
636 |
|
|
} |
637 |
|
|
|
638 |
|
|
/*! |
639 |
michael |
6680 |
* \param chptr Pointer to channel block |
640 |
|
|
* \param client_p Pointer to client to check access fo |
641 |
adx |
30 |
* \return 0 if not banned, 1 otherwise |
642 |
|
|
*/ |
643 |
|
|
int |
644 |
michael |
6680 |
is_banned(const struct Channel *chptr, const struct Client *client_p) |
645 |
adx |
30 |
{ |
646 |
michael |
6680 |
if (find_bmask(client_p, &chptr->banlist)) |
647 |
|
|
if (!find_bmask(client_p, &chptr->exceptlist)) |
648 |
michael |
632 |
return 1; |
649 |
adx |
30 |
|
650 |
michael |
632 |
return 0; |
651 |
adx |
30 |
} |
652 |
|
|
|
653 |
michael |
3308 |
/*! Tests if a client can join a certain channel |
654 |
michael |
6680 |
* \param client_p Pointer to client attempting to join |
655 |
michael |
3308 |
* \param chptr Pointer to channel |
656 |
|
|
* \param key Key sent by client attempting to join if present |
657 |
adx |
30 |
* \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL |
658 |
|
|
* or 0 if allowed to join. |
659 |
|
|
*/ |
660 |
michael |
6882 |
static int |
661 |
michael |
7548 |
can_join(struct Client *client_p, struct Channel *chptr, const char *key) |
662 |
adx |
30 |
{ |
663 |
michael |
6680 |
if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(client_p, UMODE_SSL)) |
664 |
michael |
1150 |
return ERR_SSLONLYCHAN; |
665 |
|
|
|
666 |
michael |
6680 |
if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(client_p, UMODE_REGISTERED)) |
667 |
michael |
1173 |
return ERR_NEEDREGGEDNICK; |
668 |
|
|
|
669 |
michael |
6680 |
if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(client_p, UMODE_OPER)) |
670 |
michael |
1150 |
return ERR_OPERONLYCHAN; |
671 |
|
|
|
672 |
adx |
30 |
if (chptr->mode.mode & MODE_INVITEONLY) |
673 |
michael |
7548 |
if (!find_invite(chptr, client_p)) |
674 |
michael |
6680 |
if (!find_bmask(client_p, &chptr->invexlist)) |
675 |
adx |
30 |
return ERR_INVITEONLYCHAN; |
676 |
|
|
|
677 |
michael |
1430 |
if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key))) |
678 |
adx |
30 |
return ERR_BADCHANNELKEY; |
679 |
|
|
|
680 |
|
|
if (chptr->mode.limit && dlink_list_length(&chptr->members) >= |
681 |
|
|
chptr->mode.limit) |
682 |
|
|
return ERR_CHANNELISFULL; |
683 |
|
|
|
684 |
michael |
6680 |
if (is_banned(chptr, client_p)) |
685 |
michael |
2208 |
return ERR_BANNEDFROMCHAN; |
686 |
|
|
|
687 |
michael |
1834 |
return 0; |
688 |
adx |
30 |
} |
689 |
|
|
|
690 |
|
|
int |
691 |
michael |
4816 |
has_member_flags(const struct Membership *member, const unsigned int flags) |
692 |
adx |
30 |
{ |
693 |
michael |
4816 |
return member && (member->flags & flags); |
694 |
adx |
30 |
} |
695 |
|
|
|
696 |
|
|
struct Membership * |
697 |
|
|
find_channel_link(struct Client *client_p, struct Channel *chptr) |
698 |
|
|
{ |
699 |
michael |
4801 |
dlink_node *node = NULL; |
700 |
adx |
30 |
|
701 |
|
|
if (!IsClient(client_p)) |
702 |
|
|
return NULL; |
703 |
|
|
|
704 |
michael |
2567 |
if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel)) |
705 |
|
|
{ |
706 |
michael |
4801 |
DLINK_FOREACH(node, chptr->members.head) |
707 |
|
|
if (((struct Membership *)node->data)->client_p == client_p) |
708 |
|
|
return node->data; |
709 |
michael |
2567 |
} |
710 |
|
|
else |
711 |
|
|
{ |
712 |
michael |
4801 |
DLINK_FOREACH(node, client_p->channel.head) |
713 |
|
|
if (((struct Membership *)node->data)->chptr == chptr) |
714 |
|
|
return node->data; |
715 |
michael |
2567 |
} |
716 |
adx |
30 |
|
717 |
|
|
return NULL; |
718 |
|
|
} |
719 |
|
|
|
720 |
michael |
4782 |
/*! Checks if a message contains control codes |
721 |
michael |
3889 |
* \param message The actual message string the client wants to send |
722 |
|
|
* \return 1 if the message does contain any control codes, 0 otherwise |
723 |
michael |
1937 |
*/ |
724 |
|
|
static int |
725 |
|
|
msg_has_ctrls(const char *message) |
726 |
|
|
{ |
727 |
|
|
const unsigned char *p = (const unsigned char *)message; |
728 |
|
|
|
729 |
|
|
for (; *p; ++p) |
730 |
|
|
{ |
731 |
|
|
if (*p > 31 || *p == 1) |
732 |
michael |
3953 |
continue; /* No control code or CTCP */ |
733 |
michael |
1937 |
|
734 |
michael |
3889 |
if (*p == 27) /* Escape */ |
735 |
michael |
1937 |
{ |
736 |
michael |
3889 |
/* ISO 2022 charset shift sequence */ |
737 |
michael |
1937 |
if (*(p + 1) == '$' || |
738 |
|
|
*(p + 1) == '(') |
739 |
|
|
{ |
740 |
|
|
++p; |
741 |
|
|
continue; |
742 |
|
|
} |
743 |
|
|
} |
744 |
|
|
|
745 |
michael |
3889 |
return 1; /* Control code */ |
746 |
michael |
1937 |
} |
747 |
|
|
|
748 |
michael |
4782 |
return 0; /* No control code found */ |
749 |
michael |
1937 |
} |
750 |
|
|
|
751 |
michael |
3308 |
/*! Tests if a client can send to a channel |
752 |
|
|
* \param chptr Pointer to Channel struct |
753 |
michael |
6680 |
* \param client_p Pointer to Client struct |
754 |
michael |
4816 |
* \param member Pointer to Membership struct (can be NULL) |
755 |
michael |
3308 |
* \param message The actual message string the client wants to send |
756 |
adx |
30 |
* \return CAN_SEND_OPV if op or voiced on channel\n |
757 |
|
|
* CAN_SEND_NONOP if can send to channel but is not an op\n |
758 |
michael |
1173 |
* ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n |
759 |
adx |
30 |
*/ |
760 |
|
|
int |
761 |
michael |
6680 |
can_send(struct Channel *chptr, struct Client *client_p, |
762 |
michael |
6918 |
struct Membership *member, const char *message, int notice) |
763 |
adx |
30 |
{ |
764 |
michael |
7281 |
const struct ResvItem *resv = NULL; |
765 |
michael |
1858 |
|
766 |
michael |
6680 |
if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE)) |
767 |
adx |
30 |
return CAN_SEND_OPV; |
768 |
|
|
|
769 |
michael |
7053 |
if (MyConnect(client_p) && !HasFlag(client_p, FLAGS_EXEMPTRESV)) |
770 |
michael |
6680 |
if (!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV))) |
771 |
michael |
7281 |
if ((resv = resv_find(chptr->name, match)) && !resv_exempt_find(client_p, resv)) |
772 |
michael |
1834 |
return ERR_CANNOTSENDTOCHAN; |
773 |
adx |
30 |
|
774 |
michael |
1944 |
if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message)) |
775 |
|
|
return ERR_NOCTRLSONCHAN; |
776 |
michael |
4883 |
|
777 |
michael |
5463 |
if (chptr->mode.mode & MODE_NOCTCP) |
778 |
michael |
5466 |
if (*message == '\001' && strncmp(message + 1, "ACTION ", 7)) |
779 |
michael |
5463 |
return ERR_NOCTCP; |
780 |
|
|
|
781 |
michael |
6680 |
if (member || (member = find_channel_link(client_p, chptr))) |
782 |
michael |
5582 |
if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
783 |
adx |
30 |
return CAN_SEND_OPV; |
784 |
michael |
4883 |
|
785 |
michael |
4816 |
if (!member && (chptr->mode.mode & MODE_NOPRIVMSGS)) |
786 |
michael |
2441 |
return ERR_CANNOTSENDTOCHAN; |
787 |
michael |
4883 |
|
788 |
michael |
1944 |
if (chptr->mode.mode & MODE_MODERATED) |
789 |
|
|
return ERR_CANNOTSENDTOCHAN; |
790 |
michael |
4883 |
|
791 |
michael |
6680 |
if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(client_p, UMODE_REGISTERED)) |
792 |
michael |
1944 |
return ERR_NEEDREGGEDNICK; |
793 |
adx |
30 |
|
794 |
michael |
6918 |
if ((chptr->mode.mode & MODE_NONOTICE) && notice) |
795 |
|
|
return ERR_CANNOTSENDTOCHAN; |
796 |
|
|
|
797 |
michael |
3308 |
/* Cache can send if banned */ |
798 |
michael |
7053 |
if (MyConnect(client_p)) |
799 |
michael |
1944 |
{ |
800 |
michael |
4816 |
if (member) |
801 |
adx |
30 |
{ |
802 |
michael |
4816 |
if (member->flags & CHFL_BAN_SILENCED) |
803 |
michael |
1834 |
return ERR_CANNOTSENDTOCHAN; |
804 |
adx |
30 |
|
805 |
michael |
4816 |
if (!(member->flags & CHFL_BAN_CHECKED)) |
806 |
adx |
30 |
{ |
807 |
michael |
6680 |
if (is_banned(chptr, client_p)) |
808 |
adx |
30 |
{ |
809 |
michael |
5582 |
member->flags |= (CHFL_BAN_CHECKED | CHFL_BAN_SILENCED); |
810 |
michael |
1834 |
return ERR_CANNOTSENDTOCHAN; |
811 |
adx |
30 |
} |
812 |
|
|
|
813 |
michael |
4816 |
member->flags |= CHFL_BAN_CHECKED; |
814 |
adx |
30 |
} |
815 |
|
|
} |
816 |
michael |
6680 |
else if (is_banned(chptr, client_p)) |
817 |
michael |
1941 |
return ERR_CANNOTSENDTOCHAN; |
818 |
|
|
} |
819 |
adx |
30 |
|
820 |
|
|
return CAN_SEND_NONOP; |
821 |
|
|
} |
822 |
|
|
|
823 |
|
|
/*! \brief Updates the client's oper_warn_count_down, warns the |
824 |
|
|
* IRC operators if necessary, and updates |
825 |
|
|
* join_leave_countdown as needed. |
826 |
michael |
6683 |
* \param client_p Pointer to struct Client to check |
827 |
michael |
3308 |
* \param name Channel name or NULL if this is a part. |
828 |
adx |
30 |
*/ |
829 |
|
|
void |
830 |
michael |
6683 |
check_spambot_warning(struct Client *client_p, const char *name) |
831 |
adx |
30 |
{ |
832 |
|
|
int t_delta = 0; |
833 |
|
|
int decrement_count = 0; |
834 |
|
|
|
835 |
|
|
if ((GlobalSetOptions.spam_num && |
836 |
michael |
6683 |
(client_p->connection->join_leave_count >= |
837 |
adx |
30 |
GlobalSetOptions.spam_num))) |
838 |
|
|
{ |
839 |
michael |
6683 |
if (client_p->connection->oper_warn_count_down > 0) |
840 |
|
|
client_p->connection->oper_warn_count_down--; |
841 |
adx |
30 |
else |
842 |
michael |
6683 |
client_p->connection->oper_warn_count_down = 0; |
843 |
adx |
30 |
|
844 |
michael |
6683 |
if (client_p->connection->oper_warn_count_down == 0) |
845 |
adx |
30 |
{ |
846 |
michael |
3308 |
/* It's already known as a possible spambot */ |
847 |
michael |
3235 |
if (name) |
848 |
michael |
1618 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
849 |
adx |
30 |
"User %s (%s@%s) trying to join %s is a possible spambot", |
850 |
michael |
6683 |
client_p->name, client_p->username, |
851 |
|
|
client_p->host, name); |
852 |
adx |
30 |
else |
853 |
michael |
1618 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
854 |
adx |
30 |
"User %s (%s@%s) is a possible spambot", |
855 |
michael |
6683 |
client_p->name, client_p->username, |
856 |
|
|
client_p->host); |
857 |
|
|
client_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN; |
858 |
adx |
30 |
} |
859 |
|
|
} |
860 |
|
|
else |
861 |
|
|
{ |
862 |
michael |
6683 |
if ((t_delta = (CurrentTime - client_p->connection->last_leave_time)) > |
863 |
adx |
30 |
JOIN_LEAVE_COUNT_EXPIRE_TIME) |
864 |
|
|
{ |
865 |
|
|
decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); |
866 |
michael |
4883 |
|
867 |
michael |
6683 |
if (decrement_count > client_p->connection->join_leave_count) |
868 |
|
|
client_p->connection->join_leave_count = 0; |
869 |
adx |
30 |
else |
870 |
michael |
6683 |
client_p->connection->join_leave_count -= decrement_count; |
871 |
adx |
30 |
} |
872 |
|
|
else |
873 |
|
|
{ |
874 |
michael |
6683 |
if ((CurrentTime - (client_p->connection->last_join_time)) < |
875 |
adx |
30 |
GlobalSetOptions.spam_time) |
876 |
michael |
6683 |
client_p->connection->join_leave_count++; /* It's a possible spambot */ |
877 |
adx |
30 |
} |
878 |
|
|
|
879 |
michael |
3215 |
if (name) |
880 |
michael |
6683 |
client_p->connection->last_join_time = CurrentTime; |
881 |
adx |
30 |
else |
882 |
michael |
6683 |
client_p->connection->last_leave_time = CurrentTime; |
883 |
adx |
30 |
} |
884 |
|
|
} |
885 |
|
|
|
886 |
michael |
3308 |
/*! \brief Sets the channel topic for a certain channel |
887 |
adx |
30 |
* \param chptr Pointer to struct Channel |
888 |
|
|
* \param topic The topic string |
889 |
|
|
* \param topic_info n!u\@h formatted string of the topic setter |
890 |
michael |
3308 |
* \param topicts Timestamp on the topic |
891 |
|
|
* \param local Whether the topic is set by a local client |
892 |
adx |
30 |
*/ |
893 |
|
|
void |
894 |
michael |
3940 |
channel_set_topic(struct Channel *chptr, const char *topic, |
895 |
michael |
7329 |
const char *topic_info, uintmax_t topicts, int local) |
896 |
adx |
30 |
{ |
897 |
michael |
1751 |
if (local) |
898 |
michael |
4341 |
strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ConfigServerInfo.max_topic_length + 1)); |
899 |
michael |
1751 |
else |
900 |
|
|
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
901 |
|
|
|
902 |
michael |
1203 |
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
903 |
michael |
2345 |
chptr->topic_time = topicts; |
904 |
adx |
30 |
} |
905 |
michael |
3913 |
|
906 |
|
|
/* do_join_0() |
907 |
|
|
* |
908 |
|
|
* inputs - pointer to client doing join 0 |
909 |
|
|
* output - NONE |
910 |
|
|
* side effects - Use has decided to join 0. This is legacy |
911 |
|
|
* from the days when channels were numbers not names. *sigh* |
912 |
|
|
* There is a bunch of evilness necessary here due to |
913 |
|
|
* anti spambot code. |
914 |
|
|
*/ |
915 |
|
|
void |
916 |
michael |
6683 |
channel_do_join_0(struct Client *client_p) |
917 |
michael |
3913 |
{ |
918 |
michael |
6683 |
if (client_p->channel.head) |
919 |
|
|
if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER)) |
920 |
|
|
check_spambot_warning(client_p, NULL); |
921 |
michael |
3913 |
|
922 |
michael |
7265 |
while (client_p->channel.head) |
923 |
michael |
3913 |
{ |
924 |
michael |
7265 |
struct Membership *member = client_p->channel.head->data; |
925 |
michael |
3913 |
|
926 |
michael |
6683 |
sendto_server(client_p, 0, 0, ":%s PART %s", |
927 |
michael |
7265 |
client_p->id, member->chptr->name); |
928 |
|
|
sendto_channel_local(NULL, member->chptr, 0, 0, 0, ":%s!%s@%s PART %s", |
929 |
michael |
6683 |
client_p->name, client_p->username, |
930 |
michael |
7265 |
client_p->host, member->chptr->name); |
931 |
michael |
3913 |
|
932 |
michael |
7265 |
remove_user_from_channel(member); |
933 |
michael |
3913 |
} |
934 |
|
|
} |
935 |
|
|
|
936 |
|
|
static char * |
937 |
michael |
6683 |
channel_find_last0(struct Client *client_p, char *chanlist) |
938 |
michael |
3913 |
{ |
939 |
|
|
int join0 = 0; |
940 |
|
|
|
941 |
|
|
for (char *p = chanlist; *p; ++p) /* Find last "JOIN 0" */ |
942 |
|
|
{ |
943 |
|
|
if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0')) |
944 |
|
|
{ |
945 |
michael |
4757 |
if (*(p + 1) == ',') |
946 |
michael |
3913 |
++p; |
947 |
|
|
|
948 |
|
|
chanlist = p + 1; |
949 |
|
|
join0 = 1; |
950 |
|
|
} |
951 |
|
|
else |
952 |
|
|
{ |
953 |
|
|
while (*p != ',' && *p != '\0') /* Skip past channel name */ |
954 |
|
|
++p; |
955 |
|
|
|
956 |
|
|
if (*p == '\0') /* Hit the end */ |
957 |
|
|
break; |
958 |
|
|
} |
959 |
|
|
} |
960 |
|
|
|
961 |
|
|
if (join0) |
962 |
michael |
6683 |
channel_do_join_0(client_p); |
963 |
michael |
3913 |
|
964 |
|
|
return chanlist; |
965 |
|
|
} |
966 |
|
|
|
967 |
|
|
void |
968 |
michael |
6683 |
channel_do_join(struct Client *client_p, char *channel, char *key_list) |
969 |
michael |
3913 |
{ |
970 |
|
|
char *p = NULL; |
971 |
|
|
char *chan_list = NULL; |
972 |
|
|
struct Channel *chptr = NULL; |
973 |
michael |
7281 |
const struct ResvItem *resv = NULL; |
974 |
michael |
6683 |
const struct ClassItem *const class = get_class_ptr(&client_p->connection->confs); |
975 |
michael |
3913 |
unsigned int flags = 0; |
976 |
|
|
|
977 |
michael |
6683 |
assert(IsClient(client_p)); |
978 |
michael |
5591 |
|
979 |
michael |
6683 |
chan_list = channel_find_last0(client_p, channel); |
980 |
michael |
3913 |
|
981 |
michael |
7543 |
for (const char *chan = strtok_r(chan_list, ",", &p); chan; |
982 |
|
|
chan = strtok_r(NULL, ",", &p)) |
983 |
michael |
3913 |
{ |
984 |
|
|
const char *key = NULL; |
985 |
|
|
|
986 |
|
|
/* If we have any more keys, take the first for this channel. */ |
987 |
|
|
if (!EmptyString(key_list) && (key_list = strchr(key = key_list, ','))) |
988 |
|
|
*key_list++ = '\0'; |
989 |
|
|
|
990 |
|
|
/* Empty keys are the same as no keys. */ |
991 |
|
|
if (key && *key == '\0') |
992 |
|
|
key = NULL; |
993 |
|
|
|
994 |
michael |
6374 |
if (!channel_check_name(chan, 1)) |
995 |
michael |
3913 |
{ |
996 |
michael |
6683 |
sendto_one_numeric(client_p, &me, ERR_BADCHANNAME, chan); |
997 |
michael |
3913 |
continue; |
998 |
|
|
} |
999 |
|
|
|
1000 |
michael |
6683 |
if (!HasFlag(client_p, FLAGS_EXEMPTRESV) && |
1001 |
|
|
!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)) && |
1002 |
michael |
7281 |
((resv = resv_find(chan, match)) && !resv_exempt_find(client_p, resv))) |
1003 |
michael |
3913 |
{ |
1004 |
michael |
7281 |
sendto_one_numeric(client_p, &me, ERR_CHANBANREASON, chan, resv->reason); |
1005 |
michael |
4152 |
sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, |
1006 |
michael |
3913 |
"Forbidding reserved channel %s from user %s", |
1007 |
michael |
6683 |
chan, get_client_name(client_p, HIDE_IP)); |
1008 |
michael |
3913 |
continue; |
1009 |
|
|
} |
1010 |
|
|
|
1011 |
michael |
6683 |
if (dlink_list_length(&client_p->channel) >= |
1012 |
michael |
3934 |
((class->max_channels) ? class->max_channels : ConfigChannel.max_channels)) |
1013 |
michael |
3913 |
{ |
1014 |
michael |
6683 |
sendto_one_numeric(client_p, &me, ERR_TOOMANYCHANNELS, chan); |
1015 |
michael |
3913 |
break; |
1016 |
|
|
} |
1017 |
|
|
|
1018 |
|
|
if ((chptr = hash_find_channel(chan))) |
1019 |
|
|
{ |
1020 |
michael |
6683 |
if (IsMember(client_p, chptr)) |
1021 |
michael |
3913 |
continue; |
1022 |
|
|
|
1023 |
michael |
7556 |
/* can_join() checks for +i, +l, key, bans, etc. */ |
1024 |
|
|
int ret = can_join(client_p, chptr, key); |
1025 |
|
|
if (ret) |
1026 |
michael |
3913 |
{ |
1027 |
michael |
7556 |
sendto_one_numeric(client_p, &me, ret, chptr->name); |
1028 |
michael |
3913 |
continue; |
1029 |
|
|
} |
1030 |
|
|
|
1031 |
|
|
/* |
1032 |
|
|
* This should never be the case unless there is some sort of |
1033 |
|
|
* persistant channels. |
1034 |
|
|
*/ |
1035 |
michael |
4976 |
if (!dlink_list_length(&chptr->members)) |
1036 |
michael |
3913 |
flags = CHFL_CHANOP; |
1037 |
|
|
else |
1038 |
|
|
flags = 0; |
1039 |
|
|
} |
1040 |
|
|
else |
1041 |
|
|
{ |
1042 |
|
|
flags = CHFL_CHANOP; |
1043 |
michael |
6374 |
chptr = channel_make(chan); |
1044 |
michael |
3913 |
} |
1045 |
|
|
|
1046 |
michael |
6683 |
if (!HasUMode(client_p, UMODE_OPER)) |
1047 |
|
|
check_spambot_warning(client_p, chptr->name); |
1048 |
michael |
3913 |
|
1049 |
michael |
6683 |
add_user_to_channel(chptr, client_p, flags, 1); |
1050 |
michael |
3913 |
|
1051 |
|
|
/* |
1052 |
michael |
5546 |
* Set timestamp if appropriate, and propagate |
1053 |
michael |
3913 |
*/ |
1054 |
|
|
if (flags == CHFL_CHANOP) |
1055 |
|
|
{ |
1056 |
michael |
4817 |
chptr->creationtime = CurrentTime; |
1057 |
michael |
3913 |
chptr->mode.mode |= MODE_TOPICLIMIT; |
1058 |
|
|
chptr->mode.mode |= MODE_NOPRIVMSGS; |
1059 |
|
|
|
1060 |
michael |
6781 |
sendto_server(client_p, 0, 0, ":%s SJOIN %ju %s +nt :@%s", |
1061 |
|
|
me.id, chptr->creationtime, |
1062 |
michael |
6683 |
chptr->name, client_p->id); |
1063 |
michael |
3913 |
|
1064 |
|
|
/* |
1065 |
|
|
* Notify all other users on the new channel |
1066 |
|
|
*/ |
1067 |
michael |
6760 |
sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s", |
1068 |
|
|
client_p->name, client_p->username, |
1069 |
michael |
6920 |
client_p->host, chptr->name, client_p->account, client_p->info); |
1070 |
michael |
6760 |
sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s", |
1071 |
|
|
client_p->name, client_p->username, |
1072 |
|
|
client_p->host, chptr->name); |
1073 |
|
|
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s MODE %s +nt", |
1074 |
michael |
4617 |
me.name, chptr->name); |
1075 |
michael |
3913 |
|
1076 |
michael |
6683 |
if (client_p->away[0]) |
1077 |
michael |
6760 |
sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0, |
1078 |
|
|
":%s!%s@%s AWAY :%s", |
1079 |
|
|
client_p->name, client_p->username, |
1080 |
|
|
client_p->host, client_p->away); |
1081 |
michael |
3913 |
} |
1082 |
|
|
else |
1083 |
|
|
{ |
1084 |
michael |
6781 |
sendto_server(client_p, 0, 0, ":%s JOIN %ju %s +", |
1085 |
|
|
client_p->id, chptr->creationtime, |
1086 |
michael |
4617 |
chptr->name); |
1087 |
michael |
3913 |
|
1088 |
michael |
6760 |
sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s", |
1089 |
|
|
client_p->name, client_p->username, |
1090 |
michael |
6920 |
client_p->host, chptr->name, client_p->account, client_p->info); |
1091 |
michael |
6760 |
sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s", |
1092 |
|
|
client_p->name, client_p->username, |
1093 |
|
|
client_p->host, chptr->name); |
1094 |
michael |
4793 |
|
1095 |
michael |
6683 |
if (client_p->away[0]) |
1096 |
michael |
6760 |
sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0, |
1097 |
|
|
":%s!%s@%s AWAY :%s", |
1098 |
|
|
client_p->name, client_p->username, |
1099 |
|
|
client_p->host, client_p->away); |
1100 |
michael |
3913 |
} |
1101 |
|
|
|
1102 |
michael |
7548 |
struct Invite *invite = find_invite(chptr, client_p); |
1103 |
|
|
if (invite) |
1104 |
|
|
del_invite(invite); |
1105 |
michael |
3913 |
|
1106 |
|
|
if (chptr->topic[0]) |
1107 |
|
|
{ |
1108 |
michael |
6683 |
sendto_one_numeric(client_p, &me, RPL_TOPIC, chptr->name, chptr->topic); |
1109 |
|
|
sendto_one_numeric(client_p, &me, RPL_TOPICWHOTIME, chptr->name, |
1110 |
michael |
3913 |
chptr->topic_info, chptr->topic_time); |
1111 |
|
|
} |
1112 |
|
|
|
1113 |
michael |
6683 |
channel_member_names(client_p, chptr, 1); |
1114 |
michael |
3913 |
|
1115 |
michael |
6683 |
client_p->connection->last_join_time = CurrentTime; |
1116 |
michael |
3913 |
} |
1117 |
|
|
} |
1118 |
|
|
|
1119 |
|
|
/*! \brief Removes a client from a specific channel |
1120 |
michael |
7611 |
* \param client_p Pointer to client to remove |
1121 |
michael |
3913 |
* \param name Name of channel to remove from |
1122 |
|
|
* \param reason Part reason to show |
1123 |
|
|
*/ |
1124 |
|
|
static void |
1125 |
michael |
6683 |
channel_part_one_client(struct Client *client_p, const char *name, const char *reason) |
1126 |
michael |
3913 |
{ |
1127 |
|
|
struct Channel *chptr = NULL; |
1128 |
michael |
4816 |
struct Membership *member = NULL; |
1129 |
michael |
3913 |
|
1130 |
|
|
if ((chptr = hash_find_channel(name)) == NULL) |
1131 |
|
|
{ |
1132 |
michael |
6683 |
sendto_one_numeric(client_p, &me, ERR_NOSUCHCHANNEL, name); |
1133 |
michael |
3913 |
return; |
1134 |
|
|
} |
1135 |
|
|
|
1136 |
michael |
6683 |
if ((member = find_channel_link(client_p, chptr)) == NULL) |
1137 |
michael |
3913 |
{ |
1138 |
michael |
6683 |
sendto_one_numeric(client_p, &me, ERR_NOTONCHANNEL, chptr->name); |
1139 |
michael |
3913 |
return; |
1140 |
|
|
} |
1141 |
|
|
|
1142 |
michael |
6683 |
if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER)) |
1143 |
|
|
check_spambot_warning(client_p, NULL); |
1144 |
michael |
3913 |
|
1145 |
|
|
/* |
1146 |
|
|
* Remove user from the old channel (if any) |
1147 |
|
|
* only allow /part reasons in -m chans |
1148 |
|
|
*/ |
1149 |
michael |
6683 |
if (*reason && (!MyConnect(client_p) || |
1150 |
michael |
6907 |
((client_p->connection->firsttime + |
1151 |
|
|
ConfigGeneral.anti_spam_exit_message_time) < CurrentTime && |
1152 |
michael |
6918 |
can_send(chptr, client_p, member, reason, 0) < 0))) |
1153 |
michael |
3913 |
{ |
1154 |
michael |
6683 |
sendto_server(client_p, 0, 0, ":%s PART %s :%s", |
1155 |
|
|
client_p->id, chptr->name, reason); |
1156 |
michael |
6760 |
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s :%s", |
1157 |
michael |
6683 |
client_p->name, client_p->username, |
1158 |
|
|
client_p->host, chptr->name, reason); |
1159 |
michael |
3913 |
} |
1160 |
|
|
else |
1161 |
|
|
{ |
1162 |
michael |
6683 |
sendto_server(client_p, 0, 0, ":%s PART %s", |
1163 |
|
|
client_p->id, chptr->name); |
1164 |
michael |
6760 |
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s", |
1165 |
michael |
6683 |
client_p->name, client_p->username, |
1166 |
|
|
client_p->host, chptr->name); |
1167 |
michael |
3913 |
} |
1168 |
|
|
|
1169 |
michael |
4816 |
remove_user_from_channel(member); |
1170 |
michael |
3913 |
} |
1171 |
|
|
|
1172 |
|
|
void |
1173 |
michael |
6683 |
channel_do_part(struct Client *client_p, char *channel, const char *reason) |
1174 |
michael |
3913 |
{ |
1175 |
|
|
char *p = NULL, *name = NULL; |
1176 |
michael |
4784 |
char buf[KICKLEN + 1] = ""; |
1177 |
michael |
3913 |
|
1178 |
michael |
6683 |
assert(IsClient(client_p)); |
1179 |
michael |
5591 |
|
1180 |
michael |
3936 |
if (!EmptyString(reason)) |
1181 |
michael |
4784 |
strlcpy(buf, reason, sizeof(buf)); |
1182 |
michael |
3913 |
|
1183 |
michael |
6545 |
for (name = strtok_r(channel, ",", &p); name; |
1184 |
|
|
name = strtok_r(NULL, ",", &p)) |
1185 |
michael |
6683 |
channel_part_one_client(client_p, name, buf); |
1186 |
michael |
3913 |
} |