From bf4423ee5b924b02f247acf34a5e4dfeee1da3c7 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Mon, 9 Dec 2024 19:40:48 -0500 Subject: [PATCH 1/2] chore: Add package to deserialize json objects This change adds the System.Text.Json package to the project. --- Directory.Packages.props | 1 + src/Application/CTF.Application.csproj | 1 + src/Application/Usings.cs | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 89a44ba7..be585a5a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,6 +3,7 @@ true + diff --git a/src/Application/CTF.Application.csproj b/src/Application/CTF.Application.csproj index 2b91f1a9..aa30e1b6 100644 --- a/src/Application/CTF.Application.csproj +++ b/src/Application/CTF.Application.csproj @@ -5,6 +5,7 @@ + diff --git a/src/Application/Usings.cs b/src/Application/Usings.cs index 812f7993..a8705545 100644 --- a/src/Application/Usings.cs +++ b/src/Application/Usings.cs @@ -1,4 +1,5 @@ -global using System.Collections; +global using System.Text.Json; +global using System.Collections; global using System.Globalization; global using System.Reflection; global using System.Text.RegularExpressions; From d9de73a56444e12dff84f73b6dcdd9cb539c69af Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Mon, 9 Dec 2024 19:45:55 -0500 Subject: [PATCH 2/2] feat: Load banned players from bans.json file --- .../Players/GeneralCommands/AdminCommands.cs | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Application/Players/GeneralCommands/AdminCommands.cs b/src/Application/Players/GeneralCommands/AdminCommands.cs index d97035f5..d8d22e7b 100644 --- a/src/Application/Players/GeneralCommands/AdminCommands.cs +++ b/src/Application/Players/GeneralCommands/AdminCommands.cs @@ -106,20 +106,40 @@ public void ShowBannedIPs(Player currentPlayer) if (currentPlayer.HasLowerRoleThan(RoleId.Admin)) return; - var path = Path.Combine(Directory.GetCurrentDirectory(), "samp.ban"); - var bannedIPs = File.ReadAllLines(path); - if (bannedIPs.Length == 0) + var path = Path.Combine(Directory.GetCurrentDirectory(), "bans.json"); + var content = File.ReadAllText(path); + var options = new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true + }; + var bannedPlayers = JsonSerializer.Deserialize(content, options); + if (bannedPlayers.Length == 0) { currentPlayer.SendClientMessage(Color.Red, Messages.NoMatchFound); return; } - var dialog = new ListDialog(caption: $"Banned IPs: {bannedIPs.Length}", "Close"); - foreach (string bannedIP in bannedIPs) + var dialog = new ListDialog(caption: $"Banned Players: {bannedPlayers.Length}", "Close"); + foreach (BannedPlayer bannedPlayer in bannedPlayers) { - dialog.Add(bannedIP); + dialog.Add(bannedPlayer.ToString()); } dialogService.ShowAsync(currentPlayer, dialog); } + + private class BannedPlayer + { + public string Address { get; set; } = string.Empty; + public string Player { get; set; } = string.Empty; + public string Reason { get; set; } = string.Empty; + public string Time { get; set; } = "2023-12-07T16:05:21-0500"; + public override string ToString() + { + var dt = DateTimeOffset.Parse(Time).DateTime; + var date = dt.ToString("yyyy/MM/dd"); + var time = dt.ToString("HH:mm:ss"); + return $"{Address} [{date} | {time}] {Player} - {Reason}"; + } + } }