From e07b92a408cb65363aed2d7c35eec5938b09da2f Mon Sep 17 00:00:00 2001 From: TheMas3212 Date: Fri, 15 Apr 2022 02:00:34 +1000 Subject: [PATCH 1/2] fix 2993 sleeve.travel with invalid city names --- src/NetscriptFunctions/Sleeve.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/NetscriptFunctions/Sleeve.ts b/src/NetscriptFunctions/Sleeve.ts index 6b7751001..214f9e55c 100644 --- a/src/NetscriptFunctions/Sleeve.ts +++ b/src/NetscriptFunctions/Sleeve.ts @@ -99,7 +99,17 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel const cityName = helper.string("travel", "cityName", _cityName); checkSleeveAPIAccess("travel"); checkSleeveNumber("travel", sleeveNumber); - return player.sleeves[sleeveNumber].travel(player, cityName as CityName); + switch (cityName) { + case CityName.Aevum: + case CityName.Chongqing: + case CityName.Sector12: + case CityName.NewTokyo: + case CityName.Ishima: + case CityName.Volhaven: + return player.sleeves[sleeveNumber].travel(player, cityName as CityName); + default: + throw helper.makeRuntimeErrorMsg("sleeve.setToCompanyWork", `Invalid city name: '${cityName}'.`); + } }, setToCompanyWork: function (_sleeveNumber: unknown, acompanyName: unknown): boolean { updateRam("setToCompanyWork"); From de3359dfade26f1f9e6805927497b6277c263ef5 Mon Sep 17 00:00:00 2001 From: TheMas3212 Date: Fri, 15 Apr 2022 02:07:47 +1000 Subject: [PATCH 2/2] switch to checkEnum --- src/NetscriptFunctions/Sleeve.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/NetscriptFunctions/Sleeve.ts b/src/NetscriptFunctions/Sleeve.ts index 214f9e55c..42ca7bac0 100644 --- a/src/NetscriptFunctions/Sleeve.ts +++ b/src/NetscriptFunctions/Sleeve.ts @@ -16,6 +16,7 @@ import { SleeveSkills, SleeveTask, } from "../ScriptEditor/NetscriptDefinitions"; +import { checkEnum } from "../utils/helpers/checkEnum"; export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, helper: INetscriptHelper): ISleeve { const checkSleeveAPIAccess = function (func: string): void { @@ -99,16 +100,10 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel const cityName = helper.string("travel", "cityName", _cityName); checkSleeveAPIAccess("travel"); checkSleeveNumber("travel", sleeveNumber); - switch (cityName) { - case CityName.Aevum: - case CityName.Chongqing: - case CityName.Sector12: - case CityName.NewTokyo: - case CityName.Ishima: - case CityName.Volhaven: - return player.sleeves[sleeveNumber].travel(player, cityName as CityName); - default: - throw helper.makeRuntimeErrorMsg("sleeve.setToCompanyWork", `Invalid city name: '${cityName}'.`); + if (checkEnum(CityName, cityName)) { + return player.sleeves[sleeveNumber].travel(player, cityName as CityName); + } else { + throw helper.makeRuntimeErrorMsg("sleeve.setToCompanyWork", `Invalid city name: '${cityName}'.`); } }, setToCompanyWork: function (_sleeveNumber: unknown, acompanyName: unknown): boolean {