Merge pull request #2328 from danielyxie/dev

update
This commit is contained in:
hydroflame
2022-01-04 12:26:23 -05:00
committed by GitHub
77 changed files with 2382 additions and 671 deletions
+7 -1
View File
@@ -48,7 +48,7 @@ export function isValidFilename(filename: string): boolean {
* Checks whether a string is a valid directory name. Only used for the directory itself,
* not an entire path
*/
export function isValidDirectoryName(name: string): boolean {
export function isValidDirectoryName(name: string): boolean {
// Allows alphanumerics, hyphens, underscores, and percentage signs.
// Name can begin with a single period, but otherwise cannot have any
const regex = /^.?[a-zA-Z0-9_-]+$/;
@@ -310,3 +310,9 @@ export function areFilesEqual(f0: string, f1: string): boolean {
if (!f1.startsWith("/")) f1 = "/" + f1;
return f0 === f1;
}
export function areImportsEquals(f0: string, f1: string): boolean {
if (!f0.endsWith(".ns") && !f0.endsWith(".js")) f0 = f0 + ".js";
if (!f1.endsWith(".ns") && !f1.endsWith(".js")) f1 = f1 + ".js";
return areFilesEqual(f0, f1);
}
+16 -9
View File
@@ -27,7 +27,7 @@ export const TerminalHelpText: string[] = [
"killall Stops all running scripts on the current machine",
"ls [dir] [| grep pattern] Displays all files on the machine",
"lscpu Displays the number of CPU cores on the machine",
"mem [script] [-t] [n] Displays the amount of RAM required to run the script",
"mem [script] [-t n] Displays the amount of RAM required to run the script",
"mv [src] [dest] Move/rename a text or script file",
"nano [file ...] Text editor - Open up and edit one or more scripts or text files",
"ps Display all scripts that are currently running",
@@ -35,7 +35,7 @@ export const TerminalHelpText: string[] = [
"run [name] [-t n] [--tail] [args...] Execute a program or script",
"scan Prints all immediately-available network connections",
"scan-analyze [d] [-a] Prints info for all servers up to <i>d</i> nodes away",
"scp [file] [server] Copies a file to a destination server",
"scp [file ...] [server] Copies a file to a destination server",
"sudov Shows whether you have root access on this computer",
"tail [script] [args...] Displays dynamic logs for the specified script",
"top Displays all running scripts and their RAM usage",
@@ -80,7 +80,7 @@ export const HelpTexts: IMap<string[]> = {
" ",
],
analyze: [
"analze",
"analyze",
" ",
"Prints details and statistics about the current server. The information that is printed includes basic ",
"server details such as the hostname, whether the player has root access, what ports are opened/closed, and also ",
@@ -96,13 +96,15 @@ export const HelpTexts: IMap<string[]> = {
" ",
],
buy: [
"buy [-l / program]",
"buy [-l / -a / program]",
" ",
"Purchase a program through the Dark Web. Requires a TOR router to use.",
" ",
"If this command is ran with the '-l' flag, it will display a list of all programs that can be bought through the ",
"dark web to the Terminal, as well as their costs.",
" ",
"If this command is ran with the '-a' flag, it will attempt to purchase all unowned programs.",
" ",
"Otherwise, the name of the program must be passed in as a parameter. This name is NOT case-sensitive.",
],
cat: [
@@ -191,7 +193,7 @@ export const HelpTexts: IMap<string[]> = {
free: [
"free",
" ",
"Display's the memory usage on the current machine. Print the amount of RAM that is available on the current server as well as ",
"Displays the memory usage on the current machine. Print the amount of RAM that is available on the current server as well as ",
"how much of it is being used.",
],
grow: [
@@ -360,12 +362,17 @@ export const HelpTexts: IMap<string[]> = {
"-a flag at the end of the command if you would like to enable that.",
],
scp: [
"scp [filename] [target server]",
"scp [filename ...] [target server]",
" ",
"Copies the specified file from the current server to the target server. ",
"This command only works for script files (.script extension), literature files (.lit extension), ",
"Copies the specified file(s) from the current server to the target server. ",
"This command only works for script files (.script or .js extension), literature files (.lit extension), ",
"and text files (.txt extension). ",
"The second argument passed in must be the hostname or IP of the target server.",
"The second argument passed in must be the hostname or IP of the target server. Examples:",
" ",
"scp foo.script n00dles",
" ",
"scp foo.script bar.script n00dles",
" ",
],
sudov: ["sudov", " ", "Prints whether or not you have root access to the current machine"],
+4 -1
View File
@@ -2,7 +2,7 @@ import { ITerminal } from "../ITerminal";
import { IRouter } from "../../ui/Router";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { BaseServer } from "../../Server/BaseServer";
import { listAllDarkwebItems, buyDarkwebItem } from "../../DarkWeb/DarkWeb";
import { listAllDarkwebItems, buyAllDarkwebItems, buyDarkwebItem } from "../../DarkWeb/DarkWeb";
import { SpecialServers } from "../../Server/data/SpecialServers";
import { GetServer } from "../../Server/AllServers";
@@ -22,12 +22,15 @@ export function buy(
if (args.length != 1) {
terminal.print("Incorrect number of arguments. Usage: ");
terminal.print("buy -l");
terminal.print("buy -a");
terminal.print("buy [item name]");
return;
}
const arg = args[0] + "";
if (arg == "-l" || arg == "-1" || arg == "--list") {
listAllDarkwebItems();
} else if (arg == "-a" || arg == "--all") {
buyAllDarkwebItems();
} else {
buyDarkwebItem(arg);
}
+2 -2
View File
@@ -53,7 +53,7 @@ export function mv(
// Also, you can't convert between different file types
if (isScriptFilename(source)) {
const script = srcFile as Script;
if (!isScriptFilename(dest)) {
if (!isScriptFilename(destPath)) {
terminal.error(`Source and destination files must have the same type`);
return;
}
@@ -66,7 +66,7 @@ export function mv(
if (destFile != null) {
// Already exists, will be overwritten, so we'll delete it
const status = server.removeFile(dest);
const status = server.removeFile(destPath);
if (!status.res) {
terminal.error(`Something went wrong...please contact game dev (probably a bug)`);
return;
+33 -8
View File
@@ -2,6 +2,7 @@ import { ITerminal } from "../ITerminal";
import { IRouter } from "../../ui/Router";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { BaseServer } from "../../Server/BaseServer";
import * as libarg from "arg"
export function ps(
terminal: ITerminal,
@@ -10,16 +11,40 @@ export function ps(
server: BaseServer,
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of ps command. Usage: ps");
let flags;
try{
flags = libarg({
'--grep': String,
'-g': '--grep'
},
{ argv: args }
)
}catch(e){
// catch passing only -g / --grep with no string to use as the search
terminal.error("Incorrect usage of ps command. Usage: ps [-g, --grep pattern]");
return;
}
for (let i = 0; i < server.runningScripts.length; i++) {
const rsObj = server.runningScripts[i];
let res = `(PID - ${rsObj.pid}) ${rsObj.filename}`;
for (let j = 0; j < rsObj.args.length; ++j) {
res += " " + rsObj.args[j].toString();
const pattern = flags['--grep']
if (pattern) {
const re = new RegExp(pattern.toString())
const matching = server.runningScripts.filter((x) => re.test(x.filename))
for (let i = 0; i < matching.length; i++) {
const rsObj = matching[i];
let res = `(PID - ${rsObj.pid}) ${rsObj.filename}`;
for (let j = 0; j < rsObj.args.length; ++j) {
res += " " + rsObj.args[j].toString();
}
terminal.print(res);
}
}
if(args.length === 0){
for (let i = 0; i < server.runningScripts.length; i++) {
const rsObj = server.runningScripts[i];
let res = `(PID - ${rsObj.pid}) ${rsObj.filename}`;
for (let j = 0; j < rsObj.args.length; ++j) {
res += " " + rsObj.args[j].toString();
}
terminal.print(res);
}
terminal.print(res);
}
}
+6 -4
View File
@@ -350,7 +350,12 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
event.preventDefault();
modifyInput("deletewordbefore");
}
if (event.keyCode === KEY.D && event.altKey) {
event.preventDefault();
modifyInput("deletewordafter");
}
if (event.keyCode === KEY.U && event.ctrlKey) {
event.preventDefault();
modifyInput("clearbefore");
@@ -360,9 +365,6 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
event.preventDefault();
modifyInput("clearafter");
}
// TODO AFTER THIS:
// alt + d deletes word after cursor
}
}