]>
Commit | Line | Data |
---|---|---|
212380e3 | 1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * channel.c: Controls channels. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
83294285 | 24 | * $Id: channel.c 3580 2007-11-07 23:45:14Z jilles $ |
212380e3 | 25 | */ |
26 | ||
27 | #include "stdinc.h" | |
212380e3 | 28 | #include "channel.h" |
fba62b01 | 29 | #include "chmode.h" |
212380e3 | 30 | #include "client.h" |
31 | #include "common.h" | |
32 | #include "hash.h" | |
33 | #include "hook.h" | |
13ae2f4b | 34 | #include "match.h" |
212380e3 | 35 | #include "ircd.h" |
36 | #include "numeric.h" | |
37 | #include "s_serv.h" /* captab */ | |
38 | #include "s_user.h" | |
39 | #include "send.h" | |
40 | #include "whowas.h" | |
41 | #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */ | |
42 | #include "s_newconf.h" | |
d3455e2c | 43 | #include "logger.h" |
3472ff3f | 44 | #include "packet.h" |
212380e3 | 45 | |
9813daca | 46 | struct config_channel_entry ConfigChannel; |
1a218aaf | 47 | rb_dlink_list global_channel_list; |
5475a932 VY |
48 | static rb_bh *channel_heap; |
49 | static rb_bh *ban_heap; | |
50 | static rb_bh *topic_heap; | |
51 | static rb_bh *member_heap; | |
52 | ||
212380e3 | 53 | static int channel_capabs[] = { CAP_EX, CAP_IE, |
54 | CAP_SERVICE, | |
55 | CAP_TS6 | |
56 | }; | |
57 | ||
58 | #define NCHCAPS (sizeof(channel_capabs)/sizeof(int)) | |
59 | #define NCHCAP_COMBOS (1 << NCHCAPS) | |
60 | ||
61 | static struct ChCapCombo chcap_combos[NCHCAP_COMBOS]; | |
62 | ||
63 | static void free_topic(struct Channel *chptr); | |
64 | ||
65 | static int h_can_join; | |
67b90240 JH |
66 | static int h_can_create_channel; |
67 | static int h_channel_join; | |
212380e3 | 68 | |
69 | /* init_channels() | |
70 | * | |
71 | * input - | |
72 | * output - | |
73 | * side effects - initialises the various blockheaps | |
74 | */ | |
75 | void | |
76 | init_channels(void) | |
77 | { | |
dd9be678 WP |
78 | channel_heap = rb_bh_create(sizeof(struct Channel), CHANNEL_HEAP_SIZE, "channel_heap"); |
79 | ban_heap = rb_bh_create(sizeof(struct Ban), BAN_HEAP_SIZE, "ban_heap"); | |
80 | topic_heap = rb_bh_create(TOPICLEN + 1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE, "topic_heap"); | |
81 | member_heap = rb_bh_create(sizeof(struct membership), MEMBER_HEAP_SIZE, "member_heap"); | |
212380e3 | 82 | |
83 | h_can_join = register_hook("can_join"); | |
67b90240 JH |
84 | h_channel_join = register_hook("channel_join"); |
85 | h_can_create_channel = register_hook("can_create_channel"); | |
212380e3 | 86 | } |
87 | ||
88 | /* | |
89 | * allocate_channel - Allocates a channel | |
90 | */ | |
91 | struct Channel * | |
92 | allocate_channel(const char *chname) | |
93 | { | |
94 | struct Channel *chptr; | |
6e9b4415 | 95 | chptr = rb_bh_alloc(channel_heap); |
62d28946 | 96 | chptr->chname = rb_strdup(chname); |
212380e3 | 97 | return (chptr); |
98 | } | |
99 | ||
100 | void | |
101 | free_channel(struct Channel *chptr) | |
102 | { | |
90a3c35b | 103 | rb_free(chptr->chname); |
6e9b4415 | 104 | rb_bh_free(channel_heap, chptr); |
212380e3 | 105 | } |
106 | ||
107 | struct Ban * | |
108 | allocate_ban(const char *banstr, const char *who) | |
109 | { | |
110 | struct Ban *bptr; | |
6e9b4415 | 111 | bptr = rb_bh_alloc(ban_heap); |
62d28946 VY |
112 | bptr->banstr = rb_strdup(banstr); |
113 | bptr->who = rb_strdup(who); | |
212380e3 | 114 | |
115 | return (bptr); | |
116 | } | |
117 | ||
118 | void | |
119 | free_ban(struct Ban *bptr) | |
120 | { | |
90a3c35b VY |
121 | rb_free(bptr->banstr); |
122 | rb_free(bptr->who); | |
6e9b4415 | 123 | rb_bh_free(ban_heap, bptr); |
212380e3 | 124 | } |
125 | ||
126 | ||
127 | /* find_channel_membership() | |
128 | * | |
129 | * input - channel to find them in, client to find | |
130 | * output - membership of client in channel, else NULL | |
131 | * side effects - | |
132 | */ | |
133 | struct membership * | |
134 | find_channel_membership(struct Channel *chptr, struct Client *client_p) | |
135 | { | |
136 | struct membership *msptr; | |
af81d5a0 | 137 | rb_dlink_node *ptr; |
212380e3 | 138 | |
139 | if(!IsClient(client_p)) | |
140 | return NULL; | |
141 | ||
142 | /* Pick the most efficient list to use to be nice to things like | |
143 | * CHANSERV which could be in a large number of channels | |
144 | */ | |
af81d5a0 | 145 | if(rb_dlink_list_length(&chptr->members) < rb_dlink_list_length(&client_p->user->channel)) |
212380e3 | 146 | { |
8e69bb4e | 147 | RB_DLINK_FOREACH(ptr, chptr->members.head) |
212380e3 | 148 | { |
149 | msptr = ptr->data; | |
150 | ||
151 | if(msptr->client_p == client_p) | |
152 | return msptr; | |
153 | } | |
154 | } | |
155 | else | |
156 | { | |
8e69bb4e | 157 | RB_DLINK_FOREACH(ptr, client_p->user->channel.head) |
212380e3 | 158 | { |
159 | msptr = ptr->data; | |
160 | ||
161 | if(msptr->chptr == chptr) | |
162 | return msptr; | |
163 | } | |
164 | } | |
165 | ||
166 | return NULL; | |
167 | } | |
168 | ||
169 | /* find_channel_status() | |
170 | * | |
171 | * input - membership to get status for, whether we can combine flags | |
172 | * output - flags of user on channel | |
173 | * side effects - | |
174 | */ | |
175 | const char * | |
176 | find_channel_status(struct membership *msptr, int combine) | |
177 | { | |
178 | static char buffer[3]; | |
179 | char *p; | |
180 | ||
181 | p = buffer; | |
182 | ||
183 | if(is_chanop(msptr)) | |
184 | { | |
185 | if(!combine) | |
186 | return "@"; | |
187 | *p++ = '@'; | |
188 | } | |
189 | ||
190 | if(is_voiced(msptr)) | |
191 | *p++ = '+'; | |
192 | ||
193 | *p = '\0'; | |
194 | return buffer; | |
195 | } | |
196 | ||
197 | /* add_user_to_channel() | |
198 | * | |
199 | * input - channel to add client to, client to add, channel flags | |
200 | * output - | |
201 | * side effects - user is added to channel | |
202 | */ | |
203 | void | |
204 | add_user_to_channel(struct Channel *chptr, struct Client *client_p, int flags) | |
205 | { | |
206 | struct membership *msptr; | |
207 | ||
208 | s_assert(client_p->user != NULL); | |
209 | if(client_p->user == NULL) | |
210 | return; | |
211 | ||
6e9b4415 | 212 | msptr = rb_bh_alloc(member_heap); |
212380e3 | 213 | |
214 | msptr->chptr = chptr; | |
215 | msptr->client_p = client_p; | |
216 | msptr->flags = flags; | |
217 | ||
af81d5a0 WP |
218 | rb_dlinkAdd(msptr, &msptr->usernode, &client_p->user->channel); |
219 | rb_dlinkAdd(msptr, &msptr->channode, &chptr->members); | |
212380e3 | 220 | |
221 | if(MyClient(client_p)) | |
af81d5a0 | 222 | rb_dlinkAdd(msptr, &msptr->locchannode, &chptr->locmembers); |
212380e3 | 223 | } |
224 | ||
225 | /* remove_user_from_channel() | |
226 | * | |
227 | * input - membership pointer to remove from channel | |
228 | * output - | |
229 | * side effects - membership (thus user) is removed from channel | |
230 | */ | |
231 | void | |
232 | remove_user_from_channel(struct membership *msptr) | |
233 | { | |
234 | struct Client *client_p; | |
235 | struct Channel *chptr; | |
236 | s_assert(msptr != NULL); | |
237 | if(msptr == NULL) | |
238 | return; | |
239 | ||
240 | client_p = msptr->client_p; | |
241 | chptr = msptr->chptr; | |
242 | ||
af81d5a0 WP |
243 | rb_dlinkDelete(&msptr->usernode, &client_p->user->channel); |
244 | rb_dlinkDelete(&msptr->channode, &chptr->members); | |
212380e3 | 245 | |
246 | if(client_p->servptr == &me) | |
af81d5a0 | 247 | rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); |
212380e3 | 248 | |
af81d5a0 | 249 | if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) |
212380e3 | 250 | destroy_channel(chptr); |
251 | ||
6e9b4415 | 252 | rb_bh_free(member_heap, msptr); |
212380e3 | 253 | |
254 | return; | |
255 | } | |
256 | ||
257 | /* remove_user_from_channels() | |
258 | * | |
259 | * input - user to remove from all channels | |
260 | * output - | |
261 | * side effects - user is removed from all channels | |
262 | */ | |
263 | void | |
264 | remove_user_from_channels(struct Client *client_p) | |
265 | { | |
266 | struct Channel *chptr; | |
267 | struct membership *msptr; | |
af81d5a0 | 268 | rb_dlink_node *ptr; |
90a3c35b | 269 | rb_dlink_node *next_ptr; |
212380e3 | 270 | |
271 | if(client_p == NULL) | |
272 | return; | |
273 | ||
90a3c35b | 274 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->user->channel.head) |
212380e3 | 275 | { |
276 | msptr = ptr->data; | |
277 | chptr = msptr->chptr; | |
278 | ||
af81d5a0 | 279 | rb_dlinkDelete(&msptr->channode, &chptr->members); |
212380e3 | 280 | |
281 | if(client_p->servptr == &me) | |
af81d5a0 | 282 | rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); |
212380e3 | 283 | |
af81d5a0 | 284 | if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) |
212380e3 | 285 | destroy_channel(chptr); |
286 | ||
6e9b4415 | 287 | rb_bh_free(member_heap, msptr); |
212380e3 | 288 | } |
289 | ||
290 | client_p->user->channel.head = client_p->user->channel.tail = NULL; | |
291 | client_p->user->channel.length = 0; | |
292 | } | |
293 | ||
294 | /* invalidate_bancache_user() | |
295 | * | |
296 | * input - user to invalidate ban cache for | |
297 | * output - | |
298 | * side effects - ban cache is invalidated for all memberships of that user | |
299 | * to be used after a nick change | |
300 | */ | |
301 | void | |
302 | invalidate_bancache_user(struct Client *client_p) | |
303 | { | |
304 | struct membership *msptr; | |
af81d5a0 | 305 | rb_dlink_node *ptr; |
212380e3 | 306 | |
307 | if(client_p == NULL) | |
308 | return; | |
309 | ||
8e69bb4e | 310 | RB_DLINK_FOREACH(ptr, client_p->user->channel.head) |
212380e3 | 311 | { |
312 | msptr = ptr->data; | |
313 | msptr->bants = 0; | |
314 | msptr->flags &= ~CHFL_BANNED; | |
315 | } | |
316 | } | |
317 | ||
318 | /* check_channel_name() | |
319 | * | |
320 | * input - channel name | |
321 | * output - 1 if valid channel name, else 0 | |
322 | * side effects - | |
323 | */ | |
324 | int | |
325 | check_channel_name(const char *name) | |
326 | { | |
327 | s_assert(name != NULL); | |
328 | if(name == NULL) | |
329 | return 0; | |
330 | ||
331 | for (; *name; ++name) | |
332 | { | |
333 | if(!IsChanChar(*name)) | |
334 | return 0; | |
335 | } | |
336 | ||
337 | return 1; | |
338 | } | |
339 | ||
340 | /* free_channel_list() | |
341 | * | |
af81d5a0 | 342 | * input - rb_dlink list to free |
212380e3 | 343 | * output - |
344 | * side effects - list of b/e/I modes is cleared | |
345 | */ | |
346 | void | |
af81d5a0 | 347 | free_channel_list(rb_dlink_list * list) |
212380e3 | 348 | { |
af81d5a0 | 349 | rb_dlink_node *ptr; |
90a3c35b | 350 | rb_dlink_node *next_ptr; |
212380e3 | 351 | struct Ban *actualBan; |
352 | ||
90a3c35b | 353 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) |
212380e3 | 354 | { |
355 | actualBan = ptr->data; | |
356 | free_ban(actualBan); | |
357 | } | |
358 | ||
359 | list->head = list->tail = NULL; | |
360 | list->length = 0; | |
361 | } | |
362 | ||
363 | /* destroy_channel() | |
364 | * | |
365 | * input - channel to destroy | |
366 | * output - | |
367 | * side effects - channel is obliterated | |
368 | */ | |
369 | void | |
370 | destroy_channel(struct Channel *chptr) | |
371 | { | |
90a3c35b | 372 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 373 | |
90a3c35b | 374 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) |
212380e3 | 375 | { |
376 | del_invite(chptr, ptr->data); | |
377 | } | |
378 | ||
379 | /* free all bans/exceptions/denies */ | |
380 | free_channel_list(&chptr->banlist); | |
381 | free_channel_list(&chptr->exceptlist); | |
382 | free_channel_list(&chptr->invexlist); | |
fea1ad52 | 383 | free_channel_list(&chptr->quietlist); |
212380e3 | 384 | |
385 | /* Free the topic */ | |
386 | free_topic(chptr); | |
387 | ||
af81d5a0 | 388 | rb_dlinkDelete(&chptr->node, &global_channel_list); |
212380e3 | 389 | del_from_channel_hash(chptr->chname, chptr); |
390 | free_channel(chptr); | |
391 | } | |
392 | ||
393 | /* channel_pub_or_secret() | |
394 | * | |
395 | * input - channel | |
396 | * output - "=" if public, "@" if secret, else "*" | |
397 | * side effects - | |
398 | */ | |
399 | static const char * | |
400 | channel_pub_or_secret(struct Channel *chptr) | |
401 | { | |
402 | if(PubChannel(chptr)) | |
403 | return ("="); | |
404 | else if(SecretChannel(chptr)) | |
405 | return ("@"); | |
406 | return ("*"); | |
407 | } | |
408 | ||
409 | /* channel_member_names() | |
410 | * | |
411 | * input - channel to list, client to list to, show endofnames | |
412 | * output - | |
413 | * side effects - client is given list of users on channel | |
414 | */ | |
415 | void | |
416 | channel_member_names(struct Channel *chptr, struct Client *client_p, int show_eon) | |
417 | { | |
418 | struct membership *msptr; | |
419 | struct Client *target_p; | |
af81d5a0 | 420 | rb_dlink_node *ptr; |
212380e3 | 421 | char lbuf[BUFSIZE]; |
422 | char *t; | |
423 | int mlen; | |
424 | int tlen; | |
425 | int cur_len; | |
426 | int is_member; | |
427 | int stack = IsCapable(client_p, CLICAP_MULTI_PREFIX); | |
428 | ||
429 | if(ShowChannel(client_p, chptr)) | |
430 | { | |
431 | is_member = IsMember(client_p, chptr); | |
432 | ||
38e6acdd | 433 | cur_len = mlen = rb_sprintf(lbuf, form_str(RPL_NAMREPLY), |
212380e3 | 434 | me.name, client_p->name, |
435 | channel_pub_or_secret(chptr), chptr->chname); | |
436 | ||
437 | t = lbuf + cur_len; | |
438 | ||
8e69bb4e | 439 | RB_DLINK_FOREACH(ptr, chptr->members.head) |
212380e3 | 440 | { |
441 | msptr = ptr->data; | |
442 | target_p = msptr->client_p; | |
443 | ||
444 | if(IsInvisible(target_p) && !is_member) | |
445 | continue; | |
446 | ||
447 | /* space, possible "@+" prefix */ | |
448 | if(cur_len + strlen(target_p->name) + 3 >= BUFSIZE - 3) | |
449 | { | |
450 | *(t - 1) = '\0'; | |
451 | sendto_one(client_p, "%s", lbuf); | |
452 | cur_len = mlen; | |
453 | t = lbuf + mlen; | |
454 | } | |
455 | ||
38e6acdd | 456 | tlen = rb_sprintf(t, "%s%s ", find_channel_status(msptr, stack), |
212380e3 | 457 | target_p->name); |
458 | ||
459 | cur_len += tlen; | |
460 | t += tlen; | |
461 | } | |
462 | ||
463 | /* The old behaviour here was to always output our buffer, | |
464 | * even if there are no clients we can show. This happens | |
465 | * when a client does "NAMES" with no parameters, and all | |
466 | * the clients on a -sp channel are +i. I dont see a good | |
467 | * reason for keeping that behaviour, as it just wastes | |
468 | * bandwidth. --anfl | |
469 | */ | |
470 | if(cur_len != mlen) | |
471 | { | |
472 | *(t - 1) = '\0'; | |
473 | sendto_one(client_p, "%s", lbuf); | |
474 | } | |
475 | } | |
476 | ||
477 | if(show_eon) | |
478 | sendto_one(client_p, form_str(RPL_ENDOFNAMES), | |
479 | me.name, client_p->name, chptr->chname); | |
480 | } | |
481 | ||
482 | /* del_invite() | |
483 | * | |
484 | * input - channel to remove invite from, client to remove | |
485 | * output - | |
486 | * side effects - user is removed from invite list, if exists | |
487 | */ | |
488 | void | |
489 | del_invite(struct Channel *chptr, struct Client *who) | |
490 | { | |
af81d5a0 WP |
491 | rb_dlinkFindDestroy(who, &chptr->invites); |
492 | rb_dlinkFindDestroy(chptr, &who->user->invited); | |
212380e3 | 493 | } |
494 | ||
495 | /* is_banned() | |
496 | * | |
497 | * input - channel to check bans for, user to check bans against | |
498 | * optional prebuilt buffers | |
499 | * output - 1 if banned, else 0 | |
500 | * side effects - | |
501 | */ | |
502 | int | |
503 | is_banned(struct Channel *chptr, struct Client *who, struct membership *msptr, | |
504 | const char *s, const char *s2) | |
505 | { | |
506 | char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; | |
507 | char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
508 | char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
509 | char *s3 = NULL; | |
af81d5a0 | 510 | rb_dlink_node *ptr; |
212380e3 | 511 | struct Ban *actualBan = NULL; |
512 | struct Ban *actualExcept = NULL; | |
513 | ||
514 | if(!MyClient(who)) | |
515 | return 0; | |
516 | ||
517 | /* if the buffers havent been built, do it here */ | |
518 | if(s == NULL) | |
519 | { | |
38e6acdd WP |
520 | rb_sprintf(src_host, "%s!%s@%s", who->name, who->username, who->host); |
521 | rb_sprintf(src_iphost, "%s!%s@%s", who->name, who->username, who->sockhost); | |
212380e3 | 522 | |
523 | s = src_host; | |
524 | s2 = src_iphost; | |
525 | } | |
526 | if(who->localClient->mangledhost != NULL) | |
527 | { | |
528 | /* if host mangling mode enabled, also check their real host */ | |
529 | if(!strcmp(who->host, who->localClient->mangledhost)) | |
530 | { | |
38e6acdd | 531 | rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->orighost); |
212380e3 | 532 | s3 = src_althost; |
533 | } | |
534 | /* if host mangling mode not enabled and no other spoof, | |
535 | * also check the mangled form of their host */ | |
536 | else if (!IsDynSpoof(who)) | |
537 | { | |
38e6acdd | 538 | rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->localClient->mangledhost); |
212380e3 | 539 | s3 = src_althost; |
540 | } | |
541 | } | |
542 | ||
8e69bb4e | 543 | RB_DLINK_FOREACH(ptr, chptr->banlist.head) |
212380e3 | 544 | { |
545 | actualBan = ptr->data; | |
546 | if(match(actualBan->banstr, s) || | |
547 | match(actualBan->banstr, s2) || | |
548 | match_cidr(actualBan->banstr, s2) || | |
549 | match_extban(actualBan->banstr, who, chptr, CHFL_BAN) || | |
550 | (s3 != NULL && match(actualBan->banstr, s3))) | |
551 | break; | |
552 | else | |
553 | actualBan = NULL; | |
554 | } | |
555 | ||
556 | if((actualBan != NULL) && ConfigChannel.use_except) | |
557 | { | |
8e69bb4e | 558 | RB_DLINK_FOREACH(ptr, chptr->exceptlist.head) |
212380e3 | 559 | { |
560 | actualExcept = ptr->data; | |
561 | ||
562 | /* theyre exempted.. */ | |
563 | if(match(actualExcept->banstr, s) || | |
564 | match(actualExcept->banstr, s2) || | |
565 | match_cidr(actualExcept->banstr, s2) || | |
566 | match_extban(actualExcept->banstr, who, chptr, CHFL_EXCEPTION) || | |
567 | (s3 != NULL && match(actualExcept->banstr, s3))) | |
568 | { | |
569 | /* cache the fact theyre not banned */ | |
570 | if(msptr != NULL) | |
571 | { | |
572 | msptr->bants = chptr->bants; | |
573 | msptr->flags &= ~CHFL_BANNED; | |
574 | } | |
575 | ||
576 | return CHFL_EXCEPTION; | |
577 | } | |
578 | } | |
579 | } | |
580 | ||
581 | /* cache the banned/not banned status */ | |
582 | if(msptr != NULL) | |
583 | { | |
584 | msptr->bants = chptr->bants; | |
585 | ||
586 | if(actualBan != NULL) | |
587 | { | |
588 | msptr->flags |= CHFL_BANNED; | |
589 | return CHFL_BAN; | |
590 | } | |
591 | else | |
592 | { | |
593 | msptr->flags &= ~CHFL_BANNED; | |
594 | return 0; | |
595 | } | |
596 | } | |
597 | ||
598 | return ((actualBan ? CHFL_BAN : 0)); | |
599 | } | |
600 | ||
601 | /* is_quieted() | |
602 | * | |
603 | * input - channel to check bans for, user to check bans against | |
604 | * optional prebuilt buffers | |
605 | * output - 1 if banned, else 0 | |
606 | * side effects - | |
607 | */ | |
608 | int | |
609 | is_quieted(struct Channel *chptr, struct Client *who, struct membership *msptr, | |
610 | const char *s, const char *s2) | |
611 | { | |
612 | char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; | |
613 | char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
614 | char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
615 | char *s3 = NULL; | |
af81d5a0 | 616 | rb_dlink_node *ptr; |
212380e3 | 617 | struct Ban *actualBan = NULL; |
618 | struct Ban *actualExcept = NULL; | |
619 | ||
620 | if(!MyClient(who)) | |
621 | return 0; | |
622 | ||
623 | /* if the buffers havent been built, do it here */ | |
624 | if(s == NULL) | |
625 | { | |
38e6acdd WP |
626 | rb_sprintf(src_host, "%s!%s@%s", who->name, who->username, who->host); |
627 | rb_sprintf(src_iphost, "%s!%s@%s", who->name, who->username, who->sockhost); | |
212380e3 | 628 | |
629 | s = src_host; | |
630 | s2 = src_iphost; | |
631 | } | |
632 | if(who->localClient->mangledhost != NULL) | |
633 | { | |
634 | /* if host mangling mode enabled, also check their real host */ | |
635 | if(!strcmp(who->host, who->localClient->mangledhost)) | |
636 | { | |
38e6acdd | 637 | rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->orighost); |
212380e3 | 638 | s3 = src_althost; |
639 | } | |
640 | /* if host mangling mode not enabled and no other spoof, | |
641 | * also check the mangled form of their host */ | |
642 | else if (!IsDynSpoof(who)) | |
643 | { | |
38e6acdd | 644 | rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->localClient->mangledhost); |
212380e3 | 645 | s3 = src_althost; |
646 | } | |
647 | } | |
648 | ||
8e69bb4e | 649 | RB_DLINK_FOREACH(ptr, chptr->quietlist.head) |
212380e3 | 650 | { |
651 | actualBan = ptr->data; | |
652 | if(match(actualBan->banstr, s) || | |
653 | match(actualBan->banstr, s2) || | |
654 | match_cidr(actualBan->banstr, s2) || | |
655 | match_extban(actualBan->banstr, who, chptr, CHFL_QUIET) || | |
656 | (s3 != NULL && match(actualBan->banstr, s3))) | |
657 | break; | |
658 | else | |
659 | actualBan = NULL; | |
660 | } | |
661 | ||
662 | if((actualBan != NULL) && ConfigChannel.use_except) | |
663 | { | |
8e69bb4e | 664 | RB_DLINK_FOREACH(ptr, chptr->exceptlist.head) |
212380e3 | 665 | { |
666 | actualExcept = ptr->data; | |
667 | ||
668 | /* theyre exempted.. */ | |
669 | if(match(actualExcept->banstr, s) || | |
670 | match(actualExcept->banstr, s2) || | |
671 | match_cidr(actualExcept->banstr, s2) || | |
672 | match_extban(actualExcept->banstr, who, chptr, CHFL_EXCEPTION) || | |
673 | (s3 != NULL && match(actualExcept->banstr, s3))) | |
674 | { | |
675 | /* cache the fact theyre not banned */ | |
676 | if(msptr != NULL) | |
677 | { | |
678 | msptr->bants = chptr->bants; | |
679 | msptr->flags &= ~CHFL_BANNED; | |
680 | } | |
681 | ||
682 | return CHFL_EXCEPTION; | |
683 | } | |
684 | } | |
685 | } | |
686 | ||
687 | /* cache the banned/not banned status */ | |
688 | if(msptr != NULL) | |
689 | { | |
690 | msptr->bants = chptr->bants; | |
691 | ||
692 | if(actualBan != NULL) | |
693 | { | |
694 | msptr->flags |= CHFL_BANNED; | |
695 | return CHFL_BAN; | |
696 | } | |
697 | else | |
698 | { | |
699 | msptr->flags &= ~CHFL_BANNED; | |
700 | return 0; | |
701 | } | |
702 | } | |
703 | ||
704 | return ((actualBan ? CHFL_BAN : 0)); | |
705 | } | |
706 | ||
707 | /* can_join() | |
708 | * | |
709 | * input - client to check, channel to check for, key | |
710 | * output - reason for not being able to join, else 0 | |
711 | * side effects - | |
712 | */ | |
713 | int | |
714 | can_join(struct Client *source_p, struct Channel *chptr, char *key) | |
715 | { | |
af81d5a0 WP |
716 | rb_dlink_node *invite = NULL; |
717 | rb_dlink_node *ptr; | |
212380e3 | 718 | struct Ban *invex = NULL; |
719 | char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; | |
720 | char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
721 | char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
722 | int use_althost = 0; | |
1ebf4db4 | 723 | int i = 0; |
212380e3 | 724 | hook_data_channel moduledata; |
725 | ||
726 | s_assert(source_p->localClient != NULL); | |
727 | ||
13a467bb JH |
728 | if(IsOverride(source_p)) |
729 | return 0; | |
730 | ||
38e6acdd WP |
731 | rb_sprintf(src_host, "%s!%s@%s", source_p->name, source_p->username, source_p->host); |
732 | rb_sprintf(src_iphost, "%s!%s@%s", source_p->name, source_p->username, source_p->sockhost); | |
212380e3 | 733 | if(source_p->localClient->mangledhost != NULL) |
734 | { | |
735 | /* if host mangling mode enabled, also check their real host */ | |
736 | if(!strcmp(source_p->host, source_p->localClient->mangledhost)) | |
737 | { | |
38e6acdd | 738 | rb_sprintf(src_althost, "%s!%s@%s", source_p->name, source_p->username, source_p->orighost); |
212380e3 | 739 | use_althost = 1; |
740 | } | |
741 | /* if host mangling mode not enabled and no other spoof, | |
742 | * also check the mangled form of their host */ | |
743 | else if (!IsDynSpoof(source_p)) | |
744 | { | |
38e6acdd | 745 | rb_sprintf(src_althost, "%s!%s@%s", source_p->name, source_p->username, source_p->localClient->mangledhost); |
212380e3 | 746 | use_althost = 1; |
747 | } | |
748 | } | |
749 | ||
750 | if((is_banned(chptr, source_p, NULL, src_host, src_iphost)) == CHFL_BAN) | |
751 | return (ERR_BANNEDFROMCHAN); | |
752 | ||
753 | if(chptr->mode.mode & MODE_INVITEONLY) | |
754 | { | |
8e69bb4e | 755 | RB_DLINK_FOREACH(invite, source_p->user->invited.head) |
212380e3 | 756 | { |
1ebf4db4 | 757 | if(invite->data == chptr) |
212380e3 | 758 | break; |
759 | } | |
1ebf4db4 | 760 | if(invite == NULL) |
212380e3 | 761 | { |
762 | if(!ConfigChannel.use_invex) | |
763 | return (ERR_INVITEONLYCHAN); | |
8e69bb4e | 764 | RB_DLINK_FOREACH(ptr, chptr->invexlist.head) |
212380e3 | 765 | { |
766 | invex = ptr->data; | |
767 | if(match(invex->banstr, src_host) | |
768 | || match(invex->banstr, src_iphost) | |
769 | || match_cidr(invex->banstr, src_iphost) | |
770 | || match_extban(invex->banstr, source_p, chptr, CHFL_INVEX) | |
771 | || (use_althost && match(invex->banstr, src_althost))) | |
772 | break; | |
773 | } | |
774 | if(ptr == NULL) | |
775 | return (ERR_INVITEONLYCHAN); | |
776 | } | |
777 | } | |
778 | ||
779 | if(*chptr->mode.key && (EmptyString(key) || irccmp(chptr->mode.key, key))) | |
780 | return (ERR_BADCHANNELKEY); | |
781 | ||
782 | if(chptr->mode.limit && | |
af81d5a0 | 783 | rb_dlink_list_length(&chptr->members) >= (unsigned long) chptr->mode.limit) |
1ebf4db4 | 784 | i = ERR_CHANNELISFULL; |
212380e3 | 785 | if(chptr->mode.mode & MODE_REGONLY && EmptyString(source_p->user->suser)) |
1ebf4db4 | 786 | i = ERR_NEEDREGGEDNICK; |
212380e3 | 787 | /* join throttling stuff --nenolod */ |
1ebf4db4 | 788 | else if(chptr->mode.join_num > 0 && chptr->mode.join_time > 0) |
212380e3 | 789 | { |
9f6bbe3c | 790 | if ((rb_current_time() - chptr->join_delta <= |
212380e3 | 791 | chptr->mode.join_time) && (chptr->join_count >= |
792 | chptr->mode.join_num)) | |
1ebf4db4 | 793 | i = ERR_THROTTLE; |
794 | } | |
795 | ||
796 | /* allow /invite to override +l/+r/+j also -- jilles */ | |
797 | if (i != 0 && invite == NULL) | |
798 | { | |
8e69bb4e | 799 | RB_DLINK_FOREACH(invite, source_p->user->invited.head) |
1ebf4db4 | 800 | { |
801 | if(invite->data == chptr) | |
802 | break; | |
803 | } | |
804 | if (invite == NULL) | |
805 | return i; | |
212380e3 | 806 | } |
807 | ||
808 | moduledata.client = source_p; | |
809 | moduledata.chptr = chptr; | |
810 | moduledata.approved = 0; | |
811 | ||
812 | call_hook(h_can_join, &moduledata); | |
813 | ||
814 | return moduledata.approved; | |
815 | } | |
816 | ||
817 | /* can_send() | |
818 | * | |
819 | * input - user to check in channel, membership pointer | |
820 | * output - whether can explicitly send or not, else CAN_SEND_NONOP | |
821 | * side effects - | |
822 | */ | |
823 | int | |
824 | can_send(struct Channel *chptr, struct Client *source_p, struct membership *msptr) | |
825 | { | |
826 | if(IsServer(source_p) || IsService(source_p)) | |
827 | return CAN_SEND_OPV; | |
828 | ||
829 | if(MyClient(source_p) && hash_find_resv(chptr->chname) && | |
830 | !IsOper(source_p) && !IsExemptResv(source_p)) | |
831 | return CAN_SEND_NO; | |
832 | ||
833 | if(msptr == NULL) | |
834 | { | |
835 | msptr = find_channel_membership(chptr, source_p); | |
836 | ||
837 | if(msptr == NULL) | |
838 | { | |
839 | /* if its +m or +n and theyre not in the channel, | |
840 | * they cant send. we dont check bans here because | |
841 | * theres no possibility of caching them --fl | |
842 | */ | |
843 | if(chptr->mode.mode & MODE_NOPRIVMSGS || chptr->mode.mode & MODE_MODERATED) | |
844 | return CAN_SEND_NO; | |
845 | else | |
846 | return CAN_SEND_NONOP; | |
847 | } | |
848 | } | |
849 | ||
850 | if(is_chanop_voiced(msptr)) | |
851 | return CAN_SEND_OPV; | |
852 | ||
13a467bb JH |
853 | if(IsOverride(source_p)) |
854 | return CAN_SEND_NONOP; | |
855 | ||
212380e3 | 856 | if(chptr->mode.mode & MODE_MODERATED) |
857 | return CAN_SEND_NO; | |
858 | ||
859 | if(MyClient(source_p)) | |
860 | { | |
861 | /* cached can_send */ | |
862 | if(msptr->bants == chptr->bants) | |
863 | { | |
864 | if(can_send_banned(msptr)) | |
865 | return CAN_SEND_NO; | |
866 | } | |
867 | else if(is_banned(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN | |
868 | || is_quieted(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN) | |
869 | return CAN_SEND_NO; | |
870 | } | |
871 | ||
872 | return CAN_SEND_NONOP; | |
873 | } | |
874 | ||
875 | /* find_bannickchange_channel() | |
876 | * Input: client to check | |
877 | * Output: channel preventing nick change | |
878 | */ | |
879 | struct Channel * | |
880 | find_bannickchange_channel(struct Client *client_p) | |
881 | { | |
882 | struct Channel *chptr; | |
883 | struct membership *msptr; | |
af81d5a0 | 884 | rb_dlink_node *ptr; |
212380e3 | 885 | char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; |
886 | char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
887 | ||
13a467bb | 888 | if (!MyClient(client_p) || IsOverride(client_p)) |
212380e3 | 889 | return NULL; |
890 | ||
38e6acdd WP |
891 | rb_sprintf(src_host, "%s!%s@%s", client_p->name, client_p->username, client_p->host); |
892 | rb_sprintf(src_iphost, "%s!%s@%s", client_p->name, client_p->username, client_p->sockhost); | |
212380e3 | 893 | |
8e69bb4e | 894 | RB_DLINK_FOREACH(ptr, client_p->user->channel.head) |
212380e3 | 895 | { |
896 | msptr = ptr->data; | |
897 | chptr = msptr->chptr; | |
898 | if (is_chanop_voiced(msptr)) | |
899 | continue; | |
900 | /* cached can_send */ | |
901 | if (msptr->bants == chptr->bants) | |
902 | { | |
903 | if (can_send_banned(msptr)) | |
904 | return chptr; | |
905 | } | |
906 | else if (is_banned(chptr, client_p, msptr, src_host, src_iphost) == CHFL_BAN | |
907 | || is_quieted(chptr, client_p, msptr, src_host, src_iphost) == CHFL_BAN) | |
908 | return chptr; | |
909 | } | |
910 | return NULL; | |
911 | } | |
912 | ||
afd4834b G |
913 | /* find_nonickchange_channel() |
914 | * Input: client to check | |
915 | * Output: channel preventing nick change | |
916 | */ | |
917 | struct Channel * | |
918 | find_nonickchange_channel(struct Client *client_p) | |
919 | { | |
920 | struct Channel *chptr; | |
921 | struct membership *msptr; | |
922 | rb_dlink_node *ptr; | |
923 | ||
924 | if (!MyClient(client_p)) | |
925 | return NULL; | |
926 | ||
927 | RB_DLINK_FOREACH(ptr, client_p->user->channel.head) | |
928 | { | |
929 | msptr = ptr->data; | |
930 | chptr = msptr->chptr; | |
931 | if (is_chanop_voiced(msptr)) | |
932 | continue; | |
933 | if (chptr->mode.mode & MODE_NONICK) | |
934 | return chptr; | |
935 | } | |
936 | return NULL; | |
937 | } | |
938 | ||
212380e3 | 939 | /* void check_spambot_warning(struct Client *source_p) |
940 | * Input: Client to check, channel name or NULL if this is a part. | |
941 | * Output: none | |
942 | * Side-effects: Updates the client's oper_warn_count_down, warns the | |
943 | * IRC operators if necessary, and updates join_leave_countdown as | |
944 | * needed. | |
945 | */ | |
946 | void | |
947 | check_spambot_warning(struct Client *source_p, const char *name) | |
948 | { | |
949 | int t_delta; | |
950 | int decrement_count; | |
951 | if((GlobalSetOptions.spam_num && | |
952 | (source_p->localClient->join_leave_count >= GlobalSetOptions.spam_num))) | |
953 | { | |
954 | if(source_p->localClient->oper_warn_count_down > 0) | |
955 | source_p->localClient->oper_warn_count_down--; | |
956 | else | |
957 | source_p->localClient->oper_warn_count_down = 0; | |
05d8a68c JT |
958 | if(source_p->localClient->oper_warn_count_down == 0 && |
959 | name != NULL) | |
212380e3 | 960 | { |
961 | /* Its already known as a possible spambot */ | |
05d8a68c JT |
962 | sendto_realops_snomask(SNO_BOTS, L_NETWIDE, |
963 | "User %s (%s@%s) trying to join %s is a possible spambot", | |
964 | source_p->name, | |
965 | source_p->username, source_p->orighost, name); | |
212380e3 | 966 | source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN; |
967 | } | |
968 | } | |
969 | else | |
970 | { | |
971 | if((t_delta = | |
9f6bbe3c | 972 | (rb_current_time() - source_p->localClient->last_leave_time)) > |
212380e3 | 973 | JOIN_LEAVE_COUNT_EXPIRE_TIME) |
974 | { | |
975 | decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); | |
b6698246 JT |
976 | if(name != NULL) |
977 | ; | |
978 | else if(decrement_count > source_p->localClient->join_leave_count) | |
212380e3 | 979 | source_p->localClient->join_leave_count = 0; |
980 | else | |
981 | source_p->localClient->join_leave_count -= decrement_count; | |
982 | } | |
983 | else | |
984 | { | |
9f6bbe3c | 985 | if((rb_current_time() - |
212380e3 | 986 | (source_p->localClient->last_join_time)) < GlobalSetOptions.spam_time) |
987 | { | |
988 | /* oh, its a possible spambot */ | |
989 | source_p->localClient->join_leave_count++; | |
990 | } | |
991 | } | |
992 | if(name != NULL) | |
9f6bbe3c | 993 | source_p->localClient->last_join_time = rb_current_time(); |
212380e3 | 994 | else |
9f6bbe3c | 995 | source_p->localClient->last_leave_time = rb_current_time(); |
212380e3 | 996 | } |
997 | } | |
998 | ||
999 | /* check_splitmode() | |
1000 | * | |
1001 | * input - | |
1002 | * output - | |
1003 | * side effects - compares usercount and servercount against their split | |
1004 | * values and adjusts splitmode accordingly | |
1005 | */ | |
1006 | void | |
1007 | check_splitmode(void *unused) | |
1008 | { | |
1009 | if(splitchecking && (ConfigChannel.no_join_on_split || ConfigChannel.no_create_on_split)) | |
1010 | { | |
1011 | /* not split, we're being asked to check now because someone | |
1012 | * has left | |
1013 | */ | |
1014 | if(!splitmode) | |
1015 | { | |
1016 | if(eob_count < split_servers || Count.total < split_users) | |
1017 | { | |
1018 | splitmode = 1; | |
1019 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1020 | "Network split, activating splitmode"); | |
dd9be678 | 1021 | check_splitmode_ev = rb_event_addish("check_splitmode", check_splitmode, NULL, 2); |
212380e3 | 1022 | } |
1023 | } | |
1024 | /* in splitmode, check whether its finished */ | |
1025 | else if(eob_count >= split_servers && Count.total >= split_users) | |
1026 | { | |
1027 | splitmode = 0; | |
1028 | ||
1029 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1030 | "Network rejoined, deactivating splitmode"); | |
1031 | ||
dd9be678 | 1032 | rb_event_delete(check_splitmode_ev); |
0ae330b4 | 1033 | check_splitmode_ev = NULL; |
212380e3 | 1034 | } |
1035 | } | |
1036 | } | |
1037 | ||
1038 | ||
1039 | /* allocate_topic() | |
1040 | * | |
1041 | * input - channel to allocate topic for | |
1042 | * output - 1 on success, else 0 | |
1043 | * side effects - channel gets a topic allocated | |
1044 | */ | |
1045 | static void | |
1046 | allocate_topic(struct Channel *chptr) | |
1047 | { | |
1048 | void *ptr; | |
1049 | ||
1050 | if(chptr == NULL) | |
1051 | return; | |
1052 | ||
6e9b4415 | 1053 | ptr = rb_bh_alloc(topic_heap); |
212380e3 | 1054 | |
1055 | /* Basically we allocate one large block for the topic and | |
1056 | * the topic info. We then split it up into two and shove it | |
1057 | * in the chptr | |
1058 | */ | |
1059 | chptr->topic = ptr; | |
1060 | chptr->topic_info = (char *) ptr + TOPICLEN + 1; | |
1061 | *chptr->topic = '\0'; | |
1062 | *chptr->topic_info = '\0'; | |
1063 | } | |
1064 | ||
1065 | /* free_topic() | |
1066 | * | |
1067 | * input - channel which has topic to free | |
1068 | * output - | |
1069 | * side effects - channels topic is free'd | |
1070 | */ | |
1071 | static void | |
1072 | free_topic(struct Channel *chptr) | |
1073 | { | |
1074 | void *ptr; | |
1075 | ||
1076 | if(chptr == NULL || chptr->topic == NULL) | |
1077 | return; | |
1078 | ||
1079 | /* This is safe for now - If you change allocate_topic you | |
1080 | * MUST change this as well | |
1081 | */ | |
1082 | ptr = chptr->topic; | |
6e9b4415 | 1083 | rb_bh_free(topic_heap, ptr); |
212380e3 | 1084 | chptr->topic = NULL; |
1085 | chptr->topic_info = NULL; | |
1086 | } | |
1087 | ||
1088 | /* set_channel_topic() | |
1089 | * | |
1090 | * input - channel, topic to set, topic info and topic ts | |
1091 | * output - | |
1092 | * side effects - channels topic, topic info and TS are set. | |
1093 | */ | |
1094 | void | |
1095 | set_channel_topic(struct Channel *chptr, const char *topic, const char *topic_info, time_t topicts) | |
1096 | { | |
1097 | if(strlen(topic) > 0) | |
1098 | { | |
1099 | if(chptr->topic == NULL) | |
1100 | allocate_topic(chptr); | |
907468c4 VY |
1101 | rb_strlcpy(chptr->topic, topic, TOPICLEN + 1); |
1102 | rb_strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN); | |
212380e3 | 1103 | chptr->topic_time = topicts; |
1104 | } | |
1105 | else | |
1106 | { | |
1107 | if(chptr->topic != NULL) | |
1108 | free_topic(chptr); | |
1109 | chptr->topic_time = 0; | |
1110 | } | |
1111 | } | |
1112 | ||
212380e3 | 1113 | /* channel_modes() |
1114 | * | |
1115 | * inputs - pointer to channel | |
1116 | * - pointer to client | |
f1e35c19 | 1117 | * output - string with simple modes |
1118 | * side effects - result from previous calls overwritten | |
212380e3 | 1119 | * |
1120 | * Stolen from ShadowIRCd 4 --nenolod | |
1121 | */ | |
1122 | const char * | |
1123 | channel_modes(struct Channel *chptr, struct Client *client_p) | |
1124 | { | |
1125 | int i; | |
1126 | char buf1[BUFSIZE]; | |
1127 | char buf2[BUFSIZE]; | |
1128 | static char final[BUFSIZE]; | |
1129 | char *mbuf = buf1; | |
1130 | char *pbuf = buf2; | |
1131 | ||
1132 | *mbuf++ = '+'; | |
1133 | *pbuf = '\0'; | |
1134 | ||
75818939 VY |
1135 | for (i = 0; i < 256; i++) |
1136 | if(chptr->mode.mode & chmode_flags[i]) | |
1137 | *mbuf++ = i; | |
212380e3 | 1138 | |
1139 | if(chptr->mode.limit) | |
1140 | { | |
1141 | *mbuf++ = 'l'; | |
1142 | ||
f1e35c19 | 1143 | if(!IsClient(client_p) || IsMember(client_p, chptr)) |
38e6acdd | 1144 | pbuf += rb_sprintf(pbuf, " %d", chptr->mode.limit); |
212380e3 | 1145 | } |
1146 | ||
1147 | if(*chptr->mode.key) | |
1148 | { | |
1149 | *mbuf++ = 'k'; | |
1150 | ||
f1e35c19 | 1151 | if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) |
38e6acdd | 1152 | pbuf += rb_sprintf(pbuf, " %s", chptr->mode.key); |
212380e3 | 1153 | } |
1154 | ||
1155 | if(chptr->mode.join_num) | |
1156 | { | |
1157 | *mbuf++ = 'j'; | |
1158 | ||
f1e35c19 | 1159 | if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) |
38e6acdd | 1160 | pbuf += rb_sprintf(pbuf, " %d:%d", chptr->mode.join_num, |
212380e3 | 1161 | chptr->mode.join_time); |
1162 | } | |
1163 | ||
f1e35c19 | 1164 | if(*chptr->mode.forward && (ConfigChannel.use_forward || !IsClient(client_p))) |
212380e3 | 1165 | { |
1166 | *mbuf++ = 'f'; | |
1167 | ||
f1e35c19 | 1168 | if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) |
38e6acdd | 1169 | pbuf += rb_sprintf(pbuf, " %s", chptr->mode.forward); |
212380e3 | 1170 | } |
1171 | ||
1172 | *mbuf = '\0'; | |
1173 | ||
907468c4 | 1174 | rb_strlcpy(final, buf1, sizeof final); |
a64c5173 | 1175 | rb_strlcat(final, buf2, sizeof final); |
212380e3 | 1176 | return final; |
1177 | } | |
1178 | ||
1179 | /* Now lets do some stuff to keep track of what combinations of | |
1180 | * servers exist... | |
1181 | * Note that the number of combinations doubles each time you add | |
1182 | * something to this list. Each one is only quick if no servers use that | |
1183 | * combination, but if the numbers get too high here MODE will get too | |
1184 | * slow. I suggest if you get more than 7 here, you consider getting rid | |
1185 | * of some and merging or something. If it wasn't for irc+cs we would | |
1186 | * probably not even need to bother about most of these, but unfortunately | |
1187 | * we do. -A1kmm | |
1188 | */ | |
1189 | ||
1190 | /* void init_chcap_usage_counts(void) | |
1191 | * | |
1192 | * Inputs - none | |
1193 | * Output - none | |
1194 | * Side-effects - Initialises the usage counts to zero. Fills in the | |
1195 | * chcap_yes and chcap_no combination tables. | |
1196 | */ | |
1197 | void | |
1198 | init_chcap_usage_counts(void) | |
1199 | { | |
1200 | unsigned long m, c, y, n; | |
1201 | ||
1202 | memset(chcap_combos, 0, sizeof(chcap_combos)); | |
1203 | ||
1204 | /* For every possible combination */ | |
1205 | for (m = 0; m < NCHCAP_COMBOS; m++) | |
1206 | { | |
1207 | /* Check each capab */ | |
1208 | for (c = y = n = 0; c < NCHCAPS; c++) | |
1209 | { | |
1210 | if((m & (1 << c)) == 0) | |
1211 | n |= channel_capabs[c]; | |
1212 | else | |
1213 | y |= channel_capabs[c]; | |
1214 | } | |
1215 | chcap_combos[m].cap_yes = y; | |
1216 | chcap_combos[m].cap_no = n; | |
1217 | } | |
1218 | } | |
1219 | ||
1220 | /* void set_chcap_usage_counts(struct Client *serv_p) | |
1221 | * Input: serv_p; The client whose capabs to register. | |
1222 | * Output: none | |
1223 | * Side-effects: Increments the usage counts for the correct capab | |
1224 | * combination. | |
1225 | */ | |
1226 | void | |
1227 | set_chcap_usage_counts(struct Client *serv_p) | |
1228 | { | |
1229 | int n; | |
1230 | ||
1231 | for (n = 0; n < NCHCAP_COMBOS; n++) | |
1232 | { | |
1233 | if(IsCapable(serv_p, chcap_combos[n].cap_yes) && | |
1234 | NotCapable(serv_p, chcap_combos[n].cap_no)) | |
1235 | { | |
1236 | chcap_combos[n].count++; | |
1237 | return; | |
1238 | } | |
1239 | } | |
1240 | ||
1241 | /* This should be impossible -A1kmm. */ | |
1242 | s_assert(0); | |
1243 | } | |
1244 | ||
1245 | /* void set_chcap_usage_counts(struct Client *serv_p) | |
1246 | * | |
1247 | * Inputs - serv_p; The client whose capabs to register. | |
1248 | * Output - none | |
1249 | * Side-effects - Decrements the usage counts for the correct capab | |
1250 | * combination. | |
1251 | */ | |
1252 | void | |
1253 | unset_chcap_usage_counts(struct Client *serv_p) | |
1254 | { | |
1255 | int n; | |
1256 | ||
1257 | for (n = 0; n < NCHCAP_COMBOS; n++) | |
1258 | { | |
1259 | if(IsCapable(serv_p, chcap_combos[n].cap_yes) && | |
1260 | NotCapable(serv_p, chcap_combos[n].cap_no)) | |
1261 | { | |
1262 | /* Hopefully capabs can't change dynamically or anything... */ | |
1263 | s_assert(chcap_combos[n].count > 0); | |
1264 | ||
1265 | if(chcap_combos[n].count > 0) | |
1266 | chcap_combos[n].count--; | |
1267 | return; | |
1268 | } | |
1269 | } | |
1270 | ||
1271 | /* This should be impossible -A1kmm. */ | |
1272 | s_assert(0); | |
1273 | } | |
1274 | ||
1275 | /* void send_cap_mode_changes(struct Client *client_p, | |
1276 | * struct Client *source_p, | |
1277 | * struct Channel *chptr, int cap, int nocap) | |
1278 | * Input: The client sending(client_p), the source client(source_p), | |
1279 | * the channel to send mode changes for(chptr) | |
1280 | * Output: None. | |
1281 | * Side-effects: Sends the appropriate mode changes to capable servers. | |
1282 | * | |
1283 | * Reverted back to my original design, except that we now keep a count | |
1284 | * of the number of servers which each combination as an optimisation, so | |
1285 | * the capabs combinations which are not needed are not worked out. -A1kmm | |
1286 | */ | |
1287 | void | |
1288 | send_cap_mode_changes(struct Client *client_p, struct Client *source_p, | |
1289 | struct Channel *chptr, struct ChModeChange mode_changes[], int mode_count) | |
1290 | { | |
1291 | static char modebuf[BUFSIZE]; | |
1292 | static char parabuf[BUFSIZE]; | |
1293 | int i, mbl, pbl, nc, mc, preflen, len; | |
1294 | char *pbuf; | |
1295 | const char *arg; | |
1296 | int dir; | |
1297 | int j; | |
1298 | int cap; | |
1299 | int nocap; | |
1300 | int arglen; | |
1301 | ||
1302 | /* Now send to servers... */ | |
1303 | for (j = 0; j < NCHCAP_COMBOS; j++) | |
1304 | { | |
1305 | if(chcap_combos[j].count == 0) | |
1306 | continue; | |
1307 | ||
1308 | mc = 0; | |
1309 | nc = 0; | |
1310 | pbl = 0; | |
1311 | parabuf[0] = 0; | |
1312 | pbuf = parabuf; | |
1313 | dir = MODE_QUERY; | |
1314 | ||
1315 | cap = chcap_combos[j].cap_yes; | |
1316 | nocap = chcap_combos[j].cap_no; | |
1317 | ||
9f9b4d7b WP |
1318 | mbl = preflen = rb_sprintf(modebuf, ":%s TMODE %ld %s ", |
1319 | use_id(source_p), (long) chptr->channelts, | |
1320 | chptr->chname); | |
212380e3 | 1321 | |
1322 | /* loop the list of - modes we have */ | |
1323 | for (i = 0; i < mode_count; i++) | |
1324 | { | |
1325 | /* if they dont support the cap we need, or they do support a cap they | |
1326 | * cant have, then dont add it to the modebuf.. that way they wont see | |
1327 | * the mode | |
1328 | */ | |
1329 | if((mode_changes[i].letter == 0) || | |
1330 | ((cap & mode_changes[i].caps) != mode_changes[i].caps) | |
1331 | || ((nocap & mode_changes[i].nocaps) != mode_changes[i].nocaps)) | |
1332 | continue; | |
1333 | ||
7592f950 JT |
1334 | if(!EmptyString(mode_changes[i].id)) |
1335 | arg = mode_changes[i].id; | |
1336 | else | |
1337 | arg = mode_changes[i].arg; | |
212380e3 | 1338 | |
1339 | if(arg) | |
1340 | { | |
1341 | arglen = strlen(arg); | |
1342 | ||
1343 | /* dont even think about it! --fl */ | |
1344 | if(arglen > MODEBUFLEN - 5) | |
1345 | continue; | |
1346 | } | |
1347 | ||
1348 | /* if we're creeping past the buf size, we need to send it and make | |
1349 | * another line for the other modes | |
1350 | * XXX - this could give away server topology with uids being | |
1351 | * different lengths, but not much we can do, except possibly break | |
1352 | * them as if they were the longest of the nick or uid at all times, | |
1353 | * which even then won't work as we don't always know the uid -A1kmm. | |
1354 | */ | |
1355 | if(arg && ((mc == MAXMODEPARAMSSERV) || | |
1356 | ((mbl + pbl + arglen + 4) > (BUFSIZE - 3)))) | |
1357 | { | |
1358 | if(nc != 0) | |
1359 | sendto_server(client_p, chptr, cap, nocap, | |
1360 | "%s %s", modebuf, parabuf); | |
1361 | nc = 0; | |
1362 | mc = 0; | |
1363 | ||
1364 | mbl = preflen; | |
1365 | pbl = 0; | |
1366 | pbuf = parabuf; | |
1367 | parabuf[0] = 0; | |
1368 | dir = MODE_QUERY; | |
1369 | } | |
1370 | ||
1371 | if(dir != mode_changes[i].dir) | |
1372 | { | |
1373 | modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; | |
1374 | dir = mode_changes[i].dir; | |
1375 | } | |
1376 | ||
1377 | modebuf[mbl++] = mode_changes[i].letter; | |
1378 | modebuf[mbl] = 0; | |
1379 | nc++; | |
1380 | ||
1381 | if(arg != NULL) | |
1382 | { | |
38e6acdd | 1383 | len = rb_sprintf(pbuf, "%s ", arg); |
212380e3 | 1384 | pbuf += len; |
1385 | pbl += len; | |
1386 | mc++; | |
1387 | } | |
1388 | } | |
1389 | ||
1390 | if(pbl && parabuf[pbl - 1] == ' ') | |
1391 | parabuf[pbl - 1] = 0; | |
1392 | ||
1393 | if(nc != 0) | |
1394 | sendto_server(client_p, chptr, cap, nocap, "%s %s", modebuf, parabuf); | |
1395 | } | |
1396 | } | |
080bb5cf JH |
1397 | |
1398 | /* Check what we will forward to, without sending any notices to the user | |
1399 | * -- jilles | |
1400 | */ | |
1401 | struct Channel * | |
1402 | check_forward(struct Client *source_p, struct Channel *chptr, | |
1403 | char *key) | |
1404 | { | |
1405 | int depth = 0, i; | |
1406 | ||
1407 | /* User is +Q */ | |
1408 | if (IsNoForward(source_p)) | |
1409 | return NULL; | |
1410 | ||
1411 | while (depth < 16) | |
1412 | { | |
1413 | chptr = find_channel(chptr->mode.forward); | |
1414 | /* Can only forward to existing channels */ | |
1415 | if (chptr == NULL) | |
1416 | return NULL; | |
1417 | /* Already on there, show original error message */ | |
1418 | if (IsMember(source_p, chptr)) | |
1419 | return NULL; | |
1420 | /* Juped. Sending a warning notice would be unfair */ | |
1421 | if (hash_find_resv(chptr->chname)) | |
1422 | return NULL; | |
1423 | /* Don't forward to +Q channel */ | |
1424 | if (chptr->mode.mode & MODE_DISFORWARD) | |
1425 | return NULL; | |
1426 | i = can_join(source_p, chptr, key); | |
1427 | if (i == 0) | |
1428 | return chptr; | |
1429 | if (i != ERR_INVITEONLYCHAN && i != ERR_NEEDREGGEDNICK && i != ERR_THROTTLE && i != ERR_CHANNELISFULL) | |
1430 | return NULL; | |
1431 | depth++; | |
1432 | } | |
1433 | ||
1434 | return NULL; | |
1435 | } | |
67b90240 | 1436 | |
9230426e JH |
1437 | /* |
1438 | * do_join_0 | |
1439 | * | |
1440 | * inputs - pointer to client doing join 0 | |
1441 | * output - NONE | |
1442 | * side effects - Use has decided to join 0. This is legacy | |
1443 | * from the days when channels were numbers not names. *sigh* | |
9230426e JH |
1444 | */ |
1445 | void | |
1446 | do_join_0(struct Client *client_p, struct Client *source_p) | |
1447 | { | |
1448 | struct membership *msptr; | |
1449 | struct Channel *chptr = NULL; | |
1450 | rb_dlink_node *ptr; | |
1451 | ||
1452 | /* Finish the flood grace period... */ | |
1453 | if(MyClient(source_p) && !IsFloodDone(source_p)) | |
1454 | flood_endgrace(source_p); | |
1455 | ||
1456 | sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s JOIN 0", use_id(source_p)); | |
1457 | ||
aa35afbb JH |
1458 | while((ptr = source_p->user->channel.head)) |
1459 | { | |
9230426e JH |
1460 | if(source_p->user->channel.head && MyConnect(source_p) && |
1461 | !IsOper(source_p) && !IsExemptSpambot(source_p)) | |
1462 | check_spambot_warning(source_p, NULL); | |
1463 | ||
9230426e JH |
1464 | msptr = ptr->data; |
1465 | chptr = msptr->chptr; | |
1466 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", | |
1467 | source_p->name, | |
1468 | source_p->username, source_p->host, chptr->chname); | |
1469 | remove_user_from_channel(msptr); | |
1470 | } | |
1471 | } | |
1472 | ||
1473 | int | |
1474 | check_channel_name_loc(struct Client *source_p, const char *name) | |
1475 | { | |
aa35afbb JH |
1476 | const char *p; |
1477 | ||
9230426e JH |
1478 | s_assert(name != NULL); |
1479 | if(EmptyString(name)) | |
1480 | return 0; | |
1481 | ||
1482 | if(ConfigFileEntry.disable_fake_channels && !IsOper(source_p)) | |
1483 | { | |
aa35afbb | 1484 | for(p = name; *p; ++p) |
9230426e | 1485 | { |
aa35afbb | 1486 | if(!IsChanChar(*p) || IsFakeChanChar(*p)) |
9230426e JH |
1487 | return 0; |
1488 | } | |
1489 | } | |
1490 | else | |
1491 | { | |
aa35afbb | 1492 | for(p = name; *p; ++p) |
9230426e | 1493 | { |
aa35afbb | 1494 | if(!IsChanChar(*p)) |
9230426e JH |
1495 | return 0; |
1496 | } | |
1497 | } | |
1498 | ||
aa35afbb JH |
1499 | if(ConfigChannel.only_ascii_channels) |
1500 | { | |
1501 | for(p = name; *p; ++p) | |
1502 | if(*p < 33 || *p > 126) | |
1503 | return 0; | |
1504 | } | |
1505 | ||
1506 | ||
9230426e JH |
1507 | return 1; |
1508 | } | |
1509 | ||
824455ab | 1510 | void user_join(struct Client * client_p, struct Client * source_p, const char * channels, const char * keys) |
67b90240 JH |
1511 | { |
1512 | static char jbuf[BUFSIZE]; | |
1513 | struct Channel *chptr = NULL; | |
1514 | struct ConfItem *aconf; | |
1515 | char *name; | |
1516 | char *key = NULL; | |
1517 | const char *modes; | |
1518 | int i, flags = 0; | |
1519 | char *p = NULL, *p2 = NULL; | |
1520 | char *chanlist; | |
1521 | char *mykey; | |
67b90240 JH |
1522 | |
1523 | jbuf[0] = '\0'; | |
1524 | ||
1525 | if(channels == NULL) | |
1526 | return; | |
1527 | ||
1528 | /* rebuild the list of channels theyre supposed to be joining. | |
1529 | * this code has a side effect of losing keys, but.. | |
1530 | */ | |
1531 | chanlist = LOCAL_COPY(channels); | |
1532 | for(name = rb_strtok_r(chanlist, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) | |
1533 | { | |
1534 | /* check the length and name of channel is ok */ | |
1535 | if(!check_channel_name_loc(source_p, name) || (strlen(name) > LOC_CHANNELLEN)) | |
1536 | { | |
1537 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
1538 | form_str(ERR_BADCHANNAME), (unsigned char *) name); | |
1539 | continue; | |
1540 | } | |
1541 | ||
1542 | /* join 0 parts all channels */ | |
1543 | if(*name == '0' && (name[1] == ',' || name[1] == '\0') && name == chanlist) | |
1544 | { | |
1545 | (void) strcpy(jbuf, "0"); | |
1546 | continue; | |
1547 | } | |
1548 | ||
1549 | /* check it begins with # or &, and local chans are disabled */ | |
1550 | else if(!IsChannelName(name)) | |
1551 | { | |
1552 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
1553 | form_str(ERR_NOSUCHCHANNEL), name); | |
1554 | continue; | |
1555 | } | |
1556 | ||
1557 | /* see if its resv'd */ | |
1558 | if(!IsExemptResv(source_p) && (aconf = hash_find_resv(name))) | |
1559 | { | |
1560 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
1561 | form_str(ERR_BADCHANNAME), name); | |
1562 | ||
1563 | /* dont warn for opers */ | |
1564 | if(!IsExemptJupe(source_p) && !IsOper(source_p)) | |
1565 | sendto_realops_snomask(SNO_SPY, L_NETWIDE, | |
1566 | "User %s (%s@%s) is attempting to join locally juped channel %s (%s)", | |
1567 | source_p->name, source_p->username, | |
1568 | source_p->orighost, name, aconf->passwd); | |
1569 | /* dont update tracking for jupe exempt users, these | |
1570 | * are likely to be spamtrap leaves | |
1571 | */ | |
1572 | else if(IsExemptJupe(source_p)) | |
1573 | aconf->port--; | |
1574 | ||
1575 | continue; | |
1576 | } | |
1577 | ||
1578 | if(splitmode && !IsOper(source_p) && (*name != '&') && | |
1579 | ConfigChannel.no_join_on_split) | |
1580 | { | |
1581 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
1582 | me.name, source_p->name, name); | |
1583 | continue; | |
1584 | } | |
1585 | ||
1586 | if(*jbuf) | |
1587 | (void) strcat(jbuf, ","); | |
1588 | (void) rb_strlcat(jbuf, name, sizeof(jbuf)); | |
1589 | } | |
1590 | ||
1591 | if(keys != NULL) | |
1592 | { | |
1593 | mykey = LOCAL_COPY(keys); | |
1594 | key = rb_strtok_r(mykey, ",", &p2); | |
1595 | } | |
1596 | ||
1597 | for(name = rb_strtok_r(jbuf, ",", &p); name; | |
1598 | key = (key) ? rb_strtok_r(NULL, ",", &p2) : NULL, name = rb_strtok_r(NULL, ",", &p)) | |
1599 | { | |
1600 | hook_data_channel_activity hook_info; | |
1601 | ||
1602 | /* JOIN 0 simply parts all channels the user is in */ | |
1603 | if(*name == '0' && !atoi(name)) | |
1604 | { | |
1605 | if(source_p->user->channel.head == NULL) | |
1606 | continue; | |
1607 | ||
1608 | do_join_0(&me, source_p); | |
1609 | continue; | |
1610 | } | |
1611 | ||
1612 | /* look for the channel */ | |
1613 | if((chptr = find_channel(name)) != NULL) | |
1614 | { | |
1615 | if(IsMember(source_p, chptr)) | |
1616 | continue; | |
1617 | ||
1618 | flags = 0; | |
1619 | } | |
1620 | else | |
1621 | { | |
1622 | hook_data_client_approval moduledata; | |
1623 | ||
1624 | moduledata.client = source_p; | |
1625 | moduledata.approved = 0; | |
1626 | ||
1627 | call_hook(h_can_create_channel, &moduledata); | |
1628 | ||
1629 | if(moduledata.approved != 0) | |
1630 | { | |
1631 | sendto_one(source_p, form_str(moduledata.approved), | |
1632 | me.name, source_p->name, name); | |
1633 | continue; | |
1634 | } | |
1635 | ||
1636 | if(splitmode && !IsOper(source_p) && (*name != '&') && | |
1637 | ConfigChannel.no_create_on_split) | |
1638 | { | |
1639 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
1640 | me.name, source_p->name, name); | |
1641 | continue; | |
1642 | } | |
1643 | ||
1644 | flags = CHFL_CHANOP; | |
1645 | } | |
1646 | ||
1647 | if((rb_dlink_list_length(&source_p->user->channel) >= | |
1648 | (unsigned long) ConfigChannel.max_chans_per_user) && | |
1649 | (!IsOper(source_p) || | |
1650 | (rb_dlink_list_length(&source_p->user->channel) >= | |
1651 | (unsigned long) ConfigChannel.max_chans_per_user * 3))) | |
1652 | { | |
1653 | sendto_one(source_p, form_str(ERR_TOOMANYCHANNELS), | |
1654 | me.name, source_p->name, name); | |
67b90240 JH |
1655 | return; |
1656 | } | |
1657 | ||
67b90240 JH |
1658 | if(chptr == NULL) /* If I already have a chptr, no point doing this */ |
1659 | { | |
1660 | chptr = get_or_create_channel(source_p, name, NULL); | |
1661 | ||
1662 | if(chptr == NULL) | |
1663 | { | |
1664 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
1665 | me.name, source_p->name, name); | |
67b90240 JH |
1666 | continue; |
1667 | } | |
1668 | } | |
1669 | ||
67b90240 JH |
1670 | /* can_join checks for +i key, bans etc */ |
1671 | if((i = can_join(source_p, chptr, key))) | |
1672 | { | |
1673 | if ((i != ERR_NEEDREGGEDNICK && i != ERR_THROTTLE && i != ERR_INVITEONLYCHAN && i != ERR_CHANNELISFULL) || | |
1674 | (!ConfigChannel.use_forward || (chptr = check_forward(source_p, chptr, key)) == NULL)) | |
1675 | { | |
1676 | /* might be wrong, but is there any other better location for such? | |
1677 | * see extensions/chm_operonly.c for other comments on this | |
1678 | * -- dwr | |
1679 | */ | |
1680 | if(i != ERR_CUSTOM) | |
1681 | sendto_one(source_p, form_str(i), me.name, source_p->name, name); | |
1682 | ||
67b90240 JH |
1683 | continue; |
1684 | } | |
1685 | ||
1686 | sendto_one_numeric(source_p, ERR_LINKCHANNEL, form_str(ERR_LINKCHANNEL), name, chptr->chname); | |
1687 | } | |
aa35afbb JH |
1688 | |
1689 | if(flags == 0 && | |
1690 | !IsOper(source_p) && !IsExemptSpambot(source_p)) | |
1691 | check_spambot_warning(source_p, name); | |
67b90240 JH |
1692 | |
1693 | /* add the user to the channel */ | |
1694 | add_user_to_channel(chptr, source_p, flags); | |
1695 | if (chptr->mode.join_num && | |
1696 | rb_current_time() - chptr->join_delta >= chptr->mode.join_time) | |
1697 | { | |
1698 | chptr->join_count = 0; | |
1699 | chptr->join_delta = rb_current_time(); | |
1700 | } | |
1701 | chptr->join_count++; | |
1702 | ||
1703 | /* we send the user their join here, because we could have to | |
1704 | * send a mode out next. | |
1705 | */ | |
1706 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", | |
1707 | source_p->name, | |
1708 | source_p->username, source_p->host, chptr->chname); | |
1709 | ||
1710 | /* its a new channel, set +nt and burst. */ | |
1711 | if(flags & CHFL_CHANOP) | |
1712 | { | |
1713 | chptr->channelts = rb_current_time(); | |
13ec57db JH |
1714 | |
1715 | /* autochanmodes stuff */ | |
1716 | if(ConfigChannel.autochanmodes) | |
1717 | { | |
1718 | char * ch; | |
1719 | for(ch = ConfigChannel.autochanmodes; *ch; *ch++) | |
1720 | { | |
1721 | chptr->mode.mode |= chmode_table[*ch].mode_type; | |
1722 | } | |
1723 | } | |
1724 | else | |
1725 | { | |
1726 | chptr->mode.mode |= MODE_TOPICLIMIT; | |
1727 | chptr->mode.mode |= MODE_NOPRIVMSGS; | |
1728 | } | |
1729 | ||
67b90240 JH |
1730 | modes = channel_modes(chptr, &me); |
1731 | ||
1732 | sendto_channel_local(ONLY_CHANOPS, chptr, ":%s MODE %s %s", | |
1733 | me.name, chptr->chname, modes); | |
1734 | ||
1735 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, | |
1736 | ":%s SJOIN %ld %s %s :@%s", | |
1737 | me.id, (long) chptr->channelts, | |
1738 | chptr->chname, modes, source_p->id); | |
1739 | } | |
1740 | else | |
1741 | { | |
1742 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, | |
1743 | ":%s JOIN %ld %s +", | |
1744 | use_id(source_p), (long) chptr->channelts, | |
1745 | chptr->chname); | |
1746 | } | |
1747 | ||
1748 | del_invite(chptr, source_p); | |
1749 | ||
1750 | if(chptr->topic != NULL) | |
1751 | { | |
1752 | sendto_one(source_p, form_str(RPL_TOPIC), me.name, | |
1753 | source_p->name, chptr->chname, chptr->topic); | |
1754 | ||
1755 | sendto_one(source_p, form_str(RPL_TOPICWHOTIME), | |
1756 | me.name, source_p->name, chptr->chname, | |
1757 | chptr->topic_info, chptr->topic_time); | |
1758 | } | |
1759 | ||
1760 | channel_member_names(chptr, source_p, 1); | |
1761 | ||
67b90240 JH |
1762 | hook_info.client = source_p; |
1763 | hook_info.chptr = chptr; | |
1764 | hook_info.key = key; | |
1765 | call_hook(h_channel_join, &hook_info); | |
1766 | } | |
1767 | ||
1768 | return; | |
1769 | } |