import { type FormEvent, useState } from "react"; import { platformApiClient } from "../api/client"; import { scumAnnouncementCommand, scumManagementRCONCommandRequest } from "../schemas/scumManagementRcon"; import { ResultBadge } from "./StateViews"; interface SourceRCONCommandPanelProps { serverId: string; pluginId: string; } type DispatchState = { status: "pending" | "succeeded" | "failed"; label: string } | null; export function SourceRCONCommandPanel({ serverId, pluginId }: SourceRCONCommandPanelProps) { const [announcement, setAnnouncement] = useState(""); const [rawCommand, setRawCommand] = useState(""); const [pending, setPending] = useState<"announcement" | "command" | null>(null); const [dispatch, setDispatch] = useState(null); if (pluginId !== "game.scum") { return null; } async function sendAnnouncement(event: FormEvent) { event.preventDefault(); setPending("announcement"); setDispatch({ status: "pending", label: "正在提交服务器公告" }); try { const submitted = await platformApiClient.queueGameClientBridgeCommand(serverId, scumManagementRCONCommandRequest(serverId, scumAnnouncementCommand(announcement))); setAnnouncement(""); setDispatch({ status: "succeeded", label: protectedRCONDispatchLabel(submitted.id, submitted.state) }); } catch (error) { setDispatch({ status: "failed", label: error instanceof Error ? error.message : "服务器公告提交失败" }); } finally { setPending(null); } } async function sendRawCommand(event: FormEvent) { event.preventDefault(); setPending("command"); setDispatch({ status: "pending", label: "正在提交原始管理员指令" }); try { const submitted = await platformApiClient.queueGameClientBridgeCommand(serverId, scumManagementRCONCommandRequest(serverId, rawCommand)); setRawCommand(""); setDispatch({ status: "succeeded", label: protectedRCONDispatchLabel(submitted.id, submitted.state) }); } catch (error) { setDispatch({ status: "failed", label: error instanceof Error ? error.message : "原始管理员指令提交失败" }); } finally { setPending(null); } } return (

SCUM 公告与管理员指令

通过插件声明的 protected RCON 通道派发;只显示安全状态,不保留指令原文。

{dispatch && }

发送公告

void sendAnnouncement(event)}>