Skip to content

Commit

Permalink
Add MDNS reg type for 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxu committed Nov 13, 2024
1 parent 97c4a69 commit 88f33e7
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions crates/lan/src/mdns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ pub mod publisher;
pub mod search;

pub(crate) fn get_reg_type(game_version: &str) -> Result<String> {
let minor = game_version
.split(".")
.skip(1)
.take(1)
.next()
.ok_or_else(|| Error::InvalidVersionString(game_version.to_string()))?;
let num = format!("100{minor}")
let segments = game_version.split(".").collect::<Vec<&str>>();
if segments.len() != 4 {
return Err(Error::InvalidVersionString(game_version.to_string()));
}
let major = segments[0]
.parse::<i64>()
.map_err(|_| Error::InvalidVersionString(game_version.to_string()))?;
let major_offset = major - 1;
let minor = segments[1]
.parse::<i64>()
.map_err(|_| Error::InvalidVersionString(game_version.to_string()))?;
let num = format!("10{major_offset}{minor:02}")
.parse::<i64>()
.map_err(|_| Error::InvalidVersionString(game_version.to_string()))?;

Expand All @@ -27,4 +32,8 @@ fn test_get_reg_type() {
get_reg_type("1.34.0.00000").unwrap(),
"_blizzard._udp,_w3xp2732"
);
assert_eq!(
get_reg_type("2.0.0.00000").unwrap(),
"_blizzard._udp,_w3xp2774"
);
}

0 comments on commit 88f33e7

Please sign in to comment.