mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Expose Slave to instance plugins
Allow the slave object to be accessed by instance plugins through the this.slave property.
This commit is contained in:
1 parent
3ff5e630ca
commit
9a4a535add
2 files changed
+26
-4
No files matched your search
+23
-1
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Plugin interfaces and utilities.
|
||||
* @module
|
||||
*/
|
||||
"use strict";
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
@@ -9,9 +13,27 @@ const errors = require("lib/errors");
|
||||
* Base class for instance plugins
|
||||
*/
|
||||
class BaseInstancePlugin {
|
||||
constructor(info, instance) {
|
||||
constructor(info, instance, slave) {
|
||||
/**
|
||||
* The plugin's own info module
|
||||
*/
|
||||
this.info = info;
|
||||
|
||||
/**
|
||||
* Instance the plugin started for
|
||||
* @type {Instance}
|
||||
*/
|
||||
this.instance = instance;
|
||||
|
||||
/**
|
||||
* Slave running the instance
|
||||
*
|
||||
* With the exepction of accessing the slave's config you should
|
||||
* avoid ineracting with the slave object directly.
|
||||
*
|
||||
* @type {Slave}
|
||||
*/
|
||||
this.slave = slave;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,7 @@ class Instance extends link.Link{
|
||||
});
|
||||
}
|
||||
|
||||
async init(pluginInfos) {
|
||||
async init(pluginInfos, slave) {
|
||||
await this.server.init();
|
||||
|
||||
// load plugins
|
||||
@@ -62,7 +62,7 @@ class Instance extends link.Link{
|
||||
// require plugin class and initialize it
|
||||
let pluginLoadStarted = Date.now();
|
||||
let { InstancePlugin } = require(`./plugins/${pluginInfo.name}/${pluginInfo.instanceEntrypoint}`);
|
||||
let instancePlugin = new InstancePlugin(pluginInfo, this);
|
||||
let instancePlugin = new InstancePlugin(pluginInfo, this, slave);
|
||||
await instancePlugin.init();
|
||||
this.plugins.set(pluginInfo.name, instancePlugin);
|
||||
plugin.attachPluginMessages(this, pluginInfo, instancePlugin);
|
||||
@@ -543,7 +543,7 @@ class Slave extends link.Link {
|
||||
let instance = new Instance(
|
||||
connectionClient, instanceInfo.path, this.config.get("slave.factorio_directory"), instanceInfo.config
|
||||
);
|
||||
await instance.init(this.pluginInfos);
|
||||
await instance.init(this.pluginInfos, this);
|
||||
|
||||
// XXX: race condition on multiple simultanious calls
|
||||
this.instanceConnections.set(instanceId, instanceConnection);
|
||||
|
||||
Reference in new issue
Block a user