ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/channel.c
Revision: 364
Committed: Sun Jan 8 15:39:24 2006 UTC (19 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 25379 byte(s)
Log Message:
- Entirely changed the way of ban match processing to be more cleaner.
  It also should nicely speed up matching of pure ip (may include cidr mask)
  bans.
- Removed match_cidr() which is now not longed needed
- Add back some prototypes to res.h to fix compile errors

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 *
4 * Copyright (C) 2002 by the past and present ircd coders, and others.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file channel.c
23 * \brief Responsible for managing channels, members, bans and topics
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "channel.h"
29 #include "channel_mode.h"
30 #include "client.h"
31 #include "common.h"
32 #include "hash.h"
33 #include "hostmask.h"
34 #include "ircd.h"
35 #include "numeric.h"
36 #include "s_serv.h" /* captab */
37 #include "s_user.h"
38 #include "send.h"
39 #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
40
41 struct config_channel_entry ConfigChannel;
42 dlink_list global_channel_list = { NULL, NULL, 0 };
43 dlink_list lazylink_channels = { NULL, NULL, 0 };
44 BlockHeap *ban_heap; /*! \todo ban_heap shouldn't be a global var */
45
46 static BlockHeap *topic_heap = NULL;
47 static BlockHeap *member_heap = NULL;
48 static BlockHeap *channel_heap = NULL;
49
50 static char buf[IRCD_BUFSIZE];
51 static char modebuf[MODEBUFLEN];
52 static char parabuf[MODEBUFLEN];
53
54
55 /*! \brief Initializes the channel blockheap, adds known channel CAPAB
56 */
57 void
58 init_channels(void)
59 {
60 /*
61 * XXX - These should get moved to somwhere else once we have
62 * a modular channelmode system
63 */
64 add_capability("EX", CAP_EX, 1);
65 add_capability("IE", CAP_IE, 1);
66 add_capability("CHW", CAP_CHW, 1);
67
68 channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE);
69 ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE);
70 topic_heap = BlockHeapCreate("topic", TOPICLEN+1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE);
71 member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2);
72 }
73
74 /*! \brief adds a user to a channel by adding another link to the
75 * channels member chain.
76 * \param chptr pointer to channel to add client to
77 * \param who pointer to client (who) to add
78 * \param flags flags for chanops etc
79 * \param flood_ctrl whether to count this join in flood calculations
80 */
81 void
82 add_user_to_channel(struct Channel *chptr, struct Client *who,
83 unsigned int flags, int flood_ctrl)
84 {
85 struct Membership *ms = NULL;
86
87 if (GlobalSetOptions.joinfloodtime > 0)
88 {
89 if (flood_ctrl)
90 chptr->number_joined++;
91
92 chptr->number_joined -= (CurrentTime - chptr->last_join_time) *
93 (((float)GlobalSetOptions.joinfloodcount) /
94 (float)GlobalSetOptions.joinfloodtime);
95
96 if (chptr->number_joined <= 0)
97 {
98 chptr->number_joined = 0;
99 ClearJoinFloodNoticed(chptr);
100 }
101 else if (chptr->number_joined >= GlobalSetOptions.joinfloodcount)
102 {
103 chptr->number_joined = GlobalSetOptions.joinfloodcount;
104
105 if (!IsSetJoinFloodNoticed(chptr))
106 {
107 SetJoinFloodNoticed(chptr);
108 sendto_realops_flags(UMODE_BOTS, L_ALL,
109 "Possible Join Flooder %s on %s target: %s",
110 get_client_name(who, HIDE_IP),
111 who->servptr->name, chptr->chname);
112 }
113 }
114
115 chptr->last_join_time = CurrentTime;
116 }
117
118 ms = BlockHeapAlloc(member_heap);
119 ms->client_p = who;
120 ms->chptr = chptr;
121 ms->flags = flags;
122
123 dlinkAdd(ms, &ms->channode, &chptr->members);
124 dlinkAdd(ms, &ms->usernode, &who->channel);
125 }
126
127 /*! \brief deletes an user from a channel by removing a link in the
128 * channels member chain.
129 * \param member pointer to Membership struct
130 */
131 void
132 remove_user_from_channel(struct Membership *member)
133 {
134 struct Client *client_p = member->client_p;
135 struct Channel *chptr = member->chptr;
136
137 dlinkDelete(&member->channode, &chptr->members);
138 dlinkDelete(&member->usernode, &client_p->channel);
139
140 BlockHeapFree(member_heap, member);
141
142 if (chptr->members.head == NULL)
143 {
144 assert(dlink_list_length(&chptr->members) == 0);
145 destroy_channel(chptr);
146 }
147 }
148
149 /* send_members()
150 *
151 * inputs -
152 * output - NONE
153 * side effects -
154 */
155 static void
156 send_members(struct Client *client_p, struct Channel *chptr,
157 char *lmodebuf, char *lparabuf)
158 {
159 struct Membership *ms;
160 dlink_node *ptr;
161 int tlen; /* length of text to append */
162 char *t, *start; /* temp char pointer */
163
164 start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:",
165 ID_or_name(&me, client_p),
166 (unsigned long)chptr->channelts,
167 chptr->chname, lmodebuf, lparabuf);
168
169 DLINK_FOREACH(ptr, chptr->members.head)
170 {
171 ms = ptr->data;
172
173 tlen = strlen(IsCapable(client_p, CAP_TS6) ?
174 ID(ms->client_p) : ms->client_p->name) + 1; /* nick + space */
175
176 if (ms->flags & CHFL_CHANOP)
177 tlen++;
178 #ifdef HALFOPS
179 else if (ms->flags & CHFL_HALFOP)
180 tlen++;
181 #endif
182 if (ms->flags & CHFL_VOICE)
183 tlen++;
184
185 /* space will be converted into CR, but we also need space for LF..
186 * That's why we use '- 1' here
187 * -adx */
188 if (t + tlen - buf > sizeof(buf) - 1)
189 {
190 *(t - 1) = '\0'; /* kill the space and terminate the string */
191 sendto_one(client_p, "%s", buf);
192 t = start;
193 }
194
195 if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP)))
196 *t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ?
197 '%' : '@';
198 if ((ms->flags & CHFL_VOICE))
199 *t++ = '+';
200
201 if (IsCapable(client_p, CAP_TS6))
202 strcpy(t, ID(ms->client_p));
203 else
204 strcpy(t, ms->client_p->name);
205 t += strlen(t);
206 *t++ = ' ';
207 }
208
209 /* should always be non-NULL unless we have a kind of persistent channels */
210 if (chptr->members.head != NULL)
211 t--; /* take the space out */
212 *t = '\0';
213 sendto_one(client_p, "%s", buf);
214 }
215
216 /*! \brief sends +b/+e/+I
217 * \param client_p client pointer to server
218 * \param chptr pointer to channel
219 * \param top pointer to top of mode link list to send
220 * \param flag char flag flagging type of mode. Currently this can be 'b', e' or 'I'
221 */
222 static void
223 send_mode_list(struct Client *client_p, struct Channel *chptr,
224 dlink_list *top, char flag)
225 {
226 int ts5 = !IsCapable(client_p, CAP_TS6);
227 dlink_node *lp;
228 struct Ban *banptr;
229 char pbuf[IRCD_BUFSIZE];
230 int tlen, mlen, cur_len, count = 0;
231 char *mp = NULL, *pp = pbuf;
232
233 if (top == NULL || top->length == 0)
234 return;
235
236 if (ts5)
237 mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname);
238 else
239 mlen = ircsprintf(buf, ":%s BMASK %lu %s %c :", me.id,
240 (unsigned long)chptr->channelts, chptr->chname, flag);
241
242 /* MODE needs additional one byte for space between buf and pbuf */
243 cur_len = mlen + ts5;
244 mp = buf + mlen;
245
246 DLINK_FOREACH(lp, top->head)
247 {
248 banptr = lp->data;
249
250 /* must add another b/e/I letter if we use MODE */
251 tlen = banptr->len + 3 + ts5;
252
253 /*
254 * send buffer and start over if we cannot fit another ban,
255 * or if the target is non-ts6 and we have too many modes in
256 * in this line.
257 */
258 if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 ||
259 (!IsCapable(client_p, CAP_TS6) &&
260 (count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN)))
261 {
262 *(pp - 1) = '\0'; /* get rid of trailing space on buffer */
263 sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf);
264
265 cur_len = mlen + ts5;
266 mp = buf + mlen;
267 pp = pbuf;
268 count = 0;
269 }
270
271 count++;
272 if (ts5)
273 {
274 *mp++ = flag;
275 *mp = '\0';
276 }
277
278 pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username,
279 banptr->host);
280 cur_len += tlen;
281 }
282
283 *(pp - 1) = '\0'; /* get rid of trailing space on buffer */
284 sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf);
285 }
286
287 /*! \brief send "client_p" a full list of the modes for channel chptr
288 * \param client_p pointer to client client_p
289 * \param chptr pointer to channel pointer
290 */
291 void
292 send_channel_modes(struct Client *client_p, struct Channel *chptr)
293 {
294 if (chptr->chname[0] != '#')
295 return;
296
297 *modebuf = *parabuf = '\0';
298 channel_modes(chptr, client_p, modebuf, parabuf);
299 send_members(client_p, chptr, modebuf, parabuf);
300
301 send_mode_list(client_p, chptr, &chptr->banlist, 'b');
302
303 if (IsCapable(client_p, CAP_EX))
304 send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
305 if (IsCapable(client_p, CAP_IE))
306 send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
307 }
308
309 /*! \brief check channel name for invalid characters
310 * \param name pointer to channel name string
311 * \return TRUE (1) if name ok, FALSE (0) otherwise
312 */
313 int
314 check_channel_name(const char *name)
315 {
316 const unsigned char *p = (const unsigned char *)name;
317 assert(name != NULL);
318
319 for (; *p; ++p)
320 if (!IsChanChar(*p))
321 return 0;
322
323 return 1;
324 }
325
326 void
327 remove_ban(struct Ban *bptr, dlink_list *list)
328 {
329 dlinkDelete(&bptr->node, list);
330
331 MyFree(bptr->name);
332 MyFree(bptr->username);
333 MyFree(bptr->host);
334 MyFree(bptr->who);
335
336 BlockHeapFree(ban_heap, bptr);
337 }
338
339 /* free_channel_list()
340 *
341 * inputs - pointer to dlink_list
342 * output - NONE
343 * side effects -
344 */
345 void
346 free_channel_list(dlink_list *list)
347 {
348 dlink_node *ptr = NULL, *next_ptr = NULL;
349
350 DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
351 remove_ban(ptr->data, list);
352
353 assert(list->tail == NULL && list->head == NULL);
354 }
355
356 /*! \brief Get Channel block for chname (and allocate a new channel
357 * block, if it didn't exist before)
358 * \param client_p client pointer
359 * \param chname channel name
360 * \param isnew pointer to int flag whether channel was newly created or not
361 * \return channel block or NULL if illegal name
362 */
363 struct Channel *
364 get_or_create_channel(struct Client *client_p, const char *chname, int *isnew)
365 {
366 struct Channel *chptr = NULL;
367 int len;
368
369 if (EmptyString(chname))
370 return NULL;
371
372 if ((len = strlen(chname)) > CHANNELLEN)
373 {
374 if (IsServer(client_p))
375 sendto_realops_flags(UMODE_DEBUG, L_ALL,
376 "*** Long channel name from %s (%d > %d): %s",
377 client_p->name, len, CHANNELLEN, chname);
378 return NULL;
379 }
380
381 if ((chptr = hash_find_channel(chname)) != NULL)
382 {
383 if (isnew != NULL)
384 *isnew = 0;
385
386 return chptr;
387 }
388
389 if (isnew != NULL)
390 *isnew = 1;
391
392 chptr = BlockHeapAlloc(channel_heap);
393 /* doesn't hurt to set it here */
394 chptr->channelts = chptr->last_join_time = CurrentTime;
395
396 strlcpy(chptr->chname, chname, sizeof(chptr->chname));
397 dlinkAdd(chptr, &chptr->node, &global_channel_list);
398
399 hash_add_channel(chptr);
400
401 return chptr;
402 }
403
404 /*! \brief walk through this channel, and destroy it.
405 * \param chptr channel pointer
406 */
407 void
408 destroy_channel(struct Channel *chptr)
409 {
410 dlink_node *ptr = NULL, *ptr_next = NULL;
411
412 DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head)
413 del_invite(chptr, ptr->data);
414
415 /* free ban/exception/invex lists */
416 free_channel_list(&chptr->banlist);
417 free_channel_list(&chptr->exceptlist);
418 free_channel_list(&chptr->invexlist);
419
420 /* Free the topic */
421 free_topic(chptr);
422
423 dlinkDelete(&chptr->node, &global_channel_list);
424 hash_del_channel(chptr);
425
426 if (ServerInfo.hub)
427 if ((ptr = dlinkFindDelete(&lazylink_channels, chptr)))
428 free_dlink_node(ptr);
429
430 BlockHeapFree(channel_heap, chptr);
431 }
432
433 /*!
434 * \param chptr pointer to channel
435 * \return string pointer "=" if public, "@" if secret else "*"
436 */
437 static const char *
438 channel_pub_or_secret(struct Channel *chptr)
439 {
440 if (SecretChannel(chptr))
441 return "@";
442 if (ParanoidChannel(chptr))
443 return "*";
444 return "=";
445 }
446
447 /*! \brief lists all names on given channel
448 * \param source_p pointer to client struct requesting names
449 * \param chptr pointer to channel block
450 * \param show_eon show ENDOFNAMES numeric or not
451 * (don't want it with /names with no params)
452 */
453 void
454 channel_member_names(struct Client *source_p, struct Channel *chptr,
455 int show_eon)
456 {
457 struct Client *target_p = NULL;
458 struct Membership *ms = NULL;
459 dlink_node *ptr = NULL;
460 char lbuf[IRCD_BUFSIZE + 1];
461 char *t = NULL, *start = NULL;
462 int tlen = 0;
463 int is_member = IsMember(source_p, chptr);
464
465 if (PubChannel(chptr) || is_member)
466 {
467 t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY),
468 me.name, source_p->name,
469 channel_pub_or_secret(chptr),
470 chptr->chname);
471 start = t;
472
473 DLINK_FOREACH(ptr, chptr->members.head)
474 {
475 ms = ptr->data;
476 target_p = ms->client_p;
477
478 if (IsInvisible(target_p) && !is_member)
479 continue;
480
481 tlen = strlen(target_p->name) + 1; /* nick + space */
482
483 if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
484 ++tlen;
485 if (t + tlen - lbuf > IRCD_BUFSIZE)
486 {
487 *(t - 1) = '\0';
488 sendto_one(source_p, "%s", lbuf);
489 t = start;
490 }
491
492 t += ircsprintf(t, "%s%s ", get_member_status(ms, NO),
493 target_p->name);
494 }
495
496 if (tlen != 0)
497 {
498 *(t - 1) = '\0';
499 sendto_one(source_p, "%s", lbuf);
500 }
501 }
502
503 if (show_eon)
504 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
505 me.name, source_p->name, chptr->chname);
506 }
507
508 /*! \brief adds client to invite list
509 * \param chptr pointer to channel block
510 * \param who pointer to client to add invite to
511 */
512 void
513 add_invite(struct Channel *chptr, struct Client *who)
514 {
515 del_invite(chptr, who);
516
517 /*
518 * delete last link in chain if the list is max length
519 */
520 if (dlink_list_length(&who->localClient->invited) >=
521 ConfigChannel.max_chans_per_user)
522 del_invite(who->localClient->invited.tail->data, who);
523
524 /* add client to channel invite list */
525 dlinkAdd(who, make_dlink_node(), &chptr->invites);
526
527 /* add channel to the end of the client invite list */
528 dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited);
529 }
530
531 /*! \brief Delete Invite block from channel invite list
532 * and client invite list
533 * \param chptr pointer to Channel struct
534 * \param who pointer to client to remove invites from
535 */
536 void
537 del_invite(struct Channel *chptr, struct Client *who)
538 {
539 dlink_node *ptr = NULL;
540
541 if ((ptr = dlinkFindDelete(&who->localClient->invited, chptr)))
542 free_dlink_node(ptr);
543
544 if ((ptr = dlinkFindDelete(&chptr->invites, who)))
545 free_dlink_node(ptr);
546 }
547
548 /* get_member_status()
549 *
550 * inputs - pointer to struct Membership
551 * - YES if we can combine different flags
552 * output - string either @, +, % or "" depending on whether
553 * chanop, voiced or user
554 * side effects -
555 *
556 * NOTE: Returned string is usually a static buffer
557 * (like in get_client_name)
558 */
559 const char *
560 get_member_status(const struct Membership *ms, int combine)
561 {
562 static char buffer[4];
563 char *p = NULL;
564
565 if (ms == NULL)
566 return "";
567 p = buffer;
568
569 if (ms->flags & CHFL_CHANOP)
570 {
571 if (!combine)
572 return "@";
573 *p++ = '@';
574 }
575
576 #ifdef HALFOPS
577 if (ms->flags & CHFL_HALFOP)
578 {
579 if (!combine)
580 return "%";
581 *p++ = '%';
582 }
583 #endif
584
585 if (ms->flags & CHFL_VOICE)
586 *p++ = '+';
587 *p = '\0';
588
589 return buffer;
590 }
591
592 /*!
593 * \param who pointer to Client to check
594 * \param list pointer to ban list to search
595 * \return 1 if ban found for given n!u\@h mask, 0 otherwise
596 *
597 */
598 static int
599 find_bmask(const struct Client *who, const dlink_list *const list)
600 {
601 const dlink_node *ptr = NULL;
602
603 DLINK_FOREACH(ptr, list->head)
604 {
605 struct Ban *bp = ptr->data;
606
607 if (match(bp->name, who->name) && match(bp->username, who->username))
608 {
609 switch (bp->type)
610 {
611 case HM_HOST:
612 if (match(bp->host, who->host) || match(bp->host, who->sockhost))
613 return 1;
614 break;
615 case HM_IPV4:
616 if (who->localClient->aftype == AF_INET)
617 if (match_ipv4(&who->localClient->ip, &bp->addr, bp->bits))
618 return 1;
619 break;
620 #ifdef IPV6
621 case HM_IPV6:
622 if (who->localClient->aftype == AF_INET6)
623 if (match_ipv6(&who->localClient->ip, &bp->addr, bp->bits))
624 return 1;
625 break;
626 #endif
627 default:
628 assert(0);
629 }
630 }
631 }
632
633 return 0;
634 }
635
636 /*!
637 * \param chptr pointer to channel block
638 * \param who pointer to client to check access fo
639 * \return 0 if not banned, 1 otherwise
640 */
641 int
642 is_banned(struct Channel *chptr, struct Client *who)
643 {
644 assert(IsClient(who));
645
646 return find_bmask(who, &chptr->banlist) && (!ConfigChannel.use_except ||
647 !find_bmask(who, &chptr->exceptlist));
648 }
649
650 /*!
651 * \param source_p pointer to client attempting to join
652 * \param chptr pointer to channel
653 * \param key key sent by client attempting to join if present
654 * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
655 * or 0 if allowed to join.
656 */
657 int
658 can_join(struct Client *source_p, struct Channel *chptr, const char *key)
659 {
660 if (find_bmask(source_p, &chptr->banlist))
661 if (!ConfigChannel.use_except || !find_bmask(source_p, &chptr->exceptlist))
662 return ERR_BANNEDFROMCHAN;
663
664 if (chptr->mode.mode & MODE_INVITEONLY)
665 if (!dlinkFind(&source_p->localClient->invited, chptr))
666 if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist))
667 return ERR_INVITEONLYCHAN;
668
669 if (chptr->mode.key[0] && (EmptyString(key) || irccmp(chptr->mode.key, key)))
670 return ERR_BADCHANNELKEY;
671
672 if (chptr->mode.limit && dlink_list_length(&chptr->members) >=
673 chptr->mode.limit)
674 return ERR_CHANNELISFULL;
675
676 return 0;
677 }
678
679 int
680 has_member_flags(struct Membership *ms, unsigned int flags)
681 {
682 if (ms != NULL)
683 return ms->flags & flags;
684 return 0;
685 }
686
687 struct Membership *
688 find_channel_link(struct Client *client_p, struct Channel *chptr)
689 {
690 dlink_node *ptr = NULL;
691
692 if (!IsClient(client_p))
693 return NULL;
694
695 DLINK_FOREACH(ptr, client_p->channel.head)
696 if (((struct Membership *)ptr->data)->chptr == chptr)
697 return (struct Membership *)ptr->data;
698
699 return NULL;
700 }
701
702 /*!
703 * \param chptr pointer to Channel struct
704 * \param source_p pointer to Client struct
705 * \return CAN_SEND_OPV if op or voiced on channel\n
706 * CAN_SEND_NONOP if can send to channel but is not an op\n
707 * CAN_SEND_NO if they cannot send to channel\n
708 */
709 int
710 can_send(struct Channel *chptr, struct Client *source_p)
711 {
712 struct Membership *ms = NULL;
713
714 if (IsServer(source_p))
715 return CAN_SEND_OPV;
716
717 if (MyClient(source_p) && !IsExemptResv(source_p) &&
718 !(IsOper(source_p) && ConfigFileEntry.oper_pass_resv) &&
719 (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels))
720 return CAN_SEND_NO;
721
722 if ((ms = find_channel_link(source_p, chptr)) == NULL)
723 {
724 if (chptr->mode.mode & MODE_NOPRIVMSGS)
725 return CAN_SEND_NO;
726 }
727 else
728 {
729 if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE))
730 return CAN_SEND_OPV;
731
732 /* cache can send if quiet_on_ban and banned */
733 if (ConfigChannel.quiet_on_ban && MyClient(source_p))
734 {
735 if (ms->flags & CHFL_BAN_SILENCED)
736 return CAN_SEND_NO;
737
738 if (!(ms->flags & CHFL_BAN_CHECKED))
739 {
740 if (is_banned(chptr, source_p))
741 {
742 ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED);
743 return CAN_SEND_NO;
744 }
745
746 ms->flags |= CHFL_BAN_CHECKED;
747 }
748 }
749 }
750
751 if (chptr->mode.mode & MODE_MODERATED)
752 return CAN_SEND_NO;
753
754 return CAN_SEND_NONOP;
755 }
756
757 /*! \brief Checks to see if given client can send a part message
758 * \param member pointer to channel membership
759 * \param chptr pointer to channel struct
760 * \param source_p pointer to struct Client to check
761 */
762 int
763 can_send_part(struct Membership *member, struct Channel *chptr,
764 struct Client *source_p)
765 {
766 if (has_member_flags(member, CHFL_CHANOP|CHFL_HALFOP))
767 return CAN_SEND_OPV;
768
769 if (chptr->mode.mode & MODE_MODERATED)
770 return CAN_SEND_NO;
771
772 if (ConfigChannel.quiet_on_ban && MyClient(source_p) &&
773 is_banned(chptr, source_p))
774 return CAN_SEND_NO;
775
776 return CAN_SEND_NONOP;
777 }
778
779 /*! \brief Updates the client's oper_warn_count_down, warns the
780 * IRC operators if necessary, and updates
781 * join_leave_countdown as needed.
782 * \param source_p pointer to struct Client to check
783 * \param name channel name or NULL if this is a part.
784 */
785 void
786 check_spambot_warning(struct Client *source_p, const char *name)
787 {
788 int t_delta = 0;
789 int decrement_count = 0;
790
791 if ((GlobalSetOptions.spam_num &&
792 (source_p->localClient->join_leave_count >=
793 GlobalSetOptions.spam_num)))
794 {
795 if (source_p->localClient->oper_warn_count_down > 0)
796 source_p->localClient->oper_warn_count_down--;
797 else
798 source_p->localClient->oper_warn_count_down = 0;
799
800 if (source_p->localClient->oper_warn_count_down == 0)
801 {
802 /* Its already known as a possible spambot */
803 if (name != NULL)
804 sendto_realops_flags(UMODE_BOTS, L_ALL,
805 "User %s (%s@%s) trying to join %s is a possible spambot",
806 source_p->name, source_p->username,
807 source_p->host, name);
808 else
809 sendto_realops_flags(UMODE_BOTS, L_ALL,
810 "User %s (%s@%s) is a possible spambot",
811 source_p->name, source_p->username,
812 source_p->host);
813 source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
814 }
815 }
816 else
817 {
818 if ((t_delta = (CurrentTime - source_p->localClient->last_leave_time)) >
819 JOIN_LEAVE_COUNT_EXPIRE_TIME)
820 {
821 decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
822 if (decrement_count > source_p->localClient->join_leave_count)
823 source_p->localClient->join_leave_count = 0;
824 else
825 source_p->localClient->join_leave_count -= decrement_count;
826 }
827 else
828 {
829 if ((CurrentTime - (source_p->localClient->last_join_time)) <
830 GlobalSetOptions.spam_time)
831 {
832 /* oh, its a possible spambot */
833 source_p->localClient->join_leave_count++;
834 }
835 }
836
837 if (name != NULL)
838 source_p->localClient->last_join_time = CurrentTime;
839 else
840 source_p->localClient->last_leave_time = CurrentTime;
841 }
842 }
843
844 /*! \brief compares usercount and servercount against their split
845 * values and adjusts splitmode accordingly
846 * \param unused Unused address pointer
847 */
848 void
849 check_splitmode(void *unused)
850 {
851 if (splitchecking && (ConfigChannel.no_join_on_split ||
852 ConfigChannel.no_create_on_split))
853 {
854 const unsigned int server = dlink_list_length(&global_serv_list);
855
856 if (!splitmode && ((server < split_servers) || (Count.total < split_users)))
857 {
858 splitmode = 1;
859
860 sendto_realops_flags(UMODE_ALL,L_ALL,
861 "Network split, activating splitmode");
862 eventAddIsh("check_splitmode", check_splitmode, NULL, 10);
863 }
864 else if (splitmode && (server > split_servers) && (Count.total > split_users))
865 {
866 splitmode = 0;
867
868 sendto_realops_flags(UMODE_ALL, L_ALL,
869 "Network rejoined, deactivating splitmode");
870 eventDelete(check_splitmode, NULL);
871 }
872 }
873 }
874
875 /*! \brief Allocates a new topic
876 * \param chptr Channel to allocate a new topic for
877 */
878 static void
879 allocate_topic(struct Channel *chptr)
880 {
881 void *ptr = NULL;
882
883 if (chptr == NULL)
884 return;
885
886 ptr = BlockHeapAlloc(topic_heap);
887
888 /* Basically we allocate one large block for the topic and
889 * the topic info. We then split it up into two and shove it
890 * in the chptr
891 */
892 chptr->topic = ptr;
893 chptr->topic_info = (char *)ptr + TOPICLEN+1;
894 *chptr->topic = '\0';
895 *chptr->topic_info = '\0';
896 }
897
898 void
899 free_topic(struct Channel *chptr)
900 {
901 void *ptr = NULL;
902 assert(chptr);
903 if (chptr->topic == NULL)
904 return;
905
906 /*
907 * If you change allocate_topic you MUST change this as well
908 */
909 ptr = chptr->topic;
910 BlockHeapFree(topic_heap, ptr);
911 chptr->topic = NULL;
912 chptr->topic_info = NULL;
913 }
914
915 /*! \brief Sets the channel topic for chptr
916 * \param chptr Pointer to struct Channel
917 * \param topic The topic string
918 * \param topic_info n!u\@h formatted string of the topic setter
919 * \param topicts timestamp on the topic
920 */
921 void
922 set_channel_topic(struct Channel *chptr, const char *topic,
923 const char *topic_info, time_t topicts)
924 {
925 if (!EmptyString(topic))
926 {
927 if (chptr->topic == NULL)
928 allocate_topic(chptr);
929
930 strlcpy(chptr->topic, topic, TOPICLEN+1);
931 strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN);
932 chptr->topic_time = topicts;
933 }
934 else
935 {
936 if (chptr->topic != NULL)
937 free_topic(chptr);
938
939 chptr->topic_time = 0;
940 }
941 }
942

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision