mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-01-05 12:57:35 +01:00
Fixed at least some of the bugs with Evaluator. needs more testing
This commit is contained in:
parent
53273596e2
commit
37a38c1e27
@ -6,6 +6,9 @@
|
|||||||
//wait for that promise to finish before continuing
|
//wait for that promise to finish before continuing
|
||||||
function evaluate(exp, workerScript) {
|
function evaluate(exp, workerScript) {
|
||||||
var env = workerScript.env;
|
var env = workerScript.env;
|
||||||
|
if (exp == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (exp.type) {
|
switch (exp.type) {
|
||||||
case "num":
|
case "num":
|
||||||
case "str":
|
case "str":
|
||||||
@ -103,7 +106,7 @@ function evaluate(exp, workerScript) {
|
|||||||
var numConds = exp.cond.length;
|
var numConds = exp.cond.length;
|
||||||
var numThens = exp.then.length;
|
var numThens = exp.then.length;
|
||||||
if (numConds == 0 || numThens == 0 || numConds != numThens) {
|
if (numConds == 0 || numThens == 0 || numConds != numThens) {
|
||||||
throw new Error ("|" + workerScript.serverIp + "|" + workerScript.name + "|Number of conds and thens in if structure don't match (or there are none)");
|
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Number of conds and thens in if structure don't match (or there are none)");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < numConds; i++) {
|
for (var i = 0; i < numConds; i++) {
|
||||||
@ -165,7 +168,9 @@ function evaluate(exp, workerScript) {
|
|||||||
evaluateProgPromise.then(function(w) {
|
evaluateProgPromise.then(function(w) {
|
||||||
resolve(workerScript);
|
resolve(workerScript);
|
||||||
}, function(e) {
|
}, function(e) {
|
||||||
reject(e);
|
console.log("Here");
|
||||||
|
workerScript.errorMessage = e.toString();
|
||||||
|
reject(workerScript);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -188,7 +193,7 @@ function evaluate(exp, workerScript) {
|
|||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
if (exp.func.value == "hack") {
|
if (exp.func.value == "hack") {
|
||||||
if (exp.args.length != 1) {
|
if (exp.args.length != 1) {
|
||||||
throw new Error("|" + workerScript.serverIp + "|" + workerScript.name + "|Hack() call has incorrect number of arguments. Takes 1 argument");
|
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Hack() call has incorrect number of arguments. Takes 1 argument");
|
||||||
}
|
}
|
||||||
|
|
||||||
//IP of server to hack
|
//IP of server to hack
|
||||||
@ -215,12 +220,12 @@ function evaluate(exp, workerScript) {
|
|||||||
//No root access or skill level too low
|
//No root access or skill level too low
|
||||||
if (server.hasAdminRights == false) {
|
if (server.hasAdminRights == false) {
|
||||||
workerScript.scriptRef.log("Cannot hack this server (" + server.hostname + ") because user does not have root access");
|
workerScript.scriptRef.log("Cannot hack this server (" + server.hostname + ") because user does not have root access");
|
||||||
throw new Error("|" + workerScript.serverIp + "|" + workerScript.name + "|Script crashed because it did not have root access to " + server.hostname);
|
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Script crashed because it did not have root access to " + server.hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server.requiredHackingSkill > Player.hacking_skill) {
|
if (server.requiredHackingSkill > Player.hacking_skill) {
|
||||||
workerScript.scriptRef.log("Cannot hack this server (" + server.hostaname + ") because user does not have root access");
|
workerScript.scriptRef.log("Cannot hack this server (" + server.hostaname + ") because user does not have root access");
|
||||||
throw new Error("|" + workerScript.serverIp + "|" + workerScript.name + "|Script crashed because player's hacking skill is not high enough to hack " + server.hostname);
|
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Script crashed because player's hacking skill is not high enough to hack " + server.hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
workerScript.scriptRef.log("Attempting to hack " + ip + " in " + hackingTime + " seconds");
|
workerScript.scriptRef.log("Attempting to hack " + ip + " in " + hackingTime + " seconds");
|
||||||
@ -272,7 +277,7 @@ function evaluate(exp, workerScript) {
|
|||||||
|
|
||||||
} else if (exp.func.value == "sleep") {
|
} else if (exp.func.value == "sleep") {
|
||||||
if (exp.args.length != 1) {
|
if (exp.args.length != 1) {
|
||||||
throw new Error("|" + workerScript.serverIp + "|" + workerScript.name + "|Sleep() call has incorrect number of arguments. Takes 1 argument.");
|
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Sleep() call has incorrect number of arguments. Takes 1 argument.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var sleepTimePromise = evaluate(exp.args[0], workerScript);
|
var sleepTimePromise = evaluate(exp.args[0], workerScript);
|
||||||
@ -296,7 +301,7 @@ function evaluate(exp, workerScript) {
|
|||||||
|
|
||||||
} else if (exp.func.value == "print") {
|
} else if (exp.func.value == "print") {
|
||||||
if (exp.args.length != 1) {
|
if (exp.args.length != 1) {
|
||||||
throw new Error("|" + workerScript.serverIp + "|" + workerScript.name + "| Print() call has incorrect number of arguments. Takes 1 argument");
|
reject("|" + workerScript.serverIp + "|" + workerScript.name + "| Print() call has incorrect number of arguments. Takes 1 argument");
|
||||||
}
|
}
|
||||||
|
|
||||||
var p = new Promise(function(resolve, reject) {
|
var p = new Promise(function(resolve, reject) {
|
||||||
@ -322,7 +327,7 @@ function evaluate(exp, workerScript) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("|" + workerScript.serverIp + "|" + workerScript.name + "| Can't evaluate type " + exp.type);
|
reject("|" + workerScript.serverIp + "|" + workerScript.name + "| Can't evaluate type " + exp.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,6 +526,18 @@ function apply_op(op, a, b) {
|
|||||||
throw new Error("Can't apply operator " + op);
|
throw new Error("Can't apply operator " + op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isScriptErrorMessage(msg) {
|
||||||
|
splitMsg = msg.split("|");
|
||||||
|
if (splitMsg.length != 4){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var ip = splitMsg[1];
|
||||||
|
if (!isValidIPAddress(ip)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//The same as Player's calculateHackingChance() function but takes in the server as an argument
|
//The same as Player's calculateHackingChance() function but takes in the server as an argument
|
||||||
function scriptCalculateHackingChance(server) {
|
function scriptCalculateHackingChance(server) {
|
||||||
var difficultyMult = (100 - server.hackDifficulty) / 100;
|
var difficultyMult = (100 - server.hackDifficulty) / 100;
|
||||||
|
@ -12,6 +12,7 @@ function WorkerScript(script) {
|
|||||||
this.output = "";
|
this.output = "";
|
||||||
this.ramUsage = 0;
|
this.ramUsage = 0;
|
||||||
this.scriptRef = script;
|
this.scriptRef = script;
|
||||||
|
this.errorMessage = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Returns the server on which the workerScript is running
|
//Returns the server on which the workerScript is running
|
||||||
@ -60,9 +61,6 @@ function runScriptsLoop() {
|
|||||||
var scriptName = errorTextArray[2];
|
var scriptName = errorTextArray[2];
|
||||||
var errorMsg = errorTextArray[3];
|
var errorMsg = errorTextArray[3];
|
||||||
|
|
||||||
//Post error message to terminal
|
|
||||||
//TODO Only post this if you're on the machine the script is running on?
|
|
||||||
post("Script runtime error: " + errorMsg);
|
|
||||||
dialogBoxCreate("Script runtime error: ", "Server Ip: " + serverIp, "Script name: " + scriptName, errorMsg);
|
dialogBoxCreate("Script runtime error: ", "Server Ip: " + serverIp, "Script name: " + scriptName, errorMsg);
|
||||||
|
|
||||||
//Find the corresponding workerscript and set its flags to kill it
|
//Find the corresponding workerscript and set its flags to kill it
|
||||||
@ -72,10 +70,20 @@ function runScriptsLoop() {
|
|||||||
workerScripts[i].env.stopFlag = true;
|
workerScripts[i].env.stopFlag = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (w instanceof WorkerScript) {
|
||||||
|
if (isScriptErrorMessage(w.errorMessage)) {
|
||||||
|
var errorTextArray = w.errorMessage.split("|");
|
||||||
|
if (errorTextArray.length != 4) {
|
||||||
|
console.log("ERROR: Something wrong with Error text in evaluator...");
|
||||||
|
console.log("Error text: " + errorText);
|
||||||
|
}
|
||||||
|
var serverIp = errorTextArray[1];
|
||||||
|
var scriptName = errorTextArray[2];
|
||||||
|
var errorMsg = errorTextArray[3];
|
||||||
|
|
||||||
} else {
|
dialogBoxCreate("Script runtime error: ", "Server Ip: " + serverIp, "Script name: " + scriptName, errorMsg);
|
||||||
console.log("Stopping script" + w.name + " because it was manually stopped (rejected)")
|
}
|
||||||
w.running = false;
|
w.running = false;
|
||||||
w.env.stopFlag = true;
|
w.env.stopFlag = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user