2020-10-07 10:31:49 +00:00
|
|
|
use super::{EcsCompPacket, PingMsg};
|
2019-07-21 17:03:06 +00:00
|
|
|
use crate::{
|
2020-05-09 15:41:25 +00:00
|
|
|
character::CharacterItem,
|
2020-07-14 20:11:39 +00:00
|
|
|
comp,
|
2020-07-31 17:16:20 +00:00
|
|
|
outcome::Outcome,
|
2020-07-14 20:11:39 +00:00
|
|
|
recipe::RecipeBook,
|
|
|
|
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;
|
2020-07-06 14:23:08 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-09-06 19:24:52 +00:00
|
|
|
use std::time::Duration;
|
2019-04-10 23:16:29 +00:00
|
|
|
use vek::*;
|
2019-04-19 19:32:47 +00:00
|
|
|
|
2020-10-07 10:31:49 +00:00
|
|
|
///This struct contains all messages the server might send (on different
|
|
|
|
/// streams though)
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub enum ServerMsg {
|
|
|
|
/// Basic info about server, send ONCE, clients need it to Register
|
|
|
|
Info(ServerInfo),
|
|
|
|
/// Initial data package, send BEFORE Register ONCE. Not Register relevant
|
|
|
|
Init(ServerInit),
|
|
|
|
/// Result to `ClientMsg::Register`. send ONCE
|
|
|
|
RegisterAnswer(ServerRegisterAnswer),
|
|
|
|
/// Msg only to send when client is on the character screen, e.g.
|
|
|
|
/// `CharacterListUpdate`
|
|
|
|
CharacterScreen(ServerCharacterScreen),
|
|
|
|
/// Msg only to send when client is playing in game, e.g.
|
|
|
|
/// `TerrainChunkUpdate`
|
|
|
|
InGame(ServerInGame),
|
|
|
|
///Msg that can be send ALWAYS as soon as client is registered, e.g. `Chat`
|
|
|
|
General(ServerGeneral),
|
|
|
|
Ping(PingMsg),
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
2nd Level Enums
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
/// Reponse To ClientType
|
2019-04-22 00:38:29 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2020-10-05 10:44:33 +00:00
|
|
|
#[allow(clippy::clippy::large_enum_variant)]
|
2020-10-07 10:31:49 +00:00
|
|
|
pub enum ServerInit {
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
TooManyPlayers,
|
|
|
|
GameSync {
|
2019-12-18 05:22:52 +00:00
|
|
|
entity_package: sync::EntityPackage<EcsCompPacket>,
|
|
|
|
time_of_day: state::TimeOfDay,
|
2020-08-07 01:59:28 +00:00
|
|
|
max_group_size: u32,
|
2020-09-06 19:24:52 +00:00
|
|
|
client_timeout: Duration,
|
2020-10-07 10:31:49 +00:00
|
|
|
world_map: crate::msg::world_packet::WorldMapMsg,
|
2020-07-14 20:11:39 +00:00
|
|
|
recipe_book: RecipeBook,
|
2019-04-10 17:23:27 +00:00
|
|
|
},
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 10:31:49 +00:00
|
|
|
pub type ServerRegisterAnswer = Result<(), RegisterError>;
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
|
2020-10-06 11:15:20 +00:00
|
|
|
//Messages only allowed while client in character screen
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2020-10-07 10:31:49 +00:00
|
|
|
pub enum ServerCharacterScreen {
|
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>),
|
2020-08-25 12:21:25 +00:00
|
|
|
/// An error occurred while creating or deleting a character
|
2020-05-09 15:41:25 +00:00
|
|
|
CharacterActionError(String),
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
CharacterSuccess,
|
|
|
|
}
|
|
|
|
|
2020-10-06 11:15:20 +00:00
|
|
|
//Messages only allowed while client is in game (with a character)
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2020-10-07 10:31:49 +00:00
|
|
|
pub enum ServerInGame {
|
2020-04-26 17:03:19 +00:00
|
|
|
GroupUpdate(comp::group::ChangeNotification<sync::Uid>),
|
2020-08-07 01:59:28 +00:00
|
|
|
// Indicate to the client that they are invited to join a group
|
|
|
|
GroupInvite {
|
|
|
|
inviter: sync::Uid,
|
|
|
|
timeout: std::time::Duration,
|
|
|
|
},
|
|
|
|
// Indicate to the client that their sent invite was not invalid and is currently pending
|
|
|
|
InvitePending(sync::Uid),
|
|
|
|
// Note: this could potentially include all the failure cases such as inviting yourself in
|
|
|
|
// which case the `InvitePending` message could be removed and the client could consider their
|
|
|
|
// invite pending until they receive this message
|
|
|
|
// Indicate to the client the result of their invite
|
|
|
|
InviteComplete {
|
|
|
|
target: sync::Uid,
|
|
|
|
answer: InviteAnswer,
|
|
|
|
},
|
2020-02-01 20:39:39 +00:00
|
|
|
/// Trigger cleanup for when the client goes back to the `Registered` state
|
|
|
|
/// from an ingame state
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
ExitInGameSuccess,
|
|
|
|
InventoryUpdate(comp::Inventory, comp::InventoryUpdateEvent),
|
|
|
|
TerrainChunkUpdate {
|
|
|
|
key: Vec2<i32>,
|
|
|
|
chunk: Result<Box<TerrainChunk>, ()>,
|
|
|
|
},
|
|
|
|
TerrainBlockUpdates(HashMap<Vec3<i32>, Block>),
|
|
|
|
SetViewDistance(u32),
|
|
|
|
Outcomes(Vec<Outcome>),
|
|
|
|
Knockback(Vec3<f32>),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Messages sent from the server to the client
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2020-10-07 10:31:49 +00:00
|
|
|
pub enum ServerGeneral {
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
PlayerListUpdate(PlayerListUpdate),
|
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-09-14 06:16:09 +00:00
|
|
|
Disconnect(DisconnectReason),
|
2020-05-14 16:56:10 +00:00
|
|
|
/// Send a popup notification such as "Waypoint Saved"
|
|
|
|
Notification(Notification),
|
2020-01-07 06:27:18 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 10:31:49 +00:00
|
|
|
/*
|
|
|
|
end of 2nd level Enums
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// Inform the client of updates to the player list.
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub enum PlayerListUpdate {
|
|
|
|
Init(HashMap<Uid, PlayerInfo>),
|
|
|
|
Add(Uid, PlayerInfo),
|
|
|
|
SelectedCharacter(Uid, CharacterInfo),
|
|
|
|
LevelChange(Uid, u32),
|
|
|
|
Admin(Uid, bool),
|
|
|
|
Remove(Uid),
|
|
|
|
Alias(Uid, String),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub struct PlayerInfo {
|
|
|
|
pub is_admin: bool,
|
|
|
|
pub is_online: bool,
|
|
|
|
pub player_alias: String,
|
|
|
|
pub character: Option<CharacterInfo>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub struct CharacterInfo {
|
|
|
|
pub name: String,
|
|
|
|
pub level: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub enum InviteAnswer {
|
|
|
|
Accepted,
|
|
|
|
Declined,
|
|
|
|
TimedOut,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub enum Notification {
|
|
|
|
WaypointSaved,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub enum DisconnectReason {
|
|
|
|
/// Server shut down
|
|
|
|
Shutdown,
|
|
|
|
/// Client sent disconnect message
|
|
|
|
Requested,
|
|
|
|
/// Client was kicked
|
|
|
|
Kicked(String),
|
|
|
|
}
|
|
|
|
|
2020-01-07 06:27:18 +00:00
|
|
|
#[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-07-31 03:34:35 +00:00
|
|
|
Banned(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()) }
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:31:49 +00:00
|
|
|
impl From<comp::ChatMsg> for ServerGeneral {
|
|
|
|
fn from(v: comp::ChatMsg) -> Self { ServerGeneral::ChatMsg(v) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<ServerMsg> for ServerInfo {
|
|
|
|
fn into(self) -> ServerMsg { ServerMsg::Info(self) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<ServerMsg> for ServerInit {
|
|
|
|
fn into(self) -> ServerMsg { ServerMsg::Init(self) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<ServerMsg> for ServerRegisterAnswer {
|
|
|
|
fn into(self) -> ServerMsg { ServerMsg::RegisterAnswer(self) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<ServerMsg> for ServerCharacterScreen {
|
|
|
|
fn into(self) -> ServerMsg { ServerMsg::CharacterScreen(self) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<ServerMsg> for ServerInGame {
|
|
|
|
fn into(self) -> ServerMsg { ServerMsg::InGame(self) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<ServerMsg> for ServerGeneral {
|
|
|
|
fn into(self) -> ServerMsg { ServerMsg::General(self) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<ServerMsg> for PingMsg {
|
|
|
|
fn into(self) -> ServerMsg { ServerMsg::Ping(self) }
|
2020-06-12 07:43:20 +00:00
|
|
|
}
|