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