some changes blob
This commit is contained in:
parent
e2cc99dfb7
commit
d39ee60729
72
README.md
72
README.md
@ -1,75 +1,52 @@
|
||||
# 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](https://wiki.vg/) \
|
||||
[crates](https://crates.io/crates/rust_mc_proto)
|
||||
[github](https://github.com/MeexReay/rust_mc_proto)
|
||||
Lightweight minecraft packets protocol support in pure rust \
|
||||
Has compression (`MinecraftConnection::set_compression`) \
|
||||
This crate can be used for a server on rust idk -_-
|
||||
|
||||
## setup
|
||||
|
||||
stable
|
||||
## Setup
|
||||
|
||||
```toml
|
||||
rust_mc_proto = "0.1.16"
|
||||
rust_mc_proto = "0.1.16" # stable version
|
||||
rust_mc_proto = { git = "https://github.com/MeexReay/rust_mc_proto" } # unstable version
|
||||
```
|
||||
|
||||
unstable
|
||||
Features:
|
||||
- `atomic_compression` (default)
|
||||
|
||||
```toml
|
||||
rust_mc_proto = { git = "https://github.com/MeexReay/rust_mc_proto" }
|
||||
```
|
||||
## How to use
|
||||
|
||||
features:
|
||||
- atomic_compression (default)
|
||||
|
||||
## how to use it
|
||||
|
||||
for reference:
|
||||
For reference:
|
||||
```rust
|
||||
pub type MCConn<T> = MinecraftConnection<T>;
|
||||
pub type MCConnTcp = MinecraftConnection<TcpStream>;
|
||||
```
|
||||
|
||||
example of receiving motd:
|
||||
Example of receiving motd:
|
||||
|
||||
```rust
|
||||
use rust_mc_proto::{Packet, ProtocolError, MCConnTcp, DataBufferReader, DataBufferWriter};
|
||||
|
||||
/*
|
||||
|
||||
Example of receiving motd from the server
|
||||
Sends handshake, status request and receiving one
|
||||
|
||||
*/
|
||||
|
||||
fn send_handshake(conn: &mut MCConnTcp,
|
||||
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);
|
||||
|
||||
next_state: u8
|
||||
) -> Result<(), ProtocolError> {
|
||||
conn.write_packet(&Packet::build(0x00, |packet| {
|
||||
packet.write_u16_varint(protocol_version)?;
|
||||
packet.write_string(server_address)?;
|
||||
packet.write_unsigned_short(server_port)?;
|
||||
packet.write_u8_varint(next_state)?;
|
||||
|
||||
conn.write_packet(&packet)?;
|
||||
|
||||
Ok(())
|
||||
packet.write_u8_varint(next_state)
|
||||
})?)
|
||||
}
|
||||
|
||||
fn send_status_request(conn: &mut MCConnTcp) -> Result<(), ProtocolError> {
|
||||
let packet = Packet::empty(0x00);
|
||||
conn.write_packet(&packet)?;
|
||||
|
||||
Ok(())
|
||||
conn.write_packet(&Packet::empty(0x00))
|
||||
}
|
||||
|
||||
fn read_status_response(conn: &mut MCConnTcp) -> Result<String, ProtocolError> {
|
||||
let mut packet = conn.read_packet()?;
|
||||
|
||||
packet.read_string()
|
||||
conn.read_packet()?.read_string()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -84,6 +61,11 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
[more examples](https://github.com/MeexReay/rust_mc_proto/tree/main/examples)
|
||||
[More examples](https://github.com/MeexReay/rust_mc_proto/tree/main/examples)
|
||||
|
||||
this crate can be used for a server on rust idk -_-
|
||||
### Contributing
|
||||
|
||||
If you would like to contribute to the project, feel free to fork the repository and submit a pull request.
|
||||
|
||||
### License
|
||||
This project is licensed under the WTFPL License
|
@ -7,34 +7,27 @@ use rust_mc_proto::{Packet, ProtocolError, MCConnTcp, DataBufferReader, DataBuff
|
||||
|
||||
*/
|
||||
|
||||
fn send_handshake(conn: &mut MCConnTcp,
|
||||
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);
|
||||
|
||||
next_state: u8
|
||||
) -> Result<(), ProtocolError> {
|
||||
conn.write_packet(&Packet::build(0x00, |packet| {
|
||||
packet.write_u16_varint(protocol_version)?;
|
||||
packet.write_string(server_address)?;
|
||||
packet.write_unsigned_short(server_port)?;
|
||||
packet.write_u8_varint(next_state)?;
|
||||
|
||||
conn.write_packet(&packet)?;
|
||||
|
||||
Ok(())
|
||||
packet.write_u8_varint(next_state)
|
||||
})?)
|
||||
}
|
||||
|
||||
fn send_status_request(conn: &mut MCConnTcp) -> Result<(), ProtocolError> {
|
||||
let packet = Packet::empty(0x00);
|
||||
conn.write_packet(&packet)?;
|
||||
|
||||
Ok(())
|
||||
conn.write_packet(&Packet::empty(0x00))
|
||||
}
|
||||
|
||||
fn read_status_response(conn: &mut MCConnTcp) -> Result<String, ProtocolError> {
|
||||
let mut packet = conn.read_packet()?;
|
||||
|
||||
packet.read_string()
|
||||
conn.read_packet()?.read_string()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -87,66 +87,66 @@ pub trait DataBufferReader {
|
||||
size_varint!(usize, self)
|
||||
}
|
||||
/// Read VarInt as u8 with size in bytes (varint, size)
|
||||
fn read_u8_varint_size(&mut self) -> Result<(u8, u8), ProtocolError> {
|
||||
fn read_u8_varint_size(&mut self) -> Result<(u8, usize), ProtocolError> {
|
||||
size_varint!(u8, self)
|
||||
}
|
||||
/// Read VarInt as u16 with size in bytes (varint, size)
|
||||
fn read_u16_varint_size(&mut self) -> Result<(u16, u16), ProtocolError> {
|
||||
fn read_u16_varint_size(&mut self) -> Result<(u16, usize), ProtocolError> {
|
||||
size_varint!(u16, self)
|
||||
}
|
||||
/// Read VarInt as u32 with size in bytes (varint, size)
|
||||
fn read_u32_varint_size(&mut self) -> Result<(u32, u32), ProtocolError> {
|
||||
fn read_u32_varint_size(&mut self) -> Result<(u32, usize), ProtocolError> {
|
||||
size_varint!(u32, self)
|
||||
}
|
||||
/// Read VarInt as u64 with size in bytes (varint, size)
|
||||
fn read_u64_varint_size(&mut self) -> Result<(u64, u64), ProtocolError> {
|
||||
fn read_u64_varint_size(&mut self) -> Result<(u64, usize), ProtocolError> {
|
||||
size_varint!(u64, self)
|
||||
}
|
||||
/// Read VarInt as u128 with size in bytes (varint, size)
|
||||
fn read_u128_varint_size(&mut self) -> Result<(u128, u128), ProtocolError> {
|
||||
fn read_u128_varint_size(&mut self) -> Result<(u128, usize), ProtocolError> {
|
||||
size_varint!(u128, self)
|
||||
}
|
||||
|
||||
/// Read VarInt as isize with size in bytes (varint, size)
|
||||
fn read_isize_varint_size(&mut self) -> Result<(isize, isize), ProtocolError> {
|
||||
fn read_isize_varint_size(&mut self) -> Result<(isize, usize), ProtocolError> {
|
||||
Ok({
|
||||
let i = self.read_usize_varint_size()?;
|
||||
(i.0.zigzag(), i.1.zigzag())
|
||||
(i.0.zigzag(), i.1)
|
||||
})
|
||||
}
|
||||
/// Read VarInt as i8 with size in bytes (varint, size)
|
||||
fn read_i8_varint_size(&mut self) -> Result<(i8, i8), ProtocolError> {
|
||||
fn read_i8_varint_size(&mut self) -> Result<(i8, usize), ProtocolError> {
|
||||
Ok({
|
||||
let i = self.read_u8_varint_size()?;
|
||||
(i.0.zigzag(), i.1.zigzag())
|
||||
(i.0.zigzag(), i.1)
|
||||
})
|
||||
}
|
||||
/// Read VarInt as i16 with size in bytes (varint, size)
|
||||
fn read_i16_varint_size(&mut self) -> Result<(i16, i16), ProtocolError> {
|
||||
fn read_i16_varint_size(&mut self) -> Result<(i16, usize), ProtocolError> {
|
||||
Ok({
|
||||
let i = self.read_u16_varint_size()?;
|
||||
(i.0.zigzag(), i.1.zigzag())
|
||||
(i.0.zigzag(), i.1)
|
||||
})
|
||||
}
|
||||
/// Read VarInt as i32 with size in bytes (varint, size)
|
||||
fn read_i32_varint_size(&mut self) -> Result<(i32, i32), ProtocolError> {
|
||||
fn read_i32_varint_size(&mut self) -> Result<(i32, usize), ProtocolError> {
|
||||
Ok({
|
||||
let i = self.read_u32_varint_size()?;
|
||||
(i.0.zigzag(), i.1.zigzag())
|
||||
(i.0.zigzag(), i.1)
|
||||
})
|
||||
}
|
||||
/// Read VarInt as i64 with size in bytes (varint, size)
|
||||
fn read_i64_varint_size(&mut self) -> Result<(i64, i64), ProtocolError> {
|
||||
fn read_i64_varint_size(&mut self) -> Result<(i64, usize), ProtocolError> {
|
||||
Ok({
|
||||
let i = self.read_u64_varint_size()?;
|
||||
(i.0.zigzag(), i.1.zigzag())
|
||||
(i.0.zigzag(), i.1)
|
||||
})
|
||||
}
|
||||
/// Read VarInt as i128 with size in bytes (varint, size)
|
||||
fn read_i128_varint_size(&mut self) -> Result<(i128, i128), ProtocolError> {
|
||||
fn read_i128_varint_size(&mut self) -> Result<(i128, usize), ProtocolError> {
|
||||
Ok({
|
||||
let i = self.read_u128_varint_size()?;
|
||||
(i.0.zigzag(), i.1.zigzag())
|
||||
(i.0.zigzag(), i.1)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ macro_rules! size_varint {
|
||||
($type:ty, $self:expr) => {{
|
||||
let mut shift: $type = 0;
|
||||
let mut decoded: $type = 0;
|
||||
let mut size: $type = 0;
|
||||
let mut size: usize = 0;
|
||||
|
||||
loop {
|
||||
let next = DataBufferReader::read_byte($self).or(Err(ProtocolError::VarIntError))?;
|
||||
|
Loading…
Reference in New Issue
Block a user