ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/channel.c
Revision: 1219
Committed: Sun Sep 18 09:02:38 2011 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/src/channel.c
File size: 23759 byte(s)
Log Message:
- Start cleaning up macros in client.h. Replace several ClientHasSomeCoolFlag()
with simple HasFlag/HasUMode macros.

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 "common.h"
33 #include "hash.h"
34 #include "hostmask.h"
35 #include "irc_string.h"
36 #include "sprintf_irc.h"
37 #include "ircd.h"
38 #include "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 BlockHeap *ban_heap; /*! \todo ban_heap shouldn't be a global var */
50
51 static BlockHeap *member_heap = NULL;
52 static BlockHeap *channel_heap = NULL;
53
54 static char buf[IRCD_BUFSIZE];
55 static char modebuf[MODEBUFLEN];
56 static char parabuf[MODEBUFLEN];
57
58
59 /*! \brief Initializes the channel blockheap, adds known channel CAPAB
60 */
61 void
62 init_channels(void)
63 {
64 add_capability("EX", CAP_EX, 1);
65 add_capability("IE", CAP_IE, 1);
66 add_capability("CHW", CAP_CHW, 1);
67
68 channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE);
69 ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE);
70 member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2);
71 }
72
73 /*! \brief adds a user to a channel by adding another link to the
74 * channels member chain.
75 * \param chptr pointer to channel to add client to
76 * \param who pointer to client (who) to add
77 * \param flags flags for chanops etc
78 * \param flood_ctrl whether to count this join in flood calculations
79 */
80 void
81 add_user_to_channel(struct Channel *chptr, struct Client *who,
82 unsigned int flags, int flood_ctrl)
83 {
84 struct Membership *ms = NULL;
85
86 if (GlobalSetOptions.joinfloodtime > 0)
87 {
88 if (flood_ctrl)
89 chptr->number_joined++;
90
91 chptr->number_joined -= (CurrentTime - chptr->last_join_time) *
92 (((float)GlobalSetOptions.joinfloodcount) /
93 (float)GlobalSetOptions.joinfloodtime);
94
95 if (chptr->number_joined <= 0)
96 {
97 chptr->number_joined = 0;
98 ClearJoinFloodNoticed(chptr);
99 }
100 else if (chptr->number_joined >= GlobalSetOptions.joinfloodcount)
101 {
102 chptr->number_joined = GlobalSetOptions.joinfloodcount;
103
104 if (!IsSetJoinFloodNoticed(chptr))
105 {
106 SetJoinFloodNoticed(chptr);
107 sendto_realops_flags(UMODE_BOTS, L_ALL,
108 "Possible Join Flooder %s on %s target: %s",
109 get_client_name(who, HIDE_IP),
110 who->servptr->name, chptr->chname);
111 }
112 }
113
114 chptr->last_join_time = CurrentTime;
115 }
116
117 ms = BlockHeapAlloc(member_heap);
118 ms->client_p = who;
119 ms->chptr = chptr;
120 ms->flags = flags;
121
122 dlinkAdd(ms, &ms->channode, &chptr->members);
123 dlinkAdd(ms, &ms->usernode, &who->channel);
124 }
125
126 /*! \brief deletes an user from a channel by removing a link in the
127 * channels member chain.
128 * \param member pointer to Membership struct
129 */
130 void
131 remove_user_from_channel(struct Membership *member)
132 {
133 struct Client *client_p = member->client_p;
134 struct Channel *chptr = member->chptr;
135
136 dlinkDelete(&member->channode, &chptr->members);
137 dlinkDelete(&member->usernode, &client_p->channel);
138
139 BlockHeapFree(member_heap, member);
140
141 if (chptr->members.head == NULL)
142 destroy_channel(chptr);
143 }
144
145 /* send_members()
146 *
147 * inputs -
148 * output - NONE
149 * side effects -
150 */
151 static void
152 send_members(struct Client *client_p, struct Channel *chptr,
153 char *lmodebuf, char *lparabuf)
154 {
155 struct Membership *ms;
156 dlink_node *ptr;
157 int tlen; /* length of text to append */
158 char *t, *start; /* temp char pointer */
159
160 start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:",
161 ID_or_name(&me, client_p),
162 (unsigned long)chptr->channelts,
163 chptr->chname, lmodebuf, lparabuf);
164
165 DLINK_FOREACH(ptr, chptr->members.head)
166 {
167 ms = ptr->data;
168
169 tlen = strlen(IsCapable(client_p, CAP_TS6) ?
170 ID(ms->client_p) : ms->client_p->name) + 1; /* nick + space */
171
172 if (ms->flags & CHFL_CHANOP)
173 tlen++;
174 #ifdef HALFOPS
175 else if (ms->flags & CHFL_HALFOP)
176 tlen++;
177 #endif
178 if (ms->flags & CHFL_VOICE)
179 tlen++;
180
181 /* space will be converted into CR, but we also need space for LF..
182 * That's why we use '- 1' here
183 * -adx */
184 if (t + tlen - buf > sizeof(buf) - 1)
185 {
186 *(t - 1) = '\0'; /* kill the space and terminate the string */
187 sendto_one(client_p, "%s", buf);
188 t = start;
189 }
190
191 if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP)))
192 *t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ?
193 '%' : '@';
194 if ((ms->flags & CHFL_VOICE))
195 *t++ = '+';
196
197 if (IsCapable(client_p, CAP_TS6))
198 strcpy(t, ID(ms->client_p));
199 else
200 strcpy(t, ms->client_p->name);
201 t += strlen(t);
202 *t++ = ' ';
203 }
204
205 /* should always be non-NULL unless we have a kind of persistent channels */
206 if (chptr->members.head != NULL)
207 t--; /* take the space out */
208 *t = '\0';
209 sendto_one(client_p, "%s", buf);
210 }
211
212 /*! \brief sends +b/+e/+I
213 * \param client_p client pointer to server
214 * \param chptr pointer to channel
215 * \param top pointer to top of mode link list to send
216 * \param flag char flag flagging type of mode. Currently this can be 'b', e' or 'I'
217 */
218 static void
219 send_mode_list(struct Client *client_p, struct Channel *chptr,
220 dlink_list *top, char flag)
221 {
222 int ts5 = !IsCapable(client_p, CAP_TS6);
223 dlink_node *lp;
224 struct Ban *banptr;
225 char pbuf[IRCD_BUFSIZE];
226 int tlen, mlen, cur_len, count = 0;
227 char *mp = NULL, *pp = pbuf;
228
229 if (top == NULL || top->length == 0)
230 return;
231
232 if (ts5)
233 mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname);
234 else
235 mlen = ircsprintf(buf, ":%s BMASK %lu %s %c :", me.id,
236 (unsigned long)chptr->channelts, chptr->chname, flag);
237
238 /* MODE needs additional one byte for space between buf and pbuf */
239 cur_len = mlen + ts5;
240 mp = buf + mlen;
241
242 DLINK_FOREACH(lp, top->head)
243 {
244 banptr = lp->data;
245
246 /* must add another b/e/I letter if we use MODE */
247 tlen = banptr->len + 3 + ts5;
248
249 /*
250 * send buffer and start over if we cannot fit another ban,
251 * or if the target is non-ts6 and we have too many modes in
252 * in this line.
253 */
254 if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 ||
255 (!IsCapable(client_p, CAP_TS6) &&
256 (count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN)))
257 {
258 *(pp - 1) = '\0'; /* get rid of trailing space on buffer */
259 sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf);
260
261 cur_len = mlen + ts5;
262 mp = buf + mlen;
263 pp = pbuf;
264 count = 0;
265 }
266
267 count++;
268 if (ts5)
269 {
270 *mp++ = flag;
271 *mp = '\0';
272 }
273
274 pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username,
275 banptr->host);
276 cur_len += tlen;
277 }
278
279 *(pp - 1) = '\0'; /* get rid of trailing space on buffer */
280 sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf);
281 }
282
283 /*! \brief send "client_p" a full list of the modes for channel chptr
284 * \param client_p pointer to client client_p
285 * \param chptr pointer to channel pointer
286 */
287 void
288 send_channel_modes(struct Client *client_p, struct Channel *chptr)
289 {
290 if (chptr->chname[0] != '#')
291 return;
292
293 *modebuf = *parabuf = '\0';
294 channel_modes(chptr, client_p, modebuf, parabuf);
295 send_members(client_p, chptr, modebuf, parabuf);
296
297 send_mode_list(client_p, chptr, &chptr->banlist, 'b');
298
299 if (IsCapable(client_p, CAP_EX))
300 send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
301 if (IsCapable(client_p, CAP_IE))
302 send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
303 }
304
305 /*! \brief check channel name for invalid characters
306 * \param name pointer to channel name string
307 * \param local indicates whether it's a local or remote creation
308 * \return 0 if invalid, 1 otherwise
309 */
310 int
311 check_channel_name(const char *name, int local)
312 {
313 const char *p = name;
314 int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN;
315 assert(name != NULL);
316
317 if (!IsChanPrefix(*p))
318 return 0;
319
320 if (!local || !ConfigChannel.disable_fake_channels)
321 {
322 while (*++p)
323 if (!IsChanChar(*p))
324 return 0;
325 }
326 else
327 {
328 while (*++p)
329 if (!IsVisibleChanChar(*p))
330 return 0;
331 }
332
333 return p - name <= max_length;
334 }
335
336 void
337 remove_ban(struct Ban *bptr, dlink_list *list)
338 {
339 dlinkDelete(&bptr->node, list);
340
341 MyFree(bptr->name);
342 MyFree(bptr->username);
343 MyFree(bptr->host);
344 MyFree(bptr->who);
345
346 BlockHeapFree(ban_heap, bptr);
347 }
348
349 /* free_channel_list()
350 *
351 * inputs - pointer to dlink_list
352 * output - NONE
353 * side effects -
354 */
355 void
356 free_channel_list(dlink_list *list)
357 {
358 dlink_node *ptr = NULL, *next_ptr = NULL;
359
360 DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
361 remove_ban(ptr->data, list);
362
363 assert(list->tail == NULL && list->head == NULL);
364 }
365
366 /*! \brief Get Channel block for chname (and allocate a new channel
367 * block, if it didn't exist before)
368 * \param chname channel name
369 * \return channel block
370 */
371 struct Channel *
372 make_channel(const char *chname)
373 {
374 struct Channel *chptr = NULL;
375
376 assert(!EmptyString(chname));
377
378 chptr = BlockHeapAlloc(channel_heap);
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 BlockHeapFree(channel_heap, 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 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 (!ConfigChannel.use_except || !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 (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist))
673 return ERR_INVITEONLYCHAN;
674
675 if (chptr->mode.key[0] && (!key || irccmp(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,
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,
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,
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,
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