From d47d5f44b1cfc81626837cd57f80d26570070214264f094164a7a1a4be440543 Mon Sep 17 00:00:00 2001 From: raven <7156279+RavenX8@users.noreply.github.com> Date: Fri, 21 Mar 2025 23:24:32 -0400 Subject: [PATCH] - add: Not hardcoded object tag for the user when switching to the in game map --- packet-service/src/handlers/character.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packet-service/src/handlers/character.rs b/packet-service/src/handlers/character.rs index f8ca91b..e7c4a97 100644 --- a/packet-service/src/handlers/character.rs +++ b/packet-service/src/handlers/character.rs @@ -7,8 +7,6 @@ use crate::enums::ItemType; use crate::packet::{send_packet, Packet, PacketPayload}; use crate::packet_type::PacketType; use crate::packets::*; -use std::collections::HashMap; -use std::env; use std::error::Error; use std::sync::Arc; use tokio::net::TcpStream; @@ -16,6 +14,17 @@ use tokio::sync::Mutex; use tonic::{Code, Status}; use tracing::{debug, error, info, warn}; use utils::null_string::NullTerminatedString; +use std::hash::{Hash, Hasher}; +use std::collections::hash_map::DefaultHasher; + + +fn string_to_u32(s: &str) -> u32 { + let mut hasher = DefaultHasher::new(); + s.hash(&mut hasher); + // Convert the 64-bit hash to a 32-bit number. + // Note: This cast might lead to collisions if there are a lot of objects, + hasher.finish() as u32 +} pub(crate) fn convert_slot_to_equip_slot(slot: i32) -> srv_char_list_reply::EquippedPosition { match enums::EquippedPosition::from_i32(slot) { @@ -368,10 +377,9 @@ pub(crate) async fn handle_select_char_req( pat_cooldown_time: stats.pat_cooldown_time as u32, skills: skill_list, hotbar: hotbar_list, - tag: 100, + tag: string_to_u32(&user_id), name, }; - debug!("{:?}", data); let response_packet = Packet::new(PacketType::PakwcSelectCharReply, &data)?; send_packet(stream, &response_packet).await?;