stevenarella icon indicating copy to clipboard operation
stevenarella copied to clipboard

Release steven_protocol crate on cargo

Open iceiix opened this issue 5 years ago • 3 comments

#167 moved the protocol into a new steven_protocol crate, but it would be nice to also properly release it on cargo, ready for other users. Should include documentation and probably a minimal (text-based) client example if possible.

iceiix avatar Feb 02 '20 16:02 iceiix

Even only an example client would be enough, I was looking for something like this

EDIT: nevermind, figured it out

Kezii avatar Feb 15 '20 17:02 Kezii

src/server/mod.rs Server connect() is a good place to start for an example reference, but the connection handshake logic is in this module instead of steven_protocol. A new client would have to duplicate this logic (likely simplified..). Maybe I should move most of Server connect into steven_protocol instead (use only protocol::Conn), #494 has shown it is awkward how this functionality is spread across multiple modules... and it could facilitate writing a simple demo client (chat? #63 but simpler than #479 if only a CLI demo) to release with the crate.

iceiix avatar Jan 24 '21 05:01 iceiix

Hello, here's a minimal chat client for an offline server

use steven_protocol::protocol::{packet, Error, Conn, VarInt, State};

fn main() -> Result<(), Error> {
    let protocol_version = 754; //1.16.5
    let hostname = "localhost";
    let username = String::from("steven");

    let mut conn = Conn::new(hostname, protocol_version)?;

    conn.write_packet(packet::handshake::serverbound::Handshake {
            protocol_version: VarInt(conn.protocol_version),
            host: conn.host.clone(),
            port: conn.port,
            next: VarInt(2),
        })?;

    conn.state = State::Login;
    conn.write_packet(packet::login::serverbound::LoginStart { username })?;

    loop {
        match conn.read_packet()? {
            packet::Packet::SetInitialCompression(val) => {
                conn.set_compresssion(val.threshold.0);
            }
            packet::Packet::LoginSuccess_UUID(val) => {  // skipping encryption, offline mode
                println!("Server is running in offline mode\nLogin: {} {:?}", val.username, val.uuid);
                conn.state = State::Play;
            }
            packet::Packet::ServerMessage_Sender(val) => {
                println!("CHAT: {}", val.message);
            }
            packet::Packet::KeepAliveClientbound_i64(val) => {
                conn.write_packet(packet::play::serverbound::KeepAliveServerbound_i64 { id: val.id })?;
            }
            _ => { }
        };
    }
}

Kezii avatar Feb 20 '21 11:02 Kezii