Skip to content

Commit

Permalink
fix: Config bypass service
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed May 18, 2024
1 parent c6d24b7 commit f5c1409
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 19 deletions.
25 changes: 13 additions & 12 deletions src/KitsuneSteamRestrict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,23 @@ private bool IsRestrictionViolated(CCSPlayerController player, SteamUserInfo use
return false;

BypassConfig bypassConfig = _bypassConfig ?? new BypassConfig();
PlayerBypassConfig? playerBypassConfig = bypassConfig.GetPlayerConfig(player.AuthorizedSteamID?.SteamId64 ?? 0);

bool isPrime = userInfo.HasPrime;
var configChecks = new[]
{
(isPrime && !bypassConfig.BypassMinimumCS2Level, Config.MinimumCS2LevelPrime, userInfo.CS2Level),
(!isPrime && !bypassConfig.BypassMinimumCS2Level, Config.MinimumCS2LevelNonPrime, userInfo.CS2Level),
(isPrime && !bypassConfig.BypassMinimumHours, Config.MinimumHourPrime, userInfo.CS2Playtime),
(!isPrime && !bypassConfig.BypassMinimumHours, Config.MinimumHourNonPrime, userInfo.CS2Playtime),
(isPrime && !bypassConfig.BypassMinimumLevel, Config.MinimumLevelPrime, userInfo.SteamLevel),
(!isPrime && !bypassConfig.BypassMinimumLevel, Config.MinimumLevelNonPrime, userInfo.SteamLevel),
(!bypassConfig.BypassMinimumSteamAccountAge, Config.MinimumSteamAccountAgeInDays, (DateTime.Now - userInfo.SteamAccountAge).TotalDays),
(Config.BlockPrivateProfile && !bypassConfig.BypassPrivateProfile, 1, userInfo.IsPrivate ? 0 : 1),
(Config.BlockTradeBanned && !bypassConfig.BypassTradeBanned, 1, userInfo.IsTradeBanned ? 0 : 1),
(Config.BlockGameBanned && !bypassConfig.BypassGameBanned, 1, userInfo.IsGameBanned ? 0 : 1),
(!string.IsNullOrEmpty(Config.SteamGroupID) && !bypassConfig.BypassSteamGroupCheck, 1, userInfo.IsInSteamGroup ? 1 : 0),
(Config.BlockVACBanned && !bypassConfig.BypassVACBanned, 1, userInfo.IsVACBanned ? 0 : 1),
(isPrime && (playerBypassConfig?.BypassMinimumCS2Level ?? false), Config.MinimumCS2LevelPrime, userInfo.CS2Level),
(!isPrime && (playerBypassConfig?.BypassMinimumCS2Level ?? false), Config.MinimumCS2LevelNonPrime, userInfo.CS2Level),
(isPrime && (playerBypassConfig?.BypassMinimumHours ?? false), Config.MinimumHourPrime, userInfo.CS2Playtime),
(!isPrime && (playerBypassConfig?.BypassMinimumHours ?? false), Config.MinimumHourNonPrime, userInfo.CS2Playtime),
(isPrime && (playerBypassConfig?.BypassMinimumLevel ?? false), Config.MinimumLevelPrime, userInfo.SteamLevel),
(!isPrime && (playerBypassConfig?.BypassMinimumLevel ?? false), Config.MinimumLevelNonPrime, userInfo.SteamLevel),
(playerBypassConfig?.BypassMinimumSteamAccountAge ?? false, Config.MinimumSteamAccountAgeInDays, (DateTime.Now - userInfo.SteamAccountAge).TotalDays),
(Config.BlockPrivateProfile && (playerBypassConfig?.BypassPrivateProfile ?? false), 1, userInfo.IsPrivate ? 0 : 1),
(Config.BlockTradeBanned && (playerBypassConfig?.BypassTradeBanned ?? false), 1, userInfo.IsTradeBanned ? 0 : 1),
(Config.BlockGameBanned && (playerBypassConfig?.BypassGameBanned ?? false), 1, userInfo.IsGameBanned ? 0 : 1),
(!string.IsNullOrEmpty(Config.SteamGroupID) && (playerBypassConfig?.BypassSteamGroupCheck ?? false), 1, userInfo.IsInSteamGroup ? 1 : 0),
(Config.BlockVACBanned && (playerBypassConfig?.BypassVACBanned ?? false), 1, userInfo.IsVACBanned ? 0 : 1),
};

return configChecks.Any(check => check.Item1 && check.Item2 != -1 && check.Item3 < check.Item2);
Expand Down
58 changes: 51 additions & 7 deletions src/Models/BypassConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace KitsuneSteamRestrict
{
public class BypassConfig
public class PlayerBypassConfig
{
public ulong SteamID { get; set; }
public bool BypassMinimumCS2Level { get; set; } = false;
public bool BypassMinimumHours { get; set; } = false;
public bool BypassMinimumLevel { get; set; } = false;
Expand All @@ -16,6 +15,29 @@ public class BypassConfig
public bool BypassGameBanned { get; set; } = false;
}

public class BypassConfig
{
private Dictionary<ulong, PlayerBypassConfig> _playerConfigs = new Dictionary<ulong, PlayerBypassConfig>();

public PlayerBypassConfig? GetPlayerConfig(ulong steamID)
{
if (_playerConfigs.TryGetValue(steamID, out var playerConfig))
return playerConfig;

return null;
}

public void AddPlayerConfig(ulong steamID, PlayerBypassConfig playerConfig)
{
_playerConfigs[steamID] = playerConfig;
}

public Dictionary<ulong, PlayerBypassConfig> GetAllPlayerConfigs()
{
return _playerConfigs;
}
}

public class BypassConfigService
{
private readonly string _configFilePath;
Expand All @@ -30,13 +52,22 @@ public BypassConfig LoadConfig()
if (File.Exists(_configFilePath))
{
string json = File.ReadAllText(_configFilePath);
return JsonSerializer.Deserialize<BypassConfig>(json)!;
var playerConfigs = JsonSerializer.Deserialize<Dictionary<ulong, PlayerBypassConfig>>(json)!;
var bypassConfig = new BypassConfig();

foreach (var kvp in playerConfigs)
{
bypassConfig.AddPlayerConfig(kvp.Key, kvp.Value);
}

return bypassConfig;
}
else
{
BypassConfig defaultConfig = new BypassConfig
var defaultConfig = new BypassConfig();

defaultConfig.AddPlayerConfig(76561198345583467, new PlayerBypassConfig
{
SteamID = 76561198345583467,
BypassMinimumCS2Level = true,
BypassMinimumHours = false,
BypassMinimumLevel = true,
Expand All @@ -46,9 +77,22 @@ public BypassConfig LoadConfig()
BypassVACBanned = true,
BypassSteamGroupCheck = false,
BypassGameBanned = true
};
});

defaultConfig.AddPlayerConfig(76561198132924835, new PlayerBypassConfig
{
BypassMinimumCS2Level = false,
BypassMinimumHours = true,
BypassMinimumLevel = false,
BypassMinimumSteamAccountAge = true,
BypassPrivateProfile = false,
BypassTradeBanned = true,
BypassVACBanned = false,
BypassSteamGroupCheck = true,
BypassGameBanned = false
});

string json = JsonSerializer.Serialize(defaultConfig, new JsonSerializerOptions { WriteIndented = true });
string json = JsonSerializer.Serialize(defaultConfig.GetAllPlayerConfigs(), new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(_configFilePath, json);

return defaultConfig;
Expand Down

0 comments on commit f5c1409

Please sign in to comment.