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_bh_free(channel_heap
, chptr
);
113 allocate_ban(const char *banstr
, const char *who
)
116 bptr
= rb_bh_alloc(ban_heap
);
117 bptr
->banstr
= rb_strdup(banstr
);
118 bptr
->who
= rb_strdup(who
);
124 free_ban(struct Ban
*bptr
)
126 rb_free(bptr
->banstr
);
128 rb_bh_free(ban_heap
, bptr
);
132 /* find_channel_membership()
134 * input - channel to find them in, client to find
135 * output - membership of client in channel, else NULL
139 find_channel_membership(struct Channel
*chptr
, struct Client
*client_p
)
141 struct membership
*msptr
;
144 if(!IsClient(client_p
))
147 /* Pick the most efficient list to use to be nice to things like
148 * CHANSERV which could be in a large number of channels
150 if(rb_dlink_list_length(&chptr
->members
) < rb_dlink_list_length(&client_p
->user
->channel
))
152 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
156 if(msptr
->client_p
== client_p
)
162 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
166 if(msptr
->chptr
== chptr
)
174 /* find_channel_status()
176 * input - membership to get status for, whether we can combine flags
177 * output - flags of user on channel
181 find_channel_status(struct membership
*msptr
, int combine
)
183 static char buffer
[5];
218 * input - membership to check for halfops
219 * output - 1 if the user is halfopped, 0 if the user is not or halfop
225 is_halfop(struct membership
*msptr
)
227 if(!ConfigChannel
.use_halfop
)
229 if(is_chmode_h(msptr
))
237 * input - membership to check for admin
238 * output - 1 if the user is an admin, 0 if the user is not or admin
244 is_admin(struct membership
*msptr
)
246 if(!ConfigChannel
.use_admin
)
248 if(is_chmode_a(msptr
))
256 * input - membership to check for ops
257 * output - 1 if the user is op, halfop, or admin, 0 elsewise
261 is_any_op(struct membership
*msptr
)
263 if(is_chanop(msptr
) || is_halfop(msptr
) || is_admin(msptr
))
269 /* is_chanop_voiced()
271 * input - memebership to check for status
272 * output - 1 if the user is op, halfop, admin, or voice, 0 elsewise
276 is_chanop_voiced(struct membership
*msptr
)
278 if(is_chanop(msptr
) || is_voiced(msptr
) || is_halfop(msptr
) || is_admin(msptr
))
286 * input - two memeberships
287 * output - 1 if the first memebership can kick/deop the second, 0 elsewise
291 can_kick_deop(struct membership
*source
, struct membership
*target
)
293 if(is_chanop(source
) && !is_admin(target
))
295 else if(is_halfop(source
) && !is_any_op(target
))
297 else if(is_admin(source
))
303 /* add_user_to_channel()
305 * input - channel to add client to, client to add, channel flags
307 * side effects - user is added to channel
310 add_user_to_channel(struct Channel
*chptr
, struct Client
*client_p
, int flags
)
312 struct membership
*msptr
;
314 s_assert(client_p
->user
!= NULL
);
315 if(client_p
->user
== NULL
)
318 msptr
= rb_bh_alloc(member_heap
);
320 msptr
->chptr
= chptr
;
321 msptr
->client_p
= client_p
;
322 msptr
->flags
= flags
;
324 rb_dlinkAdd(msptr
, &msptr
->usernode
, &client_p
->user
->channel
);
325 rb_dlinkAdd(msptr
, &msptr
->channode
, &chptr
->members
);
327 if(MyClient(client_p
))
328 rb_dlinkAdd(msptr
, &msptr
->locchannode
, &chptr
->locmembers
);
331 /* remove_user_from_channel()
333 * input - membership pointer to remove from channel
335 * side effects - membership (thus user) is removed from channel
338 remove_user_from_channel(struct membership
*msptr
)
340 struct Client
*client_p
;
341 struct Channel
*chptr
;
342 s_assert(msptr
!= NULL
);
346 client_p
= msptr
->client_p
;
347 chptr
= msptr
->chptr
;
349 rb_dlinkDelete(&msptr
->usernode
, &client_p
->user
->channel
);
350 rb_dlinkDelete(&msptr
->channode
, &chptr
->members
);
352 if(client_p
->servptr
== &me
)
353 rb_dlinkDelete(&msptr
->locchannode
, &chptr
->locmembers
);
355 if(!(chptr
->mode
.mode
& MODE_PERMANENT
) && rb_dlink_list_length(&chptr
->members
) <= 0)
356 destroy_channel(chptr
);
358 rb_bh_free(member_heap
, msptr
);
363 /* remove_user_from_channels()
365 * input - user to remove from all channels
367 * side effects - user is removed from all channels
370 remove_user_from_channels(struct Client
*client_p
)
372 struct Channel
*chptr
;
373 struct membership
*msptr
;
375 rb_dlink_node
*next_ptr
;
380 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->user
->channel
.head
)
383 chptr
= msptr
->chptr
;
385 rb_dlinkDelete(&msptr
->channode
, &chptr
->members
);
387 if(client_p
->servptr
== &me
)
388 rb_dlinkDelete(&msptr
->locchannode
, &chptr
->locmembers
);
390 if(!(chptr
->mode
.mode
& MODE_PERMANENT
) && rb_dlink_list_length(&chptr
->members
) <= 0)
391 destroy_channel(chptr
);
393 rb_bh_free(member_heap
, msptr
);
396 client_p
->user
->channel
.head
= client_p
->user
->channel
.tail
= NULL
;
397 client_p
->user
->channel
.length
= 0;
400 /* invalidate_bancache_user()
402 * input - user to invalidate ban cache for
404 * side effects - ban cache is invalidated for all memberships of that user
405 * to be used after a nick change
408 invalidate_bancache_user(struct Client
*client_p
)
410 struct membership
*msptr
;
416 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
420 msptr
->flags
&= ~CHFL_BANNED
;
424 /* check_channel_name()
426 * input - channel name
427 * output - 1 if valid channel name, else 0
431 check_channel_name(const char *name
)
433 s_assert(name
!= NULL
);
437 for (; *name
; ++name
)
439 if(!IsChanChar(*name
))
446 /* free_channel_list()
448 * input - rb_dlink list to free
450 * side effects - list of b/e/I modes is cleared
453 free_channel_list(rb_dlink_list
* list
)
456 rb_dlink_node
*next_ptr
;
457 struct Ban
*actualBan
;
459 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
461 actualBan
= ptr
->data
;
465 list
->head
= list
->tail
= NULL
;
471 * input - channel to destroy
473 * side effects - channel is obliterated
476 destroy_channel(struct Channel
*chptr
)
478 rb_dlink_node
*ptr
, *next_ptr
;
480 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
482 del_invite(chptr
, ptr
->data
);
485 /* free all bans/exceptions/denies */
486 free_channel_list(&chptr
->banlist
);
487 free_channel_list(&chptr
->exceptlist
);
488 free_channel_list(&chptr
->invexlist
);
489 free_channel_list(&chptr
->quietlist
);
494 rb_dlinkDelete(&chptr
->node
, &global_channel_list
);
495 del_from_channel_hash(chptr
->chname
, chptr
);
499 /* channel_pub_or_secret()
502 * output - "=" if public, "@" if secret, else "*"
506 channel_pub_or_secret(struct Channel
*chptr
)
508 if(PubChannel(chptr
))
510 else if(SecretChannel(chptr
))
515 /* channel_member_names()
517 * input - channel to list, client to list to, show endofnames
519 * side effects - client is given list of users on channel
522 channel_member_names(struct Channel
*chptr
, struct Client
*client_p
, int show_eon
)
524 struct membership
*msptr
;
525 struct Client
*target_p
;
533 int stack
= IsCapable(client_p
, CLICAP_MULTI_PREFIX
);
535 if(ShowChannel(client_p
, chptr
))
537 is_member
= IsMember(client_p
, chptr
);
539 cur_len
= mlen
= rb_sprintf(lbuf
, form_str(RPL_NAMREPLY
),
540 me
.name
, client_p
->name
,
541 channel_pub_or_secret(chptr
), chptr
->chname
);
545 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
548 target_p
= msptr
->client_p
;
550 if(IsInvisible(target_p
) && !is_member
)
553 /* space, possible "@+" prefix */
554 if(cur_len
+ strlen(target_p
->name
) + 3 >= BUFSIZE
- 3)
557 sendto_one(client_p
, "%s", lbuf
);
562 tlen
= rb_sprintf(t
, "%s%s ", find_channel_status(msptr
, stack
),
569 /* The old behaviour here was to always output our buffer,
570 * even if there are no clients we can show. This happens
571 * when a client does "NAMES" with no parameters, and all
572 * the clients on a -sp channel are +i. I dont see a good
573 * reason for keeping that behaviour, as it just wastes
579 sendto_one(client_p
, "%s", lbuf
);
584 sendto_one(client_p
, form_str(RPL_ENDOFNAMES
),
585 me
.name
, client_p
->name
, chptr
->chname
);
590 * input - channel to remove invite from, client to remove
592 * side effects - user is removed from invite list, if exists
595 del_invite(struct Channel
*chptr
, struct Client
*who
)
597 rb_dlinkFindDestroy(who
, &chptr
->invites
);
598 rb_dlinkFindDestroy(chptr
, &who
->user
->invited
);
603 * input - channel to check bans for, user to check bans against
604 * optional prebuilt buffers
605 * output - 1 if banned, else 0
609 is_banned(struct Channel
*chptr
, struct Client
*who
, struct membership
*msptr
,
610 const char *s
, const char *s2
)
612 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
613 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
614 char src_althost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
617 struct Ban
*actualBan
= NULL
;
618 struct Ban
*actualExcept
= NULL
;
623 /* if the buffers havent been built, do it here */
626 rb_sprintf(src_host
, "%s!%s@%s", who
->name
, who
->username
, who
->host
);
627 rb_sprintf(src_iphost
, "%s!%s@%s", who
->name
, who
->username
, who
->sockhost
);
632 if(who
->localClient
->mangledhost
!= NULL
)
634 /* if host mangling mode enabled, also check their real host */
635 if(!strcmp(who
->host
, who
->localClient
->mangledhost
))
637 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->orighost
);
640 /* if host mangling mode not enabled and no other spoof,
641 * also check the mangled form of their host */
642 else if (!IsDynSpoof(who
))
644 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->localClient
->mangledhost
);
649 RB_DLINK_FOREACH(ptr
, chptr
->banlist
.head
)
651 actualBan
= ptr
->data
;
652 if(match(actualBan
->banstr
, s
) ||
653 match(actualBan
->banstr
, s2
) ||
654 match_cidr(actualBan
->banstr
, s2
) ||
655 match_extban(actualBan
->banstr
, who
, chptr
, CHFL_BAN
) ||
656 (s3
!= NULL
&& match(actualBan
->banstr
, s3
)))
662 if((actualBan
!= NULL
) && ConfigChannel
.use_except
)
664 RB_DLINK_FOREACH(ptr
, chptr
->exceptlist
.head
)
666 actualExcept
= ptr
->data
;
668 /* theyre exempted.. */
669 if(match(actualExcept
->banstr
, s
) ||
670 match(actualExcept
->banstr
, s2
) ||
671 match_cidr(actualExcept
->banstr
, s2
) ||
672 match_extban(actualExcept
->banstr
, who
, chptr
, CHFL_EXCEPTION
) ||
673 (s3
!= NULL
&& match(actualExcept
->banstr
, s3
)))
675 /* cache the fact theyre not banned */
678 msptr
->bants
= chptr
->bants
;
679 msptr
->flags
&= ~CHFL_BANNED
;
682 return CHFL_EXCEPTION
;
687 /* cache the banned/not banned status */
690 msptr
->bants
= chptr
->bants
;
692 if(actualBan
!= NULL
)
694 msptr
->flags
|= CHFL_BANNED
;
699 msptr
->flags
&= ~CHFL_BANNED
;
704 return ((actualBan
? CHFL_BAN
: 0));
709 * input - channel to check bans for, user to check bans against
710 * optional prebuilt buffers
711 * output - 1 if banned, else 0
715 is_quieted(struct Channel
*chptr
, struct Client
*who
, struct membership
*msptr
,
716 const char *s
, const char *s2
)
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 struct Ban
*actualBan
= NULL
;
724 struct Ban
*actualExcept
= NULL
;
729 /* if the buffers havent been built, do it here */
732 rb_sprintf(src_host
, "%s!%s@%s", who
->name
, who
->username
, who
->host
);
733 rb_sprintf(src_iphost
, "%s!%s@%s", who
->name
, who
->username
, who
->sockhost
);
738 if(who
->localClient
->mangledhost
!= NULL
)
740 /* if host mangling mode enabled, also check their real host */
741 if(!strcmp(who
->host
, who
->localClient
->mangledhost
))
743 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->orighost
);
746 /* if host mangling mode not enabled and no other spoof,
747 * also check the mangled form of their host */
748 else if (!IsDynSpoof(who
))
750 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->localClient
->mangledhost
);
755 RB_DLINK_FOREACH(ptr
, chptr
->quietlist
.head
)
757 actualBan
= ptr
->data
;
758 if(match(actualBan
->banstr
, s
) ||
759 match(actualBan
->banstr
, s2
) ||
760 match_cidr(actualBan
->banstr
, s2
) ||
761 match_extban(actualBan
->banstr
, who
, chptr
, CHFL_QUIET
) ||
762 (s3
!= NULL
&& match(actualBan
->banstr
, s3
)))
768 if((actualBan
!= NULL
) && ConfigChannel
.use_except
)
770 RB_DLINK_FOREACH(ptr
, chptr
->exceptlist
.head
)
772 actualExcept
= ptr
->data
;
774 /* theyre exempted.. */
775 if(match(actualExcept
->banstr
, s
) ||
776 match(actualExcept
->banstr
, s2
) ||
777 match_cidr(actualExcept
->banstr
, s2
) ||
778 match_extban(actualExcept
->banstr
, who
, chptr
, CHFL_EXCEPTION
) ||
779 (s3
!= NULL
&& match(actualExcept
->banstr
, s3
)))
781 /* cache the fact theyre not banned */
784 msptr
->bants
= chptr
->bants
;
785 msptr
->flags
&= ~CHFL_BANNED
;
788 return CHFL_EXCEPTION
;
793 /* cache the banned/not banned status */
796 msptr
->bants
= chptr
->bants
;
798 if(actualBan
!= NULL
)
800 msptr
->flags
|= CHFL_BANNED
;
805 msptr
->flags
&= ~CHFL_BANNED
;
810 return ((actualBan
? CHFL_BAN
: 0));
815 * input - client to check, channel to check for, key
816 * output - reason for not being able to join, else 0
820 can_join(struct Client
*source_p
, struct Channel
*chptr
, char *key
)
822 rb_dlink_node
*invite
= NULL
;
824 struct Ban
*invex
= NULL
;
825 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
826 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
827 char src_althost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
831 hook_data_channel moduledata
;
833 struct DictionaryIter iter
;
835 s_assert(source_p
->localClient
!= NULL
);
837 rb_sprintf(src_host
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->host
);
838 rb_sprintf(src_iphost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->sockhost
);
839 if(source_p
->localClient
->mangledhost
!= NULL
)
841 /* if host mangling mode enabled, also check their real host */
842 if(!strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
844 rb_sprintf(src_althost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->orighost
);
847 /* if host mangling mode not enabled and no other spoof,
848 * also check the mangled form of their host */
849 else if (!IsDynSpoof(source_p
))
851 rb_sprintf(src_althost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->localClient
->mangledhost
);
856 if((is_banned(chptr
, source_p
, NULL
, src_host
, src_iphost
)) == CHFL_BAN
)
857 return (ERR_BANNEDFROMCHAN
);
859 rb_snprintf(text
, sizeof(text
), "K%s", source_p
->id
);
861 DICTIONARY_FOREACH(md
, &iter
, chptr
->metadata
)
863 if(!strcmp(md
->value
, "KICKNOREJOIN") && !strcmp(md
->name
, text
) && (md
->timevalue
+ 2 > rb_current_time()))
864 return ERR_KICKNOREJOIN
;
865 /* cleanup any stale KICKNOREJOIN metadata we find while we're at it */
866 if(!strcmp(md
->value
, "KICKNOREJOIN") && !(md
->timevalue
+ 2 > rb_current_time()))
867 channel_metadata_delete(chptr
, md
->name
, 0);
870 if(chptr
->mode
.mode
& MODE_INVITEONLY
)
872 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
874 if(invite
->data
== chptr
)
879 if(!ConfigChannel
.use_invex
)
880 return (ERR_INVITEONLYCHAN
);
881 RB_DLINK_FOREACH(ptr
, chptr
->invexlist
.head
)
884 if(match(invex
->banstr
, src_host
)
885 || match(invex
->banstr
, src_iphost
)
886 || match_cidr(invex
->banstr
, src_iphost
)
887 || match_extban(invex
->banstr
, source_p
, chptr
, CHFL_INVEX
)
888 || (use_althost
&& match(invex
->banstr
, src_althost
)))
892 return (ERR_INVITEONLYCHAN
);
896 if(*chptr
->mode
.key
&& (EmptyString(key
) || irccmp(chptr
->mode
.key
, key
)))
897 return (ERR_BADCHANNELKEY
);
899 if(chptr
->mode
.limit
&&
900 rb_dlink_list_length(&chptr
->members
) >= (unsigned long) chptr
->mode
.limit
)
901 i
= ERR_CHANNELISFULL
;
902 if(chptr
->mode
.mode
& MODE_REGONLY
&& EmptyString(source_p
->user
->suser
))
903 i
= ERR_NEEDREGGEDNICK
;
904 /* join throttling stuff --nenolod */
905 else if(chptr
->mode
.join_num
> 0 && chptr
->mode
.join_time
> 0)
907 if ((rb_current_time() - chptr
->join_delta
<=
908 chptr
->mode
.join_time
) && (chptr
->join_count
>=
909 chptr
->mode
.join_num
))
913 /* allow /invite to override +l/+r/+j also -- jilles */
914 if (i
!= 0 && invite
== NULL
)
916 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
918 if(invite
->data
== chptr
)
925 moduledata
.client
= source_p
;
926 moduledata
.chptr
= chptr
;
927 moduledata
.approved
= 0;
929 call_hook(h_can_join
, &moduledata
);
931 return moduledata
.approved
;
936 * input - user to check in channel, membership pointer
937 * output - whether can explicitly send or not, else CAN_SEND_NONOP
941 can_send(struct Channel
*chptr
, struct Client
*source_p
, struct membership
*msptr
)
943 if(IsServer(source_p
) || IsService(source_p
))
946 if(MyClient(source_p
) && hash_find_resv(chptr
->chname
) &&
947 !IsOper(source_p
) && !IsExemptResv(source_p
))
952 msptr
= find_channel_membership(chptr
, source_p
);
956 /* if its +m or +n and theyre not in the channel,
957 * they cant send. we dont check bans here because
958 * theres no possibility of caching them --fl
960 if(chptr
->mode
.mode
& MODE_NOPRIVMSGS
|| chptr
->mode
.mode
& MODE_MODERATED
)
963 return CAN_SEND_NONOP
;
967 if(is_chanop_voiced(msptr
))
970 if(chptr
->mode
.mode
& MODE_MODERATED
)
973 if(MyClient(source_p
))
975 /* cached can_send */
976 if(msptr
->bants
== chptr
->bants
)
978 if(can_send_banned(msptr
))
981 else if(is_banned(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
982 || is_quieted(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
)
986 return CAN_SEND_NONOP
;
989 /* find_bannickchange_channel()
990 * Input: client to check
991 * Output: channel preventing nick change
994 find_bannickchange_channel(struct Client
*client_p
)
996 struct Channel
*chptr
;
997 struct membership
*msptr
;
999 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
1000 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
1002 if (!MyClient(client_p
) || IsOverride(client_p
))
1005 rb_sprintf(src_host
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->host
);
1006 rb_sprintf(src_iphost
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->sockhost
);
1008 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1011 chptr
= msptr
->chptr
;
1012 if (is_chanop_voiced(msptr
))
1014 /* cached can_send */
1015 if (msptr
->bants
== chptr
->bants
)
1017 if (can_send_banned(msptr
))
1020 else if (is_banned(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
1021 || is_quieted(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
)
1027 /* find_nonickchange_channel()
1028 * Input: client to check
1029 * Output: channel preventing nick change
1032 find_nonickchange_channel(struct Client
*client_p
)
1034 struct Channel
*chptr
;
1035 struct membership
*msptr
;
1038 if (!MyClient(client_p
))
1041 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1044 chptr
= msptr
->chptr
;
1045 if (chptr
->mode
.mode
& MODE_NONICK
&& (!ConfigChannel
.exempt_cmode_N
|| !is_any_op(msptr
)))
1051 /* void check_spambot_warning(struct Client *source_p)
1052 * Input: Client to check, channel name or NULL if this is a part.
1054 * Side-effects: Updates the client's oper_warn_count_down, warns the
1055 * IRC operators if necessary, and updates join_leave_countdown as
1059 check_spambot_warning(struct Client
*source_p
, const char *name
)
1062 int decrement_count
;
1063 if((GlobalSetOptions
.spam_num
&&
1064 (source_p
->localClient
->join_leave_count
>= GlobalSetOptions
.spam_num
)))
1066 if(source_p
->localClient
->oper_warn_count_down
> 0)
1067 source_p
->localClient
->oper_warn_count_down
--;
1069 source_p
->localClient
->oper_warn_count_down
= 0;
1070 if(source_p
->localClient
->oper_warn_count_down
== 0 &&
1073 /* Its already known as a possible spambot */
1074 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
1075 "User %s (%s@%s) trying to join %s is a possible spambot",
1077 source_p
->username
, source_p
->orighost
, name
);
1078 source_p
->localClient
->oper_warn_count_down
= OPER_SPAM_COUNTDOWN
;
1084 (rb_current_time() - source_p
->localClient
->last_leave_time
)) >
1085 JOIN_LEAVE_COUNT_EXPIRE_TIME
)
1087 decrement_count
= (t_delta
/ JOIN_LEAVE_COUNT_EXPIRE_TIME
);
1090 else if(decrement_count
> source_p
->localClient
->join_leave_count
)
1091 source_p
->localClient
->join_leave_count
= 0;
1093 source_p
->localClient
->join_leave_count
-= decrement_count
;
1097 if((rb_current_time() -
1098 (source_p
->localClient
->last_join_time
)) < GlobalSetOptions
.spam_time
)
1100 /* oh, its a possible spambot */
1101 source_p
->localClient
->join_leave_count
++;
1105 source_p
->localClient
->last_join_time
= rb_current_time();
1107 source_p
->localClient
->last_leave_time
= rb_current_time();
1111 /* check_splitmode()
1115 * side effects - compares usercount and servercount against their split
1116 * values and adjusts splitmode accordingly
1119 check_splitmode(void *unused
)
1121 if(splitchecking
&& (ConfigChannel
.no_join_on_split
|| ConfigChannel
.no_create_on_split
))
1123 /* not split, we're being asked to check now because someone
1128 if(eob_count
< split_servers
|| Count
.total
< split_users
)
1131 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1132 "Network split, activating splitmode");
1133 check_splitmode_ev
= rb_event_addish("check_splitmode", check_splitmode
, NULL
, 2);
1136 /* in splitmode, check whether its finished */
1137 else if(eob_count
>= split_servers
&& Count
.total
>= split_users
)
1141 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1142 "Network rejoined, deactivating splitmode");
1144 rb_event_delete(check_splitmode_ev
);
1145 check_splitmode_ev
= NULL
;
1153 * input - channel to allocate topic for
1154 * output - 1 on success, else 0
1155 * side effects - channel gets a topic allocated
1158 allocate_topic(struct Channel
*chptr
)
1165 ptr
= rb_bh_alloc(topic_heap
);
1167 /* Basically we allocate one large block for the topic and
1168 * the topic info. We then split it up into two and shove it
1172 chptr
->topic_info
= (char *) ptr
+ TOPICLEN
+ 1;
1173 *chptr
->topic
= '\0';
1174 *chptr
->topic_info
= '\0';
1179 * input - channel which has topic to free
1181 * side effects - channels topic is free'd
1184 free_topic(struct Channel
*chptr
)
1188 if(chptr
== NULL
|| chptr
->topic
== NULL
)
1191 /* This is safe for now - If you change allocate_topic you
1192 * MUST change this as well
1195 rb_bh_free(topic_heap
, ptr
);
1196 chptr
->topic
= NULL
;
1197 chptr
->topic_info
= NULL
;
1200 /* set_channel_topic()
1202 * input - channel, topic to set, topic info and topic ts
1204 * side effects - channels topic, topic info and TS are set.
1207 set_channel_topic(struct Channel
*chptr
, const char *topic
, const char *topic_info
, time_t topicts
)
1209 if(strlen(topic
) > 0)
1211 if(chptr
->topic
== NULL
)
1212 allocate_topic(chptr
);
1213 rb_strlcpy(chptr
->topic
, topic
, TOPICLEN
+ 1);
1214 rb_strlcpy(chptr
->topic_info
, topic_info
, USERHOST_REPLYLEN
);
1215 chptr
->topic_time
= topicts
;
1219 if(chptr
->topic
!= NULL
)
1221 chptr
->topic_time
= 0;
1225 /* has_common_channel()
1227 * input - pointer to client
1228 * - pointer to another client
1229 * output - 1 if the two have a channel in common, 0 elsewise
1230 * side effects - none
1233 has_common_channel(struct Client
*client1
, struct Client
*client2
)
1237 RB_DLINK_FOREACH(ptr
, client1
->user
->channel
.head
)
1239 if(IsMember(client2
, ((struct membership
*)ptr
->data
)->chptr
))
1247 * inputs - pointer to channel
1248 * - pointer to client
1249 * output - string with simple modes
1250 * side effects - result from previous calls overwritten
1252 * Stolen from ShadowIRCd 4 --nenolod
1255 channel_modes(struct Channel
*chptr
, struct Client
*client_p
)
1260 static char final
[BUFSIZE
];
1267 for (i
= 0; i
< 256; i
++)
1269 if(chmode_table
[i
].set_func
== chm_hidden
&& !IsOper(client_p
) && IsClient(client_p
))
1271 if(chptr
->mode
.mode
& chmode_flags
[i
])
1275 if(chptr
->mode
.limit
)
1279 if(!IsClient(client_p
) || IsMember(client_p
, chptr
))
1280 pbuf
+= rb_sprintf(pbuf
, " %d", chptr
->mode
.limit
);
1283 if(*chptr
->mode
.key
)
1287 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1288 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.key
);
1291 if(chptr
->mode
.join_num
)
1295 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1296 pbuf
+= rb_sprintf(pbuf
, " %d:%d", chptr
->mode
.join_num
,
1297 chptr
->mode
.join_time
);
1300 if(*chptr
->mode
.forward
&& (ConfigChannel
.use_forward
|| !IsClient(client_p
)))
1304 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1305 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.forward
);
1310 rb_strlcpy(final
, buf1
, sizeof final
);
1311 rb_strlcat(final
, buf2
, sizeof final
);
1315 /* Now lets do some stuff to keep track of what combinations of
1317 * Note that the number of combinations doubles each time you add
1318 * something to this list. Each one is only quick if no servers use that
1319 * combination, but if the numbers get too high here MODE will get too
1320 * slow. I suggest if you get more than 7 here, you consider getting rid
1321 * of some and merging or something. If it wasn't for irc+cs we would
1322 * probably not even need to bother about most of these, but unfortunately
1326 /* void init_chcap_usage_counts(void)
1330 * Side-effects - Initialises the usage counts to zero. Fills in the
1331 * chcap_yes and chcap_no combination tables.
1334 init_chcap_usage_counts(void)
1336 unsigned long m
, c
, y
, n
;
1338 memset(chcap_combos
, 0, sizeof(chcap_combos
));
1340 /* For every possible combination */
1341 for (m
= 0; m
< NCHCAP_COMBOS
; m
++)
1343 /* Check each capab */
1344 for (c
= y
= n
= 0; c
< NCHCAPS
; c
++)
1346 if((m
& (1 << c
)) == 0)
1347 n
|= channel_capabs
[c
];
1349 y
|= channel_capabs
[c
];
1351 chcap_combos
[m
].cap_yes
= y
;
1352 chcap_combos
[m
].cap_no
= n
;
1356 /* void set_chcap_usage_counts(struct Client *serv_p)
1357 * Input: serv_p; The client whose capabs to register.
1359 * Side-effects: Increments the usage counts for the correct capab
1363 set_chcap_usage_counts(struct Client
*serv_p
)
1367 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1369 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1370 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1372 chcap_combos
[n
].count
++;
1377 /* This should be impossible -A1kmm. */
1381 /* void set_chcap_usage_counts(struct Client *serv_p)
1383 * Inputs - serv_p; The client whose capabs to register.
1385 * Side-effects - Decrements the usage counts for the correct capab
1389 unset_chcap_usage_counts(struct Client
*serv_p
)
1393 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1395 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1396 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1398 /* Hopefully capabs can't change dynamically or anything... */
1399 s_assert(chcap_combos
[n
].count
> 0);
1401 if(chcap_combos
[n
].count
> 0)
1402 chcap_combos
[n
].count
--;
1407 /* This should be impossible -A1kmm. */
1411 /* void send_cap_mode_changes(struct Client *client_p,
1412 * struct Client *source_p,
1413 * struct Channel *chptr, int cap, int nocap)
1414 * Input: The client sending(client_p), the source client(source_p),
1415 * the channel to send mode changes for(chptr)
1417 * Side-effects: Sends the appropriate mode changes to capable servers.
1419 * Reverted back to my original design, except that we now keep a count
1420 * of the number of servers which each combination as an optimisation, so
1421 * the capabs combinations which are not needed are not worked out. -A1kmm
1424 send_cap_mode_changes(struct Client
*client_p
, struct Client
*source_p
,
1425 struct Channel
*chptr
, struct ChModeChange mode_changes
[], int mode_count
)
1427 static char modebuf
[BUFSIZE
];
1428 static char parabuf
[BUFSIZE
];
1429 int i
, mbl
, pbl
, nc
, mc
, preflen
, len
;
1438 /* Now send to servers... */
1439 for (j
= 0; j
< NCHCAP_COMBOS
; j
++)
1441 if(chcap_combos
[j
].count
== 0)
1451 cap
= chcap_combos
[j
].cap_yes
;
1452 nocap
= chcap_combos
[j
].cap_no
;
1454 mbl
= preflen
= rb_sprintf(modebuf
, ":%s TMODE %ld %s ",
1455 use_id(source_p
), (long) chptr
->channelts
,
1458 /* loop the list of - modes we have */
1459 for (i
= 0; i
< mode_count
; i
++)
1461 /* if they dont support the cap we need, or they do support a cap they
1462 * cant have, then dont add it to the modebuf.. that way they wont see
1465 if((mode_changes
[i
].letter
== 0) ||
1466 ((cap
& mode_changes
[i
].caps
) != mode_changes
[i
].caps
)
1467 || ((nocap
& mode_changes
[i
].nocaps
) != mode_changes
[i
].nocaps
))
1470 if(!EmptyString(mode_changes
[i
].id
))
1471 arg
= mode_changes
[i
].id
;
1473 arg
= mode_changes
[i
].arg
;
1477 arglen
= strlen(arg
);
1479 /* dont even think about it! --fl */
1480 if(arglen
> MODEBUFLEN
- 5)
1484 /* if we're creeping past the buf size, we need to send it and make
1485 * another line for the other modes
1486 * XXX - this could give away server topology with uids being
1487 * different lengths, but not much we can do, except possibly break
1488 * them as if they were the longest of the nick or uid at all times,
1489 * which even then won't work as we don't always know the uid -A1kmm.
1491 if(arg
&& ((mc
== MAXMODEPARAMSSERV
) ||
1492 ((mbl
+ pbl
+ arglen
+ 4) > (BUFSIZE
- 3))))
1495 sendto_server(client_p
, chptr
, cap
, nocap
,
1496 "%s %s", modebuf
, parabuf
);
1507 if(dir
!= mode_changes
[i
].dir
)
1509 modebuf
[mbl
++] = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1510 dir
= mode_changes
[i
].dir
;
1513 modebuf
[mbl
++] = mode_changes
[i
].letter
;
1519 len
= rb_sprintf(pbuf
, "%s ", arg
);
1526 if(pbl
&& parabuf
[pbl
- 1] == ' ')
1527 parabuf
[pbl
- 1] = 0;
1530 sendto_server(client_p
, chptr
, cap
, nocap
, "%s %s", modebuf
, parabuf
);
1535 resv_chan_forcepart(const char *name
, const char *reason
, int temp_time
)
1538 rb_dlink_node
*next_ptr
;
1539 struct Channel
*chptr
;
1540 struct membership
*msptr
;
1541 struct Client
*target_p
;
1543 if(!ConfigChannel
.resv_forcepart
)
1546 /* for each user on our server in the channel list
1547 * send them a PART, and notify opers.
1549 chptr
= find_channel(name
);
1552 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
1555 target_p
= msptr
->client_p
;
1557 if(IsExemptResv(target_p
))
1560 sendto_server(target_p
, chptr
, CAP_TS6
, NOCAPS
,
1561 ":%s PART %s", target_p
->id
, chptr
->chname
);
1563 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s :%s",
1564 target_p
->name
, target_p
->username
,
1565 target_p
->host
, chptr
->chname
, target_p
->name
);
1567 remove_user_from_channel(msptr
);
1569 /* notify opers & user they were removed from the channel */
1570 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1571 "Forced PART for %s!%s@%s from %s (%s)",
1572 target_p
->name
, target_p
->username
,
1573 target_p
->host
, name
, reason
);
1576 sendto_one_notice(target_p
, ":*** Channel %s is temporarily unavailable on this server.",
1579 sendto_one_notice(target_p
, ":*** Channel %s is no longer available on this server.",
1585 /* Check what we will forward to, without sending any notices to the user
1589 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
1595 if (IsNoForward(source_p
))
1600 chptr
= find_channel(chptr
->mode
.forward
);
1601 /* Can only forward to existing channels */
1604 /* Already on there, show original error message */
1605 if (IsMember(source_p
, chptr
))
1607 /* Juped. Sending a warning notice would be unfair */
1608 if (hash_find_resv(chptr
->chname
))
1610 /* Don't forward to +Q channel */
1611 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
1613 i
= can_join(source_p
, chptr
, key
);
1616 if (i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_CHANNELISFULL
)
1627 * inputs - pointer to client doing join 0
1629 * side effects - Use has decided to join 0. This is legacy
1630 * from the days when channels were numbers not names. *sigh*
1633 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
1635 struct membership
*msptr
;
1636 struct Channel
*chptr
= NULL
;
1639 /* Finish the flood grace period... */
1640 if(MyClient(source_p
) && !IsFloodDone(source_p
))
1641 flood_endgrace(source_p
);
1643 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
1645 while((ptr
= source_p
->user
->channel
.head
))
1647 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
1648 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1649 check_spambot_warning(source_p
, NULL
);
1652 chptr
= msptr
->chptr
;
1653 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
1655 source_p
->username
, source_p
->host
, chptr
->chname
);
1656 remove_user_from_channel(msptr
);
1661 check_channel_name_loc(struct Client
*source_p
, const char *name
)
1665 s_assert(name
!= NULL
);
1666 if(EmptyString(name
))
1669 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1671 for(p
= name
; *p
; ++p
)
1673 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
1679 for(p
= name
; *p
; ++p
)
1686 if(ConfigChannel
.only_ascii_channels
)
1688 for(p
= name
; *p
; ++p
)
1689 if(*p
< 33 || *p
> 126)
1697 void user_join(struct Client
* client_p
, struct Client
* source_p
, const char * channels
, const char * keys
)
1699 static char jbuf
[BUFSIZE
];
1700 struct Channel
*chptr
= NULL
;
1701 struct ConfItem
*aconf
;
1706 char *p
= NULL
, *p2
= NULL
;
1712 if(channels
== NULL
)
1715 /* rebuild the list of channels theyre supposed to be joining.
1716 * this code has a side effect of losing keys, but..
1718 chanlist
= LOCAL_COPY(channels
);
1719 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
1721 /* check the length and name of channel is ok */
1722 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
1724 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1725 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
1729 /* join 0 parts all channels */
1730 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
1732 (void) strcpy(jbuf
, "0");
1736 /* check it begins with # or &, and local chans are disabled */
1737 else if(!IsChannelName(name
) ||
1738 ( !ConfigChannel
.use_local_channels
&& name
[0] == '&'))
1740 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
1741 form_str(ERR_NOSUCHCHANNEL
), name
);
1745 /* see if its resv'd */
1746 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
1748 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1749 form_str(ERR_BADCHANNAME
), name
);
1751 /* dont warn for opers */
1752 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
1753 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
1754 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
1755 source_p
->name
, source_p
->username
,
1756 source_p
->orighost
, name
, aconf
->passwd
);
1757 /* dont update tracking for jupe exempt users, these
1758 * are likely to be spamtrap leaves
1760 else if(IsExemptJupe(source_p
))
1766 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1767 ConfigChannel
.no_join_on_split
)
1769 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1770 me
.name
, source_p
->name
, name
);
1775 (void) strcat(jbuf
, ",");
1776 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
1781 mykey
= LOCAL_COPY(keys
);
1782 key
= rb_strtok_r(mykey
, ",", &p2
);
1785 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
1786 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
1788 hook_data_channel_activity hook_info
;
1790 /* JOIN 0 simply parts all channels the user is in */
1791 if(*name
== '0' && !atoi(name
))
1793 if(source_p
->user
->channel
.head
== NULL
)
1796 do_join_0(&me
, source_p
);
1800 /* look for the channel */
1801 if((chptr
= find_channel(name
)) != NULL
)
1803 if(IsMember(source_p
, chptr
))
1810 hook_data_client_approval moduledata
;
1812 moduledata
.client
= source_p
;
1813 moduledata
.approved
= 0;
1815 call_hook(h_can_create_channel
, &moduledata
);
1817 if(moduledata
.approved
!= 0)
1819 sendto_one(source_p
, form_str(moduledata
.approved
),
1820 me
.name
, source_p
->name
, name
);
1824 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1825 ConfigChannel
.no_create_on_split
)
1827 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1828 me
.name
, source_p
->name
, name
);
1832 flags
= CHFL_CHANOP
;
1835 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
1836 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
1837 (!IsOper(source_p
) ||
1838 (rb_dlink_list_length(&source_p
->user
->channel
) >=
1839 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
1841 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
1842 me
.name
, source_p
->name
, name
);
1846 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
1848 chptr
= get_or_create_channel(source_p
, name
, NULL
);
1852 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1853 me
.name
, source_p
->name
, name
);
1858 /* can_join checks for +i key, bans etc */
1859 if((i
= can_join(source_p
, chptr
, key
)))
1861 if(IsOverride(source_p
))
1863 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1864 "%s is overriding JOIN to [%s]",
1865 get_oper_name(source_p
), chptr
->chname
);
1866 sendto_server(NULL
, chptr
, NOCAPS
, NOCAPS
,
1867 ":%s WALLOPS :%s is overriding JOIN to [%s]",
1868 me
.name
, get_oper_name(source_p
), chptr
->chname
);
1870 else if ((i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_CHANNELISFULL
) ||
1871 (!ConfigChannel
.use_forward
|| (chptr
= check_forward(source_p
, chptr
, key
)) == NULL
))
1873 /* might be wrong, but is there any other better location for such?
1874 * see extensions/chm_operonly.c for other comments on this
1878 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
1883 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr
->chname
);
1887 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1888 check_spambot_warning(source_p
, name
);
1890 /* add the user to the channel */
1891 add_user_to_channel(chptr
, source_p
, flags
);
1892 if (chptr
->mode
.join_num
&&
1893 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
1895 chptr
->join_count
= 0;
1896 chptr
->join_delta
= rb_current_time();
1898 chptr
->join_count
++;
1900 /* we send the user their join here, because we could have to
1901 * send a mode out next.
1903 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1905 source_p
->username
, source_p
->host
, chptr
->chname
);
1907 /* its a new channel, set +nt and burst. */
1908 if(flags
& CHFL_CHANOP
)
1910 chptr
->channelts
= rb_current_time();
1912 /* autochanmodes stuff */
1913 if(ConfigChannel
.autochanmodes
)
1916 for(ch
= ConfigChannel
.autochanmodes
; *ch
; *ch
++)
1918 chptr
->mode
.mode
|= chmode_table
[*ch
].mode_type
;
1923 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
1924 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
1927 modes
= channel_modes(chptr
, &me
);
1929 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
1930 me
.name
, chptr
->chname
, modes
);
1932 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
1933 ":%s SJOIN %ld %s %s :@%s",
1934 me
.id
, (long) chptr
->channelts
,
1935 chptr
->chname
, modes
, source_p
->id
);
1939 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
1940 ":%s JOIN %ld %s +",
1941 use_id(source_p
), (long) chptr
->channelts
,
1945 del_invite(chptr
, source_p
);
1947 if(chptr
->topic
!= NULL
)
1949 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
1950 source_p
->name
, chptr
->chname
, chptr
->topic
);
1952 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
1953 me
.name
, source_p
->name
, chptr
->chname
,
1954 chptr
->topic_info
, chptr
->topic_time
);
1957 channel_member_names(chptr
, source_p
, 1);
1959 hook_info
.client
= source_p
;
1960 hook_info
.chptr
= chptr
;
1961 hook_info
.key
= key
;
1962 call_hook(h_channel_join
, &hook_info
);
1969 * channel_metadata_add
1971 * inputs - pointer to channel struct
1972 * - name of metadata item you wish to add
1973 * - value of metadata item
1974 * - 1 if metadata should be propegated, 0 if not
1976 * side effects - metadata is added to the channel in question
1977 * - metadata is propegated if propegate is set.
1980 channel_metadata_add(struct Channel
*target
, const char *name
, const char *value
, int propegate
)
1982 struct Metadata
*md
;
1984 md
= rb_malloc(sizeof(struct Metadata
));
1985 md
->name
= rb_strdup(name
);
1986 md
->value
= rb_strdup(value
);
1988 irc_dictionary_add(target
->metadata
, md
->name
, md
);
1991 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA ADD %s %s :%s",
1992 target
->chname
, name
, value
);
1998 * channel_metadata_time_add
2000 * inputs - pointer to channel struct
2001 * - name of metadata item you wish to add
2002 * - time_t you wish to add
2003 * - value you wish to add
2005 * side effects - metadata is added to the channel in question
2008 channel_metadata_time_add(struct Channel
*target
, const char *name
, time_t timevalue
, const char *value
)
2010 struct Metadata
*md
;
2012 md
= rb_malloc(sizeof(struct Metadata
));
2013 md
->name
= rb_strdup(name
);
2014 md
->value
= rb_strdup(value
);
2015 md
->timevalue
= timevalue
;
2017 irc_dictionary_add(target
->metadata
, md
->name
, md
);
2023 * channel_metadata_delete
2025 * inputs - pointer to channel struct
2026 * - name of metadata item you wish to delete
2028 * side effects - metadata is deleted from the channel in question
2029 * - deletion is propegated if propegate is set
2032 channel_metadata_delete(struct Channel
*target
, const char *name
, int propegate
)
2034 struct Metadata
*md
= channel_metadata_find(target
, name
);
2039 irc_dictionary_delete(target
->metadata
, md
->name
);
2044 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA DELETE %s %s",
2045 target
->chname
, name
);
2049 * channel_metadata_find
2051 * inputs - pointer to channel struct
2052 * - name of metadata item you wish to read
2053 * output - the requested metadata, if it exists, elsewise null.
2057 channel_metadata_find(struct Channel
*target
, const char *name
)
2062 if(!target
->metadata
)
2065 return irc_dictionary_retrieve(target
->metadata
, name
);
2069 * channel_metadata_clear
2071 * inputs - pointer to channel struct
2073 * side effects - metadata is cleared from the channel in question
2076 channel_metadata_clear(struct Channel
*chptr
)
2078 struct Metadata
*md
;
2079 struct DictionaryIter iter
;
2081 DICTIONARY_FOREACH(md
, &iter
, chptr
->metadata
)
2083 channel_metadata_delete(chptr
, md
->name
, 0);