Reapply "."

This reverts commit 685260080e.
This commit is contained in:
2025-08-15 20:07:44 +09:00
parent 685260080e
commit 6057a62d50
14 changed files with 364 additions and 470 deletions

34
instance.js Normal file
View File

@@ -0,0 +1,34 @@
"use strict";
const lib = require("@clusterio/lib");
const {BaseInstancePlugin} = require("@clusterio/host");
const {InstanceActionEvent} = require("./info.js");
class InstancePlugin extends BaseInstancePlugin {
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]);
}
}
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]);
}
}
}
module.exports = {InstancePlugin};