| name | ra3-maputils-companion-http |
| description | Detects whether the Ra3MapUtils desktop app (地编伴侣) is running by calling its local HTTP companion-presence endpoint. Use when the user asks if 地编伴侣 or Ra3MapUtils is running, alive, up, reachable, or before relying on other localhost:30033 APIs. |
地编伴侣是否在运行(HTTP)
基址
Ra3MapUtils 内置 Kestrel:http://127.0.0.1:30033(仅本机)。
专用接口(识别应用身份)
| 方法 | 路径 | 作用 |
|---|
GET | /api/status/companion | 返回固定 appId 与展示名,用于确认是地编伴侣而非误连其他服务 |
完整 URL:http://127.0.0.1:30033/api/status/companion
判定步骤
- 连接失败 / 超时 / 非 HTTP → 视为未运行或本机服务不可达(可提示用户先启动地编伴侣)。
- HTTP 200 且响应 JSON:
- 根字段
code === 1000(成功,见 Ra3MapUtils ApiResponseCode.Success)
- 且
data.appId === "Ra3MapUtils"( Newtonsoft 默认 camelCase 时为 data.appId)
→ 地编伴侣进程已启动且 HTTP 服务可用。
- 可选:向用户附带
data.displayName(地编伴侣)、data.version。
data.running 在成功响应中应为 true;仍以 code 与 appId 为准。
轻量探活(不区分应用)
GET /api/status/ping 返回 pong 也可说明端口上有服务,但不能区分是否为 Ra3MapUtils。需要确认是地编伴侣时,请用 /api/status/companion。
curl 示例
curl -s "http://127.0.0.1:30033/api/status/companion"
PowerShell 也可用 Invoke-RestMethod 解析 JSON 后检查 code 与 data.appId。
代理执行说明
在对话中需要判断地编伴侣是否运行时:用终端执行上述请求,根据结果回答用户;若失败,明确说明可能未启动或端口被占用。