- fix: character service to compile issues with new packet structure

This commit is contained in:
2025-01-05 22:17:12 -05:00
parent 2153583813
commit f8243fe68c
2 changed files with 12 additions and 8 deletions

View File

@@ -18,12 +18,11 @@ use crate::connection_service::ConnectionService;
use crate::packets::cli_create_char_req::CliCreateCharReq;
use crate::packets::cli_delete_char_req::CliDeleteCharReq;
use crate::packets::cli_select_char_req::CliSelectCharReq;
use crate::packets::srv_char_list_reply::{CharInfo, EquippedItem, SrvCharListReply};
use crate::packets::srv_create_char_reply::SrvCreateCharReply;
use crate::packets::srv_delete_char_reply::SrvDeleteCharReply;
use crate::packets::srv_select_char_reply::SrvSelectCharReply;
pub(crate) async fn handle_char_list_req(stream: &mut TcpStream, packet: Packet, character_client: Arc<Mutex<CharacterClient>>, connection_service: Arc<ConnectionService>, connection_id: String) -> Result<(), Box<dyn Error + Send + Sync>> {
use crate::packets::srv_char_list_reply::*;
let request = CliCharListReq::decode(packet.payload.as_slice());
debug!("{:?}", request);
@@ -123,6 +122,8 @@ pub(crate) async fn handle_delete_char_req(stream: &mut TcpStream, packet: Packe
}
pub(crate) async fn handle_select_char_req(stream: &mut TcpStream, packet: Packet, character_client: Arc<Mutex<CharacterClient>>, connection_service: Arc<ConnectionService>, connection_id: String) -> Result<(), Box<dyn Error + Send + Sync>> {
use crate::packets::srv_select_char_reply::*;
use crate::types::{HotbarItem, StatusEffect};
let request = CliSelectCharReq::decode(packet.payload.as_slice())?;
debug!("{:?}", request);
@@ -134,6 +135,9 @@ pub(crate) async fn handle_select_char_req(stream: &mut TcpStream, packet: Packe
let mut character_client = character_client.lock().await;
// character_client.get_character(&user_id.to_string(), request.char_id);
let mut equipped_item_list: [EquippedItem; (MAX_VISIBLE_ITEMS as usize)] = core::array::from_fn(|i| EquippedItem::default());
let mut effect_list: [StatusEffect; (MAX_STATUS_EFFECTS as usize)] = core::array::from_fn(|i| StatusEffect::default());
let mut hotbar_list: [HotbarItem; (MAX_HOTBAR_ITEMS as usize)] = core::array::from_fn(|i| HotbarItem::default());
let data = SrvSelectCharReply {
race: 0,
map: 0,
@@ -142,7 +146,7 @@ pub(crate) async fn handle_select_char_req(stream: &mut TcpStream, packet: Packe
spawn: 0,
body_face: 0,
body_hair: 0,
equipped_items: vec![],
equipped_items: equipped_item_list,
stone: 0,
face: 0,
hair: 0,
@@ -172,11 +176,11 @@ pub(crate) async fn handle_select_char_req(stream: &mut TcpStream, packet: Packe
guild_rank: 0,
pk_flag: 0,
stamina: 0,
effects: vec![],
effects: effect_list,
pat_hp: 0,
pat_cooldown_time: 0,
skills: [0u16; (MAX_SKILL_COUNT as usize)],
hotbar: vec![],
hotbar: hotbar_list,
tag: 0,
name: request.name,
};

View File

@@ -2,21 +2,21 @@ use std::time::{Duration};
use bincode::{Encode, Decode};
// `HotbarItem` structure converted to Rust.
#[derive(Debug, Clone, Copy, Encode, Decode)]
#[derive(Debug, Clone, Copy, Encode, Decode, Default)]
pub(crate) struct HotbarItem {
type_: u8,
slot_id: u16,
}
// `Skill` structure converted to Rust.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode, Default)]
pub(crate) struct Skill {
id: u16,
level: u8,
}
// `StatusEffect` structure converted to Rust.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode, Default)]
pub(crate) struct StatusEffect {
expired: Duration,
value: u16,