mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-23 08:03:48 +01:00
Add hostname safety
This commit is contained in:
parent
358f5ee8ee
commit
c8db709287
@ -120,9 +120,10 @@ export function ls(
|
|||||||
interface ClickableScriptRowProps {
|
interface ClickableScriptRowProps {
|
||||||
row: string;
|
row: string;
|
||||||
prefix: string;
|
prefix: string;
|
||||||
|
hostname: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ClickableScriptRow({ row, prefix }: ClickableScriptRowProps): React.ReactElement {
|
function ClickableScriptRow({ row, prefix, hostname }: ClickableScriptRowProps): React.ReactElement {
|
||||||
const classes = makeStyles((theme: Theme) =>
|
const classes = makeStyles((theme: Theme) =>
|
||||||
createStyles({
|
createStyles({
|
||||||
scriptLinksWrap: {
|
scriptLinksWrap: {
|
||||||
@ -144,6 +145,9 @@ export function ls(
|
|||||||
.filter((x) => !!x);
|
.filter((x) => !!x);
|
||||||
|
|
||||||
function onScriptLinkClick(filename: string): void {
|
function onScriptLinkClick(filename: string): void {
|
||||||
|
if (player.getCurrentServer().hostname !== hostname) {
|
||||||
|
return terminal.error(`File is not on this server, connect to ${hostname} and try again`);
|
||||||
|
}
|
||||||
if (filename.startsWith("/")) filename = filename.slice(1);
|
if (filename.startsWith("/")) filename = filename.slice(1);
|
||||||
const filepath = terminal.getFilepath(`${prefix}${filename}`);
|
const filepath = terminal.getFilepath(`${prefix}${filename}`);
|
||||||
const code = toString(terminal.getScript(player, filepath)?.code);
|
const code = toString(terminal.getScript(player, filepath)?.code);
|
||||||
@ -177,7 +181,7 @@ export function ls(
|
|||||||
terminal.print(row);
|
terminal.print(row);
|
||||||
} else {
|
} else {
|
||||||
if (linked) {
|
if (linked) {
|
||||||
terminal.printRaw(<ClickableScriptRow row={row} prefix={prefix} />);
|
terminal.printRaw(<ClickableScriptRow row={row} prefix={prefix} hostname={server.hostname} />);
|
||||||
} else {
|
} else {
|
||||||
terminal.printRaw(<span style={style}>{row}</span>);
|
terminal.printRaw(<span style={style}>{row}</span>);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user