Merge branch 'plugins' into 'master'

Hide plugins behind a feature flag to resolve Windows CI issue

See merge request veloren/veloren!1639
This commit is contained in:
Joshua Barretto 2020-12-15 12:51:56 +00:00
commit 242ee1d2de
10 changed files with 90 additions and 76 deletions

View File

@ -6,6 +6,7 @@ edition = "2018"
[features]
simd = ["vek/platform_intrinsics"]
plugins = ["common-sys/plugins"]
default = ["simd"]

View File

@ -7,6 +7,7 @@ version = "0.8.0"
[features]
tracy = ["tracy-client"]
simd = ["vek/platform_intrinsics"]
plugins = ["toml", "tar", "wasmer-runtime", "bincode", "plugin-api"]
default = ["simd"]
@ -34,8 +35,8 @@ serde = { version = "1.0.110", features = ["derive"] }
tracy-client = { version = "0.9.0", optional = true }
# Plugins
toml = "0.5.7"
tar = "0.4.30"
wasmer-runtime = "0.17.1"
bincode = "1.3.1"
plugin-api = { package = "veloren-plugin-api", path = "../../plugin/api"}
toml = { version = "0.5.7", optional = true }
tar = { version = "0.4.30", optional = true }
wasmer-runtime = { version = "0.17.1", optional = true }
bincode = { version = "1.3.1", optional = true }
plugin-api = { package = "veloren-plugin-api", path = "../../plugin/api", optional = true }

View File

@ -9,7 +9,7 @@ pub mod controller;
pub mod melee;
mod mount;
pub mod phys;
pub mod plugin;
#[cfg(feature = "plugins")] pub mod plugin;
mod projectile;
mod shockwave;
pub mod state;

View File

@ -104,7 +104,7 @@ 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);
info!("Searching {:?} for plugins...", assets_path);
Self::from_dir(assets_path)
}

View File

@ -1,3 +1,4 @@
#[cfg(feature = "plugins")]
use crate::plugin::PluginMgr;
use common::{
comp,
@ -20,7 +21,6 @@ use specs::{
Component, DispatcherBuilder, Entity as EcsEntity, WorldExt,
};
use std::{sync::Arc, time::Duration};
use tracing::info;
use vek::*;
/// How much faster should an in-game day be compared to a real day?
@ -191,13 +191,16 @@ impl State {
ecs.insert(PhysicsMetrics::default());
// Load plugins from asset directory
#[cfg(feature = "plugins")]
ecs.insert(match PluginMgr::from_assets() {
Ok(plugin_mgr) => {
if let Err(e) = plugin_mgr
.execute_event("on_load", &plugin_api::event::PluginLoadEvent { game_mode })
{
tracing::error!(?e, "Failed to run plugin init");
info!("Error occurred when loading plugins. Running without plugins instead.");
tracing::info!(
"Error occurred when loading plugins. Running without plugins instead."
);
PluginMgr::default()
} else {
plugin_mgr

View File

@ -8,6 +8,7 @@ edition = "2018"
worldgen = ["server/worldgen"]
default = ["worldgen"]
tracy = ["common/tracy", "tracing-tracy"]
plugins = ["server/plugins"]
[dependencies]
server = { package = "veloren-server", path = "../server", default-features = false }

View File

@ -7,6 +7,7 @@ edition = "2018"
[features]
worldgen = []
simd = ["vek/platform_intrinsics"]
plugins = ["common-sys/plugins"]
default = ["worldgen", "simd"]

View File

@ -49,14 +49,13 @@ use crate::{
use common::{
assets::Asset,
cmd::ChatCommand,
comp::{self, ChatType},
comp,
event::{EventBus, ServerEvent},
outcome::Outcome,
recipe::default_recipe_book,
resources::TimeOfDay,
rtsim::RtSimEntity,
terrain::TerrainChunkSize,
uid::Uid,
vol::{ReadVol, RectVolSize},
};
use common_net::{
@ -65,7 +64,9 @@ use common_net::{
},
sync::WorldSyncExt,
};
use common_sys::{plugin::PluginMgr, state::State};
#[cfg(feature = "plugins")]
use common_sys::plugin::PluginMgr;
use common_sys::state::State;
use futures_executor::block_on;
use metrics::{PhysicsMetrics, ServerMetrics, StateTickMetrics, TickMetrics};
use network::{Network, Pid, ProtocolAddr};
@ -1011,6 +1012,9 @@ impl Server {
if let Ok(command) = kwd.parse::<ChatCommand>() {
command.execute(self, entity, args);
} else {
#[cfg(feature = "plugins")]
{
use common::uid::Uid;
let plugin_manager = self.state.ecs().read_resource::<PluginMgr>();
let rs = plugin_manager.execute_event(
&format!("on_command_{}", &kwd),
@ -1033,9 +1037,10 @@ impl Server {
self.notify_client(
entity,
ServerGeneral::server_msg(
ChatType::CommandError,
comp::ChatType::CommandError,
format!(
"Unknown command '/{}'.\nType '/help' for available commands",
"Unknown command '/{}'.\nType '/help' for available \
commands",
kwd
),
),
@ -1057,7 +1062,7 @@ impl Server {
self.notify_client(
entity,
ServerGeneral::server_msg(
ChatType::CommandError,
comp::ChatType::CommandError,
format!(
"Error occurred while executing command '/{}'.\n{}",
kwd, e
@ -1073,7 +1078,7 @@ impl Server {
self.notify_client(
entity,
ServerGeneral::server_msg(
ChatType::CommandError,
comp::ChatType::CommandError,
format!(
"Internal error while executing '/{}'.\nContact the server \
administrator",
@ -1085,6 +1090,7 @@ impl Server {
}
}
}
}
fn entity_is_admin(&self, entity: EcsEntity) -> bool {
self.state

View File

@ -15,6 +15,7 @@ singleplayer = ["server"]
tweak = ["const-tweaker"]
simd = ["vek/platform_intrinsics"]
tracy = ["tracing-tracy", "common/tracy"]
plugins = ["client/plugins"]
default = ["gl", "singleplayer", "native-dialog", "simd"]