ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/src/channel.c
Revision: 30
Committed: Sun Oct 2 20:03:27 2005 UTC (18 years, 6 months ago) by adx
Content type: text/x-csrc
Original Path: ircd-hybrid/src/channel.c
File size: 25068 byte(s)
Log Message:
- imported sources
- can be moved later according to the directory/branching scheme,
  but we need the svn up

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

Properties

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