mirror of
https://github.com/OMGeeky/mc-server-rs-sample.git
synced 2026-01-07 03:41:20 +01:00
create package structs for easier handling of individual packages & finally fix status.
It finally works in the client to list the server
This commit is contained in:
@@ -1,11 +1,45 @@
|
||||
use crate::types::long::Long;
|
||||
use crate::types::string::McString;
|
||||
use crate::types::var_int::VarInt;
|
||||
use crate::types::var_long::VarLong;
|
||||
use crate::types::{McRead, McWrite};
|
||||
use crate::utils::RWStreamWithLimit;
|
||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
||||
|
||||
pub struct Protocol {}
|
||||
pub struct Protocol();
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Data {
|
||||
pub timespan: Long,
|
||||
}
|
||||
impl McRead for Data {
|
||||
async fn read_stream<T: AsyncRead + Unpin>(stream: &mut T) -> Result<Self, String>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Ok(Self {
|
||||
timespan: Long::read_stream(stream).await?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ResponseData {
|
||||
pub(crate) timespan: Long,
|
||||
}
|
||||
impl McWrite for ResponseData {
|
||||
type Error = String;
|
||||
|
||||
async fn write_stream<T: AsyncWrite + Unpin>(
|
||||
&self,
|
||||
stream: &mut T,
|
||||
) -> Result<usize, Self::Error> {
|
||||
self.timespan
|
||||
.write_stream(stream)
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
impl Protocol {
|
||||
pub async fn handle<T: AsyncRead + AsyncWrite + Unpin>(
|
||||
stream: &mut RWStreamWithLimit<'_, T>,
|
||||
|
||||
Reference in New Issue
Block a user