Players are removed from social menu when logged out.

This commit is contained in:
CapsizeGlimmer 2020-06-10 23:40:48 -04:00 committed by Forest Anderson
parent aabf9d7b21
commit 34acc4ddf3
4 changed files with 23 additions and 8 deletions

View File

@ -803,19 +803,30 @@ impl Client {
};
}
},
ServerMsg::PlayerListUpdate(PlayerListUpdate::Remove(_uid)) => {
// Don't remove players because we need to remember the
// names of disconnected players in chat.
ServerMsg::PlayerListUpdate(PlayerListUpdate::Remove(uid)) => {
// Instead of removing players, mark them as offline because we need to
// remember the names of disconnected players in chat.
//
// TODO the server should re-use uids of players that log out and log back
// in.
/*
if self.player_list.remove(&uid).is_none() {
if let Some(player_info) = self.player_list.get_mut(&uid) {
if player_info.is_online {
player_info.is_online = false;
} else {
warn!(
"Received msg to remove uid {} from the player list by they \
were already marked offline",
uid
);
}
} else {
warn!(
"Received msg to remove uid {} from the player list by they \
weren't in the list!",
uid
);
}
*/
},
ServerMsg::PlayerListUpdate(PlayerListUpdate::Alias(uid, new_name)) => {
if let Some(player_info) = self.player_list.get_mut(&uid) {

View File

@ -33,6 +33,7 @@ pub enum PlayerListUpdate {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlayerInfo {
pub is_admin: bool,
pub is_online: bool,
pub player_alias: String,
pub character: Option<CharacterInfo>,
}

View File

@ -93,6 +93,7 @@ impl<'a> System<'a> for Sys {
.join()
.map(|(uid, player, stats, admin)| {
((*uid).into(), PlayerInfo {
is_online: true,
is_admin: admin.is_some(),
player_alias: player.alias.clone(),
character: stats.map(|stats| CharacterInfo {
@ -455,6 +456,7 @@ impl<'a> System<'a> for Sys {
let msg =
ServerMsg::PlayerListUpdate(PlayerListUpdate::Add((*uid).into(), PlayerInfo {
player_alias: player.alias.clone(),
is_online: true,
is_admin: admins.get(entity).is_some(),
character: None, // new players will be on character select.
}));

View File

@ -175,7 +175,8 @@ impl<'a> Widget for Social<'a> {
// Players list
// TODO: this list changes infrequently enough that it should not have to be
// recreated every frame
let count = self.client.player_list.len();
let players = self.client.player_list.values().filter(|p| p.is_online);
let count = players.clone().count();
if ids.player_names.len() < count {
ids.update(|ids| {
ids.player_names
@ -193,7 +194,7 @@ impl<'a> Widget for Social<'a> {
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
.set(ids.online_title, ui);
for (i, (_, player_info)) in self.client.player_list.iter().enumerate() {
for (i, player_info) in players.enumerate() {
Text::new(&format!(
"[{}] {}",
player_info.player_alias,