Cleanup ClientStates

Former-commit-id: 060cf9800dc6f09c58f41a4baaccb1a43bd97621
This commit is contained in:
timokoesters 2019-04-21 20:46:07 +02:00
parent e9027c6433
commit 37367491da

View File

@ -264,16 +264,16 @@ impl Server {
ClientMsg::RequestState(requested_state) => match requested_state { ClientMsg::RequestState(requested_state) => match requested_state {
ClientState::Connected => disconnect = true, // Default state ClientState::Connected => disconnect = true, // Default state
ClientState::Registered => match client.client_state { ClientState::Registered => match client.client_state {
ClientState::Connected => {}, // Use ClientMsg::Connect instead ClientState::Connected => disconnect = true, // Use ClientMsg::Register instead
ClientState::Registered => client.error_state(RequestStateError::Already), ClientState::Registered => client.error_state(RequestStateError::Already),
ClientState::Spectator => client.allow_state(ClientState::Registered), ClientState::Spectator | ClientState::Character
ClientState::Character => client.allow_state(ClientState::Registered), => client.allow_state(ClientState::Registered),
}, },
ClientState::Spectator => match requested_state { ClientState::Spectator => match requested_state {
ClientState::Connected => disconnect = true, // Become Connected first ClientState::Connected => disconnect = true, // Become Registered first
ClientState::Registered => client.allow_state(ClientState::Spectator),
ClientState::Spectator => client.error_state(RequestStateError::Already), ClientState::Spectator => client.error_state(RequestStateError::Already),
ClientState::Character => client.allow_state(ClientState::Spectator), ClientState::Registered | ClientState::Character
=> client.allow_state(ClientState::Spectator),
}, },
ClientState::Character => disconnect = true, // Use ClientMsg::Character instead ClientState::Character => disconnect = true, // Use ClientMsg::Character instead
}, },
@ -282,16 +282,15 @@ impl Server {
_ => disconnect = true, _ => disconnect = true,
}, },
ClientMsg::Character(character) => match client.client_state { ClientMsg::Character(character) => match client.client_state {
ClientState::Connected => disconnect = true, // Become Connected first ClientState::Connected => disconnect = true, // Become Registered first
ClientState::Registered | ClientState::Spectator => ClientState::Registered | ClientState::Spectator =>
Self::create_player_character(state, entity, client, character), Self::create_player_character(state, entity, client, character),
ClientState::Character => client.error_state(RequestStateError::Already), ClientState::Character => client.error_state(RequestStateError::Already),
}, },
ClientMsg::Chat(msg) => match client.client_state { ClientMsg::Chat(msg) => match client.client_state {
ClientState::Connected => disconnect = true, ClientState::Connected => disconnect = true,
ClientState::Registered => new_chat_msgs.push((entity, msg)), ClientState::Registered | ClientState::Spectator | ClientState::Character
ClientState::Spectator => new_chat_msgs.push((entity, msg)), => new_chat_msgs.push((entity, msg)),
ClientState::Character => new_chat_msgs.push((entity, msg)),
}, },
ClientMsg::PlayerAnimation(animation_history) => match client.client_state { ClientMsg::PlayerAnimation(animation_history) => match client.client_state {
ClientState::Character => state.write_component(entity, animation_history), ClientState::Character => state.write_component(entity, animation_history),