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