fix naming, replace NotInGame with CharacterScreen

This commit is contained in:
Marcel Märtens 2020-10-06 13:15:20 +02:00
parent 8b40f81ee2
commit e8452fafc6
9 changed files with 86 additions and 80 deletions

View File

@ -25,11 +25,11 @@ use common::{
},
event::{EventBus, LocalEvent},
msg::{
validate_chat_msg, ChatMsgValidationError, ClientGeneralMsg, ClientInGameMsg, ClientIngame,
ClientNotInGameMsg, ClientRegisterMsg, ClientType, DisconnectReason, InviteAnswer,
Notification, PingMsg, PlayerInfo, PlayerListUpdate, RegisterError, ServerGeneralMsg,
ServerInGameMsg, ServerInfo, ServerInitMsg, ServerNotInGameMsg, ServerRegisterAnswerMsg,
MAX_BYTES_CHAT_MSG,
validate_chat_msg, ChatMsgValidationError, ClientCharacterScreenMsg, ClientGeneralMsg,
ClientInGameMsg, ClientIngame, ClientRegisterMsg, ClientType, DisconnectReason,
InviteAnswer, Notification, PingMsg, PlayerInfo, PlayerListUpdate, RegisterError,
ServerCharacterScreenMsg, ServerGeneralMsg, ServerInGameMsg, ServerInfo, ServerInitMsg,
ServerRegisterAnswerMsg, MAX_BYTES_CHAT_MSG,
},
outcome::Outcome,
recipe::RecipeBook,
@ -113,11 +113,11 @@ pub struct Client {
_network: Network,
participant: Option<Participant>,
singleton_stream: Stream,
general_stream: Stream,
ping_stream: Stream,
register_stream: Stream,
character_screen_stream: Stream,
in_game_stream: Stream,
not_in_game_stream: Stream,
client_timeout: Duration,
last_server_ping: f64,
@ -161,8 +161,8 @@ impl Client {
let stream = block_on(participant.opened())?;
let mut ping_stream = block_on(participant.opened())?;
let mut register_stream = block_on(participant.opened())?;
let character_screen_stream = block_on(participant.opened())?;
let in_game_stream = block_on(participant.opened())?;
let not_in_game_stream = block_on(participant.opened())?;
register_stream.send(ClientType::Game)?;
let server_info: ServerInfo = block_on(register_stream.recv())?;
@ -397,10 +397,10 @@ impl Client {
_network: network,
participant: Some(participant),
singleton_stream: stream,
general_stream: stream,
ping_stream,
register_stream,
not_in_game_stream,
character_screen_stream,
in_game_stream,
client_timeout,
@ -462,8 +462,8 @@ impl Client {
/// Request a state transition to `ClientState::Character`.
pub fn request_character(&mut self, character_id: CharacterId) {
self.not_in_game_stream
.send(ClientNotInGameMsg::Character(character_id))
self.character_screen_stream
.send(ClientCharacterScreenMsg::Character(character_id))
.unwrap();
//Assume we are in_game unless server tells us otherwise
@ -475,31 +475,31 @@ impl Client {
/// Load the current players character list
pub fn load_character_list(&mut self) {
self.character_list.loading = true;
self.not_in_game_stream
.send(ClientNotInGameMsg::RequestCharacterList)
self.character_screen_stream
.send(ClientCharacterScreenMsg::RequestCharacterList)
.unwrap();
}
/// New character creation
pub fn create_character(&mut self, alias: String, tool: Option<String>, body: comp::Body) {
self.character_list.loading = true;
self.not_in_game_stream
.send(ClientNotInGameMsg::CreateCharacter { alias, tool, body })
self.character_screen_stream
.send(ClientCharacterScreenMsg::CreateCharacter { alias, tool, body })
.unwrap();
}
/// Character deletion
pub fn delete_character(&mut self, character_id: CharacterId) {
self.character_list.loading = true;
self.not_in_game_stream
.send(ClientNotInGameMsg::DeleteCharacter(character_id))
self.character_screen_stream
.send(ClientCharacterScreenMsg::DeleteCharacter(character_id))
.unwrap();
}
/// Send disconnect message to the server
pub fn request_logout(&mut self) {
debug!("Requesting logout from server");
if let Err(e) = self.singleton_stream.send(ClientGeneralMsg::Disconnect) {
if let Err(e) = self.general_stream.send(ClientGeneralMsg::Disconnect) {
error!(
?e,
"Couldn't send disconnect package to server, did server close already?"
@ -840,7 +840,7 @@ impl Client {
pub fn send_chat(&mut self, message: String) {
match validate_chat_msg(&message) {
Ok(()) => self
.singleton_stream
.general_stream
.send(ClientGeneralMsg::ChatMsg(message))
.unwrap(),
Err(ChatMsgValidationError::TooLong) => tracing::warn!(
@ -1116,12 +1116,12 @@ impl Client {
DisconnectReason::Requested => {
debug!("finally sending ClientMsg::Terminate");
frontend_events.push(Event::Disconnect);
self.singleton_stream.send(ClientGeneralMsg::Terminate)?;
self.general_stream.send(ClientGeneralMsg::Terminate)?;
},
DisconnectReason::Kicked(reason) => {
debug!("sending ClientMsg::Terminate because we got kicked");
frontend_events.push(Event::Kicked(reason));
self.singleton_stream.send(ClientGeneralMsg::Terminate)?;
self.general_stream.send(ClientGeneralMsg::Terminate)?;
},
},
ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::Init(list)) => {
@ -1407,23 +1407,26 @@ impl Client {
Ok(())
}
fn handle_server_not_in_game_msg(&mut self, msg: ServerNotInGameMsg) -> Result<(), Error> {
fn handle_server_character_screen_msg(
&mut self,
msg: ServerCharacterScreenMsg,
) -> Result<(), Error> {
match msg {
ServerNotInGameMsg::CharacterListUpdate(character_list) => {
ServerCharacterScreenMsg::CharacterListUpdate(character_list) => {
self.character_list.characters = character_list;
self.character_list.loading = false;
},
ServerNotInGameMsg::CharacterActionError(error) => {
ServerCharacterScreenMsg::CharacterActionError(error) => {
warn!("CharacterActionError: {:?}.", error);
self.character_list.error = Some(error);
},
ServerNotInGameMsg::CharacterDataLoadError(error) => {
ServerCharacterScreenMsg::CharacterDataLoadError(error) => {
trace!("Handling join error by server");
self.client_ingame = None;
self.clean_state();
self.character_list.error = Some(error);
},
ServerNotInGameMsg::CharacterSuccess => {
ServerCharacterScreenMsg::CharacterSuccess => {
debug!("client is now in ingame state on server");
if let Some(vd) = self.view_distance {
self.set_view_distance(vd);
@ -1461,9 +1464,9 @@ impl Client {
) -> Result<(), Error> {
loop {
let (m1, m2, m3, m4) = select!(
msg = self.singleton_stream.recv().fuse() => (Some(msg), None, None, None),
msg = self.general_stream.recv().fuse() => (Some(msg), None, None, None),
msg = self.ping_stream.recv().fuse() => (None, Some(msg), None, None),
msg = self.not_in_game_stream.recv().fuse() => (None, None, Some(msg), None),
msg = self.character_screen_stream.recv().fuse() => (None, None, Some(msg), None),
msg = self.in_game_stream.recv().fuse() => (None, None, None, Some(msg)),
);
*cnt += 1;
@ -1474,7 +1477,7 @@ impl Client {
self.handle_ping_msg(msg?)?;
}
if let Some(msg) = m3 {
self.handle_server_not_in_game_msg(msg?)?;
self.handle_server_character_screen_msg(msg?)?;
}
if let Some(msg) = m4 {
self.handle_server_in_game_msg(frontend_events, msg?)?;
@ -1807,7 +1810,7 @@ impl Client {
impl Drop for Client {
fn drop(&mut self) {
trace!("Dropping client");
if let Err(e) = self.singleton_stream.send(ClientGeneralMsg::Disconnect) {
if let Err(e) = self.general_stream.send(ClientGeneralMsg::Disconnect) {
warn!(
?e,
"Error during drop of client, couldn't send disconnect package, is the connection \

View File

@ -23,9 +23,9 @@ pub struct ClientRegisterMsg {
pub token_or_username: String,
}
//messages send by clients only valid when NOT ingame
//messages send by clients only valid when in character screen
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ClientNotInGameMsg {
pub enum ClientCharacterScreenMsg {
RequestCharacterList,
CreateCharacter {
alias: String,
@ -37,7 +37,7 @@ pub enum ClientNotInGameMsg {
Spectate,
}
//messages send by clients only valid when ingame
//messages send by clients only valid when in game (with a character)
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ClientInGameMsg {
ControllerInputs(comp::ControllerInputs),

View File

@ -5,13 +5,13 @@ pub mod server;
// Reexports
pub use self::{
client::{
ClientGeneralMsg, ClientInGameMsg, ClientNotInGameMsg, ClientRegisterMsg, ClientType,
ClientCharacterScreenMsg, ClientGeneralMsg, ClientInGameMsg, ClientRegisterMsg, ClientType,
},
ecs_packet::EcsCompPacket,
server::{
CharacterInfo, DisconnectReason, InviteAnswer, Notification, PlayerInfo, PlayerListUpdate,
RegisterError, ServerGeneralMsg, ServerInGameMsg, ServerInfo, ServerInitMsg,
ServerNotInGameMsg, ServerRegisterAnswerMsg,
RegisterError, ServerCharacterScreenMsg, ServerGeneralMsg, ServerInGameMsg, ServerInfo,
ServerInitMsg, ServerRegisterAnswerMsg,
},
};
use serde::{Deserialize, Serialize};

View File

@ -209,9 +209,9 @@ pub enum ServerInitMsg {
pub type ServerRegisterAnswerMsg = Result<(), RegisterError>;
//Messages only allowed while client ingame
//Messages only allowed while client in character screen
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ServerNotInGameMsg {
pub enum ServerCharacterScreenMsg {
/// An error occurred while loading character data
CharacterDataLoadError(String),
/// A list of characters belonging to the a authenticated player was sent
@ -221,7 +221,7 @@ pub enum ServerNotInGameMsg {
CharacterSuccess,
}
//Messages only allowed while client ingame
//Messages only allowed while client is in game (with a character)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ServerInGameMsg {
GroupUpdate(comp::group::ChangeNotification<sync::Uid>),

View File

@ -1,7 +1,7 @@
use crate::error::Error;
use common::msg::{
ClientGeneralMsg, ClientInGameMsg, ClientIngame, ClientNotInGameMsg, ClientType, PingMsg,
ServerGeneralMsg, ServerInGameMsg, ServerInitMsg, ServerNotInGameMsg,
ClientCharacterScreenMsg, ClientGeneralMsg, ClientInGameMsg, ClientIngame, ClientType, PingMsg,
ServerCharacterScreenMsg, ServerGeneralMsg, ServerInGameMsg, ServerInitMsg,
};
use hashbrown::HashSet;
use network::{MessageBuffer, Participant, Stream};
@ -23,8 +23,8 @@ pub struct Client {
pub singleton_stream: Stream,
pub ping_stream: Stream,
pub register_stream: Stream,
pub character_screen_stream: Stream,
pub in_game_stream: Stream,
pub not_in_game_stream: Stream,
pub network_error: AtomicBool,
pub last_ping: f64,
pub login_msg_sent: bool,
@ -65,8 +65,8 @@ impl Client {
Self::internal_send(&self.network_error, &mut self.in_game_stream, msg);
}
pub fn send_not_in_game(&mut self, msg: ServerNotInGameMsg) {
Self::internal_send(&self.network_error, &mut self.not_in_game_stream, msg);
pub fn send_character_screen(&mut self, msg: ServerCharacterScreenMsg) {
Self::internal_send(&self.network_error, &mut self.character_screen_stream, msg);
}
pub fn send_ping(&mut self, msg: PingMsg) {
@ -103,8 +103,8 @@ impl Client {
Self::internal_recv(&self.network_error, &mut self.in_game_stream).await
}
pub async fn recv_not_in_game_msg(&mut self) -> Result<ClientNotInGameMsg, Error> {
Self::internal_recv(&self.network_error, &mut self.not_in_game_stream).await
pub async fn recv_character_screen_msg(&mut self) -> Result<ClientCharacterScreenMsg, Error> {
Self::internal_recv(&self.network_error, &mut self.character_screen_stream).await
}
pub async fn recv_ping_msg(&mut self) -> Result<PingMsg, Error> {

View File

@ -110,8 +110,8 @@ impl ConnectionHandler {
let general_stream = participant.open(10, reliablec).await?;
let ping_stream = participant.open(5, reliable).await?;
let mut register_stream = participant.open(10, reliablec).await?;
let character_screen_stream = participant.open(10, reliablec).await?;
let in_game_stream = participant.open(10, reliablec).await?;
let not_in_game_stream = participant.open(10, reliablec).await?;
let server_data = receiver.recv()?;
@ -138,7 +138,7 @@ impl ConnectionHandler {
ping_stream,
register_stream,
in_game_stream,
not_in_game_stream,
character_screen_stream,
network_error: std::sync::atomic::AtomicBool::new(false),
last_ping: server_data.time,
login_msg_sent: false,

View File

@ -47,8 +47,8 @@ use common::{
comp::{self, ChatType},
event::{EventBus, ServerEvent},
msg::{
server::WorldMapMsg, ClientType, DisconnectReason, ServerGeneralMsg, ServerInGameMsg,
ServerInfo, ServerInitMsg, ServerNotInGameMsg,
server::WorldMapMsg, ClientType, DisconnectReason, ServerCharacterScreenMsg,
ServerGeneralMsg, ServerInGameMsg, ServerInfo, ServerInitMsg,
},
outcome::Outcome,
recipe::default_recipe_book,
@ -525,13 +525,13 @@ impl Server {
.messages()
.for_each(|query_result| match query_result.result {
CharacterLoaderResponseType::CharacterList(result) => match result {
Ok(character_list_data) => self.notify_not_in_game_client(
Ok(character_list_data) => self.notify_character_screen_client(
query_result.entity,
ServerNotInGameMsg::CharacterListUpdate(character_list_data),
ServerCharacterScreenMsg::CharacterListUpdate(character_list_data),
),
Err(error) => self.notify_not_in_game_client(
Err(error) => self.notify_character_screen_client(
query_result.entity,
ServerNotInGameMsg::CharacterActionError(error.to_string()),
ServerCharacterScreenMsg::CharacterActionError(error.to_string()),
),
},
CharacterLoaderResponseType::CharacterData(result) => {
@ -544,9 +544,9 @@ impl Server {
// We failed to load data for the character from the DB. Notify the
// client to push the state back to character selection, with the error
// to display
self.notify_not_in_game_client(
self.notify_character_screen_client(
query_result.entity,
ServerNotInGameMsg::CharacterDataLoadError(error.to_string()),
ServerCharacterScreenMsg::CharacterDataLoadError(error.to_string()),
);
// Clean up the entity data on the server
@ -874,12 +874,12 @@ impl Server {
}
}
pub fn notify_not_in_game_client<S>(&self, entity: EcsEntity, msg: S)
pub fn notify_character_screen_client<S>(&self, entity: EcsEntity, msg: S)
where
S: Into<ServerNotInGameMsg>,
S: Into<ServerCharacterScreenMsg>,
{
if let Some(client) = self.state.ecs().write_storage::<Client>().get_mut(entity) {
client.send_not_in_game(msg.into())
client.send_character_screen(msg.into())
}
}

View File

@ -6,8 +6,8 @@ use common::{
comp,
effect::Effect,
msg::{
CharacterInfo, ClientIngame, PlayerListUpdate, ServerGeneralMsg, ServerInGameMsg,
ServerNotInGameMsg,
CharacterInfo, ClientIngame, PlayerListUpdate, ServerCharacterScreenMsg, ServerGeneralMsg,
ServerInGameMsg,
},
state::State,
sync::{Uid, UidAllocator, WorldSyncExt},
@ -220,7 +220,7 @@ impl StateExt for State {
// Tell the client its request was successful.
if let Some(client) = self.ecs().write_storage::<Client>().get_mut(entity) {
client.in_game = Some(ClientIngame::Character);
client.send_not_in_game(ServerNotInGameMsg::CharacterSuccess)
client.send_character_screen(ServerCharacterScreenMsg::CharacterSuccess)
}
}

View File

@ -15,10 +15,10 @@ use common::{
},
event::{EventBus, ServerEvent},
msg::{
validate_chat_msg, CharacterInfo, ChatMsgValidationError, ClientGeneralMsg,
ClientInGameMsg, ClientIngame, ClientNotInGameMsg, ClientRegisterMsg, DisconnectReason,
PingMsg, PlayerInfo, PlayerListUpdate, RegisterError, ServerGeneralMsg, ServerInGameMsg,
ServerNotInGameMsg, ServerRegisterAnswerMsg, MAX_BYTES_CHAT_MSG,
validate_chat_msg, CharacterInfo, ChatMsgValidationError, ClientCharacterScreenMsg,
ClientGeneralMsg, ClientInGameMsg, ClientIngame, ClientRegisterMsg, DisconnectReason,
PingMsg, PlayerInfo, PlayerListUpdate, RegisterError, ServerCharacterScreenMsg,
ServerGeneralMsg, ServerInGameMsg, ServerRegisterAnswerMsg, MAX_BYTES_CHAT_MSG,
},
span,
state::{BlockChange, Time},
@ -237,7 +237,7 @@ impl Sys {
}
#[allow(clippy::too_many_arguments)]
fn handle_client_not_in_game_msg(
fn handle_client_character_screen_msg(
server_emitter: &mut common::event::Emitter<'_, ServerEvent>,
new_chat_msgs: &mut Vec<(Option<specs::Entity>, UnresolvedChatMsg)>,
entity: specs::Entity,
@ -247,18 +247,18 @@ impl Sys {
players: &mut WriteStorage<'_, Player>,
editable_settings: &ReadExpect<'_, EditableSettings>,
alias_validator: &ReadExpect<'_, AliasValidator>,
msg: ClientNotInGameMsg,
msg: ClientCharacterScreenMsg,
) -> Result<(), crate::error::Error> {
match msg {
// Request spectator state
ClientNotInGameMsg::Spectate => {
ClientCharacterScreenMsg::Spectate => {
if client.registered {
client.in_game = Some(ClientIngame::Spectator)
} else {
debug!("dropped Spectate msg from unregistered client");
}
},
ClientNotInGameMsg::Character(character_id) => {
ClientCharacterScreenMsg::Character(character_id) => {
if client.registered && client.in_game.is_none() {
// Only send login message if it wasn't already
// sent previously
@ -301,9 +301,11 @@ impl Sys {
}
}
} else {
client.send_not_in_game(ServerNotInGameMsg::CharacterDataLoadError(
String::from("Failed to fetch player entity"),
))
client.send_character_screen(
ServerCharacterScreenMsg::CharacterDataLoadError(String::from(
"Failed to fetch player entity",
)),
)
}
} else {
let registered = client.registered;
@ -311,15 +313,15 @@ impl Sys {
debug!(?registered, ?in_game, "dropped Character msg from client");
}
},
ClientNotInGameMsg::RequestCharacterList => {
ClientCharacterScreenMsg::RequestCharacterList => {
if let Some(player) = players.get(entity) {
character_loader.load_character_list(entity, player.uuid().to_string())
}
},
ClientNotInGameMsg::CreateCharacter { alias, tool, body } => {
ClientCharacterScreenMsg::CreateCharacter { alias, tool, body } => {
if let Err(error) = alias_validator.validate(&alias) {
debug!(?error, ?alias, "denied alias as it contained a banned word");
client.send_not_in_game(ServerNotInGameMsg::CharacterActionError(
client.send_character_screen(ServerCharacterScreenMsg::CharacterActionError(
error.to_string(),
));
} else if let Some(player) = players.get(entity) {
@ -333,7 +335,7 @@ impl Sys {
);
}
},
ClientNotInGameMsg::DeleteCharacter(character_id) => {
ClientCharacterScreenMsg::DeleteCharacter(character_id) => {
if let Some(player) = players.get(entity) {
character_loader.delete_character(
entity,
@ -458,7 +460,8 @@ impl Sys {
loop {
let q1 = Client::internal_recv(&client.network_error, &mut client.singleton_stream);
let q2 = Client::internal_recv(&client.network_error, &mut client.in_game_stream);
let q3 = Client::internal_recv(&client.network_error, &mut client.not_in_game_stream);
let q3 =
Client::internal_recv(&client.network_error, &mut client.character_screen_stream);
let q4 = Client::internal_recv(&client.network_error, &mut client.ping_stream);
let q5 = Client::internal_recv(&client.network_error, &mut client.register_stream);
@ -503,7 +506,7 @@ impl Sys {
)?;
}
if let Some(msg) = m3 {
Self::handle_client_not_in_game_msg(
Self::handle_client_character_screen_msg(
server_emitter,
new_chat_msgs,
entity,