Merge branch 'master' into Mario/cursor
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / client.qh
1 #pragma once
2
3 #include "utils.qh"
4 #include <common/sounds/all.qh>
5
6 void ClientState_attach(entity this);
7
8 IntrusiveList g_players;
9 STATIC_INIT(g_players) { g_players = IL_NEW(); }
10
11 CLASS(Client, Object)
12     /** Client name */
13     ATTRIB(Client, netname, string, this.netname);
14     ATTRIB(Client, colormap, int, this.colormap);
15     ATTRIB(Client, team, int, this.team);
16     ATTRIB(Client, clientcolors, int, this.clientcolors);
17     /** Client IP */
18     ATTRIB(Client, netaddress, string, this.netaddress);
19     ATTRIB(Client, playermodel, string, this.playermodel);
20     ATTRIB(Client, playerskin, string, this.playerskin);
21
22     /** fingerprint of CA key the player used to authenticate */
23     ATTRIB(Client, crypto_keyfp, string, this.crypto_keyfp);
24     /** fingerprint of CA key the server used to authenticate to the player */
25     ATTRIB(Client, crypto_mykeyfp, string, this.crypto_mykeyfp);
26     /** fingerprint of ID used by the player entity, or string_null if not identified */
27     ATTRIB(Client, crypto_idfp, string, this.crypto_idfp);
28     /** set if the player's ID has been signed */
29     ATTRIB(Client, crypto_idfp_signed, bool, this.crypto_idfp_signed);
30     /** the string "AES128" if encrypting, and string_null if plaintext */
31     ATTRIB(Client, crypto_encryptmethod, string, this.crypto_encryptmethod);
32     /** the string "HMAC-SHA256" if signing, and string_null if plaintext */
33     ATTRIB(Client, crypto_signmethod, string, this.crypto_signmethod);
34
35     // engine client fields
36     ATTRIB(Client, impulse, int, this.impulse);
37
38     ATTRIB(Client, button0, int, this.button0);
39     ATTRIB(Client, button2, int, this.button2);
40     ATTRIB(Client, button3, int, this.button3);
41     ATTRIB(Client, button4, int, this.button4);
42     ATTRIB(Client, button5, int, this.button5);
43     ATTRIB(Client, button6, int, this.button6);
44     ATTRIB(Client, button7, int, this.button7);
45     ATTRIB(Client, button8, int, this.button8);
46     ATTRIB(Client, button9, int, this.button9);
47     ATTRIB(Client, button10, int, this.button10);
48     ATTRIB(Client, button11, int, this.button11);
49     ATTRIB(Client, button12, int, this.button12);
50     ATTRIB(Client, button13, int, this.button13);
51     ATTRIB(Client, button14, int, this.button14);
52     ATTRIB(Client, button15, int, this.button15);
53     ATTRIB(Client, button16, int, this.button16);
54     ATTRIB(Client, buttonuse, int, this.buttonuse);
55     ATTRIB(Client, buttonchat, int, this.buttonchat);
56
57     ATTRIB(Client, cursor_active, int, this.cursor_active);
58     ATTRIB(Client, cursor_screen, vector, this.cursor_screen);
59     ATTRIB(Client, cursor_trace_start, vector, this.cursor_trace_start);
60     ATTRIB(Client, cursor_trace_endpos, vector, this.cursor_trace_endpos);
61     ATTRIB(Client, cursor_trace_ent, entity, this.cursor_trace_ent);
62
63     ATTRIB(Client, ping, float, this.ping);
64     ATTRIB(Client, ping_packetloss, float, this.ping_packetloss);
65     ATTRIB(Client, ping_movementloss, float, this.ping_movementloss);
66
67     ATTRIB(Client, v_angle, vector, this.v_angle);
68     ATTRIB(Client, movement, vector, this.movement);
69
70     // custom
71
72     ATTRIB(Client, playerid, int, this.playerid);
73
74     ATTRIB(Client, parm_idlesince, int, this.parm_idlesince);
75     ATTRIB(Client, muted, bool, this.muted);
76     ATTRIB(Client, idlekick_lasttimeleft, float, this.idlekick_lasttimeleft);
77     ATTRIB(Client, pm_frametime, float, this.pm_frametime);
78     ATTRIB(Client, pressedkeys, int, this.pressedkeys);
79     ATTRIB(Client, movement_old, vector, this.movement_old);
80     ATTRIB(Client, buttons_old, int, this.buttons_old);
81     ATTRIB(Client, teamkill_complain, float, this.teamkill_complain);
82     ATTRIB(Client, teamkill_soundtime, float, this.teamkill_soundtime);
83     ATTRIB(Client, teamkill_soundsource, entity, this.teamkill_soundsource);
84     ATTRIB(Client, usekeypressed, bool, this.usekeypressed);
85     ATTRIB(Client, motd_actived_time, float, this.motd_actived_time);
86     ATTRIB(Client, jointime, float, this.jointime);
87     ATTRIB(Client, spectatortime, float, this.spectatortime);
88     ATTRIB(Client, startplaytime, float, this.startplaytime);
89     ATTRIB(Client, version_nagtime, float, this.version_nagtime);
90     ATTRIB(Client, netname_previous, string, this.netname_previous);
91     ATTRIB(Client, allowed_timeouts, int, this.allowed_timeouts);
92     ATTRIB(Client, active_minigame, entity, this.active_minigame);
93     ATTRIB(Client, taunt_soundtime, float, this.taunt_soundtime);
94     ATTRIB(Client, killcount, int, this.killcount);
95     ATTRIB(Client, version_mismatch, bool, this.version_mismatch);
96     ATTRIB(Client, version, int, this.version);
97     ATTRIB(Client, spectatee_status, int, this.spectatee_status);
98     ATTRIB(Client, zoomstate, bool, this.zoomstate);
99     ATTRIB(Client, just_joined, bool, this.just_joined);
100     ATTRIB(Client, race_completed, bool, this.race_completed);
101     ATTRIBARRAY(Client, msg_choice_choices, int, 50); // TODO: actually NOTIF_CHOICE_MAX
102     ATTRIB(Client, latency_sum, float, this.latency_sum);
103     ATTRIB(Client, latency_cnt, int, this.latency_cnt);
104     ATTRIB(Client, latency_time, float, this.latency_time);
105     ATTRIB(Client, v_angle_old, vector, this.v_angle_old);
106     ATTRIB(Client, model_randomizer, float, this.model_randomizer);
107     ATTRIB(Client, accuracy, entity, this.accuracy);
108     ATTRIB(Client, hasweapon_complain_spam, float, this.hasweapon_complain_spam);
109     ATTRIB(Client, scorekeeper, entity, this.scorekeeper);
110     ATTRIB(Client, specialcommand_pos, int, this.specialcommand_pos);
111     ATTRIB(Client, hitplotfh, int, this.hitplotfh);
112     ATTRIB(Client, clientdata, entity, this.clientdata);
113     ATTRIB(Client, cmd_floodcount, int, this.cmd_floodcount);
114     ATTRIB(Client, cmd_floodtime, float, this.cmd_floodtime);
115     ATTRIB(Client, wasplayer, bool, this.wasplayer);
116     ATTRIB(Client, weaponorder_byimpulse, string, this.weaponorder_byimpulse);
117     ATTRIB(Client, autojoin_checked, bool, this.wasplayer);
118
119     // networked cvars
120
121     ATTRIB(Client, cvar_cl_allow_uid2name, int, this.cvar_cl_allow_uid2name);
122     ATTRIB(Client, cvar_cl_allow_uidtracking, int, this.cvar_cl_allow_uidtracking);
123     ATTRIB(Client, cvar_cl_autotaunt, float, this.cvar_cl_autotaunt);
124     ATTRIB(Client, cvar_cl_voice_directional, int, this.cvar_cl_voice_directional);
125     ATTRIB(Client, cvar_cl_voice_directional_taunt_attenuation, float, this.cvar_cl_voice_directional_taunt_attenuation);
126     ATTRIB(Client, cvar_cl_physics, string, this.cvar_cl_physics);
127     ATTRIB(Client, cvar_cl_buffs_autoreplace, bool, this.cvar_cl_buffs_autoreplace);
128     ATTRIB(Client, cvar_cl_nade_type, int, this.cvar_cl_nade_type);
129     ATTRIB(Client, cvar_cl_pokenade_type, string, this.cvar_cl_pokenade_type);
130     ATTRIB(Client, cvar_cl_spawn_near_teammate, bool, this.cvar_cl_spawn_near_teammate);
131     ATTRIB(Client, cvar_cl_gunalign, int, this.cvar_cl_gunalign);
132     ATTRIB(Client, cvar_cl_handicap, float, this.cvar_cl_handicap);
133     ATTRIB(Client, cvar_cl_clippedspectating, bool, this.cvar_cl_clippedspectating);
134     ATTRIB(Client, cvar_cl_autoscreenshot, int, this.cvar_cl_autoscreenshot);
135     ATTRIB(Client, cvar_cl_jetpack_jump, bool, this.cvar_cl_jetpack_jump);
136     ATTRIB(Client, cvar_cl_newusekeysupported, bool, this.cvar_cl_newusekeysupported);
137     ATTRIB(Client, cvar_cl_noantilag, bool, this.cvar_cl_noantilag);
138     ATTRIB(Client, cvar_cl_movement_track_canjump, bool, this.cvar_cl_movement_track_canjump);
139     ATTRIB(Client, cvar_cl_weaponimpulsemode, int, this.cvar_cl_weaponimpulsemode);
140     ATTRIB(Client, cvar_g_xonoticversion, string, this.cvar_g_xonoticversion);
141     ATTRIB(Client, autoswitch, bool, this.autoswitch);
142     ATTRIB(Client, cvar_cl_dodging_timeout, float, this.cvar_cl_dodging_timeout);
143     ATTRIB(Client, cvar_cl_multijump, bool, this.cvar_cl_multijump);
144     ATTRIB(Client, cvar_cl_accuracy_data_share, bool, this.cvar_cl_accuracy_data_share);
145     ATTRIB(Client, cvar_cl_accuracy_data_receive, bool, this.cvar_cl_accuracy_data_receive);
146     ATTRIBARRAY(Client, cvar_cl_weaponpriorities, string, 10);
147     ATTRIB(Client, cvar_cl_weaponpriority, string, this.cvar_cl_weaponpriority);
148
149     METHOD(Client, m_unwind, bool(Client this));
150
151     STATIC_METHOD(Client, Add, void(Client this, int _team));
152     STATIC_METHOD(Client, Remove, void(Client this));
153
154     INIT(Client) {
155         if (this.m_unwind(this)) return this;
156         make_impure(this);
157         this.classname = "player_joining";
158         static int playerid_last;
159         this.playerid = ++playerid_last;
160         ClientState_attach(this);
161     }
162     DESTRUCTOR(Client) {
163         Client_Remove(this);
164     }
165     CONSTRUCTOR(Client, string name) {
166         CONSTRUCT(Client);
167         this.netname = name;
168         this.netaddress = "local";
169         this.playermodel = cvar_defstring("sv_defaultplayermodel");
170     }
171 ENDCLASS(Client)
172
173 CLASS(Observer, Client)
174     INIT(Observer) {
175         this.classname = STR_OBSERVER;
176     }
177     DESTRUCTOR(Observer) { }
178 ENDCLASS(Observer)
179
180 CLASS(Spectator, Client)
181     INIT(Spectator) {
182         this.classname = STR_SPECTATOR;
183     }
184     DESTRUCTOR(Spectator) { }
185 ENDCLASS(Spectator)
186
187 CLASS(Player, Client)
188
189     // custom
190
191     ATTRIB(Player, dual_weapons, vector, this.dual_weapons); // TODO: actually WepSet!
192     ATTRIB(Player, itemkeys, int, this.itemkeys);
193     ATTRIB(Player, ballistics_density, float, this.ballistics_density);
194     ATTRIB(Player, prevstrengthsound, float, this.prevstrengthsound);
195     ATTRIB(Player, prevstrengthsoundattempt, float, this.prevstrengthsoundattempt);
196     ATTRIB(Player, buff_shield, float, this.buff_shield);
197
198     INIT(Player) {
199         this.classname = STR_PLAYER;
200         IL_PUSH(g_players, this);
201     }
202     DESTRUCTOR(Player) {
203         IL_REMOVE(g_players, this);
204     }
205 ENDCLASS(Player)
206
207 METHOD(Client, m_unwind, bool(Client this))
208 {
209     TC(Client, this);
210     #define UNWIND(class) MACRO_BEGIN if (this.instanceOf##class) { METHOD_REFERENCE(class, dtorimpl)(this); } MACRO_END
211     switch (this.classname) {
212         case "Observer":
213             UNWIND(Spectator);
214             UNWIND(Player);
215             return true;
216         case "Spectator":
217             UNWIND(Observer);
218             UNWIND(Player);
219             return true;
220         case "Player":
221             UNWIND(Observer);
222             UNWIND(Spectator);
223             return true;
224     }
225     #undef UNWIND
226     return false;
227 }
228
229 bool PlayerInList(entity player, string list);
230
231 /// \brief Print the string to the client's chat.
232 /// \param[in] client Client to print to.
233 /// \param[in] text Text to print.
234 void PrintToChat(entity client, string text);
235
236 /// \brief Print the string to the client's chat if the server cvar "developer"
237 /// is not 0.
238 /// \param[in] client Client to print to.
239 /// \param[in] text Text to print.
240 void DebugPrintToChat(entity client, string text);
241
242 /// \brief Prints the string to all clients' chat.
243 /// \param[in] text Text to print.
244 void PrintToChatAll(string text);
245
246 /// \brief Prints the string to all clients' chat if the server cvar "developer"
247 /// is not 0.
248 /// \param[in] text Text to print.
249 void DebugPrintToChatAll(string text);
250
251 /// \brief Print the string to chat of all clients of the specified team.
252 /// \param[in] team_num Team to print to. See NUM_TEAM constants.
253 /// \param[in] text Text to print.
254 void PrintToChatTeam(int team_num, string text);
255
256 /// \brief Print the string to chat of all clients of the specified team if the
257 /// server cvar "developer" is not 0.
258 /// \param[in] team_num Team to print to. See NUM_TEAM constants.
259 /// \param[in] text Text to print.
260 void DebugPrintToChatTeam(int team_num, string text);
261
262 void play_countdown(entity this, float finished, Sound samp);
263
264 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit);
265
266 bool Spectate(entity this, entity pl);
267
268 void ClientInit_Spawn();
269
270 void PutObserverInServer(entity this);
271
272 void SetSpectatee(entity this, entity spectatee);
273 void SetSpectatee_status(entity this, int spectatee_num);
274
275 void FixPlayermodel(entity player);
276
277 void ClientInit_misc(entity this);
278
279 bool joinAllowed(entity this);
280 void Join(entity this);
281
282 #define SPECTATE_COPY() ACCUMULATE void SpectateCopy(entity this, entity spectatee)
283 #define SPECTATE_COPYFIELD(fld) SPECTATE_COPY() { this.(fld) = spectatee.(fld); }