2 * ircd-ratbox: A slightly useful ircd.
3 * m_join.c: Joins a channel.
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: m_join.c 3494 2007-05-27 13:07:27Z jilles $
38 #include "s_newconf.h"
44 #include "ratelimit.h"
46 static int m_join(struct Client
*, struct Client
*, int, const char **);
47 static int ms_join(struct Client
*, struct Client
*, int, const char **);
48 static int ms_sjoin(struct Client
*, struct Client
*, int, const char **);
50 static int h_can_create_channel
;
51 static int h_channel_join
;
53 struct Message join_msgtab
= {
54 "JOIN", 0, 0, 0, MFLG_SLOW
,
55 {mg_unreg
, {m_join
, 2}, {ms_join
, 2}, mg_ignore
, mg_ignore
, {m_join
, 2}}
58 struct Message sjoin_msgtab
= {
59 "SJOIN", 0, 0, 0, MFLG_SLOW
,
60 {mg_unreg
, mg_ignore
, mg_ignore
, {ms_sjoin
, 4}, mg_ignore
, mg_ignore
}
63 mapi_clist_av1 join_clist
[] = { &join_msgtab
, &sjoin_msgtab
, NULL
};
65 mapi_hlist_av1 join_hlist
[] = {
66 { "can_create_channel", &h_can_create_channel
},
67 { "channel_join", &h_channel_join
},
71 DECLARE_MODULE_AV1(join
, NULL
, NULL
, join_clist
, join_hlist
, NULL
, "$Revision: 3494 $");
73 static void do_join_0(struct Client
*client_p
, struct Client
*source_p
);
74 static int check_channel_name_loc(struct Client
*source_p
, const char *name
);
76 static void set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
);
77 static void remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
);
79 static void remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
80 rb_dlink_list
* list
, char c
, int mems
);
82 static char modebuf
[MODEBUFLEN
];
83 static char parabuf
[MODEBUFLEN
];
84 static const char *para
[MAXMODEPARAMS
];
88 /* Check what we will forward to, without sending any notices to the user
91 static struct Channel
*
92 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
96 const char *next
= NULL
;
98 /* The caller (m_join) is only interested in the reason
99 * for the original channel.
101 if ((*err
= can_join(source_p
, chptr
, key
, &next
)) == 0)
104 /* User is +Q, or forwarding disabled */
105 if (IsNoForward(source_p
) || !ConfigChannel
.use_forward
)
112 chptr
= find_channel(next
);
113 /* Can only forward to existing channels */
116 /* Already on there, show original error message */
117 if (IsMember(source_p
, chptr
))
119 /* Juped. Sending a warning notice would be unfair */
120 if (hash_find_resv(chptr
->chname
))
122 /* Don't forward to +Q channel */
123 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
125 i
= can_join(source_p
, chptr
, key
, &next
);
137 * parv[2] = channel password (key)
140 m_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
142 static char jbuf
[BUFSIZE
];
143 struct Channel
*chptr
= NULL
, *chptr2
= NULL
;
144 struct ConfItem
*aconf
;
149 char *p
= NULL
, *p2
= NULL
;
155 /* rebuild the list of channels theyre supposed to be joining.
156 * this code has a side effect of losing keys, but..
158 chanlist
= LOCAL_COPY(parv
[1]);
159 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
161 /* check the length and name of channel is ok */
162 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
164 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
165 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
169 /* join 0 parts all channels */
170 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
172 (void) strcpy(jbuf
, "0");
176 /* check it begins with # or &, and local chans are disabled */
177 else if(!IsChannelName(name
) ||
178 ( ConfigChannel
.disable_local_channels
&& name
[0] == '&'))
180 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
181 form_str(ERR_NOSUCHCHANNEL
), name
);
185 /* see if its resv'd */
186 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
188 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
189 form_str(ERR_BADCHANNAME
), name
);
191 /* dont warn for opers */
192 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
193 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
194 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
195 source_p
->name
, source_p
->username
,
196 source_p
->orighost
, name
, aconf
->passwd
);
197 /* dont update tracking for jupe exempt users, these
198 * are likely to be spamtrap leaves
200 else if(IsExemptJupe(source_p
))
206 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
207 ConfigChannel
.no_join_on_split
)
209 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
210 me
.name
, source_p
->name
, name
);
215 (void) strcat(jbuf
, ",");
216 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
221 mykey
= LOCAL_COPY(parv
[2]);
222 key
= rb_strtok_r(mykey
, ",", &p2
);
225 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
226 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
228 hook_data_channel_activity hook_info
;
230 /* JOIN 0 simply parts all channels the user is in */
231 if(*name
== '0' && !atoi(name
))
233 if(source_p
->user
->channel
.head
== NULL
)
236 do_join_0(&me
, source_p
);
240 /* look for the channel */
241 if((chptr
= find_channel(name
)) != NULL
)
243 if(IsMember(source_p
, chptr
))
250 hook_data_client_approval moduledata
;
252 moduledata
.client
= source_p
;
253 moduledata
.approved
= 0;
255 call_hook(h_can_create_channel
, &moduledata
);
257 if(moduledata
.approved
!= 0)
260 sendto_one(source_p
, form_str(moduledata
.approved
),
261 me
.name
, source_p
->name
, name
);
266 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
267 ConfigChannel
.no_create_on_split
)
269 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
270 me
.name
, source_p
->name
, name
);
277 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
278 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
279 (!IsOper(source_p
) ||
280 (rb_dlink_list_length(&source_p
->user
->channel
) >=
281 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
283 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
284 me
.name
, source_p
->name
, name
);
288 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
290 chptr
= get_or_create_channel(source_p
, name
, NULL
);
294 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
295 me
.name
, source_p
->name
, name
);
300 /* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */
301 if(!(chptr2
= check_forward(source_p
, chptr
, key
, &i
)))
303 /* might be wrong, but is there any other better location for such?
304 * see extensions/chm_operonly.c for other comments on this
309 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
313 else if(chptr
!= chptr2
)
314 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr2
->chname
);
319 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
320 check_spambot_warning(source_p
, name
);
322 /* add the user to the channel */
323 add_user_to_channel(chptr
, source_p
, flags
);
324 if (chptr
->mode
.join_num
&&
325 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
327 chptr
->join_count
= 0;
328 chptr
->join_delta
= rb_current_time();
332 /* credit user for join */
333 credit_client_join(source_p
);
335 /* we send the user their join here, because we could have to
336 * send a mode out next.
338 send_channel_join(chptr
, source_p
);
340 /* its a new channel, set +nt and burst. */
341 if(flags
& CHFL_CHANOP
)
343 chptr
->channelts
= rb_current_time();
344 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
345 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
346 modes
= channel_modes(chptr
, &me
);
348 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
349 me
.name
, chptr
->chname
, modes
);
351 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
352 ":%s SJOIN %ld %s %s :@%s",
353 me
.id
, (long) chptr
->channelts
,
354 chptr
->chname
, modes
, source_p
->id
);
358 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
360 use_id(source_p
), (long) chptr
->channelts
,
364 del_invite(chptr
, source_p
);
366 if(chptr
->topic
!= NULL
)
368 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
369 source_p
->name
, chptr
->chname
, chptr
->topic
);
371 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
372 me
.name
, source_p
->name
, chptr
->chname
,
374 (unsigned long)chptr
->topic_time
);
377 channel_member_names(chptr
, source_p
, 1);
379 hook_info
.client
= source_p
;
380 hook_info
.chptr
= chptr
;
382 call_hook(h_channel_join
, &hook_info
);
390 * parv[1] = channel TS
392 * parv[3] = "+", formerly channel modes but now unused
393 * alternatively, a single "0" parameter parts all channels
396 ms_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
398 struct Channel
*chptr
;
399 static struct Mode mode
;
403 int keep_our_modes
= YES
;
404 rb_dlink_node
*ptr
, *next_ptr
;
406 /* special case for join 0 */
407 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
409 do_join_0(client_p
, source_p
);
416 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
419 /* joins for local channels cant happen. */
420 if(parv
[2][0] == '&')
424 mode
.key
[0] = mode
.forward
[0] = '\0';
425 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
427 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
430 newts
= atol(parv
[1]);
431 oldts
= chptr
->channelts
;
433 #ifdef IGNORE_BOGUS_TS
434 if(newts
< 800000000)
436 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
437 "*** Bogus TS %ld on %s ignored from %s",
438 (long) newts
, chptr
->chname
, client_p
->name
);
439 newts
= (oldts
== 0) ? oldts
: 800000000;
442 /* making a channel TS0 */
443 if(!isnew
&& !newts
&& oldts
)
445 sendto_channel_local(ALL_MEMBERS
, chptr
,
446 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
447 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
448 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
449 "Server %s changing TS on %s from %ld to 0",
450 source_p
->name
, chptr
->chname
, (long) oldts
);
455 chptr
->channelts
= newts
;
456 else if(newts
== 0 || oldts
== 0)
457 chptr
->channelts
= 0;
458 else if(newts
== oldts
)
460 else if(newts
< oldts
)
463 chptr
->channelts
= newts
;
466 /* Lost the TS, other side wins, so remove modes on this side */
469 set_final_mode(&mode
, &chptr
->mode
);
471 remove_our_modes(chptr
, source_p
);
472 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
474 del_invite(chptr
, ptr
->data
);
476 /* If setting -j, clear join throttle state -- jilles */
477 chptr
->join_count
= chptr
->join_delta
= 0;
478 sendto_channel_local(ALL_MEMBERS
, chptr
,
479 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
480 me
.name
, chptr
->chname
, chptr
->chname
,
481 (long) oldts
, (long) newts
);
482 /* Update capitalization in channel name, this makes the
483 * capitalization timestamped like modes are -- jilles */
484 strcpy(chptr
->chname
, parv
[2]);
486 sendto_channel_local(ALL_MEMBERS
, chptr
,
488 source_p
->servptr
->name
,
489 chptr
->chname
, modebuf
, parabuf
);
490 *modebuf
= *parabuf
= '\0';
492 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
493 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, FALSE
);
496 if(!IsMember(source_p
, chptr
))
498 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
499 if (chptr
->mode
.join_num
&&
500 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
502 chptr
->join_count
= 0;
503 chptr
->join_delta
= rb_current_time();
506 send_channel_join(chptr
, source_p
);
509 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
511 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
516 ms_sjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
518 static char buf_uid
[BUFSIZE
];
519 static const char empty_modes
[] = "0";
520 struct Channel
*chptr
;
521 struct Client
*target_p
, *fakesource_p
;
524 static struct Mode mode
, *oldmode
;
527 int keep_our_modes
= 1;
528 int keep_new_modes
= 1;
539 int i
, joinc
= 0, timeslice
= 0;
540 static char empty
[] = "";
541 rb_dlink_node
*ptr
, *next_ptr
;
543 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
546 /* SJOIN's for local channels can't happen. */
550 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
551 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
553 /* Hide connecting server on netburst -- jilles */
554 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
557 fakesource_p
= source_p
;
560 newts
= atol(parv
[1]);
568 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
574 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
576 mode
.join_num
= joinc
;
577 mode
.join_time
= timeslice
;
582 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
588 mode
.limit
= atoi(parv
[4 + args
]);
594 if(chmode_flags
[(int) *s
] != 0)
596 mode
.mode
|= chmode_flags
[(int) *s
];
605 /* remove any leading spaces */
612 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
613 return 0; /* channel name too long? */
616 oldts
= chptr
->channelts
;
617 oldmode
= &chptr
->mode
;
619 #ifdef IGNORE_BOGUS_TS
620 if(newts
< 800000000)
622 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
623 "*** Bogus TS %ld on %s ignored from %s",
624 (long) newts
, chptr
->chname
, client_p
->name
);
626 newts
= (oldts
== 0) ? oldts
: 800000000;
629 if(!isnew
&& !newts
&& oldts
)
631 sendto_channel_local(ALL_MEMBERS
, chptr
,
632 ":%s NOTICE %s :*** Notice -- TS for %s "
633 "changed from %ld to 0",
634 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
635 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
636 "Server %s changing TS on %s from %ld to 0",
637 source_p
->name
, chptr
->chname
, (long) oldts
);
642 chptr
->channelts
= newts
;
644 else if(newts
== 0 || oldts
== 0)
645 chptr
->channelts
= 0;
646 else if(newts
== oldts
)
648 else if(newts
< oldts
)
650 /* If configured, kick people trying to join +i/+k
651 * channels by recreating them on split servers.
652 * If the source has sent EOB, assume this is some
653 * sort of hack by services. If cmode +i is set,
654 * services can send kicks if needed; if the key
655 * differs, services cannot kick in a race-free
656 * manner so do so here.
658 if (ConfigChannel
.kick_on_split_riding
&&
659 ((!HasSentEob(source_p
) &&
660 mode
.mode
& MODE_INVITEONLY
) ||
661 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
663 struct membership
*msptr
;
665 int l
= rb_dlink_list_length(&chptr
->members
);
667 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
670 who
= msptr
->client_p
;
671 sendto_one(who
, ":%s KICK %s %s :Net Rider",
672 me
.name
, chptr
->chname
, who
->name
);
674 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
675 ":%s KICK %s %s :Net Rider",
676 me
.id
, chptr
->chname
,
678 remove_user_from_channel(msptr
);
684 /* Channel was emptied, create a new one */
685 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
686 return 0; /* oops! */
688 oldmode
= &chptr
->mode
;
692 chptr
->channelts
= newts
;
699 else if(keep_our_modes
)
701 mode
.mode
|= oldmode
->mode
;
702 if(oldmode
->limit
> mode
.limit
)
703 mode
.limit
= oldmode
->limit
;
704 if(strcmp(mode
.key
, oldmode
->key
) < 0)
705 strcpy(mode
.key
, oldmode
->key
);
706 if(oldmode
->join_num
> mode
.join_num
||
707 (oldmode
->join_num
== mode
.join_num
&&
708 oldmode
->join_time
> mode
.join_time
))
710 mode
.join_num
= oldmode
->join_num
;
711 mode
.join_time
= oldmode
->join_time
;
713 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
714 strcpy(mode
.forward
, oldmode
->forward
);
718 /* If setting -j, clear join throttle state -- jilles */
720 chptr
->join_count
= chptr
->join_delta
= 0;
723 set_final_mode(&mode
, oldmode
);
726 /* Lost the TS, other side wins, so remove modes on this side */
729 remove_our_modes(chptr
, fakesource_p
);
730 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
732 del_invite(chptr
, ptr
->data
);
735 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
736 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
737 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
738 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
740 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
741 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
743 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
744 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
748 sendto_channel_local(ALL_MEMBERS
, chptr
,
749 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
750 me
.name
, chptr
->chname
, chptr
->chname
,
751 (long) oldts
, (long) newts
);
752 /* Update capitalization in channel name, this makes the
753 * capitalization timestamped like modes are -- jilles */
754 strcpy(chptr
->chname
, parv
[2]);
756 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
757 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, FALSE
);
761 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
762 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
764 *modebuf
= *parabuf
= '\0';
766 if(parv
[3][0] != '0' && keep_new_modes
)
767 modes
= channel_modes(chptr
, source_p
);
771 mlen_uid
= rb_sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
772 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
773 ptr_uid
= buf_uid
+ mlen_uid
;
776 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
778 len_nick
= len_uid
= 0;
780 /* if theres a space, theres going to be more than one nick, change the
781 * first space to \0, so s is just the first nick, and point p to the
784 if((p
= strchr(s
, ' ')) != NULL
)
795 for (i
= 0; i
< 2; i
++)
809 /* if the client doesnt exist or is fake direction, skip. */
810 if(!(target_p
= find_client(s
)) ||
811 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
814 /* we assume for these we can fit at least one nick/uid in.. */
816 /* check we can fit another status+nick+space into a buffer */
817 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
819 *(ptr_uid
- 1) = '\0';
820 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
821 ptr_uid
= buf_uid
+ mlen_uid
;
841 /* copy the nick to the two buffers */
842 len
= rb_sprintf(ptr_uid
, "%s ", use_id(target_p
));
849 if(!IsMember(target_p
, chptr
))
851 add_user_to_channel(chptr
, target_p
, fl
);
852 send_channel_join(chptr
, target_p
);
859 para
[pargs
++] = target_p
->name
;
861 /* a +ov user.. bleh */
864 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
867 if(pargs
>= MAXMODEPARAMS
)
870 sendto_channel_local(ALL_MEMBERS
, chptr
,
871 ":%s MODE %s %s %s %s %s %s",
872 fakesource_p
->name
, chptr
->chname
,
874 para
[0], para
[1], para
[2], para
[3]);
877 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
882 para
[pargs
++] = target_p
->name
;
885 else if(fl
& CHFL_VOICE
)
888 para
[pargs
++] = target_p
->name
;
891 if(pargs
>= MAXMODEPARAMS
)
894 sendto_channel_local(ALL_MEMBERS
, chptr
,
895 ":%s MODE %s %s %s %s %s %s",
898 modebuf
, para
[0], para
[1], para
[2], para
[3]);
901 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
906 /* p points to the next nick */
909 /* if there was a trailing space and p was pointing to it, then we
910 * need to exit.. this has the side effect of breaking double spaces
911 * in an sjoin.. but that shouldnt happen anyway
913 if(s
&& (*s
== '\0'))
916 /* if p was NULL due to no spaces, s wont exist due to the above, so
917 * we cant check it for spaces.. if there are no spaces, then when
918 * we next get here, s will be NULL
920 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
929 sendto_channel_local(ALL_MEMBERS
, chptr
,
930 ":%s MODE %s %s %s %s %s %s",
931 fakesource_p
->name
, chptr
->chname
, modebuf
,
932 para
[0], CheckEmpty(para
[1]),
933 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
936 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
938 destroy_channel(chptr
);
943 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
946 *(ptr_uid
- 1) = '\0';
949 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
957 * inputs - pointer to client doing join 0
959 * side effects - Use has decided to join 0. This is legacy
960 * from the days when channels were numbers not names. *sigh*
963 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
965 struct membership
*msptr
;
966 struct Channel
*chptr
= NULL
;
969 /* Finish the flood grace period... */
970 if(MyClient(source_p
) && !IsFloodDone(source_p
))
971 flood_endgrace(source_p
);
973 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
975 while((ptr
= source_p
->user
->channel
.head
))
977 if(MyConnect(source_p
) &&
978 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
979 check_spambot_warning(source_p
, NULL
);
982 chptr
= msptr
->chptr
;
983 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
985 source_p
->username
, source_p
->host
, chptr
->chname
);
986 remove_user_from_channel(msptr
);
991 check_channel_name_loc(struct Client
*source_p
, const char *name
)
995 s_assert(name
!= NULL
);
996 if(EmptyString(name
))
999 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1001 for(p
= name
; *p
; ++p
)
1003 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
1009 for(p
= name
; *p
; ++p
)
1016 if(ConfigChannel
.only_ascii_channels
)
1018 for(p
= name
; *p
; ++p
)
1019 if(*p
< 33 || *p
> 126)
1027 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1029 int dir
= MODE_QUERY
;
1030 char *pbuf
= parabuf
;
1034 /* ok, first get a list of modes we need to add */
1035 for (i
= 0; i
< 256; i
++)
1037 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1048 /* now the ones we need to remove. */
1049 for (i
= 0; i
< 256; i
++)
1051 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1062 if(oldmode
->limit
&& !mode
->limit
)
1071 if(oldmode
->key
[0] && !mode
->key
[0])
1079 len
= rb_sprintf(pbuf
, "%s ", oldmode
->key
);
1082 if(oldmode
->join_num
&& !mode
->join_num
)
1091 if(oldmode
->forward
[0] && !mode
->forward
[0])
1100 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1108 len
= rb_sprintf(pbuf
, "%d ", mode
->limit
);
1111 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1119 len
= rb_sprintf(pbuf
, "%s ", mode
->key
);
1122 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1130 len
= rb_sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1133 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) &&
1134 ConfigChannel
.use_forward
)
1142 len
= rb_sprintf(pbuf
, "%s ", mode
->forward
);
1156 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1158 struct membership
*msptr
;
1160 char lmodebuf
[MODEBUFLEN
];
1161 char *lpara
[MAXMODEPARAMS
];
1168 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1171 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1175 if(is_chanop(msptr
))
1177 msptr
->flags
&= ~CHFL_CHANOP
;
1178 lpara
[count
++] = msptr
->client_p
->name
;
1181 /* +ov, might not fit so check. */
1182 if(is_voiced(msptr
))
1184 if(count
>= MAXMODEPARAMS
)
1187 sendto_channel_local(ALL_MEMBERS
, chptr
,
1188 ":%s MODE %s %s %s %s %s %s",
1189 source_p
->name
, chptr
->chname
,
1190 lmodebuf
, lpara
[0], lpara
[1],
1191 lpara
[2], lpara
[3]);
1193 /* preserve the initial '-' */
1198 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1202 msptr
->flags
&= ~CHFL_VOICE
;
1203 lpara
[count
++] = msptr
->client_p
->name
;
1207 else if(is_voiced(msptr
))
1209 msptr
->flags
&= ~CHFL_VOICE
;
1210 lpara
[count
++] = msptr
->client_p
->name
;
1216 if(count
>= MAXMODEPARAMS
)
1219 sendto_channel_local(ALL_MEMBERS
, chptr
,
1220 ":%s MODE %s %s %s %s %s %s",
1221 source_p
->name
, chptr
->chname
, lmodebuf
,
1222 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1227 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1235 sendto_channel_local(ALL_MEMBERS
, chptr
,
1236 ":%s MODE %s %s %s %s %s %s",
1237 source_p
->name
, chptr
->chname
, lmodebuf
,
1238 EmptyString(lpara
[0]) ? "" : lpara
[0],
1239 EmptyString(lpara
[1]) ? "" : lpara
[1],
1240 EmptyString(lpara
[2]) ? "" : lpara
[2],
1241 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1246 /* remove_ban_list()
1248 * inputs - channel, source, list to remove, char of mode, caps needed
1250 * side effects - given list is removed, with modes issued to local clients
1253 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1254 rb_dlink_list
* list
, char c
, int mems
)
1256 static char lmodebuf
[BUFSIZE
];
1257 static char lparabuf
[BUFSIZE
];
1260 rb_dlink_node
*next_ptr
;
1263 int cur_len
, mlen
, plen
;
1267 cur_len
= mlen
= rb_sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1268 mbuf
= lmodebuf
+ mlen
;
1270 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1274 /* trailing space, and the mode letter itself */
1275 plen
= strlen(banptr
->banstr
) +
1276 (banptr
->forward
? strlen(banptr
->forward
) + 1 : 0) + 2;
1278 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1280 /* remove trailing space */
1284 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1287 mbuf
= lmodebuf
+ mlen
;
1294 if (banptr
->forward
)
1295 pbuf
+= rb_sprintf(pbuf
, "%s$%s ", banptr
->banstr
, banptr
->forward
);
1297 pbuf
+= rb_sprintf(pbuf
, "%s ", banptr
->banstr
);
1305 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1307 list
->head
= list
->tail
= NULL
;