Skip to content
This repository was archived by the owner on Oct 12, 2026. It is now read-only.

Commit 83cbbdf

Browse files
thedaxredstrate
authored andcommitted
Add unit tests for size of custom IPC packets
-Via this test I also found the size of RequestCreateCharacter was incorrect!
1 parent edcaaf0 commit 83cbbdf

4 files changed

Lines changed: 97 additions & 5 deletions

File tree

‎resources/data/opcodes.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@
863863
"name": "RequestCreateCharacter",
864864
"comment": "Request the world server to create a character",
865865
"opcode": 1,
866-
"size": 1060
866+
"size": 1064
867867
},
868868
{
869869
"name": "CharacterCreated",
@@ -902,7 +902,7 @@
902902
"size": 8
903903
},
904904
{
905-
"name": "RequestCharacterListRepsonse",
905+
"name": "RequestCharacterListResponse",
906906
"comment": "Response to RequestCharacterList",
907907
"opcode": 8,
908908
"size": 9473

‎src/ipc/kawari/mod.rs‎

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub enum CustomIpcData {
5454
RequestCharacterList {
5555
service_account_id: u64,
5656
},
57-
RequestCharacterListRepsonse {
57+
RequestCharacterListResponse {
5858
#[bw(calc = characters.len() as u8)]
5959
num_characters: u8,
6060
#[br(count = num_characters)]
@@ -116,3 +116,95 @@ impl Default for CustomIpcData {
116116
}
117117
}
118118
}
119+
120+
#[cfg(test)]
121+
mod tests {
122+
use std::io::Cursor;
123+
124+
use binrw::BinWrite;
125+
126+
use crate::packet::{IpcSegmentHeader, ReadWriteIpcOpcode, ReadWriteIpcSegment};
127+
128+
use super::*;
129+
130+
/// Ensure that the IPC data size as reported matches up with what we write
131+
#[test]
132+
fn custom_ipc_sizes() {
133+
let ipc_types = [
134+
CustomIpcData::RequestCreateCharacter {
135+
service_account_id: 0,
136+
name: "".to_string(),
137+
chara_make_json: "".to_string(),
138+
},
139+
CustomIpcData::CharacterCreated {
140+
actor_id: 0,
141+
content_id: 0,
142+
},
143+
CustomIpcData::GetActorId {
144+
content_id: 0,
145+
},
146+
CustomIpcData::ActorIdFound {
147+
actor_id: 0,
148+
},
149+
CustomIpcData::CheckNameIsAvailable {
150+
name: "".to_string(),
151+
},
152+
CustomIpcData::NameIsAvailableResponse {
153+
free: false,
154+
},
155+
CustomIpcData::RequestCharacterList {
156+
service_account_id: 0,
157+
},
158+
CustomIpcData::RequestCharacterListResponse {
159+
characters: vec![CharacterDetails::default(); 8],
160+
},
161+
CustomIpcData::DeleteCharacter {
162+
content_id: 0,
163+
},
164+
CustomIpcData::CharacterDeleted {
165+
deleted: 0,
166+
},
167+
CustomIpcData::ImportCharacter {
168+
service_account_id: 0,
169+
path: "".to_string(),
170+
},
171+
CustomIpcData::RemakeCharacter {
172+
content_id: 0,
173+
chara_make_json: "".to_string(),
174+
},
175+
CustomIpcData::CharacterRemade {
176+
content_id: 0,
177+
},
178+
CustomIpcData::CharacterImported {
179+
message: "".to_string(),
180+
},
181+
CustomIpcData::DeleteServiceAccount {
182+
service_account_id: 0,
183+
},
184+
CustomIpcData::RequestFullCharacterList {}, // Included here for completeness despite the 0 size
185+
CustomIpcData::FullCharacterListResponse {
186+
json: "".to_string(),
187+
},
188+
];
189+
190+
for data in &ipc_types {
191+
let mut cursor = Cursor::new(Vec::new());
192+
193+
let opcode: CustomIpcType = ReadWriteIpcOpcode::from_data(data);
194+
let ipc_segment = CustomIpcSegment {
195+
header: IpcSegmentHeader::from_opcode(opcode.clone()),
196+
data: data.clone(),
197+
..Default::default()
198+
};
199+
ipc_segment.write_le(&mut cursor).unwrap();
200+
201+
let buffer = cursor.into_inner();
202+
203+
assert_eq!(
204+
buffer.len(),
205+
ipc_segment.calc_size() as usize,
206+
"{opcode:#?} did not match size!"
207+
);
208+
}
209+
}
210+
}

‎src/lobby/connection.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl LobbyConnection {
155155
let name_response = send_custom_world_packet(charlist_request)
156156
.await
157157
.expect("Failed to get name request packet!");
158-
let CustomIpcData::RequestCharacterListRepsonse { characters } = &name_response.data
158+
let CustomIpcData::RequestCharacterListResponse { characters } = &name_response.data
159159
else {
160160
panic!("Unexpedted custom IPC type!")
161161
};

‎src/world/custom_ipc_connection.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl CustomIpcConnection {
168168
self.send_custom_response(PacketSegment {
169169
segment_type: SegmentType::KawariIpc,
170170
data: SegmentData::KawariIpc(CustomIpcSegment::new(
171-
CustomIpcData::RequestCharacterListRepsonse { characters },
171+
CustomIpcData::RequestCharacterListResponse { characters },
172172
)),
173173
..Default::default()
174174
})

0 commit comments

Comments
 (0)