simplify/dehardcode failOnHacknetServer

This commit is contained in:
Snarling 2022-09-05 10:35:12 -04:00
parent 83c62bbc63
commit 824d8db653
2 changed files with 13 additions and 13 deletions

@ -686,9 +686,9 @@ function createPublicRunningScript(runningScript: RunningScript): IRunningScript
* @param {string} callingFn - Name of calling function. For logging purposes
* @returns {boolean} True if the server is a Hacknet Server, false otherwise
*/
function failOnHacknetServer(ctx: NetscriptContext, server: BaseServer, callingFn = ""): boolean {
function failOnHacknetServer(ctx: NetscriptContext, server: BaseServer): boolean {
if (server instanceof HacknetServer) {
ctx.workerScript.log(callingFn, () => `Does not work on Hacknet Servers`);
log(ctx, () => `Does not work on Hacknet Servers`);
return true;
} else {
return false;

@ -1110,7 +1110,7 @@ const base: InternalAPI<NS> = {
helpers.log(ctx, () => "Cannot be executed on this server.");
return 0;
}
if (helpers.failOnHacknetServer(ctx, server, "getServerMoneyAvailable")) {
if (helpers.failOnHacknetServer(ctx, server)) {
return 0;
}
if (server.hostname == "home") {
@ -1130,7 +1130,7 @@ const base: InternalAPI<NS> = {
helpers.log(ctx, () => "Cannot be executed on this server.");
return 1;
}
if (helpers.failOnHacknetServer(ctx, server, "getServerSecurityLevel")) {
if (helpers.failOnHacknetServer(ctx, server)) {
return 1;
}
helpers.log(
@ -1149,7 +1149,7 @@ const base: InternalAPI<NS> = {
helpers.log(ctx, () => "Cannot be executed on this server.");
return 1;
}
if (helpers.failOnHacknetServer(ctx, server, "getServerBaseSecurityLevel")) {
if (helpers.failOnHacknetServer(ctx, server)) {
return 1;
}
helpers.log(
@ -1167,7 +1167,7 @@ const base: InternalAPI<NS> = {
helpers.log(ctx, () => "Cannot be executed on this server.");
return 1;
}
if (helpers.failOnHacknetServer(ctx, server, "getServerMinSecurityLevel")) {
if (helpers.failOnHacknetServer(ctx, server)) {
return 1;
}
helpers.log(
@ -1185,7 +1185,7 @@ const base: InternalAPI<NS> = {
helpers.log(ctx, () => "Cannot be executed on this server.");
return 1;
}
if (helpers.failOnHacknetServer(ctx, server, "getServerRequiredHackingLevel")) {
if (helpers.failOnHacknetServer(ctx, server)) {
return 1;
}
helpers.log(
@ -1203,7 +1203,7 @@ const base: InternalAPI<NS> = {
helpers.log(ctx, () => "Cannot be executed on this server.");
return 0;
}
if (helpers.failOnHacknetServer(ctx, server, "getServerMaxMoney")) {
if (helpers.failOnHacknetServer(ctx, server)) {
return 0;
}
helpers.log(ctx, () => `returned ${numeralWrapper.formatMoney(server.moneyMax)} for '${server.hostname}'`);
@ -1218,7 +1218,7 @@ const base: InternalAPI<NS> = {
helpers.log(ctx, () => "Cannot be executed on this server.");
return 1;
}
if (helpers.failOnHacknetServer(ctx, server, "getServerGrowth")) {
if (helpers.failOnHacknetServer(ctx, server)) {
return 1;
}
helpers.log(ctx, () => `returned ${server.serverGrowth} for '${server.hostname}'`);
@ -1233,7 +1233,7 @@ const base: InternalAPI<NS> = {
helpers.log(ctx, () => "Cannot be executed on this server.");
return 5;
}
if (helpers.failOnHacknetServer(ctx, server, "getServerNumPortsRequired")) {
if (helpers.failOnHacknetServer(ctx, server)) {
return 5;
}
helpers.log(ctx, () => `returned ${server.numOpenPortsRequired} for '${server.hostname}'`);
@ -1679,7 +1679,7 @@ const base: InternalAPI<NS> = {
helpers.log(ctx, () => "invalid for this kind of server");
return Infinity;
}
if (helpers.failOnHacknetServer(ctx, server, "getHackTime")) {
if (helpers.failOnHacknetServer(ctx, server)) {
return Infinity;
}
@ -1694,7 +1694,7 @@ const base: InternalAPI<NS> = {
helpers.log(ctx, () => "invalid for this kind of server");
return Infinity;
}
if (helpers.failOnHacknetServer(ctx, server, "getGrowTime")) {
if (helpers.failOnHacknetServer(ctx, server)) {
return Infinity;
}
@ -1709,7 +1709,7 @@ const base: InternalAPI<NS> = {
helpers.log(ctx, () => "invalid for this kind of server");
return Infinity;
}
if (helpers.failOnHacknetServer(ctx, server, "getWeakenTime")) {
if (helpers.failOnHacknetServer(ctx, server)) {
return Infinity;
}