mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 07:04:52 +09:00
In order to import a path inside packages/lib/ in the webpack shared
module environment it has to be declared as shared in both the web_ui
webpack config and the plugin's webpack config. This is rather error
prone and easy to miss. Move the burden of specifying which entrypoints
are valid in lib to lib itself by changing all imports in the web
interface code to import from @clusterio/lib instead sub paths.
For web code this means imports is done like this from now on:
import { libConfig, libLink } from "@clusterio/lib";
For info.js which has to be loadable by both Node.js and web code the
imports are done as follows:
const { libConfig, libLink } = require("@clusterio/lib");
While the Node.js only code can either continue to import sub paths
directly or use the info.js style.
92 lines
2.5 KiB
JavaScript
92 lines
2.5 KiB
JavaScript
"use strict";
|
|
const { libConfig, libLink, libUsers } = require("@clusterio/lib");
|
|
|
|
class MasterConfigGroup extends libConfig.PluginConfigGroup { }
|
|
MasterConfigGroup.defaultAccess = ["master", "slave", "control"];
|
|
MasterConfigGroup.groupName = "inventory_sync";
|
|
MasterConfigGroup.define({
|
|
name: "autosave_interval",
|
|
title: "Autosave Interval",
|
|
description: "Interval the player data is autosaved at in seconds.",
|
|
type: "number",
|
|
initial_value: 600, // 10 minutes
|
|
});
|
|
MasterConfigGroup.finalize();
|
|
|
|
class InstanceConfigGroup extends libConfig.PluginConfigGroup { }
|
|
InstanceConfigGroup.defaultAccess = ["master", "slave", "control"];
|
|
InstanceConfigGroup.groupName = "inventory_sync";
|
|
InstanceConfigGroup.define({
|
|
name: "rcon_chunk_size",
|
|
title: "Rcon inventory chunk size",
|
|
description: "Divide inventories into multiple chunks before sending with rcon to prevent blocking the pipe",
|
|
type: "number",
|
|
initial_value: 1000,
|
|
});
|
|
InstanceConfigGroup.finalize();
|
|
|
|
libUsers.definePermission({
|
|
name: "inventory_sync.inventory.view",
|
|
title: "View player inventories",
|
|
description: "View player inventories",
|
|
grantByDefault: true,
|
|
});
|
|
|
|
module.exports = {
|
|
name: "inventory_sync",
|
|
title: "Inventory sync",
|
|
description: "Synchronizes players inventories between instances",
|
|
|
|
instanceEntrypoint: "instance",
|
|
InstanceConfigGroup,
|
|
|
|
masterEntrypoint: "master",
|
|
MasterConfigGroup,
|
|
|
|
webEntrypoint: "./web",
|
|
routes: ["/inventory"],
|
|
|
|
messages: {
|
|
upload: new libLink.Request({
|
|
type: "inventory_sync:upload",
|
|
links: ["instance-slave", "slave-master"],
|
|
forwardTo: "master",
|
|
requestProperties: {
|
|
"instance_id": { type: "integer" },
|
|
"instance_name": { type: "string" },
|
|
"player_name": { type: "string" },
|
|
"inventory": { type: "object" },
|
|
},
|
|
}),
|
|
download: new libLink.Request({
|
|
type: "inventory_sync:download",
|
|
links: ["instance-slave", "slave-master"],
|
|
forwardTo: "master",
|
|
requestProperties: {
|
|
"player_name": { type: "string" },
|
|
},
|
|
responseProperties: {
|
|
"player_name": { type: "string" },
|
|
"inventory": { type: "object" },
|
|
"new_player": { type: "boolean" },
|
|
},
|
|
}),
|
|
databaseStats: new libLink.Request({
|
|
type: "inventory_sync:databaseStats",
|
|
links: ["control-master"],
|
|
permission: "inventory_sync.inventory.view",
|
|
responseProperties: {
|
|
"database_size": { type: "integer" },
|
|
"database_entries": { type: "integer" },
|
|
"largest_entry": {
|
|
type: "object",
|
|
properties: {
|
|
name: { type: "string" },
|
|
size: { type: "number" },
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
},
|
|
};
|