From 23050e7b952427c63871c913bb3d9b3eafe3b997 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 16 Mar 2025 15:39:44 -0400 Subject: [PATCH] Move more structs out of the root src/ folder and into their respective server --- src/bin/kawari-lobby.rs | 2 +- src/bin/kawari-world.rs | 2 +- .../customize_data.rs} | 75 +------------------ src/{common.rs => common/mod.rs} | 3 + src/ipc.rs | 2 +- src/lib.rs | 9 +-- src/{ => lobby}/chara_make.rs | 6 +- src/lobby/client_select_data.rs | 75 +++++++++++++++++++ src/lobby/connection.rs | 3 +- src/lobby/mod.rs | 2 + src/world/chat_handler.rs | 2 +- src/world/player_spawn.rs | 5 +- 12 files changed, 96 insertions(+), 90 deletions(-) rename src/{client_select_data.rs => common/customize_data.rs} (62%) rename src/{common.rs => common/mod.rs} (91%) rename src/{ => lobby}/chara_make.rs (89%) create mode 100644 src/lobby/client_select_data.rs diff --git a/src/bin/kawari-lobby.rs b/src/bin/kawari-lobby.rs index 33b8de6..883d7ce 100644 --- a/src/bin/kawari-lobby.rs +++ b/src/bin/kawari-lobby.rs @@ -1,6 +1,6 @@ use kawari::CONTENT_ID; -use kawari::chara_make::CharaMake; use kawari::ipc::{CharacterDetails, IPCOpCode, IPCSegment, IPCStructData, LobbyCharacterAction}; +use kawari::lobby::chara_make::CharaMake; use kawari::lobby::connection::LobbyConnection; use kawari::oodle::FFXIVOodle; use kawari::packet::{PacketSegment, SegmentType, State, send_keep_alive}; diff --git a/src/bin/kawari-world.rs b/src/bin/kawari-world.rs index 32e26c3..91e5eae 100644 --- a/src/bin/kawari-world.rs +++ b/src/bin/kawari-world.rs @@ -9,7 +9,7 @@ use kawari::world::{ }; use kawari::{ CHAR_NAME, CITY_STATE, CONTENT_ID, CUSTOMIZE_DATA, DEITY, NAMEDAY_DAY, NAMEDAY_MONTH, WORLD_ID, - ZONE_ID, timestamp_secs, + ZONE_ID, common::timestamp_secs, }; use tokio::io::AsyncReadExt; use tokio::net::TcpListener; diff --git a/src/client_select_data.rs b/src/common/customize_data.rs similarity index 62% rename from src/client_select_data.rs rename to src/common/customize_data.rs index dc5235a..33f51a7 100644 --- a/src/client_select_data.rs +++ b/src/common/customize_data.rs @@ -3,7 +3,7 @@ use serde_json::{Value, json}; #[binrw] #[derive(Debug, Clone, Default)] -pub struct ClientCustomizeData { +pub struct CustomizeData { pub race: u8, pub gender: u8, pub age: u8, @@ -32,7 +32,7 @@ pub struct ClientCustomizeData { pub face_paint_color: u8, } -impl ClientCustomizeData { +impl CustomizeData { pub fn to_json(&self) -> Value { json!([ self.race.to_string(), @@ -95,74 +95,3 @@ impl ClientCustomizeData { } } } -/// See https://github.com/aers/FFXIVClientStructs/blob/main/FFXIVClientStructs/FFXIV/Application/Network/WorkDefinitions/ClientSelectData.cs -pub struct ClientSelectData { - pub game_name_unk: String, - pub current_class: i32, - pub class_levels: [i32; 30], - pub race: i32, - pub subrace: i32, - pub gender: i32, - pub birth_month: i32, - pub birth_day: i32, - pub guardian: i32, - pub unk8: i32, - pub unk9: i32, - pub zone_id: i32, - pub unk11: i32, - pub customize: ClientCustomizeData, - pub unk12: i32, - pub unk13: i32, - pub unk14: [i32; 10], // probably model ids - pub unk15: i32, - pub unk16: i32, - /// If set to 1, the user is granted one opportunity to edit their character and are prompted to re-choose their class. - pub legacy_character: i32, - pub unk18: i32, - pub unk19: i32, - pub unk20: i32, - pub unk21: String, - pub unk22: i32, - pub unk23: i32, -} - -impl ClientSelectData { - pub fn to_json(&self) -> String { - let content = json!([ - self.game_name_unk, - self.current_class.to_string(), - self.class_levels.map(|x| x.to_string()), - self.race.to_string(), - self.subrace.to_string(), - self.gender.to_string(), - self.birth_month.to_string(), - self.birth_day.to_string(), - self.guardian.to_string(), - self.unk8.to_string(), - self.unk9.to_string(), - self.zone_id.to_string(), - self.unk11.to_string(), - self.customize.to_json(), - self.unk12.to_string(), - self.unk13.to_string(), - self.unk14.map(|x| x.to_string()), - self.unk15.to_string(), - self.unk16.to_string(), - self.legacy_character.to_string(), - self.unk18.to_string(), - self.unk19.to_string(), - self.unk20.to_string(), - self.unk21, - self.unk22.to_string(), - self.unk23.to_string(), - ]); - - let obj = json!({ - "content": content, - "classname": "ClientSelectData", - "classid": 116, - }); - - serde_json::to_string(&obj).unwrap() - } -} diff --git a/src/common.rs b/src/common/mod.rs similarity index 91% rename from src/common.rs rename to src/common/mod.rs index 05d65b6..f75f8a7 100644 --- a/src/common.rs +++ b/src/common/mod.rs @@ -3,6 +3,9 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; +mod customize_data; +pub use customize_data::CustomizeData; + pub(crate) fn read_string(byte_stream: Vec) -> String { let str = String::from_utf8(byte_stream).unwrap(); str.trim_matches(char::from(0)).to_string() // trim \0 from the end of strings diff --git a/src/ipc.rs b/src/ipc.rs index 932c0bb..9b4259f 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -239,7 +239,7 @@ pub enum IPCStructData { ClientVersionInfo { sequence: u64, - #[brw(pad_before = 14)] // full of nonsense i don't understand yet + #[brw(pad_before = 10)] // full of nonsense i don't understand yet #[br(count = 64)] #[br(map = read_string)] #[bw(ignore)] diff --git a/src/lib.rs b/src/lib.rs index 57d75f7..0c3c43d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,13 +1,10 @@ -use client_select_data::ClientCustomizeData; +use common::CustomizeData; use minijinja::Environment; use rand::Rng; use rand::distributions::Alphanumeric; pub mod blowfish; -pub mod chara_make; -pub mod client_select_data; -mod common; -pub use common::timestamp_secs; +pub mod common; mod compression; pub mod config; pub mod encryption; @@ -27,7 +24,7 @@ pub const ZONE_ID: u16 = 132; pub const CONTENT_ID: u64 = 11111111111111111; -pub const CUSTOMIZE_DATA: ClientCustomizeData = ClientCustomizeData { +pub const CUSTOMIZE_DATA: CustomizeData = CustomizeData { race: 4, gender: 1, age: 1, diff --git a/src/chara_make.rs b/src/lobby/chara_make.rs similarity index 89% rename from src/chara_make.rs rename to src/lobby/chara_make.rs index 52908fa..b953343 100644 --- a/src/chara_make.rs +++ b/src/lobby/chara_make.rs @@ -1,10 +1,10 @@ use serde_json::Value; -use crate::client_select_data::ClientCustomizeData; +use crate::common::CustomizeData; #[derive(Debug)] pub struct CharaMake { - pub customize: ClientCustomizeData, + pub customize: CustomizeData, pub unk1: i32, // always 1? pub guardian: i32, pub birth_month: i32, @@ -19,7 +19,7 @@ impl CharaMake { let content = &v["content"]; Self { - customize: ClientCustomizeData::from_json(&content[0]), + customize: CustomizeData::from_json(&content[0]), unk1: content[1].as_str().unwrap().parse::().unwrap(), guardian: content[2].as_str().unwrap().parse::().unwrap(), birth_month: content[3].as_str().unwrap().parse::().unwrap(), diff --git a/src/lobby/client_select_data.rs b/src/lobby/client_select_data.rs new file mode 100644 index 0000000..468ca20 --- /dev/null +++ b/src/lobby/client_select_data.rs @@ -0,0 +1,75 @@ +use serde_json::json; + +use crate::common::CustomizeData; + +/// See https://github.com/aers/FFXIVClientStructs/blob/main/FFXIVClientStructs/FFXIV/Application/Network/WorkDefinitions/ClientSelectData.cs +pub struct ClientSelectData { + pub game_name_unk: String, + pub current_class: i32, + pub class_levels: [i32; 30], + pub race: i32, + pub subrace: i32, + pub gender: i32, + pub birth_month: i32, + pub birth_day: i32, + pub guardian: i32, + pub unk8: i32, + pub unk9: i32, + pub zone_id: i32, + pub unk11: i32, + pub customize: CustomizeData, + pub unk12: i32, + pub unk13: i32, + pub unk14: [i32; 10], // probably model ids + pub unk15: i32, + pub unk16: i32, + /// If set to 1, the user is granted one opportunity to edit their character and are prompted to re-choose their class. + pub legacy_character: i32, + pub unk18: i32, + pub unk19: i32, + pub unk20: i32, + pub unk21: String, + pub unk22: i32, + pub unk23: i32, +} + +impl ClientSelectData { + pub fn to_json(&self) -> String { + let content = json!([ + self.game_name_unk, + self.current_class.to_string(), + self.class_levels.map(|x| x.to_string()), + self.race.to_string(), + self.subrace.to_string(), + self.gender.to_string(), + self.birth_month.to_string(), + self.birth_day.to_string(), + self.guardian.to_string(), + self.unk8.to_string(), + self.unk9.to_string(), + self.zone_id.to_string(), + self.unk11.to_string(), + self.customize.to_json(), + self.unk12.to_string(), + self.unk13.to_string(), + self.unk14.map(|x| x.to_string()), + self.unk15.to_string(), + self.unk16.to_string(), + self.legacy_character.to_string(), + self.unk18.to_string(), + self.unk19.to_string(), + self.unk20.to_string(), + self.unk21, + self.unk22.to_string(), + self.unk23.to_string(), + ]); + + let obj = json!({ + "content": content, + "classname": "ClientSelectData", + "classid": 116, + }); + + serde_json::to_string(&obj).unwrap() + } +} diff --git a/src/lobby/connection.rs b/src/lobby/connection.rs index b6259ae..31a8ea8 100644 --- a/src/lobby/connection.rs +++ b/src/lobby/connection.rs @@ -6,7 +6,6 @@ use crate::{ CHAR_NAME, CONTENT_ID, CUSTOMIZE_DATA, DEITY, NAMEDAY_DAY, NAMEDAY_MONTH, WORLD_ID, WORLD_NAME, ZONE_ID, blowfish::Blowfish, - client_select_data::ClientSelectData, common::timestamp_secs, encryption::generate_encryption_key, ipc::{CharacterDetails, IPCOpCode, IPCSegment, IPCStructData, Server, ServiceAccount}, @@ -16,6 +15,8 @@ use crate::{ }, }; +use super::client_select_data::ClientSelectData; + pub struct LobbyConnection { pub socket: TcpStream, diff --git a/src/lobby/mod.rs b/src/lobby/mod.rs index b3b606b..cf3bc19 100644 --- a/src/lobby/mod.rs +++ b/src/lobby/mod.rs @@ -1 +1,3 @@ +pub mod chara_make; +mod client_select_data; pub mod connection; diff --git a/src/world/chat_handler.rs b/src/world/chat_handler.rs index 896300a..303351b 100644 --- a/src/world/chat_handler.rs +++ b/src/world/chat_handler.rs @@ -1,8 +1,8 @@ use crate::{ CHAR_NAME, CUSTOMIZE_DATA, WORLD_ID, + common::timestamp_secs, ipc::{IPCOpCode, IPCSegment, IPCStructData}, packet::{PacketSegment, SegmentType}, - timestamp_secs, world::PlayerSpawn, }; diff --git a/src/world/player_spawn.rs b/src/world/player_spawn.rs index bf3ebad..6c5c907 100644 --- a/src/world/player_spawn.rs +++ b/src/world/player_spawn.rs @@ -1,8 +1,7 @@ use binrw::binrw; use crate::CHAR_NAME_MAX_LENGTH; -use crate::client_select_data::ClientCustomizeData; -use crate::common::{read_string, write_string}; +use crate::common::{CustomizeData, read_string, write_string}; use super::position::Position; use super::status_effect::StatusEffect; @@ -103,7 +102,7 @@ pub struct PlayerSpawn { #[br(map = read_string)] #[bw(map = write_string)] pub name: String, - pub look: ClientCustomizeData, + pub look: CustomizeData, #[br(count = 6)] #[bw(pad_size_to = 6)] #[br(map = read_string)]