mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 17:53:55 +01:00
fix a few test
This commit is contained in:
parent
8ae23937fb
commit
f05b533af5
@ -536,14 +536,14 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return out;
|
return out;
|
||||||
},
|
},
|
||||||
hack: function (_hostname: unknown, { threads: requestedThreads, stock }: BasicHGWOptions = {}): Promise<number> {
|
hack: function (_hostname: unknown, { threads: requestedThreads, stock }: BasicHGWOptions = {}): Promise<number> {
|
||||||
const hostname = helper.string("hack", "hostname", _hostname);
|
|
||||||
updateDynamicRam("hack", getRamCost(Player, "hack"));
|
updateDynamicRam("hack", getRamCost(Player, "hack"));
|
||||||
|
const hostname = helper.string("hack", "hostname", _hostname);
|
||||||
return hack(hostname, false, { threads: requestedThreads, stock: stock });
|
return hack(hostname, false, { threads: requestedThreads, stock: stock });
|
||||||
},
|
},
|
||||||
hackAnalyzeThreads: function (_hostname: unknown, _hackAmount: unknown): number {
|
hackAnalyzeThreads: function (_hostname: unknown, _hackAmount: unknown): number {
|
||||||
|
updateDynamicRam("hackAnalyzeThreads", getRamCost(Player, "hackAnalyzeThreads"));
|
||||||
const hostname = helper.string("hackAnalyzeThreads", "hostname", _hostname);
|
const hostname = helper.string("hackAnalyzeThreads", "hostname", _hostname);
|
||||||
const hackAmount = helper.number("hackAnalyzeThreads", "hackAmount", _hackAmount);
|
const hackAmount = helper.number("hackAnalyzeThreads", "hackAmount", _hackAmount);
|
||||||
updateDynamicRam("hackAnalyzeThreads", getRamCost(Player, "hackAnalyzeThreads"));
|
|
||||||
|
|
||||||
// Check argument validity
|
// Check argument validity
|
||||||
const server = safeGetServer(hostname, "hackAnalyzeThreads");
|
const server = safeGetServer(hostname, "hackAnalyzeThreads");
|
||||||
@ -573,8 +573,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return hackAmount / Math.floor(server.moneyAvailable * percentHacked);
|
return hackAmount / Math.floor(server.moneyAvailable * percentHacked);
|
||||||
},
|
},
|
||||||
hackAnalyze: function (_hostname: unknown): number {
|
hackAnalyze: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("hackAnalyze", "hostname", _hostname);
|
|
||||||
updateDynamicRam("hackAnalyze", getRamCost(Player, "hackAnalyze"));
|
updateDynamicRam("hackAnalyze", getRamCost(Player, "hackAnalyze"));
|
||||||
|
const hostname = helper.string("hackAnalyze", "hostname", _hostname);
|
||||||
|
|
||||||
const server = safeGetServer(hostname, "hackAnalyze");
|
const server = safeGetServer(hostname, "hackAnalyze");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
@ -585,13 +585,13 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return calculatePercentMoneyHacked(server, Player);
|
return calculatePercentMoneyHacked(server, Player);
|
||||||
},
|
},
|
||||||
hackAnalyzeSecurity: function (_threads: unknown): number {
|
hackAnalyzeSecurity: function (_threads: unknown): number {
|
||||||
const threads = helper.number("hackAnalyzeSecurity", "threads", _threads);
|
|
||||||
updateDynamicRam("hackAnalyzeSecurity", getRamCost(Player, "hackAnalyzeSecurity"));
|
updateDynamicRam("hackAnalyzeSecurity", getRamCost(Player, "hackAnalyzeSecurity"));
|
||||||
|
const threads = helper.number("hackAnalyzeSecurity", "threads", _threads);
|
||||||
return CONSTANTS.ServerFortifyAmount * threads;
|
return CONSTANTS.ServerFortifyAmount * threads;
|
||||||
},
|
},
|
||||||
hackAnalyzeChance: function (_hostname: unknown): number {
|
hackAnalyzeChance: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("hackAnalyzeChance", "hostname", _hostname);
|
|
||||||
updateDynamicRam("hackAnalyzeChance", getRamCost(Player, "hackAnalyzeChance"));
|
updateDynamicRam("hackAnalyzeChance", getRamCost(Player, "hackAnalyzeChance"));
|
||||||
|
const hostname = helper.string("hackAnalyzeChance", "hostname", _hostname);
|
||||||
|
|
||||||
const server = safeGetServer(hostname, "hackAnalyzeChance");
|
const server = safeGetServer(hostname, "hackAnalyzeChance");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
@ -602,8 +602,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return calculateHackingChance(server, Player);
|
return calculateHackingChance(server, Player);
|
||||||
},
|
},
|
||||||
sleep: async function (_time: unknown = 0): Promise<true> {
|
sleep: async function (_time: unknown = 0): Promise<true> {
|
||||||
const time = helper.number("sleep", "time", _time);
|
|
||||||
updateDynamicRam("sleep", getRamCost(Player, "sleep"));
|
updateDynamicRam("sleep", getRamCost(Player, "sleep"));
|
||||||
|
const time = helper.number("sleep", "time", _time);
|
||||||
if (time === undefined) {
|
if (time === undefined) {
|
||||||
throw makeRuntimeErrorMsg("sleep", "Takes 1 argument.");
|
throw makeRuntimeErrorMsg("sleep", "Takes 1 argument.");
|
||||||
}
|
}
|
||||||
@ -613,8 +613,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
asleep: function (_time: unknown = 0): Promise<true> {
|
asleep: function (_time: unknown = 0): Promise<true> {
|
||||||
const time = helper.number("asleep", "time", _time);
|
|
||||||
updateDynamicRam("asleep", getRamCost(Player, "asleep"));
|
updateDynamicRam("asleep", getRamCost(Player, "asleep"));
|
||||||
|
const time = helper.number("asleep", "time", _time);
|
||||||
if (time === undefined) {
|
if (time === undefined) {
|
||||||
throw makeRuntimeErrorMsg("asleep", "Takes 1 argument.");
|
throw makeRuntimeErrorMsg("asleep", "Takes 1 argument.");
|
||||||
}
|
}
|
||||||
@ -625,8 +625,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
_hostname: unknown,
|
_hostname: unknown,
|
||||||
{ threads: requestedThreads, stock }: BasicHGWOptions = {},
|
{ threads: requestedThreads, stock }: BasicHGWOptions = {},
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const hostname = helper.string("grow", "hostname", _hostname);
|
|
||||||
updateDynamicRam("grow", getRamCost(Player, "grow"));
|
updateDynamicRam("grow", getRamCost(Player, "grow"));
|
||||||
|
const hostname = helper.string("grow", "hostname", _hostname);
|
||||||
const threads = resolveNetscriptRequestedThreads(
|
const threads = resolveNetscriptRequestedThreads(
|
||||||
workerScript,
|
workerScript,
|
||||||
"grow",
|
"grow",
|
||||||
@ -685,10 +685,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
growthAnalyze: function (_hostname: unknown, _growth: unknown, _cores: unknown = 1): number {
|
growthAnalyze: function (_hostname: unknown, _growth: unknown, _cores: unknown = 1): number {
|
||||||
|
updateDynamicRam("growthAnalyze", getRamCost(Player, "growthAnalyze"));
|
||||||
const hostname = helper.string("growthAnalyze", "hostname", _hostname);
|
const hostname = helper.string("growthAnalyze", "hostname", _hostname);
|
||||||
const growth = helper.number("growthAnalyze", "growth", _growth);
|
const growth = helper.number("growthAnalyze", "growth", _growth);
|
||||||
const cores = helper.number("growthAnalyze", "cores", _cores);
|
const cores = helper.number("growthAnalyze", "cores", _cores);
|
||||||
updateDynamicRam("growthAnalyze", getRamCost(Player, "growthAnalyze"));
|
|
||||||
|
|
||||||
// Check argument validity
|
// Check argument validity
|
||||||
const server = safeGetServer(hostname, "growthAnalyze");
|
const server = safeGetServer(hostname, "growthAnalyze");
|
||||||
@ -703,13 +703,13 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return numCycleForGrowth(server, Number(growth), Player, cores);
|
return numCycleForGrowth(server, Number(growth), Player, cores);
|
||||||
},
|
},
|
||||||
growthAnalyzeSecurity: function (_threads: unknown): number {
|
growthAnalyzeSecurity: function (_threads: unknown): number {
|
||||||
const threads = helper.number("growthAnalyzeSecurity", "threads", _threads);
|
|
||||||
updateDynamicRam("growthAnalyzeSecurity", getRamCost(Player, "growthAnalyzeSecurity"));
|
updateDynamicRam("growthAnalyzeSecurity", getRamCost(Player, "growthAnalyzeSecurity"));
|
||||||
|
const threads = helper.number("growthAnalyzeSecurity", "threads", _threads);
|
||||||
return 2 * CONSTANTS.ServerFortifyAmount * threads;
|
return 2 * CONSTANTS.ServerFortifyAmount * threads;
|
||||||
},
|
},
|
||||||
weaken: async function (_hostname: unknown, { threads: requestedThreads }: BasicHGWOptions = {}): Promise<number> {
|
weaken: async function (_hostname: unknown, { threads: requestedThreads }: BasicHGWOptions = {}): Promise<number> {
|
||||||
const hostname = helper.string("weaken", "hostname", _hostname);
|
|
||||||
updateDynamicRam("weaken", getRamCost(Player, "weaken"));
|
updateDynamicRam("weaken", getRamCost(Player, "weaken"));
|
||||||
|
const hostname = helper.string("weaken", "hostname", _hostname);
|
||||||
const threads = resolveNetscriptRequestedThreads(
|
const threads = resolveNetscriptRequestedThreads(
|
||||||
workerScript,
|
workerScript,
|
||||||
"weaken",
|
"weaken",
|
||||||
@ -762,9 +762,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
weakenAnalyze: function (_threads: unknown, _cores: unknown = 1): number {
|
weakenAnalyze: function (_threads: unknown, _cores: unknown = 1): number {
|
||||||
|
updateDynamicRam("weakenAnalyze", getRamCost(Player, "weakenAnalyze"));
|
||||||
const threads = helper.number("weakenAnalyze", "threads", _threads);
|
const threads = helper.number("weakenAnalyze", "threads", _threads);
|
||||||
const cores = helper.number("weakenAnalyze", "cores", _cores);
|
const cores = helper.number("weakenAnalyze", "cores", _cores);
|
||||||
updateDynamicRam("weakenAnalyze", getRamCost(Player, "weakenAnalyze"));
|
|
||||||
const coreBonus = 1 + (cores - 1) / 16;
|
const coreBonus = 1 + (cores - 1) / 16;
|
||||||
return CONSTANTS.ServerWeakenAmount * threads * coreBonus * BitNodeMultipliers.ServerWeakenRate;
|
return CONSTANTS.ServerWeakenAmount * threads * coreBonus * BitNodeMultipliers.ServerWeakenRate;
|
||||||
},
|
},
|
||||||
@ -789,8 +789,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
workerScript.print(argsToString(args));
|
workerScript.print(argsToString(args));
|
||||||
},
|
},
|
||||||
printf: function (_format: unknown, ...args: any[]): void {
|
printf: function (_format: unknown, ...args: any[]): void {
|
||||||
const format = helper.string("printf", "format", _format);
|
|
||||||
updateDynamicRam("printf", getRamCost(Player, "printf"));
|
updateDynamicRam("printf", getRamCost(Player, "printf"));
|
||||||
|
const format = helper.string("printf", "format", _format);
|
||||||
if (typeof format !== "string") {
|
if (typeof format !== "string") {
|
||||||
throw makeRuntimeErrorMsg("printf", "First argument must be string for the format.");
|
throw makeRuntimeErrorMsg("printf", "First argument must be string for the format.");
|
||||||
}
|
}
|
||||||
@ -821,8 +821,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
Terminal.print(`${workerScript.scriptRef.filename}: ${str}`);
|
Terminal.print(`${workerScript.scriptRef.filename}: ${str}`);
|
||||||
},
|
},
|
||||||
tprintf: function (_format: unknown, ...args: any[]): void {
|
tprintf: function (_format: unknown, ...args: any[]): void {
|
||||||
const format = helper.string("printf", "format", _format);
|
|
||||||
updateDynamicRam("tprintf", getRamCost(Player, "tprintf"));
|
updateDynamicRam("tprintf", getRamCost(Player, "tprintf"));
|
||||||
|
const format = helper.string("printf", "format", _format);
|
||||||
if (typeof format !== "string") {
|
if (typeof format !== "string") {
|
||||||
throw makeRuntimeErrorMsg("tprintf", "First argument must be string for the format.");
|
throw makeRuntimeErrorMsg("tprintf", "First argument must be string for the format.");
|
||||||
}
|
}
|
||||||
@ -851,8 +851,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
workerScript.scriptRef.clearLog();
|
workerScript.scriptRef.clearLog();
|
||||||
},
|
},
|
||||||
disableLog: function (_fn: unknown): void {
|
disableLog: function (_fn: unknown): void {
|
||||||
const fn = helper.string("disableLog", "fn", _fn);
|
|
||||||
updateDynamicRam("disableLog", getRamCost(Player, "disableLog"));
|
updateDynamicRam("disableLog", getRamCost(Player, "disableLog"));
|
||||||
|
const fn = helper.string("disableLog", "fn", _fn);
|
||||||
if (fn === "ALL") {
|
if (fn === "ALL") {
|
||||||
for (const fn of Object.keys(possibleLogs)) {
|
for (const fn of Object.keys(possibleLogs)) {
|
||||||
workerScript.disableLogs[fn] = true;
|
workerScript.disableLogs[fn] = true;
|
||||||
@ -866,8 +866,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
enableLog: function (_fn: unknown): void {
|
enableLog: function (_fn: unknown): void {
|
||||||
const fn = helper.string("enableLog", "fn", _fn);
|
|
||||||
updateDynamicRam("enableLog", getRamCost(Player, "enableLog"));
|
updateDynamicRam("enableLog", getRamCost(Player, "enableLog"));
|
||||||
|
const fn = helper.string("enableLog", "fn", _fn);
|
||||||
if (fn === "ALL") {
|
if (fn === "ALL") {
|
||||||
for (const fn of Object.keys(possibleLogs)) {
|
for (const fn of Object.keys(possibleLogs)) {
|
||||||
delete workerScript.disableLogs[fn];
|
delete workerScript.disableLogs[fn];
|
||||||
@ -880,8 +880,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
workerScript.log("enableLog", () => `Enabled logging for ${fn}`);
|
workerScript.log("enableLog", () => `Enabled logging for ${fn}`);
|
||||||
},
|
},
|
||||||
isLogEnabled: function (_fn: unknown): boolean {
|
isLogEnabled: function (_fn: unknown): boolean {
|
||||||
const fn = helper.string("isLogEnabled", "fn", _fn);
|
|
||||||
updateDynamicRam("isLogEnabled", getRamCost(Player, "isLogEnabled"));
|
updateDynamicRam("isLogEnabled", getRamCost(Player, "isLogEnabled"));
|
||||||
|
const fn = helper.string("isLogEnabled", "fn", _fn);
|
||||||
if (possibleLogs[fn] === undefined) {
|
if (possibleLogs[fn] === undefined) {
|
||||||
throw makeRuntimeErrorMsg("isLogEnabled", `Invalid argument: ${fn}.`);
|
throw makeRuntimeErrorMsg("isLogEnabled", `Invalid argument: ${fn}.`);
|
||||||
}
|
}
|
||||||
@ -915,8 +915,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
LogBoxEvents.emit(runningScriptObj);
|
LogBoxEvents.emit(runningScriptObj);
|
||||||
},
|
},
|
||||||
nuke: function (_hostname: unknown): boolean {
|
nuke: function (_hostname: unknown): boolean {
|
||||||
const hostname = helper.string("tail", "hostname", _hostname);
|
|
||||||
updateDynamicRam("nuke", getRamCost(Player, "nuke"));
|
updateDynamicRam("nuke", getRamCost(Player, "nuke"));
|
||||||
|
const hostname = helper.string("tail", "hostname", _hostname);
|
||||||
if (hostname === undefined) {
|
if (hostname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("nuke", "Takes 1 argument.");
|
throw makeRuntimeErrorMsg("nuke", "Takes 1 argument.");
|
||||||
}
|
}
|
||||||
@ -940,8 +940,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
brutessh: function (_hostname: unknown): boolean {
|
brutessh: function (_hostname: unknown): boolean {
|
||||||
const hostname = helper.string("brutessh", "hostname", _hostname);
|
|
||||||
updateDynamicRam("brutessh", getRamCost(Player, "brutessh"));
|
updateDynamicRam("brutessh", getRamCost(Player, "brutessh"));
|
||||||
|
const hostname = helper.string("brutessh", "hostname", _hostname);
|
||||||
if (hostname === undefined) {
|
if (hostname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("brutessh", "Takes 1 argument.");
|
throw makeRuntimeErrorMsg("brutessh", "Takes 1 argument.");
|
||||||
}
|
}
|
||||||
@ -963,8 +963,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
ftpcrack: function (_hostname: unknown): boolean {
|
ftpcrack: function (_hostname: unknown): boolean {
|
||||||
const hostname = helper.string("ftpcrack", "hostname", _hostname);
|
|
||||||
updateDynamicRam("ftpcrack", getRamCost(Player, "ftpcrack"));
|
updateDynamicRam("ftpcrack", getRamCost(Player, "ftpcrack"));
|
||||||
|
const hostname = helper.string("ftpcrack", "hostname", _hostname);
|
||||||
if (hostname === undefined) {
|
if (hostname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("ftpcrack", "Takes 1 argument.");
|
throw makeRuntimeErrorMsg("ftpcrack", "Takes 1 argument.");
|
||||||
}
|
}
|
||||||
@ -986,8 +986,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
relaysmtp: function (_hostname: unknown): boolean {
|
relaysmtp: function (_hostname: unknown): boolean {
|
||||||
const hostname = helper.string("relaysmtp", "hostname", _hostname);
|
|
||||||
updateDynamicRam("relaysmtp", getRamCost(Player, "relaysmtp"));
|
updateDynamicRam("relaysmtp", getRamCost(Player, "relaysmtp"));
|
||||||
|
const hostname = helper.string("relaysmtp", "hostname", _hostname);
|
||||||
if (hostname === undefined) {
|
if (hostname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("relaysmtp", "Takes 1 argument.");
|
throw makeRuntimeErrorMsg("relaysmtp", "Takes 1 argument.");
|
||||||
}
|
}
|
||||||
@ -1009,8 +1009,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
httpworm: function (_hostname: unknown): boolean {
|
httpworm: function (_hostname: unknown): boolean {
|
||||||
const hostname = helper.string("httpworm", "hostname", _hostname);
|
|
||||||
updateDynamicRam("httpworm", getRamCost(Player, "httpworm"));
|
updateDynamicRam("httpworm", getRamCost(Player, "httpworm"));
|
||||||
|
const hostname = helper.string("httpworm", "hostname", _hostname);
|
||||||
if (hostname === undefined) {
|
if (hostname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("httpworm", "Takes 1 argument");
|
throw makeRuntimeErrorMsg("httpworm", "Takes 1 argument");
|
||||||
}
|
}
|
||||||
@ -1032,8 +1032,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
sqlinject: function (_hostname: unknown): boolean {
|
sqlinject: function (_hostname: unknown): boolean {
|
||||||
const hostname = helper.string("sqlinject", "hostname", _hostname);
|
|
||||||
updateDynamicRam("sqlinject", getRamCost(Player, "sqlinject"));
|
updateDynamicRam("sqlinject", getRamCost(Player, "sqlinject"));
|
||||||
|
const hostname = helper.string("sqlinject", "hostname", _hostname);
|
||||||
if (hostname === undefined) {
|
if (hostname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("sqlinject", "Takes 1 argument.");
|
throw makeRuntimeErrorMsg("sqlinject", "Takes 1 argument.");
|
||||||
}
|
}
|
||||||
@ -1055,9 +1055,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
run: function (_scriptname: unknown, _threads: unknown = 1, ...args: any[]): number {
|
run: function (_scriptname: unknown, _threads: unknown = 1, ...args: any[]): number {
|
||||||
|
updateDynamicRam("run", getRamCost(Player, "run"));
|
||||||
const scriptname = helper.string("run", "scriptname", _scriptname);
|
const scriptname = helper.string("run", "scriptname", _scriptname);
|
||||||
const threads = helper.number("run", "threads", _threads);
|
const threads = helper.number("run", "threads", _threads);
|
||||||
updateDynamicRam("run", getRamCost(Player, "run"));
|
|
||||||
if (scriptname === undefined) {
|
if (scriptname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("run", "Usage: run(scriptname, [numThreads], [arg1], [arg2]...)");
|
throw makeRuntimeErrorMsg("run", "Usage: run(scriptname, [numThreads], [arg1], [arg2]...)");
|
||||||
}
|
}
|
||||||
@ -1072,10 +1072,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return runScriptFromScript(Player, "run", scriptServer, scriptname, args, workerScript, threads);
|
return runScriptFromScript(Player, "run", scriptServer, scriptname, args, workerScript, threads);
|
||||||
},
|
},
|
||||||
exec: function (_scriptname: unknown, _hostname: unknown, _threads: unknown = 1, ...args: any[]): number {
|
exec: function (_scriptname: unknown, _hostname: unknown, _threads: unknown = 1, ...args: any[]): number {
|
||||||
|
updateDynamicRam("exec", getRamCost(Player, "exec"));
|
||||||
const scriptname = helper.string("exec", "scriptname", _scriptname);
|
const scriptname = helper.string("exec", "scriptname", _scriptname);
|
||||||
const hostname = helper.string("exec", "hostname", _hostname);
|
const hostname = helper.string("exec", "hostname", _hostname);
|
||||||
const threads = helper.number("exec", "threads", _threads);
|
const threads = helper.number("exec", "threads", _threads);
|
||||||
updateDynamicRam("exec", getRamCost(Player, "exec"));
|
|
||||||
if (scriptname === undefined || hostname === undefined) {
|
if (scriptname === undefined || hostname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("exec", "Usage: exec(scriptname, server, [numThreads], [arg1], [arg2]...)");
|
throw makeRuntimeErrorMsg("exec", "Usage: exec(scriptname, server, [numThreads], [arg1], [arg2]...)");
|
||||||
}
|
}
|
||||||
@ -1086,9 +1086,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return runScriptFromScript(Player, "exec", server, scriptname, args, workerScript, threads);
|
return runScriptFromScript(Player, "exec", server, scriptname, args, workerScript, threads);
|
||||||
},
|
},
|
||||||
spawn: function (_scriptname: unknown, _threads: unknown = 1, ...args: any[]): void {
|
spawn: function (_scriptname: unknown, _threads: unknown = 1, ...args: any[]): void {
|
||||||
|
updateDynamicRam("spawn", getRamCost(Player, "spawn"));
|
||||||
const scriptname = helper.string("spawn", "scriptname", _scriptname);
|
const scriptname = helper.string("spawn", "scriptname", _scriptname);
|
||||||
const threads = helper.number("spawn", "threads", _threads);
|
const threads = helper.number("spawn", "threads", _threads);
|
||||||
updateDynamicRam("spawn", getRamCost(Player, "spawn"));
|
|
||||||
if (!scriptname || !threads) {
|
if (!scriptname || !threads) {
|
||||||
throw makeRuntimeErrorMsg("spawn", "Usage: spawn(scriptname, threads)");
|
throw makeRuntimeErrorMsg("spawn", "Usage: spawn(scriptname, threads)");
|
||||||
}
|
}
|
||||||
@ -1160,8 +1160,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
killall: function (_hostname: unknown = workerScript.hostname): boolean {
|
killall: function (_hostname: unknown = workerScript.hostname): boolean {
|
||||||
const hostname = helper.string("killall", "hostname", _hostname);
|
|
||||||
updateDynamicRam("killall", getRamCost(Player, "killall"));
|
updateDynamicRam("killall", getRamCost(Player, "killall"));
|
||||||
|
const hostname = helper.string("killall", "hostname", _hostname);
|
||||||
if (hostname === undefined) {
|
if (hostname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("killall", "Takes 1 argument");
|
throw makeRuntimeErrorMsg("killall", "Takes 1 argument");
|
||||||
}
|
}
|
||||||
@ -1188,8 +1188,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
scp: async function (scriptname: any, _hostname1: unknown, hostname2?: any): Promise<boolean> {
|
scp: async function (scriptname: any, _hostname1: unknown, hostname2?: any): Promise<boolean> {
|
||||||
const hostname1 = helper.string("scp", "hostname1", _hostname1);
|
|
||||||
updateDynamicRam("scp", getRamCost(Player, "scp"));
|
updateDynamicRam("scp", getRamCost(Player, "scp"));
|
||||||
|
const hostname1 = helper.string("scp", "hostname1", _hostname1);
|
||||||
if (arguments.length !== 2 && arguments.length !== 3) {
|
if (arguments.length !== 2 && arguments.length !== 3) {
|
||||||
throw makeRuntimeErrorMsg("scp", "Takes 2 or 3 arguments");
|
throw makeRuntimeErrorMsg("scp", "Takes 2 or 3 arguments");
|
||||||
}
|
}
|
||||||
@ -1346,9 +1346,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
ls: function (_hostname: unknown, _grep: unknown = ""): string[] {
|
ls: function (_hostname: unknown, _grep: unknown = ""): string[] {
|
||||||
|
updateDynamicRam("ls", getRamCost(Player, "ls"));
|
||||||
const hostname = helper.string("ls", "hostname", _hostname);
|
const hostname = helper.string("ls", "hostname", _hostname);
|
||||||
const grep = helper.string("ls", "grep", _grep);
|
const grep = helper.string("ls", "grep", _grep);
|
||||||
updateDynamicRam("ls", getRamCost(Player, "ls"));
|
|
||||||
if (hostname === undefined) {
|
if (hostname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("ls", "Usage: ls(hostname/ip, [grep filter])");
|
throw makeRuntimeErrorMsg("ls", "Usage: ls(hostname/ip, [grep filter])");
|
||||||
}
|
}
|
||||||
@ -1415,8 +1415,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return allFiles;
|
return allFiles;
|
||||||
},
|
},
|
||||||
ps: function (_hostname: unknown = workerScript.hostname): ProcessInfo[] {
|
ps: function (_hostname: unknown = workerScript.hostname): ProcessInfo[] {
|
||||||
const hostname = helper.string("ps", "hostname", _hostname);
|
|
||||||
updateDynamicRam("ps", getRamCost(Player, "ps"));
|
updateDynamicRam("ps", getRamCost(Player, "ps"));
|
||||||
|
const hostname = helper.string("ps", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "ps");
|
const server = safeGetServer(hostname, "ps");
|
||||||
const processes = [];
|
const processes = [];
|
||||||
for (const script of server.runningScripts) {
|
for (const script of server.runningScripts) {
|
||||||
@ -1430,8 +1430,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return processes;
|
return processes;
|
||||||
},
|
},
|
||||||
hasRootAccess: function (_hostname: unknown): boolean {
|
hasRootAccess: function (_hostname: unknown): boolean {
|
||||||
const hostname = helper.string("hasRootAccess", "hostname", _hostname);
|
|
||||||
updateDynamicRam("hasRootAccess", getRamCost(Player, "hasRootAccess"));
|
updateDynamicRam("hasRootAccess", getRamCost(Player, "hasRootAccess"));
|
||||||
|
const hostname = helper.string("hasRootAccess", "hostname", _hostname);
|
||||||
if (hostname === undefined) {
|
if (hostname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("hasRootAccess", "Takes 1 argument");
|
throw makeRuntimeErrorMsg("hasRootAccess", "Takes 1 argument");
|
||||||
}
|
}
|
||||||
@ -1480,8 +1480,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return copy;
|
return copy;
|
||||||
},
|
},
|
||||||
getServer: function (_hostname: unknown = workerScript.hostname): IServerDef {
|
getServer: function (_hostname: unknown = workerScript.hostname): IServerDef {
|
||||||
const hostname = helper.string("getServer", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServer", getRamCost(Player, "getServer"));
|
updateDynamicRam("getServer", getRamCost(Player, "getServer"));
|
||||||
|
const hostname = helper.string("getServer", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getServer");
|
const server = safeGetServer(hostname, "getServer");
|
||||||
const copy = Object.assign({}, server) as any;
|
const copy = Object.assign({}, server) as any;
|
||||||
// These fields should be hidden.
|
// These fields should be hidden.
|
||||||
@ -1504,8 +1504,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return copy;
|
return copy;
|
||||||
},
|
},
|
||||||
getServerMoneyAvailable: function (_hostname: unknown): number {
|
getServerMoneyAvailable: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("getServerMoneyAvailable", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServerMoneyAvailable", getRamCost(Player, "getServerMoneyAvailable"));
|
updateDynamicRam("getServerMoneyAvailable", getRamCost(Player, "getServerMoneyAvailable"));
|
||||||
|
const hostname = helper.string("getServerMoneyAvailable", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getServerMoneyAvailable");
|
const server = safeGetServer(hostname, "getServerMoneyAvailable");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
workerScript.log("getServerMoneyAvailable", () => "Cannot be executed on this server.");
|
workerScript.log("getServerMoneyAvailable", () => "Cannot be executed on this server.");
|
||||||
@ -1529,8 +1529,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return server.moneyAvailable;
|
return server.moneyAvailable;
|
||||||
},
|
},
|
||||||
getServerSecurityLevel: function (_hostname: unknown): number {
|
getServerSecurityLevel: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("getServerSecurityLevel", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServerSecurityLevel", getRamCost(Player, "getServerSecurityLevel"));
|
updateDynamicRam("getServerSecurityLevel", getRamCost(Player, "getServerSecurityLevel"));
|
||||||
|
const hostname = helper.string("getServerSecurityLevel", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getServerSecurityLevel");
|
const server = safeGetServer(hostname, "getServerSecurityLevel");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
workerScript.log("getServerSecurityLevel", () => "Cannot be executed on this server.");
|
workerScript.log("getServerSecurityLevel", () => "Cannot be executed on this server.");
|
||||||
@ -1546,8 +1546,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return server.hackDifficulty;
|
return server.hackDifficulty;
|
||||||
},
|
},
|
||||||
getServerBaseSecurityLevel: function (_hostname: unknown): number {
|
getServerBaseSecurityLevel: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("getServerBaseSecurityLevel", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServerBaseSecurityLevel", getRamCost(Player, "getServerBaseSecurityLevel"));
|
updateDynamicRam("getServerBaseSecurityLevel", getRamCost(Player, "getServerBaseSecurityLevel"));
|
||||||
|
const hostname = helper.string("getServerBaseSecurityLevel", "hostname", _hostname);
|
||||||
workerScript.log(
|
workerScript.log(
|
||||||
"getServerBaseSecurityLevel",
|
"getServerBaseSecurityLevel",
|
||||||
() => `getServerBaseSecurityLevel is deprecated because it's not useful.`,
|
() => `getServerBaseSecurityLevel is deprecated because it's not useful.`,
|
||||||
@ -1567,8 +1567,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return server.baseDifficulty;
|
return server.baseDifficulty;
|
||||||
},
|
},
|
||||||
getServerMinSecurityLevel: function (_hostname: unknown): number {
|
getServerMinSecurityLevel: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("getServerMinSecurityLevel", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServerMinSecurityLevel", getRamCost(Player, "getServerMinSecurityLevel"));
|
updateDynamicRam("getServerMinSecurityLevel", getRamCost(Player, "getServerMinSecurityLevel"));
|
||||||
|
const hostname = helper.string("getServerMinSecurityLevel", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getServerMinSecurityLevel");
|
const server = safeGetServer(hostname, "getServerMinSecurityLevel");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
workerScript.log("getServerMinSecurityLevel", () => "Cannot be executed on this server.");
|
workerScript.log("getServerMinSecurityLevel", () => "Cannot be executed on this server.");
|
||||||
@ -1584,8 +1584,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return server.minDifficulty;
|
return server.minDifficulty;
|
||||||
},
|
},
|
||||||
getServerRequiredHackingLevel: function (_hostname: unknown): number {
|
getServerRequiredHackingLevel: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("getServerRequiredHackingLevel", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServerRequiredHackingLevel", getRamCost(Player, "getServerRequiredHackingLevel"));
|
updateDynamicRam("getServerRequiredHackingLevel", getRamCost(Player, "getServerRequiredHackingLevel"));
|
||||||
|
const hostname = helper.string("getServerRequiredHackingLevel", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getServerRequiredHackingLevel");
|
const server = safeGetServer(hostname, "getServerRequiredHackingLevel");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
workerScript.log("getServerRequiredHackingLevel", () => "Cannot be executed on this server.");
|
workerScript.log("getServerRequiredHackingLevel", () => "Cannot be executed on this server.");
|
||||||
@ -1601,8 +1601,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return server.requiredHackingSkill;
|
return server.requiredHackingSkill;
|
||||||
},
|
},
|
||||||
getServerMaxMoney: function (_hostname: unknown): number {
|
getServerMaxMoney: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("getServerMaxMoney", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServerMaxMoney", getRamCost(Player, "getServerMaxMoney"));
|
updateDynamicRam("getServerMaxMoney", getRamCost(Player, "getServerMaxMoney"));
|
||||||
|
const hostname = helper.string("getServerMaxMoney", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getServerMaxMoney");
|
const server = safeGetServer(hostname, "getServerMaxMoney");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
workerScript.log("getServerMaxMoney", () => "Cannot be executed on this server.");
|
workerScript.log("getServerMaxMoney", () => "Cannot be executed on this server.");
|
||||||
@ -1618,8 +1618,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return server.moneyMax;
|
return server.moneyMax;
|
||||||
},
|
},
|
||||||
getServerGrowth: function (_hostname: unknown): number {
|
getServerGrowth: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("getServerGrowth", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServerGrowth", getRamCost(Player, "getServerGrowth"));
|
updateDynamicRam("getServerGrowth", getRamCost(Player, "getServerGrowth"));
|
||||||
|
const hostname = helper.string("getServerGrowth", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getServerGrowth");
|
const server = safeGetServer(hostname, "getServerGrowth");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
workerScript.log("getServerGrowth", () => "Cannot be executed on this server.");
|
workerScript.log("getServerGrowth", () => "Cannot be executed on this server.");
|
||||||
@ -1632,8 +1632,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return server.serverGrowth;
|
return server.serverGrowth;
|
||||||
},
|
},
|
||||||
getServerNumPortsRequired: function (_hostname: unknown): number {
|
getServerNumPortsRequired: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("getServerNumPortsRequired", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServerNumPortsRequired", getRamCost(Player, "getServerNumPortsRequired"));
|
updateDynamicRam("getServerNumPortsRequired", getRamCost(Player, "getServerNumPortsRequired"));
|
||||||
|
const hostname = helper.string("getServerNumPortsRequired", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getServerNumPortsRequired");
|
const server = safeGetServer(hostname, "getServerNumPortsRequired");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
workerScript.log("getServerNumPortsRequired", () => "Cannot be executed on this server.");
|
workerScript.log("getServerNumPortsRequired", () => "Cannot be executed on this server.");
|
||||||
@ -1649,8 +1649,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return server.numOpenPortsRequired;
|
return server.numOpenPortsRequired;
|
||||||
},
|
},
|
||||||
getServerRam: function (_hostname: unknown): [number, number] {
|
getServerRam: function (_hostname: unknown): [number, number] {
|
||||||
const hostname = helper.string("getServerRam", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServerRam", getRamCost(Player, "getServerRam"));
|
updateDynamicRam("getServerRam", getRamCost(Player, "getServerRam"));
|
||||||
|
const hostname = helper.string("getServerRam", "hostname", _hostname);
|
||||||
workerScript.log(
|
workerScript.log(
|
||||||
"getServerRam",
|
"getServerRam",
|
||||||
() => `getServerRam is deprecated in favor of getServerMaxRam / getServerUsedRam`,
|
() => `getServerRam is deprecated in favor of getServerMaxRam / getServerUsedRam`,
|
||||||
@ -1663,28 +1663,28 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return [server.maxRam, server.ramUsed];
|
return [server.maxRam, server.ramUsed];
|
||||||
},
|
},
|
||||||
getServerMaxRam: function (_hostname: unknown): number {
|
getServerMaxRam: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("getServerMaxRam", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServerMaxRam", getRamCost(Player, "getServerMaxRam"));
|
updateDynamicRam("getServerMaxRam", getRamCost(Player, "getServerMaxRam"));
|
||||||
|
const hostname = helper.string("getServerMaxRam", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getServerMaxRam");
|
const server = safeGetServer(hostname, "getServerMaxRam");
|
||||||
workerScript.log("getServerMaxRam", () => `returned ${numeralWrapper.formatRAM(server.maxRam)}`);
|
workerScript.log("getServerMaxRam", () => `returned ${numeralWrapper.formatRAM(server.maxRam)}`);
|
||||||
return server.maxRam;
|
return server.maxRam;
|
||||||
},
|
},
|
||||||
getServerUsedRam: function (_hostname: unknown): number {
|
getServerUsedRam: function (_hostname: unknown): number {
|
||||||
const hostname = helper.string("getServerUsedRam", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getServerUsedRam", getRamCost(Player, "getServerUsedRam"));
|
updateDynamicRam("getServerUsedRam", getRamCost(Player, "getServerUsedRam"));
|
||||||
|
const hostname = helper.string("getServerUsedRam", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getServerUsedRam");
|
const server = safeGetServer(hostname, "getServerUsedRam");
|
||||||
workerScript.log("getServerUsedRam", () => `returned ${numeralWrapper.formatRAM(server.ramUsed)}`);
|
workerScript.log("getServerUsedRam", () => `returned ${numeralWrapper.formatRAM(server.ramUsed)}`);
|
||||||
return server.ramUsed;
|
return server.ramUsed;
|
||||||
},
|
},
|
||||||
serverExists: function (_hostname: unknown): boolean {
|
serverExists: function (_hostname: unknown): boolean {
|
||||||
const hostname = helper.string("serverExists", "hostname", _hostname);
|
|
||||||
updateDynamicRam("serverExists", getRamCost(Player, "serverExists"));
|
updateDynamicRam("serverExists", getRamCost(Player, "serverExists"));
|
||||||
|
const hostname = helper.string("serverExists", "hostname", _hostname);
|
||||||
return GetServer(hostname) !== null;
|
return GetServer(hostname) !== null;
|
||||||
},
|
},
|
||||||
fileExists: function (_filename: unknown, _hostname: unknown = workerScript.hostname): boolean {
|
fileExists: function (_filename: unknown, _hostname: unknown = workerScript.hostname): boolean {
|
||||||
|
updateDynamicRam("fileExists", getRamCost(Player, "fileExists"));
|
||||||
const filename = helper.string("fileExists", "filename", _filename);
|
const filename = helper.string("fileExists", "filename", _filename);
|
||||||
const hostname = helper.string("fileExists", "hostname", _hostname);
|
const hostname = helper.string("fileExists", "hostname", _hostname);
|
||||||
updateDynamicRam("fileExists", getRamCost(Player, "fileExists"));
|
|
||||||
if (filename === undefined) {
|
if (filename === undefined) {
|
||||||
throw makeRuntimeErrorMsg("fileExists", "Usage: fileExists(scriptname, [server])");
|
throw makeRuntimeErrorMsg("fileExists", "Usage: fileExists(scriptname, [server])");
|
||||||
}
|
}
|
||||||
@ -1729,8 +1729,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return getPurchaseServerMaxRam();
|
return getPurchaseServerMaxRam();
|
||||||
},
|
},
|
||||||
getPurchasedServerCost: function (_ram: unknown): number {
|
getPurchasedServerCost: function (_ram: unknown): number {
|
||||||
const ram = helper.number("getPurchasedServerCost", "ram", _ram);
|
|
||||||
updateDynamicRam("getPurchasedServerCost", getRamCost(Player, "getPurchasedServerCost"));
|
updateDynamicRam("getPurchasedServerCost", getRamCost(Player, "getPurchasedServerCost"));
|
||||||
|
const ram = helper.number("getPurchasedServerCost", "ram", _ram);
|
||||||
|
|
||||||
const cost = getPurchaseServerCost(ram);
|
const cost = getPurchaseServerCost(ram);
|
||||||
if (cost === Infinity) {
|
if (cost === Infinity) {
|
||||||
@ -1741,10 +1741,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return cost;
|
return cost;
|
||||||
},
|
},
|
||||||
purchaseServer: function (_name: unknown, _ram: unknown): string {
|
purchaseServer: function (_name: unknown, _ram: unknown): string {
|
||||||
|
updateDynamicRam("purchaseServer", getRamCost(Player, "purchaseServer"));
|
||||||
const name = helper.string("purchaseServer", "name", _name);
|
const name = helper.string("purchaseServer", "name", _name);
|
||||||
const ram = helper.number("purchaseServer", "ram", _ram);
|
const ram = helper.number("purchaseServer", "ram", _ram);
|
||||||
if (arguments.length !== 2) throw makeRuntimeErrorMsg("purchaseServer", "Takes 2 arguments");
|
if (arguments.length !== 2) throw makeRuntimeErrorMsg("purchaseServer", "Takes 2 arguments");
|
||||||
updateDynamicRam("purchaseServer", getRamCost(Player, "purchaseServer"));
|
|
||||||
let hostnameStr = String(name);
|
let hostnameStr = String(name);
|
||||||
hostnameStr = hostnameStr.replace(/\s+/g, "");
|
hostnameStr = hostnameStr.replace(/\s+/g, "");
|
||||||
if (hostnameStr == "") {
|
if (hostnameStr == "") {
|
||||||
@ -1805,8 +1805,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return newServ.hostname;
|
return newServ.hostname;
|
||||||
},
|
},
|
||||||
deleteServer: function (_name: unknown): boolean {
|
deleteServer: function (_name: unknown): boolean {
|
||||||
const name = helper.string("purchaseServer", "name", _name);
|
|
||||||
updateDynamicRam("deleteServer", getRamCost(Player, "deleteServer"));
|
updateDynamicRam("deleteServer", getRamCost(Player, "deleteServer"));
|
||||||
|
const name = helper.string("purchaseServer", "name", _name);
|
||||||
let hostnameStr = String(name);
|
let hostnameStr = String(name);
|
||||||
hostnameStr = hostnameStr.replace(/\s\s+/g, "");
|
hostnameStr = hostnameStr.replace(/\s\s+/g, "");
|
||||||
const server = GetServer(hostnameStr);
|
const server = GetServer(hostnameStr);
|
||||||
@ -1890,8 +1890,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
writePort: function (_port: unknown, data: any = ""): Promise<any> {
|
writePort: function (_port: unknown, data: any = ""): Promise<any> {
|
||||||
const port = helper.number("writePort", "port", _port);
|
|
||||||
updateDynamicRam("writePort", getRamCost(Player, "writePort"));
|
updateDynamicRam("writePort", getRamCost(Player, "writePort"));
|
||||||
|
const port = helper.number("writePort", "port", _port);
|
||||||
if (typeof data !== "string" && typeof data !== "number") {
|
if (typeof data !== "string" && typeof data !== "number") {
|
||||||
throw makeRuntimeErrorMsg(
|
throw makeRuntimeErrorMsg(
|
||||||
"writePort",
|
"writePort",
|
||||||
@ -1902,9 +1902,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return Promise.resolve(iport.write(data));
|
return Promise.resolve(iport.write(data));
|
||||||
},
|
},
|
||||||
write: function (_port: unknown, data: any = "", _mode: unknown = "a"): Promise<void> {
|
write: function (_port: unknown, data: any = "", _mode: unknown = "a"): Promise<void> {
|
||||||
|
updateDynamicRam("write", getRamCost(Player, "write"));
|
||||||
const port = helper.string("write", "port", _port);
|
const port = helper.string("write", "port", _port);
|
||||||
const mode = helper.string("write", "mode", _mode);
|
const mode = helper.string("write", "mode", _mode);
|
||||||
updateDynamicRam("write", getRamCost(Player, "write"));
|
|
||||||
if (isString(port)) {
|
if (isString(port)) {
|
||||||
// Write to script or text file
|
// Write to script or text file
|
||||||
let fn = port;
|
let fn = port;
|
||||||
@ -1957,8 +1957,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
tryWritePort: function (_port: unknown, data: any = ""): Promise<any> {
|
tryWritePort: function (_port: unknown, data: any = ""): Promise<any> {
|
||||||
let port = helper.number("tryWritePort", "port", _port);
|
|
||||||
updateDynamicRam("tryWritePort", getRamCost(Player, "tryWritePort"));
|
updateDynamicRam("tryWritePort", getRamCost(Player, "tryWritePort"));
|
||||||
|
let port = helper.number("tryWritePort", "port", _port);
|
||||||
if (typeof data !== "string" && typeof data !== "number") {
|
if (typeof data !== "string" && typeof data !== "number") {
|
||||||
throw makeRuntimeErrorMsg(
|
throw makeRuntimeErrorMsg(
|
||||||
"tryWritePort",
|
"tryWritePort",
|
||||||
@ -1983,16 +1983,16 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
readPort: function (_port: unknown): any {
|
readPort: function (_port: unknown): any {
|
||||||
const port = helper.number("readPort", "port", _port);
|
|
||||||
updateDynamicRam("readPort", getRamCost(Player, "readPort"));
|
updateDynamicRam("readPort", getRamCost(Player, "readPort"));
|
||||||
|
const port = helper.number("readPort", "port", _port);
|
||||||
// Read from port
|
// Read from port
|
||||||
const iport = helper.getValidPort("readPort", port);
|
const iport = helper.getValidPort("readPort", port);
|
||||||
const x = iport.read();
|
const x = iport.read();
|
||||||
return x;
|
return x;
|
||||||
},
|
},
|
||||||
read: function (_port: unknown): string {
|
read: function (_port: unknown): string {
|
||||||
const port = helper.string("read", "port", _port);
|
|
||||||
updateDynamicRam("read", getRamCost(Player, "read"));
|
updateDynamicRam("read", getRamCost(Player, "read"));
|
||||||
|
const port = helper.string("read", "port", _port);
|
||||||
if (isString(port)) {
|
if (isString(port)) {
|
||||||
// Read from script or text file
|
// Read from script or text file
|
||||||
const fn = port;
|
const fn = port;
|
||||||
@ -2021,15 +2021,15 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
peek: function (_port: unknown): any {
|
peek: function (_port: unknown): any {
|
||||||
const port = helper.number("peek", "port", _port);
|
|
||||||
updateDynamicRam("peek", getRamCost(Player, "peek"));
|
updateDynamicRam("peek", getRamCost(Player, "peek"));
|
||||||
|
const port = helper.number("peek", "port", _port);
|
||||||
const iport = helper.getValidPort("peek", port);
|
const iport = helper.getValidPort("peek", port);
|
||||||
const x = iport.peek();
|
const x = iport.peek();
|
||||||
return x;
|
return x;
|
||||||
},
|
},
|
||||||
clear: function (_file: unknown): void {
|
clear: function (_file: unknown): void {
|
||||||
const file = helper.string("peek", "file", _file);
|
|
||||||
updateDynamicRam("clear", getRamCost(Player, "clear"));
|
updateDynamicRam("clear", getRamCost(Player, "clear"));
|
||||||
|
const file = helper.string("peek", "file", _file);
|
||||||
if (isString(file)) {
|
if (isString(file)) {
|
||||||
// Clear text file
|
// Clear text file
|
||||||
const fn = file;
|
const fn = file;
|
||||||
@ -2046,21 +2046,21 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
clearPort: function (_port: unknown): void {
|
clearPort: function (_port: unknown): void {
|
||||||
const port = helper.number("clearPort", "port", _port);
|
|
||||||
updateDynamicRam("clearPort", getRamCost(Player, "clearPort"));
|
updateDynamicRam("clearPort", getRamCost(Player, "clearPort"));
|
||||||
|
const port = helper.number("clearPort", "port", _port);
|
||||||
// Clear port
|
// Clear port
|
||||||
const iport = helper.getValidPort("clearPort", port);
|
const iport = helper.getValidPort("clearPort", port);
|
||||||
iport.clear();
|
iport.clear();
|
||||||
},
|
},
|
||||||
getPortHandle: function (_port: unknown): IPort {
|
getPortHandle: function (_port: unknown): IPort {
|
||||||
const port = helper.number("getPortHandle", "port", _port);
|
|
||||||
updateDynamicRam("getPortHandle", getRamCost(Player, "getPortHandle"));
|
updateDynamicRam("getPortHandle", getRamCost(Player, "getPortHandle"));
|
||||||
|
const port = helper.number("getPortHandle", "port", _port);
|
||||||
const iport = helper.getValidPort("getPortHandle", port);
|
const iport = helper.getValidPort("getPortHandle", port);
|
||||||
return iport;
|
return iport;
|
||||||
},
|
},
|
||||||
rm: function (_fn: unknown, hostname: any): boolean {
|
rm: function (_fn: unknown, hostname: any): boolean {
|
||||||
const fn = helper.string("rm", "fn", _fn);
|
|
||||||
updateDynamicRam("rm", getRamCost(Player, "rm"));
|
updateDynamicRam("rm", getRamCost(Player, "rm"));
|
||||||
|
const fn = helper.string("rm", "fn", _fn);
|
||||||
|
|
||||||
if (hostname == null || hostname === "") {
|
if (hostname == null || hostname === "") {
|
||||||
hostname = workerScript.hostname;
|
hostname = workerScript.hostname;
|
||||||
@ -2075,9 +2075,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return status.res;
|
return status.res;
|
||||||
},
|
},
|
||||||
scriptRunning: function (_scriptname: unknown, _hostname: unknown): boolean {
|
scriptRunning: function (_scriptname: unknown, _hostname: unknown): boolean {
|
||||||
|
updateDynamicRam("scriptRunning", getRamCost(Player, "scriptRunning"));
|
||||||
const scriptname = helper.string("scriptRunning", "scriptname", _scriptname);
|
const scriptname = helper.string("scriptRunning", "scriptname", _scriptname);
|
||||||
const hostname = helper.string("scriptRunning", "hostname", _hostname);
|
const hostname = helper.string("scriptRunning", "hostname", _hostname);
|
||||||
updateDynamicRam("scriptRunning", getRamCost(Player, "scriptRunning"));
|
|
||||||
const server = safeGetServer(hostname, "scriptRunning");
|
const server = safeGetServer(hostname, "scriptRunning");
|
||||||
for (let i = 0; i < server.runningScripts.length; ++i) {
|
for (let i = 0; i < server.runningScripts.length; ++i) {
|
||||||
if (server.runningScripts[i].filename == scriptname) {
|
if (server.runningScripts[i].filename == scriptname) {
|
||||||
@ -2087,9 +2087,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
scriptKill: function (_scriptname: unknown, _hostname: unknown): boolean {
|
scriptKill: function (_scriptname: unknown, _hostname: unknown): boolean {
|
||||||
|
updateDynamicRam("scriptKill", getRamCost(Player, "scriptKill"));
|
||||||
const scriptname = helper.string("scriptKill", "scriptname", _scriptname);
|
const scriptname = helper.string("scriptKill", "scriptname", _scriptname);
|
||||||
const hostname = helper.string("scriptKill", "hostname", _hostname);
|
const hostname = helper.string("scriptKill", "hostname", _hostname);
|
||||||
updateDynamicRam("scriptKill", getRamCost(Player, "scriptKill"));
|
|
||||||
const server = safeGetServer(hostname, "scriptKill");
|
const server = safeGetServer(hostname, "scriptKill");
|
||||||
let suc = false;
|
let suc = false;
|
||||||
for (let i = 0; i < server.runningScripts.length; i++) {
|
for (let i = 0; i < server.runningScripts.length; i++) {
|
||||||
@ -2106,9 +2106,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return workerScript.name;
|
return workerScript.name;
|
||||||
},
|
},
|
||||||
getScriptRam: function (_scriptname: unknown, _hostname: unknown = workerScript.hostname): number {
|
getScriptRam: function (_scriptname: unknown, _hostname: unknown = workerScript.hostname): number {
|
||||||
|
updateDynamicRam("getScriptRam", getRamCost(Player, "getScriptRam"));
|
||||||
const scriptname = helper.string("getScriptRam", "scriptname", _scriptname);
|
const scriptname = helper.string("getScriptRam", "scriptname", _scriptname);
|
||||||
const hostname = helper.string("getScriptRam", "hostname", _hostname);
|
const hostname = helper.string("getScriptRam", "hostname", _hostname);
|
||||||
updateDynamicRam("getScriptRam", getRamCost(Player, "getScriptRam"));
|
|
||||||
const server = safeGetServer(hostname, "getScriptRam");
|
const server = safeGetServer(hostname, "getScriptRam");
|
||||||
for (let i = 0; i < server.scripts.length; ++i) {
|
for (let i = 0; i < server.scripts.length; ++i) {
|
||||||
if (server.scripts[i].filename == scriptname) {
|
if (server.scripts[i].filename == scriptname) {
|
||||||
@ -2146,8 +2146,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
getHackTime: function (_hostname: unknown = workerScript.hostname): number {
|
getHackTime: function (_hostname: unknown = workerScript.hostname): number {
|
||||||
const hostname = helper.string("getHackTime", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getHackTime", getRamCost(Player, "getHackTime"));
|
updateDynamicRam("getHackTime", getRamCost(Player, "getHackTime"));
|
||||||
|
const hostname = helper.string("getHackTime", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getHackTime");
|
const server = safeGetServer(hostname, "getHackTime");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
workerScript.log("getHackTime", () => "invalid for this kind of server");
|
workerScript.log("getHackTime", () => "invalid for this kind of server");
|
||||||
@ -2160,8 +2160,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return calculateHackingTime(server, Player) * 1000;
|
return calculateHackingTime(server, Player) * 1000;
|
||||||
},
|
},
|
||||||
getGrowTime: function (_hostname: unknown = workerScript.hostname): number {
|
getGrowTime: function (_hostname: unknown = workerScript.hostname): number {
|
||||||
const hostname = helper.string("getGrowTime", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getGrowTime", getRamCost(Player, "getGrowTime"));
|
updateDynamicRam("getGrowTime", getRamCost(Player, "getGrowTime"));
|
||||||
|
const hostname = helper.string("getGrowTime", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getGrowTime");
|
const server = safeGetServer(hostname, "getGrowTime");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
workerScript.log("getGrowTime", () => "invalid for this kind of server");
|
workerScript.log("getGrowTime", () => "invalid for this kind of server");
|
||||||
@ -2174,8 +2174,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return calculateGrowTime(server, Player) * 1000;
|
return calculateGrowTime(server, Player) * 1000;
|
||||||
},
|
},
|
||||||
getWeakenTime: function (_hostname: unknown = workerScript.hostname): number {
|
getWeakenTime: function (_hostname: unknown = workerScript.hostname): number {
|
||||||
const hostname = helper.string("getWeakenTime", "hostname", _hostname);
|
|
||||||
updateDynamicRam("getWeakenTime", getRamCost(Player, "getWeakenTime"));
|
updateDynamicRam("getWeakenTime", getRamCost(Player, "getWeakenTime"));
|
||||||
|
const hostname = helper.string("getWeakenTime", "hostname", _hostname);
|
||||||
const server = safeGetServer(hostname, "getWeakenTime");
|
const server = safeGetServer(hostname, "getWeakenTime");
|
||||||
if (!(server instanceof Server)) {
|
if (!(server instanceof Server)) {
|
||||||
workerScript.log("getWeakenTime", () => "invalid for this kind of server");
|
workerScript.log("getWeakenTime", () => "invalid for this kind of server");
|
||||||
@ -2239,9 +2239,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
nFormat: function (_n: unknown, _format: unknown): string {
|
nFormat: function (_n: unknown, _format: unknown): string {
|
||||||
|
updateDynamicRam("nFormat", getRamCost(Player, "nFormat"));
|
||||||
const n = helper.number("nFormat", "n", _n);
|
const n = helper.number("nFormat", "n", _n);
|
||||||
const format = helper.string("nFormat", "format", _format);
|
const format = helper.string("nFormat", "format", _format);
|
||||||
updateDynamicRam("nFormat", getRamCost(Player, "nFormat"));
|
|
||||||
if (isNaN(n)) {
|
if (isNaN(n)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -2249,9 +2249,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return numeralWrapper.format(n, format);
|
return numeralWrapper.format(n, format);
|
||||||
},
|
},
|
||||||
tFormat: function (_milliseconds: unknown, _milliPrecision: unknown = false): string {
|
tFormat: function (_milliseconds: unknown, _milliPrecision: unknown = false): string {
|
||||||
|
updateDynamicRam("tFormat", getRamCost(Player, "tFormat"));
|
||||||
const milliseconds = helper.number("tFormat", "milliseconds", _milliseconds);
|
const milliseconds = helper.number("tFormat", "milliseconds", _milliseconds);
|
||||||
const milliPrecision = helper.boolean(_milliPrecision);
|
const milliPrecision = helper.boolean(_milliPrecision);
|
||||||
updateDynamicRam("tFormat", getRamCost(Player, "tFormat"));
|
|
||||||
return convertTimeMsToTimeElapsedString(milliseconds, milliPrecision);
|
return convertTimeMsToTimeElapsedString(milliseconds, milliPrecision);
|
||||||
},
|
},
|
||||||
getTimeSinceLastAug: function (): number {
|
getTimeSinceLastAug: function (): number {
|
||||||
@ -2259,21 +2259,21 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return Player.playtimeSinceLastAug;
|
return Player.playtimeSinceLastAug;
|
||||||
},
|
},
|
||||||
alert: function (_message: unknown): void {
|
alert: function (_message: unknown): void {
|
||||||
const message = helper.string("alert", "message", _message);
|
|
||||||
updateDynamicRam("alert", getRamCost(Player, "alert"));
|
updateDynamicRam("alert", getRamCost(Player, "alert"));
|
||||||
|
const message = helper.string("alert", "message", _message);
|
||||||
dialogBoxCreate(message);
|
dialogBoxCreate(message);
|
||||||
},
|
},
|
||||||
toast: function (_message: unknown, _variant: unknown = "success", duration: any = 2000): void {
|
toast: function (_message: unknown, _variant: unknown = "success", duration: any = 2000): void {
|
||||||
|
updateDynamicRam("toast", getRamCost(Player, "toast"));
|
||||||
const message = helper.string("toast", "message", _message);
|
const message = helper.string("toast", "message", _message);
|
||||||
const variant = helper.string("toast", "variant", _variant);
|
const variant = helper.string("toast", "variant", _variant);
|
||||||
updateDynamicRam("toast", getRamCost(Player, "toast"));
|
|
||||||
if (!["success", "info", "warning", "error"].includes(variant))
|
if (!["success", "info", "warning", "error"].includes(variant))
|
||||||
throw new Error(`variant must be one of "success", "info", "warning", or "error"`);
|
throw new Error(`variant must be one of "success", "info", "warning", or "error"`);
|
||||||
SnackbarEvents.emit(message, variant as any, duration);
|
SnackbarEvents.emit(message, variant as any, duration);
|
||||||
},
|
},
|
||||||
prompt: function (_txt: unknown, options?: { type?: string; options?: string[] }): Promise<boolean | string> {
|
prompt: function (_txt: unknown, options?: { type?: string; options?: string[] }): Promise<boolean | string> {
|
||||||
const txt = helper.string("toast", "txt", _txt);
|
|
||||||
updateDynamicRam("prompt", getRamCost(Player, "prompt"));
|
updateDynamicRam("prompt", getRamCost(Player, "prompt"));
|
||||||
|
const txt = helper.string("toast", "txt", _txt);
|
||||||
|
|
||||||
return new Promise(function (resolve) {
|
return new Promise(function (resolve) {
|
||||||
PromptEvent.emit({
|
PromptEvent.emit({
|
||||||
@ -2288,10 +2288,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
_target: unknown,
|
_target: unknown,
|
||||||
_hostname: unknown = workerScript.hostname,
|
_hostname: unknown = workerScript.hostname,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
updateDynamicRam("wget", getRamCost(Player, "wget"));
|
||||||
const url = helper.string("wget", "url", _url);
|
const url = helper.string("wget", "url", _url);
|
||||||
const target = helper.string("wget", "target", _target);
|
const target = helper.string("wget", "target", _target);
|
||||||
const hostname = helper.string("wget", "hostname", _hostname);
|
const hostname = helper.string("wget", "hostname", _hostname);
|
||||||
updateDynamicRam("wget", getRamCost(Player, "wget"));
|
|
||||||
if (!isScriptFilename(target) && !target.endsWith(".txt")) {
|
if (!isScriptFilename(target) && !target.endsWith(".txt")) {
|
||||||
workerScript.log("wget", () => `Invalid target file: '${target}'. Must be a script or text file.`);
|
workerScript.log("wget", () => `Invalid target file: '${target}'. Must be a script or text file.`);
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
@ -2450,10 +2450,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}; // Wrap the user function to prevent WorkerScript leaking as 'this'
|
}; // Wrap the user function to prevent WorkerScript leaking as 'this'
|
||||||
},
|
},
|
||||||
mv: function (_host: unknown, _source: unknown, _destination: unknown): void {
|
mv: function (_host: unknown, _source: unknown, _destination: unknown): void {
|
||||||
|
updateDynamicRam("mv", getRamCost(Player, "mv"));
|
||||||
const host = helper.string("mv", "host", _host);
|
const host = helper.string("mv", "host", _host);
|
||||||
const source = helper.string("mv", "source", _source);
|
const source = helper.string("mv", "source", _source);
|
||||||
const destination = helper.string("mv", "destination", _destination);
|
const destination = helper.string("mv", "destination", _destination);
|
||||||
updateDynamicRam("mv", getRamCost(Player, "mv"));
|
|
||||||
|
|
||||||
if (!isValidFilePath(source)) throw makeRuntimeErrorMsg("mv", `Invalid filename: '${source}'`);
|
if (!isValidFilePath(source)) throw makeRuntimeErrorMsg("mv", `Invalid filename: '${source}'`);
|
||||||
if (!isValidFilePath(destination)) throw makeRuntimeErrorMsg("mv", `Invalid filename: '${destination}'`);
|
if (!isValidFilePath(destination)) throw makeRuntimeErrorMsg("mv", `Invalid filename: '${destination}'`);
|
||||||
|
Loading…
Reference in New Issue
Block a user