2019-12-18 05:22:52 +00:00
|
|
|
use super::{ClientState, EcsCompPacket};
|
2019-07-21 17:03:06 +00:00
|
|
|
use crate::{
|
2019-12-18 05:22:52 +00:00
|
|
|
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;
|
2019-04-10 23:16:29 +00:00
|
|
|
use vek::*;
|
2019-04-19 19:32:47 +00:00
|
|
|
|
2019-08-08 16:01:15 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
2019-04-19 19:32:47 +00:00
|
|
|
pub enum RequestStateError {
|
|
|
|
Denied,
|
|
|
|
Already,
|
|
|
|
Impossible,
|
2019-04-22 14:25:37 +00:00
|
|
|
WrongMessage,
|
2019-04-19 19:32:47 +00:00
|
|
|
}
|
2019-03-04 19:50:26 +00:00
|
|
|
|
2019-05-08 16:22:52 +00:00
|
|
|
#[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,
|
2019-05-08 16:22:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-23 06:02:00 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub enum PlayerListUpdate {
|
|
|
|
Init(HashMap<u64, String>),
|
|
|
|
Add(u64, String),
|
|
|
|
Remove(u64),
|
|
|
|
Alias(u64, String),
|
|
|
|
}
|
|
|
|
|
2019-04-22 00:38:29 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2019-03-03 22:02:38 +00:00
|
|
|
pub enum ServerMsg {
|
2019-04-19 19:32:47 +00:00
|
|
|
InitialSync {
|
2019-12-18 05:22:52 +00:00
|
|
|
entity_package: sync::EntityPackage<EcsCompPacket>,
|
2019-05-08 16:22:52 +00:00
|
|
|
server_info: ServerInfo,
|
2019-12-18 05:22:52 +00:00
|
|
|
time_of_day: state::TimeOfDay,
|
2020-01-11 19:25:48 +00:00
|
|
|
world_map: (Vec2<u32>, Vec<u32>)
|
2019-04-10 17:23:27 +00:00
|
|
|
},
|
2019-12-23 06:02:00 +00:00
|
|
|
PlayerListUpdate(PlayerListUpdate),
|
2019-04-21 18:12:29 +00:00
|
|
|
StateAnswer(Result<ClientState, (RequestStateError, ClientState)>),
|
2019-12-31 08:10:51 +00:00
|
|
|
/// Trigger cleanup for when the client goes back to the `Registered` state from an ingame
|
|
|
|
/// state
|
|
|
|
ExitIngameCleanup,
|
2019-03-05 18:39:18 +00:00
|
|
|
Ping,
|
|
|
|
Pong,
|
2019-07-17 22:10:42 +00:00
|
|
|
ChatMsg {
|
|
|
|
chat_type: ChatType,
|
2019-07-21 18:34:52 +00:00
|
|
|
message: String,
|
2019-07-17 22:10:42 +00:00
|
|
|
},
|
2019-04-10 17:23:27 +00:00
|
|
|
SetPlayerEntity(u64),
|
2019-12-18 05:22:52 +00:00
|
|
|
TimeOfDay(state::TimeOfDay),
|
2019-11-24 20:12:03 +00:00
|
|
|
EcsSync(sync::SyncPackage<EcsCompPacket>),
|
|
|
|
CreateEntity(sync::EntityPackage<EcsCompPacket>),
|
2019-10-06 17:35:47 +00:00
|
|
|
DeleteEntity(u64),
|
2019-07-30 11:35:16 +00:00
|
|
|
EntityPos {
|
2019-04-14 20:30:27 +00:00
|
|
|
entity: u64,
|
2019-06-14 15:27:05 +00:00
|
|
|
pos: comp::Pos,
|
2019-07-30 11:35:16 +00:00
|
|
|
},
|
|
|
|
EntityVel {
|
|
|
|
entity: u64,
|
|
|
|
vel: comp::Vel,
|
|
|
|
},
|
|
|
|
EntityOri {
|
|
|
|
entity: u64,
|
|
|
|
ori: comp::Ori,
|
|
|
|
},
|
2019-08-23 10:11:37 +00:00
|
|
|
EntityCharacterState {
|
2019-07-30 11:35:16 +00:00
|
|
|
entity: u64,
|
2019-08-23 10:11:37 +00:00
|
|
|
character_state: comp::CharacterState,
|
2019-04-14 20:30:27 +00:00
|
|
|
},
|
2019-07-25 14:48:27 +00:00
|
|
|
InventoryUpdate(comp::Inventory),
|
2019-04-10 23:16:29 +00:00
|
|
|
TerrainChunkUpdate {
|
2019-05-17 17:44:30 +00:00
|
|
|
key: Vec2<i32>,
|
2019-09-16 01:38:53 +00:00
|
|
|
chunk: Result<Box<TerrainChunk>, ()>,
|
2019-04-10 23:16:29 +00:00
|
|
|
},
|
2019-08-11 20:38:28 +00:00
|
|
|
TerrainBlockUpdates(HashMap<Vec3<i32>, Block>),
|
2019-07-04 16:14:45 +00:00
|
|
|
Error(ServerError),
|
2019-04-23 12:01:16 +00:00
|
|
|
Disconnect,
|
2019-04-19 19:32:47 +00:00
|
|
|
Shutdown,
|
2019-03-03 22:02:38 +00:00
|
|
|
}
|
2019-07-04 16:14:45 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub enum ServerError {
|
|
|
|
TooManyPlayers,
|
2019-08-08 03:56:02 +00:00
|
|
|
InvalidAuth,
|
2019-07-05 12:16:08 +00:00
|
|
|
//TODO: InvalidAlias,
|
2019-07-04 16:14:45 +00:00
|
|
|
}
|
2019-07-17 22:10:42 +00:00
|
|
|
|
|
|
|
impl ServerMsg {
|
2019-07-21 18:34:52 +00:00
|
|
|
pub fn chat(message: String) -> ServerMsg {
|
|
|
|
ServerMsg::ChatMsg {
|
2019-07-17 22:10:42 +00:00
|
|
|
chat_type: ChatType::Chat,
|
2019-07-21 18:34:52 +00:00
|
|
|
message,
|
2019-07-17 22:10:42 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-21 18:34:52 +00:00
|
|
|
pub fn tell(message: String) -> ServerMsg {
|
|
|
|
ServerMsg::ChatMsg {
|
2019-07-17 22:10:42 +00:00
|
|
|
chat_type: ChatType::Tell,
|
2019-07-21 18:34:52 +00:00
|
|
|
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
|
|
|
}
|