Skip to content

Commit

Permalink
Add filter support to qst command (#4257)
Browse files Browse the repository at this point in the history
  • Loading branch information
LtRipley36706 authored Jan 15, 2025
1 parent 10fac6b commit d4b278e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Source/ACE.Common/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text.RegularExpressions;

namespace ACE.Common.Extensions
{
Expand Down Expand Up @@ -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("\\*", ".*") + "$";
}
}
}
23 changes: 21 additions & 2 deletions Source/ACE.Server/Command/Handlers/AdminCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;

using log4net;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit d4b278e

Please sign in to comment.