Crates.io | msp |
lib.rs | msp |
version | 0.1.2 |
source | src |
created_at | 2023-05-17 15:14:51.712982 |
updated_at | 2023-05-20 15:14:42.780965 |
description | Fast and lightweight Minecraft Server protocol client implemented in Rust. |
homepage | https://github.com/zRains/msp |
repository | https://github.com/zRains/msp |
max_upload_size | |
id | 867042 |
size | 69,381 |
English | 中文
WIP: Currently, it is in the alpha stage. It is functional and can be used, but configuration and feature APIs may still undergo changes between minor version releases.
A Minecraft Server Protocol client implemented in Rust that offers fast response, lightweightness, stability, comprehensive type exporting, and error feedback. It enables retrieval of server status through various protocols and returns strongly-typed JSON data.
Supports Java Edition and Bedrock Edition servers. The applicable version range is as follows.
Server Information Query Protocol covering most versions, with certain protocols requiring the server to enable corresponding features.
cargo add msp
Or, add this dependency to your Cargo.toml
file:
[dependencies]
msp = "0.1.0"
Here are some basic examples showcased below.
Conf::get_server_status
to retrieve server information, return Server
. Note that older versions are not supported:use msp::{Conf, MspErr, Server};
fn main() -> Result<(), MspErr> {
let server = Conf::create_with_port("www.example.com", 25565);
let info: Server = server.get_server_status()?;
println!("{}", info);
Ok(())
}
Conf::create_with_port
to create a connection configuration specifying the port:use msp::{Conf, MspErr, Server};
fn main() -> Result<(), MspErr> {
let server = Conf::create_with_port("www.example.com", 25565);
let info: Server = server.get_server_status()?;
println!("{}", info);
Ok(())
}
get_lan_server_status
to retrieve LAN online hosts:use msp::{get_lan_server_status, MspErr, SocketConf};
fn main() -> Result<(), MspErr> {
get_lan_server_status(&SocketConf::default())?;
Ok(())
}
Conf::query_full
to retrieve server information using the Query protocol:use msp::{Conf, MspErr};
fn main() -> Result<(), MspErr> {
let server = Conf::create_with_port("www.example.com", 25565);
println!("{}", server.query_full()?);
Ok(())
}
:warning:To use this protocol, you need to enable the enable-query
option on the server side. This option can be found in the server.properties
file located in the root directory. Set it as follows:
enable-query=true
query.port=25565 # Configure the port according to your specific situation
Make sure to save the changes and restart the server for the configuration to take effect.
MIT.