]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/state.qc
Merge branch 'master' into Mario/q3compat_sanity
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / state.qc
1 #include "state.qh"
2
3 #include <server/command/getreplies.qh>
4
5 void Inventory_new(PlayerState this);
6 void Inventory_delete(entity this);
7
8 void PlayerState_attach(entity this)
9 {
10         if (PS(this) && PS(this).m_client == this)
11                 return;
12
13         this._ps = NEW(PlayerState, this);
14
15         Inventory_new(PS(this));
16 }
17
18 void PlayerState_detach(entity this)
19 {
20     PlayerState ps = PS(this);
21         if (!ps) return;  // initial connect
22         PS(this) = NULL;
23
24         if (ps.m_client != this) return;  // don't own state, spectator
25         ps.ps_push(ps, this);
26     Inventory_delete(ps);
27
28         FOREACH_CLIENT(PS(it) == ps, { PS(it) = NULL; });
29         delete(ps);
30 }
31
32 void DecodeLevelParms(entity this);
33 void PlayerScore_Attach(entity this);
34 void ClientData_Attach(entity this);
35 void accuracy_init(entity this);
36 void entcs_attach(entity this);
37 void anticheat_init(entity this);
38 void W_HitPlotOpen(entity this);
39 void bot_clientconnect(entity this);
40
41 void ClientState_attach(entity this)
42 {
43         this._cs = NEW(ClientState, this);
44
45         // TODO: fold all of these into ClientState
46
47         DecodeLevelParms(this);
48
49         PlayerScore_Attach(this);
50         PlayerStats_PlayerBasic_CheckUpdate(this);
51         ClientData_Attach(this);
52         accuracy_init(this);
53         entcs_attach(this);
54         anticheat_init(this);
55         W_HitPlotOpen(this);
56 }
57
58 void bot_clientdisconnect(entity this);
59 void W_HitPlotClose(entity this);
60 void anticheat_report_to_eventlog(entity this);
61 void entcs_detach(entity this);
62 void accuracy_free(entity this);
63 void ClientData_Detach(entity this);
64 void PlayerScore_Detach(entity this);
65
66 void ClientState_detach(entity this)
67 {
68     GetCvars(this, CS(this), -1);  // free cvars TODO: is this still needed now that it's stored on the clientstate entity?
69     accuracy_free(this); // TODO: needs to be before CS() is deleted!
70     PlayerScore_Detach(this); // what ^they^ said
71     W_HitPlotClose(this);
72     ClientData_Detach(this);
73     entcs_detach(this);
74         delete(CS(this));
75         this._cs = NULL;
76
77     bot_clientdisconnect(this);
78
79     anticheat_report_to_eventlog(this);
80 }