Skip to content

Commit

Permalink
Merge pull request #222 from Far-Beyond-Dev/219-fix-code-scanning-ale…
Browse files Browse the repository at this point in the history
…rt-add-player-joining-object-creation-to-the-backend-example

Moved Code Success!
  • Loading branch information
SafeShows authored Dec 30, 2024
2 parents 076e7d3 + 84311f0 commit 094cd60
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions backends/stars_beyond/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ horizon-plugin-api = "0.2.0"
horizon_data_types = "0.4.0"
socketioxide = "0.15.1"
parking_lot = "0.12.3"
serde_json = "1.0.134"
#
#
#
Expand Down
13 changes: 11 additions & 2 deletions backends/stars_beyond/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub use horizon_plugin_api::{Plugin, Pluginstate, LoadedPlugin};
use parking_lot::RwLock;
use std::sync::Arc;
use std::collections::HashMap;
use player_lib::world;
// use socketioxide::packet::Str;

pub trait PluginAPI {
Expand All @@ -30,10 +31,18 @@ impl PluginConstruct for Plugin {
impl PluginAPI for Plugin {
fn player_joined(&self, socket: SocketRef, player: Arc<RwLock<horizon_data_types::Player>>) {
println!("player_lib");
setup_listeners(socket, player);
setup_listeners(&socket, player);

let player_char = world::Object::new("Player Character".to_string(), true);
println!("Player joined: {:?}", player_char.get_uuid().to_string());

let player_json_value: serde_json::Value = serde_json::json!({ "joined": true });
player_char.send_event(socket, "playerjoined".to_string(), player_json_value);
println!("Sent player joined event Successfully");
}
}


fn setup_listeners(_socket: SocketRef, _player: Arc<RwLock<Player>>) {
fn setup_listeners(_socket: &SocketRef, _player: Arc<RwLock<Player>>) {

}
3 changes: 3 additions & 0 deletions plugins/player_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ horizon-plugin-api = "0.2.0"
horizon_data_types = "0.4.0"
socketioxide = "0.15.1"
parking_lot = "0.12.3"
serde = "1.0.217"
serde_json = "1.0.134"
uuid = "1.11.0"
2 changes: 2 additions & 0 deletions plugins/player_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pub use horizon_plugin_api::{Plugin, Pluginstate, LoadedPlugin};
use parking_lot::RwLock;
use std::sync::Arc;
use std::collections::HashMap;

pub mod world;
// use socketioxide::packet::Str;
// use PebbleVault;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use socketioxide::extract::{ SocketRef, Data };
use serde::Serialize;
use serde_json::Value;
use std::collections::HashMap;
use uuid::Uuid;


#[allow(dead_code)]
pub struct Object {
uuid: Uuid,
name: String,
Expand Down
14 changes: 2 additions & 12 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,9 +30,8 @@ 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;


use lazy_static::lazy_static;

Expand Down Expand Up @@ -189,15 +188,6 @@ fn on_connect(socket: SocketRef, Data(data): Data<serde_json::Value>) {

let player_arc: Arc<horizon_data_types::Player> = Arc::new(player);

// TODO: move this to example backend
let player_char = in_world::Object::new("Player Character".to_string(), true);
println!("Player joined: {:?}", player_char.get_uuid().to_string());

let player_json_value: serde_json::Value = serde_json::json!({ "joined": true });
player_char.send_event(socket, "playerjoined".to_string(), player_json_value);
println!("Sent player joined event Successfully");


// let casted_struct = plugin_api::get_plugin!(unreal_adapter_horizon, target_thread.plugins);
// casted_struct.player_joined(socket, player_arc);
}
Expand Down

0 comments on commit 094cd60

Please sign in to comment.