From 685103c5d4a3dc3027662a2d43de64c3703a761c Mon Sep 17 00:00:00 2001 From: Daniel Xie Date: Thu, 13 Apr 2017 14:36:03 -0500 Subject: [PATCH] Implemented 'rm' command. FIxed some bugs --- README.md | 2 +- src/Netscript/NetscriptWorker.js | 3 ++- src/Terminal.js | 31 +++++++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 64d7f8d5b..f7997dca1 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Tasks TODO: Tutorial and help - INTERACTIVE TUTORIAL Secret Servers - Hack time formula needs rebalancing I think + Hack time formula needs rebalancing I think, so does hack exp Create new menu page for purchased servers diff --git a/src/Netscript/NetscriptWorker.js b/src/Netscript/NetscriptWorker.js index bd2c17c10..f91ede785 100644 --- a/src/Netscript/NetscriptWorker.js +++ b/src/Netscript/NetscriptWorker.js @@ -31,7 +31,8 @@ function runScriptsLoop() { try { var ast = Parser(Tokenizer(InputStream(workerScripts[i].code))); } catch (e) { - post("Syntax error in " + workerScript[i].name + ": " + e); + dialogBoxCreate("Syntax ERROR in " + workerScripts[i].name + ":", e, "", ""); + workerScripts[i].env.stopFlag = true; continue; } diff --git a/src/Terminal.js b/src/Terminal.js index b023af2d0..30488c905 100644 --- a/src/Terminal.js +++ b/src/Terminal.js @@ -396,14 +396,41 @@ var Terminal = { break; case "ps": if (commandArray.length != 1) { - post("Incorrect usage of ps command. Usage: ps"); + post("Incorrect usage of ps command. Usage: ps"); return; } for (var i = 0; i < Player.getCurrentServer().runningScripts.length; i++) { post(Player.getCurrentServer().runningScripts[i]); } break; case "rm": - //TODO + if (commandArray.length != 2) { + post("Incorrect number of arguments. Usage: rm [program/script]"); return; + } + + //Check programs + var delTarget = commandArray[1]; + var s = Player.getCurrentServer(); + for (var i = 0; i < s.programs.length; ++i) { + if (s.programs[i] == delTarget) { + s.programs.splice(i, 1); + return; + } + } + + //Check scripts + for (var i = 0; i < s.scripts.length; ++i) { + if (s.scripts[i].filename == delTarget) { + //Check that the script isnt currently running + if (s.runningScripts.indexOf(delTarget) > -1) { + post("Cannot delete a script that is currently running!"); + } else { + s.scripts.splice(i, 1); + } + return; + } + } + + post("No such file exists"); break; case "run": //Run a program or a script