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 if (IsNoForward(source_p
))
102 chptr
= find_channel(chptr
->mode
.forward
);
103 /* Can only forward to existing channels */
106 /* Already on there, show original error message */
107 if (IsMember(source_p
, chptr
))
109 /* Juped. Sending a warning notice would be unfair */
110 if (hash_find_resv(chptr
->chname
))
112 /* Don't forward to +Q channel */
113 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
115 i
= can_join(source_p
, chptr
, key
);
118 if (i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_CHANNELISFULL
)
129 * parv[2] = channel password (key)
132 m_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
134 static char jbuf
[BUFSIZE
];
135 struct Channel
*chptr
= NULL
;
136 struct ConfItem
*aconf
;
141 char *p
= NULL
, *p2
= NULL
;
147 /* rebuild the list of channels theyre supposed to be joining.
148 * this code has a side effect of losing keys, but..
150 chanlist
= LOCAL_COPY(parv
[1]);
151 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
153 /* check the length and name of channel is ok */
154 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
156 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
157 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
161 /* join 0 parts all channels */
162 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
164 (void) strcpy(jbuf
, "0");
168 /* check it begins with # or &, and local chans are disabled */
169 else if(!IsChannelName(name
))
171 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
172 form_str(ERR_NOSUCHCHANNEL
), name
);
176 /* see if its resv'd */
177 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
179 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
180 form_str(ERR_BADCHANNAME
), name
);
182 /* dont warn for opers */
183 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
184 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
185 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
186 source_p
->name
, source_p
->username
,
187 source_p
->orighost
, name
, aconf
->passwd
);
188 /* dont update tracking for jupe exempt users, these
189 * are likely to be spamtrap leaves
191 else if(IsExemptJupe(source_p
))
197 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
198 ConfigChannel
.no_join_on_split
)
200 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
201 me
.name
, source_p
->name
, name
);
206 (void) strcat(jbuf
, ",");
207 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
212 mykey
= LOCAL_COPY(parv
[2]);
213 key
= rb_strtok_r(mykey
, ",", &p2
);
216 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
217 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
219 hook_data_channel_activity hook_info
;
221 /* JOIN 0 simply parts all channels the user is in */
222 if(*name
== '0' && !atoi(name
))
224 if(source_p
->user
->channel
.head
== NULL
)
227 do_join_0(&me
, source_p
);
231 /* look for the channel */
232 if((chptr
= find_channel(name
)) != NULL
)
234 if(IsMember(source_p
, chptr
))
241 hook_data_client_approval moduledata
;
243 moduledata
.client
= source_p
;
244 moduledata
.approved
= 0;
246 call_hook(h_can_create_channel
, &moduledata
);
248 if(moduledata
.approved
!= 0)
250 sendto_one(source_p
, form_str(moduledata
.approved
),
251 me
.name
, source_p
->name
, name
);
255 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
256 ConfigChannel
.no_create_on_split
)
258 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
259 me
.name
, source_p
->name
, name
);
266 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
267 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
268 (!IsOper(source_p
) ||
269 (rb_dlink_list_length(&source_p
->user
->channel
) >=
270 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
272 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
273 me
.name
, source_p
->name
, name
);
277 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
279 chptr
= get_or_create_channel(source_p
, name
, NULL
);
283 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
284 me
.name
, source_p
->name
, name
);
289 /* can_join checks for +i key, bans etc */
290 if((i
= can_join(source_p
, chptr
, key
)))
292 if ((i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_CHANNELISFULL
) ||
293 (!ConfigChannel
.use_forward
|| (chptr
= check_forward(source_p
, chptr
, key
)) == NULL
))
295 /* might be wrong, but is there any other better location for such?
296 * see extensions/chm_operonly.c for other comments on this
300 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
305 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr
->chname
);
309 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
310 check_spambot_warning(source_p
, name
);
312 /* add the user to the channel */
313 add_user_to_channel(chptr
, source_p
, flags
);
314 if (chptr
->mode
.join_num
&&
315 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
317 chptr
->join_count
= 0;
318 chptr
->join_delta
= rb_current_time();
322 /* we send the user their join here, because we could have to
323 * send a mode out next.
325 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
327 source_p
->username
, source_p
->host
, chptr
->chname
);
329 /* its a new channel, set +nt and burst. */
330 if(flags
& CHFL_CHANOP
)
332 chptr
->channelts
= rb_current_time();
333 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
334 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
335 modes
= channel_modes(chptr
, &me
);
337 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
338 me
.name
, chptr
->chname
, modes
);
340 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
341 ":%s SJOIN %ld %s %s :@%s",
342 me
.id
, (long) chptr
->channelts
,
343 chptr
->chname
, modes
, source_p
->id
);
347 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
349 use_id(source_p
), (long) chptr
->channelts
,
353 del_invite(chptr
, source_p
);
355 if(chptr
->topic
!= NULL
)
357 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
358 source_p
->name
, chptr
->chname
, chptr
->topic
);
360 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
361 me
.name
, source_p
->name
, chptr
->chname
,
362 chptr
->topic_info
, chptr
->topic_time
);
365 channel_member_names(chptr
, source_p
, 1);
367 hook_info
.client
= source_p
;
368 hook_info
.chptr
= chptr
;
370 call_hook(h_channel_join
, &hook_info
);
378 * parv[1] = channel TS
380 * parv[3] = "+", formerly channel modes but now unused
381 * alternatively, a single "0" parameter parts all channels
384 ms_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
386 struct Channel
*chptr
;
387 static struct Mode mode
;
391 int keep_our_modes
= YES
;
392 int keep_new_modes
= YES
;
393 rb_dlink_node
*ptr
, *next_ptr
;
395 /* special case for join 0 */
396 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
398 do_join_0(client_p
, source_p
);
405 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
408 /* joins for local channels cant happen. */
409 if(parv
[2][0] == '&')
413 mode
.key
[0] = mode
.forward
[0] = '\0';
414 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
416 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
419 newts
= atol(parv
[1]);
420 oldts
= chptr
->channelts
;
422 #ifdef IGNORE_BOGUS_TS
423 if(newts
< 800000000)
425 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
426 "*** Bogus TS %ld on %s ignored from %s",
427 (long) newts
, chptr
->chname
, client_p
->name
);
428 newts
= (oldts
== 0) ? oldts
: 800000000;
431 /* making a channel TS0 */
432 if(!isnew
&& !newts
&& oldts
)
434 sendto_channel_local(ALL_MEMBERS
, chptr
,
435 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
436 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
437 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
438 "Server %s changing TS on %s from %ld to 0",
439 source_p
->name
, chptr
->chname
, (long) oldts
);
444 chptr
->channelts
= newts
;
445 else if(newts
== 0 || oldts
== 0)
446 chptr
->channelts
= 0;
447 else if(newts
== oldts
)
449 else if(newts
< oldts
)
452 chptr
->channelts
= newts
;
457 /* Lost the TS, other side wins, so remove modes on this side */
460 set_final_mode(&mode
, &chptr
->mode
);
462 remove_our_modes(chptr
, source_p
);
463 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
465 del_invite(chptr
, ptr
->data
);
467 /* If setting -j, clear join throttle state -- jilles */
468 chptr
->join_count
= chptr
->join_delta
= 0;
469 sendto_channel_local(ALL_MEMBERS
, chptr
,
470 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
471 me
.name
, chptr
->chname
, chptr
->chname
,
472 (long) oldts
, (long) newts
);
473 /* Update capitalization in channel name, this makes the
474 * capitalization timestamped like modes are -- jilles */
475 strcpy(chptr
->chname
, parv
[2]);
477 sendto_channel_local(ALL_MEMBERS
, chptr
,
479 source_p
->servptr
->name
,
480 chptr
->chname
, modebuf
, parabuf
);
481 *modebuf
= *parabuf
= '\0';
484 if(!IsMember(source_p
, chptr
))
486 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
487 if (chptr
->mode
.join_num
&&
488 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
490 chptr
->join_count
= 0;
491 chptr
->join_delta
= rb_current_time();
494 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
495 source_p
->name
, source_p
->username
,
496 source_p
->host
, chptr
->chname
);
499 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
501 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
506 ms_sjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
508 static char buf_uid
[BUFSIZE
];
509 static const char empty_modes
[] = "0";
510 struct Channel
*chptr
;
511 struct Client
*target_p
, *fakesource_p
;
514 static struct Mode mode
, *oldmode
;
517 int keep_our_modes
= 1;
518 int keep_new_modes
= 1;
529 int i
, joinc
= 0, timeslice
= 0;
530 static char empty
[] = "";
531 rb_dlink_node
*ptr
, *next_ptr
;
533 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
536 /* SJOIN's for local channels can't happen. */
540 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
541 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
543 /* Hide connecting server on netburst -- jilles */
544 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
547 fakesource_p
= source_p
;
550 newts
= atol(parv
[1]);
558 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
564 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
566 mode
.join_num
= joinc
;
567 mode
.join_time
= timeslice
;
572 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
578 mode
.limit
= atoi(parv
[4 + args
]);
584 if(chmode_flags
[(int) *s
] != 0)
586 mode
.mode
|= chmode_flags
[(int) *s
];
595 /* remove any leading spaces */
602 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
603 return 0; /* channel name too long? */
606 oldts
= chptr
->channelts
;
607 oldmode
= &chptr
->mode
;
609 #ifdef IGNORE_BOGUS_TS
610 if(newts
< 800000000)
612 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
613 "*** Bogus TS %ld on %s ignored from %s",
614 (long) newts
, chptr
->chname
, client_p
->name
);
616 newts
= (oldts
== 0) ? oldts
: 800000000;
619 if(!isnew
&& !newts
&& oldts
)
621 sendto_channel_local(ALL_MEMBERS
, chptr
,
622 ":%s NOTICE %s :*** Notice -- TS for %s "
623 "changed from %ld to 0",
624 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
625 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
626 "Server %s changing TS on %s from %ld to 0",
627 source_p
->name
, chptr
->chname
, (long) oldts
);
632 chptr
->channelts
= newts
;
634 else if(newts
== 0 || oldts
== 0)
635 chptr
->channelts
= 0;
636 else if(newts
== oldts
)
638 else if(newts
< oldts
)
640 /* If configured, kick people trying to join +i/+k
641 * channels by recreating them on split servers.
642 * Don't kick if the source has sent EOB (services
643 * deopping everyone by TS-1 SJOIN).
645 if (ConfigChannel
.kick_on_split_riding
&&
646 !HasSentEob(source_p
) &&
647 ((mode
.mode
& MODE_INVITEONLY
) ||
648 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
650 struct membership
*msptr
;
652 int l
= rb_dlink_list_length(&chptr
->members
);
654 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
657 who
= msptr
->client_p
;
658 sendto_one(who
, ":%s KICK %s %s :Net Rider",
659 me
.name
, chptr
->chname
, who
->name
);
661 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
662 ":%s KICK %s %s :Net Rider",
663 me
.id
, chptr
->chname
,
665 remove_user_from_channel(msptr
);
671 /* Channel was emptied, create a new one */
672 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
673 return 0; /* oops! */
675 oldmode
= &chptr
->mode
;
679 chptr
->channelts
= newts
;
686 else if(keep_our_modes
)
688 mode
.mode
|= oldmode
->mode
;
689 if(oldmode
->limit
> mode
.limit
)
690 mode
.limit
= oldmode
->limit
;
691 if(strcmp(mode
.key
, oldmode
->key
) < 0)
692 strcpy(mode
.key
, oldmode
->key
);
693 if(oldmode
->join_num
> mode
.join_num
||
694 (oldmode
->join_num
== mode
.join_num
&&
695 oldmode
->join_time
> mode
.join_time
))
697 mode
.join_num
= oldmode
->join_num
;
698 mode
.join_time
= oldmode
->join_time
;
700 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
701 strcpy(mode
.forward
, oldmode
->forward
);
705 /* If setting -j, clear join throttle state -- jilles */
707 chptr
->join_count
= chptr
->join_delta
= 0;
710 set_final_mode(&mode
, oldmode
);
713 /* Lost the TS, other side wins, so remove modes on this side */
716 remove_our_modes(chptr
, fakesource_p
);
717 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
719 del_invite(chptr
, ptr
->data
);
722 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
723 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
724 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
725 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
727 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
728 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
730 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
731 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
735 sendto_channel_local(ALL_MEMBERS
, chptr
,
736 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
737 me
.name
, chptr
->chname
, chptr
->chname
,
738 (long) oldts
, (long) newts
);
739 /* Update capitalization in channel name, this makes the
740 * capitalization timestamped like modes are -- jilles */
741 strcpy(chptr
->chname
, parv
[2]);
745 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
746 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
748 *modebuf
= *parabuf
= '\0';
750 if(parv
[3][0] != '0' && keep_new_modes
)
751 modes
= channel_modes(chptr
, source_p
);
755 mlen_uid
= rb_sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
756 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
757 ptr_uid
= buf_uid
+ mlen_uid
;
760 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
762 len_nick
= len_uid
= 0;
764 /* if theres a space, theres going to be more than one nick, change the
765 * first space to \0, so s is just the first nick, and point p to the
768 if((p
= strchr(s
, ' ')) != NULL
)
779 for (i
= 0; i
< 2; i
++)
793 /* if the client doesnt exist or is fake direction, skip. */
794 if(!(target_p
= find_client(s
)) ||
795 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
798 /* we assume for these we can fit at least one nick/uid in.. */
800 /* check we can fit another status+nick+space into a buffer */
801 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
803 *(ptr_uid
- 1) = '\0';
804 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
805 ptr_uid
= buf_uid
+ mlen_uid
;
825 /* copy the nick to the two buffers */
826 len
= rb_sprintf(ptr_uid
, "%s ", use_id(target_p
));
833 if(!IsMember(target_p
, chptr
))
835 add_user_to_channel(chptr
, target_p
, fl
);
836 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
838 target_p
->username
, target_p
->host
, parv
[2]);
845 para
[pargs
++] = target_p
->name
;
847 /* a +ov user.. bleh */
850 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
853 if(pargs
>= MAXMODEPARAMS
)
856 sendto_channel_local(ALL_MEMBERS
, chptr
,
857 ":%s MODE %s %s %s %s %s %s",
858 fakesource_p
->name
, chptr
->chname
,
860 para
[0], para
[1], para
[2], para
[3]);
863 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
868 para
[pargs
++] = target_p
->name
;
871 else if(fl
& CHFL_VOICE
)
874 para
[pargs
++] = target_p
->name
;
877 if(pargs
>= MAXMODEPARAMS
)
880 sendto_channel_local(ALL_MEMBERS
, chptr
,
881 ":%s MODE %s %s %s %s %s %s",
884 modebuf
, para
[0], para
[1], para
[2], para
[3]);
887 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
892 /* p points to the next nick */
895 /* if there was a trailing space and p was pointing to it, then we
896 * need to exit.. this has the side effect of breaking double spaces
897 * in an sjoin.. but that shouldnt happen anyway
899 if(s
&& (*s
== '\0'))
902 /* if p was NULL due to no spaces, s wont exist due to the above, so
903 * we cant check it for spaces.. if there are no spaces, then when
904 * we next get here, s will be NULL
906 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
915 sendto_channel_local(ALL_MEMBERS
, chptr
,
916 ":%s MODE %s %s %s %s %s %s",
917 fakesource_p
->name
, chptr
->chname
, modebuf
,
918 para
[0], CheckEmpty(para
[1]),
919 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
922 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
924 destroy_channel(chptr
);
929 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
932 *(ptr_uid
- 1) = '\0';
935 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
943 * inputs - pointer to client doing join 0
945 * side effects - Use has decided to join 0. This is legacy
946 * from the days when channels were numbers not names. *sigh*
949 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
951 struct membership
*msptr
;
952 struct Channel
*chptr
= NULL
;
955 /* Finish the flood grace period... */
956 if(MyClient(source_p
) && !IsFloodDone(source_p
))
957 flood_endgrace(source_p
);
959 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
961 while((ptr
= source_p
->user
->channel
.head
))
963 if(MyConnect(source_p
) &&
964 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
965 check_spambot_warning(source_p
, NULL
);
968 chptr
= msptr
->chptr
;
969 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
971 source_p
->username
, source_p
->host
, chptr
->chname
);
972 remove_user_from_channel(msptr
);
977 check_channel_name_loc(struct Client
*source_p
, const char *name
)
981 s_assert(name
!= NULL
);
982 if(EmptyString(name
))
985 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
987 for(p
= name
; *p
; ++p
)
989 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
995 for(p
= name
; *p
; ++p
)
1002 if(ConfigChannel
.only_ascii_channels
)
1004 for(p
= name
; *p
; ++p
)
1005 if(*p
< 33 || *p
> 126)
1013 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1015 int dir
= MODE_QUERY
;
1016 char *pbuf
= parabuf
;
1020 /* ok, first get a list of modes we need to add */
1021 for (i
= 0; i
< 256; i
++)
1023 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1034 /* now the ones we need to remove. */
1035 for (i
= 0; i
< 256; i
++)
1037 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1048 if(oldmode
->limit
&& !mode
->limit
)
1057 if(oldmode
->key
[0] && !mode
->key
[0])
1065 len
= rb_sprintf(pbuf
, "%s ", oldmode
->key
);
1068 if(oldmode
->join_num
&& !mode
->join_num
)
1077 if(oldmode
->forward
[0] && !mode
->forward
[0])
1086 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1094 len
= rb_sprintf(pbuf
, "%d ", mode
->limit
);
1097 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1105 len
= rb_sprintf(pbuf
, "%s ", mode
->key
);
1108 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1116 len
= rb_sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1119 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) && ConfigChannel
.use_forward
)
1127 len
= rb_sprintf(pbuf
, "%s ", mode
->forward
);
1141 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1143 struct membership
*msptr
;
1145 char lmodebuf
[MODEBUFLEN
];
1146 char *lpara
[MAXMODEPARAMS
];
1153 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1156 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1160 if(is_chanop(msptr
))
1162 msptr
->flags
&= ~CHFL_CHANOP
;
1163 lpara
[count
++] = msptr
->client_p
->name
;
1166 /* +ov, might not fit so check. */
1167 if(is_voiced(msptr
))
1169 if(count
>= MAXMODEPARAMS
)
1172 sendto_channel_local(ALL_MEMBERS
, chptr
,
1173 ":%s MODE %s %s %s %s %s %s",
1174 source_p
->name
, chptr
->chname
,
1175 lmodebuf
, lpara
[0], lpara
[1],
1176 lpara
[2], lpara
[3]);
1178 /* preserve the initial '-' */
1183 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1187 msptr
->flags
&= ~CHFL_VOICE
;
1188 lpara
[count
++] = msptr
->client_p
->name
;
1192 else if(is_voiced(msptr
))
1194 msptr
->flags
&= ~CHFL_VOICE
;
1195 lpara
[count
++] = msptr
->client_p
->name
;
1201 if(count
>= MAXMODEPARAMS
)
1204 sendto_channel_local(ALL_MEMBERS
, chptr
,
1205 ":%s MODE %s %s %s %s %s %s",
1206 source_p
->name
, chptr
->chname
, lmodebuf
,
1207 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1212 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1220 sendto_channel_local(ALL_MEMBERS
, chptr
,
1221 ":%s MODE %s %s %s %s %s %s",
1222 source_p
->name
, chptr
->chname
, lmodebuf
,
1223 EmptyString(lpara
[0]) ? "" : lpara
[0],
1224 EmptyString(lpara
[1]) ? "" : lpara
[1],
1225 EmptyString(lpara
[2]) ? "" : lpara
[2],
1226 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1231 /* remove_ban_list()
1233 * inputs - channel, source, list to remove, char of mode, caps needed
1235 * side effects - given list is removed, with modes issued to local clients
1238 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1239 rb_dlink_list
* list
, char c
, int mems
)
1241 static char lmodebuf
[BUFSIZE
];
1242 static char lparabuf
[BUFSIZE
];
1245 rb_dlink_node
*next_ptr
;
1248 int cur_len
, mlen
, plen
;
1252 cur_len
= mlen
= rb_sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1253 mbuf
= lmodebuf
+ mlen
;
1255 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1259 /* trailing space, and the mode letter itself */
1260 plen
= strlen(banptr
->banstr
) + 2;
1262 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1264 /* remove trailing space */
1268 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1271 mbuf
= lmodebuf
+ mlen
;
1278 pbuf
+= rb_sprintf(pbuf
, "%s ", banptr
->banstr
);
1286 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1288 list
->head
= list
->tail
= NULL
;