1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-29 09:57:46 +00:00

Move more structs out of the root src/ folder and into their respective server

This commit is contained in:
Joshua Goins 2025-03-16 15:39:44 -04:00
parent bdef7752b0
commit 23050e7b95
12 changed files with 96 additions and 90 deletions

View file

@ -1,6 +1,6 @@
use kawari::CONTENT_ID; use kawari::CONTENT_ID;
use kawari::chara_make::CharaMake;
use kawari::ipc::{CharacterDetails, IPCOpCode, IPCSegment, IPCStructData, LobbyCharacterAction}; use kawari::ipc::{CharacterDetails, IPCOpCode, IPCSegment, IPCStructData, LobbyCharacterAction};
use kawari::lobby::chara_make::CharaMake;
use kawari::lobby::connection::LobbyConnection; use kawari::lobby::connection::LobbyConnection;
use kawari::oodle::FFXIVOodle; use kawari::oodle::FFXIVOodle;
use kawari::packet::{PacketSegment, SegmentType, State, send_keep_alive}; use kawari::packet::{PacketSegment, SegmentType, State, send_keep_alive};

View file

@ -9,7 +9,7 @@ use kawari::world::{
}; };
use kawari::{ use kawari::{
CHAR_NAME, CITY_STATE, CONTENT_ID, CUSTOMIZE_DATA, DEITY, NAMEDAY_DAY, NAMEDAY_MONTH, WORLD_ID, 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::io::AsyncReadExt;
use tokio::net::TcpListener; use tokio::net::TcpListener;

View file

@ -3,7 +3,7 @@ use serde_json::{Value, json};
#[binrw] #[binrw]
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct ClientCustomizeData { pub struct CustomizeData {
pub race: u8, pub race: u8,
pub gender: u8, pub gender: u8,
pub age: u8, pub age: u8,
@ -32,7 +32,7 @@ pub struct ClientCustomizeData {
pub face_paint_color: u8, pub face_paint_color: u8,
} }
impl ClientCustomizeData { impl CustomizeData {
pub fn to_json(&self) -> Value { pub fn to_json(&self) -> Value {
json!([ json!([
self.race.to_string(), 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()
}
}

View file

@ -3,6 +3,9 @@ use std::{
time::{SystemTime, UNIX_EPOCH}, time::{SystemTime, UNIX_EPOCH},
}; };
mod customize_data;
pub use customize_data::CustomizeData;
pub(crate) fn read_string(byte_stream: Vec<u8>) -> String { pub(crate) fn read_string(byte_stream: Vec<u8>) -> String {
let str = String::from_utf8(byte_stream).unwrap(); let str = String::from_utf8(byte_stream).unwrap();
str.trim_matches(char::from(0)).to_string() // trim \0 from the end of strings str.trim_matches(char::from(0)).to_string() // trim \0 from the end of strings

View file

@ -239,7 +239,7 @@ pub enum IPCStructData {
ClientVersionInfo { ClientVersionInfo {
sequence: u64, 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(count = 64)]
#[br(map = read_string)] #[br(map = read_string)]
#[bw(ignore)] #[bw(ignore)]

View file

@ -1,13 +1,10 @@
use client_select_data::ClientCustomizeData; use common::CustomizeData;
use minijinja::Environment; use minijinja::Environment;
use rand::Rng; use rand::Rng;
use rand::distributions::Alphanumeric; use rand::distributions::Alphanumeric;
pub mod blowfish; pub mod blowfish;
pub mod chara_make; pub mod common;
pub mod client_select_data;
mod common;
pub use common::timestamp_secs;
mod compression; mod compression;
pub mod config; pub mod config;
pub mod encryption; pub mod encryption;
@ -27,7 +24,7 @@ pub const ZONE_ID: u16 = 132;
pub const CONTENT_ID: u64 = 11111111111111111; pub const CONTENT_ID: u64 = 11111111111111111;
pub const CUSTOMIZE_DATA: ClientCustomizeData = ClientCustomizeData { pub const CUSTOMIZE_DATA: CustomizeData = CustomizeData {
race: 4, race: 4,
gender: 1, gender: 1,
age: 1, age: 1,

View file

@ -1,10 +1,10 @@
use serde_json::Value; use serde_json::Value;
use crate::client_select_data::ClientCustomizeData; use crate::common::CustomizeData;
#[derive(Debug)] #[derive(Debug)]
pub struct CharaMake { pub struct CharaMake {
pub customize: ClientCustomizeData, pub customize: CustomizeData,
pub unk1: i32, // always 1? pub unk1: i32, // always 1?
pub guardian: i32, pub guardian: i32,
pub birth_month: i32, pub birth_month: i32,
@ -19,7 +19,7 @@ impl CharaMake {
let content = &v["content"]; let content = &v["content"];
Self { Self {
customize: ClientCustomizeData::from_json(&content[0]), customize: CustomizeData::from_json(&content[0]),
unk1: content[1].as_str().unwrap().parse::<i32>().unwrap(), unk1: content[1].as_str().unwrap().parse::<i32>().unwrap(),
guardian: content[2].as_str().unwrap().parse::<i32>().unwrap(), guardian: content[2].as_str().unwrap().parse::<i32>().unwrap(),
birth_month: content[3].as_str().unwrap().parse::<i32>().unwrap(), birth_month: content[3].as_str().unwrap().parse::<i32>().unwrap(),

View file

@ -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()
}
}

View file

@ -6,7 +6,6 @@ use crate::{
CHAR_NAME, CONTENT_ID, CUSTOMIZE_DATA, DEITY, NAMEDAY_DAY, NAMEDAY_MONTH, WORLD_ID, WORLD_NAME, CHAR_NAME, CONTENT_ID, CUSTOMIZE_DATA, DEITY, NAMEDAY_DAY, NAMEDAY_MONTH, WORLD_ID, WORLD_NAME,
ZONE_ID, ZONE_ID,
blowfish::Blowfish, blowfish::Blowfish,
client_select_data::ClientSelectData,
common::timestamp_secs, common::timestamp_secs,
encryption::generate_encryption_key, encryption::generate_encryption_key,
ipc::{CharacterDetails, IPCOpCode, IPCSegment, IPCStructData, Server, ServiceAccount}, ipc::{CharacterDetails, IPCOpCode, IPCSegment, IPCStructData, Server, ServiceAccount},
@ -16,6 +15,8 @@ use crate::{
}, },
}; };
use super::client_select_data::ClientSelectData;
pub struct LobbyConnection { pub struct LobbyConnection {
pub socket: TcpStream, pub socket: TcpStream,

View file

@ -1 +1,3 @@
pub mod chara_make;
mod client_select_data;
pub mod connection; pub mod connection;

View file

@ -1,8 +1,8 @@
use crate::{ use crate::{
CHAR_NAME, CUSTOMIZE_DATA, WORLD_ID, CHAR_NAME, CUSTOMIZE_DATA, WORLD_ID,
common::timestamp_secs,
ipc::{IPCOpCode, IPCSegment, IPCStructData}, ipc::{IPCOpCode, IPCSegment, IPCStructData},
packet::{PacketSegment, SegmentType}, packet::{PacketSegment, SegmentType},
timestamp_secs,
world::PlayerSpawn, world::PlayerSpawn,
}; };

View file

@ -1,8 +1,7 @@
use binrw::binrw; use binrw::binrw;
use crate::CHAR_NAME_MAX_LENGTH; use crate::CHAR_NAME_MAX_LENGTH;
use crate::client_select_data::ClientCustomizeData; use crate::common::{CustomizeData, read_string, write_string};
use crate::common::{read_string, write_string};
use super::position::Position; use super::position::Position;
use super::status_effect::StatusEffect; use super::status_effect::StatusEffect;
@ -103,7 +102,7 @@ pub struct PlayerSpawn {
#[br(map = read_string)] #[br(map = read_string)]
#[bw(map = write_string)] #[bw(map = write_string)]
pub name: String, pub name: String,
pub look: ClientCustomizeData, pub look: CustomizeData,
#[br(count = 6)] #[br(count = 6)]
#[bw(pad_size_to = 6)] #[bw(pad_size_to = 6)]
#[br(map = read_string)] #[br(map = read_string)]