From 6a2e5b06ad03de496bf31a051ceed0e7a77a0dd8 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Wed, 25 May 2022 20:19:42 -0400 Subject: [PATCH] fix manualHack --- src/Netscript/APIWrapper.ts | 2 +- src/NetscriptFunctions/Singularity.ts | 61 +++++++++++++-------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/Netscript/APIWrapper.ts b/src/Netscript/APIWrapper.ts index e8fce813d..2037584a2 100644 --- a/src/Netscript/APIWrapper.ts +++ b/src/Netscript/APIWrapper.ts @@ -95,7 +95,7 @@ function wrapFunction( boolean: helpers.boolean, getServer: (hostname: string) => helpers.getServer(hostname, ctx), checkSingularityAccess: () => helpers.checkSingularityAccess(functionName), - hack: helpers.hack, + hack: (hostname: any, manual: any, extra?: any) => helpers.hack(ctx, hostname, manual, extra), getValidPort: (port: any) => helpers.getValidPort(functionPath, port), }, }; diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index 87d0892c8..55ebdba68 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -598,38 +598,37 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript const server = player.getCurrentServer(); return _ctx.helper.hack(server.hostname, true); }, - installBackdoor: (_ctx: NetscriptContext) => - function (): Promise { - _ctx.helper.checkSingularityAccess(); - const baseserver = player.getCurrentServer(); - if (!(baseserver instanceof Server)) { - _ctx.log(() => "cannot backdoor this kind of server"); - return Promise.resolve(); + installBackdoor: (_ctx: NetscriptContext) => async (): Promise => { + _ctx.helper.checkSingularityAccess(); + const baseserver = player.getCurrentServer(); + if (!(baseserver instanceof Server)) { + _ctx.log(() => "cannot backdoor this kind of server"); + return Promise.resolve(); + } + const server = baseserver; + const installTime = (calculateHackingTime(server, player) / 4) * 1000; + + // No root access or skill level too low + const canHack = netscriptCanHack(server, player); + if (!canHack.res) { + throw _ctx.helper.makeRuntimeErrorMsg(canHack.msg || ""); + } + + _ctx.log( + () => `Installing backdoor on '${server.hostname}' in ${convertTimeMsToTimeElapsedString(installTime, true)}`, + ); + + return netscriptDelay(installTime, workerScript).then(function () { + _ctx.log(() => `Successfully installed backdoor on '${server.hostname}'`); + + server.backdoorInstalled = true; + + if (SpecialServers.WorldDaemon === server.hostname) { + Router.toBitVerse(false, false); } - const server = baseserver ; - const installTime = (calculateHackingTime(server, player) / 4) * 1000; - - // No root access or skill level too low - const canHack = netscriptCanHack(server, player); - if (!canHack.res) { - throw _ctx.helper.makeRuntimeErrorMsg(canHack.msg || ""); - } - - _ctx.log( - () => `Installing backdoor on '${server.hostname}' in ${convertTimeMsToTimeElapsedString(installTime, true)}`, - ); - - return netscriptDelay(installTime, workerScript).then(function () { - _ctx.log(() => `Successfully installed backdoor on '${server.hostname}'`); - - server.backdoorInstalled = true; - - if (SpecialServers.WorldDaemon === server.hostname) { - Router.toBitVerse(false, false); - } - return Promise.resolve(); - }); - }, + return Promise.resolve(); + }); + }, isFocused: (_ctx: NetscriptContext) => function (): boolean { _ctx.helper.checkSingularityAccess();