diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2009-12-06 18:58:50 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2009-12-06 19:00:24 +0100 |
commit | 232792634184759eec072782be875cb0f31b7247 (patch) | |
tree | 9c3bf65f3429d37d88247343ab82d6ff68a8cfd3 /src | |
parent | c0a5b22aa8f90c3d5de4a4b7495cf157d9a189d1 (diff) | |
download | manaserv-232792634184759eec072782be875cb0f31b7247.tar.gz manaserv-232792634184759eec072782be875cb0f31b7247.tar.bz2 manaserv-232792634184759eec072782be875cb0f31b7247.tar.xz manaserv-232792634184759eec072782be875cb0f31b7247.zip |
Fixed crash when an invalid status effect is requested
Log an error instead.
Diffstat (limited to 'src')
-rw-r--r-- | src/game-server/being.cpp | 23 | ||||
-rw-r--r-- | src/game-server/being.hpp | 4 | ||||
-rw-r--r-- | src/game-server/character.cpp | 2 |
3 files changed, 18 insertions, 11 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index a85cc974..e9b1e3c8 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -317,10 +317,17 @@ void Being::applyStatusEffect(int id, int timer) if (mAction == DEAD) return; - Status newStatus; - newStatus.status = StatusManager::getStatus(id); - newStatus.time = timer; - mStatus[id] = newStatus; + if (StatusEffect *statusEffect = StatusManager::getStatus(id)) + { + Status newStatus; + newStatus.status = statusEffect; + newStatus.time = timer; + mStatus[id] = newStatus; + } + else + { + LOG_ERROR("No status effect with ID " << id); + } } void Being::removeStatusEffect(int id) @@ -328,9 +335,9 @@ void Being::removeStatusEffect(int id) setStatusEffectTime(id, 0); } -bool Being::hasStatusEffect(int id) +bool Being::hasStatusEffect(int id) const { - StatusEffects::iterator it = mStatus.begin(); + StatusEffects::const_iterator it = mStatus.begin(); while (it != mStatus.end()) { if (it->second.status->getId() == id) @@ -340,9 +347,9 @@ bool Being::hasStatusEffect(int id) return false; } -unsigned Being::getStatusEffectTime(int id) +unsigned Being::getStatusEffectTime(int id) const { - StatusEffects::iterator it = mStatus.find(id); + StatusEffects::const_iterator it = mStatus.find(id); if (it != mStatus.end()) return it->second.time; else return 0; } diff --git a/src/game-server/being.hpp b/src/game-server/being.hpp index d0ca4be3..35c3bb62 100644 --- a/src/game-server/being.hpp +++ b/src/game-server/being.hpp @@ -308,12 +308,12 @@ class Being : public Actor /** * Returns true if the being has a status effect */ - bool hasStatusEffect(int id); + bool hasStatusEffect(int id) const; /** * Returns the time of the status effect if in effect, or 0 if not */ - unsigned getStatusEffectTime(int id); + unsigned getStatusEffectTime(int id) const; /** * Changes the time of the status effect (if in effect) diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index f351edb3..99a6bcfd 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -126,7 +126,7 @@ void Character::update() mStatusEffects.clear(); StatusEffects::iterator it = mStatus.begin(); - while(it != mStatus.end()) + while (it != mStatus.end()) { mStatusEffects[it->first] = it->second.time; it++; |