keywords and hating .unwrap()
This commit is contained in:
parent
337a833838
commit
382090c1c1
@ -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"
|
||||
|
@ -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)
|
||||
|
50
src/lib.rs
50
src/lib.rs
@ -221,26 +221,56 @@ impl<T: Read + Write> MinecraftConnection<T> {
|
||||
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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user