123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- /**
- * @file lleconomy.cpp
- *
- * $LicenseInfo:firstyear=2002&license=viewergpl$
- *
- * Copyright (c) 2002-2009, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- #include "linden_common.h"
- #include "lleconomy.h"
- #include "llsdutil.h"
- #include "llmessage.h"
- constexpr S32 MAX_1K_TEXTURE_AREA = 1024 * 1024;
- LLEconomy::LLEconomy()
- : mPriceUpload(-1),
- mAnimationUploadCost(-1),
- mSoundUploadCost(-1),
- mTextureUploadCost(-1),
- m2KTextureUploadCost(-1),
- mCreateGroupCost(-1),
- mAttachmentLimit(-1),
- mAnimatedObjectLimit(-1),
- mGroupMembershipLimit(-1),
- mPicksLimit(-1),
- mGotBenefits(false)
- {
- }
- void LLEconomy::setDefaultCosts(bool in_sl)
- {
- mPriceUpload = mAnimationUploadCost = mSoundUploadCost =
- mTextureUploadCost = m2KTextureUploadCost =
- in_sl ? DEFAULT_UPLOAD_COST : 0;
- mCreateGroupCost = in_sl ? DEFAULT_GROUP_COST : 0;
- llinfos << "Price per upload: " << mPriceUpload
- << " - Price for group creation: " << mCreateGroupCost << llendl;
- }
- void LLEconomy::processEconomyData(LLMessageSystem* msg)
- {
- if (mGotBenefits)
- {
- llinfos << "Received legacy message for economy data after valid user account benefits were set. Ignoring."
- << llendl;
- return;
- }
- msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceUpload, mPriceUpload);
- msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceGroupCreate,
- mCreateGroupCost);
- #if 0 // Old economy data, never used...
- S32 i;
- msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCapacity, i);
- msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCount, i);
- msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceEnergyUnit, i);
- msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceObjectClaim, i);
- msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDecay, i);
- msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDelete, i);
- msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceRentLight, i);
- msg->getS32Fast(_PREHASH_Info, _PREHASH_TeleportMinPrice, i);
- F32 f;
- msg->getF32Fast(_PREHASH_Info, _PREHASH_TeleportPriceExponent, f);
- #endif
- llinfos << "Received economy data. Price per upload: " << mPriceUpload
- << " - Price for group creation: " << mCreateGroupCost << llendl;
- if (mAnimationUploadCost == -1)
- {
- mAnimationUploadCost = mPriceUpload;
- }
- if (mSoundUploadCost == -1)
- {
- mSoundUploadCost = mPriceUpload;
- }
- if (mTextureUploadCost == -1)
- {
- mTextureUploadCost = mPriceUpload;
- }
- if (m2KTextureUploadCost == -1)
- {
- m2KTextureUploadCost = mPriceUpload;
- }
- }
- static std::vector<std::string> sBenefits;
- bool get_S32_value(const LLSD& sd, const char* key, S32& value)
- {
- if (sd.has(key))
- {
- value = sd[key].asInteger();
- sBenefits.emplace_back(llformat(" - %s: %d", key, value));
- return true;
- }
- return false;
- }
- void LLEconomy::setBenefits(const LLSD& data, const std::string& account_type)
- {
- LL_DEBUGS("Benefits") << ll_pretty_print_sd(data) << LL_ENDL;
- llinfos << "Account type: " << account_type << " - Setting benefits:"
- << llendl;
- mAccountType = account_type;
- mBenefits = data;
- mGotBenefits = true;
- get_S32_value(data, "attachment_limit", mAttachmentLimit);
- get_S32_value(data, "animated_object_limit", mAnimatedObjectLimit);
- get_S32_value(data, "picks_limit", mPicksLimit);
- get_S32_value(data, "group_membership_limit", mGroupMembershipLimit);
- if (!get_S32_value(data, "create_group_cost", mCreateGroupCost))
- {
- mGotBenefits = false;
- }
- if (get_S32_value(data, "animation_upload_cost", mAnimationUploadCost))
- {
- if (mAnimationUploadCost > mPriceUpload)
- {
- mPriceUpload = mAnimationUploadCost;
- }
- }
- else
- {
- mGotBenefits = false;
- }
- if (get_S32_value(data, "sound_upload_cost", mSoundUploadCost))
- {
- if (mSoundUploadCost > mPriceUpload)
- {
- mPriceUpload = mSoundUploadCost;
- }
- }
- else
- {
- mGotBenefits = false;
- }
- if (get_S32_value(data, "texture_upload_cost", mTextureUploadCost))
- {
- if (mTextureUploadCost > mPriceUpload)
- {
- mPriceUpload = mTextureUploadCost;
- }
- }
- else
- {
- mGotBenefits = false;
- }
- m2KTextureUploadCost = 0;
- if (data.has("large_texture_upload_cost"))
- {
- const LLSD& costs = data["large_texture_upload_cost"];
- if (costs.isArray())
- {
- LL_DEBUGS("Benefits") << "Large textures upload cost: "
- << ll_pretty_print_sd(costs) << LL_ENDL;
- // Apparently, LL considered several costs, but only use the
- // lowest. HB
- for (LLSD::array_const_iterator it = costs.beginArray(),
- end = costs.endArray();
- it != end; ++it)
- {
- S32 cost = it->asInteger();
- if (cost > 0 &&
- (cost < m2KTextureUploadCost || !m2KTextureUploadCost))
- {
- m2KTextureUploadCost = cost; // Use the lowest cost.
- }
- }
- if (m2KTextureUploadCost > 0)
- {
- sBenefits.emplace_back(llformat(" - large_texture_upload_cost: %d",
- m2KTextureUploadCost));
- }
- }
- else
- {
- get_S32_value(data, "large_texture_upload_cost",
- m2KTextureUploadCost);
- }
- }
- if (m2KTextureUploadCost <= 0)
- {
- m2KTextureUploadCost = mTextureUploadCost;
- }
- for (size_t i = 0, count = sBenefits.size(); i < count; ++i)
- {
- llinfos << sBenefits[i] << llendl;
- }
- sBenefits.clear();
- llinfos << "Done." << llendl;
- }
- const LLSD& LLEconomy::getBenefit(const std::string& key) const
- {
- static const LLSD empty;
- return mBenefits.has(key) ? mBenefits[key] : empty;
- }
- S32 LLEconomy::getTextureUploadCost(S32 tex_area) const
- {
- return tex_area > MAX_1K_TEXTURE_AREA ? m2KTextureUploadCost
- : mTextureUploadCost;
- }
- S32 LLEconomy::getTextureUploadCost(S32 x_size, S32 y_size) const
- {
- return x_size * y_size > MAX_1K_TEXTURE_AREA ? m2KTextureUploadCost
- : mTextureUploadCost;
- }
|