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:
Hornwitser committed 2020-04-03 20:51:28 +02:00
1 parent 3ff5e630ca
commit 9a4a535add
2 files changed
+26 -4

No files matched your search

+23 -1
View File
@@ -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;
}
/**
+3 -3
View File
@@ -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);