From 342dea77fa636143c80633f67de97021ee008504 Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Mon, 9 Mar 2026 03:57:13 +0700 Subject: [PATCH] API: Make ns.cloud.purchaseServer() and ns.cloud.deleteServer() use hostname as provided (#2560) --- src/Locations/ui/PurchaseServerModal.tsx | 4 +++- src/NetscriptFunctions/Cloud.ts | 6 ++---- src/Server/ServerHelpers.ts | 2 +- src/utils/APIBreaks/3.0.0.ts | 7 +++++++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Locations/ui/PurchaseServerModal.tsx b/src/Locations/ui/PurchaseServerModal.tsx index f4f4c02ad..614935b1d 100644 --- a/src/Locations/ui/PurchaseServerModal.tsx +++ b/src/Locations/ui/PurchaseServerModal.tsx @@ -30,7 +30,9 @@ export function PurchaseServerModal(props: IProps): React.ReactElement { } function onChange(event: React.ChangeEvent): void { - setHostname(event.target.value); + // Players may accidentally include whitespace in the hostname and later wonder why they cannot use the cloud APIs. + // For example, they intend the hostname to be "foobar", but type "foobar " or "foo bar" instead. + setHostname(event.target.value.replace(/\s+/g, "")); } return ( diff --git a/src/NetscriptFunctions/Cloud.ts b/src/NetscriptFunctions/Cloud.ts index 0affde0c0..408f19ed6 100644 --- a/src/NetscriptFunctions/Cloud.ts +++ b/src/NetscriptFunctions/Cloud.ts @@ -33,9 +33,8 @@ export function NetscriptCloud(): InternalAPI { return cost; }, purchaseServer: (ctx) => (_hostname, _ram) => { - let hostname = helpers.string(ctx, "hostname", _hostname); + const hostname = helpers.string(ctx, "hostname", _hostname); const ram = helpers.number(ctx, "ram", _ram); - hostname = hostname.replace(/\s+/g, ""); if (hostname === "") { helpers.log(ctx, () => `Invalid argument: hostname='${hostname}' is an empty string.`); return ""; @@ -126,8 +125,7 @@ export function NetscriptCloud(): InternalAPI { }, deleteServer: (ctx) => (_name) => { - let host = helpers.string(ctx, "name", _name); - host = host.replace(/\s\s+/g, ""); + const host = helpers.string(ctx, "name", _name); const server = helpers.getNormalServer(ctx, host); const hostname = server.hostname; diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index bd61e3705..f9bb7fad6 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -40,7 +40,7 @@ export enum ServerOwnershipType { * does not have a duplicate hostname/ip. */ export function safelyCreateUniqueServer(params: StandardServerConstructorParams): Server { - let hostname: string = params.hostname.replace(/ /g, `-`); + let hostname = params.hostname; if (params.ip != null && ipExists(params.ip)) { params.ip = createUniqueRandomIp(); diff --git a/src/utils/APIBreaks/3.0.0.ts b/src/utils/APIBreaks/3.0.0.ts index 239bcbbc6..e420f6b3f 100644 --- a/src/utils/APIBreaks/3.0.0.ts +++ b/src/utils/APIBreaks/3.0.0.ts @@ -575,5 +575,12 @@ export const breakingChanges300: VersionBreakingChange = { info: "ns.sleeve.travel() did not cancel the sleeve's current task. It does now.", showWarning: false, }, + { + brokenAPIs: [{ name: "ns.cloud.purchaseServer" }, { name: "ns.cloud.deleteServer" }], + info: + "ns.cloud.purchaseServer() and ns.cloud.deleteServer() previously removed whitespace from the provided hostname inconsistently.\n" + + "They now use the hostname as provided.", + showWarning: false, + }, ], };