start work on message delivery

This commit is contained in:
Maple Nebel 2026-06-19 19:50:38 +02:00
commit c54d022d8f
5 changed files with 94 additions and 6 deletions

View file

@ -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);
}
}*/
}*/

View file

@ -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<UserMessage>) -> 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)
}
}

View file

@ -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<UserMessage>) -> Result<(), ErrorCode>;
}
#[rmc_proto(27, NoReturn)]
pub trait MessageDeliveryNoResponse {
#[method_id(1)]
async fn deliver_message(&self, message: Any<UserMessage>);
}

View file

@ -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,
}

View file

@ -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;