diff --git a/Cargo.lock b/Cargo.lock index 503c852..a59562b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -422,6 +422,15 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" +[[package]] +name = "enable-ansi-support" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea7457668b3da8a4b702f3d79e131aa3e81cd7e81cc95fb2d54fce9f182ecc77" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "encoding_rs" version = "0.8.35" @@ -1872,6 +1881,7 @@ dependencies = [ "colored", "cpal", "display-info", + "enable-ansi-support", "mac_address", "num_cpus", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index 4ecb206..1f06b27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ clap = { version = "4.6.0", features = ["cargo", "derive"] } colored = "3.1.1" cpal = { version = "0.17.3", optional = true } display-info = { version = "0.5.9", optional = true } +enable-ansi-support = "0.3.1" mac_address = "1.1.8" num_cpus = "1.17.0" reqwest = { version = "0.13.2", features = ["blocking", "json"] } diff --git a/server/src/main.rs b/server/src/main.rs index 33ea467..f8b5c8a 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -46,6 +46,8 @@ pub struct FullReport { pub timestamp: String, pub slimes: Option>>, pub benchmark: Option, + pub client_version: String, + pub signature: String, } #[derive(Deserialize)] @@ -70,14 +72,19 @@ async fn submit( let raw_json = serde_json::to_string(&payload) .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; - sqlx::query("INSERT INTO reports (mac_address, score, timestamp, data) VALUES (?, ?, ?, ?)") - .bind(payload.mac_address) - .bind(score as i64) - .bind(payload.timestamp) - .bind(raw_json) - .execute(&state.db) - .await - .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; + sqlx::query( + "INSERT INTO reports (mac_address, score, timestamp, client_version, signature, data) + VALUES (?, ?, ?, ?, ?, ?)", + ) + .bind(&payload.mac_address) + .bind(score as i64) + .bind(&payload.timestamp) + .bind(&payload.client_version) + .bind(&payload.signature) + .bind(raw_json) + .execute(&state.db) + .await + .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; Ok(StatusCode::CREATED) } @@ -142,6 +149,8 @@ async fn main() -> anyhow::Result<()> { mac_address TEXT NOT NULL, score INTEGER NOT NULL, timestamp TEXT NOT NULL, + client_version TEXT NOT NULL, + signature TEXT, data TEXT NOT NULL );", ) diff --git a/src/main.rs b/src/main.rs index 3a72775..33025ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,6 +58,7 @@ struct FullReport { slimes: Option>>, benchmark: Option, client_version: String, + signature: String, } #[derive(Serialize)] @@ -69,6 +70,9 @@ struct BenchmarkReport { } fn main() { + #[cfg(windows)] + let _ = enable_ansi_support::enable_ansi_support(); + let cli = Cli::parse(); let mut report = FullReport { mac_address: get_mac_address() @@ -80,6 +84,7 @@ fn main() { slimes: None, benchmark: None, client_version: crate_version!().to_string(), + signature: String::new(), }; vprintln!( @@ -152,18 +157,33 @@ fn main() { } if !cli.offline { - let json_payload = serde_json::to_string_pretty(&report).unwrap(); - vprintln!(cli.verbose, "Generated JSON report: {:?}", &json_payload); - println!(); if !confirm_upload() { return; } + report.signature = sign_upload(); + + let json_payload = serde_json::to_string_pretty(&report).unwrap(); + vprintln!(cli.verbose, "Generated JSON report: {:?}", &json_payload); + send_to_server(&cli.server_url, &report); } } +fn sign_upload() -> String { + print!("Please sign your report, it should allow to identify it (or leave empty): "); + io::stdout().flush().unwrap(); + + let mut input = String::new(); + io::stdin() + .read_line(&mut input) + .expect("Failed to read line"); + let input = input.trim().to_string(); + + input +} + fn confirm_upload() -> bool { print!("Send data to leaderboard server? [Y/n] "); io::stdout().flush().unwrap();