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