fix port binding
This commit is contained in:
parent
dad8ac498c
commit
785341e883
43 changed files with 1543 additions and 431 deletions
4
rnex-core/src/rmc/protocols/account_management.rs
Normal file
4
rnex-core/src/rmc/protocols/account_management.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
use macros::rmc_proto;
|
||||
|
||||
#[rmc_proto(25)]
|
||||
pub trait AccountManagement {}
|
||||
|
|
@ -1,9 +1,21 @@
|
|||
use crate::rmc::structures::connection_data::{ConnectionData, ConnectionDataOld};
|
||||
use cfg_if::cfg_if;
|
||||
use macros::{method_id, rmc_proto};
|
||||
use rnex_core::PID;
|
||||
use rnex_core::rmc::response::ErrorCode;
|
||||
use rnex_core::rmc::structures::any::Any;
|
||||
use rnex_core::rmc::structures::qresult::QResult;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "nx")]{
|
||||
type LOGIN_EX_RET = (QResult, PID, Vec<u8>, ConnectionData, String, String);
|
||||
type REQUEST_TICKET_RET = (QResult, Vec<u8>, String);
|
||||
} else {
|
||||
type LOGIN_EX_RET = (QResult, PID, Vec<u8>, ConnectionData, String);
|
||||
type REQUEST_TICKET_RET = (QResult, Vec<u8>);
|
||||
}
|
||||
}
|
||||
|
||||
/// This is the representation for `Ticket Granting`(for details see the
|
||||
/// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol))
|
||||
#[rmc_proto(10)]
|
||||
|
|
@ -14,25 +26,22 @@ pub trait Auth {
|
|||
async fn login(
|
||||
&self,
|
||||
name: String,
|
||||
) -> Result<(QResult, u32, Vec<u8>, ConnectionDataOld, String), ErrorCode>;
|
||||
) -> Result<(QResult, PID, Vec<u8>, ConnectionDataOld, String), ErrorCode>;
|
||||
|
||||
/// representation of the `LoginEx` method(for details see the
|
||||
/// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol))
|
||||
#[method_id(2)]
|
||||
async fn login_ex(
|
||||
&self,
|
||||
name: String,
|
||||
extra_data: Any,
|
||||
) -> Result<(QResult, u32, Vec<u8>, ConnectionData, String), ErrorCode>;
|
||||
async fn login_ex(&self, name: String, extra_data: Any) -> Result<LOGIN_EX_RET, ErrorCode>;
|
||||
|
||||
/// representation of the `RequestTicket` method(for details see the
|
||||
/// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol))
|
||||
#[method_id(3)]
|
||||
async fn request_ticket(
|
||||
&self,
|
||||
source_pid: u32,
|
||||
destination_pid: u32,
|
||||
) -> Result<(QResult, Vec<u8>), ErrorCode>;
|
||||
source_pid: PID,
|
||||
destination_pid: PID,
|
||||
) -> Result<REQUEST_TICKET_RET, ErrorCode>;
|
||||
|
||||
/// representation of the `RequestTicket` method(for details see the
|
||||
/// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol))
|
||||
|
||||
/// representation of the `GetPID` method(for details see the
|
||||
/// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol))
|
||||
|
|
@ -42,7 +51,7 @@ pub trait Auth {
|
|||
/// representation of the `LoginWithContext` method(for details see the
|
||||
/// [kinnay wiki entry](https://github.com/kinnay/NintendoClients/wiki/Authentication-Protocol))
|
||||
#[method_id(5)]
|
||||
async fn get_name(&self, pid: u32) -> Result<String, ErrorCode>;
|
||||
async fn get_name(&self, pid: PID) -> Result<String, ErrorCode>;
|
||||
|
||||
// `LoginWithContext` is left out here because we don't need it right now and versioning still
|
||||
// needs to be figured out
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ use macros::{method_id, rmc_proto};
|
|||
use rnex_core::prudp::station_url::StationUrl;
|
||||
use rnex_core::rmc::response::ErrorCode;
|
||||
|
||||
use rnex_core::PID;
|
||||
|
||||
#[rmc_proto(21)]
|
||||
pub trait Matchmake{
|
||||
pub trait Matchmake {
|
||||
#[method_id(2)]
|
||||
async fn unregister_gathering(&self, gid: u32) -> Result<bool, ErrorCode>;
|
||||
#[method_id(41)]
|
||||
|
|
@ -11,5 +13,10 @@ pub trait Matchmake{
|
|||
#[method_id(42)]
|
||||
async fn update_session_host(&self, gid: u32, change_owner: bool) -> Result<(), ErrorCode>;
|
||||
#[method_id(44)]
|
||||
async fn migrate_gathering_ownership(&self, gid: u32, candidates: Vec<u32>, participants_only: bool) -> Result<(), ErrorCode>;
|
||||
}
|
||||
async fn migrate_gathering_ownership(
|
||||
&self,
|
||||
gid: u32,
|
||||
candidates: Vec<PID>,
|
||||
participants_only: bool,
|
||||
) -> Result<(), ErrorCode>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#![allow(async_fn_in_trait)]
|
||||
|
||||
pub mod account_management;
|
||||
pub mod auth;
|
||||
pub mod friends;
|
||||
pub mod matchmake;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
use macros::{method_id, rmc_proto, rmc_struct, RmcSerialize};
|
||||
use macros::{RmcSerialize, method_id, rmc_proto, rmc_struct};
|
||||
|
||||
pub mod notification_types{
|
||||
use rnex_core::PID;
|
||||
|
||||
pub mod notification_types {
|
||||
pub const OWNERSHIP_CHANGED: u32 = 4000;
|
||||
pub const HOST_CHANGED: u32 = 110000;
|
||||
}
|
||||
|
||||
#[derive(RmcSerialize, Debug, Default, Clone)]
|
||||
#[rmc_struct(0)]
|
||||
pub struct NotificationEvent{
|
||||
pub pid_source: u32,
|
||||
pub struct NotificationEvent {
|
||||
pub pid_source: PID,
|
||||
pub notif_type: u32,
|
||||
pub param_1: u32,
|
||||
pub param_2: u32,
|
||||
pub param_1: PID,
|
||||
pub param_2: PID,
|
||||
pub str_param: String,
|
||||
pub param_3: u32,
|
||||
pub param_3: PID,
|
||||
}
|
||||
|
||||
#[rmc_proto(14, NoReturn)]
|
||||
|
|
@ -21,4 +23,3 @@ pub trait Notification {
|
|||
#[method_id(1)]
|
||||
async fn process_notification_event(&self, event: NotificationEvent);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ pub trait Secure {
|
|||
&self,
|
||||
station_urls: Vec<StationUrl>,
|
||||
) -> Result<(QResult, u32, StationUrl), ErrorCode>;
|
||||
|
||||
#[method_id(4)]
|
||||
async fn register_ex(
|
||||
&self,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<()> {
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue