diff --git a/src/protocols/custom_report_details.rs b/src/protocols/custom_report_details.rs index b0ab449..f79472e 100644 --- a/src/protocols/custom_report_details.rs +++ b/src/protocols/custom_report_details.rs @@ -5,8 +5,6 @@ use crate::types::McRead; use crate::utils::RWStreamWithLimit; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, BufWriter}; -pub struct Protocol {} - #[derive(Debug, Clone)] pub struct Data { details: Vec<(McString<128>, McString<4096>)>, @@ -18,56 +16,14 @@ impl McRead for Data { where Self: Sized, { - // let size = stream. - // let mut v = vec![0; size]; - // let mut writer = BufWriter::new(&mut v); - - // let x = stream.read_buf(&mut v) - println!(); - loop { - let byte = stream.read_u8().await.map_err(|e| { - dbg!(e); - "idk" - })?; - print!(" '{:0>2x}' ", byte); - dbg!(byte); + let count = VarInt::read_stream(stream).await?; + let mut details = vec![]; + for i in 0..*count { + let title = McString::read_stream(stream).await?; + let description = McString::read_stream(stream).await?; + details.push((title, description)); } - // println!("x"); - // println!("{:?}", v); - // dbg!(&v); - // let count = VarInt::read_stream(stream).await?; - let details = vec![]; - // let string = format!("Still need to get details from stream ({})", *count); - // dbg!(string); - // for i in 0..*count { - // let title = McString::<128>::read_stream(stream).await?; - // let description = McString::<128>::read_stream(stream).await?; - // } Ok(Self { details }) } } -impl Protocol { - pub async fn handle( - stream: &mut RWStreamWithLimit<'_, T>, - // bytes_left_in_package: &mut i32, - ) -> Result<(), bool> { - println!("Some custom report detail stuff..."); - let count = VarInt::read_stream(stream).await.map_err(|x| { - dbg!(x); - true - })?; - dbg!(&count); - for i in 0..*count { - // McString::<128>::read_stream(stream).await.map_err(|x| { - // dbg!(x); - // true - // })?; - // McString::<4096>::read_stream(stream).await.map_err(|x| { - // dbg!(x); - // true - // })?; - } - Err(true) - } -} diff --git a/src/protocols/ping.rs b/src/protocols/ping.rs index 87b0a90..7bfb03a 100644 --- a/src/protocols/ping.rs +++ b/src/protocols/ping.rs @@ -7,8 +7,6 @@ use crate::types::{McRead, McWrite}; use crate::utils::RWStreamWithLimit; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; -pub struct Protocol(); - #[derive(Debug, Clone)] pub struct Data { pub timespan: Long, @@ -42,24 +40,3 @@ impl McWrite for ResponseData { .map_err(|e| e.to_string()) } } -impl Protocol { - pub async fn handle( - stream: &mut RWStreamWithLimit<'_, T>, - ) -> Result<(), bool> { - println!("Ping"); - let v = stream.read_i64().await.map_err(|e| { - dbg!(e); - false - })?; - VarInt(0x01).write_stream(stream).await.map_err(|x| { - dbg!(x); - false - })?; - stream.write_i64(v).await.map_err(|e| { - dbg!(e); - false - })?; - - Ok(()) - } -} diff --git a/src/protocols/status.rs b/src/protocols/status.rs index c5c281a..e4dccd0 100644 --- a/src/protocols/status.rs +++ b/src/protocols/status.rs @@ -8,8 +8,6 @@ use crate::utils::RWStreamWithLimit; use serde_json::json; use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, BufWriter}; -pub struct Protocol {} - #[derive(Debug, Clone)] pub struct Data {} @@ -30,7 +28,7 @@ pub struct ResponseData { impl Default for ResponseData { fn default() -> Self { Self { - json_response: McString::from_string(Protocol::get_sample_result()), + json_response: McString::from_string(get_sample_result()), } } } @@ -47,84 +45,27 @@ impl McWrite for ResponseData { .map_err(|e| e.to_string()) } } -impl Protocol { - pub async fn handle( - stream: &mut RWStreamWithLimit<'_, T>, - ) -> Result<(), bool> { - println!("Status"); - stream.discard_unread().await.map_err(|x| { - dbg!(x); - false - })?; - let string = Self::get_sample_result(); - let response = ResponseData { - json_response: McString::from_string(string), - }; - let x = Package::Outgoing(OutgoingPackage { - protocol: crate::protocols::ProtocolResponseId::Status, - content: OutgoingPackageContent::StatusResponse(response), - }); - // - // let mut total_size = 0; - // let mut v = Vec::new(); - // let mut writer = BufWriter::new(&mut v); - // - // //Package ID - // total_size += VarInt(0x00).write_stream(&mut writer).await.map_err(|x| { - // dbg!(x); - // false - // })?; - // - // //Status JSON - // total_size += McString::<32767>::from_string(string) - // .write_stream(&mut writer) - // .await - // .map_err(|x| { - // dbg!(x); - // false - // })?; - // writer.flush().await.unwrap(); - // - // println!("total size: {}: {:?}", total_size, &v); - // //Size in front - // VarInt(total_size as i32) - // .write_stream(stream) - // .await - // .map_err(|x| { - // dbg!(x); - // false - // })?; - // //actually write the content to the stream, not just a local buffer - // stream.write_all(&v).await.map_err(|x| { - // dbg!(x); - // false - // })?; - - Ok(()) - } - - fn get_sample_result() -> String { - json!({ - "version": { - "name": "1.21.2", - "protocol": 768 - }, - "players": { - "max": 1000000000, - "online": 5, - "sample": [ - { - "name": "thinkofdeath", - "id": "4566e69f-c907-48ee-8d71-d7ba5aa00d20", - }, - ], - }, - "description": { - "text": "Hello, world!" - }, - // "favicon": "data:image/png;base64,", - "enforcesSecureChat": false, - }) - .to_string() - } +fn get_sample_result() -> String { + json!({ + "version": { + "name": "1.21.2", + "protocol": 768 + }, + "players": { + "max": 1000000000, + "online": 5, + "sample": [ + { + "name": "thinkofdeath", + "id": "4566e69f-c907-48ee-8d71-d7ba5aa00d20", + }, + ], + }, + "description": { + "text": "Hello, world!" + }, + // "favicon": "data:image/png;base64,", + "enforcesSecureChat": false, + }) + .to_string() }