From ebf9cd31d789c0556d741987e95a961edd2955d0 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Wed, 5 Aug 2026 17:15:43 -0700 Subject: Move object publishing tracking to its own manager in the viewer. --- indra/newview/llpublishedobjectmgr.cpp | 838 +++++++++++++++++++++++++++++++++ 1 file changed, 838 insertions(+) create mode 100644 indra/newview/llpublishedobjectmgr.cpp (limited to 'indra/newview/llpublishedobjectmgr.cpp') diff --git a/indra/newview/llpublishedobjectmgr.cpp b/indra/newview/llpublishedobjectmgr.cpp new file mode 100644 index 0000000000..2c2eff58a5 --- /dev/null +++ b/indra/newview/llpublishedobjectmgr.cpp @@ -0,0 +1,838 @@ +/** + * @file llpublishedobjectmgr.cpp + * @brief Published object state/logic manager extracted from llscripteditorws + * + * $LicenseInfo:firstyear=2026&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2026, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" +#include "llpublishedobjectmgr.h" + +#include "llscripteditorws.h" + +#include "llinventorydefines.h" +#include "llselectmgr.h" +#include "llviewerinventory.h" +#include "llviewerobject.h" +#include "llviewerobjectlist.h" +#include "llviewerregion.h" +#include "llvoinventorylistener.h" + +namespace +{ + std::string nv_string(LLViewerObject* obj, const char* key) + { + if (!obj) + { + return std::string(); + } + LLNameValue* nv = obj->getNVPair(key); + if (!nv) + { + return std::string(); + } + const char* s = nv->getString(); + if (!s || s[0] == '\0') + { + return std::string(); + } + return std::string(s); + } + + std::string get_prim_name(LLViewerObject* obj) + { + std::string name = nv_string(obj, "Name"); + if (!name.empty()) + { + return name; + } + + if (!obj) + { + return std::string(); + } + + LLSelectNode* node = LLSelectMgr::instance().getSelection()->findNode(obj); + return (node && !node->mName.empty()) ? node->mName : std::string(); + } +} + +class LLPublishedPrimListener : public LLVOInventoryListener +{ +public: + LLPublishedPrimListener(LLScriptEditorWSServer* server, const LLUUID& object_id, const LLUUID& prim_id, + LLViewerObject* object) + : mServer(server) + , mObjectID(object_id) + , mPrimID(prim_id) + { + registerVOInventoryListener(object, nullptr); + } + + ~LLPublishedPrimListener() override = default; + + void inventoryChanged(LLViewerObject* object, + LLInventoryObject::object_list_t* inventory, + S32 serial_num, void* user_data) override + { + if (mServer) + { + if (mServer->isObjectPublished(mObjectID)) + { + mServer->onPrimInventoryChanged(mObjectID, mPrimID); + } + else + { + mServer->onPrimInventoryReady(mObjectID, mPrimID); + } + } + } + + const LLUUID& getObjectID() const { return mObjectID; } + const LLUUID& getPrimID() const { return mPrimID; } + +private: + LLScriptEditorWSServer* mServer; + LLUUID mObjectID; + LLUUID mPrimID; +}; + +LLPublishedObjectMgr::LLPublishedObjectMgr(LLScriptEditorWSServer* server) + : mServer(server) +{ +} + +LLPublishedObjectMgr::~LLPublishedObjectMgr() = default; + +LLPublishedObjectMgr::PublishedObjectInfo::PublishedObjectInfo() = default; +LLPublishedObjectMgr::PublishedObjectInfo::~PublishedObjectInfo() = default; +LLPublishedObjectMgr::PublishedObjectInfo::PublishedObjectInfo(PublishedObjectInfo&&) noexcept = default; +LLPublishedObjectMgr::PublishedObjectInfo& LLPublishedObjectMgr::PublishedObjectInfo::operator=(PublishedObjectInfo&&) noexcept = default; + +LLPublishedObjectMgr::PendingPublish::PendingPublish() = default; +LLPublishedObjectMgr::PendingPublish::~PendingPublish() = default; +LLPublishedObjectMgr::PendingPublish::PendingPublish(PendingPublish&&) noexcept = default; +LLPublishedObjectMgr::PendingPublish& LLPublishedObjectMgr::PendingPublish::operator=(PendingPublish&&) noexcept = default; + +void LLPublishedObjectMgr::beginPendingPublish(const LLUUID& object_id, const std::vector& prims) +{ + PendingPublish pending; + pending.mObjectID = object_id; + for (LLViewerObject* prim : prims) + { + pending.mPendingPrims.insert(prim->getID()); + auto listener = std::make_unique( + mServer, object_id, prim->getID(), prim); + pending.mListeners.push_back(std::move(listener)); + } + mPendingPublishes[object_id] = std::move(pending); +} + +bool LLPublishedObjectMgr::hasPendingPublish(const LLUUID& object_id) const +{ + return mPendingPublishes.find(object_id) != mPendingPublishes.end(); +} + +bool LLPublishedObjectMgr::markPendingPublishPrimReady(const LLUUID& object_id, const LLUUID& prim_id) +{ + auto it = mPendingPublishes.find(object_id); + if (it == mPendingPublishes.end()) + { + return false; + } + + it->second.mPendingPrims.erase(prim_id); + return it->second.mPendingPrims.empty(); +} + +std::vector> LLPublishedObjectMgr::takePendingPublishListeners(const LLUUID& object_id) +{ + auto it = mPendingPublishes.find(object_id); + if (it == mPendingPublishes.end()) + { + return {}; + } + + auto listeners = std::move(it->second.mListeners); + mPendingPublishes.erase(it); + return listeners; +} + +void LLPublishedObjectMgr::cancelPendingPublish(const LLUUID& object_id) +{ + mPendingPublishes.erase(object_id); +} + +void LLPublishedObjectMgr::cancelPendingPublishWithCleanup(const LLUUID& object_id) +{ + auto it = mPendingPublishes.find(object_id); + if (it == mPendingPublishes.end()) + { + return; + } + + it->second.mListeners.clear(); + mPendingPublishes.erase(it); +} + +LLPublishedObjectMgr::PublishedObjectInfo* LLPublishedObjectMgr::getPublished(const LLUUID& object_id) +{ + auto it = mPublishedObjects.find(object_id); + if (it == mPublishedObjects.end()) + { + return nullptr; + } + + return &it->second; +} + +const LLPublishedObjectMgr::PublishedObjectInfo* LLPublishedObjectMgr::getPublished(const LLUUID& object_id) const +{ + auto it = mPublishedObjects.find(object_id); + if (it == mPublishedObjects.end()) + { + return nullptr; + } + + return &it->second; +} + +bool LLPublishedObjectMgr::reservePendingItemCreate(const LLUUID& prim_id, std::string&& pump_name) +{ + auto it = mPendingItemCreates.find(prim_id); + if (it != mPendingItemCreates.end()) + { + return false; + } + + mPendingItemCreates[prim_id] = std::move(pump_name); + return true; +} + +bool LLPublishedObjectMgr::consumePendingItemCreate(const LLUUID& prim_id, std::string& pump_name) +{ + auto it = mPendingItemCreates.find(prim_id); + if (it == mPendingItemCreates.end()) + { + return false; + } + + pump_name = it->second; + mPendingItemCreates.erase(it); + return true; +} + +void LLPublishedObjectMgr::clearPendingItemCreate(const LLUUID& prim_id) +{ + mPendingItemCreates.erase(prim_id); +} + +LLSD LLPublishedObjectMgr::buildPrimInventoryLLSD(LLViewerObject* object) const +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_SCRIPTDEV; + LLSD items = LLSD::emptyArray(); + if (!object) + { + return items; + } + + LLInventoryObject::object_list_t contents; + object->getInventoryContents(contents); + + for (const auto& obj : contents) + { + LLInventoryItem* item = dynamic_cast(obj.get()); + if (!item) + { + continue; + } + + LLAssetType::EType type = item->getType(); + if (type != LLAssetType::AT_LSL_TEXT && type != LLAssetType::AT_NOTECARD) + { + continue; + } + + LLSD entry; + entry["item_id"] = item->getUUID(); + entry["name"] = item->getName(); + entry["description"] = item->getDescription(); + entry["type"] = (type == LLAssetType::AT_LSL_TEXT) ? "script" : "notecard"; + + if (type == LLAssetType::AT_LSL_TEXT) + { + U8 subtype = item->getInventorySubType(); + entry["subtype"] = static_cast(subtype); + + const std::string& runtime = item->getRuntime(); + if (!runtime.empty()) + { + entry["vm"] = runtime; + } + + LLViewerInventoryItem* viewer_item = dynamic_cast(item); + if (viewer_item) + { + entry["running"] = viewer_item->getIsRunning(); + entry["faulted"] = viewer_item->getIsFaulted(); + } + } + + const LLPermissions& perms = item->getPermissions(); + LLSD perm_entry; + perm_entry["owner"] = static_cast(perms.getMaskOwner()); + perm_entry["next_owner"] = static_cast(perms.getMaskNextOwner()); + entry["permissions"] = perm_entry; + + entry["creator_id"] = perms.getCreator(); + + items.append(entry); + } + + return items; +} + +LLSD LLPublishedObjectMgr::buildPublishedObjectLLSD(LLViewerObject* root) const +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_SCRIPTDEV; + LLSD pub; + pub["object_id"] = root->getID(); + pub["object_name"] = get_prim_name(root); + pub["object_description"] = nv_string(root, "Desc"); + pub["owner_id"] = root->mOwnerID; + if (root->getRegion()) + { + pub["region"] = root->getRegion()->getName(); + } + pub["inventory"] = buildPrimInventoryLLSD(root); + + LLSD linked_objects = LLSD::emptyArray(); + S32 link_number = 2; + for (LLViewerObject* child : root->getChildren()) + { + LLSD link; + link["link_id"] = child->getID(); + link["link_number"] = link_number++; + link["link_name"] = get_prim_name(child); + link["link_description"] = nv_string(child, "Desc"); + link["inventory"] = buildPrimInventoryLLSD(child); + linked_objects.append(link); + } + if (linked_objects.size() > 0) + { + pub["linked_objects"] = linked_objects; + } + + return pub; +} + +LLSD LLPublishedObjectMgr::buildObjectListLLSD() const +{ + LLSD objects = LLSD::emptyArray(); + for (const auto& [object_id, info] : mPublishedObjects) + { + LLViewerObject* root = gObjectList.findObject(object_id); + if (!root) + { + LL_DEBUGS("ScriptEditorWS") << "object.list: skipping " << object_id + << " (no longer in scene)" << LL_ENDL; + continue; + } + + LLSD pub; + pub["object_id"] = info.mObjectID; + pub["object_name"] = info.mObjectName; + pub["object_description"] = info.mObjectDescription; + pub["owner_id"] = info.mOwnerID; + if (!info.mRegionName.empty()) + { + pub["region"] = info.mRegionName; + } + pub["inventory"] = buildPrimInventoryLLSD(root); + + LLSD linked_objects = LLSD::emptyArray(); + for (const auto& prim_info : info.mPrims) + { + if (prim_info.mLinkNumber == 1) + { + continue; + } + + LLViewerObject* child = gObjectList.findObject(prim_info.mPrimID); + if (!child) + { + continue; + } + + LLSD link; + link["link_id"] = prim_info.mPrimID; + link["link_number"] = prim_info.mLinkNumber; + link["link_name"] = prim_info.mPrimName; + link["inventory"] = buildPrimInventoryLLSD(child); + linked_objects.append(link); + } + if (linked_objects.size() > 0) + { + pub["linked_objects"] = linked_objects; + } + + objects.append(pub); + } + + return objects; +} + +bool LLPublishedObjectMgr::buildLinksetUpdateLLSD( + const LLUUID& root_id, LLSD& update) const +{ + const PublishedObjectInfo* info = getPublished(root_id); + if (!info) + { + return false; + } + + LLSD linked_objects = LLSD::emptyArray(); + for (const PublishedPrimInfo& prim_info : info->mPrims) + { + if (prim_info.mPrimID == root_id) + { + continue; + } + + LLSD entry; + entry["link_id"] = prim_info.mPrimID; + entry["link_number"] = prim_info.mLinkNumber; + + LLViewerObject* prim = gObjectList.findObject(prim_info.mPrimID); + std::string link_name = prim ? get_prim_name(prim) : std::string(); + if (link_name.empty()) + { + link_name = prim_info.mPrimName; + } + entry["link_name"] = link_name; + entry["inventory"] = prim ? buildPrimInventoryLLSD(prim) : LLSD::emptyArray(); + + linked_objects.append(entry); + } + + update = LLSD(); + update["object_id"] = root_id; + update["linked_objects"] = linked_objects; + return true; +} + +bool LLPublishedObjectMgr::reconcileLinksetChildAdded( + const LLUUID& root_id, + LLViewerObject* child, + F64 request_start_sec) +{ + PublishedObjectInfo* info = getPublished(root_id); + if (!info || !child) + { + return false; + } + + const LLUUID child_id = child->getID(); + + info->mPrims.erase( + std::remove_if( + info->mPrims.begin(), + info->mPrims.end(), + [&](const PublishedPrimInfo& p) { return p.mPrimID == child_id; }), + info->mPrims.end()); + + PublishedPrimInfo prim_info; + prim_info.mPrimID = child_id; + prim_info.mPrimName = get_prim_name(child); + prim_info.mLinkNumber = static_cast(info->mPrims.size()) + 1; + prim_info.mInventorySerial = -1; + info->mPrims.push_back(prim_info); + + auto listener = std::make_unique( + mServer, root_id, child_id, child); + info->mListeners.push_back(std::move(listener)); + + mInventoryRequestStartSec[child_id] = request_start_sec; + mNewChildPrims[root_id].insert(child_id); + return true; +} + +bool LLPublishedObjectMgr::reconcileLinksetChildRemoved( + const LLUUID& root_id, const LLUUID& child_id) +{ + PublishedObjectInfo* info = getPublished(root_id); + if (!info) + { + return false; + } + + info->mPrims.erase( + std::remove_if( + info->mPrims.begin(), + info->mPrims.end(), + [&](const PublishedPrimInfo& p) { return p.mPrimID == child_id; }), + info->mPrims.end()); + + info->mListeners.erase( + std::remove_if( + info->mListeners.begin(), + info->mListeners.end(), + [&](const std::unique_ptr& l) + { + return l->getPrimID() == child_id; + }), + info->mListeners.end()); + + bool root_empty_after_remove = false; + consumePendingNewChild(root_id, child_id, root_empty_after_remove); + + mInventoryRequestStartSec.erase(child_id); + + S32 link_num = 2; + for (auto& p : info->mPrims) + { + if (p.mPrimID != root_id) + { + p.mLinkNumber = link_num++; + } + } + + return true; +} + +bool LLPublishedObjectMgr::handlePrimInventoryReadyEvent( + const LLUUID& object_id, const LLUUID& prim_id) +{ + return markPendingPublishPrimReady(object_id, prim_id); +} + +LLPublishedObjectMgr::PrimInventoryEventResult +LLPublishedObjectMgr::handlePrimInventoryChangedEvent( + const LLUUID& object_id, + const LLUUID& prim_id, + LLViewerObject* prim, + F64 now_sec) +{ + PrimInventoryEventResult result; + if (!hasPublished(object_id) || !prim) + { + return result; + } + + F64 request_start_sec = 0.0; + if (consumeInventoryRequestStart(prim_id, request_start_sec)) + { + result.mTimingConsumed = true; + result.mTimingElapsedSec = llmax(0.0, now_sec - request_start_sec); + } + + InventoryChangeResult inv_result = reconcileInventoryChanged(object_id, prim_id, prim); + result.mKind = inv_result.mKind; + result.mUpdate = inv_result.mUpdate; + + if (result.mKind == InventoryChangeKind::ROOT_INVENTORY_UPDATE || + result.mKind == InventoryChangeKind::CHILD_INVENTORY_UPDATE) + { + std::string pending_item_create_pump; + if (consumePendingItemCreate(prim_id, pending_item_create_pump)) + { + result.mHasPendingItemCreate = true; + result.mPendingItemCreatePump = pending_item_create_pump; + } + } + + return result; +} + +LLPublishedObjectMgr::InventoryChangeResult +LLPublishedObjectMgr::reconcileInventoryChanged( + const LLUUID& object_id, + const LLUUID& prim_id, + LLViewerObject* prim) +{ + InventoryChangeResult result; + PublishedObjectInfo* pub_info = getPublished(object_id); + if (!pub_info || !prim) + { + return result; + } + + bool root_empty_after_remove = false; + if (consumePendingNewChild(object_id, prim_id, root_empty_after_remove)) + { + for (auto& p : pub_info->mPrims) + { + if (p.mPrimID == prim_id) + { + p.mPrimName = get_prim_name(prim); + p.mInventorySerial = 0; + break; + } + } + result.mKind = root_empty_after_remove + ? InventoryChangeKind::CHILD_READY_FLUSH_NOW + : InventoryChangeKind::CHILD_READY_WAIT; + return result; + } + + result.mUpdate = LLSD(); + result.mUpdate["object_id"] = object_id; + LLSD inv = buildPrimInventoryLLSD(prim); + if (prim_id == object_id) + { + result.mUpdate["inventory"] = inv; + result.mKind = InventoryChangeKind::ROOT_INVENTORY_UPDATE; + } + else + { + LLSD modified_entry; + modified_entry["link_id"] = prim_id; + modified_entry["inventory"] = inv; + LLSD modified_arr = LLSD::emptyArray(); + modified_arr.append(modified_entry); + result.mUpdate["changes"]["linked_objects"]["modified"] = modified_arr; + result.mKind = InventoryChangeKind::CHILD_INVENTORY_UPDATE; + } + return result; +} + +bool LLPublishedObjectMgr::applyPropertyChange( + const LLUUID& root_id, + const LLUUID& prim_id, + const std::string& name, + const std::string& desc, + LLSD& update) +{ + PublishedObjectInfo* pub_info = getPublished(root_id); + if (!pub_info) + { + return false; + } + + update = LLSD(); + update["object_id"] = root_id; + + if (prim_id == root_id) + { + bool name_changed = (pub_info->mObjectName != name); + bool desc_changed = (pub_info->mObjectDescription != desc); + if (!name_changed && !desc_changed) + { + return false; + } + + if (name_changed) + { + pub_info->mObjectName = name; + update["object_name"] = name; + } + if (desc_changed) + { + pub_info->mObjectDescription = desc; + update["object_description"] = desc; + } + return true; + } + + auto prim_it = std::find_if(pub_info->mPrims.begin(), pub_info->mPrims.end(), + [&](const PublishedPrimInfo& p) { return p.mPrimID == prim_id; }); + if (prim_it == pub_info->mPrims.end()) + { + return false; + } + if (prim_it->mPrimName == name) + { + return false; + } + + prim_it->mPrimName = name; + LLSD modified_entry; + modified_entry["link_id"] = prim_id; + modified_entry["link_name"] = name; + LLSD modified_arr = LLSD::emptyArray(); + modified_arr.append(modified_entry); + update["changes"]["linked_objects"]["modified"] = modified_arr; + return true; +} + +bool LLPublishedObjectMgr::hasActiveLinksetFlushTimer(const LLUUID& root_id) const +{ + auto it = mLinksetFlushTimers.find(root_id); + if (it == mLinksetFlushTimers.end()) + { + return false; + } + + return !it->second.expired(); +} + +void LLPublishedObjectMgr::setLinksetFlushTimer( + const LLUUID& root_id, const std::weak_ptr& timer) +{ + mLinksetFlushTimers[root_id] = timer; +} + +bool LLPublishedObjectMgr::cancelLinksetFlushTimer(const LLUUID& root_id) +{ + auto it = mLinksetFlushTimers.find(root_id); + if (it == mLinksetFlushTimers.end()) + { + return false; + } + + if (auto locked = it->second.lock()) + { + delete locked.get(); + } + + mLinksetFlushTimers.erase(it); + return true; +} + +void LLPublishedObjectMgr::clearLinksetFlushTimer(const LLUUID& root_id) +{ + mLinksetFlushTimers.erase(root_id); +} + +bool LLPublishedObjectMgr::consumeInventoryRequestStart( + const LLUUID& prim_id, F64& start_sec) +{ + auto it = mInventoryRequestStartSec.find(prim_id); + if (it == mInventoryRequestStartSec.end()) + { + return false; + } + + start_sec = it->second; + mInventoryRequestStartSec.erase(it); + return true; +} + +bool LLPublishedObjectMgr::markPrimInventorySerialAndDetectChange( + const LLUUID& root_id, const LLUUID& prim_id, S16 inventory_serial) +{ + if (inventory_serial < 0) + { + return false; + } + + PublishedObjectInfo* info = getPublished(root_id); + if (!info) + { + return false; + } + + auto it = std::find_if( + info->mPrims.begin(), + info->mPrims.end(), + [&](const PublishedPrimInfo& p) + { + return p.mPrimID == prim_id; + }); + if (it == info->mPrims.end()) + { + return false; + } + + if (it->mInventorySerial == inventory_serial) + { + return false; + } + + it->mInventorySerial = inventory_serial; + return true; +} + +bool LLPublishedObjectMgr::consumePendingNewChild( + const LLUUID& root_id, const LLUUID& child_id, bool& root_empty_after_remove) +{ + root_empty_after_remove = false; + auto root_it = mNewChildPrims.find(root_id); + if (root_it == mNewChildPrims.end()) + { + return false; + } + + auto child_it = root_it->second.find(child_id); + if (child_it == root_it->second.end()) + { + return false; + } + + root_it->second.erase(child_it); + if (root_it->second.empty()) + { + root_empty_after_remove = true; + mNewChildPrims.erase(root_it); + } + + return true; +} + +LLPublishedObjectMgr::PublishedObjectInfo& LLPublishedObjectMgr::finalizePendingPublish( + const LLUUID& object_id, PublishedObjectInfo&& info) +{ + PublishedObjectInfo& published_info = mPublishedObjects[object_id]; + published_info = std::move(info); + published_info.mListeners = takePendingPublishListeners(object_id); + return published_info; +} + +bool LLPublishedObjectMgr::cleanupObjectStateForUnpublish(const LLUUID& object_id) +{ + const bool was_published = hasPublished(object_id); + + cancelPendingPublishWithCleanup(object_id); + clearPublishedListeners(object_id); + erasePublished(object_id); + + cancelLinksetFlushTimer(object_id); + clearPendingNewChildren(object_id); + + return was_published; +} + +void LLPublishedObjectMgr::clearPublishedListeners(const LLUUID& object_id) +{ + auto pub_info = getPublished(object_id); + if (!pub_info) + { + return; + } + + pub_info->mListeners.clear(); +} + +void LLPublishedObjectMgr::clearAllStateWithListenerCleanup() +{ + for (auto& [id, pending] : mPendingPublishes) + { + pending.mListeners.clear(); + } + mPendingPublishes.clear(); + + for (auto& [id, info] : mPublishedObjects) + { + info.mListeners.clear(); + } + mPublishedObjects.clear(); +} -- cgit v1.3 From 5e2d671895b292726f923db5f8e7375097b6e159 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Mon, 10 Aug 2026 15:45:03 -0700 Subject: Refresh the object's data when it is published. (link children seem to be an issue still) --- indra/newview/llpublishedobjectmgr.cpp | 107 ++++++++++++++++++++++++++++++--- indra/newview/llpublishedobjectmgr.h | 11 ++++ indra/newview/llscripteditorws.cpp | 49 ++++++++++++++- 3 files changed, 159 insertions(+), 8 deletions(-) (limited to 'indra/newview/llpublishedobjectmgr.cpp') diff --git a/indra/newview/llpublishedobjectmgr.cpp b/indra/newview/llpublishedobjectmgr.cpp index 2c2eff58a5..6f78ba82d9 100644 --- a/indra/newview/llpublishedobjectmgr.cpp +++ b/indra/newview/llpublishedobjectmgr.cpp @@ -72,7 +72,13 @@ namespace } LLSelectNode* node = LLSelectMgr::instance().getSelection()->findNode(obj); - return (node && !node->mName.empty()) ? node->mName : std::string(); + if (node && !node->mName.empty()) + { + return node->mName; + } + + // Never emit an empty prim/object name to downstream tooling. + return obj->getID().asString(); } } @@ -164,6 +170,37 @@ bool LLPublishedObjectMgr::markPendingPublishPrimReady(const LLUUID& object_id, return it->second.mPendingPrims.empty(); } +void LLPublishedObjectMgr::recordPendingPropertyChange( + const LLUUID& root_id, + const LLUUID& prim_id, + const std::string& name, + const std::string& desc) +{ + auto it = mPendingPublishes.find(root_id); + if (it == mPendingPublishes.end()) + { + return; + } + + PendingPublish& pending = it->second; + if (prim_id == root_id) + { + pending.mHasRootProperties = true; + pending.mObjectDescription = desc; + if (!name.empty()) + { + pending.mObjectName = name; + } + return; + } + + if (!name.empty()) + { + pending.mPrimNames[prim_id] = name; + } + pending.mPrimDescriptions[prim_id] = desc; +} + std::vector> LLPublishedObjectMgr::takePendingPublishListeners(const LLUUID& object_id) { auto it = mPendingPublishes.find(object_id); @@ -387,6 +424,7 @@ LLSD LLPublishedObjectMgr::buildObjectListLLSD() const link["link_id"] = prim_info.mPrimID; link["link_number"] = prim_info.mLinkNumber; link["link_name"] = prim_info.mPrimName; + link["link_description"] = prim_info.mPrimDescription; link["inventory"] = buildPrimInventoryLLSD(child); linked_objects.append(link); } @@ -428,7 +466,13 @@ bool LLPublishedObjectMgr::buildLinksetUpdateLLSD( { link_name = prim_info.mPrimName; } + std::string link_desc = prim ? nv_string(prim, "Desc") : std::string(); + if (link_desc.empty()) + { + link_desc = prim_info.mPrimDescription; + } entry["link_name"] = link_name; + entry["link_description"] = link_desc; entry["inventory"] = prim ? buildPrimInventoryLLSD(prim) : LLSD::emptyArray(); linked_objects.append(entry); @@ -463,6 +507,7 @@ bool LLPublishedObjectMgr::reconcileLinksetChildAdded( PublishedPrimInfo prim_info; prim_info.mPrimID = child_id; prim_info.mPrimName = get_prim_name(child); + prim_info.mPrimDescription = nv_string(child, "Desc"); prim_info.mLinkNumber = static_cast(info->mPrims.size()) + 1; prim_info.mInventorySerial = -1; info->mPrims.push_back(prim_info); @@ -584,6 +629,7 @@ LLPublishedObjectMgr::reconcileInventoryChanged( if (p.mPrimID == prim_id) { p.mPrimName = get_prim_name(prim); + p.mPrimDescription = nv_string(prim, "Desc"); p.mInventorySerial = 0; break; } @@ -633,7 +679,8 @@ bool LLPublishedObjectMgr::applyPropertyChange( if (prim_id == root_id) { - bool name_changed = (pub_info->mObjectName != name); + bool has_name = !name.empty(); + bool name_changed = has_name && (pub_info->mObjectName != name); bool desc_changed = (pub_info->mObjectDescription != desc); if (!name_changed && !desc_changed) { @@ -659,15 +706,25 @@ bool LLPublishedObjectMgr::applyPropertyChange( { return false; } - if (prim_it->mPrimName == name) + const bool name_changed = !name.empty() && prim_it->mPrimName != name; + const bool desc_changed = prim_it->mPrimDescription != desc; + if (!name_changed && !desc_changed) { return false; } - prim_it->mPrimName = name; LLSD modified_entry; - modified_entry["link_id"] = prim_id; - modified_entry["link_name"] = name; + modified_entry["link_id"] = prim_id; + if (name_changed) + { + prim_it->mPrimName = name; + modified_entry["link_name"] = name; + } + if (desc_changed) + { + prim_it->mPrimDescription = desc; + modified_entry["link_description"] = desc; + } LLSD modified_arr = LLSD::emptyArray(); modified_arr.append(modified_entry); update["changes"]["linked_objects"]["modified"] = modified_arr; @@ -792,8 +849,44 @@ LLPublishedObjectMgr::PublishedObjectInfo& LLPublishedObjectMgr::finalizePending const LLUUID& object_id, PublishedObjectInfo&& info) { PublishedObjectInfo& published_info = mPublishedObjects[object_id]; + auto pending_it = mPendingPublishes.find(object_id); published_info = std::move(info); - published_info.mListeners = takePendingPublishListeners(object_id); + + if (pending_it != mPendingPublishes.end()) + { + PendingPublish& pending = pending_it->second; + if (pending.mHasRootProperties) + { + if (!pending.mObjectName.empty()) + { + published_info.mObjectName = pending.mObjectName; + } + published_info.mObjectDescription = pending.mObjectDescription; + } + + for (PublishedPrimInfo& prim_info : published_info.mPrims) + { + auto name_it = pending.mPrimNames.find(prim_info.mPrimID); + if (name_it != pending.mPrimNames.end() && !name_it->second.empty()) + { + prim_info.mPrimName = name_it->second; + } + + auto desc_it = pending.mPrimDescriptions.find(prim_info.mPrimID); + if (desc_it != pending.mPrimDescriptions.end()) + { + prim_info.mPrimDescription = desc_it->second; + } + } + + published_info.mListeners = std::move(pending.mListeners); + mPendingPublishes.erase(pending_it); + } + else + { + published_info.mListeners = takePendingPublishListeners(object_id); + } + return published_info; } diff --git a/indra/newview/llpublishedobjectmgr.h b/indra/newview/llpublishedobjectmgr.h index 4d4bd55aff..d7eca09d80 100644 --- a/indra/newview/llpublishedobjectmgr.h +++ b/indra/newview/llpublishedobjectmgr.h @@ -49,6 +49,7 @@ public: LLUUID mPrimID; std::string mPrimName; S32 mLinkNumber; + std::string mPrimDescription; S16 mInventorySerial; }; @@ -82,6 +83,11 @@ public: LLUUID mObjectID; std::set mPendingPrims; std::vector> mListeners; + bool mHasRootProperties{ false }; + std::string mObjectName; + std::string mObjectDescription; + std::map mPrimNames; + std::map mPrimDescriptions; }; enum class InventoryChangeKind @@ -153,6 +159,11 @@ public: bool hasPendingPublish(const LLUUID& object_id) const; bool markPendingPublishPrimReady(const LLUUID& object_id, const LLUUID& prim_id); std::vector> takePendingPublishListeners(const LLUUID& object_id); + void recordPendingPropertyChange( + const LLUUID& root_id, + const LLUUID& prim_id, + const std::string& name, + const std::string& desc); void cancelPendingPublish(const LLUUID& object_id); PublishedObjectInfo& finalizePendingPublish(const LLUUID& object_id, PublishedObjectInfo&& info); bool cleanupObjectStateForUnpublish(const LLUUID& object_id); diff --git a/indra/newview/llscripteditorws.cpp b/indra/newview/llscripteditorws.cpp index 3fbcd5c384..95e06583d3 100644 --- a/indra/newview/llscripteditorws.cpp +++ b/indra/newview/llscripteditorws.cpp @@ -2086,7 +2086,13 @@ std::string LLScriptEditorWSServer::getPrimName(LLViewerObject* obj) } LLSelectNode* node = LLSelectMgr::instance().getSelection()->findNode(obj); - return (node && !node->mName.empty()) ? node->mName : std::string(); + if (node && !node->mName.empty()) + { + return node->mName; + } + + // Never emit an empty prim/object name to downstream tooling. + return obj->getID().asString(); } bool LLScriptEditorWSServer::publishObject(const LLUUID& object_id) @@ -2114,6 +2120,13 @@ bool LLScriptEditorWSServer::publishObject(const LLUUID& object_id) // Collect root + all children std::vector prims = collect_linkset(root); + // Request object properties for each prim in the linkset (root + children), + // matching the hover path so name/description metadata is refreshed. + for (LLViewerObject* prim : prims) + { + LLSelectMgr::instance().requestObjectPropertiesFamily(prim); + } + // Set up a PendingPublish to coordinate inventory loading across all prims. // We register a listener and call requestInventory() on every prim. // If inventory is already loaded, requestInventory() fires the callback @@ -2196,6 +2209,31 @@ void LLScriptEditorWSServer::buildAndSendPublish(const LLUUID& object_id) LLPublishedObjectMgr::PublishedObjectInfo& published_info = mPublishedObjectManager.finalizePendingPublish(object_id, std::move(info)); + // Align outgoing publish payload with any property responses that arrived + // while inventory-gated publish was still pending. + pub["object_name"] = published_info.mObjectName; + pub["object_description"] = published_info.mObjectDescription; + if (pub.has("linked_objects")) + { + LLSD& linked_objects = pub["linked_objects"]; + for (S32 i = 0; i < linked_objects.size(); ++i) + { + const LLUUID link_id = linked_objects[i]["link_id"].asUUID(); + auto prim_it = std::find_if( + published_info.mPrims.begin(), + published_info.mPrims.end(), + [&](const LLPublishedObjectMgr::PublishedPrimInfo& p) + { + return p.mPrimID == link_id; + }); + if (prim_it != published_info.mPrims.end()) + { + linked_objects[i]["link_name"] = prim_it->mPrimName; + linked_objects[i]["link_description"] = prim_it->mPrimDescription; + } + } + } + // Send notification LLSD message; message["object"] = pub; @@ -2204,6 +2242,13 @@ void LLScriptEditorWSServer::buildAndSendPublish(const LLUUID& object_id) LL_INFOS("ScriptEditorWS") << "Published object " << object_id << " (" << pub["object_name"].asString() << ") with " << (prims.size() - 1) << " linked prim(s)" << LL_ENDL; + + // Re-request object properties now that the object is published so + // onObjectPropertyChanged can emit object.update for root and linked prims. + for (LLViewerObject* prim : prims) + { + LLSelectMgr::instance().requestObjectPropertiesFamily(prim); + } } void LLScriptEditorWSServer::onLinksetChildAdded(const LLUUID& root_id, LLViewerObject* child) @@ -2344,6 +2389,8 @@ void LLScriptEditorWSServer::onObjectPropertyChanged( LLUUID root_id = prim->getRootEdit()->getID(); + mPublishedObjectManager.recordPendingPropertyChange(root_id, prim_id, name, desc); + bool should_refresh_inventory = mPublishedObjectManager.markPrimInventorySerialAndDetectChange( root_id, prim_id, -- cgit v1.3 From 32a8200a788b286073a11c81255aac471aa37b67 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Wed, 12 Aug 2026 15:25:20 -0700 Subject: Issue https://github.com/secondlife/sl-vscode-plugin/issues/99: Allow rezzed objects to be saved back to their rezzer's inventory. --- indra/newview/llpublishedobjectmgr.cpp | 1 + indra/newview/llpublishedobjectmgr.h | 2 + indra/newview/llscripteditorws.cpp | 80 ++++++++++++++++++++++++++++++++++ indra/newview/llscripteditorws.h | 1 + indra/newview/llviewermenu.cpp | 34 +++++++++++++-- indra/newview/llviewermenu.h | 2 + 6 files changed, 117 insertions(+), 3 deletions(-) (limited to 'indra/newview/llpublishedobjectmgr.cpp') diff --git a/indra/newview/llpublishedobjectmgr.cpp b/indra/newview/llpublishedobjectmgr.cpp index 6f78ba82d9..e9d13c1213 100644 --- a/indra/newview/llpublishedobjectmgr.cpp +++ b/indra/newview/llpublishedobjectmgr.cpp @@ -404,6 +404,7 @@ LLSD LLPublishedObjectMgr::buildObjectListLLSD() const { pub["region"] = info.mRegionName; } + pub["can_save_back"] = info.mCanSaveBackToContents; pub["inventory"] = buildPrimInventoryLLSD(root); LLSD linked_objects = LLSD::emptyArray(); diff --git a/indra/newview/llpublishedobjectmgr.h b/indra/newview/llpublishedobjectmgr.h index d7eca09d80..99ffa34b39 100644 --- a/indra/newview/llpublishedobjectmgr.h +++ b/indra/newview/llpublishedobjectmgr.h @@ -67,6 +67,8 @@ public: std::string mObjectName; std::string mObjectDescription; std::string mRegionName; + bool mCanSaveBackToContents{ false }; + LLUUID mSourceTaskID; std::vector mPrims; std::vector> mListeners; }; diff --git a/indra/newview/llscripteditorws.cpp b/indra/newview/llscripteditorws.cpp index d9a4e4b064..2b77ff1481 100644 --- a/indra/newview/llscripteditorws.cpp +++ b/indra/newview/llscripteditorws.cpp @@ -208,6 +208,12 @@ LLScriptEditorWSServer::LLScriptEditorWSServer(const std::string& name, U16 port response["success"] = true; return response; }); + + registerCommand({ "viewer.object.save_back_to_contents", "Save an in-world object back to source object contents" }, + [this](U32 connection_id, const LLSD& p) -> LLSD + { + return this->handleSaveBackToObjectContents(connection_id, p); + }); } LLScriptEditorWSServer::ptr_t LLScriptEditorWSServer::getServer() @@ -918,6 +924,65 @@ bool LLScriptEditorWSConnection::hasFeature(const std::string& feature) const return mFeatures.count(feature) > 0; } +LLSD LLScriptEditorWSServer::handleSaveBackToObjectContents(U32 connection_id, const LLSD& params) +{ + LLUUID object_id = params["object_id"].asUUID(); + if (object_id.isNull()) + { + throw LLJSONRPCConnection::InvalidParams("object_id is required"); + } + + const LLPublishedObjectMgr::PublishedObjectInfo* published_info = + mPublishedObjectManager.getPublished(object_id); + if (!published_info) + { + LLSD response; + response["success"] = false; + response["error_code"] = WSCommandError::InvalidParams; + response["message"] = "Object is not published"; + return response; + } + + if (!published_info->mCanSaveBackToContents || published_info->mSourceTaskID.isNull()) + { + LLSD response; + response["success"] = false; + response["error_code"] = WSCommandError::NotPermitted; + response["message"] = "Save back is not available for this object"; + return response; + } + + LLViewerObject* root = gObjectList.findObject(object_id); + if (!root) + { + LLSD response; + response["success"] = false; + response["error_code"] = WSCommandError::InvalidParams; + response["message"] = "object_id not found"; + return response; + } + + if (!save_object_back_to_contents(root, published_info->mSourceTaskID)) + { + LLSD response; + response["success"] = false; + response["error_code"] = WSCommandError::ExecutionError; + response["message"] = "Failed to save object back to contents"; + return response; + } + + LL_DEBUGS("ScriptEditorWS") << "Save-back requested via command for object " + << object_id << " on connection " << connection_id << LL_ENDL; + + LLSD response; + response["success"] = true; + + LLSD result; + result["object_id"] = object_id; + response["result"] = result; + return response; +} + LLSD LLScriptEditorWSServer::handleCommandExecute(U32 connection_id, const LLSD& params) { const std::string command = params["command"].asString(); @@ -2228,6 +2293,20 @@ void LLScriptEditorWSServer::buildAndSendPublish(const LLUUID& object_id) { info.mRegionName = root->getRegion()->getName(); } + LLSelectNode* root_select_node = LLSelectMgr::instance().getSelection()->findNode(root); + if (root_select_node + && root_select_node->mValid + && !root_select_node->mFromTaskID.isNull() + && !root->isAttachment()) + { + info.mCanSaveBackToContents = true; + info.mSourceTaskID = root_select_node->mFromTaskID; + } + else + { + info.mCanSaveBackToContents = false; + info.mSourceTaskID.setNull(); + } S32 link_num = 1; std::vector prims = collect_linkset(root); @@ -2246,6 +2325,7 @@ void LLScriptEditorWSServer::buildAndSendPublish(const LLUUID& object_id) // Align outgoing publish payload with any property responses that arrived // while inventory-gated publish was still pending. pub["object_name"] = published_info.mObjectName; + pub["can_save_back"] = published_info.mCanSaveBackToContents; pub["object_description"] = published_info.mObjectDescription; if (pub.has("linked_objects")) { diff --git a/indra/newview/llscripteditorws.h b/indra/newview/llscripteditorws.h index 63b60335ff..ded83e6369 100644 --- a/indra/newview/llscripteditorws.h +++ b/indra/newview/llscripteditorws.h @@ -247,6 +247,7 @@ protected: LLSD handleObjectModify(U32 connection_id, const LLSD& params); LLSD handleObjectItemModify(U32 connection_id, const LLSD& params); LLSD handleCommandExecute(U32 connection_id, const LLSD& params); + LLSD handleSaveBackToObjectContents(U32 connection_id, const LLSD& params); LLSD handleCommandList(); void sendCommandExecute(U32 connection_id, const std::string& command, const LLSD& params); diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp index dc509479c4..eaaa923b59 100644 --- a/indra/newview/llviewermenu.cpp +++ b/indra/newview/llviewermenu.cpp @@ -5136,6 +5136,31 @@ static void derez_objects(EDeRezDestination dest, const LLUUID& dest_id) derez_objects(dest, dest_id, first_region, error, NULL); } +bool save_object_back_to_contents(LLViewerObject* object, const LLUUID& source_task_id) +{ + if (!object || source_task_id.isNull()) + { + return false; + } + + LLViewerRegion* first_region = object->getRegion(); + if (!first_region) + { + return false; + } + + std::vector objects; + objects.push_back(object); + + std::string error; + derez_objects(DRD_SAVE_INTO_TASK_INVENTORY, source_task_id, first_region, error, &objects); + if (!error.empty()) + { + return false; + } + return true; +} + static void derez_objects_separate(EDeRezDestination dest, const LLUUID &dest_id) { std::vector derez_object_list; @@ -5710,10 +5735,13 @@ class LLToolsSaveToObjectInventory : public view_listener_t bool handleEvent(const LLSD& userdata) { LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode(); - if(node && (node->mValid) && (!node->mFromTaskID.isNull())) + if (node && node->mValid && !node->mFromTaskID.isNull()) { - // *TODO: check to see if the fromtaskid object exists. - derez_objects(DRD_SAVE_INTO_TASK_INVENTORY, node->mFromTaskID); + LLViewerObject* object = node->getObject(); + if (object) + { + save_object_back_to_contents(object, node->mFromTaskID); + } } return true; } diff --git a/indra/newview/llviewermenu.h b/indra/newview/llviewermenu.h index 522c7e8109..6699780a76 100644 --- a/indra/newview/llviewermenu.h +++ b/indra/newview/llviewermenu.h @@ -37,6 +37,7 @@ class LLView; class LLParcelSelection; class LLObjectSelection; class LLSelectNode; +class LLViewerObject; void initialize_edit_menu(); void initialize_spellcheck_menu(); @@ -74,6 +75,7 @@ void handle_take(bool take_separate = false); void handle_take_copy(); void handle_look_at_selection(const LLSD& param); bool handle_zoom_to_object(const LLUUID& object_id); +bool save_object_back_to_contents(LLViewerObject* object, const LLUUID& source_task_id); void handle_object_return(); void handle_object_delete(); void handle_object_edit(); -- cgit v1.3