Update Root.tsx

Went back to tracking lastServer as a hostname, since server IPs are not static.
This commit is contained in:
Snarling 2021-08-23 07:03:20 -04:00 committed by danielyxie
parent 1a8b194341
commit faf625b34d

@ -23,6 +23,7 @@ import { libSource } from "../NetscriptDefinitions";
import { NetscriptFunctions } from "../../NetscriptFunctions";
import { WorkerScript } from "../../Netscript/WorkerScript";
import { Settings } from "../../Settings/Settings";
import { GetServerByHostname } from "../../Server/ServerHelpers";
import {
iTutorialNextStep,
ITutorial,
@ -90,7 +91,7 @@ export function Root(props: IProps): React.ReactElement {
useEffect(() => {
if(props.filename === "") return;
if(lastFilename === "")
lastServer = props.player.getCurrentServer();
lastServer = props.player.getCurrentServer().hostname;
lastFilename = props.filename;
lastCode = props.code;
lastPosition = null;
@ -121,11 +122,11 @@ export function Root(props: IProps): React.ReactElement {
}
//Save the script
const server = lastServer;
const server = GetServerByHostname(lastServer);
if(server === null) throw new Error('Server should not be null but it is.');
for (let i = 0; i < server.scripts.length; i++) {
if (filename == server.scripts[i].filename) {
server.scripts[i].saveScript(code, lastServer.ip, server.scripts);
server.scripts[i].saveScript(code, server.ip, server.scripts);
props.engine.loadTerminalContent();
return iTutorialNextStep();
}
@ -133,7 +134,7 @@ export function Root(props: IProps): React.ReactElement {
// If the current script does NOT exist, create a new one
const script = new Script();
script.saveScript(code, lastServer.ip, server.scripts);
script.saveScript(code, server.ip, server.scripts);
server.scripts.push(script);
return iTutorialNextStep();
@ -149,7 +150,7 @@ export function Root(props: IProps): React.ReactElement {
return;
}
const server = lastServer;
const server = GetServerByHostname(lastServer);
if(server === null) throw new Error('Server should not be null but it is.');
if (filename === ".fconf") {
try {
@ -162,7 +163,7 @@ export function Root(props: IProps): React.ReactElement {
//If the current script already exists on the server, overwrite it
for (let i = 0; i < server.scripts.length; i++) {
if (filename == server.scripts[i].filename) {
server.scripts[i].saveScript(code, lastServer.ip, server.scripts);
server.scripts[i].saveScript(code, server.ip, server.scripts);
props.engine.loadTerminalContent();
return;
}
@ -170,7 +171,7 @@ export function Root(props: IProps): React.ReactElement {
//If the current script does NOT exist, create a new one
const script = new Script();
script.saveScript(code, lastServer.ip, server.scripts);
script.saveScript(code, server.ip, server.scripts);
server.scripts.push(script);
} else if (filename.endsWith(".txt")) {
for (let i = 0; i < server.textFiles.length; ++i) {