-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreduxmcp.js
More file actions
214 lines (197 loc) · 5.47 KB
/
reduxmcp.js
File metadata and controls
214 lines (197 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import {analyze,getAllHosts} from 'utils/scan'
import {runScript} from 'utils/run'
import {hashingFunction} from 'utils/general'
// import * as someNamespace from 'yourScript.js'
// someNamespace.someFunc()
const DELAY_TICK = 20;
const DELAY_TICKCYCLE = 1000; //1000;
const TURN_ORDER = ["scan","buy","spread","bots"]
let DEBUG = true
let MEMORY = {
servers:{
bots:{},
targets:{
all:{},
primary:""
},
byVal:[]
},
preferences:{
mode:"swarm",//swarm,spread
turns:TURN_ORDER,//[]
},
scripts:{
filenames:[
"utils/run.js",
"utils/scan.js",
"utils/formatting.js"
],
ram:{
},
},
}
// const Botnet = (ns)=>{
// // bot:()=>{},
// };
async function Factions(ns,factionName){}
async function Gang(ns){}
async function HacknetNodes(ns){
return await {
}
}
//Classes for managing botnet
//
async function Botnet(ns){
// if(DEBUG)console.log(`[tick] tacking a tick.`);
return await {
"server":(botName)=>{
return {
hasFiles:(files)=>{
if(!files)files=MEMORY.scripts.filenames;
//if files is a string and not array then mk array
console.log(`[Botnet][server][${botName}] hasFiles`,{files})
return ns.hasFiles(files,botName);
},
getFiles:(files,soureServerName)=>{
if(!files)files=MEMORY.scripts.filenames;
return ns.scp(files,botName,soureServerName)
},
runScript:(fileName,threads,targetName)=>{
if(!ns.hasRootAccess(host))return;
if(Botnet(ns).server(botName).hasFiles([fileName])){Botnet(ns).server(botName).getFiles([fileName]);};
if(!targetName)targetName=botName;
if(!threads||threads=="auto"){
threads = 1
// const scriptRam = ns.getScriptRam(fileName,botName)
// const availRam = ns.getAv
// getServerMaxRam(host)
// getServerUsedRam(host)
}
ns.exec(fileName, botName, threads, targetName, botName);
},
};
// aggregate & assess targets
// choose targets & assign bots
// release bots
},
"scan":async()=>{
// scan all servers
// analyze each server
//
//update memory
},
// "crawl"
"buy":async()=>{
// buy purchaseable programs
// buy purchaseable servers
// buy hacker nodes
// ? buy purchaseable upgrades
//
}
}
}
async function Tick(ns){
// if(DEBUG)console.log(`[tick] tacking a tick.`);
const tickThis = this;
return await {
"bot":async(hostName)=>{
// prep
const whatIsThis = this;
console.log(`[Tick][bot] ${hostName}`,{whatIsThis,tickThis})
let hasFiles = Botnet(ns).server(hostName).hasFiles(MEMORY.scripts.filenames)
if (!hasFiles)Botnet(ns).server(hostName).getFiles(MEMORY.scripts.filenames);
// aggregate & assess targets
// choose targets & assign bots
// release bots
},
"scan":async()=>{
// scan all servers
// analyze each server
//
//update memory
},
// "crawl"
"buy":async()=>{
// buy purchaseable programs
// buy purchaseable servers
// buy hacker nodes
// ? buy purchaseable upgrades
//
}
}
}
/** @param {NS} ns */
export async function main(ns) {
/*# Init
actions that only need to be taken once before turn loop i.e.; launch crawler script
*/
const flags = ns.flags([
["debug",true]
])
DEBUG = flags.debug
const scriptHost = await ns.getHostname();
console.log(`[main] initiating reduxmcp`,{
player:await ns.getPlayer(),
server:await ns.getServer(),
hackingLvl:await ns.getHackingLevel(),
hackingMultipliers:await ns.getHackingMultipliers(),
moneySources:await ns.getMoneySources(),
servers:{
purchased:await ns.getPurchasedServers(),
limit:await ns.getPurchasedServerLimit()
},
hasTor:await ns.hasTorRouter(),
files: await ns.ls(scriptHost)
})
const servers = getAllHosts(ns);
const analyzedServers = await analyze(ns)
// for (const server of servers) {
// scannedServers
// };
console.log(`[main] initial scan`,{
servers,
analyzedServers
})
// for(const serv )
/*# Pre-Turn
actions that only need to be taken once before turn loop i.e.; launch crawler script
*/
// ns.run(crawler)
/*# Turn Ticks
*/
// let ticks = 0;
let turnIndex = 0
while(true){
const turn = MEMORY.preferences.turns[turnIndex]
// MEMORY.preferences.turns.length
// if(DEBUG)console.log(`[main] starting game tick. turn: ${turn}`);
await Tick(ns)[turn];
// switch (turn) {
// case "scan":
// // Code to execute if expression === value1
// break;
// case "bots":
// // Code to execute if expression === value2
// break;
// // ... more cases
// default:
// // Code to execute if no case matches
// tick(ns)[turn];
// }
//setup next turn
turnIndex++
if(turnIndex>=MEMORY.preferences.turns.length){
turnIndex=0
await ns.sleep(DELAY_TICKCYCLE);
}else{
await ns.sleep(DELAY_TICK);
};
/* Post-Turn
stuff that runs after every turn
*/
// share() spare RAM with faction
};
/* Post-Tick
stuff that runs after every tick
*/
}