lleconomy.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /**
  2. * @file lleconomy.cpp
  3. *
  4. * $LicenseInfo:firstyear=2002&license=viewergpl$
  5. *
  6. * Copyright (c) 2002-2009, Linden Research, Inc.
  7. *
  8. * Second Life Viewer Source Code
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab. Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. *
  16. * There are special exceptions to the terms and conditions of the GPL as
  17. * it is applied to this Source Code. View the full text of the exception
  18. * in the file doc/FLOSS-exception.txt in this software distribution, or
  19. * online at
  20. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21. *
  22. * By copying, modifying or distributing this software, you acknowledge
  23. * that you have read and understood your obligations described above,
  24. * and agree to abide by those obligations.
  25. *
  26. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28. * COMPLETENESS OR PERFORMANCE.
  29. * $/LicenseInfo$
  30. */
  31. #include "linden_common.h"
  32. #include "lleconomy.h"
  33. #include "llsdutil.h"
  34. #include "llmessage.h"
  35. constexpr S32 MAX_1K_TEXTURE_AREA = 1024 * 1024;
  36. LLEconomy::LLEconomy()
  37. : mPriceUpload(-1),
  38. mAnimationUploadCost(-1),
  39. mSoundUploadCost(-1),
  40. mTextureUploadCost(-1),
  41. m2KTextureUploadCost(-1),
  42. mCreateGroupCost(-1),
  43. mAttachmentLimit(-1),
  44. mAnimatedObjectLimit(-1),
  45. mGroupMembershipLimit(-1),
  46. mPicksLimit(-1),
  47. mGotBenefits(false)
  48. {
  49. }
  50. void LLEconomy::setDefaultCosts(bool in_sl)
  51. {
  52. mPriceUpload = mAnimationUploadCost = mSoundUploadCost =
  53. mTextureUploadCost = m2KTextureUploadCost =
  54. in_sl ? DEFAULT_UPLOAD_COST : 0;
  55. mCreateGroupCost = in_sl ? DEFAULT_GROUP_COST : 0;
  56. llinfos << "Price per upload: " << mPriceUpload
  57. << " - Price for group creation: " << mCreateGroupCost << llendl;
  58. }
  59. void LLEconomy::processEconomyData(LLMessageSystem* msg)
  60. {
  61. if (mGotBenefits)
  62. {
  63. llinfos << "Received legacy message for economy data after valid user account benefits were set. Ignoring."
  64. << llendl;
  65. return;
  66. }
  67. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceUpload, mPriceUpload);
  68. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceGroupCreate,
  69. mCreateGroupCost);
  70. #if 0 // Old economy data, never used...
  71. S32 i;
  72. msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCapacity, i);
  73. msg->getS32Fast(_PREHASH_Info, _PREHASH_ObjectCount, i);
  74. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceEnergyUnit, i);
  75. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceObjectClaim, i);
  76. msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDecay, i);
  77. msg->getS32Fast(_PREHASH_Info, _PREHASH_PricePublicObjectDelete, i);
  78. msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceRentLight, i);
  79. msg->getS32Fast(_PREHASH_Info, _PREHASH_TeleportMinPrice, i);
  80. F32 f;
  81. msg->getF32Fast(_PREHASH_Info, _PREHASH_TeleportPriceExponent, f);
  82. #endif
  83. llinfos << "Received economy data. Price per upload: " << mPriceUpload
  84. << " - Price for group creation: " << mCreateGroupCost << llendl;
  85. if (mAnimationUploadCost == -1)
  86. {
  87. mAnimationUploadCost = mPriceUpload;
  88. }
  89. if (mSoundUploadCost == -1)
  90. {
  91. mSoundUploadCost = mPriceUpload;
  92. }
  93. if (mTextureUploadCost == -1)
  94. {
  95. mTextureUploadCost = mPriceUpload;
  96. }
  97. if (m2KTextureUploadCost == -1)
  98. {
  99. m2KTextureUploadCost = mPriceUpload;
  100. }
  101. }
  102. static std::vector<std::string> sBenefits;
  103. bool get_S32_value(const LLSD& sd, const char* key, S32& value)
  104. {
  105. if (sd.has(key))
  106. {
  107. value = sd[key].asInteger();
  108. sBenefits.emplace_back(llformat(" - %s: %d", key, value));
  109. return true;
  110. }
  111. return false;
  112. }
  113. void LLEconomy::setBenefits(const LLSD& data, const std::string& account_type)
  114. {
  115. LL_DEBUGS("Benefits") << ll_pretty_print_sd(data) << LL_ENDL;
  116. llinfos << "Account type: " << account_type << " - Setting benefits:"
  117. << llendl;
  118. mAccountType = account_type;
  119. mBenefits = data;
  120. mGotBenefits = true;
  121. get_S32_value(data, "attachment_limit", mAttachmentLimit);
  122. get_S32_value(data, "animated_object_limit", mAnimatedObjectLimit);
  123. get_S32_value(data, "picks_limit", mPicksLimit);
  124. get_S32_value(data, "group_membership_limit", mGroupMembershipLimit);
  125. if (!get_S32_value(data, "create_group_cost", mCreateGroupCost))
  126. {
  127. mGotBenefits = false;
  128. }
  129. if (get_S32_value(data, "animation_upload_cost", mAnimationUploadCost))
  130. {
  131. if (mAnimationUploadCost > mPriceUpload)
  132. {
  133. mPriceUpload = mAnimationUploadCost;
  134. }
  135. }
  136. else
  137. {
  138. mGotBenefits = false;
  139. }
  140. if (get_S32_value(data, "sound_upload_cost", mSoundUploadCost))
  141. {
  142. if (mSoundUploadCost > mPriceUpload)
  143. {
  144. mPriceUpload = mSoundUploadCost;
  145. }
  146. }
  147. else
  148. {
  149. mGotBenefits = false;
  150. }
  151. if (get_S32_value(data, "texture_upload_cost", mTextureUploadCost))
  152. {
  153. if (mTextureUploadCost > mPriceUpload)
  154. {
  155. mPriceUpload = mTextureUploadCost;
  156. }
  157. }
  158. else
  159. {
  160. mGotBenefits = false;
  161. }
  162. m2KTextureUploadCost = 0;
  163. if (data.has("large_texture_upload_cost"))
  164. {
  165. const LLSD& costs = data["large_texture_upload_cost"];
  166. if (costs.isArray())
  167. {
  168. LL_DEBUGS("Benefits") << "Large textures upload cost: "
  169. << ll_pretty_print_sd(costs) << LL_ENDL;
  170. // Apparently, LL considered several costs, but only use the
  171. // lowest. HB
  172. for (LLSD::array_const_iterator it = costs.beginArray(),
  173. end = costs.endArray();
  174. it != end; ++it)
  175. {
  176. S32 cost = it->asInteger();
  177. if (cost > 0 &&
  178. (cost < m2KTextureUploadCost || !m2KTextureUploadCost))
  179. {
  180. m2KTextureUploadCost = cost; // Use the lowest cost.
  181. }
  182. }
  183. if (m2KTextureUploadCost > 0)
  184. {
  185. sBenefits.emplace_back(llformat(" - large_texture_upload_cost: %d",
  186. m2KTextureUploadCost));
  187. }
  188. }
  189. else
  190. {
  191. get_S32_value(data, "large_texture_upload_cost",
  192. m2KTextureUploadCost);
  193. }
  194. }
  195. if (m2KTextureUploadCost <= 0)
  196. {
  197. m2KTextureUploadCost = mTextureUploadCost;
  198. }
  199. for (size_t i = 0, count = sBenefits.size(); i < count; ++i)
  200. {
  201. llinfos << sBenefits[i] << llendl;
  202. }
  203. sBenefits.clear();
  204. llinfos << "Done." << llendl;
  205. }
  206. const LLSD& LLEconomy::getBenefit(const std::string& key) const
  207. {
  208. static const LLSD empty;
  209. return mBenefits.has(key) ? mBenefits[key] : empty;
  210. }
  211. S32 LLEconomy::getTextureUploadCost(S32 tex_area) const
  212. {
  213. return tex_area > MAX_1K_TEXTURE_AREA ? m2KTextureUploadCost
  214. : mTextureUploadCost;
  215. }
  216. S32 LLEconomy::getTextureUploadCost(S32 x_size, S32 y_size) const
  217. {
  218. return x_size * y_size > MAX_1K_TEXTURE_AREA ? m2KTextureUploadCost
  219. : mTextureUploadCost;
  220. }