Converted Programs and DarkWeb implementations to Typescript

This commit is contained in:
danielyxie
2018-12-25 02:14:18 -08:00
parent a9bd883395
commit ab138ea477
18 changed files with 2905 additions and 2645 deletions
+26
View File
@@ -0,0 +1,26 @@
export interface IPlayer {
hacking_skill: number;
sourceFiles: any[];
}
export interface IProgramCreate {
level: number;
req(p: IPlayer): boolean; // Function that indicates whether player meets requirements
time: number;
tooltip: string;
}
export class Program {
name: string = "";
create: IProgramCreate | null;
constructor(name: string, create: IProgramCreate | null) {
this.name = name;
this.create = create;
}
htmlID(): string {
const name = this.name.endsWith('.exe') ? this.name.slice(0, -('.exe'.length)) : this.name;
return "create-program-" + name;
}
}
+75
View File
@@ -0,0 +1,75 @@
import { Programs } from "./Programs";
import { CONSTANTS } from "../Constants";
import { Player } from "../Player";
import { createElement } from "../../utils/uiHelpers/createElement";
// this has the same key as 'Programs', not program names
const aLinks = {};
function displayCreateProgramContent() {
for(const key in aLinks) {
const p = Programs[key]
aLinks[key].style.display = "none";
if(!Player.hasProgram(p.name) && p.create.req(Player)){
aLinks[key].style.display = "inline-block";
}
}
}
//Returns the number of programs that are currently available to be created
function getNumAvailableCreateProgram() {
var count = 0;
for (const key in Programs) {
// Non-creatable program
if (Programs[key].create == null) {
continue;
}
// Already has program
if (Player.hasProgram(Programs[key].name)) {
continue;
}
// Does not meet requirements
if (!Programs[key].create.req(Player)) {
continue;
}
count++;
}
if (Player.firstProgramAvailable === false && count > 0) {
Player.firstProgramAvailable = true;
document.getElementById("create-program-tab").style.display = "list-item";
document.getElementById("hacking-menu-header").click();
document.getElementById("hacking-menu-header").click();
}
return count;
}
function initCreateProgramButtons() {
const createProgramList = document.getElementById("create-program-list");
for (const key in Programs) {
if(Programs[key].create === null) {
continue;
}
const elem = createElement("a", {
class: "a-link-button", id: Programs[key].htmlID(), innerText: Programs[key].name,
tooltip: Programs[key].create.tooltip,
});
aLinks[key] = elem;
createProgramList.appendChild(elem);
}
for (const key in aLinks) {
const p = Programs[key]
aLinks[key].addEventListener("click", function() {
Player.startCreateProgramWork(p.name, p.create.time, p.create.level);
return false;
});
}
}
export {displayCreateProgramContent, getNumAvailableCreateProgram,
initCreateProgramButtons};
+10
View File
@@ -0,0 +1,10 @@
import { Program } from "./Program";
import { IProgramCreationParams,
programsMetadata } from "./data/programsMetadata";
import { IMap } from "../types";
export const Programs: IMap<Program> = {};
for (const params of programsMetadata) {
Programs[params.key] = new Program(params.name, params.create);
}
+139
View File
@@ -0,0 +1,139 @@
import { IPlayer,
IProgramCreate } from "../Program";
import { CONSTANTS } from "../../Constants";
function requireHackingLevel(lvl: number) {
return function(p: IPlayer) {
return p.hacking_skill >= lvl;
}
}
function bitFlumeRequirements() {
return function(p: IPlayer) {
return p.sourceFiles.length > 0 && p.hacking_skill >= 1;
}
}
export interface IProgramCreationParams {
key: string;
name: string;
create: IProgramCreate | null;
}
export const programsMetadata: IProgramCreationParams[] = [
{
key: "NukeProgram",
name: "NUKE.exe",
create: {
level: 1,
tooltip: "This virus is used to gain root access to a machine if enough ports are opened.",
req: requireHackingLevel(1),
time: CONSTANTS.MillisecondsPerFiveMinutes,
},
},
{
key: "BruteSSHProgram",
name: "BruteSSH.exe",
create: {
level: 50,
tooltip: "This program executes a brute force attack that opens SSH ports",
req: requireHackingLevel(50),
time: CONSTANTS.MillisecondsPerFiveMinutes * 2,
},
},
{
key: "FTPCrackProgram",
name: "FTPCrack.exe",
create: {
level: 100,
tooltip: "This program cracks open FTP ports",
req: requireHackingLevel(100),
time: CONSTANTS.MillisecondsPerHalfHour,
},
},
{
key: "RelaySMTPProgram",
name: "relaySMTP.exe",
create: {
level: 250,
tooltip: "This program opens SMTP ports by redirecting data",
req: requireHackingLevel(250),
time: CONSTANTS.MillisecondsPer2Hours,
},
},
{
key: "HTTPWormProgram",
name: "HTTPWorm.exe",
create: {
level: 500,
tooltip: "This virus opens up HTTP ports",
req: requireHackingLevel(500),
time: CONSTANTS.MillisecondsPer4Hours,
},
},
{
key: "SQLInjectProgram",
name: "SQLInject.exe",
create: {
level: 750,
tooltip: "This virus opens SQL ports",
req: requireHackingLevel(750),
time: CONSTANTS.MillisecondsPer8Hours,
},
},
{
key: "DeepscanV1",
name: "DeepscanV1.exe",
create: {
level: 75,
tooltip: "This program allows you to use the scan-analyze command with a depth up to 5",
req: requireHackingLevel(75),
time: CONSTANTS.MillisecondsPerQuarterHour,
},
},
{
key: "DeepscanV2",
name: "DeepscanV2.exe",
create: {
level: 400,
tooltip: "This program allows you to use the scan-analyze command with a depth up to 10",
req: requireHackingLevel(400),
time: CONSTANTS.MillisecondsPer2Hours,
},
},
{
key: "ServerProfiler",
name: "ServerProfiler.exe",
create: {
level: 75,
tooltip: "This program is used to display hacking and Netscript-related information about servers",
req: requireHackingLevel(75),
time: CONSTANTS.MillisecondsPerHalfHour,
},
},
{
key: "AutoLink",
name: "AutoLink.exe",
create: {
level: 25,
tooltip: "This program allows you to directly connect to other servers through the 'scan-analyze' command",
req: requireHackingLevel(25),
time: CONSTANTS.MillisecondsPerQuarterHour,
},
},
{
key: "BitFlume",
name: "b1t_flum3.exe",
create: {
level: 1,
tooltip: "This program creates a portal to the BitNode Nexus (allows you to restart and switch BitNodes)",
req: bitFlumeRequirements(),
time: CONSTANTS.MillisecondsPerFiveMinutes / 20,
},
},
{
key: "Flight",
name: "fl1ght.exe",
create: null,
},
];