From a9580a81bc65933b51ee0805a749310da9096041 Mon Sep 17 00:00:00 2001 From: Capucho Date: Tue, 10 Mar 2020 21:04:13 +0000 Subject: [PATCH] Rebased on master and moved logout message to events --- server/src/events/player.rs | 9 ++++++++- server/src/sys/message.rs | 21 ++------------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/server/src/events/player.rs b/server/src/events/player.rs index 3237ee57dd..10d1ee78bf 100644 --- a/server/src/events/player.rs +++ b/server/src/events/player.rs @@ -7,7 +7,7 @@ use common::{ sync::{Uid, UidAllocator}, }; use log::error; -use specs::{saveload::MarkerAllocator, Builder, Entity as EcsEntity, WorldExt}; +use specs::{saveload::MarkerAllocator, Builder, Entity as EcsEntity, Join, WorldExt}; pub fn handle_exit_ingame(server: &mut Server, entity: EcsEntity) { let state = server.state_mut(); @@ -53,12 +53,19 @@ pub fn handle_client_disconnect(server: &mut Server, entity: EcsEntity) -> Event } // Make sure to remove the player from the logged in list. (See AuthProvider) + // And send a disconnected message { let players = state.ecs().read_storage::(); let mut accounts = state.ecs().write_resource::(); + let mut clients = state.ecs().write_storage::(); if let Some(player) = players.get(entity) { accounts.logout(player.uuid()); + + let msg = ServerMsg::broadcast(format!("{} went offline.", &player.alias)); + for client in (&mut clients).join().filter(|c| c.is_registered()) { + client.notify(msg.clone()); + } } } // Delete client entity diff --git a/server/src/sys/message.rs b/server/src/sys/message.rs index 0274184af6..156e13b860 100644 --- a/server/src/sys/message.rs +++ b/server/src/sys/message.rs @@ -1,7 +1,7 @@ use super::SysTimer; use crate::{auth_provider::AuthProvider, client::Client, CLIENT_TIMEOUT}; use common::{ - comp::{Admin, Body, CanBuild, Controller, ForceUpdate, Ori, Player, Pos, Stats, Vel}, + comp::{Admin, CanBuild, Controller, ForceUpdate, Ori, Player, Pos, Stats, Vel}, event::{EventBus, ServerEvent}, msg::{ validate_chat_msg, ChatMsgValidationError, ClientMsg, ClientState, PlayerListUpdate, @@ -27,7 +27,6 @@ impl<'a> System<'a> for Sys { ReadExpect<'a, TerrainGrid>, Write<'a, SysTimer>, ReadStorage<'a, Uid>, - ReadStorage<'a, Body>, ReadStorage<'a, CanBuild>, ReadStorage<'a, Admin>, ReadStorage<'a, ForceUpdate>, @@ -51,7 +50,6 @@ impl<'a> System<'a> for Sys { terrain, mut timer, uids, - bodies, can_build, admins, force_updates, @@ -81,7 +79,6 @@ impl<'a> System<'a> for Sys { let mut new_players = Vec::new(); for (entity, client) in (&entities, &mut clients).join() { - let mut disconnect = false; let new_msgs = client.postbox.new_messages(); // Update client ping. @@ -285,27 +282,13 @@ impl<'a> System<'a> for Sys { ClientMsg::Ping => client.postbox.send_message(ServerMsg::Pong), ClientMsg::Pong => {}, ClientMsg::Disconnect => { - disconnect = true; + client.postbox.send_message(ServerMsg::Disconnect); }, ClientMsg::Terminate => { server_emitter.emit(ServerEvent::ClientDisconnect(entity)); }, } } - - if disconnect { - if let (Some(player), Some(_)) = ( - players.get(entity), - // It only shows a message if you had a body (not in char selection) - bodies.get(entity), - ) { - new_chat_msgs.push(( - None, - ServerMsg::broadcast(format!("{} went offline.", &player.alias)), - )); - } - client.postbox.send_message(ServerMsg::Disconnect); - } } // Handle new players.