2016-11-30 23:08:21 +01:00
|
|
|
function TestObj() {
|
2016-12-01 23:18:18 +01:00
|
|
|
this.num = 1;
|
2016-11-30 23:08:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TestObj.prototype.setValue = function(val) {
|
2016-12-01 23:18:18 +01:00
|
|
|
this.num = val;
|
2016-11-30 23:08:21 +01:00
|
|
|
}
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
TestObj.prototype.toJSON = function() {
|
|
|
|
console.log("toJSON() called");
|
|
|
|
return Generic_toJSON("TestObj", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
TestObj.fromJSON = function(value) {
|
|
|
|
console.log("fromJSON() called");
|
|
|
|
return Generic_fromJSON(TestObj, value.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
Reviver.constructors.TestObj = TestObj;
|
|
|
|
|
2016-11-30 23:08:21 +01:00
|
|
|
var testObj = new TestObj();
|
|
|
|
|
2016-10-17 10:24:39 +02:00
|
|
|
//Terminal
|
|
|
|
var post = function(input) {
|
2016-11-01 06:30:59 +01:00
|
|
|
$("#terminal-input").before('<tr class="posted"><td style="color: #66ff33;">' + input.replace( / /g, " " ) + '</td></tr>');
|
2016-10-17 10:24:39 +02:00
|
|
|
window.scrollTo(0, document.body.scrollHeight);
|
|
|
|
}
|
|
|
|
|
2016-10-27 05:34:18 +02:00
|
|
|
//Same thing as post but the td cells have ids so they can be animated for the hack progress bar
|
|
|
|
var hackProgressBarPost = function(input) {
|
|
|
|
$("#terminal-input").before('<tr class="posted"><td id="hack-progress-bar" style="color: #66ff33;">' + input + '</td></tr>');
|
|
|
|
window.scrollTo(0, document.body.scrollHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
var hackProgressPost = function(input) {
|
|
|
|
$("#terminal-input").before('<tr class="posted"><td id="hack-progress" style="color: #66ff33;">' + input + '</td></tr>');
|
|
|
|
window.scrollTo(0, document.body.scrollHeight);
|
|
|
|
}
|
|
|
|
|
2016-10-20 23:11:01 +02:00
|
|
|
var postNetburnerText = function() {
|
|
|
|
post("Netburner v1.0");
|
|
|
|
}
|
|
|
|
|
2016-11-24 23:30:33 +01:00
|
|
|
//Defines what happens when enter is pressed (keycode 13)
|
2016-10-17 10:24:39 +02:00
|
|
|
$(document).keyup(function(event) {
|
2016-11-24 23:30:33 +01:00
|
|
|
//Terminal
|
|
|
|
if (Engine.currentPage == Engine.Page.Terminal) {
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
var command = $('input[class=terminal-input]').val();
|
|
|
|
if (command.length > 0) {
|
|
|
|
post("> " + command);
|
|
|
|
|
|
|
|
//TODO Do i have to switch the order of these two?
|
|
|
|
Terminal.executeCommand(command);
|
|
|
|
$('input[class=terminal-input]').val("");
|
|
|
|
}
|
2016-10-17 10:24:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-24 23:30:33 +01:00
|
|
|
//Keep terminal in focus
|
|
|
|
$(document).ready(function() {
|
|
|
|
if (Engine.currentPage == Engine.Page.Terminal) {
|
|
|
|
$('.terminal-input').focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(document).keydown(function() {
|
|
|
|
if (Engine.currentPage == Engine.Page.Terminal) {
|
|
|
|
$('.terminal-input').focus();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-10-20 20:26:38 +02:00
|
|
|
var Terminal = {
|
2016-11-01 06:30:59 +01:00
|
|
|
//Flags to determine whether the player is currently running a hack or an analyze
|
|
|
|
hackFlag: false,
|
|
|
|
analyzeFlag: false,
|
|
|
|
|
|
|
|
finishAction: function() {
|
|
|
|
if (Terminal.hackFlag) {
|
|
|
|
Terminal.finishHack();
|
|
|
|
} else if (Terminal.analyzeFlag) {
|
|
|
|
Terminal.finishAnalyze();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//Complete the hack/analyze command
|
2016-10-27 20:26:00 +02:00
|
|
|
finishHack: function() {
|
2016-11-01 06:30:59 +01:00
|
|
|
console.log("Hack done. Determining success/failure of hack. Re-enabling terminal and changing the id of the hack progress bar");
|
|
|
|
|
|
|
|
//Calculate whether hack was successful
|
|
|
|
var hackChance = Player.calculateHackingChance();
|
|
|
|
var rand = Math.random();
|
|
|
|
console.log("Hack success chance: " + hackChance + ", rand: " + rand);
|
|
|
|
var expGainedOnSuccess = Player.calculateExpGain();
|
|
|
|
var expGainedOnFailure = Math.round(expGainedOnSuccess / 4);
|
|
|
|
if (rand < hackChance) { //Success!
|
|
|
|
var moneyGained = Player.calculatePercentMoneyHacked();
|
2016-12-01 23:18:18 +01:00
|
|
|
moneyGained = Math.floor(Player.getCurrentServer().moneyAvailable * moneyGained);
|
2016-11-01 06:30:59 +01:00
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
Player.getCurrentServer().moneyAvailable -= moneyGained;
|
2016-11-01 06:30:59 +01:00
|
|
|
Player.money += moneyGained;
|
|
|
|
|
|
|
|
Player.hacking_exp += expGainedOnSuccess;
|
|
|
|
|
|
|
|
post("Hack successful! Gained $" + moneyGained + " and " + expGainedOnSuccess + " hacking EXP");
|
|
|
|
} else { //Failure
|
|
|
|
//Player only gains 25% exp for failure? TODO Can change this later to balance
|
|
|
|
Player.hacking_exp += expGainedOnFailure;
|
2016-12-01 23:18:18 +01:00
|
|
|
post("Failed to hack " + Player.getCurrentServer().hostname + ". Gained " + expGainedOnFailure + " hacking EXP");
|
2016-11-01 06:30:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Rename the progress bar so that the next hacks dont trigger it. Re-enable terminal
|
|
|
|
$("#hack-progress-bar").attr('id', "old-hack-progress-bar");
|
|
|
|
$("#hack-progress").attr('id', "old-hack-progress");
|
|
|
|
document.getElementById("terminal-input-td").innerHTML = '$ <input type="text" class="terminal-input"/>';
|
|
|
|
$('input[class=terminal-input]').prop('disabled', false);
|
|
|
|
|
|
|
|
Terminal.hackFlag = false;
|
2016-10-27 20:26:00 +02:00
|
|
|
},
|
2016-11-01 06:30:59 +01:00
|
|
|
|
|
|
|
finishAnalyze: function() {
|
2016-12-01 23:18:18 +01:00
|
|
|
post(Player.getCurrentServer().hostname + ": ");
|
|
|
|
post("Required hacking skill: " + Player.getCurrentServer().requiredHackingSkill);
|
2016-11-01 06:30:59 +01:00
|
|
|
//TODO Make these actual estimates by adding a random offset to result?
|
|
|
|
//TODO Change the text to sound better
|
|
|
|
post("Estimated chance to hack: " + Math.round(Player.calculateHackingChance() * 100) + "%");
|
|
|
|
post("Estimated time to hack: " + Math.round(Player.calculateHackingTime()) + " seconds");
|
2016-12-01 23:18:18 +01:00
|
|
|
post("Required number of open ports for PortHack: " +Player.getCurrentServer().numOpenPortsRequired);
|
|
|
|
if (Player.getCurrentServer().sshPortOpen) {
|
2016-11-01 06:30:59 +01:00
|
|
|
post("SSH port: Open")
|
|
|
|
} else {
|
|
|
|
post("SSH port: Closed")
|
|
|
|
}
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
if (Player.getCurrentServer().ftpPortOpen) {
|
2016-11-01 06:30:59 +01:00
|
|
|
post("FTP port: Open")
|
|
|
|
} else {
|
|
|
|
post("FTP port: Closed")
|
|
|
|
}
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
if (Player.getCurrentServer().smtpPortOpen) {
|
2016-11-01 06:30:59 +01:00
|
|
|
post("SMTP port: Open")
|
|
|
|
} else {
|
|
|
|
post("SMTP port: Closed")
|
|
|
|
}
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
if (Player.getCurrentServer().httpPortOpen) {
|
2016-11-01 06:30:59 +01:00
|
|
|
post("HTTP port: Open")
|
|
|
|
} else {
|
|
|
|
post("HTTP port: Closed")
|
|
|
|
}
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
if (Player.getCurrentServer().sqlPortOpen) {
|
2016-11-01 06:30:59 +01:00
|
|
|
post("SQL port: Open")
|
|
|
|
} else {
|
|
|
|
post("SQL port: Closed")
|
|
|
|
}
|
|
|
|
Terminal.analyzeFlag = false;
|
2016-11-21 07:11:14 +01:00
|
|
|
|
|
|
|
//Rename the progress bar so that the next hacks dont trigger it. Re-enable terminal
|
|
|
|
$("#hack-progress-bar").attr('id', "old-hack-progress-bar");
|
|
|
|
$("#hack-progress").attr('id', "old-hack-progress");
|
|
|
|
document.getElementById("terminal-input-td").innerHTML = '$ <input type="text" class="terminal-input"/>';
|
|
|
|
$('input[class=terminal-input]').prop('disabled', false);
|
2016-11-01 06:30:59 +01:00
|
|
|
},
|
2016-10-27 20:26:00 +02:00
|
|
|
|
2016-10-20 20:26:38 +02:00
|
|
|
executeCommand: function(command) {
|
2016-10-24 09:18:01 +02:00
|
|
|
var commandArray = command.split(" ");
|
2016-10-20 20:26:38 +02:00
|
|
|
|
|
|
|
if (commandArray.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (commandArray[0]) {
|
|
|
|
case "analyze":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of analyze command. Usage: analyze"); return;
|
|
|
|
}
|
2016-11-01 06:30:59 +01:00
|
|
|
//Analyze the current server for information
|
|
|
|
console.log("analyze terminal command called");
|
|
|
|
Terminal.analyzeFlag = true;
|
|
|
|
post("Analyzing system...");
|
|
|
|
hackProgressPost("Time left:");
|
|
|
|
hackProgressBarPost("[");
|
|
|
|
Player.analyze();
|
|
|
|
|
|
|
|
//Disable terminal
|
|
|
|
console.log("Disabling terminal");
|
|
|
|
document.getElementById("terminal-input-td").innerHTML = '<input type="text" class="terminal-input"/>';
|
|
|
|
$('input[class=terminal-input]').prop('disabled', true);
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "clear":
|
|
|
|
case "cls":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of clear/cls command. Usage: clear/cls"); return;
|
|
|
|
}
|
2016-10-24 08:34:04 +02:00
|
|
|
console.log("cls/clear terminal command called");
|
2016-10-20 23:11:01 +02:00
|
|
|
$("#terminal tr:not(:last)").remove();
|
|
|
|
postNetburnerText();
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "connect":
|
2016-10-24 08:34:04 +02:00
|
|
|
case "telnet":
|
2016-10-27 20:26:00 +02:00
|
|
|
//Disconnect from current server in terminal and connect to new one
|
2016-10-24 08:34:04 +02:00
|
|
|
if (commandArray.length != 2) {
|
2016-10-24 23:16:51 +02:00
|
|
|
post("Incorrect usage of connect/telnet command. Usage: connect/telnet [ip/hostname]");
|
2016-10-24 08:34:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ip = commandArray[1];
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().serversOnNetwork.length; i++) {
|
|
|
|
if (Player.getCurrentServer().getServerOnNetwork(i).ip == ip || Player.getCurrentServer().getServerOnNetwork(i).hostname == ip) {
|
|
|
|
Player.getCurrentServer().isConnectedTo = false;
|
|
|
|
Player.currentServer = Player.getCurrentServer().getServerOnNetwork(i).ip;
|
2016-10-24 09:18:01 +02:00
|
|
|
post("Connected to " + ip);
|
2016-10-24 08:34:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-24 09:18:01 +02:00
|
|
|
post("Host not found");
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
2016-12-01 23:18:18 +01:00
|
|
|
case "free":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
2016-12-05 23:31:46 +01:00
|
|
|
post("Incorrect usage of free command. Usage: free"); return;
|
2016-11-24 23:30:33 +01:00
|
|
|
}
|
2016-12-05 23:31:46 +01:00
|
|
|
console.log("free terminal command called");
|
2016-12-01 23:18:18 +01:00
|
|
|
post("Total: " + Player.getCurrentServer().maxRam.toString() + " GB");
|
|
|
|
post("Used: " + Player.getCurrentServer().ramUsed.toString() + " GB");
|
|
|
|
post("Available: " + (Player.getCurrentServer().maxRam - Player.getCurrentServer().ramUsed).toString() + " GB");
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "hack":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of hack command. Usage: hack"); return;
|
|
|
|
}
|
2016-10-27 20:26:00 +02:00
|
|
|
//Hack the current PC (usually for money)
|
2016-10-20 20:26:38 +02:00
|
|
|
//You can't hack your home pc or servers you purchased
|
2016-12-01 23:18:18 +01:00
|
|
|
if (Player.getCurrentServer().purchasedByPlayer) {
|
2016-10-20 20:26:38 +02:00
|
|
|
post("Cannot hack your own machines! You are currently connected to your home PC or one of your purchased servers");
|
2016-12-01 23:18:18 +01:00
|
|
|
} else if (Player.getCurrentServer().hasAdminRights == false ) {
|
2016-10-20 23:34:21 +02:00
|
|
|
post("You do not have admin rights for this machine! Cannot hack");
|
2016-12-01 23:18:18 +01:00
|
|
|
} else if (Player.getCurrentServer().requiredHackingSkill > Player.hacking_skill) {
|
2016-10-24 23:16:51 +02:00
|
|
|
post("Your hacking skill is not high enough to attempt hacking this machine. Try analyzing the machine to determine the required hacking skill");
|
2016-10-20 20:26:38 +02:00
|
|
|
} else {
|
2016-11-01 06:30:59 +01:00
|
|
|
Terminal.hackFlag = true;
|
2016-10-27 05:34:18 +02:00
|
|
|
hackProgressPost("Time left:");
|
|
|
|
hackProgressBarPost("[");
|
2016-11-01 06:30:59 +01:00
|
|
|
Player.hack();
|
2016-10-27 20:26:00 +02:00
|
|
|
|
|
|
|
//Disable terminal
|
|
|
|
console.log("Disabling terminal");
|
|
|
|
document.getElementById("terminal-input-td").innerHTML = '<input type="text" class="terminal-input"/>';
|
|
|
|
$('input[class=terminal-input]').prop('disabled', true);
|
2016-10-20 20:26:38 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "help":
|
|
|
|
//TODO
|
|
|
|
break;
|
|
|
|
case "hostname":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of hostname command. Usage: hostname"); return;
|
|
|
|
}
|
2016-10-20 20:26:38 +02:00
|
|
|
//Print the hostname of current system
|
2016-12-01 23:18:18 +01:00
|
|
|
post(Player.getCurrentServer().hostname);
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "ifconfig":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of ifconfig command. Usage: ifconfig"); return;
|
|
|
|
}
|
2016-10-20 20:26:38 +02:00
|
|
|
//Print the IP address of the current system
|
2016-12-01 23:18:18 +01:00
|
|
|
post(Player.getCurrentServer().ip);
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "kill":
|
2016-12-06 19:09:23 +01:00
|
|
|
if (commandArray.length != 2) {
|
|
|
|
post("Incorrect usage of kill command. Usage: kill [scriptname]"); return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var scriptName = commandArray[1];
|
|
|
|
for (var i = 0; i < Player.getCurrentServer().runningScripts.length; i++) {
|
|
|
|
if (Player.getCurrentServer().runningScripts[i] == scriptName) {
|
|
|
|
Player.getCurrentServer().runningScripts.splice(i, 1);
|
|
|
|
|
|
|
|
killWorkerScript(scriptName, Player.getCurrentServer().ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
post("No such script is running. Nothing to kill");
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "ls":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of ls command. Usage: ls"); return;
|
|
|
|
}
|
|
|
|
|
2016-10-27 20:26:00 +02:00
|
|
|
//Display all programs and scripts
|
|
|
|
var allFiles = [];
|
|
|
|
|
|
|
|
//Get all of the programs and scripts on the machine into one temporary array
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().programs.length; i++) {
|
|
|
|
allFiles.push(Player.getCurrentServer().programs[i]);
|
2016-10-27 20:26:00 +02:00
|
|
|
}
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().scripts.length; i++) {
|
|
|
|
allFiles.push(Player.getCurrentServer().scripts[i].filename);
|
2016-10-27 20:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Sort the files alphabetically then print each
|
|
|
|
allFiles.sort();
|
|
|
|
|
|
|
|
for (var i = 0; i < allFiles.length; i++) {
|
|
|
|
post(allFiles[i]);
|
|
|
|
}
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
2016-11-24 23:30:33 +01:00
|
|
|
case "nano":
|
|
|
|
if (commandArray.length != 2) {
|
|
|
|
post("Incorrect usage of nano command. Usage: nano [scriptname]"); return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var filename = commandArray[1];
|
|
|
|
|
|
|
|
//Can only edit script files
|
|
|
|
if (filename.endsWith(".script") == false) {
|
|
|
|
post("Error: Only .script files are editable with nano (filename must end with .scrip)"); return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Script name is the filename without the .script at the end
|
|
|
|
var scriptname = filename.substr(0, filename.indexOf(".script"));
|
|
|
|
|
|
|
|
//Cannot edit scripts that are currently running
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().runningScripts.length; i++) {
|
|
|
|
if (filename == Player.getCurrentServer().runningScripts[i].filename) {
|
2016-11-24 23:30:33 +01:00
|
|
|
post("Cannot open/edit scripts that are currently running!"); return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check if the script already exists
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().scripts.length; i++) {
|
|
|
|
if (filename == Player.getCurrentServer().scripts[i].filename) {
|
|
|
|
Engine.loadScriptEditorContent(scriptname, Player.getCurrentServer().scripts[i].code);
|
2016-11-24 23:30:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Engine.loadScriptEditorContent(scriptname, "");
|
|
|
|
break;
|
2016-10-20 20:26:38 +02:00
|
|
|
case "netstat":
|
|
|
|
case "scan":
|
2016-10-24 08:34:04 +02:00
|
|
|
if (commandArray.length != 1) {
|
2016-11-24 23:30:33 +01:00
|
|
|
post("Incorrect usage of netstat/scan command. Usage: netstat/scan"); return;
|
2016-10-24 08:34:04 +02:00
|
|
|
}
|
|
|
|
//Displays available network connections using TCP
|
|
|
|
console.log("netstat/scan terminal command called");
|
2016-11-01 06:30:59 +01:00
|
|
|
post("Hostname IP Root Access");
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().serversOnNetwork.length; i++) {
|
2016-11-01 06:30:59 +01:00
|
|
|
//Add hostname
|
2016-12-01 23:18:18 +01:00
|
|
|
var entry = Player.getCurrentServer().getServerOnNetwork(i).hostname;
|
2016-11-01 06:30:59 +01:00
|
|
|
|
|
|
|
//Calculate padding and add IP
|
|
|
|
var numSpaces = 21 - entry.length;
|
|
|
|
var spaces = Array(numSpaces+1).join(" ");
|
|
|
|
entry += spaces;
|
2016-12-01 23:18:18 +01:00
|
|
|
entry += Player.getCurrentServer().getServerOnNetwork(i).ip;
|
2016-11-01 06:30:59 +01:00
|
|
|
|
|
|
|
//Calculate padding and add root access info
|
|
|
|
var hasRoot;
|
2016-12-01 23:18:18 +01:00
|
|
|
if (Player.getCurrentServer().getServerOnNetwork(i).hasAdminRights) {
|
2016-11-01 06:30:59 +01:00
|
|
|
hasRoot = 'Y';
|
|
|
|
} else {
|
|
|
|
hasRoot = 'N';
|
|
|
|
}
|
2016-12-01 23:18:18 +01:00
|
|
|
numSpaces = 21 - Player.getCurrentServer().getServerOnNetwork(i).ip.length;
|
2016-11-01 06:30:59 +01:00
|
|
|
spaces = Array(numSpaces+1).join(" ");
|
|
|
|
entry += spaces;
|
|
|
|
entry += hasRoot;
|
|
|
|
post(entry);
|
2016-10-24 08:34:04 +02:00
|
|
|
}
|
2016-11-24 23:30:33 +01:00
|
|
|
break;
|
2016-10-20 20:26:38 +02:00
|
|
|
case "ps":
|
2016-12-05 23:31:46 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of ps command. Usage: ps");
|
|
|
|
}
|
|
|
|
for (var i = 0; i < Player.getCurrentServer().runningScripts.length; i++) {
|
|
|
|
post(Player.getCurrentServer().runningScripts[i]);
|
|
|
|
}
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "rm":
|
|
|
|
//TODO
|
|
|
|
break;
|
|
|
|
case "run":
|
2016-10-24 23:16:51 +02:00
|
|
|
//Run a program or a script
|
|
|
|
if (commandArray.length == 1) {
|
|
|
|
post("No program specified to run. Usage: run [program/script]");
|
|
|
|
} else if (commandArray.length > 2) {
|
|
|
|
post("Too many arguments. Usage: run [program/script]");
|
|
|
|
} else {
|
|
|
|
var executableName = commandArray[1];
|
|
|
|
//Check if its a script or just a program/executable
|
|
|
|
if (executableName.indexOf(".script") == -1) {
|
|
|
|
//Not a script
|
|
|
|
Terminal.runProgram(executableName);
|
|
|
|
} else {
|
|
|
|
//Script
|
|
|
|
Terminal.runScript(executableName);
|
|
|
|
}
|
|
|
|
}
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "scp":
|
|
|
|
//TODO
|
|
|
|
break;
|
2016-12-02 22:57:20 +01:00
|
|
|
case "tail":
|
|
|
|
break;
|
2016-12-01 23:18:18 +01:00
|
|
|
case "top":
|
|
|
|
//TODO List each's script RAM usage
|
|
|
|
break;
|
2016-11-17 23:25:40 +01:00
|
|
|
case "test":
|
2016-12-01 23:18:18 +01:00
|
|
|
post(testObj.num.toString());
|
|
|
|
testObj.setValue(testObj.num + 1);
|
2016-11-30 23:08:21 +01:00
|
|
|
break;
|
|
|
|
case "testSave":
|
2016-12-01 23:18:18 +01:00
|
|
|
var testSave = JSON.stringify(testObj);
|
2016-11-30 23:08:21 +01:00
|
|
|
window.localStorage.setItem("netburnerTest", testSave);
|
|
|
|
console.log("Netburner TestSave saved");
|
|
|
|
break;
|
|
|
|
case "testLoad":
|
|
|
|
if (!window.localStorage.getItem("netburnerTest")) {
|
|
|
|
console.log("No TestSave file to load");
|
|
|
|
} else {
|
2016-12-01 23:18:18 +01:00
|
|
|
console.log("Here");
|
2016-11-30 23:08:21 +01:00
|
|
|
var testSave = window.localStorage.getItem("netburnerTest");
|
2016-12-01 23:18:18 +01:00
|
|
|
testObj = JSON.parse(testSave, Reviver);
|
2016-11-30 23:08:21 +01:00
|
|
|
console.log("TestSave loaded");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "testDelete":
|
|
|
|
if (!window.localStorage.getItem("netburnetTest")) {
|
|
|
|
console.log("No TestSave file to delete");
|
|
|
|
} else {
|
|
|
|
window.localStorage.removeItem("netburnerTest");
|
|
|
|
console.log("TestSave deleted");
|
|
|
|
}
|
2016-11-17 23:25:40 +01:00
|
|
|
break;
|
2016-10-20 20:26:38 +02:00
|
|
|
default:
|
2016-10-24 08:34:04 +02:00
|
|
|
post("Command not found");
|
2016-10-20 20:26:38 +02:00
|
|
|
}
|
|
|
|
},
|
2016-10-17 23:23:23 +02:00
|
|
|
|
2016-10-27 20:26:00 +02:00
|
|
|
//First called when the "run [program]" command is called. Checks to see if you
|
|
|
|
//have the executable and, if you do, calls the executeProgram() function
|
2016-10-20 20:26:38 +02:00
|
|
|
runProgram: function(programName) {
|
2016-10-27 20:26:00 +02:00
|
|
|
//Check if you have the program on your computer. If you do, execute it, otherwise
|
|
|
|
//display an error message
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getHomeComputer().programs.length; i++) {
|
|
|
|
if (Player.getHomeComputer().programs[i] == programName) {
|
2016-10-27 20:26:00 +02:00
|
|
|
Terminal.executeProgram(programName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 23:02:06 +01:00
|
|
|
post("ERROR: No such executable on home computer (Programs can only be run from home computer)");
|
2016-10-27 20:26:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
//Contains the implementations of all possible programs
|
|
|
|
executeProgram: function(programName) {
|
2016-10-24 23:16:51 +02:00
|
|
|
switch (programName) {
|
2016-10-27 20:26:00 +02:00
|
|
|
case "PortHack.exe":
|
2016-12-01 23:18:18 +01:00
|
|
|
if (Player.getCurrentServer().hasAdminRights) {
|
2016-10-27 20:26:00 +02:00
|
|
|
post("You already have root access to this computer. There is no reason to run PortHack.exe");
|
2016-10-24 23:16:51 +02:00
|
|
|
} else {
|
2016-10-27 20:26:00 +02:00
|
|
|
console.log("Running PortHack executable");
|
2016-12-01 23:18:18 +01:00
|
|
|
if (Player.getCurrentServer().openPortCount >= Player.getCurrentServer().numOpenPortsRequired) {
|
|
|
|
Player.getCurrentServer().hasAdminRights = true;
|
|
|
|
post("PortHack successful! Gained root access to " + Player.getCurrentServer().hostname);
|
2016-10-27 20:26:00 +02:00
|
|
|
//TODO Make this take time rather than be instant
|
|
|
|
} else {
|
|
|
|
post("PortHack unsuccessful. Not enough ports have been opened");
|
|
|
|
}
|
2016-10-24 23:16:51 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
post("Executable not found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
2016-10-20 20:26:38 +02:00
|
|
|
|
2016-10-24 23:16:51 +02:00
|
|
|
runScript: function(scriptName) {
|
2016-11-28 23:02:06 +01:00
|
|
|
//Check if this script is already running
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().runningScripts.length; i++) {
|
|
|
|
if (Player.getCurrentServer().runningScripts[i] == scriptName) {
|
2016-11-28 23:02:06 +01:00
|
|
|
post("ERROR: This script is already running. Cannot run multiple instances");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check if the script exists and if it does run it
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().scripts.length; i++) {
|
|
|
|
if (Player.getCurrentServer().scripts[i].filename == scriptName) {
|
|
|
|
if (Player.getCurrentServer().hasAdminRights == false) {
|
2016-11-28 23:02:06 +01:00
|
|
|
post("Need root access to run script");
|
|
|
|
} else {
|
2016-12-01 23:18:18 +01:00
|
|
|
var filename = Player.getCurrentServer().scripts[i].filename;
|
2016-11-30 00:38:50 +01:00
|
|
|
|
|
|
|
//Add to current server's runningScripts
|
2016-12-01 23:18:18 +01:00
|
|
|
Player.getCurrentServer().runningScripts.push(filename)
|
2016-11-30 00:38:50 +01:00
|
|
|
|
|
|
|
//Create WorkerScript
|
2016-11-28 23:13:13 +01:00
|
|
|
var s = new WorkerScript();
|
2016-11-30 00:38:50 +01:00
|
|
|
s.name = filename;
|
2016-12-01 23:18:18 +01:00
|
|
|
s.code = Player.getCurrentServer().scripts[i].code;
|
2016-12-02 22:57:20 +01:00
|
|
|
s.serverIp = Player.getCurrentServer().ip;
|
2016-11-28 23:13:13 +01:00
|
|
|
workerScripts.push(s);
|
|
|
|
console.log("Pushed script onto workerScripts");
|
2016-11-29 23:56:05 +01:00
|
|
|
return;
|
2016-11-28 23:02:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-24 23:16:51 +02:00
|
|
|
|
2016-11-28 23:02:06 +01:00
|
|
|
post("ERROR: No such script");
|
2016-10-20 20:26:38 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|