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
24 * $Id: m_join.c 3494 2007-05-27 13:07:27Z jilles $
32 #include "irc_string.h"
38 #include "s_newconf.h"
42 #include "sprintf_irc.h"
45 static int m_join(struct Client
*, struct Client
*, int, const char **);
46 static int ms_join(struct Client
*, struct Client
*, int, const char **);
47 static int ms_sjoin(struct Client
*, struct Client
*, int, const char **);
49 static int h_can_create_channel
;
50 static int h_channel_join
;
52 struct Message join_msgtab
= {
53 "JOIN", 0, 0, 0, MFLG_SLOW
,
54 {mg_unreg
, {m_join
, 2}, {ms_join
, 2}, mg_ignore
, mg_ignore
, {m_join
, 2}}
57 struct Message sjoin_msgtab
= {
58 "SJOIN", 0, 0, 0, MFLG_SLOW
,
59 {mg_unreg
, mg_ignore
, mg_ignore
, {ms_sjoin
, 0}, mg_ignore
, mg_ignore
}
62 mapi_clist_av1 join_clist
[] = { &join_msgtab
, &sjoin_msgtab
, NULL
};
64 mapi_hlist_av1 join_hlist
[] = {
65 { "can_create_channel", &h_can_create_channel
},
66 { "channel_join", &h_channel_join
},
70 DECLARE_MODULE_AV1(join
, NULL
, NULL
, join_clist
, join_hlist
, NULL
, "$Revision: 3494 $");
72 static void do_join_0(struct Client
*client_p
, struct Client
*source_p
);
73 static int check_channel_name_loc(struct Client
*source_p
, const char *name
);
75 static void set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
);
76 static void remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
);
78 static void remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
79 rb_dlink_list
* list
, char c
, int cap
, int mems
);
81 static char modebuf
[MODEBUFLEN
];
82 static char parabuf
[MODEBUFLEN
];
83 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
,
97 if (IsNoForward(source_p
))
102 chptr
= find_channel(chptr
->mode
.forward
);
103 /* Can only forward to existing channels */
106 /* Already on there, show original error message */
107 if (IsMember(source_p
, chptr
))
109 /* Juped. Sending a warning notice would be unfair */
110 if (hash_find_resv(chptr
->chname
))
112 /* Don't forward to +Q channel */
113 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
115 i
= can_join(source_p
, chptr
, key
);
118 if (i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_CHANNELISFULL
)
128 * parv[0] = sender prefix
130 * parv[2] = channel password (key)
133 m_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
135 static char jbuf
[BUFSIZE
];
136 struct Channel
*chptr
= NULL
;
137 struct ConfItem
*aconf
;
141 char *p
= NULL
, *p2
= NULL
;
144 int successful_join_count
= 0; /* Number of channels successfully joined */
148 /* rebuild the list of channels theyre supposed to be joining.
149 * this code has a side effect of losing keys, but..
151 chanlist
= LOCAL_COPY(parv
[1]);
152 for(name
= strtoken(&p
, chanlist
, ","); name
; name
= strtoken(&p
, NULL
, ","))
154 /* check the length and name of channel is ok */
155 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
157 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
158 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
162 /* join 0 parts all channels */
163 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
165 (void) strcpy(jbuf
, "0");
169 /* check it begins with # or &, and local chans are disabled */
170 else if(!IsChannelName(name
))
172 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
173 form_str(ERR_NOSUCHCHANNEL
), name
);
177 /* see if its resv'd */
178 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
180 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
181 form_str(ERR_BADCHANNAME
), name
);
183 /* dont warn for opers */
184 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
185 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
186 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
187 source_p
->name
, source_p
->username
,
188 source_p
->orighost
, name
, aconf
->passwd
);
189 /* dont update tracking for jupe exempt users, these
190 * are likely to be spamtrap leaves
192 else if(IsExemptJupe(source_p
))
198 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
199 ConfigChannel
.no_join_on_split
)
201 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
202 me
.name
, source_p
->name
, name
);
207 (void) strcat(jbuf
, ",");
208 (void) strlcat(jbuf
, name
, sizeof(jbuf
));
213 mykey
= LOCAL_COPY(parv
[2]);
214 key
= strtoken(&p2
, mykey
, ",");
217 for(name
= strtoken(&p
, jbuf
, ","); name
;
218 key
= (key
) ? strtoken(&p2
, NULL
, ",") : NULL
, name
= strtoken(&p
, NULL
, ","))
220 hook_data_channel_activity hook_info
;
222 /* JOIN 0 simply parts all channels the user is in */
223 if(*name
== '0' && !atoi(name
))
225 if(source_p
->user
->channel
.head
== NULL
)
228 do_join_0(&me
, source_p
);
232 /* look for the channel */
233 if((chptr
= find_channel(name
)) != NULL
)
235 if(IsMember(source_p
, chptr
))
242 hook_data_client_approval moduledata
;
244 moduledata
.client
= source_p
;
245 moduledata
.approved
= 0;
247 call_hook(h_can_create_channel
, &moduledata
);
249 if(moduledata
.approved
!= 0)
251 sendto_one(source_p
, form_str(moduledata
.approved
),
252 me
.name
, source_p
->name
, name
);
256 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
257 ConfigChannel
.no_create_on_split
)
259 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
260 me
.name
, source_p
->name
, name
);
267 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
268 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
269 (!IsOper(source_p
) ||
270 (rb_dlink_list_length(&source_p
->user
->channel
) >=
271 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
273 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
274 me
.name
, source_p
->name
, name
);
275 if(successful_join_count
)
276 source_p
->localClient
->last_join_time
= rb_current_time();
280 if(flags
== 0) /* if channel doesn't exist, don't penalize */
281 successful_join_count
++;
283 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
285 chptr
= get_or_create_channel(source_p
, name
, NULL
);
289 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
290 me
.name
, source_p
->name
, name
);
291 if(successful_join_count
> 0)
292 successful_join_count
--;
297 if(!IsOper(source_p
) && !IsExemptSpambot(source_p
))
298 check_spambot_warning(source_p
, name
);
300 /* can_join checks for +i key, bans etc */
301 if((i
= can_join(source_p
, chptr
, key
)))
303 if ((i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_CHANNELISFULL
) ||
304 (!ConfigChannel
.use_forward
|| (chptr
= check_forward(source_p
, chptr
, key
)) == NULL
))
306 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
307 if(successful_join_count
> 0)
308 successful_join_count
--;
311 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr
->chname
);
314 /* add the user to the channel */
315 add_user_to_channel(chptr
, source_p
, flags
);
316 if (chptr
->mode
.join_num
&&
317 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
319 chptr
->join_count
= 0;
320 chptr
->join_delta
= rb_current_time();
324 /* we send the user their join here, because we could have to
325 * send a mode out next.
327 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
329 source_p
->username
, source_p
->host
, chptr
->chname
);
331 /* its a new channel, set +nt and burst. */
332 if(flags
& CHFL_CHANOP
)
334 chptr
->channelts
= rb_current_time();
335 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
336 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
338 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s +nt",
339 me
.name
, chptr
->chname
);
341 if(*chptr
->chname
== '#')
343 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
344 ":%s SJOIN %ld %s +nt :@%s",
345 me
.id
, (long) chptr
->channelts
,
346 chptr
->chname
, source_p
->id
);
347 sendto_server(client_p
, chptr
, NOCAPS
, CAP_TS6
,
348 ":%s SJOIN %ld %s +nt :@%s",
349 me
.name
, (long) chptr
->channelts
,
350 chptr
->chname
, source_p
->name
);
355 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
357 use_id(source_p
), (long) chptr
->channelts
,
360 sendto_server(client_p
, chptr
, NOCAPS
, CAP_TS6
,
361 ":%s SJOIN %ld %s + :%s",
362 me
.name
, (long) chptr
->channelts
,
363 chptr
->chname
, source_p
->name
);
366 del_invite(chptr
, source_p
);
368 if(chptr
->topic
!= NULL
)
370 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
371 source_p
->name
, chptr
->chname
, chptr
->topic
);
373 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
374 me
.name
, source_p
->name
, chptr
->chname
,
375 chptr
->topic_info
, chptr
->topic_time
);
378 channel_member_names(chptr
, source_p
, 1);
380 if(successful_join_count
)
381 source_p
->localClient
->last_join_time
= rb_current_time();
383 hook_info
.client
= source_p
;
384 hook_info
.chptr
= chptr
;
386 call_hook(h_channel_join
, &hook_info
);
397 * side effects - handles remote JOIN's sent by servers. In TSora
398 * remote clients are joined using SJOIN, hence a
399 * JOIN sent by a server on behalf of a client is an error.
400 * here, the initial code is in to take an extra parameter
401 * and use it for the TimeStamp on a new channel.
404 ms_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
406 struct Channel
*chptr
;
407 static struct Mode mode
;
411 int keep_our_modes
= YES
;
412 int keep_new_modes
= YES
;
413 rb_dlink_node
*ptr
, *next_ptr
;
415 /* special case for join 0 */
416 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
418 do_join_0(client_p
, source_p
);
425 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
428 /* joins for local channels cant happen. */
429 if(parv
[2][0] == '&')
433 mode
.key
[0] = mode
.forward
[0] = '\0';
434 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
436 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
439 newts
= atol(parv
[1]);
440 oldts
= chptr
->channelts
;
442 #ifdef IGNORE_BOGUS_TS
443 if(newts
< 800000000)
445 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
446 "*** Bogus TS %ld on %s ignored from %s",
447 (long) newts
, chptr
->chname
, client_p
->name
);
448 newts
= (oldts
== 0) ? oldts
: 800000000;
451 /* making a channel TS0 */
452 if(!isnew
&& !newts
&& oldts
)
454 sendto_channel_local(ALL_MEMBERS
, chptr
,
455 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
456 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
457 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
458 "Server %s changing TS on %s from %ld to 0",
459 source_p
->name
, chptr
->chname
, (long) oldts
);
464 chptr
->channelts
= newts
;
465 else if(newts
== 0 || oldts
== 0)
466 chptr
->channelts
= 0;
467 else if(newts
== oldts
)
469 else if(newts
< oldts
)
472 chptr
->channelts
= newts
;
477 /* Lost the TS, other side wins, so remove modes on this side */
480 set_final_mode(&mode
, &chptr
->mode
);
482 remove_our_modes(chptr
, source_p
);
483 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
485 del_invite(chptr
, ptr
->data
);
487 /* If setting -j, clear join throttle state -- jilles */
488 chptr
->join_count
= chptr
->join_delta
= 0;
489 sendto_channel_local(ALL_MEMBERS
, chptr
,
490 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
491 me
.name
, chptr
->chname
, chptr
->chname
,
492 (long) oldts
, (long) newts
);
493 /* Update capitalization in channel name, this makes the
494 * capitalization timestamped like modes are -- jilles */
495 strcpy(chptr
->chname
, parv
[2]);
497 sendto_channel_local(ALL_MEMBERS
, chptr
,
499 source_p
->servptr
->name
,
500 chptr
->chname
, modebuf
, parabuf
);
501 *modebuf
= *parabuf
= '\0';
504 if(!IsMember(source_p
, chptr
))
506 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
507 if (chptr
->mode
.join_num
&&
508 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
510 chptr
->join_count
= 0;
511 chptr
->join_delta
= rb_current_time();
514 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
515 source_p
->name
, source_p
->username
,
516 source_p
->host
, chptr
->chname
);
519 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
521 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
522 sendto_server(client_p
, chptr
, NOCAPS
, CAP_TS6
,
523 ":%s SJOIN %ld %s %s :%s",
524 source_p
->servptr
->name
, (long) chptr
->channelts
,
525 chptr
->chname
, keep_new_modes
? "+" : "0",
531 ms_sjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
533 static char buf_nick
[BUFSIZE
];
534 static char buf_uid
[BUFSIZE
];
535 static const char empty_modes
[] = "0";
536 struct Channel
*chptr
;
537 struct Client
*target_p
, *fakesource_p
;
540 static struct Mode mode
, *oldmode
;
543 int keep_our_modes
= 1;
544 int keep_new_modes
= 1;
547 int mlen_nick
, mlen_uid
;
556 int i
, joinc
= 0, timeslice
= 0;
557 static char empty
[] = "";
558 rb_dlink_node
*ptr
, *next_ptr
;
560 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
563 /* SJOIN's for local channels can't happen. */
567 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
568 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
570 /* Hide connecting server on netburst -- jilles */
571 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
574 fakesource_p
= source_p
;
577 newts
= atol(parv
[1]);
585 mode
.mode
|= MODE_INVITEONLY
;
588 mode
.mode
|= MODE_NOPRIVMSGS
;
591 mode
.mode
|= MODE_PRIVATE
;
594 mode
.mode
|= MODE_SECRET
;
597 mode
.mode
|= MODE_MODERATED
;
600 mode
.mode
|= MODE_TOPICLIMIT
;
603 mode
.mode
|= MODE_REGONLY
;
606 mode
.mode
|= MODE_EXLIMIT
;
609 mode
.mode
|= MODE_PERMANENT
;
612 mode
.mode
|= MODE_NOCOLOR
;
615 mode
.mode
|= MODE_FREEINVITE
;
618 mode
.mode
|= MODE_OPMODERATE
;
621 mode
.mode
|= MODE_FREETARGET
;
624 mode
.mode
|= MODE_DISFORWARD
;
627 strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
633 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
635 mode
.join_num
= joinc
;
636 mode
.join_time
= timeslice
;
641 strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
647 mode
.limit
= atoi(parv
[4 + args
]);
659 /* remove any leading spaces */
666 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
667 return 0; /* channel name too long? */
670 oldts
= chptr
->channelts
;
671 oldmode
= &chptr
->mode
;
673 #ifdef IGNORE_BOGUS_TS
674 if(newts
< 800000000)
676 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
677 "*** Bogus TS %ld on %s ignored from %s",
678 (long) newts
, chptr
->chname
, client_p
->name
);
680 newts
= (oldts
== 0) ? oldts
: 800000000;
683 if(!isnew
&& !newts
&& oldts
)
685 sendto_channel_local(ALL_MEMBERS
, chptr
,
686 ":%s NOTICE %s :*** Notice -- TS for %s "
687 "changed from %ld to 0",
688 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
689 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
690 "Server %s changing TS on %s from %ld to 0",
691 source_p
->name
, chptr
->chname
, (long) oldts
);
696 chptr
->channelts
= newts
;
698 else if(newts
== 0 || oldts
== 0)
699 chptr
->channelts
= 0;
700 else if(newts
== oldts
)
702 else if(newts
< oldts
)
704 /* If configured, kick people trying to join +i/+k
705 * channels by recreating them on split servers.
706 * Don't kick if the source has sent EOB (services
707 * deopping everyone by TS-1 SJOIN).
709 if (ConfigChannel
.kick_on_split_riding
&&
710 !HasSentEob(source_p
) &&
711 ((mode
.mode
& MODE_INVITEONLY
) ||
712 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
714 struct membership
*msptr
;
716 int l
= rb_dlink_list_length(&chptr
->members
);
717 int b
= rb_dlink_list_length(&chptr
->banlist
) +
718 rb_dlink_list_length(&chptr
->exceptlist
) +
719 rb_dlink_list_length(&chptr
->invexlist
) +
720 rb_dlink_list_length(&chptr
->quietlist
);
722 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
725 who
= msptr
->client_p
;
726 sendto_one(who
, ":%s KICK %s %s :Net Rider",
727 me
.name
, chptr
->chname
, who
->name
);
729 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
730 ":%s KICK %s %s :Net Rider",
731 me
.id
, chptr
->chname
,
733 sendto_server(NULL
, chptr
, NOCAPS
, CAP_TS6
,
734 ":%s KICK %s %s :Net Rider",
735 me
.name
, chptr
->chname
, who
->name
);
736 remove_user_from_channel(msptr
);
742 /* Channel was emptied, create a new one */
743 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
744 return 0; /* oops! */
746 /* If the source does not do TS6,
747 * nontimestamped bans have been sent to it,
748 * but we have just lost those here. Let's
749 * warn the channel about this. Because
750 * of the kicks, any users on the channel
751 * will be at client_p. -- jilles */
752 if (!has_id(source_p
) && b
> 0)
753 sendto_one(client_p
, ":%s NOTICE %s :*** Notice -- possible ban desync on %s, please remove any bans just added by servers", get_id(&me
, client_p
), parv
[2], parv
[2]);
754 oldmode
= &chptr
->mode
;
758 chptr
->channelts
= newts
;
765 else if(keep_our_modes
)
767 mode
.mode
|= oldmode
->mode
;
768 if(oldmode
->limit
> mode
.limit
)
769 mode
.limit
= oldmode
->limit
;
770 if(strcmp(mode
.key
, oldmode
->key
) < 0)
771 strcpy(mode
.key
, oldmode
->key
);
772 if(oldmode
->join_num
> mode
.join_num
||
773 (oldmode
->join_num
== mode
.join_num
&&
774 oldmode
->join_time
> mode
.join_time
))
776 mode
.join_num
= oldmode
->join_num
;
777 mode
.join_time
= oldmode
->join_time
;
779 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
780 strcpy(mode
.forward
, oldmode
->forward
);
784 /* If setting -j, clear join throttle state -- jilles */
786 chptr
->join_count
= chptr
->join_delta
= 0;
789 set_final_mode(&mode
, oldmode
);
792 /* Lost the TS, other side wins, so remove modes on this side */
795 remove_our_modes(chptr
, fakesource_p
);
796 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
798 del_invite(chptr
, ptr
->data
);
800 sendto_channel_local(ALL_MEMBERS
, chptr
,
801 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
802 me
.name
, chptr
->chname
, chptr
->chname
,
803 (long) oldts
, (long) newts
);
804 /* Update capitalization in channel name, this makes the
805 * capitalization timestamped like modes are -- jilles */
806 strcpy(chptr
->chname
, parv
[2]);
810 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
811 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
813 *modebuf
= *parabuf
= '\0';
815 if(parv
[3][0] != '0' && keep_new_modes
)
816 modes
= channel_modes(chptr
, source_p
);
820 mlen_nick
= rb_sprintf(buf_nick
, ":%s SJOIN %ld %s %s :",
821 source_p
->name
, (long) chptr
->channelts
, parv
[2], modes
);
822 ptr_nick
= buf_nick
+ mlen_nick
;
824 /* working on the presumption eventually itll be more efficient to
825 * build a TS6 buffer without checking its needed..
827 mlen_uid
= rb_sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
828 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
829 ptr_uid
= buf_uid
+ mlen_uid
;
832 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
834 len_nick
= len_uid
= 0;
836 /* if theres a space, theres going to be more than one nick, change the
837 * first space to \0, so s is just the first nick, and point p to the
840 if((p
= strchr(s
, ' ')) != NULL
)
851 for (i
= 0; i
< 2; i
++)
865 /* if the client doesnt exist or is fake direction, skip. */
866 if(!(target_p
= find_client(s
)) ||
867 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
870 /* we assume for these we can fit at least one nick/uid in.. */
872 /* check we can fit another status+nick+space into a buffer */
873 if((mlen_nick
+ len_nick
+ NICKLEN
+ 3) > (BUFSIZE
- 3))
875 *(ptr_nick
- 1) = '\0';
876 sendto_server(client_p
->from
, NULL
, NOCAPS
, CAP_TS6
, "%s", buf_nick
);
877 ptr_nick
= buf_nick
+ mlen_nick
;
881 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
883 *(ptr_uid
- 1) = '\0';
884 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
885 ptr_uid
= buf_uid
+ mlen_uid
;
907 /* copy the nick to the two buffers */
908 len
= rb_sprintf(ptr_nick
, "%s ", target_p
->name
);
911 len
= rb_sprintf(ptr_uid
, "%s ", use_id(target_p
));
918 if(!IsMember(target_p
, chptr
))
920 add_user_to_channel(chptr
, target_p
, fl
);
921 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
923 target_p
->username
, target_p
->host
, parv
[2]);
930 para
[pargs
++] = target_p
->name
;
932 /* a +ov user.. bleh */
935 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
938 if(pargs
>= MAXMODEPARAMS
)
941 sendto_channel_local(ALL_MEMBERS
, chptr
,
942 ":%s MODE %s %s %s %s %s %s",
943 fakesource_p
->name
, chptr
->chname
,
945 para
[0], para
[1], para
[2], para
[3]);
948 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
953 para
[pargs
++] = target_p
->name
;
956 else if(fl
& CHFL_VOICE
)
959 para
[pargs
++] = target_p
->name
;
962 if(pargs
>= MAXMODEPARAMS
)
965 sendto_channel_local(ALL_MEMBERS
, chptr
,
966 ":%s MODE %s %s %s %s %s %s",
969 modebuf
, para
[0], para
[1], para
[2], para
[3]);
972 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
977 /* p points to the next nick */
980 /* if there was a trailing space and p was pointing to it, then we
981 * need to exit.. this has the side effect of breaking double spaces
982 * in an sjoin.. but that shouldnt happen anyway
984 if(s
&& (*s
== '\0'))
987 /* if p was NULL due to no spaces, s wont exist due to the above, so
988 * we cant check it for spaces.. if there are no spaces, then when
989 * we next get here, s will be NULL
991 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
1000 sendto_channel_local(ALL_MEMBERS
, chptr
,
1001 ":%s MODE %s %s %s %s %s %s",
1002 fakesource_p
->name
, chptr
->chname
, modebuf
,
1003 para
[0], CheckEmpty(para
[1]),
1004 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
1007 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
1009 destroy_channel(chptr
);
1014 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
1017 *(ptr_nick
- 1) = '\0';
1018 *(ptr_uid
- 1) = '\0';
1021 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
1022 sendto_server(client_p
->from
, NULL
, NOCAPS
, CAP_TS6
, "%s", buf_nick
);
1024 /* if the source does TS6 we have to remove our bans. Its now safe
1025 * to issue -b's to the non-ts6 servers, as the sjoin we've just
1026 * sent will kill any ops they have.
1028 if(!keep_our_modes
&& source_p
->id
[0] != '\0')
1030 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
1031 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', NOCAPS
, ALL_MEMBERS
);
1033 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
1034 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
1035 'e', CAP_EX
, ONLY_CHANOPS
);
1037 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
1038 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
1039 'I', CAP_IE
, ONLY_CHANOPS
);
1041 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
1042 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
1043 'q', NOCAPS
, ALL_MEMBERS
);
1054 * inputs - pointer to client doing join 0
1056 * side effects - Use has decided to join 0. This is legacy
1057 * from the days when channels were numbers not names. *sigh*
1058 * There is a bunch of evilness necessary here due to
1059 * anti spambot code.
1062 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
1064 struct membership
*msptr
;
1065 struct Channel
*chptr
= NULL
;
1068 /* Finish the flood grace period... */
1069 if(MyClient(source_p
) && !IsFloodDone(source_p
))
1070 flood_endgrace(source_p
);
1073 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
1074 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s JOIN 0", source_p
->name
);
1076 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
1077 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1078 check_spambot_warning(source_p
, NULL
);
1080 while((ptr
= source_p
->user
->channel
.head
))
1083 chptr
= msptr
->chptr
;
1084 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
1086 source_p
->username
, source_p
->host
, chptr
->chname
);
1087 remove_user_from_channel(msptr
);
1092 check_channel_name_loc(struct Client
*source_p
, const char *name
)
1094 s_assert(name
!= NULL
);
1095 if(EmptyString(name
))
1098 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1100 for(; *name
; ++name
)
1102 if(!IsChanChar(*name
) || IsFakeChanChar(*name
))
1108 for(; *name
; ++name
)
1110 if(!IsChanChar(*name
))
1119 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1121 int dir
= MODE_QUERY
;
1122 char *pbuf
= parabuf
;
1126 /* ok, first get a list of modes we need to add */
1127 for (i
= 0; chmode_flags
[i
].letter
; i
++)
1129 if((mode
->mode
& chmode_flags
[i
].mode
) && !(oldmode
->mode
& chmode_flags
[i
].mode
))
1136 *mbuf
++ = chmode_flags
[i
].letter
;
1140 /* now the ones we need to remove. */
1141 for (i
= 0; chmode_flags
[i
].letter
; i
++)
1143 if((oldmode
->mode
& chmode_flags
[i
].mode
) && !(mode
->mode
& chmode_flags
[i
].mode
))
1150 *mbuf
++ = chmode_flags
[i
].letter
;
1154 if(oldmode
->limit
&& !mode
->limit
)
1163 if(oldmode
->key
[0] && !mode
->key
[0])
1171 len
= rb_sprintf(pbuf
, "%s ", oldmode
->key
);
1174 if(oldmode
->join_num
&& !mode
->join_num
)
1183 if(oldmode
->forward
[0] && !mode
->forward
[0])
1192 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1200 len
= rb_sprintf(pbuf
, "%d ", mode
->limit
);
1203 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1211 len
= rb_sprintf(pbuf
, "%s ", mode
->key
);
1214 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1222 len
= rb_sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1225 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) && ConfigChannel
.use_forward
)
1233 len
= rb_sprintf(pbuf
, "%s ", mode
->forward
);
1247 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1249 struct membership
*msptr
;
1251 char lmodebuf
[MODEBUFLEN
];
1252 char *lpara
[MAXMODEPARAMS
];
1259 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1262 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1266 if(is_chanop(msptr
))
1268 msptr
->flags
&= ~CHFL_CHANOP
;
1269 lpara
[count
++] = msptr
->client_p
->name
;
1272 /* +ov, might not fit so check. */
1273 if(is_voiced(msptr
))
1275 if(count
>= MAXMODEPARAMS
)
1278 sendto_channel_local(ALL_MEMBERS
, chptr
,
1279 ":%s MODE %s %s %s %s %s %s",
1280 me
.name
, chptr
->chname
,
1281 lmodebuf
, lpara
[0], lpara
[1],
1282 lpara
[2], lpara
[3]);
1284 /* preserve the initial '-' */
1289 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1293 msptr
->flags
&= ~CHFL_VOICE
;
1294 lpara
[count
++] = msptr
->client_p
->name
;
1298 else if(is_voiced(msptr
))
1300 msptr
->flags
&= ~CHFL_VOICE
;
1301 lpara
[count
++] = msptr
->client_p
->name
;
1307 if(count
>= MAXMODEPARAMS
)
1310 sendto_channel_local(ALL_MEMBERS
, chptr
,
1311 ":%s MODE %s %s %s %s %s %s",
1312 me
.name
, chptr
->chname
, lmodebuf
,
1313 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1318 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1326 sendto_channel_local(ALL_MEMBERS
, chptr
,
1327 ":%s MODE %s %s %s %s %s %s",
1328 me
.name
, chptr
->chname
, lmodebuf
,
1329 EmptyString(lpara
[0]) ? "" : lpara
[0],
1330 EmptyString(lpara
[1]) ? "" : lpara
[1],
1331 EmptyString(lpara
[2]) ? "" : lpara
[2],
1332 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1337 /* remove_ban_list()
1339 * inputs - channel, source, list to remove, char of mode, caps needed
1341 * side effects - given list is removed, with modes issued to local clients
1342 * and non-TS6 servers.
1345 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1346 rb_dlink_list
* list
, char c
, int cap
, int mems
)
1348 static char lmodebuf
[BUFSIZE
];
1349 static char lparabuf
[BUFSIZE
];
1352 rb_dlink_node
*next_ptr
;
1355 int cur_len
, mlen
, plen
;
1359 cur_len
= mlen
= rb_sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1360 mbuf
= lmodebuf
+ mlen
;
1362 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1366 /* trailing space, and the mode letter itself */
1367 plen
= strlen(banptr
->banstr
) + 2;
1369 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1371 /* remove trailing space */
1375 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1376 /* Tricky tricky. If we changed source_p to &me
1377 * in ms_sjoin(), this still won't send stuff
1378 * where it should not be sent, because the
1379 * real source_p does TS6 -- jilles */
1380 sendto_server(source_p
, chptr
, cap
, CAP_TS6
, "%s %s", lmodebuf
, lparabuf
);
1383 mbuf
= lmodebuf
+ mlen
;
1390 pbuf
+= rb_sprintf(pbuf
, "%s ", banptr
->banstr
);
1398 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1399 sendto_server(source_p
, chptr
, cap
, CAP_TS6
, "%s %s", lmodebuf
, lparabuf
);
1401 list
->head
= list
->tail
= NULL
;