- chore: ran cargo fix on the codebase
This commit is contained in:
@@ -21,7 +21,12 @@ pub struct PacketRouter {
|
||||
}
|
||||
|
||||
impl PacketRouter {
|
||||
pub async fn handle_connection(&self, stream: &mut TcpStream, pool: Arc<BufferPool>, connection_id: String) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
pub async fn handle_connection(
|
||||
&self,
|
||||
stream: &mut TcpStream,
|
||||
pool: Arc<BufferPool>,
|
||||
connection_id: String,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
ACTIVE_CONNECTIONS.inc();
|
||||
while let Some(mut buffer) = pool.acquire().await {
|
||||
// Read data into the buffer
|
||||
@@ -46,7 +51,8 @@ impl PacketRouter {
|
||||
Ok(packet) => {
|
||||
debug!("Parsed Packet: {:?}", packet);
|
||||
// Handle the parsed packet (route it, process it, etc.)
|
||||
self.route_packet(stream, packet, connection_id.clone()).await?;
|
||||
self.route_packet(stream, packet, connection_id.clone())
|
||||
.await?;
|
||||
}
|
||||
Err(e) => warn!("Failed to parse packet: {}", e),
|
||||
}
|
||||
@@ -67,28 +73,131 @@ impl PacketRouter {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn route_packet(&self, stream: &mut TcpStream, packet: Packet, connection_id: String) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
pub async fn route_packet(
|
||||
&self,
|
||||
stream: &mut TcpStream,
|
||||
packet: Packet,
|
||||
connection_id: String,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
debug!("Routing packet: {:?}", packet);
|
||||
match packet.packet_type {
|
||||
// Generic Server Packets
|
||||
PacketType::PakcsAlive => auth::handle_alive_req(stream, packet, self.auth_client.clone(), self.connection_service.clone(), connection_id).await,
|
||||
PacketType::PakcsAlive => {
|
||||
auth::handle_alive_req(
|
||||
stream,
|
||||
packet,
|
||||
self.auth_client.clone(),
|
||||
self.connection_service.clone(),
|
||||
connection_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
PacketType::PakcsAcceptReq => auth::handle_accept_req(stream, packet).await,
|
||||
PacketType::PakcsJoinServerTokenReq => auth::handle_join_server_req(stream, packet, self.auth_client.clone(), self.connection_service.clone(), connection_id).await,
|
||||
PacketType::PakcsJoinServerTokenReq => {
|
||||
auth::handle_join_server_req(
|
||||
stream,
|
||||
packet,
|
||||
self.auth_client.clone(),
|
||||
self.connection_service.clone(),
|
||||
connection_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
// Login Packets
|
||||
PacketType::PakcsLoginTokenReq => auth::handle_login_req(stream, packet, self.auth_client.clone(), self.connection_service.clone(), connection_id, stream.peer_addr()?).await,
|
||||
PacketType::PakcsLogoutReq => auth::handle_logout_req(stream, packet, self.auth_client.clone(), self.connection_service.clone(), connection_id).await,
|
||||
PacketType::PakcsSrvSelectReq => auth::handle_server_select_req(stream, packet, self.connection_service.clone(), connection_id).await,
|
||||
PacketType::PakcsLoginTokenReq => {
|
||||
auth::handle_login_req(
|
||||
stream,
|
||||
packet,
|
||||
self.auth_client.clone(),
|
||||
self.connection_service.clone(),
|
||||
connection_id,
|
||||
stream.peer_addr()?,
|
||||
)
|
||||
.await
|
||||
}
|
||||
PacketType::PakcsLogoutReq => {
|
||||
auth::handle_logout_req(
|
||||
stream,
|
||||
packet,
|
||||
self.auth_client.clone(),
|
||||
self.connection_service.clone(),
|
||||
connection_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
PacketType::PakcsSrvSelectReq => {
|
||||
auth::handle_server_select_req(
|
||||
stream,
|
||||
packet,
|
||||
self.connection_service.clone(),
|
||||
connection_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
PacketType::PakcsChannelListReq => auth::handle_channel_list_req(stream, packet).await,
|
||||
|
||||
// Character Packets
|
||||
PacketType::PakcsCharListReq => character::handle_char_list_req(stream, packet, self.character_client.clone(), self.connection_service.clone(), connection_id).await,
|
||||
PacketType::PakcsCreateCharReq => character::handle_create_char_req(stream, packet, self.character_client.clone(), self.connection_service.clone(), connection_id).await,
|
||||
PacketType::PakcsDeleteCharReq => character::handle_delete_char_req(stream, packet, self.character_client.clone(), self.connection_service.clone(), connection_id).await,
|
||||
PacketType::PakcsSelectCharReq => character::handle_select_char_req(stream, packet, self.character_client.clone(), self.connection_service.clone(), connection_id).await,
|
||||
PacketType::PakcsCharListReq => {
|
||||
character::handle_char_list_req(
|
||||
stream,
|
||||
packet,
|
||||
self.character_client.clone(),
|
||||
self.connection_service.clone(),
|
||||
connection_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
PacketType::PakcsCreateCharReq => {
|
||||
character::handle_create_char_req(
|
||||
stream,
|
||||
packet,
|
||||
self.character_client.clone(),
|
||||
self.connection_service.clone(),
|
||||
connection_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
PacketType::PakcsDeleteCharReq => {
|
||||
character::handle_delete_char_req(
|
||||
stream,
|
||||
packet,
|
||||
self.character_client.clone(),
|
||||
self.connection_service.clone(),
|
||||
connection_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
PacketType::PakcsSelectCharReq => {
|
||||
character::handle_select_char_req(
|
||||
stream,
|
||||
packet,
|
||||
self.character_client.clone(),
|
||||
self.connection_service.clone(),
|
||||
connection_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
// World Packets
|
||||
PacketType::PakcsChangeMapReq => world::handle_change_map_req(stream, packet, self.character_client.clone(), self.connection_service.clone(), connection_id).await,
|
||||
PacketType::PakcsMouseCmd => world::handle_mouse_cmd_req(stream, packet, self.connection_service.clone(), connection_id).await,
|
||||
PacketType::PakcsChangeMapReq => {
|
||||
world::handle_change_map_req(
|
||||
stream,
|
||||
packet,
|
||||
self.character_client.clone(),
|
||||
self.connection_service.clone(),
|
||||
connection_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
PacketType::PakcsMouseCmd => {
|
||||
world::handle_mouse_cmd_req(
|
||||
stream,
|
||||
packet,
|
||||
self.connection_service.clone(),
|
||||
connection_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
// 1 => chat::handle_chat(packet).await?,
|
||||
// 2 => movement::handle_movement(packet).await?,
|
||||
|
||||
Reference in New Issue
Block a user