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
35 #include "s_newconf.h"
41 #include "ratelimit.h"
44 static const char join_desc
[] = "Provides the JOIN and TS6 SJOIN commands to facilitate joining and creating channels";
46 static void m_join(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
47 static void ms_join(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
48 static void ms_sjoin(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
50 static int h_can_create_channel
;
51 static int h_channel_join
;
53 struct Message join_msgtab
= {
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 bool 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
)
114 chptr
= find_channel(next
);
115 /* Can only forward to existing channels */
118 /* Already on there... but don't send the original reason for
119 * being unable to join. It isn't their fault they're already
120 * on the channel, and it looks hostile otherwise.
123 if (IsMember(source_p
, chptr
))
125 *err
= ERR_USERONCHANNEL
; /* I'm borrowing this for now. --Elizafox */
128 /* Juped. Sending a warning notice would be unfair */
129 if (hash_find_resv(chptr
->chname
))
131 /* Don't forward to +Q channel */
132 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
135 i
= can_join(source_p
, chptr
, key
, &next
);
147 * parv[2] = channel password (key)
150 m_join(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
152 static char jbuf
[BUFSIZE
];
153 struct Channel
*chptr
= NULL
, *chptr2
= NULL
;
154 struct ConfItem
*aconf
;
159 char *p
= NULL
, *p2
= NULL
;
165 /* rebuild the list of channels theyre supposed to be joining.
166 * this code has a side effect of losing keys, but..
168 chanlist
= LOCAL_COPY(parv
[1]);
169 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
171 /* check the length and name of channel is ok */
172 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
174 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
175 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
179 /* join 0 parts all channels */
180 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
182 (void) strcpy(jbuf
, "0");
186 /* check it begins with # or &, and local chans are disabled */
187 else if(!IsChannelName(name
) ||
188 ( ConfigChannel
.disable_local_channels
&& name
[0] == '&'))
190 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
191 form_str(ERR_NOSUCHCHANNEL
), name
);
195 /* see if its resv'd */
196 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
198 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
199 form_str(ERR_BADCHANNAME
), name
);
201 /* dont warn for opers */
202 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
203 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
204 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
205 source_p
->name
, source_p
->username
,
206 source_p
->orighost
, name
, aconf
->passwd
);
207 /* dont update tracking for jupe exempt users, these
208 * are likely to be spamtrap leaves
210 else if(IsExemptJupe(source_p
))
216 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
217 ConfigChannel
.no_join_on_split
)
219 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
220 me
.name
, source_p
->name
, name
);
225 (void) strcat(jbuf
, ",");
226 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
231 mykey
= LOCAL_COPY(parv
[2]);
232 key
= rb_strtok_r(mykey
, ",", &p2
);
235 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
236 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
238 hook_data_channel_activity hook_info
;
240 /* JOIN 0 simply parts all channels the user is in */
241 if(*name
== '0' && !atoi(name
))
243 if(source_p
->user
->channel
.head
== NULL
)
246 do_join_0(&me
, source_p
);
250 /* look for the channel */
251 if((chptr
= find_channel(name
)) != NULL
)
253 if(IsMember(source_p
, chptr
))
260 hook_data_client_approval moduledata
;
262 moduledata
.client
= source_p
;
263 moduledata
.approved
= 0;
265 call_hook(h_can_create_channel
, &moduledata
);
267 if(moduledata
.approved
!= 0)
269 if(moduledata
.approved
!= ERR_CUSTOM
)
270 send_join_error(source_p
,
276 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
277 ConfigChannel
.no_create_on_split
)
279 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
280 me
.name
, source_p
->name
, name
);
287 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
288 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
289 (!IsExtendChans(source_p
) ||
290 (rb_dlink_list_length(&source_p
->user
->channel
) >=
291 (unsigned long) ConfigChannel
.max_chans_per_user_large
)))
293 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
294 me
.name
, source_p
->name
, name
);
298 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
300 chptr
= get_or_create_channel(source_p
, name
, NULL
);
304 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
305 me
.name
, source_p
->name
, name
);
310 /* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */
311 if((chptr2
= check_forward(source_p
, chptr
, key
, &i
)) == NULL
)
313 /* might be wrong, but is there any other better location for such?
314 * see extensions/chm_operonly.c for other comments on this
318 send_join_error(source_p
, i
, name
);
321 else if(chptr
!= chptr2
)
322 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr2
->chname
);
327 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
328 check_spambot_warning(source_p
, name
);
330 /* add the user to the channel */
331 add_user_to_channel(chptr
, source_p
, flags
);
332 if (chptr
->mode
.join_num
&&
333 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
335 chptr
->join_count
= 0;
336 chptr
->join_delta
= rb_current_time();
340 /* credit user for join */
341 credit_client_join(source_p
);
343 /* we send the user their join here, because we could have to
344 * send a mode out next.
346 send_channel_join(chptr
, source_p
);
348 /* its a new channel, set +nt and burst. */
349 if(flags
& CHFL_CHANOP
)
351 chptr
->channelts
= rb_current_time();
352 chptr
->mode
.mode
|= ConfigChannel
.autochanmodes
;
353 modes
= channel_modes(chptr
, &me
);
355 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
356 me
.name
, chptr
->chname
, modes
);
358 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
359 ":%s SJOIN %ld %s %s :@%s",
360 me
.id
, (long) chptr
->channelts
,
361 chptr
->chname
, modes
, source_p
->id
);
365 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
367 use_id(source_p
), (long) chptr
->channelts
,
371 del_invite(chptr
, source_p
);
373 if(chptr
->topic
!= NULL
)
375 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
376 source_p
->name
, chptr
->chname
, chptr
->topic
);
378 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
379 me
.name
, source_p
->name
, chptr
->chname
,
381 (unsigned long)chptr
->topic_time
);
384 channel_member_names(chptr
, source_p
, 1);
386 hook_info
.client
= source_p
;
387 hook_info
.chptr
= chptr
;
389 call_hook(h_channel_join
, &hook_info
);
395 * parv[1] = channel TS
397 * parv[3] = "+", formerly channel modes but now unused
398 * alternatively, a single "0" parameter parts all channels
401 ms_join(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
403 struct Channel
*chptr
;
404 static struct Mode mode
;
408 bool keep_our_modes
= true;
409 rb_dlink_node
*ptr
, *next_ptr
;
411 /* special case for join 0 */
412 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
414 do_join_0(client_p
, source_p
);
421 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
424 /* joins for local channels cant happen. */
425 if(parv
[2][0] == '&')
429 mode
.key
[0] = mode
.forward
[0] = '\0';
430 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
432 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
435 newts
= atol(parv
[1]);
436 oldts
= chptr
->channelts
;
438 /* making a channel TS0 */
439 if(!isnew
&& !newts
&& oldts
)
441 sendto_channel_local(ALL_MEMBERS
, chptr
,
442 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
443 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
444 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
445 "Server %s changing TS on %s from %ld to 0",
446 source_p
->name
, chptr
->chname
, (long) oldts
);
450 chptr
->channelts
= newts
;
451 else if(newts
== 0 || oldts
== 0)
452 chptr
->channelts
= 0;
453 else if(newts
== oldts
)
455 else if(newts
< oldts
)
457 keep_our_modes
= false;
458 chptr
->channelts
= newts
;
461 /* Lost the TS, other side wins, so remove modes on this side */
464 set_final_mode(&mode
, &chptr
->mode
);
466 remove_our_modes(chptr
, source_p
);
467 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
469 del_invite(chptr
, ptr
->data
);
471 /* If setting -j, clear join throttle state -- jilles */
472 chptr
->join_count
= chptr
->join_delta
= 0;
473 sendto_channel_local(ALL_MEMBERS
, chptr
,
474 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
475 me
.name
, chptr
->chname
, chptr
->chname
,
476 (long) oldts
, (long) newts
);
477 /* Update capitalization in channel name, this makes the
478 * capitalization timestamped like modes are -- jilles */
479 strcpy(chptr
->chname
, parv
[2]);
481 sendto_channel_local(ALL_MEMBERS
, chptr
,
483 source_p
->servptr
->name
,
484 chptr
->chname
, modebuf
, parabuf
);
485 *modebuf
= *parabuf
= '\0';
487 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
488 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, false);
491 if(!IsMember(source_p
, chptr
))
493 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
494 if (chptr
->mode
.join_num
&&
495 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
497 chptr
->join_count
= 0;
498 chptr
->join_delta
= rb_current_time();
501 send_channel_join(chptr
, source_p
);
504 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
506 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
510 ms_sjoin(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
512 static char buf_uid
[BUFSIZE
];
513 static const char empty_modes
[] = "0";
514 struct Channel
*chptr
;
515 struct Client
*target_p
, *fakesource_p
;
518 static struct Mode mode
, *oldmode
;
521 bool keep_our_modes
= true;
522 bool keep_new_modes
= true;
532 int i
, joinc
= 0, timeslice
= 0;
533 static char empty
[] = "";
534 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; /* channel name too long? */
612 oldts
= chptr
->channelts
;
613 oldmode
= &chptr
->mode
;
615 if(!isnew
&& !newts
&& oldts
)
617 sendto_channel_local(ALL_MEMBERS
, chptr
,
618 ":%s NOTICE %s :*** Notice -- TS for %s "
619 "changed from %ld to 0",
620 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
621 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
622 "Server %s changing TS on %s from %ld to 0",
623 source_p
->name
, chptr
->chname
, (long) oldts
);
627 chptr
->channelts
= newts
;
629 else if(newts
== 0 || oldts
== 0)
630 chptr
->channelts
= 0;
631 else if(newts
== oldts
)
633 else if(newts
< oldts
)
635 /* If configured, kick people trying to join +i/+k
636 * channels by recreating them on split servers.
637 * If the source has sent EOB, assume this is some
638 * sort of hack by services. If cmode +i is set,
639 * services can send kicks if needed; if the key
640 * differs, services cannot kick in a race-free
641 * manner so do so here.
643 if (ConfigChannel
.kick_on_split_riding
&&
644 ((!HasSentEob(source_p
) &&
645 mode
.mode
& MODE_INVITEONLY
) ||
646 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
648 struct membership
*msptr
;
650 int l
= rb_dlink_list_length(&chptr
->members
);
652 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
655 who
= msptr
->client_p
;
656 sendto_one(who
, ":%s KICK %s %s :Net Rider",
657 me
.name
, chptr
->chname
, who
->name
);
659 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
660 ":%s KICK %s %s :Net Rider",
661 me
.id
, chptr
->chname
,
663 remove_user_from_channel(msptr
);
669 /* Channel was emptied, create a new one */
670 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
673 oldmode
= &chptr
->mode
;
676 keep_our_modes
= false;
677 chptr
->channelts
= newts
;
680 keep_new_modes
= false;
684 else if(keep_our_modes
)
686 mode
.mode
|= oldmode
->mode
;
687 if(oldmode
->limit
> mode
.limit
)
688 mode
.limit
= oldmode
->limit
;
689 if(strcmp(mode
.key
, oldmode
->key
) < 0)
690 strcpy(mode
.key
, oldmode
->key
);
691 if(oldmode
->join_num
> mode
.join_num
||
692 (oldmode
->join_num
== mode
.join_num
&&
693 oldmode
->join_time
> mode
.join_time
))
695 mode
.join_num
= oldmode
->join_num
;
696 mode
.join_time
= oldmode
->join_time
;
698 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
699 strcpy(mode
.forward
, oldmode
->forward
);
703 /* If setting -j, clear join throttle state -- jilles */
705 chptr
->join_count
= chptr
->join_delta
= 0;
708 set_final_mode(&mode
, oldmode
);
711 /* Lost the TS, other side wins, so remove modes on this side */
714 remove_our_modes(chptr
, fakesource_p
);
715 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
717 del_invite(chptr
, ptr
->data
);
720 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
721 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
722 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
723 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
725 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
726 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
728 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
729 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
733 sendto_channel_local(ALL_MEMBERS
, chptr
,
734 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
735 me
.name
, chptr
->chname
, chptr
->chname
,
736 (long) oldts
, (long) newts
);
737 /* Update capitalization in channel name, this makes the
738 * capitalization timestamped like modes are -- jilles */
739 strcpy(chptr
->chname
, parv
[2]);
741 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
742 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, false);
746 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
747 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
749 *modebuf
= *parabuf
= '\0';
751 if(parv
[3][0] != '0' && keep_new_modes
)
752 modes
= channel_modes(chptr
, source_p
);
756 mlen_uid
= sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
757 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
758 ptr_uid
= buf_uid
+ mlen_uid
;
761 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
765 /* if theres a space, theres going to be more than one nick, change the
766 * first space to \0, so s is just the first nick, and point p to the
769 if((p
= strchr(s
, ' ')) != NULL
)
780 for (i
= 0; i
< 2; i
++)
794 /* if the client doesnt exist or is fake direction, skip. */
795 if(!(target_p
= find_client(s
)) ||
796 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
799 /* we assume for these we can fit at least one nick/uid in.. */
801 /* check we can fit another status+nick+space into a buffer */
802 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
804 *(ptr_uid
- 1) = '\0';
805 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
806 ptr_uid
= buf_uid
+ mlen_uid
;
824 /* copy the nick to the two buffers */
825 len
= sprintf(ptr_uid
, "%s ", use_id(target_p
));
832 if(!IsMember(target_p
, chptr
))
834 add_user_to_channel(chptr
, target_p
, fl
);
835 send_channel_join(chptr
, target_p
);
842 para
[pargs
++] = target_p
->name
;
844 /* a +ov user.. bleh */
847 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
850 if(pargs
>= MAXMODEPARAMS
)
853 sendto_channel_local(ALL_MEMBERS
, chptr
,
854 ":%s MODE %s %s %s %s %s %s",
855 fakesource_p
->name
, chptr
->chname
,
857 para
[0], para
[1], para
[2], para
[3]);
860 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
865 para
[pargs
++] = target_p
->name
;
868 else if(fl
& CHFL_VOICE
)
871 para
[pargs
++] = target_p
->name
;
874 if(pargs
>= MAXMODEPARAMS
)
877 sendto_channel_local(ALL_MEMBERS
, chptr
,
878 ":%s MODE %s %s %s %s %s %s",
881 modebuf
, para
[0], para
[1], para
[2], para
[3]);
884 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
889 /* p points to the next nick */
892 /* if there was a trailing space and p was pointing to it, then we
893 * need to exit.. this has the side effect of breaking double spaces
894 * in an sjoin.. but that shouldnt happen anyway
896 if(s
&& (*s
== '\0'))
899 /* if p was NULL due to no spaces, s wont exist due to the above, so
900 * we cant check it for spaces.. if there are no spaces, then when
901 * we next get here, s will be NULL
903 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
912 sendto_channel_local(ALL_MEMBERS
, chptr
,
913 ":%s MODE %s %s %s %s %s %s",
914 fakesource_p
->name
, chptr
->chname
, modebuf
,
915 para
[0], CheckEmpty(para
[1]),
916 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
919 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
921 destroy_channel(chptr
);
926 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
929 *(ptr_uid
- 1) = '\0';
932 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
938 * inputs - pointer to client doing join 0
940 * side effects - Use has decided to join 0. This is legacy
941 * from the days when channels were numbers not names. *sigh*
944 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
946 struct membership
*msptr
;
947 struct Channel
*chptr
= NULL
;
950 /* Finish the flood grace period... */
951 if(MyClient(source_p
) && !IsFloodDone(source_p
))
952 flood_endgrace(source_p
);
954 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
956 while((ptr
= source_p
->user
->channel
.head
))
958 if(MyConnect(source_p
) &&
959 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
960 check_spambot_warning(source_p
, NULL
);
963 chptr
= msptr
->chptr
;
964 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
966 source_p
->username
, source_p
->host
, chptr
->chname
);
967 remove_user_from_channel(msptr
);
972 check_channel_name_loc(struct Client
*source_p
, const char *name
)
976 s_assert(name
!= NULL
);
977 if(EmptyString(name
))
980 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
982 for(p
= name
; *p
; ++p
)
984 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
990 for(p
= name
; *p
; ++p
)
997 if(ConfigChannel
.only_ascii_channels
)
999 for(p
= name
; *p
; ++p
)
1000 if(*p
< 33 || *p
> 126)
1007 /* send_join_error()
1009 * input - client to send to, reason, channel name
1011 * side effects - error message sent to client
1014 send_join_error(struct Client
*source_p
, int numeric
, const char *name
)
1016 /* This stuff is necessary because the form_str macro only
1017 * accepts constants.
1021 #define NORMAL_NUMERIC(i) \
1023 sendto_one(source_p, form_str(i), \
1024 me.name, source_p->name, name); \
1027 NORMAL_NUMERIC(ERR_BANNEDFROMCHAN
);
1028 NORMAL_NUMERIC(ERR_INVITEONLYCHAN
);
1029 NORMAL_NUMERIC(ERR_BADCHANNELKEY
);
1030 NORMAL_NUMERIC(ERR_CHANNELISFULL
);
1031 NORMAL_NUMERIC(ERR_NEEDREGGEDNICK
);
1032 NORMAL_NUMERIC(ERR_THROTTLE
);
1035 sendto_one_numeric(source_p
, numeric
,
1036 "%s :Cannot join channel", name
);
1042 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1044 int dir
= MODE_QUERY
;
1045 char *pbuf
= parabuf
;
1049 /* ok, first get a list of modes we need to add */
1050 for (i
= 0; i
< 256; i
++)
1052 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1063 /* now the ones we need to remove. */
1064 for (i
= 0; i
< 256; i
++)
1066 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1077 if(oldmode
->limit
&& !mode
->limit
)
1086 if(oldmode
->key
[0] && !mode
->key
[0])
1094 len
= sprintf(pbuf
, "%s ", oldmode
->key
);
1097 if(oldmode
->join_num
&& !mode
->join_num
)
1106 if(oldmode
->forward
[0] && !mode
->forward
[0])
1115 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1123 len
= sprintf(pbuf
, "%d ", mode
->limit
);
1126 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1134 len
= sprintf(pbuf
, "%s ", mode
->key
);
1137 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1145 len
= sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1148 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) &&
1149 ConfigChannel
.use_forward
)
1157 len
= sprintf(pbuf
, "%s ", mode
->forward
);
1171 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1173 struct membership
*msptr
;
1175 char lmodebuf
[MODEBUFLEN
];
1176 char *lpara
[MAXMODEPARAMS
];
1183 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1186 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1190 if(is_chanop(msptr
))
1192 msptr
->flags
&= ~CHFL_CHANOP
;
1193 lpara
[count
++] = msptr
->client_p
->name
;
1196 /* +ov, might not fit so check. */
1197 if(is_voiced(msptr
))
1199 if(count
>= MAXMODEPARAMS
)
1202 sendto_channel_local(ALL_MEMBERS
, chptr
,
1203 ":%s MODE %s %s %s %s %s %s",
1204 source_p
->name
, chptr
->chname
,
1205 lmodebuf
, lpara
[0], lpara
[1],
1206 lpara
[2], lpara
[3]);
1208 /* preserve the initial '-' */
1213 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1217 msptr
->flags
&= ~CHFL_VOICE
;
1218 lpara
[count
++] = msptr
->client_p
->name
;
1222 else if(is_voiced(msptr
))
1224 msptr
->flags
&= ~CHFL_VOICE
;
1225 lpara
[count
++] = msptr
->client_p
->name
;
1231 if(count
>= MAXMODEPARAMS
)
1234 sendto_channel_local(ALL_MEMBERS
, chptr
,
1235 ":%s MODE %s %s %s %s %s %s",
1236 source_p
->name
, chptr
->chname
, lmodebuf
,
1237 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1242 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1250 sendto_channel_local(ALL_MEMBERS
, chptr
,
1251 ":%s MODE %s %s %s %s %s %s",
1252 source_p
->name
, chptr
->chname
, lmodebuf
,
1253 EmptyString(lpara
[0]) ? "" : lpara
[0],
1254 EmptyString(lpara
[1]) ? "" : lpara
[1],
1255 EmptyString(lpara
[2]) ? "" : lpara
[2],
1256 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1261 /* remove_ban_list()
1263 * inputs - channel, source, list to remove, char of mode, caps needed
1265 * side effects - given list is removed, with modes issued to local clients
1268 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1269 rb_dlink_list
* list
, char c
, int mems
)
1271 static char lmodebuf
[BUFSIZE
];
1272 static char lparabuf
[BUFSIZE
];
1275 rb_dlink_node
*next_ptr
;
1278 int cur_len
, mlen
, plen
;
1282 cur_len
= mlen
= sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1283 mbuf
= lmodebuf
+ mlen
;
1285 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1289 /* trailing space, and the mode letter itself */
1290 plen
= strlen(banptr
->banstr
) +
1291 (banptr
->forward
? strlen(banptr
->forward
) + 1 : 0) + 2;
1293 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1295 /* remove trailing space */
1299 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1302 mbuf
= lmodebuf
+ mlen
;
1309 if (banptr
->forward
)
1310 pbuf
+= sprintf(pbuf
, "%s$%s ", banptr
->banstr
, banptr
->forward
);
1312 pbuf
+= sprintf(pbuf
, "%s ", banptr
->banstr
);
1320 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1322 list
->head
= list
->tail
= NULL
;