ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/src/channel.c
Revision: 885
Committed: Wed Oct 31 18:09:24 2007 UTC (17 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 24590 byte(s)
Log Message:
- Removed LazyLinks in 7.2 to stop people from asking why we keep
  broken code for half a decade. LL will be implemented in a smarter
  fashion in due time

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

Properties

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