This commit is contained in:
2025-06-15 13:42:56 +09:00
parent 740dffcbaf
commit e46b697a33
4 changed files with 65 additions and 26 deletions

View File

@@ -4,18 +4,30 @@ 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 (const [action, content] of this.messageQueue) {try {this.instance.sendTo('controller', new InstanceActionEvent(this.instance.name, action, content))} catch (err) {this.messageQueue.push([output.action, output.message])}}
for (const [action, content] of this.messageQueue) {
try {
this.instance.sendTo('controller', new InstanceActionEvent(this.instance.name, action, content));
} catch (err) {
this.messageQueue.push([output.action, output.message]);
}
}
this.messageQueue = [];
}
}
async onOutput(output) {
if (output.type !== 'action') return;
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])}
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]);
}
}
}