Struct msp::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)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() -> Result<(), MspErr> {
    let conf = Conf::create("www.example.com");

    assert_eq!(conf.host, "www.example.com");
    assert_eq!(conf.port, 25565);
    assert_eq!(conf.socket_conf, SocketConf::default());

    let conf = Conf::create_with_port("www.example.com", 19132);
    assert_eq!(conf.port, 19132);

    let conf = Conf::create_from_str("192.168.1.10:25565")?;

    assert_eq!(conf.host, "192.168.1.10");
    assert_eq!(conf.port, 25565);

    let conf = Conf::create_from_str("www.example.com:25565")?;

    assert_eq!(conf.host, "www.example.com");
    assert_eq!(conf.port, 25565);
    Ok(())
}
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)
3
4
5
6
7
8
9
fn main() -> Result<(), MspErr> {
    let server = Conf::create_with_port("www.example.com", 25565);

    println!("{}", server.query_full()?);

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

    println!("{}", info);

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

    println!("{}", info);

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

    println!("{}", server.get_netty_server_status()?);

    Ok(())
}
examples/test.rs (line 10)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() -> Result<(), MspErr> {
    let conf = Conf::create("www.example.com");

    assert_eq!(conf.host, "www.example.com");
    assert_eq!(conf.port, 25565);
    assert_eq!(conf.socket_conf, SocketConf::default());

    let conf = Conf::create_with_port("www.example.com", 19132);
    assert_eq!(conf.port, 19132);

    let conf = Conf::create_from_str("192.168.1.10:25565")?;

    assert_eq!(conf.host, "192.168.1.10");
    assert_eq!(conf.port, 25565);

    let conf = Conf::create_from_str("www.example.com:25565")?;

    assert_eq!(conf.host, "www.example.com");
    assert_eq!(conf.port, 25565);
    Ok(())
}
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)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() -> Result<(), MspErr> {
    let conf = Conf::create("www.example.com");

    assert_eq!(conf.host, "www.example.com");
    assert_eq!(conf.port, 25565);
    assert_eq!(conf.socket_conf, SocketConf::default());

    let conf = Conf::create_with_port("www.example.com", 19132);
    assert_eq!(conf.port, 19132);

    let conf = Conf::create_from_str("192.168.1.10:25565")?;

    assert_eq!(conf.host, "192.168.1.10");
    assert_eq!(conf.port, 25565);

    let conf = Conf::create_from_str("www.example.com:25565")?;

    assert_eq!(conf.host, "www.example.com");
    assert_eq!(conf.port, 25565);
    Ok(())
}
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)
3
4
5
6
7
8
9
10
fn main() -> Result<(), MspErr> {
    let server = Conf::create_with_port("www.example.com", 25565);
    let info: Server = server.get_server_status()?;

    println!("{}", info);

    Ok(())
}
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)
3
4
5
6
7
8
9
10
fn main() -> Result<(), MspErr> {
    // let server = Msp::create_with_port("play.elysion.network", 25565)?;
    let server = Conf::create_with_port("bteam.mineyourmind.net", 25565);

    println!("{}", server.get_netty_server_status()?);

    Ok(())
}
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)
3
4
5
6
7
8
9
fn main() -> Result<(), MspErr> {
    let server = Conf::create_with_port("www.example.com", 25565);

    println!("{}", server.query_full()?);

    Ok(())
}
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)
3
4
5
6
7
8
9
10
fn main() -> Result<(), MspErr> {
    let server = Conf::create_with_port("www.example.com", 19132);
    let info = server.get_bedrock_server_status()?;

    println!("{}", info);

    Ok(())
}

Trait Implementations§

source§

impl Clone for Conf

source§

fn clone(&self) -> Conf

Returns a copy of the value. Read more
1.0.0 · source§

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

§

type Iter = IntoIter<SocketAddr, Global>

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 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.