Skip to content

Commit

Permalink
DERIVE MACROS LETS GOOOO
Browse files Browse the repository at this point in the history
  • Loading branch information
dankmeme01 committed Dec 2, 2023
1 parent 9f66a28 commit 7885d4e
Show file tree
Hide file tree
Showing 44 changed files with 786 additions and 859 deletions.
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["central", "game", "shared"]
members = ["central", "game", "game-derives", "shared"]
resolver = "2"

[profile.release]
Expand Down
3 changes: 0 additions & 3 deletions server/central/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ async-rate-limit = "0.0.3"
async-watcher = "0.2.0"
base64 = "0.21.5"
blake2 = "0.10.6"
colored = "2.0.4"
digest = "0.10.7"
hmac = "0.12.1"
log = { version = "0.4.20" }
rand = "0.8.5"
reqwest = "0.11.22"
roa = { version = "0.6.1", features = ["router"] }
serde = { version = "1.0.192", features = ["serde_derive"] }
serde_json = "1.0.108"
sha2 = "0.10.8"
time = { version = "0.3.30", features = ["formatting"] }
tokio = { version = "1.34.0", features = ["full"] }
totp-rs = "5.4.0"
iprange = "0.6.7"
Expand Down
3 changes: 2 additions & 1 deletion server/central/src/allowed_ranges.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# that are not originated from one of these IP ranges.
# In debug or with the "cloudflare_protection" option disabled this file has no impact on anything, no IP addresses will be blocked.
#
# Use hashtags for comments and separate ranges by newlines. Start with 'v4' or 'v6' depending if it's IPv4 or IPv6
# Use hashtags for comments and separate ranges by newlines. Start with 'v4' or 'v6' depending if it's IPv4 or IPv6.
# NOTE: these are included in the executable at compile time. If you want to change anything here, you have to recompile the server.

# List of cloudflare IP ranges (from https://www.cloudflare.com/ips/):
# Updated 2023-11-17
Expand Down
12 changes: 11 additions & 1 deletion server/central/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ fn default_userlist() -> HashSet<i32> {
HashSet::new()
}

fn default_tps() -> u32 {
30
}

fn default_secret_key() -> String {
let rand_string: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
Expand Down Expand Up @@ -121,6 +125,10 @@ pub struct ServerConfig {
#[serde(default = "default_userlist")]
pub no_chat_list: HashSet<i32>,

// game stuff
#[serde(default = "default_tps")]
pub tps: u32,

// security
#[serde(default = "default_use_gd_api")]
pub use_gd_api: bool,
Expand Down Expand Up @@ -155,7 +163,8 @@ impl ServerConfig {
let writer = OpenOptions::new().write(true).create(true).open(dest)?;

// i hate 2 spaces i hate 2 spaces i hate 2 spaces
let mut serializer = Serializer::with_formatter(writer, PrettyFormatter::with_indent(b" "));
let formatter = PrettyFormatter::with_indent(b" ");
let mut serializer = Serializer::with_formatter(writer, formatter);
self.serialize(&mut serializer)?;

Ok(())
Expand All @@ -181,6 +190,7 @@ impl ServerConfig {
userlist_mode: default_userlist_mode(),
userlist: default_userlist(),
no_chat_list: default_userlist(),
tps: default_tps(),
secret_key: default_secret_key(),
game_server_password: default_secret_key(),
challenge_expiry: default_challenge_expiry(),
Expand Down
57 changes: 0 additions & 57 deletions server/central/src/logger.rs

This file was deleted.

24 changes: 14 additions & 10 deletions server/central/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,32 @@ use std::{error::Error, path::PathBuf, sync::Arc, time::Duration};

use async_watcher::{notify::RecursiveMode, AsyncDebouncer};
use config::ServerConfig;
use log::{error, info, warn, LevelFilter};
use logger::Logger;
use globed_shared::logger::{error, info, log, warn, LogLevelFilter, Logger};
use roa::{tcp::Listener, App};
use state::{ServerState, ServerStateData};
use tokio::sync::RwLock;

pub mod config;
pub mod ip_blocker;
pub mod logger;
pub mod state;
pub mod web;

fn abort_misconfig() -> ! {
error!("aborting launch due to misconfiguration.");
std::process::exit(1);
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
log::set_logger(Logger::instance()).unwrap();
log::set_logger(Logger::instance("globed_central_server")).unwrap();

if std::env::var("GLOBED_LESS_LOG").unwrap_or("0".to_string()) == "1" {
log::set_max_level(LevelFilter::Warn);
log::set_max_level(LogLevelFilter::Warn);
} else {
log::set_max_level(if cfg!(debug_assertions) {
LevelFilter::Trace
LogLevelFilter::Trace
} else {
LevelFilter::Info
LogLevelFilter::Info
});
}

Expand All @@ -48,9 +51,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
match ServerConfig::load(&config_path) {
Ok(x) => x,
Err(err) => {
error!("Failed to open configuration file: {}", err.to_string());
error!("Please fix the mistakes in the file or delete it for a new template to be created.");
panic!("aborting due to broken config");
error!("failed to open/parse configuration file: {err}");
warn!("hint: if you don't have anything important there, delete the file for a new template to be created.");
warn!("hint: the faulty configuration resides at: {config_path:?}");
abort_misconfig();
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion server/central/src/web/routes/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
use anyhow::anyhow;
use async_rate_limit::limiters::VariableCostRateLimiter;
use base64::{engine::general_purpose as b64e, Engine as _};
use log::{debug, info, warn};
use globed_shared::logger::{debug, info, log, warn};
use rand::{distributions::Alphanumeric, Rng};
use roa::{http::StatusCode, preload::PowerBody, query::Query, throw, Context};

Expand Down
4 changes: 2 additions & 2 deletions server/central/src/web/routes/game_server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use globed_shared::{GameServerBootData, PROTOCOL_VERSION};
use log::debug;
use globed_shared::{logger::debug, GameServerBootData, PROTOCOL_VERSION};
use reqwest::StatusCode;
use roa::{preload::PowerBody, query::Query, throw, Context};

Expand Down Expand Up @@ -52,6 +51,7 @@ pub async fn boot(context: &mut Context<ServerState>) -> roa::Result {
protocol: PROTOCOL_VERSION,
no_chat: config.no_chat_list.clone(),
special_users: config.special_users.clone(),
tps: config.tps,
};

debug!(
Expand Down
15 changes: 15 additions & 0 deletions server/game-derives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "globed-derives"
version = "1.0.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
proc-macro = true

[dependencies]
darling = "0.20.3"
proc-macro2 = "1.0.70"
quote = "1.0.33"
syn = { version = "2.0.39", features = ["full"] }
Loading

0 comments on commit 7885d4e

Please sign in to comment.