diff --git a/Dockerfile b/Dockerfile index 886b5200b..57db48cf1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ FROM rust:1-alpine3.20 AS builder +ARG GIT_VERSION=Docker +ENV GIT_VERSION=$GIT_VERSION ENV RUSTFLAGS="-C target-feature=-crt-static -C target-cpu=native" RUN apk add --no-cache musl-dev diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index d5b2b00e4..607b52934 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -68,9 +68,12 @@ png = "0.17.14" # logging simple_logger = { version = "5.0.0", features = ["threads"] } +time = "0.3.36" +sys-info = "0.9.1" # commands async-trait = "0.1.83" [build-dependencies] winresource = "0.1.17" +git-version = "0.3.9" diff --git a/pumpkin/build.rs b/pumpkin/build.rs index eabfb2b98..57d4532d2 100644 --- a/pumpkin/build.rs +++ b/pumpkin/build.rs @@ -1,8 +1,18 @@ -fn main() { - if cfg!(target_os = "windows") { - let mut res = winresource::WindowsResource::new(); - res.set_icon("../assets/icon.ico"); - res.set_language(0x0009); // English - res.compile().unwrap(); - } -} +use git_version::git_version; +use std::env; + +fn main() { + if cfg!(target_os = "windows") { + let mut res = winresource::WindowsResource::new(); + res.set_icon("../assets/icon.ico"); + res.set_language(0x0009); // English + res.compile().unwrap(); + } + + let version = git_version!(fallback = "unknown"); + let git_version = match version { + "unknown" => env::var("GIT_VERSION").unwrap_or("unknown".to_string()), + _ => version.to_string(), + }; + println!("cargo:rustc-env=GIT_VERSION={}", git_version); +} diff --git a/pumpkin/src/command/commands/cmd_pumpkin.rs b/pumpkin/src/command/commands/cmd_pumpkin.rs index 0ee43b679..32c9d124e 100644 --- a/pumpkin/src/command/commands/cmd_pumpkin.rs +++ b/pumpkin/src/command/commands/cmd_pumpkin.rs @@ -7,6 +7,7 @@ use crate::{ args::ConsumedArgs, tree::CommandTree, CommandError, CommandExecutor, CommandSender, }, server::CURRENT_MC_VERSION, + GIT_VERSION, }; const NAMES: [&str; 2] = ["pumpkin", "version"]; @@ -15,6 +16,9 @@ const DESCRIPTION: &str = "Display information about Pumpkin."; struct PumpkinExecutor; +const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); +const CARGO_PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION"); + #[async_trait] impl CommandExecutor for PumpkinExecutor { async fn execute<'a>( @@ -23,13 +27,12 @@ impl CommandExecutor for PumpkinExecutor { _server: &crate::server::Server, _args: &ConsumedArgs<'a>, ) -> Result<(), CommandError> { - let version = env!("CARGO_PKG_VERSION"); - let description = env!("CARGO_PKG_DESCRIPTION"); - - sender.send_message(TextComponent::text( - &format!("Pumpkin {version}, {description} (Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL})") - ).color_named(NamedColor::Green)).await; - + sender + .send_message( + TextComponent::text(&format!("Pumpkin {CARGO_PKG_VERSION} ({GIT_VERSION}), {CARGO_PKG_DESCRIPTION} (Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL})", )) + .color_named(NamedColor::Green), + ) + .await; Ok(()) } } diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 4409ba878..c4d61771d 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -30,11 +30,12 @@ use tokio::signal::unix::{signal, SignalKind}; use std::sync::Arc; +use crate::server::CURRENT_MC_VERSION; use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG}; use pumpkin_core::text::{color::NamedColor, TextComponent}; +use pumpkin_protocol::CURRENT_MC_PROTOCOL; use rcon::RCONServer; use std::time::Instant; - // Setup some tokens to allow us to identify which event is for which socket. pub mod client; @@ -62,6 +63,9 @@ fn init_logger() { use pumpkin_config::ADVANCED_CONFIG; if ADVANCED_CONFIG.logging.enabled { let mut logger = simple_logger::SimpleLogger::new(); + logger = logger.with_timestamp_format(time::macros::format_description!( + "[year]-[month]-[day] [hour]:[minute]:[second]" + )); if !ADVANCED_CONFIG.logging.timestamp { logger = logger.without_timestamps(); @@ -90,9 +94,40 @@ const fn convert_logger_filter(level: pumpkin_config::logging::LevelFilter) -> L } } +const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); + +fn log_system_info() { + let os_type = sys_info::os_type().unwrap(); + let os_release = sys_info::os_release().unwrap(); + let arch = std::env::consts::ARCH; + + if cfg!(target_os = "linux") { + if let Some(linux_release) = sys_info::linux_os_release().unwrap().pretty_name { + log::info!( + "Running on {} ({}) {} ({})", + os_type, + linux_release, + os_release, + arch + ); + return; + } + } + log::info!("Running on {} {} ({})", os_type, os_release, arch); +} + +const GIT_VERSION: &str = env!("GIT_VERSION"); + #[tokio::main] async fn main() -> io::Result<()> { init_logger(); + log_system_info(); + log::info!("Starting Pumpkin {CARGO_PKG_VERSION} ({GIT_VERSION}) for Minecraft {CURRENT_MC_VERSION} (Protocol {CURRENT_MC_PROTOCOL})",); + log::warn!("Pumpkin is currently under heavy development!"); + log::info!("Report Issues on https://github.com/Snowiiii/Pumpkin/issues"); + log::info!("Join our Discord for community support https://discord.com/invite/wT8XjrjKkf"); + //log::info!("CPU {} Cores {}MHz", sys_info::cpu_num().unwrap(), sys_info::cpu_speed().unwrap()); + // let rt = tokio::runtime::Builder::new_multi_thread() // .enable_all() // .build()