merge dev

This commit is contained in:
Olivier Gagnon
2021-10-07 17:58:32 -04:00
59 changed files with 617 additions and 671 deletions
+90 -105
View File
@@ -59,18 +59,6 @@ import { Factions, factionExists } from "./Faction/Factions";
import { joinFaction, purchaseAugmentation } from "./Faction/FactionHelpers";
import { netscriptCanGrow, netscriptCanHack, netscriptCanWeaken } from "./Hacking/netscriptCanHack";
import {
getCostOfNextHacknetNode,
getCostOfNextHacknetServer,
hasHacknetServers,
purchaseHacknet,
purchaseLevelUpgrade,
purchaseRamUpgrade,
purchaseCoreUpgrade,
purchaseCacheUpgrade,
purchaseHashUpgrade,
updateHashManagerCapacity,
} from "./Hacknet/HacknetHelpers";
import {
calculateMoneyGainRate,
calculateLevelUpgradeCost,
@@ -101,11 +89,9 @@ import { findRunningScript, findRunningScriptByPid } from "./Script/ScriptHelper
import { isScriptFilename } from "./Script/isScriptFilename";
import { PromptEvent } from "./ui/React/PromptManager";
import { AllServers, AddToAllServers, createUniqueRandomIp } from "./Server/AllServers";
import { GetServer, GetAllServers, DeleteServer, AddToAllServers, createUniqueRandomIp } from "./Server/AllServers";
import { RunningScript } from "./Script/RunningScript";
import {
GetServerByHostname,
getServer,
getServerOnNetwork,
numCycleForGrowth,
processSingleServerGrowth,
@@ -113,7 +99,6 @@ import {
} from "./Server/ServerHelpers";
import { getPurchaseServerCost, getPurchaseServerLimit, getPurchaseServerMaxRam } from "./Server/ServerPurchases";
import { Server } from "./Server/Server";
import { SpecialServerIps } from "./Server/SpecialServerIps";
import { SourceFileFlags } from "./SourceFile/SourceFileFlags";
import { buyStock, sellStock, shortStock, sellShort } from "./StockMarket/BuyingAndSelling";
import { influenceStockThroughServerHack, influenceStockThroughServerGrow } from "./StockMarket/PlayerInfluencing";
@@ -151,7 +136,6 @@ import { IIndustry } from "./Corporation/IIndustry";
import { Faction } from "./Faction/Faction";
import { Augmentation } from "./Augmentation/Augmentation";
import { HacknetNode } from "./Hacknet/HacknetNode";
import { CodingContract } from "./CodingContracts";
import { Stock } from "./StockMarket/Stock";
@@ -214,7 +198,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
let threads = workerScript.scriptRef.threads;
if (typeof threads !== "number") {
console.warn(`WorkerScript detected NaN for threadcount for ${workerScript.name} on ${workerScript.serverIp}`);
console.warn(`WorkerScript detected NaN for threadcount for ${workerScript.name} on ${workerScript.hostname}`);
threads = 1;
}
@@ -253,7 +237,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
* @returns {Server} The specified Server
*/
const safeGetServer = function (ip: any, callingFnName: any = ""): BaseServer {
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg(callingFnName, `Invalid IP/hostname: ${ip}`);
}
@@ -287,7 +271,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (fn != null && typeof fn === "string") {
// Get Logs of another script
if (ip == null) {
ip = workerScript.serverIp;
ip = workerScript.hostname;
}
const server = safeGetServer(ip, callingFnName);
@@ -303,8 +287,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
callingFnName = "getRunningScriptgetRunningScriptByPid";
}
for (const name of Object.keys(AllServers)) {
const server = AllServers[name];
for (const server of GetAllServers()) {
const runningScript = findRunningScriptByPid(pid, server);
if (runningScript) return runningScript;
}
@@ -611,7 +594,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
throw makeRuntimeErrorMsg("hack", "Takes 1 argument.");
}
const threads = resolveNetscriptRequestedThreads(workerScript, "hack", requestedThreads);
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
throw makeRuntimeErrorMsg("hack", `Invalid IP/hostname: ${ip}.`);
}
@@ -675,7 +658,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
workerScript.scriptRef.onlineMoneyMade += moneyGained;
Player.scriptProdSinceLastAug += moneyGained;
Player.recordMoneySource(moneyGained, "hacking");
workerScript.scriptRef.recordHack(server.ip, moneyGained, threads);
workerScript.scriptRef.recordHack(server.hostname, moneyGained, threads);
Player.gainHackingExp(expGainedOnSuccess);
workerScript.scriptRef.onlineExpGained += expGainedOnSuccess;
workerScript.log(
@@ -749,9 +732,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
hacknet: hacknet,
sprintf: sprintf,
vsprintf: vsprintf,
scan: function (ip: any = workerScript.serverIp, hostnames: any = true): any {
scan: function (ip: any = workerScript.hostname, hostnames: any = true): any {
updateDynamicRam("scan", getRamCost("scan"));
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("scan", `Invalid IP/hostname: ${ip}.`);
}
@@ -763,7 +746,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (hostnames) {
entry = s.hostname;
} else {
entry = s.ip;
entry = s.hostname;
}
if (entry == null) {
continue;
@@ -838,7 +821,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("grow", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("grow", "Cannot be executed on this server.");
return false;
@@ -847,10 +830,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
throw makeRuntimeErrorMsg("grow", `Invalid IP/hostname: ${ip}.`);
}
const host = getServer(workerScript.serverIp);
if (!(host instanceof Server)) {
workerScript.log("grow", "Cannot be executed on this server.");
return false;
const host = GetServer(workerScript.hostname);
if (host === null) {
throw new Error("Workerscript host is null");
}
// No root access or skill level too low
@@ -874,7 +856,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
const moneyBefore = server.moneyAvailable <= 0 ? 1 : server.moneyAvailable;
processSingleServerGrowth(server, threads, Player, host.cpuCores);
const moneyAfter = server.moneyAvailable;
workerScript.scriptRef.recordGrow(server.ip, threads);
workerScript.scriptRef.recordGrow(server.hostname, threads);
const expGain = calculateHackingExpGain(server, Player) * threads;
const logGrowPercent = moneyAfter / moneyBefore - 1;
workerScript.log(
@@ -905,7 +887,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
throw makeRuntimeErrorMsg("growthAnalyze", `Invalid argument: growth must be numeric and >= 1, is ${growth}.`);
}
return numCycleForGrowth(server, Number(growth), Player, server.cpuCores);
return numCycleForGrowth(server, Number(growth), Player, 1);
},
weaken: function (ip: any, { threads: requestedThreads }: any = {}): any {
updateDynamicRam("weaken", getRamCost("weaken"));
@@ -913,7 +895,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("weaken", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("weaken", "Cannot be executed on this server.");
return false;
@@ -938,14 +920,14 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
);
return netscriptDelay(weakenTime * 1000, workerScript).then(function () {
if (workerScript.env.stopFlag) return Promise.reject(workerScript);
const host = getServer(workerScript.serverIp);
const host = GetServer(workerScript.hostname);
if (host === null) {
workerScript.log("weaken", "Server is null, did it die?");
return Promise.resolve(0);
}
const coreBonus = 1 + (host.cpuCores - 1) / 16;
server.weaken(CONSTANTS.ServerWeakenAmount * threads * coreBonus);
workerScript.scriptRef.recordWeaken(server.ip, threads);
workerScript.scriptRef.recordWeaken(server.hostname, threads);
const expGain = calculateHackingExpGain(server, Player) * threads;
workerScript.log(
"weaken",
@@ -1011,7 +993,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
return runningScriptObj.logs.slice();
},
tail: function (fn: any, ip: any = workerScript.serverIp, ...scriptArgs: any): any {
tail: function (fn: any, ip: any = workerScript.hostname, ...scriptArgs: any): any {
let runningScriptObj;
if (arguments.length === 0) {
runningScriptObj = workerScript.scriptRef;
@@ -1032,7 +1014,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("nuke", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("nuke", "Cannot be executed on this server.");
return false;
@@ -1059,7 +1041,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("brutessh", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("brutessh", "Cannot be executed on this server.");
return false;
@@ -1084,7 +1066,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("ftpcrack", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("ftpcrack", "Cannot be executed on this server.");
return false;
@@ -1109,7 +1091,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("relaysmtp", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("relaysmtp", "Cannot be executed on this server.");
return false;
@@ -1134,7 +1116,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("httpworm", "Takes 1 argument");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("httpworm", "Cannot be executed on this server.");
return false;
@@ -1159,7 +1141,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("sqlinject", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("sqlinject", "Cannot be executed on this server.");
return false;
@@ -1187,7 +1169,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (isNaN(threads) || threads <= 0) {
throw makeRuntimeErrorMsg("run", `Invalid thread count. Must be numeric and > 0, is ${threads}`);
}
const scriptServer = getServer(workerScript.serverIp);
const scriptServer = GetServer(workerScript.hostname);
if (scriptServer == null) {
throw makeRuntimeErrorMsg("run", "Could not find server. This is a bug. Report to dev.");
}
@@ -1202,7 +1184,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (isNaN(threads) || threads <= 0) {
throw makeRuntimeErrorMsg("exec", `Invalid thread count. Must be numeric and > 0, is ${threads}`);
}
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("exec", `Invalid IP/hostname: ${ip}`);
}
@@ -1219,7 +1201,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (isNaN(threads) || threads <= 0) {
throw makeRuntimeErrorMsg("spawn", `Invalid thread count. Must be numeric and > 0, is ${threads}`);
}
const scriptServer = getServer(workerScript.serverIp);
const scriptServer = GetServer(workerScript.hostname);
if (scriptServer == null) {
throw makeRuntimeErrorMsg("spawn", "Could not find server. This is a bug. Report to dev");
}
@@ -1255,7 +1237,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
return false;
}
res = killWorkerScript(runningScriptObj, server.ip);
res = killWorkerScript(runningScriptObj, server.hostname);
}
if (res) {
@@ -1274,18 +1256,18 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
return false;
}
},
killall: function (ip: any = workerScript.serverIp): any {
killall: function (ip: any = workerScript.hostname): any {
updateDynamicRam("killall", getRamCost("killall"));
if (ip === undefined) {
throw makeRuntimeErrorMsg("killall", "Takes 1 argument");
}
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("killall", `Invalid IP/hostname: ${ip}`);
}
const scriptsRunning = server.runningScripts.length > 0;
for (let i = server.runningScripts.length - 1; i >= 0; --i) {
killWorkerScript(server.runningScripts[i], server.ip, false);
killWorkerScript(server.runningScripts[i], server.hostname, false);
}
WorkerScriptStartStopEventEmitter.emit();
workerScript.log(
@@ -1336,12 +1318,12 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (scriptname === undefined || ip1 === undefined || ip2 === undefined) {
throw makeRuntimeErrorMsg("scp", "Takes 2 or 3 arguments");
}
destServer = getServer(ip2);
destServer = GetServer(ip2);
if (destServer == null) {
throw makeRuntimeErrorMsg("scp", `Invalid IP/hostname: ${ip2}`);
}
currServ = getServer(ip1);
currServ = GetServer(ip1);
if (currServ == null) {
throw makeRuntimeErrorMsg("scp", `Invalid IP/hostname: ${ip1}`);
}
@@ -1350,12 +1332,12 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (scriptname === undefined || ip1 === undefined) {
throw makeRuntimeErrorMsg("scp", "Takes 2 or 3 arguments");
}
destServer = getServer(ip1);
destServer = GetServer(ip1);
if (destServer == null) {
throw makeRuntimeErrorMsg("scp", `Invalid IP/hostname: ${ip1}`);
}
currServ = getServer(workerScript.serverIp);
currServ = GetServer(workerScript.hostname);
if (currServ == null) {
throw makeRuntimeErrorMsg("scp", "Could not find server ip for this script. This is a bug. Report to dev.");
}
@@ -1450,7 +1432,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
const newScript = new Script(scriptname);
newScript.code = sourceScript.code;
newScript.ramUsage = sourceScript.ramUsage;
newScript.server = destServer.ip;
newScript.server = destServer.hostname;
destServer.scripts.push(newScript);
workerScript.log("scp", `File '${scriptname}' copied over to '${destServer.hostname}'.`);
return true;
@@ -1460,7 +1442,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("ls", "Usage: ls(ip/hostname, [grep filter])");
}
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("ls", `Invalid IP/hostname: ${ip}`);
}
@@ -1534,9 +1516,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
allFiles.sort();
return allFiles;
},
ps: function (ip: any = workerScript.serverIp): any {
ps: function (ip: any = workerScript.hostname): any {
updateDynamicRam("ps", getRamCost("ps"));
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("ps", `Invalid IP/hostname: ${ip}`);
}
@@ -1557,7 +1539,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("hasRootAccess", "Takes 1 argument");
}
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("hasRootAccess", `Invalid IP/hostname: ${ip}`);
}
@@ -1565,15 +1547,15 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
},
getIp: function (): any {
updateDynamicRam("getIp", getRamCost("getIp"));
const scriptServer = getServer(workerScript.serverIp);
const scriptServer = GetServer(workerScript.hostname);
if (scriptServer == null) {
throw makeRuntimeErrorMsg("getIp", "Could not find server. This is a bug. Report to dev.");
}
return scriptServer.ip;
return scriptServer.hostname;
},
getHostname: function (): any {
updateDynamicRam("getHostname", getRamCost("getHostname"));
const scriptServer = getServer(workerScript.serverIp);
const scriptServer = GetServer(workerScript.hostname);
if (scriptServer == null) {
throw makeRuntimeErrorMsg("getHostname", "Could not find server. This is a bug. Report to dev.");
}
@@ -1782,14 +1764,14 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
},
serverExists: function (ip: any): any {
updateDynamicRam("serverExists", getRamCost("serverExists"));
return getServer(ip) !== null;
return GetServer(ip) !== null;
},
fileExists: function (filename: any, ip: any = workerScript.serverIp): any {
fileExists: function (filename: any, ip: any = workerScript.hostname): any {
updateDynamicRam("fileExists", getRamCost("fileExists"));
if (filename === undefined) {
throw makeRuntimeErrorMsg("fileExists", "Usage: fileExists(scriptname, [server])");
}
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("fileExists", `Invalid IP/hostname: ${ip}`);
}
@@ -1814,7 +1796,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
}
return false;
},
isRunning: function (fn: any, ip: any = workerScript.serverIp, ...scriptArgs: any): any {
isRunning: function (fn: any, ip: any = workerScript.hostname, ...scriptArgs: any): any {
updateDynamicRam("isRunning", getRamCost("isRunning"));
if (fn === undefined || ip === undefined) {
throw makeRuntimeErrorMsg("isRunning", "Usage: isRunning(scriptname, server, [arg1], [arg2]...)");
@@ -2198,10 +2180,10 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
});
AddToAllServers(newServ);
Player.purchasedServers.push(newServ.ip);
Player.purchasedServers.push(newServ.hostname);
const homeComputer = Player.getHomeComputer();
homeComputer.serversOnNetwork.push(newServ.ip);
newServ.serversOnNetwork.push(homeComputer.ip);
homeComputer.serversOnNetwork.push(newServ.hostname);
newServ.serversOnNetwork.push(homeComputer.hostname);
Player.loseMoney(cost);
workerScript.log(
"purchaseServer",
@@ -2213,7 +2195,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
updateDynamicRam("deleteServer", getRamCost("deleteServer"));
let hostnameStr = String(hostname);
hostnameStr = hostnameStr.replace(/\s\s+/g, "");
const server = GetServerByHostname(hostnameStr);
const server = GetServer(hostnameStr);
if (!(server instanceof Server)) {
workerScript.log("deleteServer", `Invalid argument: hostname='${hostnameStr}'`);
return false;
@@ -2228,7 +2210,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
return false;
}
const ip = server.ip;
const ip = server.hostname;
// Can't delete server you're currently connected to
if (server.isConnectedTo) {
@@ -2237,7 +2219,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
}
// A server cannot delete itself
if (ip === workerScript.serverIp) {
if (ip === workerScript.hostname) {
workerScript.log("deleteServer", "Cannot delete the server this script is running on.");
return false;
}
@@ -2270,7 +2252,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
}
// Delete from all servers
delete AllServers[ip];
DeleteServer(ip);
// Delete from home computer
found = false;
@@ -2294,7 +2276,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
const res: string[] = [];
Player.purchasedServers.forEach(function (ip) {
if (hostname) {
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("getPurchasedServers", "Could not find server. This is a bug. Report to dev.");
}
@@ -2349,7 +2331,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
let script = workerScript.getScriptOnServer(fn, server);
if (script == null) {
// Create a new script
script = new Script(fn, data, server.ip, server.scripts);
script = new Script(fn, data, server.hostname, server.scripts);
server.scripts.push(script);
return true;
}
@@ -2409,11 +2391,13 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (iport == null || !(iport instanceof Object)) {
throw makeRuntimeErrorMsg("read", `Could not find port: ${port}. This is a bug. Report to dev.`);
}
return iport.read();
const x = iport.read();
console.log(x);
return x;
} else if (isString(port)) {
// Read from script or text file
const fn = port;
const server = getServer(workerScript.serverIp);
const server = GetServer(workerScript.hostname);
if (server == null) {
throw makeRuntimeErrorMsg("read", "Error getting Server. This is a bug. Report to dev.");
}
@@ -2456,7 +2440,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (iport == null || !(iport instanceof Object)) {
throw makeRuntimeErrorMsg("peek", `Could not find port: ${port}. This is a bug. Report to dev.`);
}
return iport.peek();
const x = iport.peek();
console.log(x);
return x;
},
clear: function (port: any): any {
updateDynamicRam("clear", getRamCost("clear"));
@@ -2477,7 +2463,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
} else if (isString(port)) {
// Clear text file
const fn = port;
const server = getServer(workerScript.serverIp);
const server = GetServer(workerScript.hostname);
if (server == null) {
throw makeRuntimeErrorMsg("clear", "Error getting Server. This is a bug. Report to dev.");
}
@@ -2515,7 +2501,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
updateDynamicRam("rm", getRamCost("rm"));
if (ip == null || ip === "") {
ip = workerScript.serverIp;
ip = workerScript.hostname;
}
const s = safeGetServer(ip, "rm");
@@ -2528,7 +2514,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
},
scriptRunning: function (scriptname: any, ip: any): any {
updateDynamicRam("scriptRunning", getRamCost("scriptRunning"));
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("scriptRunning", `Invalid IP/hostname: ${ip}`);
}
@@ -2541,14 +2527,14 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
},
scriptKill: function (scriptname: any, ip: any): any {
updateDynamicRam("scriptKill", getRamCost("scriptKill"));
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("scriptKill", `Invalid IP/hostname: ${ip}`);
}
let suc = false;
for (let i = 0; i < server.runningScripts.length; ++i) {
if (server.runningScripts[i].filename == scriptname) {
killWorkerScript(server.runningScripts[i], server.ip);
killWorkerScript(server.runningScripts[i], server.hostname);
suc = true;
}
}
@@ -2557,9 +2543,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
getScriptName: function (): any {
return workerScript.name;
},
getScriptRam: function (scriptname: any, ip: any = workerScript.serverIp): any {
getScriptRam: function (scriptname: any, ip: any = workerScript.hostname): any {
updateDynamicRam("getScriptRam", getRamCost("getScriptRam"));
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("getScriptRam", `Invalid IP/hostname: ${ip}`);
}
@@ -2658,7 +2644,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
return res;
} else {
// Get income for a particular script
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("getScriptIncome", `Invalid IP/hostnamed: ${ip}`);
}
@@ -2683,7 +2669,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
return total;
} else {
// Get income for a particular script
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("getScriptExpGain", `Invalid IP/hostnamed: ${ip}`);
}
@@ -2724,7 +2710,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
});
});
},
wget: async function (url: any, target: any, ip: any = workerScript.serverIp): Promise<boolean> {
wget: async function (url: any, target: any, ip: any = workerScript.hostname): Promise<boolean> {
if (!isScriptFilename(target) && !target.endsWith(".txt")) {
workerScript.log("wget", `Invalid target file: '${target}'. Must be a script or text file.`);
return Promise.resolve(false);
@@ -2962,7 +2948,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
updateDynamicRam("purchaseTor", getRamCost("purchaseTor"));
checkSingularityAccess("purchaseTor", 1);
if (SpecialServerIps["Darkweb Server"] != null) {
if (Player.hasTorRouter()) {
workerScript.log("purchaseTor", "You already have a TOR router!");
return false;
}
@@ -2983,10 +2969,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
maxRam: 1,
});
AddToAllServers(darkweb);
SpecialServerIps.addIp("Darkweb Server", darkweb.ip);
Player.getHomeComputer().serversOnNetwork.push(darkweb.ip);
darkweb.serversOnNetwork.push(Player.getHomeComputer().ip);
Player.getHomeComputer().serversOnNetwork.push(darkweb.hostname);
darkweb.serversOnNetwork.push(Player.getHomeComputer().hostname);
Player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain);
workerScript.log("purchaseTor", "You have purchased a Tor router!");
return true;
@@ -2995,7 +2980,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
updateDynamicRam("purchaseProgram", getRamCost("purchaseProgram"));
checkSingularityAccess("purchaseProgram", 1);
if (SpecialServerIps["Darkweb Server"] == null) {
if (!Player.hasTorRouter()) {
workerScript.log("purchaseProgram", "You do not have the TOR router.");
return false;
}
@@ -3048,7 +3033,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
throw makeRuntimeErrorMsg("connect", `Invalid hostname: '${hostname}'`);
}
const target = getServer(hostname);
const target = GetServer(hostname);
if (target == null) {
throw makeRuntimeErrorMsg("connect", `Invalid hostname: '${hostname}'`);
return;
@@ -3056,7 +3041,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (hostname === "home") {
Player.getCurrentServer().isConnectedTo = false;
Player.currentServer = Player.getHomeComputer().ip;
Player.currentServer = Player.getHomeComputer().hostname;
Player.getCurrentServer().isConnectedTo = true;
Terminal.setcwd("/");
return true;
@@ -3066,9 +3051,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
for (let i = 0; i < server.serversOnNetwork.length; i++) {
const other = getServerOnNetwork(server, i);
if (other === null) continue;
if (other.ip == hostname || other.hostname == hostname) {
if (other.hostname == hostname) {
Player.getCurrentServer().isConnectedTo = false;
Player.currentServer = target.ip;
Player.currentServer = target.hostname;
Player.getCurrentServer().isConnectedTo = true;
Terminal.setcwd("/");
return true;
@@ -3161,7 +3146,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
workMoney: Player.work_money_mult,
},
timeWorked: Player.timeWorked,
tor: SpecialServerIps.hasOwnProperty("Darkweb Server"),
tor: Player.hasTorRouter(),
workHackExpGain: Player.workHackExpGained,
workStrExpGain: Player.workStrExpGained,
workDefExpGain: Player.workDefExpGained,
@@ -3267,7 +3252,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
playtimeSinceLastBitnode: Player.playtimeSinceLastBitnode,
jobs: {},
factions: Player.factions.slice(),
tor: SpecialServerIps.hasOwnProperty("Darkweb Server"),
tor: Player.hasTorRouter(),
};
Object.assign(data.jobs, Player.jobs);
return data;
@@ -4422,7 +4407,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
// Coding Contract API
codingcontract: {
attempt: function (answer: any, fn: any, ip: any = workerScript.serverIp, { returnReward }: any = {}): any {
attempt: function (answer: any, fn: any, ip: any = workerScript.hostname, { returnReward }: any = {}): any {
updateDynamicRam("attempt", getRamCost("codingcontract", "attempt"));
const contract = getCodingContract("attempt", ip, fn);
@@ -4465,12 +4450,12 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
return returnReward ? "" : false;
}
},
getContractType: function (fn: any, ip: any = workerScript.serverIp): any {
getContractType: function (fn: any, ip: any = workerScript.hostname): any {
updateDynamicRam("getContractType", getRamCost("codingcontract", "getContractType"));
const contract = getCodingContract("getContractType", ip, fn);
return contract.getType();
},
getData: function (fn: any, ip: any = workerScript.serverIp): any {
getData: function (fn: any, ip: any = workerScript.hostname): any {
updateDynamicRam("getData", getRamCost("codingcontract", "getData"));
const contract = getCodingContract("getData", ip, fn);
const data = contract.getData();
@@ -4490,12 +4475,12 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
return data;
}
},
getDescription: function (fn: any, ip: any = workerScript.serverIp): any {
getDescription: function (fn: any, ip: any = workerScript.hostname): any {
updateDynamicRam("getDescription", getRamCost("codingcontract", "getDescription"));
const contract = getCodingContract("getDescription", ip, fn);
return contract.getDescription();
},
getNumTriesRemaining: function (fn: any, ip: any = workerScript.serverIp): any {
getNumTriesRemaining: function (fn: any, ip: any = workerScript.hostname): any {
updateDynamicRam("getNumTriesRemaining", getRamCost("codingcontract", "getNumTriesRemaining"));
const contract = getCodingContract("getNumTriesRemaining", ip, fn);
return contract.getMaxNumTries() - contract.tries;