Skip to content

Commit

Permalink
fix: check spectator get player nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Sep 22, 2023
1 parent acc87b3 commit 0191a3d
Showing 1 changed file with 56 additions and 14 deletions.
70 changes: 56 additions & 14 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5736,7 +5736,12 @@ void Game::changeSpeed(std::shared_ptr<Creature> creature, int32_t varSpeedDelta
SpectatorHashSet spectators;
map.getSpectators(spectators, creature->getPosition(), false, true);
for (auto spectator : spectators) {
spectator->getPlayer()->sendChangeSpeed(creature, creature->getStepSpeed());
auto player = spectator->getPlayer();
if (!player) {
continue;
}

player->sendChangeSpeed(creature, creature->getStepSpeed());
}
}

Expand All @@ -5747,7 +5752,12 @@ void Game::setCreatureSpeed(std::shared_ptr<Creature> creature, int32_t speed) {
SpectatorHashSet spectators;
map.getSpectators(spectators, creature->getPosition(), false, true);
for (auto spectator : spectators) {
spectator->getPlayer()->sendChangeSpeed(creature, creature->getStepSpeed());
auto player = spectator->getPlayer();
if (!player) {
continue;
}

player->sendChangeSpeed(creature, creature->getStepSpeed());
}
}

Expand Down Expand Up @@ -5795,7 +5805,12 @@ void Game::internalCreatureChangeOutfit(std::shared_ptr<Creature> creature, cons
SpectatorHashSet spectators;
map.getSpectators(spectators, creature->getPosition(), true, true);
for (auto spectator : spectators) {
spectator->getPlayer()->sendCreatureChangeOutfit(creature, outfit);
auto player = spectator->getPlayer();
if (!player) {
continue;
}

player->sendCreatureChangeOutfit(creature, outfit);
}
}

Expand All @@ -5804,7 +5819,12 @@ void Game::internalCreatureChangeVisible(std::shared_ptr<Creature> creature, boo
SpectatorHashSet spectators;
map.getSpectators(spectators, creature->getPosition(), true, true);
for (auto spectator : spectators) {
spectator->getPlayer()->sendCreatureChangeVisible(creature, visible);
auto player = spectator->getPlayer();
if (!player) {
continue;
}

player->sendCreatureChangeVisible(creature, visible);
}
}

Expand All @@ -5813,7 +5833,12 @@ void Game::changeLight(std::shared_ptr<Creature> creature) {
SpectatorHashSet spectators;
map.getSpectators(spectators, creature->getPosition(), true, true);
for (auto spectator : spectators) {
spectator->getPlayer()->sendCreatureLight(creature);
auto player = spectator->getPlayer();
if (!player) {
continue;
}

player->sendCreatureLight(creature);
}
}

Expand All @@ -5822,7 +5847,12 @@ void Game::updateCreatureIcon(std::shared_ptr<Creature> creature) {
SpectatorHashSet spectators;
map.getSpectators(spectators, creature->getPosition(), true, true);
for (auto spectator : spectators) {
spectator->getPlayer()->sendCreatureIcon(creature);
auto player = spectator->getPlayer();
if (!player) {
continue;
}

player->sendCreatureIcon(creature);
}
}

Expand Down Expand Up @@ -6370,7 +6400,6 @@ bool Game::combatChangeHealth(std::shared_ptr<Creature> attacker, std::shared_pt
map.getSpectators(spectators, targetPos, false, true);
for (auto spectator : spectators) {
auto tmpPlayer = spectator->getPlayer();

if (!tmpPlayer) {
continue;
}
Expand Down Expand Up @@ -6794,7 +6823,7 @@ void Game::sendMessages(

for (std::shared_ptr<Creature> spectator : spectators) {
std::shared_ptr<Player> tmpPlayer = spectator->getPlayer();
if (tmpPlayer->getPosition().z != targetPos.z) {
if (!tmpPlayer || tmpPlayer->getPosition().z != targetPos.z) {
continue;
}

Expand Down Expand Up @@ -7041,7 +7070,6 @@ bool Game::combatChangeMana(std::shared_ptr<Creature> attacker, std::shared_ptr<
map.getSpectators(spectators, targetPos, false, true);
for (auto spectator : spectators) {
auto tmpPlayer = spectator->getPlayer();

if (!tmpPlayer) {
continue;
}
Expand Down Expand Up @@ -7141,7 +7169,6 @@ bool Game::combatChangeMana(std::shared_ptr<Creature> attacker, std::shared_ptr<
map.getSpectators(spectators, targetPos, false, true);
for (auto spectator : spectators) {
auto tmpPlayer = spectator->getPlayer();

if (!tmpPlayer) {
continue;
}
Expand Down Expand Up @@ -7426,6 +7453,10 @@ void Game::updateCreatureWalkthrough(std::shared_ptr<Creature> creature) {
map.getSpectators(spectators, creature->getPosition(), true, true);
for (auto spectator : spectators) {
auto tmpPlayer = spectator->getPlayer();
if (!tmpPlayer) {
continue;
}

tmpPlayer->sendCreatureWalkthrough(creature, tmpPlayer->canWalkthroughEx(creature));
}
}
Expand All @@ -7438,15 +7469,25 @@ void Game::updateCreatureSkull(std::shared_ptr<Creature> creature) {
SpectatorHashSet spectators;
map.getSpectators(spectators, creature->getPosition(), true, true);
for (auto spectator : spectators) {
spectator->getPlayer()->sendCreatureSkull(creature);
auto player = spectator->getPlayer();
if (!player) {
continue;
}

player->sendCreatureSkull(creature);
}
}

void Game::updatePlayerShield(std::shared_ptr<Player> player) {
SpectatorHashSet spectators;
map.getSpectators(spectators, player->getPosition(), true, true);
for (auto spectator : spectators) {
spectator->getPlayer()->sendCreatureShield(player);
auto player = spectator->getPlayer();
if (!player) {
continue;
}

player->sendCreatureShield(player);
}
}

Expand Down Expand Up @@ -7603,11 +7644,12 @@ void Game::updatePlayerHelpers(std::shared_ptr<Player> player) {
SpectatorHashSet spectators;
map.getSpectators(spectators, player->getPosition(), true, true);
for (auto spectator : spectators) {
if (!spectator || !spectator->getPlayer()) {
auto specPlayer = spectator->getPlayer();
if (!specPlayer) {
continue;
}

spectator->getPlayer()->sendCreatureHelpers(player->getID(), helpers);
specPlayer->sendCreatureHelpers(player->getID(), helpers);
}
}

Expand Down

0 comments on commit 0191a3d

Please sign in to comment.