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,14 +160,16 @@ impl ExtendedMatchmakeSession{
continue; continue;
}*/ }*/
other_conn.remote.process_notification_event(NotificationEvent{ for pid in &list_of_connected_pids {
pid_source: initiating_pid, other_conn.remote.process_notification_event(NotificationEvent {
notif_type: 3001, pid_source: initiating_pid,
param_1: self.session.gathering.self_gid, notif_type: 3001,
param_2: other_pid, param_1: self.session.gathering.self_gid,
str_param: join_msg.clone(), param_2: *pid,
param_3: self.connected_players.len() as _ str_param: join_msg.clone(),
}).await; param_3: self.connected_players.len() as _
}).await;
}
} }
for old_conns in &old_particip{ for old_conns in &old_particip{
@ -173,9 +177,10 @@ impl ExtendedMatchmakeSession{
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;
@ -70,7 +68,7 @@ impl Secure for User {
let mut public_station: Option<StationUrl> = None; let mut public_station: Option<StationUrl> = None;
let mut private_station: Option<StationUrl> = None; let mut private_station: Option<StationUrl> = None;
for station in station_urls{ for station in station_urls {
let is_public = station.options.iter().any(|v| { let is_public = station.options.iter().any(|v| {
if let NatType(v) = v { if let NatType(v) = v {
if *v & PUBLIC != 0 { if *v & PUBLIC != 0 {
@ -94,11 +92,11 @@ impl Secure for User {
return Err(Core_Exception); return Err(Core_Exception);
}; };
if !is_public || (*nat_filtering == 0 && *nat_mapping == 0){ if !is_public || (*nat_filtering == 0 && *nat_mapping == 0) {
private_station = Some(station.clone()); private_station = Some(station.clone());
} }
if is_public{ if is_public {
public_station = Some(station); public_station = Some(station);
} }
} }
@ -107,7 +105,7 @@ impl Secure for User {
return Err(Core_Exception); return Err(Core_Exception);
}; };
let mut public_station = if let Some(public_station) = public_station{ let mut public_station = if let Some(public_station) = public_station {
public_station public_station
} else { } else {
let mut public_station = private_station.clone(); let mut public_station = private_station.clone();
@ -130,7 +128,7 @@ impl Secure for User {
let mut both = [&mut public_station, &mut private_station]; let mut both = [&mut public_station, &mut private_station];
for station in both{ for station in both {
station.options.retain(|v| { station.options.retain(|v| {
match v { match v {
PrincipalID(_) | RVConnectionID(_) => false, PrincipalID(_) | RVConnectionID(_) => false,
@ -147,7 +145,7 @@ impl Secure for User {
*lock = vec![ *lock = vec![
public_station.clone(), public_station.clone(),
//private_station.clone() // private_station.clone()
]; ];
drop(lock); drop(lock);
@ -164,11 +162,11 @@ impl Secure for User {
async fn replace_url(&self, target_url: StationUrl, dest: StationUrl) -> Result<(), ErrorCode> { async fn replace_url(&self, target_url: StationUrl, dest: StationUrl) -> Result<(), ErrorCode> {
let mut lock = self.station_url.write().await; let mut lock = self.station_url.write().await;
let Some(target_addr) = target_url.options.iter().find(|v| matches!(v, Address(_))) else{ let Some(target_addr) = target_url.options.iter().find(|v| matches!(v, Address(_))) else {
return Err(ErrorCode::Core_InvalidArgument); return Err(ErrorCode::Core_InvalidArgument);
}; };
let Some(target_port) = target_url.options.iter().find(|v| matches!(v, Port(_))) else{ let Some(target_port) = target_url.options.iter().find(|v| matches!(v, Port(_))) else {
return Err(ErrorCode::Core_InvalidArgument); return Err(ErrorCode::Core_InvalidArgument);
}; };
@ -224,18 +222,22 @@ impl MatchmakeExtension for User {
create_session_param.matchmake_session, create_session_param.matchmake_session,
&self.this.clone(), &self.this.clone(),
) )
.await; .await;
let mut joining_players = vec![self.this.clone()]; let mut joining_players = vec![self.this.clone()];
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,28 +295,31 @@ 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));
} }
} }
drop(users); drop(users);
let sessions = self.matchmake_manager.sessions.read().await; let sessions = self.matchmake_manager.sessions.read().await;
for session in sessions.values(){ for session in sessions.values() {
let mut session = session.lock().await; let mut session = session.lock().await;
println!("checking session!"); println!("checking session!");
if !session.is_joinable(){ if !session.is_joinable() {
continue; continue;
} }
let mut bool_matched_criteria = false; let mut bool_matched_criteria = false;
for criteria in &param.search_criteria{ for criteria in &param.search_criteria {
if session.matches_criteria(criteria)?{ if session.matches_criteria(criteria)? {
bool_matched_criteria = true; bool_matched_criteria = true;
} }
} }
@ -321,15 +329,13 @@ impl MatchmakeExtension for User {
return Ok(session.session.clone()); return Ok(session.session.clone());
} }
} }
drop(sessions); drop(sessions);
println!("making new session!"); println!("making new session!");
let AutoMatchmakeParam{ let AutoMatchmakeParam {
join_message, join_message,
participation_count, participation_count,
gid_for_participation_check, gid_for_participation_check,
@ -338,13 +344,13 @@ impl MatchmakeExtension for User {
.. ..
} = param; } = param;
self.create_matchmake_session_with_param(CreateMatchmakeSessionParam{ self.create_matchmake_session_with_param(CreateMatchmakeSessionParam {
join_message, join_message,
participation_count, participation_count,
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
} }
@ -390,13 +396,13 @@ impl Matchmake for User {
session.session.gathering.host_pid = self.pid; session.session.gathering.host_pid = self.pid;
for player in &session.connected_players{ for player in &session.connected_players {
let Some(player) = player.upgrade() else { let Some(player) = player.upgrade() else {
continue; continue;
}; };
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,
@ -405,16 +411,16 @@ impl Matchmake for User {
}).await; }).await;
} }
if change_session_owner{ if change_session_owner {
session.session.gathering.owner_pid = self.pid; session.session.gathering.owner_pid = self.pid;
for player in &session.connected_players{ for player in &session.connected_players {
let Some(player) = player.upgrade() else { let Some(player) = player.upgrade() else {
continue; continue;
}; };
player.remote.process_notification_event(NotificationEvent{ player.remote.process_notification_event(NotificationEvent {
notif_type: 4000, notif_type: 4000,
pid_source: self.pid, pid_source: self.pid,
param_1: gid, param_1: gid,
@ -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() {
@ -477,16 +482,16 @@ impl NatTraversal for User {
println!("requesting station probe for {:?} to {:?}", target_list, station_to_probe); println!("requesting station probe for {:?} to {:?}", target_list, station_to_probe);
for target in target_list{ for target in target_list {
let Ok(url) = StationUrl::try_from(target.as_ref()) else{ let Ok(url) = StationUrl::try_from(target.as_ref()) else {
continue; continue;
}; };
let Some(RVConnectionID(v)) = url.options.into_iter().find(|o| { matches!(o, &RVConnectionID(_)) }) else{ let Some(RVConnectionID(v)) = url.options.into_iter().find(|o| { matches!(o, &RVConnectionID(_)) }) else {
continue; continue;
}; };
let Some(v) = users.get(&v) else{ let Some(v) = users.get(&v) else {
continue; continue;
}; };
@ -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);
}*/ }