Skip to content

Commit

Permalink
feat: VAC ban blocker feature
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed Apr 6, 2024
1 parent 29d015a commit 432170e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/KitsuneSteamRestrict.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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; } = "";

Expand Down Expand Up @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion src/Models/SteamService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 432170e

Please sign in to comment.