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
)
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
;
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
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
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) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
213 mykey
= LOCAL_COPY(parv
[2]);
214 key
= rb_strtok_r(mykey
, ",", &p2
);
217 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
218 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
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 /* might be wrong, but is there any other better location for such?
307 * see extensions/chm_operonly.c for other comments on this
311 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
313 if(successful_join_count
> 0)
314 successful_join_count
--;
318 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr
->chname
);
321 /* add the user to the channel */
322 add_user_to_channel(chptr
, source_p
, flags
);
323 if (chptr
->mode
.join_num
&&
324 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
326 chptr
->join_count
= 0;
327 chptr
->join_delta
= rb_current_time();
331 /* we send the user their join here, because we could have to
332 * send a mode out next.
334 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
336 source_p
->username
, source_p
->host
, chptr
->chname
);
338 /* its a new channel, set +nt and burst. */
339 if(flags
& CHFL_CHANOP
)
341 chptr
->channelts
= rb_current_time();
342 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
343 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
344 modes
= channel_modes(chptr
, &me
);
346 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
347 me
.name
, chptr
->chname
, modes
);
349 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
350 ":%s SJOIN %ld %s %s :@%s",
351 me
.id
, (long) chptr
->channelts
,
352 chptr
->chname
, modes
, source_p
->id
);
356 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
358 use_id(source_p
), (long) chptr
->channelts
,
362 del_invite(chptr
, source_p
);
364 if(chptr
->topic
!= NULL
)
366 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
367 source_p
->name
, chptr
->chname
, chptr
->topic
);
369 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
370 me
.name
, source_p
->name
, chptr
->chname
,
371 chptr
->topic_info
, chptr
->topic_time
);
374 channel_member_names(chptr
, source_p
, 1);
376 if(successful_join_count
)
377 source_p
->localClient
->last_join_time
= rb_current_time();
379 hook_info
.client
= source_p
;
380 hook_info
.chptr
= chptr
;
382 call_hook(h_channel_join
, &hook_info
);
390 * parv[1] = channel TS
392 * parv[3] = "+", formerly channel modes but now unused
393 * alternatively, a single "0" parameter parts all channels
396 ms_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
398 struct Channel
*chptr
;
399 static struct Mode mode
;
403 int keep_our_modes
= YES
;
404 int keep_new_modes
= YES
;
405 rb_dlink_node
*ptr
, *next_ptr
;
407 /* special case for join 0 */
408 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
410 do_join_0(client_p
, source_p
);
417 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
420 /* joins for local channels cant happen. */
421 if(parv
[2][0] == '&')
425 mode
.key
[0] = mode
.forward
[0] = '\0';
426 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
428 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
431 newts
= atol(parv
[1]);
432 oldts
= chptr
->channelts
;
434 #ifdef IGNORE_BOGUS_TS
435 if(newts
< 800000000)
437 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
438 "*** Bogus TS %ld on %s ignored from %s",
439 (long) newts
, chptr
->chname
, client_p
->name
);
440 newts
= (oldts
== 0) ? oldts
: 800000000;
443 /* making a channel TS0 */
444 if(!isnew
&& !newts
&& oldts
)
446 sendto_channel_local(ALL_MEMBERS
, chptr
,
447 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
448 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
449 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
450 "Server %s changing TS on %s from %ld to 0",
451 source_p
->name
, chptr
->chname
, (long) oldts
);
456 chptr
->channelts
= newts
;
457 else if(newts
== 0 || oldts
== 0)
458 chptr
->channelts
= 0;
459 else if(newts
== oldts
)
461 else if(newts
< oldts
)
464 chptr
->channelts
= newts
;
469 /* Lost the TS, other side wins, so remove modes on this side */
472 set_final_mode(&mode
, &chptr
->mode
);
474 remove_our_modes(chptr
, source_p
);
475 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
477 del_invite(chptr
, ptr
->data
);
479 /* If setting -j, clear join throttle state -- jilles */
480 chptr
->join_count
= chptr
->join_delta
= 0;
481 sendto_channel_local(ALL_MEMBERS
, chptr
,
482 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
483 me
.name
, chptr
->chname
, chptr
->chname
,
484 (long) oldts
, (long) newts
);
485 /* Update capitalization in channel name, this makes the
486 * capitalization timestamped like modes are -- jilles */
487 strcpy(chptr
->chname
, parv
[2]);
489 sendto_channel_local(ALL_MEMBERS
, chptr
,
491 source_p
->servptr
->name
,
492 chptr
->chname
, modebuf
, parabuf
);
493 *modebuf
= *parabuf
= '\0';
496 if(!IsMember(source_p
, chptr
))
498 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
499 if (chptr
->mode
.join_num
&&
500 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
502 chptr
->join_count
= 0;
503 chptr
->join_delta
= rb_current_time();
506 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
507 source_p
->name
, source_p
->username
,
508 source_p
->host
, chptr
->chname
);
511 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
513 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
518 ms_sjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
520 static char buf_uid
[BUFSIZE
];
521 static const char empty_modes
[] = "0";
522 struct Channel
*chptr
;
523 struct Client
*target_p
, *fakesource_p
;
526 static struct Mode mode
, *oldmode
;
529 int keep_our_modes
= 1;
530 int keep_new_modes
= 1;
541 int i
, joinc
= 0, timeslice
= 0;
542 static char empty
[] = "";
543 rb_dlink_node
*ptr
, *next_ptr
;
545 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
548 /* SJOIN's for local channels can't happen. */
552 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
553 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
555 /* Hide connecting server on netburst -- jilles */
556 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
559 fakesource_p
= source_p
;
562 newts
= atol(parv
[1]);
570 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
576 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
578 mode
.join_num
= joinc
;
579 mode
.join_time
= timeslice
;
584 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
590 mode
.limit
= atoi(parv
[4 + args
]);
596 if(chmode_flags
[(int) *s
] != 0)
598 mode
.mode
|= chmode_flags
[(int) *s
];
607 /* remove any leading spaces */
614 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
615 return 0; /* channel name too long? */
618 oldts
= chptr
->channelts
;
619 oldmode
= &chptr
->mode
;
621 #ifdef IGNORE_BOGUS_TS
622 if(newts
< 800000000)
624 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
625 "*** Bogus TS %ld on %s ignored from %s",
626 (long) newts
, chptr
->chname
, client_p
->name
);
628 newts
= (oldts
== 0) ? oldts
: 800000000;
631 if(!isnew
&& !newts
&& oldts
)
633 sendto_channel_local(ALL_MEMBERS
, chptr
,
634 ":%s NOTICE %s :*** Notice -- TS for %s "
635 "changed from %ld to 0",
636 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
637 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
638 "Server %s changing TS on %s from %ld to 0",
639 source_p
->name
, chptr
->chname
, (long) oldts
);
644 chptr
->channelts
= newts
;
646 else if(newts
== 0 || oldts
== 0)
647 chptr
->channelts
= 0;
648 else if(newts
== oldts
)
650 else if(newts
< oldts
)
652 /* If configured, kick people trying to join +i/+k
653 * channels by recreating them on split servers.
654 * Don't kick if the source has sent EOB (services
655 * deopping everyone by TS-1 SJOIN).
657 if (ConfigChannel
.kick_on_split_riding
&&
658 !HasSentEob(source_p
) &&
659 ((mode
.mode
& MODE_INVITEONLY
) ||
660 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
662 struct membership
*msptr
;
664 int l
= rb_dlink_list_length(&chptr
->members
);
666 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
669 who
= msptr
->client_p
;
670 sendto_one(who
, ":%s KICK %s %s :Net Rider",
671 me
.name
, chptr
->chname
, who
->name
);
673 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
674 ":%s KICK %s %s :Net Rider",
675 me
.id
, chptr
->chname
,
677 remove_user_from_channel(msptr
);
683 /* Channel was emptied, create a new one */
684 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
685 return 0; /* oops! */
687 oldmode
= &chptr
->mode
;
691 chptr
->channelts
= newts
;
698 else if(keep_our_modes
)
700 mode
.mode
|= oldmode
->mode
;
701 if(oldmode
->limit
> mode
.limit
)
702 mode
.limit
= oldmode
->limit
;
703 if(strcmp(mode
.key
, oldmode
->key
) < 0)
704 strcpy(mode
.key
, oldmode
->key
);
705 if(oldmode
->join_num
> mode
.join_num
||
706 (oldmode
->join_num
== mode
.join_num
&&
707 oldmode
->join_time
> mode
.join_time
))
709 mode
.join_num
= oldmode
->join_num
;
710 mode
.join_time
= oldmode
->join_time
;
712 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
713 strcpy(mode
.forward
, oldmode
->forward
);
717 /* If setting -j, clear join throttle state -- jilles */
719 chptr
->join_count
= chptr
->join_delta
= 0;
722 set_final_mode(&mode
, oldmode
);
725 /* Lost the TS, other side wins, so remove modes on this side */
728 remove_our_modes(chptr
, fakesource_p
);
729 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
731 del_invite(chptr
, ptr
->data
);
734 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
735 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
736 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
737 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
739 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
740 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
742 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
743 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
747 sendto_channel_local(ALL_MEMBERS
, chptr
,
748 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
749 me
.name
, chptr
->chname
, chptr
->chname
,
750 (long) oldts
, (long) newts
);
751 /* Update capitalization in channel name, this makes the
752 * capitalization timestamped like modes are -- jilles */
753 strcpy(chptr
->chname
, parv
[2]);
757 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
758 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
760 *modebuf
= *parabuf
= '\0';
762 if(parv
[3][0] != '0' && keep_new_modes
)
763 modes
= channel_modes(chptr
, source_p
);
767 mlen_uid
= rb_sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
768 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
769 ptr_uid
= buf_uid
+ mlen_uid
;
772 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
774 len_nick
= len_uid
= 0;
776 /* if theres a space, theres going to be more than one nick, change the
777 * first space to \0, so s is just the first nick, and point p to the
780 if((p
= strchr(s
, ' ')) != NULL
)
791 for (i
= 0; i
< 2; i
++)
805 /* if the client doesnt exist or is fake direction, skip. */
806 if(!(target_p
= find_client(s
)) ||
807 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
810 /* we assume for these we can fit at least one nick/uid in.. */
812 /* check we can fit another status+nick+space into a buffer */
813 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
815 *(ptr_uid
- 1) = '\0';
816 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
817 ptr_uid
= buf_uid
+ mlen_uid
;
837 /* copy the nick to the two buffers */
838 len
= rb_sprintf(ptr_uid
, "%s ", use_id(target_p
));
845 if(!IsMember(target_p
, chptr
))
847 add_user_to_channel(chptr
, target_p
, fl
);
848 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
850 target_p
->username
, target_p
->host
, parv
[2]);
857 para
[pargs
++] = target_p
->name
;
859 /* a +ov user.. bleh */
862 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
865 if(pargs
>= MAXMODEPARAMS
)
868 sendto_channel_local(ALL_MEMBERS
, chptr
,
869 ":%s MODE %s %s %s %s %s %s",
870 fakesource_p
->name
, chptr
->chname
,
872 para
[0], para
[1], para
[2], para
[3]);
875 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
880 para
[pargs
++] = target_p
->name
;
883 else if(fl
& CHFL_VOICE
)
886 para
[pargs
++] = target_p
->name
;
889 if(pargs
>= MAXMODEPARAMS
)
892 sendto_channel_local(ALL_MEMBERS
, chptr
,
893 ":%s MODE %s %s %s %s %s %s",
896 modebuf
, para
[0], para
[1], para
[2], para
[3]);
899 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
904 /* p points to the next nick */
907 /* if there was a trailing space and p was pointing to it, then we
908 * need to exit.. this has the side effect of breaking double spaces
909 * in an sjoin.. but that shouldnt happen anyway
911 if(s
&& (*s
== '\0'))
914 /* if p was NULL due to no spaces, s wont exist due to the above, so
915 * we cant check it for spaces.. if there are no spaces, then when
916 * we next get here, s will be NULL
918 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
927 sendto_channel_local(ALL_MEMBERS
, chptr
,
928 ":%s MODE %s %s %s %s %s %s",
929 fakesource_p
->name
, chptr
->chname
, modebuf
,
930 para
[0], CheckEmpty(para
[1]),
931 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
934 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
936 destroy_channel(chptr
);
941 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
944 *(ptr_uid
- 1) = '\0';
947 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
955 * inputs - pointer to client doing join 0
957 * side effects - Use has decided to join 0. This is legacy
958 * from the days when channels were numbers not names. *sigh*
959 * There is a bunch of evilness necessary here due to
963 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
965 struct membership
*msptr
;
966 struct Channel
*chptr
= NULL
;
969 /* Finish the flood grace period... */
970 if(MyClient(source_p
) && !IsFloodDone(source_p
))
971 flood_endgrace(source_p
);
973 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
975 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
976 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
977 check_spambot_warning(source_p
, NULL
);
979 while((ptr
= source_p
->user
->channel
.head
))
982 chptr
= msptr
->chptr
;
983 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
985 source_p
->username
, source_p
->host
, chptr
->chname
);
986 remove_user_from_channel(msptr
);
991 check_channel_name_loc(struct Client
*source_p
, const char *name
)
993 s_assert(name
!= NULL
);
994 if(EmptyString(name
))
997 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1001 if(!IsChanChar(*name
) || IsFakeChanChar(*name
))
1007 for(; *name
; ++name
)
1009 if(!IsChanChar(*name
))
1018 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1020 int dir
= MODE_QUERY
;
1021 char *pbuf
= parabuf
;
1025 /* ok, first get a list of modes we need to add */
1026 for (i
= 0; i
< 256; i
++)
1028 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1039 /* now the ones we need to remove. */
1040 for (i
= 0; i
< 256; i
++)
1042 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1053 if(oldmode
->limit
&& !mode
->limit
)
1062 if(oldmode
->key
[0] && !mode
->key
[0])
1070 len
= rb_sprintf(pbuf
, "%s ", oldmode
->key
);
1073 if(oldmode
->join_num
&& !mode
->join_num
)
1082 if(oldmode
->forward
[0] && !mode
->forward
[0])
1091 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1099 len
= rb_sprintf(pbuf
, "%d ", mode
->limit
);
1102 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1110 len
= rb_sprintf(pbuf
, "%s ", mode
->key
);
1113 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1121 len
= rb_sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1124 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) && ConfigChannel
.use_forward
)
1132 len
= rb_sprintf(pbuf
, "%s ", mode
->forward
);
1146 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1148 struct membership
*msptr
;
1150 char lmodebuf
[MODEBUFLEN
];
1151 char *lpara
[MAXMODEPARAMS
];
1158 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1161 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1165 if(is_chanop(msptr
))
1167 msptr
->flags
&= ~CHFL_CHANOP
;
1168 lpara
[count
++] = msptr
->client_p
->name
;
1171 /* +ov, might not fit so check. */
1172 if(is_voiced(msptr
))
1174 if(count
>= MAXMODEPARAMS
)
1177 sendto_channel_local(ALL_MEMBERS
, chptr
,
1178 ":%s MODE %s %s %s %s %s %s",
1179 source_p
->name
, chptr
->chname
,
1180 lmodebuf
, lpara
[0], lpara
[1],
1181 lpara
[2], lpara
[3]);
1183 /* preserve the initial '-' */
1188 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1192 msptr
->flags
&= ~CHFL_VOICE
;
1193 lpara
[count
++] = msptr
->client_p
->name
;
1197 else if(is_voiced(msptr
))
1199 msptr
->flags
&= ~CHFL_VOICE
;
1200 lpara
[count
++] = msptr
->client_p
->name
;
1206 if(count
>= MAXMODEPARAMS
)
1209 sendto_channel_local(ALL_MEMBERS
, chptr
,
1210 ":%s MODE %s %s %s %s %s %s",
1211 source_p
->name
, chptr
->chname
, lmodebuf
,
1212 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1217 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1225 sendto_channel_local(ALL_MEMBERS
, chptr
,
1226 ":%s MODE %s %s %s %s %s %s",
1227 source_p
->name
, chptr
->chname
, lmodebuf
,
1228 EmptyString(lpara
[0]) ? "" : lpara
[0],
1229 EmptyString(lpara
[1]) ? "" : lpara
[1],
1230 EmptyString(lpara
[2]) ? "" : lpara
[2],
1231 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1236 /* remove_ban_list()
1238 * inputs - channel, source, list to remove, char of mode, caps needed
1240 * side effects - given list is removed, with modes issued to local clients
1243 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1244 rb_dlink_list
* list
, char c
, int mems
)
1246 static char lmodebuf
[BUFSIZE
];
1247 static char lparabuf
[BUFSIZE
];
1250 rb_dlink_node
*next_ptr
;
1253 int cur_len
, mlen
, plen
;
1257 cur_len
= mlen
= rb_sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1258 mbuf
= lmodebuf
+ mlen
;
1260 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1264 /* trailing space, and the mode letter itself */
1265 plen
= strlen(banptr
->banstr
) + 2;
1267 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1269 /* remove trailing space */
1273 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1276 mbuf
= lmodebuf
+ mlen
;
1283 pbuf
+= rb_sprintf(pbuf
, "%s ", banptr
->banstr
);
1291 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1293 list
->head
= list
->tail
= NULL
;