]> jfr.im git - solanum.git/blob - extensions/extb_usermode.c
modules: Add AV2 descriptions to all m_u* modules
[solanum.git] / extensions / extb_usermode.c
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
18 static int _modinit(void);
19 static void _moddeinit(void);
20 static int eb_usermode(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type);
21 static const char extb_desc[] = "Usermode ($m) extban type";
22
23 DECLARE_MODULE_AV2(extb_usermode, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
24
25 static int
26 _modinit(void)
27 {
28 extban_table['m'] = eb_usermode;
29
30 return 0;
31 }
32
33 static void
34 _moddeinit(void)
35 {
36 extban_table['m'] = NULL;
37 }
38
39 static 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)
50 return EXTBAN_INVALID;
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
77 return ((client_p->umodes & modes_ack) == modes_ack &&
78 !(client_p->umodes & modes_nak)) ?
79 EXTBAN_MATCH : EXTBAN_NOMATCH;
80 }