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
35 #include "s_newconf.h"
41 #include "ratelimit.h"
44 static const char join_desc
[] = "Provides the JOIN and TS6 SJOIN commands to facilitate joining and creating channels";
46 static void m_join(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
47 static void ms_join(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
48 static void ms_sjoin(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
50 static int h_can_create_channel
;
51 static int h_channel_join
;
53 struct Message join_msgtab
= {
55 {mg_unreg
, {m_join
, 2}, {ms_join
, 2}, mg_ignore
, mg_ignore
, {m_join
, 2}}
58 struct Message sjoin_msgtab
= {
60 {mg_unreg
, mg_ignore
, mg_ignore
, {ms_sjoin
, 4}, mg_ignore
, mg_ignore
}
63 mapi_clist_av1 join_clist
[] = { &join_msgtab
, &sjoin_msgtab
, NULL
};
65 mapi_hlist_av1 join_hlist
[] = {
66 { "can_create_channel", &h_can_create_channel
},
67 { "channel_join", &h_channel_join
},
71 DECLARE_MODULE_AV2(join
, NULL
, NULL
, join_clist
, join_hlist
, NULL
, NULL
, NULL
, join_desc
);
73 static void do_join_0(struct Client
*client_p
, struct Client
*source_p
);
74 static bool check_channel_name_loc(struct Client
*source_p
, const char *name
);
75 static void send_join_error(struct Client
*source_p
, int numeric
, const char *name
);
77 static char *set_final_mode(char *mbuf
, char *parabuf
, struct Mode
*mode
, struct Mode
*oldmode
);
78 static void remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
);
80 static void remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
81 rb_dlink_list
* list
, char c
, int mems
);
83 /* Check what we will forward to, without sending any notices to the user
86 static struct Channel
*
87 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
91 const char *next
= NULL
;
93 /* The caller (m_join) is only interested in the reason
94 * for the original channel.
96 if ((*err
= can_join(source_p
, chptr
, key
, &next
)) == 0)
99 /* User is +Q, or forwarding disabled */
100 if (IsNoForward(source_p
) || !ConfigChannel
.use_forward
)
108 chptr
= find_channel(next
);
109 /* Can only forward to existing channels */
112 /* Already on there... but don't send the original reason for
113 * being unable to join. It isn't their fault they're already
114 * on the channel, and it looks hostile otherwise.
117 if (IsMember(source_p
, chptr
))
119 *err
= ERR_USERONCHANNEL
; /* I'm borrowing this for now. --Elizafox */
122 /* Juped. Sending a warning notice would be unfair */
123 if (hash_find_resv(chptr
->chname
))
125 /* Don't forward to +Q channel */
126 if (chptr
->mode
.mode
& MODE_DISFORWARD
)
129 i
= can_join(source_p
, chptr
, key
, &next
);
141 * parv[2] = channel password (key)
144 m_join(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
146 static char jbuf
[BUFSIZE
];
147 static char parabuf
[MODEBUFLEN
];
148 struct Channel
*chptr
= NULL
, *chptr2
= NULL
;
149 struct ConfItem
*aconf
;
154 char *p
= NULL
, *p2
= NULL
;
160 /* rebuild the list of channels theyre supposed to be joining.
161 * this code has a side effect of losing keys, but..
163 chanlist
= LOCAL_COPY(parv
[1]);
164 for(name
= rb_strtok_r(chanlist
, ",", &p
); name
; name
= rb_strtok_r(NULL
, ",", &p
))
166 /* check the length and name of channel is ok */
167 if(!check_channel_name_loc(source_p
, name
) || (strlen(name
) > LOC_CHANNELLEN
))
169 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
170 form_str(ERR_BADCHANNAME
), (unsigned char *) name
);
174 /* join 0 parts all channels */
175 if(*name
== '0' && (name
[1] == ',' || name
[1] == '\0') && name
== chanlist
)
177 rb_strlcpy(jbuf
, "0", sizeof(jbuf
));
181 /* check it begins with a valid channel prefix per policy. */
182 else if (!IsChannelName(name
))
184 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
185 form_str(ERR_NOSUCHCHANNEL
), name
);
189 /* see if its resv'd */
190 if(!IsExemptResv(source_p
) && (aconf
= hash_find_resv(name
)))
192 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
193 form_str(ERR_BADCHANNAME
), name
);
195 /* dont warn for opers */
196 if(!IsExemptJupe(source_p
) && !IsOper(source_p
))
197 sendto_realops_snomask(SNO_SPY
, L_NETWIDE
,
198 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
199 source_p
->name
, source_p
->username
,
200 source_p
->orighost
, name
, aconf
->passwd
);
201 /* dont update tracking for jupe exempt users, these
202 * are likely to be spamtrap leaves
204 else if(IsExemptJupe(source_p
))
210 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
211 ConfigChannel
.no_join_on_split
)
213 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
214 me
.name
, source_p
->name
, name
);
219 (void) strcat(jbuf
, ",");
220 (void) rb_strlcat(jbuf
, name
, sizeof(jbuf
));
225 mykey
= LOCAL_COPY(parv
[2]);
226 key
= rb_strtok_r(mykey
, ",", &p2
);
229 for(name
= rb_strtok_r(jbuf
, ",", &p
); name
;
230 key
= (key
) ? rb_strtok_r(NULL
, ",", &p2
) : NULL
, name
= rb_strtok_r(NULL
, ",", &p
))
232 hook_data_channel_activity hook_info
;
234 /* JOIN 0 simply parts all channels the user is in */
235 if(*name
== '0' && !atoi(name
))
237 if(source_p
->user
->channel
.head
== NULL
)
240 do_join_0(&me
, source_p
);
244 /* look for the channel */
245 if((chptr
= find_channel(name
)) != NULL
)
247 if(IsMember(source_p
, chptr
))
254 hook_data_client_approval moduledata
;
256 moduledata
.client
= source_p
;
257 moduledata
.approved
= 0;
259 call_hook(h_can_create_channel
, &moduledata
);
261 if(moduledata
.approved
!= 0)
263 if(moduledata
.approved
!= ERR_CUSTOM
)
264 send_join_error(source_p
,
270 if(splitmode
&& !IsOper(source_p
) && (*name
!= '&') &&
271 ConfigChannel
.no_create_on_split
)
273 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
274 me
.name
, source_p
->name
, name
);
281 if((rb_dlink_list_length(&source_p
->user
->channel
) >=
282 (unsigned long) ConfigChannel
.max_chans_per_user
) &&
283 (!IsExtendChans(source_p
) ||
284 (rb_dlink_list_length(&source_p
->user
->channel
) >=
285 (unsigned long) ConfigChannel
.max_chans_per_user_large
)))
287 sendto_one(source_p
, form_str(ERR_TOOMANYCHANNELS
),
288 me
.name
, source_p
->name
, name
);
292 if(chptr
== NULL
) /* If I already have a chptr, no point doing this */
294 chptr
= get_or_create_channel(source_p
, name
, NULL
);
298 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
299 me
.name
, source_p
->name
, name
);
304 /* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */
305 if((chptr2
= check_forward(source_p
, chptr
, key
, &i
)) == 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 send_join_error(source_p
, i
, name
);
315 else if(chptr
!= chptr2
)
316 sendto_one_numeric(source_p
, ERR_LINKCHANNEL
, form_str(ERR_LINKCHANNEL
), name
, chptr2
->chname
);
321 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
322 check_spambot_warning(source_p
, name
);
324 /* add the user to the channel */
325 add_user_to_channel(chptr
, source_p
, flags
);
326 if (chptr
->mode
.join_num
&&
327 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
329 chptr
->join_count
= 0;
330 chptr
->join_delta
= rb_current_time();
334 /* credit user for join */
335 credit_client_join(source_p
);
337 /* we send the user their join here, because we could have to
338 * send a mode out next.
340 send_channel_join(chptr
, source_p
);
342 /* its a new channel, set +nt and burst. */
343 if(flags
& CHFL_CHANOP
)
345 chptr
->channelts
= rb_current_time();
346 chptr
->mode
.mode
|= ConfigChannel
.autochanmodes
;
347 modes
= channel_modes(chptr
, &me
);
349 sendto_channel_local(ONLY_CHANOPS
, chptr
, ":%s MODE %s %s",
350 me
.name
, chptr
->chname
, modes
);
352 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
353 ":%s SJOIN %ld %s %s :@%s",
354 me
.id
, (long) chptr
->channelts
,
355 chptr
->chname
, modes
, source_p
->id
);
359 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
361 use_id(source_p
), (long) chptr
->channelts
,
365 del_invite(chptr
, source_p
);
367 if(chptr
->topic
!= NULL
)
369 sendto_one(source_p
, form_str(RPL_TOPIC
), me
.name
,
370 source_p
->name
, chptr
->chname
, chptr
->topic
);
372 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
373 me
.name
, source_p
->name
, chptr
->chname
,
375 (unsigned long)chptr
->topic_time
);
378 channel_member_names(chptr
, source_p
, 1);
380 hook_info
.client
= source_p
;
381 hook_info
.chptr
= chptr
;
383 call_hook(h_channel_join
, &hook_info
);
389 * parv[1] = channel TS
391 * parv[3] = "+", formerly channel modes but now unused
392 * alternatively, a single "0" parameter parts all channels
395 ms_join(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
397 static char modebuf
[MODEBUFLEN
];
398 static char parabuf
[MODEBUFLEN
];
399 struct Channel
*chptr
;
400 static struct Mode mode
;
404 bool keep_our_modes
= true;
405 rb_dlink_node
*ptr
, *next_ptr
;
408 /* special case for join 0 */
409 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
411 do_join_0(client_p
, source_p
);
418 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
421 /* joins for local channels cant happen. */
422 if(parv
[2][0] == '&')
426 mode
.key
[0] = mode
.forward
[0] = '\0';
427 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
429 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
432 newts
= atol(parv
[1]);
433 oldts
= chptr
->channelts
;
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
);
447 chptr
->channelts
= newts
;
448 else if(newts
== 0 || oldts
== 0)
449 chptr
->channelts
= 0;
450 else if(newts
== oldts
)
452 else if(newts
< oldts
)
454 keep_our_modes
= false;
455 chptr
->channelts
= newts
;
458 /* Lost the TS, other side wins, so remove modes on this side */
461 mbuf
= set_final_mode(mbuf
, parabuf
, &mode
, &chptr
->mode
);
463 remove_our_modes(chptr
, source_p
);
464 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
466 del_invite(chptr
, ptr
->data
);
468 /* If setting -j, clear join throttle state -- jilles */
469 chptr
->join_count
= chptr
->join_delta
= 0;
470 sendto_channel_local(ALL_MEMBERS
, chptr
,
471 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
472 me
.name
, chptr
->chname
, chptr
->chname
,
473 (long) oldts
, (long) newts
);
474 /* Update capitalization in channel name, this makes the
475 * capitalization timestamped like modes are -- jilles */
476 strcpy(chptr
->chname
, parv
[2]);
478 sendto_channel_local(ALL_MEMBERS
, chptr
,
480 source_p
->servptr
->name
,
481 chptr
->chname
, modebuf
, parabuf
);
482 *modebuf
= *parabuf
= '\0';
484 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
485 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, false);
488 if(!IsMember(source_p
, chptr
))
490 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
491 if (chptr
->mode
.join_num
&&
492 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
494 chptr
->join_count
= 0;
495 chptr
->join_delta
= rb_current_time();
498 send_channel_join(chptr
, source_p
);
501 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
503 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
507 ms_sjoin(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
509 static char modebuf
[MODEBUFLEN
];
510 static char parabuf
[MODEBUFLEN
];
511 static char buf_uid
[BUFSIZE
];
512 static const char empty_modes
[] = "0";
513 struct Channel
*chptr
;
514 struct Client
*target_p
, *fakesource_p
;
517 static struct Mode mode
, *oldmode
;
520 bool keep_our_modes
= true;
521 bool keep_new_modes
= true;
531 int i
, joinc
= 0, timeslice
= 0;
532 static char empty
[] = "";
533 rb_dlink_node
*ptr
, *next_ptr
;
536 const char *para
[MAXMODEPARAMS
];
541 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
544 /* SJOIN's for local channels can't happen. */
548 modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
549 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
551 /* Hide connecting server on netburst -- jilles */
552 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
555 fakesource_p
= source_p
;
558 newts
= atol(parv
[1]);
566 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
572 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
574 mode
.join_num
= joinc
;
575 mode
.join_time
= timeslice
;
580 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
586 mode
.limit
= atoi(parv
[4 + args
]);
592 if(chmode_flags
[(int) *s
] != 0)
594 mode
.mode
|= chmode_flags
[(int) *s
];
603 /* remove any leading spaces */
610 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
611 return; /* channel name too long? */
614 oldts
= chptr
->channelts
;
615 oldmode
= &chptr
->mode
;
617 if(!isnew
&& !newts
&& oldts
)
619 sendto_channel_local(ALL_MEMBERS
, chptr
,
620 ":%s NOTICE %s :*** Notice -- TS for %s "
621 "changed from %ld to 0",
622 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
623 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
624 "Server %s changing TS on %s from %ld to 0",
625 source_p
->name
, chptr
->chname
, (long) oldts
);
629 chptr
->channelts
= newts
;
631 else if(newts
== 0 || oldts
== 0)
632 chptr
->channelts
= 0;
633 else if(newts
== oldts
)
635 else if(newts
< oldts
)
637 /* If configured, kick people trying to join +i/+k
638 * channels by recreating them on split servers.
639 * If the source has sent EOB, assume this is some
640 * sort of hack by services. If cmode +i is set,
641 * services can send kicks if needed; if the key
642 * differs, services cannot kick in a race-free
643 * manner so do so here.
645 if (ConfigChannel
.kick_on_split_riding
&&
646 ((!HasSentEob(source_p
) &&
647 mode
.mode
& MODE_INVITEONLY
) ||
648 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
650 struct membership
*msptr
;
652 int l
= rb_dlink_list_length(&chptr
->members
);
654 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
657 who
= msptr
->client_p
;
658 sendto_one(who
, ":%s KICK %s %s :Net Rider",
659 me
.name
, chptr
->chname
, who
->name
);
661 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
662 ":%s KICK %s %s :Net Rider",
663 me
.id
, chptr
->chname
,
665 remove_user_from_channel(msptr
);
671 /* Channel was emptied, create a new one */
672 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
675 oldmode
= &chptr
->mode
;
678 keep_our_modes
= false;
679 chptr
->channelts
= newts
;
682 keep_new_modes
= false;
686 else if(keep_our_modes
)
688 mode
.mode
|= oldmode
->mode
;
689 if(oldmode
->limit
> mode
.limit
)
690 mode
.limit
= oldmode
->limit
;
691 if(strcmp(mode
.key
, oldmode
->key
) < 0)
692 rb_strlcpy(mode
.key
, oldmode
->key
, sizeof(mode
.key
));
693 if(oldmode
->join_num
> mode
.join_num
||
694 (oldmode
->join_num
== mode
.join_num
&&
695 oldmode
->join_time
> mode
.join_time
))
697 mode
.join_num
= oldmode
->join_num
;
698 mode
.join_time
= oldmode
->join_time
;
700 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
701 rb_strlcpy(mode
.forward
, oldmode
->forward
, sizeof(mode
.forward
));
705 /* If setting -j, clear join throttle state -- jilles */
707 chptr
->join_count
= chptr
->join_delta
= 0;
710 mbuf
= set_final_mode(mbuf
, parabuf
, &mode
, oldmode
);
713 /* Lost the TS, other side wins, so remove modes on this side */
716 remove_our_modes(chptr
, fakesource_p
);
717 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
719 del_invite(chptr
, ptr
->data
);
722 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
723 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
724 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
725 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
727 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
728 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
730 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
731 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
735 sendto_channel_local(ALL_MEMBERS
, chptr
,
736 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
737 me
.name
, chptr
->chname
, chptr
->chname
,
738 (long) oldts
, (long) newts
);
739 /* Update capitalization in channel name, this makes the
740 * capitalization timestamped like modes are -- jilles */
741 strcpy(chptr
->chname
, parv
[2]);
743 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
744 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, false);
748 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
749 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
751 *modebuf
= *parabuf
= '\0';
753 if(parv
[3][0] != '0' && keep_new_modes
)
754 modes
= channel_modes(chptr
, source_p
);
758 mlen_uid
= sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
759 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
760 ptr_uid
= buf_uid
+ mlen_uid
;
763 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
767 /* if theres a space, theres going to be more than one nick, change the
768 * first space to \0, so s is just the first nick, and point p to the
771 if((p
= strchr(s
, ' ')) != NULL
)
782 for (i
= 0; i
< 2; i
++)
796 /* if the client doesnt exist or is fake direction, skip. */
797 if(!(target_p
= find_client(s
)) ||
798 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
801 /* we assume for these we can fit at least one nick/uid in.. */
803 /* check we can fit another status+nick+space into a buffer */
804 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
806 *(ptr_uid
- 1) = '\0';
807 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
808 ptr_uid
= buf_uid
+ mlen_uid
;
826 /* copy the nick to the two buffers */
827 len
= sprintf(ptr_uid
, "%s ", use_id(target_p
));
834 if(!IsMember(target_p
, chptr
))
836 add_user_to_channel(chptr
, target_p
, fl
);
837 send_channel_join(chptr
, target_p
);
844 para
[pargs
++] = target_p
->name
;
846 /* a +ov user.. bleh */
849 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
852 if(pargs
>= MAXMODEPARAMS
)
855 sendto_channel_local(ALL_MEMBERS
, chptr
,
856 ":%s MODE %s %s %s %s %s %s",
857 fakesource_p
->name
, chptr
->chname
,
859 para
[0], para
[1], para
[2], para
[3]);
862 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
867 para
[pargs
++] = target_p
->name
;
870 else if(fl
& CHFL_VOICE
)
873 para
[pargs
++] = target_p
->name
;
876 if(pargs
>= MAXMODEPARAMS
)
879 sendto_channel_local(ALL_MEMBERS
, chptr
,
880 ":%s MODE %s %s %s %s %s %s",
883 modebuf
, para
[0], para
[1], para
[2], para
[3]);
886 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
891 /* p points to the next nick */
894 /* if there was a trailing space and p was pointing to it, then we
895 * need to exit.. this has the side effect of breaking double spaces
896 * in an sjoin.. but that shouldnt happen anyway
898 if(s
&& (*s
== '\0'))
901 /* if p was NULL due to no spaces, s wont exist due to the above, so
902 * we cant check it for spaces.. if there are no spaces, then when
903 * we next get here, s will be NULL
905 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
914 sendto_channel_local(ALL_MEMBERS
, chptr
,
915 ":%s MODE %s %s %s %s %s %s",
916 fakesource_p
->name
, chptr
->chname
, modebuf
,
917 para
[0], CheckEmpty(para
[1]),
918 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
921 if(!joins
&& !(chptr
->mode
.mode
& MODE_PERMANENT
) && isnew
)
923 destroy_channel(chptr
);
928 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
931 *(ptr_uid
- 1) = '\0';
934 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
940 * inputs - pointer to client doing join 0
942 * side effects - Use has decided to join 0. This is legacy
943 * from the days when channels were numbers not names. *sigh*
946 do_join_0(struct Client
*client_p
, struct Client
*source_p
)
948 struct membership
*msptr
;
949 struct Channel
*chptr
= NULL
;
952 /* Finish the flood grace period... */
953 if(MyClient(source_p
) && !IsFloodDone(source_p
))
954 flood_endgrace(source_p
);
956 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s JOIN 0", use_id(source_p
));
958 while((ptr
= source_p
->user
->channel
.head
))
960 if(MyConnect(source_p
) &&
961 !IsOper(source_p
) && !IsExemptSpambot(source_p
))
962 check_spambot_warning(source_p
, NULL
);
965 chptr
= msptr
->chptr
;
966 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s PART %s",
968 source_p
->username
, source_p
->host
, chptr
->chname
);
969 remove_user_from_channel(msptr
);
974 check_channel_name_loc(struct Client
*source_p
, const char *name
)
978 s_assert(name
!= NULL
);
979 if(EmptyString(name
))
982 if(ConfigFileEntry
.disable_fake_channels
&& !IsOper(source_p
))
984 for(p
= name
; *p
; ++p
)
986 if(!IsChanChar(*p
) || IsFakeChanChar(*p
))
992 for(p
= name
; *p
; ++p
)
999 if(ConfigChannel
.only_ascii_channels
)
1001 for(p
= name
; *p
; ++p
)
1002 if(*p
< 33 || *p
> 126)
1009 /* send_join_error()
1011 * input - client to send to, reason, channel name
1013 * side effects - error message sent to client
1016 send_join_error(struct Client
*source_p
, int numeric
, const char *name
)
1018 /* This stuff is necessary because the form_str macro only
1019 * accepts constants.
1023 #define NORMAL_NUMERIC(i) \
1025 sendto_one(source_p, form_str(i), \
1026 me.name, source_p->name, name); \
1029 NORMAL_NUMERIC(ERR_BANNEDFROMCHAN
);
1030 NORMAL_NUMERIC(ERR_INVITEONLYCHAN
);
1031 NORMAL_NUMERIC(ERR_BADCHANNELKEY
);
1032 NORMAL_NUMERIC(ERR_CHANNELISFULL
);
1033 NORMAL_NUMERIC(ERR_NEEDREGGEDNICK
);
1034 NORMAL_NUMERIC(ERR_THROTTLE
);
1037 sendto_one_numeric(source_p
, numeric
,
1038 "%s :Cannot join channel", name
);
1044 set_final_mode(char *mbuf
, char *parabuf
, struct Mode
*mode
, struct Mode
*oldmode
)
1046 int dir
= MODE_QUERY
;
1047 char *pbuf
= parabuf
;
1051 /* ok, first get a list of modes we need to add */
1052 for (i
= 0; i
< 256; i
++)
1054 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
1065 /* now the ones we need to remove. */
1066 for (i
= 0; i
< 256; i
++)
1068 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
1079 if(oldmode
->limit
&& !mode
->limit
)
1088 if(oldmode
->key
[0] && !mode
->key
[0])
1096 len
= sprintf(pbuf
, "%s ", oldmode
->key
);
1099 if(oldmode
->join_num
&& !mode
->join_num
)
1108 if(oldmode
->forward
[0] && !mode
->forward
[0])
1117 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
1125 len
= sprintf(pbuf
, "%d ", mode
->limit
);
1128 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
1136 len
= sprintf(pbuf
, "%s ", mode
->key
);
1139 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
1147 len
= sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
1150 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) &&
1151 ConfigChannel
.use_forward
)
1159 len
= sprintf(pbuf
, "%s ", mode
->forward
);
1175 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1177 struct membership
*msptr
;
1179 char lmodebuf
[MODEBUFLEN
];
1180 char *lpara
[MAXMODEPARAMS
];
1183 char *mbuf
= lmodebuf
;
1187 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1190 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1194 if(is_chanop(msptr
))
1196 msptr
->flags
&= ~CHFL_CHANOP
;
1197 lpara
[count
++] = msptr
->client_p
->name
;
1200 /* +ov, might not fit so check. */
1201 if(is_voiced(msptr
))
1203 if(count
>= MAXMODEPARAMS
)
1206 sendto_channel_local(ALL_MEMBERS
, chptr
,
1207 ":%s MODE %s %s %s %s %s %s",
1208 source_p
->name
, chptr
->chname
,
1209 lmodebuf
, lpara
[0], lpara
[1],
1210 lpara
[2], lpara
[3]);
1212 /* preserve the initial '-' */
1217 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1221 msptr
->flags
&= ~CHFL_VOICE
;
1222 lpara
[count
++] = msptr
->client_p
->name
;
1226 else if(is_voiced(msptr
))
1228 msptr
->flags
&= ~CHFL_VOICE
;
1229 lpara
[count
++] = msptr
->client_p
->name
;
1235 if(count
>= MAXMODEPARAMS
)
1238 sendto_channel_local(ALL_MEMBERS
, chptr
,
1239 ":%s MODE %s %s %s %s %s %s",
1240 source_p
->name
, chptr
->chname
, lmodebuf
,
1241 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1246 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1254 sendto_channel_local(ALL_MEMBERS
, chptr
,
1255 ":%s MODE %s %s %s %s %s %s",
1256 source_p
->name
, chptr
->chname
, lmodebuf
,
1257 EmptyString(lpara
[0]) ? "" : lpara
[0],
1258 EmptyString(lpara
[1]) ? "" : lpara
[1],
1259 EmptyString(lpara
[2]) ? "" : lpara
[2],
1260 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1265 /* remove_ban_list()
1267 * inputs - channel, source, list to remove, char of mode, caps needed
1269 * side effects - given list is removed, with modes issued to local clients
1272 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1273 rb_dlink_list
* list
, char c
, int mems
)
1275 static char lmodebuf
[BUFSIZE
];
1276 static char lparabuf
[BUFSIZE
];
1279 rb_dlink_node
*next_ptr
;
1282 int cur_len
, mlen
, plen
;
1287 cur_len
= mlen
= sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1288 mbuf
= lmodebuf
+ mlen
;
1290 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1294 /* trailing space, and the mode letter itself */
1295 plen
= strlen(banptr
->banstr
) +
1296 (banptr
->forward
? strlen(banptr
->forward
) + 1 : 0) + 2;
1298 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1300 /* remove trailing space */
1304 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1307 mbuf
= lmodebuf
+ mlen
;
1314 if (banptr
->forward
)
1315 pbuf
+= sprintf(pbuf
, "%s$%s ", banptr
->banstr
, banptr
->forward
);
1317 pbuf
+= sprintf(pbuf
, "%s ", banptr
->banstr
);
1325 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1327 list
->head
= list
->tail
= NULL
;