mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 20:25:45 +01:00
Added hasRootAccess() and getNumHacknetNodes commands to netscript
This commit is contained in:
parent
ea17334792
commit
6b40482e6c
@ -274,6 +274,9 @@ CONSTANTS = {
|
||||
"be used to run scripts located on the same server. Returns true if the script is successfully started, and false otherwise. Requires a significant amount " +
|
||||
"of RAM to run this command. Does NOT work while offline <br>Example: run('hack-foodnstuff.script'); <br> The example above will try and launch the 'hack-foodnstuff.script' script on " +
|
||||
"the current server, if it exists. <br><br>" +
|
||||
"<i>hasRootAccess(hostname/ip)</i><br> Returns a boolean (true or false) indicating whether or not the Player has root access to a server. " +
|
||||
"The argument passed in must be a string with either the hostname or IP of the target server. Does NOT work while offline.<br> " +
|
||||
"Example: if (hasRootAccess('foodnstuff') == false) {<br> nuke('foodnstuff');<br>}<br><br>" +
|
||||
"<i>getHackingLevel() </i><br> Returns the Player's current hacking level. Does NOT work while offline <br><br> " +
|
||||
"<i>getServerMoneyAvailable(hostname/ip)</i><br> Returns the amount of money available on a server. The argument passed in must be a string with either the " +
|
||||
"hostname or IP of the target server. Does NOT work while offline <br> Example: getServerMoneyAvailable('foodnstuff');<br><br>" +
|
||||
@ -290,6 +293,7 @@ CONSTANTS = {
|
||||
"};<br><br>" +
|
||||
"The example code above will attempt to purchase a new Hacknet Node. If the Hacknet Node is purchased, then it will " +
|
||||
"continuously try to level it up until it is leveled up 10 times. <br><br>" +
|
||||
"<i>getNumHacknetNodes()</i><br> returns the number of Hacknet Nodes that the Player owns. Does NOT work while offline<br><br>" +
|
||||
"<u><h1>While loops </h1></u><br>" +
|
||||
"A while loop is a control flow statement that repeatedly executes code as long as a condition is met. <br><br> " +
|
||||
"<i>while (<i>[cond]</i>) {<br> <i>[code]</i><br>}</i><br><br>" +
|
||||
|
@ -654,6 +654,27 @@ function evaluate(exp, workerScript) {
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
});
|
||||
} else if (exp.func.value == "hasRootAccess") {
|
||||
if (exp.args.length != 1) {
|
||||
reject("|"+workerScript.serverIp+"|"+workerScript.name+"|hasRootAccess() call has incorrect number of arguments. Takes 1 argument");
|
||||
return;
|
||||
}
|
||||
var ipPromise = evaluate(exp.args[0], workerScript);
|
||||
ipPromise.then(function(ip) {
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
setTimeout(function() {
|
||||
var server = getServer(ip);
|
||||
if (server == null) {
|
||||
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Invalid IP or hostname passed into hasRootAccess() command");
|
||||
workerScript.scriptRef.log("Cannot hasRootAccess(). Invalid IP or hostname passed in: " + ip);
|
||||
return;
|
||||
}
|
||||
workerScript.scriptRef.log("hasRootAccess() returned " + server.hasAdminRights);
|
||||
resolve(server.hasAdminRights);
|
||||
}, CONSTANTS.CodeInstructionRunTime);
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
});
|
||||
} else if (exp.func.value == "run") {
|
||||
if (exp.args.length != 1) {
|
||||
reject("|"+workerScript.serverIp+"|"+workerScript.name+"|run() call has incorrect number of arguments. Takes 1 argument");
|
||||
@ -661,6 +682,7 @@ function evaluate(exp, workerScript) {
|
||||
}
|
||||
var scriptNamePromise = evaluate(exp.args[0], workerScript);
|
||||
scriptNamePromise.then(function(scriptname) {
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
var serverIp = workerScript.serverIp;
|
||||
var scriptServer = AllServers[serverIp];
|
||||
if (scriptServer == null) {
|
||||
@ -684,6 +706,7 @@ function evaluate(exp, workerScript) {
|
||||
return;
|
||||
}
|
||||
setTimeout(function() {
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
Player.updateSkillLevels();
|
||||
workerScript.scriptRef.log("getHackingLevel() returned " + Player.hacking_skill);
|
||||
resolve(Player.hacking_skill);
|
||||
@ -771,6 +794,16 @@ function evaluate(exp, workerScript) {
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
});
|
||||
} else if (exp.func.value == "getNumHacknetNodes") {
|
||||
if (exp.args.length != 0) {
|
||||
reject("|"+workerScript.serverIp+"|"+workerScript.name+"|getNumHacknetNodes() call has incorrect number of arguments. Takes 0 arguments");
|
||||
return;
|
||||
}
|
||||
setTimeout(function() {
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
workerScript.scriptRef.log("getNumHacknetNodes() returned " + Player.hacknetNodes.length);
|
||||
resolve(Player.hacknetNodes.length);
|
||||
}, CONSTANTS.CodeInstructionRunTime);
|
||||
}
|
||||
}, CONSTANTS.CodeInstructionRunTime);
|
||||
});
|
||||
@ -990,7 +1023,7 @@ function apply_op(op, a, b) {
|
||||
return x;
|
||||
}
|
||||
switch (op) {
|
||||
case "+": return num(a) + num(b);
|
||||
case "+": return a + b;
|
||||
case "-": return num(a) - num(b);
|
||||
case "*": return num(a) * num(b);
|
||||
case "/": return num(a) / div(b);
|
||||
|
@ -849,9 +849,9 @@ var Terminal = {
|
||||
post("<strong>" + serv.hostname + "</strong>");
|
||||
var c = "N";
|
||||
if (serv.hasAdminRights) {c = "Y";}
|
||||
post("----Root Access: " + c);
|
||||
post("----Required hacking skill: " + serv.requiredHackingSkill);
|
||||
post("----Number open ports required to NUKE: " + serv.numOpenPortsRequired);
|
||||
post("--Root Access: " + c);
|
||||
post("--Required hacking skill: " + serv.requiredHackingSkill);
|
||||
post("--Number open ports required to NUKE: " + serv.numOpenPortsRequired);
|
||||
post(" ");
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user