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
;
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
;
345 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s +nt",
346 me
.name
, chptr
->chname
);
348 if(*chptr
->chname
== '#')
350 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
351 ":%s SJOIN %ld %s +nt :@%s",
352 me
.id
, (long) chptr
->channelts
,
353 chptr
->chname
, source_p
->id
);
358 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
360 use_id(source_p
), (long) chptr
->channelts
,
364 del_invite(chptr
, source_p
);
366 if(chptr
->topic
!= NULL
)
368 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
369 source_p
->name
, chptr
->chname
, chptr
->topic
);
371 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
372 me
.name
, source_p
->name
, chptr
->chname
,
373 chptr
->topic_info
, chptr
->topic_time
);
376 channel_member_names(chptr
, source_p
, 1);
378 if(successful_join_count
)
379 source_p
->localClient
->last_join_time
= rb_current_time();
381 hook_info
.client
= source_p
;
382 hook_info
.chptr
= chptr
;
384 call_hook(h_channel_join
, &hook_info
);
395 * side effects - handles remote JOIN's sent by servers. In TSora
396 * remote clients are joined using SJOIN, hence a
397 * JOIN sent by a server on behalf of a client is an error.
398 * here, the initial code is in to take an extra parameter
399 * and use it for the TimeStamp on a new channel.
402 ms_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
404 struct Channel
*chptr
;
405 static struct Mode mode
;
409 int keep_our_modes
= YES
;
410 int keep_new_modes
= YES
;
411 rb_dlink_node
*ptr
, *next_ptr
;
413 /* special case for join 0 */
414 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
416 do_join_0(client_p
, source_p
);
423 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
426 /* joins for local channels cant happen. */
427 if(parv
[2][0] == '&')
431 mode
.key
[0] = mode
.forward
[0] = '\0';
432 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
434 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
437 newts
= atol(parv
[1]);
438 oldts
= chptr
->channelts
;
440 #ifdef IGNORE_BOGUS_TS
441 if(newts
< 800000000)
443 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
444 "*** Bogus TS %ld on %s ignored from %s",
445 (long) newts
, chptr
->chname
, client_p
->name
);
446 newts
= (oldts
== 0) ? oldts
: 800000000;
449 /* making a channel TS0 */
450 if(!isnew
&& !newts
&& oldts
)
452 sendto_channel_local(ALL_MEMBERS
, chptr
,
453 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
454 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
455 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
456 "Server %s changing TS on %s from %ld to 0",
457 source_p
->name
, chptr
->chname
, (long) oldts
);
462 chptr
->channelts
= newts
;
463 else if(newts
== 0 || oldts
== 0)
464 chptr
->channelts
= 0;
465 else if(newts
== oldts
)
467 else if(newts
< oldts
)
470 chptr
->channelts
= newts
;
475 /* Lost the TS, other side wins, so remove modes on this side */
478 set_final_mode(&mode
, &chptr
->mode
);
480 remove_our_modes(chptr
, source_p
);
481 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
483 del_invite(chptr
, ptr
->data
);
485 /* If setting -j, clear join throttle state -- jilles */
486 chptr
->join_count
= chptr
->join_delta
= 0;
487 sendto_channel_local(ALL_MEMBERS
, chptr
,
488 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
489 me
.name
, chptr
->chname
, chptr
->chname
,
490 (long) oldts
, (long) newts
);
491 /* Update capitalization in channel name, this makes the
492 * capitalization timestamped like modes are -- jilles */
493 strcpy(chptr
->chname
, parv
[2]);
495 sendto_channel_local(ALL_MEMBERS
, chptr
,
497 source_p
->servptr
->name
,
498 chptr
->chname
, modebuf
, parabuf
);
499 *modebuf
= *parabuf
= '\0';
502 if(!IsMember(source_p
, chptr
))
504 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
505 if (chptr
->mode
.join_num
&&
506 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
508 chptr
->join_count
= 0;
509 chptr
->join_delta
= rb_current_time();
512 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
513 source_p
->name
, source_p
->username
,
514 source_p
->host
, chptr
->chname
);
517 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
519 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
524 ms_sjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
526 static char buf_uid
[BUFSIZE
];
527 static const char empty_modes
[] = "0";
528 struct Channel
*chptr
;
529 struct Client
*target_p
, *fakesource_p
;
532 static struct Mode mode
, *oldmode
;
535 int keep_our_modes
= 1;
536 int keep_new_modes
= 1;
547 int i
, joinc
= 0, timeslice
= 0;
548 static char empty
[] = "";
549 rb_dlink_node
*ptr
, *next_ptr
;
551 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
554 /* SJOIN's for local channels can't happen. */
558 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
559 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
561 /* Hide connecting server on netburst -- jilles */
562 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
565 fakesource_p
= source_p
;
568 newts
= atol(parv
[1]);
576 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
582 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
584 mode
.join_num
= joinc
;
585 mode
.join_time
= timeslice
;
590 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
596 mode
.limit
= atoi(parv
[4 + args
]);
602 if(chmode_flags
[(int) *s
] != 0)
604 mode
.mode
|= chmode_flags
[(int) *s
];
613 /* remove any leading spaces */
620 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
621 return 0; /* channel name too long? */
624 oldts
= chptr
->channelts
;
625 oldmode
= &chptr
->mode
;
627 #ifdef IGNORE_BOGUS_TS
628 if(newts
< 800000000)
630 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
631 "*** Bogus TS %ld on %s ignored from %s",
632 (long) newts
, chptr
->chname
, client_p
->name
);
634 newts
= (oldts
== 0) ? oldts
: 800000000;
637 if(!isnew
&& !newts
&& oldts
)
639 sendto_channel_local(ALL_MEMBERS
, chptr
,
640 ":%s NOTICE %s :*** Notice -- TS for %s "
641 "changed from %ld to 0",
642 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
643 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
644 "Server %s changing TS on %s from %ld to 0",
645 source_p
->name
, chptr
->chname
, (long) oldts
);
650 chptr
->channelts
= newts
;
652 else if(newts
== 0 || oldts
== 0)
653 chptr
->channelts
= 0;
654 else if(newts
== oldts
)
656 else if(newts
< oldts
)
658 /* If configured, kick people trying to join +i/+k
659 * channels by recreating them on split servers.
660 * Don't kick if the source has sent EOB (services
661 * deopping everyone by TS-1 SJOIN).
663 if (ConfigChannel
.kick_on_split_riding
&&
664 !HasSentEob(source_p
) &&
665 ((mode
.mode
& MODE_INVITEONLY
) ||
666 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
668 struct membership
*msptr
;
670 int l
= rb_dlink_list_length(&chptr
->members
);
672 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
675 who
= msptr
->client_p
;
676 sendto_one(who
, ":%s KICK %s %s :Net Rider",
677 me
.name
, chptr
->chname
, who
->name
);
679 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
680 ":%s KICK %s %s :Net Rider",
681 me
.id
, chptr
->chname
,
683 remove_user_from_channel(msptr
);
689 /* Channel was emptied, create a new one */
690 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
691 return 0; /* oops! */
693 oldmode
= &chptr
->mode
;
697 chptr
->channelts
= newts
;
704 else if(keep_our_modes
)
706 mode
.mode
|= oldmode
->mode
;
707 if(oldmode
->limit
> mode
.limit
)
708 mode
.limit
= oldmode
->limit
;
709 if(strcmp(mode
.key
, oldmode
->key
) < 0)
710 strcpy(mode
.key
, oldmode
->key
);
711 if(oldmode
->join_num
> mode
.join_num
||
712 (oldmode
->join_num
== mode
.join_num
&&
713 oldmode
->join_time
> mode
.join_time
))
715 mode
.join_num
= oldmode
->join_num
;
716 mode
.join_time
= oldmode
->join_time
;
718 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
719 strcpy(mode
.forward
, oldmode
->forward
);
723 /* If setting -j, clear join throttle state -- jilles */
725 chptr
->join_count
= chptr
->join_delta
= 0;
728 set_final_mode(&mode
, oldmode
);
731 /* Lost the TS, other side wins, so remove modes on this side */
734 remove_our_modes(chptr
, fakesource_p
);
735 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
737 del_invite(chptr
, ptr
->data
);
740 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
741 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
742 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
743 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
745 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
746 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
748 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
749 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
753 sendto_channel_local(ALL_MEMBERS
, chptr
,
754 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
755 me
.name
, chptr
->chname
, chptr
->chname
,
756 (long) oldts
, (long) newts
);
757 /* Update capitalization in channel name, this makes the
758 * capitalization timestamped like modes are -- jilles */
759 strcpy(chptr
->chname
, parv
[2]);
763 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
764 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
766 *modebuf
= *parabuf
= '\0';
768 if(parv
[3][0] != '0' && keep_new_modes
)
769 modes
= channel_modes(chptr
, source_p
);
773 /* working on the presumption eventually itll be more efficient to
774 * build a TS6 buffer without checking its needed..
776 mlen_uid
= rb_sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
777 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
778 ptr_uid
= buf_uid
+ mlen_uid
;
781 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
783 len_nick
= len_uid
= 0;
785 /* if theres a space, theres going to be more than one nick, change the
786 * first space to \0, so s is just the first nick, and point p to the
789 if((p
= strchr(s
, ' ')) != NULL
)
800 for (i
= 0; i
< 2; i
++)
814 /* if the client doesnt exist or is fake direction, skip. */
815 if(!(target_p
= find_client(s
)) ||
816 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
819 /* we assume for these we can fit at least one nick/uid in.. */
821 /* check we can fit another status+nick+space into a buffer */
822 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
824 *(ptr_uid
- 1) = '\0';
825 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
826 ptr_uid
= buf_uid
+ mlen_uid
;
846 /* copy the nick to the two buffers */
847 len
= rb_sprintf(ptr_uid
, "%s ", use_id(target_p
));
854 if(!IsMember(target_p
, chptr
))
856 add_user_to_channel(chptr
, target_p
, fl
);
857 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
859 target_p
->username
, target_p
->host
, parv
[2]);
866 para
[pargs
++] = target_p
->name
;
868 /* a +ov user.. bleh */
871 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
874 if(pargs
>= MAXMODEPARAMS
)
877 sendto_channel_local(ALL_MEMBERS
, chptr
,
878 ":%s MODE %s %s %s %s %s %s",
879 fakesource_p
->name
, chptr
->chname
,
881 para
[0], para
[1], para
[2], para
[3]);
884 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
889 para
[pargs
++] = target_p
->name
;
892 else if(fl
& CHFL_VOICE
)
895 para
[pargs
++] = target_p
->name
;
898 if(pargs
>= MAXMODEPARAMS
)
901 sendto_channel_local(ALL_MEMBERS
, chptr
,
902 ":%s MODE %s %s %s %s %s %s",
905 modebuf
, para
[0], para
[1], para
[2], para
[3]);
908 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
913 /* p points to the next nick */
916 /* if there was a trailing space and p was pointing to it, then we
917 * need to exit.. this has the side effect of breaking double spaces
918 * in an sjoin.. but that shouldnt happen anyway
920 if(s
&& (*s
== '\0'))
923 /* if p was NULL due to no spaces, s wont exist due to the above, so
924 * we cant check it for spaces.. if there are no spaces, then when
925 * we next get here, s will be NULL
927 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
936 sendto_channel_local(ALL_MEMBERS
, chptr
,
937 ":%s MODE %s %s %s %s %s %s",
938 fakesource_p
->name
, chptr
->chname
, modebuf
,
939 para
[0], CheckEmpty(para
[1]),
940 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
943 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
945 destroy_channel(chptr
);
950 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
953 *(ptr_uid
- 1) = '\0';
956 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
964 * inputs - pointer to client doing join 0
966 * side effects - Use has decided to join 0. This is legacy
967 * from the days when channels were numbers not names. *sigh*
968 * There is a bunch of evilness necessary here due to
972 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
974 struct membership
*msptr
;
975 struct Channel
*chptr
= NULL
;
978 /* Finish the flood grace period... */
979 if(MyClient(source_p
) && !IsFloodDone(source_p
))
980 flood_endgrace(source_p
);
982 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
984 if(source_p
->user
->channel
.head
&& MyConnect(source_p
) &&
985 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
986 check_spambot_warning(source_p
, NULL
);
988 while((ptr
= source_p
->user
->channel
.head
))
991 chptr
= msptr
->chptr
;
992 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
994 source_p
->username
, source_p
->host
, chptr
->chname
);
995 remove_user_from_channel(msptr
);
1000 check_channel_name_loc(struct Client
*source_p
, const char *name
)
1002 s_assert(name
!= NULL
);
1003 if(EmptyString(name
))
1006 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
1008 for(; *name
; ++name
)
1010 if(!IsChanChar(*name
) || IsFakeChanChar(*name
))
1016 for(; *name
; ++name
)
1018 if(!IsChanChar(*name
))
1027 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1029 int dir
= MODE_QUERY
;
1030 char *pbuf
= parabuf
;
1034 /* ok, first get a list of modes we need to add */
1035 for (i
= 0; i
< 256; i
++)
1037 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1048 /* now the ones we need to remove. */
1049 for (i
= 0; i
< 256; i
++)
1051 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1062 if(oldmode
->limit
&& !mode
->limit
)
1071 if(oldmode
->key
[0] && !mode
->key
[0])
1079 len
= rb_sprintf(pbuf
, "%s ", oldmode
->key
);
1082 if(oldmode
->join_num
&& !mode
->join_num
)
1091 if(oldmode
->forward
[0] && !mode
->forward
[0])
1100 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1108 len
= rb_sprintf(pbuf
, "%d ", mode
->limit
);
1111 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1119 len
= rb_sprintf(pbuf
, "%s ", mode
->key
);
1122 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1130 len
= rb_sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1133 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) && ConfigChannel
.use_forward
)
1141 len
= rb_sprintf(pbuf
, "%s ", mode
->forward
);
1155 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1157 struct membership
*msptr
;
1159 char lmodebuf
[MODEBUFLEN
];
1160 char *lpara
[MAXMODEPARAMS
];
1167 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1170 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1174 if(is_chanop(msptr
))
1176 msptr
->flags
&= ~CHFL_CHANOP
;
1177 lpara
[count
++] = msptr
->client_p
->name
;
1180 /* +ov, might not fit so check. */
1181 if(is_voiced(msptr
))
1183 if(count
>= MAXMODEPARAMS
)
1186 sendto_channel_local(ALL_MEMBERS
, chptr
,
1187 ":%s MODE %s %s %s %s %s %s",
1188 me
.name
, chptr
->chname
,
1189 lmodebuf
, lpara
[0], lpara
[1],
1190 lpara
[2], lpara
[3]);
1192 /* preserve the initial '-' */
1197 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1201 msptr
->flags
&= ~CHFL_VOICE
;
1202 lpara
[count
++] = msptr
->client_p
->name
;
1206 else if(is_voiced(msptr
))
1208 msptr
->flags
&= ~CHFL_VOICE
;
1209 lpara
[count
++] = msptr
->client_p
->name
;
1215 if(count
>= MAXMODEPARAMS
)
1218 sendto_channel_local(ALL_MEMBERS
, chptr
,
1219 ":%s MODE %s %s %s %s %s %s",
1220 me
.name
, chptr
->chname
, lmodebuf
,
1221 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1226 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1234 sendto_channel_local(ALL_MEMBERS
, chptr
,
1235 ":%s MODE %s %s %s %s %s %s",
1236 me
.name
, chptr
->chname
, lmodebuf
,
1237 EmptyString(lpara
[0]) ? "" : lpara
[0],
1238 EmptyString(lpara
[1]) ? "" : lpara
[1],
1239 EmptyString(lpara
[2]) ? "" : lpara
[2],
1240 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1245 /* remove_ban_list()
1247 * inputs - channel, source, list to remove, char of mode, caps needed
1249 * side effects - given list is removed, with modes issued to local clients
1252 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1253 rb_dlink_list
* list
, char c
, int mems
)
1255 static char lmodebuf
[BUFSIZE
];
1256 static char lparabuf
[BUFSIZE
];
1259 rb_dlink_node
*next_ptr
;
1262 int cur_len
, mlen
, plen
;
1266 cur_len
= mlen
= rb_sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1267 mbuf
= lmodebuf
+ mlen
;
1269 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1273 /* trailing space, and the mode letter itself */
1274 plen
= strlen(banptr
->banstr
) + 2;
1276 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1278 /* remove trailing space */
1282 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1285 mbuf
= lmodebuf
+ mlen
;
1292 pbuf
+= rb_sprintf(pbuf
, "%s ", banptr
->banstr
);
1300 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1302 list
->head
= list
->tail
= NULL
;