Skip to content

Commit

Permalink
Merge pull request #202 from Far-Beyond-Dev/feature/server-link-plugin
Browse files Browse the repository at this point in the history
Feat: Add Customizable Server Communication Framework via Link Plugins
  • Loading branch information
tristanpoland authored Dec 27, 2024
2 parents 699e6a3 + f8a6eb6 commit 35b9cda
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 4 deletions.
1 change: 1 addition & 0 deletions backends/stars_beyond/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ######
1 change: 1 addition & 0 deletions plugin_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ######
4 changes: 4 additions & 0 deletions plugin_api/src/plugin_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +18,7 @@ pub use player_lib::Plugin as player_lib_plugin;
pub fn load_plugins() -> HashMap<String, (Pluginstate, Plugin)> {
let plugins = crate::load_plugins!(
chronos_plugin,
link_plugin,
player_lib
);
plugins
Expand Down
1 change: 1 addition & 0 deletions plugins/chronos_plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ######
12 changes: 12 additions & 0 deletions plugins/community_link_plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[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"
serde = "1.0.216"
47 changes: 47 additions & 0 deletions plugins/community_link_plugin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use horizon_data_types::Player;
use parking_lot::RwLock;
use std::sync::Arc;
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>;
// If you want default implementations, mark them with 'default'
fn new(plugins: HashMap<String, (Pluginstate, Plugin)>) -> Plugin;

}

impl PluginConstruct for Plugin {
fn new(_plugins: HashMap<String, (Pluginstate, Plugin)>) -> 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<T, F>(&self, event: &str, callback: F)
where
T: DeserializeOwned + Send + Sync + 'static,
F: Fn(Data<T>, SocketRef) + Send + Sync + 'static + Clone,
{
let event = event.to_string();
let event_clone = event.clone();
self.socketref.on(event_clone, move |data: Data<T>, socket: SocketRef| {
//TODO: Pass the data to other servers as well, and strip any un-needed fields here.

callback(data, socket);
});
}
}
7 changes: 3 additions & 4 deletions server/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;
pub mod in_world;

Expand Down Expand Up @@ -198,9 +199,7 @@ fn on_connect(socket: SocketRef, Data(data): Data<serde_json::Value>) {


// 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);
}

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 35b9cda

Please sign in to comment.