Skip to content

Commit a8543ec

Browse files
authored
Merge pull request #76 from CedaryCat/develop
Develop
2 parents 4264704 + 2c42ff6 commit a8543ec

41 files changed

Lines changed: 2945 additions & 1453 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,30 +285,36 @@ Startup precedence is:
285285

286286
On interactive terminals, missing port/password prompts use semantic readline with ghost text, rotating suggestions, and live validation/status lines; non-interactive hosts fall back automatically.
287287

288-
`launcher.consoleStatusThresholds` controls command-line status bar thresholding, and `launcher.colorfulConsoleStatus` toggles the vivid ANSI palette when the terminal supports it:
288+
`launcher.consoleStatus` controls command-line status rendering. `launcher.colorfulConsoleStatus` still toggles the vivid ANSI palette, while `launcher.consoleStatus.bandwidthUnit` selects `bytes` (`KB/s -> MB/s -> GB/s -> TB/s`, default) or `bits` (`Kbps -> Mbps -> Gbps -> Tbps`), and `launcher.consoleStatus.bandwidthRolloverThreshold` controls when the formatter promotes to the next unit family step (default: `500.0`).
289289

290290
<details>
291-
<summary><strong>Default status-threshold values</strong></summary>
291+
<summary><strong>Default console-status values</strong></summary>
292292

293293
| Key | Unit | Default | Description |
294294
|:--|:--|:--|:--|
295295
| `targetUps` | UPS | `60.0` | Target update rate used as the baseline for TPS health checks |
296-
| `healthyUpsDeviation` | UPS delta | `1.2` | Maximum absolute deviation from `targetUps` that still counts as healthy |
297-
| `warningUpsDeviation` | UPS delta | `4.0` | Maximum absolute deviation from `targetUps` that still counts as warning before turning bad |
298-
| `utilHealthyMax` | ratio (`0.0`-`1.0`) | `0.50` | Highest busy-utilization value that still counts as healthy |
296+
| `healthyUpsDeviation` | UPS delta | `2.0` | Maximum absolute deviation from `targetUps` that still counts as healthy |
297+
| `warningUpsDeviation` | UPS delta | `5.0` | Maximum absolute deviation from `targetUps` that still counts as warning before turning bad |
298+
| `utilHealthyMax` | ratio (`0.0`-`1.0`) | `0.55` | Highest busy-utilization value that still counts as healthy |
299299
| `utilWarningMax` | ratio (`0.0`-`1.0`) | `0.80` | Highest busy-utilization value that still counts as warning before turning bad |
300300
| `onlineWarnRemainingSlots` | slots | `5` | Remaining player slots at or below this value turn the online indicator to warning |
301301
| `onlineBadRemainingSlots` | slots | `0` | Remaining player slots at or below this value turn the online indicator to bad/full |
302-
| `upWarnKbps` | KB/s | `65.0` | Upstream bandwidth threshold that turns the network indicator to warning |
303-
| `upBadKbps` | KB/s | `75.0` | Upstream bandwidth threshold that turns the network indicator to bad |
304-
| `downWarnKbps` | KB/s | `85.0` | Downstream bandwidth threshold that turns the network indicator to warning |
305-
| `downBadKbps` | KB/s | `95.0` | Downstream bandwidth threshold that turns the network indicator to bad |
302+
| `bandwidthUnit` | enum | `bytes` | Bandwidth display family: `bytes` (`KB/s -> MB/s -> GB/s -> TB/s`) or `bits` (`Kbps -> Mbps -> Gbps -> Tbps`) |
303+
| `bandwidthRolloverThreshold` | current display unit | `500.0` | Value at or above this threshold promotes the formatter to the next bandwidth unit |
304+
| `upWarnKBps` | KB/s | `800.0` | Server upstream bandwidth threshold that turns the network indicator to warning |
305+
| `upBadKBps` | KB/s | `1600.0` | Server upstream bandwidth threshold that turns the network indicator to bad |
306+
| `downWarnKBps` | KB/s | `50.0` | Server downstream bandwidth threshold that turns the network indicator to warning |
307+
| `downBadKBps` | KB/s | `100.0` | Server downstream bandwidth threshold that turns the network indicator to bad |
308+
| `launcherUpWarnKBps` | KB/s | `2400.0` | Launcher upstream bandwidth threshold that turns the network indicator to warning |
309+
| `launcherUpBadKBps` | KB/s | `4800.0` | Launcher upstream bandwidth threshold that turns the network indicator to bad |
310+
| `launcherDownWarnKBps` | KB/s | `150.0` | Launcher downstream bandwidth threshold that turns the network indicator to warning |
311+
| `launcherDownBadKBps` | KB/s | `300.0` | Launcher downstream bandwidth threshold that turns the network indicator to bad |
306312

307313
</details>
308314

309315
After `UnifiedServerCoordinator.Launch(...)` succeeds, the launcher begins watching `config/config.json` for safe hot reloads:
310316

311-
- Live-applied: `launcher.serverPassword`, `launcher.joinServer`, additive `launcher.autoStartServers`, `launcher.listenPort` (listener rebind), `launcher.colorfulConsoleStatus`, `launcher.consoleStatusThresholds`
317+
- Live-applied: `launcher.serverPassword`, `launcher.joinServer`, additive `launcher.autoStartServers`, `launcher.listenPort` (listener rebind), `launcher.colorfulConsoleStatus`, `launcher.consoleStatus`
312318

313319
### Server Definition Keys
314320

docs/README.zh-cn.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,30 +285,36 @@ dotnet run --project src/UnifierTSL/UnifierTSL.csproj -- \
285285

286286
在交互式终端中,缺失端口/密码的补全会使用语义化 readline,提供 ghost 文本、候选轮换和实时校验/状态行;非交互宿主会自动回退。
287287

288-
`launcher.consoleStatusThresholds` 用于控制命令行状态栏阈值,而 `launcher.colorfulConsoleStatus` 用于在终端支持时启用鲜艳 ANSI 配色
288+
`launcher.consoleStatus` 用于控制命令行状态栏渲染。`launcher.colorfulConsoleStatus` 仍然负责鲜艳 ANSI 配色,而 `launcher.consoleStatus.bandwidthUnit` 用于选择带宽显示单位族:`bytes` 显示 `KB/s -> MB/s -> GB/s -> TB/s`(默认),`bits` 显示 `Kbps -> Mbps -> Gbps -> Tbps``launcher.consoleStatus.bandwidthRolloverThreshold` 用于控制何时向上进位到下一个单位(默认 `500.0`)。
289289

290290
<details>
291-
<summary><strong>默认状态阈值</strong></summary>
291+
<summary><strong>默认控制台状态值</strong></summary>
292292

293293
|| 单位 | 默认值 | 描述 |
294294
|:--|:--|:--|:--|
295295
| `targetUps` | UPS | `60.0` | 作为 TPS 健康判断基线的目标更新速率 |
296-
| `healthyUpsDeviation` | UPS 偏差 | `1.2` | 相对 `targetUps` 的绝对偏差不超过该值时仍视为健康 |
297-
| `warningUpsDeviation` | UPS 偏差 | `4.0` | 相对 `targetUps` 的绝对偏差不超过该值时视为警告,再高则转为异常 |
298-
| `utilHealthyMax` | 比例(`0.0`-`1.0`| `0.50` | 忙碌利用率不高于该值时仍视为健康 |
296+
| `healthyUpsDeviation` | UPS 偏差 | `2.0` | 相对 `targetUps` 的绝对偏差不超过该值时仍视为健康 |
297+
| `warningUpsDeviation` | UPS 偏差 | `5.0` | 相对 `targetUps` 的绝对偏差不超过该值时视为警告,再高则转为异常 |
298+
| `utilHealthyMax` | 比例(`0.0`-`1.0`| `0.55` | 忙碌利用率不高于该值时仍视为健康 |
299299
| `utilWarningMax` | 比例(`0.0`-`1.0`| `0.80` | 忙碌利用率不高于该值时视为警告,再高则转为异常 |
300300
| `onlineWarnRemainingSlots` | 槽位数 | `5` | 剩余玩家槽位小于等于该值时,在线指标转为警告 |
301301
| `onlineBadRemainingSlots` | 槽位数 | `0` | 剩余玩家槽位小于等于该值时,在线指标转为异常/满员 |
302-
| `upWarnKbps` | KB/s | `65.0` | 上行带宽达到该阈值时,网络指标转为警告 |
303-
| `upBadKbps` | KB/s | `75.0` | 上行带宽达到该阈值时,网络指标转为异常 |
304-
| `downWarnKbps` | KB/s | `85.0` | 下行带宽达到该阈值时,网络指标转为警告 |
305-
| `downBadKbps` | KB/s | `95.0` | 下行带宽达到该阈值时,网络指标转为异常 |
302+
| `bandwidthUnit` | 枚举 | `bytes` | 带宽显示单位族:`bytes``KB/s -> MB/s -> GB/s -> TB/s`)或 `bits``Kbps -> Mbps -> Gbps -> Tbps`|
303+
| `bandwidthRolloverThreshold` | 当前显示单位 | `500.0` | 数值达到或超过该阈值时,格式化器会进位到下一个带宽单位 |
304+
| `upWarnKBps` | KB/s | `800.0` | Server 上行带宽达到该阈值时,网络指标转为警告 |
305+
| `upBadKBps` | KB/s | `1600.0` | Server 上行带宽达到该阈值时,网络指标转为异常 |
306+
| `downWarnKBps` | KB/s | `50.0` | Server 下行带宽达到该阈值时,网络指标转为警告 |
307+
| `downBadKBps` | KB/s | `100.0` | Server 下行带宽达到该阈值时,网络指标转为异常 |
308+
| `launcherUpWarnKBps` | KB/s | `2400.0` | Launcher 上行带宽达到该阈值时,网络指标转为警告 |
309+
| `launcherUpBadKBps` | KB/s | `4800.0` | Launcher 上行带宽达到该阈值时,网络指标转为异常 |
310+
| `launcherDownWarnKBps` | KB/s | `150.0` | Launcher 下行带宽达到该阈值时,网络指标转为警告 |
311+
| `launcherDownBadKBps` | KB/s | `300.0` | Launcher 下行带宽达到该阈值时,网络指标转为异常 |
306312

307313
</details>
308314

309315
`UnifiedServerCoordinator.Launch(...)` 成功后,启动器会开始监视 `config/config.json`,只做安全范围内的热重载:
310316

311-
- 立即生效:`launcher.serverPassword``launcher.joinServer`、追加式 `launcher.autoStartServers``launcher.listenPort`(监听器重绑)、`launcher.colorfulConsoleStatus``launcher.consoleStatusThresholds`
317+
- 立即生效:`launcher.serverPassword``launcher.joinServer`、追加式 `launcher.autoStartServers``launcher.listenPort`(监听器重绑)、`launcher.colorfulConsoleStatus``launcher.consoleStatus`
312318

313319
### 服务器定义键
314320

docs/dev-overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ For more logging examples, see `src/Plugins/TShockAPI/TShock.cs` and `src/Unifie
14931493
- You get back a `ConfigHandle<T>` that lets you `RequestAsync`, `Overwrite`, `ModifyInMemory`, and subscribe via `OnChangedAsync` for hot reload. File access is guarded by `FileLockManager` to prevent corruption.
14941494
- Launcher root config is separate from plugin config: `LauncherConfigManager` owns `config/config.json`, creates it when missing, and intentionally ignores the legacy root-level `config.json`.
14951495
- Startup precedence for launcher settings is `config/config.json` -> CLI overrides -> interactive fallback for missing port/password, and the effective startup snapshot is persisted back to `config/config.json`. After startup, edits to `config/config.json` apply to the launcher settings that support reload.
1496-
- Root-config hot reload applies `launcher.serverPassword`, `launcher.joinServer`, additive `launcher.autoStartServers`, `launcher.listenPort` (via listener rebind), `launcher.colorfulConsoleStatus`, and `launcher.consoleStatusThresholds`.
1496+
- Root-config hot reload applies `launcher.serverPassword`, `launcher.joinServer`, additive `launcher.autoStartServers`, `launcher.listenPort` (via listener rebind), `launcher.colorfulConsoleStatus`, and `launcher.consoleStatus`.
14971497

14981498
## 3. USP Integration Points
14991499

@@ -1561,7 +1561,7 @@ For more logging examples, see `src/Plugins/TShockAPI/TShock.cs` and `src/Unifie
15611561
### 5.2 Runtime Operations
15621562
- Event handlers handle cross-cutting concerns — chat moderation, transfer control, packet filtering, etc.
15631563
- Config handles react to file changes, so you can tweak settings without restarting.
1564-
- The launcher root config watcher applies password changes, join-policy changes, additive auto-start worlds (hot-add only), `launcher.listenPort` listener rebinding, `launcher.colorfulConsoleStatus`, and `launcher.consoleStatusThresholds`.
1564+
- The launcher root config watcher applies password changes, join-policy changes, additive auto-start worlds (hot-add only), `launcher.listenPort` listener rebinding, `launcher.colorfulConsoleStatus`, and `launcher.consoleStatus`.
15651565
- The coordinator keeps window titles updated, maintains server lists, replays join/leave sequences, and can swap the active listener without tearing down the process.
15661566
- Launcher and per-server consoles now exchange semantic prompt/render/status frames through `TerminalLauncherConsoleHost`, `RemoteConsoleService`, and the console-client protocol, so reconnects can replay cached state instead of dropping back to plain text.
15671567
- Logging metadata and the bounded history ring let you trace any log entry back to its server, plugin, or subsystem, and attach new sinks without losing recent context.

docs/dev-overview.zh-cn.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ Output in Server1's console window with server-specific colors
15041504
- 你得到一个 `ConfigHandle<T>` ,它可以让你 `RequestAsync``Overwrite``ModifyInMemory` ,并通过 `OnChangedAsync` 订阅热重载。文件访问由 `FileLockManager` 保护以防止损坏。
15051505
- 启动器根配置与插件配置分离:`LauncherConfigManager` 专门管理 `config/config.json`,文件缺失时会自动创建,并且会明确忽略旧的根目录 `config.json`
15061506
- 启动器设置的启动优先级是 `config/config.json` -> CLI 覆盖 -> 缺失端口/密码时的交互式补全,并会把启动阶段生效快照回写到 `config/config.json`。启动完成后,对 `config/config.json` 的修改会应用到支持热重载的启动器设置。
1507-
- 根配置热重载会应用 `launcher.serverPassword``launcher.joinServer`、追加式 `launcher.autoStartServers`、通过重绑监听器实现的 `launcher.listenPort``launcher.colorfulConsoleStatus`,以及 `launcher.consoleStatusThresholds`
1507+
- 根配置热重载会应用 `launcher.serverPassword``launcher.joinServer`、追加式 `launcher.autoStartServers`、通过重绑监听器实现的 `launcher.listenPort``launcher.colorfulConsoleStatus`,以及 `launcher.consoleStatus`
15081508

15091509
<a id="3-usp-integration-points"></a>
15101510
## 3. USP 集成点
@@ -1582,7 +1582,7 @@ Output in Server1's console window with server-specific colors
15821582
### 5.2 运行时操作
15831583
- 事件处理程序处理横切问题——聊天审核、传输控制、数据包过滤等。
15841584
- 配置处理对文件更改的反应,因此你可以调整设置而无需重新启动。
1585-
- 启动器根配置监视会热应用密码变更、入服策略变更、追加式自动启动世界(仅热追加)、`launcher.listenPort` 的监听器重绑、`launcher.colorfulConsoleStatus`,以及 `launcher.consoleStatusThresholds`
1585+
- 启动器根配置监视会热应用密码变更、入服策略变更、追加式自动启动世界(仅热追加)、`launcher.listenPort` 的监听器重绑、`launcher.colorfulConsoleStatus`,以及 `launcher.consoleStatus`
15861586
- 协调器保持窗口标题更新,维护服务器列表,重放加入/离开序列,并且可以在不退出进程的前提下切换当前监听器。
15871587
- 启动器和每服务器控制台现在会通过 `TerminalLauncherConsoleHost``RemoteConsoleService` 与控制台客户端协议交换语义化提示/渲染/状态帧,因此重连时可以回放缓存状态,而不必退回纯文本。
15881588
- 日志元数据和有界历史环使你可以把任何日志条目追溯到其服务器、插件或子系统,并在不丢失最近上下文的前提下挂接新 sink。

i18n/UnifierTSL.template.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ msgid "launcher.colorfulConsoleStatus changed from '{0}' to '{1}'. Status bar ap
942942
msgstr ""
943943

944944
#: ..\..\..\src\UnifierTSL\LauncherRuntimeOps.cs:232
945-
msgid "launcher.consoleStatusThresholds changed. Command-line status thresholds are now using the reloaded values."
945+
msgid "launcher.consoleStatus changed. Command-line status settings are now using the reloaded values."
946946
msgstr ""
947947

948948
#: ..\..\..\src\UnifierTSL\LauncherRuntimeOps.cs:975

i18n/zh_CN/UnifierTSL.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,8 @@ msgid "launcher.colorfulConsoleStatus changed from '{0}' to '{1}'. Status bar ap
967967
msgstr "launcher.colorfulConsoleStatus 已从 '{0}' 更改为 '{1}'。状态栏外观已刷新。"
968968

969969
#: ..\..\..\src\UnifierTSL\LauncherRuntimeOps.cs:232
970-
msgid "launcher.consoleStatusThresholds changed. Command-line status thresholds are now using the reloaded values."
971-
msgstr "launcher.consoleStatusThresholds 已更改。命令行状态阈值现已使用重载后的值。"
970+
msgid "launcher.consoleStatus changed. Command-line status settings are now using the reloaded values."
971+
msgstr "launcher.consoleStatus 已更改。命令行状态设置现已使用重载后的值。"
972972

973973
#: ..\..\..\src\UnifierTSL\LauncherRuntimeOps.cs:975
974974
#, csharp-format

src/Plugins/TShockAPI/ConsolePrompting/AnnotatedConsolePromptProvider.cs

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
using UnifierTSL.CLI;
33
using UnifierTSL.CLI.Prompting;
44
using UnifierTSL.Servers;
5-
using Terraria;
6-
using Terraria.ID;
7-
using Terraria.Localization;
8-
using TShockAPI.Localization;
95

106
namespace TShockAPI.ConsolePrompting
117
{
128
internal static class TShockConsolePromptInstaller
139
{
14-
private static readonly Lazy<IReadOnlyList<string>> ItemCandidates = new(BuildItemCandidatesCore);
15-
1610
public static void Install()
1711
{
1812
TShockConsoleParameterExplainers.RegisterDefaults();
@@ -24,9 +18,7 @@ private static ConsolePromptSpec BuildPromptSpec(ServerContext? server)
2418
AnnotatedConsolePromptOptions options = new() {
2519
CommandPrefixResolver = BuildCommandPrefixes,
2620
CommandSpecResolver = () => BuildCommandSpecs(server),
27-
PlayerCandidateResolver = () => BuildPlayerCandidates(server),
28-
ServerCandidateResolver = BuildServerCandidates,
29-
ItemCandidateResolver = BuildItemCandidates,
21+
PlayerCandidateResolver = () => ConsolePromptCommonObjects.GetPlayerCandidates(server),
3022
ParameterExplainerResolver = TShockConsoleParameterExplainers.CreateSnapshot,
3123
};
3224

@@ -105,50 +97,6 @@ private static List<ConsoleCommandSpec> BuildCommandSpecs(ServerContext? server)
10597
return merged;
10698
}
10799

108-
private static IReadOnlyList<string> BuildPlayerCandidates(ServerContext? server)
109-
{
110-
return [.. TShock.Players
111-
.Where(static player => player is not null && player.Active)
112-
.Where(player => server is null || player!.GetCurrentServer() == server)
113-
.Select(player => player!.Name)
114-
.Where(static name => !string.IsNullOrWhiteSpace(name))
115-
.OrderBy(static name => name, StringComparer.OrdinalIgnoreCase)];
116-
}
117-
118-
private static IReadOnlyList<string> BuildServerCandidates()
119-
{
120-
return [.. UnifiedServerCoordinator.Servers
121-
.Where(static server => server.IsRunning)
122-
.Select(static server => server.Name)
123-
.Where(static name => !string.IsNullOrWhiteSpace(name))
124-
.OrderBy(static name => name, StringComparer.OrdinalIgnoreCase)];
125-
}
126-
127-
private static IReadOnlyList<string> BuildItemCandidates()
128-
{
129-
return ItemCandidates.Value;
130-
}
131-
132-
private static IReadOnlyList<string> BuildItemCandidatesCore()
133-
{
134-
HashSet<string> names = new(StringComparer.OrdinalIgnoreCase);
135-
for (int i = 1; i < ItemID.Count; i++) {
136-
AddItemCandidateName(names, Lang.GetItemNameValue(i));
137-
AddItemCandidateName(names, EnglishLanguage.GetItemNameById(i));
138-
}
139-
140-
return [.. names.OrderBy(static name => name, StringComparer.OrdinalIgnoreCase)];
141-
}
142-
143-
private static void AddItemCandidateName(HashSet<string> names, string? value)
144-
{
145-
if (string.IsNullOrWhiteSpace(value)) {
146-
return;
147-
}
148-
149-
names.Add(value.Trim());
150-
}
151-
152100
private static ConsoleCommandSpec Merge(ConsoleCommandSpec runtimeSpec, ConsoleCommandSpec? builtin)
153101
{
154102
if (builtin is null) {

src/Plugins/TShockAPI/ConsolePrompting/BuiltinConsoleCommandSpecs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ private static ConsoleCommandParameterSpec P(
464464
private static string? InferSemanticKey(Kind kind)
465465
{
466466
return kind switch {
467-
Kind.Player => TShockConsoleParameterSemanticKeys.PlayerRef,
468-
Kind.Item => TShockConsoleParameterSemanticKeys.ItemRef,
467+
Kind.Player => ConsolePromptCommonParameterSemanticKeys.PlayerRef,
468+
Kind.Item => ConsolePromptCommonParameterSemanticKeys.ItemRef,
469469
_ => null,
470470
};
471471
}

0 commit comments

Comments
 (0)