import { type FormEvent, useState } from "react"; import { platformApiClient } from "../api/client"; import { sourceRCONChatRequest, sourceRCONRawCommandRequest } from "../schemas/sourceRcon"; 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 [chatType, setChatType] = useState(4); const [chatMessage, setChatMessage] = useState(""); const [targetSteamId, setTargetSteamId] = useState(""); const [rawCommand, setRawCommand] = useState(""); const [pending, setPending] = useState<"chat" | "command" | null>(null); const [dispatch, setDispatch] = useState(null); if (pluginId !== "game.scum") { return null; } async function sendChat(event: FormEvent) { event.preventDefault(); setPending("chat"); setDispatch({ status: "pending", label: "正在提交聊天消息" }); try { const submitted = await platformApiClient.sendSourceRCONCommand(serverId, sourceRCONChatRequest(serverId, { chatType, message: chatMessage, targetSteamId })); setChatMessage(""); setTargetSteamId(""); setDispatch({ status: "succeeded", label: sourceRCONDispatchLabel(submitted.jobId, submitted.status) }); } 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.sendSourceRCONCommand(serverId, sourceRCONRawCommandRequest(serverId, rawCommand)); setRawCommand(""); setDispatch({ status: "succeeded", label: sourceRCONDispatchLabel(submitted.jobId, submitted.status) }); } catch (error) { setDispatch({ status: "failed", label: error instanceof Error ? error.message : "原始管理员指令提交失败" }); } finally { setPending(null); } } return (

SCUM 聊天与管理员指令

立即派发一次性任务;只显示安全状态,不保留聊天或指令记录。

{dispatch && }

发送聊天

void sendChat(event)}>