Skip to content

Commit

Permalink
Update server CI, dependencies and change to Rust 2024 edition (#256)
Browse files Browse the repository at this point in the history
* Reformat

* Update server CI

* Remove since not needed (gives error if exists)

* Remove unused import

* Remove

* WIP

* Done

* Update async-watcher requirement from 0.2.1 to 0.3.0 in /server

Updates the requirements on [async-watcher](https://github.com/justinrubek/async-watcher) to permit the latest version.
- [Release notes](https://github.com/justinrubek/async-watcher/releases)
- [Changelog](https://github.com/justinrubek/async-watcher/blob/main/CHANGELOG.md)
- [Commits](justinrubek/async-watcher@0.2.1...0.3.0)

---
updated-dependencies:
- dependency-name: async-watcher
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update console-subscriber requirement in /server/game

Updates the requirements on [console-subscriber](https://github.com/tokio-rs/console) to permit the latest version.
- [Release notes](https://github.com/tokio-rs/console/releases)
- [Changelog](https://github.com/tokio-rs/console/blob/main/release-plz.toml)
- [Commits](tokio-rs/console@console-subscriber-v0.2.0...console-subscriber-v0.4.1)

---
updated-dependencies:
- dependency-name: console-subscriber
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update rustc-hash requirement from 1.1.0 to 2.0.0 in /server

Updates the requirements on [rustc-hash](https://github.com/rust-lang/rustc-hash) to permit the latest version.
- [Changelog](https://github.com/rust-lang/rustc-hash/blob/master/CHANGELOG.md)
- [Commits](rust-lang/rustc-hash@v1.2.0...v2.0.0)

---
updated-dependencies:
- dependency-name: rustc-hash
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update rocket_db_pools requirement from 0.1.0 to 0.2.0 in /server

Updates the requirements on [rocket_db_pools](https://github.com/rwf2/Rocket) to permit the latest version.
- [Release notes](https://github.com/rwf2/Rocket/releases)
- [Changelog](https://github.com/rwf2/Rocket/blob/master/CHANGELOG.md)
- [Commits](rwf2/Rocket@v0.1.0...v0.2.0)

---
updated-dependencies:
- dependency-name: rocket_db_pools
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update egui requirement from 0.27.2 to 0.29.1 in /server/observer

Updates the requirements on [egui](https://github.com/emilk/egui) to permit the latest version.
- [Release notes](https://github.com/emilk/egui/releases)
- [Changelog](https://github.com/emilk/egui/blob/master/CHANGELOG.md)
- [Commits](emilk/egui@0.27.2...0.29.1)

---
updated-dependencies:
- dependency-name: egui
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update base64 requirement from 0.21.7 to 0.22.1 in /server/shared

Updates the requirements on [base64](https://github.com/marshallpierce/rust-base64) to permit the latest version.
- [Changelog](https://github.com/marshallpierce/rust-base64/blob/master/RELEASE-NOTES.md)
- [Commits](marshallpierce/rust-base64@v0.21.7...v0.22.1)

---
updated-dependencies:
- dependency-name: base64
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update Cargo.toml

* Update CMakeLists

* oops

* fix?

* Update libs

* update

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* Update Cargo.toml

* try fxi

* fix

* Update fast_string.rs

* Update fast_string.rs

* should work now

* pls work

* PLEASE WORK.

* oopsiees

* should workkk nowwwww

* oops

* fixes

* naother fix

* Update lib.rs

* Update socket.rs

* Update unauthorized.rs

* fix

* Update socket.rs

* Update unauthorized.rs

* Update unauthorized.rs

* Update socket.rs

* Update Cargo.toml

* i suck

* warning fix

* fix warn

* fix warning

* Update unauthorized.rs

* Update room.rs

* Update channel.rs

* Update channel.rs

* Update lockfreemutcell.rs

* unsure abt this one

* fix

* fix

* [skip ci] comment fix

* fixup

* Update lockfreemutcell.rs

* Update thread.rs

* Update unauthorized.rs

* Update server.rs

* Update lockfreemutcell.rs

* Update lockfreemutcell.rs

* unsafe fixes

* Update channel.rs

* my bad

* Update game_pinger.rs

* rand fix

* done lol

* undo the unsafe changes and remove other thing

* fix minor issues and bump deps

* fix KeyInit compile errors

* fix clippy warnings

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dankmeme01 <[email protected]>
  • Loading branch information
3 people authored Dec 1, 2024
1 parent 58d14ec commit 5d25494
Show file tree
Hide file tree
Showing 33 changed files with 171 additions and 162 deletions.
26 changes: 26 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
package:
name: Package builds
runs-on: ubuntu-latest
needs: ['build']
needs: build

steps:
- name: Combine builds
Expand Down
27 changes: 12 additions & 15 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 15 additions & 14 deletions server/central/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 0 additions & 2 deletions server/central/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::env;

fn main() {
// trigger recompilation when a new migration is added
println!("cargo:rerun-if-changed=migrations");
Expand Down
2 changes: 1 addition & 1 deletion server/central/src/game_pinger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions server/central/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,7 +61,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// 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();
Expand Down
36 changes: 16 additions & 20 deletions server/central/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -63,7 +62,7 @@ impl ServerStateData {

let hmac = Hmac::<Sha256>::new_from_slice(skey_bytes).unwrap();
let mut challenge_pubkey = GenericArray::<u8, U32>::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);
Expand Down Expand Up @@ -97,10 +96,10 @@ impl ServerStateData {
ip_address: IpAddr,
current_time: SystemTime,
) -> anyhow::Result<String> {
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;
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions server/central/src/web/routes/auth.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -229,7 +229,7 @@ fn decrypt_trust_token(token: &str, key: &str) -> WebResult<Vec<u8>> {
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..];

Expand Down Expand Up @@ -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");
Expand Down
9 changes: 4 additions & 5 deletions server/central/src/web/routes/meta.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -76,7 +75,7 @@ pub fn versioncheck(gd: &str, globed: &str, protocol: u16) -> WebResult<Json<Ver

#[get("/")]
pub fn index() -> (Status, (ContentType, String)) {
if rand::thread_rng().gen_ratio(1, 0xaa) {
if rand::rng().random_ratio(1, 0xaa) {
return _check();
}

Expand Down
7 changes: 4 additions & 3 deletions server/central/src/web/routes/user.rs
Original file line number Diff line number Diff line change
@@ -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::*};
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 5 additions & 7 deletions server/derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
Loading

0 comments on commit 5d25494

Please sign in to comment.