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