From 40babcb2ee674f445ec2e364f49a75b83da9a1df Mon Sep 17 00:00:00 2001 From: omuretsu <84951833+Snarling@users.noreply.github.com> Date: Fri, 26 May 2023 14:59:31 -0400 Subject: [PATCH] more hotfixing Hotfixed usage tips for alias Hotfixed prestigeHomeComputer to avoid crashing prestige Added checking at startWorkerScript to try and find instances where script is launched on wrong server Fixed corp issue with multibuy not providing multibenefits --- src/Corporation/Corporation.tsx | 2 +- src/NetscriptWorker.ts | 7 +++++++ src/Server/ServerHelpers.ts | 13 ++++++++++++- src/Terminal/HelpText.ts | 10 +++++----- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Corporation/Corporation.tsx b/src/Corporation/Corporation.tsx index 383fc34b5..0279c372c 100644 --- a/src/Corporation/Corporation.tsx +++ b/src/Corporation/Corporation.tsx @@ -305,7 +305,7 @@ export class Corporation { if (this.funds < totalCost) return `Not enough funds to purchase ${amount} of upgrade ${upgradeName}.`; this.funds -= totalCost; this.upgrades[upgradeName].level += amount; - this.upgrades[upgradeName].value += upgrade.benefit; + this.upgrades[upgradeName].value += upgrade.benefit * amount; // Apply effects for upgrades if (upgradeName === CorpUpgradeName.SmartStorage) { diff --git a/src/NetscriptWorker.ts b/src/NetscriptWorker.ts index 8b1645426..bad97bc5c 100644 --- a/src/NetscriptWorker.ts +++ b/src/NetscriptWorker.ts @@ -261,6 +261,13 @@ function processNetscript1Imports(code: string, workerScript: WorkerScript): { c * it is active */ export function startWorkerScript(runningScript: RunningScript, server: BaseServer, parent?: WorkerScript): number { + if (server.hostname !== runningScript.server) { + // Temporarily adding a check here to see if this ever triggers + console.error( + `Tried to launch a worker script on a different server ${server.hostname} than the runningScript's server ${runningScript.server}`, + ); + return 0; + } if (createAndAddWorkerScript(runningScript, server, parent)) { // Push onto runningScripts. // This has to come after createAndAddWorkerScript() because that fn updates RAM usage diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index d202eab28..67b6f26a7 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -11,6 +11,8 @@ import { LiteratureName } from "../Literature/data/LiteratureNames"; import { Person as IPerson } from "@nsdefs"; import { isValidNumber } from "../utils/helpers/isValidNumber"; import { Server as IServer } from "@nsdefs"; +import { workerScripts } from "../Netscript/WorkerScripts"; +import { killWorkerScriptByPid } from "../Netscript/killWorkerScript"; /** * Constructs a new server, while also ensuring that the new server @@ -263,7 +265,16 @@ export function prestigeHomeComputer(homeComp: Server): void { homeComp.messages.length = 0; //Remove .lit and .msg files homeComp.messages.push(LiteratureName.HackersStartingHandbook); if (homeComp.runningScriptMap.size !== 0) { - throw new Error("All programs weren't already killed!"); + // Temporary verbose logging section to gather data on a bug + console.error("Some runningScripts were still present on home during prestige"); + for (const [scriptKey, byPidMap] of homeComp.runningScriptMap) { + console.error(`script key: ${scriptKey}: ${byPidMap.size} scripts`); + for (const pid of byPidMap.keys()) { + if (workerScripts.has(pid)) killWorkerScriptByPid(pid); + } + byPidMap.clear(); + } + homeComp.runningScriptMap.clear(); } } diff --git a/src/Terminal/HelpText.ts b/src/Terminal/HelpText.ts index 57a67506c..02e1a7820 100644 --- a/src/Terminal/HelpText.ts +++ b/src/Terminal/HelpText.ts @@ -1,7 +1,7 @@ export const TerminalHelpText: string[] = [ "Type 'help name' to learn more about the command ", " ", - ' alias [-g] [name="value"] Create or display Terminal aliases', + ' alias [-g] ["name=value"] Create or display Terminal aliases', " analyze Get information about the current machine ", " backdoor Install a backdoor on the current machine ", " buy [-l/-a/program] Purchase a program through the Dark Web", @@ -69,20 +69,20 @@ const TemplatedHelpTexts: Record string[]> = { export const HelpTexts: Record = { alias: [ - 'Usage: alias [-g] [name="value"] ', + 'Usage: alias [-g] ["name=value"] ', " ", "Create or display aliases. An alias enables a replacement of a word with another string. ", "It can be used to abbreviate a commonly used command, or commonly used parts of a command. The NAME ", "of an alias defines the word that will be replaced, while the VALUE defines what it will be replaced by. For example, ", "you could create the alias 'nuke' for the Terminal command 'run NUKE.exe' using the following: ", " ", - ' alias nuke="run NUKE.exe"', + ' alias "nuke=run NUKE.exe"', " ", "Then, to run the NUKE.exe program you would just have to enter 'nuke' in Terminal rather than the full command. ", "It is important to note that 'default' aliases will only be substituted for the first word of a Terminal command. For ", "example, if the following alias was set: ", " ", - ' alias worm="HTTPWorm.exe"', + ' alias "worm=HTTPWorm.exe"', " ", "and then you tried to run the following terminal command: ", " ", @@ -91,7 +91,7 @@ export const HelpTexts: Record = { "This would fail because the worm alias is not the first word of a Terminal command. To allow an alias to be substituted ", "anywhere in a Terminal command, rather than just the first word, you must set it to be a global alias using the -g flag: ", " ", - ' alias -g worm="HTTPWorm.exe"', + ' alias -g "worm=HTTPWorm.exe"', " ", "Now, the 'worm' alias will be substituted anytime it shows up as an individual word in a Terminal command. ", " ",