0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 15:00:51 +01:00
construct/extensions/extb_usermode.c
Jilles Tjoelker 63dd387b13 Require all modes to be set for + part in $m extban.
This is like the - part requiring none of the modes to be set and is more
useful because the old behaviour can be emulated with multiple bans.
2012-02-04 15:02:26 +01:00

79 lines
1.4 KiB
C

/*
* Usermode extban type: bans all users with a specific usermode
* -- nenolod
*/
#include "stdinc.h"
#include "modules.h"
#include "hook.h"
#include "client.h"
#include "ircd.h"
#include "send.h"
#include "hash.h"
#include "s_conf.h"
#include "s_user.h"
#include "s_serv.h"
#include "numeric.h"
static int _modinit(void);
static void _moddeinit(void);
static int eb_usermode(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type);
DECLARE_MODULE_AV1(extb_usermode, _modinit, _moddeinit, NULL, NULL, NULL, "$Revision: 1299 $");
static int
_modinit(void)
{
extban_table['m'] = eb_usermode;
return 0;
}
static void
_moddeinit(void)
{
extban_table['m'] = NULL;
}
static int eb_usermode(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type)
{
int dir = MODE_ADD;
unsigned int modes_ack = 0, modes_nak = 0;
const char *p;
(void)chptr;
/* $m must have a specified mode */
if (data == NULL)
return EXTBAN_INVALID;
for (p = data; *p != '\0'; p++)
{
switch (*p)
{
case '+':
dir = MODE_ADD;
break;
case '-':
dir = MODE_DEL;
break;
default:
switch (dir)
{
case MODE_DEL:
modes_nak |= user_modes[(unsigned char) *p];
break;
case MODE_ADD:
default:
modes_ack |= user_modes[(unsigned char) *p];
break;
}
break;
}
}
return ((client_p->umodes & modes_ack) == modes_ack &&
!(client_p->umodes & modes_nak)) ?
EXTBAN_MATCH : EXTBAN_NOMATCH;
}