Merge pull request #288 from hydroflame/netscript-ps

Netscript ps function
This commit is contained in:
danielyxie 2018-06-13 09:17:58 -05:00 committed by GitHub
commit fa42d4ee43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -951,6 +951,23 @@ function NetscriptFunctions(workerScript) {
allFiles.sort();
return allFiles;
},
ps : function(ip=workerScript.serverIp) {
if (workerScript.checkingRam) {
return updateStaticRam("ps", CONSTANTS.ScriptScanRamCost);
}
updateDynamicRam("ps", CONSTANTS.ScriptScanRamCost);
var server = getServer(ip);
if (server == null){
workerScript.scriptRef.log("ps() failed. Invalid IP or hostname passed in: " + ip);
throw makeRuntimeRejectMsg(workerScript, "ps() failed. Invalid IP or hostname passed in: " + ip);
}
const processes = [];
for(const i in server.runningScripts) {
const script = server.runningScripts[i];
processes.push({filename:script.filename, threads: script.threads, args: script.args.slice()})
}
return processes;
},
hasRootAccess : function(ip) {
if (workerScript.checkingRam) {
return updateStaticRam("hasRootAccess", CONSTANTS.ScriptHasRootAccessRamCost);