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 |
29 |
|
#include "channel.h" |
30 |
|
#include "channel_mode.h" |
31 |
|
#include "client.h" |
32 |
– |
#include "common.h" |
32 |
|
#include "hash.h" |
33 |
+ |
#include "conf.h" |
34 |
|
#include "hostmask.h" |
35 |
|
#include "irc_string.h" |
36 |
– |
#include "sprintf_irc.h" |
36 |
|
#include "ircd.h" |
37 |
|
#include "numeric.h" |
38 |
< |
#include "s_serv.h" /* captab */ |
40 |
< |
#include "s_user.h" |
38 |
> |
#include "s_serv.h" |
39 |
|
#include "send.h" |
42 |
– |
#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 |
|
|
47 |
– |
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 *topic_heap = NULL; |
50 |
< |
static BlockHeap *member_heap = NULL; |
53 |
< |
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]; |
53 |
|
static char modebuf[MODEBUFLEN]; |
57 |
|
/*! \brief Initializes the channel blockheap, adds known channel CAPAB |
58 |
|
*/ |
59 |
|
void |
60 |
< |
init_channels(void) |
60 |
> |
channel_init(void) |
61 |
|
{ |
62 |
|
add_capability("EX", CAP_EX, 1); |
63 |
|
add_capability("IE", CAP_IE, 1); |
67 |
– |
add_capability("CHW", CAP_CHW, 1); |
64 |
|
|
65 |
< |
channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE); |
66 |
< |
ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE); |
67 |
< |
topic_heap = BlockHeapCreate("topic", TOPICLEN+1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE); |
72 |
< |
member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2); |
65 |
> |
channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL); |
66 |
> |
ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN); |
67 |
> |
member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER); |
68 |
|
} |
69 |
|
|
70 |
|
/*! \brief adds a user to a channel by adding another link to the |
101 |
|
if (!IsSetJoinFloodNoticed(chptr)) |
102 |
|
{ |
103 |
|
SetJoinFloodNoticed(chptr); |
104 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
104 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
105 |
|
"Possible Join Flooder %s on %s target: %s", |
106 |
|
get_client_name(who, HIDE_IP), |
107 |
|
who->servptr->name, chptr->chname); |
111 |
|
chptr->last_join_time = CurrentTime; |
112 |
|
} |
113 |
|
|
114 |
< |
ms = BlockHeapAlloc(member_heap); |
114 |
> |
ms = mp_pool_get(member_pool); |
115 |
> |
memset(ms, 0, sizeof(*ms)); |
116 |
> |
|
117 |
|
ms->client_p = who; |
118 |
|
ms->chptr = chptr; |
119 |
|
ms->flags = flags; |
135 |
|
dlinkDelete(&member->channode, &chptr->members); |
136 |
|
dlinkDelete(&member->usernode, &client_p->channel); |
137 |
|
|
138 |
< |
BlockHeapFree(member_heap, member); |
138 |
> |
mp_pool_release(member); |
139 |
|
|
140 |
|
if (chptr->members.head == NULL) |
141 |
|
destroy_channel(chptr); |
151 |
|
send_members(struct Client *client_p, struct Channel *chptr, |
152 |
|
char *lmodebuf, char *lparabuf) |
153 |
|
{ |
154 |
< |
struct Membership *ms; |
158 |
< |
dlink_node *ptr; |
154 |
> |
const dlink_node *ptr = NULL; |
155 |
|
int tlen; /* length of text to append */ |
156 |
|
char *t, *start; /* temp char pointer */ |
157 |
|
|
158 |
< |
start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:", |
159 |
< |
ID_or_name(&me, client_p), |
160 |
< |
(unsigned long)chptr->channelts, |
161 |
< |
chptr->chname, lmodebuf, lparabuf); |
158 |
> |
start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:", |
159 |
> |
ID_or_name(&me, client_p), |
160 |
> |
(unsigned long)chptr->channelts, |
161 |
> |
chptr->chname, lmodebuf, lparabuf); |
162 |
|
|
163 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
164 |
|
{ |
165 |
< |
ms = ptr->data; |
165 |
> |
const struct Membership *ms = ptr->data; |
166 |
|
|
167 |
< |
tlen = strlen(IsCapable(client_p, CAP_TS6) ? |
172 |
< |
ID(ms->client_p) : ms->client_p->name) + 1; /* nick + space */ |
167 |
> |
tlen = strlen(ID(ms->client_p)) + 1; /* nick + space */ |
168 |
|
|
169 |
|
if (ms->flags & CHFL_CHANOP) |
170 |
|
tlen++; |
171 |
|
#ifdef HALFOPS |
172 |
< |
else if (ms->flags & CHFL_HALFOP) |
172 |
> |
if (ms->flags & CHFL_HALFOP) |
173 |
|
tlen++; |
174 |
|
#endif |
175 |
|
if (ms->flags & CHFL_VOICE) |
178 |
|
/* space will be converted into CR, but we also need space for LF.. |
179 |
|
* That's why we use '- 1' here |
180 |
|
* -adx */ |
181 |
< |
if (t + tlen - buf > sizeof(buf) - 1) |
181 |
> |
if (t + tlen - buf > IRCD_BUFSIZE - 1) |
182 |
|
{ |
183 |
|
*(t - 1) = '\0'; /* kill the space and terminate the string */ |
184 |
|
sendto_one(client_p, "%s", buf); |
185 |
|
t = start; |
186 |
|
} |
187 |
|
|
188 |
< |
if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP))) |
189 |
< |
*t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ? |
190 |
< |
'%' : '@'; |
191 |
< |
if ((ms->flags & CHFL_VOICE)) |
188 |
> |
if (ms->flags & CHFL_CHANOP) |
189 |
> |
*t++ = '@'; |
190 |
> |
if (ms->flags & CHFL_HALFOP) |
191 |
> |
*t++ = '%'; |
192 |
> |
if (ms->flags & CHFL_VOICE) |
193 |
|
*t++ = '+'; |
194 |
|
|
195 |
< |
if (IsCapable(client_p, CAP_TS6)) |
196 |
< |
strcpy(t, ID(ms->client_p)); |
201 |
< |
else |
202 |
< |
strcpy(t, ms->client_p->name); |
195 |
> |
strcpy(t, ID(ms->client_p)); |
196 |
> |
|
197 |
|
t += strlen(t); |
198 |
|
*t++ = ' '; |
199 |
|
} |
213 |
|
*/ |
214 |
|
static void |
215 |
|
send_mode_list(struct Client *client_p, struct Channel *chptr, |
216 |
< |
dlink_list *top, char flag) |
216 |
> |
const dlink_list *top, char flag) |
217 |
|
{ |
218 |
< |
int ts5 = !IsCapable(client_p, CAP_TS6); |
225 |
< |
dlink_node *lp; |
226 |
< |
struct Ban *banptr; |
218 |
> |
const dlink_node *lp = NULL; |
219 |
|
char pbuf[IRCD_BUFSIZE]; |
220 |
|
int tlen, mlen, cur_len, count = 0; |
221 |
< |
char *mp = NULL, *pp = pbuf; |
221 |
> |
char *pp = pbuf; |
222 |
|
|
223 |
|
if (top == NULL || top->length == 0) |
224 |
|
return; |
225 |
|
|
226 |
< |
if (ts5) |
227 |
< |
mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname); |
228 |
< |
else |
237 |
< |
mlen = ircsprintf(buf, ":%s BMASK %lu %s %c :", me.id, |
238 |
< |
(unsigned long)chptr->channelts, chptr->chname, flag); |
239 |
< |
|
240 |
< |
/* MODE needs additional one byte for space between buf and pbuf */ |
241 |
< |
cur_len = mlen + ts5; |
242 |
< |
mp = buf + mlen; |
226 |
> |
mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id, |
227 |
> |
(unsigned long)chptr->channelts, chptr->chname, flag); |
228 |
> |
cur_len = mlen; |
229 |
|
|
230 |
|
DLINK_FOREACH(lp, top->head) |
231 |
|
{ |
232 |
< |
banptr = lp->data; |
232 |
> |
const struct Ban *banptr = lp->data; |
233 |
|
|
234 |
< |
/* must add another b/e/I letter if we use MODE */ |
249 |
< |
tlen = banptr->len + 3 + ts5; |
234 |
> |
tlen = banptr->len + 3; |
235 |
|
|
236 |
|
/* |
237 |
|
* send buffer and start over if we cannot fit another ban, |
238 |
|
* or if the target is non-ts6 and we have too many modes in |
239 |
|
* in this line. |
240 |
|
*/ |
241 |
< |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 || |
257 |
< |
(!IsCapable(client_p, CAP_TS6) && |
258 |
< |
(count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN))) |
241 |
> |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2) |
242 |
|
{ |
243 |
|
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
244 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
244 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
245 |
|
|
246 |
< |
cur_len = mlen + ts5; |
264 |
< |
mp = buf + mlen; |
246 |
> |
cur_len = mlen; |
247 |
|
pp = pbuf; |
248 |
|
count = 0; |
249 |
|
} |
250 |
|
|
251 |
|
count++; |
252 |
< |
if (ts5) |
253 |
< |
{ |
272 |
< |
*mp++ = flag; |
273 |
< |
*mp = '\0'; |
274 |
< |
} |
275 |
< |
|
276 |
< |
pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username, |
277 |
< |
banptr->host); |
252 |
> |
pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user, |
253 |
> |
banptr->host); |
254 |
|
cur_len += tlen; |
255 |
|
} |
256 |
|
|
257 |
|
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
258 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
258 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
259 |
|
} |
260 |
|
|
261 |
|
/*! \brief send "client_p" a full list of the modes for channel chptr |
265 |
|
void |
266 |
|
send_channel_modes(struct Client *client_p, struct Channel *chptr) |
267 |
|
{ |
292 |
– |
if (chptr->chname[0] != '#') |
293 |
– |
return; |
294 |
– |
|
268 |
|
*modebuf = *parabuf = '\0'; |
269 |
|
channel_modes(chptr, client_p, modebuf, parabuf); |
270 |
|
send_members(client_p, chptr, modebuf, parabuf); |
271 |
|
|
272 |
|
send_mode_list(client_p, chptr, &chptr->banlist, 'b'); |
273 |
< |
|
274 |
< |
if (IsCapable(client_p, CAP_EX)) |
302 |
< |
send_mode_list(client_p, chptr, &chptr->exceptlist, 'e'); |
303 |
< |
if (IsCapable(client_p, CAP_IE)) |
304 |
< |
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
273 |
> |
send_mode_list(client_p, chptr, &chptr->exceptlist, 'e'); |
274 |
> |
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
275 |
|
} |
276 |
|
|
277 |
|
/*! \brief check channel name for invalid characters |
280 |
|
* \return 0 if invalid, 1 otherwise |
281 |
|
*/ |
282 |
|
int |
283 |
< |
check_channel_name(const char *name, int local) |
283 |
> |
check_channel_name(const char *name, const int local) |
284 |
|
{ |
285 |
|
const char *p = name; |
286 |
< |
int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN; |
286 |
> |
const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN; |
287 |
|
assert(name != NULL); |
288 |
|
|
289 |
|
if (!IsChanPrefix(*p)) |
311 |
|
dlinkDelete(&bptr->node, list); |
312 |
|
|
313 |
|
MyFree(bptr->name); |
314 |
< |
MyFree(bptr->username); |
314 |
> |
MyFree(bptr->user); |
315 |
|
MyFree(bptr->host); |
316 |
|
MyFree(bptr->who); |
317 |
|
|
318 |
< |
BlockHeapFree(ban_heap, bptr); |
318 |
> |
mp_pool_release(bptr); |
319 |
|
} |
320 |
|
|
321 |
|
/* free_channel_list() |
347 |
|
|
348 |
|
assert(!EmptyString(chname)); |
349 |
|
|
350 |
< |
chptr = BlockHeapAlloc(channel_heap); |
350 |
> |
chptr = mp_pool_get(channel_pool); |
351 |
> |
|
352 |
> |
memset(chptr, 0, sizeof(*chptr)); |
353 |
|
|
354 |
|
/* doesn't hurt to set it here */ |
355 |
|
chptr->channelts = CurrentTime; |
379 |
|
free_channel_list(&chptr->exceptlist); |
380 |
|
free_channel_list(&chptr->invexlist); |
381 |
|
|
410 |
– |
/* Free the topic */ |
411 |
– |
free_topic(chptr); |
412 |
– |
|
382 |
|
dlinkDelete(&chptr->node, &global_channel_list); |
383 |
|
hash_del_channel(chptr); |
384 |
|
|
385 |
< |
BlockHeapFree(channel_heap, chptr); |
385 |
> |
mp_pool_release(chptr); |
386 |
|
} |
387 |
|
|
388 |
|
/*! |
409 |
|
channel_member_names(struct Client *source_p, struct Channel *chptr, |
410 |
|
int show_eon) |
411 |
|
{ |
412 |
< |
struct Client *target_p = NULL; |
444 |
< |
struct Membership *ms = NULL; |
445 |
< |
dlink_node *ptr = NULL; |
412 |
> |
const dlink_node *ptr = NULL; |
413 |
|
char lbuf[IRCD_BUFSIZE + 1]; |
414 |
|
char *t = NULL, *start = NULL; |
415 |
|
int tlen = 0; |
416 |
|
int is_member = IsMember(source_p, chptr); |
417 |
|
int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0; |
418 |
+ |
int uhnames = HasCap(source_p, CAP_UHNAMES) != 0; |
419 |
|
|
420 |
|
if (PubChannel(chptr) || is_member) |
421 |
|
{ |
422 |
< |
t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY), |
423 |
< |
me.name, source_p->name, |
424 |
< |
channel_pub_or_secret(chptr), |
457 |
< |
chptr->chname); |
422 |
> |
t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY), |
423 |
> |
me.name, source_p->name, |
424 |
> |
channel_pub_or_secret(chptr), chptr->chname); |
425 |
|
start = t; |
426 |
|
|
427 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
428 |
|
{ |
429 |
< |
ms = ptr->data; |
463 |
< |
target_p = ms->client_p; |
429 |
> |
const struct Membership *ms = ptr->data; |
430 |
|
|
431 |
< |
if (IsInvisible(target_p) && !is_member) |
431 |
> |
if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member) |
432 |
|
continue; |
433 |
|
|
434 |
< |
tlen = strlen(target_p->name) + 1; /* nick + space */ |
434 |
> |
if (!uhnames) |
435 |
> |
tlen = strlen(ms->client_p->name) + 1; /* nick + space */ |
436 |
> |
else |
437 |
> |
tlen = strlen(ms->client_p->name) + strlen(ms->client_p->username) + |
438 |
> |
strlen(ms->client_p->host) + 3; |
439 |
|
|
440 |
|
if (!multi_prefix) |
441 |
|
{ |
459 |
|
t = start; |
460 |
|
} |
461 |
|
|
462 |
< |
t += ircsprintf(t, "%s%s ", get_member_status(ms, multi_prefix), |
463 |
< |
target_p->name); |
462 |
> |
if (!uhnames) |
463 |
> |
t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix), |
464 |
> |
ms->client_p->name); |
465 |
> |
else |
466 |
> |
t += sprintf(t, "%s%s!%s@%s ", get_member_status(ms, multi_prefix), |
467 |
> |
ms->client_p->name, ms->client_p->username, |
468 |
> |
ms->client_p->host); |
469 |
|
} |
470 |
|
|
471 |
|
if (tlen != 0) |
476 |
|
} |
477 |
|
|
478 |
|
if (show_eon) |
479 |
< |
sendto_one(source_p, form_str(RPL_ENDOFNAMES), |
505 |
< |
me.name, source_p->name, chptr->chname); |
479 |
> |
sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname); |
480 |
|
} |
481 |
|
|
482 |
|
/*! \brief adds client to invite list |
531 |
|
* (like in get_client_name) |
532 |
|
*/ |
533 |
|
const char * |
534 |
< |
get_member_status(const struct Membership *ms, int combine) |
534 |
> |
get_member_status(const struct Membership *ms, const int combine) |
535 |
|
{ |
536 |
|
static char buffer[4]; |
537 |
< |
char *p = NULL; |
564 |
< |
|
565 |
< |
if (ms == NULL) |
566 |
< |
return ""; |
567 |
< |
p = buffer; |
537 |
> |
char *p = buffer; |
538 |
|
|
539 |
|
if (ms->flags & CHFL_CHANOP) |
540 |
|
{ |
572 |
|
|
573 |
|
DLINK_FOREACH(ptr, list->head) |
574 |
|
{ |
575 |
< |
struct Ban *bp = ptr->data; |
575 |
> |
const struct Ban *bp = ptr->data; |
576 |
|
|
577 |
< |
if (match(bp->name, who->name) && match(bp->username, who->username)) |
577 |
> |
if (!match(bp->name, who->name) && !match(bp->user, who->username)) |
578 |
|
{ |
579 |
|
switch (bp->type) |
580 |
|
{ |
581 |
|
case HM_HOST: |
582 |
< |
if (match(bp->host, who->host) || match(bp->host, who->sockhost)) |
582 |
> |
if (!match(bp->host, who->host) || !match(bp->host, who->sockhost)) |
583 |
|
return 1; |
584 |
|
break; |
585 |
|
case HM_IPV4: |
612 |
|
is_banned(const struct Channel *chptr, const struct Client *who) |
613 |
|
{ |
614 |
|
if (find_bmask(who, &chptr->banlist)) |
615 |
< |
if (!ConfigChannel.use_except || !find_bmask(who, &chptr->exceptlist)) |
615 |
> |
if (!find_bmask(who, &chptr->exceptlist)) |
616 |
|
return 1; |
617 |
|
|
618 |
|
return 0; |
620 |
|
|
621 |
|
/*! |
622 |
|
* \param source_p pointer to client attempting to join |
623 |
< |
* \param chptr pointer to channel |
623 |
> |
* \param chptr pointer to channel |
624 |
|
* \param key key sent by client attempting to join if present |
625 |
|
* \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL |
626 |
|
* or 0 if allowed to join. |
628 |
|
int |
629 |
|
can_join(struct Client *source_p, struct Channel *chptr, const char *key) |
630 |
|
{ |
631 |
< |
if (is_banned(chptr, source_p)) |
662 |
< |
return ERR_BANNEDFROMCHAN; |
663 |
< |
|
664 |
< |
#ifdef HAVE_LIBCRYPTO |
665 |
< |
if ((chptr->mode.mode & MODE_SSLONLY) && !source_p->localClient->fd.ssl) |
631 |
> |
if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL)) |
632 |
|
return ERR_SSLONLYCHAN; |
667 |
– |
#endif |
633 |
|
|
634 |
< |
if ((chptr->mode.mode & MODE_OPERONLY) && !IsOper(source_p)) |
634 |
> |
if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED)) |
635 |
> |
return ERR_NEEDREGGEDNICK; |
636 |
> |
|
637 |
> |
if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER)) |
638 |
|
return ERR_OPERONLYCHAN; |
639 |
|
|
640 |
|
if (chptr->mode.mode & MODE_INVITEONLY) |
641 |
|
if (!dlinkFind(&source_p->localClient->invited, chptr)) |
642 |
< |
if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist)) |
642 |
> |
if (!find_bmask(source_p, &chptr->invexlist)) |
643 |
|
return ERR_INVITEONLYCHAN; |
644 |
|
|
645 |
< |
if (chptr->mode.key[0] && (!key || irccmp(chptr->mode.key, key))) |
645 |
> |
if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key))) |
646 |
|
return ERR_BADCHANNELKEY; |
647 |
|
|
648 |
|
if (chptr->mode.limit && dlink_list_length(&chptr->members) >= |
649 |
|
chptr->mode.limit) |
650 |
|
return ERR_CHANNELISFULL; |
651 |
|
|
652 |
+ |
if (is_banned(chptr, source_p)) |
653 |
+ |
return ERR_BANNEDFROMCHAN; |
654 |
+ |
|
655 |
|
return 0; |
656 |
|
} |
657 |
|
|
658 |
|
int |
659 |
< |
has_member_flags(struct Membership *ms, unsigned int flags) |
659 |
> |
has_member_flags(const struct Membership *ms, const unsigned int flags) |
660 |
|
{ |
661 |
|
if (ms != NULL) |
662 |
|
return ms->flags & flags; |
671 |
|
if (!IsClient(client_p)) |
672 |
|
return NULL; |
673 |
|
|
674 |
< |
DLINK_FOREACH(ptr, client_p->channel.head) |
675 |
< |
if (((struct Membership *)ptr->data)->chptr == chptr) |
676 |
< |
return ptr->data; |
674 |
> |
if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel)) |
675 |
> |
{ |
676 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
677 |
> |
if (((struct Membership *)ptr->data)->client_p == client_p) |
678 |
> |
return ptr->data; |
679 |
> |
} |
680 |
> |
else |
681 |
> |
{ |
682 |
> |
DLINK_FOREACH(ptr, client_p->channel.head) |
683 |
> |
if (((struct Membership *)ptr->data)->chptr == chptr) |
684 |
> |
return ptr->data; |
685 |
> |
} |
686 |
|
|
687 |
|
return NULL; |
688 |
|
} |
689 |
|
|
690 |
+ |
/* |
691 |
+ |
* Basically the same functionality as in bahamut |
692 |
+ |
*/ |
693 |
+ |
static int |
694 |
+ |
msg_has_ctrls(const char *message) |
695 |
+ |
{ |
696 |
+ |
const unsigned char *p = (const unsigned char *)message; |
697 |
+ |
|
698 |
+ |
for (; *p; ++p) |
699 |
+ |
{ |
700 |
+ |
if (*p > 31 || *p == 1) |
701 |
+ |
continue; |
702 |
+ |
|
703 |
+ |
if (*p == 27) |
704 |
+ |
{ |
705 |
+ |
if (*(p + 1) == '$' || |
706 |
+ |
*(p + 1) == '(') |
707 |
+ |
{ |
708 |
+ |
++p; |
709 |
+ |
continue; |
710 |
+ |
} |
711 |
+ |
} |
712 |
+ |
|
713 |
+ |
return 1; |
714 |
+ |
} |
715 |
+ |
|
716 |
+ |
return 0; |
717 |
+ |
} |
718 |
+ |
|
719 |
|
/*! |
720 |
|
* \param chptr pointer to Channel struct |
721 |
|
* \param source_p pointer to Client struct |
722 |
|
* \param ms pointer to Membership struct (can be NULL) |
723 |
|
* \return CAN_SEND_OPV if op or voiced on channel\n |
724 |
|
* CAN_SEND_NONOP if can send to channel but is not an op\n |
725 |
< |
* CAN_SEND_NO if they cannot send to channel\n |
725 |
> |
* ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n |
726 |
|
*/ |
727 |
|
int |
728 |
< |
can_send(struct Channel *chptr, struct Client *source_p, struct Membership *ms) |
728 |
> |
can_send(struct Channel *chptr, struct Client *source_p, |
729 |
> |
struct Membership *ms, const char *message) |
730 |
|
{ |
731 |
< |
if (IsServer(source_p)) |
731 |
> |
struct MaskItem *conf = NULL; |
732 |
> |
|
733 |
> |
if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE)) |
734 |
|
return CAN_SEND_OPV; |
735 |
|
|
736 |
|
if (MyClient(source_p) && !IsExemptResv(source_p)) |
737 |
< |
if (!(IsOper(source_p) && ConfigFileEntry.oper_pass_resv)) |
738 |
< |
if (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels) |
739 |
< |
return CAN_SEND_NO; |
740 |
< |
|
741 |
< |
if (ms != NULL || (ms = find_channel_link(source_p, chptr))) |
742 |
< |
{ |
737 |
> |
if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv)) |
738 |
> |
if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf)) |
739 |
> |
return ERR_CANNOTSENDTOCHAN; |
740 |
> |
|
741 |
> |
if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message)) |
742 |
> |
return ERR_NOCTRLSONCHAN; |
743 |
> |
if (ms || (ms = find_channel_link(source_p, chptr))) |
744 |
|
if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE)) |
745 |
|
return CAN_SEND_OPV; |
746 |
+ |
if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS)) |
747 |
+ |
return ERR_CANNOTSENDTOCHAN; |
748 |
+ |
if (chptr->mode.mode & MODE_MODERATED) |
749 |
+ |
return ERR_CANNOTSENDTOCHAN; |
750 |
+ |
if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED)) |
751 |
+ |
return ERR_NEEDREGGEDNICK; |
752 |
|
|
753 |
< |
/* cache can send if quiet_on_ban and banned */ |
754 |
< |
if (ConfigChannel.quiet_on_ban && MyClient(source_p)) |
753 |
> |
/* cache can send if banned */ |
754 |
> |
if (MyClient(source_p)) |
755 |
> |
{ |
756 |
> |
if (ms) |
757 |
|
{ |
758 |
|
if (ms->flags & CHFL_BAN_SILENCED) |
759 |
< |
return CAN_SEND_NO; |
759 |
> |
return ERR_CANNOTSENDTOCHAN; |
760 |
|
|
761 |
|
if (!(ms->flags & CHFL_BAN_CHECKED)) |
762 |
|
{ |
763 |
|
if (is_banned(chptr, source_p)) |
764 |
|
{ |
765 |
|
ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED); |
766 |
< |
return CAN_SEND_NO; |
766 |
> |
return ERR_CANNOTSENDTOCHAN; |
767 |
|
} |
768 |
|
|
769 |
|
ms->flags |= CHFL_BAN_CHECKED; |
770 |
|
} |
771 |
|
} |
772 |
+ |
else if (is_banned(chptr, source_p)) |
773 |
+ |
return ERR_CANNOTSENDTOCHAN; |
774 |
|
} |
752 |
– |
else if (chptr->mode.mode & MODE_NOPRIVMSGS) |
753 |
– |
return CAN_SEND_NO; |
754 |
– |
|
755 |
– |
if (chptr->mode.mode & MODE_MODERATED) |
756 |
– |
return CAN_SEND_NO; |
775 |
|
|
776 |
|
return CAN_SEND_NONOP; |
777 |
|
} |
801 |
|
{ |
802 |
|
/* Its already known as a possible spambot */ |
803 |
|
if (name != NULL) |
804 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
804 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
805 |
|
"User %s (%s@%s) trying to join %s is a possible spambot", |
806 |
|
source_p->name, source_p->username, |
807 |
|
source_p->host, name); |
808 |
|
else |
809 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
809 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
810 |
|
"User %s (%s@%s) is a possible spambot", |
811 |
|
source_p->name, source_p->username, |
812 |
|
source_p->host); |
857 |
|
{ |
858 |
|
splitmode = 1; |
859 |
|
|
860 |
< |
sendto_realops_flags(UMODE_ALL,L_ALL, |
860 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
861 |
|
"Network split, activating splitmode"); |
862 |
|
eventAddIsh("check_splitmode", check_splitmode, NULL, 10); |
863 |
|
} |
865 |
|
{ |
866 |
|
splitmode = 0; |
867 |
|
|
868 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
868 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
869 |
|
"Network rejoined, deactivating splitmode"); |
870 |
|
eventDelete(check_splitmode, NULL); |
871 |
|
} |
872 |
|
} |
873 |
|
} |
874 |
|
|
857 |
– |
/*! \brief Allocates a new topic |
858 |
– |
* \param chptr Channel to allocate a new topic for |
859 |
– |
*/ |
860 |
– |
static void |
861 |
– |
allocate_topic(struct Channel *chptr) |
862 |
– |
{ |
863 |
– |
void *ptr = NULL; |
864 |
– |
|
865 |
– |
if (chptr == NULL) |
866 |
– |
return; |
867 |
– |
|
868 |
– |
ptr = BlockHeapAlloc(topic_heap); |
869 |
– |
|
870 |
– |
/* Basically we allocate one large block for the topic and |
871 |
– |
* the topic info. We then split it up into two and shove it |
872 |
– |
* in the chptr |
873 |
– |
*/ |
874 |
– |
chptr->topic = ptr; |
875 |
– |
chptr->topic_info = (char *)ptr + TOPICLEN+1; |
876 |
– |
*chptr->topic = '\0'; |
877 |
– |
*chptr->topic_info = '\0'; |
878 |
– |
} |
879 |
– |
|
880 |
– |
void |
881 |
– |
free_topic(struct Channel *chptr) |
882 |
– |
{ |
883 |
– |
void *ptr = NULL; |
884 |
– |
assert(chptr); |
885 |
– |
if (chptr->topic == NULL) |
886 |
– |
return; |
887 |
– |
|
888 |
– |
/* |
889 |
– |
* If you change allocate_topic you MUST change this as well |
890 |
– |
*/ |
891 |
– |
ptr = chptr->topic; |
892 |
– |
BlockHeapFree(topic_heap, ptr); |
893 |
– |
chptr->topic = NULL; |
894 |
– |
chptr->topic_info = NULL; |
895 |
– |
} |
896 |
– |
|
875 |
|
/*! \brief Sets the channel topic for chptr |
876 |
|
* \param chptr Pointer to struct Channel |
877 |
|
* \param topic The topic string |
880 |
|
*/ |
881 |
|
void |
882 |
|
set_channel_topic(struct Channel *chptr, const char *topic, |
883 |
< |
const char *topic_info, time_t topicts) |
883 |
> |
const char *topic_info, time_t topicts, int local) |
884 |
|
{ |
885 |
< |
if (!EmptyString(topic)) |
886 |
< |
{ |
909 |
< |
if (chptr->topic == NULL) |
910 |
< |
allocate_topic(chptr); |
911 |
< |
|
912 |
< |
strlcpy(chptr->topic, topic, TOPICLEN+1); |
913 |
< |
strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN); |
914 |
< |
chptr->topic_time = topicts; |
915 |
< |
} |
885 |
> |
if (local) |
886 |
> |
strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1)); |
887 |
|
else |
888 |
< |
{ |
889 |
< |
/* |
890 |
< |
* Do not reset chptr->topic_time here, it's required for |
891 |
< |
* bursting topics properly. |
921 |
< |
*/ |
922 |
< |
if (chptr->topic != NULL) |
923 |
< |
free_topic(chptr); |
924 |
< |
} |
888 |
> |
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
889 |
> |
|
890 |
> |
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
891 |
> |
chptr->topic_time = topicts; |
892 |
|
} |