mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 01:23:49 +01:00
Merge pull request #2010 from hexnaught/server-purchase-naming-patch
Fix issue of space in server name and server counting when made with same name
This commit is contained in:
commit
a76f67ade5
@ -16,22 +16,25 @@ import { isValidNumber } from "../utils/helpers/isValidNumber";
|
|||||||
* does not have a duplicate hostname/ip.
|
* does not have a duplicate hostname/ip.
|
||||||
*/
|
*/
|
||||||
export function safetlyCreateUniqueServer(params: IConstructorParams): Server {
|
export function safetlyCreateUniqueServer(params: IConstructorParams): Server {
|
||||||
|
let hostname: string = params.hostname.replace(/ /g, `-`);
|
||||||
|
|
||||||
if (params.ip != null && ipExists(params.ip)) {
|
if (params.ip != null && ipExists(params.ip)) {
|
||||||
params.ip = createUniqueRandomIp();
|
params.ip = createUniqueRandomIp();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetServer(params.hostname) != null) {
|
if (GetServer(hostname) != null) {
|
||||||
|
hostname = `${hostname}-0`;
|
||||||
|
|
||||||
// Use a for loop to ensure that we don't get suck in an infinite loop somehow
|
// 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) {
|
for (let i = 0; i < 200; ++i) {
|
||||||
hostname = `${params.hostname}-${i}`;
|
hostname = hostname.replace(/-[0-9]+$/, `-${i}`);
|
||||||
if (GetServer(hostname) == null) {
|
if (GetServer(hostname) == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
params.hostname = hostname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
params.hostname = hostname;
|
||||||
return new Server(params);
|
return new Server(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ export function purchaseServer(hostname: string, ram: number, cost: number, p: I
|
|||||||
|
|
||||||
p.loseMoney(cost, "servers");
|
p.loseMoney(cost, "servers");
|
||||||
|
|
||||||
dialogBoxCreate("Server successfully purchased with hostname " + hostname);
|
dialogBoxCreate("Server successfully purchased with hostname " + newServ.hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manually upgrade RAM on home computer (NOT through Netscript)
|
// Manually upgrade RAM on home computer (NOT through Netscript)
|
||||||
|
Loading…
Reference in New Issue
Block a user