mirror of
https://github.com/matrix-construct/construct
synced 2024-09-06 08:45:20 +02:00
393 lines
9.9 KiB
C
393 lines
9.9 KiB
C
/*
|
|
* charybdis: An advanced ircd.
|
|
* m_list_safelist.c: Version of /list that uses the safelist code.
|
|
*
|
|
* Copyright (c) 2006 William Pitcock <nenolod@nenolod.net>
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are
|
|
* met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
*
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
* derived from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
* $Id: m_list.c 3372 2007-04-03 10:18:07Z nenolod $
|
|
*/
|
|
|
|
#include "stdinc.h"
|
|
#include "channel.h"
|
|
#include "client.h"
|
|
#include "hash.h"
|
|
#include "match.h"
|
|
#include "ircd.h"
|
|
#include "numeric.h"
|
|
#include "s_conf.h"
|
|
#include "s_newconf.h"
|
|
#include "s_serv.h"
|
|
#include "supported.h"
|
|
#include "send.h"
|
|
#include "msg.h"
|
|
#include "parse.h"
|
|
#include "modules.h"
|
|
#include "inline/stringops.h"
|
|
#include "s_assert.h"
|
|
#include "logger.h"
|
|
|
|
static int _modinit(void);
|
|
static void _moddeinit(void);
|
|
|
|
static int m_list(struct Client *, struct Client *, int, const char **);
|
|
static int mo_list(struct Client *, struct Client *, int, const char **);
|
|
|
|
struct ListOptions
|
|
{
|
|
unsigned int users_min, users_max;
|
|
time_t created_min, created_max, topic_min, topic_max;
|
|
int operspy;
|
|
};
|
|
|
|
static void list_one_channel(struct Client *source_p, struct Channel *chptr, int visible);
|
|
|
|
static void safelist_one_channel(struct Client *source_p, struct Channel *chptr, struct ListOptions *params);
|
|
static void safelist_channel_named(struct Client *source_p, const char *name, int operspy);
|
|
|
|
struct Message list_msgtab = {
|
|
"LIST", 0, 0, 0, MFLG_SLOW,
|
|
{mg_unreg, {m_list, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_list, 0}}
|
|
};
|
|
|
|
mapi_clist_av1 list_clist[] = { &list_msgtab, NULL };
|
|
|
|
DECLARE_MODULE_AV1(list, _modinit, _moddeinit, list_clist, NULL, NULL, "$Revision: 3372 $");
|
|
|
|
static int _modinit(void)
|
|
{
|
|
/* ELIST=[tokens]:
|
|
*
|
|
* M = mask search
|
|
* N = !mask search
|
|
* U = user count search (< >)
|
|
* C = creation time search (C> C<)
|
|
* T = topic search (T> T<)
|
|
*/
|
|
add_isupport("SAFELIST", isupport_string, "");
|
|
add_isupport("ELIST", isupport_string, "CTU");
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void _moddeinit(void)
|
|
{
|
|
delete_isupport("SAFELIST");
|
|
delete_isupport("ELIST");
|
|
}
|
|
|
|
/* m_list()
|
|
* parv[1] = channel
|
|
*
|
|
* XXX - With SAFELIST, do we really need to continue pacing?
|
|
* In theory, the server cannot be lagged by this. --nenolod
|
|
*/
|
|
static int m_list(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
|
{
|
|
static time_t last_used = 0L;
|
|
|
|
if (parc < 2 || !IsChannelName(parv[1]))
|
|
{
|
|
/* pace this due to the sheer traffic involved */
|
|
if (((last_used + ConfigFileEntry.pace_wait) > rb_current_time()))
|
|
{
|
|
sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "LIST");
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
|
|
return 0;
|
|
}
|
|
else
|
|
last_used = rb_current_time();
|
|
}
|
|
|
|
return mo_list(client_p, source_p, parc, parv);
|
|
}
|
|
|
|
/* mo_list()
|
|
* parv[1] = channel
|
|
*/
|
|
static int mo_list(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
|
{
|
|
struct ListOptions *params;
|
|
char *p;
|
|
char *args = NULL;
|
|
int i;
|
|
int operspy = 0;
|
|
int sendq_limit = get_sendq_hard(client_p);
|
|
rb_dlink_node *ptr;
|
|
|
|
sendq_limit /= 10;
|
|
sendq_limit *= 9;
|
|
|
|
if (parc > 1)
|
|
{
|
|
args = LOCAL_COPY(parv[1]);
|
|
}
|
|
|
|
if (args && *args == '!' && IsOperSpy(source_p))
|
|
{
|
|
args++;
|
|
report_operspy(source_p, "LIST", args);
|
|
operspy = 1;
|
|
}
|
|
|
|
/* Single channel. */
|
|
if (args && IsChannelName(args))
|
|
{
|
|
safelist_channel_named(source_p, args, operspy);
|
|
return 0;
|
|
}
|
|
|
|
/* Multiple channels, possibly with parameters. */
|
|
params = rb_malloc(sizeof(struct ListOptions));
|
|
|
|
params->users_min = ConfigChannel.displayed_usercount;
|
|
params->users_max = INT_MAX;
|
|
params->operspy = operspy;
|
|
params->created_min = params->topic_min =
|
|
params->created_max = params->topic_max = 0;
|
|
|
|
if (args && !EmptyString(args))
|
|
{
|
|
/* Cancel out default minimum. */
|
|
params->users_min = 0;
|
|
|
|
for (i = 0; i < 7; i++)
|
|
{
|
|
if ((p = strchr(args, ',')) != NULL)
|
|
*p++ = '\0';
|
|
|
|
if (*args == '<')
|
|
{
|
|
args++;
|
|
if (IsDigit(*args))
|
|
{
|
|
params->users_max = atoi(args);
|
|
if (params->users_max == 0)
|
|
params->users_max = INT_MAX;
|
|
else
|
|
params->users_max--;
|
|
}
|
|
}
|
|
else if (*args == '>')
|
|
{
|
|
args++;
|
|
if (IsDigit(*args))
|
|
params->users_min = atoi(args) + 1;
|
|
else
|
|
params->users_min = 0;
|
|
}
|
|
else if (*args == 'C' || *args == 'c')
|
|
{
|
|
args++;
|
|
if (*args == '>')
|
|
{
|
|
/* Creation time earlier than last x minutes. */
|
|
args++;
|
|
if (IsDigit(*args))
|
|
{
|
|
params->created_max = rb_current_time() - (60 * atoi(args));
|
|
}
|
|
}
|
|
else if (*args == '<')
|
|
{
|
|
/* Creation time within last x minutes. */
|
|
args++;
|
|
if (IsDigit(*args))
|
|
{
|
|
params->created_min = rb_current_time() - (60 * atoi(args));
|
|
}
|
|
}
|
|
}
|
|
else if (*args == 'T' || *args == 't')
|
|
{
|
|
args++;
|
|
if (*args == '>')
|
|
{
|
|
/* Topic change time earlier than last x minutes. */
|
|
args++;
|
|
if (IsDigit(*args))
|
|
{
|
|
params->topic_max = rb_current_time() - (60 * atoi(args));
|
|
}
|
|
}
|
|
else if (*args == '<')
|
|
{
|
|
/* Topic change time within last x minutes. */
|
|
args++;
|
|
if (IsDigit(*args))
|
|
{
|
|
params->topic_min = rb_current_time() - (60 * atoi(args));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (EmptyString(p))
|
|
break;
|
|
else
|
|
args = p;
|
|
}
|
|
}
|
|
|
|
sendto_one(client_p, form_str(RPL_LISTSTART), me.name, client_p->name);
|
|
|
|
RB_DLINK_FOREACH(ptr, global_channel_list.head)
|
|
{
|
|
safelist_one_channel(client_p, ptr->data, params);
|
|
|
|
if (rb_linebuf_len(&client_p->localClient->buf_sendq) > sendq_limit)
|
|
{
|
|
sendto_one(source_p, form_str(ERR_TOOMANYMATCHES), me.name, source_p->name, "LIST");
|
|
break;
|
|
}
|
|
}
|
|
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* list_one_channel()
|
|
*
|
|
* inputs - client pointer, channel pointer, whether normally visible
|
|
* outputs - none
|
|
* side effects - a channel is listed
|
|
*/
|
|
static void list_one_channel(struct Client *source_p, struct Channel *chptr,
|
|
int visible)
|
|
{
|
|
char topic[TOPICLEN + 1];
|
|
|
|
if (chptr->topic != NULL)
|
|
rb_strlcpy(topic, chptr->topic, sizeof topic);
|
|
else
|
|
topic[0] = '\0';
|
|
strip_colour(topic);
|
|
sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name,
|
|
visible ? "" : "!",
|
|
chptr->chname, rb_dlink_list_length(&chptr->members),
|
|
topic);
|
|
}
|
|
|
|
/*
|
|
* safelist_sendq_exceeded()
|
|
*
|
|
* inputs - pointer to client that needs checking
|
|
* outputs - 1 if a client has exceeded the reserved
|
|
* sendq limit, 0 if not
|
|
* side effects - none
|
|
*
|
|
* When safelisting, we only use half of the SendQ at any
|
|
* given time.
|
|
*/
|
|
static int safelist_sendq_exceeded(struct Client *client_p)
|
|
{
|
|
if (rb_linebuf_len(&client_p->localClient->buf_sendq) > (get_sendq(client_p) / 2))
|
|
return YES;
|
|
else
|
|
return NO;
|
|
}
|
|
|
|
/*
|
|
* safelist_channel_named()
|
|
*
|
|
* inputs - client pointer, channel name, operspy
|
|
* outputs - none
|
|
* side effects - a named channel is listed
|
|
*/
|
|
static void safelist_channel_named(struct Client *source_p, const char *name, int operspy)
|
|
{
|
|
struct Channel *chptr;
|
|
char *p;
|
|
int visible;
|
|
|
|
sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
|
|
|
|
if ((p = strchr(name, ',')))
|
|
*p = '\0';
|
|
|
|
if (*name == '\0')
|
|
{
|
|
sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name);
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
|
|
return;
|
|
}
|
|
|
|
chptr = find_channel(name);
|
|
|
|
if (chptr == NULL)
|
|
{
|
|
sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name);
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
|
|
return;
|
|
}
|
|
|
|
visible = !SecretChannel(chptr) || IsMember(source_p, chptr);
|
|
if (visible || operspy)
|
|
list_one_channel(source_p, chptr, visible);
|
|
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* safelist_one_channel()
|
|
*
|
|
* inputs - client pointer and channel pointer
|
|
* outputs - none
|
|
* side effects - a channel is listed if it meets the
|
|
* requirements
|
|
*/
|
|
static void safelist_one_channel(struct Client *source_p, struct Channel *chptr, struct ListOptions *params)
|
|
{
|
|
int visible;
|
|
|
|
visible = !SecretChannel(chptr) || IsMember(source_p, chptr);
|
|
if (!visible && !params->operspy)
|
|
return;
|
|
|
|
if ((unsigned int)chptr->members.length < params->users_min
|
|
|| (unsigned int)chptr->members.length > params->users_max)
|
|
return;
|
|
|
|
if (params->topic_min && chptr->topic_time < params->topic_min)
|
|
return;
|
|
|
|
/* If a topic TS is provided, don't show channels without a topic set. */
|
|
if (params->topic_max && (chptr->topic_time > params->topic_max
|
|
|| chptr->topic_time == 0))
|
|
return;
|
|
|
|
if (params->created_min && chptr->channelts < params->created_min)
|
|
return;
|
|
|
|
if (params->created_max && chptr->channelts > params->created_max)
|
|
return;
|
|
|
|
list_one_channel(source_p, chptr, visible);
|
|
}
|