mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-09-19 20:38:42 +02:00
BUGFIX: Fix inconsistencies of error handling in promise-based API (#1377)
This commit is contained in:
parent
701c5d8e64
commit
94eef8ecde
@ -261,13 +261,7 @@ export const ns: InternalAPI<NSFull> = {
|
|||||||
|
|
||||||
const server = helpers.getServer(ctx, hostname);
|
const server = helpers.getServer(ctx, hostname);
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
throw helpers.errorMessage(ctx, "Cannot be executed on this server.");
|
||||||
return Promise.resolve(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const host = GetServer(ctx.workerScript.hostname);
|
|
||||||
if (host === null) {
|
|
||||||
throw new Error("Workerscript host is null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No root access or skill level too low
|
// No root access or skill level too low
|
||||||
@ -286,6 +280,10 @@ export const ns: InternalAPI<NSFull> = {
|
|||||||
)} (t=${formatThreads(threads)}).`,
|
)} (t=${formatThreads(threads)}).`,
|
||||||
);
|
);
|
||||||
return helpers.netscriptDelay(ctx, growTime * 1000).then(function () {
|
return helpers.netscriptDelay(ctx, growTime * 1000).then(function () {
|
||||||
|
const host = GetServer(ctx.workerScript.hostname);
|
||||||
|
if (host === null) {
|
||||||
|
throw helpers.errorMessage(ctx, `Cannot find host of WorkerScript. Hostname: ${ctx.workerScript.hostname}.`);
|
||||||
|
}
|
||||||
const moneyBefore = server.moneyAvailable <= 0 ? 1 : server.moneyAvailable;
|
const moneyBefore = server.moneyAvailable <= 0 ? 1 : server.moneyAvailable;
|
||||||
processSingleServerGrowth(server, threads, host.cpuCores);
|
processSingleServerGrowth(server, threads, host.cpuCores);
|
||||||
const moneyAfter = server.moneyAvailable;
|
const moneyAfter = server.moneyAvailable;
|
||||||
@ -360,8 +358,7 @@ export const ns: InternalAPI<NSFull> = {
|
|||||||
|
|
||||||
const server = helpers.getServer(ctx, hostname);
|
const server = helpers.getServer(ctx, hostname);
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
throw helpers.errorMessage(ctx, "Cannot be executed on this server.");
|
||||||
return Promise.resolve(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No root access or skill level too low
|
// No root access or skill level too low
|
||||||
@ -382,8 +379,7 @@ export const ns: InternalAPI<NSFull> = {
|
|||||||
return helpers.netscriptDelay(ctx, weakenTime * 1000).then(function () {
|
return helpers.netscriptDelay(ctx, weakenTime * 1000).then(function () {
|
||||||
const host = GetServer(ctx.workerScript.hostname);
|
const host = GetServer(ctx.workerScript.hostname);
|
||||||
if (host === null) {
|
if (host === null) {
|
||||||
helpers.log(ctx, () => "Server is null, did it die?");
|
throw helpers.errorMessage(ctx, `Cannot find host of WorkerScript. Hostname: ${ctx.workerScript.hostname}.`);
|
||||||
return Promise.resolve(0);
|
|
||||||
}
|
}
|
||||||
const weakenAmt = getWeakenEffect(threads, host.cpuCores);
|
const weakenAmt = getWeakenEffect(threads, host.cpuCores);
|
||||||
server.weaken(weakenAmt);
|
server.weaken(weakenAmt);
|
||||||
|
@ -559,8 +559,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
|||||||
helpers.checkSingularityAccess(ctx);
|
helpers.checkSingularityAccess(ctx);
|
||||||
const baseserver = Player.getCurrentServer();
|
const baseserver = Player.getCurrentServer();
|
||||||
if (!(baseserver instanceof Server)) {
|
if (!(baseserver instanceof Server)) {
|
||||||
helpers.log(ctx, () => "Cannot backdoor this kind of server");
|
throw helpers.errorMessage(ctx, "Cannot backdoor this kind of server.");
|
||||||
return Promise.resolve();
|
|
||||||
}
|
}
|
||||||
const server = baseserver;
|
const server = baseserver;
|
||||||
const installTime = (calculateHackingTime(server, Player) / 4) * 1000;
|
const installTime = (calculateHackingTime(server, Player) / 4) * 1000;
|
||||||
|
@ -2,7 +2,6 @@ import { Terminal } from "../../Terminal";
|
|||||||
import { Player } from "@player";
|
import { Player } from "@player";
|
||||||
import { BaseServer } from "../../Server/BaseServer";
|
import { BaseServer } from "../../Server/BaseServer";
|
||||||
import { Server } from "../../Server/Server";
|
import { Server } from "../../Server/Server";
|
||||||
import { HacknetServer } from "../../Hacknet/HacknetServer";
|
|
||||||
|
|
||||||
export function backdoor(args: (string | number | boolean)[], server: BaseServer): void {
|
export function backdoor(args: (string | number | boolean)[], server: BaseServer): void {
|
||||||
if (args.length !== 0) {
|
if (args.length !== 0) {
|
||||||
@ -11,24 +10,24 @@ export function backdoor(args: (string | number | boolean)[], server: BaseServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
Terminal.error("Can only backdoor normal servers");
|
Terminal.error("Can only install a backdoor on normal servers");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if (server.purchasedByPlayer) {
|
||||||
const normalServer = server as Server;
|
|
||||||
|
|
||||||
if (normalServer.purchasedByPlayer) {
|
|
||||||
Terminal.error(
|
Terminal.error(
|
||||||
"Cannot use backdoor on your own machines! You are currently connected to your home PC or one of your purchased servers",
|
"Cannot install a backdoor on your own machines! You are currently connected to your home PC or one of your purchased servers.",
|
||||||
);
|
);
|
||||||
} else if (!normalServer.hasAdminRights) {
|
return;
|
||||||
Terminal.error("You do not have admin rights for this machine! Cannot backdoor");
|
|
||||||
} else if (normalServer.requiredHackingSkill > Player.skills.hacking) {
|
|
||||||
Terminal.error(
|
|
||||||
"Your hacking skill is not high enough to use backdoor on this machine. Try analyzing the machine to determine the required hacking skill",
|
|
||||||
);
|
|
||||||
} else if (normalServer instanceof HacknetServer) {
|
|
||||||
Terminal.error("Cannot use backdoor on this type of Server");
|
|
||||||
} else {
|
|
||||||
Terminal.startBackdoor();
|
|
||||||
}
|
}
|
||||||
|
if (!server.hasAdminRights) {
|
||||||
|
Terminal.error("You do not have admin rights for this machine");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (server.requiredHackingSkill > Player.skills.hacking) {
|
||||||
|
Terminal.error(
|
||||||
|
"Your hacking skill is not high enough to install a backdoor on this machine. Try analyzing the machine to determine the required hacking skill.",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Terminal.startBackdoor();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user