Add sendOrderedRcon for plugins

Add BaseInstancePlugin method for sending RCON commands in order to
simplify logic in plugins that depend on commands being delivered in
order.
This commit is contained in:
Hornwitser committed 2021-10-01 01:52:18 +02:00
1 parent e8b515c733
commit c40362fa7f
3 files changed
+113 -3

No files matched your search

+15 -1
View File
@@ -3,6 +3,7 @@ const events = require("events");
const http = require("http");
const express = require("express");
const libHelpers = require("@clusterio/lib/helpers");
const libLink = require("@clusterio/lib/link");
const libPlugin = require("@clusterio/lib/plugin");
const libUsers = require("@clusterio/lib/users");
@@ -105,7 +106,20 @@ class MockServer extends events.EventEmitter {
async sendRcon(command) {
this.rconCommands.push(command);
return this.rconCommandResults.get(command) || "";
let result = this.rconCommandResults.get(command);
if (!result) {
result = { response: "" };
}
if (result instanceof Error || typeof result === "string") {
result = { response: result };
}
if (result.time) {
await libHelpers.wait(result.time);
}
if (result.response instanceof Error) {
throw result.response;
}
return result.response || "";
}
}