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