From c54d022d8f7d087887e1507a4e05b103f3bf2471 Mon Sep 17 00:00:00 2001 From: Maple Nebel Date: Fri, 19 Jun 2026 19:50:38 +0200 Subject: [PATCH] start work on message delivery --- rnex-core/src/nex/remote_console.rs | 17 ++++++-- rnex-core/src/nex/user.rs | 35 ++++++++++++++++- .../src/rmc/protocols/message_delivery.rs | 8 +++- rnex-core/src/rmc/protocols/messaging.rs | 39 +++++++++++++++++++ rnex-core/src/rmc/protocols/mod.rs | 1 + 5 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 rnex-core/src/rmc/protocols/messaging.rs diff --git a/rnex-core/src/nex/remote_console.rs b/rnex-core/src/nex/remote_console.rs index 3d3cb49..016dca1 100644 --- a/rnex-core/src/nex/remote_console.rs +++ b/rnex-core/src/nex/remote_console.rs @@ -1,11 +1,20 @@ -use crate::rmc::protocols::notifications::{Notification, RawNotification, RawNotificationInfo, RemoteNotification}; -use crate::rmc::protocols::nat_traversal::{NatTraversalConsole, RemoteNatTraversalConsole, RawNatTraversalConsoleInfo, RawNatTraversalConsole}; use crate::define_rmc_proto; +use crate::rmc::protocols::message_delivery::{ + MessageDelivery, RawMessageDelivery, RawMessageDeliveryInfo, RemoteMessageDelivery, +}; +use crate::rmc::protocols::nat_traversal::{ + NatTraversalConsole, RawNatTraversalConsole, RawNatTraversalConsoleInfo, + RemoteNatTraversalConsole, +}; +use crate::rmc::protocols::notifications::{ + Notification, RawNotification, RawNotificationInfo, RemoteNotification, +}; define_rmc_proto!( proto Console{ Notification, - NatTraversalConsole + NatTraversalConsole, + MessageDelivery } ); /* @@ -18,4 +27,4 @@ impl Notification for TestRemoteConsole{ async fn process_notification_event(&self, event: NotificationEvent) { println!("NOTIF RECIEVED: {:?}", event); } -}*/ \ No newline at end of file +}*/ diff --git a/rnex-core/src/nex/user.rs b/rnex-core/src/nex/user.rs index dffe49f..c79401d 100644 --- a/rnex-core/src/nex/user.rs +++ b/rnex-core/src/nex/user.rs @@ -54,6 +54,7 @@ use rnex_core::rmc::structures::ranking::UploadCompetitionData; use std::sync::{Arc, Weak}; use tokio::sync::{Mutex, RwLock}; +use crate::rmc::protocols::messaging::UserMessage; use crate::rmc::structures::matchmake::Gathering; use crate::rmc::structures::matchmake::MatchmakeSessionSearchCriteria; @@ -923,7 +924,39 @@ impl Ranking for User { } impl MessageDelivery for User { - async fn deliver_message(&self, message: Any) -> Result<(), ErrorCode> { + async fn deliver_message(&self, mut message: Any) -> Result<(), ErrorCode> { + let mut msg = message.get()?; + + let users = match msg.recipient_type { + 1 => { + let Some(user) = self + .matchmake_manager + .users_by_pid + .read() + .await + .get(&msg.recipient_id) + .map(Weak::upgrade) + .flatten() + else { + return Err(ErrorCode::Core_InvalidArgument); + }; + if msg.flags & 1 != 0 { + msg.recipient_id = user.pid; + msg.recipient_type = 1; + } + + message.emplace_parent(&msg)?; + + user.remote.deliver_message(message).await; + } + 2 => { + return Err(ErrorCode::Core_NotImplemented); + } + _ => { + return Err(ErrorCode::Core_InvalidArgument); + } + }; + Err(ErrorCode::Core_NotImplemented) } } diff --git a/rnex-core/src/rmc/protocols/message_delivery.rs b/rnex-core/src/rmc/protocols/message_delivery.rs index ea4dd91..8cd806f 100644 --- a/rnex-core/src/rmc/protocols/message_delivery.rs +++ b/rnex-core/src/rmc/protocols/message_delivery.rs @@ -1,6 +1,7 @@ use macros::{method_id, rmc_proto}; use crate::rmc::{ + protocols::messaging::UserMessage, response::ErrorCode, structures::{Error, any::Any}, }; @@ -8,5 +9,10 @@ use crate::rmc::{ #[rmc_proto(27)] pub trait MessageDelivery { #[method_id(1)] - async fn deliver_message(&self, message: Any) -> Result<(), ErrorCode>; + async fn deliver_message(&self, message: Any) -> Result<(), ErrorCode>; +} +#[rmc_proto(27, NoReturn)] +pub trait MessageDeliveryNoResponse { + #[method_id(1)] + async fn deliver_message(&self, message: Any); } diff --git a/rnex-core/src/rmc/protocols/messaging.rs b/rnex-core/src/rmc/protocols/messaging.rs new file mode 100644 index 0000000..9849865 --- /dev/null +++ b/rnex-core/src/rmc/protocols/messaging.rs @@ -0,0 +1,39 @@ +use macros::RmcSerialize; + +use crate::{ + kerberos::KerberosDateTime, + rmc::structures::{data::Data, qbuffer::QBuffer}, +}; + +#[derive(RmcSerialize, Debug, Clone)] +#[rmc_struct(0)] +pub struct UserMessage { + #[extends] + pub data: Data, + pub id: u32, + pub recipient_id: i32, + pub recipient_type: u32, + pub parent_id: u32, + pub pid_sender: u32, + pub receptiontime: KerberosDateTime, + pub life_time: u32, + pub flags: u32, + pub subject: String, + pub sender: String, +} + +#[derive(RmcSerialize, Debug, Clone)] +#[rmc_struct(0)] +pub struct TextMessage { + #[extends] + pub msg: UserMessage, + pub text_body: String, +} + +#[derive(RmcSerialize, Debug, Clone)] +#[rmc_struct(0)] +pub struct BinaryMessage { + #[extends] + pub msg: UserMessage, + pub text_body: QBuffer, +} diff --git a/rnex-core/src/rmc/protocols/mod.rs b/rnex-core/src/rmc/protocols/mod.rs index d9e8482..5da022c 100644 --- a/rnex-core/src/rmc/protocols/mod.rs +++ b/rnex-core/src/rmc/protocols/mod.rs @@ -9,6 +9,7 @@ pub mod matchmake; pub mod matchmake_ext; pub mod matchmake_extension; pub mod message_delivery; +pub mod messaging; pub mod nat_traversal; pub mod nintendo_notification; pub mod notifications;