Crate msp

Source
Expand description

A fast, lightweight, stable, and feature-rich Minecraft Server Protocol client implemented in Rust.

license version download

Offering efficient type exporting and error feedback. It enables retrieving server status using various protocols and returns strongly-typed JSON data.

§Applicable version

Supports Java Edition and Bedrock Edition servers. The applicable version range is as follows.

  • Java Edition: Suitable for server versions 1.4 and above (Protocol version number >= 47).
  • Bedrock Edition: Suitable for modern Bedrock servers (1.16.220 and above).

§Supported protocols

Server Information Query Protocol covering most versions, with certain protocols requiring the server to enable corresponding features.

§Usage

  1. To integrate it as a library into your own Rust project, run it in the root project directory.
cargo add msp

Or, add this dependency to your Cargo.toml file:

[dependencies]
msp = "0.1.0"

§Examples

Here are some basic examples showcased below.

  1. Use 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(())
}
  1. Use 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(())
}
  1. Use 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(())
}
  1. Use 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(())
}

Note: 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.

§License

MIT.

Structs§

BedrockServer
Bedrock server info type.
Conf
Main struct used for configuring the connection.
LanServer
LAN server info structure.
LegacyBetaServer
Legacy beta server info type.
LegacyServer
Legacy server info type.
QueryBasic
Basic stat in Query protocol.
QueryFull
Full stat in Query protocol.
Server
Regular Server info type.
SocketConf
Additional socket configuration.

Enums§

MspErr
Msp error uniform error definition.

Functions§

get_lan_server_status
Get the host information of other open servers in the current LAN.

Type Aliases§

NettyServer
The alias of LegacyServer is identical in content.