mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Add a per field access parameter to the config class which specifies which of master, slave and control can access the given field. A location is added to the config class to specify which party owns it and fields which do not have an access parameter are not present in the config and will throw if attempted to be read from or writen to. The serialize, load, update, get, set and setProp are ammended with a location parameter which specifiy where the data is from or destined to and the access checks are performed to ensure remote access to the config is still limited by the access parameter of field. With this system in place the master config can be shared with control and slave connections without compromising secrets that should stay private. This is primarily the master authentication secret, but other plugins may define secrets it does not want to have shared with slave and/or control connections.
109 lines
2.8 KiB
JavaScript
109 lines
2.8 KiB
JavaScript
"use strict";
|
|
const libLink = require("@clusterio/lib/link");
|
|
const libConfig = require("@clusterio/lib/config");
|
|
|
|
class MasterConfigGroup extends libConfig.PluginConfigGroup {}
|
|
MasterConfigGroup.defaultAccess = ["master", "slave", "control"];
|
|
MasterConfigGroup.groupName = "subspace_storage";
|
|
MasterConfigGroup.define({
|
|
name: "autosave_interval",
|
|
title: "Autosave Interval",
|
|
description: "Interval the storage is autosaved at in seconds.",
|
|
type: "number",
|
|
initial_value: 60,
|
|
});
|
|
MasterConfigGroup.define({
|
|
name: "division_method",
|
|
title: "Division Method",
|
|
description: "Method for dividing resource requests between instances.",
|
|
type: "string",
|
|
enum: ["simple", "dole", "neural_dole"],
|
|
initial_value: "simple",
|
|
});
|
|
MasterConfigGroup.define({
|
|
name: "log_item_transfers",
|
|
title: "Log Item Transfers",
|
|
description: "Spam master console with item transfers done.",
|
|
type: "boolean",
|
|
initial_value: false,
|
|
});
|
|
MasterConfigGroup.finalize();
|
|
|
|
class InstanceConfigGroup extends libConfig.PluginConfigGroup {}
|
|
InstanceConfigGroup.defaultAccess = ["master", "slave", "control"];
|
|
InstanceConfigGroup.groupName = "subspace_storage";
|
|
InstanceConfigGroup.define({
|
|
name: "log_item_transfers",
|
|
title: "Log Item Transfers",
|
|
description: "Spam slave console with item transfers done.",
|
|
type: "boolean",
|
|
initial_value: false,
|
|
});
|
|
InstanceConfigGroup.finalize();
|
|
|
|
// JSON schema for subspace storage items
|
|
const items = {
|
|
type: "array",
|
|
items: {
|
|
type: "array",
|
|
minItems: 2,
|
|
maxItems: 2,
|
|
items: [
|
|
{ type: "string" },
|
|
{ type: "integer" },
|
|
],
|
|
},
|
|
};
|
|
|
|
module.exports = {
|
|
name: "subspace_storage",
|
|
title: "Subspace Storage",
|
|
description: "Provides shared storage across instances for the Subspace Storage mod",
|
|
instanceEntrypoint: "instance",
|
|
InstanceConfigGroup,
|
|
|
|
masterEntrypoint: "master",
|
|
MasterConfigGroup,
|
|
|
|
messages: {
|
|
// XXX this should be a request to be reliable
|
|
place: new libLink.Event({
|
|
type: "subspace_storage:place",
|
|
links: ["instance-slave", "slave-master"],
|
|
forwardTo: "master",
|
|
eventProperties: {
|
|
"instance_id": { type: "integer" },
|
|
"items": items,
|
|
},
|
|
}),
|
|
remove: new libLink.Request({
|
|
type: "subspace_storage:remove",
|
|
links: ["instance-slave", "slave-master"],
|
|
forwardTo: "master",
|
|
requestProperties: {
|
|
"instance_id": { type: "integer" },
|
|
"items": items,
|
|
},
|
|
responseProperties: {
|
|
"items": items,
|
|
},
|
|
}),
|
|
getStorage: new libLink.Request({
|
|
type: "subspace_storage:get_storage",
|
|
links: ["instance-slave", "slave-master"],
|
|
forwardTo: "master",
|
|
responseProperties: {
|
|
"items": items,
|
|
},
|
|
}),
|
|
updateStorage: new libLink.Event({
|
|
type: "subspace_storage:update_storage",
|
|
links: ["master-slave", "slave-instance"],
|
|
broadcastTo: "instance",
|
|
eventProperties: {
|
|
"items": items,
|
|
},
|
|
}),
|
|
},
|
|
};
|