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,
ticket.into(),
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{
gathering: Gathering{
self_gid: 1,
self_gid: gid,
owner_pid: host.pid,
host_pid: host.pid,
..session.gathering.clone()
},
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{
params: vec![
("@SR".to_owned(), Variant::Bool(true)),
@ -124,7 +124,7 @@ impl ExtendedMatchmakeSession{
}
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 {
continue;
};
@ -146,7 +146,9 @@ impl ExtendedMatchmakeSession{
}).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 {
continue;
};
@ -158,14 +160,16 @@ impl ExtendedMatchmakeSession{
continue;
}*/
other_conn.remote.process_notification_event(NotificationEvent{
pid_source: initiating_pid,
notif_type: 3001,
param_1: self.session.gathering.self_gid,
param_2: other_pid,
str_param: join_msg.clone(),
param_3: self.connected_players.len() as _
}).await;
for pid in &list_of_connected_pids {
other_conn.remote.process_notification_event(NotificationEvent {
pid_source: initiating_pid,
notif_type: 3001,
param_1: self.session.gathering.self_gid,
param_2: *pid,
str_param: join_msg.clone(),
param_3: self.connected_players.len() as _
}).await;
}
}
for old_conns in &old_particip{
@ -173,9 +177,10 @@ impl ExtendedMatchmakeSession{
continue;
};
let older_pid = old_conns.pid;
initiating_user.remote.process_notification_event(NotificationEvent{
pid_source: initiating_pid,
notif_type: 3001,

View file

@ -1,13 +1,13 @@
use macros::rmc_struct;
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::nex::user::RemoteUserProtocol;
define_rmc_proto!(
proto Console{
Notification,
NatTraversal
NatTraversalConsole
}
);
/*

View file

@ -15,9 +15,7 @@ use crate::rmc::protocols::matchmake::{
use crate::rmc::protocols::matchmake_extension::{
MatchmakeExtension, RawMatchmakeExtension, RawMatchmakeExtensionInfo, RemoteMatchmakeExtension,
};
use crate::rmc::protocols::nat_traversal::{
NatTraversal, RawNatTraversal, RawNatTraversalInfo, RemoteNatTraversal,
};
use crate::rmc::protocols::nat_traversal::{NatTraversal, RawNatTraversal, RawNatTraversalInfo, RemoteNatTraversal, RemoteNatTraversalConsole};
use crate::rmc::protocols::secure::{RawSecure, RawSecureInfo, RemoteSecure, Secure};
use crate::rmc::protocols::matchmake_ext::{MatchmakeExt, RawMatchmakeExt, RawMatchmakeExtInfo, RemoteMatchmakeExt};
use crate::rmc::response::ErrorCode;
@ -70,7 +68,7 @@ impl Secure for User {
let mut public_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| {
if let NatType(v) = v {
if *v & PUBLIC != 0 {
@ -94,11 +92,11 @@ impl Secure for User {
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());
}
if is_public{
if is_public {
public_station = Some(station);
}
}
@ -107,7 +105,7 @@ impl Secure for User {
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
} else {
let mut public_station = private_station.clone();
@ -130,7 +128,7 @@ impl Secure for User {
let mut both = [&mut public_station, &mut private_station];
for station in both{
for station in both {
station.options.retain(|v| {
match v {
PrincipalID(_) | RVConnectionID(_) => false,
@ -147,7 +145,7 @@ impl Secure for User {
*lock = vec![
public_station.clone(),
//private_station.clone()
// private_station.clone()
];
drop(lock);
@ -164,11 +162,11 @@ impl Secure for User {
async fn replace_url(&self, target_url: StationUrl, dest: StationUrl) -> Result<(), ErrorCode> {
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);
};
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);
};
@ -196,7 +194,7 @@ impl MatchmakeExtension for User {
Ok(())
}
async fn get_playing_session(&self, pids: Vec<u32>) -> Result<Vec<()>, ErrorCode> {
Ok(Vec::new())
}
@ -224,18 +222,22 @@ impl MatchmakeExtension for User {
create_session_param.matchmake_session,
&self.this.clone(),
)
.await;
.await;
let mut joining_players = vec![self.this.clone()];
let users = self.matchmake_manager.users.read().await;
for pid in create_session_param.additional_participants{
if let Some(user) = users.get(&pid){
joining_players.push(user.clone());
if let Ok(old_gathering) = self.matchmake_manager.get_session(create_session_param.gid_for_participation_check).await {
let old_gathering = old_gathering.lock().await;
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);
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;
for pid in join_session_param.additional_participants{
if let Some(user) = users.get(&pid){
joining_players.push(user.clone());
if let Ok(old_gathering) = self.matchmake_manager.get_session(join_session_param.gid_for_participation_check).await {
let old_gathering = old_gathering.lock().await;
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;
for pid in &param.additional_participants{
if let Some(user) = users.get(pid){
joining_players.push(user.clone());
if let Ok(old_gathering) = self.matchmake_manager.get_session(param.gid_for_participation_check).await {
let old_gathering = old_gathering.lock().await;
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);
let sessions = self.matchmake_manager.sessions.read().await;
for session in sessions.values(){
for session in sessions.values() {
let mut session = session.lock().await;
println!("checking session!");
if !session.is_joinable(){
if !session.is_joinable() {
continue;
}
let mut bool_matched_criteria = false;
for criteria in &param.search_criteria{
if session.matches_criteria(criteria)?{
for criteria in &param.search_criteria {
if session.matches_criteria(criteria)? {
bool_matched_criteria = true;
}
}
@ -321,15 +329,13 @@ impl MatchmakeExtension for User {
return Ok(session.session.clone());
}
}
drop(sessions);
println!("making new session!");
let AutoMatchmakeParam{
let AutoMatchmakeParam {
join_message,
participation_count,
gid_for_participation_check,
@ -338,13 +344,13 @@ impl MatchmakeExtension for User {
..
} = param;
self.create_matchmake_session_with_param(CreateMatchmakeSessionParam{
self.create_matchmake_session_with_param(CreateMatchmakeSessionParam {
join_message,
participation_count,
gid_for_participation_check,
create_matchmake_session_option: 0,
matchmake_session,
additional_participants
additional_participants,
}).await
}
@ -390,13 +396,13 @@ impl Matchmake for User {
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 {
continue;
};
player.remote.process_notification_event(NotificationEvent{
notif_type: 3008,
player.remote.process_notification_event(NotificationEvent {
notif_type: 110000,
pid_source: self.pid,
param_1: gid,
param_2: self.pid,
@ -405,16 +411,16 @@ impl Matchmake for User {
}).await;
}
if change_session_owner{
if change_session_owner {
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 {
continue;
};
player.remote.process_notification_event(NotificationEvent{
player.remote.process_notification_event(NotificationEvent {
notif_type: 4000,
pid_source: self.pid,
param_1: gid,
@ -447,7 +453,6 @@ impl NatTraversal for User {
nat_filtering: u32,
_rtt: u32,
) -> Result<(), ErrorCode> {
let mut urls = self.station_url.write().await;
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);
for target in target_list{
let Ok(url) = StationUrl::try_from(target.as_ref()) else{
for target in target_list {
let Ok(url) = StationUrl::try_from(target.as_ref()) else {
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;
};
let Some(v) = users.get(&v) else{
let Some(v) = users.get(&v) else {
continue;
};
@ -494,9 +499,7 @@ impl NatTraversal for User {
continue;
};
if let Err(e) = user.remote.request_probe_initiation(station_to_probe.clone()).await{
error!("error whilest probing");
}
user.remote.request_probe_initiation(station_to_probe.clone()).await;
}
info!("finished probing");

View file

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

View file

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