2018-07-31 20:00:03 +02:00
|
|
|
import {BitNodeMultipliers} from "./BitNodeMultipliers";
|
2018-06-26 18:34:11 +02:00
|
|
|
import {CONSTANTS} from "./Constants";
|
|
|
|
import {Programs} from "./CreateProgram";
|
|
|
|
import {Player} from "./Player";
|
2018-09-07 05:56:59 +02:00
|
|
|
import {SpecialServerIps} from "./SpecialServerIps";
|
2018-07-05 02:35:33 +02:00
|
|
|
import {getRandomInt} from "../utils/helpers/getRandomInt";
|
2018-07-05 03:30:50 +02:00
|
|
|
import {createRandomIp, ipExists} from "../utils/IPAddress";
|
2018-09-07 05:56:59 +02:00
|
|
|
import {serverMetadata} from "./data/servers";
|
2017-08-30 19:44:29 +02:00
|
|
|
import {Reviver, Generic_toJSON,
|
2018-06-26 18:34:11 +02:00
|
|
|
Generic_fromJSON} from "../utils/JSONReviver";
|
2018-07-05 03:30:50 +02:00
|
|
|
import {isValidIPAddress} from "../utils/helpers/isValidIPAddress";
|
2017-08-30 19:44:29 +02:00
|
|
|
|
2018-05-05 22:23:57 +02:00
|
|
|
function Server(params={ip:createRandomIp(), hostname:""}) {
|
|
|
|
/* Properties */
|
|
|
|
//Connection information
|
|
|
|
this.ip = params.ip ? params.ip : createRandomIp();
|
|
|
|
|
|
|
|
var hostname = params.hostname;
|
2017-08-03 06:21:15 +02:00
|
|
|
var i = 0;
|
2017-10-07 07:51:49 +02:00
|
|
|
var suffix = "";
|
|
|
|
while (GetServerByHostname(hostname+suffix) != null) {
|
2017-08-03 06:21:15 +02:00
|
|
|
//Server already exists
|
2017-10-07 07:51:49 +02:00
|
|
|
suffix = "-" + i;
|
2017-08-03 06:21:15 +02:00
|
|
|
++i;
|
|
|
|
}
|
2018-05-05 22:23:57 +02:00
|
|
|
this.hostname = hostname + suffix;
|
2018-05-06 22:27:47 +02:00
|
|
|
this.organizationName = params.organizationName != null ? params.organizationName : "";
|
|
|
|
this.isConnectedTo = params.isConnectedTo != null ? params.isConnectedTo : false;
|
2018-05-05 22:23:57 +02:00
|
|
|
|
|
|
|
//Access information
|
2018-05-06 22:27:47 +02:00
|
|
|
this.hasAdminRights = params.adminRights != null ? params.adminRights : false;
|
|
|
|
this.purchasedByPlayer = params.purchasedByPlayer != null ? params.purchasedByPlayer : false;
|
2018-05-05 22:23:57 +02:00
|
|
|
this.manuallyHacked = false; //Flag that tracks whether or not the server has been hacked at least once
|
|
|
|
|
|
|
|
//RAM, CPU speed and Scripts
|
2018-05-06 22:27:47 +02:00
|
|
|
this.maxRam = params.maxRam != null ? params.maxRam : 0; //GB
|
2018-05-05 22:23:57 +02:00
|
|
|
this.ramUsed = 0;
|
|
|
|
this.cpuCores = 1; //Max of 8, affects hacking times and Hacking Mission starting Cores
|
|
|
|
|
|
|
|
this.scripts = [];
|
|
|
|
this.runningScripts = []; //Stores RunningScript objects
|
|
|
|
this.programs = [];
|
|
|
|
this.messages = [];
|
|
|
|
this.textFiles = [];
|
|
|
|
this.dir = 0; //new Directory(this, null, ""); TODO
|
|
|
|
|
|
|
|
/* Hacking information (only valid for "foreign" aka non-purchased servers) */
|
2018-05-06 22:27:47 +02:00
|
|
|
this.requiredHackingSkill = params.requiredHackingSkill != null ? params.requiredHackingSkill : 1;
|
2018-05-06 23:20:00 +02:00
|
|
|
this.moneyAvailable = params.moneyAvailable != null ? params.moneyAvailable * BitNodeMultipliers.ServerStartingMoney : 0;
|
2018-05-05 22:23:57 +02:00
|
|
|
this.moneyMax = 25 * this.moneyAvailable * BitNodeMultipliers.ServerMaxMoney;
|
|
|
|
|
|
|
|
//Hack Difficulty is synonymous with server security. Base Difficulty = Starting difficulty
|
2018-05-06 22:27:47 +02:00
|
|
|
this.hackDifficulty = params.hackDifficulty != null ? params.hackDifficulty * BitNodeMultipliers.ServerStartingSecurity : 1;
|
2018-05-05 22:23:57 +02:00
|
|
|
this.baseDifficulty = this.hackDifficulty;
|
|
|
|
this.minDifficulty = Math.max(1, Math.round(this.hackDifficulty / 3));
|
2018-05-06 22:27:47 +02:00
|
|
|
this.serverGrowth = params.serverGrowth != null ? params.serverGrowth : 1; //Integer from 0 to 100. Affects money increase from grow()
|
2018-05-05 22:23:57 +02:00
|
|
|
|
|
|
|
//The IP's of all servers reachable from this one (what shows up if you run scan/netstat)
|
2016-12-01 23:18:18 +01:00
|
|
|
// NOTE: Only contains IP and not the Server objects themselves
|
2018-05-05 22:23:57 +02:00
|
|
|
this.serversOnNetwork = [];
|
|
|
|
|
|
|
|
//Port information, required for porthacking servers to get admin rights
|
2018-05-06 22:27:47 +02:00
|
|
|
this.numOpenPortsRequired = params.numOpenPortsRequired != null ? params.numOpenPortsRequired : 5;
|
2018-05-05 22:23:57 +02:00
|
|
|
this.sshPortOpen = false; //Port 22
|
|
|
|
this.ftpPortOpen = false; //Port 21
|
|
|
|
this.smtpPortOpen = false; //Port 25
|
|
|
|
this.httpPortOpen = false; //Port 80
|
|
|
|
this.sqlPortOpen = false; //Port 1433
|
|
|
|
this.openPortCount = 0;
|
2016-10-17 23:23:23 +02:00
|
|
|
};
|
|
|
|
|
2017-08-30 19:44:29 +02:00
|
|
|
Server.prototype.setMaxRam = function(ram) {
|
|
|
|
this.maxRam = ram;
|
|
|
|
}
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
//The serverOnNetwork array holds the IP of all the servers. This function
|
|
|
|
//returns the actual Server objects
|
|
|
|
Server.prototype.getServerOnNetwork = function(i) {
|
|
|
|
if (i > this.serversOnNetwork.length) {
|
|
|
|
console.log("Tried to get server on network that was out of range");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return AllServers[this.serversOnNetwork[i]];
|
2016-10-19 23:43:49 +02:00
|
|
|
}
|
|
|
|
|
2016-12-15 18:51:23 +01:00
|
|
|
//Given the name of the script, returns the corresponding
|
|
|
|
//script object on the server (if it exists)
|
|
|
|
Server.prototype.getScript = function(scriptName) {
|
2018-05-05 22:23:57 +02:00
|
|
|
for (var i = 0; i < this.scripts.length; i++) {
|
|
|
|
if (this.scripts[i].filename == scriptName) {
|
|
|
|
return this.scripts[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2016-12-15 18:51:23 +01:00
|
|
|
}
|
|
|
|
|
2018-06-22 21:41:55 +02:00
|
|
|
Server.prototype.capDifficulty = function() {
|
|
|
|
if (this.hackDifficulty < this.minDifficulty) {this.hackDifficulty = this.minDifficulty;}
|
|
|
|
if (this.hackDifficulty < 1) {this.hackDifficulty = 1;}
|
2017-09-19 20:38:03 +02:00
|
|
|
//Place some arbitrarily limit that realistically should never happen unless someone is
|
|
|
|
//screwing around with the game
|
|
|
|
if (this.hackDifficulty > 1000000) {this.hackDifficulty = 1000000;}
|
2017-05-31 18:45:30 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 21:41:55 +02:00
|
|
|
//Strengthens a server's security level (difficulty) by the specified amount
|
|
|
|
Server.prototype.fortify = function(amt) {
|
|
|
|
this.hackDifficulty += amt;
|
|
|
|
this.capDifficulty();
|
|
|
|
}
|
|
|
|
|
2017-05-31 18:45:30 +02:00
|
|
|
Server.prototype.weaken = function(amt) {
|
2017-08-30 19:44:29 +02:00
|
|
|
this.hackDifficulty -= (amt * BitNodeMultipliers.ServerWeakenRate);
|
2018-06-22 21:41:55 +02:00
|
|
|
this.capDifficulty();
|
2017-05-31 18:45:30 +02:00
|
|
|
}
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
//Functions for loading and saving a Server
|
|
|
|
Server.prototype.toJSON = function() {
|
2018-05-05 22:23:57 +02:00
|
|
|
return Generic_toJSON("Server", this);
|
2016-10-18 23:37:53 +02:00
|
|
|
}
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
Server.fromJSON = function(value) {
|
2018-05-05 22:23:57 +02:00
|
|
|
return Generic_fromJSON(Server, value.data);
|
2016-12-01 23:18:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Reviver.constructors.Server = Server;
|
|
|
|
|
2017-08-30 19:44:29 +02:00
|
|
|
function initForeignServers() {
|
2016-12-01 23:18:18 +01:00
|
|
|
/* Create a randomized network for all the foreign servers */
|
|
|
|
//Groupings for creating a randomized network
|
2018-09-07 05:56:59 +02:00
|
|
|
const networkLayers = [];
|
|
|
|
for (let i = 0; i < 15; i++) {
|
|
|
|
networkLayers.push([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Essentially any property that is of type 'number | IMinMaxRange'
|
|
|
|
const propertiesToPatternMatch = [
|
|
|
|
"hackDifficulty",
|
|
|
|
"moneyAvailable",
|
|
|
|
"requiredHackingSkill",
|
|
|
|
"serverGrowth"
|
|
|
|
];
|
|
|
|
|
|
|
|
const toNumber = (value) => {
|
|
|
|
switch (typeof value) {
|
|
|
|
case 'number':
|
|
|
|
return value;
|
|
|
|
case 'object':
|
|
|
|
return getRandomInt(value.min, value.max);
|
|
|
|
default:
|
|
|
|
throw Error(`Do not know how to convert the type '${typeof value}' to a number`);
|
|
|
|
}
|
2016-12-01 23:18:18 +01:00
|
|
|
}
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2018-09-07 05:56:59 +02:00
|
|
|
for (const metadata of serverMetadata) {
|
|
|
|
const serverParams = {
|
|
|
|
hostname: metadata.hostname,
|
|
|
|
ip: createRandomIp(),
|
|
|
|
numOpenPortsRequired: metadata.numOpenPortsRequired,
|
|
|
|
organizationName: metadata.organizationName
|
|
|
|
};
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2018-09-07 06:25:48 +02:00
|
|
|
if (metadata.maxRamExponent !== undefined) {
|
2018-09-07 06:37:59 +02:00
|
|
|
serverParams.maxRam = Math.pow(2, toNumber(metadata.maxRamExponent));
|
2018-09-07 06:25:48 +02:00
|
|
|
}
|
|
|
|
|
2018-09-07 05:56:59 +02:00
|
|
|
for (const prop of propertiesToPatternMatch) {
|
|
|
|
if (metadata[prop] !== undefined) {
|
|
|
|
serverParams[prop] = toNumber(metadata[prop]);
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2018-09-07 05:56:59 +02:00
|
|
|
const server = new Server(serverParams);
|
|
|
|
for (const filename of (metadata.literature || [])) {
|
|
|
|
server.messages.push(filename);
|
|
|
|
}
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2018-09-07 05:56:59 +02:00
|
|
|
if (metadata.specialName !== undefined) {
|
|
|
|
SpecialServerIps.addIp(metadata.specialName, server.ip);
|
|
|
|
}
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2018-09-07 05:56:59 +02:00
|
|
|
AddToAllServers(server);
|
|
|
|
if (metadata.networkLayer !== undefined) {
|
2018-09-07 06:05:34 +02:00
|
|
|
networkLayers[toNumber(metadata.networkLayer) - 1].push(server);
|
2018-09-07 05:56:59 +02:00
|
|
|
}
|
2016-12-01 23:18:18 +01:00
|
|
|
}
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2018-09-07 05:56:59 +02:00
|
|
|
/* Create a randomized network for all the foreign servers */
|
|
|
|
const linkComputers = (server1, server2) => {
|
|
|
|
server1.serversOnNetwork.push(server2.ip);
|
|
|
|
server2.serversOnNetwork.push(server1.ip);
|
|
|
|
};
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2018-09-07 05:56:59 +02:00
|
|
|
const getRandomArrayItem = (arr) => arr[Math.floor(Math.random() * arr.length)];
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2018-09-07 05:56:59 +02:00
|
|
|
const linkNetworkLayers = (network1, selectServer) => {
|
|
|
|
for (const server of network1) {
|
|
|
|
linkComputers(server, selectServer());
|
|
|
|
}
|
|
|
|
};
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2018-09-07 05:56:59 +02:00
|
|
|
// Connect the first tier of servers to the player's home computer
|
|
|
|
linkNetworkLayers(networkLayers[0], () => Player.getHomeComputer());
|
|
|
|
for (let i = 1; i < networkLayers.length; i++) {
|
|
|
|
linkNetworkLayers(networkLayers[i], () => getRandomArrayItem(networkLayers[i - 1]));
|
2016-12-01 23:18:18 +01:00
|
|
|
}
|
2017-05-02 18:28:54 +02:00
|
|
|
}
|
2016-12-01 23:18:18 +01:00
|
|
|
|
2018-06-13 23:12:58 +02:00
|
|
|
function numCycleForGrowth(server, growth) {
|
|
|
|
let ajdGrowthRate = 1 + (CONSTANTS.ServerBaseGrowthRate - 1) / server.hackDifficulty;
|
|
|
|
if(ajdGrowthRate > CONSTANTS.ServerMaxGrowthRate) {
|
|
|
|
ajdGrowthRate = CONSTANTS.ServerMaxGrowthRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
const serverGrowthPercentage = server.serverGrowth / 100;
|
|
|
|
|
|
|
|
const cycles = Math.log(growth)/(Math.log(ajdGrowthRate)*Player.hacking_grow_mult*serverGrowthPercentage);
|
|
|
|
return cycles;
|
|
|
|
}
|
|
|
|
|
2017-05-02 18:28:54 +02:00
|
|
|
//Applied server growth for a single server. Returns the percentage growth
|
2017-08-30 19:44:29 +02:00
|
|
|
function processSingleServerGrowth(server, numCycles) {
|
2017-05-02 18:28:54 +02:00
|
|
|
//Server growth processed once every 450 game cycles
|
2018-06-13 23:12:58 +02:00
|
|
|
const numServerGrowthCycles = Math.max(Math.floor(numCycles / 450), 0);
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2017-06-06 23:22:57 +02:00
|
|
|
//Get adjusted growth rate, which accounts for server security
|
2018-06-13 23:12:58 +02:00
|
|
|
const growthRate = CONSTANTS.ServerBaseGrowthRate;
|
2017-07-28 16:19:28 +02:00
|
|
|
var adjGrowthRate = 1 + (growthRate - 1) / server.hackDifficulty;
|
2017-06-06 23:22:57 +02:00
|
|
|
if (adjGrowthRate > CONSTANTS.ServerMaxGrowthRate) {adjGrowthRate = CONSTANTS.ServerMaxGrowthRate;}
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2017-06-06 23:22:57 +02:00
|
|
|
//Calculate adjusted server growth rate based on parameters
|
2018-06-13 23:12:58 +02:00
|
|
|
const serverGrowthPercentage = server.serverGrowth / 100;
|
|
|
|
const numServerGrowthCyclesAdjusted = numServerGrowthCycles * serverGrowthPercentage * BitNodeMultipliers.ServerGrowthRate;
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2017-05-02 18:28:54 +02:00
|
|
|
//Apply serverGrowth for the calculated number of growth cycles
|
2017-06-14 03:07:02 +02:00
|
|
|
var serverGrowth = Math.pow(adjGrowthRate, numServerGrowthCyclesAdjusted * Player.hacking_grow_mult);
|
2017-05-30 00:37:38 +02:00
|
|
|
if (serverGrowth < 1) {
|
|
|
|
console.log("WARN: serverGrowth calculated to be less than 1");
|
|
|
|
serverGrowth = 1;
|
|
|
|
}
|
2017-07-28 16:19:28 +02:00
|
|
|
|
2018-06-13 23:12:58 +02:00
|
|
|
const oldMoneyAvailable = server.moneyAvailable;
|
2017-05-02 18:28:54 +02:00
|
|
|
server.moneyAvailable *= serverGrowth;
|
2018-06-13 23:12:58 +02:00
|
|
|
|
|
|
|
// in case of data corruption
|
2017-07-06 00:33:46 +02:00
|
|
|
if (server.moneyMax && isNaN(server.moneyAvailable)) {
|
|
|
|
server.moneyAvailable = server.moneyMax;
|
|
|
|
}
|
2018-06-13 23:12:58 +02:00
|
|
|
|
|
|
|
// cap at max
|
2017-07-06 00:33:46 +02:00
|
|
|
if (server.moneyMax && server.moneyAvailable > server.moneyMax) {
|
2017-06-07 02:04:18 +02:00
|
|
|
server.moneyAvailable = server.moneyMax;
|
|
|
|
}
|
2018-07-04 04:12:46 +02:00
|
|
|
|
2018-06-13 23:12:58 +02:00
|
|
|
// if there was any growth at all, increase security
|
|
|
|
if(oldMoneyAvailable !== server.moneyAvailable) {
|
|
|
|
//Growing increases server security twice as much as hacking
|
2018-06-22 21:41:55 +02:00
|
|
|
let usedCycles = numCycleForGrowth(server, server.moneyAvailable / oldMoneyAvailable);
|
|
|
|
usedCycles = Math.max(0, usedCycles);
|
2018-06-13 23:12:58 +02:00
|
|
|
server.fortify(2 * CONSTANTS.ServerFortifyAmount * Math.ceil(usedCycles));
|
|
|
|
}
|
|
|
|
return server.moneyAvailable / oldMoneyAvailable;
|
2017-05-02 18:28:54 +02:00
|
|
|
}
|
2016-12-20 21:18:34 +01:00
|
|
|
|
2017-08-30 19:44:29 +02:00
|
|
|
function prestigeHomeComputer(homeComp) {
|
2018-02-24 23:55:06 +01:00
|
|
|
homeComp.programs.length = 0; //Remove programs
|
2017-08-30 19:44:29 +02:00
|
|
|
homeComp.runningScripts = [];
|
|
|
|
homeComp.serversOnNetwork = [];
|
|
|
|
homeComp.isConnectedTo = true;
|
|
|
|
homeComp.ramUsed = 0;
|
2018-06-02 01:31:34 +02:00
|
|
|
homeComp.programs.push(Programs.NukeProgram.name);
|
2017-08-30 19:44:29 +02:00
|
|
|
|
2017-12-11 06:04:00 +01:00
|
|
|
//Update RAM usage on all scripts
|
2017-12-11 06:07:16 +01:00
|
|
|
homeComp.scripts.forEach(function(script) {
|
2017-12-11 06:04:00 +01:00
|
|
|
script.updateRamUsage();
|
|
|
|
});
|
|
|
|
|
2018-02-24 23:55:06 +01:00
|
|
|
homeComp.messages.length = 0; //Remove .lit and .msg files
|
2017-12-07 04:45:47 +01:00
|
|
|
homeComp.messages.push("hackers-starting-handbook.lit");
|
2017-08-30 19:44:29 +02:00
|
|
|
}
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
//List of all servers that exist in the game, indexed by their ip
|
2017-08-30 19:44:29 +02:00
|
|
|
let AllServers = {};
|
2016-12-01 23:18:18 +01:00
|
|
|
|
2017-08-30 19:44:29 +02:00
|
|
|
function prestigeAllServers() {
|
|
|
|
for (var member in AllServers) {
|
|
|
|
delete AllServers[member];
|
|
|
|
}
|
|
|
|
AllServers = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadAllServers(saveString) {
|
|
|
|
AllServers = JSON.parse(saveString, Reviver);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SizeOfAllServers() {
|
2018-05-05 22:23:57 +02:00
|
|
|
var size = 0, key;
|
|
|
|
for (key in AllServers) {
|
|
|
|
if (AllServers.hasOwnProperty(key)) size++;
|
|
|
|
}
|
|
|
|
return size;
|
2016-12-15 18:51:23 +01:00
|
|
|
}
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
//Add a server onto the map of all servers in the game
|
2017-08-30 19:44:29 +02:00
|
|
|
function AddToAllServers(server) {
|
2016-12-01 23:18:18 +01:00
|
|
|
var serverIp = server.ip;
|
|
|
|
if (ipExists(serverIp)) {
|
|
|
|
console.log("IP of server that's being added: " + serverIp);
|
|
|
|
console.log("Hostname of the server thats being added: " + server.hostname);
|
|
|
|
console.log("The server that already has this IP is: " + AllServers[serverIp].hostname);
|
|
|
|
throw new Error("Error: Trying to add a server with an existing IP");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AllServers[serverIp] = server;
|
2016-10-18 23:37:53 +02:00
|
|
|
}
|
2016-12-01 23:18:18 +01:00
|
|
|
|
2016-12-15 18:51:23 +01:00
|
|
|
//Returns server object with corresponding hostname
|
2018-05-05 22:23:57 +02:00
|
|
|
// Relatively slow, would rather not use this a lot
|
2017-08-30 19:44:29 +02:00
|
|
|
function GetServerByHostname(hostname) {
|
2018-05-05 22:23:57 +02:00
|
|
|
for (var ip in AllServers) {
|
|
|
|
if (AllServers.hasOwnProperty(ip)) {
|
|
|
|
if (AllServers[ip].hostname == hostname) {
|
|
|
|
return AllServers[ip];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2016-12-15 18:51:23 +01:00
|
|
|
}
|
|
|
|
|
2017-05-11 06:20:17 +02:00
|
|
|
//Get server by IP or hostname. Returns null if invalid
|
2017-08-30 19:44:29 +02:00
|
|
|
function getServer(s) {
|
2017-05-11 06:20:17 +02:00
|
|
|
if (!isValidIPAddress(s)) {
|
|
|
|
return GetServerByHostname(s);
|
2018-06-13 18:34:32 +02:00
|
|
|
}
|
|
|
|
if(AllServers[s] !== undefined) {
|
2017-05-11 06:20:17 +02:00
|
|
|
return AllServers[s];
|
|
|
|
}
|
2018-06-13 18:34:32 +02:00
|
|
|
return null;
|
2017-05-11 06:20:17 +02:00
|
|
|
}
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
//Debugging tool
|
2017-08-30 19:44:29 +02:00
|
|
|
function PrintAllServers() {
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var ip in AllServers) {
|
|
|
|
if (AllServers.hasOwnProperty(ip)) {
|
|
|
|
console.log("Ip: " + ip + ", hostname: " + AllServers[ip].hostname);
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 16:19:28 +02:00
|
|
|
}
|
2017-08-30 19:44:29 +02:00
|
|
|
|
2017-10-10 06:56:48 +02:00
|
|
|
// Directory object (folders)
|
|
|
|
function Directory(server, parent, name) {
|
|
|
|
this.s = server; //Ref to server
|
|
|
|
this.p = parent; //Ref to parent directory
|
|
|
|
this.c = []; //Subdirs
|
|
|
|
this.n = name;
|
|
|
|
this.d = parent.d + 1; //We'll only have a maximum depth of 3 or something
|
|
|
|
this.scrs = []; //Holds references to the scripts in server.scripts
|
|
|
|
this.pgms = [];
|
|
|
|
this.msgs = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
Directory.prototype.createSubdir = function(name) {
|
|
|
|
var subdir = new Directory(this.s, this, name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Directory.prototype.getPath = function(name) {
|
|
|
|
var res = [];
|
|
|
|
var i = this;
|
|
|
|
while (i !== null) {
|
|
|
|
res.unshift(i.n, "/");
|
|
|
|
i = i.parent;
|
|
|
|
}
|
|
|
|
res.unshift("/");
|
|
|
|
return res.join("");
|
|
|
|
}
|
|
|
|
|
2017-08-30 19:44:29 +02:00
|
|
|
export {Server, AllServers, getServer, GetServerByHostname, loadAllServers,
|
|
|
|
AddToAllServers, processSingleServerGrowth, initForeignServers,
|
|
|
|
prestigeAllServers, prestigeHomeComputer};
|