HACKNET: Disallow negative count argument for spendHashes (#1127)

* disallow buying a negative amount of an upgrade
* allow 0 silently
This commit is contained in:
Yichi Zhang 2024-02-27 12:34:36 -08:00 committed by GitHub
parent 3d6692b292
commit 6288eec6d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -201,7 +201,11 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
(_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;
}