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