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 $
38 #include "s_newconf.h"
44 static int m_join(struct Client
*, struct Client
*, int, const char **);
45 static int ms_join(struct Client
*, struct Client
*, int, const char **);
46 static int ms_sjoin(struct Client
*, struct Client
*, int, const char **);
48 static int h_can_create_channel
;
49 static int h_channel_join
;
51 struct Message join_msgtab
= {
52 "JOIN", 0, 0, 0, MFLG_SLOW
,
53 {mg_unreg
, {m_join
, 2}, {ms_join
, 2}, mg_ignore
, mg_ignore
, {m_join
, 2}}
56 struct Message sjoin_msgtab
= {
57 "SJOIN", 0, 0, 0, MFLG_SLOW
,
58 {mg_unreg
, mg_ignore
, mg_ignore
, {ms_sjoin
, 4}, mg_ignore
, mg_ignore
}
61 mapi_clist_av1 join_clist
[] = { &join_msgtab
, &sjoin_msgtab
, NULL
};
63 mapi_hlist_av1 join_hlist
[] = {
64 { "can_create_channel", &h_can_create_channel
},
65 { "channel_join", &h_channel_join
},
69 DECLARE_MODULE_AV1(join
, NULL
, NULL
, join_clist
, join_hlist
, NULL
, "$Revision: 3494 $");
71 static void do_join_0(struct Client
*client_p
, struct Client
*source_p
);
72 static int check_channel_name_loc(struct Client
*source_p
, const char *name
);
74 static void set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
);
75 static void remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
);
77 static void remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
78 rb_dlink_list
* list
, char c
, int mems
);
80 static char modebuf
[MODEBUFLEN
];
81 static char parabuf
[MODEBUFLEN
];
82 static const char *para
[MAXMODEPARAMS
];
86 /* Check what we will forward to, without sending any notices to the user
89 static struct Channel
*
90 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
96 if (IsNoForward(source_p
))
101 chptr
= find_channel(chptr
->mode
.forward
);
102 /* Can only forward to existing channels */
105 /* Already on there, show original error message */
106 if (IsMember(source_p
, chptr
))
108 /* Juped. Sending a warning notice would be unfair */
109 if (hash_find_resv(chptr
->chname
))
111 /* Don't forward to +Q channel */
112 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
114 i
= can_join(source_p
, chptr
, key
);
117 if (i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_CHANNELISFULL
)
127 * parv[0] = sender prefix
129 * parv[2] = channel password (key)
132 m_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
134 static char jbuf
[BUFSIZE
];
135 struct Channel
*chptr
= NULL
;
136 struct ConfItem
*aconf
;
140 char *p
= NULL
, *p2
= NULL
;
143 int successful_join_count
= 0; /* Number of channels successfully joined */
147 /* rebuild the list of channels theyre supposed to be joining.
148 * this code has a side effect of losing keys, but..
150 chanlist
= LOCAL_COPY(parv
[1]);
151 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
153 /* check the length and name of channel is ok */
154 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
156 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
157 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
161 /* join 0 parts all channels */
162 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
164 (void) strcpy(jbuf
, "0");
168 /* check it begins with # or &, and local chans are disabled */
169 else if(!IsChannelName(name
))
171 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
172 form_str(ERR_NOSUCHCHANNEL
), name
);
176 /* see if its resv'd */
177 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
179 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
180 form_str(ERR_BADCHANNAME
), name
);
182 /* dont warn for opers */
183 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
184 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
185 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
186 source_p
->name
, source_p
->username
,
187 source_p
->orighost
, name
, aconf
->passwd
);
188 /* dont update tracking for jupe exempt users, these
189 * are likely to be spamtrap leaves
191 else if(IsExemptJupe(source_p
))
197 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
198 ConfigChannel
.no_join_on_split
)
200 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
201 me
.name
, source_p
->name
, name
);
206 (void) strcat(jbuf
, ",");
207 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
212 mykey
= LOCAL_COPY(parv
[2]);
213 key
= rb_strtok_r(mykey
, ",", &p2
);
216 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
217 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
219 hook_data_channel_activity hook_info
;
221 /* JOIN 0 simply parts all channels the user is in */
222 if(*name
== '0' && !atoi(name
))
224 if(source_p
->user
->channel
.head
== NULL
)
227 do_join_0(&me
, source_p
);
231 /* look for the channel */
232 if((chptr
= find_channel(name
)) != NULL
)
234 if(IsMember(source_p
, chptr
))
241 hook_data_client_approval moduledata
;
243 moduledata
.client
= source_p
;
244 moduledata
.approved
= 0;
246 call_hook(h_can_create_channel
, &moduledata
);
248 if(moduledata
.approved
!= 0)
250 sendto_one(source_p
, form_str(moduledata
.approved
),
251 me
.name
, source_p
->name
, name
);
255 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
256 ConfigChannel
.no_create_on_split
)
258 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
259 me
.name
, source_p
->name
, name
);
266 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
267 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
268 (!IsOper(source_p
) ||
269 (rb_dlink_list_length(&source_p
->user
->channel
) >=
270 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
272 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
273 me
.name
, source_p
->name
, name
);
274 if(successful_join_count
)
275 source_p
->localClient
->last_join_time
= rb_current_time();
279 if(flags
== 0) /* if channel doesn't exist, don't penalize */
280 successful_join_count
++;
282 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
284 chptr
= get_or_create_channel(source_p
, name
, NULL
);
288 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
289 me
.name
, source_p
->name
, name
);
290 if(successful_join_count
> 0)
291 successful_join_count
--;
296 if(!IsOper(source_p
) && !IsExemptSpambot(source_p
))
297 check_spambot_warning(source_p
, name
);
299 /* can_join checks for +i key, bans etc */
300 if((i
= can_join(source_p
, chptr
, key
)))
302 if ((i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_CHANNELISFULL
) ||
303 (!ConfigChannel
.use_forward
|| (chptr
= check_forward(source_p
, chptr
, key
)) == NULL
))
305 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
306 if(successful_join_count
> 0)
307 successful_join_count
--;
310 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr
->chname
);
313 /* add the user to the channel */
314 add_user_to_channel(chptr
, source_p
, flags
);
315 if (chptr
->mode
.join_num
&&
316 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
318 chptr
->join_count
= 0;
319 chptr
->join_delta
= rb_current_time();
323 /* we send the user their join here, because we could have to
324 * send a mode out next.
326 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
328 source_p
->username
, source_p
->host
, chptr
->chname
);
330 /* its a new channel, set +nt and burst. */
331 if(flags
& CHFL_CHANOP
)
333 chptr
->channelts
= rb_current_time();
334 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
335 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
337 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s +nt",
338 me
.name
, chptr
->chname
);
340 if(*chptr
->chname
== '#')
342 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
343 ":%s SJOIN %ld %s +nt :@%s",
344 me
.id
, (long) chptr
->channelts
,
345 chptr
->chname
, source_p
->id
);
350 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
352 use_id(source_p
), (long) chptr
->channelts
,
356 del_invite(chptr
, source_p
);
358 if(chptr
->topic
!= NULL
)
360 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
361 source_p
->name
, chptr
->chname
, chptr
->topic
);
363 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
364 me
.name
, source_p
->name
, chptr
->chname
,
365 chptr
->topic_info
, chptr
->topic_time
);
368 channel_member_names(chptr
, source_p
, 1);
370 if(successful_join_count
)
371 source_p
->localClient
->last_join_time
= rb_current_time();
373 hook_info
.client
= source_p
;
374 hook_info
.chptr
= chptr
;
376 call_hook(h_channel_join
, &hook_info
);
387 * side effects - handles remote JOIN's sent by servers. In TSora
388 * remote clients are joined using SJOIN, hence a
389 * JOIN sent by a server on behalf of a client is an error.
390 * here, the initial code is in to take an extra parameter
391 * and use it for the TimeStamp on a new channel.
394 ms_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
396 struct Channel
*chptr
;
397 static struct Mode mode
;
401 int keep_our_modes
= YES
;
402 int keep_new_modes
= YES
;
403 rb_dlink_node
*ptr
, *next_ptr
;
405 /* special case for join 0 */
406 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
408 do_join_0(client_p
, source_p
);
415 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
418 /* joins for local channels cant happen. */
419 if(parv
[2][0] == '&')
423 mode
.key
[0] = mode
.forward
[0] = '\0';
424 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
426 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
429 newts
= atol(parv
[1]);
430 oldts
= chptr
->channelts
;
432 #ifdef IGNORE_BOGUS_TS
433 if(newts
< 800000000)
435 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
436 "*** Bogus TS %ld on %s ignored from %s",
437 (long) newts
, chptr
->chname
, client_p
->name
);
438 newts
= (oldts
== 0) ? oldts
: 800000000;
441 /* making a channel TS0 */
442 if(!isnew
&& !newts
&& oldts
)
444 sendto_channel_local(ALL_MEMBERS
, chptr
,
445 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
446 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
447 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
448 "Server %s changing TS on %s from %ld to 0",
449 source_p
->name
, chptr
->chname
, (long) oldts
);
454 chptr
->channelts
= newts
;
455 else if(newts
== 0 || oldts
== 0)
456 chptr
->channelts
= 0;
457 else if(newts
== oldts
)
459 else if(newts
< oldts
)
462 chptr
->channelts
= newts
;
467 /* Lost the TS, other side wins, so remove modes on this side */
470 set_final_mode(&mode
, &chptr
->mode
);
472 remove_our_modes(chptr
, source_p
);
473 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
475 del_invite(chptr
, ptr
->data
);
477 /* If setting -j, clear join throttle state -- jilles */
478 chptr
->join_count
= chptr
->join_delta
= 0;
479 sendto_channel_local(ALL_MEMBERS
, chptr
,
480 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
481 me
.name
, chptr
->chname
, chptr
->chname
,
482 (long) oldts
, (long) newts
);
483 /* Update capitalization in channel name, this makes the
484 * capitalization timestamped like modes are -- jilles */
485 strcpy(chptr
->chname
, parv
[2]);
487 sendto_channel_local(ALL_MEMBERS
, chptr
,
489 source_p
->servptr
->name
,
490 chptr
->chname
, modebuf
, parabuf
);
491 *modebuf
= *parabuf
= '\0';
494 if(!IsMember(source_p
, chptr
))
496 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
497 if (chptr
->mode
.join_num
&&
498 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
500 chptr
->join_count
= 0;
501 chptr
->join_delta
= rb_current_time();
504 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
505 source_p
->name
, source_p
->username
,
506 source_p
->host
, chptr
->chname
);
509 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
511 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
516 ms_sjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
518 static char buf_uid
[BUFSIZE
];
519 static const char empty_modes
[] = "0";
520 struct Channel
*chptr
;
521 struct Client
*target_p
, *fakesource_p
;
524 static struct Mode mode
, *oldmode
;
527 int keep_our_modes
= 1;
528 int keep_new_modes
= 1;
539 int i
, joinc
= 0, timeslice
= 0;
540 static char empty
[] = "";
541 rb_dlink_node
*ptr
, *next_ptr
;
543 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
546 /* SJOIN's for local channels can't happen. */
550 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
551 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
553 /* Hide connecting server on netburst -- jilles */
554 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
557 fakesource_p
= source_p
;
560 newts
= atol(parv
[1]);
568 mode
.mode
|= MODE_INVITEONLY
;
571 mode
.mode
|= MODE_NOPRIVMSGS
;
574 mode
.mode
|= MODE_PRIVATE
;
577 mode
.mode
|= MODE_SECRET
;
580 mode
.mode
|= MODE_MODERATED
;
583 mode
.mode
|= MODE_TOPICLIMIT
;
586 mode
.mode
|= MODE_REGONLY
;
589 mode
.mode
|= MODE_EXLIMIT
;
592 mode
.mode
|= MODE_PERMANENT
;
595 mode
.mode
|= MODE_NOCOLOR
;
598 mode
.mode
|= MODE_FREEINVITE
;
601 mode
.mode
|= MODE_OPMODERATE
;
604 mode
.mode
|= MODE_FREETARGET
;
607 mode
.mode
|= MODE_DISFORWARD
;
610 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
616 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
618 mode
.join_num
= joinc
;
619 mode
.join_time
= timeslice
;
624 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
630 mode
.limit
= atoi(parv
[4 + args
]);
642 /* remove any leading spaces */
649 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
650 return 0; /* channel name too long? */
653 oldts
= chptr
->channelts
;
654 oldmode
= &chptr
->mode
;
656 #ifdef IGNORE_BOGUS_TS
657 if(newts
< 800000000)
659 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
660 "*** Bogus TS %ld on %s ignored from %s",
661 (long) newts
, chptr
->chname
, client_p
->name
);
663 newts
= (oldts
== 0) ? oldts
: 800000000;
666 if(!isnew
&& !newts
&& oldts
)
668 sendto_channel_local(ALL_MEMBERS
, chptr
,
669 ":%s NOTICE %s :*** Notice -- TS for %s "
670 "changed from %ld to 0",
671 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
672 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
673 "Server %s changing TS on %s from %ld to 0",
674 source_p
->name
, chptr
->chname
, (long) oldts
);
679 chptr
->channelts
= newts
;
681 else if(newts
== 0 || oldts
== 0)
682 chptr
->channelts
= 0;
683 else if(newts
== oldts
)
685 else if(newts
< oldts
)
687 /* If configured, kick people trying to join +i/+k
688 * channels by recreating them on split servers.
689 * Don't kick if the source has sent EOB (services
690 * deopping everyone by TS-1 SJOIN).
692 if (ConfigChannel
.kick_on_split_riding
&&
693 !HasSentEob(source_p
) &&
694 ((mode
.mode
& MODE_INVITEONLY
) ||
695 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
697 struct membership
*msptr
;
699 int l
= rb_dlink_list_length(&chptr
->members
);
701 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
704 who
= msptr
->client_p
;
705 sendto_one(who
, ":%s KICK %s %s :Net Rider",
706 me
.name
, chptr
->chname
, who
->name
);
708 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
709 ":%s KICK %s %s :Net Rider",
710 me
.id
, chptr
->chname
,
712 remove_user_from_channel(msptr
);
718 /* Channel was emptied, create a new one */
719 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
720 return 0; /* oops! */
722 oldmode
= &chptr
->mode
;
726 chptr
->channelts
= newts
;
733 else if(keep_our_modes
)
735 mode
.mode
|= oldmode
->mode
;
736 if(oldmode
->limit
> mode
.limit
)
737 mode
.limit
= oldmode
->limit
;
738 if(strcmp(mode
.key
, oldmode
->key
) < 0)
739 strcpy(mode
.key
, oldmode
->key
);
740 if(oldmode
->join_num
> mode
.join_num
||
741 (oldmode
->join_num
== mode
.join_num
&&
742 oldmode
->join_time
> mode
.join_time
))
744 mode
.join_num
= oldmode
->join_num
;
745 mode
.join_time
= oldmode
->join_time
;
747 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
748 strcpy(mode
.forward
, oldmode
->forward
);
752 /* If setting -j, clear join throttle state -- jilles */
754 chptr
->join_count
= chptr
->join_delta
= 0;
757 set_final_mode(&mode
, oldmode
);
760 /* Lost the TS, other side wins, so remove modes on this side */
763 remove_our_modes(chptr
, fakesource_p
);
764 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
766 del_invite(chptr
, ptr
->data
);
768 sendto_channel_local(ALL_MEMBERS
, chptr
,
769 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
770 me
.name
, chptr
->chname
, chptr
->chname
,
771 (long) oldts
, (long) newts
);
772 /* Update capitalization in channel name, this makes the
773 * capitalization timestamped like modes are -- jilles */
774 strcpy(chptr
->chname
, parv
[2]);
778 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
779 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
781 *modebuf
= *parabuf
= '\0';
783 if(parv
[3][0] != '0' && keep_new_modes
)
784 modes
= channel_modes(chptr
, source_p
);
788 /* working on the presumption eventually itll be more efficient to
789 * build a TS6 buffer without checking its needed..
791 mlen_uid
= rb_sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
792 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
793 ptr_uid
= buf_uid
+ mlen_uid
;
796 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
798 len_nick
= len_uid
= 0;
800 /* if theres a space, theres going to be more than one nick, change the
801 * first space to \0, so s is just the first nick, and point p to the
804 if((p
= strchr(s
, ' ')) != NULL
)
815 for (i
= 0; i
< 2; i
++)
829 /* if the client doesnt exist or is fake direction, skip. */
830 if(!(target_p
= find_client(s
)) ||
831 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
834 /* we assume for these we can fit at least one nick/uid in.. */
836 /* check we can fit another status+nick+space into a buffer */
837 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
839 *(ptr_uid
- 1) = '\0';
840 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
841 ptr_uid
= buf_uid
+ mlen_uid
;
861 /* copy the nick to the two buffers */
862 len
= rb_sprintf(ptr_uid
, "%s ", use_id(target_p
));
869 if(!IsMember(target_p
, chptr
))
871 add_user_to_channel(chptr
, target_p
, fl
);
872 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
874 target_p
->username
, target_p
->host
, parv
[2]);
881 para
[pargs
++] = target_p
->name
;
883 /* a +ov user.. bleh */
886 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
889 if(pargs
>= MAXMODEPARAMS
)
892 sendto_channel_local(ALL_MEMBERS
, chptr
,
893 ":%s MODE %s %s %s %s %s %s",
894 fakesource_p
->name
, chptr
->chname
,
896 para
[0], para
[1], para
[2], para
[3]);
899 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
904 para
[pargs
++] = target_p
->name
;
907 else if(fl
& CHFL_VOICE
)
910 para
[pargs
++] = target_p
->name
;
913 if(pargs
>= MAXMODEPARAMS
)
916 sendto_channel_local(ALL_MEMBERS
, chptr
,
917 ":%s MODE %s %s %s %s %s %s",
920 modebuf
, para
[0], para
[1], para
[2], para
[3]);
923 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
928 /* p points to the next nick */
931 /* if there was a trailing space and p was pointing to it, then we
932 * need to exit.. this has the side effect of breaking double spaces
933 * in an sjoin.. but that shouldnt happen anyway
935 if(s
&& (*s
== '\0'))
938 /* if p was NULL due to no spaces, s wont exist due to the above, so
939 * we cant check it for spaces.. if there are no spaces, then when
940 * we next get here, s will be NULL
942 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
951 sendto_channel_local(ALL_MEMBERS
, chptr
,
952 ":%s MODE %s %s %s %s %s %s",
953 fakesource_p
->name
, chptr
->chname
, modebuf
,
954 para
[0], CheckEmpty(para
[1]),
955 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
958 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
960 destroy_channel(chptr
);
965 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
968 *(ptr_uid
- 1) = '\0';
971 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
973 /* if the source does TS6 we have to remove our bans. */
976 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
977 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
979 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
980 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
983 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
984 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
987 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
988 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
1000 * inputs - pointer to client doing join 0
1002 * side effects - Use has decided to join 0. This is legacy
1003 * from the days when channels were numbers not names. *sigh*
1004 * There is a bunch of evilness necessary here due to
1005 * anti spambot code.
1008 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
1010 struct membership
*msptr
;
1011 struct Channel
*chptr
= NULL
;
1014 /* Finish the flood grace period... */
1015 if(MyClient(source_p
) && !IsFloodDone(source_p
))
1016 flood_endgrace(source_p
);
1018 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
1020 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
1021 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
1022 check_spambot_warning(source_p
, NULL
);
1024 while((ptr
= source_p
->user
->channel
.head
))
1027 chptr
= msptr
->chptr
;
1028 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
1030 source_p
->username
, source_p
->host
, chptr
->chname
);
1031 remove_user_from_channel(msptr
);
1036 check_channel_name_loc(struct Client
*source_p
, const char *name
)
1038 s_assert(name
!= NULL
);
1039 if(EmptyString(name
))
1042 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1044 for(; *name
; ++name
)
1046 if(!IsChanChar(*name
) || IsFakeChanChar(*name
))
1052 for(; *name
; ++name
)
1054 if(!IsChanChar(*name
))
1063 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1065 int dir
= MODE_QUERY
;
1066 char *pbuf
= parabuf
;
1070 /* ok, first get a list of modes we need to add */
1071 for (i
= 0; chmode_flags
[i
].letter
; i
++)
1073 if((mode
->mode
& chmode_flags
[i
].mode
) && !(oldmode
->mode
& chmode_flags
[i
].mode
))
1080 *mbuf
++ = chmode_flags
[i
].letter
;
1084 /* now the ones we need to remove. */
1085 for (i
= 0; chmode_flags
[i
].letter
; i
++)
1087 if((oldmode
->mode
& chmode_flags
[i
].mode
) && !(mode
->mode
& chmode_flags
[i
].mode
))
1094 *mbuf
++ = chmode_flags
[i
].letter
;
1098 if(oldmode
->limit
&& !mode
->limit
)
1107 if(oldmode
->key
[0] && !mode
->key
[0])
1115 len
= rb_sprintf(pbuf
, "%s ", oldmode
->key
);
1118 if(oldmode
->join_num
&& !mode
->join_num
)
1127 if(oldmode
->forward
[0] && !mode
->forward
[0])
1136 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1144 len
= rb_sprintf(pbuf
, "%d ", mode
->limit
);
1147 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1155 len
= rb_sprintf(pbuf
, "%s ", mode
->key
);
1158 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1166 len
= rb_sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1169 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) && ConfigChannel
.use_forward
)
1177 len
= rb_sprintf(pbuf
, "%s ", mode
->forward
);
1191 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1193 struct membership
*msptr
;
1195 char lmodebuf
[MODEBUFLEN
];
1196 char *lpara
[MAXMODEPARAMS
];
1203 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1206 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1210 if(is_chanop(msptr
))
1212 msptr
->flags
&= ~CHFL_CHANOP
;
1213 lpara
[count
++] = msptr
->client_p
->name
;
1216 /* +ov, might not fit so check. */
1217 if(is_voiced(msptr
))
1219 if(count
>= MAXMODEPARAMS
)
1222 sendto_channel_local(ALL_MEMBERS
, chptr
,
1223 ":%s MODE %s %s %s %s %s %s",
1224 me
.name
, chptr
->chname
,
1225 lmodebuf
, lpara
[0], lpara
[1],
1226 lpara
[2], lpara
[3]);
1228 /* preserve the initial '-' */
1233 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1237 msptr
->flags
&= ~CHFL_VOICE
;
1238 lpara
[count
++] = msptr
->client_p
->name
;
1242 else if(is_voiced(msptr
))
1244 msptr
->flags
&= ~CHFL_VOICE
;
1245 lpara
[count
++] = msptr
->client_p
->name
;
1251 if(count
>= MAXMODEPARAMS
)
1254 sendto_channel_local(ALL_MEMBERS
, chptr
,
1255 ":%s MODE %s %s %s %s %s %s",
1256 me
.name
, chptr
->chname
, lmodebuf
,
1257 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1262 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1270 sendto_channel_local(ALL_MEMBERS
, chptr
,
1271 ":%s MODE %s %s %s %s %s %s",
1272 me
.name
, chptr
->chname
, lmodebuf
,
1273 EmptyString(lpara
[0]) ? "" : lpara
[0],
1274 EmptyString(lpara
[1]) ? "" : lpara
[1],
1275 EmptyString(lpara
[2]) ? "" : lpara
[2],
1276 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1281 /* remove_ban_list()
1283 * inputs - channel, source, list to remove, char of mode, caps needed
1285 * side effects - given list is removed, with modes issued to local clients
1288 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1289 rb_dlink_list
* list
, char c
, int mems
)
1291 static char lmodebuf
[BUFSIZE
];
1292 static char lparabuf
[BUFSIZE
];
1295 rb_dlink_node
*next_ptr
;
1298 int cur_len
, mlen
, plen
;
1302 cur_len
= mlen
= rb_sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1303 mbuf
= lmodebuf
+ mlen
;
1305 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1309 /* trailing space, and the mode letter itself */
1310 plen
= strlen(banptr
->banstr
) + 2;
1312 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1314 /* remove trailing space */
1318 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1321 mbuf
= lmodebuf
+ mlen
;
1328 pbuf
+= rb_sprintf(pbuf
, "%s ", banptr
->banstr
);
1336 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1338 list
->head
= list
->tail
= NULL
;