4 #include <common/replicate.qh>
5 #include <common/sounds/all.qh>
8 .string weaponorder_byimpulse;
12 .float jointime; // time of connecting
13 .float startplaytime; // time of switching from spectator to player
14 .float alivetime; // time of being alive
15 .float motd_actived_time; // used for both motd and campaign_message
19 .int spectatee_status;
31 void ClientState_attach(entity this);
33 IntrusiveList g_players;
34 STATIC_INIT(g_players) { g_players = IL_NEW(); }
38 ATTRIB(Client, netname, string, this.netname);
39 ATTRIB(Client, colormap, int, this.colormap);
40 ATTRIB(Client, team, int, this.team);
41 ATTRIB(Client, clientcolors, int, this.clientcolors);
43 ATTRIB(Client, netaddress, string, this.netaddress);
44 ATTRIB(Client, playermodel, string, this.playermodel);
45 ATTRIB(Client, playerskin, string, this.playerskin);
47 /** fingerprint of CA key the player used to authenticate */
48 ATTRIB(Client, crypto_keyfp, string, this.crypto_keyfp);
49 /** fingerprint of CA key the server used to authenticate to the player */
50 ATTRIB(Client, crypto_mykeyfp, string, this.crypto_mykeyfp);
51 /** fingerprint of ID used by the player entity, or string_null if not identified */
52 ATTRIB(Client, crypto_idfp, string, this.crypto_idfp);
53 /** set if the player's ID has been signed */
54 ATTRIB(Client, crypto_idfp_signed, bool, this.crypto_idfp_signed);
55 /** the string "AES128" if encrypting, and string_null if plaintext */
56 ATTRIB(Client, crypto_encryptmethod, string, this.crypto_encryptmethod);
57 /** the string "HMAC-SHA256" if signing, and string_null if plaintext */
58 ATTRIB(Client, crypto_signmethod, string, this.crypto_signmethod);
60 // engine client fields
61 ATTRIB(Client, impulse, int, this.impulse);
63 ATTRIB(Client, button0, int, this.button0);
64 ATTRIB(Client, button2, int, this.button2);
65 ATTRIB(Client, button3, int, this.button3);
66 ATTRIB(Client, button4, int, this.button4);
67 ATTRIB(Client, button5, int, this.button5);
68 ATTRIB(Client, button6, int, this.button6);
69 ATTRIB(Client, button7, int, this.button7);
70 ATTRIB(Client, button8, int, this.button8);
71 ATTRIB(Client, button9, int, this.button9);
72 ATTRIB(Client, button10, int, this.button10);
73 ATTRIB(Client, button11, int, this.button11);
74 ATTRIB(Client, button12, int, this.button12);
75 ATTRIB(Client, button13, int, this.button13);
76 ATTRIB(Client, button14, int, this.button14);
77 ATTRIB(Client, button15, int, this.button15);
78 ATTRIB(Client, button16, int, this.button16);
79 ATTRIB(Client, buttonuse, int, this.buttonuse);
80 ATTRIB(Client, buttonchat, int, this.buttonchat);
82 ATTRIB(Client, cursor_active, int, this.cursor_active);
83 ATTRIB(Client, cursor_screen, vector, this.cursor_screen);
84 ATTRIB(Client, cursor_trace_start, vector, this.cursor_trace_start);
85 ATTRIB(Client, cursor_trace_endpos, vector, this.cursor_trace_endpos);
86 ATTRIB(Client, cursor_trace_ent, entity, this.cursor_trace_ent);
88 ATTRIB(Client, ping, float, this.ping);
89 ATTRIB(Client, ping_packetloss, float, this.ping_packetloss);
90 ATTRIB(Client, ping_movementloss, float, this.ping_movementloss);
92 ATTRIB(Client, v_angle, vector, this.v_angle);
93 ATTRIB(Client, movement, vector, this.movement);
97 ATTRIB(Client, playerid, int, this.playerid);
99 ATTRIB(Client, parm_idlesince, int, this.parm_idlesince);
100 ATTRIB(Client, muted, bool, this.muted);
101 ATTRIB(Client, idlekick_lasttimeleft, float, this.idlekick_lasttimeleft);
102 ATTRIB(Client, pm_frametime, float, this.pm_frametime);
103 ATTRIB(Client, pressedkeys, int, this.pressedkeys);
104 ATTRIB(Client, movement_old, vector, this.movement_old);
105 ATTRIB(Client, buttons_old, int, this.buttons_old);
106 ATTRIB(Client, teamkill_complain, float, this.teamkill_complain);
107 ATTRIB(Client, teamkill_soundtime, float, this.teamkill_soundtime);
108 ATTRIB(Client, teamkill_soundsource, entity, this.teamkill_soundsource);
109 ATTRIB(Client, usekeypressed, bool, this.usekeypressed);
110 ATTRIB(Client, motd_actived_time, float, this.motd_actived_time);
111 ATTRIB(Client, jointime, float, this.jointime);
112 ATTRIB(Client, spectatortime, float, this.spectatortime);
113 ATTRIB(Client, startplaytime, float, this.startplaytime);
114 ATTRIB(Client, version_nagtime, float, this.version_nagtime);
115 ATTRIB(Client, netname_previous, string, this.netname_previous);
116 ATTRIB(Client, allowed_timeouts, int, this.allowed_timeouts);
117 ATTRIB(Client, active_minigame, entity, this.active_minigame);
118 ATTRIB(Client, taunt_soundtime, float, this.taunt_soundtime);
119 ATTRIB(Client, killcount, int, this.killcount);
120 ATTRIB(Client, version_mismatch, bool, this.version_mismatch);
121 ATTRIB(Client, version, int, this.version);
122 ATTRIB(Client, spectatee_status, int, this.spectatee_status);
123 ATTRIB(Client, zoomstate, bool, this.zoomstate);
124 ATTRIB(Client, just_joined, bool, this.just_joined);
125 ATTRIB(Client, race_completed, bool, this.race_completed);
126 ATTRIBARRAY(Client, msg_choice_choices, int, 20); // TODO: actually NOTIF_CHOICE_MAX
127 ATTRIB(Client, latency_sum, float, this.latency_sum);
128 ATTRIB(Client, latency_cnt, int, this.latency_cnt);
129 ATTRIB(Client, latency_time, float, this.latency_time);
130 ATTRIB(Client, v_angle_old, vector, this.v_angle_old);
131 ATTRIB(Client, model_randomizer, float, this.model_randomizer);
132 ATTRIB(Client, accuracy, entity, this.accuracy);
133 ATTRIB(Client, hasweapon_complain_spam, float, this.hasweapon_complain_spam);
134 ATTRIB(Client, scorekeeper, entity, this.scorekeeper);
135 ATTRIB(Client, specialcommand_pos, int, this.specialcommand_pos);
136 ATTRIB(Client, hitplotfh, int, this.hitplotfh);
137 ATTRIB(Client, clientdata, entity, this.clientdata);
138 ATTRIB(Client, cmd_floodcount, int, this.cmd_floodcount);
139 ATTRIB(Client, cmd_floodtime, float, this.cmd_floodtime);
140 ATTRIB(Client, wasplayer, bool, this.wasplayer);
141 ATTRIB(Client, weaponorder_byimpulse, string, this.weaponorder_byimpulse);
142 ATTRIB(Client, autojoin_checked, int, this.wasplayer);
146 ATTRIB(Client, cvar_cl_allow_uid2name, int, this.cvar_cl_allow_uid2name);
147 ATTRIB(Client, cvar_cl_allow_uidtracking, int, this.cvar_cl_allow_uidtracking);
148 ATTRIB(Client, cvar_cl_autotaunt, float, this.cvar_cl_autotaunt);
149 ATTRIB(Client, cvar_cl_voice_directional, int, this.cvar_cl_voice_directional);
150 ATTRIB(Client, cvar_cl_voice_directional_taunt_attenuation, float, this.cvar_cl_voice_directional_taunt_attenuation);
151 ATTRIB(Client, cvar_cl_physics, string, this.cvar_cl_physics);
152 ATTRIB(Client, cvar_cl_buffs_autoreplace, bool, this.cvar_cl_buffs_autoreplace);
153 ATTRIB(Client, cvar_cl_nade_type, int, this.cvar_cl_nade_type);
154 ATTRIB(Client, cvar_cl_pokenade_type, string, this.cvar_cl_pokenade_type);
155 ATTRIB(Client, cvar_cl_spawn_near_teammate, bool, this.cvar_cl_spawn_near_teammate);
156 ATTRIB(Client, cvar_cl_gunalign, int, this.cvar_cl_gunalign);
157 ATTRIB(Client, cvar_cl_handicap, float, this.cvar_cl_handicap);
158 ATTRIB(Client, cvar_cl_clippedspectating, bool, this.cvar_cl_clippedspectating);
159 ATTRIB(Client, cvar_cl_autoscreenshot, int, this.cvar_cl_autoscreenshot);
160 ATTRIB(Client, cvar_cl_jetpack_jump, bool, this.cvar_cl_jetpack_jump);
161 ATTRIB(Client, cvar_cl_newusekeysupported, bool, this.cvar_cl_newusekeysupported);
162 ATTRIB(Client, cvar_cl_noantilag, bool, this.cvar_cl_noantilag);
163 ATTRIB(Client, cvar_cl_movement_track_canjump, bool, this.cvar_cl_movement_track_canjump);
164 ATTRIB(Client, cvar_cl_weaponimpulsemode, int, this.cvar_cl_weaponimpulsemode);
165 ATTRIB(Client, cvar_g_xonoticversion, string, this.cvar_g_xonoticversion);
166 ATTRIB(Client, autoswitch, bool, this.autoswitch);
167 ATTRIB(Client, cvar_cl_casings, bool, this.cvar_cl_casings);
168 ATTRIB(Client, cvar_cl_dodging_timeout, float, this.cvar_cl_dodging_timeout);
169 ATTRIB(Client, cvar_cl_dodging, float, this.cvar_cl_dodging);
170 ATTRIB(Client, cvar_cl_multijump, bool, this.cvar_cl_multijump);
171 ATTRIB(Client, cvar_cl_accuracy_data_share, bool, this.cvar_cl_accuracy_data_share);
172 ATTRIB(Client, cvar_cl_accuracy_data_receive, bool, this.cvar_cl_accuracy_data_receive);
173 ATTRIBARRAY(Client, cvar_cl_weaponpriorities, string, 10);
174 ATTRIB(Client, cvar_cl_weaponpriority, string, this.cvar_cl_weaponpriority);
175 ATTRIB(Client, cvar_cl_cts_noautoswitch, bool, this.cvar_cl_cts_noautoswitch);
176 ATTRIB(Client, cvar_cl_weapon_switch_reload, bool, this.cvar_cl_weapon_switch_reload);
177 ATTRIB(Client, cvar_cl_weapon_switch_fallback_to_impulse, bool, this.cvar_cl_weapon_switch_fallback_to_impulse);
179 METHOD(Client, m_unwind, bool(Client this));
181 STATIC_METHOD(Client, Add, void(Client this, int _team));
182 STATIC_METHOD(Client, Remove, void(Client this));
185 if (this.m_unwind(this)) return this;
187 this.classname = "player_joining";
188 static int playerid_last;
189 this.playerid = ++playerid_last;
190 ClientState_attach(this);
195 CONSTRUCTOR(Client, string name) {
198 this.netaddress = "local";
199 this.playermodel = cvar_defstring("sv_defaultplayermodel");
203 CLASS(Observer, Client)
205 this.classname = STR_OBSERVER;
207 DESTRUCTOR(Observer) { }
210 CLASS(Spectator, Client)
212 this.classname = STR_SPECTATOR;
214 DESTRUCTOR(Spectator) { }
217 CLASS(Player, Client)
221 ATTRIB(Player, dual_weapons, vector, this.dual_weapons); // TODO: actually WepSet!
222 ATTRIB(Player, itemkeys, int, this.itemkeys);
223 ATTRIB(Player, ballistics_density, float, this.ballistics_density);
224 ATTRIB(Player, prevstrengthsound, float, this.prevstrengthsound);
225 ATTRIB(Player, prevstrengthsoundattempt, float, this.prevstrengthsoundattempt);
226 ATTRIB(Player, buff_shield, float, this.buff_shield);
229 this.classname = STR_PLAYER;
230 IL_PUSH(g_players, this);
233 IL_REMOVE(g_players, this);
237 METHOD(Client, m_unwind, bool(Client this))
240 #define UNWIND(class) MACRO_BEGIN if (this.instanceOf##class) { METHOD_REFERENCE(class, dtorimpl)(this); } MACRO_END
241 switch (this.classname) {
259 int autocvar__independent_players;
260 bool independent_players;
261 #define INDEPENDENT_PLAYERS (autocvar__independent_players ? (autocvar__independent_players > 0) : independent_players)
262 #define IS_INDEPENDENT_PLAYER(e) ((e).solid == SOLID_TRIGGER)
263 #define MAKE_INDEPENDENT_PLAYER(e) (((e).solid = SOLID_TRIGGER), ((e).frags = FRAGS_PLAYER_OUT_OF_GAME))
268 .float nickspamtime; // time of last nick change
269 .float nickspamcount;
270 .float floodcontrol_chat;
271 .float floodcontrol_chatteam;
272 .float floodcontrol_chattell;
273 .float floodcontrol_voice;
274 .float floodcontrol_voiceteam;
279 .float respawn_time_max;
281 .float respawn_countdown; // next number to count
283 const int RESPAWN_FORCE = BIT(0);
284 const int RESPAWN_SILENT = BIT(1);
285 const int RESPAWN_DENY = BIT(2);
287 float blockSpectators; // if set, new or existing spectators or observers will be removed unless they become a player within g_maxplayers_spectator_blocktime seconds
288 .float spectatortime; // point in time since the client is spectating or observing
290 .bool player_blocked;
292 const int SVC_SETVIEW = 5; // TODO: move to dpdefs where this belongs!
294 // TODO: standardise resource regeneration
295 .float pauseregen_finished;
296 .float pauserothealth_finished;
297 .float pauserotarmor_finished;
298 .float pauserotfuel_finished;
302 float sv_maxidle_spectatorsareidle;
303 int sv_maxidle_slots;
304 bool sv_maxidle_slots_countbots;
307 // If 0, default is used.
309 // Otherwise, g_str (default value) is used.
310 // For consistency, negative values there are mapped to zero too.
311 #define GAMETYPE_DEFAULTED_SETTING(str) \
312 ((gametype_setting_tmp = cvar(strcat("g_", GetGametype(), "_" #str))), \
313 (gametype_setting_tmp < 0) ? 0 \
314 : (gametype_setting_tmp == 0 || autocvar_g_respawn_delay_forced) ? max(0, autocvar_g_##str) \
315 : gametype_setting_tmp)
317 void calculate_player_respawn_time(entity this);
319 bool PlayerInList(entity player, string list);
321 void ClientData_Touch(entity e);
323 int nJoinAllowed(entity this, entity ignore);
325 void FixIntermissionClient(entity e);
327 void checkSpectatorBlock(entity this);
329 void PlayerUseKey(entity this);
331 void FixClientCvars(entity e);
333 // called when a client connects, useful for updating sounds and such of static objects
334 .void(entity this, entity player) init_for_player;
336 IntrusiveList g_initforplayer;
337 STATIC_INIT(g_initforplayer) { g_initforplayer = IL_NEW(); }
339 /// \brief Print the string to the client's chat.
340 /// \param[in] client Client to print to.
341 /// \param[in] text Text to print.
342 void PrintToChat(entity client, string text);
344 /// \brief Print the string to the client's chat if the server cvar "developer"
346 /// \param[in] client Client to print to.
347 /// \param[in] text Text to print.
348 void DebugPrintToChat(entity client, string text);
350 /// \brief Prints the string to all clients' chat.
351 /// \param[in] text Text to print.
352 void PrintToChatAll(string text);
354 /// \brief Prints the string to all clients' chat if the server cvar "developer"
356 /// \param[in] text Text to print.
357 void DebugPrintToChatAll(string text);
359 /// \brief Print the string to chat of all clients of the specified team.
360 /// \param[in] team_num Team to print to. See NUM_TEAM constants.
361 /// \param[in] text Text to print.
362 void PrintToChatTeam(int team_num, string text);
364 /// \brief Print the string to chat of all clients of the specified team if the
365 /// server cvar "developer" is not 0.
366 /// \param[in] team_num Team to print to. See NUM_TEAM constants.
367 /// \param[in] text Text to print.
368 void DebugPrintToChatTeam(int team_num, string text);
370 void play_countdown(entity this, float finished, Sound samp);
372 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);
374 bool Spectate(entity this, entity pl);
376 void ClientInit_Spawn();
378 void PutObserverInServer(entity this);
380 void SetSpectatee(entity this, entity spectatee);
381 void SetSpectatee_status(entity this, int spectatee_num);
383 void FixPlayermodel(entity player);
385 void ClientInit_misc(entity this);
387 int GetPlayerLimit();
389 const int MIN_SPEC_TIME = 1;
390 bool joinAllowed(entity this);
391 void Join(entity this);
393 #define SPECTATE_COPY() ACCUMULATE void SpectateCopy(entity this, entity spectatee)
394 #define SPECTATE_COPYFIELD(fld) SPECTATE_COPY() { this.(fld) = spectatee.(fld); }
396 int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodcontrol);
398 const int MAX_SPECTATORS = 7;