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