cleanup & probably fix custom_report_details

This commit is contained in:
OMGeeky
2024-11-17 17:29:33 +01:00
parent 5d6bdfe10f
commit 6a61b0ba9f
3 changed files with 30 additions and 156 deletions

View File

@@ -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<T: AsyncRead + AsyncWrite + Unpin>(
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)
}
}

View File

@@ -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<T: AsyncRead + AsyncWrite + Unpin>(
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(())
}
}

View File

@@ -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,62 +45,6 @@ impl McWrite for ResponseData {
.map_err(|e| e.to_string())
}
}
impl Protocol {
pub async fn handle<T: AsyncRead + AsyncWrite + Unpin>(
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": {
@@ -127,4 +69,3 @@ impl Protocol {
})
.to_string()
}
}