mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-30 04:47:03 +02:00
more convertion from ip to hostname
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
import { GetAllServers, GetServerByIP, createUniqueRandomIp, ipExists } from "./AllServers";
|
||||
import { GetServer, createUniqueRandomIp, ipExists } from "./AllServers";
|
||||
import { Server, IConstructorParams } from "./Server";
|
||||
import { BaseServer } from "./BaseServer";
|
||||
import { calculateServerGrowth } from "./formulas/grow";
|
||||
|
||||
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
||||
import { CONSTANTS } from "../Constants";
|
||||
import { HacknetServer } from "../Hacknet/HacknetServer";
|
||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||
import { Programs } from "../Programs/Programs";
|
||||
import { LiteratureNames } from "../Literature/data/LiteratureNames";
|
||||
|
||||
import { isValidNumber } from "../utils/helpers/isValidNumber";
|
||||
import { isValidIPAddress } from "../utils/helpers/isValidIPAddress";
|
||||
|
||||
/**
|
||||
* Constructs a new server, while also ensuring that the new server
|
||||
@@ -22,12 +20,12 @@ export function safetlyCreateUniqueServer(params: IConstructorParams): Server {
|
||||
params.ip = createUniqueRandomIp();
|
||||
}
|
||||
|
||||
if (GetServerByHostname(params.hostname) != null) {
|
||||
if (GetServer(params.hostname) != null) {
|
||||
// Use a for loop to ensure that we don't get suck in an infinite loop somehow
|
||||
let hostname: string = params.hostname;
|
||||
for (let i = 0; i < 200; ++i) {
|
||||
hostname = `${params.hostname}-${i}`;
|
||||
if (GetServerByHostname(hostname) == null) {
|
||||
if (GetServer(hostname) == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -119,31 +117,6 @@ export function prestigeHomeComputer(homeComp: Server): void {
|
||||
homeComp.messages.push(LiteratureNames.HackersStartingHandbook);
|
||||
}
|
||||
|
||||
//Returns server object with corresponding hostname
|
||||
// Relatively slow, would rather not use this a lot
|
||||
export function GetServerByHostname(hostname: string): BaseServer | null {
|
||||
for (const server of GetAllServers()) {
|
||||
if (server.hostname == hostname) {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//Get server by IP or hostname. Returns null if invalid
|
||||
export function getServer(s: string): BaseServer | null {
|
||||
if (!isValidIPAddress(s)) {
|
||||
return GetServerByHostname(s);
|
||||
}
|
||||
const server = GetServerByIP(s);
|
||||
if (server !== undefined) {
|
||||
return server;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Returns the i-th server on the specified server's network
|
||||
// A Server's serverOnNetwork property holds only the IPs. This function returns
|
||||
// the actual Server object
|
||||
@@ -153,7 +126,7 @@ export function getServerOnNetwork(server: BaseServer, i: number): BaseServer |
|
||||
return null;
|
||||
}
|
||||
|
||||
return getServer(server.serversOnNetwork[i]);
|
||||
return GetServer(server.serversOnNetwork[i]);
|
||||
}
|
||||
|
||||
export function isBackdoorInstalled(server: BaseServer): boolean {
|
||||
|
||||
Reference in New Issue
Block a user