Fix
This commit is contained in:
parent
03267e3318
commit
99a331c6ab
4
generate.sh
Executable file
4
generate.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
cargo run
|
||||
cargo fmt
|
@ -48,4 +48,4 @@ impl {{packet_enum_name}} {
|
||||
}
|
||||
{{/each~}}
|
||||
}
|
||||
{{~/if}}
|
||||
{{~/if}}
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
{{#each imports as |i|~}}
|
||||
use {{i}};
|
||||
{{/each}}
|
||||
{{/each~}}
|
||||
|
@ -239,6 +239,20 @@ impl Decoder for u8 {
|
||||
}
|
||||
}
|
||||
|
||||
impl Encoder for u16 {
|
||||
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
|
||||
Ok(writer.write_u16::<BigEndian>(*self)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for u16 {
|
||||
type Output = Self;
|
||||
|
||||
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
|
||||
Ok(reader.read_u16::<BigEndian>()?)
|
||||
}
|
||||
}
|
||||
|
||||
impl Encoder for i32 {
|
||||
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
|
||||
Ok(writer.write_i32::<BigEndian>(*self)?)
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
@ -41,6 +43,7 @@ impl HandshakeServerBoundPacket {
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
|
@ -1,13 +1,14 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use std::io::Read;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
pub enum LoginServerBoundPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
LoginPluginResponse(LoginPluginResponse)
|
||||
LoginPluginResponse(LoginPluginResponse),
|
||||
}
|
||||
|
||||
impl LoginServerBoundPacket {
|
||||
@ -15,7 +16,7 @@ impl LoginServerBoundPacket {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
Self::LoginPluginResponse(_) => 0x02
|
||||
Self::LoginPluginResponse(_) => 0x02,
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,14 +37,12 @@ impl LoginServerBoundPacket {
|
||||
|
||||
Ok(Self::LoginPluginResponse(login_plugin_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id })
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart {
|
||||
username
|
||||
};
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
@ -51,27 +50,25 @@ impl LoginServerBoundPacket {
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
|
||||
pub fn login_plugin_response(message_id: i32, data: Vec<u8>) -> Self {
|
||||
let login_plugin_response = LoginPluginResponse {
|
||||
message_id,
|
||||
data
|
||||
};
|
||||
let login_plugin_response = LoginPluginResponse { message_id, data };
|
||||
|
||||
Self::LoginPluginResponse(login_plugin_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum LoginClientBoundPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
LoginPluginRequest(LoginPluginRequest)
|
||||
LoginPluginRequest(LoginPluginRequest),
|
||||
}
|
||||
|
||||
impl LoginClientBoundPacket {
|
||||
@ -81,7 +78,7 @@ impl LoginClientBoundPacket {
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
Self::LoginPluginRequest(_) => 0x04
|
||||
Self::LoginPluginRequest(_) => 0x04,
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,41 +109,38 @@ impl LoginClientBoundPacket {
|
||||
|
||||
Ok(Self::LoginPluginRequest(login_plugin_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id })
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect {
|
||||
reason
|
||||
};
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
pub fn encryption_request(server_id: String, public_key: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
pub fn encryption_request(
|
||||
server_id: String,
|
||||
public_key: Vec<u8>,
|
||||
verify_token: Vec<u8>,
|
||||
) -> Self {
|
||||
let encryption_request = EncryptionRequest {
|
||||
server_id,
|
||||
public_key,
|
||||
verify_token
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success {
|
||||
uuid,
|
||||
username
|
||||
};
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress {
|
||||
threshold
|
||||
};
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
@ -155,21 +149,22 @@ impl LoginClientBoundPacket {
|
||||
let login_plugin_request = LoginPluginRequest {
|
||||
message_id,
|
||||
channel,
|
||||
data
|
||||
data,
|
||||
};
|
||||
|
||||
Self::LoginPluginRequest(login_plugin_request)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
@ -177,32 +172,31 @@ pub struct LoginPluginResponse {
|
||||
#[packet(with = "var_int")]
|
||||
pub message_id: i32,
|
||||
#[packet(with = "rest")]
|
||||
pub data: Vec<u8>
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32
|
||||
pub threshold: i32,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
@ -211,6 +205,5 @@ pub struct LoginPluginRequest {
|
||||
pub message_id: i32,
|
||||
pub channel: String,
|
||||
#[packet(with = "rest")]
|
||||
pub data: Vec<u8>
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
|
@ -1,33 +1,32 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use std::io::Read;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
pub enum StatusServerBoundPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest)
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl StatusServerBoundPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
Ok(Self::StatusRequest)
|
||||
}
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id })
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,23 +35,22 @@ impl StatusServerBoundPacket {
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest {
|
||||
time
|
||||
};
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum StatusClientBoundPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse)
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl StatusClientBoundPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,39 +66,34 @@ impl StatusClientBoundPacket {
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id })
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse {
|
||||
response
|
||||
};
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse {
|
||||
time
|
||||
};
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user