2019-03-30 00:14:32 +01:00
|
|
|
/**
|
|
|
|
* Functions used to determine whether the target can be hacked (or grown/weakened).
|
|
|
|
* Meant to be used for Netscript implementation
|
|
|
|
*
|
|
|
|
* The returned status object's message should be used for logging in Netscript
|
|
|
|
*/
|
|
|
|
import { IReturnStatus } from "../types";
|
|
|
|
|
|
|
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
|
|
|
import { Server } from "../Server/Server";
|
|
|
|
|
2019-05-05 06:03:40 +02:00
|
|
|
function baseCheck(server: Server, fnName: string): IReturnStatus {
|
|
|
|
const hostname = server.hostname;
|
|
|
|
|
|
|
|
if (!("requiredHackingSkill" in server)) {
|
2019-03-30 00:14:32 +01:00
|
|
|
return {
|
|
|
|
res: false,
|
2019-05-05 06:03:40 +02:00
|
|
|
msg: `Cannot ${fnName} ${hostname} server because it is a Hacknet Node`
|
2019-03-30 00:14:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (server.hasAdminRights === false) {
|
|
|
|
return {
|
|
|
|
res: false,
|
2019-05-05 06:03:40 +02:00
|
|
|
msg: `Cannot ${fnName} ${hostname} server because you do not have root access`,
|
2019-03-30 00:14:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { res: true }
|
|
|
|
}
|
|
|
|
|
2019-05-05 06:03:40 +02:00
|
|
|
export function netscriptCanHack(server: Server, p: IPlayer): IReturnStatus {
|
2019-03-30 00:14:32 +01:00
|
|
|
const initialCheck = baseCheck(server, "hack");
|
|
|
|
if (!initialCheck.res) { return initialCheck; }
|
|
|
|
|
2019-05-05 06:03:40 +02:00
|
|
|
let s = server;
|
2019-03-30 00:14:32 +01:00
|
|
|
if (s.requiredHackingSkill > p.hacking_skill) {
|
|
|
|
return {
|
|
|
|
res: false,
|
|
|
|
msg: `Cannot hack ${server.hostname} server because your hacking skill is not high enough`,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { res: true }
|
|
|
|
}
|
|
|
|
|
2019-05-05 06:03:40 +02:00
|
|
|
export function netscriptCanGrow(server: Server): IReturnStatus {
|
2019-03-30 00:14:32 +01:00
|
|
|
return baseCheck(server, "grow");
|
|
|
|
}
|
|
|
|
|
2019-05-05 06:03:40 +02:00
|
|
|
export function netscriptCanWeaken(server: Server): IReturnStatus {
|
2019-03-30 00:14:32 +01:00
|
|
|
return baseCheck(server, "weaken");
|
|
|
|
}
|