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
*metadata
;
97 chptr
= rb_bh_alloc(channel_heap
);
98 chptr
->chname
= rb_strdup(chname
);
100 metadata
= irc_dictionary_create(irccmp
);
101 chptr
->metadata
= metadata
;
106 free_channel(struct Channel
*chptr
)
108 channel_metadata_clear(chptr
);
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 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];
829 char *text
= rb_strdup("");
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_sprintf(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
+ ConfigChannel
.kick_no_rejoin_time
> 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
+ ConfigChannel
.kick_no_rejoin_time
> 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
;
990 /* find_bannickchange_channel()
991 * Input: client to check
992 * Output: channel preventing nick change
995 find_bannickchange_channel(struct Client
*client_p
)
997 struct Channel
*chptr
;
998 struct membership
*msptr
;
1000 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
1001 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
1003 if (!MyClient(client_p
) || IsOverride(client_p
))
1006 rb_sprintf(src_host
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->host
);
1007 rb_sprintf(src_iphost
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->sockhost
);
1009 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1012 chptr
= msptr
->chptr
;
1013 if (is_chanop_voiced(msptr
))
1015 /* cached can_send */
1016 if (msptr
->bants
== chptr
->bants
)
1018 if (can_send_banned(msptr
))
1021 else if (is_banned(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
1022 || is_quieted(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
)
1028 /* find_nonickchange_channel()
1029 * Input: client to check
1030 * Output: channel preventing nick change
1033 find_nonickchange_channel(struct Client
*client_p
)
1035 struct Channel
*chptr
;
1036 struct membership
*msptr
;
1039 if (!MyClient(client_p
))
1042 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1045 chptr
= msptr
->chptr
;
1046 if (chptr
->mode
.mode
& MODE_NONICK
&& (!ConfigChannel
.exempt_cmode_N
|| !is_any_op(msptr
)))
1052 /* void check_spambot_warning(struct Client *source_p)
1053 * Input: Client to check, channel name or NULL if this is a part.
1055 * Side-effects: Updates the client's oper_warn_count_down, warns the
1056 * IRC operators if necessary, and updates join_leave_countdown as
1060 check_spambot_warning(struct Client
*source_p
, const char *name
)
1063 int decrement_count
;
1064 if((GlobalSetOptions
.spam_num
&&
1065 (source_p
->localClient
->join_leave_count
>= GlobalSetOptions
.spam_num
)))
1067 if(source_p
->localClient
->oper_warn_count_down
> 0)
1068 source_p
->localClient
->oper_warn_count_down
--;
1070 source_p
->localClient
->oper_warn_count_down
= 0;
1071 if(source_p
->localClient
->oper_warn_count_down
== 0 &&
1074 /* Its already known as a possible spambot */
1075 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
1076 "User %s (%s@%s) trying to join %s is a possible spambot",
1078 source_p
->username
, source_p
->orighost
, name
);
1079 source_p
->localClient
->oper_warn_count_down
= OPER_SPAM_COUNTDOWN
;
1085 (rb_current_time() - source_p
->localClient
->last_leave_time
)) >
1086 JOIN_LEAVE_COUNT_EXPIRE_TIME
)
1088 decrement_count
= (t_delta
/ JOIN_LEAVE_COUNT_EXPIRE_TIME
);
1091 else if(decrement_count
> source_p
->localClient
->join_leave_count
)
1092 source_p
->localClient
->join_leave_count
= 0;
1094 source_p
->localClient
->join_leave_count
-= decrement_count
;
1098 if((rb_current_time() -
1099 (source_p
->localClient
->last_join_time
)) < GlobalSetOptions
.spam_time
)
1101 /* oh, its a possible spambot */
1102 source_p
->localClient
->join_leave_count
++;
1106 source_p
->localClient
->last_join_time
= rb_current_time();
1108 source_p
->localClient
->last_leave_time
= rb_current_time();
1112 /* check_splitmode()
1116 * side effects - compares usercount and servercount against their split
1117 * values and adjusts splitmode accordingly
1120 check_splitmode(void *unused
)
1122 if(splitchecking
&& (ConfigChannel
.no_join_on_split
|| ConfigChannel
.no_create_on_split
))
1124 /* not split, we're being asked to check now because someone
1129 if(eob_count
< split_servers
|| Count
.total
< split_users
)
1132 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1133 "Network split, activating splitmode");
1134 check_splitmode_ev
= rb_event_addish("check_splitmode", check_splitmode
, NULL
, 2);
1137 /* in splitmode, check whether its finished */
1138 else if(eob_count
>= split_servers
&& Count
.total
>= split_users
)
1142 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1143 "Network rejoined, deactivating splitmode");
1145 rb_event_delete(check_splitmode_ev
);
1146 check_splitmode_ev
= NULL
;
1154 * input - channel to allocate topic for
1155 * output - 1 on success, else 0
1156 * side effects - channel gets a topic allocated
1159 allocate_topic(struct Channel
*chptr
)
1166 ptr
= rb_bh_alloc(topic_heap
);
1168 /* Basically we allocate one large block for the topic and
1169 * the topic info. We then split it up into two and shove it
1173 chptr
->topic_info
= (char *) ptr
+ TOPICLEN
+ 1;
1174 *chptr
->topic
= '\0';
1175 *chptr
->topic_info
= '\0';
1180 * input - channel which has topic to free
1182 * side effects - channels topic is free'd
1185 free_topic(struct Channel
*chptr
)
1189 if(chptr
== NULL
|| chptr
->topic
== NULL
)
1192 /* This is safe for now - If you change allocate_topic you
1193 * MUST change this as well
1196 rb_bh_free(topic_heap
, ptr
);
1197 chptr
->topic
= NULL
;
1198 chptr
->topic_info
= NULL
;
1201 /* set_channel_topic()
1203 * input - channel, topic to set, topic info and topic ts
1205 * side effects - channels topic, topic info and TS are set.
1208 set_channel_topic(struct Channel
*chptr
, const char *topic
, const char *topic_info
, time_t topicts
)
1210 if(strlen(topic
) > 0)
1212 if(chptr
->topic
== NULL
)
1213 allocate_topic(chptr
);
1214 rb_strlcpy(chptr
->topic
, topic
, TOPICLEN
+ 1);
1215 rb_strlcpy(chptr
->topic_info
, topic_info
, USERHOST_REPLYLEN
);
1216 chptr
->topic_time
= topicts
;
1220 if(chptr
->topic
!= NULL
)
1222 chptr
->topic_time
= 0;
1226 /* has_common_channel()
1228 * input - pointer to client
1229 * - pointer to another client
1230 * output - 1 if the two have a channel in common, 0 elsewise
1231 * side effects - none
1234 has_common_channel(struct Client
*client1
, struct Client
*client2
)
1238 RB_DLINK_FOREACH(ptr
, client1
->user
->channel
.head
)
1240 if(IsMember(client2
, ((struct membership
*)ptr
->data
)->chptr
))
1248 * inputs - pointer to channel
1249 * - pointer to client
1250 * output - string with simple modes
1251 * side effects - result from previous calls overwritten
1253 * Stolen from ShadowIRCd 4 --nenolod
1256 channel_modes(struct Channel
*chptr
, struct Client
*client_p
)
1261 static char final
[BUFSIZE
];
1268 for (i
= 0; i
< 256; i
++)
1270 if(chmode_table
[i
].set_func
== chm_hidden
&& !IsOper(client_p
) && IsClient(client_p
))
1272 if(chptr
->mode
.mode
& chmode_flags
[i
])
1276 if(chptr
->mode
.limit
)
1280 if(!IsClient(client_p
) || IsMember(client_p
, chptr
))
1281 pbuf
+= rb_sprintf(pbuf
, " %d", chptr
->mode
.limit
);
1284 if(*chptr
->mode
.key
)
1288 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1289 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.key
);
1292 if(chptr
->mode
.join_num
)
1296 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1297 pbuf
+= rb_sprintf(pbuf
, " %d:%d", chptr
->mode
.join_num
,
1298 chptr
->mode
.join_time
);
1301 if(*chptr
->mode
.forward
&& (ConfigChannel
.use_forward
|| !IsClient(client_p
)))
1305 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1306 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.forward
);
1311 rb_strlcpy(final
, buf1
, sizeof final
);
1312 rb_strlcat(final
, buf2
, sizeof final
);
1316 /* Now lets do some stuff to keep track of what combinations of
1318 * Note that the number of combinations doubles each time you add
1319 * something to this list. Each one is only quick if no servers use that
1320 * combination, but if the numbers get too high here MODE will get too
1321 * slow. I suggest if you get more than 7 here, you consider getting rid
1322 * of some and merging or something. If it wasn't for irc+cs we would
1323 * probably not even need to bother about most of these, but unfortunately
1327 /* void init_chcap_usage_counts(void)
1331 * Side-effects - Initialises the usage counts to zero. Fills in the
1332 * chcap_yes and chcap_no combination tables.
1335 init_chcap_usage_counts(void)
1337 unsigned long m
, c
, y
, n
;
1339 memset(chcap_combos
, 0, sizeof(chcap_combos
));
1341 /* For every possible combination */
1342 for (m
= 0; m
< NCHCAP_COMBOS
; m
++)
1344 /* Check each capab */
1345 for (c
= y
= n
= 0; c
< NCHCAPS
; c
++)
1347 if((m
& (1 << c
)) == 0)
1348 n
|= channel_capabs
[c
];
1350 y
|= channel_capabs
[c
];
1352 chcap_combos
[m
].cap_yes
= y
;
1353 chcap_combos
[m
].cap_no
= n
;
1357 /* void set_chcap_usage_counts(struct Client *serv_p)
1358 * Input: serv_p; The client whose capabs to register.
1360 * Side-effects: Increments the usage counts for the correct capab
1364 set_chcap_usage_counts(struct Client
*serv_p
)
1368 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1370 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1371 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1373 chcap_combos
[n
].count
++;
1378 /* This should be impossible -A1kmm. */
1382 /* void set_chcap_usage_counts(struct Client *serv_p)
1384 * Inputs - serv_p; The client whose capabs to register.
1386 * Side-effects - Decrements the usage counts for the correct capab
1390 unset_chcap_usage_counts(struct Client
*serv_p
)
1394 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1396 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1397 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1399 /* Hopefully capabs can't change dynamically or anything... */
1400 s_assert(chcap_combos
[n
].count
> 0);
1402 if(chcap_combos
[n
].count
> 0)
1403 chcap_combos
[n
].count
--;
1408 /* This should be impossible -A1kmm. */
1412 /* void send_cap_mode_changes(struct Client *client_p,
1413 * struct Client *source_p,
1414 * struct Channel *chptr, int cap, int nocap)
1415 * Input: The client sending(client_p), the source client(source_p),
1416 * the channel to send mode changes for(chptr)
1418 * Side-effects: Sends the appropriate mode changes to capable servers.
1420 * Reverted back to my original design, except that we now keep a count
1421 * of the number of servers which each combination as an optimisation, so
1422 * the capabs combinations which are not needed are not worked out. -A1kmm
1425 send_cap_mode_changes(struct Client
*client_p
, struct Client
*source_p
,
1426 struct Channel
*chptr
, struct ChModeChange mode_changes
[], int mode_count
)
1428 static char modebuf
[BUFSIZE
];
1429 static char parabuf
[BUFSIZE
];
1430 int i
, mbl
, pbl
, nc
, mc
, preflen
, len
;
1439 /* Now send to servers... */
1440 for (j
= 0; j
< NCHCAP_COMBOS
; j
++)
1442 if(chcap_combos
[j
].count
== 0)
1452 cap
= chcap_combos
[j
].cap_yes
;
1453 nocap
= chcap_combos
[j
].cap_no
;
1455 mbl
= preflen
= rb_sprintf(modebuf
, ":%s TMODE %ld %s ",
1456 use_id(source_p
), (long) chptr
->channelts
,
1459 /* loop the list of - modes we have */
1460 for (i
= 0; i
< mode_count
; i
++)
1462 /* if they dont support the cap we need, or they do support a cap they
1463 * cant have, then dont add it to the modebuf.. that way they wont see
1466 if((mode_changes
[i
].letter
== 0) ||
1467 ((cap
& mode_changes
[i
].caps
) != mode_changes
[i
].caps
)
1468 || ((nocap
& mode_changes
[i
].nocaps
) != mode_changes
[i
].nocaps
))
1471 if(!EmptyString(mode_changes
[i
].id
))
1472 arg
= mode_changes
[i
].id
;
1474 arg
= mode_changes
[i
].arg
;
1478 arglen
= strlen(arg
);
1480 /* dont even think about it! --fl */
1481 if(arglen
> MODEBUFLEN
- 5)
1485 /* if we're creeping past the buf size, we need to send it and make
1486 * another line for the other modes
1487 * XXX - this could give away server topology with uids being
1488 * different lengths, but not much we can do, except possibly break
1489 * them as if they were the longest of the nick or uid at all times,
1490 * which even then won't work as we don't always know the uid -A1kmm.
1492 if(arg
&& ((mc
== MAXMODEPARAMSSERV
) ||
1493 ((mbl
+ pbl
+ arglen
+ 4) > (BUFSIZE
- 3))))
1496 sendto_server(client_p
, chptr
, cap
, nocap
,
1497 "%s %s", modebuf
, parabuf
);
1508 if(dir
!= mode_changes
[i
].dir
)
1510 modebuf
[mbl
++] = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1511 dir
= mode_changes
[i
].dir
;
1514 modebuf
[mbl
++] = mode_changes
[i
].letter
;
1520 len
= rb_sprintf(pbuf
, "%s ", arg
);
1527 if(pbl
&& parabuf
[pbl
- 1] == ' ')
1528 parabuf
[pbl
- 1] = 0;
1531 sendto_server(client_p
, chptr
, cap
, nocap
, "%s %s", modebuf
, parabuf
);
1535 /* Check what we will forward to, without sending any notices to the user
1539 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
1545 if (IsNoForward(source_p
))
1550 chptr
= find_channel(chptr
->mode
.forward
);
1551 /* Can only forward to existing channels */
1554 /* Already on there, show original error message */
1555 if (IsMember(source_p
, chptr
))
1557 /* Juped. Sending a warning notice would be unfair */
1558 if (hash_find_resv(chptr
->chname
))
1560 /* Don't forward to +Q channel */
1561 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
1563 i
= can_join(source_p
, chptr
, key
);
1566 if (i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_CHANNELISFULL
)
1577 * inputs - pointer to client doing join 0
1579 * side effects - Use has decided to join 0. This is legacy
1580 * from the days when channels were numbers not names. *sigh*
1583 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
1585 struct membership
*msptr
;
1586 struct Channel
*chptr
= NULL
;
1589 /* Finish the flood grace period... */
1590 if(MyClient(source_p
) && !IsFloodDone(source_p
))
1591 flood_endgrace(source_p
);
1593 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
1595 while((ptr
= source_p
->user
->channel
.head
))
1597 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
1598 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1599 check_spambot_warning(source_p
, NULL
);
1602 chptr
= msptr
->chptr
;
1603 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
1605 source_p
->username
, source_p
->host
, chptr
->chname
);
1606 remove_user_from_channel(msptr
);
1611 check_channel_name_loc(struct Client
*source_p
, const char *name
)
1615 s_assert(name
!= NULL
);
1616 if(EmptyString(name
))
1619 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1621 for(p
= name
; *p
; ++p
)
1623 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
1629 for(p
= name
; *p
; ++p
)
1636 if(ConfigChannel
.only_ascii_channels
)
1638 for(p
= name
; *p
; ++p
)
1639 if(*p
< 33 || *p
> 126)
1647 void user_join(struct Client
* client_p
, struct Client
* source_p
, const char * channels
, const char * keys
)
1649 static char jbuf
[BUFSIZE
];
1650 struct Channel
*chptr
= NULL
;
1651 struct ConfItem
*aconf
;
1656 char *p
= NULL
, *p2
= NULL
;
1662 if(channels
== NULL
)
1665 /* rebuild the list of channels theyre supposed to be joining.
1666 * this code has a side effect of losing keys, but..
1668 chanlist
= LOCAL_COPY(channels
);
1669 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
1671 /* check the length and name of channel is ok */
1672 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
1674 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1675 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
1679 /* join 0 parts all channels */
1680 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
1682 (void) strcpy(jbuf
, "0");
1686 /* check it begins with # or &, and local chans are disabled */
1687 else if(!IsChannelName(name
) ||
1688 ( !ConfigChannel
.use_local_channels
&& name
[0] == '&'))
1690 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
1691 form_str(ERR_NOSUCHCHANNEL
), name
);
1695 /* see if its resv'd */
1696 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
1698 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1699 form_str(ERR_BADCHANNAME
), name
);
1701 /* dont warn for opers */
1702 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
1703 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
1704 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
1705 source_p
->name
, source_p
->username
,
1706 source_p
->orighost
, name
, aconf
->passwd
);
1707 /* dont update tracking for jupe exempt users, these
1708 * are likely to be spamtrap leaves
1710 else if(IsExemptJupe(source_p
))
1716 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1717 ConfigChannel
.no_join_on_split
)
1719 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1720 me
.name
, source_p
->name
, name
);
1725 (void) strcat(jbuf
, ",");
1726 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
1731 mykey
= LOCAL_COPY(keys
);
1732 key
= rb_strtok_r(mykey
, ",", &p2
);
1735 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
1736 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
1738 hook_data_channel_activity hook_info
;
1740 /* JOIN 0 simply parts all channels the user is in */
1741 if(*name
== '0' && !atoi(name
))
1743 if(source_p
->user
->channel
.head
== NULL
)
1746 do_join_0(&me
, source_p
);
1750 /* look for the channel */
1751 if((chptr
= find_channel(name
)) != NULL
)
1753 if(IsMember(source_p
, chptr
))
1760 hook_data_client_approval moduledata
;
1762 moduledata
.client
= source_p
;
1763 moduledata
.approved
= 0;
1765 call_hook(h_can_create_channel
, &moduledata
);
1767 if(moduledata
.approved
!= 0)
1769 sendto_one(source_p
, form_str(moduledata
.approved
),
1770 me
.name
, source_p
->name
, name
);
1774 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1775 ConfigChannel
.no_create_on_split
)
1777 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1778 me
.name
, source_p
->name
, name
);
1782 flags
= CHFL_CHANOP
;
1785 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
1786 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
1787 (!IsOper(source_p
) ||
1788 (rb_dlink_list_length(&source_p
->user
->channel
) >=
1789 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
1791 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
1792 me
.name
, source_p
->name
, name
);
1796 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
1798 chptr
= get_or_create_channel(source_p
, name
, NULL
);
1802 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1803 me
.name
, source_p
->name
, name
);
1808 /* can_join checks for +i key, bans etc */
1809 if((i
= can_join(source_p
, chptr
, key
)))
1811 if(IsOverride(source_p
))
1813 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1814 "%s is overriding JOIN to [%s]",
1815 get_oper_name(source_p
), chptr
->chname
);
1816 sendto_server(NULL
, chptr
, NOCAPS
, NOCAPS
,
1817 ":%s WALLOPS :%s is overriding JOIN to [%s]",
1818 me
.name
, get_oper_name(source_p
), chptr
->chname
);
1820 else if ((i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_CHANNELISFULL
) ||
1821 (!ConfigChannel
.use_forward
|| (chptr
= check_forward(source_p
, chptr
, key
)) == NULL
))
1823 /* might be wrong, but is there any other better location for such?
1824 * see extensions/chm_operonly.c for other comments on this
1828 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
1833 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr
->chname
);
1837 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1838 check_spambot_warning(source_p
, name
);
1840 /* add the user to the channel */
1841 add_user_to_channel(chptr
, source_p
, flags
);
1842 if (chptr
->mode
.join_num
&&
1843 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
1845 chptr
->join_count
= 0;
1846 chptr
->join_delta
= rb_current_time();
1848 chptr
->join_count
++;
1850 /* we send the user their join here, because we could have to
1851 * send a mode out next.
1853 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1855 source_p
->username
, source_p
->host
, chptr
->chname
);
1857 /* its a new channel, set +nt and burst. */
1858 if(flags
& CHFL_CHANOP
)
1860 chptr
->channelts
= rb_current_time();
1862 /* autochanmodes stuff */
1863 if(ConfigChannel
.autochanmodes
)
1866 for(ch
= ConfigChannel
.autochanmodes
; *ch
; *ch
++)
1868 chptr
->mode
.mode
|= chmode_table
[*ch
].mode_type
;
1873 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
1874 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
1877 modes
= channel_modes(chptr
, &me
);
1879 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
1880 me
.name
, chptr
->chname
, modes
);
1882 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
1883 ":%s SJOIN %ld %s %s :@%s",
1884 me
.id
, (long) chptr
->channelts
,
1885 chptr
->chname
, modes
, source_p
->id
);
1889 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
1890 ":%s JOIN %ld %s +",
1891 use_id(source_p
), (long) chptr
->channelts
,
1895 del_invite(chptr
, source_p
);
1897 if(chptr
->topic
!= NULL
)
1899 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
1900 source_p
->name
, chptr
->chname
, chptr
->topic
);
1902 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
1903 me
.name
, source_p
->name
, chptr
->chname
,
1904 chptr
->topic_info
, chptr
->topic_time
);
1907 channel_member_names(chptr
, source_p
, 1);
1909 hook_info
.client
= source_p
;
1910 hook_info
.chptr
= chptr
;
1911 hook_info
.key
= key
;
1912 call_hook(h_channel_join
, &hook_info
);
1919 * channel_metadata_add
1921 * inputs - pointer to channel struct
1922 * - name of metadata item you wish to add
1923 * - value of metadata item
1924 * - 1 if metadata should be propegated, 0 if not
1926 * side effects - metadata is added to the channel in question
1927 * - metadata is propegated if propegate is set.
1930 channel_metadata_add(struct Channel
*target
, const char *name
, const char *value
, int propegate
)
1932 struct Metadata
*md
;
1934 md
= rb_malloc(sizeof(struct Metadata
));
1935 md
->name
= rb_strdup(name
);
1936 md
->value
= rb_strdup(value
);
1938 irc_dictionary_add(target
->metadata
, md
->name
, md
);
1941 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA ADD %s %s :%s",
1942 target
->chname
, name
, value
);
1948 * channel_metadata_time_add
1950 * inputs - pointer to channel struct
1951 * - name of metadata item you wish to add
1952 * - time_t you wish to add
1953 * - value you wish to add
1955 * side effects - metadata is added to the channel in question
1958 channel_metadata_time_add(struct Channel
*target
, const char *name
, time_t timevalue
, const char *value
)
1960 struct Metadata
*md
;
1962 md
= rb_malloc(sizeof(struct Metadata
));
1963 md
->name
= rb_strdup(name
);
1964 md
->value
= rb_strdup(value
);
1965 md
->timevalue
= timevalue
;
1967 irc_dictionary_add(target
->metadata
, md
->name
, md
);
1973 * channel_metadata_delete
1975 * inputs - pointer to channel struct
1976 * - name of metadata item you wish to delete
1978 * side effects - metadata is deleted from the channel in question
1979 * - deletion is propegated if propegate is set
1982 channel_metadata_delete(struct Channel
*target
, const char *name
, int propegate
)
1984 struct Metadata
*md
= channel_metadata_find(target
, name
);
1989 irc_dictionary_delete(target
->metadata
, md
->name
);
1994 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA DELETE %s %s",
1995 target
->chname
, name
);
1999 * channel_metadata_find
2001 * inputs - pointer to channel struct
2002 * - name of metadata item you wish to read
2003 * output - the requested metadata, if it exists, elsewise null.
2007 channel_metadata_find(struct Channel
*target
, const char *name
)
2012 if(!target
->metadata
)
2015 return irc_dictionary_retrieve(target
->metadata
, name
);
2019 * channel_metadata_clear
2021 * inputs - pointer to channel struct
2023 * side effects - metadata is cleared from the channel in question
2026 channel_metadata_clear(struct Channel
*chptr
)
2028 struct Metadata
*md
;
2029 struct DictionaryIter iter
;
2031 DICTIONARY_FOREACH(md
, &iter
, chptr
->metadata
)
2033 channel_metadata_delete(chptr
, md
->name
, 0);