Skip to content

Commit

Permalink
fix: IC-139 - fixed output for VALUES block type (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-ivanuzzo authored Sep 9, 2024
1 parent a85a460 commit 1f1f7e4
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.3"
tentacli-traits = "8.1.0"
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"] }
Expand Down
96 changes: 82 additions & 14 deletions src/features/wotlk_realm/player/handle_update_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,14 @@ impl PacketHandler for Handler {
async fn handle(&mut self, input: &mut HandlerInput) -> HandlerResult {
let mut response = Vec::new();

let (UpdateDataIncoming { blocks, .. }, json) = if input.opcode == Opcode::SMSG_UPDATE_OBJECT {
UpdateDataIncoming::from_binary(&input.data)?
} else {
UpdateDataIncoming::from_compressed_binary(&input.data)?
let (UpdateDataIncoming { blocks, blocks_amount }, _) = {
if input.opcode == Opcode::SMSG_UPDATE_OBJECT {
UpdateDataIncoming::from_binary(&input.data)?
} else {
UpdateDataIncoming::from_compressed_binary(&input.data)?
}
};

response.push(HandlerOutput::ResponseMessage(
Opcode::get_opcode_name(input.opcode as u32)
.unwrap_or(format!("Unknown opcode: {}", input.opcode)),
Some(json),
));

if input.session.lock().await.me.is_none() {
response.push(HandlerOutput::ErrorMessage(
"Session player was not initialized ?!!".to_string(),
Expand All @@ -128,10 +124,11 @@ impl PacketHandler for Handler {
input.session.lock().await.me.as_ref().unwrap().guid
};

for block in blocks {
if block.guid == 0 {
continue;
}
let mut refined_blocks: Vec<Block> = vec![];

for mut block in blocks {
let mut update_data = UpdateData::default();
let cloned_block = block.clone();

let PackedGuid(guid) = block.guid;

Expand All @@ -140,6 +137,7 @@ impl PacketHandler for Handler {
{
match mask {
m if m & ObjectTypeMask::PLAYER != 0 => {
update_data = block.update_data.clone();
let mut object = Player {
update_data: block.update_data,
guid,
Expand All @@ -158,6 +156,7 @@ impl PacketHandler for Handler {
guard.players_map.insert(guid, object);
},
m if m & ObjectTypeMask::UNIT != 0 => {
update_data = block.update_data.clone();
let mut object = Unit {
update_data: block.update_data,
guid,
Expand All @@ -170,6 +169,7 @@ impl PacketHandler for Handler {
guard.units_map.insert(guid, object);
},
m if m & ObjectTypeMask::GAMEOBJECT != 0 => {
update_data = block.update_data.clone();
let mut object = GameObject {
update_data: block.update_data,
guid,
Expand All @@ -182,6 +182,7 @@ impl PacketHandler for Handler {
guard.game_objects_map.insert(guid, object);
},
m if m & ObjectTypeMask::DYNAMICOBJECT != 0 => {
update_data = block.update_data.clone();
let mut object = DynamicObject {
update_data: block.update_data,
guid,
Expand All @@ -194,6 +195,7 @@ impl PacketHandler for Handler {
guard.dynamic_objects_map.insert(guid, object);
},
m if m & ObjectTypeMask::ITEM != 0 => {
update_data = block.update_data.clone();
if let Some(FieldValue::Long(guid)) =
block.update_data.item_fields.get(&ItemField::Owner)
{
Expand All @@ -216,6 +218,7 @@ impl PacketHandler for Handler {
guard.items_map.insert(guid, object);
},
m if m & ObjectTypeMask::CONTAINER != 0 => {
update_data = block.update_data.clone();
if let Some(FieldValue::Long(guid)) =
block.update_data.item_fields.get(&ItemField::Owner)
{
Expand All @@ -238,6 +241,7 @@ impl PacketHandler for Handler {
guard.containers_map.insert(guid, object);
},
m if m & ObjectTypeMask::CORPSE != 0 => {
update_data = block.update_data.clone();
let mut object = Corpse {
update_data: block.update_data,
guid,
Expand All @@ -251,9 +255,73 @@ impl PacketHandler for Handler {
}
_ => {},
}
} else {
let mut guard = input.data_storage.lock().unwrap();

match guid {
g if guard.players_map.contains_key(&g) => {
guard.players_map.entry(guid).and_modify(|o| {
o.update_data.extend_or_clear_source(&mut block.update_data);
update_data = block.update_data.clone();
});
},
g if guard.units_map.contains_key(&g) => {
guard.units_map.entry(guid).and_modify(|o| {
o.update_data.extend_or_clear_source(&mut block.update_data);
update_data = block.update_data.clone();
});
},
g if guard.game_objects_map.contains_key(&g) => {
guard.game_objects_map.entry(guid).and_modify(|o| {
o.update_data.extend_or_clear_source(&mut block.update_data);
update_data = block.update_data.clone();
});
},
g if guard.dynamic_objects_map.contains_key(&g) => {
guard.dynamic_objects_map.entry(guid).and_modify(|o| {
o.update_data.extend_or_clear_source(&mut block.update_data);
update_data = block.update_data.clone();
});
},
g if guard.items_map.contains_key(&g) => {
guard.items_map.entry(guid).and_modify(|o| {
o.update_data.extend_or_clear_source(&mut block.update_data);
update_data = block.update_data.clone();
});
},
g if guard.containers_map.contains_key(&g) => {
guard.containers_map.entry(guid).and_modify(|o| {
o.update_data.extend_or_clear_source(&mut block.update_data);
update_data = block.update_data.clone();
});
},
g if guard.corpses_map.contains_key(&g) => {
guard.corpses_map.entry(guid).and_modify(|o| {
o.update_data.extend_or_clear_source(&mut block.update_data);
update_data = block.update_data.clone();
});
},
_ => {},
}
}

refined_blocks.push(Block {
update_data,
..cloned_block
});
}

let json = UpdateDataIncoming {
blocks_amount,
blocks: refined_blocks,
}.get_json_details()?;

response.push(HandlerOutput::ResponseMessage(
Opcode::get_opcode_name(input.opcode as u32)
.unwrap_or(format!("Unknown opcode: {}", input.opcode)),
Some(json),
));

Ok(response)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/primary/traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tentacli-traits"
version = "8.0.3"
version = "8.1.0"
edition = "2021"
authors = ["Sergio Ivanuzzo <[email protected]>"]
description = "Traits and types for tentacli and related projects"
Expand Down
Loading

0 comments on commit 1f1f7e4

Please sign in to comment.