]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * channel.c: Controls channels. | |
4 | * | |
55abcbb2 KB |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
212380e3 AC |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
212380e3 AC |
23 | */ |
24 | ||
25 | #include "stdinc.h" | |
212380e3 | 26 | #include "channel.h" |
392ae75c | 27 | #include "chmode.h" |
212380e3 | 28 | #include "client.h" |
212380e3 AC |
29 | #include "hash.h" |
30 | #include "hook.h" | |
4562c604 | 31 | #include "match.h" |
212380e3 AC |
32 | #include "ircd.h" |
33 | #include "numeric.h" | |
34 | #include "s_serv.h" /* captab */ | |
35 | #include "s_user.h" | |
36 | #include "send.h" | |
37 | #include "whowas.h" | |
38 | #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */ | |
39 | #include "s_newconf.h" | |
4016731b | 40 | #include "logger.h" |
77d3d2db | 41 | #include "s_assert.h" |
212380e3 | 42 | |
18e4d421 | 43 | struct config_channel_entry ConfigChannel; |
c3d10343 | 44 | rb_dlink_list global_channel_list; |
b617afdc VY |
45 | static rb_bh *channel_heap; |
46 | static rb_bh *ban_heap; | |
47 | static rb_bh *topic_heap; | |
48 | static rb_bh *member_heap; | |
49 | ||
212380e3 AC |
50 | static void free_topic(struct Channel *chptr); |
51 | ||
52 | static int h_can_join; | |
0aa36c5f | 53 | static int h_can_send; |
749d8c11 | 54 | int h_get_channel_access; |
212380e3 AC |
55 | |
56 | /* init_channels() | |
57 | * | |
58 | * input - | |
59 | * output - | |
60 | * side effects - initialises the various blockheaps | |
61 | */ | |
62 | void | |
63 | init_channels(void) | |
64 | { | |
c608a061 AC |
65 | channel_heap = rb_bh_create(sizeof(struct Channel), CHANNEL_HEAP_SIZE, "channel_heap"); |
66 | ban_heap = rb_bh_create(sizeof(struct Ban), BAN_HEAP_SIZE, "ban_heap"); | |
67 | topic_heap = rb_bh_create(TOPICLEN + 1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE, "topic_heap"); | |
68 | member_heap = rb_bh_create(sizeof(struct membership), MEMBER_HEAP_SIZE, "member_heap"); | |
212380e3 AC |
69 | |
70 | h_can_join = register_hook("can_join"); | |
0aa36c5f | 71 | h_can_send = register_hook("can_send"); |
749d8c11 | 72 | h_get_channel_access = register_hook("get_channel_access"); |
212380e3 AC |
73 | } |
74 | ||
75 | /* | |
76 | * allocate_channel - Allocates a channel | |
77 | */ | |
78 | struct Channel * | |
79 | allocate_channel(const char *chname) | |
80 | { | |
81 | struct Channel *chptr; | |
398b6a73 | 82 | chptr = rb_bh_alloc(channel_heap); |
47a03750 | 83 | chptr->chname = rb_strdup(chname); |
212380e3 AC |
84 | return (chptr); |
85 | } | |
86 | ||
87 | void | |
88 | free_channel(struct Channel *chptr) | |
89 | { | |
637c4932 | 90 | rb_free(chptr->chname); |
78e6b731 | 91 | rb_free(chptr->mode_lock); |
398b6a73 | 92 | rb_bh_free(channel_heap, chptr); |
212380e3 AC |
93 | } |
94 | ||
95 | struct Ban * | |
765d839d | 96 | allocate_ban(const char *banstr, const char *who, const char *forward) |
212380e3 AC |
97 | { |
98 | struct Ban *bptr; | |
398b6a73 | 99 | bptr = rb_bh_alloc(ban_heap); |
47a03750 VY |
100 | bptr->banstr = rb_strdup(banstr); |
101 | bptr->who = rb_strdup(who); | |
765d839d | 102 | bptr->forward = forward ? rb_strdup(forward) : NULL; |
212380e3 AC |
103 | |
104 | return (bptr); | |
105 | } | |
106 | ||
107 | void | |
108 | free_ban(struct Ban *bptr) | |
109 | { | |
637c4932 VY |
110 | rb_free(bptr->banstr); |
111 | rb_free(bptr->who); | |
765d839d | 112 | rb_free(bptr->forward); |
398b6a73 | 113 | rb_bh_free(ban_heap, bptr); |
212380e3 AC |
114 | } |
115 | ||
27912fd4 AC |
116 | /* |
117 | * send_channel_join() | |
118 | * | |
119 | * input - channel to join, client joining. | |
120 | * output - none | |
121 | * side effects - none | |
122 | */ | |
123 | void | |
124 | send_channel_join(struct Channel *chptr, struct Client *client_p) | |
125 | { | |
126 | if (!IsClient(client_p)) | |
127 | return; | |
128 | ||
4b1cce65 | 129 | sendto_channel_local_with_capability(client_p, ALL_MEMBERS, NOCAPS, CLICAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN %s", |
92052a5c AC |
130 | client_p->name, client_p->username, client_p->host, chptr->chname); |
131 | ||
4b1cce65 | 132 | sendto_channel_local_with_capability(client_p, ALL_MEMBERS, CLICAP_EXTENDED_JOIN, NOCAPS, chptr, ":%s!%s@%s JOIN %s %s :%s", |
92052a5c AC |
133 | client_p->name, client_p->username, client_p->host, chptr->chname, |
134 | EmptyString(client_p->user->suser) ? "*" : client_p->user->suser, | |
26e9dd93 | 135 | client_p->info); |
c5bbc603 KB |
136 | |
137 | /* Send away message to away-notify enabled clients. */ | |
138 | if (client_p->user->away) | |
139 | sendto_channel_local_with_capability_butone(client_p, ALL_MEMBERS, CLICAP_AWAY_NOTIFY, NOCAPS, chptr, | |
140 | ":%s!%s@%s AWAY :%s", client_p->name, client_p->username, | |
141 | client_p->host, client_p->user->away); | |
27912fd4 | 142 | } |
212380e3 AC |
143 | |
144 | /* find_channel_membership() | |
145 | * | |
146 | * input - channel to find them in, client to find | |
147 | * output - membership of client in channel, else NULL | |
148 | * side effects - | |
149 | */ | |
150 | struct membership * | |
151 | find_channel_membership(struct Channel *chptr, struct Client *client_p) | |
152 | { | |
153 | struct membership *msptr; | |
330fc5c1 | 154 | rb_dlink_node *ptr; |
212380e3 AC |
155 | |
156 | if(!IsClient(client_p)) | |
157 | return NULL; | |
158 | ||
159 | /* Pick the most efficient list to use to be nice to things like | |
160 | * CHANSERV which could be in a large number of channels | |
161 | */ | |
330fc5c1 | 162 | if(rb_dlink_list_length(&chptr->members) < rb_dlink_list_length(&client_p->user->channel)) |
212380e3 | 163 | { |
5cefa1d6 | 164 | RB_DLINK_FOREACH(ptr, chptr->members.head) |
212380e3 AC |
165 | { |
166 | msptr = ptr->data; | |
167 | ||
168 | if(msptr->client_p == client_p) | |
169 | return msptr; | |
170 | } | |
171 | } | |
172 | else | |
173 | { | |
5cefa1d6 | 174 | RB_DLINK_FOREACH(ptr, client_p->user->channel.head) |
212380e3 AC |
175 | { |
176 | msptr = ptr->data; | |
177 | ||
178 | if(msptr->chptr == chptr) | |
179 | return msptr; | |
180 | } | |
181 | } | |
182 | ||
183 | return NULL; | |
184 | } | |
185 | ||
186 | /* find_channel_status() | |
187 | * | |
188 | * input - membership to get status for, whether we can combine flags | |
189 | * output - flags of user on channel | |
190 | * side effects - | |
191 | */ | |
192 | const char * | |
193 | find_channel_status(struct membership *msptr, int combine) | |
194 | { | |
195 | static char buffer[3]; | |
196 | char *p; | |
197 | ||
198 | p = buffer; | |
199 | ||
200 | if(is_chanop(msptr)) | |
201 | { | |
202 | if(!combine) | |
203 | return "@"; | |
204 | *p++ = '@'; | |
205 | } | |
206 | ||
207 | if(is_voiced(msptr)) | |
208 | *p++ = '+'; | |
209 | ||
210 | *p = '\0'; | |
211 | return buffer; | |
212 | } | |
213 | ||
214 | /* add_user_to_channel() | |
215 | * | |
216 | * input - channel to add client to, client to add, channel flags | |
55abcbb2 | 217 | * output - |
212380e3 AC |
218 | * side effects - user is added to channel |
219 | */ | |
220 | void | |
221 | add_user_to_channel(struct Channel *chptr, struct Client *client_p, int flags) | |
222 | { | |
223 | struct membership *msptr; | |
224 | ||
225 | s_assert(client_p->user != NULL); | |
226 | if(client_p->user == NULL) | |
227 | return; | |
228 | ||
398b6a73 | 229 | msptr = rb_bh_alloc(member_heap); |
212380e3 AC |
230 | |
231 | msptr->chptr = chptr; | |
232 | msptr->client_p = client_p; | |
233 | msptr->flags = flags; | |
234 | ||
330fc5c1 AC |
235 | rb_dlinkAdd(msptr, &msptr->usernode, &client_p->user->channel); |
236 | rb_dlinkAdd(msptr, &msptr->channode, &chptr->members); | |
212380e3 AC |
237 | |
238 | if(MyClient(client_p)) | |
330fc5c1 | 239 | rb_dlinkAdd(msptr, &msptr->locchannode, &chptr->locmembers); |
212380e3 AC |
240 | } |
241 | ||
242 | /* remove_user_from_channel() | |
243 | * | |
244 | * input - membership pointer to remove from channel | |
245 | * output - | |
246 | * side effects - membership (thus user) is removed from channel | |
247 | */ | |
248 | void | |
249 | remove_user_from_channel(struct membership *msptr) | |
250 | { | |
251 | struct Client *client_p; | |
252 | struct Channel *chptr; | |
253 | s_assert(msptr != NULL); | |
254 | if(msptr == NULL) | |
255 | return; | |
256 | ||
257 | client_p = msptr->client_p; | |
258 | chptr = msptr->chptr; | |
259 | ||
330fc5c1 AC |
260 | rb_dlinkDelete(&msptr->usernode, &client_p->user->channel); |
261 | rb_dlinkDelete(&msptr->channode, &chptr->members); | |
212380e3 AC |
262 | |
263 | if(client_p->servptr == &me) | |
330fc5c1 | 264 | rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); |
212380e3 | 265 | |
330fc5c1 | 266 | if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) |
212380e3 AC |
267 | destroy_channel(chptr); |
268 | ||
398b6a73 | 269 | rb_bh_free(member_heap, msptr); |
212380e3 AC |
270 | |
271 | return; | |
272 | } | |
273 | ||
274 | /* remove_user_from_channels() | |
275 | * | |
276 | * input - user to remove from all channels | |
277 | * output - | |
278 | * side effects - user is removed from all channels | |
279 | */ | |
280 | void | |
281 | remove_user_from_channels(struct Client *client_p) | |
282 | { | |
283 | struct Channel *chptr; | |
284 | struct membership *msptr; | |
330fc5c1 | 285 | rb_dlink_node *ptr; |
637c4932 | 286 | rb_dlink_node *next_ptr; |
212380e3 AC |
287 | |
288 | if(client_p == NULL) | |
289 | return; | |
290 | ||
637c4932 | 291 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->user->channel.head) |
212380e3 AC |
292 | { |
293 | msptr = ptr->data; | |
294 | chptr = msptr->chptr; | |
295 | ||
330fc5c1 | 296 | rb_dlinkDelete(&msptr->channode, &chptr->members); |
212380e3 AC |
297 | |
298 | if(client_p->servptr == &me) | |
330fc5c1 | 299 | rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); |
212380e3 | 300 | |
330fc5c1 | 301 | if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) |
212380e3 AC |
302 | destroy_channel(chptr); |
303 | ||
398b6a73 | 304 | rb_bh_free(member_heap, msptr); |
212380e3 AC |
305 | } |
306 | ||
307 | client_p->user->channel.head = client_p->user->channel.tail = NULL; | |
308 | client_p->user->channel.length = 0; | |
309 | } | |
310 | ||
311 | /* invalidate_bancache_user() | |
312 | * | |
313 | * input - user to invalidate ban cache for | |
314 | * output - | |
315 | * side effects - ban cache is invalidated for all memberships of that user | |
316 | * to be used after a nick change | |
317 | */ | |
318 | void | |
319 | invalidate_bancache_user(struct Client *client_p) | |
320 | { | |
321 | struct membership *msptr; | |
330fc5c1 | 322 | rb_dlink_node *ptr; |
212380e3 AC |
323 | |
324 | if(client_p == NULL) | |
325 | return; | |
326 | ||
5cefa1d6 | 327 | RB_DLINK_FOREACH(ptr, client_p->user->channel.head) |
212380e3 AC |
328 | { |
329 | msptr = ptr->data; | |
330 | msptr->bants = 0; | |
331 | msptr->flags &= ~CHFL_BANNED; | |
332 | } | |
333 | } | |
334 | ||
335 | /* check_channel_name() | |
336 | * | |
337 | * input - channel name | |
216f58a2 | 338 | * output - true if valid channel name, else false |
212380e3 AC |
339 | * side effects - |
340 | */ | |
3a46803f | 341 | bool |
212380e3 AC |
342 | check_channel_name(const char *name) |
343 | { | |
344 | s_assert(name != NULL); | |
345 | if(name == NULL) | |
3a46803f | 346 | return false; |
212380e3 AC |
347 | |
348 | for (; *name; ++name) | |
349 | { | |
350 | if(!IsChanChar(*name)) | |
3a46803f | 351 | return false; |
212380e3 AC |
352 | } |
353 | ||
3a46803f | 354 | return true; |
212380e3 AC |
355 | } |
356 | ||
357 | /* free_channel_list() | |
358 | * | |
330fc5c1 | 359 | * input - rb_dlink list to free |
212380e3 AC |
360 | * output - |
361 | * side effects - list of b/e/I modes is cleared | |
362 | */ | |
363 | void | |
330fc5c1 | 364 | free_channel_list(rb_dlink_list * list) |
212380e3 | 365 | { |
330fc5c1 | 366 | rb_dlink_node *ptr; |
637c4932 | 367 | rb_dlink_node *next_ptr; |
212380e3 AC |
368 | struct Ban *actualBan; |
369 | ||
637c4932 | 370 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) |
212380e3 AC |
371 | { |
372 | actualBan = ptr->data; | |
373 | free_ban(actualBan); | |
374 | } | |
375 | ||
376 | list->head = list->tail = NULL; | |
377 | list->length = 0; | |
378 | } | |
379 | ||
380 | /* destroy_channel() | |
381 | * | |
382 | * input - channel to destroy | |
383 | * output - | |
384 | * side effects - channel is obliterated | |
385 | */ | |
386 | void | |
387 | destroy_channel(struct Channel *chptr) | |
388 | { | |
637c4932 | 389 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 390 | |
637c4932 | 391 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) |
212380e3 AC |
392 | { |
393 | del_invite(chptr, ptr->data); | |
394 | } | |
395 | ||
396 | /* free all bans/exceptions/denies */ | |
397 | free_channel_list(&chptr->banlist); | |
398 | free_channel_list(&chptr->exceptlist); | |
399 | free_channel_list(&chptr->invexlist); | |
fea1ad52 | 400 | free_channel_list(&chptr->quietlist); |
212380e3 AC |
401 | |
402 | /* Free the topic */ | |
403 | free_topic(chptr); | |
404 | ||
330fc5c1 | 405 | rb_dlinkDelete(&chptr->node, &global_channel_list); |
212380e3 AC |
406 | del_from_channel_hash(chptr->chname, chptr); |
407 | free_channel(chptr); | |
408 | } | |
409 | ||
410 | /* channel_pub_or_secret() | |
411 | * | |
412 | * input - channel | |
413 | * output - "=" if public, "@" if secret, else "*" | |
414 | * side effects - | |
415 | */ | |
416 | static const char * | |
417 | channel_pub_or_secret(struct Channel *chptr) | |
418 | { | |
419 | if(PubChannel(chptr)) | |
420 | return ("="); | |
421 | else if(SecretChannel(chptr)) | |
422 | return ("@"); | |
423 | return ("*"); | |
424 | } | |
425 | ||
426 | /* channel_member_names() | |
427 | * | |
428 | * input - channel to list, client to list to, show endofnames | |
429 | * output - | |
430 | * side effects - client is given list of users on channel | |
431 | */ | |
432 | void | |
433 | channel_member_names(struct Channel *chptr, struct Client *client_p, int show_eon) | |
434 | { | |
435 | struct membership *msptr; | |
436 | struct Client *target_p; | |
330fc5c1 | 437 | rb_dlink_node *ptr; |
212380e3 AC |
438 | char lbuf[BUFSIZE]; |
439 | char *t; | |
440 | int mlen; | |
441 | int tlen; | |
442 | int cur_len; | |
443 | int is_member; | |
444 | int stack = IsCapable(client_p, CLICAP_MULTI_PREFIX); | |
445 | ||
446 | if(ShowChannel(client_p, chptr)) | |
447 | { | |
448 | is_member = IsMember(client_p, chptr); | |
449 | ||
5203cba5 | 450 | cur_len = mlen = sprintf(lbuf, form_str(RPL_NAMREPLY), |
212380e3 AC |
451 | me.name, client_p->name, |
452 | channel_pub_or_secret(chptr), chptr->chname); | |
453 | ||
454 | t = lbuf + cur_len; | |
455 | ||
5cefa1d6 | 456 | RB_DLINK_FOREACH(ptr, chptr->members.head) |
212380e3 AC |
457 | { |
458 | msptr = ptr->data; | |
459 | target_p = msptr->client_p; | |
460 | ||
461 | if(IsInvisible(target_p) && !is_member) | |
462 | continue; | |
463 | ||
1b54aa5c | 464 | if (IsCapable(client_p, CLICAP_USERHOST_IN_NAMES)) |
212380e3 | 465 | { |
1b54aa5c MT |
466 | /* space, possible "@+" prefix */ |
467 | if (cur_len + strlen(target_p->name) + strlen(target_p->username) + strlen(target_p->host) + 5 >= BUFSIZE - 5) | |
468 | { | |
469 | *(t - 1) = '\0'; | |
470 | sendto_one(client_p, "%s", lbuf); | |
471 | cur_len = mlen; | |
472 | t = lbuf + mlen; | |
473 | } | |
474 | ||
5203cba5 | 475 | tlen = sprintf(t, "%s%s!%s@%s ", find_channel_status(msptr, stack), |
1b54aa5c MT |
476 | target_p->name, target_p->username, target_p->host); |
477 | } | |
478 | else | |
479 | { | |
480 | /* space, possible "@+" prefix */ | |
481 | if(cur_len + strlen(target_p->name) + 3 >= BUFSIZE - 3) | |
482 | { | |
483 | *(t - 1) = '\0'; | |
484 | sendto_one(client_p, "%s", lbuf); | |
485 | cur_len = mlen; | |
486 | t = lbuf + mlen; | |
487 | } | |
488 | ||
5203cba5 | 489 | tlen = sprintf(t, "%s%s ", find_channel_status(msptr, stack), |
1b54aa5c | 490 | target_p->name); |
212380e3 | 491 | } |
212380e3 AC |
492 | |
493 | cur_len += tlen; | |
494 | t += tlen; | |
495 | } | |
496 | ||
497 | /* The old behaviour here was to always output our buffer, | |
498 | * even if there are no clients we can show. This happens | |
499 | * when a client does "NAMES" with no parameters, and all | |
500 | * the clients on a -sp channel are +i. I dont see a good | |
501 | * reason for keeping that behaviour, as it just wastes | |
502 | * bandwidth. --anfl | |
503 | */ | |
504 | if(cur_len != mlen) | |
505 | { | |
506 | *(t - 1) = '\0'; | |
507 | sendto_one(client_p, "%s", lbuf); | |
508 | } | |
509 | } | |
510 | ||
511 | if(show_eon) | |
512 | sendto_one(client_p, form_str(RPL_ENDOFNAMES), | |
513 | me.name, client_p->name, chptr->chname); | |
514 | } | |
515 | ||
516 | /* del_invite() | |
517 | * | |
518 | * input - channel to remove invite from, client to remove | |
519 | * output - | |
520 | * side effects - user is removed from invite list, if exists | |
521 | */ | |
522 | void | |
523 | del_invite(struct Channel *chptr, struct Client *who) | |
524 | { | |
330fc5c1 AC |
525 | rb_dlinkFindDestroy(who, &chptr->invites); |
526 | rb_dlinkFindDestroy(chptr, &who->user->invited); | |
212380e3 AC |
527 | } |
528 | ||
a14de124 | 529 | /* is_banned_list() |
212380e3 | 530 | * |
a14de124 JT |
531 | * input - channel to check bans for, ban list (banlist or quietlist), |
532 | * user to check bans against, optional prebuilt buffers, | |
533 | * optional forward channel pointer | |
212380e3 AC |
534 | * output - 1 if banned, else 0 |
535 | * side effects - | |
536 | */ | |
a14de124 JT |
537 | static int |
538 | is_banned_list(struct Channel *chptr, rb_dlink_list *list, | |
539 | struct Client *who, struct membership *msptr, | |
a7d4a0ab | 540 | const struct matchset *ms, const char **forward) |
212380e3 | 541 | { |
a7d4a0ab | 542 | struct matchset ms_; |
330fc5c1 | 543 | rb_dlink_node *ptr; |
212380e3 AC |
544 | struct Ban *actualBan = NULL; |
545 | struct Ban *actualExcept = NULL; | |
546 | ||
a7d4a0ab | 547 | if (!MyClient(who)) |
212380e3 AC |
548 | return 0; |
549 | ||
a7d4a0ab | 550 | if (ms == NULL) |
212380e3 | 551 | { |
a7d4a0ab EK |
552 | matchset_for_client(who, &ms_); |
553 | ms = &ms_; | |
1c60de97 | 554 | } |
212380e3 | 555 | |
a14de124 | 556 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 AC |
557 | { |
558 | actualBan = ptr->data; | |
a7d4a0ab | 559 | if (matches_mask(ms, actualBan->banstr)) |
212380e3 | 560 | break; |
a7d4a0ab EK |
561 | if (match_extban(actualBan->banstr, who, chptr, CHFL_BAN)) |
562 | break; | |
563 | actualBan = NULL; | |
212380e3 AC |
564 | } |
565 | ||
a7d4a0ab | 566 | if ((actualBan != NULL) && ConfigChannel.use_except) |
212380e3 | 567 | { |
5cefa1d6 | 568 | RB_DLINK_FOREACH(ptr, chptr->exceptlist.head) |
212380e3 AC |
569 | { |
570 | actualExcept = ptr->data; | |
571 | ||
572 | /* theyre exempted.. */ | |
a7d4a0ab EK |
573 | if (matches_mask(ms, actualExcept->banstr) || |
574 | match_extban(actualExcept->banstr, who, chptr, CHFL_BAN)) | |
212380e3 AC |
575 | { |
576 | /* cache the fact theyre not banned */ | |
577 | if(msptr != NULL) | |
578 | { | |
579 | msptr->bants = chptr->bants; | |
580 | msptr->flags &= ~CHFL_BANNED; | |
581 | } | |
582 | ||
583 | return CHFL_EXCEPTION; | |
584 | } | |
585 | } | |
586 | } | |
587 | ||
588 | /* cache the banned/not banned status */ | |
589 | if(msptr != NULL) | |
590 | { | |
591 | msptr->bants = chptr->bants; | |
592 | ||
593 | if(actualBan != NULL) | |
594 | { | |
595 | msptr->flags |= CHFL_BANNED; | |
596 | return CHFL_BAN; | |
597 | } | |
598 | else | |
599 | { | |
600 | msptr->flags &= ~CHFL_BANNED; | |
601 | return 0; | |
602 | } | |
603 | } | |
604 | ||
765d839d EM |
605 | if (actualBan && actualBan->forward && forward) |
606 | *forward = actualBan->forward; | |
607 | ||
212380e3 AC |
608 | return ((actualBan ? CHFL_BAN : 0)); |
609 | } | |
610 | ||
a14de124 JT |
611 | /* is_banned() |
612 | * | |
613 | * input - channel to check bans for, user to check bans against | |
614 | * optional prebuilt buffers, optional forward channel pointer | |
615 | * output - 1 if banned, else 0 | |
616 | * side effects - | |
617 | */ | |
618 | int | |
619 | is_banned(struct Channel *chptr, struct Client *who, struct membership *msptr, | |
a7d4a0ab | 620 | const struct matchset *ms, const char **forward) |
a14de124 | 621 | { |
ed9f6a65 | 622 | #if 0 |
2f9687c4 AC |
623 | if (chptr->last_checked_client != NULL && |
624 | who == chptr->last_checked_client && | |
625 | chptr->last_checked_type == CHFL_BAN && | |
1e8138af | 626 | chptr->last_checked_ts > chptr->bants) |
2f9687c4 AC |
627 | return chptr->last_checked_result; |
628 | ||
bcbc6bd9 | 629 | chptr->last_checked_client = who; |
2f9687c4 AC |
630 | chptr->last_checked_type = CHFL_BAN; |
631 | chptr->last_checked_result = is_banned_list(chptr, &chptr->banlist, who, msptr, s, s2, forward); | |
632 | chptr->last_checked_ts = rb_current_time(); | |
633 | ||
634 | return chptr->last_checked_result; | |
ed9f6a65 | 635 | #else |
a7d4a0ab | 636 | return is_banned_list(chptr, &chptr->banlist, who, msptr, ms, forward); |
ed9f6a65 | 637 | #endif |
a14de124 JT |
638 | } |
639 | ||
212380e3 AC |
640 | /* is_quieted() |
641 | * | |
642 | * input - channel to check bans for, user to check bans against | |
643 | * optional prebuilt buffers | |
644 | * output - 1 if banned, else 0 | |
645 | * side effects - | |
646 | */ | |
647 | int | |
648 | is_quieted(struct Channel *chptr, struct Client *who, struct membership *msptr, | |
a7d4a0ab | 649 | const struct matchset *ms) |
212380e3 | 650 | { |
ed9f6a65 | 651 | #if 0 |
2f9687c4 AC |
652 | if (chptr->last_checked_client != NULL && |
653 | who == chptr->last_checked_client && | |
654 | chptr->last_checked_type == CHFL_QUIET && | |
1e8138af | 655 | chptr->last_checked_ts > chptr->bants) |
2f9687c4 AC |
656 | return chptr->last_checked_result; |
657 | ||
bcbc6bd9 | 658 | chptr->last_checked_client = who; |
2f9687c4 AC |
659 | chptr->last_checked_type = CHFL_QUIET; |
660 | chptr->last_checked_result = is_banned_list(chptr, &chptr->quietlist, who, msptr, s, s2, NULL); | |
661 | chptr->last_checked_ts = rb_current_time(); | |
662 | ||
663 | return chptr->last_checked_result; | |
ed9f6a65 | 664 | #else |
a7d4a0ab | 665 | return is_banned_list(chptr, &chptr->quietlist, who, msptr, ms, NULL); |
ed9f6a65 | 666 | #endif |
212380e3 AC |
667 | } |
668 | ||
669 | /* can_join() | |
670 | * | |
671 | * input - client to check, channel to check for, key | |
765d839d | 672 | * output - reason for not being able to join, else 0, channel name to forward to |
212380e3 | 673 | * side effects - |
a63f7af7 | 674 | * caveats - this function should only be called on a local user. |
212380e3 AC |
675 | */ |
676 | int | |
fe74401b | 677 | can_join(struct Client *source_p, struct Channel *chptr, const char *key, const char **forward) |
212380e3 | 678 | { |
330fc5c1 AC |
679 | rb_dlink_node *invite = NULL; |
680 | rb_dlink_node *ptr; | |
212380e3 | 681 | struct Ban *invex = NULL; |
a7d4a0ab | 682 | struct matchset ms; |
1ebf4db4 | 683 | int i = 0; |
212380e3 AC |
684 | hook_data_channel moduledata; |
685 | ||
686 | s_assert(source_p->localClient != NULL); | |
687 | ||
8bb19bd7 AC |
688 | moduledata.client = source_p; |
689 | moduledata.chptr = chptr; | |
690 | moduledata.approved = 0; | |
691 | ||
a7d4a0ab | 692 | matchset_for_client(source_p, &ms); |
212380e3 | 693 | |
a7d4a0ab | 694 | if((is_banned(chptr, source_p, NULL, &ms, forward)) == CHFL_BAN) |
8bb19bd7 AC |
695 | { |
696 | moduledata.approved = ERR_BANNEDFROMCHAN; | |
697 | goto finish_join_check; | |
698 | } | |
212380e3 | 699 | |
765d839d EM |
700 | if(*chptr->mode.key && (EmptyString(key) || irccmp(chptr->mode.key, key))) |
701 | { | |
702 | moduledata.approved = ERR_BADCHANNELKEY; | |
703 | goto finish_join_check; | |
704 | } | |
705 | ||
706 | /* All checks from this point on will forward... */ | |
707 | if(forward) | |
708 | *forward = chptr->mode.forward; | |
709 | ||
212380e3 AC |
710 | if(chptr->mode.mode & MODE_INVITEONLY) |
711 | { | |
5cefa1d6 | 712 | RB_DLINK_FOREACH(invite, source_p->user->invited.head) |
212380e3 | 713 | { |
1ebf4db4 | 714 | if(invite->data == chptr) |
212380e3 AC |
715 | break; |
716 | } | |
1ebf4db4 | 717 | if(invite == NULL) |
212380e3 AC |
718 | { |
719 | if(!ConfigChannel.use_invex) | |
8bb19bd7 | 720 | moduledata.approved = ERR_INVITEONLYCHAN; |
5cefa1d6 | 721 | RB_DLINK_FOREACH(ptr, chptr->invexlist.head) |
212380e3 AC |
722 | { |
723 | invex = ptr->data; | |
a7d4a0ab EK |
724 | if (matches_mask(&ms, invex->banstr) || |
725 | match_extban(invex->banstr, source_p, chptr, CHFL_INVEX)) | |
212380e3 AC |
726 | break; |
727 | } | |
728 | if(ptr == NULL) | |
8bb19bd7 | 729 | moduledata.approved = ERR_INVITEONLYCHAN; |
212380e3 AC |
730 | } |
731 | } | |
732 | ||
212380e3 | 733 | if(chptr->mode.limit && |
330fc5c1 | 734 | rb_dlink_list_length(&chptr->members) >= (unsigned long) chptr->mode.limit) |
1ebf4db4 | 735 | i = ERR_CHANNELISFULL; |
212380e3 | 736 | if(chptr->mode.mode & MODE_REGONLY && EmptyString(source_p->user->suser)) |
1ebf4db4 | 737 | i = ERR_NEEDREGGEDNICK; |
212380e3 | 738 | /* join throttling stuff --nenolod */ |
1ebf4db4 | 739 | else if(chptr->mode.join_num > 0 && chptr->mode.join_time > 0) |
212380e3 | 740 | { |
55abcbb2 | 741 | if ((rb_current_time() - chptr->join_delta <= |
212380e3 AC |
742 | chptr->mode.join_time) && (chptr->join_count >= |
743 | chptr->mode.join_num)) | |
1ebf4db4 JT |
744 | i = ERR_THROTTLE; |
745 | } | |
746 | ||
747 | /* allow /invite to override +l/+r/+j also -- jilles */ | |
748 | if (i != 0 && invite == NULL) | |
749 | { | |
5cefa1d6 | 750 | RB_DLINK_FOREACH(invite, source_p->user->invited.head) |
1ebf4db4 JT |
751 | { |
752 | if(invite->data == chptr) | |
753 | break; | |
754 | } | |
755 | if (invite == NULL) | |
8bb19bd7 | 756 | moduledata.approved = i; |
212380e3 AC |
757 | } |
758 | ||
8bb19bd7 | 759 | finish_join_check: |
212380e3 AC |
760 | call_hook(h_can_join, &moduledata); |
761 | ||
762 | return moduledata.approved; | |
763 | } | |
764 | ||
765 | /* can_send() | |
766 | * | |
767 | * input - user to check in channel, membership pointer | |
768 | * output - whether can explicitly send or not, else CAN_SEND_NONOP | |
769 | * side effects - | |
770 | */ | |
771 | int | |
772 | can_send(struct Channel *chptr, struct Client *source_p, struct membership *msptr) | |
773 | { | |
0aa36c5f AC |
774 | hook_data_channel_approval moduledata; |
775 | ||
776 | moduledata.approved = CAN_SEND_NONOP; | |
202d4966 | 777 | moduledata.dir = MODE_QUERY; |
0aa36c5f | 778 | |
212380e3 AC |
779 | if(IsServer(source_p) || IsService(source_p)) |
780 | return CAN_SEND_OPV; | |
781 | ||
782 | if(MyClient(source_p) && hash_find_resv(chptr->chname) && | |
783 | !IsOper(source_p) && !IsExemptResv(source_p)) | |
0aa36c5f | 784 | moduledata.approved = CAN_SEND_NO; |
212380e3 AC |
785 | |
786 | if(msptr == NULL) | |
787 | { | |
788 | msptr = find_channel_membership(chptr, source_p); | |
789 | ||
790 | if(msptr == NULL) | |
791 | { | |
792 | /* if its +m or +n and theyre not in the channel, | |
793 | * they cant send. we dont check bans here because | |
794 | * theres no possibility of caching them --fl | |
795 | */ | |
796 | if(chptr->mode.mode & MODE_NOPRIVMSGS || chptr->mode.mode & MODE_MODERATED) | |
0aa36c5f | 797 | moduledata.approved = CAN_SEND_NO; |
212380e3 | 798 | else |
0aa36c5f | 799 | moduledata.approved = CAN_SEND_NONOP; |
b697041e AC |
800 | |
801 | return moduledata.approved; | |
212380e3 AC |
802 | } |
803 | } | |
804 | ||
212380e3 | 805 | if(chptr->mode.mode & MODE_MODERATED) |
0aa36c5f | 806 | moduledata.approved = CAN_SEND_NO; |
212380e3 AC |
807 | |
808 | if(MyClient(source_p)) | |
809 | { | |
810 | /* cached can_send */ | |
811 | if(msptr->bants == chptr->bants) | |
812 | { | |
813 | if(can_send_banned(msptr)) | |
0aa36c5f | 814 | moduledata.approved = CAN_SEND_NO; |
212380e3 | 815 | } |
a7d4a0ab EK |
816 | else if(is_banned(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN |
817 | || is_quieted(chptr, source_p, msptr, NULL) == CHFL_BAN) | |
0aa36c5f | 818 | moduledata.approved = CAN_SEND_NO; |
212380e3 AC |
819 | } |
820 | ||
e06988c6 AC |
821 | if(is_chanop_voiced(msptr)) |
822 | moduledata.approved = CAN_SEND_OPV; | |
823 | ||
f4b52a0a EM |
824 | moduledata.client = source_p; |
825 | moduledata.chptr = msptr->chptr; | |
826 | moduledata.msptr = msptr; | |
827 | moduledata.target = NULL; | |
202d4966 | 828 | moduledata.dir = (moduledata.approved == CAN_SEND_NO) ? MODE_ADD : MODE_QUERY; |
f4b52a0a | 829 | |
0aa36c5f AC |
830 | call_hook(h_can_send, &moduledata); |
831 | ||
832 | return moduledata.approved; | |
212380e3 AC |
833 | } |
834 | ||
15484f02 BG |
835 | /* |
836 | * flood_attack_channel | |
837 | * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC | |
838 | * says NOTICE must not auto reply | |
55abcbb2 | 839 | * - pointer to source Client |
3b9507d0 MU |
840 | * - pointer to target channel |
841 | * output - true if target is under flood attack | |
15484f02 BG |
842 | * side effects - check for flood attack on target chptr |
843 | */ | |
3b9507d0 | 844 | bool |
15484f02 BG |
845 | flood_attack_channel(int p_or_n, struct Client *source_p, struct Channel *chptr, char *chname) |
846 | { | |
847 | int delta; | |
848 | ||
849 | if(GlobalSetOptions.floodcount && MyClient(source_p)) | |
850 | { | |
851 | if((chptr->first_received_message_time + 1) < rb_current_time()) | |
852 | { | |
853 | delta = rb_current_time() - chptr->first_received_message_time; | |
854 | chptr->received_number_of_privmsgs -= delta; | |
855 | chptr->first_received_message_time = rb_current_time(); | |
856 | if(chptr->received_number_of_privmsgs <= 0) | |
857 | { | |
858 | chptr->received_number_of_privmsgs = 0; | |
859 | chptr->flood_noticed = 0; | |
860 | } | |
861 | } | |
862 | ||
863 | if((chptr->received_number_of_privmsgs >= GlobalSetOptions.floodcount) | |
864 | || chptr->flood_noticed) | |
865 | { | |
866 | if(chptr->flood_noticed == 0) | |
867 | { | |
868 | sendto_realops_snomask(SNO_BOTS, *chptr->chname == '&' ? L_ALL : L_NETWIDE, | |
869 | "Possible Flooder %s[%s@%s] on %s target: %s", | |
870 | source_p->name, source_p->username, | |
871 | source_p->orighost, | |
872 | source_p->servptr->name, chptr->chname); | |
873 | chptr->flood_noticed = 1; | |
874 | ||
875 | /* Add a bit of penalty */ | |
876 | chptr->received_number_of_privmsgs += 2; | |
877 | } | |
878 | if(MyClient(source_p) && (p_or_n != 1)) | |
879 | sendto_one(source_p, | |
880 | ":%s NOTICE %s :*** Message to %s throttled due to flooding", | |
881 | me.name, source_p->name, chptr->chname); | |
3b9507d0 | 882 | return true; |
15484f02 BG |
883 | } |
884 | else | |
885 | chptr->received_number_of_privmsgs++; | |
886 | } | |
887 | ||
3b9507d0 | 888 | return false; |
15484f02 BG |
889 | } |
890 | ||
212380e3 AC |
891 | /* find_bannickchange_channel() |
892 | * Input: client to check | |
893 | * Output: channel preventing nick change | |
894 | */ | |
895 | struct Channel * | |
896 | find_bannickchange_channel(struct Client *client_p) | |
897 | { | |
898 | struct Channel *chptr; | |
899 | struct membership *msptr; | |
330fc5c1 | 900 | rb_dlink_node *ptr; |
a7d4a0ab | 901 | struct matchset ms; |
212380e3 AC |
902 | |
903 | if (!MyClient(client_p)) | |
904 | return NULL; | |
905 | ||
a7d4a0ab | 906 | matchset_for_client(client_p, &ms); |
212380e3 | 907 | |
5cefa1d6 | 908 | RB_DLINK_FOREACH(ptr, client_p->user->channel.head) |
212380e3 AC |
909 | { |
910 | msptr = ptr->data; | |
911 | chptr = msptr->chptr; | |
912 | if (is_chanop_voiced(msptr)) | |
913 | continue; | |
914 | /* cached can_send */ | |
915 | if (msptr->bants == chptr->bants) | |
916 | { | |
917 | if (can_send_banned(msptr)) | |
918 | return chptr; | |
919 | } | |
a7d4a0ab EK |
920 | else if (is_banned(chptr, client_p, msptr, &ms, NULL) == CHFL_BAN |
921 | || is_quieted(chptr, client_p, msptr, &ms) == CHFL_BAN) | |
212380e3 AC |
922 | return chptr; |
923 | } | |
924 | return NULL; | |
925 | } | |
926 | ||
927 | /* void check_spambot_warning(struct Client *source_p) | |
928 | * Input: Client to check, channel name or NULL if this is a part. | |
929 | * Output: none | |
930 | * Side-effects: Updates the client's oper_warn_count_down, warns the | |
931 | * IRC operators if necessary, and updates join_leave_countdown as | |
932 | * needed. | |
933 | */ | |
934 | void | |
935 | check_spambot_warning(struct Client *source_p, const char *name) | |
936 | { | |
937 | int t_delta; | |
938 | int decrement_count; | |
939 | if((GlobalSetOptions.spam_num && | |
940 | (source_p->localClient->join_leave_count >= GlobalSetOptions.spam_num))) | |
941 | { | |
942 | if(source_p->localClient->oper_warn_count_down > 0) | |
943 | source_p->localClient->oper_warn_count_down--; | |
944 | else | |
945 | source_p->localClient->oper_warn_count_down = 0; | |
e0c1f4ec JT |
946 | if(source_p->localClient->oper_warn_count_down == 0 && |
947 | name != NULL) | |
212380e3 AC |
948 | { |
949 | /* Its already known as a possible spambot */ | |
e0c1f4ec JT |
950 | sendto_realops_snomask(SNO_BOTS, L_NETWIDE, |
951 | "User %s (%s@%s) trying to join %s is a possible spambot", | |
952 | source_p->name, | |
953 | source_p->username, source_p->orighost, name); | |
212380e3 AC |
954 | source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN; |
955 | } | |
956 | } | |
957 | else | |
958 | { | |
959 | if((t_delta = | |
e3354945 | 960 | (rb_current_time() - source_p->localClient->last_leave_time)) > |
212380e3 AC |
961 | JOIN_LEAVE_COUNT_EXPIRE_TIME) |
962 | { | |
963 | decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); | |
981586df JT |
964 | if(name != NULL) |
965 | ; | |
966 | else if(decrement_count > source_p->localClient->join_leave_count) | |
212380e3 AC |
967 | source_p->localClient->join_leave_count = 0; |
968 | else | |
969 | source_p->localClient->join_leave_count -= decrement_count; | |
970 | } | |
971 | else | |
972 | { | |
e3354945 | 973 | if((rb_current_time() - |
212380e3 AC |
974 | (source_p->localClient->last_join_time)) < GlobalSetOptions.spam_time) |
975 | { | |
976 | /* oh, its a possible spambot */ | |
977 | source_p->localClient->join_leave_count++; | |
978 | } | |
979 | } | |
980 | if(name != NULL) | |
e3354945 | 981 | source_p->localClient->last_join_time = rb_current_time(); |
212380e3 | 982 | else |
e3354945 | 983 | source_p->localClient->last_leave_time = rb_current_time(); |
212380e3 AC |
984 | } |
985 | } | |
986 | ||
987 | /* check_splitmode() | |
988 | * | |
989 | * input - | |
990 | * output - | |
991 | * side effects - compares usercount and servercount against their split | |
992 | * values and adjusts splitmode accordingly | |
993 | */ | |
994 | void | |
995 | check_splitmode(void *unused) | |
996 | { | |
997 | if(splitchecking && (ConfigChannel.no_join_on_split || ConfigChannel.no_create_on_split)) | |
998 | { | |
999 | /* not split, we're being asked to check now because someone | |
1000 | * has left | |
1001 | */ | |
1002 | if(!splitmode) | |
1003 | { | |
1004 | if(eob_count < split_servers || Count.total < split_users) | |
1005 | { | |
1006 | splitmode = 1; | |
1007 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1008 | "Network split, activating splitmode"); | |
c608a061 | 1009 | check_splitmode_ev = rb_event_addish("check_splitmode", check_splitmode, NULL, 2); |
212380e3 AC |
1010 | } |
1011 | } | |
1012 | /* in splitmode, check whether its finished */ | |
1013 | else if(eob_count >= split_servers && Count.total >= split_users) | |
1014 | { | |
1015 | splitmode = 0; | |
1016 | ||
1017 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1018 | "Network rejoined, deactivating splitmode"); | |
1019 | ||
c608a061 | 1020 | rb_event_delete(check_splitmode_ev); |
6a309903 | 1021 | check_splitmode_ev = NULL; |
212380e3 AC |
1022 | } |
1023 | } | |
1024 | } | |
1025 | ||
1026 | ||
1027 | /* allocate_topic() | |
1028 | * | |
1029 | * input - channel to allocate topic for | |
1030 | * output - 1 on success, else 0 | |
1031 | * side effects - channel gets a topic allocated | |
1032 | */ | |
1033 | static void | |
1034 | allocate_topic(struct Channel *chptr) | |
1035 | { | |
1036 | void *ptr; | |
1037 | ||
1038 | if(chptr == NULL) | |
1039 | return; | |
1040 | ||
398b6a73 | 1041 | ptr = rb_bh_alloc(topic_heap); |
212380e3 AC |
1042 | |
1043 | /* Basically we allocate one large block for the topic and | |
1044 | * the topic info. We then split it up into two and shove it | |
55abcbb2 | 1045 | * in the chptr |
212380e3 AC |
1046 | */ |
1047 | chptr->topic = ptr; | |
1048 | chptr->topic_info = (char *) ptr + TOPICLEN + 1; | |
1049 | *chptr->topic = '\0'; | |
1050 | *chptr->topic_info = '\0'; | |
1051 | } | |
1052 | ||
1053 | /* free_topic() | |
1054 | * | |
1055 | * input - channel which has topic to free | |
1056 | * output - | |
1057 | * side effects - channels topic is free'd | |
1058 | */ | |
1059 | static void | |
1060 | free_topic(struct Channel *chptr) | |
1061 | { | |
1062 | void *ptr; | |
1063 | ||
1064 | if(chptr == NULL || chptr->topic == NULL) | |
1065 | return; | |
1066 | ||
1067 | /* This is safe for now - If you change allocate_topic you | |
1068 | * MUST change this as well | |
1069 | */ | |
1070 | ptr = chptr->topic; | |
398b6a73 | 1071 | rb_bh_free(topic_heap, ptr); |
212380e3 AC |
1072 | chptr->topic = NULL; |
1073 | chptr->topic_info = NULL; | |
1074 | } | |
1075 | ||
1076 | /* set_channel_topic() | |
1077 | * | |
1078 | * input - channel, topic to set, topic info and topic ts | |
1079 | * output - | |
1080 | * side effects - channels topic, topic info and TS are set. | |
1081 | */ | |
1082 | void | |
1083 | set_channel_topic(struct Channel *chptr, const char *topic, const char *topic_info, time_t topicts) | |
1084 | { | |
1085 | if(strlen(topic) > 0) | |
1086 | { | |
1087 | if(chptr->topic == NULL) | |
1088 | allocate_topic(chptr); | |
f427c8b0 VY |
1089 | rb_strlcpy(chptr->topic, topic, TOPICLEN + 1); |
1090 | rb_strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN); | |
212380e3 AC |
1091 | chptr->topic_time = topicts; |
1092 | } | |
1093 | else | |
1094 | { | |
1095 | if(chptr->topic != NULL) | |
1096 | free_topic(chptr); | |
1097 | chptr->topic_time = 0; | |
1098 | } | |
1099 | } | |
1100 | ||
3b8a6350 | 1101 | /* channel_modes() |
212380e3 AC |
1102 | * |
1103 | * inputs - pointer to channel | |
1104 | * - pointer to client | |
f1e35c19 JT |
1105 | * output - string with simple modes |
1106 | * side effects - result from previous calls overwritten | |
212380e3 AC |
1107 | * |
1108 | * Stolen from ShadowIRCd 4 --nenolod | |
1109 | */ | |
1110 | const char * | |
3b8a6350 | 1111 | channel_modes(struct Channel *chptr, struct Client *client_p) |
212380e3 AC |
1112 | { |
1113 | int i; | |
1114 | char buf1[BUFSIZE]; | |
1115 | char buf2[BUFSIZE]; | |
1116 | static char final[BUFSIZE]; | |
1117 | char *mbuf = buf1; | |
1118 | char *pbuf = buf2; | |
1119 | ||
1120 | *mbuf++ = '+'; | |
1121 | *pbuf = '\0'; | |
1122 | ||
efccc22c | 1123 | for (i = 0; i < 256; i++) |
be29ec79 AC |
1124 | { |
1125 | if(chmode_table[i].set_func == chm_hidden && (!IsOper(client_p) || !IsClient(client_p))) | |
1126 | continue; | |
3b8a6350 | 1127 | if(chptr->mode.mode & chmode_flags[i]) |
efccc22c | 1128 | *mbuf++ = i; |
be29ec79 | 1129 | } |
212380e3 | 1130 | |
3b8a6350 | 1131 | if(chptr->mode.limit) |
212380e3 AC |
1132 | { |
1133 | *mbuf++ = 'l'; | |
1134 | ||
f1e35c19 | 1135 | if(!IsClient(client_p) || IsMember(client_p, chptr)) |
5203cba5 | 1136 | pbuf += sprintf(pbuf, " %d", chptr->mode.limit); |
212380e3 AC |
1137 | } |
1138 | ||
3b8a6350 | 1139 | if(*chptr->mode.key) |
212380e3 AC |
1140 | { |
1141 | *mbuf++ = 'k'; | |
1142 | ||
f1e35c19 | 1143 | if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) |
5203cba5 | 1144 | pbuf += sprintf(pbuf, " %s", chptr->mode.key); |
212380e3 AC |
1145 | } |
1146 | ||
3b8a6350 | 1147 | if(chptr->mode.join_num) |
212380e3 AC |
1148 | { |
1149 | *mbuf++ = 'j'; | |
1150 | ||
f1e35c19 | 1151 | if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) |
5203cba5 | 1152 | pbuf += sprintf(pbuf, " %d:%d", chptr->mode.join_num, |
3b8a6350 | 1153 | chptr->mode.join_time); |
212380e3 AC |
1154 | } |
1155 | ||
2da6f6eb JT |
1156 | if(*chptr->mode.forward && |
1157 | (ConfigChannel.use_forward || !IsClient(client_p))) | |
212380e3 AC |
1158 | { |
1159 | *mbuf++ = 'f'; | |
1160 | ||
f1e35c19 | 1161 | if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) |
5203cba5 | 1162 | pbuf += sprintf(pbuf, " %s", chptr->mode.forward); |
212380e3 AC |
1163 | } |
1164 | ||
1165 | *mbuf = '\0'; | |
1166 | ||
f427c8b0 | 1167 | rb_strlcpy(final, buf1, sizeof final); |
1f9de103 | 1168 | rb_strlcat(final, buf2, sizeof final); |
212380e3 AC |
1169 | return final; |
1170 | } | |
1171 | ||
212380e3 AC |
1172 | /* void send_cap_mode_changes(struct Client *client_p, |
1173 | * struct Client *source_p, | |
1174 | * struct Channel *chptr, int cap, int nocap) | |
1175 | * Input: The client sending(client_p), the source client(source_p), | |
1176 | * the channel to send mode changes for(chptr) | |
1177 | * Output: None. | |
1178 | * Side-effects: Sends the appropriate mode changes to capable servers. | |
1179 | * | |
1180 | * Reverted back to my original design, except that we now keep a count | |
1181 | * of the number of servers which each combination as an optimisation, so | |
1182 | * the capabs combinations which are not needed are not worked out. -A1kmm | |
346fba92 AC |
1183 | * |
1184 | * Removed most code here because we don't need to be compatible with ircd | |
1185 | * 2.8.21+CSr and stuff. --nenolod | |
212380e3 AC |
1186 | */ |
1187 | void | |
1188 | send_cap_mode_changes(struct Client *client_p, struct Client *source_p, | |
1189 | struct Channel *chptr, struct ChModeChange mode_changes[], int mode_count) | |
1190 | { | |
1191 | static char modebuf[BUFSIZE]; | |
1192 | static char parabuf[BUFSIZE]; | |
1193 | int i, mbl, pbl, nc, mc, preflen, len; | |
1194 | char *pbuf; | |
1195 | const char *arg; | |
346fba92 | 1196 | int dir; |
d352ca15 | 1197 | int arglen = 0; |
212380e3 AC |
1198 | |
1199 | /* Now send to servers... */ | |
346fba92 AC |
1200 | mc = 0; |
1201 | nc = 0; | |
1202 | pbl = 0; | |
1203 | parabuf[0] = 0; | |
1204 | pbuf = parabuf; | |
1205 | dir = MODE_QUERY; | |
1206 | ||
5203cba5 | 1207 | mbl = preflen = sprintf(modebuf, ":%s TMODE %ld %s ", |
346fba92 AC |
1208 | use_id(source_p), (long) chptr->channelts, |
1209 | chptr->chname); | |
1210 | ||
1211 | /* loop the list of - modes we have */ | |
1212 | for (i = 0; i < mode_count; i++) | |
212380e3 | 1213 | { |
346fba92 AC |
1214 | /* if they dont support the cap we need, or they do support a cap they |
1215 | * cant have, then dont add it to the modebuf.. that way they wont see | |
1216 | * the mode | |
1217 | */ | |
1218 | if (mode_changes[i].letter == 0) | |
212380e3 AC |
1219 | continue; |
1220 | ||
346fba92 AC |
1221 | if (!EmptyString(mode_changes[i].id)) |
1222 | arg = mode_changes[i].id; | |
1223 | else | |
1224 | arg = mode_changes[i].arg; | |
212380e3 | 1225 | |
346fba92 | 1226 | if(arg) |
212380e3 | 1227 | { |
346fba92 | 1228 | arglen = strlen(arg); |
212380e3 | 1229 | |
346fba92 AC |
1230 | /* dont even think about it! --fl */ |
1231 | if(arglen > MODEBUFLEN - 5) | |
1232 | continue; | |
1233 | } | |
212380e3 | 1234 | |
346fba92 AC |
1235 | /* if we're creeping past the buf size, we need to send it and make |
1236 | * another line for the other modes | |
1237 | * XXX - this could give away server topology with uids being | |
1238 | * different lengths, but not much we can do, except possibly break | |
1239 | * them as if they were the longest of the nick or uid at all times, | |
1240 | * which even then won't work as we don't always know the uid -A1kmm. | |
1241 | */ | |
1242 | if(arg && ((mc == MAXMODEPARAMSSERV) || | |
1243 | ((mbl + pbl + arglen + 4) > (BUFSIZE - 3)))) | |
1244 | { | |
1245 | if(nc != 0) | |
51452a37 | 1246 | sendto_server(client_p, chptr, NOCAPS, NOCAPS, |
346fba92 AC |
1247 | "%s %s", modebuf, parabuf); |
1248 | nc = 0; | |
1249 | mc = 0; | |
1250 | ||
1251 | mbl = preflen; | |
1252 | pbl = 0; | |
1253 | pbuf = parabuf; | |
1254 | parabuf[0] = 0; | |
1255 | dir = MODE_QUERY; | |
1256 | } | |
212380e3 | 1257 | |
346fba92 AC |
1258 | if(dir != mode_changes[i].dir) |
1259 | { | |
1260 | modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; | |
1261 | dir = mode_changes[i].dir; | |
1262 | } | |
212380e3 | 1263 | |
346fba92 AC |
1264 | modebuf[mbl++] = mode_changes[i].letter; |
1265 | modebuf[mbl] = 0; | |
1266 | nc++; | |
212380e3 | 1267 | |
346fba92 AC |
1268 | if(arg != NULL) |
1269 | { | |
5203cba5 | 1270 | len = sprintf(pbuf, "%s ", arg); |
346fba92 AC |
1271 | pbuf += len; |
1272 | pbl += len; | |
1273 | mc++; | |
212380e3 | 1274 | } |
346fba92 | 1275 | } |
212380e3 | 1276 | |
346fba92 AC |
1277 | if(pbl && parabuf[pbl - 1] == ' ') |
1278 | parabuf[pbl - 1] = 0; | |
212380e3 | 1279 | |
346fba92 | 1280 | if(nc != 0) |
51452a37 | 1281 | sendto_server(client_p, chptr, NOCAPS, NOCAPS, "%s %s", modebuf, parabuf); |
212380e3 | 1282 | } |
dca9e552 | 1283 | |
346fba92 | 1284 | void |
dca9e552 JT |
1285 | resv_chan_forcepart(const char *name, const char *reason, int temp_time) |
1286 | { | |
1287 | rb_dlink_node *ptr; | |
1288 | rb_dlink_node *next_ptr; | |
1289 | struct Channel *chptr; | |
1290 | struct membership *msptr; | |
1291 | struct Client *target_p; | |
1292 | ||
1293 | if(!ConfigChannel.resv_forcepart) | |
1294 | return; | |
1295 | ||
1296 | /* for each user on our server in the channel list | |
1297 | * send them a PART, and notify opers. | |
1298 | */ | |
1299 | chptr = find_channel(name); | |
1300 | if(chptr != NULL) | |
1301 | { | |
1302 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) | |
1303 | { | |
1304 | msptr = ptr->data; | |
1305 | target_p = msptr->client_p; | |
1306 | ||
1307 | if(IsExemptResv(target_p)) | |
1308 | continue; | |
1309 | ||
1310 | sendto_server(target_p, chptr, CAP_TS6, NOCAPS, | |
1311 | ":%s PART %s", target_p->id, chptr->chname); | |
1312 | ||
4b1cce65 | 1313 | sendto_channel_local(target_p, ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s", |
dca9e552 JT |
1314 | target_p->name, target_p->username, |
1315 | target_p->host, chptr->chname, target_p->name); | |
1316 | ||
1317 | remove_user_from_channel(msptr); | |
1318 | ||
1319 | /* notify opers & user they were removed from the channel */ | |
1320 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1321 | "Forced PART for %s!%s@%s from %s (%s)", | |
55abcbb2 | 1322 | target_p->name, target_p->username, |
dca9e552 JT |
1323 | target_p->host, name, reason); |
1324 | ||
1325 | if(temp_time > 0) | |
1326 | sendto_one_notice(target_p, ":*** Channel %s is temporarily unavailable on this server.", | |
1327 | name); | |
1328 | else | |
1329 | sendto_one_notice(target_p, ":*** Channel %s is no longer available on this server.", | |
1330 | name); | |
1331 | } | |
1332 | } | |
1333 | } |