reorganize file structure, define rpc protocol

This commit is contained in:
2026-05-10 18:13:04 +02:00
parent 5324cb8c29
commit 20ce06657d
12 changed files with 591 additions and 48 deletions

33
src/minecraft/socket.rs Normal file
View File

@ -0,0 +1,33 @@
use std::io::{self, Error};
use crate::minecraft::client::Client;
use tokio::net::TcpStream;
pub async fn process_mc_socket(stream: TcpStream) -> io::Result<()> {
let mut buf = vec![0 as u8; 1024];
let mut client = Client::create(stream);
loop {
client.in_stream.readable().await?;
match client.in_stream.try_read(&mut buf) {
Ok(n) => {
let result = client.buffer_append((&buf[..n]).to_vec()).await;
if let Err(error) = result {
eprintln!("mc error : {}", error);
break;
}
if n == 0 {
break;
}
}
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
continue;
}
Err(e) => {
return Err(e.into());
}
}
}
Ok(())
}