mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-26 08:37:44 +00:00
Move IPC opcodes to their own enum & module
This commit is contained in:
parent
6aed610276
commit
970d756809
3 changed files with 29 additions and 14 deletions
11
src/ipc.rs
Normal file
11
src/ipc.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
use binrw::binrw;
|
||||||
|
|
||||||
|
#[binrw]
|
||||||
|
#[brw(repr = u16)]
|
||||||
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
|
pub enum IPCOpCode {
|
||||||
|
/// Sent by the client after exchanging encryption information with the lobby server.
|
||||||
|
ClientVersionInfo = 0x5,
|
||||||
|
/// Sent by the server to inform the client of service accounts.
|
||||||
|
LobbyServiceAccountList = 0xC,
|
||||||
|
}
|
|
@ -2,11 +2,12 @@ use minijinja::Environment;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
|
|
||||||
|
mod common;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod encryption;
|
pub mod encryption;
|
||||||
|
pub mod ipc;
|
||||||
pub mod packet;
|
pub mod packet;
|
||||||
pub mod patchlist;
|
pub mod patchlist;
|
||||||
mod common;
|
|
||||||
|
|
||||||
pub fn generate_sid() -> String {
|
pub fn generate_sid() -> String {
|
||||||
let random_id: String = rand::thread_rng()
|
let random_id: String = rand::thread_rng()
|
||||||
|
|
|
@ -10,7 +10,11 @@ use tokio::{
|
||||||
net::TcpStream,
|
net::TcpStream,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{common::{read_bool_from, read_string, write_bool_as, write_string}, encryption::{blowfish_encode, decrypt, encrypt, generate_encryption_key}};
|
use crate::{
|
||||||
|
common::{read_bool_from, read_string, write_bool_as, write_string},
|
||||||
|
encryption::{blowfish_encode, decrypt, encrypt, generate_encryption_key},
|
||||||
|
ipc::IPCOpCode,
|
||||||
|
};
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(repr = u16)]
|
#[brw(repr = u16)]
|
||||||
|
@ -36,11 +40,11 @@ struct ServiceAccount {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[br(import(magic: u16))]
|
#[br(import(magic: &IPCOpCode))]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum IPCOpCode {
|
enum IPCStructData {
|
||||||
// Client->Server IPC
|
// Client->Server IPC
|
||||||
#[br(pre_assert(magic == 0x5u16))]
|
#[br(pre_assert(*magic == IPCOpCode::ClientVersionInfo))]
|
||||||
ClientVersionInfo {
|
ClientVersionInfo {
|
||||||
#[brw(pad_before = 18)] // full of nonsense i don't understand yet
|
#[brw(pad_before = 18)] // full of nonsense i don't understand yet
|
||||||
#[br(count = 64)]
|
#[br(count = 64)]
|
||||||
|
@ -57,7 +61,6 @@ enum IPCOpCode {
|
||||||
},
|
},
|
||||||
|
|
||||||
// Server->Client IPC
|
// Server->Client IPC
|
||||||
//#[br(pre_assert(magic == 0x000C))]
|
|
||||||
LobbyServiceAccountList {
|
LobbyServiceAccountList {
|
||||||
sequence: u64,
|
sequence: u64,
|
||||||
#[brw(pad_before = 4)]
|
#[brw(pad_before = 4)]
|
||||||
|
@ -75,13 +78,13 @@ enum IPCOpCode {
|
||||||
struct IPCSegment {
|
struct IPCSegment {
|
||||||
unk1: u8,
|
unk1: u8,
|
||||||
unk2: u8,
|
unk2: u8,
|
||||||
op_code: u16,
|
op_code: IPCOpCode,
|
||||||
#[brw(pad_before = 2)] // empty
|
#[brw(pad_before = 2)] // empty
|
||||||
server_id: u16,
|
server_id: u16,
|
||||||
timestamp: u32,
|
timestamp: u32,
|
||||||
#[brw(pad_before = 4)]
|
#[brw(pad_before = 4)]
|
||||||
#[br(args(op_code))]
|
#[br(args(&op_code))]
|
||||||
pub data: IPCOpCode,
|
pub data: IPCStructData,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IPCSegment {
|
impl IPCSegment {
|
||||||
|
@ -89,8 +92,8 @@ impl IPCSegment {
|
||||||
let header = 16;
|
let header = 16;
|
||||||
header
|
header
|
||||||
+ match self.data {
|
+ match self.data {
|
||||||
IPCOpCode::ClientVersionInfo { .. } => todo!(),
|
IPCStructData::ClientVersionInfo { .. } => todo!(),
|
||||||
IPCOpCode::LobbyServiceAccountList { .. } => 19,
|
IPCStructData::LobbyServiceAccountList { .. } => 19,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,7 +289,7 @@ pub async fn parse_packet(socket: &mut WriteHalf<TcpStream>, data: &[u8], state:
|
||||||
}
|
}
|
||||||
SegmentType::IPC { data } => {
|
SegmentType::IPC { data } => {
|
||||||
match &data.data {
|
match &data.data {
|
||||||
IPCOpCode::ClientVersionInfo {
|
IPCStructData::ClientVersionInfo {
|
||||||
session_id,
|
session_id,
|
||||||
version_info,
|
version_info,
|
||||||
} => {
|
} => {
|
||||||
|
@ -307,7 +310,7 @@ pub async fn parse_packet(socket: &mut WriteHalf<TcpStream>, data: &[u8], state:
|
||||||
name: "Test Service Account".to_string(),
|
name: "Test Service Account".to_string(),
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let service_account_list = IPCOpCode::LobbyServiceAccountList {
|
let service_account_list = IPCStructData::LobbyServiceAccountList {
|
||||||
sequence: 0,
|
sequence: 0,
|
||||||
num_service_accounts: service_accounts.len() as u8,
|
num_service_accounts: service_accounts.len() as u8,
|
||||||
unk1: 3,
|
unk1: 3,
|
||||||
|
@ -318,7 +321,7 @@ pub async fn parse_packet(socket: &mut WriteHalf<TcpStream>, data: &[u8], state:
|
||||||
let ipc = IPCSegment {
|
let ipc = IPCSegment {
|
||||||
unk1: 0,
|
unk1: 0,
|
||||||
unk2: 0,
|
unk2: 0,
|
||||||
op_code: 0xC, // FIXME: use enum pls
|
op_code: IPCOpCode::LobbyServiceAccountList,
|
||||||
server_id: 0,
|
server_id: 0,
|
||||||
timestamp,
|
timestamp,
|
||||||
data: service_account_list,
|
data: service_account_list,
|
||||||
|
|
Loading…
Add table
Reference in a new issue