diff --git a/Plugins/Shared/ServerPack/ServerPackCommands.cs b/Plugins/Shared/ServerPack/ServerPackCommands.cs
index 8cdd6c0..d258f2f 100644
--- a/Plugins/Shared/ServerPack/ServerPackCommands.cs
+++ b/Plugins/Shared/ServerPack/ServerPackCommands.cs
@@ -46,12 +46,22 @@ internal static class ServerPackCommands
/// "/rserver [show|hide|toggle]": the window after it.
public static string Window(string serverName, bool shown) => CommandReply.Shown($"The {serverName} window", shown);
- /// The usage, two lines.
- public static string[] Usage(string serverName) => new[]
+ ///
+ /// The usage: two lines, then the server's own (ServerUsageLines), if any. With none, the two lines are
+ /// exactly what every server plugin has always printed.
+ ///
+ public static string[] Usage(string serverName, IReadOnlyList? serverLines = null)
{
- $"/rserver [show|hide|toggle] - the {serverName} server card (also in the Mini Remote's Char section).",
- $"/rserver info - what is known about {serverName}; /rserver auto|on|off - this character's override.",
- };
+ var lines = new List
+ {
+ $"/rserver [show|hide|toggle] - the {serverName} server card (also in the Mini Remote's Char section).",
+ $"/rserver info - what is known about {serverName}; /rserver auto|on|off - this character's override.",
+ };
+ if (serverLines != null)
+ foreach (string l in serverLines)
+ if (!string.IsNullOrWhiteSpace(l)) lines.Add(l.Trim());
+ return lines.ToArray();
+ }
public static string Unknown(string word) => $"Unknown '/rserver {word}'.";
}
diff --git a/Plugins/Shared/ServerPack/ServerPackPlugin.cs b/Plugins/Shared/ServerPack/ServerPackPlugin.cs
index d2f1a96..a30ac23 100644
--- a/Plugins/Shared/ServerPack/ServerPackPlugin.cs
+++ b/Plugins/Shared/ServerPack/ServerPackPlugin.cs
@@ -32,6 +32,7 @@
// SetProfileValue(key, n) a live number in its "RynthServer.Profile" ("values"), for other
// plugins that apply a server rule without knowing the server.
// ServerCommandVerbs(list) its own "/rserver " words, handled in ServerChatCommand.
+// ServerUsageLines(add) the usage lines for those words, after the shared two (help, unknown word).
// RunOnTick(action) work for the next tick (a page's button, on the render thread).
// ServerCardActions() the server's own buttons at the top of its card, under RynthCore's verdict
// (render thread: ImGui calls only; queue work with RunOnTick).
@@ -87,6 +88,8 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
private readonly ConcurrentQueue _tickActions = new();
// The server's own "/rserver" verbs (ServerCommandVerbs).
private readonly HashSet _serverVerbs = new(StringComparer.OrdinalIgnoreCase);
+ // The server's own "/rserver" usage lines (ServerUsageLines), after the shared two.
+ private readonly List _usageLines = new();
private volatile bool _loginComplete;
private volatile string? _world;
private bool _wasActive;
@@ -104,6 +107,7 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
var verbs = new List();
ServerCommandVerbs(verbs);
foreach (string v in verbs) if (!string.IsNullOrWhiteSpace(v)) _serverVerbs.Add(v.Trim());
+ ServerUsageLines(_usageLines.Add);
_ui = new ServerPackUi(_model, RynthPluginInfo.Name + " " + Marshal.PtrToStringAnsi(VersionPointer), () => _world, _pages, DrawCardActions);
}
@@ -135,6 +139,11 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
/// instead of being read as another server's id. Called once, from the constructor.
///
partial void ServerCommandVerbs(List verbs);
+ ///
+ /// Usage lines for the server's own verbs, printed after the shared two by "/rserver help" and an
+ /// unknown word. Called once, from the constructor (no Host yet).
+ ///
+ partial void ServerUsageLines(Action add);
/// Extra lines for "/rserver info".
partial void ServerInfoLines(Action line);
/// The server's own pages (ServerPackPages.cs). Called once, from the constructor (no Host yet).
@@ -475,9 +484,10 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
bool handled = false;
ServerChatCommand(parts, ref handled);
if (handled) return;
- if (verb == ServerVerb.Unknown) Reply.Fail(ServerPackCommands.Unknown(parts[1]) + " " + ServerPackCommands.Usage(Info.Name)[0]);
- else ChatLine(ServerPackCommands.Usage(Info.Name)[0]);
- ChatLine(ServerPackCommands.Usage(Info.Name)[1]);
+ string[] usage = ServerPackCommands.Usage(Info.Name, _usageLines);
+ if (verb == ServerVerb.Unknown) Reply.Fail(ServerPackCommands.Unknown(parts[1]) + " " + usage[0]);
+ else ChatLine(usage[0]);
+ for (int i = 1; i < usage.Length; i++) ChatLine(usage[i]);
}
private void PrintInfo()
diff --git a/Tools/RynthServerPack.Tests/ServerPackCommandsTests.cs b/Tools/RynthServerPack.Tests/ServerPackCommandsTests.cs
index 7ab9644..7a50db9 100644
--- a/Tools/RynthServerPack.Tests/ServerPackCommandsTests.cs
+++ b/Tools/RynthServerPack.Tests/ServerPackCommandsTests.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using RynthCore.Plugin.ServerPack;
using RynthCore.Plugin.Shared;
using RynthCore.RynthAiTests.Harness;
@@ -50,6 +51,25 @@ internal static class ServerPackCommandsTests
Check.Eq(usage.Length, 2, "two usage lines");
Check.True(usage[0].Contains("/rserver [show|hide|toggle]") && usage[1].Contains("/rserver auto|on|off"), "the usage names every verb");
Check.Eq(ServerPackCommands.Unknown("wobble"), "Unknown '/rserver wobble'.", "an unknown word");
+
+ // A server without ServerUsageLines (Coldeve) prints exactly the two shared lines, byte for byte.
+ string[] pinned =
+ {
+ "/rserver [show|hide|toggle] - the Coldeve server card (also in the Mini Remote's Char section).",
+ "/rserver info - what is known about Coldeve; /rserver auto|on|off - this character's override.",
+ };
+ Check.Eq(string.Join("\n", usage), string.Join("\n", pinned), "hookless usage is unchanged");
+ Check.Eq(string.Join("\n", ServerPackCommands.Usage("Coldeve", new List())), string.Join("\n", pinned), "no own lines: unchanged");
+ Check.Eq(string.Join("\n", ServerPackCommands.Usage("Coldeve", new List { "", " " })), string.Join("\n", pinned), "blank own lines are dropped");
+ string coldeve = string.Join("\n", System.IO.Directory.GetFiles(System.IO.Path.Combine(ServerProjectsTests.PluginsDir(), "RynthCore.Plugin.RynthColdeve"), "*.cs", System.IO.SearchOption.AllDirectories)
+ .Where(f => !f.Contains("\\obj\\") && !f.Contains("\\bin\\")).Select(System.IO.File.ReadAllText));
+ Check.False(coldeve.Contains("ServerUsageLines", StringComparison.Ordinal), "Coldeve has no ServerUsageLines (so the pin above is what it prints)");
+
+ // A server's own lines follow the shared two, which stay first and unchanged.
+ string[] own = ServerPackCommands.Usage("Coldeve", new List { " /rserver x - one more line " });
+ Check.Eq(own.Length, 3, "an own line is appended");
+ Check.Eq(own[2], "/rserver x - one more line", "trimmed");
+ Check.True(own[0] == pinned[0] && own[1] == pinned[1], "the shared two come first, unchanged");
}
private static void Queue()
diff --git a/Tools/RynthServerPack.Tests/ServerProjectsTests.cs b/Tools/RynthServerPack.Tests/ServerProjectsTests.cs
index 621b92c..7e8468b 100644
--- a/Tools/RynthServerPack.Tests/ServerProjectsTests.cs
+++ b/Tools/RynthServerPack.Tests/ServerProjectsTests.cs
@@ -35,7 +35,7 @@ internal static class ServerProjectsTests
"levistras",
};
- private static string PluginsDir()
+ internal static string PluginsDir()
{
string? dir = AppContext.BaseDirectory;
while (dir != null && !Directory.Exists(Path.Combine(dir, "Plugins", "Shared", "ServerPack")))