basic autocomplete working

This commit is contained in:
Olivier Gagnon 2021-08-20 16:11:49 -04:00
parent 0b3c48827b
commit 4497143785
2 changed files with 154 additions and 164 deletions

@ -1,144 +1,150 @@
export declare function scan(ip: string, hostnames: boolean): string[];
export declare function hack(ip: string, threads: number, stock: boolean): Promise<string>;
export declare function hackAnalyzeThreads(ip: string, hackAmount: number): number;
export declare function hackAnalyzePercent(ip: string): number;
export declare function hackChance(ip: string): number;
export declare function sleep(time: number): Promise<void>;
export declare function grow(ip: string, threads: number, stock: boolean): Promise<string>;
export declare function growthAnalyze(ip: string, growth: number): number;
export declare function weaken(ip: string, threads: boolean): Promise<string>;
export declare function print(): void;
export declare function tprint(): void;
export declare function clearLog(): void;
export declare function disableLog(fn: string): void;
export declare function enableLog(fn: string): void;
export declare function isLogEnabled(fn: string): boolean;
export declare function getScriptLogs(fn: string, ip: string, ...scriptArgs: any[]): string[];
export declare function tail(fn: string, ip: string, ...scriptArgs: any[]): void;
export declare function nuke(ip: string): boolean;
export declare function brutessh(ip: string): boolean;
export declare function ftpcrack(ip: string): boolean;
export declare function relaysmtp(ip: string): boolean;
export declare function httpworm(ip: string): boolean;
export declare function sqlinject(ip: string): boolean;
export declare function run(scriptname: string, threads: number): number;
export declare function exec(scriptname: string, ip: string, threads: number): number;
export declare function spawn(scriptname: string, threads: number): void;
export declare function kill(filename: string, ip: string, ...scriptArgs: any[]): boolean;
export declare function killall(ip: string): boolean;
export declare function exit(): void;
export declare function scp(scriptname: string, ip1: string, ip2: string): boolean;
export declare function ls(ip: string, grep: string): string[];
export declare function ps(ip: string): {filename: string, threads: number, args: string[], pid: number}[];
export declare function hasRootAccess(ip: string): boolean;
export declare function getIp(): string;
export declare function getHostname(): string;
export declare function getHackingLevel(): number;
export declare function getHackingMultipliers(): number;
export declare function getHacknetMultipliers(): number;
export declare function getBitNodeMultipliers(): number;
export declare function getServer(ip: string): any;
export declare function getServerMoneyAvailable(ip: string): number;
export declare function getServerSecurityLevel(ip: string): number;
export declare function getServerBaseSecurityLevel(ip: string): number;
export declare function getServerMinSecurityLevel(ip: string): number;
export declare function getServerRequiredHackingLevel(ip: string): number;
export declare function getServerMaxMoney(ip: string): number;
export declare function getServerGrowth(ip: string): number;
export declare function getServerNumPortsRequired(ip: string): number;
export declare function getServerRam(ip: string): number[];
export declare function getServerMaxRam(ip: string): number;
export declare function getServerUsedRam(ip: string): number;
export declare function serverExists(ip: string): boolean;
export declare function fileExists(filename: string, ip: string): boolean;
export declare function isRunning(fn: string, ip: string, ...scriptArgs: any[]): boolean;
export declare function getStockSymbols(): string[];
export declare function getStockPrice(symbol: string): number;
export declare function getStockAskPrice(symbol: string): number;
export declare function getStockBidPrice(symbol: string): number;
export declare function getStockPosition(symbol: string): number;
export declare function getStockMaxShares(symbol: string): number;
export declare function getStockPurchaseCost(symbol: string, shares: number, posType: string): number;
export declare function getStockSaleGain(symbol: string, shares: number, posType: string): number;
export declare function buyStock(symbol: string, shares: number): number;
export declare function sellStock(symbol: string, shares: number): number;
export declare function shortStock(symbol: string, shares: number): number;
export declare function sellShort(symbol: string, shares: number): number;
export declare function placeOrder(symbol: string, shares: number, price: number, type: string, pos: string): boolean;
export declare function cancelOrder(symbol: string, shares: number, price: number, type: string, pos: string): boolean;
export declare function getOrders(): any;
export declare function getStockVolatility(symbol: string): number;
export declare function getStockForecast(symbol: string): number;
export declare function getPurchasedServerLimit(): number;
export declare function getPurchasedServerMaxRam(): number;
export declare function getPurchasedServerCost(ram: number): number;
export declare function purchaseServer(hostname: string, ram: number): string;
export declare function deleteServer(hostname: string): boolean;
export declare function getPurchasedServers(hostname: string): string[];
export declare function write(port: number, data: string, mode: string): boolean;
export declare function tryWrite(port: number, data: string): boolean;
export declare function read(port: number): any;
export declare function peek(port: number): any;
export declare function clear(port: number): number;
export declare function getPortHandle(port: number): any; // netscript port
export declare function rm(fn: string, ip: string): boolean;
export declare function scriptRunning(scriptname: string, ip: string): boolean;
export declare function scriptKill(scriptname: string, ip: string): boolean;
export declare function getScriptName(): string;
export declare function getScriptRam(scriptname: string, ip: string): number;
export declare function getRunningScript(fn: string, ip: string): any; // running script
export declare function getHackTime(ip: string): number;
export declare function getGrowTime(ip: string): number;
export declare function getWeakenTime(ip: string): number;
export declare function getScriptIncome(scriptname: string, ip: string): number;
export declare function getScriptExpGain(scriptname: string, ip: string): number;
export declare function nFormat(n: number, format: string): string;
export declare function tFormat(milliseconds: number, milliPrecision: boolean): string;
export declare function getTimeSinceLastAug(): number;
export declare function prompt(txt: string): Promise<boolean>;
export declare function getFavorToDonate(): number;
export declare function universityCourse(universityName: string, className: string): boolean;
export declare function gymWorkout(gymName: string, stat: string): boolean;
export declare function travelToCity(cityname: string): boolean;
export declare function purchaseTor(): boolean;
export declare function purchaseProgram(programName: string): boolean;
export declare function getCurrentServer(): any; // server object
export declare function connect(hostname: string): boolean;
export declare function manualHack(): Promise<string>;
export declare function installBackdoor(): Promise<void>;
export declare function getStats(): any; // complex type
export declare function getCharacterInformation(): any; // complex type
export declare function getPlayer(): any; // complex type
export declare function hospitalize(): number;
export declare function isBusy(): boolean;
export declare function stopAction(): boolean;
export declare function upgradeHomeRam(): number;
export declare function getUpgradeHomeRamCost(): number;
export declare function workForCompany(companyName: string): boolean;
export declare function applyToCompany(companyName: string, field: string): boolean;
export declare function getCompanyRep(companyName: string): number;
export declare function getCompanyFavor(companyName: string): number;
export declare function getCompanyFavorGain(companyName: string): number;
export declare function checkFactionInvitations(): string[];
export declare function joinFaction(name: string): boolean;
export declare function workForFaction(name: string, type: string): boolean;
export declare function getFactionRep(name: string): number;
export declare function getFactionFavor(name: string): number;
export declare function getFactionFavorGain(name: string): number;
export declare function donateToFaction(name: string, amt: number): boolean;
export declare function createProgram(name: string): boolean;
export declare function commitCrime(crimeRoughName: string): number;
export declare function getCrimeChance(crimeRoughName: string): boolean;
export declare function getCrimeStats(crimeRoughName: string): any; // complex type
export declare function getOwnedAugmentations(purchased: boolean): string[];
export declare function getOwnedSourceFiles(): any; // complex type
export declare function getAugmentationsFromFaction(facname: string): string[];
export declare function getAugmentationPrereq(name: string): string[];
export declare function getAugmentationCost(name: string): number;
export declare function getAugmentationStats(name: string): any; // complex type
export declare function purchaseAugmentation(faction: string, name: string): boolean;
export declare function softReset(cbScript: string): void;
export declare function installAugmentations(cbScript: string): void;
export declare function exploit(): void;
export declare function bypass(doc: any): void;
export declare function flags(data: any): any;
export const libSource = `interface NS {
args: string[];
/**
* Example documentation for scan.
*/
scan(ip: string, hostnames: boolean): string[];
hack(ip: string, threads: number, stock: boolean): Promise<string>;
hackAnalyzeThreads(ip: string, hackAmount: number): number;
hackAnalyzePercent(ip: string): number;
hackChance(ip: string): number;
sleep(time: number): Promise<void>;
grow(ip: string, threads: number, stock: boolean): Promise<string>;
growthAnalyze(ip: string, growth: number): number;
weaken(ip: string, threads: boolean): Promise<string>;
print(...args: any[]): void;
tprint(...args: any[]): void;
clearLog(): void;
disableLog(fn: string): void;
enableLog(fn: string): void;
isLogEnabled(fn: string): boolean;
getScriptLogs(fn: string, ip: string, ...scriptArgs: any[]): string[];
tail(fn: string, ip: string, ...scriptArgs: any[]): void;
nuke(ip: string): boolean;
brutessh(ip: string): boolean;
ftpcrack(ip: string): boolean;
relaysmtp(ip: string): boolean;
httpworm(ip: string): boolean;
sqlinject(ip: string): boolean;
run(scriptname: string, threads: number): number;
exec(scriptname: string, ip: string, threads: number): number;
spawn(scriptname: string, threads: number): void;
kill(filename: string, ip: string, ...scriptArgs: any[]): boolean;
killall(ip: string): boolean;
exit(): void;
scp(scriptname: string, ip1: string, ip2: string): boolean;
ls(ip: string, grep: string): string[];
ps(ip: string): {filename: string, threads: number, args: string[], pid: number}[];
hasRootAccess(ip: string): boolean;
getIp(): string;
getHostname(): string;
getHackingLevel(): number;
getHackingMultipliers(): number;
getHacknetMultipliers(): number;
getBitNodeMultipliers(): number;
getServer(ip: string): any;
getServerMoneyAvailable(ip: string): number;
getServerSecurityLevel(ip: string): number;
getServerBaseSecurityLevel(ip: string): number;
getServerMinSecurityLevel(ip: string): number;
getServerRequiredHackingLevel(ip: string): number;
getServerMaxMoney(ip: string): number;
getServerGrowth(ip: string): number;
getServerNumPortsRequired(ip: string): number;
getServerRam(ip: string): number[];
getServerMaxRam(ip: string): number;
getServerUsedRam(ip: string): number;
serverExists(ip: string): boolean;
fileExists(filename: string, ip: string): boolean;
isRunning(fn: string, ip: string, ...scriptArgs: any[]): boolean;
getStockSymbols(): string[];
getStockPrice(symbol: string): number;
getStockAskPrice(symbol: string): number;
getStockBidPrice(symbol: string): number;
getStockPosition(symbol: string): number;
getStockMaxShares(symbol: string): number;
getStockPurchaseCost(symbol: string, shares: number, posType: string): number;
getStockSaleGain(symbol: string, shares: number, posType: string): number;
buyStock(symbol: string, shares: number): number;
sellStock(symbol: string, shares: number): number;
shortStock(symbol: string, shares: number): number;
sellShort(symbol: string, shares: number): number;
placeOrder(symbol: string, shares: number, price: number, type: string, pos: string): boolean;
cancelOrder(symbol: string, shares: number, price: number, type: string, pos: string): boolean;
getOrders(): any;
getStockVolatility(symbol: string): number;
getStockForecast(symbol: string): number;
getPurchasedServerLimit(): number;
getPurchasedServerMaxRam(): number;
getPurchasedServerCost(ram: number): number;
purchaseServer(hostname: string, ram: number): string;
deleteServer(hostname: string): boolean;
getPurchasedServers(hostname: string): string[];
write(port: number, data: string, mode: string): boolean;
tryWrite(port: number, data: string): boolean;
read(port: number): any;
peek(port: number): any;
clear(port: number): number;
getPortHandle(port: number): any; // netscript port
rm(fn: string, ip: string): boolean;
scriptRunning(scriptname: string, ip: string): boolean;
scriptKill(scriptname: string, ip: string): boolean;
getScriptName(): string;
getScriptRam(scriptname: string, ip: string): number;
getRunningScript(fn: string, ip: string): any; // running script
getHackTime(ip: string): number;
getGrowTime(ip: string): number;
getWeakenTime(ip: string): number;
getScriptIncome(scriptname: string, ip: string): number;
getScriptExpGain(scriptname: string, ip: string): number;
nFormat(n: number, format: string): string;
tFormat(milliseconds: number, milliPrecision: boolean): string;
getTimeSinceLastAug(): number;
prompt(txt: string): Promise<boolean>;
getFavorToDonate(): number;
universityCourse(universityName: string, className: string): boolean;
gymWorkout(gymName: string, stat: string): boolean;
travelToCity(cityname: string): boolean;
purchaseTor(): boolean;
purchaseProgram(programName: string): boolean;
getCurrentServer(): any; // server object
connect(hostname: string): boolean;
manualHack(): Promise<string>;
installBackdoor(): Promise<void>;
getStats(): any; // complex type
getCharacterInformation(): any; // complex type
getPlayer(): any; // complex type
hospitalize(): number;
isBusy(): boolean;
stopAction(): boolean;
upgradeHomeRam(): number;
getUpgradeHomeRamCost(): number;
workForCompany(companyName: string): boolean;
applyToCompany(companyName: string, field: string): boolean;
getCompanyRep(companyName: string): number;
getCompanyFavor(companyName: string): number;
getCompanyFavorGain(companyName: string): number;
checkFactionInvitations(): string[];
joinFaction(name: string): boolean;
workForFaction(name: string, type: string): boolean;
getFactionRep(name: string): number;
getFactionFavor(name: string): number;
getFactionFavorGain(name: string): number;
donateToFaction(name: string, amt: number): boolean;
createProgram(name: string): boolean;
commitCrime(crimeRoughName: string): number;
getCrimeChance(crimeRoughName: string): boolean;
getCrimeStats(crimeRoughName: string): any; // complex type
getOwnedAugmentations(purchased: boolean): string[];
getOwnedSourceFiles(): any; // complex type
getAugmentationsFromFaction(facname: string): string[];
getAugmentationPrereq(name: string): string[];
getAugmentationCost(name: string): number;
getAugmentationStats(name: string): any; // complex type
purchaseAugmentation(faction: string, name: string): boolean;
softReset(cbScript: string): void;
installAugmentations(cbScript: string): void;
exploit(): void;
bypass(doc: any): void;
flags(data: any): any;
}`

@ -19,7 +19,7 @@ import { calculateRamUsage } from "../../Script/RamCalculations";
import { RamCalculationErrorCode } from "../../Script/RamCalculationErrorCodes";
import { numeralWrapper } from "../../ui/numeralFormat";
import { CursorPositions } from "../../ScriptEditor/CursorPositions";
import * as NetscriptDefinitions from "../NetscriptDefinitions";
import { libSource } from "../NetscriptDefinitions";
interface IProps {
filename: string;
@ -202,24 +202,8 @@ export function Root(props: IProps): React.ReactElement {
}
function beforeMount(monaco: any): void {
// extra libraries
const libSource = `
export declare function upgradeHomeRam(): number;
export declare function getUpgradeHomeRamCost(): number;
export declare function workForCompany(companyName: string): boolean;
export declare function applyToCompany(companyName: string, field: string): boolean;
export declare function getCompanyRep(companyName: string): number;
export declare function getCompanyFavor(companyName: string): number;
export declare function getCompanyFavorGain(companyName: string): number;
export declare function checkFactionInvitations(): string[];
export declare function joinFaction(name: string): boolean;
export declare function workForFaction(name: string, type: string): boolean;
export declare function getFactionRep(name: string): number;
export declare function getFactionFavor(name: string): number;`;
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource);
monaco.languages.typescript.typescriptDefaults.addExtraLib(libSource);
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, 'netscript.d.ts');
monaco.languages.typescript.typescriptDefaults.addExtraLib(libSource, 'netscript.d.ts');
}
return (<div id="script-editor-wrapper">
@ -233,7 +217,7 @@ export declare function getFactionFavor(name: string): number;`;
onMount={onMount}
loading={<p>Loading script editor!</p>}
height="80%"
defaultLanguage="javascript"
defaultLanguage="typescript"
defaultValue={code}
value={code}
onChange={updateCode}