/
free_user.c
127 lines (111 loc) · 3.05 KB
/
free_user.c
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
/* Copyright (C) 2000-1 drscholl@users.sourceforge.net
This is free software distributed under the terms of the
GNU Public License. See the file COPYING for details.
$Id: free_user.c,v 1.49 2001/09/22 05:52:06 drscholl Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include "opennap.h"
#include "hashlist.h"
#include "debug.h"
void
free_user (USER * user)
{
LIST *list;
USERDB *db;
whowas_t *who;
ip_info_t *info;
ASSERT (validate_user (user));
if (ISUSER (user->con) && Servers && !user->con->killed)
{
/* local user, notify peers of this user's departure */
pass_message_args (user->con, MSG_CLIENT_QUIT, "%s", user->nick);
}
/* remove this user from any channels they were on */
if (user->channels)
{
for (list = user->channels; list; list = list->next)
{
/* notify locally connected clients in the same channel that
this user has parted */
part_channel (list->data, user);
}
list_free (user->channels, 0);
}
/* check the global hotlist for this user to see if anyone wants notice
of this user's departure */
for (list = hashlist_lookup (Hotlist, user->nick); list;
list = list->next)
{
ASSERT (validate_connection (list->data));
send_cmd (list->data, MSG_SERVER_USER_SIGNOFF, "%s", user->nick);
}
ASSERT (Num_Files >= user->shared);
Num_Files -= user->shared;
ASSERT (Num_Gigs >= user->libsize);
if (Num_Gigs < user->libsize)
{
log_message ("free_user: bad total lib size: Num_Gigs=%f user->libsize=%u",
Num_Gigs, user->libsize);
Num_Gigs = user->libsize; /* prevent negative value */
}
Num_Gigs -= user->libsize; /* this is in kB */
#ifndef ROUTING_ONLY
if (ISUSER (user->con))
{
if (user->shared > Local_Files)
{
log_message
("free_user: local file count error, %s is sharing %d, more than %d",
user->nick, user->shared, Local_Files);
Local_Files = 0;
}
else
Local_Files -= user->shared;
}
#endif /* !ROUTING_ONLY */
/* record the log off time */
if ((db = hash_lookup (User_Db, user->nick)))
db->lastSeen = global.current_time;
/* save info in the who-was table */
who = hash_lookup (Who_Was, user->nick);
if (!who)
{
who = CALLOC (1, sizeof (whowas_t));
if (!who)
{
OUTOFMEMORY ("free_user");
FREE (user->nick);
}
else
{
who->nick = user->nick;
hash_add (Who_Was, who->nick, who);
}
}
else
FREE (user->nick);
if (who)
{
who->ip = user->ip;
who->when = global.current_time;
who->server = user->server;
who->clientinfo = user->clientinfo;
}
memset (user->pass, 0, strlen (user->pass));
FREE (user->pass);
/* decrement the clone count */
info = hash_lookup (Clones, (void *) user->ip);
if (info->users <= 0)
{
log_message ("free_user: ERROR, info->users <= 0");
info->users = 0;
}
else
info->users--;
/* NOTE: user->server is just a ref, not a malloc'd pointer */
memset (user, 0xff, sizeof (USER)); /* catch refs to bad memory */
FREE (user);
}