]> jfr.im git - solanum.git/blame - extensions/extb_usermode.c
m_stats: z: remove unnecessary casting and fix format strings
[solanum.git] / extensions / extb_usermode.c
CommitLineData
0b18e32c
AC
1/*
2 * Usermode extban type: bans all users with a specific usermode
3 * -- nenolod
4 */
5
6#include "stdinc.h"
7#include "modules.h"
8#include "hook.h"
9#include "client.h"
10#include "ircd.h"
11#include "send.h"
12#include "hash.h"
13#include "s_conf.h"
14#include "s_user.h"
15#include "s_serv.h"
16#include "numeric.h"
17
eeabf33a
EM
18static const char extb_desc[] = "Usermode ($m) extban type";
19
0b18e32c
AC
20static int _modinit(void);
21static void _moddeinit(void);
22static int eb_usermode(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type);
23
c81afd15 24DECLARE_MODULE_AV2(extb_usermode, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
0b18e32c
AC
25
26static int
27_modinit(void)
28{
fef6857e 29 extban_table['u'] = eb_usermode;
0b18e32c
AC
30
31 return 0;
32}
33
34static void
35_moddeinit(void)
36{
fef6857e 37 extban_table['u'] = NULL;
0b18e32c
AC
38}
39
40static int eb_usermode(const char *data, struct Client *client_p,
41 struct Channel *chptr, long mode_type)
42{
43 int dir = MODE_ADD;
44 unsigned int modes_ack = 0, modes_nak = 0;
45 const char *p;
46
47 (void)chptr;
48
49 /* $m must have a specified mode */
50 if (data == NULL)
11f2e787 51 return EXTBAN_INVALID;
0b18e32c
AC
52
53 for (p = data; *p != '\0'; p++)
54 {
55 switch (*p)
56 {
57 case '+':
58 dir = MODE_ADD;
59 break;
60 case '-':
61 dir = MODE_DEL;
62 break;
63 default:
64 switch (dir)
65 {
66 case MODE_DEL:
67 modes_nak |= user_modes[(unsigned char) *p];
68 break;
69 case MODE_ADD:
70 default:
71 modes_ack |= user_modes[(unsigned char) *p];
72 break;
73 }
74 break;
75 }
76 }
77
63dd387b
JT
78 return ((client_p->umodes & modes_ack) == modes_ack &&
79 !(client_p->umodes & modes_nak)) ?
80 EXTBAN_MATCH : EXTBAN_NOMATCH;
0b18e32c 81}