Skip to content

Commit

Permalink
fix: player "client" validation to avoid addEvent crash (#1249)
Browse files Browse the repository at this point in the history
"player:reloadData" is called in an addEvent, which calls these functions and because it is not validating the "client" ends up crashing if you try to access a client that no longer exists.
  • Loading branch information
dudantas authored Jul 17, 2023
1 parent 6c98c45 commit 5a0cb00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/creatures/players/wheel/player_wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ int PlayerWheel::getSpellAdditionalDuration(const std::string &spellName) const
}

void PlayerWheel::sendOpenWheelWindow(NetworkMessage &msg, uint32_t ownerId) const {
if (m_player.client->oldProtocol) {
if (m_player.client && m_player.client->oldProtocol) {
return;
}

Expand All @@ -719,7 +719,7 @@ void PlayerWheel::sendOpenWheelWindow(NetworkMessage &msg, uint32_t ownerId) con
}

void PlayerWheel::sendGiftOfLifeCooldown() const {
if (m_player.client->oldProtocol) {
if (!m_player.client || m_player.client->oldProtocol) {
return;
}

Expand Down Expand Up @@ -772,7 +772,7 @@ void PlayerWheel::saveSlotPointsHandleRetryErrors(std::vector<SlotInfo> &retryTa
}

void PlayerWheel::saveSlotPointsOnPressSaveButton(NetworkMessage &msg) {
if (m_player.client->oldProtocol) {
if (m_player.client && m_player.client->oldProtocol) {
return;
}

Expand Down Expand Up @@ -1025,7 +1025,7 @@ void PlayerWheel::resetPlayerBonusData() {
}

void PlayerWheel::initializePlayerData() {
if (m_player.client->oldProtocol) {
if (m_player.client && m_player.client->oldProtocol) {
return;
}

Expand Down
6 changes: 4 additions & 2 deletions src/creatures/players/wheel/wheel_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#ifndef SRC_CREATURES_PLAYERS_WHEEL_PLAYER_WHEEL_DEFINITIONS_HPP_
#define SRC_CREATURES_PLAYERS_WHEEL_PLAYER_WHEEL_DEFINITIONS_HPP_

#include "creatures/creatures_definitions.hpp"

enum WheelSlots_t : uint8_t {
SLOT_GREEN_200 = 1,
SLOT_GREEN_TOP_150 = 2,
Expand Down Expand Up @@ -195,8 +197,8 @@ struct PlayerWheelMethodsBonusData {
int damage = 0;
int healing = 0;
};
// value * 100. Example: 1% == 100, NOTE: the "12" is the "COMBAT_COUNT"
std::array<uint16_t, 12> resistance = {};
// value * 100. Example: 1% == 100
std::array<uint16_t, COMBAT_COUNT> resistance = {};

// Raw value. Example: 1 == 1
struct Skills {
Expand Down

0 comments on commit 5a0cb00

Please sign in to comment.