From a448df65b421734d7b5ebd96a516eac19efa1ba4 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 12 Mar 2025 19:34:15 -0400 Subject: [PATCH] Handle chat messages This makes the server not panic and exit when recieving chat messages from the client, but we only extract the message for now. --- src/bin/kawari-world.rs | 11 +++++++++++ src/ipc.rs | 15 +++++++++++++++ src/world/player_spawn.rs | 10 ++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/bin/kawari-world.rs b/src/bin/kawari-world.rs index c391b33..44f6cc3 100644 --- a/src/bin/kawari-world.rs +++ b/src/bin/kawari-world.rs @@ -362,10 +362,18 @@ async fn main() { server_id: 0, timestamp: timestamp_secs(), data: IPCStructData::PlayerSpawn(PlayerSpawn { + current_world_id: WORLD_ID, + home_world_id: WORLD_ID, + title: 1, + class_job: 35, + name: "Test".to_string(), hp_curr: 100, hp_max: 100, mp_curr: 100, mp_max: 100, + model_type: 1, + spawn_index: 1, + state: 1, ..Default::default() }), }; @@ -442,6 +450,9 @@ async fn main() { IPCStructData::Disconnected { .. } => { tracing::info!("Client disconnected!"); } + IPCStructData::ChatMessage { message } => { + tracing::info!("Client sent chat message: {message}!"); + } _ => panic!( "The server is recieving a IPC response or unknown packet!" ), diff --git a/src/ipc.rs b/src/ipc.rs index ff17905..b0f1537 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -76,6 +76,8 @@ pub enum IPCOpCode { LogOutComplete = 0x369, // Sent by the client when it's actually disconnecting Disconnected = 0x360, + // Sent by the client when they send a chat message + ChatMessage = 0xCA, } #[binrw] @@ -275,6 +277,18 @@ pub enum IPCStructData { // TODO: full of possibly interesting information unk: [u8; 8], }, + #[br(pre_assert(*magic == IPCOpCode::ChatMessage))] + ChatMessage { + // TODO: incomplete + #[br(dbg)] + #[brw(pad_before = 26)] + #[brw(pad_after = 998)] + #[br(count = 32)] + #[bw(pad_size_to = 32)] + #[br(map = read_string)] + #[bw(map = write_string)] + message: String, + }, // Server->Client IPC #[br(pre_assert(false))] @@ -433,6 +447,7 @@ impl IPCSegment { IPCStructData::LogOut { .. } => todo!(), IPCStructData::LogOutComplete { .. } => 8, IPCStructData::Disconnected { .. } => todo!(), + IPCStructData::ChatMessage { .. } => todo!(), } } } diff --git a/src/world/player_spawn.rs b/src/world/player_spawn.rs index 2226dba..f324dc2 100644 --- a/src/world/player_spawn.rs +++ b/src/world/player_spawn.rs @@ -1,10 +1,12 @@ use binrw::binrw; +use crate::common::{read_string, write_string}; + use super::position::Position; use super::status_effect::StatusEffect; #[binrw] -#[derive(Debug, Clone, Copy, Default)] +#[derive(Debug, Clone, Default)] pub struct PlayerSpawn { pub title: u16, pub u1b: u16, @@ -78,7 +80,11 @@ pub struct PlayerSpawn { pub models: [u32; 10], pub unknown6_58: [u8; 10], pub padding3: [u8; 7], - pub name: [u8; 32], + #[br(count = 32)] + #[bw(pad_size_to = 32)] + #[br(map = read_string)] + #[bw(map = write_string)] + pub name: String, pub look: [u8; 26], pub fc_tag: [u8; 6], pub padding: [u8; 26],