From f8c8e342e69cdd1049f17311c09ed8788c0112b1 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 13 Dec 2020 17:11:55 +0000 Subject: [PATCH] Moved common networking code to common/net, clippy fixes --- Cargo.lock | 72 +++-- Cargo.toml | 1 - client/Cargo.toml | 3 +- client/src/lib.rs | 19 +- common/Cargo.toml | 5 +- common/net/Cargo.toml | 33 ++ common/net/src/lib.rs | 2 + common/{ => net}/src/msg/client.rs | 2 +- common/{ => net}/src/msg/ecs_packet.rs | 3 +- common/{ => net}/src/msg/mod.rs | 2 +- common/{ => net}/src/msg/server.rs | 21 +- common/{ => net}/src/msg/world_msg.rs | 2 +- common/net/src/plugin/errors.rs | 21 ++ common/net/src/plugin/mod.rs | 138 +++++++++ common/net/src/plugin/module.rs | 150 +++++++++ common/{ => net}/src/sync/mod.rs | 3 +- common/{ => net}/src/sync/packet.rs | 3 +- common/{ => net}/src/sync/sync_ext.rs | 2 +- common/{ => net}/src/sync/track.rs | 6 +- common/src/combat.rs | 2 +- common/src/comp/agent.rs | 2 +- common/src/comp/beam.rs | 2 +- common/src/comp/buff.rs | 2 +- common/src/comp/chat.rs | 11 +- common/src/comp/controller.rs | 2 +- common/src/comp/group.rs | 2 +- common/src/comp/health.rs | 2 +- common/src/comp/misc.rs | 2 +- common/src/comp/phys.rs | 2 +- common/src/comp/player.rs | 2 +- common/src/comp/projectile.rs | 2 +- common/src/comp/shockwave.rs | 2 +- common/src/event.rs | 2 +- common/src/lib.rs | 3 +- common/src/states/basic_beam.rs | 2 +- common/src/states/behavior.rs | 2 +- common/src/states/utils.rs | 4 +- common/src/terrain/map.rs | 2 +- common/src/{sync => }/uid.rs | 0 common/sys/Cargo.toml | 8 +- common/sys/src/agent.rs | 2 +- common/sys/src/beam.rs | 2 +- common/sys/src/character_behavior.rs | 2 +- common/sys/src/controller.rs | 2 +- common/sys/src/melee.rs | 2 +- common/sys/src/mount.rs | 2 +- common/sys/src/phys.rs | 2 +- common/sys/src/projectile.rs | 2 +- common/sys/src/shockwave.rs | 2 +- common/sys/src/state.rs | 2 +- network/examples/fileshare/commands.rs | 2 +- network/examples/fileshare/main.rs | 4 +- network/examples/fileshare/server.rs | 14 +- network/examples/network-speed/main.rs | 2 +- network/examples/network-speed/metrics.rs | 8 +- network/examples/tcp_loadtest.rs | 2 +- plugin/api/src/lib.rs | 6 +- plugin/hello/Cargo.lock | 354 +--------------------- plugin/hello/src/lib.rs | 16 +- server-cli/Cargo.toml | 1 + server-cli/src/shutdown_coordinator.rs | 3 +- server/Cargo.toml | 3 +- server/src/client.rs | 2 +- server/src/cmd.rs | 244 ++++++++------- server/src/events/entity_manipulation.rs | 9 +- server/src/events/group_manip.rs | 143 ++++----- server/src/events/interaction.rs | 4 +- server/src/events/inventory_manip.rs | 4 +- server/src/events/player.rs | 6 +- server/src/lib.rs | 15 +- server/src/login_provider.rs | 2 +- server/src/presence.rs | 2 +- server/src/state_ext.rs | 7 +- server/src/sys/entity_sync.rs | 4 +- server/src/sys/invite_timeout.rs | 4 +- server/src/sys/msg/character_screen.rs | 9 +- server/src/sys/msg/general.rs | 4 +- server/src/sys/msg/in_game.rs | 2 +- server/src/sys/msg/ping.rs | 2 +- server/src/sys/msg/register.rs | 10 +- server/src/sys/persistence.rs | 2 +- server/src/sys/sentinel.rs | 7 +- server/src/sys/subscription.rs | 4 +- server/src/sys/terrain.rs | 2 +- server/src/sys/terrain_sync.rs | 3 +- server/src/sys/waypoint.rs | 2 +- voxygen/Cargo.toml | 3 +- voxygen/src/ecs/sys/floater.rs | 2 +- voxygen/src/hud/chat.rs | 10 +- voxygen/src/hud/group.rs | 5 +- voxygen/src/hud/map.rs | 3 +- voxygen/src/hud/minimap.rs | 7 +- voxygen/src/hud/mod.rs | 16 +- voxygen/src/hud/popup.rs | 2 +- voxygen/src/hud/social.rs | 2 +- voxygen/src/session.rs | 2 +- world/Cargo.toml | 3 +- world/src/lib.rs | 2 +- world/src/sim/mod.rs | 2 +- 99 files changed, 786 insertions(+), 747 deletions(-) create mode 100644 common/net/Cargo.toml create mode 100644 common/net/src/lib.rs rename common/{ => net}/src/msg/client.rs (99%) rename common/{ => net}/src/msg/ecs_packet.rs (99%) rename common/{ => net}/src/msg/mod.rs (96%) rename common/{ => net}/src/msg/server.rs (95%) rename common/{ => net}/src/msg/world_msg.rs (99%) create mode 100644 common/net/src/plugin/errors.rs create mode 100644 common/net/src/plugin/mod.rs create mode 100644 common/net/src/plugin/module.rs rename common/{ => net}/src/sync/mod.rs (89%) rename common/{ => net}/src/sync/packet.rs (98%) rename common/{ => net}/src/sync/sync_ext.rs (99%) rename common/{ => net}/src/sync/track.rs (98%) rename common/src/{sync => }/uid.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index f4623ed7b0..44b52c1658 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5531,7 +5531,8 @@ dependencies = [ "uvth 3.1.1", "vek 0.12.0", "veloren-common", - "veloren_common_sys", + "veloren-common-net", + "veloren-common-sys", "veloren_network", ] @@ -5540,7 +5541,6 @@ name = "veloren-common" version = "0.8.0" dependencies = [ "arraygen", - "authc", "criterion", "crossbeam", "csv", @@ -5568,10 +5568,48 @@ dependencies = [ "specs-idvs", "spin_sleep", "structopt", + "tracing", + "tracy-client", + "uuid", + "vek 0.12.0", +] + +[[package]] +name = "veloren-common-net" +version = "0.8.0" +dependencies = [ + "authc", + "hashbrown 0.7.2", + "serde", + "specs", "sum_type", "tracing", "tracy-client", "vek 0.12.0", + "veloren-common", +] + +[[package]] +name = "veloren-common-sys" +version = "0.8.0" +dependencies = [ + "bincode", + "hashbrown 0.7.2", + "indexmap", + "rand 0.7.3", + "rayon", + "serde", + "slab", + "specs", + "tar", + "toml", + "tracing", + "tracy-client", + "vek 0.12.0", + "veloren-common", + "veloren-common-net", + "veloren-plugin-api", + "wasmer-runtime", ] [[package]] @@ -5634,9 +5672,10 @@ dependencies = [ "uvth 3.1.1", "vek 0.12.0", "veloren-common", + "veloren-common-net", + "veloren-common-sys", "veloren-plugin-api", "veloren-world", - "veloren_common_sys", "veloren_network", ] @@ -5657,6 +5696,7 @@ dependencies = [ "tracing-tracy", "tui", "veloren-common", + "veloren-common-net", "veloren-server", ] @@ -5716,10 +5756,11 @@ dependencies = [ "vek 0.12.0", "veloren-client", "veloren-common", + "veloren-common-net", + "veloren-common-sys", "veloren-server", "veloren-voxygen-anim", "veloren-world", - "veloren_common_sys", "window_clipboard", "winit", "winres", @@ -5766,28 +5807,7 @@ dependencies = [ "tracing-subscriber", "vek 0.12.0", "veloren-common", -] - -[[package]] -name = "veloren_common_sys" -version = "0.8.0" -dependencies = [ - "bincode", - "hashbrown 0.7.2", - "indexmap", - "rand 0.7.3", - "rayon", - "serde", - "slab", - "specs", - "tar", - "toml", - "tracing", - "tracy-client", - "vek 0.12.0", - "veloren-common", - "veloren-plugin-api", - "wasmer-runtime", + "veloren-common-net", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 4689614679..465694a3b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ members = [ "plugin/api", "plugin/derive", "client", - "plugin-api", "server", "server-cli", "voxygen", diff --git a/client/Cargo.toml b/client/Cargo.toml index d1f4ff721e..668150da6d 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -11,7 +11,8 @@ default = ["simd"] [dependencies] common = { package = "veloren-common", path = "../common", features = ["no-assets"] } -common_sys = { package = "veloren_common_sys", path = "../common/sys", default-features = false } +common-sys = { package = "veloren-common-sys", path = "../common/sys", default-features = false } +common-net = { package = "veloren-common-net", path = "../common/net" } network = { package = "veloren_network", path = "../network", features = ["compression"], default-features = false } byteorder = "1.3.2" diff --git a/client/src/lib.rs b/client/src/lib.rs index 6a982ace1f..7a40bf5aff 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -25,20 +25,23 @@ use common::{ }, event::{EventBus, LocalEvent}, grid::Grid, - msg::{ - validate_chat_msg, world_msg::SiteInfo, ChatMsgValidationError, ClientGeneral, ClientMsg, - ClientRegister, ClientType, DisconnectReason, InviteAnswer, Notification, PingMsg, - PlayerInfo, PlayerListUpdate, PresenceKind, RegisterError, ServerGeneral, ServerInfo, - ServerInit, ServerRegisterAnswer, MAX_BYTES_CHAT_MSG, - }, outcome::Outcome, recipe::RecipeBook, span, - sync::{Uid, UidAllocator, WorldSyncExt}, + uid::{Uid, UidAllocator}, terrain::{block::Block, neighbors, BiomeKind, SitesKind, TerrainChunk, TerrainChunkSize}, vol::RectVolSize, }; use common_sys::state::State; +use common_net::{ + msg::{ + self, validate_chat_msg, world_msg::SiteInfo, ChatMsgValidationError, ClientGeneral, ClientMsg, + ClientRegister, ClientType, DisconnectReason, InviteAnswer, Notification, PingMsg, + PlayerInfo, PlayerListUpdate, PresenceKind, RegisterError, ServerGeneral, ServerInfo, + ServerInit, ServerRegisterAnswer, MAX_BYTES_CHAT_MSG, + }, + sync::WorldSyncExt, +}; use comp::BuffKind; use futures_executor::block_on; use futures_timer::Delay; @@ -1247,7 +1250,7 @@ impl Client { ServerGeneral::PlayerListUpdate(PlayerListUpdate::LevelChange(uid, next_level)) => { if let Some(player_info) = self.player_list.get_mut(&uid) { player_info.character = match &player_info.character { - Some(character) => Some(common::msg::CharacterInfo { + Some(character) => Some(msg::CharacterInfo { name: character.name.to_string(), level: next_level, }), diff --git a/common/Cargo.toml b/common/Cargo.toml index 23e77ffcae..b71bb79487 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -24,9 +24,9 @@ rand = "0.7" rayon = "1.3.0" roots = "0.0.6" spin_sleep = "1.0" -sum_type = "0.2.0" tracing = { version = "0.1", default-features = false } vek = { version = "0.12.0", features = ["serde"] } +uuid = { version = "0.8.1", default-features = false, features = ["serde", "v4"] } # Assets directories-next = "2.0" @@ -34,9 +34,6 @@ dot_vox = "4.0" image = { version = "0.23.8", default-features = false, features = ["png"] } notify = "5.0.0-pre.3" -# Auth -authc = { git = "https://gitlab.com/veloren/auth.git", rev = "b943c85e4a38f5ec60cd18c34c73097640162bfe" } - # Data structures hashbrown = { version = "0.7.2", features = ["rayon", "serde", "nightly"] } slotmap = { version = "0.4.0", features = ["serde", "unstable"] } diff --git a/common/net/Cargo.toml b/common/net/Cargo.toml new file mode 100644 index 0000000000..ed783f74c3 --- /dev/null +++ b/common/net/Cargo.toml @@ -0,0 +1,33 @@ +[package] +authors = ["Marcel Märtens "] +edition = "2018" +name = "veloren-common-net" +version = "0.8.0" + +[features] +tracy = ["tracy-client"] +simd = ["vek/platform_intrinsics"] + +default = ["simd"] + +[dependencies] +common = {package = "veloren-common", path = "../../common"} + +sum_type = "0.2.0" +vek = { version = "0.12.0", features = ["serde"] } +tracing = { version = "0.1", default-features = false } + +# Data structures +hashbrown = { version = "0.7.2", features = ["rayon", "serde", "nightly"] } + +# Auth +authc = { git = "https://gitlab.com/veloren/auth.git", rev = "b943c85e4a38f5ec60cd18c34c73097640162bfe" } + +# ECS +specs = { git = "https://github.com/amethyst/specs.git", features = ["serde", "storage-event-control"], rev = "7a2e348ab2223818bad487695c66c43db88050a5" } + +# Serde +serde = { version = "1.0.110", features = ["derive"] } + +# Tracy +tracy-client = { version = "0.9.0", optional = true } diff --git a/common/net/src/lib.rs b/common/net/src/lib.rs new file mode 100644 index 0000000000..71446d5515 --- /dev/null +++ b/common/net/src/lib.rs @@ -0,0 +1,2 @@ +pub mod msg; +pub mod sync; diff --git a/common/src/msg/client.rs b/common/net/src/msg/client.rs similarity index 99% rename from common/src/msg/client.rs rename to common/net/src/msg/client.rs index c9c5bb1fba..60266156b5 100644 --- a/common/src/msg/client.rs +++ b/common/net/src/msg/client.rs @@ -1,5 +1,5 @@ use super::PingMsg; -use crate::{ +use common::{ character::CharacterId, comp, comp::{Skill, SkillGroupType}, diff --git a/common/src/msg/ecs_packet.rs b/common/net/src/msg/ecs_packet.rs similarity index 99% rename from common/src/msg/ecs_packet.rs rename to common/net/src/msg/ecs_packet.rs index 3cacc2dab1..fe14d85154 100644 --- a/common/src/msg/ecs_packet.rs +++ b/common/net/src/msg/ecs_packet.rs @@ -1,4 +1,5 @@ -use crate::{comp, sync}; +use common::comp; +use crate::sync; use serde::{Deserialize, Serialize}; use std::marker::PhantomData; use sum_type::sum_type; diff --git a/common/src/msg/mod.rs b/common/net/src/msg/mod.rs similarity index 96% rename from common/src/msg/mod.rs rename to common/net/src/msg/mod.rs index 4580088795..667038ac78 100644 --- a/common/src/msg/mod.rs +++ b/common/net/src/msg/mod.rs @@ -13,7 +13,7 @@ pub use self::{ }, world_msg::WorldMapMsg, }; -use crate::character::CharacterId; +use common::character::CharacterId; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] diff --git a/common/src/msg/server.rs b/common/net/src/msg/server.rs similarity index 95% rename from common/src/msg/server.rs rename to common/net/src/msg/server.rs index 8101b1284e..c8a40a5eec 100644 --- a/common/src/msg/server.rs +++ b/common/net/src/msg/server.rs @@ -1,14 +1,14 @@ use super::{ClientType, EcsCompPacket, PingMsg}; -use crate::{ - character::CharacterItem, +use common::{ + character::{self, CharacterItem}, comp, outcome::Outcome, recipe::RecipeBook, resources::TimeOfDay, - sync, - sync::Uid, + uid::Uid, terrain::{Block, TerrainChunk}, }; +use crate::sync; use authc::AuthClientError; use hashbrown::HashMap; use serde::{Deserialize, Serialize}; @@ -55,7 +55,7 @@ pub enum ServerInit { client_timeout: Duration, world_map: crate::msg::world_msg::WorldMapMsg, recipe_book: RecipeBook, - ability_map: crate::comp::item::tool::AbilityMap, + ability_map: comp::item::tool::AbilityMap, }, } @@ -72,7 +72,7 @@ pub enum ServerGeneral { /// An error occurred while creating or deleting a character CharacterActionError(String), /// A new character was created - CharacterCreated(crate::character::CharacterId), + CharacterCreated(character::CharacterId), CharacterSuccess, //Ingame related GroupUpdate(comp::group::ChangeNotification), @@ -121,6 +121,15 @@ pub enum ServerGeneral { Notification(Notification), } +impl ServerGeneral { + pub fn server_msg(chat_type: comp::ChatType, msg: S) -> Self + where + S: Into, + { + ServerGeneral::ChatMsg(chat_type.chat_msg(msg)) + } +} + /* end of 2nd level Enums */ diff --git a/common/src/msg/world_msg.rs b/common/net/src/msg/world_msg.rs similarity index 99% rename from common/src/msg/world_msg.rs rename to common/net/src/msg/world_msg.rs index d6d2d470f4..e0421da899 100644 --- a/common/src/msg/world_msg.rs +++ b/common/net/src/msg/world_msg.rs @@ -1,4 +1,4 @@ -use crate::grid::Grid; +use common::grid::Grid; use serde::{Deserialize, Serialize}; use vek::*; diff --git a/common/net/src/plugin/errors.rs b/common/net/src/plugin/errors.rs new file mode 100644 index 0000000000..ad6bfef789 --- /dev/null +++ b/common/net/src/plugin/errors.rs @@ -0,0 +1,21 @@ +use bincode::ErrorKind; +use wasmer_runtime::error::{ResolveError, RuntimeError}; + +#[derive(Debug)] +pub enum PluginError { + Io(std::io::Error), + Toml(toml::de::Error), + NoConfig, + NoSuchModule, + PluginModuleError(PluginModuleError) +} + +#[derive(Debug)] +pub enum PluginModuleError { + FindFunction(String), + FunctionGet(ResolveError), + Compile(wasmer_runtime::error::CompileError), + Instantiate(wasmer_runtime::error::Error), + RunFunction(RuntimeError), + Encoding(Box), +} \ No newline at end of file diff --git a/common/net/src/plugin/mod.rs b/common/net/src/plugin/mod.rs new file mode 100644 index 0000000000..afc88cd944 --- /dev/null +++ b/common/net/src/plugin/mod.rs @@ -0,0 +1,138 @@ + +pub mod errors; +pub mod module; + +use common::assets::ASSETS_PATH; +use serde::{Deserialize, Serialize}; +use std::{collections::{HashMap, HashSet}, fs, io::Read, path::{Path, PathBuf}}; +use tracing::{error, info}; + +use plugin_api::Event; + +use self::{ errors::PluginError, module::{PluginModule, PreparedEventQuery}}; + +use rayon::prelude::*; + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct PluginData { + name: String, + modules: HashSet, + dependencies: HashSet, +} + +#[derive(Clone)] +pub struct Plugin { + data: PluginData, + modules: Vec, + files: HashMap>, +} + +impl Plugin { + pub fn from_reader(mut reader: R) -> Result { + let mut buf = Vec::new(); + reader.read_to_end(&mut buf).map_err(PluginError::Io)?; + + let mut files = tar::Archive::new(&*buf) + .entries() + .map_err(PluginError::Io)? + .map(|e| { + e.and_then(|e| { + Ok((e.path()?.into_owned(), { + let offset = e.raw_file_position() as usize; + buf[offset..offset + e.size() as usize].to_vec() + })) + }) + }) + .collect::, _>>() + .map_err(PluginError::Io)?; + + let data = toml::de::from_slice::( + &files + .get(Path::new("plugin.toml")) + .ok_or(PluginError::NoConfig)?, + ) + .map_err(PluginError::Toml)?; + + let modules = data + .modules + .iter() + .map(|path| { + let wasm_data = files.remove(path).ok_or(PluginError::NoSuchModule)?; + PluginModule::new(&wasm_data).map_err(|e| PluginError::PluginModuleError(e)) + }) + .collect::>()?; + + Ok(Plugin { + data, + modules, + files, + }) + } + + pub fn execute_prepared(&self, event_name: &str, event: &PreparedEventQuery) -> Result, PluginError> where T: Event { + self.modules.iter().flat_map(|module| { + module.try_execute(event_name, event).map(|x| x.map_err(|e| PluginError::PluginModuleError(e))) + }).collect::,_>>() + } +} + +#[derive(Clone, Default)] +pub struct PluginMgr { + plugins: Vec, +} + +impl PluginMgr { + pub fn from_assets() -> Result { + let mut assets_path = (&*ASSETS_PATH).clone(); + assets_path.push("plugins"); + info!("Searching {:?} for assets...", assets_path); + Self::from_dir(assets_path) + } + + pub fn execute_prepared(&self, event_name: &str,event: &PreparedEventQuery) -> Result, PluginError> where T: Event { + Ok(self.plugins.par_iter().map(|plugin| { + plugin.execute_prepared(event_name, event) + }).collect::,_>>()?.into_iter().flatten().collect()) + } + + pub fn execute_event(&self, event_name: &str,event: &T) -> Result, PluginError> where T: Event { + self.execute_prepared(event_name, &PreparedEventQuery::new(event)?) + } + + pub fn from_dir>(path: P) -> Result { + let plugins = fs::read_dir(path) + .map_err(PluginError::Io)? + .filter_map(|e| e.ok()) + .map(|entry| { + if entry.file_type().map(|ft| ft.is_file()).unwrap_or(false) + && entry + .path() + .file_name() + .and_then(|n| n.to_str()) + .map(|s| s.ends_with(".plugin.tar")) + .unwrap_or(false) + { + info!("Loading plugin at {:?}", entry.path()); + Plugin::from_reader(fs::File::open(entry.path()).map_err(PluginError::Io)?) + .map(Some) + } else { + Ok(None) + } + }) + .filter_map(Result::transpose) + .inspect(|p| { + let _ = p.as_ref().map_err(|e| error!(?e, "Failed to load plugin")); + }) + .collect::, _>>()?; + + for plugin in &plugins { + info!( + "Loaded plugin '{}' with {} module(s)", + plugin.data.name, + plugin.modules.len() + ); + } + + Ok(Self { plugins }) + } +} diff --git a/common/net/src/plugin/module.rs b/common/net/src/plugin/module.rs new file mode 100644 index 0000000000..2610195636 --- /dev/null +++ b/common/net/src/plugin/module.rs @@ -0,0 +1,150 @@ +use std::{ + cell::Cell, + collections::HashSet, + marker::PhantomData, + sync::{Arc, Mutex}, +}; + +use error::RuntimeError; +use wasmer_runtime::*; + +use super::errors::{PluginError, PluginModuleError}; +use plugin_api::{Action, Event}; + +// This represent a WASM function interface +pub type Function<'a> = Func<'a, (i32, u32), i32>; + +#[derive(Clone)] +// This structure represent the WASM State of the plugin. +pub struct PluginModule { + wasm_instance: Arc>, + events: HashSet, +} + +impl PluginModule { + + // This function takes bytes from a WASM File and compile them + pub fn new(wasm_data: &Vec) -> Result { + let module = compile(&wasm_data).map_err(|e| PluginModuleError::Compile(e))?; + let instance = module + .instantiate(&imports! {"env" => { + "raw_emit_actions" => func!(read_action), + }}).map_err(|e| PluginModuleError::Instantiate(e))?; + + Ok(Self { + events: instance.exports.into_iter().map(|(name, _)| name).collect(), + wasm_instance: Arc::new(Mutex::new(instance)), + }) + } + + // This function tries to execute an event for the current module. Will return None if the event doesn't exists + pub fn try_execute( + &self, + event_name: &str, + request: &PreparedEventQuery, + ) -> Option> + where + T: Event, + { + if !self.events.contains(event_name) { + return None; + } + let bytes = { + let instance = self.wasm_instance.lock().unwrap(); + let func = match instance.exports.get(event_name).map_err(|e| PluginModuleError::FunctionGet(e)) { + Ok(e) => e, + Err(e) => return Some(Err(e)) + }; + let mem = instance.context().memory(0); + match execute_raw(&mem, &func, &request.bytes).map_err(|e| PluginModuleError::RunFunction(e)) { + Ok(e) => e, + Err(e) => return Some(Err(e)) + } + }; + Some(bincode::deserialize(&bytes).map_err(|e| PluginModuleError::Encoding(e))) + } +} + +// This structure represent a Pre-encoded event object (Useful to avoid reencoding for each module in every plugin) +pub struct PreparedEventQuery { + bytes: Vec, + _phantom: PhantomData, +} + +impl PreparedEventQuery { + // Create a prepared query from an event reference (Encode to bytes the struct) + // This Prepared Query is used by the `try_execute` method in `PluginModule` + pub fn new(event: &T) -> Result + where + T: Event, + { + Ok(Self { + bytes: bincode::serialize(&event).map_err(|e| PluginError::PluginModuleError(PluginModuleError::Encoding(e)))?, + _phantom: PhantomData::default(), + }) + } +} + +const MEMORY_POS: usize = 100000; + +// This function is not public because this function should not be used without an interface to limit unsafe behaviours +fn execute_raw( + memory: &Memory, + function: &Function, + bytes: &[u8], +) -> Result, RuntimeError> { + let view = memory.view::(); + let len = bytes.len(); + for (cell, byte) in view[MEMORY_POS..len + MEMORY_POS].iter().zip(bytes.iter()) { + cell.set(*byte) + } + let start = function + .call(MEMORY_POS as i32, len as u32)? as usize; + let view = memory.view::(); + let mut new_len_bytes = [0u8; 4]; + // TODO: It is probably better to dirrectly make the new_len_bytes + for i in 0..4 { + new_len_bytes[i] = view.get(i + 1).map(Cell::get).unwrap_or(0); + } + let new_len = u32::from_ne_bytes(new_len_bytes) as usize; + Ok(view[start..start + new_len] + .iter() + .map(|c| c.get()) + .collect()) +} + +pub fn read_action(ctx: &mut Ctx, ptr: u32, len: u32) { + let memory = ctx.memory(0); + + let memory = memory.view::(); + + let str_slice = &memory[ptr as usize..(ptr + len) as usize]; + + let bytes: Vec = str_slice.iter().map(|x| x.get()).collect(); + + let e: Vec = match bincode::deserialize(&bytes) { + Ok(e) => e, + Err(e) => { + tracing::error!(?e, "Can't decode action"); + return; + } + }; + + for action in e { + match action { + Action::ServerClose => { + tracing::info!("Server closed by plugin"); + std::process::exit(-1); + } + Action::Print(e) => { + tracing::info!("{}",e); + } + Action::PlayerSendMessage(a, b) => { + tracing::info!("SendMessage {} -> {}",a,b); + } + Action::KillEntity(e) => { + tracing::info!("Kill Entity {}",e); + } + } + } +} diff --git a/common/src/sync/mod.rs b/common/net/src/sync/mod.rs similarity index 89% rename from common/src/sync/mod.rs rename to common/net/src/sync/mod.rs index 914793c024..72de7392bc 100644 --- a/common/src/sync/mod.rs +++ b/common/net/src/sync/mod.rs @@ -3,7 +3,6 @@ mod packet; mod sync_ext; mod track; -mod uid; // Reexports pub use packet::{ @@ -12,4 +11,4 @@ pub use packet::{ }; pub use sync_ext::WorldSyncExt; pub use track::UpdateTracker; -pub use uid::{Uid, UidAllocator}; +pub use common::uid::{Uid, UidAllocator}; diff --git a/common/src/sync/packet.rs b/common/net/src/sync/packet.rs similarity index 98% rename from common/src/sync/packet.rs rename to common/net/src/sync/packet.rs index ed9d93f4d2..9085a23bd7 100644 --- a/common/src/sync/packet.rs +++ b/common/net/src/sync/packet.rs @@ -1,4 +1,5 @@ -use super::{track::UpdateTracker, uid::Uid}; +use super::track::UpdateTracker; +use common::uid::Uid; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use specs::{Component, Entity, Join, ReadStorage, World, WorldExt}; use std::{ diff --git a/common/src/sync/sync_ext.rs b/common/net/src/sync/sync_ext.rs similarity index 99% rename from common/src/sync/sync_ext.rs rename to common/net/src/sync/sync_ext.rs index 17ac09fff9..332cecd1e3 100644 --- a/common/src/sync/sync_ext.rs +++ b/common/net/src/sync/sync_ext.rs @@ -3,8 +3,8 @@ use super::{ CompPacket, CompSyncPackage, CompUpdateKind, EntityPackage, EntitySyncPackage, StatePackage, }, track::UpdateTracker, - uid::{Uid, UidAllocator}, }; +use common::uid::{Uid, UidAllocator}; use specs::{ saveload::{MarkedBuilder, MarkerAllocator}, world::Builder, diff --git a/common/src/sync/track.rs b/common/net/src/sync/track.rs similarity index 98% rename from common/src/sync/track.rs rename to common/net/src/sync/track.rs index 273160f089..e3cd58c361 100644 --- a/common/src/sync/track.rs +++ b/common/net/src/sync/track.rs @@ -1,7 +1,5 @@ -use super::{ - packet::{CompPacket, CompUpdateKind}, - uid::Uid, -}; +use super::packet::{CompPacket, CompUpdateKind}; +use common::uid::Uid; use specs::{BitSet, Component, Entity, Join, ReadStorage, World, WorldExt}; use std::{ convert::{TryFrom, TryInto}, diff --git a/common/src/combat.rs b/common/src/combat.rs index 91be46af58..a414735cd6 100644 --- a/common/src/combat.rs +++ b/common/src/combat.rs @@ -1,6 +1,6 @@ use crate::{ comp::{HealthChange, HealthSource, Loadout}, - sync::Uid, + uid::Uid, util::Dir, }; use serde::{Deserialize, Serialize}; diff --git a/common/src/comp/agent.rs b/common/src/comp/agent.rs index 05f4189b1b..9f12acadc6 100644 --- a/common/src/comp/agent.rs +++ b/common/src/comp/agent.rs @@ -2,7 +2,7 @@ use crate::{ comp::{humanoid, quadruped_low, quadruped_medium, quadruped_small, Body}, path::Chaser, rtsim::RtSimController, - sync::Uid, + uid::Uid, }; use specs::{Component, Entity as EcsEntity}; use specs_idvs::IdvStorage; diff --git a/common/src/comp/beam.rs b/common/src/comp/beam.rs index 302b4d8437..433d9f1f55 100644 --- a/common/src/comp/beam.rs +++ b/common/src/comp/beam.rs @@ -1,4 +1,4 @@ -use crate::{sync::Uid, Damage, GroupTarget}; +use crate::{uid::Uid, Damage, GroupTarget}; use serde::{Deserialize, Serialize}; use specs::{Component, FlaggedStorage}; use specs_idvs::IdvStorage; diff --git a/common/src/comp/buff.rs b/common/src/comp/buff.rs index c5de02505e..ec803fcbde 100644 --- a/common/src/comp/buff.rs +++ b/common/src/comp/buff.rs @@ -1,4 +1,4 @@ -use crate::sync::Uid; +use crate::uid::Uid; use serde::{Deserialize, Serialize}; use specs::{Component, FlaggedStorage}; use specs_idvs::IdvStorage; diff --git a/common/src/comp/chat.rs b/common/src/comp/chat.rs index 4d5b0f9590..bbba9c8f63 100644 --- a/common/src/comp/chat.rs +++ b/common/src/comp/chat.rs @@ -1,4 +1,4 @@ -use crate::{comp::group::Group, msg::ServerGeneral, sync::Uid}; +use crate::{comp::group::Group, uid::Uid}; use serde::{Deserialize, Serialize}; use specs::Component; use specs_idvs::IdvStorage; @@ -118,14 +118,7 @@ impl ChatType { } } } -impl ChatType { - pub fn server_msg(self, msg: S) -> ServerGeneral - where - S: Into, - { - ServerGeneral::ChatMsg(self.chat_msg(msg)) - } -} + // Stores chat text, type #[derive(Debug, Clone, Serialize, Deserialize)] pub struct GenericChatMsg { diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 8e7c8e8adb..4ac54fbaaa 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -1,6 +1,6 @@ use crate::{ comp::{inventory::slot::Slot, BuffKind}, - sync::Uid, + uid::Uid, util::Dir, }; use serde::{Deserialize, Serialize}; diff --git a/common/src/comp/group.rs b/common/src/comp/group.rs index d7eb39de42..164d491e95 100644 --- a/common/src/comp/group.rs +++ b/common/src/comp/group.rs @@ -1,4 +1,4 @@ -use crate::{comp::Alignment, sync::Uid}; +use crate::{comp::Alignment, uid::Uid}; use hashbrown::HashMap; use serde::{Deserialize, Serialize}; use slab::Slab; diff --git a/common/src/comp/health.rs b/common/src/comp/health.rs index 9cddb6ebe9..f44cdf3972 100644 --- a/common/src/comp/health.rs +++ b/common/src/comp/health.rs @@ -1,4 +1,4 @@ -use crate::{comp::Body, sync::Uid, DamageSource}; +use crate::{comp::Body, uid::Uid, DamageSource}; use serde::{Deserialize, Serialize}; use specs::{Component, FlaggedStorage}; use specs_idvs::IdvStorage; diff --git a/common/src/comp/misc.rs b/common/src/comp/misc.rs index 70bd4748c4..4702f99d09 100644 --- a/common/src/comp/misc.rs +++ b/common/src/comp/misc.rs @@ -1,5 +1,5 @@ use super::item::Reagent; -use crate::sync::Uid; +use crate::uid::Uid; use serde::{Deserialize, Serialize}; use specs::Component; use specs_idvs::IdvStorage; diff --git a/common/src/comp/phys.rs b/common/src/comp/phys.rs index be854c54c6..44fe4614d1 100644 --- a/common/src/comp/phys.rs +++ b/common/src/comp/phys.rs @@ -1,4 +1,4 @@ -use crate::{sync::Uid, util::Dir}; +use crate::{uid::Uid, util::Dir}; use serde::{Deserialize, Serialize}; use specs::{Component, FlaggedStorage, NullStorage}; use specs_idvs::IdvStorage; diff --git a/common/src/comp/player.rs b/common/src/comp/player.rs index d8a5a90307..c7b5773866 100644 --- a/common/src/comp/player.rs +++ b/common/src/comp/player.rs @@ -1,4 +1,4 @@ -use authc::Uuid; +use uuid::Uuid; use serde::{Deserialize, Serialize}; use specs::{Component, FlaggedStorage, NullStorage}; use specs_idvs::IdvStorage; diff --git a/common/src/comp/projectile.rs b/common/src/comp/projectile.rs index bafc001db2..5df64d2d0d 100644 --- a/common/src/comp/projectile.rs +++ b/common/src/comp/projectile.rs @@ -1,7 +1,7 @@ use crate::{ comp::buff::{BuffCategory, BuffData, BuffKind}, effect::{self, BuffEffect}, - sync::Uid, + uid::Uid, Damage, DamageSource, Explosion, GroupTarget, Knockback, RadiusEffect, }; use serde::{Deserialize, Serialize}; diff --git a/common/src/comp/shockwave.rs b/common/src/comp/shockwave.rs index 677ffc43ec..93707cc826 100644 --- a/common/src/comp/shockwave.rs +++ b/common/src/comp/shockwave.rs @@ -1,4 +1,4 @@ -use crate::{sync::Uid, Damage, GroupTarget, Knockback}; +use crate::{uid::Uid, Damage, GroupTarget, Knockback}; use serde::{Deserialize, Serialize}; use specs::{Component, FlaggedStorage}; use specs_idvs::IdvStorage; diff --git a/common/src/event.rs b/common/src/event.rs index 44c9aec7de..42cb2c4c36 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -1,4 +1,4 @@ -use crate::{character::CharacterId, comp, rtsim::RtSimEntity, sync::Uid, util::Dir, Explosion}; +use crate::{character::CharacterId, comp, rtsim::RtSimEntity, uid::Uid, util::Dir, Explosion}; use comp::{ item::{Item, Reagent}, Ori, Pos, diff --git a/common/src/lib.rs b/common/src/lib.rs index 0eb7be1620..a7596a907f 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -34,7 +34,6 @@ pub mod grid; pub mod loadout_builder; pub mod lottery; pub mod metrics; -pub mod msg; pub mod npc; pub mod outcome; pub mod path; @@ -46,11 +45,11 @@ pub mod rtsim; pub mod spiral; pub mod states; pub mod store; -pub mod sync; pub mod terrain; pub mod time; pub mod typed; pub mod util; +pub mod uid; pub mod vol; pub mod volumes; diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index 3877835bbb..1891bf81d2 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -5,7 +5,7 @@ use crate::{ behavior::{CharacterBehavior, JoinData}, utils::*, }, - sync::Uid, + uid::Uid, Damage, DamageSource, GroupTarget, }; use serde::{Deserialize, Serialize}; diff --git a/common/src/states/behavior.rs b/common/src/states/behavior.rs index 97a592be96..aa4b4d7f7c 100644 --- a/common/src/states/behavior.rs +++ b/common/src/states/behavior.rs @@ -4,7 +4,7 @@ use crate::{ Health, Loadout, Ori, PhysicsState, Pos, StateUpdate, Vel, }, resources::DeltaTime, - sync::Uid, + uid::Uid, }; use specs::{ hibitset, diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index d1a7991061..178ae1150f 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -139,7 +139,9 @@ impl Body { ) } - pub fn can_climb(&self) -> bool { matches!(self, Body::Humanoid(_)) } + pub fn can_climb(&self) -> bool { + matches!(self, Body::Humanoid(_)) + } } /// Handles updating `Components` to move player based on state of `JoinData` diff --git a/common/src/terrain/map.rs b/common/src/terrain/map.rs index 8ff78641cc..dcde0db0e3 100644 --- a/common/src/terrain/map.rs +++ b/common/src/terrain/map.rs @@ -147,7 +147,7 @@ impl MapSizeLg { // not technically been stabilized yet, Clippy probably doesn't check for this // case yet. When it can, or when is_some() is stabilized as a `const fn`, // we should deal with this. - #[allow(clippy::redundant_pattern_matching)] + #[allow(clippy::redundant_pattern_matching, clippy::result_unit_err)] /// Construct a new `MapSizeLg`, returning an error if the needed invariants /// do not hold and the vector otherwise. /// diff --git a/common/src/sync/uid.rs b/common/src/uid.rs similarity index 100% rename from common/src/sync/uid.rs rename to common/src/uid.rs diff --git a/common/sys/Cargo.toml b/common/sys/Cargo.toml index db5b266381..28cf8213da 100644 --- a/common/sys/Cargo.toml +++ b/common/sys/Cargo.toml @@ -1,12 +1,9 @@ [package] authors = ["Marcel Märtens "] edition = "2018" -name = "veloren_common_sys" +name = "veloren-common-sys" version = "0.8.0" -[lib] -name = "common_sys" - [features] tracy = ["tracy-client"] simd = ["vek/platform_intrinsics"] @@ -14,7 +11,8 @@ simd = ["vek/platform_intrinsics"] default = ["simd"] [dependencies] -common = {package = "veloren-common", path = "../../common"} +common = { package = "veloren-common", path = ".." } +common-net = { package = "veloren-common-net", path = "../net" } rand = "0.7" rayon = "1.3.0" diff --git a/common/sys/src/agent.rs b/common/sys/src/agent.rs index 774b8967a7..63b49e64e7 100644 --- a/common/sys/src/agent.rs +++ b/common/sys/src/agent.rs @@ -17,7 +17,7 @@ use common::{ path::{Chaser, TraversalConfig}, resources::{DeltaTime, Time, TimeOfDay}, span, - sync::{Uid, UidAllocator}, + uid::{Uid, UidAllocator}, terrain::{Block, TerrainGrid}, time::DayPeriod, util::Dir, diff --git a/common/sys/src/beam.rs b/common/sys/src/beam.rs index d264f0b273..4728b96c70 100644 --- a/common/sys/src/beam.rs +++ b/common/sys/src/beam.rs @@ -5,7 +5,7 @@ use common::{ }, event::{EventBus, ServerEvent}, resources::{DeltaTime, Time}, - sync::{Uid, UidAllocator}, + uid::{Uid, UidAllocator}, GroupTarget, }; use specs::{saveload::MarkerAllocator, Entities, Join, Read, ReadStorage, System, WriteStorage}; diff --git a/common/sys/src/character_behavior.rs b/common/sys/src/character_behavior.rs index 2ed8e53b6b..59151b79e3 100644 --- a/common/sys/src/character_behavior.rs +++ b/common/sys/src/character_behavior.rs @@ -11,7 +11,7 @@ use common::{ self, behavior::{CharacterBehavior, JoinData, JoinTuple}, }, - sync::{Uid, UidAllocator}, + uid::{Uid, UidAllocator}, }; use specs::{Entities, Join, LazyUpdate, Read, ReadExpect, ReadStorage, System, WriteStorage}; diff --git a/common/sys/src/controller.rs b/common/sys/src/controller.rs index 3728640155..07027322f9 100644 --- a/common/sys/src/controller.rs +++ b/common/sys/src/controller.rs @@ -7,7 +7,7 @@ use common::{ metrics::SysMetrics, resources::DeltaTime, span, - sync::{Uid, UidAllocator}, + uid::{Uid, UidAllocator}, }; use specs::{ saveload::{Marker, MarkerAllocator}, diff --git a/common/sys/src/melee.rs b/common/sys/src/melee.rs index 8807dc25d3..3591672b73 100644 --- a/common/sys/src/melee.rs +++ b/common/sys/src/melee.rs @@ -3,7 +3,7 @@ use common::{ event::{EventBus, LocalEvent, ServerEvent}, metrics::SysMetrics, span, - sync::Uid, + uid::Uid, util::Dir, GroupTarget, }; diff --git a/common/sys/src/mount.rs b/common/sys/src/mount.rs index 83a3fda803..8074436567 100644 --- a/common/sys/src/mount.rs +++ b/common/sys/src/mount.rs @@ -2,7 +2,7 @@ use common::{ comp::{Controller, MountState, Mounting, Ori, Pos, Vel}, metrics::SysMetrics, span, - sync::UidAllocator, + uid::UidAllocator, }; use specs::{ saveload::{Marker, MarkerAllocator}, diff --git a/common/sys/src/phys.rs b/common/sys/src/phys.rs index d9246e03c1..5bb5431ede 100644 --- a/common/sys/src/phys.rs +++ b/common/sys/src/phys.rs @@ -8,7 +8,7 @@ use common::{ metrics::{PhysicsMetrics, SysMetrics}, resources::DeltaTime, span, - sync::Uid, + uid::Uid, terrain::{Block, TerrainGrid}, vol::ReadVol, }; diff --git a/common/sys/src/projectile.rs b/common/sys/src/projectile.rs index 0caec44c8d..61bdd1a9ab 100644 --- a/common/sys/src/projectile.rs +++ b/common/sys/src/projectile.rs @@ -8,7 +8,7 @@ use common::{ metrics::SysMetrics, resources::DeltaTime, span, - sync::UidAllocator, + uid::UidAllocator, GroupTarget, }; use rand::{thread_rng, Rng}; diff --git a/common/sys/src/shockwave.rs b/common/sys/src/shockwave.rs index 023c8457b8..2f2df564ff 100644 --- a/common/sys/src/shockwave.rs +++ b/common/sys/src/shockwave.rs @@ -5,7 +5,7 @@ use common::{ }, event::{EventBus, LocalEvent, ServerEvent}, resources::{DeltaTime, Time}, - sync::{Uid, UidAllocator}, + uid::{Uid, UidAllocator}, util::Dir, GroupTarget, }; diff --git a/common/sys/src/state.rs b/common/sys/src/state.rs index 389d528ebe..eafb7770cd 100644 --- a/common/sys/src/state.rs +++ b/common/sys/src/state.rs @@ -5,12 +5,12 @@ use common::{ region::RegionMap, resources::{DeltaTime, Time, TimeOfDay}, span, - sync::WorldSyncExt, terrain::{Block, TerrainChunk, TerrainGrid}, time::DayPeriod, vol::{ReadVol, WriteVol}, resources, }; +use common_net::sync::WorldSyncExt; use hashbrown::{HashMap, HashSet}; use rayon::{ThreadPool, ThreadPoolBuilder}; use specs::{ diff --git a/network/examples/fileshare/commands.rs b/network/examples/fileshare/commands.rs index 0e56c7bcc0..3967631a56 100644 --- a/network/examples/fileshare/commands.rs +++ b/network/examples/fileshare/commands.rs @@ -77,7 +77,7 @@ impl RemoteInfo { } } - pub fn get_info(&self, id: u32) -> Option { self.infos.get(&id).map(|fi| fi.clone()) } + pub fn get_info(&self, id: u32) -> Option { self.infos.get(&id).cloned() } pub fn insert_infos(&mut self, mut fi: Vec) { for fi in fi.drain(..) { diff --git a/network/examples/fileshare/main.rs b/network/examples/fileshare/main.rs index 55df15b586..d4b7b832e7 100644 --- a/network/examples/fileshare/main.rs +++ b/network/examples/fileshare/main.rs @@ -71,7 +71,7 @@ fn file_exists(file: String) -> Result<(), String> { if file.exists() { Ok(()) } else { - Err(format!("File does not exist")) + Err("File does not exist".to_string()) } } @@ -203,7 +203,7 @@ async fn client(mut cmd_sender: mpsc::UnboundedSender) { // this 100 ms is because i am super lazy, and i want to appear the logs before // the next '==>' appears... thread::sleep(Duration::from_millis(100)); - println!(""); + println!(); } thread::sleep(Duration::from_millis(30)); // TODO: still needed for correct shutdown } diff --git a/network/examples/fileshare/server.rs b/network/examples/fileshare/server.rs index 3f0d9601cb..d56b07c116 100644 --- a/network/examples/fileshare/server.rs +++ b/network/examples/fileshare/server.rs @@ -1,3 +1,5 @@ +#![allow(clippy::eval_order_dependence)] + use crate::commands::{Command, FileInfo, LocalCommand, RemoteInfo}; use async_std::{ fs, @@ -58,22 +60,16 @@ impl Server { command_receiver .for_each_concurrent(None, async move |cmd| { match cmd { - LocalCommand::Shutdown => { - println!("Shutting down service"); - return; - }, + LocalCommand::Shutdown => println!("Shutting down service"), LocalCommand::Disconnect => { self.remotes.write().await.clear(); println!("Disconnecting all connections"); - return; }, LocalCommand::Connect(addr) => { println!("Trying to connect to: {:?}", &addr); match self.network.connect(addr.clone()).await { Ok(p) => self.loop_participant(p).await, - Err(e) => { - println!("Failed to connect to {:?}, err: {:?}", &addr, e); - }, + Err(e) => println!("Failed to connect to {:?}, err: {:?}", &addr, e), } }, LocalCommand::Serve(fileinfo) => { @@ -188,7 +184,7 @@ impl Server { } } -fn print_fileinfos(infos: &Vec) { +fn print_fileinfos(infos: &[FileInfo]) { let mut i = 0; for info in infos { let bytes = info.size; diff --git a/network/examples/network-speed/main.rs b/network/examples/network-speed/main.rs index f1ad37efea..5f0617ec68 100644 --- a/network/examples/network-speed/main.rs +++ b/network/examples/network-speed/main.rs @@ -151,7 +151,7 @@ fn client(address: ProtocolAddr) { std::thread::spawn(f); metrics.run("0.0.0.0:59111".parse().unwrap()).unwrap(); - let p1 = block_on(client.connect(address.clone())).unwrap(); //remote representation of p1 + let p1 = block_on(client.connect(address)).unwrap(); //remote representation of p1 let mut s1 = block_on(p1.open(16, Promises::ORDERED | Promises::CONSISTENCY)).unwrap(); //remote representation of s1 let mut last = Instant::now(); let mut id = 0u64; diff --git a/network/examples/network-speed/metrics.rs b/network/examples/network-speed/metrics.rs index 4052c606a9..657a00abf4 100644 --- a/network/examples/network-speed/metrics.rs +++ b/network/examples/network-speed/metrics.rs @@ -8,7 +8,6 @@ use std::{ }, thread, }; -use tiny_http; use tracing::*; pub struct SimpleMetrics { @@ -68,12 +67,11 @@ impl SimpleMetrics { let response = tiny_http::Response::from_string( String::from_utf8(buffer).expect("Failed to parse bytes as a string."), ); - match request.respond(response) { - Err(e) => error!( + if let Err(e) = request.respond(response) { + error!( ?e, "The metrics HTTP server had encountered and error with answering" - ), - _ => (), + ) } } debug!("Stopping tiny_http server to serve metrics"); diff --git a/network/examples/tcp_loadtest.rs b/network/examples/tcp_loadtest.rs index d7f8dd2cc0..9d3d1c6bf1 100644 --- a/network/examples/tcp_loadtest.rs +++ b/network/examples/tcp_loadtest.rs @@ -24,7 +24,7 @@ fn setup() -> Result { } let a: SocketAddr = format!("{}:{}", args[1], args[2]).parse().unwrap(); println!("You provided address: {}", &a); - return Ok(a); + Ok(a) } /// This example file is not running veloren-network at all, /// instead it's just trying to create 4 threads and pump as much bytes as diff --git a/plugin/api/src/lib.rs b/plugin/api/src/lib.rs index 0ffad8f33b..ee93095299 100644 --- a/plugin/api/src/lib.rs +++ b/plugin/api/src/lib.rs @@ -1,5 +1,5 @@ use serde::{Serialize, de::DeserializeOwned, Deserialize}; -use common::{sync, resources}; +use common::uid::Uid; #[derive(Deserialize,Serialize,Debug)] pub enum Action { @@ -13,7 +13,7 @@ pub trait Event: Serialize + DeserializeOwned + Send + Sync{ type Response: Serialize + DeserializeOwned + Send + Sync; } -pub use resources::GameMode; +pub use common::resources::GameMode; pub mod event { use super::*; @@ -32,7 +32,7 @@ pub mod event { #[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] pub struct Player { - pub id: sync::Uid, + pub id: Uid, } #[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] diff --git a/plugin/hello/Cargo.lock b/plugin/hello/Cargo.lock index 22d5d3dbb3..464cb7fe0d 100644 --- a/plugin/hello/Cargo.lock +++ b/plugin/hello/Cargo.lock @@ -39,12 +39,6 @@ dependencies = [ "syn", ] -[[package]] -name = "arrayref" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - [[package]] name = "arrayvec" version = "0.5.2" @@ -57,30 +51,6 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9ff149ed9780025acfdb36862d35b28856bb693ceb451259a7164442f22fdc3" -[[package]] -name = "auth-common" -version = "0.1.0" -source = "git+https://gitlab.com/veloren/auth.git?rev=b943c85e4a38f5ec60cd18c34c73097640162bfe#b943c85e4a38f5ec60cd18c34c73097640162bfe" -dependencies = [ - "rand", - "serde", - "uuid", -] - -[[package]] -name = "authc" -version = "1.0.0" -source = "git+https://gitlab.com/veloren/auth.git?rev=b943c85e4a38f5ec60cd18c34c73097640162bfe#b943c85e4a38f5ec60cd18c34c73097640162bfe" -dependencies = [ - "auth-common", - "fxhash", - "hex", - "rust-argon2", - "serde_json", - "ureq", - "uuid", -] - [[package]] name = "autocfg" version = "1.0.1" @@ -93,12 +63,6 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" -[[package]] -name = "base64" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" - [[package]] name = "bincode" version = "1.3.1" @@ -115,23 +79,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "blake2b_simd" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" -dependencies = [ - "arrayref", - "arrayvec", - "constant_time_eq", -] - -[[package]] -name = "bumpalo" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" - [[package]] name = "bytemuck" version = "1.4.1" @@ -144,12 +91,6 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" -[[package]] -name = "cc" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" - [[package]] name = "cfg-if" version = "0.1.10" @@ -162,12 +103,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chunked_transfer" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7477065d45a8fe57167bf3cf8bcd3729b54cfcb81cca49bda2d038ea89ae82ca" - [[package]] name = "color_quant" version = "1.1.0" @@ -180,12 +115,6 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826" -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - [[package]] name = "crc32fast" version = "1.2.1" @@ -394,16 +323,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "form_urlencoded" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00" -dependencies = [ - "matches", - "percent-encoding", -] - [[package]] name = "fsevent" version = "2.0.2" @@ -439,15 +358,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "getrandom" version = "0.1.15" @@ -493,12 +403,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hex" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" - [[package]] name = "hibitset" version = "0.6.3" @@ -509,17 +413,6 @@ dependencies = [ "rayon", ] -[[package]] -name = "idna" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "image" version = "0.23.12" @@ -580,15 +473,6 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" -[[package]] -name = "js-sys" -version = "0.3.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175" -dependencies = [ - "wasm-bindgen", -] - [[package]] name = "kernel32-sys" version = "0.2.2" @@ -626,12 +510,6 @@ dependencies = [ "cfg-if 0.1.10", ] -[[package]] -name = "matches" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" - [[package]] name = "maybe-uninit" version = "2.0.0" @@ -848,12 +726,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "percent-encoding" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" - [[package]] name = "pin-project-lite" version = "0.2.0" @@ -911,15 +783,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "qstring" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d464fae65fff2680baf48019211ce37aaec0c78e9264c84a3e484717f965104e" -dependencies = [ - "percent-encoding", -] - [[package]] name = "quote" version = "1.0.7" @@ -1011,28 +874,13 @@ dependencies = [ "redox_syscall", ] -[[package]] -name = "ring" -version = "0.16.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "024a1e66fea74c66c66624ee5622a7ff0e4b73a13b4f5c326ddb50c708944226" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin", - "untrusted", - "web-sys", - "winapi 0.3.9", -] - [[package]] name = "ron" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8a58080b7bb83b2ea28c3b7a9a994fd5e310330b7c8ca5258d99b98128ecfe4" dependencies = [ - "base64 0.12.3", + "base64", "bitflags", "serde", ] @@ -1043,17 +891,6 @@ version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84348444bd7ad45729d0c49a4240d7cdc11c9d512c06c5ad1835c1ad4acda6db" -[[package]] -name = "rust-argon2" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" -dependencies = [ - "base64 0.13.0", - "blake2b_simd", - "constant_time_eq", -] - [[package]] name = "rustc_version" version = "0.2.3" @@ -1063,19 +900,6 @@ dependencies = [ "semver", ] -[[package]] -name = "rustls" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b" -dependencies = [ - "base64 0.13.0", - "log", - "ring", - "sct", - "webpki", -] - [[package]] name = "ryu" version = "1.0.5" @@ -1097,16 +921,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "sct" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "semver" version = "0.9.0" @@ -1229,12 +1043,6 @@ dependencies = [ "specs", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin_sleep" version = "1.0.0" @@ -1251,12 +1059,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "sum_type" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da5b4a0c9f3c7c8e891e445a7c776627e208e8bba23ab680798066dd283e6a15" - [[package]] name = "syn" version = "1.0.54" @@ -1268,21 +1070,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "tinyvec" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - [[package]] name = "tracing" version = "0.1.22" @@ -1315,65 +1102,12 @@ dependencies = [ "nom 5.1.2", ] -[[package]] -name = "unicode-bidi" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -dependencies = [ - "matches", -] - -[[package]] -name = "unicode-normalization" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-xid" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - -[[package]] -name = "ureq" -version = "1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "294b85ef5dbc3670a72e82a89971608a1fcc4ed5c7c5a2895230d31a95f0569b" -dependencies = [ - "base64 0.13.0", - "chunked_transfer", - "log", - "once_cell", - "qstring", - "rustls", - "url", - "webpki", - "webpki-roots", -] - -[[package]] -name = "url" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" -dependencies = [ - "form_urlencoded", - "idna", - "matches", - "percent-encoding", -] - [[package]] name = "uuid" version = "0.8.1" @@ -1403,7 +1137,6 @@ name = "veloren-common" version = "0.8.0" dependencies = [ "arraygen", - "authc", "crossbeam", "directories-next", "dot_vox", @@ -1428,8 +1161,8 @@ dependencies = [ "specs", "specs-idvs", "spin_sleep", - "sum_type", "tracing", + "uuid", "vek", ] @@ -1489,89 +1222,6 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -[[package]] -name = "wasm-bindgen" -version = "0.2.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" -dependencies = [ - "cfg-if 1.0.0", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" - -[[package]] -name = "web-sys" -version = "0.3.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "webpki" -version = "0.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "webpki-roots" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82015b7e0b8bad8185994674a13a93306bea76cf5a16c5a181382fd3a5ec2376" -dependencies = [ - "webpki", -] - [[package]] name = "winapi" version = "0.2.8" diff --git a/plugin/hello/src/lib.rs b/plugin/hello/src/lib.rs index e295094ceb..fb0adf41a8 100644 --- a/plugin/hello/src/lib.rs +++ b/plugin/hello/src/lib.rs @@ -1,7 +1,9 @@ extern crate plugin_rt; -use plugin_rt::*; -use plugin_rt::api::{Action, GameMode, event::*}; +use plugin_rt::{ + api::{event::*, Action, GameMode}, + *, +}; #[event_handler] pub fn on_load(load: PluginLoadEvent) { @@ -14,12 +16,18 @@ pub fn on_load(load: PluginLoadEvent) { #[event_handler] pub fn on_command_testplugin(command: ChatCommandEvent) -> Result, String> { - Ok(vec![format!("Player of id {:?} sended command with args {:?}",command.player,command.command_args)]) + Ok(vec![format!( + "Player of id {:?} sended command with args {:?}", + command.player, command.command_args + )]) } #[event_handler] pub fn on_player_join(input: PlayerJoinEvent) -> PlayerJoinResult { - emit_action(Action::PlayerSendMessage(input.player_id,format!("Welcome {} on our server",input.player_name))); + emit_action(Action::PlayerSendMessage( + input.player_id, + format!("Welcome {} on our server", input.player_name), + )); if input.player_name == "Cheater123" { PlayerJoinResult::CloseConnection } else { diff --git a/server-cli/Cargo.toml b/server-cli/Cargo.toml index b5fdae92f2..a343606c53 100644 --- a/server-cli/Cargo.toml +++ b/server-cli/Cargo.toml @@ -12,6 +12,7 @@ tracy = ["common/tracy", "tracing-tracy"] [dependencies] server = { package = "veloren-server", path = "../server", default-features = false } common = { package = "veloren-common", path = "../common" } +common-net = { package = "veloren-common-net", path = "../common/net" } ansi-parser = "0.6" clap = "2.33" diff --git a/server-cli/src/shutdown_coordinator.rs b/server-cli/src/shutdown_coordinator.rs index fa9be90b25..d655809859 100644 --- a/server-cli/src/shutdown_coordinator.rs +++ b/server-cli/src/shutdown_coordinator.rs @@ -1,5 +1,6 @@ use crate::settings::Settings; use common::comp::chat::ChatType; +use common_net::msg::ServerGeneral; use server::Server; use std::{ ops::Add, @@ -155,7 +156,7 @@ impl ShutdownCoordinator { /// Logs and sends a message to all connected clients fn send_msg(server: &mut Server, msg: String) { info!("{}", &msg); - server.notify_players(ChatType::CommandError.server_msg(msg)); + server.notify_players(ServerGeneral::server_msg(ChatType::CommandError, msg)); } /// Converts a `Duration` into text in the format XsXm for example 1 minute diff --git a/server/Cargo.toml b/server/Cargo.toml index f3225ababc..20be34fa50 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -12,7 +12,8 @@ default = ["worldgen", "simd"] [dependencies] common = { package = "veloren-common", path = "../common" } -common_sys = { package = "veloren_common_sys", path = "../common/sys" } +common-sys = { package = "veloren-common-sys", path = "../common/sys" } +common-net = { package = "veloren-common-net", path = "../common/net" } world = { package = "veloren-world", path = "../world" } network = { package = "veloren_network", path = "../network", features = ["metrics", "compression"], default-features = false } diff --git a/server/src/client.rs b/server/src/client.rs index 68a3097f5b..068ae649f6 100644 --- a/server/src/client.rs +++ b/server/src/client.rs @@ -1,4 +1,4 @@ -use common::msg::{ClientType, ServerGeneral, ServerMsg}; +use common_net::msg::{ClientType, ServerGeneral, ServerMsg}; use network::{Message, Participant, Stream, StreamError}; use serde::{de::DeserializeOwned, Serialize}; use specs::Component; diff --git a/server/src/cmd.rs b/server/src/cmd.rs index a4f8924530..a46de0b0e1 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -17,15 +17,18 @@ use common::{ }, effect::Effect, event::{EventBus, ServerEvent}, - msg::{DisconnectReason, Notification, PlayerListUpdate, ServerGeneral}, npc::{self, get_npc_name}, resources::TimeOfDay, - sync::{Uid, WorldSyncExt}, + uid::Uid, terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize}, util::Dir, vol::RectVolSize, Damage, DamageSource, Explosion, LoadoutBuilder, RadiusEffect, }; +use common_net::{ + msg::{DisconnectReason, Notification, PlayerListUpdate, ServerGeneral}, + sync::WorldSyncExt, +}; use rand::Rng; use specs::{Builder, Entity as EcsEntity, Join, WorldExt}; use std::{convert::TryFrom, time::Duration}; @@ -45,7 +48,7 @@ impl ChatCommandExt for ChatCommand { if self.needs_admin() && !server.entity_is_admin(entity) { server.notify_client( entity, - ChatType::CommandError.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandError, format!( "You don't have permission to use '/{}'.", self.keyword() )), @@ -147,7 +150,7 @@ fn handle_give_item( if inv.push(item).is_some() { server.notify_client( client, - ChatType::CommandError.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandError, format!( "Player inventory full. Gave 0 of {} items.", give_amount )), @@ -166,7 +169,7 @@ fn handle_give_item( if inv.push(item.duplicate()).is_some() { server.notify_client( client, - ChatType::CommandError.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandError, format!( "Player inventory full. Gave {} of {} items.", i, give_amount )), @@ -188,13 +191,13 @@ fn handle_give_item( } else { server.notify_client( client, - ChatType::CommandError.server_msg(format!("Invalid item: {}", item_name)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Invalid item: {}", item_name)), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -215,19 +218,19 @@ fn handle_make_block( ), None => server.notify_client( client, - ChatType::CommandError.server_msg(String::from("You have no position.")), + ServerGeneral::server_msg(ChatType::CommandError, String::from("You have no position.")), ), } } else { server.notify_client( client, - ChatType::CommandError.server_msg(format!("Invalid block kind: {}", block_name)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Invalid block kind: {}", block_name)), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -254,19 +257,19 @@ fn handle_make_sprite( }, None => server.notify_client( client, - ChatType::CommandError.server_msg(String::from("You have no position.")), + ServerGeneral::server_msg(ChatType::CommandError, String::from("You have no position.")), ), } } else { server.notify_client( client, - ChatType::CommandError.server_msg(format!("Invalid sprite kind: {}", sprite_name)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Invalid sprite kind: {}", sprite_name)), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -280,7 +283,7 @@ fn handle_motd( ) { server.notify_client( client, - ChatType::CommandError.server_msg((*server.editable_settings().server_description).clone()), + ServerGeneral::server_msg(ChatType::CommandError, (*server.editable_settings().server_description).clone()), ); } @@ -300,7 +303,7 @@ fn handle_set_motd( .edit(data_dir.as_ref(), |d| **d = msg.clone()); server.notify_client( client, - ChatType::CommandError.server_msg(format!("Server description set to \"{}\"", msg)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Server description set to \"{}\"", msg)), ); }, Err(_) => { @@ -310,7 +313,7 @@ fn handle_set_motd( .edit(data_dir.as_ref(), |d| d.clear()); server.notify_client( client, - ChatType::CommandError.server_msg("Removed server description".to_string()), + ServerGeneral::server_msg(ChatType::CommandError, "Removed server description".to_string()), ); }, } @@ -333,7 +336,7 @@ fn handle_jump( }, None => server.notify_client( client, - ChatType::CommandError.server_msg("You have no position."), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position."), ), } } @@ -359,13 +362,13 @@ fn handle_goto( } else { server.notify_client( client, - ChatType::CommandError.server_msg("You have no position."), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position."), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -396,7 +399,7 @@ fn handle_home( } else { server.notify_client( client, - ChatType::CommandError.server_msg("You have no position."), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position."), ); } } @@ -456,8 +459,7 @@ fn handle_time( None => { server.notify_client( client, - ChatType::CommandError - .server_msg(format!("'{}' is not a valid time.", n)), + ServerGeneral::server_msg(ChatType::CommandError, format!("'{}' is not a valid time.", n)), ); return; }, @@ -516,7 +518,7 @@ fn handle_time( Some(time) => format!("It is {}", time.format("%H:%M").to_string()), None => String::from("Unknown Time"), }; - server.notify_client(client, ChatType::CommandInfo.server_msg(msg)); + server.notify_client(client, ServerGeneral::server_msg(ChatType::CommandInfo, msg)); return; }, }; @@ -528,7 +530,7 @@ fn handle_time( { server.notify_client( client, - ChatType::CommandInfo.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandInfo, format!( "Time changed to: {}", new_time.format("%H:%M").to_string(), )), @@ -554,13 +556,13 @@ fn handle_health( } else { server.notify_client( client, - ChatType::CommandError.server_msg("You have no health."), + ServerGeneral::server_msg(ChatType::CommandError, "You have no health."), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg("You must specify health amount!"), + ServerGeneral::server_msg(ChatType::CommandError, "You must specify health amount!"), ); } } @@ -576,14 +578,14 @@ fn handle_alias( // Notify target that an admin changed the alias due to /sudo server.notify_client( target, - ChatType::CommandInfo.server_msg("An admin changed your alias."), + ServerGeneral::server_msg(ChatType::CommandInfo, "An admin changed your alias."), ); return; } if let Ok(alias) = scan_fmt!(&args, &action.arg_fmt(), String) { if !comp::Player::alias_is_valid(&alias) { // Prevent silly aliases - server.notify_client(client, ChatType::CommandError.server_msg("Invalid alias.")); + server.notify_client(client, ServerGeneral::server_msg(ChatType::CommandError, "Invalid alias.")); return; } let old_alias_optional = server @@ -609,15 +611,14 @@ fn handle_alias( // Announce alias change if target has a Body. if ecs.read_storage::().get(target).is_some() { server.state.notify_players( - ChatType::CommandInfo - .server_msg(format!("{} is now known as {}.", old_alias, player.alias)), + ServerGeneral::server_msg(ChatType::CommandInfo, format!("{} is now known as {}.", old_alias, player.alias)), ); } } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -640,11 +641,11 @@ fn handle_tp( } else { server.notify_client( client, - ChatType::CommandError.server_msg("You must specify a player name"), + ServerGeneral::server_msg(ChatType::CommandError, "You must specify a player name"), ); server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); return; }; @@ -656,23 +657,23 @@ fn handle_tp( } else { server.notify_client( client, - ChatType::CommandError.server_msg("Unable to teleport to player!"), + ServerGeneral::server_msg(ChatType::CommandError, "Unable to teleport to player!"), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg("Player not found!"), + ServerGeneral::server_msg(ChatType::CommandError, "Player not found!"), ); server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg("You have no position!"), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position!"), ); } } @@ -791,20 +792,18 @@ fn handle_spawn( if let Some(uid) = server.state.ecs().uid_from_entity(new_entity) { server.notify_client( client, - ChatType::CommandInfo - .server_msg(format!("Spawned entity with ID: {}", uid)), + ServerGeneral::server_msg(ChatType::CommandInfo, format!("Spawned entity with ID: {}", uid)), ); } } server.notify_client( client, - ChatType::CommandInfo - .server_msg(format!("Spawned {} entities", amount)), + ServerGeneral::server_msg(ChatType::CommandInfo, format!("Spawned {} entities", amount)), ); }, None => server.notify_client( client, - ChatType::CommandError.server_msg("You have no position!"), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position!"), ), } } @@ -812,7 +811,7 @@ fn handle_spawn( _ => { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); }, } @@ -851,12 +850,12 @@ fn handle_spawn_training_dummy( server.notify_client( client, - ChatType::CommandInfo.server_msg("Spawned a training dummy"), + ServerGeneral::server_msg(ChatType::CommandInfo, "Spawned a training dummy"), ); }, None => server.notify_client( client, - ChatType::CommandError.server_msg("You have no position!"), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position!"), ), } } @@ -894,12 +893,12 @@ fn handle_spawn_campfire( server.notify_client( client, - ChatType::CommandInfo.server_msg("Spawned a campfire"), + ServerGeneral::server_msg(ChatType::CommandInfo, "Spawned a campfire"), ); }, None => server.notify_client( client, - ChatType::CommandError.server_msg("You have no position!"), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position!"), ), } } @@ -921,7 +920,7 @@ fn handle_players( server.notify_client( client, - ChatType::CommandInfo.server_msg(entity_tuples.join().fold( + ServerGeneral::server_msg(ChatType::CommandInfo, entity_tuples.join().fold( format!("{} online players:", entity_tuples.join().count()), |s, (_, player, stat)| { format!( @@ -956,7 +955,7 @@ fn handle_build( .remove(target); server.notify_client( client, - ChatType::CommandInfo.server_msg("Toggled off build mode!"), + ServerGeneral::server_msg(ChatType::CommandInfo, "Toggled off build mode!"), ); } else { let _ = server @@ -966,7 +965,7 @@ fn handle_build( .insert(target, comp::CanBuild); server.notify_client( client, - ChatType::CommandInfo.server_msg("Toggled on build mode!"), + ServerGeneral::server_msg(ChatType::CommandInfo, "Toggled on build mode!"), ); } } @@ -979,7 +978,7 @@ fn handle_help( action: &ChatCommand, ) { if let Some(cmd) = scan_fmt_some!(&args, &action.arg_fmt(), ChatCommand) { - server.notify_client(client, ChatType::CommandInfo.server_msg(cmd.help_string())); + server.notify_client(client, ServerGeneral::server_msg(ChatType::CommandInfo, cmd.help_string())); } else { let mut message = String::new(); for cmd in CHAT_COMMANDS.iter() { @@ -992,7 +991,7 @@ fn handle_help( for (k, v) in CHAT_SHORTCUTS.iter() { message += &format!(" /{} => /{}", k, v.keyword()); } - server.notify_client(client, ChatType::CommandInfo.server_msg(message)); + server.notify_client(client, ServerGeneral::server_msg(ChatType::CommandInfo, message)); } } @@ -1026,7 +1025,7 @@ fn handle_kill_npcs( } else { "No NPCs on server.".to_string() }; - server.notify_client(client, ChatType::CommandInfo.server_msg(text)); + server.notify_client(client, ServerGeneral::server_msg(ChatType::CommandInfo, text)); } #[allow(clippy::float_cmp)] // TODO: Pending review in #587 @@ -1080,7 +1079,7 @@ fn handle_object( .build(); server.notify_client( client, - ChatType::CommandInfo.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandInfo, format!( "Spawned: {}", obj_str_res.unwrap_or("") )), @@ -1088,13 +1087,13 @@ fn handle_object( } else { return server.notify_client( client, - ChatType::CommandError.server_msg("Object not found!"), + ServerGeneral::server_msg(ChatType::CommandError, "Object not found!"), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg("You have no position!"), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position!"), ); } } @@ -1117,7 +1116,7 @@ fn handle_light( if r < 0.0 || g < 0.0 || b < 0.0 { server.notify_client( client, - ChatType::CommandError.server_msg("cr, cg and cb values mustn't be negative."), + ServerGeneral::server_msg(ChatType::CommandError, "cr, cg and cb values mustn't be negative."), ); return; } @@ -1156,11 +1155,11 @@ fn handle_light( } else { builder.build(); } - server.notify_client(client, ChatType::CommandInfo.server_msg("Spawned object.")); + server.notify_client(client, ServerGeneral::server_msg(ChatType::CommandInfo, "Spawned object.")); } else { server.notify_client( client, - ChatType::CommandError.server_msg("You have no position!"), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position!"), ); } } @@ -1190,24 +1189,24 @@ fn handle_lantern( .into(); server.notify_client( client, - ChatType::CommandInfo.server_msg("You adjusted flame strength and color."), + ServerGeneral::server_msg(ChatType::CommandInfo, "You adjusted flame strength and color."), ); } else { server.notify_client( client, - ChatType::CommandInfo.server_msg("You adjusted flame strength."), + ServerGeneral::server_msg(ChatType::CommandInfo, "You adjusted flame strength."), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg("Please equip a lantern first"), + ServerGeneral::server_msg(ChatType::CommandError, "Please equip a lantern first"), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -1224,13 +1223,13 @@ fn handle_explosion( if power > 512.0 { server.notify_client( client, - ChatType::CommandError.server_msg("Explosion power mustn't be more than 512."), + ServerGeneral::server_msg(ChatType::CommandError, "Explosion power mustn't be more than 512."), ); return; } else if power <= 0.0 { server.notify_client( client, - ChatType::CommandError.server_msg("Explosion power must be more than 0."), + ServerGeneral::server_msg(ChatType::CommandError, "Explosion power must be more than 0."), ); return; } @@ -1262,7 +1261,7 @@ fn handle_explosion( }, None => server.notify_client( client, - ChatType::CommandError.server_msg("You have no position!"), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position!"), ), } } @@ -1282,7 +1281,7 @@ fn handle_waypoint( .ecs() .write_storage::() .insert(target, comp::Waypoint::temp_new(pos.0, *time)); - server.notify_client(client, ChatType::CommandInfo.server_msg("Waypoint saved!")); + server.notify_client(client, ServerGeneral::server_msg(ChatType::CommandInfo, "Waypoint saved!")); server.notify_client( client, ServerGeneral::Notification(Notification::WaypointSaved), @@ -1290,7 +1289,7 @@ fn handle_waypoint( }, None => server.notify_client( client, - ChatType::CommandError.server_msg("You have no position!"), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position!"), ), } } @@ -1333,14 +1332,14 @@ fn handle_adminify( None => { server.notify_client( client, - ChatType::CommandError.server_msg(format!("Player '{}' not found!", alias)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Player '{}' not found!", alias)), ); }, } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -1358,7 +1357,7 @@ fn handle_tell( // This happens when [ab]using /sudo server.notify_client( client, - ChatType::CommandError.server_msg("It's rude to impersonate people"), + ServerGeneral::server_msg(ChatType::CommandError, "It's rude to impersonate people"), ); return; } @@ -1372,7 +1371,7 @@ fn handle_tell( if player == client { server.notify_client( client, - ChatType::CommandError.server_msg("You can't /tell yourself."), + ServerGeneral::server_msg(ChatType::CommandError, "You can't /tell yourself."), ); return; } @@ -1395,13 +1394,13 @@ fn handle_tell( } else { server.notify_client( client, - ChatType::CommandError.server_msg(format!("Player '{}' not found!", alias)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Player '{}' not found!", alias)), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -1417,7 +1416,7 @@ fn handle_faction( // This happens when [ab]using /sudo server.notify_client( client, - ChatType::CommandError.server_msg("It's rude to impersonate people"), + ServerGeneral::server_msg(ChatType::CommandError, "It's rude to impersonate people"), ); return; } @@ -1433,7 +1432,7 @@ fn handle_faction( } else { server.notify_client( client, - ChatType::CommandError.server_msg("Please join a faction with /join_faction"), + ServerGeneral::server_msg(ChatType::CommandError, "Please join a faction with /join_faction"), ); } } @@ -1449,7 +1448,7 @@ fn handle_group( // This happens when [ab]using /sudo server.notify_client( client, - ChatType::CommandError.server_msg("It's rude to impersonate people"), + ServerGeneral::server_msg(ChatType::CommandError, "It's rude to impersonate people"), ); return; } @@ -1465,7 +1464,7 @@ fn handle_group( } else { server.notify_client( client, - ChatType::CommandError.server_msg("Please create a group first"), + ServerGeneral::server_msg(ChatType::CommandError, "Please create a group first"), ); } } @@ -1498,19 +1497,18 @@ fn handle_group_invite( server.notify_client( client, - ChatType::CommandInfo.server_msg(format!("Invited {} to the group.", target_alias)), + ServerGeneral::server_msg(ChatType::CommandInfo, format!("Invited {} to the group.", target_alias)), ); } else { server.notify_client( client, - ChatType::CommandError - .server_msg(format!("Player with alias {} not found", target_alias)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Player with alias {} not found", target_alias)), ) } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -1541,14 +1539,13 @@ fn handle_group_kick( } else { server.notify_client( client, - ChatType::CommandError - .server_msg(format!("Player with alias {} not found", target_alias)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Player with alias {} not found", target_alias)), ) } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -1596,14 +1593,13 @@ fn handle_group_promote( } else { server.notify_client( client, - ChatType::CommandError - .server_msg(format!("Player with alias {} not found", target_alias)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Player with alias {} not found", target_alias)), ) } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -1619,7 +1615,7 @@ fn handle_region( // This happens when [ab]using /sudo server.notify_client( client, - ChatType::CommandError.server_msg("It's rude to impersonate people"), + ServerGeneral::server_msg(ChatType::CommandError, "It's rude to impersonate people"), ); return; } @@ -1647,7 +1643,7 @@ fn handle_say( // This happens when [ab]using /sudo server.notify_client( client, - ChatType::CommandError.server_msg("It's rude to impersonate people"), + ServerGeneral::server_msg(ChatType::CommandError, "It's rude to impersonate people"), ); return; } @@ -1675,7 +1671,7 @@ fn handle_world( // This happens when [ab]using /sudo server.notify_client( client, - ChatType::CommandError.server_msg("It's rude to impersonate people"), + ServerGeneral::server_msg(ChatType::CommandError, "It's rude to impersonate people"), ); return; } @@ -1703,7 +1699,7 @@ fn handle_join_faction( // This happens when [ab]using /sudo server.notify_client( client, - ChatType::CommandError.server_msg("It's rude to impersonate people"), + ServerGeneral::server_msg(ChatType::CommandError, "It's rude to impersonate people"), ); return; } @@ -1749,7 +1745,7 @@ fn handle_join_faction( } else { server.notify_client( client, - ChatType::CommandError.server_msg("Could not find your player alias"), + ServerGeneral::server_msg(ChatType::CommandError, "Could not find your player alias"), ); } } @@ -1764,7 +1760,7 @@ fn handle_debug_column( ) { server.notify_client( client, - ChatType::CommandError.server_msg("Unsupported without worldgen enabled"), + ServerGeneral::server_msg(ChatType::CommandError, "Unsupported without worldgen enabled"), ); } @@ -1786,7 +1782,7 @@ fn handle_debug_column( Some(pos) => wpos = pos.0.xy().map(|x| x as i32), None => server.notify_client( client, - ChatType::CommandError.server_msg(String::from("You have no position.")), + ServerGeneral::server_msg(ChatType::CommandError, String::from("You have no position.")), ), } } @@ -1842,11 +1838,11 @@ spawn_rate {:?} "#, )) }; if let Some(s) = msg_generator() { - server.notify_client(client, ChatType::CommandInfo.server_msg(s)); + server.notify_client(client, ServerGeneral::server_msg(ChatType::CommandInfo, s)); } else { server.notify_client( client, - ChatType::CommandError.server_msg("Not a pregenerated chunk."), + ServerGeneral::server_msg(ChatType::CommandError, "Not a pregenerated chunk."), ); } } @@ -1862,7 +1858,7 @@ fn find_target( .find(|(_, player)| player.alias == alias) .map(|(entity, _)| entity) .ok_or_else(|| { - ChatType::CommandError.server_msg(format!("Player '{}' not found!", alias)) + ServerGeneral::server_msg(ChatType::CommandError, format!("Player '{}' not found!", alias)) }) } else { Ok(fallback) @@ -1889,7 +1885,7 @@ fn handle_give_exp( if let Some(stats) = ecs.write_storage::().get_mut(player) { stats.exp.change_by(exp); } else { - error_msg = Some(ChatType::CommandError.server_msg("Player has no stats!")); + error_msg = Some(ServerGeneral::server_msg(ChatType::CommandError, "Player has no stats!")); } }, Err(e) => { @@ -1940,7 +1936,7 @@ fn handle_set_level( stats.level.set_level(lvl); body_type = Some(stats.body_type); } else { - error_msg = Some(ChatType::CommandError.server_msg("Player has no stats!")); + error_msg = Some(ServerGeneral::server_msg(ChatType::CommandError, "Player has no stats!")); body_type = None; } @@ -1990,7 +1986,7 @@ fn handle_debug( } else { server.notify_client( client, - ChatType::CommandError.server_msg("Debug items not found? Something is very broken."), + ServerGeneral::server_msg(ChatType::CommandError, "Debug items not found? Something is very broken."), ); } } @@ -2028,7 +2024,7 @@ fn handle_remove_lights( }, None => server.notify_client( client, - ChatType::CommandError.server_msg("You have no position."), + ServerGeneral::server_msg(ChatType::CommandError, "You have no position."), ), } @@ -2042,7 +2038,7 @@ fn handle_remove_lights( server.notify_client( client, - ChatType::CommandError.server_msg(format!("Removed {} lights!", size)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Removed {} lights!", size)), ); } @@ -2068,19 +2064,19 @@ fn handle_sudo( } else { server.notify_client( client, - ChatType::CommandError.server_msg("Could not find that player"), + ServerGeneral::server_msg(ChatType::CommandError, "Could not find that player"), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg(format!("Unknown command: /{}", cmd)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Unknown command: /{}", cmd)), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -2094,7 +2090,7 @@ fn handle_version( ) { server.notify_client( client, - ChatType::CommandInfo.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandInfo, format!( "Server is running {}[{}]", common::util::GIT_HASH.to_string(), common::util::GIT_DATE.to_string(), @@ -2119,7 +2115,7 @@ fn handle_whitelist( .map_err(|_| { server.notify_client( client, - ChatType::CommandError.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandError, format!( "Unable to determine UUID for username \"{}\"", &username )), @@ -2136,8 +2132,7 @@ fn handle_whitelist( .edit(server.data_dir().as_ref(), |w| w.insert(uuid)); server.notify_client( client, - ChatType::CommandInfo - .server_msg(format!("\"{}\" added to whitelist", username)), + ServerGeneral::server_msg(ChatType::CommandInfo, format!("\"{}\" added to whitelist", username)), ); } } else if whitelist_action.eq_ignore_ascii_case("remove") { @@ -2148,20 +2143,19 @@ fn handle_whitelist( .edit(server.data_dir().as_ref(), |w| w.remove(&uuid)); server.notify_client( client, - ChatType::CommandInfo - .server_msg(format!("\"{}\" removed from whitelist", username)), + ServerGeneral::server_msg(ChatType::CommandInfo, format!("\"{}\" removed from whitelist", username)), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -2199,7 +2193,7 @@ fn handle_kick( kick_player(server, target_player, &reason); server.notify_client( client, - ChatType::CommandInfo.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandInfo, format!( "Kicked {} from the server with reason: {}", target_alias, reason )), @@ -2207,14 +2201,13 @@ fn handle_kick( } else { server.notify_client( client, - ChatType::CommandError - .server_msg(format!("Player with alias {} not found", target_alias)), + ServerGeneral::server_msg(ChatType::CommandError, format!("Player with alias {} not found", target_alias)), ) } } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -2240,8 +2233,7 @@ fn handle_ban( if server.editable_settings().banlist.contains_key(&uuid) { server.notify_client( client, - ChatType::CommandError - .server_msg(format!("{} is already on the banlist", target_alias)), + ServerGeneral::server_msg(ChatType::CommandError, format!("{} is already on the banlist", target_alias)), ) } else { server @@ -2255,7 +2247,7 @@ fn handle_ban( }); server.notify_client( client, - ChatType::CommandInfo.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandInfo, format!( "Added {} to the banlist with reason: {}", target_alias, reason )), @@ -2274,7 +2266,7 @@ fn handle_ban( } else { server.notify_client( client, - ChatType::CommandError.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandError, format!( "Unable to determine UUID for username \"{}\"", target_alias )), @@ -2283,7 +2275,7 @@ fn handle_ban( } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } @@ -2311,12 +2303,12 @@ fn handle_unban( }); server.notify_client( client, - ChatType::CommandInfo.server_msg(format!("{} was successfully unbanned", username)), + ServerGeneral::server_msg(ChatType::CommandInfo, format!("{} was successfully unbanned", username)), ); } else { server.notify_client( client, - ChatType::CommandError.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandError, format!( "Unable to determine UUID for username \"{}\"", username )), @@ -2325,7 +2317,7 @@ fn handle_unban( } else { server.notify_client( client, - ChatType::CommandError.server_msg(action.help_string()), + ServerGeneral::server_msg(ChatType::CommandError, action.help_string()), ); } } diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 73a85b45f7..b05599e00f 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -14,14 +14,17 @@ use common::{ }, effect::Effect, lottery::Lottery, - msg::{PlayerListUpdate, ServerGeneral}, outcome::Outcome, rtsim::RtSimEntity, - sync::{Uid, UidAllocator, WorldSyncExt}, + uid::{Uid, UidAllocator}, terrain::{Block, TerrainGrid}, vol::ReadVol, Damage, DamageSource, Explosion, GroupTarget, RadiusEffect, }; +use common_net::{ + msg::{PlayerListUpdate, ServerGeneral}, + sync::WorldSyncExt, +}; use common_sys::state::BlockChange; use comp::item::Reagent; use rand::prelude::*; @@ -225,7 +228,7 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc | HealthSource::Unknown => KillSource::Other, }; state - .notify_players(comp::ChatType::Kill(kill_source, *uid).server_msg("".to_string())); + .notify_players(ServerGeneral::server_msg(comp::ChatType::Kill(kill_source, *uid), "".to_string())); } } diff --git a/server/src/events/group_manip.rs b/server/src/events/group_manip.rs index a4af2c0f8a..a42c6c75d6 100644 --- a/server/src/events/group_manip.rs +++ b/server/src/events/group_manip.rs @@ -5,8 +5,10 @@ use common::{ group::{self, Group, GroupManager, Invite, PendingInvites}, ChatType, GroupManip, }, + uid::Uid, +}; +use common_net::{ msg::{InviteAnswer, ServerGeneral}, - sync, sync::WorldSyncExt, }; use specs::world::WorldExt; @@ -31,16 +33,16 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani None => { // Inform of failure if let Some(client) = clients.get(entity) { - client.send_fallible( - ChatType::Meta - .server_msg("Invite failed, target does not exist.".to_owned()), - ); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Invite failed, target does not exist.", + )); } return; }, }; - let uids = state.ecs().read_storage::(); + let uids = state.ecs().read_storage::(); // Check if entity is trying to invite themselves to a group if uids @@ -63,8 +65,9 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani if already_in_same_group { // Inform of failure if let Some(client) = clients.get(entity) { - client.send_fallible(ChatType::Meta.server_msg( - "Invite failed, can't invite someone already in your group".to_owned(), + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Invite failed, can't invite someone already in your group", )); } return; @@ -93,13 +96,12 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani if group_size_limit_reached { // Inform inviter that they have reached the group size limit if let Some(client) = clients.get(entity) { - client.send_fallible( - ChatType::Meta.server_msg( - "Invite failed, pending invites plus current group size have reached \ - the group size limit" - .to_owned(), - ), - ); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Invite failed, pending invites plus current group size have reached \ + the group size limit" + .to_owned(), + )); } return; } @@ -110,10 +112,10 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani if invites.contains(invitee) { // Inform inviter that there is already an invite if let Some(client) = clients.get(entity) { - client.send_fallible( - ChatType::Meta - .server_msg("This player already has a pending invite.".to_owned()), - ); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "This player already has a pending invite.", + )); } return; } @@ -162,9 +164,10 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani } else if agents.contains(invitee) { send_invite(); } else if let Some(client) = clients.get(entity) { - client.send_fallible( - ChatType::Meta.server_msg("Can't invite, not a player or npc".to_owned()), - ); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Can't invite, not a player or npc", + )); } // Notify inviter that the invite is pending @@ -176,7 +179,7 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani }, GroupManip::Accept => { let clients = state.ecs().read_storage::(); - let uids = state.ecs().read_storage::(); + let uids = state.ecs().read_storage::(); let mut invites = state.ecs().write_storage::(); if let Some(inviter) = invites.remove(entity).and_then(|invite| { let inviter = invite.0; @@ -223,7 +226,7 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani }, GroupManip::Decline => { let clients = state.ecs().read_storage::(); - let uids = state.ecs().read_storage::(); + let uids = state.ecs().read_storage::(); let mut invites = state.ecs().write_storage::(); if let Some(inviter) = invites.remove(entity).and_then(|invite| { let inviter = invite.0; @@ -252,7 +255,7 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani }, GroupManip::Leave => { let clients = state.ecs().read_storage::(); - let uids = state.ecs().read_storage::(); + let uids = state.ecs().read_storage::(); let mut group_manager = state.ecs().write_resource::(); group_manager.leave_group( entity, @@ -274,7 +277,7 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani }, GroupManip::Kick(uid) => { let clients = state.ecs().read_storage::(); - let uids = state.ecs().read_storage::(); + let uids = state.ecs().read_storage::(); let alignments = state.ecs().read_storage::(); let target = match state.ecs().entity_from_uid(uid.into()) { @@ -282,10 +285,10 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani None => { // Inform of failure if let Some(client) = clients.get(entity) { - client.send_fallible( - ChatType::Meta - .server_msg("Kick failed, target does not exist.".to_owned()), - ); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Kick failed, target does not exist.", + )); } return; }, @@ -295,19 +298,20 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani if matches!(alignments.get(target), Some(comp::Alignment::Owned(owner)) if uids.get(target).map_or(true, |u| u != owner)) { if let Some(general_stream) = clients.get(entity) { - general_stream.send_fallible( - ChatType::Meta.server_msg("Kick failed, you can't kick pets.".to_owned()), - ); + general_stream.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Kick failed, you can't kick pets.", + )); } return; } // Can't kick yourself if uids.get(entity).map_or(false, |u| *u == uid) { if let Some(client) = clients.get(entity) { - client.send_fallible( - ChatType::Meta - .server_msg("Kick failed, you can't kick yourself.".to_owned()), - ); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Kick failed, you can't kick yourself.", + )); } return; } @@ -341,47 +345,50 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani // Tell them the have been kicked if let Some(client) = clients.get(target) { - client.send_fallible( - ChatType::Meta - .server_msg("You were removed from the group.".to_owned()), - ); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "You were removed from the group.", + )); } // Tell kicker that they were succesful if let Some(client) = clients.get(entity) { - client - .send_fallible(ChatType::Meta.server_msg("Player kicked.".to_owned())); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Player kicked.", + )); } }, Some(_) => { // Inform kicker that they are not the leader if let Some(client) = clients.get(entity) { - client.send_fallible(ChatType::Meta.server_msg( - "Kick failed: You are not the leader of the target's group.".to_owned(), + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Kick failed: You are not the leader of the target's group.", )); } }, None => { // Inform kicker that the target is not in a group if let Some(client) = clients.get(entity) { - client.send_fallible( - ChatType::Meta.server_msg( - "Kick failed: Your target is not in a group.".to_owned(), - ), - ); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Kick failed: Your target is not in a group.", + )); } }, } }, GroupManip::AssignLeader(uid) => { let clients = state.ecs().read_storage::(); - let uids = state.ecs().read_storage::(); + let uids = state.ecs().read_storage::(); let target = match state.ecs().entity_from_uid(uid.into()) { Some(t) => t, None => { // Inform of failure if let Some(client) = clients.get(entity) { - client.send_fallible(ChatType::Meta.server_msg( - "Leadership transfer failed, target does not exist".to_owned(), + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Leadership transfer failed, target does not exist", )); } return; @@ -415,34 +422,34 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani ); // Tell them they are the leader if let Some(client) = clients.get(target) { - client.send_fallible( - ChatType::Meta.server_msg("You are the group leader now.".to_owned()), - ); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "You are the group leader now.", + )); } // Tell the old leader that the transfer was succesful if let Some(client) = clients.get(target) { - client.send_fallible( - ChatType::Meta - .server_msg("You are no longer the group leader.".to_owned()), - ); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "You are no longer the group leader.", + )); } }, Some(_) => { // Inform transferer that they are not the leader if let Some(client) = clients.get(entity) { - client.send_fallible( - ChatType::Meta.server_msg( - "Transfer failed: You are not the leader of the target's group." - .to_owned(), - ), - ); + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Transfer failed: You are not the leader of the target's group.", + )); } }, None => { // Inform transferer that the target is not in a group if let Some(client) = clients.get(entity) { - client.send_fallible(ChatType::Meta.server_msg( - "Transfer failed: Your target is not in a group.".to_owned(), + client.send_fallible(ServerGeneral::server_msg( + ChatType::Meta, + "Transfer failed: Your target is not in a group.", )); } }, diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index 4f322654f1..1f52413494 100644 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -10,9 +10,9 @@ use common::{ Pos, }, consts::MAX_MOUNT_RANGE, - msg::ServerGeneral, - sync::{Uid, WorldSyncExt}, + uid::Uid, }; +use common_net::{msg::ServerGeneral, sync::WorldSyncExt}; use specs::{world::WorldExt, Entity as EcsEntity}; use tracing::error; diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index 013c07ae44..85e7beea5a 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -5,12 +5,12 @@ use common::{ slot::{self, Slot}, }, consts::MAX_PICKUP_RANGE, - msg::ServerGeneral, recipe::default_recipe_book, - sync::{Uid, WorldSyncExt}, + uid::Uid, util::find_dist::{self, FindDist}, vol::ReadVol, }; +use common_net::{msg::ServerGeneral, sync::WorldSyncExt}; use common_sys::state::State; use comp::LightEmitter; use rand::Rng; diff --git a/server/src/events/player.rs b/server/src/events/player.rs index d22790d634..fa9cbc1b8b 100644 --- a/server/src/events/player.rs +++ b/server/src/events/player.rs @@ -6,10 +6,10 @@ use crate::{ use common::{ comp, comp::{group, Player}, - msg::{PlayerListUpdate, PresenceKind, ServerGeneral}, span, - sync::{Uid, UidAllocator}, + uid::{Uid, UidAllocator}, }; +use common_net::msg::{PlayerListUpdate, PresenceKind, ServerGeneral}; use common_sys::state::State; use futures_executor::block_on; use specs::{saveload::MarkerAllocator, Builder, Entity as EcsEntity, WorldExt}; @@ -137,7 +137,7 @@ pub fn handle_client_disconnect(server: &mut Server, entity: EcsEntity) -> Event state.read_storage::().get(entity), state.read_storage::().get(entity), ) { - state.notify_players(comp::ChatType::Offline(*uid).server_msg("")); + state.notify_players(ServerGeneral::server_msg(comp::ChatType::Offline(*uid), "")); state.notify_players(ServerGeneral::PlayerListUpdate(PlayerListUpdate::Remove( *uid, diff --git a/server/src/lib.rs b/server/src/lib.rs index fc6b8c5014..4162e6a8cd 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -51,15 +51,18 @@ use common::{ cmd::ChatCommand, comp::{self, ChatType}, event::{EventBus, ServerEvent}, - msg::{ClientType, DisconnectReason, ServerGeneral, ServerInfo, ServerInit, ServerMsg, WorldMapMsg}, outcome::Outcome, recipe::default_recipe_book, resources::TimeOfDay, rtsim::RtSimEntity, - sync::{Uid, WorldSyncExt}, + uid::Uid, terrain::TerrainChunkSize, vol::{ReadVol, RectVolSize}, }; +use common_net::{ + sync::WorldSyncExt, + msg::{ClientType, DisconnectReason, ServerGeneral, ServerInfo, ServerInit, ServerMsg, WorldMapMsg}, +}; use common_sys::{ state::State, plugin::PluginMgr, @@ -1022,7 +1025,7 @@ impl Server { if e.is_empty() { self.notify_client( entity, - ChatType::CommandError.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandError, format!( "Unknown command '/{}'.\nType '/help' for available commands", kwd )) @@ -1034,14 +1037,14 @@ impl Server { if !e.is_empty() { self.notify_client( entity, - ChatType::CommandInfo.server_msg(e.join("\n")), + ServerGeneral::server_msg(ChatType::CommandInfo, e.join("\n")), ); } }, Err(e) => { self.notify_client( entity, - ChatType::CommandError.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandError, format!( "Error occurred while executing command '/{}'.\n{}", kwd, e @@ -1056,7 +1059,7 @@ impl Server { error!(?e, "Can't execute command {} {}",kwd,args); self.notify_client( entity, - ChatType::CommandError.server_msg(format!( + ServerGeneral::server_msg(ChatType::CommandError, format!( "Internal error while executing '/{}'.\nContact the server administrator", kwd )) diff --git a/server/src/login_provider.rs b/server/src/login_provider.rs index 30d84c510a..e3914f021c 100644 --- a/server/src/login_provider.rs +++ b/server/src/login_provider.rs @@ -1,6 +1,6 @@ use crate::settings::BanRecord; use authc::{AuthClient, AuthClientError, AuthToken, Uuid}; -use common::msg::RegisterError; +use common_net::msg::RegisterError; use hashbrown::{HashMap, HashSet}; use std::str::FromStr; use tracing::{error, info}; diff --git a/server/src/presence.rs b/server/src/presence.rs index 5cba90dd72..c15f9157db 100644 --- a/server/src/presence.rs +++ b/server/src/presence.rs @@ -1,4 +1,4 @@ -use common::msg::PresenceKind; +use common_net::msg::PresenceKind; use hashbrown::HashSet; use serde::{Deserialize, Serialize}; use specs::{Component, FlaggedStorage}; diff --git a/server/src/state_ext.rs b/server/src/state_ext.rs index fb0b6382fb..02c66ca76a 100644 --- a/server/src/state_ext.rs +++ b/server/src/state_ext.rs @@ -6,10 +6,13 @@ use common::{ character::CharacterId, comp, effect::Effect, - msg::{CharacterInfo, PlayerListUpdate, PresenceKind, ServerGeneral}, - sync::{Uid, UidAllocator, WorldSyncExt}, + uid::{Uid, UidAllocator}, util::Dir, }; +use common_net::{ + msg::{CharacterInfo, PlayerListUpdate, PresenceKind, ServerGeneral}, + sync::WorldSyncExt, +}; use common_sys::state::State; use rand::prelude::*; use specs::{ diff --git a/server/src/sys/entity_sync.rs b/server/src/sys/entity_sync.rs index 93a8881be6..7adf7e0cd9 100644 --- a/server/src/sys/entity_sync.rs +++ b/server/src/sys/entity_sync.rs @@ -9,15 +9,15 @@ use crate::{ }; use common::{ comp::{ForceUpdate, Inventory, InventoryUpdate, Last, Ori, Pos, Vel}, - msg::ServerGeneral, outcome::Outcome, region::{Event as RegionEvent, RegionMap}, resources::TimeOfDay, span, - sync::{CompSyncPackage, Uid}, + uid::Uid, terrain::TerrainChunkSize, vol::RectVolSize, }; +use common_net::{msg::ServerGeneral, sync::CompSyncPackage}; use specs::{ Entities, Entity as EcsEntity, Join, Read, ReadExpect, ReadStorage, System, Write, WriteStorage, }; diff --git a/server/src/sys/invite_timeout.rs b/server/src/sys/invite_timeout.rs index 27819c317f..92995fba35 100644 --- a/server/src/sys/invite_timeout.rs +++ b/server/src/sys/invite_timeout.rs @@ -2,10 +2,10 @@ use super::SysTimer; use crate::client::Client; use common::{ comp::group::{Invite, PendingInvites}, - msg::{InviteAnswer, ServerGeneral}, span, - sync::Uid, + uid::Uid, }; +use common_net::msg::{InviteAnswer, ServerGeneral}; use specs::{Entities, Join, ReadStorage, System, Write, WriteStorage}; /// This system removes timed out group invites diff --git a/server/src/sys/msg/character_screen.rs b/server/src/sys/msg/character_screen.rs index d9667b8f1f..ab901c8bf0 100644 --- a/server/src/sys/msg/character_screen.rs +++ b/server/src/sys/msg/character_screen.rs @@ -6,10 +6,10 @@ use crate::{ use common::{ comp::{item::tool::AbilityMap, ChatType, Player, UnresolvedChatMsg}, event::{EventBus, ServerEvent}, - msg::{ClientGeneral, ServerGeneral}, span, - sync::Uid, + uid::Uid, }; +use common_net::msg::{ClientGeneral, ServerGeneral}; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write}; use std::sync::atomic::Ordering; use tracing::{debug, warn}; @@ -62,9 +62,10 @@ impl Sys { // Give the player a welcome message if !editable_settings.server_description.is_empty() { - client.send(ChatType::CommandInfo.server_msg(String::from( + client.send(ServerGeneral::server_msg( + ChatType::CommandInfo, &*editable_settings.server_description, - )))?; + ))?; } if !client.login_msg_sent.load(Ordering::Relaxed) { diff --git a/server/src/sys/msg/general.rs b/server/src/sys/msg/general.rs index a41734dde7..14fb764952 100644 --- a/server/src/sys/msg/general.rs +++ b/server/src/sys/msg/general.rs @@ -3,11 +3,11 @@ use crate::{client::Client, metrics::PlayerMetrics}; use common::{ comp::{ChatMode, Player, UnresolvedChatMsg}, event::{EventBus, ServerEvent}, - msg::{validate_chat_msg, ChatMsgValidationError, ClientGeneral, MAX_BYTES_CHAT_MSG}, resources::Time, span, - sync::Uid, + uid::Uid, }; +use common_net::msg::{validate_chat_msg, ChatMsgValidationError, ClientGeneral, MAX_BYTES_CHAT_MSG}; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write}; use std::sync::atomic::Ordering; use tracing::{debug, error, warn}; diff --git a/server/src/sys/msg/in_game.rs b/server/src/sys/msg/in_game.rs index 78aaf09e9b..d07881725c 100644 --- a/server/src/sys/msg/in_game.rs +++ b/server/src/sys/msg/in_game.rs @@ -3,11 +3,11 @@ use crate::{client::Client, metrics::NetworkRequestMetrics, presence::Presence, use common::{ comp::{CanBuild, ControlEvent, Controller, ForceUpdate, Health, Ori, Pos, Stats, Vel}, event::{EventBus, ServerEvent}, - msg::{ClientGeneral, PresenceKind, ServerGeneral}, span, terrain::{TerrainChunkSize, TerrainGrid}, vol::{ReadVol, RectVolSize}, }; +use common_net::msg::{ClientGeneral, PresenceKind, ServerGeneral}; use common_sys::state::BlockChange; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write, WriteStorage}; use tracing::{debug, trace}; diff --git a/server/src/sys/msg/ping.rs b/server/src/sys/msg/ping.rs index 254af6f4c7..ea12514b1b 100644 --- a/server/src/sys/msg/ping.rs +++ b/server/src/sys/msg/ping.rs @@ -2,10 +2,10 @@ use super::super::SysTimer; use crate::{client::Client, metrics::PlayerMetrics, Settings}; use common::{ event::{EventBus, ServerEvent}, - msg::PingMsg, resources::Time, span, }; +use common_net::msg::PingMsg; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write}; use std::sync::atomic::Ordering; use tracing::{debug, info}; diff --git a/server/src/sys/msg/register.rs b/server/src/sys/msg/register.rs index d072ada6c8..dc8f8f1ef3 100644 --- a/server/src/sys/msg/register.rs +++ b/server/src/sys/msg/register.rs @@ -4,12 +4,12 @@ use crate::{ }; use common::{ comp::{Admin, Player, Stats}, - msg::{ - CharacterInfo, ClientRegister, PlayerInfo, PlayerListUpdate, RegisterError, ServerGeneral, - ServerRegisterAnswer, - }, span, - sync::Uid, + uid::Uid, +}; +use common_net::msg::{ + CharacterInfo, ClientRegister, PlayerInfo, PlayerListUpdate, RegisterError, ServerGeneral, + ServerRegisterAnswer, }; use hashbrown::HashMap; use specs::{Entities, Join, ReadExpect, ReadStorage, System, Write, WriteExpect, WriteStorage}; diff --git a/server/src/sys/persistence.rs b/server/src/sys/persistence.rs index e2e22181cd..ac7053e061 100644 --- a/server/src/sys/persistence.rs +++ b/server/src/sys/persistence.rs @@ -5,9 +5,9 @@ use crate::{ }; use common::{ comp::{Inventory, Loadout, Stats, Waypoint}, - msg::PresenceKind, span, }; +use common_net::msg::PresenceKind; use specs::{Join, ReadExpect, ReadStorage, System, Write}; pub struct Sys; diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs index 283b0b8898..98a8c096a2 100644 --- a/server/src/sys/sentinel.rs +++ b/server/src/sys/sentinel.rs @@ -5,9 +5,12 @@ use common::{ Group, Health, Item, LightEmitter, Loadout, Mass, MountState, Mounting, Ori, Player, Pos, Scale, Shockwave, Stats, Sticky, Vel, }, - msg::EcsCompPacket, span, - sync::{CompSyncPackage, EntityPackage, EntitySyncPackage, Uid, UpdateTracker, WorldSyncExt}, + uid::Uid, +}; +use common_net::{ + msg::EcsCompPacket, + sync::{CompSyncPackage, EntityPackage, EntitySyncPackage, UpdateTracker, WorldSyncExt}, }; use hashbrown::HashMap; use specs::{ diff --git a/server/src/sys/subscription.rs b/server/src/sys/subscription.rs index 1c9be91e09..13fff27f56 100644 --- a/server/src/sys/subscription.rs +++ b/server/src/sys/subscription.rs @@ -8,13 +8,13 @@ use crate::{ }; use common::{ comp::{Ori, Pos, Vel}, - msg::ServerGeneral, region::{region_in_vd, regions_in_vd, Event as RegionEvent, RegionMap}, span, - sync::Uid, + uid::Uid, terrain::TerrainChunkSize, vol::RectVolSize, }; +use common_net::msg::ServerGeneral; use specs::{ Entities, Join, ReadExpect, ReadStorage, System, SystemData, World, WorldExt, Write, WriteStorage, diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index ca3af162e3..ca3b0c357d 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -6,12 +6,12 @@ use common::{ comp::{self, bird_medium, item::tool::AbilityMap, Alignment, Pos}, event::{EventBus, ServerEvent}, generation::get_npc_name, - msg::ServerGeneral, npc::NPC_NAMES, span, terrain::TerrainGrid, LoadoutBuilder, }; +use common_net::msg::ServerGeneral; use common_sys::state::TerrainChanges; use rand::Rng; use specs::{Join, Read, ReadExpect, ReadStorage, System, Write, WriteExpect}; diff --git a/server/src/sys/terrain_sync.rs b/server/src/sys/terrain_sync.rs index 9149706e33..ffbfcfab60 100644 --- a/server/src/sys/terrain_sync.rs +++ b/server/src/sys/terrain_sync.rs @@ -1,6 +1,7 @@ use super::SysTimer; use crate::{client::Client, presence::Presence}; -use common::{comp::Pos, msg::ServerGeneral, span, terrain::TerrainGrid}; +use common::{comp::Pos, span, terrain::TerrainGrid}; +use common_net::msg::ServerGeneral; use common_sys::state::TerrainChanges; use specs::{Join, Read, ReadExpect, ReadStorage, System, Write}; diff --git a/server/src/sys/waypoint.rs b/server/src/sys/waypoint.rs index 012b538c8d..de81c557bf 100644 --- a/server/src/sys/waypoint.rs +++ b/server/src/sys/waypoint.rs @@ -2,10 +2,10 @@ use super::SysTimer; use crate::client::Client; use common::{ comp::{Player, Pos, Waypoint, WaypointArea}, - msg::{Notification, ServerGeneral}, resources::Time, span, }; +use common_net::msg::{Notification, ServerGeneral}; use specs::{Entities, Join, Read, ReadStorage, System, Write, WriteStorage}; /// Cooldown time (in seconds) for "Waypoint Saved" notifications diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index d6a49948db..8862a3f33e 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -21,7 +21,8 @@ default = ["gl", "singleplayer", "native-dialog", "simd"] [dependencies] client = {package = "veloren-client", path = "../client"} common = {package = "veloren-common", path = "../common"} -common_sys = {package = "veloren_common_sys", path = "../common/sys"} +common-net = {package = "veloren-common-net", path = "../common/net"} +common-sys = {package = "veloren-common-sys", path = "../common/sys"} anim = {package = "veloren-voxygen-anim", path = "anim", default-features = false} diff --git a/voxygen/src/ecs/sys/floater.rs b/voxygen/src/ecs/sys/floater.rs index e49d5ae60c..943fbea033 100644 --- a/voxygen/src/ecs/sys/floater.rs +++ b/voxygen/src/ecs/sys/floater.rs @@ -5,7 +5,7 @@ use crate::ecs::{ use common::{ comp::{Health, HealthSource, Pos, Stats}, resources::DeltaTime, - sync::Uid, + uid::Uid, }; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, Write, WriteStorage}; diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index 9fe39ed1cf..ff640bbeed 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -4,13 +4,11 @@ use super::{ }; use crate::{i18n::Localization, ui::fonts::Fonts, GlobalState}; use client::{cmd, Client}; -use common::{ - comp::{ - chat::{KillSource, KillType}, - ChatMsg, ChatType, - }, - msg::validate_chat_msg, +use common::comp::{ + chat::{KillSource, KillType}, + ChatMsg, ChatType, }; +use common_net::msg::validate_chat_msg; use conrod_core::{ input::Key, position::Dimension, diff --git a/voxygen/src/hud/group.rs b/voxygen/src/hud/group.rs index 7afed827d2..f43467ef3c 100644 --- a/voxygen/src/hud/group.rs +++ b/voxygen/src/hud/group.rs @@ -15,8 +15,9 @@ use crate::{ use client::{self, Client}; use common::{ comp::{group::Role, BuffKind, Stats}, - sync::{Uid, WorldSyncExt}, + uid::{Uid, UidAllocator}, }; +use common_net::sync::WorldSyncExt; use conrod_core::{ color, position::{Place, Relative}, @@ -329,7 +330,7 @@ impl<'a> Widget for Group<'a> { let buffs = client_state.ecs().read_storage::(); let uid_allocator = client_state .ecs() - .read_resource::(); + .read_resource::(); // Keep track of the total number of widget ids we are using for buffs let mut total_buff_count = 0; diff --git a/voxygen/src/hud/map.rs b/voxygen/src/hud/map.rs index 4564a4f9da..6faaa7eed2 100644 --- a/voxygen/src/hud/map.rs +++ b/voxygen/src/hud/map.rs @@ -9,7 +9,8 @@ use crate::{ GlobalState, }; use client::{self, Client}; -use common::{comp, msg::world_msg::SiteKind, terrain::TerrainChunkSize, vol::RectVolSize}; +use common::{comp, terrain::TerrainChunkSize, vol::RectVolSize}; +use common_net::msg::world_msg::SiteKind; use conrod_core::{ color, position, widget::{self, Button, Image, Rectangle, Text}, diff --git a/voxygen/src/hud/minimap.rs b/voxygen/src/hud/minimap.rs index e4264dbbed..01880606fc 100644 --- a/voxygen/src/hud/minimap.rs +++ b/voxygen/src/hud/minimap.rs @@ -5,7 +5,12 @@ use super::{ }; use crate::ui::{fonts::Fonts, img_ids}; use client::{self, Client}; -use common::{comp, msg::world_msg::SiteKind, terrain::TerrainChunkSize, vol::RectVolSize}; +use common::{ + comp, + terrain::TerrainChunkSize, + vol::RectVolSize, +}; +use common_net::msg::world_msg::SiteKind; use conrod_core::{ color, position, widget::{self, Button, Image, Rectangle, Text}, diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 3f97949fdb..a276128e71 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -61,13 +61,13 @@ use common::{ item::{ItemDesc, Quality}, BuffKind, }, - msg::PresenceKind, span, - sync::Uid, + uid::Uid, terrain::TerrainChunk, util::srgba_to_linear, vol::RectRasterableVol, }; +use common_net::msg::{PresenceKind, Notification}; use conrod_core::{ text::cursor::Index, widget::{self, Button, Image, Text}, @@ -365,12 +365,12 @@ pub enum Event { ChangeAutoWalkBehavior(PressBehavior), ChangeStopAutoWalkOnInput(bool), CraftRecipe(String), - InviteMember(common::sync::Uid), + InviteMember(Uid), AcceptInvite, DeclineInvite, - KickMember(common::sync::Uid), + KickMember(Uid), LeaveGroup, - AssignLeader(common::sync::Uid), + AssignLeader(Uid), RemoveBuff(BuffKind), } @@ -613,7 +613,7 @@ pub struct Hud { fonts: Fonts, rot_imgs: ImgsRot, new_messages: VecDeque, - new_notifications: VecDeque, + new_notifications: VecDeque, speech_bubbles: HashMap, show: Show, //never_show: bool, @@ -767,7 +767,7 @@ impl Hud { let buffs = ecs.read_storage::(); let energy = ecs.read_storage::(); let hp_floater_lists = ecs.read_storage::(); - let uids = ecs.read_storage::(); + let uids = ecs.read_storage::(); let interpolated = ecs.read_storage::(); let scales = ecs.read_storage::(); let bodies = ecs.read_storage::(); @@ -2439,7 +2439,7 @@ impl Hud { pub fn new_message(&mut self, msg: comp::ChatMsg) { self.new_messages.push_back(msg); } - pub fn new_notification(&mut self, msg: common::msg::Notification) { + pub fn new_notification(&mut self, msg: Notification) { self.new_notifications.push_back(msg); } diff --git a/voxygen/src/hud/popup.rs b/voxygen/src/hud/popup.rs index b1237c53e4..78c44bc085 100644 --- a/voxygen/src/hud/popup.rs +++ b/voxygen/src/hud/popup.rs @@ -1,7 +1,7 @@ use super::Show; use crate::{i18n::Localization, ui::fonts::Fonts}; use client::{self, Client}; -use common::msg::Notification; +use common_net::msg::Notification; use conrod_core::{ widget::{self, Text}, widget_ids, Color, Colorable, Positionable, Widget, WidgetCommon, diff --git a/voxygen/src/hud/social.rs b/voxygen/src/hud/social.rs index 1a5423a330..af0a8c8fa7 100644 --- a/voxygen/src/hud/social.rs +++ b/voxygen/src/hud/social.rs @@ -8,7 +8,7 @@ use crate::{ ui::{fonts::Fonts, ImageFrame, Tooltip, TooltipManager, Tooltipable}, }; use client::{self, Client}; -use common::{comp::group, sync::Uid}; +use common::{comp::group, uid::Uid}; use conrod_core::{ color, widget::{self, Button, Image, Rectangle, Scrollbar, Text}, diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 8b98dbf25d..c5997b0b5d 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -17,7 +17,6 @@ use common::{ comp, comp::{ChatMsg, ChatType, InventoryUpdateEvent, Pos, Vel}, consts::{MAX_MOUNT_RANGE, MAX_PICKUP_RANGE}, - msg::PresenceKind, outcome::Outcome, span, terrain::{Block, BlockKind}, @@ -27,6 +26,7 @@ use common::{ }, vol::ReadVol, }; +use common_net::msg::PresenceKind; use ordered_float::OrderedFloat; use specs::{Join, WorldExt}; use std::{cell::RefCell, rc::Rc, sync::Arc, time::Duration}; diff --git a/world/Cargo.toml b/world/Cargo.toml index 5669873d15..f566c97784 100644 --- a/world/Cargo.toml +++ b/world/Cargo.toml @@ -10,8 +10,9 @@ simd = ["vek/platform_intrinsics"] default = ["simd"] [dependencies] -bincode = "1.2.0" common = { package = "veloren-common", path = "../common" } +common-net = { package = "veloren-common-net", path = "../common/net" } +bincode = "1.2.0" bitvec = "0.17.4" fxhash = "0.2.1" image = { version = "0.23.8", default-features = false, features = ["png"] } diff --git a/world/src/lib.rs b/world/src/lib.rs index 6529a27443..348ba158f6 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -42,10 +42,10 @@ use crate::{ }; use common::{ generation::{ChunkSupplement, EntityInfo}, - msg::{world_msg, WorldMapMsg}, terrain::{Block, BlockKind, SpriteKind, TerrainChunk, TerrainChunkMeta, TerrainChunkSize}, vol::{ReadVol, RectVolSize, WriteVol}, }; +use common_net::msg::{world_msg, WorldMapMsg}; use rand::Rng; use serde::Deserialize; use std::time::Duration; diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index cac34dfe68..adff0cb42c 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -37,7 +37,6 @@ use crate::{ use common::{ assets, grid::Grid, - msg::WorldMapMsg, store::Id, terrain::{ map::MapConfig, uniform_idx_as_vec2, vec2_as_uniform_idx, BiomeKind, MapSizeLg, @@ -45,6 +44,7 @@ use common::{ }, vol::RectVolSize, }; +use common_net::msg::WorldMapMsg; use noise::{ BasicMulti, Billow, Fbm, HybridMulti, MultiFractal, NoiseFn, RangeFunction, RidgedMulti, Seedable, SuperSimplex, Worley,