Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "SteamAuth" core config option #432

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions configs/addons/counterstrikesharp/configs/core.example.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"PublicChatTrigger": [ "!" ],
"SilentChatTrigger": [ "/" ],
"FollowCS2ServerGuidelines": true,
"PluginHotReloadEnabled": true,
"PluginAutoLoadEnabled": true,
"ServerLanguage": "en",
"UnlockConCommands": true,
"UnlockConVars": true
}
"PublicChatTrigger": [
"!"
],
"SilentChatTrigger": [
"/"
],
"FollowCS2ServerGuidelines": true,
"PluginHotReloadEnabled": true,
"PluginAutoLoadEnabled": true,
"ServerLanguage": "en",
"UnlockConCommands": true,
"UnlockConVars": true,
"SteamAuth": "Strict"
}
9 changes: 9 additions & 0 deletions docfx/docs/reference/core-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
15 changes: 15 additions & 0 deletions managed/CounterStrikeSharp.API/Core/CoreConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

/// <summary>
Expand Down Expand Up @@ -115,6 +118,18 @@ public partial class CoreConfig

public static bool UnlockConVars => _coreConfig.UnlockConVars;


/// <summary>
/// Configures the strictness of <see cref="CCSPlayerController.AuthorizedSteamID"/>
///
/// <list type="bullet">
/// <item>"Strict": CS# will only grant permissions to users if the server is currently connected to steam and the user has passed auth checks.</item>
/// <item>"Flexible" CS# will try to use the users checked steam auth, but failing that will use standard SteamID.</item>
/// <item>"Off": CS# will always just use the standard SteamID.</item>
/// </list>
/// </summary>
public static string SteamAuth => _coreConfig.SteamAuth;

}

public partial class CoreConfig : IStartupService
Expand Down
9 changes: 9 additions & 0 deletions src/core/coreconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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<SteamAuthStrictness>();
}
catch (const std::exception& ex)
{
Expand Down
8 changes: 8 additions & 0 deletions src/core/coreconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@

namespace counterstrikesharp {

enum SteamAuthStrictness
{
Strict,
Flexible,
Off
};

class CCoreConfig
{
public:
Expand All @@ -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);
Expand Down
234 changes: 112 additions & 122 deletions src/core/managers/player_manager.cpp

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions src/core/managers/player_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -188,4 +189,4 @@ class PlayerManager : public GlobalClass
ScriptCallback* m_on_client_authorized_callback;
};

} // namespace counterstrikesharp
} // namespace counterstrikesharp
32 changes: 28 additions & 4 deletions src/scripting/natives/natives_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <ios>
#include <sstream>


#include "core/coreconfig.h"
#include "core/log.h"
#include "core/managers/entity_manager.h"
#include "core/managers/player_manager.h"
Expand Down Expand Up @@ -172,18 +174,40 @@ unsigned long GetPlayerAuthorizedSteamID(ScriptContext& script_context)
auto iSlot = script_context.GetArgument<int>(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)
Expand Down
Loading