From d4b278e569da5814ee7fc67c6caaa4f6074ae70e Mon Sep 17 00:00:00 2001 From: Ty Conner Date: Tue, 14 Jan 2025 20:55:39 -0500 Subject: [PATCH] Add filter support to qst command (#4257) --- .../ACE.Common/Extensions/StringExtensions.cs | 6 +++++ .../Command/Handlers/AdminCommands.cs | 23 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Source/ACE.Common/Extensions/StringExtensions.cs b/Source/ACE.Common/Extensions/StringExtensions.cs index ac9111e6f1..d6c7716d9f 100644 --- a/Source/ACE.Common/Extensions/StringExtensions.cs +++ b/Source/ACE.Common/Extensions/StringExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Text.RegularExpressions; namespace ACE.Common.Extensions { @@ -52,5 +53,10 @@ public static string TrimEnd(this string result, string trimEnd) return result; } + + public static string WildCardToRegular(this string value) + { + return "^" + Regex.Escape(value).Replace("\\*", ".*") + "$"; + } } } diff --git a/Source/ACE.Server/Command/Handlers/AdminCommands.cs b/Source/ACE.Server/Command/Handlers/AdminCommands.cs index 8e3a332da5..cae651fe21 100644 --- a/Source/ACE.Server/Command/Handlers/AdminCommands.cs +++ b/Source/ACE.Server/Command/Handlers/AdminCommands.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Net; +using System.Text.RegularExpressions; using System.Threading; using log4net; @@ -3606,9 +3607,18 @@ public static void Handleqst(Session session, params string[] parameters) var quests = creature.QuestManager.GetQuests(); + var filter = string.Empty; + if (parameters.Length >= 2) + { + filter = parameters[1].ToString(); + + if (!string.IsNullOrWhiteSpace(filter)) + quests = quests.Where(q => Regex.IsMatch(q.QuestName, filter.WildCardToRegular(), RegexOptions.IgnoreCase)).ToList(); + } + if (quests.Count == 0) { - session.Player.SendMessage("No quests found."); + session.Player.SendMessage($"No quests found{(!string.IsNullOrWhiteSpace(filter) ? $" with filter {filter}" : "")}."); return; } @@ -3876,9 +3886,18 @@ public static void Handleqst(Session session, params string[] parameters) var quests = fellowship.QuestManager.GetQuests(); + var filter = string.Empty; + if (parameters.Length >= 2) + { + filter = parameters[1].ToString(); + + if (!string.IsNullOrWhiteSpace(filter)) + quests = quests.Where(q => Regex.IsMatch(q.QuestName, filter.WildCardToRegular(), RegexOptions.IgnoreCase)).ToList(); + } + if (quests.Count == 0) { - session.Player.SendMessage("No quests found."); + session.Player.SendMessage($"No quests found{(!string.IsNullOrWhiteSpace(filter) ? $" with filter {filter}" : "")}."); return; }