| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2018 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.c |
| 23 |
* \brief Responsible for managing channels, members, bans and topics |
| 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 "hash.h" |
| 33 |
#include "conf.h" |
| 34 |
#include "conf_resv.h" |
| 35 |
#include "hostmask.h" |
| 36 |
#include "irc_string.h" |
| 37 |
#include "ircd.h" |
| 38 |
#include "numeric.h" |
| 39 |
#include "server.h" |
| 40 |
#include "send.h" |
| 41 |
#include "event.h" |
| 42 |
#include "memory.h" |
| 43 |
#include "misc.h" |
| 44 |
|
| 45 |
|
| 46 |
dlink_list channel_list; |
| 47 |
|
| 48 |
|
| 49 |
/*! \brief Adds a user to a channel by adding another link to the |
| 50 |
* channels member chain. |
| 51 |
* \param chptr Pointer to channel to add client to |
| 52 |
* \param client_p Pointer to client (who) to add |
| 53 |
* \param flags Flags for chanops etc |
| 54 |
* \param flood_ctrl Whether to count this join in flood calculations |
| 55 |
*/ |
| 56 |
void |
| 57 |
add_user_to_channel(struct Channel *chptr, struct Client *client_p, |
| 58 |
unsigned int flags, int flood_ctrl) |
| 59 |
{ |
| 60 |
assert(IsClient(client_p)); |
| 61 |
|
| 62 |
if (GlobalSetOptions.joinfloodtime) |
| 63 |
{ |
| 64 |
if (flood_ctrl) |
| 65 |
++chptr->number_joined; |
| 66 |
|
| 67 |
chptr->number_joined -= (CurrentTime - chptr->last_join_time) * |
| 68 |
(((float)GlobalSetOptions.joinfloodcount) / |
| 69 |
(float)GlobalSetOptions.joinfloodtime); |
| 70 |
|
| 71 |
if (chptr->number_joined <= 0) |
| 72 |
{ |
| 73 |
chptr->number_joined = 0; |
| 74 |
ClearJoinFloodNoticed(chptr); |
| 75 |
} |
| 76 |
else if (chptr->number_joined >= GlobalSetOptions.joinfloodcount) |
| 77 |
{ |
| 78 |
chptr->number_joined = GlobalSetOptions.joinfloodcount; |
| 79 |
|
| 80 |
if (!IsSetJoinFloodNoticed(chptr)) |
| 81 |
{ |
| 82 |
SetJoinFloodNoticed(chptr); |
| 83 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
| 84 |
"Possible Join Flooder %s on %s target: %s", |
| 85 |
client_get_name(client_p, HIDE_IP), |
| 86 |
client_p->servptr->name, chptr->name); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
chptr->last_join_time = CurrentTime; |
| 91 |
} |
| 92 |
|
| 93 |
struct Membership *member = xcalloc(sizeof(*member)); |
| 94 |
member->client_p = client_p; |
| 95 |
member->chptr = chptr; |
| 96 |
member->flags = flags; |
| 97 |
|
| 98 |
dlinkAdd(member, &member->channode, &chptr->members); |
| 99 |
|
| 100 |
if (MyConnect(client_p)) |
| 101 |
dlinkAdd(member, &member->locchannode, &chptr->locmembers); |
| 102 |
|
| 103 |
dlinkAdd(member, &member->usernode, &client_p->channel); |
| 104 |
} |
| 105 |
|
| 106 |
/*! \brief Deletes an user from a channel by removing a link in the |
| 107 |
* channels member chain. |
| 108 |
* \param member Pointer to Membership struct |
| 109 |
*/ |
| 110 |
void |
| 111 |
remove_user_from_channel(struct Membership *member) |
| 112 |
{ |
| 113 |
struct Client *const client_p = member->client_p; |
| 114 |
struct Channel *const chptr = member->chptr; |
| 115 |
|
| 116 |
dlinkDelete(&member->channode, &chptr->members); |
| 117 |
|
| 118 |
if (MyConnect(client_p)) |
| 119 |
dlinkDelete(&member->locchannode, &chptr->locmembers); |
| 120 |
|
| 121 |
dlinkDelete(&member->usernode, &client_p->channel); |
| 122 |
|
| 123 |
xfree(member); |
| 124 |
|
| 125 |
if (chptr->members.head == NULL) |
| 126 |
channel_free(chptr); |
| 127 |
} |
| 128 |
|
| 129 |
/* channel_send_members() |
| 130 |
* |
| 131 |
* inputs - |
| 132 |
* output - NONE |
| 133 |
* side effects - |
| 134 |
*/ |
| 135 |
static void |
| 136 |
channel_send_members(struct Client *client_p, const struct Channel *chptr, |
| 137 |
const char *modebuf, const char *parabuf) |
| 138 |
{ |
| 139 |
dlink_node *node; |
| 140 |
char buf[IRCD_BUFSIZE] = ""; |
| 141 |
int tlen; /* length of text to append */ |
| 142 |
char *t, *start; /* temp char pointer */ |
| 143 |
|
| 144 |
start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %ju %s %s %s:", |
| 145 |
me.id, chptr->creationtime, |
| 146 |
chptr->name, modebuf, parabuf); |
| 147 |
|
| 148 |
DLINK_FOREACH(node, chptr->members.head) |
| 149 |
{ |
| 150 |
const struct Membership *member = node->data; |
| 151 |
|
| 152 |
tlen = strlen(member->client_p->id) + 1; /* +1 for space */ |
| 153 |
|
| 154 |
if (member->flags & CHFL_CHANOP) |
| 155 |
++tlen; |
| 156 |
if (member->flags & CHFL_HALFOP) |
| 157 |
++tlen; |
| 158 |
if (member->flags & CHFL_VOICE) |
| 159 |
++tlen; |
| 160 |
|
| 161 |
/* |
| 162 |
* Space will be converted into CR, but we also need space for LF.. |
| 163 |
* That's why we use '- 1' here -adx |
| 164 |
*/ |
| 165 |
if (t + tlen - buf > IRCD_BUFSIZE - 1) |
| 166 |
{ |
| 167 |
*(t - 1) = '\0'; /* Kill the space and terminate the string */ |
| 168 |
sendto_one(client_p, "%s", buf); |
| 169 |
t = start; |
| 170 |
} |
| 171 |
|
| 172 |
if (member->flags & CHFL_CHANOP) |
| 173 |
*t++ = '@'; |
| 174 |
if (member->flags & CHFL_HALFOP) |
| 175 |
*t++ = '%'; |
| 176 |
if (member->flags & CHFL_VOICE) |
| 177 |
*t++ = '+'; |
| 178 |
|
| 179 |
strcpy(t, member->client_p->id); |
| 180 |
|
| 181 |
t += strlen(t); |
| 182 |
*t++ = ' '; |
| 183 |
} |
| 184 |
|
| 185 |
/* Should always be non-NULL unless we have a kind of persistent channels */ |
| 186 |
if (chptr->members.head) |
| 187 |
t--; /* Take the space out */ |
| 188 |
*t = '\0'; |
| 189 |
sendto_one(client_p, "%s", buf); |
| 190 |
} |
| 191 |
|
| 192 |
/*! \brief Sends +b/+e/+I |
| 193 |
* \param client_p Client pointer to server |
| 194 |
* \param chptr Pointer to channel |
| 195 |
* \param list Pointer to list of modes to send |
| 196 |
* \param flag Char flag flagging type of mode. Currently this can be 'b', e' or 'I' |
| 197 |
*/ |
| 198 |
static void |
| 199 |
channel_send_mask_list(struct Client *client_p, const struct Channel *chptr, |
| 200 |
const dlink_list *list, const char flag) |
| 201 |
{ |
| 202 |
dlink_node *node; |
| 203 |
char mbuf[IRCD_BUFSIZE] = ""; |
| 204 |
char pbuf[IRCD_BUFSIZE] = ""; |
| 205 |
int tlen, mlen, cur_len; |
| 206 |
char *pp = pbuf; |
| 207 |
|
| 208 |
if (!dlink_list_length(list)) |
| 209 |
return; |
| 210 |
|
| 211 |
mlen = snprintf(mbuf, sizeof(mbuf), ":%s BMASK %ju %s %c :", me.id, |
| 212 |
chptr->creationtime, chptr->name, flag); |
| 213 |
cur_len = mlen; |
| 214 |
|
| 215 |
DLINK_FOREACH(node, list->head) |
| 216 |
{ |
| 217 |
const struct Ban *ban = node->data; |
| 218 |
|
| 219 |
tlen = ban->len + 3; /* +3 for ! + @ + space */ |
| 220 |
|
| 221 |
/* |
| 222 |
* Send buffer and start over if we cannot fit another ban |
| 223 |
*/ |
| 224 |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2) |
| 225 |
{ |
| 226 |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
| 227 |
sendto_one(client_p, "%s%s", mbuf, pbuf); |
| 228 |
|
| 229 |
cur_len = mlen; |
| 230 |
pp = pbuf; |
| 231 |
} |
| 232 |
|
| 233 |
pp += sprintf(pp, "%s!%s@%s ", ban->name, ban->user, ban->host); |
| 234 |
cur_len += tlen; |
| 235 |
} |
| 236 |
|
| 237 |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
| 238 |
sendto_one(client_p, "%s%s", mbuf, pbuf); |
| 239 |
} |
| 240 |
|
| 241 |
/*! \brief Send "client_p" a full list of the modes for channel chptr |
| 242 |
* \param client_p Pointer to client client_p |
| 243 |
* \param chptr Pointer to channel pointer |
| 244 |
*/ |
| 245 |
void |
| 246 |
channel_send_modes(struct Client *client_p, struct Channel *chptr) |
| 247 |
{ |
| 248 |
char modebuf[MODEBUFLEN] = ""; |
| 249 |
char parabuf[MODEBUFLEN] = ""; |
| 250 |
|
| 251 |
channel_modes(chptr, client_p, modebuf, parabuf); |
| 252 |
channel_send_members(client_p, chptr, modebuf, parabuf); |
| 253 |
|
| 254 |
channel_send_mask_list(client_p, chptr, &chptr->banlist, 'b'); |
| 255 |
channel_send_mask_list(client_p, chptr, &chptr->exceptlist, 'e'); |
| 256 |
channel_send_mask_list(client_p, chptr, &chptr->invexlist, 'I'); |
| 257 |
} |
| 258 |
|
| 259 |
/*! \brief Check channel name for invalid characters |
| 260 |
* \param name Pointer to channel name string |
| 261 |
* \param local Indicates whether it's a local or remote creation |
| 262 |
* \return 0 if invalid, 1 otherwise |
| 263 |
*/ |
| 264 |
int |
| 265 |
channel_check_name(const char *name, const int local) |
| 266 |
{ |
| 267 |
const char *p = name; |
| 268 |
|
| 269 |
assert(!EmptyString(p)); |
| 270 |
|
| 271 |
if (!IsChanPrefix(*p)) |
| 272 |
return 0; |
| 273 |
|
| 274 |
if (!local || !ConfigChannel.disable_fake_channels) |
| 275 |
{ |
| 276 |
while (*++p) |
| 277 |
if (!IsChanChar(*p)) |
| 278 |
return 0; |
| 279 |
} |
| 280 |
else |
| 281 |
{ |
| 282 |
while (*++p) |
| 283 |
if (!IsVisibleChanChar(*p)) |
| 284 |
return 0; |
| 285 |
} |
| 286 |
|
| 287 |
return p - name <= CHANNELLEN; |
| 288 |
} |
| 289 |
|
| 290 |
void |
| 291 |
remove_ban(struct Ban *ban, dlink_list *list) |
| 292 |
{ |
| 293 |
dlinkDelete(&ban->node, list); |
| 294 |
xfree(ban); |
| 295 |
} |
| 296 |
|
| 297 |
/* channel_free_mask_list() |
| 298 |
* |
| 299 |
* inputs - pointer to dlink_list |
| 300 |
* output - NONE |
| 301 |
* side effects - |
| 302 |
*/ |
| 303 |
static void |
| 304 |
channel_free_mask_list(dlink_list *list) |
| 305 |
{ |
| 306 |
while (list->head) |
| 307 |
{ |
| 308 |
struct Ban *ban = list->head->data; |
| 309 |
remove_ban(ban, list); |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
/*! \brief Get Channel block for name (and allocate a new channel |
| 314 |
* block, if it didn't exist before) |
| 315 |
* \param name Channel name |
| 316 |
* \return Channel block |
| 317 |
*/ |
| 318 |
struct Channel * |
| 319 |
channel_make(const char *name) |
| 320 |
{ |
| 321 |
assert(!EmptyString(name)); |
| 322 |
|
| 323 |
struct Channel *chptr = xcalloc(sizeof(*chptr)); |
| 324 |
/* Doesn't hurt to set it here */ |
| 325 |
chptr->creationtime = CurrentTime; |
| 326 |
chptr->last_join_time = CurrentTime; |
| 327 |
|
| 328 |
/* Cache channel name length to avoid repetitive strlen() calls. */ |
| 329 |
chptr->name_len = strlcpy(chptr->name, name, sizeof(chptr->name)); |
| 330 |
if (chptr->name_len >= sizeof(chptr->name)) |
| 331 |
chptr->name_len = sizeof(chptr->name) - 1; |
| 332 |
|
| 333 |
dlinkAdd(chptr, &chptr->node, &channel_list); |
| 334 |
hash_add_channel(chptr); |
| 335 |
|
| 336 |
return chptr; |
| 337 |
} |
| 338 |
|
| 339 |
/*! \brief Walk through this channel, and destroy it. |
| 340 |
* \param chptr Channel pointer |
| 341 |
*/ |
| 342 |
void |
| 343 |
channel_free(struct Channel *chptr) |
| 344 |
{ |
| 345 |
clear_invite_list(&chptr->invites); |
| 346 |
|
| 347 |
/* Free ban/exception/invex lists */ |
| 348 |
channel_free_mask_list(&chptr->banlist); |
| 349 |
channel_free_mask_list(&chptr->exceptlist); |
| 350 |
channel_free_mask_list(&chptr->invexlist); |
| 351 |
|
| 352 |
dlinkDelete(&chptr->node, &channel_list); |
| 353 |
hash_del_channel(chptr); |
| 354 |
|
| 355 |
xfree(chptr); |
| 356 |
} |
| 357 |
|
| 358 |
/*! |
| 359 |
* \param chptr Pointer to channel |
| 360 |
* \return String pointer "=" if public, "@" if secret else "*" |
| 361 |
*/ |
| 362 |
static const char * |
| 363 |
channel_pub_or_secret(const struct Channel *chptr) |
| 364 |
{ |
| 365 |
if (SecretChannel(chptr)) |
| 366 |
return "@"; |
| 367 |
if (PrivateChannel(chptr)) |
| 368 |
return "*"; |
| 369 |
return "="; |
| 370 |
} |
| 371 |
|
| 372 |
/*! \brief lists all names on given channel |
| 373 |
* \param client_p Pointer to client struct requesting names |
| 374 |
* \param chptr Pointer to channel block |
| 375 |
* \param show_eon Show RPL_ENDOFNAMES numeric or not |
| 376 |
* (don't want it with /names with no params) |
| 377 |
*/ |
| 378 |
void |
| 379 |
channel_member_names(struct Client *client_p, struct Channel *chptr, |
| 380 |
int show_eon) |
| 381 |
{ |
| 382 |
dlink_node *node; |
| 383 |
char buf[IRCD_BUFSIZE + 1] = ""; |
| 384 |
char *t = NULL, *start = NULL; |
| 385 |
int tlen = 0; |
| 386 |
const int is_member = IsMember(client_p, chptr); |
| 387 |
const int multi_prefix = HasCap(client_p, CAP_MULTI_PREFIX) != 0; |
| 388 |
const int uhnames = HasCap(client_p, CAP_UHNAMES) != 0; |
| 389 |
|
| 390 |
assert(IsClient(client_p)); |
| 391 |
|
| 392 |
if (PubChannel(chptr) || is_member) |
| 393 |
{ |
| 394 |
t = buf + snprintf(buf, sizeof(buf), numeric_form(RPL_NAMREPLY), |
| 395 |
me.name, client_p->name, |
| 396 |
channel_pub_or_secret(chptr), chptr->name); |
| 397 |
start = t; |
| 398 |
|
| 399 |
DLINK_FOREACH(node, chptr->members.head) |
| 400 |
{ |
| 401 |
const struct Membership *member = node->data; |
| 402 |
|
| 403 |
if (HasUMode(member->client_p, UMODE_INVISIBLE) && !is_member) |
| 404 |
continue; |
| 405 |
|
| 406 |
if (!uhnames) |
| 407 |
tlen = strlen(member->client_p->name) + 1; /* +1 for space */ |
| 408 |
else |
| 409 |
tlen = strlen(member->client_p->name) + strlen(member->client_p->username) + |
| 410 |
strlen(member->client_p->host) + 3; /* +3 for ! + @ + space */ |
| 411 |
|
| 412 |
if (!multi_prefix) |
| 413 |
{ |
| 414 |
if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
| 415 |
++tlen; |
| 416 |
} |
| 417 |
else |
| 418 |
{ |
| 419 |
if (member->flags & CHFL_CHANOP) |
| 420 |
++tlen; |
| 421 |
if (member->flags & CHFL_HALFOP) |
| 422 |
++tlen; |
| 423 |
if (member->flags & CHFL_VOICE) |
| 424 |
++tlen; |
| 425 |
} |
| 426 |
|
| 427 |
if (t + tlen - buf > IRCD_BUFSIZE - 2) |
| 428 |
{ |
| 429 |
*(t - 1) = '\0'; |
| 430 |
sendto_one(client_p, "%s", buf); |
| 431 |
t = start; |
| 432 |
} |
| 433 |
|
| 434 |
if (!uhnames) |
| 435 |
t += sprintf(t, "%s%s ", get_member_status(member, multi_prefix), |
| 436 |
member->client_p->name); |
| 437 |
else |
| 438 |
t += sprintf(t, "%s%s!%s@%s ", get_member_status(member, multi_prefix), |
| 439 |
member->client_p->name, member->client_p->username, |
| 440 |
member->client_p->host); |
| 441 |
} |
| 442 |
|
| 443 |
if (tlen) |
| 444 |
{ |
| 445 |
*(t - 1) = '\0'; |
| 446 |
sendto_one(client_p, "%s", buf); |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
if (show_eon) |
| 451 |
sendto_one_numeric(client_p, &me, RPL_ENDOFNAMES, chptr->name); |
| 452 |
} |
| 453 |
|
| 454 |
static struct Invite * |
| 455 |
find_invite(struct Channel *chptr, struct Client *client_p) |
| 456 |
{ |
| 457 |
dlink_node *node, *node_next; |
| 458 |
dlink_list *list; |
| 459 |
|
| 460 |
/* Take the shortest of the two lists */ |
| 461 |
if (dlink_list_length(&client_p->connection->invited) < dlink_list_length(&chptr->invites)) |
| 462 |
list = &client_p->connection->invited; |
| 463 |
else |
| 464 |
list = &chptr->invites; |
| 465 |
|
| 466 |
DLINK_FOREACH_SAFE(node, node_next, list->head) |
| 467 |
{ |
| 468 |
struct Invite *invite = node->data; |
| 469 |
|
| 470 |
if (ConfigChannel.invite_expire_time && |
| 471 |
ConfigChannel.invite_expire_time + invite->when < CurrentTime) |
| 472 |
del_invite(invite); |
| 473 |
else if (invite->chptr == chptr && invite->client_p == client_p) |
| 474 |
return invite; |
| 475 |
} |
| 476 |
|
| 477 |
return NULL; |
| 478 |
} |
| 479 |
|
| 480 |
/*! \brief Adds client to invite list |
| 481 |
* \param chptr Pointer to channel block |
| 482 |
* \param client_p Pointer to client to add invite to |
| 483 |
*/ |
| 484 |
void |
| 485 |
add_invite(struct Channel *chptr, struct Client *client_p) |
| 486 |
{ |
| 487 |
struct Invite *invite = find_invite(chptr, client_p); |
| 488 |
if (invite) |
| 489 |
del_invite(invite); |
| 490 |
|
| 491 |
invite = xcalloc(sizeof(*invite)); |
| 492 |
invite->client_p = client_p; |
| 493 |
invite->chptr = chptr; |
| 494 |
invite->when = CurrentTime; |
| 495 |
|
| 496 |
/* Delete last link in chain if the list is max length */ |
| 497 |
while (dlink_list_length(&client_p->connection->invited) && |
| 498 |
dlink_list_length(&client_p->connection->invited) >= ConfigChannel.max_invites) |
| 499 |
del_invite(client_p->connection->invited.tail->data); |
| 500 |
|
| 501 |
/* Add client to channel invite list */ |
| 502 |
dlinkAdd(invite, &invite->chan_node, &chptr->invites); |
| 503 |
|
| 504 |
/* Add channel to the end of the client invite list */ |
| 505 |
dlinkAdd(invite, &invite->user_node, &client_p->connection->invited); |
| 506 |
} |
| 507 |
|
| 508 |
/*! \brief Delete Invite block from channel invite list |
| 509 |
* and client invite list |
| 510 |
* \param invite Pointer to Invite struct |
| 511 |
*/ |
| 512 |
void |
| 513 |
del_invite(struct Invite *invite) |
| 514 |
{ |
| 515 |
dlinkDelete(&invite->user_node, &invite->client_p->connection->invited); |
| 516 |
dlinkDelete(&invite->chan_node, &invite->chptr->invites); |
| 517 |
|
| 518 |
/* Release memory pointed to by 'invite' */ |
| 519 |
xfree(invite); |
| 520 |
} |
| 521 |
|
| 522 |
/*! \brief Removes and frees all Invite blocks from a list |
| 523 |
* \param list Pointer to a dlink_list |
| 524 |
*/ |
| 525 |
void |
| 526 |
clear_invite_list(dlink_list *list) |
| 527 |
{ |
| 528 |
while (list->head) |
| 529 |
del_invite(list->head->data); |
| 530 |
} |
| 531 |
|
| 532 |
/* get_member_status() |
| 533 |
* |
| 534 |
* inputs - pointer to struct Membership |
| 535 |
* - YES if we can combine different flags |
| 536 |
* output - string either @, +, % or "" depending on whether |
| 537 |
* chanop, voiced or user |
| 538 |
* side effects - |
| 539 |
* |
| 540 |
* NOTE: Returned string is usually a static buffer |
| 541 |
* (like in client_get_name) |
| 542 |
*/ |
| 543 |
const char * |
| 544 |
get_member_status(const struct Membership *member, const int combine) |
| 545 |
{ |
| 546 |
static char buffer[CMEMBER_STATUS_FLAGS_LEN + 1]; /* +1 for \0 */ |
| 547 |
char *p = buffer; |
| 548 |
|
| 549 |
if (member->flags & CHFL_CHANOP) |
| 550 |
{ |
| 551 |
if (!combine) |
| 552 |
return "@"; |
| 553 |
*p++ = '@'; |
| 554 |
} |
| 555 |
|
| 556 |
if (member->flags & CHFL_HALFOP) |
| 557 |
{ |
| 558 |
if (!combine) |
| 559 |
return "%"; |
| 560 |
*p++ = '%'; |
| 561 |
} |
| 562 |
|
| 563 |
if (member->flags & CHFL_VOICE) |
| 564 |
*p++ = '+'; |
| 565 |
*p = '\0'; |
| 566 |
|
| 567 |
return buffer; |
| 568 |
} |
| 569 |
|
| 570 |
/*! |
| 571 |
* \param client_p Pointer to Client to check |
| 572 |
* \param list Pointer to ban list to search |
| 573 |
* \return 1 if ban found for given n!u\@h mask, 0 otherwise |
| 574 |
*/ |
| 575 |
static int |
| 576 |
find_bmask(const struct Client *client_p, const dlink_list *list) |
| 577 |
{ |
| 578 |
dlink_node *node; |
| 579 |
|
| 580 |
DLINK_FOREACH(node, list->head) |
| 581 |
{ |
| 582 |
const struct Ban *ban = node->data; |
| 583 |
|
| 584 |
if (!match(ban->name, client_p->name) && !match(ban->user, client_p->username)) |
| 585 |
{ |
| 586 |
switch (ban->type) |
| 587 |
{ |
| 588 |
case HM_HOST: |
| 589 |
if (!match(ban->host, client_p->host) || !match(ban->host, client_p->sockhost)) |
| 590 |
return 1; |
| 591 |
break; |
| 592 |
case HM_IPV4: |
| 593 |
if (client_p->connection->aftype == AF_INET) |
| 594 |
if (match_ipv4(&client_p->connection->ip, &ban->addr, ban->bits)) |
| 595 |
return 1; |
| 596 |
break; |
| 597 |
case HM_IPV6: |
| 598 |
if (client_p->connection->aftype == AF_INET6) |
| 599 |
if (match_ipv6(&client_p->connection->ip, &ban->addr, ban->bits)) |
| 600 |
return 1; |
| 601 |
break; |
| 602 |
default: |
| 603 |
assert(0); |
| 604 |
} |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
return 0; |
| 609 |
} |
| 610 |
|
| 611 |
/*! |
| 612 |
* \param chptr Pointer to channel block |
| 613 |
* \param client_p Pointer to client to check access fo |
| 614 |
* \return 0 if not banned, 1 otherwise |
| 615 |
*/ |
| 616 |
int |
| 617 |
is_banned(const struct Channel *chptr, const struct Client *client_p) |
| 618 |
{ |
| 619 |
if (find_bmask(client_p, &chptr->banlist)) |
| 620 |
if (!find_bmask(client_p, &chptr->exceptlist)) |
| 621 |
return 1; |
| 622 |
|
| 623 |
return 0; |
| 624 |
} |
| 625 |
|
| 626 |
/*! Tests if a client can join a certain channel |
| 627 |
* \param client_p Pointer to client attempting to join |
| 628 |
* \param chptr Pointer to channel |
| 629 |
* \param key Key sent by client attempting to join if present |
| 630 |
* \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL |
| 631 |
* or 0 if allowed to join. |
| 632 |
*/ |
| 633 |
static int |
| 634 |
can_join(struct Client *client_p, struct Channel *chptr, const char *key) |
| 635 |
{ |
| 636 |
if (HasCMode(chptr, MODE_SSLONLY) && !HasUMode(client_p, UMODE_SSL)) |
| 637 |
return ERR_SSLONLYCHAN; |
| 638 |
|
| 639 |
if (HasCMode(chptr, MODE_REGONLY) && !HasUMode(client_p, UMODE_REGISTERED)) |
| 640 |
return ERR_NEEDREGGEDNICK; |
| 641 |
|
| 642 |
if (HasCMode(chptr, MODE_OPERONLY) && !HasUMode(client_p, UMODE_OPER)) |
| 643 |
return ERR_OPERONLYCHAN; |
| 644 |
|
| 645 |
if (HasCMode(chptr, MODE_INVITEONLY)) |
| 646 |
if (!find_invite(chptr, client_p)) |
| 647 |
if (!find_bmask(client_p, &chptr->invexlist)) |
| 648 |
return ERR_INVITEONLYCHAN; |
| 649 |
|
| 650 |
if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key))) |
| 651 |
return ERR_BADCHANNELKEY; |
| 652 |
|
| 653 |
if (chptr->mode.limit && dlink_list_length(&chptr->members) >= |
| 654 |
chptr->mode.limit) |
| 655 |
return ERR_CHANNELISFULL; |
| 656 |
|
| 657 |
if (is_banned(chptr, client_p)) |
| 658 |
return ERR_BANNEDFROMCHAN; |
| 659 |
|
| 660 |
return 0; |
| 661 |
} |
| 662 |
|
| 663 |
int |
| 664 |
has_member_flags(const struct Membership *member, const unsigned int flags) |
| 665 |
{ |
| 666 |
return member && (member->flags & flags); |
| 667 |
} |
| 668 |
|
| 669 |
struct Membership * |
| 670 |
find_channel_link(struct Client *client_p, struct Channel *chptr) |
| 671 |
{ |
| 672 |
dlink_node *node; |
| 673 |
|
| 674 |
if (!IsClient(client_p)) |
| 675 |
return NULL; |
| 676 |
|
| 677 |
if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel)) |
| 678 |
{ |
| 679 |
DLINK_FOREACH(node, chptr->members.head) |
| 680 |
if (((struct Membership *)node->data)->client_p == client_p) |
| 681 |
return node->data; |
| 682 |
} |
| 683 |
else |
| 684 |
{ |
| 685 |
DLINK_FOREACH(node, client_p->channel.head) |
| 686 |
if (((struct Membership *)node->data)->chptr == chptr) |
| 687 |
return node->data; |
| 688 |
} |
| 689 |
|
| 690 |
return NULL; |
| 691 |
} |
| 692 |
|
| 693 |
/*! Checks if a message contains control codes |
| 694 |
* \param message The actual message string the client wants to send |
| 695 |
* \return 1 if the message does contain any control codes, 0 otherwise |
| 696 |
*/ |
| 697 |
static int |
| 698 |
msg_has_ctrls(const char *message) |
| 699 |
{ |
| 700 |
const unsigned char *p = (const unsigned char *)message; |
| 701 |
|
| 702 |
for (; *p; ++p) |
| 703 |
{ |
| 704 |
if (*p > 31 || *p == 1) |
| 705 |
continue; /* No control code or CTCP */ |
| 706 |
|
| 707 |
if (*p == 27) /* Escape */ |
| 708 |
{ |
| 709 |
/* ISO 2022 charset shift sequence */ |
| 710 |
if (*(p + 1) == '$' || |
| 711 |
*(p + 1) == '(') |
| 712 |
{ |
| 713 |
++p; |
| 714 |
continue; |
| 715 |
} |
| 716 |
} |
| 717 |
|
| 718 |
return 1; /* Control code */ |
| 719 |
} |
| 720 |
|
| 721 |
return 0; /* No control code found */ |
| 722 |
} |
| 723 |
|
| 724 |
/*! Tests if a client can send to a channel |
| 725 |
* \param chptr Pointer to Channel struct |
| 726 |
* \param client_p Pointer to Client struct |
| 727 |
* \param member Pointer to Membership struct (can be NULL) |
| 728 |
* \param message The actual message string the client wants to send |
| 729 |
* \return CAN_SEND_OPV if op or voiced on channel\n |
| 730 |
* CAN_SEND_NONOP if can send to channel but is not an op\n |
| 731 |
* ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n |
| 732 |
*/ |
| 733 |
int |
| 734 |
can_send(struct Channel *chptr, struct Client *client_p, |
| 735 |
struct Membership *member, const char *message, int notice) |
| 736 |
{ |
| 737 |
const struct ResvItem *resv = NULL; |
| 738 |
|
| 739 |
if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE)) |
| 740 |
return CAN_SEND_OPV; |
| 741 |
|
| 742 |
if (MyConnect(client_p) && !HasFlag(client_p, FLAGS_EXEMPTRESV)) |
| 743 |
if (!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV))) |
| 744 |
if ((resv = resv_find(chptr->name, match)) && !resv_exempt_find(client_p, resv)) |
| 745 |
return ERR_CANNOTSENDTOCHAN; |
| 746 |
|
| 747 |
if (HasCMode(chptr, MODE_NOCTRL) && msg_has_ctrls(message)) |
| 748 |
return ERR_NOCTRLSONCHAN; |
| 749 |
|
| 750 |
if (HasCMode(chptr, MODE_NOCTCP)) |
| 751 |
if (*message == '\001' && strncmp(message + 1, "ACTION ", 7)) |
| 752 |
return ERR_NOCTCP; |
| 753 |
|
| 754 |
if (member || (member = find_channel_link(client_p, chptr))) |
| 755 |
if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
| 756 |
return CAN_SEND_OPV; |
| 757 |
|
| 758 |
if (!member && HasCMode(chptr, MODE_NOPRIVMSGS)) |
| 759 |
return ERR_CANNOTSENDTOCHAN; |
| 760 |
|
| 761 |
if (HasCMode(chptr, MODE_MODERATED)) |
| 762 |
return ERR_CANNOTSENDTOCHAN; |
| 763 |
|
| 764 |
if (HasCMode(chptr, MODE_MODREG) && !HasUMode(client_p, UMODE_REGISTERED)) |
| 765 |
return ERR_NEEDREGGEDNICK; |
| 766 |
|
| 767 |
if (HasCMode(chptr, MODE_NONOTICE) && notice) |
| 768 |
return ERR_CANNOTSENDTOCHAN; |
| 769 |
|
| 770 |
/* Cache can send if banned */ |
| 771 |
if (MyConnect(client_p)) |
| 772 |
{ |
| 773 |
if (member) |
| 774 |
{ |
| 775 |
if (member->flags & CHFL_BAN_SILENCED) |
| 776 |
return ERR_CANNOTSENDTOCHAN; |
| 777 |
|
| 778 |
if (!(member->flags & CHFL_BAN_CHECKED)) |
| 779 |
{ |
| 780 |
if (is_banned(chptr, client_p)) |
| 781 |
{ |
| 782 |
member->flags |= (CHFL_BAN_CHECKED | CHFL_BAN_SILENCED); |
| 783 |
return ERR_CANNOTSENDTOCHAN; |
| 784 |
} |
| 785 |
|
| 786 |
member->flags |= CHFL_BAN_CHECKED; |
| 787 |
} |
| 788 |
} |
| 789 |
else if (is_banned(chptr, client_p)) |
| 790 |
return ERR_CANNOTSENDTOCHAN; |
| 791 |
} |
| 792 |
|
| 793 |
return CAN_SEND_NONOP; |
| 794 |
} |
| 795 |
|
| 796 |
/*! \brief Updates the client's oper_warn_count_down, warns the |
| 797 |
* IRC operators if necessary, and updates |
| 798 |
* join_leave_countdown as needed. |
| 799 |
* \param client_p Pointer to struct Client to check |
| 800 |
* \param name Channel name or NULL if this is a part. |
| 801 |
*/ |
| 802 |
void |
| 803 |
check_spambot_warning(struct Client *client_p, const char *name) |
| 804 |
{ |
| 805 |
if (GlobalSetOptions.spam_num && |
| 806 |
(client_p->connection->join_leave_count >= GlobalSetOptions.spam_num)) |
| 807 |
{ |
| 808 |
if (client_p->connection->oper_warn_count_down > 0) |
| 809 |
client_p->connection->oper_warn_count_down--; |
| 810 |
else |
| 811 |
client_p->connection->oper_warn_count_down = 0; |
| 812 |
|
| 813 |
if (client_p->connection->oper_warn_count_down == 0) |
| 814 |
{ |
| 815 |
/* It's already known as a possible spambot */ |
| 816 |
if (name) |
| 817 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
| 818 |
"User %s (%s@%s) trying to join %s is a possible spambot", |
| 819 |
client_p->name, client_p->username, |
| 820 |
client_p->host, name); |
| 821 |
else |
| 822 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
| 823 |
"User %s (%s@%s) is a possible spambot", |
| 824 |
client_p->name, client_p->username, |
| 825 |
client_p->host); |
| 826 |
client_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN; |
| 827 |
} |
| 828 |
} |
| 829 |
else |
| 830 |
{ |
| 831 |
int t_delta = CurrentTime - client_p->connection->last_leave_time; |
| 832 |
if (t_delta > JOIN_LEAVE_COUNT_EXPIRE_TIME) |
| 833 |
{ |
| 834 |
int decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); |
| 835 |
if (decrement_count > client_p->connection->join_leave_count) |
| 836 |
client_p->connection->join_leave_count = 0; |
| 837 |
else |
| 838 |
client_p->connection->join_leave_count -= decrement_count; |
| 839 |
} |
| 840 |
else |
| 841 |
{ |
| 842 |
if ((CurrentTime - (client_p->connection->last_join_time)) < |
| 843 |
GlobalSetOptions.spam_time) |
| 844 |
client_p->connection->join_leave_count++; /* It's a possible spambot */ |
| 845 |
} |
| 846 |
|
| 847 |
if (name) |
| 848 |
client_p->connection->last_join_time = CurrentTime; |
| 849 |
else |
| 850 |
client_p->connection->last_leave_time = CurrentTime; |
| 851 |
} |
| 852 |
} |
| 853 |
|
| 854 |
/*! \brief Sets the channel topic for a certain channel |
| 855 |
* \param chptr Pointer to struct Channel |
| 856 |
* \param topic The topic string |
| 857 |
* \param topic_info n!u\@h formatted string of the topic setter |
| 858 |
* \param topicts Timestamp on the topic |
| 859 |
* \param local Whether the topic is set by a local client |
| 860 |
*/ |
| 861 |
void |
| 862 |
channel_set_topic(struct Channel *chptr, const char *topic, |
| 863 |
const char *topic_info, uintmax_t topicts, int local) |
| 864 |
{ |
| 865 |
if (local) |
| 866 |
strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ConfigServerInfo.max_topic_length + 1)); |
| 867 |
else |
| 868 |
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
| 869 |
|
| 870 |
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
| 871 |
chptr->topic_time = topicts; |
| 872 |
} |
| 873 |
|
| 874 |
void |
| 875 |
channel_do_join(struct Client *client_p, char *chan_list, char *key_list) |
| 876 |
{ |
| 877 |
char *p = NULL; |
| 878 |
const struct ResvItem *resv = NULL; |
| 879 |
const struct ClassItem *const class = get_class_ptr(&client_p->connection->confs); |
| 880 |
unsigned int flags = 0; |
| 881 |
|
| 882 |
assert(IsClient(client_p)); |
| 883 |
|
| 884 |
for (const char *name = strtok_r(chan_list, ",", &p); name; |
| 885 |
name = strtok_r(NULL, ",", &p)) |
| 886 |
{ |
| 887 |
const char *key = NULL; |
| 888 |
|
| 889 |
/* If we have any more keys, take the first for this channel. */ |
| 890 |
if (!EmptyString(key_list) && (key_list = strchr(key = key_list, ','))) |
| 891 |
*key_list++ = '\0'; |
| 892 |
|
| 893 |
/* Empty keys are the same as no keys. */ |
| 894 |
if (key && *key == '\0') |
| 895 |
key = NULL; |
| 896 |
|
| 897 |
if (!channel_check_name(name, 1)) |
| 898 |
{ |
| 899 |
sendto_one_numeric(client_p, &me, ERR_BADCHANNAME, name); |
| 900 |
continue; |
| 901 |
} |
| 902 |
|
| 903 |
if (!HasFlag(client_p, FLAGS_EXEMPTRESV) && |
| 904 |
!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)) && |
| 905 |
((resv = resv_find(name, match)) && !resv_exempt_find(client_p, resv))) |
| 906 |
{ |
| 907 |
sendto_one_numeric(client_p, &me, ERR_CHANBANREASON, name, resv->reason); |
| 908 |
sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, |
| 909 |
"Forbidding reserved channel %s from user %s", |
| 910 |
name, client_get_name(client_p, HIDE_IP)); |
| 911 |
continue; |
| 912 |
} |
| 913 |
|
| 914 |
if (dlink_list_length(&client_p->channel) >= |
| 915 |
((class->max_channels) ? class->max_channels : ConfigChannel.max_channels)) |
| 916 |
{ |
| 917 |
sendto_one_numeric(client_p, &me, ERR_TOOMANYCHANNELS, name); |
| 918 |
break; |
| 919 |
} |
| 920 |
|
| 921 |
struct Channel *chptr = hash_find_channel(name); |
| 922 |
if (chptr) |
| 923 |
{ |
| 924 |
if (IsMember(client_p, chptr)) |
| 925 |
continue; |
| 926 |
|
| 927 |
/* can_join() checks for +i, +l, key, bans, etc. */ |
| 928 |
int ret = can_join(client_p, chptr, key); |
| 929 |
if (ret) |
| 930 |
{ |
| 931 |
sendto_one_numeric(client_p, &me, ret, chptr->name); |
| 932 |
continue; |
| 933 |
} |
| 934 |
|
| 935 |
/* |
| 936 |
* This should never be the case unless there is some sort of |
| 937 |
* persistant channels. |
| 938 |
*/ |
| 939 |
if (!dlink_list_length(&chptr->members)) |
| 940 |
flags = CHFL_CHANOP; |
| 941 |
else |
| 942 |
flags = 0; |
| 943 |
} |
| 944 |
else |
| 945 |
{ |
| 946 |
flags = CHFL_CHANOP; |
| 947 |
chptr = channel_make(name); |
| 948 |
} |
| 949 |
|
| 950 |
if (!HasUMode(client_p, UMODE_OPER)) |
| 951 |
check_spambot_warning(client_p, chptr->name); |
| 952 |
|
| 953 |
add_user_to_channel(chptr, client_p, flags, 1); |
| 954 |
|
| 955 |
/* |
| 956 |
* Set timestamp if appropriate, and propagate |
| 957 |
*/ |
| 958 |
if (flags == CHFL_CHANOP) |
| 959 |
{ |
| 960 |
chptr->creationtime = CurrentTime; |
| 961 |
AddCMode(chptr, MODE_TOPICLIMIT); |
| 962 |
AddCMode(chptr, MODE_NOPRIVMSGS); |
| 963 |
|
| 964 |
sendto_server(client_p, 0, 0, ":%s SJOIN %ju %s +nt :@%s", |
| 965 |
me.id, chptr->creationtime, |
| 966 |
chptr->name, client_p->id); |
| 967 |
|
| 968 |
/* |
| 969 |
* Notify all other users on the new channel |
| 970 |
*/ |
| 971 |
sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s", |
| 972 |
client_p->name, client_p->username, |
| 973 |
client_p->host, chptr->name, client_p->account, client_p->info); |
| 974 |
sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s", |
| 975 |
client_p->name, client_p->username, |
| 976 |
client_p->host, chptr->name); |
| 977 |
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s MODE %s +nt", |
| 978 |
me.name, chptr->name); |
| 979 |
|
| 980 |
if (client_p->away[0]) |
| 981 |
sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0, |
| 982 |
":%s!%s@%s AWAY :%s", |
| 983 |
client_p->name, client_p->username, |
| 984 |
client_p->host, client_p->away); |
| 985 |
} |
| 986 |
else |
| 987 |
{ |
| 988 |
sendto_server(client_p, 0, 0, ":%s JOIN %ju %s +", |
| 989 |
client_p->id, chptr->creationtime, |
| 990 |
chptr->name); |
| 991 |
|
| 992 |
sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s", |
| 993 |
client_p->name, client_p->username, |
| 994 |
client_p->host, chptr->name, client_p->account, client_p->info); |
| 995 |
sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s", |
| 996 |
client_p->name, client_p->username, |
| 997 |
client_p->host, chptr->name); |
| 998 |
|
| 999 |
if (client_p->away[0]) |
| 1000 |
sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0, |
| 1001 |
":%s!%s@%s AWAY :%s", |
| 1002 |
client_p->name, client_p->username, |
| 1003 |
client_p->host, client_p->away); |
| 1004 |
} |
| 1005 |
|
| 1006 |
struct Invite *invite = find_invite(chptr, client_p); |
| 1007 |
if (invite) |
| 1008 |
del_invite(invite); |
| 1009 |
|
| 1010 |
if (chptr->topic[0]) |
| 1011 |
{ |
| 1012 |
sendto_one_numeric(client_p, &me, RPL_TOPIC, chptr->name, chptr->topic); |
| 1013 |
sendto_one_numeric(client_p, &me, RPL_TOPICWHOTIME, chptr->name, |
| 1014 |
chptr->topic_info, chptr->topic_time); |
| 1015 |
} |
| 1016 |
|
| 1017 |
channel_member_names(client_p, chptr, 1); |
| 1018 |
|
| 1019 |
client_p->connection->last_join_time = CurrentTime; |
| 1020 |
} |
| 1021 |
} |
| 1022 |
|
| 1023 |
/*! \brief Removes a client from a specific channel |
| 1024 |
* \param client_p Pointer to client to remove |
| 1025 |
* \param name Name of channel to remove from |
| 1026 |
* \param reason Part reason to show |
| 1027 |
*/ |
| 1028 |
static void |
| 1029 |
channel_part_one_client(struct Client *client_p, const char *name, const char *reason) |
| 1030 |
{ |
| 1031 |
struct Channel *chptr = NULL; |
| 1032 |
struct Membership *member = NULL; |
| 1033 |
|
| 1034 |
if ((chptr = hash_find_channel(name)) == NULL) |
| 1035 |
{ |
| 1036 |
sendto_one_numeric(client_p, &me, ERR_NOSUCHCHANNEL, name); |
| 1037 |
return; |
| 1038 |
} |
| 1039 |
|
| 1040 |
if ((member = find_channel_link(client_p, chptr)) == NULL) |
| 1041 |
{ |
| 1042 |
sendto_one_numeric(client_p, &me, ERR_NOTONCHANNEL, chptr->name); |
| 1043 |
return; |
| 1044 |
} |
| 1045 |
|
| 1046 |
if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER)) |
| 1047 |
check_spambot_warning(client_p, NULL); |
| 1048 |
|
| 1049 |
/* |
| 1050 |
* Remove user from the old channel (if any) |
| 1051 |
* only allow /part reasons in -m chans |
| 1052 |
*/ |
| 1053 |
if (*reason && (!MyConnect(client_p) || |
| 1054 |
((client_p->connection->firsttime + |
| 1055 |
ConfigGeneral.anti_spam_exit_message_time) < CurrentTime && |
| 1056 |
can_send(chptr, client_p, member, reason, 0) < 0))) |
| 1057 |
{ |
| 1058 |
sendto_server(client_p, 0, 0, ":%s PART %s :%s", |
| 1059 |
client_p->id, chptr->name, reason); |
| 1060 |
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s :%s", |
| 1061 |
client_p->name, client_p->username, |
| 1062 |
client_p->host, chptr->name, reason); |
| 1063 |
} |
| 1064 |
else |
| 1065 |
{ |
| 1066 |
sendto_server(client_p, 0, 0, ":%s PART %s", |
| 1067 |
client_p->id, chptr->name); |
| 1068 |
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s", |
| 1069 |
client_p->name, client_p->username, |
| 1070 |
client_p->host, chptr->name); |
| 1071 |
} |
| 1072 |
|
| 1073 |
remove_user_from_channel(member); |
| 1074 |
} |
| 1075 |
|
| 1076 |
void |
| 1077 |
channel_do_part(struct Client *client_p, char *channel, const char *reason) |
| 1078 |
{ |
| 1079 |
char *p = NULL; |
| 1080 |
char buf[KICKLEN + 1] = ""; |
| 1081 |
|
| 1082 |
assert(IsClient(client_p)); |
| 1083 |
|
| 1084 |
if (!EmptyString(reason)) |
| 1085 |
strlcpy(buf, reason, sizeof(buf)); |
| 1086 |
|
| 1087 |
for (const char *name = strtok_r(channel, ",", &p); name; |
| 1088 |
name = strtok_r(NULL, ",", &p)) |
| 1089 |
channel_part_one_client(client_p, name, buf); |
| 1090 |
} |