-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstatus.rs
More file actions
48 lines (37 loc) · 1.05 KB
/
Copy pathstatus.rs
File metadata and controls
48 lines (37 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use anyhow::Result;
use structopt::StructOpt;
use async_minecraft_ping::ConnectionConfig;
#[derive(Debug, StructOpt)]
#[structopt(name = "example")]
struct Args {
/// Server to connect to
#[structopt()]
address: String,
/// Port to connect to
#[structopt(short = "p", long = "port")]
port: Option<u16>,
/// Enable SRV record lookup (requires 'srv' feature)
#[cfg(feature = "srv")]
#[structopt(long = "srv")]
srv_lookup: bool,
}
#[tokio::main]
async fn main() -> Result<()> {
let args = Args::from_args();
let mut config = ConnectionConfig::build(args.address);
if let Some(port) = args.port {
config = config.with_port(port);
}
#[cfg(feature = "srv")]
if args.srv_lookup {
config = config.with_srv_lookup();
}
let connection = config.connect().await?;
let connection = connection.status().await?;
println!(
"{} of {} player(s) online",
connection.status.players.online, connection.status.players.max
);
connection.ping(42).await?;
Ok(())
}