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"
|
repository = "https://github.com/MeexReay/rust_mc_proto"
|
||||||
license-file = "LICENSE"
|
license-file = "LICENSE"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
keywords = ["minecraft", "protocol", "packets", "lightweight"]
|
||||||
|
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# rust_mc_proto
|
# rust_mc_proto
|
||||||
minecraft packets protocol in pure rust \
|
lightweight minecraft packets protocol support in pure rust \
|
||||||
supports compression (`MinecraftConnection::set_compression`) \
|
has compression (`MinecraftConnection::set_compression`) \
|
||||||
all types of packets you can find on [wiki.vg](https://wiki.vg/) \
|
all types of packets you can find on [wiki.vg](https://wiki.vg/) \
|
||||||
[on crates](https://crates.io/crates/rust_mc_proto)
|
[on crates](https://crates.io/crates/rust_mc_proto)
|
||||||
[on github](https://github.com/MeexReay/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();
|
let mut pack = ByteBuffer::new();
|
||||||
|
|
||||||
if packet.buffer.len() < self.compress_threashold {
|
if packet.buffer.len() < self.compress_threashold {
|
||||||
pack.write_usize_varint(0).unwrap();
|
match pack.write_usize_varint(0) {
|
||||||
pack.write_u8_varint(packet.id).unwrap();
|
Ok(_) => {},
|
||||||
pack.write_all(packet.buffer.as_bytes()).unwrap();
|
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 {
|
} else {
|
||||||
let mut data = ByteBuffer::new();
|
let mut data = ByteBuffer::new();
|
||||||
|
|
||||||
data.write_u8_varint(packet.id).unwrap();
|
match data.write_u8_varint(packet.id) {
|
||||||
data.write_all(packet.buffer.as_bytes()).unwrap();
|
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())?;
|
let data = compress_zlib(data.as_bytes())?;
|
||||||
|
|
||||||
pack.write_usize_varint(packet.buffer.len() + 1).unwrap();
|
match pack.write_usize_varint(packet.buffer.len() + 1) {
|
||||||
pack.write_all(&data).unwrap();
|
Ok(_) => {},
|
||||||
|
Err(_) => { return Err(ProtocolError::WriteError) },
|
||||||
|
};
|
||||||
|
match pack.write_all(&data) {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(_) => { return Err(ProtocolError::WriteError) },
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.write_usize_varint(pack.len()).unwrap();
|
match buf.write_usize_varint(pack.len()) {
|
||||||
buf.write_all(pack.as_bytes()).unwrap();
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user