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