diff --git a/configs/addons/counterstrikesharp/configs/core.example.json b/configs/addons/counterstrikesharp/configs/core.example.json index 97dc9bfc3..bd1f476cb 100644 --- a/configs/addons/counterstrikesharp/configs/core.example.json +++ b/configs/addons/counterstrikesharp/configs/core.example.json @@ -1,10 +1,15 @@ { - "PublicChatTrigger": [ "!" ], - "SilentChatTrigger": [ "/" ], - "FollowCS2ServerGuidelines": true, - "PluginHotReloadEnabled": true, - "PluginAutoLoadEnabled": true, - "ServerLanguage": "en", - "UnlockConCommands": true, - "UnlockConVars": true -} \ No newline at end of file + "PublicChatTrigger": [ + "!" + ], + "SilentChatTrigger": [ + "/" + ], + "FollowCS2ServerGuidelines": true, + "PluginHotReloadEnabled": true, + "PluginAutoLoadEnabled": true, + "ServerLanguage": "en", + "UnlockConCommands": true, + "UnlockConVars": true, + "SteamAuth": "Strict" +} diff --git a/docfx/docs/reference/core-configuration.md b/docfx/docs/reference/core-configuration.md index 914da0bad..92fef75d5 100644 --- a/docfx/docs/reference/core-configuration.md +++ b/docfx/docs/reference/core-configuration.md @@ -47,3 +47,12 @@ When enabled, will remove the `FCVAR_HIDDEN`,`FCVAR_DEVELOPMENTONLY`, `FCVAR_MIS ## UnlockConVars When enabled, will remove the `FCVAR_HIDDEN`,`FCVAR_DEVELOPMENTONLY`, `FCVAR_MISSING0`, `FCVAR_MISSING1`, `FCVAR_MISSING2`, `FCVAR_MISSING3` flags from all console variables. + + +## SteamAuth + +Configures the strictness of "AuthorizedSteamID" on the server. Defaults to "Strict". Options are: + +- "Strict": CS# will only grant permissions to users if the server is currently connected to steam and the user has passed auth checks. +- "Flexible" CS# will try to use the users checked steam auth, but failing that will use standard SteamID. +- "Off": CS# will always just use the standard SteamID. diff --git a/managed/CounterStrikeSharp.API/Core/CoreConfig.cs b/managed/CounterStrikeSharp.API/Core/CoreConfig.cs index 7771456bf..8a5e96757 100644 --- a/managed/CounterStrikeSharp.API/Core/CoreConfig.cs +++ b/managed/CounterStrikeSharp.API/Core/CoreConfig.cs @@ -61,6 +61,9 @@ internal sealed partial class CoreConfigData [JsonPropertyName("UnlockConVars")] public bool UnlockConVars { get; set; } = true; + + [JsonPropertyName("SteamAuth")] + public string SteamAuth { get; set; } = "Strict"; } /// @@ -115,6 +118,18 @@ public partial class CoreConfig public static bool UnlockConVars => _coreConfig.UnlockConVars; + + /// + /// Configures the strictness of + /// + /// + /// "Strict": CS# will only grant permissions to users if the server is currently connected to steam and the user has passed auth checks. + /// "Flexible" CS# will try to use the users checked steam auth, but failing that will use standard SteamID. + /// "Off": CS# will always just use the standard SteamID. + /// + /// + public static string SteamAuth => _coreConfig.SteamAuth; + } public partial class CoreConfig : IStartupService diff --git a/src/core/coreconfig.cpp b/src/core/coreconfig.cpp index 77efe587f..85edc400a 100644 --- a/src/core/coreconfig.cpp +++ b/src/core/coreconfig.cpp @@ -26,6 +26,14 @@ CCoreConfig::CCoreConfig(const std::string& path) { m_sPath = path; } CCoreConfig::~CCoreConfig() = default; +// map TaskState values to JSON as strings +NLOHMANN_JSON_SERIALIZE_ENUM(SteamAuthStrictness, + { + { Strict, "Strict" }, + { Flexible, "Flexible" }, + { Off, "Off" }, + }) + bool CCoreConfig::Init(char* conf_error, int conf_error_size) { std::ifstream ifs(std::string(m_sPath + ".json")); @@ -60,6 +68,7 @@ bool CCoreConfig::Init(char* conf_error, int conf_error_size) ServerLanguage = m_json.value("ServerLanguage", ServerLanguage); UnlockConCommands = m_json.value("UnlockConCommands", UnlockConCommands); UnlockConVars = m_json.value("UnlockConVars", UnlockConVars); + SteamAuth = m_json["SteamAuth"].template get(); } catch (const std::exception& ex) { diff --git a/src/core/coreconfig.h b/src/core/coreconfig.h index bca42baa2..242054016 100644 --- a/src/core/coreconfig.h +++ b/src/core/coreconfig.h @@ -24,6 +24,13 @@ namespace counterstrikesharp { +enum SteamAuthStrictness +{ + Strict, + Flexible, + Off +}; + class CCoreConfig { public: @@ -35,6 +42,7 @@ class CCoreConfig std::string ServerLanguage = "en"; bool UnlockConCommands = true; bool UnlockConVars = true; + SteamAuthStrictness SteamAuth = Strict; using json = nlohmann::json; CCoreConfig(const std::string& path); diff --git a/src/core/managers/player_manager.cpp b/src/core/managers/player_manager.cpp index 69d6a4435..caa971a84 100644 --- a/src/core/managers/player_manager.cpp +++ b/src/core/managers/player_manager.cpp @@ -30,33 +30,29 @@ */ #include "core/managers/player_manager.h" -#include "core/managers/con_command_manager.h" -#include "core/managers/voice_manager.h" +#include #include #include #include #include #include "core/log.h" +#include "core/managers/con_command_manager.h" +#include "core/managers/voice_manager.h" #include "core/timer_system.h" #include "scripting/callback_manager.h" -#include // extern CEntitySystem *g_pEntitySystem; -SH_DECL_HOOK4_void(IServerGameClients, ClientActive, SH_NOATTRIB, 0, CPlayerSlot, bool, const char*, - uint64); -SH_DECL_HOOK5_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, CPlayerSlot, - ENetworkDisconnectionReason, const char*, uint64, const char*); +SH_DECL_HOOK4_void(IServerGameClients, ClientActive, SH_NOATTRIB, 0, CPlayerSlot, bool, const char*, uint64); +SH_DECL_HOOK5_void( + IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, CPlayerSlot, ENetworkDisconnectionReason, const char*, uint64, const char*); SH_DECL_HOOK1_void(IServerGameClients, ClientVoice, SH_NOATTRIB, 0, CPlayerSlot); -SH_DECL_HOOK4_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, CPlayerSlot, char const*, - int, uint64); +SH_DECL_HOOK4_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, CPlayerSlot, char const*, int, uint64); SH_DECL_HOOK1_void(IServerGameClients, ClientSettingsChanged, SH_NOATTRIB, 0, CPlayerSlot); -SH_DECL_HOOK6_void(IServerGameClients, OnClientConnected, SH_NOATTRIB, 0, CPlayerSlot, const char*, - uint64, const char*, const char*, bool); -SH_DECL_HOOK6(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, CPlayerSlot, const char*, - uint64, const char*, bool, CBufferString*); +SH_DECL_HOOK6_void(IServerGameClients, OnClientConnected, SH_NOATTRIB, 0, CPlayerSlot, const char*, uint64, const char*, const char*, bool); +SH_DECL_HOOK6(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, CPlayerSlot, const char*, uint64, const char*, bool, CBufferString*); SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, CPlayerSlot, const CCommand&); @@ -66,48 +62,39 @@ void PlayerManager::OnStartup() {} void PlayerManager::OnAllInitialized() { - SH_ADD_HOOK(IServerGameClients, ClientConnect, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientConnect), false); - SH_ADD_HOOK(IServerGameClients, ClientConnect, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientConnect_Post), true); - SH_ADD_HOOK(IServerGameClients, ClientPutInServer, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientPutInServer), true); - SH_ADD_HOOK(IServerGameClients, ClientDisconnect, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientDisconnect), false); - SH_ADD_HOOK(IServerGameClients, ClientDisconnect, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientDisconnect_Post), true); - SH_ADD_HOOK(IServerGameClients, ClientCommand, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientCommand), false); - SH_ADD_HOOK(IServerGameClients, ClientVoice, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientVoice), true); + SH_ADD_HOOK(IServerGameClients, ClientConnect, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientConnect), false); + SH_ADD_HOOK(IServerGameClients, ClientConnect, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientConnect_Post), true); + SH_ADD_HOOK(IServerGameClients, ClientPutInServer, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientPutInServer), + true); + SH_ADD_HOOK(IServerGameClients, ClientDisconnect, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientDisconnect), + false); + SH_ADD_HOOK(IServerGameClients, ClientDisconnect, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientDisconnect_Post), + true); + SH_ADD_HOOK(IServerGameClients, ClientCommand, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientCommand), false); + SH_ADD_HOOK(IServerGameClients, ClientVoice, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientVoice), true); m_on_client_connect_callback = globals::callbackManager.CreateCallback("OnClientConnect"); m_on_client_connected_callback = globals::callbackManager.CreateCallback("OnClientConnected"); - m_on_client_put_in_server_callback = - globals::callbackManager.CreateCallback("OnClientPutInServer"); + m_on_client_put_in_server_callback = globals::callbackManager.CreateCallback("OnClientPutInServer"); m_on_client_disconnect_callback = globals::callbackManager.CreateCallback("OnClientDisconnect"); - m_on_client_disconnect_post_callback = - globals::callbackManager.CreateCallback("OnClientDisconnectPost"); + m_on_client_disconnect_post_callback = globals::callbackManager.CreateCallback("OnClientDisconnectPost"); m_on_client_voice_callback = globals::callbackManager.CreateCallback("OnClientVoice"); m_on_client_authorized_callback = globals::callbackManager.CreateCallback("OnClientAuthorized"); } void PlayerManager::OnShutdown() { - SH_REMOVE_HOOK(IServerGameClients, ClientConnect, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientConnect), false); - SH_REMOVE_HOOK(IServerGameClients, ClientConnect, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientConnect_Post), true); - SH_REMOVE_HOOK(IServerGameClients, ClientPutInServer, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientPutInServer), true); - SH_REMOVE_HOOK(IServerGameClients, ClientDisconnect, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientDisconnect), false); + SH_REMOVE_HOOK(IServerGameClients, ClientConnect, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientConnect), false); + SH_REMOVE_HOOK(IServerGameClients, ClientConnect, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientConnect_Post), + true); + SH_REMOVE_HOOK(IServerGameClients, ClientPutInServer, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientPutInServer), + true); + SH_REMOVE_HOOK(IServerGameClients, ClientDisconnect, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientDisconnect), + false); SH_REMOVE_HOOK(IServerGameClients, ClientDisconnect, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientDisconnect_Post), true); - SH_REMOVE_HOOK(IServerGameClients, ClientCommand, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientCommand), false); - SH_REMOVE_HOOK(IServerGameClients, ClientVoice, globals::serverGameClients, - SH_MEMBER(this, &PlayerManager::OnClientVoice), true); + SH_REMOVE_HOOK(IServerGameClients, ClientCommand, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientCommand), false); + SH_REMOVE_HOOK(IServerGameClients, ClientVoice, globals::serverGameClients, SH_MEMBER(this, &PlayerManager::OnClientVoice), true); globals::callbackManager.ReleaseCallback(m_on_client_connect_callback); globals::callbackManager.ReleaseCallback(m_on_client_connected_callback); @@ -118,21 +105,18 @@ void PlayerManager::OnShutdown() globals::callbackManager.ReleaseCallback(m_on_client_voice_callback); } -bool PlayerManager::OnClientConnect(CPlayerSlot slot, const char* pszName, uint64 xuid, - const char* pszNetworkID, bool unk1, - CBufferString* pRejectReason) +bool PlayerManager::OnClientConnect( + CPlayerSlot slot, const char* pszName, uint64 xuid, const char* pszNetworkID, bool unk1, CBufferString* pRejectReason) { - CSSHARP_CORE_TRACE("[PlayerManager][OnClientConnect] - {}, {}, {}", slot.Get(), pszName, - pszNetworkID); + CSSHARP_CORE_TRACE("[PlayerManager][OnClientConnect] - {}, {}, {}", slot.Get(), pszName, pszNetworkID); int client = slot.Get(); CPlayer* pPlayer = &m_players[client]; - if (pPlayer->IsConnected()) { - OnClientDisconnect(slot, ENetworkDisconnectionReason::NETWORK_DISCONNECT_INVALID, pszName, - xuid, pszNetworkID); - OnClientDisconnect_Post(slot, ENetworkDisconnectionReason::NETWORK_DISCONNECT_INVALID, - pszName, xuid, pszNetworkID); + if (pPlayer->IsConnected()) + { + OnClientDisconnect(slot, ENetworkDisconnectionReason::NETWORK_DISCONNECT_INVALID, pszName, xuid, pszNetworkID); + OnClientDisconnect_Post(slot, ENetworkDisconnectionReason::NETWORK_DISCONNECT_INVALID, pszName, xuid, pszNetworkID); } pPlayer->Initialize(pszName, pszNetworkID, slot); @@ -143,7 +127,8 @@ bool PlayerManager::OnClientConnect(CPlayerSlot slot, const char* pszName, uint6 m_on_client_connect_callback->ScriptContext().Push(pszNetworkID); m_on_client_connect_callback->Execute(); - if (m_on_client_connect_callback->GetFunctionCount() > 0) { + if (m_on_client_connect_callback->GetFunctionCount() > 0) + { // auto cancel = m_on_client_connect_callback->ScriptContext().GetArgument(0); // auto cancelReason = // m_on_client_connect_callback->ScriptContext().GetArgument(1); @@ -167,47 +152,47 @@ bool PlayerManager::OnClientConnect(CPlayerSlot slot, const char* pszName, uint6 return true; } -bool PlayerManager::OnClientConnect_Post(CPlayerSlot slot, const char* pszName, uint64 xuid, - const char* pszNetworkID, bool unk1, - CBufferString* pRejectReason) +bool PlayerManager::OnClientConnect_Post( + CPlayerSlot slot, const char* pszName, uint64 xuid, const char* pszNetworkID, bool unk1, CBufferString* pRejectReason) { - CSSHARP_CORE_TRACE("[PlayerManager][OnClientConnect_Post] - {}, {}, {}", slot.Get(), pszName, - pszNetworkID); + CSSHARP_CORE_TRACE("[PlayerManager][OnClientConnect_Post] - {}, {}, {}", slot.Get(), pszName, pszNetworkID); int client = slot.Get(); bool orig_value = META_RESULT_ORIG_RET(bool); CPlayer* pPlayer = &m_players[client]; - if (orig_value) { + if (orig_value) + { m_on_client_connected_callback->ScriptContext().Reset(); m_on_client_connected_callback->ScriptContext().Push(pPlayer->m_slot.Get()); m_on_client_connected_callback->Execute(); - if (!pPlayer->IsFakeClient() && m_is_listen_server && - strncmp(pszNetworkID, "127.0.0.1", 9) == 0) { + if (!pPlayer->IsFakeClient() && m_is_listen_server && strncmp(pszNetworkID, "127.0.0.1", 9) == 0) + { m_listen_client = client; } - } else { + } + else + { InvalidatePlayer(pPlayer); } return true; } -void PlayerManager::OnClientPutInServer(CPlayerSlot slot, char const* pszName, int type, - uint64 xuid) +void PlayerManager::OnClientPutInServer(CPlayerSlot slot, char const* pszName, int type, uint64 xuid) { - CSSHARP_CORE_TRACE("[PlayerManager][OnClientPutInServer] - {}, {}, {}", slot.Get(), pszName, - type); + CSSHARP_CORE_TRACE("[PlayerManager][OnClientPutInServer] - {}, {}, {}", slot.Get(), pszName, type); int client = slot.Get(); CPlayer* pPlayer = &m_players[client]; - if (!pPlayer->IsConnected()) { + if (!pPlayer->IsConnected()) + { pPlayer->m_is_fake_client = true; - if (!OnClientConnect(slot, pszName, 0, "127.0.0.1", false, - new CBufferStringGrowable<255>())) { + if (!OnClientConnect(slot, pszName, 0, "127.0.0.1", false, new CBufferStringGrowable<255>())) + { /* :TODO: kick the bot if it's rejected */ return; } @@ -233,39 +218,39 @@ void PlayerManager::OnClientPutInServer(CPlayerSlot slot, char const* pszName, i m_on_client_put_in_server_callback->Execute(); } -void PlayerManager::OnClientDisconnect(CPlayerSlot slot, ENetworkDisconnectionReason reason, - const char* pszName, uint64 xuid, const char* pszNetworkID) +void PlayerManager::OnClientDisconnect( + CPlayerSlot slot, ENetworkDisconnectionReason reason, const char* pszName, uint64 xuid, const char* pszNetworkID) { - CSSHARP_CORE_TRACE("[PlayerManager][OnClientDisconnect] - {}, {}, {}", slot.Get(), pszName, - pszNetworkID); + CSSHARP_CORE_TRACE("[PlayerManager][OnClientDisconnect] - {}, {}, {}", slot.Get(), pszName, pszNetworkID); int client = slot.Get(); CPlayer* pPlayer = &m_players[client]; - if (pPlayer->IsConnected()) { + if (pPlayer->IsConnected()) + { m_on_client_disconnect_callback->ScriptContext().Reset(); m_on_client_disconnect_callback->ScriptContext().Push(pPlayer->m_slot.Get()); m_on_client_disconnect_callback->ScriptContext().Push(reason); m_on_client_disconnect_callback->Execute(); } - if (pPlayer->WasCountedAsInGame()) { + if (pPlayer->WasCountedAsInGame()) + { m_player_count--; } // globals::entityListener.HandleEntityDeleted(pPlayer->GetBaseEntity(), client); } -void PlayerManager::OnClientDisconnect_Post(CPlayerSlot slot, ENetworkDisconnectionReason reason, - const char* pszName, uint64 xuid, - const char* pszNetworkID) const +void PlayerManager::OnClientDisconnect_Post( + CPlayerSlot slot, ENetworkDisconnectionReason reason, const char* pszName, uint64 xuid, const char* pszNetworkID) const { - CSSHARP_CORE_TRACE("[PlayerManager][OnClientDisconnect_Post] - {}, {}, {}", slot.Get(), pszName, - pszNetworkID); + CSSHARP_CORE_TRACE("[PlayerManager][OnClientDisconnect_Post] - {}, {}, {}", slot.Get(), pszName, pszNetworkID); int client = slot.Get(); CPlayer* pPlayer = &m_players[client]; - if (!pPlayer->IsConnected()) { + if (!pPlayer->IsConnected()) + { /* We don't care, prevent a double call */ return; } @@ -291,14 +276,14 @@ void PlayerManager::OnLevelEnd() { CSSHARP_CORE_TRACE("[PlayerManager][OnLevelEnd]"); - for (int i = 0; i <= MaxClients(); i++) { - if (m_players[i].IsConnected()) { - OnClientDisconnect(m_players[i].m_slot, - ENetworkDisconnectionReason::NETWORK_DISCONNECT_INVALID, - m_players[i].GetName(), 0, m_players[i].GetIpAddress()); - OnClientDisconnect_Post(m_players[i].m_slot, - ENetworkDisconnectionReason::NETWORK_DISCONNECT_INVALID, - m_players[i].GetName(), 0, m_players[i].GetIpAddress()); + for (int i = 0; i <= MaxClients(); i++) + { + if (m_players[i].IsConnected()) + { + OnClientDisconnect(m_players[i].m_slot, ENetworkDisconnectionReason::NETWORK_DISCONNECT_INVALID, m_players[i].GetName(), 0, + m_players[i].GetIpAddress()); + OnClientDisconnect_Post(m_players[i].m_slot, ENetworkDisconnectionReason::NETWORK_DISCONNECT_INVALID, m_players[i].GetName(), 0, + m_players[i].GetIpAddress()); } } m_player_count = 0; @@ -306,17 +291,17 @@ void PlayerManager::OnLevelEnd() void PlayerManager::OnClientCommand(CPlayerSlot slot, const CCommand& args) const { - CSSHARP_CORE_TRACE("[PlayerManager][OnClientCommand] - {}, {}, {}", slot.Get(), args.Arg(0), - (void*)&args); + CSSHARP_CORE_TRACE("[PlayerManager][OnClientCommand] - {}, {}, {}", slot.Get(), args.Arg(0), (void*)&args); const char* cmd = args.Arg(0); globals::voiceManager.OnClientCommand(slot, args); - auto result = globals::conCommandManager.ExecuteCommandCallbacks( - cmd, CCommandContext(CommandTarget_t::CT_NO_TARGET, slot), args, HookMode::Pre, CommandCallingContext::Console); + auto result = globals::conCommandManager.ExecuteCommandCallbacks(cmd, CCommandContext(CommandTarget_t::CT_NO_TARGET, slot), args, + HookMode::Pre, CommandCallingContext::Console); - if (result >= HookResult::Handled) { + if (result >= HookResult::Handled) + { RETURN_META(MRES_SUPERCEDE); } } @@ -329,7 +314,8 @@ int PlayerManager::MaxClients() const { return globals::getGlobalVars()->maxClie CPlayer* PlayerManager::GetPlayerBySlot(int client) const { - if (client > MaxClients() || client < 0) { + if (client > MaxClients() || client < 0) + { return nullptr; } @@ -378,8 +364,7 @@ CPlayer* PlayerManager::GetPlayerBySlot(int client) const void PlayerManager::InvalidatePlayer(CPlayer* pPlayer) const { auto userid = globals::engine->GetPlayerUserId(pPlayer->m_slot); - if (userid.Get() != -1) - m_user_id_lookup[userid.Get()] = 0; + if (userid.Get() != -1) m_user_id_lookup[userid.Get()] = 0; pPlayer->Disconnect(); } @@ -396,6 +381,8 @@ void CPlayer::Initialize(const char* name, const char* ip, CPlayerSlot slot) IPlayerInfo* CPlayer::GetPlayerInfo() const { return m_info; } +CPlayerSlot CPlayer::GetSlot() const { return m_slot; } + const char* CPlayer::GetName() const { return strdup(m_name.c_str()); } bool CPlayer::IsConnected() const { return m_is_connected; } @@ -406,7 +393,8 @@ bool CPlayer::IsAuthorized() const { return m_is_authorized; } bool CPlayer::IsAuthStringValidated() const { - if (!IsFakeClient()) { + if (!IsFakeClient()) + { return globals::engine->IsClientFullyAuthenticated(m_slot); } return false; @@ -416,12 +404,14 @@ void CPlayer::Authorize() { m_is_authorized = true; } void CPlayer::PrintToConsole(const char* message) const { - if (m_is_connected == false || m_is_fake_client == true) { + if (m_is_connected == false || m_is_fake_client == true) + { return; } INetChannelInfo* pNetChan = globals::engine->GetPlayerNetInfo(m_slot); - if (pNetChan == nullptr) { + if (pNetChan == nullptr) + { return; } @@ -457,18 +447,21 @@ PlayerManager::PlayerManager() void PlayerManager::RunAuthChecks() { - if (globals::timerSystem.GetTickedTime() - m_last_auth_check_time < 0.5F) { + if (globals::timerSystem.GetTickedTime() - m_last_auth_check_time < 0.5F) + { return; } m_last_auth_check_time = globals::timerSystem.GetTickedTime(); - for (int i = 0; i <= MaxClients(); i++) { - if (m_players[i].IsConnected()) { - if (m_players[i].IsAuthorized() || m_players[i].IsFakeClient()) - continue; + for (int i = 0; i <= MaxClients(); i++) + { + if (m_players[i].IsConnected()) + { + if (m_players[i].IsAuthorized() || m_players[i].IsFakeClient()) continue; - if (globals::engine->IsClientFullyAuthenticated(i)) { + if (globals::engine->IsClientFullyAuthenticated(i)) + { m_players[i].Authorize(); m_players[i].SetSteamId(globals::engine->GetClientSteamID(i)); OnAuthorized(&m_players[i]); @@ -479,8 +472,7 @@ void PlayerManager::RunAuthChecks() void PlayerManager::OnAuthorized(CPlayer* player) const { - CSSHARP_CORE_TRACE("[PlayerManager][OnAuthorized] - {} {}", player->GetName(), - player->GetSteamId()->ConvertToUint64()); + CSSHARP_CORE_TRACE("[PlayerManager][OnAuthorized] - {} {}", player->GetName(), player->GetSteamId()->ConvertToUint64()); m_on_client_authorized_callback->ScriptContext().Reset(); m_on_client_authorized_callback->ScriptContext().Push(player->m_slot.Get()); @@ -492,7 +484,8 @@ bool CPlayer::WasCountedAsInGame() const { return m_is_in_game; } int CPlayer::GetUserId() { - if (m_user_id == -1) { + if (m_user_id == -1) + { m_user_id = globals::engine->GetPlayerUserId(m_slot).Get(); } @@ -523,10 +516,7 @@ int CPlayer::GetFrags() const { return m_info->GetFragCount(); } int CPlayer::GetDeaths() const { return m_info->GetDeathCount(); } -const char* CPlayer::GetKeyValue(const char* key) const -{ - return globals::engine->GetClientConVarValue(m_slot, key); -} +const char* CPlayer::GetKeyValue(const char* key) const { return globals::engine->GetClientConVarValue(m_slot, key); } Vector CPlayer::GetMaxSize() const { return m_info->GetPlayerMaxs(); } @@ -542,17 +532,15 @@ int CPlayer::GetUserId() const { return m_user_id; } float CPlayer::GetTimeConnected() const { - if (!IsConnected() || IsFakeClient()) { + if (!IsConnected() || IsFakeClient()) + { return 0; } return GetNetInfo()->GetTimeConnected(); } -void CPlayer::SetListen(CPlayerSlot slot, ListenOverride listen) -{ - m_listenMap[slot.Get()] = listen; -} +void CPlayer::SetListen(CPlayerSlot slot, ListenOverride listen) { m_listenMap[slot.Get()] = listen; } void CPlayer::SetVoiceFlags(VoiceFlag_t flags) { m_voiceFlag = flags; } @@ -562,7 +550,8 @@ ListenOverride CPlayer::GetListen(CPlayerSlot slot) const { return m_listenMap[s void CPlayer::Connect() { - if (m_is_in_game) { + if (m_is_in_game) + { return; } @@ -590,7 +579,8 @@ Vector CPlayer::GetAbsOrigin() const { return m_info->GetAbsOrigin(); } bool CPlayer::IsAlive() const { - if (!IsInGame()) { + if (!IsInGame()) + { return false; } @@ -599,4 +589,4 @@ bool CPlayer::IsAlive() const const CSteamID* CPlayer::GetSteamId() { return m_steamId; } void CPlayer::SetSteamId(const CSteamID* steam_id) { m_steamId = steam_id; } -} // namespace counterstrikesharp \ No newline at end of file +} // namespace counterstrikesharp diff --git a/src/core/managers/player_manager.h b/src/core/managers/player_manager.h index 25d0ae9a0..a1c8efca3 100644 --- a/src/core/managers/player_manager.h +++ b/src/core/managers/player_manager.h @@ -82,6 +82,7 @@ class CPlayer void Authorize(); public: + CPlayerSlot GetSlot() const; const char* GetName() const; const CSteamID* GetSteamId(); void SetSteamId(const CSteamID* steam_id); @@ -143,15 +144,15 @@ class PlayerManager : public GlobalClass PlayerManager(); void OnStartup() override; void OnAllInitialized() override; - bool OnClientConnect(CPlayerSlot slot, const char* pszName, uint64 xuid, - const char* pszNetworkID, bool unk1, CBufferString* pRejectReason); - bool OnClientConnect_Post(CPlayerSlot slot, const char* pszName, uint64 xuid, - const char* pszNetworkID, bool unk1, CBufferString* pRejectReason); + bool + OnClientConnect(CPlayerSlot slot, const char* pszName, uint64 xuid, const char* pszNetworkID, bool unk1, CBufferString* pRejectReason); + bool OnClientConnect_Post( + CPlayerSlot slot, const char* pszName, uint64 xuid, const char* pszNetworkID, bool unk1, CBufferString* pRejectReason); void OnClientPutInServer(CPlayerSlot slot, char const* pszName, int type, uint64 xuid); - void OnClientDisconnect(CPlayerSlot slot, ENetworkDisconnectionReason reason, - const char* pszName, uint64 xuid, const char* pszNetworkID); - void OnClientDisconnect_Post(CPlayerSlot slot, ENetworkDisconnectionReason reason, - const char* pszName, uint64 xuid, const char* pszNetworkID) const; + void + OnClientDisconnect(CPlayerSlot slot, ENetworkDisconnectionReason reason, const char* pszName, uint64 xuid, const char* pszNetworkID); + void OnClientDisconnect_Post( + CPlayerSlot slot, ENetworkDisconnectionReason reason, const char* pszName, uint64 xuid, const char* pszNetworkID) const; void OnClientVoice(CPlayerSlot slot) const; void OnAuthorized(CPlayer* player) const; void OnServerActivate(edict_t* pEdictList, int edictCount, int clientMax) const; @@ -188,4 +189,4 @@ class PlayerManager : public GlobalClass ScriptCallback* m_on_client_authorized_callback; }; -} // namespace counterstrikesharp \ No newline at end of file +} // namespace counterstrikesharp diff --git a/src/scripting/natives/natives_entities.cpp b/src/scripting/natives/natives_entities.cpp index b01ae74ce..da2a97059 100644 --- a/src/scripting/natives/natives_entities.cpp +++ b/src/scripting/natives/natives_entities.cpp @@ -19,6 +19,8 @@ #include #include + +#include "core/coreconfig.h" #include "core/log.h" #include "core/managers/entity_manager.h" #include "core/managers/player_manager.h" @@ -172,18 +174,40 @@ unsigned long GetPlayerAuthorizedSteamID(ScriptContext& script_context) auto iSlot = script_context.GetArgument(0); auto pPlayer = globals::playerManager.GetPlayerBySlot(iSlot); - if (pPlayer == nullptr || !pPlayer->m_is_authorized) + if (pPlayer == nullptr) { return -1; } - auto pSteamId = pPlayer->GetSteamId(); - if (pSteamId == nullptr) + if (globals::coreConfig->SteamAuth == Off) + { + return globals::engine->GetClientSteamID(pPlayer->GetSlot())->ConvertToUint64(); + } + + if (globals::coreConfig->SteamAuth == Flexible) + { + auto pSteamId = pPlayer->GetSteamId(); + if (pSteamId == nullptr) + { + return globals::engine->GetClientSteamID(pPlayer->GetSlot())->ConvertToUint64(); + } + + return pSteamId->ConvertToUint64(); + } + + // Default to "Strict" + if (!pPlayer->m_is_authorized) { return -1; } - return pSteamId->ConvertToUint64(); + auto pSteamId = pPlayer->GetSteamId(); + if (pSteamId != nullptr) + { + return pSteamId->ConvertToUint64(); + } + + return -1; } const char* GetPlayerIpAddress(ScriptContext& script_context)