Moved common networking code to common/net, clippy fixes

This commit is contained in:
Joshua Barretto 2020-12-13 17:11:55 +00:00
parent 7963ad930c
commit f8c8e342e6
99 changed files with 786 additions and 747 deletions

72
Cargo.lock generated
View File

@ -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]]

View File

@ -8,7 +8,6 @@ members = [
"plugin/api",
"plugin/derive",
"client",
"plugin-api",
"server",
"server-cli",
"voxygen",

View File

@ -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"

View File

@ -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,
}),

View File

@ -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"] }

33
common/net/Cargo.toml Normal file
View File

@ -0,0 +1,33 @@
[package]
authors = ["Marcel Märtens <marcel.cochem@googlemail.com>"]
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 }

2
common/net/src/lib.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod msg;
pub mod sync;

View File

@ -1,5 +1,5 @@
use super::PingMsg;
use crate::{
use common::{
character::CharacterId,
comp,
comp::{Skill, SkillGroupType},

View File

@ -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;

View File

@ -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)]

View File

@ -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<sync::Uid>),
@ -121,6 +121,15 @@ pub enum ServerGeneral {
Notification(Notification),
}
impl ServerGeneral {
pub fn server_msg<S>(chat_type: comp::ChatType<String>, msg: S) -> Self
where
S: Into<String>,
{
ServerGeneral::ChatMsg(chat_type.chat_msg(msg))
}
}
/*
end of 2nd level Enums
*/

View File

@ -1,4 +1,4 @@
use crate::grid::Grid;
use common::grid::Grid;
use serde::{Deserialize, Serialize};
use vek::*;

View File

@ -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<ErrorKind>),
}

View File

@ -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<PathBuf>,
dependencies: HashSet<String>,
}
#[derive(Clone)]
pub struct Plugin {
data: PluginData,
modules: Vec<PluginModule>,
files: HashMap<PathBuf, Vec<u8>>,
}
impl Plugin {
pub fn from_reader<R: Read>(mut reader: R) -> Result<Self, PluginError> {
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::<Result<HashMap<_, _>, _>>()
.map_err(PluginError::Io)?;
let data = toml::de::from_slice::<PluginData>(
&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::<Result<_, _>>()?;
Ok(Plugin {
data,
modules,
files,
})
}
pub fn execute_prepared<T>(&self, event_name: &str, event: &PreparedEventQuery<T>) -> Result<Vec<T::Response>, 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::<Result<Vec<_>,_>>()
}
}
#[derive(Clone, Default)]
pub struct PluginMgr {
plugins: Vec<Plugin>,
}
impl PluginMgr {
pub fn from_assets() -> Result<Self, PluginError> {
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<T>(&self, event_name: &str,event: &PreparedEventQuery<T>) -> Result<Vec<T::Response>, PluginError> where T: Event {
Ok(self.plugins.par_iter().map(|plugin| {
plugin.execute_prepared(event_name, event)
}).collect::<Result<Vec<_>,_>>()?.into_iter().flatten().collect())
}
pub fn execute_event<T>(&self, event_name: &str,event: &T) -> Result<Vec<T::Response>, PluginError> where T: Event {
self.execute_prepared(event_name, &PreparedEventQuery::new(event)?)
}
pub fn from_dir<P: AsRef<Path>>(path: P) -> Result<Self, PluginError> {
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::<Result<Vec<_>, _>>()?;
for plugin in &plugins {
info!(
"Loaded plugin '{}' with {} module(s)",
plugin.data.name,
plugin.modules.len()
);
}
Ok(Self { plugins })
}
}

View File

@ -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<Mutex<Instance>>,
events: HashSet<String>,
}
impl PluginModule {
// This function takes bytes from a WASM File and compile them
pub fn new(wasm_data: &Vec<u8>) -> Result<Self,PluginModuleError> {
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<T>(
&self,
event_name: &str,
request: &PreparedEventQuery<T>,
) -> Option<Result<T::Response,PluginModuleError>>
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<T> {
bytes: Vec<u8>,
_phantom: PhantomData<T>,
}
impl<T: Event> PreparedEventQuery<T> {
// 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<Self, PluginError>
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<Vec<u8>, RuntimeError> {
let view = memory.view::<u8>();
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::<u8>();
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::<u8>();
let str_slice = &memory[ptr as usize..(ptr + len) as usize];
let bytes: Vec<u8> = str_slice.iter().map(|x| x.get()).collect();
let e: Vec<Action> = 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);
}
}
}
}

View File

@ -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};

View File

@ -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::{

View File

@ -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,

View File

@ -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},

View File

@ -1,6 +1,6 @@
use crate::{
comp::{HealthChange, HealthSource, Loadout},
sync::Uid,
uid::Uid,
util::Dir,
};
use serde::{Deserialize, Serialize};

View File

@ -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;

View File

@ -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;

View File

@ -1,4 +1,4 @@
use crate::sync::Uid;
use crate::uid::Uid;
use serde::{Deserialize, Serialize};
use specs::{Component, FlaggedStorage};
use specs_idvs::IdvStorage;

View File

@ -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<G> ChatType<G> {
}
}
}
impl ChatType<String> {
pub fn server_msg<S>(self, msg: S) -> ServerGeneral
where
S: Into<String>,
{
ServerGeneral::ChatMsg(self.chat_msg(msg))
}
}
// Stores chat text, type
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenericChatMsg<G> {

View File

@ -1,6 +1,6 @@
use crate::{
comp::{inventory::slot::Slot, BuffKind},
sync::Uid,
uid::Uid,
util::Dir,
};
use serde::{Deserialize, Serialize};

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,4 +1,4 @@
use authc::Uuid;
use uuid::Uuid;
use serde::{Deserialize, Serialize};
use specs::{Component, FlaggedStorage, NullStorage};
use specs_idvs::IdvStorage;

View File

@ -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};

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -5,7 +5,7 @@ use crate::{
behavior::{CharacterBehavior, JoinData},
utils::*,
},
sync::Uid,
uid::Uid,
Damage, DamageSource, GroupTarget,
};
use serde::{Deserialize, Serialize};

View File

@ -4,7 +4,7 @@ use crate::{
Health, Loadout, Ori, PhysicsState, Pos, StateUpdate, Vel,
},
resources::DeltaTime,
sync::Uid,
uid::Uid,
};
use specs::{
hibitset,

View File

@ -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`

View File

@ -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.
///

View File

@ -1,12 +1,9 @@
[package]
authors = ["Marcel Märtens <marcel.cochem@googlemail.com>"]
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"

View File

@ -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,

View File

@ -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};

View File

@ -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};

View File

@ -7,7 +7,7 @@ use common::{
metrics::SysMetrics,
resources::DeltaTime,
span,
sync::{Uid, UidAllocator},
uid::{Uid, UidAllocator},
};
use specs::{
saveload::{Marker, MarkerAllocator},

View File

@ -3,7 +3,7 @@ use common::{
event::{EventBus, LocalEvent, ServerEvent},
metrics::SysMetrics,
span,
sync::Uid,
uid::Uid,
util::Dir,
GroupTarget,
};

View File

@ -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},

View File

@ -8,7 +8,7 @@ use common::{
metrics::{PhysicsMetrics, SysMetrics},
resources::DeltaTime,
span,
sync::Uid,
uid::Uid,
terrain::{Block, TerrainGrid},
vol::ReadVol,
};

View File

@ -8,7 +8,7 @@ use common::{
metrics::SysMetrics,
resources::DeltaTime,
span,
sync::UidAllocator,
uid::UidAllocator,
GroupTarget,
};
use rand::{thread_rng, Rng};

View File

@ -5,7 +5,7 @@ use common::{
},
event::{EventBus, LocalEvent, ServerEvent},
resources::{DeltaTime, Time},
sync::{Uid, UidAllocator},
uid::{Uid, UidAllocator},
util::Dir,
GroupTarget,
};

View File

@ -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::{

View File

@ -77,7 +77,7 @@ impl RemoteInfo {
}
}
pub fn get_info(&self, id: u32) -> Option<FileInfo> { self.infos.get(&id).map(|fi| fi.clone()) }
pub fn get_info(&self, id: u32) -> Option<FileInfo> { self.infos.get(&id).cloned() }
pub fn insert_infos(&mut self, mut fi: Vec<FileInfo>) {
for fi in fi.drain(..) {

View File

@ -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<LocalCommand>) {
// 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
}

View File

@ -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<FileInfo>) {
fn print_fileinfos(infos: &[FileInfo]) {
let mut i = 0;
for info in infos {
let bytes = info.size;

View File

@ -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;

View File

@ -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");

View File

@ -24,7 +24,7 @@ fn setup() -> Result<SocketAddr, u32> {
}
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

View File

@ -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)]

354
plugin/hello/Cargo.lock generated
View File

@ -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"

View File

@ -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<Vec<String>, 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 {

View File

@ -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"

View File

@ -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

View File

@ -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 }

View File

@ -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;

View File

@ -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::<comp::Body>().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("<Unknown object>")
)),
@ -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::<comp::Waypoint>()
.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::<comp::Stats>().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()),
);
}
}

View File

@ -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()));
}
}

View File

@ -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::<sync::Uid>();
let uids = state.ecs().read_storage::<Uid>();
// 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(
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::<Client>();
let uids = state.ecs().read_storage::<sync::Uid>();
let uids = state.ecs().read_storage::<Uid>();
let mut invites = state.ecs().write_storage::<Invite>();
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::<Client>();
let uids = state.ecs().read_storage::<sync::Uid>();
let uids = state.ecs().read_storage::<Uid>();
let mut invites = state.ecs().write_storage::<Invite>();
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::<Client>();
let uids = state.ecs().read_storage::<sync::Uid>();
let uids = state.ecs().read_storage::<Uid>();
let mut group_manager = state.ecs().write_resource::<GroupManager>();
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::<Client>();
let uids = state.ecs().read_storage::<sync::Uid>();
let uids = state.ecs().read_storage::<Uid>();
let alignments = state.ecs().read_storage::<comp::Alignment>();
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::<Client>();
let uids = state.ecs().read_storage::<sync::Uid>();
let uids = state.ecs().read_storage::<Uid>();
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.",
));
}
},

View File

@ -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;

View File

@ -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;

View File

@ -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::<Uid>().get(entity),
state.read_storage::<comp::Player>().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,

View File

@ -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
))

View File

@ -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};

View File

@ -1,4 +1,4 @@
use common::msg::PresenceKind;
use common_net::msg::PresenceKind;
use hashbrown::HashSet;
use serde::{Deserialize, Serialize};
use specs::{Component, FlaggedStorage};

View File

@ -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::{

View File

@ -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,
};

View File

@ -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

View File

@ -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) {

View File

@ -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};

View File

@ -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};

View File

@ -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};

View File

@ -4,12 +4,12 @@ use crate::{
};
use common::{
comp::{Admin, Player, Stats},
msg::{
span,
uid::Uid,
};
use common_net::msg::{
CharacterInfo, ClientRegister, PlayerInfo, PlayerListUpdate, RegisterError, ServerGeneral,
ServerRegisterAnswer,
},
span,
sync::Uid,
};
use hashbrown::HashMap;
use specs::{Entities, Join, ReadExpect, ReadStorage, System, Write, WriteExpect, WriteStorage};

View File

@ -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;

View File

@ -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::{

View File

@ -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,

View File

@ -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};

View File

@ -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};

View File

@ -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

View File

@ -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}

View File

@ -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};

View File

@ -4,13 +4,11 @@ use super::{
};
use crate::{i18n::Localization, ui::fonts::Fonts, GlobalState};
use client::{cmd, Client};
use common::{
comp::{
use common::comp::{
chat::{KillSource, KillType},
ChatMsg, ChatType,
},
msg::validate_chat_msg,
};
use common_net::msg::validate_chat_msg;
use conrod_core::{
input::Key,
position::Dimension,

View File

@ -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::<common::comp::Buffs>();
let uid_allocator = client_state
.ecs()
.read_resource::<common::sync::UidAllocator>();
.read_resource::<UidAllocator>();
// Keep track of the total number of widget ids we are using for buffs
let mut total_buff_count = 0;

View File

@ -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},

View File

@ -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},

View File

@ -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<comp::ChatMsg>,
new_notifications: VecDeque<common::msg::Notification>,
new_notifications: VecDeque<Notification>,
speech_bubbles: HashMap<Uid, comp::SpeechBubble>,
show: Show,
//never_show: bool,
@ -767,7 +767,7 @@ impl Hud {
let buffs = ecs.read_storage::<comp::Buffs>();
let energy = ecs.read_storage::<comp::Energy>();
let hp_floater_lists = ecs.read_storage::<vcomp::HpFloaterList>();
let uids = ecs.read_storage::<common::sync::Uid>();
let uids = ecs.read_storage::<Uid>();
let interpolated = ecs.read_storage::<vcomp::Interpolated>();
let scales = ecs.read_storage::<comp::Scale>();
let bodies = ecs.read_storage::<comp::Body>();
@ -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);
}

View File

@ -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,

View File

@ -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},

View File

@ -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};

View File

@ -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"] }

View File

@ -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;

View File

@ -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,