Reverse argument order for sendTo

It makes more sense to put the address first then have the large
structure to send as the second argument to sendTo.  The opposite order
was originally chosen to be similar to that of sendto in BSD sockets.
This commit is contained in:
Hornwitser committed 2023-07-27 00:24:24 +02:00
1 parent 183d2921a8
commit 295cc7543a
24 files changed
+87 -74

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ globalChatCommands.add(new libCommand.Command({
yargs.positional("message", { describe: "message to send", type: "string" });
}],
handler: async function(args, control) {
await control.sendTo(new ChatEvent("Console", args.message), "allInstances");
await control.sendTo("allInstances", new ChatEvent("Console", args.message));
},
}));
+1 -1
View File
@@ -39,7 +39,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
}
sendChat(message) {
this.instance.sendTo(new ChatEvent(this.instance.name, message), "allInstances");
this.instance.sendTo("allInstances", new ChatEvent(this.instance.name, message));
}
async onOutput(output) {
+5 -5
View File
@@ -53,7 +53,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
return;
}
this.playersToRelease.delete(player);
await this.instance.sendTo(new ReleaseRequest(this.instance.id, player_name), "controller");
await this.instance.sendTo("controller", new ReleaseRequest(this.instance.id, player_name));
}
})().catch(
err => this.logger.error(`Unpexpected error releasing queued up players:\n${err.stack}`)
@@ -71,8 +71,8 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
if (this.host.connector.connected && !this.disconnecting) {
try {
let acquireResponse = await this.instance.sendTo(
"controller",
new AcquireRequest(this.instance.id, request.player_name),
"controller"
);
response = {
player_name: request.player_name,
@@ -99,7 +99,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
}
try {
await this.instance.sendTo(new ReleaseRequest(this.instance.id, request.player_name), "controller");
await this.instance.sendTo("controller", new ReleaseRequest(this.instance.id, request.player_name));
} catch (err) {
if (err instanceof libErrors.SessionLost) {
this.playersToRelease.set(request.player_name);
@@ -117,8 +117,8 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
this.logger.verbose(`Uploading ${player_data.name} (${JSON.stringify(player_data).length / 1000}kB)`);
try {
await this.instance.sendTo(
"controller",
new UploadRequest(this.instance.id, player_data.name, player_data),
"controller"
);
} catch (err) {
@@ -137,7 +137,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
const playerName = request.player_name;
this.logger.verbose(`Downloading ${playerName}`);
let response = await this.instance.sendTo(new DownloadRequest(this.instance.id, playerName), "controller");
let response = await this.instance.sendTo("controller", new DownloadRequest(this.instance.id, playerName));
if (!response.player_data) {
await this.sendRcon(`/sc inventory_sync.download_inventory('${playerName}',nil,0,0)`, true);
+2 -2
View File
@@ -27,7 +27,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
let response;
try {
response = await this.instance.sendTo(new FetchPlayerCodeRequest(event.player), "controller");
response = await this.instance.sendTo("controller", new FetchPlayerCodeRequest(event.player));
} catch (err) {
await this.sendRcon(`/web-login error ${event.player} ${err.message}`);
return;
@@ -36,7 +36,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
} else if (event.type === "set_verify_code") {
try {
await this.instance.sendTo(new SetVerifyCodeRequest(event.player, event.verify_code), "controller");
await this.instance.sendTo("controller", new SetVerifyCodeRequest(event.player, event.verify_code));
} catch (err) {
await this.sendRcon(`/web-login error ${event.player} ${err.message}`);
+4 -4
View File
@@ -71,7 +71,7 @@ class ControllerPlugin extends libPlugin.BaseControllerPlugin {
this.lastProgressBroadcast = Date.now();
if (techs.length) {
this.controller.sendTo(new ProgressEvent(techs), "allInstances");
this.controller.sendTo("allInstances", new ProgressEvent(techs));
}
}
@@ -109,7 +109,7 @@ class ControllerPlugin extends libPlugin.BaseControllerPlugin {
tech.progress = null;
this.progressToBroadcast.delete(name);
this.controller.sendTo(new FinishedEvent(name, tech.level), "allInstances");
this.controller.sendTo("allInstances", new FinishedEvent(name, tech.level));
}
}
@@ -139,7 +139,7 @@ class ControllerPlugin extends libPlugin.BaseControllerPlugin {
if (progress) {
this.progressToBroadcast.add(name);
} else if (researched || baseLevel(name) !== level) {
this.controller.sendTo(new FinishedEvent(name, tech), "allInstances");
this.controller.sendTo("allInstances", new FinishedEvent(name, tech));
}
} else {
@@ -150,7 +150,7 @@ class ControllerPlugin extends libPlugin.BaseControllerPlugin {
if (tech.level < level || researched) {
// Send update if the unlocked level is greater
if (level - !researched > tech.level - !tech.researched) {
this.controller.sendTo(new FinishedEvent(name, level - !researched), "allInstances");
this.controller.sendTo("allInstances", new FinishedEvent(name, level - !researched));
}
tech.level = level;
tech.progress = progress;
+3 -3
View File
@@ -33,7 +33,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
}
async researchContribution(tech) {
this.instance.sendTo(new ContributionEvent(tech.name, tech.level, tech.contribution), "controller");
this.instance.sendTo("controller", new ContributionEvent(tech.name, tech.level, tech.contribution));
}
async handleProgressEvent(event) {
@@ -45,7 +45,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
}
async researchFinished(tech) {
this.instance.sendTo(new FinishedEvent(tech.name, tech.level), "allInstances");
this.instance.sendTo("allInstances", new FinishedEvent(tech.name, tech.level));
}
async handleFinishedEvent(event) {
@@ -72,7 +72,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
instanceTechs.set(tech.name, tech);
}
let controllerTechs = await this.instance.sendTo(new SyncTechnologiesRequest(techsToSend), "controller");
let controllerTechs = await this.instance.sendTo("controller", new SyncTechnologiesRequest(techsToSend));
this.syncStarted = true;
let techsToSync = [];
for (let controllerTech of controllerTechs) {
+1 -1
View File
@@ -122,7 +122,7 @@ class ControllerPlugin extends libPlugin.BaseControllerPlugin {
itemsToUpdate = [...itemsToUpdate.entries()];
let update = new UpdateStorageEvent(itemsToUpdate);
this.controller.sendTo(update, "allInstances");
this.controller.sendTo("allInstances", update);
for (let link of this.subscribedControlLinks) {
link.send(update);
}
+3 -3
View File
@@ -44,7 +44,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
).catch(err => this.unexpectedError(err));
}, 5000);
let items = await this.instance.sendTo(new GetStorageRequest(), "controller");
let items = await this.instance.sendTo("controller", new GetStorageRequest());
// TODO Diff with dump of invdata produce minimal command to sync
let itemsJson = libLuaTools.escapeString(JSON.stringify(items));
await this.sendRcon(`/sc __subspace_storage__ UpdateInvData("${itemsJson}", true)`, true);
@@ -71,7 +71,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
return;
}
this.instance.sendTo(new PlaceEvent(items), "controller");
this.instance.sendTo("controller", new PlaceEvent(items));
if (this.instance.config.get("subspace_storage.log_item_transfers")) {
this.logger.verbose("Exported the following to controller:");
@@ -82,7 +82,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
// request items --------------------------------------------------------------
async requestItems(requestItems) {
// Request the items all at once
let items = await this.instance.sendTo(new RemoveRequest(requestItems), "controller");
let items = await this.instance.sendTo("controller", new RemoveRequest(requestItems));
if (!items.length) {
return;