mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 15:33:12 +09:00
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:
1 parent
e8b515c733
commit
c40362fa7f
3 files changed
+113
-3
No files matched your search
+15
-1
@@ -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 || "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user