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
+13 -11
View File
@@ -464,9 +464,11 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
Player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 5000);
return true;
},
getCurrentServer: (ctx) => () => {
getCurrentServer: (ctx) => (_returnOpts) => {
helpers.checkSingularityAccess(ctx);
return Player.getCurrentServer().hostname;
const returnOpts = helpers.hostReturnOptions(_returnOpts);
const server = Player.getCurrentServer();
return helpers.returnServerID(server, returnOpts);
},
cat: (ctx) => (_filename) => {
helpers.checkSingularityAccess(ctx);
@@ -474,16 +476,16 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
const server = Player.getCurrentServer();
cat([filename], server);
},
connect: (ctx) => (_hostname) => {
connect: (ctx) => (_host) => {
helpers.checkSingularityAccess(ctx);
const hostname = helpers.string(ctx, "hostname", _hostname);
if (!hostname) {
throw helpers.errorMessage(ctx, `Invalid hostname: '${hostname}'`);
const host = helpers.string(ctx, "host", _host);
if (!host) {
throw helpers.errorMessage(ctx, `Invalid server: '${host}'`);
}
const target = GetServer(hostname);
const target = GetServer(host);
if (target == null) {
throw helpers.errorMessage(ctx, `Invalid hostname: '${hostname}'`);
throw helpers.errorMessage(ctx, `Invalid server: '${host}'`);
}
// Adjacent servers
@@ -498,8 +500,8 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
);
return false;
}
if (other.hostname === hostname) {
Terminal.connectToServer(hostname, true);
if (other.hostname === target.hostname) {
Terminal.connectToServer(host, true);
return true;
}
}
@@ -509,7 +511,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
* is true.
*/
if (target.backdoorInstalled || target.purchasedByPlayer) {
Terminal.connectToServer(hostname, true);
Terminal.connectToServer(host, true);
return true;
}