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 |
|
|
char **parv, int *errors, int alev, int dir, char c, void *d, |
504 |
|
|
const char *chname) |
505 |
|
|
{ |
506 |
|
|
if (*errors & SM_ERR_UNKNOWN) |
507 |
|
|
return; |
508 |
|
|
|
509 |
|
|
*errors |= SM_ERR_UNKNOWN; |
510 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, |
511 |
adx |
30 |
source_p->name, c); |
512 |
|
|
} |
513 |
|
|
|
514 |
|
|
static void |
515 |
|
|
chm_simple(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
516 |
|
|
int parc, int *parn, char **parv, int *errors, int alev, int dir, |
517 |
|
|
char c, void *d, const char *chname) |
518 |
|
|
{ |
519 |
michael |
2892 |
long mode_type = (long)d; |
520 |
adx |
30 |
|
521 |
|
|
if ((alev < CHACCESS_HALFOP) || |
522 |
|
|
((mode_type == MODE_PRIVATE) && (alev < CHACCESS_CHANOP))) |
523 |
|
|
{ |
524 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
525 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
526 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
527 |
adx |
30 |
me.name, source_p->name, chname); |
528 |
|
|
*errors |= SM_ERR_NOOPS; |
529 |
|
|
return; |
530 |
|
|
} |
531 |
|
|
|
532 |
|
|
/* If have already dealt with this simple mode, ignore it */ |
533 |
|
|
if (simple_modes_mask & mode_type) |
534 |
|
|
return; |
535 |
|
|
|
536 |
|
|
simple_modes_mask |= mode_type; |
537 |
|
|
|
538 |
|
|
/* setting + */ |
539 |
michael |
2892 |
/* Apparently, (though no one has ever told the hybrid group directly) |
540 |
|
|
* admins don't like redundant mode checking. ok. It would have been nice |
541 |
|
|
* if you had have told us directly. I've left the original code snippets |
542 |
|
|
* in place. |
543 |
|
|
* |
544 |
|
|
* -Dianora |
545 |
|
|
*/ |
546 |
michael |
2534 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & mode_type)) */ |
547 |
adx |
30 |
{ |
548 |
|
|
chptr->mode.mode |= mode_type; |
549 |
|
|
|
550 |
|
|
mode_changes[mode_count].letter = c; |
551 |
|
|
mode_changes[mode_count].dir = MODE_ADD; |
552 |
|
|
mode_changes[mode_count].caps = 0; |
553 |
|
|
mode_changes[mode_count].nocaps = 0; |
554 |
|
|
mode_changes[mode_count].id = NULL; |
555 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
556 |
|
|
mode_changes[mode_count++].arg = NULL; |
557 |
|
|
} |
558 |
michael |
2534 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & mode_type)) */ |
559 |
adx |
30 |
{ |
560 |
|
|
/* setting - */ |
561 |
|
|
|
562 |
|
|
chptr->mode.mode &= ~mode_type; |
563 |
|
|
|
564 |
|
|
mode_changes[mode_count].letter = c; |
565 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
566 |
|
|
mode_changes[mode_count].caps = 0; |
567 |
|
|
mode_changes[mode_count].nocaps = 0; |
568 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
569 |
|
|
mode_changes[mode_count].id = NULL; |
570 |
|
|
mode_changes[mode_count++].arg = NULL; |
571 |
|
|
} |
572 |
|
|
} |
573 |
|
|
|
574 |
|
|
static void |
575 |
michael |
1167 |
chm_registered(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
576 |
|
|
int parc, int *parn, char **parv, int *errors, int alev, int dir, |
577 |
|
|
char c, void *d, const char *chname) |
578 |
|
|
{ |
579 |
michael |
2892 |
long mode_type = (long)d; |
580 |
michael |
1167 |
|
581 |
|
|
|
582 |
michael |
1219 |
if (!IsServer(source_p) && !HasFlag(source_p, FLAGS_SERVICE)) |
583 |
michael |
1167 |
{ |
584 |
|
|
if (!(*errors & SM_ERR_ONLYSERVER)) |
585 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
586 |
|
|
ERR_NOTONCHANNEL : ERR_ONLYSERVERSCANCHANGE), |
587 |
michael |
1167 |
me.name, source_p->name, chname); |
588 |
|
|
*errors |= SM_ERR_ONLYSERVER; |
589 |
|
|
return; |
590 |
|
|
} |
591 |
|
|
|
592 |
|
|
/* If have already dealt with this simple mode, ignore it */ |
593 |
|
|
if (simple_modes_mask & mode_type) |
594 |
|
|
return; |
595 |
|
|
|
596 |
|
|
simple_modes_mask |= mode_type; |
597 |
|
|
|
598 |
|
|
/* setting + */ |
599 |
michael |
2892 |
/* Apparently, (though no one has ever told the hybrid group directly) |
600 |
|
|
* admins don't like redundant mode checking. ok. It would have been nice |
601 |
|
|
* if you had have told us directly. I've left the original code snippets |
602 |
|
|
* in place. |
603 |
|
|
* |
604 |
|
|
* -Dianora |
605 |
michael |
1167 |
*/ |
606 |
michael |
2534 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & mode_type)) */ |
607 |
michael |
1167 |
{ |
608 |
|
|
chptr->mode.mode |= mode_type; |
609 |
|
|
|
610 |
|
|
mode_changes[mode_count].letter = c; |
611 |
|
|
mode_changes[mode_count].dir = MODE_ADD; |
612 |
|
|
mode_changes[mode_count].caps = 0; |
613 |
|
|
mode_changes[mode_count].nocaps = 0; |
614 |
|
|
mode_changes[mode_count].id = NULL; |
615 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
616 |
|
|
mode_changes[mode_count++].arg = NULL; |
617 |
|
|
} |
618 |
michael |
2534 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & mode_type)) */ |
619 |
michael |
1167 |
{ |
620 |
|
|
/* setting - */ |
621 |
|
|
|
622 |
|
|
chptr->mode.mode &= ~mode_type; |
623 |
|
|
|
624 |
|
|
mode_changes[mode_count].letter = c; |
625 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
626 |
|
|
mode_changes[mode_count].caps = 0; |
627 |
|
|
mode_changes[mode_count].nocaps = 0; |
628 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
629 |
|
|
mode_changes[mode_count].id = NULL; |
630 |
|
|
mode_changes[mode_count++].arg = NULL; |
631 |
|
|
} |
632 |
|
|
} |
633 |
|
|
|
634 |
|
|
static void |
635 |
michael |
1150 |
chm_operonly(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
636 |
|
|
int parc, int *parn, char **parv, int *errors, int alev, int dir, |
637 |
|
|
char c, void *d, const char *chname) |
638 |
|
|
{ |
639 |
michael |
2892 |
long mode_type = (long)d; |
640 |
michael |
1150 |
|
641 |
|
|
if ((alev < CHACCESS_HALFOP) || |
642 |
|
|
((mode_type == MODE_PRIVATE) && (alev < CHACCESS_CHANOP))) |
643 |
|
|
{ |
644 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
645 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
646 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
647 |
michael |
1150 |
me.name, source_p->name, chname); |
648 |
|
|
*errors |= SM_ERR_NOOPS; |
649 |
|
|
return; |
650 |
|
|
} |
651 |
michael |
1219 |
else if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER)) |
652 |
michael |
1150 |
{ |
653 |
|
|
if (!(*errors & SM_ERR_NOTOPER)) |
654 |
|
|
{ |
655 |
|
|
if (alev == CHACCESS_NOTONCHAN) |
656 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
657 |
michael |
1150 |
me.name, source_p->name, chname); |
658 |
|
|
else |
659 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
660 |
michael |
1150 |
me.name, source_p->name); |
661 |
|
|
} |
662 |
|
|
|
663 |
|
|
*errors |= SM_ERR_NOTOPER; |
664 |
|
|
return; |
665 |
|
|
} |
666 |
|
|
|
667 |
|
|
/* If have already dealt with this simple mode, ignore it */ |
668 |
|
|
if (simple_modes_mask & mode_type) |
669 |
|
|
return; |
670 |
|
|
|
671 |
|
|
simple_modes_mask |= mode_type; |
672 |
|
|
|
673 |
michael |
2534 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & mode_type)) */ |
674 |
michael |
1150 |
{ |
675 |
|
|
chptr->mode.mode |= mode_type; |
676 |
|
|
|
677 |
|
|
mode_changes[mode_count].letter = c; |
678 |
|
|
mode_changes[mode_count].dir = MODE_ADD; |
679 |
|
|
mode_changes[mode_count].caps = 0; |
680 |
|
|
mode_changes[mode_count].nocaps = 0; |
681 |
|
|
mode_changes[mode_count].id = NULL; |
682 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
683 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
684 |
|
|
mode_changes[mode_count++].arg = NULL; |
685 |
|
|
} |
686 |
michael |
2534 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & mode_type)) */ |
687 |
michael |
1150 |
{ |
688 |
|
|
/* setting - */ |
689 |
|
|
|
690 |
|
|
chptr->mode.mode &= ~mode_type; |
691 |
|
|
|
692 |
|
|
mode_changes[mode_count].letter = c; |
693 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
694 |
|
|
mode_changes[mode_count].caps = 0; |
695 |
|
|
mode_changes[mode_count].nocaps = 0; |
696 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
697 |
|
|
mode_changes[mode_count].id = NULL; |
698 |
|
|
mode_changes[mode_count++].arg = NULL; |
699 |
|
|
} |
700 |
|
|
} |
701 |
|
|
|
702 |
|
|
static void |
703 |
adx |
30 |
chm_ban(struct Client *client_p, struct Client *source_p, |
704 |
|
|
struct Channel *chptr, int parc, int *parn, |
705 |
|
|
char **parv, int *errors, int alev, int dir, char c, void *d, |
706 |
|
|
const char *chname) |
707 |
|
|
{ |
708 |
|
|
char *mask = NULL; |
709 |
|
|
|
710 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
711 |
|
|
{ |
712 |
|
|
dlink_node *ptr = NULL; |
713 |
|
|
|
714 |
|
|
if (*errors & SM_ERR_RPL_B) |
715 |
|
|
return; |
716 |
|
|
|
717 |
|
|
*errors |= SM_ERR_RPL_B; |
718 |
|
|
|
719 |
|
|
DLINK_FOREACH(ptr, chptr->banlist.head) |
720 |
|
|
{ |
721 |
|
|
const struct Ban *banptr = ptr->data; |
722 |
michael |
1834 |
sendto_one(client_p, form_str(RPL_BANLIST), |
723 |
adx |
30 |
me.name, client_p->name, chname, |
724 |
michael |
2296 |
banptr->name, banptr->user, banptr->host, |
725 |
michael |
2892 |
banptr->who, banptr->when); |
726 |
adx |
30 |
} |
727 |
|
|
|
728 |
michael |
1834 |
sendto_one(source_p, form_str(RPL_ENDOFBANLIST), me.name, |
729 |
adx |
30 |
source_p->name, chname); |
730 |
|
|
return; |
731 |
|
|
} |
732 |
|
|
|
733 |
|
|
if (alev < CHACCESS_HALFOP) |
734 |
|
|
{ |
735 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
736 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
737 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
738 |
adx |
30 |
me.name, source_p->name, chname); |
739 |
|
|
*errors |= SM_ERR_NOOPS; |
740 |
|
|
return; |
741 |
|
|
} |
742 |
|
|
|
743 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
744 |
|
|
return; |
745 |
|
|
|
746 |
michael |
388 |
mask = nuh_mask[*parn]; |
747 |
|
|
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
748 |
|
|
++*parn; |
749 |
|
|
|
750 |
adx |
30 |
if (IsServer(client_p)) |
751 |
|
|
if (strchr(mask, ' ')) |
752 |
|
|
return; |
753 |
|
|
|
754 |
|
|
switch (dir) |
755 |
|
|
{ |
756 |
|
|
case MODE_ADD: |
757 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_BAN)) |
758 |
|
|
return; |
759 |
|
|
break; |
760 |
|
|
case MODE_DEL: |
761 |
|
|
if (!del_id(chptr, mask, CHFL_BAN)) |
762 |
|
|
return; |
763 |
|
|
break; |
764 |
|
|
default: |
765 |
|
|
assert(0); |
766 |
|
|
} |
767 |
|
|
|
768 |
|
|
mode_changes[mode_count].letter = c; |
769 |
|
|
mode_changes[mode_count].dir = dir; |
770 |
|
|
mode_changes[mode_count].caps = 0; |
771 |
|
|
mode_changes[mode_count].nocaps = 0; |
772 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
773 |
|
|
mode_changes[mode_count].id = NULL; |
774 |
|
|
mode_changes[mode_count++].arg = mask; |
775 |
|
|
} |
776 |
|
|
|
777 |
|
|
static void |
778 |
|
|
chm_except(struct Client *client_p, struct Client *source_p, |
779 |
|
|
struct Channel *chptr, int parc, int *parn, |
780 |
|
|
char **parv, int *errors, int alev, int dir, char c, void *d, |
781 |
|
|
const char *chname) |
782 |
|
|
{ |
783 |
|
|
char *mask = NULL; |
784 |
|
|
|
785 |
|
|
if (alev < CHACCESS_HALFOP) |
786 |
|
|
{ |
787 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
788 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
789 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
790 |
adx |
30 |
me.name, source_p->name, chname); |
791 |
|
|
*errors |= SM_ERR_NOOPS; |
792 |
|
|
return; |
793 |
|
|
} |
794 |
|
|
|
795 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
796 |
|
|
{ |
797 |
|
|
dlink_node *ptr = NULL; |
798 |
|
|
|
799 |
|
|
if (*errors & SM_ERR_RPL_E) |
800 |
|
|
return; |
801 |
|
|
|
802 |
|
|
*errors |= SM_ERR_RPL_E; |
803 |
|
|
|
804 |
|
|
DLINK_FOREACH(ptr, chptr->exceptlist.head) |
805 |
|
|
{ |
806 |
|
|
const struct Ban *banptr = ptr->data; |
807 |
michael |
1834 |
sendto_one(client_p, form_str(RPL_EXCEPTLIST), |
808 |
adx |
30 |
me.name, client_p->name, chname, |
809 |
michael |
2296 |
banptr->name, banptr->user, banptr->host, |
810 |
michael |
2892 |
banptr->who, banptr->when); |
811 |
adx |
30 |
} |
812 |
|
|
|
813 |
michael |
1834 |
sendto_one(source_p, form_str(RPL_ENDOFEXCEPTLIST), me.name, |
814 |
adx |
30 |
source_p->name, chname); |
815 |
|
|
return; |
816 |
|
|
} |
817 |
|
|
|
818 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
819 |
|
|
return; |
820 |
|
|
|
821 |
michael |
388 |
mask = nuh_mask[*parn]; |
822 |
|
|
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
823 |
|
|
++*parn; |
824 |
adx |
30 |
|
825 |
|
|
if (IsServer(client_p)) |
826 |
|
|
if (strchr(mask, ' ')) |
827 |
|
|
return; |
828 |
|
|
|
829 |
|
|
switch (dir) |
830 |
|
|
{ |
831 |
|
|
case MODE_ADD: |
832 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION)) |
833 |
|
|
return; |
834 |
|
|
break; |
835 |
|
|
case MODE_DEL: |
836 |
|
|
if (!del_id(chptr, mask, CHFL_EXCEPTION)) |
837 |
|
|
return; |
838 |
|
|
break; |
839 |
|
|
default: |
840 |
|
|
assert(0); |
841 |
|
|
} |
842 |
|
|
|
843 |
|
|
mode_changes[mode_count].letter = c; |
844 |
|
|
mode_changes[mode_count].dir = dir; |
845 |
michael |
1684 |
mode_changes[mode_count].caps = 0; |
846 |
adx |
30 |
mode_changes[mode_count].nocaps = 0; |
847 |
michael |
1495 |
mode_changes[mode_count].mems = ONLY_CHANOPS; |
848 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
849 |
|
|
mode_changes[mode_count++].arg = mask; |
850 |
|
|
} |
851 |
|
|
|
852 |
|
|
static void |
853 |
|
|
chm_invex(struct Client *client_p, struct Client *source_p, |
854 |
|
|
struct Channel *chptr, int parc, int *parn, |
855 |
|
|
char **parv, int *errors, int alev, int dir, char c, void *d, |
856 |
|
|
const char *chname) |
857 |
|
|
{ |
858 |
|
|
char *mask = NULL; |
859 |
|
|
|
860 |
|
|
if (alev < CHACCESS_HALFOP) |
861 |
|
|
{ |
862 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
863 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
864 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
865 |
adx |
30 |
me.name, source_p->name, chname); |
866 |
|
|
*errors |= SM_ERR_NOOPS; |
867 |
|
|
return; |
868 |
|
|
} |
869 |
|
|
|
870 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
871 |
|
|
{ |
872 |
|
|
dlink_node *ptr = NULL; |
873 |
|
|
|
874 |
|
|
if (*errors & SM_ERR_RPL_I) |
875 |
|
|
return; |
876 |
|
|
|
877 |
|
|
*errors |= SM_ERR_RPL_I; |
878 |
|
|
|
879 |
|
|
DLINK_FOREACH(ptr, chptr->invexlist.head) |
880 |
|
|
{ |
881 |
|
|
const struct Ban *banptr = ptr->data; |
882 |
michael |
1834 |
sendto_one(client_p, form_str(RPL_INVITELIST), me.name, |
883 |
adx |
30 |
client_p->name, chname, |
884 |
michael |
2892 |
banptr->name, banptr->user, banptr->host, |
885 |
adx |
30 |
banptr->who, banptr->when); |
886 |
|
|
} |
887 |
|
|
|
888 |
michael |
1834 |
sendto_one(source_p, form_str(RPL_ENDOFINVITELIST), me.name, |
889 |
adx |
30 |
source_p->name, chname); |
890 |
|
|
return; |
891 |
|
|
} |
892 |
|
|
|
893 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
894 |
|
|
return; |
895 |
|
|
|
896 |
michael |
388 |
mask = nuh_mask[*parn]; |
897 |
|
|
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
898 |
|
|
++*parn; |
899 |
adx |
30 |
|
900 |
|
|
if (IsServer(client_p)) |
901 |
|
|
if (strchr(mask, ' ')) |
902 |
|
|
return; |
903 |
|
|
|
904 |
|
|
switch (dir) |
905 |
|
|
{ |
906 |
|
|
case MODE_ADD: |
907 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_INVEX)) |
908 |
|
|
return; |
909 |
|
|
break; |
910 |
|
|
case MODE_DEL: |
911 |
|
|
if (!del_id(chptr, mask, CHFL_INVEX)) |
912 |
|
|
return; |
913 |
|
|
break; |
914 |
|
|
default: |
915 |
|
|
assert(0); |
916 |
|
|
} |
917 |
|
|
|
918 |
|
|
mode_changes[mode_count].letter = c; |
919 |
|
|
mode_changes[mode_count].dir = dir; |
920 |
michael |
1684 |
mode_changes[mode_count].caps = 0; |
921 |
adx |
30 |
mode_changes[mode_count].nocaps = 0; |
922 |
michael |
1495 |
mode_changes[mode_count].mems = ONLY_CHANOPS; |
923 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
924 |
|
|
mode_changes[mode_count++].arg = mask; |
925 |
|
|
} |
926 |
|
|
|
927 |
|
|
/* |
928 |
|
|
* inputs - pointer to channel |
929 |
|
|
* output - none |
930 |
|
|
* side effects - clear ban cache |
931 |
|
|
*/ |
932 |
|
|
void |
933 |
|
|
clear_ban_cache(struct Channel *chptr) |
934 |
|
|
{ |
935 |
|
|
dlink_node *ptr = NULL; |
936 |
|
|
|
937 |
michael |
572 |
DLINK_FOREACH(ptr, chptr->members.head) |
938 |
adx |
30 |
{ |
939 |
|
|
struct Membership *ms = ptr->data; |
940 |
michael |
572 |
|
941 |
|
|
if (MyConnect(ms->client_p)) |
942 |
|
|
ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED); |
943 |
adx |
30 |
} |
944 |
|
|
} |
945 |
|
|
|
946 |
michael |
759 |
void |
947 |
|
|
clear_ban_cache_client(struct Client *client_p) |
948 |
|
|
{ |
949 |
|
|
dlink_node *ptr = NULL; |
950 |
|
|
|
951 |
michael |
760 |
DLINK_FOREACH(ptr, client_p->channel.head) |
952 |
michael |
759 |
{ |
953 |
|
|
struct Membership *ms = ptr->data; |
954 |
|
|
ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED); |
955 |
|
|
} |
956 |
|
|
} |
957 |
|
|
|
958 |
adx |
30 |
static void |
959 |
|
|
chm_op(struct Client *client_p, struct Client *source_p, |
960 |
|
|
struct Channel *chptr, int parc, int *parn, |
961 |
|
|
char **parv, int *errors, int alev, int dir, char c, void *d, |
962 |
|
|
const char *chname) |
963 |
|
|
{ |
964 |
michael |
2892 |
const char *opnick = NULL; |
965 |
adx |
30 |
struct Client *targ_p; |
966 |
|
|
struct Membership *member; |
967 |
adx |
356 |
int caps = 0; |
968 |
adx |
30 |
|
969 |
|
|
if (alev < CHACCESS_CHANOP) |
970 |
|
|
{ |
971 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
972 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
973 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
974 |
adx |
30 |
me.name, source_p->name, chname); |
975 |
|
|
*errors |= SM_ERR_NOOPS; |
976 |
|
|
return; |
977 |
|
|
} |
978 |
|
|
|
979 |
|
|
if ((dir == MODE_QUERY) || (parc <= *parn)) |
980 |
|
|
return; |
981 |
|
|
|
982 |
|
|
opnick = parv[(*parn)++]; |
983 |
|
|
|
984 |
michael |
2475 |
if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) |
985 |
adx |
30 |
return; |
986 |
|
|
if (!IsClient(targ_p)) |
987 |
|
|
return; |
988 |
|
|
|
989 |
|
|
if ((member = find_channel_link(targ_p, chptr)) == NULL) |
990 |
|
|
{ |
991 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
992 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), |
993 |
adx |
30 |
me.name, source_p->name, opnick, chname); |
994 |
|
|
*errors |= SM_ERR_NOTONCHANNEL; |
995 |
|
|
return; |
996 |
|
|
} |
997 |
|
|
|
998 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
999 |
|
|
return; |
1000 |
|
|
|
1001 |
|
|
/* no redundant mode changes */ |
1002 |
|
|
if (dir == MODE_ADD && has_member_flags(member, CHFL_CHANOP)) |
1003 |
|
|
return; |
1004 |
|
|
if (dir == MODE_DEL && !has_member_flags(member, CHFL_CHANOP)) |
1005 |
adx |
356 |
{ |
1006 |
|
|
#ifdef HALFOPS |
1007 |
|
|
if (has_member_flags(member, CHFL_HALFOP)) |
1008 |
db |
931 |
{ |
1009 |
|
|
--*parn; |
1010 |
adx |
356 |
chm_hop(client_p, source_p, chptr, parc, parn, parv, errors, alev, |
1011 |
|
|
dir, c, d, chname); |
1012 |
db |
931 |
} |
1013 |
adx |
356 |
#endif |
1014 |
adx |
30 |
return; |
1015 |
adx |
356 |
} |
1016 |
adx |
30 |
|
1017 |
adx |
356 |
#ifdef HALFOPS |
1018 |
|
|
if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP)) |
1019 |
|
|
{ |
1020 |
|
|
/* promoting from % to @ is visible only to CAP_HOPS servers */ |
1021 |
|
|
mode_changes[mode_count].letter = 'h'; |
1022 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
1023 |
|
|
mode_changes[mode_count].caps = caps = CAP_HOPS; |
1024 |
|
|
mode_changes[mode_count].nocaps = 0; |
1025 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1026 |
|
|
mode_changes[mode_count].id = NULL; |
1027 |
|
|
mode_changes[mode_count].arg = targ_p->name; |
1028 |
|
|
mode_changes[mode_count++].client = targ_p; |
1029 |
|
|
} |
1030 |
|
|
#endif |
1031 |
|
|
|
1032 |
adx |
30 |
mode_changes[mode_count].letter = 'o'; |
1033 |
|
|
mode_changes[mode_count].dir = dir; |
1034 |
adx |
356 |
mode_changes[mode_count].caps = caps; |
1035 |
adx |
30 |
mode_changes[mode_count].nocaps = 0; |
1036 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1037 |
|
|
mode_changes[mode_count].id = targ_p->id; |
1038 |
|
|
mode_changes[mode_count].arg = targ_p->name; |
1039 |
|
|
mode_changes[mode_count++].client = targ_p; |
1040 |
|
|
|
1041 |
|
|
if (dir == MODE_ADD) |
1042 |
|
|
{ |
1043 |
|
|
AddMemberFlag(member, CHFL_CHANOP); |
1044 |
adx |
356 |
DelMemberFlag(member, CHFL_DEOPPED | CHFL_HALFOP); |
1045 |
adx |
30 |
} |
1046 |
|
|
else |
1047 |
|
|
DelMemberFlag(member, CHFL_CHANOP); |
1048 |
|
|
} |
1049 |
|
|
|
1050 |
|
|
#ifdef HALFOPS |
1051 |
|
|
static void |
1052 |
|
|
chm_hop(struct Client *client_p, struct Client *source_p, |
1053 |
|
|
struct Channel *chptr, int parc, int *parn, |
1054 |
|
|
char **parv, int *errors, int alev, int dir, char c, void *d, |
1055 |
|
|
const char *chname) |
1056 |
|
|
{ |
1057 |
michael |
2892 |
const char *opnick = NULL; |
1058 |
adx |
30 |
struct Client *targ_p; |
1059 |
|
|
struct Membership *member; |
1060 |
|
|
|
1061 |
|
|
/* *sigh* - dont allow halfops to set +/-h, they could fully control a |
1062 |
|
|
* channel if there were no ops - it doesnt solve anything.. MODE_PRIVATE |
1063 |
|
|
* when used with MODE_SECRET is paranoid - cant use +p |
1064 |
|
|
* |
1065 |
|
|
* it needs to be optional per channel - but not via +p, that or remove |
1066 |
|
|
* paranoid.. -- fl_ |
1067 |
|
|
* |
1068 |
|
|
* +p means paranoid, it is useless for anything else on modern IRC, as |
1069 |
|
|
* list isn't really usable. If you want to have a private channel these |
1070 |
|
|
* days, you set it +s. Halfops can no longer remove simple modes when |
1071 |
|
|
* +p is set (although they can set +p) so it is safe to use this to |
1072 |
|
|
* control whether they can (de)halfop... |
1073 |
|
|
*/ |
1074 |
|
|
if (alev < |
1075 |
|
|
((chptr->mode.mode & MODE_PRIVATE) ? CHACCESS_CHANOP : CHACCESS_HALFOP)) |
1076 |
|
|
{ |
1077 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
1078 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1079 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1080 |
adx |
30 |
me.name, source_p->name, chname); |
1081 |
|
|
*errors |= SM_ERR_NOOPS; |
1082 |
|
|
return; |
1083 |
|
|
} |
1084 |
|
|
|
1085 |
|
|
if ((dir == MODE_QUERY) || (parc <= *parn)) |
1086 |
|
|
return; |
1087 |
|
|
|
1088 |
|
|
opnick = parv[(*parn)++]; |
1089 |
|
|
|
1090 |
michael |
2475 |
if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) |
1091 |
adx |
30 |
return; |
1092 |
|
|
if (!IsClient(targ_p)) |
1093 |
|
|
return; |
1094 |
|
|
|
1095 |
|
|
if ((member = find_channel_link(targ_p, chptr)) == NULL) |
1096 |
|
|
{ |
1097 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
1098 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), |
1099 |
adx |
30 |
me.name, source_p->name, opnick, chname); |
1100 |
|
|
*errors |= SM_ERR_NOTONCHANNEL; |
1101 |
|
|
return; |
1102 |
|
|
} |
1103 |
|
|
|
1104 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
1105 |
|
|
return; |
1106 |
|
|
|
1107 |
|
|
/* no redundant mode changes */ |
1108 |
adx |
356 |
if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP | CHFL_CHANOP)) |
1109 |
adx |
30 |
return; |
1110 |
|
|
if (dir == MODE_DEL && !has_member_flags(member, CHFL_HALFOP)) |
1111 |
|
|
return; |
1112 |
|
|
|
1113 |
|
|
mode_changes[mode_count].letter = 'h'; |
1114 |
|
|
mode_changes[mode_count].dir = dir; |
1115 |
adx |
356 |
mode_changes[mode_count].caps = CAP_HOPS; |
1116 |
adx |
30 |
mode_changes[mode_count].nocaps = 0; |
1117 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1118 |
|
|
mode_changes[mode_count].id = targ_p->id; |
1119 |
|
|
mode_changes[mode_count].arg = targ_p->name; |
1120 |
|
|
mode_changes[mode_count++].client = targ_p; |
1121 |
|
|
|
1122 |
adx |
356 |
mode_changes[mode_count].letter = 'o'; |
1123 |
|
|
mode_changes[mode_count].dir = dir; |
1124 |
|
|
mode_changes[mode_count].caps = 0; |
1125 |
|
|
mode_changes[mode_count].nocaps = CAP_HOPS; |
1126 |
|
|
mode_changes[mode_count].mems = ONLY_SERVERS; |
1127 |
|
|
mode_changes[mode_count].id = targ_p->id; |
1128 |
|
|
mode_changes[mode_count].arg = targ_p->name; |
1129 |
|
|
mode_changes[mode_count++].client = targ_p; |
1130 |
|
|
|
1131 |
adx |
30 |
if (dir == MODE_ADD) |
1132 |
|
|
{ |
1133 |
|
|
AddMemberFlag(member, CHFL_HALFOP); |
1134 |
|
|
DelMemberFlag(member, CHFL_DEOPPED); |
1135 |
|
|
} |
1136 |
|
|
else |
1137 |
|
|
DelMemberFlag(member, CHFL_HALFOP); |
1138 |
|
|
} |
1139 |
|
|
#endif |
1140 |
|
|
|
1141 |
|
|
static void |
1142 |
|
|
chm_voice(struct Client *client_p, struct Client *source_p, |
1143 |
|
|
struct Channel *chptr, int parc, int *parn, |
1144 |
|
|
char **parv, int *errors, int alev, int dir, char c, void *d, |
1145 |
|
|
const char *chname) |
1146 |
|
|
{ |
1147 |
michael |
2892 |
const char *opnick = NULL; |
1148 |
adx |
30 |
struct Client *targ_p; |
1149 |
|
|
struct Membership *member; |
1150 |
|
|
|
1151 |
|
|
if (alev < CHACCESS_HALFOP) |
1152 |
|
|
{ |
1153 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
1154 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1155 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1156 |
adx |
30 |
me.name, source_p->name, chname); |
1157 |
|
|
*errors |= SM_ERR_NOOPS; |
1158 |
|
|
return; |
1159 |
|
|
} |
1160 |
|
|
|
1161 |
|
|
if ((dir == MODE_QUERY) || parc <= *parn) |
1162 |
|
|
return; |
1163 |
|
|
|
1164 |
|
|
opnick = parv[(*parn)++]; |
1165 |
|
|
|
1166 |
michael |
2475 |
if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) |
1167 |
adx |
30 |
return; |
1168 |
|
|
if (!IsClient(targ_p)) |
1169 |
|
|
return; |
1170 |
|
|
|
1171 |
|
|
if ((member = find_channel_link(targ_p, chptr)) == NULL) |
1172 |
|
|
{ |
1173 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
1174 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), |
1175 |
adx |
30 |
me.name, source_p->name, opnick, chname); |
1176 |
|
|
*errors |= SM_ERR_NOTONCHANNEL; |
1177 |
|
|
return; |
1178 |
|
|
} |
1179 |
|
|
|
1180 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
1181 |
|
|
return; |
1182 |
|
|
|
1183 |
|
|
/* no redundant mode changes */ |
1184 |
|
|
if (dir == MODE_ADD && has_member_flags(member, CHFL_VOICE)) |
1185 |
|
|
return; |
1186 |
|
|
if (dir == MODE_DEL && !has_member_flags(member, CHFL_VOICE)) |
1187 |
|
|
return; |
1188 |
|
|
|
1189 |
|
|
mode_changes[mode_count].letter = 'v'; |
1190 |
|
|
mode_changes[mode_count].dir = dir; |
1191 |
|
|
mode_changes[mode_count].caps = 0; |
1192 |
|
|
mode_changes[mode_count].nocaps = 0; |
1193 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1194 |
|
|
mode_changes[mode_count].id = targ_p->id; |
1195 |
|
|
mode_changes[mode_count].arg = targ_p->name; |
1196 |
|
|
mode_changes[mode_count++].client = targ_p; |
1197 |
|
|
|
1198 |
|
|
if (dir == MODE_ADD) |
1199 |
|
|
AddMemberFlag(member, CHFL_VOICE); |
1200 |
|
|
else |
1201 |
|
|
DelMemberFlag(member, CHFL_VOICE); |
1202 |
|
|
} |
1203 |
|
|
|
1204 |
|
|
static void |
1205 |
|
|
chm_limit(struct Client *client_p, struct Client *source_p, |
1206 |
|
|
struct Channel *chptr, int parc, int *parn, |
1207 |
|
|
char **parv, int *errors, int alev, int dir, char c, void *d, |
1208 |
|
|
const char *chname) |
1209 |
|
|
{ |
1210 |
|
|
int i, limit; |
1211 |
|
|
char *lstr; |
1212 |
|
|
|
1213 |
|
|
if (alev < CHACCESS_HALFOP) |
1214 |
|
|
{ |
1215 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
1216 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1217 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1218 |
adx |
30 |
me.name, source_p->name, chname); |
1219 |
|
|
*errors |= SM_ERR_NOOPS; |
1220 |
|
|
return; |
1221 |
|
|
} |
1222 |
|
|
|
1223 |
|
|
if (dir == MODE_QUERY) |
1224 |
|
|
return; |
1225 |
|
|
|
1226 |
|
|
if ((dir == MODE_ADD) && parc > *parn) |
1227 |
|
|
{ |
1228 |
|
|
lstr = parv[(*parn)++]; |
1229 |
|
|
|
1230 |
|
|
if ((limit = atoi(lstr)) <= 0) |
1231 |
|
|
return; |
1232 |
|
|
|
1233 |
michael |
1793 |
sprintf(lstr, "%d", limit); |
1234 |
adx |
30 |
|
1235 |
|
|
/* if somebody sets MODE #channel +ll 1 2, accept latter --fl */ |
1236 |
|
|
for (i = 0; i < mode_count; i++) |
1237 |
|
|
if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD) |
1238 |
|
|
mode_changes[i].letter = 0; |
1239 |
|
|
|
1240 |
|
|
mode_changes[mode_count].letter = c; |
1241 |
|
|
mode_changes[mode_count].dir = MODE_ADD; |
1242 |
|
|
mode_changes[mode_count].caps = 0; |
1243 |
|
|
mode_changes[mode_count].nocaps = 0; |
1244 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1245 |
|
|
mode_changes[mode_count].id = NULL; |
1246 |
|
|
mode_changes[mode_count++].arg = lstr; |
1247 |
|
|
|
1248 |
|
|
chptr->mode.limit = limit; |
1249 |
|
|
} |
1250 |
|
|
else if (dir == MODE_DEL) |
1251 |
|
|
{ |
1252 |
|
|
if (!chptr->mode.limit) |
1253 |
|
|
return; |
1254 |
|
|
|
1255 |
|
|
chptr->mode.limit = 0; |
1256 |
|
|
|
1257 |
|
|
mode_changes[mode_count].letter = c; |
1258 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
1259 |
|
|
mode_changes[mode_count].caps = 0; |
1260 |
|
|
mode_changes[mode_count].nocaps = 0; |
1261 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1262 |
|
|
mode_changes[mode_count].id = NULL; |
1263 |
|
|
mode_changes[mode_count++].arg = NULL; |
1264 |
|
|
} |
1265 |
|
|
} |
1266 |
|
|
|
1267 |
|
|
static void |
1268 |
|
|
chm_key(struct Client *client_p, struct Client *source_p, |
1269 |
|
|
struct Channel *chptr, int parc, int *parn, |
1270 |
|
|
char **parv, int *errors, int alev, int dir, char c, void *d, |
1271 |
|
|
const char *chname) |
1272 |
|
|
{ |
1273 |
|
|
int i; |
1274 |
|
|
char *key; |
1275 |
|
|
|
1276 |
|
|
if (alev < CHACCESS_HALFOP) |
1277 |
|
|
{ |
1278 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
1279 |
michael |
1834 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1280 |
|
|
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1281 |
adx |
30 |
me.name, source_p->name, chname); |
1282 |
|
|
*errors |= SM_ERR_NOOPS; |
1283 |
|
|
return; |
1284 |
|
|
} |
1285 |
|
|
|
1286 |
|
|
if (dir == MODE_QUERY) |
1287 |
|
|
return; |
1288 |
|
|
|
1289 |
|
|
if ((dir == MODE_ADD) && parc > *parn) |
1290 |
|
|
{ |
1291 |
|
|
key = parv[(*parn)++]; |
1292 |
|
|
|
1293 |
|
|
if (MyClient(source_p)) |
1294 |
|
|
fix_key(key); |
1295 |
|
|
else |
1296 |
|
|
fix_key_old(key); |
1297 |
|
|
|
1298 |
|
|
if (*key == '\0') |
1299 |
|
|
return; |
1300 |
|
|
|
1301 |
|
|
assert(key[0] != ' '); |
1302 |
|
|
strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); |
1303 |
|
|
|
1304 |
|
|
/* if somebody does MODE #channel +kk a b, accept latter --fl */ |
1305 |
|
|
for (i = 0; i < mode_count; i++) |
1306 |
|
|
if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD) |
1307 |
|
|
mode_changes[i].letter = 0; |
1308 |
|
|
|
1309 |
|
|
mode_changes[mode_count].letter = c; |
1310 |
|
|
mode_changes[mode_count].dir = MODE_ADD; |
1311 |
|
|
mode_changes[mode_count].caps = 0; |
1312 |
|
|
mode_changes[mode_count].nocaps = 0; |
1313 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1314 |
|
|
mode_changes[mode_count].id = NULL; |
1315 |
|
|
mode_changes[mode_count++].arg = chptr->mode.key; |
1316 |
|
|
} |
1317 |
|
|
else if (dir == MODE_DEL) |
1318 |
|
|
{ |
1319 |
|
|
if (parc > *parn) |
1320 |
|
|
(*parn)++; |
1321 |
|
|
|
1322 |
|
|
if (chptr->mode.key[0] == '\0') |
1323 |
|
|
return; |
1324 |
|
|
|
1325 |
|
|
chptr->mode.key[0] = '\0'; |
1326 |
|
|
|
1327 |
|
|
mode_changes[mode_count].letter = c; |
1328 |
|
|
mode_changes[mode_count].dir = MODE_DEL; |
1329 |
|
|
mode_changes[mode_count].caps = 0; |
1330 |
|
|
mode_changes[mode_count].nocaps = 0; |
1331 |
|
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
1332 |
|
|
mode_changes[mode_count].id = NULL; |
1333 |
|
|
mode_changes[mode_count++].arg = "*"; |
1334 |
|
|
} |
1335 |
|
|
} |
1336 |
|
|
|
1337 |
|
|
struct ChannelMode |
1338 |
|
|
{ |
1339 |
|
|
void (*func) (struct Client *client_p, struct Client *source_p, |
1340 |
|
|
struct Channel *chptr, int parc, int *parn, char **parv, |
1341 |
|
|
int *errors, int alev, int dir, char c, void *d, |
1342 |
|
|
const char *chname); |
1343 |
|
|
void *d; |
1344 |
|
|
}; |
1345 |
|
|
|
1346 |
|
|
static struct ChannelMode ModeTable[255] = |
1347 |
|
|
{ |
1348 |
|
|
{chm_nosuch, NULL}, |
1349 |
|
|
{chm_nosuch, NULL}, /* A */ |
1350 |
|
|
{chm_nosuch, NULL}, /* B */ |
1351 |
|
|
{chm_nosuch, NULL}, /* C */ |
1352 |
|
|
{chm_nosuch, NULL}, /* D */ |
1353 |
|
|
{chm_nosuch, NULL}, /* E */ |
1354 |
|
|
{chm_nosuch, NULL}, /* F */ |
1355 |
|
|
{chm_nosuch, NULL}, /* G */ |
1356 |
|
|
{chm_nosuch, NULL}, /* H */ |
1357 |
|
|
{chm_invex, NULL}, /* I */ |
1358 |
|
|
{chm_nosuch, NULL}, /* J */ |
1359 |
|
|
{chm_nosuch, NULL}, /* K */ |
1360 |
|
|
{chm_nosuch, NULL}, /* L */ |
1361 |
michael |
1954 |
{chm_simple, (void *)MODE_MODREG}, /* M */ |
1362 |
adx |
30 |
{chm_nosuch, NULL}, /* N */ |
1363 |
michael |
1150 |
{chm_operonly, (void *) MODE_OPERONLY}, /* O */ |
1364 |
adx |
30 |
{chm_nosuch, NULL}, /* P */ |
1365 |
|
|
{chm_nosuch, NULL}, /* Q */ |
1366 |
michael |
1175 |
{chm_simple, (void *) MODE_REGONLY}, /* R */ |
1367 |
michael |
1150 |
{chm_simple, (void *) MODE_SSLONLY}, /* S */ |
1368 |
adx |
30 |
{chm_nosuch, NULL}, /* T */ |
1369 |
|
|
{chm_nosuch, NULL}, /* U */ |
1370 |
|
|
{chm_nosuch, NULL}, /* V */ |
1371 |
|
|
{chm_nosuch, NULL}, /* W */ |
1372 |
|
|
{chm_nosuch, NULL}, /* X */ |
1373 |
|
|
{chm_nosuch, NULL}, /* Y */ |
1374 |
|
|
{chm_nosuch, NULL}, /* Z */ |
1375 |
|
|
{chm_nosuch, NULL}, |
1376 |
|
|
{chm_nosuch, NULL}, |
1377 |
|
|
{chm_nosuch, NULL}, |
1378 |
|
|
{chm_nosuch, NULL}, |
1379 |
|
|
{chm_nosuch, NULL}, |
1380 |
|
|
{chm_nosuch, NULL}, |
1381 |
michael |
2892 |
{chm_nosuch, NULL}, /* a */ |
1382 |
adx |
30 |
{chm_ban, NULL}, /* b */ |
1383 |
michael |
1937 |
{chm_simple, (void *) MODE_NOCTRL}, /* c */ |
1384 |
adx |
30 |
{chm_nosuch, NULL}, /* d */ |
1385 |
|
|
{chm_except, NULL}, /* e */ |
1386 |
|
|
{chm_nosuch, NULL}, /* f */ |
1387 |
|
|
{chm_nosuch, NULL}, /* g */ |
1388 |
|
|
#ifdef HALFOPS |
1389 |
|
|
{chm_hop, NULL}, /* h */ |
1390 |
|
|
#else |
1391 |
michael |
2892 |
{chm_nosuch, NULL}, /* h */ |
1392 |
adx |
30 |
#endif |
1393 |
|
|
{chm_simple, (void *) MODE_INVITEONLY}, /* i */ |
1394 |
|
|
{chm_nosuch, NULL}, /* j */ |
1395 |
|
|
{chm_key, NULL}, /* k */ |
1396 |
|
|
{chm_limit, NULL}, /* l */ |
1397 |
|
|
{chm_simple, (void *) MODE_MODERATED}, /* m */ |
1398 |
|
|
{chm_simple, (void *) MODE_NOPRIVMSGS}, /* n */ |
1399 |
|
|
{chm_op, NULL}, /* o */ |
1400 |
|
|
{chm_simple, (void *) MODE_PRIVATE}, /* p */ |
1401 |
|
|
{chm_nosuch, NULL}, /* q */ |
1402 |
michael |
1167 |
{chm_registered, (void *) MODE_REGISTERED}, /* r */ |
1403 |
adx |
30 |
{chm_simple, (void *) MODE_SECRET}, /* s */ |
1404 |
|
|
{chm_simple, (void *) MODE_TOPICLIMIT}, /* t */ |
1405 |
|
|
{chm_nosuch, NULL}, /* u */ |
1406 |
|
|
{chm_voice, NULL}, /* v */ |
1407 |
|
|
{chm_nosuch, NULL}, /* w */ |
1408 |
|
|
{chm_nosuch, NULL}, /* x */ |
1409 |
|
|
{chm_nosuch, NULL}, /* y */ |
1410 |
|
|
{chm_nosuch, NULL}, /* z */ |
1411 |
|
|
}; |
1412 |
|
|
|
1413 |
|
|
/* get_channel_access() |
1414 |
|
|
* |
1415 |
|
|
* inputs - pointer to Client struct |
1416 |
|
|
* - pointer to Membership struct |
1417 |
|
|
* output - CHACCESS_CHANOP if we should let them have |
1418 |
|
|
* chanop level access, 0 for peon level access. |
1419 |
|
|
* side effects - NONE |
1420 |
|
|
*/ |
1421 |
|
|
static int |
1422 |
|
|
get_channel_access(struct Client *source_p, struct Membership *member) |
1423 |
|
|
{ |
1424 |
|
|
/* Let hacked servers in for now... */ |
1425 |
|
|
if (!MyClient(source_p)) |
1426 |
|
|
return CHACCESS_CHANOP; |
1427 |
|
|
|
1428 |
|
|
if (member == NULL) |
1429 |
|
|
return CHACCESS_NOTONCHAN; |
1430 |
|
|
|
1431 |
|
|
/* just to be sure.. */ |
1432 |
|
|
assert(source_p == member->client_p); |
1433 |
|
|
|
1434 |
|
|
if (has_member_flags(member, CHFL_CHANOP)) |
1435 |
|
|
return CHACCESS_CHANOP; |
1436 |
|
|
|
1437 |
|
|
#ifdef HALFOPS |
1438 |
|
|
if (has_member_flags(member, CHFL_HALFOP)) |
1439 |
|
|
return CHACCESS_HALFOP; |
1440 |
|
|
#endif |
1441 |
|
|
|
1442 |
|
|
return CHACCESS_PEON; |
1443 |
|
|
} |
1444 |
|
|
|
1445 |
|
|
/* void send_cap_mode_changes(struct Client *client_p, |
1446 |
|
|
* struct Client *source_p, |
1447 |
|
|
* struct Channel *chptr, int cap, int nocap) |
1448 |
|
|
* Input: The client sending(client_p), the source client(source_p), |
1449 |
|
|
* the channel to send mode changes for(chptr) |
1450 |
|
|
* Output: None. |
1451 |
|
|
* Side-effects: Sends the appropriate mode changes to capable servers. |
1452 |
|
|
* |
1453 |
|
|
* send_cap_mode_changes() will loop the server list itself, because |
1454 |
|
|
* at this point in time we have 4 capabs for channels, CAP_IE, CAP_EX, |
1455 |
|
|
* and a server could support any number of these.. |
1456 |
|
|
* so we make the modebufs per server, tailoring them to each servers |
1457 |
|
|
* specific demand. Its not very pretty, but its one of the few realistic |
1458 |
|
|
* ways to handle having this many capabs for channel modes.. --fl_ |
1459 |
|
|
* |
1460 |
|
|
* Reverted back to my original design, except that we now keep a count |
1461 |
|
|
* of the number of servers which each combination as an optimisation, so |
1462 |
|
|
* the capabs combinations which are not needed are not worked out. -A1kmm |
1463 |
|
|
*/ |
1464 |
|
|
/* rewritten to ensure parabuf < MODEBUFLEN -db */ |
1465 |
|
|
|
1466 |
|
|
static void |
1467 |
|
|
send_cap_mode_changes(struct Client *client_p, struct Client *source_p, |
1468 |
michael |
1015 |
struct Channel *chptr, unsigned int cap, unsigned int nocap) |
1469 |
adx |
30 |
{ |
1470 |
|
|
int i, mbl, pbl, arglen, nc, mc; |
1471 |
|
|
int len; |
1472 |
|
|
const char *arg = NULL; |
1473 |
|
|
char *parptr; |
1474 |
|
|
int dir = MODE_QUERY; |
1475 |
|
|
|
1476 |
|
|
mc = 0; |
1477 |
|
|
nc = 0; |
1478 |
|
|
pbl = 0; |
1479 |
|
|
|
1480 |
|
|
parabuf[0] = '\0'; |
1481 |
|
|
parptr = parabuf; |
1482 |
|
|
|
1483 |
|
|
if ((cap & CAP_TS6) && source_p->id[0] != '\0') |
1484 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s TMODE %lu %s ", source_p->id, |
1485 |
michael |
2892 |
(unsigned long)chptr->channelts, chptr->chname); |
1486 |
adx |
30 |
else |
1487 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s MODE %s ", source_p->name, |
1488 |
michael |
2892 |
chptr->chname); |
1489 |
adx |
30 |
|
1490 |
|
|
/* loop the list of - modes we have */ |
1491 |
|
|
for (i = 0; i < mode_count; i++) |
1492 |
|
|
{ |
1493 |
|
|
/* if they dont support the cap we need, or they do support a cap they |
1494 |
|
|
* cant have, then dont add it to the modebuf.. that way they wont see |
1495 |
|
|
* the mode |
1496 |
|
|
*/ |
1497 |
|
|
if ((mode_changes[i].letter == 0) || |
1498 |
michael |
2892 |
((cap & mode_changes[i].caps) != mode_changes[i].caps) || |
1499 |
|
|
((nocap & mode_changes[i].nocaps) != mode_changes[i].nocaps)) |
1500 |
adx |
30 |
continue; |
1501 |
|
|
|
1502 |
|
|
arg = ""; |
1503 |
|
|
|
1504 |
|
|
if ((cap & CAP_TS6) && mode_changes[i].id) |
1505 |
|
|
arg = mode_changes[i].id; |
1506 |
|
|
if (*arg == '\0') |
1507 |
|
|
arg = mode_changes[i].arg; |
1508 |
|
|
|
1509 |
|
|
/* if we're creeping past the buf size, we need to send it and make |
1510 |
|
|
* another line for the other modes |
1511 |
|
|
* XXX - this could give away server topology with uids being |
1512 |
|
|
* different lengths, but not much we can do, except possibly break |
1513 |
|
|
* them as if they were the longest of the nick or uid at all times, |
1514 |
|
|
* which even then won't work as we don't always know the uid -A1kmm. |
1515 |
|
|
*/ |
1516 |
|
|
if (arg != NULL) |
1517 |
|
|
arglen = strlen(arg); |
1518 |
|
|
else |
1519 |
|
|
arglen = 0; |
1520 |
|
|
|
1521 |
|
|
if ((mc == MAXMODEPARAMS) || |
1522 |
|
|
((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) || |
1523 |
|
|
(pbl + arglen + BAN_FUDGE) >= MODEBUFLEN) |
1524 |
|
|
{ |
1525 |
|
|
if (nc != 0) |
1526 |
michael |
2892 |
sendto_server(client_p, cap, nocap, "%s %s", modebuf, parabuf); |
1527 |
adx |
30 |
nc = 0; |
1528 |
|
|
mc = 0; |
1529 |
|
|
|
1530 |
|
|
if ((cap & CAP_TS6) && source_p->id[0] != '\0') |
1531 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s MODE %s ", source_p->id, |
1532 |
|
|
chptr->chname); |
1533 |
adx |
30 |
else |
1534 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s MODE %s ", source_p->name, |
1535 |
|
|
chptr->chname); |
1536 |
adx |
30 |
|
1537 |
|
|
pbl = 0; |
1538 |
|
|
parabuf[0] = '\0'; |
1539 |
|
|
parptr = parabuf; |
1540 |
|
|
dir = MODE_QUERY; |
1541 |
|
|
} |
1542 |
|
|
|
1543 |
|
|
if (dir != mode_changes[i].dir) |
1544 |
|
|
{ |
1545 |
|
|
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
1546 |
|
|
dir = mode_changes[i].dir; |
1547 |
|
|
} |
1548 |
|
|
|
1549 |
|
|
modebuf[mbl++] = mode_changes[i].letter; |
1550 |
|
|
modebuf[mbl] = '\0'; |
1551 |
|
|
nc++; |
1552 |
|
|
|
1553 |
|
|
if (arg != NULL) |
1554 |
|
|
{ |
1555 |
michael |
1793 |
len = sprintf(parptr, "%s ", arg); |
1556 |
adx |
30 |
pbl += len; |
1557 |
|
|
parptr += len; |
1558 |
|
|
mc++; |
1559 |
|
|
} |
1560 |
|
|
} |
1561 |
|
|
|
1562 |
|
|
if (pbl && parabuf[pbl - 1] == ' ') |
1563 |
|
|
parabuf[pbl - 1] = 0; |
1564 |
|
|
|
1565 |
|
|
if (nc != 0) |
1566 |
michael |
2892 |
sendto_server(client_p, cap, nocap, "%s %s", modebuf, parabuf); |
1567 |
adx |
30 |
} |
1568 |
|
|
|
1569 |
|
|
/* void send_mode_changes(struct Client *client_p, |
1570 |
|
|
* struct Client *source_p, |
1571 |
|
|
* struct Channel *chptr) |
1572 |
|
|
* Input: The client sending(client_p), the source client(source_p), |
1573 |
|
|
* the channel to send mode changes for(chptr), |
1574 |
|
|
* mode change globals. |
1575 |
|
|
* Output: None. |
1576 |
|
|
* Side-effects: Sends the appropriate mode changes to other clients |
1577 |
|
|
* and propagates to servers. |
1578 |
|
|
*/ |
1579 |
|
|
/* ensure parabuf < MODEBUFLEN -db */ |
1580 |
|
|
static void |
1581 |
|
|
send_mode_changes(struct Client *client_p, struct Client *source_p, |
1582 |
|
|
struct Channel *chptr, char *chname) |
1583 |
|
|
{ |
1584 |
|
|
int i, mbl, pbl, arglen, nc, mc; |
1585 |
|
|
int len; |
1586 |
|
|
const char *arg = NULL; |
1587 |
|
|
char *parptr; |
1588 |
|
|
int dir = MODE_QUERY; |
1589 |
|
|
|
1590 |
|
|
/* bail out if we have nothing to do... */ |
1591 |
|
|
if (!mode_count) |
1592 |
|
|
return; |
1593 |
|
|
|
1594 |
|
|
if (IsServer(source_p)) |
1595 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s MODE %s ", (IsHidden(source_p) || |
1596 |
|
|
ConfigServerHide.hide_servers) ? |
1597 |
|
|
me.name : source_p->name, chname); |
1598 |
adx |
30 |
else |
1599 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s!%s@%s MODE %s ", source_p->name, |
1600 |
|
|
source_p->username, source_p->host, chname); |
1601 |
adx |
30 |
|
1602 |
|
|
mc = 0; |
1603 |
|
|
nc = 0; |
1604 |
|
|
pbl = 0; |
1605 |
|
|
|
1606 |
|
|
parabuf[0] = '\0'; |
1607 |
|
|
parptr = parabuf; |
1608 |
|
|
|
1609 |
|
|
for (i = 0; i < mode_count; i++) |
1610 |
|
|
{ |
1611 |
|
|
if (mode_changes[i].letter == 0 || |
1612 |
|
|
mode_changes[i].mems == NON_CHANOPS || |
1613 |
|
|
mode_changes[i].mems == ONLY_SERVERS) |
1614 |
|
|
continue; |
1615 |
|
|
|
1616 |
|
|
arg = mode_changes[i].arg; |
1617 |
|
|
if (arg != NULL) |
1618 |
|
|
arglen = strlen(arg); |
1619 |
|
|
else |
1620 |
|
|
arglen = 0; |
1621 |
|
|
|
1622 |
michael |
2892 |
if ((mc == MAXMODEPARAMS) || |
1623 |
adx |
30 |
((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) || |
1624 |
michael |
2892 |
((arglen + pbl + BAN_FUDGE) >= MODEBUFLEN)) |
1625 |
adx |
30 |
{ |
1626 |
|
|
if (mbl && modebuf[mbl - 1] == '-') |
1627 |
|
|
modebuf[mbl - 1] = '\0'; |
1628 |
|
|
|
1629 |
|
|
if (nc != 0) |
1630 |
michael |
1243 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf); |
1631 |
adx |
30 |
|
1632 |
|
|
nc = 0; |
1633 |
|
|
mc = 0; |
1634 |
|
|
|
1635 |
|
|
if (IsServer(source_p)) |
1636 |
michael |
2557 |
mbl = sprintf(modebuf, ":%s MODE %s ", (IsHidden(source_p) || |
1637 |
|
|
ConfigServerHide.hide_servers) ? |
1638 |
|
|
me.name : source_p->name, chname); |
1639 |
adx |
30 |
else |
1640 |
michael |
1793 |
mbl = sprintf(modebuf, ":%s!%s@%s MODE %s ", source_p->name, |
1641 |
|
|
source_p->username, source_p->host, chname); |
1642 |
adx |
30 |
|
1643 |
|
|
pbl = 0; |
1644 |
|
|
parabuf[0] = '\0'; |
1645 |
|
|
parptr = parabuf; |
1646 |
|
|
dir = MODE_QUERY; |
1647 |
|
|
} |
1648 |
|
|
|
1649 |
|
|
if (dir != mode_changes[i].dir) |
1650 |
|
|
{ |
1651 |
|
|
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
1652 |
|
|
dir = mode_changes[i].dir; |
1653 |
|
|
} |
1654 |
|
|
|
1655 |
|
|
modebuf[mbl++] = mode_changes[i].letter; |
1656 |
|
|
modebuf[mbl] = '\0'; |
1657 |
|
|
nc++; |
1658 |
|
|
|
1659 |
|
|
if (arg != NULL) |
1660 |
|
|
{ |
1661 |
michael |
1793 |
len = sprintf(parptr, "%s ", arg); |
1662 |
adx |
30 |
pbl += len; |
1663 |
|
|
parptr += len; |
1664 |
|
|
mc++; |
1665 |
|
|
} |
1666 |
|
|
} |
1667 |
|
|
|
1668 |
|
|
if (pbl && parabuf[pbl - 1] == ' ') |
1669 |
|
|
parabuf[pbl - 1] = 0; |
1670 |
|
|
|
1671 |
|
|
if (nc != 0) |
1672 |
michael |
1243 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf); |
1673 |
adx |
30 |
|
1674 |
|
|
nc = 0; |
1675 |
|
|
mc = 0; |
1676 |
|
|
|
1677 |
|
|
/* Now send to servers... */ |
1678 |
|
|
for (i = 0; i < NCHCAP_COMBOS; i++) |
1679 |
|
|
if (chcap_combos[i].count != 0) |
1680 |
|
|
send_cap_mode_changes(client_p, source_p, chptr, |
1681 |
|
|
chcap_combos[i].cap_yes, |
1682 |
|
|
chcap_combos[i].cap_no); |
1683 |
|
|
} |
1684 |
|
|
|
1685 |
|
|
/* void set_channel_mode(struct Client *client_p, struct Client *source_p, |
1686 |
|
|
* struct Channel *chptr, int parc, char **parv, |
1687 |
|
|
* char *chname) |
1688 |
|
|
* Input: The client we received this from, the client this originated |
1689 |
|
|
* from, the channel, the parameter count starting at the modes, |
1690 |
|
|
* the parameters, the channel name. |
1691 |
|
|
* Output: None. |
1692 |
|
|
* Side-effects: Changes the channel membership and modes appropriately, |
1693 |
|
|
* sends the appropriate MODE messages to the appropriate |
1694 |
|
|
* clients. |
1695 |
|
|
*/ |
1696 |
|
|
void |
1697 |
|
|
set_channel_mode(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
1698 |
|
|
struct Membership *member, int parc, char *parv[], char *chname) |
1699 |
|
|
{ |
1700 |
|
|
int dir = MODE_ADD; |
1701 |
|
|
int parn = 1; |
1702 |
|
|
int alevel, errors = 0; |
1703 |
|
|
char *ml = parv[0], c; |
1704 |
|
|
int table_position; |
1705 |
|
|
|
1706 |
|
|
mode_count = 0; |
1707 |
|
|
mode_limit = 0; |
1708 |
|
|
simple_modes_mask = 0; |
1709 |
|
|
|
1710 |
|
|
alevel = get_channel_access(source_p, member); |
1711 |
|
|
|
1712 |
michael |
2892 |
for (; (c = *ml) != '\0'; ml++) |
1713 |
adx |
30 |
{ |
1714 |
|
|
switch (c) |
1715 |
|
|
{ |
1716 |
|
|
case '+': |
1717 |
|
|
dir = MODE_ADD; |
1718 |
|
|
break; |
1719 |
|
|
case '-': |
1720 |
|
|
dir = MODE_DEL; |
1721 |
|
|
break; |
1722 |
|
|
case '=': |
1723 |
|
|
dir = MODE_QUERY; |
1724 |
|
|
break; |
1725 |
|
|
default: |
1726 |
|
|
if (c < 'A' || c > 'z') |
1727 |
|
|
table_position = 0; |
1728 |
|
|
else |
1729 |
|
|
table_position = c - 'A' + 1; |
1730 |
|
|
ModeTable[table_position].func(client_p, source_p, chptr, |
1731 |
|
|
parc, &parn, |
1732 |
|
|
parv, &errors, alevel, dir, c, |
1733 |
|
|
ModeTable[table_position].d, |
1734 |
|
|
chname); |
1735 |
|
|
break; |
1736 |
|
|
} |
1737 |
|
|
} |
1738 |
|
|
|
1739 |
|
|
send_mode_changes(client_p, source_p, chptr, chname); |
1740 |
|
|
} |