Keep join messages on the controller and print them from the instance

Join messages were stored in exp_legacy's PlayerData, which nothing
ever synced. The controller now keeps a players.json datastore of
per-player settings keyed by player name, starting with the join
message, and saves it on the save and shutdown hooks. Records with
nothing set are removed.

When a player joins, the instance plugin fetches their record and
prints the message to everyone over rcon in the player's colour, so no
lua is needed to show it. The in-game /set-join-message and
/remove-join-message commands send ipc which the instance forwards to
the controller; /set-join-message without a message asks the instance,
which prints the stored message back to the player.

Greetings is now a feature. Disabling it stops the greeting, the
commands, and the printed join messages. The private greeting with the
community name and Discord link is shown to every joining player, even
those with a join message, since one is a welcome for the player and
the other an announcement to everyone else.

Two controller permissions cover the web interface:
exp_scenario.join_message.set for your own message and .set_other for
anyone's, checked against the requesting user the same way
exp_discord_auth checks unlinking. The seed grants them to Supporter
and Moderator alongside the in-game commands. The user page gets a
Scenario section showing the message with an edit button for users who
may change it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-14 22:10:31 +00:00
1 parent 4d3c4de5b1
commit 6821d62c10
17 files changed
+491 -40

No files matched your search

+76 -2
View File
@@ -25,7 +25,9 @@ class TestConnector extends lib.BaseConnector {
}
/** Run the plugin on a real instance with spies on what leaves it, returns the event handler it registered. */
async function startPlugin(t2, features = [new messages.FeatureRecord("death_markers", false, { show_map_markers: false })]) {
async function startPlugin(
t2, features = [new messages.FeatureRecord("death_markers", false, { show_map_markers: false })], players = [],
) {
const instanceConfig = new lib.InstanceConfig("host");
instanceConfig.set("instance.id", 1);
instanceConfig.set("instance.name", "test");
@@ -35,8 +37,9 @@ async function startPlugin(t2, features = [new messages.FeatureRecord("death_mar
);
const state = { sent: [], rcons: [] };
const ipcHandlers = new Map();
instance.server = {
handle: () => {},
handle: (channel, handler) => ipcHandlers.set(channel, handler),
sendRcon: async command => {
state.rcons.push(command);
return "";
@@ -44,6 +47,10 @@ async function startPlugin(t2, features = [new messages.FeatureRecord("death_mar
};
instance.sendTo = async (dst, request) => {
state.sent.push(request);
if (request instanceof messages.PlayerGetRequest) {
const found = players.find(record => record.id === request.playerName);
return found ?? new messages.PlayerRecord(request.playerName);
}
return request instanceof messages.FeatureListRequest ? features : undefined;
};
@@ -58,6 +65,9 @@ async function startPlugin(t2, features = [new messages.FeatureRecord("death_mar
exit: () => hooks.exit.invoke(),
connectionEvent: event => hooks.controllerConnectionEvent.invoke(event),
featureUpdated: handlers.get(messages.FeatureUpdatedEvent),
ipc: (channel, event) => ipcHandlers.get(channel)(event),
playerEvent: event => hooks.playerEvent.invoke(event),
setStatus: status => { instance._status = status; },
};
}
@@ -67,6 +77,14 @@ function decodeRcon(command) {
return JSON.parse(match[2]);
}
/** The player data and code of a recorded rcon command made by luaWithPlayer. */
function decodePlayerRcon(command) {
const match = command.match(
/^\/sc local d = helpers\.json_to_table\[(=+)\[(.*)\]\1\] local p = game\.get_player\(d\.name\) if p then (.*) end$/s,
);
return { data: JSON.parse(match[2]), code: match[3] };
}
t.test("instance plugin", t2 => {
t2.test("start subscribes and sends every feature to lua", async t3 => {
const { start, state } = await startPlugin(t3);
@@ -134,3 +152,59 @@ t.test("instance plugin", t2 => {
t2.end();
});
t.test("join messages", t2 => {
const alice = new messages.PlayerRecord("Alice", "Alice has arrived ]=] ]==]");
t2.test("a joining player's message is printed to everyone", async t3 => {
const { start, playerEvent, setStatus, state } = await startPlugin(t3, [], [alice]);
await start();
setStatus("running");
state.rcons.length = 0;
await playerEvent({ type: "join", name: "Alice" });
t3.equal(state.rcons.length, 1);
const { data, code } = decodePlayerRcon(state.rcons[0]);
t3.strictSame(data, { message: alice.joinMessage, name: "Alice" }, "the message survives the long bracket");
t3.equal(code, "game.print(d.message, { color = p.color })");
await playerEvent({ type: "join", name: "Bob" });
await playerEvent({ type: "leave", name: "Alice" });
t3.equal(state.rcons.length, 1, "players without a message and leaves print nothing");
});
t2.test("nothing is printed while the instance is not running or greetings are disabled", async t3 => {
const { start, playerEvent, setStatus, featureUpdated, state } = await startPlugin(t3, [], [alice]);
await start();
state.rcons.length = 0;
await playerEvent({ type: "join", name: "Alice" });
t3.strictSame(state.rcons, [], "not running");
setStatus("running");
await featureUpdated(new messages.FeatureUpdatedEvent([new messages.FeatureRecord("greetings", false)]));
state.rcons.length = 0;
await playerEvent({ type: "join", name: "Alice" });
t3.strictSame(state.rcons, [], "greetings disabled");
});
t2.test("ipc from the set and remove commands is forwarded to the controller", async t3 => {
const { ipc, state } = await startPlugin(t3);
await ipc("exp_scenario:join_message_set", { player_name: "Alice", message: "Hi" });
await ipc("exp_scenario:join_message_set", { player_name: "Alice" });
const sent = state.sent.filter(request => request instanceof messages.JoinMessageSetRequest);
t3.strictSame(sent.map(request => [request.playerName, request.message]), [["Alice", "Hi"], ["Alice", null]]);
});
t2.test("ipc asking for the message prints it to the player", async t3 => {
const { ipc, setStatus, state } = await startPlugin(t3, [], [alice]);
setStatus("running");
await ipc("exp_scenario:join_message_get", { player_name: "Alice" });
await ipc("exp_scenario:join_message_get", { player_name: "Bob" });
const [found, missing] = state.rcons.map(decodePlayerRcon);
t3.equal(found.data.message, alice.joinMessage);
t3.equal(missing.data.message, undefined, "no message key, so the lua side prints message-none");
t3.match(found.code, "exp_greetings.message-none");
});
t2.end();
});