1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
|
/*
* whowas.c a linked list buffer of people who have left your channel
* mainly used for ban prot and stats stuff.
* Should even speed stuff up a bit too.
*
* Written by Scott H Kilau
*
* Copyright(c) 1995
* Modified Colten Edwards 1996
* See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT
*/
#include "irc.h"
static char cvsrevision[] = "$Id: whowas.c,v 1.1.1.1 2003/04/11 01:09:07 dan Exp $";
CVS_REVISION(whowas_c)
#include "struct.h"
#include "vars.h"
#include "ircaux.h"
#include "window.h"
#include "who.h"
#include "hook.h"
#include "input.h"
#include "names.h"
#include "alias.h"
#include "output.h"
#include "numbers.h"
#include "status.h"
#include "screen.h"
#include "commands.h"
#include "config.h"
#include "list.h"
#include "userlist.h"
#include "misc.h"
#include "hash.h"
#include "hash2.h"
#define MAIN_SOURCE
#include "modval.h"
/*
#include "ctimers.h"
#include "edit2.h"
#include "edit3.h"
#include "edit4.h"
*/
#include "userlist.h"
#include "whowas.h"
WhowasWrapList whowas_userlist_list = { 0 };
WhowasWrapList whowas_reg_list = { 0 };
WhowasWrapList whowas_splitin_list = { 0 };
WhowasChanList *whowas_chan_list = NULL;
static int whowas_userlist_count = 0;
static int whowas_reg_count = 0;
static int whowas_chan_count = 0;
extern WhowasList *check_whowas_buffer(char *nick, char *userhost, char *channel, int unlink)
{
WhowasList *tmp = NULL;
if (!(tmp = find_userhost_channel(userhost, channel, unlink, &whowas_userlist_list)))
tmp = find_userhost_channel(userhost, channel, unlink, &whowas_reg_list);
return tmp;
}
extern WhowasList * check_whowas_nick_buffer(char *nick, char *channel, int unlink)
{
WhowasList *tmp = NULL, *last = NULL;
for (tmp = next_userhost(&whowas_userlist_list, NULL); tmp; tmp = next_userhost(&whowas_userlist_list, tmp))
{
if (!my_stricmp(tmp->nicklist->nick, nick) && !my_stricmp(tmp->channel, channel))
{
if (unlink)
{
last = find_userhost_channel(tmp->nicklist->host, tmp->channel, 1, &whowas_userlist_list);
tmp = NULL;
}
return last?last:tmp;
}
}
for (tmp = next_userhost(&whowas_reg_list, NULL); tmp; tmp = next_userhost(&whowas_reg_list, tmp))
{
if (!my_stricmp(tmp->nicklist->nick, nick) && !my_stricmp(tmp->channel, channel))
{
if (unlink)
{
last = find_userhost_channel(tmp->nicklist->host, tmp->channel, 1, &whowas_reg_list);
tmp = NULL;
}
return last?last:tmp;
}
}
return( NULL );
}
extern WhowasList * check_whosplitin_buffer(char *nick, char *userhost, char *channel, int unlink)
{
WhowasList *tmp = NULL;
tmp = find_userhost_channel(userhost, channel, unlink, &whowas_splitin_list);
return tmp;
}
void add_to_whowas_buffer(NickList *nicklist, char *channel, char *server1, char *server2)
{
WhowasList *new;
if (!nicklist || !nicklist->nick)
return;
if (nicklist->userlist)
{
if (whowas_userlist_count >= whowas_userlist_max)
{
whowas_userlist_count -=
remove_oldest_whowas(&whowas_userlist_list, 0,
(whowas_userlist_max + 1) - whowas_userlist_count);
}
new = (WhowasList *) new_malloc(sizeof(WhowasList));
new->has_ops = nick_isop(nicklist);
new->nicklist = nicklist;
malloc_strcpy(&(new->channel), channel);
malloc_strcpy(&(new->server1), server1);
if (server2)
malloc_strcpy(&(new->server2), server2);
new->time = now;
add_whowas_userhost_channel(new, &whowas_userlist_list);
whowas_userlist_count++;
}
else
{
if (whowas_reg_count >= whowas_reg_max)
{
whowas_reg_count -=
remove_oldest_whowas(&whowas_reg_list, 0,
(whowas_reg_max + 1) - whowas_reg_count);
}
new = (WhowasList *) new_malloc(sizeof(WhowasList));
new->has_ops = nick_isop(nicklist);
new->nicklist = (NickList *) nicklist;
malloc_strcpy(&(new->channel), channel);
malloc_strcpy(&(new->server1), server1);
malloc_strcpy(&(new->server2), server2);
new->time = now;
add_whowas_userhost_channel(new, &whowas_reg_list);
whowas_reg_count++;
}
}
void add_to_whosplitin_buffer(NickList *nicklist, char *channel, char *server1, char *server2)
{
WhowasList *new;
new = (WhowasList *) new_malloc(sizeof(WhowasList));
new->has_ops = nick_isop(nicklist);
new->nicklist = (NickList *)new_malloc(sizeof(NickList)); /*nicklist;*/
new->nicklist->nick = m_strdup(nicklist->nick);
new->nicklist->host = m_strdup(nicklist->host);
malloc_strcpy(&(new->channel), channel);
malloc_strcpy(&(new->server1), server1);
malloc_strcpy(&(new->server2), server2);
new->time = now;
add_whowas_userhost_channel(new, &whowas_splitin_list);
}
int remove_oldest_whowas(WhowasWrapList *list, time_t timet, int count)
{
int total = 0;
/* if no ..count.. then remove ..time.. links */
total = remove_oldest_whowas_hashlist(list, timet, count);
return total;
}
void clean_whowas_list(void)
{
if (whowas_userlist_count)
whowas_userlist_count -= remove_oldest_whowas_hashlist(&whowas_userlist_list, 20 * 60, 0);
if (whowas_reg_count)
whowas_reg_count -= remove_oldest_whowas_hashlist(&whowas_reg_list, 10 * 60, 0);
remove_oldest_whowas_hashlist(&whowas_splitin_list, 25 * 60 , 0);
}
/* Used to rehash whowas listings for new users */
void sync_whowas_adduser(UserList *added)
{
WhowasList *tmp;
for (tmp = next_userhost(&whowas_userlist_list, NULL); tmp; tmp = next_userhost(&whowas_userlist_list, tmp))
{
if (check_channel_match(added->channels, tmp->channel))
if (wild_match(added->host, tmp->nicklist->host) && wild_match(added->nick, tmp->nicklist->nick))
tmp->nicklist->userlist = added;
}
for (tmp = next_userhost(&whowas_reg_list, NULL); tmp; tmp = next_userhost(&whowas_reg_list, tmp))
{
if (check_channel_match(added->channels, tmp->channel))
if (wild_match(added->host, tmp->nicklist->host) && wild_match(added->nick, tmp->nicklist->nick))
tmp->nicklist->userlist = added;
}
}
/* Used to rehash whowas listings for removed userlist entries */
void sync_whowas_unuser(UserList *entry)
{
WhowasList *tmp;
for (tmp = next_userhost(&whowas_userlist_list, NULL); tmp; tmp = next_userhost(&whowas_userlist_list, tmp))
{
if (!tmp->nicklist->userlist) continue;
if (!my_stricmp(tmp->nicklist->userlist->host, entry->host) && !my_stricmp(tmp->nicklist->userlist->nick, entry->nick) &&
check_channel_match(tmp->nicklist->userlist->channels, entry->channels))
tmp->nicklist->userlist = NULL;
}
for (tmp = next_userhost(&whowas_reg_list, NULL); tmp; tmp = next_userhost(&whowas_reg_list, tmp))
{
if (!tmp->nicklist->userlist) continue;
if (!my_stricmp(tmp->nicklist->userlist->host, entry->host) && !my_stricmp(tmp->nicklist->userlist->nick, entry->nick) &&
check_channel_match(tmp->nicklist->userlist->channels, entry->channels))
tmp->nicklist->userlist = NULL;
}
}
/* Used to rehash whowas listings for new shitlist entries */
void sync_whowas_addshit(ShitList *added)
{
WhowasList *tmp;
char user[BIG_BUFFER_SIZE];
for (tmp = next_userhost(&whowas_userlist_list, NULL); tmp; tmp = next_userhost(&whowas_userlist_list, tmp))
{
if (check_channel_match(added->channels, tmp->channel))
{
sprintf(user, "%s!%s", tmp->nicklist->nick, tmp->nicklist->host);
if (wild_match(added->filter, user))
tmp->nicklist->shitlist = added;
}
}
for (tmp = next_userhost(&whowas_reg_list, NULL); tmp; tmp = next_userhost(&whowas_reg_list, tmp))
{
if (check_channel_match(added->channels, tmp->channel))
{
sprintf(user, "%s!%s", tmp->nicklist->nick, tmp->nicklist->host);
if (wild_match(added->filter, user))
tmp->nicklist->shitlist = added;
}
}
}
/* Used to rehash whowas listings for removed shitlist entries */
void sync_whowas_unshit(ShitList *entry)
{
WhowasList *tmp;
for (tmp = next_userhost(&whowas_userlist_list, NULL); tmp; tmp = next_userhost(&whowas_userlist_list, tmp))
{
if (!tmp->nicklist->shitlist) continue;
if (!my_stricmp(tmp->nicklist->shitlist->filter, entry->filter) &&
check_channel_match(tmp->nicklist->shitlist->channels, entry->channels))
tmp->nicklist->shitlist = NULL;
}
for (tmp = next_userhost(&whowas_reg_list, NULL); tmp; tmp = next_userhost(&whowas_reg_list, tmp))
{
if (!tmp->nicklist->shitlist) continue;
if (!my_stricmp(tmp->nicklist->shitlist->filter, entry->filter) &&
check_channel_match(tmp->nicklist->shitlist->channels, entry->channels))
tmp->nicklist->shitlist = NULL;
}
}
/* BELOW THIS MARK IS THE CHANNEL WHOWAS STUFF */
extern WhowasChanList *check_whowas_chan_buffer(char *channel, int refnum, int unlink)
{
WhowasChanList *tmp, *last = NULL;
for (tmp = whowas_chan_list; tmp; tmp = tmp->next) {
if (!my_stricmp(tmp->channellist->channel, channel))
{
if ((refnum == -1) || (refnum == tmp->channellist->refnum))
{
if (unlink) {
if (last)
last->next = tmp->next;
else
whowas_chan_list = tmp->next;
whowas_chan_count--;
}
return(tmp);
}
}
last = tmp;
}
return( NULL );
}
void add_to_whowas_chan_buffer(ChannelList *channel)
{
WhowasChanList *new;
WhowasChanList **slot;
if (whowas_chan_count >= whowas_chan_max)
{
whowas_chan_count -=
remove_oldest_chan_whowas(&whowas_chan_list, 0,
(whowas_chan_max + 1) - whowas_chan_count);
}
new = (WhowasChanList *) new_malloc(sizeof(WhowasChanList));
new->channellist = channel;
new->time = now;
clear_nicklist_hashtable(channel);
/* we've created it, now put it in order */
for (slot = &whowas_chan_list; *slot; slot = &(*slot)->next)
{
if ((*slot)->time > new->time)
break;
}
new->next = *slot;
*slot = new;
whowas_chan_count++;
}
int remove_oldest_chan_whowas(WhowasChanList **list, time_t timet, int count)
{
WhowasChanList *tmp = NULL;
time_t t;
int total = 0;
/* if no ..count.. then remove ..time.. links */
if (!count)
{
t = now;
while (*list && ((*list)->time + timet) <= t)
{
tmp = *list;
new_free(&(tmp->channellist->channel));
new_free(&(tmp->channellist->topic));
new_free(&(tmp->channellist->modelock_key));
clear_bans(tmp->channellist);
if (tmp->channellist->msglog_fp)
fclose(tmp->channellist->msglog_fp);
remove_csets_for_channel(tmp->channellist->csets);
new_free((char **)&(tmp->channellist));
*list = tmp->next;
new_free((char **)&tmp);
total++;
}
}
else
{
while (*list && count)
{
tmp = *list;
new_free(&(tmp->channellist->channel));
new_free(&(tmp->channellist->topic));
new_free(&(tmp->channellist->modelock_key));
clear_bans(tmp->channellist);
if (tmp->channellist->msglog_fp)
fclose(tmp->channellist->msglog_fp);
remove_csets_for_channel(tmp->channellist->csets);
new_free((char **)&(tmp->channellist));
*list = tmp->next;
new_free((char **)&tmp);
total++;
count--;
}
}
return total;
}
void clean_whowas_chan_list(void)
{
whowas_chan_count -= remove_oldest_chan_whowas(&whowas_chan_list, 24 * 60 * 60, 0);
}
void clear_whowas(void)
{
whowas_chan_count -= remove_oldest_chan_whowas(&whowas_chan_list, 0, 0);
if (whowas_userlist_count)
whowas_userlist_count -= remove_oldest_whowas_hashlist(&whowas_userlist_list, 0, 0);
if (whowas_reg_count)
whowas_reg_count -= remove_oldest_whowas_hashlist(&whowas_reg_list, 0, 0);
remove_oldest_whowas_hashlist(&whowas_splitin_list, 0 , 0);
}
void show_whowas(void)
{
reset_display_target();
show_whowas_hashtable(&whowas_userlist_list, "Userlist");
show_whowas_hashtable(&whowas_reg_list, "Reglist");
}
void show_wholeft(char *channel)
{
int count = 0;
int hook = 0;
time_t ltime = now;
reset_display_target();
#if 0
hook = show_wholeft_hashtable(&whowas_splitin_list, ltime, &count, &hook, "SplitList");
#endif
hook = show_wholeft_hashtable(&whowas_userlist_list, ltime, &count, &hook, "Splitin");
hook = show_wholeft_hashtable(&whowas_reg_list, ltime, &count, &hook, "Splitin");
if (count && hook && fget_string_var(FORMAT_WHOLEFT_FOOTER_FSET))
put_it("%s", convert_output_format(fget_string_var(FORMAT_WHOLEFT_FOOTER_FSET), NULL));
}
|