]>
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 | 46 | |
428ca87b AC |
47 | static int m_join(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
48 | static int ms_join(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
49 | static int ms_sjoin(struct MsgBuf *, 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 = { | |
7baa37a9 | 55 | "JOIN", 0, 0, 0, 0, |
212380e3 AC |
56 | {mg_unreg, {m_join, 2}, {ms_join, 2}, mg_ignore, mg_ignore, {m_join, 2}} |
57 | }; | |
58 | ||
8cc12805 | 59 | struct Message sjoin_msgtab = { |
7baa37a9 | 60 | "SJOIN", 0, 0, 0, 0, |
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 | |
428ca87b | 142 | m_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
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 | 280 | (unsigned long) ConfigChannel.max_chans_per_user) && |
a4721f5e | 281 | (!IsExtendChans(source_p) || |
5b96d9a6 | 282 | (rb_dlink_list_length(&source_p->user->channel) >= |
a4721f5e | 283 | (unsigned long) ConfigChannel.max_chans_per_user_large))) |
212380e3 AC |
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(); |
63eb8567 | 344 | chptr->mode.mode |= ConfigChannel.autochanmodes; |
095efcf0 | 345 | modes = channel_modes(chptr, &me); |
212380e3 | 346 | |
095efcf0 JT |
347 | sendto_channel_local(ONLY_CHANOPS, chptr, ":%s MODE %s %s", |
348 | me.name, chptr->chname, modes); | |
212380e3 | 349 | |
db2545b1 JT |
350 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, |
351 | ":%s SJOIN %ld %s %s :@%s", | |
352 | me.id, (long) chptr->channelts, | |
353 | chptr->chname, modes, source_p->id); | |
212380e3 AC |
354 | } |
355 | else | |
356 | { | |
212380e3 | 357 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, |
bee3b671 | 358 | ":%s JOIN %ld %s +", |
212380e3 | 359 | use_id(source_p), (long) chptr->channelts, |
bee3b671 | 360 | chptr->chname); |
212380e3 AC |
361 | } |
362 | ||
363 | del_invite(chptr, source_p); | |
364 | ||
365 | if(chptr->topic != NULL) | |
366 | { | |
367 | sendto_one(source_p, form_str(RPL_TOPIC), me.name, | |
368 | source_p->name, chptr->chname, chptr->topic); | |
369 | ||
370 | sendto_one(source_p, form_str(RPL_TOPICWHOTIME), | |
371 | me.name, source_p->name, chptr->chname, | |
0cce01d3 JT |
372 | chptr->topic_info, |
373 | (unsigned long)chptr->topic_time); | |
212380e3 AC |
374 | } |
375 | ||
376 | channel_member_names(chptr, source_p, 1); | |
377 | ||
212380e3 AC |
378 | hook_info.client = source_p; |
379 | hook_info.chptr = chptr; | |
380 | hook_info.key = key; | |
381 | call_hook(h_channel_join, &hook_info); | |
382 | } | |
383 | ||
384 | return 0; | |
385 | } | |
386 | ||
387 | /* | |
388 | * ms_join | |
35835646 JT |
389 | * parv[1] = channel TS |
390 | * parv[2] = channel | |
391 | * parv[3] = "+", formerly channel modes but now unused | |
392 | * alternatively, a single "0" parameter parts all channels | |
212380e3 AC |
393 | */ |
394 | static int | |
428ca87b | 395 | ms_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
396 | { |
397 | struct Channel *chptr; | |
bee3b671 | 398 | static struct Mode mode; |
212380e3 AC |
399 | time_t oldts; |
400 | time_t newts; | |
401 | int isnew; | |
212380e3 | 402 | int keep_our_modes = YES; |
637c4932 | 403 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 404 | |
f4a80ce6 JT |
405 | /* special case for join 0 */ |
406 | if((parv[1][0] == '0') && (parv[1][1] == '\0') && parc == 2) | |
407 | { | |
408 | do_join_0(client_p, source_p); | |
409 | return 0; | |
410 | } | |
411 | ||
212380e3 AC |
412 | if(parc < 4) |
413 | return 0; | |
414 | ||
415 | if(!IsChannelName(parv[2]) || !check_channel_name(parv[2])) | |
416 | return 0; | |
417 | ||
418 | /* joins for local channels cant happen. */ | |
419 | if(parv[2][0] == '&') | |
420 | return 0; | |
421 | ||
422 | mbuf = modebuf; | |
423 | mode.key[0] = mode.forward[0] = '\0'; | |
424 | mode.mode = mode.limit = mode.join_num = mode.join_time = 0; | |
425 | ||
212380e3 AC |
426 | if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) |
427 | return 0; | |
428 | ||
429 | newts = atol(parv[1]); | |
430 | oldts = chptr->channelts; | |
212380e3 AC |
431 | |
432 | #ifdef IGNORE_BOGUS_TS | |
433 | if(newts < 800000000) | |
434 | { | |
435 | sendto_realops_snomask(SNO_DEBUG, L_ALL, | |
436 | "*** Bogus TS %ld on %s ignored from %s", | |
437 | (long) newts, chptr->chname, client_p->name); | |
438 | newts = (oldts == 0) ? oldts : 800000000; | |
439 | } | |
440 | #else | |
441 | /* making a channel TS0 */ | |
442 | if(!isnew && !newts && oldts) | |
443 | { | |
444 | sendto_channel_local(ALL_MEMBERS, chptr, | |
445 | ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0", | |
446 | me.name, chptr->chname, chptr->chname, (long) oldts); | |
447 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
448 | "Server %s changing TS on %s from %ld to 0", | |
449 | source_p->name, chptr->chname, (long) oldts); | |
450 | } | |
451 | #endif | |
452 | ||
453 | if(isnew) | |
454 | chptr->channelts = newts; | |
455 | else if(newts == 0 || oldts == 0) | |
456 | chptr->channelts = 0; | |
457 | else if(newts == oldts) | |
458 | ; | |
459 | else if(newts < oldts) | |
460 | { | |
461 | keep_our_modes = NO; | |
462 | chptr->channelts = newts; | |
463 | } | |
212380e3 | 464 | |
212380e3 AC |
465 | /* Lost the TS, other side wins, so remove modes on this side */ |
466 | if(!keep_our_modes) | |
467 | { | |
bee3b671 JT |
468 | set_final_mode(&mode, &chptr->mode); |
469 | chptr->mode = mode; | |
212380e3 | 470 | remove_our_modes(chptr, source_p); |
637c4932 | 471 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) |
212380e3 AC |
472 | { |
473 | del_invite(chptr, ptr->data); | |
474 | } | |
bee3b671 JT |
475 | /* If setting -j, clear join throttle state -- jilles */ |
476 | chptr->join_count = chptr->join_delta = 0; | |
212380e3 AC |
477 | sendto_channel_local(ALL_MEMBERS, chptr, |
478 | ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld", | |
479 | me.name, chptr->chname, chptr->chname, | |
480 | (long) oldts, (long) newts); | |
1117fbd3 JT |
481 | /* Update capitalization in channel name, this makes the |
482 | * capitalization timestamped like modes are -- jilles */ | |
483 | strcpy(chptr->chname, parv[2]); | |
bee3b671 JT |
484 | if(*modebuf != '\0') |
485 | sendto_channel_local(ALL_MEMBERS, chptr, | |
486 | ":%s MODE %s %s %s", | |
487 | source_p->servptr->name, | |
488 | chptr->chname, modebuf, parabuf); | |
489 | *modebuf = *parabuf = '\0'; | |
6fb6bd15 AC |
490 | |
491 | /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */ | |
492 | set_channel_mlock(client_p, source_p, chptr, NULL, FALSE); | |
212380e3 AC |
493 | } |
494 | ||
212380e3 AC |
495 | if(!IsMember(source_p, chptr)) |
496 | { | |
497 | add_user_to_channel(chptr, source_p, CHFL_PEON); | |
498 | if (chptr->mode.join_num && | |
e3354945 | 499 | rb_current_time() - chptr->join_delta >= chptr->mode.join_time) |
212380e3 AC |
500 | { |
501 | chptr->join_count = 0; | |
e3354945 | 502 | chptr->join_delta = rb_current_time(); |
212380e3 AC |
503 | } |
504 | chptr->join_count++; | |
805cfa5a | 505 | send_channel_join(chptr, source_p); |
212380e3 AC |
506 | } |
507 | ||
212380e3 | 508 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, |
bee3b671 JT |
509 | ":%s JOIN %ld %s +", |
510 | source_p->id, (long) chptr->channelts, chptr->chname); | |
212380e3 AC |
511 | return 0; |
512 | } | |
513 | ||
8cc12805 | 514 | static int |
428ca87b | 515 | ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
8cc12805 | 516 | { |
8cc12805 VY |
517 | static char buf_uid[BUFSIZE]; |
518 | static const char empty_modes[] = "0"; | |
519 | struct Channel *chptr; | |
520 | struct Client *target_p, *fakesource_p; | |
521 | time_t newts; | |
522 | time_t oldts; | |
523 | static struct Mode mode, *oldmode; | |
524 | const char *modes; | |
525 | int args = 0; | |
526 | int keep_our_modes = 1; | |
527 | int keep_new_modes = 1; | |
528 | int fl; | |
529 | int isnew; | |
890423fb | 530 | int mlen_uid; |
8cc12805 VY |
531 | int len_uid; |
532 | int len; | |
533 | int joins = 0; | |
534 | const char *s; | |
8cc12805 VY |
535 | char *ptr_uid; |
536 | char *p; | |
537 | int i, joinc = 0, timeslice = 0; | |
538 | static char empty[] = ""; | |
539 | rb_dlink_node *ptr, *next_ptr; | |
540 | ||
b733b9fa JT |
541 | if(parc < 5) |
542 | return 0; | |
543 | ||
8cc12805 VY |
544 | if(!IsChannelName(parv[2]) || !check_channel_name(parv[2])) |
545 | return 0; | |
546 | ||
547 | /* SJOIN's for local channels can't happen. */ | |
548 | if(*parv[2] == '&') | |
549 | return 0; | |
550 | ||
551 | modebuf[0] = parabuf[0] = mode.key[0] = mode.forward[0] = '\0'; | |
552 | pargs = mode.mode = mode.limit = mode.join_num = mode.join_time = 0; | |
553 | ||
554 | /* Hide connecting server on netburst -- jilles */ | |
555 | if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) | |
556 | fakesource_p = &me; | |
557 | else | |
558 | fakesource_p = source_p; | |
559 | ||
560 | mbuf = modebuf; | |
561 | newts = atol(parv[1]); | |
562 | ||
563 | s = parv[3]; | |
564 | while (*s) | |
565 | { | |
566 | switch (*(s++)) | |
567 | { | |
8cc12805 | 568 | case 'f': |
f427c8b0 | 569 | rb_strlcpy(mode.forward, parv[4 + args], sizeof(mode.forward)); |
8cc12805 VY |
570 | args++; |
571 | if(parc < 5 + args) | |
572 | return 0; | |
573 | break; | |
574 | case 'j': | |
575 | sscanf(parv[4 + args], "%d:%d", &joinc, ×lice); | |
576 | args++; | |
577 | mode.join_num = joinc; | |
578 | mode.join_time = timeslice; | |
579 | if(parc < 5 + args) | |
580 | return 0; | |
581 | break; | |
582 | case 'k': | |
f427c8b0 | 583 | rb_strlcpy(mode.key, parv[4 + args], sizeof(mode.key)); |
8cc12805 VY |
584 | args++; |
585 | if(parc < 5 + args) | |
586 | return 0; | |
587 | break; | |
588 | case 'l': | |
589 | mode.limit = atoi(parv[4 + args]); | |
590 | args++; | |
591 | if(parc < 5 + args) | |
592 | return 0; | |
593 | break; | |
efccc22c VY |
594 | default: |
595 | if(chmode_flags[(int) *s] != 0) | |
596 | { | |
597 | mode.mode |= chmode_flags[(int) *s]; | |
598 | } | |
8cc12805 VY |
599 | } |
600 | } | |
601 | ||
602 | if(parv[args + 4]) | |
603 | { | |
604 | s = parv[args + 4]; | |
605 | ||
606 | /* remove any leading spaces */ | |
607 | while (*s == ' ') | |
608 | s++; | |
609 | } | |
610 | else | |
611 | s = ""; | |
612 | ||
613 | if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) | |
614 | return 0; /* channel name too long? */ | |
615 | ||
616 | ||
617 | oldts = chptr->channelts; | |
618 | oldmode = &chptr->mode; | |
619 | ||
620 | #ifdef IGNORE_BOGUS_TS | |
621 | if(newts < 800000000) | |
622 | { | |
623 | sendto_realops_snomask(SNO_DEBUG, L_ALL, | |
624 | "*** Bogus TS %ld on %s ignored from %s", | |
625 | (long) newts, chptr->chname, client_p->name); | |
626 | ||
627 | newts = (oldts == 0) ? oldts : 800000000; | |
628 | } | |
629 | #else | |
630 | if(!isnew && !newts && oldts) | |
631 | { | |
632 | sendto_channel_local(ALL_MEMBERS, chptr, | |
633 | ":%s NOTICE %s :*** Notice -- TS for %s " | |
634 | "changed from %ld to 0", | |
635 | me.name, chptr->chname, chptr->chname, (long) oldts); | |
636 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
637 | "Server %s changing TS on %s from %ld to 0", | |
638 | source_p->name, chptr->chname, (long) oldts); | |
639 | } | |
640 | #endif | |
641 | ||
642 | if(isnew) | |
643 | chptr->channelts = newts; | |
55abcbb2 | 644 | |
8cc12805 VY |
645 | else if(newts == 0 || oldts == 0) |
646 | chptr->channelts = 0; | |
647 | else if(newts == oldts) | |
648 | ; | |
649 | else if(newts < oldts) | |
650 | { | |
651 | /* If configured, kick people trying to join +i/+k | |
652 | * channels by recreating them on split servers. | |
a1574df4 JT |
653 | * If the source has sent EOB, assume this is some |
654 | * sort of hack by services. If cmode +i is set, | |
655 | * services can send kicks if needed; if the key | |
656 | * differs, services cannot kick in a race-free | |
657 | * manner so do so here. | |
8cc12805 VY |
658 | * -- jilles */ |
659 | if (ConfigChannel.kick_on_split_riding && | |
a1574df4 JT |
660 | ((!HasSentEob(source_p) && |
661 | mode.mode & MODE_INVITEONLY) || | |
8cc12805 VY |
662 | (mode.key[0] != 0 && irccmp(mode.key, oldmode->key) != 0))) |
663 | { | |
664 | struct membership *msptr; | |
665 | struct Client *who; | |
666 | int l = rb_dlink_list_length(&chptr->members); | |
8cc12805 VY |
667 | |
668 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) | |
669 | { | |
670 | msptr = ptr->data; | |
671 | who = msptr->client_p; | |
672 | sendto_one(who, ":%s KICK %s %s :Net Rider", | |
673 | me.name, chptr->chname, who->name); | |
674 | ||
675 | sendto_server(NULL, chptr, CAP_TS6, NOCAPS, | |
676 | ":%s KICK %s %s :Net Rider", | |
677 | me.id, chptr->chname, | |
678 | who->id); | |
8cc12805 VY |
679 | remove_user_from_channel(msptr); |
680 | if (--l == 0) | |
681 | break; | |
682 | } | |
683 | if (l == 0) | |
684 | { | |
685 | /* Channel was emptied, create a new one */ | |
686 | if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) | |
687 | return 0; /* oops! */ | |
688 | ||
8cc12805 VY |
689 | oldmode = &chptr->mode; |
690 | } | |
691 | } | |
692 | keep_our_modes = NO; | |
693 | chptr->channelts = newts; | |
694 | } | |
695 | else | |
696 | keep_new_modes = NO; | |
697 | ||
698 | if(!keep_new_modes) | |
699 | mode = *oldmode; | |
700 | else if(keep_our_modes) | |
701 | { | |
702 | mode.mode |= oldmode->mode; | |
703 | if(oldmode->limit > mode.limit) | |
704 | mode.limit = oldmode->limit; | |
705 | if(strcmp(mode.key, oldmode->key) < 0) | |
706 | strcpy(mode.key, oldmode->key); | |
707 | if(oldmode->join_num > mode.join_num || | |
708 | (oldmode->join_num == mode.join_num && | |
709 | oldmode->join_time > mode.join_time)) | |
710 | { | |
711 | mode.join_num = oldmode->join_num; | |
712 | mode.join_time = oldmode->join_time; | |
713 | } | |
714 | if(irccmp(mode.forward, oldmode->forward) < 0) | |
715 | strcpy(mode.forward, oldmode->forward); | |
716 | } | |
717 | else | |
718 | { | |
719 | /* If setting -j, clear join throttle state -- jilles */ | |
720 | if (!mode.join_num) | |
721 | chptr->join_count = chptr->join_delta = 0; | |
722 | } | |
723 | ||
724 | set_final_mode(&mode, oldmode); | |
725 | chptr->mode = mode; | |
726 | ||
727 | /* Lost the TS, other side wins, so remove modes on this side */ | |
728 | if(!keep_our_modes) | |
729 | { | |
730 | remove_our_modes(chptr, fakesource_p); | |
731 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) | |
732 | { | |
733 | del_invite(chptr, ptr->data); | |
734 | } | |
7b22c84f JT |
735 | |
736 | if(rb_dlink_list_length(&chptr->banlist) > 0) | |
737 | remove_ban_list(chptr, fakesource_p, &chptr->banlist, 'b', ALL_MEMBERS); | |
738 | if(rb_dlink_list_length(&chptr->exceptlist) > 0) | |
739 | remove_ban_list(chptr, fakesource_p, &chptr->exceptlist, | |
740 | 'e', ONLY_CHANOPS); | |
741 | if(rb_dlink_list_length(&chptr->invexlist) > 0) | |
742 | remove_ban_list(chptr, fakesource_p, &chptr->invexlist, | |
743 | 'I', ONLY_CHANOPS); | |
744 | if(rb_dlink_list_length(&chptr->quietlist) > 0) | |
745 | remove_ban_list(chptr, fakesource_p, &chptr->quietlist, | |
746 | 'q', ALL_MEMBERS); | |
747 | chptr->bants++; | |
748 | ||
8cc12805 VY |
749 | sendto_channel_local(ALL_MEMBERS, chptr, |
750 | ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld", | |
751 | me.name, chptr->chname, chptr->chname, | |
752 | (long) oldts, (long) newts); | |
753 | /* Update capitalization in channel name, this makes the | |
754 | * capitalization timestamped like modes are -- jilles */ | |
755 | strcpy(chptr->chname, parv[2]); | |
6fb6bd15 AC |
756 | |
757 | /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */ | |
758 | set_channel_mlock(client_p, source_p, chptr, NULL, FALSE); | |
8cc12805 VY |
759 | } |
760 | ||
761 | if(*modebuf != '\0') | |
762 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s %s %s", | |
763 | fakesource_p->name, chptr->chname, modebuf, parabuf); | |
764 | ||
765 | *modebuf = *parabuf = '\0'; | |
766 | ||
767 | if(parv[3][0] != '0' && keep_new_modes) | |
768 | modes = channel_modes(chptr, source_p); | |
769 | else | |
770 | modes = empty_modes; | |
771 | ||
5203cba5 | 772 | mlen_uid = sprintf(buf_uid, ":%s SJOIN %ld %s %s :", |
8cc12805 VY |
773 | use_id(source_p), (long) chptr->channelts, parv[2], modes); |
774 | ptr_uid = buf_uid + mlen_uid; | |
775 | ||
776 | mbuf = modebuf; | |
777 | para[0] = para[1] = para[2] = para[3] = empty; | |
778 | pargs = 0; | |
40709472 | 779 | len_uid = 0; |
8cc12805 VY |
780 | |
781 | /* if theres a space, theres going to be more than one nick, change the | |
782 | * first space to \0, so s is just the first nick, and point p to the | |
783 | * second nick | |
784 | */ | |
785 | if((p = strchr(s, ' ')) != NULL) | |
786 | { | |
787 | *p++ = '\0'; | |
788 | } | |
789 | ||
790 | *mbuf++ = '+'; | |
791 | ||
792 | while (s) | |
793 | { | |
794 | fl = 0; | |
795 | ||
796 | for (i = 0; i < 2; i++) | |
797 | { | |
798 | if(*s == '@') | |
799 | { | |
800 | fl |= CHFL_CHANOP; | |
801 | s++; | |
802 | } | |
803 | else if(*s == '+') | |
804 | { | |
805 | fl |= CHFL_VOICE; | |
806 | s++; | |
807 | } | |
808 | } | |
809 | ||
810 | /* if the client doesnt exist or is fake direction, skip. */ | |
811 | if(!(target_p = find_client(s)) || | |
812 | (target_p->from != client_p) || !IsPerson(target_p)) | |
813 | goto nextnick; | |
814 | ||
815 | /* we assume for these we can fit at least one nick/uid in.. */ | |
816 | ||
817 | /* check we can fit another status+nick+space into a buffer */ | |
8cc12805 VY |
818 | if((mlen_uid + len_uid + IDLEN + 3) > (BUFSIZE - 3)) |
819 | { | |
820 | *(ptr_uid - 1) = '\0'; | |
821 | sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid); | |
822 | ptr_uid = buf_uid + mlen_uid; | |
823 | len_uid = 0; | |
824 | } | |
825 | ||
826 | if(keep_new_modes) | |
827 | { | |
828 | if(fl & CHFL_CHANOP) | |
829 | { | |
8cc12805 | 830 | *ptr_uid++ = '@'; |
8cc12805 VY |
831 | len_uid++; |
832 | } | |
833 | if(fl & CHFL_VOICE) | |
834 | { | |
8cc12805 | 835 | *ptr_uid++ = '+'; |
8cc12805 VY |
836 | len_uid++; |
837 | } | |
838 | } | |
839 | ||
840 | /* copy the nick to the two buffers */ | |
5203cba5 | 841 | len = sprintf(ptr_uid, "%s ", use_id(target_p)); |
8cc12805 VY |
842 | ptr_uid += len; |
843 | len_uid += len; | |
844 | ||
845 | if(!keep_new_modes) | |
846 | fl = 0; | |
847 | ||
848 | if(!IsMember(target_p, chptr)) | |
849 | { | |
850 | add_user_to_channel(chptr, target_p, fl); | |
805cfa5a | 851 | send_channel_join(chptr, target_p); |
8cc12805 VY |
852 | joins++; |
853 | } | |
854 | ||
855 | if(fl & CHFL_CHANOP) | |
856 | { | |
857 | *mbuf++ = 'o'; | |
858 | para[pargs++] = target_p->name; | |
859 | ||
860 | /* a +ov user.. bleh */ | |
861 | if(fl & CHFL_VOICE) | |
862 | { | |
863 | /* its possible the +o has filled up MAXMODEPARAMS, if so, start | |
864 | * a new buffer | |
865 | */ | |
866 | if(pargs >= MAXMODEPARAMS) | |
867 | { | |
868 | *mbuf = '\0'; | |
869 | sendto_channel_local(ALL_MEMBERS, chptr, | |
870 | ":%s MODE %s %s %s %s %s %s", | |
871 | fakesource_p->name, chptr->chname, | |
872 | modebuf, | |
873 | para[0], para[1], para[2], para[3]); | |
874 | mbuf = modebuf; | |
875 | *mbuf++ = '+'; | |
876 | para[0] = para[1] = para[2] = para[3] = NULL; | |
877 | pargs = 0; | |
878 | } | |
879 | ||
880 | *mbuf++ = 'v'; | |
881 | para[pargs++] = target_p->name; | |
882 | } | |
883 | } | |
884 | else if(fl & CHFL_VOICE) | |
885 | { | |
886 | *mbuf++ = 'v'; | |
887 | para[pargs++] = target_p->name; | |
888 | } | |
889 | ||
890 | if(pargs >= MAXMODEPARAMS) | |
891 | { | |
892 | *mbuf = '\0'; | |
893 | sendto_channel_local(ALL_MEMBERS, chptr, | |
894 | ":%s MODE %s %s %s %s %s %s", | |
895 | fakesource_p->name, | |
896 | chptr->chname, | |
897 | modebuf, para[0], para[1], para[2], para[3]); | |
898 | mbuf = modebuf; | |
899 | *mbuf++ = '+'; | |
900 | para[0] = para[1] = para[2] = para[3] = NULL; | |
901 | pargs = 0; | |
902 | } | |
903 | ||
904 | nextnick: | |
905 | /* p points to the next nick */ | |
906 | s = p; | |
907 | ||
908 | /* if there was a trailing space and p was pointing to it, then we | |
909 | * need to exit.. this has the side effect of breaking double spaces | |
910 | * in an sjoin.. but that shouldnt happen anyway | |
911 | */ | |
912 | if(s && (*s == '\0')) | |
913 | s = p = NULL; | |
914 | ||
915 | /* if p was NULL due to no spaces, s wont exist due to the above, so | |
916 | * we cant check it for spaces.. if there are no spaces, then when | |
917 | * we next get here, s will be NULL | |
918 | */ | |
919 | if(s && ((p = strchr(s, ' ')) != NULL)) | |
920 | { | |
921 | *p++ = '\0'; | |
922 | } | |
923 | } | |
924 | ||
925 | *mbuf = '\0'; | |
926 | if(pargs) | |
927 | { | |
928 | sendto_channel_local(ALL_MEMBERS, chptr, | |
929 | ":%s MODE %s %s %s %s %s %s", | |
930 | fakesource_p->name, chptr->chname, modebuf, | |
931 | para[0], CheckEmpty(para[1]), | |
932 | CheckEmpty(para[2]), CheckEmpty(para[3])); | |
933 | } | |
934 | ||
935 | if(!joins && !(chptr->mode.mode & MODE_PERMANENT) && isnew) | |
936 | { | |
937 | destroy_channel(chptr); | |
938 | ||
939 | return 0; | |
940 | } | |
941 | ||
942 | /* Keep the colon if we're sending an SJOIN without nicks -- jilles */ | |
943 | if (joins) | |
944 | { | |
8cc12805 VY |
945 | *(ptr_uid - 1) = '\0'; |
946 | } | |
947 | ||
948 | sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid); | |
8cc12805 | 949 | |
8cc12805 VY |
950 | return 0; |
951 | } | |
952 | ||
f4a80ce6 JT |
953 | /* |
954 | * do_join_0 | |
955 | * | |
956 | * inputs - pointer to client doing join 0 | |
957 | * output - NONE | |
958 | * side effects - Use has decided to join 0. This is legacy | |
959 | * from the days when channels were numbers not names. *sigh* | |
f4a80ce6 JT |
960 | */ |
961 | static void | |
962 | do_join_0(struct Client *client_p, struct Client *source_p) | |
963 | { | |
964 | struct membership *msptr; | |
965 | struct Channel *chptr = NULL; | |
5b96d9a6 | 966 | rb_dlink_node *ptr; |
f4a80ce6 JT |
967 | |
968 | /* Finish the flood grace period... */ | |
969 | if(MyClient(source_p) && !IsFloodDone(source_p)) | |
970 | flood_endgrace(source_p); | |
971 | ||
f4a80ce6 | 972 | sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s JOIN 0", use_id(source_p)); |
f4a80ce6 | 973 | |
f4a80ce6 JT |
974 | while((ptr = source_p->user->channel.head)) |
975 | { | |
4eb9a3ca JT |
976 | if(MyConnect(source_p) && |
977 | !IsOper(source_p) && !IsExemptSpambot(source_p)) | |
978 | check_spambot_warning(source_p, NULL); | |
979 | ||
f4a80ce6 JT |
980 | msptr = ptr->data; |
981 | chptr = msptr->chptr; | |
982 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", | |
983 | source_p->name, | |
984 | source_p->username, source_p->host, chptr->chname); | |
985 | remove_user_from_channel(msptr); | |
986 | } | |
987 | } | |
988 | ||
212380e3 AC |
989 | static int |
990 | check_channel_name_loc(struct Client *source_p, const char *name) | |
991 | { | |
6865c0b0 JT |
992 | const char *p; |
993 | ||
212380e3 AC |
994 | s_assert(name != NULL); |
995 | if(EmptyString(name)) | |
996 | return 0; | |
997 | ||
998 | if(ConfigFileEntry.disable_fake_channels && !IsOper(source_p)) | |
999 | { | |
6865c0b0 | 1000 | for(p = name; *p; ++p) |
212380e3 | 1001 | { |
6865c0b0 | 1002 | if(!IsChanChar(*p) || IsFakeChanChar(*p)) |
212380e3 AC |
1003 | return 0; |
1004 | } | |
1005 | } | |
1006 | else | |
1007 | { | |
6865c0b0 | 1008 | for(p = name; *p; ++p) |
212380e3 | 1009 | { |
6865c0b0 | 1010 | if(!IsChanChar(*p)) |
212380e3 AC |
1011 | return 0; |
1012 | } | |
1013 | } | |
1014 | ||
6865c0b0 JT |
1015 | if(ConfigChannel.only_ascii_channels) |
1016 | { | |
1017 | for(p = name; *p; ++p) | |
1018 | if(*p < 33 || *p > 126) | |
1019 | return 0; | |
1020 | } | |
1021 | ||
212380e3 AC |
1022 | return 1; |
1023 | } | |
1024 | ||
35bfe0e6 JT |
1025 | /* send_join_error() |
1026 | * | |
1027 | * input - client to send to, reason, channel name | |
1028 | * output - none | |
1029 | * side effects - error message sent to client | |
1030 | */ | |
1031 | static void | |
1032 | send_join_error(struct Client *source_p, int numeric, const char *name) | |
1033 | { | |
1034 | /* This stuff is necessary because the form_str macro only | |
1035 | * accepts constants. | |
1036 | */ | |
1037 | switch (numeric) | |
1038 | { | |
1039 | #define NORMAL_NUMERIC(i) \ | |
1040 | case i: \ | |
1041 | sendto_one(source_p, form_str(i), \ | |
1042 | me.name, source_p->name, name); \ | |
1043 | break | |
1044 | ||
1045 | NORMAL_NUMERIC(ERR_BANNEDFROMCHAN); | |
1046 | NORMAL_NUMERIC(ERR_INVITEONLYCHAN); | |
1047 | NORMAL_NUMERIC(ERR_BADCHANNELKEY); | |
1048 | NORMAL_NUMERIC(ERR_CHANNELISFULL); | |
1049 | NORMAL_NUMERIC(ERR_NEEDREGGEDNICK); | |
1050 | NORMAL_NUMERIC(ERR_THROTTLE); | |
1051 | ||
1052 | default: | |
1053 | sendto_one_numeric(source_p, numeric, | |
1054 | "%s :Cannot join channel", name); | |
1055 | break; | |
1056 | } | |
1057 | } | |
1058 | ||
212380e3 AC |
1059 | static void |
1060 | set_final_mode(struct Mode *mode, struct Mode *oldmode) | |
1061 | { | |
1062 | int dir = MODE_QUERY; | |
1063 | char *pbuf = parabuf; | |
1064 | int len; | |
1065 | int i; | |
1066 | ||
1067 | /* ok, first get a list of modes we need to add */ | |
efccc22c | 1068 | for (i = 0; i < 256; i++) |
212380e3 | 1069 | { |
efccc22c | 1070 | if((mode->mode & chmode_flags[i]) && !(oldmode->mode & chmode_flags[i])) |
212380e3 AC |
1071 | { |
1072 | if(dir != MODE_ADD) | |
1073 | { | |
1074 | *mbuf++ = '+'; | |
1075 | dir = MODE_ADD; | |
1076 | } | |
efccc22c | 1077 | *mbuf++ = i; |
212380e3 AC |
1078 | } |
1079 | } | |
1080 | ||
1081 | /* now the ones we need to remove. */ | |
efccc22c | 1082 | for (i = 0; i < 256; i++) |
212380e3 | 1083 | { |
efccc22c | 1084 | if((oldmode->mode & chmode_flags[i]) && !(mode->mode & chmode_flags[i])) |
212380e3 AC |
1085 | { |
1086 | if(dir != MODE_DEL) | |
1087 | { | |
1088 | *mbuf++ = '-'; | |
1089 | dir = MODE_DEL; | |
1090 | } | |
efccc22c | 1091 | *mbuf++ = i; |
212380e3 AC |
1092 | } |
1093 | } | |
1094 | ||
1095 | if(oldmode->limit && !mode->limit) | |
1096 | { | |
1097 | if(dir != MODE_DEL) | |
1098 | { | |
1099 | *mbuf++ = '-'; | |
1100 | dir = MODE_DEL; | |
1101 | } | |
1102 | *mbuf++ = 'l'; | |
1103 | } | |
1104 | if(oldmode->key[0] && !mode->key[0]) | |
1105 | { | |
1106 | if(dir != MODE_DEL) | |
1107 | { | |
1108 | *mbuf++ = '-'; | |
1109 | dir = MODE_DEL; | |
1110 | } | |
1111 | *mbuf++ = 'k'; | |
5203cba5 | 1112 | len = sprintf(pbuf, "%s ", oldmode->key); |
212380e3 AC |
1113 | pbuf += len; |
1114 | } | |
1115 | if(oldmode->join_num && !mode->join_num) | |
1116 | { | |
1117 | if(dir != MODE_DEL) | |
1118 | { | |
1119 | *mbuf++ = '-'; | |
1120 | dir = MODE_DEL; | |
1121 | } | |
1122 | *mbuf++ = 'j'; | |
1123 | } | |
1124 | if(oldmode->forward[0] && !mode->forward[0]) | |
1125 | { | |
1126 | if(dir != MODE_DEL) | |
1127 | { | |
1128 | *mbuf++ = '-'; | |
1129 | dir = MODE_DEL; | |
1130 | } | |
1131 | *mbuf++ = 'f'; | |
1132 | } | |
1133 | if(mode->limit && oldmode->limit != mode->limit) | |
1134 | { | |
1135 | if(dir != MODE_ADD) | |
1136 | { | |
1137 | *mbuf++ = '+'; | |
1138 | dir = MODE_ADD; | |
1139 | } | |
1140 | *mbuf++ = 'l'; | |
5203cba5 | 1141 | len = sprintf(pbuf, "%d ", mode->limit); |
212380e3 AC |
1142 | pbuf += len; |
1143 | } | |
1144 | if(mode->key[0] && strcmp(oldmode->key, mode->key)) | |
1145 | { | |
1146 | if(dir != MODE_ADD) | |
1147 | { | |
1148 | *mbuf++ = '+'; | |
1149 | dir = MODE_ADD; | |
1150 | } | |
1151 | *mbuf++ = 'k'; | |
5203cba5 | 1152 | len = sprintf(pbuf, "%s ", mode->key); |
212380e3 AC |
1153 | pbuf += len; |
1154 | } | |
1155 | if(mode->join_num && (oldmode->join_num != mode->join_num || oldmode->join_time != mode->join_time)) | |
1156 | { | |
1157 | if(dir != MODE_ADD) | |
1158 | { | |
1159 | *mbuf++ = '+'; | |
1160 | dir = MODE_ADD; | |
1161 | } | |
1162 | *mbuf++ = 'j'; | |
5203cba5 | 1163 | len = sprintf(pbuf, "%d:%d ", mode->join_num, mode->join_time); |
212380e3 AC |
1164 | pbuf += len; |
1165 | } | |
2da6f6eb JT |
1166 | if(mode->forward[0] && strcmp(oldmode->forward, mode->forward) && |
1167 | ConfigChannel.use_forward) | |
212380e3 AC |
1168 | { |
1169 | if(dir != MODE_ADD) | |
1170 | { | |
1171 | *mbuf++ = '+'; | |
1172 | dir = MODE_ADD; | |
1173 | } | |
1174 | *mbuf++ = 'f'; | |
5203cba5 | 1175 | len = sprintf(pbuf, "%s ", mode->forward); |
212380e3 AC |
1176 | pbuf += len; |
1177 | } | |
1178 | *mbuf = '\0'; | |
1179 | } | |
1180 | ||
1181 | /* | |
1182 | * remove_our_modes | |
1183 | * | |
1184 | * inputs - | |
55abcbb2 KB |
1185 | * output - |
1186 | * side effects - | |
212380e3 AC |
1187 | */ |
1188 | static void | |
1189 | remove_our_modes(struct Channel *chptr, struct Client *source_p) | |
1190 | { | |
1191 | struct membership *msptr; | |
5b96d9a6 | 1192 | rb_dlink_node *ptr; |
212380e3 AC |
1193 | char lmodebuf[MODEBUFLEN]; |
1194 | char *lpara[MAXMODEPARAMS]; | |
1195 | int count = 0; | |
1196 | int i; | |
1197 | ||
1198 | mbuf = lmodebuf; | |
1199 | *mbuf++ = '-'; | |
1200 | ||
1201 | for(i = 0; i < MAXMODEPARAMS; i++) | |
1202 | lpara[i] = NULL; | |
1203 | ||
5b96d9a6 | 1204 | RB_DLINK_FOREACH(ptr, chptr->members.head) |
212380e3 AC |
1205 | { |
1206 | msptr = ptr->data; | |
1207 | ||
1208 | if(is_chanop(msptr)) | |
1209 | { | |
1210 | msptr->flags &= ~CHFL_CHANOP; | |
1211 | lpara[count++] = msptr->client_p->name; | |
1212 | *mbuf++ = 'o'; | |
1213 | ||
1214 | /* +ov, might not fit so check. */ | |
1215 | if(is_voiced(msptr)) | |
1216 | { | |
1217 | if(count >= MAXMODEPARAMS) | |
1218 | { | |
1219 | *mbuf = '\0'; | |
1220 | sendto_channel_local(ALL_MEMBERS, chptr, | |
1221 | ":%s MODE %s %s %s %s %s %s", | |
7bf78de0 | 1222 | source_p->name, chptr->chname, |
212380e3 AC |
1223 | lmodebuf, lpara[0], lpara[1], |
1224 | lpara[2], lpara[3]); | |
1225 | ||
1226 | /* preserve the initial '-' */ | |
1227 | mbuf = lmodebuf; | |
1228 | *mbuf++ = '-'; | |
1229 | count = 0; | |
1230 | ||
1231 | for(i = 0; i < MAXMODEPARAMS; i++) | |
1232 | lpara[i] = NULL; | |
1233 | } | |
1234 | ||
1235 | msptr->flags &= ~CHFL_VOICE; | |
1236 | lpara[count++] = msptr->client_p->name; | |
1237 | *mbuf++ = 'v'; | |
1238 | } | |
1239 | } | |
1240 | else if(is_voiced(msptr)) | |
1241 | { | |
1242 | msptr->flags &= ~CHFL_VOICE; | |
1243 | lpara[count++] = msptr->client_p->name; | |
1244 | *mbuf++ = 'v'; | |
1245 | } | |
1246 | else | |
1247 | continue; | |
1248 | ||
1249 | if(count >= MAXMODEPARAMS) | |
1250 | { | |
1251 | *mbuf = '\0'; | |
1252 | sendto_channel_local(ALL_MEMBERS, chptr, | |
1253 | ":%s MODE %s %s %s %s %s %s", | |
7bf78de0 | 1254 | source_p->name, chptr->chname, lmodebuf, |
212380e3 AC |
1255 | lpara[0], lpara[1], lpara[2], lpara[3]); |
1256 | mbuf = lmodebuf; | |
1257 | *mbuf++ = '-'; | |
1258 | count = 0; | |
1259 | ||
1260 | for(i = 0; i < MAXMODEPARAMS; i++) | |
1261 | lpara[i] = NULL; | |
1262 | } | |
1263 | } | |
1264 | ||
1265 | if(count != 0) | |
1266 | { | |
1267 | *mbuf = '\0'; | |
1268 | sendto_channel_local(ALL_MEMBERS, chptr, | |
1269 | ":%s MODE %s %s %s %s %s %s", | |
7bf78de0 | 1270 | source_p->name, chptr->chname, lmodebuf, |
212380e3 AC |
1271 | EmptyString(lpara[0]) ? "" : lpara[0], |
1272 | EmptyString(lpara[1]) ? "" : lpara[1], | |
1273 | EmptyString(lpara[2]) ? "" : lpara[2], | |
1274 | EmptyString(lpara[3]) ? "" : lpara[3]); | |
1275 | ||
1276 | } | |
1277 | } | |
8cc12805 VY |
1278 | |
1279 | /* remove_ban_list() | |
1280 | * | |
1281 | * inputs - channel, source, list to remove, char of mode, caps needed | |
1282 | * outputs - | |
1283 | * side effects - given list is removed, with modes issued to local clients | |
8cc12805 VY |
1284 | */ |
1285 | static void | |
1286 | remove_ban_list(struct Channel *chptr, struct Client *source_p, | |
8afeb720 | 1287 | rb_dlink_list * list, char c, int mems) |
8cc12805 VY |
1288 | { |
1289 | static char lmodebuf[BUFSIZE]; | |
1290 | static char lparabuf[BUFSIZE]; | |
1291 | struct Ban *banptr; | |
1292 | rb_dlink_node *ptr; | |
1293 | rb_dlink_node *next_ptr; | |
1294 | char *pbuf; | |
1295 | int count = 0; | |
1296 | int cur_len, mlen, plen; | |
1297 | ||
1298 | pbuf = lparabuf; | |
1299 | ||
5203cba5 | 1300 | cur_len = mlen = sprintf(lmodebuf, ":%s MODE %s -", source_p->name, chptr->chname); |
8cc12805 VY |
1301 | mbuf = lmodebuf + mlen; |
1302 | ||
1303 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) | |
1304 | { | |
1305 | banptr = ptr->data; | |
1306 | ||
1307 | /* trailing space, and the mode letter itself */ | |
23f6b63a JT |
1308 | plen = strlen(banptr->banstr) + |
1309 | (banptr->forward ? strlen(banptr->forward) + 1 : 0) + 2; | |
8cc12805 VY |
1310 | |
1311 | if(count >= MAXMODEPARAMS || (cur_len + plen) > BUFSIZE - 4) | |
1312 | { | |
1313 | /* remove trailing space */ | |
1314 | *mbuf = '\0'; | |
1315 | *(pbuf - 1) = '\0'; | |
1316 | ||
1317 | sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf); | |
8cc12805 VY |
1318 | |
1319 | cur_len = mlen; | |
1320 | mbuf = lmodebuf + mlen; | |
1321 | pbuf = lparabuf; | |
1322 | count = 0; | |
1323 | } | |
1324 | ||
1325 | *mbuf++ = c; | |
1326 | cur_len += plen; | |
23f6b63a | 1327 | if (banptr->forward) |
5203cba5 | 1328 | pbuf += sprintf(pbuf, "%s$%s ", banptr->banstr, banptr->forward); |
23f6b63a | 1329 | else |
5203cba5 | 1330 | pbuf += sprintf(pbuf, "%s ", banptr->banstr); |
8cc12805 VY |
1331 | count++; |
1332 | ||
1333 | free_ban(banptr); | |
1334 | } | |
1335 | ||
1336 | *mbuf = '\0'; | |
1337 | *(pbuf - 1) = '\0'; | |
1338 | sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf); | |
8cc12805 VY |
1339 | |
1340 | list->head = list->tail = NULL; | |
1341 | list->length = 0; | |
1342 | } |