]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/client.qh
Port parm_idlesince 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     // custom
33
34     ATTRIB(Client, playerid, int, this.playerid);
35
36     ATTRIB(Client, parm_idlesince, int, this.parm_idlesince);
37
38     METHOD(Client, m_unwind, bool(Client this));
39
40     STATIC_METHOD(Client, Add, void(Client this, int _team));
41     STATIC_METHOD(Client, Remove, void(Client this));
42
43     INIT(Client) {
44         if (this.m_unwind(this)) return this;
45         make_impure(this);
46         this.classname = "player_joining";
47         static int playerid_last;
48         this.playerid = ++playerid_last;
49         ClientState_attach(this);
50     }
51     DESTRUCTOR(Client) {
52         Client_Remove(this);
53     }
54     CONSTRUCTOR(Client, string name) {
55         CONSTRUCT(Client);
56         this.netname = name;
57         this.netaddress = "local";
58         this.playermodel = cvar_defstring("sv_defaultplayermodel");
59     }
60 ENDCLASS(Client)
61
62 CLASS(Observer, Client)
63     INIT(Observer) {
64         this.classname = STR_OBSERVER;
65     }
66     DESTRUCTOR(Observer) { }
67 ENDCLASS(Observer)
68
69 CLASS(Spectator, Client)
70     INIT(Spectator) {
71         this.classname = STR_SPECTATOR;
72     }
73     DESTRUCTOR(Spectator) { }
74 ENDCLASS(Spectator)
75
76 CLASS(Player, Client)
77     INIT(Player) {
78         this.classname = STR_PLAYER;
79         IL_PUSH(g_players, this);
80     }
81     DESTRUCTOR(Player) {
82         IL_REMOVE(g_players, this);
83     }
84 ENDCLASS(Player)
85
86 METHOD(Client, m_unwind, bool(Client this))
87 {
88     TC(Client, this);
89     #define UNWIND(class) MACRO_BEGIN if (this.instanceOf##class) { METHOD_REFERENCE(class, dtorimpl)(this); } MACRO_END
90     switch (this.classname) {
91         case "Observer":
92             UNWIND(Spectator);
93             UNWIND(Player);
94             return true;
95         case "Spectator":
96             UNWIND(Observer);
97             UNWIND(Player);
98             return true;
99         case "Player":
100             UNWIND(Observer);
101             UNWIND(Spectator);
102             return true;
103     }
104     #undef UNWIND
105     return false;
106 }
107
108 float c1, c2, c3, c4;
109
110 void play_countdown(entity this, float finished, Sound samp);
111
112 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit);
113
114 bool Spectate(entity this, entity pl);
115
116 #define SPECTATE_COPY() [[accumulate]] void SpectateCopy(entity this, entity spectatee)
117 #define SPECTATE_COPYFIELD(fld) SPECTATE_COPY() { this.(fld) = spectatee.(fld); }