forked from spacebar/rust-nex
start work on message delivery
This commit is contained in:
parent
3353a99e54
commit
c54d022d8f
5 changed files with 94 additions and 6 deletions
|
|
@ -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::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!(
|
define_rmc_proto!(
|
||||||
proto Console{
|
proto Console{
|
||||||
Notification,
|
Notification,
|
||||||
NatTraversalConsole
|
NatTraversalConsole,
|
||||||
|
MessageDelivery
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ use rnex_core::rmc::structures::ranking::UploadCompetitionData;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use tokio::sync::{Mutex, RwLock};
|
use tokio::sync::{Mutex, RwLock};
|
||||||
|
|
||||||
|
use crate::rmc::protocols::messaging::UserMessage;
|
||||||
use crate::rmc::structures::matchmake::Gathering;
|
use crate::rmc::structures::matchmake::Gathering;
|
||||||
use crate::rmc::structures::matchmake::MatchmakeSessionSearchCriteria;
|
use crate::rmc::structures::matchmake::MatchmakeSessionSearchCriteria;
|
||||||
|
|
||||||
|
|
@ -923,7 +924,39 @@ impl Ranking for User {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageDelivery 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)
|
Err(ErrorCode::Core_NotImplemented)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use macros::{method_id, rmc_proto};
|
use macros::{method_id, rmc_proto};
|
||||||
|
|
||||||
use crate::rmc::{
|
use crate::rmc::{
|
||||||
|
protocols::messaging::UserMessage,
|
||||||
response::ErrorCode,
|
response::ErrorCode,
|
||||||
structures::{Error, any::Any},
|
structures::{Error, any::Any},
|
||||||
};
|
};
|
||||||
|
|
@ -8,5 +9,10 @@ use crate::rmc::{
|
||||||
#[rmc_proto(27)]
|
#[rmc_proto(27)]
|
||||||
pub trait MessageDelivery {
|
pub trait MessageDelivery {
|
||||||
#[method_id(1)]
|
#[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>);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
39
rnex-core/src/rmc/protocols/messaging.rs
Normal file
39
rnex-core/src/rmc/protocols/messaging.rs
Normal 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,
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ pub mod matchmake;
|
||||||
pub mod matchmake_ext;
|
pub mod matchmake_ext;
|
||||||
pub mod matchmake_extension;
|
pub mod matchmake_extension;
|
||||||
pub mod message_delivery;
|
pub mod message_delivery;
|
||||||
|
pub mod messaging;
|
||||||
pub mod nat_traversal;
|
pub mod nat_traversal;
|
||||||
pub mod nintendo_notification;
|
pub mod nintendo_notification;
|
||||||
pub mod notifications;
|
pub mod notifications;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue