rust_mc_proto

Crates.iorust_mc_proto
lib.rsrust_mc_proto
version0.1.16
sourcesrc
created_at2024-05-11 21:17:47.703057
updated_at2024-08-22 10:09:41.389305
descriptionlightweight minecraft protocol support in pure rust
homepage
repositoryhttps://github.com/MeexReay/rust_mc_proto
max_upload_size
id1237060
size43,328
(MeexReay)

documentation

README

rust_mc_proto

lightweight minecraft packets protocol support in pure rust
has compression (MinecraftConnection::set_compression)
all types of packets you can find on wiki.vg
crates github

setup

stable

rust_mc_proto = "0.1.15"

unstable

rust_mc_proto = { git = "https://github.com/MeexReay/rust_mc_proto" }

features:

  • atomic_compression (default)

how to use it

for reference:

pub type MCConn<T> = MinecraftConnection<T>;
pub type MCConnTcp = MinecraftConnection<TcpStream>;

example of receiving motd:

use rust_mc_proto::{Packet, ProtocolError, MCConnTcp, DataBufferReader, DataBufferWriter};

/*

    Example of receiving motd from the server
    Sends handshake, status request and receiving one

*/

fn send_handshake(conn: &mut MCConnTcp,
                protocol_version: u16,
                server_address: &str,
                server_port: u16,
                next_state: u8) -> Result<(), ProtocolError> {
    let mut packet = Packet::empty(0x00);

    packet.write_u16_varint(protocol_version)?;
    packet.write_string(server_address)?;
    packet.write_unsigned_short(server_port)?;
    packet.write_u8_varint(next_state)?;

    conn.write_packet(&packet)?;

    Ok(())
}

fn send_status_request(conn: &mut MCConnTcp) -> Result<(), ProtocolError> {
    let packet = Packet::empty(0x00);
    conn.write_packet(&packet)?;

    Ok(())
}

fn read_status_response(conn: &mut MCConnTcp) -> Result<String, ProtocolError> {
    let mut packet = conn.read_packet()?;

    packet.read_string()
}

fn main() {
    let mut conn = MCConnTcp::connect("sloganmc.ru:25565").unwrap();

    send_handshake(&mut conn, 765, "sloganmc.ru", 25565, 1).unwrap();
    send_status_request(&mut conn).unwrap();

    let motd = read_status_response(&mut conn).unwrap();

    dbg!(motd);
}

more examples

this crate can be used for a server on rust idk -_-

Commit count: 34

cargo fmt