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