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 /* The caller (m_join) is only interested in the reason
98 * for the original channel.
100 if ((*err
= can_join(source_p
, chptr
, key
, &next
)) == 0)
104 if (IsNoForward(source_p
))
109 chptr
= find_channel(next
);
110 /* Can only forward to existing channels */
113 /* Already on there, show original error message */
114 if (IsMember(source_p
, chptr
))
116 /* Juped. Sending a warning notice would be unfair */
117 if (hash_find_resv(chptr
->chname
))
119 /* Don't forward to +Q channel */
120 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
122 i
= can_join(source_p
, chptr
, key
, &next
);
136 * parv[2] = channel password (key)
139 m_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
141 static char jbuf
[BUFSIZE
];
142 struct Channel
*chptr
= NULL
, *chptr2
= NULL
;
143 struct ConfItem
*aconf
;
148 char *p
= NULL
, *p2
= NULL
;
154 /* rebuild the list of channels theyre supposed to be joining.
155 * this code has a side effect of losing keys, but..
157 chanlist
= LOCAL_COPY(parv
[1]);
158 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
160 /* check the length and name of channel is ok */
161 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
163 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
164 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
168 /* join 0 parts all channels */
169 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
171 (void) strcpy(jbuf
, "0");
175 /* check it begins with # or &, and local chans are disabled */
176 else if(!IsChannelName(name
) ||
177 ( ConfigChannel
.disable_local_channels
&& name
[0] == '&'))
179 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
180 form_str(ERR_NOSUCHCHANNEL
), name
);
184 /* see if its resv'd */
185 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
187 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
188 form_str(ERR_BADCHANNAME
), name
);
190 /* dont warn for opers */
191 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
192 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
193 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
194 source_p
->name
, source_p
->username
,
195 source_p
->orighost
, name
, aconf
->passwd
);
196 /* dont update tracking for jupe exempt users, these
197 * are likely to be spamtrap leaves
199 else if(IsExemptJupe(source_p
))
205 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
206 ConfigChannel
.no_join_on_split
)
208 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
209 me
.name
, source_p
->name
, name
);
214 (void) strcat(jbuf
, ",");
215 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
220 mykey
= LOCAL_COPY(parv
[2]);
221 key
= rb_strtok_r(mykey
, ",", &p2
);
224 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
225 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
227 hook_data_channel_activity hook_info
;
229 /* JOIN 0 simply parts all channels the user is in */
230 if(*name
== '0' && !atoi(name
))
232 if(source_p
->user
->channel
.head
== NULL
)
235 do_join_0(&me
, source_p
);
239 /* look for the channel */
240 if((chptr
= find_channel(name
)) != NULL
)
242 if(IsMember(source_p
, chptr
))
249 hook_data_client_approval moduledata
;
251 moduledata
.client
= source_p
;
252 moduledata
.approved
= 0;
254 call_hook(h_can_create_channel
, &moduledata
);
256 if(moduledata
.approved
!= 0)
258 sendto_one(source_p
, form_str(moduledata
.approved
),
259 me
.name
, source_p
->name
, name
);
263 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
264 ConfigChannel
.no_create_on_split
)
266 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
267 me
.name
, source_p
->name
, name
);
274 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
275 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
276 (!IsOper(source_p
) ||
277 (rb_dlink_list_length(&source_p
->user
->channel
) >=
278 (unsigned long) ConfigChannel
.max_chans_per_user
* 3)))
280 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
281 me
.name
, source_p
->name
, name
);
285 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
287 chptr
= get_or_create_channel(source_p
, name
, NULL
);
291 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
292 me
.name
, source_p
->name
, name
);
297 /* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */
298 if(!(chptr2
= check_forward(source_p
, chptr
, key
, &i
)))
300 /* might be wrong, but is there any other better location for such?
301 * see extensions/chm_operonly.c for other comments on this
305 sendto_one(source_p
, form_str(i
), me
.name
, source_p
->name
, name
);
309 else if(chptr
!= chptr2
)
310 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr2
->chname
);
315 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
316 check_spambot_warning(source_p
, name
);
318 /* add the user to the channel */
319 add_user_to_channel(chptr
, source_p
, flags
);
320 if (chptr
->mode
.join_num
&&
321 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
323 chptr
->join_count
= 0;
324 chptr
->join_delta
= rb_current_time();
328 /* we send the user their join here, because we could have to
329 * send a mode out next.
331 send_channel_join(chptr
, source_p
);
333 /* its a new channel, set +nt and burst. */
334 if(flags
& CHFL_CHANOP
)
336 chptr
->channelts
= rb_current_time();
337 chptr
->mode
.mode
|= MODE_TOPICLIMIT
;
338 chptr
->mode
.mode
|= MODE_NOPRIVMSGS
;
339 modes
= channel_modes(chptr
, &me
);
341 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
342 me
.name
, chptr
->chname
, modes
);
344 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
345 ":%s SJOIN %ld %s %s :@%s",
346 me
.id
, (long) chptr
->channelts
,
347 chptr
->chname
, modes
, source_p
->id
);
351 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
353 use_id(source_p
), (long) chptr
->channelts
,
357 del_invite(chptr
, source_p
);
359 if(chptr
->topic
!= NULL
)
361 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
362 source_p
->name
, chptr
->chname
, chptr
->topic
);
364 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
365 me
.name
, source_p
->name
, chptr
->chname
,
366 chptr
->topic_info
, chptr
->topic_time
);
369 channel_member_names(chptr
, source_p
, 1);
371 hook_info
.client
= source_p
;
372 hook_info
.chptr
= chptr
;
374 call_hook(h_channel_join
, &hook_info
);
382 * parv[1] = channel TS
384 * parv[3] = "+", formerly channel modes but now unused
385 * alternatively, a single "0" parameter parts all channels
388 ms_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
390 struct Channel
*chptr
;
391 static struct Mode mode
;
395 int keep_our_modes
= YES
;
396 int keep_new_modes
= YES
;
397 rb_dlink_node
*ptr
, *next_ptr
;
399 /* special case for join 0 */
400 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
402 do_join_0(client_p
, source_p
);
409 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
412 /* joins for local channels cant happen. */
413 if(parv
[2][0] == '&')
417 mode
.key
[0] = mode
.forward
[0] = '\0';
418 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
420 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
423 newts
= atol(parv
[1]);
424 oldts
= chptr
->channelts
;
426 #ifdef IGNORE_BOGUS_TS
427 if(newts
< 800000000)
429 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
430 "*** Bogus TS %ld on %s ignored from %s",
431 (long) newts
, chptr
->chname
, client_p
->name
);
432 newts
= (oldts
== 0) ? oldts
: 800000000;
435 /* making a channel TS0 */
436 if(!isnew
&& !newts
&& oldts
)
438 sendto_channel_local(ALL_MEMBERS
, chptr
,
439 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
440 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
441 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
442 "Server %s changing TS on %s from %ld to 0",
443 source_p
->name
, chptr
->chname
, (long) oldts
);
448 chptr
->channelts
= newts
;
449 else if(newts
== 0 || oldts
== 0)
450 chptr
->channelts
= 0;
451 else if(newts
== oldts
)
453 else if(newts
< oldts
)
456 chptr
->channelts
= newts
;
461 /* Lost the TS, other side wins, so remove modes on this side */
464 set_final_mode(&mode
, &chptr
->mode
);
466 remove_our_modes(chptr
, source_p
);
467 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
469 del_invite(chptr
, ptr
->data
);
471 /* If setting -j, clear join throttle state -- jilles */
472 chptr
->join_count
= chptr
->join_delta
= 0;
473 sendto_channel_local(ALL_MEMBERS
, chptr
,
474 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
475 me
.name
, chptr
->chname
, chptr
->chname
,
476 (long) oldts
, (long) newts
);
477 /* Update capitalization in channel name, this makes the
478 * capitalization timestamped like modes are -- jilles */
479 strcpy(chptr
->chname
, parv
[2]);
481 sendto_channel_local(ALL_MEMBERS
, chptr
,
483 source_p
->servptr
->name
,
484 chptr
->chname
, modebuf
, parabuf
);
485 *modebuf
= *parabuf
= '\0';
487 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
488 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, FALSE
);
491 if(!IsMember(source_p
, chptr
))
493 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
494 if (chptr
->mode
.join_num
&&
495 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
497 chptr
->join_count
= 0;
498 chptr
->join_delta
= rb_current_time();
501 send_channel_join(chptr
, source_p
);
504 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
506 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
511 ms_sjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
513 static char buf_uid
[BUFSIZE
];
514 static const char empty_modes
[] = "0";
515 struct Channel
*chptr
;
516 struct Client
*target_p
, *fakesource_p
;
519 static struct Mode mode
, *oldmode
;
522 int keep_our_modes
= 1;
523 int keep_new_modes
= 1;
534 int i
, joinc
= 0, timeslice
= 0;
535 static char empty
[] = "";
536 rb_dlink_node
*ptr
, *next_ptr
;
538 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
541 /* SJOIN's for local channels can't happen. */
545 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
546 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
548 /* Hide connecting server on netburst -- jilles */
549 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
552 fakesource_p
= source_p
;
555 newts
= atol(parv
[1]);
563 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
569 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
571 mode
.join_num
= joinc
;
572 mode
.join_time
= timeslice
;
577 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
583 mode
.limit
= atoi(parv
[4 + args
]);
589 if(chmode_flags
[(int) *s
] != 0)
591 mode
.mode
|= chmode_flags
[(int) *s
];
600 /* remove any leading spaces */
607 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
608 return 0; /* channel name too long? */
611 oldts
= chptr
->channelts
;
612 oldmode
= &chptr
->mode
;
614 #ifdef IGNORE_BOGUS_TS
615 if(newts
< 800000000)
617 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
618 "*** Bogus TS %ld on %s ignored from %s",
619 (long) newts
, chptr
->chname
, client_p
->name
);
621 newts
= (oldts
== 0) ? oldts
: 800000000;
624 if(!isnew
&& !newts
&& oldts
)
626 sendto_channel_local(ALL_MEMBERS
, chptr
,
627 ":%s NOTICE %s :*** Notice -- TS for %s "
628 "changed from %ld to 0",
629 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
630 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
631 "Server %s changing TS on %s from %ld to 0",
632 source_p
->name
, chptr
->chname
, (long) oldts
);
637 chptr
->channelts
= newts
;
639 else if(newts
== 0 || oldts
== 0)
640 chptr
->channelts
= 0;
641 else if(newts
== oldts
)
643 else if(newts
< oldts
)
645 /* If configured, kick people trying to join +i/+k
646 * channels by recreating them on split servers.
647 * If the source has sent EOB, assume this is some
648 * sort of hack by services. If cmode +i is set,
649 * services can send kicks if needed; if the key
650 * differs, services cannot kick in a race-free
651 * manner so do so here.
653 if (ConfigChannel
.kick_on_split_riding
&&
654 ((!HasSentEob(source_p
) &&
655 mode
.mode
& MODE_INVITEONLY
) ||
656 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
658 struct membership
*msptr
;
660 int l
= rb_dlink_list_length(&chptr
->members
);
662 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
665 who
= msptr
->client_p
;
666 sendto_one(who
, ":%s KICK %s %s :Net Rider",
667 me
.name
, chptr
->chname
, who
->name
);
669 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
670 ":%s KICK %s %s :Net Rider",
671 me
.id
, chptr
->chname
,
673 remove_user_from_channel(msptr
);
679 /* Channel was emptied, create a new one */
680 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
681 return 0; /* oops! */
683 oldmode
= &chptr
->mode
;
687 chptr
->channelts
= newts
;
694 else if(keep_our_modes
)
696 mode
.mode
|= oldmode
->mode
;
697 if(oldmode
->limit
> mode
.limit
)
698 mode
.limit
= oldmode
->limit
;
699 if(strcmp(mode
.key
, oldmode
->key
) < 0)
700 strcpy(mode
.key
, oldmode
->key
);
701 if(oldmode
->join_num
> mode
.join_num
||
702 (oldmode
->join_num
== mode
.join_num
&&
703 oldmode
->join_time
> mode
.join_time
))
705 mode
.join_num
= oldmode
->join_num
;
706 mode
.join_time
= oldmode
->join_time
;
708 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
709 strcpy(mode
.forward
, oldmode
->forward
);
713 /* If setting -j, clear join throttle state -- jilles */
715 chptr
->join_count
= chptr
->join_delta
= 0;
718 set_final_mode(&mode
, oldmode
);
721 /* Lost the TS, other side wins, so remove modes on this side */
724 remove_our_modes(chptr
, fakesource_p
);
725 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
727 del_invite(chptr
, ptr
->data
);
730 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
731 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
732 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
733 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
735 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
736 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
738 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
739 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
743 sendto_channel_local(ALL_MEMBERS
, chptr
,
744 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
745 me
.name
, chptr
->chname
, chptr
->chname
,
746 (long) oldts
, (long) newts
);
747 /* Update capitalization in channel name, this makes the
748 * capitalization timestamped like modes are -- jilles */
749 strcpy(chptr
->chname
, parv
[2]);
751 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
752 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, FALSE
);
756 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
757 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
759 *modebuf
= *parabuf
= '\0';
761 if(parv
[3][0] != '0' && keep_new_modes
)
762 modes
= channel_modes(chptr
, source_p
);
766 mlen_uid
= rb_sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
767 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
768 ptr_uid
= buf_uid
+ mlen_uid
;
771 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
773 len_nick
= len_uid
= 0;
775 /* if theres a space, theres going to be more than one nick, change the
776 * first space to \0, so s is just the first nick, and point p to the
779 if((p
= strchr(s
, ' ')) != NULL
)
790 for (i
= 0; i
< 2; i
++)
804 /* if the client doesnt exist or is fake direction, skip. */
805 if(!(target_p
= find_client(s
)) ||
806 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
809 /* we assume for these we can fit at least one nick/uid in.. */
811 /* check we can fit another status+nick+space into a buffer */
812 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
814 *(ptr_uid
- 1) = '\0';
815 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
816 ptr_uid
= buf_uid
+ mlen_uid
;
836 /* copy the nick to the two buffers */
837 len
= rb_sprintf(ptr_uid
, "%s ", use_id(target_p
));
844 if(!IsMember(target_p
, chptr
))
846 add_user_to_channel(chptr
, target_p
, fl
);
847 send_channel_join(chptr
, target_p
);
854 para
[pargs
++] = target_p
->name
;
856 /* a +ov user.. bleh */
859 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
862 if(pargs
>= MAXMODEPARAMS
)
865 sendto_channel_local(ALL_MEMBERS
, chptr
,
866 ":%s MODE %s %s %s %s %s %s",
867 fakesource_p
->name
, chptr
->chname
,
869 para
[0], para
[1], para
[2], para
[3]);
872 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
877 para
[pargs
++] = target_p
->name
;
880 else if(fl
& CHFL_VOICE
)
883 para
[pargs
++] = target_p
->name
;
886 if(pargs
>= MAXMODEPARAMS
)
889 sendto_channel_local(ALL_MEMBERS
, chptr
,
890 ":%s MODE %s %s %s %s %s %s",
893 modebuf
, para
[0], para
[1], para
[2], para
[3]);
896 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
901 /* p points to the next nick */
904 /* if there was a trailing space and p was pointing to it, then we
905 * need to exit.. this has the side effect of breaking double spaces
906 * in an sjoin.. but that shouldnt happen anyway
908 if(s
&& (*s
== '\0'))
911 /* if p was NULL due to no spaces, s wont exist due to the above, so
912 * we cant check it for spaces.. if there are no spaces, then when
913 * we next get here, s will be NULL
915 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
924 sendto_channel_local(ALL_MEMBERS
, chptr
,
925 ":%s MODE %s %s %s %s %s %s",
926 fakesource_p
->name
, chptr
->chname
, modebuf
,
927 para
[0], CheckEmpty(para
[1]),
928 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
931 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
933 destroy_channel(chptr
);
938 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
941 *(ptr_uid
- 1) = '\0';
944 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
952 * inputs - pointer to client doing join 0
954 * side effects - Use has decided to join 0. This is legacy
955 * from the days when channels were numbers not names. *sigh*
958 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
960 struct membership
*msptr
;
961 struct Channel
*chptr
= NULL
;
964 /* Finish the flood grace period... */
965 if(MyClient(source_p
) && !IsFloodDone(source_p
))
966 flood_endgrace(source_p
);
968 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
970 while((ptr
= source_p
->user
->channel
.head
))
972 if(MyConnect(source_p
) &&
973 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
974 check_spambot_warning(source_p
, NULL
);
977 chptr
= msptr
->chptr
;
978 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
980 source_p
->username
, source_p
->host
, chptr
->chname
);
981 remove_user_from_channel(msptr
);
986 check_channel_name_loc(struct Client
*source_p
, const char *name
)
990 s_assert(name
!= NULL
);
991 if(EmptyString(name
))
994 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
996 for(p
= name
; *p
; ++p
)
998 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
1004 for(p
= name
; *p
; ++p
)
1011 if(ConfigChannel
.only_ascii_channels
)
1013 for(p
= name
; *p
; ++p
)
1014 if(*p
< 33 || *p
> 126)
1022 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
1024 int dir
= MODE_QUERY
;
1025 char *pbuf
= parabuf
;
1029 /* ok, first get a list of modes we need to add */
1030 for (i
= 0; i
< 256; i
++)
1032 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1043 /* now the ones we need to remove. */
1044 for (i
= 0; i
< 256; i
++)
1046 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1057 if(oldmode
->limit
&& !mode
->limit
)
1066 if(oldmode
->key
[0] && !mode
->key
[0])
1074 len
= rb_sprintf(pbuf
, "%s ", oldmode
->key
);
1077 if(oldmode
->join_num
&& !mode
->join_num
)
1086 if(oldmode
->forward
[0] && !mode
->forward
[0])
1095 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1103 len
= rb_sprintf(pbuf
, "%d ", mode
->limit
);
1106 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1114 len
= rb_sprintf(pbuf
, "%s ", mode
->key
);
1117 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1125 len
= rb_sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1128 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) &&
1129 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
;