mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-21 15:33:12 +09:00
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:
1 parent
4d3c4de5b1
commit
6821d62c10
17 files changed
+491
-40
No files matched your search
@@ -18,6 +18,26 @@ export default async function (context: ControllerPluginContext) {
|
||||
messages.FeatureRecord.fromJSON.bind(messages.FeatureRecord),
|
||||
).bootstrap()
|
||||
);
|
||||
const playerStore = new lib.SubscribableDatastore(
|
||||
...await new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_scenario", "players.json"),
|
||||
messages.PlayerRecord.fromJSON.bind(messages.PlayerRecord),
|
||||
).bootstrap()
|
||||
);
|
||||
|
||||
type PlayerSettings = Pick<messages.PlayerRecord, "joinMessage">;
|
||||
|
||||
/** Change some settings of a player, empty values are removed and so is a record left empty */
|
||||
function updatePlayer(name: string, changes: PlayerSettings) {
|
||||
const old = playerStore.get(name);
|
||||
const settings: PlayerSettings = { joinMessage: old?.joinMessage, ...changes };
|
||||
const record = new messages.PlayerRecord(name, settings.joinMessage || undefined);
|
||||
if (record.joinMessage) {
|
||||
playerStore.set(record);
|
||||
} else if (old) {
|
||||
playerStore.delete(old);
|
||||
}
|
||||
}
|
||||
|
||||
/** Add new features, delete removed ones, and drop stored values which no longer fit a field */
|
||||
function reconcileFeatures() {
|
||||
@@ -202,8 +222,21 @@ export default async function (context: ControllerPluginContext) {
|
||||
return feature;
|
||||
});
|
||||
|
||||
controller.handle(messages.PlayerGetRequest, async (request: messages.PlayerGetRequest) => (
|
||||
playerStore.get(request.playerName) ?? new messages.PlayerRecord(request.playerName)
|
||||
));
|
||||
|
||||
controller.handle(messages.JoinMessageSetRequest, async (request: messages.JoinMessageSetRequest) => {
|
||||
updatePlayer(request.playerName, { joinMessage: request.message?.trim() });
|
||||
});
|
||||
|
||||
controller.hooks.save.attach(plugin.name, async () => {
|
||||
await playerStore.save();
|
||||
});
|
||||
|
||||
controller.hooks.shutdown.attach(plugin.name, async () => {
|
||||
await featureStore.save();
|
||||
await playerStore.save();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user