fix port binding

This commit is contained in:
Maple 2026-03-24 15:48:56 +01:00
commit 785341e883
43 changed files with 1543 additions and 431 deletions

View file

@ -1,14 +1,16 @@
use macros::RmcSerialize;
use rnex_core::kerberos::KerberosDateTime;
use rnex_core::rmc::structures::variant::Variant;
use macros::RmcSerialize;
use rnex_core::PID;
// rmc structure
#[derive(RmcSerialize, Debug, Clone, Default)]
#[rmc_struct(0)]
pub struct Gathering {
pub self_gid: u32,
pub owner_pid: u32,
pub host_pid: u32,
pub owner_pid: PID,
pub host_pid: PID,
pub minimum_participants: u16,
pub maximum_participants: u16,
pub participant_policy: u32,
@ -73,7 +75,7 @@ pub struct MatchmakeSessionSearchCriteria {
#[rmc_struct(0)]
pub struct AutoMatchmakeParam {
pub matchmake_session: MatchmakeSession,
pub additional_participants: Vec<u32>,
pub additional_participants: Vec<PID>,
pub gid_for_participation_check: u32,
pub auto_matchmake_option: u32,
pub join_message: String,
@ -86,7 +88,7 @@ pub struct AutoMatchmakeParam {
#[rmc_struct(0)]
pub struct CreateMatchmakeSessionParam {
pub matchmake_session: MatchmakeSession,
pub additional_participants: Vec<u32>,
pub additional_participants: Vec<PID>,
pub gid_for_participation_check: u32,
pub create_matchmake_session_option: u32,
pub join_message: String,
@ -103,7 +105,7 @@ pub struct MatchmakeBlockListParam {
#[rmc_struct(0)]
pub struct JoinMatchmakeSessionParam {
pub gid: u32,
pub additional_participants: Vec<u32>,
pub additional_participants: Vec<PID>,
pub gid_for_participation_check: u32,
pub join_matchmake_session_open: u32,
pub join_matchmake_session_behavior: u8,

View file

@ -1,9 +1,37 @@
use std::io::{Read, Write};
use std::net::{Ipv4Addr, SocketAddrV4};
use crate::rmc::structures::{Error, Result, RmcSerialize};
use rnex_core::prudp::virtual_port::VirtualPort;
use crate::rmc::structures::RmcSerialize;
use std::io::{Read, Write};
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
impl RmcSerialize for SocketAddrV4{
impl RmcSerialize for SocketAddr {
fn deserialize(reader: &mut impl std::io::Read) -> Result<Self>
where
Self: Sized,
{
let val: u8 = reader.read_struct(IS_BIG_ENDIAN)?;
match val {
4 => Ok(SocketAddr::V4(SocketAddrV4::deserialize(reader)?)),
6 => Ok(SocketAddr::V6(SocketAddrV6::deserialize(reader)?)),
v => Err(Error::UnexpectedValue(v as u64)),
}
}
fn serialize(&self, writer: &mut impl Write) -> Result<()> {
match self {
SocketAddr::V4(v) => {
writer.write_all(&[4])?;
v.serialize(writer)?;
}
SocketAddr::V6(v) => {
writer.write_all(&[6])?;
v.serialize(writer)?;
}
}
Ok(())
}
}
impl RmcSerialize for SocketAddrV4 {
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
self.ip().to_bits().serialize(writer)?;
self.port().serialize(writer)?;
@ -21,9 +49,35 @@ impl RmcSerialize for SocketAddrV4{
Ok(6)
}
}
impl RmcSerialize for SocketAddrV6 {
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
self.ip().to_bits().serialize(writer)?;
self.port().serialize(writer)?;
self.flowinfo().serialize(writer)?;
self.scope_id().serialize(writer)?;
Ok(())
}
impl RmcSerialize for VirtualPort{
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
let ip = u128::deserialize(reader)?;
let port = u16::deserialize(reader)?;
let flowinfo = u32::deserialize(reader)?;
let scope_id = u32::deserialize(reader)?;
Ok(SocketAddrV6::new(
Ipv6Addr::from_bits(ip),
port,
flowinfo,
scope_id,
))
}
fn serialize_write_size(&self) -> crate::rmc::structures::Result<u32> {
Ok(6)
}
}
impl RmcSerialize for VirtualPort {
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
self.0.serialize(writer)?;
@ -36,4 +90,4 @@ impl RmcSerialize for VirtualPort{
fn serialize_write_size(&self) -> crate::rmc::structures::Result<u32> {
Ok(1)
}
}
}

View file

@ -1,5 +1,5 @@
use crate::rmc::structures::RmcSerialize;
use bytemuck::bytes_of;
use bytemuck::{bytes_of, bytes_of_mut};
use std::io::{Read, Write};
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
@ -110,6 +110,23 @@ impl RmcSerialize for u64 {
}
}
impl RmcSerialize for u128 {
#[inline(always)]
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {
Ok(writer.write_all(bytes_of(self))?)
}
#[inline(always)]
fn deserialize(reader: &mut impl Read) -> crate::rmc::structures::Result<Self> {
let mut data = 0u128;
reader.read_exact(&mut bytes_of_mut(&mut data))?;
Ok(data)
}
#[inline(always)]
fn serialize_write_size(&self) -> crate::rmc::structures::Result<u32> {
Ok(8)
}
}
impl RmcSerialize for i64 {
#[inline(always)]
fn serialize(&self, writer: &mut impl Write) -> crate::rmc::structures::Result<()> {

View file

@ -20,55 +20,3 @@ struct UploadCompetitionData {
struct UserData {
name: [u16; 0x10],
}
#[cfg(test)]
mod test {
use crate::rmc::structures::ranking::{UploadCompetitionData, UserData};
use bytemuck::from_bytes;
use rnex_core::rmc::structures::RmcSerialize;
use std::io::Cursor;
#[test]
fn test() {
return;
let data: [u8; 0xBD] = [
0x00, 0xB8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFC, 0x03, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0xA0,
0x00, 0x00, 0x49, 0x00, 0x7A, 0x00, 0x7A, 0x00, 0x79, 0x00, 0x53, 0x00, 0x50, 0x00,
0x46, 0x00, 0x4E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0xF2, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x1F, 0x5E, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x90, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x14, 0x87, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
0x00, 0x00, 0x00, 0x4C, 0x00, 0x00, 0x00,
];
let mut cursor = Cursor::new(data);
let data =
UploadCompetitionData::deserialize(&mut cursor).expect("unable to deserialize data");
let user_data: &UserData = from_bytes(&data.player_data.0[..size_of::<UserData>()]);
let pos = user_data
.name
.iter()
.position(|v| *v == 0x0000)
.unwrap_or(0x10);
let mut name = user_data.name[0..pos].to_vec();
name.iter_mut().for_each(|v| *v = v.swap_bytes());
let name = String::from_utf16(&name).expect("unable to get name");
println!("{:?}", name);
assert!(u8::deserialize(&mut cursor).is_err())
}
}