]> jfr.im git - solanum.git/blame - ircd/channel.c
Resolve shfit/reduce conflict in timespec production (#54)
[solanum.git] / ircd / channel.c
CommitLineData
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 43struct config_channel_entry ConfigChannel;
c3d10343 44rb_dlink_list global_channel_list;
b617afdc
VY
45static rb_bh *channel_heap;
46static rb_bh *ban_heap;
47static rb_bh *topic_heap;
48static rb_bh *member_heap;
49
212380e3
AC
50static void free_topic(struct Channel *chptr);
51
52static int h_can_join;
0aa36c5f 53static int h_can_send;
749d8c11 54int h_get_channel_access;
212380e3
AC
55
56/* init_channels()
57 *
58 * input -
59 * output -
60 * side effects - initialises the various blockheaps
61 */
62void
63init_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 */
78struct Channel *
79allocate_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
87void
88free_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
95struct Ban *
765d839d 96allocate_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
107void
108free_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 */
123void
124send_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 */
150struct membership *
151find_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 */
192const char *
193find_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 */
220void
221add_user_to_channel(struct Channel *chptr, struct Client *client_p, int flags)
222{
223 struct membership *msptr;
25365ce7 224 rb_dlink_node *p;
212380e3
AC
225
226 s_assert(client_p->user != NULL);
227 if(client_p->user == NULL)
228 return;
229
398b6a73 230 msptr = rb_bh_alloc(member_heap);
212380e3
AC
231
232 msptr->chptr = chptr;
233 msptr->client_p = client_p;
234 msptr->flags = flags;
235
25365ce7
EK
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
330fc5c1 247 rb_dlinkAdd(msptr, &msptr->channode, &chptr->members);
212380e3
AC
248
249 if(MyClient(client_p))
330fc5c1 250 rb_dlinkAdd(msptr, &msptr->locchannode, &chptr->locmembers);
212380e3
AC
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 */
259void
260remove_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
330fc5c1
AC
271 rb_dlinkDelete(&msptr->usernode, &client_p->user->channel);
272 rb_dlinkDelete(&msptr->channode, &chptr->members);
212380e3
AC
273
274 if(client_p->servptr == &me)
330fc5c1 275 rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers);
212380e3 276
330fc5c1 277 if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0)
212380e3
AC
278 destroy_channel(chptr);
279
398b6a73 280 rb_bh_free(member_heap, msptr);
212380e3
AC
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 */
291void
292remove_user_from_channels(struct Client *client_p)
293{
294 struct Channel *chptr;
295 struct membership *msptr;
330fc5c1 296 rb_dlink_node *ptr;
637c4932 297 rb_dlink_node *next_ptr;
212380e3
AC
298
299 if(client_p == NULL)
300 return;
301
637c4932 302 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->user->channel.head)
212380e3
AC
303 {
304 msptr = ptr->data;
305 chptr = msptr->chptr;
306
330fc5c1 307 rb_dlinkDelete(&msptr->channode, &chptr->members);
212380e3
AC
308
309 if(client_p->servptr == &me)
330fc5c1 310 rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers);
212380e3 311
330fc5c1 312 if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0)
212380e3
AC
313 destroy_channel(chptr);
314
398b6a73 315 rb_bh_free(member_heap, msptr);
212380e3
AC
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 */
329void
330invalidate_bancache_user(struct Client *client_p)
331{
332 struct membership *msptr;
330fc5c1 333 rb_dlink_node *ptr;
212380e3
AC
334
335 if(client_p == NULL)
336 return;
337
5cefa1d6 338 RB_DLINK_FOREACH(ptr, client_p->user->channel.head)
212380e3
AC
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
216f58a2 349 * output - true if valid channel name, else false
212380e3
AC
350 * side effects -
351 */
3a46803f 352bool
212380e3
AC
353check_channel_name(const char *name)
354{
355 s_assert(name != NULL);
356 if(name == NULL)
3a46803f 357 return false;
212380e3
AC
358
359 for (; *name; ++name)
360 {
361 if(!IsChanChar(*name))
3a46803f 362 return false;
212380e3
AC
363 }
364
3a46803f 365 return true;
212380e3
AC
366}
367
368/* free_channel_list()
369 *
330fc5c1 370 * input - rb_dlink list to free
212380e3
AC
371 * output -
372 * side effects - list of b/e/I modes is cleared
373 */
374void
330fc5c1 375free_channel_list(rb_dlink_list * list)
212380e3 376{
330fc5c1 377 rb_dlink_node *ptr;
637c4932 378 rb_dlink_node *next_ptr;
212380e3
AC
379 struct Ban *actualBan;
380
637c4932 381 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
212380e3
AC
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 */
397void
398destroy_channel(struct Channel *chptr)
399{
637c4932 400 rb_dlink_node *ptr, *next_ptr;
212380e3 401
637c4932 402 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head)
212380e3
AC
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);
fea1ad52 411 free_channel_list(&chptr->quietlist);
212380e3
AC
412
413 /* Free the topic */
414 free_topic(chptr);
415
330fc5c1 416 rb_dlinkDelete(&chptr->node, &global_channel_list);
212380e3
AC
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 */
427static const char *
428channel_pub_or_secret(struct Channel *chptr)
429{
430 if(PubChannel(chptr))
431 return ("=");
432 else if(SecretChannel(chptr))
433 return ("@");
434 return ("*");
435}
436
e8a8d7a4
EK
437int
438iter_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
212380e3
AC
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 */
484void
485channel_member_names(struct Channel *chptr, struct Client *client_p, int show_eon)
486{
487 struct membership *msptr;
488 struct Client *target_p;
330fc5c1 489 rb_dlink_node *ptr;
212380e3
AC
490 char lbuf[BUFSIZE];
491 char *t;
492 int mlen;
493 int tlen;
494 int cur_len;
495 int is_member;
496 int stack = IsCapable(client_p, CLICAP_MULTI_PREFIX);
497
498 if(ShowChannel(client_p, chptr))
499 {
500 is_member = IsMember(client_p, chptr);
501
5203cba5 502 cur_len = mlen = sprintf(lbuf, form_str(RPL_NAMREPLY),
212380e3
AC
503 me.name, client_p->name,
504 channel_pub_or_secret(chptr), chptr->chname);
505
506 t = lbuf + cur_len;
507
5cefa1d6 508 RB_DLINK_FOREACH(ptr, chptr->members.head)
212380e3
AC
509 {
510 msptr = ptr->data;
511 target_p = msptr->client_p;
512
513 if(IsInvisible(target_p) && !is_member)
514 continue;
515
1b54aa5c 516 if (IsCapable(client_p, CLICAP_USERHOST_IN_NAMES))
212380e3 517 {
1b54aa5c
MT
518 /* space, possible "@+" prefix */
519 if (cur_len + strlen(target_p->name) + strlen(target_p->username) + strlen(target_p->host) + 5 >= BUFSIZE - 5)
520 {
521 *(t - 1) = '\0';
522 sendto_one(client_p, "%s", lbuf);
523 cur_len = mlen;
524 t = lbuf + mlen;
525 }
526
5203cba5 527 tlen = sprintf(t, "%s%s!%s@%s ", find_channel_status(msptr, stack),
1b54aa5c
MT
528 target_p->name, target_p->username, target_p->host);
529 }
530 else
531 {
532 /* space, possible "@+" prefix */
533 if(cur_len + strlen(target_p->name) + 3 >= BUFSIZE - 3)
534 {
535 *(t - 1) = '\0';
536 sendto_one(client_p, "%s", lbuf);
537 cur_len = mlen;
538 t = lbuf + mlen;
539 }
540
5203cba5 541 tlen = sprintf(t, "%s%s ", find_channel_status(msptr, stack),
1b54aa5c 542 target_p->name);
212380e3 543 }
212380e3
AC
544
545 cur_len += tlen;
546 t += tlen;
547 }
548
549 /* The old behaviour here was to always output our buffer,
550 * even if there are no clients we can show. This happens
551 * when a client does "NAMES" with no parameters, and all
552 * the clients on a -sp channel are +i. I dont see a good
553 * reason for keeping that behaviour, as it just wastes
554 * bandwidth. --anfl
555 */
556 if(cur_len != mlen)
557 {
558 *(t - 1) = '\0';
559 sendto_one(client_p, "%s", lbuf);
560 }
561 }
562
563 if(show_eon)
564 sendto_one(client_p, form_str(RPL_ENDOFNAMES),
565 me.name, client_p->name, chptr->chname);
566}
567
568/* del_invite()
569 *
570 * input - channel to remove invite from, client to remove
571 * output -
572 * side effects - user is removed from invite list, if exists
573 */
574void
575del_invite(struct Channel *chptr, struct Client *who)
576{
330fc5c1
AC
577 rb_dlinkFindDestroy(who, &chptr->invites);
578 rb_dlinkFindDestroy(chptr, &who->user->invited);
212380e3
AC
579}
580
a14de124 581/* is_banned_list()
212380e3 582 *
a14de124
JT
583 * input - channel to check bans for, ban list (banlist or quietlist),
584 * user to check bans against, optional prebuilt buffers,
585 * optional forward channel pointer
212380e3
AC
586 * output - 1 if banned, else 0
587 * side effects -
588 */
a14de124
JT
589static int
590is_banned_list(struct Channel *chptr, rb_dlink_list *list,
591 struct Client *who, struct membership *msptr,
a7d4a0ab 592 const struct matchset *ms, const char **forward)
212380e3 593{
a7d4a0ab 594 struct matchset ms_;
330fc5c1 595 rb_dlink_node *ptr;
212380e3
AC
596 struct Ban *actualBan = NULL;
597 struct Ban *actualExcept = NULL;
598
a7d4a0ab 599 if (!MyClient(who))
212380e3
AC
600 return 0;
601
a7d4a0ab 602 if (ms == NULL)
212380e3 603 {
a7d4a0ab
EK
604 matchset_for_client(who, &ms_);
605 ms = &ms_;
1c60de97 606 }
212380e3 607
a14de124 608 RB_DLINK_FOREACH(ptr, list->head)
212380e3
AC
609 {
610 actualBan = ptr->data;
a7d4a0ab 611 if (matches_mask(ms, actualBan->banstr))
212380e3 612 break;
a7d4a0ab
EK
613 if (match_extban(actualBan->banstr, who, chptr, CHFL_BAN))
614 break;
615 actualBan = NULL;
212380e3
AC
616 }
617
a7d4a0ab 618 if ((actualBan != NULL) && ConfigChannel.use_except)
212380e3 619 {
5cefa1d6 620 RB_DLINK_FOREACH(ptr, chptr->exceptlist.head)
212380e3
AC
621 {
622 actualExcept = ptr->data;
623
624 /* theyre exempted.. */
a7d4a0ab 625 if (matches_mask(ms, actualExcept->banstr) ||
255233fc 626 match_extban(actualExcept->banstr, who, chptr, CHFL_EXCEPTION))
212380e3
AC
627 {
628 /* cache the fact theyre not banned */
629 if(msptr != NULL)
630 {
631 msptr->bants = chptr->bants;
632 msptr->flags &= ~CHFL_BANNED;
633 }
634
635 return CHFL_EXCEPTION;
636 }
637 }
638 }
639
640 /* cache the banned/not banned status */
641 if(msptr != NULL)
642 {
643 msptr->bants = chptr->bants;
644
645 if(actualBan != NULL)
646 {
647 msptr->flags |= CHFL_BANNED;
648 return CHFL_BAN;
649 }
650 else
651 {
652 msptr->flags &= ~CHFL_BANNED;
653 return 0;
654 }
655 }
656
765d839d
EM
657 if (actualBan && actualBan->forward && forward)
658 *forward = actualBan->forward;
659
212380e3
AC
660 return ((actualBan ? CHFL_BAN : 0));
661}
662
a14de124
JT
663/* is_banned()
664 *
665 * input - channel to check bans for, user to check bans against
666 * optional prebuilt buffers, optional forward channel pointer
667 * output - 1 if banned, else 0
668 * side effects -
669 */
670int
671is_banned(struct Channel *chptr, struct Client *who, struct membership *msptr,
a7d4a0ab 672 const struct matchset *ms, const char **forward)
a14de124 673{
ed9f6a65 674#if 0
2f9687c4
AC
675 if (chptr->last_checked_client != NULL &&
676 who == chptr->last_checked_client &&
677 chptr->last_checked_type == CHFL_BAN &&
1e8138af 678 chptr->last_checked_ts > chptr->bants)
2f9687c4
AC
679 return chptr->last_checked_result;
680
bcbc6bd9 681 chptr->last_checked_client = who;
2f9687c4
AC
682 chptr->last_checked_type = CHFL_BAN;
683 chptr->last_checked_result = is_banned_list(chptr, &chptr->banlist, who, msptr, s, s2, forward);
684 chptr->last_checked_ts = rb_current_time();
685
686 return chptr->last_checked_result;
ed9f6a65 687#else
a7d4a0ab 688 return is_banned_list(chptr, &chptr->banlist, who, msptr, ms, forward);
ed9f6a65 689#endif
a14de124
JT
690}
691
212380e3
AC
692/* is_quieted()
693 *
694 * input - channel to check bans for, user to check bans against
695 * optional prebuilt buffers
696 * output - 1 if banned, else 0
697 * side effects -
698 */
699int
700is_quieted(struct Channel *chptr, struct Client *who, struct membership *msptr,
a7d4a0ab 701 const struct matchset *ms)
212380e3 702{
ed9f6a65 703#if 0
2f9687c4
AC
704 if (chptr->last_checked_client != NULL &&
705 who == chptr->last_checked_client &&
706 chptr->last_checked_type == CHFL_QUIET &&
1e8138af 707 chptr->last_checked_ts > chptr->bants)
2f9687c4
AC
708 return chptr->last_checked_result;
709
bcbc6bd9 710 chptr->last_checked_client = who;
2f9687c4
AC
711 chptr->last_checked_type = CHFL_QUIET;
712 chptr->last_checked_result = is_banned_list(chptr, &chptr->quietlist, who, msptr, s, s2, NULL);
713 chptr->last_checked_ts = rb_current_time();
714
715 return chptr->last_checked_result;
ed9f6a65 716#else
a7d4a0ab 717 return is_banned_list(chptr, &chptr->quietlist, who, msptr, ms, NULL);
ed9f6a65 718#endif
212380e3
AC
719}
720
721/* can_join()
722 *
723 * input - client to check, channel to check for, key
765d839d 724 * output - reason for not being able to join, else 0, channel name to forward to
212380e3 725 * side effects -
a63f7af7 726 * caveats - this function should only be called on a local user.
212380e3
AC
727 */
728int
fe74401b 729can_join(struct Client *source_p, struct Channel *chptr, const char *key, const char **forward)
212380e3 730{
330fc5c1
AC
731 rb_dlink_node *invite = NULL;
732 rb_dlink_node *ptr;
212380e3 733 struct Ban *invex = NULL;
a7d4a0ab 734 struct matchset ms;
1ebf4db4 735 int i = 0;
212380e3
AC
736 hook_data_channel moduledata;
737
738 s_assert(source_p->localClient != NULL);
739
8bb19bd7
AC
740 moduledata.client = source_p;
741 moduledata.chptr = chptr;
742 moduledata.approved = 0;
743
a7d4a0ab 744 matchset_for_client(source_p, &ms);
212380e3 745
a7d4a0ab 746 if((is_banned(chptr, source_p, NULL, &ms, forward)) == CHFL_BAN)
8bb19bd7
AC
747 {
748 moduledata.approved = ERR_BANNEDFROMCHAN;
749 goto finish_join_check;
750 }
212380e3 751
765d839d
EM
752 if(*chptr->mode.key && (EmptyString(key) || irccmp(chptr->mode.key, key)))
753 {
754 moduledata.approved = ERR_BADCHANNELKEY;
755 goto finish_join_check;
756 }
757
758 /* All checks from this point on will forward... */
759 if(forward)
760 *forward = chptr->mode.forward;
761
212380e3
AC
762 if(chptr->mode.mode & MODE_INVITEONLY)
763 {
5cefa1d6 764 RB_DLINK_FOREACH(invite, source_p->user->invited.head)
212380e3 765 {
1ebf4db4 766 if(invite->data == chptr)
212380e3
AC
767 break;
768 }
1ebf4db4 769 if(invite == NULL)
212380e3
AC
770 {
771 if(!ConfigChannel.use_invex)
8bb19bd7 772 moduledata.approved = ERR_INVITEONLYCHAN;
5cefa1d6 773 RB_DLINK_FOREACH(ptr, chptr->invexlist.head)
212380e3
AC
774 {
775 invex = ptr->data;
a7d4a0ab
EK
776 if (matches_mask(&ms, invex->banstr) ||
777 match_extban(invex->banstr, source_p, chptr, CHFL_INVEX))
212380e3
AC
778 break;
779 }
780 if(ptr == NULL)
8bb19bd7 781 moduledata.approved = ERR_INVITEONLYCHAN;
212380e3
AC
782 }
783 }
784
212380e3 785 if(chptr->mode.limit &&
330fc5c1 786 rb_dlink_list_length(&chptr->members) >= (unsigned long) chptr->mode.limit)
1ebf4db4 787 i = ERR_CHANNELISFULL;
212380e3 788 if(chptr->mode.mode & MODE_REGONLY && EmptyString(source_p->user->suser))
1ebf4db4 789 i = ERR_NEEDREGGEDNICK;
212380e3 790 /* join throttling stuff --nenolod */
1ebf4db4 791 else if(chptr->mode.join_num > 0 && chptr->mode.join_time > 0)
212380e3 792 {
55abcbb2 793 if ((rb_current_time() - chptr->join_delta <=
212380e3
AC
794 chptr->mode.join_time) && (chptr->join_count >=
795 chptr->mode.join_num))
1ebf4db4
JT
796 i = ERR_THROTTLE;
797 }
798
799 /* allow /invite to override +l/+r/+j also -- jilles */
800 if (i != 0 && invite == NULL)
801 {
5cefa1d6 802 RB_DLINK_FOREACH(invite, source_p->user->invited.head)
1ebf4db4
JT
803 {
804 if(invite->data == chptr)
805 break;
806 }
807 if (invite == NULL)
8bb19bd7 808 moduledata.approved = i;
212380e3
AC
809 }
810
8bb19bd7 811finish_join_check:
212380e3
AC
812 call_hook(h_can_join, &moduledata);
813
814 return moduledata.approved;
815}
816
817/* can_send()
818 *
819 * input - user to check in channel, membership pointer
820 * output - whether can explicitly send or not, else CAN_SEND_NONOP
821 * side effects -
822 */
823int
824can_send(struct Channel *chptr, struct Client *source_p, struct membership *msptr)
825{
0aa36c5f
AC
826 hook_data_channel_approval moduledata;
827
828 moduledata.approved = CAN_SEND_NONOP;
202d4966 829 moduledata.dir = MODE_QUERY;
0aa36c5f 830
212380e3
AC
831 if(IsServer(source_p) || IsService(source_p))
832 return CAN_SEND_OPV;
833
834 if(MyClient(source_p) && hash_find_resv(chptr->chname) &&
835 !IsOper(source_p) && !IsExemptResv(source_p))
0aa36c5f 836 moduledata.approved = CAN_SEND_NO;
212380e3
AC
837
838 if(msptr == NULL)
839 {
840 msptr = find_channel_membership(chptr, source_p);
841
842 if(msptr == NULL)
843 {
844 /* if its +m or +n and theyre not in the channel,
845 * they cant send. we dont check bans here because
846 * theres no possibility of caching them --fl
847 */
848 if(chptr->mode.mode & MODE_NOPRIVMSGS || chptr->mode.mode & MODE_MODERATED)
0aa36c5f 849 moduledata.approved = CAN_SEND_NO;
212380e3 850 else
0aa36c5f 851 moduledata.approved = CAN_SEND_NONOP;
b697041e
AC
852
853 return moduledata.approved;
212380e3
AC
854 }
855 }
856
212380e3 857 if(chptr->mode.mode & MODE_MODERATED)
0aa36c5f 858 moduledata.approved = CAN_SEND_NO;
212380e3
AC
859
860 if(MyClient(source_p))
861 {
862 /* cached can_send */
863 if(msptr->bants == chptr->bants)
864 {
865 if(can_send_banned(msptr))
0aa36c5f 866 moduledata.approved = CAN_SEND_NO;
212380e3 867 }
a7d4a0ab
EK
868 else if(is_banned(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN
869 || is_quieted(chptr, source_p, msptr, NULL) == CHFL_BAN)
0aa36c5f 870 moduledata.approved = CAN_SEND_NO;
212380e3
AC
871 }
872
e06988c6
AC
873 if(is_chanop_voiced(msptr))
874 moduledata.approved = CAN_SEND_OPV;
875
f4b52a0a
EM
876 moduledata.client = source_p;
877 moduledata.chptr = msptr->chptr;
878 moduledata.msptr = msptr;
879 moduledata.target = NULL;
202d4966 880 moduledata.dir = (moduledata.approved == CAN_SEND_NO) ? MODE_ADD : MODE_QUERY;
f4b52a0a 881
0aa36c5f
AC
882 call_hook(h_can_send, &moduledata);
883
884 return moduledata.approved;
212380e3
AC
885}
886
15484f02
BG
887/*
888 * flood_attack_channel
889 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
890 * says NOTICE must not auto reply
55abcbb2 891 * - pointer to source Client
3b9507d0
MU
892 * - pointer to target channel
893 * output - true if target is under flood attack
15484f02
BG
894 * side effects - check for flood attack on target chptr
895 */
3b9507d0 896bool
15484f02
BG
897flood_attack_channel(int p_or_n, struct Client *source_p, struct Channel *chptr, char *chname)
898{
899 int delta;
900
901 if(GlobalSetOptions.floodcount && MyClient(source_p))
902 {
903 if((chptr->first_received_message_time + 1) < rb_current_time())
904 {
905 delta = rb_current_time() - chptr->first_received_message_time;
906 chptr->received_number_of_privmsgs -= delta;
907 chptr->first_received_message_time = rb_current_time();
908 if(chptr->received_number_of_privmsgs <= 0)
909 {
910 chptr->received_number_of_privmsgs = 0;
911 chptr->flood_noticed = 0;
912 }
913 }
914
915 if((chptr->received_number_of_privmsgs >= GlobalSetOptions.floodcount)
916 || chptr->flood_noticed)
917 {
918 if(chptr->flood_noticed == 0)
919 {
920 sendto_realops_snomask(SNO_BOTS, *chptr->chname == '&' ? L_ALL : L_NETWIDE,
921 "Possible Flooder %s[%s@%s] on %s target: %s",
922 source_p->name, source_p->username,
923 source_p->orighost,
924 source_p->servptr->name, chptr->chname);
925 chptr->flood_noticed = 1;
926
927 /* Add a bit of penalty */
928 chptr->received_number_of_privmsgs += 2;
929 }
930 if(MyClient(source_p) && (p_or_n != 1))
931 sendto_one(source_p,
932 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
933 me.name, source_p->name, chptr->chname);
3b9507d0 934 return true;
15484f02
BG
935 }
936 else
937 chptr->received_number_of_privmsgs++;
938 }
939
3b9507d0 940 return false;
15484f02
BG
941}
942
212380e3
AC
943/* find_bannickchange_channel()
944 * Input: client to check
945 * Output: channel preventing nick change
946 */
947struct Channel *
948find_bannickchange_channel(struct Client *client_p)
949{
950 struct Channel *chptr;
951 struct membership *msptr;
330fc5c1 952 rb_dlink_node *ptr;
a7d4a0ab 953 struct matchset ms;
212380e3
AC
954
955 if (!MyClient(client_p))
956 return NULL;
957
a7d4a0ab 958 matchset_for_client(client_p, &ms);
212380e3 959
5cefa1d6 960 RB_DLINK_FOREACH(ptr, client_p->user->channel.head)
212380e3
AC
961 {
962 msptr = ptr->data;
963 chptr = msptr->chptr;
964 if (is_chanop_voiced(msptr))
965 continue;
966 /* cached can_send */
967 if (msptr->bants == chptr->bants)
968 {
969 if (can_send_banned(msptr))
970 return chptr;
971 }
a7d4a0ab
EK
972 else if (is_banned(chptr, client_p, msptr, &ms, NULL) == CHFL_BAN
973 || is_quieted(chptr, client_p, msptr, &ms) == CHFL_BAN)
212380e3
AC
974 return chptr;
975 }
976 return NULL;
977}
978
979/* void check_spambot_warning(struct Client *source_p)
980 * Input: Client to check, channel name or NULL if this is a part.
981 * Output: none
982 * Side-effects: Updates the client's oper_warn_count_down, warns the
983 * IRC operators if necessary, and updates join_leave_countdown as
984 * needed.
985 */
986void
987check_spambot_warning(struct Client *source_p, const char *name)
988{
989 int t_delta;
990 int decrement_count;
991 if((GlobalSetOptions.spam_num &&
992 (source_p->localClient->join_leave_count >= GlobalSetOptions.spam_num)))
993 {
994 if(source_p->localClient->oper_warn_count_down > 0)
995 source_p->localClient->oper_warn_count_down--;
996 else
997 source_p->localClient->oper_warn_count_down = 0;
e0c1f4ec
JT
998 if(source_p->localClient->oper_warn_count_down == 0 &&
999 name != NULL)
212380e3
AC
1000 {
1001 /* Its already known as a possible spambot */
e0c1f4ec
JT
1002 sendto_realops_snomask(SNO_BOTS, L_NETWIDE,
1003 "User %s (%s@%s) trying to join %s is a possible spambot",
1004 source_p->name,
1005 source_p->username, source_p->orighost, name);
212380e3
AC
1006 source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
1007 }
1008 }
1009 else
1010 {
1011 if((t_delta =
e3354945 1012 (rb_current_time() - source_p->localClient->last_leave_time)) >
212380e3
AC
1013 JOIN_LEAVE_COUNT_EXPIRE_TIME)
1014 {
1015 decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
981586df
JT
1016 if(name != NULL)
1017 ;
1018 else if(decrement_count > source_p->localClient->join_leave_count)
212380e3
AC
1019 source_p->localClient->join_leave_count = 0;
1020 else
1021 source_p->localClient->join_leave_count -= decrement_count;
1022 }
1023 else
1024 {
e3354945 1025 if((rb_current_time() -
212380e3
AC
1026 (source_p->localClient->last_join_time)) < GlobalSetOptions.spam_time)
1027 {
1028 /* oh, its a possible spambot */
1029 source_p->localClient->join_leave_count++;
1030 }
1031 }
1032 if(name != NULL)
e3354945 1033 source_p->localClient->last_join_time = rb_current_time();
212380e3 1034 else
e3354945 1035 source_p->localClient->last_leave_time = rb_current_time();
212380e3
AC
1036 }
1037}
1038
1039/* check_splitmode()
1040 *
1041 * input -
1042 * output -
1043 * side effects - compares usercount and servercount against their split
1044 * values and adjusts splitmode accordingly
1045 */
1046void
1047check_splitmode(void *unused)
1048{
1049 if(splitchecking && (ConfigChannel.no_join_on_split || ConfigChannel.no_create_on_split))
1050 {
1051 /* not split, we're being asked to check now because someone
1052 * has left
1053 */
1054 if(!splitmode)
1055 {
1056 if(eob_count < split_servers || Count.total < split_users)
1057 {
1058 splitmode = 1;
1059 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1060 "Network split, activating splitmode");
c608a061 1061 check_splitmode_ev = rb_event_addish("check_splitmode", check_splitmode, NULL, 2);
212380e3
AC
1062 }
1063 }
1064 /* in splitmode, check whether its finished */
1065 else if(eob_count >= split_servers && Count.total >= split_users)
1066 {
1067 splitmode = 0;
1068
1069 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1070 "Network rejoined, deactivating splitmode");
1071
c608a061 1072 rb_event_delete(check_splitmode_ev);
6a309903 1073 check_splitmode_ev = NULL;
212380e3
AC
1074 }
1075 }
1076}
1077
1078
1079/* allocate_topic()
1080 *
1081 * input - channel to allocate topic for
1082 * output - 1 on success, else 0
1083 * side effects - channel gets a topic allocated
1084 */
1085static void
1086allocate_topic(struct Channel *chptr)
1087{
1088 void *ptr;
1089
1090 if(chptr == NULL)
1091 return;
1092
398b6a73 1093 ptr = rb_bh_alloc(topic_heap);
212380e3
AC
1094
1095 /* Basically we allocate one large block for the topic and
1096 * the topic info. We then split it up into two and shove it
55abcbb2 1097 * in the chptr
212380e3
AC
1098 */
1099 chptr->topic = ptr;
1100 chptr->topic_info = (char *) ptr + TOPICLEN + 1;
1101 *chptr->topic = '\0';
1102 *chptr->topic_info = '\0';
1103}
1104
1105/* free_topic()
1106 *
1107 * input - channel which has topic to free
1108 * output -
1109 * side effects - channels topic is free'd
1110 */
1111static void
1112free_topic(struct Channel *chptr)
1113{
1114 void *ptr;
1115
1116 if(chptr == NULL || chptr->topic == NULL)
1117 return;
1118
1119 /* This is safe for now - If you change allocate_topic you
1120 * MUST change this as well
1121 */
1122 ptr = chptr->topic;
398b6a73 1123 rb_bh_free(topic_heap, ptr);
212380e3
AC
1124 chptr->topic = NULL;
1125 chptr->topic_info = NULL;
1126}
1127
1128/* set_channel_topic()
1129 *
1130 * input - channel, topic to set, topic info and topic ts
1131 * output -
1132 * side effects - channels topic, topic info and TS are set.
1133 */
1134void
1135set_channel_topic(struct Channel *chptr, const char *topic, const char *topic_info, time_t topicts)
1136{
1137 if(strlen(topic) > 0)
1138 {
1139 if(chptr->topic == NULL)
1140 allocate_topic(chptr);
f427c8b0
VY
1141 rb_strlcpy(chptr->topic, topic, TOPICLEN + 1);
1142 rb_strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN);
212380e3
AC
1143 chptr->topic_time = topicts;
1144 }
1145 else
1146 {
1147 if(chptr->topic != NULL)
1148 free_topic(chptr);
1149 chptr->topic_time = 0;
1150 }
1151}
1152
3b8a6350 1153/* channel_modes()
212380e3
AC
1154 *
1155 * inputs - pointer to channel
1156 * - pointer to client
f1e35c19
JT
1157 * output - string with simple modes
1158 * side effects - result from previous calls overwritten
212380e3
AC
1159 *
1160 * Stolen from ShadowIRCd 4 --nenolod
1161 */
1162const char *
3b8a6350 1163channel_modes(struct Channel *chptr, struct Client *client_p)
212380e3
AC
1164{
1165 int i;
1166 char buf1[BUFSIZE];
1167 char buf2[BUFSIZE];
1168 static char final[BUFSIZE];
1169 char *mbuf = buf1;
1170 char *pbuf = buf2;
1171
1172 *mbuf++ = '+';
1173 *pbuf = '\0';
1174
efccc22c 1175 for (i = 0; i < 256; i++)
be29ec79 1176 {
cc61cada 1177 if(chmode_table[i].set_func == chm_hidden && (!HasPrivilege(client_p, "auspex:cmodes") || !IsClient(client_p)))
be29ec79 1178 continue;
3b8a6350 1179 if(chptr->mode.mode & chmode_flags[i])
efccc22c 1180 *mbuf++ = i;
be29ec79 1181 }
212380e3 1182
3b8a6350 1183 if(chptr->mode.limit)
212380e3
AC
1184 {
1185 *mbuf++ = 'l';
1186
f1e35c19 1187 if(!IsClient(client_p) || IsMember(client_p, chptr))
5203cba5 1188 pbuf += sprintf(pbuf, " %d", chptr->mode.limit);
212380e3
AC
1189 }
1190
3b8a6350 1191 if(*chptr->mode.key)
212380e3
AC
1192 {
1193 *mbuf++ = 'k';
1194
f1e35c19 1195 if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr))
5203cba5 1196 pbuf += sprintf(pbuf, " %s", chptr->mode.key);
212380e3
AC
1197 }
1198
3b8a6350 1199 if(chptr->mode.join_num)
212380e3
AC
1200 {
1201 *mbuf++ = 'j';
1202
f1e35c19 1203 if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr))
5203cba5 1204 pbuf += sprintf(pbuf, " %d:%d", chptr->mode.join_num,
3b8a6350 1205 chptr->mode.join_time);
212380e3
AC
1206 }
1207
2da6f6eb
JT
1208 if(*chptr->mode.forward &&
1209 (ConfigChannel.use_forward || !IsClient(client_p)))
212380e3
AC
1210 {
1211 *mbuf++ = 'f';
1212
f1e35c19 1213 if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr))
5203cba5 1214 pbuf += sprintf(pbuf, " %s", chptr->mode.forward);
212380e3
AC
1215 }
1216
1217 *mbuf = '\0';
1218
f427c8b0 1219 rb_strlcpy(final, buf1, sizeof final);
1f9de103 1220 rb_strlcat(final, buf2, sizeof final);
212380e3
AC
1221 return final;
1222}
1223
212380e3
AC
1224/* void send_cap_mode_changes(struct Client *client_p,
1225 * struct Client *source_p,
1226 * struct Channel *chptr, int cap, int nocap)
1227 * Input: The client sending(client_p), the source client(source_p),
1228 * the channel to send mode changes for(chptr)
1229 * Output: None.
1230 * Side-effects: Sends the appropriate mode changes to capable servers.
1231 *
1232 * Reverted back to my original design, except that we now keep a count
1233 * of the number of servers which each combination as an optimisation, so
1234 * the capabs combinations which are not needed are not worked out. -A1kmm
346fba92
AC
1235 *
1236 * Removed most code here because we don't need to be compatible with ircd
1237 * 2.8.21+CSr and stuff. --nenolod
212380e3
AC
1238 */
1239void
1240send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
1241 struct Channel *chptr, struct ChModeChange mode_changes[], int mode_count)
1242{
1243 static char modebuf[BUFSIZE];
1244 static char parabuf[BUFSIZE];
1245 int i, mbl, pbl, nc, mc, preflen, len;
1246 char *pbuf;
1247 const char *arg;
346fba92 1248 int dir;
d352ca15 1249 int arglen = 0;
212380e3
AC
1250
1251 /* Now send to servers... */
346fba92
AC
1252 mc = 0;
1253 nc = 0;
1254 pbl = 0;
1255 parabuf[0] = 0;
1256 pbuf = parabuf;
1257 dir = MODE_QUERY;
1258
5203cba5 1259 mbl = preflen = sprintf(modebuf, ":%s TMODE %ld %s ",
346fba92
AC
1260 use_id(source_p), (long) chptr->channelts,
1261 chptr->chname);
1262
1263 /* loop the list of - modes we have */
1264 for (i = 0; i < mode_count; i++)
212380e3 1265 {
346fba92
AC
1266 /* if they dont support the cap we need, or they do support a cap they
1267 * cant have, then dont add it to the modebuf.. that way they wont see
1268 * the mode
1269 */
1270 if (mode_changes[i].letter == 0)
212380e3
AC
1271 continue;
1272
346fba92
AC
1273 if (!EmptyString(mode_changes[i].id))
1274 arg = mode_changes[i].id;
1275 else
1276 arg = mode_changes[i].arg;
212380e3 1277
346fba92 1278 if(arg)
212380e3 1279 {
346fba92 1280 arglen = strlen(arg);
212380e3 1281
346fba92
AC
1282 /* dont even think about it! --fl */
1283 if(arglen > MODEBUFLEN - 5)
1284 continue;
1285 }
212380e3 1286
346fba92
AC
1287 /* if we're creeping past the buf size, we need to send it and make
1288 * another line for the other modes
1289 * XXX - this could give away server topology with uids being
1290 * different lengths, but not much we can do, except possibly break
1291 * them as if they were the longest of the nick or uid at all times,
1292 * which even then won't work as we don't always know the uid -A1kmm.
1293 */
1294 if(arg && ((mc == MAXMODEPARAMSSERV) ||
1295 ((mbl + pbl + arglen + 4) > (BUFSIZE - 3))))
1296 {
1297 if(nc != 0)
51452a37 1298 sendto_server(client_p, chptr, NOCAPS, NOCAPS,
346fba92
AC
1299 "%s %s", modebuf, parabuf);
1300 nc = 0;
1301 mc = 0;
1302
1303 mbl = preflen;
1304 pbl = 0;
1305 pbuf = parabuf;
1306 parabuf[0] = 0;
1307 dir = MODE_QUERY;
1308 }
212380e3 1309
346fba92
AC
1310 if(dir != mode_changes[i].dir)
1311 {
1312 modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1313 dir = mode_changes[i].dir;
1314 }
212380e3 1315
346fba92
AC
1316 modebuf[mbl++] = mode_changes[i].letter;
1317 modebuf[mbl] = 0;
1318 nc++;
212380e3 1319
346fba92
AC
1320 if(arg != NULL)
1321 {
5203cba5 1322 len = sprintf(pbuf, "%s ", arg);
346fba92
AC
1323 pbuf += len;
1324 pbl += len;
1325 mc++;
212380e3 1326 }
346fba92 1327 }
212380e3 1328
346fba92
AC
1329 if(pbl && parabuf[pbl - 1] == ' ')
1330 parabuf[pbl - 1] = 0;
212380e3 1331
346fba92 1332 if(nc != 0)
51452a37 1333 sendto_server(client_p, chptr, NOCAPS, NOCAPS, "%s %s", modebuf, parabuf);
212380e3 1334}
dca9e552 1335
346fba92 1336void
dca9e552
JT
1337resv_chan_forcepart(const char *name, const char *reason, int temp_time)
1338{
1339 rb_dlink_node *ptr;
1340 rb_dlink_node *next_ptr;
1341 struct Channel *chptr;
1342 struct membership *msptr;
1343 struct Client *target_p;
1344
1345 if(!ConfigChannel.resv_forcepart)
1346 return;
1347
1348 /* for each user on our server in the channel list
1349 * send them a PART, and notify opers.
1350 */
1351 chptr = find_channel(name);
1352 if(chptr != NULL)
1353 {
1354 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
1355 {
1356 msptr = ptr->data;
1357 target_p = msptr->client_p;
1358
1359 if(IsExemptResv(target_p))
1360 continue;
1361
1362 sendto_server(target_p, chptr, CAP_TS6, NOCAPS,
1363 ":%s PART %s", target_p->id, chptr->chname);
1364
4b1cce65 1365 sendto_channel_local(target_p, ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s",
dca9e552
JT
1366 target_p->name, target_p->username,
1367 target_p->host, chptr->chname, target_p->name);
1368
1369 remove_user_from_channel(msptr);
1370
1371 /* notify opers & user they were removed from the channel */
1372 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1373 "Forced PART for %s!%s@%s from %s (%s)",
55abcbb2 1374 target_p->name, target_p->username,
dca9e552
JT
1375 target_p->host, name, reason);
1376
1377 if(temp_time > 0)
1378 sendto_one_notice(target_p, ":*** Channel %s is temporarily unavailable on this server.",
1379 name);
1380 else
1381 sendto_one_notice(target_p, ":*** Channel %s is no longer available on this server.",
1382 name);
1383 }
1384 }
1385}