2 * ircd-ratbox: A slightly useful ircd.
3 * channel.c: Controls channels.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: channel.c 3580 2007-11-07 23:45:14Z jilles $
37 #include "s_serv.h" /* captab */
41 #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
42 #include "s_newconf.h"
45 #include "irc_dictionary.h"
47 struct config_channel_entry ConfigChannel
;
48 rb_dlink_list global_channel_list
;
49 static rb_bh
*channel_heap
;
50 static rb_bh
*ban_heap
;
51 static rb_bh
*topic_heap
;
52 static rb_bh
*member_heap
;
54 static int channel_capabs
[] = { CAP_EX
, CAP_IE
,
59 #define NCHCAPS (sizeof(channel_capabs)/sizeof(int))
60 #define NCHCAP_COMBOS (1 << NCHCAPS)
62 static struct ChCapCombo chcap_combos
[NCHCAP_COMBOS
];
64 static void free_topic(struct Channel
*chptr
);
66 static int h_can_join
;
67 static int h_can_create_channel
;
68 static int h_channel_join
;
74 * side effects - initialises the various blockheaps
79 channel_heap
= rb_bh_create(sizeof(struct Channel
), CHANNEL_HEAP_SIZE
, "channel_heap");
80 ban_heap
= rb_bh_create(sizeof(struct Ban
), BAN_HEAP_SIZE
, "ban_heap");
81 topic_heap
= rb_bh_create(TOPICLEN
+ 1 + USERHOST_REPLYLEN
, TOPIC_HEAP_SIZE
, "topic_heap");
82 member_heap
= rb_bh_create(sizeof(struct membership
), MEMBER_HEAP_SIZE
, "member_heap");
84 h_can_join
= register_hook("can_join");
85 h_channel_join
= register_hook("channel_join");
86 h_can_create_channel
= register_hook("can_create_channel");
90 * allocate_channel - Allocates a channel
93 allocate_channel(const char *chname
)
95 struct Channel
*chptr
;
96 struct Dictionary
*c_metadata
;
97 chptr
= rb_bh_alloc(channel_heap
);
98 chptr
->chname
= rb_strdup(chname
);
100 c_metadata
= irc_dictionary_create(irccmp
);
101 chptr
->c_metadata
= c_metadata
;
106 free_channel(struct Channel
*chptr
)
108 /* insert deletion of metadata here! */
109 rb_free(chptr
->chname
);
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 owner
239 * output - 1 if the user is an owner, 0 if the user is not or owner
245 is_owner(struct membership
*msptr
)
247 if(!ConfigChannel
.use_owner
)
249 if(is_chmode_a(msptr
))
257 * input - membership to check for ops
258 * output - 1 if the user is op, halfop, or owner, 0 elsewise
262 is_any_op(struct membership
*msptr
)
264 if(is_chanop(msptr
) || is_halfop(msptr
) || is_owner(msptr
))
270 /* is_chanop_voiced()
272 * input - memebership to check for status
273 * output - 1 if the user is op, halfop, owner, or voice, 0 elsewise
277 is_chanop_voiced(struct membership
*msptr
)
279 if(is_chanop(msptr
) || is_voiced(msptr
) || is_halfop(msptr
) || is_owner(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_owner(target
))
296 else if(is_halfop(source
) && !is_any_op(target
))
298 else if(is_owner(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];
831 hook_data_channel moduledata
;
833 s_assert(source_p
->localClient
!= NULL
);
835 if(IsOverride(source_p
))
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 if(chptr
->mode
.mode
& MODE_INVITEONLY
)
862 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
864 if(invite
->data
== chptr
)
869 if(!ConfigChannel
.use_invex
)
870 return (ERR_INVITEONLYCHAN
);
871 RB_DLINK_FOREACH(ptr
, chptr
->invexlist
.head
)
874 if(match(invex
->banstr
, src_host
)
875 || match(invex
->banstr
, src_iphost
)
876 || match_cidr(invex
->banstr
, src_iphost
)
877 || match_extban(invex
->banstr
, source_p
, chptr
, CHFL_INVEX
)
878 || (use_althost
&& match(invex
->banstr
, src_althost
)))
882 return (ERR_INVITEONLYCHAN
);
886 if(*chptr
->mode
.key
&& (EmptyString(key
) || irccmp(chptr
->mode
.key
, key
)))
887 return (ERR_BADCHANNELKEY
);
889 if(chptr
->mode
.limit
&&
890 rb_dlink_list_length(&chptr
->members
) >= (unsigned long) chptr
->mode
.limit
)
891 i
= ERR_CHANNELISFULL
;
892 if(chptr
->mode
.mode
& MODE_REGONLY
&& EmptyString(source_p
->user
->suser
))
893 i
= ERR_NEEDREGGEDNICK
;
894 /* join throttling stuff --nenolod */
895 else if(chptr
->mode
.join_num
> 0 && chptr
->mode
.join_time
> 0)
897 if ((rb_current_time() - chptr
->join_delta
<=
898 chptr
->mode
.join_time
) && (chptr
->join_count
>=
899 chptr
->mode
.join_num
))
903 /* allow /invite to override +l/+r/+j also -- jilles */
904 if (i
!= 0 && invite
== NULL
)
906 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
908 if(invite
->data
== chptr
)
915 moduledata
.client
= source_p
;
916 moduledata
.chptr
= chptr
;
917 moduledata
.approved
= 0;
919 call_hook(h_can_join
, &moduledata
);
921 return moduledata
.approved
;
926 * input - user to check in channel, membership pointer
927 * output - whether can explicitly send or not, else CAN_SEND_NONOP
931 can_send(struct Channel
*chptr
, struct Client
*source_p
, struct membership
*msptr
)
933 if(IsServer(source_p
) || IsService(source_p
))
936 if(MyClient(source_p
) && hash_find_resv(chptr
->chname
) &&
937 !IsOper(source_p
) && !IsExemptResv(source_p
))
942 msptr
= find_channel_membership(chptr
, source_p
);
946 /* if its +m or +n and theyre not in the channel,
947 * they cant send. we dont check bans here because
948 * theres no possibility of caching them --fl
950 if(chptr
->mode
.mode
& MODE_NOPRIVMSGS
|| chptr
->mode
.mode
& MODE_MODERATED
)
953 return CAN_SEND_NONOP
;
957 if(is_chanop_voiced(msptr
))
960 if(IsOverride(source_p
))
961 return CAN_SEND_NONOP
;
963 if(chptr
->mode
.mode
& MODE_MODERATED
)
966 if(MyClient(source_p
))
968 /* cached can_send */
969 if(msptr
->bants
== chptr
->bants
)
971 if(can_send_banned(msptr
))
974 else if(is_banned(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
975 || is_quieted(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
)
979 return CAN_SEND_NONOP
;
982 /* find_bannickchange_channel()
983 * Input: client to check
984 * Output: channel preventing nick change
987 find_bannickchange_channel(struct Client
*client_p
)
989 struct Channel
*chptr
;
990 struct membership
*msptr
;
992 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
993 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
995 if (!MyClient(client_p
) || IsOverride(client_p
))
998 rb_sprintf(src_host
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->host
);
999 rb_sprintf(src_iphost
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->sockhost
);
1001 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1004 chptr
= msptr
->chptr
;
1005 if (is_chanop_voiced(msptr
))
1007 /* cached can_send */
1008 if (msptr
->bants
== chptr
->bants
)
1010 if (can_send_banned(msptr
))
1013 else if (is_banned(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
1014 || is_quieted(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
)
1020 /* find_nonickchange_channel()
1021 * Input: client to check
1022 * Output: channel preventing nick change
1025 find_nonickchange_channel(struct Client
*client_p
)
1027 struct Channel
*chptr
;
1028 struct membership
*msptr
;
1031 if (!MyClient(client_p
))
1034 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1037 chptr
= msptr
->chptr
;
1038 if (chptr
->mode
.mode
& MODE_NONICK
&& (!ConfigChannel
.exempt_cmode_N
|| !is_any_op(msptr
)))
1044 /* void check_spambot_warning(struct Client *source_p)
1045 * Input: Client to check, channel name or NULL if this is a part.
1047 * Side-effects: Updates the client's oper_warn_count_down, warns the
1048 * IRC operators if necessary, and updates join_leave_countdown as
1052 check_spambot_warning(struct Client
*source_p
, const char *name
)
1055 int decrement_count
;
1056 if((GlobalSetOptions
.spam_num
&&
1057 (source_p
->localClient
->join_leave_count
>= GlobalSetOptions
.spam_num
)))
1059 if(source_p
->localClient
->oper_warn_count_down
> 0)
1060 source_p
->localClient
->oper_warn_count_down
--;
1062 source_p
->localClient
->oper_warn_count_down
= 0;
1063 if(source_p
->localClient
->oper_warn_count_down
== 0 &&
1066 /* Its already known as a possible spambot */
1067 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
1068 "User %s (%s@%s) trying to join %s is a possible spambot",
1070 source_p
->username
, source_p
->orighost
, name
);
1071 source_p
->localClient
->oper_warn_count_down
= OPER_SPAM_COUNTDOWN
;
1077 (rb_current_time() - source_p
->localClient
->last_leave_time
)) >
1078 JOIN_LEAVE_COUNT_EXPIRE_TIME
)
1080 decrement_count
= (t_delta
/ JOIN_LEAVE_COUNT_EXPIRE_TIME
);
1083 else if(decrement_count
> source_p
->localClient
->join_leave_count
)
1084 source_p
->localClient
->join_leave_count
= 0;
1086 source_p
->localClient
->join_leave_count
-= decrement_count
;
1090 if((rb_current_time() -
1091 (source_p
->localClient
->last_join_time
)) < GlobalSetOptions
.spam_time
)
1093 /* oh, its a possible spambot */
1094 source_p
->localClient
->join_leave_count
++;
1098 source_p
->localClient
->last_join_time
= rb_current_time();
1100 source_p
->localClient
->last_leave_time
= rb_current_time();
1104 /* check_splitmode()
1108 * side effects - compares usercount and servercount against their split
1109 * values and adjusts splitmode accordingly
1112 check_splitmode(void *unused
)
1114 if(splitchecking
&& (ConfigChannel
.no_join_on_split
|| ConfigChannel
.no_create_on_split
))
1116 /* not split, we're being asked to check now because someone
1121 if(eob_count
< split_servers
|| Count
.total
< split_users
)
1124 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1125 "Network split, activating splitmode");
1126 check_splitmode_ev
= rb_event_addish("check_splitmode", check_splitmode
, NULL
, 2);
1129 /* in splitmode, check whether its finished */
1130 else if(eob_count
>= split_servers
&& Count
.total
>= split_users
)
1134 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1135 "Network rejoined, deactivating splitmode");
1137 rb_event_delete(check_splitmode_ev
);
1138 check_splitmode_ev
= NULL
;
1146 * input - channel to allocate topic for
1147 * output - 1 on success, else 0
1148 * side effects - channel gets a topic allocated
1151 allocate_topic(struct Channel
*chptr
)
1158 ptr
= rb_bh_alloc(topic_heap
);
1160 /* Basically we allocate one large block for the topic and
1161 * the topic info. We then split it up into two and shove it
1165 chptr
->topic_info
= (char *) ptr
+ TOPICLEN
+ 1;
1166 *chptr
->topic
= '\0';
1167 *chptr
->topic_info
= '\0';
1172 * input - channel which has topic to free
1174 * side effects - channels topic is free'd
1177 free_topic(struct Channel
*chptr
)
1181 if(chptr
== NULL
|| chptr
->topic
== NULL
)
1184 /* This is safe for now - If you change allocate_topic you
1185 * MUST change this as well
1188 rb_bh_free(topic_heap
, ptr
);
1189 chptr
->topic
= NULL
;
1190 chptr
->topic_info
= NULL
;
1193 /* set_channel_topic()
1195 * input - channel, topic to set, topic info and topic ts
1197 * side effects - channels topic, topic info and TS are set.
1200 set_channel_topic(struct Channel
*chptr
, const char *topic
, const char *topic_info
, time_t topicts
)
1202 if(strlen(topic
) > 0)
1204 if(chptr
->topic
== NULL
)
1205 allocate_topic(chptr
);
1206 rb_strlcpy(chptr
->topic
, topic
, TOPICLEN
+ 1);
1207 rb_strlcpy(chptr
->topic_info
, topic_info
, USERHOST_REPLYLEN
);
1208 chptr
->topic_time
= topicts
;
1212 if(chptr
->topic
!= NULL
)
1214 chptr
->topic_time
= 0;
1218 /* has_common_channel()
1220 * input - pointer to client
1221 * - pointer to another client
1222 * output - 1 if the two have a channel in common, 0 elsewise
1223 * side effects - none
1226 has_common_channel(struct Client
*client1
, struct Client
*client2
)
1230 RB_DLINK_FOREACH(ptr
, client1
->user
->channel
.head
)
1232 if(IsMember(client2
, ((struct membership
*)ptr
->data
)->chptr
))
1240 * inputs - pointer to channel
1241 * - pointer to client
1242 * output - string with simple modes
1243 * side effects - result from previous calls overwritten
1245 * Stolen from ShadowIRCd 4 --nenolod
1248 channel_modes(struct Channel
*chptr
, struct Client
*client_p
)
1253 static char final
[BUFSIZE
];
1260 for (i
= 0; i
< 256; i
++)
1262 if(chmode_table
[i
].set_func
== chm_hidden
&& !IsOper(client_p
) && IsClient(client_p
))
1264 if(chptr
->mode
.mode
& chmode_flags
[i
])
1268 if(chptr
->mode
.limit
)
1272 if(!IsClient(client_p
) || IsMember(client_p
, chptr
))
1273 pbuf
+= rb_sprintf(pbuf
, " %d", chptr
->mode
.limit
);
1276 if(*chptr
->mode
.key
)
1280 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1281 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.key
);
1284 if(chptr
->mode
.join_num
)
1288 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1289 pbuf
+= rb_sprintf(pbuf
, " %d:%d", chptr
->mode
.join_num
,
1290 chptr
->mode
.join_time
);
1293 if(*chptr
->mode
.forward
&& (ConfigChannel
.use_forward
|| !IsClient(client_p
)))
1297 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1298 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.forward
);
1303 rb_strlcpy(final
, buf1
, sizeof final
);
1304 rb_strlcat(final
, buf2
, sizeof final
);
1308 /* Now lets do some stuff to keep track of what combinations of
1310 * Note that the number of combinations doubles each time you add
1311 * something to this list. Each one is only quick if no servers use that
1312 * combination, but if the numbers get too high here MODE will get too
1313 * slow. I suggest if you get more than 7 here, you consider getting rid
1314 * of some and merging or something. If it wasn't for irc+cs we would
1315 * probably not even need to bother about most of these, but unfortunately
1319 /* void init_chcap_usage_counts(void)
1323 * Side-effects - Initialises the usage counts to zero. Fills in the
1324 * chcap_yes and chcap_no combination tables.
1327 init_chcap_usage_counts(void)
1329 unsigned long m
, c
, y
, n
;
1331 memset(chcap_combos
, 0, sizeof(chcap_combos
));
1333 /* For every possible combination */
1334 for (m
= 0; m
< NCHCAP_COMBOS
; m
++)
1336 /* Check each capab */
1337 for (c
= y
= n
= 0; c
< NCHCAPS
; c
++)
1339 if((m
& (1 << c
)) == 0)
1340 n
|= channel_capabs
[c
];
1342 y
|= channel_capabs
[c
];
1344 chcap_combos
[m
].cap_yes
= y
;
1345 chcap_combos
[m
].cap_no
= n
;
1349 /* void set_chcap_usage_counts(struct Client *serv_p)
1350 * Input: serv_p; The client whose capabs to register.
1352 * Side-effects: Increments the usage counts for the correct capab
1356 set_chcap_usage_counts(struct Client
*serv_p
)
1360 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1362 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1363 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1365 chcap_combos
[n
].count
++;
1370 /* This should be impossible -A1kmm. */
1374 /* void set_chcap_usage_counts(struct Client *serv_p)
1376 * Inputs - serv_p; The client whose capabs to register.
1378 * Side-effects - Decrements the usage counts for the correct capab
1382 unset_chcap_usage_counts(struct Client
*serv_p
)
1386 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1388 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1389 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1391 /* Hopefully capabs can't change dynamically or anything... */
1392 s_assert(chcap_combos
[n
].count
> 0);
1394 if(chcap_combos
[n
].count
> 0)
1395 chcap_combos
[n
].count
--;
1400 /* This should be impossible -A1kmm. */
1404 /* void send_cap_mode_changes(struct Client *client_p,
1405 * struct Client *source_p,
1406 * struct Channel *chptr, int cap, int nocap)
1407 * Input: The client sending(client_p), the source client(source_p),
1408 * the channel to send mode changes for(chptr)
1410 * Side-effects: Sends the appropriate mode changes to capable servers.
1412 * Reverted back to my original design, except that we now keep a count
1413 * of the number of servers which each combination as an optimisation, so
1414 * the capabs combinations which are not needed are not worked out. -A1kmm
1417 send_cap_mode_changes(struct Client
*client_p
, struct Client
*source_p
,
1418 struct Channel
*chptr
, struct ChModeChange mode_changes
[], int mode_count
)
1420 static char modebuf
[BUFSIZE
];
1421 static char parabuf
[BUFSIZE
];
1422 int i
, mbl
, pbl
, nc
, mc
, preflen
, len
;
1431 /* Now send to servers... */
1432 for (j
= 0; j
< NCHCAP_COMBOS
; j
++)
1434 if(chcap_combos
[j
].count
== 0)
1444 cap
= chcap_combos
[j
].cap_yes
;
1445 nocap
= chcap_combos
[j
].cap_no
;
1447 mbl
= preflen
= rb_sprintf(modebuf
, ":%s TMODE %ld %s ",
1448 use_id(source_p
), (long) chptr
->channelts
,
1451 /* loop the list of - modes we have */
1452 for (i
= 0; i
< mode_count
; i
++)
1454 /* if they dont support the cap we need, or they do support a cap they
1455 * cant have, then dont add it to the modebuf.. that way they wont see
1458 if((mode_changes
[i
].letter
== 0) ||
1459 ((cap
& mode_changes
[i
].caps
) != mode_changes
[i
].caps
)
1460 || ((nocap
& mode_changes
[i
].nocaps
) != mode_changes
[i
].nocaps
))
1463 if(!EmptyString(mode_changes
[i
].id
))
1464 arg
= mode_changes
[i
].id
;
1466 arg
= mode_changes
[i
].arg
;
1470 arglen
= strlen(arg
);
1472 /* dont even think about it! --fl */
1473 if(arglen
> MODEBUFLEN
- 5)
1477 /* if we're creeping past the buf size, we need to send it and make
1478 * another line for the other modes
1479 * XXX - this could give away server topology with uids being
1480 * different lengths, but not much we can do, except possibly break
1481 * them as if they were the longest of the nick or uid at all times,
1482 * which even then won't work as we don't always know the uid -A1kmm.
1484 if(arg
&& ((mc
== MAXMODEPARAMSSERV
) ||
1485 ((mbl
+ pbl
+ arglen
+ 4) > (BUFSIZE
- 3))))
1488 sendto_server(client_p
, chptr
, cap
, nocap
,
1489 "%s %s", modebuf
, parabuf
);
1500 if(dir
!= mode_changes
[i
].dir
)
1502 modebuf
[mbl
++] = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1503 dir
= mode_changes
[i
].dir
;
1506 modebuf
[mbl
++] = mode_changes
[i
].letter
;
1512 len
= rb_sprintf(pbuf
, "%s ", arg
);
1519 if(pbl
&& parabuf
[pbl
- 1] == ' ')
1520 parabuf
[pbl
- 1] = 0;
1523 sendto_server(client_p
, chptr
, cap
, nocap
, "%s %s", modebuf
, parabuf
);
1527 /* Check what we will forward to, without sending any notices to the user
1531 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
1537 if (IsNoForward(source_p
))
1542 chptr
= find_channel(chptr
->mode
.forward
);
1543 /* Can only forward to existing channels */
1546 /* Already on there, show original error message */
1547 if (IsMember(source_p
, chptr
))
1549 /* Juped. Sending a warning notice would be unfair */
1550 if (hash_find_resv(chptr
->chname
))
1552 /* Don't forward to +Q channel */
1553 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
1555 i
= can_join(source_p
, chptr
, key
);
1558 if (i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_CHANNELISFULL
)
1569 * inputs - pointer to client doing join 0
1571 * side effects - Use has decided to join 0. This is legacy
1572 * from the days when channels were numbers not names. *sigh*
1575 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
1577 struct membership
*msptr
;
1578 struct Channel
*chptr
= NULL
;
1581 /* Finish the flood grace period... */
1582 if(MyClient(source_p
) && !IsFloodDone(source_p
))
1583 flood_endgrace(source_p
);
1585 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
1587 while((ptr
= source_p
->user
->channel
.head
))
1589 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
1590 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1591 check_spambot_warning(source_p
, NULL
);
1594 chptr
= msptr
->chptr
;
1595 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
1597 source_p
->username
, source_p
->host
, chptr
->chname
);
1598 remove_user_from_channel(msptr
);
1603 check_channel_name_loc(struct Client
*source_p
, const char *name
)
1607 s_assert(name
!= NULL
);
1608 if(EmptyString(name
))
1611 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1613 for(p
= name
; *p
; ++p
)
1615 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
1621 for(p
= name
; *p
; ++p
)
1628 if(ConfigChannel
.only_ascii_channels
)
1630 for(p
= name
; *p
; ++p
)
1631 if(*p
< 33 || *p
> 126)
1639 void user_join(struct Client
* client_p
, struct Client
* source_p
, const char * channels
, const char * keys
)
1641 static char jbuf
[BUFSIZE
];
1642 struct Channel
*chptr
= NULL
;
1643 struct ConfItem
*aconf
;
1648 char *p
= NULL
, *p2
= NULL
;
1654 if(channels
== NULL
)
1657 /* rebuild the list of channels theyre supposed to be joining.
1658 * this code has a side effect of losing keys, but..
1660 chanlist
= LOCAL_COPY(channels
);
1661 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
1663 /* check the length and name of channel is ok */
1664 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
1666 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1667 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
1671 /* join 0 parts all channels */
1672 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
1674 (void) strcpy(jbuf
, "0");
1678 /* check it begins with # or &, and local chans are disabled */
1679 else if(!IsChannelName(name
) ||
1680 ( !ConfigChannel
.use_local_channels
&& name
[0] == '&'))
1682 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
1683 form_str(ERR_NOSUCHCHANNEL
), name
);
1687 /* see if its resv'd */
1688 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
1690 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1691 form_str(ERR_BADCHANNAME
), name
);
1693 /* dont warn for opers */
1694 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
1695 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
1696 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
1697 source_p
->name
, source_p
->username
,
1698 source_p
->orighost
, name
, aconf
->passwd
);
1699 /* dont update tracking for jupe exempt users, these
1700 * are likely to be spamtrap leaves
1702 else if(IsExemptJupe(source_p
))
1708 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1709 ConfigChannel
.no_join_on_split
)
1711 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1712 me
.name
, source_p
->name
, name
);
1717 (void) strcat(jbuf
, ",");
1718 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
1723 mykey
= LOCAL_COPY(keys
);
1724 key
= rb_strtok_r(mykey
, ",", &p2
);
1727 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
1728 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
1730 hook_data_channel_activity hook_info
;
1732 /* JOIN 0 simply parts all channels the user is in */
1733 if(*name
== '0' && !atoi(name
))
1735 if(source_p
->user
->channel
.head
== NULL
)
1738 do_join_0(&me
, source_p
);
1742 /* look for the channel */
1743 if((chptr
= find_channel(name
)) != NULL
)
1745 if(IsMember(source_p
, chptr
))
1752 hook_data_client_approval moduledata
;
1754 moduledata
.client
= source_p
;
1755 moduledata
.approved
= 0;
1757 call_hook(h_can_create_channel
, &moduledata
);
1759 if(moduledata
.approved
!= 0)
1761 sendto_one(source_p
, form_str(moduledata
.approved
),
1762 me
.name
, source_p
->name
, name
);
1766 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1767 ConfigChannel
.no_create_on_split
)
1769 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1770 me
.name
, source_p
->name
, name
);
1774 flags
= CHFL_CHANOP
;
1777 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
1778 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
1779 (!IsOper(source_p
) ||
1780 (rb_dlink_list_length(&source_p
->user
->channel
) >=
1781 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
1783 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
1784 me
.name
, source_p
->name
, name
);
1788 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
1790 chptr
= get_or_create_channel(source_p
, name
, NULL
);
1794 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1795 me
.name
, source_p
->name
, name
);
1800 /* can_join checks for +i key, bans etc */
1801 if((i
= can_join(source_p
, chptr
, key
)))
1803 if ((i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_CHANNELISFULL
) ||
1804 (!ConfigChannel
.use_forward
|| (chptr
= check_forward(source_p
, chptr
, key
)) == NULL
))
1806 /* might be wrong, but is there any other better location for such?
1807 * see extensions/chm_operonly.c for other comments on this
1811 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
1816 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr
->chname
);
1820 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1821 check_spambot_warning(source_p
, name
);
1823 /* add the user to the channel */
1824 add_user_to_channel(chptr
, source_p
, flags
);
1825 if (chptr
->mode
.join_num
&&
1826 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
1828 chptr
->join_count
= 0;
1829 chptr
->join_delta
= rb_current_time();
1831 chptr
->join_count
++;
1833 /* we send the user their join here, because we could have to
1834 * send a mode out next.
1836 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1838 source_p
->username
, source_p
->host
, chptr
->chname
);
1840 /* its a new channel, set +nt and burst. */
1841 if(flags
& CHFL_CHANOP
)
1843 chptr
->channelts
= rb_current_time();
1845 /* autochanmodes stuff */
1846 if(ConfigChannel
.autochanmodes
)
1849 for(ch
= ConfigChannel
.autochanmodes
; *ch
; *ch
++)
1851 chptr
->mode
.mode
|= chmode_table
[*ch
].mode_type
;
1856 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
1857 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
1860 modes
= channel_modes(chptr
, &me
);
1862 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
1863 me
.name
, chptr
->chname
, modes
);
1865 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
1866 ":%s SJOIN %ld %s %s :@%s",
1867 me
.id
, (long) chptr
->channelts
,
1868 chptr
->chname
, modes
, source_p
->id
);
1872 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
1873 ":%s JOIN %ld %s +",
1874 use_id(source_p
), (long) chptr
->channelts
,
1878 del_invite(chptr
, source_p
);
1880 if(chptr
->topic
!= NULL
)
1882 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
1883 source_p
->name
, chptr
->chname
, chptr
->topic
);
1885 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
1886 me
.name
, source_p
->name
, chptr
->chname
,
1887 chptr
->topic_info
, chptr
->topic_time
);
1890 channel_member_names(chptr
, source_p
, 1);
1892 hook_info
.client
= source_p
;
1893 hook_info
.chptr
= chptr
;
1894 hook_info
.key
= key
;
1895 call_hook(h_channel_join
, &hook_info
);
1902 * channel_metadata_add
1904 * inputs - pointer to channel struct
1905 * - name of metadata item you wish to add
1906 * - value of metadata item
1907 * - 1 if metadata should be propegated, 0 if not
1909 * side effects - metadata is added to the channel in question
1910 * - metadata is propegated if propegate is set.
1913 channel_metadata_add(struct Channel
*target
, const char *name
, const char *value
, int propegate
)
1915 struct Metadata
*md
;
1917 if(irc_dictionary_find(target
->c_metadata
, name
) != NULL
)
1920 md
= rb_malloc(sizeof(struct Metadata
));
1921 md
->name
= rb_strdup(name
);
1922 md
->value
= rb_strdup(value
);
1924 irc_dictionary_add(target
->c_metadata
, md
->name
, md
);
1927 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA ADD %s %s :%s",
1928 target
->chname
, name
, value
);
1934 * channel_metadata_delete
1936 * inputs - pointer to channel struct
1937 * - name of metadata item you wish to delete
1939 * side effects - metadata is deleted from the channel in question
1940 * - deletion is propegated if propegate is set
1943 channel_metadata_delete(struct Channel
*target
, const char *name
, int propegate
)
1945 struct Metadata
*md
= channel_metadata_find(target
, name
);
1950 irc_dictionary_delete(target
->c_metadata
, md
->name
);
1955 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA DELETE %s %s",
1956 target
->chname
, name
);
1960 * channel_metadata_find
1962 * inputs - pointer to channel struct
1963 * - name of metadata item you wish to read
1964 * output - the requested metadata, if it exists, elsewise null.
1968 channel_metadata_find(struct Channel
*target
, const char *name
)
1973 if(!target
->c_metadata
)
1976 return irc_dictionary_retrieve(target
->c_metadata
, name
);