mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 20:25:45 +01:00
Added executeCommand netscript function
This commit is contained in:
parent
42e9a368b4
commit
1eddddd14f
21
doc/source/netscript/singularityfunctions/executeCommand.rst
Normal file
21
doc/source/netscript/singularityfunctions/executeCommand.rst
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
executeCommand() Netscript Function
|
||||||
|
========================================
|
||||||
|
|
||||||
|
.. js:function:: executeCommand(command)
|
||||||
|
|
||||||
|
:RAM cost: 4 GB
|
||||||
|
:param string commands: The full string of the command.
|
||||||
|
|
||||||
|
If you are not in BitNode-4, then you must have Level 1 of Source-File 4 in order to use this function.
|
||||||
|
|
||||||
|
This function writes the command to the terminal and executes it. This
|
||||||
|
can be used to perform manual hacks. Only one command can be sent at a time.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
.. code-block:: javascript
|
||||||
|
|
||||||
|
await ns.executeCommand('connect CSEC');
|
||||||
|
await ns.executeCommand('hack');
|
||||||
|
await ns.executeCommand('home');
|
||||||
|
// a manual hack will be performed and CSEC will invite you.
|
@ -176,6 +176,7 @@ export const RamCosts: IMap<any> = {
|
|||||||
travelToCity: () => RamCostConstants.ScriptSingularityFn1RamCost,
|
travelToCity: () => RamCostConstants.ScriptSingularityFn1RamCost,
|
||||||
purchaseTor: () => RamCostConstants.ScriptSingularityFn1RamCost,
|
purchaseTor: () => RamCostConstants.ScriptSingularityFn1RamCost,
|
||||||
purchaseProgram: () => RamCostConstants.ScriptSingularityFn1RamCost,
|
purchaseProgram: () => RamCostConstants.ScriptSingularityFn1RamCost,
|
||||||
|
executeCommand: () => RamCostConstants.ScriptSingularityFn1RamCost * 2,
|
||||||
getStats: () => RamCostConstants.ScriptSingularityFn1RamCost / 4,
|
getStats: () => RamCostConstants.ScriptSingularityFn1RamCost / 4,
|
||||||
getCharacterInformation: () => RamCostConstants.ScriptSingularityFn1RamCost / 4,
|
getCharacterInformation: () => RamCostConstants.ScriptSingularityFn1RamCost / 4,
|
||||||
isBusy: () => RamCostConstants.ScriptSingularityFn1RamCost / 4,
|
isBusy: () => RamCostConstants.ScriptSingularityFn1RamCost / 4,
|
||||||
|
@ -59,6 +59,7 @@ import {
|
|||||||
import { HacknetServer, MaxNumberHacknetServers } from "./Hacknet/HacknetServer";
|
import { HacknetServer, MaxNumberHacknetServers } from "./Hacknet/HacknetServer";
|
||||||
import { CityName } from "./Locations/data/CityNames";
|
import { CityName } from "./Locations/data/CityNames";
|
||||||
import { LocationName } from "./Locations/data/LocationNames";
|
import { LocationName } from "./Locations/data/LocationNames";
|
||||||
|
import { Terminal } from "./Terminal";
|
||||||
|
|
||||||
import { Message } from "./Message/Message";
|
import { Message } from "./Message/Message";
|
||||||
import { Messages } from "./Message/MessageHelpers";
|
import { Messages } from "./Message/MessageHelpers";
|
||||||
@ -537,23 +538,17 @@ function NetscriptFunctions(workerScript) {
|
|||||||
|
|
||||||
const runAfterReset = function(cbScript=null) {
|
const runAfterReset = function(cbScript=null) {
|
||||||
//Run a script after reset
|
//Run a script after reset
|
||||||
console.log(cbScript);
|
|
||||||
if (cbScript && isString(cbScript)) {
|
if (cbScript && isString(cbScript)) {
|
||||||
console.log('here');
|
|
||||||
const home = Player.getHomeComputer();
|
const home = Player.getHomeComputer();
|
||||||
for (const script of home.scripts) {
|
for (const script of home.scripts) {
|
||||||
console.log('here 2'+script);
|
|
||||||
if (script.filename === cbScript) {
|
if (script.filename === cbScript) {
|
||||||
console.log('here 3');
|
|
||||||
const ramUsage = script.ramUsage;
|
const ramUsage = script.ramUsage;
|
||||||
const ramAvailable = home.maxRam - home.ramUsed;
|
const ramAvailable = home.maxRam - home.ramUsed;
|
||||||
if (ramUsage > ramAvailable) {
|
if (ramUsage > ramAvailable) {
|
||||||
console.log('here 4');
|
|
||||||
return; // Not enough RAM
|
return; // Not enough RAM
|
||||||
}
|
}
|
||||||
const runningScriptObj = new RunningScript(script, []); // No args
|
const runningScriptObj = new RunningScript(script, []); // No args
|
||||||
runningScriptObj.threads = 1; // Only 1 thread
|
runningScriptObj.threads = 1; // Only 1 thread
|
||||||
console.log('running!');
|
|
||||||
startWorkerScript(runningScriptObj, home);
|
startWorkerScript(runningScriptObj, home);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2684,6 +2679,17 @@ function NetscriptFunctions(workerScript) {
|
|||||||
workerScript.log("purchaseProgram", `You have purchased the '${item.program}' program. The new program can be found on your home computer.`);
|
workerScript.log("purchaseProgram", `You have purchased the '${item.program}' program. The new program can be found on your home computer.`);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
executeCommand: function(command) {
|
||||||
|
updateDynamicRam("executeCommand", getRamCost("executeCommand"));
|
||||||
|
checkSingularityAccess("executeCommand", 1);
|
||||||
|
Terminal.executeCommand(command);
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
(function wait(){
|
||||||
|
if (!Terminal.hackFlag && !Terminal.analyzeFlag) return resolve();
|
||||||
|
setTimeout(wait, 30);
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
},
|
||||||
getStats: function() {
|
getStats: function() {
|
||||||
updateDynamicRam("getStats", getRamCost("getStats"));
|
updateDynamicRam("getStats", getRamCost("getStats"));
|
||||||
checkSingularityAccess("getStats", 1);
|
checkSingularityAccess("getStats", 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user