mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-11 23:54:52 +09:00
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>
51 lines
2.0 KiB
Lua
51 lines
2.0 KiB
Lua
--[[-- Control - Greetings
|
|
Greets players when they join, and lets players set a message shown to everyone when they join
|
|
|
|
The join messages are kept by the controller, the instance plugin prints them when a player joins
|
|
]]
|
|
|
|
local Commands = require("modules/exp_commands")
|
|
local Feature = require("modules/exp_scenario/features")
|
|
local clusterio_api = require("modules/clusterio/api")
|
|
local community_details = require("modules/exp_scenario/config/community_details").config
|
|
|
|
local feature = Feature.register("greetings")
|
|
|
|
--- @param event EventData.on_player_joined_game
|
|
local function on_player_joined_game(event)
|
|
local player = assert(game.get_player(event.player_index))
|
|
player.print{ "exp_greetings.greet", community_details.community_name, community_details.discord }
|
|
end
|
|
|
|
--- Set your custom join message, or show it when no message is given
|
|
Commands.new("set-join-message", { "exp_greetings.description-set" })
|
|
:optional("message", { "exp_greetings.arg-message" }, Commands.types.string_max_length(255))
|
|
:enable_auto_concatenation()
|
|
:add_aliases{ "join-message" }
|
|
:add_flags{ feature = feature }
|
|
:register(function(player, message)
|
|
--- @cast message string?
|
|
if message then
|
|
clusterio_api.send_json("exp_scenario:join_message_set", { player_name = player.name, message = message })
|
|
return Commands.status.success{ "exp_greetings.message-set" }
|
|
end
|
|
-- The instance plugin prints the message
|
|
clusterio_api.send_json("exp_scenario:join_message_get", { player_name = player.name })
|
|
end)
|
|
|
|
--- Removes your custom join message
|
|
Commands.new("remove-join-message", { "exp_greetings.description-remove" })
|
|
:add_flags{ feature = feature }
|
|
:register(function(player)
|
|
clusterio_api.send_json("exp_scenario:join_message_set", { player_name = player.name })
|
|
return Commands.status.success{ "exp_greetings.message-cleared" }
|
|
end)
|
|
|
|
local e = defines.events
|
|
|
|
return feature:guard{
|
|
events = {
|
|
[e.on_player_joined_game] = on_player_joined_game,
|
|
},
|
|
}
|