diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..fd11b04c9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,26 @@ +version: 2 +updates: + - package-ecosystem: "cargo" + directory: "/server/central" + schedule: + interval: "daily" + - package-ecosystem: "cargo" + directory: "/server/derive" + schedule: + interval: "daily" + - package-ecosystem: "cargo" + directory: "/server/esp" + schedule: + interval: "daily" + - package-ecosystem: "cargo" + directory: "/server/game" + schedule: + interval: "daily" + - package-ecosystem: "cargo" + directory: "/server/shared" + schedule: + interval: "daily" + - package-ecosystem: "cargo" + directory: "/server" + schedule: + interval: "daily" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 85aa71662..db85e66fe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,7 +43,7 @@ jobs: package: name: Package builds runs-on: ubuntu-latest - needs: ['build'] + needs: build steps: - name: Combine builds diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml index 1c4201bba..a2756d0ac 100644 --- a/.github/workflows/server.yml +++ b/.github/workflows/server.yml @@ -11,38 +11,36 @@ jobs: strategy: matrix: include: - - os: ubuntu-latest + - name: Linux + os: ubuntu-latest target: x86_64-unknown-linux-gnu - name: Linux x64 bin-suffix: "-x64" - - os: ubuntu-latest + - name: Linux ARM64 + os: ubuntu-latest target: aarch64-unknown-linux-gnu - name: Linux arm64 bin-suffix: "-arm64" - - os: windows-latest + - name: Windows + os: windows-latest target: x86_64-pc-windows-msvc - name: Windows x64 bin-suffix: ".exe" steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v4 - - name: Install rust - uses: actions-rs/toolchain@v1 + - name: Setup Rust + uses: dtolnay/rust-toolchain@nightly with: toolchain: nightly target: ${{ matrix.target }} - override: true - - name: Add rust target + - name: Add Rust target if: matrix.target != 'aarch64-unknown-linux-gnu' run: rustup target add ${{ matrix.target }} shell: bash - # install cross for arm target - name: Install cross if: matrix.target == 'aarch64-unknown-linux-gnu' run: | @@ -87,8 +85,7 @@ jobs: shell: bash - name: Create artifacts folder - run: | - mkdir -p server/artifacts + run: mkdir -p server/artifacts shell: bash - name: Copy artifacts (Windows) diff --git a/server/central/Cargo.toml b/server/central/Cargo.toml index eac3ebc14..e3dc37e27 100644 --- a/server/central/Cargo.toml +++ b/server/central/Cargo.toml @@ -1,25 +1,26 @@ [package] name = "globed-central-server" version = "1.4.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +edition = "2024" [dependencies] globed-shared = { path = "../shared" } -async-watcher = "0.2.1" -blake2 = "0.10.6" -digest = "0.10.7" -ipnet = "2.9.0" +async-watcher = "0.3.0" +blake2 = "0.11.0-pre.4" +digest = "0.11.0-pre.9" +ipnet = "2.10.1" iprange = "0.6.7" -serde = { version = "1.0.202", features = ["serde_derive"] } -serde_json = "1.0.117" -tokio = { version = "1.37.0", features = ["full"] } +serde = { version = "1.0.215", features = ["serde_derive"] } +serde_json = "1.0.133" +tokio = { version = "1.41.1", features = ["full"] } json_comments = "0.2.2" -rocket = { version = "0.5.0", features = ["json"] } -rocket_db_pools = { version = "0.1.0", features = ["sqlx_sqlite"] } -sqlx = { version = "0.7.4", features = ["migrate"] } +rocket = { version = "0.5.1", features = ["json"] } +rocket_db_pools = { version = "0.2.0", features = ["sqlx_sqlite"] } +sqlx = { version = "^0.7.0", features = [ # TODO: rocket_db_pools is broken in sqlx 0.8.x + "migrate", + "runtime-tokio-rustls", +] } rocket_cors = "0.6.0" -const_format = "0.2.32" +const_format = "0.2.33" hex = "0.4.3" diff --git a/server/central/build.rs b/server/central/build.rs index c8d152ab0..25c393629 100644 --- a/server/central/build.rs +++ b/server/central/build.rs @@ -1,5 +1,3 @@ -use std::env; - fn main() { // trigger recompilation when a new migration is added println!("cargo:rerun-if-changed=migrations"); diff --git a/server/central/src/game_pinger.rs b/server/central/src/game_pinger.rs index 973d077c0..24aa6861e 100644 --- a/server/central/src/game_pinger.rs +++ b/server/central/src/game_pinger.rs @@ -62,7 +62,7 @@ impl GameServerPinger { // ping packet LOL let mut buffer = ByteBuffer::new(); - let ping_id = rand::thread_rng().gen(); + let ping_id = rand::rng().random(); buffer.write_u16(10000); buffer.write_bool(false); buffer.write_u32(ping_id); diff --git a/server/central/src/main.rs b/server/central/src/main.rs index 4fbe13b23..80990edb9 100644 --- a/server/central/src/main.rs +++ b/server/central/src/main.rs @@ -16,14 +16,13 @@ use std::{ time::Duration, }; -use async_watcher::{notify::RecursiveMode, AsyncDebouncer}; +use async_watcher::{AsyncDebouncer, notify::RecursiveMode}; use config::ServerConfig; use db::GlobedDb; use game_pinger::GameServerPinger; use globed_shared::{ - get_log_level, - logger::{error, info, log, warn, Logger}, - LogLevelFilter, + LogLevelFilter, get_log_level, + logger::{Logger, error, info, log, warn}, }; use rocket::catchers; use rocket_db_pools::Database; @@ -62,7 +61,7 @@ async fn main() -> Result<(), Box> { // create Rocket.toml if it doesn't exist let rocket_toml = std::env::var("ROCKET_CONFIG").map_or_else(|_| std::env::current_dir().unwrap().join("Rocket.toml"), PathBuf::from); - if !rocket_toml.file_name().is_some_and(|x| x == "Rocket.toml") || !rocket_toml.parent().is_some_and(Path::exists) { + if rocket_toml.file_name().is_none_or(|x| x != "Rocket.toml") || !rocket_toml.parent().is_some_and(Path::exists) { error!("invalid value for ROCKET_CONFIG"); warn!("hint: the filename must be 'Rocket.toml' and the parent folder must exist on the disk"); abort_misconfig(); diff --git a/server/central/src/state.rs b/server/central/src/state.rs index 72c97a68d..d9998bdf8 100644 --- a/server/central/src/state.rs +++ b/server/central/src/state.rs @@ -4,28 +4,27 @@ use std::{ net::IpAddr, path::PathBuf, sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, time::{Duration, SystemTime}, }; use globed_shared::{ - anyhow, - base64::{engine::general_purpose::STANDARD as b64e, Engine}, - crypto_box::aead::{generic_array::GenericArray, AeadMutInPlace}, - crypto_secretbox::{KeyInit, XSalsa20Poly1305}, + TokenIssuer, anyhow, + base64::{Engine, engine::general_purpose::STANDARD as b64e}, + crypto_box::aead::{AeadMutInPlace, generic_array::GenericArray}, + crypto_secretbox::{KeyInit as _, XSalsa20Poly1305}, hmac::Hmac, - rand::{self, distributions::Alphanumeric, rngs::OsRng, Rng, RngCore}, + rand::{self, distr::Alphanumeric, prelude::*}, reqwest, sha2::Sha256, - TokenIssuer, }; use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use crate::{config::ServerConfig, db::GlobedDb, game_pinger::GameServerPinger, verifier::AccountVerifier}; use blake2::{Blake2b, Digest}; -use digest::consts::U32; +use digest::{KeyInit as _, consts::U32}; #[derive(Clone)] pub struct ActiveChallenge { @@ -63,7 +62,7 @@ impl ServerStateData { let hmac = Hmac::::new_from_slice(skey_bytes).unwrap(); let mut challenge_pubkey = GenericArray::::default(); - OsRng.fill_bytes(&mut challenge_pubkey); + rand::rng().fill_bytes(&mut challenge_pubkey); let challenge_box = XSalsa20Poly1305::new(&challenge_pubkey); let token_expiry = Duration::from_secs(config.token_expiry); @@ -97,10 +96,10 @@ impl ServerStateData { ip_address: IpAddr, current_time: SystemTime, ) -> anyhow::Result { - let answer: String = rand::thread_rng().sample_iter(&Alphanumeric).take(16).map(char::from).collect(); + let answer: String = rand::rng().sample_iter(&Alphanumeric).take(16).map(char::from).collect(); let mut nonce = [0u8; XSalsa20Poly1305::NONCE_SIZE]; - OsRng.fill_bytes(&mut nonce); + rand::rng().fill_bytes(&mut nonce); let nonce_start = 0usize; let mac_start = nonce_start + XSalsa20Poly1305::NONCE_SIZE; @@ -223,15 +222,12 @@ impl ServerStateData { lowercase.hash(&mut hasher); let hash = hasher.finish(); - self.last_logins.insert( - hash, - LoginEntry { - account_id, - name: name.to_owned(), - time: SystemTime::now(), - link_code, - }, - ); + self.last_logins.insert(hash, LoginEntry { + account_id, + name: name.to_owned(), + time: SystemTime::now(), + link_code, + }); } pub fn remove_login_code(&mut self, name: &str) { diff --git a/server/central/src/web/routes/auth.rs b/server/central/src/web/routes/auth.rs index f70ba2194..64c253f72 100644 --- a/server/central/src/web/routes/auth.rs +++ b/server/central/src/web/routes/auth.rs @@ -1,15 +1,15 @@ use std::{net::IpAddr, time::SystemTime}; -use digest::KeyInit; -use rocket::{post, State}; +use rocket::{State, post}; use serde::Deserialize; use globed_shared::{ + MIN_CLIENT_VERSION, anyhow::{self, anyhow}, - base64::{engine::general_purpose as b64e, Engine as _}, + base64::{Engine as _, engine::general_purpose as b64e}, crypto_box::aead::Aead, + crypto_secretbox::{KeyInit, XSalsa20Poly1305}, logger::*, - MIN_CLIENT_VERSION, }; use super::*; @@ -229,7 +229,7 @@ fn decrypt_trust_token(token: &str, key: &str) -> WebResult> { let mut key_arr = [0u8; 32]; key_arr.copy_from_slice(&key); - let cipher = globed_shared::crypto_secretbox::XSalsa20Poly1305::new((&key_arr).into()); + let cipher = XSalsa20Poly1305::new((&key_arr).into()); let nonce = encrypted[..24].into(); let ciphertext = &encrypted[24..]; @@ -320,7 +320,7 @@ pub async fn challenge_verify( // verify trust token let trust_token = if let Ok(sm_key) = std::env::var("GLOBED_GS_SECURE_MODE_KEY") { if let Some(trust_token) = &post_data.0.trust_token { - let decrypted = String::from_utf8(decrypt_trust_token(&trust_token, &sm_key)?)?; + let decrypted = String::from_utf8(decrypt_trust_token(trust_token, &sm_key)?)?; if let Some((s_value, token_rest)) = decrypted.split_once('|') { if s_value != challenge.value { unauthorized!("security check failed: trust token value mismatch"); diff --git a/server/central/src/web/routes/meta.rs b/server/central/src/web/routes/meta.rs index 087ab9720..1223c8547 100644 --- a/server/central/src/web/routes/meta.rs +++ b/server/central/src/web/routes/meta.rs @@ -1,17 +1,16 @@ use std::sync::OnceLock; use globed_shared::{ - base64::{engine::general_purpose as b64e, Engine as _}, + MAX_SUPPORTED_PROTOCOL, MIN_CLIENT_VERSION, MIN_GD_VERSION, MIN_SUPPORTED_PROTOCOL, SERVER_MAGIC, + base64::{Engine as _, engine::general_purpose as b64e}, esp::{ByteBuffer, ByteBufferExt, ByteBufferExtWrite}, rand::{self, Rng}, - MAX_SUPPORTED_PROTOCOL, MIN_CLIENT_VERSION, MIN_GD_VERSION, MIN_SUPPORTED_PROTOCOL, SERVER_MAGIC, }; use rocket::{ - get, + State, get, http::{ContentType, Status}, serde::json::Json, - State, }; use serde::Serialize; @@ -76,7 +75,7 @@ pub fn versioncheck(gd: &str, globed: &str, protocol: u16) -> WebResult (Status, (ContentType, String)) { - if rand::thread_rng().gen_ratio(1, 0xaa) { + if rand::rng().random_ratio(1, 0xaa) { return _check(); } diff --git a/server/central/src/web/routes/user.rs b/server/central/src/web/routes/user.rs index 73698966f..446a40c1f 100644 --- a/server/central/src/web/routes/user.rs +++ b/server/central/src/web/routes/user.rs @@ -1,11 +1,12 @@ use globed_shared::{ + ServerUserEntry, UserLoginData, UserLoginResponse, data::*, logger::debug, rand::{self, Rng}, - warn, ServerUserEntry, UserLoginData, UserLoginResponse, + warn, }; -use rocket::{get, post, serde::json::Json, State}; +use rocket::{State, get, post, serde::json::Json}; use serde::{Deserialize, Serialize}; use crate::{db::GlobedDb, state::ServerState, web::*}; @@ -188,7 +189,7 @@ pub async fn user_login( unauthorized!("invalid gameserver credentials"); } - let link_code = rand::thread_rng().gen_range(1000..10_000); + let link_code = rand::rng().random_range(1000..10_000); // store login attempt state.state_write().await.put_login(&userdata.0.name, userdata.0.account_id, link_code); diff --git a/server/derive/Cargo.toml b/server/derive/Cargo.toml index 1793f8c02..68a45441d 100644 --- a/server/derive/Cargo.toml +++ b/server/derive/Cargo.toml @@ -1,15 +1,13 @@ [package] name = "globed-derive" version = "1.0.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +edition = "2024" [lib] proc-macro = true [dependencies] -darling = "0.20.9" -proc-macro2 = "1.0.82" -quote = "1.0.36" -syn = { version = "2.0.63", features = ["full"] } +darling = "0.20.10" +proc-macro2 = "1.0.92" +quote = "1.0.37" +syn = { version = "2.0.90", features = ["full"] } diff --git a/server/derive/src/lib.rs b/server/derive/src/lib.rs index c3d7eb390..511d17749 100644 --- a/server/derive/src/lib.rs +++ b/server/derive/src/lib.rs @@ -25,7 +25,7 @@ pub fn derive_encodable(input: TokenStream) -> TokenStream { let struct_name = &input.ident; let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - let gen = match &input.data { + let other_gen = match &input.data { Data::Struct(data) if let Some(bit_attrs) = bit_attrs => { encode::for_bit_struct(data, bit_attrs, struct_name, &impl_generics, &ty_generics, where_clause) } @@ -39,7 +39,7 @@ pub fn derive_encodable(input: TokenStream) -> TokenStream { } }; - gen.into() + other_gen.into() } /// Implements `Decodable` for the given type, allowing you to deserialize it from a `ByteReader`/`ByteBuffer`. @@ -54,7 +54,7 @@ pub fn derive_decodable(input: TokenStream) -> TokenStream { let struct_name = &input.ident; - let gen = match &input.data { + let other_gen = match &input.data { Data::Struct(data) if let Some(bit_attrs) = bit_attrs => decode::for_bit_struct(data, bit_attrs, struct_name), Data::Struct(data) => decode::for_struct(data, struct_name), Data::Enum(data) => decode::for_enum(data, struct_name, &get_enum_repr_type(&input)), @@ -66,7 +66,7 @@ pub fn derive_decodable(input: TokenStream) -> TokenStream { } }; - gen.into() + other_gen.into() } /// Implements `StaticSize` for the given type, allowing you to compute the encoded size of the value at compile time. @@ -111,14 +111,14 @@ pub fn derive_static_size(input: TokenStream) -> TokenStream { } }; - let gen = quote! { + let other_gen = quote! { impl StaticSize for #struct_name { const ENCODED_SIZE: usize = #encoded_size; } }; // Return the generated implementation as a TokenStream - gen.into() + other_gen.into() } /// Implements `DynamicSize` for the given type, allowing you to compute the encoded size of the value at runtime. @@ -190,7 +190,7 @@ pub fn derive_dynamic_size(input: TokenStream) -> TokenStream { } }; - let gen = quote! { + let other_gen = quote! { impl #impl_generics DynamicSize for #struct_name #ty_generics #where_clause { #[inline] fn encoded_size(&self) -> usize { @@ -200,7 +200,7 @@ pub fn derive_dynamic_size(input: TokenStream) -> TokenStream { }; // Return the generated implementation as a TokenStream - gen.into() + other_gen.into() } /// Implements `Packet`, `PacketMetadata` and the function `const fn header() -> PacketHeader` for the given struct. diff --git a/server/esp/Cargo.toml b/server/esp/Cargo.toml index cf20b3e67..6a0347252 100644 --- a/server/esp/Cargo.toml +++ b/server/esp/Cargo.toml @@ -1,14 +1,12 @@ [package] name = "esp" version = "1.0.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +edition = "2024" [dependencies] simd-adler32 = { version = "0.3.7", default-features = false } -bytebuffer = "2.2.0" -crc32fast = "1.4.0" +bytebuffer = "2.3.0" +crc32fast = "1.4.2" [dev-dependencies] globed-derive = { path = "../derive" } diff --git a/server/esp/src/common.rs b/server/esp/src/common.rs index c5648f220..20864aa94 100644 --- a/server/esp/src/common.rs +++ b/server/esp/src/common.rs @@ -10,11 +10,7 @@ use std::{ // this is bizarre const fn constmax(a: usize, b: usize) -> usize { - if a >= b { - a - } else { - b - } + if a >= b { a } else { b } } macro_rules! impl_primitive { @@ -153,7 +149,7 @@ where /* Cow<'a, T> */ -impl<'a, T: ?Sized + ToOwned> Encodable for Cow<'a, T> +impl Encodable for Cow<'_, T> where ::Owned: Encodable, T: Encodable, @@ -175,7 +171,7 @@ where } } -impl<'a, T: ?Sized + ToOwned> Decodable for Cow<'a, T> +impl Decodable for Cow<'_, T> where ::Owned: Decodable, T: Decodable, @@ -189,7 +185,7 @@ where } } -impl<'a, T: ?Sized + ToOwned> DynamicSize for Cow<'a, T> +impl DynamicSize for Cow<'_, T> where ::Owned: DynamicSize, T: DynamicSize, diff --git a/server/esp/src/lib.rs b/server/esp/src/lib.rs index 51d0ecdae..3023b3679 100644 --- a/server/esp/src/lib.rs +++ b/server/esp/src/lib.rs @@ -439,7 +439,7 @@ impl ByteBufferExtWrite for ByteBuffer { impl_extwrite!(encode); } -impl<'a> ByteBufferExtWrite for FastByteBuffer<'a> { +impl ByteBufferExtWrite for FastByteBuffer<'_> { impl_extwrite!(encode_fast); } @@ -447,7 +447,7 @@ impl ByteBufferExtRead for ByteBuffer { impl_extread!(decode); } -impl<'a> ByteBufferExtRead for ByteReader<'a> { +impl ByteBufferExtRead for ByteReader<'_> { impl_extread!(decode_from_reader); } diff --git a/server/esp/src/types/fast_string.rs b/server/esp/src/types/fast_string.rs index 9f726f2fe..ddcaa00b0 100644 --- a/server/esp/src/types/fast_string.rs +++ b/server/esp/src/types/fast_string.rs @@ -296,7 +296,7 @@ impl FastString { /// Converts the string to a `&str`, bypassing utf-8 validation checks #[inline] pub unsafe fn to_str_unchecked(&self) -> &str { - std::str::from_utf8_unchecked(self.as_bytes()) + unsafe { std::str::from_utf8_unchecked(self.as_bytes()) } } /// Converts the string to a `&str`, returns """ if utf-8 validation fails diff --git a/server/esp/src/types/inline_string.rs b/server/esp/src/types/inline_string.rs index 17a0ff77c..031710059 100644 --- a/server/esp/src/types/inline_string.rs +++ b/server/esp/src/types/inline_string.rs @@ -127,7 +127,7 @@ impl InlineString { .expect("Attempted to unsafely convert a non-UTF-8 InlineString into a string slice"); #[cfg(not(debug_assertions))] - let ret = std::str::from_utf8_unchecked(&self.buffer[..self.len()]); + let ret = unsafe { std::str::from_utf8_unchecked(&self.buffer[..self.len()]) }; ret } diff --git a/server/game/Cargo.toml b/server/game/Cargo.toml index 8d3f50de8..f95187e44 100644 --- a/server/game/Cargo.toml +++ b/server/game/Cargo.toml @@ -1,9 +1,7 @@ [package] name = "globed-game-server" version = "1.4.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +edition = "2024" [dependencies] globed-shared = { path = "../shared" } @@ -11,18 +9,18 @@ globed-derive = { path = "../derive" } esp = { path = "../esp" } alloca = "0.4.0" -ctrlc = "3.4.4" -rustc-hash = "1.1.0" -serde = { version = "1.0.202", features = ["serde_derive"] } -serde_json = "1.0.117" -futures-util = "0.3.30" -console-subscriber = { version = "0.2.0", features = ["parking_lot"] } - -# tokio_tracing = { package = "tokio", version = "1.37.0", features = [ +ctrlc = "3.4.5" +rustc-hash = "2.1.0" +serde = { version = "1.0.215", features = ["serde_derive"] } +serde_json = "1.0.133" +futures-util = "0.3.31" +console-subscriber = { version = "0.4.1", features = ["parking_lot"] } + +# tokio_tracing = { package = "tokio", version = "1.41.1", features = [ # "full", # "tracing", # ], optional = true } -tokio = { version = "1.37.0", features = ["full"], optional = true } +tokio = { version = "1.41.1", features = ["full"], optional = true } aho-corasick = "1.1.3" [dev-dependencies] diff --git a/server/game/src/bridge.rs b/server/game/src/bridge.rs index 67ec35b0d..fcdc2fa9f 100644 --- a/server/game/src/bridge.rs +++ b/server/game/src/bridge.rs @@ -7,14 +7,14 @@ use std::{ }; use esp::{ - size_of_types, ByteBuffer, ByteBufferExt, ByteBufferExtRead, ByteBufferExtWrite, ByteReader, Decodable, DecodeError, DynamicSize, Encodable, - FastVec, StaticSize, + ByteBuffer, ByteBufferExt, ByteBufferExtRead, ByteBufferExtWrite, ByteReader, Decodable, DecodeError, DynamicSize, Encodable, FastVec, + StaticSize, size_of_types, }; use globed_derive::{DynamicSize, Encodable}; use globed_shared::{ + GameServerBootData, MAX_SUPPORTED_PROTOCOL, SERVER_MAGIC, SERVER_MAGIC_LEN, ServerUserEntry, SyncMutex, TokenIssuer, UserLoginResponse, data::*, reqwest::{self, Response, StatusCode}, - GameServerBootData, ServerUserEntry, SyncMutex, TokenIssuer, UserLoginResponse, MAX_SUPPORTED_PROTOCOL, SERVER_MAGIC, SERVER_MAGIC_LEN, }; use crate::webhook::{self, *}; @@ -160,7 +160,7 @@ impl CentralBridge { // verify that the magic bytes match let valid_magic = reader .read_value_array::() - .map_or(false, |magic| magic.iter().eq(SERVER_MAGIC.iter())); + .is_ok_and(|magic| magic.iter().eq(SERVER_MAGIC.iter())); if !valid_magic { let txt = String::from_utf8(reader.as_bytes().to_vec()).unwrap_or_else(|_| "".to_owned()); @@ -377,6 +377,7 @@ impl CentralBridge { Ok(()) } + #[allow(clippy::too_many_arguments)] pub async fn send_webhook_message_for_action( &self, action: &AdminUserAction, diff --git a/server/game/src/client/socket.rs b/server/game/src/client/socket.rs index a697c32eb..829f6cf45 100644 --- a/server/game/src/client/socket.rs +++ b/server/game/src/client/socket.rs @@ -431,7 +431,7 @@ impl ClientSocket { let mut vec = vec![0u8; self.mtu]; let mut buf = FastByteBuffer::new(&mut vec[..]); - let unique_id: u32 = globed_shared::rand::thread_rng().gen(); + let unique_id: u32 = globed_shared::rand::rng().random(); // // ok let chunk_size = self.mtu - 8; diff --git a/server/game/src/client/thread.rs b/server/game/src/client/thread.rs index cf8923a9a..1c9d2b053 100644 --- a/server/game/src/client/thread.rs +++ b/server/game/src/client/thread.rs @@ -3,8 +3,8 @@ use std::{ collections::VecDeque, net::SocketAddrV4, sync::{ - atomic::{AtomicBool, AtomicI32, AtomicU16, AtomicU32, Ordering}, Arc, + atomic::{AtomicBool, AtomicI32, AtomicU16, AtomicU32, Ordering}, }, time::Duration, }; @@ -17,7 +17,7 @@ use crate::{ }, }; use esp::ByteReader; -use globed_shared::{logger::*, should_ignore_error, ServerUserEntry, SyncMutex}; +use globed_shared::{ServerUserEntry, SyncMutex, logger::*, should_ignore_error}; use handlers::game::MAX_VOICE_PACKET_SIZE; use tokio::time::Instant; @@ -300,7 +300,7 @@ impl ClientThread { warn!("[{} @ {}] {}", self.account_id.load(Ordering::Relaxed), self.get_tcp_peer(), error); } - PacketHandlingError::IOError(ref e) => { + PacketHandlingError::IOError(e) => { if !should_ignore_error(e) { warn!("[{} @ {}] {}", self.account_id.load(Ordering::Relaxed), self.get_tcp_peer(), e); } @@ -447,7 +447,7 @@ impl ClientThread { // decrypt the packet in-place if encrypted if header.encrypted { - data = unsafe { self.socket.get_mut() }.decrypt(message)?; + data = unsafe { self.socket.get_mut().decrypt(message)? }; } match header.packet_id { diff --git a/server/game/src/client/unauthorized.rs b/server/game/src/client/unauthorized.rs index 7bc83e9cb..c02a9673c 100644 --- a/server/game/src/client/unauthorized.rs +++ b/server/game/src/client/unauthorized.rs @@ -81,7 +81,7 @@ impl UnauthorizedThread { socket: LockfreeMutCell::new(ClientSocket::new(socket, peer, 0, game_server)), connection_state: AtomicClientThreadState::default(), - secret_key: rand::thread_rng().gen(), + secret_key: rand::rng().random(), protocol_version: AtomicU16::new(0), account_id: AtomicI32::new(0), @@ -345,7 +345,7 @@ impl UnauthorizedThread { ); } - unsafe { self.socket.get_mut() }.set_mtu(packet.fragmentation_limit as usize); + unsafe { self.socket.get_mut().set_mtu(packet.fragmentation_limit as usize) }; if packet.account_id <= 0 || packet.user_id <= 0 { let message = Cow::Owned(format!( diff --git a/server/game/src/data/mod.rs b/server/game/src/data/mod.rs index 2a107a32c..84b50ce05 100644 --- a/server/game/src/data/mod.rs +++ b/server/game/src/data/mod.rs @@ -6,9 +6,9 @@ pub use esp::*; pub use globed_derive::*; pub use globed_shared::MAX_NAME_SIZE; +pub use v_current::VERSION as CURRENT_PROTOCOL; pub use v_current::packets; pub use v_current::types; -pub use v_current::VERSION as CURRENT_PROTOCOL; pub use packets::*; pub use types::*; @@ -39,7 +39,7 @@ impl ByteBufferExtRead2 for ByteBuffer { } } -impl<'a> ByteBufferExtRead2 for ByteReader<'a> { +impl ByteBufferExtRead2 for ByteReader<'_> { #[inline] fn read_packet_header(&mut self) -> DecodeResult { self.read_value() @@ -73,7 +73,7 @@ impl ByteBufferExtWrite2 for ByteBuffer { } } -impl<'a> ByteBufferExtWrite2 for FastByteBuffer<'a> { +impl ByteBufferExtWrite2 for FastByteBuffer<'_> { #[inline] fn write_packet_header(&mut self) { self.write_value(&PacketHeader::from_packet::()); diff --git a/server/game/src/managers/room.rs b/server/game/src/managers/room.rs index 069d5d596..be8a1ad6f 100644 --- a/server/game/src/managers/room.rs +++ b/server/game/src/managers/room.rs @@ -246,7 +246,7 @@ impl RoomManager { // in case we accidentally generate an existing room id, keep looping until we find a suitable id let room_id = loop { - let room_id = rand::thread_rng().gen_range(ROOM_ID_START..ROOM_ID_END); + let room_id = rand::rng().random_range(ROOM_ID_START..ROOM_ID_END); if !rooms.contains_key(&room_id) { break room_id; } diff --git a/server/game/src/server.rs b/server/game/src/server.rs index f15181d4f..4eff873f9 100644 --- a/server/game/src/server.rs +++ b/server/game/src/server.rs @@ -1,16 +1,17 @@ use std::{ collections::VecDeque, net::{SocketAddr, SocketAddrV4}, - sync::{atomic::Ordering, Arc}, + sync::{Arc, atomic::Ordering}, time::Duration, }; use globed_shared::{ + ServerUserEntry, SyncMutex, anyhow::{self, anyhow, bail}, - crypto_box::{aead::OsRng, PublicKey, SecretKey}, + crypto_box::{PublicKey, SecretKey, aead::OsRng}, esp::ByteBufferExtWrite as _, logger::*, - should_ignore_error, ServerUserEntry, SyncMutex, + should_ignore_error, }; use rustc_hash::FxHashMap; use tokio::{ @@ -33,7 +34,7 @@ use crate::{ use crate::{ bridge::{self, CentralBridge}, - client::{thread::ClientThreadOutcome, unauthorized::UnauthorizedThread, ClientThread, ServerThreadMessage, UnauthorizedThreadOutcome}, + client::{ClientThread, ServerThreadMessage, UnauthorizedThreadOutcome, thread::ClientThreadOutcome, unauthorized::UnauthorizedThread}, data::*, state::ServerState, }; diff --git a/server/game/src/util/channel.rs b/server/game/src/util/channel.rs index b16beac08..9be930c5a 100644 --- a/server/game/src/util/channel.rs +++ b/server/game/src/util/channel.rs @@ -33,7 +33,7 @@ impl TokioChannel { /// Safety: is guaranteed to be safe as long as you don't call it from multiple threads at once. pub async unsafe fn recv(&self) -> Result { - let chan = self.rx.get_mut(); + let chan = unsafe { self.rx.get_mut() }; chan.recv().await.ok_or(SenderDropped) } } diff --git a/server/game/src/util/lockfreemutcell.rs b/server/game/src/util/lockfreemutcell.rs index 90bc2f43c..0842bd968 100644 --- a/server/game/src/util/lockfreemutcell.rs +++ b/server/game/src/util/lockfreemutcell.rs @@ -14,7 +14,7 @@ impl LockfreeMutCell { } pub unsafe fn get(&self) -> &T { - &*self.cell.get() + unsafe { &*self.cell.get() } } /// We trust you have received the usual lecture from the local System @@ -27,10 +27,10 @@ impl LockfreeMutCell { /// #3) With great power comes great responsibility. #[allow(clippy::mut_from_ref)] pub unsafe fn get_mut(&self) -> &mut T { - &mut *self.cell.get() + unsafe { &mut *self.cell.get() } } pub unsafe fn swap(&self, new: T) -> T { - std::mem::replace(self.get_mut(), new) + std::mem::replace(unsafe { self.get_mut() }, new) } } diff --git a/server/observer-shared/Cargo.toml b/server/observer-shared/Cargo.toml index 6343d11d0..5a11969f8 100644 --- a/server/observer-shared/Cargo.toml +++ b/server/observer-shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "observer-shared" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] diff --git a/server/observer/Cargo.toml b/server/observer/Cargo.toml index 52ad33599..00332dc33 100644 --- a/server/observer/Cargo.toml +++ b/server/observer/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "observer" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] globed-shared = { path = "../shared" } globed-derive = { path = "../derive" } observer-shared = { path = "../observer-shared" } esp = { path = "../esp" } -egui = "0.27.2" +egui = "0.29.1" diff --git a/server/shared/Cargo.toml b/server/shared/Cargo.toml index 7cceb673d..78b3727c2 100644 --- a/server/shared/Cargo.toml +++ b/server/shared/Cargo.toml @@ -1,29 +1,27 @@ [package] name = "globed-shared" version = "1.0.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +edition = "2024" [dependencies] esp = { path = "../esp" } globed-derive = { path = "../derive" } -anyhow = "1.0.83" -base64 = "0.21.7" +anyhow = "1.0.93" +base64 = "0.22.1" colored = "2.1.0" crypto_box = { version = "0.9.1", features = ["std", "chacha20"] } -hmac = "0.12.1" -log = { version = "0.4.21" } +hmac = "0.13.0-pre.4" +log = "0.4.22" nohash-hasher = "0.2.0" -parking_lot = "0.12.2" -rand = "0.8.5" -reqwest = { version = "0.12.4", default-features = false, features = [ +parking_lot = "0.12.3" +rand = "0.9.0-beta.1" +reqwest = { version = "0.12.9", default-features = false, features = [ "rustls-tls", ] } -sha2 = "0.10.8" +sha2 = "0.11.0-pre.4" time = { version = "0.3.36", features = ["formatting"] } -serde = { version = "1.0.202", features = ["derive"] } +serde = { version = "1.0.215", features = ["derive"] } crypto_secretbox = { version = "0.1.1", features = ["chacha20"] } -serde_json = "1.0.120" -argon2 = "0.5.3" +serde_json = "1.0.133" +argon2 = "0.6.0-pre.1" diff --git a/server/shared/src/lib.rs b/server/shared/src/lib.rs index 62a057c0b..9bb31c6ea 100644 --- a/server/shared/src/lib.rs +++ b/server/shared/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(const_option)] #![allow( clippy::must_use_candidate, clippy::module_name_repetitions, @@ -9,7 +8,8 @@ use esp::{Decodable, DynamicSize, Encodable, StaticSize}; pub use globed_derive::{Decodable, DynamicSize, Encodable, StaticSize}; -use rand::{distributions::Alphanumeric, Rng}; +use rand::distr::Alphanumeric; +use rand::prelude::*; // import reexports pub use nohash_hasher::{IntMap, IntSet}; @@ -59,7 +59,7 @@ pub const DEFAULT_CENTRAL_SERVER_PORT: u16 = 4201; pub const DEFAULT_GAME_SERVER_PORT: u16 = 4202; pub fn generate_alphanum_string(n: usize) -> String { - rand::thread_rng().sample_iter(&Alphanumeric).take(n).map(char::from).collect() + rand::rng().sample_iter(&Alphanumeric).take(n).map(char::from).collect() } pub fn get_log_level(env_var: &str) -> Option { diff --git a/server/shared/src/token_issuer.rs b/server/shared/src/token_issuer.rs index ab59c86d6..193b62e76 100644 --- a/server/shared/src/token_issuer.rs +++ b/server/shared/src/token_issuer.rs @@ -4,7 +4,7 @@ use std::{ }; use base64::{engine::general_purpose as b64e, Engine}; -use hmac::{Hmac, Mac}; +use hmac::{Hmac, KeyInit, Mac}; use sha2::Sha256; pub struct TokenIssuer { @@ -20,6 +20,8 @@ pub enum TokenValidationFailure { InvalidSignature, // signature does not match } +type HmacSha256 = Hmac; + impl TokenValidationFailure { pub const fn error_message(&self) -> &'static str { match self { @@ -41,7 +43,7 @@ impl Display for TokenValidationFailure { impl TokenIssuer { pub fn new(secret_key: &str, expiration_period: Duration) -> Self { let skey_bytes = secret_key.as_bytes(); - let hmac = Hmac::::new_from_slice(skey_bytes).unwrap(); + let hmac = HmacSha256::new_from_slice(skey_bytes).unwrap(); Self { hmac, expiration_period } } @@ -49,7 +51,7 @@ impl TokenIssuer { /// Change the secret key of this token issuer. pub fn set_secret_key(&mut self, secret_key: &str) { let skey_bytes = secret_key.as_bytes(); - let hmac = Hmac::::new_from_slice(skey_bytes).unwrap(); + let hmac = HmacSha256::new_from_slice(skey_bytes).unwrap(); self.hmac = hmac; }