mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-25 08:27:44 +00:00
89 lines
2.8 KiB
Rust
89 lines
2.8 KiB
Rust
|
use binrw::binrw;
|
||
|
|
||
|
use crate::{
|
||
|
CHAR_NAME_MAX_LENGTH,
|
||
|
common::read_string,
|
||
|
packet::{IpcSegment, ReadWriteIpcSegment},
|
||
|
};
|
||
|
|
||
|
use super::write_string;
|
||
|
|
||
|
pub type CustomIpcSegment = IpcSegment<CustomIpcType, CustomIpcData>;
|
||
|
|
||
|
impl ReadWriteIpcSegment for CustomIpcSegment {
|
||
|
fn calc_size(&self) -> u32 {
|
||
|
// 16 is the size of the IPC header
|
||
|
16 + match self.op_code {
|
||
|
CustomIpcType::RequestCreateCharacter => 1024 + CHAR_NAME_MAX_LENGTH as u32,
|
||
|
CustomIpcType::CharacterCreated => 12,
|
||
|
CustomIpcType::GetActorId => 8,
|
||
|
CustomIpcType::ActorIdFound => 4,
|
||
|
CustomIpcType::CheckNameIsAvailable => CHAR_NAME_MAX_LENGTH as u32,
|
||
|
CustomIpcType::NameIsAvailableResponse => 1,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[binrw]
|
||
|
#[brw(repr = u16)]
|
||
|
#[derive(Default, Clone, PartialEq, Debug)]
|
||
|
pub enum CustomIpcType {
|
||
|
#[default]
|
||
|
/// Request the world server to create a character
|
||
|
RequestCreateCharacter = 0x1,
|
||
|
/// Response from the world server when the character is created
|
||
|
CharacterCreated = 0x2,
|
||
|
/// Request the actor id from the content id of a character
|
||
|
GetActorId = 0x3,
|
||
|
/// Response from the world server when the actor id is found
|
||
|
ActorIdFound = 0x4,
|
||
|
/// Check if a name is available on the world server
|
||
|
CheckNameIsAvailable = 0x5,
|
||
|
/// Response to CheckNameIsAvailable
|
||
|
NameIsAvailableResponse = 0x6,
|
||
|
}
|
||
|
|
||
|
#[binrw]
|
||
|
#[br(import(magic: &CustomIpcType))]
|
||
|
#[derive(Debug, Clone)]
|
||
|
pub enum CustomIpcData {
|
||
|
#[br(pre_assert(*magic == CustomIpcType::RequestCreateCharacter))]
|
||
|
RequestCreateCharacter {
|
||
|
#[bw(pad_size_to = CHAR_NAME_MAX_LENGTH)]
|
||
|
#[br(count = CHAR_NAME_MAX_LENGTH)]
|
||
|
#[br(map = read_string)]
|
||
|
#[bw(map = write_string)]
|
||
|
name: String,
|
||
|
#[bw(pad_size_to = 1024)]
|
||
|
#[br(count = 1024)]
|
||
|
#[br(map = read_string)]
|
||
|
#[bw(map = write_string)]
|
||
|
chara_make_json: String,
|
||
|
},
|
||
|
#[br(pre_assert(*magic == CustomIpcType::CharacterCreated))]
|
||
|
CharacterCreated { actor_id: u32, content_id: u64 },
|
||
|
#[br(pre_assert(*magic == CustomIpcType::GetActorId))]
|
||
|
GetActorId { content_id: u64 },
|
||
|
#[br(pre_assert(*magic == CustomIpcType::ActorIdFound))]
|
||
|
ActorIdFound { actor_id: u32 },
|
||
|
#[br(pre_assert(*magic == CustomIpcType::CheckNameIsAvailable))]
|
||
|
CheckNameIsAvailable {
|
||
|
#[bw(pad_size_to = CHAR_NAME_MAX_LENGTH)]
|
||
|
#[br(count = CHAR_NAME_MAX_LENGTH)]
|
||
|
#[br(map = read_string)]
|
||
|
#[bw(map = write_string)]
|
||
|
name: String,
|
||
|
},
|
||
|
#[br(pre_assert(*magic == CustomIpcType::NameIsAvailableResponse))]
|
||
|
NameIsAvailableResponse { free: u8 },
|
||
|
}
|
||
|
|
||
|
impl Default for CustomIpcData {
|
||
|
fn default() -> CustomIpcData {
|
||
|
CustomIpcData::RequestCreateCharacter {
|
||
|
chara_make_json: String::new(),
|
||
|
name: String::new(),
|
||
|
}
|
||
|
}
|
||
|
}
|