1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2916 |
* Copyright (c) 1997-2014 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 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
|
* 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 |
2892 |
#include "s_serv.h" |
38 |
adx |
30 |
#include "s_user.h" |
39 |
|
|
#include "send.h" |
40 |
|
|
#include "memory.h" |
41 |
michael |
1654 |
#include "mempool.h" |
42 |
michael |
1243 |
#include "parse.h" |
43 |
adx |
30 |
|
44 |
|
|
/* 10 is a magic number in hybrid 6 NFI where it comes from -db */ |
45 |
michael |
2892 |
#define BAN_FUDGE 10 |
46 |
adx |
30 |
#define NCHCAPS (sizeof(channel_capabs)/sizeof(int)) |
47 |
|
|
#define NCHCAP_COMBOS (1 << NCHCAPS) |
48 |
|
|
|
49 |
michael |
2892 |
|
50 |
michael |
388 |
static char nuh_mask[MAXPARA][IRCD_BUFSIZE]; |
51 |
adx |
30 |
/* some buffers for rebuilding channel/nick lists with ,'s */ |
52 |
|
|
static char modebuf[IRCD_BUFSIZE]; |
53 |
|
|
static char parabuf[MODEBUFLEN]; |
54 |
|
|
static struct ChModeChange mode_changes[IRCD_BUFSIZE]; |
55 |
|
|
static int mode_count; |
56 |
michael |
2892 |
static int mode_limit; /* number of modes set other than simple */ |
57 |
|
|
static int simple_modes_mask; /* bit mask of simple modes already set */ |
58 |
adx |
356 |
#ifdef HALFOPS |
59 |
|
|
static int channel_capabs[] = { CAP_EX, CAP_IE, CAP_TS6, CAP_HOPS }; |
60 |
|
|
#else |
61 |
adx |
30 |
static int channel_capabs[] = { CAP_EX, CAP_IE, CAP_TS6 }; |
62 |
adx |
356 |
#endif |
63 |
adx |
30 |
static struct ChCapCombo chcap_combos[NCHCAP_COMBOS]; |
64 |
michael |
1654 |
extern mp_pool_t *ban_pool; |
65 |
adx |
30 |
|
66 |
|
|
|
67 |
|
|
/* check_string() |
68 |
|
|
* |
69 |
|
|
* inputs - string to check |
70 |
|
|
* output - pointer to modified string |
71 |
|
|
* side effects - Fixes a string so that the first white space found |
72 |
|
|
* becomes an end of string marker (`\0`). |
73 |
|
|
* returns the 'fixed' string or "*" if the string |
74 |
|
|
* was NULL length or a NULL pointer. |
75 |
|
|
*/ |
76 |
|
|
static char * |
77 |
|
|
check_string(char *s) |
78 |
|
|
{ |
79 |
|
|
char *str = s; |
80 |
|
|
static char star[] = "*"; |
81 |
|
|
|
82 |
michael |
1772 |
if (EmptyString(str)) |
83 |
michael |
593 |
return star; |
84 |
adx |
30 |
|
85 |
|
|
for (; *s; ++s) |
86 |
|
|
{ |
87 |
|
|
if (IsSpace(*s)) |
88 |
|
|
{ |
89 |
|
|
*s = '\0'; |
90 |
|
|
break; |
91 |
|
|
} |
92 |
|
|
} |
93 |
|
|
|
94 |
michael |
1772 |
return EmptyString(str) ? star : str; |
95 |
adx |
30 |
} |
96 |
|
|
|
97 |
|
|
/* |
98 |
|
|
* Ban functions to work with mode +b/e/d/I |
99 |
|
|
*/ |
100 |
michael |
2892 |
/* add the specified ID to the channel. |
101 |
|
|
* -is 8/9/00 |
102 |
adx |
30 |
*/ |
103 |
|
|
|
104 |
|
|
int |
105 |
|
|
add_id(struct Client *client_p, struct Channel *chptr, char *banid, int type) |
106 |
|
|
{ |
107 |
michael |
593 |
dlink_list *list = NULL; |
108 |
|
|
dlink_node *ban = NULL; |
109 |
adx |
30 |
size_t len = 0; |
110 |
michael |
593 |
struct Ban *ban_p = NULL; |
111 |
adx |
30 |
unsigned int num_mask; |
112 |
michael |
1431 |
char name[NICKLEN + 1]; |
113 |
michael |
593 |
char user[USERLEN + 1]; |
114 |
|
|
char host[HOSTLEN + 1]; |
115 |
|
|
struct split_nuh_item nuh; |
116 |
adx |
30 |
|
117 |
|
|
/* dont let local clients overflow the b/e/I lists */ |
118 |
|
|
if (MyClient(client_p)) |
119 |
|
|
{ |
120 |
|
|
num_mask = dlink_list_length(&chptr->banlist) + |
121 |
|
|
dlink_list_length(&chptr->exceptlist) + |
122 |
|
|
dlink_list_length(&chptr->invexlist); |
123 |
|
|
|
124 |
|
|
if (num_mask >= ConfigChannel.max_bans) |
125 |
|
|
{ |
126 |
michael |
1834 |
sendto_one(client_p, form_str(ERR_BANLISTFULL), |
127 |
adx |
30 |
me.name, client_p->name, chptr->chname, banid); |
128 |
|
|
return 0; |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
collapse(banid); |
132 |
|
|
} |
133 |
|
|
|
134 |
michael |
593 |
nuh.nuhmask = check_string(banid); |
135 |
|
|
nuh.nickptr = name; |
136 |
|
|
nuh.userptr = user; |
137 |
|
|
nuh.hostptr = host; |
138 |
adx |
30 |
|
139 |
michael |
593 |
nuh.nicksize = sizeof(name); |
140 |
|
|
nuh.usersize = sizeof(user); |
141 |
|
|
nuh.hostsize = sizeof(host); |
142 |
|
|
|
143 |
|
|
split_nuh(&nuh); |
144 |
|
|
|
145 |
adx |
30 |
/* |
146 |
michael |
593 |
* Re-assemble a new n!u@h and print it back to banid for sending |
147 |
adx |
30 |
* the mode to the channel. |
148 |
|
|
*/ |
149 |
michael |
1793 |
len = sprintf(banid, "%s!%s@%s", name, user, host); |
150 |
adx |
30 |
|
151 |
|
|
switch (type) |
152 |
|
|
{ |
153 |
|
|
case CHFL_BAN: |
154 |
|
|
list = &chptr->banlist; |
155 |
|
|
clear_ban_cache(chptr); |
156 |
|
|
break; |
157 |
|
|
case CHFL_EXCEPTION: |
158 |
|
|
list = &chptr->exceptlist; |
159 |
|
|
clear_ban_cache(chptr); |
160 |
|
|
break; |
161 |
|
|
case CHFL_INVEX: |
162 |
|
|
list = &chptr->invexlist; |
163 |
|
|
break; |
164 |
|
|
default: |
165 |
|
|
assert(0); |
166 |
|
|
return 0; |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
DLINK_FOREACH(ban, list->head) |
170 |
|
|
{ |
171 |
michael |
593 |
ban_p = ban->data; |
172 |
michael |
2892 |
|
173 |
michael |
593 |
if (!irccmp(ban_p->name, name) && |
174 |
michael |
2296 |
!irccmp(ban_p->user, user) && |
175 |
michael |
593 |
!irccmp(ban_p->host, host)) |
176 |
adx |
30 |
return 0; |
177 |
|
|
} |
178 |
|
|
|
179 |
michael |
1654 |
ban_p = mp_pool_get(ban_pool); |
180 |
|
|
memset(ban_p, 0, sizeof(*ban_p)); |
181 |
michael |
1646 |
ban_p->name = xstrdup(name); |
182 |
michael |
2296 |
ban_p->user = xstrdup(user); |
183 |
michael |
1646 |
ban_p->host = xstrdup(host); |
184 |
michael |
593 |
ban_p->when = CurrentTime; |
185 |
michael |
2892 |
ban_p->len = len - 2; /* -2 for @ and ! */ |
186 |
michael |
593 |
ban_p->type = parse_netmask(host, &ban_p->addr, &ban_p->bits); |
187 |
|
|
|
188 |
adx |
30 |
if (IsClient(client_p)) |
189 |
|
|
{ |
190 |
michael |
593 |
ban_p->who = MyMalloc(strlen(client_p->name) + |
191 |
|
|
strlen(client_p->username) + |
192 |
|
|
strlen(client_p->host) + 3); |
193 |
michael |
1793 |
sprintf(ban_p->who, "%s!%s@%s", client_p->name, |
194 |
michael |
2296 |
client_p->username, client_p->host); |
195 |
adx |
30 |
} |
196 |
michael |
2242 |
else if (IsHidden(client_p) || (IsServer(client_p) && ConfigServerHide.hide_servers)) |
197 |
|
|
ban_p->who = xstrdup(me.name); |
198 |
adx |
30 |
else |
199 |
michael |
1646 |
ban_p->who = xstrdup(client_p->name); |
200 |
adx |
30 |
|
201 |
michael |
593 |
dlinkAdd(ban_p, &ban_p->node, list); |
202 |
adx |
30 |
|
203 |
|
|
return 1; |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
/* |
207 |
|
|
* inputs - pointer to channel |
208 |
|
|
* - pointer to ban id |
209 |
|
|
* - type of ban, i.e. ban, exception, invex |
210 |
|
|
* output - 0 for failure, 1 for success |
211 |
|
|
* side effects - |
212 |
|
|
*/ |
213 |
|
|
static int |
214 |
|
|
del_id(struct Channel *chptr, char *banid, int type) |
215 |
|
|
{ |
216 |
|
|
dlink_list *list; |
217 |
|
|
dlink_node *ban; |
218 |
|
|
struct Ban *banptr; |
219 |
michael |
1431 |
char name[NICKLEN + 1]; |
220 |
michael |
593 |
char user[USERLEN + 1]; |
221 |
|
|
char host[HOSTLEN + 1]; |
222 |
|
|
struct split_nuh_item nuh; |
223 |
adx |
30 |
|
224 |
michael |
2892 |
assert(banid); |
225 |
adx |
30 |
|
226 |
michael |
593 |
nuh.nuhmask = check_string(banid); |
227 |
|
|
nuh.nickptr = name; |
228 |
|
|
nuh.userptr = user; |
229 |
|
|
nuh.hostptr = host; |
230 |
adx |
30 |
|
231 |
michael |
593 |
nuh.nicksize = sizeof(name); |
232 |
|
|
nuh.usersize = sizeof(user); |
233 |
|
|
nuh.hostsize = sizeof(host); |
234 |
|
|
|
235 |
|
|
split_nuh(&nuh); |
236 |
|
|
|
237 |
adx |
30 |
/* |
238 |
michael |
593 |
* Re-assemble a new n!u@h and print it back to banid for sending |
239 |
adx |
30 |
* the mode to the channel. |
240 |
|
|
*/ |
241 |
michael |
1793 |
sprintf(banid, "%s!%s@%s", name, user, host); |
242 |
adx |
30 |
|
243 |
|
|
switch (type) |
244 |
|
|
{ |
245 |
|
|
case CHFL_BAN: |
246 |
|
|
list = &chptr->banlist; |
247 |
|
|
clear_ban_cache(chptr); |
248 |
|
|
break; |
249 |
|
|
case CHFL_EXCEPTION: |
250 |
|
|
list = &chptr->exceptlist; |
251 |
|
|
clear_ban_cache(chptr); |
252 |
|
|
break; |
253 |
|
|
case CHFL_INVEX: |
254 |
|
|
list = &chptr->invexlist; |
255 |
|
|
break; |
256 |
|
|
default: |
257 |
michael |
2892 |
assert(0); |
258 |
michael |
593 |
return 0; |
259 |
adx |
30 |
} |
260 |
|
|
|
261 |
|
|
DLINK_FOREACH(ban, list->head) |
262 |
|
|
{ |
263 |
|
|
banptr = ban->data; |
264 |
|
|
|
265 |
|
|
if (!irccmp(name, banptr->name) && |
266 |
michael |
2296 |
!irccmp(user, banptr->user) && |
267 |
michael |
593 |
!irccmp(host, banptr->host)) |
268 |
adx |
30 |
{ |
269 |
|
|
remove_ban(banptr, list); |
270 |
|
|
return 1; |
271 |
|
|
} |
272 |
|
|
} |
273 |
|
|
|
274 |
|
|
return 0; |
275 |
|
|
} |
276 |
|
|
|
277 |
michael |
2892 |
const struct mode_letter chan_modes[] = |
278 |
|
|
{ |
279 |
michael |
1937 |
{ MODE_NOCTRL, 'c' }, |
280 |
adx |
30 |
{ MODE_INVITEONLY, 'i' }, |
281 |
|
|
{ MODE_MODERATED, 'm' }, |
282 |
|
|
{ MODE_NOPRIVMSGS, 'n' }, |
283 |
|
|
{ MODE_PRIVATE, 'p' }, |
284 |
michael |
1167 |
{ MODE_REGISTERED, 'r' }, |
285 |
adx |
30 |
{ MODE_SECRET, 's' }, |
286 |
|
|
{ MODE_TOPICLIMIT, 't' }, |
287 |
michael |
1954 |
{ MODE_MODREG, 'M' }, |
288 |
michael |
1150 |
{ MODE_OPERONLY, 'O' }, |
289 |
michael |
1175 |
{ MODE_REGONLY, 'R' }, |
290 |
michael |
1150 |
{ MODE_SSLONLY, 'S' }, |
291 |
adx |
30 |
{ 0, '\0' } |
292 |
|
|
}; |
293 |
|
|
|
294 |
|
|
/* channel_modes() |
295 |
|
|
* |
296 |
|
|
* inputs - pointer to channel |
297 |
|
|
* - pointer to client |
298 |
|
|
* - pointer to mode buf |
299 |
|
|
* - pointer to parameter buf |
300 |
|
|
* output - NONE |
301 |
|
|
* side effects - write the "simple" list of channel modes for channel |
302 |
|
|
* chptr onto buffer mbuf with the parameters in pbuf. |
303 |
|
|
*/ |
304 |
|
|
void |
305 |
|
|
channel_modes(struct Channel *chptr, struct Client *client_p, |
306 |
|
|
char *mbuf, char *pbuf) |
307 |
|
|
{ |
308 |
michael |
1175 |
const struct mode_letter *tab = chan_modes; |
309 |
adx |
30 |
|
310 |
|
|
*mbuf++ = '+'; |
311 |
|
|
*pbuf = '\0'; |
312 |
|
|
|
313 |
michael |
1175 |
for (; tab->mode; ++tab) |
314 |
|
|
if (chptr->mode.mode & tab->mode) |
315 |
|
|
*mbuf++ = tab->letter; |
316 |
adx |
30 |
|
317 |
|
|
if (chptr->mode.limit) |
318 |
|
|
{ |
319 |
|
|
*mbuf++ = 'l'; |
320 |
|
|
|
321 |
michael |
1219 |
if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE) || IsMember(client_p, chptr)) |
322 |
michael |
1793 |
pbuf += sprintf(pbuf, "%d ", chptr->mode.limit); |
323 |
adx |
30 |
} |
324 |
|
|
|
325 |
|
|
if (chptr->mode.key[0]) |
326 |
|
|
{ |
327 |
|
|
*mbuf++ = 'k'; |
328 |
|
|
|
329 |
michael |
1219 |
if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE) || IsMember(client_p, chptr)) |
330 |
michael |
1793 |
sprintf(pbuf, "%s ", chptr->mode.key); |
331 |
adx |
30 |
} |
332 |
|
|
|
333 |
|
|
*mbuf = '\0'; |
334 |
|
|
} |
335 |
|
|
|
336 |
|
|
/* fix_key() |
337 |
michael |
2892 |
* |
338 |
adx |
30 |
* inputs - pointer to key to clean up |
339 |
|
|
* output - pointer to cleaned up key |
340 |
|
|
* side effects - input string is modified |
341 |
|
|
* |
342 |
|
|
* stolen from Undernet's ircd -orabidoo |
343 |
|
|
*/ |
344 |
|
|
static char * |
345 |
|
|
fix_key(char *arg) |
346 |
|
|
{ |
347 |
|
|
unsigned char *s, *t, c; |
348 |
|
|
|
349 |
|
|
for (s = t = (unsigned char *)arg; (c = *s); s++) |
350 |
|
|
{ |
351 |
|
|
c &= 0x7f; |
352 |
michael |
2892 |
|
353 |
adx |
30 |
if (c != ':' && c > ' ' && c != ',') |
354 |
|
|
*t++ = c; |
355 |
|
|
} |
356 |
|
|
|
357 |
|
|
*t = '\0'; |
358 |
michael |
2892 |
return arg; |
359 |
adx |
30 |
} |
360 |
|
|
|
361 |
|
|
/* fix_key_old() |
362 |
michael |
2892 |
* |
363 |
adx |
30 |
* inputs - pointer to key to clean up |
364 |
|
|
* output - pointer to cleaned up key |
365 |
michael |
2892 |
* side effects - input string is modifed |
366 |
adx |
30 |
* |
367 |
|
|
* Here we attempt to be compatible with older non-hybrid servers. |
368 |
|
|
* We can't back down from the ':' issue however. --Rodder |
369 |
|
|
*/ |
370 |
|
|
static char * |
371 |
|
|
fix_key_old(char *arg) |
372 |
|
|
{ |
373 |
|
|
unsigned char *s, *t, c; |
374 |
|
|
|
375 |
|
|
for (s = t = (unsigned char *)arg; (c = *s); s++) |
376 |
|
|
{ |
377 |
|
|
c &= 0x7f; |
378 |
michael |
2892 |
|
379 |
|
|
if ((c != 0x0a) && (c != ':') && |
380 |
|
|
(c != 0x0d) && (c != ',')) |
381 |
adx |
30 |
*t++ = c; |
382 |
|
|
} |
383 |
|
|
|
384 |
|
|
*t = '\0'; |
385 |
michael |
2892 |
return arg; |
386 |
adx |
30 |
} |
387 |
|
|
|
388 |
|
|
/* bitmasks for various error returns that set_channel_mode should only return |
389 |
|
|
* once per call -orabidoo |
390 |
|
|
*/ |
391 |
|
|
|
392 |
|
|
#define SM_ERR_NOTS 0x00000001 /* No TS on channel */ |
393 |
|
|
#define SM_ERR_NOOPS 0x00000002 /* No chan ops */ |
394 |
|
|
#define SM_ERR_UNKNOWN 0x00000004 |
395 |
|
|
#define SM_ERR_RPL_B 0x00000008 |
396 |
|
|
#define SM_ERR_RPL_E 0x00000010 |
397 |
|
|
#define SM_ERR_NOTONCHANNEL 0x00000020 /* Not on channel */ |
398 |
|
|
#define SM_ERR_RPL_I 0x00000040 |
399 |
michael |
1150 |
#define SM_ERR_NOTOPER 0x00000080 |
400 |
michael |
1167 |
#define SM_ERR_ONLYSERVER 0x00000100 |
401 |
adx |
30 |
|
402 |
|
|
/* Now lets do some stuff to keep track of what combinations of |
403 |
|
|
* servers exist... |
404 |
|
|
* Note that the number of combinations doubles each time you add |
405 |
|
|
* something to this list. Each one is only quick if no servers use that |
406 |
|
|
* combination, but if the numbers get too high here MODE will get too |
407 |
|
|
* slow. I suggest if you get more than 7 here, you consider getting rid |
408 |
|
|
* of some and merging or something. If it wasn't for irc+cs we would |
409 |
|
|
* probably not even need to bother about most of these, but unfortunately |
410 |
|
|
* we do. -A1kmm |
411 |
|
|
*/ |
412 |
|
|
|
413 |
|
|
/* void init_chcap_usage_counts(void) |
414 |
|
|
* |
415 |
|
|
* Inputs - none |
416 |
|
|
* Output - none |
417 |
|
|
* Side-effects - Initialises the usage counts to zero. Fills in the |
418 |
|
|
* chcap_yes and chcap_no combination tables. |
419 |
|
|
*/ |
420 |
|
|
void |
421 |
|
|
init_chcap_usage_counts(void) |
422 |
|
|
{ |
423 |
|
|
unsigned long m, c, y, n; |
424 |
|
|
|
425 |
|
|
memset(chcap_combos, 0, sizeof(chcap_combos)); |
426 |
|
|
|
427 |
|
|
/* For every possible combination */ |
428 |
|
|
for (m = 0; m < NCHCAP_COMBOS; m++) |
429 |
|
|
{ |
430 |
|
|
/* Check each capab */ |
431 |
|
|
for (c = y = n = 0; c < NCHCAPS; c++) |
432 |
|
|
{ |
433 |
|
|
if ((m & (1 << c)) == 0) |
434 |
|
|
n |= channel_capabs[c]; |
435 |
|
|
else |
436 |
|
|
y |= channel_capabs[c]; |
437 |
|
|
} |
438 |
michael |
2892 |
|
439 |
adx |
30 |
chcap_combos[m].cap_yes = y; |
440 |
|
|
chcap_combos[m].cap_no = n; |
441 |
|
|
} |
442 |
|
|
} |
443 |
|
|
|
444 |
|
|
/* void set_chcap_usage_counts(struct Client *serv_p) |
445 |
|
|
* Input: serv_p; The client whose capabs to register. |
446 |
|
|
* Output: none |
447 |
|
|
* Side-effects: Increments the usage counts for the correct capab |
448 |
|
|
* combination. |
449 |
|
|
*/ |
450 |
|
|
void |
451 |
|
|
set_chcap_usage_counts(struct Client *serv_p) |
452 |
|
|
{ |
453 |
|
|
int n; |
454 |
|
|
|
455 |
|
|
for (n = 0; n < NCHCAP_COMBOS; n++) |
456 |
|
|
{ |
457 |
|
|
if (((serv_p->localClient->caps & chcap_combos[n].cap_yes) == |
458 |
|
|
chcap_combos[n].cap_yes) && |
459 |
|
|
((serv_p->localClient->caps & chcap_combos[n].cap_no) == 0)) |
460 |
|
|
{ |
461 |
|
|
chcap_combos[n].count++; |
462 |
|
|
return; |
463 |
|
|
} |
464 |
|
|
} |
465 |
|
|
|
466 |
|
|
/* This should be impossible -A1kmm. */ |
467 |
|
|
assert(0); |
468 |
|
|
} |
469 |
|
|
|
470 |
|
|
/* void set_chcap_usage_counts(struct Client *serv_p) |
471 |
|
|
* |
472 |
|
|
* Inputs - serv_p; The client whose capabs to register. |
473 |
|
|
* Output - none |
474 |
|
|
* Side-effects - Decrements the usage counts for the correct capab |
475 |
|
|
* combination. |
476 |
|
|
*/ |
477 |
|
|
void |
478 |
|
|
unset_chcap_usage_counts(struct Client *serv_p) |
479 |
|
|
{ |
480 |
|
|
int n; |
481 |
|
|
|
482 |
|
|
for (n = 0; n < NCHCAP_COMBOS; n++) |
483 |
|
|
{ |
484 |
|
|
if ((serv_p->localClient->caps & chcap_combos[n].cap_yes) == |
485 |
|
|
chcap_combos[n].cap_yes && |
486 |
|
|
(serv_p->localClient->caps & chcap_combos[n].cap_no) == 0) |
487 |
|
|
{ |
488 |
|
|
/* Hopefully capabs can't change dynamically or anything... */ |
489 |
|
|
assert(chcap_combos[n].count > 0); |
490 |
|
|
chcap_combos[n].count--; |
491 |
|
|
return; |
492 |
|
|
} |
493 |
|
|
} |
494 |
|
|
|
495 |
|
|
/* This should be impossible -A1kmm. */ |
496 |
|
|
assert(0); |
497 |
|
|
} |
498 |
|
|
|
499 |
|
|
/* Mode functions handle mode changes for a particular mode... */ |
500 |
|
|
static void |
501 |
|
|
chm_nosuch(struct Client *client_p, struct Client *source_p, |
502 |
|
|
struct Channel *chptr, int parc, int *parn, |
503 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
504 |
adx |
30 |
{ |
505 |
|
|
if (*errors & SM_ERR_UNKNOWN) |
506 |
|
|
return; |
507 |
|
|
|
508 |
|
|
*errors |= SM_ERR_UNKNOWN; |
509 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, |
510 |
adx |
30 |
source_p->name, c); |
511 |
|
|
} |
512 |
|
|
|
513 |
|
|
static void |
514 |
|
|
chm_simple(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
515 |
|
|
int parc, int *parn, char **parv, int *errors, int alev, int dir, |
516 |
michael |
2937 |
char c, unsigned int d) |
517 |
adx |
30 |
{ |
518 |
|
|
if ((alev < CHACCESS_HALFOP) || |
519 |
michael |
2937 |
((d == MODE_PRIVATE) && (alev < CHACCESS_CHANOP))) |
520 |
adx |
30 |
{ |
521 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
522 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
523 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
524 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
525 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
526 |
|
|
return; |
527 |
|
|
} |
528 |
|
|
|
529 |
|
|
/* If have already dealt with this simple mode, ignore it */ |
530 |
michael |
2937 |
if (simple_modes_mask & d) |
531 |
adx |
30 |
return; |
532 |
|
|
|
533 |
michael |
2937 |
simple_modes_mask |= d; |
534 |
adx |
30 |
|
535 |
|
|
/* setting + */ |
536 |
michael |
2892 |
/* Apparently, (though no one has ever told the hybrid group directly) |
537 |
|
|
* admins don't like redundant mode checking. ok. It would have been nice |
538 |
|
|
* if you had have told us directly. I've left the original code snippets |
539 |
|
|
* in place. |
540 |
|
|
* |
541 |
|
|
* -Dianora |
542 |
|
|
*/ |
543 |
michael |
2937 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */ |
544 |
adx |
30 |
{ |
545 |
michael |
2937 |
chptr->mode.mode |= d; |
546 |
adx |
30 |
|
547 |
|
|
mode_changes[mode_count].letter = c; |
548 |
|
|
mode_changes[mode_count].dir = MODE_ADD; |
549 |
|
|
mode_changes[mode_count].caps = 0; |
550 |
|
|
mode_changes[mode_count].nocaps = 0; |
551 |
|
|
mode_changes[mode_count].id = NULL; |
552 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
553 |
|
|
mode_changes[mode_count++].arg = NULL; |
554 |
|
|
} |
555 |
michael |
2937 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */ |
556 |
adx |
30 |
{ |
557 |
|
|
/* setting - */ |
558 |
|
|
|
559 |
michael |
2937 |
chptr->mode.mode &= ~d; |
560 |
adx |
30 |
|
561 |
|
|
mode_changes[mode_count].letter = c; |
562 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
563 |
|
|
mode_changes[mode_count].caps = 0; |
564 |
|
|
mode_changes[mode_count].nocaps = 0; |
565 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
566 |
|
|
mode_changes[mode_count].id = NULL; |
567 |
|
|
mode_changes[mode_count++].arg = NULL; |
568 |
|
|
} |
569 |
|
|
} |
570 |
|
|
|
571 |
|
|
static void |
572 |
michael |
1167 |
chm_registered(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
573 |
|
|
int parc, int *parn, char **parv, int *errors, int alev, int dir, |
574 |
michael |
2937 |
char c, unsigned int d) |
575 |
michael |
1167 |
{ |
576 |
michael |
1219 |
if (!IsServer(source_p) && !HasFlag(source_p, FLAGS_SERVICE)) |
577 |
michael |
1167 |
{ |
578 |
|
|
if (!(*errors & SM_ERR_ONLYSERVER)) |
579 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
580 |
|
|
ERR_NOTONCHANNEL : ERR_ONLYSERVERSCANCHANGE), |
581 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
582 |
michael |
1167 |
*errors |= SM_ERR_ONLYSERVER; |
583 |
|
|
return; |
584 |
|
|
} |
585 |
|
|
|
586 |
|
|
/* If have already dealt with this simple mode, ignore it */ |
587 |
michael |
2937 |
if (simple_modes_mask & d) |
588 |
michael |
1167 |
return; |
589 |
|
|
|
590 |
michael |
2937 |
simple_modes_mask |= d; |
591 |
michael |
1167 |
|
592 |
|
|
/* setting + */ |
593 |
michael |
2892 |
/* Apparently, (though no one has ever told the hybrid group directly) |
594 |
|
|
* admins don't like redundant mode checking. ok. It would have been nice |
595 |
|
|
* if you had have told us directly. I've left the original code snippets |
596 |
|
|
* in place. |
597 |
|
|
* |
598 |
|
|
* -Dianora |
599 |
michael |
1167 |
*/ |
600 |
michael |
2937 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */ |
601 |
michael |
1167 |
{ |
602 |
michael |
2937 |
chptr->mode.mode |= d; |
603 |
michael |
1167 |
|
604 |
|
|
mode_changes[mode_count].letter = c; |
605 |
|
|
mode_changes[mode_count].dir = MODE_ADD; |
606 |
|
|
mode_changes[mode_count].caps = 0; |
607 |
|
|
mode_changes[mode_count].nocaps = 0; |
608 |
|
|
mode_changes[mode_count].id = NULL; |
609 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
610 |
|
|
mode_changes[mode_count++].arg = NULL; |
611 |
|
|
} |
612 |
michael |
2937 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */ |
613 |
michael |
1167 |
{ |
614 |
|
|
/* setting - */ |
615 |
|
|
|
616 |
michael |
2937 |
chptr->mode.mode &= ~d; |
617 |
michael |
1167 |
|
618 |
|
|
mode_changes[mode_count].letter = c; |
619 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
620 |
|
|
mode_changes[mode_count].caps = 0; |
621 |
|
|
mode_changes[mode_count].nocaps = 0; |
622 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
623 |
|
|
mode_changes[mode_count].id = NULL; |
624 |
|
|
mode_changes[mode_count++].arg = NULL; |
625 |
|
|
} |
626 |
|
|
} |
627 |
|
|
|
628 |
|
|
static void |
629 |
michael |
1150 |
chm_operonly(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
630 |
|
|
int parc, int *parn, char **parv, int *errors, int alev, int dir, |
631 |
michael |
2937 |
char c, unsigned int d) |
632 |
michael |
1150 |
{ |
633 |
|
|
if ((alev < CHACCESS_HALFOP) || |
634 |
michael |
2937 |
((d == MODE_PRIVATE) && (alev < CHACCESS_CHANOP))) |
635 |
michael |
1150 |
{ |
636 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
637 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
638 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
639 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
640 |
michael |
1150 |
*errors |= SM_ERR_NOOPS; |
641 |
|
|
return; |
642 |
|
|
} |
643 |
michael |
1219 |
else if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER)) |
644 |
michael |
1150 |
{ |
645 |
|
|
if (!(*errors & SM_ERR_NOTOPER)) |
646 |
|
|
{ |
647 |
|
|
if (alev == CHACCESS_NOTONCHAN) |
648 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
649 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
650 |
michael |
1150 |
else |
651 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
652 |
michael |
1150 |
me.name, source_p->name); |
653 |
|
|
} |
654 |
|
|
|
655 |
|
|
*errors |= SM_ERR_NOTOPER; |
656 |
|
|
return; |
657 |
|
|
} |
658 |
|
|
|
659 |
|
|
/* If have already dealt with this simple mode, ignore it */ |
660 |
michael |
2937 |
if (simple_modes_mask & d) |
661 |
michael |
1150 |
return; |
662 |
|
|
|
663 |
michael |
2937 |
simple_modes_mask |= d; |
664 |
michael |
1150 |
|
665 |
michael |
2937 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */ |
666 |
michael |
1150 |
{ |
667 |
michael |
2937 |
chptr->mode.mode |= d; |
668 |
michael |
1150 |
|
669 |
|
|
mode_changes[mode_count].letter = c; |
670 |
|
|
mode_changes[mode_count].dir = MODE_ADD; |
671 |
|
|
mode_changes[mode_count].caps = 0; |
672 |
|
|
mode_changes[mode_count].nocaps = 0; |
673 |
|
|
mode_changes[mode_count].id = NULL; |
674 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
675 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
676 |
|
|
mode_changes[mode_count++].arg = NULL; |
677 |
|
|
} |
678 |
michael |
2937 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */ |
679 |
michael |
1150 |
{ |
680 |
|
|
/* setting - */ |
681 |
|
|
|
682 |
michael |
2937 |
chptr->mode.mode &= ~d; |
683 |
michael |
1150 |
|
684 |
|
|
mode_changes[mode_count].letter = c; |
685 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
686 |
|
|
mode_changes[mode_count].caps = 0; |
687 |
|
|
mode_changes[mode_count].nocaps = 0; |
688 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
689 |
|
|
mode_changes[mode_count].id = NULL; |
690 |
|
|
mode_changes[mode_count++].arg = NULL; |
691 |
|
|
} |
692 |
|
|
} |
693 |
|
|
|
694 |
|
|
static void |
695 |
adx |
30 |
chm_ban(struct Client *client_p, struct Client *source_p, |
696 |
|
|
struct Channel *chptr, int parc, int *parn, |
697 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
698 |
adx |
30 |
{ |
699 |
|
|
char *mask = NULL; |
700 |
|
|
|
701 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
702 |
|
|
{ |
703 |
|
|
dlink_node *ptr = NULL; |
704 |
|
|
|
705 |
|
|
if (*errors & SM_ERR_RPL_B) |
706 |
|
|
return; |
707 |
|
|
|
708 |
|
|
*errors |= SM_ERR_RPL_B; |
709 |
|
|
|
710 |
|
|
DLINK_FOREACH(ptr, chptr->banlist.head) |
711 |
|
|
{ |
712 |
|
|
const struct Ban *banptr = ptr->data; |
713 |
michael |
1834 |
sendto_one(client_p, form_str(RPL_BANLIST), |
714 |
michael |
2937 |
me.name, client_p->name, chptr->chname, |
715 |
michael |
2296 |
banptr->name, banptr->user, banptr->host, |
716 |
michael |
2892 |
banptr->who, banptr->when); |
717 |
adx |
30 |
} |
718 |
|
|
|
719 |
michael |
1834 |
sendto_one(source_p, form_str(RPL_ENDOFBANLIST), me.name, |
720 |
michael |
2937 |
source_p->name, chptr->chname); |
721 |
adx |
30 |
return; |
722 |
|
|
} |
723 |
|
|
|
724 |
|
|
if (alev < CHACCESS_HALFOP) |
725 |
|
|
{ |
726 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
727 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
728 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
729 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
730 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
731 |
|
|
return; |
732 |
|
|
} |
733 |
|
|
|
734 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
735 |
|
|
return; |
736 |
|
|
|
737 |
michael |
388 |
mask = nuh_mask[*parn]; |
738 |
|
|
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
739 |
|
|
++*parn; |
740 |
|
|
|
741 |
adx |
30 |
if (IsServer(client_p)) |
742 |
|
|
if (strchr(mask, ' ')) |
743 |
|
|
return; |
744 |
|
|
|
745 |
|
|
switch (dir) |
746 |
|
|
{ |
747 |
|
|
case MODE_ADD: |
748 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_BAN)) |
749 |
|
|
return; |
750 |
|
|
break; |
751 |
|
|
case MODE_DEL: |
752 |
|
|
if (!del_id(chptr, mask, CHFL_BAN)) |
753 |
|
|
return; |
754 |
|
|
break; |
755 |
|
|
default: |
756 |
|
|
assert(0); |
757 |
|
|
} |
758 |
|
|
|
759 |
|
|
mode_changes[mode_count].letter = c; |
760 |
|
|
mode_changes[mode_count].dir = dir; |
761 |
|
|
mode_changes[mode_count].caps = 0; |
762 |
|
|
mode_changes[mode_count].nocaps = 0; |
763 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
764 |
|
|
mode_changes[mode_count].id = NULL; |
765 |
|
|
mode_changes[mode_count++].arg = mask; |
766 |
|
|
} |
767 |
|
|
|
768 |
|
|
static void |
769 |
|
|
chm_except(struct Client *client_p, struct Client *source_p, |
770 |
|
|
struct Channel *chptr, int parc, int *parn, |
771 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
772 |
adx |
30 |
{ |
773 |
|
|
char *mask = NULL; |
774 |
|
|
|
775 |
|
|
if (alev < CHACCESS_HALFOP) |
776 |
|
|
{ |
777 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
778 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
779 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
780 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
781 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
782 |
|
|
return; |
783 |
|
|
} |
784 |
|
|
|
785 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
786 |
|
|
{ |
787 |
|
|
dlink_node *ptr = NULL; |
788 |
|
|
|
789 |
|
|
if (*errors & SM_ERR_RPL_E) |
790 |
|
|
return; |
791 |
|
|
|
792 |
|
|
*errors |= SM_ERR_RPL_E; |
793 |
|
|
|
794 |
|
|
DLINK_FOREACH(ptr, chptr->exceptlist.head) |
795 |
|
|
{ |
796 |
|
|
const struct Ban *banptr = ptr->data; |
797 |
michael |
1834 |
sendto_one(client_p, form_str(RPL_EXCEPTLIST), |
798 |
michael |
2937 |
me.name, client_p->name, chptr->chname, |
799 |
michael |
2296 |
banptr->name, banptr->user, banptr->host, |
800 |
michael |
2892 |
banptr->who, banptr->when); |
801 |
adx |
30 |
} |
802 |
|
|
|
803 |
michael |
1834 |
sendto_one(source_p, form_str(RPL_ENDOFEXCEPTLIST), me.name, |
804 |
michael |
2937 |
source_p->name, chptr->chname); |
805 |
adx |
30 |
return; |
806 |
|
|
} |
807 |
|
|
|
808 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
809 |
|
|
return; |
810 |
|
|
|
811 |
michael |
388 |
mask = nuh_mask[*parn]; |
812 |
|
|
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
813 |
|
|
++*parn; |
814 |
adx |
30 |
|
815 |
|
|
if (IsServer(client_p)) |
816 |
|
|
if (strchr(mask, ' ')) |
817 |
|
|
return; |
818 |
|
|
|
819 |
|
|
switch (dir) |
820 |
|
|
{ |
821 |
|
|
case MODE_ADD: |
822 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION)) |
823 |
|
|
return; |
824 |
|
|
break; |
825 |
|
|
case MODE_DEL: |
826 |
|
|
if (!del_id(chptr, mask, CHFL_EXCEPTION)) |
827 |
|
|
return; |
828 |
|
|
break; |
829 |
|
|
default: |
830 |
|
|
assert(0); |
831 |
|
|
} |
832 |
|
|
|
833 |
|
|
mode_changes[mode_count].letter = c; |
834 |
|
|
mode_changes[mode_count].dir = dir; |
835 |
michael |
1684 |
mode_changes[mode_count].caps = 0; |
836 |
adx |
30 |
mode_changes[mode_count].nocaps = 0; |
837 |
michael |
1495 |
mode_changes[mode_count].mems = ONLY_CHANOPS; |
838 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
839 |
|
|
mode_changes[mode_count++].arg = mask; |
840 |
|
|
} |
841 |
|
|
|
842 |
|
|
static void |
843 |
|
|
chm_invex(struct Client *client_p, struct Client *source_p, |
844 |
|
|
struct Channel *chptr, int parc, int *parn, |
845 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
846 |
adx |
30 |
{ |
847 |
|
|
char *mask = NULL; |
848 |
|
|
|
849 |
|
|
if (alev < CHACCESS_HALFOP) |
850 |
|
|
{ |
851 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
852 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
853 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
854 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
855 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
856 |
|
|
return; |
857 |
|
|
} |
858 |
|
|
|
859 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
860 |
|
|
{ |
861 |
|
|
dlink_node *ptr = NULL; |
862 |
|
|
|
863 |
|
|
if (*errors & SM_ERR_RPL_I) |
864 |
|
|
return; |
865 |
|
|
|
866 |
|
|
*errors |= SM_ERR_RPL_I; |
867 |
|
|
|
868 |
|
|
DLINK_FOREACH(ptr, chptr->invexlist.head) |
869 |
|
|
{ |
870 |
|
|
const struct Ban *banptr = ptr->data; |
871 |
michael |
1834 |
sendto_one(client_p, form_str(RPL_INVITELIST), me.name, |
872 |
michael |
2937 |
client_p->name, chptr->chname, |
873 |
michael |
2892 |
banptr->name, banptr->user, banptr->host, |
874 |
adx |
30 |
banptr->who, banptr->when); |
875 |
|
|
} |
876 |
|
|
|
877 |
michael |
1834 |
sendto_one(source_p, form_str(RPL_ENDOFINVITELIST), me.name, |
878 |
michael |
2937 |
source_p->name, chptr->chname); |
879 |
adx |
30 |
return; |
880 |
|
|
} |
881 |
|
|
|
882 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
883 |
|
|
return; |
884 |
|
|
|
885 |
michael |
388 |
mask = nuh_mask[*parn]; |
886 |
|
|
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
887 |
|
|
++*parn; |
888 |
adx |
30 |
|
889 |
|
|
if (IsServer(client_p)) |
890 |
|
|
if (strchr(mask, ' ')) |
891 |
|
|
return; |
892 |
|
|
|
893 |
|
|
switch (dir) |
894 |
|
|
{ |
895 |
|
|
case MODE_ADD: |
896 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_INVEX)) |
897 |
|
|
return; |
898 |
|
|
break; |
899 |
|
|
case MODE_DEL: |
900 |
|
|
if (!del_id(chptr, mask, CHFL_INVEX)) |
901 |
|
|
return; |
902 |
|
|
break; |
903 |
|
|
default: |
904 |
|
|
assert(0); |
905 |
|
|
} |
906 |
|
|
|
907 |
|
|
mode_changes[mode_count].letter = c; |
908 |
|
|
mode_changes[mode_count].dir = dir; |
909 |
michael |
1684 |
mode_changes[mode_count].caps = 0; |
910 |
adx |
30 |
mode_changes[mode_count].nocaps = 0; |
911 |
michael |
1495 |
mode_changes[mode_count].mems = ONLY_CHANOPS; |
912 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
913 |
|
|
mode_changes[mode_count++].arg = mask; |
914 |
|
|
} |
915 |
|
|
|
916 |
|
|
/* |
917 |
|
|
* inputs - pointer to channel |
918 |
|
|
* output - none |
919 |
|
|
* side effects - clear ban cache |
920 |
|
|
*/ |
921 |
|
|
void |
922 |
|
|
clear_ban_cache(struct Channel *chptr) |
923 |
|
|
{ |
924 |
|
|
dlink_node *ptr = NULL; |
925 |
|
|
|
926 |
michael |
572 |
DLINK_FOREACH(ptr, chptr->members.head) |
927 |
adx |
30 |
{ |
928 |
|
|
struct Membership *ms = ptr->data; |
929 |
michael |
572 |
|
930 |
|
|
if (MyConnect(ms->client_p)) |
931 |
|
|
ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED); |
932 |
adx |
30 |
} |
933 |
|
|
} |
934 |
|
|
|
935 |
michael |
759 |
void |
936 |
|
|
clear_ban_cache_client(struct Client *client_p) |
937 |
|
|
{ |
938 |
|
|
dlink_node *ptr = NULL; |
939 |
|
|
|
940 |
michael |
760 |
DLINK_FOREACH(ptr, client_p->channel.head) |
941 |
michael |
759 |
{ |
942 |
|
|
struct Membership *ms = ptr->data; |
943 |
|
|
ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED); |
944 |
|
|
} |
945 |
|
|
} |
946 |
|
|
|
947 |
adx |
30 |
static void |
948 |
|
|
chm_op(struct Client *client_p, struct Client *source_p, |
949 |
|
|
struct Channel *chptr, int parc, int *parn, |
950 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
951 |
adx |
30 |
{ |
952 |
michael |
2892 |
const char *opnick = NULL; |
953 |
adx |
30 |
struct Client *targ_p; |
954 |
|
|
struct Membership *member; |
955 |
adx |
356 |
int caps = 0; |
956 |
adx |
30 |
|
957 |
|
|
if (alev < CHACCESS_CHANOP) |
958 |
|
|
{ |
959 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
960 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
961 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
962 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
963 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
964 |
|
|
return; |
965 |
|
|
} |
966 |
|
|
|
967 |
|
|
if ((dir == MODE_QUERY) || (parc <= *parn)) |
968 |
|
|
return; |
969 |
|
|
|
970 |
|
|
opnick = parv[(*parn)++]; |
971 |
|
|
|
972 |
michael |
2475 |
if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) |
973 |
adx |
30 |
return; |
974 |
|
|
if (!IsClient(targ_p)) |
975 |
|
|
return; |
976 |
|
|
|
977 |
|
|
if ((member = find_channel_link(targ_p, chptr)) == NULL) |
978 |
|
|
{ |
979 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
980 |
michael |
2937 |
sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), me.name, |
981 |
|
|
source_p->name, opnick, chptr->chname); |
982 |
adx |
30 |
*errors |= SM_ERR_NOTONCHANNEL; |
983 |
|
|
return; |
984 |
|
|
} |
985 |
|
|
|
986 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
987 |
|
|
return; |
988 |
|
|
|
989 |
|
|
/* no redundant mode changes */ |
990 |
|
|
if (dir == MODE_ADD && has_member_flags(member, CHFL_CHANOP)) |
991 |
|
|
return; |
992 |
|
|
if (dir == MODE_DEL && !has_member_flags(member, CHFL_CHANOP)) |
993 |
adx |
356 |
{ |
994 |
|
|
#ifdef HALFOPS |
995 |
|
|
if (has_member_flags(member, CHFL_HALFOP)) |
996 |
db |
931 |
{ |
997 |
|
|
--*parn; |
998 |
adx |
356 |
chm_hop(client_p, source_p, chptr, parc, parn, parv, errors, alev, |
999 |
michael |
2937 |
dir, c, d); |
1000 |
db |
931 |
} |
1001 |
adx |
356 |
#endif |
1002 |
adx |
30 |
return; |
1003 |
adx |
356 |
} |
1004 |
adx |
30 |
|
1005 |
adx |
356 |
#ifdef HALFOPS |
1006 |
|
|
if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP)) |
1007 |
|
|
{ |
1008 |
|
|
/* promoting from % to @ is visible only to CAP_HOPS servers */ |
1009 |
|
|
mode_changes[mode_count].letter = 'h'; |
1010 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
1011 |
|
|
mode_changes[mode_count].caps = caps = CAP_HOPS; |
1012 |
|
|
mode_changes[mode_count].nocaps = 0; |
1013 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1014 |
|
|
mode_changes[mode_count].id = NULL; |
1015 |
|
|
mode_changes[mode_count].arg = targ_p->name; |
1016 |
|
|
mode_changes[mode_count++].client = targ_p; |
1017 |
|
|
} |
1018 |
|
|
#endif |
1019 |
|
|
|
1020 |
adx |
30 |
mode_changes[mode_count].letter = 'o'; |
1021 |
|
|
mode_changes[mode_count].dir = dir; |
1022 |
adx |
356 |
mode_changes[mode_count].caps = caps; |
1023 |
adx |
30 |
mode_changes[mode_count].nocaps = 0; |
1024 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1025 |
|
|
mode_changes[mode_count].id = targ_p->id; |
1026 |
|
|
mode_changes[mode_count].arg = targ_p->name; |
1027 |
|
|
mode_changes[mode_count++].client = targ_p; |
1028 |
|
|
|
1029 |
|
|
if (dir == MODE_ADD) |
1030 |
|
|
{ |
1031 |
|
|
AddMemberFlag(member, CHFL_CHANOP); |
1032 |
adx |
356 |
DelMemberFlag(member, CHFL_DEOPPED | CHFL_HALFOP); |
1033 |
adx |
30 |
} |
1034 |
|
|
else |
1035 |
|
|
DelMemberFlag(member, CHFL_CHANOP); |
1036 |
|
|
} |
1037 |
|
|
|
1038 |
|
|
#ifdef HALFOPS |
1039 |
|
|
static void |
1040 |
|
|
chm_hop(struct Client *client_p, struct Client *source_p, |
1041 |
|
|
struct Channel *chptr, int parc, int *parn, |
1042 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
1043 |
adx |
30 |
{ |
1044 |
michael |
2892 |
const char *opnick = NULL; |
1045 |
adx |
30 |
struct Client *targ_p; |
1046 |
|
|
struct Membership *member; |
1047 |
|
|
|
1048 |
|
|
/* *sigh* - dont allow halfops to set +/-h, they could fully control a |
1049 |
|
|
* channel if there were no ops - it doesnt solve anything.. MODE_PRIVATE |
1050 |
|
|
* when used with MODE_SECRET is paranoid - cant use +p |
1051 |
|
|
* |
1052 |
|
|
* it needs to be optional per channel - but not via +p, that or remove |
1053 |
|
|
* paranoid.. -- fl_ |
1054 |
|
|
* |
1055 |
|
|
* +p means paranoid, it is useless for anything else on modern IRC, as |
1056 |
|
|
* list isn't really usable. If you want to have a private channel these |
1057 |
|
|
* days, you set it +s. Halfops can no longer remove simple modes when |
1058 |
|
|
* +p is set (although they can set +p) so it is safe to use this to |
1059 |
|
|
* control whether they can (de)halfop... |
1060 |
|
|
*/ |
1061 |
|
|
if (alev < |
1062 |
|
|
((chptr->mode.mode & MODE_PRIVATE) ? CHACCESS_CHANOP : CHACCESS_HALFOP)) |
1063 |
|
|
{ |
1064 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
1065 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1066 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1067 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
1068 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
1069 |
|
|
return; |
1070 |
|
|
} |
1071 |
|
|
|
1072 |
|
|
if ((dir == MODE_QUERY) || (parc <= *parn)) |
1073 |
|
|
return; |
1074 |
|
|
|
1075 |
|
|
opnick = parv[(*parn)++]; |
1076 |
|
|
|
1077 |
michael |
2475 |
if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) |
1078 |
adx |
30 |
return; |
1079 |
|
|
if (!IsClient(targ_p)) |
1080 |
|
|
return; |
1081 |
|
|
|
1082 |
|
|
if ((member = find_channel_link(targ_p, chptr)) == NULL) |
1083 |
|
|
{ |
1084 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
1085 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), |
1086 |
michael |
2937 |
me.name, source_p->name, opnick, chptr->chname); |
1087 |
adx |
30 |
*errors |= SM_ERR_NOTONCHANNEL; |
1088 |
|
|
return; |
1089 |
|
|
} |
1090 |
|
|
|
1091 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
1092 |
|
|
return; |
1093 |
|
|
|
1094 |
|
|
/* no redundant mode changes */ |
1095 |
adx |
356 |
if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP | CHFL_CHANOP)) |
1096 |
adx |
30 |
return; |
1097 |
|
|
if (dir == MODE_DEL && !has_member_flags(member, CHFL_HALFOP)) |
1098 |
|
|
return; |
1099 |
|
|
|
1100 |
|
|
mode_changes[mode_count].letter = 'h'; |
1101 |
|
|
mode_changes[mode_count].dir = dir; |
1102 |
adx |
356 |
mode_changes[mode_count].caps = CAP_HOPS; |
1103 |
adx |
30 |
mode_changes[mode_count].nocaps = 0; |
1104 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1105 |
|
|
mode_changes[mode_count].id = targ_p->id; |
1106 |
|
|
mode_changes[mode_count].arg = targ_p->name; |
1107 |
|
|
mode_changes[mode_count++].client = targ_p; |
1108 |
|
|
|
1109 |
adx |
356 |
mode_changes[mode_count].letter = 'o'; |
1110 |
|
|
mode_changes[mode_count].dir = dir; |
1111 |
|
|
mode_changes[mode_count].caps = 0; |
1112 |
|
|
mode_changes[mode_count].nocaps = CAP_HOPS; |
1113 |
|
|
mode_changes[mode_count].mems = ONLY_SERVERS; |
1114 |
|
|
mode_changes[mode_count].id = targ_p->id; |
1115 |
|
|
mode_changes[mode_count].arg = targ_p->name; |
1116 |
|
|
mode_changes[mode_count++].client = targ_p; |
1117 |
|
|
|
1118 |
adx |
30 |
if (dir == MODE_ADD) |
1119 |
|
|
{ |
1120 |
|
|
AddMemberFlag(member, CHFL_HALFOP); |
1121 |
|
|
DelMemberFlag(member, CHFL_DEOPPED); |
1122 |
|
|
} |
1123 |
|
|
else |
1124 |
|
|
DelMemberFlag(member, CHFL_HALFOP); |
1125 |
|
|
} |
1126 |
|
|
#endif |
1127 |
|
|
|
1128 |
|
|
static void |
1129 |
|
|
chm_voice(struct Client *client_p, struct Client *source_p, |
1130 |
|
|
struct Channel *chptr, int parc, int *parn, |
1131 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
1132 |
adx |
30 |
{ |
1133 |
michael |
2892 |
const char *opnick = NULL; |
1134 |
adx |
30 |
struct Client *targ_p; |
1135 |
|
|
struct Membership *member; |
1136 |
|
|
|
1137 |
|
|
if (alev < CHACCESS_HALFOP) |
1138 |
|
|
{ |
1139 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
1140 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1141 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1142 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
1143 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
1144 |
|
|
return; |
1145 |
|
|
} |
1146 |
|
|
|
1147 |
|
|
if ((dir == MODE_QUERY) || parc <= *parn) |
1148 |
|
|
return; |
1149 |
|
|
|
1150 |
|
|
opnick = parv[(*parn)++]; |
1151 |
|
|
|
1152 |
michael |
2475 |
if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) |
1153 |
adx |
30 |
return; |
1154 |
|
|
if (!IsClient(targ_p)) |
1155 |
|
|
return; |
1156 |
|
|
|
1157 |
|
|
if ((member = find_channel_link(targ_p, chptr)) == NULL) |
1158 |
|
|
{ |
1159 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
1160 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), |
1161 |
michael |
2937 |
me.name, source_p->name, opnick, chptr->chname); |
1162 |
adx |
30 |
*errors |= SM_ERR_NOTONCHANNEL; |
1163 |
|
|
return; |
1164 |
|
|
} |
1165 |
|
|
|
1166 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
1167 |
|
|
return; |
1168 |
|
|
|
1169 |
|
|
/* no redundant mode changes */ |
1170 |
|
|
if (dir == MODE_ADD && has_member_flags(member, CHFL_VOICE)) |
1171 |
|
|
return; |
1172 |
|
|
if (dir == MODE_DEL && !has_member_flags(member, CHFL_VOICE)) |
1173 |
|
|
return; |
1174 |
|
|
|
1175 |
|
|
mode_changes[mode_count].letter = 'v'; |
1176 |
|
|
mode_changes[mode_count].dir = dir; |
1177 |
|
|
mode_changes[mode_count].caps = 0; |
1178 |
|
|
mode_changes[mode_count].nocaps = 0; |
1179 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1180 |
|
|
mode_changes[mode_count].id = targ_p->id; |
1181 |
|
|
mode_changes[mode_count].arg = targ_p->name; |
1182 |
|
|
mode_changes[mode_count++].client = targ_p; |
1183 |
|
|
|
1184 |
|
|
if (dir == MODE_ADD) |
1185 |
|
|
AddMemberFlag(member, CHFL_VOICE); |
1186 |
|
|
else |
1187 |
|
|
DelMemberFlag(member, CHFL_VOICE); |
1188 |
|
|
} |
1189 |
|
|
|
1190 |
|
|
static void |
1191 |
|
|
chm_limit(struct Client *client_p, struct Client *source_p, |
1192 |
|
|
struct Channel *chptr, int parc, int *parn, |
1193 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
1194 |
adx |
30 |
{ |
1195 |
|
|
int i, limit; |
1196 |
|
|
char *lstr; |
1197 |
|
|
|
1198 |
|
|
if (alev < CHACCESS_HALFOP) |
1199 |
|
|
{ |
1200 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
1201 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1202 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1203 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
1204 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
1205 |
|
|
return; |
1206 |
|
|
} |
1207 |
|
|
|
1208 |
|
|
if (dir == MODE_QUERY) |
1209 |
|
|
return; |
1210 |
|
|
|
1211 |
|
|
if ((dir == MODE_ADD) && parc > *parn) |
1212 |
|
|
{ |
1213 |
|
|
lstr = parv[(*parn)++]; |
1214 |
|
|
|
1215 |
|
|
if ((limit = atoi(lstr)) <= 0) |
1216 |
|
|
return; |
1217 |
|
|
|
1218 |
michael |
1793 |
sprintf(lstr, "%d", limit); |
1219 |
adx |
30 |
|
1220 |
|
|
/* if somebody sets MODE #channel +ll 1 2, accept latter --fl */ |
1221 |
|
|
for (i = 0; i < mode_count; i++) |
1222 |
|
|
if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD) |
1223 |
|
|
mode_changes[i].letter = 0; |
1224 |
|
|
|
1225 |
|
|
mode_changes[mode_count].letter = c; |
1226 |
|
|
mode_changes[mode_count].dir = MODE_ADD; |
1227 |
|
|
mode_changes[mode_count].caps = 0; |
1228 |
|
|
mode_changes[mode_count].nocaps = 0; |
1229 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1230 |
|
|
mode_changes[mode_count].id = NULL; |
1231 |
|
|
mode_changes[mode_count++].arg = lstr; |
1232 |
|
|
|
1233 |
|
|
chptr->mode.limit = limit; |
1234 |
|
|
} |
1235 |
|
|
else if (dir == MODE_DEL) |
1236 |
|
|
{ |
1237 |
|
|
if (!chptr->mode.limit) |
1238 |
|
|
return; |
1239 |
|
|
|
1240 |
|
|
chptr->mode.limit = 0; |
1241 |
|
|
|
1242 |
|
|
mode_changes[mode_count].letter = c; |
1243 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
1244 |
|
|
mode_changes[mode_count].caps = 0; |
1245 |
|
|
mode_changes[mode_count].nocaps = 0; |
1246 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1247 |
|
|
mode_changes[mode_count].id = NULL; |
1248 |
|
|
mode_changes[mode_count++].arg = NULL; |
1249 |
|
|
} |
1250 |
|
|
} |
1251 |
|
|
|
1252 |
|
|
static void |
1253 |
|
|
chm_key(struct Client *client_p, struct Client *source_p, |
1254 |
|
|
struct Channel *chptr, int parc, int *parn, |
1255 |
michael |
2937 |
char **parv, int *errors, int alev, int dir, char c, unsigned int d) |
1256 |
adx |
30 |
{ |
1257 |
|
|
int i; |
1258 |
|
|
char *key; |
1259 |
|
|
|
1260 |
|
|
if (alev < CHACCESS_HALFOP) |
1261 |
|
|
{ |
1262 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
1263 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1264 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1265 |
michael |
2937 |
me.name, source_p->name, chptr->chname); |
1266 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
1267 |
|
|
return; |
1268 |
|
|
} |
1269 |
|
|
|
1270 |
|
|
if (dir == MODE_QUERY) |
1271 |
|
|
return; |
1272 |
|
|
|
1273 |
|
|
if ((dir == MODE_ADD) && parc > *parn) |
1274 |
|
|
{ |
1275 |
|
|
key = parv[(*parn)++]; |
1276 |
|
|
|
1277 |
|
|
if (MyClient(source_p)) |
1278 |
|
|
fix_key(key); |
1279 |
|
|
else |
1280 |
|
|
fix_key_old(key); |
1281 |
|
|
|
1282 |
|
|
if (*key == '\0') |
1283 |
|
|
return; |
1284 |
|
|
|
1285 |
|
|
assert(key[0] != ' '); |
1286 |
|
|
strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); |
1287 |
|
|
|
1288 |
|
|
/* if somebody does MODE #channel +kk a b, accept latter --fl */ |
1289 |
|
|
for (i = 0; i < mode_count; i++) |
1290 |
|
|
if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD) |
1291 |
|
|
mode_changes[i].letter = 0; |
1292 |
|
|
|
1293 |
|
|
mode_changes[mode_count].letter = c; |
1294 |
|
|
mode_changes[mode_count].dir = MODE_ADD; |
1295 |
|
|
mode_changes[mode_count].caps = 0; |
1296 |
|
|
mode_changes[mode_count].nocaps = 0; |
1297 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1298 |
|
|
mode_changes[mode_count].id = NULL; |
1299 |
|
|
mode_changes[mode_count++].arg = chptr->mode.key; |
1300 |
|
|
} |
1301 |
|
|
else if (dir == MODE_DEL) |
1302 |
|
|
{ |
1303 |
|
|
if (parc > *parn) |
1304 |
|
|
(*parn)++; |
1305 |
|
|
|
1306 |
|
|
if (chptr->mode.key[0] == '\0') |
1307 |
|
|
return; |
1308 |
|
|
|
1309 |
|
|
chptr->mode.key[0] = '\0'; |
1310 |
|
|
|
1311 |
|
|
mode_changes[mode_count].letter = c; |
1312 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
1313 |
|
|
mode_changes[mode_count].caps = 0; |
1314 |
|
|
mode_changes[mode_count].nocaps = 0; |
1315 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1316 |
|
|
mode_changes[mode_count].id = NULL; |
1317 |
|
|
mode_changes[mode_count++].arg = "*"; |
1318 |
|
|
} |
1319 |
|
|
} |
1320 |
|
|
|
1321 |
|
|
struct ChannelMode |
1322 |
|
|
{ |
1323 |
michael |
2937 |
void (*func)(struct Client *, struct Client *, |
1324 |
|
|
struct Channel *, int, int *, char **, |
1325 |
|
|
int *, int, int, char, unsigned int); |
1326 |
|
|
unsigned int d; |
1327 |
adx |
30 |
}; |
1328 |
|
|
|
1329 |
|
|
static struct ChannelMode ModeTable[255] = |
1330 |
|
|
{ |
1331 |
michael |
2937 |
{chm_nosuch, 0}, |
1332 |
|
|
{chm_nosuch, 0}, /* A */ |
1333 |
|
|
{chm_nosuch, 0}, /* B */ |
1334 |
|
|
{chm_nosuch, 0}, /* C */ |
1335 |
|
|
{chm_nosuch, 0}, /* D */ |
1336 |
|
|
{chm_nosuch, 0}, /* E */ |
1337 |
|
|
{chm_nosuch, 0}, /* F */ |
1338 |
|
|
{chm_nosuch, 0}, /* G */ |
1339 |
|
|
{chm_nosuch, 0}, /* H */ |
1340 |
|
|
{chm_invex, 0}, /* I */ |
1341 |
|
|
{chm_nosuch, 0}, /* J */ |
1342 |
|
|
{chm_nosuch, 0}, /* K */ |
1343 |
|
|
{chm_nosuch, 0}, /* L */ |
1344 |
|
|
{chm_simple, MODE_MODREG}, /* M */ |
1345 |
|
|
{chm_nosuch, 0}, /* N */ |
1346 |
|
|
{chm_operonly, MODE_OPERONLY}, /* O */ |
1347 |
|
|
{chm_nosuch, 0}, /* P */ |
1348 |
|
|
{chm_nosuch, 0}, /* Q */ |
1349 |
|
|
{chm_simple, MODE_REGONLY}, /* R */ |
1350 |
|
|
{chm_simple, MODE_SSLONLY}, /* S */ |
1351 |
|
|
{chm_nosuch, 0}, /* T */ |
1352 |
|
|
{chm_nosuch, 0}, /* U */ |
1353 |
|
|
{chm_nosuch, 0}, /* V */ |
1354 |
|
|
{chm_nosuch, 0}, /* W */ |
1355 |
|
|
{chm_nosuch, 0}, /* X */ |
1356 |
|
|
{chm_nosuch, 0}, /* Y */ |
1357 |
|
|
{chm_nosuch, 0}, /* Z */ |
1358 |
|
|
{chm_nosuch, 0}, |
1359 |
|
|
{chm_nosuch, 0}, |
1360 |
|
|
{chm_nosuch, 0}, |
1361 |
|
|
{chm_nosuch, 0}, |
1362 |
|
|
{chm_nosuch, 0}, |
1363 |
|
|
{chm_nosuch, 0}, |
1364 |
|
|
{chm_nosuch, 0}, /* a */ |
1365 |
|
|
{chm_ban, 0}, /* b */ |
1366 |
|
|
{chm_simple, MODE_NOCTRL}, /* c */ |
1367 |
|
|
{chm_nosuch, 0}, /* d */ |
1368 |
|
|
{chm_except, 0}, /* e */ |
1369 |
|
|
{chm_nosuch, 0}, /* f */ |
1370 |
|
|
{chm_nosuch, 0}, /* g */ |
1371 |
adx |
30 |
#ifdef HALFOPS |
1372 |
michael |
2937 |
{chm_hop, 0}, /* h */ |
1373 |
adx |
30 |
#else |
1374 |
michael |
2937 |
{chm_nosuch, 0}, /* h */ |
1375 |
adx |
30 |
#endif |
1376 |
michael |
2937 |
{chm_simple, MODE_INVITEONLY}, /* i */ |
1377 |
|
|
{chm_nosuch, 0}, /* j */ |
1378 |
|
|
{chm_key, 0}, /* k */ |
1379 |
|
|
{chm_limit, 0}, /* l */ |
1380 |
|
|
{chm_simple, MODE_MODERATED}, /* m */ |
1381 |
|
|
{chm_simple, MODE_NOPRIVMSGS}, /* n */ |
1382 |
|
|
{chm_op, 0}, /* o */ |
1383 |
|
|
{chm_simple, MODE_PRIVATE}, /* p */ |
1384 |
|
|
{chm_nosuch, 0}, /* q */ |
1385 |
|
|
{chm_registered, MODE_REGISTERED}, /* r */ |
1386 |
|
|
{chm_simple, MODE_SECRET}, /* s */ |
1387 |
|
|
{chm_simple, MODE_TOPICLIMIT}, /* t */ |
1388 |
|
|
{chm_nosuch, 0}, /* u */ |
1389 |
|
|
{chm_voice, 0}, /* v */ |
1390 |
|
|
{chm_nosuch, 0}, /* w */ |
1391 |
|
|
{chm_nosuch, 0}, /* x */ |
1392 |
|
|
{chm_nosuch, 0}, /* y */ |
1393 |
|
|
{chm_nosuch, 0}, /* z */ |
1394 |
adx |
30 |
}; |
1395 |
|
|
|
1396 |
|
|
/* get_channel_access() |
1397 |
|
|
* |
1398 |
|
|
* inputs - pointer to Client struct |
1399 |
|
|
* - pointer to Membership struct |
1400 |
|
|
* output - CHACCESS_CHANOP if we should let them have |
1401 |
|
|
* chanop level access, 0 for peon level access. |
1402 |
|
|
* side effects - NONE |
1403 |
|
|
*/ |
1404 |
|
|
static int |
1405 |
|
|
get_channel_access(struct Client *source_p, struct Membership *member) |
1406 |
|
|
{ |
1407 |
|
|
/* Let hacked servers in for now... */ |
1408 |
|
|
if (!MyClient(source_p)) |
1409 |
|
|
return CHACCESS_CHANOP; |
1410 |
|
|
|
1411 |
|
|
if (member == NULL) |
1412 |
|
|
return CHACCESS_NOTONCHAN; |
1413 |
|
|
|
1414 |
|
|
/* just to be sure.. */ |
1415 |
|
|
assert(source_p == member->client_p); |
1416 |
|
|
|
1417 |
|
|
if (has_member_flags(member, CHFL_CHANOP)) |
1418 |
|
|
return CHACCESS_CHANOP; |
1419 |
|
|
|
1420 |
|
|
#ifdef HALFOPS |
1421 |
|
|
if (has_member_flags(member, CHFL_HALFOP)) |
1422 |
|
|
return CHACCESS_HALFOP; |
1423 |
|
|
#endif |
1424 |
|
|
|
1425 |
|
|
return CHACCESS_PEON; |
1426 |
|
|
} |
1427 |
|
|
|
1428 |
|
|
/* void send_cap_mode_changes(struct Client *client_p, |
1429 |
|
|
* struct Client *source_p, |
1430 |
|
|
* struct Channel *chptr, int cap, int nocap) |
1431 |
|
|
* Input: The client sending(client_p), the source client(source_p), |
1432 |
|
|
* the channel to send mode changes for(chptr) |
1433 |
|
|
* Output: None. |
1434 |
|
|
* Side-effects: Sends the appropriate mode changes to capable servers. |
1435 |
|
|
* |
1436 |
|
|
* send_cap_mode_changes() will loop the server list itself, because |
1437 |
|
|
* at this point in time we have 4 capabs for channels, CAP_IE, CAP_EX, |
1438 |
|
|
* and a server could support any number of these.. |
1439 |
|
|
* so we make the modebufs per server, tailoring them to each servers |
1440 |
|
|
* specific demand. Its not very pretty, but its one of the few realistic |
1441 |
|
|
* ways to handle having this many capabs for channel modes.. --fl_ |
1442 |
|
|
* |
1443 |
|
|
* Reverted back to my original design, except that we now keep a count |
1444 |
|
|
* of the number of servers which each combination as an optimisation, so |
1445 |
|
|
* the capabs combinations which are not needed are not worked out. -A1kmm |
1446 |
|
|
*/ |
1447 |
|
|
/* rewritten to ensure parabuf < MODEBUFLEN -db */ |
1448 |
|
|
|
1449 |
|
|
static void |
1450 |
|
|
send_cap_mode_changes(struct Client *client_p, struct Client *source_p, |
1451 |
michael |
1015 |
struct Channel *chptr, unsigned int cap, unsigned int nocap) |
1452 |
adx |
30 |
{ |
1453 |
|
|
int i, mbl, pbl, arglen, nc, mc; |
1454 |
|
|
int len; |
1455 |
|
|
const char *arg = NULL; |
1456 |
|
|
char *parptr; |
1457 |
|
|
int dir = MODE_QUERY; |
1458 |
|
|
|
1459 |
|
|
mc = 0; |
1460 |
|
|
nc = 0; |
1461 |
|
|
pbl = 0; |
1462 |
|
|
|
1463 |
|
|
parabuf[0] = '\0'; |
1464 |
|
|
parptr = parabuf; |
1465 |
|
|
|
1466 |
|
|
if ((cap & CAP_TS6) && source_p->id[0] != '\0') |
1467 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s TMODE %lu %s ", source_p->id, |
1468 |
michael |
2892 |
(unsigned long)chptr->channelts, chptr->chname); |
1469 |
adx |
30 |
else |
1470 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s MODE %s ", source_p->name, |
1471 |
michael |
2892 |
chptr->chname); |
1472 |
adx |
30 |
|
1473 |
|
|
/* loop the list of - modes we have */ |
1474 |
|
|
for (i = 0; i < mode_count; i++) |
1475 |
|
|
{ |
1476 |
|
|
/* if they dont support the cap we need, or they do support a cap they |
1477 |
|
|
* cant have, then dont add it to the modebuf.. that way they wont see |
1478 |
|
|
* the mode |
1479 |
|
|
*/ |
1480 |
|
|
if ((mode_changes[i].letter == 0) || |
1481 |
michael |
2892 |
((cap & mode_changes[i].caps) != mode_changes[i].caps) || |
1482 |
|
|
((nocap & mode_changes[i].nocaps) != mode_changes[i].nocaps)) |
1483 |
adx |
30 |
continue; |
1484 |
|
|
|
1485 |
|
|
arg = ""; |
1486 |
|
|
|
1487 |
|
|
if ((cap & CAP_TS6) && mode_changes[i].id) |
1488 |
|
|
arg = mode_changes[i].id; |
1489 |
|
|
if (*arg == '\0') |
1490 |
|
|
arg = mode_changes[i].arg; |
1491 |
|
|
|
1492 |
|
|
/* if we're creeping past the buf size, we need to send it and make |
1493 |
|
|
* another line for the other modes |
1494 |
|
|
* XXX - this could give away server topology with uids being |
1495 |
|
|
* different lengths, but not much we can do, except possibly break |
1496 |
|
|
* them as if they were the longest of the nick or uid at all times, |
1497 |
|
|
* which even then won't work as we don't always know the uid -A1kmm. |
1498 |
|
|
*/ |
1499 |
|
|
if (arg != NULL) |
1500 |
|
|
arglen = strlen(arg); |
1501 |
|
|
else |
1502 |
|
|
arglen = 0; |
1503 |
|
|
|
1504 |
|
|
if ((mc == MAXMODEPARAMS) || |
1505 |
|
|
((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) || |
1506 |
|
|
(pbl + arglen + BAN_FUDGE) >= MODEBUFLEN) |
1507 |
|
|
{ |
1508 |
|
|
if (nc != 0) |
1509 |
michael |
2892 |
sendto_server(client_p, cap, nocap, "%s %s", modebuf, parabuf); |
1510 |
adx |
30 |
nc = 0; |
1511 |
|
|
mc = 0; |
1512 |
|
|
|
1513 |
|
|
if ((cap & CAP_TS6) && source_p->id[0] != '\0') |
1514 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s MODE %s ", source_p->id, |
1515 |
|
|
chptr->chname); |
1516 |
adx |
30 |
else |
1517 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s MODE %s ", source_p->name, |
1518 |
|
|
chptr->chname); |
1519 |
adx |
30 |
|
1520 |
|
|
pbl = 0; |
1521 |
|
|
parabuf[0] = '\0'; |
1522 |
|
|
parptr = parabuf; |
1523 |
|
|
dir = MODE_QUERY; |
1524 |
|
|
} |
1525 |
|
|
|
1526 |
|
|
if (dir != mode_changes[i].dir) |
1527 |
|
|
{ |
1528 |
|
|
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
1529 |
|
|
dir = mode_changes[i].dir; |
1530 |
|
|
} |
1531 |
|
|
|
1532 |
|
|
modebuf[mbl++] = mode_changes[i].letter; |
1533 |
|
|
modebuf[mbl] = '\0'; |
1534 |
|
|
nc++; |
1535 |
|
|
|
1536 |
|
|
if (arg != NULL) |
1537 |
|
|
{ |
1538 |
michael |
1793 |
len = sprintf(parptr, "%s ", arg); |
1539 |
adx |
30 |
pbl += len; |
1540 |
|
|
parptr += len; |
1541 |
|
|
mc++; |
1542 |
|
|
} |
1543 |
|
|
} |
1544 |
|
|
|
1545 |
|
|
if (pbl && parabuf[pbl - 1] == ' ') |
1546 |
|
|
parabuf[pbl - 1] = 0; |
1547 |
|
|
|
1548 |
|
|
if (nc != 0) |
1549 |
michael |
2892 |
sendto_server(client_p, cap, nocap, "%s %s", modebuf, parabuf); |
1550 |
adx |
30 |
} |
1551 |
|
|
|
1552 |
|
|
/* void send_mode_changes(struct Client *client_p, |
1553 |
|
|
* struct Client *source_p, |
1554 |
|
|
* struct Channel *chptr) |
1555 |
|
|
* Input: The client sending(client_p), the source client(source_p), |
1556 |
|
|
* the channel to send mode changes for(chptr), |
1557 |
|
|
* mode change globals. |
1558 |
|
|
* Output: None. |
1559 |
|
|
* Side-effects: Sends the appropriate mode changes to other clients |
1560 |
|
|
* and propagates to servers. |
1561 |
|
|
*/ |
1562 |
|
|
/* ensure parabuf < MODEBUFLEN -db */ |
1563 |
|
|
static void |
1564 |
|
|
send_mode_changes(struct Client *client_p, struct Client *source_p, |
1565 |
michael |
2937 |
struct Channel *chptr) |
1566 |
adx |
30 |
{ |
1567 |
|
|
int i, mbl, pbl, arglen, nc, mc; |
1568 |
|
|
int len; |
1569 |
|
|
const char *arg = NULL; |
1570 |
|
|
char *parptr; |
1571 |
|
|
int dir = MODE_QUERY; |
1572 |
|
|
|
1573 |
|
|
/* bail out if we have nothing to do... */ |
1574 |
|
|
if (!mode_count) |
1575 |
|
|
return; |
1576 |
|
|
|
1577 |
|
|
if (IsServer(source_p)) |
1578 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s MODE %s ", (IsHidden(source_p) || |
1579 |
|
|
ConfigServerHide.hide_servers) ? |
1580 |
michael |
2937 |
me.name : source_p->name, chptr->chname); |
1581 |
adx |
30 |
else |
1582 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s!%s@%s MODE %s ", source_p->name, |
1583 |
michael |
2937 |
source_p->username, source_p->host, chptr->chname); |
1584 |
adx |
30 |
|
1585 |
|
|
mc = 0; |
1586 |
|
|
nc = 0; |
1587 |
|
|
pbl = 0; |
1588 |
|
|
|
1589 |
|
|
parabuf[0] = '\0'; |
1590 |
|
|
parptr = parabuf; |
1591 |
|
|
|
1592 |
|
|
for (i = 0; i < mode_count; i++) |
1593 |
|
|
{ |
1594 |
|
|
if (mode_changes[i].letter == 0 || |
1595 |
|
|
mode_changes[i].mems == NON_CHANOPS || |
1596 |
|
|
mode_changes[i].mems == ONLY_SERVERS) |
1597 |
|
|
continue; |
1598 |
|
|
|
1599 |
|
|
arg = mode_changes[i].arg; |
1600 |
|
|
if (arg != NULL) |
1601 |
|
|
arglen = strlen(arg); |
1602 |
|
|
else |
1603 |
|
|
arglen = 0; |
1604 |
|
|
|
1605 |
michael |
2892 |
if ((mc == MAXMODEPARAMS) || |
1606 |
adx |
30 |
((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) || |
1607 |
michael |
2892 |
((arglen + pbl + BAN_FUDGE) >= MODEBUFLEN)) |
1608 |
adx |
30 |
{ |
1609 |
|
|
if (mbl && modebuf[mbl - 1] == '-') |
1610 |
|
|
modebuf[mbl - 1] = '\0'; |
1611 |
|
|
|
1612 |
|
|
if (nc != 0) |
1613 |
michael |
1243 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf); |
1614 |
adx |
30 |
|
1615 |
|
|
nc = 0; |
1616 |
|
|
mc = 0; |
1617 |
|
|
|
1618 |
|
|
if (IsServer(source_p)) |
1619 |
michael |
2557 |
mbl = sprintf(modebuf, ":%s MODE %s ", (IsHidden(source_p) || |
1620 |
|
|
ConfigServerHide.hide_servers) ? |
1621 |
michael |
2937 |
me.name : source_p->name, chptr->chname); |
1622 |
adx |
30 |
else |
1623 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s!%s@%s MODE %s ", source_p->name, |
1624 |
michael |
2937 |
source_p->username, source_p->host, chptr->chname); |
1625 |
adx |
30 |
|
1626 |
|
|
pbl = 0; |
1627 |
|
|
parabuf[0] = '\0'; |
1628 |
|
|
parptr = parabuf; |
1629 |
|
|
dir = MODE_QUERY; |
1630 |
|
|
} |
1631 |
|
|
|
1632 |
|
|
if (dir != mode_changes[i].dir) |
1633 |
|
|
{ |
1634 |
|
|
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
1635 |
|
|
dir = mode_changes[i].dir; |
1636 |
|
|
} |
1637 |
|
|
|
1638 |
|
|
modebuf[mbl++] = mode_changes[i].letter; |
1639 |
|
|
modebuf[mbl] = '\0'; |
1640 |
|
|
nc++; |
1641 |
|
|
|
1642 |
|
|
if (arg != NULL) |
1643 |
|
|
{ |
1644 |
michael |
1793 |
len = sprintf(parptr, "%s ", arg); |
1645 |
adx |
30 |
pbl += len; |
1646 |
|
|
parptr += len; |
1647 |
|
|
mc++; |
1648 |
|
|
} |
1649 |
|
|
} |
1650 |
|
|
|
1651 |
|
|
if (pbl && parabuf[pbl - 1] == ' ') |
1652 |
|
|
parabuf[pbl - 1] = 0; |
1653 |
|
|
|
1654 |
|
|
if (nc != 0) |
1655 |
michael |
1243 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf); |
1656 |
adx |
30 |
|
1657 |
|
|
nc = 0; |
1658 |
|
|
mc = 0; |
1659 |
|
|
|
1660 |
|
|
/* Now send to servers... */ |
1661 |
|
|
for (i = 0; i < NCHCAP_COMBOS; i++) |
1662 |
|
|
if (chcap_combos[i].count != 0) |
1663 |
|
|
send_cap_mode_changes(client_p, source_p, chptr, |
1664 |
|
|
chcap_combos[i].cap_yes, |
1665 |
|
|
chcap_combos[i].cap_no); |
1666 |
|
|
} |
1667 |
|
|
|
1668 |
|
|
/* void set_channel_mode(struct Client *client_p, struct Client *source_p, |
1669 |
|
|
* struct Channel *chptr, int parc, char **parv, |
1670 |
|
|
* char *chname) |
1671 |
|
|
* Input: The client we received this from, the client this originated |
1672 |
|
|
* from, the channel, the parameter count starting at the modes, |
1673 |
|
|
* the parameters, the channel name. |
1674 |
|
|
* Output: None. |
1675 |
|
|
* Side-effects: Changes the channel membership and modes appropriately, |
1676 |
|
|
* sends the appropriate MODE messages to the appropriate |
1677 |
|
|
* clients. |
1678 |
|
|
*/ |
1679 |
|
|
void |
1680 |
|
|
set_channel_mode(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
1681 |
michael |
2937 |
struct Membership *member, int parc, char *parv[]) |
1682 |
adx |
30 |
{ |
1683 |
|
|
int dir = MODE_ADD; |
1684 |
|
|
int parn = 1; |
1685 |
|
|
int alevel, errors = 0; |
1686 |
|
|
char *ml = parv[0], c; |
1687 |
|
|
int table_position; |
1688 |
|
|
|
1689 |
|
|
mode_count = 0; |
1690 |
|
|
mode_limit = 0; |
1691 |
|
|
simple_modes_mask = 0; |
1692 |
|
|
|
1693 |
|
|
alevel = get_channel_access(source_p, member); |
1694 |
|
|
|
1695 |
michael |
2892 |
for (; (c = *ml) != '\0'; ml++) |
1696 |
adx |
30 |
{ |
1697 |
|
|
switch (c) |
1698 |
|
|
{ |
1699 |
|
|
case '+': |
1700 |
|
|
dir = MODE_ADD; |
1701 |
|
|
break; |
1702 |
|
|
case '-': |
1703 |
|
|
dir = MODE_DEL; |
1704 |
|
|
break; |
1705 |
|
|
case '=': |
1706 |
|
|
dir = MODE_QUERY; |
1707 |
|
|
break; |
1708 |
|
|
default: |
1709 |
|
|
if (c < 'A' || c > 'z') |
1710 |
|
|
table_position = 0; |
1711 |
|
|
else |
1712 |
|
|
table_position = c - 'A' + 1; |
1713 |
|
|
ModeTable[table_position].func(client_p, source_p, chptr, |
1714 |
|
|
parc, &parn, |
1715 |
|
|
parv, &errors, alevel, dir, c, |
1716 |
michael |
2937 |
ModeTable[table_position].d); |
1717 |
adx |
30 |
break; |
1718 |
|
|
} |
1719 |
|
|
} |
1720 |
|
|
|
1721 |
michael |
2937 |
send_mode_changes(client_p, source_p, chptr); |
1722 |
adx |
30 |
} |