2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* charybdis: A slightly useful ircd.
|
|
|
|
* supported.c: isupport (005) numeric
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jilles Tjoelker
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* From the old supported.h which is
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2004 ircd-ratbox development team
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* - from mirc's versions.txt
|
|
|
|
*
|
|
|
|
* mIRC now supports the numeric 005 tokens: CHANTYPES=# and
|
|
|
|
* PREFIX=(ohv)@%+ and can handle a dynamic set of channel and
|
|
|
|
* nick prefixes.
|
|
|
|
*
|
|
|
|
* mIRC assumes that @ is supported on all networks, any mode
|
|
|
|
* left of @ is assumed to have at least equal power to @, and
|
|
|
|
* any mode right of @ has less power.
|
|
|
|
*
|
|
|
|
* mIRC has internal support for @%+ modes.
|
|
|
|
*
|
|
|
|
* $nick() can now handle all mode letters listed in PREFIX.
|
|
|
|
*
|
|
|
|
* Also added support for CHANMODES=A,B,C,D token (not currently
|
|
|
|
* supported by any servers), which lists all modes supported
|
|
|
|
* by a channel, where:
|
|
|
|
*
|
|
|
|
* A = modes that take a parameter, and add or remove nicks
|
|
|
|
* or addresses to a list, such as +bIe for the ban,
|
|
|
|
* invite, and exception lists.
|
|
|
|
*
|
|
|
|
* B = modes that change channel settings, but which take
|
|
|
|
* a parameter when they are set and unset, such as
|
|
|
|
* +k key, and -k key.
|
|
|
|
*
|
|
|
|
* C = modes that change channel settings, but which take
|
|
|
|
* a parameter only when they are set, such as +l N,
|
|
|
|
* and -l.
|
|
|
|
*
|
|
|
|
* D = modes that change channel settings, such as +imnpst
|
|
|
|
* and take no parameters.
|
|
|
|
*
|
|
|
|
* All unknown/unlisted modes are treated as type D.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "ircd.h"
|
|
|
|
#include "s_conf.h"
|
2012-05-27 22:46:24 +02:00
|
|
|
#include "s_user.h"
|
2008-03-18 23:28:03 +01:00
|
|
|
#include "supported.h"
|
2008-06-25 05:51:32 +02:00
|
|
|
#include "chmode.h"
|
2013-09-10 07:35:56 +02:00
|
|
|
#include "send.h"
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_list isupportlist;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
struct isupportitem
|
|
|
|
{
|
|
|
|
const char *name;
|
2008-03-18 23:28:03 +01:00
|
|
|
const char *(*func)(const void *);
|
|
|
|
const void *param;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node node;
|
2007-01-25 07:40:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2008-03-18 23:28:03 +01:00
|
|
|
add_isupport(const char *name, const char *(*func)(const void *), const void *param)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
struct isupportitem *item;
|
|
|
|
|
2008-04-02 01:07:29 +02:00
|
|
|
item = rb_malloc(sizeof(struct isupportitem));
|
2007-01-25 07:40:21 +01:00
|
|
|
item->name = name;
|
|
|
|
item->func = func;
|
|
|
|
item->param = param;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlinkAddTail(item, &item->node, &isupportlist);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2008-08-29 22:36:41 +02:00
|
|
|
const void *
|
2008-08-29 22:27:34 +02:00
|
|
|
change_isupport(const char *name, const char *(*func)(const void *), const void *param)
|
|
|
|
{
|
|
|
|
rb_dlink_node *ptr;
|
|
|
|
struct isupportitem *item;
|
2010-11-14 22:51:27 +01:00
|
|
|
const void *oldvalue = NULL;
|
2008-08-29 22:27:34 +02:00
|
|
|
|
|
|
|
RB_DLINK_FOREACH(ptr, isupportlist.head)
|
|
|
|
{
|
|
|
|
item = ptr->data;
|
|
|
|
|
|
|
|
if (!strcmp(item->name, name))
|
|
|
|
{
|
2008-08-29 22:36:41 +02:00
|
|
|
oldvalue = item->param;
|
|
|
|
|
2008-08-31 01:57:27 +02:00
|
|
|
// item->name = name;
|
2008-08-29 22:27:34 +02:00
|
|
|
item->func = func;
|
|
|
|
item->param = param;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-08-29 22:36:41 +02:00
|
|
|
|
|
|
|
return oldvalue;
|
2008-08-29 22:27:34 +02:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
void
|
|
|
|
delete_isupport(const char *name)
|
|
|
|
{
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *ptr, *next_ptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
struct isupportitem *item;
|
|
|
|
|
2008-04-02 00:47:17 +02:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, isupportlist.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
item = ptr->data;
|
|
|
|
|
|
|
|
if (!strcmp(item->name, name))
|
|
|
|
{
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlinkDelete(ptr, &isupportlist);
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_free(item);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX caching? */
|
|
|
|
void
|
|
|
|
show_isupport(struct Client *client_p)
|
|
|
|
{
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
struct isupportitem *item;
|
|
|
|
const char *value;
|
|
|
|
char buf[512];
|
|
|
|
int extra_space;
|
2008-03-18 23:28:03 +01:00
|
|
|
unsigned int nchars, nparams;
|
2007-01-25 07:40:21 +01:00
|
|
|
int l;
|
|
|
|
|
|
|
|
extra_space = strlen(client_p->name);
|
|
|
|
/* UID */
|
|
|
|
if (!MyClient(client_p) && extra_space < 9)
|
|
|
|
extra_space = 9;
|
|
|
|
/* :<me.name> 005 <nick> <params> :are supported by this server */
|
|
|
|
/* form_str(RPL_ISUPPORT) is %s :are supported by this server */
|
|
|
|
extra_space += strlen(me.name) + 1 + strlen(form_str(RPL_ISUPPORT));
|
|
|
|
|
|
|
|
nchars = extra_space, nparams = 0, buf[0] = '\0';
|
2008-04-01 22:43:10 +02:00
|
|
|
RB_DLINK_FOREACH(ptr, isupportlist.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
item = ptr->data;
|
|
|
|
value = (*item->func)(item->param);
|
|
|
|
if (value == NULL)
|
|
|
|
continue;
|
|
|
|
l = strlen(item->name) + (EmptyString(value) ? 0 : 1 + strlen(value));
|
|
|
|
if (nchars + l + (nparams > 0) >= sizeof buf || nparams + 1 > 12)
|
|
|
|
{
|
|
|
|
sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf);
|
|
|
|
nchars = extra_space, nparams = 0, buf[0] = '\0';
|
|
|
|
}
|
|
|
|
if (nparams > 0)
|
2008-04-20 06:44:04 +02:00
|
|
|
rb_strlcat(buf, " ", sizeof buf), nchars++;
|
|
|
|
rb_strlcat(buf, item->name, sizeof buf);
|
2007-01-25 07:40:21 +01:00
|
|
|
if (!EmptyString(value))
|
|
|
|
{
|
2008-04-20 06:44:04 +02:00
|
|
|
rb_strlcat(buf, "=", sizeof buf);
|
|
|
|
rb_strlcat(buf, value, sizeof buf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
nchars += l;
|
|
|
|
nparams++;
|
|
|
|
}
|
|
|
|
if (nparams > 0)
|
|
|
|
sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2008-03-18 23:28:03 +01:00
|
|
|
isupport_intptr(const void *ptr)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
static char buf[15];
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(buf, sizeof buf, "%d", *(const int *)ptr);
|
2007-01-25 07:40:21 +01:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2008-03-18 23:28:03 +01:00
|
|
|
isupport_boolean(const void *ptr)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
|
2008-03-18 23:28:03 +01:00
|
|
|
return *(const int *)ptr ? "" : NULL;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2008-03-18 23:28:03 +01:00
|
|
|
isupport_string(const void *ptr)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
return (const char *)ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2008-03-18 23:28:03 +01:00
|
|
|
isupport_stringptr(const void *ptr)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2014-03-03 05:25:47 +01:00
|
|
|
return *(char * const *)ptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2012-05-27 22:46:24 +02:00
|
|
|
static const char *
|
|
|
|
isupport_umode(const void *ptr)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
str = ptr;
|
2013-08-14 23:49:22 +02:00
|
|
|
return ConfigFileEntry.oper_only_umodes &
|
|
|
|
user_modes[(unsigned char)*str] ? NULL : str;
|
2012-05-27 22:46:24 +02:00
|
|
|
}
|
|
|
|
|
2008-03-18 23:28:03 +01:00
|
|
|
static const char *
|
|
|
|
isupport_chanmodes(const void *ptr)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
static char result[80];
|
|
|
|
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(result, sizeof result, "%s%sbq,k,%slj,%s",
|
2007-01-25 07:40:21 +01:00
|
|
|
ConfigChannel.use_except ? "e" : "",
|
|
|
|
ConfigChannel.use_invex ? "I" : "",
|
2011-09-25 16:22:29 +02:00
|
|
|
ConfigChannel.use_forward ? "f" : "",
|
2008-06-25 05:51:32 +02:00
|
|
|
cflagsbuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-12-21 21:38:04 +01:00
|
|
|
static const char *
|
|
|
|
isupport_chantypes(const void *ptr)
|
|
|
|
{
|
|
|
|
return ConfigChannel.disable_local_channels ? "#" : "&#";
|
|
|
|
}
|
|
|
|
|
2008-03-18 23:28:03 +01:00
|
|
|
static const char *
|
|
|
|
isupport_chanlimit(const void *ptr)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
static char result[30];
|
|
|
|
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(result, sizeof result, "%s:%i",
|
2010-12-21 21:38:04 +01:00
|
|
|
ConfigChannel.disable_local_channels ? "#" : "&#", ConfigChannel.max_chans_per_user);
|
2007-01-25 07:40:21 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-03-18 23:28:03 +01:00
|
|
|
static const char *
|
|
|
|
isupport_maxlist(const void *ptr)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
static char result[30];
|
|
|
|
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(result, sizeof result, "bq%s%s:%i",
|
2007-01-25 07:40:21 +01:00
|
|
|
ConfigChannel.use_except ? "e" : "",
|
|
|
|
ConfigChannel.use_invex ? "I" : "",
|
|
|
|
ConfigChannel.max_bans);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-11-20 06:10:36 +01:00
|
|
|
static const char *
|
|
|
|
isupport_targmax(const void *ptr)
|
|
|
|
{
|
|
|
|
static char result[200];
|
|
|
|
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(result, sizeof result, "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%d,NOTICE:%d,ACCEPT:,MONITOR:",
|
2015-11-20 06:10:36 +01:00
|
|
|
ConfigFileEntry.max_targets,
|
|
|
|
ConfigFileEntry.max_targets);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-03-18 23:28:03 +01:00
|
|
|
static const char *
|
|
|
|
isupport_extban(const void *ptr)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
static char result[200];
|
|
|
|
|
|
|
|
p = get_extban_string();
|
|
|
|
if (EmptyString(p))
|
|
|
|
return NULL;
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(result, sizeof result, "$,%s", p);
|
2007-01-25 07:40:21 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-11-29 23:24:48 +01:00
|
|
|
static const char *
|
|
|
|
isupport_nicklen(const void *ptr)
|
|
|
|
{
|
|
|
|
static char result[200];
|
|
|
|
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(result, sizeof result, "%u", ConfigFileEntry.nicklen - 1);
|
2011-11-29 23:24:48 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
void
|
|
|
|
init_isupport(void)
|
|
|
|
{
|
|
|
|
static int maxmodes = MAXMODEPARAMS;
|
|
|
|
static int channellen = LOC_CHANNELLEN;
|
|
|
|
static int topiclen = TOPICLEN;
|
2011-11-29 23:24:48 +01:00
|
|
|
static int maxnicklen = NICKLEN - 1;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2010-12-21 21:38:04 +01:00
|
|
|
add_isupport("CHANTYPES", isupport_chantypes, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
add_isupport("EXCEPTS", isupport_boolean, &ConfigChannel.use_except);
|
|
|
|
add_isupport("INVEX", isupport_boolean, &ConfigChannel.use_invex);
|
|
|
|
add_isupport("CHANMODES", isupport_chanmodes, NULL);
|
|
|
|
add_isupport("CHANLIMIT", isupport_chanlimit, NULL);
|
|
|
|
add_isupport("PREFIX", isupport_string, "(ov)@+");
|
|
|
|
add_isupport("MAXLIST", isupport_maxlist, NULL);
|
|
|
|
add_isupport("MODES", isupport_intptr, &maxmodes);
|
|
|
|
add_isupport("NETWORK", isupport_stringptr, &ServerInfo.network_name);
|
|
|
|
add_isupport("STATUSMSG", isupport_string, "@+");
|
2012-05-27 22:46:24 +02:00
|
|
|
add_isupport("CALLERID", isupport_umode, "g");
|
2007-01-25 07:40:21 +01:00
|
|
|
add_isupport("CASEMAPPING", isupport_string, "rfc1459");
|
2011-11-29 23:24:48 +01:00
|
|
|
add_isupport("NICKLEN", isupport_nicklen, NULL);
|
|
|
|
add_isupport("MAXNICKLEN", isupport_intptr, &maxnicklen);
|
2007-01-25 07:40:21 +01:00
|
|
|
add_isupport("CHANNELLEN", isupport_intptr, &channellen);
|
|
|
|
add_isupport("TOPICLEN", isupport_intptr, &topiclen);
|
2012-05-27 22:46:24 +02:00
|
|
|
add_isupport("DEAF", isupport_umode, "D");
|
2015-11-20 06:10:36 +01:00
|
|
|
add_isupport("TARGMAX", isupport_targmax, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
add_isupport("EXTBAN", isupport_extban, NULL);
|
2010-01-19 08:47:21 +01:00
|
|
|
add_isupport("CLIENTVER", isupport_string, "3.0");
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|