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