Update RLVa to 1.4.0-compatible

This commit is contained in:
Siana Gearz
2012-01-25 21:11:33 +01:00
parent d385de9139
commit 7fec659979
31 changed files with 1637 additions and 322 deletions

View File

@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2009-2010, Kitty Barnett
* Copyright (c) 2009-2011, Kitty Barnett
*
* The source code in this file is provided to you under the terms of the
* GNU General Public License, version 2.0, but WITHOUT ANY WARRANTY;
@@ -20,6 +20,15 @@
#include "rlvdefines.h"
#include "rlvcommon.h"
#ifdef LL_WINDOWS
#pragma warning (push)
#pragma warning (disable : 4702) // warning C4702: unreachable code
#endif
#include <boost/variant.hpp>
#ifdef LL_WINDOWS
#pragma warning (pop)
#endif
// ============================================================================
// RlvAttachPtLookup class declaration
//
@@ -36,12 +45,13 @@
class RlvAttachPtLookup
{
public:
static LLViewerJointAttachment* getAttachPoint(S32 idxAttachPt);
static LLViewerJointAttachment* getAttachPoint(const std::string& strText);
static LLViewerJointAttachment* getAttachPoint(const LLInventoryItem* pItem);
static S32 getAttachPointIndex(std::string strText);
static S32 getAttachPointIndex(const LLViewerObject* pObj);
static S32 getAttachPointIndex(const LLViewerJointAttachment* pObj);
static S32 getAttachPointIndex(const LLViewerObject* pAttachObj);
static S32 getAttachPointIndex(const LLViewerJointAttachment* pAttachPt);
static S32 getAttachPointIndex(const LLInventoryCategory* pFolder);
static S32 getAttachPointIndex(const LLInventoryItem* pItem, bool fFollowLinks = true);
@@ -80,7 +90,7 @@ public:
bool hasLockedHUD() const { return m_fHasLockedHUD; }
// Returns TRUE if the attachment is RLV_LOCK_REMOVE locked
bool isLockedAttachment(const LLViewerObject* pObj) const;
bool isLockedAttachment(const LLViewerObject* pAttachObj) const;
// Returns TRUE if the attachment point is RLV_LOCK_REMOVE locked by anything other than idRlvObj
bool isLockedAttachmentExcept(const LLViewerObject* pObj, const LLUUID& idRlvObj) const;
// Returns TRUE if the attachment point is eLock type locked (RLV_LOCK_ANY = RLV_LOCK_ADD *or* RLV_LOCK_REMOVE)
@@ -276,10 +286,118 @@ protected:
extern RlvWearableLocks gRlvWearableLocks;
// ============================================================================
// RlvFolderLocks class declaration
//
class RlvFolderLocks : public LLSingleton<RlvFolderLocks>
{
friend class RlvLockedDescendentsCollector;
public:
RlvFolderLocks();
// Specifies the source of a folder lock
enum ELockSourceType
{
ST_ATTACHMENT = 0x01, ST_ATTACHMENTPOINT = 0x02, ST_FOLDER = 0x04, ST_ROOTFOLDER = 0x08,
ST_SHAREDPATH = 0x10, ST_WEARABLETYPE = 0x20, ST_NONE= 0x00, ST_MASK_ANY = 0xFF
};
typedef boost::variant<LLUUID, std::string, S32, LLWearableType::EType> lock_source_t;
typedef std::pair<ELockSourceType, lock_source_t> folderlock_source_t;
// Specifies options for the folder lock
enum ELockPermission { PERM_ALLOW = 0x1, PERM_DENY = 0x2, PERM_MASK_ANY = 0x3 };
enum ELockScope { SCOPE_NODE, SCOPE_SUBTREE } ;
protected:
struct folderlock_descr_t
{
LLUUID idRlvObj;
ERlvLockMask eLockType;
folderlock_source_t lockSource;
ELockPermission eLockPermission;
ELockScope eLockScope;
folderlock_descr_t(const LLUUID& rlvObj, ERlvLockMask lockType, folderlock_source_t source, ELockPermission perm, ELockScope scope);
bool operator ==(const folderlock_descr_t& rhs) const;
};
public:
// Adds an eLock type lock (held by idRlvObj) for the specified folder source (with ePerm and eScope lock options)
void addFolderLock(const folderlock_source_t& lockSource, ELockPermission ePerm, ELockScope eScope, const LLUUID& idRlvObj, ERlvLockMask eLockType);
// Returns TRUE if there is at least 1 non-detachable attachment as a result of a RLV_LOCK_REMOVE folder PERM_DENY lock
bool hasLockedAttachment() const;
// Returns TRUE if there is at least 1 eLock type PERM_DENY locked folder (RLV_LOCK_ANY = RLV_LOCK_ADD *or* RLV_LOCK_REMOVE)
bool hasLockedFolder(ERlvLockMask eLockTypeMask) const;
// Returns TRUE if the folder has a descendent folder lock with the specified charateristics
bool hasLockedFolderDescendent(const LLUUID& idFolder, int eSourceTypeMask, ELockPermission ePermMask,
ERlvLockMask eLockTypeMask, bool fCheckSelf) const;
// Returns TRUE if there is at least 1 non-removable wearable as a result of a RLV_LOCK_REMOVE folder PERM_DENY lock
bool hasLockedWearable() const;
// Returns TRUE if the attachment (specified by item UUID) is non-detachable as a result of a RLV_LOCK_REMOVE folder PERM_DENY lock
bool isLockedAttachment(const LLUUID& idItem) const;
// Returns TRUE if the folder is locked as a result of a RLV_LOCK_REMOVE folder PERM_DENY lock
bool isLockedFolder(const LLUUID& idFolder, ERlvLockMask eLock, int eSourceTypeMask = ST_MASK_ANY, folderlock_source_t* plockSource = NULL) const;
// Returns TRUE if the wearable (specified by item UUID) is non-removable as a result of a RLV_LOCK_REMOVE folder PERM_DENY lock
bool isLockedWearable(const LLUUID& idItem) const;
// Removes an eLock type lock (held by idRlvObj) for the specified folder source (with ePerm and eScope lock options)
void removeFolderLock(const folderlock_source_t& lockSource, ELockPermission ePerm, ELockScope eScope, const LLUUID& idRlvObj, ERlvLockMask eLockType);
protected:
// Returns TRUE if the folder has an explicit folder lock entry with the specified charateristics
bool isLockedFolderEntry(const LLUUID& idFolder, int eSourceTypeMask, ELockPermission ePermMask, ERlvLockMask eLockTypeMask) const;
/*
* canXXX helper functions (note that a more approriate name might be userCanXXX)
*/
public:
bool canMoveFolder(const LLUUID& idFolder, const LLUUID& idFolderDest) const;
bool canRemoveFolder(const LLUUID& idFolder) const;
bool canRenameFolder(const LLUUID& idFolder) const;
bool canMoveItem(const LLUUID& idItem, const LLUUID& idFolderDest) const;
bool canRemoveItem(const LLUUID& idItem) const;
bool canRenameItem(const LLUUID& idItem) const;
/*
* Cached item/folder look-up helper functions
*/
protected:
bool getLockedFolders(const folderlock_source_t& lockSource, LLInventoryModel::cat_array_t& lockFolders) const;
bool getLockedItems(const LLUUID& idFolder, LLInventoryModel::item_array_t& lockItems, bool fFollowLinks) const;
void onNeedsLookupRefresh();
void refreshLockedLookups() const;
/*
* Member variables
*/
protected:
// Map of folder locks (idRlvObj -> lockDescr)
typedef std::list<const folderlock_descr_t*> folderlock_list_t;
folderlock_list_t m_FolderLocks; // List of add and remove locked folder descriptions
S32 m_cntLockAdd; // Number of RLV_LOCK_ADD locked folders in m_FolderLocks
S32 m_cntLockRem; // Number of RLV_LOCK_REMOVE locked folders in m_FolderLocks
// Cached item look-up variables
typedef std::multimap<LLUUID, const folderlock_descr_t*> folderlock_map_t;
mutable bool m_fLookupDirty;
mutable bool m_fLockedRoot;
mutable uuid_vec_t m_LockedAttachmentRem;
mutable folderlock_map_t m_LockedFolderMap;
mutable uuid_vec_t m_LockedWearableRem;
private:
friend class LLSingleton<RlvFolderLocks>;
};
// ============================================================================
// RlvAttachPtLookup inlined member functions
//
// Checked: 2010-11-30 (RLVa-1.4.0b) | Added: RLVa-1.4.0b
inline LLViewerJointAttachment* RlvAttachPtLookup::getAttachPoint(S32 idxAttachPt)
{
return (isAgentAvatarValid()) ? get_if_there(gAgentAvatarp->mAttachmentPoints, idxAttachPt, (LLViewerJointAttachment*)NULL) : NULL;
}
// Checked: 2010-03-03 (RLVa-1.1.3a) | Modified: RLVa-0.2.0d
inline LLViewerJointAttachment* RlvAttachPtLookup::getAttachPoint(const std::string& strText)
{
@@ -311,7 +429,7 @@ inline S32 RlvAttachPtLookup::getAttachPointIndex(const LLViewerObject* pObj)
// RlvAttachmentLocks inlined member functions
//
// Checked: 2010-08-07 (RLVa-1.2.0i) | Modified: RLVa-1.2.0i
// Checked: 2011-03-27 (RLVa-1.3.0g) | Modified: RLVa-1.3.0g
inline ERlvWearMask RlvAttachmentLocks::canAttach(const LLInventoryItem* pItem, LLViewerJointAttachment** ppAttachPtOut /*=NULL*/) const
{
// The specified item can be attached if:
@@ -320,7 +438,8 @@ inline ERlvWearMask RlvAttachmentLocks::canAttach(const LLInventoryItem* pItem,
LLViewerJointAttachment* pAttachPt = RlvAttachPtLookup::getAttachPoint(pItem);
if (ppAttachPtOut)
*ppAttachPtOut = pAttachPt;
return (!pAttachPt) ? RLV_WEAR : canAttach(pAttachPt);
return ((pItem) && (!RlvFolderLocks::instance().isLockedFolder(pItem->getParentUUID(), RLV_LOCK_ADD)))
? ((!pAttachPt) ? RLV_WEAR : canAttach(pAttachPt)) : RLV_WEAR_LOCKED;
}
// Checked: 2010-08-07 (RLVa-1.2.0i) | Modified: RLVa-1.2.0i
@@ -345,28 +464,30 @@ inline bool RlvAttachmentLocks::canDetach(const LLInventoryItem* pItem) const
return (pAttachObj) && (!isLockedAttachment(pAttachObj));
}
// Checked: 2010-02-28 (RLVa-1.2.0a) | Modified: RLVa-1.2.0a
// Checked: 2010-11-30 (RLVa-1.3.0b) | Modified: RLVa-1.3.0b
inline bool RlvAttachmentLocks::hasLockedAttachmentPoint(ERlvLockMask eLock) const
{
// Remove locks are more common so check those first
return
( (eLock & RLV_LOCK_REMOVE) && ((!m_AttachPtRem.empty()) || (!m_AttachObjRem.empty())) ) ||
( (eLock & RLV_LOCK_ADD) && (!m_AttachPtAdd.empty()) );
((eLock & RLV_LOCK_REMOVE) && ((!m_AttachPtRem.empty()) || (!m_AttachObjRem.empty()) || (RlvFolderLocks::instance().hasLockedAttachment()))) ||
((eLock & RLV_LOCK_ADD) && (!m_AttachPtAdd.empty()) );
}
// Checked: 2010-02-28 (RLVa-1.2.0a) | Modified: RLVa-1.2.0a
inline bool RlvAttachmentLocks::isLockedAttachment(const LLViewerObject* pObj) const
// Checked: 2010-11-30 (RLVa-1.3.0b) | Modified: RLVa-1.3.0b
inline bool RlvAttachmentLocks::isLockedAttachment(const LLViewerObject* pAttachObj) const
{
// If pObj is valid then it should always specify a root since we store root UUIDs in m_AttachObjRem
RLV_ASSERT( (!pObj) || (pObj == pObj->getRootEdit()) );
RLV_ASSERT( (!pAttachObj) || (pAttachObj == pAttachObj->getRootEdit()) );
// Object is locked if:
// - it's specifically marked as non-detachable (ie @detach=n)
// - it's attached to an attachment point that is RLV_LOCK_REMOVE locked (ie @remattach:<attachpt>=n)
// - it's part of a locked folder
return
(pObj) && (pObj->isAttachment()) &&
( (m_AttachObjRem.find(pObj->getID()) != m_AttachObjRem.end()) ||
(isLockedAttachmentPoint(RlvAttachPtLookup::getAttachPointIndex(pObj), RLV_LOCK_REMOVE)) );
(pAttachObj) && (pAttachObj->isAttachment()) &&
( (m_AttachObjRem.find(pAttachObj->getID()) != m_AttachObjRem.end()) ||
(isLockedAttachmentPoint(RlvAttachPtLookup::getAttachPointIndex(pAttachObj), RLV_LOCK_REMOVE)) ||
(RlvFolderLocks::instance().isLockedAttachment(pAttachObj->getAttachmentItemID())) );
}
// Checked: 2010-02-28 (RLVa-1.2.0a) | Added: RLVa-1.0.5a
@@ -406,12 +527,13 @@ inline bool RlvWearableLocks::canRemove(const LLInventoryItem* pItem) const
return (pWearable) && (!isLockedWearable(pWearable));
}
// Checked: 2010-05-14 (RLVa-1.2.0g) | Modified: RLVa-1.2.0g
// Checked: 2011-03-27 (RLVa-1.3.0g) | Modified: RLVa-1.3.0g
inline ERlvWearMask RlvWearableLocks::canWear(const LLViewerInventoryItem* pItem) const
{
// The specified item can be worn if the wearable type it specifies can be worn on
RLV_ASSERT( (pItem) && (LLInventoryType::IT_WEARABLE == pItem->getInventoryType()) );
return (pItem) ? canWear(pItem->getWearableType()) : RLV_WEAR_LOCKED;
return ((pItem) && (!RlvFolderLocks::instance().isLockedFolder(pItem->getParentUUID(), RLV_LOCK_ADD)))
? canWear(pItem->getWearableType()) : RLV_WEAR_LOCKED;
}
// Checked: 2010-05-14 (RLVa-1.2.0g) | Modified: RLVa-1.2.0g
@@ -435,15 +557,18 @@ inline bool RlvWearableLocks::hasLockedWearableType(ERlvLockMask eLock) const
return ( (eLock & RLV_LOCK_REMOVE) && (!m_WearableTypeRem.empty()) ) || ( (eLock & RLV_LOCK_ADD) && (!m_WearableTypeAdd.empty()) );
}
// Checked: 2010-03-19 (RLVa-1.2.0c) | Added: RLVa-1.2.0a
// Checked: 2010-11-30 (RLVa-1.3.0b) | Modified: RLVa-1.2.0a
inline bool RlvWearableLocks::isLockedWearable(const LLWearable* pWearable) const
{
// Wearable is locked if:
// - it's specifically marked as non-removable
// - it's worn on a wearable type that is RLV_LOCK_REMOVE locked
// - it's part of a locked folder
// TODO-RLVa: [RLVa-1.2.1] We don't have the ability to lock a specific wearable yet so rewrite this when we do
RLV_ASSERT(pWearable);
return (pWearable) && (isLockedWearableType(pWearable->getType(), RLV_LOCK_REMOVE));
return
(pWearable) &&
( (isLockedWearableType(pWearable->getType(), RLV_LOCK_REMOVE)) || (RlvFolderLocks::instance().isLockedWearable(pWearable->getItemID())) );
}
// Checked: 2010-03-19 (RLVa-1.2.0c) | Added: RLVa-1.2.0a
@@ -454,6 +579,134 @@ inline bool RlvWearableLocks::isLockedWearableType(LLWearableType::EType eType,
( (eLock & RLV_LOCK_ADD) && (m_WearableTypeAdd.find(eType) != m_WearableTypeAdd.end()) );
}
// ============================================================================
// RlvFolderLocks member functions
//
// Checked: 2011-03-27 (RLVa-1.3.0g) | Added: RLVa-1.3.0g
inline RlvFolderLocks::folderlock_descr_t::folderlock_descr_t(const LLUUID& rlvObj, ERlvLockMask lockType, folderlock_source_t source,
ELockPermission perm, ELockScope scope)
: idRlvObj(rlvObj), eLockType(lockType), lockSource(source), eLockPermission(perm), eLockScope(scope)
{
}
// Checked: 2011-03-27 (RLVa-1.3.0g) | Added: RLVa-1.3.0g
inline bool RlvFolderLocks::folderlock_descr_t::operator ==(const folderlock_descr_t& rhs) const
{
return (idRlvObj == rhs.idRlvObj) && (eLockType == rhs.eLockType) && (lockSource == rhs.lockSource) &&
(eLockPermission == rhs.eLockPermission) && (eLockScope == rhs.eLockScope);
}
// Checked: 2011-03-29 (RLVa-1.3.0g) | Added: RLVa-1.3.0g
inline bool RlvFolderLocks::canMoveFolder(const LLUUID& idFolder, const LLUUID& idFolderDest) const
{
// Block moving the folder to destination if:
// - the folder (or one of its descendents) is explicitly locked
// - folder and destination are subject to different locks
// -> Possible combinations:
// * folder locked + destination unlocked => block move
// * folder unlocked + destination locked => block move
// * folder locked + destination locked => allow move only if both are subject to the same folder lock
// * folder unlocked + destination unlocked => allow move (special case of above since both locks are equal when there is none)
// => so the above becomes (isLockedFolder(A) == isLockedFolder(B)) && (lockA == lockB)
folderlock_source_t lockSource(ST_NONE, 0), lockSourceDest(ST_NONE, 0);
return
(!hasLockedFolderDescendent(idFolder, ST_MASK_ANY, PERM_MASK_ANY, RLV_LOCK_ANY, true)) &&
( (isLockedFolder(idFolder, RLV_LOCK_ANY, ST_MASK_ANY, &lockSource) == isLockedFolder(idFolderDest, RLV_LOCK_ANY, ST_MASK_ANY, &lockSourceDest)) &&
(lockSource == lockSourceDest) );
}
// Checked: 2011-03-29 (RLVa-1.3.0g) | Added: RLVa-1.3.0g
inline bool RlvFolderLocks::canRemoveFolder(const LLUUID& idFolder) const
{
// Block removing a folder if:
// - the folder (or one of its descendents) is explicitly locked
// - the folder itself is locked (but disregard root folder locks)
return
(!hasLockedFolderDescendent(idFolder, ST_MASK_ANY, PERM_MASK_ANY, RLV_LOCK_ANY, true)) &&
(!isLockedFolder(idFolder, RLV_LOCK_ANY, ST_MASK_ANY & ~ST_ROOTFOLDER));
}
// Checked: 2011-03-29 (RLVa-1.3.0g) | Added: RLVa-1.3.0g
inline bool RlvFolderLocks::canRenameFolder(const LLUUID& idFolder) const
{
// Block renaming a folder if:
// - the folder (or one of its descendents) is explicitly locked by:
// -> a "shared path" => renaming the folder would change the shared path and hence invalidate the lock
// -> an attachment point \
// -> an attachment |--> renaming the folder to a "dot" (=invisible) folder would invalidate the lock
// -> a wearable type /
return !hasLockedFolderDescendent(idFolder, ST_SHAREDPATH | ST_ATTACHMENT | ST_ATTACHMENTPOINT | ST_WEARABLETYPE, PERM_MASK_ANY, RLV_LOCK_ANY, true);
}
// Checked: 2011-03-30 (RLVa-1.3.0g) | Added: RLVa-1.3.0g
inline bool RlvFolderLocks::canMoveItem(const LLUUID& idItem, const LLUUID& idFolderDest) const
{
// Block moving the folder to destination if:
// - folder and destination are subject to different locks [see canMoveFolder() for more details]
const LLViewerInventoryItem* pItem = gInventory.getItem(idItem); const LLUUID& idFolder = (pItem) ? pItem->getParentUUID() : LLUUID::null;
int maskSource = ST_MASK_ANY & ~ST_ROOTFOLDER; folderlock_source_t lockSource(ST_NONE, 0), lockSourceDest(ST_NONE, 0);
return
(idFolder.notNull()) &&
(isLockedFolder(idFolder, RLV_LOCK_ANY, maskSource, &lockSource) == isLockedFolder(idFolderDest, RLV_LOCK_ANY, maskSource, &lockSourceDest)) &&
(lockSource == lockSourceDest);
}
// Checked: 2011-03-30 (RLVa-1.3.0g) | Added: RLVa-1.3.0g
inline bool RlvFolderLocks::canRemoveItem(const LLUUID& idItem) const
{
// Block removing items from locked folders (but disregard root folder locks)
const LLViewerInventoryItem* pItem = gInventory.getItem(idItem); const LLUUID& idFolder = (pItem) ? pItem->getParentUUID() : LLUUID::null;
int maskSource = ST_MASK_ANY & ~ST_ROOTFOLDER;
return (idFolder.notNull()) && (!isLockedFolder(idFolder, RLV_LOCK_ANY, maskSource));
}
// Checked: 2011-03-30 (RLVa-1.3.0g) | Added: RLVa-1.3.0g
inline bool RlvFolderLocks::canRenameItem(const LLUUID& idItem) const
{
// Items can always be renamed, regardless of folder locks
return true;
}
// Checked: 2010-11-30 (RLVa-1.3.0g) | Added: RLVa-1.3.0b
inline bool RlvFolderLocks::hasLockedAttachment() const
{
if (m_fLookupDirty)
refreshLockedLookups();
return !m_LockedAttachmentRem.empty();
}
// Checked: 2011-03-27 (RLVa-1.3.0g) | Modified: RLVa-1.3.0g
inline bool RlvFolderLocks::hasLockedFolder(ERlvLockMask eLock) const
{
// Remove locks are more common so check those first
return ((eLock & RLV_LOCK_REMOVE) && (m_cntLockRem)) || ((eLock & RLV_LOCK_ADD) && (m_cntLockAdd));
}
// Checked: 2010-11-30 (RLVa-1.3.0g) | Added: RLVa-1.3.0b
inline bool RlvFolderLocks::hasLockedWearable() const
{
if (m_fLookupDirty)
refreshLockedLookups();
return !m_LockedWearableRem.empty();
}
// Checked: 2010-11-30 (RLVa-1.3.0g) | Added: RLVa-1.3.0b
inline bool RlvFolderLocks::isLockedAttachment(const LLUUID& idItem) const
{
if (m_fLookupDirty)
refreshLockedLookups();
return (std::find(m_LockedAttachmentRem.begin(), m_LockedAttachmentRem.end(), idItem) != m_LockedAttachmentRem.end());
}
// Checked: 2010-11-30 (RLVa-1.3.0g) | Added: RLVa-1.3.0b
inline bool RlvFolderLocks::isLockedWearable(const LLUUID& idItem) const
{
if (m_fLookupDirty)
refreshLockedLookups();
return (std::find(m_LockedWearableRem.begin(), m_LockedWearableRem.end(), idItem) != m_LockedWearableRem.end());
}
// ============================================================================
#endif // RLV_LOCKS_H