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
36 #include "s_newconf.h"
42 #include "ratelimit.h"
45 static const char join_desc
[] = "Provides the JOIN and TS6 SJOIN commands to facilitate joining and creating channels";
47 static void m_join(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
48 static void ms_join(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
49 static void ms_sjoin(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
51 static int h_can_create_channel
;
52 static int h_channel_join
;
54 struct Message join_msgtab
= {
56 {mg_unreg
, {m_join
, 2}, {ms_join
, 2}, mg_ignore
, mg_ignore
, {m_join
, 2}}
59 struct Message sjoin_msgtab
= {
61 {mg_unreg
, mg_ignore
, mg_ignore
, {ms_sjoin
, 4}, mg_ignore
, mg_ignore
}
64 mapi_clist_av1 join_clist
[] = { &join_msgtab
, &sjoin_msgtab
, NULL
};
66 mapi_hlist_av1 join_hlist
[] = {
67 { "can_create_channel", &h_can_create_channel
},
68 { "channel_join", &h_channel_join
},
72 DECLARE_MODULE_AV2(join
, NULL
, NULL
, join_clist
, join_hlist
, NULL
, NULL
, NULL
, join_desc
);
74 static void do_join_0(struct Client
*client_p
, struct Client
*source_p
);
75 static bool check_channel_name_loc(struct Client
*source_p
, const char *name
);
76 static void send_join_error(struct Client
*source_p
, int numeric
, const char *name
);
78 static void set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
);
79 static void remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
);
81 static void remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
82 rb_dlink_list
* list
, char c
, int mems
);
84 static char modebuf
[MODEBUFLEN
];
85 static char parabuf
[MODEBUFLEN
];
86 static const char *para
[MAXMODEPARAMS
];
90 /* Check what we will forward to, without sending any notices to the user
93 static struct Channel
*
94 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
98 const char *next
= NULL
;
100 /* The caller (m_join) is only interested in the reason
101 * for the original channel.
103 if ((*err
= can_join(source_p
, chptr
, key
, &next
)) == 0)
106 /* User is +Q, or forwarding disabled */
107 if (IsNoForward(source_p
) || !ConfigChannel
.use_forward
)
114 chptr
= find_channel(next
);
115 /* Can only forward to existing channels */
118 /* Already on there, show original error message */
119 if (IsMember(source_p
, chptr
))
121 /* Juped. Sending a warning notice would be unfair */
122 if (hash_find_resv(chptr
->chname
))
124 /* Don't forward to +Q channel */
125 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
127 i
= can_join(source_p
, chptr
, key
, &next
);
139 * parv[2] = channel password (key)
142 m_join(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
144 static char jbuf
[BUFSIZE
];
145 struct Channel
*chptr
= NULL
, *chptr2
= NULL
;
146 struct ConfItem
*aconf
;
151 char *p
= NULL
, *p2
= NULL
;
157 /* rebuild the list of channels theyre supposed to be joining.
158 * this code has a side effect of losing keys, but..
160 chanlist
= LOCAL_COPY(parv
[1]);
161 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
163 /* check the length and name of channel is ok */
164 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
166 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
167 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
171 /* join 0 parts all channels */
172 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
174 (void) strcpy(jbuf
, "0");
178 /* check it begins with # or &, and local chans are disabled */
179 else if(!IsChannelName(name
) ||
180 ( ConfigChannel
.disable_local_channels
&& name
[0] == '&'))
182 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
183 form_str(ERR_NOSUCHCHANNEL
), name
);
187 /* see if its resv'd */
188 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
190 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
191 form_str(ERR_BADCHANNAME
), name
);
193 /* dont warn for opers */
194 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
195 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
196 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
197 source_p
->name
, source_p
->username
,
198 source_p
->orighost
, name
, aconf
->passwd
);
199 /* dont update tracking for jupe exempt users, these
200 * are likely to be spamtrap leaves
202 else if(IsExemptJupe(source_p
))
208 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
209 ConfigChannel
.no_join_on_split
)
211 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
212 me
.name
, source_p
->name
, name
);
217 (void) strcat(jbuf
, ",");
218 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
223 mykey
= LOCAL_COPY(parv
[2]);
224 key
= rb_strtok_r(mykey
, ",", &p2
);
227 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
228 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
230 hook_data_channel_activity hook_info
;
232 /* JOIN 0 simply parts all channels the user is in */
233 if(*name
== '0' && !atoi(name
))
235 if(source_p
->user
->channel
.head
== NULL
)
238 do_join_0(&me
, source_p
);
242 /* look for the channel */
243 if((chptr
= find_channel(name
)) != NULL
)
245 if(IsMember(source_p
, chptr
))
252 hook_data_client_approval moduledata
;
254 moduledata
.client
= source_p
;
255 moduledata
.approved
= 0;
257 call_hook(h_can_create_channel
, &moduledata
);
259 if(moduledata
.approved
!= 0)
261 if(moduledata
.approved
!= ERR_CUSTOM
)
262 send_join_error(source_p
,
268 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
269 ConfigChannel
.no_create_on_split
)
271 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
272 me
.name
, source_p
->name
, name
);
279 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
280 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
281 (!IsExtendChans(source_p
) ||
282 (rb_dlink_list_length(&source_p
->user
->channel
) >=
283 (unsigned long) ConfigChannel
.max_chans_per_user_large
)))
285 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
286 me
.name
, source_p
->name
, name
);
290 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
292 chptr
= get_or_create_channel(source_p
, name
, NULL
);
296 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
297 me
.name
, source_p
->name
, name
);
302 /* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */
303 if(!(chptr2
= check_forward(source_p
, chptr
, key
, &i
)))
305 /* might be wrong, but is there any other better location for such?
306 * see extensions/chm_operonly.c for other comments on this
310 send_join_error(source_p
, i
, 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
|= ConfigChannel
.autochanmodes
;
345 modes
= channel_modes(chptr
, &me
);
347 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
348 me
.name
, chptr
->chname
, modes
);
350 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
351 ":%s SJOIN %ld %s %s :@%s",
352 me
.id
, (long) chptr
->channelts
,
353 chptr
->chname
, modes
, source_p
->id
);
357 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
359 use_id(source_p
), (long) chptr
->channelts
,
363 del_invite(chptr
, source_p
);
365 if(chptr
->topic
!= NULL
)
367 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
368 source_p
->name
, chptr
->chname
, chptr
->topic
);
370 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
371 me
.name
, source_p
->name
, chptr
->chname
,
373 (unsigned long)chptr
->topic_time
);
376 channel_member_names(chptr
, source_p
, 1);
378 hook_info
.client
= source_p
;
379 hook_info
.chptr
= chptr
;
381 call_hook(h_channel_join
, &hook_info
);
387 * parv[1] = channel TS
389 * parv[3] = "+", formerly channel modes but now unused
390 * alternatively, a single "0" parameter parts all channels
393 ms_join(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
395 struct Channel
*chptr
;
396 static struct Mode mode
;
400 bool keep_our_modes
= true;
401 rb_dlink_node
*ptr
, *next_ptr
;
403 /* special case for join 0 */
404 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
406 do_join_0(client_p
, source_p
);
413 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
416 /* joins for local channels cant happen. */
417 if(parv
[2][0] == '&')
421 mode
.key
[0] = mode
.forward
[0] = '\0';
422 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
424 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
427 newts
= atol(parv
[1]);
428 oldts
= chptr
->channelts
;
430 #ifdef IGNORE_BOGUS_TS
431 if(newts
< 800000000)
433 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
434 "*** Bogus TS %ld on %s ignored from %s",
435 (long) newts
, chptr
->chname
, client_p
->name
);
436 newts
= (oldts
== 0) ? oldts
: 800000000;
439 /* making a channel TS0 */
440 if(!isnew
&& !newts
&& oldts
)
442 sendto_channel_local(ALL_MEMBERS
, chptr
,
443 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
444 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
445 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
446 "Server %s changing TS on %s from %ld to 0",
447 source_p
->name
, chptr
->chname
, (long) oldts
);
452 chptr
->channelts
= newts
;
453 else if(newts
== 0 || oldts
== 0)
454 chptr
->channelts
= 0;
455 else if(newts
== oldts
)
457 else if(newts
< oldts
)
459 keep_our_modes
= false;
460 chptr
->channelts
= newts
;
463 /* Lost the TS, other side wins, so remove modes on this side */
466 set_final_mode(&mode
, &chptr
->mode
);
468 remove_our_modes(chptr
, source_p
);
469 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
471 del_invite(chptr
, ptr
->data
);
473 /* If setting -j, clear join throttle state -- jilles */
474 chptr
->join_count
= chptr
->join_delta
= 0;
475 sendto_channel_local(ALL_MEMBERS
, chptr
,
476 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
477 me
.name
, chptr
->chname
, chptr
->chname
,
478 (long) oldts
, (long) newts
);
479 /* Update capitalization in channel name, this makes the
480 * capitalization timestamped like modes are -- jilles */
481 strcpy(chptr
->chname
, parv
[2]);
483 sendto_channel_local(ALL_MEMBERS
, chptr
,
485 source_p
->servptr
->name
,
486 chptr
->chname
, modebuf
, parabuf
);
487 *modebuf
= *parabuf
= '\0';
489 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
490 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, false);
493 if(!IsMember(source_p
, chptr
))
495 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
496 if (chptr
->mode
.join_num
&&
497 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
499 chptr
->join_count
= 0;
500 chptr
->join_delta
= rb_current_time();
503 send_channel_join(chptr
, source_p
);
506 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
508 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
512 ms_sjoin(struct MsgBuf
*msgbuf_p
, 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 bool keep_our_modes
= true;
524 bool keep_new_modes
= true;
534 int i
, joinc
= 0, timeslice
= 0;
535 static char empty
[] = "";
536 rb_dlink_node
*ptr
, *next_ptr
;
541 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
544 /* SJOIN's for local channels can't happen. */
548 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
549 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
551 /* Hide connecting server on netburst -- jilles */
552 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
555 fakesource_p
= source_p
;
558 newts
= atol(parv
[1]);
566 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
572 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
574 mode
.join_num
= joinc
;
575 mode
.join_time
= timeslice
;
580 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
586 mode
.limit
= atoi(parv
[4 + args
]);
592 if(chmode_flags
[(int) *s
] != 0)
594 mode
.mode
|= chmode_flags
[(int) *s
];
603 /* remove any leading spaces */
610 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
611 return; /* channel name too long? */
614 oldts
= chptr
->channelts
;
615 oldmode
= &chptr
->mode
;
617 #ifdef IGNORE_BOGUS_TS
618 if(newts
< 800000000)
620 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
621 "*** Bogus TS %ld on %s ignored from %s",
622 (long) newts
, chptr
->chname
, client_p
->name
);
624 newts
= (oldts
== 0) ? oldts
: 800000000;
627 if(!isnew
&& !newts
&& oldts
)
629 sendto_channel_local(ALL_MEMBERS
, chptr
,
630 ":%s NOTICE %s :*** Notice -- TS for %s "
631 "changed from %ld to 0",
632 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
633 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
634 "Server %s changing TS on %s from %ld to 0",
635 source_p
->name
, chptr
->chname
, (long) oldts
);
640 chptr
->channelts
= newts
;
642 else if(newts
== 0 || oldts
== 0)
643 chptr
->channelts
= 0;
644 else if(newts
== oldts
)
646 else if(newts
< oldts
)
648 /* If configured, kick people trying to join +i/+k
649 * channels by recreating them on split servers.
650 * If the source has sent EOB, assume this is some
651 * sort of hack by services. If cmode +i is set,
652 * services can send kicks if needed; if the key
653 * differs, services cannot kick in a race-free
654 * manner so do so here.
656 if (ConfigChannel
.kick_on_split_riding
&&
657 ((!HasSentEob(source_p
) &&
658 mode
.mode
& MODE_INVITEONLY
) ||
659 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
661 struct membership
*msptr
;
663 int l
= rb_dlink_list_length(&chptr
->members
);
665 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
668 who
= msptr
->client_p
;
669 sendto_one(who
, ":%s KICK %s %s :Net Rider",
670 me
.name
, chptr
->chname
, who
->name
);
672 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
673 ":%s KICK %s %s :Net Rider",
674 me
.id
, chptr
->chname
,
676 remove_user_from_channel(msptr
);
682 /* Channel was emptied, create a new one */
683 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
686 oldmode
= &chptr
->mode
;
689 keep_our_modes
= false;
690 chptr
->channelts
= newts
;
693 keep_new_modes
= false;
697 else if(keep_our_modes
)
699 mode
.mode
|= oldmode
->mode
;
700 if(oldmode
->limit
> mode
.limit
)
701 mode
.limit
= oldmode
->limit
;
702 if(strcmp(mode
.key
, oldmode
->key
) < 0)
703 strcpy(mode
.key
, oldmode
->key
);
704 if(oldmode
->join_num
> mode
.join_num
||
705 (oldmode
->join_num
== mode
.join_num
&&
706 oldmode
->join_time
> mode
.join_time
))
708 mode
.join_num
= oldmode
->join_num
;
709 mode
.join_time
= oldmode
->join_time
;
711 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
712 strcpy(mode
.forward
, oldmode
->forward
);
716 /* If setting -j, clear join throttle state -- jilles */
718 chptr
->join_count
= chptr
->join_delta
= 0;
721 set_final_mode(&mode
, oldmode
);
724 /* Lost the TS, other side wins, so remove modes on this side */
727 remove_our_modes(chptr
, fakesource_p
);
728 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
730 del_invite(chptr
, ptr
->data
);
733 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
734 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
735 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
736 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
738 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
739 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
741 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
742 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
746 sendto_channel_local(ALL_MEMBERS
, chptr
,
747 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
748 me
.name
, chptr
->chname
, chptr
->chname
,
749 (long) oldts
, (long) newts
);
750 /* Update capitalization in channel name, this makes the
751 * capitalization timestamped like modes are -- jilles */
752 strcpy(chptr
->chname
, parv
[2]);
754 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
755 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, false);
759 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
760 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
762 *modebuf
= *parabuf
= '\0';
764 if(parv
[3][0] != '0' && keep_new_modes
)
765 modes
= channel_modes(chptr
, source_p
);
769 mlen_uid
= sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
770 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
771 ptr_uid
= buf_uid
+ mlen_uid
;
774 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
778 /* if theres a space, theres going to be more than one nick, change the
779 * first space to \0, so s is just the first nick, and point p to the
782 if((p
= strchr(s
, ' ')) != NULL
)
793 for (i
= 0; i
< 2; i
++)
807 /* if the client doesnt exist or is fake direction, skip. */
808 if(!(target_p
= find_client(s
)) ||
809 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
812 /* we assume for these we can fit at least one nick/uid in.. */
814 /* check we can fit another status+nick+space into a buffer */
815 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
817 *(ptr_uid
- 1) = '\0';
818 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
819 ptr_uid
= buf_uid
+ mlen_uid
;
837 /* copy the nick to the two buffers */
838 len
= 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
);
951 * inputs - pointer to client doing join 0
953 * side effects - Use has decided to join 0. This is legacy
954 * from the days when channels were numbers not names. *sigh*
957 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
959 struct membership
*msptr
;
960 struct Channel
*chptr
= NULL
;
963 /* Finish the flood grace period... */
964 if(MyClient(source_p
) && !IsFloodDone(source_p
))
965 flood_endgrace(source_p
);
967 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
969 while((ptr
= source_p
->user
->channel
.head
))
971 if(MyConnect(source_p
) &&
972 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
973 check_spambot_warning(source_p
, NULL
);
976 chptr
= msptr
->chptr
;
977 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
979 source_p
->username
, source_p
->host
, chptr
->chname
);
980 remove_user_from_channel(msptr
);
985 check_channel_name_loc(struct Client
*source_p
, const char *name
)
989 s_assert(name
!= NULL
);
990 if(EmptyString(name
))
993 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
995 for(p
= name
; *p
; ++p
)
997 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
1003 for(p
= name
; *p
; ++p
)
1010 if(ConfigChannel
.only_ascii_channels
)
1012 for(p
= name
; *p
; ++p
)
1013 if(*p
< 33 || *p
> 126)
1020 /* send_join_error()
1022 * input - client to send to, reason, channel name
1024 * side effects - error message sent to client
1027 send_join_error(struct Client
*source_p
, int numeric
, const char *name
)
1029 /* This stuff is necessary because the form_str macro only
1030 * accepts constants.
1034 #define NORMAL_NUMERIC(i) \
1036 sendto_one(source_p, form_str(i), \
1037 me.name, source_p->name, name); \
1040 NORMAL_NUMERIC(ERR_BANNEDFROMCHAN
);
1041 NORMAL_NUMERIC(ERR_INVITEONLYCHAN
);
1042 NORMAL_NUMERIC(ERR_BADCHANNELKEY
);
1043 NORMAL_NUMERIC(ERR_CHANNELISFULL
);
1044 NORMAL_NUMERIC(ERR_NEEDREGGEDNICK
);
1045 NORMAL_NUMERIC(ERR_THROTTLE
);
1048 sendto_one_numeric(source_p
, numeric
,
1049 "%s :Cannot join channel", name
);
1055 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1057 int dir
= MODE_QUERY
;
1058 char *pbuf
= parabuf
;
1062 /* ok, first get a list of modes we need to add */
1063 for (i
= 0; i
< 256; i
++)
1065 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1076 /* now the ones we need to remove. */
1077 for (i
= 0; i
< 256; i
++)
1079 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1090 if(oldmode
->limit
&& !mode
->limit
)
1099 if(oldmode
->key
[0] && !mode
->key
[0])
1107 len
= sprintf(pbuf
, "%s ", oldmode
->key
);
1110 if(oldmode
->join_num
&& !mode
->join_num
)
1119 if(oldmode
->forward
[0] && !mode
->forward
[0])
1128 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1136 len
= sprintf(pbuf
, "%d ", mode
->limit
);
1139 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1147 len
= sprintf(pbuf
, "%s ", mode
->key
);
1150 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1158 len
= sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1161 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) &&
1162 ConfigChannel
.use_forward
)
1170 len
= sprintf(pbuf
, "%s ", mode
->forward
);
1184 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1186 struct membership
*msptr
;
1188 char lmodebuf
[MODEBUFLEN
];
1189 char *lpara
[MAXMODEPARAMS
];
1196 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1199 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1203 if(is_chanop(msptr
))
1205 msptr
->flags
&= ~CHFL_CHANOP
;
1206 lpara
[count
++] = msptr
->client_p
->name
;
1209 /* +ov, might not fit so check. */
1210 if(is_voiced(msptr
))
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
,
1218 lmodebuf
, lpara
[0], lpara
[1],
1219 lpara
[2], lpara
[3]);
1221 /* preserve the initial '-' */
1226 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1230 msptr
->flags
&= ~CHFL_VOICE
;
1231 lpara
[count
++] = msptr
->client_p
->name
;
1235 else if(is_voiced(msptr
))
1237 msptr
->flags
&= ~CHFL_VOICE
;
1238 lpara
[count
++] = msptr
->client_p
->name
;
1244 if(count
>= MAXMODEPARAMS
)
1247 sendto_channel_local(ALL_MEMBERS
, chptr
,
1248 ":%s MODE %s %s %s %s %s %s",
1249 source_p
->name
, chptr
->chname
, lmodebuf
,
1250 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1255 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1263 sendto_channel_local(ALL_MEMBERS
, chptr
,
1264 ":%s MODE %s %s %s %s %s %s",
1265 source_p
->name
, chptr
->chname
, lmodebuf
,
1266 EmptyString(lpara
[0]) ? "" : lpara
[0],
1267 EmptyString(lpara
[1]) ? "" : lpara
[1],
1268 EmptyString(lpara
[2]) ? "" : lpara
[2],
1269 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1274 /* remove_ban_list()
1276 * inputs - channel, source, list to remove, char of mode, caps needed
1278 * side effects - given list is removed, with modes issued to local clients
1281 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1282 rb_dlink_list
* list
, char c
, int mems
)
1284 static char lmodebuf
[BUFSIZE
];
1285 static char lparabuf
[BUFSIZE
];
1288 rb_dlink_node
*next_ptr
;
1291 int cur_len
, mlen
, plen
;
1295 cur_len
= mlen
= sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1296 mbuf
= lmodebuf
+ mlen
;
1298 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1302 /* trailing space, and the mode letter itself */
1303 plen
= strlen(banptr
->banstr
) +
1304 (banptr
->forward
? strlen(banptr
->forward
) + 1 : 0) + 2;
1306 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1308 /* remove trailing space */
1312 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1315 mbuf
= lmodebuf
+ mlen
;
1322 if (banptr
->forward
)
1323 pbuf
+= sprintf(pbuf
, "%s$%s ", banptr
->banstr
, banptr
->forward
);
1325 pbuf
+= sprintf(pbuf
, "%s ", banptr
->banstr
);
1333 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1335 list
->head
= list
->tail
= NULL
;