]>
Commit | Line | Data |
---|---|---|
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 | */ | |
24 | ||
25 | #include "stdinc.h" | |
26 | #include "channel.h" | |
27 | #include "chmode.h" | |
28 | #include "client.h" | |
29 | #include "hash.h" | |
30 | #include "hook.h" | |
31 | #include "match.h" | |
32 | #include "ircd.h" | |
33 | #include "numeric.h" | |
34 | #include "s_serv.h" /* captab */ | |
35 | #include "s_user.h" | |
36 | #include "send.h" | |
37 | #include "whowas.h" | |
38 | #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */ | |
39 | #include "s_newconf.h" | |
40 | #include "logger.h" | |
41 | #include "s_assert.h" | |
42 | ||
43 | struct config_channel_entry ConfigChannel; | |
44 | rb_dlink_list global_channel_list; | |
45 | static rb_bh *channel_heap; | |
46 | static rb_bh *ban_heap; | |
47 | static rb_bh *topic_heap; | |
48 | static rb_bh *member_heap; | |
49 | ||
50 | static void free_topic(struct Channel *chptr); | |
51 | ||
52 | static int h_can_join; | |
53 | static int h_can_send; | |
54 | int h_get_channel_access; | |
55 | ||
56 | /* init_channels() | |
57 | * | |
58 | * input - | |
59 | * output - | |
60 | * side effects - initialises the various blockheaps | |
61 | */ | |
62 | void | |
63 | init_channels(void) | |
64 | { | |
65 | channel_heap = rb_bh_create(sizeof(struct Channel), CHANNEL_HEAP_SIZE, "channel_heap"); | |
66 | ban_heap = rb_bh_create(sizeof(struct Ban), BAN_HEAP_SIZE, "ban_heap"); | |
67 | topic_heap = rb_bh_create(TOPICLEN + 1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE, "topic_heap"); | |
68 | member_heap = rb_bh_create(sizeof(struct membership), MEMBER_HEAP_SIZE, "member_heap"); | |
69 | ||
70 | h_can_join = register_hook("can_join"); | |
71 | h_can_send = register_hook("can_send"); | |
72 | h_get_channel_access = register_hook("get_channel_access"); | |
73 | } | |
74 | ||
75 | /* | |
76 | * allocate_channel - Allocates a channel | |
77 | */ | |
78 | struct Channel * | |
79 | allocate_channel(const char *chname) | |
80 | { | |
81 | struct Channel *chptr; | |
82 | chptr = rb_bh_alloc(channel_heap); | |
83 | chptr->chname = rb_strdup(chname); | |
84 | return (chptr); | |
85 | } | |
86 | ||
87 | void | |
88 | free_channel(struct Channel *chptr) | |
89 | { | |
90 | rb_free(chptr->chname); | |
91 | rb_free(chptr->mode_lock); | |
92 | rb_bh_free(channel_heap, chptr); | |
93 | } | |
94 | ||
95 | struct Ban * | |
96 | allocate_ban(const char *banstr, const char *who, const char *forward) | |
97 | { | |
98 | struct Ban *bptr; | |
99 | bptr = rb_bh_alloc(ban_heap); | |
100 | bptr->banstr = rb_strdup(banstr); | |
101 | bptr->who = rb_strdup(who); | |
102 | bptr->forward = forward ? rb_strdup(forward) : NULL; | |
103 | ||
104 | return (bptr); | |
105 | } | |
106 | ||
107 | void | |
108 | free_ban(struct Ban *bptr) | |
109 | { | |
110 | rb_free(bptr->banstr); | |
111 | rb_free(bptr->who); | |
112 | rb_free(bptr->forward); | |
113 | rb_bh_free(ban_heap, bptr); | |
114 | } | |
115 | ||
116 | /* | |
117 | * send_channel_join() | |
118 | * | |
119 | * input - channel to join, client joining. | |
120 | * output - none | |
121 | * side effects - none | |
122 | */ | |
123 | void | |
124 | send_channel_join(struct Channel *chptr, struct Client *client_p) | |
125 | { | |
126 | if (!IsClient(client_p)) | |
127 | return; | |
128 | ||
129 | sendto_channel_local_with_capability(client_p, ALL_MEMBERS, NOCAPS, CLICAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN %s", | |
130 | client_p->name, client_p->username, client_p->host, chptr->chname); | |
131 | ||
132 | sendto_channel_local_with_capability(client_p, ALL_MEMBERS, CLICAP_EXTENDED_JOIN, NOCAPS, chptr, ":%s!%s@%s JOIN %s %s :%s", | |
133 | client_p->name, client_p->username, client_p->host, chptr->chname, | |
134 | EmptyString(client_p->user->suser) ? "*" : client_p->user->suser, | |
135 | client_p->info); | |
136 | ||
137 | /* Send away message to away-notify enabled clients. */ | |
138 | if (client_p->user->away) | |
139 | sendto_channel_local_with_capability_butone(client_p, ALL_MEMBERS, CLICAP_AWAY_NOTIFY, NOCAPS, chptr, | |
140 | ":%s!%s@%s AWAY :%s", client_p->name, client_p->username, | |
141 | client_p->host, client_p->user->away); | |
142 | } | |
143 | ||
144 | /* find_channel_membership() | |
145 | * | |
146 | * input - channel to find them in, client to find | |
147 | * output - membership of client in channel, else NULL | |
148 | * side effects - | |
149 | */ | |
150 | struct membership * | |
151 | find_channel_membership(struct Channel *chptr, struct Client *client_p) | |
152 | { | |
153 | struct membership *msptr; | |
154 | rb_dlink_node *ptr; | |
155 | ||
156 | if(!IsClient(client_p)) | |
157 | return NULL; | |
158 | ||
159 | /* Pick the most efficient list to use to be nice to things like | |
160 | * CHANSERV which could be in a large number of channels | |
161 | */ | |
162 | if(rb_dlink_list_length(&chptr->members) < rb_dlink_list_length(&client_p->user->channel)) | |
163 | { | |
164 | RB_DLINK_FOREACH(ptr, chptr->members.head) | |
165 | { | |
166 | msptr = ptr->data; | |
167 | ||
168 | if(msptr->client_p == client_p) | |
169 | return msptr; | |
170 | } | |
171 | } | |
172 | else | |
173 | { | |
174 | RB_DLINK_FOREACH(ptr, client_p->user->channel.head) | |
175 | { | |
176 | msptr = ptr->data; | |
177 | ||
178 | if(msptr->chptr == chptr) | |
179 | return msptr; | |
180 | } | |
181 | } | |
182 | ||
183 | return NULL; | |
184 | } | |
185 | ||
186 | /* find_channel_status() | |
187 | * | |
188 | * input - membership to get status for, whether we can combine flags | |
189 | * output - flags of user on channel | |
190 | * side effects - | |
191 | */ | |
192 | const char * | |
193 | find_channel_status(struct membership *msptr, int combine) | |
194 | { | |
195 | static char buffer[3]; | |
196 | char *p; | |
197 | ||
198 | p = buffer; | |
199 | ||
200 | if(is_chanop(msptr)) | |
201 | { | |
202 | if(!combine) | |
203 | return "@"; | |
204 | *p++ = '@'; | |
205 | } | |
206 | ||
207 | if(is_voiced(msptr)) | |
208 | *p++ = '+'; | |
209 | ||
210 | *p = '\0'; | |
211 | return buffer; | |
212 | } | |
213 | ||
214 | /* add_user_to_channel() | |
215 | * | |
216 | * input - channel to add client to, client to add, channel flags | |
217 | * output - | |
218 | * side effects - user is added to channel | |
219 | */ | |
220 | void | |
221 | add_user_to_channel(struct Channel *chptr, struct Client *client_p, int flags) | |
222 | { | |
223 | struct membership *msptr; | |
224 | ||
225 | s_assert(client_p->user != NULL); | |
226 | if(client_p->user == NULL) | |
227 | return; | |
228 | ||
229 | msptr = rb_bh_alloc(member_heap); | |
230 | ||
231 | msptr->chptr = chptr; | |
232 | msptr->client_p = client_p; | |
233 | msptr->flags = flags; | |
234 | ||
235 | rb_dlinkAdd(msptr, &msptr->usernode, &client_p->user->channel); | |
236 | rb_dlinkAdd(msptr, &msptr->channode, &chptr->members); | |
237 | ||
238 | if(MyClient(client_p)) | |
239 | rb_dlinkAdd(msptr, &msptr->locchannode, &chptr->locmembers); | |
240 | } | |
241 | ||
242 | /* remove_user_from_channel() | |
243 | * | |
244 | * input - membership pointer to remove from channel | |
245 | * output - | |
246 | * side effects - membership (thus user) is removed from channel | |
247 | */ | |
248 | void | |
249 | remove_user_from_channel(struct membership *msptr) | |
250 | { | |
251 | struct Client *client_p; | |
252 | struct Channel *chptr; | |
253 | s_assert(msptr != NULL); | |
254 | if(msptr == NULL) | |
255 | return; | |
256 | ||
257 | client_p = msptr->client_p; | |
258 | chptr = msptr->chptr; | |
259 | ||
260 | rb_dlinkDelete(&msptr->usernode, &client_p->user->channel); | |
261 | rb_dlinkDelete(&msptr->channode, &chptr->members); | |
262 | ||
263 | if(client_p->servptr == &me) | |
264 | rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); | |
265 | ||
266 | if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) | |
267 | destroy_channel(chptr); | |
268 | ||
269 | rb_bh_free(member_heap, msptr); | |
270 | ||
271 | return; | |
272 | } | |
273 | ||
274 | /* remove_user_from_channels() | |
275 | * | |
276 | * input - user to remove from all channels | |
277 | * output - | |
278 | * side effects - user is removed from all channels | |
279 | */ | |
280 | void | |
281 | remove_user_from_channels(struct Client *client_p) | |
282 | { | |
283 | struct Channel *chptr; | |
284 | struct membership *msptr; | |
285 | rb_dlink_node *ptr; | |
286 | rb_dlink_node *next_ptr; | |
287 | ||
288 | if(client_p == NULL) | |
289 | return; | |
290 | ||
291 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->user->channel.head) | |
292 | { | |
293 | msptr = ptr->data; | |
294 | chptr = msptr->chptr; | |
295 | ||
296 | rb_dlinkDelete(&msptr->channode, &chptr->members); | |
297 | ||
298 | if(client_p->servptr == &me) | |
299 | rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); | |
300 | ||
301 | if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) | |
302 | destroy_channel(chptr); | |
303 | ||
304 | rb_bh_free(member_heap, msptr); | |
305 | } | |
306 | ||
307 | client_p->user->channel.head = client_p->user->channel.tail = NULL; | |
308 | client_p->user->channel.length = 0; | |
309 | } | |
310 | ||
311 | /* invalidate_bancache_user() | |
312 | * | |
313 | * input - user to invalidate ban cache for | |
314 | * output - | |
315 | * side effects - ban cache is invalidated for all memberships of that user | |
316 | * to be used after a nick change | |
317 | */ | |
318 | void | |
319 | invalidate_bancache_user(struct Client *client_p) | |
320 | { | |
321 | struct membership *msptr; | |
322 | rb_dlink_node *ptr; | |
323 | ||
324 | if(client_p == NULL) | |
325 | return; | |
326 | ||
327 | RB_DLINK_FOREACH(ptr, client_p->user->channel.head) | |
328 | { | |
329 | msptr = ptr->data; | |
330 | msptr->bants = 0; | |
331 | msptr->flags &= ~CHFL_BANNED; | |
332 | } | |
333 | } | |
334 | ||
335 | /* check_channel_name() | |
336 | * | |
337 | * input - channel name | |
338 | * output - true if valid channel name, else false | |
339 | * side effects - | |
340 | */ | |
341 | bool | |
342 | check_channel_name(const char *name) | |
343 | { | |
344 | s_assert(name != NULL); | |
345 | if(name == NULL) | |
346 | return false; | |
347 | ||
348 | for (; *name; ++name) | |
349 | { | |
350 | if(!IsChanChar(*name)) | |
351 | return false; | |
352 | } | |
353 | ||
354 | return true; | |
355 | } | |
356 | ||
357 | /* free_channel_list() | |
358 | * | |
359 | * input - rb_dlink list to free | |
360 | * output - | |
361 | * side effects - list of b/e/I modes is cleared | |
362 | */ | |
363 | void | |
364 | free_channel_list(rb_dlink_list * list) | |
365 | { | |
366 | rb_dlink_node *ptr; | |
367 | rb_dlink_node *next_ptr; | |
368 | struct Ban *actualBan; | |
369 | ||
370 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) | |
371 | { | |
372 | actualBan = ptr->data; | |
373 | free_ban(actualBan); | |
374 | } | |
375 | ||
376 | list->head = list->tail = NULL; | |
377 | list->length = 0; | |
378 | } | |
379 | ||
380 | /* destroy_channel() | |
381 | * | |
382 | * input - channel to destroy | |
383 | * output - | |
384 | * side effects - channel is obliterated | |
385 | */ | |
386 | void | |
387 | destroy_channel(struct Channel *chptr) | |
388 | { | |
389 | rb_dlink_node *ptr, *next_ptr; | |
390 | ||
391 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) | |
392 | { | |
393 | del_invite(chptr, ptr->data); | |
394 | } | |
395 | ||
396 | /* free all bans/exceptions/denies */ | |
397 | free_channel_list(&chptr->banlist); | |
398 | free_channel_list(&chptr->exceptlist); | |
399 | free_channel_list(&chptr->invexlist); | |
400 | free_channel_list(&chptr->quietlist); | |
401 | ||
402 | /* Free the topic */ | |
403 | free_topic(chptr); | |
404 | ||
405 | rb_dlinkDelete(&chptr->node, &global_channel_list); | |
406 | del_from_channel_hash(chptr->chname, chptr); | |
407 | free_channel(chptr); | |
408 | } | |
409 | ||
410 | /* channel_pub_or_secret() | |
411 | * | |
412 | * input - channel | |
413 | * output - "=" if public, "@" if secret, else "*" | |
414 | * side effects - | |
415 | */ | |
416 | static const char * | |
417 | channel_pub_or_secret(struct Channel *chptr) | |
418 | { | |
419 | if(PubChannel(chptr)) | |
420 | return ("="); | |
421 | else if(SecretChannel(chptr)) | |
422 | return ("@"); | |
423 | return ("*"); | |
424 | } | |
425 | ||
426 | /* channel_member_names() | |
427 | * | |
428 | * input - channel to list, client to list to, show endofnames | |
429 | * output - | |
430 | * side effects - client is given list of users on channel | |
431 | */ | |
432 | void | |
433 | channel_member_names(struct Channel *chptr, struct Client *client_p, int show_eon) | |
434 | { | |
435 | struct membership *msptr; | |
436 | struct Client *target_p; | |
437 | rb_dlink_node *ptr; | |
438 | char lbuf[BUFSIZE]; | |
439 | char *t; | |
440 | int mlen; | |
441 | int tlen; | |
442 | int cur_len; | |
443 | int is_member; | |
444 | int stack = IsCapable(client_p, CLICAP_MULTI_PREFIX); | |
445 | ||
446 | if(ShowChannel(client_p, chptr)) | |
447 | { | |
448 | is_member = IsMember(client_p, chptr); | |
449 | ||
450 | cur_len = mlen = sprintf(lbuf, form_str(RPL_NAMREPLY), | |
451 | me.name, client_p->name, | |
452 | channel_pub_or_secret(chptr), chptr->chname); | |
453 | ||
454 | t = lbuf + cur_len; | |
455 | ||
456 | RB_DLINK_FOREACH(ptr, chptr->members.head) | |
457 | { | |
458 | msptr = ptr->data; | |
459 | target_p = msptr->client_p; | |
460 | ||
461 | if(IsInvisible(target_p) && !is_member) | |
462 | continue; | |
463 | ||
464 | if (IsCapable(client_p, CLICAP_USERHOST_IN_NAMES)) | |
465 | { | |
466 | /* space, possible "@+" prefix */ | |
467 | if (cur_len + strlen(target_p->name) + strlen(target_p->username) + strlen(target_p->host) + 5 >= BUFSIZE - 5) | |
468 | { | |
469 | *(t - 1) = '\0'; | |
470 | sendto_one(client_p, "%s", lbuf); | |
471 | cur_len = mlen; | |
472 | t = lbuf + mlen; | |
473 | } | |
474 | ||
475 | tlen = sprintf(t, "%s%s!%s@%s ", find_channel_status(msptr, stack), | |
476 | target_p->name, target_p->username, target_p->host); | |
477 | } | |
478 | else | |
479 | { | |
480 | /* space, possible "@+" prefix */ | |
481 | if(cur_len + strlen(target_p->name) + 3 >= BUFSIZE - 3) | |
482 | { | |
483 | *(t - 1) = '\0'; | |
484 | sendto_one(client_p, "%s", lbuf); | |
485 | cur_len = mlen; | |
486 | t = lbuf + mlen; | |
487 | } | |
488 | ||
489 | tlen = sprintf(t, "%s%s ", find_channel_status(msptr, stack), | |
490 | target_p->name); | |
491 | } | |
492 | ||
493 | cur_len += tlen; | |
494 | t += tlen; | |
495 | } | |
496 | ||
497 | /* The old behaviour here was to always output our buffer, | |
498 | * even if there are no clients we can show. This happens | |
499 | * when a client does "NAMES" with no parameters, and all | |
500 | * the clients on a -sp channel are +i. I dont see a good | |
501 | * reason for keeping that behaviour, as it just wastes | |
502 | * bandwidth. --anfl | |
503 | */ | |
504 | if(cur_len != mlen) | |
505 | { | |
506 | *(t - 1) = '\0'; | |
507 | sendto_one(client_p, "%s", lbuf); | |
508 | } | |
509 | } | |
510 | ||
511 | if(show_eon) | |
512 | sendto_one(client_p, form_str(RPL_ENDOFNAMES), | |
513 | me.name, client_p->name, chptr->chname); | |
514 | } | |
515 | ||
516 | /* del_invite() | |
517 | * | |
518 | * input - channel to remove invite from, client to remove | |
519 | * output - | |
520 | * side effects - user is removed from invite list, if exists | |
521 | */ | |
522 | void | |
523 | del_invite(struct Channel *chptr, struct Client *who) | |
524 | { | |
525 | rb_dlinkFindDestroy(who, &chptr->invites); | |
526 | rb_dlinkFindDestroy(chptr, &who->user->invited); | |
527 | } | |
528 | ||
529 | /* is_banned_list() | |
530 | * | |
531 | * input - channel to check bans for, ban list (banlist or quietlist), | |
532 | * user to check bans against, optional prebuilt buffers, | |
533 | * optional forward channel pointer | |
534 | * output - 1 if banned, else 0 | |
535 | * side effects - | |
536 | */ | |
537 | static int | |
538 | is_banned_list(struct Channel *chptr, rb_dlink_list *list, | |
539 | struct Client *who, struct membership *msptr, | |
540 | const char *s, const char *s2, const char **forward) | |
541 | { | |
542 | char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; | |
543 | char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
544 | char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
545 | char src_ip4host[NICKLEN + USERLEN + HOSTLEN + 6]; | |
546 | char *s3 = NULL; | |
547 | char *s4 = NULL; | |
548 | struct sockaddr_in ip4; | |
549 | rb_dlink_node *ptr; | |
550 | struct Ban *actualBan = NULL; | |
551 | struct Ban *actualExcept = NULL; | |
552 | ||
553 | if(!MyClient(who)) | |
554 | return 0; | |
555 | ||
556 | /* if the buffers havent been built, do it here */ | |
557 | if(s == NULL) | |
558 | { | |
559 | sprintf(src_host, "%s!%s@%s", who->name, who->username, who->host); | |
560 | sprintf(src_iphost, "%s!%s@%s", who->name, who->username, who->sockhost); | |
561 | ||
562 | s = src_host; | |
563 | s2 = src_iphost; | |
564 | } | |
565 | if(who->localClient->mangledhost != NULL) | |
566 | { | |
567 | /* if host mangling mode enabled, also check their real host */ | |
568 | if(!strcmp(who->host, who->localClient->mangledhost)) | |
569 | { | |
570 | sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->orighost); | |
571 | s3 = src_althost; | |
572 | } | |
573 | /* if host mangling mode not enabled and no other spoof, | |
574 | * also check the mangled form of their host */ | |
575 | else if (!IsDynSpoof(who)) | |
576 | { | |
577 | sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->localClient->mangledhost); | |
578 | s3 = src_althost; | |
579 | } | |
580 | } | |
581 | #ifdef RB_IPV6 | |
582 | if(GET_SS_FAMILY(&who->localClient->ip) == AF_INET6 && | |
583 | rb_ipv4_from_ipv6((const struct sockaddr_in6 *)&who->localClient->ip, &ip4)) | |
584 | { | |
585 | sprintf(src_ip4host, "%s!%s@", who->name, who->username); | |
586 | s4 = src_ip4host + strlen(src_ip4host); | |
587 | rb_inet_ntop_sock((struct sockaddr *)&ip4, | |
588 | s4, src_ip4host + sizeof src_ip4host - s4); | |
589 | s4 = src_ip4host; | |
590 | } | |
591 | #endif | |
592 | ||
593 | RB_DLINK_FOREACH(ptr, list->head) | |
594 | { | |
595 | actualBan = ptr->data; | |
596 | if(match(actualBan->banstr, s) || | |
597 | match(actualBan->banstr, s2) || | |
598 | match_cidr(actualBan->banstr, s2) || | |
599 | match_extban(actualBan->banstr, who, chptr, CHFL_BAN) || | |
600 | (s3 != NULL && match(actualBan->banstr, s3)) | |
601 | #ifdef RB_IPV6 | |
602 | || | |
603 | (s4 != NULL && (match(actualBan->banstr, s4) || match_cidr(actualBan->banstr, s4))) | |
604 | #endif | |
605 | ) | |
606 | break; | |
607 | else | |
608 | actualBan = NULL; | |
609 | } | |
610 | ||
611 | if((actualBan != NULL) && ConfigChannel.use_except) | |
612 | { | |
613 | RB_DLINK_FOREACH(ptr, chptr->exceptlist.head) | |
614 | { | |
615 | actualExcept = ptr->data; | |
616 | ||
617 | /* theyre exempted.. */ | |
618 | if(match(actualExcept->banstr, s) || | |
619 | match(actualExcept->banstr, s2) || | |
620 | match_cidr(actualExcept->banstr, s2) || | |
621 | match_extban(actualExcept->banstr, who, chptr, CHFL_EXCEPTION) || | |
622 | (s3 != NULL && match(actualExcept->banstr, s3))) | |
623 | { | |
624 | /* cache the fact theyre not banned */ | |
625 | if(msptr != NULL) | |
626 | { | |
627 | msptr->bants = chptr->bants; | |
628 | msptr->flags &= ~CHFL_BANNED; | |
629 | } | |
630 | ||
631 | return CHFL_EXCEPTION; | |
632 | } | |
633 | } | |
634 | } | |
635 | ||
636 | /* cache the banned/not banned status */ | |
637 | if(msptr != NULL) | |
638 | { | |
639 | msptr->bants = chptr->bants; | |
640 | ||
641 | if(actualBan != NULL) | |
642 | { | |
643 | msptr->flags |= CHFL_BANNED; | |
644 | return CHFL_BAN; | |
645 | } | |
646 | else | |
647 | { | |
648 | msptr->flags &= ~CHFL_BANNED; | |
649 | return 0; | |
650 | } | |
651 | } | |
652 | ||
653 | if (actualBan && actualBan->forward && forward) | |
654 | *forward = actualBan->forward; | |
655 | ||
656 | return ((actualBan ? CHFL_BAN : 0)); | |
657 | } | |
658 | ||
659 | /* is_banned() | |
660 | * | |
661 | * input - channel to check bans for, user to check bans against | |
662 | * optional prebuilt buffers, optional forward channel pointer | |
663 | * output - 1 if banned, else 0 | |
664 | * side effects - | |
665 | */ | |
666 | int | |
667 | is_banned(struct Channel *chptr, struct Client *who, struct membership *msptr, | |
668 | const char *s, const char *s2, const char **forward) | |
669 | { | |
670 | #if 0 | |
671 | if (chptr->last_checked_client != NULL && | |
672 | who == chptr->last_checked_client && | |
673 | chptr->last_checked_type == CHFL_BAN && | |
674 | chptr->last_checked_ts > chptr->bants) | |
675 | return chptr->last_checked_result; | |
676 | ||
677 | chptr->last_checked_client = who; | |
678 | chptr->last_checked_type = CHFL_BAN; | |
679 | chptr->last_checked_result = is_banned_list(chptr, &chptr->banlist, who, msptr, s, s2, forward); | |
680 | chptr->last_checked_ts = rb_current_time(); | |
681 | ||
682 | return chptr->last_checked_result; | |
683 | #else | |
684 | return is_banned_list(chptr, &chptr->banlist, who, msptr, s, s2, forward); | |
685 | #endif | |
686 | } | |
687 | ||
688 | /* is_quieted() | |
689 | * | |
690 | * input - channel to check bans for, user to check bans against | |
691 | * optional prebuilt buffers | |
692 | * output - 1 if banned, else 0 | |
693 | * side effects - | |
694 | */ | |
695 | int | |
696 | is_quieted(struct Channel *chptr, struct Client *who, struct membership *msptr, | |
697 | const char *s, const char *s2) | |
698 | { | |
699 | #if 0 | |
700 | if (chptr->last_checked_client != NULL && | |
701 | who == chptr->last_checked_client && | |
702 | chptr->last_checked_type == CHFL_QUIET && | |
703 | chptr->last_checked_ts > chptr->bants) | |
704 | return chptr->last_checked_result; | |
705 | ||
706 | chptr->last_checked_client = who; | |
707 | chptr->last_checked_type = CHFL_QUIET; | |
708 | chptr->last_checked_result = is_banned_list(chptr, &chptr->quietlist, who, msptr, s, s2, NULL); | |
709 | chptr->last_checked_ts = rb_current_time(); | |
710 | ||
711 | return chptr->last_checked_result; | |
712 | #else | |
713 | return is_banned_list(chptr, &chptr->quietlist, who, msptr, s, s2, NULL); | |
714 | #endif | |
715 | } | |
716 | ||
717 | /* can_join() | |
718 | * | |
719 | * input - client to check, channel to check for, key | |
720 | * output - reason for not being able to join, else 0, channel name to forward to | |
721 | * side effects - | |
722 | * caveats - this function should only be called on a local user. | |
723 | */ | |
724 | int | |
725 | can_join(struct Client *source_p, struct Channel *chptr, const char *key, const char **forward) | |
726 | { | |
727 | rb_dlink_node *invite = NULL; | |
728 | rb_dlink_node *ptr; | |
729 | struct Ban *invex = NULL; | |
730 | char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; | |
731 | char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
732 | char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
733 | int use_althost = 0; | |
734 | int i = 0; | |
735 | hook_data_channel moduledata; | |
736 | ||
737 | s_assert(source_p->localClient != NULL); | |
738 | ||
739 | moduledata.client = source_p; | |
740 | moduledata.chptr = chptr; | |
741 | moduledata.approved = 0; | |
742 | ||
743 | sprintf(src_host, "%s!%s@%s", source_p->name, source_p->username, source_p->host); | |
744 | sprintf(src_iphost, "%s!%s@%s", source_p->name, source_p->username, source_p->sockhost); | |
745 | if(source_p->localClient->mangledhost != NULL) | |
746 | { | |
747 | /* if host mangling mode enabled, also check their real host */ | |
748 | if(!strcmp(source_p->host, source_p->localClient->mangledhost)) | |
749 | { | |
750 | sprintf(src_althost, "%s!%s@%s", source_p->name, source_p->username, source_p->orighost); | |
751 | use_althost = 1; | |
752 | } | |
753 | /* if host mangling mode not enabled and no other spoof, | |
754 | * also check the mangled form of their host */ | |
755 | else if (!IsDynSpoof(source_p)) | |
756 | { | |
757 | sprintf(src_althost, "%s!%s@%s", source_p->name, source_p->username, source_p->localClient->mangledhost); | |
758 | use_althost = 1; | |
759 | } | |
760 | } | |
761 | ||
762 | if((is_banned(chptr, source_p, NULL, src_host, src_iphost, forward)) == CHFL_BAN) | |
763 | { | |
764 | moduledata.approved = ERR_BANNEDFROMCHAN; | |
765 | goto finish_join_check; | |
766 | } | |
767 | ||
768 | if(*chptr->mode.key && (EmptyString(key) || irccmp(chptr->mode.key, key))) | |
769 | { | |
770 | moduledata.approved = ERR_BADCHANNELKEY; | |
771 | goto finish_join_check; | |
772 | } | |
773 | ||
774 | /* All checks from this point on will forward... */ | |
775 | if(forward) | |
776 | *forward = chptr->mode.forward; | |
777 | ||
778 | if(chptr->mode.mode & MODE_INVITEONLY) | |
779 | { | |
780 | RB_DLINK_FOREACH(invite, source_p->user->invited.head) | |
781 | { | |
782 | if(invite->data == chptr) | |
783 | break; | |
784 | } | |
785 | if(invite == NULL) | |
786 | { | |
787 | if(!ConfigChannel.use_invex) | |
788 | moduledata.approved = ERR_INVITEONLYCHAN; | |
789 | RB_DLINK_FOREACH(ptr, chptr->invexlist.head) | |
790 | { | |
791 | invex = ptr->data; | |
792 | if(match(invex->banstr, src_host) | |
793 | || match(invex->banstr, src_iphost) | |
794 | || match_cidr(invex->banstr, src_iphost) | |
795 | || match_extban(invex->banstr, source_p, chptr, CHFL_INVEX) | |
796 | || (use_althost && match(invex->banstr, src_althost))) | |
797 | break; | |
798 | } | |
799 | if(ptr == NULL) | |
800 | moduledata.approved = ERR_INVITEONLYCHAN; | |
801 | } | |
802 | } | |
803 | ||
804 | if(chptr->mode.limit && | |
805 | rb_dlink_list_length(&chptr->members) >= (unsigned long) chptr->mode.limit) | |
806 | i = ERR_CHANNELISFULL; | |
807 | if(chptr->mode.mode & MODE_REGONLY && EmptyString(source_p->user->suser)) | |
808 | i = ERR_NEEDREGGEDNICK; | |
809 | /* join throttling stuff --nenolod */ | |
810 | else if(chptr->mode.join_num > 0 && chptr->mode.join_time > 0) | |
811 | { | |
812 | if ((rb_current_time() - chptr->join_delta <= | |
813 | chptr->mode.join_time) && (chptr->join_count >= | |
814 | chptr->mode.join_num)) | |
815 | i = ERR_THROTTLE; | |
816 | } | |
817 | ||
818 | /* allow /invite to override +l/+r/+j also -- jilles */ | |
819 | if (i != 0 && invite == NULL) | |
820 | { | |
821 | RB_DLINK_FOREACH(invite, source_p->user->invited.head) | |
822 | { | |
823 | if(invite->data == chptr) | |
824 | break; | |
825 | } | |
826 | if (invite == NULL) | |
827 | moduledata.approved = i; | |
828 | } | |
829 | ||
830 | finish_join_check: | |
831 | call_hook(h_can_join, &moduledata); | |
832 | ||
833 | return moduledata.approved; | |
834 | } | |
835 | ||
836 | /* can_send() | |
837 | * | |
838 | * input - user to check in channel, membership pointer | |
839 | * output - whether can explicitly send or not, else CAN_SEND_NONOP | |
840 | * side effects - | |
841 | */ | |
842 | int | |
843 | can_send(struct Channel *chptr, struct Client *source_p, struct membership *msptr) | |
844 | { | |
845 | hook_data_channel_approval moduledata; | |
846 | ||
847 | moduledata.approved = CAN_SEND_NONOP; | |
848 | moduledata.dir = MODE_QUERY; | |
849 | ||
850 | if(IsServer(source_p) || IsService(source_p)) | |
851 | return CAN_SEND_OPV; | |
852 | ||
853 | if(MyClient(source_p) && hash_find_resv(chptr->chname) && | |
854 | !IsOper(source_p) && !IsExemptResv(source_p)) | |
855 | moduledata.approved = CAN_SEND_NO; | |
856 | ||
857 | if(msptr == NULL) | |
858 | { | |
859 | msptr = find_channel_membership(chptr, source_p); | |
860 | ||
861 | if(msptr == NULL) | |
862 | { | |
863 | /* if its +m or +n and theyre not in the channel, | |
864 | * they cant send. we dont check bans here because | |
865 | * theres no possibility of caching them --fl | |
866 | */ | |
867 | if(chptr->mode.mode & MODE_NOPRIVMSGS || chptr->mode.mode & MODE_MODERATED) | |
868 | moduledata.approved = CAN_SEND_NO; | |
869 | else | |
870 | moduledata.approved = CAN_SEND_NONOP; | |
871 | ||
872 | return moduledata.approved; | |
873 | } | |
874 | } | |
875 | ||
876 | if(chptr->mode.mode & MODE_MODERATED) | |
877 | moduledata.approved = CAN_SEND_NO; | |
878 | ||
879 | if(MyClient(source_p)) | |
880 | { | |
881 | /* cached can_send */ | |
882 | if(msptr->bants == chptr->bants) | |
883 | { | |
884 | if(can_send_banned(msptr)) | |
885 | moduledata.approved = CAN_SEND_NO; | |
886 | } | |
887 | else if(is_banned(chptr, source_p, msptr, NULL, NULL, NULL) == CHFL_BAN | |
888 | || is_quieted(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN) | |
889 | moduledata.approved = CAN_SEND_NO; | |
890 | } | |
891 | ||
892 | if(is_chanop_voiced(msptr)) | |
893 | moduledata.approved = CAN_SEND_OPV; | |
894 | ||
895 | moduledata.client = source_p; | |
896 | moduledata.chptr = msptr->chptr; | |
897 | moduledata.msptr = msptr; | |
898 | moduledata.target = NULL; | |
899 | moduledata.dir = (moduledata.approved == CAN_SEND_NO) ? MODE_ADD : MODE_QUERY; | |
900 | ||
901 | call_hook(h_can_send, &moduledata); | |
902 | ||
903 | return moduledata.approved; | |
904 | } | |
905 | ||
906 | /* | |
907 | * flood_attack_channel | |
908 | * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC | |
909 | * says NOTICE must not auto reply | |
910 | * - pointer to source Client | |
911 | * - pointer to target channel | |
912 | * output - true if target is under flood attack | |
913 | * side effects - check for flood attack on target chptr | |
914 | */ | |
915 | bool | |
916 | flood_attack_channel(int p_or_n, struct Client *source_p, struct Channel *chptr, char *chname) | |
917 | { | |
918 | int delta; | |
919 | ||
920 | if(GlobalSetOptions.floodcount && MyClient(source_p)) | |
921 | { | |
922 | if((chptr->first_received_message_time + 1) < rb_current_time()) | |
923 | { | |
924 | delta = rb_current_time() - chptr->first_received_message_time; | |
925 | chptr->received_number_of_privmsgs -= delta; | |
926 | chptr->first_received_message_time = rb_current_time(); | |
927 | if(chptr->received_number_of_privmsgs <= 0) | |
928 | { | |
929 | chptr->received_number_of_privmsgs = 0; | |
930 | chptr->flood_noticed = 0; | |
931 | } | |
932 | } | |
933 | ||
934 | if((chptr->received_number_of_privmsgs >= GlobalSetOptions.floodcount) | |
935 | || chptr->flood_noticed) | |
936 | { | |
937 | if(chptr->flood_noticed == 0) | |
938 | { | |
939 | sendto_realops_snomask(SNO_BOTS, *chptr->chname == '&' ? L_ALL : L_NETWIDE, | |
940 | "Possible Flooder %s[%s@%s] on %s target: %s", | |
941 | source_p->name, source_p->username, | |
942 | source_p->orighost, | |
943 | source_p->servptr->name, chptr->chname); | |
944 | chptr->flood_noticed = 1; | |
945 | ||
946 | /* Add a bit of penalty */ | |
947 | chptr->received_number_of_privmsgs += 2; | |
948 | } | |
949 | if(MyClient(source_p) && (p_or_n != 1)) | |
950 | sendto_one(source_p, | |
951 | ":%s NOTICE %s :*** Message to %s throttled due to flooding", | |
952 | me.name, source_p->name, chptr->chname); | |
953 | return true; | |
954 | } | |
955 | else | |
956 | chptr->received_number_of_privmsgs++; | |
957 | } | |
958 | ||
959 | return false; | |
960 | } | |
961 | ||
962 | /* find_bannickchange_channel() | |
963 | * Input: client to check | |
964 | * Output: channel preventing nick change | |
965 | */ | |
966 | struct Channel * | |
967 | find_bannickchange_channel(struct Client *client_p) | |
968 | { | |
969 | struct Channel *chptr; | |
970 | struct membership *msptr; | |
971 | rb_dlink_node *ptr; | |
972 | char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; | |
973 | char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; | |
974 | ||
975 | if (!MyClient(client_p)) | |
976 | return NULL; | |
977 | ||
978 | sprintf(src_host, "%s!%s@%s", client_p->name, client_p->username, client_p->host); | |
979 | sprintf(src_iphost, "%s!%s@%s", client_p->name, client_p->username, client_p->sockhost); | |
980 | ||
981 | RB_DLINK_FOREACH(ptr, client_p->user->channel.head) | |
982 | { | |
983 | msptr = ptr->data; | |
984 | chptr = msptr->chptr; | |
985 | if (is_chanop_voiced(msptr)) | |
986 | continue; | |
987 | /* cached can_send */ | |
988 | if (msptr->bants == chptr->bants) | |
989 | { | |
990 | if (can_send_banned(msptr)) | |
991 | return chptr; | |
992 | } | |
993 | else if (is_banned(chptr, client_p, msptr, src_host, src_iphost, NULL) == CHFL_BAN | |
994 | || is_quieted(chptr, client_p, msptr, src_host, src_iphost) == CHFL_BAN) | |
995 | return chptr; | |
996 | } | |
997 | return NULL; | |
998 | } | |
999 | ||
1000 | /* void check_spambot_warning(struct Client *source_p) | |
1001 | * Input: Client to check, channel name or NULL if this is a part. | |
1002 | * Output: none | |
1003 | * Side-effects: Updates the client's oper_warn_count_down, warns the | |
1004 | * IRC operators if necessary, and updates join_leave_countdown as | |
1005 | * needed. | |
1006 | */ | |
1007 | void | |
1008 | check_spambot_warning(struct Client *source_p, const char *name) | |
1009 | { | |
1010 | int t_delta; | |
1011 | int decrement_count; | |
1012 | if((GlobalSetOptions.spam_num && | |
1013 | (source_p->localClient->join_leave_count >= GlobalSetOptions.spam_num))) | |
1014 | { | |
1015 | if(source_p->localClient->oper_warn_count_down > 0) | |
1016 | source_p->localClient->oper_warn_count_down--; | |
1017 | else | |
1018 | source_p->localClient->oper_warn_count_down = 0; | |
1019 | if(source_p->localClient->oper_warn_count_down == 0 && | |
1020 | name != NULL) | |
1021 | { | |
1022 | /* Its already known as a possible spambot */ | |
1023 | sendto_realops_snomask(SNO_BOTS, L_NETWIDE, | |
1024 | "User %s (%s@%s) trying to join %s is a possible spambot", | |
1025 | source_p->name, | |
1026 | source_p->username, source_p->orighost, name); | |
1027 | source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN; | |
1028 | } | |
1029 | } | |
1030 | else | |
1031 | { | |
1032 | if((t_delta = | |
1033 | (rb_current_time() - source_p->localClient->last_leave_time)) > | |
1034 | JOIN_LEAVE_COUNT_EXPIRE_TIME) | |
1035 | { | |
1036 | decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); | |
1037 | if(name != NULL) | |
1038 | ; | |
1039 | else if(decrement_count > source_p->localClient->join_leave_count) | |
1040 | source_p->localClient->join_leave_count = 0; | |
1041 | else | |
1042 | source_p->localClient->join_leave_count -= decrement_count; | |
1043 | } | |
1044 | else | |
1045 | { | |
1046 | if((rb_current_time() - | |
1047 | (source_p->localClient->last_join_time)) < GlobalSetOptions.spam_time) | |
1048 | { | |
1049 | /* oh, its a possible spambot */ | |
1050 | source_p->localClient->join_leave_count++; | |
1051 | } | |
1052 | } | |
1053 | if(name != NULL) | |
1054 | source_p->localClient->last_join_time = rb_current_time(); | |
1055 | else | |
1056 | source_p->localClient->last_leave_time = rb_current_time(); | |
1057 | } | |
1058 | } | |
1059 | ||
1060 | /* check_splitmode() | |
1061 | * | |
1062 | * input - | |
1063 | * output - | |
1064 | * side effects - compares usercount and servercount against their split | |
1065 | * values and adjusts splitmode accordingly | |
1066 | */ | |
1067 | void | |
1068 | check_splitmode(void *unused) | |
1069 | { | |
1070 | if(splitchecking && (ConfigChannel.no_join_on_split || ConfigChannel.no_create_on_split)) | |
1071 | { | |
1072 | /* not split, we're being asked to check now because someone | |
1073 | * has left | |
1074 | */ | |
1075 | if(!splitmode) | |
1076 | { | |
1077 | if(eob_count < split_servers || Count.total < split_users) | |
1078 | { | |
1079 | splitmode = 1; | |
1080 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1081 | "Network split, activating splitmode"); | |
1082 | check_splitmode_ev = rb_event_addish("check_splitmode", check_splitmode, NULL, 2); | |
1083 | } | |
1084 | } | |
1085 | /* in splitmode, check whether its finished */ | |
1086 | else if(eob_count >= split_servers && Count.total >= split_users) | |
1087 | { | |
1088 | splitmode = 0; | |
1089 | ||
1090 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1091 | "Network rejoined, deactivating splitmode"); | |
1092 | ||
1093 | rb_event_delete(check_splitmode_ev); | |
1094 | check_splitmode_ev = NULL; | |
1095 | } | |
1096 | } | |
1097 | } | |
1098 | ||
1099 | ||
1100 | /* allocate_topic() | |
1101 | * | |
1102 | * input - channel to allocate topic for | |
1103 | * output - 1 on success, else 0 | |
1104 | * side effects - channel gets a topic allocated | |
1105 | */ | |
1106 | static void | |
1107 | allocate_topic(struct Channel *chptr) | |
1108 | { | |
1109 | void *ptr; | |
1110 | ||
1111 | if(chptr == NULL) | |
1112 | return; | |
1113 | ||
1114 | ptr = rb_bh_alloc(topic_heap); | |
1115 | ||
1116 | /* Basically we allocate one large block for the topic and | |
1117 | * the topic info. We then split it up into two and shove it | |
1118 | * in the chptr | |
1119 | */ | |
1120 | chptr->topic = ptr; | |
1121 | chptr->topic_info = (char *) ptr + TOPICLEN + 1; | |
1122 | *chptr->topic = '\0'; | |
1123 | *chptr->topic_info = '\0'; | |
1124 | } | |
1125 | ||
1126 | /* free_topic() | |
1127 | * | |
1128 | * input - channel which has topic to free | |
1129 | * output - | |
1130 | * side effects - channels topic is free'd | |
1131 | */ | |
1132 | static void | |
1133 | free_topic(struct Channel *chptr) | |
1134 | { | |
1135 | void *ptr; | |
1136 | ||
1137 | if(chptr == NULL || chptr->topic == NULL) | |
1138 | return; | |
1139 | ||
1140 | /* This is safe for now - If you change allocate_topic you | |
1141 | * MUST change this as well | |
1142 | */ | |
1143 | ptr = chptr->topic; | |
1144 | rb_bh_free(topic_heap, ptr); | |
1145 | chptr->topic = NULL; | |
1146 | chptr->topic_info = NULL; | |
1147 | } | |
1148 | ||
1149 | /* set_channel_topic() | |
1150 | * | |
1151 | * input - channel, topic to set, topic info and topic ts | |
1152 | * output - | |
1153 | * side effects - channels topic, topic info and TS are set. | |
1154 | */ | |
1155 | void | |
1156 | set_channel_topic(struct Channel *chptr, const char *topic, const char *topic_info, time_t topicts) | |
1157 | { | |
1158 | if(strlen(topic) > 0) | |
1159 | { | |
1160 | if(chptr->topic == NULL) | |
1161 | allocate_topic(chptr); | |
1162 | rb_strlcpy(chptr->topic, topic, TOPICLEN + 1); | |
1163 | rb_strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN); | |
1164 | chptr->topic_time = topicts; | |
1165 | } | |
1166 | else | |
1167 | { | |
1168 | if(chptr->topic != NULL) | |
1169 | free_topic(chptr); | |
1170 | chptr->topic_time = 0; | |
1171 | } | |
1172 | } | |
1173 | ||
1174 | /* channel_modes() | |
1175 | * | |
1176 | * inputs - pointer to channel | |
1177 | * - pointer to client | |
1178 | * output - string with simple modes | |
1179 | * side effects - result from previous calls overwritten | |
1180 | * | |
1181 | * Stolen from ShadowIRCd 4 --nenolod | |
1182 | */ | |
1183 | const char * | |
1184 | channel_modes(struct Channel *chptr, struct Client *client_p) | |
1185 | { | |
1186 | int i; | |
1187 | char buf1[BUFSIZE]; | |
1188 | char buf2[BUFSIZE]; | |
1189 | static char final[BUFSIZE]; | |
1190 | char *mbuf = buf1; | |
1191 | char *pbuf = buf2; | |
1192 | ||
1193 | *mbuf++ = '+'; | |
1194 | *pbuf = '\0'; | |
1195 | ||
1196 | for (i = 0; i < 256; i++) | |
1197 | { | |
1198 | if(chmode_table[i].set_func == chm_hidden && (!IsOper(client_p) || !IsClient(client_p))) | |
1199 | continue; | |
1200 | if(chptr->mode.mode & chmode_flags[i]) | |
1201 | *mbuf++ = i; | |
1202 | } | |
1203 | ||
1204 | if(chptr->mode.limit) | |
1205 | { | |
1206 | *mbuf++ = 'l'; | |
1207 | ||
1208 | if(!IsClient(client_p) || IsMember(client_p, chptr)) | |
1209 | pbuf += sprintf(pbuf, " %d", chptr->mode.limit); | |
1210 | } | |
1211 | ||
1212 | if(*chptr->mode.key) | |
1213 | { | |
1214 | *mbuf++ = 'k'; | |
1215 | ||
1216 | if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) | |
1217 | pbuf += sprintf(pbuf, " %s", chptr->mode.key); | |
1218 | } | |
1219 | ||
1220 | if(chptr->mode.join_num) | |
1221 | { | |
1222 | *mbuf++ = 'j'; | |
1223 | ||
1224 | if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) | |
1225 | pbuf += sprintf(pbuf, " %d:%d", chptr->mode.join_num, | |
1226 | chptr->mode.join_time); | |
1227 | } | |
1228 | ||
1229 | if(*chptr->mode.forward && | |
1230 | (ConfigChannel.use_forward || !IsClient(client_p))) | |
1231 | { | |
1232 | *mbuf++ = 'f'; | |
1233 | ||
1234 | if(pbuf > buf2 || !IsClient(client_p) || IsMember(client_p, chptr)) | |
1235 | pbuf += sprintf(pbuf, " %s", chptr->mode.forward); | |
1236 | } | |
1237 | ||
1238 | *mbuf = '\0'; | |
1239 | ||
1240 | rb_strlcpy(final, buf1, sizeof final); | |
1241 | rb_strlcat(final, buf2, sizeof final); | |
1242 | return final; | |
1243 | } | |
1244 | ||
1245 | /* void send_cap_mode_changes(struct Client *client_p, | |
1246 | * struct Client *source_p, | |
1247 | * struct Channel *chptr, int cap, int nocap) | |
1248 | * Input: The client sending(client_p), the source client(source_p), | |
1249 | * the channel to send mode changes for(chptr) | |
1250 | * Output: None. | |
1251 | * Side-effects: Sends the appropriate mode changes to capable servers. | |
1252 | * | |
1253 | * Reverted back to my original design, except that we now keep a count | |
1254 | * of the number of servers which each combination as an optimisation, so | |
1255 | * the capabs combinations which are not needed are not worked out. -A1kmm | |
1256 | * | |
1257 | * Removed most code here because we don't need to be compatible with ircd | |
1258 | * 2.8.21+CSr and stuff. --nenolod | |
1259 | */ | |
1260 | void | |
1261 | send_cap_mode_changes(struct Client *client_p, struct Client *source_p, | |
1262 | struct Channel *chptr, struct ChModeChange mode_changes[], int mode_count) | |
1263 | { | |
1264 | static char modebuf[BUFSIZE]; | |
1265 | static char parabuf[BUFSIZE]; | |
1266 | int i, mbl, pbl, nc, mc, preflen, len; | |
1267 | char *pbuf; | |
1268 | const char *arg; | |
1269 | int dir; | |
1270 | int arglen = 0; | |
1271 | ||
1272 | /* Now send to servers... */ | |
1273 | mc = 0; | |
1274 | nc = 0; | |
1275 | pbl = 0; | |
1276 | parabuf[0] = 0; | |
1277 | pbuf = parabuf; | |
1278 | dir = MODE_QUERY; | |
1279 | ||
1280 | mbl = preflen = sprintf(modebuf, ":%s TMODE %ld %s ", | |
1281 | use_id(source_p), (long) chptr->channelts, | |
1282 | chptr->chname); | |
1283 | ||
1284 | /* loop the list of - modes we have */ | |
1285 | for (i = 0; i < mode_count; i++) | |
1286 | { | |
1287 | /* if they dont support the cap we need, or they do support a cap they | |
1288 | * cant have, then dont add it to the modebuf.. that way they wont see | |
1289 | * the mode | |
1290 | */ | |
1291 | if (mode_changes[i].letter == 0) | |
1292 | continue; | |
1293 | ||
1294 | if (!EmptyString(mode_changes[i].id)) | |
1295 | arg = mode_changes[i].id; | |
1296 | else | |
1297 | arg = mode_changes[i].arg; | |
1298 | ||
1299 | if(arg) | |
1300 | { | |
1301 | arglen = strlen(arg); | |
1302 | ||
1303 | /* dont even think about it! --fl */ | |
1304 | if(arglen > MODEBUFLEN - 5) | |
1305 | continue; | |
1306 | } | |
1307 | ||
1308 | /* if we're creeping past the buf size, we need to send it and make | |
1309 | * another line for the other modes | |
1310 | * XXX - this could give away server topology with uids being | |
1311 | * different lengths, but not much we can do, except possibly break | |
1312 | * them as if they were the longest of the nick or uid at all times, | |
1313 | * which even then won't work as we don't always know the uid -A1kmm. | |
1314 | */ | |
1315 | if(arg && ((mc == MAXMODEPARAMSSERV) || | |
1316 | ((mbl + pbl + arglen + 4) > (BUFSIZE - 3)))) | |
1317 | { | |
1318 | if(nc != 0) | |
1319 | sendto_server(client_p, chptr, NOCAPS, NOCAPS, | |
1320 | "%s %s", modebuf, parabuf); | |
1321 | nc = 0; | |
1322 | mc = 0; | |
1323 | ||
1324 | mbl = preflen; | |
1325 | pbl = 0; | |
1326 | pbuf = parabuf; | |
1327 | parabuf[0] = 0; | |
1328 | dir = MODE_QUERY; | |
1329 | } | |
1330 | ||
1331 | if(dir != mode_changes[i].dir) | |
1332 | { | |
1333 | modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; | |
1334 | dir = mode_changes[i].dir; | |
1335 | } | |
1336 | ||
1337 | modebuf[mbl++] = mode_changes[i].letter; | |
1338 | modebuf[mbl] = 0; | |
1339 | nc++; | |
1340 | ||
1341 | if(arg != NULL) | |
1342 | { | |
1343 | len = sprintf(pbuf, "%s ", arg); | |
1344 | pbuf += len; | |
1345 | pbl += len; | |
1346 | mc++; | |
1347 | } | |
1348 | } | |
1349 | ||
1350 | if(pbl && parabuf[pbl - 1] == ' ') | |
1351 | parabuf[pbl - 1] = 0; | |
1352 | ||
1353 | if(nc != 0) | |
1354 | sendto_server(client_p, chptr, NOCAPS, NOCAPS, "%s %s", modebuf, parabuf); | |
1355 | } | |
1356 | ||
1357 | void | |
1358 | resv_chan_forcepart(const char *name, const char *reason, int temp_time) | |
1359 | { | |
1360 | rb_dlink_node *ptr; | |
1361 | rb_dlink_node *next_ptr; | |
1362 | struct Channel *chptr; | |
1363 | struct membership *msptr; | |
1364 | struct Client *target_p; | |
1365 | ||
1366 | if(!ConfigChannel.resv_forcepart) | |
1367 | return; | |
1368 | ||
1369 | /* for each user on our server in the channel list | |
1370 | * send them a PART, and notify opers. | |
1371 | */ | |
1372 | chptr = find_channel(name); | |
1373 | if(chptr != NULL) | |
1374 | { | |
1375 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) | |
1376 | { | |
1377 | msptr = ptr->data; | |
1378 | target_p = msptr->client_p; | |
1379 | ||
1380 | if(IsExemptResv(target_p)) | |
1381 | continue; | |
1382 | ||
1383 | sendto_server(target_p, chptr, CAP_TS6, NOCAPS, | |
1384 | ":%s PART %s", target_p->id, chptr->chname); | |
1385 | ||
1386 | sendto_channel_local(target_p, ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s", | |
1387 | target_p->name, target_p->username, | |
1388 | target_p->host, chptr->chname, target_p->name); | |
1389 | ||
1390 | remove_user_from_channel(msptr); | |
1391 | ||
1392 | /* notify opers & user they were removed from the channel */ | |
1393 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1394 | "Forced PART for %s!%s@%s from %s (%s)", | |
1395 | target_p->name, target_p->username, | |
1396 | target_p->host, name, reason); | |
1397 | ||
1398 | if(temp_time > 0) | |
1399 | sendto_one_notice(target_p, ":*** Channel %s is temporarily unavailable on this server.", | |
1400 | name); | |
1401 | else | |
1402 | sendto_one_notice(target_p, ":*** Channel %s is no longer available on this server.", | |
1403 | name); | |
1404 | } | |
1405 | } | |
1406 | } |