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
);
391 * parv[0] = sender prefix
392 * parv[1] = channel TS
394 * parv[3] = "+", formerly channel modes but now unused
395 * alternatively, a single "0" parameter parts all channels
398 ms_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
400 struct Channel
*chptr
;
401 static struct Mode mode
;
405 int keep_our_modes
= YES
;
406 int keep_new_modes
= YES
;
407 rb_dlink_node
*ptr
, *next_ptr
;
409 /* special case for join 0 */
410 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
412 do_join_0(client_p
, source_p
);
419 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
422 /* joins for local channels cant happen. */
423 if(parv
[2][0] == '&')
427 mode
.key
[0] = mode
.forward
[0] = '\0';
428 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
430 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
433 newts
= atol(parv
[1]);
434 oldts
= chptr
->channelts
;
436 #ifdef IGNORE_BOGUS_TS
437 if(newts
< 800000000)
439 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
440 "*** Bogus TS %ld on %s ignored from %s",
441 (long) newts
, chptr
->chname
, client_p
->name
);
442 newts
= (oldts
== 0) ? oldts
: 800000000;
445 /* making a channel TS0 */
446 if(!isnew
&& !newts
&& oldts
)
448 sendto_channel_local(ALL_MEMBERS
, chptr
,
449 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
450 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
451 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
452 "Server %s changing TS on %s from %ld to 0",
453 source_p
->name
, chptr
->chname
, (long) oldts
);
458 chptr
->channelts
= newts
;
459 else if(newts
== 0 || oldts
== 0)
460 chptr
->channelts
= 0;
461 else if(newts
== oldts
)
463 else if(newts
< oldts
)
466 chptr
->channelts
= newts
;
471 /* Lost the TS, other side wins, so remove modes on this side */
474 set_final_mode(&mode
, &chptr
->mode
);
476 remove_our_modes(chptr
, source_p
);
477 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
479 del_invite(chptr
, ptr
->data
);
481 /* If setting -j, clear join throttle state -- jilles */
482 chptr
->join_count
= chptr
->join_delta
= 0;
483 sendto_channel_local(ALL_MEMBERS
, chptr
,
484 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
485 me
.name
, chptr
->chname
, chptr
->chname
,
486 (long) oldts
, (long) newts
);
487 /* Update capitalization in channel name, this makes the
488 * capitalization timestamped like modes are -- jilles */
489 strcpy(chptr
->chname
, parv
[2]);
491 sendto_channel_local(ALL_MEMBERS
, chptr
,
493 source_p
->servptr
->name
,
494 chptr
->chname
, modebuf
, parabuf
);
495 *modebuf
= *parabuf
= '\0';
498 if(!IsMember(source_p
, chptr
))
500 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
501 if (chptr
->mode
.join_num
&&
502 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
504 chptr
->join_count
= 0;
505 chptr
->join_delta
= rb_current_time();
508 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
509 source_p
->name
, source_p
->username
,
510 source_p
->host
, chptr
->chname
);
513 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
515 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
520 ms_sjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
522 static char buf_uid
[BUFSIZE
];
523 static const char empty_modes
[] = "0";
524 struct Channel
*chptr
;
525 struct Client
*target_p
, *fakesource_p
;
528 static struct Mode mode
, *oldmode
;
531 int keep_our_modes
= 1;
532 int keep_new_modes
= 1;
543 int i
, joinc
= 0, timeslice
= 0;
544 static char empty
[] = "";
545 rb_dlink_node
*ptr
, *next_ptr
;
547 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
550 /* SJOIN's for local channels can't happen. */
554 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
555 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
557 /* Hide connecting server on netburst -- jilles */
558 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
561 fakesource_p
= source_p
;
564 newts
= atol(parv
[1]);
572 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
578 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
580 mode
.join_num
= joinc
;
581 mode
.join_time
= timeslice
;
586 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
592 mode
.limit
= atoi(parv
[4 + args
]);
598 if(chmode_flags
[(int) *s
] != 0)
600 mode
.mode
|= chmode_flags
[(int) *s
];
609 /* remove any leading spaces */
616 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
617 return 0; /* channel name too long? */
620 oldts
= chptr
->channelts
;
621 oldmode
= &chptr
->mode
;
623 #ifdef IGNORE_BOGUS_TS
624 if(newts
< 800000000)
626 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
627 "*** Bogus TS %ld on %s ignored from %s",
628 (long) newts
, chptr
->chname
, client_p
->name
);
630 newts
= (oldts
== 0) ? oldts
: 800000000;
633 if(!isnew
&& !newts
&& oldts
)
635 sendto_channel_local(ALL_MEMBERS
, chptr
,
636 ":%s NOTICE %s :*** Notice -- TS for %s "
637 "changed from %ld to 0",
638 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
639 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
640 "Server %s changing TS on %s from %ld to 0",
641 source_p
->name
, chptr
->chname
, (long) oldts
);
646 chptr
->channelts
= newts
;
648 else if(newts
== 0 || oldts
== 0)
649 chptr
->channelts
= 0;
650 else if(newts
== oldts
)
652 else if(newts
< oldts
)
654 /* If configured, kick people trying to join +i/+k
655 * channels by recreating them on split servers.
656 * Don't kick if the source has sent EOB (services
657 * deopping everyone by TS-1 SJOIN).
659 if (ConfigChannel
.kick_on_split_riding
&&
660 !HasSentEob(source_p
) &&
661 ((mode
.mode
& MODE_INVITEONLY
) ||
662 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
664 struct membership
*msptr
;
666 int l
= rb_dlink_list_length(&chptr
->members
);
668 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
671 who
= msptr
->client_p
;
672 sendto_one(who
, ":%s KICK %s %s :Net Rider",
673 me
.name
, chptr
->chname
, who
->name
);
675 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
676 ":%s KICK %s %s :Net Rider",
677 me
.id
, chptr
->chname
,
679 remove_user_from_channel(msptr
);
685 /* Channel was emptied, create a new one */
686 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
687 return 0; /* oops! */
689 oldmode
= &chptr
->mode
;
693 chptr
->channelts
= newts
;
700 else if(keep_our_modes
)
702 mode
.mode
|= oldmode
->mode
;
703 if(oldmode
->limit
> mode
.limit
)
704 mode
.limit
= oldmode
->limit
;
705 if(strcmp(mode
.key
, oldmode
->key
) < 0)
706 strcpy(mode
.key
, oldmode
->key
);
707 if(oldmode
->join_num
> mode
.join_num
||
708 (oldmode
->join_num
== mode
.join_num
&&
709 oldmode
->join_time
> mode
.join_time
))
711 mode
.join_num
= oldmode
->join_num
;
712 mode
.join_time
= oldmode
->join_time
;
714 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
715 strcpy(mode
.forward
, oldmode
->forward
);
719 /* If setting -j, clear join throttle state -- jilles */
721 chptr
->join_count
= chptr
->join_delta
= 0;
724 set_final_mode(&mode
, oldmode
);
727 /* Lost the TS, other side wins, so remove modes on this side */
730 remove_our_modes(chptr
, fakesource_p
);
731 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
733 del_invite(chptr
, ptr
->data
);
736 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
737 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
738 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
739 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
741 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
742 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
744 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
745 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
749 sendto_channel_local(ALL_MEMBERS
, chptr
,
750 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
751 me
.name
, chptr
->chname
, chptr
->chname
,
752 (long) oldts
, (long) newts
);
753 /* Update capitalization in channel name, this makes the
754 * capitalization timestamped like modes are -- jilles */
755 strcpy(chptr
->chname
, parv
[2]);
759 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
760 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
762 *modebuf
= *parabuf
= '\0';
764 if(parv
[3][0] != '0' && keep_new_modes
)
765 modes
= channel_modes(chptr
, source_p
);
769 /* working on the presumption eventually itll be more efficient to
770 * build a TS6 buffer without checking its needed..
772 mlen_uid
= rb_sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
773 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
774 ptr_uid
= buf_uid
+ mlen_uid
;
777 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
779 len_nick
= len_uid
= 0;
781 /* if theres a space, theres going to be more than one nick, change the
782 * first space to \0, so s is just the first nick, and point p to the
785 if((p
= strchr(s
, ' ')) != NULL
)
796 for (i
= 0; i
< 2; i
++)
810 /* if the client doesnt exist or is fake direction, skip. */
811 if(!(target_p
= find_client(s
)) ||
812 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
815 /* we assume for these we can fit at least one nick/uid in.. */
817 /* check we can fit another status+nick+space into a buffer */
818 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
820 *(ptr_uid
- 1) = '\0';
821 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
822 ptr_uid
= buf_uid
+ mlen_uid
;
842 /* copy the nick to the two buffers */
843 len
= rb_sprintf(ptr_uid
, "%s ", use_id(target_p
));
850 if(!IsMember(target_p
, chptr
))
852 add_user_to_channel(chptr
, target_p
, fl
);
853 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
855 target_p
->username
, target_p
->host
, parv
[2]);
862 para
[pargs
++] = target_p
->name
;
864 /* a +ov user.. bleh */
867 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
870 if(pargs
>= MAXMODEPARAMS
)
873 sendto_channel_local(ALL_MEMBERS
, chptr
,
874 ":%s MODE %s %s %s %s %s %s",
875 fakesource_p
->name
, chptr
->chname
,
877 para
[0], para
[1], para
[2], para
[3]);
880 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
885 para
[pargs
++] = target_p
->name
;
888 else if(fl
& CHFL_VOICE
)
891 para
[pargs
++] = target_p
->name
;
894 if(pargs
>= MAXMODEPARAMS
)
897 sendto_channel_local(ALL_MEMBERS
, chptr
,
898 ":%s MODE %s %s %s %s %s %s",
901 modebuf
, para
[0], para
[1], para
[2], para
[3]);
904 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
909 /* p points to the next nick */
912 /* if there was a trailing space and p was pointing to it, then we
913 * need to exit.. this has the side effect of breaking double spaces
914 * in an sjoin.. but that shouldnt happen anyway
916 if(s
&& (*s
== '\0'))
919 /* if p was NULL due to no spaces, s wont exist due to the above, so
920 * we cant check it for spaces.. if there are no spaces, then when
921 * we next get here, s will be NULL
923 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
932 sendto_channel_local(ALL_MEMBERS
, chptr
,
933 ":%s MODE %s %s %s %s %s %s",
934 fakesource_p
->name
, chptr
->chname
, modebuf
,
935 para
[0], CheckEmpty(para
[1]),
936 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
939 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
941 destroy_channel(chptr
);
946 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
949 *(ptr_uid
- 1) = '\0';
952 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
960 * inputs - pointer to client doing join 0
962 * side effects - Use has decided to join 0. This is legacy
963 * from the days when channels were numbers not names. *sigh*
964 * There is a bunch of evilness necessary here due to
968 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
970 struct membership
*msptr
;
971 struct Channel
*chptr
= NULL
;
974 /* Finish the flood grace period... */
975 if(MyClient(source_p
) && !IsFloodDone(source_p
))
976 flood_endgrace(source_p
);
978 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
980 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
981 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
982 check_spambot_warning(source_p
, NULL
);
984 while((ptr
= source_p
->user
->channel
.head
))
987 chptr
= msptr
->chptr
;
988 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
990 source_p
->username
, source_p
->host
, chptr
->chname
);
991 remove_user_from_channel(msptr
);
996 check_channel_name_loc(struct Client
*source_p
, const char *name
)
998 s_assert(name
!= NULL
);
999 if(EmptyString(name
))
1002 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1004 for(; *name
; ++name
)
1006 if(!IsChanChar(*name
) || IsFakeChanChar(*name
))
1012 for(; *name
; ++name
)
1014 if(!IsChanChar(*name
))
1023 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1025 int dir
= MODE_QUERY
;
1026 char *pbuf
= parabuf
;
1030 /* ok, first get a list of modes we need to add */
1031 for (i
= 0; i
< 256; i
++)
1033 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1044 /* now the ones we need to remove. */
1045 for (i
= 0; i
< 256; i
++)
1047 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1058 if(oldmode
->limit
&& !mode
->limit
)
1067 if(oldmode
->key
[0] && !mode
->key
[0])
1075 len
= rb_sprintf(pbuf
, "%s ", oldmode
->key
);
1078 if(oldmode
->join_num
&& !mode
->join_num
)
1087 if(oldmode
->forward
[0] && !mode
->forward
[0])
1096 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1104 len
= rb_sprintf(pbuf
, "%d ", mode
->limit
);
1107 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1115 len
= rb_sprintf(pbuf
, "%s ", mode
->key
);
1118 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1126 len
= rb_sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1129 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) && ConfigChannel
.use_forward
)
1137 len
= rb_sprintf(pbuf
, "%s ", mode
->forward
);
1151 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1153 struct membership
*msptr
;
1155 char lmodebuf
[MODEBUFLEN
];
1156 char *lpara
[MAXMODEPARAMS
];
1163 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1166 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1170 if(is_chanop(msptr
))
1172 msptr
->flags
&= ~CHFL_CHANOP
;
1173 lpara
[count
++] = msptr
->client_p
->name
;
1176 /* +ov, might not fit so check. */
1177 if(is_voiced(msptr
))
1179 if(count
>= MAXMODEPARAMS
)
1182 sendto_channel_local(ALL_MEMBERS
, chptr
,
1183 ":%s MODE %s %s %s %s %s %s",
1184 source_p
->name
, chptr
->chname
,
1185 lmodebuf
, lpara
[0], lpara
[1],
1186 lpara
[2], lpara
[3]);
1188 /* preserve the initial '-' */
1193 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1197 msptr
->flags
&= ~CHFL_VOICE
;
1198 lpara
[count
++] = msptr
->client_p
->name
;
1202 else if(is_voiced(msptr
))
1204 msptr
->flags
&= ~CHFL_VOICE
;
1205 lpara
[count
++] = msptr
->client_p
->name
;
1211 if(count
>= MAXMODEPARAMS
)
1214 sendto_channel_local(ALL_MEMBERS
, chptr
,
1215 ":%s MODE %s %s %s %s %s %s",
1216 source_p
->name
, chptr
->chname
, lmodebuf
,
1217 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1222 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1230 sendto_channel_local(ALL_MEMBERS
, chptr
,
1231 ":%s MODE %s %s %s %s %s %s",
1232 source_p
->name
, chptr
->chname
, lmodebuf
,
1233 EmptyString(lpara
[0]) ? "" : lpara
[0],
1234 EmptyString(lpara
[1]) ? "" : lpara
[1],
1235 EmptyString(lpara
[2]) ? "" : lpara
[2],
1236 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1241 /* remove_ban_list()
1243 * inputs - channel, source, list to remove, char of mode, caps needed
1245 * side effects - given list is removed, with modes issued to local clients
1248 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1249 rb_dlink_list
* list
, char c
, int mems
)
1251 static char lmodebuf
[BUFSIZE
];
1252 static char lparabuf
[BUFSIZE
];
1255 rb_dlink_node
*next_ptr
;
1258 int cur_len
, mlen
, plen
;
1262 cur_len
= mlen
= rb_sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1263 mbuf
= lmodebuf
+ mlen
;
1265 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1269 /* trailing space, and the mode letter itself */
1270 plen
= strlen(banptr
->banstr
) + 2;
1272 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1274 /* remove trailing space */
1278 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1281 mbuf
= lmodebuf
+ mlen
;
1288 pbuf
+= rb_sprintf(pbuf
, "%s ", banptr
->banstr
);
1296 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1298 list
->head
= list
->tail
= NULL
;