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
- Added context-sensitive crosshair - Added context-sensitive crosshair
- Announce alias changes to all clients.
### Changed ### Changed

View File

@ -339,24 +339,31 @@ fn handle_alias(
action: &ChatCommand, action: &ChatCommand,
) { ) {
if let Ok(alias) = scan_fmt!(&args, &action.arg_fmt(), String) { if let Ok(alias) = scan_fmt!(&args, &action.arg_fmt(), String) {
server let old_alias_optional = server
.state .state
.ecs_mut() .ecs_mut()
.write_storage::<comp::Player>() .write_storage::<comp::Player>()
.get_mut(target) .get_mut(target)
.map(|player| player.alias = alias); .map(|player| std::mem::replace(&mut player.alias, alias));
// Update name on client player lists // Update name on client player lists
let ecs = server.state.ecs(); 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::<Uid>().get(target),
ecs.read_storage::<comp::Player>().get(target), ecs.read_storage::<comp::Player>().get(target),
old_alias_optional,
) { ) {
let msg = ServerMsg::PlayerListUpdate(PlayerListUpdate::Alias( let msg = ServerMsg::PlayerListUpdate(PlayerListUpdate::Alias(
(*uid).into(), (*uid).into(),
player.alias.clone(), player.alias.clone(),
)); ));
server.state.notify_registered_clients(msg); server.state.notify_registered_clients(msg);
server
.state
.notify_registered_clients(ServerMsg::broadcast(format!(
"{} is now known as {}.",
old_alias, player.alias
)));
} }
} else { } else {
server.notify_client( server.notify_client(