2019-04-10 08:07:12 +02:00
|
|
|
import {
|
|
|
|
Aliases,
|
|
|
|
GlobalAliases
|
|
|
|
} from "../Alias";
|
|
|
|
import { DarkWebItems } from "../DarkWeb/DarkWebItems";
|
|
|
|
import { Message } from "../Message/Message";
|
|
|
|
import { IPlayer } from "../PersonObjects/IPlayer"
|
|
|
|
import { AllServers } from "../Server/AllServers";
|
|
|
|
|
|
|
|
// An array of all Terminal commands
|
|
|
|
const commands = [
|
|
|
|
"alias",
|
|
|
|
"analyze",
|
|
|
|
"cat",
|
|
|
|
"cd",
|
|
|
|
"check",
|
|
|
|
"clear",
|
|
|
|
"cls",
|
|
|
|
"connect",
|
|
|
|
"download",
|
|
|
|
"expr",
|
|
|
|
"free",
|
|
|
|
"hack",
|
|
|
|
"help",
|
|
|
|
"home",
|
|
|
|
"hostname",
|
|
|
|
"ifconfig",
|
|
|
|
"kill",
|
|
|
|
"killall",
|
|
|
|
"ls",
|
|
|
|
"lscpu",
|
|
|
|
"mem",
|
|
|
|
"mv",
|
|
|
|
"nano",
|
|
|
|
"ps",
|
|
|
|
"rm",
|
|
|
|
"run",
|
|
|
|
"scan",
|
|
|
|
"scan-analyze",
|
|
|
|
"scp",
|
|
|
|
"sudov",
|
|
|
|
"tail",
|
|
|
|
"theme",
|
|
|
|
"top"
|
|
|
|
];
|
2019-04-05 11:08:41 +02:00
|
|
|
|
|
|
|
export function determineAllPossibilitiesForTabCompletion(p: IPlayer, input: string, index: number=0): string[] {
|
|
|
|
let allPos: string[] = [];
|
|
|
|
allPos = allPos.concat(Object.keys(GlobalAliases));
|
|
|
|
const currServ = p.getCurrentServer();
|
|
|
|
const homeComputer = p.getHomeComputer();
|
|
|
|
input = input.toLowerCase();
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
// Helper functions
|
|
|
|
function addAllCodingContracts() {
|
|
|
|
for (const cct of currServ.contracts) {
|
|
|
|
allPos.push(cct.fn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addAllLitFiles() {
|
|
|
|
for (const file of currServ.messages) {
|
|
|
|
if (!(file instanceof Message)) {
|
|
|
|
allPos.push(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addAllMessages() {
|
|
|
|
for (const file of currServ.messages) {
|
|
|
|
if (file instanceof Message) {
|
|
|
|
allPos.push(file.filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addAllPrograms() {
|
2019-04-13 01:52:59 +02:00
|
|
|
for (const program of homeComputer.programs) {
|
2019-04-10 08:07:12 +02:00
|
|
|
allPos.push(program);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addAllScripts() {
|
|
|
|
for (const script of currServ.scripts) {
|
|
|
|
allPos.push(script.filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addAllTextFiles() {
|
|
|
|
for (const txt of currServ.textFiles) {
|
|
|
|
allPos.push(txt.fn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isCommand(cmd: string) {
|
|
|
|
let t_cmd = cmd;
|
|
|
|
if (!t_cmd.endsWith(" ")) {
|
|
|
|
t_cmd += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
return input.startsWith(t_cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the command starts with './' and the index == -1, then the user
|
|
|
|
* has input ./partialexecutablename so autocomplete the script or program.
|
|
|
|
* Put './' in front of each script/executable
|
|
|
|
*/
|
|
|
|
if (isCommand("./") && index == -1) {
|
2019-04-05 11:08:41 +02:00
|
|
|
//All programs and scripts
|
|
|
|
for (var i = 0; i < currServ.scripts.length; ++i) {
|
|
|
|
allPos.push("./" + currServ.scripts[i].filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Programs are on home computer
|
|
|
|
for(var i = 0; i < homeComputer.programs.length; ++i) {
|
|
|
|
allPos.push("./" + homeComputer.programs[i]);
|
|
|
|
}
|
|
|
|
return allPos;
|
|
|
|
}
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
// Autocomplete the command
|
2019-04-05 11:08:41 +02:00
|
|
|
if (index == -1) {
|
2019-04-10 08:07:12 +02:00
|
|
|
return commands.concat(Object.keys(Aliases)).concat(Object.keys(GlobalAliases));
|
2019-04-05 11:08:41 +02:00
|
|
|
}
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
if (isCommand("buy")) {
|
2019-04-05 11:08:41 +02:00
|
|
|
let options = [];
|
|
|
|
for (const i in DarkWebItems) {
|
|
|
|
const item = DarkWebItems[i]
|
|
|
|
options.push(item.program);
|
|
|
|
}
|
2019-04-10 08:07:12 +02:00
|
|
|
|
2019-04-05 11:08:41 +02:00
|
|
|
return options.concat(Object.keys(GlobalAliases));
|
|
|
|
}
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
if (isCommand("scp") && index === 1) {
|
|
|
|
for (const iphostname in AllServers) {
|
|
|
|
allPos.push(AllServers[iphostname].ip);
|
|
|
|
allPos.push(AllServers[iphostname].hostname);
|
2019-04-05 11:08:41 +02:00
|
|
|
}
|
2019-04-10 08:07:12 +02:00
|
|
|
|
|
|
|
return allPos;
|
2019-04-05 11:08:41 +02:00
|
|
|
}
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
if (isCommand("scp") && index === 0) {
|
|
|
|
addAllScripts();
|
|
|
|
addAllLitFiles();
|
|
|
|
addAllTextFiles();
|
|
|
|
|
|
|
|
return allPos;
|
2019-04-05 11:08:41 +02:00
|
|
|
}
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
if (isCommand("connect")) {
|
|
|
|
// All network connections
|
2019-04-05 11:08:41 +02:00
|
|
|
for (var i = 0; i < currServ.serversOnNetwork.length; ++i) {
|
|
|
|
var serv = AllServers[currServ.serversOnNetwork[i]];
|
2019-04-10 08:07:12 +02:00
|
|
|
if (serv == null) { continue; }
|
|
|
|
allPos.push(serv.ip);
|
|
|
|
allPos.push(serv.hostname);
|
2019-04-05 11:08:41 +02:00
|
|
|
}
|
2019-04-10 08:07:12 +02:00
|
|
|
|
2019-04-05 11:08:41 +02:00
|
|
|
return allPos;
|
|
|
|
}
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
if (isCommand("kill") || isCommand("tail") || isCommand("mem") || isCommand("check")) {
|
|
|
|
addAllScripts();
|
|
|
|
|
2019-04-05 11:08:41 +02:00
|
|
|
return allPos;
|
|
|
|
}
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
if (isCommand("nano")) {
|
|
|
|
addAllScripts();
|
|
|
|
addAllTextFiles();
|
2019-04-05 11:08:41 +02:00
|
|
|
allPos.push(".fconf");
|
2019-04-10 08:07:12 +02:00
|
|
|
|
2019-04-05 11:08:41 +02:00
|
|
|
return allPos;
|
|
|
|
}
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
if (isCommand("rm")) {
|
|
|
|
addAllScripts();
|
|
|
|
addAllPrograms();
|
|
|
|
addAllLitFiles();
|
|
|
|
addAllTextFiles();
|
|
|
|
addAllCodingContracts();
|
|
|
|
|
2019-04-05 11:08:41 +02:00
|
|
|
return allPos;
|
|
|
|
}
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
if (isCommand("run")) {
|
|
|
|
addAllScripts();
|
|
|
|
addAllPrograms();
|
|
|
|
addAllCodingContracts();
|
2019-04-05 11:08:41 +02:00
|
|
|
|
|
|
|
return allPos;
|
|
|
|
}
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
if (isCommand("cat")) {
|
|
|
|
addAllMessages();
|
|
|
|
addAllLitFiles();
|
|
|
|
addAllTextFiles();
|
|
|
|
|
2019-04-05 11:08:41 +02:00
|
|
|
return allPos;
|
|
|
|
}
|
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
if (isCommand("download") || isCommand("mv")) {
|
|
|
|
addAllScripts();
|
|
|
|
addAllTextFiles();
|
2019-04-05 11:08:41 +02:00
|
|
|
|
2019-04-10 08:07:12 +02:00
|
|
|
return allPos;
|
2019-04-05 11:08:41 +02:00
|
|
|
}
|
2019-04-10 08:07:12 +02:00
|
|
|
|
2019-04-05 11:08:41 +02:00
|
|
|
return allPos;
|
|
|
|
}
|