From cba403df3664a6aa707fbca100670adbc60691af Mon Sep 17 00:00:00 2001 From: Prashan Dharmasena Date: Sat, 23 May 2020 00:13:51 -0700 Subject: [PATCH] Closes #450: Send update chat message to all clients on successful alias change. --- CHANGELOG.md | 1 + server/src/cmd.rs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b21edd215..14a77a8f86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added context-sensitive crosshair +- Announce alias changes to all clients. ### Changed diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 8f421902dc..4b84b1d979 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -339,24 +339,31 @@ fn handle_alias( action: &ChatCommand, ) { if let Ok(alias) = scan_fmt!(&args, &action.arg_fmt(), String) { - server + let old_alias_optional = server .state .ecs_mut() .write_storage::() .get_mut(target) - .map(|player| player.alias = alias); + .map(|player| std::mem::replace(&mut player.alias, alias)); // Update name on client player lists let ecs = server.state.ecs(); - if let (Some(uid), Some(player)) = ( + if let (Some(uid), Some(player), Some(old_alias)) = ( ecs.read_storage::().get(target), ecs.read_storage::().get(target), + old_alias_optional, ) { let msg = ServerMsg::PlayerListUpdate(PlayerListUpdate::Alias( (*uid).into(), player.alias.clone(), )); server.state.notify_registered_clients(msg); + server + .state + .notify_registered_clients(ServerMsg::broadcast(format!( + "{} is now known as {}.", + old_alias, player.alias + ))); } } else { server.notify_client(