mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-30 01:47:33 +01:00
Attempt at logging line number on netscript error
This commit is contained in:
parent
1b8214b6fa
commit
e2a353fc8a
@ -362,6 +362,7 @@ a:visited {
|
|||||||
|
|
||||||
|
|
||||||
.optionCheckbox {
|
.optionCheckbox {
|
||||||
|
filter: invert(1) sepia(1) hue-rotate(41deg) brightness(100%) saturate(10);
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,7 @@ import { Programs } from "./Programs/Programs";
|
|||||||
import { Script } from "./Script/Script";
|
import { Script } from "./Script/Script";
|
||||||
import { findRunningScript } from "./Script/ScriptHelpers";
|
import { findRunningScript } from "./Script/ScriptHelpers";
|
||||||
import { isScriptFilename } from "./Script/ScriptHelpersTS";
|
import { isScriptFilename } from "./Script/ScriptHelpersTS";
|
||||||
|
import { _getScriptUrls } from "./NetscriptJSEvaluator";
|
||||||
import {
|
import {
|
||||||
AllServers,
|
AllServers,
|
||||||
AddToAllServers,
|
AddToAllServers,
|
||||||
@ -392,6 +393,23 @@ function NetscriptFunctions(workerScript) {
|
|||||||
return server.getContract(fn);
|
return server.getContract(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lineNumber = function() {
|
||||||
|
// exactly 5 function call parent from this one, so index 4
|
||||||
|
const fileline = (new Error()).stack.split('\n')[4];
|
||||||
|
const scripts = workerScript.getServer().scripts;
|
||||||
|
|
||||||
|
let problem;
|
||||||
|
for(const script of scripts) {
|
||||||
|
if (script.url && fileline.includes(script.url)) {
|
||||||
|
problem = script.filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const re = /.*:(\d+):\d+.*/;
|
||||||
|
const match = fileline.match(re);
|
||||||
|
return `${problem}#${match[1]}`;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hacknet : {
|
hacknet : {
|
||||||
numNodes : function() {
|
numNodes : function() {
|
||||||
@ -531,7 +549,7 @@ function NetscriptFunctions(workerScript) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.hack == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.hack == null) {
|
||||||
workerScript.scriptRef.log("Attempting to hack " + ip + " in " + hackingTime.toFixed(3) + " seconds (t=" + threads + ")");
|
workerScript.scriptRef.log(`Executing hack ${ip} in ${hackingTime.toFixed(3)} seconds (t=${threads})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return netscriptDelay(hackingTime * 1000, workerScript).then(function() {
|
return netscriptDelay(hackingTime * 1000, workerScript).then(function() {
|
||||||
@ -567,7 +585,7 @@ function NetscriptFunctions(workerScript) {
|
|||||||
Player.gainHackingExp(expGainedOnSuccess);
|
Player.gainHackingExp(expGainedOnSuccess);
|
||||||
workerScript.scriptRef.onlineExpGained += expGainedOnSuccess;
|
workerScript.scriptRef.onlineExpGained += expGainedOnSuccess;
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.hack == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.hack == null) {
|
||||||
workerScript.scriptRef.log("Script SUCCESSFULLY hacked " + server.hostname + " for $" + formatNumber(moneyGained, 2) + " and " + formatNumber(expGainedOnSuccess, 4) + " exp (t=" + threads + ")");
|
workerScript.scriptRef.log(`Successfully hacked ${server.hostname} for ${numeralWrapper.format(moneyGained, '$0.000a')} and ${numeralWrapper.format(expGainedOnSuccess, '0.000a')} exp (t=${threads})`);
|
||||||
}
|
}
|
||||||
server.fortify(CONSTANTS.ServerFortifyAmount * Math.min(threads, maxThreadNeeded));
|
server.fortify(CONSTANTS.ServerFortifyAmount * Math.min(threads, maxThreadNeeded));
|
||||||
if (stock) {
|
if (stock) {
|
||||||
@ -579,7 +597,7 @@ function NetscriptFunctions(workerScript) {
|
|||||||
Player.gainHackingExp(expGainedOnFailure);
|
Player.gainHackingExp(expGainedOnFailure);
|
||||||
workerScript.scriptRef.onlineExpGained += expGainedOnFailure;
|
workerScript.scriptRef.onlineExpGained += expGainedOnFailure;
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.hack == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.hack == null) {
|
||||||
workerScript.scriptRef.log("Script FAILED to hack " + server.hostname + ". Gained " + formatNumber(expGainedOnFailure, 4) + " exp (t=" + threads + ")");
|
workerScript.scriptRef.log(`Failed to hack ${server.hostname}. Gained ${numeralWrapper.format(expGainedOnFailure, '0.000a')} exp (t=${threads})`);
|
||||||
}
|
}
|
||||||
return Promise.resolve(0);
|
return Promise.resolve(0);
|
||||||
}
|
}
|
||||||
@ -635,8 +653,8 @@ function NetscriptFunctions(workerScript) {
|
|||||||
}
|
}
|
||||||
var server = getServer(ip);
|
var server = getServer(ip);
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
workerScript.scriptRef.log("Cannot grow(). Invalid IP or hostname passed in: " + ip);
|
workerScript.scriptRef.log(`Cannot grow(). Invalid IP or hostname passed in: ${ip}`);
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Cannot grow(). Invalid IP or hostname passed in: " + ip);
|
throw makeRuntimeRejectMsg(workerScript, `Cannot grow(). Invalid IP or hostname passed in: ${ip}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No root access or skill level too low
|
// No root access or skill level too low
|
||||||
@ -648,7 +666,7 @@ function NetscriptFunctions(workerScript) {
|
|||||||
|
|
||||||
var growTime = calculateGrowTime(server);
|
var growTime = calculateGrowTime(server);
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.grow == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.grow == null) {
|
||||||
workerScript.scriptRef.log("Executing grow() on server " + server.hostname + " in " + formatNumber(growTime, 3) + " seconds (t=" + threads + ")");
|
workerScript.scriptRef.log(`Executing grow('${server.hostname}') in ${formatNumber(growTime, 3)} seconds (t=${threads})`);
|
||||||
}
|
}
|
||||||
return netscriptDelay(growTime * 1000, workerScript).then(function() {
|
return netscriptDelay(growTime * 1000, workerScript).then(function() {
|
||||||
if (workerScript.env.stopFlag) {return Promise.reject(workerScript);}
|
if (workerScript.env.stopFlag) {return Promise.reject(workerScript);}
|
||||||
@ -661,10 +679,9 @@ function NetscriptFunctions(workerScript) {
|
|||||||
if (growthPercentage == 1) {
|
if (growthPercentage == 1) {
|
||||||
expGain = 0;
|
expGain = 0;
|
||||||
}
|
}
|
||||||
|
const logGrowPercent = (moneyAfter/moneyBefore)*100 - 100;
|
||||||
if (workerScript.shouldLog("grow")) {
|
if (workerScript.shouldLog("grow")) {
|
||||||
workerScript.log("Available money on " + server.hostname + " grown by " +
|
workerScript.log(`Available money on ${server.hostname} grown by ${formatNumber(logGrowPercent, 6)}%. Gained ${numeralWrapper.format(expGain, '0.000a')} hacking exp (t=${threads})`);
|
||||||
formatNumber((moneyAfter/moneyBefore)*100 - 100, 6) + "%. Gained " +
|
|
||||||
formatNumber(expGain, 4) + " hacking exp (t=" + threads +")");
|
|
||||||
}
|
}
|
||||||
workerScript.scriptRef.onlineExpGained += expGain;
|
workerScript.scriptRef.onlineExpGained += expGain;
|
||||||
Player.gainHackingExp(expGain);
|
Player.gainHackingExp(expGain);
|
||||||
@ -706,8 +723,7 @@ function NetscriptFunctions(workerScript) {
|
|||||||
|
|
||||||
var weakenTime = calculateWeakenTime(server);
|
var weakenTime = calculateWeakenTime(server);
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.weaken == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.weaken == null) {
|
||||||
workerScript.scriptRef.log("Executing weaken() on server " + server.hostname + " in " +
|
workerScript.scriptRef.log(`Executing weaken('${server.hostname}') in ${formatNumber(weakenTime, 3)} seconds (t=${threads})`);
|
||||||
formatNumber(weakenTime, 3) + " seconds (t=" + threads + ")");
|
|
||||||
}
|
}
|
||||||
return netscriptDelay(weakenTime * 1000, workerScript).then(function() {
|
return netscriptDelay(weakenTime * 1000, workerScript).then(function() {
|
||||||
if (workerScript.env.stopFlag) {return Promise.reject(workerScript);}
|
if (workerScript.env.stopFlag) {return Promise.reject(workerScript);}
|
||||||
@ -715,8 +731,7 @@ function NetscriptFunctions(workerScript) {
|
|||||||
workerScript.scriptRef.recordWeaken(server.ip, threads);
|
workerScript.scriptRef.recordWeaken(server.ip, threads);
|
||||||
var expGain = calculateHackingExpGain(server) * threads;
|
var expGain = calculateHackingExpGain(server) * threads;
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.weaken == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.weaken == null) {
|
||||||
workerScript.scriptRef.log("Server security level on " + server.hostname + " weakened to " + server.hackDifficulty +
|
workerScript.scriptRef.log(`${server.hostname} security level weakened to ${server.hackDifficulty}. Gained ${numeralWrapper.format(expGain, '0.000a')} hacking exp (t=${threads})`);
|
||||||
". Gained " + formatNumber(expGain, 4) + " hacking exp (t=" + threads + ")");
|
|
||||||
}
|
}
|
||||||
workerScript.scriptRef.onlineExpGained += expGain;
|
workerScript.scriptRef.onlineExpGained += expGain;
|
||||||
Player.gainHackingExp(expGain);
|
Player.gainHackingExp(expGain);
|
||||||
@ -734,32 +749,32 @@ function NetscriptFunctions(workerScript) {
|
|||||||
throw makeRuntimeRejectMsg(workerScript, "tprint() call has incorrect number of arguments. Takes 1 argument");
|
throw makeRuntimeRejectMsg(workerScript, "tprint() call has incorrect number of arguments. Takes 1 argument");
|
||||||
}
|
}
|
||||||
var x = args.toString();
|
var x = args.toString();
|
||||||
post(workerScript.scriptRef.filename + ": " + args.toString());
|
post(`${workerScript.scriptRef.filename}: ${args.toString()}`);
|
||||||
},
|
},
|
||||||
clearLog: function() {
|
clearLog: function() {
|
||||||
workerScript.scriptRef.clearLog();
|
workerScript.scriptRef.clearLog();
|
||||||
},
|
},
|
||||||
disableLog: function(fn) {
|
disableLog: function(fn) {
|
||||||
if (possibleLogs[fn]===undefined) {
|
if (possibleLogs[fn]===undefined) {
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Invalid argument to disableLog: "+fn);
|
throw makeRuntimeRejectMsg(workerScript, `Invalid argument to disableLog: ${fn}`);
|
||||||
}
|
}
|
||||||
workerScript.disableLogs[fn] = true;
|
workerScript.disableLogs[fn] = true;
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.disableLog == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.disableLog == null) {
|
||||||
workerScript.scriptRef.log("Disabled logging for " + fn);
|
workerScript.scriptRef.log(`Disabled logging for ${fn}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enableLog: function(fn) {
|
enableLog: function(fn) {
|
||||||
if (possibleLogs[fn]===undefined) {
|
if (possibleLogs[fn]===undefined) {
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Invalid argument to enableLog: "+fn);
|
throw makeRuntimeRejectMsg(workerScript, `Invalid argument to enableLog: ${fn}`);
|
||||||
}
|
}
|
||||||
delete workerScript.disableLogs[fn];
|
delete workerScript.disableLogs[fn];
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.enableLog == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.enableLog == null) {
|
||||||
workerScript.scriptRef.log("Enabled logging for " + fn);
|
workerScript.scriptRef.log(`Enabled logging for ${fn}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isLogEnabled : function(fn) {
|
isLogEnabled : function(fn) {
|
||||||
if (possibleLogs[fn] === undefined) {
|
if (possibleLogs[fn] === undefined) {
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Invalid argument to isLogEnabled: " + fn);
|
throw makeRuntimeRejectMsg(workerScript, `Invalid argument to isLogEnabled: ${fn}`);
|
||||||
}
|
}
|
||||||
return workerScript.disableLogs[fn] ? false : true;
|
return workerScript.disableLogs[fn] ? false : true;
|
||||||
},
|
},
|
||||||
@ -784,12 +799,13 @@ function NetscriptFunctions(workerScript) {
|
|||||||
nuke: function(ip){
|
nuke: function(ip){
|
||||||
updateDynamicRam("nuke", getRamCost("nuke"));
|
updateDynamicRam("nuke", getRamCost("nuke"));
|
||||||
if (ip === undefined) {
|
if (ip === undefined) {
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Program call has incorrect number of arguments. Takes 1 argument");
|
throw makeRuntimeRejectMsg(workerScript, "nuke call has incorrect number of arguments. Takes 1 argument");
|
||||||
}
|
}
|
||||||
var server = getServer(ip);
|
var server = getServer(ip);
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
workerScript.scriptRef.log("Cannot call nuke(). Invalid IP or hostname passed in: " + ip);
|
const msg = `Cannot call nuke('${ip}'). Invalid IP/hostname.`;
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Cannot call nuke(). Invalid IP or hostname passed in: " + ip);
|
workerScript.scriptRef.log(msg);
|
||||||
|
throw makeRuntimeRejectMsg(workerScript, msg);
|
||||||
}
|
}
|
||||||
if (!Player.hasProgram(Programs.NukeProgram.name)) {
|
if (!Player.hasProgram(Programs.NukeProgram.name)) {
|
||||||
throw makeRuntimeRejectMsg(workerScript, "You do not have the NUKE.exe virus!");
|
throw makeRuntimeRejectMsg(workerScript, "You do not have the NUKE.exe virus!");
|
||||||
@ -799,12 +815,12 @@ function NetscriptFunctions(workerScript) {
|
|||||||
}
|
}
|
||||||
if (server.hasAdminRights) {
|
if (server.hasAdminRights) {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.nuke == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.nuke == null) {
|
||||||
workerScript.scriptRef.log("Already have root access to " + server.hostname);
|
workerScript.scriptRef.log(`Already have root access to ${server.hostname}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
server.hasAdminRights = true;
|
server.hasAdminRights = true;
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.nuke == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.nuke == null) {
|
||||||
workerScript.scriptRef.log("Executed NUKE.exe virus on " + server.hostname + " to gain root access");
|
workerScript.scriptRef.log(`Executed NUKE.exe virus on ${server.hostname} to gain root access`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -812,12 +828,13 @@ function NetscriptFunctions(workerScript) {
|
|||||||
brutessh: function(ip){
|
brutessh: function(ip){
|
||||||
updateDynamicRam("brutessh", getRamCost("brutessh"));
|
updateDynamicRam("brutessh", getRamCost("brutessh"));
|
||||||
if (ip === undefined) {
|
if (ip === undefined) {
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Program call has incorrect number of arguments. Takes 1 argument");
|
throw makeRuntimeRejectMsg(workerScript, "brutessh call has incorrect number of arguments. Takes 1 argument");
|
||||||
}
|
}
|
||||||
var server = getServer(ip);
|
var server = getServer(ip);
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
workerScript.scriptRef.log("Cannot call brutessh(). Invalid IP or hostname passed in: " + ip);
|
const msg = `Cannot call brutessh('${ip}'). Invalid IP/hostname.`;
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Cannot call brutessh(). Invalid IP or hostname passed in: " + ip);
|
workerScript.scriptRef.log(msg);
|
||||||
|
throw makeRuntimeRejectMsg(workerScript, msg);
|
||||||
}
|
}
|
||||||
if (!Player.hasProgram(Programs.BruteSSHProgram.name)) {
|
if (!Player.hasProgram(Programs.BruteSSHProgram.name)) {
|
||||||
workerScript.scriptRef.log("You do not have the BruteSSH.exe program!");
|
workerScript.scriptRef.log("You do not have the BruteSSH.exe program!");
|
||||||
@ -825,13 +842,13 @@ function NetscriptFunctions(workerScript) {
|
|||||||
}
|
}
|
||||||
if (!server.sshPortOpen) {
|
if (!server.sshPortOpen) {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.brutessh == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.brutessh == null) {
|
||||||
workerScript.scriptRef.log("Executed BruteSSH.exe on " + server.hostname + " to open SSH port (22)");
|
workerScript.scriptRef.log(`Executed BruteSSH.exe on ${server.hostname} to open SSH port (22)`);
|
||||||
}
|
}
|
||||||
server.sshPortOpen = true;
|
server.sshPortOpen = true;
|
||||||
++server.openPortCount;
|
++server.openPortCount;
|
||||||
} else {
|
} else {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.brutessh == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.brutessh == null) {
|
||||||
workerScript.scriptRef.log("SSH Port (22) already opened on " + server.hostname);
|
workerScript.scriptRef.log(`SSH Port (22) already opened on ${server.hostname}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -843,21 +860,22 @@ function NetscriptFunctions(workerScript) {
|
|||||||
}
|
}
|
||||||
var server = getServer(ip);
|
var server = getServer(ip);
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
workerScript.scriptRef.log("Cannot call ftpcrack(). Invalid IP or hostname passed in: " + ip);
|
const msg = `Cannot call ftpcrack('${ip}'). Invalid IP/hostname.`
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Cannot call ftpcrack(). Invalid IP or hostname passed in: " + ip);
|
workerScript.scriptRef.log(msg);
|
||||||
|
throw makeRuntimeRejectMsg(workerScript, msg);
|
||||||
}
|
}
|
||||||
if (!Player.hasProgram(Programs.FTPCrackProgram.name)) {
|
if (!Player.hasProgram(Programs.FTPCrackProgram.name)) {
|
||||||
throw makeRuntimeRejectMsg(workerScript, "You do not have the FTPCrack.exe program!");
|
throw makeRuntimeRejectMsg(workerScript, "You do not have the FTPCrack.exe program!");
|
||||||
}
|
}
|
||||||
if (!server.ftpPortOpen) {
|
if (!server.ftpPortOpen) {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.ftpcrack == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.ftpcrack == null) {
|
||||||
workerScript.scriptRef.log("Executed FTPCrack.exe on " + server.hostname + " to open FTP port (21)");
|
workerScript.scriptRef.log(`Executed FTPCrack.exe on ${server.hostname} to open FTP port (21)`);
|
||||||
}
|
}
|
||||||
server.ftpPortOpen = true;
|
server.ftpPortOpen = true;
|
||||||
++server.openPortCount;
|
++server.openPortCount;
|
||||||
} else {
|
} else {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.ftpcrack == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.ftpcrack == null) {
|
||||||
workerScript.scriptRef.log("FTP Port (21) already opened on " + server.hostname);
|
workerScript.scriptRef.log(`FTP Port (21) already opened on ${server.hostname}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -869,21 +887,22 @@ function NetscriptFunctions(workerScript) {
|
|||||||
}
|
}
|
||||||
var server = getServer(ip);
|
var server = getServer(ip);
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
workerScript.scriptRef.log("Cannot call relaysmtp(). Invalid IP or hostname passed in: " + ip);
|
const msg = `Cannot call relaysmtp('${ip}'). Invalid IP/hostname.`
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Cannot call relaysmtp(). Invalid IP or hostname passed in: " + ip);
|
workerScript.scriptRef.log(msg);
|
||||||
|
throw makeRuntimeRejectMsg(workerScript, msg);
|
||||||
}
|
}
|
||||||
if (!Player.hasProgram(Programs.RelaySMTPProgram.name)) {
|
if (!Player.hasProgram(Programs.RelaySMTPProgram.name)) {
|
||||||
throw makeRuntimeRejectMsg(workerScript, "You do not have the relaySMTP.exe program!");
|
throw makeRuntimeRejectMsg(workerScript, "You do not have the relaySMTP.exe program!");
|
||||||
}
|
}
|
||||||
if (!server.smtpPortOpen) {
|
if (!server.smtpPortOpen) {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.relaysmtp == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.relaysmtp == null) {
|
||||||
workerScript.scriptRef.log("Executed relaySMTP.exe on " + server.hostname + " to open SMTP port (25)");
|
workerScript.scriptRef.log(`Executed relaySMTP.exe on ${server.hostname} to open SMTP port (25)`);
|
||||||
}
|
}
|
||||||
server.smtpPortOpen = true;
|
server.smtpPortOpen = true;
|
||||||
++server.openPortCount;
|
++server.openPortCount;
|
||||||
} else {
|
} else {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.relaysmtp == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.relaysmtp == null) {
|
||||||
workerScript.scriptRef.log("SMTP Port (25) already opened on " + server.hostname);
|
workerScript.scriptRef.log(`SMTP Port (25) already opened on ${server.hostname}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -895,21 +914,22 @@ function NetscriptFunctions(workerScript) {
|
|||||||
}
|
}
|
||||||
var server = getServer(ip);
|
var server = getServer(ip);
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
workerScript.scriptRef.log("Cannot call httpworm(). Invalid IP or hostname passed in: " + ip);
|
const msg = `Cannot call httpworm('${ip}'). Invalid IP/hostname.`
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Cannot call httpworm(). Invalid IP or hostname passed in: " + ip);
|
workerScript.scriptRef.log(msg);
|
||||||
|
throw makeRuntimeRejectMsg(workerScript, msg);
|
||||||
}
|
}
|
||||||
if (!Player.hasProgram(Programs.HTTPWormProgram.name)) {
|
if (!Player.hasProgram(Programs.HTTPWormProgram.name)) {
|
||||||
throw makeRuntimeRejectMsg(workerScript, "You do not have the HTTPWorm.exe program!");
|
throw makeRuntimeRejectMsg(workerScript, "You do not have the HTTPWorm.exe program!");
|
||||||
}
|
}
|
||||||
if (!server.httpPortOpen) {
|
if (!server.httpPortOpen) {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.httpworm == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.httpworm == null) {
|
||||||
workerScript.scriptRef.log("Executed HTTPWorm.exe on " + server.hostname + " to open HTTP port (80)");
|
workerScript.scriptRef.log(`Executed HTTPWorm.exe on ${server.hostname} to open HTTP port (80)`);
|
||||||
}
|
}
|
||||||
server.httpPortOpen = true;
|
server.httpPortOpen = true;
|
||||||
++server.openPortCount;
|
++server.openPortCount;
|
||||||
} else {
|
} else {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.httpworm == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.httpworm == null) {
|
||||||
workerScript.scriptRef.log("HTTP Port (80) already opened on " + server.hostname);
|
workerScript.scriptRef.log(`HTTP Port (80) already opened on ${server.hostname}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -921,21 +941,22 @@ function NetscriptFunctions(workerScript) {
|
|||||||
}
|
}
|
||||||
var server = getServer(ip);
|
var server = getServer(ip);
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
workerScript.scriptRef.log("Cannot call sqlinject(). Invalid IP or hostname passed in: " + ip);
|
const msg = `Cannot call sqlinject('${ip}'). Invalid IP/hostname.`
|
||||||
throw makeRuntimeRejectMsg(workerScript, "Cannot call sqlinject(). Invalid IP or hostname passed in: " + ip);
|
workerScript.scriptRef.log(msg);
|
||||||
|
throw makeRuntimeRejectMsg(workerScript, msg);
|
||||||
}
|
}
|
||||||
if (!Player.hasProgram(Programs.SQLInjectProgram.name)) {
|
if (!Player.hasProgram(Programs.SQLInjectProgram.name)) {
|
||||||
throw makeRuntimeRejectMsg(workerScript, "You do not have the SQLInject.exe program!");
|
throw makeRuntimeRejectMsg(workerScript, "You do not have the SQLInject.exe program!");
|
||||||
}
|
}
|
||||||
if (!server.sqlPortOpen) {
|
if (!server.sqlPortOpen) {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.sqlinject == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.sqlinject == null) {
|
||||||
workerScript.scriptRef.log("Executed SQLInject.exe on " + server.hostname + " to open SQL port (1433)");
|
workerScript.scriptRef.log(`Executed SQLInject.exe on ${server.hostname} to open SQL port (1433)`);
|
||||||
}
|
}
|
||||||
server.sqlPortOpen = true;
|
server.sqlPortOpen = true;
|
||||||
++server.openPortCount;
|
++server.openPortCount;
|
||||||
} else {
|
} else {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.sqlinject == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.sqlinject == null) {
|
||||||
workerScript.scriptRef.log("SQL Port (1433) already opened on " + server.hostname);
|
workerScript.scriptRef.log(`SQL Port (1433) already opened on ${server.hostname}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1154,21 +1175,21 @@ function NetscriptFunctions(workerScript) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
workerScript.scriptRef.log(scriptname + " does not exist. scp() failed");
|
workerScript.scriptRef.log(`${scriptname} does not exist. scp() failed`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < destServer.messages.length; ++i) {
|
for (var i = 0; i < destServer.messages.length; ++i) {
|
||||||
if (destServer.messages[i] === scriptname) {
|
if (destServer.messages[i] === scriptname) {
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.scp == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.scp == null) {
|
||||||
workerScript.scriptRef.log(scriptname + " copied over to " + destServer.hostname);
|
workerScript.scriptRef.log(`${scriptname} copied over to ${destServer.hostname}`);
|
||||||
}
|
}
|
||||||
return true; // Already exists
|
return true; // Already exists
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
destServer.messages.push(scriptname);
|
destServer.messages.push(scriptname);
|
||||||
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.scp == null) {
|
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.scp == null) {
|
||||||
workerScript.scriptRef.log(scriptname + " copied over to " + destServer.hostname);
|
workerScript.scriptRef.log(`${scriptname} copied over to ${destServer.hostname}`);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -4717,6 +4738,12 @@ function NetscriptFunctions(workerScript) {
|
|||||||
},
|
},
|
||||||
exploit: function() {
|
exploit: function() {
|
||||||
Player.giveExploit(Exploit.UndocumentedFunctionCall);
|
Player.giveExploit(Exploit.UndocumentedFunctionCall);
|
||||||
|
},
|
||||||
|
whatever: function(ip) {
|
||||||
|
const server = getServer(ip);
|
||||||
|
if (server == null) {
|
||||||
|
throw makeRuntimeRejectMsg(workerScript, `${lineNumber()}: hack('${ip}'): Invalid IP/hostname.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // End return
|
} // End return
|
||||||
} // End NetscriptFunction()
|
} // End NetscriptFunction()
|
||||||
|
@ -38,6 +38,7 @@ export async function executeJSScript(scripts = [], workerScript) {
|
|||||||
// load fully dynamic content. So we hide the import from webpack
|
// load fully dynamic content. So we hide the import from webpack
|
||||||
// by placing it inside an eval call.
|
// by placing it inside an eval call.
|
||||||
urls = _getScriptUrls(script, scripts, []);
|
urls = _getScriptUrls(script, scripts, []);
|
||||||
|
script.url = urls[urls.length - 1].url;
|
||||||
script.module = new Promise(resolve => resolve(eval('import(urls[urls.length - 1].url)')));
|
script.module = new Promise(resolve => resolve(eval('import(urls[urls.length - 1].url)')));
|
||||||
script.dependencies = urls.map(u => u.filename);
|
script.dependencies = urls.map(u => u.filename);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,9 @@ export class Script {
|
|||||||
// Filename for the script file
|
// Filename for the script file
|
||||||
filename: string = "";
|
filename: string = "";
|
||||||
|
|
||||||
|
// url of the script if any, only for NS2.
|
||||||
|
url: string = "";
|
||||||
|
|
||||||
// The dynamic module generated for this script when it is run.
|
// The dynamic module generated for this script when it is run.
|
||||||
// This is only applicable for NetscriptJS
|
// This is only applicable for NetscriptJS
|
||||||
module: any = "";
|
module: any = "";
|
||||||
|
Loading…
Reference in New Issue
Block a user