From 2e5e03b73a5bc581097c9b5828537796568aa2e3 Mon Sep 17 00:00:00 2001
From: dmitrykproductengine <none@none>
Date: Wed, 25 Sep 2013 12:58:16 +0300
Subject: [PATCH] MAINT-3169 FIXED [Improvement] Prevent latest Voice service
 from connecting or error popup from occurring when Voice Chat setting is
 disabled in the viewer.

---
 indra/newview/llvoicevivox.cpp | 11 ++++++++---
 indra/newview/llvoicevivox.h   |  2 ++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp
index 9497041482..050d9dd785 100755
--- a/indra/newview/llvoicevivox.cpp
+++ b/indra/newview/llvoicevivox.cpp
@@ -261,6 +261,7 @@ LLVivoxVoiceClient::LLVivoxVoiceClient() :
 	mSessionTerminateRequested(false),
 	mRelogRequested(false),
 	mConnected(false),
+	mTerminateDaemon(false),
 	mPump(NULL),
 	mSpatialJoiningNum(0),
 
@@ -695,7 +696,7 @@ void LLVivoxVoiceClient::stateMachine()
 		setVoiceEnabled(false);
 	}
 	
-	if(mVoiceEnabled || !mIsInitialized)
+	if(mVoiceEnabled || (!mIsInitialized &&!mTerminateDaemon) )
 	{
 		updatePosition();
 	}
@@ -708,11 +709,12 @@ void LLVivoxVoiceClient::stateMachine()
 		if((getState() != stateDisabled) && (getState() != stateDisableCleanup))
 		{
 			// User turned off voice support.  Send the cleanup messages, close the socket, and reset.
-			if(!mConnected)
+			if(!mConnected || mTerminateDaemon)
 			{
 				// if voice was turned off after the daemon was launched but before we could connect to it, we may need to issue a kill.
 				LL_INFOS("Voice") << "Disabling voice before connection to daemon, terminating." << LL_ENDL;
 				killGateway();
+				mTerminateDaemon = false;
 			}
 			
 			logout();
@@ -753,7 +755,7 @@ void LLVivoxVoiceClient::stateMachine()
 				// Voice is locked out, we must not launch the vivox daemon.
 				setState(stateJail);
 			}
-			else if(!isGatewayRunning())
+			else if(!isGatewayRunning() && gSavedSettings.getBOOL("EnableVoiceChat"))
 			{
 				if (true)           // production build, not test
 				{
@@ -1136,6 +1138,7 @@ void LLVivoxVoiceClient::stateMachine()
 				std::stringstream errs;
 				errs << mVoiceAccountServerURI << "\n:UDP: 3478, 3479, 5060, 5062, 12000-17000";
 				args["HOSTID"] = errs.str();
+				mTerminateDaemon = true;
 				if (LLGridManager::getInstance()->isSystemGrid())
 				{
 					LLNotificationsUtil::add("NoVoiceConnect", args);	
@@ -2618,6 +2621,7 @@ void LLVivoxVoiceClient::connectorCreateResponse(int statusCode, std::string &st
 		std::stringstream errs;
 		errs << mVoiceAccountServerURI << "\n:UDP: 3478, 3479, 5060, 5062, 12000-17000";
 		args["HOSTID"] = errs.str();
+		mTerminateDaemon = true;
 		if (LLGridManager::getInstance()->isSystemGrid())
 		{
 			LLNotificationsUtil::add("NoVoiceConnect", args);	
@@ -2633,6 +2637,7 @@ void LLVivoxVoiceClient::connectorCreateResponse(int statusCode, std::string &st
 		LL_INFOS("Voice") << "Connector.Create succeeded, Vivox SDK version is " << versionID << LL_ENDL;
 		mVoiceVersion.serverVersion = versionID;
 		mConnectorHandle = connectorHandle;
+		mTerminateDaemon = false;
 		if(getState() == stateConnectorStarting)
 		{
 			setState(stateConnectorStarted);
diff --git a/indra/newview/llvoicevivox.h b/indra/newview/llvoicevivox.h
index e2d1585c15..c325d72ba6 100755
--- a/indra/newview/llvoicevivox.h
+++ b/indra/newview/llvoicevivox.h
@@ -659,6 +659,8 @@ private:
 	LLSocket::ptr_t mSocket;
 	bool mConnected;
 	
+	// We should kill the voice daemon in case of connection alert 
+	bool mTerminateDaemon;
 	
 	LLPumpIO *mPump;
 	friend class LLVivoxProtocolParser;
-- 
GitLab