]> jfr.im git - irc/rqf/shadowircd.git/blob - src/snomask.c
Move cmode +N to cmode +d, so that extensions/m_roleplay can retain cmode +N and...
[irc/rqf/shadowircd.git] / src / snomask.c
1 /*
2 * charybdis: An advanced ircd.
3 * snomask.c: Management for user server-notice masks.
4 *
5 * Copyright (c) 2006 William Pitcock <nenolod@nenolod.net>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * $Id$
34 */
35
36 #include "stdinc.h"
37 #include "client.h"
38 #include "snomask.h"
39
40 /* *INDENT-OFF* */
41 int snomask_modes[256] = {
42 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
43 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
44 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
45 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
46 0, /* @ */
47 0, /* A */
48 0, /* B */
49 SNO_CCONNEXT, /* C */
50 0, /* D */
51 0, /* E */
52 0, /* F */
53 0, /* G */
54 0, /* H */
55 0, /* I */
56 0, /* J */
57 0, /* K */
58 0, /* L */
59 0, /* M */
60 0, /* N */
61 0, /* O */
62 0, /* P */
63 0, /* Q */
64 0, /* R */
65 0, /* S */
66 0, /* T */
67 0, /* U */
68 0, /* V */
69 0, /* W */
70 0, /* X */
71 0, /* Y */
72 SNO_OPERSPY, /* Z */
73 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
74 0, /* a */
75 SNO_BOTS, /* b */
76 SNO_CCONN, /* c */
77 SNO_DEBUG, /* d */
78 0, /* e */
79 SNO_FULL, /* f */
80 0, /* g */
81 0, /* h */
82 0, /* i */
83 0, /* j */
84 SNO_SKILL, /* k */
85 0, /* l */
86 0, /* m */
87 SNO_NCHANGE, /* n */
88 0, /* o */
89 0, /* p */
90 0, /* q */
91 SNO_REJ, /* r */
92 SNO_GENERAL, /* s */
93 0, /* t */
94 SNO_UNAUTH, /* u */
95 0, /* v */
96 0, /* w */
97 SNO_EXTERNAL, /* x */
98 SNO_SPY, /* y */
99 0, /* z */
100 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
101 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
102 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
103 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
104 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
105 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
106 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
107 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
108 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
109 };
110 /* *INDENT-ON* */
111
112 static char snobuf[BUFSIZE];
113
114 /*
115 * construct_snobuf
116 *
117 * inputs - client to generate snomask string for
118 * outputs - snomask string of client
119 * side effects - NONE
120 */
121 char *
122 construct_snobuf(unsigned int val)
123 {
124 int i;
125 char *ptr = snobuf;
126
127 *ptr = '\0';
128 *ptr++ = '+';
129
130 for (i = 0; i < 128; i++)
131 if (snomask_modes[i] && (val & snomask_modes[i]))
132 *ptr++ = (char) i;
133
134 *ptr++ = '\0';
135
136 return snobuf;
137 }
138
139 /*
140 * parse_snobuf_to_mask
141 *
142 * inputs - value to alter bitmask for, snomask itself
143 * outputs - replacement bitmask to set
144 * side effects - NONE
145 */
146 unsigned int
147 parse_snobuf_to_mask(unsigned int val, const char *sno)
148 {
149 const char *p;
150 int what = SNO_ADD;
151
152 if (sno == NULL)
153 return val;
154
155 for (p = sno; *p != '\0'; p++)
156 {
157 switch(*p)
158 {
159 case '+':
160 what = SNO_ADD;
161 break;
162 case '-':
163 what = SNO_DEL;
164 break;
165 default:
166 if (what == SNO_ADD)
167 val |= snomask_modes[(unsigned char) *p];
168 else if (what == SNO_DEL)
169 val &= ~snomask_modes[(unsigned char) *p];
170
171 break;
172 }
173 }
174
175 return val;
176 }
177
178 /*
179 * find_snomask_slot
180 *
181 * inputs - NONE
182 * outputs - an available umode bitmask or
183 * 0 if no umodes are available
184 * side effects - NONE
185 */
186 unsigned int
187 find_snomask_slot(void)
188 {
189 unsigned int all_umodes = 0, my_umode = 0, i;
190
191 for (i = 0; i < 128; i++)
192 all_umodes |= snomask_modes[i];
193
194 for (my_umode = 1; my_umode && (all_umodes & my_umode);
195 my_umode <<= 1);
196
197 return my_umode;
198 }
199