mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 23:04:52 +09:00
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:
1 parent
183d2921a8
commit
295cc7543a
24 files changed
+87
-74
No files matched your search
@@ -421,7 +421,7 @@ class ControlConnection extends BaseConnection {
|
||||
|
||||
// Let host handle request if source and target is on the same host.
|
||||
if (sourceHostId === targetHostId) {
|
||||
return await this._controller.sendTo(request, { hostId: sourceHostId });
|
||||
return await this._controller.sendTo({ hostId: sourceHostId }, request);
|
||||
}
|
||||
|
||||
// Check connectivity
|
||||
@@ -451,23 +451,23 @@ class ControlConnection extends BaseConnection {
|
||||
// ensure the file size is known prior to the target host pull.
|
||||
await Promise.all([
|
||||
this._controller.sendTo(
|
||||
{ hostId: sourceHostId },
|
||||
new libData.InstancePushSaveRequest(request.sourceInstanceId, stream.id, request.sourceName),
|
||||
{ hostId: sourceHostId }
|
||||
),
|
||||
events.once(stream.events, "source"),
|
||||
]);
|
||||
|
||||
// Establish pull from target host to stream and wait for completion.
|
||||
let storedName = await this._controller.sendTo(
|
||||
new libData.InstancePullSaveRequest(request.targetInstanceId, stream.id, request.targetName),
|
||||
{ hostId: targetHostId },
|
||||
new libData.InstancePullSaveRequest(request.targetInstanceId, stream.id, request.targetName),
|
||||
);
|
||||
|
||||
// Delete source save if this is not a copy
|
||||
if (!request.copy) {
|
||||
await this._controller.sendTo(
|
||||
{ hostId: sourceHostId },
|
||||
new libData.InstanceDeleteSaveRequest(request.sourceInstanceId, request.sourceName),
|
||||
{ hostId: sourceHostId }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -887,7 +887,7 @@ class ControlConnection extends BaseConnection {
|
||||
|
||||
user.isAdmin = admin;
|
||||
this._controller.userUpdated(user);
|
||||
this._controller.sendTo(new libData.InstanceAdminlistUpdateEvent(name, admin), "allInstances");
|
||||
this._controller.sendTo("allInstances", new libData.InstanceAdminlistUpdateEvent(name, admin));
|
||||
}
|
||||
|
||||
async handleUserSetBannedRequest(request) {
|
||||
@@ -905,7 +905,7 @@ class ControlConnection extends BaseConnection {
|
||||
user.isBanned = banned;
|
||||
user.banReason = reason;
|
||||
this._controller.userUpdated(user);
|
||||
this._controller.sendTo(new libData.InstanceBanlistUpdateEvent(name, banned, reason), "allInstances");
|
||||
this._controller.sendTo("allInstances", new libData.InstanceBanlistUpdateEvent(name, banned, reason));
|
||||
}
|
||||
|
||||
async handleUserSetWhitelistedRequest(request) {
|
||||
@@ -922,7 +922,7 @@ class ControlConnection extends BaseConnection {
|
||||
|
||||
user.isWhitelisted = whitelisted;
|
||||
this._controller.userUpdated(user);
|
||||
this._controller.sendTo(new libData.InstanceWhitelistUpdateEvent(name, whitelisted), "allInstances");
|
||||
this._controller.sendTo("allInstances", new libData.InstanceWhitelistUpdateEvent(name, whitelisted));
|
||||
}
|
||||
|
||||
async handleUserDeleteRequest(request) {
|
||||
@@ -937,13 +937,13 @@ class ControlConnection extends BaseConnection {
|
||||
this._controller.userUpdated(user);
|
||||
|
||||
if (user.is_admin) {
|
||||
this._controller.sendTo(new libData.InstanceAdminlistUpdateEvent(name, false), "allInstances");
|
||||
this._controller.sendTo("allInstances", new libData.InstanceAdminlistUpdateEvent(name, false));
|
||||
}
|
||||
if (user.is_whitelisted) {
|
||||
this._controller.sendTo(new libData.InstanceWhitelistUpdateEvent(name, false), "allInstances");
|
||||
this._controller.sendTo("allInstances", new libData.InstanceWhitelistUpdateEvent(name, false));
|
||||
}
|
||||
if (user.is_banned) {
|
||||
this._controller.sendTo(new libData.InstanceBanlistUpdateEvent(name, false, ""), "allInstances");
|
||||
this._controller.sendTo("allInstances", new libData.InstanceBanlistUpdateEvent(name, false, ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -715,7 +715,7 @@ class Controller {
|
||||
let instance = this.getRequestInstance(instanceId);
|
||||
let hostId = instance.config.get("instance.assigned_host");
|
||||
if (hostId !== null) {
|
||||
await this.sendTo(new libData.InstanceDeleteInternalRequest(instanceId), { hostId });
|
||||
await this.sendTo({ hostId }, new libData.InstanceDeleteInternalRequest(instanceId));
|
||||
}
|
||||
this.instances.delete(instanceId);
|
||||
|
||||
@@ -1028,13 +1028,13 @@ class Controller {
|
||||
* destination argument supports address shorthands, see {@link
|
||||
* module:lib/data.Address.fromShorthand}
|
||||
*
|
||||
* @param {*} requestOrEvent - The request or event to send.
|
||||
* @param {*|module:lib/data.Address} address - Where to send it.
|
||||
* @param {*} requestOrEvent - The request or event to send.
|
||||
* @returns {Promise<*>|undefined}
|
||||
* Promise that resolves to the response if a request was sent or
|
||||
* undefined if it was an event.
|
||||
*/
|
||||
sendTo(requestOrEvent, address) {
|
||||
sendTo(address, requestOrEvent) {
|
||||
let dst = libData.Address.fromShorthand(address);
|
||||
if (requestOrEvent.constructor.type === "request") {
|
||||
return this.sendRequest(requestOrEvent, dst);
|
||||
|
||||
@@ -515,7 +515,7 @@ instanceSaveCommands.add(new libCommand.Command({
|
||||
}],
|
||||
handler: async function(args, control) {
|
||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||
let saves = await control.sendTo(new libData.InstanceListSavesRequest(), { instanceId });
|
||||
let saves = await control.sendTo({ instanceId }, new libData.InstanceListSavesRequest());
|
||||
for (let entry of saves) {
|
||||
entry.mtime = new Date(entry.mtimeMs).toLocaleString();
|
||||
delete entry.mtimeMs;
|
||||
@@ -540,7 +540,8 @@ instanceSaveCommands.add(new libCommand.Command({
|
||||
let { seed, mapGenSettings, mapSettings } = await loadMapSettings(args);
|
||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
||||
await control.sendTo(
|
||||
new libData.InstanceCreateSaveRequest(args.name, seed, mapGenSettings, mapSettings), { instanceId }
|
||||
{ instanceId },
|
||||
new libData.InstanceCreateSaveRequest(args.name, seed, mapGenSettings, mapSettings),
|
||||
);
|
||||
},
|
||||
}));
|
||||
@@ -711,7 +712,7 @@ instanceCommands.add(new libCommand.Command({
|
||||
handler: async function(args, control) {
|
||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
||||
await control.sendTo(new libData.InstanceExportDataRequest(), { instanceId });
|
||||
await control.sendTo({ instanceId }, new libData.InstanceExportDataRequest());
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -722,7 +723,7 @@ instanceCommands.add(new libCommand.Command({
|
||||
handler: async function(args, control) {
|
||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
||||
await control.sendTo(new libData.InstanceExtractPlayersRequest(), { instanceId });
|
||||
await control.sendTo({ instanceId }, new libData.InstanceExtractPlayersRequest());
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -737,7 +738,7 @@ instanceCommands.add(new libCommand.Command({
|
||||
handler: async function(args, control) {
|
||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
||||
await control.sendTo(new libData.InstanceStartRequest(args.save), { instanceId });
|
||||
await control.sendTo({ instanceId }, new libData.InstanceStartRequest(args.save));
|
||||
control.keepOpen = args.keepOpen;
|
||||
},
|
||||
}));
|
||||
@@ -759,7 +760,8 @@ instanceCommands.add(new libCommand.Command({
|
||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
||||
let { seed, mapGenSettings, mapSettings } = await loadMapSettings(args);
|
||||
await control.sendTo(
|
||||
new libData.InstanceLoadScenarioRequest(args.scenario, seed, mapGenSettings, mapSettings), { instanceId }
|
||||
{ instanceId },
|
||||
new libData.InstanceLoadScenarioRequest(args.scenario, seed, mapGenSettings, mapSettings),
|
||||
);
|
||||
control.keepOpen = args.keepOpen;
|
||||
},
|
||||
@@ -772,7 +774,7 @@ instanceCommands.add(new libCommand.Command({
|
||||
handler: async function(args, control) {
|
||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
||||
await control.sendTo(new libData.InstanceStopRequest(args.save), { instanceId });
|
||||
await control.sendTo({ instanceId }, new libData.InstanceStopRequest(args.save));
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -783,7 +785,7 @@ instanceCommands.add(new libCommand.Command({
|
||||
handler: async function(args, control) {
|
||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
||||
await control.sendTo(new libData.InstanceKillRequest(args.save), { instanceId });
|
||||
await control.sendTo({ instanceId }, new libData.InstanceKillRequest(args.save));
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -804,8 +806,8 @@ instanceCommands.add(new libCommand.Command({
|
||||
}],
|
||||
handler: async function(args, control) {
|
||||
let result = await control.sendTo(
|
||||
new libData.InstanceSendRconRequest(args.command),
|
||||
{ instanceId: await libCommand.resolveInstance(control, args.instance) },
|
||||
new libData.InstanceSendRconRequest(args.command),
|
||||
);
|
||||
|
||||
// Factorio includes a newline in its response output.
|
||||
|
||||
@@ -303,7 +303,7 @@ class Instance extends libLink.Link {
|
||||
name,
|
||||
stats,
|
||||
};
|
||||
this.sendTo(new libData.InstancePlayerUpdateEvent("join", name, undefined, stats), "controller");
|
||||
this.sendTo("controller", new libData.InstancePlayerUpdateEvent("join", name, undefined, stats));
|
||||
libPlugin.invokeHook(this.plugins, "onPlayerEvent", event);
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ class Instance extends libLink.Link {
|
||||
reason,
|
||||
stats,
|
||||
};
|
||||
this.sendTo(new libData.InstancePlayerUpdateEvent("leave", name, reason, stats), "controller");
|
||||
this.sendTo("controller", new libData.InstancePlayerUpdateEvent("leave", name, reason, stats));
|
||||
libPlugin.invokeHook(this.plugins, "onPlayerEvent", event);
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
||||
name,
|
||||
stats: stats.toJSON(),
|
||||
};
|
||||
this.sendTo(new libData.InstancePlayerUpdateEvent("import", name, undefined, stats), "controller");
|
||||
this.sendTo("controller", new libData.InstancePlayerUpdateEvent("import", name, undefined, stats));
|
||||
libPlugin.invokeHook(this.plugins, "onPlayerEvent", event);
|
||||
count += 1;
|
||||
}
|
||||
@@ -405,10 +405,13 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
||||
}
|
||||
|
||||
async sendSaveListUpdate() {
|
||||
this.sendTo(new libData.InstanceSaveListUpdateEvent(
|
||||
this.id,
|
||||
await Instance.listSaves(this.path("saves"), this._loadedSave),
|
||||
), "controller");
|
||||
this.sendTo(
|
||||
"controller",
|
||||
new libData.InstanceSaveListUpdateEvent(
|
||||
this.id,
|
||||
await Instance.listSaves(this.path("saves"), this._loadedSave),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async _autosave(name) {
|
||||
@@ -436,12 +439,12 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
||||
notifyStatus(status) {
|
||||
this._status = status;
|
||||
this.sendTo(
|
||||
"controller",
|
||||
new libData.InstanceStatusChangedEvent(
|
||||
this.id,
|
||||
status,
|
||||
this.server && this.server.gamePort || this.config.get("factorio.game_port") || null,
|
||||
),
|
||||
"controller"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -622,9 +625,9 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
||||
const modPackId = this.config.get("factorio.mod_pack");
|
||||
let modPack;
|
||||
if (modPackId === null) {
|
||||
modPack = await this.sendTo(new libData.ModPackGetDefaultRequest(), "controller");
|
||||
modPack = await this.sendTo("controller", new libData.ModPackGetDefaultRequest());
|
||||
} else {
|
||||
modPack = await this.sendTo(new libData.ModPackGetRequest(modPackId), "controller");
|
||||
modPack = await this.sendTo("controller", new libData.ModPackGetRequest(modPackId));
|
||||
}
|
||||
this.activeModPack = modPack;
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ async function resolveHost(client, hostName) {
|
||||
if (/^-?\d+$/.test(hostName)) {
|
||||
hostId = parseInt(hostName, 10);
|
||||
} else {
|
||||
let hosts = await client.sendTo(new libData.HostListRequest(), "controller");
|
||||
let hosts = await client.sendTo("controller", new libData.HostListRequest());
|
||||
for (let host of hosts) {
|
||||
if (host.name === hostName) {
|
||||
hostId = host.id;
|
||||
@@ -183,7 +183,7 @@ async function resolveInstance(client, instanceName) {
|
||||
if (/^-?\d+$/.test(instanceName)) {
|
||||
instanceId = parseInt(instanceName, 10);
|
||||
} else {
|
||||
let instances = await client.sendTo(new libData.InstanceDetailsListRequest(), "controller");
|
||||
let instances = await client.sendTo("controller", new libData.InstanceDetailsListRequest());
|
||||
for (let instance of instances) {
|
||||
if (instance.name === instanceName) {
|
||||
instanceId = instance.id;
|
||||
@@ -216,7 +216,7 @@ async function resolveModPack(client, modPackName) {
|
||||
if (/^-?\d+/.test(modPackName)) {
|
||||
modPackId = parseInt(modPackName, 10);
|
||||
} else {
|
||||
let modPacks = await client.sendTo(new libData.ModPackListRequest(), "controller");
|
||||
let modPacks = await client.sendTo("controller", new libData.ModPackListRequest());
|
||||
for (let modPack of modPacks) {
|
||||
if (modPack.name === modPackName) {
|
||||
modPackId = modPack.id;
|
||||
@@ -244,7 +244,7 @@ async function resolveModPack(client, modPackName) {
|
||||
* @static
|
||||
*/
|
||||
async function retrieveRole(client, roleName) {
|
||||
let roles = await client.sendTo(new libData.RoleListRequest(), "controller");
|
||||
let roles = await client.sendTo("controller", new libData.RoleListRequest());
|
||||
|
||||
let resolvedRole;
|
||||
if (/^-?\d+$/.test(roleName)) {
|
||||
|
||||
@@ -374,19 +374,19 @@ class Link {
|
||||
* undefined if it was an event.
|
||||
*/
|
||||
send(requestOrEvent) {
|
||||
return this.sendTo(requestOrEvent, this.connector.dst);
|
||||
return this.sendTo(this.connector.dst, requestOrEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a request or event to the given address
|
||||
*
|
||||
* @param {*} requestOrEvent - Request or event to send
|
||||
* @param {*|module:lib/data.Address} destination - Where to send it
|
||||
* @param {*} requestOrEvent - Request or event to send
|
||||
* @returns {Promise<*>|undefined}
|
||||
* Promise that resolves to the response if a request was sent or
|
||||
* undefined if it was an event.
|
||||
*/
|
||||
sendTo(requestOrEvent, destination) {
|
||||
sendTo(destination, requestOrEvent) {
|
||||
let dst = libData.Address.fromShorthand(destination);
|
||||
|
||||
if (requestOrEvent.constructor.type === "request") {
|
||||
|
||||
@@ -52,8 +52,8 @@ export default function CreateSaveModal(props) {
|
||||
|
||||
setCreatingSave(true);
|
||||
control.sendTo(
|
||||
{ instanceId: props.instance.id },
|
||||
new libData.InstanceCreateSaveRequest(name, seed, mapGenSettings, mapSettings),
|
||||
{ instanceId: props.instance.id }
|
||||
).then(() => {
|
||||
form.resetFields();
|
||||
setVisible(false);
|
||||
|
||||
@@ -23,8 +23,8 @@ export default function InstanceRcon(props) {
|
||||
setRunning(true);
|
||||
try {
|
||||
let result = await control.sendTo(
|
||||
{ instanceId: props.id },
|
||||
new libData.InstanceSendRconRequest(command),
|
||||
{ instanceId: props.id }
|
||||
);
|
||||
setOutput(result);
|
||||
} finally {
|
||||
|
||||
@@ -132,7 +132,8 @@ export default function InstanceViewPage(props) {
|
||||
if (key === "export") {
|
||||
setExportingData(true);
|
||||
control.sendTo(
|
||||
new libData.InstanceExportDataRequest(), { instanceId }
|
||||
{ instanceId },
|
||||
new libData.InstanceExportDataRequest(),
|
||||
).catch(
|
||||
notifyErrorHandler("Error exporting data")
|
||||
).finally(() => {
|
||||
@@ -141,12 +142,14 @@ export default function InstanceViewPage(props) {
|
||||
|
||||
} else if (key === "extract") {
|
||||
control.sendTo(
|
||||
new libData.InstanceExtractPlayersRequest(), { instanceId }
|
||||
{ instanceId },
|
||||
new libData.InstanceExtractPlayersRequest(),
|
||||
).catch(notifyErrorHandler("Error extracting player data"));
|
||||
|
||||
} else if (key === "kill") {
|
||||
control.sendTo(
|
||||
new libData.InstanceKillRequest(), { instanceId }
|
||||
{ instanceId },
|
||||
new libData.InstanceKillRequest(),
|
||||
).catch(notifyErrorHandler("Error killing instance"));
|
||||
|
||||
} else if (key === "delete") {
|
||||
|
||||
@@ -84,7 +84,8 @@ export default function InstancesPage() {
|
||||
&& <Button onClick={e => instanceList.forEach(instance => {
|
||||
if (["starting", "running"].includes(instance.status)) {
|
||||
control.sendTo(
|
||||
new libData.InstanceStopRequest(), { instanceId: instance.id }
|
||||
{ instanceId: instance.id },
|
||||
new libData.InstanceStopRequest(),
|
||||
).catch(notifyErrorHandler("Error stopping instance"));
|
||||
}
|
||||
})
|
||||
|
||||
@@ -52,8 +52,8 @@ export default function LoadScenarioModal(props) {
|
||||
|
||||
setLoadingScenario(true);
|
||||
control.sendTo(
|
||||
{ instanceId: props.instance.id },
|
||||
new libData.InstanceLoadScenarioRequest(scenario, seed, mapGenSettings, mapSettings),
|
||||
{ instanceId: props.instance.id }
|
||||
).then(() => {
|
||||
setVisible(false);
|
||||
}).catch(
|
||||
|
||||
@@ -228,7 +228,8 @@ export default function SavesList(props) {
|
||||
onClick={() => {
|
||||
setStarting(true);
|
||||
control.sendTo(
|
||||
new libData.InstanceStartRequest(save.name), { instanceId: props.instance.id }
|
||||
{ instanceId: props.instance.id },
|
||||
new libData.InstanceStartRequest(save.name),
|
||||
).catch(
|
||||
notifyErrorHandler("Error loading save")
|
||||
).finally(
|
||||
|
||||
@@ -17,14 +17,16 @@ export default function StartStopInstanceButton(props) {
|
||||
let action;
|
||||
if (props.instance["status"] === "stopped") {
|
||||
action = control.sendTo(
|
||||
new libData.InstanceStartRequest(undefined), { instanceId: props.instance["id"] }
|
||||
{ instanceId: props.instance["id"] },
|
||||
new libData.InstanceStartRequest(undefined),
|
||||
).catch(
|
||||
notifyErrorHandler("Error starting instance")
|
||||
);
|
||||
|
||||
} else if (["starting", "running"].includes(props.instance["status"])) {
|
||||
action = control.sendTo(
|
||||
new libData.InstanceStopRequest(), { instanceId: props.instance["id"] }
|
||||
{ instanceId: props.instance["id"] },
|
||||
new libData.InstanceStopRequest(),
|
||||
).catch(
|
||||
notifyErrorHandler("Error stopping instance")
|
||||
);
|
||||
|
||||
@@ -10,7 +10,7 @@ export function useSaves(instanceId) {
|
||||
let [saves, setSaves] = useState([]);
|
||||
|
||||
function updateSaves() {
|
||||
control.sendTo(new libData.InstanceListSavesRequest(), { instanceId }).then(updatedSaves => {
|
||||
control.sendTo({ instanceId }, new libData.InstanceListSavesRequest()).then(updatedSaves => {
|
||||
setSaves(updatedSaves);
|
||||
}).catch(err => {
|
||||
logger.error(`Failed to list instance saves: ${err}`);
|
||||
|
||||
@@ -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));
|
||||
},
|
||||
}));
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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}`);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -338,7 +338,7 @@ describe("Integration of Clusterio", function() {
|
||||
let savesDir = path.join("temp", "test", "instances", "test", "saves");
|
||||
await fs.copy(path.join(savesDir, "world.zip"), path.join(savesDir, "_autosave1.zip"));
|
||||
await execCtl("instance start test");
|
||||
let saves = await getControl().sendTo(new libData.InstanceListSavesRequest(), { instanceId: 44 });
|
||||
let saves = await getControl().sendTo({ instanceId: 44 }, new libData.InstanceListSavesRequest());
|
||||
let running = saves.find(s => s.loaded);
|
||||
assert(running.name !== "_autosave1.zip");
|
||||
});
|
||||
|
||||
@@ -150,7 +150,7 @@ async function execCtl(...args) {
|
||||
}
|
||||
|
||||
async function sendRcon(instanceId, command) {
|
||||
return await control.sendTo(new libData.InstanceSendRconRequest(command), { instanceId });
|
||||
return await control.sendTo({ instanceId }, new libData.InstanceSendRconRequest(command));
|
||||
}
|
||||
|
||||
function getControl() {
|
||||
@@ -234,9 +234,10 @@ before(async function() {
|
||||
testPack.factorioVersion = "1.1.0";
|
||||
testPack.mods.set("clusterio_lib", { name: "clusterio_lib", enabled: true, version: "0.1.2" });
|
||||
testPack.mods.set("subspace_storage", { name: "subspace_storage", enabled: true, version: "1.99.8" });
|
||||
await control.sendTo(new libData.ModPackCreateRequest(testPack), "controller");
|
||||
await control.sendTo("controller", new libData.ModPackCreateRequest(testPack));
|
||||
await control.sendTo(
|
||||
new libData.ControllerConfigSetFieldRequest("controller.default_mod_pack_id", "12"), "controller"
|
||||
"controller",
|
||||
new libData.ControllerConfigSetFieldRequest("controller.default_mod_pack_id", "12"),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user