2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char list_desc[] = "Provides the LIST command to clients to view non-hidden channels";
|
|
|
|
|
2016-01-21 04:26:55 +01:00
|
|
|
static rb_dlink_list safelisting_clients = { NULL, NULL, 0 };
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static struct ev_entry *iterate_clients_ev = NULL;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
static int _modinit(void);
|
|
|
|
static void _moddeinit(void);
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void m_list(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
|
|
|
static void mo_list(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void list_one_channel(client::client &source, chan::chan *chptr, int visible);
|
2012-04-29 00:44:33 +02:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void safelist_one_channel(client::client &source, chan::chan *chptr, struct ListClient *params);
|
2016-01-21 04:26:55 +01:00
|
|
|
static void safelist_check_cliexit(hook_data_client_exit * hdata);
|
2016-08-23 02:37:07 +02:00
|
|
|
static void safelist_client_instantiate(client::client &, struct ListClient *);
|
|
|
|
static void safelist_client_release(client::client &);
|
|
|
|
static void safelist_iterate_client(client::client &source);
|
2016-01-21 04:26:55 +01:00
|
|
|
static void safelist_iterate_clients(void *unused);
|
2016-08-23 02:37:07 +02:00
|
|
|
static void safelist_channel_named(client::client &source, const char *name, int operspy);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
struct Message list_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"LIST", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_unreg, {m_list, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_list, 0}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 list_clist[] = { &list_msgtab, NULL };
|
|
|
|
|
2016-01-21 04:26:55 +01:00
|
|
|
mapi_hfn_list_av1 list_hfnlist[] = {
|
|
|
|
{"client_exit", (hookfn) safelist_check_cliexit},
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2016-03-07 09:34:00 +01:00
|
|
|
DECLARE_MODULE_AV2(list, _modinit, _moddeinit, list_clist, NULL, list_hfnlist, NULL, NULL, list_desc);
|
2016-01-21 04:26:55 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
static int _modinit(void)
|
|
|
|
{
|
2016-01-21 04:26:55 +01:00
|
|
|
iterate_clients_ev = rb_event_add("safelist_iterate_clients", safelist_iterate_clients, NULL, 3);
|
|
|
|
|
2011-01-06 09:40:08 +01:00
|
|
|
/* ELIST=[tokens]:
|
|
|
|
*
|
|
|
|
* M = mask search
|
|
|
|
* N = !mask search
|
|
|
|
* U = user count search (< >)
|
|
|
|
* C = creation time search (C> C<)
|
|
|
|
* T = topic search (T> T<)
|
|
|
|
*/
|
2016-08-25 09:59:58 +02:00
|
|
|
supported::add("SAFELIST");
|
|
|
|
supported::add("ELIST", "CTU");
|
2011-01-06 09:40:08 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _moddeinit(void)
|
|
|
|
{
|
2016-01-21 04:26:55 +01:00
|
|
|
rb_event_delete(iterate_clients_ev);
|
|
|
|
|
2016-08-25 09:59:58 +02:00
|
|
|
supported::del("SAFELIST");
|
|
|
|
supported::del("ELIST");
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-21 04:26:55 +01:00
|
|
|
static void safelist_check_cliexit(hook_data_client_exit * hdata)
|
|
|
|
{
|
|
|
|
/* Cancel the safelist request if we are disconnecting
|
|
|
|
* from the server. That way it doesn't core. :P --nenolod
|
|
|
|
*/
|
2016-08-23 04:33:36 +02:00
|
|
|
if (my(*hdata->target) && hdata->target->localClient->safelist_data != NULL)
|
2016-08-23 02:37:07 +02:00
|
|
|
safelist_client_release(*hdata->target);
|
2016-01-21 04:26:55 +01:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* 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
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
m_list(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
static time_t last_used = 0L;
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
if (source.localClient->safelist_data != NULL)
|
2016-01-21 04:26:55 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":/LIST aborted");
|
|
|
|
safelist_client_release(source);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-21 04:26:55 +01:00
|
|
|
}
|
|
|
|
|
2016-08-19 01:53:12 +02:00
|
|
|
if (parc < 2 || chan::has_prefix(parv[1]))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
/* pace this due to the sheer traffic involved */
|
2008-04-02 01:53:20 +02:00
|
|
|
if (((last_used + ConfigFileEntry.pace_wait) > rb_current_time()))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_LOAD2HI), me.name, source.name, "LIST");
|
|
|
|
sendto_one(&source, form_str(RPL_LISTEND), me.name, source.name);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
2008-04-02 01:53:20 +02:00
|
|
|
last_used = rb_current_time();
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
mo_list(msgbuf_p, client, source, parc, parv);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mo_list()
|
|
|
|
* parv[1] = channel
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
mo_list(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-01-21 04:26:55 +01:00
|
|
|
struct ListClient *params;
|
2011-05-23 05:30:49 +02:00
|
|
|
char *p;
|
|
|
|
char *args = NULL;
|
2007-01-25 07:40:21 +01:00
|
|
|
int i;
|
2011-05-23 05:30:49 +02:00
|
|
|
int operspy = 0;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
if (source.localClient->safelist_data != NULL)
|
2016-01-21 04:26:55 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":/LIST aborted");
|
|
|
|
safelist_client_release(source);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-21 04:26:55 +01:00
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2011-05-23 05:30:49 +02:00
|
|
|
if (parc > 1)
|
|
|
|
{
|
|
|
|
args = LOCAL_COPY(parv[1]);
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
if (args && *args == '!' && IsOperSpy(&source))
|
2011-05-23 05:30:49 +02:00
|
|
|
{
|
|
|
|
args++;
|
2016-08-26 06:38:15 +02:00
|
|
|
//report_operspy(&source, "LIST", args);
|
2011-05-23 05:30:49 +02:00
|
|
|
operspy = 1;
|
|
|
|
}
|
|
|
|
|
2011-01-06 06:15:36 +01:00
|
|
|
/* Single channel. */
|
2016-08-19 01:53:12 +02:00
|
|
|
if (args && chan::has_prefix(args))
|
2011-01-06 06:15:36 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
safelist_channel_named(source, args, operspy);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2011-01-06 06:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Multiple channels, possibly with parameters. */
|
2016-07-13 07:17:21 +02:00
|
|
|
params = (ListClient *)rb_malloc(sizeof(struct ListClient));
|
2011-01-06 06:15:36 +01:00
|
|
|
|
2015-12-27 05:23:28 +01:00
|
|
|
params->users_min = ConfigChannel.displayed_usercount;
|
2011-01-06 06:15:36 +01:00
|
|
|
params->users_max = INT_MAX;
|
2011-05-23 05:30:49 +02:00
|
|
|
params->operspy = operspy;
|
2014-03-03 05:25:47 +01:00
|
|
|
params->created_min = params->topic_min =
|
2011-01-06 06:15:36 +01:00
|
|
|
params->created_max = params->topic_max = 0;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2011-05-23 05:30:49 +02:00
|
|
|
if (args && !EmptyString(args))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2011-01-06 03:57:27 +01:00
|
|
|
/* Cancel out default minimum. */
|
2011-01-06 06:15:36 +01:00
|
|
|
params->users_min = 0;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2011-01-06 06:15:36 +01:00
|
|
|
for (i = 0; i < 7; i++)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if ((p = strchr(args, ',')) != NULL)
|
|
|
|
*p++ = '\0';
|
|
|
|
|
|
|
|
if (*args == '<')
|
|
|
|
{
|
|
|
|
args++;
|
2016-08-16 11:12:01 +02:00
|
|
|
if (rfc1459::is_digit(*args))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2011-01-06 06:15:36 +01:00
|
|
|
params->users_max = atoi(args);
|
|
|
|
if (params->users_max == 0)
|
|
|
|
params->users_max = INT_MAX;
|
2007-01-25 07:40:21 +01:00
|
|
|
else
|
2011-01-06 06:15:36 +01:00
|
|
|
params->users_max--;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*args == '>')
|
|
|
|
{
|
|
|
|
args++;
|
2016-08-16 11:12:01 +02:00
|
|
|
if (rfc1459::is_digit(*args))
|
2011-01-06 06:15:36 +01:00
|
|
|
params->users_min = atoi(args) + 1;
|
2007-01-25 07:40:21 +01:00
|
|
|
else
|
2011-01-06 06:15:36 +01:00
|
|
|
params->users_min = 0;
|
|
|
|
}
|
|
|
|
else if (*args == 'C' || *args == 'c')
|
|
|
|
{
|
|
|
|
args++;
|
|
|
|
if (*args == '>')
|
|
|
|
{
|
|
|
|
/* Creation time earlier than last x minutes. */
|
|
|
|
args++;
|
2016-08-16 11:12:01 +02:00
|
|
|
if (rfc1459::is_digit(*args))
|
2011-01-06 06:15:36 +01:00
|
|
|
{
|
|
|
|
params->created_max = rb_current_time() - (60 * atoi(args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*args == '<')
|
|
|
|
{
|
|
|
|
/* Creation time within last x minutes. */
|
|
|
|
args++;
|
2016-08-16 11:12:01 +02:00
|
|
|
if (rfc1459::is_digit(*args))
|
2011-01-06 06:15:36 +01:00
|
|
|
{
|
|
|
|
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++;
|
2016-08-16 11:12:01 +02:00
|
|
|
if (rfc1459::is_digit(*args))
|
2011-01-06 06:15:36 +01:00
|
|
|
{
|
|
|
|
params->topic_max = rb_current_time() - (60 * atoi(args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*args == '<')
|
|
|
|
{
|
|
|
|
/* Topic change time within last x minutes. */
|
|
|
|
args++;
|
2016-08-16 11:12:01 +02:00
|
|
|
if (rfc1459::is_digit(*args))
|
2011-01-06 06:15:36 +01:00
|
|
|
{
|
|
|
|
params->topic_min = rb_current_time() - (60 * atoi(args));
|
|
|
|
}
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EmptyString(p))
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
args = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
safelist_client_instantiate(source, params);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2012-04-29 00:44:33 +02:00
|
|
|
/*
|
|
|
|
* list_one_channel()
|
|
|
|
*
|
|
|
|
* inputs - client pointer, channel pointer, whether normally visible
|
|
|
|
* outputs - none
|
|
|
|
* side effects - a channel is listed
|
|
|
|
*/
|
2016-08-23 02:37:07 +02:00
|
|
|
static void list_one_channel(client::client &source, chan::chan *chptr,
|
2012-04-29 00:44:33 +02:00
|
|
|
int visible)
|
|
|
|
{
|
2016-01-14 00:11:16 +01:00
|
|
|
char topic[TOPICLEN + 1];
|
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
if (!chptr->topic.text.empty())
|
|
|
|
rb_strlcpy(topic, chptr->topic.text.c_str(), sizeof topic);
|
2016-01-14 00:11:16 +01:00
|
|
|
else
|
|
|
|
topic[0] = '\0';
|
|
|
|
strip_colour(topic);
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_LIST), me.name, source.name,
|
2012-04-29 00:44:33 +02:00
|
|
|
visible ? "" : "!",
|
2016-08-20 02:32:26 +02:00
|
|
|
chptr->name.c_str(), size(chptr->members),
|
2016-01-14 00:11:16 +01:00
|
|
|
topic);
|
2012-04-29 00:44:33 +02:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* safelist_sendq_exceeded()
|
|
|
|
*
|
|
|
|
* inputs - pointer to client that needs checking
|
2016-03-09 08:37:03 +01:00
|
|
|
* outputs - true if a client has exceeded the reserved
|
|
|
|
* sendq limit, false if not
|
2007-01-25 07:40:21 +01:00
|
|
|
* side effects - none
|
|
|
|
*
|
|
|
|
* When safelisting, we only use half of the SendQ at any
|
|
|
|
* given time.
|
|
|
|
*/
|
2016-08-23 02:37:07 +02:00
|
|
|
static bool safelist_sendq_exceeded(client::client &client)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
return rb_linebuf_len(&client.localClient->buf_sendq) > (get_sendq(&client) / 2);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-21 04:26:55 +01:00
|
|
|
/*
|
|
|
|
* safelist_client_instantiate()
|
|
|
|
*
|
|
|
|
* inputs - pointer to Client to be listed,
|
|
|
|
* pointer to ListClient for params
|
|
|
|
* outputs - none
|
|
|
|
* side effects - the safelist process begins for a
|
|
|
|
* client.
|
|
|
|
*
|
|
|
|
* Please do not ever call this on a non-local client.
|
|
|
|
* If you do, you will get SIGSEGV.
|
|
|
|
*/
|
2016-08-23 02:37:07 +02:00
|
|
|
static void safelist_client_instantiate(client::client &client, struct ListClient *params)
|
2016-01-21 04:26:55 +01:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
s_assert(my(client));
|
2016-01-21 04:26:55 +01:00
|
|
|
s_assert(params != NULL);
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
client.localClient->safelist_data = params;
|
2016-01-21 04:26:55 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&client, form_str(RPL_LISTSTART), me.name, client.name);
|
2016-01-21 04:26:55 +01:00
|
|
|
|
|
|
|
/* pop the client onto the queue for processing */
|
2016-08-23 02:37:07 +02:00
|
|
|
rb_dlinkAddAlloc(&client, &safelisting_clients);
|
2016-01-21 04:26:55 +01:00
|
|
|
|
|
|
|
/* give the user some initial data to work with */
|
2016-08-23 02:37:07 +02:00
|
|
|
safelist_iterate_client(client);
|
2016-01-21 04:26:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* safelist_client_release()
|
|
|
|
*
|
|
|
|
* inputs - pointer to Client being listed on
|
|
|
|
* outputs - none
|
|
|
|
* side effects - the client is no longer being
|
|
|
|
* listed
|
|
|
|
*/
|
2016-08-23 02:37:07 +02:00
|
|
|
static void safelist_client_release(client::client &client)
|
2016-01-21 04:26:55 +01:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my(client))
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
s_assert(my(client));
|
2016-01-21 04:26:55 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
rb_dlinkFindDestroy(&client, &safelisting_clients);
|
2016-01-21 04:26:55 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
rb_free(client.localClient->safelist_data->chname);
|
|
|
|
rb_free(client.localClient->safelist_data);
|
2016-01-21 04:26:55 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
client.localClient->safelist_data = NULL;
|
2016-01-21 04:26:55 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&client, form_str(RPL_LISTEND), me.name, client.name);
|
2016-01-21 04:26:55 +01:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* safelist_channel_named()
|
|
|
|
*
|
2011-05-23 05:30:49 +02:00
|
|
|
* inputs - client pointer, channel name, operspy
|
2007-01-25 07:40:21 +01:00
|
|
|
* outputs - none
|
|
|
|
* side effects - a named channel is listed
|
|
|
|
*/
|
2016-08-23 02:37:07 +02:00
|
|
|
static void safelist_channel_named(client::client &source, const char *name, int operspy)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::chan *chptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
char *p;
|
2011-05-24 00:30:45 +02:00
|
|
|
int visible;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_LISTSTART), me.name, source.name);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
if ((p = (char *)strchr(name, ',')))
|
2007-01-25 07:40:21 +01:00
|
|
|
*p = '\0';
|
|
|
|
|
2011-05-23 05:30:49 +02:00
|
|
|
if (*name == '\0')
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name);
|
|
|
|
sendto_one(&source, form_str(RPL_LISTEND), me.name, source.name);
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-20 04:51:37 +02:00
|
|
|
chptr = chan::get(name, std::nothrow);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if (chptr == NULL)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name);
|
|
|
|
sendto_one(&source, form_str(RPL_LISTEND), me.name, source.name);
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
visible = !is_secret(chptr) || is_member(chptr, &source);
|
2011-05-24 00:30:45 +02:00
|
|
|
if (visible || operspy)
|
2016-08-23 02:37:07 +02:00
|
|
|
list_one_channel(source, chptr, visible);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_LISTEND), me.name, source.name);
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* safelist_one_channel()
|
|
|
|
*
|
|
|
|
* inputs - client pointer and channel pointer
|
|
|
|
* outputs - none
|
|
|
|
* side effects - a channel is listed if it meets the
|
|
|
|
* requirements
|
|
|
|
*/
|
2016-08-23 02:37:07 +02:00
|
|
|
static void safelist_one_channel(client::client &source, chan::chan *chptr, struct ListClient *params)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2011-05-24 00:30:45 +02:00
|
|
|
int visible;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
visible = !is_secret(chptr) || is_member(chptr, &source);
|
2016-01-10 06:34:52 +01:00
|
|
|
if (!visible && !params->operspy)
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
if (size(chptr->members) < params->users_min || size(chptr->members) > params->users_max)
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
if (params->topic_min && chptr->topic.time < params->topic_min)
|
2011-01-06 06:15:36 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* If a topic TS is provided, don't show channels without a topic set. */
|
2016-08-18 07:33:38 +02:00
|
|
|
if (params->topic_max && (chptr->topic.time > params->topic_max || chptr->topic.time == 0))
|
2011-01-06 06:15:36 +01:00
|
|
|
return;
|
|
|
|
|
2016-01-10 06:34:52 +01:00
|
|
|
if (params->created_min && chptr->channelts < params->created_min)
|
2011-01-06 06:15:36 +01:00
|
|
|
return;
|
|
|
|
|
2016-01-10 06:34:52 +01:00
|
|
|
if (params->created_max && chptr->channelts > params->created_max)
|
2011-01-06 06:15:36 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
list_one_channel(source, chptr, visible);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-01-21 04:26:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* safelist_iterate_client()
|
|
|
|
*
|
|
|
|
* inputs - client pointer
|
|
|
|
* outputs - none
|
|
|
|
* side effects - the client's sendq is filled up again
|
|
|
|
*/
|
2016-08-23 02:37:07 +02:00
|
|
|
static void safelist_iterate_client(client::client &source)
|
2016-01-21 04:26:55 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
std::string chname(source.localClient->safelist_data->chname);
|
2016-08-20 04:51:37 +02:00
|
|
|
auto it(chan::chans.lower_bound(&chname));
|
|
|
|
for (; it != end(chan::chans); ++it)
|
2016-01-21 04:26:55 +01:00
|
|
|
{
|
2016-08-20 04:51:37 +02:00
|
|
|
auto &chan(*it->second);
|
2016-08-23 02:37:07 +02:00
|
|
|
if (safelist_sendq_exceeded(*source.from))
|
2016-01-21 04:26:55 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
rb_free(source.localClient->safelist_data->chname);
|
2016-08-20 04:51:37 +02:00
|
|
|
chname = rb_strdup(name(chan).c_str());
|
2016-01-21 04:26:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
safelist_one_channel(source, &chan, source.localClient->safelist_data);
|
2016-01-21 04:26:55 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
safelist_client_release(source);
|
2016-01-21 04:26:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void safelist_iterate_clients(void *unused)
|
|
|
|
{
|
|
|
|
rb_dlink_node *n, *n2;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH_SAFE(n, n2, safelisting_clients.head)
|
2016-08-23 02:37:07 +02:00
|
|
|
safelist_iterate_client(*(client::client *)n->data);
|
2016-01-21 04:26:55 +01:00
|
|
|
}
|