mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 01:33:54 +01:00
Merge pull request #2317 from nickofolas/validate-ram-purchase
Validate RAM amount in ns.purchaseServer()
This commit is contained in:
commit
772317a4f1
@ -1639,7 +1639,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
|
|
||||||
const cost = getPurchaseServerCost(ram);
|
const cost = getPurchaseServerCost(ram);
|
||||||
if (cost === Infinity) {
|
if (cost === Infinity) {
|
||||||
workerScript.log("purchaseServer", () => `Invalid argument: ram='${ram}' must be power of 2`);
|
workerScript.log("purchaseServer", () => `Invalid argument: ram='${ram}' must be a positive power of 2`);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import { isPowerOfTwo } from "../utils/helpers/isPowerOfTwo";
|
|||||||
*/
|
*/
|
||||||
export function getPurchaseServerCost(ram: number): number {
|
export function getPurchaseServerCost(ram: number): number {
|
||||||
const sanitizedRam = Math.round(ram);
|
const sanitizedRam = Math.round(ram);
|
||||||
if (isNaN(sanitizedRam) || !isPowerOfTwo(sanitizedRam)) {
|
if (isNaN(sanitizedRam) || !isPowerOfTwo(sanitizedRam) || !(Math.sign(sanitizedRam) === 1)) {
|
||||||
return Infinity;
|
return Infinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user