diff --git a/src/Exploits/Unclickable.tsx b/src/Exploits/Unclickable.tsx index 3dbc2d004..7fab8d376 100644 --- a/src/Exploits/Unclickable.tsx +++ b/src/Exploits/Unclickable.tsx @@ -2,13 +2,14 @@ import React from "react"; import { use } from "../ui/Context"; import { Exploit } from "./Exploit"; +const getComputedStyle = window.getComputedStyle; export function Unclickable(): React.ReactElement { const player = use.Player(); function unclickable(event: React.MouseEvent): void { if (!event.target || !(event.target instanceof Element)) return; - const display = window.getComputedStyle(event.target as Element).display; - const visibility = window.getComputedStyle(event.target as Element).visibility; + const display = getComputedStyle(event.target as Element).display; + const visibility = getComputedStyle(event.target as Element).visibility; if (display === "none" && visibility === "hidden" && event.isTrusted) player.giveExploit(Exploit.Unclickable); } diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index c06345e03..f281d6b02 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -122,6 +122,7 @@ import { Router } from "./ui/GameRoot"; import { numeralWrapper } from "./ui/numeralFormat"; import { is2DArray } from "./utils/helpers/is2DArray"; import { convertTimeMsToTimeElapsedString } from "./utils/StringHelperFunctions"; +import { SpecialServers } from "./Server/data/SpecialServers"; import { LogBoxEvents } from "./ui/React/LogBoxManager"; import { arrayToString } from "./utils/helpers/arrayToString"; @@ -3076,6 +3077,10 @@ function NetscriptFunctions(workerScript: WorkerScript): NS { workerScript.log("installBackdoor", `Successfully installed backdoor on '${server.hostname}'`); server.backdoorInstalled = true; + + if (SpecialServers.WorldDaemon === server.hostname) { + Router.toBitVerse(false, false); + } return Promise.resolve(); }); }, diff --git a/src/Terminal/HelpText.ts b/src/Terminal/HelpText.ts index d12145cc7..0a1fb8081 100644 --- a/src/Terminal/HelpText.ts +++ b/src/Terminal/HelpText.ts @@ -14,6 +14,7 @@ export const TerminalHelpText: string[] = [ "clear Clear all text on the terminal ", "cls See 'clear' command ", "connect [hostname] Connects to a remote server", + "cp [src] [dst]: Copy a file", "download [script/text file] Downloads scripts or text files to your computer", "expr [math expression] Evaluate a mathematical expression", "free Check the machine's memory (RAM) usage", @@ -158,6 +159,7 @@ export const HelpTexts: IMap = { "to this command. Note that only servers that are immediately adjacent to the current server in the network can be connected to. To ", "see which servers can be connected to, use the 'scan' command.", ], + cp: ["cp [src] [dst]", " ", "Copy a file on this server. To copy a file to another server use scp."], download: [ "download [script/text file]", " ", diff --git a/src/Terminal/Terminal.ts b/src/Terminal/Terminal.ts index 2c710d3e2..8479455f5 100644 --- a/src/Terminal/Terminal.ts +++ b/src/Terminal/Terminal.ts @@ -41,6 +41,7 @@ import { cat } from "./commands/cat"; import { cd } from "./commands/cd"; import { check } from "./commands/check"; import { connect } from "./commands/connect"; +import { cp } from "./commands/cp"; import { download } from "./commands/download"; import { expr } from "./commands/expr"; import { free } from "./commands/free"; @@ -729,6 +730,7 @@ export class Terminal implements ITerminal { clear: () => this.clear(), cls: () => this.clear(), connect: connect, + cp: cp, download: download, expr: expr, free: free, diff --git a/src/Terminal/commands/cp.ts b/src/Terminal/commands/cp.ts new file mode 100644 index 000000000..e59244079 --- /dev/null +++ b/src/Terminal/commands/cp.ts @@ -0,0 +1,92 @@ +import { ITerminal } from "../ITerminal"; +import { IRouter } from "../../ui/Router"; +import { IPlayer } from "../../PersonObjects/IPlayer"; +import { BaseServer } from "../../Server/BaseServer"; +import { isScriptFilename } from "../../Script/isScriptFilename"; + +export function cp( + terminal: ITerminal, + router: IRouter, + player: IPlayer, + server: BaseServer, + args: (string | number)[], +): void { + try { + if (args.length !== 2) { + terminal.error("Incorrect usage of cp command. Usage: cp [src] [dst]"); + return; + } + const src = args[0] + ""; + const dst = args[1] + ""; + if (src === dst) { + terminal.error("src and dst cannot be the same"); + return; + } + const srcExt = src.slice(src.lastIndexOf(".")); + const dstExt = dst.slice(dst.lastIndexOf(".")); + if (srcExt !== dstExt) { + terminal.error("src and dst must have the same extension."); + return; + } + const filename = terminal.getFilepath(src); + if (!isScriptFilename(filename) && !filename.endsWith(".txt")) { + terminal.error("cp only works for scripts and .txt files"); + return; + } + + // Scp for txt files + if (filename.endsWith(".txt")) { + let txtFile = null; + for (let i = 0; i < server.textFiles.length; ++i) { + if (server.textFiles[i].fn === filename) { + txtFile = server.textFiles[i]; + break; + } + } + + if (txtFile === null) { + return terminal.error("No such file exists!"); + } + + const tRes = server.writeToTextFile(dst, txtFile.text); + if (!tRes.success) { + terminal.error("scp failed"); + return; + } + if (tRes.overwritten) { + terminal.print(`WARNING: ${dst} already exists and will be overwriten`); + terminal.print(`${dst} overwritten`); + return; + } + terminal.print(`${dst} copied`); + return; + } + + // Get the current script + let sourceScript = null; + for (let i = 0; i < server.scripts.length; ++i) { + if (filename == server.scripts[i].filename) { + sourceScript = server.scripts[i]; + break; + } + } + if (sourceScript == null) { + terminal.error("cp() failed. No such script exists"); + return; + } + + const sRes = server.writeToScriptFile(dst, sourceScript.code); + if (!sRes.success) { + terminal.error(`scp failed`); + return; + } + if (sRes.overwritten) { + terminal.print(`WARNING: ${dst} already exists and will be overwritten`); + terminal.print(`${dst} overwritten`); + return; + } + terminal.print(`${dst} copied`); + } catch (e) { + terminal.error(e + ""); + } +}