- add: utils library

- add: packet-service to handle game client packets
- fix: health check for database-service
- fix: health check for auth-service
This commit is contained in:
2024-12-09 23:10:26 -05:00
parent 20e86dd117
commit e5c961d1b4
25 changed files with 1176 additions and 120 deletions

View File

@@ -1,13 +1,29 @@
use crate::packet::Packet;
// use crate::handlers::{chat, movement};
use crate::packet::{Packet};
use crate::handlers::{auth};
use crate::packet_type::PacketType;
use std::error::Error;
use std::sync::Arc;
use tokio::net::TcpStream;
use tokio::sync::Mutex;
use tracing::{debug, warn};
use crate::auth_client::AuthClient;
pub async fn route_packet(data: &[u8]) -> Result<(), Box<dyn Error>> {
let packet = Packet::parse(data)?;
pub async fn route_packet(stream: &mut TcpStream, packet: Packet, auth_client: Arc<Mutex<AuthClient>>) -> Result<(), Box<dyn Error + Send + Sync>> {
debug!("Routing packet: {:?}", packet);
match packet.packet_type {
PacketType::PakcsAlive => Ok(()),
PacketType::PakcsAcceptReq => auth::handle_accept_req(stream, packet).await,
PacketType::PakcsJoinServerReq => auth::handle_join_server_req(stream, packet).await,
// Login Stuff
PacketType::PakcsLoginReq => auth::handle_login_req(stream, packet, auth_client).await,
PacketType::PakcsSrvSelectReq => auth::handle_server_select_req(stream, packet).await,
PacketType::PakcsChannelListReq => auth::handle_channel_list_req(stream, packet).await,
// 1 => chat::handle_chat(packet).await?,
// 2 => movement::handle_movement(packet).await?,
_ => Err("Unknown packet type".into()),
_ => {
warn!("Unhandled packet type: {:?}", packet.packet_type);
Ok(())
},
}
}