server list working

This commit is contained in:
2026-05-06 02:49:03 +02:00
parent ddfb5b3ddb
commit 5324cb8c29
6 changed files with 371 additions and 2 deletions

View File

@ -1,3 +1,48 @@
fn main() {
println!("Hello, world!");
use tokio::net::{TcpListener, TcpStream};
mod client;
use client::Client;
use std::io;
pub mod varint;
pub mod handshake;
async fn process_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 _ = client.buffer_append((&buf[..n]).to_vec()).await;
if n == 0 {
break;
}
}
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
continue;
}
Err(e) => {
return Err(e.into());
}
}
}
Ok(())
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> io::Result<()> {
let listener = TcpListener::bind("0.0.0.0:25565").await?;
loop {
let (socket, _) = listener.accept().await?;
tokio::spawn(async move {
if let Err(e) = process_socket(socket).await {
eprintln!("error: {:?}", e);
}
});
}
}