First push

This commit is contained in:
xeon
2024-03-29 09:46:31 +03:00
parent 46a868ca85
commit c0cdf91849
32 changed files with 39006 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
use anyhow::Result;
use tokio::net::TcpListener;
use tracing::{info_span, Instrument};
use crate::{log_error, net::PlayerSession};
pub async fn listen(host: &str, port: u16) -> Result<()> {
let listener = TcpListener::bind(format!("{host}:{port}")).await?;
tracing::info!("Listening at {host}:{port}");
loop {
let Ok((client_socket, client_addr)) = listener.accept().await else {
continue;
};
let mut session = PlayerSession::new(client_socket);
tokio::spawn(
async move {
log_error!(
"Session from {client_addr} disconnected",
format!("An error occurred while processing session ({client_addr})"),
Box::pin(session.run()).await
);
}
.instrument(info_span!("session", addr = %client_addr)),
);
}
}