mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 15:04:52 +09:00
fix: filter server-specific chat tags (#970)
Co-authored-by: ColumbusLabs <287001685+ColumbusLabs@users.noreply.github.com>
This commit is contained in:
1 parent
c0138c3fe0
commit
aa59cd1992
3 files changed
+24
-3
No files matched your search
@@ -53,6 +53,7 @@ Many thanks to the following for contributing to this release:
|
||||
|
||||
### Changes
|
||||
|
||||
- Global chat now filters server-specific GPS, blueprint, train, and train-stop rich-text tags before relaying messages between instances. [#593](<https://github.com/clusterio/clusterio/issues/593>)
|
||||
- Reworked the site layout into a fixed sidebar with a top bar. [#924](<https://github.com/clusterio/clusterio/pull/924>)
|
||||
- The builtin "recycler" mod is now included correctly as builtin. [#925](<https://github.com/clusterio/clusterio/issues/925>)
|
||||
- Mod `info.json` versions (a mod's version and its `factorio_version`) are now parsed leniently, matching how the game reads them, instead of being validated against a fixed list of Factorio versions. [#941](<https://github.com/clusterio/clusterio/pull/941>)
|
||||
|
||||
@@ -3,13 +3,13 @@ import { BaseInstancePlugin } from "@clusterio/host";
|
||||
import { ChatEvent } from "./messages";
|
||||
|
||||
/**
|
||||
* Removes gps and train tags from messags
|
||||
* Removes server-specific tags from messages.
|
||||
*
|
||||
* @param content - string to strip tags from.
|
||||
* @returns stripped string.
|
||||
*/
|
||||
function removeTags(content: string): string {
|
||||
return content.replace(/(\[gps=-?\d+,-?\d+\]|\[train=\d+\])/g, "");
|
||||
return content.replace(/\[(?:gps|special-item|train|train-stop)=\S*?\]/gm, "");
|
||||
}
|
||||
|
||||
export class InstancePlugin extends BaseInstancePlugin {
|
||||
|
||||
@@ -15,11 +15,23 @@ describe("global_chat plugin", function() {
|
||||
assert.equal(instance._removeTags("string"), "string");
|
||||
});
|
||||
it("should strip out gps tag", function() {
|
||||
assert.equal(instance._removeTags("Look at [gps=12,-4]"), "Look at ");
|
||||
assert.equal(instance._removeTags("Look at [gps=12,-4,nauvis]"), "Look at ");
|
||||
});
|
||||
it("should strip out special item tag", function() {
|
||||
assert.equal(instance._removeTags("Blueprint [special-item=0eNqV...]"), "Blueprint ");
|
||||
});
|
||||
it("should strip out train tag", function() {
|
||||
assert.equal(instance._removeTags("Train [train=1235]"), "Train ");
|
||||
});
|
||||
it("should strip out train stop tag", function() {
|
||||
assert.equal(instance._removeTags("Stop [train-stop=42]"), "Stop ");
|
||||
});
|
||||
it("should preserve portable rich text tags", function() {
|
||||
assert.equal(
|
||||
instance._removeTags("[gps=12,-4][img=item.iron-plate] [item=iron-plate]"),
|
||||
"[img=item.iron-plate] [item=iron-plate]",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("class InstancePlugin", function() {
|
||||
@@ -39,6 +51,14 @@ describe("global_chat plugin", function() {
|
||||
["/sc game.print('[test] User: message')"],
|
||||
);
|
||||
});
|
||||
it("should filter server-specific tags from received chat", async function() {
|
||||
instancePlugin.instance.server.rconCommands = [];
|
||||
await instancePlugin.handleChatEvent(new ChatEvent("test", "Train [train=1235]"));
|
||||
assert.deepEqual(
|
||||
instancePlugin.instance.server.rconCommands,
|
||||
["/sc game.print('[test] Train ')"],
|
||||
);
|
||||
});
|
||||
});
|
||||
describe(".onOutput()", function() {
|
||||
it("should forward chat", async function() {
|
||||
|
||||
Reference in new issue
Block a user