2021-09-16 01:50:44 +02:00
|
|
|
import { ITerminal } from "../ITerminal";
|
2021-09-17 08:58:02 +02:00
|
|
|
import { IRouter } from "../../ui/Router";
|
2021-09-16 01:50:44 +02:00
|
|
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
|
|
|
import { BaseServer } from "../../Server/BaseServer";
|
|
|
|
import { showMessage } from "../../Message/MessageHelpers";
|
|
|
|
import { showLiterature } from "../../Literature/LiteratureHelpers";
|
|
|
|
|
|
|
|
export function cat(
|
|
|
|
terminal: ITerminal,
|
2021-09-17 08:58:02 +02:00
|
|
|
router: IRouter,
|
2021-09-16 01:50:44 +02:00
|
|
|
player: IPlayer,
|
|
|
|
server: BaseServer,
|
2021-12-03 20:44:32 +01:00
|
|
|
args: (string | number | boolean)[],
|
2021-09-16 01:50:44 +02:00
|
|
|
): void {
|
|
|
|
if (args.length !== 1) {
|
|
|
|
terminal.error("Incorrect usage of cat command. Usage: cat [file]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const filename = terminal.getFilepath(args[0] + "");
|
|
|
|
if (!filename.endsWith(".msg") && !filename.endsWith(".lit") && !filename.endsWith(".txt")) {
|
|
|
|
terminal.error(
|
|
|
|
"Only .msg, .txt, and .lit files are viewable with cat (filename must end with .msg, .txt, or .lit)",
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filename.endsWith(".msg") || filename.endsWith(".lit")) {
|
|
|
|
for (let i = 0; i < server.messages.length; ++i) {
|
|
|
|
if (filename.endsWith(".lit") && server.messages[i] === filename) {
|
|
|
|
const file = server.messages[i];
|
2021-10-14 08:07:05 +02:00
|
|
|
if (file.endsWith(".msg")) throw new Error(".lit file should not be a .msg");
|
2021-09-16 01:50:44 +02:00
|
|
|
showLiterature(file);
|
|
|
|
return;
|
|
|
|
} else if (filename.endsWith(".msg")) {
|
2021-10-14 08:07:05 +02:00
|
|
|
const file = server.messages[i];
|
|
|
|
if (file !== filename) continue;
|
2021-09-18 08:21:48 +02:00
|
|
|
showMessage(file);
|
|
|
|
return;
|
2021-09-16 01:50:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (filename.endsWith(".txt")) {
|
|
|
|
const txt = terminal.getTextFile(player, filename);
|
|
|
|
if (txt != null) {
|
|
|
|
txt.show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
terminal.error(`No such file ${filename}`);
|
|
|
|
}
|