Skip to content

Commit

Permalink
Merge pull request #65 from Xunjin/improve/handle-set-action-button-c…
Browse files Browse the repository at this point in the history
…lient-opcode

Improve/handle set action button client opcode
  • Loading branch information
Victov authored Dec 30, 2023
2 parents e88d893 + 22f6d84 commit 2f9fd05
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion world_server/src/character/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bit_field::BitField;
use std::collections::HashMap;
use std::sync::{Arc, Weak};
use wow_world_messages::wrath::{
Area, Class, Gender, Map, MovementInfo, ObjectType, Power, Race, RelationType, UnitStandState, UpdateMask, UpdatePlayer,
ActionButton, Area, Class, Gender, Map, MovementInfo, ObjectType, Power, Race, RelationType, UnitStandState, UpdateMask, UpdatePlayer,
};
use wrath_realm_db::RealmDatabase;

Expand Down Expand Up @@ -211,6 +211,10 @@ impl Character {
self.gameplay_data.set_player_features(a, b, action_bars, d);
}

pub fn set_action_bar_button(&mut self, slot: u8, action_button: ActionButton) {
self.action_bar.set_action_button(slot as usize, action_button);
}

fn set_rested_bytes(&mut self, rested: bool) -> Result<()> {
let _value = match rested {
true => 1,
Expand Down
4 changes: 4 additions & 0 deletions world_server/src/data/action_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ impl ActionBar {
data: [ActionButton::default(); MAXSLOTS],
}
}

pub fn set_action_button(&mut self, slot: usize, action_button: ActionButton) {
self.data[slot] = action_button;
}
}
17 changes: 16 additions & 1 deletion world_server/src/handlers/bars_buttons_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use wow_world_messages::wrath::CMSG_SET_ACTIONBAR_TOGGLES;
use wow_world_messages::wrath::{ActionButton, CMSG_SET_ACTIONBAR_TOGGLES, CMSG_SET_ACTION_BUTTON};

use crate::client_manager::ClientManager;
use crate::prelude::*;
Expand All @@ -12,3 +12,18 @@ pub async fn handle_csmg_set_actionbar_toggles(client_manager: &ClientManager, c
character.set_visible_actionbar_mask(action_bar);
Ok(())
}

pub async fn handle_cmsg_set_action_button(client_manager: &ClientManager, client_id: u64, packet: &CMSG_SET_ACTION_BUTTON) -> Result<()> {
let client = client_manager.get_authenticated_client(client_id).await?;
let character_lock = client.get_active_character().await?;
let button_slot = packet.button;
let action_button = ActionButton {
action: packet.action,
action_type: packet.action_type,
misc: packet.misc,
};

let mut character = character_lock.write().await;
character.set_action_bar_button(button_slot, action_button);
Ok(())
}
1 change: 1 addition & 0 deletions world_server/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use account_data_handler::handle_csmg_update_account_data;
pub use account_data_handler::send_character_account_data_times;

mod bars_buttons_handler;
pub use bars_buttons_handler::handle_cmsg_set_action_button;
pub use bars_buttons_handler::handle_csmg_set_actionbar_toggles;

mod character_handler;
Expand Down
1 change: 1 addition & 0 deletions world_server/src/packet_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl PacketHandler {
ClientOpcodeMessage::CMSG_SWAP_INV_ITEM(data) => handle_cmsg_swap_inv_item(client_manager, world, packet.client_id, data).await,
ClientOpcodeMessage::CMSG_AUTOEQUIP_ITEM(data) => handle_cmsg_autoequip_item(client_manager, world, packet.client_id, data).await,
ClientOpcodeMessage::CMSG_MESSAGECHAT(data) => handle_cmsg_messagechat(client_manager, world, packet.client_id, data).await,
ClientOpcodeMessage::CMSG_SET_ACTION_BUTTON(data) => handle_cmsg_set_action_button(client_manager, packet.client_id, data).await,
_ => bail!("Unhandled opcode"),
}
}
Expand Down

0 comments on commit 2f9fd05

Please sign in to comment.