MISC: Cancel spawned scripts in Bitverse (#1429)

This commit is contained in:
catloversg 2024-06-25 12:20:08 +07:00 committed by GitHub
parent bf8c15332e
commit fd8eae5cf5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -108,6 +108,8 @@ import { getEnumHelper } from "./utils/EnumHelper";
import { setDeprecatedProperties, deprecationWarning } from "./utils/DeprecationHelper"; import { setDeprecatedProperties, deprecationWarning } from "./utils/DeprecationHelper";
import { ServerConstants } from "./Server/data/Constants"; import { ServerConstants } from "./Server/data/Constants";
import { assertFunction } from "./Netscript/TypeAssertion"; import { assertFunction } from "./Netscript/TypeAssertion";
import { Router } from "./ui/GameRoot";
import { Page } from "./ui/Router";
export const enums: NSEnums = { export const enums: NSEnums = {
CityName, CityName,
@ -736,6 +738,10 @@ export const ns: InternalAPI<NSFull> = {
const runOpts = helpers.spawnOptions(ctx, _thread_or_opt); const runOpts = helpers.spawnOptions(ctx, _thread_or_opt);
const args = helpers.scriptArgs(ctx, _args); const args = helpers.scriptArgs(ctx, _args);
setTimeout(() => { setTimeout(() => {
if (Router.page() === Page.BitVerse) {
helpers.log(ctx, () => `Script execution is canceled because you are in Bitverse.`);
return;
}
const scriptServer = GetServer(ctx.workerScript.hostname); const scriptServer = GetServer(ctx.workerScript.hostname);
if (scriptServer === null) { if (scriptServer === null) {
throw helpers.errorMessage(ctx, `Cannot find server ${ctx.workerScript.hostname}`); throw helpers.errorMessage(ctx, `Cannot find server ${ctx.workerScript.hostname}`);