From 2facb2c6ed6b3e803c11cfa61c41f6c1b2cacd0b Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Thu, 3 Mar 2022 20:02:01 -0500
Subject: [PATCH] Wire up old economy data for opensim

---
 indra/llinventory/CMakeLists.txt      |  2 +
 indra/newview/llagentbenefits.cpp     | 71 +++++++++++++++++++++++----
 indra/newview/llagentpicksinfo.cpp    |  3 +-
 indra/newview/llappviewer.cpp         |  2 +-
 indra/newview/llpanelprofilepicks.cpp |  3 +-
 indra/newview/llstartup.cpp           | 36 +++++++++++++-
 indra/newview/llstartup.h             |  1 +
 indra/newview/llviewermessage.cpp     | 18 ++++++-
 8 files changed, 122 insertions(+), 14 deletions(-)

diff --git a/indra/llinventory/CMakeLists.txt b/indra/llinventory/CMakeLists.txt
index 7758978c290..a37b3ca65f3 100644
--- a/indra/llinventory/CMakeLists.txt
+++ b/indra/llinventory/CMakeLists.txt
@@ -19,6 +19,7 @@ include_directories(
 
 set(llinventory_SOURCE_FILES
     llcategory.cpp
+    lleconomy.cpp
     llfoldertype.cpp
     llinventory.cpp
     llinventorydefines.cpp
@@ -41,6 +42,7 @@ set(llinventory_HEADER_FILES
     CMakeLists.txt
 
     llcategory.h
+    lleconomy.h
     llfoldertype.h
     llinventory.h
     llinventorydefines.h
diff --git a/indra/newview/llagentbenefits.cpp b/indra/newview/llagentbenefits.cpp
index 2d219735a09..e97136ef5c8 100644
--- a/indra/newview/llagentbenefits.cpp
+++ b/indra/newview/llagentbenefits.cpp
@@ -26,6 +26,14 @@
 #include "llviewerprecompiledheaders.h"
 #include "llagentbenefits.h"
 
+#include "llagent.h"
+#include "llagentpicksinfo.h"
+#include "lleconomy.h"
+#include "llstartup.h"
+#include "llviewercontrol.h"
+#include "llviewernetwork.h"
+#include "llviewerregion.h"
+
 LLAgentBenefits::LLAgentBenefits():
 	m_initalized(false),
 	m_animated_object_limit(-1),
@@ -34,7 +42,8 @@ LLAgentBenefits::LLAgentBenefits():
 	m_group_membership_limit(-1),
 	m_picks_limit(-1),
 	m_sound_upload_cost(-1),
-	m_texture_upload_cost(-1)
+	m_texture_upload_cost(-1),
+	m_create_group_cost(-1)
 {
 }
 
@@ -102,42 +111,86 @@ bool LLAgentBenefits::init(const LLSD& benefits_sd)
 
 S32 LLAgentBenefits::getAnimatedObjectLimit() const
 {
-	return m_animated_object_limit;
+	if (LLGridManager::instance().isInSecondlife())
+	{
+		return m_animated_object_limit;
+	}
+	else
+	{
+		S32 max_attach = 0;
+		if (gSavedSettings.getBOOL("AnimatedObjectsIgnoreLimits"))
+		{
+			max_attach = getAttachmentLimit();
+		}
+		else
+		{
+			if (gAgent.getRegion())
+			{
+				LLSD features;
+				gAgent.getRegion()->getSimulatorFeatures(features);
+				if (features.has("AnimatedObjects"))
+				{
+					max_attach = features["AnimatedObjects"]["MaxAgentAnimatedObjectAttachments"].asInteger();
+				}
+			}
+		}
+		return max_attach;
+	}
 }
 
 S32 LLAgentBenefits::getAnimationUploadCost() const
 {
-	return m_animation_upload_cost;
+	return LLGridManager::instance().isInSecondlife() ? m_animation_upload_cost : LLGlobalEconomy::instance().getPriceUpload();
 }
 
 S32 LLAgentBenefits::getAttachmentLimit() const
 {
-	return m_attachment_limit;
+	if (LLGridManager::instance().isInSecondlife())
+	{
+		return m_attachment_limit;
+	}
+	else
+	{
+		const S32 MAX_AGENT_ATTACHMENTS = 38;
+
+		S32 max_attach = MAX_AGENT_ATTACHMENTS;
+
+		if (gAgent.getRegion())
+		{
+			LLSD features;
+			gAgent.getRegion()->getSimulatorFeatures(features);
+			if (features.has("MaxAgentAttachments"))
+			{
+				max_attach = features["MaxAgentAttachments"].asInteger();
+			}
+		}
+		return max_attach;
+	}
 }
 
 S32 LLAgentBenefits::getCreateGroupCost() const
 {
-	return m_create_group_cost;
+	return LLGridManager::instance().isInSecondlife() ? m_create_group_cost : 0;
 }
 
 S32 LLAgentBenefits::getGroupMembershipLimit() const
 {
-	return m_group_membership_limit;
+	return LLGridManager::instance().isInSecondlife() ? m_group_membership_limit : gMaxAgentGroups;
 }
 
 S32 LLAgentBenefits::getPicksLimit() const
 {
-	return m_picks_limit;
+	return LLGridManager::instance().isInSecondlife() ? m_picks_limit : LLAgentPicksInfo::instance().getMaxNumberOfPicks();
 }
 
 S32 LLAgentBenefits::getSoundUploadCost() const
 {
-	return m_sound_upload_cost;
+	return LLGridManager::instance().isInSecondlife() ? m_sound_upload_cost : LLGlobalEconomy::instance().getPriceUpload();
 }
 
 S32 LLAgentBenefits::getTextureUploadCost() const
 {
-	return m_texture_upload_cost;
+	return LLGridManager::instance().isInSecondlife() ? m_texture_upload_cost : LLGlobalEconomy::instance().getPriceUpload();
 }
 
 bool LLAgentBenefits::findUploadCost(LLAssetType::EType& asset_type, S32& cost) const
diff --git a/indra/newview/llagentpicksinfo.cpp b/indra/newview/llagentpicksinfo.cpp
index d1adc184447..15efbd0061a 100644
--- a/indra/newview/llagentpicksinfo.cpp
+++ b/indra/newview/llagentpicksinfo.cpp
@@ -28,6 +28,7 @@
 #include "llagentpicksinfo.h"
 
 #include "llagent.h"
+#include "llagentbenefits.h"
 #include "llavatarpropertiesprocessor.h"
 
 const S32 MAX_AVATAR_PICKS = 10;
@@ -112,7 +113,7 @@ void LLAgentPicksInfo::requestNumberOfPicks()
 
 bool LLAgentPicksInfo::isPickLimitReached()
 {
-	return getNumberOfPicks() >= getMaxNumberOfPicks();
+	return getNumberOfPicks() >= LLAgentBenefitsMgr::current().getPicksLimit();
 }
 
 void LLAgentPicksInfo::onServerRespond(LLAvatarPicks* picks)
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index c856fad7d62..b55931858c5 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -2775,7 +2775,7 @@ bool LLAppViewer::initConfiguration()
 		LLStartUp::setStartSLURL(start_slurl);
 		if(start_slurl.getType() == LLSLURL::LOCATION)
 		{
-			LLGridManager::getInstance()->setGridChoice(start_slurl.getGrid());
+			LLGridManager::getInstance()->setGridChoice(start_slurl.getGrid(), false);
 		}
 	}
 
diff --git a/indra/newview/llpanelprofilepicks.cpp b/indra/newview/llpanelprofilepicks.cpp
index efd1e03d68b..6f8acae5916 100644
--- a/indra/newview/llpanelprofilepicks.cpp
+++ b/indra/newview/llpanelprofilepicks.cpp
@@ -29,6 +29,7 @@
 #include "llpanelprofilepicks.h"
 
 #include "llagent.h"
+#include "llagentbenefits.h"
 #include "llagentpicksinfo.h"
 #include "llavataractions.h"
 #include "llavatarpropertiesprocessor.h"
@@ -360,7 +361,7 @@ void LLPanelProfilePicks::updateData()
 bool LLPanelProfilePicks::canAddNewPick()
 {
     return (!LLAgentPicksInfo::getInstanceFast()->isPickLimitReached() &&
-        mTabContainer->getTabCount() < LLAgentPicksInfo::getInstanceFast()->getMaxNumberOfPicks() &&
+        mTabContainer->getTabCount() < LLAgentBenefitsMgr::current().getPicksLimit() &&
         RlvActions::canShowLocation());
 }
 
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index bebdfc87e82..76e03ca55f5 100644
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -219,6 +219,7 @@
 // exported globals
 //
 bool gAgentMovementCompleted = false;
+S32  gMaxAgentGroups;
 
 const std::string SCREEN_HOME_FILENAME = "screen_home%s.png";
 const std::string SCREEN_LAST_FILENAME = "screen_last%s.png";
@@ -1635,6 +1636,11 @@ bool idle_startup()
 			send_complete_agent_movement(regionp->getHost());
 			gAssetStorage->setUpstream(regionp->getHost());
 			gCacheName->setUpstream(regionp->getHost());
+			if (!LLGridManager::instance().isInSecondlife())
+			{
+				msg->newMessageFast(_PREHASH_EconomyDataRequest);
+				gAgent.sendReliableMessage();
+			}
 		}
 		display_startup();
 
@@ -3331,7 +3337,14 @@ bool process_login_success_response()
 {
 	LLSD response = LLLoginInstance::getInstance()->getResponse();
 
-	mBenefitsSuccessfullyInit = init_benefits(response);
+	if (LLGridManager::instance().isInSecondlife())
+	{
+		mBenefitsSuccessfullyInit = init_benefits(response);
+	}
+	else
+	{
+		mBenefitsSuccessfullyInit = true;
+	}
 
 	std::string text(response["udp_blacklist"]);
 	if(!text.empty())
@@ -3650,6 +3663,27 @@ bool process_login_success_response()
 		LLViewerMedia::getInstance()->openIDSetup(openid_url, openid_token);
 	}
 
+	if (!LLGridManager::instance().isInSecondlife())
+	{
+		if (response.has("max-agent-groups") || response.has("max_groups"))
+		{
+			std::string max_agent_groups;
+			response.has("max_groups") ?
+				max_agent_groups = response["max_groups"].asString()
+				: max_agent_groups = response["max-agent-groups"].asString();
+
+			gMaxAgentGroups = atoi(max_agent_groups.c_str());
+			LL_INFOS("LLStartup") << "gMaxAgentGroups read from login.cgi: "
+				<< gMaxAgentGroups << LL_ENDL;
+		}
+		else
+		{
+			gMaxAgentGroups = 0;
+			LL_INFOS("LLStartup") << "did not receive max-agent-groups. unlimited groups activated" << LL_ENDL;
+		}
+	}
+
+
 	bool success = false;
 	// JC: gesture loading done below, when we have an asset system
 	// in place.  Don't delete/clear gUserCredentials until then.
diff --git a/indra/newview/llstartup.h b/indra/newview/llstartup.h
index 3fb4eec4d83..f6825ad0e83 100644
--- a/indra/newview/llstartup.h
+++ b/indra/newview/llstartup.h
@@ -78,6 +78,7 @@ typedef enum {
 
 // exported symbols
 extern bool gAgentMovementCompleted;
+extern S32  gMaxAgentGroups;
 extern LLPointer<LLViewerTexture> gStartTexture;
 
 class LLStartUp
diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
index d1ae3d7f618..6effc71229e 100644
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -32,6 +32,7 @@
 #include "llaudioengine.h" 
 #include "llavataractions.h"
 #include "llavatarnamecache.h"		// IDEVO HACK
+#include "lleconomy.h"
 #include "lleventtimer.h"
 #include "llfloaterreg.h"
 #include "llfolderview.h"
@@ -93,6 +94,7 @@
 #include "lluri.h"
 #include "llviewergenericmessage.h"
 #include "llviewermenu.h"
+#include "llviewernetwork.h"
 #include "llviewerinventory.h"
 #include "llviewerjoystick.h"
 #include "llviewerobjectlist.h"
@@ -5832,7 +5834,21 @@ void process_frozen_message(LLMessageSystem *msgsystem, void **user_data)
 // do some extra stuff once we get our economy data
 void process_economy_data(LLMessageSystem *msg, void** /*user_data*/)
 {
-	LL_DEBUGS("Benefits") << "Received economy data, not currently used" << LL_ENDL;
+	if (!LLGridManager::getInstance()->isInSecondlife())
+	{
+		LLGlobalEconomy::processEconomyData(msg, LLGlobalEconomy::getInstance());
+
+		const std::string texture_upload_cost_str = std::to_string(LLAgentBenefitsMgr::current().getTextureUploadCost());
+		const std::string sound_upload_cost_str = std::to_string(LLAgentBenefitsMgr::current().getSoundUploadCost());
+		const std::string animation_upload_cost_str = std::to_string(LLAgentBenefitsMgr::current().getAnimationUploadCost());
+		gMenuHolder->getChild<LLUICtrl>("Upload Image")->setLabelArg("[COST]",  texture_upload_cost_str);
+		gMenuHolder->getChild<LLUICtrl>("Upload Sound")->setLabelArg("[COST]",  sound_upload_cost_str);
+		gMenuHolder->getChild<LLUICtrl>("Upload Animation")->setLabelArg("[COST]", animation_upload_cost_str);
+	}
+	else
+	{
+		LL_DEBUGS("Benefits") << "Received economy data, not currently used" << LL_ENDL;
+	}
 }
 
 void notify_cautioned_script_question(const LLSD& notification, const LLSD& response, S32 orig_questions, BOOL granted)
-- 
GitLab