Closes #450: Send update chat message to all clients on successful alias change.

This commit is contained in:
Prashan Dharmasena 2020-05-23 00:13:51 -07:00
parent 49d4141f0e
commit cba403df36
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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::<comp::Player>()
.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::<Uid>().get(target),
ecs.read_storage::<comp::Player>().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(