From ed4591559f952766f6bf17ea52aab8639f432359 Mon Sep 17 00:00:00 2001 From: Denis Drakhnia Date: Wed, 13 Nov 2024 09:15:11 +0200 Subject: [PATCH] protocol: fix build with MSRV --- master/src/master_server.rs | 8 ++++---- protocol/Cargo.toml | 2 +- protocol/src/cursor.rs | 3 ++- protocol/src/filter.rs | 7 +++---- protocol/src/lib.rs | 3 ++- protocol/src/net/game.rs | 2 +- protocol/src/net/master.rs | 2 +- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/master/src/master_server.rs b/master/src/master_server.rs index 54b5b2f..a45d417 100644 --- a/master/src/master_server.rs +++ b/master/src/master_server.rs @@ -146,8 +146,8 @@ impl Entry { } impl Entry { - fn matches(&self, addr: Addr, region: Region, filter: &Filter) -> bool { - self.region == region && filter.matches(addr.wrap(), &self.value) + fn matches(&self, region: Region, filter: &Filter) -> bool { + self.region == region && filter.matches(&self.value) } } @@ -448,9 +448,9 @@ impl MasterServer { self.filtered_servers_nat.clear(); self.servers .iter() - .filter(|(addr, info)| { + .filter(|(_addr, info)| { info.is_valid(now, self.timeout.server) - && info.matches(**addr, p.region, &p.filter) + && info.matches(p.region, &p.filter) }) .for_each(|(addr, info)| { self.filtered_servers.push(*addr); diff --git a/protocol/Cargo.toml b/protocol/Cargo.toml index 6dfb2fa..fb514e4 100644 --- a/protocol/Cargo.toml +++ b/protocol/Cargo.toml @@ -15,7 +15,7 @@ repository = "https://git.mentality.rip/numas13/xash3d-master" default = ["std", "net"] std = ["alloc"] alloc = [] -net = [] +net = ["std"] [dependencies] log = "0.4.18" diff --git a/protocol/src/cursor.rs b/protocol/src/cursor.rs index 86b9788..bdbab13 100644 --- a/protocol/src/cursor.rs +++ b/protocol/src/cursor.rs @@ -49,7 +49,8 @@ impl fmt::Display for CursorError { } } -impl core::error::Error for CursorError {} +#[cfg(feature = "std")] +impl std::error::Error for CursorError {} pub type Result = core::result::Result; diff --git a/protocol/src/filter.rs b/protocol/src/filter.rs index c8157b8..198bc1e 100644 --- a/protocol/src/filter.rs +++ b/protocol/src/filter.rs @@ -29,7 +29,7 @@ //! * Do not have bots //! * Is not protected by a password -use core::{fmt, net::SocketAddr, str::FromStr}; +use core::{fmt, str::FromStr}; use bitflags::bitflags; @@ -203,11 +203,10 @@ impl Filter<'_> { } /// Returns `true` if a server matches the filter. - pub fn matches(&self, _addr: SocketAddr, info: &ServerInfo) -> bool + pub fn matches(&self, info: &ServerInfo) -> bool where T: AsRef<[u8]>, { - // TODO: match addr !((info.flags & self.flags_mask) != self.flags || self.gamedir.map_or(false, |s| *s != info.gamedir.as_ref()) || self.map.map_or(false, |s| *s != info.map.as_ref()) @@ -498,7 +497,7 @@ mod match_tests { let iter = servers .iter() .enumerate() - .filter(|(_, (addr, server))| filter.matches(*addr, &server)) + .filter(|(_, (_addr, server))| filter.matches(&server)) .map(|(i, _)| i); assert_eq!(iter.collect::>(), [$($expected),*]) ); diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index 97395a2..434043e 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -85,7 +85,8 @@ impl fmt::Display for Error { } } -impl core::error::Error for Error {} +#[cfg(feature = "std")] +impl std::error::Error for Error {} impl From for Error { fn from(source: CursorError) -> Self { diff --git a/protocol/src/net/game.rs b/protocol/src/net/game.rs index 5e8bda7..7d2e4b3 100644 --- a/protocol/src/net/game.rs +++ b/protocol/src/net/game.rs @@ -3,7 +3,7 @@ //! Game client packets. -use core::{fmt, net::SocketAddr}; +use std::{fmt, net::SocketAddr}; use crate::{ cursor::{Cursor, CursorMut}, diff --git a/protocol/src/net/master.rs b/protocol/src/net/master.rs index bad5078..2abd925 100644 --- a/protocol/src/net/master.rs +++ b/protocol/src/net/master.rs @@ -3,7 +3,7 @@ //! Master server packets. -use core::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; +use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; use crate::{ cursor::{Cursor, CursorMut},