From 1b9be69f4e1bd02a6ba7fc528ff741a4fe8dbd15 Mon Sep 17 00:00:00 2001 From: Cain <75994858+cainthebest@users.noreply.github.com> Date: Fri, 11 Oct 2024 11:32:04 +0100 Subject: [PATCH 1/7] fix(protocol): try to match port on epic --- crates/lib/src/protocols/epic/protocol.rs | 24 ++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/lib/src/protocols/epic/protocol.rs b/crates/lib/src/protocols/epic/protocol.rs index 6d57e707..2a554486 100644 --- a/crates/lib/src/protocols/epic/protocol.rs +++ b/crates/lib/src/protocols/epic/protocol.rs @@ -122,22 +122,28 @@ impl EpicProtocol { let attributes = session .get("attributes") .ok_or(PacketBad.context("Expected attributes field missing in sessions."))?; - if attributes + + let address_match = attributes .get("ADDRESSBOUND_s") .and_then(Value::as_str) .map_or(false, |v| { - v.contains(&address) || v.contains(&port.to_string()) - }) - || attributes - .get("ADDRESS_s") - .and_then(Value::as_str) - .map_or(false, |v| v.contains(&address)) - { + v == format!("0.0.0.0:{}", port) || v == format!("{}:{}", address, port) + }); + + let port_match = attributes + .get("GAMESERVER_PORT_l") + .and_then(Value::as_u64) + .map_or(false, |v| v == port as u64); + + // If either address or port matches, return the session + if address_match || port_match { return Ok(session); } } - return Err(PacketBad.context("Servers were provided but the specified one couldn't be find amonst them.")); + return Err( + PacketBad.context("Servers were provided but the specified one couldn't be found amongst them.") + ); } Err(PacketBad.context("Expected session field to be an array.")) From 43baa19cdb081c00d81fae7d9ca52740d91f4924 Mon Sep 17 00:00:00 2001 From: Cain <75994858+cainthebest@users.noreply.github.com> Date: Fri, 11 Oct 2024 11:59:00 +0100 Subject: [PATCH 2/7] fix(protocol): add a fallback session to epic for matching --- crates/lib/src/protocols/epic/protocol.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/lib/src/protocols/epic/protocol.rs b/crates/lib/src/protocols/epic/protocol.rs index 2a554486..b331c425 100644 --- a/crates/lib/src/protocols/epic/protocol.rs +++ b/crates/lib/src/protocols/epic/protocol.rs @@ -118,6 +118,8 @@ impl EpicProtocol { return Err(PacketBad.context("No servers provided.")); } + let mut fallback_session: Option = None; + for session in sessions.into_iter() { let attributes = session .get("attributes") @@ -135,10 +137,20 @@ impl EpicProtocol { .and_then(Value::as_u64) .map_or(false, |v| v == port as u64); - // If either address or port matches, return the session - if address_match || port_match { + // Prioritize exact match of both address and port + if address_match && port_match { return Ok(session); } + + // Store session that matches either the address or port + if address_match || port_match { + fallback_session = Some(session); + } + } + + // If no exact match, return the fallback session if available + if let Some(fallback) = fallback_session { + return Ok(fallback); } return Err( From ac65c040164106c354545f2fc810243cfe0d5cd9 Mon Sep 17 00:00:00 2001 From: Cain <75994858+cainthebest@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:19:25 +0100 Subject: [PATCH 3/7] revert(protocol): remove bad fallback and handle as err --- crates/lib/src/protocols/epic/protocol.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/crates/lib/src/protocols/epic/protocol.rs b/crates/lib/src/protocols/epic/protocol.rs index b331c425..4a6c6689 100644 --- a/crates/lib/src/protocols/epic/protocol.rs +++ b/crates/lib/src/protocols/epic/protocol.rs @@ -118,8 +118,6 @@ impl EpicProtocol { return Err(PacketBad.context("No servers provided.")); } - let mut fallback_session: Option = None; - for session in sessions.into_iter() { let attributes = session .get("attributes") @@ -137,20 +135,9 @@ impl EpicProtocol { .and_then(Value::as_u64) .map_or(false, |v| v == port as u64); - // Prioritize exact match of both address and port if address_match && port_match { return Ok(session); } - - // Store session that matches either the address or port - if address_match || port_match { - fallback_session = Some(session); - } - } - - // If no exact match, return the fallback session if available - if let Some(fallback) = fallback_session { - return Ok(fallback); } return Err( From 2ade7f9a4ea60c8e128014683b0d9c88dcdb2561 Mon Sep 17 00:00:00 2001 From: Cain <75994858+cainthebest@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:36:07 +0100 Subject: [PATCH 4/7] fix(protocol): clean up addr match in epic --- crates/lib/src/protocols/epic/protocol.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/crates/lib/src/protocols/epic/protocol.rs b/crates/lib/src/protocols/epic/protocol.rs index 4a6c6689..58c33f32 100644 --- a/crates/lib/src/protocols/epic/protocol.rs +++ b/crates/lib/src/protocols/epic/protocol.rs @@ -123,19 +123,12 @@ impl EpicProtocol { .get("attributes") .ok_or(PacketBad.context("Expected attributes field missing in sessions."))?; - let address_match = attributes + let full_address_match = attributes .get("ADDRESSBOUND_s") .and_then(Value::as_str) - .map_or(false, |v| { - v == format!("0.0.0.0:{}", port) || v == format!("{}:{}", address, port) - }); + .map_or(false, |v| v == address || v == format!("0.0.0.0:{}", port)); - let port_match = attributes - .get("GAMESERVER_PORT_l") - .and_then(Value::as_u64) - .map_or(false, |v| v == port as u64); - - if address_match && port_match { + if full_address_match { return Ok(session); } } From 2ef9a59a0f91a92034c1effa341464a2738675f5 Mon Sep 17 00:00:00 2001 From: Cain <75994858+cainthebest@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:45:09 +0100 Subject: [PATCH 5/7] fix(protocol): add ADDRESS_s back for epic --- crates/lib/src/protocols/epic/protocol.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/lib/src/protocols/epic/protocol.rs b/crates/lib/src/protocols/epic/protocol.rs index 58c33f32..f7194bb9 100644 --- a/crates/lib/src/protocols/epic/protocol.rs +++ b/crates/lib/src/protocols/epic/protocol.rs @@ -123,12 +123,16 @@ impl EpicProtocol { .get("attributes") .ok_or(PacketBad.context("Expected attributes field missing in sessions."))?; - let full_address_match = attributes + let address_match = attributes .get("ADDRESSBOUND_s") .and_then(Value::as_str) - .map_or(false, |v| v == address || v == format!("0.0.0.0:{}", port)); + .map_or(false, |v| v == address || v == format!("0.0.0.0:{}", port)) + || attributes + .get("ADDRESS_s") + .and_then(Value::as_str) + .map_or(false, |v| v == address || v == format!("0.0.0.0:{}", port)); - if full_address_match { + if address_match { return Ok(session); } } From 249f910bc6857ae4a04ac92f01a0fd7237f81001 Mon Sep 17 00:00:00 2001 From: Cain <75994858+cainthebest@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:08:48 +0100 Subject: [PATCH 6/7] fix(protocol): add GAMESERVER_PORT_1 match for epic --- crates/lib/src/protocols/epic/protocol.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/lib/src/protocols/epic/protocol.rs b/crates/lib/src/protocols/epic/protocol.rs index f7194bb9..9eb90df9 100644 --- a/crates/lib/src/protocols/epic/protocol.rs +++ b/crates/lib/src/protocols/epic/protocol.rs @@ -130,7 +130,11 @@ impl EpicProtocol { || attributes .get("ADDRESS_s") .and_then(Value::as_str) - .map_or(false, |v| v == address || v == format!("0.0.0.0:{}", port)); + .map_or(false, |v| v == address || v == format!("0.0.0.0:{}", port)) + || attributes + .get("GAMESERVER_PORT_1") + .and_then(Value::as_u64) + .map_or(false, |v| v == port as u64); if address_match { return Ok(session); From c574a8c7b25bdc82c4427698556acab30f2baa3c Mon Sep 17 00:00:00 2001 From: Cain <75994858+cainthebest@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:19:10 +0100 Subject: [PATCH 7/7] fix(protocol): remove ADDRESS_s from matching as it is always true --- crates/lib/src/protocols/epic/protocol.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/lib/src/protocols/epic/protocol.rs b/crates/lib/src/protocols/epic/protocol.rs index 9eb90df9..6ace21d6 100644 --- a/crates/lib/src/protocols/epic/protocol.rs +++ b/crates/lib/src/protocols/epic/protocol.rs @@ -127,10 +127,6 @@ impl EpicProtocol { .get("ADDRESSBOUND_s") .and_then(Value::as_str) .map_or(false, |v| v == address || v == format!("0.0.0.0:{}", port)) - || attributes - .get("ADDRESS_s") - .and_then(Value::as_str) - .map_or(false, |v| v == address || v == format!("0.0.0.0:{}", port)) || attributes .get("GAMESERVER_PORT_1") .and_then(Value::as_u64)