-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathplayermanager.h
422 lines (386 loc) · 14.2 KB
/
playermanager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
/**
* =============================================================================
* CS2Fixes
* Copyright (C) 2023-2025 Source2ZE
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "bitvec.h"
#include "common.h"
#include "entity/cparticlesystem.h"
#include "entity/lights.h"
#include "gamesystem.h"
#include "steam/isteamuser.h"
#include "steam/steam_api_common.h"
#include "steam/steamclientpublic.h"
#include "utlvector.h"
#include <playerslot.h>
#define NO_TARGET_BLOCKS (0)
#define NO_RANDOM (1 << 1)
#define NO_MULTIPLE (1 << 2)
#define NO_SELF (1 << 3)
#define NO_BOT (1 << 4)
#define NO_HUMAN (1 << 5)
#define NO_UNAUTHENTICATED (1 << 6)
#define NO_DEAD (1 << 7)
#define NO_ALIVE (1 << 8)
#define NO_TERRORIST (1 << 9)
#define NO_COUNTER_TERRORIST (1 << 10)
#define NO_SPECTATOR (1 << 11)
#define NO_IMMUNITY (1 << 12)
#define DECAL_PREF_KEY_NAME "hide_decals"
#define HIDE_DISTANCE_PREF_KEY_NAME "hide_distance"
#define SOUND_STATUS_PREF_KEY_NAME "sound_status"
#define NO_SHAKE_PREF_KEY_NAME "no_shake"
#define BUTTON_WATCH_PREF_KEY_NAME "button_watch"
#define INVALID_ZEPLAYERHANDLE_INDEX 0u
static uint32 iZEPlayerHandleSerial = 0u; // this should actually be 3 bytes large, but no way enough players join in servers lifespan for this to be an issue
enum class ETargetType
{
NONE,
PLAYER,
SELF,
RANDOM,
RANDOM_T,
RANDOM_CT,
RANDOM_SPEC,
AIM,
ALL,
SPECTATOR,
T,
CT,
DEAD,
ALIVE,
BOT,
HUMAN,
ALL_BUT_SELF,
ALL_BUT_RANDOM,
ALL_BUT_RANDOM_T,
ALL_BUT_RANDOM_CT,
ALL_BUT_RANDOM_SPEC,
ALL_BUT_AIM,
ALL_BUT_SPECTATOR,
ALL_BUT_T,
ALL_BUT_CT
};
enum class ETargetError
{
NO_ERRORS,
INVALID,
CONNECTING,
MULTIPLE_NAME_MATCHES,
RANDOM,
MULTIPLE,
SELF,
BOT,
HUMAN,
UNAUTHENTICATED,
INSUFFICIENT_IMMUNITY_LEVEL,
DEAD,
ALIVE,
TERRORIST,
COUNTER_TERRORIST,
SPECTATOR
};
class ZEPlayer;
struct ZRClass;
struct ZRModelEntry;
class ZEPlayerHandle
{
public:
ZEPlayerHandle();
ZEPlayerHandle(CPlayerSlot slot); // used for initialization inside ZEPlayer constructor
ZEPlayerHandle(const ZEPlayerHandle& other);
ZEPlayerHandle(ZEPlayer* pZEPlayer);
bool IsValid() const { return static_cast<bool>(Get()); }
uint32 GetIndex() const { return m_Index; }
uint32 GetPlayerSlot() const { return m_Parts.m_PlayerSlot; }
uint32 GetSerial() const { return m_Parts.m_Serial; }
bool operator==(const ZEPlayerHandle& other) const { return other.m_Index == m_Index; }
bool operator!=(const ZEPlayerHandle& other) const { return other.m_Index != m_Index; }
bool operator==(ZEPlayer* pZEPlayer) const;
bool operator!=(ZEPlayer* pZEPlayer) const;
void operator=(const ZEPlayerHandle& other) { m_Index = other.m_Index; }
void operator=(ZEPlayer* pZEPlayer) { Set(pZEPlayer); }
void Set(ZEPlayer* pZEPlayer);
ZEPlayer* Get() const;
private:
union
{
uint32 m_Index;
struct
{
uint32 m_PlayerSlot : 6;
uint32 m_Serial : 26;
} m_Parts;
};
};
class ZEPlayer
{
public:
ZEPlayer(CPlayerSlot slot, bool m_bFakeClient = false) :
m_slot(slot), m_bFakeClient(m_bFakeClient), m_Handle(slot)
{
m_bAuthenticated = false;
m_iAdminFlags = 0;
m_iAdminImmunity = 0;
m_SteamID = nullptr;
m_bGagged = false;
m_bMuted = false;
m_iHideDistance = 0;
m_bConnected = false;
m_iTotalDamage = 0;
m_iTotalHits = 0;
m_iTotalKills = 0;
m_bVotedRTV = false;
m_bVotedExtend = false;
m_bIsInfected = false;
m_flRTVVoteTime = -60.0f;
m_flExtendVoteTime = 0;
m_iFloodTokens = 0;
m_flLastTalkTime = 0;
m_bInGame = false;
m_iMZImmunity = 0; // out of 100
m_flNominateTime = -60.0f;
m_iPlayerState = 1; // STATE_WELCOME is the initial state
m_bIsLeader = false;
m_handleMark = nullptr;
m_colorLeader = Color(0, 0, 0, 0);
m_colorTracer = Color(0, 0, 0, 0);
m_colorGlow = Color(0, 0, 0, 0);
m_colorBeacon = Color(0, 0, 0, 0);
m_flLeaderVoteTime = -30.0f;
m_flSpeedMod = 1.f;
m_flMaxSpeed = 1.f;
m_iLastInputs = IN_NONE;
m_iLastInputTime = std::time(0);
m_pActiveZRClass = nullptr;
m_pActiveZRModel = nullptr;
m_iButtonWatchMode = 0;
}
~ZEPlayer()
{
CBarnLight* pFlashLight = m_hFlashLight.Get();
if (pFlashLight)
pFlashLight->Remove();
}
bool IsFakeClient() { return m_bFakeClient; }
bool IsAuthenticated() { return m_bAuthenticated; }
bool IsConnected() { return m_bConnected; }
uint64 GetUnauthenticatedSteamId64() { return m_UnauthenticatedSteamID->ConvertToUint64(); }
const CSteamID* GetUnauthenticatedSteamId() { return m_UnauthenticatedSteamID; }
uint64 GetSteamId64() { return m_SteamID->ConvertToUint64(); }
const CSteamID* GetSteamId() { return m_SteamID; }
bool IsAdminFlagSet(uint64 iFlag);
bool IsFlooding();
void SetConnected() { m_bConnected = true; }
void SetUnauthenticatedSteamId(const CSteamID* steamID) { m_UnauthenticatedSteamID = steamID; }
void SetSteamId(const CSteamID* steamID) { m_SteamID = steamID; }
void SetAdminFlags(uint64 iAdminFlags) { m_iAdminFlags = iAdminFlags; }
void SetAdminImmunity(int iAdminImmunity) { m_iAdminImmunity = iAdminImmunity; }
void SetPlayerSlot(CPlayerSlot slot) { m_slot = slot; }
void SetMuted(bool muted) { m_bMuted = muted; }
void SetGagged(bool gagged) { m_bGagged = gagged; }
void SetTransmit(int index, bool shouldTransmit) { shouldTransmit ? m_shouldTransmit.Set(index) : m_shouldTransmit.Clear(index); }
void ClearTransmit() { m_shouldTransmit.ClearAll(); }
void SetHideDistance(int distance);
void SetTotalDamage(int damage) { m_iTotalDamage = damage; }
void SetTotalHits(int hits) { m_iTotalHits = hits; }
void SetTotalKills(int kills) { m_iTotalKills = kills; }
void SetRTVVote(bool bRTVVote) { m_bVotedRTV = bRTVVote; }
void SetRTVVoteTime(float flCurtime) { m_flRTVVoteTime = flCurtime; }
void SetExtendVote(bool bExtendVote) { m_bVotedExtend = bExtendVote; }
void SetInfectState(bool bInfectState) { m_bIsInfected = bInfectState; }
void SetExtendVoteTime(float flCurtime) { m_flExtendVoteTime = flCurtime; }
void SetIpAddress(std::string strIp) { m_strIp = strIp; }
void SetInGame(bool bInGame) { m_bInGame = bInGame; }
void SetImmunity(int iMZImmunity) { m_iMZImmunity = iMZImmunity; }
void SetNominateTime(float flCurtime) { m_flNominateTime = flCurtime; }
void SetFlashLight(CBarnLight* pLight) { m_hFlashLight.Set(pLight); }
void SetBeaconParticle(CParticleSystem* pParticle) { m_hBeaconParticle.Set(pParticle); }
void SetPlayerState(uint32 iPlayerState) { m_iPlayerState = iPlayerState; }
void SetLeader(bool bIsLeader) { m_bIsLeader = bIsLeader; }
void CreateMark(float fDuration, Vector vecOrigin);
void SetLeaderColor(Color colorLeader) { m_colorLeader = colorLeader; }
void SetTracerColor(Color colorTracer) { m_colorTracer = colorTracer; }
void SetGlowColor(Color colorGlow) { m_colorGlow = colorGlow; }
void SetBeaconColor(Color colorBeacon) { m_colorBeacon = colorBeacon; }
void SetLeaderVoteTime(float flCurtime) { m_flLeaderVoteTime = flCurtime; }
void SetGlowModel(CBaseModelEntity* pModel) { m_hGlowModel.Set(pModel); }
void SetSpeedMod(float flSpeedMod) { m_flSpeedMod = flSpeedMod; }
void SetLastInputs(uint64 iLastInputs) { m_iLastInputs = iLastInputs; }
void UpdateLastInputTime() { m_iLastInputTime = std::time(0); }
void SetMaxSpeed(float flMaxSpeed) { m_flMaxSpeed = flMaxSpeed; }
void CycleButtonWatch();
void ReplicateConVar(const char* pszName, const char* pszValue);
void SetActiveZRClass(std::shared_ptr<ZRClass> pZRModel) { m_pActiveZRClass = pZRModel; }
void SetActiveZRModel(std::shared_ptr<ZRModelEntry> pZRClass) { m_pActiveZRModel = pZRClass; }
uint64 GetAdminFlags() { return m_iAdminFlags; }
int GetAdminImmunity() { return m_iAdminImmunity; }
bool IsMuted() { return m_bMuted; }
bool IsGagged() { return m_bGagged; }
bool ShouldBlockTransmit(int index) { return m_shouldTransmit.Get(index); }
int GetHideDistance();
CPlayerSlot GetPlayerSlot() { return m_slot; }
int GetTotalDamage() { return m_iTotalDamage; }
int GetTotalHits() { return m_iTotalHits; }
int GetTotalKills() { return m_iTotalKills; }
bool GetRTVVote() { return m_bVotedRTV; }
float GetRTVVoteTime() { return m_flRTVVoteTime; }
bool GetExtendVote() { return m_bVotedExtend; }
bool IsInfected() { return m_bIsInfected; }
float GetExtendVoteTime() { return m_flExtendVoteTime; }
const char* GetIpAddress() { return m_strIp.c_str(); }
bool IsInGame() { return m_bInGame; }
int GetImmunity() { return m_iMZImmunity; }
float GetNominateTime() { return m_flNominateTime; }
CBarnLight* GetFlashLight() { return m_hFlashLight.Get(); }
CParticleSystem* GetBeaconParticle() { return m_hBeaconParticle.Get(); }
ZEPlayerHandle GetHandle() { return m_Handle; }
uint32 GetPlayerState() { return m_iPlayerState; }
bool IsLeader() { return m_bIsLeader; }
Color GetLeaderColor() { return m_colorLeader; }
Color GetTracerColor() { return m_colorTracer; }
Color GetGlowColor() { return m_colorGlow; }
Color GetBeaconColor() { return m_colorBeacon; }
int GetLeaderVoteCount();
bool HasPlayerVotedLeader(ZEPlayer* pPlayer);
float GetLeaderVoteTime() { return m_flLeaderVoteTime; }
CBaseModelEntity* GetGlowModel() { return m_hGlowModel.Get(); }
float GetSpeedMod() { return m_flSpeedMod; }
float GetMaxSpeed() { return m_flMaxSpeed; }
uint64 GetLastInputs() { return m_iLastInputs; }
std::time_t GetLastInputTime() { return m_iLastInputTime; }
std::shared_ptr<ZRClass> GetActiveZRClass() { return m_pActiveZRClass; }
std::shared_ptr<ZRModelEntry> GetActiveZRModel() { return m_pActiveZRModel; }
int GetButtonWatchMode();
void OnSpawn();
void OnAuthenticated();
void CheckAdmin();
void CheckInfractions();
void SpawnFlashLight();
void ToggleFlashLight();
void StartBeacon(Color color, ZEPlayerHandle Giver = 0);
void EndBeacon();
void AddLeaderVote(ZEPlayer* pPlayer);
void PurgeLeaderVotes();
void StartGlow(Color color, int duration);
void EndGlow();
void SetSteamIdAttribute();
private:
bool m_bAuthenticated;
bool m_bConnected;
const CSteamID* m_UnauthenticatedSteamID;
const CSteamID* m_SteamID;
CPlayerSlot m_slot;
bool m_bFakeClient;
bool m_bMuted;
bool m_bGagged;
uint64 m_iAdminFlags;
int m_iAdminImmunity;
int m_iHideDistance;
CBitVec<MAXPLAYERS> m_shouldTransmit;
int m_iTotalDamage;
int m_iTotalHits;
int m_iTotalKills;
bool m_bVotedRTV;
float m_flRTVVoteTime;
bool m_bVotedExtend;
bool m_bIsInfected;
float m_flExtendVoteTime;
int m_iFloodTokens;
float m_flLastTalkTime;
std::string m_strIp;
bool m_bInGame;
int m_iMZImmunity;
float m_flNominateTime;
CHandle<CBarnLight> m_hFlashLight;
CHandle<CParticleSystem> m_hBeaconParticle;
ZEPlayerHandle m_Handle;
uint32 m_iPlayerState;
bool m_bIsLeader;
CHandle<CBaseEntity> m_handleMark;
Color m_colorLeader;
Color m_colorTracer;
Color m_colorGlow;
Color m_colorBeacon;
CUtlVector<ZEPlayerHandle> m_vecLeaderVotes;
float m_flLeaderVoteTime;
CHandle<CBaseModelEntity> m_hGlowModel;
float m_flSpeedMod;
float m_flMaxSpeed;
uint64 m_iLastInputs;
std::time_t m_iLastInputTime;
std::shared_ptr<ZRClass> m_pActiveZRClass;
std::shared_ptr<ZRModelEntry> m_pActiveZRModel;
int m_iButtonWatchMode;
};
class CPlayerManager
{
public:
CPlayerManager(bool late = false)
{
V_memset(m_vecPlayers, 0, sizeof(m_vecPlayers));
m_nUsingStopSound = -1; // On by default
m_nUsingSilenceSound = 0;
m_nUsingStopDecals = -1; // On by default
m_nUsingNoShake = 0;
if (late)
OnLateLoad();
}
bool OnClientConnected(CPlayerSlot slot, uint64 xuid, const char* pszNetworkID);
void OnClientDisconnect(CPlayerSlot slot);
void OnBotConnected(CPlayerSlot slot);
void OnClientPutInServer(CPlayerSlot slot);
void OnLateLoad();
void OnSteamAPIActivated();
void CheckInfractions();
void FlashLightThink();
void CheckHideDistances();
void SetupInfiniteAmmo();
CPlayerSlot GetSlotFromUserId(uint16 userid);
ZEPlayer* GetPlayerFromUserId(uint16 userid);
ZEPlayer* GetPlayerFromSteamId(uint64 steamid);
ETargetError GetPlayersFromString(CCSPlayerController* pPlayer, const char* pszTarget, int& iNumClients, int* clients, uint64 iBlockedFlags = NO_TARGET_BLOCKS);
ETargetError GetPlayersFromString(CCSPlayerController* pPlayer, const char* pszTarget, int& iNumClients, int* clients, uint64 iBlockedFlags, ETargetType& nType);
static std::string GetErrorString(ETargetError eType, int iSlot = 0);
bool CanTargetPlayers(CCSPlayerController* pPlayer, const char* pszTarget, int& iNumClients, int* clients, uint64 iBlockedFlags = NO_TARGET_BLOCKS);
bool CanTargetPlayers(CCSPlayerController* pPlayer, const char* pszTarget, int& iNumClients, int* clients, uint64 iBlockedFlags, ETargetType& nType);
ZEPlayer* GetPlayer(CPlayerSlot slot);
uint64 GetStopSoundMask() { return m_nUsingStopSound; }
uint64 GetSilenceSoundMask() { return m_nUsingSilenceSound; }
uint64 GetStopDecalsMask() { return m_nUsingStopDecals; }
uint64 GetNoShakeMask() { return m_nUsingNoShake; }
void SetPlayerStopSound(int slot, bool set);
void SetPlayerSilenceSound(int slot, bool set);
void SetPlayerStopDecals(int slot, bool set);
void SetPlayerNoShake(int slot, bool set);
void ResetPlayerFlags(int slot);
bool IsPlayerUsingStopSound(int slot) { return m_nUsingStopSound & ((uint64)1 << slot); }
bool IsPlayerUsingSilenceSound(int slot) { return m_nUsingSilenceSound & ((uint64)1 << slot); }
bool IsPlayerUsingStopDecals(int slot) { return m_nUsingStopDecals & ((uint64)1 << slot); }
bool IsPlayerUsingNoShake(int slot) { return m_nUsingNoShake & ((uint64)1 << slot); }
void UpdatePlayerStates();
int GetOnlinePlayerCount(bool bCountBots);
STEAM_GAMESERVER_CALLBACK_MANUAL(CPlayerManager, OnValidateAuthTicket, ValidateAuthTicketResponse_t, m_CallbackValidateAuthTicketResponse);
private:
ZEPlayer* m_vecPlayers[MAXPLAYERS];
uint64 m_nUsingStopSound;
uint64 m_nUsingSilenceSound;
uint64 m_nUsingStopDecals;
uint64 m_nUsingNoShake;
};
extern CPlayerManager* g_playerManager;
void PrecacheBeaconParticle(IEntityResourceManifest* pResourceManifest);