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