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