Commits

Stinson Linden committed eb649be

EXP-1942, EXP-1945: Improved handling of the maturity preference change response. Still needs work though.

  • Participants
  • Parent commits df17b02

Comments (0)

Files changed (2)

File indra/newview/llagent.cpp

 	mMaturityRatingChange(0U),
 	mIsDoSendMaturityPreferenceToServer(false),
 	mMaturityPreferenceConfirmCallback(NULL),
-	mMaturityPerferenceMessageId(0U),
+	mMaturityPerferenceRequestId(0U),
+	mMaturityPerferenceResponseId(0U),
+	mLastKnownRequestMaturity(SIM_ACCESS_MIN),
+	mLastKnownResponseMaturity(SIM_ACCESS_MIN),
 	mPreferredMaturityValidateSlot(),
 	mPreferredMaturityCommitSlot(),
 	mTeleportState( TELEPORT_NONE ),
 
 	mPreferredMaturityValidateSlot = gSavedSettings.getControl("PreferredMaturity")->getValidateSignal()->connect(boost::bind(&LLAgent::validateMaturity, this, _2));
 	mPreferredMaturityCommitSlot = gSavedSettings.getControl("PreferredMaturity")->getSignal()->connect(boost::bind(&LLAgent::handleMaturity, this, _2, _3));
+	mLastKnownRequestMaturity = static_cast<U8>(gSavedSettings.getU32("PreferredMaturity"));
+	mLastKnownResponseMaturity = mLastKnownRequestMaturity;
 	mIsDoSendMaturityPreferenceToServer = true;
 
 	if (!mTeleportFinishedSlot.connected())
 class LLMaturityPreferencesResponder : public LLHTTPClient::Responder
 {
 public:
-	LLMaturityPreferencesResponder(LLAgent *pAgent, unsigned int pMessageId, U8 pPreferredMaturity, U8 pPreviousMaturity, LLAgent::maturity_preferences_callback_t pMaturityPreferencesCallback);
+	LLMaturityPreferencesResponder(LLAgent *pAgent, unsigned int pRequestId, U8 pPreferredMaturity, U8 pPreviousMaturity, LLAgent::maturity_preferences_callback_t pMaturityPreferencesCallback);
 	virtual ~LLMaturityPreferencesResponder();
 
 	virtual void result(const LLSD &pContent);
 	U8 parseMaturityFromServerResponse(const LLSD &pContent);
 
 	LLAgent                                  *mAgent;
-	unsigned int                             mMessageId;
+	unsigned int                             mRequestId;
 	U8                                       mPreferredMaturity;
 	U8                                       mPreviousMaturity;
 	LLAgent::maturity_preferences_callback_t mMaturityPreferencesCallback;
 };
 
-LLMaturityPreferencesResponder::LLMaturityPreferencesResponder(LLAgent *pAgent, unsigned int pMessageId, U8 pPreferredMaturity, U8 pPreviousMaturity, LLAgent::maturity_preferences_callback_t pMaturityPreferencesCallback)
+LLMaturityPreferencesResponder::LLMaturityPreferencesResponder(LLAgent *pAgent, unsigned int pRequestId, U8 pPreferredMaturity, U8 pPreviousMaturity, LLAgent::maturity_preferences_callback_t pMaturityPreferencesCallback)
 	: LLHTTPClient::Responder(),
 	mAgent(pAgent),
-	mMessageId(pMessageId),
+	mRequestId(pRequestId),
 	mPreferredMaturity(pPreferredMaturity),
 	mPreviousMaturity(pPreviousMaturity),
 	mMaturityPreferencesCallback(pMaturityPreferencesCallback)
 			<< "' to '" << LLViewerRegion::accessToString(mPreferredMaturity) << "', the server responded with '"
 			<< LLViewerRegion::accessToString(actualMaturity) << "' [value:" << static_cast<U32>(actualMaturity) << ", llsd:"
 			<< pContent << "]" << llendl;
-		mAgent->handlePreferredMaturityResult(mMessageId, actualMaturity);
+		mAgent->handlePreferredMaturityResult(mRequestId, actualMaturity);
 	}
 	else
 	{
 			<< "' to '" << LLViewerRegion::accessToString(mPreferredMaturity) << "', the server responded with '"
 			<< LLViewerRegion::accessToString(actualMaturity) << "' [value:" << static_cast<U32>(actualMaturity) << ", llsd:"
 			<< pContent << "]" << llendl;
-		mAgent->handlePreferredMaturityUnexpectedResult(mMessageId, mPreferredMaturity, mPreviousMaturity, actualMaturity);
+		mAgent->handlePreferredMaturityUnexpectedResult(mRequestId, mPreferredMaturity, mPreviousMaturity, actualMaturity);
 	}
 
 	if (!mMaturityPreferencesCallback.empty())
 	llwarns << "while attempting to change maturity preference from '" << LLViewerRegion::accessToString(mPreviousMaturity)
 		<< "' to '" << LLViewerRegion::accessToString(mPreferredMaturity) << "', we got an error because '"
 		<< pReason << "' [status:" << pStatus << "]" << llendl;
-	mAgent->handlePreferredMaturityError(mMessageId, mPreferredMaturity, mPreviousMaturity);
+	mAgent->handlePreferredMaturityError(mRequestId, mPreferredMaturity, mPreviousMaturity);
 	if (!mMaturityPreferencesCallback.empty())
 	{
 		mMaturityPreferencesCallback(mPreviousMaturity);
 	U8 maturity = SIM_ACCESS_MIN;
 	if (pContent.isUndefined())
 	{
-		maturity = mPreviousMaturity;
+		maturity = mPreferredMaturity;
 	}
 	else
 	{
 	mMaturityPreferenceConfirmCallback = NULL;
 }
 
-void LLAgent::handlePreferredMaturityResult(unsigned int pMessageId, U8 pServerMaturity)
+void LLAgent::handlePreferredMaturityResult(unsigned int pRequestId, U8 pServerMaturity)
 {
-	llassert(pMessageId <= mMaturityPerferenceMessageId);
-	if (pMessageId < mMaturityPerferenceMessageId)
+	++mMaturityPerferenceResponseId;
+	mLastKnownResponseMaturity = pServerMaturity;
+	llassert(mMaturityPerferenceResponseId <= mMaturityPerferenceRequestId);
+	if (mMaturityPerferenceResponseId == mMaturityPerferenceRequestId)
 	{
-		llwarns << "out of order result while changing maturity preference" << llendl;
+		U8 localMaturity = static_cast<U8>(gSavedSettings.getU32("PreferredMaturity"));
+		if (localMaturity != mLastKnownResponseMaturity)
+		{
+			bool tmpIsDoSendMaturityPreferenceToServer = mIsDoSendMaturityPreferenceToServer;
+			mIsDoSendMaturityPreferenceToServer = false;
+			llinfos << "Setting viewer preferred maturity to '" << LLViewerRegion::accessToString(pServerMaturity) << "'" << llendl;
+			gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(pServerMaturity));
+			mIsDoSendMaturityPreferenceToServer = tmpIsDoSendMaturityPreferenceToServer;
+		}
+		if (mLastKnownRequestMaturity != mLastKnownResponseMaturity)
+		{
+			llwarns << "Last known requested maturity '" << LLViewerRegion::accessToString(mLastKnownRequestMaturity)
+				<< "' does not match last known response maturity '" << LLViewerRegion::accessToString(mLastKnownResponseMaturity)
+				<< "'" << llendl;
+		}
 	}
-	U8 localMaturity = static_cast<U8>(gSavedSettings.getU32("PreferredMaturity"));
-	if (localMaturity != pServerMaturity)
+}
+
+void LLAgent::handlePreferredMaturityError(unsigned int pRequestId, U8 pPreferredMaturity, U8 pPreviousMaturity)
+{
+	++mMaturityPerferenceResponseId;
+	llassert(mMaturityPerferenceResponseId <= mMaturityPerferenceRequestId);
+	if (mMaturityPerferenceResponseId == mMaturityPerferenceRequestId)
 	{
-		bool tmpIsDoSendMaturityPreferenceToServer = mIsDoSendMaturityPreferenceToServer;
-		mIsDoSendMaturityPreferenceToServer = false;
-		llinfos << "Setting viewer preferred maturity to '" << LLViewerRegion::accessToString(pServerMaturity) << "'" << llendl;
-		gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(pServerMaturity));
-		mIsDoSendMaturityPreferenceToServer = tmpIsDoSendMaturityPreferenceToServer;
+		U8 localMaturity = static_cast<U8>(gSavedSettings.getU32("PreferredMaturity"));
+		if (localMaturity != mLastKnownResponseMaturity)
+		{
+			bool tmpIsDoSendMaturityPreferenceToServer = mIsDoSendMaturityPreferenceToServer;
+			mIsDoSendMaturityPreferenceToServer = false;
+			llinfos << "Setting viewer preferred maturity to '" << LLViewerRegion::accessToString(mLastKnownResponseMaturity) << "'" << llendl;
+			gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(mLastKnownResponseMaturity));
+			mIsDoSendMaturityPreferenceToServer = tmpIsDoSendMaturityPreferenceToServer;
+		}
 	}
 }
 
-void LLAgent::handlePreferredMaturityError(unsigned int pMessageId, U8 pPreferredMaturity, U8 pPreviousMaturity)
+void LLAgent::handlePreferredMaturityUnexpectedResult(unsigned int pRequestId, U8 pPreferredMaturity, U8 pPreviousMaturity, U8 pServerMaturity)
 {
-	llassert(pMessageId <= mMaturityPerferenceMessageId);
-	if (pMessageId < mMaturityPerferenceMessageId)
+	++mMaturityPerferenceResponseId;
+	mLastKnownResponseMaturity = pServerMaturity;
+	llassert(mMaturityPerferenceResponseId <= mMaturityPerferenceRequestId);
+	if (mMaturityPerferenceResponseId == mMaturityPerferenceRequestId)
 	{
-		llwarns << "out of order result while changing maturity preference" << llendl;
+		U8 localMaturity = static_cast<U8>(gSavedSettings.getU32("PreferredMaturity"));
+		if (localMaturity != mLastKnownResponseMaturity)
+		{
+			bool tmpIsDoSendMaturityPreferenceToServer = mIsDoSendMaturityPreferenceToServer;
+			mIsDoSendMaturityPreferenceToServer = false;
+			llinfos << "Setting viewer preferred maturity to '" << LLViewerRegion::accessToString(pServerMaturity) << "'" << llendl;
+			gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(pServerMaturity));
+			mIsDoSendMaturityPreferenceToServer = tmpIsDoSendMaturityPreferenceToServer;
+		}
+		if (mLastKnownRequestMaturity != mLastKnownResponseMaturity)
+		{
+			llwarns << "Last known requested maturity '" << LLViewerRegion::accessToString(mLastKnownRequestMaturity)
+				<< "' does not match last known response maturity '" << LLViewerRegion::accessToString(mLastKnownResponseMaturity)
+				<< "'" << llendl;
+		}
 	}
-	if (pMessageId == mMaturityPerferenceMessageId)
-	{
-		bool tmpIsDoSendMaturityPreferenceToServer = mIsDoSendMaturityPreferenceToServer;
-		mIsDoSendMaturityPreferenceToServer = false;
-		llinfos << "Setting viewer preferred maturity to '" << LLViewerRegion::accessToString(pPreviousMaturity) << "'" << llendl;
-		gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(pPreviousMaturity));
-		mIsDoSendMaturityPreferenceToServer = tmpIsDoSendMaturityPreferenceToServer;
-	}
-}
-
-void LLAgent::handlePreferredMaturityUnexpectedResult(unsigned int pMessageId, U8 pPreferredMaturity, U8 pPreviousMaturity, U8 pServerMaturity)
-{
-	llassert(pMessageId <= mMaturityPerferenceMessageId);
-	if (pMessageId < mMaturityPerferenceMessageId)
-	{
-		llwarns << "out of order result while changing maturity preference" << llendl;
-	}
-	bool tmpIsDoSendMaturityPreferenceToServer = mIsDoSendMaturityPreferenceToServer;
-	mIsDoSendMaturityPreferenceToServer = false;
-	llinfos << "Setting viewer preferred maturity to '" << LLViewerRegion::accessToString(pServerMaturity) << "'" << llendl;
-	gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(pServerMaturity));
-	mIsDoSendMaturityPreferenceToServer = tmpIsDoSendMaturityPreferenceToServer;
 }
 
 void LLAgent::sendMaturityPreferenceToServer(U8 pPreferredMaturity, U8 pPreviousMaturity)
 {
 	if (mIsDoSendMaturityPreferenceToServer)
 	{
-		LLHTTPClient::ResponderPtr responderPtr = LLHTTPClient::ResponderPtr(new LLMaturityPreferencesResponder(this, ++mMaturityPerferenceMessageId, pPreferredMaturity, pPreviousMaturity, mMaturityPreferenceConfirmCallback));
+		mLastKnownRequestMaturity = pPreferredMaturity;
+		LLHTTPClient::ResponderPtr responderPtr = LLHTTPClient::ResponderPtr(new LLMaturityPreferencesResponder(this, ++mMaturityPerferenceRequestId, pPreferredMaturity, pPreviousMaturity, mMaturityPreferenceConfirmCallback));
 		if (getRegion() == NULL)
 		{
 			responderPtr->error(0U, "region is not defined");

File indra/newview/llagent.h

 private:
 	bool                            mIsDoSendMaturityPreferenceToServer;
 	maturity_preferences_callback_t mMaturityPreferenceConfirmCallback;
-	unsigned int                    mMaturityPerferenceMessageId;
+	unsigned int                    mMaturityPerferenceRequestId;
+	unsigned int                    mMaturityPerferenceResponseId;
+	U8                              mLastKnownRequestMaturity;
+	U8                              mLastKnownResponseMaturity;
 	boost::signals2::connection     mPreferredMaturityValidateSlot;
 	boost::signals2::connection     mPreferredMaturityCommitSlot;
 
 	void 			sendMaturityPreferenceToServer(U8 pPreferredMaturity, U8 pPreviousMaturity); // ! "U8" instead of "int"?
 
 	friend class LLMaturityPreferencesResponder;
-	void            handlePreferredMaturityResult(unsigned int pMessageId, U8 pServerMaturity);
-	void            handlePreferredMaturityError(unsigned int pMessageId, U8 pPreferredMaturity, U8 pPreviousMaturity);
-	void            handlePreferredMaturityUnexpectedResult(unsigned int pMessageId, U8 pPreferredMaturity, U8 pPreviousMaturity, U8 pServerMaturity);
+	void            handlePreferredMaturityResult(unsigned int pRequestId, U8 pServerMaturity);
+	void            handlePreferredMaturityError(unsigned int pRequestId, U8 pPreferredMaturity, U8 pPreviousMaturity);
+	void            handlePreferredMaturityUnexpectedResult(unsigned int pRequestId, U8 pPreferredMaturity, U8 pPreviousMaturity, U8 pServerMaturity);
 
 	// Maturity callbacks for PreferredMaturity control variable
 	void 			handleMaturity(const LLSD &pNewValue, const LLSD &pPreviousValue);