mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 08:13:12 +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.
|
// Let host handle request if source and target is on the same host.
|
||||||
if (sourceHostId === targetHostId) {
|
if (sourceHostId === targetHostId) {
|
||||||
return await this._controller.sendTo(request, { hostId: sourceHostId });
|
return await this._controller.sendTo({ hostId: sourceHostId }, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check connectivity
|
// Check connectivity
|
||||||
@@ -451,23 +451,23 @@ class ControlConnection extends BaseConnection {
|
|||||||
// ensure the file size is known prior to the target host pull.
|
// ensure the file size is known prior to the target host pull.
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this._controller.sendTo(
|
this._controller.sendTo(
|
||||||
|
{ hostId: sourceHostId },
|
||||||
new libData.InstancePushSaveRequest(request.sourceInstanceId, stream.id, request.sourceName),
|
new libData.InstancePushSaveRequest(request.sourceInstanceId, stream.id, request.sourceName),
|
||||||
{ hostId: sourceHostId }
|
|
||||||
),
|
),
|
||||||
events.once(stream.events, "source"),
|
events.once(stream.events, "source"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Establish pull from target host to stream and wait for completion.
|
// Establish pull from target host to stream and wait for completion.
|
||||||
let storedName = await this._controller.sendTo(
|
let storedName = await this._controller.sendTo(
|
||||||
new libData.InstancePullSaveRequest(request.targetInstanceId, stream.id, request.targetName),
|
|
||||||
{ hostId: targetHostId },
|
{ hostId: targetHostId },
|
||||||
|
new libData.InstancePullSaveRequest(request.targetInstanceId, stream.id, request.targetName),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Delete source save if this is not a copy
|
// Delete source save if this is not a copy
|
||||||
if (!request.copy) {
|
if (!request.copy) {
|
||||||
await this._controller.sendTo(
|
await this._controller.sendTo(
|
||||||
|
{ hostId: sourceHostId },
|
||||||
new libData.InstanceDeleteSaveRequest(request.sourceInstanceId, request.sourceName),
|
new libData.InstanceDeleteSaveRequest(request.sourceInstanceId, request.sourceName),
|
||||||
{ hostId: sourceHostId }
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -887,7 +887,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
|
|
||||||
user.isAdmin = admin;
|
user.isAdmin = admin;
|
||||||
this._controller.userUpdated(user);
|
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) {
|
async handleUserSetBannedRequest(request) {
|
||||||
@@ -905,7 +905,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
user.isBanned = banned;
|
user.isBanned = banned;
|
||||||
user.banReason = reason;
|
user.banReason = reason;
|
||||||
this._controller.userUpdated(user);
|
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) {
|
async handleUserSetWhitelistedRequest(request) {
|
||||||
@@ -922,7 +922,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
|
|
||||||
user.isWhitelisted = whitelisted;
|
user.isWhitelisted = whitelisted;
|
||||||
this._controller.userUpdated(user);
|
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) {
|
async handleUserDeleteRequest(request) {
|
||||||
@@ -937,13 +937,13 @@ class ControlConnection extends BaseConnection {
|
|||||||
this._controller.userUpdated(user);
|
this._controller.userUpdated(user);
|
||||||
|
|
||||||
if (user.is_admin) {
|
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) {
|
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) {
|
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 instance = this.getRequestInstance(instanceId);
|
||||||
let hostId = instance.config.get("instance.assigned_host");
|
let hostId = instance.config.get("instance.assigned_host");
|
||||||
if (hostId !== null) {
|
if (hostId !== null) {
|
||||||
await this.sendTo(new libData.InstanceDeleteInternalRequest(instanceId), { hostId });
|
await this.sendTo({ hostId }, new libData.InstanceDeleteInternalRequest(instanceId));
|
||||||
}
|
}
|
||||||
this.instances.delete(instanceId);
|
this.instances.delete(instanceId);
|
||||||
|
|
||||||
@@ -1028,13 +1028,13 @@ class Controller {
|
|||||||
* destination argument supports address shorthands, see {@link
|
* destination argument supports address shorthands, see {@link
|
||||||
* module:lib/data.Address.fromShorthand}
|
* module:lib/data.Address.fromShorthand}
|
||||||
*
|
*
|
||||||
* @param {*} requestOrEvent - The request or event to send.
|
|
||||||
* @param {*|module:lib/data.Address} address - Where to send it.
|
* @param {*|module:lib/data.Address} address - Where to send it.
|
||||||
|
* @param {*} requestOrEvent - The request or event to send.
|
||||||
* @returns {Promise<*>|undefined}
|
* @returns {Promise<*>|undefined}
|
||||||
* Promise that resolves to the response if a request was sent or
|
* Promise that resolves to the response if a request was sent or
|
||||||
* undefined if it was an event.
|
* undefined if it was an event.
|
||||||
*/
|
*/
|
||||||
sendTo(requestOrEvent, address) {
|
sendTo(address, requestOrEvent) {
|
||||||
let dst = libData.Address.fromShorthand(address);
|
let dst = libData.Address.fromShorthand(address);
|
||||||
if (requestOrEvent.constructor.type === "request") {
|
if (requestOrEvent.constructor.type === "request") {
|
||||||
return this.sendRequest(requestOrEvent, dst);
|
return this.sendRequest(requestOrEvent, dst);
|
||||||
|
|||||||
@@ -515,7 +515,7 @@ instanceSaveCommands.add(new libCommand.Command({
|
|||||||
}],
|
}],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
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) {
|
for (let entry of saves) {
|
||||||
entry.mtime = new Date(entry.mtimeMs).toLocaleString();
|
entry.mtime = new Date(entry.mtimeMs).toLocaleString();
|
||||||
delete entry.mtimeMs;
|
delete entry.mtimeMs;
|
||||||
@@ -540,7 +540,8 @@ instanceSaveCommands.add(new libCommand.Command({
|
|||||||
let { seed, mapGenSettings, mapSettings } = await loadMapSettings(args);
|
let { seed, mapGenSettings, mapSettings } = await loadMapSettings(args);
|
||||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
||||||
await control.sendTo(
|
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) {
|
handler: async function(args, control) {
|
||||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
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) {
|
handler: async function(args, control) {
|
||||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
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) {
|
handler: async function(args, control) {
|
||||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
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;
|
control.keepOpen = args.keepOpen;
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@@ -759,7 +760,8 @@ instanceCommands.add(new libCommand.Command({
|
|||||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
||||||
let { seed, mapGenSettings, mapSettings } = await loadMapSettings(args);
|
let { seed, mapGenSettings, mapSettings } = await loadMapSettings(args);
|
||||||
await control.sendTo(
|
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;
|
control.keepOpen = args.keepOpen;
|
||||||
},
|
},
|
||||||
@@ -772,7 +774,7 @@ instanceCommands.add(new libCommand.Command({
|
|||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
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) {
|
handler: async function(args, control) {
|
||||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||||
await control.setLogSubscriptions({ instanceIds: [instanceId] });
|
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) {
|
handler: async function(args, control) {
|
||||||
let result = await control.sendTo(
|
let result = await control.sendTo(
|
||||||
new libData.InstanceSendRconRequest(args.command),
|
|
||||||
{ instanceId: await libCommand.resolveInstance(control, args.instance) },
|
{ instanceId: await libCommand.resolveInstance(control, args.instance) },
|
||||||
|
new libData.InstanceSendRconRequest(args.command),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Factorio includes a newline in its response output.
|
// Factorio includes a newline in its response output.
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ class Instance extends libLink.Link {
|
|||||||
name,
|
name,
|
||||||
stats,
|
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);
|
libPlugin.invokeHook(this.plugins, "onPlayerEvent", event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,7 +325,7 @@ class Instance extends libLink.Link {
|
|||||||
reason,
|
reason,
|
||||||
stats,
|
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);
|
libPlugin.invokeHook(this.plugins, "onPlayerEvent", event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
name,
|
name,
|
||||||
stats: stats.toJSON(),
|
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);
|
libPlugin.invokeHook(this.plugins, "onPlayerEvent", event);
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
@@ -405,10 +405,13 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
}
|
}
|
||||||
|
|
||||||
async sendSaveListUpdate() {
|
async sendSaveListUpdate() {
|
||||||
this.sendTo(new libData.InstanceSaveListUpdateEvent(
|
this.sendTo(
|
||||||
this.id,
|
"controller",
|
||||||
await Instance.listSaves(this.path("saves"), this._loadedSave),
|
new libData.InstanceSaveListUpdateEvent(
|
||||||
), "controller");
|
this.id,
|
||||||
|
await Instance.listSaves(this.path("saves"), this._loadedSave),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _autosave(name) {
|
async _autosave(name) {
|
||||||
@@ -436,12 +439,12 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
notifyStatus(status) {
|
notifyStatus(status) {
|
||||||
this._status = status;
|
this._status = status;
|
||||||
this.sendTo(
|
this.sendTo(
|
||||||
|
"controller",
|
||||||
new libData.InstanceStatusChangedEvent(
|
new libData.InstanceStatusChangedEvent(
|
||||||
this.id,
|
this.id,
|
||||||
status,
|
status,
|
||||||
this.server && this.server.gamePort || this.config.get("factorio.game_port") || null,
|
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");
|
const modPackId = this.config.get("factorio.mod_pack");
|
||||||
let modPack;
|
let modPack;
|
||||||
if (modPackId === null) {
|
if (modPackId === null) {
|
||||||
modPack = await this.sendTo(new libData.ModPackGetDefaultRequest(), "controller");
|
modPack = await this.sendTo("controller", new libData.ModPackGetDefaultRequest());
|
||||||
} else {
|
} else {
|
||||||
modPack = await this.sendTo(new libData.ModPackGetRequest(modPackId), "controller");
|
modPack = await this.sendTo("controller", new libData.ModPackGetRequest(modPackId));
|
||||||
}
|
}
|
||||||
this.activeModPack = modPack;
|
this.activeModPack = modPack;
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ async function resolveHost(client, hostName) {
|
|||||||
if (/^-?\d+$/.test(hostName)) {
|
if (/^-?\d+$/.test(hostName)) {
|
||||||
hostId = parseInt(hostName, 10);
|
hostId = parseInt(hostName, 10);
|
||||||
} else {
|
} else {
|
||||||
let hosts = await client.sendTo(new libData.HostListRequest(), "controller");
|
let hosts = await client.sendTo("controller", new libData.HostListRequest());
|
||||||
for (let host of hosts) {
|
for (let host of hosts) {
|
||||||
if (host.name === hostName) {
|
if (host.name === hostName) {
|
||||||
hostId = host.id;
|
hostId = host.id;
|
||||||
@@ -183,7 +183,7 @@ async function resolveInstance(client, instanceName) {
|
|||||||
if (/^-?\d+$/.test(instanceName)) {
|
if (/^-?\d+$/.test(instanceName)) {
|
||||||
instanceId = parseInt(instanceName, 10);
|
instanceId = parseInt(instanceName, 10);
|
||||||
} else {
|
} else {
|
||||||
let instances = await client.sendTo(new libData.InstanceDetailsListRequest(), "controller");
|
let instances = await client.sendTo("controller", new libData.InstanceDetailsListRequest());
|
||||||
for (let instance of instances) {
|
for (let instance of instances) {
|
||||||
if (instance.name === instanceName) {
|
if (instance.name === instanceName) {
|
||||||
instanceId = instance.id;
|
instanceId = instance.id;
|
||||||
@@ -216,7 +216,7 @@ async function resolveModPack(client, modPackName) {
|
|||||||
if (/^-?\d+/.test(modPackName)) {
|
if (/^-?\d+/.test(modPackName)) {
|
||||||
modPackId = parseInt(modPackName, 10);
|
modPackId = parseInt(modPackName, 10);
|
||||||
} else {
|
} else {
|
||||||
let modPacks = await client.sendTo(new libData.ModPackListRequest(), "controller");
|
let modPacks = await client.sendTo("controller", new libData.ModPackListRequest());
|
||||||
for (let modPack of modPacks) {
|
for (let modPack of modPacks) {
|
||||||
if (modPack.name === modPackName) {
|
if (modPack.name === modPackName) {
|
||||||
modPackId = modPack.id;
|
modPackId = modPack.id;
|
||||||
@@ -244,7 +244,7 @@ async function resolveModPack(client, modPackName) {
|
|||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
async function retrieveRole(client, roleName) {
|
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;
|
let resolvedRole;
|
||||||
if (/^-?\d+$/.test(roleName)) {
|
if (/^-?\d+$/.test(roleName)) {
|
||||||
|
|||||||
@@ -374,19 +374,19 @@ class Link {
|
|||||||
* undefined if it was an event.
|
* undefined if it was an event.
|
||||||
*/
|
*/
|
||||||
send(requestOrEvent) {
|
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
|
* 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 {*|module:lib/data.Address} destination - Where to send it
|
||||||
|
* @param {*} requestOrEvent - Request or event to send
|
||||||
* @returns {Promise<*>|undefined}
|
* @returns {Promise<*>|undefined}
|
||||||
* Promise that resolves to the response if a request was sent or
|
* Promise that resolves to the response if a request was sent or
|
||||||
* undefined if it was an event.
|
* undefined if it was an event.
|
||||||
*/
|
*/
|
||||||
sendTo(requestOrEvent, destination) {
|
sendTo(destination, requestOrEvent) {
|
||||||
let dst = libData.Address.fromShorthand(destination);
|
let dst = libData.Address.fromShorthand(destination);
|
||||||
|
|
||||||
if (requestOrEvent.constructor.type === "request") {
|
if (requestOrEvent.constructor.type === "request") {
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ export default function CreateSaveModal(props) {
|
|||||||
|
|
||||||
setCreatingSave(true);
|
setCreatingSave(true);
|
||||||
control.sendTo(
|
control.sendTo(
|
||||||
|
{ instanceId: props.instance.id },
|
||||||
new libData.InstanceCreateSaveRequest(name, seed, mapGenSettings, mapSettings),
|
new libData.InstanceCreateSaveRequest(name, seed, mapGenSettings, mapSettings),
|
||||||
{ instanceId: props.instance.id }
|
|
||||||
).then(() => {
|
).then(() => {
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ export default function InstanceRcon(props) {
|
|||||||
setRunning(true);
|
setRunning(true);
|
||||||
try {
|
try {
|
||||||
let result = await control.sendTo(
|
let result = await control.sendTo(
|
||||||
|
{ instanceId: props.id },
|
||||||
new libData.InstanceSendRconRequest(command),
|
new libData.InstanceSendRconRequest(command),
|
||||||
{ instanceId: props.id }
|
|
||||||
);
|
);
|
||||||
setOutput(result);
|
setOutput(result);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ export default function InstanceViewPage(props) {
|
|||||||
if (key === "export") {
|
if (key === "export") {
|
||||||
setExportingData(true);
|
setExportingData(true);
|
||||||
control.sendTo(
|
control.sendTo(
|
||||||
new libData.InstanceExportDataRequest(), { instanceId }
|
{ instanceId },
|
||||||
|
new libData.InstanceExportDataRequest(),
|
||||||
).catch(
|
).catch(
|
||||||
notifyErrorHandler("Error exporting data")
|
notifyErrorHandler("Error exporting data")
|
||||||
).finally(() => {
|
).finally(() => {
|
||||||
@@ -141,12 +142,14 @@ export default function InstanceViewPage(props) {
|
|||||||
|
|
||||||
} else if (key === "extract") {
|
} else if (key === "extract") {
|
||||||
control.sendTo(
|
control.sendTo(
|
||||||
new libData.InstanceExtractPlayersRequest(), { instanceId }
|
{ instanceId },
|
||||||
|
new libData.InstanceExtractPlayersRequest(),
|
||||||
).catch(notifyErrorHandler("Error extracting player data"));
|
).catch(notifyErrorHandler("Error extracting player data"));
|
||||||
|
|
||||||
} else if (key === "kill") {
|
} else if (key === "kill") {
|
||||||
control.sendTo(
|
control.sendTo(
|
||||||
new libData.InstanceKillRequest(), { instanceId }
|
{ instanceId },
|
||||||
|
new libData.InstanceKillRequest(),
|
||||||
).catch(notifyErrorHandler("Error killing instance"));
|
).catch(notifyErrorHandler("Error killing instance"));
|
||||||
|
|
||||||
} else if (key === "delete") {
|
} else if (key === "delete") {
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ export default function InstancesPage() {
|
|||||||
&& <Button onClick={e => instanceList.forEach(instance => {
|
&& <Button onClick={e => instanceList.forEach(instance => {
|
||||||
if (["starting", "running"].includes(instance.status)) {
|
if (["starting", "running"].includes(instance.status)) {
|
||||||
control.sendTo(
|
control.sendTo(
|
||||||
new libData.InstanceStopRequest(), { instanceId: instance.id }
|
{ instanceId: instance.id },
|
||||||
|
new libData.InstanceStopRequest(),
|
||||||
).catch(notifyErrorHandler("Error stopping instance"));
|
).catch(notifyErrorHandler("Error stopping instance"));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ export default function LoadScenarioModal(props) {
|
|||||||
|
|
||||||
setLoadingScenario(true);
|
setLoadingScenario(true);
|
||||||
control.sendTo(
|
control.sendTo(
|
||||||
|
{ instanceId: props.instance.id },
|
||||||
new libData.InstanceLoadScenarioRequest(scenario, seed, mapGenSettings, mapSettings),
|
new libData.InstanceLoadScenarioRequest(scenario, seed, mapGenSettings, mapSettings),
|
||||||
{ instanceId: props.instance.id }
|
|
||||||
).then(() => {
|
).then(() => {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
}).catch(
|
}).catch(
|
||||||
|
|||||||
@@ -228,7 +228,8 @@ export default function SavesList(props) {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
setStarting(true);
|
setStarting(true);
|
||||||
control.sendTo(
|
control.sendTo(
|
||||||
new libData.InstanceStartRequest(save.name), { instanceId: props.instance.id }
|
{ instanceId: props.instance.id },
|
||||||
|
new libData.InstanceStartRequest(save.name),
|
||||||
).catch(
|
).catch(
|
||||||
notifyErrorHandler("Error loading save")
|
notifyErrorHandler("Error loading save")
|
||||||
).finally(
|
).finally(
|
||||||
|
|||||||
@@ -17,14 +17,16 @@ export default function StartStopInstanceButton(props) {
|
|||||||
let action;
|
let action;
|
||||||
if (props.instance["status"] === "stopped") {
|
if (props.instance["status"] === "stopped") {
|
||||||
action = control.sendTo(
|
action = control.sendTo(
|
||||||
new libData.InstanceStartRequest(undefined), { instanceId: props.instance["id"] }
|
{ instanceId: props.instance["id"] },
|
||||||
|
new libData.InstanceStartRequest(undefined),
|
||||||
).catch(
|
).catch(
|
||||||
notifyErrorHandler("Error starting instance")
|
notifyErrorHandler("Error starting instance")
|
||||||
);
|
);
|
||||||
|
|
||||||
} else if (["starting", "running"].includes(props.instance["status"])) {
|
} else if (["starting", "running"].includes(props.instance["status"])) {
|
||||||
action = control.sendTo(
|
action = control.sendTo(
|
||||||
new libData.InstanceStopRequest(), { instanceId: props.instance["id"] }
|
{ instanceId: props.instance["id"] },
|
||||||
|
new libData.InstanceStopRequest(),
|
||||||
).catch(
|
).catch(
|
||||||
notifyErrorHandler("Error stopping instance")
|
notifyErrorHandler("Error stopping instance")
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export function useSaves(instanceId) {
|
|||||||
let [saves, setSaves] = useState([]);
|
let [saves, setSaves] = useState([]);
|
||||||
|
|
||||||
function updateSaves() {
|
function updateSaves() {
|
||||||
control.sendTo(new libData.InstanceListSavesRequest(), { instanceId }).then(updatedSaves => {
|
control.sendTo({ instanceId }, new libData.InstanceListSavesRequest()).then(updatedSaves => {
|
||||||
setSaves(updatedSaves);
|
setSaves(updatedSaves);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
logger.error(`Failed to list instance saves: ${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" });
|
yargs.positional("message", { describe: "message to send", type: "string" });
|
||||||
}],
|
}],
|
||||||
handler: async function(args, control) {
|
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) {
|
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) {
|
async onOutput(output) {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.playersToRelease.delete(player);
|
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(
|
})().catch(
|
||||||
err => this.logger.error(`Unpexpected error releasing queued up players:\n${err.stack}`)
|
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) {
|
if (this.host.connector.connected && !this.disconnecting) {
|
||||||
try {
|
try {
|
||||||
let acquireResponse = await this.instance.sendTo(
|
let acquireResponse = await this.instance.sendTo(
|
||||||
|
"controller",
|
||||||
new AcquireRequest(this.instance.id, request.player_name),
|
new AcquireRequest(this.instance.id, request.player_name),
|
||||||
"controller"
|
|
||||||
);
|
);
|
||||||
response = {
|
response = {
|
||||||
player_name: request.player_name,
|
player_name: request.player_name,
|
||||||
@@ -99,7 +99,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (err) {
|
||||||
if (err instanceof libErrors.SessionLost) {
|
if (err instanceof libErrors.SessionLost) {
|
||||||
this.playersToRelease.set(request.player_name);
|
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)`);
|
this.logger.verbose(`Uploading ${player_data.name} (${JSON.stringify(player_data).length / 1000}kB)`);
|
||||||
try {
|
try {
|
||||||
await this.instance.sendTo(
|
await this.instance.sendTo(
|
||||||
|
"controller",
|
||||||
new UploadRequest(this.instance.id, player_data.name, player_data),
|
new UploadRequest(this.instance.id, player_data.name, player_data),
|
||||||
"controller"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -137,7 +137,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
const playerName = request.player_name;
|
const playerName = request.player_name;
|
||||||
this.logger.verbose(`Downloading ${playerName}`);
|
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) {
|
if (!response.player_data) {
|
||||||
await this.sendRcon(`/sc inventory_sync.download_inventory('${playerName}',nil,0,0)`, true);
|
await this.sendRcon(`/sc inventory_sync.download_inventory('${playerName}',nil,0,0)`, true);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
|
|
||||||
let response;
|
let response;
|
||||||
try {
|
try {
|
||||||
response = await this.instance.sendTo(new FetchPlayerCodeRequest(event.player), "controller");
|
response = await this.instance.sendTo("controller", new FetchPlayerCodeRequest(event.player));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await this.sendRcon(`/web-login error ${event.player} ${err.message}`);
|
await this.sendRcon(`/web-login error ${event.player} ${err.message}`);
|
||||||
return;
|
return;
|
||||||
@@ -36,7 +36,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
|
|
||||||
} else if (event.type === "set_verify_code") {
|
} else if (event.type === "set_verify_code") {
|
||||||
try {
|
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) {
|
} catch (err) {
|
||||||
await this.sendRcon(`/web-login error ${event.player} ${err.message}`);
|
await this.sendRcon(`/web-login error ${event.player} ${err.message}`);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class ControllerPlugin extends libPlugin.BaseControllerPlugin {
|
|||||||
|
|
||||||
this.lastProgressBroadcast = Date.now();
|
this.lastProgressBroadcast = Date.now();
|
||||||
if (techs.length) {
|
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;
|
tech.progress = null;
|
||||||
this.progressToBroadcast.delete(name);
|
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) {
|
if (progress) {
|
||||||
this.progressToBroadcast.add(name);
|
this.progressToBroadcast.add(name);
|
||||||
} else if (researched || baseLevel(name) !== level) {
|
} else if (researched || baseLevel(name) !== level) {
|
||||||
this.controller.sendTo(new FinishedEvent(name, tech), "allInstances");
|
this.controller.sendTo("allInstances", new FinishedEvent(name, tech));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -150,7 +150,7 @@ class ControllerPlugin extends libPlugin.BaseControllerPlugin {
|
|||||||
if (tech.level < level || researched) {
|
if (tech.level < level || researched) {
|
||||||
// Send update if the unlocked level is greater
|
// Send update if the unlocked level is greater
|
||||||
if (level - !researched > tech.level - !tech.researched) {
|
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.level = level;
|
||||||
tech.progress = progress;
|
tech.progress = progress;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async researchContribution(tech) {
|
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) {
|
async handleProgressEvent(event) {
|
||||||
@@ -45,7 +45,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async researchFinished(tech) {
|
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) {
|
async handleFinishedEvent(event) {
|
||||||
@@ -72,7 +72,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
instanceTechs.set(tech.name, tech);
|
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;
|
this.syncStarted = true;
|
||||||
let techsToSync = [];
|
let techsToSync = [];
|
||||||
for (let controllerTech of controllerTechs) {
|
for (let controllerTech of controllerTechs) {
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ class ControllerPlugin extends libPlugin.BaseControllerPlugin {
|
|||||||
|
|
||||||
itemsToUpdate = [...itemsToUpdate.entries()];
|
itemsToUpdate = [...itemsToUpdate.entries()];
|
||||||
let update = new UpdateStorageEvent(itemsToUpdate);
|
let update = new UpdateStorageEvent(itemsToUpdate);
|
||||||
this.controller.sendTo(update, "allInstances");
|
this.controller.sendTo("allInstances", update);
|
||||||
for (let link of this.subscribedControlLinks) {
|
for (let link of this.subscribedControlLinks) {
|
||||||
link.send(update);
|
link.send(update);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
).catch(err => this.unexpectedError(err));
|
).catch(err => this.unexpectedError(err));
|
||||||
}, 5000);
|
}, 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
|
// TODO Diff with dump of invdata produce minimal command to sync
|
||||||
let itemsJson = libLuaTools.escapeString(JSON.stringify(items));
|
let itemsJson = libLuaTools.escapeString(JSON.stringify(items));
|
||||||
await this.sendRcon(`/sc __subspace_storage__ UpdateInvData("${itemsJson}", true)`, true);
|
await this.sendRcon(`/sc __subspace_storage__ UpdateInvData("${itemsJson}", true)`, true);
|
||||||
@@ -71,7 +71,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
return;
|
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")) {
|
if (this.instance.config.get("subspace_storage.log_item_transfers")) {
|
||||||
this.logger.verbose("Exported the following to controller:");
|
this.logger.verbose("Exported the following to controller:");
|
||||||
@@ -82,7 +82,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
// request items --------------------------------------------------------------
|
// request items --------------------------------------------------------------
|
||||||
async requestItems(requestItems) {
|
async requestItems(requestItems) {
|
||||||
// Request the items all at once
|
// 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) {
|
if (!items.length) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ describe("Integration of Clusterio", function() {
|
|||||||
let savesDir = path.join("temp", "test", "instances", "test", "saves");
|
let savesDir = path.join("temp", "test", "instances", "test", "saves");
|
||||||
await fs.copy(path.join(savesDir, "world.zip"), path.join(savesDir, "_autosave1.zip"));
|
await fs.copy(path.join(savesDir, "world.zip"), path.join(savesDir, "_autosave1.zip"));
|
||||||
await execCtl("instance start test");
|
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);
|
let running = saves.find(s => s.loaded);
|
||||||
assert(running.name !== "_autosave1.zip");
|
assert(running.name !== "_autosave1.zip");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ async function execCtl(...args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sendRcon(instanceId, command) {
|
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() {
|
function getControl() {
|
||||||
@@ -234,9 +234,10 @@ before(async function() {
|
|||||||
testPack.factorioVersion = "1.1.0";
|
testPack.factorioVersion = "1.1.0";
|
||||||
testPack.mods.set("clusterio_lib", { name: "clusterio_lib", enabled: true, version: "0.1.2" });
|
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" });
|
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(
|
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