1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
4 |
> |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
30 |
|
#include "channel_mode.h" |
31 |
|
#include "client.h" |
32 |
|
#include "hash.h" |
33 |
+ |
#include "conf.h" |
34 |
|
#include "hostmask.h" |
35 |
|
#include "irc_string.h" |
35 |
– |
#include "sprintf_irc.h" |
36 |
|
#include "ircd.h" |
37 |
|
#include "numeric.h" |
38 |
< |
#include "s_serv.h" /* captab */ |
39 |
< |
#include "s_user.h" |
38 |
> |
#include "s_serv.h" |
39 |
|
#include "send.h" |
41 |
– |
#include "s_conf.h" /* ConfigFileEntry, ConfigChannel */ |
40 |
|
#include "event.h" |
41 |
|
#include "memory.h" |
42 |
< |
#include "balloc.h" |
42 |
> |
#include "mempool.h" |
43 |
> |
#include "s_misc.h" |
44 |
> |
#include "resv.h" |
45 |
|
|
46 |
– |
struct config_channel_entry ConfigChannel; |
46 |
|
dlink_list global_channel_list = { NULL, NULL, 0 }; |
47 |
< |
BlockHeap *ban_heap; /*! \todo ban_heap shouldn't be a global var */ |
47 |
> |
mp_pool_t *ban_pool; /*! \todo ban_pool shouldn't be a global var */ |
48 |
|
|
49 |
< |
static BlockHeap *member_heap = NULL; |
50 |
< |
static BlockHeap *channel_heap = NULL; |
49 |
> |
static mp_pool_t *member_pool = NULL; |
50 |
> |
static mp_pool_t *channel_pool = NULL; |
51 |
|
|
52 |
|
static char buf[IRCD_BUFSIZE]; |
54 |
– |
static char modebuf[MODEBUFLEN]; |
55 |
– |
static char parabuf[MODEBUFLEN]; |
53 |
|
|
54 |
|
|
55 |
|
/*! \brief Initializes the channel blockheap, adds known channel CAPAB |
56 |
|
*/ |
57 |
|
void |
58 |
< |
init_channels(void) |
58 |
> |
channel_init(void) |
59 |
|
{ |
60 |
|
add_capability("EX", CAP_EX, 1); |
61 |
|
add_capability("IE", CAP_IE, 1); |
65 |
– |
add_capability("CHW", CAP_CHW, 1); |
62 |
|
|
63 |
< |
channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE); |
64 |
< |
ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE); |
65 |
< |
member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2); |
63 |
> |
channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL); |
64 |
> |
ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN); |
65 |
> |
member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER); |
66 |
|
} |
67 |
|
|
68 |
|
/*! \brief adds a user to a channel by adding another link to the |
99 |
|
if (!IsSetJoinFloodNoticed(chptr)) |
100 |
|
{ |
101 |
|
SetJoinFloodNoticed(chptr); |
102 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
102 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
103 |
|
"Possible Join Flooder %s on %s target: %s", |
104 |
|
get_client_name(who, HIDE_IP), |
105 |
|
who->servptr->name, chptr->chname); |
109 |
|
chptr->last_join_time = CurrentTime; |
110 |
|
} |
111 |
|
|
112 |
< |
ms = BlockHeapAlloc(member_heap); |
112 |
> |
ms = mp_pool_get(member_pool); |
113 |
> |
memset(ms, 0, sizeof(*ms)); |
114 |
> |
|
115 |
|
ms->client_p = who; |
116 |
|
ms->chptr = chptr; |
117 |
|
ms->flags = flags; |
133 |
|
dlinkDelete(&member->channode, &chptr->members); |
134 |
|
dlinkDelete(&member->usernode, &client_p->channel); |
135 |
|
|
136 |
< |
BlockHeapFree(member_heap, member); |
136 |
> |
mp_pool_release(member); |
137 |
|
|
138 |
|
if (chptr->members.head == NULL) |
139 |
|
destroy_channel(chptr); |
147 |
|
*/ |
148 |
|
static void |
149 |
|
send_members(struct Client *client_p, struct Channel *chptr, |
150 |
< |
char *lmodebuf, char *lparabuf) |
150 |
> |
char *modebuf, char *parabuf) |
151 |
|
{ |
152 |
< |
struct Membership *ms; |
155 |
< |
dlink_node *ptr; |
152 |
> |
const dlink_node *ptr = NULL; |
153 |
|
int tlen; /* length of text to append */ |
154 |
|
char *t, *start; /* temp char pointer */ |
155 |
|
|
156 |
< |
start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:", |
157 |
< |
ID_or_name(&me, client_p), |
158 |
< |
(unsigned long)chptr->channelts, |
162 |
< |
chptr->chname, lmodebuf, lparabuf); |
156 |
> |
start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:", |
157 |
> |
me.id, (unsigned long)chptr->channelts, |
158 |
> |
chptr->chname, modebuf, parabuf); |
159 |
|
|
160 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
161 |
|
{ |
162 |
< |
ms = ptr->data; |
162 |
> |
const struct Membership *ms = ptr->data; |
163 |
|
|
164 |
< |
tlen = strlen(IsCapable(client_p, CAP_TS6) ? |
169 |
< |
ID(ms->client_p) : ms->client_p->name) + 1; /* nick + space */ |
164 |
> |
tlen = strlen(ms->client_p->id) + 1; /* nick + space */ |
165 |
|
|
166 |
|
if (ms->flags & CHFL_CHANOP) |
167 |
|
tlen++; |
168 |
|
#ifdef HALFOPS |
169 |
< |
else if (ms->flags & CHFL_HALFOP) |
169 |
> |
if (ms->flags & CHFL_HALFOP) |
170 |
|
tlen++; |
171 |
|
#endif |
172 |
|
if (ms->flags & CHFL_VOICE) |
175 |
|
/* space will be converted into CR, but we also need space for LF.. |
176 |
|
* That's why we use '- 1' here |
177 |
|
* -adx */ |
178 |
< |
if (t + tlen - buf > sizeof(buf) - 1) |
178 |
> |
if (t + tlen - buf > IRCD_BUFSIZE - 1) |
179 |
|
{ |
180 |
|
*(t - 1) = '\0'; /* kill the space and terminate the string */ |
181 |
|
sendto_one(client_p, "%s", buf); |
182 |
|
t = start; |
183 |
|
} |
184 |
|
|
185 |
< |
if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP))) |
186 |
< |
*t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ? |
187 |
< |
'%' : '@'; |
188 |
< |
if ((ms->flags & CHFL_VOICE)) |
185 |
> |
if (ms->flags & CHFL_CHANOP) |
186 |
> |
*t++ = '@'; |
187 |
> |
if (ms->flags & CHFL_HALFOP) |
188 |
> |
*t++ = '%'; |
189 |
> |
if (ms->flags & CHFL_VOICE) |
190 |
|
*t++ = '+'; |
191 |
|
|
192 |
< |
if (IsCapable(client_p, CAP_TS6)) |
193 |
< |
strcpy(t, ID(ms->client_p)); |
198 |
< |
else |
199 |
< |
strcpy(t, ms->client_p->name); |
192 |
> |
strcpy(t, ms->client_p->id); |
193 |
> |
|
194 |
|
t += strlen(t); |
195 |
|
*t++ = ' '; |
196 |
|
} |
210 |
|
*/ |
211 |
|
static void |
212 |
|
send_mode_list(struct Client *client_p, struct Channel *chptr, |
213 |
< |
dlink_list *top, char flag) |
213 |
> |
const dlink_list *top, char flag) |
214 |
|
{ |
215 |
< |
int ts5 = !IsCapable(client_p, CAP_TS6); |
216 |
< |
dlink_node *lp; |
223 |
< |
struct Ban *banptr; |
224 |
< |
char pbuf[IRCD_BUFSIZE]; |
215 |
> |
const dlink_node *lp = NULL; |
216 |
> |
char pbuf[IRCD_BUFSIZE] = ""; |
217 |
|
int tlen, mlen, cur_len, count = 0; |
218 |
< |
char *mp = NULL, *pp = pbuf; |
218 |
> |
char *pp = pbuf; |
219 |
|
|
220 |
< |
if (top == NULL || top->length == 0) |
220 |
> |
if (top->length == 0) |
221 |
|
return; |
222 |
|
|
223 |
< |
if (ts5) |
224 |
< |
mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname); |
225 |
< |
else |
234 |
< |
mlen = ircsprintf(buf, ":%s BMASK %lu %s %c :", me.id, |
235 |
< |
(unsigned long)chptr->channelts, chptr->chname, flag); |
236 |
< |
|
237 |
< |
/* MODE needs additional one byte for space between buf and pbuf */ |
238 |
< |
cur_len = mlen + ts5; |
239 |
< |
mp = buf + mlen; |
223 |
> |
mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id, |
224 |
> |
(unsigned long)chptr->channelts, chptr->chname, flag); |
225 |
> |
cur_len = mlen; |
226 |
|
|
227 |
|
DLINK_FOREACH(lp, top->head) |
228 |
|
{ |
229 |
< |
banptr = lp->data; |
229 |
> |
const struct Ban *banptr = lp->data; |
230 |
|
|
231 |
< |
/* must add another b/e/I letter if we use MODE */ |
246 |
< |
tlen = banptr->len + 3 + ts5; |
231 |
> |
tlen = banptr->len + 3; |
232 |
|
|
233 |
|
/* |
234 |
|
* send buffer and start over if we cannot fit another ban, |
235 |
|
* or if the target is non-ts6 and we have too many modes in |
236 |
|
* in this line. |
237 |
|
*/ |
238 |
< |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 || |
254 |
< |
(!IsCapable(client_p, CAP_TS6) && |
255 |
< |
(count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN))) |
238 |
> |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2) |
239 |
|
{ |
240 |
|
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
241 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
241 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
242 |
|
|
243 |
< |
cur_len = mlen + ts5; |
261 |
< |
mp = buf + mlen; |
243 |
> |
cur_len = mlen; |
244 |
|
pp = pbuf; |
245 |
|
count = 0; |
246 |
|
} |
247 |
|
|
248 |
|
count++; |
249 |
< |
if (ts5) |
250 |
< |
{ |
269 |
< |
*mp++ = flag; |
270 |
< |
*mp = '\0'; |
271 |
< |
} |
272 |
< |
|
273 |
< |
pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username, |
274 |
< |
banptr->host); |
249 |
> |
pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user, |
250 |
> |
banptr->host); |
251 |
|
cur_len += tlen; |
252 |
|
} |
253 |
|
|
254 |
|
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
255 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
255 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
256 |
|
} |
257 |
|
|
258 |
|
/*! \brief send "client_p" a full list of the modes for channel chptr |
262 |
|
void |
263 |
|
send_channel_modes(struct Client *client_p, struct Channel *chptr) |
264 |
|
{ |
265 |
< |
if (chptr->chname[0] != '#') |
266 |
< |
return; |
265 |
> |
char modebuf[MODEBUFLEN] = ""; |
266 |
> |
char parabuf[MODEBUFLEN] = ""; |
267 |
|
|
292 |
– |
*modebuf = *parabuf = '\0'; |
268 |
|
channel_modes(chptr, client_p, modebuf, parabuf); |
269 |
|
send_members(client_p, chptr, modebuf, parabuf); |
270 |
|
|
271 |
|
send_mode_list(client_p, chptr, &chptr->banlist, 'b'); |
272 |
< |
|
273 |
< |
if (IsCapable(client_p, CAP_EX)) |
299 |
< |
send_mode_list(client_p, chptr, &chptr->exceptlist, 'e'); |
300 |
< |
if (IsCapable(client_p, CAP_IE)) |
301 |
< |
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
272 |
> |
send_mode_list(client_p, chptr, &chptr->exceptlist, 'e'); |
273 |
> |
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
274 |
|
} |
275 |
|
|
276 |
|
/*! \brief check channel name for invalid characters |
279 |
|
* \return 0 if invalid, 1 otherwise |
280 |
|
*/ |
281 |
|
int |
282 |
< |
check_channel_name(const char *name, int local) |
282 |
> |
check_channel_name(const char *name, const int local) |
283 |
|
{ |
284 |
|
const char *p = name; |
285 |
< |
int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN; |
285 |
> |
const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN; |
286 |
|
assert(name != NULL); |
287 |
|
|
288 |
|
if (!IsChanPrefix(*p)) |
310 |
|
dlinkDelete(&bptr->node, list); |
311 |
|
|
312 |
|
MyFree(bptr->name); |
313 |
< |
MyFree(bptr->username); |
313 |
> |
MyFree(bptr->user); |
314 |
|
MyFree(bptr->host); |
315 |
|
MyFree(bptr->who); |
316 |
|
|
317 |
< |
BlockHeapFree(ban_heap, bptr); |
317 |
> |
mp_pool_release(bptr); |
318 |
|
} |
319 |
|
|
320 |
|
/* free_channel_list() |
346 |
|
|
347 |
|
assert(!EmptyString(chname)); |
348 |
|
|
349 |
< |
chptr = BlockHeapAlloc(channel_heap); |
349 |
> |
chptr = mp_pool_get(channel_pool); |
350 |
> |
|
351 |
> |
memset(chptr, 0, sizeof(*chptr)); |
352 |
|
|
353 |
|
/* doesn't hurt to set it here */ |
354 |
|
chptr->channelts = CurrentTime; |
381 |
|
dlinkDelete(&chptr->node, &global_channel_list); |
382 |
|
hash_del_channel(chptr); |
383 |
|
|
384 |
< |
BlockHeapFree(channel_heap, chptr); |
384 |
> |
mp_pool_release(chptr); |
385 |
|
} |
386 |
|
|
387 |
|
/*! |
408 |
|
channel_member_names(struct Client *source_p, struct Channel *chptr, |
409 |
|
int show_eon) |
410 |
|
{ |
411 |
< |
struct Client *target_p = NULL; |
412 |
< |
struct Membership *ms = NULL; |
439 |
< |
dlink_node *ptr = NULL; |
440 |
< |
char lbuf[IRCD_BUFSIZE + 1]; |
411 |
> |
const dlink_node *ptr = NULL; |
412 |
> |
char lbuf[IRCD_BUFSIZE + 1] = ""; |
413 |
|
char *t = NULL, *start = NULL; |
414 |
|
int tlen = 0; |
415 |
|
int is_member = IsMember(source_p, chptr); |
416 |
|
int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0; |
417 |
+ |
int uhnames = HasCap(source_p, CAP_UHNAMES) != 0; |
418 |
|
|
419 |
|
if (PubChannel(chptr) || is_member) |
420 |
|
{ |
421 |
< |
t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY), |
422 |
< |
me.name, source_p->name, |
423 |
< |
channel_pub_or_secret(chptr), |
451 |
< |
chptr->chname); |
421 |
> |
t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY), |
422 |
> |
me.name, source_p->name, |
423 |
> |
channel_pub_or_secret(chptr), chptr->chname); |
424 |
|
start = t; |
425 |
|
|
426 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
427 |
|
{ |
428 |
< |
ms = ptr->data; |
457 |
< |
target_p = ms->client_p; |
428 |
> |
const struct Membership *ms = ptr->data; |
429 |
|
|
430 |
< |
if (HasUMode(target_p, UMODE_INVISIBLE) && !is_member) |
430 |
> |
if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member) |
431 |
|
continue; |
432 |
|
|
433 |
< |
tlen = strlen(target_p->name) + 1; /* nick + space */ |
433 |
> |
if (!uhnames) |
434 |
> |
tlen = strlen(ms->client_p->name) + 1; /* nick + space */ |
435 |
> |
else |
436 |
> |
tlen = strlen(ms->client_p->name) + strlen(ms->client_p->username) + |
437 |
> |
strlen(ms->client_p->host) + 3; |
438 |
|
|
439 |
|
if (!multi_prefix) |
440 |
|
{ |
458 |
|
t = start; |
459 |
|
} |
460 |
|
|
461 |
< |
t += ircsprintf(t, "%s%s ", get_member_status(ms, multi_prefix), |
462 |
< |
target_p->name); |
461 |
> |
if (!uhnames) |
462 |
> |
t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix), |
463 |
> |
ms->client_p->name); |
464 |
> |
else |
465 |
> |
t += sprintf(t, "%s%s!%s@%s ", get_member_status(ms, multi_prefix), |
466 |
> |
ms->client_p->name, ms->client_p->username, |
467 |
> |
ms->client_p->host); |
468 |
|
} |
469 |
|
|
470 |
< |
if (tlen != 0) |
470 |
> |
if (tlen) |
471 |
|
{ |
472 |
|
*(t - 1) = '\0'; |
473 |
|
sendto_one(source_p, "%s", lbuf); |
475 |
|
} |
476 |
|
|
477 |
|
if (show_eon) |
478 |
< |
sendto_one(source_p, form_str(RPL_ENDOFNAMES), |
499 |
< |
me.name, source_p->name, chptr->chname); |
478 |
> |
sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname); |
479 |
|
} |
480 |
|
|
481 |
|
/*! \brief adds client to invite list |
530 |
|
* (like in get_client_name) |
531 |
|
*/ |
532 |
|
const char * |
533 |
< |
get_member_status(const struct Membership *ms, int combine) |
533 |
> |
get_member_status(const struct Membership *ms, const int combine) |
534 |
|
{ |
535 |
|
static char buffer[4]; |
536 |
< |
char *p = NULL; |
558 |
< |
|
559 |
< |
if (ms == NULL) |
560 |
< |
return ""; |
561 |
< |
p = buffer; |
536 |
> |
char *p = buffer; |
537 |
|
|
538 |
|
if (ms->flags & CHFL_CHANOP) |
539 |
|
{ |
571 |
|
|
572 |
|
DLINK_FOREACH(ptr, list->head) |
573 |
|
{ |
574 |
< |
struct Ban *bp = ptr->data; |
574 |
> |
const struct Ban *bp = ptr->data; |
575 |
|
|
576 |
< |
if (match(bp->name, who->name) && match(bp->username, who->username)) |
576 |
> |
if (!match(bp->name, who->name) && !match(bp->user, who->username)) |
577 |
|
{ |
578 |
|
switch (bp->type) |
579 |
|
{ |
580 |
|
case HM_HOST: |
581 |
< |
if (match(bp->host, who->host) || match(bp->host, who->sockhost)) |
581 |
> |
if (!match(bp->host, who->host) || !match(bp->host, who->sockhost)) |
582 |
|
return 1; |
583 |
|
break; |
584 |
|
case HM_IPV4: |
611 |
|
is_banned(const struct Channel *chptr, const struct Client *who) |
612 |
|
{ |
613 |
|
if (find_bmask(who, &chptr->banlist)) |
614 |
< |
if (!ConfigChannel.use_except || !find_bmask(who, &chptr->exceptlist)) |
614 |
> |
if (!find_bmask(who, &chptr->exceptlist)) |
615 |
|
return 1; |
616 |
|
|
617 |
|
return 0; |
619 |
|
|
620 |
|
/*! |
621 |
|
* \param source_p pointer to client attempting to join |
622 |
< |
* \param chptr pointer to channel |
622 |
> |
* \param chptr pointer to channel |
623 |
|
* \param key key sent by client attempting to join if present |
624 |
|
* \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL |
625 |
|
* or 0 if allowed to join. |
627 |
|
int |
628 |
|
can_join(struct Client *source_p, struct Channel *chptr, const char *key) |
629 |
|
{ |
630 |
< |
if (is_banned(chptr, source_p)) |
656 |
< |
return ERR_BANNEDFROMCHAN; |
657 |
< |
|
658 |
< |
#ifdef HAVE_LIBCRYPTO |
659 |
< |
if ((chptr->mode.mode & MODE_SSLONLY) && !source_p->localClient->fd.ssl) |
630 |
> |
if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL)) |
631 |
|
return ERR_SSLONLYCHAN; |
661 |
– |
#endif |
632 |
|
|
633 |
|
if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED)) |
634 |
|
return ERR_NEEDREGGEDNICK; |
638 |
|
|
639 |
|
if (chptr->mode.mode & MODE_INVITEONLY) |
640 |
|
if (!dlinkFind(&source_p->localClient->invited, chptr)) |
641 |
< |
if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist)) |
641 |
> |
if (!find_bmask(source_p, &chptr->invexlist)) |
642 |
|
return ERR_INVITEONLYCHAN; |
643 |
|
|
644 |
< |
if (chptr->mode.key[0] && (!key || irccmp(chptr->mode.key, key))) |
644 |
> |
if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key))) |
645 |
|
return ERR_BADCHANNELKEY; |
646 |
|
|
647 |
|
if (chptr->mode.limit && dlink_list_length(&chptr->members) >= |
648 |
|
chptr->mode.limit) |
649 |
|
return ERR_CHANNELISFULL; |
650 |
|
|
651 |
+ |
if (is_banned(chptr, source_p)) |
652 |
+ |
return ERR_BANNEDFROMCHAN; |
653 |
+ |
|
654 |
|
return 0; |
655 |
|
} |
656 |
|
|
657 |
|
int |
658 |
< |
has_member_flags(struct Membership *ms, unsigned int flags) |
658 |
> |
has_member_flags(const struct Membership *ms, const unsigned int flags) |
659 |
|
{ |
660 |
< |
if (ms != NULL) |
688 |
< |
return ms->flags & flags; |
689 |
< |
return 0; |
660 |
> |
return ms && (ms->flags & flags); |
661 |
|
} |
662 |
|
|
663 |
|
struct Membership * |
668 |
|
if (!IsClient(client_p)) |
669 |
|
return NULL; |
670 |
|
|
671 |
< |
DLINK_FOREACH(ptr, client_p->channel.head) |
672 |
< |
if (((struct Membership *)ptr->data)->chptr == chptr) |
673 |
< |
return ptr->data; |
671 |
> |
if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel)) |
672 |
> |
{ |
673 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
674 |
> |
if (((struct Membership *)ptr->data)->client_p == client_p) |
675 |
> |
return ptr->data; |
676 |
> |
} |
677 |
> |
else |
678 |
> |
{ |
679 |
> |
DLINK_FOREACH(ptr, client_p->channel.head) |
680 |
> |
if (((struct Membership *)ptr->data)->chptr == chptr) |
681 |
> |
return ptr->data; |
682 |
> |
} |
683 |
|
|
684 |
|
return NULL; |
685 |
|
} |
686 |
|
|
687 |
+ |
/* |
688 |
+ |
* Basically the same functionality as in bahamut |
689 |
+ |
*/ |
690 |
+ |
static int |
691 |
+ |
msg_has_ctrls(const char *message) |
692 |
+ |
{ |
693 |
+ |
const unsigned char *p = (const unsigned char *)message; |
694 |
+ |
|
695 |
+ |
for (; *p; ++p) |
696 |
+ |
{ |
697 |
+ |
if (*p > 31 || *p == 1) |
698 |
+ |
continue; |
699 |
+ |
|
700 |
+ |
if (*p == 27) |
701 |
+ |
{ |
702 |
+ |
if (*(p + 1) == '$' || |
703 |
+ |
*(p + 1) == '(') |
704 |
+ |
{ |
705 |
+ |
++p; |
706 |
+ |
continue; |
707 |
+ |
} |
708 |
+ |
} |
709 |
+ |
|
710 |
+ |
return 1; |
711 |
+ |
} |
712 |
+ |
|
713 |
+ |
return 0; |
714 |
+ |
} |
715 |
+ |
|
716 |
|
/*! |
717 |
|
* \param chptr pointer to Channel struct |
718 |
|
* \param source_p pointer to Client struct |
722 |
|
* ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n |
723 |
|
*/ |
724 |
|
int |
725 |
< |
can_send(struct Channel *chptr, struct Client *source_p, struct Membership *ms) |
725 |
> |
can_send(struct Channel *chptr, struct Client *source_p, |
726 |
> |
struct Membership *ms, const char *message) |
727 |
|
{ |
728 |
+ |
struct MaskItem *conf = NULL; |
729 |
+ |
|
730 |
|
if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE)) |
731 |
|
return CAN_SEND_OPV; |
732 |
|
|
733 |
|
if (MyClient(source_p) && !IsExemptResv(source_p)) |
734 |
|
if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv)) |
735 |
< |
if (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels) |
735 |
> |
if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf)) |
736 |
|
return ERR_CANNOTSENDTOCHAN; |
737 |
|
|
738 |
< |
if (ms != NULL || (ms = find_channel_link(source_p, chptr))) |
739 |
< |
{ |
738 |
> |
if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message)) |
739 |
> |
return ERR_NOCTRLSONCHAN; |
740 |
> |
if (ms || (ms = find_channel_link(source_p, chptr))) |
741 |
|
if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE)) |
742 |
|
return CAN_SEND_OPV; |
743 |
+ |
if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS)) |
744 |
+ |
return ERR_CANNOTSENDTOCHAN; |
745 |
+ |
if (chptr->mode.mode & MODE_MODERATED) |
746 |
+ |
return ERR_CANNOTSENDTOCHAN; |
747 |
+ |
if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED)) |
748 |
+ |
return ERR_NEEDREGGEDNICK; |
749 |
|
|
750 |
< |
/* cache can send if quiet_on_ban and banned */ |
751 |
< |
if (ConfigChannel.quiet_on_ban && MyClient(source_p)) |
750 |
> |
/* cache can send if banned */ |
751 |
> |
if (MyClient(source_p)) |
752 |
> |
{ |
753 |
> |
if (ms) |
754 |
|
{ |
755 |
|
if (ms->flags & CHFL_BAN_SILENCED) |
756 |
|
return ERR_CANNOTSENDTOCHAN; |
766 |
|
ms->flags |= CHFL_BAN_CHECKED; |
767 |
|
} |
768 |
|
} |
769 |
+ |
else if (is_banned(chptr, source_p)) |
770 |
+ |
return ERR_CANNOTSENDTOCHAN; |
771 |
|
} |
749 |
– |
else if (chptr->mode.mode & MODE_NOPRIVMSGS) |
750 |
– |
return ERR_CANNOTSENDTOCHAN; |
751 |
– |
|
752 |
– |
if (chptr->mode.mode & MODE_MODERATED) |
753 |
– |
return ERR_CANNOTSENDTOCHAN; |
772 |
|
|
773 |
|
return CAN_SEND_NONOP; |
774 |
|
} |
798 |
|
{ |
799 |
|
/* Its already known as a possible spambot */ |
800 |
|
if (name != NULL) |
801 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
801 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
802 |
|
"User %s (%s@%s) trying to join %s is a possible spambot", |
803 |
|
source_p->name, source_p->username, |
804 |
|
source_p->host, name); |
805 |
|
else |
806 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
806 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
807 |
|
"User %s (%s@%s) is a possible spambot", |
808 |
|
source_p->name, source_p->username, |
809 |
|
source_p->host); |
831 |
|
} |
832 |
|
} |
833 |
|
|
834 |
< |
if (name != NULL) |
834 |
> |
if (name) |
835 |
|
source_p->localClient->last_join_time = CurrentTime; |
836 |
|
else |
837 |
|
source_p->localClient->last_leave_time = CurrentTime; |
854 |
|
{ |
855 |
|
splitmode = 1; |
856 |
|
|
857 |
< |
sendto_realops_flags(UMODE_ALL,L_ALL, |
857 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
858 |
|
"Network split, activating splitmode"); |
859 |
|
eventAddIsh("check_splitmode", check_splitmode, NULL, 10); |
860 |
|
} |
862 |
|
{ |
863 |
|
splitmode = 0; |
864 |
|
|
865 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
865 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
866 |
|
"Network rejoined, deactivating splitmode"); |
867 |
|
eventDelete(check_splitmode, NULL); |
868 |
|
} |
877 |
|
*/ |
878 |
|
void |
879 |
|
set_channel_topic(struct Channel *chptr, const char *topic, |
880 |
< |
const char *topic_info, time_t topicts) |
880 |
> |
const char *topic_info, time_t topicts, int local) |
881 |
|
{ |
882 |
< |
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
882 |
> |
if (local) |
883 |
> |
strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1)); |
884 |
> |
else |
885 |
> |
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
886 |
> |
|
887 |
|
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
888 |
< |
chptr->topic_time = topicts; |
888 |
> |
chptr->topic_time = topicts; |
889 |
|
} |