ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/src/channel.c
Revision: 1011
Committed: Fri Sep 18 10:14:09 2009 UTC (14 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 24559 byte(s)
Log Message:
- move list manipulation routines from tools.c to list.c
- mem_frob() goes to memory.c
- sort out redundant/unneeded header includes

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

Properties

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