Added logging to scripts

This commit is contained in:
Daniel Xie 2017-04-11 08:59:48 -05:00
parent be641b19db
commit e9c2fd46ff

@ -211,7 +211,7 @@ function evaluate(exp, workerScript) {
} }
if (server == null) { if (server == null) {
resolve("Invalid IP or server hostname passed in"); resolve("Invalid IP or server hostname passed in");
//TODO LOg...or throw error or something workerScript.scriptRef.log("Cannot hack(). Invalid IP or hostname passed in: " + ip);
} }
//Calculate the hacking time //Calculate the hacking time
@ -219,9 +219,11 @@ function evaluate(exp, workerScript) {
if (server.hasAdminRights == false) { if (server.hasAdminRights == false) {
console.log("Cannot hack server " + server.hostname); console.log("Cannot hack server " + server.hostname);
resolve("Cannot hack"); resolve("Cannot hack, no admin rights");
//TODO LOG That it can't be hacked workerScript.scriptRef.log("Cannot hack this server because user does not have root access");
} }
workerScript.scriptRef.log("Attempting to hack " + ip + " in " + hackingTime + " seconds");
var p = new Promise(function(resolve, reject) { var p = new Promise(function(resolve, reject) {
if (env.stopFlag) {reject(workerScript);} if (env.stopFlag) {reject(workerScript);}
@ -245,6 +247,7 @@ function evaluate(exp, workerScript) {
Player.hacking_exp += expGainedOnSuccess; Player.hacking_exp += expGainedOnSuccess;
workerScript.scriptRef.onlineExpGained += expGainedOnSuccess; workerScript.scriptRef.onlineExpGained += expGainedOnSuccess;
console.log("Script successfully hacked " + server.hostname + " for $" + moneyGained + " and " + expGainedOnSuccess + " exp"); console.log("Script successfully hacked " + server.hostname + " for $" + moneyGained + " and " + expGainedOnSuccess + " exp");
workerScript.scriptRef.log("Script successfully hacked " + server.hostname + " for $" + moneyGained + " and " + expGainedOnSuccess + " exp");
resolve("Hack success"); resolve("Hack success");
} else { } else {
//Player only gains 25% exp for failure? TODO Can change this later to balance //Player only gains 25% exp for failure? TODO Can change this later to balance
@ -252,6 +255,7 @@ function evaluate(exp, workerScript) {
workerScript.scriptRef.onlineExpGained += expGainedOnFailure; workerScript.scriptRef.onlineExpGained += expGainedOnFailure;
console.log("Script unsuccessful to hack " + server.hostname + ". Gained " + expGainedOnFailure + "exp"); console.log("Script unsuccessful to hack " + server.hostname + ". Gained " + expGainedOnFailure + "exp");
workerScript.scriptRef.log("Script unsuccessful to hack " + server.hostname + ". Gained " + expGainedOnFailure + "exp");
resolve("Hack failure"); resolve("Hack failure");
} }
}, hackingTime * 1000); }, hackingTime * 1000);
@ -275,6 +279,7 @@ function evaluate(exp, workerScript) {
var sleepTimePromise = evaluate(exp.args[0], workerScript); var sleepTimePromise = evaluate(exp.args[0], workerScript);
sleepTimePromise.then(function(sleepTime) { sleepTimePromise.then(function(sleepTime) {
console.log("Sleep time: " + sleepTime); console.log("Sleep time: " + sleepTime);
workerScript.scriptRef.log("Sleeping for " + sleepTime + " milliseconds");
var p = new Promise(function(resolve, reject) { var p = new Promise(function(resolve, reject) {
setTimeout(function() { setTimeout(function() {
resolve("foo"); resolve("foo");