diff --git a/markdown/bitburner.ns.renamepurchasedserver.md b/markdown/bitburner.ns.renamepurchasedserver.md index 9538662f6..210a95f71 100644 --- a/markdown/bitburner.ns.renamepurchasedserver.md +++ b/markdown/bitburner.ns.renamepurchasedserver.md @@ -23,9 +23,9 @@ renamePurchasedServer(hostname: string, newName: string): boolean; boolean -True if the upgrade succeeded, and false otherwise. +True if successful, and false otherwise. ## Remarks -RAM cost: 2.00 GB +RAM cost: 0 GB diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 6dcdaf7b2..372474131 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -1270,7 +1270,13 @@ export const ns: InternalAPI = { renamePurchasedServer: (ctx) => (_hostname, _newName) => { const hostname = helpers.string(ctx, "hostname", _hostname); const newName = helpers.string(ctx, "newName", _newName); - renamePurchasedServer(hostname, newName); + try { + renamePurchasedServer(hostname, newName); + return true; + } catch (err) { + helpers.log(ctx, () => String(err)); + return false; + } }, deleteServer: (ctx) => (_name) => { diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 6a8c378cb..39b0b8d35 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6086,8 +6086,9 @@ export interface NS { * * @param hostname - Current server hostname. * @param newName - New server hostname. + * @returns True if successful, and false otherwise. */ - renamePurchasedServer(hostname: string, newName: string): void; + renamePurchasedServer(hostname: string, newName: string): boolean; /** * Delete a purchased server. diff --git a/src/Server/ServerPurchases.ts b/src/Server/ServerPurchases.ts index 879b0912b..ff045ab5f 100644 --- a/src/Server/ServerPurchases.ts +++ b/src/Server/ServerPurchases.ts @@ -61,7 +61,7 @@ export const upgradePurchasedServer = (hostname: string, ram: number): void => { export const renamePurchasedServer = (hostname: string, newName: string): void => { const server = GetServer(hostname); - if (!server) throw new Error(`Server '${newName}' doesn't exists.`); + if (!server) throw new Error(`Server '${hostname}' doesn't exists.`); if (GetServer(newName)) throw new Error(`Server '${newName}' already exists.`); if (!Player.purchasedServers.includes(hostname)) throw new Error(`Server '${hostname}' is not a player server.`); const replace = (arr: string[], old: string, next: string): string[] => {