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