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