mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-22 14:12:27 +01:00
BUGFIX: Block hacking-related actions on player-owned servers (#1585)
This commit is contained in:
parent
a9cb46606c
commit
4a1506cf7e
@ -9,28 +9,28 @@ import { IReturnStatus } from "../types";
|
|||||||
import { Player } from "@player";
|
import { Player } from "@player";
|
||||||
import { Server } from "../Server/Server";
|
import { Server } from "../Server/Server";
|
||||||
|
|
||||||
function baseCheck(server: Server, fnName: string): IReturnStatus {
|
function baseCheck(server: Server, actionName: string): IReturnStatus {
|
||||||
const hostname = server.hostname;
|
const hostname = server.hostname;
|
||||||
|
|
||||||
if (!("requiredHackingSkill" in server)) {
|
if (server.purchasedByPlayer) {
|
||||||
return {
|
return {
|
||||||
res: false,
|
res: false,
|
||||||
msg: `Cannot ${fnName} ${hostname} server because it is a Hacknet Node`,
|
msg: `Cannot ${actionName} ${hostname} server because it is your server`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server.hasAdminRights) {
|
if (!server.hasAdminRights) {
|
||||||
return {
|
return {
|
||||||
res: false,
|
res: false,
|
||||||
msg: `Cannot ${fnName} ${hostname} server because you do not have root access`,
|
msg: `Cannot ${actionName} ${hostname} server because you do not have root access`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return { res: true };
|
return { res: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function netscriptCanHack(server: Server): IReturnStatus {
|
export function netscriptCanHack(server: Server, customActionName?: string): IReturnStatus {
|
||||||
const initialCheck = baseCheck(server, "hack");
|
const initialCheck = baseCheck(server, customActionName ?? "hack");
|
||||||
if (!initialCheck.res) {
|
if (!initialCheck.res) {
|
||||||
return initialCheck;
|
return initialCheck;
|
||||||
}
|
}
|
||||||
|
@ -559,14 +559,14 @@ 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");
|
helpers.log(ctx, () => "Cannot backdoor this kind of server");
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
const server = baseserver;
|
const server = baseserver;
|
||||||
const installTime = (calculateHackingTime(server, Player) / 4) * 1000;
|
const installTime = (calculateHackingTime(server, Player) / 4) * 1000;
|
||||||
|
|
||||||
// No root access or skill level too low
|
// No root access or skill level too low
|
||||||
const canHack = netscriptCanHack(server);
|
const canHack = netscriptCanHack(server, "backdoor");
|
||||||
if (!canHack.res) {
|
if (!canHack.res) {
|
||||||
throw helpers.errorMessage(ctx, canHack.msg || "");
|
throw helpers.errorMessage(ctx, canHack.msg || "");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user