diff --git a/Cargo.toml b/Cargo.toml index a22c82a..6d00550 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ description = "minecraft packets protocol in pure rust" repository = "https://github.com/MeexReay/rust_mc_proto" license-file = "LICENSE" readme = "README.md" +keywords = ["minecraft", "protocol", "packets", "lightweight"] version = "0.1.1" edition = "2021" diff --git a/README.md b/README.md index 9b5190b..db8d5da 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # rust_mc_proto -minecraft packets protocol in pure rust \ -supports compression (`MinecraftConnection::set_compression`) \ +lightweight minecraft packets protocol support in pure rust \ +has compression (`MinecraftConnection::set_compression`) \ all types of packets you can find on [wiki.vg](https://wiki.vg/) \ [on crates](https://crates.io/crates/rust_mc_proto) [on github](https://github.com/MeexReay/rust_mc_proto) diff --git a/src/lib.rs b/src/lib.rs index 7a8e609..cf2579e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -221,26 +221,56 @@ impl MinecraftConnection { let mut pack = ByteBuffer::new(); if packet.buffer.len() < self.compress_threashold { - pack.write_usize_varint(0).unwrap(); - pack.write_u8_varint(packet.id).unwrap(); - pack.write_all(packet.buffer.as_bytes()).unwrap(); + match pack.write_usize_varint(0) { + Ok(_) => {}, + Err(_) => { return Err(ProtocolError::WriteError) }, + }; + match pack.write_u8_varint(packet.id) { + Ok(_) => {}, + Err(_) => { return Err(ProtocolError::WriteError) }, + }; + match pack.write_all(packet.buffer.as_bytes()) { + Ok(_) => {}, + Err(_) => { return Err(ProtocolError::WriteError) }, + }; } else { let mut data = ByteBuffer::new(); - data.write_u8_varint(packet.id).unwrap(); - data.write_all(packet.buffer.as_bytes()).unwrap(); + match data.write_u8_varint(packet.id) { + Ok(_) => {}, + Err(_) => { return Err(ProtocolError::WriteError) }, + }; + match data.write_all(packet.buffer.as_bytes()) { + Ok(_) => {}, + Err(_) => { return Err(ProtocolError::WriteError) }, + }; let data = compress_zlib(data.as_bytes())?; - pack.write_usize_varint(packet.buffer.len() + 1).unwrap(); - pack.write_all(&data).unwrap(); + match pack.write_usize_varint(packet.buffer.len() + 1) { + Ok(_) => {}, + Err(_) => { return Err(ProtocolError::WriteError) }, + }; + match pack.write_all(&data) { + Ok(_) => {}, + Err(_) => { return Err(ProtocolError::WriteError) }, + }; } - buf.write_usize_varint(pack.len()).unwrap(); - buf.write_all(pack.as_bytes()).unwrap(); + match buf.write_usize_varint(pack.len()) { + Ok(_) => {}, + Err(_) => { return Err(ProtocolError::WriteError) }, + }; + match buf.write_all(pack.as_bytes()) { + Ok(_) => {}, + Err(_) => { return Err(ProtocolError::WriteError) }, + }; } - self.stream.write_all(buf.as_bytes()).unwrap(); + match self.stream.write_all(buf.as_bytes()) { + Ok(_) => {}, + Err(_) => { return Err(ProtocolError::WriteError) }, + }; Ok(()) }