Snapshot for release 2026.10.28.3 (internal 1eeafca)
This commit is contained in:
parent
f9ae10d692
commit
0bfe184288
19 changed files with 1510 additions and 454 deletions
|
|
@ -1130,12 +1130,16 @@ internal static class AcMainThreadQueue
|
|||
// Dispatch() itself (rather than at each caller) covers all three at once.
|
||||
// A full command line can't ride the uint Entry ring, so it gets its own
|
||||
// string queue, same shape as the WriteToChat slot above.
|
||||
private static readonly System.Collections.Generic.Queue<(string Text, long At, int Epoch)> _chatCommandQueue = new();
|
||||
private static readonly System.Collections.Generic.Queue<(string Text, long At, int Epoch, ChatCommandOrigin Origin)> _chatCommandQueue = new();
|
||||
private static readonly object _chatCommandLock = new();
|
||||
private const int MaxChatCommandQueue = 64;
|
||||
|
||||
// Off-thread enqueue. Drops (returns false) if the queue is full.
|
||||
public static bool EnqueueChatCommand(string text)
|
||||
public static bool EnqueueChatCommand(string text) => EnqueueChatCommand(text, ChatCommandOrigin.Script);
|
||||
|
||||
// The same, saying who sent the line (Player: a RynthCore hotkey), for the answer of an engine
|
||||
// /rc command (ChatCommandDispatcher.Dispatch, RynthCoreChatCommands).
|
||||
public static bool EnqueueChatCommand(string text, ChatCommandOrigin origin)
|
||||
{
|
||||
lock (_chatCommandLock)
|
||||
{
|
||||
|
|
@ -1144,7 +1148,7 @@ internal static class AcMainThreadQueue
|
|||
Interlocked.Increment(ref _dropped);
|
||||
return false;
|
||||
}
|
||||
_chatCommandQueue.Enqueue((text, NowMs, Volatile.Read(ref _loginEpoch)));
|
||||
_chatCommandQueue.Enqueue((text, NowMs, Volatile.Read(ref _loginEpoch), origin));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1162,7 +1166,7 @@ internal static class AcMainThreadQueue
|
|||
int epoch = Volatile.Read(ref _loginEpoch);
|
||||
while (budget-- > 0)
|
||||
{
|
||||
(string Text, long At, int Epoch) item;
|
||||
(string Text, long At, int Epoch, ChatCommandOrigin Origin) item;
|
||||
lock (_chatCommandLock)
|
||||
{
|
||||
if (_chatCommandQueue.Count == 0) return;
|
||||
|
|
@ -1173,7 +1177,7 @@ internal static class AcMainThreadQueue
|
|||
NoteStale("a chat command", now - item.At, dropped: true);
|
||||
continue;
|
||||
}
|
||||
try { ChatCommandDispatcher.Dispatch(item.Text); }
|
||||
try { ChatCommandDispatcher.Dispatch(item.Text, item.Origin); }
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -563,12 +563,18 @@ internal static class ChatCallbackHooks
|
|||
|
||||
// RynthCore engine commands (/rc ...) — consume before plugins or
|
||||
// AC see the line so the user never broadcasts "/rc resetbar" and
|
||||
// a hidden overlay bar stays recoverable.
|
||||
if (RynthCoreChatCommands.TryHandle(line))
|
||||
// a hidden overlay bar stays recoverable. Typed by the player: every
|
||||
// reply goes to chat.
|
||||
if (RynthCoreChatCommands.TryHandle(line, ChatCommandOrigin.Player))
|
||||
return 1;
|
||||
|
||||
if (PluginManager.DispatchChatBarEnter(line))
|
||||
return 1;
|
||||
// A /rc line a plugin runs while it handles this one (RynthAi's /ra videopatch) is the
|
||||
// player's too, so it answers in chat.
|
||||
using (RynthCoreChatCommands.PlayerLine())
|
||||
{
|
||||
if (PluginManager.DispatchChatBarEnter(line))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return _originalOutgoingChat!(thisPtr, text, commandSource);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,7 +108,14 @@ internal static unsafe class ChatCommandDispatcher
|
|||
}
|
||||
}
|
||||
|
||||
public static bool Dispatch(string? text)
|
||||
/// <summary>A line from a plugin, a command file or the login commands (<see cref="ChatCommandOrigin.Script"/>).</summary>
|
||||
public static bool Dispatch(string? text) => Dispatch(text, ChatCommandOrigin.Script);
|
||||
|
||||
/// <summary>
|
||||
/// Runs a chat line as if typed. <paramref name="origin"/> says who sent it, for the answer of an
|
||||
/// engine /rc command (RynthCoreChatCommands): Player for a RynthCore hotkey, Script for the rest.
|
||||
/// </summary>
|
||||
public static bool Dispatch(string? text, ChatCommandOrigin origin)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
return false;
|
||||
|
|
@ -128,7 +135,7 @@ internal static unsafe class ChatCommandDispatcher
|
|||
// from the drain, where IsOnMainThread is satisfied and the body
|
||||
// below runs directly — so there's only one code path to keep in sync.
|
||||
if (!MainThreadGuard.IsOnMainThread())
|
||||
return AcMainThreadQueue.EnqueueChatCommand(text);
|
||||
return AcMainThreadQueue.EnqueueChatCommand(text, origin);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -139,7 +146,7 @@ internal static unsafe class ChatCommandDispatcher
|
|||
// RynthCore engine commands (/rc ...) are handled before plugin
|
||||
// pre-dispatch and before any AC chat routing so they work even
|
||||
// when the overlay is hidden and no plugin can eat the line.
|
||||
if (RynthCoreChatCommands.TryHandle(trimmed))
|
||||
if (RynthCoreChatCommands.TryHandle(trimmed, origin))
|
||||
return true;
|
||||
|
||||
// Expand shorthand: /s → /say, /t → /tell, /e → /emote
|
||||
|
|
@ -161,7 +168,15 @@ internal static unsafe class ChatCommandDispatcher
|
|||
_inPluginPreDispatch = true;
|
||||
try
|
||||
{
|
||||
if (PluginManager.DispatchChatBarEnter(trimmed))
|
||||
// The player's line (a hotkey's /ra command): a /rc line a plugin runs while it
|
||||
// handles it is the player's too (RynthCoreChatCommands.PlayerLine).
|
||||
if (origin == ChatCommandOrigin.Player)
|
||||
{
|
||||
using (RynthCoreChatCommands.PlayerLine())
|
||||
if (PluginManager.DispatchChatBarEnter(trimmed))
|
||||
return true;
|
||||
}
|
||||
else if (PluginManager.DispatchChatBarEnter(trimmed))
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
376
src/RynthCore.Engine/Compatibility/ChatCommandReplies.cs
Normal file
376
src/RynthCore.Engine/Compatibility/ChatCommandReplies.cs
Normal file
|
|
@ -0,0 +1,376 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - Compatibility/ChatCommandReplies.cs
|
||||
//
|
||||
// How the engine's chat commands (/rc ..., /rv plates) answer. Every command a
|
||||
// player types gets a clear line back: what changed and the value now, or why
|
||||
// not with the usage (2026-10-28: "It should tell you whether it worked for
|
||||
// every single command a player punches in").
|
||||
//
|
||||
// The pure part (no AC, no engine state), so tools\ChatCommandReplyTests can
|
||||
// compile it in: who a line came from and whether a reply goes to chat or only
|
||||
// to the log, the two reply colours, every verb with its usage, the argument
|
||||
// check made before a command runs, and the reply texts built from plain
|
||||
// values. Writing the reply (log + chat) is RynthCoreChatCommands.Reply.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace RynthCore.Engine.Compatibility;
|
||||
|
||||
/// <summary>Who an engine command line came from (<see cref="RynthCoreChatCommands.TryHandle"/>).</summary>
|
||||
internal enum ChatCommandOrigin
|
||||
{
|
||||
/// <summary>
|
||||
/// A plugin (Host.InvokeChatParser: a meta, a window's button), the command files (dispatch.txt,
|
||||
/// RynthRemote's sendchat), the login commands, or one of the engine's own buttons and menus.
|
||||
/// A reply that says it worked goes to the log only; one that says it didn't still goes to chat.
|
||||
/// </summary>
|
||||
Script = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The player: typed in AC's chat bar or RynthChat's, a RynthCore hotkey, or a line a plugin passes
|
||||
/// on while it handles one the player typed (/ra videopatch runs /rc videopatch). Every reply goes
|
||||
/// to chat.
|
||||
/// </summary>
|
||||
Player = 1,
|
||||
}
|
||||
|
||||
/// <summary>What a reply says: it worked (or here is the state), or it didn't.</summary>
|
||||
internal enum ChatReplyKind
|
||||
{
|
||||
Ok = 0,
|
||||
Fail = 1,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One engine verb: its name, other spellings, usage, and the argument check made before it runs
|
||||
/// (<see cref="Args"/> null: the command's own handler checks its arguments and answers with its usage).
|
||||
/// </summary>
|
||||
internal sealed record ChatVerb(string Name, string[] Aliases, string Usage, Func<string, bool>? Args);
|
||||
|
||||
/// <summary>What the check before a command runs found: the verb (null: unknown), its arguments, and
|
||||
/// the reply when the command can't run (null: run it).</summary>
|
||||
internal readonly record struct ChatVerbCheck(ChatVerb? Verb, string Args, string? Problem);
|
||||
|
||||
internal static class ChatCommandReplies
|
||||
{
|
||||
/// <summary>Every engine reply starts with this (the style since the first /rc command).</summary>
|
||||
public const string ReplyPrefix = "[RynthCore] ";
|
||||
|
||||
/// <summary>ChatMessageType 0x01, green in AC's chat: it worked, or the state.</summary>
|
||||
public const int OkChatType = 1;
|
||||
|
||||
/// <summary>ChatMessageType 0x1A, red: the type AC prints its own command notices in
|
||||
/// ("Someone must @tell you first!", ChatCommandDispatcher.ChatTypeNotice).</summary>
|
||||
public const int FailChatType = 0x1A;
|
||||
|
||||
// ── who sent it, where the reply goes ──────────────────────────────────
|
||||
|
||||
/// <summary>The origin a line is handled with: the player's when the caller says so, or when it
|
||||
/// arrives while a line the player typed is being handed on (RynthCoreChatCommands.PlayerLine).</summary>
|
||||
public static ChatCommandOrigin Effective(ChatCommandOrigin given, bool insidePlayerLine) =>
|
||||
given == ChatCommandOrigin.Player || insidePlayerLine ? ChatCommandOrigin.Player : ChatCommandOrigin.Script;
|
||||
|
||||
/// <summary>True when the reply goes to chat as well as the log: always for the player, and for
|
||||
/// anyone else only when it says the command didn't work.</summary>
|
||||
public static bool ToChat(ChatReplyKind kind, ChatCommandOrigin origin) =>
|
||||
kind == ChatReplyKind.Fail || origin == ChatCommandOrigin.Player;
|
||||
|
||||
/// <summary>The AC chat type (colour) a reply is written with.</summary>
|
||||
public static int ChatType(ChatReplyKind kind) => kind == ChatReplyKind.Fail ? FailChatType : OkChatType;
|
||||
|
||||
/// <summary>
|
||||
/// How the modules a command hands its arguments to (the video patch, flight recorder, report,
|
||||
/// AutoId, server messages, Discord relay, action gates) start a line that says the command
|
||||
/// didn't work. Their other lines are the state.
|
||||
/// </summary>
|
||||
private static readonly string[] FailOpenings =
|
||||
{
|
||||
"Usage", "Unknown", "Can't", "Not dumped", "Not capturing", "Capture failed", "Report not sent",
|
||||
"Log in first", "No route", "No hotkey on", "Which key", "Unlock skipped",
|
||||
"Video patch unavailable", "Video patch is switched off", "Flight recorder is off",
|
||||
"The server message stream is off", "The relay is off",
|
||||
};
|
||||
|
||||
/// <summary>Whether a line a module returned says the command didn't work.</summary>
|
||||
public static ChatReplyKind KindOfLine(string line)
|
||||
{
|
||||
string s = line.TrimStart();
|
||||
foreach (string f in FailOpenings)
|
||||
if (s.StartsWith(f, StringComparison.OrdinalIgnoreCase))
|
||||
return ChatReplyKind.Fail;
|
||||
return s.Contains("isn't available", StringComparison.OrdinalIgnoreCase) ? ChatReplyKind.Fail : ChatReplyKind.Ok;
|
||||
}
|
||||
|
||||
/// <summary>A module's reply lines as one answer: failed when any line says so.</summary>
|
||||
public static ChatReplyKind KindOfLines(IEnumerable<string> lines)
|
||||
{
|
||||
foreach (string l in lines)
|
||||
if (KindOfLine(l) == ChatReplyKind.Fail)
|
||||
return ChatReplyKind.Fail;
|
||||
return ChatReplyKind.Ok;
|
||||
}
|
||||
|
||||
// ── the verbs ──────────────────────────────────────────────────────────
|
||||
|
||||
public const string PlatesUsage =
|
||||
"Usage: /rv plates [on|off] | all on|off | self [numbers|name|firstperson|lock|debuffs] [on|off] | " +
|
||||
"self fixed|follow|unlock|reset | self debuffs size <50-200%> | " +
|
||||
"debuffs [on|off] | debuffs size <50-200%> | others [on|off] | numbers [dealt|taken|heals|kills] [on|off] | " +
|
||||
"gains [xp|lum|radiance] [on|off] | npcs [on|off] | npcs dist <yd>|max <n> | players [on|off] | portals [on|off] | portals dist <yd> | " +
|
||||
"all|engaged |dist <yd>|max <n>|scale <x>|opacity <x>|lift <m> | " +
|
||||
"names|hp|level|weak|distance|fade|click [on|off] | reset | status | test";
|
||||
|
||||
public const string ServerUsage =
|
||||
"Usage: /rc server [<server> auto|on|off] | pick <server>|auto | [aelrynth|other|auto] | names ilt [add|remove <pattern>]";
|
||||
|
||||
public const string HotkeyUsage =
|
||||
"Usage: /rc hotkey list | add <combo> <action or /command> | remove <combo> | enable|disable <combo> | actions | status | on|off";
|
||||
|
||||
/// <summary>The Classic dashboard look's tabs, in order (RynthAiDashboardState.SetClassicTab's index).</summary>
|
||||
public static readonly string[] ClassicTabNames = { "main", "monsters", "gear", "buffs", "route", "loot", "meta", "tuning" };
|
||||
|
||||
private static ChatVerb V(string name, string usage, Func<string, bool>? args, params string[] aliases) =>
|
||||
new(name, aliases, usage, args);
|
||||
|
||||
private static bool NoArgs(string a) => a.Length == 0;
|
||||
|
||||
private static Func<string, bool> Words(params string[] allowed) =>
|
||||
a => Array.Exists(allowed, w => w.Equals(a, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
private static bool PanelArgs(string a) => TryPanelMode(a, out _);
|
||||
|
||||
/// <summary>
|
||||
/// Every /rc verb RynthCoreChatCommands answers. Keep it in step with TryHandle: a verb missing
|
||||
/// here is answered as unknown before its handler runs (tools\ChatCommandReplyTests reads TryHandle
|
||||
/// and checks both ways).
|
||||
/// </summary>
|
||||
public static readonly ChatVerb[] Verbs =
|
||||
{
|
||||
V("vendor", "Usage: /rc vendor list | info | status | buy <id|sel> [n] | sell <id|sel> [id ...]", null),
|
||||
V("imgui", "Usage: /rc imgui on|off|fonttest|diag", Words("", "on", "off", "fonttest", "diag")),
|
||||
V("ui", "Usage: /rc ui list | open|close|popout|redock|snap <Panel> | channels | retailvitals [on|off] | retailtoolbar [on|off] | barsize [0-10|+|-|status] | barrows [1-6|+|-] | baricons [2-30|none|+|-]", null),
|
||||
V("chathold", "Usage: /rc chathold [on|off|status]", Words("", "on", "off", "status")),
|
||||
V("discord", "Usage: /rc discord [on|off|status|window|test [route]|resume [route]]", null),
|
||||
V("plates", PlatesUsage, null, "nameplates"),
|
||||
V("server", ServerUsage, null),
|
||||
V("ilt", "Usage: /rc ilt [auto|on|off]", Words("", "on", "ilt", "off", "other", "auto")),
|
||||
V("mastery", "Usage: /rc mastery (the Aelrynth mastery feed's state; asks the server again)", null),
|
||||
V("worldlayer", "Usage: /rc worldlayer [auto|uipass|transition|endscene|status]",
|
||||
Words("", "status", "auto", "uipass", "ui", "transition", "zenable", "endscene")),
|
||||
V("acmouse", "Usage: /rc acmouse [watch [seconds]]", a => a.Length == 0 || IsVerb(a, "watch", out _), "mouseover"),
|
||||
V("video", "Usage: /rc video [status|enable|disable|off|world|unfocused|all|fps <n>]", null, "videopatch"),
|
||||
V("hooks", "Usage: /rc hooks [status] | /rc hooks on|off <name>", null, "uihooks"),
|
||||
V("flightdump", "Usage: /rc flightdump [note] | /rc flightdump auto <reason>", null),
|
||||
V("quit", "Usage: /rc quit (closes the client, as its close button)", null, "exit"),
|
||||
V("report", "Usage: /rc report [what went wrong] (alone: opens the Report a problem panel)", null),
|
||||
V("flight", "Usage: /rc flight [status|mark <text>|on|off|auto on|off]", null),
|
||||
V("autoid", "Usage: /rc autoid [all|limited|off] (alone: status)", null),
|
||||
V("netmsg", "Usage: /rc netmsg [status|on|off|log on|off|capture on|off]", null),
|
||||
V("vtank", "Usage: /rc vtank [clear]", Words("", "clear")),
|
||||
V("bounties", "Usage: /rc bounties [show|hide|toggle]", PanelArgs, "bounty", "bountys"),
|
||||
V("guardian", "Usage: /rc guardian [show|hide|toggle]", PanelArgs, "guardians"),
|
||||
V("dashboard", "Usage: /rc dashboard classic|modern|tab <" + string.Join("|", ClassicTabNames) + ">", DashboardArgs),
|
||||
V("miniremote", "Usage: /rc miniremote [show|hide|toggle|tab <tab>|section <id>]",
|
||||
a => TryPanelMode(a, out _) || IsVerb(a, "tab", out _) || IsVerb(a, "section", out _), "remote"),
|
||||
V("oracle-skills", "Usage: /rc oracle-skills <skills|attrs|progress|off>", a => OracleSkillsTab(a) != InvalidTab),
|
||||
V("skills", "Usage: /rc skills [show|hide|toggle]", PanelArgs),
|
||||
V("progression", "Usage: /rc progression (opens the Progress tab)", NoArgs, "progress"),
|
||||
V("spells", "Usage: /rc spells [show|hide|toggle]", PanelArgs),
|
||||
V("hotkeys", "Usage: /rc hotkeys (opens Settings > Hotkeys) | /rc hotkeys <verb> (as /rc hotkey)", null),
|
||||
V("diagnostics", "Usage: /rc diagnostics (opens Settings > Diagnostics, the server picker)", NoArgs, "serverpick"),
|
||||
V("settings", "Usage: /rc settings [tab]", null),
|
||||
V("shortcuts", "Usage: /rc shortcuts [use <1-18> | set <1-18> [id] | clear <1-18>]", ShortcutsArgs),
|
||||
V("keymap", "Usage: /rc keymap check|bind|unbind <action> <key> | dump, e.g. /rc keymap bind UseQuickSlot_10 F11", KeymapArgs),
|
||||
V("panels", "Usage: /rc panels [open|close|toggle <id>]", PanelsArgs),
|
||||
V("hotkey", HotkeyUsage, null),
|
||||
V("rl", "Usage: /rc rl (reloads RynthCore, as the bar's RL button)", NoArgs, "reload"),
|
||||
V("inventory", "Usage: /rc inventory (opens or closes the Inventory panel)", NoArgs, "inv"),
|
||||
V("sense", "Usage: /rc sense (opens or closes the Sense panel)", NoArgs),
|
||||
V("characters", "Usage: /rc characters (opens or closes RynthNet's Characters window)", NoArgs, "chars"),
|
||||
V("itemcount", "Usage: /rc itemcount (opens or closes the Item Count panel)", NoArgs, "itemhud"),
|
||||
V("resetbar", "Usage: /rc resetbar (moves the RynthCore bar back to the top-left corner)", NoArgs, "barreset"),
|
||||
V("actionstate", "Usage: /rc actionstate (the client's item-action gates)", NoArgs, "actions"),
|
||||
V("unlockactions", "Usage: /rc unlockactions (opens the client's item-action gates now)", NoArgs, "unlock"),
|
||||
V("vitals", "Usage: /rc vitals (the old vitals HUD is gone: /rv plates self)", NoArgs, "hud"),
|
||||
};
|
||||
|
||||
/// <summary>The verb <paramref name="word"/> names (its name or another spelling), or null.</summary>
|
||||
public static ChatVerb? Find(string word)
|
||||
{
|
||||
foreach (ChatVerb v in Verbs)
|
||||
{
|
||||
if (v.Name.Equals(word, StringComparison.OrdinalIgnoreCase)) return v;
|
||||
foreach (string a in v.Aliases)
|
||||
if (a.Equals(word, StringComparison.OrdinalIgnoreCase)) return v;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>The usage of the verb called <paramref name="name"/>.</summary>
|
||||
public static string Usage(string name) => Find(name)?.Usage ?? "Usage: /rc " + name;
|
||||
|
||||
/// <summary>The check made before a /rc command runs: <paramref name="sub"/> is the line after "/rc ".</summary>
|
||||
public static ChatVerbCheck Check(string sub)
|
||||
{
|
||||
string s = sub.Trim();
|
||||
int sp = s.IndexOf(' ');
|
||||
string word = sp < 0 ? s : s.Substring(0, sp);
|
||||
string args = sp < 0 ? string.Empty : s.Substring(sp + 1).Trim();
|
||||
if (word.Length == 0)
|
||||
return new ChatVerbCheck(null, string.Empty, "Usage: /rc <command>. " + CommandList());
|
||||
ChatVerb? v = Find(word);
|
||||
if (v == null)
|
||||
return new ChatVerbCheck(null, args, UnknownReply(word));
|
||||
if (v.Args != null && !v.Args(args))
|
||||
return new ChatVerbCheck(v, args, v.Usage);
|
||||
return new ChatVerbCheck(v, args, null);
|
||||
}
|
||||
|
||||
/// <summary>"RynthCore's commands: /rc acmouse, actionstate, ...": every verb by its name.</summary>
|
||||
public static string CommandList()
|
||||
{
|
||||
var names = new List<string>(Verbs.Length);
|
||||
foreach (ChatVerb v in Verbs) names.Add(v.Name);
|
||||
names.Sort(StringComparer.Ordinal);
|
||||
return "RynthCore's commands: /rc " + string.Join(", ", names) + ".";
|
||||
}
|
||||
|
||||
/// <summary>The answer to a /rc verb the engine doesn't have.</summary>
|
||||
public static string UnknownReply(string word) => $"Unknown command '/rc {word}'. {CommandList()}";
|
||||
|
||||
/// <summary>"/rc vendor" for "/rc vendor buy 1": the command's name in a reply.</summary>
|
||||
public static string CommandName(string trimmedLine)
|
||||
{
|
||||
string s = trimmedLine.Trim();
|
||||
int first = s.IndexOf(' ');
|
||||
if (first < 0) return s;
|
||||
int second = s.IndexOf(' ', first + 1);
|
||||
return second < 0 ? s : s.Substring(0, second);
|
||||
}
|
||||
|
||||
// ── argument parsing (shared with RynthCoreChatCommands) ───────────────
|
||||
|
||||
/// <summary>"verb" or "verb args..." (case-insensitive); args trimmed.</summary>
|
||||
public static bool IsVerb(string sub, string verb, out string args)
|
||||
{
|
||||
args = string.Empty;
|
||||
if (sub.Equals(verb, StringComparison.OrdinalIgnoreCase)) return true;
|
||||
if (!sub.StartsWith(verb + " ", StringComparison.OrdinalIgnoreCase)) return false;
|
||||
args = sub.Substring(verb.Length + 1).Trim();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "" / "toggle" → null (flip), "show" / "on" / "open" → true, "hide" / "off" / "close" →
|
||||
/// false. False for anything else.
|
||||
/// </summary>
|
||||
public static bool TryPanelMode(string args, out bool? show)
|
||||
{
|
||||
show = null;
|
||||
switch (args.Trim().ToLowerInvariant())
|
||||
{
|
||||
case "": case "toggle": return true;
|
||||
case "show": case "on": case "open": show = true; return true;
|
||||
case "hide": case "off": case "close": show = false; return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>What "/rc oracle-skills" can't take.</summary>
|
||||
public const int InvalidTab = -2;
|
||||
|
||||
/// <summary>"/rc oracle-skills <x>": -1 off, 0 skills, 1 attributes, 2 progress, <see cref="InvalidTab"/> for anything else.</summary>
|
||||
public static int OracleSkillsTab(string args) => args.Trim().ToLowerInvariant() switch
|
||||
{
|
||||
"off" or "clear" or "none" or "-1" => -1,
|
||||
"0" or "skills" or "skill" => 0,
|
||||
"1" or "attrs" or "attributes" or "vitals" => 1,
|
||||
"2" or "progress" or "progression" => 2,
|
||||
_ => InvalidTab,
|
||||
};
|
||||
|
||||
/// <summary>The Classic look's tab index for <paramref name="name"/>, or -1.</summary>
|
||||
public static int ClassicTab(string name) =>
|
||||
Array.FindIndex(ClassicTabNames, n => n.Equals(name.Trim(), StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
private static bool DashboardArgs(string a) =>
|
||||
a.Length == 0 || a.Equals("classic", StringComparison.OrdinalIgnoreCase) || a.Equals("modern", StringComparison.OrdinalIgnoreCase)
|
||||
|| (IsVerb(a, "tab", out string tab) && ClassicTab(tab) >= 0);
|
||||
|
||||
/// <summary>"use N", "set N [id]", "clear N" (more words are ignored, as before), or nothing (the list).</summary>
|
||||
private static bool ShortcutsArgs(string a)
|
||||
{
|
||||
string[] sa = a.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (sa.Length == 0) return true;
|
||||
return sa.Length >= 2 && int.TryParse(sa[1], out _)
|
||||
&& (sa[0].Equals("use", StringComparison.OrdinalIgnoreCase) || sa[0].Equals("set", StringComparison.OrdinalIgnoreCase)
|
||||
|| sa[0].Equals("clear", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>"check|bind|unbind <action> <key>", "dump", or nothing (the keymap's state).</summary>
|
||||
private static bool KeymapArgs(string a)
|
||||
{
|
||||
string[] ka = a.Split(' ', 3, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (ka.Length == 0) return true;
|
||||
string verb = ka[0].ToLowerInvariant();
|
||||
return verb == "dump" || (verb is "check" or "bind" or "unbind" && ka.Length == 3);
|
||||
}
|
||||
|
||||
/// <summary>"<op> <id>" (open, close, anything else toggles, as before), or nothing (the list).</summary>
|
||||
private static bool PanelsArgs(string a)
|
||||
{
|
||||
string[] pa = a.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
return pa.Length == 0 || (pa.Length == 2 && TryPanelId(pa[1], out _));
|
||||
}
|
||||
|
||||
/// <summary>An AC panel id: decimal, or hex with 0x.</summary>
|
||||
public static bool TryPanelId(string text, out uint id) =>
|
||||
uint.TryParse(text.Replace("0x", "", StringComparison.OrdinalIgnoreCase),
|
||||
text.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? NumberStyles.HexNumber : NumberStyles.Integer,
|
||||
null, out id);
|
||||
|
||||
// ── reply texts ────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>"Bounties panel opened." / "... closed." / "... is already open.": a panel after
|
||||
/// show (true), hide (false) or toggle (null), from whether it was open before.</summary>
|
||||
public static string PanelReply(string label, bool? show, bool wasOpen)
|
||||
{
|
||||
if (show is bool want && want == wasOpen)
|
||||
return $"{label} is already {(want ? "open" : "closed")}.";
|
||||
bool nowOpen = show ?? !wasOpen;
|
||||
return $"{label} {(nowOpen ? "opened" : "closed")}.";
|
||||
}
|
||||
|
||||
/// <summary>"Settings opened on Hotkeys." / "Settings switched to Hotkeys."</summary>
|
||||
public static string SettingsTabReply(string tab, bool wasOpen) =>
|
||||
$"Settings {(wasOpen ? "switched to" : "opened on")} {tab}.";
|
||||
|
||||
/// <summary>The answer when a command threw.</summary>
|
||||
public static string Failed(string command, string error, string message) =>
|
||||
$"{command} failed: {error}: {message} (the RynthCore log has more).";
|
||||
|
||||
/// <summary>The answer when a command ran and its handler said nothing (a gap: the log names it).</summary>
|
||||
public static string Done(string command) => $"{command}: done.";
|
||||
|
||||
/// <summary>"/rc oracle-skills": what RynthOracle's window embeds now.</summary>
|
||||
public static string OracleSkillsReply(int tab) => tab switch
|
||||
{
|
||||
0 => "RynthOracle's window shows the Skills tab.",
|
||||
1 => "RynthOracle's window shows the Attributes tab.",
|
||||
2 => "RynthOracle's window shows the Progress tab.",
|
||||
_ => "RynthOracle's window shows none of the Skills tabs.",
|
||||
};
|
||||
|
||||
/// <summary>"/rc dashboard ...": the look now (and the Classic tab), and whether the dashboard opened.</summary>
|
||||
public static string DashboardReply(bool classic, string? tab, bool hasDashboard)
|
||||
{
|
||||
var sb = new StringBuilder("RynthAi dashboard: ").Append(classic ? "Classic" : "Modern").Append(" look");
|
||||
if (tab != null) sb.Append(", ").Append(tab.ToLowerInvariant()).Append(" tab");
|
||||
sb.Append(hasDashboard ? "." : " (RynthAi's dashboard isn't loaded, so nothing opened).");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
51
src/RynthCore.Engine/Compatibility/ChatRateLimiter.cs
Normal file
51
src/RynthCore.Engine/Compatibility/ChatRateLimiter.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - Compatibility/ChatRateLimiter.cs
|
||||
//
|
||||
// How many plugin chat lines (WriteToChat off AC's thread) go to AC's chat, and
|
||||
// when (2026-10-28). A token bucket: a burst of up to Burst lines at once, then
|
||||
// one line per IntervalMs. It used to drop any line within 100 ms of the one
|
||||
// before, so a command's help or list reached chat as its first line only
|
||||
// ("/rn help", "/ilt help", "/rthreads stats"). The steady rate is unchanged
|
||||
// (10 a second), which is what keeps a retry loop's spam ("Casting: X" dozens
|
||||
// of times) away from AC's AddTextToScroll and its 0x00460D1D crash.
|
||||
//
|
||||
// Pure (no AC, no engine state), so tools\ChatCommandReplyTests compiles it in.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
|
||||
namespace RynthCore.Engine.Compatibility;
|
||||
|
||||
internal sealed class ChatRateLimiter
|
||||
{
|
||||
public const int DefaultBurst = 12;
|
||||
public const int DefaultIntervalMs = 100;
|
||||
|
||||
private readonly int _burst;
|
||||
private readonly int _intervalMs;
|
||||
private readonly object _lock = new();
|
||||
private double _tokens;
|
||||
private long _at;
|
||||
|
||||
public ChatRateLimiter(int burst = DefaultBurst, int intervalMs = DefaultIntervalMs)
|
||||
{
|
||||
_burst = Math.Max(1, burst);
|
||||
_intervalMs = Math.Max(1, intervalMs);
|
||||
_tokens = _burst;
|
||||
}
|
||||
|
||||
/// <summary>True when a line may go at <paramref name="nowMs"/> (a monotonic clock, e.g.
|
||||
/// Environment.TickCount64), and counts it; false when the burst is spent.</summary>
|
||||
public bool TryTake(long nowMs)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_at != 0 && nowMs > _at)
|
||||
_tokens = Math.Min(_burst, _tokens + (nowMs - _at) / (double)_intervalMs);
|
||||
if (_at == 0 || nowMs > _at) _at = nowMs;
|
||||
if (_tokens < 1) return false;
|
||||
_tokens -= 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1112,10 +1112,11 @@ internal static class ClientHelperHooks
|
|||
// also hook the same function in ChatCallbackHooks.IncomingChatAddTextDetour,
|
||||
// which fires when AC processes our own WriteToChat output — guard
|
||||
// against unbounded recursion into ourselves.
|
||||
private const int WriteToChatMinIntervalMs = 100;
|
||||
// A burst of up to 12 lines, then one per 100 ms (ChatRateLimiter, 2026-10-28; it was one line
|
||||
// per 100 ms, which cut every multi-line command reply to its first line).
|
||||
private static readonly ChatRateLimiter _chatLimiter = new();
|
||||
[System.Runtime.CompilerServices.ModuleInitializer]
|
||||
internal static void EnsureChatRateLimiterReady() { /* triggers static init */ }
|
||||
private static long _lastWriteToChatTick;
|
||||
[ThreadStatic] private static int _writeToChatDepth;
|
||||
|
||||
public static bool WriteToChat(string? text, int chatType)
|
||||
|
|
@ -1130,11 +1131,8 @@ internal static class ClientHelperHooks
|
|||
// dropped before they queue, and drained messages are never re-dropped.
|
||||
if (!MainThreadGuard.IsOnMainThread())
|
||||
{
|
||||
long now = Environment.TickCount64;
|
||||
long last = System.Threading.Interlocked.Read(ref _lastWriteToChatTick);
|
||||
if (last != 0 && now - last < WriteToChatMinIntervalMs)
|
||||
if (!_chatLimiter.TryTake(Environment.TickCount64))
|
||||
return false;
|
||||
System.Threading.Interlocked.Exchange(ref _lastWriteToChatTick, now);
|
||||
return AcMainThreadQueue.EnqueueWriteToChat(text!, chatType);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -405,9 +405,12 @@ internal static unsafe class DecalBridgeHost
|
|||
// VTank, UB and MagTools already ran them).
|
||||
if (arg0 == 0)
|
||||
break;
|
||||
if (RynthCoreChatCommands.TryHandle(text))
|
||||
// Decal hands the bridge typed lines and its plugins' InvokeChatParser lines (a VTank
|
||||
// meta's chat command) alike, so these count as the player's: every reply shows.
|
||||
if (RynthCoreChatCommands.TryHandle(text, ChatCommandOrigin.Player))
|
||||
break;
|
||||
PluginManager.DispatchChatBarEnter(text);
|
||||
using (RynthCoreChatCommands.PlayerLine())
|
||||
PluginManager.DispatchChatBarEnter(text);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -353,7 +353,8 @@ internal static class HotkeyService
|
|||
if (b.IsCommand)
|
||||
{
|
||||
if (b.Command.Trim().Length == 0) return;
|
||||
if (!AcMainThreadQueue.EnqueueChatCommand(b.Command.Trim()))
|
||||
// The player pressed it: a /rc command answers in chat, as typed.
|
||||
if (!AcMainThreadQueue.EnqueueChatCommand(b.Command.Trim(), ChatCommandOrigin.Player))
|
||||
Reply("Hotkey: the chat command queue is full; try again.");
|
||||
return;
|
||||
}
|
||||
|
|
@ -386,7 +387,7 @@ internal static class HotkeyService
|
|||
Reply($"Hotkey {b.Combo}: '{a.Name}' has no {a.Param!.ToLowerInvariant()} (edit it in Settings > Hotkeys).");
|
||||
return;
|
||||
}
|
||||
if (!AcMainThreadQueue.EnqueueChatCommand(HotkeyActions.ChatFor(a, b)))
|
||||
if (!AcMainThreadQueue.EnqueueChatCommand(HotkeyActions.ChatFor(a, b), ChatCommandOrigin.Player))
|
||||
Reply("Hotkey: the chat command queue is full; try again.");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,10 @@
|
|||
// nothing out there the margin is 0 and the picture is just the panel. The
|
||||
// window grows by the margin and moves so the panel stays put (LayeredWindow
|
||||
// .Present). Before this, the window was the panel and a tooltip below the
|
||||
// one-button-high popped-out bar was cut off at its edge.
|
||||
// one-button-high popped-out bar was cut off at its edge. A tooltip in the
|
||||
// margin lets clicks through; a menu, or a window of the face's own drawn
|
||||
// past the panel (RynthAi's dashboard drawers, 2026-10-24), takes them where
|
||||
// it is drawn (transparent pixels still let them through).
|
||||
//
|
||||
// Threads: everything here runs on AC's main thread, which both renders
|
||||
// (EndScene) and dispatches the game and pop-out WndProcs. No locks.
|
||||
|
|
@ -507,7 +510,8 @@ internal static unsafe class ImGuiPopOuts
|
|||
// a menu). Only a menu there takes clicks; a tooltip lets them through.
|
||||
ImDrawDataPtr drawData = ImGuiNET.ImGui.GetDrawData();
|
||||
UpdateMargins(pop, drawData.NativePtr, w, h);
|
||||
window.MarginsClickThrough = !ImGuiNET.ImGui.IsPopupOpen("", ImGuiPopupFlags.AnyPopupId | ImGuiPopupFlags.AnyPopupLevel);
|
||||
window.MarginsClickThrough = !ImGuiNET.ImGui.IsPopupOpen("", ImGuiPopupFlags.AnyPopupId | ImGuiPopupFlags.AnyPopupLevel)
|
||||
&& !WindowPastPanel(drawData.NativePtr, pop.OriginX, pop.OriginY, pop.OriginX + w, pop.OriginY + h, pop.DisplayW, pop.DisplayH);
|
||||
int sx = pop.OriginX - pop.MarginL, sy = pop.OriginY - pop.MarginT;
|
||||
int sw = w + pop.MarginL + pop.MarginR, sh = h + pop.MarginT + pop.MarginB;
|
||||
if (drawData.NativePtr != null)
|
||||
|
|
@ -627,46 +631,81 @@ internal static unsafe class ImGuiPopOuts
|
|||
out float x0, out float y0, out float x1, out float y1)
|
||||
{
|
||||
x0 = px0; y0 = py0; x1 = px1; y1 = py1;
|
||||
if (dd == null) return false;
|
||||
ImDrawList** lists = (ImDrawList**)dd->CmdLists.Data;
|
||||
for (int n = 0; n < dd->CmdListsCount; n++)
|
||||
ListOverflow(lists[n], px0, py0, px1, py1, displayW, displayH, ref x0, ref y0, ref x1, ref y1);
|
||||
return px0 - x0 > OverflowSlack || py0 - y0 > OverflowSlack || x1 - px1 > OverflowSlack || y1 - py1 > OverflowSlack;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A window other than a tooltip draws past the panel: a face's own window (a dashboard's
|
||||
/// drawers). Popups count too, but IsPopupOpen already says so. ImGui names a tooltip
|
||||
/// window "##Tooltip_NN" and its draw list after its window.
|
||||
/// </summary>
|
||||
private static bool WindowPastPanel(ImDrawData* dd, float px0, float py0, float px1, float py1, float displayW, float displayH)
|
||||
{
|
||||
if (dd == null) return false;
|
||||
ImDrawList** lists = (ImDrawList**)dd->CmdLists.Data;
|
||||
for (int n = 0; n < dd->CmdListsCount; n++)
|
||||
{
|
||||
ImDrawList* list = lists[n];
|
||||
if (list == null) continue;
|
||||
int vtxCount = list->VtxBuffer.Size, idxCount = list->IdxBuffer.Size;
|
||||
ImDrawVert* vtx = (ImDrawVert*)list->VtxBuffer.Data;
|
||||
ushort* idx = (ushort*)list->IdxBuffer.Data;
|
||||
ImDrawCmd* cmds = (ImDrawCmd*)list->CmdBuffer.Data;
|
||||
for (int c = 0; c < list->CmdBuffer.Size; c++)
|
||||
{
|
||||
ImDrawCmd* cmd = &cmds[c];
|
||||
if (cmd->UserCallback != IntPtr.Zero || cmd->ElemCount == 0) continue;
|
||||
float cx0 = Math.Max(cmd->ClipRect.X, 0f), cy0 = Math.Max(cmd->ClipRect.Y, 0f);
|
||||
float cx1 = Math.Min(cmd->ClipRect.Z, displayW), cy1 = Math.Min(cmd->ClipRect.W, displayH);
|
||||
if (cx1 <= cx0 || cy1 <= cy0) continue;
|
||||
if (cx0 >= px0 && cy0 >= py0 && cx1 <= px1 && cy1 <= py1) continue; // can't draw outside the panel
|
||||
|
||||
float vx0 = float.MaxValue, vy0 = float.MaxValue, vx1 = float.MinValue, vy1 = float.MinValue;
|
||||
long start = cmd->IdxOffset, end = Math.Min((long)idxCount, start + cmd->ElemCount);
|
||||
long vbase = cmd->VtxOffset;
|
||||
for (long i = start; i < end; i++)
|
||||
{
|
||||
long v = vbase + idx[i];
|
||||
if (v >= vtxCount) continue;
|
||||
Vector2 pos = vtx[v].pos;
|
||||
if (pos.X < vx0) vx0 = pos.X;
|
||||
if (pos.Y < vy0) vy0 = pos.Y;
|
||||
if (pos.X > vx1) vx1 = pos.X;
|
||||
if (pos.Y > vy1) vy1 = pos.Y;
|
||||
}
|
||||
vx0 = Math.Max(vx0, cx0); vy0 = Math.Max(vy0, cy0);
|
||||
vx1 = Math.Min(vx1, cx1); vy1 = Math.Min(vy1, cy1);
|
||||
if (vx1 <= vx0 || vy1 <= vy0) continue;
|
||||
x0 = Math.Min(x0, vx0); y0 = Math.Min(y0, vy0);
|
||||
x1 = Math.Max(x1, vx1); y1 = Math.Max(y1, vy1);
|
||||
}
|
||||
if (list == null || IsTooltipList(list)) continue;
|
||||
float x0 = px0, y0 = py0, x1 = px1, y1 = py1;
|
||||
ListOverflow(list, px0, py0, px1, py1, displayW, displayH, ref x0, ref y0, ref x1, ref y1);
|
||||
if (px0 - x0 > OverflowSlack || py0 - y0 > OverflowSlack || x1 - px1 > OverflowSlack || y1 - py1 > OverflowSlack)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool IsTooltipList(ImDrawList* list)
|
||||
{
|
||||
byte* name = list->_OwnerName;
|
||||
if (name == null) return false;
|
||||
ReadOnlySpan<byte> prefix = "##Tooltip"u8;
|
||||
for (int i = 0; i < prefix.Length; i++)
|
||||
if (name[i] != prefix[i]) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Widens the bounds by what one draw list shows outside the panel (see <see cref="OverflowBounds"/>).</summary>
|
||||
private static void ListOverflow(ImDrawList* list, float px0, float py0, float px1, float py1, float displayW, float displayH,
|
||||
ref float x0, ref float y0, ref float x1, ref float y1)
|
||||
{
|
||||
if (list == null) return;
|
||||
int vtxCount = list->VtxBuffer.Size, idxCount = list->IdxBuffer.Size;
|
||||
ImDrawVert* vtx = (ImDrawVert*)list->VtxBuffer.Data;
|
||||
ushort* idx = (ushort*)list->IdxBuffer.Data;
|
||||
ImDrawCmd* cmds = (ImDrawCmd*)list->CmdBuffer.Data;
|
||||
for (int c = 0; c < list->CmdBuffer.Size; c++)
|
||||
{
|
||||
ImDrawCmd* cmd = &cmds[c];
|
||||
if (cmd->UserCallback != IntPtr.Zero || cmd->ElemCount == 0) continue;
|
||||
float cx0 = Math.Max(cmd->ClipRect.X, 0f), cy0 = Math.Max(cmd->ClipRect.Y, 0f);
|
||||
float cx1 = Math.Min(cmd->ClipRect.Z, displayW), cy1 = Math.Min(cmd->ClipRect.W, displayH);
|
||||
if (cx1 <= cx0 || cy1 <= cy0) continue;
|
||||
if (cx0 >= px0 && cy0 >= py0 && cx1 <= px1 && cy1 <= py1) continue; // can't draw outside the panel
|
||||
|
||||
float vx0 = float.MaxValue, vy0 = float.MaxValue, vx1 = float.MinValue, vy1 = float.MinValue;
|
||||
long start = cmd->IdxOffset, end = Math.Min((long)idxCount, start + cmd->ElemCount);
|
||||
long vbase = cmd->VtxOffset;
|
||||
for (long i = start; i < end; i++)
|
||||
{
|
||||
long v = vbase + idx[i];
|
||||
if (v >= vtxCount) continue;
|
||||
Vector2 pos = vtx[v].pos;
|
||||
if (pos.X < vx0) vx0 = pos.X;
|
||||
if (pos.Y < vy0) vy0 = pos.Y;
|
||||
if (pos.X > vx1) vx1 = pos.X;
|
||||
if (pos.Y > vy1) vy1 = pos.Y;
|
||||
}
|
||||
vx0 = Math.Max(vx0, cx0); vy0 = Math.Max(vy0, cy0);
|
||||
vx1 = Math.Min(vx1, cx1); vy1 = Math.Min(vy1, cy1);
|
||||
if (vx1 <= vx0 || vy1 <= vy0) continue;
|
||||
x0 = Math.Min(x0, vx0); y0 = Math.Min(y0, vy0);
|
||||
x1 = Math.Max(x1, vx1); y1 = Math.Max(y1, vy1);
|
||||
}
|
||||
return px0 - x0 > OverflowSlack || py0 - y0 > OverflowSlack || x1 - px1 > OverflowSlack || y1 - py1 > OverflowSlack;
|
||||
}
|
||||
|
||||
/// <summary>Folds the picture's placement into the draw-data hash.</summary>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,10 @@
|
|||
// pinned My settings, the rows the player pinned (QuickSettingsDrawer.cs)
|
||||
// Each is the same drawer the engine's own dashboard shows, so a value changed
|
||||
// here is saved the same way and a pin made here is the same pin. A drawer
|
||||
// that wasn't drawn in a frame drops its hub subscriptions (EndFrame).
|
||||
// not drawn for 2 s drops its hub subscriptions (EndFrame). Not "this frame":
|
||||
// a popped-out dashboard draws at its own rate (30 Hz at most, 10 idle), so a
|
||||
// drawer there missed most game frames, let its sources go each time and came
|
||||
// back empty (2026-10-24).
|
||||
//
|
||||
// 2026-10-27: RynthVision draws the whole Vision window itself (it takes over
|
||||
// the engine's VisionFace, "takeOver"), but two of its tabs set things that are
|
||||
|
|
@ -23,8 +26,8 @@
|
|||
// engine's Vision panel shows (MonsterHudSettingsUi), saved the same way:
|
||||
// nameplates the "Nameplates" tab
|
||||
// combattext the "Combat text" tab
|
||||
// They draw popped out too (the engine's Vision panel did); the three drawers
|
||||
// above stay docked-only (UiKit.RenderSettingsDrawer, DrawsPoppedOut).
|
||||
// They draw popped out too (the engine's Vision panel did), as the three
|
||||
// drawers above do since 2026-10-24.
|
||||
//
|
||||
// AC thread only (inside RynthAi's or RynthVision's window, and EndFrame after
|
||||
// the panels).
|
||||
|
|
@ -42,8 +45,9 @@ internal static class SettingsDrawerBodies
|
|||
private static RynthAiFace.PatrolDrawer? _patrol;
|
||||
private static QuickSettingsDrawer? _pinned;
|
||||
|
||||
// The frame each was last drawn in (EndFrame counts frames).
|
||||
private static long _frame, _rangesDrawn = -1, _patrolDrawn = -1, _pinnedDrawn = -1;
|
||||
// When each was last drawn (Environment.TickCount64).
|
||||
private static long _rangesDrawn = long.MinValue / 2, _patrolDrawn = long.MinValue / 2, _pinnedDrawn = long.MinValue / 2;
|
||||
private const long KeepMs = 2000;
|
||||
|
||||
/// <summary>
|
||||
/// Draws <paramref name="key"/>'s body at the cursor, <paramref name="width"/> pixels wide, in at most
|
||||
|
|
@ -65,7 +69,7 @@ internal static class SettingsDrawerBodies
|
|||
case "ranges":
|
||||
{
|
||||
_ranges ??= new RangesSlideOut();
|
||||
_rangesDrawn = _frame;
|
||||
_rangesDrawn = Environment.TickCount64;
|
||||
_ranges.Update(true);
|
||||
float h = RangesSlideOut.BodyHeight(k);
|
||||
ImGuiNET.ImGui.PushID("##sdb_ranges");
|
||||
|
|
@ -78,7 +82,7 @@ internal static class SettingsDrawerBodies
|
|||
case "patrol":
|
||||
{
|
||||
_patrol ??= new RynthAiFace.PatrolDrawer();
|
||||
_patrolDrawn = _frame;
|
||||
_patrolDrawn = Environment.TickCount64;
|
||||
_patrol.Update(true);
|
||||
RynthAiFace.UseScale(k);
|
||||
float h = room > 0 ? room : 400 * k;
|
||||
|
|
@ -93,7 +97,7 @@ internal static class SettingsDrawerBodies
|
|||
case "pinned":
|
||||
{
|
||||
_pinned ??= new QuickSettingsDrawer();
|
||||
_pinnedDrawn = _frame;
|
||||
_pinnedDrawn = Environment.TickCount64;
|
||||
_pinned.Update(true);
|
||||
float h = room > 0 ? room : 120 * k;
|
||||
float want;
|
||||
|
|
@ -114,9 +118,6 @@ internal static class SettingsDrawerBodies
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>True for the bodies that draw in a popped-out window too (the Vision tabs).</summary>
|
||||
public static bool DrawsPoppedOut(string key) => key is "nameplates" or "combattext";
|
||||
|
||||
/// <summary>
|
||||
/// A Vision tab RynthVision's window shows (the engine's rows: MonsterHudSettingsUi), in Ui11 as the
|
||||
/// engine's Vision panel drew them. Returns the height drawn.
|
||||
|
|
@ -138,12 +139,12 @@ internal static class SettingsDrawerBodies
|
|||
return MathF.Max(0f, ImGuiNET.ImGui.GetCursorScreenPos().Y - at.Y);
|
||||
}
|
||||
|
||||
/// <summary>After the panels each frame: a body that wasn't drawn this frame lets its hub sources go.</summary>
|
||||
/// <summary>After the panels each frame: a body not drawn for <see cref="KeepMs"/> lets its hub sources go.</summary>
|
||||
public static void EndFrame()
|
||||
{
|
||||
if (_ranges != null && _rangesDrawn != _frame) _ranges.Update(false);
|
||||
if (_patrol != null && _patrolDrawn != _frame) _patrol.Update(false);
|
||||
if (_pinned != null && _pinnedDrawn != _frame) _pinned.Update(false);
|
||||
_frame++;
|
||||
long now = Environment.TickCount64;
|
||||
if (_ranges != null && now - _rangesDrawn > KeepMs) _ranges.Update(false);
|
||||
if (_patrol != null && now - _patrolDrawn > KeepMs) _patrol.Update(false);
|
||||
if (_pinned != null && now - _pinnedDrawn > KeepMs) _pinned.Update(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -381,8 +381,11 @@ internal static unsafe class FlightRecorder
|
|||
if (rest.Equals("off", StringComparison.OrdinalIgnoreCase)) { _autoOff = true; return new[] { "Automatic flight dumps off for this session." }; }
|
||||
if (rest.Equals("on", StringComparison.OrdinalIgnoreCase)) { _autoOff = false; return new[] { "Automatic flight dumps on." }; }
|
||||
return new[] { "Usage: /rc flight auto on|off" };
|
||||
default:
|
||||
case "status":
|
||||
return StatusLines();
|
||||
default:
|
||||
// A word it doesn't take: the usage, not the status (every command answers a typo so).
|
||||
return new[] { "Usage: /rc flight [status|mark <text>|on|off|auto on|off]" };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -213,8 +213,10 @@ internal static unsafe class UiKit
|
|||
/// "patrol", "pinned"; SettingsDrawerBodies) at the cursor, <paramref name="width"/> pixels wide
|
||||
/// and at most <paramref name="room"/> tall (0 = its own height); flags 1: open My settings' list
|
||||
/// of settings to pin. Since 2026-10-27 also the Vision window's engine-owned tabs for RynthVision's
|
||||
/// own window ("nameplates", "combattext"), which draw popped out too. Returns the height it wants
|
||||
/// (pixels), -1 for another key or outside a panel's draw on AC's thread (docked, for the drawers).
|
||||
/// own window ("nameplates", "combattext"). All of them draw popped out too (2026-10-24: RynthAi's
|
||||
/// popped-out dashboard has its drawers; SettingsDrawerBodies keeps a body's sources between its
|
||||
/// draws). Returns the height it wants (pixels), -1 for another key or outside a panel's draw on
|
||||
/// AC's thread.
|
||||
/// </summary>
|
||||
public static float RenderSettingsDrawer(byte* key, float width, float room, int flags)
|
||||
{
|
||||
|
|
@ -224,7 +226,6 @@ internal static unsafe class UiKit
|
|||
|| !float.IsFinite(width) || !float.IsFinite(room)) return -1f;
|
||||
string? name = Marshal.PtrToStringUTF8((IntPtr)key);
|
||||
if (string.IsNullOrEmpty(name) || name.Length > MaxKeyLength) return -1f;
|
||||
if (ImGuiPopOuts.InPopOutFrame && !SettingsDrawerBodies.DrawsPoppedOut(name)) return -1f;
|
||||
return SettingsDrawerBodies.Draw(name, width, MathF.Max(0f, room), (flags & 1) != 0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -1137,7 +1137,13 @@ internal static class ChatModel
|
|||
IntPtr send = SendLinePtr;
|
||||
if (text.Length == 0 || send == IntPtr.Zero) return;
|
||||
IntPtr ptr = Marshal.StringToHGlobalAnsi(text);
|
||||
try { ((delegate* unmanaged[Cdecl]<IntPtr, void>)send)(ptr); }
|
||||
// RynthChat sends the line through Host.InvokeChatParser, on this thread: an engine /rc
|
||||
// command in it is the player's, so it answers in chat (RynthCoreChatCommands.PlayerLine).
|
||||
try
|
||||
{
|
||||
using (RynthCoreChatCommands.PlayerLine())
|
||||
((delegate* unmanaged[Cdecl]<IntPtr, void>)send)(ptr);
|
||||
}
|
||||
finally { Marshal.FreeHGlobal(ptr); }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -644,7 +644,7 @@ internal static class ChatDiscord
|
|||
? $"No route{(rest.Length > 0 ? $" named '{rest}'" : "s")}. Add one in Chat > gear > Discord (or /rc discord window)."
|
||||
: $"{(verb == "test" ? "Test sent to" : "Resumed")} {n} route(s).");
|
||||
break;
|
||||
default:
|
||||
case "status":
|
||||
reply.Add($"Discord relay: {SwitchLine()} {StatusLine()}");
|
||||
if (s.Characters.Length > 0)
|
||||
reply.Add(" On for: " + string.Join(", ", Array.ConvertAll(s.Characters, c => c.ToString())));
|
||||
|
|
@ -658,6 +658,10 @@ internal static class ChatDiscord
|
|||
}
|
||||
reply.Add("/rc discord on|off (this character) | window | test [route] | resume [route] | status");
|
||||
break;
|
||||
default:
|
||||
// A word it doesn't take: the usage, not the status (every command answers a typo so).
|
||||
reply.Add("Usage: /rc discord [on|off|status|window|test [route]|resume [route]]");
|
||||
break;
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,13 +74,19 @@ internal static class ServerMenus
|
|||
|
||||
/// <summary>
|
||||
/// Runs an item's command: an engine "/rc" command directly, anything else through the
|
||||
/// chat dispatcher (plugins' commands, as if typed). Render thread.
|
||||
/// chat dispatcher (plugins' commands, as if typed). Render thread. A click on an engine
|
||||
/// button or menu is a Script's command: what it opens is the answer, so only a failure
|
||||
/// reaches chat.
|
||||
/// </summary>
|
||||
public static void Run(string command)
|
||||
/// <param name="showReply">Answer in chat as for a typed command: a click whose result the player
|
||||
/// wants to read (the server window's "Treat this world as ..." prints the server summary). Other
|
||||
/// clicks stay quiet unless they fail.</param>
|
||||
public static void Run(string command, bool showReply = false)
|
||||
{
|
||||
string cmd = SectionManifestParser.Command(command);
|
||||
if (cmd.Length == 0) return;
|
||||
if (Compatibility.RynthCoreChatCommands.TryHandle(cmd)) return;
|
||||
var origin = showReply ? Compatibility.ChatCommandOrigin.Player : Compatibility.ChatCommandOrigin.Script;
|
||||
if (Compatibility.RynthCoreChatCommands.TryHandle(cmd, origin)) return;
|
||||
if (cmd.StartsWith("/rc ", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
RynthLog.UI($"ServerMenus: '{cmd}' is not an engine command.");
|
||||
|
|
@ -255,7 +261,7 @@ internal static class ServerMenus
|
|||
foreach (MenuGroup g in groups)
|
||||
{
|
||||
if (ImGuiNET.ImGui.MenuItem("Treat this world as " + g.Server.Name + "##srvforce_" + g.Server.Id))
|
||||
Run(ForceCommand(g.Server.Id));
|
||||
Run(ForceCommand(g.Server.Id), showReply: true);
|
||||
SafeImGui.SetItemTooltip("Saved for this character. Undo with /rc server " + g.Server.Id + " auto, or in the Mini Remote's Char section.");
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
28
tools/ChatCommandReplyTests/ChatCommandReplyTests.csproj
Normal file
28
tools/ChatCommandReplyTests/ChatCommandReplyTests.csproj
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!--
|
||||
Offline checks for how the engine's chat commands answer (src\RynthCore.Engine\Compatibility\
|
||||
ChatCommandReplies.cs, compiled in; Hotkeys\HotkeyModel.cs for the /rc hotkey parser): every
|
||||
/rc verb with a valid and an invalid form (the check made before a command runs: unknown verbs
|
||||
and arguments a verb can't take answer with the usage), where a reply goes (chat for the player,
|
||||
the log only for a script's success, chat for every failure) and its colour, the reply texts,
|
||||
and a read of RynthCoreChatCommands.cs: the verb list matches TryHandle both ways and every
|
||||
reply goes through the one writer. The dispatcher itself needs the live engine, so it isn't run.
|
||||
Reads only the source tree. Run: dotnet run -c Release (exit 0 = pass, 1 = fail)
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<RootNamespace>ChatCommandReplyTests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Compatibility\ChatCommandReplies.cs" Link="Engine\ChatCommandReplies.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Compatibility\ChatRateLimiter.cs" Link="Engine\ChatRateLimiter.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Hotkeys\HotkeyModel.cs" Link="Engine\HotkeyModel.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
388
tools/ChatCommandReplyTests/Program.cs
Normal file
388
tools/ChatCommandReplyTests/Program.cs
Normal file
|
|
@ -0,0 +1,388 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using RynthCore.Engine.Compatibility;
|
||||
using RynthCore.Engine.Hotkeys;
|
||||
|
||||
namespace ChatCommandReplyTests;
|
||||
|
||||
/// <summary>
|
||||
/// How the engine's chat commands answer (ChatCommandReplies.cs) without AC: every /rc verb with a
|
||||
/// valid and an invalid form, where each reply goes and its colour, the reply texts, and a read of
|
||||
/// RynthCoreChatCommands.cs so the verb list can't drift from TryHandle. The dispatcher needs the
|
||||
/// live engine (panels, settings, AC), so the decision before a command runs is what is tested.
|
||||
/// </summary>
|
||||
internal static class Program
|
||||
{
|
||||
private static int _checks, _failed;
|
||||
private static string _case = "";
|
||||
|
||||
private static int Main()
|
||||
{
|
||||
WhereRepliesGo();
|
||||
EveryVerbValidAndInvalid();
|
||||
HandlerVerbsPassThrough();
|
||||
UnknownAndBare();
|
||||
ModuleLinesClassified();
|
||||
ParsersShared();
|
||||
ReplyTexts();
|
||||
SourceMatchesCatalog();
|
||||
ChatBurst();
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"{_checks - _failed}/{_checks} checks passed.");
|
||||
Console.WriteLine(_failed == 0 ? "ALL CHAT COMMAND REPLY TESTS PASSED." : $"{_failed} FAILED.");
|
||||
return _failed == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
// ── where a reply goes ──────────────────────────────────────────────────
|
||||
|
||||
private static void WhereRepliesGo()
|
||||
{
|
||||
Case("where a reply goes, and its colour");
|
||||
Check(ChatCommandReplies.ToChat(ChatReplyKind.Ok, ChatCommandOrigin.Player), "the player's success: chat");
|
||||
Check(ChatCommandReplies.ToChat(ChatReplyKind.Fail, ChatCommandOrigin.Player), "the player's failure: chat");
|
||||
Check(!ChatCommandReplies.ToChat(ChatReplyKind.Ok, ChatCommandOrigin.Script), "a script's success: the log only");
|
||||
Check(ChatCommandReplies.ToChat(ChatReplyKind.Fail, ChatCommandOrigin.Script), "a script's failure: chat");
|
||||
Check(ChatCommandReplies.Effective(ChatCommandOrigin.Script, insidePlayerLine: true) == ChatCommandOrigin.Player,
|
||||
"a plugin's line while it handles one the player typed is the player's");
|
||||
Check(ChatCommandReplies.Effective(ChatCommandOrigin.Script, insidePlayerLine: false) == ChatCommandOrigin.Script, "a plugin's own line is a script's");
|
||||
Check(ChatCommandReplies.Effective(ChatCommandOrigin.Player, insidePlayerLine: false) == ChatCommandOrigin.Player, "typed stays the player's");
|
||||
Check(default(ChatCommandOrigin) == ChatCommandOrigin.Script, "the default (an unset [ThreadStatic]) is a script's");
|
||||
Check(ChatCommandReplies.ChatType(ChatReplyKind.Ok) == 1, "success: chat type 1 (green), as every reply before");
|
||||
Check(ChatCommandReplies.ChatType(ChatReplyKind.Fail) == 0x1A, "failure: 0x1A, AC's own command-notice red");
|
||||
Check(ChatCommandReplies.ReplyPrefix == "[RynthCore] ", "the prefix is unchanged");
|
||||
}
|
||||
|
||||
// ── every verb: a valid and an invalid form ────────────────────────────
|
||||
|
||||
/// <summary>Verbs whose arguments are checked before they run: (form that runs, form answered with the usage).</summary>
|
||||
private static readonly (string Verb, string Valid, string Invalid)[] Checked =
|
||||
{
|
||||
("imgui", "imgui on", "imgui frob"),
|
||||
("imgui", "imgui", "imgui on off"),
|
||||
("chathold", "chathold status", "chathold frob"),
|
||||
("ilt", "ilt auto", "ilt frob"),
|
||||
("worldlayer", "worldlayer uipass", "worldlayer frob"),
|
||||
("acmouse", "acmouse watch 30", "acmouse frob"),
|
||||
("acmouse", "mouseover", "mouseover frob"),
|
||||
("vtank", "vtank clear", "vtank frob"),
|
||||
("bounties", "bounties show", "bounties frob"),
|
||||
("bounties", "bounty", "bountys frob"),
|
||||
("guardian", "guardian hide", "guardians frob"),
|
||||
("dashboard", "dashboard tab loot", "dashboard tab frob"),
|
||||
("dashboard", "dashboard classic", "dashboard frob"),
|
||||
("dashboard", "dashboard", "dashboard modern now"),
|
||||
("miniremote", "miniremote section map", "miniremote frob"),
|
||||
("miniremote", "remote toggle", "remote frob"),
|
||||
("miniremote", "miniremote tab pets", "miniremote shows"),
|
||||
("oracle-skills", "oracle-skills attrs", "oracle-skills frob"),
|
||||
("oracle-skills", "oracle-skills off", "oracle-skills"),
|
||||
("skills", "skills toggle", "skills frob"),
|
||||
("progression", "progression", "progression now"),
|
||||
("progression", "progress", "progress now"),
|
||||
("spells", "spells show", "spells frob"),
|
||||
("diagnostics", "diagnostics", "diagnostics now"),
|
||||
("diagnostics", "serverpick", "serverpick now"),
|
||||
("shortcuts", "shortcuts use 5", "shortcuts use five"),
|
||||
("shortcuts", "shortcuts", "shortcuts frob"),
|
||||
("shortcuts", "shortcuts set 3 0x50000001", "shortcuts set"),
|
||||
("shortcuts", "shortcuts clear 18", "shortcuts clear"),
|
||||
("keymap", "keymap bind UseQuickSlot_10 F11", "keymap bind F11"),
|
||||
("keymap", "keymap check /ra start Ctrl+F1", "keymap frob"),
|
||||
("keymap", "keymap dump", "keymap unbind"),
|
||||
("keymap", "keymap", "keymap check x"),
|
||||
("panels", "panels open 0x1F", "panels open"),
|
||||
("panels", "panels toggle 12", "panels open twelve"),
|
||||
("panels", "panels", "panels open 1 2"),
|
||||
("rl", "rl", "rl now"),
|
||||
("rl", "reload", "reload now"),
|
||||
("inventory", "inv", "inv now"),
|
||||
("inventory", "inventory", "inventory now"),
|
||||
("sense", "sense", "sense now"),
|
||||
("characters", "chars", "characters now"),
|
||||
("itemcount", "itemhud", "itemcount now"),
|
||||
("resetbar", "barreset", "resetbar now"),
|
||||
("actionstate", "actions", "actionstate now"),
|
||||
("unlockactions", "unlock", "unlockactions now"),
|
||||
("vitals", "hud", "vitals now"),
|
||||
};
|
||||
|
||||
private static void EveryVerbValidAndInvalid()
|
||||
{
|
||||
Case("every checked verb: the valid form runs, the invalid one gets the usage");
|
||||
foreach (var (verb, valid, invalid) in Checked)
|
||||
{
|
||||
ChatVerbCheck ok = ChatCommandReplies.Check(valid);
|
||||
Check(ok.Problem == null && ok.Verb?.Name == verb, $"'/rc {valid}' runs as {verb} (got {ok.Verb?.Name ?? "unknown"}: {ok.Problem})");
|
||||
ChatVerbCheck bad = ChatCommandReplies.Check(invalid);
|
||||
Check(bad.Verb?.Name == verb && bad.Problem != null && bad.Problem == bad.Verb.Usage,
|
||||
$"'/rc {invalid}' answers with {verb}'s usage (got {bad.Problem ?? "no reply"})");
|
||||
Check(bad.Problem != null && bad.Problem.StartsWith("Usage: /rc ", StringComparison.Ordinal),
|
||||
$"'/rc {invalid}': the reply is a usage line");
|
||||
Check(ChatCommandReplies.KindOfLine(bad.Problem ?? "") == ChatReplyKind.Fail, $"'/rc {invalid}': a failure (red, and shown to a script too)");
|
||||
}
|
||||
|
||||
Case("every verb in the list has a valid and an invalid form here");
|
||||
var covered = new HashSet<string>(Checked.Select(c => c.Verb));
|
||||
foreach (var h in Handled) covered.Add(h.Verb);
|
||||
foreach (ChatVerb v in ChatCommandReplies.Verbs)
|
||||
{
|
||||
Check(covered.Contains(v.Name), $"{v.Name} is tested");
|
||||
Check(v.Usage.StartsWith("Usage: /r", StringComparison.Ordinal) && v.Usage.Length > 12, $"{v.Name} has a usage line");
|
||||
Check(v.Usage.Contains(v.Name, StringComparison.OrdinalIgnoreCase), $"{v.Name}'s usage names it");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verbs whose own handler checks the arguments (Args null): the check before they run lets the
|
||||
/// invalid form through, and the handler or module answers with its usage (Who), in red because
|
||||
/// the line starts "Usage" (ModuleLinesClassified) or is the parser's error (hotkey).
|
||||
/// </summary>
|
||||
private static readonly (string Verb, string Valid, string Invalid, string Who)[] Handled =
|
||||
{
|
||||
("vendor", "vendor list", "vendor frob", "VendorTrade: '[RC] /rc vendor list | info | ...'"),
|
||||
("ui", "ui list", "ui frob", "HandleUiCommand: its usage"),
|
||||
("discord", "discord status", "discord frob", "ChatDiscord.HandleCommand: its usage"),
|
||||
("plates", "plates status", "plates frob", "HandlePlatesCommand: the plates usage"),
|
||||
("plates", "nameplates off", "nameplates frob", "HandlePlatesCommand: the plates usage"),
|
||||
("server", "server ilt auto", "server a b c", "HandleServerCommand: the server usage"),
|
||||
("mastery", "mastery", "mastery", "HandleMasteryCommand (takes no arguments; ignores any, as before)"),
|
||||
("video", "video world", "video frob", "VideoPatch.HandleCommand: its usage"),
|
||||
("video", "videopatch fps 30", "videopatch fps x", "VideoPatch.HandleCommand: the fps usage"),
|
||||
("hooks", "hooks status", "hooks frob", "HandleHooksCommand: its usage"),
|
||||
("hooks", "uihooks off Tooltip", "uihooks on", "HandleHooksCommand: its usage"),
|
||||
("flightdump", "flightdump before the wall", "flightdump", "FlightRecorder (any text is the note)"),
|
||||
("quit", "quit", "exit", "closes the client (takes no arguments)"),
|
||||
("report", "report the map froze", "report", "ProblemReport (alone: opens the panel)"),
|
||||
("flight", "flight mark here", "flight frob", "FlightRecorder.HandleCommand: its usage"),
|
||||
("autoid", "autoid limited", "autoid frob", "AutoIdService.HandleCommand: its usage"),
|
||||
("netmsg", "netmsg log on", "netmsg frob", "ServerMessageStream.HandleCommand: its usage"),
|
||||
("hotkeys", "hotkeys", "hotkeys frob", "HotkeyCommandParser: unknown verb + usage"),
|
||||
("settings", "settings Hotkeys", "settings frob", "SettingsCommand: no tab called 'frob' (tabs: ...)"),
|
||||
("hotkey", "hotkey list", "hotkey frob", "HotkeyCommandParser: unknown verb + usage"),
|
||||
("hotkey", "hotkey add F5 /ra start", "hotkey add F5", "HotkeyCommandParser: the add usage"),
|
||||
};
|
||||
|
||||
private static void HandlerVerbsPassThrough()
|
||||
{
|
||||
Case("verbs that check their own arguments: both forms reach the handler");
|
||||
foreach (var (verb, valid, invalid, who) in Handled)
|
||||
{
|
||||
ChatVerbCheck ok = ChatCommandReplies.Check(valid);
|
||||
Check(ok.Problem == null && ok.Verb?.Name == verb, $"'/rc {valid}' runs as {verb}");
|
||||
ChatVerbCheck bad = ChatCommandReplies.Check(invalid);
|
||||
Check(bad.Problem == null && bad.Verb?.Name == verb, $"'/rc {invalid}' reaches {verb}'s handler, which answers: {who}");
|
||||
}
|
||||
|
||||
Case("the /rc hotkey parser answers every invalid form (compiled in)");
|
||||
foreach (string args in new[] { "frob", "add F5", "add NotAKey /ra start", "remove", "enable", "add F5 notanaction" })
|
||||
{
|
||||
HotkeyCommand c = HotkeyCommandParser.Parse(args);
|
||||
Check(c.Verb == HotkeyVerb.Error && c.Error.Length > 0, $"'/rc hotkey {args}': {c.Error}");
|
||||
}
|
||||
foreach (string args in new[] { "", "list", "add F5 /ra start", "remove F5", "on", "off", "status", "actions" })
|
||||
Check(HotkeyCommandParser.Parse(args).Verb != HotkeyVerb.Error, $"'/rc hotkey {args}' runs");
|
||||
}
|
||||
|
||||
private static void UnknownAndBare()
|
||||
{
|
||||
Case("unknown verbs and a bare /rc answer with the command list");
|
||||
ChatVerbCheck unknown = ChatCommandReplies.Check("frobnicate now");
|
||||
Check(unknown.Verb == null && unknown.Problem != null && unknown.Problem.StartsWith("Unknown command '/rc frobnicate'", StringComparison.Ordinal),
|
||||
$"an unknown verb says so: {unknown.Problem}");
|
||||
Check(ChatCommandReplies.KindOfLine(unknown.Problem ?? "") == ChatReplyKind.Fail, "and is a failure");
|
||||
foreach (ChatVerb v in ChatCommandReplies.Verbs)
|
||||
Check(unknown.Problem!.Contains(v.Name, StringComparison.Ordinal), $"the list names {v.Name}");
|
||||
ChatVerbCheck bare = ChatCommandReplies.Check("");
|
||||
Check(bare.Verb == null && bare.Problem != null && bare.Problem.StartsWith("Usage: /rc <command>.", StringComparison.Ordinal), "'/rc' alone: the usage and the list");
|
||||
Check(ChatCommandReplies.Check("window save").Problem!.StartsWith("Unknown command '/rc window'", StringComparison.Ordinal),
|
||||
"'/rc window save' (sent by /ub window save) is not an engine verb, and now says so");
|
||||
Check(ChatCommandReplies.Check(" SKILLS Show ").Problem == null, "case and spaces as IsVerb takes them");
|
||||
}
|
||||
|
||||
private static void ModuleLinesClassified()
|
||||
{
|
||||
Case("module reply lines: failures and state");
|
||||
string[] fails =
|
||||
{
|
||||
"Usage: /rc video fps <0|5-60> (now none).",
|
||||
"Usage: /rc autoid [all|limited|off] (alone: status)",
|
||||
"usage: /rv plates numbers size 0.5-2.5",
|
||||
"Video patch unavailable: no hook.",
|
||||
"Video patch is switched off (/rc hooks on VideoPatch to switch it back on).",
|
||||
"Flight recorder is off.",
|
||||
"Not dumped: the last automatic dump was 10 s ago (one per 5 min).",
|
||||
"Not capturing.",
|
||||
"Capture failed: access denied",
|
||||
"The server message stream is off; /rc netmsg on first (engine.json must allow it).",
|
||||
"Report not sent: one report a minute.",
|
||||
"The Report a problem panel isn't available (the ImGui layer is off?). Use /rc report <what went wrong> to send one from chat.",
|
||||
"Log in first: the relay is switched on or off for the character you're playing.",
|
||||
"The relay is off: /rc discord on, or use Send test in the Discord panel (/rc discord window).",
|
||||
"No route named 'x'. Add one in Chat > gear > Discord (or /rc discord window).",
|
||||
"Unknown '/rc hotkey frob'. Usage: ...",
|
||||
"No hotkey on F5.",
|
||||
"Unlock skipped: not on the game thread.",
|
||||
"Can't: no AC panel functions",
|
||||
};
|
||||
foreach (string f in fails)
|
||||
Check(ChatCommandReplies.KindOfLine(f) == ChatReplyKind.Fail, $"failure: {f}");
|
||||
string[] oks =
|
||||
{
|
||||
"Video patch: WORLD - AC's 3D world isn't drawn; AC's UI and the panels are. /rc video off to restore.",
|
||||
"Flight recorder: recording, 120 entries recorded",
|
||||
"Flight recorder paused for this session (/rc flight on resumes).",
|
||||
"Automatic flight dumps on.",
|
||||
"AutoId: limited (selected target; ...). Saved in engine.json.",
|
||||
"Server message log off.",
|
||||
"Hotkeys on.",
|
||||
"No hotkeys. Add one in Settings > Hotkeys (/rc hotkeys) or with /rc hotkey add <combo> <action or /command>.",
|
||||
"Hotkey added: F5 - /ra start.",
|
||||
"Sending your report (with your recent RynthCore log; use the panel, /rc report, to leave the log out)...",
|
||||
"Discord relay on for Someone. 2 routes.",
|
||||
"Action state (what the client checks before a use, equip or move):",
|
||||
"Unlock queued for the next game tick.",
|
||||
};
|
||||
foreach (string o in oks)
|
||||
Check(ChatCommandReplies.KindOfLine(o) == ChatReplyKind.Ok, $"state: {o}");
|
||||
Check(ChatCommandReplies.KindOfLines(new[] { "Video patch: off - normal drawing.", "Usage: /rc video fps <0|5-60>" }) == ChatReplyKind.Fail,
|
||||
"one failing line makes the answer a failure (all of it then reaches a script's chat)");
|
||||
Check(ChatCommandReplies.KindOfLines(Array.Empty<string>()) == ChatReplyKind.Ok, "no lines: not a failure");
|
||||
}
|
||||
|
||||
private static void ParsersShared()
|
||||
{
|
||||
Case("the parsers the dispatcher and the check share");
|
||||
Check(ChatCommandReplies.IsVerb("skills show", "skills", out string a) && a == "show", "IsVerb: verb and args");
|
||||
Check(ChatCommandReplies.IsVerb("SKILLS", "skills", out a) && a == "", "IsVerb: case, no args");
|
||||
Check(!ChatCommandReplies.IsVerb("skillset", "skills", out _), "IsVerb: a longer word is another verb");
|
||||
Check(!ChatCommandReplies.IsVerb("flightdump x", "flight", out _), "IsVerb: flight is not flightdump");
|
||||
foreach (var (args, want) in new (string, bool?)[] { ("", null), ("toggle", null), ("show", true), ("on", true), ("open", true), ("hide", false), ("off", false), ("close", false) })
|
||||
Check(ChatCommandReplies.TryPanelMode(args, out bool? show) && show == want, $"TryPanelMode '{args}'");
|
||||
Check(!ChatCommandReplies.TryPanelMode("frob", out _), "TryPanelMode: anything else is wrong");
|
||||
Check(ChatCommandReplies.OracleSkillsTab("skills") == 0 && ChatCommandReplies.OracleSkillsTab("attributes") == 1
|
||||
&& ChatCommandReplies.OracleSkillsTab("progression") == 2 && ChatCommandReplies.OracleSkillsTab("none") == -1
|
||||
&& ChatCommandReplies.OracleSkillsTab("frob") == ChatCommandReplies.InvalidTab, "oracle-skills tabs");
|
||||
Check(ChatCommandReplies.ClassicTab("LOOT") == 5 && ChatCommandReplies.ClassicTab("frob") == -1, "the Classic tabs by name");
|
||||
Check(ChatCommandReplies.TryPanelId("0x1F", out uint id) && id == 0x1F && ChatCommandReplies.TryPanelId("12", out id) && id == 12
|
||||
&& !ChatCommandReplies.TryPanelId("twelve", out _), "AC panel ids: decimal or 0x hex");
|
||||
}
|
||||
|
||||
private static void ReplyTexts()
|
||||
{
|
||||
Case("reply texts");
|
||||
Check(ChatCommandReplies.PanelReply("Inventory panel", null, wasOpen: false) == "Inventory panel opened.", "toggle a closed panel");
|
||||
Check(ChatCommandReplies.PanelReply("Inventory panel", null, wasOpen: true) == "Inventory panel closed.", "toggle an open panel");
|
||||
Check(ChatCommandReplies.PanelReply("Mini Remote", true, wasOpen: false) == "Mini Remote opened.", "show a closed panel");
|
||||
Check(ChatCommandReplies.PanelReply("Mini Remote", true, wasOpen: true) == "Mini Remote is already open.", "show an open panel");
|
||||
Check(ChatCommandReplies.PanelReply("Bounties panel", false, wasOpen: false) == "Bounties panel is already closed.", "hide a closed panel");
|
||||
Check(ChatCommandReplies.PanelReply("Bounties panel", false, wasOpen: true) == "Bounties panel closed.", "hide an open panel");
|
||||
Check(ChatCommandReplies.SettingsTabReply("Hotkeys", false) == "Settings opened on Hotkeys.", "Settings opened on a tab");
|
||||
Check(ChatCommandReplies.SettingsTabReply("Hotkeys", true) == "Settings switched to Hotkeys.", "Settings switched tab");
|
||||
Check(ChatCommandReplies.DashboardReply(true, "loot", true) == "RynthAi dashboard: Classic look, loot tab.", "dashboard tab");
|
||||
Check(ChatCommandReplies.DashboardReply(false, null, false) == "RynthAi dashboard: Modern look (RynthAi's dashboard isn't loaded, so nothing opened).", "dashboard without RynthAi");
|
||||
for (int t = -1; t <= 2; t++)
|
||||
Check(ChatCommandReplies.OracleSkillsReply(t).StartsWith("RynthOracle's window shows", StringComparison.Ordinal), $"oracle-skills {t}");
|
||||
Check(ChatCommandReplies.Failed("/rc vendor", "NullReferenceException", "x") == "/rc vendor failed: NullReferenceException: x (the RynthCore log has more).", "a thrown command");
|
||||
Check(ChatCommandReplies.Done("/rc sense") == "/rc sense: done.", "the gap filler");
|
||||
Check(ChatCommandReplies.CommandName("/rc vendor buy 1") == "/rc vendor" && ChatCommandReplies.CommandName("/rc") == "/rc"
|
||||
&& ChatCommandReplies.CommandName("/rv plates self on") == "/rv plates", "a command's name in a reply");
|
||||
}
|
||||
|
||||
// ── the source: catalog and TryHandle in step, one writer ──────────────
|
||||
|
||||
private static void SourceMatchesCatalog()
|
||||
{
|
||||
Case("RynthCoreChatCommands.cs: the verbs TryHandle routes are the catalog's, both ways");
|
||||
string? path = FindRepoFile(Path.Combine("src", "RynthCore.Engine", "Compatibility", "RynthCoreChatCommands.cs"));
|
||||
Check(path != null, "found RynthCoreChatCommands.cs by walking up");
|
||||
if (path == null) return;
|
||||
string src = File.ReadAllText(path);
|
||||
int start = src.IndexOf("private static void Handle(string trimmed)", StringComparison.Ordinal);
|
||||
int end = src.IndexOf("private static void HandleUiCommand", StringComparison.Ordinal);
|
||||
Check(start > 0 && end > start, "found Handle()");
|
||||
if (start < 0 || end < start) return;
|
||||
string handle = src.Substring(start, end - start);
|
||||
|
||||
var routed = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (Match m in Regex.Matches(handle, @"IsVerb\(sub, ""([^""]+)"""))
|
||||
routed.Add(m.Groups[1].Value);
|
||||
int sw = handle.IndexOf("switch (sub.ToLowerInvariant())", StringComparison.Ordinal);
|
||||
Check(sw > 0, "found the no-argument switch");
|
||||
if (sw > 0)
|
||||
foreach (Match m in Regex.Matches(handle.Substring(sw), @"case ""([a-z-]+)"":"))
|
||||
routed.Add(m.Groups[1].Value);
|
||||
Check(routed.Count >= 60, $"read {routed.Count} spellings from Handle()");
|
||||
|
||||
var listed = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (ChatVerb v in ChatCommandReplies.Verbs)
|
||||
{
|
||||
listed.Add(v.Name);
|
||||
foreach (string al in v.Aliases) listed.Add(al);
|
||||
}
|
||||
foreach (string r in routed)
|
||||
Check(listed.Contains(r), $"'{r}' (routed in Handle) is in ChatCommandReplies.Verbs, so it isn't answered as unknown");
|
||||
foreach (string l in listed)
|
||||
Check(routed.Contains(l), $"'{l}' (in the list) is routed in Handle");
|
||||
|
||||
Case("RynthCoreChatCommands.cs: every reply goes through the one writer");
|
||||
Check(Regex.Matches(src, @"EnqueueWriteToChat\(").Count == 1, "one EnqueueWriteToChat (the writer in Reply)");
|
||||
Check(!Regex.IsMatch(src, @"\bReply\(\$?""[Uu]sage"), "no usage line is written as a success (they go through Fail)");
|
||||
Check(!Regex.IsMatch(src, @"\bReply\((usage|ServerUsage)\)"), "nor the usage constants");
|
||||
Check(!Regex.IsMatch(src, @"catch \(Exception ex\) \{ RynthLog\.Compat"), "no command's exception is only logged");
|
||||
}
|
||||
|
||||
private static string? FindRepoFile(string relative)
|
||||
{
|
||||
string? dir = AppContext.BaseDirectory;
|
||||
while (dir != null)
|
||||
{
|
||||
string candidate = Path.Combine(dir, relative);
|
||||
if (File.Exists(candidate)) return candidate;
|
||||
dir = Path.GetDirectoryName(dir);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ── the chat rate limit (ChatRateLimiter, 2026-10-28) ──────────
|
||||
|
||||
private static void ChatBurst()
|
||||
{
|
||||
Case("plugin chat: a burst of 12 lines goes at once, then one per 100 ms");
|
||||
var r = new ChatRateLimiter();
|
||||
int sent = 0;
|
||||
for (int i = 0; i < 20; i++) if (r.TryTake(1000)) sent++;
|
||||
Check(sent == 12, $"a 20-line reply at one moment: 12 go (got {sent})");
|
||||
Check(!r.TryTake(1050), "50 ms later: still spent");
|
||||
Check(r.TryTake(1100), "100 ms later: one more");
|
||||
Check(!r.TryTake(1100), "and only one");
|
||||
int steady = 0;
|
||||
for (long t = 1200; t <= 3100; t += 100) if (r.TryTake(t)) steady++;
|
||||
Check(steady == 20, $"one a line every 100 ms keeps going (20 of 20, got {steady})");
|
||||
var idle = new ChatRateLimiter();
|
||||
idle.TryTake(1000);
|
||||
int after = 0;
|
||||
for (int i = 0; i < 30; i++) if (idle.TryTake(60_000)) after++;
|
||||
Check(after == 12, $"a long quiet spell refills to 12, no more (got {after})");
|
||||
var back = new ChatRateLimiter();
|
||||
for (int i = 0; i < 12; i++) back.TryTake(5000);
|
||||
Check(!back.TryTake(4000), "a clock that went backwards refills nothing");
|
||||
int spam = 0;
|
||||
var loop = new ChatRateLimiter();
|
||||
for (long t = 0; t < 1000; t += 5) if (loop.TryTake(10_000 + t)) spam++;
|
||||
Check(spam <= 22, $"a retry loop sending every 5 ms for 1 s: at most 12 + 10 (got {spam})");
|
||||
}
|
||||
|
||||
private static void Case(string name)
|
||||
{
|
||||
_case = name;
|
||||
Console.WriteLine($"-- {name}");
|
||||
}
|
||||
|
||||
private static void Check(bool ok, string what)
|
||||
{
|
||||
_checks++;
|
||||
if (ok) return;
|
||||
_failed++;
|
||||
Console.WriteLine($" FAIL [{_case}] {what}");
|
||||
}
|
||||
}
|
||||
|
|
@ -60,6 +60,12 @@
|
|||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\ChatLineColors.cs" Link="Engine\ChatLineColors.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\ChatRuleMatching.cs" Link="Engine\ChatRuleMatching.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\ChatSettingsDto.cs" Link="Engine\ChatSettingsDto.cs" />
|
||||
<!-- ChatRouting's standard filters (2026-10-28: the bench stopped building when ChatRouting
|
||||
started calling RynthChatPresets; the same files as tools\ChatFilterTests). -->
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Panels\RynthChatPresets.cs" Link="Engine\RynthChatPresets.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\ChatFilterPresets.cs" Link="Engine\ChatFilterPresets.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\ChatRetailVerdict.cs" Link="Engine\ChatRetailVerdict.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\SharedFileWatch.cs" Link="Engine\SharedFileWatch.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="Exists('$(RynthChatDir)\ChatBuffer.cs')">
|
||||
|
|
|
|||
Loading…
Reference in a new issue