/[svn]/ircd-hybrid-7.2/src/channel.c
ViewVC logotype

Contents of /ircd-hybrid-7.2/src/channel.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 632 - (show annotations)
Thu Jun 1 10:53:00 2006 UTC (13 years, 4 months ago) by michael
File MIME type: text/x-chdr
File size: 24770 byte(s)
- Added channel::disable_fake_channels which disallows creation of channels
  that have ascii 2, 3, 31 and 160 in their names.
- Minor improvements and cleanups to channel name validation routines
  backported from 7.3

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.26