Add Handshake (#19)
Co-authored-by: mibac138 <5672750+mibac138@users.noreply.github.com>
This commit is contained in:
parent
6a069edaff
commit
f19f598abe
55
protocol/src/version/v1_14_4/handshake.rs
Normal file
55
protocol/src/version/v1_14_4/handshake.rs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
use crate::decoder::Decoder;
|
||||||
|
use crate::error::DecodeError;
|
||||||
|
use minecraft_protocol_derive::{Decoder, Encoder};
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
pub enum HandshakeServerBoundPacket {
|
||||||
|
Handshake(Handshake),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HandshakeServerBoundPacket {
|
||||||
|
pub fn get_type_id(&self) -> u8 {
|
||||||
|
match self {
|
||||||
|
HandshakeServerBoundPacket::Handshake(_) => 0x00,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||||
|
match type_id {
|
||||||
|
0x00 => {
|
||||||
|
let handshake = Handshake::decode(reader)?;
|
||||||
|
Ok(HandshakeServerBoundPacket::Handshake(handshake))
|
||||||
|
}
|
||||||
|
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Encoder, Decoder, Debug)]
|
||||||
|
pub struct Handshake {
|
||||||
|
#[data_type(with = "var_int")]
|
||||||
|
pub protocol_version: i32,
|
||||||
|
#[data_type(max_length = 255)]
|
||||||
|
pub server_addr: String,
|
||||||
|
pub server_port: u16,
|
||||||
|
#[data_type(with = "var_int")]
|
||||||
|
pub next_state: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Handshake {
|
||||||
|
pub fn new(
|
||||||
|
protocol_version: i32,
|
||||||
|
server_addr: String,
|
||||||
|
server_port: u16,
|
||||||
|
next_state: i32,
|
||||||
|
) -> HandshakeServerBoundPacket {
|
||||||
|
let handshake = Handshake {
|
||||||
|
protocol_version,
|
||||||
|
server_addr,
|
||||||
|
server_port,
|
||||||
|
next_state,
|
||||||
|
};
|
||||||
|
|
||||||
|
HandshakeServerBoundPacket::Handshake(handshake)
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
pub mod game;
|
pub mod game;
|
||||||
|
pub mod handshake;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod status;
|
pub mod status;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user