From 6288eec6d70b7f30fd1f4ad96beb4ff3ecb7bc26 Mon Sep 17 00:00:00 2001 From: Yichi Zhang Date: Tue, 27 Feb 2024 12:34:36 -0800 Subject: [PATCH] HACKNET: Disallow negative `count` argument for spendHashes (#1127) * disallow buying a negative amount of an upgrade * allow 0 silently --- src/NetscriptFunctions/Hacknet.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/NetscriptFunctions/Hacknet.ts b/src/NetscriptFunctions/Hacknet.ts index bb93b87e4..cbe6a433a 100644 --- a/src/NetscriptFunctions/Hacknet.ts +++ b/src/NetscriptFunctions/Hacknet.ts @@ -201,7 +201,11 @@ export function NetscriptHacknet(): InternalAPI { (_upgName, _upgTarget = "", _count = 1) => { const upgName = helpers.string(ctx, "upgName", _upgName); const upgTarget = helpers.string(ctx, "upgTarget", _upgTarget); - const count = helpers.number(ctx, "count", _count); + const count = Math.floor(helpers.number(ctx, "count", _count)); + // TODO (3.0.0): use helpers.positiveInteger + if (!(count >= 0)) { + throw helpers.errorMessage(ctx, "count may not be negative"); + } if (!hasHacknetServers()) { return false; }