2011-08-13 03:27:52 +02:00
|
|
|
/*
|
|
|
|
* charybdis: A slightly useful ircd.
|
|
|
|
* chmode.c: channel mode management
|
|
|
|
*
|
2014-03-03 05:25:47 +01:00
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
2011-08-13 03:27:52 +02:00
|
|
|
* Copyright (C) 2005-2006 charybdis development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
namespace mode = ircd::chan::mode;
|
|
|
|
using namespace ircd;
|
2016-08-13 05:05:54 +02:00
|
|
|
|
2011-08-13 03:27:52 +02:00
|
|
|
/* bitmasks for error returns, so we send once per call */
|
|
|
|
#define SM_ERR_NOTS 0x00000001 /* No TS on channel */
|
|
|
|
#define SM_ERR_NOOPS 0x00000002 /* No chan ops */
|
|
|
|
#define SM_ERR_UNKNOWN 0x00000004
|
|
|
|
#define SM_ERR_RPL_C 0x00000008
|
|
|
|
#define SM_ERR_RPL_B 0x00000010
|
|
|
|
#define SM_ERR_RPL_E 0x00000020
|
|
|
|
#define SM_ERR_NOTONCHANNEL 0x00000040 /* Not on channel */
|
|
|
|
#define SM_ERR_RPL_I 0x00000100
|
|
|
|
#define SM_ERR_RPL_D 0x00000200
|
|
|
|
#define SM_ERR_NOPRIVS 0x00000400
|
|
|
|
#define SM_ERR_RPL_Q 0x00000800
|
|
|
|
#define SM_ERR_RPL_F 0x00001000
|
|
|
|
#define SM_ERR_MLOCK 0x00002000
|
|
|
|
|
|
|
|
#define MAXMODES_SIMPLE 46 /* a-zA-Z except bqeIov */
|
|
|
|
|
|
|
|
static int mode_count;
|
|
|
|
static int mode_limit;
|
|
|
|
static int mode_limit_simple;
|
|
|
|
static int removed_mask_pos;
|
2016-08-17 05:01:20 +02:00
|
|
|
static int h_get_channel_access;
|
|
|
|
mode::change mode_changes[BUFSIZE];
|
2010-12-07 05:57:28 +01:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
mode::mode mode::table[256];
|
|
|
|
char mode::arity[2][256]; // RPL_MYINFO (note that [0] is for 0 OR MORE params)
|
|
|
|
char mode::categories[4][256]; // RPL_ISUPPORT classification
|
2016-07-13 07:17:21 +02:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wchar-subscripts"
|
|
|
|
static void
|
|
|
|
table_init()
|
2008-06-24 18:45:19 +02:00
|
|
|
{
|
2016-08-17 05:01:20 +02:00
|
|
|
using namespace mode;
|
|
|
|
using namespace functor;
|
|
|
|
|
2016-06-26 05:54:37 +02:00
|
|
|
// Leading tab only please:
|
2016-08-17 05:01:20 +02:00
|
|
|
// <tab>mode::table['X'] = {<sp>handler,<sp>class,<sp>flag<sp>};
|
|
|
|
|
|
|
|
table['C'] = { type(0), category::D, nullptr };
|
|
|
|
table['F'] = { FREETARGET, category::D, simple };
|
|
|
|
table['I'] = { INVEX, category::A, ban };
|
|
|
|
table['L'] = { EXLIMIT, category::D, staff };
|
|
|
|
table['P'] = { PERMANENT, category::D, staff };
|
|
|
|
table['Q'] = { DISFORWARD, category::D, simple };
|
|
|
|
table['b'] = { BAN, category::A, ban };
|
|
|
|
table['e'] = { EXCEPTION, category::A, ban };
|
|
|
|
table['f'] = { type(0), category::C, forward };
|
|
|
|
table['g'] = { FREEINVITE, category::D, simple };
|
|
|
|
table['i'] = { INVITEONLY, category::D, simple };
|
|
|
|
table['j'] = { type(0), category::C, throttle };
|
|
|
|
table['k'] = { type(0), category::B, key };
|
|
|
|
table['l'] = { type(0), category::C, limit };
|
|
|
|
table['m'] = { MODERATED, category::D, simple };
|
|
|
|
table['n'] = { NOPRIVMSGS, category::D, simple };
|
|
|
|
table['o'] = { type(0), category::B, op };
|
|
|
|
table['p'] = { PRIVATE, category::D, simple };
|
|
|
|
table['q'] = { QUIET, category::A, ban };
|
|
|
|
table['r'] = { REGONLY, category::D, simple };
|
|
|
|
table['s'] = { SECRET, category::D, simple };
|
|
|
|
table['t'] = { TOPICLIMIT, category::D, simple };
|
|
|
|
table['v'] = { type(0), category::B, voice };
|
|
|
|
table['z'] = { OPMODERATE, category::D, simple };
|
2016-07-13 07:17:21 +02:00
|
|
|
}
|
2016-08-17 05:01:20 +02:00
|
|
|
#pragma GCC diagnostic pop
|
2008-06-24 18:45:19 +02:00
|
|
|
|
2016-06-26 05:54:37 +02:00
|
|
|
/* OPTIMIZE ME! -- dwr
|
|
|
|
* sure! --jzk */
|
|
|
|
void
|
2016-08-17 05:01:20 +02:00
|
|
|
chan::mode::init()
|
2016-06-26 05:54:37 +02:00
|
|
|
{
|
2016-08-17 05:01:20 +02:00
|
|
|
table_init();
|
2016-07-13 07:17:21 +02:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
categories[uint(category::A)][0] = '\0';
|
|
|
|
categories[uint(category::B)][0] = '\0';
|
|
|
|
categories[uint(category::C)][0] = '\0';
|
|
|
|
categories[uint(category::D)][0] = '\0';
|
2016-06-26 05:54:37 +02:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
arity[0][0] = '\0';
|
|
|
|
arity[1][0] = '\0';
|
2016-06-26 05:54:37 +02:00
|
|
|
|
|
|
|
/* Filter out anything disabled by the configuraton */
|
|
|
|
unsigned long disabled = 0;
|
2016-08-17 05:01:20 +02:00
|
|
|
if (!ConfigChannel.use_invex) disabled |= INVEX;
|
|
|
|
if (!ConfigChannel.use_except) disabled |= EXCEPTION;
|
|
|
|
if (!ConfigChannel.use_forward) disabled |= FREETARGET | DISFORWARD;
|
2016-06-26 05:54:37 +02:00
|
|
|
|
|
|
|
/* Construct the chmode data */
|
|
|
|
for (size_t i = 0; i < 256; i++)
|
2008-06-24 18:45:19 +02:00
|
|
|
{
|
2016-08-17 05:01:20 +02:00
|
|
|
if (!table[i].set_func)
|
2008-06-24 18:45:19 +02:00
|
|
|
{
|
2016-08-17 05:01:20 +02:00
|
|
|
table[i].set_func = functor::nosuch;
|
|
|
|
table[i].category = category::D;
|
2016-06-26 05:54:37 +02:00
|
|
|
continue;
|
2008-06-24 18:45:19 +02:00
|
|
|
}
|
2014-03-03 05:25:47 +01:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
if (table[i].type & disabled || table[i].set_func == functor::nosuch)
|
2016-06-26 05:54:37 +02:00
|
|
|
continue;
|
2014-03-03 05:25:47 +01:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
const char ch[2] = { char(i), '\0' };
|
|
|
|
const auto &cat(table[i].category);
|
|
|
|
rb_strlcat(categories[uint(cat)], ch, 256);
|
|
|
|
rb_strlcat(arity[0], ch, 256);
|
2008-06-24 18:45:19 +02:00
|
|
|
}
|
2014-03-03 05:25:47 +01:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
/* Any non-category::D mode has parameters, this sets up RPL_MYINFO */
|
2016-06-26 05:54:37 +02:00
|
|
|
for (size_t i = 0; i < 3; i++)
|
2016-08-17 05:01:20 +02:00
|
|
|
rb_strlcat(arity[1], categories[i], 256);
|
2008-06-24 19:26:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* find_umode_slot
|
|
|
|
*
|
|
|
|
* inputs - NONE
|
|
|
|
* outputs - an available cflag bitmask or
|
|
|
|
* 0 if no cflags are available
|
|
|
|
* side effects - NONE
|
|
|
|
*/
|
2016-08-17 05:01:20 +02:00
|
|
|
static mode::type
|
2008-06-24 19:26:49 +02:00
|
|
|
find_cflag_slot(void)
|
|
|
|
{
|
2016-08-17 05:01:20 +02:00
|
|
|
using namespace mode;
|
|
|
|
|
2008-06-24 19:26:49 +02:00
|
|
|
unsigned int all_cflags = 0, my_cflag = 0, i;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
2016-08-17 05:01:20 +02:00
|
|
|
all_cflags |= table[i].type;
|
2008-06-24 19:26:49 +02:00
|
|
|
|
|
|
|
for (my_cflag = 1; my_cflag && (all_cflags & my_cflag);
|
|
|
|
my_cflag <<= 1);
|
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
return type(my_cflag);
|
2008-06-24 18:45:19 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
mode::type
|
|
|
|
mode::add(const uint8_t &c,
|
|
|
|
const category &category,
|
|
|
|
const func &set_func)
|
2010-04-01 01:16:16 +02:00
|
|
|
{
|
2016-08-17 05:01:20 +02:00
|
|
|
if(table[c].set_func &&
|
|
|
|
table[c].set_func != functor::nosuch &&
|
|
|
|
table[c].set_func != functor::orphaned)
|
|
|
|
return type(0);
|
2010-04-01 01:16:16 +02:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
if(table[c].set_func == functor::nosuch)
|
|
|
|
table[c].type = find_cflag_slot();
|
2016-06-26 05:54:37 +02:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
if(!table[c].type)
|
|
|
|
return type(0);
|
2016-06-26 05:54:37 +02:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
table[c].category = category;
|
|
|
|
table[c].set_func = set_func;
|
|
|
|
init();
|
2016-06-26 05:54:37 +02:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
return table[c].type;
|
2010-04-01 01:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-17 05:01:20 +02:00
|
|
|
mode::orphan(const uint8_t &c)
|
2010-04-01 01:16:16 +02:00
|
|
|
{
|
2016-08-17 05:01:20 +02:00
|
|
|
s_assert(table[c].type != 0);
|
|
|
|
table[c].set_func = functor::orphaned;
|
|
|
|
init();
|
2010-04-01 01:16:16 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
namespace ircd {
|
|
|
|
|
2010-12-07 07:12:36 +01:00
|
|
|
int
|
2016-08-22 03:57:43 +02:00
|
|
|
chan::get_channel_access(client::client *source_p, chan *chptr, membership *msptr, int dir, const char *modestr)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2010-12-07 05:57:28 +01:00
|
|
|
hook_data_channel_approval moduledata;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my(*source_p))
|
2016-08-18 07:33:38 +02:00
|
|
|
return CHANOP;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2010-12-07 05:57:28 +01:00
|
|
|
moduledata.client = source_p;
|
2016-01-14 05:16:44 +01:00
|
|
|
moduledata.chptr = chptr;
|
2010-12-07 05:57:28 +01:00
|
|
|
moduledata.msptr = msptr;
|
|
|
|
moduledata.target = NULL;
|
2016-08-18 07:33:38 +02:00
|
|
|
moduledata.approved = (msptr != NULL && is_chanop(msptr)) ? CHANOP : PEON;
|
2015-12-10 08:00:32 +01:00
|
|
|
moduledata.dir = dir;
|
2016-01-12 05:40:32 +01:00
|
|
|
moduledata.modestr = modestr;
|
2011-07-06 19:35:11 +02:00
|
|
|
|
2010-12-07 05:57:28 +01:00
|
|
|
call_hook(h_get_channel_access, &moduledata);
|
|
|
|
|
|
|
|
return moduledata.approved;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2012-06-19 00:33:29 +02:00
|
|
|
/* allow_mode_change()
|
|
|
|
*
|
|
|
|
* Checks if mlock and chanops permit a mode change.
|
|
|
|
*
|
|
|
|
* inputs - client, channel, access level, errors pointer, mode char
|
2016-03-24 19:26:02 +01:00
|
|
|
* outputs - false on failure, true on success
|
2012-06-19 00:33:29 +02:00
|
|
|
* side effects - error message sent on failure
|
|
|
|
*/
|
2016-03-24 19:26:02 +01:00
|
|
|
static bool
|
2016-08-22 03:57:43 +02:00
|
|
|
allow_mode_change(client::client *source_p, chan::chan *chptr, int alevel,
|
2012-06-19 00:33:29 +02:00
|
|
|
int *errors, char c)
|
|
|
|
{
|
|
|
|
/* If this mode char is locked, don't allow local users to change it. */
|
2016-08-23 04:33:36 +02:00
|
|
|
if (my(*source_p) && !chptr->mode_lock.empty() && strchr(chptr->mode_lock.c_str(), c))
|
2012-06-19 00:33:29 +02:00
|
|
|
{
|
|
|
|
if (!(*errors & SM_ERR_MLOCK))
|
|
|
|
sendto_one_numeric(source_p,
|
|
|
|
ERR_MLOCKRESTRICTED,
|
|
|
|
form_str(ERR_MLOCKRESTRICTED),
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->name.c_str(),
|
2012-06-19 00:33:29 +02:00
|
|
|
c,
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->mode_lock.c_str());
|
2012-06-19 00:33:29 +02:00
|
|
|
*errors |= SM_ERR_MLOCK;
|
2016-03-24 19:26:02 +01:00
|
|
|
return false;
|
2012-06-19 00:33:29 +02:00
|
|
|
}
|
2016-08-18 07:33:38 +02:00
|
|
|
if(alevel < chan::CHANOP)
|
2012-06-19 00:33:29 +02:00
|
|
|
{
|
|
|
|
if(!(*errors & SM_ERR_NOOPS))
|
|
|
|
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
|
2016-08-18 07:33:38 +02:00
|
|
|
me.name, source_p->name, chptr->name.c_str());
|
2012-06-19 00:33:29 +02:00
|
|
|
*errors |= SM_ERR_NOOPS;
|
2016-03-24 19:26:02 +01:00
|
|
|
return false;
|
2012-06-19 00:33:29 +02:00
|
|
|
}
|
2016-03-24 19:26:02 +01:00
|
|
|
return true;
|
2012-06-19 00:33:29 +02:00
|
|
|
}
|
|
|
|
|
2011-12-10 00:40:07 +01:00
|
|
|
/* check_forward()
|
|
|
|
*
|
|
|
|
* input - client, channel to set mode on, target channel name
|
|
|
|
* output - true if forwarding should be allowed
|
|
|
|
* side effects - numeric sent if not allowed
|
|
|
|
*/
|
2016-03-24 19:42:54 +01:00
|
|
|
static bool
|
2016-08-22 03:57:43 +02:00
|
|
|
check_forward(client::client *source_p, chan::chan *chptr, const char *forward)
|
2011-12-10 00:40:07 +01:00
|
|
|
{
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::chan *targptr = NULL;
|
|
|
|
chan::membership *msptr;
|
2011-12-10 00:40:07 +01:00
|
|
|
|
2016-08-19 01:53:12 +02:00
|
|
|
if(!chan::valid_name(forward) ||
|
2016-08-23 04:33:36 +02:00
|
|
|
(my(*source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward))))
|
2011-12-10 00:40:07 +01:00
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward);
|
2016-03-24 19:42:54 +01:00
|
|
|
return false;
|
2011-12-10 00:40:07 +01:00
|
|
|
}
|
|
|
|
/* don't forward to inconsistent target -- jilles */
|
2016-08-18 07:33:38 +02:00
|
|
|
if(chptr->name[0] == '#' && forward[0] == '&')
|
2011-12-10 00:40:07 +01:00
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_BADCHANNAME,
|
|
|
|
form_str(ERR_BADCHANNAME), forward);
|
2016-03-24 19:42:54 +01:00
|
|
|
return false;
|
2011-12-10 00:40:07 +01:00
|
|
|
}
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && (targptr = chan::get(forward, std::nothrow)) == NULL)
|
2011-12-10 00:40:07 +01:00
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
|
|
|
form_str(ERR_NOSUCHCHANNEL), forward);
|
2016-03-24 19:42:54 +01:00
|
|
|
return false;
|
2011-12-10 00:40:07 +01:00
|
|
|
}
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && !(targptr->mode.mode & mode::FREETARGET))
|
2011-12-10 00:40:07 +01:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
auto *const msptr(get(targptr->members, *source_p, std::nothrow));
|
|
|
|
if(!msptr || get_channel_access(source_p, targptr, msptr, MODE_QUERY, NULL) < chan::CHANOP)
|
2011-12-10 00:40:07 +01:00
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
|
2016-08-20 02:32:26 +02:00
|
|
|
me.name,
|
|
|
|
source_p->name,
|
|
|
|
targptr->name.c_str());
|
2016-03-24 19:42:54 +01:00
|
|
|
return false;
|
2011-12-10 00:40:07 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-24 19:42:54 +01:00
|
|
|
return true;
|
2011-12-10 00:40:07 +01:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* fix_key()
|
|
|
|
*
|
|
|
|
* input - key to fix
|
|
|
|
* output - the same key, fixed
|
|
|
|
* side effects - anything below ascii 13 is discarded, ':' discarded,
|
|
|
|
* high ascii is dropped to lower half of ascii table
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
fix_key(char *arg)
|
|
|
|
{
|
2016-03-24 00:11:42 +01:00
|
|
|
unsigned char *s, *t, c;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-24 00:11:42 +01:00
|
|
|
for(s = t = (unsigned char *) arg; (c = *s); s++)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
c &= 0x7f;
|
|
|
|
if(c != ':' && c != ',' && c > ' ')
|
|
|
|
*t++ = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
*t = '\0';
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fix_key_remote()
|
|
|
|
*
|
|
|
|
* input - key to fix
|
|
|
|
* ouput - the same key, fixed
|
|
|
|
* side effects - high ascii dropped to lower half of table,
|
|
|
|
* CR/LF/':' are dropped
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
fix_key_remote(char *arg)
|
|
|
|
{
|
2016-03-24 00:11:42 +01:00
|
|
|
unsigned char *s, *t, c;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-24 00:11:42 +01:00
|
|
|
for(s = t = (unsigned char *) arg; (c = *s); s++)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
c &= 0x7f;
|
|
|
|
if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' '))
|
|
|
|
*t++ = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
*t = '\0';
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* chm_*()
|
|
|
|
*
|
|
|
|
* The handlers for each specific mode.
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::nosuch(client::client *source_p, chan *chptr,
|
2007-01-25 07:40:21 +01:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if(*errors & SM_ERR_UNKNOWN)
|
|
|
|
return;
|
|
|
|
*errors |= SM_ERR_UNKNOWN;
|
|
|
|
sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::simple(client::client *source_p, chan *chptr,
|
2007-01-25 07:40:21 +01:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2012-06-19 00:33:29 +02:00
|
|
|
if(!allow_mode_change(source_p, chptr, alevel, errors, c))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* setting + */
|
2010-04-30 23:01:21 +02:00
|
|
|
if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2011-09-25 16:22:29 +02:00
|
|
|
/* if +f is disabled, ignore an attempt to set +QF locally */
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!ConfigChannel.use_forward && my(*source_p) &&
|
2011-09-25 16:22:29 +02:00
|
|
|
(c == 'Q' || c == 'F'))
|
|
|
|
return;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
chptr->mode.mode |= mode_type;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_ADD;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
2008-06-24 20:00:41 +02:00
|
|
|
mode_changes[mode_count++].arg = NULL;
|
|
|
|
}
|
2010-04-30 23:01:21 +02:00
|
|
|
else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
|
2008-06-24 20:00:41 +02:00
|
|
|
{
|
|
|
|
chptr->mode.mode &= ~mode_type;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_DEL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::orphaned(client::client *source_p, chan *chptr,
|
2008-06-24 20:00:41 +02:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2008-06-24 20:00:41 +02:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p))
|
2008-06-24 20:00:41 +02:00
|
|
|
return;
|
2014-03-03 05:25:47 +01:00
|
|
|
|
2008-06-24 20:00:41 +02:00
|
|
|
if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
|
|
|
|
{
|
|
|
|
chptr->mode.mode |= mode_type;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_ADD;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
2007-01-25 07:40:21 +01:00
|
|
|
mode_changes[mode_count++].arg = NULL;
|
|
|
|
}
|
|
|
|
else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
|
|
|
|
{
|
|
|
|
chptr->mode.mode &= ~mode_type;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_DEL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-13 23:34:27 +01:00
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::hidden(client::client *source_p, chan *chptr,
|
2016-01-13 23:34:27 +01:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2016-01-13 23:34:27 +01:00
|
|
|
{
|
2016-08-24 00:25:09 +02:00
|
|
|
if(!is(*source_p, umode::OPER) && !is_server(*source_p))
|
2016-01-13 23:34:27 +01:00
|
|
|
{
|
|
|
|
if(!(*errors & SM_ERR_NOPRIVS))
|
|
|
|
sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
|
|
|
|
*errors |= SM_ERR_NOPRIVS;
|
|
|
|
return;
|
|
|
|
}
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && !IsOperAdmin(source_p))
|
2016-01-13 23:34:27 +01:00
|
|
|
{
|
|
|
|
if(!(*errors & SM_ERR_NOPRIVS))
|
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
|
|
|
|
source_p->name, "admin");
|
|
|
|
*errors |= SM_ERR_NOPRIVS;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
|
2016-01-13 23:34:27 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* setting + */
|
|
|
|
if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
|
|
|
|
{
|
|
|
|
chptr->mode.mode |= mode_type;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_ADD;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count].mems = ONLY_OPERS;
|
|
|
|
mode_changes[mode_count++].arg = NULL;
|
|
|
|
}
|
|
|
|
else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
|
|
|
|
{
|
|
|
|
chptr->mode.mode &= ~mode_type;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_DEL;
|
|
|
|
mode_changes[mode_count].mems = ONLY_OPERS;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::staff(client::client *source_p, chan *chptr,
|
2007-01-25 07:40:21 +01:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-24 00:25:09 +02:00
|
|
|
if(!is(*source_p, umode::OPER) && !is_server(*source_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if(!(*errors & SM_ERR_NOPRIVS))
|
|
|
|
sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
|
|
|
|
*errors |= SM_ERR_NOPRIVS;
|
|
|
|
return;
|
|
|
|
}
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && !IsOperResv(source_p))
|
2007-12-18 00:24:05 +01:00
|
|
|
{
|
|
|
|
if(!(*errors & SM_ERR_NOPRIVS))
|
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
|
|
|
|
source_p->name, "resv");
|
|
|
|
*errors |= SM_ERR_NOPRIVS;
|
|
|
|
return;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
if(!allow_mode_change(source_p, chptr, CHANOP, errors, c))
|
2014-08-18 00:26:38 +02:00
|
|
|
return;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
|
2008-06-25 19:27:30 +02:00
|
|
|
return;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* setting + */
|
|
|
|
if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
|
|
|
|
{
|
|
|
|
chptr->mode.mode |= mode_type;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_ADD;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count++].arg = NULL;
|
|
|
|
}
|
|
|
|
else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
|
|
|
|
{
|
|
|
|
chptr->mode.mode &= ~mode_type;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_DEL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::ban(client::client *source_p, chan *chptr,
|
2007-01-25 07:40:21 +01:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-19 07:58:17 +02:00
|
|
|
namespace chan = ircd::chan;
|
|
|
|
|
2014-01-26 11:02:07 +01:00
|
|
|
const char *mask, *raw_mask;
|
|
|
|
char *forward;
|
2016-08-19 07:58:17 +02:00
|
|
|
chan::list *list;
|
2007-01-25 07:40:21 +01:00
|
|
|
int errorval;
|
2013-02-21 12:44:16 +01:00
|
|
|
const char *rpl_list_p;
|
|
|
|
const char *rpl_endlist_p;
|
2007-01-25 07:40:21 +01:00
|
|
|
int mems;
|
|
|
|
|
|
|
|
switch (mode_type)
|
|
|
|
{
|
2016-08-18 07:33:38 +02:00
|
|
|
case BAN:
|
2016-08-19 07:58:17 +02:00
|
|
|
list = &get(*chptr, mode_type);
|
2007-01-25 07:40:21 +01:00
|
|
|
errorval = SM_ERR_RPL_B;
|
2013-02-21 12:44:16 +01:00
|
|
|
rpl_list_p = form_str(RPL_BANLIST);
|
|
|
|
rpl_endlist_p = form_str(RPL_ENDOFBANLIST);
|
2007-01-25 07:40:21 +01:00
|
|
|
mems = ALL_MEMBERS;
|
|
|
|
break;
|
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
case EXCEPTION:
|
2007-01-25 07:40:21 +01:00
|
|
|
/* if +e is disabled, allow all but +e locally */
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!ConfigChannel.use_except && my(*source_p) &&
|
2007-01-25 07:40:21 +01:00
|
|
|
((dir == MODE_ADD) && (parc > *parn)))
|
|
|
|
return;
|
|
|
|
|
2016-08-19 07:58:17 +02:00
|
|
|
list = &get(*chptr, mode_type);
|
2007-01-25 07:40:21 +01:00
|
|
|
errorval = SM_ERR_RPL_E;
|
2013-02-21 12:44:16 +01:00
|
|
|
rpl_list_p = form_str(RPL_EXCEPTLIST);
|
|
|
|
rpl_endlist_p = form_str(RPL_ENDOFEXCEPTLIST);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(ConfigChannel.use_except || (dir == MODE_DEL))
|
|
|
|
mems = ONLY_CHANOPS;
|
|
|
|
else
|
|
|
|
mems = ONLY_SERVERS;
|
|
|
|
break;
|
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
case INVEX:
|
2007-01-25 07:40:21 +01:00
|
|
|
/* if +I is disabled, allow all but +I locally */
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!ConfigChannel.use_invex && my(*source_p) &&
|
2007-01-25 07:40:21 +01:00
|
|
|
(dir == MODE_ADD) && (parc > *parn))
|
|
|
|
return;
|
|
|
|
|
2016-08-19 07:58:17 +02:00
|
|
|
list = &get(*chptr, mode_type);
|
2007-01-25 07:40:21 +01:00
|
|
|
errorval = SM_ERR_RPL_I;
|
2013-02-21 12:44:16 +01:00
|
|
|
rpl_list_p = form_str(RPL_INVITELIST);
|
|
|
|
rpl_endlist_p = form_str(RPL_ENDOFINVITELIST);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(ConfigChannel.use_invex || (dir == MODE_DEL))
|
|
|
|
mems = ONLY_CHANOPS;
|
|
|
|
else
|
|
|
|
mems = ONLY_SERVERS;
|
|
|
|
break;
|
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
case QUIET:
|
2016-08-19 07:58:17 +02:00
|
|
|
list = &get(*chptr, mode_type);
|
2007-01-25 07:40:21 +01:00
|
|
|
errorval = SM_ERR_RPL_Q;
|
2013-02-21 12:44:16 +01:00
|
|
|
rpl_list_p = form_str(RPL_QUIETLIST);
|
|
|
|
rpl_endlist_p = form_str(RPL_ENDOFQUIETLIST);
|
2007-01-25 07:40:21 +01:00
|
|
|
mems = ALL_MEMBERS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "chm_ban() called with unknown type!");
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dir == 0 || parc <= *parn)
|
|
|
|
{
|
|
|
|
if((*errors & errorval) != 0)
|
|
|
|
return;
|
|
|
|
*errors |= errorval;
|
|
|
|
|
|
|
|
/* non-ops cant see +eI lists.. */
|
2012-06-19 00:33:29 +02:00
|
|
|
/* note that this is still permitted if +e/+I are mlocked. */
|
2016-08-18 07:33:38 +02:00
|
|
|
if(alevel < CHANOP && mode_type != BAN &&
|
2016-08-17 05:01:20 +02:00
|
|
|
mode_type != QUIET)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if(!(*errors & SM_ERR_NOOPS))
|
|
|
|
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
|
2016-08-18 07:33:38 +02:00
|
|
|
me.name, source_p->name, chptr->name.c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
*errors |= SM_ERR_NOOPS;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-19 07:58:17 +02:00
|
|
|
for (const auto &ban : *list)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-18 07:33:38 +02:00
|
|
|
char buf[ban::LEN];
|
2016-08-19 07:58:17 +02:00
|
|
|
if(!ban.forward.empty())
|
|
|
|
snprintf(buf, sizeof(buf), "%s$%s", ban.banstr.c_str(), ban.forward.c_str());
|
2011-08-13 02:33:10 +02:00
|
|
|
else
|
2016-08-19 07:58:17 +02:00
|
|
|
rb_strlcpy(buf, ban.banstr.c_str(), sizeof(buf));
|
2011-08-13 02:33:10 +02:00
|
|
|
|
2013-02-21 12:44:16 +01:00
|
|
|
sendto_one(source_p, rpl_list_p,
|
2016-08-19 07:58:17 +02:00
|
|
|
me.name,
|
|
|
|
source_p->name,
|
|
|
|
chptr->name.c_str(),
|
|
|
|
buf,
|
|
|
|
ban.who.c_str(),
|
|
|
|
ban.when);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-08-19 07:58:17 +02:00
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
sendto_one(source_p, rpl_endlist_p, me.name, source_p->name, chptr->name.c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-19 00:33:29 +02:00
|
|
|
if(!allow_mode_change(source_p, chptr, alevel, errors, c))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
2012-06-19 00:33:29 +02:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && (++mode_limit > MAXPARAMS))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
raw_mask = parv[(*parn)];
|
|
|
|
(*parn)++;
|
|
|
|
|
|
|
|
/* empty ban, or starts with ':' which messes up s2s, ignore it */
|
|
|
|
if(EmptyString(raw_mask) || *raw_mask == ':')
|
|
|
|
return;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my(*source_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if(strchr(raw_mask, ' '))
|
|
|
|
return;
|
|
|
|
|
|
|
|
mask = raw_mask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mask = pretty_mask(raw_mask);
|
|
|
|
|
2011-09-25 16:25:17 +02:00
|
|
|
/* we'd have problems parsing this, hyb6 does it too
|
|
|
|
* also make sure it will always fit on a line with channel
|
|
|
|
* name etc.
|
|
|
|
*/
|
2016-08-18 07:33:38 +02:00
|
|
|
if(strlen(mask) > MIN(ban::LEN, BUFLEN - 5))
|
2011-12-18 23:24:22 +01:00
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_INVALIDBAN,
|
|
|
|
form_str(ERR_INVALIDBAN),
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->name.c_str(), c, raw_mask);
|
2011-09-25 16:25:17 +02:00
|
|
|
return;
|
2011-12-18 23:24:22 +01:00
|
|
|
}
|
2011-09-25 16:25:17 +02:00
|
|
|
|
2011-08-13 02:33:10 +02:00
|
|
|
/* Look for a $ after the first character.
|
|
|
|
* As the first character, it marks an extban; afterwards
|
|
|
|
* it delimits a forward channel.
|
|
|
|
*/
|
2016-07-13 07:17:21 +02:00
|
|
|
if ((forward = (char *)strchr(mask+1, '$')) != NULL)
|
2011-08-13 02:33:10 +02:00
|
|
|
{
|
|
|
|
*forward++ = '\0';
|
|
|
|
if (*forward == '\0')
|
|
|
|
forward = NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* if we're adding a NEW id */
|
|
|
|
if(dir == MODE_ADD)
|
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if (*mask == '$' && my(*source_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if (!valid_extban(mask, source_p, chptr, mode_type))
|
2011-12-18 23:24:22 +01:00
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_INVALIDBAN,
|
|
|
|
form_str(ERR_INVALIDBAN),
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->name.c_str(), c, raw_mask);
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
2011-12-18 23:24:22 +01:00
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2011-12-10 00:45:57 +01:00
|
|
|
/* For compatibility, only check the forward channel from
|
|
|
|
* local clients. Accept any forward channel from servers.
|
|
|
|
*/
|
2016-08-23 04:33:36 +02:00
|
|
|
if(forward != NULL && my(*source_p))
|
2011-12-10 00:45:57 +01:00
|
|
|
{
|
2011-12-11 16:56:37 +01:00
|
|
|
/* For simplicity and future flexibility, do not
|
|
|
|
* allow '$' in forwarding targets.
|
|
|
|
*/
|
2011-12-18 23:24:22 +01:00
|
|
|
if(!ConfigChannel.use_forward ||
|
|
|
|
strchr(forward, '$') != NULL)
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_INVALIDBAN,
|
|
|
|
form_str(ERR_INVALIDBAN),
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->name.c_str(), c, raw_mask);
|
2011-12-18 23:24:22 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* check_forward() sends its own error message */
|
|
|
|
if(!check_forward(source_p, chptr, forward))
|
2011-12-11 16:56:37 +01:00
|
|
|
return;
|
2011-12-10 00:58:08 +01:00
|
|
|
/* Forwards only make sense for bans. */
|
2016-08-18 07:33:38 +02:00
|
|
|
if(mode_type != BAN)
|
2011-12-18 23:24:22 +01:00
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_INVALIDBAN,
|
|
|
|
form_str(ERR_INVALIDBAN),
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->name.c_str(), c, raw_mask);
|
2011-12-10 00:58:08 +01:00
|
|
|
return;
|
2011-12-18 23:24:22 +01:00
|
|
|
}
|
2011-12-10 00:45:57 +01:00
|
|
|
}
|
2011-09-25 16:22:29 +02:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* dont allow local clients to overflow the banlist, dont
|
|
|
|
* let remote servers set duplicate bans
|
|
|
|
*/
|
2016-08-19 07:58:17 +02:00
|
|
|
if(!add(*chptr, mode_type, mask, *source_p, forward?: std::string{}))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2011-08-13 02:33:10 +02:00
|
|
|
if(forward)
|
|
|
|
forward[-1]= '$';
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_ADD;
|
|
|
|
mode_changes[mode_count].mems = mems;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = mask;
|
|
|
|
}
|
|
|
|
else if(dir == MODE_DEL)
|
|
|
|
{
|
2016-08-19 07:58:17 +02:00
|
|
|
// When this whole function gets hosed all of this will be better
|
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
static char buf[ban::LEN * MAXPARAMS];
|
2016-08-19 07:58:17 +02:00
|
|
|
const int old_removed_mask_pos(removed_mask_pos);
|
|
|
|
std::string _mask(mask);
|
|
|
|
|
|
|
|
auto it(list->find(_mask));
|
|
|
|
if (it == end(*list))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-19 07:58:17 +02:00
|
|
|
_mask = raw_mask;
|
|
|
|
it = list->find(_mask);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-19 07:58:17 +02:00
|
|
|
if (it != end(*list))
|
2011-08-13 02:33:10 +02:00
|
|
|
{
|
2016-08-19 07:58:17 +02:00
|
|
|
const auto &ban(*it);
|
|
|
|
if (!ban.forward.empty())
|
|
|
|
removed_mask_pos += snprintf(buf + old_removed_mask_pos, sizeof(buf), "%s$%s", ban.banstr.c_str(), ban.forward.c_str()) + 1;
|
|
|
|
else
|
|
|
|
removed_mask_pos += rb_strlcpy(buf + old_removed_mask_pos, mask, sizeof(buf)) + 1;
|
|
|
|
|
|
|
|
del(*chptr, mode_type, _mask);
|
2011-08-13 02:33:10 +02:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_DEL;
|
|
|
|
mode_changes[mode_count].mems = mems;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
2011-08-13 02:33:10 +02:00
|
|
|
mode_changes[mode_count++].arg = buf + old_removed_mask_pos;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::op(client::client *source_p, chan *chptr,
|
2007-01-25 07:40:21 +01:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-18 07:33:38 +02:00
|
|
|
membership *mstptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
const char *opnick;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *targ_p;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2012-06-19 00:33:29 +02:00
|
|
|
if(!allow_mode_change(source_p, chptr, alevel, errors, c))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if((dir == MODE_QUERY) || (parc <= *parn))
|
|
|
|
return;
|
|
|
|
|
|
|
|
opnick = parv[(*parn)];
|
|
|
|
(*parn)++;
|
|
|
|
|
|
|
|
/* empty nick */
|
|
|
|
if(EmptyString(opnick))
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
mstptr = get(chptr->members, *targ_p, std::nothrow);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(mstptr == NULL)
|
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!(*errors & SM_ERR_NOTONCHANNEL) && my(*source_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
|
2016-08-18 07:33:38 +02:00
|
|
|
form_str(ERR_USERNOTINCHANNEL), opnick, chptr->name.c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
*errors |= SM_ERR_NOTONCHANNEL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && (++mode_limit > MAXPARAMS))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if(dir == MODE_ADD)
|
|
|
|
{
|
2016-08-18 07:33:38 +02:00
|
|
|
if(targ_p == source_p && mstptr->flags & CHANOP)
|
2010-12-31 02:43:16 +01:00
|
|
|
return;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_ADD;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = targ_p->id;
|
2014-05-29 16:22:58 +02:00
|
|
|
mode_changes[mode_count++].arg = targ_p->name;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
mstptr->flags |= CHANOP;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-24 00:25:09 +02:00
|
|
|
if(my(*source_p) && is(*targ_p, umode::SERVICE))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_ISCHANSERVICE),
|
2016-08-18 07:33:38 +02:00
|
|
|
me.name, source_p->name, targ_p->name, chptr->name.c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_DEL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = targ_p->id;
|
2014-05-29 16:22:58 +02:00
|
|
|
mode_changes[mode_count++].arg = targ_p->name;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
mstptr->flags &= ~CHANOP;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::voice(client::client *source_p, chan *chptr,
|
2007-01-25 07:40:21 +01:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-18 07:33:38 +02:00
|
|
|
membership *mstptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
const char *opnick;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *targ_p;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2012-06-19 00:33:29 +02:00
|
|
|
if(!allow_mode_change(source_p, chptr, alevel, errors, c))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if((dir == MODE_QUERY) || parc <= *parn)
|
|
|
|
return;
|
|
|
|
|
|
|
|
opnick = parv[(*parn)];
|
|
|
|
(*parn)++;
|
|
|
|
|
|
|
|
/* empty nick */
|
|
|
|
if(EmptyString(opnick))
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
mstptr = get(chptr->members, *targ_p, std::nothrow);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(mstptr == NULL)
|
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!(*errors & SM_ERR_NOTONCHANNEL) && my(*source_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
|
2016-08-18 07:33:38 +02:00
|
|
|
form_str(ERR_USERNOTINCHANNEL), opnick, chptr->name.c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
*errors |= SM_ERR_NOTONCHANNEL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && (++mode_limit > MAXPARAMS))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if(dir == MODE_ADD)
|
|
|
|
{
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_ADD;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = targ_p->id;
|
2014-05-29 16:22:58 +02:00
|
|
|
mode_changes[mode_count++].arg = targ_p->name;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
mstptr->flags |= VOICE;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mode_changes[mode_count].letter = 'v';
|
|
|
|
mode_changes[mode_count].dir = MODE_DEL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = targ_p->id;
|
2014-05-29 16:22:58 +02:00
|
|
|
mode_changes[mode_count++].arg = targ_p->name;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
mstptr->flags &= ~VOICE;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::limit(client::client *source_p, chan *chptr,
|
2007-01-25 07:40:21 +01:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
const char *lstr;
|
|
|
|
static char limitstr[30];
|
|
|
|
int limit;
|
|
|
|
|
2012-06-19 00:33:29 +02:00
|
|
|
if(!allow_mode_change(source_p, chptr, alevel, errors, c))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if(dir == MODE_QUERY)
|
|
|
|
return;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
|
2008-06-25 19:27:30 +02:00
|
|
|
return;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
if((dir == MODE_ADD) && parc > *parn)
|
|
|
|
{
|
|
|
|
lstr = parv[(*parn)];
|
|
|
|
(*parn)++;
|
|
|
|
|
|
|
|
if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
|
|
|
|
return;
|
|
|
|
|
2016-02-10 02:25:32 +01:00
|
|
|
sprintf(limitstr, "%d", limit);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_ADD;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = limitstr;
|
|
|
|
|
|
|
|
chptr->mode.limit = limit;
|
|
|
|
}
|
|
|
|
else if(dir == MODE_DEL)
|
|
|
|
{
|
|
|
|
if(!chptr->mode.limit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
chptr->mode.limit = 0;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_DEL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::throttle(client::client *source_p, chan *chptr,
|
2007-01-25 07:40:21 +01:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
int joins = 0, timeslice = 0;
|
|
|
|
|
2012-06-19 00:33:29 +02:00
|
|
|
if(!allow_mode_change(source_p, chptr, alevel, errors, c))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if(dir == MODE_QUERY)
|
|
|
|
return;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
|
2008-06-25 19:27:30 +02:00
|
|
|
return;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
if((dir == MODE_ADD) && parc > *parn)
|
|
|
|
{
|
2016-01-06 02:06:05 +01:00
|
|
|
if (sscanf(parv[(*parn)], "%d:%d", &joins, ×lice) < 2)
|
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-01-06 02:02:44 +01:00
|
|
|
if(joins <= 0 || timeslice <= 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_ADD;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = parv[(*parn)];
|
|
|
|
|
|
|
|
(*parn)++;
|
|
|
|
|
|
|
|
chptr->mode.join_num = joins;
|
|
|
|
chptr->mode.join_time = timeslice;
|
|
|
|
}
|
|
|
|
else if(dir == MODE_DEL)
|
|
|
|
{
|
|
|
|
if(!chptr->mode.join_num)
|
|
|
|
return;
|
|
|
|
|
|
|
|
chptr->mode.join_num = 0;
|
|
|
|
chptr->mode.join_time = 0;
|
|
|
|
chptr->join_count = 0;
|
|
|
|
chptr->join_delta = 0;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_DEL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::forward(client::client *source_p, chan *chptr,
|
2007-01-25 07:40:21 +01:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
const char *forward;
|
|
|
|
|
2011-09-25 16:22:29 +02:00
|
|
|
/* if +f is disabled, ignore local attempts to set it */
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!ConfigChannel.use_forward && my(*source_p) &&
|
2011-09-25 16:22:29 +02:00
|
|
|
(dir == MODE_ADD) && (parc > *parn))
|
|
|
|
return;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn))
|
|
|
|
{
|
|
|
|
if (!(*errors & SM_ERR_RPL_F))
|
|
|
|
{
|
|
|
|
if (*chptr->mode.forward == '\0')
|
2016-08-18 07:33:38 +02:00
|
|
|
sendto_one_notice(source_p, ":%s has no forward channel", chptr->name.c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
else
|
2016-08-18 07:33:38 +02:00
|
|
|
sendto_one_notice(source_p, ":%s forward channel is %s", chptr->name.c_str(), chptr->mode.forward);
|
2007-01-25 07:40:21 +01:00
|
|
|
*errors |= SM_ERR_RPL_F;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef FORWARD_OPERONLY
|
2012-06-19 00:33:29 +02:00
|
|
|
if(!allow_mode_change(source_p, chptr, alevel, errors, c))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
#else
|
2016-08-24 00:25:09 +02:00
|
|
|
if(!is(*source_p, umode::OPER) && !is_server(*source_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if(!(*errors & SM_ERR_NOPRIVS))
|
|
|
|
sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
|
|
|
|
*errors |= SM_ERR_NOPRIVS;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
|
2008-06-25 19:27:30 +02:00
|
|
|
return;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
if(dir == MODE_ADD && parc > *parn)
|
|
|
|
{
|
|
|
|
forward = parv[(*parn)];
|
|
|
|
(*parn)++;
|
|
|
|
|
|
|
|
if(EmptyString(forward))
|
|
|
|
return;
|
2011-12-10 00:40:07 +01:00
|
|
|
|
|
|
|
if(!check_forward(source_p, chptr, forward))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2008-04-20 06:40:40 +02:00
|
|
|
rb_strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward));
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_ADD;
|
2011-09-25 16:22:29 +02:00
|
|
|
mode_changes[mode_count].mems =
|
|
|
|
ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS;
|
2007-01-25 07:40:21 +01:00
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = forward;
|
|
|
|
}
|
|
|
|
else if(dir == MODE_DEL)
|
|
|
|
{
|
|
|
|
if(!(*chptr->mode.forward))
|
|
|
|
return;
|
|
|
|
|
|
|
|
*chptr->mode.forward = '\0';
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_DEL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
mode::functor::key(client::client *source_p, chan *chptr,
|
2007-01-25 07:40:21 +01:00
|
|
|
int alevel, int parc, int *parn,
|
2016-08-17 05:01:20 +02:00
|
|
|
const char **parv, int *errors, int dir, char c, type mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
char *key;
|
|
|
|
|
2012-06-19 00:33:29 +02:00
|
|
|
if(!allow_mode_change(source_p, chptr, alevel, errors, c))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if(dir == MODE_QUERY)
|
|
|
|
return;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
|
2008-06-25 19:27:30 +02:00
|
|
|
return;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
if((dir == MODE_ADD) && parc > *parn)
|
|
|
|
{
|
|
|
|
key = LOCAL_COPY(parv[(*parn)]);
|
|
|
|
(*parn)++;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
fix_key(key);
|
|
|
|
else
|
|
|
|
fix_key_remote(key);
|
|
|
|
|
|
|
|
if(EmptyString(key))
|
|
|
|
return;
|
|
|
|
|
|
|
|
s_assert(key[0] != ' ');
|
2008-04-20 06:40:40 +02:00
|
|
|
rb_strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_ADD;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = chptr->mode.key;
|
|
|
|
}
|
|
|
|
else if(dir == MODE_DEL)
|
|
|
|
{
|
|
|
|
static char splat[] = "*";
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(parc > *parn)
|
|
|
|
(*parn)++;
|
|
|
|
|
|
|
|
if(!(*chptr->mode.key))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* hack time. when we get a +k-k mode, the +k arg is
|
|
|
|
* chptr->mode.key, which the -k sets to \0, so hunt for a
|
|
|
|
* +k when we get a -k, and set the arg to splat. --anfl
|
|
|
|
*/
|
|
|
|
for(i = 0; i < mode_count; i++)
|
|
|
|
{
|
|
|
|
if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD)
|
|
|
|
mode_changes[i].arg = splat;
|
|
|
|
}
|
|
|
|
|
|
|
|
*chptr->mode.key = 0;
|
|
|
|
|
|
|
|
mode_changes[mode_count].letter = c;
|
|
|
|
mode_changes[mode_count].dir = MODE_DEL;
|
|
|
|
mode_changes[mode_count].mems = ALL_MEMBERS;
|
|
|
|
mode_changes[mode_count].id = NULL;
|
|
|
|
mode_changes[mode_count++].arg = "*";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set_channel_mode()
|
|
|
|
*
|
|
|
|
* inputs - client, source, channel, membership pointer, params
|
2014-03-03 05:25:47 +01:00
|
|
|
* output -
|
2007-01-25 07:40:21 +01:00
|
|
|
* side effects - channel modes/memberships are changed, MODE is issued
|
|
|
|
*
|
|
|
|
* Extensively modified to be hotpluggable, 03/09/06 -- nenolod
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
chan::set_channel_mode(client::client *client_p, client::client *source_p,
|
2016-08-18 07:33:38 +02:00
|
|
|
chan *chptr, membership *msptr, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
static char modebuf[BUFSIZE];
|
|
|
|
static char parabuf[BUFSIZE];
|
|
|
|
char *mbuf;
|
|
|
|
char *pbuf;
|
|
|
|
int cur_len, mlen, paralen, paracount, arglen, len;
|
|
|
|
int i, j, flags;
|
2015-12-10 08:00:32 +01:00
|
|
|
int dir = MODE_QUERY;
|
2007-01-25 07:40:21 +01:00
|
|
|
int parn = 1;
|
|
|
|
int errors = 0;
|
|
|
|
int alevel;
|
|
|
|
const char *ml = parv[0];
|
|
|
|
char c;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *fakesource_p;
|
2015-12-10 08:00:32 +01:00
|
|
|
int reauthorized = 0; /* if we change from MODE_QUERY to MODE_ADD/MODE_DEL, then reauth once, ugly but it works */
|
2016-01-13 23:34:27 +01:00
|
|
|
int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS };
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2011-08-13 02:33:10 +02:00
|
|
|
removed_mask_pos = 0;
|
2007-01-25 07:40:21 +01:00
|
|
|
mode_count = 0;
|
|
|
|
mode_limit = 0;
|
2008-06-25 19:27:30 +02:00
|
|
|
mode_limit_simple = 0;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* Hide connecting server on netburst -- jilles */
|
2016-08-23 04:33:36 +02:00
|
|
|
if (ConfigServerHide.flatten_links && is_server(*source_p) && !has_id(source_p) && !has_sent_eob(*source_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
fakesource_p = &me;
|
|
|
|
else
|
|
|
|
fakesource_p = source_p;
|
|
|
|
|
2016-01-14 05:16:44 +01:00
|
|
|
alevel = get_channel_access(source_p, chptr, msptr, dir, reconstruct_parv(parc, parv));
|
2015-12-10 08:00:32 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
for(; (c = *ml) != 0; ml++)
|
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case '+':
|
|
|
|
dir = MODE_ADD;
|
2015-12-10 08:00:32 +01:00
|
|
|
if (!reauthorized)
|
|
|
|
{
|
2016-01-14 05:16:44 +01:00
|
|
|
alevel = get_channel_access(source_p, chptr, msptr, dir, reconstruct_parv(parc, parv));
|
2015-12-10 08:00:32 +01:00
|
|
|
reauthorized = 1;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
dir = MODE_DEL;
|
2015-12-10 08:00:32 +01:00
|
|
|
if (!reauthorized)
|
|
|
|
{
|
2016-01-14 05:16:44 +01:00
|
|
|
alevel = get_channel_access(source_p, chptr, msptr, dir, reconstruct_parv(parc, parv));
|
2015-12-10 08:00:32 +01:00
|
|
|
reauthorized = 1;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
dir = MODE_QUERY;
|
|
|
|
break;
|
|
|
|
default:
|
2016-08-17 05:01:20 +02:00
|
|
|
mode::table[uint8_t(c)].set_func(fakesource_p, chptr, alevel, parc, &parn, parv, &errors, dir, c, mode::table[uint8_t(c)].type);
|
2007-01-25 07:40:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bail out if we have nothing to do... */
|
|
|
|
if(!mode_count)
|
|
|
|
return;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_server(*source_p))
|
2016-08-18 07:33:38 +02:00
|
|
|
mlen = sprintf(modebuf, ":%s MODE %s ", fakesource_p->name, chptr->name.c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
else
|
2016-02-10 02:25:32 +01:00
|
|
|
mlen = sprintf(modebuf, ":%s!%s@%s MODE %s ",
|
2007-01-25 07:40:21 +01:00
|
|
|
source_p->name, source_p->username,
|
2016-08-18 07:33:38 +02:00
|
|
|
source_p->host, chptr->name.c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-02-06 16:50:17 +01:00
|
|
|
for(j = 0; j < 3; j++)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-02-06 16:50:17 +01:00
|
|
|
flags = flags_list[j];
|
2007-01-25 07:40:21 +01:00
|
|
|
cur_len = mlen;
|
|
|
|
mbuf = modebuf + mlen;
|
|
|
|
pbuf = parabuf;
|
|
|
|
parabuf[0] = '\0';
|
|
|
|
paracount = paralen = 0;
|
|
|
|
dir = MODE_QUERY;
|
|
|
|
|
|
|
|
for(i = 0; i < mode_count; i++)
|
|
|
|
{
|
|
|
|
if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(mode_changes[i].arg != NULL)
|
|
|
|
{
|
|
|
|
arglen = strlen(mode_changes[i].arg);
|
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
if(arglen > mode::BUFLEN - 5)
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
arglen = 0;
|
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
/* if we're creeping over mode::MAXPARAMSSERV, or over
|
2007-01-25 07:40:21 +01:00
|
|
|
* bufsize (4 == +/-,modechar,two spaces) send now.
|
|
|
|
*/
|
|
|
|
if(mode_changes[i].arg != NULL &&
|
2016-08-17 05:01:20 +02:00
|
|
|
((paracount == mode::MAXPARAMSSERV) ||
|
2007-01-25 07:40:21 +01:00
|
|
|
((cur_len + paralen + arglen + 4) > (BUFSIZE - 3))))
|
|
|
|
{
|
|
|
|
*mbuf = '\0';
|
|
|
|
|
|
|
|
if(cur_len > mlen)
|
|
|
|
sendto_channel_local(flags, chptr, "%s %s", modebuf,
|
|
|
|
parabuf);
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
paracount = paralen = 0;
|
|
|
|
cur_len = mlen;
|
|
|
|
mbuf = modebuf + mlen;
|
|
|
|
pbuf = parabuf;
|
|
|
|
parabuf[0] = '\0';
|
|
|
|
dir = MODE_QUERY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dir != mode_changes[i].dir)
|
|
|
|
{
|
|
|
|
*mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
|
|
|
|
cur_len++;
|
|
|
|
dir = mode_changes[i].dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
*mbuf++ = mode_changes[i].letter;
|
|
|
|
cur_len++;
|
|
|
|
|
|
|
|
if(mode_changes[i].arg != NULL)
|
|
|
|
{
|
|
|
|
paracount++;
|
2016-02-10 02:25:32 +01:00
|
|
|
len = sprintf(pbuf, "%s ", mode_changes[i].arg);
|
2007-01-25 07:40:21 +01:00
|
|
|
pbuf += len;
|
|
|
|
paralen += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(paralen && parabuf[paralen - 1] == ' ')
|
|
|
|
parabuf[paralen - 1] = '\0';
|
|
|
|
|
|
|
|
*mbuf = '\0';
|
|
|
|
if(cur_len > mlen)
|
|
|
|
sendto_channel_local(flags, chptr, "%s %s", modebuf, parabuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only propagate modes originating locally, or if we're hubbing */
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) || rb_dlink_list_length(&serv_list) > 1)
|
2007-01-25 07:40:21 +01:00
|
|
|
send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count);
|
|
|
|
}
|
2010-03-08 06:13:39 +01:00
|
|
|
|
|
|
|
/* set_channel_mlock()
|
|
|
|
*
|
|
|
|
* inputs - client, source, channel, params
|
2014-03-03 05:25:47 +01:00
|
|
|
* output -
|
2010-03-08 06:13:39 +01:00
|
|
|
* side effects - channel mlock is changed / MLOCK is propagated
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
chan::set_channel_mlock(client::client *client_p, client::client *source_p,
|
2016-08-18 07:33:38 +02:00
|
|
|
chan *chptr, const char *newmlock, bool propagate)
|
2010-03-08 06:13:39 +01:00
|
|
|
{
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->mode_lock = newmlock?: std::string{};
|
2010-03-08 06:13:39 +01:00
|
|
|
|
2010-08-24 03:22:59 +02:00
|
|
|
if (propagate)
|
|
|
|
{
|
|
|
|
sendto_server(client_p, NULL, CAP_TS6 | CAP_MLOCK, NOCAPS, ":%s MLOCK %ld %s :%s",
|
2016-08-18 07:33:38 +02:00
|
|
|
source_p->id, (long) chptr->channelts, chptr->name.c_str(),
|
|
|
|
chptr->mode_lock.c_str());
|
2010-08-24 03:22:59 +02:00
|
|
|
}
|
2010-03-08 06:13:39 +01:00
|
|
|
}
|
2016-08-13 05:05:54 +02:00
|
|
|
|
|
|
|
} // namespace ircd
|