1use rust_mc_status::{McClient, ServerEdition, ServerInfo};
2use std::time::Duration;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let client = McClient::new()
7 .with_timeout(Duration::from_secs(5))
8 .with_max_parallel(10);
9
10 let servers = vec![
12 ServerInfo {
13 address: "mc.hypixel.net:25565".to_string(),
14 edition: ServerEdition::Java,
15 },
16 ServerInfo {
17 address: "geo.hivebedrock.network:19132".to_string(),
18 edition: ServerEdition::Bedrock,
19 },
20 ];
21
22 let results = client.ping_many(&servers).await;
23
24 for (server, result) in results {
25 println!("\nChecking server: {}", server.address);
26 match result {
27 Ok(status) => {
28 println!("Status: Online ({} ms)", status.latency);
29 match status.data {
30 rust_mc_status::ServerData::Java(java) => {
31 println!("Name: {}", java.description);
32 println!("Version: {}", java.version.name);
33 println!("Players: {}/{}", java.players.online, java.players.max);
34
35 let filename = format!("{}_favicon.png", server.address.replace(':', "_"));
37 match java.save_favicon(&filename) {
38 Ok(_) => println!("Favicon saved as {}", filename),
39 Err(e) => println!("Favicon not available: {}", e),
40 }
41 }
42 rust_mc_status::ServerData::Bedrock(bedrock) => {
43 println!("Name: {}", bedrock.motd);
44 println!("Version: {}", bedrock.version);
45 println!("Players: {}/{}", bedrock.online_players, bedrock.max_players);
46 println!("Favicon: Not supported in Bedrock");
47 }
48 }
49 }
50 Err(e) => println!("Status: Offline or error ({})", e),
51 }
52 }
53
54 Ok(())
55}