mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-18 23:03:13 +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>
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import React, { useContext, useEffect, useState } from "react";
|
|
import { Button, Descriptions, Input, Space } from "antd";
|
|
|
|
import { ControlContext, PluginExtensionProps, SectionHeader, notifyErrorHandler, useAccount } from "@clusterio/web_ui";
|
|
|
|
import { JoinMessageSetRequest, PlayerGetRequest, PlayerRecord, joinMessageMaxLength } from "../../messages.js";
|
|
|
|
/** The settings the scenario keeps for a player, shown on their user page. */
|
|
export default function UserPlayerSettings(props: PluginExtensionProps<"UserViewPage">) {
|
|
const control = useContext(ControlContext);
|
|
const account = useAccount();
|
|
const name = props.user.name;
|
|
const own = account.name.toLowerCase() === name.toLowerCase();
|
|
const canGet = own || Boolean(account.hasPermission("core.user.get"));
|
|
const canEdit = Boolean(account.hasPermission(
|
|
own ? "exp_scenario.join_message.set" : "exp_scenario.join_message.set_other",
|
|
));
|
|
const [record, setRecord] = useState<PlayerRecord>();
|
|
/** The message being typed, undefined while not editing */
|
|
const [draft, setDraft] = useState<string>();
|
|
|
|
function load() {
|
|
control.send(new PlayerGetRequest(name))
|
|
.then(setRecord)
|
|
.catch(notifyErrorHandler("Error loading player settings"));
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (canGet) {
|
|
load();
|
|
}
|
|
}, [name, canGet]);
|
|
|
|
if (!canGet || !record) {
|
|
return null;
|
|
}
|
|
|
|
async function save(message: string) {
|
|
await control.send(new JoinMessageSetRequest(name, message.trim() || null));
|
|
setDraft(undefined);
|
|
load();
|
|
}
|
|
|
|
function onSave() {
|
|
save(draft ?? "").catch(notifyErrorHandler("Error saving join message"));
|
|
}
|
|
|
|
return <>
|
|
<SectionHeader title="Scenario" />
|
|
<Descriptions bordered size="small" column={1}>
|
|
<Descriptions.Item label="Join message">
|
|
{draft !== undefined
|
|
? <Space.Compact style={{ width: "100%", maxWidth: 600 }}>
|
|
<Input
|
|
value={draft}
|
|
maxLength={joinMessageMaxLength}
|
|
placeholder="Shown to everyone when they join, empty for none"
|
|
onChange={e => setDraft(e.target.value)}
|
|
onPressEnter={onSave}
|
|
/>
|
|
<Button type="primary" onClick={onSave}>Save</Button>
|
|
<Button onClick={() => setDraft(undefined)}>Cancel</Button>
|
|
</Space.Compact>
|
|
: <>
|
|
{record.joinMessage ?? <span style={{ color: "#888" }}>None</span>}
|
|
{canEdit && <Button
|
|
size="small"
|
|
style={{ marginLeft: 8 }}
|
|
onClick={() => setDraft(record.joinMessage ?? "")}
|
|
>Edit</Button>}
|
|
</>}
|
|
</Descriptions.Item>
|
|
</Descriptions>
|
|
</>;
|
|
}
|