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