This commit is contained in:
2025-06-15 01:22:31 +09:00
parent 214fb75f98
commit 43a35e81bd
3 changed files with 55 additions and 87 deletions

View File

@@ -1,33 +1,19 @@
"use strict";
const lib = require("@clusterio/lib");
const { BaseInstancePlugin } = require("@clusterio/host");
const { InstanceActionEvent } = require("./info.js");
const {BaseInstancePlugin} = require("@clusterio/host");
const {InstanceActionEvent} = require("./info.js");
class InstancePlugin extends BaseInstancePlugin {
async init() {
this.messageQueue = [];
}
async init() {this.messageQueue = [];}
onControllerConnectionEvent(event) {
if (event === "connect") {
for (let [action, content] of this.messageQueue) {
this.instance.sendTo("controller", new InstanceActionEvent(this.instance.name, action, content));
}
if (event === 'connect') {
for (let [action, content] of this.messageQueue) {this.instance.sendTo('controller', new InstanceActionEvent(this.instance.name, action, content));}
this.messageQueue = [];
}
}
async onOutput(output) {
if (output.type == "action") {
if (this.host.connector.connected) {
this.instance.sendTo("controller", new InstanceActionEvent(this.instance.name, output.action, output.message));
} else {
this.messageQueue.push([output.action, output.message]);
}
}
}
async onOutput(output) {if (output.type == 'action') {if (this.host.connector.connected) {this.instance.sendTo('controller', new InstanceActionEvent(this.instance.name, output.action, output.message));} else {this.messageQueue.push([output.action, output.message]);}}}
}
module.exports = {
InstancePlugin
};
module.exports = {InstancePlugin};