From 58472a27b1f62289521482929cc2331d856accdc Mon Sep 17 00:00:00 2001 From: "Tristan Poland (Trident_For_U)" <34868944+tristanpoland@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:27:36 -0500 Subject: [PATCH 1/4] empty commit to create PR to start discussion From 7e7aca4e44e1ff890f307e1ea0eeb57c3b8ecf70 Mon Sep 17 00:00:00 2001 From: "Tristan Poland (Trident_For_U)" <34868944+tristanpoland@users.noreply.github.com> Date: Tue, 24 Dec 2024 15:00:03 -0500 Subject: [PATCH 2/4] Began setting up the link plugin standard --- backends/stars_beyond/Cargo.toml | 1 + plugin_api/Cargo.toml | 1 + plugin_api/src/plugin_imports.rs | 4 +++ plugins/chronos_plugin/Cargo.toml | 1 + plugins/community_link_plugin/Cargo.toml | 11 ++++++ plugins/community_link_plugin/src/lib.rs | 45 ++++++++++++++++++++++++ server/src/server/mod.rs | 7 ++-- 7 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 plugins/community_link_plugin/Cargo.toml create mode 100644 plugins/community_link_plugin/src/lib.rs diff --git a/backends/stars_beyond/Cargo.toml b/backends/stars_beyond/Cargo.toml index 3292d94..18ccc16 100644 --- a/backends/stars_beyond/Cargo.toml +++ b/backends/stars_beyond/Cargo.toml @@ -15,5 +15,6 @@ parking_lot = "0.12.3" # ###### BEGIN AUTO-GENERATED BACKEND DEPENDENCIES - DO NOT EDIT THIS SECTION ###### chronos_plugin = { path = "../../plugins/chronos_plugin", version = "0.1.0" } +link_plugin = { path = "../../plugins/community_link_plugin", version = "0.1.0" } player_lib = { path = "../../plugins/player_lib", version = "0.1.0" } ###### END AUTO-GENERATED BACKEND DEPENDENCIES ###### diff --git a/plugin_api/Cargo.toml b/plugin_api/Cargo.toml index 931f9f6..d64a856 100644 --- a/plugin_api/Cargo.toml +++ b/plugin_api/Cargo.toml @@ -23,5 +23,6 @@ horizon-plugin-api = "0.2.0" # ###### BEGIN AUTO-GENERATED PLUGIN DEPENDENCIES - DO NOT EDIT THIS SECTION ###### chronos_plugin = { path = "../plugins/chronos_plugin", version = "0.1.0" } +link_plugin = { path = "../plugins/community_link_plugin", version = "0.1.0" } player_lib = { path = "../plugins/player_lib", version = "0.1.0" } ###### END AUTO-GENERATED PLUGIN DEPENDENCIES ###### diff --git a/plugin_api/src/plugin_imports.rs b/plugin_api/src/plugin_imports.rs index 23da8d0..443bcf2 100644 --- a/plugin_api/src/plugin_imports.rs +++ b/plugin_api/src/plugin_imports.rs @@ -6,6 +6,9 @@ use std::collections::HashMap; pub use chronos_plugin; pub use chronos_plugin::*; pub use chronos_plugin::Plugin as chronos_plugin_plugin; +pub use link_plugin; +pub use link_plugin::*; +pub use link_plugin::Plugin as link_plugin_plugin; pub use player_lib; pub use player_lib::*; pub use player_lib::Plugin as player_lib_plugin; @@ -15,6 +18,7 @@ pub use player_lib::Plugin as player_lib_plugin; pub fn load_plugins() -> HashMap { let plugins = crate::load_plugins!( chronos_plugin, + link_plugin, player_lib ); plugins diff --git a/plugins/chronos_plugin/Cargo.toml b/plugins/chronos_plugin/Cargo.toml index 6aa12d0..28fb9d9 100644 --- a/plugins/chronos_plugin/Cargo.toml +++ b/plugins/chronos_plugin/Cargo.toml @@ -10,5 +10,6 @@ lazy_static = "1.5.0" parking_lot = "0.12.3" socketioxide = "0.15.1" ###### BEGIN AUTO-GENERATED PLUGIN DEPENDENCIES - DO NOT EDIT THIS SECTION ###### +link_plugin = { path = "../community_link_plugin", version = "0.1.0" } player_lib = { path = "../player_lib", version = "0.1.0" } ###### END AUTO-GENERATED PLUGIN DEPENDENCIES ###### diff --git a/plugins/community_link_plugin/Cargo.toml b/plugins/community_link_plugin/Cargo.toml new file mode 100644 index 0000000..3f6352a --- /dev/null +++ b/plugins/community_link_plugin/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "link_plugin" +version = "0.1.0" +edition = "2021" + +[dependencies] +PebbleVault = "0.6.1" +horizon-plugin-api = "0.2.0" +horizon_data_types = "0.4.0" +socketioxide = "0.15.1" +parking_lot = "0.12.3" diff --git a/plugins/community_link_plugin/src/lib.rs b/plugins/community_link_plugin/src/lib.rs new file mode 100644 index 0000000..34d3488 --- /dev/null +++ b/plugins/community_link_plugin/src/lib.rs @@ -0,0 +1,45 @@ +use horizon_data_types::Player; +use socketioxide::extract::SocketRef; +pub use horizon_plugin_api::{Plugin, Pluginstate, LoadedPlugin}; +use parking_lot::RwLock; +use std::sync::Arc; +use std::collections::HashMap;\ +use socketioxide::extract::SocketRef; + +pub trait PluginConstruct { + fn get_structs(&self) -> Vec<&str>; + // If you want default implementations, mark them with 'default' + fn new(plugins: HashMap) -> Plugin; + +} + +impl PluginConstruct for Plugin { + fn new(_plugins: HashMap) -> Plugin { + Plugin {} + } + + fn get_structs(&self) -> Vec<&str> { + vec!["MyPlayer"] + } +} + +pub trait PluginAPI {} +impl PluginAPI for Plugin {} + +pub struct listner { + socketref: SocketRef, +} + +impl listner { + pub fn on(&self, event: &str, callback: F) + where + T: DeserializeOwned + Send + 'static, + F: Fn(Data, SocketRef) + Send + Sync + 'static, + { + self.socket.on(event, move |data: Data, socket: SocketRef| { + //TODO: Pass the data to other servers as well, and strip any un-needed fields here. + + callback(data, socket); + }); + } +} \ No newline at end of file diff --git a/server/src/server/mod.rs b/server/src/server/mod.rs index c8b65bf..6bdf7b2 100644 --- a/server/src/server/mod.rs +++ b/server/src/server/mod.rs @@ -20,7 +20,7 @@ use axum::{routing::get, Router}; use config::ServerConfig; use horizon_data_types::Player; use horizon_logger::{log_debug, log_error, log_info}; -use horizon_plugin_api::LoadedPlugin; +use horizon_plugin_api::{LoadedPlugin}; use parking_lot::RwLock; use socketioxide::{ extract::{AckSender, Data, SocketRef}, @@ -30,6 +30,7 @@ use std::collections::HashMap; use std::sync::Arc; use tokio::sync::Mutex; use uuid::Uuid; +use plugin_api::*; pub mod config; mod event_rep; use lazy_static::lazy_static; @@ -187,9 +188,9 @@ fn on_connect(socket: SocketRef, Data(data): Data) { let player_arc: Arc = Arc::new(player); - //let casted_struct = plugin_api::get_plugin!(unreal_adapter_horizon, target_thread.plugins); + // let casted_struct = plugin_api::get_plugin!(unreal_adapter_horizon, target_thread.plugins); - //casted_struct.player_joined(socket, player_arc); + // casted_struct.player_joined(socket, player_arc); } //----------------------------------------------------------------------------- From 51fdf2e8fa2905f550b31b802eda86540d755485 Mon Sep 17 00:00:00 2001 From: "Tristan Poland (Trident_For_U)" <34868944+tristanpoland@users.noreply.github.com> Date: Tue, 24 Dec 2024 15:08:07 -0500 Subject: [PATCH 3/4] Fixed compile errors --- plugins/community_link_plugin/Cargo.toml | 1 + plugins/community_link_plugin/src/lib.rs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/community_link_plugin/Cargo.toml b/plugins/community_link_plugin/Cargo.toml index 3f6352a..eeaad9d 100644 --- a/plugins/community_link_plugin/Cargo.toml +++ b/plugins/community_link_plugin/Cargo.toml @@ -9,3 +9,4 @@ horizon-plugin-api = "0.2.0" horizon_data_types = "0.4.0" socketioxide = "0.15.1" parking_lot = "0.12.3" +serde = "1.0.216" diff --git a/plugins/community_link_plugin/src/lib.rs b/plugins/community_link_plugin/src/lib.rs index 34d3488..e21ca16 100644 --- a/plugins/community_link_plugin/src/lib.rs +++ b/plugins/community_link_plugin/src/lib.rs @@ -1,10 +1,10 @@ use horizon_data_types::Player; -use socketioxide::extract::SocketRef; -pub use horizon_plugin_api::{Plugin, Pluginstate, LoadedPlugin}; use parking_lot::RwLock; use std::sync::Arc; -use std::collections::HashMap;\ -use socketioxide::extract::SocketRef; +use std::collections::HashMap; +use socketioxide::extract::{ SocketRef, Data }; +use serde::de::DeserializeOwned; +pub use horizon_plugin_api::{Plugin, Pluginstate, LoadedPlugin}; pub trait PluginConstruct { fn get_structs(&self) -> Vec<&str>; From 52c649fa315f28d8a9292e08fe4858000a80792a Mon Sep 17 00:00:00 2001 From: "Tristan Poland (Trident_For_U)" <34868944+tristanpoland@users.noreply.github.com> Date: Tue, 24 Dec 2024 15:11:58 -0500 Subject: [PATCH 4/4] Update lib.rs --- plugins/community_link_plugin/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/community_link_plugin/src/lib.rs b/plugins/community_link_plugin/src/lib.rs index e21ca16..b96d371 100644 --- a/plugins/community_link_plugin/src/lib.rs +++ b/plugins/community_link_plugin/src/lib.rs @@ -33,10 +33,12 @@ pub struct listner { impl listner { pub fn on(&self, event: &str, callback: F) where - T: DeserializeOwned + Send + 'static, - F: Fn(Data, SocketRef) + Send + Sync + 'static, + T: DeserializeOwned + Send + Sync + 'static, + F: Fn(Data, SocketRef) + Send + Sync + 'static + Clone, { - self.socket.on(event, move |data: Data, socket: SocketRef| { + let event = event.to_string(); + let event_clone = event.clone(); + self.socketref.on(event_clone, move |data: Data, socket: SocketRef| { //TODO: Pass the data to other servers as well, and strip any un-needed fields here. callback(data, socket);