mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 23:08:36 +02:00
API: Make ns.cloud.purchaseServer() and ns.cloud.deleteServer() use hostname as provided (#2560)
This commit is contained in:
@@ -30,7 +30,9 @@ export function PurchaseServerModal(props: IProps): React.ReactElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {
|
function onChange(event: React.ChangeEvent<HTMLInputElement>): 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 (
|
return (
|
||||||
|
|||||||
@@ -33,9 +33,8 @@ export function NetscriptCloud(): InternalAPI<Cloud> {
|
|||||||
return cost;
|
return cost;
|
||||||
},
|
},
|
||||||
purchaseServer: (ctx) => (_hostname, _ram) => {
|
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);
|
const ram = helpers.number(ctx, "ram", _ram);
|
||||||
hostname = hostname.replace(/\s+/g, "");
|
|
||||||
if (hostname === "") {
|
if (hostname === "") {
|
||||||
helpers.log(ctx, () => `Invalid argument: hostname='${hostname}' is an empty string.`);
|
helpers.log(ctx, () => `Invalid argument: hostname='${hostname}' is an empty string.`);
|
||||||
return "";
|
return "";
|
||||||
@@ -126,8 +125,7 @@ export function NetscriptCloud(): InternalAPI<Cloud> {
|
|||||||
},
|
},
|
||||||
|
|
||||||
deleteServer: (ctx) => (_name) => {
|
deleteServer: (ctx) => (_name) => {
|
||||||
let host = helpers.string(ctx, "name", _name);
|
const host = helpers.string(ctx, "name", _name);
|
||||||
host = host.replace(/\s\s+/g, "");
|
|
||||||
const server = helpers.getNormalServer(ctx, host);
|
const server = helpers.getNormalServer(ctx, host);
|
||||||
const hostname = server.hostname;
|
const hostname = server.hostname;
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export enum ServerOwnershipType {
|
|||||||
* does not have a duplicate hostname/ip.
|
* does not have a duplicate hostname/ip.
|
||||||
*/
|
*/
|
||||||
export function safelyCreateUniqueServer(params: StandardServerConstructorParams): Server {
|
export function safelyCreateUniqueServer(params: StandardServerConstructorParams): Server {
|
||||||
let hostname: string = params.hostname.replace(/ /g, `-`);
|
let hostname = params.hostname;
|
||||||
|
|
||||||
if (params.ip != null && ipExists(params.ip)) {
|
if (params.ip != null && ipExists(params.ip)) {
|
||||||
params.ip = createUniqueRandomIp();
|
params.ip = createUniqueRandomIp();
|
||||||
|
|||||||
@@ -575,5 +575,12 @@ export const breakingChanges300: VersionBreakingChange = {
|
|||||||
info: "ns.sleeve.travel() did not cancel the sleeve's current task. It does now.",
|
info: "ns.sleeve.travel() did not cancel the sleeve's current task. It does now.",
|
||||||
showWarning: false,
|
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,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user