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 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 struct DictionaryIter iter
;
835 s_assert(source_p
->localClient
!= NULL
);
837 if(IsOverride(source_p
))
840 rb_sprintf(src_host
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->host
);
841 rb_sprintf(src_iphost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->sockhost
);
842 if(source_p
->localClient
->mangledhost
!= NULL
)
844 /* if host mangling mode enabled, also check their real host */
845 if(!strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
847 rb_sprintf(src_althost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->orighost
);
850 /* if host mangling mode not enabled and no other spoof,
851 * also check the mangled form of their host */
852 else if (!IsDynSpoof(source_p
))
854 rb_sprintf(src_althost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->localClient
->mangledhost
);
859 if((is_banned(chptr
, source_p
, NULL
, src_host
, src_iphost
)) == CHFL_BAN
)
860 return (ERR_BANNEDFROMCHAN
);
862 DICTIONARY_FOREACH(md
, &iter
, chptr
->metadata
)
864 if(!strcmp(md
->name
, "KICKNOREJOIN") && !strcmp(md
->value
, source_p
->id
) && (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
->name
, "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(IsOverride(source_p
))
972 return CAN_SEND_NONOP
;
974 if(chptr
->mode
.mode
& MODE_MODERATED
)
977 if(MyClient(source_p
))
979 /* cached can_send */
980 if(msptr
->bants
== chptr
->bants
)
982 if(can_send_banned(msptr
))
985 else if(is_banned(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
986 || is_quieted(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
)
990 return CAN_SEND_NONOP
;
993 /* find_bannickchange_channel()
994 * Input: client to check
995 * Output: channel preventing nick change
998 find_bannickchange_channel(struct Client
*client_p
)
1000 struct Channel
*chptr
;
1001 struct membership
*msptr
;
1003 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
1004 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
1006 if (!MyClient(client_p
) || IsOverride(client_p
))
1009 rb_sprintf(src_host
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->host
);
1010 rb_sprintf(src_iphost
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->sockhost
);
1012 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1015 chptr
= msptr
->chptr
;
1016 if (is_chanop_voiced(msptr
))
1018 /* cached can_send */
1019 if (msptr
->bants
== chptr
->bants
)
1021 if (can_send_banned(msptr
))
1024 else if (is_banned(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
1025 || is_quieted(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
)
1031 /* find_nonickchange_channel()
1032 * Input: client to check
1033 * Output: channel preventing nick change
1036 find_nonickchange_channel(struct Client
*client_p
)
1038 struct Channel
*chptr
;
1039 struct membership
*msptr
;
1042 if (!MyClient(client_p
))
1045 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1048 chptr
= msptr
->chptr
;
1049 if (chptr
->mode
.mode
& MODE_NONICK
&& (!ConfigChannel
.exempt_cmode_N
|| !is_any_op(msptr
)))
1055 /* void check_spambot_warning(struct Client *source_p)
1056 * Input: Client to check, channel name or NULL if this is a part.
1058 * Side-effects: Updates the client's oper_warn_count_down, warns the
1059 * IRC operators if necessary, and updates join_leave_countdown as
1063 check_spambot_warning(struct Client
*source_p
, const char *name
)
1066 int decrement_count
;
1067 if((GlobalSetOptions
.spam_num
&&
1068 (source_p
->localClient
->join_leave_count
>= GlobalSetOptions
.spam_num
)))
1070 if(source_p
->localClient
->oper_warn_count_down
> 0)
1071 source_p
->localClient
->oper_warn_count_down
--;
1073 source_p
->localClient
->oper_warn_count_down
= 0;
1074 if(source_p
->localClient
->oper_warn_count_down
== 0 &&
1077 /* Its already known as a possible spambot */
1078 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
1079 "User %s (%s@%s) trying to join %s is a possible spambot",
1081 source_p
->username
, source_p
->orighost
, name
);
1082 source_p
->localClient
->oper_warn_count_down
= OPER_SPAM_COUNTDOWN
;
1088 (rb_current_time() - source_p
->localClient
->last_leave_time
)) >
1089 JOIN_LEAVE_COUNT_EXPIRE_TIME
)
1091 decrement_count
= (t_delta
/ JOIN_LEAVE_COUNT_EXPIRE_TIME
);
1094 else if(decrement_count
> source_p
->localClient
->join_leave_count
)
1095 source_p
->localClient
->join_leave_count
= 0;
1097 source_p
->localClient
->join_leave_count
-= decrement_count
;
1101 if((rb_current_time() -
1102 (source_p
->localClient
->last_join_time
)) < GlobalSetOptions
.spam_time
)
1104 /* oh, its a possible spambot */
1105 source_p
->localClient
->join_leave_count
++;
1109 source_p
->localClient
->last_join_time
= rb_current_time();
1111 source_p
->localClient
->last_leave_time
= rb_current_time();
1115 /* check_splitmode()
1119 * side effects - compares usercount and servercount against their split
1120 * values and adjusts splitmode accordingly
1123 check_splitmode(void *unused
)
1125 if(splitchecking
&& (ConfigChannel
.no_join_on_split
|| ConfigChannel
.no_create_on_split
))
1127 /* not split, we're being asked to check now because someone
1132 if(eob_count
< split_servers
|| Count
.total
< split_users
)
1135 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1136 "Network split, activating splitmode");
1137 check_splitmode_ev
= rb_event_addish("check_splitmode", check_splitmode
, NULL
, 2);
1140 /* in splitmode, check whether its finished */
1141 else if(eob_count
>= split_servers
&& Count
.total
>= split_users
)
1145 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1146 "Network rejoined, deactivating splitmode");
1148 rb_event_delete(check_splitmode_ev
);
1149 check_splitmode_ev
= NULL
;
1157 * input - channel to allocate topic for
1158 * output - 1 on success, else 0
1159 * side effects - channel gets a topic allocated
1162 allocate_topic(struct Channel
*chptr
)
1169 ptr
= rb_bh_alloc(topic_heap
);
1171 /* Basically we allocate one large block for the topic and
1172 * the topic info. We then split it up into two and shove it
1176 chptr
->topic_info
= (char *) ptr
+ TOPICLEN
+ 1;
1177 *chptr
->topic
= '\0';
1178 *chptr
->topic_info
= '\0';
1183 * input - channel which has topic to free
1185 * side effects - channels topic is free'd
1188 free_topic(struct Channel
*chptr
)
1192 if(chptr
== NULL
|| chptr
->topic
== NULL
)
1195 /* This is safe for now - If you change allocate_topic you
1196 * MUST change this as well
1199 rb_bh_free(topic_heap
, ptr
);
1200 chptr
->topic
= NULL
;
1201 chptr
->topic_info
= NULL
;
1204 /* set_channel_topic()
1206 * input - channel, topic to set, topic info and topic ts
1208 * side effects - channels topic, topic info and TS are set.
1211 set_channel_topic(struct Channel
*chptr
, const char *topic
, const char *topic_info
, time_t topicts
)
1213 if(strlen(topic
) > 0)
1215 if(chptr
->topic
== NULL
)
1216 allocate_topic(chptr
);
1217 rb_strlcpy(chptr
->topic
, topic
, TOPICLEN
+ 1);
1218 rb_strlcpy(chptr
->topic_info
, topic_info
, USERHOST_REPLYLEN
);
1219 chptr
->topic_time
= topicts
;
1223 if(chptr
->topic
!= NULL
)
1225 chptr
->topic_time
= 0;
1229 /* has_common_channel()
1231 * input - pointer to client
1232 * - pointer to another client
1233 * output - 1 if the two have a channel in common, 0 elsewise
1234 * side effects - none
1237 has_common_channel(struct Client
*client1
, struct Client
*client2
)
1241 RB_DLINK_FOREACH(ptr
, client1
->user
->channel
.head
)
1243 if(IsMember(client2
, ((struct membership
*)ptr
->data
)->chptr
))
1251 * inputs - pointer to channel
1252 * - pointer to client
1253 * output - string with simple modes
1254 * side effects - result from previous calls overwritten
1256 * Stolen from ShadowIRCd 4 --nenolod
1259 channel_modes(struct Channel
*chptr
, struct Client
*client_p
)
1264 static char final
[BUFSIZE
];
1271 for (i
= 0; i
< 256; i
++)
1273 if(chmode_table
[i
].set_func
== chm_hidden
&& !IsOper(client_p
) && IsClient(client_p
))
1275 if(chptr
->mode
.mode
& chmode_flags
[i
])
1279 if(chptr
->mode
.limit
)
1283 if(!IsClient(client_p
) || IsMember(client_p
, chptr
))
1284 pbuf
+= rb_sprintf(pbuf
, " %d", chptr
->mode
.limit
);
1287 if(*chptr
->mode
.key
)
1291 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1292 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.key
);
1295 if(chptr
->mode
.join_num
)
1299 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1300 pbuf
+= rb_sprintf(pbuf
, " %d:%d", chptr
->mode
.join_num
,
1301 chptr
->mode
.join_time
);
1304 if(*chptr
->mode
.forward
&& (ConfigChannel
.use_forward
|| !IsClient(client_p
)))
1308 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1309 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.forward
);
1314 rb_strlcpy(final
, buf1
, sizeof final
);
1315 rb_strlcat(final
, buf2
, sizeof final
);
1319 /* Now lets do some stuff to keep track of what combinations of
1321 * Note that the number of combinations doubles each time you add
1322 * something to this list. Each one is only quick if no servers use that
1323 * combination, but if the numbers get too high here MODE will get too
1324 * slow. I suggest if you get more than 7 here, you consider getting rid
1325 * of some and merging or something. If it wasn't for irc+cs we would
1326 * probably not even need to bother about most of these, but unfortunately
1330 /* void init_chcap_usage_counts(void)
1334 * Side-effects - Initialises the usage counts to zero. Fills in the
1335 * chcap_yes and chcap_no combination tables.
1338 init_chcap_usage_counts(void)
1340 unsigned long m
, c
, y
, n
;
1342 memset(chcap_combos
, 0, sizeof(chcap_combos
));
1344 /* For every possible combination */
1345 for (m
= 0; m
< NCHCAP_COMBOS
; m
++)
1347 /* Check each capab */
1348 for (c
= y
= n
= 0; c
< NCHCAPS
; c
++)
1350 if((m
& (1 << c
)) == 0)
1351 n
|= channel_capabs
[c
];
1353 y
|= channel_capabs
[c
];
1355 chcap_combos
[m
].cap_yes
= y
;
1356 chcap_combos
[m
].cap_no
= n
;
1360 /* void set_chcap_usage_counts(struct Client *serv_p)
1361 * Input: serv_p; The client whose capabs to register.
1363 * Side-effects: Increments the usage counts for the correct capab
1367 set_chcap_usage_counts(struct Client
*serv_p
)
1371 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1373 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1374 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1376 chcap_combos
[n
].count
++;
1381 /* This should be impossible -A1kmm. */
1385 /* void set_chcap_usage_counts(struct Client *serv_p)
1387 * Inputs - serv_p; The client whose capabs to register.
1389 * Side-effects - Decrements the usage counts for the correct capab
1393 unset_chcap_usage_counts(struct Client
*serv_p
)
1397 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1399 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1400 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1402 /* Hopefully capabs can't change dynamically or anything... */
1403 s_assert(chcap_combos
[n
].count
> 0);
1405 if(chcap_combos
[n
].count
> 0)
1406 chcap_combos
[n
].count
--;
1411 /* This should be impossible -A1kmm. */
1415 /* void send_cap_mode_changes(struct Client *client_p,
1416 * struct Client *source_p,
1417 * struct Channel *chptr, int cap, int nocap)
1418 * Input: The client sending(client_p), the source client(source_p),
1419 * the channel to send mode changes for(chptr)
1421 * Side-effects: Sends the appropriate mode changes to capable servers.
1423 * Reverted back to my original design, except that we now keep a count
1424 * of the number of servers which each combination as an optimisation, so
1425 * the capabs combinations which are not needed are not worked out. -A1kmm
1428 send_cap_mode_changes(struct Client
*client_p
, struct Client
*source_p
,
1429 struct Channel
*chptr
, struct ChModeChange mode_changes
[], int mode_count
)
1431 static char modebuf
[BUFSIZE
];
1432 static char parabuf
[BUFSIZE
];
1433 int i
, mbl
, pbl
, nc
, mc
, preflen
, len
;
1442 /* Now send to servers... */
1443 for (j
= 0; j
< NCHCAP_COMBOS
; j
++)
1445 if(chcap_combos
[j
].count
== 0)
1455 cap
= chcap_combos
[j
].cap_yes
;
1456 nocap
= chcap_combos
[j
].cap_no
;
1458 mbl
= preflen
= rb_sprintf(modebuf
, ":%s TMODE %ld %s ",
1459 use_id(source_p
), (long) chptr
->channelts
,
1462 /* loop the list of - modes we have */
1463 for (i
= 0; i
< mode_count
; i
++)
1465 /* if they dont support the cap we need, or they do support a cap they
1466 * cant have, then dont add it to the modebuf.. that way they wont see
1469 if((mode_changes
[i
].letter
== 0) ||
1470 ((cap
& mode_changes
[i
].caps
) != mode_changes
[i
].caps
)
1471 || ((nocap
& mode_changes
[i
].nocaps
) != mode_changes
[i
].nocaps
))
1474 if(!EmptyString(mode_changes
[i
].id
))
1475 arg
= mode_changes
[i
].id
;
1477 arg
= mode_changes
[i
].arg
;
1481 arglen
= strlen(arg
);
1483 /* dont even think about it! --fl */
1484 if(arglen
> MODEBUFLEN
- 5)
1488 /* if we're creeping past the buf size, we need to send it and make
1489 * another line for the other modes
1490 * XXX - this could give away server topology with uids being
1491 * different lengths, but not much we can do, except possibly break
1492 * them as if they were the longest of the nick or uid at all times,
1493 * which even then won't work as we don't always know the uid -A1kmm.
1495 if(arg
&& ((mc
== MAXMODEPARAMSSERV
) ||
1496 ((mbl
+ pbl
+ arglen
+ 4) > (BUFSIZE
- 3))))
1499 sendto_server(client_p
, chptr
, cap
, nocap
,
1500 "%s %s", modebuf
, parabuf
);
1511 if(dir
!= mode_changes
[i
].dir
)
1513 modebuf
[mbl
++] = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1514 dir
= mode_changes
[i
].dir
;
1517 modebuf
[mbl
++] = mode_changes
[i
].letter
;
1523 len
= rb_sprintf(pbuf
, "%s ", arg
);
1530 if(pbl
&& parabuf
[pbl
- 1] == ' ')
1531 parabuf
[pbl
- 1] = 0;
1534 sendto_server(client_p
, chptr
, cap
, nocap
, "%s %s", modebuf
, parabuf
);
1538 /* Check what we will forward to, without sending any notices to the user
1542 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
1548 if (IsNoForward(source_p
))
1553 chptr
= find_channel(chptr
->mode
.forward
);
1554 /* Can only forward to existing channels */
1557 /* Already on there, show original error message */
1558 if (IsMember(source_p
, chptr
))
1560 /* Juped. Sending a warning notice would be unfair */
1561 if (hash_find_resv(chptr
->chname
))
1563 /* Don't forward to +Q channel */
1564 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
1566 i
= can_join(source_p
, chptr
, key
);
1569 if (i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_CHANNELISFULL
)
1580 * inputs - pointer to client doing join 0
1582 * side effects - Use has decided to join 0. This is legacy
1583 * from the days when channels were numbers not names. *sigh*
1586 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
1588 struct membership
*msptr
;
1589 struct Channel
*chptr
= NULL
;
1592 /* Finish the flood grace period... */
1593 if(MyClient(source_p
) && !IsFloodDone(source_p
))
1594 flood_endgrace(source_p
);
1596 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
1598 while((ptr
= source_p
->user
->channel
.head
))
1600 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
1601 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1602 check_spambot_warning(source_p
, NULL
);
1605 chptr
= msptr
->chptr
;
1606 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
1608 source_p
->username
, source_p
->host
, chptr
->chname
);
1609 remove_user_from_channel(msptr
);
1614 check_channel_name_loc(struct Client
*source_p
, const char *name
)
1618 s_assert(name
!= NULL
);
1619 if(EmptyString(name
))
1622 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1624 for(p
= name
; *p
; ++p
)
1626 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
1632 for(p
= name
; *p
; ++p
)
1639 if(ConfigChannel
.only_ascii_channels
)
1641 for(p
= name
; *p
; ++p
)
1642 if(*p
< 33 || *p
> 126)
1650 void user_join(struct Client
* client_p
, struct Client
* source_p
, const char * channels
, const char * keys
)
1652 static char jbuf
[BUFSIZE
];
1653 struct Channel
*chptr
= NULL
;
1654 struct ConfItem
*aconf
;
1659 char *p
= NULL
, *p2
= NULL
;
1665 if(channels
== NULL
)
1668 /* rebuild the list of channels theyre supposed to be joining.
1669 * this code has a side effect of losing keys, but..
1671 chanlist
= LOCAL_COPY(channels
);
1672 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
1674 /* check the length and name of channel is ok */
1675 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
1677 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1678 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
1682 /* join 0 parts all channels */
1683 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
1685 (void) strcpy(jbuf
, "0");
1689 /* check it begins with # or &, and local chans are disabled */
1690 else if(!IsChannelName(name
) ||
1691 ( !ConfigChannel
.use_local_channels
&& name
[0] == '&'))
1693 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
1694 form_str(ERR_NOSUCHCHANNEL
), name
);
1698 /* see if its resv'd */
1699 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
1701 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1702 form_str(ERR_BADCHANNAME
), name
);
1704 /* dont warn for opers */
1705 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
1706 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
1707 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
1708 source_p
->name
, source_p
->username
,
1709 source_p
->orighost
, name
, aconf
->passwd
);
1710 /* dont update tracking for jupe exempt users, these
1711 * are likely to be spamtrap leaves
1713 else if(IsExemptJupe(source_p
))
1719 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1720 ConfigChannel
.no_join_on_split
)
1722 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1723 me
.name
, source_p
->name
, name
);
1728 (void) strcat(jbuf
, ",");
1729 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
1734 mykey
= LOCAL_COPY(keys
);
1735 key
= rb_strtok_r(mykey
, ",", &p2
);
1738 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
1739 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
1741 hook_data_channel_activity hook_info
;
1743 /* JOIN 0 simply parts all channels the user is in */
1744 if(*name
== '0' && !atoi(name
))
1746 if(source_p
->user
->channel
.head
== NULL
)
1749 do_join_0(&me
, source_p
);
1753 /* look for the channel */
1754 if((chptr
= find_channel(name
)) != NULL
)
1756 if(IsMember(source_p
, chptr
))
1763 hook_data_client_approval moduledata
;
1765 moduledata
.client
= source_p
;
1766 moduledata
.approved
= 0;
1768 call_hook(h_can_create_channel
, &moduledata
);
1770 if(moduledata
.approved
!= 0)
1772 sendto_one(source_p
, form_str(moduledata
.approved
),
1773 me
.name
, source_p
->name
, name
);
1777 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1778 ConfigChannel
.no_create_on_split
)
1780 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1781 me
.name
, source_p
->name
, name
);
1785 flags
= CHFL_CHANOP
;
1788 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
1789 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
1790 (!IsOper(source_p
) ||
1791 (rb_dlink_list_length(&source_p
->user
->channel
) >=
1792 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
1794 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
1795 me
.name
, source_p
->name
, name
);
1799 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
1801 chptr
= get_or_create_channel(source_p
, name
, NULL
);
1805 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1806 me
.name
, source_p
->name
, name
);
1811 /* can_join checks for +i key, bans etc */
1812 if((i
= can_join(source_p
, chptr
, key
)))
1814 if ((i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_CHANNELISFULL
) ||
1815 (!ConfigChannel
.use_forward
|| (chptr
= check_forward(source_p
, chptr
, key
)) == NULL
))
1817 /* might be wrong, but is there any other better location for such?
1818 * see extensions/chm_operonly.c for other comments on this
1822 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
1827 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr
->chname
);
1831 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1832 check_spambot_warning(source_p
, name
);
1834 /* add the user to the channel */
1835 add_user_to_channel(chptr
, source_p
, flags
);
1836 if (chptr
->mode
.join_num
&&
1837 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
1839 chptr
->join_count
= 0;
1840 chptr
->join_delta
= rb_current_time();
1842 chptr
->join_count
++;
1844 /* we send the user their join here, because we could have to
1845 * send a mode out next.
1847 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1849 source_p
->username
, source_p
->host
, chptr
->chname
);
1851 /* its a new channel, set +nt and burst. */
1852 if(flags
& CHFL_CHANOP
)
1854 chptr
->channelts
= rb_current_time();
1856 /* autochanmodes stuff */
1857 if(ConfigChannel
.autochanmodes
)
1860 for(ch
= ConfigChannel
.autochanmodes
; *ch
; *ch
++)
1862 chptr
->mode
.mode
|= chmode_table
[*ch
].mode_type
;
1867 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
1868 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
1871 modes
= channel_modes(chptr
, &me
);
1873 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
1874 me
.name
, chptr
->chname
, modes
);
1876 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
1877 ":%s SJOIN %ld %s %s :@%s",
1878 me
.id
, (long) chptr
->channelts
,
1879 chptr
->chname
, modes
, source_p
->id
);
1883 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
1884 ":%s JOIN %ld %s +",
1885 use_id(source_p
), (long) chptr
->channelts
,
1889 del_invite(chptr
, source_p
);
1891 if(chptr
->topic
!= NULL
)
1893 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
1894 source_p
->name
, chptr
->chname
, chptr
->topic
);
1896 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
1897 me
.name
, source_p
->name
, chptr
->chname
,
1898 chptr
->topic_info
, chptr
->topic_time
);
1901 channel_member_names(chptr
, source_p
, 1);
1903 hook_info
.client
= source_p
;
1904 hook_info
.chptr
= chptr
;
1905 hook_info
.key
= key
;
1906 call_hook(h_channel_join
, &hook_info
);
1913 * channel_metadata_add
1915 * inputs - pointer to channel struct
1916 * - name of metadata item you wish to add
1917 * - value of metadata item
1918 * - 1 if metadata should be propegated, 0 if not
1920 * side effects - metadata is added to the channel in question
1921 * - metadata is propegated if propegate is set.
1924 channel_metadata_add(struct Channel
*target
, const char *name
, const char *value
, int propegate
)
1926 struct Metadata
*md
;
1928 md
= rb_malloc(sizeof(struct Metadata
));
1929 md
->name
= rb_strdup(name
);
1930 md
->value
= rb_strdup(value
);
1932 irc_dictionary_add(target
->metadata
, md
->name
, md
);
1935 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA ADD %s %s :%s",
1936 target
->chname
, name
, value
);
1942 * channel_metadata_time_add
1944 * inputs - pointer to channel struct
1945 * - name of metadata item you wish to add
1946 * - time_t you wish to add
1947 * - value you wish to add
1949 * side effects - metadata is added to the channel in question
1952 channel_metadata_time_add(struct Channel
*target
, const char *name
, time_t timevalue
, const char *value
)
1954 struct Metadata
*md
;
1956 md
= rb_malloc(sizeof(struct Metadata
));
1957 md
->name
= rb_strdup(name
);
1958 md
->value
= rb_strdup(value
);
1959 md
->timevalue
= timevalue
;
1961 irc_dictionary_add(target
->metadata
, md
->name
, md
);
1967 * channel_metadata_delete
1969 * inputs - pointer to channel struct
1970 * - name of metadata item you wish to delete
1972 * side effects - metadata is deleted from the channel in question
1973 * - deletion is propegated if propegate is set
1976 channel_metadata_delete(struct Channel
*target
, const char *name
, int propegate
)
1978 struct Metadata
*md
= channel_metadata_find(target
, name
);
1983 irc_dictionary_delete(target
->metadata
, md
->name
);
1988 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA DELETE %s %s",
1989 target
->chname
, name
);
1993 * channel_metadata_find
1995 * inputs - pointer to channel struct
1996 * - name of metadata item you wish to read
1997 * output - the requested metadata, if it exists, elsewise null.
2001 channel_metadata_find(struct Channel
*target
, const char *name
)
2006 if(!target
->metadata
)
2009 return irc_dictionary_retrieve(target
->metadata
, name
);
2013 * channel_metadata_clear
2015 * inputs - pointer to channel struct
2017 * side effects - metadata is cleared from the channel in question
2020 channel_metadata_clear(struct Channel
*chptr
)
2022 struct Metadata
*md
;
2023 struct DictionaryIter iter
;
2025 DICTIONARY_FOREACH(md
, &iter
, chptr
->metadata
)
2027 channel_metadata_delete(chptr
, md
->name
, 0);