veloren/common/src/msg/server.rs

74 lines
1.8 KiB
Rust
Raw Normal View History

use super::{ClientState, EcsCompPacket, EcsResPacket};
2019-07-17 22:10:42 +00:00
use crate::{comp, terrain::TerrainChunk, ChatType};
use vek::*;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RequestStateError {
Denied,
Already,
Impossible,
WrongMessage,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServerInfo {
pub name: String,
pub description: String,
2019-07-21 17:45:31 +00:00
pub git_hash: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ServerMsg {
InitialSync {
ecs_state: sphynx::StatePackage<EcsCompPacket, EcsResPacket>,
entity_uid: u64,
server_info: ServerInfo,
},
StateAnswer(Result<ClientState, (RequestStateError, ClientState)>),
ForceState(ClientState),
Ping,
Pong,
2019-07-17 22:10:42 +00:00
ChatMsg {
chat_type: ChatType,
msg: String,
},
SetPlayerEntity(u64),
EcsSync(sphynx::SyncPackage<EcsCompPacket, EcsResPacket>),
EntityPhysics {
entity: u64,
pos: comp::Pos,
2019-07-25 20:51:20 +00:00
vel: Option<comp::Vel>,
ori: Option<comp::Ori>,
2019-07-21 12:42:45 +00:00
action_state: Option<comp::ActionState>,
},
TerrainChunkUpdate {
key: Vec2<i32>,
chunk: Box<TerrainChunk>,
},
TerrainBlockUpdates(FxHashMap<Vec3<i32>, Block>),
Error(ServerError),
Disconnect,
Shutdown,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ServerError {
TooManyPlayers,
//TODO: InvalidAlias,
}
2019-07-17 22:10:42 +00:00
impl ServerMsg {
pub fn chat(message: String) -> crate::msg::server::ServerMsg {
crate::msg::server::ServerMsg::ChatMsg {
chat_type: ChatType::Chat,
msg: message,
}
}
pub fn tell(message: String) -> crate::msg::server::ServerMsg {
crate::msg::server::ServerMsg::ChatMsg {
chat_type: ChatType::Tell,
msg: message,
}
}
}