From fe5d7d41335ca22c8078ddaeb9fe40e6b0d57b6d Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Mon, 17 Mar 2025 18:56:07 +0200 Subject: #3731 Follow-up: Use SLua defaults only on SLua-enabled regions (#3753) --- indra/newview/llpanelcontents.cpp | 141 +++++++++++++++++++----------------- indra/newview/llviewerinventory.cpp | 54 ++++++++------ 2 files changed, 107 insertions(+), 88 deletions(-) diff --git a/indra/newview/llpanelcontents.cpp b/indra/newview/llpanelcontents.cpp index e403462f09..e9e48382b4 100644 --- a/indra/newview/llpanelcontents.cpp +++ b/indra/newview/llpanelcontents.cpp @@ -198,7 +198,7 @@ void LLPanelContents::onClickNewScript(void *userdata) { const bool children_ok = true; LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject(children_ok); - if(object) + if (object) { LLPermissions perm; perm.init(gAgent.getID(), gAgent.getID(), LLUUID::null, LLUUID::null); @@ -227,78 +227,87 @@ void LLPanelContents::onClickNewScript(void *userdata) // This temporary workaround should be removed after a server-side fix. // See https://github.com/secondlife/viewer/issues/3731 for more information. // - if (std::string::size_type pos = desc.find("lsl2"); pos != std::string::npos) + LLViewerRegion* region = object->getRegion(); + if (region && region->simulatorFeaturesReceived()) { - desc.replace(pos, 4, "SLua"); - } - - auto scriptCreationCallback = [object](const LLUUID& inv_item) + LLSD simulatorFeatures; + region->getSimulatorFeatures(simulatorFeatures); + if (simulatorFeatures["LuaScriptsEnabled"].asBoolean()) { - if (!inv_item.isNull()) + if (std::string::size_type pos = desc.find("lsl2"); pos != std::string::npos) { - LLViewerInventoryItem* item = gInventory.getItem(inv_item); - if (item) + desc.replace(pos, 4, "SLua"); + } + + auto scriptCreationCallback = [object](const LLUUID& inv_item) { - const std::string hello_lua_script = - "function state_entry()\n" - " ll.Say(0, \"Hello, Avatar!\")\n" - "end\n" - "\n" - "function touch_start(total_number)\n" - " ll.Say(0, \"Touched.\")\n" - "end\n" - "\n" - "-- Simulate the state_entry event\n" - "state_entry()\n"; - - auto scriptUploadFinished = [object, item](LLUUID itemId, LLUUID newAssetId, LLUUID newItemId, LLSD response) + if (!inv_item.isNull()) + { + LLViewerInventoryItem* item = gInventory.getItem(inv_item); + if (item) { - LLPointer new_script = new LLViewerInventoryItem(item); - object->saveScript(new_script, true, true); - - // Delete the temporary item from the user's inventory after rezzing it in the object's inventory - gInventory.deleteObject(item->getUUID()); + const std::string hello_lua_script = + "function state_entry()\n" + " ll.Say(0, \"Hello, Avatar!\")\n" + "end\n" + "\n" + "function touch_start(total_number)\n" + " ll.Say(0, \"Touched.\")\n" + "end\n" + "\n" + "-- Simulate the state_entry event\n" + "state_entry()\n"; + + auto scriptUploadFinished = [object, item](LLUUID itemId, LLUUID newAssetId, LLUUID newItemId, LLSD response) + { + LLPointer new_script = new LLViewerInventoryItem(item); + object->saveScript(new_script, true, true); + + // Delete the temporary item from the user's inventory after rezzing it in the object's inventory + gInventory.deleteObject(item->getUUID()); + gInventory.notifyObservers(); + }; + + std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgent"); + if (!url.empty()) + { + LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared( + item->getUUID(), + "luau", + hello_lua_script, + scriptUploadFinished, + nullptr)); + + LLViewerAssetUpload::EnqueueInventoryUpload(url, uploadInfo); + } + + gInventory.updateItem(item); gInventory.notifyObservers(); - }; - - std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgent"); - if (!url.empty()) - { - LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared( - item->getUUID(), - "luau", - hello_lua_script, - scriptUploadFinished, - nullptr)); - - LLViewerAssetUpload::EnqueueInventoryUpload(url, uploadInfo); + } } - - gInventory.updateItem(item); - gInventory.notifyObservers(); - } - } - }; - LLPointer cb = new LLBoostFuncInventoryCallback(scriptCreationCallback); - - LLMessageSystem* msg = gMessageSystem; - msg->newMessageFast(_PREHASH_CreateInventoryItem); - msg->nextBlock(_PREHASH_AgentData); - msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); - msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); - msg->nextBlock(_PREHASH_InventoryBlock); - msg->addU32Fast(_PREHASH_CallbackID, gInventoryCallbacks.registerCB(cb)); - msg->addUUIDFast(_PREHASH_FolderID, gInventory.getRootFolderID()); - msg->addUUIDFast(_PREHASH_TransactionID, LLTransactionID::tnull); - msg->addU32Fast(_PREHASH_NextOwnerMask, PERM_MOVE | PERM_TRANSFER); - msg->addS8Fast(_PREHASH_Type, LLAssetType::AT_LSL_TEXT); - msg->addS8Fast(_PREHASH_InvType, LLInventoryType::IT_LSL); - msg->addU8Fast(_PREHASH_WearableType, NO_INV_SUBTYPE); - msg->addStringFast(_PREHASH_Name, "New Script"); - msg->addStringFast(_PREHASH_Description, desc); - - gAgent.sendReliableMessage(); - return; + }; + LLPointer cb = new LLBoostFuncInventoryCallback(scriptCreationCallback); + + LLMessageSystem* msg = gMessageSystem; + msg->newMessageFast(_PREHASH_CreateInventoryItem); + msg->nextBlock(_PREHASH_AgentData); + msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); + msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); + msg->nextBlock(_PREHASH_InventoryBlock); + msg->addU32Fast(_PREHASH_CallbackID, gInventoryCallbacks.registerCB(cb)); + msg->addUUIDFast(_PREHASH_FolderID, gInventory.getRootFolderID()); + msg->addUUIDFast(_PREHASH_TransactionID, LLTransactionID::tnull); + msg->addU32Fast(_PREHASH_NextOwnerMask, PERM_MOVE | PERM_TRANSFER); + msg->addS8Fast(_PREHASH_Type, LLAssetType::AT_LSL_TEXT); + msg->addS8Fast(_PREHASH_InvType, LLInventoryType::IT_LSL); + msg->addU8Fast(_PREHASH_WearableType, NO_INV_SUBTYPE); + msg->addStringFast(_PREHASH_Name, "New Script"); + msg->addStringFast(_PREHASH_Description, desc); + + gAgent.sendReliableMessage(); + return; + } + } // // End hack // -------------------------------------------------------------------------------------------------- diff --git a/indra/newview/llviewerinventory.cpp b/indra/newview/llviewerinventory.cpp index 7c0143623b..0066d662a3 100644 --- a/indra/newview/llviewerinventory.cpp +++ b/indra/newview/llviewerinventory.cpp @@ -1024,29 +1024,39 @@ void create_script_cb(const LLUUID& inv_item) // This temporary workaround should be removed after a server-side fix. // See https://github.com/secondlife/viewer/issues/3731 for more information. // - const std::string hello_lua_script = - "function state_entry()\n" - " ll.Say(0, \"Hello, Avatar!\")\n" - "end\n" - "\n" - "function touch_start(total_number)\n" - " ll.Say(0, \"Touched.\")\n" - "end\n" - "\n" - "-- Simulate the state_entry event\n" - "state_entry()\n"; - - std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgent"); - if (!url.empty()) + LLViewerRegion* region = gAgent.getRegion(); + if (region && region->simulatorFeaturesReceived()) { - LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared( - item->getUUID(), - "luau", - hello_lua_script, - nullptr, - nullptr)); - - LLViewerAssetUpload::EnqueueInventoryUpload(url, uploadInfo); + LLSD simulatorFeatures; + region->getSimulatorFeatures(simulatorFeatures); + if (simulatorFeatures["LuaScriptsEnabled"].asBoolean()) + { + + const std::string hello_lua_script = + "function state_entry()\n" + " ll.Say(0, \"Hello, Avatar!\")\n" + "end\n" + "\n" + "function touch_start(total_number)\n" + " ll.Say(0, \"Touched.\")\n" + "end\n" + "\n" + "-- Simulate the state_entry event\n" + "state_entry()\n"; + + std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgent"); + if (!url.empty()) + { + LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared( + item->getUUID(), + "luau", + hello_lua_script, + nullptr, + nullptr)); + + LLViewerAssetUpload::EnqueueInventoryUpload(url, uploadInfo); + } + } } // // End hack -- cgit v1.3