2 * ircd-ratbox: A slightly useful ircd.
3 * channel.c: Controls channels.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
36 #include "s_serv.h" /* captab */
40 #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
41 #include "s_newconf.h"
44 #include "irc_dictionary.h"
46 struct config_channel_entry ConfigChannel
;
47 rb_dlink_list global_channel_list
;
48 static rb_bh
*channel_heap
;
49 static rb_bh
*ban_heap
;
50 static rb_bh
*topic_heap
;
51 static rb_bh
*member_heap
;
53 static int channel_capabs
[] = { CAP_EX
, CAP_IE
,
58 #define NCHCAPS (sizeof(channel_capabs)/sizeof(int))
59 #define NCHCAP_COMBOS (1 << NCHCAPS)
61 static struct ChCapCombo chcap_combos
[NCHCAP_COMBOS
];
63 static void free_topic(struct Channel
*chptr
);
65 static int h_can_join
;
66 static int h_can_create_channel
;
67 static int h_channel_join
;
69 struct module_modes ModuleModes
;
75 * side effects - initialises the various blockheaps
80 channel_heap
= rb_bh_create(sizeof(struct Channel
), CHANNEL_HEAP_SIZE
, "channel_heap");
81 ban_heap
= rb_bh_create(sizeof(struct Ban
), BAN_HEAP_SIZE
, "ban_heap");
82 topic_heap
= rb_bh_create(TOPICLEN
+ 1 + USERHOST_REPLYLEN
, TOPIC_HEAP_SIZE
, "topic_heap");
83 member_heap
= rb_bh_create(sizeof(struct membership
), MEMBER_HEAP_SIZE
, "member_heap");
85 h_can_join
= register_hook("can_join");
86 h_channel_join
= register_hook("channel_join");
87 h_can_create_channel
= register_hook("can_create_channel");
90 /* is this the best place to put this? */
91 /* init_module_modes()
95 * side effects - various MODE_ values are set to 0
100 ModuleModes
.MODE_REGONLY
= 0;
101 ModuleModes
.MODE_NOCTCP
= 0;
102 ModuleModes
.MODE_NOCOLOR
= 0;
103 ModuleModes
.MODE_EXLIMIT
= 0;
104 ModuleModes
.MODE_PERMANENT
= 0;
105 ModuleModes
.MODE_OPMODERATE
= 0;
106 ModuleModes
.MODE_FREEINVITE
= 0;
107 ModuleModes
.MODE_FREETARGET
= 0;
108 ModuleModes
.MODE_DISFORWARD
= 0;
109 ModuleModes
.MODE_THROTTLE
= 0;
110 ModuleModes
.MODE_FORWARD
= 0;
111 ModuleModes
.MODE_NONOTICE
= 0;
112 ModuleModes
.MODE_NOACTION
= 0;
113 ModuleModes
.MODE_NOKICK
= 0;
114 ModuleModes
.MODE_NONICK
= 0;
115 ModuleModes
.MODE_NOCAPS
= 0;
116 ModuleModes
.MODE_NOREJOIN
= 0;
117 ModuleModes
.MODE_NOREPEAT
= 0;
118 ModuleModes
.MODE_NOOPERKICK
= 0;
120 ModuleModes
.CHFL_QUIET
= 0;
125 * allocate_channel - Allocates a channel
128 allocate_channel(const char *chname
)
130 struct Channel
*chptr
;
131 struct Dictionary
*metadata
;
132 chptr
= rb_bh_alloc(channel_heap
);
133 chptr
->chname
= rb_strdup(chname
);
135 metadata
= irc_dictionary_create(irccmp
);
136 chptr
->metadata
= metadata
;
141 free_channel(struct Channel
*chptr
)
143 channel_metadata_clear(chptr
);
144 rb_free(chptr
->chname
);
145 rb_free(chptr
->mode_lock
);
146 rb_bh_free(channel_heap
, chptr
);
150 allocate_ban(const char *banstr
, const char *who
)
153 bptr
= rb_bh_alloc(ban_heap
);
154 bptr
->banstr
= rb_strdup(banstr
);
155 bptr
->who
= rb_strdup(who
);
161 free_ban(struct Ban
*bptr
)
163 rb_free(bptr
->banstr
);
165 rb_bh_free(ban_heap
, bptr
);
169 /* find_channel_membership()
171 * input - channel to find them in, client to find
172 * output - membership of client in channel, else NULL
176 find_channel_membership(struct Channel
*chptr
, struct Client
*client_p
)
178 struct membership
*msptr
;
181 if(!IsClient(client_p
))
184 /* Pick the most efficient list to use to be nice to things like
185 * CHANSERV which could be in a large number of channels
187 if(rb_dlink_list_length(&chptr
->members
) < rb_dlink_list_length(&client_p
->user
->channel
))
189 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
193 if(msptr
->client_p
== client_p
)
199 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
203 if(msptr
->chptr
== chptr
)
211 /* find_channel_status()
213 * input - membership to get status for, whether we can combine flags
214 * output - flags of user on channel
218 find_channel_status(struct membership
*msptr
, int combine
)
220 static char buffer
[5];
255 * input - membership to check for halfops
256 * output - 1 if the user is halfopped, 0 if the user is not or halfop
262 is_halfop(struct membership
*msptr
)
264 if(!ConfigChannel
.use_halfop
)
266 if(is_chmode_h(msptr
))
274 * input - membership to check for admin
275 * output - 1 if the user is an admin, 0 if the user is not or admin
281 is_admin(struct membership
*msptr
)
283 if(!ConfigChannel
.use_admin
)
285 if(is_chmode_a(msptr
))
293 * input - membership to check for ops
294 * output - 1 if the user is op, halfop, or admin, 0 elsewise
298 is_any_op(struct membership
*msptr
)
300 if(is_chanop(msptr
) || is_halfop(msptr
) || is_admin(msptr
))
306 /* is_chanop_voiced()
308 * input - memebership to check for status
309 * output - 1 if the user is op, halfop, admin, or voice, 0 elsewise
313 is_chanop_voiced(struct membership
*msptr
)
315 if(is_chanop(msptr
) || is_voiced(msptr
) || is_halfop(msptr
) || is_admin(msptr
))
323 * input - two memeberships
324 * output - 1 if the first memebership can kick/deop the second, 0 elsewise
328 can_kick_deop(struct membership
*source
, struct membership
*target
)
330 if(is_chanop(source
) && !is_admin(target
))
332 else if(is_halfop(source
) && !is_any_op(target
))
334 else if(is_admin(source
))
340 /* add_user_to_channel()
342 * input - channel to add client to, client to add, channel flags
344 * side effects - user is added to channel
347 add_user_to_channel(struct Channel
*chptr
, struct Client
*client_p
, int flags
)
349 struct membership
*msptr
;
351 s_assert(client_p
->user
!= NULL
);
352 if(client_p
->user
== NULL
)
355 msptr
= rb_bh_alloc(member_heap
);
357 msptr
->chptr
= chptr
;
358 msptr
->client_p
= client_p
;
359 msptr
->flags
= flags
;
361 rb_dlinkAdd(msptr
, &msptr
->usernode
, &client_p
->user
->channel
);
362 rb_dlinkAdd(msptr
, &msptr
->channode
, &chptr
->members
);
364 if(MyClient(client_p
))
365 rb_dlinkAdd(msptr
, &msptr
->locchannode
, &chptr
->locmembers
);
368 /* remove_user_from_channel()
370 * input - membership pointer to remove from channel
372 * side effects - membership (thus user) is removed from channel
375 remove_user_from_channel(struct membership
*msptr
)
377 struct Client
*client_p
;
378 struct Channel
*chptr
;
379 s_assert(msptr
!= NULL
);
383 client_p
= msptr
->client_p
;
384 chptr
= msptr
->chptr
;
386 rb_dlinkDelete(&msptr
->usernode
, &client_p
->user
->channel
);
387 rb_dlinkDelete(&msptr
->channode
, &chptr
->members
);
389 if(client_p
->servptr
== &me
)
390 rb_dlinkDelete(&msptr
->locchannode
, &chptr
->locmembers
);
392 if(!(chptr
->mode
.mode
& ModuleModes
.MODE_PERMANENT
) && rb_dlink_list_length(&chptr
->members
) <= 0)
393 destroy_channel(chptr
);
395 rb_bh_free(member_heap
, msptr
);
400 /* remove_user_from_channels()
402 * input - user to remove from all channels
404 * side effects - user is removed from all channels
407 remove_user_from_channels(struct Client
*client_p
)
409 struct Channel
*chptr
;
410 struct membership
*msptr
;
412 rb_dlink_node
*next_ptr
;
417 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->user
->channel
.head
)
420 chptr
= msptr
->chptr
;
422 rb_dlinkDelete(&msptr
->channode
, &chptr
->members
);
424 if(client_p
->servptr
== &me
)
425 rb_dlinkDelete(&msptr
->locchannode
, &chptr
->locmembers
);
427 if(!(chptr
->mode
.mode
& ModuleModes
.MODE_PERMANENT
) && rb_dlink_list_length(&chptr
->members
) <= 0)
428 destroy_channel(chptr
);
430 rb_bh_free(member_heap
, msptr
);
433 client_p
->user
->channel
.head
= client_p
->user
->channel
.tail
= NULL
;
434 client_p
->user
->channel
.length
= 0;
437 /* invalidate_bancache_user()
439 * input - user to invalidate ban cache for
441 * side effects - ban cache is invalidated for all memberships of that user
442 * to be used after a nick change
445 invalidate_bancache_user(struct Client
*client_p
)
447 struct membership
*msptr
;
453 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
457 msptr
->flags
&= ~CHFL_BANNED
;
461 /* check_channel_name()
463 * input - channel name
464 * output - 1 if valid channel name, else 0
468 check_channel_name(const char *name
)
470 s_assert(name
!= NULL
);
474 for (; *name
; ++name
)
476 if(!IsChanChar(*name
))
483 /* free_channel_list()
485 * input - rb_dlink list to free
487 * side effects - list of b/e/I modes is cleared
490 free_channel_list(rb_dlink_list
* list
)
493 rb_dlink_node
*next_ptr
;
494 struct Ban
*actualBan
;
496 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
498 actualBan
= ptr
->data
;
502 list
->head
= list
->tail
= NULL
;
508 * input - channel to destroy
510 * side effects - channel is obliterated
513 destroy_channel(struct Channel
*chptr
)
515 rb_dlink_node
*ptr
, *next_ptr
;
517 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
519 del_invite(chptr
, ptr
->data
);
522 /* free all bans/exceptions/denies */
523 free_channel_list(&chptr
->banlist
);
524 free_channel_list(&chptr
->exceptlist
);
525 free_channel_list(&chptr
->invexlist
);
526 free_channel_list(&chptr
->quietlist
);
531 rb_dlinkDelete(&chptr
->node
, &global_channel_list
);
532 del_from_channel_hash(chptr
->chname
, chptr
);
536 /* channel_pub_or_secret()
539 * output - "=" if public, "@" if secret, else "*"
543 channel_pub_or_secret(struct Channel
*chptr
)
545 if(PubChannel(chptr
))
547 else if(SecretChannel(chptr
))
552 /* channel_member_names()
554 * input - channel to list, client to list to, show endofnames
556 * side effects - client is given list of users on channel
559 channel_member_names(struct Channel
*chptr
, struct Client
*client_p
, int show_eon
)
561 struct membership
*msptr
;
562 struct Client
*target_p
;
570 int stack
= IsCapable(client_p
, CLICAP_MULTI_PREFIX
);
572 if(ShowChannel(client_p
, chptr
))
574 is_member
= IsMember(client_p
, chptr
);
576 cur_len
= mlen
= rb_sprintf(lbuf
, form_str(RPL_NAMREPLY
),
577 me
.name
, client_p
->name
,
578 channel_pub_or_secret(chptr
), chptr
->chname
);
582 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
585 target_p
= msptr
->client_p
;
587 if(IsInvisible(target_p
) && !is_member
)
590 /* space, possible "@+" prefix */
591 if(cur_len
+ strlen(target_p
->name
) + 3 >= BUFSIZE
- 3)
594 sendto_one(client_p
, "%s", lbuf
);
599 tlen
= rb_sprintf(t
, "%s%s ", find_channel_status(msptr
, stack
),
606 /* The old behaviour here was to always output our buffer,
607 * even if there are no clients we can show. This happens
608 * when a client does "NAMES" with no parameters, and all
609 * the clients on a -sp channel are +i. I dont see a good
610 * reason for keeping that behaviour, as it just wastes
616 sendto_one(client_p
, "%s", lbuf
);
621 sendto_one(client_p
, form_str(RPL_ENDOFNAMES
),
622 me
.name
, client_p
->name
, chptr
->chname
);
627 * input - channel to remove invite from, client to remove
629 * side effects - user is removed from invite list, if exists
632 del_invite(struct Channel
*chptr
, struct Client
*who
)
634 rb_dlinkFindDestroy(who
, &chptr
->invites
);
635 rb_dlinkFindDestroy(chptr
, &who
->user
->invited
);
640 * input - channel to check bans for, user to check bans against
641 * optional prebuilt buffers
642 * output - 1 if banned, else 0
646 is_banned(struct Channel
*chptr
, struct Client
*who
, struct membership
*msptr
,
647 const char *s
, const char *s2
)
649 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
650 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
651 char src_althost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
654 struct Ban
*actualBan
= NULL
;
655 struct Ban
*actualExcept
= NULL
;
660 /* if the buffers havent been built, do it here */
663 rb_sprintf(src_host
, "%s!%s@%s", who
->name
, who
->username
, who
->host
);
664 rb_sprintf(src_iphost
, "%s!%s@%s", who
->name
, who
->username
, who
->sockhost
);
669 if(who
->localClient
->mangledhost
!= NULL
)
671 /* if host mangling mode enabled, also check their real host */
672 if(!strcmp(who
->host
, who
->localClient
->mangledhost
))
674 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->orighost
);
677 /* if host mangling mode not enabled and no other spoof,
678 * also check the mangled form of their host */
679 else if (!IsDynSpoof(who
))
681 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->localClient
->mangledhost
);
686 RB_DLINK_FOREACH(ptr
, chptr
->banlist
.head
)
688 actualBan
= ptr
->data
;
689 if(match(actualBan
->banstr
, s
) ||
690 match(actualBan
->banstr
, s2
) ||
691 match_cidr(actualBan
->banstr
, s2
) ||
692 match_extban(actualBan
->banstr
, who
, chptr
, CHFL_BAN
) ||
693 (s3
!= NULL
&& match(actualBan
->banstr
, s3
)))
699 if((actualBan
!= NULL
) && ConfigChannel
.use_except
)
701 RB_DLINK_FOREACH(ptr
, chptr
->exceptlist
.head
)
703 actualExcept
= ptr
->data
;
705 /* theyre exempted.. */
706 if(match(actualExcept
->banstr
, s
) ||
707 match(actualExcept
->banstr
, s2
) ||
708 match_cidr(actualExcept
->banstr
, s2
) ||
709 match_extban(actualExcept
->banstr
, who
, chptr
, CHFL_EXCEPTION
) ||
710 (s3
!= NULL
&& match(actualExcept
->banstr
, s3
)))
712 /* cache the fact theyre not banned */
715 msptr
->bants
= chptr
->bants
;
716 msptr
->flags
&= ~CHFL_BANNED
;
719 return CHFL_EXCEPTION
;
724 /* cache the banned/not banned status */
727 msptr
->bants
= chptr
->bants
;
729 if(actualBan
!= NULL
)
731 msptr
->flags
|= CHFL_BANNED
;
736 msptr
->flags
&= ~CHFL_BANNED
;
741 return ((actualBan
? CHFL_BAN
: 0));
746 * input - channel to check bans for, user to check bans against
747 * optional prebuilt buffers
748 * output - 1 if banned, else 0
752 is_quieted(struct Channel
*chptr
, struct Client
*who
, struct membership
*msptr
,
753 const char *s
, const char *s2
)
755 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
756 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
757 char src_althost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
760 struct Ban
*actualBan
= NULL
;
761 struct Ban
*actualExcept
= NULL
;
763 /* check to make sure quiets even exist on this server first */
764 if(ModuleModes
.CHFL_QUIET
== 0)
770 /* if the buffers havent been built, do it here */
773 rb_sprintf(src_host
, "%s!%s@%s", who
->name
, who
->username
, who
->host
);
774 rb_sprintf(src_iphost
, "%s!%s@%s", who
->name
, who
->username
, who
->sockhost
);
779 if(who
->localClient
->mangledhost
!= NULL
)
781 /* if host mangling mode enabled, also check their real host */
782 if(!strcmp(who
->host
, who
->localClient
->mangledhost
))
784 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->orighost
);
787 /* if host mangling mode not enabled and no other spoof,
788 * also check the mangled form of their host */
789 else if (!IsDynSpoof(who
))
791 rb_sprintf(src_althost
, "%s!%s@%s", who
->name
, who
->username
, who
->localClient
->mangledhost
);
796 RB_DLINK_FOREACH(ptr
, chptr
->quietlist
.head
)
798 actualBan
= ptr
->data
;
799 if(match(actualBan
->banstr
, s
) ||
800 match(actualBan
->banstr
, s2
) ||
801 match_cidr(actualBan
->banstr
, s2
) ||
802 match_extban(actualBan
->banstr
, who
, chptr
, ModuleModes
.CHFL_QUIET
) ||
803 (s3
!= NULL
&& match(actualBan
->banstr
, s3
)))
809 if((actualBan
!= NULL
) && ConfigChannel
.use_except
)
811 RB_DLINK_FOREACH(ptr
, chptr
->exceptlist
.head
)
813 actualExcept
= ptr
->data
;
815 /* theyre exempted.. */
816 if(match(actualExcept
->banstr
, s
) ||
817 match(actualExcept
->banstr
, s2
) ||
818 match_cidr(actualExcept
->banstr
, s2
) ||
819 match_extban(actualExcept
->banstr
, who
, chptr
, CHFL_EXCEPTION
) ||
820 (s3
!= NULL
&& match(actualExcept
->banstr
, s3
)))
822 /* cache the fact theyre not banned */
825 msptr
->bants
= chptr
->bants
;
826 msptr
->flags
&= ~CHFL_BANNED
;
829 return CHFL_EXCEPTION
;
834 /* cache the banned/not banned status */
837 msptr
->bants
= chptr
->bants
;
839 if(actualBan
!= NULL
)
841 msptr
->flags
|= CHFL_BANNED
;
846 msptr
->flags
&= ~CHFL_BANNED
;
851 return ((actualBan
? CHFL_BAN
: 0));
856 * input - client to check, channel to check for, key
857 * output - reason for not being able to join, else 0
861 can_join(struct Client
*source_p
, struct Channel
*chptr
, char *key
)
863 rb_dlink_node
*invite
= NULL
;
865 struct Ban
*invex
= NULL
;
866 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
867 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
868 char src_althost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
872 hook_data_channel moduledata
;
874 struct DictionaryIter iter
;
876 s_assert(source_p
->localClient
!= NULL
);
878 rb_sprintf(src_host
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->host
);
879 rb_sprintf(src_iphost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->sockhost
);
880 if(source_p
->localClient
->mangledhost
!= NULL
)
882 /* if host mangling mode enabled, also check their real host */
883 if(!strcmp(source_p
->host
, source_p
->localClient
->mangledhost
))
885 rb_sprintf(src_althost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->orighost
);
888 /* if host mangling mode not enabled and no other spoof,
889 * also check the mangled form of their host */
890 else if (!IsDynSpoof(source_p
))
892 rb_sprintf(src_althost
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->localClient
->mangledhost
);
897 if((is_banned(chptr
, source_p
, NULL
, src_host
, src_iphost
)) == CHFL_BAN
)
898 return (ERR_BANNEDFROMCHAN
);
900 rb_snprintf(text
, sizeof(text
), "K%s", source_p
->id
);
902 DICTIONARY_FOREACH(md
, &iter
, chptr
->metadata
)
904 if(!strcmp(md
->value
, "KICKNOREJOIN") && !strcmp(md
->name
, text
) && (md
->timevalue
+ 2 > rb_current_time()))
905 return ERR_KICKNOREJOIN
;
906 /* cleanup any stale KICKNOREJOIN metadata we find while we're at it */
907 if(!strcmp(md
->value
, "KICKNOREJOIN") && !(md
->timevalue
+ 2 > rb_current_time()))
908 channel_metadata_delete(chptr
, md
->name
, 0);
911 if(chptr
->mode
.mode
& MODE_INVITEONLY
)
913 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
915 if(invite
->data
== chptr
)
920 if(!ConfigChannel
.use_invex
)
921 return (ERR_INVITEONLYCHAN
);
922 RB_DLINK_FOREACH(ptr
, chptr
->invexlist
.head
)
925 if(match(invex
->banstr
, src_host
)
926 || match(invex
->banstr
, src_iphost
)
927 || match_cidr(invex
->banstr
, src_iphost
)
928 || match_extban(invex
->banstr
, source_p
, chptr
, CHFL_INVEX
)
929 || (use_althost
&& match(invex
->banstr
, src_althost
)))
933 return (ERR_INVITEONLYCHAN
);
937 if(*chptr
->mode
.key
&& (EmptyString(key
) || irccmp(chptr
->mode
.key
, key
)))
938 return (ERR_BADCHANNELKEY
);
940 if(chptr
->mode
.limit
&&
941 rb_dlink_list_length(&chptr
->members
) >= (unsigned long) chptr
->mode
.limit
)
942 i
= ERR_CHANNELISFULL
;
943 if(chptr
->mode
.mode
& ModuleModes
.MODE_REGONLY
&& EmptyString(source_p
->user
->suser
))
944 i
= ERR_NEEDREGGEDNICK
;
945 /* join throttling stuff --nenolod */
946 /* only check for throttles if they exist on this server --Taros */
947 else if(ModuleModes
.MODE_THROTTLE
)
949 if(chptr
->mode
.join_num
> 0 && chptr
->mode
.join_time
> 0)
951 if ((rb_current_time() - chptr
->join_delta
<=
952 chptr
->mode
.join_time
) && (chptr
->join_count
>=
953 chptr
->mode
.join_num
))
958 /* allow /invite to override +l/+r/+j also -- jilles */
959 if (i
!= 0 && invite
== NULL
)
961 RB_DLINK_FOREACH(invite
, source_p
->user
->invited
.head
)
963 if(invite
->data
== chptr
)
970 moduledata
.client
= source_p
;
971 moduledata
.chptr
= chptr
;
972 moduledata
.approved
= 0;
974 call_hook(h_can_join
, &moduledata
);
976 return moduledata
.approved
;
981 * input - user to check in channel, membership pointer
982 * output - whether can explicitly send or not, else CAN_SEND_NONOP
986 can_send(struct Channel
*chptr
, struct Client
*source_p
, struct membership
*msptr
)
988 if(IsServer(source_p
) || IsService(source_p
))
991 if(MyClient(source_p
) && hash_find_resv(chptr
->chname
) &&
992 !IsOper(source_p
) && !IsExemptResv(source_p
))
997 msptr
= find_channel_membership(chptr
, source_p
);
1001 /* if its +m or +n and theyre not in the channel,
1002 * they cant send. we dont check bans here because
1003 * theres no possibility of caching them --fl
1005 if(chptr
->mode
.mode
& MODE_NOPRIVMSGS
|| chptr
->mode
.mode
& MODE_MODERATED
)
1008 return CAN_SEND_NONOP
;
1012 if(is_chanop_voiced(msptr
))
1013 return CAN_SEND_OPV
;
1015 if(chptr
->mode
.mode
& MODE_MODERATED
)
1018 if(MyClient(source_p
))
1020 /* cached can_send */
1021 if(msptr
->bants
== chptr
->bants
)
1023 if(can_send_banned(msptr
))
1026 else if(is_banned(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
1027 || is_quieted(chptr
, source_p
, msptr
, NULL
, NULL
) == CHFL_BAN
)
1031 return CAN_SEND_NONOP
;
1034 /* find_bannickchange_channel()
1035 * Input: client to check
1036 * Output: channel preventing nick change
1039 find_bannickchange_channel(struct Client
*client_p
)
1041 struct Channel
*chptr
;
1042 struct membership
*msptr
;
1044 char src_host
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
1045 char src_iphost
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 6];
1047 if (!MyClient(client_p
) || IsOverride(client_p
))
1050 rb_sprintf(src_host
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->host
);
1051 rb_sprintf(src_iphost
, "%s!%s@%s", client_p
->name
, client_p
->username
, client_p
->sockhost
);
1053 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1056 chptr
= msptr
->chptr
;
1057 if (is_chanop_voiced(msptr
))
1059 /* cached can_send */
1060 if (msptr
->bants
== chptr
->bants
)
1062 if (can_send_banned(msptr
))
1065 else if (is_banned(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
1066 || is_quieted(chptr
, client_p
, msptr
, src_host
, src_iphost
) == CHFL_BAN
)
1072 /* find_nonickchange_channel()
1073 * Input: client to check
1074 * Output: channel preventing nick change
1077 find_nonickchange_channel(struct Client
*client_p
)
1079 struct Channel
*chptr
;
1080 struct membership
*msptr
;
1083 if (!MyClient(client_p
))
1086 RB_DLINK_FOREACH(ptr
, client_p
->user
->channel
.head
)
1089 chptr
= msptr
->chptr
;
1090 if (chptr
->mode
.mode
& ModuleModes
.MODE_NONICK
&& (!ConfigChannel
.exempt_cmode_N
|| !is_any_op(msptr
)))
1096 /* void check_spambot_warning(struct Client *source_p)
1097 * Input: Client to check, channel name or NULL if this is a part.
1099 * Side-effects: Updates the client's oper_warn_count_down, warns the
1100 * IRC operators if necessary, and updates join_leave_countdown as
1104 check_spambot_warning(struct Client
*source_p
, const char *name
)
1107 int decrement_count
;
1108 if((GlobalSetOptions
.spam_num
&&
1109 (source_p
->localClient
->join_leave_count
>= GlobalSetOptions
.spam_num
)))
1111 if(source_p
->localClient
->oper_warn_count_down
> 0)
1112 source_p
->localClient
->oper_warn_count_down
--;
1114 source_p
->localClient
->oper_warn_count_down
= 0;
1115 if(source_p
->localClient
->oper_warn_count_down
== 0 &&
1118 /* Its already known as a possible spambot */
1119 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
1120 "User %s (%s@%s) trying to join %s is a possible spambot",
1122 source_p
->username
, source_p
->orighost
, name
);
1123 source_p
->localClient
->oper_warn_count_down
= OPER_SPAM_COUNTDOWN
;
1129 (rb_current_time() - source_p
->localClient
->last_leave_time
)) >
1130 JOIN_LEAVE_COUNT_EXPIRE_TIME
)
1132 decrement_count
= (t_delta
/ JOIN_LEAVE_COUNT_EXPIRE_TIME
);
1135 else if(decrement_count
> source_p
->localClient
->join_leave_count
)
1136 source_p
->localClient
->join_leave_count
= 0;
1138 source_p
->localClient
->join_leave_count
-= decrement_count
;
1142 if((rb_current_time() -
1143 (source_p
->localClient
->last_join_time
)) < GlobalSetOptions
.spam_time
)
1145 /* oh, its a possible spambot */
1146 source_p
->localClient
->join_leave_count
++;
1150 source_p
->localClient
->last_join_time
= rb_current_time();
1152 source_p
->localClient
->last_leave_time
= rb_current_time();
1156 /* check_splitmode()
1160 * side effects - compares usercount and servercount against their split
1161 * values and adjusts splitmode accordingly
1164 check_splitmode(void *unused
)
1166 if(splitchecking
&& (ConfigChannel
.no_join_on_split
|| ConfigChannel
.no_create_on_split
))
1168 /* not split, we're being asked to check now because someone
1173 if(eob_count
< split_servers
|| Count
.total
< split_users
)
1176 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1177 "Network split, activating splitmode");
1178 check_splitmode_ev
= rb_event_addish("check_splitmode", check_splitmode
, NULL
, 2);
1181 /* in splitmode, check whether its finished */
1182 else if(eob_count
>= split_servers
&& Count
.total
>= split_users
)
1186 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1187 "Network rejoined, deactivating splitmode");
1189 rb_event_delete(check_splitmode_ev
);
1190 check_splitmode_ev
= NULL
;
1198 * input - channel to allocate topic for
1199 * output - 1 on success, else 0
1200 * side effects - channel gets a topic allocated
1203 allocate_topic(struct Channel
*chptr
)
1210 ptr
= rb_bh_alloc(topic_heap
);
1212 /* Basically we allocate one large block for the topic and
1213 * the topic info. We then split it up into two and shove it
1217 chptr
->topic_info
= (char *) ptr
+ TOPICLEN
+ 1;
1218 *chptr
->topic
= '\0';
1219 *chptr
->topic_info
= '\0';
1224 * input - channel which has topic to free
1226 * side effects - channels topic is free'd
1229 free_topic(struct Channel
*chptr
)
1233 if(chptr
== NULL
|| chptr
->topic
== NULL
)
1236 /* This is safe for now - If you change allocate_topic you
1237 * MUST change this as well
1240 rb_bh_free(topic_heap
, ptr
);
1241 chptr
->topic
= NULL
;
1242 chptr
->topic_info
= NULL
;
1245 /* set_channel_topic()
1247 * input - channel, topic to set, topic info and topic ts
1249 * side effects - channels topic, topic info and TS are set.
1252 set_channel_topic(struct Channel
*chptr
, const char *topic
, const char *topic_info
, time_t topicts
)
1254 if(strlen(topic
) > 0)
1256 if(chptr
->topic
== NULL
)
1257 allocate_topic(chptr
);
1258 rb_strlcpy(chptr
->topic
, topic
, TOPICLEN
+ 1);
1259 rb_strlcpy(chptr
->topic_info
, topic_info
, USERHOST_REPLYLEN
);
1260 chptr
->topic_time
= topicts
;
1264 if(chptr
->topic
!= NULL
)
1266 chptr
->topic_time
= 0;
1270 /* has_common_channel()
1272 * input - pointer to client
1273 * - pointer to another client
1274 * output - 1 if the two have a channel in common, 0 elsewise
1275 * side effects - none
1278 has_common_channel(struct Client
*client1
, struct Client
*client2
)
1282 RB_DLINK_FOREACH(ptr
, client1
->user
->channel
.head
)
1284 if(IsMember(client2
, ((struct membership
*)ptr
->data
)->chptr
))
1292 * inputs - pointer to channel
1293 * - pointer to client
1294 * output - string with simple modes
1295 * side effects - result from previous calls overwritten
1297 * Stolen from ShadowIRCd 4 --nenolod
1300 channel_modes(struct Channel
*chptr
, struct Client
*client_p
)
1305 static char final
[BUFSIZE
];
1312 for (i
= 0; i
< 256; i
++)
1314 if(chmode_table
[i
].set_func
== chm_hidden
&& !IsOper(client_p
) && IsClient(client_p
))
1316 if(chptr
->mode
.mode
& chmode_flags
[i
])
1320 if(chptr
->mode
.limit
)
1324 if(!IsClient(client_p
) || IsMember(client_p
, chptr
))
1325 pbuf
+= rb_sprintf(pbuf
, " %d", chptr
->mode
.limit
);
1328 if(*chptr
->mode
.key
)
1332 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1333 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.key
);
1336 if(chptr
->mode
.join_num
)
1340 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1341 pbuf
+= rb_sprintf(pbuf
, " %d:%d", chptr
->mode
.join_num
,
1342 chptr
->mode
.join_time
);
1345 if(*chptr
->mode
.forward
&& (ModuleModes
.MODE_FORWARD
|| !IsClient(client_p
)))
1349 if(pbuf
> buf2
|| !IsClient(client_p
) || IsMember(client_p
, chptr
))
1350 pbuf
+= rb_sprintf(pbuf
, " %s", chptr
->mode
.forward
);
1355 rb_strlcpy(final
, buf1
, sizeof final
);
1356 rb_strlcat(final
, buf2
, sizeof final
);
1360 /* Now lets do some stuff to keep track of what combinations of
1362 * Note that the number of combinations doubles each time you add
1363 * something to this list. Each one is only quick if no servers use that
1364 * combination, but if the numbers get too high here MODE will get too
1365 * slow. I suggest if you get more than 7 here, you consider getting rid
1366 * of some and merging or something. If it wasn't for irc+cs we would
1367 * probably not even need to bother about most of these, but unfortunately
1371 /* void init_chcap_usage_counts(void)
1375 * Side-effects - Initialises the usage counts to zero. Fills in the
1376 * chcap_yes and chcap_no combination tables.
1379 init_chcap_usage_counts(void)
1381 unsigned long m
, c
, y
, n
;
1383 memset(chcap_combos
, 0, sizeof(chcap_combos
));
1385 /* For every possible combination */
1386 for (m
= 0; m
< NCHCAP_COMBOS
; m
++)
1388 /* Check each capab */
1389 for (c
= y
= n
= 0; c
< NCHCAPS
; c
++)
1391 if((m
& (1 << c
)) == 0)
1392 n
|= channel_capabs
[c
];
1394 y
|= channel_capabs
[c
];
1396 chcap_combos
[m
].cap_yes
= y
;
1397 chcap_combos
[m
].cap_no
= n
;
1401 /* void set_chcap_usage_counts(struct Client *serv_p)
1402 * Input: serv_p; The client whose capabs to register.
1404 * Side-effects: Increments the usage counts for the correct capab
1408 set_chcap_usage_counts(struct Client
*serv_p
)
1412 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1414 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1415 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1417 chcap_combos
[n
].count
++;
1422 /* This should be impossible -A1kmm. */
1426 /* void set_chcap_usage_counts(struct Client *serv_p)
1428 * Inputs - serv_p; The client whose capabs to register.
1430 * Side-effects - Decrements the usage counts for the correct capab
1434 unset_chcap_usage_counts(struct Client
*serv_p
)
1438 for (n
= 0; n
< NCHCAP_COMBOS
; n
++)
1440 if(IsCapable(serv_p
, chcap_combos
[n
].cap_yes
) &&
1441 NotCapable(serv_p
, chcap_combos
[n
].cap_no
))
1443 /* Hopefully capabs can't change dynamically or anything... */
1444 s_assert(chcap_combos
[n
].count
> 0);
1446 if(chcap_combos
[n
].count
> 0)
1447 chcap_combos
[n
].count
--;
1452 /* This should be impossible -A1kmm. */
1456 /* void send_cap_mode_changes(struct Client *client_p,
1457 * struct Client *source_p,
1458 * struct Channel *chptr, int cap, int nocap)
1459 * Input: The client sending(client_p), the source client(source_p),
1460 * the channel to send mode changes for(chptr)
1462 * Side-effects: Sends the appropriate mode changes to capable servers.
1464 * Reverted back to my original design, except that we now keep a count
1465 * of the number of servers which each combination as an optimisation, so
1466 * the capabs combinations which are not needed are not worked out. -A1kmm
1469 send_cap_mode_changes(struct Client
*client_p
, struct Client
*source_p
,
1470 struct Channel
*chptr
, struct ChModeChange mode_changes
[], int mode_count
)
1472 static char modebuf
[BUFSIZE
];
1473 static char parabuf
[BUFSIZE
];
1474 int i
, mbl
, pbl
, nc
, mc
, preflen
, len
;
1483 /* Now send to servers... */
1484 for (j
= 0; j
< NCHCAP_COMBOS
; j
++)
1486 if(chcap_combos
[j
].count
== 0)
1496 cap
= chcap_combos
[j
].cap_yes
;
1497 nocap
= chcap_combos
[j
].cap_no
;
1499 mbl
= preflen
= rb_sprintf(modebuf
, ":%s TMODE %ld %s ",
1500 use_id(source_p
), (long) chptr
->channelts
,
1503 /* loop the list of - modes we have */
1504 for (i
= 0; i
< mode_count
; i
++)
1506 /* if they dont support the cap we need, or they do support a cap they
1507 * cant have, then dont add it to the modebuf.. that way they wont see
1510 if((mode_changes
[i
].letter
== 0) ||
1511 ((cap
& mode_changes
[i
].caps
) != mode_changes
[i
].caps
)
1512 || ((nocap
& mode_changes
[i
].nocaps
) != mode_changes
[i
].nocaps
))
1515 if(!EmptyString(mode_changes
[i
].id
))
1516 arg
= mode_changes
[i
].id
;
1518 arg
= mode_changes
[i
].arg
;
1522 arglen
= strlen(arg
);
1524 /* dont even think about it! --fl */
1525 if(arglen
> MODEBUFLEN
- 5)
1529 /* if we're creeping past the buf size, we need to send it and make
1530 * another line for the other modes
1531 * XXX - this could give away server topology with uids being
1532 * different lengths, but not much we can do, except possibly break
1533 * them as if they were the longest of the nick or uid at all times,
1534 * which even then won't work as we don't always know the uid -A1kmm.
1536 if(arg
&& ((mc
== MAXMODEPARAMSSERV
) ||
1537 ((mbl
+ pbl
+ arglen
+ 4) > (BUFSIZE
- 3))))
1540 sendto_server(client_p
, chptr
, cap
, nocap
,
1541 "%s %s", modebuf
, parabuf
);
1552 if(dir
!= mode_changes
[i
].dir
)
1554 modebuf
[mbl
++] = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1555 dir
= mode_changes
[i
].dir
;
1558 modebuf
[mbl
++] = mode_changes
[i
].letter
;
1564 len
= rb_sprintf(pbuf
, "%s ", arg
);
1571 if(pbl
&& parabuf
[pbl
- 1] == ' ')
1572 parabuf
[pbl
- 1] = 0;
1575 sendto_server(client_p
, chptr
, cap
, nocap
, "%s %s", modebuf
, parabuf
);
1580 resv_chan_forcepart(const char *name
, const char *reason
, int temp_time
)
1583 rb_dlink_node
*next_ptr
;
1584 struct Channel
*chptr
;
1585 struct membership
*msptr
;
1586 struct Client
*target_p
;
1588 if(!ConfigChannel
.resv_forcepart
)
1591 /* for each user on our server in the channel list
1592 * send them a PART, and notify opers.
1594 chptr
= find_channel(name
);
1597 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
1600 target_p
= msptr
->client_p
;
1602 if(IsExemptResv(target_p
))
1605 sendto_server(target_p
, chptr
, CAP_TS6
, NOCAPS
,
1606 ":%s PART %s", target_p
->id
, chptr
->chname
);
1608 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s :%s",
1609 target_p
->name
, target_p
->username
,
1610 target_p
->host
, chptr
->chname
, target_p
->name
);
1612 remove_user_from_channel(msptr
);
1614 /* notify opers & user they were removed from the channel */
1615 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1616 "Forced PART for %s!%s@%s from %s (%s)",
1617 target_p
->name
, target_p
->username
,
1618 target_p
->host
, name
, reason
);
1621 sendto_one_notice(target_p
, ":*** Channel %s is temporarily unavailable on this server.",
1624 sendto_one_notice(target_p
, ":*** Channel %s is no longer available on this server.",
1630 /* Check what we will forward to, without sending any notices to the user
1634 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
1640 if (IsNoForward(source_p
))
1645 chptr
= find_channel(chptr
->mode
.forward
);
1646 /* Can only forward to existing channels */
1649 /* Already on there, show original error message */
1650 if (IsMember(source_p
, chptr
))
1652 /* Juped. Sending a warning notice would be unfair */
1653 if (hash_find_resv(chptr
->chname
))
1655 /* Don't forward to +Q channel */
1656 if (chptr
->mode
.mode
& ModuleModes
.MODE_DISFORWARD
)
1658 i
= can_join(source_p
, chptr
, key
);
1661 if (i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_CHANNELISFULL
)
1672 * inputs - pointer to client doing join 0
1674 * side effects - Use has decided to join 0. This is legacy
1675 * from the days when channels were numbers not names. *sigh*
1678 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
1680 struct membership
*msptr
;
1681 struct Channel
*chptr
= NULL
;
1684 /* Finish the flood grace period... */
1685 if(MyClient(source_p
) && !IsFloodDone(source_p
))
1686 flood_endgrace(source_p
);
1688 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
1690 while((ptr
= source_p
->user
->channel
.head
))
1692 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
1693 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1694 check_spambot_warning(source_p
, NULL
);
1697 chptr
= msptr
->chptr
;
1698 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
1700 source_p
->username
, source_p
->host
, chptr
->chname
);
1701 remove_user_from_channel(msptr
);
1706 check_channel_name_loc(struct Client
*source_p
, const char *name
)
1710 s_assert(name
!= NULL
);
1711 if(EmptyString(name
))
1714 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1716 for(p
= name
; *p
; ++p
)
1718 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
1724 for(p
= name
; *p
; ++p
)
1731 if(ConfigChannel
.only_ascii_channels
)
1733 for(p
= name
; *p
; ++p
)
1734 if(*p
< 33 || *p
> 126)
1742 void user_join(struct Client
* client_p
, struct Client
* source_p
, const char * channels
, const char * keys
)
1744 static char jbuf
[BUFSIZE
];
1745 struct Channel
*chptr
= NULL
;
1746 struct ConfItem
*aconf
;
1751 char *p
= NULL
, *p2
= NULL
;
1757 if(channels
== NULL
)
1760 /* rebuild the list of channels theyre supposed to be joining.
1761 * this code has a side effect of losing keys, but..
1763 chanlist
= LOCAL_COPY(channels
);
1764 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
1766 /* check the length and name of channel is ok */
1767 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
1769 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1770 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
1774 /* join 0 parts all channels */
1775 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
1777 (void) strcpy(jbuf
, "0");
1781 /* check it begins with # or &, and local chans are disabled */
1782 else if(!IsChannelName(name
) ||
1783 ( !ConfigChannel
.use_local_channels
&& name
[0] == '&'))
1785 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
1786 form_str(ERR_NOSUCHCHANNEL
), name
);
1790 /* see if its resv'd */
1791 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
1793 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1794 form_str(ERR_BADCHANNAME
), name
);
1796 /* dont warn for opers */
1797 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
1798 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
1799 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
1800 source_p
->name
, source_p
->username
,
1801 source_p
->orighost
, name
, aconf
->passwd
);
1802 /* dont update tracking for jupe exempt users, these
1803 * are likely to be spamtrap leaves
1805 else if(IsExemptJupe(source_p
))
1811 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1812 ConfigChannel
.no_join_on_split
)
1814 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1815 me
.name
, source_p
->name
, name
);
1820 (void) strcat(jbuf
, ",");
1821 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
1826 mykey
= LOCAL_COPY(keys
);
1827 key
= rb_strtok_r(mykey
, ",", &p2
);
1830 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
1831 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
1833 hook_data_channel_activity hook_info
;
1835 /* JOIN 0 simply parts all channels the user is in */
1836 if(*name
== '0' && !atoi(name
))
1838 if(source_p
->user
->channel
.head
== NULL
)
1841 do_join_0(&me
, source_p
);
1845 /* look for the channel */
1846 if((chptr
= find_channel(name
)) != NULL
)
1848 if(IsMember(source_p
, chptr
))
1855 hook_data_client_approval moduledata
;
1857 moduledata
.client
= source_p
;
1858 moduledata
.approved
= 0;
1860 call_hook(h_can_create_channel
, &moduledata
);
1862 if(moduledata
.approved
!= 0)
1864 sendto_one(source_p
, form_str(moduledata
.approved
),
1865 me
.name
, source_p
->name
, name
);
1869 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
1870 ConfigChannel
.no_create_on_split
)
1872 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1873 me
.name
, source_p
->name
, name
);
1877 if(ConfigChannel
.admin_on_channel_create
&& ConfigChannel
.use_admin
)
1878 flags
= CHFL_ADMIN
| CHFL_CHANOP
;
1880 flags
= CHFL_CHANOP
;
1883 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
1884 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
1885 (!IsOper(source_p
) ||
1886 (rb_dlink_list_length(&source_p
->user
->channel
) >=
1887 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
1889 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
1890 me
.name
, source_p
->name
, name
);
1894 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
1896 chptr
= get_or_create_channel(source_p
, name
, NULL
);
1900 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
1901 me
.name
, source_p
->name
, name
);
1906 /* can_join checks for +i key, bans etc */
1907 if((i
= can_join(source_p
, chptr
, key
)))
1909 if(IsOverride(source_p
))
1911 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1912 "%s is overriding JOIN to [%s]",
1913 get_oper_name(source_p
), chptr
->chname
);
1914 sendto_server(NULL
, chptr
, NOCAPS
, NOCAPS
,
1915 ":%s WALLOPS :%s is overriding JOIN to [%s]",
1916 me
.name
, get_oper_name(source_p
), chptr
->chname
);
1918 else if ((i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_CHANNELISFULL
) ||
1919 (!ModuleModes
.MODE_FORWARD
|| (chptr
= check_forward(source_p
, chptr
, key
)) == NULL
))
1921 /* might be wrong, but is there any other better location for such?
1922 * see extensions/chm_operonly.c for other comments on this
1926 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
1931 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr
->chname
);
1935 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1936 check_spambot_warning(source_p
, name
);
1938 /* add the user to the channel */
1939 add_user_to_channel(chptr
, source_p
, flags
);
1940 if (chptr
->mode
.join_num
&&
1941 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
1943 chptr
->join_count
= 0;
1944 chptr
->join_delta
= rb_current_time();
1946 chptr
->join_count
++;
1948 /* we send the user their join here, because we could have to
1949 * send a mode out next.
1951 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1953 source_p
->username
, source_p
->host
, chptr
->chname
);
1955 /* its a new channel, set +nt and burst. */
1956 if(flags
& CHFL_CHANOP
)
1958 chptr
->channelts
= rb_current_time();
1960 /* autochanmodes stuff */
1961 if(ConfigChannel
.autochanmodes
)
1964 for(ch
= ConfigChannel
.autochanmodes
; *ch
; *ch
++)
1966 chptr
->mode
.mode
|= chmode_table
[*ch
].mode_type
;
1971 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
1972 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
1975 modes
= channel_modes(chptr
, &me
);
1977 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
1978 me
.name
, chptr
->chname
, modes
);
1980 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
1981 ":%s SJOIN %ld %s %s :@%s",
1982 me
.id
, (long) chptr
->channelts
,
1983 chptr
->chname
, modes
, source_p
->id
);
1987 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
1988 ":%s JOIN %ld %s +",
1989 use_id(source_p
), (long) chptr
->channelts
,
1993 del_invite(chptr
, source_p
);
1995 if(chptr
->topic
!= NULL
)
1997 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
1998 source_p
->name
, chptr
->chname
, chptr
->topic
);
2000 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
2001 me
.name
, source_p
->name
, chptr
->chname
,
2002 chptr
->topic_info
, chptr
->topic_time
);
2005 channel_member_names(chptr
, source_p
, 1);
2007 hook_info
.client
= source_p
;
2008 hook_info
.chptr
= chptr
;
2009 hook_info
.key
= key
;
2010 call_hook(h_channel_join
, &hook_info
);
2017 * channel_metadata_add
2019 * inputs - pointer to channel struct
2020 * - name of metadata item you wish to add
2021 * - value of metadata item
2022 * - 1 if metadata should be propegated, 0 if not
2024 * side effects - metadata is added to the channel in question
2025 * - metadata is propegated if propegate is set.
2028 channel_metadata_add(struct Channel
*target
, const char *name
, const char *value
, int propegate
)
2030 struct Metadata
*md
;
2032 md
= rb_malloc(sizeof(struct Metadata
));
2033 md
->name
= rb_strdup(name
);
2034 md
->value
= rb_strdup(value
);
2036 irc_dictionary_add(target
->metadata
, md
->name
, md
);
2039 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA ADD %s %s :%s",
2040 target
->chname
, name
, value
);
2046 * channel_metadata_time_add
2048 * inputs - pointer to channel struct
2049 * - name of metadata item you wish to add
2050 * - time_t you wish to add
2051 * - value you wish to add
2053 * side effects - metadata is added to the channel in question
2056 channel_metadata_time_add(struct Channel
*target
, const char *name
, time_t timevalue
, const char *value
)
2058 struct Metadata
*md
;
2060 md
= rb_malloc(sizeof(struct Metadata
));
2061 md
->name
= rb_strdup(name
);
2062 md
->value
= rb_strdup(value
);
2063 md
->timevalue
= timevalue
;
2065 irc_dictionary_add(target
->metadata
, md
->name
, md
);
2071 * channel_metadata_delete
2073 * inputs - pointer to channel struct
2074 * - name of metadata item you wish to delete
2076 * side effects - metadata is deleted from the channel in question
2077 * - deletion is propegated if propegate is set
2080 channel_metadata_delete(struct Channel
*target
, const char *name
, int propegate
)
2082 struct Metadata
*md
= channel_metadata_find(target
, name
);
2087 irc_dictionary_delete(target
->metadata
, md
->name
);
2092 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA DELETE %s %s",
2093 target
->chname
, name
);
2097 * channel_metadata_find
2099 * inputs - pointer to channel struct
2100 * - name of metadata item you wish to read
2101 * output - the requested metadata, if it exists, elsewise null.
2105 channel_metadata_find(struct Channel
*target
, const char *name
)
2110 if(!target
->metadata
)
2113 return irc_dictionary_retrieve(target
->metadata
, name
);
2117 * channel_metadata_clear
2119 * inputs - pointer to channel struct
2121 * side effects - metadata is cleared from the channel in question
2124 channel_metadata_clear(struct Channel
*chptr
)
2126 struct Metadata
*md
;
2127 struct DictionaryIter iter
;
2129 DICTIONARY_FOREACH(md
, &iter
, chptr
->metadata
)
2131 channel_metadata_delete(chptr
, md
->name
, 0);