ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
Revision: 572
Committed: Sun Apr 30 16:57:48 2006 UTC (19 years, 4 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/channel.c
File size: 25197 byte(s)
Log Message:
- Backported changes made in HEAD to get rid of Channel::locmembers.
  This is mainly to save about 5megs of ram on networks like efnet where
  we have about 600k allocated Membership structures.

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

Properties

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