WIP, borked

This commit is contained in:
2026-05-19 18:59:52 +02:00
parent 20ce06657d
commit 1de458dc54
5 changed files with 170 additions and 46 deletions

View File

@ -1,33 +1,30 @@
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];
pub async fn process_mc_socket(stream: TcpStream) -> Result<(), String> {
println!("new client {:?}", stream);
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);
tokio::select! {
Ok(()) = client.in_stream.readable() => {
println!("[{}] in read", client);
let res = client.in_read().await?;
if res == 0 {
break;
}
if n == 0 {
println!("[{}] continue listening", client);
}
_ = client.out_readable() => {
println!("[{}] out read", client);
let res = client.out_read().await?;
if res == 0 {
break;
}
}
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
continue;
}
Err(e) => {
return Err(e.into());
}
}
}
Ok(())
}