fix a few things about getRecentScritps

This commit is contained in:
Olivier Gagnon 2022-04-12 14:45:48 -04:00
parent a9b03f34ab
commit 52e01fc026
7 changed files with 16 additions and 30 deletions

@ -15,6 +15,7 @@ export const RamCostConstants: IMap<number> = {
ScriptWeakenRamCost: 0.15,
ScriptWeakenAnalyzeRamCost: 1,
ScriptScanRamCost: 0.2,
ScriptRecentScriptsRamCost: 0.2,
ScriptPortProgramRamCost: 0.05,
ScriptRunRamCost: 1.0,
ScriptExecRamCost: 1.3,
@ -140,7 +141,7 @@ export const RamCosts: IMap<any> = {
scp: RamCostConstants.ScriptScpRamCost,
ls: RamCostConstants.ScriptScanRamCost,
ps: RamCostConstants.ScriptScanRamCost,
getRecentScripts: RamCostConstants.ScriptScanRamCost,
getRecentScripts: RamCostConstants.ScriptRecentScriptsRamCost,
hasRootAccess: RamCostConstants.ScriptHasRootAccessRamCost,
getIp: RamCostConstants.ScriptGetHostnameRamCost,
getHostname: RamCostConstants.ScriptGetHostnameRamCost,

@ -5,15 +5,11 @@ import { WorkerScript } from "./WorkerScript";
export const recentScripts: RecentScript[] = [];
export function AddRecentScript(workerScript: WorkerScript): void {
if (recentScripts.find((r) => r.pid === workerScript.pid)) return;
if (recentScripts.find((r) => r.runningScript.pid === workerScript.pid)) return;
const killedTime = new Date();
recentScripts.unshift({
filename: workerScript.name,
args: workerScript.args,
pid: workerScript.pid,
timestamp: killedTime,
timestampEpoch: killedTime.getTime(),
timeOfDeath: killedTime,
runningScript: workerScript.scriptRef,
});
@ -23,10 +19,6 @@ export function AddRecentScript(workerScript: WorkerScript): void {
}
export interface RecentScript {
filename: string;
args: string[];
pid: number;
timestamp: Date;
timestampEpoch: number;
timeOfDeath: Date;
runningScript: RunningScript;
}

@ -1462,7 +1462,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
},
getRecentScripts: function (): IRecentScript[] {
updateDynamicRam("getRecentScripts", getRamCost(Player, "getRecentScripts"));
return recentScripts.map((rs) => ({ ...rs, runningScript: createPublicRunningScript(rs.runningScript) }));
return recentScripts.map((rs) => ({
timeOfDeath: rs.timeOfDeath,
...createPublicRunningScript(rs.runningScript),
}));
},
ps: function (_hostname: unknown = workerScript.hostname): ProcessInfo[] {
updateDynamicRam("ps", getRamCost(Player, "ps"));

@ -136,19 +136,9 @@ export interface RunningScript {
/**
* @public
*/
interface RecentScript {
/** Arguments the script was called with */
args: string[];
/** Filename of the script */
filename: string;
/** Process ID. Must be an integer */
pid: number;
export interface RecentScript extends RunningScript {
/** Timestamp of when the script was killed */
timestamp: Date;
/** Numeric epoch of timestamp */
timestampEpoch: number;
/** An inactive copy of the last `RunningScript` associated to the script */
runningScript: RunningScript;
timeOfDeath: Date;
}
/**

@ -57,8 +57,8 @@ export function RecentScriptAccordion(props: IProps): React.ReactElement {
<ListItemText
primary={
<Typography>
{recentScript.filename} (died{" "}
{convertTimeMsToTimeElapsedString(new Date().getTime() - recentScript.timestamp.getTime())} ago)
{recentScript.runningScript.filename} (died{" "}
{convertTimeMsToTimeElapsedString(new Date().getTime() - recentScript.timeOfDeath.getTime())} ago)
</Typography>
}
/>
@ -78,7 +78,7 @@ export function RecentScriptAccordion(props: IProps): React.ReactElement {
</TableRow>
<TableRow>
<TableCell className={classes.noborder} colSpan={2}>
<Typography> Args: {arrayToString(recentScript.args)}</Typography>
<Typography> Args: {arrayToString(recentScript.runningScript.args)}</Typography>
</TableCell>
</TableRow>
<TableRow>

@ -13,7 +13,7 @@ export function RecentScriptsPage(): React.ReactElement {
<>
<Typography>List of all recently killed scripts.</Typography>
{recentScripts.map((r) => (
<RecentScriptAccordion key={r.pid} recentScript={r} />
<RecentScriptAccordion key={r.runningScript.pid} recentScript={r} />
))}
</>
);

@ -196,7 +196,7 @@ export function GameOptionsRoot(props: IProps): React.ReactElement {
value={recentScriptsSize}
onChange={handleRecentScriptsSizeChange}
step={25}
min={25}
min={0}
max={500}
valueLabelDisplay="auto"
/>