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 char *set_final_mode(char *mbuf
, 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
];
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
,
95 const char *next
= NULL
;
97 /* The caller (m_join) is only interested in the reason
98 * for the original channel.
100 if ((*err
= can_join(source_p
, chptr
, key
, &next
)) == 0)
103 /* User is +Q, or forwarding disabled */
104 if (IsNoForward(source_p
) || !ConfigChannel
.use_forward
)
112 chptr
= find_channel(next
);
113 /* Can only forward to existing channels */
116 /* Already on there... but don't send the original reason for
117 * being unable to join. It isn't their fault they're already
118 * on the channel, and it looks hostile otherwise.
121 if (IsMember(source_p
, chptr
))
123 *err
= ERR_USERONCHANNEL
; /* I'm borrowing this for now. --Elizafox */
126 /* Juped. Sending a warning notice would be unfair */
127 if (hash_find_resv(chptr
->chname
))
129 /* Don't forward to +Q channel */
130 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
133 i
= can_join(source_p
, chptr
, key
, &next
);
145 * parv[2] = channel password (key)
148 m_join(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
150 static char jbuf
[BUFSIZE
];
151 struct Channel
*chptr
= NULL
, *chptr2
= NULL
;
152 struct ConfItem
*aconf
;
157 char *p
= NULL
, *p2
= NULL
;
163 /* rebuild the list of channels theyre supposed to be joining.
164 * this code has a side effect of losing keys, but..
166 chanlist
= LOCAL_COPY(parv
[1]);
167 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
169 /* check the length and name of channel is ok */
170 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
172 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
173 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
177 /* join 0 parts all channels */
178 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
180 rb_strlcpy(jbuf
, "0", sizeof(jbuf
));
184 /* check it begins with a valid channel prefix per policy. */
185 else if (!IsChannelName(name
))
187 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
188 form_str(ERR_NOSUCHCHANNEL
), name
);
192 /* see if its resv'd */
193 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
195 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
196 form_str(ERR_BADCHANNAME
), name
);
198 /* dont warn for opers */
199 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
200 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
201 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
202 source_p
->name
, source_p
->username
,
203 source_p
->orighost
, name
, aconf
->passwd
);
204 /* dont update tracking for jupe exempt users, these
205 * are likely to be spamtrap leaves
207 else if(IsExemptJupe(source_p
))
213 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
214 ConfigChannel
.no_join_on_split
)
216 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
217 me
.name
, source_p
->name
, name
);
222 (void) strcat(jbuf
, ",");
223 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
228 mykey
= LOCAL_COPY(parv
[2]);
229 key
= rb_strtok_r(mykey
, ",", &p2
);
232 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
233 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
235 hook_data_channel_activity hook_info
;
237 /* JOIN 0 simply parts all channels the user is in */
238 if(*name
== '0' && !atoi(name
))
240 if(source_p
->user
->channel
.head
== NULL
)
243 do_join_0(&me
, source_p
);
247 /* look for the channel */
248 if((chptr
= find_channel(name
)) != NULL
)
250 if(IsMember(source_p
, chptr
))
257 hook_data_client_approval moduledata
;
259 moduledata
.client
= source_p
;
260 moduledata
.approved
= 0;
262 call_hook(h_can_create_channel
, &moduledata
);
264 if(moduledata
.approved
!= 0)
266 if(moduledata
.approved
!= ERR_CUSTOM
)
267 send_join_error(source_p
,
273 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
274 ConfigChannel
.no_create_on_split
)
276 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
277 me
.name
, source_p
->name
, name
);
284 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
285 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
286 (!IsExtendChans(source_p
) ||
287 (rb_dlink_list_length(&source_p
->user
->channel
) >=
288 (unsigned long) ConfigChannel
.max_chans_per_user_large
)))
290 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
291 me
.name
, source_p
->name
, name
);
295 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
297 chptr
= get_or_create_channel(source_p
, name
, NULL
);
301 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
302 me
.name
, source_p
->name
, name
);
307 /* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */
308 if((chptr2
= check_forward(source_p
, chptr
, key
, &i
)) == NULL
)
310 /* might be wrong, but is there any other better location for such?
311 * see extensions/chm_operonly.c for other comments on this
315 send_join_error(source_p
, i
, name
);
318 else if(chptr
!= chptr2
)
319 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr2
->chname
);
324 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
325 check_spambot_warning(source_p
, name
);
327 /* add the user to the channel */
328 add_user_to_channel(chptr
, source_p
, flags
);
329 if (chptr
->mode
.join_num
&&
330 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
332 chptr
->join_count
= 0;
333 chptr
->join_delta
= rb_current_time();
337 /* credit user for join */
338 credit_client_join(source_p
);
340 /* we send the user their join here, because we could have to
341 * send a mode out next.
343 send_channel_join(chptr
, source_p
);
345 /* its a new channel, set +nt and burst. */
346 if(flags
& CHFL_CHANOP
)
348 chptr
->channelts
= rb_current_time();
349 chptr
->mode
.mode
|= ConfigChannel
.autochanmodes
;
350 modes
= channel_modes(chptr
, &me
);
352 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
353 me
.name
, chptr
->chname
, modes
);
355 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
356 ":%s SJOIN %ld %s %s :@%s",
357 me
.id
, (long) chptr
->channelts
,
358 chptr
->chname
, modes
, source_p
->id
);
362 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
364 use_id(source_p
), (long) chptr
->channelts
,
368 del_invite(chptr
, source_p
);
370 if(chptr
->topic
!= NULL
)
372 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
373 source_p
->name
, chptr
->chname
, chptr
->topic
);
375 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
376 me
.name
, source_p
->name
, chptr
->chname
,
378 (unsigned long)chptr
->topic_time
);
381 channel_member_names(chptr
, source_p
, 1);
383 hook_info
.client
= source_p
;
384 hook_info
.chptr
= chptr
;
386 call_hook(h_channel_join
, &hook_info
);
392 * parv[1] = channel TS
394 * parv[3] = "+", formerly channel modes but now unused
395 * alternatively, a single "0" parameter parts all channels
398 ms_join(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
400 struct Channel
*chptr
;
401 static struct Mode mode
;
405 bool keep_our_modes
= true;
406 rb_dlink_node
*ptr
, *next_ptr
;
409 /* special case for join 0 */
410 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
412 do_join_0(client_p
, source_p
);
419 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
422 /* joins for local channels cant happen. */
423 if(parv
[2][0] == '&')
427 mode
.key
[0] = mode
.forward
[0] = '\0';
428 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
430 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
433 newts
= atol(parv
[1]);
434 oldts
= chptr
->channelts
;
436 /* making a channel TS0 */
437 if(!isnew
&& !newts
&& oldts
)
439 sendto_channel_local(ALL_MEMBERS
, chptr
,
440 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
441 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
442 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
443 "Server %s changing TS on %s from %ld to 0",
444 source_p
->name
, chptr
->chname
, (long) oldts
);
448 chptr
->channelts
= newts
;
449 else if(newts
== 0 || oldts
== 0)
450 chptr
->channelts
= 0;
451 else if(newts
== oldts
)
453 else if(newts
< oldts
)
455 keep_our_modes
= false;
456 chptr
->channelts
= newts
;
459 /* Lost the TS, other side wins, so remove modes on this side */
462 mbuf
= set_final_mode(mbuf
, &mode
, &chptr
->mode
);
464 remove_our_modes(chptr
, source_p
);
465 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
467 del_invite(chptr
, ptr
->data
);
469 /* If setting -j, clear join throttle state -- jilles */
470 chptr
->join_count
= chptr
->join_delta
= 0;
471 sendto_channel_local(ALL_MEMBERS
, chptr
,
472 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
473 me
.name
, chptr
->chname
, chptr
->chname
,
474 (long) oldts
, (long) newts
);
475 /* Update capitalization in channel name, this makes the
476 * capitalization timestamped like modes are -- jilles */
477 strcpy(chptr
->chname
, parv
[2]);
479 sendto_channel_local(ALL_MEMBERS
, chptr
,
481 source_p
->servptr
->name
,
482 chptr
->chname
, modebuf
, parabuf
);
483 *modebuf
= *parabuf
= '\0';
485 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
486 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, false);
489 if(!IsMember(source_p
, chptr
))
491 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
492 if (chptr
->mode
.join_num
&&
493 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
495 chptr
->join_count
= 0;
496 chptr
->join_delta
= rb_current_time();
499 send_channel_join(chptr
, source_p
);
502 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
504 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
508 ms_sjoin(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
510 static char buf_uid
[BUFSIZE
];
511 static const char empty_modes
[] = "0";
512 struct Channel
*chptr
;
513 struct Client
*target_p
, *fakesource_p
;
516 static struct Mode mode
, *oldmode
;
519 bool keep_our_modes
= true;
520 bool keep_new_modes
= true;
530 int i
, joinc
= 0, timeslice
= 0;
531 static char empty
[] = "";
532 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 rb_strlcpy(mode
.key
, oldmode
->key
, sizeof(mode
.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 rb_strlcpy(mode
.forward
, oldmode
->forward
, sizeof(mode
.forward
));
703 /* If setting -j, clear join throttle state -- jilles */
705 chptr
->join_count
= chptr
->join_delta
= 0;
708 mbuf
= set_final_mode(mbuf
, &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(char *mbuf
, 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
);
1173 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1175 struct membership
*msptr
;
1177 char lmodebuf
[MODEBUFLEN
];
1178 char *lpara
[MAXMODEPARAMS
];
1181 char *mbuf
= lmodebuf
;
1185 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1188 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1192 if(is_chanop(msptr
))
1194 msptr
->flags
&= ~CHFL_CHANOP
;
1195 lpara
[count
++] = msptr
->client_p
->name
;
1198 /* +ov, might not fit so check. */
1199 if(is_voiced(msptr
))
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
,
1207 lmodebuf
, lpara
[0], lpara
[1],
1208 lpara
[2], lpara
[3]);
1210 /* preserve the initial '-' */
1215 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1219 msptr
->flags
&= ~CHFL_VOICE
;
1220 lpara
[count
++] = msptr
->client_p
->name
;
1224 else if(is_voiced(msptr
))
1226 msptr
->flags
&= ~CHFL_VOICE
;
1227 lpara
[count
++] = msptr
->client_p
->name
;
1233 if(count
>= MAXMODEPARAMS
)
1236 sendto_channel_local(ALL_MEMBERS
, chptr
,
1237 ":%s MODE %s %s %s %s %s %s",
1238 source_p
->name
, chptr
->chname
, lmodebuf
,
1239 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1244 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1252 sendto_channel_local(ALL_MEMBERS
, chptr
,
1253 ":%s MODE %s %s %s %s %s %s",
1254 source_p
->name
, chptr
->chname
, lmodebuf
,
1255 EmptyString(lpara
[0]) ? "" : lpara
[0],
1256 EmptyString(lpara
[1]) ? "" : lpara
[1],
1257 EmptyString(lpara
[2]) ? "" : lpara
[2],
1258 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1263 /* remove_ban_list()
1265 * inputs - channel, source, list to remove, char of mode, caps needed
1267 * side effects - given list is removed, with modes issued to local clients
1270 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1271 rb_dlink_list
* list
, char c
, int mems
)
1273 static char lmodebuf
[BUFSIZE
];
1274 static char lparabuf
[BUFSIZE
];
1277 rb_dlink_node
*next_ptr
;
1280 int cur_len
, mlen
, plen
;
1285 cur_len
= mlen
= sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1286 mbuf
= lmodebuf
+ mlen
;
1288 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1292 /* trailing space, and the mode letter itself */
1293 plen
= strlen(banptr
->banstr
) +
1294 (banptr
->forward
? strlen(banptr
->forward
) + 1 : 0) + 2;
1296 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1298 /* remove trailing space */
1302 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1305 mbuf
= lmodebuf
+ mlen
;
1312 if (banptr
->forward
)
1313 pbuf
+= sprintf(pbuf
, "%s$%s ", banptr
->banstr
, banptr
->forward
);
1315 pbuf
+= sprintf(pbuf
, "%s ", banptr
->banstr
);
1323 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1325 list
->head
= list
->tail
= NULL
;