ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/src/channel.c
Revision: 634
Committed: Thu Jun 1 12:34:29 2006 UTC (17 years, 10 months ago) by db
Content type: text/x-csrc
File size: 24747 byte(s)
Log Message:
- At least I noticed it myself, I got it completely backwards
  when folding in Michael's suggested optimisation.


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 "tools.h"
29 #include "channel.h"
30 #include "channel_mode.h"
31 #include "client.h"
32 #include "common.h"
33 #include "hash.h"
34 #include "hostmask.h"
35 #include "irc_string.h"
36 #include "sprintf_irc.h"
37 #include "ircd.h"
38 #include "list.h"
39 #include "numeric.h"
40 #include "s_serv.h" /* captab */
41 #include "s_user.h"
42 #include "send.h"
43 #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
44 #include "event.h"
45 #include "memory.h"
46 #include "balloc.h"
47
48 struct config_channel_entry ConfigChannel;
49 dlink_list global_channel_list = { NULL, NULL, 0 };
50 dlink_list lazylink_channels = { NULL, NULL, 0 };
51 BlockHeap *ban_heap; /*! \todo ban_heap shouldn't be a global var */
52
53 static BlockHeap *topic_heap = NULL;
54 static BlockHeap *member_heap = NULL;
55 static BlockHeap *channel_heap = NULL;
56
57 static char buf[IRCD_BUFSIZE];
58 static char modebuf[MODEBUFLEN];
59 static char parabuf[MODEBUFLEN];
60
61
62 /*! \brief Initializes the channel blockheap, adds known channel CAPAB
63 */
64 void
65 init_channels(void)
66 {
67 add_capability("EX", CAP_EX, 1);
68 add_capability("IE", CAP_IE, 1);
69 add_capability("CHW", CAP_CHW, 1);
70
71 channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE);
72 ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE);
73 topic_heap = BlockHeapCreate("topic", TOPICLEN+1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE);
74 member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2);
75 }
76
77 /*! \brief adds a user to a channel by adding another link to the
78 * channels member chain.
79 * \param chptr pointer to channel to add client to
80 * \param who pointer to client (who) to add
81 * \param flags flags for chanops etc
82 * \param flood_ctrl whether to count this join in flood calculations
83 */
84 void
85 add_user_to_channel(struct Channel *chptr, struct Client *who,
86 unsigned int flags, int flood_ctrl)
87 {
88 struct Membership *ms = NULL;
89
90 if (GlobalSetOptions.joinfloodtime > 0)
91 {
92 if (flood_ctrl)
93 chptr->number_joined++;
94
95 chptr->number_joined -= (CurrentTime - chptr->last_join_time) *
96 (((float)GlobalSetOptions.joinfloodcount) /
97 (float)GlobalSetOptions.joinfloodtime);
98
99 if (chptr->number_joined <= 0)
100 {
101 chptr->number_joined = 0;
102 ClearJoinFloodNoticed(chptr);
103 }
104 else if (chptr->number_joined >= GlobalSetOptions.joinfloodcount)
105 {
106 chptr->number_joined = GlobalSetOptions.joinfloodcount;
107
108 if (!IsSetJoinFloodNoticed(chptr))
109 {
110 SetJoinFloodNoticed(chptr);
111 sendto_realops_flags(UMODE_BOTS, L_ALL,
112 "Possible Join Flooder %s on %s target: %s",
113 get_client_name(who, HIDE_IP),
114 who->servptr->name, chptr->chname);
115 }
116 }
117
118 chptr->last_join_time = CurrentTime;
119 }
120
121 ms = BlockHeapAlloc(member_heap);
122 ms->client_p = who;
123 ms->chptr = chptr;
124 ms->flags = flags;
125
126 dlinkAdd(ms, &ms->channode, &chptr->members);
127 dlinkAdd(ms, &ms->usernode, &who->channel);
128 }
129
130 /*! \brief deletes an user from a channel by removing a link in the
131 * channels member chain.
132 * \param member pointer to Membership struct
133 */
134 void
135 remove_user_from_channel(struct Membership *member)
136 {
137 struct Client *client_p = member->client_p;
138 struct Channel *chptr = member->chptr;
139
140 dlinkDelete(&member->channode, &chptr->members);
141 dlinkDelete(&member->usernode, &client_p->channel);
142
143 BlockHeapFree(member_heap, member);
144
145 if (dlink_list_length(&chptr->members) == 0)
146 destroy_channel(chptr);
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 * \param local indicates whether it's a local or remote creation
312 * \return 0 if invalid, 1 otherwise
313 */
314 int
315 check_channel_name(const char *name, int local)
316 {
317 const char *p = name;
318 int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN;
319 assert(name != NULL);
320
321 if (!IsChanPrefix(*p))
322 return 0;
323
324 if (!local || !ConfigChannel.disable_fake_channels)
325 {
326 while (*++p)
327 if (!IsChanChar(*p))
328 return 0;
329 }
330 else
331 {
332 while (*++p)
333 if (!IsVisibleChanChar(*p))
334 return 0;
335 }
336
337 return p - name <= max_length;
338 }
339
340 void
341 remove_ban(struct Ban *bptr, dlink_list *list)
342 {
343 dlinkDelete(&bptr->node, list);
344
345 MyFree(bptr->name);
346 MyFree(bptr->username);
347 MyFree(bptr->host);
348 MyFree(bptr->who);
349
350 BlockHeapFree(ban_heap, bptr);
351 }
352
353 /* free_channel_list()
354 *
355 * inputs - pointer to dlink_list
356 * output - NONE
357 * side effects -
358 */
359 void
360 free_channel_list(dlink_list *list)
361 {
362 dlink_node *ptr = NULL, *next_ptr = NULL;
363
364 DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
365 remove_ban(ptr->data, list);
366
367 assert(list->tail == NULL && list->head == NULL);
368 }
369
370 /*! \brief Get Channel block for chname (and allocate a new channel
371 * block, if it didn't exist before)
372 * \param chname channel name
373 * \return channel block
374 */
375 struct Channel *
376 make_channel(const char *chname)
377 {
378 struct Channel *chptr = NULL;
379
380 assert(!EmptyString(chname));
381
382 chptr = BlockHeapAlloc(channel_heap);
383
384 /* doesn't hurt to set it here */
385 chptr->channelts = CurrentTime;
386 chptr->last_join_time = CurrentTime;
387
388 strlcpy(chptr->chname, chname, sizeof(chptr->chname));
389 dlinkAdd(chptr, &chptr->node, &global_channel_list);
390
391 hash_add_channel(chptr);
392
393 return chptr;
394 }
395
396 /*! \brief walk through this channel, and destroy it.
397 * \param chptr channel pointer
398 */
399 void
400 destroy_channel(struct Channel *chptr)
401 {
402 dlink_node *ptr = NULL, *ptr_next = NULL;
403
404 DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head)
405 del_invite(chptr, ptr->data);
406
407 /* free ban/exception/invex lists */
408 free_channel_list(&chptr->banlist);
409 free_channel_list(&chptr->exceptlist);
410 free_channel_list(&chptr->invexlist);
411
412 /* Free the topic */
413 free_topic(chptr);
414
415 dlinkDelete(&chptr->node, &global_channel_list);
416 hash_del_channel(chptr);
417
418 if (ServerInfo.hub)
419 if ((ptr = dlinkFindDelete(&lazylink_channels, chptr)))
420 free_dlink_node(ptr);
421
422 BlockHeapFree(channel_heap, chptr);
423 }
424
425 /*!
426 * \param chptr pointer to channel
427 * \return string pointer "=" if public, "@" if secret else "*"
428 */
429 static const char *
430 channel_pub_or_secret(struct Channel *chptr)
431 {
432 if (SecretChannel(chptr))
433 return "@";
434 if (PrivateChannel(chptr))
435 return "*";
436 return "=";
437 }
438
439 /*! \brief lists all names on given channel
440 * \param source_p pointer to client struct requesting names
441 * \param chptr pointer to channel block
442 * \param show_eon show ENDOFNAMES numeric or not
443 * (don't want it with /names with no params)
444 */
445 void
446 channel_member_names(struct Client *source_p, struct Channel *chptr,
447 int show_eon)
448 {
449 struct Client *target_p = NULL;
450 struct Membership *ms = NULL;
451 dlink_node *ptr = NULL;
452 char lbuf[IRCD_BUFSIZE + 1];
453 char *t = NULL, *start = NULL;
454 int tlen = 0;
455 int is_member = IsMember(source_p, chptr);
456 int multi_prefix = (source_p->localClient->cap_active & CAP_MULTI_PREFIX) != 0;
457
458 if (PubChannel(chptr) || is_member)
459 {
460 t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY),
461 me.name, source_p->name,
462 channel_pub_or_secret(chptr),
463 chptr->chname);
464 start = t;
465
466 DLINK_FOREACH(ptr, chptr->members.head)
467 {
468 ms = ptr->data;
469 target_p = ms->client_p;
470
471 if (IsInvisible(target_p) && !is_member)
472 continue;
473
474 tlen = strlen(target_p->name) + 1; /* nick + space */
475
476 if (!multi_prefix)
477 {
478 if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
479 ++tlen;
480 }
481 else
482 {
483 if (ms->flags & CHFL_CHANOP)
484 ++tlen;
485 if (ms->flags & CHFL_HALFOP)
486 ++tlen;
487 if (ms->flags & CHFL_VOICE)
488 ++tlen;
489 }
490
491 if (t + tlen - lbuf > IRCD_BUFSIZE)
492 {
493 *(t - 1) = '\0';
494 sendto_one(source_p, "%s", lbuf);
495 t = start;
496 }
497
498 t += ircsprintf(t, "%s%s ", get_member_status(ms, multi_prefix),
499 target_p->name);
500 }
501
502 if (tlen != 0)
503 {
504 *(t - 1) = '\0';
505 sendto_one(source_p, "%s", lbuf);
506 }
507 }
508
509 if (show_eon)
510 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
511 me.name, source_p->name, chptr->chname);
512 }
513
514 /*! \brief adds client to invite list
515 * \param chptr pointer to channel block
516 * \param who pointer to client to add invite to
517 */
518 void
519 add_invite(struct Channel *chptr, struct Client *who)
520 {
521 del_invite(chptr, who);
522
523 /*
524 * delete last link in chain if the list is max length
525 */
526 if (dlink_list_length(&who->localClient->invited) >=
527 ConfigChannel.max_chans_per_user)
528 del_invite(who->localClient->invited.tail->data, who);
529
530 /* add client to channel invite list */
531 dlinkAdd(who, make_dlink_node(), &chptr->invites);
532
533 /* add channel to the end of the client invite list */
534 dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited);
535 }
536
537 /*! \brief Delete Invite block from channel invite list
538 * and client invite list
539 * \param chptr pointer to Channel struct
540 * \param who pointer to client to remove invites from
541 */
542 void
543 del_invite(struct Channel *chptr, struct Client *who)
544 {
545 dlink_node *ptr = NULL;
546
547 if ((ptr = dlinkFindDelete(&who->localClient->invited, chptr)))
548 free_dlink_node(ptr);
549
550 if ((ptr = dlinkFindDelete(&chptr->invites, who)))
551 free_dlink_node(ptr);
552 }
553
554 /* get_member_status()
555 *
556 * inputs - pointer to struct Membership
557 * - YES if we can combine different flags
558 * output - string either @, +, % or "" depending on whether
559 * chanop, voiced or user
560 * side effects -
561 *
562 * NOTE: Returned string is usually a static buffer
563 * (like in get_client_name)
564 */
565 const char *
566 get_member_status(const struct Membership *ms, int combine)
567 {
568 static char buffer[4];
569 char *p = NULL;
570
571 if (ms == NULL)
572 return "";
573 p = buffer;
574
575 if (ms->flags & CHFL_CHANOP)
576 {
577 if (!combine)
578 return "@";
579 *p++ = '@';
580 }
581
582 #ifdef HALFOPS
583 if (ms->flags & CHFL_HALFOP)
584 {
585 if (!combine)
586 return "%";
587 *p++ = '%';
588 }
589 #endif
590
591 if (ms->flags & CHFL_VOICE)
592 *p++ = '+';
593 *p = '\0';
594
595 return buffer;
596 }
597
598 /*!
599 * \param who pointer to Client to check
600 * \param list pointer to ban list to search
601 * \return 1 if ban found for given n!u\@h mask, 0 otherwise
602 *
603 */
604 static int
605 find_bmask(const struct Client *who, const dlink_list *const list)
606 {
607 const dlink_node *ptr = NULL;
608
609 DLINK_FOREACH(ptr, list->head)
610 {
611 struct Ban *bp = ptr->data;
612
613 if (match(bp->name, who->name) && match(bp->username, who->username))
614 {
615 switch (bp->type)
616 {
617 case HM_HOST:
618 if (match(bp->host, who->host) || match(bp->host, who->sockhost))
619 return 1;
620 break;
621 case HM_IPV4:
622 if (who->localClient->aftype == AF_INET)
623 if (match_ipv4(&who->localClient->ip, &bp->addr, bp->bits))
624 return 1;
625 break;
626 #ifdef IPV6
627 case HM_IPV6:
628 if (who->localClient->aftype == AF_INET6)
629 if (match_ipv6(&who->localClient->ip, &bp->addr, bp->bits))
630 return 1;
631 break;
632 #endif
633 default:
634 assert(0);
635 }
636 }
637 }
638
639 return 0;
640 }
641
642 /*!
643 * \param chptr pointer to channel block
644 * \param who pointer to client to check access fo
645 * \return 0 if not banned, 1 otherwise
646 */
647 int
648 is_banned(struct Channel *chptr, struct Client *who)
649 {
650 if (find_bmask(who, &chptr->banlist))
651 if (!ConfigChannel.use_except || !find_bmask(who, &chptr->exceptlist))
652 return 1;
653
654 return 0;
655 }
656
657 /*!
658 * \param source_p pointer to client attempting to join
659 * \param chptr pointer to channel
660 * \param key key sent by client attempting to join if present
661 * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
662 * or 0 if allowed to join.
663 */
664 int
665 can_join(struct Client *source_p, struct Channel *chptr, const char *key)
666 {
667 if (is_banned(chptr, source_p))
668 return ERR_BANNEDFROMCHAN;
669
670 if (chptr->mode.mode & MODE_INVITEONLY)
671 if (!dlinkFind(&source_p->localClient->invited, chptr))
672 if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist))
673 return ERR_INVITEONLYCHAN;
674
675 if (chptr->mode.key[0] && (!key || irccmp(chptr->mode.key, key)))
676 return ERR_BADCHANNELKEY;
677
678 if (chptr->mode.limit && dlink_list_length(&chptr->members) >=
679 chptr->mode.limit)
680 return ERR_CHANNELISFULL;
681
682 return 0;
683 }
684
685 int
686 has_member_flags(struct Membership *ms, unsigned int flags)
687 {
688 if (ms != NULL)
689 return ms->flags & flags;
690 return 0;
691 }
692
693 struct Membership *
694 find_channel_link(struct Client *client_p, struct Channel *chptr)
695 {
696 dlink_node *ptr = NULL;
697
698 if (!IsClient(client_p))
699 return NULL;
700
701 DLINK_FOREACH(ptr, client_p->channel.head)
702 if (((struct Membership *)ptr->data)->chptr == chptr)
703 return (struct Membership *)ptr->data;
704
705 return NULL;
706 }
707
708 /*!
709 * \param chptr pointer to Channel struct
710 * \param source_p pointer to Client struct
711 * \param ms pointer to Membership struct (can be NULL)
712 * \return CAN_SEND_OPV if op or voiced on channel\n
713 * CAN_SEND_NONOP if can send to channel but is not an op\n
714 * CAN_SEND_NO if they cannot send to channel\n
715 */
716 int
717 can_send(struct Channel *chptr, struct Client *source_p, struct Membership *ms)
718 {
719 if (IsServer(source_p))
720 return CAN_SEND_OPV;
721
722 if (MyClient(source_p) && !IsExemptResv(source_p))
723 if (!(IsOper(source_p) && ConfigFileEntry.oper_pass_resv))
724 if (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels)
725 return CAN_SEND_NO;
726
727 if (ms != NULL || (ms = find_channel_link(source_p, chptr)))
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 else if (chptr->mode.mode & MODE_NOPRIVMSGS)
751 return CAN_SEND_NO;
752
753 if (chptr->mode.mode & MODE_MODERATED)
754 return CAN_SEND_NO;
755
756 return CAN_SEND_NONOP;
757 }
758
759 /*! \brief Updates the client's oper_warn_count_down, warns the
760 * IRC operators if necessary, and updates
761 * join_leave_countdown as needed.
762 * \param source_p pointer to struct Client to check
763 * \param name channel name or NULL if this is a part.
764 */
765 void
766 check_spambot_warning(struct Client *source_p, const char *name)
767 {
768 int t_delta = 0;
769 int decrement_count = 0;
770
771 if ((GlobalSetOptions.spam_num &&
772 (source_p->localClient->join_leave_count >=
773 GlobalSetOptions.spam_num)))
774 {
775 if (source_p->localClient->oper_warn_count_down > 0)
776 source_p->localClient->oper_warn_count_down--;
777 else
778 source_p->localClient->oper_warn_count_down = 0;
779
780 if (source_p->localClient->oper_warn_count_down == 0)
781 {
782 /* Its already known as a possible spambot */
783 if (name != NULL)
784 sendto_realops_flags(UMODE_BOTS, L_ALL,
785 "User %s (%s@%s) trying to join %s is a possible spambot",
786 source_p->name, source_p->username,
787 source_p->host, name);
788 else
789 sendto_realops_flags(UMODE_BOTS, L_ALL,
790 "User %s (%s@%s) is a possible spambot",
791 source_p->name, source_p->username,
792 source_p->host);
793 source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
794 }
795 }
796 else
797 {
798 if ((t_delta = (CurrentTime - source_p->localClient->last_leave_time)) >
799 JOIN_LEAVE_COUNT_EXPIRE_TIME)
800 {
801 decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
802 if (decrement_count > source_p->localClient->join_leave_count)
803 source_p->localClient->join_leave_count = 0;
804 else
805 source_p->localClient->join_leave_count -= decrement_count;
806 }
807 else
808 {
809 if ((CurrentTime - (source_p->localClient->last_join_time)) <
810 GlobalSetOptions.spam_time)
811 {
812 /* oh, its a possible spambot */
813 source_p->localClient->join_leave_count++;
814 }
815 }
816
817 if (name != NULL)
818 source_p->localClient->last_join_time = CurrentTime;
819 else
820 source_p->localClient->last_leave_time = CurrentTime;
821 }
822 }
823
824 /*! \brief compares usercount and servercount against their split
825 * values and adjusts splitmode accordingly
826 * \param unused Unused address pointer
827 */
828 void
829 check_splitmode(void *unused)
830 {
831 if (splitchecking && (ConfigChannel.no_join_on_split ||
832 ConfigChannel.no_create_on_split))
833 {
834 const unsigned int server = dlink_list_length(&global_serv_list);
835
836 if (!splitmode && ((server < split_servers) || (Count.total < split_users)))
837 {
838 splitmode = 1;
839
840 sendto_realops_flags(UMODE_ALL,L_ALL,
841 "Network split, activating splitmode");
842 eventAddIsh("check_splitmode", check_splitmode, NULL, 10);
843 }
844 else if (splitmode && (server > split_servers) && (Count.total > split_users))
845 {
846 splitmode = 0;
847
848 sendto_realops_flags(UMODE_ALL, L_ALL,
849 "Network rejoined, deactivating splitmode");
850 eventDelete(check_splitmode, NULL);
851 }
852 }
853 }
854
855 /*! \brief Allocates a new topic
856 * \param chptr Channel to allocate a new topic for
857 */
858 static void
859 allocate_topic(struct Channel *chptr)
860 {
861 void *ptr = NULL;
862
863 if (chptr == NULL)
864 return;
865
866 ptr = BlockHeapAlloc(topic_heap);
867
868 /* Basically we allocate one large block for the topic and
869 * the topic info. We then split it up into two and shove it
870 * in the chptr
871 */
872 chptr->topic = ptr;
873 chptr->topic_info = (char *)ptr + TOPICLEN+1;
874 *chptr->topic = '\0';
875 *chptr->topic_info = '\0';
876 }
877
878 void
879 free_topic(struct Channel *chptr)
880 {
881 void *ptr = NULL;
882 assert(chptr);
883 if (chptr->topic == NULL)
884 return;
885
886 /*
887 * If you change allocate_topic you MUST change this as well
888 */
889 ptr = chptr->topic;
890 BlockHeapFree(topic_heap, ptr);
891 chptr->topic = NULL;
892 chptr->topic_info = NULL;
893 }
894
895 /*! \brief Sets the channel topic for chptr
896 * \param chptr Pointer to struct Channel
897 * \param topic The topic string
898 * \param topic_info n!u\@h formatted string of the topic setter
899 * \param topicts timestamp on the topic
900 */
901 void
902 set_channel_topic(struct Channel *chptr, const char *topic,
903 const char *topic_info, time_t topicts)
904 {
905 if (!EmptyString(topic))
906 {
907 if (chptr->topic == NULL)
908 allocate_topic(chptr);
909
910 strlcpy(chptr->topic, topic, TOPICLEN+1);
911 strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN);
912 chptr->topic_time = topicts;
913 }
914 else
915 {
916 /*
917 * Do not reset chptr->topic_time here, it's required for
918 * bursting topics properly.
919 */
920 if (chptr->topic != NULL)
921 free_topic(chptr);
922 }
923 }

Properties

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