Tons of fixes

Added movement updates
Updated how entities are checked
Events sending between packet service all the way to the logic service
This commit is contained in:
2025-06-25 12:30:07 -04:00
parent f75782885b
commit d906cd8d64
34 changed files with 3550 additions and 186 deletions

View File

@@ -9,9 +9,10 @@ use std::env;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
use tokio::sync::Mutex;
use tokio::sync::{Mutex, oneshot};
use tokio::time::{timeout, Duration};
use tonic::transport::Server;
use tracing::{info, Level};
use tracing::{info, error, warn, Level};
use tracing_subscriber::EnvFilter;
use utils::logging;
use utils::redis_cache::RedisCache;
@@ -38,22 +39,61 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let db = Arc::new(Database::new(pool, redis_cache));
let my_service = MyDatabaseService { db };
// Start gRPC server with graceful shutdown support
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
health_reporter
.set_serving::<UserServiceServer<MyDatabaseService>>()
.await;
let address = SocketAddr::new(addr.parse()?, port.parse()?);
tokio::spawn(
Server::builder()
// Create shutdown signal channel
let (shutdown_tx, shutdown_rx) = oneshot::channel::<()>();
let server_task = tokio::spawn(async move {
let server = Server::builder()
.add_service(health_service)
.add_service(UserServiceServer::new(my_service.clone()))
.add_service(CharacterDbServiceServer::new(my_service.clone()))
.add_service(SessionServiceServer::new(my_service))
.serve(address),
);
.serve_with_shutdown(address, async {
shutdown_rx.await.ok();
info!("Database service gRPC server shutdown signal received");
});
if let Err(e) = server.await {
error!("Database service gRPC server error: {}", e);
} else {
info!("Database service gRPC server shut down gracefully");
}
});
info!("Database Service running on {}", address);
// Wait for shutdown signal
info!("Database service is running. Waiting for shutdown signal...");
utils::signal_handler::wait_for_signal().await;
info!("Shutdown signal received. Beginning graceful shutdown...");
// Signal the gRPC server to stop accepting new connections
if let Err(_) = shutdown_tx.send(()) {
warn!("Failed to send shutdown signal to gRPC server (receiver may have been dropped)");
}
// Wait for the gRPC server to finish with a timeout
match timeout(Duration::from_secs(30), server_task).await {
Ok(result) => {
if let Err(e) = result {
error!("Database service gRPC server task failed: {}", e);
} else {
info!("Database service shut down successfully");
}
}
Err(_) => {
error!("Database service gRPC server shutdown timed out after 30 seconds");
}
}
Ok(())
}