2019-12-18 05:22:52 +00:00
|
|
|
use super::{ClientState, EcsCompPacket};
|
2019-07-21 17:03:06 +00:00
|
|
|
use crate::{
|
2020-05-09 15:41:25 +00:00
|
|
|
character::CharacterItem,
|
2019-12-18 05:22:52 +00:00
|
|
|
comp, state, sync,
|
2020-06-02 06:11:47 +00:00
|
|
|
sync::Uid,
|
2019-07-21 17:03:06 +00:00
|
|
|
terrain::{Block, TerrainChunk},
|
|
|
|
};
|
2020-01-01 20:17:43 +00:00
|
|
|
use authc::AuthClientError;
|
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-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-12-21 17:02:39 +00:00
|
|
|
pub auth_provider: Option<String>,
|
2019-05-08 16:22:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 06:11:47 +00:00
|
|
|
/// Inform the client of updates to the player list.
|
2019-12-23 06:02:00 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub enum PlayerListUpdate {
|
2020-06-02 06:11:47 +00:00
|
|
|
Init(HashMap<Uid, PlayerInfo>),
|
|
|
|
Add(Uid, PlayerInfo),
|
|
|
|
SelectedCharacter(Uid, CharacterInfo),
|
|
|
|
LevelChange(Uid, u32),
|
|
|
|
Admin(Uid, bool),
|
|
|
|
Remove(Uid),
|
|
|
|
Alias(Uid, String),
|
2019-12-23 06:02:00 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 11:59:44 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub struct PlayerInfo {
|
2020-06-02 06:11:47 +00:00
|
|
|
pub is_admin: bool,
|
2020-06-11 03:40:48 +00:00
|
|
|
pub is_online: bool,
|
2020-05-20 11:59:44 +00:00
|
|
|
pub player_alias: String,
|
2020-05-24 09:20:54 +00:00
|
|
|
pub character: Option<CharacterInfo>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub struct CharacterInfo {
|
|
|
|
pub name: String,
|
|
|
|
pub level: u32,
|
2020-05-20 11:59:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:56:10 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub enum Notification {
|
|
|
|
WaypointSaved,
|
|
|
|
}
|
|
|
|
|
2020-06-02 02:42:26 +00:00
|
|
|
/// Messages sent from the server to the client
|
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 20:38:30 +00:00
|
|
|
world_map: (Vec2<u32>, Vec<u32>),
|
2019-04-10 17:23:27 +00:00
|
|
|
},
|
2020-06-16 01:00:32 +00:00
|
|
|
/// An error occurred while loading character data
|
|
|
|
CharacterDataLoadError(String),
|
2020-05-09 15:41:25 +00:00
|
|
|
/// A list of characters belonging to the a authenticated player was sent
|
|
|
|
CharacterListUpdate(Vec<CharacterItem>),
|
|
|
|
/// An error occured while creating or deleting a character
|
|
|
|
CharacterActionError(String),
|
2019-12-23 06:02:00 +00:00
|
|
|
PlayerListUpdate(PlayerListUpdate),
|
2019-04-21 18:12:29 +00:00
|
|
|
StateAnswer(Result<ClientState, (RequestStateError, ClientState)>),
|
2020-02-01 20:39:39 +00:00
|
|
|
/// Trigger cleanup for when the client goes back to the `Registered` state
|
|
|
|
/// from an ingame state
|
2019-12-31 08:10:51 +00:00
|
|
|
ExitIngameCleanup,
|
2019-03-05 18:39:18 +00:00
|
|
|
Ping,
|
|
|
|
Pong,
|
2020-06-02 02:42:26 +00:00
|
|
|
/// A message to go into the client chat box. The client is responsible for
|
2020-06-04 07:11:35 +00:00
|
|
|
/// formatting the message and turning it into a speech bubble.
|
2020-06-02 02:42:26 +00:00
|
|
|
ChatMsg(comp::ChatMsg),
|
2020-06-02 06:11:47 +00:00
|
|
|
SetPlayerEntity(Uid),
|
2019-12-18 05:22:52 +00:00
|
|
|
TimeOfDay(state::TimeOfDay),
|
2020-03-18 21:00:07 +00:00
|
|
|
EntitySync(sync::EntitySyncPackage),
|
|
|
|
CompSync(sync::CompSyncPackage<EcsCompPacket>),
|
2019-11-24 20:12:03 +00:00
|
|
|
CreateEntity(sync::EntityPackage<EcsCompPacket>),
|
2020-06-02 06:11:47 +00:00
|
|
|
DeleteEntity(Uid),
|
2020-03-04 10:09:48 +00:00
|
|
|
InventoryUpdate(comp::Inventory, comp::InventoryUpdateEvent),
|
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-04-23 12:01:16 +00:00
|
|
|
Disconnect,
|
2019-04-19 19:32:47 +00:00
|
|
|
Shutdown,
|
2020-01-07 06:27:18 +00:00
|
|
|
TooManyPlayers,
|
2020-05-14 16:56:10 +00:00
|
|
|
/// Send a popup notification such as "Waypoint Saved"
|
|
|
|
Notification(Notification),
|
2020-06-25 11:20:09 +00:00
|
|
|
SetViewDistance(u32),
|
2019-03-03 22:02:38 +00:00
|
|
|
}
|
2019-07-04 16:14:45 +00:00
|
|
|
|
2020-01-07 06:27:18 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
|
|
pub enum RequestStateError {
|
|
|
|
RegisterDenied(RegisterError),
|
|
|
|
Denied,
|
|
|
|
Already,
|
|
|
|
Impossible,
|
|
|
|
WrongMessage,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
|
|
pub enum RegisterError {
|
2019-12-21 17:02:39 +00:00
|
|
|
AlreadyLoggedIn,
|
2020-01-01 20:17:43 +00:00
|
|
|
AuthError(String),
|
2020-05-11 10:06:53 +00:00
|
|
|
InvalidCharacter,
|
2020-06-24 15:27:18 +00:00
|
|
|
NotOnWhitelist,
|
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
|
|
|
|
2020-01-07 06:27:18 +00:00
|
|
|
impl From<AuthClientError> for RegisterError {
|
2020-01-01 20:17:43 +00:00
|
|
|
fn from(err: AuthClientError) -> Self { Self::AuthError(err.to_string()) }
|
|
|
|
}
|
|
|
|
|
2019-07-17 22:10:42 +00:00
|
|
|
impl ServerMsg {
|
2019-07-21 18:34:52 +00:00
|
|
|
pub fn broadcast(message: String) -> ServerMsg {
|
2020-06-02 02:42:26 +00:00
|
|
|
ServerMsg::ChatMsg(comp::ChatMsg {
|
|
|
|
chat_type: comp::ChatType::Broadcast,
|
2019-07-21 18:34:52 +00:00
|
|
|
message,
|
2020-06-02 02:42:26 +00:00
|
|
|
})
|
2019-07-21 18:34:52 +00:00
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-07-21 18:34:52 +00:00
|
|
|
pub fn private(message: String) -> ServerMsg {
|
2020-06-02 02:42:26 +00:00
|
|
|
ServerMsg::ChatMsg(comp::ChatMsg {
|
|
|
|
chat_type: comp::ChatType::Private,
|
2020-06-01 04:33:39 +00:00
|
|
|
message,
|
2020-06-02 02:42:26 +00:00
|
|
|
})
|
2020-06-01 04:33:39 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 14:40:46 +00:00
|
|
|
pub fn kill(message: String) -> ServerMsg {
|
2020-06-02 02:42:26 +00:00
|
|
|
ServerMsg::ChatMsg(comp::ChatMsg {
|
|
|
|
chat_type: comp::ChatType::Kill,
|
2019-07-29 14:40:46 +00:00
|
|
|
message,
|
2020-06-02 02:42:26 +00:00
|
|
|
})
|
2019-07-29 14:40:46 +00:00
|
|
|
}
|
2019-07-17 22:10:42 +00:00
|
|
|
}
|