REMOTE: Added possibility to change target IP of remote API (#943)

This commit is contained in:
Miłosz Giera
2024-01-07 13:57:54 +01:00
committed by GitHub
parent 68a8427838
commit 1b03618555
3 changed files with 37 additions and 4 deletions

View File

@ -7,12 +7,18 @@ import { isRemoteFileApiConnectionLive, newRemoteFileApiConnection } from "../..
export const RemoteAPIPage = (): React.ReactElement => { export const RemoteAPIPage = (): React.ReactElement => {
const [remoteFileApiPort, setRemoteFileApiPort] = useState(Settings.RemoteFileApiPort); const [remoteFileApiPort, setRemoteFileApiPort] = useState(Settings.RemoteFileApiPort);
const [remoteFileApiAddress, setRemoteFileApiAddress] = useState(Settings.RemoteFileApiAddress);
function handleRemoteFileApiPortChange(event: React.ChangeEvent<HTMLInputElement>): void { function handleRemoteFileApiPortChange(event: React.ChangeEvent<HTMLInputElement>): void {
setRemoteFileApiPort(Number(event.target.value)); setRemoteFileApiPort(Number(event.target.value));
Settings.RemoteFileApiPort = Number(event.target.value); Settings.RemoteFileApiPort = Number(event.target.value);
} }
function handleRemoteFileApiAddressChange(event: React.ChangeEvent<HTMLInputElement>): void {
setRemoteFileApiAddress(String(event.target.value));
Settings.RemoteFileApiAddress = String(event.target.value);
}
return ( return (
<GameOptionsPage title="Remote API"> <GameOptionsPage title="Remote API">
<Typography> <Typography>
@ -31,7 +37,27 @@ export const RemoteAPIPage = (): React.ReactElement => {
<Tooltip <Tooltip
title={ title={
<Typography> <Typography>
This port number is used to connect to a Remote API port, please ensure that it matches with your Remote API This address is used to connect to a Remote API, please ensure that it matches with your Remote API address.
Default localhost.
</Typography>
}
>
<TextField
key={"remoteAPIAddress"}
InputProps={{
startAdornment: <Typography>Address:&nbsp;</Typography>,
}}
value={remoteFileApiAddress}
onChange={handleRemoteFileApiAddressChange}
placeholder="localhost"
size={"medium"}
/>
</Tooltip>
<br />
<Tooltip
title={
<Typography>
This port number is used to connect to a Remote API, please ensure that it matches with your Remote API
server port. Set to 0 to disable the feature. server port. Set to 0 to disable the feature.
</Typography> </Typography>
} }
@ -44,13 +70,15 @@ export const RemoteAPIPage = (): React.ReactElement => {
Port:&nbsp; Port:&nbsp;
</Typography> </Typography>
), ),
endAdornment: <Button onClick={newRemoteFileApiConnection}>Connect</Button>,
}} }}
value={remoteFileApiPort} value={remoteFileApiPort}
onChange={handleRemoteFileApiPortChange} onChange={handleRemoteFileApiPortChange}
placeholder="12525" placeholder="12525"
size={"medium"}
/> />
</Tooltip> </Tooltip>
<br />
<Button onClick={newRemoteFileApiConnection}>Connect</Button>
</GameOptionsPage> </GameOptionsPage>
); );
}; };

View File

@ -5,8 +5,11 @@ let server: Remote;
export function newRemoteFileApiConnection(): void { export function newRemoteFileApiConnection(): void {
if (server) server.stopConnection(); if (server) server.stopConnection();
if (Settings.RemoteFileApiPort === 0) return; if (Settings.RemoteFileApiPort === 0 || Settings.RemoteFileApiPort > 65535) return;
server = new Remote("localhost", Settings.RemoteFileApiPort); server = new Remote(
Settings.RemoteFileApiAddress === "" ? "localhost" : Settings.RemoteFileApiAddress,
Settings.RemoteFileApiPort,
);
server.startConnection(); server.startConnection();
} }

View File

@ -42,6 +42,8 @@ export const Settings = {
MaxPortCapacity: 50, MaxPortCapacity: 50,
/** Limit the number of entries in the terminal. */ /** Limit the number of entries in the terminal. */
MaxTerminalCapacity: 500, MaxTerminalCapacity: 500,
/** IP address the Remote File API client will try to connect to. Default localhost . */
RemoteFileApiAddress: "localhost",
/** Port the Remote File API client will try to connect to. 0 to disable. */ /** Port the Remote File API client will try to connect to. 0 to disable. */
RemoteFileApiPort: 0, RemoteFileApiPort: 0,
/** Whether to save the game when the player saves any file. */ /** Whether to save the game when the player saves any file. */