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