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