ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/channel.c
Revision: 1661
Committed: Sat Nov 17 19:43:57 2012 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/channel.c
File size: 23596 byte(s)
Log Message:
- channel.c:send_channel_modes(): now that CAP_IE and CAP_EX are mandatory, let's
  always send invite/ban exception during a burst

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

Properties

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