]> jfr.im git - solanum.git/blame - extensions/extb_usermode.c
modules: Add AV2 descriptions to all m_u* modules
[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
18static int _modinit(void);
19static void _moddeinit(void);
20static int eb_usermode(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type);
c81afd15 21static const char extb_desc[] = "Usermode ($m) extban type";
0b18e32c 22
c81afd15 23DECLARE_MODULE_AV2(extb_usermode, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
0b18e32c
AC
24
25static int
26_modinit(void)
27{
28 extban_table['m'] = eb_usermode;
29
30 return 0;
31}
32
33static void
34_moddeinit(void)
35{
36 extban_table['m'] = NULL;
37}
38
39static int eb_usermode(const char *data, struct Client *client_p,
40 struct Channel *chptr, long mode_type)
41{
42 int dir = MODE_ADD;
43 unsigned int modes_ack = 0, modes_nak = 0;
44 const char *p;
45
46 (void)chptr;
47
48 /* $m must have a specified mode */
49 if (data == NULL)
11f2e787 50 return EXTBAN_INVALID;
0b18e32c
AC
51
52 for (p = data; *p != '\0'; p++)
53 {
54 switch (*p)
55 {
56 case '+':
57 dir = MODE_ADD;
58 break;
59 case '-':
60 dir = MODE_DEL;
61 break;
62 default:
63 switch (dir)
64 {
65 case MODE_DEL:
66 modes_nak |= user_modes[(unsigned char) *p];
67 break;
68 case MODE_ADD:
69 default:
70 modes_ack |= user_modes[(unsigned char) *p];
71 break;
72 }
73 break;
74 }
75 }
76
63dd387b
JT
77 return ((client_p->umodes & modes_ack) == modes_ack &&
78 !(client_p->umodes & modes_nak)) ?
79 EXTBAN_MATCH : EXTBAN_NOMATCH;
0b18e32c 80}