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