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"
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
, 4}, 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 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
;
142 char *p
= NULL
, *p2
= NULL
;
145 int successful_join_count
= 0; /* Number of channels successfully joined */
149 /* rebuild the list of channels theyre supposed to be joining.
150 * this code has a side effect of losing keys, but..
152 chanlist
= LOCAL_COPY(parv
[1]);
153 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
155 /* check the length and name of channel is ok */
156 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
158 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
159 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
163 /* join 0 parts all channels */
164 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
166 (void) strcpy(jbuf
, "0");
170 /* check it begins with # or &, and local chans are disabled */
171 else if(!IsChannelName(name
))
173 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
174 form_str(ERR_NOSUCHCHANNEL
), name
);
178 /* see if its resv'd */
179 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
181 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
182 form_str(ERR_BADCHANNAME
), name
);
184 /* dont warn for opers */
185 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
186 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
187 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
188 source_p
->name
, source_p
->username
,
189 source_p
->orighost
, name
, aconf
->passwd
);
190 /* dont update tracking for jupe exempt users, these
191 * are likely to be spamtrap leaves
193 else if(IsExemptJupe(source_p
))
199 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
200 ConfigChannel
.no_join_on_split
)
202 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
203 me
.name
, source_p
->name
, name
);
208 (void) strcat(jbuf
, ",");
209 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
214 mykey
= LOCAL_COPY(parv
[2]);
215 key
= rb_strtok_r(mykey
, ",", &p2
);
218 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
219 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
221 hook_data_channel_activity hook_info
;
223 /* JOIN 0 simply parts all channels the user is in */
224 if(*name
== '0' && !atoi(name
))
226 if(source_p
->user
->channel
.head
== NULL
)
229 do_join_0(&me
, source_p
);
233 /* look for the channel */
234 if((chptr
= find_channel(name
)) != NULL
)
236 if(IsMember(source_p
, chptr
))
243 hook_data_client_approval moduledata
;
245 moduledata
.client
= source_p
;
246 moduledata
.approved
= 0;
248 call_hook(h_can_create_channel
, &moduledata
);
250 if(moduledata
.approved
!= 0)
252 sendto_one(source_p
, form_str(moduledata
.approved
),
253 me
.name
, source_p
->name
, name
);
257 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
258 ConfigChannel
.no_create_on_split
)
260 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
261 me
.name
, source_p
->name
, name
);
268 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
269 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
270 (!IsOper(source_p
) ||
271 (rb_dlink_list_length(&source_p
->user
->channel
) >=
272 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
274 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
275 me
.name
, source_p
->name
, name
);
276 if(successful_join_count
)
277 source_p
->localClient
->last_join_time
= rb_current_time();
281 if(flags
== 0) /* if channel doesn't exist, don't penalize */
282 successful_join_count
++;
284 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
286 chptr
= get_or_create_channel(source_p
, name
, NULL
);
290 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
291 me
.name
, source_p
->name
, name
);
292 if(successful_join_count
> 0)
293 successful_join_count
--;
298 if(!IsOper(source_p
) && !IsExemptSpambot(source_p
))
299 check_spambot_warning(source_p
, name
);
301 /* can_join checks for +i key, bans etc */
302 if((i
= can_join(source_p
, chptr
, key
)))
304 if ((i
!= ERR_NEEDREGGEDNICK
&& i
!= ERR_THROTTLE
&& i
!= ERR_INVITEONLYCHAN
&& i
!= ERR_CHANNELISFULL
) ||
305 (!ConfigChannel
.use_forward
|| (chptr
= check_forward(source_p
, chptr
, key
)) == NULL
))
307 /* might be wrong, but is there any other better location for such?
308 * see extensions/chm_operonly.c for other comments on this
312 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
314 if(successful_join_count
> 0)
315 successful_join_count
--;
319 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr
->chname
);
322 /* add the user to the channel */
323 add_user_to_channel(chptr
, source_p
, flags
);
324 if (chptr
->mode
.join_num
&&
325 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
327 chptr
->join_count
= 0;
328 chptr
->join_delta
= rb_current_time();
332 /* we send the user their join here, because we could have to
333 * send a mode out next.
335 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
337 source_p
->username
, source_p
->host
, chptr
->chname
);
339 /* its a new channel, set +nt and burst. */
340 if(flags
& CHFL_CHANOP
)
342 chptr
->channelts
= rb_current_time();
343 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
344 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
345 modes
= channel_modes(chptr
, &me
);
347 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
348 me
.name
, chptr
->chname
, modes
);
350 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
351 ":%s SJOIN %ld %s %s :@%s",
352 me
.id
, (long) chptr
->channelts
,
353 chptr
->chname
, modes
, source_p
->id
);
357 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
359 use_id(source_p
), (long) chptr
->channelts
,
363 del_invite(chptr
, source_p
);
365 if(chptr
->topic
!= NULL
)
367 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
368 source_p
->name
, chptr
->chname
, chptr
->topic
);
370 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
371 me
.name
, source_p
->name
, chptr
->chname
,
372 chptr
->topic_info
, chptr
->topic_time
);
375 channel_member_names(chptr
, source_p
, 1);
377 if(successful_join_count
)
378 source_p
->localClient
->last_join_time
= rb_current_time();
380 hook_info
.client
= source_p
;
381 hook_info
.chptr
= chptr
;
383 call_hook(h_channel_join
, &hook_info
);
394 * side effects - handles remote JOIN's sent by servers. In TSora
395 * remote clients are joined using SJOIN, hence a
396 * JOIN sent by a server on behalf of a client is an error.
397 * here, the initial code is in to take an extra parameter
398 * and use it for the TimeStamp on a new channel.
401 ms_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
403 struct Channel
*chptr
;
404 static struct Mode mode
;
408 int keep_our_modes
= YES
;
409 int keep_new_modes
= YES
;
410 rb_dlink_node
*ptr
, *next_ptr
;
412 /* special case for join 0 */
413 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
415 do_join_0(client_p
, source_p
);
422 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
425 /* joins for local channels cant happen. */
426 if(parv
[2][0] == '&')
430 mode
.key
[0] = mode
.forward
[0] = '\0';
431 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
433 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
436 newts
= atol(parv
[1]);
437 oldts
= chptr
->channelts
;
439 #ifdef IGNORE_BOGUS_TS
440 if(newts
< 800000000)
442 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
443 "*** Bogus TS %ld on %s ignored from %s",
444 (long) newts
, chptr
->chname
, client_p
->name
);
445 newts
= (oldts
== 0) ? oldts
: 800000000;
448 /* making a channel TS0 */
449 if(!isnew
&& !newts
&& oldts
)
451 sendto_channel_local(ALL_MEMBERS
, chptr
,
452 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
453 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
454 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
455 "Server %s changing TS on %s from %ld to 0",
456 source_p
->name
, chptr
->chname
, (long) oldts
);
461 chptr
->channelts
= newts
;
462 else if(newts
== 0 || oldts
== 0)
463 chptr
->channelts
= 0;
464 else if(newts
== oldts
)
466 else if(newts
< oldts
)
469 chptr
->channelts
= newts
;
474 /* Lost the TS, other side wins, so remove modes on this side */
477 set_final_mode(&mode
, &chptr
->mode
);
479 remove_our_modes(chptr
, source_p
);
480 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
482 del_invite(chptr
, ptr
->data
);
484 /* If setting -j, clear join throttle state -- jilles */
485 chptr
->join_count
= chptr
->join_delta
= 0;
486 sendto_channel_local(ALL_MEMBERS
, chptr
,
487 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
488 me
.name
, chptr
->chname
, chptr
->chname
,
489 (long) oldts
, (long) newts
);
490 /* Update capitalization in channel name, this makes the
491 * capitalization timestamped like modes are -- jilles */
492 strcpy(chptr
->chname
, parv
[2]);
494 sendto_channel_local(ALL_MEMBERS
, chptr
,
496 source_p
->servptr
->name
,
497 chptr
->chname
, modebuf
, parabuf
);
498 *modebuf
= *parabuf
= '\0';
501 if(!IsMember(source_p
, chptr
))
503 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
504 if (chptr
->mode
.join_num
&&
505 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
507 chptr
->join_count
= 0;
508 chptr
->join_delta
= rb_current_time();
511 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
512 source_p
->name
, source_p
->username
,
513 source_p
->host
, chptr
->chname
);
516 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
518 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
523 ms_sjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
525 static char buf_uid
[BUFSIZE
];
526 static const char empty_modes
[] = "0";
527 struct Channel
*chptr
;
528 struct Client
*target_p
, *fakesource_p
;
531 static struct Mode mode
, *oldmode
;
534 int keep_our_modes
= 1;
535 int keep_new_modes
= 1;
546 int i
, joinc
= 0, timeslice
= 0;
547 static char empty
[] = "";
548 rb_dlink_node
*ptr
, *next_ptr
;
550 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
553 /* SJOIN's for local channels can't happen. */
557 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
558 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
560 /* Hide connecting server on netburst -- jilles */
561 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
564 fakesource_p
= source_p
;
567 newts
= atol(parv
[1]);
575 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
581 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
583 mode
.join_num
= joinc
;
584 mode
.join_time
= timeslice
;
589 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
595 mode
.limit
= atoi(parv
[4 + args
]);
601 if(chmode_flags
[(int) *s
] != 0)
603 mode
.mode
|= chmode_flags
[(int) *s
];
612 /* remove any leading spaces */
619 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
620 return 0; /* channel name too long? */
623 oldts
= chptr
->channelts
;
624 oldmode
= &chptr
->mode
;
626 #ifdef IGNORE_BOGUS_TS
627 if(newts
< 800000000)
629 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
630 "*** Bogus TS %ld on %s ignored from %s",
631 (long) newts
, chptr
->chname
, client_p
->name
);
633 newts
= (oldts
== 0) ? oldts
: 800000000;
636 if(!isnew
&& !newts
&& oldts
)
638 sendto_channel_local(ALL_MEMBERS
, chptr
,
639 ":%s NOTICE %s :*** Notice -- TS for %s "
640 "changed from %ld to 0",
641 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
642 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
643 "Server %s changing TS on %s from %ld to 0",
644 source_p
->name
, chptr
->chname
, (long) oldts
);
649 chptr
->channelts
= newts
;
651 else if(newts
== 0 || oldts
== 0)
652 chptr
->channelts
= 0;
653 else if(newts
== oldts
)
655 else if(newts
< oldts
)
657 /* If configured, kick people trying to join +i/+k
658 * channels by recreating them on split servers.
659 * Don't kick if the source has sent EOB (services
660 * deopping everyone by TS-1 SJOIN).
662 if (ConfigChannel
.kick_on_split_riding
&&
663 !HasSentEob(source_p
) &&
664 ((mode
.mode
& MODE_INVITEONLY
) ||
665 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
667 struct membership
*msptr
;
669 int l
= rb_dlink_list_length(&chptr
->members
);
671 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
674 who
= msptr
->client_p
;
675 sendto_one(who
, ":%s KICK %s %s :Net Rider",
676 me
.name
, chptr
->chname
, who
->name
);
678 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
679 ":%s KICK %s %s :Net Rider",
680 me
.id
, chptr
->chname
,
682 remove_user_from_channel(msptr
);
688 /* Channel was emptied, create a new one */
689 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
690 return 0; /* oops! */
692 oldmode
= &chptr
->mode
;
696 chptr
->channelts
= newts
;
703 else if(keep_our_modes
)
705 mode
.mode
|= oldmode
->mode
;
706 if(oldmode
->limit
> mode
.limit
)
707 mode
.limit
= oldmode
->limit
;
708 if(strcmp(mode
.key
, oldmode
->key
) < 0)
709 strcpy(mode
.key
, oldmode
->key
);
710 if(oldmode
->join_num
> mode
.join_num
||
711 (oldmode
->join_num
== mode
.join_num
&&
712 oldmode
->join_time
> mode
.join_time
))
714 mode
.join_num
= oldmode
->join_num
;
715 mode
.join_time
= oldmode
->join_time
;
717 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
718 strcpy(mode
.forward
, oldmode
->forward
);
722 /* If setting -j, clear join throttle state -- jilles */
724 chptr
->join_count
= chptr
->join_delta
= 0;
727 set_final_mode(&mode
, oldmode
);
730 /* Lost the TS, other side wins, so remove modes on this side */
733 remove_our_modes(chptr
, fakesource_p
);
734 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
736 del_invite(chptr
, ptr
->data
);
739 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
740 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
741 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
742 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
744 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
745 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
747 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
748 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
752 sendto_channel_local(ALL_MEMBERS
, chptr
,
753 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
754 me
.name
, chptr
->chname
, chptr
->chname
,
755 (long) oldts
, (long) newts
);
756 /* Update capitalization in channel name, this makes the
757 * capitalization timestamped like modes are -- jilles */
758 strcpy(chptr
->chname
, parv
[2]);
762 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
763 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
765 *modebuf
= *parabuf
= '\0';
767 if(parv
[3][0] != '0' && keep_new_modes
)
768 modes
= channel_modes(chptr
, source_p
);
772 /* working on the presumption eventually itll be more efficient to
773 * build a TS6 buffer without checking its needed..
775 mlen_uid
= rb_sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
776 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
777 ptr_uid
= buf_uid
+ mlen_uid
;
780 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
782 len_nick
= len_uid
= 0;
784 /* if theres a space, theres going to be more than one nick, change the
785 * first space to \0, so s is just the first nick, and point p to the
788 if((p
= strchr(s
, ' ')) != NULL
)
799 for (i
= 0; i
< 2; i
++)
813 /* if the client doesnt exist or is fake direction, skip. */
814 if(!(target_p
= find_client(s
)) ||
815 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
818 /* we assume for these we can fit at least one nick/uid in.. */
820 /* check we can fit another status+nick+space into a buffer */
821 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
823 *(ptr_uid
- 1) = '\0';
824 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
825 ptr_uid
= buf_uid
+ mlen_uid
;
845 /* copy the nick to the two buffers */
846 len
= rb_sprintf(ptr_uid
, "%s ", use_id(target_p
));
853 if(!IsMember(target_p
, chptr
))
855 add_user_to_channel(chptr
, target_p
, fl
);
856 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
858 target_p
->username
, target_p
->host
, parv
[2]);
865 para
[pargs
++] = target_p
->name
;
867 /* a +ov user.. bleh */
870 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
873 if(pargs
>= MAXMODEPARAMS
)
876 sendto_channel_local(ALL_MEMBERS
, chptr
,
877 ":%s MODE %s %s %s %s %s %s",
878 fakesource_p
->name
, chptr
->chname
,
880 para
[0], para
[1], para
[2], para
[3]);
883 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
888 para
[pargs
++] = target_p
->name
;
891 else if(fl
& CHFL_VOICE
)
894 para
[pargs
++] = target_p
->name
;
897 if(pargs
>= MAXMODEPARAMS
)
900 sendto_channel_local(ALL_MEMBERS
, chptr
,
901 ":%s MODE %s %s %s %s %s %s",
904 modebuf
, para
[0], para
[1], para
[2], para
[3]);
907 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
912 /* p points to the next nick */
915 /* if there was a trailing space and p was pointing to it, then we
916 * need to exit.. this has the side effect of breaking double spaces
917 * in an sjoin.. but that shouldnt happen anyway
919 if(s
&& (*s
== '\0'))
922 /* if p was NULL due to no spaces, s wont exist due to the above, so
923 * we cant check it for spaces.. if there are no spaces, then when
924 * we next get here, s will be NULL
926 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
935 sendto_channel_local(ALL_MEMBERS
, chptr
,
936 ":%s MODE %s %s %s %s %s %s",
937 fakesource_p
->name
, chptr
->chname
, modebuf
,
938 para
[0], CheckEmpty(para
[1]),
939 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
942 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
944 destroy_channel(chptr
);
949 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
952 *(ptr_uid
- 1) = '\0';
955 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
963 * inputs - pointer to client doing join 0
965 * side effects - Use has decided to join 0. This is legacy
966 * from the days when channels were numbers not names. *sigh*
967 * There is a bunch of evilness necessary here due to
971 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
973 struct membership
*msptr
;
974 struct Channel
*chptr
= NULL
;
977 /* Finish the flood grace period... */
978 if(MyClient(source_p
) && !IsFloodDone(source_p
))
979 flood_endgrace(source_p
);
981 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
983 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
984 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
985 check_spambot_warning(source_p
, NULL
);
987 while((ptr
= source_p
->user
->channel
.head
))
990 chptr
= msptr
->chptr
;
991 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
993 source_p
->username
, source_p
->host
, chptr
->chname
);
994 remove_user_from_channel(msptr
);
999 check_channel_name_loc(struct Client
*source_p
, const char *name
)
1001 s_assert(name
!= NULL
);
1002 if(EmptyString(name
))
1005 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1007 for(; *name
; ++name
)
1009 if(!IsChanChar(*name
) || IsFakeChanChar(*name
))
1015 for(; *name
; ++name
)
1017 if(!IsChanChar(*name
))
1026 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1028 int dir
= MODE_QUERY
;
1029 char *pbuf
= parabuf
;
1033 /* ok, first get a list of modes we need to add */
1034 for (i
= 0; i
< 256; i
++)
1036 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1047 /* now the ones we need to remove. */
1048 for (i
= 0; i
< 256; i
++)
1050 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1061 if(oldmode
->limit
&& !mode
->limit
)
1070 if(oldmode
->key
[0] && !mode
->key
[0])
1078 len
= rb_sprintf(pbuf
, "%s ", oldmode
->key
);
1081 if(oldmode
->join_num
&& !mode
->join_num
)
1090 if(oldmode
->forward
[0] && !mode
->forward
[0])
1099 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1107 len
= rb_sprintf(pbuf
, "%d ", mode
->limit
);
1110 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1118 len
= rb_sprintf(pbuf
, "%s ", mode
->key
);
1121 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1129 len
= rb_sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1132 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) && ConfigChannel
.use_forward
)
1140 len
= rb_sprintf(pbuf
, "%s ", mode
->forward
);
1154 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1156 struct membership
*msptr
;
1158 char lmodebuf
[MODEBUFLEN
];
1159 char *lpara
[MAXMODEPARAMS
];
1166 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1169 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1173 if(is_chanop(msptr
))
1175 msptr
->flags
&= ~CHFL_CHANOP
;
1176 lpara
[count
++] = msptr
->client_p
->name
;
1179 /* +ov, might not fit so check. */
1180 if(is_voiced(msptr
))
1182 if(count
>= MAXMODEPARAMS
)
1185 sendto_channel_local(ALL_MEMBERS
, chptr
,
1186 ":%s MODE %s %s %s %s %s %s",
1187 source_p
->name
, chptr
->chname
,
1188 lmodebuf
, lpara
[0], lpara
[1],
1189 lpara
[2], lpara
[3]);
1191 /* preserve the initial '-' */
1196 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1200 msptr
->flags
&= ~CHFL_VOICE
;
1201 lpara
[count
++] = msptr
->client_p
->name
;
1205 else if(is_voiced(msptr
))
1207 msptr
->flags
&= ~CHFL_VOICE
;
1208 lpara
[count
++] = msptr
->client_p
->name
;
1214 if(count
>= MAXMODEPARAMS
)
1217 sendto_channel_local(ALL_MEMBERS
, chptr
,
1218 ":%s MODE %s %s %s %s %s %s",
1219 source_p
->name
, chptr
->chname
, lmodebuf
,
1220 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1225 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1233 sendto_channel_local(ALL_MEMBERS
, chptr
,
1234 ":%s MODE %s %s %s %s %s %s",
1235 source_p
->name
, chptr
->chname
, lmodebuf
,
1236 EmptyString(lpara
[0]) ? "" : lpara
[0],
1237 EmptyString(lpara
[1]) ? "" : lpara
[1],
1238 EmptyString(lpara
[2]) ? "" : lpara
[2],
1239 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1244 /* remove_ban_list()
1246 * inputs - channel, source, list to remove, char of mode, caps needed
1248 * side effects - given list is removed, with modes issued to local clients
1251 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1252 rb_dlink_list
* list
, char c
, int mems
)
1254 static char lmodebuf
[BUFSIZE
];
1255 static char lparabuf
[BUFSIZE
];
1258 rb_dlink_node
*next_ptr
;
1261 int cur_len
, mlen
, plen
;
1265 cur_len
= mlen
= rb_sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1266 mbuf
= lmodebuf
+ mlen
;
1268 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1272 /* trailing space, and the mode letter itself */
1273 plen
= strlen(banptr
->banstr
) + 2;
1275 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1277 /* remove trailing space */
1281 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1284 mbuf
= lmodebuf
+ mlen
;
1291 pbuf
+= rb_sprintf(pbuf
, "%s ", banptr
->banstr
);
1299 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1301 list
->head
= list
->tail
= NULL
;