ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.0.x/src/channel.c
Revision: 503
Committed: Fri Mar 3 19:53:47 2006 UTC (18 years, 1 month ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/channel.c
File size: 25298 byte(s)
Log Message:
- Backported CAP changes from HEAD since it doesn't affect
  any of the ircd's core components and should be supported
  as soon as possible.

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

Properties

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