Implemented 'rm' command. FIxed some bugs

This commit is contained in:
Daniel Xie 2017-04-13 14:36:03 -05:00
parent 558939fd85
commit 685103c5d4
3 changed files with 32 additions and 4 deletions

@ -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

@ -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;
}

@ -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