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

+82
View File
@@ -66,6 +66,9 @@ async function startPlugin(t2, { withPlugins = true, databaseDirectory = t2.test
updateFeature: request => handlers.get(messages.FeatureUpdateRequest)(request),
featureSubscription: request => handlers.get(messages.FeatureUpdatedEvent)(request),
shutdown: () => controller.hooks.shutdown.invoke(),
save: () => controller.hooks.save.invoke(),
/** Call the handler of a message as it would be called for a request or event */
send: message => handlers.get(message.constructor)(message),
};
}
@@ -226,3 +229,82 @@ t.test("controller plugin", t2 => {
t2.end();
});
/** Read players.json as the next run would. */
async function loadPlayers(databaseDirectory) {
return new lib.JsonIdDatastoreProvider(
path.join(databaseDirectory, "exp_scenario", "players.json"),
messages.PlayerRecord.fromJSON.bind(messages.PlayerRecord),
).load();
}
t.test("player settings", t2 => {
t2.test("PlayerGetRequest returns an empty record for unknown players", async t3 => {
const { send } = await startPlugin(t3, { withPlugins: false });
const record = await send(new messages.PlayerGetRequest("Alice"));
t3.equal(record.id, "Alice");
t3.strictSame(record.toJSON(), { id: "Alice" }, "nothing is set");
});
t2.test("JoinMessageSetRequest sets, trims, and clears the message", async t3 => {
const { send } = await startPlugin(t3, { withPlugins: false });
await send(new messages.JoinMessageSetRequest("Alice", " Hello there "));
t3.equal((await send(new messages.PlayerGetRequest("Alice"))).joinMessage, "Hello there");
await send(new messages.JoinMessageSetRequest("Alice", null));
t3.equal((await send(new messages.PlayerGetRequest("Alice"))).joinMessage, undefined, "null clears it");
await send(new messages.JoinMessageSetRequest("Alice", "Hi"));
await send(new messages.JoinMessageSetRequest("Alice", " "));
t3.equal((await send(new messages.PlayerGetRequest("Alice"))).joinMessage, undefined, "blank clears it");
});
t2.test("players are saved on the save hook and empty records are removed", async t3 => {
const databaseDirectory = t3.testdir();
const { send, save, shutdown } = await startPlugin(t3, { withPlugins: false, databaseDirectory });
await send(new messages.JoinMessageSetRequest("Alice", "Hi"));
await send(new messages.JoinMessageSetRequest("Bob", "Hey"));
await send(new messages.JoinMessageSetRequest("Bob", null));
await save();
const stored = await loadPlayers(databaseDirectory);
t3.strictSame([...stored.keys()], ["Alice"], "only players with a setting are stored");
t3.equal(stored.get("Alice").joinMessage, "Hi");
await send(new messages.JoinMessageSetRequest("Alice", "Bye"));
await shutdown();
const restarted = await startPlugin(t3, { withPlugins: false, databaseDirectory });
const record = await restarted.send(new messages.PlayerGetRequest("Alice"));
t3.equal(record.joinMessage, "Bye", "kept across restarts");
});
t2.test("permissions", async t3 => {
const user = (name, granted = []) => ({
name,
checkPermission(permission) {
if (!granted.includes(permission)) {
throw new lib.PermissionError("denied");
}
},
});
const request = name => ({ data: { player_name: name } });
const set = messages.JoinMessageSetRequest.permission;
t3.throws(() => set(user("Alice"), request("alice")), "own message needs the set permission");
t3.doesNotThrow(() => set(user("Alice", ["exp_scenario.join_message.set"]), request("alice")), "own message");
t3.throws(
() => set(user("Alice", ["exp_scenario.join_message.set"]), request("Bob")),
"someone else's message needs set_other",
);
t3.doesNotThrow(
() => set(user("Alice", ["exp_scenario.join_message.set_other"]), request("Bob")), "with set_other",
);
const get = messages.PlayerGetRequest.permission;
t3.doesNotThrow(() => get(user("Alice"), request("alice")), "own settings");
t3.throws(() => get(user("Alice"), request("Bob")), "someone else's");
t3.doesNotThrow(() => get(user("Alice", ["core.user.get"]), request("Bob")), "with core.user.get");
});
t2.end();
});