Struct Conf

Source
pub struct Conf {
    pub host: String,
    pub port: u16,
    pub socket_conf: SocketConf,
}
Expand description

Main struct used for configuring the connection.

By default, the port number for Java Edition is 25565, and for Bedrock Edition (including Pocket Edition), it is 19132.

Fields§

§host: String

Server IP address or a domain name.

§port: u16

Server port.

§socket_conf: SocketConf

Implementations§

Source§

impl Conf

Source

pub fn create(host: &str) -> Self

Create a connection configuration using the default port.

Default port is based on Java Edition(25565), to create a default port based on Bedrock Edition(19132), use Conf::create_with_port to manually specify it.

§Examples
let conf = Conf::create("www.example.com");
Examples found in repository?
examples/test.rs (line 4)
3fn main() -> Result<(), MspErr> {
4    let conf = Conf::create("www.example.com");
5
6    assert_eq!(conf.host, "www.example.com");
7    assert_eq!(conf.port, 25565);
8    assert_eq!(conf.socket_conf, SocketConf::default());
9
10    let conf = Conf::create_with_port("www.example.com", 19132);
11    assert_eq!(conf.port, 19132);
12
13    let conf = Conf::create_from_str("192.168.1.10:25565")?;
14
15    assert_eq!(conf.host, "192.168.1.10");
16    assert_eq!(conf.port, 25565);
17
18    let conf = Conf::create_from_str("www.example.com:25565")?;
19
20    assert_eq!(conf.host, "www.example.com");
21    assert_eq!(conf.port, 25565);
22    Ok(())
23}
Source

pub fn create_with_port(host: &str, port: u16) -> Self

Create a connection configuration using the specified port.

§Example
let conf = Conf::create_with_port("www.example.com", 19132);
Examples found in repository?
examples/query.rs (line 4)
3fn main() -> Result<(), MspErr> {
4    let server = Conf::create_with_port("www.example.com", 25565);
5
6    println!("{}", server.query_full()?);
7
8    Ok(())
9}
More examples
Hide additional examples
examples/bedrock_server.rs (line 4)
3fn main() -> Result<(), MspErr> {
4    let server = Conf::create_with_port("www.example.com", 19132);
5    let info = server.get_bedrock_server_status()?;
6
7    println!("{}", info);
8
9    Ok(())
10}
examples/server.rs (line 4)
3fn main() -> Result<(), MspErr> {
4    let server = Conf::create_with_port("www.example.com", 25565);
5    let info: Server = server.get_server_status()?;
6
7    println!("{}", info);
8
9    Ok(())
10}
examples/legacy_server.rs (line 5)
3fn main() -> Result<(), MspErr> {
4    // let server = Msp::create_with_port("play.elysion.network", 25565)?;
5    let server = Conf::create_with_port("bteam.mineyourmind.net", 25565);
6
7    println!("{}", server.get_netty_server_status()?);
8
9    Ok(())
10}
examples/test.rs (line 10)
3fn main() -> Result<(), MspErr> {
4    let conf = Conf::create("www.example.com");
5
6    assert_eq!(conf.host, "www.example.com");
7    assert_eq!(conf.port, 25565);
8    assert_eq!(conf.socket_conf, SocketConf::default());
9
10    let conf = Conf::create_with_port("www.example.com", 19132);
11    assert_eq!(conf.port, 19132);
12
13    let conf = Conf::create_from_str("192.168.1.10:25565")?;
14
15    assert_eq!(conf.host, "192.168.1.10");
16    assert_eq!(conf.port, 25565);
17
18    let conf = Conf::create_from_str("www.example.com:25565")?;
19
20    assert_eq!(conf.host, "www.example.com");
21    assert_eq!(conf.port, 25565);
22    Ok(())
23}
Source

pub fn create_from_str(addr: &str) -> Result<Self, MspErr>

Create a connection configuration by using a string.

Attempting to split the given string into two parts, with the first part being the host of the server and the second part being the port of the server. If the port cannot be converted to u16, it will throw a MspErr error.

§Example
    let conf = Conf::create_from_str("www.example.com:25565")?;
Examples found in repository?
examples/test.rs (line 13)
3fn main() -> Result<(), MspErr> {
4    let conf = Conf::create("www.example.com");
5
6    assert_eq!(conf.host, "www.example.com");
7    assert_eq!(conf.port, 25565);
8    assert_eq!(conf.socket_conf, SocketConf::default());
9
10    let conf = Conf::create_with_port("www.example.com", 19132);
11    assert_eq!(conf.port, 19132);
12
13    let conf = Conf::create_from_str("192.168.1.10:25565")?;
14
15    assert_eq!(conf.host, "192.168.1.10");
16    assert_eq!(conf.port, 25565);
17
18    let conf = Conf::create_from_str("www.example.com:25565")?;
19
20    assert_eq!(conf.host, "www.example.com");
21    assert_eq!(conf.port, 25565);
22    Ok(())
23}
Source

pub fn get_server_status(&self) -> Result<Server, MspErr>

Get info from a modern Java Edition server.

Using the Server List Ping protocol. Suitable for Java Edition servers version 1.7 and above. Return type is Server.

§Example
use msp::{Conf, MspErr};

fn main() -> Result<(), MspErr> {
    let server = Conf::create("www.example.com");
    let info = server.get_bedrock_server_status()?;

    Ok(())
}
Examples found in repository?
examples/server.rs (line 5)
3fn main() -> Result<(), MspErr> {
4    let server = Conf::create_with_port("www.example.com", 25565);
5    let info: Server = server.get_server_status()?;
6
7    println!("{}", info);
8
9    Ok(())
10}
Source

pub fn get_netty_server_status(&self) -> Result<NettyServer, MspErr>

Get info from a legacy Java Edition server.

This uses a protocol which is compatible with the client-server protocol as it was before the Netty rewrite. Suitable for Java Edition servers version 1.6 and above. Return type is NettyServer.

§Example
use msp::{Conf, MspErr};

fn main() -> Result<(), MspErr> {
    let server = Conf::create("www.example.com");
    let info = server.get_netty_server_status()?;

    Ok(())
}
Examples found in repository?
examples/legacy_server.rs (line 7)
3fn main() -> Result<(), MspErr> {
4    // let server = Msp::create_with_port("play.elysion.network", 25565)?;
5    let server = Conf::create_with_port("bteam.mineyourmind.net", 25565);
6
7    println!("{}", server.get_netty_server_status()?);
8
9    Ok(())
10}
Source

pub fn get_legacy_server_status(&self) -> Result<LegacyServer, MspErr>

Get info from a legacy Java Edition server.

Suitable for Java Edition servers version 1.4 to 1.5. Return type is LegacyServer.

§Example
use msp::{Conf, MspErr};

fn main() -> Result<(), MspErr> {
    let server = Conf::create("www.example.com");
    let info = server.get_legacy_server_status()?;

    Ok(())
}
Source

pub fn get_beta_legacy_server_status(&self) -> Result<LegacyBetaServer, MspErr>

Get info from a beta legacy Java Edition server in beta release.

Suitable for Java Edition servers version beta 1.8 to 1.3. Return type is LegacyBetaServer.

§Example
use msp::{Conf, MspErr};

fn main() -> Result<(), MspErr> {
    let server = Conf::create("www.example.com");
    let info = server.get_beta_legacy_server_status()?;

    Ok(())
}
Source

pub fn query(&self) -> Result<QueryBasic, MspErr>

Get basic info from a modern Java Edition server using the Query protocol.

To use this protocol, you need to enable the enable-query option on the server side. See Server Config. Return type is QueryBasic.

§Example
use msp::{Conf, MspErr};

fn main() -> Result<(), MspErr> {
    let server = Conf::create_with_port("www.example.com", 25565);
    let info = server.query()?;

    Ok(())
}
Source

pub fn query_full(&self) -> Result<QueryFull, MspErr>

Get full info from a modern Java Edition server using the Query protocol.

To use this protocol, you need to enable the enable-query option on the server side. See Server Config. Return type is QueryFull.

§Example
use msp::{Conf, MspErr};

fn main() -> Result<(), MspErr> {
    let server = Conf::create_with_port("www.example.com", 25565);
    let info = server.query_full()?;

    Ok(())
}
Examples found in repository?
examples/query.rs (line 6)
3fn main() -> Result<(), MspErr> {
4    let server = Conf::create_with_port("www.example.com", 25565);
5
6    println!("{}", server.query_full()?);
7
8    Ok(())
9}
Source

pub fn get_bedrock_server_status(&self) -> Result<BedrockServer, MspErr>

Get info from a modern Bedrock Edition servers using the RakNet protocol

Suitable for Bedrock Edition servers version 1.16.220(protocol 431) and above.

§Example
use msp::{Conf, MspErr};

fn main() -> Result<(), MspErr> {
    let server = Conf::create_with_port("www.example.com", 19132);
    let info = server.get_bedrock_server_status()?;

    Ok(())
}
Examples found in repository?
examples/bedrock_server.rs (line 5)
3fn main() -> Result<(), MspErr> {
4    let server = Conf::create_with_port("www.example.com", 19132);
5    let info = server.get_bedrock_server_status()?;
6
7    println!("{}", info);
8
9    Ok(())
10}

Trait Implementations§

Source§

impl Clone for Conf

Source§

fn clone(&self) -> Conf

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Conf

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ToSocketAddrs for Conf

Source§

type Iter = IntoIter<SocketAddr>

Returned iterator over socket addresses which this type may correspond to.
Source§

fn to_socket_addrs(&self) -> Result<Self::Iter>

Converts this object to an iterator of resolved SocketAddrs. Read more

Auto Trait Implementations§

§

impl Freeze for Conf

§

impl RefUnwindSafe for Conf

§

impl Send for Conf

§

impl Sync for Conf

§

impl Unpin for Conf

§

impl UnwindSafe for Conf

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.