]>
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" |
77d3d2db | 45 | #include "s_assert.h" |
212380e3 AC |
46 | |
47 | static int m_join(struct Client *, struct Client *, int, const char **); | |
48 | static int ms_join(struct Client *, struct Client *, int, const char **); | |
8cc12805 | 49 | static int ms_sjoin(struct Client *, struct Client *, int, const char **); |
212380e3 AC |
50 | |
51 | static int h_can_create_channel; | |
52 | static int h_channel_join; | |
53 | ||
54 | struct Message join_msgtab = { | |
55 | "JOIN", 0, 0, 0, MFLG_SLOW, | |
56 | {mg_unreg, {m_join, 2}, {ms_join, 2}, mg_ignore, mg_ignore, {m_join, 2}} | |
57 | }; | |
58 | ||
8cc12805 VY |
59 | struct Message sjoin_msgtab = { |
60 | "SJOIN", 0, 0, 0, MFLG_SLOW, | |
1766edef | 61 | {mg_unreg, mg_ignore, mg_ignore, {ms_sjoin, 4}, mg_ignore, mg_ignore} |
8cc12805 VY |
62 | }; |
63 | ||
64 | mapi_clist_av1 join_clist[] = { &join_msgtab, &sjoin_msgtab, NULL }; | |
212380e3 AC |
65 | |
66 | mapi_hlist_av1 join_hlist[] = { | |
67 | { "can_create_channel", &h_can_create_channel }, | |
68 | { "channel_join", &h_channel_join }, | |
69 | { NULL, NULL }, | |
70 | }; | |
71 | ||
f4a80ce6 | 72 | DECLARE_MODULE_AV1(join, NULL, NULL, join_clist, join_hlist, NULL, "$Revision: 3494 $"); |
212380e3 | 73 | |
f4a80ce6 | 74 | static void do_join_0(struct Client *client_p, struct Client *source_p); |
212380e3 | 75 | static int check_channel_name_loc(struct Client *source_p, const char *name); |
35bfe0e6 | 76 | static void send_join_error(struct Client *source_p, int numeric, const char *name); |
212380e3 AC |
77 | |
78 | static void set_final_mode(struct Mode *mode, struct Mode *oldmode); | |
79 | static void remove_our_modes(struct Channel *chptr, struct Client *source_p); | |
80 | ||
8cc12805 | 81 | static void remove_ban_list(struct Channel *chptr, struct Client *source_p, |
8afeb720 | 82 | rb_dlink_list * list, char c, int mems); |
8cc12805 | 83 | |
212380e3 AC |
84 | static char modebuf[MODEBUFLEN]; |
85 | static char parabuf[MODEBUFLEN]; | |
8cc12805 | 86 | static const char *para[MAXMODEPARAMS]; |
212380e3 | 87 | static char *mbuf; |
8cc12805 | 88 | static int pargs; |
212380e3 AC |
89 | |
90 | /* Check what we will forward to, without sending any notices to the user | |
91 | * -- jilles | |
92 | */ | |
93 | static struct Channel * | |
94 | check_forward(struct Client *source_p, struct Channel *chptr, | |
765d839d | 95 | char *key, int *err) |
212380e3 AC |
96 | { |
97 | int depth = 0, i; | |
d9af501a | 98 | const char *next = NULL; |
765d839d EM |
99 | |
100 | /* The caller (m_join) is only interested in the reason | |
101 | * for the original channel. | |
102 | */ | |
103 | if ((*err = can_join(source_p, chptr, key, &next)) == 0) | |
104 | return chptr; | |
212380e3 | 105 | |
6a85e665 JT |
106 | /* User is +Q, or forwarding disabled */ |
107 | if (IsNoForward(source_p) || !ConfigChannel.use_forward) | |
212380e3 AC |
108 | return NULL; |
109 | ||
110 | while (depth < 16) | |
111 | { | |
97532cfa JT |
112 | if (next == NULL) |
113 | return NULL; | |
765d839d | 114 | chptr = find_channel(next); |
212380e3 AC |
115 | /* Can only forward to existing channels */ |
116 | if (chptr == NULL) | |
117 | return NULL; | |
118 | /* Already on there, show original error message */ | |
119 | if (IsMember(source_p, chptr)) | |
120 | return NULL; | |
121 | /* Juped. Sending a warning notice would be unfair */ | |
122 | if (hash_find_resv(chptr->chname)) | |
123 | return NULL; | |
124 | /* Don't forward to +Q channel */ | |
125 | if (chptr->mode.mode & MODE_DISFORWARD) | |
126 | return NULL; | |
765d839d | 127 | i = can_join(source_p, chptr, key, &next); |
212380e3 AC |
128 | if (i == 0) |
129 | return chptr; | |
212380e3 AC |
130 | depth++; |
131 | } | |
132 | ||
133 | return NULL; | |
134 | } | |
135 | ||
136 | /* | |
137 | * m_join | |
212380e3 AC |
138 | * parv[1] = channel |
139 | * parv[2] = channel password (key) | |
140 | */ | |
141 | static int | |
142 | m_join(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
143 | { | |
144 | static char jbuf[BUFSIZE]; | |
765d839d | 145 | struct Channel *chptr = NULL, *chptr2 = NULL; |
212380e3 AC |
146 | struct ConfItem *aconf; |
147 | char *name; | |
148 | char *key = NULL; | |
095efcf0 | 149 | const char *modes; |
212380e3 AC |
150 | int i, flags = 0; |
151 | char *p = NULL, *p2 = NULL; | |
152 | char *chanlist; | |
153 | char *mykey; | |
212380e3 AC |
154 | |
155 | jbuf[0] = '\0'; | |
156 | ||
157 | /* rebuild the list of channels theyre supposed to be joining. | |
158 | * this code has a side effect of losing keys, but.. | |
159 | */ | |
160 | chanlist = LOCAL_COPY(parv[1]); | |
4a2651e5 | 161 | for(name = rb_strtok_r(chanlist, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) |
212380e3 AC |
162 | { |
163 | /* check the length and name of channel is ok */ | |
164 | if(!check_channel_name_loc(source_p, name) || (strlen(name) > LOC_CHANNELLEN)) | |
165 | { | |
166 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
167 | form_str(ERR_BADCHANNAME), (unsigned char *) name); | |
168 | continue; | |
169 | } | |
170 | ||
f4a80ce6 JT |
171 | /* join 0 parts all channels */ |
172 | if(*name == '0' && (name[1] == ',' || name[1] == '\0') && name == chanlist) | |
173 | { | |
174 | (void) strcpy(jbuf, "0"); | |
175 | continue; | |
176 | } | |
177 | ||
212380e3 | 178 | /* check it begins with # or &, and local chans are disabled */ |
341f971e SB |
179 | else if(!IsChannelName(name) || |
180 | ( ConfigChannel.disable_local_channels && name[0] == '&')) | |
212380e3 AC |
181 | { |
182 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
183 | form_str(ERR_NOSUCHCHANNEL), name); | |
184 | continue; | |
185 | } | |
186 | ||
187 | /* see if its resv'd */ | |
188 | if(!IsExemptResv(source_p) && (aconf = hash_find_resv(name))) | |
189 | { | |
190 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
191 | form_str(ERR_BADCHANNAME), name); | |
192 | ||
193 | /* dont warn for opers */ | |
194 | if(!IsExemptJupe(source_p) && !IsOper(source_p)) | |
195 | sendto_realops_snomask(SNO_SPY, L_NETWIDE, | |
196 | "User %s (%s@%s) is attempting to join locally juped channel %s (%s)", | |
197 | source_p->name, source_p->username, | |
63aecfb9 | 198 | source_p->orighost, name, aconf->passwd); |
212380e3 AC |
199 | /* dont update tracking for jupe exempt users, these |
200 | * are likely to be spamtrap leaves | |
201 | */ | |
202 | else if(IsExemptJupe(source_p)) | |
203 | aconf->port--; | |
204 | ||
205 | continue; | |
206 | } | |
207 | ||
208 | if(splitmode && !IsOper(source_p) && (*name != '&') && | |
209 | ConfigChannel.no_join_on_split) | |
210 | { | |
211 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
212 | me.name, source_p->name, name); | |
213 | continue; | |
214 | } | |
215 | ||
216 | if(*jbuf) | |
217 | (void) strcat(jbuf, ","); | |
1f9de103 | 218 | (void) rb_strlcat(jbuf, name, sizeof(jbuf)); |
212380e3 AC |
219 | } |
220 | ||
221 | if(parc > 2) | |
222 | { | |
223 | mykey = LOCAL_COPY(parv[2]); | |
4a2651e5 | 224 | key = rb_strtok_r(mykey, ",", &p2); |
212380e3 AC |
225 | } |
226 | ||
4a2651e5 VY |
227 | for(name = rb_strtok_r(jbuf, ",", &p); name; |
228 | key = (key) ? rb_strtok_r(NULL, ",", &p2) : NULL, name = rb_strtok_r(NULL, ",", &p)) | |
212380e3 AC |
229 | { |
230 | hook_data_channel_activity hook_info; | |
231 | ||
f4a80ce6 JT |
232 | /* JOIN 0 simply parts all channels the user is in */ |
233 | if(*name == '0' && !atoi(name)) | |
234 | { | |
235 | if(source_p->user->channel.head == NULL) | |
236 | continue; | |
237 | ||
238 | do_join_0(&me, source_p); | |
239 | continue; | |
240 | } | |
241 | ||
212380e3 AC |
242 | /* look for the channel */ |
243 | if((chptr = find_channel(name)) != NULL) | |
244 | { | |
245 | if(IsMember(source_p, chptr)) | |
246 | continue; | |
247 | ||
248 | flags = 0; | |
249 | } | |
250 | else | |
251 | { | |
252 | hook_data_client_approval moduledata; | |
253 | ||
254 | moduledata.client = source_p; | |
255 | moduledata.approved = 0; | |
256 | ||
257 | call_hook(h_can_create_channel, &moduledata); | |
258 | ||
544cde90 | 259 | if(moduledata.approved != 0) |
212380e3 | 260 | { |
35bfe0e6 JT |
261 | if(moduledata.approved != ERR_CUSTOM) |
262 | send_join_error(source_p, | |
263 | moduledata.approved, | |
264 | name); | |
212380e3 AC |
265 | continue; |
266 | } | |
267 | ||
268 | if(splitmode && !IsOper(source_p) && (*name != '&') && | |
269 | ConfigChannel.no_create_on_split) | |
270 | { | |
271 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
272 | me.name, source_p->name, name); | |
273 | continue; | |
274 | } | |
275 | ||
276 | flags = CHFL_CHANOP; | |
277 | } | |
278 | ||
5b96d9a6 | 279 | if((rb_dlink_list_length(&source_p->user->channel) >= |
212380e3 AC |
280 | (unsigned long) ConfigChannel.max_chans_per_user) && |
281 | (!IsOper(source_p) || | |
5b96d9a6 | 282 | (rb_dlink_list_length(&source_p->user->channel) >= |
212380e3 AC |
283 | (unsigned long) ConfigChannel.max_chans_per_user * 3))) |
284 | { | |
285 | sendto_one(source_p, form_str(ERR_TOOMANYCHANNELS), | |
286 | me.name, source_p->name, name); | |
cddbab51 | 287 | continue; |
212380e3 AC |
288 | } |
289 | ||
212380e3 AC |
290 | if(chptr == NULL) /* If I already have a chptr, no point doing this */ |
291 | { | |
292 | chptr = get_or_create_channel(source_p, name, NULL); | |
293 | ||
294 | if(chptr == NULL) | |
295 | { | |
296 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
297 | me.name, source_p->name, name); | |
212380e3 AC |
298 | continue; |
299 | } | |
300 | } | |
301 | ||
765d839d EM |
302 | /* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */ |
303 | if(!(chptr2 = check_forward(source_p, chptr, key, &i))) | |
212380e3 | 304 | { |
765d839d EM |
305 | /* might be wrong, but is there any other better location for such? |
306 | * see extensions/chm_operonly.c for other comments on this | |
307 | * -- dwr | |
308 | */ | |
309 | if(i != ERR_CUSTOM) | |
35bfe0e6 | 310 | send_join_error(source_p, i, name); |
765d839d | 311 | continue; |
212380e3 | 312 | } |
765d839d EM |
313 | else if(chptr != chptr2) |
314 | sendto_one_numeric(source_p, ERR_LINKCHANNEL, form_str(ERR_LINKCHANNEL), name, chptr2->chname); | |
315 | ||
316 | chptr = chptr2; | |
212380e3 | 317 | |
ff91faaf JT |
318 | if(flags == 0 && |
319 | !IsOper(source_p) && !IsExemptSpambot(source_p)) | |
cf3564d6 JT |
320 | check_spambot_warning(source_p, name); |
321 | ||
212380e3 AC |
322 | /* add the user to the channel */ |
323 | add_user_to_channel(chptr, source_p, flags); | |
324 | if (chptr->mode.join_num && | |
e3354945 | 325 | rb_current_time() - chptr->join_delta >= chptr->mode.join_time) |
212380e3 AC |
326 | { |
327 | chptr->join_count = 0; | |
e3354945 | 328 | chptr->join_delta = rb_current_time(); |
212380e3 AC |
329 | } |
330 | chptr->join_count++; | |
331 | ||
7e132ff0 KB |
332 | /* credit user for join */ |
333 | credit_client_join(source_p); | |
334 | ||
212380e3 AC |
335 | /* we send the user their join here, because we could have to |
336 | * send a mode out next. | |
337 | */ | |
805cfa5a | 338 | send_channel_join(chptr, source_p); |
212380e3 AC |
339 | |
340 | /* its a new channel, set +nt and burst. */ | |
341 | if(flags & CHFL_CHANOP) | |
342 | { | |
e3354945 | 343 | chptr->channelts = rb_current_time(); |
212380e3 AC |
344 | chptr->mode.mode |= MODE_TOPICLIMIT; |
345 | chptr->mode.mode |= MODE_NOPRIVMSGS; | |
095efcf0 | 346 | modes = channel_modes(chptr, &me); |
212380e3 | 347 | |
095efcf0 JT |
348 | sendto_channel_local(ONLY_CHANOPS, chptr, ":%s MODE %s %s", |
349 | me.name, chptr->chname, modes); | |
212380e3 | 350 | |
db2545b1 JT |
351 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, |
352 | ":%s SJOIN %ld %s %s :@%s", | |
353 | me.id, (long) chptr->channelts, | |
354 | chptr->chname, modes, source_p->id); | |
212380e3 AC |
355 | } |
356 | else | |
357 | { | |
212380e3 | 358 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, |
bee3b671 | 359 | ":%s JOIN %ld %s +", |
212380e3 | 360 | use_id(source_p), (long) chptr->channelts, |
bee3b671 | 361 | chptr->chname); |
212380e3 AC |
362 | } |
363 | ||
364 | del_invite(chptr, source_p); | |
365 | ||
366 | if(chptr->topic != NULL) | |
367 | { | |
368 | sendto_one(source_p, form_str(RPL_TOPIC), me.name, | |
369 | source_p->name, chptr->chname, chptr->topic); | |
370 | ||
371 | sendto_one(source_p, form_str(RPL_TOPICWHOTIME), | |
372 | me.name, source_p->name, chptr->chname, | |
0cce01d3 JT |
373 | chptr->topic_info, |
374 | (unsigned long)chptr->topic_time); | |
212380e3 AC |
375 | } |
376 | ||
377 | channel_member_names(chptr, source_p, 1); | |
378 | ||
212380e3 AC |
379 | hook_info.client = source_p; |
380 | hook_info.chptr = chptr; | |
381 | hook_info.key = key; | |
382 | call_hook(h_channel_join, &hook_info); | |
383 | } | |
384 | ||
385 | return 0; | |
386 | } | |
387 | ||
388 | /* | |
389 | * ms_join | |
35835646 JT |
390 | * parv[1] = channel TS |
391 | * parv[2] = channel | |
392 | * parv[3] = "+", formerly channel modes but now unused | |
393 | * alternatively, a single "0" parameter parts all channels | |
212380e3 AC |
394 | */ |
395 | static int | |
396 | ms_join(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
397 | { | |
398 | struct Channel *chptr; | |
bee3b671 | 399 | static struct Mode mode; |
212380e3 AC |
400 | time_t oldts; |
401 | time_t newts; | |
402 | int isnew; | |
212380e3 | 403 | int keep_our_modes = YES; |
637c4932 | 404 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 405 | |
f4a80ce6 JT |
406 | /* special case for join 0 */ |
407 | if((parv[1][0] == '0') && (parv[1][1] == '\0') && parc == 2) | |
408 | { | |
409 | do_join_0(client_p, source_p); | |
410 | return 0; | |
411 | } | |
412 | ||
212380e3 AC |
413 | if(parc < 4) |
414 | return 0; | |
415 | ||
416 | if(!IsChannelName(parv[2]) || !check_channel_name(parv[2])) | |
417 | return 0; | |
418 | ||
419 | /* joins for local channels cant happen. */ | |
420 | if(parv[2][0] == '&') | |
421 | return 0; | |
422 | ||
423 | mbuf = modebuf; | |
424 | mode.key[0] = mode.forward[0] = '\0'; | |
425 | mode.mode = mode.limit = mode.join_num = mode.join_time = 0; | |
426 | ||
212380e3 AC |
427 | if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) |
428 | return 0; | |
429 | ||
430 | newts = atol(parv[1]); | |
431 | oldts = chptr->channelts; | |
212380e3 AC |
432 | |
433 | #ifdef IGNORE_BOGUS_TS | |
434 | if(newts < 800000000) | |
435 | { | |
436 | sendto_realops_snomask(SNO_DEBUG, L_ALL, | |
437 | "*** Bogus TS %ld on %s ignored from %s", | |
438 | (long) newts, chptr->chname, client_p->name); | |
439 | newts = (oldts == 0) ? oldts : 800000000; | |
440 | } | |
441 | #else | |
442 | /* making a channel TS0 */ | |
443 | if(!isnew && !newts && oldts) | |
444 | { | |
445 | sendto_channel_local(ALL_MEMBERS, chptr, | |
446 | ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0", | |
447 | me.name, chptr->chname, chptr->chname, (long) oldts); | |
448 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
449 | "Server %s changing TS on %s from %ld to 0", | |
450 | source_p->name, chptr->chname, (long) oldts); | |
451 | } | |
452 | #endif | |
453 | ||
454 | if(isnew) | |
455 | chptr->channelts = newts; | |
456 | else if(newts == 0 || oldts == 0) | |
457 | chptr->channelts = 0; | |
458 | else if(newts == oldts) | |
459 | ; | |
460 | else if(newts < oldts) | |
461 | { | |
462 | keep_our_modes = NO; | |
463 | chptr->channelts = newts; | |
464 | } | |
212380e3 | 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_uid; |
533 | int len; | |
534 | int joins = 0; | |
535 | const char *s; | |
8cc12805 VY |
536 | char *ptr_uid; |
537 | char *p; | |
538 | int i, joinc = 0, timeslice = 0; | |
539 | static char empty[] = ""; | |
540 | rb_dlink_node *ptr, *next_ptr; | |
541 | ||
b733b9fa JT |
542 | if(parc < 5) |
543 | return 0; | |
544 | ||
8cc12805 VY |
545 | if(!IsChannelName(parv[2]) || !check_channel_name(parv[2])) |
546 | return 0; | |
547 | ||
548 | /* SJOIN's for local channels can't happen. */ | |
549 | if(*parv[2] == '&') | |
550 | return 0; | |
551 | ||
552 | modebuf[0] = parabuf[0] = mode.key[0] = mode.forward[0] = '\0'; | |
553 | pargs = mode.mode = mode.limit = mode.join_num = mode.join_time = 0; | |
554 | ||
555 | /* Hide connecting server on netburst -- jilles */ | |
556 | if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) | |
557 | fakesource_p = &me; | |
558 | else | |
559 | fakesource_p = source_p; | |
560 | ||
561 | mbuf = modebuf; | |
562 | newts = atol(parv[1]); | |
563 | ||
564 | s = parv[3]; | |
565 | while (*s) | |
566 | { | |
567 | switch (*(s++)) | |
568 | { | |
8cc12805 | 569 | case 'f': |
f427c8b0 | 570 | rb_strlcpy(mode.forward, parv[4 + args], sizeof(mode.forward)); |
8cc12805 VY |
571 | args++; |
572 | if(parc < 5 + args) | |
573 | return 0; | |
574 | break; | |
575 | case 'j': | |
576 | sscanf(parv[4 + args], "%d:%d", &joinc, ×lice); | |
577 | args++; | |
578 | mode.join_num = joinc; | |
579 | mode.join_time = timeslice; | |
580 | if(parc < 5 + args) | |
581 | return 0; | |
582 | break; | |
583 | case 'k': | |
f427c8b0 | 584 | rb_strlcpy(mode.key, parv[4 + args], sizeof(mode.key)); |
8cc12805 VY |
585 | args++; |
586 | if(parc < 5 + args) | |
587 | return 0; | |
588 | break; | |
589 | case 'l': | |
590 | mode.limit = atoi(parv[4 + args]); | |
591 | args++; | |
592 | if(parc < 5 + args) | |
593 | return 0; | |
594 | break; | |
efccc22c VY |
595 | default: |
596 | if(chmode_flags[(int) *s] != 0) | |
597 | { | |
598 | mode.mode |= chmode_flags[(int) *s]; | |
599 | } | |
8cc12805 VY |
600 | } |
601 | } | |
602 | ||
603 | if(parv[args + 4]) | |
604 | { | |
605 | s = parv[args + 4]; | |
606 | ||
607 | /* remove any leading spaces */ | |
608 | while (*s == ' ') | |
609 | s++; | |
610 | } | |
611 | else | |
612 | s = ""; | |
613 | ||
614 | if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) | |
615 | return 0; /* channel name too long? */ | |
616 | ||
617 | ||
618 | oldts = chptr->channelts; | |
619 | oldmode = &chptr->mode; | |
620 | ||
621 | #ifdef IGNORE_BOGUS_TS | |
622 | if(newts < 800000000) | |
623 | { | |
624 | sendto_realops_snomask(SNO_DEBUG, L_ALL, | |
625 | "*** Bogus TS %ld on %s ignored from %s", | |
626 | (long) newts, chptr->chname, client_p->name); | |
627 | ||
628 | newts = (oldts == 0) ? oldts : 800000000; | |
629 | } | |
630 | #else | |
631 | if(!isnew && !newts && oldts) | |
632 | { | |
633 | sendto_channel_local(ALL_MEMBERS, chptr, | |
634 | ":%s NOTICE %s :*** Notice -- TS for %s " | |
635 | "changed from %ld to 0", | |
636 | me.name, chptr->chname, chptr->chname, (long) oldts); | |
637 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
638 | "Server %s changing TS on %s from %ld to 0", | |
639 | source_p->name, chptr->chname, (long) oldts); | |
640 | } | |
641 | #endif | |
642 | ||
643 | if(isnew) | |
644 | chptr->channelts = newts; | |
55abcbb2 | 645 | |
8cc12805 VY |
646 | else if(newts == 0 || oldts == 0) |
647 | chptr->channelts = 0; | |
648 | else if(newts == oldts) | |
649 | ; | |
650 | else if(newts < oldts) | |
651 | { | |
652 | /* If configured, kick people trying to join +i/+k | |
653 | * channels by recreating them on split servers. | |
a1574df4 JT |
654 | * If the source has sent EOB, assume this is some |
655 | * sort of hack by services. If cmode +i is set, | |
656 | * services can send kicks if needed; if the key | |
657 | * differs, services cannot kick in a race-free | |
658 | * manner so do so here. | |
8cc12805 VY |
659 | * -- jilles */ |
660 | if (ConfigChannel.kick_on_split_riding && | |
a1574df4 JT |
661 | ((!HasSentEob(source_p) && |
662 | mode.mode & MODE_INVITEONLY) || | |
8cc12805 VY |
663 | (mode.key[0] != 0 && irccmp(mode.key, oldmode->key) != 0))) |
664 | { | |
665 | struct membership *msptr; | |
666 | struct Client *who; | |
667 | int l = rb_dlink_list_length(&chptr->members); | |
8cc12805 VY |
668 | |
669 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) | |
670 | { | |
671 | msptr = ptr->data; | |
672 | who = msptr->client_p; | |
673 | sendto_one(who, ":%s KICK %s %s :Net Rider", | |
674 | me.name, chptr->chname, who->name); | |
675 | ||
676 | sendto_server(NULL, chptr, CAP_TS6, NOCAPS, | |
677 | ":%s KICK %s %s :Net Rider", | |
678 | me.id, chptr->chname, | |
679 | who->id); | |
8cc12805 VY |
680 | remove_user_from_channel(msptr); |
681 | if (--l == 0) | |
682 | break; | |
683 | } | |
684 | if (l == 0) | |
685 | { | |
686 | /* Channel was emptied, create a new one */ | |
687 | if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) | |
688 | return 0; /* oops! */ | |
689 | ||
8cc12805 VY |
690 | oldmode = &chptr->mode; |
691 | } | |
692 | } | |
693 | keep_our_modes = NO; | |
694 | chptr->channelts = newts; | |
695 | } | |
696 | else | |
697 | keep_new_modes = NO; | |
698 | ||
699 | if(!keep_new_modes) | |
700 | mode = *oldmode; | |
701 | else if(keep_our_modes) | |
702 | { | |
703 | mode.mode |= oldmode->mode; | |
704 | if(oldmode->limit > mode.limit) | |
705 | mode.limit = oldmode->limit; | |
706 | if(strcmp(mode.key, oldmode->key) < 0) | |
707 | strcpy(mode.key, oldmode->key); | |
708 | if(oldmode->join_num > mode.join_num || | |
709 | (oldmode->join_num == mode.join_num && | |
710 | oldmode->join_time > mode.join_time)) | |
711 | { | |
712 | mode.join_num = oldmode->join_num; | |
713 | mode.join_time = oldmode->join_time; | |
714 | } | |
715 | if(irccmp(mode.forward, oldmode->forward) < 0) | |
716 | strcpy(mode.forward, oldmode->forward); | |
717 | } | |
718 | else | |
719 | { | |
720 | /* If setting -j, clear join throttle state -- jilles */ | |
721 | if (!mode.join_num) | |
722 | chptr->join_count = chptr->join_delta = 0; | |
723 | } | |
724 | ||
725 | set_final_mode(&mode, oldmode); | |
726 | chptr->mode = mode; | |
727 | ||
728 | /* Lost the TS, other side wins, so remove modes on this side */ | |
729 | if(!keep_our_modes) | |
730 | { | |
731 | remove_our_modes(chptr, fakesource_p); | |
732 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) | |
733 | { | |
734 | del_invite(chptr, ptr->data); | |
735 | } | |
7b22c84f JT |
736 | |
737 | if(rb_dlink_list_length(&chptr->banlist) > 0) | |
738 | remove_ban_list(chptr, fakesource_p, &chptr->banlist, 'b', ALL_MEMBERS); | |
739 | if(rb_dlink_list_length(&chptr->exceptlist) > 0) | |
740 | remove_ban_list(chptr, fakesource_p, &chptr->exceptlist, | |
741 | 'e', ONLY_CHANOPS); | |
742 | if(rb_dlink_list_length(&chptr->invexlist) > 0) | |
743 | remove_ban_list(chptr, fakesource_p, &chptr->invexlist, | |
744 | 'I', ONLY_CHANOPS); | |
745 | if(rb_dlink_list_length(&chptr->quietlist) > 0) | |
746 | remove_ban_list(chptr, fakesource_p, &chptr->quietlist, | |
747 | 'q', ALL_MEMBERS); | |
748 | chptr->bants++; | |
749 | ||
8cc12805 VY |
750 | sendto_channel_local(ALL_MEMBERS, chptr, |
751 | ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld", | |
752 | me.name, chptr->chname, chptr->chname, | |
753 | (long) oldts, (long) newts); | |
754 | /* Update capitalization in channel name, this makes the | |
755 | * capitalization timestamped like modes are -- jilles */ | |
756 | strcpy(chptr->chname, parv[2]); | |
6fb6bd15 AC |
757 | |
758 | /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */ | |
759 | set_channel_mlock(client_p, source_p, chptr, NULL, FALSE); | |
8cc12805 VY |
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 | ||
8cc12805 VY |
773 | mlen_uid = rb_sprintf(buf_uid, ":%s SJOIN %ld %s %s :", |
774 | use_id(source_p), (long) chptr->channelts, parv[2], modes); | |
775 | ptr_uid = buf_uid + mlen_uid; | |
776 | ||
777 | mbuf = modebuf; | |
778 | para[0] = para[1] = para[2] = para[3] = empty; | |
779 | pargs = 0; | |
40709472 | 780 | len_uid = 0; |
8cc12805 VY |
781 | |
782 | /* if theres a space, theres going to be more than one nick, change the | |
783 | * first space to \0, so s is just the first nick, and point p to the | |
784 | * second nick | |
785 | */ | |
786 | if((p = strchr(s, ' ')) != NULL) | |
787 | { | |
788 | *p++ = '\0'; | |
789 | } | |
790 | ||
791 | *mbuf++ = '+'; | |
792 | ||
793 | while (s) | |
794 | { | |
795 | fl = 0; | |
796 | ||
797 | for (i = 0; i < 2; i++) | |
798 | { | |
799 | if(*s == '@') | |
800 | { | |
801 | fl |= CHFL_CHANOP; | |
802 | s++; | |
803 | } | |
804 | else if(*s == '+') | |
805 | { | |
806 | fl |= CHFL_VOICE; | |
807 | s++; | |
808 | } | |
809 | } | |
810 | ||
811 | /* if the client doesnt exist or is fake direction, skip. */ | |
812 | if(!(target_p = find_client(s)) || | |
813 | (target_p->from != client_p) || !IsPerson(target_p)) | |
814 | goto nextnick; | |
815 | ||
816 | /* we assume for these we can fit at least one nick/uid in.. */ | |
817 | ||
818 | /* check we can fit another status+nick+space into a buffer */ | |
8cc12805 VY |
819 | if((mlen_uid + len_uid + IDLEN + 3) > (BUFSIZE - 3)) |
820 | { | |
821 | *(ptr_uid - 1) = '\0'; | |
822 | sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid); | |
823 | ptr_uid = buf_uid + mlen_uid; | |
824 | len_uid = 0; | |
825 | } | |
826 | ||
827 | if(keep_new_modes) | |
828 | { | |
829 | if(fl & CHFL_CHANOP) | |
830 | { | |
8cc12805 | 831 | *ptr_uid++ = '@'; |
8cc12805 VY |
832 | len_uid++; |
833 | } | |
834 | if(fl & CHFL_VOICE) | |
835 | { | |
8cc12805 | 836 | *ptr_uid++ = '+'; |
8cc12805 VY |
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 | ||
35bfe0e6 JT |
1026 | /* send_join_error() |
1027 | * | |
1028 | * input - client to send to, reason, channel name | |
1029 | * output - none | |
1030 | * side effects - error message sent to client | |
1031 | */ | |
1032 | static void | |
1033 | send_join_error(struct Client *source_p, int numeric, const char *name) | |
1034 | { | |
1035 | /* This stuff is necessary because the form_str macro only | |
1036 | * accepts constants. | |
1037 | */ | |
1038 | switch (numeric) | |
1039 | { | |
1040 | #define NORMAL_NUMERIC(i) \ | |
1041 | case i: \ | |
1042 | sendto_one(source_p, form_str(i), \ | |
1043 | me.name, source_p->name, name); \ | |
1044 | break | |
1045 | ||
1046 | NORMAL_NUMERIC(ERR_BANNEDFROMCHAN); | |
1047 | NORMAL_NUMERIC(ERR_INVITEONLYCHAN); | |
1048 | NORMAL_NUMERIC(ERR_BADCHANNELKEY); | |
1049 | NORMAL_NUMERIC(ERR_CHANNELISFULL); | |
1050 | NORMAL_NUMERIC(ERR_NEEDREGGEDNICK); | |
1051 | NORMAL_NUMERIC(ERR_THROTTLE); | |
1052 | ||
1053 | default: | |
1054 | sendto_one_numeric(source_p, numeric, | |
1055 | "%s :Cannot join channel", name); | |
1056 | break; | |
1057 | } | |
1058 | } | |
1059 | ||
212380e3 AC |
1060 | static void |
1061 | set_final_mode(struct Mode *mode, struct Mode *oldmode) | |
1062 | { | |
1063 | int dir = MODE_QUERY; | |
1064 | char *pbuf = parabuf; | |
1065 | int len; | |
1066 | int i; | |
1067 | ||
1068 | /* ok, first get a list of modes we need to add */ | |
efccc22c | 1069 | for (i = 0; i < 256; i++) |
212380e3 | 1070 | { |
efccc22c | 1071 | if((mode->mode & chmode_flags[i]) && !(oldmode->mode & chmode_flags[i])) |
212380e3 AC |
1072 | { |
1073 | if(dir != MODE_ADD) | |
1074 | { | |
1075 | *mbuf++ = '+'; | |
1076 | dir = MODE_ADD; | |
1077 | } | |
efccc22c | 1078 | *mbuf++ = i; |
212380e3 AC |
1079 | } |
1080 | } | |
1081 | ||
1082 | /* now the ones we need to remove. */ | |
efccc22c | 1083 | for (i = 0; i < 256; i++) |
212380e3 | 1084 | { |
efccc22c | 1085 | if((oldmode->mode & chmode_flags[i]) && !(mode->mode & chmode_flags[i])) |
212380e3 AC |
1086 | { |
1087 | if(dir != MODE_DEL) | |
1088 | { | |
1089 | *mbuf++ = '-'; | |
1090 | dir = MODE_DEL; | |
1091 | } | |
efccc22c | 1092 | *mbuf++ = i; |
212380e3 AC |
1093 | } |
1094 | } | |
1095 | ||
1096 | if(oldmode->limit && !mode->limit) | |
1097 | { | |
1098 | if(dir != MODE_DEL) | |
1099 | { | |
1100 | *mbuf++ = '-'; | |
1101 | dir = MODE_DEL; | |
1102 | } | |
1103 | *mbuf++ = 'l'; | |
1104 | } | |
1105 | if(oldmode->key[0] && !mode->key[0]) | |
1106 | { | |
1107 | if(dir != MODE_DEL) | |
1108 | { | |
1109 | *mbuf++ = '-'; | |
1110 | dir = MODE_DEL; | |
1111 | } | |
1112 | *mbuf++ = 'k'; | |
7cdb0a09 | 1113 | len = rb_sprintf(pbuf, "%s ", oldmode->key); |
212380e3 AC |
1114 | pbuf += len; |
1115 | } | |
1116 | if(oldmode->join_num && !mode->join_num) | |
1117 | { | |
1118 | if(dir != MODE_DEL) | |
1119 | { | |
1120 | *mbuf++ = '-'; | |
1121 | dir = MODE_DEL; | |
1122 | } | |
1123 | *mbuf++ = 'j'; | |
1124 | } | |
1125 | if(oldmode->forward[0] && !mode->forward[0]) | |
1126 | { | |
1127 | if(dir != MODE_DEL) | |
1128 | { | |
1129 | *mbuf++ = '-'; | |
1130 | dir = MODE_DEL; | |
1131 | } | |
1132 | *mbuf++ = 'f'; | |
1133 | } | |
1134 | if(mode->limit && oldmode->limit != mode->limit) | |
1135 | { | |
1136 | if(dir != MODE_ADD) | |
1137 | { | |
1138 | *mbuf++ = '+'; | |
1139 | dir = MODE_ADD; | |
1140 | } | |
1141 | *mbuf++ = 'l'; | |
7cdb0a09 | 1142 | len = rb_sprintf(pbuf, "%d ", mode->limit); |
212380e3 AC |
1143 | pbuf += len; |
1144 | } | |
1145 | if(mode->key[0] && strcmp(oldmode->key, mode->key)) | |
1146 | { | |
1147 | if(dir != MODE_ADD) | |
1148 | { | |
1149 | *mbuf++ = '+'; | |
1150 | dir = MODE_ADD; | |
1151 | } | |
1152 | *mbuf++ = 'k'; | |
7cdb0a09 | 1153 | len = rb_sprintf(pbuf, "%s ", mode->key); |
212380e3 AC |
1154 | pbuf += len; |
1155 | } | |
1156 | if(mode->join_num && (oldmode->join_num != mode->join_num || oldmode->join_time != mode->join_time)) | |
1157 | { | |
1158 | if(dir != MODE_ADD) | |
1159 | { | |
1160 | *mbuf++ = '+'; | |
1161 | dir = MODE_ADD; | |
1162 | } | |
1163 | *mbuf++ = 'j'; | |
7cdb0a09 | 1164 | len = rb_sprintf(pbuf, "%d:%d ", mode->join_num, mode->join_time); |
212380e3 AC |
1165 | pbuf += len; |
1166 | } | |
2da6f6eb JT |
1167 | if(mode->forward[0] && strcmp(oldmode->forward, mode->forward) && |
1168 | ConfigChannel.use_forward) | |
212380e3 AC |
1169 | { |
1170 | if(dir != MODE_ADD) | |
1171 | { | |
1172 | *mbuf++ = '+'; | |
1173 | dir = MODE_ADD; | |
1174 | } | |
1175 | *mbuf++ = 'f'; | |
7cdb0a09 | 1176 | len = rb_sprintf(pbuf, "%s ", mode->forward); |
212380e3 AC |
1177 | pbuf += len; |
1178 | } | |
1179 | *mbuf = '\0'; | |
1180 | } | |
1181 | ||
1182 | /* | |
1183 | * remove_our_modes | |
1184 | * | |
1185 | * inputs - | |
55abcbb2 KB |
1186 | * output - |
1187 | * side effects - | |
212380e3 AC |
1188 | */ |
1189 | static void | |
1190 | remove_our_modes(struct Channel *chptr, struct Client *source_p) | |
1191 | { | |
1192 | struct membership *msptr; | |
5b96d9a6 | 1193 | rb_dlink_node *ptr; |
212380e3 AC |
1194 | char lmodebuf[MODEBUFLEN]; |
1195 | char *lpara[MAXMODEPARAMS]; | |
1196 | int count = 0; | |
1197 | int i; | |
1198 | ||
1199 | mbuf = lmodebuf; | |
1200 | *mbuf++ = '-'; | |
1201 | ||
1202 | for(i = 0; i < MAXMODEPARAMS; i++) | |
1203 | lpara[i] = NULL; | |
1204 | ||
5b96d9a6 | 1205 | RB_DLINK_FOREACH(ptr, chptr->members.head) |
212380e3 AC |
1206 | { |
1207 | msptr = ptr->data; | |
1208 | ||
1209 | if(is_chanop(msptr)) | |
1210 | { | |
1211 | msptr->flags &= ~CHFL_CHANOP; | |
1212 | lpara[count++] = msptr->client_p->name; | |
1213 | *mbuf++ = 'o'; | |
1214 | ||
1215 | /* +ov, might not fit so check. */ | |
1216 | if(is_voiced(msptr)) | |
1217 | { | |
1218 | if(count >= MAXMODEPARAMS) | |
1219 | { | |
1220 | *mbuf = '\0'; | |
1221 | sendto_channel_local(ALL_MEMBERS, chptr, | |
1222 | ":%s MODE %s %s %s %s %s %s", | |
7bf78de0 | 1223 | source_p->name, chptr->chname, |
212380e3 AC |
1224 | lmodebuf, lpara[0], lpara[1], |
1225 | lpara[2], lpara[3]); | |
1226 | ||
1227 | /* preserve the initial '-' */ | |
1228 | mbuf = lmodebuf; | |
1229 | *mbuf++ = '-'; | |
1230 | count = 0; | |
1231 | ||
1232 | for(i = 0; i < MAXMODEPARAMS; i++) | |
1233 | lpara[i] = NULL; | |
1234 | } | |
1235 | ||
1236 | msptr->flags &= ~CHFL_VOICE; | |
1237 | lpara[count++] = msptr->client_p->name; | |
1238 | *mbuf++ = 'v'; | |
1239 | } | |
1240 | } | |
1241 | else if(is_voiced(msptr)) | |
1242 | { | |
1243 | msptr->flags &= ~CHFL_VOICE; | |
1244 | lpara[count++] = msptr->client_p->name; | |
1245 | *mbuf++ = 'v'; | |
1246 | } | |
1247 | else | |
1248 | continue; | |
1249 | ||
1250 | if(count >= MAXMODEPARAMS) | |
1251 | { | |
1252 | *mbuf = '\0'; | |
1253 | sendto_channel_local(ALL_MEMBERS, chptr, | |
1254 | ":%s MODE %s %s %s %s %s %s", | |
7bf78de0 | 1255 | source_p->name, chptr->chname, lmodebuf, |
212380e3 AC |
1256 | lpara[0], lpara[1], lpara[2], lpara[3]); |
1257 | mbuf = lmodebuf; | |
1258 | *mbuf++ = '-'; | |
1259 | count = 0; | |
1260 | ||
1261 | for(i = 0; i < MAXMODEPARAMS; i++) | |
1262 | lpara[i] = NULL; | |
1263 | } | |
1264 | } | |
1265 | ||
1266 | if(count != 0) | |
1267 | { | |
1268 | *mbuf = '\0'; | |
1269 | sendto_channel_local(ALL_MEMBERS, chptr, | |
1270 | ":%s MODE %s %s %s %s %s %s", | |
7bf78de0 | 1271 | source_p->name, chptr->chname, lmodebuf, |
212380e3 AC |
1272 | EmptyString(lpara[0]) ? "" : lpara[0], |
1273 | EmptyString(lpara[1]) ? "" : lpara[1], | |
1274 | EmptyString(lpara[2]) ? "" : lpara[2], | |
1275 | EmptyString(lpara[3]) ? "" : lpara[3]); | |
1276 | ||
1277 | } | |
1278 | } | |
8cc12805 VY |
1279 | |
1280 | /* remove_ban_list() | |
1281 | * | |
1282 | * inputs - channel, source, list to remove, char of mode, caps needed | |
1283 | * outputs - | |
1284 | * side effects - given list is removed, with modes issued to local clients | |
8cc12805 VY |
1285 | */ |
1286 | static void | |
1287 | remove_ban_list(struct Channel *chptr, struct Client *source_p, | |
8afeb720 | 1288 | rb_dlink_list * list, char c, int mems) |
8cc12805 VY |
1289 | { |
1290 | static char lmodebuf[BUFSIZE]; | |
1291 | static char lparabuf[BUFSIZE]; | |
1292 | struct Ban *banptr; | |
1293 | rb_dlink_node *ptr; | |
1294 | rb_dlink_node *next_ptr; | |
1295 | char *pbuf; | |
1296 | int count = 0; | |
1297 | int cur_len, mlen, plen; | |
1298 | ||
1299 | pbuf = lparabuf; | |
1300 | ||
1301 | cur_len = mlen = rb_sprintf(lmodebuf, ":%s MODE %s -", source_p->name, chptr->chname); | |
1302 | mbuf = lmodebuf + mlen; | |
1303 | ||
1304 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) | |
1305 | { | |
1306 | banptr = ptr->data; | |
1307 | ||
1308 | /* trailing space, and the mode letter itself */ | |
23f6b63a JT |
1309 | plen = strlen(banptr->banstr) + |
1310 | (banptr->forward ? strlen(banptr->forward) + 1 : 0) + 2; | |
8cc12805 VY |
1311 | |
1312 | if(count >= MAXMODEPARAMS || (cur_len + plen) > BUFSIZE - 4) | |
1313 | { | |
1314 | /* remove trailing space */ | |
1315 | *mbuf = '\0'; | |
1316 | *(pbuf - 1) = '\0'; | |
1317 | ||
1318 | sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf); | |
8cc12805 VY |
1319 | |
1320 | cur_len = mlen; | |
1321 | mbuf = lmodebuf + mlen; | |
1322 | pbuf = lparabuf; | |
1323 | count = 0; | |
1324 | } | |
1325 | ||
1326 | *mbuf++ = c; | |
1327 | cur_len += plen; | |
23f6b63a JT |
1328 | if (banptr->forward) |
1329 | pbuf += rb_sprintf(pbuf, "%s$%s ", banptr->banstr, banptr->forward); | |
1330 | else | |
1331 | pbuf += rb_sprintf(pbuf, "%s ", banptr->banstr); | |
8cc12805 VY |
1332 | count++; |
1333 | ||
1334 | free_ban(banptr); | |
1335 | } | |
1336 | ||
1337 | *mbuf = '\0'; | |
1338 | *(pbuf - 1) = '\0'; | |
1339 | sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf); | |
8cc12805 VY |
1340 | |
1341 | list->head = list->tail = NULL; | |
1342 | list->length = 0; | |
1343 | } |