From d2c2928da9a762b254005929ce9346f40a4b6e65 Mon Sep 17 00:00:00 2001 From: Yehonal Date: Tue, 15 Jun 2021 11:52:29 +0200 Subject: [PATCH] fix: crash with non-existing azthGroup --- modules/mod-as-platform/src/AZTH.cpp | 5 +++++ .../mod-playerstats/src/scripts/PlayerStats.cpp | 16 ++++++++++++---- .../src/scripts/AzthTimewalkingUtils.cpp | 17 +++++++++-------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/modules/mod-as-platform/src/AZTH.cpp b/modules/mod-as-platform/src/AZTH.cpp index 11a182d..68f975e 100644 --- a/modules/mod-as-platform/src/AZTH.cpp +++ b/modules/mod-as-platform/src/AZTH.cpp @@ -159,6 +159,11 @@ AzthObject* AZTH::GetAZTHObject(Object* object) AzthGroupMgr* AZTH::GetAZTHGroup(Group* group) { + if (!group) + { + return nullptr; + } + if (!_groupStore.count(group)) { sLog->outError("AZTH::GetAZTHGroup - !_groupStore.count(group)"); diff --git a/modules/mod-playerstats/src/scripts/PlayerStats.cpp b/modules/mod-playerstats/src/scripts/PlayerStats.cpp index b369917..152616a 100644 --- a/modules/mod-playerstats/src/scripts/PlayerStats.cpp +++ b/modules/mod-playerstats/src/scripts/PlayerStats.cpp @@ -3,6 +3,7 @@ #include "Group.h" #include "Player.h" #include "AZTH.h" +#include "AzthGroupMgr.h" uint32 AzthPlayer::normalizeLvl(uint32 level) { @@ -48,11 +49,17 @@ uint32 AzthPlayer::getGroupLevel(bool normalize /*=true*/, bool checkInstance /* groupLevel = getInstanceLevel(normalize); } + Group *group = player->GetGroup(); - if (group && !groupLevel) + if (AzthGroupMgr *azthGroup = sAZTH->GetAZTHGroup(group); azthGroup) { + if (!azthGroup) + { + return 0; + } + // outworld party or limit case for dungeon - groupLevel = sAZTH->GetAZTHGroup(group)->levelMaxGroup; + groupLevel = azthGroup->levelMaxGroup; if (normalize) groupLevel = normalizeLvl(groupLevel); @@ -130,8 +137,9 @@ uint32 AzthPlayer::getGroupSize(bool checkInstance /*=true*/) if (!groupSize) { Group *group = player->GetGroup(); - if (group) - groupSize = sAZTH->GetAZTHGroup(group)->groupSize; // outworld party or limit case for dungeon + AzthGroupMgr *azthGroup = sAZTH->GetAZTHGroup(group); + if (azthGroup) + groupSize = azthGroup->groupSize; // outworld party or limit case for dungeon } return groupSize; diff --git a/modules/mod-timewalking/src/scripts/AzthTimewalkingUtils.cpp b/modules/mod-timewalking/src/scripts/AzthTimewalkingUtils.cpp index a60dbd0..2b223de 100644 --- a/modules/mod-timewalking/src/scripts/AzthTimewalkingUtils.cpp +++ b/modules/mod-timewalking/src/scripts/AzthTimewalkingUtils.cpp @@ -3,6 +3,7 @@ #include "Pet.h" #include "Spell.h" #include "AZTH.h" +#include "AzthGroupMgr.h" class Spell; @@ -197,29 +198,29 @@ bool AzthUtils::updateTwLevel(Player *player,Group *group) uint32 levelPlayer = sAZTH->GetAZTHPlayer(player)->isTimeWalking() ? sAZTH->GetAZTHPlayer(player)->GetTimeWalkingLevel() : player->getLevel(); - if (group) + if (AzthGroupMgr *azthGroup = sAZTH->GetAZTHGroup(group); azthGroup) { bool updated = false; - uint32 maxLevel = sAzthUtils->maxTwLevel(levelPlayer, sAZTH->GetAZTHGroup(group)->levelMaxGroup); + uint32 maxLevel = sAzthUtils->maxTwLevel(levelPlayer, azthGroup->levelMaxGroup); - if (maxLevel != sAZTH->GetAZTHGroup(group)->levelMaxGroup) + if (maxLevel != azthGroup->levelMaxGroup) { - sAZTH->GetAZTHGroup(group)->levelMaxGroup = maxLevel; + azthGroup->levelMaxGroup = maxLevel; updated = true; } - if (group->GetMembersCount() > sAZTH->GetAZTHGroup(group)->groupSize) + if (group->GetMembersCount() > azthGroup->groupSize) { - sAZTH->GetAZTHGroup(group)->groupSize = group->GetMembersCount(); + azthGroup->groupSize = group->GetMembersCount(); updated = true; } if (updated) { - std::string _slvl=sAzthUtils->getLevelInfo(sAZTH->GetAZTHGroup(group)->levelMaxGroup); + std::string _slvl=sAzthUtils->getLevelInfo(azthGroup->levelMaxGroup); std::string msg = sAzthLang->getf(AZTH_LANG_GROUP_LEVEL_REG,player, player->GetName().c_str(),_slvl.c_str(), group->GetMembersCount()); sAzthUtils->sendMessageToGroup(player, player->GetGroup(), msg.c_str()); - sAZTH->GetAZTHGroup(group)->saveToDb(); + azthGroup->saveToDb(); result = true; } }