mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-11 02:03:58 +01:00
commit
dfdb940aa6
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,6 +1,7 @@
|
|||||||
import { isString } from "./utils/helpers/isString";
|
import { isString } from "./utils/helpers/isString";
|
||||||
import { GetServer } from "./Server/AllServers";
|
import { GetServer } from "./Server/AllServers";
|
||||||
import { WorkerScript } from "./Netscript/WorkerScript";
|
import { WorkerScript } from "./Netscript/WorkerScript";
|
||||||
|
import { BlobsMap } from "./NetscriptJSEvaluator";
|
||||||
|
|
||||||
export function netscriptDelay(time: number, workerScript: WorkerScript): Promise<void> {
|
export function netscriptDelay(time: number, workerScript: WorkerScript): Promise<void> {
|
||||||
return new Promise(function (resolve) {
|
return new Promise(function (resolve) {
|
||||||
@ -18,6 +19,10 @@ export function makeRuntimeRejectMsg(workerScript: WorkerScript, msg: string): s
|
|||||||
throw new Error(`WorkerScript constructed with invalid server ip: ${workerScript.hostname}`);
|
throw new Error(`WorkerScript constructed with invalid server ip: ${workerScript.hostname}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const url in BlobsMap) {
|
||||||
|
msg = msg.replace(new RegExp(url, "g"), BlobsMap[url]);
|
||||||
|
}
|
||||||
|
|
||||||
return "|DELIMITER|" + server.hostname + "|DELIMITER|" + workerScript.name + "|DELIMITER|" + msg;
|
return "|DELIMITER|" + server.hostname + "|DELIMITER|" + workerScript.name + "|DELIMITER|" + msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1056,12 +1056,16 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
if (scriptname && scriptname.constructor === Array) {
|
if (scriptname && scriptname.constructor === Array) {
|
||||||
// Recursively call scp on all elements of array
|
// Recursively call scp on all elements of array
|
||||||
let res = false;
|
const scripts: Array<string> = scriptname;
|
||||||
await scriptname.forEach(async function (script) {
|
if (scripts.length === 0) {
|
||||||
if (await NetscriptFunctions(workerScript).scp(script, hostname1, hostname2)) {
|
throw makeRuntimeErrorMsg("scp", "No scripts to copy");
|
||||||
res = true;
|
}
|
||||||
|
let res = true;
|
||||||
|
await Promise.all(scripts.map(async function(script) {
|
||||||
|
if (!await NetscriptFunctions(workerScript).scp(script, hostname1, hostname2)) {
|
||||||
|
res = false;
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
return Promise.resolve(res);
|
return Promise.resolve(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ import { ScriptUrl } from "./Script/ScriptUrl";
|
|||||||
import { WorkerScript } from "./Netscript/WorkerScript";
|
import { WorkerScript } from "./Netscript/WorkerScript";
|
||||||
import { Script } from "./Script/Script";
|
import { Script } from "./Script/Script";
|
||||||
|
|
||||||
|
export const BlobsMap: { [key: string]: string } = {};
|
||||||
|
|
||||||
// Makes a blob that contains the code of a given script.
|
// Makes a blob that contains the code of a given script.
|
||||||
function makeScriptBlob(code: string): Blob {
|
function makeScriptBlob(code: string): Blob {
|
||||||
return new Blob([code], { type: "text/javascript" });
|
return new Blob([code], { type: "text/javascript" });
|
||||||
@ -19,7 +21,10 @@ export async function compile(script: Script, scripts: Script[]): Promise<void>
|
|||||||
// by placing it inside an eval call.
|
// by placing it inside an eval call.
|
||||||
await script.updateRamUsage(scripts);
|
await script.updateRamUsage(scripts);
|
||||||
const uurls = _getScriptUrls(script, scripts, []);
|
const uurls = _getScriptUrls(script, scripts, []);
|
||||||
if (script.url) URL.revokeObjectURL(script.url); // remove the old reference.
|
if (script.url) {
|
||||||
|
URL.revokeObjectURL(script.url); // remove the old reference.
|
||||||
|
delete BlobsMap[script.url];
|
||||||
|
}
|
||||||
if (script.dependencies.length > 0) script.dependencies.forEach((dep) => URL.revokeObjectURL(dep.url));
|
if (script.dependencies.length > 0) script.dependencies.forEach((dep) => URL.revokeObjectURL(dep.url));
|
||||||
script.url = uurls[uurls.length - 1].url;
|
script.url = uurls[uurls.length - 1].url;
|
||||||
script.module = new Promise((resolve) => resolve(eval("import(uurls[uurls.length - 1].url)")));
|
script.module = new Promise((resolve) => resolve(eval("import(uurls[uurls.length - 1].url)")));
|
||||||
@ -133,7 +138,9 @@ function _getScriptUrls(script: Script, scripts: Script[], seen: Script[]): Scri
|
|||||||
|
|
||||||
// If we successfully transformed the code, create a blob url for it and
|
// If we successfully transformed the code, create a blob url for it and
|
||||||
// push that URL onto the top of the stack.
|
// push that URL onto the top of the stack.
|
||||||
urlStack.push(new ScriptUrl(script.filename, URL.createObjectURL(makeScriptBlob(transformedCode))));
|
const su = new ScriptUrl(script.filename, URL.createObjectURL(makeScriptBlob(transformedCode)));
|
||||||
|
urlStack.push(su);
|
||||||
|
BlobsMap[su.url] = su.filename;
|
||||||
return urlStack;
|
return urlStack;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// If there is an error, we need to clean up the URLs.
|
// If there is an error, we need to clean up the URLs.
|
||||||
|
@ -140,7 +140,8 @@ function startNetscript2Script(workerScript: WorkerScript): Promise<WorkerScript
|
|||||||
workerScript.errorMessage = e;
|
workerScript.errorMessage = e;
|
||||||
throw workerScript;
|
throw workerScript;
|
||||||
}
|
}
|
||||||
throw e; // Don't know what to do with it, let's rethrow.
|
workerScript.errorMessage = makeRuntimeRejectMsg(workerScript, e);
|
||||||
|
throw workerScript; // Don't know what to do with it, let's rethrow.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,8 +324,8 @@ export function SidebarRoot(props: IProps): React.ReactElement {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("keypress", handleShortcuts);
|
document.addEventListener("keydown", handleShortcuts);
|
||||||
return () => document.removeEventListener("keypress", handleShortcuts);
|
return () => document.removeEventListener("keydown", handleShortcuts);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
Loading…
Reference in New Issue
Block a user