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": [
{
"name": "InitializeChat",
"opcode": 2,
"size": 8
},
{
"name": "InitZone",
"opcode": 790,
@ -273,6 +268,13 @@
"size": 48
}
],
"ServerChatIpcType": [
{
"name": "LoginReply",
"opcode": 2,
"size": 8
}
],
"ServerLobbyIpcType": [
{
"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,
common::{GameData, ObjectId, Position, timestamp_secs},
config::get_config,
opcodes::ServerZoneIpcType,
opcodes::{ServerChatIpcType, ServerZoneIpcType},
packet::{
CompressionType, ConnectionType, PacketSegment, PacketState, SegmentType, parse_packet,
send_packet,
},
world::chat::{ServerChatIpcData, ServerChatIpcSegment},
};
use super::{
@ -169,7 +170,7 @@ impl ZoneConnection {
.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(
&mut self.socket,
&mut self.state,
@ -248,10 +249,13 @@ impl ZoneConnection {
assert!(self.player_data.actor_id != 0);
{
let ipc = ServerZoneIpcSegment {
op_code: ServerZoneIpcType::InitializeChat,
let ipc = ServerChatIpcSegment {
op_code: ServerChatIpcType::LoginReply,
timestamp: timestamp_secs(),
data: ServerZoneIpcData::InitializeChat { unk: [0; 8] },
data: ServerChatIpcData::LoginReply {
timestamp: 0,
sid: 0,
},
..Default::default()
};

View file

@ -49,7 +49,9 @@ mod tests {
let mut buffer = Cursor::new(&buffer);
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.position.x, 40.519722);
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();
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_storage_id, ContainerType::Equipped);
assert_eq!(modify_inventory.src_container_index, 3);

View file

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

View file

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