From 1b03618555e065160e6ce7307e08aacaed3daefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Giera?= <42799650+Specker@users.noreply.github.com> Date: Sun, 7 Jan 2024 13:57:54 +0100 Subject: [PATCH] REMOTE: Added possibility to change target IP of remote API (#943) --- src/GameOptions/ui/RemoteAPIPage.tsx | 32 ++++++++++++++++++++++++++-- src/RemoteFileAPI/RemoteFileAPI.ts | 7 ++++-- src/Settings/Settings.ts | 2 ++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/GameOptions/ui/RemoteAPIPage.tsx b/src/GameOptions/ui/RemoteAPIPage.tsx index 4c4015334..b46735f1b 100644 --- a/src/GameOptions/ui/RemoteAPIPage.tsx +++ b/src/GameOptions/ui/RemoteAPIPage.tsx @@ -7,12 +7,18 @@ import { isRemoteFileApiConnectionLive, newRemoteFileApiConnection } from "../.. export const RemoteAPIPage = (): React.ReactElement => { const [remoteFileApiPort, setRemoteFileApiPort] = useState(Settings.RemoteFileApiPort); + const [remoteFileApiAddress, setRemoteFileApiAddress] = useState(Settings.RemoteFileApiAddress); function handleRemoteFileApiPortChange(event: React.ChangeEvent): void { setRemoteFileApiPort(Number(event.target.value)); Settings.RemoteFileApiPort = Number(event.target.value); } + function handleRemoteFileApiAddressChange(event: React.ChangeEvent): void { + setRemoteFileApiAddress(String(event.target.value)); + Settings.RemoteFileApiAddress = String(event.target.value); + } + return ( @@ -31,7 +37,27 @@ export const RemoteAPIPage = (): React.ReactElement => { - 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. + + } + > + Address: , + }} + value={remoteFileApiAddress} + onChange={handleRemoteFileApiAddressChange} + placeholder="localhost" + size={"medium"} + /> + +
+ + 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. } @@ -44,13 +70,15 @@ export const RemoteAPIPage = (): React.ReactElement => { Port:  ), - endAdornment: , }} value={remoteFileApiPort} onChange={handleRemoteFileApiPortChange} placeholder="12525" + size={"medium"} /> +
+
); }; diff --git a/src/RemoteFileAPI/RemoteFileAPI.ts b/src/RemoteFileAPI/RemoteFileAPI.ts index 82c82a462..d15dc6d53 100644 --- a/src/RemoteFileAPI/RemoteFileAPI.ts +++ b/src/RemoteFileAPI/RemoteFileAPI.ts @@ -5,8 +5,11 @@ let server: Remote; export function newRemoteFileApiConnection(): void { if (server) server.stopConnection(); - if (Settings.RemoteFileApiPort === 0) return; - server = new Remote("localhost", Settings.RemoteFileApiPort); + if (Settings.RemoteFileApiPort === 0 || Settings.RemoteFileApiPort > 65535) return; + server = new Remote( + Settings.RemoteFileApiAddress === "" ? "localhost" : Settings.RemoteFileApiAddress, + Settings.RemoteFileApiPort, + ); server.startConnection(); } diff --git a/src/Settings/Settings.ts b/src/Settings/Settings.ts index bf896f8da..5e3a3f763 100644 --- a/src/Settings/Settings.ts +++ b/src/Settings/Settings.ts @@ -42,6 +42,8 @@ export const Settings = { MaxPortCapacity: 50, /** Limit the number of entries in the terminal. */ 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. */ RemoteFileApiPort: 0, /** Whether to save the game when the player saves any file. */