1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
7925 |
* Copyright (c) 1997-2017 ircd-hybrid development team |
5 |
adx |
30 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
michael |
4564 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2916 |
/*! \file channel_mode.c |
23 |
|
|
* \brief Controls modes on channels. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
michael |
1011 |
#include "list.h" |
29 |
adx |
30 |
#include "channel.h" |
30 |
|
|
#include "channel_mode.h" |
31 |
|
|
#include "client.h" |
32 |
michael |
1632 |
#include "conf.h" |
33 |
michael |
371 |
#include "hostmask.h" |
34 |
adx |
30 |
#include "irc_string.h" |
35 |
|
|
#include "ircd.h" |
36 |
|
|
#include "numeric.h" |
37 |
michael |
3347 |
#include "server.h" |
38 |
adx |
30 |
#include "send.h" |
39 |
|
|
#include "memory.h" |
40 |
michael |
1654 |
#include "mempool.h" |
41 |
michael |
1243 |
#include "parse.h" |
42 |
adx |
30 |
|
43 |
|
|
|
44 |
michael |
388 |
static char nuh_mask[MAXPARA][IRCD_BUFSIZE]; |
45 |
adx |
30 |
static struct ChModeChange mode_changes[IRCD_BUFSIZE]; |
46 |
michael |
3057 |
static unsigned int mode_count; |
47 |
|
|
static unsigned int mode_limit; /* number of modes set other than simple */ |
48 |
|
|
static unsigned int simple_modes_mask; /* bit mask of simple modes already set */ |
49 |
michael |
1654 |
extern mp_pool_t *ban_pool; |
50 |
adx |
30 |
|
51 |
michael |
3149 |
const struct mode_letter chan_modes[] = |
52 |
|
|
{ |
53 |
|
|
{ MODE_NOCTRL, 'c' }, |
54 |
|
|
{ MODE_INVITEONLY, 'i' }, |
55 |
|
|
{ MODE_MODERATED, 'm' }, |
56 |
|
|
{ MODE_NOPRIVMSGS, 'n' }, |
57 |
|
|
{ MODE_PRIVATE, 'p' }, |
58 |
|
|
{ MODE_REGISTERED, 'r' }, |
59 |
|
|
{ MODE_SECRET, 's' }, |
60 |
|
|
{ MODE_TOPICLIMIT, 't' }, |
61 |
michael |
8039 |
{ MODE_HIDEBMASKS, 'u' }, |
62 |
michael |
5463 |
{ MODE_NOCTCP, 'C' }, |
63 |
michael |
3149 |
{ MODE_MODREG, 'M' }, |
64 |
|
|
{ MODE_OPERONLY, 'O' }, |
65 |
|
|
{ MODE_REGONLY, 'R' }, |
66 |
|
|
{ MODE_SSLONLY, 'S' }, |
67 |
michael |
6918 |
{ MODE_NONOTICE, 'T' }, |
68 |
michael |
3149 |
{ 0, '\0' } |
69 |
|
|
}; |
70 |
adx |
30 |
|
71 |
michael |
3149 |
|
72 |
adx |
30 |
/* check_string() |
73 |
|
|
* |
74 |
|
|
* inputs - string to check |
75 |
|
|
* output - pointer to modified string |
76 |
|
|
* side effects - Fixes a string so that the first white space found |
77 |
|
|
* becomes an end of string marker (`\0`). |
78 |
|
|
* returns the 'fixed' string or "*" if the string |
79 |
|
|
* was NULL length or a NULL pointer. |
80 |
|
|
*/ |
81 |
|
|
static char * |
82 |
|
|
check_string(char *s) |
83 |
|
|
{ |
84 |
michael |
4834 |
char *const str = s; |
85 |
adx |
30 |
static char star[] = "*"; |
86 |
|
|
|
87 |
michael |
1772 |
if (EmptyString(str)) |
88 |
michael |
593 |
return star; |
89 |
adx |
30 |
|
90 |
|
|
for (; *s; ++s) |
91 |
|
|
{ |
92 |
|
|
if (IsSpace(*s)) |
93 |
|
|
{ |
94 |
|
|
*s = '\0'; |
95 |
|
|
break; |
96 |
|
|
} |
97 |
|
|
} |
98 |
|
|
|
99 |
michael |
1772 |
return EmptyString(str) ? star : str; |
100 |
adx |
30 |
} |
101 |
|
|
|
102 |
|
|
/* |
103 |
michael |
5582 |
* Ban functions to work with mode +b/e/I |
104 |
adx |
30 |
*/ |
105 |
michael |
2892 |
/* add the specified ID to the channel. |
106 |
|
|
* -is 8/9/00 |
107 |
adx |
30 |
*/ |
108 |
|
|
|
109 |
|
|
int |
110 |
michael |
3044 |
add_id(struct Client *client_p, struct Channel *chptr, char *banid, unsigned int type) |
111 |
adx |
30 |
{ |
112 |
michael |
7796 |
dlink_list *list; |
113 |
|
|
dlink_node *node; |
114 |
michael |
3215 |
char name[NICKLEN + 1] = ""; |
115 |
|
|
char user[USERLEN + 1] = ""; |
116 |
|
|
char host[HOSTLEN + 1] = ""; |
117 |
michael |
593 |
struct split_nuh_item nuh; |
118 |
adx |
30 |
|
119 |
michael |
3374 |
/* Don't let local clients overflow the b/e/I lists */ |
120 |
adx |
30 |
if (MyClient(client_p)) |
121 |
|
|
{ |
122 |
michael |
3699 |
unsigned int num_mask = dlink_list_length(&chptr->banlist) + |
123 |
|
|
dlink_list_length(&chptr->exceptlist) + |
124 |
|
|
dlink_list_length(&chptr->invexlist); |
125 |
adx |
30 |
|
126 |
|
|
if (num_mask >= ConfigChannel.max_bans) |
127 |
|
|
{ |
128 |
michael |
4617 |
sendto_one_numeric(client_p, &me, ERR_BANLISTFULL, chptr->name, banid); |
129 |
adx |
30 |
return 0; |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
collapse(banid); |
133 |
|
|
} |
134 |
|
|
|
135 |
michael |
593 |
nuh.nuhmask = check_string(banid); |
136 |
|
|
nuh.nickptr = name; |
137 |
|
|
nuh.userptr = user; |
138 |
|
|
nuh.hostptr = host; |
139 |
adx |
30 |
|
140 |
michael |
593 |
nuh.nicksize = sizeof(name); |
141 |
|
|
nuh.usersize = sizeof(user); |
142 |
|
|
nuh.hostsize = sizeof(host); |
143 |
|
|
|
144 |
|
|
split_nuh(&nuh); |
145 |
|
|
|
146 |
adx |
30 |
/* |
147 |
michael |
593 |
* Re-assemble a new n!u@h and print it back to banid for sending |
148 |
adx |
30 |
* the mode to the channel. |
149 |
|
|
*/ |
150 |
michael |
7796 |
size_t len = snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host); |
151 |
adx |
30 |
|
152 |
|
|
switch (type) |
153 |
|
|
{ |
154 |
|
|
case CHFL_BAN: |
155 |
|
|
list = &chptr->banlist; |
156 |
michael |
7763 |
clear_ban_cache_list(&chptr->locmembers); |
157 |
adx |
30 |
break; |
158 |
|
|
case CHFL_EXCEPTION: |
159 |
|
|
list = &chptr->exceptlist; |
160 |
michael |
7763 |
clear_ban_cache_list(&chptr->locmembers); |
161 |
adx |
30 |
break; |
162 |
|
|
case CHFL_INVEX: |
163 |
|
|
list = &chptr->invexlist; |
164 |
|
|
break; |
165 |
|
|
default: |
166 |
michael |
7796 |
list = NULL; /* Let it crash */ |
167 |
adx |
30 |
} |
168 |
|
|
|
169 |
michael |
4801 |
DLINK_FOREACH(node, list->head) |
170 |
adx |
30 |
{ |
171 |
michael |
7796 |
const struct Ban *ban = node->data; |
172 |
michael |
2892 |
|
173 |
michael |
4816 |
if (!irccmp(ban->name, name) && |
174 |
|
|
!irccmp(ban->user, user) && |
175 |
|
|
!irccmp(ban->host, host)) |
176 |
adx |
30 |
return 0; |
177 |
|
|
} |
178 |
|
|
|
179 |
michael |
7796 |
struct Ban *ban = mp_pool_get(ban_pool); |
180 |
michael |
4816 |
ban->when = CurrentTime; |
181 |
|
|
ban->len = len - 2; /* -2 for ! + @ */ |
182 |
|
|
ban->type = parse_netmask(host, &ban->addr, &ban->bits); |
183 |
michael |
5758 |
strlcpy(ban->name, name, sizeof(ban->name)); |
184 |
|
|
strlcpy(ban->user, user, sizeof(ban->user)); |
185 |
|
|
strlcpy(ban->host, host, sizeof(ban->host)); |
186 |
michael |
3699 |
|
187 |
adx |
30 |
if (IsClient(client_p)) |
188 |
michael |
5758 |
snprintf(ban->who, sizeof(ban->who), "%s!%s@%s", client_p->name, |
189 |
|
|
client_p->username, client_p->host); |
190 |
michael |
5754 |
else if (IsHidden(client_p) || ConfigServerHide.hide_servers) |
191 |
michael |
5758 |
strlcpy(ban->who, me.name, sizeof(ban->who)); |
192 |
adx |
30 |
else |
193 |
michael |
5758 |
strlcpy(ban->who, client_p->name, sizeof(ban->who)); |
194 |
adx |
30 |
|
195 |
michael |
4816 |
dlinkAdd(ban, &ban->node, list); |
196 |
adx |
30 |
|
197 |
|
|
return 1; |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
/* |
201 |
|
|
* inputs - pointer to channel |
202 |
|
|
* - pointer to ban id |
203 |
|
|
* - type of ban, i.e. ban, exception, invex |
204 |
|
|
* output - 0 for failure, 1 for success |
205 |
|
|
* side effects - |
206 |
|
|
*/ |
207 |
|
|
static int |
208 |
michael |
3044 |
del_id(struct Channel *chptr, char *banid, unsigned int type) |
209 |
adx |
30 |
{ |
210 |
michael |
7796 |
dlink_list *list; |
211 |
|
|
dlink_node *node; |
212 |
michael |
3215 |
char name[NICKLEN + 1] = ""; |
213 |
|
|
char user[USERLEN + 1] = ""; |
214 |
|
|
char host[HOSTLEN + 1] = ""; |
215 |
michael |
593 |
struct split_nuh_item nuh; |
216 |
adx |
30 |
|
217 |
michael |
2892 |
assert(banid); |
218 |
adx |
30 |
|
219 |
michael |
593 |
nuh.nuhmask = check_string(banid); |
220 |
|
|
nuh.nickptr = name; |
221 |
|
|
nuh.userptr = user; |
222 |
|
|
nuh.hostptr = host; |
223 |
adx |
30 |
|
224 |
michael |
593 |
nuh.nicksize = sizeof(name); |
225 |
|
|
nuh.usersize = sizeof(user); |
226 |
|
|
nuh.hostsize = sizeof(host); |
227 |
|
|
|
228 |
|
|
split_nuh(&nuh); |
229 |
|
|
|
230 |
adx |
30 |
/* |
231 |
michael |
593 |
* Re-assemble a new n!u@h and print it back to banid for sending |
232 |
adx |
30 |
* the mode to the channel. |
233 |
|
|
*/ |
234 |
michael |
4825 |
snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host); |
235 |
adx |
30 |
|
236 |
|
|
switch (type) |
237 |
|
|
{ |
238 |
|
|
case CHFL_BAN: |
239 |
|
|
list = &chptr->banlist; |
240 |
michael |
7763 |
clear_ban_cache_list(&chptr->locmembers); |
241 |
adx |
30 |
break; |
242 |
|
|
case CHFL_EXCEPTION: |
243 |
|
|
list = &chptr->exceptlist; |
244 |
michael |
7763 |
clear_ban_cache_list(&chptr->locmembers); |
245 |
adx |
30 |
break; |
246 |
|
|
case CHFL_INVEX: |
247 |
|
|
list = &chptr->invexlist; |
248 |
|
|
break; |
249 |
|
|
default: |
250 |
michael |
7796 |
list = NULL; /* Let it crash */ |
251 |
adx |
30 |
} |
252 |
|
|
|
253 |
michael |
4801 |
DLINK_FOREACH(node, list->head) |
254 |
adx |
30 |
{ |
255 |
michael |
4816 |
struct Ban *ban = node->data; |
256 |
adx |
30 |
|
257 |
michael |
4816 |
if (!irccmp(name, ban->name) && |
258 |
|
|
!irccmp(user, ban->user) && |
259 |
|
|
!irccmp(host, ban->host)) |
260 |
adx |
30 |
{ |
261 |
michael |
4816 |
remove_ban(ban, list); |
262 |
adx |
30 |
return 1; |
263 |
|
|
} |
264 |
|
|
} |
265 |
|
|
|
266 |
|
|
return 0; |
267 |
|
|
} |
268 |
|
|
|
269 |
|
|
/* channel_modes() |
270 |
|
|
* |
271 |
|
|
* inputs - pointer to channel |
272 |
|
|
* - pointer to client |
273 |
|
|
* - pointer to mode buf |
274 |
|
|
* - pointer to parameter buf |
275 |
|
|
* output - NONE |
276 |
|
|
* side effects - write the "simple" list of channel modes for channel |
277 |
|
|
* chptr onto buffer mbuf with the parameters in pbuf. |
278 |
|
|
*/ |
279 |
|
|
void |
280 |
michael |
3688 |
channel_modes(struct Channel *chptr, struct Client *client_p, char *mbuf, char *pbuf) |
281 |
adx |
30 |
{ |
282 |
|
|
*mbuf++ = '+'; |
283 |
|
|
*pbuf = '\0'; |
284 |
|
|
|
285 |
michael |
3688 |
for (const struct mode_letter *tab = chan_modes; tab->mode; ++tab) |
286 |
michael |
8043 |
if (HasCMode(chptr, tab->mode)) |
287 |
michael |
1175 |
*mbuf++ = tab->letter; |
288 |
adx |
30 |
|
289 |
|
|
if (chptr->mode.limit) |
290 |
|
|
{ |
291 |
|
|
*mbuf++ = 'l'; |
292 |
|
|
|
293 |
michael |
6360 |
if (IsServer(client_p) || IsMember(client_p, chptr)) |
294 |
michael |
7356 |
pbuf += sprintf(pbuf, "%u ", chptr->mode.limit); |
295 |
adx |
30 |
} |
296 |
|
|
|
297 |
|
|
if (chptr->mode.key[0]) |
298 |
|
|
{ |
299 |
|
|
*mbuf++ = 'k'; |
300 |
|
|
|
301 |
michael |
6360 |
if (IsServer(client_p) || IsMember(client_p, chptr)) |
302 |
michael |
3693 |
sprintf(pbuf, "%s ", chptr->mode.key); |
303 |
adx |
30 |
} |
304 |
|
|
|
305 |
|
|
*mbuf = '\0'; |
306 |
|
|
} |
307 |
|
|
|
308 |
|
|
/* fix_key() |
309 |
michael |
2892 |
* |
310 |
adx |
30 |
* inputs - pointer to key to clean up |
311 |
|
|
* output - pointer to cleaned up key |
312 |
|
|
* side effects - input string is modified |
313 |
|
|
* |
314 |
|
|
* stolen from Undernet's ircd -orabidoo |
315 |
|
|
*/ |
316 |
|
|
static char * |
317 |
|
|
fix_key(char *arg) |
318 |
|
|
{ |
319 |
|
|
unsigned char *s, *t, c; |
320 |
|
|
|
321 |
michael |
8021 |
for (s = t = (unsigned char *)arg; (c = *s) && s - (unsigned char *)arg < KEYLEN; ++s) |
322 |
adx |
30 |
{ |
323 |
|
|
c &= 0x7f; |
324 |
michael |
2892 |
|
325 |
adx |
30 |
if (c != ':' && c > ' ' && c != ',') |
326 |
|
|
*t++ = c; |
327 |
|
|
} |
328 |
|
|
|
329 |
|
|
*t = '\0'; |
330 |
michael |
2892 |
return arg; |
331 |
adx |
30 |
} |
332 |
|
|
|
333 |
michael |
3149 |
/* |
334 |
|
|
* inputs - pointer to channel |
335 |
|
|
* output - none |
336 |
|
|
* side effects - clear ban cache |
337 |
|
|
*/ |
338 |
|
|
void |
339 |
michael |
7763 |
clear_ban_cache_list(dlink_list *list) |
340 |
michael |
3149 |
{ |
341 |
michael |
7763 |
dlink_node *node; |
342 |
michael |
3149 |
|
343 |
michael |
7763 |
DLINK_FOREACH(node, list->head) |
344 |
michael |
3149 |
{ |
345 |
michael |
4816 |
struct Membership *member = node->data; |
346 |
michael |
5751 |
member->flags &= ~(CHFL_BAN_SILENCED | CHFL_BAN_CHECKED); |
347 |
michael |
3149 |
} |
348 |
|
|
} |
349 |
|
|
|
350 |
michael |
3635 |
/* |
351 |
|
|
* Bitmasks for various error returns that set_channel_mode should only return |
352 |
adx |
30 |
* once per call -orabidoo |
353 |
|
|
*/ |
354 |
michael |
3635 |
enum |
355 |
|
|
{ |
356 |
|
|
SM_ERR_NOOPS = 1 << 0, /* No chan ops */ |
357 |
|
|
SM_ERR_UNKNOWN = 1 << 1, |
358 |
|
|
SM_ERR_RPL_B = 1 << 2, |
359 |
|
|
SM_ERR_RPL_E = 1 << 3, |
360 |
|
|
SM_ERR_RPL_I = 1 << 4, |
361 |
|
|
SM_ERR_NOTONCHANNEL = 1 << 5, /* Client is not on channel */ |
362 |
|
|
SM_ERR_NOTOPER = 1 << 6, |
363 |
|
|
SM_ERR_ONLYSERVER = 1 << 7 |
364 |
|
|
}; |
365 |
adx |
30 |
|
366 |
|
|
/* Mode functions handle mode changes for a particular mode... */ |
367 |
|
|
static void |
368 |
michael |
3374 |
chm_nosuch(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
369 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
370 |
adx |
30 |
{ |
371 |
|
|
if (*errors & SM_ERR_UNKNOWN) |
372 |
|
|
return; |
373 |
|
|
|
374 |
|
|
*errors |= SM_ERR_UNKNOWN; |
375 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_UNKNOWNMODE, c); |
376 |
adx |
30 |
} |
377 |
|
|
|
378 |
|
|
static void |
379 |
michael |
3374 |
chm_simple(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
380 |
|
|
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
381 |
adx |
30 |
{ |
382 |
michael |
3720 |
if (alev < CHACCESS_HALFOP) |
383 |
adx |
30 |
{ |
384 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
385 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
386 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
387 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
388 |
michael |
4883 |
|
389 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
390 |
|
|
return; |
391 |
|
|
} |
392 |
|
|
|
393 |
|
|
/* If have already dealt with this simple mode, ignore it */ |
394 |
michael |
2937 |
if (simple_modes_mask & d) |
395 |
adx |
30 |
return; |
396 |
|
|
|
397 |
michael |
2937 |
simple_modes_mask |= d; |
398 |
adx |
30 |
|
399 |
|
|
/* setting + */ |
400 |
michael |
2892 |
/* Apparently, (though no one has ever told the hybrid group directly) |
401 |
|
|
* admins don't like redundant mode checking. ok. It would have been nice |
402 |
|
|
* if you had have told us directly. I've left the original code snippets |
403 |
|
|
* in place. |
404 |
|
|
* |
405 |
|
|
* -Dianora |
406 |
|
|
*/ |
407 |
michael |
2937 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */ |
408 |
adx |
30 |
{ |
409 |
michael |
8043 |
AddCMode(chptr, d); |
410 |
adx |
30 |
|
411 |
|
|
mode_changes[mode_count].letter = c; |
412 |
michael |
3735 |
mode_changes[mode_count].arg = NULL; |
413 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
414 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
415 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
416 |
adx |
30 |
} |
417 |
michael |
2937 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */ |
418 |
adx |
30 |
{ |
419 |
|
|
/* setting - */ |
420 |
michael |
8043 |
DelCMode(chptr, d); |
421 |
adx |
30 |
|
422 |
|
|
mode_changes[mode_count].letter = c; |
423 |
michael |
3735 |
mode_changes[mode_count].arg = NULL; |
424 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
425 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
426 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
427 |
adx |
30 |
} |
428 |
|
|
} |
429 |
|
|
|
430 |
|
|
static void |
431 |
michael |
3374 |
chm_registered(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
432 |
|
|
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
433 |
michael |
1167 |
{ |
434 |
michael |
1219 |
if (!IsServer(source_p) && !HasFlag(source_p, FLAGS_SERVICE)) |
435 |
michael |
1167 |
{ |
436 |
|
|
if (!(*errors & SM_ERR_ONLYSERVER)) |
437 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
438 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
439 |
michael |
4617 |
ERR_ONLYSERVERSCANCHANGE, chptr->name); |
440 |
michael |
4883 |
|
441 |
michael |
1167 |
*errors |= SM_ERR_ONLYSERVER; |
442 |
|
|
return; |
443 |
|
|
} |
444 |
|
|
|
445 |
|
|
/* If have already dealt with this simple mode, ignore it */ |
446 |
michael |
2937 |
if (simple_modes_mask & d) |
447 |
michael |
1167 |
return; |
448 |
|
|
|
449 |
michael |
2937 |
simple_modes_mask |= d; |
450 |
michael |
1167 |
|
451 |
|
|
/* setting + */ |
452 |
michael |
2892 |
/* Apparently, (though no one has ever told the hybrid group directly) |
453 |
|
|
* admins don't like redundant mode checking. ok. It would have been nice |
454 |
|
|
* if you had have told us directly. I've left the original code snippets |
455 |
|
|
* in place. |
456 |
|
|
* |
457 |
|
|
* -Dianora |
458 |
michael |
1167 |
*/ |
459 |
michael |
2937 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */ |
460 |
michael |
1167 |
{ |
461 |
michael |
8043 |
AddCMode(chptr, d); |
462 |
michael |
1167 |
|
463 |
|
|
mode_changes[mode_count].letter = c; |
464 |
michael |
3735 |
mode_changes[mode_count].arg = NULL; |
465 |
michael |
1167 |
mode_changes[mode_count].id = NULL; |
466 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
467 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
468 |
michael |
1167 |
} |
469 |
michael |
2937 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */ |
470 |
michael |
1167 |
{ |
471 |
|
|
/* setting - */ |
472 |
michael |
8043 |
DelCMode(chptr, d); |
473 |
michael |
1167 |
|
474 |
|
|
mode_changes[mode_count].letter = c; |
475 |
michael |
3735 |
mode_changes[mode_count].arg = NULL; |
476 |
michael |
1167 |
mode_changes[mode_count].id = NULL; |
477 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
478 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
479 |
michael |
1167 |
} |
480 |
|
|
} |
481 |
|
|
|
482 |
|
|
static void |
483 |
michael |
3699 |
chm_operonly(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
484 |
|
|
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
485 |
michael |
1150 |
{ |
486 |
michael |
5579 |
if (alev < CHACCESS_HALFOP) |
487 |
michael |
1150 |
{ |
488 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
489 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
490 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
491 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
492 |
michael |
3649 |
|
493 |
michael |
1150 |
*errors |= SM_ERR_NOOPS; |
494 |
|
|
return; |
495 |
|
|
} |
496 |
michael |
3649 |
|
497 |
|
|
if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER)) |
498 |
michael |
1150 |
{ |
499 |
|
|
if (!(*errors & SM_ERR_NOTOPER)) |
500 |
michael |
3649 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
501 |
michael |
1150 |
|
502 |
|
|
*errors |= SM_ERR_NOTOPER; |
503 |
|
|
return; |
504 |
|
|
} |
505 |
|
|
|
506 |
|
|
/* If have already dealt with this simple mode, ignore it */ |
507 |
michael |
2937 |
if (simple_modes_mask & d) |
508 |
michael |
1150 |
return; |
509 |
|
|
|
510 |
michael |
2937 |
simple_modes_mask |= d; |
511 |
michael |
1150 |
|
512 |
michael |
2937 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */ |
513 |
michael |
1150 |
{ |
514 |
michael |
8043 |
AddCMode(chptr, d); |
515 |
michael |
1150 |
|
516 |
|
|
mode_changes[mode_count].letter = c; |
517 |
michael |
3735 |
mode_changes[mode_count].arg = NULL; |
518 |
michael |
1150 |
mode_changes[mode_count].id = NULL; |
519 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
520 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
521 |
michael |
1150 |
} |
522 |
michael |
2937 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */ |
523 |
michael |
1150 |
{ |
524 |
|
|
/* setting - */ |
525 |
michael |
8043 |
DelCMode(chptr, d); |
526 |
michael |
1150 |
|
527 |
|
|
mode_changes[mode_count].letter = c; |
528 |
michael |
3735 |
mode_changes[mode_count].arg = NULL; |
529 |
michael |
1150 |
mode_changes[mode_count].id = NULL; |
530 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
531 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
532 |
michael |
1150 |
} |
533 |
|
|
} |
534 |
|
|
|
535 |
|
|
static void |
536 |
michael |
3374 |
chm_ban(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
537 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
538 |
adx |
30 |
{ |
539 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
540 |
|
|
{ |
541 |
michael |
7796 |
dlink_node *node; |
542 |
adx |
30 |
|
543 |
|
|
if (*errors & SM_ERR_RPL_B) |
544 |
|
|
return; |
545 |
|
|
|
546 |
|
|
*errors |= SM_ERR_RPL_B; |
547 |
|
|
|
548 |
michael |
4801 |
DLINK_FOREACH(node, chptr->banlist.head) |
549 |
adx |
30 |
{ |
550 |
michael |
4816 |
const struct Ban *ban = node->data; |
551 |
michael |
8039 |
|
552 |
michael |
8043 |
if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP) |
553 |
michael |
8039 |
sendto_one_numeric(source_p, &me, RPL_BANLIST, chptr->name, |
554 |
|
|
ban->name, ban->user, ban->host, |
555 |
|
|
ban->who, ban->when); |
556 |
adx |
30 |
} |
557 |
|
|
|
558 |
michael |
4617 |
sendto_one_numeric(source_p, &me, RPL_ENDOFBANLIST, chptr->name); |
559 |
adx |
30 |
return; |
560 |
|
|
} |
561 |
|
|
|
562 |
|
|
if (alev < CHACCESS_HALFOP) |
563 |
|
|
{ |
564 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
565 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
566 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
567 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
568 |
michael |
4883 |
|
569 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
570 |
|
|
return; |
571 |
|
|
} |
572 |
|
|
|
573 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
574 |
|
|
return; |
575 |
|
|
|
576 |
michael |
7516 |
char *mask = nuh_mask[*parn]; |
577 |
michael |
5746 |
strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
578 |
michael |
4790 |
++(*parn); |
579 |
michael |
388 |
|
580 |
michael |
5030 |
if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' '))) |
581 |
|
|
return; |
582 |
adx |
30 |
|
583 |
|
|
switch (dir) |
584 |
|
|
{ |
585 |
|
|
case MODE_ADD: |
586 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_BAN)) |
587 |
|
|
return; |
588 |
|
|
break; |
589 |
|
|
case MODE_DEL: |
590 |
|
|
if (!del_id(chptr, mask, CHFL_BAN)) |
591 |
|
|
return; |
592 |
|
|
break; |
593 |
|
|
default: |
594 |
|
|
assert(0); |
595 |
|
|
} |
596 |
|
|
|
597 |
|
|
mode_changes[mode_count].letter = c; |
598 |
michael |
8017 |
mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */ |
599 |
michael |
3735 |
mode_changes[mode_count].id = NULL; |
600 |
michael |
8043 |
if (HasCMode(chptr, MODE_HIDEBMASKS)) |
601 |
michael |
8039 |
mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP; |
602 |
|
|
else |
603 |
|
|
mode_changes[mode_count].flags = 0; |
604 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
605 |
adx |
30 |
} |
606 |
|
|
|
607 |
|
|
static void |
608 |
michael |
3374 |
chm_except(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
609 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
610 |
adx |
30 |
{ |
611 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
612 |
|
|
{ |
613 |
michael |
7796 |
dlink_node *node; |
614 |
adx |
30 |
|
615 |
|
|
if (*errors & SM_ERR_RPL_E) |
616 |
|
|
return; |
617 |
|
|
|
618 |
|
|
*errors |= SM_ERR_RPL_E; |
619 |
|
|
|
620 |
michael |
4801 |
DLINK_FOREACH(node, chptr->exceptlist.head) |
621 |
adx |
30 |
{ |
622 |
michael |
4816 |
const struct Ban *ban = node->data; |
623 |
michael |
8039 |
|
624 |
michael |
8043 |
if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP) |
625 |
michael |
8039 |
sendto_one_numeric(source_p, &me, RPL_EXCEPTLIST, chptr->name, |
626 |
|
|
ban->name, ban->user, ban->host, |
627 |
|
|
ban->who, ban->when); |
628 |
adx |
30 |
} |
629 |
|
|
|
630 |
michael |
4617 |
sendto_one_numeric(source_p, &me, RPL_ENDOFEXCEPTLIST, chptr->name); |
631 |
adx |
30 |
return; |
632 |
|
|
} |
633 |
|
|
|
634 |
michael |
3842 |
if (alev < CHACCESS_HALFOP) |
635 |
|
|
{ |
636 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
637 |
|
|
sendto_one_numeric(source_p, &me, |
638 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
639 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
640 |
michael |
4883 |
|
641 |
michael |
3842 |
*errors |= SM_ERR_NOOPS; |
642 |
|
|
return; |
643 |
|
|
} |
644 |
|
|
|
645 |
adx |
30 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
646 |
|
|
return; |
647 |
|
|
|
648 |
michael |
7516 |
char *mask = nuh_mask[*parn]; |
649 |
michael |
5746 |
strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
650 |
michael |
4790 |
++(*parn); |
651 |
adx |
30 |
|
652 |
michael |
5030 |
if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' '))) |
653 |
|
|
return; |
654 |
adx |
30 |
|
655 |
|
|
switch (dir) |
656 |
|
|
{ |
657 |
|
|
case MODE_ADD: |
658 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION)) |
659 |
|
|
return; |
660 |
|
|
break; |
661 |
|
|
case MODE_DEL: |
662 |
|
|
if (!del_id(chptr, mask, CHFL_EXCEPTION)) |
663 |
|
|
return; |
664 |
|
|
break; |
665 |
|
|
default: |
666 |
|
|
assert(0); |
667 |
|
|
} |
668 |
|
|
|
669 |
|
|
mode_changes[mode_count].letter = c; |
670 |
michael |
8017 |
mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */ |
671 |
michael |
3735 |
mode_changes[mode_count].id = NULL; |
672 |
michael |
8043 |
if (HasCMode(chptr, MODE_HIDEBMASKS)) |
673 |
michael |
8039 |
mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP; |
674 |
|
|
else |
675 |
|
|
mode_changes[mode_count].flags = 0; |
676 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
677 |
adx |
30 |
} |
678 |
|
|
|
679 |
|
|
static void |
680 |
michael |
3374 |
chm_invex(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
681 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
682 |
adx |
30 |
{ |
683 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
684 |
|
|
{ |
685 |
michael |
7796 |
dlink_node *node; |
686 |
adx |
30 |
|
687 |
|
|
if (*errors & SM_ERR_RPL_I) |
688 |
|
|
return; |
689 |
|
|
|
690 |
|
|
*errors |= SM_ERR_RPL_I; |
691 |
|
|
|
692 |
michael |
4801 |
DLINK_FOREACH(node, chptr->invexlist.head) |
693 |
adx |
30 |
{ |
694 |
michael |
4816 |
const struct Ban *ban = node->data; |
695 |
michael |
8039 |
|
696 |
michael |
8043 |
if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP) |
697 |
michael |
8039 |
sendto_one_numeric(source_p, &me, RPL_INVEXLIST, chptr->name, |
698 |
|
|
ban->name, ban->user, ban->host, |
699 |
|
|
ban->who, ban->when); |
700 |
adx |
30 |
} |
701 |
|
|
|
702 |
michael |
4617 |
sendto_one_numeric(source_p, &me, RPL_ENDOFINVEXLIST, chptr->name); |
703 |
adx |
30 |
return; |
704 |
|
|
} |
705 |
|
|
|
706 |
michael |
3842 |
if (alev < CHACCESS_HALFOP) |
707 |
|
|
{ |
708 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
709 |
|
|
sendto_one_numeric(source_p, &me, |
710 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
711 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
712 |
michael |
4883 |
|
713 |
michael |
3842 |
*errors |= SM_ERR_NOOPS; |
714 |
|
|
return; |
715 |
|
|
} |
716 |
|
|
|
717 |
adx |
30 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
718 |
|
|
return; |
719 |
|
|
|
720 |
michael |
7516 |
char *mask = nuh_mask[*parn]; |
721 |
michael |
5746 |
strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
722 |
michael |
4790 |
++(*parn); |
723 |
adx |
30 |
|
724 |
michael |
5030 |
if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' '))) |
725 |
|
|
return; |
726 |
adx |
30 |
|
727 |
|
|
switch (dir) |
728 |
|
|
{ |
729 |
|
|
case MODE_ADD: |
730 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_INVEX)) |
731 |
|
|
return; |
732 |
|
|
break; |
733 |
|
|
case MODE_DEL: |
734 |
|
|
if (!del_id(chptr, mask, CHFL_INVEX)) |
735 |
|
|
return; |
736 |
|
|
break; |
737 |
|
|
default: |
738 |
|
|
assert(0); |
739 |
|
|
} |
740 |
|
|
|
741 |
|
|
mode_changes[mode_count].letter = c; |
742 |
michael |
8017 |
mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */ |
743 |
michael |
3735 |
mode_changes[mode_count].id = NULL; |
744 |
michael |
8043 |
if (HasCMode(chptr, MODE_HIDEBMASKS)) |
745 |
michael |
8039 |
mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP; |
746 |
|
|
else |
747 |
|
|
mode_changes[mode_count].flags = 0; |
748 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
749 |
adx |
30 |
} |
750 |
|
|
|
751 |
|
|
static void |
752 |
michael |
3374 |
chm_voice(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
753 |
michael |
2951 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
754 |
adx |
30 |
{ |
755 |
michael |
3143 |
struct Client *target_p; |
756 |
adx |
30 |
struct Membership *member; |
757 |
|
|
|
758 |
michael |
2951 |
if (alev < CHACCESS_HALFOP) |
759 |
adx |
30 |
{ |
760 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
761 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
762 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
763 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
764 |
michael |
4883 |
|
765 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
766 |
|
|
return; |
767 |
|
|
} |
768 |
|
|
|
769 |
michael |
3670 |
if (dir == MODE_QUERY || parc <= *parn) |
770 |
adx |
30 |
return; |
771 |
|
|
|
772 |
michael |
3673 |
if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL) |
773 |
michael |
3736 |
return; /* find_chasing sends ERR_NOSUCHNICK */ |
774 |
adx |
30 |
|
775 |
michael |
3143 |
if ((member = find_channel_link(target_p, chptr)) == NULL) |
776 |
adx |
30 |
{ |
777 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
778 |
michael |
4617 |
sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name); |
779 |
michael |
4883 |
|
780 |
adx |
30 |
*errors |= SM_ERR_NOTONCHANNEL; |
781 |
|
|
return; |
782 |
|
|
} |
783 |
|
|
|
784 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
785 |
|
|
return; |
786 |
|
|
|
787 |
michael |
6929 |
switch (dir) |
788 |
|
|
{ |
789 |
|
|
case MODE_ADD: |
790 |
|
|
if (has_member_flags(member, CHFL_VOICE)) |
791 |
|
|
return; /* No redundant mode changes */ |
792 |
michael |
4883 |
|
793 |
michael |
6929 |
AddMemberFlag(member, CHFL_VOICE); |
794 |
|
|
break; |
795 |
|
|
case MODE_DEL: |
796 |
|
|
if (!has_member_flags(member, CHFL_VOICE)) |
797 |
|
|
return; /* No redundant mode changes */ |
798 |
adx |
30 |
|
799 |
michael |
6929 |
DelMemberFlag(member, CHFL_VOICE); |
800 |
|
|
break; |
801 |
|
|
} |
802 |
|
|
|
803 |
michael |
3735 |
mode_changes[mode_count].letter = c; |
804 |
|
|
mode_changes[mode_count].arg = target_p->name; |
805 |
|
|
mode_changes[mode_count].id = target_p->id; |
806 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
807 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
808 |
adx |
30 |
} |
809 |
|
|
|
810 |
|
|
static void |
811 |
michael |
3374 |
chm_hop(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
812 |
michael |
3150 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
813 |
adx |
30 |
{ |
814 |
michael |
3143 |
struct Client *target_p; |
815 |
adx |
30 |
struct Membership *member; |
816 |
|
|
|
817 |
michael |
3714 |
if (alev < CHACCESS_CHANOP) |
818 |
adx |
30 |
{ |
819 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
820 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
821 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
822 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
823 |
michael |
4883 |
|
824 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
825 |
|
|
return; |
826 |
|
|
} |
827 |
|
|
|
828 |
michael |
3670 |
if (dir == MODE_QUERY || parc <= *parn) |
829 |
adx |
30 |
return; |
830 |
|
|
|
831 |
michael |
3673 |
if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL) |
832 |
michael |
3736 |
return; /* find_chasing sends ERR_NOSUCHNICK */ |
833 |
adx |
30 |
|
834 |
michael |
3143 |
if ((member = find_channel_link(target_p, chptr)) == NULL) |
835 |
adx |
30 |
{ |
836 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
837 |
michael |
4617 |
sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name); |
838 |
michael |
4883 |
|
839 |
adx |
30 |
*errors |= SM_ERR_NOTONCHANNEL; |
840 |
|
|
return; |
841 |
|
|
} |
842 |
|
|
|
843 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
844 |
|
|
return; |
845 |
|
|
|
846 |
michael |
6929 |
switch (dir) |
847 |
|
|
{ |
848 |
|
|
case MODE_ADD: |
849 |
|
|
if (has_member_flags(member, CHFL_HALFOP)) |
850 |
|
|
return; /* No redundant mode changes */ |
851 |
michael |
4883 |
|
852 |
michael |
6929 |
AddMemberFlag(member, CHFL_HALFOP); |
853 |
|
|
break; |
854 |
|
|
case MODE_DEL: |
855 |
|
|
if (!has_member_flags(member, CHFL_HALFOP)) |
856 |
|
|
return; /* No redundant mode changes */ |
857 |
adx |
30 |
|
858 |
michael |
6929 |
DelMemberFlag(member, CHFL_HALFOP); |
859 |
|
|
break; |
860 |
|
|
} |
861 |
|
|
|
862 |
michael |
3735 |
mode_changes[mode_count].letter = c; |
863 |
|
|
mode_changes[mode_count].arg = target_p->name; |
864 |
|
|
mode_changes[mode_count].id = target_p->id; |
865 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
866 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
867 |
adx |
30 |
} |
868 |
|
|
|
869 |
|
|
static void |
870 |
michael |
3374 |
chm_op(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
871 |
michael |
2951 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
872 |
adx |
30 |
{ |
873 |
michael |
3143 |
struct Client *target_p; |
874 |
adx |
30 |
struct Membership *member; |
875 |
|
|
|
876 |
michael |
2951 |
if (alev < CHACCESS_CHANOP) |
877 |
adx |
30 |
{ |
878 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
879 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
880 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
881 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
882 |
michael |
4883 |
|
883 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
884 |
|
|
return; |
885 |
|
|
} |
886 |
|
|
|
887 |
michael |
3670 |
if (dir == MODE_QUERY || parc <= *parn) |
888 |
adx |
30 |
return; |
889 |
|
|
|
890 |
michael |
3673 |
if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL) |
891 |
michael |
3736 |
return; /* find_chasing sends ERR_NOSUCHNICK */ |
892 |
adx |
30 |
|
893 |
michael |
3143 |
if ((member = find_channel_link(target_p, chptr)) == NULL) |
894 |
adx |
30 |
{ |
895 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
896 |
michael |
4617 |
sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name); |
897 |
michael |
4883 |
|
898 |
adx |
30 |
*errors |= SM_ERR_NOTONCHANNEL; |
899 |
|
|
return; |
900 |
|
|
} |
901 |
|
|
|
902 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
903 |
|
|
return; |
904 |
|
|
|
905 |
michael |
6929 |
switch (dir) |
906 |
|
|
{ |
907 |
|
|
case MODE_ADD: |
908 |
|
|
if (has_member_flags(member, CHFL_CHANOP)) |
909 |
|
|
return; /* No redundant mode changes */ |
910 |
michael |
4883 |
|
911 |
michael |
6929 |
AddMemberFlag(member, CHFL_CHANOP); |
912 |
|
|
break; |
913 |
|
|
case MODE_DEL: |
914 |
|
|
if (!has_member_flags(member, CHFL_CHANOP)) |
915 |
|
|
return; /* No redundant mode changes */ |
916 |
adx |
30 |
|
917 |
michael |
6929 |
DelMemberFlag(member, CHFL_CHANOP); |
918 |
|
|
break; |
919 |
|
|
} |
920 |
|
|
|
921 |
michael |
3735 |
mode_changes[mode_count].letter = c; |
922 |
|
|
mode_changes[mode_count].arg = target_p->name; |
923 |
|
|
mode_changes[mode_count].id = target_p->id; |
924 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
925 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
926 |
adx |
30 |
} |
927 |
|
|
|
928 |
|
|
static void |
929 |
michael |
3374 |
chm_limit(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
930 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
931 |
adx |
30 |
{ |
932 |
|
|
if (alev < CHACCESS_HALFOP) |
933 |
|
|
{ |
934 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
935 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
936 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
937 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
938 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
939 |
|
|
return; |
940 |
|
|
} |
941 |
|
|
|
942 |
|
|
if (dir == MODE_QUERY) |
943 |
|
|
return; |
944 |
|
|
|
945 |
michael |
3670 |
if (dir == MODE_ADD && parc > *parn) |
946 |
adx |
30 |
{ |
947 |
michael |
4834 |
char *const lstr = parv[(*parn)++]; |
948 |
michael |
6946 |
int limit = 0; |
949 |
adx |
30 |
|
950 |
michael |
3153 |
if (EmptyString(lstr) || (limit = atoi(lstr)) <= 0) |
951 |
adx |
30 |
return; |
952 |
|
|
|
953 |
michael |
1793 |
sprintf(lstr, "%d", limit); |
954 |
adx |
30 |
|
955 |
michael |
3151 |
/* If somebody sets MODE #channel +ll 1 2, accept latter --fl */ |
956 |
michael |
3670 |
for (unsigned int i = 0; i < mode_count; ++i) |
957 |
adx |
30 |
if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD) |
958 |
|
|
mode_changes[i].letter = 0; |
959 |
|
|
|
960 |
|
|
mode_changes[mode_count].letter = c; |
961 |
michael |
3735 |
mode_changes[mode_count].arg = lstr; |
962 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
963 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
964 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
965 |
adx |
30 |
|
966 |
|
|
chptr->mode.limit = limit; |
967 |
|
|
} |
968 |
|
|
else if (dir == MODE_DEL) |
969 |
|
|
{ |
970 |
|
|
if (!chptr->mode.limit) |
971 |
|
|
return; |
972 |
|
|
|
973 |
|
|
chptr->mode.limit = 0; |
974 |
|
|
|
975 |
|
|
mode_changes[mode_count].letter = c; |
976 |
michael |
3735 |
mode_changes[mode_count].arg = NULL; |
977 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
978 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
979 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
980 |
adx |
30 |
} |
981 |
|
|
} |
982 |
|
|
|
983 |
|
|
static void |
984 |
michael |
3374 |
chm_key(struct Client *source_p, struct Channel *chptr, int parc, int *parn, |
985 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
986 |
adx |
30 |
{ |
987 |
|
|
if (alev < CHACCESS_HALFOP) |
988 |
|
|
{ |
989 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
990 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
991 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
992 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
993 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
994 |
|
|
return; |
995 |
|
|
} |
996 |
|
|
|
997 |
|
|
if (dir == MODE_QUERY) |
998 |
|
|
return; |
999 |
|
|
|
1000 |
michael |
3670 |
if (dir == MODE_ADD && parc > *parn) |
1001 |
adx |
30 |
{ |
1002 |
michael |
4834 |
char *const key = fix_key(parv[(*parn)++]); |
1003 |
adx |
30 |
|
1004 |
michael |
3153 |
if (EmptyString(key)) |
1005 |
adx |
30 |
return; |
1006 |
|
|
|
1007 |
|
|
assert(key[0] != ' '); |
1008 |
|
|
strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); |
1009 |
|
|
|
1010 |
michael |
3151 |
/* If somebody does MODE #channel +kk a b, accept latter --fl */ |
1011 |
michael |
3670 |
for (unsigned int i = 0; i < mode_count; ++i) |
1012 |
adx |
30 |
if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD) |
1013 |
|
|
mode_changes[i].letter = 0; |
1014 |
|
|
|
1015 |
|
|
mode_changes[mode_count].letter = c; |
1016 |
michael |
8021 |
mode_changes[mode_count].arg = key; |
1017 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
1018 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
1019 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
1020 |
adx |
30 |
} |
1021 |
|
|
else if (dir == MODE_DEL) |
1022 |
|
|
{ |
1023 |
|
|
if (parc > *parn) |
1024 |
michael |
4790 |
++(*parn); |
1025 |
adx |
30 |
|
1026 |
|
|
if (chptr->mode.key[0] == '\0') |
1027 |
|
|
return; |
1028 |
|
|
|
1029 |
|
|
chptr->mode.key[0] = '\0'; |
1030 |
|
|
|
1031 |
|
|
mode_changes[mode_count].letter = c; |
1032 |
michael |
3735 |
mode_changes[mode_count].arg = "*"; |
1033 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
1034 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
1035 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
1036 |
adx |
30 |
} |
1037 |
|
|
} |
1038 |
|
|
|
1039 |
michael |
3755 |
const struct ChannelMode ModeTable[256] = |
1040 |
adx |
30 |
{ |
1041 |
michael |
2939 |
{ chm_nosuch, 0 }, /* 0x00 */ |
1042 |
|
|
{ chm_nosuch, 0 }, /* 0x01 */ |
1043 |
|
|
{ chm_nosuch, 0 }, /* 0x02 */ |
1044 |
|
|
{ chm_nosuch, 0 }, /* 0x03 */ |
1045 |
|
|
{ chm_nosuch, 0 }, /* 0x04 */ |
1046 |
|
|
{ chm_nosuch, 0 }, /* 0x05 */ |
1047 |
|
|
{ chm_nosuch, 0 }, /* 0x06 */ |
1048 |
|
|
{ chm_nosuch, 0 }, /* 0x07 */ |
1049 |
|
|
{ chm_nosuch, 0 }, /* 0x08 */ |
1050 |
|
|
{ chm_nosuch, 0 }, /* 0x09 */ |
1051 |
|
|
{ chm_nosuch, 0 }, /* 0x0a */ |
1052 |
|
|
{ chm_nosuch, 0 }, /* 0x0b */ |
1053 |
|
|
{ chm_nosuch, 0 }, /* 0x0c */ |
1054 |
|
|
{ chm_nosuch, 0 }, /* 0x0d */ |
1055 |
|
|
{ chm_nosuch, 0 }, /* 0x0e */ |
1056 |
|
|
{ chm_nosuch, 0 }, /* 0x0f */ |
1057 |
|
|
{ chm_nosuch, 0 }, /* 0x10 */ |
1058 |
|
|
{ chm_nosuch, 0 }, /* 0x11 */ |
1059 |
|
|
{ chm_nosuch, 0 }, /* 0x12 */ |
1060 |
|
|
{ chm_nosuch, 0 }, /* 0x13 */ |
1061 |
|
|
{ chm_nosuch, 0 }, /* 0x14 */ |
1062 |
|
|
{ chm_nosuch, 0 }, /* 0x15 */ |
1063 |
|
|
{ chm_nosuch, 0 }, /* 0x16 */ |
1064 |
|
|
{ chm_nosuch, 0 }, /* 0x17 */ |
1065 |
|
|
{ chm_nosuch, 0 }, /* 0x18 */ |
1066 |
|
|
{ chm_nosuch, 0 }, /* 0x19 */ |
1067 |
|
|
{ chm_nosuch, 0 }, /* 0x1a */ |
1068 |
|
|
{ chm_nosuch, 0 }, /* 0x1b */ |
1069 |
|
|
{ chm_nosuch, 0 }, /* 0x1c */ |
1070 |
|
|
{ chm_nosuch, 0 }, /* 0x1d */ |
1071 |
|
|
{ chm_nosuch, 0 }, /* 0x1e */ |
1072 |
|
|
{ chm_nosuch, 0 }, /* 0x1f */ |
1073 |
|
|
{ chm_nosuch, 0 }, /* 0x20 */ |
1074 |
|
|
{ chm_nosuch, 0 }, /* 0x21 */ |
1075 |
|
|
{ chm_nosuch, 0 }, /* 0x22 */ |
1076 |
|
|
{ chm_nosuch, 0 }, /* 0x23 */ |
1077 |
|
|
{ chm_nosuch, 0 }, /* 0x24 */ |
1078 |
|
|
{ chm_nosuch, 0 }, /* 0x25 */ |
1079 |
|
|
{ chm_nosuch, 0 }, /* 0x26 */ |
1080 |
|
|
{ chm_nosuch, 0 }, /* 0x27 */ |
1081 |
|
|
{ chm_nosuch, 0 }, /* 0x28 */ |
1082 |
|
|
{ chm_nosuch, 0 }, /* 0x29 */ |
1083 |
|
|
{ chm_nosuch, 0 }, /* 0x2a */ |
1084 |
|
|
{ chm_nosuch, 0 }, /* 0x2b */ |
1085 |
|
|
{ chm_nosuch, 0 }, /* 0x2c */ |
1086 |
|
|
{ chm_nosuch, 0 }, /* 0x2d */ |
1087 |
|
|
{ chm_nosuch, 0 }, /* 0x2e */ |
1088 |
|
|
{ chm_nosuch, 0 }, /* 0x2f */ |
1089 |
|
|
{ chm_nosuch, 0 }, /* 0x30 */ |
1090 |
|
|
{ chm_nosuch, 0 }, /* 0x31 */ |
1091 |
|
|
{ chm_nosuch, 0 }, /* 0x32 */ |
1092 |
|
|
{ chm_nosuch, 0 }, /* 0x33 */ |
1093 |
|
|
{ chm_nosuch, 0 }, /* 0x34 */ |
1094 |
|
|
{ chm_nosuch, 0 }, /* 0x35 */ |
1095 |
|
|
{ chm_nosuch, 0 }, /* 0x36 */ |
1096 |
|
|
{ chm_nosuch, 0 }, /* 0x37 */ |
1097 |
|
|
{ chm_nosuch, 0 }, /* 0x38 */ |
1098 |
|
|
{ chm_nosuch, 0 }, /* 0x39 */ |
1099 |
|
|
{ chm_nosuch, 0 }, /* 0x3a */ |
1100 |
|
|
{ chm_nosuch, 0 }, /* 0x3b */ |
1101 |
|
|
{ chm_nosuch, 0 }, /* 0x3c */ |
1102 |
|
|
{ chm_nosuch, 0 }, /* 0x3d */ |
1103 |
|
|
{ chm_nosuch, 0 }, /* 0x3e */ |
1104 |
|
|
{ chm_nosuch, 0 }, /* 0x3f */ |
1105 |
|
|
{ chm_nosuch, 0 }, /* @ */ |
1106 |
|
|
{ chm_nosuch, 0 }, /* A */ |
1107 |
|
|
{ chm_nosuch, 0 }, /* B */ |
1108 |
michael |
5463 |
{ chm_simple, MODE_NOCTCP }, /* C */ |
1109 |
michael |
2939 |
{ chm_nosuch, 0 }, /* D */ |
1110 |
|
|
{ chm_nosuch, 0 }, /* E */ |
1111 |
|
|
{ chm_nosuch, 0 }, /* F */ |
1112 |
|
|
{ chm_nosuch, 0 }, /* G */ |
1113 |
|
|
{ chm_nosuch, 0 }, /* H */ |
1114 |
|
|
{ chm_invex, 0 }, /* I */ |
1115 |
|
|
{ chm_nosuch, 0 }, /* J */ |
1116 |
|
|
{ chm_nosuch, 0 }, /* K */ |
1117 |
|
|
{ chm_nosuch, 0 }, /* L */ |
1118 |
|
|
{ chm_simple, MODE_MODREG}, /* M */ |
1119 |
|
|
{ chm_nosuch, 0 }, /* N */ |
1120 |
|
|
{ chm_operonly, MODE_OPERONLY}, /* O */ |
1121 |
|
|
{ chm_nosuch, 0 }, /* P */ |
1122 |
|
|
{ chm_nosuch, 0 }, /* Q */ |
1123 |
|
|
{ chm_simple, MODE_REGONLY}, /* R */ |
1124 |
|
|
{ chm_simple, MODE_SSLONLY}, /* S */ |
1125 |
michael |
6918 |
{ chm_simple, MODE_NONOTICE}, /* T */ |
1126 |
michael |
2939 |
{ chm_nosuch, 0 }, /* U */ |
1127 |
|
|
{ chm_nosuch, 0 }, /* V */ |
1128 |
|
|
{ chm_nosuch, 0 }, /* W */ |
1129 |
|
|
{ chm_nosuch, 0 }, /* X */ |
1130 |
|
|
{ chm_nosuch, 0 }, /* Y */ |
1131 |
|
|
{ chm_nosuch, 0 }, /* Z */ |
1132 |
|
|
{ chm_nosuch, 0 }, |
1133 |
|
|
{ chm_nosuch, 0 }, |
1134 |
|
|
{ chm_nosuch, 0 }, |
1135 |
|
|
{ chm_nosuch, 0 }, |
1136 |
|
|
{ chm_nosuch, 0 }, |
1137 |
|
|
{ chm_nosuch, 0 }, |
1138 |
|
|
{ chm_nosuch, 0 }, /* a */ |
1139 |
|
|
{ chm_ban, 0 }, /* b */ |
1140 |
|
|
{ chm_simple, MODE_NOCTRL}, /* c */ |
1141 |
|
|
{ chm_nosuch, 0 }, /* d */ |
1142 |
|
|
{ chm_except, 0 }, /* e */ |
1143 |
|
|
{ chm_nosuch, 0 }, /* f */ |
1144 |
|
|
{ chm_nosuch, 0 }, /* g */ |
1145 |
|
|
{ chm_hop, 0 }, /* h */ |
1146 |
|
|
{ chm_simple, MODE_INVITEONLY }, /* i */ |
1147 |
|
|
{ chm_nosuch, 0 }, /* j */ |
1148 |
|
|
{ chm_key, 0 }, /* k */ |
1149 |
|
|
{ chm_limit, 0 }, /* l */ |
1150 |
|
|
{ chm_simple, MODE_MODERATED }, /* m */ |
1151 |
|
|
{ chm_simple, MODE_NOPRIVMSGS }, /* n */ |
1152 |
|
|
{ chm_op, 0 }, /* o */ |
1153 |
|
|
{ chm_simple, MODE_PRIVATE }, /* p */ |
1154 |
|
|
{ chm_nosuch, 0 }, /* q */ |
1155 |
|
|
{ chm_registered, MODE_REGISTERED }, /* r */ |
1156 |
|
|
{ chm_simple, MODE_SECRET }, /* s */ |
1157 |
|
|
{ chm_simple, MODE_TOPICLIMIT }, /* t */ |
1158 |
michael |
8039 |
{ chm_simple, MODE_HIDEBMASKS }, /* u */ |
1159 |
michael |
2939 |
{ chm_voice, 0 }, /* v */ |
1160 |
|
|
{ chm_nosuch, 0 }, /* w */ |
1161 |
|
|
{ chm_nosuch, 0 }, /* x */ |
1162 |
|
|
{ chm_nosuch, 0 }, /* y */ |
1163 |
|
|
{ chm_nosuch, 0 }, /* z */ |
1164 |
|
|
{ chm_nosuch, 0 }, /* 0x7b */ |
1165 |
|
|
{ chm_nosuch, 0 }, /* 0x7c */ |
1166 |
|
|
{ chm_nosuch, 0 }, /* 0x7d */ |
1167 |
|
|
{ chm_nosuch, 0 }, /* 0x7e */ |
1168 |
|
|
{ chm_nosuch, 0 }, /* 0x7f */ |
1169 |
|
|
{ chm_nosuch, 0 }, /* 0x80 */ |
1170 |
|
|
{ chm_nosuch, 0 }, /* 0x81 */ |
1171 |
|
|
{ chm_nosuch, 0 }, /* 0x82 */ |
1172 |
|
|
{ chm_nosuch, 0 }, /* 0x83 */ |
1173 |
|
|
{ chm_nosuch, 0 }, /* 0x84 */ |
1174 |
|
|
{ chm_nosuch, 0 }, /* 0x85 */ |
1175 |
|
|
{ chm_nosuch, 0 }, /* 0x86 */ |
1176 |
|
|
{ chm_nosuch, 0 }, /* 0x87 */ |
1177 |
|
|
{ chm_nosuch, 0 }, /* 0x88 */ |
1178 |
|
|
{ chm_nosuch, 0 }, /* 0x89 */ |
1179 |
|
|
{ chm_nosuch, 0 }, /* 0x8a */ |
1180 |
|
|
{ chm_nosuch, 0 }, /* 0x8b */ |
1181 |
|
|
{ chm_nosuch, 0 }, /* 0x8c */ |
1182 |
|
|
{ chm_nosuch, 0 }, /* 0x8d */ |
1183 |
|
|
{ chm_nosuch, 0 }, /* 0x8e */ |
1184 |
|
|
{ chm_nosuch, 0 }, /* 0x8f */ |
1185 |
|
|
{ chm_nosuch, 0 }, /* 0x90 */ |
1186 |
|
|
{ chm_nosuch, 0 }, /* 0x91 */ |
1187 |
|
|
{ chm_nosuch, 0 }, /* 0x92 */ |
1188 |
|
|
{ chm_nosuch, 0 }, /* 0x93 */ |
1189 |
|
|
{ chm_nosuch, 0 }, /* 0x94 */ |
1190 |
|
|
{ chm_nosuch, 0 }, /* 0x95 */ |
1191 |
|
|
{ chm_nosuch, 0 }, /* 0x96 */ |
1192 |
|
|
{ chm_nosuch, 0 }, /* 0x97 */ |
1193 |
|
|
{ chm_nosuch, 0 }, /* 0x98 */ |
1194 |
|
|
{ chm_nosuch, 0 }, /* 0x99 */ |
1195 |
|
|
{ chm_nosuch, 0 }, /* 0x9a */ |
1196 |
|
|
{ chm_nosuch, 0 }, /* 0x9b */ |
1197 |
|
|
{ chm_nosuch, 0 }, /* 0x9c */ |
1198 |
|
|
{ chm_nosuch, 0 }, /* 0x9d */ |
1199 |
|
|
{ chm_nosuch, 0 }, /* 0x9e */ |
1200 |
|
|
{ chm_nosuch, 0 }, /* 0x9f */ |
1201 |
|
|
{ chm_nosuch, 0 }, /* 0xa0 */ |
1202 |
|
|
{ chm_nosuch, 0 }, /* 0xa1 */ |
1203 |
|
|
{ chm_nosuch, 0 }, /* 0xa2 */ |
1204 |
|
|
{ chm_nosuch, 0 }, /* 0xa3 */ |
1205 |
|
|
{ chm_nosuch, 0 }, /* 0xa4 */ |
1206 |
|
|
{ chm_nosuch, 0 }, /* 0xa5 */ |
1207 |
|
|
{ chm_nosuch, 0 }, /* 0xa6 */ |
1208 |
|
|
{ chm_nosuch, 0 }, /* 0xa7 */ |
1209 |
|
|
{ chm_nosuch, 0 }, /* 0xa8 */ |
1210 |
|
|
{ chm_nosuch, 0 }, /* 0xa9 */ |
1211 |
|
|
{ chm_nosuch, 0 }, /* 0xaa */ |
1212 |
|
|
{ chm_nosuch, 0 }, /* 0xab */ |
1213 |
|
|
{ chm_nosuch, 0 }, /* 0xac */ |
1214 |
|
|
{ chm_nosuch, 0 }, /* 0xad */ |
1215 |
|
|
{ chm_nosuch, 0 }, /* 0xae */ |
1216 |
|
|
{ chm_nosuch, 0 }, /* 0xaf */ |
1217 |
|
|
{ chm_nosuch, 0 }, /* 0xb0 */ |
1218 |
|
|
{ chm_nosuch, 0 }, /* 0xb1 */ |
1219 |
|
|
{ chm_nosuch, 0 }, /* 0xb2 */ |
1220 |
|
|
{ chm_nosuch, 0 }, /* 0xb3 */ |
1221 |
|
|
{ chm_nosuch, 0 }, /* 0xb4 */ |
1222 |
|
|
{ chm_nosuch, 0 }, /* 0xb5 */ |
1223 |
|
|
{ chm_nosuch, 0 }, /* 0xb6 */ |
1224 |
|
|
{ chm_nosuch, 0 }, /* 0xb7 */ |
1225 |
|
|
{ chm_nosuch, 0 }, /* 0xb8 */ |
1226 |
|
|
{ chm_nosuch, 0 }, /* 0xb9 */ |
1227 |
|
|
{ chm_nosuch, 0 }, /* 0xba */ |
1228 |
|
|
{ chm_nosuch, 0 }, /* 0xbb */ |
1229 |
|
|
{ chm_nosuch, 0 }, /* 0xbc */ |
1230 |
|
|
{ chm_nosuch, 0 }, /* 0xbd */ |
1231 |
|
|
{ chm_nosuch, 0 }, /* 0xbe */ |
1232 |
|
|
{ chm_nosuch, 0 }, /* 0xbf */ |
1233 |
|
|
{ chm_nosuch, 0 }, /* 0xc0 */ |
1234 |
|
|
{ chm_nosuch, 0 }, /* 0xc1 */ |
1235 |
|
|
{ chm_nosuch, 0 }, /* 0xc2 */ |
1236 |
|
|
{ chm_nosuch, 0 }, /* 0xc3 */ |
1237 |
|
|
{ chm_nosuch, 0 }, /* 0xc4 */ |
1238 |
|
|
{ chm_nosuch, 0 }, /* 0xc5 */ |
1239 |
|
|
{ chm_nosuch, 0 }, /* 0xc6 */ |
1240 |
|
|
{ chm_nosuch, 0 }, /* 0xc7 */ |
1241 |
|
|
{ chm_nosuch, 0 }, /* 0xc8 */ |
1242 |
|
|
{ chm_nosuch, 0 }, /* 0xc9 */ |
1243 |
|
|
{ chm_nosuch, 0 }, /* 0xca */ |
1244 |
|
|
{ chm_nosuch, 0 }, /* 0xcb */ |
1245 |
|
|
{ chm_nosuch, 0 }, /* 0xcc */ |
1246 |
|
|
{ chm_nosuch, 0 }, /* 0xcd */ |
1247 |
|
|
{ chm_nosuch, 0 }, /* 0xce */ |
1248 |
|
|
{ chm_nosuch, 0 }, /* 0xcf */ |
1249 |
|
|
{ chm_nosuch, 0 }, /* 0xd0 */ |
1250 |
|
|
{ chm_nosuch, 0 }, /* 0xd1 */ |
1251 |
|
|
{ chm_nosuch, 0 }, /* 0xd2 */ |
1252 |
|
|
{ chm_nosuch, 0 }, /* 0xd3 */ |
1253 |
|
|
{ chm_nosuch, 0 }, /* 0xd4 */ |
1254 |
|
|
{ chm_nosuch, 0 }, /* 0xd5 */ |
1255 |
|
|
{ chm_nosuch, 0 }, /* 0xd6 */ |
1256 |
|
|
{ chm_nosuch, 0 }, /* 0xd7 */ |
1257 |
|
|
{ chm_nosuch, 0 }, /* 0xd8 */ |
1258 |
|
|
{ chm_nosuch, 0 }, /* 0xd9 */ |
1259 |
|
|
{ chm_nosuch, 0 }, /* 0xda */ |
1260 |
|
|
{ chm_nosuch, 0 }, /* 0xdb */ |
1261 |
|
|
{ chm_nosuch, 0 }, /* 0xdc */ |
1262 |
|
|
{ chm_nosuch, 0 }, /* 0xdd */ |
1263 |
|
|
{ chm_nosuch, 0 }, /* 0xde */ |
1264 |
|
|
{ chm_nosuch, 0 }, /* 0xdf */ |
1265 |
|
|
{ chm_nosuch, 0 }, /* 0xe0 */ |
1266 |
|
|
{ chm_nosuch, 0 }, /* 0xe1 */ |
1267 |
|
|
{ chm_nosuch, 0 }, /* 0xe2 */ |
1268 |
|
|
{ chm_nosuch, 0 }, /* 0xe3 */ |
1269 |
|
|
{ chm_nosuch, 0 }, /* 0xe4 */ |
1270 |
|
|
{ chm_nosuch, 0 }, /* 0xe5 */ |
1271 |
|
|
{ chm_nosuch, 0 }, /* 0xe6 */ |
1272 |
|
|
{ chm_nosuch, 0 }, /* 0xe7 */ |
1273 |
|
|
{ chm_nosuch, 0 }, /* 0xe8 */ |
1274 |
|
|
{ chm_nosuch, 0 }, /* 0xe9 */ |
1275 |
|
|
{ chm_nosuch, 0 }, /* 0xea */ |
1276 |
|
|
{ chm_nosuch, 0 }, /* 0xeb */ |
1277 |
|
|
{ chm_nosuch, 0 }, /* 0xec */ |
1278 |
|
|
{ chm_nosuch, 0 }, /* 0xed */ |
1279 |
|
|
{ chm_nosuch, 0 }, /* 0xee */ |
1280 |
|
|
{ chm_nosuch, 0 }, /* 0xef */ |
1281 |
|
|
{ chm_nosuch, 0 }, /* 0xf0 */ |
1282 |
|
|
{ chm_nosuch, 0 }, /* 0xf1 */ |
1283 |
|
|
{ chm_nosuch, 0 }, /* 0xf2 */ |
1284 |
|
|
{ chm_nosuch, 0 }, /* 0xf3 */ |
1285 |
|
|
{ chm_nosuch, 0 }, /* 0xf4 */ |
1286 |
|
|
{ chm_nosuch, 0 }, /* 0xf5 */ |
1287 |
|
|
{ chm_nosuch, 0 }, /* 0xf6 */ |
1288 |
|
|
{ chm_nosuch, 0 }, /* 0xf7 */ |
1289 |
|
|
{ chm_nosuch, 0 }, /* 0xf8 */ |
1290 |
|
|
{ chm_nosuch, 0 }, /* 0xf9 */ |
1291 |
|
|
{ chm_nosuch, 0 }, /* 0xfa */ |
1292 |
|
|
{ chm_nosuch, 0 }, /* 0xfb */ |
1293 |
|
|
{ chm_nosuch, 0 }, /* 0xfc */ |
1294 |
|
|
{ chm_nosuch, 0 }, /* 0xfd */ |
1295 |
|
|
{ chm_nosuch, 0 }, /* 0xfe */ |
1296 |
|
|
{ chm_nosuch, 0 }, /* 0xff */ |
1297 |
adx |
30 |
}; |
1298 |
|
|
|
1299 |
|
|
/* get_channel_access() |
1300 |
|
|
* |
1301 |
|
|
* inputs - pointer to Client struct |
1302 |
|
|
* - pointer to Membership struct |
1303 |
|
|
* output - CHACCESS_CHANOP if we should let them have |
1304 |
|
|
* chanop level access, 0 for peon level access. |
1305 |
|
|
* side effects - NONE |
1306 |
|
|
*/ |
1307 |
|
|
static int |
1308 |
michael |
2941 |
get_channel_access(const struct Client *source_p, |
1309 |
|
|
const struct Membership *member) |
1310 |
adx |
30 |
{ |
1311 |
|
|
/* Let hacked servers in for now... */ |
1312 |
|
|
if (!MyClient(source_p)) |
1313 |
michael |
4101 |
return CHACCESS_REMOTE; |
1314 |
adx |
30 |
|
1315 |
michael |
3235 |
if (!member) |
1316 |
adx |
30 |
return CHACCESS_NOTONCHAN; |
1317 |
|
|
|
1318 |
michael |
3374 |
/* Just to be sure.. */ |
1319 |
adx |
30 |
assert(source_p == member->client_p); |
1320 |
|
|
|
1321 |
|
|
if (has_member_flags(member, CHFL_CHANOP)) |
1322 |
|
|
return CHACCESS_CHANOP; |
1323 |
|
|
|
1324 |
|
|
if (has_member_flags(member, CHFL_HALFOP)) |
1325 |
|
|
return CHACCESS_HALFOP; |
1326 |
|
|
|
1327 |
|
|
return CHACCESS_PEON; |
1328 |
|
|
} |
1329 |
|
|
|
1330 |
michael |
3151 |
/* send_mode_changes_server() |
1331 |
michael |
3159 |
* Input: the source client(source_p), |
1332 |
adx |
30 |
* the channel to send mode changes for(chptr) |
1333 |
|
|
* Output: None. |
1334 |
michael |
3151 |
* Side-effects: Sends the appropriate mode changes to servers. |
1335 |
adx |
30 |
* |
1336 |
|
|
*/ |
1337 |
|
|
static void |
1338 |
michael |
3150 |
send_mode_changes_server(struct Client *source_p, struct Channel *chptr) |
1339 |
adx |
30 |
{ |
1340 |
michael |
8015 |
char modebuf[IRCD_BUFSIZE] = ""; |
1341 |
|
|
char parabuf[IRCD_BUFSIZE] = ""; |
1342 |
|
|
char *parptr = parabuf; |
1343 |
michael |
8041 |
unsigned int mbl = 0, pbl = 0, arglen = 0, modecount = 0, paracount = 0; |
1344 |
|
|
unsigned int dir = MODE_QUERY; |
1345 |
adx |
30 |
|
1346 |
michael |
8015 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ", |
1347 |
|
|
source_p->id, chptr->creationtime, chptr->name); |
1348 |
adx |
30 |
|
1349 |
michael |
3374 |
/* Loop the list of modes we have */ |
1350 |
michael |
5546 |
for (unsigned int i = 0; i < mode_count; ++i) |
1351 |
adx |
30 |
{ |
1352 |
michael |
3669 |
if (mode_changes[i].letter == 0) |
1353 |
adx |
30 |
continue; |
1354 |
|
|
|
1355 |
michael |
8015 |
const char *arg; |
1356 |
michael |
3141 |
if (mode_changes[i].id) |
1357 |
|
|
arg = mode_changes[i].id; |
1358 |
|
|
else |
1359 |
|
|
arg = mode_changes[i].arg; |
1360 |
adx |
30 |
|
1361 |
michael |
3215 |
if (arg) |
1362 |
michael |
3141 |
arglen = strlen(arg); |
1363 |
|
|
else |
1364 |
|
|
arglen = 0; |
1365 |
|
|
|
1366 |
michael |
3136 |
/* |
1367 |
|
|
* If we're creeping past the buf size, we need to send it and make |
1368 |
adx |
30 |
* another line for the other modes |
1369 |
|
|
*/ |
1370 |
michael |
8013 |
if ((paracount == MAXMODEPARAMS) || |
1371 |
michael |
8015 |
((arglen + mbl + pbl + 2 /* +2 for /r/n */ ) > IRCD_BUFSIZE)) |
1372 |
adx |
30 |
{ |
1373 |
michael |
8013 |
if (modecount) |
1374 |
michael |
4963 |
sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf); |
1375 |
michael |
3215 |
|
1376 |
michael |
8013 |
modecount = 0; |
1377 |
|
|
paracount = 0; |
1378 |
adx |
30 |
|
1379 |
michael |
8015 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ", |
1380 |
|
|
source_p->id, chptr->creationtime, chptr->name); |
1381 |
adx |
30 |
|
1382 |
|
|
pbl = 0; |
1383 |
|
|
parabuf[0] = '\0'; |
1384 |
|
|
parptr = parabuf; |
1385 |
|
|
dir = MODE_QUERY; |
1386 |
|
|
} |
1387 |
|
|
|
1388 |
|
|
if (dir != mode_changes[i].dir) |
1389 |
|
|
{ |
1390 |
|
|
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
1391 |
|
|
dir = mode_changes[i].dir; |
1392 |
|
|
} |
1393 |
|
|
|
1394 |
|
|
modebuf[mbl++] = mode_changes[i].letter; |
1395 |
|
|
modebuf[mbl] = '\0'; |
1396 |
michael |
8013 |
++modecount; |
1397 |
adx |
30 |
|
1398 |
michael |
3215 |
if (arg) |
1399 |
adx |
30 |
{ |
1400 |
michael |
8015 |
int len = sprintf(parptr, (pbl == 0) ? "%s" : " %s", arg); |
1401 |
adx |
30 |
pbl += len; |
1402 |
|
|
parptr += len; |
1403 |
michael |
8013 |
++paracount; |
1404 |
adx |
30 |
} |
1405 |
|
|
} |
1406 |
|
|
|
1407 |
michael |
8013 |
if (modecount) |
1408 |
michael |
4963 |
sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf); |
1409 |
adx |
30 |
} |
1410 |
|
|
|
1411 |
|
|
/* void send_mode_changes(struct Client *client_p, |
1412 |
|
|
* struct Client *source_p, |
1413 |
|
|
* struct Channel *chptr) |
1414 |
|
|
* Input: The client sending(client_p), the source client(source_p), |
1415 |
|
|
* the channel to send mode changes for(chptr), |
1416 |
|
|
* mode change globals. |
1417 |
|
|
* Output: None. |
1418 |
|
|
* Side-effects: Sends the appropriate mode changes to other clients |
1419 |
|
|
* and propagates to servers. |
1420 |
|
|
*/ |
1421 |
|
|
static void |
1422 |
michael |
5747 |
send_mode_changes_client(struct Client *source_p, struct Channel *chptr) |
1423 |
adx |
30 |
{ |
1424 |
michael |
8039 |
unsigned int flags = 0; |
1425 |
adx |
30 |
|
1426 |
michael |
8039 |
for (unsigned int pass = 2; pass--; flags = CHFL_CHANOP | CHFL_HALFOP) |
1427 |
adx |
30 |
{ |
1428 |
michael |
8039 |
char modebuf[IRCD_BUFSIZE] = ""; |
1429 |
|
|
char parabuf[IRCD_BUFSIZE] = ""; |
1430 |
|
|
char *parptr = parabuf; |
1431 |
michael |
8041 |
unsigned int mbl = 0, pbl = 0, arglen = 0, modecount = 0, paracount = 0; |
1432 |
|
|
unsigned int dir = MODE_QUERY; |
1433 |
adx |
30 |
|
1434 |
michael |
8039 |
if (IsServer(source_p)) |
1435 |
|
|
mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) || |
1436 |
|
|
ConfigServerHide.hide_servers) ? |
1437 |
|
|
me.name : source_p->name, chptr->name); |
1438 |
adx |
30 |
else |
1439 |
michael |
8039 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name, |
1440 |
|
|
source_p->username, source_p->host, chptr->name); |
1441 |
adx |
30 |
|
1442 |
michael |
8039 |
for (unsigned int i = 0; i < mode_count; ++i) |
1443 |
adx |
30 |
{ |
1444 |
michael |
8039 |
if (mode_changes[i].letter == 0 || mode_changes[i].flags != flags) |
1445 |
|
|
continue; |
1446 |
adx |
30 |
|
1447 |
michael |
8039 |
const char *arg = mode_changes[i].arg; |
1448 |
|
|
if (arg) |
1449 |
|
|
arglen = strlen(arg); |
1450 |
adx |
30 |
else |
1451 |
michael |
8039 |
arglen = 0; |
1452 |
adx |
30 |
|
1453 |
michael |
8039 |
if ((paracount == MAXMODEPARAMS) || |
1454 |
|
|
((arglen + mbl + pbl + 2 /* +2 for /r/n */ ) > IRCD_BUFSIZE)) |
1455 |
|
|
{ |
1456 |
|
|
if (modecount) |
1457 |
|
|
sendto_channel_local(NULL, chptr, flags, 0, 0, "%s %s", modebuf, parabuf); |
1458 |
adx |
30 |
|
1459 |
michael |
8039 |
modecount = 0; |
1460 |
|
|
paracount = 0; |
1461 |
adx |
30 |
|
1462 |
michael |
8039 |
if (IsServer(source_p)) |
1463 |
|
|
mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) || |
1464 |
|
|
ConfigServerHide.hide_servers) ? |
1465 |
|
|
me.name : source_p->name, chptr->name); |
1466 |
|
|
else |
1467 |
|
|
mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name, |
1468 |
|
|
source_p->username, source_p->host, chptr->name); |
1469 |
adx |
30 |
|
1470 |
michael |
8039 |
pbl = 0; |
1471 |
|
|
parabuf[0] = '\0'; |
1472 |
|
|
parptr = parabuf; |
1473 |
|
|
dir = MODE_QUERY; |
1474 |
|
|
} |
1475 |
|
|
|
1476 |
|
|
if (dir != mode_changes[i].dir) |
1477 |
|
|
{ |
1478 |
|
|
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
1479 |
|
|
dir = mode_changes[i].dir; |
1480 |
|
|
} |
1481 |
|
|
|
1482 |
|
|
modebuf[mbl++] = mode_changes[i].letter; |
1483 |
|
|
modebuf[mbl] = '\0'; |
1484 |
|
|
++modecount; |
1485 |
|
|
|
1486 |
|
|
if (arg) |
1487 |
|
|
{ |
1488 |
|
|
int len = sprintf(parptr, (pbl == 0) ? "%s" : " %s", arg); |
1489 |
|
|
pbl += len; |
1490 |
|
|
parptr += len; |
1491 |
|
|
++paracount; |
1492 |
|
|
} |
1493 |
adx |
30 |
} |
1494 |
michael |
8039 |
|
1495 |
|
|
if (modecount) |
1496 |
|
|
sendto_channel_local(NULL, chptr, flags, 0, 0, "%s %s", modebuf, parabuf); |
1497 |
adx |
30 |
} |
1498 |
|
|
} |
1499 |
|
|
|
1500 |
michael |
3670 |
/* |
1501 |
michael |
3159 |
* Input: The the client this originated |
1502 |
adx |
30 |
* from, the channel, the parameter count starting at the modes, |
1503 |
|
|
* the parameters, the channel name. |
1504 |
|
|
* Output: None. |
1505 |
|
|
* Side-effects: Changes the channel membership and modes appropriately, |
1506 |
|
|
* sends the appropriate MODE messages to the appropriate |
1507 |
|
|
* clients. |
1508 |
|
|
*/ |
1509 |
|
|
void |
1510 |
michael |
3150 |
set_channel_mode(struct Client *source_p, struct Channel *chptr, |
1511 |
michael |
2937 |
struct Membership *member, int parc, char *parv[]) |
1512 |
adx |
30 |
{ |
1513 |
|
|
int dir = MODE_ADD; |
1514 |
|
|
int parn = 1; |
1515 |
michael |
3670 |
int alevel = 0, errors = 0; |
1516 |
adx |
30 |
|
1517 |
|
|
mode_count = 0; |
1518 |
|
|
mode_limit = 0; |
1519 |
|
|
simple_modes_mask = 0; |
1520 |
|
|
|
1521 |
|
|
alevel = get_channel_access(source_p, member); |
1522 |
|
|
|
1523 |
michael |
3283 |
for (const char *ml = parv[0]; *ml; ++ml) |
1524 |
adx |
30 |
{ |
1525 |
michael |
3250 |
switch (*ml) |
1526 |
adx |
30 |
{ |
1527 |
|
|
case '+': |
1528 |
|
|
dir = MODE_ADD; |
1529 |
|
|
break; |
1530 |
|
|
case '-': |
1531 |
|
|
dir = MODE_DEL; |
1532 |
|
|
break; |
1533 |
|
|
case '=': |
1534 |
|
|
dir = MODE_QUERY; |
1535 |
|
|
break; |
1536 |
|
|
default: |
1537 |
michael |
2939 |
{ |
1538 |
michael |
3755 |
const struct ChannelMode *tptr = &ModeTable[(unsigned char)*ml]; |
1539 |
michael |
2939 |
|
1540 |
michael |
3150 |
tptr->func(source_p, chptr, parc, &parn, parv, |
1541 |
michael |
3250 |
&errors, alevel, dir, *ml, tptr->d); |
1542 |
adx |
30 |
break; |
1543 |
michael |
2939 |
} |
1544 |
adx |
30 |
} |
1545 |
|
|
} |
1546 |
|
|
|
1547 |
michael |
5750 |
/* Bail out if we have nothing to do... */ |
1548 |
|
|
if (!mode_count) |
1549 |
|
|
return; |
1550 |
|
|
|
1551 |
michael |
5747 |
send_mode_changes_client(source_p, chptr); |
1552 |
|
|
send_mode_changes_server(source_p, chptr); |
1553 |
adx |
30 |
} |