ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
Revision: 1173
Committed: Sun Aug 14 00:23:02 2011 UTC (14 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/src/channel.c
File size: 24975 byte(s)
Log Message:
- add usermode +R; only registered clients may message other clients with that mode set
- add channelmode +R; only registered clients may join a channel with that mode set

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

Properties

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