Add installBackdoor

This commit is contained in:
Olivier Gagnon 2021-05-07 02:09:30 -04:00
parent 0642491402
commit 16c8c78b54
7 changed files with 59 additions and 15 deletions

File diff suppressed because one or more lines are too long

22
dist/vendor.bundle.js vendored

File diff suppressed because one or more lines are too long

@ -27,6 +27,7 @@ level 3, then you will be able to access all of the Singularity Functions.
getCurrentServer() <singularityfunctions/getCurrentServer> getCurrentServer() <singularityfunctions/getCurrentServer>
connect() <singularityfunctions/connect> connect() <singularityfunctions/connect>
manualHack() <singularityfunctions/manualHack> manualHack() <singularityfunctions/manualHack>
installBackdoor() <singularityfunctions/installBackdoor>
getPlayer() <singularityfunctions/getPlayer> getPlayer() <singularityfunctions/getPlayer>
hospitalize() <singularityfunctions/hospitalize> hospitalize() <singularityfunctions/hospitalize>
isBusy() <singularityfunctions/isBusy> isBusy() <singularityfunctions/isBusy>

@ -0,0 +1,22 @@
installBackdoor() Netscript Function
====================================
.. js:function:: installBackdoor()
:RAM cost: 2 GB
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 will install a backdoor on the server you are currently connected to.
Examples:
.. code-block:: javascript
connect("foodnstuff");
installBackdoor();
.. warning::
For NS2 users:
This function is async.

@ -186,6 +186,7 @@ export const RamCosts: IMap<any> = {
getCurrentServer: () => RamCostConstants.ScriptSingularityFn1RamCost, getCurrentServer: () => RamCostConstants.ScriptSingularityFn1RamCost,
connect: () => RamCostConstants.ScriptSingularityFn1RamCost, connect: () => RamCostConstants.ScriptSingularityFn1RamCost,
manualHack: () => RamCostConstants.ScriptSingularityFn1RamCost, manualHack: () => RamCostConstants.ScriptSingularityFn1RamCost,
installBackdoor: () => RamCostConstants.ScriptSingularityFn1RamCost,
getStats: () => RamCostConstants.ScriptSingularityFn1RamCost / 4, getStats: () => RamCostConstants.ScriptSingularityFn1RamCost / 4,
getCharacterInformation: () => RamCostConstants.ScriptSingularityFn1RamCost / 4, getCharacterInformation: () => RamCostConstants.ScriptSingularityFn1RamCost / 4,
getPlayer: () => RamCostConstants.ScriptSingularityFn1RamCost / 4, getPlayer: () => RamCostConstants.ScriptSingularityFn1RamCost / 4,

@ -2937,6 +2937,28 @@ function NetscriptFunctions(workerScript) {
const server = Player.getCurrentServer(); const server = Player.getCurrentServer();
return hack(server.hostname, true); return hack(server.hostname, true);
}, },
installBackdoor: function() {
updateDynamicRam("installBackdoor", getRamCost("installBackdoor"));
checkSingularityAccess("installBackdoor", 1);
const server = Player.getCurrentServer();
const installTime = calculateHackingTime(server, Player) / 4 * 1000;
// No root access or skill level too low
const canHack = netscriptCanHack(server, Player);
if (!canHack.res) {
throw makeRuntimeErrorMsg('installBackdoor', canHack.msg);
}
workerScript.log("installBackdoor", `Installing backdoor on '${server.hostname}' in ${convertTimeMsToTimeElapsedString(installTime, true)}`);
return netscriptDelay(installTime, workerScript).then(function() {
if (workerScript.env.stopFlag) {return Promise.reject(workerScript);}
workerScript.log("installBackdoor", `Successfully installed backdoor on '${server.hostname}'`);
server.backdoorInstalled = true;
return Promise.resolve();
});
},
getStats: function() { getStats: function() {
updateDynamicRam("getStats", getRamCost("getStats")); updateDynamicRam("getStats", getRamCost("getStats"));
checkSingularityAccess("getStats", 1); checkSingularityAccess("getStats", 1);

@ -20,7 +20,6 @@ export async function executeJSScript(scripts = [], workerScript) {
let urls = null; let urls = null;
let script = workerScript.getScript(); let script = workerScript.getScript();
if (shouldCompile(script, scripts)) { if (shouldCompile(script, scripts)) {
console.log("recompiling");
// The URL at the top is the one we want to import. It will // The URL at the top is the one we want to import. It will
// recursively import all the other modules in the urlStack. // recursively import all the other modules in the urlStack.
// //
@ -60,7 +59,6 @@ export async function executeJSScript(scripts = [], workerScript) {
*/ */
function shouldCompile(script, scripts) { function shouldCompile(script, scripts) {
if (script.module === "") return true; if (script.module === "") return true;
console.log(script.dependencies);
return script.dependencies.some(dep => { return script.dependencies.some(dep => {
const depScript = scripts.find(s => s.filename == dep.filename); const depScript = scripts.find(s => s.filename == dep.filename);