Browse Source

protocol: fix build with MSRV

master
Denis Drakhnia 2 weeks ago
parent
commit
ed4591559f
  1. 8
      master/src/master_server.rs
  2. 2
      protocol/Cargo.toml
  3. 3
      protocol/src/cursor.rs
  4. 7
      protocol/src/filter.rs
  5. 3
      protocol/src/lib.rs
  6. 2
      protocol/src/net/game.rs
  7. 2
      protocol/src/net/master.rs

8
master/src/master_server.rs

@ -146,8 +146,8 @@ impl<T> Entry<T> {
} }
impl Entry<ServerInfo> { impl Entry<ServerInfo> {
fn matches<Addr: AddrExt>(&self, addr: Addr, region: Region, filter: &Filter) -> bool { fn matches(&self, region: Region, filter: &Filter) -> bool {
self.region == region && filter.matches(addr.wrap(), &self.value) self.region == region && filter.matches(&self.value)
} }
} }
@ -448,9 +448,9 @@ impl<Addr: AddrExt> MasterServer<Addr> {
self.filtered_servers_nat.clear(); self.filtered_servers_nat.clear();
self.servers self.servers
.iter() .iter()
.filter(|(addr, info)| { .filter(|(_addr, info)| {
info.is_valid(now, self.timeout.server) info.is_valid(now, self.timeout.server)
&& info.matches(**addr, p.region, &p.filter) && info.matches(p.region, &p.filter)
}) })
.for_each(|(addr, info)| { .for_each(|(addr, info)| {
self.filtered_servers.push(*addr); self.filtered_servers.push(*addr);

2
protocol/Cargo.toml

@ -15,7 +15,7 @@ repository = "https://git.mentality.rip/numas13/xash3d-master"
default = ["std", "net"] default = ["std", "net"]
std = ["alloc"] std = ["alloc"]
alloc = [] alloc = []
net = [] net = ["std"]
[dependencies] [dependencies]
log = "0.4.18" log = "0.4.18"

3
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<T, E = CursorError> = core::result::Result<T, E>; pub type Result<T, E = CursorError> = core::result::Result<T, E>;

7
protocol/src/filter.rs

@ -29,7 +29,7 @@
//! * Do not have bots //! * Do not have bots
//! * Is not protected by a password //! * Is not protected by a password
use core::{fmt, net::SocketAddr, str::FromStr}; use core::{fmt, str::FromStr};
use bitflags::bitflags; use bitflags::bitflags;
@ -203,11 +203,10 @@ impl Filter<'_> {
} }
/// Returns `true` if a server matches the filter. /// Returns `true` if a server matches the filter.
pub fn matches<T>(&self, _addr: SocketAddr, info: &ServerInfo<T>) -> bool pub fn matches<T>(&self, info: &ServerInfo<T>) -> bool
where where
T: AsRef<[u8]>, T: AsRef<[u8]>,
{ {
// TODO: match addr
!((info.flags & self.flags_mask) != self.flags !((info.flags & self.flags_mask) != self.flags
|| self.gamedir.map_or(false, |s| *s != info.gamedir.as_ref()) || self.gamedir.map_or(false, |s| *s != info.gamedir.as_ref())
|| self.map.map_or(false, |s| *s != info.map.as_ref()) || self.map.map_or(false, |s| *s != info.map.as_ref())
@ -498,7 +497,7 @@ mod match_tests {
let iter = servers let iter = servers
.iter() .iter()
.enumerate() .enumerate()
.filter(|(_, (addr, server))| filter.matches(*addr, &server)) .filter(|(_, (_addr, server))| filter.matches(&server))
.map(|(i, _)| i); .map(|(i, _)| i);
assert_eq!(iter.collect::<Vec<_>>(), [$($expected),*]) assert_eq!(iter.collect::<Vec<_>>(), [$($expected),*])
); );

3
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<CursorError> for Error { impl From<CursorError> for Error {
fn from(source: CursorError) -> Self { fn from(source: CursorError) -> Self {

2
protocol/src/net/game.rs

@ -3,7 +3,7 @@
//! Game client packets. //! Game client packets.
use core::{fmt, net::SocketAddr}; use std::{fmt, net::SocketAddr};
use crate::{ use crate::{
cursor::{Cursor, CursorMut}, cursor::{Cursor, CursorMut},

2
protocol/src/net/master.rs

@ -3,7 +3,7 @@
//! Master server packets. //! Master server packets.
use core::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use crate::{ use crate::{
cursor::{Cursor, CursorMut}, cursor::{Cursor, CursorMut},

Loading…
Cancel
Save