]> jfr.im git - solanum.git/blame - modules/core/m_join.c
remove unused variables
[solanum.git] / modules / core / m_join.c
CommitLineData
212380e3
AC
1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_join.c: Joins a channel.
4 *
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
8 *
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.
13 *
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.
18 *
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
22 * USA
212380e3
AC
23 */
24
25#include "stdinc.h"
212380e3
AC
26#include "channel.h"
27#include "client.h"
212380e3 28#include "hash.h"
4562c604 29#include "match.h"
212380e3
AC
30#include "ircd.h"
31#include "numeric.h"
32#include "send.h"
33#include "s_serv.h"
34#include "s_conf.h"
35#include "s_newconf.h"
36#include "msg.h"
37#include "parse.h"
38#include "modules.h"
212380e3 39#include "packet.h"
acdf71d9 40#include "chmode.h"
7e132ff0 41#include "ratelimit.h"
77d3d2db 42#include "s_assert.h"
212380e3 43
eeabf33a
EM
44static const char join_desc[] = "Provides the JOIN and TS6 SJOIN commands to facilitate joining and creating channels";
45
3c7d6fcc
EM
46static void m_join(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
47static void ms_join(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
48static void ms_sjoin(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
49
50static int h_can_create_channel;
51static int h_channel_join;
52
53struct Message join_msgtab = {
7baa37a9 54 "JOIN", 0, 0, 0, 0,
212380e3
AC
55 {mg_unreg, {m_join, 2}, {ms_join, 2}, mg_ignore, mg_ignore, {m_join, 2}}
56};
57
8cc12805 58struct Message sjoin_msgtab = {
7baa37a9 59 "SJOIN", 0, 0, 0, 0,
1766edef 60 {mg_unreg, mg_ignore, mg_ignore, {ms_sjoin, 4}, mg_ignore, mg_ignore}
8cc12805
VY
61};
62
63mapi_clist_av1 join_clist[] = { &join_msgtab, &sjoin_msgtab, NULL };
212380e3
AC
64
65mapi_hlist_av1 join_hlist[] = {
66 { "can_create_channel", &h_can_create_channel },
67 { "channel_join", &h_channel_join },
68 { NULL, NULL },
69};
70
823ab528 71DECLARE_MODULE_AV2(join, NULL, NULL, join_clist, join_hlist, NULL, NULL, NULL, join_desc);
212380e3 72
f4a80ce6 73static void do_join_0(struct Client *client_p, struct Client *source_p);
3c7d6fcc 74static bool check_channel_name_loc(struct Client *source_p, const char *name);
35bfe0e6 75static void send_join_error(struct Client *source_p, int numeric, const char *name);
212380e3 76
2f0b6f83 77static char *set_final_mode(char *mbuf, char *parabuf, struct Mode *mode, struct Mode *oldmode);
212380e3
AC
78static void remove_our_modes(struct Channel *chptr, struct Client *source_p);
79
8cc12805 80static void remove_ban_list(struct Channel *chptr, struct Client *source_p,
8afeb720 81 rb_dlink_list * list, char c, int mems);
8cc12805 82
212380e3
AC
83/* Check what we will forward to, without sending any notices to the user
84 * -- jilles
85 */
86static struct Channel *
87check_forward(struct Client *source_p, struct Channel *chptr,
765d839d 88 char *key, int *err)
212380e3
AC
89{
90 int depth = 0, i;
d9af501a 91 const char *next = NULL;
765d839d
EM
92
93 /* The caller (m_join) is only interested in the reason
94 * for the original channel.
95 */
96 if ((*err = can_join(source_p, chptr, key, &next)) == 0)
97 return chptr;
212380e3 98
6a85e665
JT
99 /* User is +Q, or forwarding disabled */
100 if (IsNoForward(source_p) || !ConfigChannel.use_forward)
212380e3
AC
101 return NULL;
102
103 while (depth < 16)
104 {
97532cfa
JT
105 if (next == NULL)
106 return NULL;
fc9013d6 107
765d839d 108 chptr = find_channel(next);
212380e3
AC
109 /* Can only forward to existing channels */
110 if (chptr == NULL)
111 return NULL;
fc9013d6
EM
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.
115 * --Elizafox
116 */
212380e3 117 if (IsMember(source_p, chptr))
fc9013d6
EM
118 {
119 *err = ERR_USERONCHANNEL; /* I'm borrowing this for now. --Elizafox */
212380e3 120 return NULL;
fc9013d6 121 }
212380e3
AC
122 /* Juped. Sending a warning notice would be unfair */
123 if (hash_find_resv(chptr->chname))
124 return NULL;
125 /* Don't forward to +Q channel */
126 if (chptr->mode.mode & MODE_DISFORWARD)
127 return NULL;
fc9013d6 128
765d839d 129 i = can_join(source_p, chptr, key, &next);
212380e3
AC
130 if (i == 0)
131 return chptr;
212380e3
AC
132 depth++;
133 }
134
135 return NULL;
136}
137
138/*
139 * m_join
212380e3
AC
140 * parv[1] = channel
141 * parv[2] = channel password (key)
142 */
3c7d6fcc 143static void
428ca87b 144m_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
145{
146 static char jbuf[BUFSIZE];
765d839d 147 struct Channel *chptr = NULL, *chptr2 = NULL;
212380e3
AC
148 struct ConfItem *aconf;
149 char *name;
150 char *key = NULL;
095efcf0 151 const char *modes;
212380e3
AC
152 int i, flags = 0;
153 char *p = NULL, *p2 = NULL;
154 char *chanlist;
155 char *mykey;
212380e3
AC
156
157 jbuf[0] = '\0';
158
159 /* rebuild the list of channels theyre supposed to be joining.
160 * this code has a side effect of losing keys, but..
161 */
162 chanlist = LOCAL_COPY(parv[1]);
4a2651e5 163 for(name = rb_strtok_r(chanlist, ",", &p); name; name = rb_strtok_r(NULL, ",", &p))
212380e3
AC
164 {
165 /* check the length and name of channel is ok */
166 if(!check_channel_name_loc(source_p, name) || (strlen(name) > LOC_CHANNELLEN))
167 {
168 sendto_one_numeric(source_p, ERR_BADCHANNAME,
169 form_str(ERR_BADCHANNAME), (unsigned char *) name);
170 continue;
171 }
172
f4a80ce6
JT
173 /* join 0 parts all channels */
174 if(*name == '0' && (name[1] == ',' || name[1] == '\0') && name == chanlist)
175 {
4d5a902f 176 rb_strlcpy(jbuf, "0", sizeof(jbuf));
f4a80ce6
JT
177 continue;
178 }
179
01978a2c
AC
180 /* check it begins with a valid channel prefix per policy. */
181 else if (!IsChannelName(name))
212380e3
AC
182 {
183 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
184 form_str(ERR_NOSUCHCHANNEL), name);
185 continue;
186 }
187
188 /* see if its resv'd */
189 if(!IsExemptResv(source_p) && (aconf = hash_find_resv(name)))
190 {
191 sendto_one_numeric(source_p, ERR_BADCHANNAME,
192 form_str(ERR_BADCHANNAME), name);
193
194 /* dont warn for opers */
195 if(!IsExemptJupe(source_p) && !IsOper(source_p))
196 sendto_realops_snomask(SNO_SPY, L_NETWIDE,
197 "User %s (%s@%s) is attempting to join locally juped channel %s (%s)",
198 source_p->name, source_p->username,
63aecfb9 199 source_p->orighost, name, aconf->passwd);
212380e3
AC
200 /* dont update tracking for jupe exempt users, these
201 * are likely to be spamtrap leaves
202 */
203 else if(IsExemptJupe(source_p))
204 aconf->port--;
205
206 continue;
207 }
208
209 if(splitmode && !IsOper(source_p) && (*name != '&') &&
210 ConfigChannel.no_join_on_split)
211 {
212 sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
213 me.name, source_p->name, name);
214 continue;
215 }
216
217 if(*jbuf)
218 (void) strcat(jbuf, ",");
1f9de103 219 (void) rb_strlcat(jbuf, name, sizeof(jbuf));
212380e3
AC
220 }
221
222 if(parc > 2)
223 {
224 mykey = LOCAL_COPY(parv[2]);
4a2651e5 225 key = rb_strtok_r(mykey, ",", &p2);
212380e3
AC
226 }
227
4a2651e5
VY
228 for(name = rb_strtok_r(jbuf, ",", &p); name;
229 key = (key) ? rb_strtok_r(NULL, ",", &p2) : NULL, name = rb_strtok_r(NULL, ",", &p))
212380e3
AC
230 {
231 hook_data_channel_activity hook_info;
232
f4a80ce6
JT
233 /* JOIN 0 simply parts all channels the user is in */
234 if(*name == '0' && !atoi(name))
235 {
236 if(source_p->user->channel.head == NULL)
237 continue;
238
239 do_join_0(&me, source_p);
240 continue;
241 }
242
212380e3
AC
243 /* look for the channel */
244 if((chptr = find_channel(name)) != NULL)
245 {
246 if(IsMember(source_p, chptr))
247 continue;
248
249 flags = 0;
250 }
251 else
252 {
253 hook_data_client_approval moduledata;
254
255 moduledata.client = source_p;
256 moduledata.approved = 0;
257
258 call_hook(h_can_create_channel, &moduledata);
259
544cde90 260 if(moduledata.approved != 0)
212380e3 261 {
35bfe0e6
JT
262 if(moduledata.approved != ERR_CUSTOM)
263 send_join_error(source_p,
264 moduledata.approved,
265 name);
212380e3
AC
266 continue;
267 }
268
269 if(splitmode && !IsOper(source_p) && (*name != '&') &&
270 ConfigChannel.no_create_on_split)
271 {
272 sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
273 me.name, source_p->name, name);
274 continue;
275 }
276
277 flags = CHFL_CHANOP;
278 }
279
5b96d9a6 280 if((rb_dlink_list_length(&source_p->user->channel) >=
212380e3 281 (unsigned long) ConfigChannel.max_chans_per_user) &&
a4721f5e 282 (!IsExtendChans(source_p) ||
5b96d9a6 283 (rb_dlink_list_length(&source_p->user->channel) >=
a4721f5e 284 (unsigned long) ConfigChannel.max_chans_per_user_large)))
212380e3
AC
285 {
286 sendto_one(source_p, form_str(ERR_TOOMANYCHANNELS),
287 me.name, source_p->name, name);
cddbab51 288 continue;
212380e3
AC
289 }
290
212380e3
AC
291 if(chptr == NULL) /* If I already have a chptr, no point doing this */
292 {
293 chptr = get_or_create_channel(source_p, name, NULL);
294
295 if(chptr == NULL)
296 {
297 sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
298 me.name, source_p->name, name);
212380e3
AC
299 continue;
300 }
301 }
302
765d839d 303 /* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */
fc9013d6 304 if((chptr2 = check_forward(source_p, chptr, key, &i)) == NULL)
212380e3 305 {
765d839d
EM
306 /* might be wrong, but is there any other better location for such?
307 * see extensions/chm_operonly.c for other comments on this
308 * -- dwr
309 */
310 if(i != ERR_CUSTOM)
35bfe0e6 311 send_join_error(source_p, i, name);
765d839d 312 continue;
212380e3 313 }
765d839d
EM
314 else if(chptr != chptr2)
315 sendto_one_numeric(source_p, ERR_LINKCHANNEL, form_str(ERR_LINKCHANNEL), name, chptr2->chname);
316
317 chptr = chptr2;
212380e3 318
ff91faaf
JT
319 if(flags == 0 &&
320 !IsOper(source_p) && !IsExemptSpambot(source_p))
cf3564d6
JT
321 check_spambot_warning(source_p, name);
322
212380e3
AC
323 /* add the user to the channel */
324 add_user_to_channel(chptr, source_p, flags);
325 if (chptr->mode.join_num &&
e3354945 326 rb_current_time() - chptr->join_delta >= chptr->mode.join_time)
212380e3
AC
327 {
328 chptr->join_count = 0;
e3354945 329 chptr->join_delta = rb_current_time();
212380e3
AC
330 }
331 chptr->join_count++;
332
7e132ff0
KB
333 /* credit user for join */
334 credit_client_join(source_p);
335
212380e3
AC
336 /* we send the user their join here, because we could have to
337 * send a mode out next.
338 */
805cfa5a 339 send_channel_join(chptr, source_p);
212380e3
AC
340
341 /* its a new channel, set +nt and burst. */
342 if(flags & CHFL_CHANOP)
343 {
e3354945 344 chptr->channelts = rb_current_time();
63eb8567 345 chptr->mode.mode |= ConfigChannel.autochanmodes;
095efcf0 346 modes = channel_modes(chptr, &me);
212380e3 347
095efcf0
JT
348 sendto_channel_local(ONLY_CHANOPS, chptr, ":%s MODE %s %s",
349 me.name, chptr->chname, modes);
212380e3 350
db2545b1
JT
351 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
352 ":%s SJOIN %ld %s %s :@%s",
353 me.id, (long) chptr->channelts,
354 chptr->chname, modes, source_p->id);
212380e3
AC
355 }
356 else
357 {
212380e3 358 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
bee3b671 359 ":%s JOIN %ld %s +",
212380e3 360 use_id(source_p), (long) chptr->channelts,
bee3b671 361 chptr->chname);
212380e3
AC
362 }
363
364 del_invite(chptr, source_p);
365
366 if(chptr->topic != NULL)
367 {
368 sendto_one(source_p, form_str(RPL_TOPIC), me.name,
369 source_p->name, chptr->chname, chptr->topic);
370
371 sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
372 me.name, source_p->name, chptr->chname,
0cce01d3
JT
373 chptr->topic_info,
374 (unsigned long)chptr->topic_time);
212380e3
AC
375 }
376
377 channel_member_names(chptr, source_p, 1);
378
212380e3
AC
379 hook_info.client = source_p;
380 hook_info.chptr = chptr;
381 hook_info.key = key;
382 call_hook(h_channel_join, &hook_info);
383 }
212380e3
AC
384}
385
386/*
387 * ms_join
35835646
JT
388 * parv[1] = channel TS
389 * parv[2] = channel
390 * parv[3] = "+", formerly channel modes but now unused
391 * alternatively, a single "0" parameter parts all channels
212380e3 392 */
3c7d6fcc 393static void
428ca87b 394ms_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3 395{
95fff33c 396 static char modebuf[MODEBUFLEN];
2f0b6f83 397 static char parabuf[MODEBUFLEN];
212380e3 398 struct Channel *chptr;
bee3b671 399 static struct Mode mode;
212380e3
AC
400 time_t oldts;
401 time_t newts;
aa7eff28 402 bool isnew;
3c7d6fcc 403 bool keep_our_modes = true;
637c4932 404 rb_dlink_node *ptr, *next_ptr;
2077757f 405 char *mbuf;
212380e3 406
f4a80ce6
JT
407 /* special case for join 0 */
408 if((parv[1][0] == '0') && (parv[1][1] == '\0') && parc == 2)
409 {
410 do_join_0(client_p, source_p);
3c7d6fcc 411 return;
f4a80ce6
JT
412 }
413
212380e3 414 if(parc < 4)
3c7d6fcc 415 return;
212380e3
AC
416
417 if(!IsChannelName(parv[2]) || !check_channel_name(parv[2]))
3c7d6fcc 418 return;
212380e3
AC
419
420 /* joins for local channels cant happen. */
421 if(parv[2][0] == '&')
3c7d6fcc 422 return;
212380e3
AC
423
424 mbuf = modebuf;
425 mode.key[0] = mode.forward[0] = '\0';
426 mode.mode = mode.limit = mode.join_num = mode.join_time = 0;
427
212380e3 428 if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
3c7d6fcc 429 return;
212380e3
AC
430
431 newts = atol(parv[1]);
432 oldts = chptr->channelts;
212380e3 433
212380e3
AC
434 /* making a channel TS0 */
435 if(!isnew && !newts && oldts)
436 {
437 sendto_channel_local(ALL_MEMBERS, chptr,
438 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
439 me.name, chptr->chname, chptr->chname, (long) oldts);
440 sendto_realops_snomask(SNO_GENERAL, L_ALL,
441 "Server %s changing TS on %s from %ld to 0",
442 source_p->name, chptr->chname, (long) oldts);
443 }
212380e3
AC
444
445 if(isnew)
446 chptr->channelts = newts;
447 else if(newts == 0 || oldts == 0)
448 chptr->channelts = 0;
449 else if(newts == oldts)
450 ;
451 else if(newts < oldts)
452 {
3c7d6fcc 453 keep_our_modes = false;
212380e3
AC
454 chptr->channelts = newts;
455 }
212380e3 456
212380e3
AC
457 /* Lost the TS, other side wins, so remove modes on this side */
458 if(!keep_our_modes)
459 {
2f0b6f83 460 mbuf = set_final_mode(mbuf, parabuf, &mode, &chptr->mode);
bee3b671 461 chptr->mode = mode;
212380e3 462 remove_our_modes(chptr, source_p);
637c4932 463 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head)
212380e3
AC
464 {
465 del_invite(chptr, ptr->data);
466 }
bee3b671
JT
467 /* If setting -j, clear join throttle state -- jilles */
468 chptr->join_count = chptr->join_delta = 0;
212380e3
AC
469 sendto_channel_local(ALL_MEMBERS, chptr,
470 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
471 me.name, chptr->chname, chptr->chname,
472 (long) oldts, (long) newts);
1117fbd3
JT
473 /* Update capitalization in channel name, this makes the
474 * capitalization timestamped like modes are -- jilles */
475 strcpy(chptr->chname, parv[2]);
bee3b671
JT
476 if(*modebuf != '\0')
477 sendto_channel_local(ALL_MEMBERS, chptr,
478 ":%s MODE %s %s %s",
479 source_p->servptr->name,
480 chptr->chname, modebuf, parabuf);
481 *modebuf = *parabuf = '\0';
6fb6bd15
AC
482
483 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
07554369 484 set_channel_mlock(client_p, source_p, chptr, NULL, false);
212380e3
AC
485 }
486
212380e3
AC
487 if(!IsMember(source_p, chptr))
488 {
489 add_user_to_channel(chptr, source_p, CHFL_PEON);
490 if (chptr->mode.join_num &&
e3354945 491 rb_current_time() - chptr->join_delta >= chptr->mode.join_time)
212380e3
AC
492 {
493 chptr->join_count = 0;
e3354945 494 chptr->join_delta = rb_current_time();
212380e3
AC
495 }
496 chptr->join_count++;
805cfa5a 497 send_channel_join(chptr, source_p);
212380e3
AC
498 }
499
212380e3 500 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
bee3b671
JT
501 ":%s JOIN %ld %s +",
502 source_p->id, (long) chptr->channelts, chptr->chname);
212380e3
AC
503}
504
3c7d6fcc 505static void
428ca87b 506ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
8cc12805 507{
95fff33c 508 static char modebuf[MODEBUFLEN];
2f0b6f83 509 static char parabuf[MODEBUFLEN];
8cc12805
VY
510 static char buf_uid[BUFSIZE];
511 static const char empty_modes[] = "0";
512 struct Channel *chptr;
513 struct Client *target_p, *fakesource_p;
514 time_t newts;
515 time_t oldts;
516 static struct Mode mode, *oldmode;
517 const char *modes;
518 int args = 0;
3c7d6fcc
EM
519 bool keep_our_modes = true;
520 bool keep_new_modes = true;
8cc12805 521 int fl;
aa7eff28 522 bool isnew;
890423fb 523 int mlen_uid;
8cc12805
VY
524 int len_uid;
525 int len;
526 int joins = 0;
527 const char *s;
8cc12805
VY
528 char *ptr_uid;
529 char *p;
530 int i, joinc = 0, timeslice = 0;
531 static char empty[] = "";
532 rb_dlink_node *ptr, *next_ptr;
2077757f 533 char *mbuf;
7fce9c6d 534 int pargs;
b051b0ef 535 const char *para[MAXMODEPARAMS];
8cc12805 536
b733b9fa 537 if(parc < 5)
3c7d6fcc 538 return;
b733b9fa 539
8cc12805 540 if(!IsChannelName(parv[2]) || !check_channel_name(parv[2]))
3c7d6fcc 541 return;
8cc12805
VY
542
543 /* SJOIN's for local channels can't happen. */
544 if(*parv[2] == '&')
3c7d6fcc 545 return;
8cc12805
VY
546
547 modebuf[0] = parabuf[0] = mode.key[0] = mode.forward[0] = '\0';
548 pargs = mode.mode = mode.limit = mode.join_num = mode.join_time = 0;
549
550 /* Hide connecting server on netburst -- jilles */
551 if (ConfigServerHide.flatten_links && !HasSentEob(source_p))
552 fakesource_p = &me;
553 else
554 fakesource_p = source_p;
555
556 mbuf = modebuf;
557 newts = atol(parv[1]);
558
559 s = parv[3];
560 while (*s)
561 {
562 switch (*(s++))
563 {
8cc12805 564 case 'f':
f427c8b0 565 rb_strlcpy(mode.forward, parv[4 + args], sizeof(mode.forward));
8cc12805
VY
566 args++;
567 if(parc < 5 + args)
3c7d6fcc 568 return;
8cc12805
VY
569 break;
570 case 'j':
571 sscanf(parv[4 + args], "%d:%d", &joinc, &timeslice);
572 args++;
573 mode.join_num = joinc;
574 mode.join_time = timeslice;
575 if(parc < 5 + args)
3c7d6fcc 576 return;
8cc12805
VY
577 break;
578 case 'k':
f427c8b0 579 rb_strlcpy(mode.key, parv[4 + args], sizeof(mode.key));
8cc12805
VY
580 args++;
581 if(parc < 5 + args)
3c7d6fcc 582 return;
8cc12805
VY
583 break;
584 case 'l':
585 mode.limit = atoi(parv[4 + args]);
586 args++;
587 if(parc < 5 + args)
3c7d6fcc 588 return;
8cc12805 589 break;
efccc22c
VY
590 default:
591 if(chmode_flags[(int) *s] != 0)
592 {
593 mode.mode |= chmode_flags[(int) *s];
594 }
8cc12805
VY
595 }
596 }
597
598 if(parv[args + 4])
599 {
600 s = parv[args + 4];
601
602 /* remove any leading spaces */
603 while (*s == ' ')
604 s++;
605 }
606 else
607 s = "";
608
609 if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
3c7d6fcc 610 return; /* channel name too long? */
8cc12805
VY
611
612
613 oldts = chptr->channelts;
614 oldmode = &chptr->mode;
615
8cc12805
VY
616 if(!isnew && !newts && oldts)
617 {
618 sendto_channel_local(ALL_MEMBERS, chptr,
619 ":%s NOTICE %s :*** Notice -- TS for %s "
620 "changed from %ld to 0",
621 me.name, chptr->chname, chptr->chname, (long) oldts);
622 sendto_realops_snomask(SNO_GENERAL, L_ALL,
623 "Server %s changing TS on %s from %ld to 0",
624 source_p->name, chptr->chname, (long) oldts);
625 }
8cc12805
VY
626
627 if(isnew)
628 chptr->channelts = newts;
55abcbb2 629
8cc12805
VY
630 else if(newts == 0 || oldts == 0)
631 chptr->channelts = 0;
632 else if(newts == oldts)
633 ;
634 else if(newts < oldts)
635 {
636 /* If configured, kick people trying to join +i/+k
637 * channels by recreating them on split servers.
a1574df4
JT
638 * If the source has sent EOB, assume this is some
639 * sort of hack by services. If cmode +i is set,
640 * services can send kicks if needed; if the key
641 * differs, services cannot kick in a race-free
642 * manner so do so here.
8cc12805
VY
643 * -- jilles */
644 if (ConfigChannel.kick_on_split_riding &&
a1574df4
JT
645 ((!HasSentEob(source_p) &&
646 mode.mode & MODE_INVITEONLY) ||
8cc12805
VY
647 (mode.key[0] != 0 && irccmp(mode.key, oldmode->key) != 0)))
648 {
649 struct membership *msptr;
650 struct Client *who;
651 int l = rb_dlink_list_length(&chptr->members);
8cc12805
VY
652
653 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
654 {
655 msptr = ptr->data;
656 who = msptr->client_p;
657 sendto_one(who, ":%s KICK %s %s :Net Rider",
658 me.name, chptr->chname, who->name);
659
660 sendto_server(NULL, chptr, CAP_TS6, NOCAPS,
661 ":%s KICK %s %s :Net Rider",
662 me.id, chptr->chname,
663 who->id);
8cc12805
VY
664 remove_user_from_channel(msptr);
665 if (--l == 0)
666 break;
667 }
668 if (l == 0)
669 {
670 /* Channel was emptied, create a new one */
671 if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
3c7d6fcc 672 return; /* oops! */
8cc12805 673
8cc12805
VY
674 oldmode = &chptr->mode;
675 }
676 }
3c7d6fcc 677 keep_our_modes = false;
8cc12805
VY
678 chptr->channelts = newts;
679 }
680 else
3c7d6fcc 681 keep_new_modes = false;
8cc12805
VY
682
683 if(!keep_new_modes)
684 mode = *oldmode;
685 else if(keep_our_modes)
686 {
687 mode.mode |= oldmode->mode;
688 if(oldmode->limit > mode.limit)
689 mode.limit = oldmode->limit;
690 if(strcmp(mode.key, oldmode->key) < 0)
4d5a902f 691 rb_strlcpy(mode.key, oldmode->key, sizeof(mode.key));
8cc12805
VY
692 if(oldmode->join_num > mode.join_num ||
693 (oldmode->join_num == mode.join_num &&
694 oldmode->join_time > mode.join_time))
695 {
696 mode.join_num = oldmode->join_num;
697 mode.join_time = oldmode->join_time;
698 }
699 if(irccmp(mode.forward, oldmode->forward) < 0)
4d5a902f 700 rb_strlcpy(mode.forward, oldmode->forward, sizeof(mode.forward));
8cc12805
VY
701 }
702 else
703 {
704 /* If setting -j, clear join throttle state -- jilles */
705 if (!mode.join_num)
706 chptr->join_count = chptr->join_delta = 0;
707 }
708
2f0b6f83 709 mbuf = set_final_mode(mbuf, parabuf, &mode, oldmode);
8cc12805
VY
710 chptr->mode = mode;
711
712 /* Lost the TS, other side wins, so remove modes on this side */
713 if(!keep_our_modes)
714 {
715 remove_our_modes(chptr, fakesource_p);
716 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head)
717 {
718 del_invite(chptr, ptr->data);
719 }
7b22c84f
JT
720
721 if(rb_dlink_list_length(&chptr->banlist) > 0)
722 remove_ban_list(chptr, fakesource_p, &chptr->banlist, 'b', ALL_MEMBERS);
723 if(rb_dlink_list_length(&chptr->exceptlist) > 0)
724 remove_ban_list(chptr, fakesource_p, &chptr->exceptlist,
725 'e', ONLY_CHANOPS);
726 if(rb_dlink_list_length(&chptr->invexlist) > 0)
727 remove_ban_list(chptr, fakesource_p, &chptr->invexlist,
728 'I', ONLY_CHANOPS);
729 if(rb_dlink_list_length(&chptr->quietlist) > 0)
730 remove_ban_list(chptr, fakesource_p, &chptr->quietlist,
731 'q', ALL_MEMBERS);
732 chptr->bants++;
733
8cc12805
VY
734 sendto_channel_local(ALL_MEMBERS, chptr,
735 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
736 me.name, chptr->chname, chptr->chname,
737 (long) oldts, (long) newts);
738 /* Update capitalization in channel name, this makes the
739 * capitalization timestamped like modes are -- jilles */
740 strcpy(chptr->chname, parv[2]);
6fb6bd15
AC
741
742 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
07554369 743 set_channel_mlock(client_p, source_p, chptr, NULL, false);
8cc12805
VY
744 }
745
746 if(*modebuf != '\0')
747 sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s %s %s",
748 fakesource_p->name, chptr->chname, modebuf, parabuf);
749
750 *modebuf = *parabuf = '\0';
751
752 if(parv[3][0] != '0' && keep_new_modes)
753 modes = channel_modes(chptr, source_p);
754 else
755 modes = empty_modes;
756
5203cba5 757 mlen_uid = sprintf(buf_uid, ":%s SJOIN %ld %s %s :",
8cc12805
VY
758 use_id(source_p), (long) chptr->channelts, parv[2], modes);
759 ptr_uid = buf_uid + mlen_uid;
760
761 mbuf = modebuf;
762 para[0] = para[1] = para[2] = para[3] = empty;
763 pargs = 0;
40709472 764 len_uid = 0;
8cc12805
VY
765
766 /* if theres a space, theres going to be more than one nick, change the
767 * first space to \0, so s is just the first nick, and point p to the
768 * second nick
769 */
770 if((p = strchr(s, ' ')) != NULL)
771 {
772 *p++ = '\0';
773 }
774
775 *mbuf++ = '+';
776
777 while (s)
778 {
779 fl = 0;
780
781 for (i = 0; i < 2; i++)
782 {
783 if(*s == '@')
784 {
785 fl |= CHFL_CHANOP;
786 s++;
787 }
788 else if(*s == '+')
789 {
790 fl |= CHFL_VOICE;
791 s++;
792 }
793 }
794
795 /* if the client doesnt exist or is fake direction, skip. */
796 if(!(target_p = find_client(s)) ||
797 (target_p->from != client_p) || !IsPerson(target_p))
798 goto nextnick;
799
800 /* we assume for these we can fit at least one nick/uid in.. */
801
802 /* check we can fit another status+nick+space into a buffer */
8cc12805
VY
803 if((mlen_uid + len_uid + IDLEN + 3) > (BUFSIZE - 3))
804 {
805 *(ptr_uid - 1) = '\0';
806 sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid);
807 ptr_uid = buf_uid + mlen_uid;
808 len_uid = 0;
809 }
810
811 if(keep_new_modes)
812 {
813 if(fl & CHFL_CHANOP)
814 {
8cc12805 815 *ptr_uid++ = '@';
8cc12805
VY
816 len_uid++;
817 }
818 if(fl & CHFL_VOICE)
819 {
8cc12805 820 *ptr_uid++ = '+';
8cc12805
VY
821 len_uid++;
822 }
823 }
824
825 /* copy the nick to the two buffers */
5203cba5 826 len = sprintf(ptr_uid, "%s ", use_id(target_p));
8cc12805
VY
827 ptr_uid += len;
828 len_uid += len;
829
830 if(!keep_new_modes)
831 fl = 0;
832
833 if(!IsMember(target_p, chptr))
834 {
835 add_user_to_channel(chptr, target_p, fl);
805cfa5a 836 send_channel_join(chptr, target_p);
8cc12805
VY
837 joins++;
838 }
839
840 if(fl & CHFL_CHANOP)
841 {
842 *mbuf++ = 'o';
843 para[pargs++] = target_p->name;
844
845 /* a +ov user.. bleh */
846 if(fl & CHFL_VOICE)
847 {
848 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
849 * a new buffer
850 */
851 if(pargs >= MAXMODEPARAMS)
852 {
853 *mbuf = '\0';
854 sendto_channel_local(ALL_MEMBERS, chptr,
855 ":%s MODE %s %s %s %s %s %s",
856 fakesource_p->name, chptr->chname,
857 modebuf,
858 para[0], para[1], para[2], para[3]);
859 mbuf = modebuf;
860 *mbuf++ = '+';
861 para[0] = para[1] = para[2] = para[3] = NULL;
862 pargs = 0;
863 }
864
865 *mbuf++ = 'v';
866 para[pargs++] = target_p->name;
867 }
868 }
869 else if(fl & CHFL_VOICE)
870 {
871 *mbuf++ = 'v';
872 para[pargs++] = target_p->name;
873 }
874
875 if(pargs >= MAXMODEPARAMS)
876 {
877 *mbuf = '\0';
878 sendto_channel_local(ALL_MEMBERS, chptr,
879 ":%s MODE %s %s %s %s %s %s",
880 fakesource_p->name,
881 chptr->chname,
882 modebuf, para[0], para[1], para[2], para[3]);
883 mbuf = modebuf;
884 *mbuf++ = '+';
885 para[0] = para[1] = para[2] = para[3] = NULL;
886 pargs = 0;
887 }
888
889 nextnick:
890 /* p points to the next nick */
891 s = p;
892
893 /* if there was a trailing space and p was pointing to it, then we
894 * need to exit.. this has the side effect of breaking double spaces
895 * in an sjoin.. but that shouldnt happen anyway
896 */
897 if(s && (*s == '\0'))
898 s = p = NULL;
899
900 /* if p was NULL due to no spaces, s wont exist due to the above, so
901 * we cant check it for spaces.. if there are no spaces, then when
902 * we next get here, s will be NULL
903 */
904 if(s && ((p = strchr(s, ' ')) != NULL))
905 {
906 *p++ = '\0';
907 }
908 }
909
910 *mbuf = '\0';
911 if(pargs)
912 {
913 sendto_channel_local(ALL_MEMBERS, chptr,
914 ":%s MODE %s %s %s %s %s %s",
915 fakesource_p->name, chptr->chname, modebuf,
916 para[0], CheckEmpty(para[1]),
917 CheckEmpty(para[2]), CheckEmpty(para[3]));
918 }
919
920 if(!joins && !(chptr->mode.mode & MODE_PERMANENT) && isnew)
921 {
922 destroy_channel(chptr);
923
3c7d6fcc 924 return;
8cc12805
VY
925 }
926
927 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
928 if (joins)
929 {
8cc12805
VY
930 *(ptr_uid - 1) = '\0';
931 }
932
933 sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid);
8cc12805
VY
934}
935
f4a80ce6
JT
936/*
937 * do_join_0
938 *
939 * inputs - pointer to client doing join 0
940 * output - NONE
941 * side effects - Use has decided to join 0. This is legacy
942 * from the days when channels were numbers not names. *sigh*
f4a80ce6
JT
943 */
944static void
945do_join_0(struct Client *client_p, struct Client *source_p)
946{
947 struct membership *msptr;
948 struct Channel *chptr = NULL;
5b96d9a6 949 rb_dlink_node *ptr;
f4a80ce6
JT
950
951 /* Finish the flood grace period... */
952 if(MyClient(source_p) && !IsFloodDone(source_p))
953 flood_endgrace(source_p);
954
f4a80ce6 955 sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s JOIN 0", use_id(source_p));
f4a80ce6 956
f4a80ce6
JT
957 while((ptr = source_p->user->channel.head))
958 {
4eb9a3ca
JT
959 if(MyConnect(source_p) &&
960 !IsOper(source_p) && !IsExemptSpambot(source_p))
961 check_spambot_warning(source_p, NULL);
962
f4a80ce6
JT
963 msptr = ptr->data;
964 chptr = msptr->chptr;
965 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s",
966 source_p->name,
967 source_p->username, source_p->host, chptr->chname);
968 remove_user_from_channel(msptr);
969 }
970}
971
3c7d6fcc 972static bool
212380e3
AC
973check_channel_name_loc(struct Client *source_p, const char *name)
974{
6865c0b0
JT
975 const char *p;
976
212380e3
AC
977 s_assert(name != NULL);
978 if(EmptyString(name))
3c7d6fcc 979 return false;
212380e3
AC
980
981 if(ConfigFileEntry.disable_fake_channels && !IsOper(source_p))
982 {
6865c0b0 983 for(p = name; *p; ++p)
212380e3 984 {
6865c0b0 985 if(!IsChanChar(*p) || IsFakeChanChar(*p))
3c7d6fcc 986 return false;
212380e3
AC
987 }
988 }
989 else
990 {
6865c0b0 991 for(p = name; *p; ++p)
212380e3 992 {
6865c0b0 993 if(!IsChanChar(*p))
3c7d6fcc 994 return false;
212380e3
AC
995 }
996 }
997
6865c0b0
JT
998 if(ConfigChannel.only_ascii_channels)
999 {
1000 for(p = name; *p; ++p)
1001 if(*p < 33 || *p > 126)
3c7d6fcc 1002 return false;
6865c0b0
JT
1003 }
1004
3c7d6fcc 1005 return true;
212380e3
AC
1006}
1007
35bfe0e6
JT
1008/* send_join_error()
1009 *
1010 * input - client to send to, reason, channel name
1011 * output - none
1012 * side effects - error message sent to client
1013 */
1014static void
1015send_join_error(struct Client *source_p, int numeric, const char *name)
1016{
1017 /* This stuff is necessary because the form_str macro only
1018 * accepts constants.
1019 */
1020 switch (numeric)
1021 {
1022#define NORMAL_NUMERIC(i) \
1023 case i: \
1024 sendto_one(source_p, form_str(i), \
1025 me.name, source_p->name, name); \
1026 break
1027
1028 NORMAL_NUMERIC(ERR_BANNEDFROMCHAN);
1029 NORMAL_NUMERIC(ERR_INVITEONLYCHAN);
1030 NORMAL_NUMERIC(ERR_BADCHANNELKEY);
1031 NORMAL_NUMERIC(ERR_CHANNELISFULL);
1032 NORMAL_NUMERIC(ERR_NEEDREGGEDNICK);
1033 NORMAL_NUMERIC(ERR_THROTTLE);
1034
1035 default:
1036 sendto_one_numeric(source_p, numeric,
1037 "%s :Cannot join channel", name);
1038 break;
1039 }
1040}
1041
2077757f 1042static char *
2f0b6f83 1043set_final_mode(char *mbuf, char *parabuf, struct Mode *mode, struct Mode *oldmode)
212380e3
AC
1044{
1045 int dir = MODE_QUERY;
1046 char *pbuf = parabuf;
1047 int len;
1048 int i;
1049
1050 /* ok, first get a list of modes we need to add */
efccc22c 1051 for (i = 0; i < 256; i++)
212380e3 1052 {
efccc22c 1053 if((mode->mode & chmode_flags[i]) && !(oldmode->mode & chmode_flags[i]))
212380e3
AC
1054 {
1055 if(dir != MODE_ADD)
1056 {
1057 *mbuf++ = '+';
1058 dir = MODE_ADD;
1059 }
efccc22c 1060 *mbuf++ = i;
212380e3
AC
1061 }
1062 }
1063
1064 /* now the ones we need to remove. */
efccc22c 1065 for (i = 0; i < 256; i++)
212380e3 1066 {
efccc22c 1067 if((oldmode->mode & chmode_flags[i]) && !(mode->mode & chmode_flags[i]))
212380e3
AC
1068 {
1069 if(dir != MODE_DEL)
1070 {
1071 *mbuf++ = '-';
1072 dir = MODE_DEL;
1073 }
efccc22c 1074 *mbuf++ = i;
212380e3
AC
1075 }
1076 }
1077
1078 if(oldmode->limit && !mode->limit)
1079 {
1080 if(dir != MODE_DEL)
1081 {
1082 *mbuf++ = '-';
1083 dir = MODE_DEL;
1084 }
1085 *mbuf++ = 'l';
1086 }
1087 if(oldmode->key[0] && !mode->key[0])
1088 {
1089 if(dir != MODE_DEL)
1090 {
1091 *mbuf++ = '-';
1092 dir = MODE_DEL;
1093 }
1094 *mbuf++ = 'k';
5203cba5 1095 len = sprintf(pbuf, "%s ", oldmode->key);
212380e3
AC
1096 pbuf += len;
1097 }
1098 if(oldmode->join_num && !mode->join_num)
1099 {
1100 if(dir != MODE_DEL)
1101 {
1102 *mbuf++ = '-';
1103 dir = MODE_DEL;
1104 }
1105 *mbuf++ = 'j';
1106 }
1107 if(oldmode->forward[0] && !mode->forward[0])
1108 {
1109 if(dir != MODE_DEL)
1110 {
1111 *mbuf++ = '-';
1112 dir = MODE_DEL;
1113 }
1114 *mbuf++ = 'f';
1115 }
1116 if(mode->limit && oldmode->limit != mode->limit)
1117 {
1118 if(dir != MODE_ADD)
1119 {
1120 *mbuf++ = '+';
1121 dir = MODE_ADD;
1122 }
1123 *mbuf++ = 'l';
5203cba5 1124 len = sprintf(pbuf, "%d ", mode->limit);
212380e3
AC
1125 pbuf += len;
1126 }
1127 if(mode->key[0] && strcmp(oldmode->key, mode->key))
1128 {
1129 if(dir != MODE_ADD)
1130 {
1131 *mbuf++ = '+';
1132 dir = MODE_ADD;
1133 }
1134 *mbuf++ = 'k';
5203cba5 1135 len = sprintf(pbuf, "%s ", mode->key);
212380e3
AC
1136 pbuf += len;
1137 }
1138 if(mode->join_num && (oldmode->join_num != mode->join_num || oldmode->join_time != mode->join_time))
1139 {
1140 if(dir != MODE_ADD)
1141 {
1142 *mbuf++ = '+';
1143 dir = MODE_ADD;
1144 }
1145 *mbuf++ = 'j';
5203cba5 1146 len = sprintf(pbuf, "%d:%d ", mode->join_num, mode->join_time);
212380e3
AC
1147 pbuf += len;
1148 }
2da6f6eb
JT
1149 if(mode->forward[0] && strcmp(oldmode->forward, mode->forward) &&
1150 ConfigChannel.use_forward)
212380e3
AC
1151 {
1152 if(dir != MODE_ADD)
1153 {
1154 *mbuf++ = '+';
1155 dir = MODE_ADD;
1156 }
1157 *mbuf++ = 'f';
5203cba5 1158 len = sprintf(pbuf, "%s ", mode->forward);
212380e3
AC
1159 pbuf += len;
1160 }
1161 *mbuf = '\0';
2077757f
SA
1162
1163 return mbuf;
212380e3
AC
1164}
1165
1166/*
1167 * remove_our_modes
1168 *
1169 * inputs -
55abcbb2
KB
1170 * output -
1171 * side effects -
212380e3
AC
1172 */
1173static void
1174remove_our_modes(struct Channel *chptr, struct Client *source_p)
1175{
1176 struct membership *msptr;
5b96d9a6 1177 rb_dlink_node *ptr;
212380e3
AC
1178 char lmodebuf[MODEBUFLEN];
1179 char *lpara[MAXMODEPARAMS];
1180 int count = 0;
1181 int i;
2077757f 1182 char *mbuf = lmodebuf;
212380e3 1183
212380e3
AC
1184 *mbuf++ = '-';
1185
1186 for(i = 0; i < MAXMODEPARAMS; i++)
1187 lpara[i] = NULL;
1188
5b96d9a6 1189 RB_DLINK_FOREACH(ptr, chptr->members.head)
212380e3
AC
1190 {
1191 msptr = ptr->data;
1192
1193 if(is_chanop(msptr))
1194 {
1195 msptr->flags &= ~CHFL_CHANOP;
1196 lpara[count++] = msptr->client_p->name;
1197 *mbuf++ = 'o';
1198
1199 /* +ov, might not fit so check. */
1200 if(is_voiced(msptr))
1201 {
1202 if(count >= MAXMODEPARAMS)
1203 {
1204 *mbuf = '\0';
1205 sendto_channel_local(ALL_MEMBERS, chptr,
1206 ":%s MODE %s %s %s %s %s %s",
7bf78de0 1207 source_p->name, chptr->chname,
212380e3
AC
1208 lmodebuf, lpara[0], lpara[1],
1209 lpara[2], lpara[3]);
1210
1211 /* preserve the initial '-' */
1212 mbuf = lmodebuf;
1213 *mbuf++ = '-';
1214 count = 0;
1215
1216 for(i = 0; i < MAXMODEPARAMS; i++)
1217 lpara[i] = NULL;
1218 }
1219
1220 msptr->flags &= ~CHFL_VOICE;
1221 lpara[count++] = msptr->client_p->name;
1222 *mbuf++ = 'v';
1223 }
1224 }
1225 else if(is_voiced(msptr))
1226 {
1227 msptr->flags &= ~CHFL_VOICE;
1228 lpara[count++] = msptr->client_p->name;
1229 *mbuf++ = 'v';
1230 }
1231 else
1232 continue;
1233
1234 if(count >= MAXMODEPARAMS)
1235 {
1236 *mbuf = '\0';
1237 sendto_channel_local(ALL_MEMBERS, chptr,
1238 ":%s MODE %s %s %s %s %s %s",
7bf78de0 1239 source_p->name, chptr->chname, lmodebuf,
212380e3
AC
1240 lpara[0], lpara[1], lpara[2], lpara[3]);
1241 mbuf = lmodebuf;
1242 *mbuf++ = '-';
1243 count = 0;
1244
1245 for(i = 0; i < MAXMODEPARAMS; i++)
1246 lpara[i] = NULL;
1247 }
1248 }
1249
1250 if(count != 0)
1251 {
1252 *mbuf = '\0';
1253 sendto_channel_local(ALL_MEMBERS, chptr,
1254 ":%s MODE %s %s %s %s %s %s",
7bf78de0 1255 source_p->name, chptr->chname, lmodebuf,
212380e3
AC
1256 EmptyString(lpara[0]) ? "" : lpara[0],
1257 EmptyString(lpara[1]) ? "" : lpara[1],
1258 EmptyString(lpara[2]) ? "" : lpara[2],
1259 EmptyString(lpara[3]) ? "" : lpara[3]);
1260
1261 }
1262}
8cc12805
VY
1263
1264/* remove_ban_list()
1265 *
1266 * inputs - channel, source, list to remove, char of mode, caps needed
1267 * outputs -
1268 * side effects - given list is removed, with modes issued to local clients
8cc12805
VY
1269 */
1270static void
1271remove_ban_list(struct Channel *chptr, struct Client *source_p,
8afeb720 1272 rb_dlink_list * list, char c, int mems)
8cc12805
VY
1273{
1274 static char lmodebuf[BUFSIZE];
1275 static char lparabuf[BUFSIZE];
1276 struct Ban *banptr;
1277 rb_dlink_node *ptr;
1278 rb_dlink_node *next_ptr;
1279 char *pbuf;
1280 int count = 0;
1281 int cur_len, mlen, plen;
2077757f 1282 char *mbuf;
8cc12805
VY
1283
1284 pbuf = lparabuf;
1285
5203cba5 1286 cur_len = mlen = sprintf(lmodebuf, ":%s MODE %s -", source_p->name, chptr->chname);
8cc12805
VY
1287 mbuf = lmodebuf + mlen;
1288
1289 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
1290 {
1291 banptr = ptr->data;
1292
1293 /* trailing space, and the mode letter itself */
23f6b63a
JT
1294 plen = strlen(banptr->banstr) +
1295 (banptr->forward ? strlen(banptr->forward) + 1 : 0) + 2;
8cc12805
VY
1296
1297 if(count >= MAXMODEPARAMS || (cur_len + plen) > BUFSIZE - 4)
1298 {
1299 /* remove trailing space */
1300 *mbuf = '\0';
1301 *(pbuf - 1) = '\0';
1302
1303 sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf);
8cc12805
VY
1304
1305 cur_len = mlen;
1306 mbuf = lmodebuf + mlen;
1307 pbuf = lparabuf;
1308 count = 0;
1309 }
1310
1311 *mbuf++ = c;
1312 cur_len += plen;
23f6b63a 1313 if (banptr->forward)
5203cba5 1314 pbuf += sprintf(pbuf, "%s$%s ", banptr->banstr, banptr->forward);
23f6b63a 1315 else
5203cba5 1316 pbuf += sprintf(pbuf, "%s ", banptr->banstr);
8cc12805
VY
1317 count++;
1318
1319 free_ban(banptr);
1320 }
1321
1322 *mbuf = '\0';
1323 *(pbuf - 1) = '\0';
1324 sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf);
8cc12805
VY
1325
1326 list->head = list->tail = NULL;
1327 list->length = 0;
1328}