mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
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:
@ -6,6 +6,7 @@ edition = "2018"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
simd = ["vek/platform_intrinsics"]
|
simd = ["vek/platform_intrinsics"]
|
||||||
|
plugins = ["common-sys/plugins"]
|
||||||
|
|
||||||
default = ["simd"]
|
default = ["simd"]
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ version = "0.8.0"
|
|||||||
[features]
|
[features]
|
||||||
tracy = ["tracy-client"]
|
tracy = ["tracy-client"]
|
||||||
simd = ["vek/platform_intrinsics"]
|
simd = ["vek/platform_intrinsics"]
|
||||||
|
plugins = ["toml", "tar", "wasmer-runtime", "bincode", "plugin-api"]
|
||||||
|
|
||||||
default = ["simd"]
|
default = ["simd"]
|
||||||
|
|
||||||
@ -34,8 +35,8 @@ serde = { version = "1.0.110", features = ["derive"] }
|
|||||||
tracy-client = { version = "0.9.0", optional = true }
|
tracy-client = { version = "0.9.0", optional = true }
|
||||||
|
|
||||||
# Plugins
|
# Plugins
|
||||||
toml = "0.5.7"
|
toml = { version = "0.5.7", optional = true }
|
||||||
tar = "0.4.30"
|
tar = { version = "0.4.30", optional = true }
|
||||||
wasmer-runtime = "0.17.1"
|
wasmer-runtime = { version = "0.17.1", optional = true }
|
||||||
bincode = "1.3.1"
|
bincode = { version = "1.3.1", optional = true }
|
||||||
plugin-api = { package = "veloren-plugin-api", path = "../../plugin/api"}
|
plugin-api = { package = "veloren-plugin-api", path = "../../plugin/api", optional = true }
|
||||||
|
@ -9,7 +9,7 @@ pub mod controller;
|
|||||||
pub mod melee;
|
pub mod melee;
|
||||||
mod mount;
|
mod mount;
|
||||||
pub mod phys;
|
pub mod phys;
|
||||||
pub mod plugin;
|
#[cfg(feature = "plugins")] pub mod plugin;
|
||||||
mod projectile;
|
mod projectile;
|
||||||
mod shockwave;
|
mod shockwave;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
@ -104,7 +104,7 @@ impl PluginMgr {
|
|||||||
pub fn from_assets() -> Result<Self, PluginError> {
|
pub fn from_assets() -> Result<Self, PluginError> {
|
||||||
let mut assets_path = (&*ASSETS_PATH).clone();
|
let mut assets_path = (&*ASSETS_PATH).clone();
|
||||||
assets_path.push("plugins");
|
assets_path.push("plugins");
|
||||||
info!("Searching {:?} for assets...", assets_path);
|
info!("Searching {:?} for plugins...", assets_path);
|
||||||
Self::from_dir(assets_path)
|
Self::from_dir(assets_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#[cfg(feature = "plugins")]
|
||||||
use crate::plugin::PluginMgr;
|
use crate::plugin::PluginMgr;
|
||||||
use common::{
|
use common::{
|
||||||
comp,
|
comp,
|
||||||
@ -20,7 +21,6 @@ use specs::{
|
|||||||
Component, DispatcherBuilder, Entity as EcsEntity, WorldExt,
|
Component, DispatcherBuilder, Entity as EcsEntity, WorldExt,
|
||||||
};
|
};
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
use tracing::info;
|
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
/// How much faster should an in-game day be compared to a real day?
|
/// How much faster should an in-game day be compared to a real day?
|
||||||
@ -191,13 +191,16 @@ impl State {
|
|||||||
ecs.insert(PhysicsMetrics::default());
|
ecs.insert(PhysicsMetrics::default());
|
||||||
|
|
||||||
// Load plugins from asset directory
|
// Load plugins from asset directory
|
||||||
|
#[cfg(feature = "plugins")]
|
||||||
ecs.insert(match PluginMgr::from_assets() {
|
ecs.insert(match PluginMgr::from_assets() {
|
||||||
Ok(plugin_mgr) => {
|
Ok(plugin_mgr) => {
|
||||||
if let Err(e) = plugin_mgr
|
if let Err(e) = plugin_mgr
|
||||||
.execute_event("on_load", &plugin_api::event::PluginLoadEvent { game_mode })
|
.execute_event("on_load", &plugin_api::event::PluginLoadEvent { game_mode })
|
||||||
{
|
{
|
||||||
tracing::error!(?e, "Failed to run plugin init");
|
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()
|
PluginMgr::default()
|
||||||
} else {
|
} else {
|
||||||
plugin_mgr
|
plugin_mgr
|
||||||
|
@ -8,6 +8,7 @@ edition = "2018"
|
|||||||
worldgen = ["server/worldgen"]
|
worldgen = ["server/worldgen"]
|
||||||
default = ["worldgen"]
|
default = ["worldgen"]
|
||||||
tracy = ["common/tracy", "tracing-tracy"]
|
tracy = ["common/tracy", "tracing-tracy"]
|
||||||
|
plugins = ["server/plugins"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
server = { package = "veloren-server", path = "../server", default-features = false }
|
server = { package = "veloren-server", path = "../server", default-features = false }
|
||||||
|
@ -7,6 +7,7 @@ edition = "2018"
|
|||||||
[features]
|
[features]
|
||||||
worldgen = []
|
worldgen = []
|
||||||
simd = ["vek/platform_intrinsics"]
|
simd = ["vek/platform_intrinsics"]
|
||||||
|
plugins = ["common-sys/plugins"]
|
||||||
|
|
||||||
default = ["worldgen", "simd"]
|
default = ["worldgen", "simd"]
|
||||||
|
|
||||||
|
@ -49,14 +49,13 @@ use crate::{
|
|||||||
use common::{
|
use common::{
|
||||||
assets::Asset,
|
assets::Asset,
|
||||||
cmd::ChatCommand,
|
cmd::ChatCommand,
|
||||||
comp::{self, ChatType},
|
comp,
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
recipe::default_recipe_book,
|
recipe::default_recipe_book,
|
||||||
resources::TimeOfDay,
|
resources::TimeOfDay,
|
||||||
rtsim::RtSimEntity,
|
rtsim::RtSimEntity,
|
||||||
terrain::TerrainChunkSize,
|
terrain::TerrainChunkSize,
|
||||||
uid::Uid,
|
|
||||||
vol::{ReadVol, RectVolSize},
|
vol::{ReadVol, RectVolSize},
|
||||||
};
|
};
|
||||||
use common_net::{
|
use common_net::{
|
||||||
@ -65,7 +64,9 @@ use common_net::{
|
|||||||
},
|
},
|
||||||
sync::WorldSyncExt,
|
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 futures_executor::block_on;
|
||||||
use metrics::{PhysicsMetrics, ServerMetrics, StateTickMetrics, TickMetrics};
|
use metrics::{PhysicsMetrics, ServerMetrics, StateTickMetrics, TickMetrics};
|
||||||
use network::{Network, Pid, ProtocolAddr};
|
use network::{Network, Pid, ProtocolAddr};
|
||||||
@ -1011,6 +1012,9 @@ impl Server {
|
|||||||
if let Ok(command) = kwd.parse::<ChatCommand>() {
|
if let Ok(command) = kwd.parse::<ChatCommand>() {
|
||||||
command.execute(self, entity, args);
|
command.execute(self, entity, args);
|
||||||
} else {
|
} else {
|
||||||
|
#[cfg(feature = "plugins")]
|
||||||
|
{
|
||||||
|
use common::uid::Uid;
|
||||||
let plugin_manager = self.state.ecs().read_resource::<PluginMgr>();
|
let plugin_manager = self.state.ecs().read_resource::<PluginMgr>();
|
||||||
let rs = plugin_manager.execute_event(
|
let rs = plugin_manager.execute_event(
|
||||||
&format!("on_command_{}", &kwd),
|
&format!("on_command_{}", &kwd),
|
||||||
@ -1033,9 +1037,10 @@ impl Server {
|
|||||||
self.notify_client(
|
self.notify_client(
|
||||||
entity,
|
entity,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandError,
|
comp::ChatType::CommandError,
|
||||||
format!(
|
format!(
|
||||||
"Unknown command '/{}'.\nType '/help' for available commands",
|
"Unknown command '/{}'.\nType '/help' for available \
|
||||||
|
commands",
|
||||||
kwd
|
kwd
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -1057,7 +1062,7 @@ impl Server {
|
|||||||
self.notify_client(
|
self.notify_client(
|
||||||
entity,
|
entity,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandError,
|
comp::ChatType::CommandError,
|
||||||
format!(
|
format!(
|
||||||
"Error occurred while executing command '/{}'.\n{}",
|
"Error occurred while executing command '/{}'.\n{}",
|
||||||
kwd, e
|
kwd, e
|
||||||
@ -1073,7 +1078,7 @@ impl Server {
|
|||||||
self.notify_client(
|
self.notify_client(
|
||||||
entity,
|
entity,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandError,
|
comp::ChatType::CommandError,
|
||||||
format!(
|
format!(
|
||||||
"Internal error while executing '/{}'.\nContact the server \
|
"Internal error while executing '/{}'.\nContact the server \
|
||||||
administrator",
|
administrator",
|
||||||
@ -1085,6 +1090,7 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn entity_is_admin(&self, entity: EcsEntity) -> bool {
|
fn entity_is_admin(&self, entity: EcsEntity) -> bool {
|
||||||
self.state
|
self.state
|
||||||
|
@ -15,6 +15,7 @@ singleplayer = ["server"]
|
|||||||
tweak = ["const-tweaker"]
|
tweak = ["const-tweaker"]
|
||||||
simd = ["vek/platform_intrinsics"]
|
simd = ["vek/platform_intrinsics"]
|
||||||
tracy = ["tracing-tracy", "common/tracy"]
|
tracy = ["tracing-tracy", "common/tracy"]
|
||||||
|
plugins = ["client/plugins"]
|
||||||
|
|
||||||
default = ["gl", "singleplayer", "native-dialog", "simd"]
|
default = ["gl", "singleplayer", "native-dialog", "simd"]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user