use crate::auth_client::AuthClient; use crate::handlers::*; use crate::packet::Packet; 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::connection_service::ConnectionService; pub async fn route_packet(stream: &mut TcpStream, packet: Packet, auth_client: Arc>, connection_service: Arc, connection_id: String) -> Result<(), Box> { debug!("Routing packet: {:?}", packet); match packet.packet_type { PacketType::PakcsAlive => Ok(()), PacketType::PakcsAcceptReq => auth::handle_accept_req(stream, packet).await, PacketType::PakcsJoinServerTokenReq => auth::handle_join_server_req(stream, packet).await, // Login Stuff PacketType::PakcsLoginTokenReq => auth::handle_login_req(stream, packet, auth_client, connection_service, connection_id, stream.peer_addr()?).await, PacketType::PakcsLogoutReq => auth::handle_logout_req(stream, packet, auth_client, connection_service, connection_id).await, PacketType::PakcsSrvSelectReq => auth::handle_server_select_req(stream, packet, connection_service, connection_id).await, PacketType::PakcsChannelListReq => auth::handle_channel_list_req(stream, packet).await, // Character Stuff PacketType::PakcsCharListReq => character::handle_char_list_req(stream, packet).await, // 1 => chat::handle_chat(packet).await?, // 2 => movement::handle_movement(packet).await?, _ => { warn!("Unhandled packet type: {:?}", packet.packet_type); Ok(()) }, } }