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]; |
56 |
– |
static char modebuf[MODEBUFLEN]; |
57 |
– |
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); |
67 |
– |
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 |
< |
topic_heap = BlockHeapCreate("topic", TOPICLEN+1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE); |
72 |
< |
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; |
158 |
< |
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, |
165 |
< |
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) ? |
172 |
< |
ID(ms->client_p) : ms->client_p->name) + 1; /* nick + space */ |
164 |
> |
tlen = strlen(ID(ms->client_p)) + 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)); |
201 |
< |
else |
202 |
< |
strcpy(t, ms->client_p->name); |
192 |
> |
strcpy(t, ID(ms->client_p)); |
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); |
225 |
< |
dlink_node *lp; |
226 |
< |
struct Ban *banptr; |
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) |
221 |
|
return; |
222 |
|
|
223 |
< |
if (ts5) |
224 |
< |
mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname); |
225 |
< |
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; |
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 */ |
249 |
< |
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 || |
257 |
< |
(!IsCapable(client_p, CAP_TS6) && |
258 |
< |
(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; |
264 |
< |
mp = buf + mlen; |
243 |
> |
cur_len = mlen; |
244 |
|
pp = pbuf; |
245 |
|
count = 0; |
246 |
|
} |
247 |
|
|
248 |
|
count++; |
249 |
< |
if (ts5) |
250 |
< |
{ |
272 |
< |
*mp++ = flag; |
273 |
< |
*mp = '\0'; |
274 |
< |
} |
275 |
< |
|
276 |
< |
pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username, |
277 |
< |
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 |
|
|
295 |
– |
*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)) |
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'); |
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; |
378 |
|
free_channel_list(&chptr->exceptlist); |
379 |
|
free_channel_list(&chptr->invexlist); |
380 |
|
|
410 |
– |
/* Free the topic */ |
411 |
– |
free_topic(chptr); |
412 |
– |
|
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; |
444 |
< |
struct Membership *ms = NULL; |
445 |
< |
dlink_node *ptr = NULL; |
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 = (source_p->localClient->cap_active & CAP_MULTI_PREFIX) != 0; |
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), |
457 |
< |
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; |
463 |
< |
target_p = ms->client_p; |
428 |
> |
const struct Membership *ms = ptr->data; |
429 |
|
|
430 |
< |
if (IsInvisible(target_p) && !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) |
475 |
|
} |
476 |
|
|
477 |
|
if (show_eon) |
478 |
< |
sendto_one(source_p, form_str(RPL_ENDOFNAMES), |
505 |
< |
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; |
564 |
< |
|
565 |
< |
if (ms == NULL) |
566 |
< |
return ""; |
567 |
< |
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)) |
631 |
< |
return ERR_BANNEDFROMCHAN; |
630 |
> |
if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL)) |
631 |
> |
return ERR_SSLONLYCHAN; |
632 |
> |
|
633 |
> |
if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED)) |
634 |
> |
return ERR_NEEDREGGEDNICK; |
635 |
> |
|
636 |
> |
if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER)) |
637 |
> |
return ERR_OPERONLYCHAN; |
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) |
661 |
|
return ms->flags & flags; |
670 |
|
if (!IsClient(client_p)) |
671 |
|
return NULL; |
672 |
|
|
673 |
< |
DLINK_FOREACH(ptr, client_p->channel.head) |
674 |
< |
if (((struct Membership *)ptr->data)->chptr == chptr) |
675 |
< |
return ptr->data; |
673 |
> |
if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel)) |
674 |
> |
{ |
675 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
676 |
> |
if (((struct Membership *)ptr->data)->client_p == client_p) |
677 |
> |
return ptr->data; |
678 |
> |
} |
679 |
> |
else |
680 |
> |
{ |
681 |
> |
DLINK_FOREACH(ptr, client_p->channel.head) |
682 |
> |
if (((struct Membership *)ptr->data)->chptr == chptr) |
683 |
> |
return ptr->data; |
684 |
> |
} |
685 |
|
|
686 |
|
return NULL; |
687 |
|
} |
688 |
|
|
689 |
+ |
/* |
690 |
+ |
* Basically the same functionality as in bahamut |
691 |
+ |
*/ |
692 |
+ |
static int |
693 |
+ |
msg_has_ctrls(const char *message) |
694 |
+ |
{ |
695 |
+ |
const unsigned char *p = (const unsigned char *)message; |
696 |
+ |
|
697 |
+ |
for (; *p; ++p) |
698 |
+ |
{ |
699 |
+ |
if (*p > 31 || *p == 1) |
700 |
+ |
continue; |
701 |
+ |
|
702 |
+ |
if (*p == 27) |
703 |
+ |
{ |
704 |
+ |
if (*(p + 1) == '$' || |
705 |
+ |
*(p + 1) == '(') |
706 |
+ |
{ |
707 |
+ |
++p; |
708 |
+ |
continue; |
709 |
+ |
} |
710 |
+ |
} |
711 |
+ |
|
712 |
+ |
return 1; |
713 |
+ |
} |
714 |
+ |
|
715 |
+ |
return 0; |
716 |
+ |
} |
717 |
+ |
|
718 |
|
/*! |
719 |
|
* \param chptr pointer to Channel struct |
720 |
|
* \param source_p pointer to Client struct |
721 |
|
* \param ms pointer to Membership struct (can be NULL) |
722 |
|
* \return CAN_SEND_OPV if op or voiced on channel\n |
723 |
|
* CAN_SEND_NONOP if can send to channel but is not an op\n |
724 |
< |
* CAN_SEND_NO if they cannot send to channel\n |
724 |
> |
* ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n |
725 |
|
*/ |
726 |
|
int |
727 |
< |
can_send(struct Channel *chptr, struct Client *source_p, struct Membership *ms) |
727 |
> |
can_send(struct Channel *chptr, struct Client *source_p, |
728 |
> |
struct Membership *ms, const char *message) |
729 |
|
{ |
730 |
< |
if (IsServer(source_p)) |
730 |
> |
struct MaskItem *conf = NULL; |
731 |
> |
|
732 |
> |
if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE)) |
733 |
|
return CAN_SEND_OPV; |
734 |
|
|
735 |
|
if (MyClient(source_p) && !IsExemptResv(source_p)) |
736 |
< |
if (!(IsOper(source_p) && ConfigFileEntry.oper_pass_resv)) |
737 |
< |
if (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels) |
738 |
< |
return CAN_SEND_NO; |
739 |
< |
|
740 |
< |
if (ms != NULL || (ms = find_channel_link(source_p, chptr))) |
741 |
< |
{ |
736 |
> |
if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv)) |
737 |
> |
if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf)) |
738 |
> |
return ERR_CANNOTSENDTOCHAN; |
739 |
> |
|
740 |
> |
if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message)) |
741 |
> |
return ERR_NOCTRLSONCHAN; |
742 |
> |
if (ms || (ms = find_channel_link(source_p, chptr))) |
743 |
|
if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE)) |
744 |
|
return CAN_SEND_OPV; |
745 |
+ |
if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS)) |
746 |
+ |
return ERR_CANNOTSENDTOCHAN; |
747 |
+ |
if (chptr->mode.mode & MODE_MODERATED) |
748 |
+ |
return ERR_CANNOTSENDTOCHAN; |
749 |
+ |
if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED)) |
750 |
+ |
return ERR_NEEDREGGEDNICK; |
751 |
|
|
752 |
< |
/* cache can send if quiet_on_ban and banned */ |
753 |
< |
if (ConfigChannel.quiet_on_ban && MyClient(source_p)) |
752 |
> |
/* cache can send if banned */ |
753 |
> |
if (MyClient(source_p)) |
754 |
> |
{ |
755 |
> |
if (ms) |
756 |
|
{ |
757 |
|
if (ms->flags & CHFL_BAN_SILENCED) |
758 |
< |
return CAN_SEND_NO; |
758 |
> |
return ERR_CANNOTSENDTOCHAN; |
759 |
|
|
760 |
|
if (!(ms->flags & CHFL_BAN_CHECKED)) |
761 |
|
{ |
762 |
|
if (is_banned(chptr, source_p)) |
763 |
|
{ |
764 |
|
ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED); |
765 |
< |
return CAN_SEND_NO; |
765 |
> |
return ERR_CANNOTSENDTOCHAN; |
766 |
|
} |
767 |
|
|
768 |
|
ms->flags |= CHFL_BAN_CHECKED; |
769 |
|
} |
770 |
|
} |
771 |
+ |
else if (is_banned(chptr, source_p)) |
772 |
+ |
return ERR_CANNOTSENDTOCHAN; |
773 |
|
} |
744 |
– |
else if (chptr->mode.mode & MODE_NOPRIVMSGS) |
745 |
– |
return CAN_SEND_NO; |
746 |
– |
|
747 |
– |
if (chptr->mode.mode & MODE_MODERATED) |
748 |
– |
return CAN_SEND_NO; |
774 |
|
|
775 |
|
return CAN_SEND_NONOP; |
776 |
|
} |
800 |
|
{ |
801 |
|
/* Its already known as a possible spambot */ |
802 |
|
if (name != NULL) |
803 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
803 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
804 |
|
"User %s (%s@%s) trying to join %s is a possible spambot", |
805 |
|
source_p->name, source_p->username, |
806 |
|
source_p->host, name); |
807 |
|
else |
808 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
808 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
809 |
|
"User %s (%s@%s) is a possible spambot", |
810 |
|
source_p->name, source_p->username, |
811 |
|
source_p->host); |
856 |
|
{ |
857 |
|
splitmode = 1; |
858 |
|
|
859 |
< |
sendto_realops_flags(UMODE_ALL,L_ALL, |
859 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
860 |
|
"Network split, activating splitmode"); |
861 |
|
eventAddIsh("check_splitmode", check_splitmode, NULL, 10); |
862 |
|
} |
864 |
|
{ |
865 |
|
splitmode = 0; |
866 |
|
|
867 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
867 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
868 |
|
"Network rejoined, deactivating splitmode"); |
869 |
|
eventDelete(check_splitmode, NULL); |
870 |
|
} |
871 |
|
} |
872 |
|
} |
873 |
|
|
849 |
– |
/*! \brief Allocates a new topic |
850 |
– |
* \param chptr Channel to allocate a new topic for |
851 |
– |
*/ |
852 |
– |
static void |
853 |
– |
allocate_topic(struct Channel *chptr) |
854 |
– |
{ |
855 |
– |
void *ptr = NULL; |
856 |
– |
|
857 |
– |
if (chptr == NULL) |
858 |
– |
return; |
859 |
– |
|
860 |
– |
ptr = BlockHeapAlloc(topic_heap); |
861 |
– |
|
862 |
– |
/* Basically we allocate one large block for the topic and |
863 |
– |
* the topic info. We then split it up into two and shove it |
864 |
– |
* in the chptr |
865 |
– |
*/ |
866 |
– |
chptr->topic = ptr; |
867 |
– |
chptr->topic_info = (char *)ptr + TOPICLEN+1; |
868 |
– |
*chptr->topic = '\0'; |
869 |
– |
*chptr->topic_info = '\0'; |
870 |
– |
} |
871 |
– |
|
872 |
– |
void |
873 |
– |
free_topic(struct Channel *chptr) |
874 |
– |
{ |
875 |
– |
void *ptr = NULL; |
876 |
– |
assert(chptr); |
877 |
– |
if (chptr->topic == NULL) |
878 |
– |
return; |
879 |
– |
|
880 |
– |
/* |
881 |
– |
* If you change allocate_topic you MUST change this as well |
882 |
– |
*/ |
883 |
– |
ptr = chptr->topic; |
884 |
– |
BlockHeapFree(topic_heap, ptr); |
885 |
– |
chptr->topic = NULL; |
886 |
– |
chptr->topic_info = NULL; |
887 |
– |
} |
888 |
– |
|
874 |
|
/*! \brief Sets the channel topic for chptr |
875 |
|
* \param chptr Pointer to struct Channel |
876 |
|
* \param topic The topic string |
879 |
|
*/ |
880 |
|
void |
881 |
|
set_channel_topic(struct Channel *chptr, const char *topic, |
882 |
< |
const char *topic_info, time_t topicts) |
882 |
> |
const char *topic_info, time_t topicts, int local) |
883 |
|
{ |
884 |
< |
if (!EmptyString(topic)) |
885 |
< |
{ |
901 |
< |
if (chptr->topic == NULL) |
902 |
< |
allocate_topic(chptr); |
903 |
< |
|
904 |
< |
strlcpy(chptr->topic, topic, TOPICLEN+1); |
905 |
< |
strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN); |
906 |
< |
chptr->topic_time = topicts; |
907 |
< |
} |
884 |
> |
if (local) |
885 |
> |
strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1)); |
886 |
|
else |
887 |
< |
{ |
888 |
< |
/* |
889 |
< |
* Do not reset chptr->topic_time here, it's required for |
890 |
< |
* bursting topics properly. |
913 |
< |
*/ |
914 |
< |
if (chptr->topic != NULL) |
915 |
< |
free_topic(chptr); |
916 |
< |
} |
887 |
> |
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
888 |
> |
|
889 |
> |
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
890 |
> |
chptr->topic_time = topicts; |
891 |
|
} |