| 1 |
adx |
30 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
|
|
* |
| 4 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 19 |
|
|
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
|
|
/*! \file channel.c |
| 23 |
|
|
* \brief Responsible for managing channels, members, bans and topics |
| 24 |
knight |
31 |
* \version $Id$ |
| 25 |
adx |
30 |
*/ |
| 26 |
|
|
|
| 27 |
|
|
#include "stdinc.h" |
| 28 |
|
|
#include "tools.h" |
| 29 |
|
|
#include "channel.h" |
| 30 |
|
|
#include "channel_mode.h" |
| 31 |
|
|
#include "client.h" |
| 32 |
|
|
#include "common.h" |
| 33 |
|
|
#include "hash.h" |
| 34 |
michael |
371 |
#include "hostmask.h" |
| 35 |
adx |
30 |
#include "irc_string.h" |
| 36 |
|
|
#include "sprintf_irc.h" |
| 37 |
|
|
#include "ircd.h" |
| 38 |
|
|
#include "list.h" |
| 39 |
|
|
#include "numeric.h" |
| 40 |
|
|
#include "s_serv.h" /* captab */ |
| 41 |
|
|
#include "s_user.h" |
| 42 |
|
|
#include "send.h" |
| 43 |
|
|
#include "s_conf.h" /* ConfigFileEntry, ConfigChannel */ |
| 44 |
|
|
#include "event.h" |
| 45 |
|
|
#include "memory.h" |
| 46 |
|
|
#include "balloc.h" |
| 47 |
|
|
|
| 48 |
|
|
struct config_channel_entry ConfigChannel; |
| 49 |
|
|
dlink_list global_channel_list = { NULL, NULL, 0 }; |
| 50 |
|
|
dlink_list lazylink_channels = { NULL, NULL, 0 }; |
| 51 |
|
|
BlockHeap *ban_heap; /*! \todo ban_heap shouldn't be a global var */ |
| 52 |
|
|
|
| 53 |
|
|
static BlockHeap *topic_heap = NULL; |
| 54 |
|
|
static BlockHeap *member_heap = NULL; |
| 55 |
|
|
static BlockHeap *channel_heap = NULL; |
| 56 |
|
|
|
| 57 |
|
|
static char buf[IRCD_BUFSIZE]; |
| 58 |
|
|
static char modebuf[MODEBUFLEN]; |
| 59 |
|
|
static char parabuf[MODEBUFLEN]; |
| 60 |
|
|
|
| 61 |
|
|
|
| 62 |
|
|
/*! \brief Initializes the channel blockheap, adds known channel CAPAB |
| 63 |
|
|
*/ |
| 64 |
|
|
void |
| 65 |
|
|
init_channels(void) |
| 66 |
|
|
{ |
| 67 |
|
|
/* |
| 68 |
|
|
* XXX - These should get moved to somwhere else once we have |
| 69 |
|
|
* a modular channelmode system |
| 70 |
|
|
*/ |
| 71 |
|
|
add_capability("EX", CAP_EX, 1); |
| 72 |
|
|
add_capability("IE", CAP_IE, 1); |
| 73 |
|
|
add_capability("CHW", CAP_CHW, 1); |
| 74 |
|
|
|
| 75 |
|
|
channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE); |
| 76 |
|
|
ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE); |
| 77 |
|
|
topic_heap = BlockHeapCreate("topic", TOPICLEN+1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE); |
| 78 |
|
|
member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2); |
| 79 |
|
|
} |
| 80 |
|
|
|
| 81 |
|
|
/*! \brief adds a user to a channel by adding another link to the |
| 82 |
|
|
* channels member chain. |
| 83 |
|
|
* \param chptr pointer to channel to add client to |
| 84 |
|
|
* \param who pointer to client (who) to add |
| 85 |
|
|
* \param flags flags for chanops etc |
| 86 |
|
|
* \param flood_ctrl whether to count this join in flood calculations |
| 87 |
|
|
*/ |
| 88 |
|
|
void |
| 89 |
|
|
add_user_to_channel(struct Channel *chptr, struct Client *who, |
| 90 |
|
|
unsigned int flags, int flood_ctrl) |
| 91 |
|
|
{ |
| 92 |
|
|
struct Membership *ms = NULL; |
| 93 |
|
|
|
| 94 |
|
|
if (GlobalSetOptions.joinfloodtime > 0) |
| 95 |
|
|
{ |
| 96 |
|
|
if (flood_ctrl) |
| 97 |
|
|
chptr->number_joined++; |
| 98 |
|
|
|
| 99 |
|
|
chptr->number_joined -= (CurrentTime - chptr->last_join_time) * |
| 100 |
|
|
(((float)GlobalSetOptions.joinfloodcount) / |
| 101 |
|
|
(float)GlobalSetOptions.joinfloodtime); |
| 102 |
|
|
|
| 103 |
|
|
if (chptr->number_joined <= 0) |
| 104 |
|
|
{ |
| 105 |
|
|
chptr->number_joined = 0; |
| 106 |
|
|
ClearJoinFloodNoticed(chptr); |
| 107 |
|
|
} |
| 108 |
|
|
else if (chptr->number_joined >= GlobalSetOptions.joinfloodcount) |
| 109 |
|
|
{ |
| 110 |
|
|
chptr->number_joined = GlobalSetOptions.joinfloodcount; |
| 111 |
|
|
|
| 112 |
|
|
if (!IsSetJoinFloodNoticed(chptr)) |
| 113 |
|
|
{ |
| 114 |
|
|
SetJoinFloodNoticed(chptr); |
| 115 |
|
|
sendto_realops_flags(UMODE_BOTS, L_ALL, |
| 116 |
|
|
"Possible Join Flooder %s on %s target: %s", |
| 117 |
|
|
get_client_name(who, HIDE_IP), |
| 118 |
|
|
who->servptr->name, chptr->chname); |
| 119 |
|
|
} |
| 120 |
|
|
} |
| 121 |
|
|
|
| 122 |
|
|
chptr->last_join_time = CurrentTime; |
| 123 |
|
|
} |
| 124 |
|
|
|
| 125 |
|
|
ms = BlockHeapAlloc(member_heap); |
| 126 |
|
|
ms->client_p = who; |
| 127 |
|
|
ms->chptr = chptr; |
| 128 |
|
|
ms->flags = flags; |
| 129 |
|
|
|
| 130 |
|
|
dlinkAdd(ms, &ms->channode, &chptr->members); |
| 131 |
|
|
|
| 132 |
|
|
if (MyConnect(who)) |
| 133 |
|
|
dlinkAdd(ms, &ms->locchannode, &chptr->locmembers); |
| 134 |
|
|
|
| 135 |
|
|
dlinkAdd(ms, &ms->usernode, &who->channel); |
| 136 |
|
|
} |
| 137 |
|
|
|
| 138 |
|
|
/*! \brief deletes an user from a channel by removing a link in the |
| 139 |
|
|
* channels member chain. |
| 140 |
|
|
* \param member pointer to Membership struct |
| 141 |
|
|
*/ |
| 142 |
|
|
void |
| 143 |
|
|
remove_user_from_channel(struct Membership *member) |
| 144 |
|
|
{ |
| 145 |
|
|
struct Client *client_p = member->client_p; |
| 146 |
|
|
struct Channel *chptr = member->chptr; |
| 147 |
|
|
|
| 148 |
|
|
dlinkDelete(&member->channode, &chptr->members); |
| 149 |
|
|
|
| 150 |
|
|
if (MyConnect(client_p)) |
| 151 |
|
|
dlinkDelete(&member->locchannode, &chptr->locmembers); |
| 152 |
|
|
|
| 153 |
|
|
dlinkDelete(&member->usernode, &client_p->channel); |
| 154 |
|
|
|
| 155 |
|
|
BlockHeapFree(member_heap, member); |
| 156 |
|
|
|
| 157 |
|
|
if (dlink_list_length(&chptr->members) == 0) |
| 158 |
|
|
{ |
| 159 |
|
|
assert(dlink_list_length(&chptr->locmembers) == 0); |
| 160 |
|
|
destroy_channel(chptr); |
| 161 |
|
|
} |
| 162 |
|
|
} |
| 163 |
|
|
|
| 164 |
|
|
/* send_members() |
| 165 |
|
|
* |
| 166 |
|
|
* inputs - |
| 167 |
|
|
* output - NONE |
| 168 |
|
|
* side effects - |
| 169 |
|
|
*/ |
| 170 |
|
|
static void |
| 171 |
|
|
send_members(struct Client *client_p, struct Channel *chptr, |
| 172 |
|
|
char *lmodebuf, char *lparabuf) |
| 173 |
|
|
{ |
| 174 |
|
|
struct Membership *ms; |
| 175 |
|
|
dlink_node *ptr; |
| 176 |
|
|
int tlen; /* length of text to append */ |
| 177 |
|
|
char *t, *start; /* temp char pointer */ |
| 178 |
|
|
|
| 179 |
|
|
start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:", |
| 180 |
|
|
ID_or_name(&me, client_p), |
| 181 |
|
|
(unsigned long)chptr->channelts, |
| 182 |
|
|
chptr->chname, lmodebuf, lparabuf); |
| 183 |
|
|
|
| 184 |
|
|
DLINK_FOREACH(ptr, chptr->members.head) |
| 185 |
|
|
{ |
| 186 |
|
|
ms = ptr->data; |
| 187 |
|
|
|
| 188 |
|
|
tlen = strlen(IsCapable(client_p, CAP_TS6) ? |
| 189 |
|
|
ID(ms->client_p) : ms->client_p->name) + 1; /* nick + space */ |
| 190 |
|
|
|
| 191 |
|
|
if (ms->flags & CHFL_CHANOP) |
| 192 |
|
|
tlen++; |
| 193 |
|
|
#ifdef HALFOPS |
| 194 |
adx |
356 |
else if (ms->flags & CHFL_HALFOP) |
| 195 |
adx |
30 |
tlen++; |
| 196 |
|
|
#endif |
| 197 |
|
|
if (ms->flags & CHFL_VOICE) |
| 198 |
|
|
tlen++; |
| 199 |
|
|
|
| 200 |
|
|
/* space will be converted into CR, but we also need space for LF.. |
| 201 |
|
|
* That's why we use '- 1' here |
| 202 |
|
|
* -adx */ |
| 203 |
|
|
if (t + tlen - buf > sizeof(buf) - 1) |
| 204 |
|
|
{ |
| 205 |
|
|
*(t - 1) = '\0'; /* kill the space and terminate the string */ |
| 206 |
|
|
sendto_one(client_p, "%s", buf); |
| 207 |
|
|
t = start; |
| 208 |
|
|
} |
| 209 |
|
|
|
| 210 |
adx |
356 |
if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP))) |
| 211 |
|
|
*t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ? |
| 212 |
|
|
'%' : '@'; |
| 213 |
|
|
if ((ms->flags & CHFL_VOICE)) |
| 214 |
|
|
*t++ = '+'; |
| 215 |
adx |
30 |
|
| 216 |
|
|
if (IsCapable(client_p, CAP_TS6)) |
| 217 |
|
|
strcpy(t, ID(ms->client_p)); |
| 218 |
|
|
else |
| 219 |
|
|
strcpy(t, ms->client_p->name); |
| 220 |
|
|
t += strlen(t); |
| 221 |
|
|
*t++ = ' '; |
| 222 |
|
|
} |
| 223 |
|
|
|
| 224 |
|
|
/* should always be non-NULL unless we have a kind of persistent channels */ |
| 225 |
|
|
if (chptr->members.head != NULL) |
| 226 |
|
|
t--; /* take the space out */ |
| 227 |
|
|
*t = '\0'; |
| 228 |
|
|
sendto_one(client_p, "%s", buf); |
| 229 |
|
|
} |
| 230 |
|
|
|
| 231 |
|
|
/*! \brief sends +b/+e/+I |
| 232 |
|
|
* \param client_p client pointer to server |
| 233 |
|
|
* \param chptr pointer to channel |
| 234 |
|
|
* \param top pointer to top of mode link list to send |
| 235 |
|
|
* \param flag char flag flagging type of mode. Currently this can be 'b', e' or 'I' |
| 236 |
|
|
*/ |
| 237 |
|
|
static void |
| 238 |
|
|
send_mode_list(struct Client *client_p, struct Channel *chptr, |
| 239 |
|
|
dlink_list *top, char flag) |
| 240 |
|
|
{ |
| 241 |
|
|
int ts5 = !IsCapable(client_p, CAP_TS6); |
| 242 |
|
|
dlink_node *lp; |
| 243 |
|
|
struct Ban *banptr; |
| 244 |
|
|
char pbuf[IRCD_BUFSIZE]; |
| 245 |
|
|
int tlen, mlen, cur_len, count = 0; |
| 246 |
|
|
char *mp = NULL, *pp = pbuf; |
| 247 |
|
|
|
| 248 |
|
|
if (top == NULL || top->length == 0) |
| 249 |
|
|
return; |
| 250 |
|
|
|
| 251 |
|
|
if (ts5) |
| 252 |
|
|
mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname); |
| 253 |
|
|
else |
| 254 |
|
|
mlen = ircsprintf(buf, ":%s BMASK %lu %s %c :", me.id, |
| 255 |
|
|
(unsigned long)chptr->channelts, chptr->chname, flag); |
| 256 |
|
|
|
| 257 |
|
|
/* MODE needs additional one byte for space between buf and pbuf */ |
| 258 |
|
|
cur_len = mlen + ts5; |
| 259 |
|
|
mp = buf + mlen; |
| 260 |
|
|
|
| 261 |
|
|
DLINK_FOREACH(lp, top->head) |
| 262 |
|
|
{ |
| 263 |
|
|
banptr = lp->data; |
| 264 |
|
|
|
| 265 |
|
|
/* must add another b/e/I letter if we use MODE */ |
| 266 |
|
|
tlen = banptr->len + 3 + ts5; |
| 267 |
|
|
|
| 268 |
|
|
/* |
| 269 |
|
|
* send buffer and start over if we cannot fit another ban, |
| 270 |
|
|
* or if the target is non-ts6 and we have too many modes in |
| 271 |
|
|
* in this line. |
| 272 |
|
|
*/ |
| 273 |
|
|
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 || |
| 274 |
|
|
(!IsCapable(client_p, CAP_TS6) && |
| 275 |
|
|
(count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN))) |
| 276 |
|
|
{ |
| 277 |
|
|
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
| 278 |
|
|
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
| 279 |
|
|
|
| 280 |
|
|
cur_len = mlen + ts5; |
| 281 |
|
|
mp = buf + mlen; |
| 282 |
|
|
pp = pbuf; |
| 283 |
|
|
count = 0; |
| 284 |
|
|
} |
| 285 |
|
|
|
| 286 |
|
|
count++; |
| 287 |
|
|
if (ts5) |
| 288 |
|
|
{ |
| 289 |
|
|
*mp++ = flag; |
| 290 |
|
|
*mp = '\0'; |
| 291 |
|
|
} |
| 292 |
|
|
|
| 293 |
|
|
pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username, |
| 294 |
|
|
banptr->host); |
| 295 |
|
|
cur_len += tlen; |
| 296 |
|
|
} |
| 297 |
|
|
|
| 298 |
|
|
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
| 299 |
|
|
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
| 300 |
|
|
} |
| 301 |
|
|
|
| 302 |
|
|
/*! \brief send "client_p" a full list of the modes for channel chptr |
| 303 |
|
|
* \param client_p pointer to client client_p |
| 304 |
|
|
* \param chptr pointer to channel pointer |
| 305 |
|
|
*/ |
| 306 |
|
|
void |
| 307 |
|
|
send_channel_modes(struct Client *client_p, struct Channel *chptr) |
| 308 |
|
|
{ |
| 309 |
|
|
if (chptr->chname[0] != '#') |
| 310 |
|
|
return; |
| 311 |
|
|
|
| 312 |
|
|
*modebuf = *parabuf = '\0'; |
| 313 |
|
|
channel_modes(chptr, client_p, modebuf, parabuf); |
| 314 |
|
|
send_members(client_p, chptr, modebuf, parabuf); |
| 315 |
|
|
|
| 316 |
|
|
send_mode_list(client_p, chptr, &chptr->banlist, 'b'); |
| 317 |
|
|
|
| 318 |
|
|
if (IsCapable(client_p, CAP_EX)) |
| 319 |
|
|
send_mode_list(client_p, chptr, &chptr->exceptlist, 'e'); |
| 320 |
|
|
if (IsCapable(client_p, CAP_IE)) |
| 321 |
|
|
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
| 322 |
|
|
} |
| 323 |
|
|
|
| 324 |
|
|
/*! \brief check channel name for invalid characters |
| 325 |
|
|
* \param name pointer to channel name string |
| 326 |
|
|
* \return TRUE (1) if name ok, FALSE (0) otherwise |
| 327 |
|
|
*/ |
| 328 |
|
|
int |
| 329 |
|
|
check_channel_name(const char *name) |
| 330 |
|
|
{ |
| 331 |
|
|
const unsigned char *p = (const unsigned char *)name; |
| 332 |
|
|
assert(name != NULL); |
| 333 |
|
|
|
| 334 |
|
|
for (; *p; ++p) |
| 335 |
|
|
if (!IsChanChar(*p)) |
| 336 |
|
|
return 0; |
| 337 |
|
|
|
| 338 |
|
|
return 1; |
| 339 |
|
|
} |
| 340 |
|
|
|
| 341 |
|
|
void |
| 342 |
|
|
remove_ban(struct Ban *bptr, dlink_list *list) |
| 343 |
|
|
{ |
| 344 |
|
|
dlinkDelete(&bptr->node, list); |
| 345 |
|
|
|
| 346 |
|
|
MyFree(bptr->name); |
| 347 |
|
|
MyFree(bptr->username); |
| 348 |
|
|
MyFree(bptr->host); |
| 349 |
|
|
MyFree(bptr->who); |
| 350 |
|
|
|
| 351 |
|
|
BlockHeapFree(ban_heap, bptr); |
| 352 |
|
|
} |
| 353 |
|
|
|
| 354 |
|
|
/* free_channel_list() |
| 355 |
|
|
* |
| 356 |
|
|
* inputs - pointer to dlink_list |
| 357 |
|
|
* output - NONE |
| 358 |
|
|
* side effects - |
| 359 |
|
|
*/ |
| 360 |
|
|
void |
| 361 |
|
|
free_channel_list(dlink_list *list) |
| 362 |
|
|
{ |
| 363 |
|
|
dlink_node *ptr = NULL, *next_ptr = NULL; |
| 364 |
|
|
|
| 365 |
|
|
DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) |
| 366 |
|
|
remove_ban(ptr->data, list); |
| 367 |
|
|
|
| 368 |
|
|
assert(list->tail == NULL && list->head == NULL); |
| 369 |
|
|
} |
| 370 |
|
|
|
| 371 |
|
|
/*! \brief Get Channel block for chname (and allocate a new channel |
| 372 |
|
|
* block, if it didn't exist before) |
| 373 |
|
|
* \param client_p client pointer |
| 374 |
|
|
* \param chname channel name |
| 375 |
|
|
* \param isnew pointer to int flag whether channel was newly created or not |
| 376 |
|
|
* \return channel block or NULL if illegal name |
| 377 |
|
|
*/ |
| 378 |
|
|
struct Channel * |
| 379 |
|
|
get_or_create_channel(struct Client *client_p, const char *chname, int *isnew) |
| 380 |
|
|
{ |
| 381 |
|
|
struct Channel *chptr = NULL; |
| 382 |
|
|
int len; |
| 383 |
|
|
|
| 384 |
|
|
if (EmptyString(chname)) |
| 385 |
|
|
return NULL; |
| 386 |
|
|
|
| 387 |
|
|
if ((len = strlen(chname)) > CHANNELLEN) |
| 388 |
|
|
{ |
| 389 |
|
|
if (IsServer(client_p)) |
| 390 |
|
|
sendto_realops_flags(UMODE_DEBUG, L_ALL, |
| 391 |
|
|
"*** Long channel name from %s (%d > %d): %s", |
| 392 |
|
|
client_p->name, len, CHANNELLEN, chname); |
| 393 |
|
|
return NULL; |
| 394 |
|
|
} |
| 395 |
|
|
|
| 396 |
|
|
if ((chptr = hash_find_channel(chname)) != NULL) |
| 397 |
|
|
{ |
| 398 |
|
|
if (isnew != NULL) |
| 399 |
|
|
*isnew = 0; |
| 400 |
|
|
|
| 401 |
|
|
return chptr; |
| 402 |
|
|
} |
| 403 |
|
|
|
| 404 |
|
|
if (isnew != NULL) |
| 405 |
|
|
*isnew = 1; |
| 406 |
|
|
|
| 407 |
|
|
chptr = BlockHeapAlloc(channel_heap); |
| 408 |
|
|
/* doesn't hurt to set it here */ |
| 409 |
|
|
chptr->channelts = chptr->last_join_time = CurrentTime; |
| 410 |
|
|
|
| 411 |
|
|
strlcpy(chptr->chname, chname, sizeof(chptr->chname)); |
| 412 |
|
|
dlinkAdd(chptr, &chptr->node, &global_channel_list); |
| 413 |
|
|
|
| 414 |
|
|
hash_add_channel(chptr); |
| 415 |
|
|
|
| 416 |
|
|
return chptr; |
| 417 |
|
|
} |
| 418 |
|
|
|
| 419 |
|
|
/*! \brief walk through this channel, and destroy it. |
| 420 |
|
|
* \param chptr channel pointer |
| 421 |
|
|
*/ |
| 422 |
|
|
void |
| 423 |
|
|
destroy_channel(struct Channel *chptr) |
| 424 |
|
|
{ |
| 425 |
|
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 426 |
|
|
|
| 427 |
|
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head) |
| 428 |
|
|
del_invite(chptr, ptr->data); |
| 429 |
|
|
|
| 430 |
|
|
/* free ban/exception/invex lists */ |
| 431 |
|
|
free_channel_list(&chptr->banlist); |
| 432 |
|
|
free_channel_list(&chptr->exceptlist); |
| 433 |
|
|
free_channel_list(&chptr->invexlist); |
| 434 |
|
|
|
| 435 |
|
|
/* Free the topic */ |
| 436 |
|
|
free_topic(chptr); |
| 437 |
|
|
|
| 438 |
|
|
dlinkDelete(&chptr->node, &global_channel_list); |
| 439 |
|
|
hash_del_channel(chptr); |
| 440 |
|
|
|
| 441 |
|
|
if (ServerInfo.hub) |
| 442 |
|
|
if ((ptr = dlinkFindDelete(&lazylink_channels, chptr))) |
| 443 |
|
|
free_dlink_node(ptr); |
| 444 |
|
|
|
| 445 |
|
|
BlockHeapFree(channel_heap, chptr); |
| 446 |
|
|
} |
| 447 |
|
|
|
| 448 |
|
|
/*! |
| 449 |
|
|
* \param chptr pointer to channel |
| 450 |
|
|
* \return string pointer "=" if public, "@" if secret else "*" |
| 451 |
|
|
*/ |
| 452 |
|
|
static const char * |
| 453 |
|
|
channel_pub_or_secret(struct Channel *chptr) |
| 454 |
|
|
{ |
| 455 |
|
|
if (SecretChannel(chptr)) |
| 456 |
|
|
return "@"; |
| 457 |
|
|
if (PrivateChannel(chptr)) |
| 458 |
|
|
return "*"; |
| 459 |
|
|
return "="; |
| 460 |
|
|
} |
| 461 |
|
|
|
| 462 |
|
|
/*! \brief lists all names on given channel |
| 463 |
|
|
* \param source_p pointer to client struct requesting names |
| 464 |
|
|
* \param chptr pointer to channel block |
| 465 |
|
|
* \param show_eon show ENDOFNAMES numeric or not |
| 466 |
|
|
* (don't want it with /names with no params) |
| 467 |
|
|
*/ |
| 468 |
|
|
void |
| 469 |
|
|
channel_member_names(struct Client *source_p, struct Channel *chptr, |
| 470 |
|
|
int show_eon) |
| 471 |
|
|
{ |
| 472 |
|
|
struct Client *target_p = NULL; |
| 473 |
|
|
struct Membership *ms = NULL; |
| 474 |
|
|
dlink_node *ptr = NULL; |
| 475 |
|
|
char lbuf[IRCD_BUFSIZE + 1]; |
| 476 |
|
|
char *t = NULL, *start = NULL; |
| 477 |
|
|
int tlen = 0; |
| 478 |
|
|
int is_member = IsMember(source_p, chptr); |
| 479 |
michael |
503 |
int multi_prefix = (source_p->localClient->cap_active & CAP_MULTI_PREFIX) != 0; |
| 480 |
adx |
30 |
|
| 481 |
|
|
if (PubChannel(chptr) || is_member) |
| 482 |
|
|
{ |
| 483 |
|
|
t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY), |
| 484 |
|
|
me.name, source_p->name, |
| 485 |
|
|
channel_pub_or_secret(chptr), |
| 486 |
|
|
chptr->chname); |
| 487 |
|
|
start = t; |
| 488 |
|
|
|
| 489 |
|
|
DLINK_FOREACH(ptr, chptr->members.head) |
| 490 |
|
|
{ |
| 491 |
|
|
ms = ptr->data; |
| 492 |
|
|
target_p = ms->client_p; |
| 493 |
|
|
|
| 494 |
|
|
if (IsInvisible(target_p) && !is_member) |
| 495 |
|
|
continue; |
| 496 |
|
|
|
| 497 |
|
|
tlen = strlen(target_p->name) + 1; /* nick + space */ |
| 498 |
|
|
|
| 499 |
michael |
506 |
if (!multi_prefix) |
| 500 |
|
|
{ |
| 501 |
|
|
if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
| 502 |
|
|
++tlen; |
| 503 |
|
|
} |
| 504 |
|
|
else |
| 505 |
|
|
{ |
| 506 |
|
|
if (ms->flags & CHFL_CHANOP) |
| 507 |
|
|
++tlen; |
| 508 |
|
|
if (ms->flags & CHFL_HALFOP) |
| 509 |
|
|
++tlen; |
| 510 |
|
|
if (ms->flags & CHFL_VOICE) |
| 511 |
|
|
++tlen; |
| 512 |
|
|
} |
| 513 |
|
|
|
| 514 |
adx |
30 |
if (t + tlen - lbuf > IRCD_BUFSIZE) |
| 515 |
|
|
{ |
| 516 |
|
|
*(t - 1) = '\0'; |
| 517 |
|
|
sendto_one(source_p, "%s", lbuf); |
| 518 |
|
|
t = start; |
| 519 |
|
|
} |
| 520 |
|
|
|
| 521 |
michael |
503 |
t += ircsprintf(t, "%s%s ", get_member_status(ms, multi_prefix), |
| 522 |
adx |
30 |
target_p->name); |
| 523 |
|
|
} |
| 524 |
|
|
|
| 525 |
|
|
if (tlen != 0) |
| 526 |
|
|
{ |
| 527 |
|
|
*(t - 1) = '\0'; |
| 528 |
|
|
sendto_one(source_p, "%s", lbuf); |
| 529 |
|
|
} |
| 530 |
|
|
} |
| 531 |
|
|
|
| 532 |
|
|
if (show_eon) |
| 533 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFNAMES), |
| 534 |
|
|
me.name, source_p->name, chptr->chname); |
| 535 |
|
|
} |
| 536 |
|
|
|
| 537 |
|
|
/*! \brief adds client to invite list |
| 538 |
|
|
* \param chptr pointer to channel block |
| 539 |
|
|
* \param who pointer to client to add invite to |
| 540 |
|
|
*/ |
| 541 |
|
|
void |
| 542 |
|
|
add_invite(struct Channel *chptr, struct Client *who) |
| 543 |
|
|
{ |
| 544 |
|
|
del_invite(chptr, who); |
| 545 |
|
|
|
| 546 |
|
|
/* |
| 547 |
|
|
* delete last link in chain if the list is max length |
| 548 |
|
|
*/ |
| 549 |
michael |
317 |
if (dlink_list_length(&who->localClient->invited) >= |
| 550 |
adx |
30 |
ConfigChannel.max_chans_per_user) |
| 551 |
michael |
317 |
del_invite(who->localClient->invited.tail->data, who); |
| 552 |
adx |
30 |
|
| 553 |
|
|
/* add client to channel invite list */ |
| 554 |
|
|
dlinkAdd(who, make_dlink_node(), &chptr->invites); |
| 555 |
|
|
|
| 556 |
|
|
/* add channel to the end of the client invite list */ |
| 557 |
michael |
317 |
dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited); |
| 558 |
adx |
30 |
} |
| 559 |
|
|
|
| 560 |
|
|
/*! \brief Delete Invite block from channel invite list |
| 561 |
|
|
* and client invite list |
| 562 |
|
|
* \param chptr pointer to Channel struct |
| 563 |
|
|
* \param who pointer to client to remove invites from |
| 564 |
|
|
*/ |
| 565 |
|
|
void |
| 566 |
|
|
del_invite(struct Channel *chptr, struct Client *who) |
| 567 |
|
|
{ |
| 568 |
|
|
dlink_node *ptr = NULL; |
| 569 |
|
|
|
| 570 |
michael |
317 |
if ((ptr = dlinkFindDelete(&who->localClient->invited, chptr))) |
| 571 |
adx |
30 |
free_dlink_node(ptr); |
| 572 |
|
|
|
| 573 |
|
|
if ((ptr = dlinkFindDelete(&chptr->invites, who))) |
| 574 |
|
|
free_dlink_node(ptr); |
| 575 |
|
|
} |
| 576 |
|
|
|
| 577 |
|
|
/* get_member_status() |
| 578 |
|
|
* |
| 579 |
|
|
* inputs - pointer to struct Membership |
| 580 |
|
|
* - YES if we can combine different flags |
| 581 |
|
|
* output - string either @, +, % or "" depending on whether |
| 582 |
|
|
* chanop, voiced or user |
| 583 |
|
|
* side effects - |
| 584 |
|
|
* |
| 585 |
|
|
* NOTE: Returned string is usually a static buffer |
| 586 |
|
|
* (like in get_client_name) |
| 587 |
|
|
*/ |
| 588 |
|
|
const char * |
| 589 |
|
|
get_member_status(const struct Membership *ms, int combine) |
| 590 |
|
|
{ |
| 591 |
|
|
static char buffer[4]; |
| 592 |
|
|
char *p = NULL; |
| 593 |
|
|
|
| 594 |
|
|
if (ms == NULL) |
| 595 |
|
|
return ""; |
| 596 |
|
|
p = buffer; |
| 597 |
|
|
|
| 598 |
|
|
if (ms->flags & CHFL_CHANOP) |
| 599 |
|
|
{ |
| 600 |
|
|
if (!combine) |
| 601 |
|
|
return "@"; |
| 602 |
|
|
*p++ = '@'; |
| 603 |
|
|
} |
| 604 |
|
|
|
| 605 |
|
|
#ifdef HALFOPS |
| 606 |
|
|
if (ms->flags & CHFL_HALFOP) |
| 607 |
|
|
{ |
| 608 |
|
|
if (!combine) |
| 609 |
|
|
return "%"; |
| 610 |
|
|
*p++ = '%'; |
| 611 |
|
|
} |
| 612 |
|
|
#endif |
| 613 |
|
|
|
| 614 |
|
|
if (ms->flags & CHFL_VOICE) |
| 615 |
|
|
*p++ = '+'; |
| 616 |
|
|
*p = '\0'; |
| 617 |
|
|
|
| 618 |
|
|
return buffer; |
| 619 |
|
|
} |
| 620 |
|
|
|
| 621 |
|
|
/*! |
| 622 |
|
|
* \param who pointer to Client to check |
| 623 |
|
|
* \param list pointer to ban list to search |
| 624 |
|
|
* \return 1 if ban found for given n!u\@h mask, 0 otherwise |
| 625 |
|
|
* |
| 626 |
|
|
*/ |
| 627 |
|
|
static int |
| 628 |
|
|
find_bmask(const struct Client *who, const dlink_list *const list) |
| 629 |
|
|
{ |
| 630 |
|
|
const dlink_node *ptr = NULL; |
| 631 |
|
|
|
| 632 |
|
|
DLINK_FOREACH(ptr, list->head) |
| 633 |
|
|
{ |
| 634 |
michael |
371 |
struct Ban *bp = ptr->data; |
| 635 |
adx |
30 |
|
| 636 |
michael |
371 |
if (match(bp->name, who->name) && match(bp->username, who->username)) |
| 637 |
|
|
{ |
| 638 |
|
|
switch (bp->type) |
| 639 |
|
|
{ |
| 640 |
|
|
case HM_HOST: |
| 641 |
|
|
if (match(bp->host, who->host) || match(bp->host, who->sockhost)) |
| 642 |
|
|
return 1; |
| 643 |
|
|
break; |
| 644 |
|
|
case HM_IPV4: |
| 645 |
|
|
if (who->localClient->aftype == AF_INET) |
| 646 |
|
|
if (match_ipv4(&who->localClient->ip, &bp->addr, bp->bits)) |
| 647 |
|
|
return 1; |
| 648 |
|
|
break; |
| 649 |
|
|
#ifdef IPV6 |
| 650 |
|
|
case HM_IPV6: |
| 651 |
|
|
if (who->localClient->aftype == AF_INET6) |
| 652 |
|
|
if (match_ipv6(&who->localClient->ip, &bp->addr, bp->bits)) |
| 653 |
|
|
return 1; |
| 654 |
|
|
break; |
| 655 |
|
|
#endif |
| 656 |
|
|
default: |
| 657 |
|
|
assert(0); |
| 658 |
|
|
} |
| 659 |
|
|
} |
| 660 |
adx |
30 |
} |
| 661 |
|
|
|
| 662 |
|
|
return 0; |
| 663 |
|
|
} |
| 664 |
|
|
|
| 665 |
|
|
/*! |
| 666 |
|
|
* \param chptr pointer to channel block |
| 667 |
|
|
* \param who pointer to client to check access fo |
| 668 |
|
|
* \return 0 if not banned, 1 otherwise |
| 669 |
|
|
*/ |
| 670 |
|
|
int |
| 671 |
|
|
is_banned(struct Channel *chptr, struct Client *who) |
| 672 |
|
|
{ |
| 673 |
|
|
assert(IsClient(who)); |
| 674 |
|
|
|
| 675 |
|
|
return find_bmask(who, &chptr->banlist) && (!ConfigChannel.use_except || |
| 676 |
|
|
!find_bmask(who, &chptr->exceptlist)); |
| 677 |
|
|
} |
| 678 |
|
|
|
| 679 |
|
|
/*! |
| 680 |
|
|
* \param source_p pointer to client attempting to join |
| 681 |
|
|
* \param chptr pointer to channel |
| 682 |
|
|
* \param key key sent by client attempting to join if present |
| 683 |
|
|
* \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL |
| 684 |
|
|
* or 0 if allowed to join. |
| 685 |
|
|
*/ |
| 686 |
|
|
int |
| 687 |
|
|
can_join(struct Client *source_p, struct Channel *chptr, const char *key) |
| 688 |
|
|
{ |
| 689 |
|
|
if (find_bmask(source_p, &chptr->banlist)) |
| 690 |
|
|
if (!ConfigChannel.use_except || !find_bmask(source_p, &chptr->exceptlist)) |
| 691 |
|
|
return ERR_BANNEDFROMCHAN; |
| 692 |
|
|
|
| 693 |
|
|
if (chptr->mode.mode & MODE_INVITEONLY) |
| 694 |
michael |
317 |
if (!dlinkFind(&source_p->localClient->invited, chptr)) |
| 695 |
adx |
30 |
if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist)) |
| 696 |
|
|
return ERR_INVITEONLYCHAN; |
| 697 |
|
|
|
| 698 |
|
|
if (chptr->mode.key[0] && (EmptyString(key) || irccmp(chptr->mode.key, key))) |
| 699 |
|
|
return ERR_BADCHANNELKEY; |
| 700 |
|
|
|
| 701 |
|
|
if (chptr->mode.limit && dlink_list_length(&chptr->members) >= |
| 702 |
|
|
chptr->mode.limit) |
| 703 |
|
|
return ERR_CHANNELISFULL; |
| 704 |
|
|
|
| 705 |
|
|
return 0; |
| 706 |
|
|
} |
| 707 |
|
|
|
| 708 |
|
|
int |
| 709 |
|
|
has_member_flags(struct Membership *ms, unsigned int flags) |
| 710 |
|
|
{ |
| 711 |
|
|
if (ms != NULL) |
| 712 |
|
|
return ms->flags & flags; |
| 713 |
|
|
return 0; |
| 714 |
|
|
} |
| 715 |
|
|
|
| 716 |
|
|
struct Membership * |
| 717 |
|
|
find_channel_link(struct Client *client_p, struct Channel *chptr) |
| 718 |
|
|
{ |
| 719 |
|
|
dlink_node *ptr = NULL; |
| 720 |
|
|
|
| 721 |
|
|
if (!IsClient(client_p)) |
| 722 |
|
|
return NULL; |
| 723 |
|
|
|
| 724 |
|
|
DLINK_FOREACH(ptr, client_p->channel.head) |
| 725 |
|
|
if (((struct Membership *)ptr->data)->chptr == chptr) |
| 726 |
|
|
return (struct Membership *)ptr->data; |
| 727 |
|
|
|
| 728 |
|
|
return NULL; |
| 729 |
|
|
} |
| 730 |
|
|
|
| 731 |
|
|
/*! |
| 732 |
|
|
* \param chptr pointer to Channel struct |
| 733 |
|
|
* \param source_p pointer to Client struct |
| 734 |
michael |
454 |
* \param ms pointer to Membership struct (can be NULL) |
| 735 |
adx |
30 |
* \return CAN_SEND_OPV if op or voiced on channel\n |
| 736 |
|
|
* CAN_SEND_NONOP if can send to channel but is not an op\n |
| 737 |
|
|
* CAN_SEND_NO if they cannot send to channel\n |
| 738 |
|
|
*/ |
| 739 |
|
|
int |
| 740 |
michael |
454 |
can_send(struct Channel *chptr, struct Client *source_p, struct Membership *ms) |
| 741 |
adx |
30 |
{ |
| 742 |
|
|
if (IsServer(source_p)) |
| 743 |
|
|
return CAN_SEND_OPV; |
| 744 |
|
|
|
| 745 |
michael |
565 |
if (MyClient(source_p) && !IsExemptResv(source_p)) |
| 746 |
|
|
if (!(IsOper(source_p) && ConfigFileEntry.oper_pass_resv) |
| 747 |
|
|
if (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels)) |
| 748 |
|
|
return CAN_SEND_NO; |
| 749 |
adx |
30 |
|
| 750 |
michael |
454 |
if (ms != NULL || (ms = find_channel_link(source_p, chptr))) |
| 751 |
adx |
30 |
{ |
| 752 |
|
|
if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE)) |
| 753 |
|
|
return CAN_SEND_OPV; |
| 754 |
|
|
|
| 755 |
|
|
/* cache can send if quiet_on_ban and banned */ |
| 756 |
|
|
if (ConfigChannel.quiet_on_ban && MyClient(source_p)) |
| 757 |
|
|
{ |
| 758 |
|
|
if (ms->flags & CHFL_BAN_SILENCED) |
| 759 |
|
|
return CAN_SEND_NO; |
| 760 |
|
|
|
| 761 |
|
|
if (!(ms->flags & CHFL_BAN_CHECKED)) |
| 762 |
|
|
{ |
| 763 |
|
|
if (is_banned(chptr, source_p)) |
| 764 |
|
|
{ |
| 765 |
|
|
ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED); |
| 766 |
|
|
return CAN_SEND_NO; |
| 767 |
|
|
} |
| 768 |
|
|
|
| 769 |
|
|
ms->flags |= CHFL_BAN_CHECKED; |
| 770 |
|
|
} |
| 771 |
|
|
} |
| 772 |
|
|
} |
| 773 |
michael |
456 |
else if (chptr->mode.mode & MODE_NOPRIVMSGS) |
| 774 |
|
|
return CAN_SEND_NO; |
| 775 |
adx |
30 |
|
| 776 |
michael |
456 |
if (chptr->mode.mode & MODE_MODERATED) |
| 777 |
adx |
30 |
return CAN_SEND_NO; |
| 778 |
|
|
|
| 779 |
|
|
return CAN_SEND_NONOP; |
| 780 |
|
|
} |
| 781 |
|
|
|
| 782 |
|
|
/*! \brief Updates the client's oper_warn_count_down, warns the |
| 783 |
|
|
* IRC operators if necessary, and updates |
| 784 |
|
|
* join_leave_countdown as needed. |
| 785 |
|
|
* \param source_p pointer to struct Client to check |
| 786 |
|
|
* \param name channel name or NULL if this is a part. |
| 787 |
|
|
*/ |
| 788 |
|
|
void |
| 789 |
|
|
check_spambot_warning(struct Client *source_p, const char *name) |
| 790 |
|
|
{ |
| 791 |
|
|
int t_delta = 0; |
| 792 |
|
|
int decrement_count = 0; |
| 793 |
|
|
|
| 794 |
|
|
if ((GlobalSetOptions.spam_num && |
| 795 |
|
|
(source_p->localClient->join_leave_count >= |
| 796 |
|
|
GlobalSetOptions.spam_num))) |
| 797 |
|
|
{ |
| 798 |
|
|
if (source_p->localClient->oper_warn_count_down > 0) |
| 799 |
|
|
source_p->localClient->oper_warn_count_down--; |
| 800 |
|
|
else |
| 801 |
|
|
source_p->localClient->oper_warn_count_down = 0; |
| 802 |
|
|
|
| 803 |
|
|
if (source_p->localClient->oper_warn_count_down == 0) |
| 804 |
|
|
{ |
| 805 |
|
|
/* Its already known as a possible spambot */ |
| 806 |
|
|
if (name != NULL) |
| 807 |
|
|
sendto_realops_flags(UMODE_BOTS, L_ALL, |
| 808 |
|
|
"User %s (%s@%s) trying to join %s is a possible spambot", |
| 809 |
|
|
source_p->name, source_p->username, |
| 810 |
|
|
source_p->host, name); |
| 811 |
|
|
else |
| 812 |
|
|
sendto_realops_flags(UMODE_BOTS, L_ALL, |
| 813 |
|
|
"User %s (%s@%s) is a possible spambot", |
| 814 |
|
|
source_p->name, source_p->username, |
| 815 |
|
|
source_p->host); |
| 816 |
|
|
source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN; |
| 817 |
|
|
} |
| 818 |
|
|
} |
| 819 |
|
|
else |
| 820 |
|
|
{ |
| 821 |
|
|
if ((t_delta = (CurrentTime - source_p->localClient->last_leave_time)) > |
| 822 |
|
|
JOIN_LEAVE_COUNT_EXPIRE_TIME) |
| 823 |
|
|
{ |
| 824 |
|
|
decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); |
| 825 |
|
|
if (decrement_count > source_p->localClient->join_leave_count) |
| 826 |
|
|
source_p->localClient->join_leave_count = 0; |
| 827 |
|
|
else |
| 828 |
|
|
source_p->localClient->join_leave_count -= decrement_count; |
| 829 |
|
|
} |
| 830 |
|
|
else |
| 831 |
|
|
{ |
| 832 |
|
|
if ((CurrentTime - (source_p->localClient->last_join_time)) < |
| 833 |
|
|
GlobalSetOptions.spam_time) |
| 834 |
|
|
{ |
| 835 |
|
|
/* oh, its a possible spambot */ |
| 836 |
|
|
source_p->localClient->join_leave_count++; |
| 837 |
|
|
} |
| 838 |
|
|
} |
| 839 |
|
|
|
| 840 |
|
|
if (name != NULL) |
| 841 |
|
|
source_p->localClient->last_join_time = CurrentTime; |
| 842 |
|
|
else |
| 843 |
|
|
source_p->localClient->last_leave_time = CurrentTime; |
| 844 |
|
|
} |
| 845 |
|
|
} |
| 846 |
|
|
|
| 847 |
|
|
/*! \brief compares usercount and servercount against their split |
| 848 |
|
|
* values and adjusts splitmode accordingly |
| 849 |
|
|
* \param unused Unused address pointer |
| 850 |
|
|
*/ |
| 851 |
|
|
void |
| 852 |
|
|
check_splitmode(void *unused) |
| 853 |
|
|
{ |
| 854 |
|
|
if (splitchecking && (ConfigChannel.no_join_on_split || |
| 855 |
|
|
ConfigChannel.no_create_on_split)) |
| 856 |
|
|
{ |
| 857 |
|
|
const unsigned int server = dlink_list_length(&global_serv_list); |
| 858 |
|
|
|
| 859 |
|
|
if (!splitmode && ((server < split_servers) || (Count.total < split_users))) |
| 860 |
|
|
{ |
| 861 |
|
|
splitmode = 1; |
| 862 |
|
|
|
| 863 |
|
|
sendto_realops_flags(UMODE_ALL,L_ALL, |
| 864 |
|
|
"Network split, activating splitmode"); |
| 865 |
|
|
eventAddIsh("check_splitmode", check_splitmode, NULL, 10); |
| 866 |
|
|
} |
| 867 |
|
|
else if (splitmode && (server > split_servers) && (Count.total > split_users)) |
| 868 |
|
|
{ |
| 869 |
|
|
splitmode = 0; |
| 870 |
|
|
|
| 871 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 872 |
|
|
"Network rejoined, deactivating splitmode"); |
| 873 |
|
|
eventDelete(check_splitmode, NULL); |
| 874 |
|
|
} |
| 875 |
|
|
} |
| 876 |
|
|
} |
| 877 |
|
|
|
| 878 |
|
|
/*! \brief Allocates a new topic |
| 879 |
|
|
* \param chptr Channel to allocate a new topic for |
| 880 |
|
|
*/ |
| 881 |
|
|
static void |
| 882 |
|
|
allocate_topic(struct Channel *chptr) |
| 883 |
|
|
{ |
| 884 |
|
|
void *ptr = NULL; |
| 885 |
|
|
|
| 886 |
|
|
if (chptr == NULL) |
| 887 |
|
|
return; |
| 888 |
|
|
|
| 889 |
|
|
ptr = BlockHeapAlloc(topic_heap); |
| 890 |
|
|
|
| 891 |
|
|
/* Basically we allocate one large block for the topic and |
| 892 |
|
|
* the topic info. We then split it up into two and shove it |
| 893 |
|
|
* in the chptr |
| 894 |
|
|
*/ |
| 895 |
|
|
chptr->topic = ptr; |
| 896 |
|
|
chptr->topic_info = (char *)ptr + TOPICLEN+1; |
| 897 |
|
|
*chptr->topic = '\0'; |
| 898 |
|
|
*chptr->topic_info = '\0'; |
| 899 |
|
|
} |
| 900 |
|
|
|
| 901 |
|
|
void |
| 902 |
|
|
free_topic(struct Channel *chptr) |
| 903 |
|
|
{ |
| 904 |
|
|
void *ptr = NULL; |
| 905 |
|
|
assert(chptr); |
| 906 |
|
|
if (chptr->topic == NULL) |
| 907 |
|
|
return; |
| 908 |
|
|
|
| 909 |
|
|
/* |
| 910 |
|
|
* If you change allocate_topic you MUST change this as well |
| 911 |
|
|
*/ |
| 912 |
|
|
ptr = chptr->topic; |
| 913 |
|
|
BlockHeapFree(topic_heap, ptr); |
| 914 |
|
|
chptr->topic = NULL; |
| 915 |
|
|
chptr->topic_info = NULL; |
| 916 |
|
|
} |
| 917 |
|
|
|
| 918 |
|
|
/*! \brief Sets the channel topic for chptr |
| 919 |
|
|
* \param chptr Pointer to struct Channel |
| 920 |
|
|
* \param topic The topic string |
| 921 |
|
|
* \param topic_info n!u\@h formatted string of the topic setter |
| 922 |
|
|
* \param topicts timestamp on the topic |
| 923 |
|
|
*/ |
| 924 |
|
|
void |
| 925 |
|
|
set_channel_topic(struct Channel *chptr, const char *topic, |
| 926 |
|
|
const char *topic_info, time_t topicts) |
| 927 |
|
|
{ |
| 928 |
|
|
if (!EmptyString(topic)) |
| 929 |
|
|
{ |
| 930 |
|
|
if (chptr->topic == NULL) |
| 931 |
|
|
allocate_topic(chptr); |
| 932 |
|
|
|
| 933 |
|
|
strlcpy(chptr->topic, topic, TOPICLEN+1); |
| 934 |
|
|
strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN); |
| 935 |
|
|
chptr->topic_time = topicts; |
| 936 |
|
|
} |
| 937 |
|
|
else |
| 938 |
|
|
{ |
| 939 |
michael |
337 |
/* |
| 940 |
|
|
* Do not reset chptr->topic_time here, it's required for |
| 941 |
|
|
* bursting topics properly. |
| 942 |
|
|
*/ |
| 943 |
adx |
30 |
if (chptr->topic != NULL) |
| 944 |
|
|
free_topic(chptr); |
| 945 |
|
|
} |
| 946 |
|
|
} |