diff --git a/src/Netscript/NetscriptWorker.js b/src/Netscript/NetscriptWorker.js index c9dba3b8a..3f2546586 100644 --- a/src/Netscript/NetscriptWorker.js +++ b/src/Netscript/NetscriptWorker.js @@ -1,13 +1,16 @@ /* Worker code, contains Netscript scripts that are actually running */ +//TODO Need some way to stop scripts. Idea: Put a flag in the environment, we can setActive +//this flag from outside. If the evaluate() function sees that flag it rejects the current +// Promise. We can catch that rejection and stop the script. /* Actual Worker Code */ function WorkerScript() { - this.name = ""; - this.running = false; - this.server = null; - this.code = ""; - this.env = new Environment(); - this.timeout = null; + this.name = ""; + this.running = false; + this.serverHostname = null; + this.code = ""; + this.env = new Environment(); + this.timeout = null; } //Array containing all scripts that are running across all servers, to easily run them all @@ -23,8 +26,8 @@ function runScriptsLoop() { console.log("AST of new script:"); console.log(ast); - evaluate(ast, workerScripts[i]); workerScripts[i].running = true; + evaluate(ast, workerScripts[i]); } } diff --git a/src/Server.js b/src/Server.js index e258bd078..43733745f 100644 --- a/src/Server.js +++ b/src/Server.js @@ -1,4 +1,6 @@ //Netburner Server class +//TODO Make a map of all IPS in the game so far so that we don't accidentally +// get duplicate IPs..however unlikely it is function Server() { /* Properties */ //Connection information @@ -18,7 +20,7 @@ function Server() { this.cpuSpeed = 1; //MHz this.scripts = []; - this.runningScripts = []; //Names of scripts currently being run + this.runningScripts = []; //Names (and only names) of scripts being run this.programs = []; /* Hacking information (only valid for "foreign" aka non-purchased servers) */ diff --git a/src/Terminal.js b/src/Terminal.js index ec5b2ed53..23ff9fa0c 100644 --- a/src/Terminal.js +++ b/src/Terminal.js @@ -434,10 +434,16 @@ var Terminal = { if (Player.currentServer.hasAdminRights == false) { post("Need root access to run script"); } else { - //TODO Run script here + var filename = Player.currentServer.scripts[i].filename; + + //Add to current server's runningScripts + Player.currentServer.runningScripts.push(filename) + + //Create WorkerScript var s = new WorkerScript(); - s.name = Player.currentServer.scripts[i].filename; - s.code = Player.currentServer.scripts[i].code; + s.name = filename; + s.code = Player.currentServer.scripts[i].code; + s.hostname = Player.currentServer.hostname; workerScripts.push(s); console.log("Pushed script onto workerScripts"); return; diff --git a/src/engine.js b/src/engine.js index b03f29401..87353344a 100644 --- a/src/engine.js +++ b/src/engine.js @@ -1,3 +1,6 @@ +//TODO Saving only works with stirngs.key value pairs. Think of a system to do saves +// And everything with all the things I have + //Replaces the character at an index with a new character String.prototype.replaceAt=function(index, character) { return this.substr(0, index) + character + this.substr(index+character.length);