PageRenderTime 61ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llestateinfomodel.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 230 lines | 147 code | 37 blank | 46 comment | 3 complexity | fb9aebafaa87d2dab70c8744b1006626 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llestateinfomodel.cpp
  3. * @brief Estate 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 "llestateinfomodel.h"
  28. // libs
  29. #include "llhttpclient.h"
  30. #include "llregionflags.h"
  31. #include "message.h"
  32. // viewer
  33. #include "llagent.h"
  34. #include "llfloaterregioninfo.h" // for invoice id
  35. #include "llviewerregion.h"
  36. LLEstateInfoModel::LLEstateInfoModel()
  37. : mID(0)
  38. , mFlags(0)
  39. , mSunHour(0)
  40. {
  41. }
  42. boost::signals2::connection LLEstateInfoModel::setUpdateCallback(const update_signal_t::slot_type& cb)
  43. {
  44. return mUpdateSignal.connect(cb);
  45. }
  46. boost::signals2::connection LLEstateInfoModel::setCommitCallback(const update_signal_t::slot_type& cb)
  47. {
  48. return mCommitSignal.connect(cb);
  49. }
  50. void LLEstateInfoModel::sendEstateInfo()
  51. {
  52. if (!commitEstateInfoCaps())
  53. {
  54. // the caps method failed, try the old way
  55. LLFloaterRegionInfo::nextInvoice();
  56. commitEstateInfoDataserver();
  57. }
  58. }
  59. bool LLEstateInfoModel::getUseFixedSun() const { return mFlags & REGION_FLAGS_SUN_FIXED; }
  60. bool LLEstateInfoModel::getIsExternallyVisible() const { return mFlags & REGION_FLAGS_EXTERNALLY_VISIBLE; }
  61. bool LLEstateInfoModel::getAllowDirectTeleport() const { return mFlags & REGION_FLAGS_ALLOW_DIRECT_TELEPORT; }
  62. bool LLEstateInfoModel::getDenyAnonymous() const { return mFlags & REGION_FLAGS_DENY_ANONYMOUS; }
  63. bool LLEstateInfoModel::getDenyAgeUnverified() const { return mFlags & REGION_FLAGS_DENY_AGEUNVERIFIED; }
  64. bool LLEstateInfoModel::getAllowVoiceChat() const { return mFlags & REGION_FLAGS_ALLOW_VOICE; }
  65. void LLEstateInfoModel::setUseFixedSun(bool val) { setFlag(REGION_FLAGS_SUN_FIXED, val); }
  66. void LLEstateInfoModel::setIsExternallyVisible(bool val) { setFlag(REGION_FLAGS_EXTERNALLY_VISIBLE, val); }
  67. void LLEstateInfoModel::setAllowDirectTeleport(bool val) { setFlag(REGION_FLAGS_ALLOW_DIRECT_TELEPORT, val); }
  68. void LLEstateInfoModel::setDenyAnonymous(bool val) { setFlag(REGION_FLAGS_DENY_ANONYMOUS, val); }
  69. void LLEstateInfoModel::setDenyAgeUnverified(bool val) { setFlag(REGION_FLAGS_DENY_AGEUNVERIFIED, val); }
  70. void LLEstateInfoModel::setAllowVoiceChat(bool val) { setFlag(REGION_FLAGS_ALLOW_VOICE, val); }
  71. void LLEstateInfoModel::update(const strings_t& strings)
  72. {
  73. // NOTE: LLDispatcher extracts strings with an extra \0 at the
  74. // end. If we pass the std::string direct to the UI/renderer
  75. // it draws with a weird character at the end of the string.
  76. mName = strings[0].c_str();
  77. mOwnerID = LLUUID(strings[1].c_str());
  78. mID = strtoul(strings[2].c_str(), NULL, 10);
  79. mFlags = strtoul(strings[3].c_str(), NULL, 10);
  80. mSunHour = ((F32)(strtod(strings[4].c_str(), NULL)))/1024.0f;
  81. LL_DEBUGS("Windlight Sync") << "Received estate info: "
  82. << "is_sun_fixed = " << getUseFixedSun()
  83. << ", sun_hour = " << getSunHour() << LL_ENDL;
  84. lldebugs << getInfoDump() << llendl;
  85. // Update region owner.
  86. LLViewerRegion* regionp = gAgent.getRegion();
  87. regionp->setOwner(mOwnerID);
  88. // Let interested parties know that estate info has been updated.
  89. mUpdateSignal();
  90. }
  91. void LLEstateInfoModel::notifyCommit()
  92. {
  93. mCommitSignal();
  94. }
  95. //== PRIVATE STUFF ============================================================
  96. class LLEstateChangeInfoResponder : public LLHTTPClient::Responder
  97. {
  98. public:
  99. // if we get a normal response, handle it here
  100. virtual void result(const LLSD& content)
  101. {
  102. llinfos << "Committed estate info" << llendl;
  103. LLEstateInfoModel::instance().notifyCommit();
  104. }
  105. // if we get an error response
  106. virtual void error(U32 status, const std::string& reason)
  107. {
  108. llwarns << "Failed to commit estate info (" << status << "): " << reason << llendl;
  109. }
  110. };
  111. // tries to send estate info using a cap; returns true if it succeeded
  112. bool LLEstateInfoModel::commitEstateInfoCaps()
  113. {
  114. std::string url = gAgent.getRegion()->getCapability("EstateChangeInfo");
  115. if (url.empty())
  116. {
  117. // whoops, couldn't find the cap, so bail out
  118. return false;
  119. }
  120. LLSD body;
  121. body["estate_name" ] = getName();
  122. body["sun_hour" ] = getSunHour();
  123. body["is_sun_fixed" ] = getUseFixedSun();
  124. body["is_externally_visible"] = getIsExternallyVisible();
  125. body["allow_direct_teleport"] = getAllowDirectTeleport();
  126. body["deny_anonymous" ] = getDenyAnonymous();
  127. body["deny_age_unverified" ] = getDenyAgeUnverified();
  128. body["allow_voice_chat" ] = getAllowVoiceChat();
  129. body["invoice" ] = LLFloaterRegionInfo::getLastInvoice();
  130. LL_DEBUGS("Windlight Sync") << "Sending estate caps: "
  131. << "is_sun_fixed = " << getUseFixedSun()
  132. << ", sun_hour = " << getSunHour() << LL_ENDL;
  133. lldebugs << body << LL_ENDL;
  134. // we use a responder so that we can re-get the data after committing to the database
  135. LLHTTPClient::post(url, body, new LLEstateChangeInfoResponder);
  136. return true;
  137. }
  138. /* This is the old way of doing things, is deprecated, and should be
  139. deleted when the dataserver model can be removed */
  140. // key = "estatechangeinfo"
  141. // strings[0] = str(estate_id) (added by simulator before relay - not here)
  142. // strings[1] = estate_name
  143. // strings[2] = str(estate_flags)
  144. // strings[3] = str((S32)(sun_hour * 1024.f))
  145. void LLEstateInfoModel::commitEstateInfoDataserver()
  146. {
  147. LL_DEBUGS("Windlight Sync") << "Sending estate info: "
  148. << "is_sun_fixed = " << getUseFixedSun()
  149. << ", sun_hour = " << getSunHour() << LL_ENDL;
  150. lldebugs << getInfoDump() << LL_ENDL;
  151. LLMessageSystem* msg = gMessageSystem;
  152. msg->newMessage("EstateOwnerMessage");
  153. msg->nextBlockFast(_PREHASH_AgentData);
  154. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  155. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  156. msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
  157. msg->nextBlock("MethodData");
  158. msg->addString("Method", "estatechangeinfo");
  159. msg->addUUID("Invoice", LLFloaterRegionInfo::getLastInvoice());
  160. msg->nextBlock("ParamList");
  161. msg->addString("Parameter", getName());
  162. msg->nextBlock("ParamList");
  163. msg->addString("Parameter", llformat("%u", getFlags()));
  164. msg->nextBlock("ParamList");
  165. msg->addString("Parameter", llformat("%d", (S32) (getSunHour() * 1024.0f)));
  166. gAgent.sendMessage();
  167. }
  168. void LLEstateInfoModel::setFlag(U32 flag, bool val)
  169. {
  170. if (val)
  171. {
  172. mFlags |= flag;
  173. }
  174. else
  175. {
  176. mFlags &= ~flag;
  177. }
  178. }
  179. std::string LLEstateInfoModel::getInfoDump()
  180. {
  181. LLSD dump;
  182. dump["estate_name" ] = getName();
  183. dump["sun_hour" ] = getSunHour();
  184. dump["is_sun_fixed" ] = getUseFixedSun();
  185. dump["is_externally_visible"] = getIsExternallyVisible();
  186. dump["allow_direct_teleport"] = getAllowDirectTeleport();
  187. dump["deny_anonymous" ] = getDenyAnonymous();
  188. dump["deny_age_unverified" ] = getDenyAgeUnverified();
  189. dump["allow_voice_chat" ] = getAllowVoiceChat();
  190. std::stringstream dump_str;
  191. dump_str << dump;
  192. return dump_str.str();
  193. }