Merge branch 'v0' of https://git.virintox.com/spfn/rust-nex into super-mario-maker

This commit is contained in:
red binder 2026-04-25 23:48:03 +02:00
commit 08f014fe39
12 changed files with 406 additions and 151 deletions

View file

@ -1,4 +1,6 @@
use std::io::{Cursor, Write};
use std::ops::Deref;
use std::sync::Weak;
use std::sync::{Arc, atomic::AtomicU32};
use bytemuck::bytes_of;
@ -9,6 +11,10 @@ use rnex_core::rmc::protocols::account_management::{
AccountManagement, RawAccountManagement, RawAccountManagementInfo, RemoteAccountManagement,
};
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::{
define_rmc_proto,
@ -25,31 +31,51 @@ use rnex_core::{
},
};
use std::sync::atomic::Ordering::Relaxed;
use tokio::spawn;
use tokio::sync::RwLock;
use rnex_core::rmc::protocols::friends::{GameKey, MiiV2, PrincipalBasicInfo};
use rnex_core::PID;
use crate::rmc::protocols::account_management::NintendoCreateAccountData;
use rnex_core::rmc::protocols::account_management::NintendoCreateAccountData;
use rnex_core::rmc::protocols::nintendo_notification::NintendoNotificationEvent;
use rnex_core::rmc::structures::RmcSerialize;
use rnex_core::rmc::structures::data::Data;
define_rmc_proto!(
proto FriendsUser{
Secure,
Friends
}
);
define_rmc_proto!(
proto FriendRemote{
NintendoNotification
}
);
define_rmc_proto!(
proto FriendsGuest{
Secure,
AccountManagement
}
);
pub struct UserData {
info: NNAInfo,
presence: NintendoPresenceV2,
}
#[rmc_struct(FriendsUser)]
pub struct FriendsUser {
pub fm: Arc<FriendsManager>,
pub addr: PRUDPSockAddr,
pub pid: PID,
pub data: RwLock<Option<UserData>>,
pub current_friends: RwLock<Vec<PID>>,
pub this: Weak<FriendsUser>,
pub remote: RemoteFriendRemote,
}
#[rmc_struct(FriendsGuest)]
@ -60,6 +86,7 @@ pub struct FriendsGuest {
pub struct FriendsManager {
pub cid_counter: AtomicU32,
pub users: RwLock<Vec<Weak<FriendsUser>>>,
}
impl FriendsManager {
@ -68,11 +95,28 @@ impl FriendsManager {
}
}
pub fn friend_info_from_user(data: &UserData) -> FriendInfo {
FriendInfo {
data: Data {},
nna_info: data.info.clone(),
presence: data.presence.clone(),
comment: Comment {
data: Data {},
unk: 0,
message: "haii =w=".to_string(),
last_changed: KerberosDateTime::now(),
},
became_friends: KerberosDateTime::now(),
last_online: KerberosDateTime::now(),
unk: 0,
}
}
impl Friends for FriendsUser {
async fn update_and_get_all_information(
&self,
_info: NNAInfo,
_presence: NintendoPresenceV2,
info: NNAInfo,
presence: NintendoPresenceV2,
_date_time: KerberosDateTime,
) -> Result<
(
@ -88,63 +132,127 @@ impl Friends for FriendsUser {
),
ErrorCode,
> {
println!("updating own data");
let mut data = self.data.write().await;
*data = Some(UserData { info, presence });
let self_fr_info = friend_info_from_user(data.as_ref().unwrap());
let Ok(any_self_fr_info) = Any::new(&self_fr_info) else {
return Err(ErrorCode::RendezVous_ControlScriptFailure);
};
drop(data);
let mut fr_list = vec![FriendInfo {
data: Data{},
became_friends: KerberosDateTime::now(),
comment: Comment {
data: Data{},
last_changed: KerberosDateTime::now(),
message: "I'm just a dummy account :3".to_string(),
unk: 0,
},
last_online: KerberosDateTime::now(),
nna_info: NNAInfo {
data: Data{},
principal_basic_info: PrincipalBasicInfo {
data: Data{},
pid: 101,
nnid: "dummy:3".to_string(),
mii: MiiV2{
data: Data{},
date_time: KerberosDateTime::now(),
name: "TheDummy".to_string(),
mii_data: hex::decode("030000402bd7c32986a771f2dc6b35e31da15e37ff7c0000391e6f006f006d0069000000000000000000000000004040001065033568641e2013661a611821640f0000290052485000000000000000000000000000000000000000000000e838").unwrap(),
unk: 0,
unk2: 0,
},
unk: 0
},
unk: 0,
unk2: 0
},
presence: NintendoPresenceV2{
data: Data{},
changed_flags: 0,
message: "".to_string(),
app_data: vec![],
game_key: GameKey{
data: Data{},
tid: 0x00050002101ce400,
version: 0x0
},
game_server_id: 0,
is_online: true,
gid: 0,
pid: 101,
unk: 0,
unk2: 0,
unk3: 0,
unk4: 0,
unk5: 0,
unk6: 0,
unk7: 0
},
unk: 0
}];
println!("acquiring user and current friends locks");
let users = self.fm.users.read().await;
println!("started summing users");
for u in users.deref().iter().filter_map(|u| u.upgrade()) {
let data = u.data.read().await;
let Some(inner_data) = data.as_ref() else {
continue;
};
fr_list.push(friend_info_from_user(&inner_data));
drop(data);
let mut curr_friends = self.current_friends.write().await;
curr_friends.push(u.pid);
drop(curr_friends);
let mut fr = u.current_friends.write().await;
if !fr.contains(&self.pid) {
fr.push(self.pid);
drop(fr);
let data = any_self_fr_info.clone();
let u = u.clone();
let sender = self.pid;
spawn(async move {
u.remote
.process_nintendo_notification_event_1(NintendoNotificationEvent {
event_type: 30,
sender,
data,
})
.await;
});
} else {
drop(fr);
}
}
println!("finished summing users");
drop(users);
println!("adding self to users");
let mut users = self.fm.users.write().await;
users.push(self.this.clone());
drop(users);
println!("done...");
Ok((
PrincipalPreference {
data: Data {},
block_friend_request: false,
show_online: false,
show_playing_title: false,
},
Comment {
data: Data {},
last_changed: KerberosDateTime::now(),
message: "".to_string(),
unk: 0,
},
vec![FriendInfo {
became_friends: KerberosDateTime::now(),
comment: Comment {
last_changed: KerberosDateTime::now(),
message: "I'm just a dummy account :3".to_string(),
unk: 0,
},
last_online: KerberosDateTime::now(),
nna_info: NNAInfo {
principal_basic_info: PrincipalBasicInfo {
pid: 101,
nnid: "dummy:3".to_string(),
mii: MiiV2{
date_time: KerberosDateTime::now(),
name: "TheDummy".to_string(),
mii_data: hex::decode("030000402bd7c32986a771f2dc6b35e31da15e37ff7c0000391e6f006f006d0069000000000000000000000000004040001065033568641e2013661a611821640f0000290052485000000000000000000000000000000000000000000000e838").unwrap(),
unk: 0,
unk2: 0,
},
unk: 0
},
unk: 0,
unk2: 0
},
presence: NintendoPresenceV2{
changed_flags: 0,
message: "".to_string(),
app_data: vec![],
game_key: GameKey{
tid: 0x00050002101ce400,
version: 0x0
},
game_server_id: 0,
is_online: true,
gid: 0,
pid: 101,
unk: 0,
unk2: 0,
unk3: 0,
unk4: 0,
unk5: 0,
unk6: 0,
unk7: 0
},
unk: 0
}],
fr_list,
vec![],
vec![],
vec![],
@ -154,6 +262,39 @@ impl Friends for FriendsUser {
))
}
async fn update_presence(&self, presence: NintendoPresenceV2) -> Result<(), ErrorCode> {
let mut data = self.data.write().await;
let Some(inner_data) = data.as_mut() else {
return Err(ErrorCode::RendezVous_PermissionDenied);
};
inner_data.presence = presence;
let Ok(any_self_fr_info) = Any::new(&inner_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 delete_persistent_notification(
&self,
notifs: Vec<PersistentNotification>,
) -> Result<(), ErrorCode> {
Ok(())
}
async fn check_setting_status(&self) -> Result<u8, ErrorCode> {
Ok(0xFF)
}

View file

@ -247,31 +247,32 @@ impl ExtendedMatchmakeSession {
param_3: self.connected_players.len() as _,
})
.await;
}
}
}
for old_conns in &old_particip {
let Some(old_conns) = old_conns.upgrade() else {
continue;
};
if old_conns.pid != self.session.gathering.host_pid{
continue;
}
for new_conn_pid in conns.iter().filter_map(Weak::upgrade).map(|c| c.pid){
old_conns
.remote
.process_notification_event(NotificationEvent {
pid_source: initiating_pid,
notif_type: 3001,
param_1: self.session.gathering.self_gid as PID,
param_2: new_conn_pid,
str_param: join_msg.clone(),
param_3: self.connected_players.len() as _,
})
.await;
/*if old_conns.pid != self.session.gathering.host_pid {
continue;
}*/
for new_conn_pid in conns.iter().filter_map(Weak::upgrade).map(|c| c.pid) {
old_conns
.remote
.process_notification_event(NotificationEvent {
pid_source: initiating_pid,
notif_type: 3001,
param_1: self.session.gathering.self_gid as PID,
param_2: new_conn_pid,
str_param: join_msg.clone(),
param_3: self.connected_players.len() as _,
})
.await;
}
}
}
pub fn has_active_players(&self) -> bool {
self.connected_players
.iter()

View file

@ -5,15 +5,12 @@ use crate::nex::remote_console::RemoteConsole;
use crate::rmc::protocols::matchmake::{
Matchmake, RawMatchmake, RawMatchmakeInfo, RemoteMatchmake,
};
use serde::{Serialize, Deserialize};
use std::env;
use std::str::FromStr;
use crate::rmc::protocols::nat_traversal::{
NatTraversal, RawNatTraversal, RawNatTraversalInfo, RemoteNatTraversal,
RemoteNatTraversalConsole,
};
use rnex_core::kerberos::KerberosDateTime;
use rnex_core::PID;
use rnex_core::kerberos::KerberosDateTime;
use rnex_core::prudp::station_url::StationUrl;
use rnex_core::prudp::station_url::UrlOptions::{
Address, NatFiltering, NatMapping, Port, RVConnectionID,
@ -32,14 +29,21 @@ use rnex_core::rmc::structures::any::Any;
use rnex_core::rmc::structures::matchmake::{
AutoMatchmakeParam, CreateMatchmakeSessionParam, JoinMatchmakeSessionParam, MatchmakeSession,
};
use serde::{Deserialize, Serialize};
use std::env;
use std::str::FromStr;
use crate::rmc::protocols::notifications::{NotificationEvent, RemoteNotification};
use log::{info, error};
use log::{error, info};
use macros::rmc_struct;
use rnex_core::rmc::structures::qbuffer::QBuffer;
use rnex_core::prudp::socket_addr::PRUDPSockAddr;
use rnex_core::rmc::protocols::ranking::{
CompetitionRankingGetParam, CompetitionRankingScoreData, CompetitionRankingScoreInfo,
};
use rnex_core::rmc::response::ErrorCode::{Core_InvalidArgument, RendezVous_AccountExpired};
use rnex_core::rmc::structures::qbuffer::QBuffer;
use rnex_core::rmc::structures::qresult::QResult;
use rnex_core::rmc::structures::ranking::UploadCompetitionData;
use std::sync::{Arc, Weak};
use cfg_if::cfg_if;
use rnex_core::rmc::protocols::ranking::{CompetitionRankingScoreData, CompetitionRankingGetParam, CompetitionRankingScoreInfo};
@ -635,10 +639,7 @@ fn fetch_team_votes(fest_id: u32) -> Result<Vec<u32>, ErrorCode> {
})?;
let body = body.trim().trim_start_matches('[').trim_end_matches(']');
let votes: Result<Vec<u32>, _> = body
.split(',')
.map(|s| u32::from_str(s.trim()))
.collect();
let votes: Result<Vec<u32>, _> = body.split(',').map(|s| u32::from_str(s.trim())).collect();
votes.map_err(|e| {
error!("failed to parse votes: {:?}", e);
@ -653,23 +654,19 @@ impl Ranking for User {
) -> Result<Vec<CompetitionRankingScoreInfo>, ErrorCode> {
let fest_id = param.festival_ids.get(0).copied().unwrap_or(0);
let endpoint_results = env::var("RNEX_SPLATOON_RESULTS_GET")
.map_err(|_| {
error!("RNEX_SPLATOON_RESULTS_GET not set");
ErrorCode::RendezVous_InvalidConfiguration
})?;
let endpoint_results = env::var("RNEX_SPLATOON_RESULTS_GET").map_err(|_| {
error!("RNEX_SPLATOON_RESULTS_GET not set");
ErrorCode::RendezVous_InvalidConfiguration
})?;
let url_results = format!("{}?splatfest_id={}", endpoint_results, fest_id);
let response_results = ureq::get(&url_results).call();
let results: Vec<CompetitionPostResults> = match response_results {
Ok(mut res) => res
.body_mut()
.read_json()
.map_err(|e| {
error!("failed to parse JSON: {:?}", e);
ErrorCode::RendezVous_InvalidConfiguration
})?,
Ok(mut res) => res.body_mut().read_json().map_err(|e| {
error!("failed to parse JSON: {:?}", e);
ErrorCode::RendezVous_InvalidConfiguration
})?,
Err(e) => {
error!("GET failed: {:?}", e);
return Err(ErrorCode::RendezVous_InvalidConfiguration);
@ -679,9 +676,10 @@ impl Ranking for User {
let team_votes = fetch_team_votes(fest_id)?;
let mut wins = vec![0u32, 0u32];
for r in &results {
if r.team_win == 1 && (r.team_id == 0 || r.team_id == 1) {
wins[r.team_id as usize] += 1;
}
let won_team = r.team_id ^ (!r.team_win);
if let Some(team) = wins.get_mut(won_team as usize) {
*team += 1
};
}
let score_data: Vec<CompetitionRankingScoreData> = results
@ -695,7 +693,7 @@ impl Ranking for User {
appdata: QBuffer(vec![]),
})
.collect();
let info = CompetitionRankingScoreInfo {
fest_id,
score_data,
@ -707,7 +705,10 @@ impl Ranking for User {
Ok(vec![info])
}
async fn upload_competition_ranking_score(&self, param: UploadCompetitionData) -> Result<bool, ErrorCode> {
async fn upload_competition_ranking_score(
&self,
param: UploadCompetitionData,
) -> Result<bool, ErrorCode> {
info!("fest results for user {:?}:", self.pid);
info!("fest id: {:?}", param.splatfest_id);
info!("score: {:?}", param.score);
@ -750,8 +751,7 @@ impl Ranking for User {
error!("POST borked: {:?}", e);
}
}
Ok(true)
}
}