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
)
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
);
386 * parv[1] = channel TS
388 * parv[3] = "+", formerly channel modes but now unused
389 * alternatively, a single "0" parameter parts all channels
392 ms_join(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
394 struct Channel
*chptr
;
395 static struct Mode mode
;
399 bool keep_our_modes
= true;
400 rb_dlink_node
*ptr
, *next_ptr
;
402 /* special case for join 0 */
403 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
405 do_join_0(client_p
, source_p
);
412 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
415 /* joins for local channels cant happen. */
416 if(parv
[2][0] == '&')
420 mode
.key
[0] = mode
.forward
[0] = '\0';
421 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
423 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
426 newts
= atol(parv
[1]);
427 oldts
= chptr
->channelts
;
429 /* making a channel TS0 */
430 if(!isnew
&& !newts
&& oldts
)
432 sendto_channel_local(ALL_MEMBERS
, chptr
,
433 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
434 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
435 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
436 "Server %s changing TS on %s from %ld to 0",
437 source_p
->name
, chptr
->chname
, (long) oldts
);
441 chptr
->channelts
= newts
;
442 else if(newts
== 0 || oldts
== 0)
443 chptr
->channelts
= 0;
444 else if(newts
== oldts
)
446 else if(newts
< oldts
)
448 keep_our_modes
= false;
449 chptr
->channelts
= newts
;
452 /* Lost the TS, other side wins, so remove modes on this side */
455 set_final_mode(&mode
, &chptr
->mode
);
457 remove_our_modes(chptr
, source_p
);
458 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
460 del_invite(chptr
, ptr
->data
);
462 /* If setting -j, clear join throttle state -- jilles */
463 chptr
->join_count
= chptr
->join_delta
= 0;
464 sendto_channel_local(ALL_MEMBERS
, chptr
,
465 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
466 me
.name
, chptr
->chname
, chptr
->chname
,
467 (long) oldts
, (long) newts
);
468 /* Update capitalization in channel name, this makes the
469 * capitalization timestamped like modes are -- jilles */
470 strcpy(chptr
->chname
, parv
[2]);
472 sendto_channel_local(ALL_MEMBERS
, chptr
,
474 source_p
->servptr
->name
,
475 chptr
->chname
, modebuf
, parabuf
);
476 *modebuf
= *parabuf
= '\0';
478 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
479 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, false);
482 if(!IsMember(source_p
, chptr
))
484 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
485 if (chptr
->mode
.join_num
&&
486 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
488 chptr
->join_count
= 0;
489 chptr
->join_delta
= rb_current_time();
492 send_channel_join(chptr
, source_p
);
495 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
497 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
501 ms_sjoin(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
503 static char buf_uid
[BUFSIZE
];
504 static const char empty_modes
[] = "0";
505 struct Channel
*chptr
;
506 struct Client
*target_p
, *fakesource_p
;
509 static struct Mode mode
, *oldmode
;
512 bool keep_our_modes
= true;
513 bool keep_new_modes
= true;
523 int i
, joinc
= 0, timeslice
= 0;
524 static char empty
[] = "";
525 rb_dlink_node
*ptr
, *next_ptr
;
530 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
533 /* SJOIN's for local channels can't happen. */
537 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
538 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
540 /* Hide connecting server on netburst -- jilles */
541 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
544 fakesource_p
= source_p
;
547 newts
= atol(parv
[1]);
555 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
561 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
563 mode
.join_num
= joinc
;
564 mode
.join_time
= timeslice
;
569 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
575 mode
.limit
= atoi(parv
[4 + args
]);
581 if(chmode_flags
[(int) *s
] != 0)
583 mode
.mode
|= chmode_flags
[(int) *s
];
592 /* remove any leading spaces */
599 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
600 return; /* channel name too long? */
603 oldts
= chptr
->channelts
;
604 oldmode
= &chptr
->mode
;
606 if(!isnew
&& !newts
&& oldts
)
608 sendto_channel_local(ALL_MEMBERS
, chptr
,
609 ":%s NOTICE %s :*** Notice -- TS for %s "
610 "changed from %ld to 0",
611 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
612 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
613 "Server %s changing TS on %s from %ld to 0",
614 source_p
->name
, chptr
->chname
, (long) oldts
);
618 chptr
->channelts
= newts
;
620 else if(newts
== 0 || oldts
== 0)
621 chptr
->channelts
= 0;
622 else if(newts
== oldts
)
624 else if(newts
< oldts
)
626 /* If configured, kick people trying to join +i/+k
627 * channels by recreating them on split servers.
628 * If the source has sent EOB, assume this is some
629 * sort of hack by services. If cmode +i is set,
630 * services can send kicks if needed; if the key
631 * differs, services cannot kick in a race-free
632 * manner so do so here.
634 if (ConfigChannel
.kick_on_split_riding
&&
635 ((!HasSentEob(source_p
) &&
636 mode
.mode
& MODE_INVITEONLY
) ||
637 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
639 struct membership
*msptr
;
641 int l
= rb_dlink_list_length(&chptr
->members
);
643 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
646 who
= msptr
->client_p
;
647 sendto_one(who
, ":%s KICK %s %s :Net Rider",
648 me
.name
, chptr
->chname
, who
->name
);
650 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
651 ":%s KICK %s %s :Net Rider",
652 me
.id
, chptr
->chname
,
654 remove_user_from_channel(msptr
);
660 /* Channel was emptied, create a new one */
661 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
664 oldmode
= &chptr
->mode
;
667 keep_our_modes
= false;
668 chptr
->channelts
= newts
;
671 keep_new_modes
= false;
675 else if(keep_our_modes
)
677 mode
.mode
|= oldmode
->mode
;
678 if(oldmode
->limit
> mode
.limit
)
679 mode
.limit
= oldmode
->limit
;
680 if(strcmp(mode
.key
, oldmode
->key
) < 0)
681 strcpy(mode
.key
, oldmode
->key
);
682 if(oldmode
->join_num
> mode
.join_num
||
683 (oldmode
->join_num
== mode
.join_num
&&
684 oldmode
->join_time
> mode
.join_time
))
686 mode
.join_num
= oldmode
->join_num
;
687 mode
.join_time
= oldmode
->join_time
;
689 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
690 strcpy(mode
.forward
, oldmode
->forward
);
694 /* If setting -j, clear join throttle state -- jilles */
696 chptr
->join_count
= chptr
->join_delta
= 0;
699 set_final_mode(&mode
, oldmode
);
702 /* Lost the TS, other side wins, so remove modes on this side */
705 remove_our_modes(chptr
, fakesource_p
);
706 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
708 del_invite(chptr
, ptr
->data
);
711 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
712 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
713 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
714 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
716 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
717 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
719 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
720 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
724 sendto_channel_local(ALL_MEMBERS
, chptr
,
725 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
726 me
.name
, chptr
->chname
, chptr
->chname
,
727 (long) oldts
, (long) newts
);
728 /* Update capitalization in channel name, this makes the
729 * capitalization timestamped like modes are -- jilles */
730 strcpy(chptr
->chname
, parv
[2]);
732 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
733 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, false);
737 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
738 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
740 *modebuf
= *parabuf
= '\0';
742 if(parv
[3][0] != '0' && keep_new_modes
)
743 modes
= channel_modes(chptr
, source_p
);
747 mlen_uid
= sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
748 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
749 ptr_uid
= buf_uid
+ mlen_uid
;
752 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
756 /* if theres a space, theres going to be more than one nick, change the
757 * first space to \0, so s is just the first nick, and point p to the
760 if((p
= strchr(s
, ' ')) != NULL
)
771 for (i
= 0; i
< 2; i
++)
785 /* if the client doesnt exist or is fake direction, skip. */
786 if(!(target_p
= find_client(s
)) ||
787 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
790 /* we assume for these we can fit at least one nick/uid in.. */
792 /* check we can fit another status+nick+space into a buffer */
793 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
795 *(ptr_uid
- 1) = '\0';
796 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
797 ptr_uid
= buf_uid
+ mlen_uid
;
815 /* copy the nick to the two buffers */
816 len
= sprintf(ptr_uid
, "%s ", use_id(target_p
));
823 if(!IsMember(target_p
, chptr
))
825 add_user_to_channel(chptr
, target_p
, fl
);
826 send_channel_join(chptr
, target_p
);
833 para
[pargs
++] = target_p
->name
;
835 /* a +ov user.. bleh */
838 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
841 if(pargs
>= MAXMODEPARAMS
)
844 sendto_channel_local(ALL_MEMBERS
, chptr
,
845 ":%s MODE %s %s %s %s %s %s",
846 fakesource_p
->name
, chptr
->chname
,
848 para
[0], para
[1], para
[2], para
[3]);
851 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
856 para
[pargs
++] = target_p
->name
;
859 else if(fl
& CHFL_VOICE
)
862 para
[pargs
++] = target_p
->name
;
865 if(pargs
>= MAXMODEPARAMS
)
868 sendto_channel_local(ALL_MEMBERS
, chptr
,
869 ":%s MODE %s %s %s %s %s %s",
872 modebuf
, para
[0], para
[1], para
[2], para
[3]);
875 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
880 /* p points to the next nick */
883 /* if there was a trailing space and p was pointing to it, then we
884 * need to exit.. this has the side effect of breaking double spaces
885 * in an sjoin.. but that shouldnt happen anyway
887 if(s
&& (*s
== '\0'))
890 /* if p was NULL due to no spaces, s wont exist due to the above, so
891 * we cant check it for spaces.. if there are no spaces, then when
892 * we next get here, s will be NULL
894 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
903 sendto_channel_local(ALL_MEMBERS
, chptr
,
904 ":%s MODE %s %s %s %s %s %s",
905 fakesource_p
->name
, chptr
->chname
, modebuf
,
906 para
[0], CheckEmpty(para
[1]),
907 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
910 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
912 destroy_channel(chptr
);
917 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
920 *(ptr_uid
- 1) = '\0';
923 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
929 * inputs - pointer to client doing join 0
931 * side effects - Use has decided to join 0. This is legacy
932 * from the days when channels were numbers not names. *sigh*
935 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
937 struct membership
*msptr
;
938 struct Channel
*chptr
= NULL
;
941 /* Finish the flood grace period... */
942 if(MyClient(source_p
) && !IsFloodDone(source_p
))
943 flood_endgrace(source_p
);
945 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
947 while((ptr
= source_p
->user
->channel
.head
))
949 if(MyConnect(source_p
) &&
950 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
951 check_spambot_warning(source_p
, NULL
);
954 chptr
= msptr
->chptr
;
955 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
957 source_p
->username
, source_p
->host
, chptr
->chname
);
958 remove_user_from_channel(msptr
);
963 check_channel_name_loc(struct Client
*source_p
, const char *name
)
967 s_assert(name
!= NULL
);
968 if(EmptyString(name
))
971 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
973 for(p
= name
; *p
; ++p
)
975 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
981 for(p
= name
; *p
; ++p
)
988 if(ConfigChannel
.only_ascii_channels
)
990 for(p
= name
; *p
; ++p
)
991 if(*p
< 33 || *p
> 126)
1000 * input - client to send to, reason, channel name
1002 * side effects - error message sent to client
1005 send_join_error(struct Client
*source_p
, int numeric
, const char *name
)
1007 /* This stuff is necessary because the form_str macro only
1008 * accepts constants.
1012 #define NORMAL_NUMERIC(i) \
1014 sendto_one(source_p, form_str(i), \
1015 me.name, source_p->name, name); \
1018 NORMAL_NUMERIC(ERR_BANNEDFROMCHAN
);
1019 NORMAL_NUMERIC(ERR_INVITEONLYCHAN
);
1020 NORMAL_NUMERIC(ERR_BADCHANNELKEY
);
1021 NORMAL_NUMERIC(ERR_CHANNELISFULL
);
1022 NORMAL_NUMERIC(ERR_NEEDREGGEDNICK
);
1023 NORMAL_NUMERIC(ERR_THROTTLE
);
1026 sendto_one_numeric(source_p
, numeric
,
1027 "%s :Cannot join channel", name
);
1033 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1035 int dir
= MODE_QUERY
;
1036 char *pbuf
= parabuf
;
1040 /* ok, first get a list of modes we need to add */
1041 for (i
= 0; i
< 256; i
++)
1043 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1054 /* now the ones we need to remove. */
1055 for (i
= 0; i
< 256; i
++)
1057 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1068 if(oldmode
->limit
&& !mode
->limit
)
1077 if(oldmode
->key
[0] && !mode
->key
[0])
1085 len
= sprintf(pbuf
, "%s ", oldmode
->key
);
1088 if(oldmode
->join_num
&& !mode
->join_num
)
1097 if(oldmode
->forward
[0] && !mode
->forward
[0])
1106 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1114 len
= sprintf(pbuf
, "%d ", mode
->limit
);
1117 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1125 len
= sprintf(pbuf
, "%s ", mode
->key
);
1128 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1136 len
= sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1139 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) &&
1140 ConfigChannel
.use_forward
)
1148 len
= sprintf(pbuf
, "%s ", mode
->forward
);
1162 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1164 struct membership
*msptr
;
1166 char lmodebuf
[MODEBUFLEN
];
1167 char *lpara
[MAXMODEPARAMS
];
1174 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1177 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1181 if(is_chanop(msptr
))
1183 msptr
->flags
&= ~CHFL_CHANOP
;
1184 lpara
[count
++] = msptr
->client_p
->name
;
1187 /* +ov, might not fit so check. */
1188 if(is_voiced(msptr
))
1190 if(count
>= MAXMODEPARAMS
)
1193 sendto_channel_local(ALL_MEMBERS
, chptr
,
1194 ":%s MODE %s %s %s %s %s %s",
1195 source_p
->name
, chptr
->chname
,
1196 lmodebuf
, lpara
[0], lpara
[1],
1197 lpara
[2], lpara
[3]);
1199 /* preserve the initial '-' */
1204 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1208 msptr
->flags
&= ~CHFL_VOICE
;
1209 lpara
[count
++] = msptr
->client_p
->name
;
1213 else if(is_voiced(msptr
))
1215 msptr
->flags
&= ~CHFL_VOICE
;
1216 lpara
[count
++] = msptr
->client_p
->name
;
1222 if(count
>= MAXMODEPARAMS
)
1225 sendto_channel_local(ALL_MEMBERS
, chptr
,
1226 ":%s MODE %s %s %s %s %s %s",
1227 source_p
->name
, chptr
->chname
, lmodebuf
,
1228 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1233 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1241 sendto_channel_local(ALL_MEMBERS
, chptr
,
1242 ":%s MODE %s %s %s %s %s %s",
1243 source_p
->name
, chptr
->chname
, lmodebuf
,
1244 EmptyString(lpara
[0]) ? "" : lpara
[0],
1245 EmptyString(lpara
[1]) ? "" : lpara
[1],
1246 EmptyString(lpara
[2]) ? "" : lpara
[2],
1247 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1252 /* remove_ban_list()
1254 * inputs - channel, source, list to remove, char of mode, caps needed
1256 * side effects - given list is removed, with modes issued to local clients
1259 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1260 rb_dlink_list
* list
, char c
, int mems
)
1262 static char lmodebuf
[BUFSIZE
];
1263 static char lparabuf
[BUFSIZE
];
1266 rb_dlink_node
*next_ptr
;
1269 int cur_len
, mlen
, plen
;
1273 cur_len
= mlen
= sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1274 mbuf
= lmodebuf
+ mlen
;
1276 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1280 /* trailing space, and the mode letter itself */
1281 plen
= strlen(banptr
->banstr
) +
1282 (banptr
->forward
? strlen(banptr
->forward
) + 1 : 0) + 2;
1284 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1286 /* remove trailing space */
1290 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1293 mbuf
= lmodebuf
+ mlen
;
1300 if (banptr
->forward
)
1301 pbuf
+= sprintf(pbuf
, "%s$%s ", banptr
->banstr
, banptr
->forward
);
1303 pbuf
+= sprintf(pbuf
, "%s ", banptr
->banstr
);
1311 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1313 list
->head
= list
->tail
= NULL
;