bitburner-src/src/Server/Server.ts

162 lines
5.6 KiB
TypeScript
Raw Normal View History

2019-03-25 04:03:24 +01:00
// Class representing a single hackable Server
import { BaseServer } from "./BaseServer";
2019-03-03 04:15:10 +01:00
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { createRandomString } from "../utils/helpers/createRandomString";
2019-03-03 04:15:10 +01:00
import { createRandomIp } from "../../utils/IPAddress";
import { Generic_fromJSON,
Generic_toJSON,
Reviver } from "../../utils/JSONReviver";
export interface IConstructorParams {
2019-03-03 04:15:10 +01:00
adminRights?: boolean;
hackDifficulty?: number;
hostname: string;
ip?: string;
isConnectedTo?: boolean;
maxRam?: number;
moneyAvailable?: number;
numOpenPortsRequired?: number;
organizationName?: string;
purchasedByPlayer?: boolean;
requiredHackingSkill?: number;
serverGrowth?: number;
}
2019-03-25 04:03:24 +01:00
export class Server extends BaseServer {
// Initializes a Server Object from a JSON save state
static fromJSON(value: any): Server {
return Generic_fromJSON(Server, value.data);
}
v0.51.6 (#905) * Make command `cd` without arguments an alias for `cd /` (#853) In most shells `cd` without arguments takes you to the home directory of the current user. I keep trying to do this due to muscle memory from working in terminals, so I figured I'd make it do something useful. There is no home directory in the game, but going to / is the closest thing we have, since that is the starting point for the user in the game. * Add new `backdoor` terminal command (#852) * Add the backdoor command to the terminal This command will perform a manual hack without rewarding money. It will be used for the story, mainly for faction hacking tests * Add tab completion for backdoor command * Add help text for backdoor command * Change condition syntax to be more consistent with others * Extract reused code block so it is always called after actions * Update documentation for new backdoor command Modified references to manual hack as it isn't for factions anymore * Remove extra parenthesis * Rename manuallyHacked to backdoorInstalled * Fix typo * Change faction test messages to use backdoor instad of hack * Rename more instances of manuallyHacked * fixed typo in helptext of darkweb buy (#858) * Fix typos and unify descriptions of augmentations (#859) Made an attempt to... - give all "+rep% company/faction" the same text - make all augmentations with a single effect use a single line to describe the effect - make all effects end with a period * Made Cashroot starter kit display its tooltip with the money formatted properly and in gold * fix typo in docs (#860) * Initial code for Casino Card Deck implementation * Casino Blackjack Implementation * Update some tools (eslint, typescript) * Blackjack code cleanup * Update README_contribution * Update ScriptHelpers.js (#861) expand error message * More augmentation typo fixes (#862) * Add Netscript function getCurrentScript (#856) Add netscript function that returns the current script. * Added milestones menu to guide new players. (#865) Milestone menu * fix typos in milestones (#866) Co-authored-by: sschmidTU <s.schmid@phonicscore.com> * Corrupt location title when backdoor is installed (#864) * Add corruptableText component * Corrupt location title if backdoor is installed * Formatting * Add helper to check value of backdoorInstalled Helper could be oneline but it would make it less readable * Fix some formatting * Add settings option to disable text effects * Import useState * getRunningScript (#867) * Replaced getCurrentScript with getRunningScript * Bunch of smaller fixes (#904) Fix #884 Fix #879 Fix #878 Fix #876 Fix #874 Fix #873 Fix #887 Fix #891 Fix #895 * rework the early servers to be more noob friendly (#903) * v0.51.6 Co-authored-by: Andreas Eriksson <2691182+AndreasTPC@users.noreply.github.com> Co-authored-by: Jack <jackdewinter1@gmail.com> Co-authored-by: Teun Pronk <5228255+Crownie88@users.noreply.github.com> Co-authored-by: Pimvgd <Pimvgd@gmail.com> Co-authored-by: Daniel Xie <daniel.xie@flockfreight.com> Co-authored-by: Simon <33069673+sschmidTU@users.noreply.github.com> Co-authored-by: sschmidTU <s.schmid@phonicscore.com>
2021-04-29 02:07:26 +02:00
// Flag indicating whether this server has a backdoor installed by a player
2021-04-30 05:52:56 +02:00
backdoorInstalled = false;
v0.51.6 (#905) * Make command `cd` without arguments an alias for `cd /` (#853) In most shells `cd` without arguments takes you to the home directory of the current user. I keep trying to do this due to muscle memory from working in terminals, so I figured I'd make it do something useful. There is no home directory in the game, but going to / is the closest thing we have, since that is the starting point for the user in the game. * Add new `backdoor` terminal command (#852) * Add the backdoor command to the terminal This command will perform a manual hack without rewarding money. It will be used for the story, mainly for faction hacking tests * Add tab completion for backdoor command * Add help text for backdoor command * Change condition syntax to be more consistent with others * Extract reused code block so it is always called after actions * Update documentation for new backdoor command Modified references to manual hack as it isn't for factions anymore * Remove extra parenthesis * Rename manuallyHacked to backdoorInstalled * Fix typo * Change faction test messages to use backdoor instad of hack * Rename more instances of manuallyHacked * fixed typo in helptext of darkweb buy (#858) * Fix typos and unify descriptions of augmentations (#859) Made an attempt to... - give all "+rep% company/faction" the same text - make all augmentations with a single effect use a single line to describe the effect - make all effects end with a period * Made Cashroot starter kit display its tooltip with the money formatted properly and in gold * fix typo in docs (#860) * Initial code for Casino Card Deck implementation * Casino Blackjack Implementation * Update some tools (eslint, typescript) * Blackjack code cleanup * Update README_contribution * Update ScriptHelpers.js (#861) expand error message * More augmentation typo fixes (#862) * Add Netscript function getCurrentScript (#856) Add netscript function that returns the current script. * Added milestones menu to guide new players. (#865) Milestone menu * fix typos in milestones (#866) Co-authored-by: sschmidTU <s.schmid@phonicscore.com> * Corrupt location title when backdoor is installed (#864) * Add corruptableText component * Corrupt location title if backdoor is installed * Formatting * Add helper to check value of backdoorInstalled Helper could be oneline but it would make it less readable * Fix some formatting * Add settings option to disable text effects * Import useState * getRunningScript (#867) * Replaced getCurrentScript with getRunningScript * Bunch of smaller fixes (#904) Fix #884 Fix #879 Fix #878 Fix #876 Fix #874 Fix #873 Fix #887 Fix #891 Fix #895 * rework the early servers to be more noob friendly (#903) * v0.51.6 Co-authored-by: Andreas Eriksson <2691182+AndreasTPC@users.noreply.github.com> Co-authored-by: Jack <jackdewinter1@gmail.com> Co-authored-by: Teun Pronk <5228255+Crownie88@users.noreply.github.com> Co-authored-by: Pimvgd <Pimvgd@gmail.com> Co-authored-by: Daniel Xie <daniel.xie@flockfreight.com> Co-authored-by: Simon <33069673+sschmidTU@users.noreply.github.com> Co-authored-by: sschmidTU <s.schmid@phonicscore.com>
2021-04-29 02:07:26 +02:00
2019-03-03 04:15:10 +01:00
// Initial server security level
// (i.e. security level when the server was created)
2021-04-30 05:52:56 +02:00
baseDifficulty = 1;
2019-03-03 04:15:10 +01:00
// Server Security Level
2021-04-30 05:52:56 +02:00
hackDifficulty = 1;
2019-03-03 04:15:10 +01:00
// Minimum server security level that this server can be weakened to
2021-04-30 05:52:56 +02:00
minDifficulty = 1;
2019-03-03 04:15:10 +01:00
// How much money currently resides on the server and can be hacked
2021-04-30 05:52:56 +02:00
moneyAvailable = 0;
2019-03-03 04:15:10 +01:00
// Maximum amount of money that this server can hold
2021-04-30 05:52:56 +02:00
moneyMax = 0;
2019-03-03 04:15:10 +01:00
// Number of open ports required in order to gain admin/root access
2021-04-30 05:52:56 +02:00
numOpenPortsRequired = 5;
2019-03-03 04:15:10 +01:00
// How many ports are currently opened on the server
2021-04-30 05:52:56 +02:00
openPortCount = 0;
2019-03-03 04:15:10 +01:00
// Flag indicating wehther this is a purchased server
2021-04-30 05:52:56 +02:00
purchasedByPlayer = false;
2019-03-03 04:15:10 +01:00
// Hacking level required to hack this server
2021-04-30 05:52:56 +02:00
requiredHackingSkill = 1;
2019-03-03 04:15:10 +01:00
// Parameter that affects how effectively this server's money can
// be increased using the grow() Netscript function
2021-04-30 05:52:56 +02:00
serverGrowth = 1;
2019-03-03 04:15:10 +01:00
2019-03-25 04:03:24 +01:00
constructor(params: IConstructorParams={hostname: "", ip: createRandomIp() }) {
super(params);
2019-03-03 04:15:10 +01:00
2019-03-25 04:03:24 +01:00
// "hacknet-node-X" hostnames are reserved for Hacknet Servers
if (this.hostname.startsWith("hacknet-node-")) {
this.hostname = createRandomString(10);
}
2019-03-03 04:15:10 +01:00
this.purchasedByPlayer = params.purchasedByPlayer != null ? params.purchasedByPlayer : false;
//RAM, CPU speed and Scripts
this.maxRam = params.maxRam != null ? params.maxRam : 0; //GB
/* Hacking information (only valid for "foreign" aka non-purchased servers) */
this.requiredHackingSkill = params.requiredHackingSkill != null ? params.requiredHackingSkill : 1;
this.moneyAvailable = params.moneyAvailable != null ? params.moneyAvailable * BitNodeMultipliers.ServerStartingMoney : 0;
this.moneyMax = 25 * this.moneyAvailable * BitNodeMultipliers.ServerMaxMoney;
//Hack Difficulty is synonymous with server security. Base Difficulty = Starting difficulty
this.hackDifficulty = params.hackDifficulty != null ? params.hackDifficulty * BitNodeMultipliers.ServerStartingSecurity : 1;
this.baseDifficulty = this.hackDifficulty;
this.minDifficulty = Math.max(1, Math.round(this.hackDifficulty / 3));
this.serverGrowth = params.serverGrowth != null ? params.serverGrowth : 1; //Integer from 0 to 100. Affects money increase from grow()
//Port information, required for porthacking servers to get admin rights
this.numOpenPortsRequired = params.numOpenPortsRequired != null ? params.numOpenPortsRequired : 5;
2021-04-30 05:52:56 +02:00
}
2019-03-03 04:15:10 +01:00
2019-03-25 04:03:24 +01:00
/**
* Ensures that the server's difficulty (server security) doesn't get too high
*/
capDifficulty(): void {
2019-03-03 04:15:10 +01:00
if (this.hackDifficulty < this.minDifficulty) {this.hackDifficulty = this.minDifficulty;}
if (this.hackDifficulty < 1) {this.hackDifficulty = 1;}
// Place some arbitrarily limit that realistically should never happen unless someone is
// screwing around with the game
v0.51.6 (#905) * Make command `cd` without arguments an alias for `cd /` (#853) In most shells `cd` without arguments takes you to the home directory of the current user. I keep trying to do this due to muscle memory from working in terminals, so I figured I'd make it do something useful. There is no home directory in the game, but going to / is the closest thing we have, since that is the starting point for the user in the game. * Add new `backdoor` terminal command (#852) * Add the backdoor command to the terminal This command will perform a manual hack without rewarding money. It will be used for the story, mainly for faction hacking tests * Add tab completion for backdoor command * Add help text for backdoor command * Change condition syntax to be more consistent with others * Extract reused code block so it is always called after actions * Update documentation for new backdoor command Modified references to manual hack as it isn't for factions anymore * Remove extra parenthesis * Rename manuallyHacked to backdoorInstalled * Fix typo * Change faction test messages to use backdoor instad of hack * Rename more instances of manuallyHacked * fixed typo in helptext of darkweb buy (#858) * Fix typos and unify descriptions of augmentations (#859) Made an attempt to... - give all "+rep% company/faction" the same text - make all augmentations with a single effect use a single line to describe the effect - make all effects end with a period * Made Cashroot starter kit display its tooltip with the money formatted properly and in gold * fix typo in docs (#860) * Initial code for Casino Card Deck implementation * Casino Blackjack Implementation * Update some tools (eslint, typescript) * Blackjack code cleanup * Update README_contribution * Update ScriptHelpers.js (#861) expand error message * More augmentation typo fixes (#862) * Add Netscript function getCurrentScript (#856) Add netscript function that returns the current script. * Added milestones menu to guide new players. (#865) Milestone menu * fix typos in milestones (#866) Co-authored-by: sschmidTU <s.schmid@phonicscore.com> * Corrupt location title when backdoor is installed (#864) * Add corruptableText component * Corrupt location title if backdoor is installed * Formatting * Add helper to check value of backdoorInstalled Helper could be oneline but it would make it less readable * Fix some formatting * Add settings option to disable text effects * Import useState * getRunningScript (#867) * Replaced getCurrentScript with getRunningScript * Bunch of smaller fixes (#904) Fix #884 Fix #879 Fix #878 Fix #876 Fix #874 Fix #873 Fix #887 Fix #891 Fix #895 * rework the early servers to be more noob friendly (#903) * v0.51.6 Co-authored-by: Andreas Eriksson <2691182+AndreasTPC@users.noreply.github.com> Co-authored-by: Jack <jackdewinter1@gmail.com> Co-authored-by: Teun Pronk <5228255+Crownie88@users.noreply.github.com> Co-authored-by: Pimvgd <Pimvgd@gmail.com> Co-authored-by: Daniel Xie <daniel.xie@flockfreight.com> Co-authored-by: Simon <33069673+sschmidTU@users.noreply.github.com> Co-authored-by: sschmidTU <s.schmid@phonicscore.com>
2021-04-29 02:07:26 +02:00
if (this.hackDifficulty > 100) {this.hackDifficulty = 100;}
2019-03-03 04:15:10 +01:00
}
2019-03-25 04:03:24 +01:00
/**
* Change this server's minimum security
* @param n - Value by which to increase/decrease the server's minimum security
* @param perc - Whether it should be changed by a percentage, or a flat value
*/
2021-04-30 05:52:56 +02:00
changeMinimumSecurity(n: number, perc=false): void {
2019-03-25 04:03:24 +01:00
if (perc) {
this.minDifficulty *= n;
} else {
this.minDifficulty += n;
2019-03-03 04:15:10 +01:00
}
2019-03-25 04:03:24 +01:00
// Server security cannot go below 1
this.minDifficulty = Math.max(1, this.minDifficulty);
2019-03-03 04:15:10 +01:00
}
2019-03-25 04:03:24 +01:00
/**
* Change this server's maximum money
* @param n - Value by which to change the server's maximum money
* @param perc - Whether it should be changed by a percentage, or a flat value
*/
2021-04-30 05:52:56 +02:00
changeMaximumMoney(n: number, perc=false): void {
2019-03-25 04:03:24 +01:00
if (perc) {
this.moneyMax *= n;
2019-03-03 04:15:10 +01:00
} else {
2019-03-25 04:03:24 +01:00
this.moneyMax += n;
2019-03-03 04:15:10 +01:00
}
}
/**
* Strengthens a server's security level (difficulty) by the specified amount
*/
fortify(amt: number): void {
this.hackDifficulty += amt;
this.capDifficulty();
}
2019-03-25 04:03:24 +01:00
/**
* Lowers the server's security level (difficulty) by the specified amount)
*/
weaken(amt: number): void {
this.hackDifficulty -= (amt * BitNodeMultipliers.ServerWeakenRate);
this.capDifficulty();
2019-03-03 04:15:10 +01:00
}
2019-03-25 04:03:24 +01:00
/**
* Serialize the current object to a JSON save state
*/
toJSON(): any {
return Generic_toJSON("Server", this);
}
2019-03-03 04:15:10 +01:00
}
Reviver.constructors.Server = Server;