Compare commits
No commits in common. "bcf1038148b420637eaffca92d51c4af166951dd" and "196592ae78e3878843c3dea99323c1477da6d380" have entirely different histories.
bcf1038148
...
196592ae78
108
src/login.rs
108
src/login.rs
|
@ -10,7 +10,6 @@ pub mod clientbound {
|
||||||
LoginSuccess(LoginSuccess),
|
LoginSuccess(LoginSuccess),
|
||||||
SetCompression(SetCompression),
|
SetCompression(SetCompression),
|
||||||
PluginRequest(PluginRequest),
|
PluginRequest(PluginRequest),
|
||||||
CookieRequest(CookieRequest),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Login {
|
impl Login {
|
||||||
|
@ -32,9 +31,6 @@ pub mod clientbound {
|
||||||
} else if packet_id == PluginRequest::packet_id() {
|
} else if packet_id == PluginRequest::packet_id() {
|
||||||
return Ok(Self::PluginRequest(
|
return Ok(Self::PluginRequest(
|
||||||
PluginRequest::get(&mut data)?))
|
PluginRequest::get(&mut data)?))
|
||||||
} else if packet_id == CookieRequest::packet_id() {
|
|
||||||
return Ok(Self::CookieRequest(
|
|
||||||
CookieRequest::get(&mut data)?))
|
|
||||||
} else {
|
} else {
|
||||||
return Err(Box::new(PacketError::InvalidPacketId))
|
return Err(Box::new(PacketError::InvalidPacketId))
|
||||||
}
|
}
|
||||||
|
@ -101,7 +97,6 @@ pub mod clientbound {
|
||||||
pub uuid: u128,
|
pub uuid: u128,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
pub properties: Vec<LoginSuccessProperty>,
|
pub properties: Vec<LoginSuccessProperty>,
|
||||||
pub strict_error_handling: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Packet for LoginSuccess {
|
impl Packet for LoginSuccess {
|
||||||
|
@ -113,7 +108,6 @@ pub mod clientbound {
|
||||||
uuid: mc_types::get_uuid(&mut data),
|
uuid: mc_types::get_uuid(&mut data),
|
||||||
username: mc_types::get_string(&mut data)?,
|
username: mc_types::get_string(&mut data)?,
|
||||||
properties: LoginSuccessProperty::get_array(&mut data)?,
|
properties: LoginSuccessProperty::get_array(&mut data)?,
|
||||||
strict_error_handling: mc_types::get_bool(&mut data),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,8 +118,6 @@ pub mod clientbound {
|
||||||
data.append(&mut mc_types::convert_string(&self.username));
|
data.append(&mut mc_types::convert_string(&self.username));
|
||||||
data.append(&mut LoginSuccessProperty::convert_array(
|
data.append(&mut LoginSuccessProperty::convert_array(
|
||||||
&mut self.properties.clone()));
|
&mut self.properties.clone()));
|
||||||
data.append(&mut mc_types::convert_bool(
|
|
||||||
self.strict_error_handling));
|
|
||||||
|
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
@ -236,30 +228,6 @@ pub mod clientbound {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CookieRequest {
|
|
||||||
pub key: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Packet for CookieRequest {
|
|
||||||
|
|
||||||
fn packet_id() -> i32 {5}
|
|
||||||
|
|
||||||
fn get(mut data: &mut Vec<u8>) -> Result<Self> {
|
|
||||||
Ok(Self {
|
|
||||||
key: mc_types::get_string(&mut data)?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn convert(&self) -> Vec<u8> {
|
|
||||||
let mut data: Vec<u8> = vec![];
|
|
||||||
data.append(&mut mc_types::convert_var_int(Self::packet_id()));
|
|
||||||
data.append(&mut mc_types::convert_string(&self.key));
|
|
||||||
|
|
||||||
data
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod serverbound {
|
pub mod serverbound {
|
||||||
|
@ -270,8 +238,6 @@ pub mod serverbound {
|
||||||
LoginStart(LoginStart),
|
LoginStart(LoginStart),
|
||||||
EncryptionResponse(EncryptionResponse),
|
EncryptionResponse(EncryptionResponse),
|
||||||
PluginResponse(PluginResponse),
|
PluginResponse(PluginResponse),
|
||||||
Acknowledged(Acknowledged),
|
|
||||||
CookieResponse(CookieResponse),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Login {
|
impl Login {
|
||||||
|
@ -288,12 +254,6 @@ pub mod serverbound {
|
||||||
} else if packet_id == PluginResponse::packet_id() {
|
} else if packet_id == PluginResponse::packet_id() {
|
||||||
return Ok(Self::PluginResponse(
|
return Ok(Self::PluginResponse(
|
||||||
PluginResponse::get(&mut data)?))
|
PluginResponse::get(&mut data)?))
|
||||||
} else if packet_id == Acknowledged::packet_id() {
|
|
||||||
return Ok(Self::Acknowledged(
|
|
||||||
Acknowledged::get(&mut data)?))
|
|
||||||
} else if packet_id == CookieResponse::packet_id() {
|
|
||||||
return Ok(Self::CookieResponse(
|
|
||||||
CookieResponse::get(&mut data)?))
|
|
||||||
} else {
|
} else {
|
||||||
return Err(Box::new(PacketError::InvalidPacketId))
|
return Err(Box::new(PacketError::InvalidPacketId))
|
||||||
}
|
}
|
||||||
|
@ -302,7 +262,7 @@ pub mod serverbound {
|
||||||
|
|
||||||
pub struct LoginStart {
|
pub struct LoginStart {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub player_uuid: u128,
|
pub player_uuid: Option<u128>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Packet for LoginStart {
|
impl Packet for LoginStart {
|
||||||
|
@ -311,7 +271,11 @@ pub mod serverbound {
|
||||||
|
|
||||||
fn get(mut data: &mut Vec<u8>) -> Result<Self> {
|
fn get(mut data: &mut Vec<u8>) -> Result<Self> {
|
||||||
let name = mc_types::get_string(&mut data)?;
|
let name = mc_types::get_string(&mut data)?;
|
||||||
let player_uuid: u128 = mc_types::get_uuid(&mut data);
|
let has_uuid = mc_types::get_bool(&mut data);
|
||||||
|
let mut player_uuid: Option<u128> = None;
|
||||||
|
if has_uuid {
|
||||||
|
player_uuid = Some(mc_types::get_uuid(&mut data));
|
||||||
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
name,
|
name,
|
||||||
player_uuid,
|
player_uuid,
|
||||||
|
@ -322,7 +286,13 @@ pub mod serverbound {
|
||||||
let mut data: Vec<u8> = vec![];
|
let mut data: Vec<u8> = vec![];
|
||||||
data.append(&mut mc_types::convert_var_int(Self::packet_id()));
|
data.append(&mut mc_types::convert_var_int(Self::packet_id()));
|
||||||
data.append(&mut mc_types::convert_string(&self.name));
|
data.append(&mut mc_types::convert_string(&self.name));
|
||||||
data.append(&mut mc_types::convert_uuid(self.player_uuid));
|
match self.player_uuid {
|
||||||
|
Some(value) => {
|
||||||
|
data.append(&mut mc_types::convert_bool(true));
|
||||||
|
data.append(&mut mc_types::convert_uuid(value));
|
||||||
|
},
|
||||||
|
None => data.append(&mut mc_types::convert_bool(false))
|
||||||
|
}
|
||||||
|
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
@ -388,56 +358,4 @@ pub mod serverbound {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Acknowledged {}
|
|
||||||
|
|
||||||
impl Packet for Acknowledged {
|
|
||||||
|
|
||||||
fn packet_id() -> i32 {3}
|
|
||||||
|
|
||||||
fn get(_data: &mut Vec<u8>) -> Result<Self> {
|
|
||||||
Ok(Self {})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn convert(&self) -> Vec<u8> {
|
|
||||||
let mut data: Vec<u8> = vec![];
|
|
||||||
data.append(&mut mc_types::convert_var_int(Self::packet_id()));
|
|
||||||
|
|
||||||
data
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CookieResponse {
|
|
||||||
pub key: String,
|
|
||||||
pub has_payload: bool,
|
|
||||||
pub payload_load: i32,
|
|
||||||
pub payload: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Packet for CookieResponse {
|
|
||||||
|
|
||||||
fn packet_id() -> i32 {4}
|
|
||||||
|
|
||||||
fn get(mut data: &mut Vec<u8>) -> Result<Self> {
|
|
||||||
Ok(Self {
|
|
||||||
key: mc_types::get_string(&mut data)?,
|
|
||||||
has_payload: mc_types::get_bool(&mut data),
|
|
||||||
payload_load: mc_types::get_var_int(&mut data)?,
|
|
||||||
payload: data.clone(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn convert(&self) -> Vec<u8> {
|
|
||||||
let mut data: Vec<u8> = vec![];
|
|
||||||
data.append(&mut mc_types::convert_var_int(Self::packet_id()));
|
|
||||||
data.append(&mut mc_types::convert_string(&self.key));
|
|
||||||
data.append(&mut mc_types::convert_bool(self.has_payload));
|
|
||||||
data.append(&mut mc_types::convert_var_int(self.payload_load));
|
|
||||||
data.append(&mut self.payload.clone());
|
|
||||||
|
|
||||||
data
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ use crate::play::Play;
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Box<dyn Error>>;
|
pub type Result<T> = std::result::Result<T, Box<dyn Error>>;
|
||||||
|
|
||||||
pub const VERSION_NAME: &str = "1.21";
|
pub const VERSION_NAME: &str = "1.19.4";
|
||||||
pub const VERSION_PROTOCOL: i32 = 767;
|
pub const VERSION_PROTOCOL: i32 = 762;
|
||||||
|
|
||||||
const SEGMENT_BITS: u8 = 0x7F;
|
const SEGMENT_BITS: u8 = 0x7F;
|
||||||
const CONTINUE_BIT: u8 = 0x80;
|
const CONTINUE_BIT: u8 = 0x80;
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
pub mod clientbound {
|
pub mod clientbound {
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
use serde::{Serialize, Deserialize};
|
||||||
use serde::de::{self, Visitor, MapAccess};
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use crate::mc_types::{self, Result, Packet, PacketError};
|
use crate::mc_types::{self, Result, Packet, PacketError};
|
||||||
|
|
||||||
|
@ -14,64 +12,6 @@ pub mod clientbound {
|
||||||
pub protocol: i32,
|
pub protocol: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum StatusDescription {
|
|
||||||
String(String),
|
|
||||||
Chat(mc_types::Chat),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Serialize for StatusDescription {
|
|
||||||
fn serialize<S>(&self, serializer: S)
|
|
||||||
-> std::result::Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
match *self {
|
|
||||||
StatusDescription::String(ref s) => serializer.serialize_str(s),
|
|
||||||
StatusDescription::Chat(ref c) => c.serialize(serializer),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for StatusDescription {
|
|
||||||
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
struct StatusDescriptionVisitor;
|
|
||||||
|
|
||||||
impl<'de> Visitor<'de> for StatusDescriptionVisitor {
|
|
||||||
type Value = StatusDescription;
|
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter)
|
|
||||||
-> fmt::Result
|
|
||||||
{
|
|
||||||
formatter.write_str(
|
|
||||||
"a string or a map representing a Chat object")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_str<E>(self, value: &str)
|
|
||||||
-> std::result::Result<StatusDescription, E>
|
|
||||||
where
|
|
||||||
E: de::Error,
|
|
||||||
{
|
|
||||||
Ok(StatusDescription::String(value.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_map<M>(self, map: M)
|
|
||||||
-> std::result::Result<StatusDescription, M::Error>
|
|
||||||
where
|
|
||||||
M: MapAccess<'de>,
|
|
||||||
{
|
|
||||||
let chat = mc_types::Chat::deserialize(
|
|
||||||
de::value::MapAccessDeserializer::new(map))?;
|
|
||||||
Ok(StatusDescription::Chat(chat))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deserializer.deserialize_any(StatusDescriptionVisitor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct StatusPlayerInfo {
|
pub struct StatusPlayerInfo {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -90,7 +30,7 @@ pub mod clientbound {
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct StatusResponseData {
|
pub struct StatusResponseData {
|
||||||
pub version: StatusVersion,
|
pub version: StatusVersion,
|
||||||
pub description: StatusDescription,
|
pub description: mc_types::Chat,
|
||||||
pub players: StatusPlayers,
|
pub players: StatusPlayers,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub favicon: Option<String>,
|
pub favicon: Option<String>,
|
||||||
|
|
Loading…
Reference in New Issue