Compare commits
2 Commits
7260ee9984
...
1b1b41d646
Author | SHA1 | Date | |
---|---|---|---|
1b1b41d646 | |||
702805cb0e |
62
Cargo.lock
generated
62
Cargo.lock
generated
@ -2,6 +2,15 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0453232ace82dee0dd0b4c87a59bd90f7b53b314f3e0f61fe2ee7c8a16482289"
|
||||
dependencies = [
|
||||
"const-random",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
@ -91,6 +100,26 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const-random"
|
||||
version = "0.1.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5aaf16c9c2c612020bcfd042e170f6e32de9b9d75adb5277cdbbd2e2c8c8299a"
|
||||
dependencies = [
|
||||
"const-random-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const-random-macro"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
"tiny-keccak",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.1.5"
|
||||
@ -103,6 +132,12 @@ version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.0.1"
|
||||
@ -118,6 +153,17 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.57"
|
||||
@ -324,6 +370,15 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny-keccak"
|
||||
version = "2.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
|
||||
dependencies = [
|
||||
"crunchy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.11"
|
||||
@ -345,6 +400,12 @@ version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.87"
|
||||
@ -502,6 +563,7 @@ dependencies = [
|
||||
name = "xash3d-master"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bitflags 2.4.0",
|
||||
"blake2b_simd",
|
||||
"chrono",
|
||||
|
@ -19,6 +19,7 @@ fastrand = "2.0.1"
|
||||
serde = { version = "1.0.188", features = ["derive"] }
|
||||
toml = "0.5.11"
|
||||
blake2b_simd = "<0.6"
|
||||
ahash = "<0.5"
|
||||
signal-hook = { version = "0.3.17", default-features = false }
|
||||
xash3d-protocol = { path = "../protocol", version = "0.1.0" }
|
||||
|
||||
|
@ -17,9 +17,23 @@ pub const DEFAULT_CONFIG_PATH: &str = "config/main.toml";
|
||||
pub const DEFAULT_MASTER_SERVER_IP: IpAddr = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
|
||||
pub const DEFAULT_MASTER_SERVER_PORT: u16 = 27010;
|
||||
pub const DEFAULT_CHALLENGE_TIMEOUT: u32 = 10;
|
||||
pub const DEFAULT_TIMEOUT: u32 = 300;
|
||||
pub const DEFAULT_SERVER_TIMEOUT: u32 = 300;
|
||||
pub const DEFAULT_ADMIN_TIMEOUT: u32 = 10;
|
||||
|
||||
pub const DEFAULT_HASH_LEN: usize = admin::HASH_LEN;
|
||||
|
||||
macro_rules! impl_helpers {
|
||||
($($f:ident: $t:ty),+$(,)?) => (
|
||||
$(const fn $f<const N: $t>() -> $t { N })+
|
||||
);
|
||||
}
|
||||
|
||||
impl_helpers! {
|
||||
default_u16: u16,
|
||||
default_u32: u32,
|
||||
default_usize: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
@ -65,7 +79,7 @@ impl Default for LogConfig {
|
||||
pub struct ServerConfig {
|
||||
#[serde(default = "default_server_ip")]
|
||||
pub ip: IpAddr,
|
||||
#[serde(default = "default_server_port")]
|
||||
#[serde(default = "default_u16::<DEFAULT_MASTER_SERVER_PORT>")]
|
||||
pub port: u16,
|
||||
#[serde(default)]
|
||||
pub timeout: TimeoutConfig,
|
||||
@ -75,7 +89,7 @@ impl Default for ServerConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
ip: default_server_ip(),
|
||||
port: default_server_port(),
|
||||
port: DEFAULT_MASTER_SERVER_PORT,
|
||||
timeout: Default::default(),
|
||||
}
|
||||
}
|
||||
@ -84,20 +98,20 @@ impl Default for ServerConfig {
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct TimeoutConfig {
|
||||
#[serde(default = "default_challenge_timeout")]
|
||||
#[serde(default = "default_u32::<DEFAULT_CHALLENGE_TIMEOUT>")]
|
||||
pub challenge: u32,
|
||||
#[serde(default = "default_timeout")]
|
||||
#[serde(default = "default_u32::<DEFAULT_SERVER_TIMEOUT>")]
|
||||
pub server: u32,
|
||||
#[serde(default = "default_admin_timeout")]
|
||||
#[serde(default = "default_u32::<DEFAULT_ADMIN_TIMEOUT>")]
|
||||
pub admin: u32,
|
||||
}
|
||||
|
||||
impl Default for TimeoutConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
challenge: default_challenge_timeout(),
|
||||
server: default_timeout(),
|
||||
admin: default_admin_timeout(),
|
||||
challenge: DEFAULT_CHALLENGE_TIMEOUT,
|
||||
server: DEFAULT_SERVER_TIMEOUT,
|
||||
admin: DEFAULT_ADMIN_TIMEOUT,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -119,7 +133,7 @@ pub struct ClientConfig {
|
||||
#[derive(Deserialize, Default, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct HashConfig {
|
||||
#[serde(default = "default_hash_len")]
|
||||
#[serde(default = "default_usize::<DEFAULT_HASH_LEN>")]
|
||||
pub len: usize,
|
||||
#[serde(default = "default_hash_key")]
|
||||
pub key: Box<str>,
|
||||
@ -142,26 +156,6 @@ fn default_server_ip() -> IpAddr {
|
||||
DEFAULT_MASTER_SERVER_IP
|
||||
}
|
||||
|
||||
fn default_server_port() -> u16 {
|
||||
DEFAULT_MASTER_SERVER_PORT
|
||||
}
|
||||
|
||||
fn default_challenge_timeout() -> u32 {
|
||||
DEFAULT_CHALLENGE_TIMEOUT
|
||||
}
|
||||
|
||||
fn default_timeout() -> u32 {
|
||||
DEFAULT_TIMEOUT
|
||||
}
|
||||
|
||||
fn default_admin_timeout() -> u32 {
|
||||
DEFAULT_ADMIN_TIMEOUT
|
||||
}
|
||||
|
||||
fn default_hash_len() -> usize {
|
||||
admin::HASH_LEN
|
||||
}
|
||||
|
||||
fn default_hash_key() -> Box<str> {
|
||||
Box::from(admin::HASH_KEY)
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// SPDX-FileCopyrightText: 2023 Denis Drakhnia <numas13@gmail.com>
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::io;
|
||||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, ToSocketAddrs, UdpSocket};
|
||||
use std::ops::Deref;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use ahash::{AHashMap as HashMap, AHashSet as HashSet};
|
||||
use blake2b_simd::Params;
|
||||
use fastrand::Rng;
|
||||
use log::{debug, error, info, trace, warn};
|
||||
@ -493,7 +493,8 @@ impl MasterServer {
|
||||
}
|
||||
|
||||
fn add_server(&mut self, addr: SocketAddrV4, server: ServerInfo) {
|
||||
match self.servers.insert(addr, Entry::new(self.now(), server)) {
|
||||
let entry = Entry::new(self.now(), server);
|
||||
match self.servers.insert(addr, entry) {
|
||||
Some(_) => trace!("{}: Updated GameServer", addr),
|
||||
None => trace!("{}: New GameServer", addr),
|
||||
}
|
||||
|
Reference in New Issue
Block a user