/indra/newview/llregioninfomodel.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 217 lines · 142 code · 30 blank · 45 comment · 6 complexity · 4b8b20352a76684fe4ff9b9343432674 MD5 · raw file

  1. /**
  2. * @file llregioninfomodel.cpp
  3. * @brief Region info model
  4. *
  5. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llregioninfomodel.h"
  28. // libs
  29. #include "message.h"
  30. #include "llregionflags.h"
  31. // viewer
  32. #include "llagent.h"
  33. #include "llviewerregion.h"
  34. void LLRegionInfoModel::reset()
  35. {
  36. mSimAccess = 0;
  37. mAgentLimit = 0;
  38. mRegionFlags = 0;
  39. mEstateID = 0;
  40. mParentEstateID = 0;
  41. mPricePerMeter = 0;
  42. mRedirectGridX = 0;
  43. mRedirectGridY = 0;
  44. mBillableFactor = 0.0f;
  45. mObjectBonusFactor = 0.0f;
  46. mWaterHeight = 0.0f;
  47. mTerrainRaiseLimit = 0.0f;
  48. mTerrainLowerLimit = 0.0f;
  49. mSunHour = 0.0f;
  50. mUseEstateSun = false;
  51. mSimType.clear();
  52. mSimName.clear();
  53. }
  54. LLRegionInfoModel::LLRegionInfoModel()
  55. {
  56. reset();
  57. }
  58. boost::signals2::connection LLRegionInfoModel::setUpdateCallback(const update_signal_t::slot_type& cb)
  59. {
  60. return mUpdateSignal.connect(cb);
  61. }
  62. void LLRegionInfoModel::sendRegionTerrain(const LLUUID& invoice) const
  63. {
  64. std::string buffer;
  65. std::vector<std::string> strings;
  66. // ==========================================
  67. // Assemble and send setregionterrain message
  68. // "setregionterrain"
  69. // strings[0] = float water height
  70. // strings[1] = float terrain raise
  71. // strings[2] = float terrain lower
  72. // strings[3] = 'Y' use estate time
  73. // strings[4] = 'Y' fixed sun
  74. // strings[5] = float sun_hour
  75. // strings[6] = from estate, 'Y' use global time
  76. // strings[7] = from estate, 'Y' fixed sun
  77. // strings[8] = from estate, float sun_hour
  78. // *NOTE: this resets estate sun info.
  79. BOOL estate_global_time = true;
  80. BOOL estate_fixed_sun = false;
  81. F32 estate_sun_hour = 0.f;
  82. buffer = llformat("%f", mWaterHeight);
  83. strings.push_back(buffer);
  84. buffer = llformat("%f", mTerrainRaiseLimit);
  85. strings.push_back(buffer);
  86. buffer = llformat("%f", mTerrainLowerLimit);
  87. strings.push_back(buffer);
  88. buffer = llformat("%s", (mUseEstateSun ? "Y" : "N"));
  89. strings.push_back(buffer);
  90. buffer = llformat("%s", (getUseFixedSun() ? "Y" : "N"));
  91. strings.push_back(buffer);
  92. buffer = llformat("%f", mSunHour);
  93. strings.push_back(buffer);
  94. buffer = llformat("%s", (estate_global_time ? "Y" : "N") );
  95. strings.push_back(buffer);
  96. buffer = llformat("%s", (estate_fixed_sun ? "Y" : "N") );
  97. strings.push_back(buffer);
  98. buffer = llformat("%f", estate_sun_hour);
  99. strings.push_back(buffer);
  100. sendEstateOwnerMessage(gMessageSystem, "setregionterrain", invoice, strings);
  101. }
  102. bool LLRegionInfoModel::getUseFixedSun() const
  103. {
  104. return mRegionFlags & REGION_FLAGS_SUN_FIXED;
  105. }
  106. void LLRegionInfoModel::setUseFixedSun(bool fixed)
  107. {
  108. if (fixed)
  109. {
  110. mRegionFlags |= REGION_FLAGS_SUN_FIXED;
  111. }
  112. else
  113. {
  114. mRegionFlags &= ~REGION_FLAGS_SUN_FIXED;
  115. }
  116. }
  117. void LLRegionInfoModel::update(LLMessageSystem* msg)
  118. {
  119. reset();
  120. msg->getStringFast(_PREHASH_RegionInfo, _PREHASH_SimName, mSimName);
  121. msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_EstateID, mEstateID);
  122. msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_ParentEstateID, mParentEstateID);
  123. msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_RegionFlags, mRegionFlags);
  124. msg->getU8Fast(_PREHASH_RegionInfo, _PREHASH_SimAccess, mSimAccess);
  125. msg->getU8Fast(_PREHASH_RegionInfo, _PREHASH_MaxAgents, mAgentLimit);
  126. msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_ObjectBonusFactor, mObjectBonusFactor);
  127. msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_BillableFactor, mBillableFactor);
  128. msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_WaterHeight, mWaterHeight);
  129. msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainRaiseLimit, mTerrainRaiseLimit);
  130. msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainLowerLimit, mTerrainLowerLimit);
  131. msg->getS32Fast(_PREHASH_RegionInfo, _PREHASH_PricePerMeter, mPricePerMeter);
  132. msg->getS32Fast(_PREHASH_RegionInfo, _PREHASH_RedirectGridX, mRedirectGridX);
  133. msg->getS32Fast(_PREHASH_RegionInfo, _PREHASH_RedirectGridY, mRedirectGridY);
  134. msg->getBOOL(_PREHASH_RegionInfo, _PREHASH_UseEstateSun, mUseEstateSun);
  135. // actually the "last set" sun hour, not the current sun hour. JC
  136. msg->getF32(_PREHASH_RegionInfo, _PREHASH_SunHour, mSunHour);
  137. LL_DEBUGS("Windlight Sync") << "Got region sun hour: " << mSunHour << LL_ENDL;
  138. // the only reasonable way to decide if we actually have any data is to
  139. // check to see if any of these fields have nonzero sizes
  140. if (msg->getSize(_PREHASH_RegionInfo2, _PREHASH_ProductSKU) > 0 ||
  141. msg->getSize(_PREHASH_RegionInfo2, "ProductName") > 0)
  142. {
  143. msg->getString(_PREHASH_RegionInfo2, "ProductName", mSimType);
  144. }
  145. // Let interested parties know that region info has been updated.
  146. mUpdateSignal();
  147. }
  148. // static
  149. void LLRegionInfoModel::sendEstateOwnerMessage(
  150. LLMessageSystem* msg,
  151. const std::string& request,
  152. const LLUUID& invoice,
  153. const std::vector<std::string>& strings)
  154. {
  155. LLViewerRegion* cur_region = gAgent.getRegion();
  156. if (!cur_region)
  157. {
  158. llwarns << "Agent region not set" << llendl;
  159. return;
  160. }
  161. llinfos << "Sending estate request '" << request << "'" << llendl;
  162. msg->newMessage("EstateOwnerMessage");
  163. msg->nextBlockFast(_PREHASH_AgentData);
  164. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  165. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  166. msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
  167. msg->nextBlock("MethodData");
  168. msg->addString("Method", request);
  169. msg->addUUID("Invoice", invoice);
  170. if (strings.empty())
  171. {
  172. msg->nextBlock("ParamList");
  173. msg->addString("Parameter", NULL);
  174. }
  175. else
  176. {
  177. std::vector<std::string>::const_iterator it = strings.begin();
  178. std::vector<std::string>::const_iterator end = strings.end();
  179. for (unsigned i = 0; it != end; ++it, ++i)
  180. {
  181. lldebugs << "- [" << i << "] " << (*it) << llendl;
  182. msg->nextBlock("ParamList");
  183. msg->addString("Parameter", *it);
  184. }
  185. }
  186. msg->sendReliable(cur_region->getHost());
  187. }