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
34 #include "s_serv.h" /* captab */
38 #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
39 #include "s_newconf.h"
43 struct config_channel_entry ConfigChannel
;
44 rb_dlink_list global_channel_list
;
45 static rb_bh
*channel_heap
;
46 static rb_bh
*ban_heap
;
47 static rb_bh
*topic_heap
;
48 static rb_bh
*member_heap
;
50 static void free_topic(struct Channel
*chptr
);
52 static int h_can_join
;
53 static int h_can_send
;
54 int h_get_channel_access
;
60 * side effects - initialises the various blockheaps
65 channel_heap
= rb_bh_create(sizeof(struct Channel
), CHANNEL_HEAP_SIZE
, "channel_heap");
66 ban_heap
= rb_bh_create(sizeof(struct Ban
), BAN_HEAP_SIZE
, "ban_heap");
67 topic_heap
= rb_bh_create(TOPICLEN
+ 1 + USERHOST_REPLYLEN
, TOPIC_HEAP_SIZE
, "topic_heap");
68 member_heap
= rb_bh_create(sizeof(struct membership
), MEMBER_HEAP_SIZE
, "member_heap");
70 h_can_join
= register_hook("can_join");
71 h_can_send
= register_hook("can_send");
72 h_get_channel_access
= register_hook("get_channel_access");
76 * allocate_channel - Allocates a channel
79 allocate_channel(const char *chname
)
81 struct Channel
*chptr
;
82 chptr
= rb_bh_alloc(channel_heap
);
83 chptr
->chname
= rb_strdup(chname
);
88 free_channel(struct Channel
*chptr
)
90 rb_free(chptr
->chname
);
91 rb_free(chptr
->mode_lock
);
92 rb_bh_free(channel_heap
, chptr
);
96 allocate_ban(const char *banstr
, const char *who
, const char *forward
)
99 bptr
= rb_bh_alloc(ban_heap
);
100 bptr
->banstr
= rb_strdup(banstr
);
101 bptr
->who
= rb_strdup(who
);
102 bptr
->forward
= forward
? rb_strdup(forward
) : NULL
;
108 free_ban(struct Ban
*bptr
)
110 rb_free(bptr
->banstr
);
112 rb_free(bptr
->forward
);
113 rb_bh_free(ban_heap
, bptr
);
117 * send_channel_join()
119 * input - channel to join, client joining.
121 * side effects - none
124 send_channel_join(struct Channel
*chptr
, struct Client
*client_p
)
126 if (!IsClient(client_p
))
129 sendto_channel_local_with_capability(client_p
, ALL_MEMBERS
, NOCAPS
, CLICAP_EXTENDED_JOIN
, chptr
, ":%s!%s@%s JOIN %s",
130 client_p
->name
, client_p
->username
, client_p
->host
, chptr
->chname
);
132 sendto_channel_local_with_capability(client_p
, ALL_MEMBERS
, CLICAP_EXTENDED_JOIN
, NOCAPS
, chptr
, ":%s!%s@%s JOIN %s %s :%s",
133 client_p
->name
, client_p
->username
, client_p
->host
, chptr
->chname
,
134 EmptyString(client_p
->user
->suser
) ? "*" : client_p
->user
->suser
,
137 /* Send away message to away-notify enabled clients. */
138 if (client_p
->user
->away
)
139 sendto_channel_local_with_capability_butone(client_p
, ALL_MEMBERS
, CLICAP_AWAY_NOTIFY
, NOCAPS
, chptr
,
140 ":%s!%s@%s AWAY :%s", client_p
->name
, client_p
->username
,
141 client_p
->host
, client_p
->user
->away
);
144 /* find_channel_membership()
146 * input - channel to find them in, client to find
147 * output - membership of client in channel, else NULL
151 find_channel_membership(struct Channel
*chptr
, struct Client
*client_p
)
153 struct membership
*msptr
;
156 if(!IsClient(client_p
))
159 /* Pick the most efficient list to use to be nice to things like
160 * CHANSERV which could be in a large number of channels
162 if(rb_dlink_list_length(&chptr
->members
) < rb_dlink_list_length(&client_p
->user
->channel
))
164 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
168 if(msptr
->client_p
== client_p
)
174 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
178 if(msptr
->chptr
== chptr
)
186 /* find_channel_status()
188 * input - membership to get status for, whether we can combine flags
189 * output - flags of user on channel
193 find_channel_status(struct membership
*msptr
, int combine
)
195 static char buffer
[3];
214 /* add_user_to_channel()
216 * input - channel to add client to, client to add, channel flags
218 * side effects - user is added to channel
221 add_user_to_channel(struct Channel
*chptr
, struct Client
*client_p
, int flags
)
223 struct membership
*msptr
;
226 s_assert(client_p
->user
!= NULL
);
227 if(client_p
->user
== NULL
)
230 msptr
= rb_bh_alloc(member_heap
);
232 msptr
->chptr
= chptr
;
233 msptr
->client_p
= client_p
;
234 msptr
->flags
= flags
;
236 RB_DLINK_FOREACH(p
, client_p
->user
->channel
.head
)
238 struct membership
*ms2
= p
->data
;
239 if (irccmp(chptr
->chname
, ms2
->chptr
->chname
) < 0)
243 rb_dlinkAddTail(msptr
, &msptr
->usernode
, &client_p
->user
->channel
);
245 rb_dlinkAddBefore(p
, msptr
, &msptr
->usernode
, &client_p
->user
->channel
);
247 rb_dlinkAdd(msptr
, &msptr
->channode
, &chptr
->members
);
249 if(MyClient(client_p
))
250 rb_dlinkAdd(msptr
, &msptr
->locchannode
, &chptr
->locmembers
);
253 /* remove_user_from_channel()
255 * input - membership pointer to remove from channel
257 * side effects - membership (thus user) is removed from channel
260 remove_user_from_channel(struct membership
*msptr
)
262 struct Client
*client_p
;
263 struct Channel
*chptr
;
264 s_assert(msptr
!= NULL
);
268 client_p
= msptr
->client_p
;
269 chptr
= msptr
->chptr
;
271 rb_dlinkDelete(&msptr
->usernode
, &client_p
->user
->channel
);
272 rb_dlinkDelete(&msptr
->channode
, &chptr
->members
);
274 if(client_p
->servptr
== &me
)
275 rb_dlinkDelete(&msptr
->locchannode
, &chptr
->locmembers
);
277 if(!(chptr
->mode
.mode
& MODE_PERMANENT
) && rb_dlink_list_length(&chptr
->members
) <= 0)
278 destroy_channel(chptr
);
280 rb_bh_free(member_heap
, msptr
);
285 /* remove_user_from_channels()
287 * input - user to remove from all channels
289 * side effects - user is removed from all channels
292 remove_user_from_channels(struct Client
*client_p
)
294 struct Channel
*chptr
;
295 struct membership
*msptr
;
297 rb_dlink_node
*next_ptr
;
302 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->user
->channel
.head
)
305 chptr
= msptr
->chptr
;
307 rb_dlinkDelete(&msptr
->channode
, &chptr
->members
);
309 if(client_p
->servptr
== &me
)
310 rb_dlinkDelete(&msptr
->locchannode
, &chptr
->locmembers
);
312 if(!(chptr
->mode
.mode
& MODE_PERMANENT
) && rb_dlink_list_length(&chptr
->members
) <= 0)
313 destroy_channel(chptr
);
315 rb_bh_free(member_heap
, msptr
);
318 client_p
->user
->channel
.head
= client_p
->user
->channel
.tail
= NULL
;
319 client_p
->user
->channel
.length
= 0;
322 /* invalidate_bancache_user()
324 * input - user to invalidate ban cache for
326 * side effects - ban cache is invalidated for all memberships of that user
327 * to be used after a nick change
330 invalidate_bancache_user(struct Client
*client_p
)
332 struct membership
*msptr
;
338 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
342 msptr
->flags
&= ~CHFL_BANNED
;
346 /* check_channel_name()
348 * input - channel name
349 * output - true if valid channel name, else false
353 check_channel_name(const char *name
)
355 s_assert(name
!= NULL
);
359 for (; *name
; ++name
)
361 if(!IsChanChar(*name
))
368 /* free_channel_list()
370 * input - rb_dlink list to free
372 * side effects - list of b/e/I modes is cleared
375 free_channel_list(rb_dlink_list
* list
)
378 rb_dlink_node
*next_ptr
;
379 struct Ban
*actualBan
;
381 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
383 actualBan
= ptr
->data
;
387 list
->head
= list
->tail
= NULL
;
393 * input - channel to destroy
395 * side effects - channel is obliterated
398 destroy_channel(struct Channel
*chptr
)
400 rb_dlink_node
*ptr
, *next_ptr
;
402 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
404 del_invite(chptr
, ptr
->data
);
407 /* free all bans/exceptions/denies */
408 free_channel_list(&chptr
->banlist
);
409 free_channel_list(&chptr
->exceptlist
);
410 free_channel_list(&chptr
->invexlist
);
411 free_channel_list(&chptr
->quietlist
);
416 rb_dlinkDelete(&chptr
->node
, &global_channel_list
);
417 del_from_channel_hash(chptr
->chname
, chptr
);
421 /* channel_pub_or_secret()
424 * output - "=" if public, "@" if secret, else "*"
428 channel_pub_or_secret(struct Channel
*chptr
)
430 if(PubChannel(chptr
))
432 else if(SecretChannel(chptr
))
438 iter_comm_channels_step(rb_dlink_node
*pos1
, rb_dlink_node
*pos2
,
439 struct membership
**ms1
, struct membership
**ms2
,
440 struct Channel
**chptr
)
442 *ms1
= pos1
? pos1
->data
: NULL
;
443 *ms2
= pos2
? pos2
->data
: NULL
;
445 /* we're at the end */
446 if (*ms1
== NULL
&& *ms2
== NULL
)
449 /* one side is at the end, keep stepping the other one */
450 if (*ms1
== NULL
|| *ms2
== NULL
)
452 *chptr
= *ms1
!= NULL
? (*ms1
)->chptr
: (*ms2
)->chptr
;
457 if ((*ms1
)->chptr
== (*ms2
)->chptr
)
459 *chptr
= (*ms1
)->chptr
;
463 /* null out the channel that's further ahead; we'll get to it later */
464 if (irccmp((*ms1
)->chptr
->chname
, (*ms2
)->chptr
->chname
) > 0)
467 *chptr
= (*ms2
)->chptr
;
473 *chptr
= (*ms1
)->chptr
;
478 /* channel_member_names()
480 * input - channel to list, client to list to, show endofnames
482 * side effects - client is given list of users on channel
485 channel_member_names(struct Channel
*chptr
, struct Client
*client_p
, int show_eon
)
487 struct membership
*msptr
;
488 struct Client
*target_p
;
496 int stack
= IsCapable(client_p
, CLICAP_MULTI_PREFIX
);
498 if(ShowChannel(client_p
, chptr
))
500 is_member
= IsMember(client_p
, chptr
);
502 cur_len
= mlen
= sprintf(lbuf
, form_str(RPL_NAMREPLY
),
503 me
.name
, client_p
->name
,
504 channel_pub_or_secret(chptr
), chptr
->chname
);
508 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
511 target_p
= msptr
->client_p
;
513 if(IsInvisible(target_p
) && !is_member
)
516 if (IsCapable(client_p
, CLICAP_USERHOST_IN_NAMES
))
518 /* space, possible "@+" prefix */
519 if (cur_len
+ strlen(target_p
->name
) + strlen(target_p
->username
) + strlen(target_p
->host
) + 5 >= BUFSIZE
- 5)
522 sendto_one(client_p
, "%s", lbuf
);
527 tlen
= sprintf(t
, "%s%s!%s@%s ", find_channel_status(msptr
, stack
),
528 target_p
->name
, target_p
->username
, target_p
->host
);
532 /* space, possible "@+" prefix */
533 if(cur_len
+ strlen(target_p
->name
) + 3 >= BUFSIZE
- 3)
536 sendto_one(client_p
, "%s", lbuf
);
541 tlen
= sprintf(t
, "%s%s ", find_channel_status(msptr
, stack
),
549 /* The old behaviour here was to always output our buffer,
550 * even if there are no clients we can show. This happens
551 * when a client does "NAMES" with no parameters, and all
552 * the clients on a -sp channel are +i. I dont see a good
553 * reason for keeping that behaviour, as it just wastes
559 sendto_one(client_p
, "%s", lbuf
);
564 sendto_one(client_p
, form_str(RPL_ENDOFNAMES
),
565 me
.name
, client_p
->name
, chptr
->chname
);
570 * input - channel to remove invite from, client to remove
572 * side effects - user is removed from invite list, if exists
575 del_invite(struct Channel
*chptr
, struct Client
*who
)
577 rb_dlinkFindDestroy(who
, &chptr
->invites
);
578 rb_dlinkFindDestroy(chptr
, &who
->user
->invited
);
583 * input - channel to check bans for, ban list (banlist or quietlist),
584 * user to check bans against, optional prebuilt buffers,
585 * optional forward channel pointer
586 * output - 1 if banned, else 0
590 is_banned_list(struct Channel
*chptr
, rb_dlink_list
*list
,
591 struct Client
*who
, struct membership
*msptr
,
592 const struct matchset
*ms
, const char **forward
)
596 struct Ban
*actualBan
= NULL
;
597 struct Ban
*actualExcept
= NULL
;
604 matchset_for_client(who
, &ms_
);
608 RB_DLINK_FOREACH(ptr
, list
->head
)
610 actualBan
= ptr
->data
;
611 if (matches_mask(ms
, actualBan
->banstr
))
613 if (match_extban(actualBan
->banstr
, who
, chptr
, CHFL_BAN
))
618 if ((actualBan
!= NULL
) && ConfigChannel
.use_except
)
620 RB_DLINK_FOREACH(ptr
, chptr
->exceptlist
.head
)
622 actualExcept
= ptr
->data
;
624 /* theyre exempted.. */
625 if (matches_mask(ms
, actualExcept
->banstr
) ||
626 match_extban(actualExcept
->banstr
, who
, chptr
, CHFL_EXCEPTION
))
628 /* cache the fact theyre not banned */
631 msptr
->bants
= chptr
->bants
;
632 msptr
->flags
&= ~CHFL_BANNED
;
635 return CHFL_EXCEPTION
;
640 /* cache the banned/not banned status */
643 msptr
->bants
= chptr
->bants
;
645 if(actualBan
!= NULL
)
647 msptr
->flags
|= CHFL_BANNED
;
652 msptr
->flags
&= ~CHFL_BANNED
;
657 if (actualBan
&& actualBan
->forward
&& forward
)
658 *forward
= actualBan
->forward
;
660 return ((actualBan
? CHFL_BAN
: 0));
665 * input - channel to check bans for, user to check bans against
666 * optional prebuilt buffers, optional forward channel pointer
667 * output - 1 if banned, else 0
671 is_banned(struct Channel
*chptr
, struct Client
*who
, struct membership
*msptr
,
672 const struct matchset
*ms
, const char **forward
)
675 if (chptr
->last_checked_client
!= NULL
&&
676 who
== chptr
->last_checked_client
&&
677 chptr
->last_checked_type
== CHFL_BAN
&&
678 chptr
->last_checked_ts
> chptr
->bants
)
679 return chptr
->last_checked_result
;
681 chptr
->last_checked_client
= who
;
682 chptr
->last_checked_type
= CHFL_BAN
;
683 chptr
->last_checked_result
= is_banned_list(chptr
, &chptr
->banlist
, who
, msptr
, s
, s2
, forward
);
684 chptr
->last_checked_ts
= rb_current_time();
686 return chptr
->last_checked_result
;
688 return is_banned_list(chptr
, &chptr
->banlist
, who
, msptr
, ms
, forward
);
694 * input - channel to check bans for, user to check bans against
695 * optional prebuilt buffers
696 * output - 1 if banned, else 0
700 is_quieted(struct Channel
*chptr
, struct Client
*who
, struct membership
*msptr
,
701 const struct matchset
*ms
)
704 if (chptr
->last_checked_client
!= NULL
&&
705 who
== chptr
->last_checked_client
&&
706 chptr
->last_checked_type
== CHFL_QUIET
&&
707 chptr
->last_checked_ts
> chptr
->bants
)
708 return chptr
->last_checked_result
;
710 chptr
->last_checked_client
= who
;
711 chptr
->last_checked_type
= CHFL_QUIET
;
712 chptr
->last_checked_result
= is_banned_list(chptr
, &chptr
->quietlist
, who
, msptr
, s
, s2
, NULL
);
713 chptr
->last_checked_ts
= rb_current_time();
715 return chptr
->last_checked_result
;
717 return is_banned_list(chptr
, &chptr
->quietlist
, who
, msptr
, ms
, NULL
);
723 * input - client to check, channel to check for, key
724 * output - reason for not being able to join, else 0, channel name to forward to
726 * caveats - this function should only be called on a local user.
729 can_join(struct Client
*source_p
, struct Channel
*chptr
, const char *key
, const char **forward
)
731 rb_dlink_node
*invite
= NULL
;
733 struct Ban
*invex
= NULL
;
736 hook_data_channel moduledata
;
738 s_assert(source_p
->localClient
!= NULL
);
740 moduledata
.client
= source_p
;
741 moduledata
.chptr
= chptr
;
742 moduledata
.approved
= 0;
744 matchset_for_client(source_p
, &ms
);
746 if((is_banned(chptr
, source_p
, NULL
, &ms
, forward
)) == CHFL_BAN
)
748 moduledata
.approved
= ERR_BANNEDFROMCHAN
;
749 goto finish_join_check
;
752 if(*chptr
->mode
.key
&& (EmptyString(key
) || irccmp(chptr
->mode
.key
, key
)))
754 moduledata
.approved
= ERR_BADCHANNELKEY
;
755 goto finish_join_check
;
758 /* All checks from this point on will forward... */
760 *forward
= chptr
->mode
.forward
;
762 if(chptr
->mode
.mode
& MODE_INVITEONLY
)
764 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
766 if(invite
->data
== chptr
)
771 if(!ConfigChannel
.use_invex
)
772 moduledata
.approved
= ERR_INVITEONLYCHAN
;
773 RB_DLINK_FOREACH(ptr
, chptr
->invexlist
.head
)
776 if (matches_mask(&ms
, invex
->banstr
) ||
777 match_extban(invex
->banstr
, source_p
, chptr
, CHFL_INVEX
))
781 moduledata
.approved
= ERR_INVITEONLYCHAN
;
785 if(chptr
->mode
.limit
&&
786 rb_dlink_list_length(&chptr
->members
) >= (unsigned long) chptr
->mode
.limit
)
787 i
= ERR_CHANNELISFULL
;
788 if(chptr
->mode
.mode
& MODE_REGONLY
&& EmptyString(source_p
->user
->suser
))
789 i
= ERR_NEEDREGGEDNICK
;
790 /* join throttling stuff --nenolod */
791 else if(chptr
->mode
.join_num
> 0 && chptr
->mode
.join_time
> 0)
793 if ((rb_current_time() - chptr
->join_delta
<=
794 chptr
->mode
.join_time
) && (chptr
->join_count
>=
795 chptr
->mode
.join_num
))
799 /* allow /invite to override +l/+r/+j also -- jilles */
800 if (i
!= 0 && invite
== NULL
)
802 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
804 if(invite
->data
== chptr
)
808 moduledata
.approved
= i
;
812 call_hook(h_can_join
, &moduledata
);
814 return moduledata
.approved
;
819 * input - user to check in channel, membership pointer
820 * output - whether can explicitly send or not, else CAN_SEND_NONOP
824 can_send(struct Channel
*chptr
, struct Client
*source_p
, struct membership
*msptr
)
826 hook_data_channel_approval moduledata
;
828 moduledata
.approved
= CAN_SEND_NONOP
;
829 moduledata
.dir
= MODE_QUERY
;
831 if(IsServer(source_p
) || IsService(source_p
))
834 if(MyClient(source_p
) && hash_find_resv(chptr
->chname
) &&
835 !IsOper(source_p
) && !IsExemptResv(source_p
))
836 moduledata
.approved
= CAN_SEND_NO
;
840 msptr
= find_channel_membership(chptr
, source_p
);
844 /* if its +m or +n and theyre not in the channel,
845 * they cant send. we dont check bans here because
846 * theres no possibility of caching them --fl
848 if(chptr
->mode
.mode
& MODE_NOPRIVMSGS
|| chptr
->mode
.mode
& MODE_MODERATED
)
849 moduledata
.approved
= CAN_SEND_NO
;
851 moduledata
.approved
= CAN_SEND_NONOP
;
853 return moduledata
.approved
;
857 if(chptr
->mode
.mode
& MODE_MODERATED
)
858 moduledata
.approved
= CAN_SEND_NO
;
860 if(MyClient(source_p
))
862 /* cached can_send */
863 if(msptr
->bants
== chptr
->bants
)
865 if(can_send_banned(msptr
))
866 moduledata
.approved
= CAN_SEND_NO
;
868 else if(is_banned(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
869 || is_quieted(chptr
, source_p
, msptr
, NULL
) == CHFL_BAN
)
870 moduledata
.approved
= CAN_SEND_NO
;
873 if(is_chanop_voiced(msptr
))
874 moduledata
.approved
= CAN_SEND_OPV
;
876 moduledata
.client
= source_p
;
877 moduledata
.chptr
= msptr
->chptr
;
878 moduledata
.msptr
= msptr
;
879 moduledata
.target
= NULL
;
880 moduledata
.dir
= (moduledata
.approved
== CAN_SEND_NO
) ? MODE_ADD
: MODE_QUERY
;
882 call_hook(h_can_send
, &moduledata
);
884 return moduledata
.approved
;
888 * flood_attack_channel
889 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
890 * says NOTICE must not auto reply
891 * - pointer to source Client
892 * - pointer to target channel
893 * output - true if target is under flood attack
894 * side effects - check for flood attack on target chptr
897 flood_attack_channel(int p_or_n
, struct Client
*source_p
, struct Channel
*chptr
, char *chname
)
901 if(GlobalSetOptions
.floodcount
&& MyClient(source_p
))
903 if((chptr
->first_received_message_time
+ 1) < rb_current_time())
905 delta
= rb_current_time() - chptr
->first_received_message_time
;
906 chptr
->received_number_of_privmsgs
-= delta
;
907 chptr
->first_received_message_time
= rb_current_time();
908 if(chptr
->received_number_of_privmsgs
<= 0)
910 chptr
->received_number_of_privmsgs
= 0;
911 chptr
->flood_noticed
= 0;
915 if((chptr
->received_number_of_privmsgs
>= GlobalSetOptions
.floodcount
)
916 || chptr
->flood_noticed
)
918 if(chptr
->flood_noticed
== 0)
920 sendto_realops_snomask(SNO_BOTS
, *chptr
->chname
== '&' ? L_ALL
: L_NETWIDE
,
921 "Possible Flooder %s[%s@%s] on %s target: %s",
922 source_p
->name
, source_p
->username
,
924 source_p
->servptr
->name
, chptr
->chname
);
925 chptr
->flood_noticed
= 1;
927 /* Add a bit of penalty */
928 chptr
->received_number_of_privmsgs
+= 2;
930 if(MyClient(source_p
) && (p_or_n
!= 1))
932 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
933 me
.name
, source_p
->name
, chptr
->chname
);
937 chptr
->received_number_of_privmsgs
++;
943 /* find_bannickchange_channel()
944 * Input: client to check
945 * Output: channel preventing nick change
948 find_bannickchange_channel(struct Client
*client_p
)
950 struct Channel
*chptr
;
951 struct membership
*msptr
;
955 if (!MyClient(client_p
))
958 matchset_for_client(client_p
, &ms
);
960 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
963 chptr
= msptr
->chptr
;
964 if (is_chanop_voiced(msptr
))
966 /* cached can_send */
967 if (msptr
->bants
== chptr
->bants
)
969 if (can_send_banned(msptr
))
972 else if (is_banned(chptr
, client_p
, msptr
, &ms
, NULL
) == CHFL_BAN
973 || is_quieted(chptr
, client_p
, msptr
, &ms
) == CHFL_BAN
)
979 /* void check_spambot_warning(struct Client *source_p)
980 * Input: Client to check, channel name or NULL if this is a part.
982 * Side-effects: Updates the client's oper_warn_count_down, warns the
983 * IRC operators if necessary, and updates join_leave_countdown as
987 check_spambot_warning(struct Client
*source_p
, const char *name
)
991 if((GlobalSetOptions
.spam_num
&&
992 (source_p
->localClient
->join_leave_count
>= GlobalSetOptions
.spam_num
)))
994 if(source_p
->localClient
->oper_warn_count_down
> 0)
995 source_p
->localClient
->oper_warn_count_down
--;
997 source_p
->localClient
->oper_warn_count_down
= 0;
998 if(source_p
->localClient
->oper_warn_count_down
== 0 &&
1001 /* Its already known as a possible spambot */
1002 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
1003 "User %s (%s@%s) trying to join %s is a possible spambot",
1005 source_p
->username
, source_p
->orighost
, name
);
1006 source_p
->localClient
->oper_warn_count_down
= OPER_SPAM_COUNTDOWN
;
1012 (rb_current_time() - source_p
->localClient
->last_leave_time
)) >
1013 JOIN_LEAVE_COUNT_EXPIRE_TIME
)
1015 decrement_count
= (t_delta
/ JOIN_LEAVE_COUNT_EXPIRE_TIME
);
1018 else if(decrement_count
> source_p
->localClient
->join_leave_count
)
1019 source_p
->localClient
->join_leave_count
= 0;
1021 source_p
->localClient
->join_leave_count
-= decrement_count
;
1025 if((rb_current_time() -
1026 (source_p
->localClient
->last_join_time
)) < GlobalSetOptions
.spam_time
)
1028 /* oh, its a possible spambot */
1029 source_p
->localClient
->join_leave_count
++;
1033 source_p
->localClient
->last_join_time
= rb_current_time();
1035 source_p
->localClient
->last_leave_time
= rb_current_time();
1039 /* check_splitmode()
1043 * side effects - compares usercount and servercount against their split
1044 * values and adjusts splitmode accordingly
1047 check_splitmode(void *unused
)
1049 if(splitchecking
&& (ConfigChannel
.no_join_on_split
|| ConfigChannel
.no_create_on_split
))
1051 /* not split, we're being asked to check now because someone
1056 if(eob_count
< split_servers
|| Count
.total
< split_users
)
1059 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1060 "Network split, activating splitmode");
1061 check_splitmode_ev
= rb_event_addish("check_splitmode", check_splitmode
, NULL
, 2);
1064 /* in splitmode, check whether its finished */
1065 else if(eob_count
>= split_servers
&& Count
.total
>= split_users
)
1069 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1070 "Network rejoined, deactivating splitmode");
1072 rb_event_delete(check_splitmode_ev
);
1073 check_splitmode_ev
= NULL
;
1081 * input - channel to allocate topic for
1082 * output - 1 on success, else 0
1083 * side effects - channel gets a topic allocated
1086 allocate_topic(struct Channel
*chptr
)
1093 ptr
= rb_bh_alloc(topic_heap
);
1095 /* Basically we allocate one large block for the topic and
1096 * the topic info. We then split it up into two and shove it
1100 chptr
->topic_info
= (char *) ptr
+ TOPICLEN
+ 1;
1101 *chptr
->topic
= '\0';
1102 *chptr
->topic_info
= '\0';
1107 * input - channel which has topic to free
1109 * side effects - channels topic is free'd
1112 free_topic(struct Channel
*chptr
)
1116 if(chptr
== NULL
|| chptr
->topic
== NULL
)
1119 /* This is safe for now - If you change allocate_topic you
1120 * MUST change this as well
1123 rb_bh_free(topic_heap
, ptr
);
1124 chptr
->topic
= NULL
;
1125 chptr
->topic_info
= NULL
;
1128 /* set_channel_topic()
1130 * input - channel, topic to set, topic info and topic ts
1132 * side effects - channels topic, topic info and TS are set.
1135 set_channel_topic(struct Channel
*chptr
, const char *topic
, const char *topic_info
, time_t topicts
)
1137 if(strlen(topic
) > 0)
1139 if(chptr
->topic
== NULL
)
1140 allocate_topic(chptr
);
1141 rb_strlcpy(chptr
->topic
, topic
, TOPICLEN
+ 1);
1142 rb_strlcpy(chptr
->topic_info
, topic_info
, USERHOST_REPLYLEN
);
1143 chptr
->topic_time
= topicts
;
1147 if(chptr
->topic
!= NULL
)
1149 chptr
->topic_time
= 0;
1155 * inputs - pointer to channel
1156 * - pointer to client
1157 * output - string with simple modes
1158 * side effects - result from previous calls overwritten
1160 * Stolen from ShadowIRCd 4 --nenolod
1163 channel_modes(struct Channel
*chptr
, struct Client
*client_p
)
1168 static char final
[BUFSIZE
];
1175 for (i
= 0; i
< 256; i
++)
1177 if(chmode_table
[i
].set_func
== chm_hidden
&& (!HasPrivilege(client_p
, "auspex:cmodes") || !IsClient(client_p
)))
1179 if(chptr
->mode
.mode
& chmode_flags
[i
])
1183 if(chptr
->mode
.limit
)
1187 if(!IsClient(client_p
) || IsMember(client_p
, chptr
))
1188 pbuf
+= sprintf(pbuf
, " %d", chptr
->mode
.limit
);
1191 if(*chptr
->mode
.key
)
1195 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1196 pbuf
+= sprintf(pbuf
, " %s", chptr
->mode
.key
);
1199 if(chptr
->mode
.join_num
)
1203 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1204 pbuf
+= sprintf(pbuf
, " %d:%d", chptr
->mode
.join_num
,
1205 chptr
->mode
.join_time
);
1208 if(*chptr
->mode
.forward
&&
1209 (ConfigChannel
.use_forward
|| !IsClient(client_p
)))
1213 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1214 pbuf
+= sprintf(pbuf
, " %s", chptr
->mode
.forward
);
1219 rb_strlcpy(final
, buf1
, sizeof final
);
1220 rb_strlcat(final
, buf2
, sizeof final
);
1224 /* void send_cap_mode_changes(struct Client *client_p,
1225 * struct Client *source_p,
1226 * struct Channel *chptr, int cap, int nocap)
1227 * Input: The client sending(client_p), the source client(source_p),
1228 * the channel to send mode changes for(chptr)
1230 * Side-effects: Sends the appropriate mode changes to capable servers.
1232 * Reverted back to my original design, except that we now keep a count
1233 * of the number of servers which each combination as an optimisation, so
1234 * the capabs combinations which are not needed are not worked out. -A1kmm
1236 * Removed most code here because we don't need to be compatible with ircd
1237 * 2.8.21+CSr and stuff. --nenolod
1240 send_cap_mode_changes(struct Client
*client_p
, struct Client
*source_p
,
1241 struct Channel
*chptr
, struct ChModeChange mode_changes
[], int mode_count
)
1243 static char modebuf
[BUFSIZE
];
1244 static char parabuf
[BUFSIZE
];
1245 int i
, mbl
, pbl
, nc
, mc
, preflen
, len
;
1251 /* Now send to servers... */
1259 mbl
= preflen
= sprintf(modebuf
, ":%s TMODE %ld %s ",
1260 use_id(source_p
), (long) chptr
->channelts
,
1263 /* loop the list of - modes we have */
1264 for (i
= 0; i
< mode_count
; i
++)
1266 /* if they dont support the cap we need, or they do support a cap they
1267 * cant have, then dont add it to the modebuf.. that way they wont see
1270 if (mode_changes
[i
].letter
== 0)
1273 if (!EmptyString(mode_changes
[i
].id
))
1274 arg
= mode_changes
[i
].id
;
1276 arg
= mode_changes
[i
].arg
;
1280 arglen
= strlen(arg
);
1282 /* dont even think about it! --fl */
1283 if(arglen
> MODEBUFLEN
- 5)
1287 /* if we're creeping past the buf size, we need to send it and make
1288 * another line for the other modes
1289 * XXX - this could give away server topology with uids being
1290 * different lengths, but not much we can do, except possibly break
1291 * them as if they were the longest of the nick or uid at all times,
1292 * which even then won't work as we don't always know the uid -A1kmm.
1294 if(arg
&& ((mc
== MAXMODEPARAMSSERV
) ||
1295 ((mbl
+ pbl
+ arglen
+ 4) > (BUFSIZE
- 3))))
1298 sendto_server(client_p
, chptr
, NOCAPS
, NOCAPS
,
1299 "%s %s", modebuf
, parabuf
);
1310 if(dir
!= mode_changes
[i
].dir
)
1312 modebuf
[mbl
++] = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1313 dir
= mode_changes
[i
].dir
;
1316 modebuf
[mbl
++] = mode_changes
[i
].letter
;
1322 len
= sprintf(pbuf
, "%s ", arg
);
1329 if(pbl
&& parabuf
[pbl
- 1] == ' ')
1330 parabuf
[pbl
- 1] = 0;
1333 sendto_server(client_p
, chptr
, NOCAPS
, NOCAPS
, "%s %s", modebuf
, parabuf
);
1337 resv_chan_forcepart(const char *name
, const char *reason
, int temp_time
)
1340 rb_dlink_node
*next_ptr
;
1341 struct Channel
*chptr
;
1342 struct membership
*msptr
;
1343 struct Client
*target_p
;
1345 if(!ConfigChannel
.resv_forcepart
)
1348 /* for each user on our server in the channel list
1349 * send them a PART, and notify opers.
1351 chptr
= find_channel(name
);
1354 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
1357 target_p
= msptr
->client_p
;
1359 if(IsExemptResv(target_p
))
1362 sendto_server(target_p
, chptr
, CAP_TS6
, NOCAPS
,
1363 ":%s PART %s", target_p
->id
, chptr
->chname
);
1365 sendto_channel_local(target_p
, ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s :%s",
1366 target_p
->name
, target_p
->username
,
1367 target_p
->host
, chptr
->chname
, target_p
->name
);
1369 remove_user_from_channel(msptr
);
1371 /* notify opers & user they were removed from the channel */
1372 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1373 "Forced PART for %s!%s@%s from %s (%s)",
1374 target_p
->name
, target_p
->username
,
1375 target_p
->host
, name
, reason
);
1378 sendto_one_notice(target_p
, ":*** Channel %s is temporarily unavailable on this server.",
1381 sendto_one_notice(target_p
, ":*** Channel %s is no longer available on this server.",