2019-10-20 07:20:21 +00:00
|
|
|
use super::SysTimer;
|
2020-05-12 23:58:15 +00:00
|
|
|
use crate::{
|
2020-09-13 16:26:50 +00:00
|
|
|
alias_validator::AliasValidator,
|
2020-09-17 23:02:14 +00:00
|
|
|
character_creator,
|
2020-09-13 16:26:50 +00:00
|
|
|
client::Client,
|
|
|
|
login_provider::LoginProvider,
|
|
|
|
metrics::{NetworkRequestMetrics, PlayerMetrics},
|
2020-09-17 23:02:14 +00:00
|
|
|
persistence::character_loader::CharacterLoader,
|
2020-10-06 02:59:47 +00:00
|
|
|
EditableSettings, Settings,
|
2020-05-12 23:58:15 +00:00
|
|
|
};
|
2019-10-15 04:06:14 +00:00
|
|
|
use common::{
|
2020-05-24 22:18:41 +00:00
|
|
|
comp::{
|
2020-10-10 07:01:30 +00:00
|
|
|
Admin, CanBuild, ChatMode, ChatType, ControlEvent, Controller, ForceUpdate, Ori, Player,
|
|
|
|
Pos, Stats, UnresolvedChatMsg, Vel,
|
2020-05-24 22:18:41 +00:00
|
|
|
},
|
2019-10-15 04:06:14 +00:00
|
|
|
event::{EventBus, ServerEvent},
|
2019-12-23 06:02:00 +00:00
|
|
|
msg::{
|
2020-10-12 08:18:28 +00:00
|
|
|
validate_chat_msg, CharacterInfo, ChatMsgValidationError, ClientGeneral, ClientInGame,
|
|
|
|
ClientRegister, DisconnectReason, PingMsg, PlayerInfo, PlayerListUpdate, RegisterError,
|
|
|
|
ServerGeneral, ServerRegisterAnswer, MAX_BYTES_CHAT_MSG,
|
2019-12-23 06:02:00 +00:00
|
|
|
},
|
2020-08-29 07:00:26 +00:00
|
|
|
span,
|
2019-10-15 04:06:14 +00:00
|
|
|
state::{BlockChange, Time},
|
2019-12-23 06:02:00 +00:00
|
|
|
sync::Uid,
|
2020-09-26 13:55:01 +00:00
|
|
|
terrain::{TerrainChunkSize, TerrainGrid},
|
|
|
|
vol::{ReadVol, RectVolSize},
|
2019-10-15 04:06:14 +00:00
|
|
|
};
|
2020-07-01 09:51:37 +00:00
|
|
|
use futures_executor::block_on;
|
|
|
|
use futures_timer::Delay;
|
|
|
|
use futures_util::{select, FutureExt};
|
2019-12-23 06:02:00 +00:00
|
|
|
use hashbrown::HashMap;
|
2019-10-15 04:06:14 +00:00
|
|
|
use specs::{
|
|
|
|
Entities, Join, Read, ReadExpect, ReadStorage, System, Write, WriteExpect, WriteStorage,
|
|
|
|
};
|
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
|
|
|
use tracing::{debug, error, info, trace, warn};
|
2020-07-01 09:45:39 +00:00
|
|
|
|
|
|
|
impl Sys {
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
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
|
|
|
fn handle_client_msg(
|
2020-07-01 09:45:39 +00:00
|
|
|
server_emitter: &mut common::event::Emitter<'_, ServerEvent>,
|
2020-07-12 20:18:57 +00:00
|
|
|
new_chat_msgs: &mut Vec<(Option<specs::Entity>, UnresolvedChatMsg)>,
|
2020-07-01 09:45:39 +00:00
|
|
|
entity: specs::Entity,
|
|
|
|
client: &mut Client,
|
2020-09-13 16:26:50 +00:00
|
|
|
player_metrics: &ReadExpect<'_, PlayerMetrics>,
|
2020-07-01 09:45:39 +00:00
|
|
|
uids: &ReadStorage<'_, Uid>,
|
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
|
|
|
chat_modes: &ReadStorage<'_, ChatMode>,
|
2020-10-07 10:31:49 +00:00
|
|
|
msg: ClientGeneral,
|
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
|
|
|
) -> Result<(), crate::error::Error> {
|
|
|
|
match msg {
|
2020-10-07 10:31:49 +00:00
|
|
|
ClientGeneral::ChatMsg(message) => {
|
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
|
|
|
if client.registered {
|
|
|
|
match validate_chat_msg(&message) {
|
|
|
|
Ok(()) => {
|
|
|
|
if let Some(from) = uids.get(entity) {
|
|
|
|
let mode = chat_modes.get(entity).cloned().unwrap_or_default();
|
|
|
|
let msg = mode.new_message(*from, message);
|
|
|
|
new_chat_msgs.push((Some(entity), msg));
|
|
|
|
} else {
|
|
|
|
error!("Could not send message. Missing player uid");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(ChatMsgValidationError::TooLong) => {
|
|
|
|
let max = MAX_BYTES_CHAT_MSG;
|
|
|
|
let len = message.len();
|
|
|
|
warn!(?len, ?max, "Received a chat message that's too long")
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-10-07 10:31:49 +00:00
|
|
|
ClientGeneral::Disconnect => {
|
|
|
|
client.send_msg(ServerGeneral::Disconnect(DisconnectReason::Requested));
|
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
|
|
|
ClientGeneral::Terminate => {
|
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
|
|
|
debug!(?entity, "Client send message to termitate session");
|
|
|
|
player_metrics
|
|
|
|
.clients_disconnected
|
|
|
|
.with_label_values(&["gracefully"])
|
|
|
|
.inc();
|
|
|
|
server_emitter.emit(ServerEvent::ClientDisconnect(entity));
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
_ => unreachable!("not a client_general msg"),
|
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
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
fn handle_client_in_game_msg(
|
|
|
|
server_emitter: &mut common::event::Emitter<'_, ServerEvent>,
|
|
|
|
entity: specs::Entity,
|
|
|
|
client: &mut Client,
|
|
|
|
terrain: &ReadExpect<'_, TerrainGrid>,
|
|
|
|
network_metrics: &ReadExpect<'_, NetworkRequestMetrics>,
|
2020-07-01 09:45:39 +00:00
|
|
|
can_build: &ReadStorage<'_, CanBuild>,
|
|
|
|
force_updates: &ReadStorage<'_, ForceUpdate>,
|
2020-07-03 19:40:37 +00:00
|
|
|
stats: &mut WriteStorage<'_, Stats>,
|
2020-07-01 09:45:39 +00:00
|
|
|
block_changes: &mut Write<'_, BlockChange>,
|
|
|
|
positions: &mut WriteStorage<'_, Pos>,
|
|
|
|
velocities: &mut WriteStorage<'_, Vel>,
|
|
|
|
orientations: &mut WriteStorage<'_, Ori>,
|
|
|
|
players: &mut WriteStorage<'_, Player>,
|
|
|
|
controllers: &mut WriteStorage<'_, Controller>,
|
2020-10-06 02:59:47 +00:00
|
|
|
settings: &Read<'_, Settings>,
|
2020-10-12 08:18:28 +00:00
|
|
|
msg: ClientGeneral,
|
2020-07-01 09:45:39 +00:00
|
|
|
) -> Result<(), crate::error::Error> {
|
2020-10-05 10:44:33 +00:00
|
|
|
if client.in_game.is_none() {
|
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
|
|
|
debug!(?entity, "client is not in_game, ignoring msg");
|
|
|
|
trace!(?msg, "ignored msg content");
|
2020-10-12 08:18:28 +00:00
|
|
|
if matches!(msg, ClientGeneral::TerrainChunkRequest{ .. }) {
|
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
|
|
|
network_metrics.chunks_request_dropped.inc();
|
|
|
|
}
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
match msg {
|
|
|
|
// Go back to registered state (char selection screen)
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::ExitInGame => {
|
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
|
|
|
client.in_game = None;
|
|
|
|
server_emitter.emit(ServerEvent::ExitIngame { entity });
|
2020-10-12 08:18:28 +00:00
|
|
|
client.send_msg(ServerGeneral::ExitInGameSuccess);
|
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-12 08:18:28 +00:00
|
|
|
ClientGeneral::SetViewDistance(view_distance) => {
|
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
|
|
|
players.get_mut(entity).map(|player| {
|
|
|
|
player.view_distance = Some(
|
|
|
|
settings
|
|
|
|
.max_view_distance
|
|
|
|
.map(|max| view_distance.min(max))
|
|
|
|
.unwrap_or(view_distance),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
2020-10-05 10:44:33 +00:00
|
|
|
//correct client if its VD is to high
|
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
|
|
|
if settings
|
|
|
|
.max_view_distance
|
|
|
|
.map(|max| view_distance > max)
|
|
|
|
.unwrap_or(false)
|
|
|
|
{
|
2020-10-12 08:18:28 +00:00
|
|
|
client.send_msg(ServerGeneral::SetViewDistance(
|
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
|
|
|
settings.max_view_distance.unwrap_or(0),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::ControllerInputs(inputs) => {
|
|
|
|
if let Some(ClientInGame::Character) = client.in_game {
|
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
|
|
|
if let Some(controller) = controllers.get_mut(entity) {
|
|
|
|
controller.inputs.update_with_new(inputs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::ControlEvent(event) => {
|
|
|
|
if let Some(ClientInGame::Character) = client.in_game {
|
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
|
|
|
// Skip respawn if client entity is alive
|
|
|
|
if let ControlEvent::Respawn = event {
|
|
|
|
if stats.get(entity).map_or(true, |s| !s.is_dead) {
|
|
|
|
//Todo: comment why return!
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(controller) = controllers.get_mut(entity) {
|
|
|
|
controller.events.push(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::ControlAction(event) => {
|
|
|
|
if let Some(ClientInGame::Character) = client.in_game {
|
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
|
|
|
if let Some(controller) = controllers.get_mut(entity) {
|
|
|
|
controller.actions.push(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::PlayerPhysics { pos, vel, ori } => {
|
|
|
|
if let Some(ClientInGame::Character) = client.in_game {
|
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
|
|
|
if force_updates.get(entity).is_none()
|
|
|
|
&& stats.get(entity).map_or(true, |s| !s.is_dead)
|
|
|
|
{
|
|
|
|
let _ = positions.insert(entity, pos);
|
|
|
|
let _ = velocities.insert(entity, vel);
|
|
|
|
let _ = orientations.insert(entity, ori);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::BreakBlock(pos) => {
|
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
|
|
|
if let Some(block) = can_build.get(entity).and_then(|_| terrain.get(pos).ok()) {
|
|
|
|
block_changes.set(pos, block.into_vacant());
|
|
|
|
}
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::PlaceBlock(pos, block) => {
|
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
|
|
|
if can_build.get(entity).is_some() {
|
|
|
|
block_changes.try_set(pos, block);
|
|
|
|
}
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::TerrainChunkRequest { key } => {
|
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
|
|
|
let in_vd = if let (Some(view_distance), Some(pos)) = (
|
|
|
|
players.get(entity).and_then(|p| p.view_distance),
|
|
|
|
positions.get(entity),
|
|
|
|
) {
|
|
|
|
pos.0.xy().map(|e| e as f64).distance(
|
|
|
|
key.map(|e| e as f64 + 0.5) * TerrainChunkSize::RECT_SIZE.map(|e| e as f64),
|
|
|
|
) < (view_distance as f64 - 1.0 + 2.5 * 2.0_f64.sqrt())
|
|
|
|
* TerrainChunkSize::RECT_SIZE.x as f64
|
|
|
|
} else {
|
|
|
|
true
|
|
|
|
};
|
|
|
|
if in_vd {
|
|
|
|
match terrain.get_key(key) {
|
|
|
|
Some(chunk) => {
|
|
|
|
network_metrics.chunks_served_from_memory.inc();
|
2020-10-12 08:18:28 +00:00
|
|
|
client.send_msg(ServerGeneral::TerrainChunkUpdate {
|
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
|
|
|
key,
|
|
|
|
chunk: Ok(Box::new(chunk.clone())),
|
|
|
|
})
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
network_metrics.chunks_generation_triggered.inc();
|
|
|
|
server_emitter.emit(ServerEvent::ChunkRequest(entity, key))
|
2020-10-06 02:59:47 +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
|
|
|
}
|
|
|
|
} else {
|
|
|
|
network_metrics.chunks_request_dropped.inc();
|
|
|
|
}
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::UnlockSkill(skill) => {
|
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
|
|
|
stats
|
|
|
|
.get_mut(entity)
|
|
|
|
.map(|s| s.skill_set.unlock_skill(skill));
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::RefundSkill(skill) => {
|
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
|
|
|
stats
|
|
|
|
.get_mut(entity)
|
|
|
|
.map(|s| s.skill_set.refund_skill(skill));
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::UnlockSkillGroup(skill_group_type) => {
|
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
|
|
|
stats
|
|
|
|
.get_mut(entity)
|
|
|
|
.map(|s| s.skill_set.unlock_skill_group(skill_group_type));
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
_ => unreachable!("not a client_in_game msg"),
|
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
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
2020-07-01 09:45:39 +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
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-10-06 11:15:20 +00:00
|
|
|
fn handle_client_character_screen_msg(
|
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
|
|
|
server_emitter: &mut common::event::Emitter<'_, ServerEvent>,
|
|
|
|
new_chat_msgs: &mut Vec<(Option<specs::Entity>, UnresolvedChatMsg)>,
|
|
|
|
entity: specs::Entity,
|
|
|
|
client: &mut Client,
|
|
|
|
character_loader: &ReadExpect<'_, CharacterLoader>,
|
|
|
|
uids: &ReadStorage<'_, Uid>,
|
|
|
|
players: &mut WriteStorage<'_, Player>,
|
|
|
|
editable_settings: &ReadExpect<'_, EditableSettings>,
|
|
|
|
alias_validator: &ReadExpect<'_, AliasValidator>,
|
2020-10-12 08:18:28 +00:00
|
|
|
msg: ClientGeneral,
|
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
|
|
|
) -> Result<(), crate::error::Error> {
|
|
|
|
match msg {
|
|
|
|
// Request spectator state
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::Spectate if client.registered => {
|
|
|
|
client.in_game = Some(ClientInGame::Spectator)
|
2020-10-11 22:14:04 +00:00
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::Spectate => debug!("dropped Spectate msg from unregistered client"),
|
|
|
|
ClientGeneral::Character(character_id)
|
2020-10-11 22:14:04 +00:00
|
|
|
if client.registered && client.in_game.is_none() =>
|
|
|
|
{
|
|
|
|
if let Some(player) = players.get(entity) {
|
|
|
|
// Send a request to load the character's component data from the
|
|
|
|
// DB. Once loaded, persisted components such as stats and inventory
|
|
|
|
// will be inserted for the entity
|
|
|
|
character_loader.load_character_data(
|
|
|
|
entity,
|
|
|
|
player.uuid().to_string(),
|
|
|
|
character_id,
|
|
|
|
);
|
2020-07-01 09:45:39 +00:00
|
|
|
|
2020-10-11 22:14:04 +00:00
|
|
|
// Start inserting non-persisted/default components for the entity
|
|
|
|
// while we load the DB data
|
|
|
|
server_emitter.emit(ServerEvent::InitCharacterData {
|
|
|
|
entity,
|
|
|
|
character_id,
|
|
|
|
});
|
2020-07-01 09:45:39 +00:00
|
|
|
|
2020-10-11 22:14:04 +00:00
|
|
|
// Give the player a welcome message
|
|
|
|
if !editable_settings.server_description.is_empty() {
|
|
|
|
client.send_msg(
|
|
|
|
ChatType::CommandInfo
|
|
|
|
.server_msg(String::from(&*editable_settings.server_description)),
|
|
|
|
);
|
|
|
|
}
|
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-11 22:14:04 +00:00
|
|
|
if !client.login_msg_sent {
|
|
|
|
if let Some(player_uid) = uids.get(entity) {
|
|
|
|
new_chat_msgs.push((None, UnresolvedChatMsg {
|
|
|
|
chat_type: ChatType::Online(*player_uid),
|
|
|
|
message: "".to_string(),
|
|
|
|
}));
|
2020-07-01 09:45:39 +00:00
|
|
|
|
2020-10-11 22:14:04 +00:00
|
|
|
client.login_msg_sent = true;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-10-12 08:18:28 +00:00
|
|
|
client.send_msg(ServerGeneral::CharacterDataLoadError(String::from(
|
2020-10-11 22:14:04 +00:00
|
|
|
"Failed to fetch player entity",
|
|
|
|
)))
|
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-11 22:14:04 +00:00
|
|
|
}
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::Character(_) => {
|
2020-10-11 22:14:04 +00:00
|
|
|
let registered = client.registered;
|
|
|
|
let in_game = client.in_game;
|
|
|
|
debug!(?registered, ?in_game, "dropped Character msg from client");
|
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-12 08:18:28 +00:00
|
|
|
ClientGeneral::RequestCharacterList => {
|
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
|
|
|
if let Some(player) = players.get(entity) {
|
|
|
|
character_loader.load_character_list(entity, player.uuid().to_string())
|
|
|
|
}
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::CreateCharacter { alias, tool, body } => {
|
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
|
|
|
if let Err(error) = alias_validator.validate(&alias) {
|
|
|
|
debug!(?error, ?alias, "denied alias as it contained a banned word");
|
2020-10-12 08:18:28 +00:00
|
|
|
client.send_msg(ServerGeneral::CharacterActionError(error.to_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
|
|
|
} else if let Some(player) = players.get(entity) {
|
|
|
|
character_creator::create_character(
|
|
|
|
entity,
|
|
|
|
player.uuid().to_string(),
|
|
|
|
alias,
|
|
|
|
tool,
|
|
|
|
body,
|
|
|
|
character_loader,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
ClientGeneral::DeleteCharacter(character_id) => {
|
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
|
|
|
if let Some(player) = players.get(entity) {
|
|
|
|
character_loader.delete_character(
|
|
|
|
entity,
|
|
|
|
player.uuid().to_string(),
|
|
|
|
character_id,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2020-10-12 08:18:28 +00:00
|
|
|
_ => unreachable!("not a client_character_screen msg"),
|
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
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
fn handle_ping_msg(client: &mut Client, msg: PingMsg) -> Result<(), crate::error::Error> {
|
|
|
|
match msg {
|
2020-10-07 10:31:49 +00:00
|
|
|
PingMsg::Ping => client.send_msg(PingMsg::Pong),
|
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
|
|
|
PingMsg::Pong => {},
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
fn handle_register_msg(
|
|
|
|
player_list: &HashMap<Uid, PlayerInfo>,
|
|
|
|
new_players: &mut Vec<specs::Entity>,
|
|
|
|
entity: specs::Entity,
|
|
|
|
client: &mut Client,
|
|
|
|
player_metrics: &ReadExpect<'_, PlayerMetrics>,
|
|
|
|
login_provider: &mut WriteExpect<'_, LoginProvider>,
|
|
|
|
admins: &mut WriteStorage<'_, Admin>,
|
|
|
|
players: &mut WriteStorage<'_, Player>,
|
|
|
|
editable_settings: &ReadExpect<'_, EditableSettings>,
|
2020-10-07 10:31:49 +00:00
|
|
|
msg: ClientRegister,
|
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
|
|
|
) -> Result<(), crate::error::Error> {
|
|
|
|
let (username, uuid) = match login_provider.try_login(
|
|
|
|
&msg.token_or_username,
|
|
|
|
&*editable_settings.admins,
|
|
|
|
&*editable_settings.whitelist,
|
|
|
|
&*editable_settings.banlist,
|
|
|
|
) {
|
|
|
|
Err(err) => {
|
|
|
|
client
|
|
|
|
.register_stream
|
2020-10-07 10:31:49 +00:00
|
|
|
.send(ServerRegisterAnswer::Err(err))?;
|
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
|
|
|
return Ok(());
|
|
|
|
},
|
|
|
|
Ok((username, uuid)) => (username, uuid),
|
|
|
|
};
|
2020-07-01 09:45:39 +00:00
|
|
|
|
2020-10-05 10:44:33 +00:00
|
|
|
const INITIAL_VD: Option<u32> = Some(5); //will be changed after login
|
2020-10-12 08:18:28 +00:00
|
|
|
let player = Player::new(username, None, INITIAL_VD, uuid);
|
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
|
|
|
let is_admin = editable_settings.admins.contains(&uuid);
|
2020-07-01 09:45:39 +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
|
|
|
if !player.is_valid() {
|
|
|
|
// Invalid player
|
2020-10-07 10:31:49 +00:00
|
|
|
client
|
|
|
|
.register_stream
|
|
|
|
.send(ServerRegisterAnswer::Err(RegisterError::InvalidCharacter))?;
|
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
|
|
|
return Ok(());
|
|
|
|
}
|
2020-07-01 09:45:39 +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
|
|
|
if !client.registered && client.in_game.is_none() {
|
|
|
|
// Add Player component to this client
|
|
|
|
let _ = players.insert(entity, player);
|
|
|
|
player_metrics.players_connected.inc();
|
2020-07-01 09:45:39 +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
|
|
|
// Give the Admin component to the player if their name exists in
|
|
|
|
// admin list
|
|
|
|
if is_admin {
|
|
|
|
let _ = admins.insert(entity, Admin);
|
|
|
|
}
|
2020-07-07 11:42:05 +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
|
|
|
// Tell the client its request was successful.
|
|
|
|
client.registered = true;
|
2020-10-07 10:31:49 +00:00
|
|
|
client.register_stream.send(ServerRegisterAnswer::Ok(()))?;
|
2020-07-01 09:45:39 +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
|
|
|
// Send initial player list
|
2020-10-07 10:31:49 +00:00
|
|
|
client.send_msg(ServerGeneral::PlayerListUpdate(PlayerListUpdate::Init(
|
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
|
|
|
player_list.clone(),
|
|
|
|
)));
|
2020-07-01 09:45:39 +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
|
|
|
// Add to list to notify all clients of the new player
|
|
|
|
new_players.push(entity);
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
2020-07-01 09:45:39 +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
|
|
|
///We needed to move this to a async fn, if we would use a async closures
|
|
|
|
/// the compiler generates to much recursion and fails to compile this
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
async fn handle_messages(
|
|
|
|
server_emitter: &mut common::event::Emitter<'_, ServerEvent>,
|
|
|
|
new_chat_msgs: &mut Vec<(Option<specs::Entity>, UnresolvedChatMsg)>,
|
|
|
|
player_list: &HashMap<Uid, PlayerInfo>,
|
|
|
|
new_players: &mut Vec<specs::Entity>,
|
|
|
|
entity: specs::Entity,
|
|
|
|
client: &mut Client,
|
|
|
|
cnt: &mut u64,
|
|
|
|
character_loader: &ReadExpect<'_, CharacterLoader>,
|
|
|
|
terrain: &ReadExpect<'_, TerrainGrid>,
|
|
|
|
network_metrics: &ReadExpect<'_, NetworkRequestMetrics>,
|
|
|
|
player_metrics: &ReadExpect<'_, PlayerMetrics>,
|
|
|
|
uids: &ReadStorage<'_, Uid>,
|
|
|
|
can_build: &ReadStorage<'_, CanBuild>,
|
|
|
|
force_updates: &ReadStorage<'_, ForceUpdate>,
|
|
|
|
stats: &mut WriteStorage<'_, Stats>,
|
|
|
|
chat_modes: &ReadStorage<'_, ChatMode>,
|
|
|
|
login_provider: &mut WriteExpect<'_, LoginProvider>,
|
|
|
|
block_changes: &mut Write<'_, BlockChange>,
|
|
|
|
admins: &mut WriteStorage<'_, Admin>,
|
|
|
|
positions: &mut WriteStorage<'_, Pos>,
|
|
|
|
velocities: &mut WriteStorage<'_, Vel>,
|
|
|
|
orientations: &mut WriteStorage<'_, Ori>,
|
|
|
|
players: &mut WriteStorage<'_, Player>,
|
|
|
|
controllers: &mut WriteStorage<'_, Controller>,
|
|
|
|
settings: &Read<'_, Settings>,
|
|
|
|
editable_settings: &ReadExpect<'_, EditableSettings>,
|
|
|
|
alias_validator: &ReadExpect<'_, AliasValidator>,
|
|
|
|
) -> Result<(), crate::error::Error> {
|
2020-10-07 11:59:14 +00:00
|
|
|
let (mut b1, mut b2, mut b3, mut b4, mut b5) = (
|
|
|
|
client.network_error,
|
|
|
|
client.network_error,
|
|
|
|
client.network_error,
|
|
|
|
client.network_error,
|
|
|
|
client.network_error,
|
|
|
|
);
|
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
|
|
|
loop {
|
2020-10-11 22:14:04 +00:00
|
|
|
/*
|
|
|
|
waiting for 1 of the 5 streams to return a massage asynchronous.
|
|
|
|
If so, handle that msg type. This code will be refactored soon
|
|
|
|
*/
|
|
|
|
|
2020-10-07 11:59:14 +00:00
|
|
|
let q1 = Client::internal_recv(&mut b1, &mut client.general_stream);
|
|
|
|
let q2 = Client::internal_recv(&mut b2, &mut client.in_game_stream);
|
|
|
|
let q3 = Client::internal_recv(&mut b3, &mut client.character_screen_stream);
|
|
|
|
let q4 = Client::internal_recv(&mut b4, &mut client.ping_stream);
|
|
|
|
let q5 = Client::internal_recv(&mut b5, &mut client.register_stream);
|
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
|
|
|
|
|
|
|
let (m1, m2, m3, m4, m5) = select!(
|
2020-10-07 11:59:14 +00:00
|
|
|
msg = q1.fuse() => (Some(msg), None, None, None, None),
|
|
|
|
msg = q2.fuse() => (None, Some(msg), None, None, None),
|
|
|
|
msg = q3.fuse() => (None, None, Some(msg), None, None),
|
|
|
|
msg = q4.fuse() => (None, None, None, Some(msg), None),
|
|
|
|
msg = q5.fuse() => (None, None, None, None,Some(msg)),
|
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
|
|
|
);
|
|
|
|
*cnt += 1;
|
|
|
|
if let Some(msg) = m1 {
|
2020-10-07 11:59:14 +00:00
|
|
|
client.network_error |= b1;
|
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
|
|
|
Self::handle_client_msg(
|
|
|
|
server_emitter,
|
|
|
|
new_chat_msgs,
|
|
|
|
entity,
|
|
|
|
client,
|
|
|
|
player_metrics,
|
|
|
|
uids,
|
|
|
|
chat_modes,
|
2020-10-07 11:59:14 +00:00
|
|
|
msg?,
|
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
|
|
|
)?;
|
|
|
|
}
|
|
|
|
if let Some(msg) = m2 {
|
2020-10-07 11:59:14 +00:00
|
|
|
client.network_error |= b2;
|
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
|
|
|
Self::handle_client_in_game_msg(
|
|
|
|
server_emitter,
|
|
|
|
entity,
|
|
|
|
client,
|
|
|
|
terrain,
|
|
|
|
network_metrics,
|
|
|
|
can_build,
|
|
|
|
force_updates,
|
|
|
|
stats,
|
|
|
|
block_changes,
|
|
|
|
positions,
|
|
|
|
velocities,
|
|
|
|
orientations,
|
|
|
|
players,
|
|
|
|
controllers,
|
|
|
|
settings,
|
2020-10-07 11:59:14 +00:00
|
|
|
msg?,
|
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
|
|
|
)?;
|
|
|
|
}
|
|
|
|
if let Some(msg) = m3 {
|
2020-10-07 11:59:14 +00:00
|
|
|
client.network_error |= b3;
|
2020-10-06 11:15:20 +00:00
|
|
|
Self::handle_client_character_screen_msg(
|
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
|
|
|
server_emitter,
|
|
|
|
new_chat_msgs,
|
|
|
|
entity,
|
|
|
|
client,
|
|
|
|
character_loader,
|
|
|
|
uids,
|
|
|
|
players,
|
|
|
|
editable_settings,
|
|
|
|
alias_validator,
|
2020-10-07 11:59:14 +00:00
|
|
|
msg?,
|
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
|
|
|
)?;
|
|
|
|
}
|
|
|
|
if let Some(msg) = m4 {
|
2020-10-07 11:59:14 +00:00
|
|
|
client.network_error |= b4;
|
|
|
|
Self::handle_ping_msg(client, msg?)?;
|
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
|
|
|
}
|
|
|
|
if let Some(msg) = m5 {
|
2020-10-07 11:59:14 +00:00
|
|
|
client.network_error |= b5;
|
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
|
|
|
Self::handle_register_msg(
|
|
|
|
player_list,
|
|
|
|
new_players,
|
|
|
|
entity,
|
|
|
|
client,
|
|
|
|
player_metrics,
|
|
|
|
login_provider,
|
|
|
|
admins,
|
|
|
|
players,
|
|
|
|
editable_settings,
|
2020-10-07 11:59:14 +00:00
|
|
|
msg?,
|
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-07-01 09:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-15 04:06:14 +00:00
|
|
|
|
|
|
|
/// This system will handle new messages from clients
|
|
|
|
pub struct Sys;
|
|
|
|
impl<'a> System<'a> for Sys {
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::type_complexity)] // TODO: Pending review in #587
|
2019-10-15 04:06:14 +00:00
|
|
|
type SystemData = (
|
|
|
|
Entities<'a>,
|
|
|
|
Read<'a, EventBus<ServerEvent>>,
|
|
|
|
Read<'a, Time>,
|
2020-06-16 01:00:32 +00:00
|
|
|
ReadExpect<'a, CharacterLoader>,
|
2019-10-15 04:06:14 +00:00
|
|
|
ReadExpect<'a, TerrainGrid>,
|
2020-09-13 16:26:50 +00:00
|
|
|
ReadExpect<'a, NetworkRequestMetrics>,
|
|
|
|
ReadExpect<'a, PlayerMetrics>,
|
2019-10-20 07:20:21 +00:00
|
|
|
Write<'a, SysTimer<Self>>,
|
2019-12-23 06:02:00 +00:00
|
|
|
ReadStorage<'a, Uid>,
|
2019-10-15 04:06:14 +00:00
|
|
|
ReadStorage<'a, CanBuild>,
|
2019-11-29 06:04:37 +00:00
|
|
|
ReadStorage<'a, ForceUpdate>,
|
2020-07-03 19:40:37 +00:00
|
|
|
WriteStorage<'a, Stats>,
|
2020-06-02 02:42:26 +00:00
|
|
|
ReadStorage<'a, ChatMode>,
|
2020-07-23 17:16:52 +00:00
|
|
|
WriteExpect<'a, LoginProvider>,
|
2019-10-15 04:06:14 +00:00
|
|
|
Write<'a, BlockChange>,
|
2020-06-24 03:29:46 +00:00
|
|
|
WriteStorage<'a, Admin>,
|
2019-10-15 04:06:14 +00:00
|
|
|
WriteStorage<'a, Pos>,
|
|
|
|
WriteStorage<'a, Vel>,
|
|
|
|
WriteStorage<'a, Ori>,
|
|
|
|
WriteStorage<'a, Player>,
|
|
|
|
WriteStorage<'a, Client>,
|
|
|
|
WriteStorage<'a, Controller>,
|
2020-10-06 02:59:47 +00:00
|
|
|
Read<'a, Settings>,
|
|
|
|
ReadExpect<'a, EditableSettings>,
|
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
|
|
|
ReadExpect<'a, AliasValidator>,
|
2019-10-15 04:06:14 +00:00
|
|
|
);
|
|
|
|
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::match_ref_pats)] // TODO: Pending review in #587
|
|
|
|
#[allow(clippy::single_char_pattern)] // TODO: Pending review in #587
|
|
|
|
#[allow(clippy::single_match)] // TODO: Pending review in #587
|
2019-10-15 04:06:14 +00:00
|
|
|
fn run(
|
|
|
|
&mut self,
|
|
|
|
(
|
|
|
|
entities,
|
2020-03-22 04:49:32 +00:00
|
|
|
server_event_bus,
|
2019-10-15 04:06:14 +00:00
|
|
|
time,
|
2020-06-16 01:00:32 +00:00
|
|
|
character_loader,
|
2019-10-15 04:06:14 +00:00
|
|
|
terrain,
|
2020-09-13 16:26:50 +00:00
|
|
|
network_metrics,
|
|
|
|
player_metrics,
|
2019-10-20 07:20:21 +00:00
|
|
|
mut timer,
|
2019-12-23 06:02:00 +00:00
|
|
|
uids,
|
2019-10-15 04:06:14 +00:00
|
|
|
can_build,
|
2019-11-29 06:04:37 +00:00
|
|
|
force_updates,
|
2020-07-03 19:40:37 +00:00
|
|
|
mut stats,
|
2020-06-02 02:42:26 +00:00
|
|
|
chat_modes,
|
2019-10-15 04:06:14 +00:00
|
|
|
mut accounts,
|
|
|
|
mut block_changes,
|
2020-06-24 03:29:46 +00:00
|
|
|
mut admins,
|
2019-10-15 04:06:14 +00:00
|
|
|
mut positions,
|
|
|
|
mut velocities,
|
|
|
|
mut orientations,
|
|
|
|
mut players,
|
|
|
|
mut clients,
|
|
|
|
mut controllers,
|
2020-06-25 11:20:09 +00:00
|
|
|
settings,
|
2020-10-06 02:59:47 +00:00
|
|
|
editable_settings,
|
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
|
|
|
alias_validator,
|
2019-10-15 04:06:14 +00:00
|
|
|
): Self::SystemData,
|
|
|
|
) {
|
2020-09-07 04:59:16 +00:00
|
|
|
span!(_guard, "run", "message::Sys::run");
|
2019-10-20 07:20:21 +00:00
|
|
|
timer.start();
|
|
|
|
|
2020-03-22 04:49:32 +00:00
|
|
|
let mut server_emitter = server_event_bus.emitter();
|
|
|
|
|
2020-07-12 20:18:57 +00:00
|
|
|
let mut new_chat_msgs = Vec::new();
|
2019-10-15 04:06:14 +00:00
|
|
|
|
2019-12-23 06:02:00 +00:00
|
|
|
// Player list to send new players.
|
2020-06-02 06:11:47 +00:00
|
|
|
let player_list = (&uids, &players, stats.maybe(), admins.maybe())
|
2019-12-23 06:02:00 +00:00
|
|
|
.join()
|
2020-06-02 06:11:47 +00:00
|
|
|
.map(|(uid, player, stats, admin)| {
|
2020-06-28 13:15:00 +00:00
|
|
|
(*uid, PlayerInfo {
|
2020-06-11 03:40:48 +00:00
|
|
|
is_online: true,
|
2020-06-02 06:11:47 +00:00
|
|
|
is_admin: admin.is_some(),
|
2020-05-20 11:59:44 +00:00
|
|
|
player_alias: player.alias.clone(),
|
2020-06-02 06:11:47 +00:00
|
|
|
character: stats.map(|stats| CharacterInfo {
|
2020-05-24 09:20:54 +00:00
|
|
|
name: stats.name.clone(),
|
|
|
|
level: stats.level.level(),
|
|
|
|
}),
|
2020-05-20 11:59:44 +00:00
|
|
|
})
|
|
|
|
})
|
2019-12-23 06:02:00 +00:00
|
|
|
.collect::<HashMap<_, _>>();
|
|
|
|
// List of new players to update player lists of all clients.
|
|
|
|
let mut new_players = Vec::new();
|
|
|
|
|
2019-10-15 04:06:14 +00:00
|
|
|
for (entity, client) in (&entities, &mut clients).join() {
|
2020-07-01 09:45:39 +00:00
|
|
|
let mut cnt = 0;
|
|
|
|
|
2020-07-01 09:51:37 +00:00
|
|
|
let network_err: Result<(), crate::error::Error> = block_on(async {
|
2020-07-10 13:31:26 +00:00
|
|
|
//TIMEOUT 0.02 ms for msg handling
|
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
|
|
|
let work_future = Self::handle_messages(
|
2020-07-01 09:45:39 +00:00
|
|
|
&mut server_emitter,
|
|
|
|
&mut new_chat_msgs,
|
|
|
|
&player_list,
|
|
|
|
&mut new_players,
|
|
|
|
entity,
|
|
|
|
client,
|
|
|
|
&mut cnt,
|
|
|
|
&character_loader,
|
|
|
|
&terrain,
|
2020-09-13 16:26:50 +00:00
|
|
|
&network_metrics,
|
|
|
|
&player_metrics,
|
2020-07-01 09:45:39 +00:00
|
|
|
&uids,
|
|
|
|
&can_build,
|
|
|
|
&force_updates,
|
2020-07-03 19:40:37 +00:00
|
|
|
&mut stats,
|
2020-07-01 09:45:39 +00:00
|
|
|
&chat_modes,
|
|
|
|
&mut accounts,
|
|
|
|
&mut block_changes,
|
|
|
|
&mut admins,
|
|
|
|
&mut positions,
|
|
|
|
&mut velocities,
|
|
|
|
&mut orientations,
|
|
|
|
&mut players,
|
|
|
|
&mut controllers,
|
|
|
|
&settings,
|
2020-10-06 02:59:47 +00:00
|
|
|
&editable_settings,
|
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
|
|
|
&alias_validator,
|
2020-09-13 16:26:50 +00:00
|
|
|
);
|
|
|
|
select!(
|
|
|
|
_ = Delay::new(std::time::Duration::from_micros(20)).fuse() => Ok(()),
|
|
|
|
err = work_future.fuse() => err,
|
2020-07-01 09:45:39 +00:00
|
|
|
)
|
|
|
|
});
|
2019-10-15 04:06:14 +00:00
|
|
|
|
2020-10-11 22:14:04 +00:00
|
|
|
// Network error
|
2020-10-07 11:59:14 +00:00
|
|
|
if network_err.is_err() {
|
|
|
|
debug!(?entity, "postbox error with client, disconnecting");
|
|
|
|
player_metrics
|
|
|
|
.clients_disconnected
|
|
|
|
.with_label_values(&["network_error"])
|
|
|
|
.inc();
|
|
|
|
server_emitter.emit(ServerEvent::ClientDisconnect(entity));
|
|
|
|
} else if cnt > 0 {
|
|
|
|
// Update client ping.
|
2020-05-26 00:11:22 +00:00
|
|
|
client.last_ping = time.0
|
2020-09-06 19:24:52 +00:00
|
|
|
} else if time.0 - client.last_ping > settings.client_timeout.as_secs() as f64
|
2020-08-18 16:42:02 +00:00
|
|
|
// Timeout
|
|
|
|
{
|
|
|
|
info!(?entity, "timeout error with client, disconnecting");
|
2020-09-13 16:26:50 +00:00
|
|
|
player_metrics
|
2020-09-16 22:19:48 +00:00
|
|
|
.clients_disconnected
|
2020-09-13 16:26:50 +00:00
|
|
|
.with_label_values(&["timeout"])
|
|
|
|
.inc();
|
2020-08-18 16:42:02 +00:00
|
|
|
server_emitter.emit(ServerEvent::ClientDisconnect(entity));
|
2020-09-06 19:24:52 +00:00
|
|
|
} else if time.0 - client.last_ping > settings.client_timeout.as_secs() as f64 * 0.5 {
|
2019-10-15 04:06:14 +00:00
|
|
|
// Try pinging the client if the timeout is nearing.
|
2020-10-07 10:31:49 +00:00
|
|
|
client.send_msg(PingMsg::Ping);
|
2019-10-15 04:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-23 06:02:00 +00:00
|
|
|
// Handle new players.
|
|
|
|
// Tell all clients to add them to the player list.
|
|
|
|
for entity in new_players {
|
2020-05-24 09:20:54 +00:00
|
|
|
if let (Some(uid), Some(player)) = (uids.get(entity), players.get(entity)) {
|
2020-10-05 10:44:33 +00:00
|
|
|
let msg =
|
2020-10-07 10:31:49 +00:00
|
|
|
ServerGeneral::PlayerListUpdate(PlayerListUpdate::Add(*uid, PlayerInfo {
|
2020-10-05 10:44:33 +00:00
|
|
|
player_alias: player.alias.clone(),
|
|
|
|
is_online: true,
|
|
|
|
is_admin: admins.get(entity).is_some(),
|
|
|
|
character: None, // new players will be on character select.
|
|
|
|
}));
|
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
|
|
|
for client in (&mut clients).join().filter(|c| c.registered) {
|
|
|
|
client.send_msg(msg.clone())
|
2019-12-23 06:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-15 04:06:14 +00:00
|
|
|
// Handle new chat messages.
|
|
|
|
for (entity, msg) in new_chat_msgs {
|
2020-06-05 01:48:26 +00:00
|
|
|
// Handle chat commands.
|
|
|
|
if msg.message.starts_with("/") {
|
|
|
|
if let (Some(entity), true) = (entity, msg.message.len() > 1) {
|
|
|
|
let argv = String::from(&msg.message[1..]);
|
|
|
|
server_emitter.emit(ServerEvent::ChatCmd(entity, argv));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Send chat message
|
|
|
|
server_emitter.emit(ServerEvent::Chat(msg));
|
2019-10-15 04:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-20 07:20:21 +00:00
|
|
|
|
|
|
|
timer.end()
|
2019-10-15 04:06:14 +00:00
|
|
|
}
|
|
|
|
}
|