Skip to content

Commit

Permalink
Require both aura and aura owner references to be valid for auras
Browse files Browse the repository at this point in the history
  • Loading branch information
Shauren committed Mar 14, 2024
1 parent 480875c commit bd6de45
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ElunaTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ class ElunaObjectImpl : public ElunaObject
TRACKABLE_PTR_NAMESPACE unique_weak_ptr<T> _obj;
};

template <>
class ElunaObjectImpl<Aura> : public ElunaObject
{
public:
ElunaObjectImpl(Eluna* E, Aura* obj, char const* tname);

void* GetObj() const override { return _obj.lock().get(); }
bool IsValid() const override
{
// aura references are not invalidated when their owner (player) changes map
// owner reference must be checked additionally to ensure scripts don't store
// and access auras of players on another map (possibly updating in another thread)
return !_obj.expired() && !_owner.expired();
}

private:
TRACKABLE_PTR_NAMESPACE unique_weak_ptr<Aura> _obj;
TRACKABLE_PTR_NAMESPACE unique_weak_ptr<WorldObject> _owner;
};

template <typename T>
class ElunaObjectValueImpl : public ElunaObject
{
Expand Down
5 changes: 5 additions & 0 deletions LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ TRACKABLE_PTR_NAMESPACE unique_weak_ptr<Spell> GetWeakPtrFor(Spell const* obj) {
TRACKABLE_PTR_NAMESPACE unique_weak_ptr<Vehicle> GetWeakPtrFor(Vehicle const* obj) { return obj->GetWeakPtr(); }
#endif

ElunaObjectImpl<Aura>::ElunaObjectImpl(Eluna* E, Aura* obj, char const* tname) : ElunaObject(E, tname),
_obj(GetWeakPtrFor(obj)), _owner(GetWeakPtrFor(obj->GetOwner()))
{
}

// Template by Mud from http://stackoverflow.com/questions/4484437/lua-integer-type/4485511#4485511
template<> int ElunaTemplate<unsigned long long>::Add(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<unsigned long long>(1) + E->CHECKVAL<unsigned long long>(2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Substract(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<unsigned long long>(1) - E->CHECKVAL<unsigned long long>(2)); return 1; }
Expand Down

0 comments on commit bd6de45

Please sign in to comment.