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