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"
45 static int m_join(struct Client
*, struct Client
*, int, const char **);
46 static int ms_join(struct Client
*, struct Client
*, int, const char **);
47 static int ms_sjoin(struct Client
*, struct Client
*, int, const char **);
49 static int h_can_create_channel
;
50 static int h_channel_join
;
52 struct Message join_msgtab
= {
53 "JOIN", 0, 0, 0, MFLG_SLOW
,
54 {mg_unreg
, {m_join
, 2}, {ms_join
, 2}, mg_ignore
, mg_ignore
, {m_join
, 2}}
57 struct Message sjoin_msgtab
= {
58 "SJOIN", 0, 0, 0, MFLG_SLOW
,
59 {mg_unreg
, mg_ignore
, mg_ignore
, {ms_sjoin
, 4}, mg_ignore
, mg_ignore
}
62 mapi_clist_av1 join_clist
[] = { &join_msgtab
, &sjoin_msgtab
, NULL
};
64 mapi_hlist_av1 join_hlist
[] = {
65 { "can_create_channel", &h_can_create_channel
},
66 { "channel_join", &h_channel_join
},
70 DECLARE_MODULE_AV1(join
, NULL
, NULL
, join_clist
, join_hlist
, NULL
, "$Revision: 3494 $");
72 static void do_join_0(struct Client
*client_p
, struct Client
*source_p
);
73 static int check_channel_name_loc(struct Client
*source_p
, const char *name
);
75 static void set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
);
76 static void remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
);
78 static void remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
79 rb_dlink_list
* list
, char c
, int mems
);
81 static char modebuf
[MODEBUFLEN
];
82 static char parabuf
[MODEBUFLEN
];
83 static const char *para
[MAXMODEPARAMS
];
87 /* Check what we will forward to, without sending any notices to the user
90 static struct Channel
*
91 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
97 /* The caller (m_join) is only interested in the reason
98 * for the original channel.
100 if ((*err
= can_join(source_p
, chptr
, key
, &next
)) == 0)
103 /* User is +Q, or forwarding disabled */
104 if (IsNoForward(source_p
) || !ConfigChannel
.use_forward
)
109 chptr
= find_channel(next
);
110 /* Can only forward to existing channels */
113 /* Already on there, show original error message */
114 if (IsMember(source_p
, chptr
))
116 /* Juped. Sending a warning notice would be unfair */
117 if (hash_find_resv(chptr
->chname
))
119 /* Don't forward to +Q channel */
120 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
122 i
= can_join(source_p
, chptr
, key
, &next
);
136 * parv[2] = channel password (key)
139 m_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
141 static char jbuf
[BUFSIZE
];
142 struct Channel
*chptr
= NULL
, *chptr2
= NULL
;
143 struct ConfItem
*aconf
;
148 char *p
= NULL
, *p2
= NULL
;
154 /* rebuild the list of channels theyre supposed to be joining.
155 * this code has a side effect of losing keys, but..
157 chanlist
= LOCAL_COPY(parv
[1]);
158 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
160 /* check the length and name of channel is ok */
161 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
163 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
164 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
168 /* join 0 parts all channels */
169 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
171 (void) strcpy(jbuf
, "0");
175 /* check it begins with # or &, and local chans are disabled */
176 else if(!IsChannelName(name
) ||
177 ( ConfigChannel
.disable_local_channels
&& name
[0] == '&'))
179 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
180 form_str(ERR_NOSUCHCHANNEL
), name
);
184 /* see if its resv'd */
185 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
187 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
188 form_str(ERR_BADCHANNAME
), name
);
190 /* dont warn for opers */
191 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
192 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
193 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
194 source_p
->name
, source_p
->username
,
195 source_p
->orighost
, name
, aconf
->passwd
);
196 /* dont update tracking for jupe exempt users, these
197 * are likely to be spamtrap leaves
199 else if(IsExemptJupe(source_p
))
205 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
206 ConfigChannel
.no_join_on_split
)
208 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
209 me
.name
, source_p
->name
, name
);
214 (void) strcat(jbuf
, ",");
215 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
220 mykey
= LOCAL_COPY(parv
[2]);
221 key
= rb_strtok_r(mykey
, ",", &p2
);
224 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
225 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
227 hook_data_channel_activity hook_info
;
229 /* JOIN 0 simply parts all channels the user is in */
230 if(*name
== '0' && !atoi(name
))
232 if(source_p
->user
->channel
.head
== NULL
)
235 do_join_0(&me
, source_p
);
239 /* look for the channel */
240 if((chptr
= find_channel(name
)) != NULL
)
242 if(IsMember(source_p
, chptr
))
249 hook_data_client_approval moduledata
;
251 moduledata
.client
= source_p
;
252 moduledata
.approved
= 0;
254 call_hook(h_can_create_channel
, &moduledata
);
256 if(moduledata
.approved
!= 0)
258 sendto_one(source_p
, form_str(moduledata
.approved
),
259 me
.name
, source_p
->name
, name
);
263 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
264 ConfigChannel
.no_create_on_split
)
266 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
267 me
.name
, source_p
->name
, name
);
274 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
275 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
276 (!IsOper(source_p
) ||
277 (rb_dlink_list_length(&source_p
->user
->channel
) >=
278 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
280 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
281 me
.name
, source_p
->name
, name
);
285 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
287 chptr
= get_or_create_channel(source_p
, name
, NULL
);
291 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
292 me
.name
, source_p
->name
, name
);
297 /* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */
298 if(!(chptr2
= check_forward(source_p
, chptr
, key
, &i
)))
300 /* might be wrong, but is there any other better location for such?
301 * see extensions/chm_operonly.c for other comments on this
305 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
309 else if(chptr
!= chptr2
)
310 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr2
->chname
);
315 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
316 check_spambot_warning(source_p
, name
);
318 /* add the user to the channel */
319 add_user_to_channel(chptr
, source_p
, flags
);
320 if (chptr
->mode
.join_num
&&
321 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
323 chptr
->join_count
= 0;
324 chptr
->join_delta
= rb_current_time();
328 /* we send the user their join here, because we could have to
329 * send a mode out next.
331 send_channel_join(chptr
, source_p
);
333 /* its a new channel, set +nt and burst. */
334 if(flags
& CHFL_CHANOP
)
336 chptr
->channelts
= rb_current_time();
337 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
338 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
339 modes
= channel_modes(chptr
, &me
);
341 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
342 me
.name
, chptr
->chname
, modes
);
344 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
345 ":%s SJOIN %ld %s %s :@%s",
346 me
.id
, (long) chptr
->channelts
,
347 chptr
->chname
, modes
, source_p
->id
);
351 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
353 use_id(source_p
), (long) chptr
->channelts
,
357 del_invite(chptr
, source_p
);
359 if(chptr
->topic
!= NULL
)
361 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
362 source_p
->name
, chptr
->chname
, chptr
->topic
);
364 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
365 me
.name
, source_p
->name
, chptr
->chname
,
367 (unsigned long)chptr
->topic_time
);
370 channel_member_names(chptr
, source_p
, 1);
372 hook_info
.client
= source_p
;
373 hook_info
.chptr
= chptr
;
375 call_hook(h_channel_join
, &hook_info
);
383 * parv[1] = channel TS
385 * parv[3] = "+", formerly channel modes but now unused
386 * alternatively, a single "0" parameter parts all channels
389 ms_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
391 struct Channel
*chptr
;
392 static struct Mode mode
;
396 int keep_our_modes
= YES
;
397 int keep_new_modes
= YES
;
398 rb_dlink_node
*ptr
, *next_ptr
;
400 /* special case for join 0 */
401 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
403 do_join_0(client_p
, source_p
);
410 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
413 /* joins for local channels cant happen. */
414 if(parv
[2][0] == '&')
418 mode
.key
[0] = mode
.forward
[0] = '\0';
419 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
421 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
424 newts
= atol(parv
[1]);
425 oldts
= chptr
->channelts
;
427 #ifdef IGNORE_BOGUS_TS
428 if(newts
< 800000000)
430 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
431 "*** Bogus TS %ld on %s ignored from %s",
432 (long) newts
, chptr
->chname
, client_p
->name
);
433 newts
= (oldts
== 0) ? oldts
: 800000000;
436 /* making a channel TS0 */
437 if(!isnew
&& !newts
&& oldts
)
439 sendto_channel_local(ALL_MEMBERS
, chptr
,
440 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
441 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
442 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
443 "Server %s changing TS on %s from %ld to 0",
444 source_p
->name
, chptr
->chname
, (long) oldts
);
449 chptr
->channelts
= newts
;
450 else if(newts
== 0 || oldts
== 0)
451 chptr
->channelts
= 0;
452 else if(newts
== oldts
)
454 else if(newts
< oldts
)
457 chptr
->channelts
= newts
;
462 /* Lost the TS, other side wins, so remove modes on this side */
465 set_final_mode(&mode
, &chptr
->mode
);
467 remove_our_modes(chptr
, source_p
);
468 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
470 del_invite(chptr
, ptr
->data
);
472 /* If setting -j, clear join throttle state -- jilles */
473 chptr
->join_count
= chptr
->join_delta
= 0;
474 sendto_channel_local(ALL_MEMBERS
, chptr
,
475 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
476 me
.name
, chptr
->chname
, chptr
->chname
,
477 (long) oldts
, (long) newts
);
478 /* Update capitalization in channel name, this makes the
479 * capitalization timestamped like modes are -- jilles */
480 strcpy(chptr
->chname
, parv
[2]);
482 sendto_channel_local(ALL_MEMBERS
, chptr
,
484 source_p
->servptr
->name
,
485 chptr
->chname
, modebuf
, parabuf
);
486 *modebuf
= *parabuf
= '\0';
488 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
489 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, FALSE
);
492 if(!IsMember(source_p
, chptr
))
494 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
495 if (chptr
->mode
.join_num
&&
496 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
498 chptr
->join_count
= 0;
499 chptr
->join_delta
= rb_current_time();
502 send_channel_join(chptr
, source_p
);
505 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
507 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
512 ms_sjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
514 static char buf_uid
[BUFSIZE
];
515 static const char empty_modes
[] = "0";
516 struct Channel
*chptr
;
517 struct Client
*target_p
, *fakesource_p
;
520 static struct Mode mode
, *oldmode
;
523 int keep_our_modes
= 1;
524 int keep_new_modes
= 1;
535 int i
, joinc
= 0, timeslice
= 0;
536 static char empty
[] = "";
537 rb_dlink_node
*ptr
, *next_ptr
;
539 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
542 /* SJOIN's for local channels can't happen. */
546 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
547 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
549 /* Hide connecting server on netburst -- jilles */
550 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
553 fakesource_p
= source_p
;
556 newts
= atol(parv
[1]);
564 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
570 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
572 mode
.join_num
= joinc
;
573 mode
.join_time
= timeslice
;
578 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
584 mode
.limit
= atoi(parv
[4 + args
]);
590 if(chmode_flags
[(int) *s
] != 0)
592 mode
.mode
|= chmode_flags
[(int) *s
];
601 /* remove any leading spaces */
608 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
609 return 0; /* channel name too long? */
612 oldts
= chptr
->channelts
;
613 oldmode
= &chptr
->mode
;
615 #ifdef IGNORE_BOGUS_TS
616 if(newts
< 800000000)
618 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
619 "*** Bogus TS %ld on %s ignored from %s",
620 (long) newts
, chptr
->chname
, client_p
->name
);
622 newts
= (oldts
== 0) ? oldts
: 800000000;
625 if(!isnew
&& !newts
&& oldts
)
627 sendto_channel_local(ALL_MEMBERS
, chptr
,
628 ":%s NOTICE %s :*** Notice -- TS for %s "
629 "changed from %ld to 0",
630 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
631 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
632 "Server %s changing TS on %s from %ld to 0",
633 source_p
->name
, chptr
->chname
, (long) oldts
);
638 chptr
->channelts
= newts
;
640 else if(newts
== 0 || oldts
== 0)
641 chptr
->channelts
= 0;
642 else if(newts
== oldts
)
644 else if(newts
< oldts
)
646 /* If configured, kick people trying to join +i/+k
647 * channels by recreating them on split servers.
648 * If the source has sent EOB, assume this is some
649 * sort of hack by services. If cmode +i is set,
650 * services can send kicks if needed; if the key
651 * differs, services cannot kick in a race-free
652 * manner so do so here.
654 if (ConfigChannel
.kick_on_split_riding
&&
655 ((!HasSentEob(source_p
) &&
656 mode
.mode
& MODE_INVITEONLY
) ||
657 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
659 struct membership
*msptr
;
661 int l
= rb_dlink_list_length(&chptr
->members
);
663 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
666 who
= msptr
->client_p
;
667 sendto_one(who
, ":%s KICK %s %s :Net Rider",
668 me
.name
, chptr
->chname
, who
->name
);
670 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
671 ":%s KICK %s %s :Net Rider",
672 me
.id
, chptr
->chname
,
674 remove_user_from_channel(msptr
);
680 /* Channel was emptied, create a new one */
681 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
682 return 0; /* oops! */
684 oldmode
= &chptr
->mode
;
688 chptr
->channelts
= newts
;
695 else if(keep_our_modes
)
697 mode
.mode
|= oldmode
->mode
;
698 if(oldmode
->limit
> mode
.limit
)
699 mode
.limit
= oldmode
->limit
;
700 if(strcmp(mode
.key
, oldmode
->key
) < 0)
701 strcpy(mode
.key
, oldmode
->key
);
702 if(oldmode
->join_num
> mode
.join_num
||
703 (oldmode
->join_num
== mode
.join_num
&&
704 oldmode
->join_time
> mode
.join_time
))
706 mode
.join_num
= oldmode
->join_num
;
707 mode
.join_time
= oldmode
->join_time
;
709 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
710 strcpy(mode
.forward
, oldmode
->forward
);
714 /* If setting -j, clear join throttle state -- jilles */
716 chptr
->join_count
= chptr
->join_delta
= 0;
719 set_final_mode(&mode
, oldmode
);
722 /* Lost the TS, other side wins, so remove modes on this side */
725 remove_our_modes(chptr
, fakesource_p
);
726 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
728 del_invite(chptr
, ptr
->data
);
731 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
732 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
733 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
734 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
736 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
737 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
739 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
740 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
744 sendto_channel_local(ALL_MEMBERS
, chptr
,
745 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
746 me
.name
, chptr
->chname
, chptr
->chname
,
747 (long) oldts
, (long) newts
);
748 /* Update capitalization in channel name, this makes the
749 * capitalization timestamped like modes are -- jilles */
750 strcpy(chptr
->chname
, parv
[2]);
752 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
753 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, FALSE
);
757 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
758 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
760 *modebuf
= *parabuf
= '\0';
762 if(parv
[3][0] != '0' && keep_new_modes
)
763 modes
= channel_modes(chptr
, source_p
);
767 mlen_uid
= rb_sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
768 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
769 ptr_uid
= buf_uid
+ mlen_uid
;
772 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
774 len_nick
= len_uid
= 0;
776 /* if theres a space, theres going to be more than one nick, change the
777 * first space to \0, so s is just the first nick, and point p to the
780 if((p
= strchr(s
, ' ')) != NULL
)
791 for (i
= 0; i
< 2; i
++)
805 /* if the client doesnt exist or is fake direction, skip. */
806 if(!(target_p
= find_client(s
)) ||
807 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
810 /* we assume for these we can fit at least one nick/uid in.. */
812 /* check we can fit another status+nick+space into a buffer */
813 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
815 *(ptr_uid
- 1) = '\0';
816 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
817 ptr_uid
= buf_uid
+ mlen_uid
;
837 /* copy the nick to the two buffers */
838 len
= rb_sprintf(ptr_uid
, "%s ", use_id(target_p
));
845 if(!IsMember(target_p
, chptr
))
847 add_user_to_channel(chptr
, target_p
, fl
);
848 send_channel_join(chptr
, target_p
);
855 para
[pargs
++] = target_p
->name
;
857 /* a +ov user.. bleh */
860 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
863 if(pargs
>= MAXMODEPARAMS
)
866 sendto_channel_local(ALL_MEMBERS
, chptr
,
867 ":%s MODE %s %s %s %s %s %s",
868 fakesource_p
->name
, chptr
->chname
,
870 para
[0], para
[1], para
[2], para
[3]);
873 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
878 para
[pargs
++] = target_p
->name
;
881 else if(fl
& CHFL_VOICE
)
884 para
[pargs
++] = target_p
->name
;
887 if(pargs
>= MAXMODEPARAMS
)
890 sendto_channel_local(ALL_MEMBERS
, chptr
,
891 ":%s MODE %s %s %s %s %s %s",
894 modebuf
, para
[0], para
[1], para
[2], para
[3]);
897 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
902 /* p points to the next nick */
905 /* if there was a trailing space and p was pointing to it, then we
906 * need to exit.. this has the side effect of breaking double spaces
907 * in an sjoin.. but that shouldnt happen anyway
909 if(s
&& (*s
== '\0'))
912 /* if p was NULL due to no spaces, s wont exist due to the above, so
913 * we cant check it for spaces.. if there are no spaces, then when
914 * we next get here, s will be NULL
916 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
925 sendto_channel_local(ALL_MEMBERS
, chptr
,
926 ":%s MODE %s %s %s %s %s %s",
927 fakesource_p
->name
, chptr
->chname
, modebuf
,
928 para
[0], CheckEmpty(para
[1]),
929 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
932 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
934 destroy_channel(chptr
);
939 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
942 *(ptr_uid
- 1) = '\0';
945 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
953 * inputs - pointer to client doing join 0
955 * side effects - Use has decided to join 0. This is legacy
956 * from the days when channels were numbers not names. *sigh*
959 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
961 struct membership
*msptr
;
962 struct Channel
*chptr
= NULL
;
965 /* Finish the flood grace period... */
966 if(MyClient(source_p
) && !IsFloodDone(source_p
))
967 flood_endgrace(source_p
);
969 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
971 while((ptr
= source_p
->user
->channel
.head
))
973 if(MyConnect(source_p
) &&
974 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
975 check_spambot_warning(source_p
, NULL
);
978 chptr
= msptr
->chptr
;
979 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
981 source_p
->username
, source_p
->host
, chptr
->chname
);
982 remove_user_from_channel(msptr
);
987 check_channel_name_loc(struct Client
*source_p
, const char *name
)
991 s_assert(name
!= NULL
);
992 if(EmptyString(name
))
995 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
997 for(p
= name
; *p
; ++p
)
999 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
1005 for(p
= name
; *p
; ++p
)
1012 if(ConfigChannel
.only_ascii_channels
)
1014 for(p
= name
; *p
; ++p
)
1015 if(*p
< 33 || *p
> 126)
1023 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1025 int dir
= MODE_QUERY
;
1026 char *pbuf
= parabuf
;
1030 /* ok, first get a list of modes we need to add */
1031 for (i
= 0; i
< 256; i
++)
1033 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1044 /* now the ones we need to remove. */
1045 for (i
= 0; i
< 256; i
++)
1047 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1058 if(oldmode
->limit
&& !mode
->limit
)
1067 if(oldmode
->key
[0] && !mode
->key
[0])
1075 len
= rb_sprintf(pbuf
, "%s ", oldmode
->key
);
1078 if(oldmode
->join_num
&& !mode
->join_num
)
1087 if(oldmode
->forward
[0] && !mode
->forward
[0])
1096 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1104 len
= rb_sprintf(pbuf
, "%d ", mode
->limit
);
1107 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1115 len
= rb_sprintf(pbuf
, "%s ", mode
->key
);
1118 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1126 len
= rb_sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1129 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) &&
1130 ConfigChannel
.use_forward
)
1138 len
= rb_sprintf(pbuf
, "%s ", mode
->forward
);
1152 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1154 struct membership
*msptr
;
1156 char lmodebuf
[MODEBUFLEN
];
1157 char *lpara
[MAXMODEPARAMS
];
1164 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1167 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1171 if(is_chanop(msptr
))
1173 msptr
->flags
&= ~CHFL_CHANOP
;
1174 lpara
[count
++] = msptr
->client_p
->name
;
1177 /* +ov, might not fit so check. */
1178 if(is_voiced(msptr
))
1180 if(count
>= MAXMODEPARAMS
)
1183 sendto_channel_local(ALL_MEMBERS
, chptr
,
1184 ":%s MODE %s %s %s %s %s %s",
1185 source_p
->name
, chptr
->chname
,
1186 lmodebuf
, lpara
[0], lpara
[1],
1187 lpara
[2], lpara
[3]);
1189 /* preserve the initial '-' */
1194 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1198 msptr
->flags
&= ~CHFL_VOICE
;
1199 lpara
[count
++] = msptr
->client_p
->name
;
1203 else if(is_voiced(msptr
))
1205 msptr
->flags
&= ~CHFL_VOICE
;
1206 lpara
[count
++] = msptr
->client_p
->name
;
1212 if(count
>= MAXMODEPARAMS
)
1215 sendto_channel_local(ALL_MEMBERS
, chptr
,
1216 ":%s MODE %s %s %s %s %s %s",
1217 source_p
->name
, chptr
->chname
, lmodebuf
,
1218 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1223 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1231 sendto_channel_local(ALL_MEMBERS
, chptr
,
1232 ":%s MODE %s %s %s %s %s %s",
1233 source_p
->name
, chptr
->chname
, lmodebuf
,
1234 EmptyString(lpara
[0]) ? "" : lpara
[0],
1235 EmptyString(lpara
[1]) ? "" : lpara
[1],
1236 EmptyString(lpara
[2]) ? "" : lpara
[2],
1237 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1242 /* remove_ban_list()
1244 * inputs - channel, source, list to remove, char of mode, caps needed
1246 * side effects - given list is removed, with modes issued to local clients
1249 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1250 rb_dlink_list
* list
, char c
, int mems
)
1252 static char lmodebuf
[BUFSIZE
];
1253 static char lparabuf
[BUFSIZE
];
1256 rb_dlink_node
*next_ptr
;
1259 int cur_len
, mlen
, plen
;
1263 cur_len
= mlen
= rb_sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1264 mbuf
= lmodebuf
+ mlen
;
1266 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1270 /* trailing space, and the mode letter itself */
1271 plen
= strlen(banptr
->banstr
) + 2;
1273 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1275 /* remove trailing space */
1279 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1282 mbuf
= lmodebuf
+ mlen
;
1289 pbuf
+= rb_sprintf(pbuf
, "%s ", banptr
->banstr
);
1297 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1299 list
->head
= list
->tail
= NULL
;