Guests' command feedback reaches the console and the other operators
CommandSourceStack.broadcastToAdmins: on a dedicated server, a guest's command success (sendSuccess with broadcast) is logged on the console as "[Name: message]" when log_admin_commands is on, and sent gray and italic to every other operator when send_command_feedback is on. The queries and lists vanilla sends with broadcast false (commands/admin.rs) stay with the player who asked. Lines are queued while the guest acts and sent once the command returns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1139,6 +1139,10 @@ struct Game<'a> {
|
||||
lan_acting_uuid: Option<u128>,
|
||||
/// Command feedback to forward to a guest.
|
||||
chat_capture: Option<Vec<horizon_client::text::Text>>,
|
||||
/// `broadcastToAdmins` lines a guest's command queued, sent once it
|
||||
/// returns: the line, whether operators get it and whether the console
|
||||
/// logs it.
|
||||
admin_feedback: Vec<(horizon_client::text::Text, bool, bool)>,
|
||||
/// State of `/spectate`, `/posteffect`, `/debug`, `/waypoint` and friends.
|
||||
cmds: commands::extra::CommandExtras,
|
||||
ui: chat::UiState,
|
||||
@@ -10273,6 +10277,7 @@ impl<'a> Game<'a> {
|
||||
lan_acting_name: None,
|
||||
lan_acting_uuid: None,
|
||||
chat_capture: None,
|
||||
admin_feedback: Vec::new(),
|
||||
cmds: Default::default(),
|
||||
ui: Default::default(),
|
||||
combat: Default::default(),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Command execution (the `execute` side of each vanilla command class):
|
||||
//! entity selectors resolved against the game, vanilla feedback and errors.
|
||||
mod admin;
|
||||
pub(super) mod compute;
|
||||
mod data;
|
||||
mod effects;
|
||||
@@ -160,8 +161,38 @@ impl Game<'_> {
|
||||
return;
|
||||
}
|
||||
if self.ui.rules.bool("send_command_feedback") {
|
||||
self.system_message(message);
|
||||
self.system_message(message.clone());
|
||||
}
|
||||
self.broadcast_to_admins(message);
|
||||
}
|
||||
/// CommandSourceStack.broadcastToAdmins, for a guest's command on a
|
||||
/// dedicated server (`sendSuccess` with `broadcast`): `[name: message]`,
|
||||
/// gray and italic, for the other operators when `send_command_feedback`
|
||||
/// and the console when `log_admin_commands`. Queued while the guest acts;
|
||||
/// `send_admin_feedback` sends it.
|
||||
fn broadcast_to_admins(&mut self, message: Text) {
|
||||
if self.lan_acting.is_none()
|
||||
|| self.options.dedicated.is_none()
|
||||
|| message
|
||||
.translation_key()
|
||||
.is_some_and(|k| admin::QUIET.contains(&k))
|
||||
{
|
||||
return;
|
||||
}
|
||||
let ops = self.ui.rules.bool("send_command_feedback");
|
||||
let console = self.ui.rules.bool("log_admin_commands");
|
||||
if !ops && !console {
|
||||
return;
|
||||
}
|
||||
// getDisplayName: the entity the command runs as (`execute as`).
|
||||
let who = self
|
||||
.command_source
|
||||
.and_then(|s| s.entity)
|
||||
.unwrap_or(Target::Player);
|
||||
let line = Text::translate("chat.type.admin", &[self.target_name(who), message])
|
||||
.with_color(text::GRAY)
|
||||
.italic();
|
||||
self.admin_feedback.push((line, ops, console));
|
||||
}
|
||||
fn source_position(&self) -> [f64; 3] {
|
||||
if let Some(s) = &self.command_source {
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
//! Which command feedback vanilla tells the other operators and the console
|
||||
//! about (`CommandSourceStack.sendSuccess`'s `broadcast`).
|
||||
|
||||
/// The replies vanilla sends with `broadcast` false: queries and lists, which
|
||||
/// only the player who asked sees. Every other success message is broadcast.
|
||||
pub(super) const QUIET: &[&str] = &[
|
||||
"commands.attribute.base_value.get.success",
|
||||
"commands.attribute.base_value.reset.success",
|
||||
"commands.attribute.base_value.set.success",
|
||||
"commands.attribute.modifier.add.success",
|
||||
"commands.attribute.modifier.remove.success",
|
||||
"commands.attribute.modifier.value.get.success",
|
||||
"commands.attribute.value.get.success",
|
||||
"commands.banlist.entry",
|
||||
"commands.banlist.list",
|
||||
"commands.banlist.none",
|
||||
"commands.bossbar.list.bars.none",
|
||||
"commands.bossbar.list.bars.some",
|
||||
"commands.data.block.get",
|
||||
"commands.data.block.query",
|
||||
"commands.data.entity.get",
|
||||
"commands.data.entity.query",
|
||||
"commands.data.storage.get",
|
||||
"commands.data.storage.query",
|
||||
"commands.datapack.list.available.none",
|
||||
"commands.datapack.list.available.success",
|
||||
"commands.datapack.list.enabled.none",
|
||||
"commands.datapack.list.enabled.success",
|
||||
"commands.difficulty.query",
|
||||
"commands.execute.conditional.pass",
|
||||
"commands.execute.conditional.pass_count",
|
||||
"commands.experience.query.levels",
|
||||
"commands.experience.query.points",
|
||||
"commands.fetchprofile.copy_component",
|
||||
"commands.fetchprofile.copy_text",
|
||||
"commands.fetchprofile.give_item",
|
||||
"commands.fetchprofile.summon_mannequin",
|
||||
"commands.forceload.list.multiple",
|
||||
"commands.forceload.list.single",
|
||||
"commands.forceload.query.success",
|
||||
"commands.gamerule.query",
|
||||
"commands.jfr.started",
|
||||
"commands.jfr.stopped",
|
||||
"commands.list.players",
|
||||
"commands.locate.biome.success",
|
||||
"commands.locate.poi.success",
|
||||
"commands.locate.structure.success",
|
||||
"commands.perf.started",
|
||||
"commands.perf.stopped",
|
||||
"commands.posteffect.list.empty",
|
||||
"commands.posteffect.list.success",
|
||||
"commands.random.reset.all.success",
|
||||
"commands.random.reset.success",
|
||||
"commands.random.sample.success",
|
||||
"commands.save.saving",
|
||||
"commands.scoreboard.objectives.list.empty",
|
||||
"commands.scoreboard.objectives.list.success",
|
||||
"commands.scoreboard.players.get.success",
|
||||
"commands.scoreboard.players.list.empty",
|
||||
"commands.scoreboard.players.list.entity.empty",
|
||||
"commands.scoreboard.players.list.entity.entry",
|
||||
"commands.scoreboard.players.list.entity.success",
|
||||
"commands.scoreboard.players.list.success",
|
||||
"commands.seed.success",
|
||||
"commands.spectate.success.started",
|
||||
"commands.spectate.success.stopped",
|
||||
"commands.team.list.members.empty",
|
||||
"commands.team.list.members.success",
|
||||
"commands.team.list.teams.empty",
|
||||
"commands.team.list.teams.success",
|
||||
"commands.team.option.prefix.success",
|
||||
"commands.team.option.suffix.success",
|
||||
"commands.tick.query.percentiles",
|
||||
"commands.tick.query.rate.running",
|
||||
"commands.tick.query.rate.sprinting",
|
||||
"commands.tick.status.frozen",
|
||||
"commands.tick.status.lagging",
|
||||
"commands.tick.status.running",
|
||||
"commands.tick.status.sprinting",
|
||||
"commands.time.query.absolute",
|
||||
"commands.time.query.gametime",
|
||||
"commands.time.query.timeline",
|
||||
"commands.time.query.timeline.repetitions",
|
||||
"commands.waypoint.list.empty",
|
||||
"commands.waypoint.list.success",
|
||||
"commands.waypoint.modify.color",
|
||||
"commands.waypoint.modify.color.reset",
|
||||
"commands.waypoint.modify.style",
|
||||
"commands.whitelist.list",
|
||||
"commands.whitelist.none",
|
||||
"commands.worldborder.get",
|
||||
];
|
||||
@@ -650,6 +650,7 @@ impl Game<'_> {
|
||||
}),
|
||||
);
|
||||
}
|
||||
self.send_admin_feedback(host, conn);
|
||||
}
|
||||
}
|
||||
S::Unknown(8, payload) => {
|
||||
@@ -860,6 +861,32 @@ impl Game<'_> {
|
||||
}),
|
||||
);
|
||||
}
|
||||
self.send_admin_feedback(host, conn);
|
||||
}
|
||||
|
||||
/// The `broadcastToAdmins` lines a guest's command queued: every other
|
||||
/// operator gets them, and the console logs them as the server's own
|
||||
/// system messages (MinecraftServer.sendSystemMessage).
|
||||
fn send_admin_feedback(&mut self, host: &mut LanHost, source: u32) {
|
||||
for (line, ops, console) in std::mem::take(&mut self.admin_feedback) {
|
||||
if ops {
|
||||
let content = horizon_client::lan::data::component_nbt(&line.component());
|
||||
for g in host
|
||||
.hub
|
||||
.guests
|
||||
.iter()
|
||||
.filter(|g| g.conn != source && g.permission > 0)
|
||||
{
|
||||
g.send(&C::SystemChat(play::SystemChat {
|
||||
content: content.clone(),
|
||||
overlay: false,
|
||||
}));
|
||||
}
|
||||
}
|
||||
if console {
|
||||
super::dedicated::log("INFO", &format!("System chat: {}", line.plain()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// ServerGamePacketListenerImpl.handleCustomCommandSuggestions: the
|
||||
|
||||
@@ -233,6 +233,10 @@ impl Text {
|
||||
}
|
||||
/// The `Component` as vanilla's JSON (ComponentSerialization): the one
|
||||
/// built through the constructors, else the spans as literal siblings.
|
||||
/// The key of a `Component.translatable` built through [`Text::translate`].
|
||||
pub fn translation_key(&self) -> Option<&str> {
|
||||
self.source.as_deref()?.get("translate")?.as_str()
|
||||
}
|
||||
pub fn component(&self) -> Value {
|
||||
if let Some(c) = &self.source {
|
||||
return (**c).clone();
|
||||
|
||||
Reference in New Issue
Block a user