Updated handlers by spliting the TcpStream in half to allow reading and writing data at the same time.
This fixes an issue where you are unable to get chat messages until the client sends a packet to the server

Fixed client id's by adding the id manager
Added shout chat handling
This commit is contained in:
2025-06-07 00:36:02 -04:00
parent d4dadf5170
commit aa2be43f4e
17 changed files with 480 additions and 157 deletions

View File

@@ -17,7 +17,7 @@ use std::sync::Arc;
use tokio::io::AsyncReadExt;
use tokio::net::{TcpListener, TcpStream};
use tokio::sync::{Mutex, Semaphore};
use tokio::{select, signal};
use tokio::{io, select, signal};
use tracing::Level;
use tracing::{debug, error, info, warn};
use tracing_subscriber::EnvFilter;
@@ -40,6 +40,7 @@ mod packets;
mod router;
mod types;
mod interceptors;
mod id_manager;
pub mod common {
tonic::include_proto!("common");
@@ -111,14 +112,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let pool = buffer_pool.clone();
let permit = semaphore.clone().acquire_owned().await.unwrap();
let stream = Arc::new(Mutex::new(socket));
let peer_addr = socket.peer_addr().unwrap();
let (mut reader, writer) = io::split(socket);
let writer = Arc::new(tokio::sync::Mutex::new(writer));
// Spawn a new task for each connection
tokio::spawn(async move {
let _permit = permit;
let connection_id = packet_router.connection_service.add_connection();
let connection_id = packet_router.connection_service.add_connection(writer);
if let Err(e) = packet_router
.handle_connection(stream, pool, connection_id.clone())
.handle_connection(reader, pool, connection_id.clone(), peer_addr.to_string())
.await
{
error!("Error handling connection: {}", e);