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"]
@ -34,4 +35,4 @@ authc = { git = "https://gitlab.com/veloren/auth.git", rev = "b943c85e4a38f5ec60
tracing-subscriber = { version = "0.2.3", default-features = false, features = ["fmt", "chrono", "ansi", "smallvec"] }
[[example]]
name = "chat-cli"
name = "chat-cli"

View File

@ -71,4 +71,4 @@ harness = false
[[bin]]
name = "csv_export"
required-features = ["bin_csv_export"]
required-features = ["bin_csv_export"]

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,77 +1012,82 @@ impl Server {
if let Ok(command) = kwd.parse::<ChatCommand>() {
command.execute(self, entity, args);
} else {
let plugin_manager = self.state.ecs().read_resource::<PluginMgr>();
let rs = plugin_manager.execute_event(
&format!("on_command_{}", &kwd),
&plugin_api::event::ChatCommandEvent {
command: kwd.clone(),
command_args: args.split(' ').map(|x| x.to_owned()).collect(),
player: plugin_api::event::Player {
id: *(self
.state
.ecs()
.read_storage::<Uid>()
.get(entity)
.expect("Can't get player UUID [This should never appen]")),
#[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),
&plugin_api::event::ChatCommandEvent {
command: kwd.clone(),
command_args: args.split(' ').map(|x| x.to_owned()).collect(),
player: plugin_api::event::Player {
id: *(self
.state
.ecs()
.read_storage::<Uid>()
.get(entity)
.expect("Can't get player UUID [This should never appen]")),
},
},
},
);
match rs {
Ok(e) => {
if e.is_empty() {
);
match rs {
Ok(e) => {
if e.is_empty() {
self.notify_client(
entity,
ServerGeneral::server_msg(
comp::ChatType::CommandError,
format!(
"Unknown command '/{}'.\nType '/help' for available \
commands",
kwd
),
),
);
} else {
e.into_iter().for_each(|e| match e {
Ok(e) => {
if !e.is_empty() {
self.notify_client(
entity,
ServerGeneral::server_msg(
ChatType::CommandInfo,
e.join("\n"),
),
);
}
},
Err(e) => {
self.notify_client(
entity,
ServerGeneral::server_msg(
comp::ChatType::CommandError,
format!(
"Error occurred while executing command '/{}'.\n{}",
kwd, e
),
),
);
},
});
}
},
Err(e) => {
error!(?e, "Can't execute command {} {}", kwd, args);
self.notify_client(
entity,
ServerGeneral::server_msg(
ChatType::CommandError,
comp::ChatType::CommandError,
format!(
"Unknown command '/{}'.\nType '/help' for available commands",
"Internal error while executing '/{}'.\nContact the server \
administrator",
kwd
),
),
);
} else {
e.into_iter().for_each(|e| match e {
Ok(e) => {
if !e.is_empty() {
self.notify_client(
entity,
ServerGeneral::server_msg(
ChatType::CommandInfo,
e.join("\n"),
),
);
}
},
Err(e) => {
self.notify_client(
entity,
ServerGeneral::server_msg(
ChatType::CommandError,
format!(
"Error occurred while executing command '/{}'.\n{}",
kwd, e
),
),
);
},
});
}
},
Err(e) => {
error!(?e, "Can't execute command {} {}", kwd, args);
self.notify_client(
entity,
ServerGeneral::server_msg(
ChatType::CommandError,
format!(
"Internal error while executing '/{}'.\nContact the server \
administrator",
kwd
),
),
);
},
},
}
}
}
}

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