veloren/common/src/msg/server.rs

130 lines
3.0 KiB
Rust
Raw Normal View History

use super::{ClientState, EcsCompPacket};
2019-07-21 17:03:06 +00:00
use crate::{
comp, state, sync,
2019-07-21 17:03:06 +00:00
terrain::{Block, TerrainChunk},
ChatType,
};
2019-08-11 20:38:28 +00:00
use hashbrown::HashMap;
use vek::*;
2019-08-08 16:01:15 +00:00
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
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,
2019-10-18 13:32:26 +00:00
pub git_date: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PlayerListUpdate {
Init(HashMap<u64, String>),
Add(u64, String),
Remove(u64),
Alias(u64, String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ServerMsg {
InitialSync {
entity_package: sync::EntityPackage<EcsCompPacket>,
server_info: ServerInfo,
time_of_day: state::TimeOfDay,
world_map: (Vec2<u32>, Vec<u32>)
},
PlayerListUpdate(PlayerListUpdate),
StateAnswer(Result<ClientState, (RequestStateError, ClientState)>),
/// Trigger cleanup for when the client goes back to the `Registered` state from an ingame
/// state
ExitIngameCleanup,
Ping,
Pong,
2019-07-17 22:10:42 +00:00
ChatMsg {
chat_type: ChatType,
message: String,
2019-07-17 22:10:42 +00:00
},
SetPlayerEntity(u64),
TimeOfDay(state::TimeOfDay),
2019-11-24 20:12:03 +00:00
EcsSync(sync::SyncPackage<EcsCompPacket>),
CreateEntity(sync::EntityPackage<EcsCompPacket>),
DeleteEntity(u64),
EntityPos {
entity: u64,
pos: comp::Pos,
},
EntityVel {
entity: u64,
vel: comp::Vel,
},
EntityOri {
entity: u64,
ori: comp::Ori,
},
EntityCharacterState {
entity: u64,
character_state: comp::CharacterState,
},
InventoryUpdate(comp::Inventory),
TerrainChunkUpdate {
key: Vec2<i32>,
chunk: Result<Box<TerrainChunk>, ()>,
},
2019-08-11 20:38:28 +00:00
TerrainBlockUpdates(HashMap<Vec3<i32>, Block>),
Error(ServerError),
Disconnect,
Shutdown,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ServerError {
TooManyPlayers,
2019-08-08 03:56:02 +00:00
InvalidAuth,
//TODO: InvalidAlias,
}
2019-07-17 22:10:42 +00:00
impl ServerMsg {
pub fn chat(message: String) -> ServerMsg {
ServerMsg::ChatMsg {
2019-07-17 22:10:42 +00:00
chat_type: ChatType::Chat,
message,
2019-07-17 22:10:42 +00:00
}
}
pub fn tell(message: String) -> ServerMsg {
ServerMsg::ChatMsg {
2019-07-17 22:10:42 +00:00
chat_type: ChatType::Tell,
message,
}
}
pub fn game(message: String) -> ServerMsg {
ServerMsg::ChatMsg {
chat_type: ChatType::GameUpdate,
message,
}
}
pub fn broadcast(message: String) -> ServerMsg {
ServerMsg::ChatMsg {
chat_type: ChatType::Broadcast,
message,
}
}
pub fn private(message: String) -> ServerMsg {
ServerMsg::ChatMsg {
chat_type: ChatType::Private,
message,
2019-07-17 22:10:42 +00:00
}
}
2019-07-29 14:40:46 +00:00
pub fn kill(message: String) -> ServerMsg {
ServerMsg::ChatMsg {
chat_type: ChatType::Kill,
message,
}
}
2019-07-17 22:10:42 +00:00
}