From 432170eae8fc4f9871a73892988818944b38e104 Mon Sep 17 00:00:00 2001 From: K4ryuu <104531589+K4ryuu@users.noreply.github.com> Date: Sat, 6 Apr 2024 15:37:22 +0200 Subject: [PATCH] feat: VAC ban blocker feature --- CHANGELOG | 2 ++ src/KitsuneSteamRestrict.cs | 9 +++++---- src/Models/SteamService.cs | 14 +++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3bbc2de..2c523bd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ -- 2024. 04. 06 - v1.2.0 - feat: Created SteamService model +- feat: Block players if VAC banned +- feat: Block players if not in steam group - optimise: Full plugin refactoring -- 2024. 02. 14 - v1.1.3 diff --git a/src/KitsuneSteamRestrict.cs b/src/KitsuneSteamRestrict.cs index be7c489..559123b 100644 --- a/src/KitsuneSteamRestrict.cs +++ b/src/KitsuneSteamRestrict.cs @@ -1,11 +1,8 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes; -using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Timers; -using Steamworks; -using Newtonsoft.Json.Linq; using System.Text.Json.Serialization; using Microsoft.Extensions.Logging; using CounterStrikeSharp.API.Modules.Admin; @@ -44,6 +41,9 @@ public class PluginConfig : BasePluginConfig [JsonPropertyName("BlockTradeBanned")] public bool BlockTradeBanned { get; set; } = false; + [JsonPropertyName("BlockVACBanned")] + public bool BlockVACBanned { get; set; } = false; + [JsonPropertyName("SteamGroupID")] public string SteamGroupID { get; set; } = ""; @@ -190,7 +190,8 @@ private bool IsRestrictionViolated(CCSPlayerController player, SteamUserInfo use (Config.BlockPrivateProfile, 1, userInfo.IsPrivate ? 0 : 1), (Config.BlockTradeBanned, 1, userInfo.IsTradeBanned ? 0 : 1), (Config.BlockGameBanned, 1, userInfo.IsGameBanned ? 0 : 1), - (!string.IsNullOrEmpty(Config.SteamGroupID), 1, userInfo.IsInSteamGroup ? 0 : 1) + (!string.IsNullOrEmpty(Config.SteamGroupID), 1, userInfo.IsInSteamGroup ? 0 : 1), + (Config.BlockVACBanned, 1, userInfo.IsVACBanned ? 0 : 1), }; return configChecks.Any(check => check.Item1 && check.Item2 != -1 && check.Item3 < check.Item2); diff --git a/src/Models/SteamService.cs b/src/Models/SteamService.cs index c91d754..b220699 100644 --- a/src/Models/SteamService.cs +++ b/src/Models/SteamService.cs @@ -14,6 +14,7 @@ public class SteamUserInfo public bool IsPrivate { get; set; } public bool HasPrime { get; set; } public bool IsTradeBanned { get; set; } + public bool IsVACBanned { get; set; } public bool IsGameBanned { get; set; } public bool IsInSteamGroup { get; set; } } @@ -80,7 +81,11 @@ private async Task FetchTradeBanStatusAsync(string steamId, SteamUserInfo userIn { var url = $"https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key={_steamWebAPIKey}&steamids={steamId}"; var json = await GetApiResponseAsync(url); - if (json != null) ParseTradeBanStatus(json, userInfo); + if (json != null) + { + ParseTradeBanStatus(json, userInfo); + ParseVACBanStatus(json, userInfo); + } } private async Task FetchGameBanStatusAsync(string steamId, SteamUserInfo userInfo) @@ -171,4 +176,11 @@ private void ParseGameBanStatus(string json, SteamUserInfo userInfo) JToken? userGameBan = data["players"]?.FirstOrDefault(); userInfo.IsGameBanned = userGameBan != null && (bool)(userGameBan["IsGameBanned"] ?? false); } + + private void ParseVACBanStatus(string json, SteamUserInfo userInfo) + { + JObject data = JObject.Parse(json); + JToken? userGameBan = data["players"]?.FirstOrDefault(); + userInfo.IsVACBanned = userGameBan != null && (bool)(userGameBan["VACBanned"] ?? false); + } }