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