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