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