fix: unhardcode matchmake session fields and fix other stuff

This commit is contained in:
DJMrTV 2025-05-15 17:00:26 +02:00
commit b8cc89a6d9
6 changed files with 72 additions and 65 deletions

View file

@ -97,7 +97,7 @@ impl Auth for AuthHandler {
source_login_data.0, source_login_data.0,
ticket.into(), ticket.into(),
connection_data, connection_data,
format!("{}; Rust NEX Version {} by DJMrTV", self.build_name, env!("CARGO_PKG_VERSION")), self.build_name.to_string() //format!("{}; Rust NEX Version {} by DJMrTV", self.build_name, env!("CARGO_PKG_VERSION")),
)) ))
} }

View file

@ -88,13 +88,13 @@ impl ExtendedMatchmakeSession{
let mm_session = MatchmakeSession{ let mm_session = MatchmakeSession{
gathering: Gathering{ gathering: Gathering{
self_gid: 1, self_gid: gid,
owner_pid: host.pid, owner_pid: host.pid,
host_pid: host.pid, host_pid: host.pid,
..session.gathering.clone() ..session.gathering.clone()
}, },
datetime: KerberosDateTime::now(), datetime: KerberosDateTime::now(),
session_key: vec![16, 118, 112, 238, 158, 122, 106, 219, 196, 238, 34, 21, 228, 127, 137, 75, 198, 215, 192, 113, 84, 157, 53, 144, 210, 99, 233, 179, 232, 113, 203, 64],//(0..32).map(|_| random()).collect(), session_key: (0..32).map(|_| random()).collect(),
matchmake_param: MatchmakeParam{ matchmake_param: MatchmakeParam{
params: vec![ params: vec![
("@SR".to_owned(), Variant::Bool(true)), ("@SR".to_owned(), Variant::Bool(true)),
@ -124,7 +124,7 @@ impl ExtendedMatchmakeSession{
} }
self.session.participation_count = self.connected_players.len() as u32; self.session.participation_count = self.connected_players.len() as u32;
for other_connection in &self.connected_players[1..]{ for other_connection in &conns[1..]{
let Some(other_conn) = other_connection.upgrade() else { let Some(other_conn) = other_connection.upgrade() else {
continue; continue;
}; };
@ -146,7 +146,9 @@ impl ExtendedMatchmakeSession{
}).await; }).await;
} }
for other_connection in &self.connected_players{ let list_of_connected_pids: Vec<_> = self.connected_players.iter().filter_map(|p| p.upgrade()).map(|p| p.pid).collect();
for other_connection in conns{
let Some(other_conn) = other_connection.upgrade() else { let Some(other_conn) = other_connection.upgrade() else {
continue; continue;
}; };
@ -158,24 +160,27 @@ impl ExtendedMatchmakeSession{
continue; continue;
}*/ }*/
for pid in &list_of_connected_pids {
other_conn.remote.process_notification_event(NotificationEvent { other_conn.remote.process_notification_event(NotificationEvent {
pid_source: initiating_pid, pid_source: initiating_pid,
notif_type: 3001, notif_type: 3001,
param_1: self.session.gathering.self_gid, param_1: self.session.gathering.self_gid,
param_2: other_pid, param_2: *pid,
str_param: join_msg.clone(), str_param: join_msg.clone(),
param_3: self.connected_players.len() as _ param_3: self.connected_players.len() as _
}).await; }).await;
} }
}
for old_conns in &old_particip{ for old_conns in &old_particip{
let Some(old_conns) = old_conns.upgrade() else { let Some(old_conns) = old_conns.upgrade() else {
continue; continue;
}; };
let older_pid = old_conns.pid; let older_pid = old_conns.pid;
initiating_user.remote.process_notification_event(NotificationEvent{ initiating_user.remote.process_notification_event(NotificationEvent{
pid_source: initiating_pid, pid_source: initiating_pid,
notif_type: 3001, notif_type: 3001,

View file

@ -1,13 +1,13 @@
use macros::rmc_struct; use macros::rmc_struct;
use crate::rmc::protocols::notifications::{Notification, NotificationEvent, RawNotification, RawNotificationInfo, RemoteNotification}; use crate::rmc::protocols::notifications::{Notification, NotificationEvent, RawNotification, RawNotificationInfo, RemoteNotification};
use crate::rmc::protocols::nat_traversal::{NatTraversal, RemoteNatTraversal, RawNatTraversalInfo, RawNatTraversal}; use crate::rmc::protocols::nat_traversal::{NatTraversalConsole, RemoteNatTraversalConsole, RawNatTraversalConsoleInfo, RawNatTraversalConsole};
use crate::define_rmc_proto; use crate::define_rmc_proto;
use crate::nex::user::RemoteUserProtocol; use crate::nex::user::RemoteUserProtocol;
define_rmc_proto!( define_rmc_proto!(
proto Console{ proto Console{
Notification, Notification,
NatTraversal NatTraversalConsole
} }
); );
/* /*

View file

@ -15,9 +15,7 @@ use crate::rmc::protocols::matchmake::{
use crate::rmc::protocols::matchmake_extension::{ use crate::rmc::protocols::matchmake_extension::{
MatchmakeExtension, RawMatchmakeExtension, RawMatchmakeExtensionInfo, RemoteMatchmakeExtension, MatchmakeExtension, RawMatchmakeExtension, RawMatchmakeExtensionInfo, RemoteMatchmakeExtension,
}; };
use crate::rmc::protocols::nat_traversal::{ use crate::rmc::protocols::nat_traversal::{NatTraversal, RawNatTraversal, RawNatTraversalInfo, RemoteNatTraversal, RemoteNatTraversalConsole};
NatTraversal, RawNatTraversal, RawNatTraversalInfo, RemoteNatTraversal,
};
use crate::rmc::protocols::secure::{RawSecure, RawSecureInfo, RemoteSecure, Secure}; use crate::rmc::protocols::secure::{RawSecure, RawSecureInfo, RemoteSecure, Secure};
use crate::rmc::protocols::matchmake_ext::{MatchmakeExt, RawMatchmakeExt, RawMatchmakeExtInfo, RemoteMatchmakeExt}; use crate::rmc::protocols::matchmake_ext::{MatchmakeExt, RawMatchmakeExt, RawMatchmakeExtInfo, RemoteMatchmakeExt};
use crate::rmc::response::ErrorCode; use crate::rmc::response::ErrorCode;
@ -230,12 +228,16 @@ impl MatchmakeExtension for User {
let users = self.matchmake_manager.users.read().await; let users = self.matchmake_manager.users.read().await;
for pid in create_session_param.additional_participants{ if let Ok(old_gathering) = self.matchmake_manager.get_session(create_session_param.gid_for_participation_check).await {
if let Some(user) = users.get(&pid){ let old_gathering = old_gathering.lock().await;
joining_players.push(user.clone());
let players = old_gathering.connected_players.iter().filter_map(|v| v.upgrade()).filter(|u| create_session_param.additional_participants.iter().any(|p| *p == u.pid));
for player in players {
joining_players.push(Arc::downgrade(&player));
} }
} }
drop(users); drop(users);
new_session.session.participation_count = create_session_param.participation_count as u32; new_session.session.participation_count = create_session_param.participation_count as u32;
@ -266,9 +268,12 @@ impl MatchmakeExtension for User {
let users = self.matchmake_manager.users.read().await; let users = self.matchmake_manager.users.read().await;
for pid in join_session_param.additional_participants{ if let Ok(old_gathering) = self.matchmake_manager.get_session(join_session_param.gid_for_participation_check).await {
if let Some(user) = users.get(&pid){ let old_gathering = old_gathering.lock().await;
joining_players.push(user.clone());
let players = old_gathering.connected_players.iter().filter_map(|v| v.upgrade()).filter(|u| join_session_param.additional_participants.iter().any(|p| *p == u.pid));
for player in players {
joining_players.push(Arc::downgrade(&player));
} }
} }
@ -290,9 +295,12 @@ impl MatchmakeExtension for User {
let users = self.matchmake_manager.users.read().await; let users = self.matchmake_manager.users.read().await;
for pid in &param.additional_participants{ if let Ok(old_gathering) = self.matchmake_manager.get_session(param.gid_for_participation_check).await {
if let Some(user) = users.get(pid){ let old_gathering = old_gathering.lock().await;
joining_players.push(user.clone());
let players = old_gathering.connected_players.iter().filter_map(|v| v.upgrade()).filter(|u| param.additional_participants.iter().any(|p| *p == u.pid));
for player in players {
joining_players.push(Arc::downgrade(&player));
} }
} }
@ -321,8 +329,6 @@ impl MatchmakeExtension for User {
return Ok(session.session.clone()); return Ok(session.session.clone());
} }
} }
drop(sessions); drop(sessions);
@ -344,7 +350,7 @@ impl MatchmakeExtension for User {
gid_for_participation_check, gid_for_participation_check,
create_matchmake_session_option: 0, create_matchmake_session_option: 0,
matchmake_session, matchmake_session,
additional_participants additional_participants,
}).await }).await
} }
@ -396,7 +402,7 @@ impl Matchmake for User {
}; };
player.remote.process_notification_event(NotificationEvent { player.remote.process_notification_event(NotificationEvent {
notif_type: 3008, notif_type: 110000,
pid_source: self.pid, pid_source: self.pid,
param_1: gid, param_1: gid,
param_2: self.pid, param_2: self.pid,
@ -447,7 +453,6 @@ impl NatTraversal for User {
nat_filtering: u32, nat_filtering: u32,
_rtt: u32, _rtt: u32,
) -> Result<(), ErrorCode> { ) -> Result<(), ErrorCode> {
let mut urls = self.station_url.write().await; let mut urls = self.station_url.write().await;
for station_url in urls.iter_mut() { for station_url in urls.iter_mut() {
@ -494,9 +499,7 @@ impl NatTraversal for User {
continue; continue;
}; };
if let Err(e) = user.remote.request_probe_initiation(station_to_probe.clone()).await{ user.remote.request_probe_initiation(station_to_probe.clone()).await;
error!("error whilest probing");
}
} }
info!("finished probing"); info!("finished probing");

View file

@ -709,7 +709,6 @@ impl ExternalConnection{
impl SendingConnection{ impl SendingConnection{
pub async fn send(&self, data: Vec<u8>) -> Option<()> { pub async fn send(&self, data: Vec<u8>) -> Option<()> {
println!("{}", hex::encode(&data));
let internal = self.inernal.upgrade()?; let internal = self.inernal.upgrade()?;
let mut internal = internal.lock().await; let mut internal = internal.lock().await;

View file

@ -16,9 +16,9 @@ pub trait NatTraversal{
#[method_id(5)] #[method_id(5)]
async fn report_nat_properties(&self, nat_mapping: u32, nat_filtering: u32, rtt: u32) -> Result<(),ErrorCode>; async fn report_nat_properties(&self, nat_mapping: u32, nat_filtering: u32, rtt: u32) -> Result<(),ErrorCode>;
} }
/*
#[rmc_proto(3, NoReturn)] #[rmc_proto(3, NoReturn)]
pub trait NatTraversalConsole{ pub trait NatTraversalConsole{
#[method_id(2)] #[method_id(2)]
async fn request_probe_initiation(&self, station_to_probe: String) -> Result<(),ErrorCode>; async fn request_probe_initiation(&self, station_to_probe: String);
}*/ }