Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add Customizable Server Communication Framework via Link Plugins #202

Merged
merged 7 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ######
11 changes: 11 additions & 0 deletions plugins/community_link_plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
45 changes: 45 additions & 0 deletions plugins/community_link_plugin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<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 + 'static,
F: Fn(Data<T>, SocketRef) + Send + Sync + 'static,
{
self.socket.on(event, move |data: Data<T>, socket: SocketRef| {
//TODO: Pass the data to other servers as well, and strip any un-needed fields here.
Dismissed Show dismissed Hide dismissed

callback(data, socket);
});
}
}
7 changes: 4 additions & 3 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;
mod event_rep;
use lazy_static::lazy_static;
Expand Down Expand Up @@ -187,9 +188,9 @@ fn on_connect(socket: SocketRef, Data(data): Data<serde_json::Value>) {

let player_arc: Arc<horizon_data_types::Player> = 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);
}

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