mirror of
https://github.com/OMGeeky/mc-server-rs-sample.git
synced 2025-12-26 17:02:27 +01:00
cleanup & probably fix custom_report_details
This commit is contained in:
@@ -5,8 +5,6 @@ use crate::types::McRead;
|
|||||||
use crate::utils::RWStreamWithLimit;
|
use crate::utils::RWStreamWithLimit;
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, BufWriter};
|
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, BufWriter};
|
||||||
|
|
||||||
pub struct Protocol {}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
details: Vec<(McString<128>, McString<4096>)>,
|
details: Vec<(McString<128>, McString<4096>)>,
|
||||||
@@ -18,56 +16,14 @@ impl McRead for Data {
|
|||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
// let size = stream.
|
let count = VarInt::read_stream(stream).await?;
|
||||||
// let mut v = vec![0; size];
|
let mut details = vec![];
|
||||||
// let mut writer = BufWriter::new(&mut v);
|
for i in 0..*count {
|
||||||
|
let title = McString::read_stream(stream).await?;
|
||||||
// let x = stream.read_buf(&mut v)
|
let description = McString::read_stream(stream).await?;
|
||||||
println!();
|
details.push((title, description));
|
||||||
loop {
|
|
||||||
let byte = stream.read_u8().await.map_err(|e| {
|
|
||||||
dbg!(e);
|
|
||||||
"idk"
|
|
||||||
})?;
|
|
||||||
print!(" '{:0>2x}' ", byte);
|
|
||||||
dbg!(byte);
|
|
||||||
}
|
}
|
||||||
// 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 })
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ use crate::types::{McRead, McWrite};
|
|||||||
use crate::utils::RWStreamWithLimit;
|
use crate::utils::RWStreamWithLimit;
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
||||||
|
|
||||||
pub struct Protocol();
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
pub timespan: Long,
|
pub timespan: Long,
|
||||||
@@ -42,24 +40,3 @@ impl McWrite for ResponseData {
|
|||||||
.map_err(|e| e.to_string())
|
.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(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ use crate::utils::RWStreamWithLimit;
|
|||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, BufWriter};
|
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, BufWriter};
|
||||||
|
|
||||||
pub struct Protocol {}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Data {}
|
pub struct Data {}
|
||||||
|
|
||||||
@@ -30,7 +28,7 @@ pub struct ResponseData {
|
|||||||
impl Default for ResponseData {
|
impl Default for ResponseData {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
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())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Protocol {
|
fn get_sample_result() -> String {
|
||||||
pub async fn handle<T: AsyncRead + AsyncWrite + Unpin>(
|
json!({
|
||||||
stream: &mut RWStreamWithLimit<'_, T>,
|
"version": {
|
||||||
) -> Result<(), bool> {
|
"name": "1.21.2",
|
||||||
println!("Status");
|
"protocol": 768
|
||||||
stream.discard_unread().await.map_err(|x| {
|
},
|
||||||
dbg!(x);
|
"players": {
|
||||||
false
|
"max": 1000000000,
|
||||||
})?;
|
"online": 5,
|
||||||
let string = Self::get_sample_result();
|
"sample": [
|
||||||
let response = ResponseData {
|
{
|
||||||
json_response: McString::from_string(string),
|
"name": "thinkofdeath",
|
||||||
};
|
"id": "4566e69f-c907-48ee-8d71-d7ba5aa00d20",
|
||||||
let x = Package::Outgoing(OutgoingPackage {
|
},
|
||||||
protocol: crate::protocols::ProtocolResponseId::Status,
|
],
|
||||||
content: OutgoingPackageContent::StatusResponse(response),
|
},
|
||||||
});
|
"description": {
|
||||||
//
|
"text": "Hello, world!"
|
||||||
// let mut total_size = 0;
|
},
|
||||||
// let mut v = Vec::new();
|
// "favicon": "data:image/png;base64,<data>",
|
||||||
// let mut writer = BufWriter::new(&mut v);
|
"enforcesSecureChat": false,
|
||||||
//
|
})
|
||||||
// //Package ID
|
.to_string()
|
||||||
// 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,<data>",
|
|
||||||
"enforcesSecureChat": false,
|
|
||||||
})
|
|
||||||
.to_string()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user