From c236595cd71f99bd4935099b0659caf6b9e9b723 Mon Sep 17 00:00:00 2001 From: Sergio Ivanuzzo Date: Thu, 29 Aug 2024 02:46:14 +0200 Subject: [PATCH 1/2] fix: IC-136 - improved output of #[doc] for arrays of FieldValue (#96) * Update README.md (#83) * fixed clippy issues * fix: IC-136 - improved output of #[doc] for arrays of FieldValue --- Cargo.toml | 2 +- .../wotlk_realm/player/handle_update_data.rs | 208 +++++++++--------- src/primary/traits/Cargo.toml | 2 +- src/primary/traits/src/types/update_data.rs | 170 +++++++------- src/primary/traits/src/types/update_fields.rs | 6 +- 5 files changed, 191 insertions(+), 197 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f2c0591..1ca9405 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ sha-1 = { version = "0.9.8", optional = true } tentacli-crypto = "0.1.0" tentacli-formatters = "0.1.0" tentacli-packet = "7.0.0" -tentacli-traits = "8.0.0" +tentacli-traits = "8.0.2" tentacli-utils = "2.1.0" tokio = { version = "1", features = ["sync", "net", "io-util", "macros", "time", "rt-multi-thread"] } #tokio-util = { version = "0.7.10", features = ["io"] } diff --git a/src/features/wotlk_realm/player/handle_update_data.rs b/src/features/wotlk_realm/player/handle_update_data.rs index 8d7d429..44d8c15 100644 --- a/src/features/wotlk_realm/player/handle_update_data.rs +++ b/src/features/wotlk_realm/player/handle_update_data.rs @@ -135,121 +135,121 @@ impl PacketHandler for Handler { let PackedGuid(guid) = block.guid; - if let Some(object_type) = block.update_data.object_fields.get(&ObjectField::Type) { - if let FieldValue::Integer(mask) = object_type { - match mask { - m if m & ObjectTypeMask::PLAYER != 0 => { - let mut object = Player { - update_data: block.update_data, - guid, - ..Player::default() - }; - - object.movement = block.movement; - - if guid == my_guid { + if let Some(FieldValue::Integer(mask)) = + block.update_data.object_fields.get(&ObjectField::Type) + { + match mask { + m if m & ObjectTypeMask::PLAYER != 0 => { + let mut object = Player { + update_data: block.update_data, + guid, + ..Player::default() + }; + + object.movement = block.movement; + + if guid == my_guid { + let mut guard = input.session.lock().await; + let me = guard.me.as_mut().unwrap(); + *me = object.clone(); + } + + let mut guard = input.data_storage.lock().unwrap(); + guard.players_map.insert(guid, object); + }, + m if m & ObjectTypeMask::UNIT != 0 => { + let mut object = Unit { + update_data: block.update_data, + guid, + ..Unit::default() + }; + + object.movement = block.movement; + + let mut guard = input.data_storage.lock().unwrap(); + guard.units_map.insert(guid, object); + }, + m if m & ObjectTypeMask::GAMEOBJECT != 0 => { + let mut object = GameObject { + update_data: block.update_data, + guid, + ..GameObject::default() + }; + + object.movement = block.movement; + + let mut guard = input.data_storage.lock().unwrap(); + guard.game_objects_map.insert(guid, object); + }, + m if m & ObjectTypeMask::DYNAMICOBJECT != 0 => { + let mut object = DynamicObject { + update_data: block.update_data, + guid, + ..DynamicObject::default() + }; + + object.movement = block.movement; + + let mut guard = input.data_storage.lock().unwrap(); + guard.dynamic_objects_map.insert(guid, object); + }, + m if m & ObjectTypeMask::ITEM != 0 => { + if let Some(FieldValue::Long(guid)) = + block.update_data.item_fields.get(&ItemField::Owner) + { + if my_guid == *guid { let mut guard = input.session.lock().await; let me = guard.me.as_mut().unwrap(); - *me = object.clone(); - } - - let mut guard = input.data_storage.lock().unwrap(); - guard.players_map.insert(guid, object); - }, - m if m & ObjectTypeMask::UNIT != 0 => { - let mut object = Unit { - update_data: block.update_data, - guid, - ..Unit::default() - }; - - object.movement = block.movement; - - let mut guard = input.data_storage.lock().unwrap(); - guard.units_map.insert(guid, object); - }, - m if m & ObjectTypeMask::GAMEOBJECT != 0 => { - let mut object = GameObject { - update_data: block.update_data, - guid, - ..GameObject::default() - }; - - object.movement = block.movement; - - let mut guard = input.data_storage.lock().unwrap(); - guard.game_objects_map.insert(guid, object); - }, - m if m & ObjectTypeMask::DYNAMICOBJECT != 0 => { - let mut object = DynamicObject { - update_data: block.update_data, - guid, - ..DynamicObject::default() - }; - - object.movement = block.movement; - - let mut guard = input.data_storage.lock().unwrap(); - guard.dynamic_objects_map.insert(guid, object); - }, - m if m & ObjectTypeMask::ITEM != 0 => { - if let Some(owner) = block.update_data.item_fields.get(&ItemField::Owner) { - if let FieldValue::Long(guid) = owner { - if my_guid == *guid { - let mut guard = input.session.lock().await; - let me = guard.me.as_mut().unwrap(); - me.inventory.push(*guid); - } - } + me.inventory.push(*guid); } + } - let mut object = Item { - update_data: block.update_data, - guid, - ..Item::default() - }; - - object.movement = block.movement; - - let mut guard = input.data_storage.lock().unwrap(); - guard.items_map.insert(guid, object); - }, - m if m & ObjectTypeMask::CONTAINER != 0 => { - if let Some(owner) = block.update_data.item_fields.get(&ItemField::Owner) { - if let FieldValue::Long(guid) = owner { - if my_guid == *guid { - let mut guard = input.session.lock().await; - let me = guard.me.as_mut().unwrap(); - me.inventory.push(*guid); - } - } + let mut object = Item { + update_data: block.update_data, + guid, + ..Item::default() + }; + + object.movement = block.movement; + + let mut guard = input.data_storage.lock().unwrap(); + guard.items_map.insert(guid, object); + }, + m if m & ObjectTypeMask::CONTAINER != 0 => { + if let Some(FieldValue::Long(guid)) = + block.update_data.item_fields.get(&ItemField::Owner) + { + if my_guid == *guid { + let mut guard = input.session.lock().await; + let me = guard.me.as_mut().unwrap(); + me.inventory.push(*guid); } + } - let mut object = Container { - update_data: block.update_data, - guid, - ..Container::default() - }; + let mut object = Container { + update_data: block.update_data, + guid, + ..Container::default() + }; - object.movement = block.movement; + object.movement = block.movement; - let mut guard = input.data_storage.lock().unwrap(); - guard.containers_map.insert(guid, object); - }, - m if m & ObjectTypeMask::CORPSE != 0 => { - let mut object = Corpse { - update_data: block.update_data, - guid, - ..Corpse::default() - }; + let mut guard = input.data_storage.lock().unwrap(); + guard.containers_map.insert(guid, object); + }, + m if m & ObjectTypeMask::CORPSE != 0 => { + let mut object = Corpse { + update_data: block.update_data, + guid, + ..Corpse::default() + }; - object.movement = block.movement; + object.movement = block.movement; - let mut guard = input.data_storage.lock().unwrap(); - guard.corpses_map.insert(guid, object); - } - _ => {}, + let mut guard = input.data_storage.lock().unwrap(); + guard.corpses_map.insert(guid, object); } + _ => {}, } } } diff --git a/src/primary/traits/Cargo.toml b/src/primary/traits/Cargo.toml index 72f9f26..73b0a72 100644 --- a/src/primary/traits/Cargo.toml +++ b/src/primary/traits/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tentacli-traits" -version = "8.0.0" +version = "8.0.2" edition = "2021" authors = ["Sergio Ivanuzzo "] description = "Traits and types for tentacli and related projects" diff --git a/src/primary/traits/src/types/update_data.rs b/src/primary/traits/src/types/update_data.rs index 82deb7c..1dc1bc9 100644 --- a/src/primary/traits/src/types/update_data.rs +++ b/src/primary/traits/src/types/update_data.rs @@ -206,98 +206,96 @@ impl BinaryConverter for UpdateData { let mut container_fields: BTreeMap = BTreeMap::default(); let mut corpse_fields: BTreeMap = BTreeMap::default(); - if let Some(object_type) = object_fields.get(&ObjectField::Type) { - if let FieldValue::Integer(mask) = object_type { - if mask & ObjectTypeMask::PLAYER != 0 { - let blocks = Self::build_blocks( - &update_blocks, - UnitField::get_limit() + 1, - PlayerField::get_limit() - ); - - player_fields = PlayerField::read_from( - blocks.values().copied().collect::>(), - &mut update_mask - )?; - } + if let Some(FieldValue::Integer(mask)) = object_fields.get(&ObjectField::Type) { + if mask & ObjectTypeMask::PLAYER != 0 { + let blocks = Self::build_blocks( + &update_blocks, + UnitField::get_limit() + 1, + PlayerField::get_limit() + ); + + player_fields = PlayerField::read_from( + blocks.values().copied().collect::>(), + &mut update_mask + )?; + } - if mask & ObjectTypeMask::UNIT != 0 { - let blocks = Self::build_blocks( - &update_blocks, - ObjectField::get_limit() + 1, - UnitField::get_limit() - ); - - unit_fields = UnitField::read_from( - blocks.values().copied().collect::>(), - &mut update_mask - )?; - } + if mask & ObjectTypeMask::UNIT != 0 { + let blocks = Self::build_blocks( + &update_blocks, + ObjectField::get_limit() + 1, + UnitField::get_limit() + ); + + unit_fields = UnitField::read_from( + blocks.values().copied().collect::>(), + &mut update_mask + )?; + } - if mask & ObjectTypeMask::GAMEOBJECT != 0 { - let blocks = Self::build_blocks( - &update_blocks, - ObjectField::get_limit() + 1, - GameObjectField::get_limit() - ); - - game_object_fields = GameObjectField::read_from( - blocks.values().copied().collect::>(), - &mut update_mask - )?; - } + if mask & ObjectTypeMask::GAMEOBJECT != 0 { + let blocks = Self::build_blocks( + &update_blocks, + ObjectField::get_limit() + 1, + GameObjectField::get_limit() + ); + + game_object_fields = GameObjectField::read_from( + blocks.values().copied().collect::>(), + &mut update_mask + )?; + } - if mask & ObjectTypeMask::DYNAMICOBJECT != 0 { - let blocks = Self::build_blocks( - &update_blocks, - ObjectField::get_limit() + 1, - DynamicObjectField::get_limit() - ); - - dynamic_object_fields = DynamicObjectField::read_from( - blocks.values().copied().collect::>(), - &mut update_mask - )?; - } + if mask & ObjectTypeMask::DYNAMICOBJECT != 0 { + let blocks = Self::build_blocks( + &update_blocks, + ObjectField::get_limit() + 1, + DynamicObjectField::get_limit() + ); + + dynamic_object_fields = DynamicObjectField::read_from( + blocks.values().copied().collect::>(), + &mut update_mask + )?; + } - if mask & ObjectTypeMask::ITEM != 0 { - let blocks = Self::build_blocks( - &update_blocks, - ObjectField::get_limit() + 1, - ItemField::get_limit() - ); - - item_fields = ItemField::read_from( - blocks.values().copied().collect::>(), - &mut update_mask - )?; - } + if mask & ObjectTypeMask::ITEM != 0 { + let blocks = Self::build_blocks( + &update_blocks, + ObjectField::get_limit() + 1, + ItemField::get_limit() + ); + + item_fields = ItemField::read_from( + blocks.values().copied().collect::>(), + &mut update_mask + )?; + } - if mask & ObjectTypeMask::CONTAINER != 0 { - let blocks = Self::build_blocks( - &update_blocks, - ItemField::get_limit() + 1, - ContainerField::get_limit() - ); - - container_fields = ContainerField::read_from( - blocks.values().copied().collect::>(), - &mut update_mask - )?; - } + if mask & ObjectTypeMask::CONTAINER != 0 { + let blocks = Self::build_blocks( + &update_blocks, + ItemField::get_limit() + 1, + ContainerField::get_limit() + ); + + container_fields = ContainerField::read_from( + blocks.values().copied().collect::>(), + &mut update_mask + )?; + } - if mask & ObjectTypeMask::CORPSE != 0 { - let blocks = Self::build_blocks( - &update_blocks, - ObjectField::get_limit() + 1, - CorpseField::get_limit() - ); - - corpse_fields = CorpseField::read_from( - blocks.values().copied().collect::>(), - &mut update_mask - )?; - } + if mask & ObjectTypeMask::CORPSE != 0 { + let blocks = Self::build_blocks( + &update_blocks, + ObjectField::get_limit() + 1, + CorpseField::get_limit() + ); + + corpse_fields = CorpseField::read_from( + blocks.values().copied().collect::>(), + &mut update_mask + )?; } } diff --git a/src/primary/traits/src/types/update_fields.rs b/src/primary/traits/src/types/update_fields.rs index 6e0f605..137e111 100644 --- a/src/primary/traits/src/types/update_fields.rs +++ b/src/primary/traits/src/types/update_fields.rs @@ -4,8 +4,6 @@ use std::ops::Range; use core::slice::Iter; use serde::{Serialize}; -macro_rules! ignore {( $($ignored:expr)? ) => ( "" )} - #[macro_export] macro_rules! fields { ( @@ -24,12 +22,10 @@ macro_rules! fields { pub enum $enum_name { $( $(#[$variant_attr])* - // ignore! macro is a workaround to allow include "Array" string if $len param exists #[doc = concat!( stringify!(FieldValue::$field_type ), $( - ignore!($len), - "Array", + "Array(", stringify!($len), ")" )? )] $variant, From f9bd1308cb6f6508cf6aee596660f180116407df Mon Sep 17 00:00:00 2001 From: Sergio Ivanuzzo Date: Thu, 29 Aug 2024 02:48:17 +0200 Subject: [PATCH 2/2] new patch version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1ca9405..ab91f3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tentacli" -version = "14.0.0" +version = "14.0.1" edition = "2021" authors = ["Sergio Ivanuzzo "] description = "Console wow-client, it can be used either as a standalone application or integrated into your own project."