]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/client.qh
Port ping, ping_packetloss and ping_movementloss to ClientState
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / client.qh
1 #pragma once
2
3 void ClientState_attach(entity this);
4
5 IntrusiveList g_players;
6 STATIC_INIT(g_players) { g_players = IL_NEW(); }
7
8 CLASS(Client, Object)
9     /** Client name */
10     ATTRIB(Client, netname, string, this.netname);
11     ATTRIB(Client, colormap, int, this.colormap);
12     ATTRIB(Client, team, int, this.team);
13     ATTRIB(Client, clientcolors, int, this.clientcolors);
14     /** Client IP */
15     ATTRIB(Client, netaddress, string, this.netaddress);
16     ATTRIB(Client, playermodel, string, this.playermodel);
17     ATTRIB(Client, playerskin, int, this.playerskin);
18
19     /** fingerprint of CA key the player used to authenticate */
20     ATTRIB(Client, crypto_keyfp, string, this.crypto_keyfp);
21     /** fingerprint of CA key the server used to authenticate to the player */
22     ATTRIB(Client, crypto_mykeyfp, string, this.crypto_mykeyfp);
23     /** fingerprint of ID used by the player entity, or string_null if not identified */
24     ATTRIB(Client, crypto_idfp, string, this.crypto_idfp);
25     /** set if the player's ID has been signed */
26     ATTRIB(Client, crypto_idfp_signed, bool, this.crypto_idfp_signed);
27     /** the string "AES128" if encrypting, and string_null if plaintext */
28     ATTRIB(Client, crypto_encryptmethod, string, this.crypto_encryptmethod);
29     /** the string "HMAC-SHA256" if signing, and string_null if plaintext */
30     ATTRIB(Client, crypto_signmethod, string, this.crypto_signmethod);
31
32     // engine client fields
33     ATTRIB(Client, impulse, int, this.impulse);
34
35     ATTRIB(Client, button0, int, this.button0);
36     ATTRIB(Client, button2, int, this.button2);
37     ATTRIB(Client, button3, int, this.button3);
38     ATTRIB(Client, button4, int, this.button4);
39     ATTRIB(Client, button5, int, this.button5);
40     ATTRIB(Client, button6, int, this.button6);
41     ATTRIB(Client, button7, int, this.button7);
42     ATTRIB(Client, button8, int, this.button8);
43     ATTRIB(Client, button9, int, this.button9);
44     ATTRIB(Client, button10, int, this.button10);
45     ATTRIB(Client, button11, int, this.button11);
46     ATTRIB(Client, button12, int, this.button12);
47     ATTRIB(Client, button13, int, this.button13);
48     ATTRIB(Client, button14, int, this.button14);
49     ATTRIB(Client, button15, int, this.button15);
50     ATTRIB(Client, button16, int, this.button16);
51     ATTRIB(Client, buttonuse, int, this.buttonuse);
52     ATTRIB(Client, buttonchat, int, this.buttonchat);
53
54     ATTRIB(Client, cursor_active, int, this.cursor_active);
55     ATTRIB(Client, cursor_screen, vector, this.cursor_screen);
56     ATTRIB(Client, cursor_trace_start, vector, this.cursor_trace_start);
57     ATTRIB(Client, cursor_trace_endpos, vector, this.cursor_trace_endpos);
58     ATTRIB(Client, cursor_trace_ent, entity, this.cursor_trace_ent);
59
60     ATTRIB(Client, ping, float, this.ping);
61     ATTRIB(Client, ping_packetloss, float, this.ping_packetloss);
62     ATTRIB(Client, ping_movementloss, float, this.ping_movementloss);
63
64     ATTRIB(Client, v_angle, vector, this.v_angle);
65     ATTRIB(Client, movement, vector, this.movement);
66
67     // custom
68
69     ATTRIB(Client, playerid, int, this.playerid);
70
71     ATTRIB(Client, parm_idlesince, int, this.parm_idlesince);
72     ATTRIB(Client, muted, bool, this.muted);
73     ATTRIB(Client, killindicator_teamchange, int, this.killindicator_teamchange);
74     ATTRIB(Client, idlekick_lasttimeleft, float, this.idlekick_lasttimeleft);
75     ATTRIB(Client, pm_frametime, float, this.pm_frametime);
76
77     METHOD(Client, m_unwind, bool(Client this));
78
79     STATIC_METHOD(Client, Add, void(Client this, int _team));
80     STATIC_METHOD(Client, Remove, void(Client this));
81
82     INIT(Client) {
83         if (this.m_unwind(this)) return this;
84         make_impure(this);
85         this.classname = "player_joining";
86         static int playerid_last;
87         this.playerid = ++playerid_last;
88         ClientState_attach(this);
89     }
90     DESTRUCTOR(Client) {
91         Client_Remove(this);
92     }
93     CONSTRUCTOR(Client, string name) {
94         CONSTRUCT(Client);
95         this.netname = name;
96         this.netaddress = "local";
97         this.playermodel = cvar_defstring("sv_defaultplayermodel");
98     }
99 ENDCLASS(Client)
100
101 CLASS(Observer, Client)
102     INIT(Observer) {
103         this.classname = STR_OBSERVER;
104     }
105     DESTRUCTOR(Observer) { }
106 ENDCLASS(Observer)
107
108 CLASS(Spectator, Client)
109     INIT(Spectator) {
110         this.classname = STR_SPECTATOR;
111     }
112     DESTRUCTOR(Spectator) { }
113 ENDCLASS(Spectator)
114
115 CLASS(Player, Client)
116     INIT(Player) {
117         this.classname = STR_PLAYER;
118         IL_PUSH(g_players, this);
119     }
120     DESTRUCTOR(Player) {
121         IL_REMOVE(g_players, this);
122     }
123 ENDCLASS(Player)
124
125 METHOD(Client, m_unwind, bool(Client this))
126 {
127     TC(Client, this);
128     #define UNWIND(class) MACRO_BEGIN if (this.instanceOf##class) { METHOD_REFERENCE(class, dtorimpl)(this); } MACRO_END
129     switch (this.classname) {
130         case "Observer":
131             UNWIND(Spectator);
132             UNWIND(Player);
133             return true;
134         case "Spectator":
135             UNWIND(Observer);
136             UNWIND(Player);
137             return true;
138         case "Player":
139             UNWIND(Observer);
140             UNWIND(Spectator);
141             return true;
142     }
143     #undef UNWIND
144     return false;
145 }
146
147 float c1, c2, c3, c4;
148
149 void play_countdown(entity this, float finished, Sound samp);
150
151 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit);
152
153 bool Spectate(entity this, entity pl);
154
155 #define SPECTATE_COPY() [[accumulate]] void SpectateCopy(entity this, entity spectatee)
156 #define SPECTATE_COPYFIELD(fld) SPECTATE_COPY() { this.(fld) = spectatee.(fld); }