-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkots_conpersist.c
101 lines (82 loc) · 2.08 KB
/
kots_conpersist.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
#include "kots_conpersist.h"
#include "kots_utils.h"
#define KOTS_CONPERSIST_MAXWAIT 30.0
static kots_conpersist_t *conpersist[MAX_CLIENTS];
static int persist_length = 0;
int Kots_ConPersistFindIndex(edict_t *ent)
{
int i;
for (i = 0; i < persist_length; i++)
{
if (conpersist[i] != NULL)
{
if (strcmp(conpersist[i]->name, ent->client->pers.netname) == 0
&& strcmp(conpersist[i]->persist.ip_address, ent->client->pers.kots_persist.ip_address) == 0)
return i;
}
}
return -1;
}
void Kots_LoadConPersistData(edict_t *ent)
{
if (!level.intermissiontime)
{
int index = Kots_ConPersistFindIndex(ent);
if (index != -1)
{
if (level.time < KOTS_CONPERSIST_MAXWAIT)
{
ent->client->pers.kots_persist = conpersist[index]->persist;
gi.dprintf("Loaded connection persistent info for '%s'.\n", ent->client->pers.netname);
}
else
gi.dprintf("Unable to load connection persistent info for '%s' because too much time has ellapsed.\n", ent->client->pers.netname);
gi.TagFree(conpersist[index]);
conpersist[index] = NULL;
}
}
}
void Kots_ClearConPersistData(edict_t *ent)
{
int index = Kots_ConPersistFindIndex(ent);
if (index != -1)
{
gi.TagFree(conpersist[index]);
conpersist[index] = NULL;
}
}
void Kots_ClearAllConPersistData()
{
int i;
for (i = 0; i < persist_length; i++)
{
if (conpersist[i] != NULL)
{
gi.TagFree(conpersist[i]);
conpersist[i] = NULL;
}
}
persist_length = 0;
}
void Kots_SaveConPersistData(edict_t *ent)
{
if (!ent->inuse)
return;
//only persist between maps if logged in otherwise no need
if (!ent->client->pers.kots_persist.is_loggedin)
return;
if (persist_length >= MAX_CLIENTS)
return;
conpersist[persist_length] = gi.TagMalloc(sizeof(kots_conpersist_t), TAG_GAME);
Kots_strncpy(conpersist[persist_length]->name, ent->client->pers.netname, 16);
conpersist[persist_length]->persist = ent->client->pers.kots_persist;
persist_length++;
}
void Kots_SaveAllConPersistData()
{
int i;
edict_t *ent;
ent = g_edicts + 1;
for (i = 0; i < game.maxclients; i++, ent++)
Kots_SaveConPersistData(ent);
}