NETSCRIPT: Add functionality and support to fully allow Players to use IP addresses in place of hostnames (#1990)

This commit is contained in:
Naga
2025-04-10 21:41:37 -04:00
committed by GitHub
parent d28a06e764
commit 0aaa28054a
84 changed files with 610 additions and 400 deletions
+20 -20
View File
@@ -49,10 +49,10 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
}
return {
attempt: (ctx) => (answer, _filename, _hostname?) => {
attempt: (ctx) => (answer, _filename, _host?) => {
const filename = helpers.string(ctx, "filename", _filename);
const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname;
const contract = getCodingContract(ctx, hostname, filename);
const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname;
const contract = getCodingContract(ctx, host, filename);
if (!contract.isValid(answer))
throw helpers.errorMessage(
@@ -60,27 +60,27 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
`Answer is not in the right format for contract '${contract.type}'. Got: ${answer}`,
);
const serv = helpers.getServer(ctx, hostname);
const serv = helpers.getServer(ctx, host);
return attemptContract(ctx, serv, contract, answer);
},
getContractType: (ctx) => (_filename, _hostname?) => {
getContractType: (ctx) => (_filename, _host?) => {
const filename = helpers.string(ctx, "filename", _filename);
const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname;
const contract = getCodingContract(ctx, hostname, filename);
const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname;
const contract = getCodingContract(ctx, host, filename);
return contract.getType();
},
getData: (ctx) => (_filename, _hostname?) => {
getData: (ctx) => (_filename, _host?) => {
const filename = helpers.string(ctx, "filename", _filename);
const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname;
const contract = getCodingContract(ctx, hostname, filename);
const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname;
const contract = getCodingContract(ctx, host, filename);
return structuredClone(contract.getData());
},
getContract: (ctx) => (_filename, _hostname?) => {
getContract: (ctx) => (_filename, _host?) => {
const filename = helpers.string(ctx, "filename", _filename);
const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname;
const server = helpers.getServer(ctx, hostname);
const contract = getCodingContract(ctx, hostname, filename);
const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname;
const server = helpers.getServer(ctx, host);
const contract = getCodingContract(ctx, host, filename);
// asserting type here is required, since it is not feasible to properly type getData
return {
type: contract.type,
@@ -96,16 +96,16 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
},
} as CodingContractObject;
},
getDescription: (ctx) => (_filename, _hostname?) => {
getDescription: (ctx) => (_filename, _host?) => {
const filename = helpers.string(ctx, "filename", _filename);
const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname;
const contract = getCodingContract(ctx, hostname, filename);
const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname;
const contract = getCodingContract(ctx, host, filename);
return contract.getDescription();
},
getNumTriesRemaining: (ctx) => (_filename, _hostname?) => {
getNumTriesRemaining: (ctx) => (_filename, _host?) => {
const filename = helpers.string(ctx, "filename", _filename);
const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname;
const contract = getCodingContract(ctx, hostname, filename);
const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname;
const contract = getCodingContract(ctx, host, filename);
return contract.getMaxNumTries() - contract.tries;
},
createDummyContract: (ctx) => (_type) => {