1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-05-06 04:37:46 +00:00

Begin separating chat IPC, fix tests

This commit is contained in:
Joshua Goins 2025-05-01 23:34:06 -04:00
parent 5420225c74
commit b426de677f
7 changed files with 75 additions and 31 deletions

View file

@ -1,10 +1,5 @@
{ {
"ServerZoneIpcType": [ "ServerZoneIpcType": [
{
"name": "InitializeChat",
"opcode": 2,
"size": 8
},
{ {
"name": "InitZone", "name": "InitZone",
"opcode": 790, "opcode": 790,
@ -273,6 +268,13 @@
"size": 48 "size": 48
} }
], ],
"ServerChatIpcType": [
{
"name": "LoginReply",
"opcode": 2,
"size": 8
}
],
"ServerLobbyIpcType": [ "ServerLobbyIpcType": [
{ {
"name": "NackReply", "name": "NackReply",

40
src/world/chat.rs Normal file
View file

@ -0,0 +1,40 @@
use binrw::binrw;
use crate::{
opcodes::ServerChatIpcType,
packet::{IpcSegment, ReadWriteIpcSegment},
};
pub type ServerChatIpcSegment = IpcSegment<ServerChatIpcType, ServerChatIpcData>;
impl ReadWriteIpcSegment for ServerChatIpcSegment {
fn calc_size(&self) -> u32 {
// 16 is the size of the IPC header
16 + self.op_code.calc_size()
}
}
// TODO: make generic
impl Default for ServerChatIpcSegment {
fn default() -> Self {
Self {
unk1: 0x14,
unk2: 0,
op_code: ServerChatIpcType::LoginReply,
server_id: 0,
timestamp: 0,
data: ServerChatIpcData::LoginReply {
timestamp: 0,
sid: 0,
},
}
}
}
#[binrw]
#[br(import(_magic: &ServerChatIpcType))]
#[derive(Debug, Clone)]
pub enum ServerChatIpcData {
/// Sent by the server to Initialize something chat-related?
LoginReply { timestamp: u32, sid: u32 },
}

View file

@ -12,11 +12,12 @@ use crate::{
OBFUSCATION_ENABLED_MODE, OBFUSCATION_ENABLED_MODE,
common::{GameData, ObjectId, Position, timestamp_secs}, common::{GameData, ObjectId, Position, timestamp_secs},
config::get_config, config::get_config,
opcodes::ServerZoneIpcType, opcodes::{ServerChatIpcType, ServerZoneIpcType},
packet::{ packet::{
CompressionType, ConnectionType, PacketSegment, PacketState, SegmentType, parse_packet, CompressionType, ConnectionType, PacketSegment, PacketState, SegmentType, parse_packet,
send_packet, send_packet,
}, },
world::chat::{ServerChatIpcData, ServerChatIpcSegment},
}; };
use super::{ use super::{
@ -169,7 +170,7 @@ impl ZoneConnection {
.await; .await;
} }
pub async fn send_chat_segment(&mut self, segment: PacketSegment<ServerZoneIpcSegment>) { pub async fn send_chat_segment(&mut self, segment: PacketSegment<ServerChatIpcSegment>) {
send_packet( send_packet(
&mut self.socket, &mut self.socket,
&mut self.state, &mut self.state,
@ -248,10 +249,13 @@ impl ZoneConnection {
assert!(self.player_data.actor_id != 0); assert!(self.player_data.actor_id != 0);
{ {
let ipc = ServerZoneIpcSegment { let ipc = ServerChatIpcSegment {
op_code: ServerZoneIpcType::InitializeChat, op_code: ServerChatIpcType::LoginReply,
timestamp: timestamp_secs(), timestamp: timestamp_secs(),
data: ServerZoneIpcData::InitializeChat { unk: [0; 8] }, data: ServerChatIpcData::LoginReply {
timestamp: 0,
sid: 0,
},
..Default::default() ..Default::default()
}; };

View file

@ -49,7 +49,9 @@ mod tests {
let mut buffer = Cursor::new(&buffer); let mut buffer = Cursor::new(&buffer);
let init_zone = InitZone::read_le(&mut buffer).unwrap(); let init_zone = InitZone::read_le(&mut buffer).unwrap();
assert_eq!(init_zone.zone_id, 182); assert_eq!(init_zone.zone_id, 1);
assert_eq!(init_zone.territory_type, 182);
assert_eq!(init_zone.territory_index, 0);
assert_eq!(init_zone.weather_id, 2); assert_eq!(init_zone.weather_id, 2);
assert_eq!(init_zone.position.x, 40.519722); assert_eq!(init_zone.position.x, 40.519722);
assert_eq!(init_zone.position.y, 4.0); assert_eq!(init_zone.position.y, 4.0);

View file

@ -44,7 +44,7 @@ mod tests {
let modify_inventory = InventoryModify::read_le(&mut buffer).unwrap(); let modify_inventory = InventoryModify::read_le(&mut buffer).unwrap();
assert_eq!(modify_inventory.context_id, 0x10000000); assert_eq!(modify_inventory.context_id, 0x10000000);
assert_eq!(modify_inventory.operation_type, 128); assert_eq!(modify_inventory.operation_type, 60);
assert_eq!(modify_inventory.src_actor_id, 0); assert_eq!(modify_inventory.src_actor_id, 0);
assert_eq!(modify_inventory.src_storage_id, ContainerType::Equipped); assert_eq!(modify_inventory.src_storage_id, ContainerType::Equipped);
assert_eq!(modify_inventory.src_container_index, 3); assert_eq!(modify_inventory.src_container_index, 3);

View file

@ -122,10 +122,10 @@ impl Default for ServerZoneIpcSegment {
Self { Self {
unk1: 0x14, unk1: 0x14,
unk2: 0, unk2: 0,
op_code: ServerZoneIpcType::InitializeChat, op_code: ServerZoneIpcType::InitZone,
server_id: 0, server_id: 0,
timestamp: 0, timestamp: 0,
data: ServerZoneIpcData::InitializeChat { unk: [0; 8] }, data: ServerZoneIpcData::InitZone(InitZone::default()),
} }
} }
} }
@ -146,8 +146,6 @@ pub enum GameMasterCommandType {
#[br(import(_magic: &ServerZoneIpcType))] #[br(import(_magic: &ServerZoneIpcType))]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum ServerZoneIpcData { pub enum ServerZoneIpcData {
/// Sent by the server to Initialize something chat-related?
InitializeChat { unk: [u8; 8] },
/// Sent by the server as response to ZoneInitRequest. /// Sent by the server as response to ZoneInitRequest.
InitResponse { InitResponse {
unk1: u64, unk1: u64,
@ -371,10 +369,6 @@ mod tests {
#[test] #[test]
fn world_ipc_sizes() { fn world_ipc_sizes() {
let ipc_types = [ let ipc_types = [
(
ServerZoneIpcType::InitializeChat,
ServerZoneIpcData::InitializeChat { unk: [0; 8] },
),
( (
ServerZoneIpcType::InitResponse, ServerZoneIpcType::InitResponse,
ServerZoneIpcData::InitResponse { ServerZoneIpcData::InitResponse {
@ -396,8 +390,8 @@ mod tests {
ServerZoneIpcData::PlayerStats(PlayerStats::default()), ServerZoneIpcData::PlayerStats(PlayerStats::default()),
), ),
( (
ServerZoneIpcType::PlayerSetup, ServerZoneIpcType::PlayerStatus,
ServerZoneIpcData::PlayerSetup(PlayerSetup::default()), ServerZoneIpcData::PlayerStatus(PlayerSetup::default()),
), ),
( (
ServerZoneIpcType::UpdateClassInfo, ServerZoneIpcType::UpdateClassInfo,
@ -412,8 +406,8 @@ mod tests {
ServerZoneIpcData::LogOutComplete { unk: [0; 8] }, ServerZoneIpcData::LogOutComplete { unk: [0; 8] },
), ),
( (
ServerZoneIpcType::ActorSetPos, ServerZoneIpcType::Warp,
ServerZoneIpcData::ActorSetPos(ActorSetPos::default()), ServerZoneIpcData::Warp(ActorSetPos::default()),
), ),
( (
ServerZoneIpcType::ServerChatMessage, ServerZoneIpcType::ServerChatMessage,
@ -432,7 +426,7 @@ mod tests {
), ),
( (
ServerZoneIpcType::Move, ServerZoneIpcType::Move,
ServerZoneIpcData::ActorMove(ActorMove::default()), ServerZoneIpcData::Move(ActorMove::default()),
), ),
( (
ServerZoneIpcType::NpcSpawn, ServerZoneIpcType::NpcSpawn,
@ -443,20 +437,20 @@ mod tests {
ServerZoneIpcData::StatusEffectList(StatusEffectList::default()), ServerZoneIpcData::StatusEffectList(StatusEffectList::default()),
), ),
( (
ServerZoneIpcType::WeatherChange, ServerZoneIpcType::WeatherId,
ServerZoneIpcData::WeatherChange(WeatherChange::default()), ServerZoneIpcData::WeatherId(WeatherChange::default()),
), ),
( (
ServerZoneIpcType::ItemInfo, ServerZoneIpcType::UpdateItem,
ServerZoneIpcData::ItemInfo(ItemInfo::default()), ServerZoneIpcData::UpdateItem(ItemInfo::default()),
), ),
( (
ServerZoneIpcType::ContainerInfo, ServerZoneIpcType::ContainerInfo,
ServerZoneIpcData::ContainerInfo(ContainerInfo::default()), ServerZoneIpcData::ContainerInfo(ContainerInfo::default()),
), ),
( (
ServerZoneIpcType::EventPlay, ServerZoneIpcType::EventScene,
ServerZoneIpcData::EventPlay(EventPlay::default()), ServerZoneIpcData::EventScene(EventPlay::default()),
), ),
( (
ServerZoneIpcType::EventStart, ServerZoneIpcType::EventStart,

View file

@ -28,3 +28,5 @@ pub use actor::Actor;
mod status_effects; mod status_effects;
pub use status_effects::StatusEffects; pub use status_effects::StatusEffects;
pub mod chat;