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 int m_join(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
46 static int ms_join(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
47 static int ms_sjoin(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
48 static const char join_desc
[] = "Provides the JOIN and TS6 SJOIN commands to facilitate joining and creating channels";
50 static int h_can_create_channel
;
51 static int h_channel_join
;
53 struct Message join_msgtab
= {
55 {mg_unreg
, {m_join
, 2}, {ms_join
, 2}, mg_ignore
, mg_ignore
, {m_join
, 2}}
58 struct Message sjoin_msgtab
= {
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_AV2(join
, NULL
, NULL
, join_clist
, join_hlist
, NULL
, NULL
, NULL
, join_desc
);
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
);
75 static void send_join_error(struct Client
*source_p
, int numeric
, const char *name
);
77 static void set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
);
78 static void remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
);
80 static void remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
81 rb_dlink_list
* list
, char c
, int mems
);
83 static char modebuf
[MODEBUFLEN
];
84 static char parabuf
[MODEBUFLEN
];
85 static const char *para
[MAXMODEPARAMS
];
89 /* Check what we will forward to, without sending any notices to the user
92 static struct Channel
*
93 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
97 const char *next
= NULL
;
99 /* The caller (m_join) is only interested in the reason
100 * for the original channel.
102 if ((*err
= can_join(source_p
, chptr
, key
, &next
)) == 0)
105 /* User is +Q, or forwarding disabled */
106 if (IsNoForward(source_p
) || !ConfigChannel
.use_forward
)
113 chptr
= find_channel(next
);
114 /* Can only forward to existing channels */
117 /* Already on there, show original error message */
118 if (IsMember(source_p
, chptr
))
120 /* Juped. Sending a warning notice would be unfair */
121 if (hash_find_resv(chptr
->chname
))
123 /* Don't forward to +Q channel */
124 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
126 i
= can_join(source_p
, chptr
, key
, &next
);
138 * parv[2] = channel password (key)
141 m_join(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
143 static char jbuf
[BUFSIZE
];
144 struct Channel
*chptr
= NULL
, *chptr2
= NULL
;
145 struct ConfItem
*aconf
;
150 char *p
= NULL
, *p2
= NULL
;
156 /* rebuild the list of channels theyre supposed to be joining.
157 * this code has a side effect of losing keys, but..
159 chanlist
= LOCAL_COPY(parv
[1]);
160 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
162 /* check the length and name of channel is ok */
163 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
165 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
166 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
170 /* join 0 parts all channels */
171 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
173 (void) strcpy(jbuf
, "0");
177 /* check it begins with # or &, and local chans are disabled */
178 else if(!IsChannelName(name
) ||
179 ( ConfigChannel
.disable_local_channels
&& name
[0] == '&'))
181 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
182 form_str(ERR_NOSUCHCHANNEL
), name
);
186 /* see if its resv'd */
187 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
189 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
190 form_str(ERR_BADCHANNAME
), name
);
192 /* dont warn for opers */
193 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
194 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
195 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
196 source_p
->name
, source_p
->username
,
197 source_p
->orighost
, name
, aconf
->passwd
);
198 /* dont update tracking for jupe exempt users, these
199 * are likely to be spamtrap leaves
201 else if(IsExemptJupe(source_p
))
207 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
208 ConfigChannel
.no_join_on_split
)
210 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
211 me
.name
, source_p
->name
, name
);
216 (void) strcat(jbuf
, ",");
217 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
222 mykey
= LOCAL_COPY(parv
[2]);
223 key
= rb_strtok_r(mykey
, ",", &p2
);
226 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
227 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
229 hook_data_channel_activity hook_info
;
231 /* JOIN 0 simply parts all channels the user is in */
232 if(*name
== '0' && !atoi(name
))
234 if(source_p
->user
->channel
.head
== NULL
)
237 do_join_0(&me
, source_p
);
241 /* look for the channel */
242 if((chptr
= find_channel(name
)) != NULL
)
244 if(IsMember(source_p
, chptr
))
251 hook_data_client_approval moduledata
;
253 moduledata
.client
= source_p
;
254 moduledata
.approved
= 0;
256 call_hook(h_can_create_channel
, &moduledata
);
258 if(moduledata
.approved
!= 0)
260 if(moduledata
.approved
!= ERR_CUSTOM
)
261 send_join_error(source_p
,
267 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
268 ConfigChannel
.no_create_on_split
)
270 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
271 me
.name
, source_p
->name
, name
);
278 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
279 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
280 (!IsExtendChans(source_p
) ||
281 (rb_dlink_list_length(&source_p
->user
->channel
) >=
282 (unsigned long) ConfigChannel
.max_chans_per_user_large
)))
284 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
285 me
.name
, source_p
->name
, name
);
289 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
291 chptr
= get_or_create_channel(source_p
, name
, NULL
);
295 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
296 me
.name
, source_p
->name
, name
);
301 /* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */
302 if(!(chptr2
= check_forward(source_p
, chptr
, key
, &i
)))
304 /* might be wrong, but is there any other better location for such?
305 * see extensions/chm_operonly.c for other comments on this
309 send_join_error(source_p
, i
, name
);
312 else if(chptr
!= chptr2
)
313 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr2
->chname
);
318 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
319 check_spambot_warning(source_p
, name
);
321 /* add the user to the channel */
322 add_user_to_channel(chptr
, source_p
, flags
);
323 if (chptr
->mode
.join_num
&&
324 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
326 chptr
->join_count
= 0;
327 chptr
->join_delta
= rb_current_time();
331 /* credit user for join */
332 credit_client_join(source_p
);
334 /* we send the user their join here, because we could have to
335 * send a mode out next.
337 send_channel_join(chptr
, source_p
);
339 /* its a new channel, set +nt and burst. */
340 if(flags
& CHFL_CHANOP
)
342 chptr
->channelts
= rb_current_time();
343 chptr
->mode
.mode
|= ConfigChannel
.autochanmodes
;
344 modes
= channel_modes(chptr
, &me
);
346 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
347 me
.name
, chptr
->chname
, modes
);
349 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
350 ":%s SJOIN %ld %s %s :@%s",
351 me
.id
, (long) chptr
->channelts
,
352 chptr
->chname
, modes
, source_p
->id
);
356 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
358 use_id(source_p
), (long) chptr
->channelts
,
362 del_invite(chptr
, source_p
);
364 if(chptr
->topic
!= NULL
)
366 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
367 source_p
->name
, chptr
->chname
, chptr
->topic
);
369 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
370 me
.name
, source_p
->name
, chptr
->chname
,
372 (unsigned long)chptr
->topic_time
);
375 channel_member_names(chptr
, source_p
, 1);
377 hook_info
.client
= source_p
;
378 hook_info
.chptr
= chptr
;
380 call_hook(h_channel_join
, &hook_info
);
388 * parv[1] = channel TS
390 * parv[3] = "+", formerly channel modes but now unused
391 * alternatively, a single "0" parameter parts all channels
394 ms_join(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
396 struct Channel
*chptr
;
397 static struct Mode mode
;
401 int keep_our_modes
= YES
;
402 rb_dlink_node
*ptr
, *next_ptr
;
404 /* special case for join 0 */
405 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
407 do_join_0(client_p
, source_p
);
414 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
417 /* joins for local channels cant happen. */
418 if(parv
[2][0] == '&')
422 mode
.key
[0] = mode
.forward
[0] = '\0';
423 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
425 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
428 newts
= atol(parv
[1]);
429 oldts
= chptr
->channelts
;
431 #ifdef IGNORE_BOGUS_TS
432 if(newts
< 800000000)
434 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
435 "*** Bogus TS %ld on %s ignored from %s",
436 (long) newts
, chptr
->chname
, client_p
->name
);
437 newts
= (oldts
== 0) ? oldts
: 800000000;
440 /* making a channel TS0 */
441 if(!isnew
&& !newts
&& oldts
)
443 sendto_channel_local(ALL_MEMBERS
, chptr
,
444 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
445 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
446 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
447 "Server %s changing TS on %s from %ld to 0",
448 source_p
->name
, chptr
->chname
, (long) oldts
);
453 chptr
->channelts
= newts
;
454 else if(newts
== 0 || oldts
== 0)
455 chptr
->channelts
= 0;
456 else if(newts
== oldts
)
458 else if(newts
< oldts
)
461 chptr
->channelts
= newts
;
464 /* Lost the TS, other side wins, so remove modes on this side */
467 set_final_mode(&mode
, &chptr
->mode
);
469 remove_our_modes(chptr
, source_p
);
470 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
472 del_invite(chptr
, ptr
->data
);
474 /* If setting -j, clear join throttle state -- jilles */
475 chptr
->join_count
= chptr
->join_delta
= 0;
476 sendto_channel_local(ALL_MEMBERS
, chptr
,
477 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
478 me
.name
, chptr
->chname
, chptr
->chname
,
479 (long) oldts
, (long) newts
);
480 /* Update capitalization in channel name, this makes the
481 * capitalization timestamped like modes are -- jilles */
482 strcpy(chptr
->chname
, parv
[2]);
484 sendto_channel_local(ALL_MEMBERS
, chptr
,
486 source_p
->servptr
->name
,
487 chptr
->chname
, modebuf
, parabuf
);
488 *modebuf
= *parabuf
= '\0';
490 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
491 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, FALSE
);
494 if(!IsMember(source_p
, chptr
))
496 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
497 if (chptr
->mode
.join_num
&&
498 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
500 chptr
->join_count
= 0;
501 chptr
->join_delta
= rb_current_time();
504 send_channel_join(chptr
, source_p
);
507 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
509 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
514 ms_sjoin(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
516 static char buf_uid
[BUFSIZE
];
517 static const char empty_modes
[] = "0";
518 struct Channel
*chptr
;
519 struct Client
*target_p
, *fakesource_p
;
522 static struct Mode mode
, *oldmode
;
525 int keep_our_modes
= 1;
526 int keep_new_modes
= 1;
536 int i
, joinc
= 0, timeslice
= 0;
537 static char empty
[] = "";
538 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
= 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
;
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
;
839 /* copy the nick to the two buffers */
840 len
= sprintf(ptr_uid
, "%s ", use_id(target_p
));
847 if(!IsMember(target_p
, chptr
))
849 add_user_to_channel(chptr
, target_p
, fl
);
850 send_channel_join(chptr
, target_p
);
857 para
[pargs
++] = target_p
->name
;
859 /* a +ov user.. bleh */
862 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
865 if(pargs
>= MAXMODEPARAMS
)
868 sendto_channel_local(ALL_MEMBERS
, chptr
,
869 ":%s MODE %s %s %s %s %s %s",
870 fakesource_p
->name
, chptr
->chname
,
872 para
[0], para
[1], para
[2], para
[3]);
875 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
880 para
[pargs
++] = target_p
->name
;
883 else if(fl
& CHFL_VOICE
)
886 para
[pargs
++] = target_p
->name
;
889 if(pargs
>= MAXMODEPARAMS
)
892 sendto_channel_local(ALL_MEMBERS
, chptr
,
893 ":%s MODE %s %s %s %s %s %s",
896 modebuf
, para
[0], para
[1], para
[2], para
[3]);
899 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
904 /* p points to the next nick */
907 /* if there was a trailing space and p was pointing to it, then we
908 * need to exit.. this has the side effect of breaking double spaces
909 * in an sjoin.. but that shouldnt happen anyway
911 if(s
&& (*s
== '\0'))
914 /* if p was NULL due to no spaces, s wont exist due to the above, so
915 * we cant check it for spaces.. if there are no spaces, then when
916 * we next get here, s will be NULL
918 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
927 sendto_channel_local(ALL_MEMBERS
, chptr
,
928 ":%s MODE %s %s %s %s %s %s",
929 fakesource_p
->name
, chptr
->chname
, modebuf
,
930 para
[0], CheckEmpty(para
[1]),
931 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
934 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
936 destroy_channel(chptr
);
941 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
944 *(ptr_uid
- 1) = '\0';
947 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
955 * inputs - pointer to client doing join 0
957 * side effects - Use has decided to join 0. This is legacy
958 * from the days when channels were numbers not names. *sigh*
961 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
963 struct membership
*msptr
;
964 struct Channel
*chptr
= NULL
;
967 /* Finish the flood grace period... */
968 if(MyClient(source_p
) && !IsFloodDone(source_p
))
969 flood_endgrace(source_p
);
971 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
973 while((ptr
= source_p
->user
->channel
.head
))
975 if(MyConnect(source_p
) &&
976 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
977 check_spambot_warning(source_p
, NULL
);
980 chptr
= msptr
->chptr
;
981 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
983 source_p
->username
, source_p
->host
, chptr
->chname
);
984 remove_user_from_channel(msptr
);
989 check_channel_name_loc(struct Client
*source_p
, const char *name
)
993 s_assert(name
!= NULL
);
994 if(EmptyString(name
))
997 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
999 for(p
= name
; *p
; ++p
)
1001 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
1007 for(p
= name
; *p
; ++p
)
1014 if(ConfigChannel
.only_ascii_channels
)
1016 for(p
= name
; *p
; ++p
)
1017 if(*p
< 33 || *p
> 126)
1024 /* send_join_error()
1026 * input - client to send to, reason, channel name
1028 * side effects - error message sent to client
1031 send_join_error(struct Client
*source_p
, int numeric
, const char *name
)
1033 /* This stuff is necessary because the form_str macro only
1034 * accepts constants.
1038 #define NORMAL_NUMERIC(i) \
1040 sendto_one(source_p, form_str(i), \
1041 me.name, source_p->name, name); \
1044 NORMAL_NUMERIC(ERR_BANNEDFROMCHAN
);
1045 NORMAL_NUMERIC(ERR_INVITEONLYCHAN
);
1046 NORMAL_NUMERIC(ERR_BADCHANNELKEY
);
1047 NORMAL_NUMERIC(ERR_CHANNELISFULL
);
1048 NORMAL_NUMERIC(ERR_NEEDREGGEDNICK
);
1049 NORMAL_NUMERIC(ERR_THROTTLE
);
1052 sendto_one_numeric(source_p
, numeric
,
1053 "%s :Cannot join channel", name
);
1059 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1061 int dir
= MODE_QUERY
;
1062 char *pbuf
= parabuf
;
1066 /* ok, first get a list of modes we need to add */
1067 for (i
= 0; i
< 256; i
++)
1069 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1080 /* now the ones we need to remove. */
1081 for (i
= 0; i
< 256; i
++)
1083 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1094 if(oldmode
->limit
&& !mode
->limit
)
1103 if(oldmode
->key
[0] && !mode
->key
[0])
1111 len
= sprintf(pbuf
, "%s ", oldmode
->key
);
1114 if(oldmode
->join_num
&& !mode
->join_num
)
1123 if(oldmode
->forward
[0] && !mode
->forward
[0])
1132 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1140 len
= sprintf(pbuf
, "%d ", mode
->limit
);
1143 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1151 len
= sprintf(pbuf
, "%s ", mode
->key
);
1154 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1162 len
= sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1165 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) &&
1166 ConfigChannel
.use_forward
)
1174 len
= sprintf(pbuf
, "%s ", mode
->forward
);
1188 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1190 struct membership
*msptr
;
1192 char lmodebuf
[MODEBUFLEN
];
1193 char *lpara
[MAXMODEPARAMS
];
1200 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1203 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1207 if(is_chanop(msptr
))
1209 msptr
->flags
&= ~CHFL_CHANOP
;
1210 lpara
[count
++] = msptr
->client_p
->name
;
1213 /* +ov, might not fit so check. */
1214 if(is_voiced(msptr
))
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
,
1222 lmodebuf
, lpara
[0], lpara
[1],
1223 lpara
[2], lpara
[3]);
1225 /* preserve the initial '-' */
1230 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1234 msptr
->flags
&= ~CHFL_VOICE
;
1235 lpara
[count
++] = msptr
->client_p
->name
;
1239 else if(is_voiced(msptr
))
1241 msptr
->flags
&= ~CHFL_VOICE
;
1242 lpara
[count
++] = msptr
->client_p
->name
;
1248 if(count
>= MAXMODEPARAMS
)
1251 sendto_channel_local(ALL_MEMBERS
, chptr
,
1252 ":%s MODE %s %s %s %s %s %s",
1253 source_p
->name
, chptr
->chname
, lmodebuf
,
1254 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1259 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1267 sendto_channel_local(ALL_MEMBERS
, chptr
,
1268 ":%s MODE %s %s %s %s %s %s",
1269 source_p
->name
, chptr
->chname
, lmodebuf
,
1270 EmptyString(lpara
[0]) ? "" : lpara
[0],
1271 EmptyString(lpara
[1]) ? "" : lpara
[1],
1272 EmptyString(lpara
[2]) ? "" : lpara
[2],
1273 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1278 /* remove_ban_list()
1280 * inputs - channel, source, list to remove, char of mode, caps needed
1282 * side effects - given list is removed, with modes issued to local clients
1285 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1286 rb_dlink_list
* list
, char c
, int mems
)
1288 static char lmodebuf
[BUFSIZE
];
1289 static char lparabuf
[BUFSIZE
];
1292 rb_dlink_node
*next_ptr
;
1295 int cur_len
, mlen
, plen
;
1299 cur_len
= mlen
= sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1300 mbuf
= lmodebuf
+ mlen
;
1302 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1306 /* trailing space, and the mode letter itself */
1307 plen
= strlen(banptr
->banstr
) +
1308 (banptr
->forward
? strlen(banptr
->forward
) + 1 : 0) + 2;
1310 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1312 /* remove trailing space */
1316 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1319 mbuf
= lmodebuf
+ mlen
;
1326 if (banptr
->forward
)
1327 pbuf
+= sprintf(pbuf
, "%s$%s ", banptr
->banstr
, banptr
->forward
);
1329 pbuf
+= sprintf(pbuf
, "%s ", banptr
->banstr
);
1337 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1339 list
->head
= list
->tail
= NULL
;