/[svn]/ircd-hybrid-8/src/channel.c
ViewVC logotype

Contents of /ircd-hybrid-8/src/channel.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1429 - (show annotations)
Thu Jun 7 19:14:14 2012 UTC (8 years, 1 month ago) by michael
File MIME type: text/x-chdr
File size: 23984 byte(s)
- Unregistered clients may not talk in a +R channel

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28