mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Rename ClientState Connected -> Registered, Visitor -> Connected
Former-commit-id: 34f6726203b7d20b42937a02f48d8920ca3f1d7a
This commit is contained in:
parent
ba6ead4077
commit
9a48e2fd42
@ -57,7 +57,7 @@ impl Client {
|
|||||||
view_distance: u64,
|
view_distance: u64,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
|
|
||||||
let mut client_state = ClientState::Visitor;
|
let mut client_state = ClientState::Connected;
|
||||||
let mut postbox = PostBox::to(addr)?;
|
let mut postbox = PostBox::to(addr)?;
|
||||||
|
|
||||||
// Send connection request
|
// Send connection request
|
||||||
|
@ -9,8 +9,8 @@ pub use self::ecs_packet::EcsPacket;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum ClientState {
|
pub enum ClientState {
|
||||||
Visitor,
|
|
||||||
Connected,
|
Connected,
|
||||||
|
Registered,
|
||||||
Spectator,
|
Spectator,
|
||||||
Character,
|
Character,
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ impl Clients {
|
|||||||
|
|
||||||
pub fn notify_connected(&mut self, msg: ServerMsg) {
|
pub fn notify_connected(&mut self, msg: ServerMsg) {
|
||||||
for client in self.clients.values_mut() {
|
for client in self.clients.values_mut() {
|
||||||
if client.client_state != ClientState::Visitor {
|
if client.client_state != ClientState::Connected {
|
||||||
client.notify(msg.clone());
|
client.notify(msg.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ impl Clients {
|
|||||||
|
|
||||||
pub fn notify_connected_except(&mut self, except_entity: EcsEntity, msg: ServerMsg) {
|
pub fn notify_connected_except(&mut self, except_entity: EcsEntity, msg: ServerMsg) {
|
||||||
for (entity, client) in self.clients.iter_mut() {
|
for (entity, client) in self.clients.iter_mut() {
|
||||||
if client.client_state != ClientState::Visitor && *entity != except_entity {
|
if client.client_state != ClientState::Connected && *entity != except_entity {
|
||||||
client.notify(msg.clone());
|
client.notify(msg.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ impl Server {
|
|||||||
self.clients.add(
|
self.clients.add(
|
||||||
entity,
|
entity,
|
||||||
Client {
|
Client {
|
||||||
client_state: ClientState::Visitor,
|
client_state: ClientState::Connected,
|
||||||
postbox,
|
postbox,
|
||||||
last_ping: self.state.get_time(),
|
last_ping: self.state.get_time(),
|
||||||
},
|
},
|
||||||
@ -250,34 +250,34 @@ impl Server {
|
|||||||
for msg in new_msgs {
|
for msg in new_msgs {
|
||||||
match msg {
|
match msg {
|
||||||
ClientMsg::RequestState(requested_state) => match requested_state {
|
ClientMsg::RequestState(requested_state) => match requested_state {
|
||||||
ClientState::Visitor => disconnect = true,
|
ClientState::Connected => disconnect = true,
|
||||||
ClientState::Connected => match client.client_state {
|
ClientState::Registered => match client.client_state {
|
||||||
ClientState::Visitor => {}, // Use ClientMsg::Connect instead
|
ClientState::Connected => {}, // Use ClientMsg::Connect instead
|
||||||
ClientState::Connected => client.error_state(RequestStateError::Already),
|
ClientState::Registered => client.error_state(RequestStateError::Already),
|
||||||
ClientState::Spectator => client.allow_state(ClientState::Connected),
|
ClientState::Spectator => client.allow_state(ClientState::Registered),
|
||||||
ClientState::Character => client.allow_state(ClientState::Connected),
|
ClientState::Character => client.allow_state(ClientState::Registered),
|
||||||
},
|
},
|
||||||
ClientState::Spectator => match requested_state {
|
ClientState::Spectator => match requested_state {
|
||||||
ClientState::Visitor => disconnect = true, // Become Connected first
|
ClientState::Connected => disconnect = true, // Become Connected first
|
||||||
ClientState::Connected => client.allow_state(ClientState::Spectator),
|
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::Character => client.allow_state(ClientState::Spectator),
|
||||||
},
|
},
|
||||||
ClientState::Character => disconnect = true, // Use ClientMsg::Character instead
|
ClientState::Character => disconnect = true, // Use ClientMsg::Character instead
|
||||||
},
|
},
|
||||||
ClientMsg::Connect { player } => match client.client_state {
|
ClientMsg::Connect { player } => match client.client_state {
|
||||||
ClientState::Visitor => Self::initialize_client(state, entity, client, player),
|
ClientState::Connected => Self::initialize_client(state, entity, client, player),
|
||||||
_ => disconnect = true,
|
_ => disconnect = true,
|
||||||
},
|
},
|
||||||
ClientMsg::Character(character) => match client.client_state {
|
ClientMsg::Character(character) => match client.client_state {
|
||||||
ClientState::Visitor => disconnect = true, // Become Connected first
|
ClientState::Connected => disconnect = true, // Become Connected first
|
||||||
ClientState::Connected | 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::Visitor => disconnect = true,
|
ClientState::Connected => disconnect = true,
|
||||||
ClientState::Connected => new_chat_msgs.push((entity, msg)),
|
ClientState::Registered => new_chat_msgs.push((entity, msg)),
|
||||||
ClientState::Spectator => new_chat_msgs.push((entity, msg)),
|
ClientState::Spectator => new_chat_msgs.push((entity, msg)),
|
||||||
ClientState::Character => new_chat_msgs.push((entity, msg)),
|
ClientState::Character => new_chat_msgs.push((entity, msg)),
|
||||||
},
|
},
|
||||||
@ -294,7 +294,7 @@ impl Server {
|
|||||||
_ => disconnect = true, // Only characters send their position
|
_ => disconnect = true, // Only characters send their position
|
||||||
},
|
},
|
||||||
ClientMsg::TerrainChunkRequest { key } => match client.client_state {
|
ClientMsg::TerrainChunkRequest { key } => match client.client_state {
|
||||||
ClientState::Visitor | ClientState::Connected => disconnect = true, // Not allowed
|
ClientState::Connected | ClientState::Registered => disconnect = true, // Not allowed
|
||||||
ClientState::Spectator | ClientState::Character => {
|
ClientState::Spectator | ClientState::Character => {
|
||||||
match state.terrain().get_key(key) {
|
match state.terrain().get_key(key) {
|
||||||
Some(chunk) => {} /*client.postbox.send_message(ServerMsg::TerrainChunkUpdate {
|
Some(chunk) => {} /*client.postbox.send_message(ServerMsg::TerrainChunkUpdate {
|
||||||
@ -324,7 +324,7 @@ impl Server {
|
|||||||
if disconnect {
|
if disconnect {
|
||||||
disconnected_clients.push(entity);
|
disconnected_clients.push(entity);
|
||||||
client.postbox.send_message(ServerMsg::StateAnswer(
|
client.postbox.send_message(ServerMsg::StateAnswer(
|
||||||
Err((RequestStateError::Impossible, ClientState::Visitor))));
|
Err((RequestStateError::Impossible, ClientState::Connected))));
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
@ -404,7 +404,7 @@ impl Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tell the client his request was successful
|
// Tell the client his request was successful
|
||||||
client.allow_state(ClientState::Connected);
|
client.allow_state(ClientState::Registered);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sync client states with the most up to date information
|
/// Sync client states with the most up to date information
|
||||||
|
Loading…
Reference in New Issue
Block a user