]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/client.qh
Some more defs.qh cleanup, update gameplay hash
[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 // replicated cvars TODO: needs better organisation!
7 .float cvar_cl_handicap;
8 .int cvar_cl_gunalign;
9 .float cvar_cl_clippedspectating;
10 .float cvar_cl_autoscreenshot;
11 .float cvar_cl_jetpack_jump;
12 .float cvar_cl_movement_track_canjump;
13 .float cvar_cl_newusekeysupported;
14 .float cvar_cl_cts_noautoswitch;
15 .bool cvar_cl_weapon_switch_reload;
16 .bool cvar_cl_weapon_switch_fallback_to_impulse;
17
18 .string cvar_g_xonoticversion;
19 .string cvar_cl_weaponpriority;
20 .string cvar_cl_weaponpriorities[10];
21 .float cvar_cl_noantilag;
22
23 // WEAPONTODO
24 .float autoswitch;
25 .string weaponorder_byimpulse;
26 .float cvar_cl_weaponimpulsemode;
27
28 .float cvar_cl_allow_uid2name;
29 .float cvar_cl_allow_uidtracking;
30 .bool cvar_cl_allow_uidranking;
31
32 .string cvar_cl_physics;
33
34 // autotaunt system
35 .float cvar_cl_autotaunt;
36 .float cvar_cl_voice_directional;
37 .float cvar_cl_voice_directional_taunt_attenuation;
38
39 .entity clientdata;
40
41 .float jointime; // time of connecting
42 .float startplaytime; // time of switching from spectator to player
43 .float alivetime; // time of being alive
44 .float motd_actived_time; // used for both motd and campaign_message
45
46 void ClientState_attach(entity this);
47
48 IntrusiveList g_players;
49 STATIC_INIT(g_players) { g_players = IL_NEW(); }
50
51 CLASS(Client, Object)
52     /** Client name */
53     ATTRIB(Client, netname, string, this.netname);
54     ATTRIB(Client, colormap, int, this.colormap);
55     ATTRIB(Client, team, int, this.team);
56     ATTRIB(Client, clientcolors, int, this.clientcolors);
57     /** Client IP */
58     ATTRIB(Client, netaddress, string, this.netaddress);
59     ATTRIB(Client, playermodel, string, this.playermodel);
60     ATTRIB(Client, playerskin, string, this.playerskin);
61
62     /** fingerprint of CA key the player used to authenticate */
63     ATTRIB(Client, crypto_keyfp, string, this.crypto_keyfp);
64     /** fingerprint of CA key the server used to authenticate to the player */
65     ATTRIB(Client, crypto_mykeyfp, string, this.crypto_mykeyfp);
66     /** fingerprint of ID used by the player entity, or string_null if not identified */
67     ATTRIB(Client, crypto_idfp, string, this.crypto_idfp);
68     /** set if the player's ID has been signed */
69     ATTRIB(Client, crypto_idfp_signed, bool, this.crypto_idfp_signed);
70     /** the string "AES128" if encrypting, and string_null if plaintext */
71     ATTRIB(Client, crypto_encryptmethod, string, this.crypto_encryptmethod);
72     /** the string "HMAC-SHA256" if signing, and string_null if plaintext */
73     ATTRIB(Client, crypto_signmethod, string, this.crypto_signmethod);
74
75     // engine client fields
76     ATTRIB(Client, impulse, int, this.impulse);
77
78     ATTRIB(Client, button0, int, this.button0);
79     ATTRIB(Client, button2, int, this.button2);
80     ATTRIB(Client, button3, int, this.button3);
81     ATTRIB(Client, button4, int, this.button4);
82     ATTRIB(Client, button5, int, this.button5);
83     ATTRIB(Client, button6, int, this.button6);
84     ATTRIB(Client, button7, int, this.button7);
85     ATTRIB(Client, button8, int, this.button8);
86     ATTRIB(Client, button9, int, this.button9);
87     ATTRIB(Client, button10, int, this.button10);
88     ATTRIB(Client, button11, int, this.button11);
89     ATTRIB(Client, button12, int, this.button12);
90     ATTRIB(Client, button13, int, this.button13);
91     ATTRIB(Client, button14, int, this.button14);
92     ATTRIB(Client, button15, int, this.button15);
93     ATTRIB(Client, button16, int, this.button16);
94     ATTRIB(Client, buttonuse, int, this.buttonuse);
95     ATTRIB(Client, buttonchat, int, this.buttonchat);
96
97     ATTRIB(Client, cursor_active, int, this.cursor_active);
98     ATTRIB(Client, cursor_screen, vector, this.cursor_screen);
99     ATTRIB(Client, cursor_trace_start, vector, this.cursor_trace_start);
100     ATTRIB(Client, cursor_trace_endpos, vector, this.cursor_trace_endpos);
101     ATTRIB(Client, cursor_trace_ent, entity, this.cursor_trace_ent);
102
103     ATTRIB(Client, ping, float, this.ping);
104     ATTRIB(Client, ping_packetloss, float, this.ping_packetloss);
105     ATTRIB(Client, ping_movementloss, float, this.ping_movementloss);
106
107     ATTRIB(Client, v_angle, vector, this.v_angle);
108     ATTRIB(Client, movement, vector, this.movement);
109
110     // custom
111
112     ATTRIB(Client, playerid, int, this.playerid);
113
114     ATTRIB(Client, parm_idlesince, int, this.parm_idlesince);
115     ATTRIB(Client, muted, bool, this.muted);
116     ATTRIB(Client, idlekick_lasttimeleft, float, this.idlekick_lasttimeleft);
117     ATTRIB(Client, pm_frametime, float, this.pm_frametime);
118     ATTRIB(Client, pressedkeys, int, this.pressedkeys);
119     ATTRIB(Client, movement_old, vector, this.movement_old);
120     ATTRIB(Client, buttons_old, int, this.buttons_old);
121     ATTRIB(Client, teamkill_complain, float, this.teamkill_complain);
122     ATTRIB(Client, teamkill_soundtime, float, this.teamkill_soundtime);
123     ATTRIB(Client, teamkill_soundsource, entity, this.teamkill_soundsource);
124     ATTRIB(Client, usekeypressed, bool, this.usekeypressed);
125     ATTRIB(Client, motd_actived_time, float, this.motd_actived_time);
126     ATTRIB(Client, jointime, float, this.jointime);
127     ATTRIB(Client, spectatortime, float, this.spectatortime);
128     ATTRIB(Client, startplaytime, float, this.startplaytime);
129     ATTRIB(Client, version_nagtime, float, this.version_nagtime);
130     ATTRIB(Client, netname_previous, string, this.netname_previous);
131     ATTRIB(Client, allowed_timeouts, int, this.allowed_timeouts);
132     ATTRIB(Client, active_minigame, entity, this.active_minigame);
133     ATTRIB(Client, taunt_soundtime, float, this.taunt_soundtime);
134     ATTRIB(Client, killcount, int, this.killcount);
135     ATTRIB(Client, version_mismatch, bool, this.version_mismatch);
136     ATTRIB(Client, version, int, this.version);
137     ATTRIB(Client, spectatee_status, int, this.spectatee_status);
138     ATTRIB(Client, zoomstate, bool, this.zoomstate);
139     ATTRIB(Client, just_joined, bool, this.just_joined);
140     ATTRIB(Client, race_completed, bool, this.race_completed);
141     ATTRIBARRAY(Client, msg_choice_choices, int, 20); // TODO: actually NOTIF_CHOICE_MAX
142     ATTRIB(Client, latency_sum, float, this.latency_sum);
143     ATTRIB(Client, latency_cnt, int, this.latency_cnt);
144     ATTRIB(Client, latency_time, float, this.latency_time);
145     ATTRIB(Client, v_angle_old, vector, this.v_angle_old);
146     ATTRIB(Client, model_randomizer, float, this.model_randomizer);
147     ATTRIB(Client, accuracy, entity, this.accuracy);
148     ATTRIB(Client, hasweapon_complain_spam, float, this.hasweapon_complain_spam);
149     ATTRIB(Client, scorekeeper, entity, this.scorekeeper);
150     ATTRIB(Client, specialcommand_pos, int, this.specialcommand_pos);
151     ATTRIB(Client, hitplotfh, int, this.hitplotfh);
152     ATTRIB(Client, clientdata, entity, this.clientdata);
153     ATTRIB(Client, cmd_floodcount, int, this.cmd_floodcount);
154     ATTRIB(Client, cmd_floodtime, float, this.cmd_floodtime);
155     ATTRIB(Client, wasplayer, bool, this.wasplayer);
156     ATTRIB(Client, weaponorder_byimpulse, string, this.weaponorder_byimpulse);
157     ATTRIB(Client, autojoin_checked, int, this.wasplayer);
158
159     // networked cvars
160
161     ATTRIB(Client, cvar_cl_allow_uid2name, int, this.cvar_cl_allow_uid2name);
162     ATTRIB(Client, cvar_cl_allow_uidtracking, int, this.cvar_cl_allow_uidtracking);
163     ATTRIB(Client, cvar_cl_autotaunt, float, this.cvar_cl_autotaunt);
164     ATTRIB(Client, cvar_cl_voice_directional, int, this.cvar_cl_voice_directional);
165     ATTRIB(Client, cvar_cl_voice_directional_taunt_attenuation, float, this.cvar_cl_voice_directional_taunt_attenuation);
166     ATTRIB(Client, cvar_cl_physics, string, this.cvar_cl_physics);
167     ATTRIB(Client, cvar_cl_buffs_autoreplace, bool, this.cvar_cl_buffs_autoreplace);
168     ATTRIB(Client, cvar_cl_nade_type, int, this.cvar_cl_nade_type);
169     ATTRIB(Client, cvar_cl_pokenade_type, string, this.cvar_cl_pokenade_type);
170     ATTRIB(Client, cvar_cl_spawn_near_teammate, bool, this.cvar_cl_spawn_near_teammate);
171     ATTRIB(Client, cvar_cl_gunalign, int, this.cvar_cl_gunalign);
172     ATTRIB(Client, cvar_cl_handicap, float, this.cvar_cl_handicap);
173     ATTRIB(Client, cvar_cl_clippedspectating, bool, this.cvar_cl_clippedspectating);
174     ATTRIB(Client, cvar_cl_autoscreenshot, int, this.cvar_cl_autoscreenshot);
175     ATTRIB(Client, cvar_cl_jetpack_jump, bool, this.cvar_cl_jetpack_jump);
176     ATTRIB(Client, cvar_cl_newusekeysupported, bool, this.cvar_cl_newusekeysupported);
177     ATTRIB(Client, cvar_cl_noantilag, bool, this.cvar_cl_noantilag);
178     ATTRIB(Client, cvar_cl_movement_track_canjump, bool, this.cvar_cl_movement_track_canjump);
179     ATTRIB(Client, cvar_cl_weaponimpulsemode, int, this.cvar_cl_weaponimpulsemode);
180     ATTRIB(Client, cvar_g_xonoticversion, string, this.cvar_g_xonoticversion);
181     ATTRIB(Client, autoswitch, bool, this.autoswitch);
182     ATTRIB(Client, cvar_cl_casings, bool, this.cvar_cl_casings);
183     ATTRIB(Client, cvar_cl_dodging_timeout, float, this.cvar_cl_dodging_timeout);
184     ATTRIB(Client, cvar_cl_dodging, float, this.cvar_cl_dodging);
185     ATTRIB(Client, cvar_cl_multijump, bool, this.cvar_cl_multijump);
186     ATTRIB(Client, cvar_cl_accuracy_data_share, bool, this.cvar_cl_accuracy_data_share);
187     ATTRIB(Client, cvar_cl_accuracy_data_receive, bool, this.cvar_cl_accuracy_data_receive);
188     ATTRIBARRAY(Client, cvar_cl_weaponpriorities, string, 10);
189     ATTRIB(Client, cvar_cl_weaponpriority, string, this.cvar_cl_weaponpriority);
190     ATTRIB(Client, cvar_cl_cts_noautoswitch, bool, this.cvar_cl_cts_noautoswitch);
191     ATTRIB(Client, cvar_cl_weapon_switch_reload, bool, this.cvar_cl_weapon_switch_reload);
192     ATTRIB(Client, cvar_cl_weapon_switch_fallback_to_impulse, bool, this.cvar_cl_weapon_switch_fallback_to_impulse);
193
194     METHOD(Client, m_unwind, bool(Client this));
195
196     STATIC_METHOD(Client, Add, void(Client this, int _team));
197     STATIC_METHOD(Client, Remove, void(Client this));
198
199     INIT(Client) {
200         if (this.m_unwind(this)) return this;
201         make_impure(this);
202         this.classname = "player_joining";
203         static int playerid_last;
204         this.playerid = ++playerid_last;
205         ClientState_attach(this);
206     }
207     DESTRUCTOR(Client) {
208         Client_Remove(this);
209     }
210     CONSTRUCTOR(Client, string name) {
211         CONSTRUCT(Client);
212         this.netname = name;
213         this.netaddress = "local";
214         this.playermodel = cvar_defstring("sv_defaultplayermodel");
215     }
216 ENDCLASS(Client)
217
218 CLASS(Observer, Client)
219     INIT(Observer) {
220         this.classname = STR_OBSERVER;
221     }
222     DESTRUCTOR(Observer) { }
223 ENDCLASS(Observer)
224
225 CLASS(Spectator, Client)
226     INIT(Spectator) {
227         this.classname = STR_SPECTATOR;
228     }
229     DESTRUCTOR(Spectator) { }
230 ENDCLASS(Spectator)
231
232 CLASS(Player, Client)
233
234     // custom
235
236     ATTRIB(Player, dual_weapons, vector, this.dual_weapons); // TODO: actually WepSet!
237     ATTRIB(Player, itemkeys, int, this.itemkeys);
238     ATTRIB(Player, ballistics_density, float, this.ballistics_density);
239     ATTRIB(Player, prevstrengthsound, float, this.prevstrengthsound);
240     ATTRIB(Player, prevstrengthsoundattempt, float, this.prevstrengthsoundattempt);
241     ATTRIB(Player, buff_shield, float, this.buff_shield);
242
243     INIT(Player) {
244         this.classname = STR_PLAYER;
245         IL_PUSH(g_players, this);
246     }
247     DESTRUCTOR(Player) {
248         IL_REMOVE(g_players, this);
249     }
250 ENDCLASS(Player)
251
252 METHOD(Client, m_unwind, bool(Client this))
253 {
254     TC(Client, this);
255     #define UNWIND(class) MACRO_BEGIN if (this.instanceOf##class) { METHOD_REFERENCE(class, dtorimpl)(this); } MACRO_END
256     switch (this.classname) {
257         case "Observer":
258             UNWIND(Spectator);
259             UNWIND(Player);
260             return true;
261         case "Spectator":
262             UNWIND(Observer);
263             UNWIND(Player);
264             return true;
265         case "Player":
266             UNWIND(Observer);
267             UNWIND(Spectator);
268             return true;
269     }
270     #undef UNWIND
271     return false;
272 }
273
274 //flood fields
275 .float nickspamtime; // time of last nick change
276 .float nickspamcount;
277 .float floodcontrol_chat;
278 .float floodcontrol_chatteam;
279 .float floodcontrol_chattell;
280 .float floodcontrol_voice;
281 .float floodcontrol_voiceteam;
282
283 // respawning
284 .int respawn_flags;
285 .float respawn_time;
286 .float respawn_time_max;
287
288 .float respawn_countdown; // next number to count
289
290 float blockSpectators; // if set, new or existing spectators or observers will be removed unless they become a player within g_maxplayers_spectator_blocktime seconds
291 .float spectatortime; // point in time since the client is spectating or observing
292
293 // TODO: standardise resource regeneration
294 .float pauseregen_finished;
295 .float pauserothealth_finished;
296 .float pauserotarmor_finished;
297 .float pauserotfuel_finished;
298
299 // idle kicking
300 float sv_maxidle;
301 float sv_maxidle_spectatorsareidle;
302 int sv_maxidle_slots;
303 bool sv_maxidle_slots_countbots;
304
305 // g_<gametype>_str:
306 // If 0, default is used.
307 // If <0, 0 is used.
308 // Otherwise, g_str (default value) is used.
309 // For consistency, negative values there are mapped to zero too.
310 #define GAMETYPE_DEFAULTED_SETTING(str) \
311     ((gametype_setting_tmp = cvar(strcat("g_", GetGametype(), "_" #str))), \
312     (gametype_setting_tmp < 0) ? 0 \
313     : (gametype_setting_tmp == 0 || autocvar_g_respawn_delay_forced) ? max(0, autocvar_g_##str) \
314     : gametype_setting_tmp)
315
316 void calculate_player_respawn_time(entity this);
317
318 bool PlayerInList(entity player, string list);
319
320 void ClientData_Touch(entity e);
321
322 int nJoinAllowed(entity this, entity ignore);
323
324 void FixIntermissionClient(entity e);
325
326 void checkSpectatorBlock(entity this);
327
328 void PlayerUseKey(entity this);
329
330 void FixClientCvars(entity e);
331
332 // called when a client connects, useful for updating sounds and such of static objects
333 .void(entity this, entity player) init_for_player;
334
335 /// \brief Print the string to the client's chat.
336 /// \param[in] client Client to print to.
337 /// \param[in] text Text to print.
338 void PrintToChat(entity client, string text);
339
340 /// \brief Print the string to the client's chat if the server cvar "developer"
341 /// is not 0.
342 /// \param[in] client Client to print to.
343 /// \param[in] text Text to print.
344 void DebugPrintToChat(entity client, string text);
345
346 /// \brief Prints the string to all clients' chat.
347 /// \param[in] text Text to print.
348 void PrintToChatAll(string text);
349
350 /// \brief Prints the string to all clients' chat if the server cvar "developer"
351 /// is not 0.
352 /// \param[in] text Text to print.
353 void DebugPrintToChatAll(string text);
354
355 /// \brief Print the string to chat of all clients of the specified team.
356 /// \param[in] team_num Team to print to. See NUM_TEAM constants.
357 /// \param[in] text Text to print.
358 void PrintToChatTeam(int team_num, string text);
359
360 /// \brief Print the string to chat of all clients of the specified team if the
361 /// server cvar "developer" is not 0.
362 /// \param[in] team_num Team to print to. See NUM_TEAM constants.
363 /// \param[in] text Text to print.
364 void DebugPrintToChatTeam(int team_num, string text);
365
366 void play_countdown(entity this, float finished, Sound samp);
367
368 void RotRegen(entity this, float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit_mod);
369
370 bool Spectate(entity this, entity pl);
371
372 void ClientInit_Spawn();
373
374 void PutObserverInServer(entity this);
375
376 void SetSpectatee(entity this, entity spectatee);
377 void SetSpectatee_status(entity this, int spectatee_num);
378
379 void FixPlayermodel(entity player);
380
381 void ClientInit_misc(entity this);
382
383 int GetPlayerLimit();
384
385 const int MIN_SPEC_TIME = 1;
386 bool joinAllowed(entity this);
387 void Join(entity this);
388
389 #define SPECTATE_COPY() ACCUMULATE void SpectateCopy(entity this, entity spectatee)
390 #define SPECTATE_COPYFIELD(fld) SPECTATE_COPY() { this.(fld) = spectatee.(fld); }
391
392 int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodcontrol);