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
36 #include "s_serv.h" /* captab */
40 #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
41 #include "s_newconf.h"
44 #include "irc_dictionary.h"
46 struct config_channel_entry ConfigChannel
;
47 rb_dlink_list global_channel_list
;
48 static rb_bh
*channel_heap
;
49 static rb_bh
*ban_heap
;
50 static rb_bh
*topic_heap
;
51 static rb_bh
*member_heap
;
53 static int channel_capabs
[] = { CAP_EX
, CAP_IE
,
58 #define NCHCAPS (sizeof(channel_capabs)/sizeof(int))
59 #define NCHCAP_COMBOS (1 << NCHCAPS)
61 static struct ChCapCombo chcap_combos
[NCHCAP_COMBOS
];
63 static void free_topic(struct Channel
*chptr
);
65 static int h_can_join
;
66 static int h_can_create_channel
;
67 static int h_channel_join
;
73 * side effects - initialises the various blockheaps
78 channel_heap
= rb_bh_create(sizeof(struct Channel
), CHANNEL_HEAP_SIZE
, "channel_heap");
79 ban_heap
= rb_bh_create(sizeof(struct Ban
), BAN_HEAP_SIZE
, "ban_heap");
80 topic_heap
= rb_bh_create(TOPICLEN
+ 1 + USERHOST_REPLYLEN
, TOPIC_HEAP_SIZE
, "topic_heap");
81 member_heap
= rb_bh_create(sizeof(struct membership
), MEMBER_HEAP_SIZE
, "member_heap");
83 h_can_join
= register_hook("can_join");
84 h_channel_join
= register_hook("channel_join");
85 h_can_create_channel
= register_hook("can_create_channel");
89 * allocate_channel - Allocates a channel
92 allocate_channel(const char *chname
)
94 struct Channel
*chptr
;
95 struct Dictionary
*metadata
;
96 chptr
= rb_bh_alloc(channel_heap
);
97 chptr
->chname
= rb_strdup(chname
);
99 metadata
= irc_dictionary_create(irccmp
);
100 chptr
->metadata
= metadata
;
105 free_channel(struct Channel
*chptr
)
107 channel_metadata_clear(chptr
);
108 rb_free(chptr
->chname
);
109 rb_free(chptr
->mode_lock
);
110 rb_bh_free(channel_heap
, chptr
);
114 allocate_ban(const char *banstr
, const char *who
)
117 bptr
= rb_bh_alloc(ban_heap
);
118 bptr
->banstr
= rb_strdup(banstr
);
119 bptr
->who
= rb_strdup(who
);
125 free_ban(struct Ban
*bptr
)
127 rb_free(bptr
->banstr
);
129 rb_bh_free(ban_heap
, bptr
);
133 /* find_channel_membership()
135 * input - channel to find them in, client to find
136 * output - membership of client in channel, else NULL
140 find_channel_membership(struct Channel
*chptr
, struct Client
*client_p
)
142 struct membership
*msptr
;
145 if(!IsClient(client_p
))
148 /* Pick the most efficient list to use to be nice to things like
149 * CHANSERV which could be in a large number of channels
151 if(rb_dlink_list_length(&chptr
->members
) < rb_dlink_list_length(&client_p
->user
->channel
))
153 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
157 if(msptr
->client_p
== client_p
)
163 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
167 if(msptr
->chptr
== chptr
)
175 /* find_channel_status()
177 * input - membership to get status for, whether we can combine flags
178 * output - flags of user on channel
182 find_channel_status(struct membership
*msptr
, int combine
)
184 static char buffer
[5];
219 * input - membership to check for halfops
220 * output - 1 if the user is halfopped, 0 if the user is not or halfop
226 is_halfop(struct membership
*msptr
)
228 if(!ConfigChannel
.use_halfop
)
230 if(is_chmode_h(msptr
))
238 * input - membership to check for admin
239 * output - 1 if the user is an admin, 0 if the user is not or admin
245 is_admin(struct membership
*msptr
)
247 if(!ConfigChannel
.use_admin
)
249 if(is_chmode_a(msptr
))
257 * input - membership to check for ops
258 * output - 1 if the user is op, halfop, or admin, 0 elsewise
262 is_any_op(struct membership
*msptr
)
264 if(is_chanop(msptr
) || is_halfop(msptr
) || is_admin(msptr
))
270 /* is_chanop_voiced()
272 * input - memebership to check for status
273 * output - 1 if the user is op, halfop, admin, or voice, 0 elsewise
277 is_chanop_voiced(struct membership
*msptr
)
279 if(is_chanop(msptr
) || is_voiced(msptr
) || is_halfop(msptr
) || is_admin(msptr
))
287 * input - two memeberships
288 * output - 1 if the first memebership can kick/deop the second, 0 elsewise
292 can_kick_deop(struct membership
*source
, struct membership
*target
)
294 if(is_chanop(source
) && !is_admin(target
))
296 else if(is_halfop(source
) && !is_any_op(target
))
298 else if(is_admin(source
))
304 /* add_user_to_channel()
306 * input - channel to add client to, client to add, channel flags
308 * side effects - user is added to channel
311 add_user_to_channel(struct Channel
*chptr
, struct Client
*client_p
, int flags
)
313 struct membership
*msptr
;
315 s_assert(client_p
->user
!= NULL
);
316 if(client_p
->user
== NULL
)
319 msptr
= rb_bh_alloc(member_heap
);
321 msptr
->chptr
= chptr
;
322 msptr
->client_p
= client_p
;
323 msptr
->flags
= flags
;
325 rb_dlinkAdd(msptr
, &msptr
->usernode
, &client_p
->user
->channel
);
326 rb_dlinkAdd(msptr
, &msptr
->channode
, &chptr
->members
);
328 if(MyClient(client_p
))
329 rb_dlinkAdd(msptr
, &msptr
->locchannode
, &chptr
->locmembers
);
332 /* remove_user_from_channel()
334 * input - membership pointer to remove from channel
336 * side effects - membership (thus user) is removed from channel
339 remove_user_from_channel(struct membership
*msptr
)
341 struct Client
*client_p
;
342 struct Channel
*chptr
;
343 s_assert(msptr
!= NULL
);
347 client_p
= msptr
->client_p
;
348 chptr
= msptr
->chptr
;
350 rb_dlinkDelete(&msptr
->usernode
, &client_p
->user
->channel
);
351 rb_dlinkDelete(&msptr
->channode
, &chptr
->members
);
353 if(client_p
->servptr
== &me
)
354 rb_dlinkDelete(&msptr
->locchannode
, &chptr
->locmembers
);
356 if(!(chptr
->mode
.mode
& MODE_PERMANENT
) && rb_dlink_list_length(&chptr
->members
) <= 0)
357 destroy_channel(chptr
);
359 rb_bh_free(member_heap
, msptr
);
364 /* remove_user_from_channels()
366 * input - user to remove from all channels
368 * side effects - user is removed from all channels
371 remove_user_from_channels(struct Client
*client_p
)
373 struct Channel
*chptr
;
374 struct membership
*msptr
;
376 rb_dlink_node
*next_ptr
;
381 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->user
->channel
.head
)
384 chptr
= msptr
->chptr
;
386 rb_dlinkDelete(&msptr
->channode
, &chptr
->members
);
388 if(client_p
->servptr
== &me
)
389 rb_dlinkDelete(&msptr
->locchannode
, &chptr
->locmembers
);
391 if(!(chptr
->mode
.mode
& MODE_PERMANENT
) && rb_dlink_list_length(&chptr
->members
) <= 0)
392 destroy_channel(chptr
);
394 rb_bh_free(member_heap
, msptr
);
397 client_p
->user
->channel
.head
= client_p
->user
->channel
.tail
= NULL
;
398 client_p
->user
->channel
.length
= 0;
401 /* invalidate_bancache_user()
403 * input - user to invalidate ban cache for
405 * side effects - ban cache is invalidated for all memberships of that user
406 * to be used after a nick change
409 invalidate_bancache_user(struct Client
*client_p
)
411 struct membership
*msptr
;
417 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
421 msptr
->flags
&= ~CHFL_BANNED
;
425 /* check_channel_name()
427 * input - channel name
428 * output - 1 if valid channel name, else 0
432 check_channel_name(const char *name
)
434 s_assert(name
!= NULL
);
438 for (; *name
; ++name
)
440 if(!IsChanChar(*name
))
447 /* free_channel_list()
449 * input - rb_dlink list to free
451 * side effects - list of b/e/I modes is cleared
454 free_channel_list(rb_dlink_list
* list
)
457 rb_dlink_node
*next_ptr
;
458 struct Ban
*actualBan
;
460 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
462 actualBan
= ptr
->data
;
466 list
->head
= list
->tail
= NULL
;
472 * input - channel to destroy
474 * side effects - channel is obliterated
477 destroy_channel(struct Channel
*chptr
)
479 rb_dlink_node
*ptr
, *next_ptr
;
481 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
483 del_invite(chptr
, ptr
->data
);
486 /* free all bans/exceptions/denies */
487 free_channel_list(&chptr
->banlist
);
488 free_channel_list(&chptr
->exceptlist
);
489 free_channel_list(&chptr
->invexlist
);
490 free_channel_list(&chptr
->quietlist
);
495 rb_dlinkDelete(&chptr
->node
, &global_channel_list
);
496 del_from_channel_hash(chptr
->chname
, chptr
);
500 /* channel_pub_or_secret()
503 * output - "=" if public, "@" if secret, else "*"
507 channel_pub_or_secret(struct Channel
*chptr
)
509 if(PubChannel(chptr
))
511 else if(SecretChannel(chptr
))
516 /* channel_member_names()
518 * input - channel to list, client to list to, show endofnames
520 * side effects - client is given list of users on channel
523 channel_member_names(struct Channel
*chptr
, struct Client
*client_p
, int show_eon
)
525 struct membership
*msptr
;
526 struct Client
*target_p
;
534 int stack
= IsCapable(client_p
, CLICAP_MULTI_PREFIX
);
536 if(ShowChannel(client_p
, chptr
))
538 is_member
= IsMember(client_p
, chptr
);
540 cur_len
= mlen
= rb_sprintf(lbuf
, form_str(RPL_NAMREPLY
),
541 me
.name
, client_p
->name
,
542 channel_pub_or_secret(chptr
), chptr
->chname
);
546 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
549 target_p
= msptr
->client_p
;
551 if(IsInvisible(target_p
) && !is_member
)
554 /* space, possible "@+" prefix */
555 if(cur_len
+ strlen(target_p
->name
) + 3 >= BUFSIZE
- 3)
558 sendto_one(client_p
, "%s", lbuf
);
563 tlen
= rb_sprintf(t
, "%s%s ", find_channel_status(msptr
, stack
),
570 /* The old behaviour here was to always output our buffer,
571 * even if there are no clients we can show. This happens
572 * when a client does "NAMES" with no parameters, and all
573 * the clients on a -sp channel are +i. I dont see a good
574 * reason for keeping that behaviour, as it just wastes
580 sendto_one(client_p
, "%s", lbuf
);
585 sendto_one(client_p
, form_str(RPL_ENDOFNAMES
),
586 me
.name
, client_p
->name
, chptr
->chname
);
591 * input - channel to remove invite from, client to remove
593 * side effects - user is removed from invite list, if exists
596 del_invite(struct Channel
*chptr
, struct Client
*who
)
598 rb_dlinkFindDestroy(who
, &chptr
->invites
);
599 rb_dlinkFindDestroy(chptr
, &who
->user
->invited
);
604 * input - channel to check bans for, user to check bans against
605 * optional prebuilt buffers
606 * output - 1 if banned, else 0
610 is_banned(struct Channel
*chptr
, struct Client
*who
, struct membership
*msptr
,
611 const char *s
, const char *s2
)
613 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
614 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
615 char src_althost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
618 struct Ban
*actualBan
= NULL
;
619 struct Ban
*actualExcept
= NULL
;
624 /* if the buffers havent been built, do it here */
627 rb_sprintf(src_host
, "%s!%s@%s", who
->name
, who
->username
, who
->host
);
628 rb_sprintf(src_iphost
, "%s!%s@%s", who
->name
, who
->username
, who
->sockhost
);
633 if(who
->localClient
->mangledhost
!= NULL
)
635 /* if host mangling mode enabled, also check their real host */
636 if(!strcmp(who
->host
, who
->localClient
->mangledhost
))
638 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->orighost
);
641 /* if host mangling mode not enabled and no other spoof,
642 * also check the mangled form of their host */
643 else if (!IsDynSpoof(who
))
645 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->localClient
->mangledhost
);
650 RB_DLINK_FOREACH(ptr
, chptr
->banlist
.head
)
652 actualBan
= ptr
->data
;
653 if(match(actualBan
->banstr
, s
) ||
654 match(actualBan
->banstr
, s2
) ||
655 match_cidr(actualBan
->banstr
, s2
) ||
656 match_extban(actualBan
->banstr
, who
, chptr
, CHFL_BAN
) ||
657 (s3
!= NULL
&& match(actualBan
->banstr
, s3
)))
663 if((actualBan
!= NULL
) && ConfigChannel
.use_except
)
665 RB_DLINK_FOREACH(ptr
, chptr
->exceptlist
.head
)
667 actualExcept
= ptr
->data
;
669 /* theyre exempted.. */
670 if(match(actualExcept
->banstr
, s
) ||
671 match(actualExcept
->banstr
, s2
) ||
672 match_cidr(actualExcept
->banstr
, s2
) ||
673 match_extban(actualExcept
->banstr
, who
, chptr
, CHFL_EXCEPTION
) ||
674 (s3
!= NULL
&& match(actualExcept
->banstr
, s3
)))
676 /* cache the fact theyre not banned */
679 msptr
->bants
= chptr
->bants
;
680 msptr
->flags
&= ~CHFL_BANNED
;
683 return CHFL_EXCEPTION
;
688 /* cache the banned/not banned status */
691 msptr
->bants
= chptr
->bants
;
693 if(actualBan
!= NULL
)
695 msptr
->flags
|= CHFL_BANNED
;
700 msptr
->flags
&= ~CHFL_BANNED
;
705 return ((actualBan
? CHFL_BAN
: 0));
710 * input - channel to check bans for, user to check bans against
711 * optional prebuilt buffers
712 * output - 1 if banned, else 0
716 is_quieted(struct Channel
*chptr
, struct Client
*who
, struct membership
*msptr
,
717 const char *s
, const char *s2
)
719 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
720 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
721 char src_althost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
724 struct Ban
*actualBan
= NULL
;
725 struct Ban
*actualExcept
= NULL
;
730 /* if the buffers havent been built, do it here */
733 rb_sprintf(src_host
, "%s!%s@%s", who
->name
, who
->username
, who
->host
);
734 rb_sprintf(src_iphost
, "%s!%s@%s", who
->name
, who
->username
, who
->sockhost
);
739 if(who
->localClient
->mangledhost
!= NULL
)
741 /* if host mangling mode enabled, also check their real host */
742 if(!strcmp(who
->host
, who
->localClient
->mangledhost
))
744 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->orighost
);
747 /* if host mangling mode not enabled and no other spoof,
748 * also check the mangled form of their host */
749 else if (!IsDynSpoof(who
))
751 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->localClient
->mangledhost
);
756 RB_DLINK_FOREACH(ptr
, chptr
->quietlist
.head
)
758 actualBan
= ptr
->data
;
759 if(match(actualBan
->banstr
, s
) ||
760 match(actualBan
->banstr
, s2
) ||
761 match_cidr(actualBan
->banstr
, s2
) ||
762 match_extban(actualBan
->banstr
, who
, chptr
, CHFL_QUIET
) ||
763 (s3
!= NULL
&& match(actualBan
->banstr
, s3
)))
769 if((actualBan
!= NULL
) && ConfigChannel
.use_except
)
771 RB_DLINK_FOREACH(ptr
, chptr
->exceptlist
.head
)
773 actualExcept
= ptr
->data
;
775 /* theyre exempted.. */
776 if(match(actualExcept
->banstr
, s
) ||
777 match(actualExcept
->banstr
, s2
) ||
778 match_cidr(actualExcept
->banstr
, s2
) ||
779 match_extban(actualExcept
->banstr
, who
, chptr
, CHFL_EXCEPTION
) ||
780 (s3
!= NULL
&& match(actualExcept
->banstr
, s3
)))
782 /* cache the fact theyre not banned */
785 msptr
->bants
= chptr
->bants
;
786 msptr
->flags
&= ~CHFL_BANNED
;
789 return CHFL_EXCEPTION
;
794 /* cache the banned/not banned status */
797 msptr
->bants
= chptr
->bants
;
799 if(actualBan
!= NULL
)
801 msptr
->flags
|= CHFL_BANNED
;
806 msptr
->flags
&= ~CHFL_BANNED
;
811 return ((actualBan
? CHFL_BAN
: 0));
816 * input - client to check, channel to check for, key
817 * output - reason for not being able to join, else 0
821 can_join(struct Client
*source_p
, struct Channel
*chptr
, char *key
)
823 rb_dlink_node
*invite
= NULL
;
825 struct Ban
*invex
= NULL
;
826 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
827 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
828 char src_althost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
832 hook_data_channel moduledata
;
834 struct DictionaryIter iter
;
836 s_assert(source_p
->localClient
!= NULL
);
838 rb_sprintf(src_host
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->host
);
839 rb_sprintf(src_iphost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->sockhost
);
840 if(source_p
->localClient
->mangledhost
!= NULL
)
842 /* if host mangling mode enabled, also check their real host */
843 if(!strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
845 rb_sprintf(src_althost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->orighost
);
848 /* if host mangling mode not enabled and no other spoof,
849 * also check the mangled form of their host */
850 else if (!IsDynSpoof(source_p
))
852 rb_sprintf(src_althost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->localClient
->mangledhost
);
857 if((is_banned(chptr
, source_p
, NULL
, src_host
, src_iphost
)) == CHFL_BAN
)
858 return (ERR_BANNEDFROMCHAN
);
860 rb_snprintf(text
, sizeof(text
), "K%s", source_p
->id
);
862 DICTIONARY_FOREACH(md
, &iter
, chptr
->metadata
)
864 if(!strcmp(md
->value
, "KICKNOREJOIN") && !strcmp(md
->name
, text
) && (md
->timevalue
+ 2 > rb_current_time()))
865 return ERR_KICKNOREJOIN
;
866 /* cleanup any stale KICKNOREJOIN metadata we find while we're at it */
867 if(!strcmp(md
->value
, "KICKNOREJOIN") && !(md
->timevalue
+ 2 > rb_current_time()))
868 channel_metadata_delete(chptr
, md
->name
, 0);
871 if(chptr
->mode
.mode
& MODE_INVITEONLY
)
873 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
875 if(invite
->data
== chptr
)
880 if(!ConfigChannel
.use_invex
)
881 return (ERR_INVITEONLYCHAN
);
882 RB_DLINK_FOREACH(ptr
, chptr
->invexlist
.head
)
885 if(match(invex
->banstr
, src_host
)
886 || match(invex
->banstr
, src_iphost
)
887 || match_cidr(invex
->banstr
, src_iphost
)
888 || match_extban(invex
->banstr
, source_p
, chptr
, CHFL_INVEX
)
889 || (use_althost
&& match(invex
->banstr
, src_althost
)))
893 return (ERR_INVITEONLYCHAN
);
897 if(*chptr
->mode
.key
&& (EmptyString(key
) || irccmp(chptr
->mode
.key
, key
)))
898 return (ERR_BADCHANNELKEY
);
900 if(chptr
->mode
.limit
&&
901 rb_dlink_list_length(&chptr
->members
) >= (unsigned long) chptr
->mode
.limit
)
902 i
= ERR_CHANNELISFULL
;
903 if(chptr
->mode
.mode
& MODE_REGONLY
&& EmptyString(source_p
->user
->suser
))
904 i
= ERR_NEEDREGGEDNICK
;
905 /* join throttling stuff --nenolod */
906 else if(chptr
->mode
.join_num
> 0 && chptr
->mode
.join_time
> 0)
908 if ((rb_current_time() - chptr
->join_delta
<=
909 chptr
->mode
.join_time
) && (chptr
->join_count
>=
910 chptr
->mode
.join_num
))
914 /* allow /invite to override +l/+r/+j also -- jilles */
915 if (i
!= 0 && invite
== NULL
)
917 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
919 if(invite
->data
== chptr
)
926 moduledata
.client
= source_p
;
927 moduledata
.chptr
= chptr
;
928 moduledata
.approved
= 0;
930 call_hook(h_can_join
, &moduledata
);
932 return moduledata
.approved
;
937 * input - user to check in channel, membership pointer
938 * output - whether can explicitly send or not, else CAN_SEND_NONOP
942 can_send(struct Channel
*chptr
, struct Client
*source_p
, struct membership
*msptr
)
944 if(IsServer(source_p
) || IsService(source_p
))
947 if(MyClient(source_p
) && hash_find_resv(chptr
->chname
) &&
948 !IsOper(source_p
) && !IsExemptResv(source_p
))
953 msptr
= find_channel_membership(chptr
, source_p
);
957 /* if its +m or +n and theyre not in the channel,
958 * they cant send. we dont check bans here because
959 * theres no possibility of caching them --fl
961 if(chptr
->mode
.mode
& MODE_NOPRIVMSGS
|| chptr
->mode
.mode
& MODE_MODERATED
)
964 return CAN_SEND_NONOP
;
968 if(is_chanop_voiced(msptr
))
971 if(chptr
->mode
.mode
& MODE_MODERATED
)
974 if(MyClient(source_p
))
976 /* cached can_send */
977 if(msptr
->bants
== chptr
->bants
)
979 if(can_send_banned(msptr
))
982 else if(is_banned(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
983 || is_quieted(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
)
987 return CAN_SEND_NONOP
;
991 * flood_attack_channel
992 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
993 * says NOTICE must not auto reply
994 * - pointer to source Client
995 * - pointer to target channel
996 * output - 1 if target is under flood attack
997 * side effects - check for flood attack on target chptr
1000 flood_attack_channel(int p_or_n
, struct Client
*source_p
, struct Channel
*chptr
, char *chname
)
1004 if(GlobalSetOptions
.floodcount
&& MyClient(source_p
) && (!IsOper(source_p
) || !ConfigFileEntry
.true_no_oper_flood
))
1006 if((chptr
->first_received_message_time
+ 1) < rb_current_time())
1008 delta
= rb_current_time() - chptr
->first_received_message_time
;
1009 chptr
->received_number_of_privmsgs
-= delta
;
1010 chptr
->first_received_message_time
= rb_current_time();
1011 if(chptr
->received_number_of_privmsgs
<= 0)
1013 chptr
->received_number_of_privmsgs
= 0;
1014 chptr
->flood_noticed
= 0;
1018 if((chptr
->received_number_of_privmsgs
>= GlobalSetOptions
.floodcount
)
1019 || chptr
->flood_noticed
)
1021 if(chptr
->flood_noticed
== 0)
1023 sendto_realops_snomask(SNO_BOTS
, *chptr
->chname
== '&' ? L_ALL
: L_NETWIDE
,
1024 "Possible Flooder %s[%s@%s] on %s target: %s",
1025 source_p
->name
, source_p
->username
,
1027 source_p
->servptr
->name
, chptr
->chname
);
1028 chptr
->flood_noticed
= 1;
1030 /* Add a bit of penalty */
1031 chptr
->received_number_of_privmsgs
+= 2;
1033 if(MyClient(source_p
) && (p_or_n
!= 1))
1034 sendto_one(source_p
,
1035 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
1036 me
.name
, source_p
->name
, chptr
->chname
);
1040 chptr
->received_number_of_privmsgs
++;
1046 /* find_bannickchange_channel()
1047 * Input: client to check
1048 * Output: channel preventing nick change
1051 find_bannickchange_channel(struct Client
*client_p
)
1053 struct Channel
*chptr
;
1054 struct membership
*msptr
;
1056 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
1057 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
1059 if (!MyClient(client_p
) || IsOverride(client_p
))
1062 rb_sprintf(src_host
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->host
);
1063 rb_sprintf(src_iphost
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->sockhost
);
1065 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1068 chptr
= msptr
->chptr
;
1069 if (is_chanop_voiced(msptr
))
1071 /* cached can_send */
1072 if (msptr
->bants
== chptr
->bants
)
1074 if (can_send_banned(msptr
))
1077 else if (is_banned(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
1078 || is_quieted(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
)
1084 /* find_nonickchange_channel()
1085 * Input: client to check
1086 * Output: channel preventing nick change
1089 find_nonickchange_channel(struct Client
*client_p
)
1091 struct Channel
*chptr
;
1092 struct membership
*msptr
;
1095 if (!MyClient(client_p
))
1098 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1101 chptr
= msptr
->chptr
;
1102 if (chptr
->mode
.mode
& MODE_NONICK
&& (!ConfigChannel
.exempt_cmode_N
|| !is_any_op(msptr
)))
1108 /* void check_spambot_warning(struct Client *source_p)
1109 * Input: Client to check, channel name or NULL if this is a part.
1111 * Side-effects: Updates the client's oper_warn_count_down, warns the
1112 * IRC operators if necessary, and updates join_leave_countdown as
1116 check_spambot_warning(struct Client
*source_p
, const char *name
)
1119 int decrement_count
;
1120 if((GlobalSetOptions
.spam_num
&&
1121 (source_p
->localClient
->join_leave_count
>= GlobalSetOptions
.spam_num
)))
1123 if(source_p
->localClient
->oper_warn_count_down
> 0)
1124 source_p
->localClient
->oper_warn_count_down
--;
1126 source_p
->localClient
->oper_warn_count_down
= 0;
1127 if(source_p
->localClient
->oper_warn_count_down
== 0 &&
1130 /* Its already known as a possible spambot */
1131 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
1132 "User %s (%s@%s) trying to join %s is a possible spambot",
1134 source_p
->username
, source_p
->orighost
, name
);
1135 source_p
->localClient
->oper_warn_count_down
= OPER_SPAM_COUNTDOWN
;
1141 (rb_current_time() - source_p
->localClient
->last_leave_time
)) >
1142 JOIN_LEAVE_COUNT_EXPIRE_TIME
)
1144 decrement_count
= (t_delta
/ JOIN_LEAVE_COUNT_EXPIRE_TIME
);
1147 else if(decrement_count
> source_p
->localClient
->join_leave_count
)
1148 source_p
->localClient
->join_leave_count
= 0;
1150 source_p
->localClient
->join_leave_count
-= decrement_count
;
1154 if((rb_current_time() -
1155 (source_p
->localClient
->last_join_time
)) < GlobalSetOptions
.spam_time
)
1157 /* oh, its a possible spambot */
1158 source_p
->localClient
->join_leave_count
++;
1162 source_p
->localClient
->last_join_time
= rb_current_time();
1164 source_p
->localClient
->last_leave_time
= rb_current_time();
1168 /* check_splitmode()
1172 * side effects - compares usercount and servercount against their split
1173 * values and adjusts splitmode accordingly
1176 check_splitmode(void *unused
)
1178 if(splitchecking
&& (ConfigChannel
.no_join_on_split
|| ConfigChannel
.no_create_on_split
))
1180 /* not split, we're being asked to check now because someone
1185 if(eob_count
< split_servers
|| Count
.total
< split_users
)
1188 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1189 "Network split, activating splitmode");
1190 check_splitmode_ev
= rb_event_addish("check_splitmode", check_splitmode
, NULL
, 2);
1193 /* in splitmode, check whether its finished */
1194 else if(eob_count
>= split_servers
&& Count
.total
>= split_users
)
1198 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1199 "Network rejoined, deactivating splitmode");
1201 rb_event_delete(check_splitmode_ev
);
1202 check_splitmode_ev
= NULL
;
1210 * input - channel to allocate topic for
1211 * output - 1 on success, else 0
1212 * side effects - channel gets a topic allocated
1215 allocate_topic(struct Channel
*chptr
)
1222 ptr
= rb_bh_alloc(topic_heap
);
1224 /* Basically we allocate one large block for the topic and
1225 * the topic info. We then split it up into two and shove it
1229 chptr
->topic_info
= (char *) ptr
+ TOPICLEN
+ 1;
1230 *chptr
->topic
= '\0';
1231 *chptr
->topic_info
= '\0';
1236 * input - channel which has topic to free
1238 * side effects - channels topic is free'd
1241 free_topic(struct Channel
*chptr
)
1245 if(chptr
== NULL
|| chptr
->topic
== NULL
)
1248 /* This is safe for now - If you change allocate_topic you
1249 * MUST change this as well
1252 rb_bh_free(topic_heap
, ptr
);
1253 chptr
->topic
= NULL
;
1254 chptr
->topic_info
= NULL
;
1257 /* set_channel_topic()
1259 * input - channel, topic to set, topic info and topic ts
1261 * side effects - channels topic, topic info and TS are set.
1264 set_channel_topic(struct Channel
*chptr
, const char *topic
, const char *topic_info
, time_t topicts
)
1266 if(strlen(topic
) > 0)
1268 if(chptr
->topic
== NULL
)
1269 allocate_topic(chptr
);
1270 rb_strlcpy(chptr
->topic
, topic
, TOPICLEN
+ 1);
1271 rb_strlcpy(chptr
->topic_info
, topic_info
, USERHOST_REPLYLEN
);
1272 chptr
->topic_time
= topicts
;
1276 if(chptr
->topic
!= NULL
)
1278 chptr
->topic_time
= 0;
1282 /* has_common_channel()
1284 * input - pointer to client
1285 * - pointer to another client
1286 * output - 1 if the two have a channel in common, 0 elsewise
1287 * side effects - none
1290 has_common_channel(struct Client
*client1
, struct Client
*client2
)
1294 RB_DLINK_FOREACH(ptr
, client1
->user
->channel
.head
)
1296 if(IsMember(client2
, ((struct membership
*)ptr
->data
)->chptr
))
1304 * inputs - pointer to channel
1305 * - pointer to client
1306 * output - string with simple modes
1307 * side effects - result from previous calls overwritten
1309 * Stolen from ShadowIRCd 4 --nenolod
1312 channel_modes(struct Channel
*chptr
, struct Client
*client_p
)
1317 static char final
[BUFSIZE
];
1324 for (i
= 0; i
< 256; i
++)
1326 if(chmode_table
[i
].set_func
== chm_hidden
&& !IsOper(client_p
) && IsClient(client_p
))
1328 if(chptr
->mode
.mode
& chmode_flags
[i
])
1332 if(chptr
->mode
.limit
)
1336 if(!IsClient(client_p
) || IsMember(client_p
, chptr
))
1337 pbuf
+= rb_sprintf(pbuf
, " %d", chptr
->mode
.limit
);
1340 if(*chptr
->mode
.key
)
1344 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1345 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.key
);
1348 if(chptr
->mode
.join_num
)
1352 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1353 pbuf
+= rb_sprintf(pbuf
, " %d:%d", chptr
->mode
.join_num
,
1354 chptr
->mode
.join_time
);
1357 if(*chptr
->mode
.forward
&& (ConfigChannel
.use_forward
|| !IsClient(client_p
)))
1361 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1362 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.forward
);
1367 rb_strlcpy(final
, buf1
, sizeof final
);
1368 rb_strlcat(final
, buf2
, sizeof final
);
1372 /* Now lets do some stuff to keep track of what combinations of
1374 * Note that the number of combinations doubles each time you add
1375 * something to this list. Each one is only quick if no servers use that
1376 * combination, but if the numbers get too high here MODE will get too
1377 * slow. I suggest if you get more than 7 here, you consider getting rid
1378 * of some and merging or something. If it wasn't for irc+cs we would
1379 * probably not even need to bother about most of these, but unfortunately
1383 /* void init_chcap_usage_counts(void)
1387 * Side-effects - Initialises the usage counts to zero. Fills in the
1388 * chcap_yes and chcap_no combination tables.
1391 init_chcap_usage_counts(void)
1393 unsigned long m
, c
, y
, n
;
1395 memset(chcap_combos
, 0, sizeof(chcap_combos
));
1397 /* For every possible combination */
1398 for (m
= 0; m
< NCHCAP_COMBOS
; m
++)
1400 /* Check each capab */
1401 for (c
= y
= n
= 0; c
< NCHCAPS
; c
++)
1403 if((m
& (1 << c
)) == 0)
1404 n
|= channel_capabs
[c
];
1406 y
|= channel_capabs
[c
];
1408 chcap_combos
[m
].cap_yes
= y
;
1409 chcap_combos
[m
].cap_no
= n
;
1413 /* void set_chcap_usage_counts(struct Client *serv_p)
1414 * Input: serv_p; The client whose capabs to register.
1416 * Side-effects: Increments the usage counts for the correct capab
1420 set_chcap_usage_counts(struct Client
*serv_p
)
1424 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1426 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1427 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1429 chcap_combos
[n
].count
++;
1434 /* This should be impossible -A1kmm. */
1438 /* void set_chcap_usage_counts(struct Client *serv_p)
1440 * Inputs - serv_p; The client whose capabs to register.
1442 * Side-effects - Decrements the usage counts for the correct capab
1446 unset_chcap_usage_counts(struct Client
*serv_p
)
1450 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1452 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1453 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1455 /* Hopefully capabs can't change dynamically or anything... */
1456 s_assert(chcap_combos
[n
].count
> 0);
1458 if(chcap_combos
[n
].count
> 0)
1459 chcap_combos
[n
].count
--;
1464 /* This should be impossible -A1kmm. */
1468 /* void send_cap_mode_changes(struct Client *client_p,
1469 * struct Client *source_p,
1470 * struct Channel *chptr, int cap, int nocap)
1471 * Input: The client sending(client_p), the source client(source_p),
1472 * the channel to send mode changes for(chptr)
1474 * Side-effects: Sends the appropriate mode changes to capable servers.
1476 * Reverted back to my original design, except that we now keep a count
1477 * of the number of servers which each combination as an optimisation, so
1478 * the capabs combinations which are not needed are not worked out. -A1kmm
1481 send_cap_mode_changes(struct Client
*client_p
, struct Client
*source_p
,
1482 struct Channel
*chptr
, struct ChModeChange mode_changes
[], int mode_count
)
1484 static char modebuf
[BUFSIZE
];
1485 static char parabuf
[BUFSIZE
];
1486 int i
, mbl
, pbl
, nc
, mc
, preflen
, len
;
1495 /* Now send to servers... */
1496 for (j
= 0; j
< NCHCAP_COMBOS
; j
++)
1498 if(chcap_combos
[j
].count
== 0)
1508 cap
= chcap_combos
[j
].cap_yes
;
1509 nocap
= chcap_combos
[j
].cap_no
;
1511 mbl
= preflen
= rb_sprintf(modebuf
, ":%s TMODE %ld %s ",
1512 use_id(source_p
), (long) chptr
->channelts
,
1515 /* loop the list of - modes we have */
1516 for (i
= 0; i
< mode_count
; i
++)
1518 /* if they dont support the cap we need, or they do support a cap they
1519 * cant have, then dont add it to the modebuf.. that way they wont see
1522 if((mode_changes
[i
].letter
== 0) ||
1523 ((cap
& mode_changes
[i
].caps
) != mode_changes
[i
].caps
)
1524 || ((nocap
& mode_changes
[i
].nocaps
) != mode_changes
[i
].nocaps
))
1527 if(!EmptyString(mode_changes
[i
].id
))
1528 arg
= mode_changes
[i
].id
;
1530 arg
= mode_changes
[i
].arg
;
1534 arglen
= strlen(arg
);
1536 /* dont even think about it! --fl */
1537 if(arglen
> MODEBUFLEN
- 5)
1541 /* if we're creeping past the buf size, we need to send it and make
1542 * another line for the other modes
1543 * XXX - this could give away server topology with uids being
1544 * different lengths, but not much we can do, except possibly break
1545 * them as if they were the longest of the nick or uid at all times,
1546 * which even then won't work as we don't always know the uid -A1kmm.
1548 if(arg
&& ((mc
== MAXMODEPARAMSSERV
) ||
1549 ((mbl
+ pbl
+ arglen
+ 4) > (BUFSIZE
- 3))))
1552 sendto_server(client_p
, chptr
, cap
, nocap
,
1553 "%s %s", modebuf
, parabuf
);
1564 if(dir
!= mode_changes
[i
].dir
)
1566 modebuf
[mbl
++] = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1567 dir
= mode_changes
[i
].dir
;
1570 modebuf
[mbl
++] = mode_changes
[i
].letter
;
1576 len
= rb_sprintf(pbuf
, "%s ", arg
);
1583 if(pbl
&& parabuf
[pbl
- 1] == ' ')
1584 parabuf
[pbl
- 1] = 0;
1587 sendto_server(client_p
, chptr
, cap
, nocap
, "%s %s", modebuf
, parabuf
);
1592 resv_chan_forcepart(const char *name
, const char *reason
, int temp_time
)
1595 rb_dlink_node
*next_ptr
;
1596 struct Channel
*chptr
;
1597 struct membership
*msptr
;
1598 struct Client
*target_p
;
1600 if(!ConfigChannel
.resv_forcepart
)
1603 /* for each user on our server in the channel list
1604 * send them a PART, and notify opers.
1606 chptr
= find_channel(name
);
1609 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
1612 target_p
= msptr
->client_p
;
1614 if(IsExemptResv(target_p
))
1617 sendto_server(target_p
, chptr
, CAP_TS6
, NOCAPS
,
1618 ":%s PART %s", target_p
->id
, chptr
->chname
);
1620 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s :%s",
1621 target_p
->name
, target_p
->username
,
1622 target_p
->host
, chptr
->chname
, target_p
->name
);
1624 remove_user_from_channel(msptr
);
1626 /* notify opers & user they were removed from the channel */
1627 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1628 "Forced PART for %s!%s@%s from %s (%s)",
1629 target_p
->name
, target_p
->username
,
1630 target_p
->host
, name
, reason
);
1633 sendto_one_notice(target_p
, ":*** Channel %s is temporarily unavailable on this server.",
1636 sendto_one_notice(target_p
, ":*** Channel %s is no longer available on this server.",
1642 /* Check what we will forward to, without sending any notices to the user
1646 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
1652 if (IsNoForward(source_p
))
1657 chptr
= find_channel(chptr
->mode
.forward
);
1658 /* Can only forward to existing channels */
1661 /* Already on there, show original error message */
1662 if (IsMember(source_p
, chptr
))
1664 /* Juped. Sending a warning notice would be unfair */
1665 if (hash_find_resv(chptr
->chname
))
1667 /* Don't forward to +Q channel */
1668 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
1670 i
= can_join(source_p
, chptr
, key
);
1673 if (i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_CHANNELISFULL
)
1684 * inputs - pointer to client doing join 0
1686 * side effects - Use has decided to join 0. This is legacy
1687 * from the days when channels were numbers not names. *sigh*
1690 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
1692 struct membership
*msptr
;
1693 struct Channel
*chptr
= NULL
;
1696 /* Finish the flood grace period... */
1697 if(MyClient(source_p
) && !IsFloodDone(source_p
))
1698 flood_endgrace(source_p
);
1700 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
1702 while((ptr
= source_p
->user
->channel
.head
))
1704 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
1705 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1706 check_spambot_warning(source_p
, NULL
);
1709 chptr
= msptr
->chptr
;
1710 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
1712 source_p
->username
, source_p
->host
, chptr
->chname
);
1713 remove_user_from_channel(msptr
);
1718 check_channel_name_loc(struct Client
*source_p
, const char *name
)
1722 s_assert(name
!= NULL
);
1723 if(EmptyString(name
))
1726 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1728 for(p
= name
; *p
; ++p
)
1730 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
1736 for(p
= name
; *p
; ++p
)
1743 if(ConfigChannel
.only_ascii_channels
)
1745 for(p
= name
; *p
; ++p
)
1746 if(*p
< 33 || *p
> 126)
1754 void user_join(struct Client
* client_p
, struct Client
* source_p
, const char * channels
, const char * keys
)
1756 static char jbuf
[BUFSIZE
];
1757 struct Channel
*chptr
= NULL
;
1758 struct ConfItem
*aconf
;
1763 char *p
= NULL
, *p2
= NULL
;
1769 if(channels
== NULL
)
1772 /* rebuild the list of channels theyre supposed to be joining.
1773 * this code has a side effect of losing keys, but..
1775 chanlist
= LOCAL_COPY(channels
);
1776 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
1778 /* check the length and name of channel is ok */
1779 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
1781 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1782 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
1786 /* join 0 parts all channels */
1787 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
1789 (void) strcpy(jbuf
, "0");
1793 /* check it begins with # or &, and local chans are disabled */
1794 else if(!IsChannelName(name
) ||
1795 ( !ConfigChannel
.use_local_channels
&& name
[0] == '&'))
1797 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
1798 form_str(ERR_NOSUCHCHANNEL
), name
);
1802 /* see if its resv'd */
1803 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
1805 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1806 form_str(ERR_BADCHANNAME
), name
);
1808 /* dont warn for opers */
1809 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
1810 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
1811 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
1812 source_p
->name
, source_p
->username
,
1813 source_p
->orighost
, name
, aconf
->passwd
);
1814 /* dont update tracking for jupe exempt users, these
1815 * are likely to be spamtrap leaves
1817 else if(IsExemptJupe(source_p
))
1823 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1824 ConfigChannel
.no_join_on_split
)
1826 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1827 me
.name
, source_p
->name
, name
);
1832 (void) strcat(jbuf
, ",");
1833 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
1838 mykey
= LOCAL_COPY(keys
);
1839 key
= rb_strtok_r(mykey
, ",", &p2
);
1842 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
1843 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
1845 hook_data_channel_activity hook_info
;
1847 /* JOIN 0 simply parts all channels the user is in */
1848 if(*name
== '0' && !atoi(name
))
1850 if(source_p
->user
->channel
.head
== NULL
)
1853 do_join_0(&me
, source_p
);
1857 /* look for the channel */
1858 if((chptr
= find_channel(name
)) != NULL
)
1860 if(IsMember(source_p
, chptr
))
1867 hook_data_client_approval moduledata
;
1869 moduledata
.client
= source_p
;
1870 moduledata
.approved
= 0;
1872 call_hook(h_can_create_channel
, &moduledata
);
1874 if(moduledata
.approved
!= 0)
1876 sendto_one(source_p
, form_str(moduledata
.approved
),
1877 me
.name
, source_p
->name
, name
);
1881 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1882 ConfigChannel
.no_create_on_split
)
1884 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1885 me
.name
, source_p
->name
, name
);
1889 if(ConfigChannel
.admin_on_channel_create
&& ConfigChannel
.use_admin
)
1890 flags
= CHFL_ADMIN
| CHFL_CHANOP
;
1892 flags
= CHFL_CHANOP
;
1895 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
1896 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
1897 (!IsOper(source_p
) ||
1898 (rb_dlink_list_length(&source_p
->user
->channel
) >=
1899 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
1901 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
1902 me
.name
, source_p
->name
, name
);
1906 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
1908 chptr
= get_or_create_channel(source_p
, name
, NULL
);
1912 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1913 me
.name
, source_p
->name
, name
);
1918 /* can_join checks for +i key, bans etc */
1919 if((i
= can_join(source_p
, chptr
, key
)))
1921 if(IsOverride(source_p
))
1923 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1924 "%s is overriding JOIN to [%s]",
1925 get_oper_name(source_p
), chptr
->chname
);
1926 sendto_server(NULL
, chptr
, NOCAPS
, NOCAPS
,
1927 ":%s WALLOPS :%s is overriding JOIN to [%s]",
1928 me
.name
, get_oper_name(source_p
), chptr
->chname
);
1930 else if ((i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_CHANNELISFULL
) ||
1931 (!ConfigChannel
.use_forward
|| (chptr
= check_forward(source_p
, chptr
, key
)) == NULL
))
1933 /* might be wrong, but is there any other better location for such?
1934 * see extensions/chm_operonly.c for other comments on this
1938 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
1943 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr
->chname
);
1947 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1948 check_spambot_warning(source_p
, name
);
1950 /* add the user to the channel */
1951 add_user_to_channel(chptr
, source_p
, flags
);
1952 if (chptr
->mode
.join_num
&&
1953 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
1955 chptr
->join_count
= 0;
1956 chptr
->join_delta
= rb_current_time();
1958 chptr
->join_count
++;
1960 /* we send the user their join here, because we could have to
1961 * send a mode out next.
1963 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1965 source_p
->username
, source_p
->host
, chptr
->chname
);
1967 /* its a new channel, set +nt and burst. */
1968 if(flags
& CHFL_CHANOP
)
1970 chptr
->channelts
= rb_current_time();
1972 /* autochanmodes stuff */
1973 if(ConfigChannel
.autochanmodes
)
1976 for(ch
= ConfigChannel
.autochanmodes
; *ch
; *ch
++)
1978 chptr
->mode
.mode
|= chmode_table
[*ch
].mode_type
;
1983 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
1984 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
1987 modes
= channel_modes(chptr
, &me
);
1989 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
1990 me
.name
, chptr
->chname
, modes
);
1992 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
1993 ":%s SJOIN %ld %s %s :@%s",
1994 me
.id
, (long) chptr
->channelts
,
1995 chptr
->chname
, modes
, source_p
->id
);
1999 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
2000 ":%s JOIN %ld %s +",
2001 use_id(source_p
), (long) chptr
->channelts
,
2005 del_invite(chptr
, source_p
);
2007 if(chptr
->topic
!= NULL
)
2009 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
2010 source_p
->name
, chptr
->chname
, chptr
->topic
);
2012 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
2013 me
.name
, source_p
->name
, chptr
->chname
,
2014 chptr
->topic_info
, chptr
->topic_time
);
2017 channel_member_names(chptr
, source_p
, 1);
2019 hook_info
.client
= source_p
;
2020 hook_info
.chptr
= chptr
;
2021 hook_info
.key
= key
;
2022 call_hook(h_channel_join
, &hook_info
);
2029 * channel_metadata_add
2031 * inputs - pointer to channel struct
2032 * - name of metadata item you wish to add
2033 * - value of metadata item
2034 * - 1 if metadata should be propegated, 0 if not
2036 * side effects - metadata is added to the channel in question
2037 * - metadata is propegated if propegate is set.
2040 channel_metadata_add(struct Channel
*target
, const char *name
, const char *value
, int propegate
)
2042 struct Metadata
*md
;
2044 md
= rb_malloc(sizeof(struct Metadata
));
2045 md
->name
= rb_strdup(name
);
2046 md
->value
= rb_strdup(value
);
2048 irc_dictionary_add(target
->metadata
, md
->name
, md
);
2051 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA ADD %s %s :%s",
2052 target
->chname
, name
, value
);
2058 * channel_metadata_time_add
2060 * inputs - pointer to channel struct
2061 * - name of metadata item you wish to add
2062 * - time_t you wish to add
2063 * - value you wish to add
2065 * side effects - metadata is added to the channel in question
2068 channel_metadata_time_add(struct Channel
*target
, const char *name
, time_t timevalue
, const char *value
)
2070 struct Metadata
*md
;
2072 md
= rb_malloc(sizeof(struct Metadata
));
2073 md
->name
= rb_strdup(name
);
2074 md
->value
= rb_strdup(value
);
2075 md
->timevalue
= timevalue
;
2077 irc_dictionary_add(target
->metadata
, md
->name
, md
);
2083 * channel_metadata_delete
2085 * inputs - pointer to channel struct
2086 * - name of metadata item you wish to delete
2088 * side effects - metadata is deleted from the channel in question
2089 * - deletion is propegated if propegate is set
2092 channel_metadata_delete(struct Channel
*target
, const char *name
, int propegate
)
2094 struct Metadata
*md
= channel_metadata_find(target
, name
);
2099 irc_dictionary_delete(target
->metadata
, md
->name
);
2104 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA DELETE %s %s",
2105 target
->chname
, name
);
2109 * channel_metadata_find
2111 * inputs - pointer to channel struct
2112 * - name of metadata item you wish to read
2113 * output - the requested metadata, if it exists, elsewise null.
2117 channel_metadata_find(struct Channel
*target
, const char *name
)
2122 if(!target
->metadata
)
2125 return irc_dictionary_retrieve(target
->metadata
, name
);
2129 * channel_metadata_clear
2131 * inputs - pointer to channel struct
2133 * side effects - metadata is cleared from the channel in question
2136 channel_metadata_clear(struct Channel
*chptr
)
2138 struct Metadata
*md
;
2139 struct DictionaryIter iter
;
2141 DICTIONARY_FOREACH(md
, &iter
, chptr
->metadata
)
2143 channel_metadata_delete(chptr
, md
->name
, 0);