renameServer changes

* Update doc error, regenerate docs
* Update a bad error message in renamePurchasedServer@serverPurchases.ts
* restore true/false return (removed in #450 due to miscommunication)
This commit is contained in:
omuretsu 2023-03-28 16:10:24 -04:00
parent eb8bcd00e3
commit 798da75d83
4 changed files with 12 additions and 5 deletions

@ -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

@ -1270,7 +1270,13 @@ export const ns: InternalAPI<NSFull> = {
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) => {

@ -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.

@ -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[] => {