Lightweight Minecraft protocol implementation in pure rust
Go to file
2024-05-12 18:07:27 +03:00
src hate varint-rs, DataBufferReader/Writer and 0.1.4 ver 2024-05-12 18:07:27 +03:00
.gitignore you dont need to see this 2024-05-12 00:12:24 +03:00
Cargo.toml hate varint-rs, DataBufferReader/Writer and 0.1.4 ver 2024-05-12 18:07:27 +03:00
LICENSE init commit?? 2024-05-12 00:11:25 +03:00
README.md hate varint-rs, DataBufferReader/Writer and 0.1.4 ver 2024-05-12 18:07:27 +03:00
test.py hate varint-rs, DataBufferReader/Writer and 0.1.4 ver 2024-05-12 18:07:27 +03:00

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
on crates on github

how to use it

for reference:

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

example how to get motd

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

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.to_string())?;
    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("localhost:25566").unwrap();

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

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

    println!("Motd: {}", motd);
}

also you can get minecraft connection from any stream: MinecraftConnection::from_stream

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