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