mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Merge pull request #366 from Hornwitser/plugin-improvements
Plugin improvements
This commit is contained in:
26 files changed
+76
-58
No files matched your search
@@ -95,6 +95,14 @@ supported and maintained by the Clusterio developers:
|
||||
Provide shared storage that can transport items between servers via
|
||||
teleport chests.
|
||||
|
||||
There's also plugins developed and maintained by the community:
|
||||
|
||||
- [Discord Bridge](https://github.com/Hornwitser/discord_bridge):
|
||||
Bridges chat between instances and Discord. By Hornwitser.
|
||||
- [Server Select](https://github.com/Hornwitser/server_select):
|
||||
In-game GUI for connecting to other server in the cluster. Originally
|
||||
by Godmave, ported to 2.0 by Hornwitser.
|
||||
|
||||
Want to make your own plugin? Check out the documentation on [Writing
|
||||
Plugins](/docs/writing-plugins.md) for where to start.
|
||||
|
||||
|
||||
@@ -130,10 +130,10 @@ Role to automatically grant to new users. If null no role is granted.
|
||||
Defaults to 1 which correspond to the default Player role.
|
||||
|
||||
|
||||
### <plugin_name>.enabled
|
||||
### <plugin_name>.load_plugin
|
||||
|
||||
Whether to enable the given plugin on the master server. Plugins
|
||||
disabled on the master server will not be loaded on instances.
|
||||
Whether to load the plugin on the master server. Plugins not loaded on
|
||||
the master server will not be loaded on instances.
|
||||
|
||||
Defaults to true.
|
||||
|
||||
@@ -425,11 +425,11 @@ maximum_segment_size), which is around 20 in normal circumstances.
|
||||
Defaults to 5
|
||||
|
||||
|
||||
### <plugin_name>.enabled
|
||||
### <plugin_name>.load_plugin
|
||||
|
||||
Whether to enable the given plugin on the instance. Note that plugins
|
||||
need to be enabled on the master server in order for them to be loaded
|
||||
on instances.
|
||||
Whether to load the given plugin on the instance. Note that plugins
|
||||
need to be loaded on the master server in order for them to be loaded on
|
||||
instances.
|
||||
|
||||
Defaults to true
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ The following properties are recognized:
|
||||
for [defining link messages](#defining-link-messages) below.
|
||||
|
||||
The optional module folder contains a Clusterio module that will be
|
||||
patched into the save when the plugin is enabled. See the section on
|
||||
patched into the save when the plugin is loaded. See the section on
|
||||
[Clusterio Modules](developing-for-clusterio.md) in the Developing for
|
||||
Clusterio document. The only restriction imposed on modules embedded
|
||||
into plugins is that they must be named the same as the plugin.
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
* @module lib/command
|
||||
*/
|
||||
"use strict";
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
const libErrors = require("@clusterio/lib/errors");
|
||||
const libLink = require("./link");
|
||||
const libErrors = require("./errors");
|
||||
|
||||
/**
|
||||
* Represents a command that can be runned by clusterioctl
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
const events = require("events");
|
||||
|
||||
const isDeepStrictEqual = require("../is_deep_strict_equal");
|
||||
const { basicType } = require("@clusterio/lib/helpers");
|
||||
const { basicType } = require("../helpers");
|
||||
|
||||
|
||||
/**
|
||||
@@ -813,8 +813,8 @@ class PluginConfigGroup extends ConfigGroup {
|
||||
if (!this._initialized) {
|
||||
super._initSubclass();
|
||||
this.define({
|
||||
name: "enabled",
|
||||
description: "Enable plugin",
|
||||
name: "load_plugin",
|
||||
title: "Load Plugin",
|
||||
type: "boolean",
|
||||
initial_value: true,
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"use strict";
|
||||
const fs = require("fs-extra");
|
||||
|
||||
const { basicType } = require("@clusterio/lib/helpers");
|
||||
const { basicType } = require("./helpers");
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ const ini = require("ini");
|
||||
const Jimp = require("jimp");
|
||||
const JSZip = require("jszip");
|
||||
|
||||
const libBuildMod = require("@clusterio/lib/build_mod");
|
||||
const libBuildMod = require("../build_mod");
|
||||
|
||||
/**
|
||||
* Generate the export mod needed for exportData
|
||||
|
||||
@@ -7,7 +7,7 @@ const JSZip = require("jszip");
|
||||
const path = require("path");
|
||||
const semver = require("semver");
|
||||
|
||||
const libHash = require("@clusterio/lib/hash");
|
||||
const libHash = require("../hash");
|
||||
|
||||
|
||||
const knownScenarios = {
|
||||
|
||||
@@ -9,9 +9,9 @@ const crypto = require("crypto");
|
||||
|
||||
const ini = require("ini");
|
||||
const rconClient = require("rcon-client");
|
||||
const libErrors = require("@clusterio/lib/errors");
|
||||
const { logger } = require("@clusterio/lib/logging");
|
||||
const { escapeRegExp } = require("@clusterio/lib/helpers");
|
||||
const libErrors = require("../errors");
|
||||
const { logger } = require("../logging");
|
||||
const { escapeRegExp } = require("../helpers");
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
const events = require("events");
|
||||
const WebSocket = require("isomorphic-ws");
|
||||
|
||||
const libSchema = require("@clusterio/lib/schema");
|
||||
const libErrors = require("@clusterio/lib/errors");
|
||||
const { logger } = require("@clusterio/lib/logging");
|
||||
const libSchema = require("../schema");
|
||||
const libErrors = require("../errors");
|
||||
const { logger } = require("../logging");
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// Implementation of Link class
|
||||
"use strict";
|
||||
|
||||
const libSchema = require("@clusterio/lib/schema");
|
||||
const libErrors = require("@clusterio/lib/errors");
|
||||
const { logger } = require("@clusterio/lib/logging");
|
||||
const libSchema = require("../schema");
|
||||
const libErrors = require("../errors");
|
||||
const { logger } = require("../logging");
|
||||
const messages = require("./messages");
|
||||
|
||||
// Some definitions for the terminology used here:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Message definitions for links
|
||||
"use strict";
|
||||
const libSchema = require("@clusterio/lib/schema");
|
||||
const libErrors = require("@clusterio/lib/errors");
|
||||
const { logger } = require("@clusterio/lib/logging");
|
||||
const libSchema = require("../schema");
|
||||
const libErrors = require("../errors");
|
||||
const { logger } = require("../logging");
|
||||
|
||||
class MissingLinkHandlerError extends Error {
|
||||
constructor(type, source, target) {
|
||||
|
||||
@@ -4,8 +4,8 @@ const Transport = require("winston-transport");
|
||||
const { LEVEL, MESSAGE } = require("triple-beam");
|
||||
const chalk = require("chalk");
|
||||
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
const libErrors = require("@clusterio/lib/errors");
|
||||
const libLink = require("./link");
|
||||
const libErrors = require("./errors");
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const libErrors = require("@clusterio/lib/errors");
|
||||
const libErrors = require("./errors");
|
||||
const path = require("path");
|
||||
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const libConfig = require("@clusterio/lib/config");
|
||||
const { logger } = require("@clusterio/lib/logging");
|
||||
const libHelpers = require("@clusterio/lib/helpers");
|
||||
const libConfig = require("./config");
|
||||
const { logger } = require("./logging");
|
||||
const libHelpers = require("./helpers");
|
||||
|
||||
|
||||
function print(...content) {
|
||||
|
||||
@@ -14,10 +14,6 @@
|
||||
* npx clusteriomaster run
|
||||
*/
|
||||
|
||||
// Attempt updating
|
||||
// const updater = require("./updater");
|
||||
// updater.update().then(console.log);
|
||||
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const fs = require("fs-extra");
|
||||
@@ -278,8 +274,8 @@ app.get("/api/plugins", (req, res) => {
|
||||
let plugins = [];
|
||||
for (let pluginInfo of pluginInfos) {
|
||||
let name = pluginInfo.name;
|
||||
let enabled = masterPlugins.has(name) && masterConfig.group(name).get("enabled");
|
||||
plugins.push({ name, version: pluginInfo.version, enabled });
|
||||
let loaded = masterPlugins.has(name);
|
||||
plugins.push({ name, version: pluginInfo.version, loaded });
|
||||
}
|
||||
res.send(plugins);
|
||||
});
|
||||
@@ -1697,9 +1693,8 @@ ${err.stack}`
|
||||
});
|
||||
|
||||
async function loadPlugins() {
|
||||
let plugins = new Map();
|
||||
for (let pluginInfo of pluginInfos) {
|
||||
if (!masterConfig.group(pluginInfo.name).get("enabled")) {
|
||||
if (!masterConfig.group(pluginInfo.name).get("load_plugin")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1716,7 +1711,7 @@ async function loadPlugins() {
|
||||
pluginInfo, { app, config: masterConfig, db, slaveConnections }, { endpointHitCounter }, logger
|
||||
);
|
||||
await masterPlugin.init();
|
||||
plugins.set(pluginInfo.name, masterPlugin);
|
||||
masterPlugins.set(pluginInfo.name, masterPlugin);
|
||||
|
||||
} catch (err) {
|
||||
throw new libErrors.PluginError(pluginInfo.name, err);
|
||||
@@ -1724,13 +1719,12 @@ async function loadPlugins() {
|
||||
|
||||
logger.info(`Loaded plugin ${pluginInfo.name} in ${Date.now() - pluginLoadStarted}ms`);
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
|
||||
// handle plugins on the master
|
||||
async function pluginManagement() {
|
||||
let startPluginLoad = Date.now();
|
||||
masterPlugins = await loadPlugins();
|
||||
await loadPlugins();
|
||||
logger.info(`All plugins loaded in ${Date.now() - startPluginLoad}ms`);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,14 @@ module.exports = (env = {}) => merge(common(env), {
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "master",
|
||||
shared: {
|
||||
"@clusterio/lib": { singleton: true },
|
||||
"@clusterio/lib/config": { singleton: true },
|
||||
"@clusterio/lib/errors": { singleton: true },
|
||||
"@clusterio/lib/helpers": { singleton: true },
|
||||
"@clusterio/lib/link": { singleton: true },
|
||||
"@clusterio/lib/logging": { singleton: true },
|
||||
"@clusterio/lib/plugin": { singleton: true },
|
||||
"@clusterio/lib/schema": { singleton: true },
|
||||
"@clusterio/lib/users": { singleton: true },
|
||||
"@clusterio/web_ui": { singleton: true },
|
||||
"ajv": {},
|
||||
"antd": { singleton: true },
|
||||
|
||||
@@ -274,7 +274,7 @@ class Instance extends libLink.Link {
|
||||
if (
|
||||
!pluginInfo.instanceEntrypoint
|
||||
|| !this._slave.serverPlugins.has(pluginInfo.name)
|
||||
|| !this.config.group(pluginInfo.name).get("enabled")
|
||||
|| !this.config.group(pluginInfo.name).get("load_plugin")
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,9 @@ async function loadPlugins() {
|
||||
|
||||
} catch (err) {
|
||||
logger.error(`Failed to load plugin info for ${meta.name}`);
|
||||
if (err) {
|
||||
logger.error(err.stack);
|
||||
}
|
||||
plugins.push({
|
||||
meta,
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ export default function PluginViewPage() {
|
||||
title={pluginTitle}
|
||||
>
|
||||
<Descriptions.Item label="Version">{plugin.meta.version}</Descriptions.Item>
|
||||
<Descriptions.Item label="Enabled">{plugin.meta.enabled ? "Yes" : "No"}</Descriptions.Item>
|
||||
<Descriptions.Item label="Loaded">{plugin.meta.loaded ? "Yes" : "No"}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
<Alert
|
||||
style={{
|
||||
@@ -56,7 +56,7 @@ export default function PluginViewPage() {
|
||||
title={pluginTitle}
|
||||
>
|
||||
<Descriptions.Item label="Version">{plugin.meta.version}</Descriptions.Item>
|
||||
<Descriptions.Item label="Enabled" span={2}>{plugin.meta.enabled ? "Yes" : "No"}</Descriptions.Item>
|
||||
<Descriptions.Item label="Loaded" span={2}>{plugin.meta.loaded ? "Yes" : "No"}</Descriptions.Item>
|
||||
<Descriptions.Item label="Description" span={3}>{plugin.info.description}</Descriptions.Item>
|
||||
{plugin.package.homepage ? <Descriptions.Item label="Homepage" span={3}>
|
||||
<a href={plugin.package.homepage}>{plugin.package.homepage}</a>
|
||||
|
||||
@@ -33,9 +33,9 @@ export default function PluginsPage() {
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Enabled",
|
||||
dataIndex: ["meta", "enabled"],
|
||||
render: enabled => (enabled ? "Yes" : null),
|
||||
title: "Loaded",
|
||||
dataIndex: ["meta", "loaded"],
|
||||
render: loaded => (loaded ? "Yes" : null),
|
||||
responsive: ["sm"],
|
||||
},
|
||||
]}
|
||||
|
||||
@@ -22,7 +22,8 @@ module.exports = (env = {}) => merge(common(env), {
|
||||
"./package.json": "./package.json",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/lib/config": { import: false },
|
||||
"@clusterio/lib/link": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
"ajv": { import: false },
|
||||
},
|
||||
|
||||
@@ -22,7 +22,8 @@ module.exports = (env = {}) => merge(common(env), {
|
||||
"./package.json": "./package.json",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/lib/config": { import: false },
|
||||
"@clusterio/lib/link": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
"ajv": { import: false },
|
||||
},
|
||||
|
||||
@@ -15,8 +15,10 @@ InstanceConfigGroup.finalize();
|
||||
|
||||
module.exports = {
|
||||
name: "statistics_exporter",
|
||||
title: "Prometheus Statistics Export",
|
||||
description: "Exports statistics to Prometheus",
|
||||
title: "Statistics Exporter",
|
||||
description:
|
||||
"Provides in-game item/fluid production, builds, kills, and pollution "+
|
||||
"statistics to the cluster's Prometheus endpoint.",
|
||||
instanceEntrypoint: "instance",
|
||||
InstanceConfigGroup,
|
||||
};
|
||||
@@ -22,7 +22,8 @@ module.exports = (env = {}) => merge(common(env), {
|
||||
"./package.json": "./package.json",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/lib/config": { import: false },
|
||||
"@clusterio/lib/link": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
"ajv": { import: false },
|
||||
},
|
||||
|
||||
@@ -22,7 +22,8 @@ module.exports = (env = {}) => merge(common(env), {
|
||||
"./package.json": "./package.json",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/lib/config": { import: false },
|
||||
"@clusterio/lib/link": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
"ajv": { import: false },
|
||||
"antd": { import: false },
|
||||
|
||||
Reference in new issue
Block a user