From 52c270a2104e990cc38056d5c8eec2df7ef654de Mon Sep 17 00:00:00 2001 From: "Robin C. Ladiges" Date: Wed, 22 Mar 2023 21:48:53 +0100 Subject: [PATCH] add command: `unban profile ` To remove a banned profile ID from the ban list. --- Server/BanLists.cs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Server/BanLists.cs b/Server/BanLists.cs index b1194a0..9e257c7 100644 --- a/Server/BanLists.cs +++ b/Server/BanLists.cs @@ -107,6 +107,17 @@ public static class BanLists { IPs.Remove(ipv4); } + private static void UnbanProfile(Client user) { + UnbanProfile(user.Id); + } + private static void UnbanProfile(string str) { + if (!Guid.TryParse(str, out Guid id)) { return; } + UnbanProfile(id); + } + private static void UnbanProfile(Guid id) { + Profiles.Remove(id); + } + private static void Save() { Settings.SaveSettings(true); @@ -203,7 +214,7 @@ public static class BanLists { public static string HandleUnbanCommand(string[] args) { if (args.Length != 2) { - return "Usage: unban ip "; + return "Usage: unban {profile|ip} "; } string cmd = args[0]; @@ -211,7 +222,18 @@ public static class BanLists { switch (cmd) { default: - return "Usage: unban ip "; + return "Usage: unban {profile|ip} "; + + case "profile": + if (!Guid.TryParse(val, out Guid id)) { + return "Invalid profile ID value!"; + } + if (!IsProfileBanned(id)) { + return "Profile " + id.ToString() + " is not banned."; + } + UnbanProfile(id); + Save(); + return "Unbanned profile: " + id.ToString(); case "ip": if (!IsIPv4(val)) {