Bitburner

Bitburner

檢視統計資料:
wickered 2022 年 1 月 10 日 上午 10:22
Scripting backdoors - trying to work out how it SHOULD work
Okay, so, the singularity function installBackdoor() only backdoors the server you're currently connected to through the terminal, so the tricky part is scripting the connect() function to get you to every single server at least once.

I can figure out the code, but I'm struggling with how to accomplish this task most effectively.

I've currently got 4 nested FOR loops to backdoor up to four connections out. First home is scanned to get an array of what connects to it, then each of those is scanned to get an array that updates for each of those, etc. Starting with the second loop I additionally verify I'm not backtracking through previous connections.
I push servers I've successfully backdoored into an array and use .include to verify I'm not repeating work, but there's got to be a better way to spider through all connections besides over a dozen FOR loops.
...but I can't think of it. This definitely feels like the most inefficient way to accomplish the goal of backdooring everything and my general strategy to programming is to make it work before I make it "good" but this has quickly become exhausting.

Can anyone suggest a different way to approach the problem?

...and I know I don't NEED to backdoor everything, but I want to, so yeah.
引用自 Af&Fix:
I don't have a sf4, but a have some good idea for semi-efficient mass backdor.
I have this script which returns me a path to destinated host via array.
function pathFind(ns, target) { let nestArr = []; nestArr.push(target); while (nestArr[nestArr.length - 1] != 'home') { nestArr.push(ns.scan(nestArr[nestArr.length - 1])[0]); } nestArr = nestArr.reverse(); return nestArr; }

So, you can run this path finder for each server and then you can connect and install backdoors on the way to the endpoint. Also make another array to track already installed backdoors, so you will skip them afterwards. Something like this:
function backdoorAll(ns) { let servs = [Here is your list of servers]; let installedBackdors = []; servs.forEach(function (hostname) { let pathArray = pathFind(ns, hostname); pathArray.forEach(function (nestedHost) { ns.connect(nestedHost); if (!installedBackdors.includes(nestedHost) && nestedHost != 'home') { await ns.installBackdoor(); installedBackdors.push(nestedHost); } }); //in case you cannot directly go to home after pathArray.reverse().forEach(function (prevHost) { ns.connect(prevHost); }); }); }
Not really optimal, but relatively straightforward and simple
< >
目前顯示第 31-39 則留言,共 39
Af&Fix 2022 年 1 月 13 日 下午 1:20 
引用自 tclord
引用自 Af&Fix
Wow, chill guys, it's just a game with programming feature, not a ♥♥♥♥♥♥♥ production integration project. It's meant to be experimented with, some features are intentionally descret or obscure, that's a fun part of the game to figure it out

I just provide this information for those who would appreciate learning this lesson the easy way instead of the hard way, because I can tell you from experience, the hard way isn't fun.
I honestly don't even understand what's your position, so ok man
Suikoudan 2022 年 1 月 13 日 下午 2:22 
引用自 Af&Fix
引用自 tclord

I just provide this information for those who would appreciate learning this lesson the easy way instead of the hard way, because I can tell you from experience, the hard way isn't fun.
I honestly don't even understand what's your position, so ok man

This might just be adding oil to the flames, but I'll try to explain the problem anyway.

There is nothing worse than spending a whole week going through your code to find out why it randomly stops working at seemingly unrelated moments, only to find out that it was caused by an update in some third party library that "fixed" a known bug. I actually know someone that reintroduced a bug to his code, because too many parties complained that his "undocumented feature" stopped working.

Trust me, if you don't have to, don't rely on things that are not documented as features. I'm not trying to say that you have to write perfect code or anything, I'm justing asking you to think about the pros and cons of the choices you make. If in the end you still want to do it the way you have been doing, that's perfectly fine, but at least you will have had the chance to make that choice (I'm starting to sound really cheesy right now, so I'm going to stop here before it gets any worse).
Af&Fix 2022 年 1 月 13 日 下午 10:17 
引用自 Suikoudan
引用自 Af&Fix
I honestly don't even understand what's your position, so ok man

This might just be adding oil to the flames, but I'll try to explain the problem anyway.

There is nothing worse than spending a whole week going through your code to find out why it randomly stops working at seemingly unrelated moments, only to find out that it was caused by an update in some third party library that "fixed" a known bug. I actually know someone that reintroduced a bug to his code, because too many parties complained that his "undocumented feature" stopped working.

Trust me, if you don't have to, don't rely on things that are not documented as features. I'm not trying to say that you have to write perfect code or anything, I'm justing asking you to think about the pros and cons of the choices you make. If in the end you still want to do it the way you have been doing, that's perfectly fine, but at least you will have had the chance to make that choice (I'm starting to sound really cheesy right now, so I'm going to stop here before it gets any worse).
No offense, but that statement is as insitfull, as "memento mori". You do not have any bases to trust that your documented features won't change the same way, that you are describing. I not saying that you are wrong, of course you should be mindfull of what you are doing, but that's doesn't have translation to concrete actions, so it's just more of a spook out of experience which is subjective.
Suikoudan 2022 年 1 月 14 日 上午 1:44 
引用自 Af&Fix
No offense, but that statement is as insitfull, as "memento mori". You do not have any bases to trust that your documented features won't change the same way, that you are describing. I not saying that you are wrong, of course you should be mindfull of what you are doing, but that's doesn't have translation to concrete actions, so it's just more of a spook out of experience which is subjective.

No offense taken. Usually (and now I am taking in my work experience, which is indeed 100% subjective) there is an unspoken rule about not changing documented functions (or when you are doing so, leaving the old function there for an entire major version, adding an @deprecated to the function signature and notifying people of this in changelogs).

But you are correct that nothing is stopping people from changing documented features in the same way that I am describing could happen to undocumented features. It's just that my experience is that it is a bigger issue if something undocumented changes than when something documented changes (and as I said before, yes, that is subjective, I'll admit that).

I'll think on your words some more, but I probably won't be adding to this discussion anymore, because I don't think I have anything (constructive) left to add. If you (or anyone else that reads this) think there is something to learn from my experiences, I'm glad that I shared them, and if not then it's not like I lost anything by sharing them.

Thanks for responding seriously btw (it gets me to think if people present opposing views in a way I can't just bulldoze over them).
tclord 2022 年 1 月 14 日 下午 2:36 
引用自 Af&Fix
引用自 Suikoudan

This might just be adding oil to the flames, but I'll try to explain the problem anyway.

There is nothing worse than spending a whole week going through your code to find out why it randomly stops working at seemingly unrelated moments, only to find out that it was caused by an update in some third party library that "fixed" a known bug. I actually know someone that reintroduced a bug to his code, because too many parties complained that his "undocumented feature" stopped working.

Trust me, if you don't have to, don't rely on things that are not documented as features. I'm not trying to say that you have to write perfect code or anything, I'm justing asking you to think about the pros and cons of the choices you make. If in the end you still want to do it the way you have been doing, that's perfectly fine, but at least you will have had the chance to make that choice (I'm starting to sound really cheesy right now, so I'm going to stop here before it gets any worse).
No offense, but that statement is as insitfull, as "memento mori". You do not have any bases to trust that your documented features won't change the same way, that you are describing. I not saying that you are wrong, of course you should be mindfull of what you are doing, but that's doesn't have translation to concrete actions, so it's just more of a spook out of experience which is subjective.

Documented features tend to not change unless something unforeseen occurs that requires it, and can be a learning opportunity for the api designer that they should try and improve in foreseeing things, though not everything can be foreseen.

Undocumented features are subject to change at any time and without notice, at the whims of the author. You really are not supposed to be taking advantage of undocumented features and so you do so at your own risk. Using undocumented features may make your coding easier, but realize you are taking risks doing so. And also, taking the easy way out isn't the best way to learn and improve your coding skills. But everyone is free to decide for themselves what they want to do.
hajes29a 2023 年 8 月 21 日 下午 12:24 
if I run `await ns.installBackdoor();` error pops up

ns.installBackdoor is not a function
stack:
TypeError: ns.installBackdoor is not a function
X5934 078FR1 2023 年 8 月 21 日 下午 1:31 
引用自 hajes29a
if I run `await ns.installBackdoor();` error pops up

ns.installBackdoor is not a function
stack:
TypeError: ns.installBackdoor is not a function

It is a singularity function which requires source file 4:
await ns.singularity.installBackdoor ( );

if you don't have SF4 yet you can try my script
https://steamcommunity.com/sharedfiles/filedetails/?id=3022646335
最後修改者:X5934 078FR1; 2023 年 8 月 21 日 下午 1:36
hajes29a 2023 年 8 月 24 日 上午 10:22 
thanks
alex.p80 2024 年 12 月 10 日 下午 10:42 
/** @param {NS} ns */
export function netScan(ns, grab) {
let serversToScan = [{ hostname: "home", path: [] }];
let discoveredServers = [];
//let network = [];
grab = grab || (() => { });

while (serversToScan.length > 0) {
let server = serversToScan.pop();
server.path.push(server.hostname);
grab(server);
//network.push(extendFunction(server, ...params));
discoveredServers.push(server.hostname);
for (let connectedServer of ns.scan(server.hostname)) {
if (!discoveredServers.includes(connectedServer)) {
serversToScan.push({
hostname: connectedServer,
path: [...server.path],
});
}
}
}
}
/** @param {NS} ns */
export async function netScanAsync(ns, grab) {
let serversToScan = [{ hostname: "home", path: [] }];
let discoveredServers = [];
//let network = [];
grab = grab || (() => { });

while (serversToScan.length > 0) {
let server = serversToScan.pop();
server.path.push(server.hostname);
await grab(server);
//network.push(extendFunction(server, ...params));
discoveredServers.push(server.hostname);
for (let connectedServer of ns.scan(server.hostname)) {
if (!discoveredServers.includes(connectedServer)) {
serversToScan.push({
hostname: connectedServer,
path: [...server.path],
});
}
}
}
}

Those are my 2 lib functions that scans the network (sync and async).

you can pass a callback as parameter that will receive the hostname and the path of the server.
< >
目前顯示第 31-39 則留言,共 39
每頁顯示: 1530 50