implement friendships
This commit is contained in:
parent
58c9e43fa3
commit
20fc294a36
7 changed files with 196 additions and 21 deletions
|
|
@ -9,10 +9,12 @@ use tokio::net::TcpListener;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
executables::common::{OWN_IP_PRIVATE, SERVER_PORT, new_simple_backend},
|
executables::common::{OWN_IP_PRIVATE, SERVER_PORT, new_simple_backend},
|
||||||
nex::friends_handler::{FriendsGuest, FriendsManager, FriendsUser},
|
nex::friends_handler::{FriendsGuest, FriendsManager, FriendsUser, RemoteFriendsUser},
|
||||||
reggie::UnitPacketRead,
|
reggie::UnitPacketRead,
|
||||||
rmc::{
|
rmc::{
|
||||||
protocols::{RmcCallable, new_rmc_gateway_connection},
|
protocols::{
|
||||||
|
RmcCallable, RmcPureRemoteObject, friends::RemoteFriends, new_rmc_gateway_connection,
|
||||||
|
},
|
||||||
structures::RmcSerialize,
|
structures::RmcSerialize,
|
||||||
},
|
},
|
||||||
rnex_proxy_common::ConnectionInitData,
|
rnex_proxy_common::ConnectionInitData,
|
||||||
|
|
@ -21,6 +23,7 @@ use crate::{
|
||||||
pub async fn start_friends_backend() {
|
pub async fn start_friends_backend() {
|
||||||
let fm = Arc::new(FriendsManager {
|
let fm = Arc::new(FriendsManager {
|
||||||
cid_counter: AtomicU32::new(1),
|
cid_counter: AtomicU32::new(1),
|
||||||
|
users: Default::default(),
|
||||||
});
|
});
|
||||||
let listen = TcpListener::bind(SocketAddrV4::new(*OWN_IP_PRIVATE, *SERVER_PORT))
|
let listen = TcpListener::bind(SocketAddrV4::new(*OWN_IP_PRIVATE, *SERVER_PORT))
|
||||||
.await
|
.await
|
||||||
|
|
@ -53,6 +56,10 @@ pub async fn start_friends_backend() {
|
||||||
fm,
|
fm,
|
||||||
addr: c.prudpsock_addr,
|
addr: c.prudpsock_addr,
|
||||||
pid: c.pid,
|
pid: c.pid,
|
||||||
|
data: Default::default(),
|
||||||
|
current_friends: Default::default(),
|
||||||
|
this: this.clone(),
|
||||||
|
remote: RemoteFriendsUser::new(r),
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
use std::io::{Cursor, Write};
|
use std::io::{Cursor, Write};
|
||||||
|
use std::ops::Deref;
|
||||||
|
use std::sync::Weak;
|
||||||
use std::sync::{Arc, atomic::AtomicU32};
|
use std::sync::{Arc, atomic::AtomicU32};
|
||||||
|
|
||||||
use bytemuck::bytes_of;
|
use bytemuck::bytes_of;
|
||||||
|
|
@ -9,6 +11,10 @@ use rnex_core::rmc::protocols::account_management::{
|
||||||
AccountManagement, RawAccountManagement, RawAccountManagementInfo, RemoteAccountManagement,
|
AccountManagement, RawAccountManagement, RawAccountManagementInfo, RemoteAccountManagement,
|
||||||
};
|
};
|
||||||
use rnex_core::rmc::protocols::friends::{Friends, RawFriends, RawFriendsInfo, RemoteFriends};
|
use rnex_core::rmc::protocols::friends::{Friends, RawFriends, RawFriendsInfo, RemoteFriends};
|
||||||
|
use rnex_core::rmc::protocols::nintendo_notification::{
|
||||||
|
NintendoNotification, RawNintendoNotification, RawNintendoNotificationInfo,
|
||||||
|
RemoteNintendoNotification,
|
||||||
|
};
|
||||||
use rnex_core::rmc::protocols::secure::{RawSecure, RawSecureInfo, RemoteSecure, Secure};
|
use rnex_core::rmc::protocols::secure::{RawSecure, RawSecureInfo, RemoteSecure, Secure};
|
||||||
use rnex_core::{
|
use rnex_core::{
|
||||||
define_rmc_proto,
|
define_rmc_proto,
|
||||||
|
|
@ -25,12 +31,15 @@ use rnex_core::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use std::sync::atomic::Ordering::Relaxed;
|
use std::sync::atomic::Ordering::Relaxed;
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use rnex_core::rmc::protocols::friends::{GameKey, MiiV2, PrincipalBasicInfo};
|
use rnex_core::rmc::protocols::friends::{GameKey, MiiV2, PrincipalBasicInfo};
|
||||||
|
|
||||||
use rnex_core::PID;
|
use rnex_core::PID;
|
||||||
|
|
||||||
|
use crate::nex::user;
|
||||||
use crate::rmc::protocols::account_management::NintendoCreateAccountData;
|
use crate::rmc::protocols::account_management::NintendoCreateAccountData;
|
||||||
|
use crate::rmc::protocols::nintendo_notification::NintendoNotificationEvent;
|
||||||
use rnex_core::rmc::structures::RmcSerialize;
|
use rnex_core::rmc::structures::RmcSerialize;
|
||||||
|
|
||||||
define_rmc_proto!(
|
define_rmc_proto!(
|
||||||
|
|
@ -39,17 +48,32 @@ define_rmc_proto!(
|
||||||
Friends
|
Friends
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
define_rmc_proto!(
|
||||||
|
proto FriendRemote{
|
||||||
|
NintendoNotification
|
||||||
|
}
|
||||||
|
);
|
||||||
define_rmc_proto!(
|
define_rmc_proto!(
|
||||||
proto FriendsGuest{
|
proto FriendsGuest{
|
||||||
Secure,
|
Secure,
|
||||||
AccountManagement
|
AccountManagement
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
pub struct UserData {
|
||||||
|
info: NNAInfo,
|
||||||
|
presence: NintendoPresenceV2,
|
||||||
|
}
|
||||||
|
|
||||||
#[rmc_struct(FriendsUser)]
|
#[rmc_struct(FriendsUser)]
|
||||||
pub struct FriendsUser {
|
pub struct FriendsUser {
|
||||||
pub fm: Arc<FriendsManager>,
|
pub fm: Arc<FriendsManager>,
|
||||||
pub addr: PRUDPSockAddr,
|
pub addr: PRUDPSockAddr,
|
||||||
pub pid: PID,
|
pub pid: PID,
|
||||||
|
pub data: RwLock<Option<UserData>>,
|
||||||
|
pub current_friends: RwLock<Vec<PID>>,
|
||||||
|
pub this: Weak<FriendsUser>,
|
||||||
|
pub remote: RemoteFriendRemote,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rmc_struct(FriendsGuest)]
|
#[rmc_struct(FriendsGuest)]
|
||||||
|
|
@ -60,6 +84,7 @@ pub struct FriendsGuest {
|
||||||
|
|
||||||
pub struct FriendsManager {
|
pub struct FriendsManager {
|
||||||
pub cid_counter: AtomicU32,
|
pub cid_counter: AtomicU32,
|
||||||
|
pub users: RwLock<Vec<Weak<FriendsUser>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FriendsManager {
|
impl FriendsManager {
|
||||||
|
|
@ -68,11 +93,26 @@ impl FriendsManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn friend_info_from_user(data: &UserData) -> FriendInfo {
|
||||||
|
FriendInfo {
|
||||||
|
nna_info: data.info.clone(),
|
||||||
|
presence: data.presence.clone(),
|
||||||
|
comment: Comment {
|
||||||
|
unk: 0,
|
||||||
|
message: "litterally everyone is friends here =w=".to_string(),
|
||||||
|
last_changed: KerberosDateTime::now(),
|
||||||
|
},
|
||||||
|
became_friends: KerberosDateTime::now(),
|
||||||
|
last_online: KerberosDateTime::now(),
|
||||||
|
unk: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Friends for FriendsUser {
|
impl Friends for FriendsUser {
|
||||||
async fn update_and_get_all_information(
|
async fn update_and_get_all_information(
|
||||||
&self,
|
&self,
|
||||||
_info: NNAInfo,
|
info: NNAInfo,
|
||||||
_presence: NintendoPresenceV2,
|
presence: NintendoPresenceV2,
|
||||||
_date_time: KerberosDateTime,
|
_date_time: KerberosDateTime,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
|
|
@ -88,17 +128,15 @@ impl Friends for FriendsUser {
|
||||||
),
|
),
|
||||||
ErrorCode,
|
ErrorCode,
|
||||||
> {
|
> {
|
||||||
Ok((
|
let mut data = self.data.write().await;
|
||||||
PrincipalPreference {
|
*data = Some(UserData { info, presence });
|
||||||
block_friend_request: false,
|
let self_fr_info = friend_info_from_user(data.as_ref().unwrap());
|
||||||
show_online: false,
|
let Ok(any_self_fr_info) = Any::new(&self_fr_info) else {
|
||||||
show_playing_title: false,
|
return Err(ErrorCode::RendezVous_ControlScriptFailure);
|
||||||
},
|
};
|
||||||
Comment {
|
drop(data);
|
||||||
last_changed: KerberosDateTime::now(),
|
|
||||||
message: "".to_string(),
|
let mut fr_list =
|
||||||
unk: 0,
|
|
||||||
},
|
|
||||||
vec![FriendInfo {
|
vec![FriendInfo {
|
||||||
became_friends: KerberosDateTime::now(),
|
became_friends: KerberosDateTime::now(),
|
||||||
comment: Comment {
|
comment: Comment {
|
||||||
|
|
@ -144,7 +182,51 @@ impl Friends for FriendsUser {
|
||||||
unk7: 0
|
unk7: 0
|
||||||
},
|
},
|
||||||
unk: 0
|
unk: 0
|
||||||
}],
|
}];
|
||||||
|
|
||||||
|
let users = self.fm.users.read().await;
|
||||||
|
let mut curr_friends = self.current_friends.write().await;
|
||||||
|
for u in users.deref().iter().filter_map(|u| u.upgrade()) {
|
||||||
|
let data = u.data.read().await;
|
||||||
|
let Some(data) = data.as_ref() else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut fr = u.current_friends.write().await;
|
||||||
|
if !fr.contains(&self.pid) {
|
||||||
|
fr.push(self.pid);
|
||||||
|
u.remote
|
||||||
|
.process_nintendo_notification_event_1(NintendoNotificationEvent {
|
||||||
|
event_type: 30,
|
||||||
|
sender: self.pid,
|
||||||
|
data: any_self_fr_info.clone(),
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
drop(fr);
|
||||||
|
|
||||||
|
fr_list.push(friend_info_from_user(&data));
|
||||||
|
curr_friends.push(u.pid);
|
||||||
|
}
|
||||||
|
drop(curr_friends);
|
||||||
|
drop(users);
|
||||||
|
|
||||||
|
let mut users = self.fm.users.write().await;
|
||||||
|
users.push(self.this.clone());
|
||||||
|
drop(users);
|
||||||
|
|
||||||
|
Ok((
|
||||||
|
PrincipalPreference {
|
||||||
|
block_friend_request: false,
|
||||||
|
show_online: false,
|
||||||
|
show_playing_title: false,
|
||||||
|
},
|
||||||
|
Comment {
|
||||||
|
last_changed: KerberosDateTime::now(),
|
||||||
|
message: "".to_string(),
|
||||||
|
unk: 0,
|
||||||
|
},
|
||||||
|
fr_list,
|
||||||
vec![],
|
vec![],
|
||||||
vec![],
|
vec![],
|
||||||
vec![],
|
vec![],
|
||||||
|
|
@ -154,6 +236,32 @@ impl Friends for FriendsUser {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn update_presence(&self, presence: NintendoPresenceV2) -> Result<(), ErrorCode> {
|
||||||
|
let mut data = self.data.write().await;
|
||||||
|
let Some(data) = data.as_mut() else {
|
||||||
|
return Err(ErrorCode::RendezVous_PermissionDenied);
|
||||||
|
};
|
||||||
|
data.presence = presence;
|
||||||
|
let Ok(any_self_fr_info) = Any::new(&data.presence) else {
|
||||||
|
return Err(ErrorCode::RendezVous_ControlScriptFailure);
|
||||||
|
};
|
||||||
|
drop(data);
|
||||||
|
|
||||||
|
let users = self.fm.users.read().await;
|
||||||
|
for u in users.deref().iter().filter_map(|u| u.upgrade()) {
|
||||||
|
u.remote
|
||||||
|
.process_nintendo_notification_event_2(NintendoNotificationEvent {
|
||||||
|
event_type: 24,
|
||||||
|
sender: self.pid,
|
||||||
|
data: any_self_fr_info.clone(),
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
drop(users);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn check_setting_status(&self) -> Result<u8, ErrorCode> {
|
async fn check_setting_status(&self) -> Result<u8, ErrorCode> {
|
||||||
Ok(0xFF)
|
Ok(0xFF)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,14 @@ pub struct NNAInfo {
|
||||||
pub unk2: u8,
|
pub unk2: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RmcSerialize)]
|
#[derive(RmcSerialize, Clone, Copy, Debug)]
|
||||||
#[rmc_struct(0)]
|
#[rmc_struct(0)]
|
||||||
pub struct GameKey {
|
pub struct GameKey {
|
||||||
pub tid: u64,
|
pub tid: u64,
|
||||||
pub version: u16,
|
pub version: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RmcSerialize)]
|
#[derive(RmcSerialize, Clone, Debug)]
|
||||||
#[rmc_struct(0)]
|
#[rmc_struct(0)]
|
||||||
pub struct NintendoPresenceV2 {
|
pub struct NintendoPresenceV2 {
|
||||||
pub changed_flags: u32,
|
pub changed_flags: u32,
|
||||||
|
|
@ -143,6 +143,8 @@ pub trait Friends {
|
||||||
),
|
),
|
||||||
ErrorCode,
|
ErrorCode,
|
||||||
>;
|
>;
|
||||||
|
#[method_id(13)]
|
||||||
|
async fn update_presence(&self, presence: NintendoPresenceV2) -> Result<(), ErrorCode>;
|
||||||
#[method_id(19)]
|
#[method_id(19)]
|
||||||
async fn check_setting_status(&self) -> Result<u8, ErrorCode>;
|
async fn check_setting_status(&self) -> Result<u8, ErrorCode>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ pub mod matchmake;
|
||||||
pub mod matchmake_ext;
|
pub mod matchmake_ext;
|
||||||
pub mod matchmake_extension;
|
pub mod matchmake_extension;
|
||||||
pub mod nat_traversal;
|
pub mod nat_traversal;
|
||||||
|
pub mod nintendo_notification;
|
||||||
pub mod notifications;
|
pub mod notifications;
|
||||||
pub mod ranking;
|
pub mod ranking;
|
||||||
pub mod secure;
|
pub mod secure;
|
||||||
|
|
|
||||||
39
rnex-core/src/rmc/protocols/nintendo_notification.rs
Normal file
39
rnex-core/src/rmc/protocols/nintendo_notification.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
use macros::{RmcSerialize, method_id, rmc_proto};
|
||||||
|
|
||||||
|
use rnex_core::PID;
|
||||||
|
use rnex_core::rmc::structures::any::Any;
|
||||||
|
|
||||||
|
#[derive(RmcSerialize)]
|
||||||
|
#[rmc_struct(0)]
|
||||||
|
pub struct NintendoNotificationEvent {
|
||||||
|
pub event_type: u32,
|
||||||
|
pub sender: PID,
|
||||||
|
pub data: Any,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(RmcSerialize)]
|
||||||
|
#[rmc_struct(0)]
|
||||||
|
pub struct NintendoNotificationEventGeneral {
|
||||||
|
pub param1: u32,
|
||||||
|
pub param2: u64,
|
||||||
|
pub param3: u64,
|
||||||
|
pub str_param: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(RmcSerialize)]
|
||||||
|
#[rmc_struct(0)]
|
||||||
|
pub struct NintendoNotificationEventProfile {
|
||||||
|
pub region: u8,
|
||||||
|
pub country: u8,
|
||||||
|
pub area: u8,
|
||||||
|
pub language: u8,
|
||||||
|
pub platform: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rmc_proto(3, NoReturn)]
|
||||||
|
pub trait NintendoNotification {
|
||||||
|
#[method_id(1)]
|
||||||
|
async fn process_nintendo_notification_event_1(&self, notif: NintendoNotificationEvent);
|
||||||
|
#[method_id(2)]
|
||||||
|
async fn process_nintendo_notification_event_2(&self, notif: NintendoNotificationEvent);
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use rnex_core::rmc::structures::{Result, RmcSerialize};
|
use rnex_core::rmc::structures::{Result, RmcSerialize};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Cursor, Read, Write};
|
||||||
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct Any {
|
pub struct Any {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub data: Vec<u8>,
|
pub data: Vec<u8>,
|
||||||
|
|
@ -14,7 +14,7 @@ impl RmcSerialize for Any {
|
||||||
|
|
||||||
let u32_len = self.data.len() as u32;
|
let u32_len = self.data.len() as u32;
|
||||||
|
|
||||||
u32_len.serialize(writer)?;
|
(u32_len + 4).serialize(writer)?;
|
||||||
u32_len.serialize(writer)?;
|
u32_len.serialize(writer)?;
|
||||||
|
|
||||||
self.data.serialize(writer)?;
|
self.data.serialize(writer)?;
|
||||||
|
|
@ -35,3 +35,18 @@ impl RmcSerialize for Any {
|
||||||
Ok(Any { name, data })
|
Ok(Any { name, data })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Any {
|
||||||
|
pub fn try_get<T: RmcSerialize>(&self) -> Option<Result<T>> {
|
||||||
|
if self.name != T::name() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
return Some(T::deserialize(&mut Cursor::new(&self.data[..])));
|
||||||
|
}
|
||||||
|
pub fn new<T: RmcSerialize>(val: &T) -> Result<Self> {
|
||||||
|
return Ok(Self {
|
||||||
|
name: T::name().to_owned(),
|
||||||
|
data: val.to_data()?,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,9 @@ pub trait RmcSerialize {
|
||||||
|
|
||||||
Ok(data)
|
Ok(data)
|
||||||
}
|
}
|
||||||
|
fn name() -> &'static str {
|
||||||
|
"NoNameSpecified"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RmcSerialize for () {
|
impl RmcSerialize for () {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue