4 #include <common/sounds/all.qh>
6 void ClientState_attach(entity this);
8 IntrusiveList g_players;
9 STATIC_INIT(g_players) { g_players = IL_NEW(); }
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);
18 ATTRIB(Client, netaddress, string, this.netaddress);
19 ATTRIB(Client, playermodel, string, this.playermodel);
20 ATTRIB(Client, playerskin, string, this.playerskin);
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);
35 // engine client fields
36 ATTRIB(Client, impulse, int, this.impulse);
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);
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);
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);
67 ATTRIB(Client, v_angle, vector, this.v_angle);
68 ATTRIB(Client, movement, vector, this.movement);
72 ATTRIB(Client, playerid, int, this.playerid);
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);
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);
154 METHOD(Client, m_unwind, bool(Client this));
156 STATIC_METHOD(Client, Add, void(Client this, int _team));
157 STATIC_METHOD(Client, Remove, void(Client this));
160 if (this.m_unwind(this)) return this;
162 this.classname = "player_joining";
163 static int playerid_last;
164 this.playerid = ++playerid_last;
165 ClientState_attach(this);
170 CONSTRUCTOR(Client, string name) {
173 this.netaddress = "local";
174 this.playermodel = cvar_defstring("sv_defaultplayermodel");
178 CLASS(Observer, Client)
180 this.classname = STR_OBSERVER;
182 DESTRUCTOR(Observer) { }
185 CLASS(Spectator, Client)
187 this.classname = STR_SPECTATOR;
189 DESTRUCTOR(Spectator) { }
192 CLASS(Player, Client)
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);
204 this.classname = STR_PLAYER;
205 IL_PUSH(g_players, this);
208 IL_REMOVE(g_players, this);
212 METHOD(Client, m_unwind, bool(Client this))
215 #define UNWIND(class) MACRO_BEGIN if (this.instanceOf##class) { METHOD_REFERENCE(class, dtorimpl)(this); } MACRO_END
216 switch (this.classname) {
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;
246 .float respawn_time_max;
248 .float respawn_countdown; // next number to count
251 // If 0, default 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)
261 void calculate_player_respawn_time(entity this);
263 bool PlayerInList(entity player, string list);
265 void ClientData_Touch(entity e);
267 int nJoinAllowed(entity this, entity ignore);
269 void FixIntermissionClient(entity e);
271 void checkSpectatorBlock(entity this);
273 void PlayerUseKey(entity this);
275 void FixClientCvars(entity e);
277 // called when a client connects, useful for updating sounds and such of static objects
278 .void(entity this, entity player) init_for_player;
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);
285 /// \brief Print the string to the client's chat if the server cvar "developer"
287 /// \param[in] client Client to print to.
288 /// \param[in] text Text to print.
289 void DebugPrintToChat(entity client, string text);
291 /// \brief Prints the string to all clients' chat.
292 /// \param[in] text Text to print.
293 void PrintToChatAll(string text);
295 /// \brief Prints the string to all clients' chat if the server cvar "developer"
297 /// \param[in] text Text to print.
298 void DebugPrintToChatAll(string text);
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);
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);
311 void play_countdown(entity this, float finished, Sound samp);
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);
315 bool Spectate(entity this, entity pl);
317 void ClientInit_Spawn();
319 void PutObserverInServer(entity this);
321 void SetSpectatee(entity this, entity spectatee);
322 void SetSpectatee_status(entity this, int spectatee_num);
324 void FixPlayermodel(entity player);
326 void ClientInit_misc(entity this);
328 int GetPlayerLimit();
330 const int MIN_SPEC_TIME = 1;
331 bool joinAllowed(entity this);
332 void Join(entity this);
334 #define SPECTATE_COPY() ACCUMULATE void SpectateCopy(entity this, entity spectatee)
335 #define SPECTATE_COPYFIELD(fld) SPECTATE_COPY() { this.(fld) = spectatee.(fld); }
337 int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodcontrol);