connection error instead of varint error

This commit is contained in:
MeexReay 2024-11-14 12:16:30 +03:00
parent 26a78af446
commit abe738aad5
2 changed files with 4 additions and 4 deletions

View File

@ -1,11 +1,11 @@
use rust_mc_proto::{DataBufferReader, DataBufferWriter, MCConnTcp, Packet, ProtocolError}; use rust_mc_proto::{DataBufferReader, DataBufferWriter, MCConnTcp, Packet, ProtocolError};
fn main() -> Result<(), ProtocolError> { fn main() -> Result<(), ProtocolError> {
let mut conn = MCConnTcp::connect("mc.hypixel.net:25565")?; // connecting let mut conn = MCConnTcp::connect("localhost:25565")?; // connecting
conn.write_packet(&Packet::build(0x00, |packet| { conn.write_packet(&Packet::build(0x00, |packet| {
packet.write_u16_varint(765)?; // protocol_version packet.write_u16_varint(765)?; // protocol_version
packet.write_string("mc.hypixel.net")?; // server_address packet.write_string("localhost")?; // server_address
packet.write_unsigned_short(25565)?; // server_port packet.write_unsigned_short(25565)?; // server_port
packet.write_u8_varint(1) // next_state packet.write_u8_varint(1) // next_state
})?)?; // handshake packet })?)?; // handshake packet

View File

@ -5,7 +5,7 @@ macro_rules! size_varint {
let mut size: usize = 0; let mut size: usize = 0;
loop { loop {
let next = DataBufferReader::read_byte($self).or(Err(ProtocolError::VarIntError))?; let next = DataBufferReader::read_byte($self)?;
size += 1; size += 1;
if shift >= (std::mem::size_of::<$type>() * 8) as $type { if shift >= (std::mem::size_of::<$type>() * 8) as $type {
@ -29,7 +29,7 @@ macro_rules! read_varint {
let mut decoded: $type = 0; let mut decoded: $type = 0;
loop { loop {
let next = DataBufferReader::read_byte($self).or(Err(ProtocolError::VarIntError))?; let next = DataBufferReader::read_byte($self)?;
if shift >= (std::mem::size_of::<$type>() * 8) as $type { if shift >= (std::mem::size_of::<$type>() * 8) as $type {
return Err(ProtocolError::VarIntError); return Err(ProtocolError::VarIntError);