From 8a3ac5e8d3350ac8e1bf145188cc6c339aace694 Mon Sep 17 00:00:00 2001 From: Nobody Date: Mon, 4 Apr 2022 22:57:05 +0500 Subject: [PATCH] Enable TP point unlocking --- Cargo.toml | 3 +++ src/dbmanager/database_manager.rs | 29 +++++++++++++++++++++++++++++ src/dbmanager/mod.rs | 3 ++- src/dbmanager/trans_point.rs | 26 ++++++++++++++++++++++++++ src/subsystems/misc/scene.rs | 16 ++++++++++++---- src/subsystems/misc/teleport.rs | 15 +++++++++++++++ 6 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 src/dbmanager/trans_point.rs diff --git a/Cargo.toml b/Cargo.toml index 2197ac1..6b13151 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +raw_packet_dump = [] + [dependencies] kcp = { path = "../kcp" } mhycrypt = { path = "../mhycrypt" } diff --git a/src/dbmanager/database_manager.rs b/src/dbmanager/database_manager.rs index 0614c3b..35b931f 100644 --- a/src/dbmanager/database_manager.rs +++ b/src/dbmanager/database_manager.rs @@ -73,6 +73,9 @@ use super::reliquary_prop::Entity as ReliquaryPropEntity; pub use super::furniture_info::Model as FurnitureInfo; use super::furniture_info::Entity as FurnitureInfoEntity; +pub use super::trans_point::Model as TransPoint; +use super::trans_point::Entity as TransPointEntity; + /* This is used to convert async operations into sync ones */ @@ -1050,6 +1053,32 @@ impl DatabaseManager { // No assert here } + pub fn get_scene_trans_points(&self, user_id: u32, scene_id: u32) -> Vec { + let points = match TransPointEntity::find() + .filter( + Condition::all() + .add(super::trans_point::Column::Uid.eq(user_id)) + .add(super::trans_point::Column::SceneId.eq(scene_id)) + ) + .all(&self.db).wait() + { + Err(_) => { panic!("DB ERROR!") }, + Ok(points) => points.iter().map(|x| x.point_id).collect(), + }; + + return points; + } + + pub fn add_scene_trans_point(&self, user_id: u32, scene_id: u32, point_id: u32) { + let point = super::trans_point::ActiveModel { + uid: ActiveValue::Set(user_id), + scene_id: ActiveValue::Set(scene_id), + point_id: ActiveValue::Set(point_id), + }; + + let point: TransPoint = point.put(&self.db).unwrap(); + } + pub const SPOOFED_AVATAR_ID: u32 = 1; pub const SPOOFED_WEAPON_ID: u32 = 2; const SPOOFED_SCENE_ID: u32 = 3; // TODO: that's a different kind of ID! diff --git a/src/dbmanager/mod.rs b/src/dbmanager/mod.rs index 957d4e8..c25b0ca 100644 --- a/src/dbmanager/mod.rs +++ b/src/dbmanager/mod.rs @@ -20,4 +20,5 @@ mod equip_info; mod item_info; mod weapon_affix_info; mod reliquary_prop; -mod furniture_info; \ No newline at end of file +mod furniture_info; +mod trans_point; \ No newline at end of file diff --git a/src/dbmanager/trans_point.rs b/src/dbmanager/trans_point.rs new file mode 100644 index 0000000..1ba48bd --- /dev/null +++ b/src/dbmanager/trans_point.rs @@ -0,0 +1,26 @@ +// Database Manager + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "trans_point")] +pub struct Model { + #[sea_orm(primary_key, autoincrement = false)] + pub uid: u32, + pub scene_id: u32, + pub point_id: u32, +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + _ => panic!("Unknown relation type!"), + } + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/subsystems/misc/scene.rs b/src/subsystems/misc/scene.rs index eb2b598..f25be39 100644 --- a/src/subsystems/misc/scene.rs +++ b/src/subsystems/misc/scene.rs @@ -23,13 +23,15 @@ GetScenePointReq, )] pub struct SceneSubsystem { packets_to_send_tx: Sender, + db: Arc, } impl SceneSubsystem { - pub fn new(packets_to_send_tx: Sender) -> Self { + pub fn new(db: Arc, packets_to_send_tx: Sender) -> Self { let mut scs = Self { packets_to_send_tx: packets_to_send_tx, packet_callbacks: HashMap::new(), + db: db, }; scs.register(); @@ -49,10 +51,16 @@ impl SceneSubsystem { } fn process_get_scene_point(&self, user_id: u32, metadata: &proto::PacketHead, req: &proto::GetScenePointReq, rsp: &mut proto::GetScenePointRsp) { - rsp.scene_id = req.scene_id; + let scene_id = req.scene_id; + + rsp.scene_id = scene_id; + + // TODO: implemented but for the sake of debugging we hardcode it for now + rsp.unlocked_point_list = (1..300).collect(); + //rsp.unlocked_point_list = self.db.get_scene_trans_points(user_id, scene_id); + // TODO: hardcoded data! - rsp.unlocked_point_list = (1..250).collect(); - rsp.unlock_area_list = (1..11).collect(); + rsp.unlock_area_list = (1..20).collect(); //locked_point_list=vec![]; } diff --git a/src/subsystems/misc/teleport.rs b/src/subsystems/misc/teleport.rs index e148421..644b285 100644 --- a/src/subsystems/misc/teleport.rs +++ b/src/subsystems/misc/teleport.rs @@ -21,6 +21,7 @@ use crate::utils::{IdManager, TimeManager}; #[packet_processor( SceneTransToPointReq, +UnlockTransPointReq, )] pub struct TeleportSubsystem { packets_to_send_tx: Sender, @@ -75,4 +76,18 @@ impl TeleportSubsystem { self.em.player_teleported(user_id, pos, s_id, scene_info.scene_token, &proto::EnterType::EnterGoto); } + + pub fn process_unlock_trans_point(&self, user_id: u32, metadata: &proto::PacketHead, req: &proto::UnlockTransPointReq, rsp: &mut proto::UnlockTransPointRsp) { + let scene_id = req.scene_id; + let point_id = req.point_id; + + self.db.add_scene_trans_point(user_id, scene_id, point_id); + + // TODO: for unknown points we can just use player's position and add them to our collection + + build_and_send!(self, user_id, metadata, ScenePointUnlockNotify { + scene_id: scene_id, + point_list: vec![point_id], + }); + } } \ No newline at end of file