Skip to content

Commit

Permalink
fix: crash with non-existing azthGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehonal committed Jun 15, 2021
1 parent 485de52 commit d2c2928
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions modules/mod-as-platform/src/AZTH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down
16 changes: 12 additions & 4 deletions modules/mod-playerstats/src/scripts/PlayerStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Group.h"
#include "Player.h"
#include "AZTH.h"
#include "AzthGroupMgr.h"

uint32 AzthPlayer::normalizeLvl(uint32 level)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions modules/mod-timewalking/src/scripts/AzthTimewalkingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Pet.h"
#include "Spell.h"
#include "AZTH.h"
#include "AzthGroupMgr.h"

class Spell;

Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit d2c2928

Please sign in to comment.