-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from Far-Beyond-Dev/feature/server-link-plugin
Feat: Add Customizable Server Communication Framework via Link Plugins
- Loading branch information
Showing
7 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters