]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/client.qh
Merge branch 'master' into martin-t/rulesets
[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, 50); // 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, bool, 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_multijump, bool, this.cvar_cl_multijump);
145     ATTRIB(Client, cvar_cl_accuracy_data_share, bool, this.cvar_cl_accuracy_data_share);
146     ATTRIB(Client, cvar_cl_accuracy_data_receive, bool, this.cvar_cl_accuracy_data_receive);
147     ATTRIBARRAY(Client, cvar_cl_weaponpriorities, string, 10);
148     ATTRIB(Client, cvar_cl_weaponpriority, string, this.cvar_cl_weaponpriority);
149     ATTRIB(Client, cvar_cl_cts_noautoswitch, bool, this.cvar_cl_cts_noautoswitch);
150     ATTRIB(Client, cvar_cl_weapon_switch_reload, bool, this.cvar_cl_weapon_switch_reload);
151     ATTRIB(Client, cvar_cl_weapon_switch_fallback_to_impulse, bool, this.cvar_cl_weapon_switch_fallback_to_impulse);
152
153     METHOD(Client, m_unwind, bool(Client this));
154
155     STATIC_METHOD(Client, Add, void(Client this, int _team));
156     STATIC_METHOD(Client, Remove, void(Client this));
157
158     INIT(Client) {
159         if (this.m_unwind(this)) return this;
160         make_impure(this);
161         this.classname = "player_joining";
162         static int playerid_last;
163         this.playerid = ++playerid_last;
164         ClientState_attach(this);
165     }
166     DESTRUCTOR(Client) {
167         Client_Remove(this);
168     }
169     CONSTRUCTOR(Client, string name) {
170         CONSTRUCT(Client);
171         this.netname = name;
172         this.netaddress = "local";
173         this.playermodel = cvar_defstring("sv_defaultplayermodel");
174     }
175 ENDCLASS(Client)
176
177 CLASS(Observer, Client)
178     INIT(Observer) {
179         this.classname = STR_OBSERVER;
180     }
181     DESTRUCTOR(Observer) { }
182 ENDCLASS(Observer)
183
184 CLASS(Spectator, Client)
185     INIT(Spectator) {
186         this.classname = STR_SPECTATOR;
187     }
188     DESTRUCTOR(Spectator) { }
189 ENDCLASS(Spectator)
190
191 CLASS(Player, Client)
192
193     // custom
194
195     ATTRIB(Player, dual_weapons, vector, this.dual_weapons); // TODO: actually WepSet!
196     ATTRIB(Player, itemkeys, int, this.itemkeys);
197     ATTRIB(Player, ballistics_density, float, this.ballistics_density);
198     ATTRIB(Player, prevstrengthsound, float, this.prevstrengthsound);
199     ATTRIB(Player, prevstrengthsoundattempt, float, this.prevstrengthsoundattempt);
200     ATTRIB(Player, buff_shield, float, this.buff_shield);
201
202     INIT(Player) {
203         this.classname = STR_PLAYER;
204         IL_PUSH(g_players, this);
205     }
206     DESTRUCTOR(Player) {
207         IL_REMOVE(g_players, this);
208     }
209 ENDCLASS(Player)
210
211 METHOD(Client, m_unwind, bool(Client this))
212 {
213     TC(Client, this);
214     #define UNWIND(class) MACRO_BEGIN if (this.instanceOf##class) { METHOD_REFERENCE(class, dtorimpl)(this); } MACRO_END
215     switch (this.classname) {
216         case "Observer":
217             UNWIND(Spectator);
218             UNWIND(Player);
219             return true;
220         case "Spectator":
221             UNWIND(Observer);
222             UNWIND(Player);
223             return true;
224         case "Player":
225             UNWIND(Observer);
226             UNWIND(Spectator);
227             return true;
228     }
229     #undef UNWIND
230     return false;
231 }
232
233 bool PlayerInList(entity player, string list);
234
235 /// \brief Print the string to the client's chat.
236 /// \param[in] client Client to print to.
237 /// \param[in] text Text to print.
238 void PrintToChat(entity client, string text);
239
240 /// \brief Print the string to the client's chat if the server cvar "developer"
241 /// is not 0.
242 /// \param[in] client Client to print to.
243 /// \param[in] text Text to print.
244 void DebugPrintToChat(entity client, string text);
245
246 /// \brief Prints the string to all clients' chat.
247 /// \param[in] text Text to print.
248 void PrintToChatAll(string text);
249
250 /// \brief Prints the string to all clients' chat if the server cvar "developer"
251 /// is not 0.
252 /// \param[in] text Text to print.
253 void DebugPrintToChatAll(string text);
254
255 /// \brief Print the string to chat of all clients of the specified team.
256 /// \param[in] team_num Team to print to. See NUM_TEAM constants.
257 /// \param[in] text Text to print.
258 void PrintToChatTeam(int team_num, string text);
259
260 /// \brief Print the string to chat of all clients of the specified team if the
261 /// server cvar "developer" is not 0.
262 /// \param[in] team_num Team to print to. See NUM_TEAM constants.
263 /// \param[in] text Text to print.
264 void DebugPrintToChatTeam(int team_num, string text);
265
266 void play_countdown(entity this, float finished, Sound samp);
267
268 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit);
269
270 bool Spectate(entity this, entity pl);
271
272 void ClientInit_Spawn();
273
274 void PutObserverInServer(entity this);
275
276 void SetSpectatee(entity this, entity spectatee);
277 void SetSpectatee_status(entity this, int spectatee_num);
278
279 void FixPlayermodel(entity player);
280
281 void ClientInit_misc(entity this);
282
283 int GetPlayerLimit();
284
285 bool joinAllowed(entity this);
286 void Join(entity this);
287
288 #define SPECTATE_COPY() ACCUMULATE void SpectateCopy(entity this, entity spectatee)
289 #define SPECTATE_COPYFIELD(fld) SPECTATE_COPY() { this.(fld) = spectatee.(fld); }
290
291 int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodcontrol);