2 * ircd-ratbox: A slightly useful ircd.
3 * channel.c: Controls channels.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: channel.c 3580 2007-11-07 23:45:14Z jilles $
33 #include "irc_string.h"
36 #include "s_serv.h" /* captab */
40 #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
41 #include "s_newconf.h"
44 extern rb_dlink_list global_channel_list
;
46 extern struct config_channel_entry ConfigChannel
;
47 extern rb_bh
*channel_heap
;
48 extern rb_bh
*ban_heap
;
49 extern rb_bh
*topic_heap
;
50 extern rb_bh
*member_heap
;
52 static int channel_capabs
[] = { CAP_EX
, CAP_IE
,
57 #define NCHCAPS (sizeof(channel_capabs)/sizeof(int))
58 #define NCHCAP_COMBOS (1 << NCHCAPS)
60 static struct ChCapCombo chcap_combos
[NCHCAP_COMBOS
];
62 static void free_topic(struct Channel
*chptr
);
64 static int h_can_join
;
70 * side effects - initialises the various blockheaps
75 channel_heap
= rb_bh_create(sizeof(struct Channel
), CHANNEL_HEAP_SIZE
, "channel_heap");
76 ban_heap
= rb_bh_create(sizeof(struct Ban
), BAN_HEAP_SIZE
, "ban_heap");
77 topic_heap
= rb_bh_create(TOPICLEN
+ 1 + USERHOST_REPLYLEN
, TOPIC_HEAP_SIZE
, "topic_heap");
78 member_heap
= rb_bh_create(sizeof(struct membership
), MEMBER_HEAP_SIZE
, "member_heap");
80 h_can_join
= register_hook("can_join");
84 * allocate_channel - Allocates a channel
87 allocate_channel(const char *chname
)
89 struct Channel
*chptr
;
90 chptr
= rb_bh_alloc(channel_heap
);
91 chptr
->chname
= rb_strdup(chname
);
96 free_channel(struct Channel
*chptr
)
98 rb_free(chptr
->chname
);
99 rb_bh_free(channel_heap
, chptr
);
103 allocate_ban(const char *banstr
, const char *who
)
106 bptr
= rb_bh_alloc(ban_heap
);
107 bptr
->banstr
= rb_strdup(banstr
);
108 bptr
->who
= rb_strdup(who
);
114 free_ban(struct Ban
*bptr
)
116 rb_free(bptr
->banstr
);
118 rb_bh_free(ban_heap
, bptr
);
122 /* find_channel_membership()
124 * input - channel to find them in, client to find
125 * output - membership of client in channel, else NULL
129 find_channel_membership(struct Channel
*chptr
, struct Client
*client_p
)
131 struct membership
*msptr
;
134 if(!IsClient(client_p
))
137 /* Pick the most efficient list to use to be nice to things like
138 * CHANSERV which could be in a large number of channels
140 if(rb_dlink_list_length(&chptr
->members
) < rb_dlink_list_length(&client_p
->user
->channel
))
142 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
146 if(msptr
->client_p
== client_p
)
152 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
156 if(msptr
->chptr
== chptr
)
164 /* find_channel_status()
166 * input - membership to get status for, whether we can combine flags
167 * output - flags of user on channel
171 find_channel_status(struct membership
*msptr
, int combine
)
173 static char buffer
[3];
192 /* add_user_to_channel()
194 * input - channel to add client to, client to add, channel flags
196 * side effects - user is added to channel
199 add_user_to_channel(struct Channel
*chptr
, struct Client
*client_p
, int flags
)
201 struct membership
*msptr
;
203 s_assert(client_p
->user
!= NULL
);
204 if(client_p
->user
== NULL
)
207 msptr
= rb_bh_alloc(member_heap
);
209 msptr
->chptr
= chptr
;
210 msptr
->client_p
= client_p
;
211 msptr
->flags
= flags
;
213 rb_dlinkAdd(msptr
, &msptr
->usernode
, &client_p
->user
->channel
);
214 rb_dlinkAdd(msptr
, &msptr
->channode
, &chptr
->members
);
216 if(MyClient(client_p
))
217 rb_dlinkAdd(msptr
, &msptr
->locchannode
, &chptr
->locmembers
);
220 /* remove_user_from_channel()
222 * input - membership pointer to remove from channel
224 * side effects - membership (thus user) is removed from channel
227 remove_user_from_channel(struct membership
*msptr
)
229 struct Client
*client_p
;
230 struct Channel
*chptr
;
231 s_assert(msptr
!= NULL
);
235 client_p
= msptr
->client_p
;
236 chptr
= msptr
->chptr
;
238 rb_dlinkDelete(&msptr
->usernode
, &client_p
->user
->channel
);
239 rb_dlinkDelete(&msptr
->channode
, &chptr
->members
);
241 if(client_p
->servptr
== &me
)
242 rb_dlinkDelete(&msptr
->locchannode
, &chptr
->locmembers
);
244 chptr
->users_last
= rb_current_time();
246 if(!(chptr
->mode
.mode
& MODE_PERMANENT
) && rb_dlink_list_length(&chptr
->members
) <= 0)
247 destroy_channel(chptr
);
249 rb_bh_free(member_heap
, msptr
);
254 /* remove_user_from_channels()
256 * input - user to remove from all channels
258 * side effects - user is removed from all channels
261 remove_user_from_channels(struct Client
*client_p
)
263 struct Channel
*chptr
;
264 struct membership
*msptr
;
266 rb_dlink_node
*next_ptr
;
271 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->user
->channel
.head
)
274 chptr
= msptr
->chptr
;
276 rb_dlinkDelete(&msptr
->channode
, &chptr
->members
);
278 if(client_p
->servptr
== &me
)
279 rb_dlinkDelete(&msptr
->locchannode
, &chptr
->locmembers
);
281 chptr
->users_last
= rb_current_time();
283 if(!(chptr
->mode
.mode
& MODE_PERMANENT
) && rb_dlink_list_length(&chptr
->members
) <= 0)
284 destroy_channel(chptr
);
286 rb_bh_free(member_heap
, msptr
);
289 client_p
->user
->channel
.head
= client_p
->user
->channel
.tail
= NULL
;
290 client_p
->user
->channel
.length
= 0;
293 /* invalidate_bancache_user()
295 * input - user to invalidate ban cache for
297 * side effects - ban cache is invalidated for all memberships of that user
298 * to be used after a nick change
301 invalidate_bancache_user(struct Client
*client_p
)
303 struct membership
*msptr
;
309 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
313 msptr
->flags
&= ~CHFL_BANNED
;
317 /* check_channel_name()
319 * input - channel name
320 * output - 1 if valid channel name, else 0
324 check_channel_name(const char *name
)
326 s_assert(name
!= NULL
);
330 for (; *name
; ++name
)
332 if(!IsChanChar(*name
))
339 /* free_channel_list()
341 * input - rb_dlink list to free
343 * side effects - list of b/e/I modes is cleared
346 free_channel_list(rb_dlink_list
* list
)
349 rb_dlink_node
*next_ptr
;
350 struct Ban
*actualBan
;
352 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
354 actualBan
= ptr
->data
;
358 list
->head
= list
->tail
= NULL
;
364 * input - channel to destroy
366 * side effects - channel is obliterated
369 destroy_channel(struct Channel
*chptr
)
371 rb_dlink_node
*ptr
, *next_ptr
;
373 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
375 del_invite(chptr
, ptr
->data
);
378 /* free all bans/exceptions/denies */
379 free_channel_list(&chptr
->banlist
);
380 free_channel_list(&chptr
->exceptlist
);
381 free_channel_list(&chptr
->invexlist
);
382 free_channel_list(&chptr
->quietlist
);
387 rb_dlinkDelete(&chptr
->node
, &global_channel_list
);
388 del_from_channel_hash(chptr
->chname
, chptr
);
392 /* channel_pub_or_secret()
395 * output - "=" if public, "@" if secret, else "*"
399 channel_pub_or_secret(struct Channel
*chptr
)
401 if(PubChannel(chptr
))
403 else if(SecretChannel(chptr
))
408 /* channel_member_names()
410 * input - channel to list, client to list to, show endofnames
412 * side effects - client is given list of users on channel
415 channel_member_names(struct Channel
*chptr
, struct Client
*client_p
, int show_eon
)
417 struct membership
*msptr
;
418 struct Client
*target_p
;
426 int stack
= IsCapable(client_p
, CLICAP_MULTI_PREFIX
);
428 if(ShowChannel(client_p
, chptr
))
430 is_member
= IsMember(client_p
, chptr
);
432 cur_len
= mlen
= rb_sprintf(lbuf
, form_str(RPL_NAMREPLY
),
433 me
.name
, client_p
->name
,
434 channel_pub_or_secret(chptr
), chptr
->chname
);
438 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
441 target_p
= msptr
->client_p
;
443 if(IsInvisible(target_p
) && !is_member
)
446 /* space, possible "@+" prefix */
447 if(cur_len
+ strlen(target_p
->name
) + 3 >= BUFSIZE
- 3)
450 sendto_one(client_p
, "%s", lbuf
);
455 tlen
= rb_sprintf(t
, "%s%s ", find_channel_status(msptr
, stack
),
462 /* The old behaviour here was to always output our buffer,
463 * even if there are no clients we can show. This happens
464 * when a client does "NAMES" with no parameters, and all
465 * the clients on a -sp channel are +i. I dont see a good
466 * reason for keeping that behaviour, as it just wastes
472 sendto_one(client_p
, "%s", lbuf
);
477 sendto_one(client_p
, form_str(RPL_ENDOFNAMES
),
478 me
.name
, client_p
->name
, chptr
->chname
);
483 * input - channel to remove invite from, client to remove
485 * side effects - user is removed from invite list, if exists
488 del_invite(struct Channel
*chptr
, struct Client
*who
)
490 rb_dlinkFindDestroy(who
, &chptr
->invites
);
491 rb_dlinkFindDestroy(chptr
, &who
->user
->invited
);
496 * input - channel to check bans for, user to check bans against
497 * optional prebuilt buffers
498 * output - 1 if banned, else 0
502 is_banned(struct Channel
*chptr
, struct Client
*who
, struct membership
*msptr
,
503 const char *s
, const char *s2
)
505 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
506 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
507 char src_althost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
510 struct Ban
*actualBan
= NULL
;
511 struct Ban
*actualExcept
= NULL
;
516 /* if the buffers havent been built, do it here */
519 rb_sprintf(src_host
, "%s!%s@%s", who
->name
, who
->username
, who
->host
);
520 rb_sprintf(src_iphost
, "%s!%s@%s", who
->name
, who
->username
, who
->sockhost
);
525 if(who
->localClient
->mangledhost
!= NULL
)
527 /* if host mangling mode enabled, also check their real host */
528 if(!strcmp(who
->host
, who
->localClient
->mangledhost
))
530 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->orighost
);
533 /* if host mangling mode not enabled and no other spoof,
534 * also check the mangled form of their host */
535 else if (!IsDynSpoof(who
))
537 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->localClient
->mangledhost
);
542 RB_DLINK_FOREACH(ptr
, chptr
->banlist
.head
)
544 actualBan
= ptr
->data
;
545 if(match(actualBan
->banstr
, s
) ||
546 match(actualBan
->banstr
, s2
) ||
547 match_cidr(actualBan
->banstr
, s2
) ||
548 match_extban(actualBan
->banstr
, who
, chptr
, CHFL_BAN
) ||
549 (s3
!= NULL
&& match(actualBan
->banstr
, s3
)))
555 if((actualBan
!= NULL
) && ConfigChannel
.use_except
)
557 RB_DLINK_FOREACH(ptr
, chptr
->exceptlist
.head
)
559 actualExcept
= ptr
->data
;
561 /* theyre exempted.. */
562 if(match(actualExcept
->banstr
, s
) ||
563 match(actualExcept
->banstr
, s2
) ||
564 match_cidr(actualExcept
->banstr
, s2
) ||
565 match_extban(actualExcept
->banstr
, who
, chptr
, CHFL_EXCEPTION
) ||
566 (s3
!= NULL
&& match(actualExcept
->banstr
, s3
)))
568 /* cache the fact theyre not banned */
571 msptr
->bants
= chptr
->bants
;
572 msptr
->flags
&= ~CHFL_BANNED
;
575 return CHFL_EXCEPTION
;
580 /* cache the banned/not banned status */
583 msptr
->bants
= chptr
->bants
;
585 if(actualBan
!= NULL
)
587 msptr
->flags
|= CHFL_BANNED
;
592 msptr
->flags
&= ~CHFL_BANNED
;
597 return ((actualBan
? CHFL_BAN
: 0));
602 * input - channel to check bans for, user to check bans against
603 * optional prebuilt buffers
604 * output - 1 if banned, else 0
608 is_quieted(struct Channel
*chptr
, struct Client
*who
, struct membership
*msptr
,
609 const char *s
, const char *s2
)
611 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
612 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
613 char src_althost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
616 struct Ban
*actualBan
= NULL
;
617 struct Ban
*actualExcept
= NULL
;
622 /* if the buffers havent been built, do it here */
625 rb_sprintf(src_host
, "%s!%s@%s", who
->name
, who
->username
, who
->host
);
626 rb_sprintf(src_iphost
, "%s!%s@%s", who
->name
, who
->username
, who
->sockhost
);
631 if(who
->localClient
->mangledhost
!= NULL
)
633 /* if host mangling mode enabled, also check their real host */
634 if(!strcmp(who
->host
, who
->localClient
->mangledhost
))
636 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->orighost
);
639 /* if host mangling mode not enabled and no other spoof,
640 * also check the mangled form of their host */
641 else if (!IsDynSpoof(who
))
643 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->localClient
->mangledhost
);
648 RB_DLINK_FOREACH(ptr
, chptr
->quietlist
.head
)
650 actualBan
= ptr
->data
;
651 if(match(actualBan
->banstr
, s
) ||
652 match(actualBan
->banstr
, s2
) ||
653 match_cidr(actualBan
->banstr
, s2
) ||
654 match_extban(actualBan
->banstr
, who
, chptr
, CHFL_QUIET
) ||
655 (s3
!= NULL
&& match(actualBan
->banstr
, s3
)))
661 if((actualBan
!= NULL
) && ConfigChannel
.use_except
)
663 RB_DLINK_FOREACH(ptr
, chptr
->exceptlist
.head
)
665 actualExcept
= ptr
->data
;
667 /* theyre exempted.. */
668 if(match(actualExcept
->banstr
, s
) ||
669 match(actualExcept
->banstr
, s2
) ||
670 match_cidr(actualExcept
->banstr
, s2
) ||
671 match_extban(actualExcept
->banstr
, who
, chptr
, CHFL_EXCEPTION
) ||
672 (s3
!= NULL
&& match(actualExcept
->banstr
, s3
)))
674 /* cache the fact theyre not banned */
677 msptr
->bants
= chptr
->bants
;
678 msptr
->flags
&= ~CHFL_BANNED
;
681 return CHFL_EXCEPTION
;
686 /* cache the banned/not banned status */
689 msptr
->bants
= chptr
->bants
;
691 if(actualBan
!= NULL
)
693 msptr
->flags
|= CHFL_BANNED
;
698 msptr
->flags
&= ~CHFL_BANNED
;
703 return ((actualBan
? CHFL_BAN
: 0));
708 * input - client to check, channel to check for, key
709 * output - reason for not being able to join, else 0
713 can_join(struct Client
*source_p
, struct Channel
*chptr
, char *key
)
715 rb_dlink_node
*invite
= NULL
;
717 struct Ban
*invex
= NULL
;
718 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
719 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
720 char src_althost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
723 hook_data_channel moduledata
;
725 s_assert(source_p
->localClient
!= NULL
);
727 rb_sprintf(src_host
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->host
);
728 rb_sprintf(src_iphost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->sockhost
);
729 if(source_p
->localClient
->mangledhost
!= NULL
)
731 /* if host mangling mode enabled, also check their real host */
732 if(!strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
734 rb_sprintf(src_althost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->orighost
);
737 /* if host mangling mode not enabled and no other spoof,
738 * also check the mangled form of their host */
739 else if (!IsDynSpoof(source_p
))
741 rb_sprintf(src_althost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->localClient
->mangledhost
);
746 if((is_banned(chptr
, source_p
, NULL
, src_host
, src_iphost
)) == CHFL_BAN
)
747 return (ERR_BANNEDFROMCHAN
);
749 if(chptr
->mode
.mode
& MODE_INVITEONLY
)
751 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
753 if(invite
->data
== chptr
)
758 if(!ConfigChannel
.use_invex
)
759 return (ERR_INVITEONLYCHAN
);
760 RB_DLINK_FOREACH(ptr
, chptr
->invexlist
.head
)
763 if(match(invex
->banstr
, src_host
)
764 || match(invex
->banstr
, src_iphost
)
765 || match_cidr(invex
->banstr
, src_iphost
)
766 || match_extban(invex
->banstr
, source_p
, chptr
, CHFL_INVEX
)
767 || (use_althost
&& match(invex
->banstr
, src_althost
)))
771 return (ERR_INVITEONLYCHAN
);
775 if(*chptr
->mode
.key
&& (EmptyString(key
) || irccmp(chptr
->mode
.key
, key
)))
776 return (ERR_BADCHANNELKEY
);
778 if(chptr
->mode
.limit
&&
779 rb_dlink_list_length(&chptr
->members
) >= (unsigned long) chptr
->mode
.limit
)
780 i
= ERR_CHANNELISFULL
;
781 if(chptr
->mode
.mode
& MODE_REGONLY
&& EmptyString(source_p
->user
->suser
))
782 i
= ERR_NEEDREGGEDNICK
;
783 /* join throttling stuff --nenolod */
784 else if(chptr
->mode
.join_num
> 0 && chptr
->mode
.join_time
> 0)
786 if ((rb_current_time() - chptr
->join_delta
<=
787 chptr
->mode
.join_time
) && (chptr
->join_count
>=
788 chptr
->mode
.join_num
))
792 /* allow /invite to override +l/+r/+j also -- jilles */
793 if (i
!= 0 && invite
== NULL
)
795 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
797 if(invite
->data
== chptr
)
804 moduledata
.client
= source_p
;
805 moduledata
.chptr
= chptr
;
806 moduledata
.approved
= 0;
808 call_hook(h_can_join
, &moduledata
);
810 return moduledata
.approved
;
815 * input - user to check in channel, membership pointer
816 * output - whether can explicitly send or not, else CAN_SEND_NONOP
820 can_send(struct Channel
*chptr
, struct Client
*source_p
, struct membership
*msptr
)
822 if(IsServer(source_p
) || IsService(source_p
))
825 if(MyClient(source_p
) && hash_find_resv(chptr
->chname
) &&
826 !IsOper(source_p
) && !IsExemptResv(source_p
))
831 msptr
= find_channel_membership(chptr
, source_p
);
835 /* if its +m or +n and theyre not in the channel,
836 * they cant send. we dont check bans here because
837 * theres no possibility of caching them --fl
839 if(chptr
->mode
.mode
& MODE_NOPRIVMSGS
|| chptr
->mode
.mode
& MODE_MODERATED
)
842 return CAN_SEND_NONOP
;
846 if(is_chanop_voiced(msptr
))
849 if(chptr
->mode
.mode
& MODE_MODERATED
)
852 if(MyClient(source_p
))
854 /* cached can_send */
855 if(msptr
->bants
== chptr
->bants
)
857 if(can_send_banned(msptr
))
860 else if(is_banned(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
861 || is_quieted(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
)
865 return CAN_SEND_NONOP
;
868 /* find_bannickchange_channel()
869 * Input: client to check
870 * Output: channel preventing nick change
873 find_bannickchange_channel(struct Client
*client_p
)
875 struct Channel
*chptr
;
876 struct membership
*msptr
;
878 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
879 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
881 if (!MyClient(client_p
))
884 rb_sprintf(src_host
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->host
);
885 rb_sprintf(src_iphost
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->sockhost
);
887 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
890 chptr
= msptr
->chptr
;
891 if (is_chanop_voiced(msptr
))
893 /* cached can_send */
894 if (msptr
->bants
== chptr
->bants
)
896 if (can_send_banned(msptr
))
899 else if (is_banned(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
900 || is_quieted(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
)
906 /* void check_spambot_warning(struct Client *source_p)
907 * Input: Client to check, channel name or NULL if this is a part.
909 * Side-effects: Updates the client's oper_warn_count_down, warns the
910 * IRC operators if necessary, and updates join_leave_countdown as
914 check_spambot_warning(struct Client
*source_p
, const char *name
)
918 if((GlobalSetOptions
.spam_num
&&
919 (source_p
->localClient
->join_leave_count
>= GlobalSetOptions
.spam_num
)))
921 if(source_p
->localClient
->oper_warn_count_down
> 0)
922 source_p
->localClient
->oper_warn_count_down
--;
924 source_p
->localClient
->oper_warn_count_down
= 0;
925 if(source_p
->localClient
->oper_warn_count_down
== 0)
927 /* Its already known as a possible spambot */
929 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
930 "User %s (%s@%s) trying to join %s is a possible spambot",
932 source_p
->username
, source_p
->orighost
, name
);
934 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
935 "User %s (%s@%s) is a possible spambot",
937 source_p
->username
, source_p
->orighost
);
938 source_p
->localClient
->oper_warn_count_down
= OPER_SPAM_COUNTDOWN
;
944 (rb_current_time() - source_p
->localClient
->last_leave_time
)) >
945 JOIN_LEAVE_COUNT_EXPIRE_TIME
)
947 decrement_count
= (t_delta
/ JOIN_LEAVE_COUNT_EXPIRE_TIME
);
948 if(decrement_count
> source_p
->localClient
->join_leave_count
)
949 source_p
->localClient
->join_leave_count
= 0;
951 source_p
->localClient
->join_leave_count
-= decrement_count
;
955 if((rb_current_time() -
956 (source_p
->localClient
->last_join_time
)) < GlobalSetOptions
.spam_time
)
958 /* oh, its a possible spambot */
959 source_p
->localClient
->join_leave_count
++;
963 source_p
->localClient
->last_join_time
= rb_current_time();
965 source_p
->localClient
->last_leave_time
= rb_current_time();
973 * side effects - compares usercount and servercount against their split
974 * values and adjusts splitmode accordingly
977 check_splitmode(void *unused
)
979 if(splitchecking
&& (ConfigChannel
.no_join_on_split
|| ConfigChannel
.no_create_on_split
))
981 /* not split, we're being asked to check now because someone
986 if(eob_count
< split_servers
|| Count
.total
< split_users
)
989 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
990 "Network split, activating splitmode");
991 check_splitmode_ev
= rb_event_addish("check_splitmode", check_splitmode
, NULL
, 2);
994 /* in splitmode, check whether its finished */
995 else if(eob_count
>= split_servers
&& Count
.total
>= split_users
)
999 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1000 "Network rejoined, deactivating splitmode");
1002 rb_event_delete(check_splitmode_ev
);
1010 * input - channel to allocate topic for
1011 * output - 1 on success, else 0
1012 * side effects - channel gets a topic allocated
1015 allocate_topic(struct Channel
*chptr
)
1022 ptr
= rb_bh_alloc(topic_heap
);
1024 /* Basically we allocate one large block for the topic and
1025 * the topic info. We then split it up into two and shove it
1029 chptr
->topic_info
= (char *) ptr
+ TOPICLEN
+ 1;
1030 *chptr
->topic
= '\0';
1031 *chptr
->topic_info
= '\0';
1036 * input - channel which has topic to free
1038 * side effects - channels topic is free'd
1041 free_topic(struct Channel
*chptr
)
1045 if(chptr
== NULL
|| chptr
->topic
== NULL
)
1048 /* This is safe for now - If you change allocate_topic you
1049 * MUST change this as well
1052 rb_bh_free(topic_heap
, ptr
);
1053 chptr
->topic
= NULL
;
1054 chptr
->topic_info
= NULL
;
1057 /* set_channel_topic()
1059 * input - channel, topic to set, topic info and topic ts
1061 * side effects - channels topic, topic info and TS are set.
1064 set_channel_topic(struct Channel
*chptr
, const char *topic
, const char *topic_info
, time_t topicts
)
1066 if(strlen(topic
) > 0)
1068 if(chptr
->topic
== NULL
)
1069 allocate_topic(chptr
);
1070 rb_strlcpy(chptr
->topic
, topic
, TOPICLEN
+ 1);
1071 rb_strlcpy(chptr
->topic_info
, topic_info
, USERHOST_REPLYLEN
);
1072 chptr
->topic_time
= topicts
;
1076 if(chptr
->topic
!= NULL
)
1078 chptr
->topic_time
= 0;
1082 const struct mode_letter chmode_flags
[] =
1084 {MODE_INVITEONLY
, 'i'},
1085 {MODE_MODERATED
, 'm'},
1086 {MODE_NOPRIVMSGS
, 'n'},
1087 {MODE_PRIVATE
, 'p'},
1089 {MODE_TOPICLIMIT
, 't'},
1090 {MODE_NOCOLOR
, 'c'},
1091 {MODE_FREEINVITE
, 'g'},
1092 {MODE_OPMODERATE
, 'z'},
1093 {MODE_EXLIMIT
, 'L'},
1094 {MODE_PERMANENT
, 'P'},
1095 {MODE_FREETARGET
, 'F'},
1096 {MODE_DISFORWARD
, 'Q'},
1097 {MODE_REGONLY
, 'r'},
1103 * inputs - pointer to channel
1104 * - pointer to client
1105 * output - string with simple modes
1106 * side effects - result from previous calls overwritten
1108 * Stolen from ShadowIRCd 4 --nenolod
1111 channel_modes(struct Channel
*chptr
, struct Client
*client_p
)
1116 static char final
[BUFSIZE
];
1123 for (i
= 0; chmode_flags
[i
].mode
; ++i
)
1124 if(chptr
->mode
.mode
& chmode_flags
[i
].mode
)
1125 *mbuf
++ = chmode_flags
[i
].letter
;
1127 if(chptr
->mode
.limit
)
1131 if(!IsClient(client_p
) || IsMember(client_p
, chptr
))
1132 pbuf
+= rb_sprintf(pbuf
, " %d", chptr
->mode
.limit
);
1135 if(*chptr
->mode
.key
)
1139 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1140 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.key
);
1143 if(chptr
->mode
.join_num
)
1147 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1148 pbuf
+= rb_sprintf(pbuf
, " %d:%d", chptr
->mode
.join_num
,
1149 chptr
->mode
.join_time
);
1152 if(*chptr
->mode
.forward
&& (ConfigChannel
.use_forward
|| !IsClient(client_p
)))
1156 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1157 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.forward
);
1162 rb_strlcpy(final
, buf1
, sizeof final
);
1163 rb_strlcat(final
, buf2
, sizeof final
);
1167 /* Now lets do some stuff to keep track of what combinations of
1169 * Note that the number of combinations doubles each time you add
1170 * something to this list. Each one is only quick if no servers use that
1171 * combination, but if the numbers get too high here MODE will get too
1172 * slow. I suggest if you get more than 7 here, you consider getting rid
1173 * of some and merging or something. If it wasn't for irc+cs we would
1174 * probably not even need to bother about most of these, but unfortunately
1178 /* void init_chcap_usage_counts(void)
1182 * Side-effects - Initialises the usage counts to zero. Fills in the
1183 * chcap_yes and chcap_no combination tables.
1186 init_chcap_usage_counts(void)
1188 unsigned long m
, c
, y
, n
;
1190 memset(chcap_combos
, 0, sizeof(chcap_combos
));
1192 /* For every possible combination */
1193 for (m
= 0; m
< NCHCAP_COMBOS
; m
++)
1195 /* Check each capab */
1196 for (c
= y
= n
= 0; c
< NCHCAPS
; c
++)
1198 if((m
& (1 << c
)) == 0)
1199 n
|= channel_capabs
[c
];
1201 y
|= channel_capabs
[c
];
1203 chcap_combos
[m
].cap_yes
= y
;
1204 chcap_combos
[m
].cap_no
= n
;
1208 /* void set_chcap_usage_counts(struct Client *serv_p)
1209 * Input: serv_p; The client whose capabs to register.
1211 * Side-effects: Increments the usage counts for the correct capab
1215 set_chcap_usage_counts(struct Client
*serv_p
)
1219 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1221 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1222 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1224 chcap_combos
[n
].count
++;
1229 /* This should be impossible -A1kmm. */
1233 /* void set_chcap_usage_counts(struct Client *serv_p)
1235 * Inputs - serv_p; The client whose capabs to register.
1237 * Side-effects - Decrements the usage counts for the correct capab
1241 unset_chcap_usage_counts(struct Client
*serv_p
)
1245 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1247 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1248 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1250 /* Hopefully capabs can't change dynamically or anything... */
1251 s_assert(chcap_combos
[n
].count
> 0);
1253 if(chcap_combos
[n
].count
> 0)
1254 chcap_combos
[n
].count
--;
1259 /* This should be impossible -A1kmm. */
1263 /* void send_cap_mode_changes(struct Client *client_p,
1264 * struct Client *source_p,
1265 * struct Channel *chptr, int cap, int nocap)
1266 * Input: The client sending(client_p), the source client(source_p),
1267 * the channel to send mode changes for(chptr)
1269 * Side-effects: Sends the appropriate mode changes to capable servers.
1271 * Reverted back to my original design, except that we now keep a count
1272 * of the number of servers which each combination as an optimisation, so
1273 * the capabs combinations which are not needed are not worked out. -A1kmm
1276 send_cap_mode_changes(struct Client
*client_p
, struct Client
*source_p
,
1277 struct Channel
*chptr
, struct ChModeChange mode_changes
[], int mode_count
)
1279 static char modebuf
[BUFSIZE
];
1280 static char parabuf
[BUFSIZE
];
1281 int i
, mbl
, pbl
, nc
, mc
, preflen
, len
;
1290 /* Now send to servers... */
1291 for (j
= 0; j
< NCHCAP_COMBOS
; j
++)
1293 if(chcap_combos
[j
].count
== 0)
1303 cap
= chcap_combos
[j
].cap_yes
;
1304 nocap
= chcap_combos
[j
].cap_no
;
1307 mbl
= preflen
= rb_sprintf(modebuf
, ":%s TMODE %ld %s ",
1308 use_id(source_p
), (long) chptr
->channelts
,
1311 mbl
= preflen
= rb_sprintf(modebuf
, ":%s MODE %s ",
1312 source_p
->name
, chptr
->chname
);
1314 /* loop the list of - modes we have */
1315 for (i
= 0; i
< mode_count
; i
++)
1317 /* if they dont support the cap we need, or they do support a cap they
1318 * cant have, then dont add it to the modebuf.. that way they wont see
1321 if((mode_changes
[i
].letter
== 0) ||
1322 ((cap
& mode_changes
[i
].caps
) != mode_changes
[i
].caps
)
1323 || ((nocap
& mode_changes
[i
].nocaps
) != mode_changes
[i
].nocaps
))
1326 if((cap
& CAP_TS6
) && !EmptyString(mode_changes
[i
].id
))
1327 arg
= mode_changes
[i
].id
;
1329 arg
= mode_changes
[i
].arg
;
1333 arglen
= strlen(arg
);
1335 /* dont even think about it! --fl */
1336 if(arglen
> MODEBUFLEN
- 5)
1340 /* if we're creeping past the buf size, we need to send it and make
1341 * another line for the other modes
1342 * XXX - this could give away server topology with uids being
1343 * different lengths, but not much we can do, except possibly break
1344 * them as if they were the longest of the nick or uid at all times,
1345 * which even then won't work as we don't always know the uid -A1kmm.
1347 if(arg
&& ((mc
== MAXMODEPARAMSSERV
) ||
1348 ((mbl
+ pbl
+ arglen
+ 4) > (BUFSIZE
- 3))))
1351 sendto_server(client_p
, chptr
, cap
, nocap
,
1352 "%s %s", modebuf
, parabuf
);
1363 if(dir
!= mode_changes
[i
].dir
)
1365 modebuf
[mbl
++] = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1366 dir
= mode_changes
[i
].dir
;
1369 modebuf
[mbl
++] = mode_changes
[i
].letter
;
1375 len
= rb_sprintf(pbuf
, "%s ", arg
);
1382 if(pbl
&& parabuf
[pbl
- 1] == ' ')
1383 parabuf
[pbl
- 1] = 0;
1386 sendto_server(client_p
, chptr
, cap
, nocap
, "%s %s", modebuf
, parabuf
);