mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 07:24:52 +09:00
It makes more sense to put the address first then have the large structure to send as the second argument to sendTo. The opposite order was originally chosen to be similar to that of sendto in BSD sockets.
50 lines
1.1 KiB
React
50 lines
1.1 KiB
React
import React, { useContext, useState } from "react";
|
|
import { Input, Typography } from "antd";
|
|
|
|
import { libData } from "@clusterio/lib";
|
|
|
|
import ControlContext from "./ControlContext";
|
|
import { notifyErrorHandler } from "../util/notify";
|
|
|
|
const { Title, Paragraph } = Typography;
|
|
|
|
|
|
export default function InstanceRcon(props) {
|
|
let control = useContext(ControlContext);
|
|
let [output, setOutput] = useState(null);
|
|
let [running, setRunning] = useState(false);
|
|
|
|
async function sendCommand(command) {
|
|
if (!command) {
|
|
setOutput(null);
|
|
return;
|
|
}
|
|
|
|
setRunning(true);
|
|
try {
|
|
let result = await control.sendTo(
|
|
{ instanceId: props.id },
|
|
new libData.InstanceSendRconRequest(command),
|
|
);
|
|
setOutput(result);
|
|
} finally {
|
|
setRunning(false);
|
|
}
|
|
}
|
|
|
|
return <>
|
|
{output && <>
|
|
<Title level={5}>Rcon result</Title>
|
|
<Paragraph code className="rcon-result">{output}</Paragraph>
|
|
</>}
|
|
<Input.Search
|
|
disabled={props.disabled}
|
|
placeholder="Send RCON Command"
|
|
enterButton="Send"
|
|
onSearch={(command) => sendCommand(command).catch(notifyErrorHandler("Error sending command"))}
|
|
loading={running}
|
|
/>
|
|
</>;
|
|
}
|
|
|