From f5c1409ddfc2dda51df192c51a1adaa8dc497502 Mon Sep 17 00:00:00 2001 From: K4ryuu <104531589+K4ryuu@users.noreply.github.com> Date: Sat, 18 May 2024 19:16:00 +0200 Subject: [PATCH] fix: Config bypass service --- src/KitsuneSteamRestrict.cs | 25 ++++++------- src/Models/BypassConfigService.cs | 58 +++++++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/KitsuneSteamRestrict.cs b/src/KitsuneSteamRestrict.cs index 45f311b..d21051c 100644 --- a/src/KitsuneSteamRestrict.cs +++ b/src/KitsuneSteamRestrict.cs @@ -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); diff --git a/src/Models/BypassConfigService.cs b/src/Models/BypassConfigService.cs index 6c2c479..698e18e 100644 --- a/src/Models/BypassConfigService.cs +++ b/src/Models/BypassConfigService.cs @@ -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; @@ -16,6 +15,29 @@ public class BypassConfig public bool BypassGameBanned { get; set; } = false; } + public class BypassConfig + { + private Dictionary _playerConfigs = new Dictionary(); + + 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 GetAllPlayerConfigs() + { + return _playerConfigs; + } + } + public class BypassConfigService { private readonly string _configFilePath; @@ -30,13 +52,22 @@ public BypassConfig LoadConfig() if (File.Exists(_configFilePath)) { string json = File.ReadAllText(_configFilePath); - return JsonSerializer.Deserialize(json)!; + var playerConfigs = JsonSerializer.Deserialize>(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, @@ -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;