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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1654 - (show annotations)
Fri Nov 16 19:39:37 2012 UTC (7 years, 7 months ago) by michael
File MIME type: text/x-chdr
File size: 23671 byte(s)
- Implemented memory pool allocator which basically is taken from Tor's
  mempool allocator for Tor cells
- Fixed compile warnings in conf_class.c
- ./configure --enable-assert works again

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

Properties

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

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