PageRenderTime 1625ms CodeModel.GetById 191ms app.highlight 732ms RepoModel.GetById 592ms app.codeStats 1ms

/indra/newview/llstartup.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 2004 lines | 1358 code | 273 blank | 373 comment | 210 complexity | 603f9e6c06d16124425fed069407d556 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/** 
   2 * @file llstartup.cpp
   3 * @brief startup routines.
   4 *
   5 * $LicenseInfo:firstyear=2004&license=viewerlgpl$
   6 * Second Life Viewer Source Code
   7 * Copyright (C) 2010, 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 "llstartup.h"
  30
  31#if LL_WINDOWS
  32#	include <process.h>		// _spawnl()
  33#else
  34#	include <sys/stat.h>		// mkdir()
  35#endif
  36
  37#include "llviewermedia_streamingaudio.h"
  38#include "llaudioengine.h"
  39
  40#ifdef LL_FMOD
  41# include "llaudioengine_fmod.h"
  42#endif
  43
  44#ifdef LL_OPENAL
  45#include "llaudioengine_openal.h"
  46#endif
  47
  48#include "llares.h"
  49#include "llavatarnamecache.h"
  50#include "lllandmark.h"
  51#include "llcachename.h"
  52#include "lldir.h"
  53#include "llerrorcontrol.h"
  54#include "llfloaterreg.h"
  55#include "llfocusmgr.h"
  56#include "llhttpsender.h"
  57#include "llimfloater.h"
  58#include "lllocationhistory.h"
  59#include "llimageworker.h"
  60
  61#include "llloginflags.h"
  62#include "llmd5.h"
  63#include "llmemorystream.h"
  64#include "llmessageconfig.h"
  65#include "llmoveview.h"
  66#include "llnearbychat.h"
  67#include "llnotifications.h"
  68#include "llnotificationsutil.h"
  69#include "llteleporthistory.h"
  70#include "llregionhandle.h"
  71#include "llsd.h"
  72#include "llsdserialize.h"
  73#include "llsdutil_math.h"
  74#include "llsecondlifeurls.h"
  75#include "llstring.h"
  76#include "lluserrelations.h"
  77#include "llversioninfo.h"
  78#include "llviewercontrol.h"
  79#include "llviewerhelp.h"
  80#include "llvfs.h"
  81#include "llxorcipher.h"	// saved password, MAC address
  82#include "llwindow.h"
  83#include "imageids.h"
  84#include "message.h"
  85#include "v3math.h"
  86
  87#include "llagent.h"
  88#include "llagentcamera.h"
  89#include "llagentpicksinfo.h"
  90#include "llagentwearables.h"
  91#include "llagentpilot.h"
  92#include "llfloateravatarpicker.h"
  93#include "llcallbacklist.h"
  94#include "llcallingcard.h"
  95#include "llconsole.h"
  96#include "llcontainerview.h"
  97#include "lldebugview.h"
  98#include "lldrawable.h"
  99#include "lleventnotifier.h"
 100#include "llface.h"
 101#include "llfeaturemanager.h"
 102//#include "llfirstuse.h"
 103#include "llfloaterhud.h"
 104#include "llfloaterland.h"
 105#include "llfloaterpreference.h"
 106#include "llfloatertopobjects.h"
 107#include "llfloaterworldmap.h"
 108#include "llgesturemgr.h"
 109#include "llgroupmgr.h"
 110#include "llhudeffecttrail.h"
 111#include "llhudmanager.h"
 112#include "llhttpclient.h"
 113#include "llimagebmp.h"
 114#include "llinventorybridge.h"
 115#include "llinventorymodel.h"
 116#include "llinventorymodelbackgroundfetch.h"
 117#include "llkeyboard.h"
 118#include "llloginhandler.h"			// gLoginHandler, SLURL support
 119#include "lllogininstance.h" // Host the login module.
 120#include "llpanellogin.h"
 121#include "llmutelist.h"
 122#include "llavatarpropertiesprocessor.h"
 123#include "llpanelclassified.h"
 124#include "llpanelpick.h"
 125#include "llpanelgrouplandmoney.h"
 126#include "llpanelgroupnotices.h"
 127#include "llpreview.h"
 128#include "llpreviewscript.h"
 129#include "llproxy.h"
 130#include "llproductinforequest.h"
 131#include "llsecondlifeurls.h"
 132#include "llselectmgr.h"
 133#include "llsky.h"
 134#include "llstatview.h"
 135#include "llstatusbar.h"		// sendMoneyBalanceRequest(), owns L$ balance
 136#include "llsurface.h"
 137#include "lltexturecache.h"
 138#include "lltexturefetch.h"
 139#include "lltoolmgr.h"
 140#include "lltrans.h"
 141#include "llui.h"
 142#include "llurldispatcher.h"
 143#include "llurlentry.h"
 144#include "llslurl.h"
 145#include "llurlhistory.h"
 146#include "llurlwhitelist.h"
 147#include "llvieweraudio.h"
 148#include "llviewerassetstorage.h"
 149#include "llviewercamera.h"
 150#include "llviewerdisplay.h"
 151#include "llviewergenericmessage.h"
 152#include "llviewergesture.h"
 153#include "llviewertexturelist.h"
 154#include "llviewermedia.h"
 155#include "llviewermenu.h"
 156#include "llviewermessage.h"
 157#include "llviewernetwork.h"
 158#include "llviewerobjectlist.h"
 159#include "llviewerparcelmedia.h"
 160#include "llviewerparcelmgr.h"
 161#include "llviewerregion.h"
 162#include "llviewerstats.h"
 163#include "llviewerthrottle.h"
 164#include "llviewerwindow.h"
 165#include "llvoavatar.h"
 166#include "llvoavatarself.h"
 167#include "llweb.h"
 168#include "llworld.h"
 169#include "llworldmapmessage.h"
 170#include "llxfermanager.h"
 171#include "pipeline.h"
 172#include "llappviewer.h"
 173#include "llfasttimerview.h"
 174#include "llfloatermap.h"
 175#include "llweb.h"
 176#include "llvoiceclient.h"
 177#include "llnamelistctrl.h"
 178#include "llnamebox.h"
 179#include "llnameeditor.h"
 180#include "llpostprocess.h"
 181#include "llwlparammanager.h"
 182#include "llwaterparammanager.h"
 183#include "llagentlanguage.h"
 184#include "llwearable.h"
 185#include "llinventorybridge.h"
 186#include "llappearancemgr.h"
 187#include "llavatariconctrl.h"
 188#include "llvoicechannel.h"
 189
 190#include "lllogin.h"
 191#include "llevents.h"
 192#include "llstartuplistener.h"
 193#include "lltoolbarview.h"
 194
 195#if LL_WINDOWS
 196#include "lldxhardware.h"
 197#endif
 198
 199//
 200// exported globals
 201//
 202bool gAgentMovementCompleted = false;
 203S32  gMaxAgentGroups;
 204
 205std::string SCREEN_HOME_FILENAME = "screen_home.bmp";
 206std::string SCREEN_LAST_FILENAME = "screen_last.bmp";
 207
 208LLPointer<LLViewerTexture> gStartTexture;
 209
 210//
 211// Imported globals
 212//
 213extern S32 gStartImageWidth;
 214extern S32 gStartImageHeight;
 215
 216//
 217// local globals
 218//
 219static bool gGotUseCircuitCodeAck = false;
 220static std::string sInitialOutfit;
 221static std::string sInitialOutfitGender;	// "male" or "female"
 222static boost::signals2::connection sWearablesLoadedCon;
 223
 224static bool gUseCircuitCallbackCalled = false;
 225
 226EStartupState LLStartUp::gStartupState = STATE_FIRST;
 227LLSLURL LLStartUp::sStartSLURL;
 228
 229static LLPointer<LLCredential> gUserCredential;
 230static std::string gDisplayName;
 231static BOOL gRememberPassword = TRUE;     
 232
 233static U64 gFirstSimHandle = 0;
 234static LLHost gFirstSim;
 235static std::string gFirstSimSeedCap;
 236static LLVector3 gAgentStartLookAt(1.0f, 0.f, 0.f);
 237static std::string gAgentStartLocation = "safe";
 238static bool mLoginStatePastUI = false;
 239
 240
 241boost::scoped_ptr<LLEventPump> LLStartUp::sStateWatcher(new LLEventStream("StartupState"));
 242boost::scoped_ptr<LLStartupListener> LLStartUp::sListener(new LLStartupListener());
 243
 244//
 245// local function declaration
 246//
 247
 248void login_show();
 249void login_callback(S32 option, void* userdata);
 250void show_first_run_dialog();
 251bool first_run_dialog_callback(const LLSD& notification, const LLSD& response);
 252void set_startup_status(const F32 frac, const std::string& string, const std::string& msg);
 253bool login_alert_status(const LLSD& notification, const LLSD& response);
 254void login_packet_failed(void**, S32 result);
 255void use_circuit_callback(void**, S32 result);
 256void register_viewer_callbacks(LLMessageSystem* msg);
 257void asset_callback_nothing(LLVFS*, const LLUUID&, LLAssetType::EType, void*, S32);
 258bool callback_choose_gender(const LLSD& notification, const LLSD& response);
 259void init_start_screen(S32 location_id);
 260void release_start_screen();
 261void reset_login();
 262LLSD transform_cert_args(LLPointer<LLCertificate> cert);
 263void general_cert_done(const LLSD& notification, const LLSD& response);
 264void trust_cert_done(const LLSD& notification, const LLSD& response);
 265void apply_udp_blacklist(const std::string& csv);
 266bool process_login_success_response();
 267void transition_back_to_login_panel(const std::string& emsg);
 268
 269void callback_cache_name(const LLUUID& id, const std::string& full_name, bool is_group)
 270{
 271	LLNameBox::refreshAll(id, full_name, is_group);
 272	LLNameEditor::refreshAll(id, full_name, is_group);
 273	
 274	// TODO: Actually be intelligent about the refresh.
 275	// For now, just brute force refresh the dialogs.
 276	dialog_refresh_all();
 277}
 278
 279//
 280// exported functionality
 281//
 282
 283//
 284// local classes
 285//
 286
 287namespace
 288{
 289	class LLNullHTTPSender : public LLHTTPSender
 290	{
 291		virtual void send(const LLHost& host, 
 292						  const std::string& message, const LLSD& body, 
 293						  LLHTTPClient::ResponderPtr response) const
 294		{
 295			LL_WARNS("AppInit") << " attemped to send " << message << " to " << host
 296					<< " with null sender" << LL_ENDL;
 297		}
 298	};
 299}
 300
 301void update_texture_fetch()
 302{
 303	LLAppViewer::getTextureCache()->update(1); // unpauses the texture cache thread
 304	LLAppViewer::getImageDecodeThread()->update(1); // unpauses the image thread
 305	LLAppViewer::getTextureFetch()->update(1); // unpauses the texture fetch thread
 306	gTextureList.updateImages(0.10f);
 307}
 308
 309// Returns false to skip other idle processing. Should only return
 310// true when all initialization done.
 311bool idle_startup()
 312{
 313	LLMemType mt1(LLMemType::MTYPE_STARTUP);
 314	
 315	const F32 PRECACHING_DELAY = gSavedSettings.getF32("PrecachingDelay");
 316	static LLTimer timeout;
 317	static S32 timeout_count = 0;
 318
 319	static LLTimer login_time;
 320
 321	// until this is encapsulated, this little hack for the
 322	// auth/transform loop will do.
 323	static F32 progress = 0.10f;
 324
 325	static std::string auth_desc;
 326	static std::string auth_message;
 327
 328	static LLVector3 initial_sun_direction(1.f, 0.f, 0.f);
 329	static LLVector3 agent_start_position_region(10.f, 10.f, 10.f);		// default for when no space server
 330
 331	// last location by default
 332	static S32  agent_location_id = START_LOCATION_ID_LAST;
 333	static S32  location_which = START_LOCATION_ID_LAST;
 334
 335	static bool show_connect_box = true;
 336
 337	//static bool stipend_since_login = false;
 338
 339	// HACK: These are things from the main loop that usually aren't done
 340	// until initialization is complete, but need to be done here for things
 341	// to work.
 342	gIdleCallbacks.callFunctions();
 343	gViewerWindow->updateUI();
 344	LLMortician::updateClass();
 345
 346	const std::string delims (" ");
 347	std::string system;
 348	int begIdx, endIdx;
 349	std::string osString = LLAppViewer::instance()->getOSInfo().getOSStringSimple();
 350
 351	begIdx = osString.find_first_not_of (delims);
 352	endIdx = osString.find_first_of (delims, begIdx);
 353	system = osString.substr (begIdx, endIdx - begIdx);
 354	system += "Locale";
 355
 356	LLStringUtil::setLocale (LLTrans::getString(system));
 357
 358	//note: Removing this line will cause incorrect button size in the login screen. -- bao.
 359	gTextureList.updateImages(0.01f) ;
 360
 361	if ( STATE_FIRST == LLStartUp::getStartupState() )
 362	{
 363		gViewerWindow->showCursor(); 
 364		gViewerWindow->getWindow()->setCursor(UI_CURSOR_WAIT);
 365
 366		/////////////////////////////////////////////////
 367		//
 368		// Initialize stuff that doesn't need data from simulators
 369		//
 370		std::string lastGPU = gSavedSettings.getString("LastGPUString");
 371		std::string thisGPU = LLFeatureManager::getInstance()->getGPUString();
 372		
 373		if (LLFeatureManager::getInstance()->isSafe())
 374		{
 375			LLNotificationsUtil::add("DisplaySetToSafe");
 376		}
 377		else if ((gSavedSettings.getS32("LastFeatureVersion") < LLFeatureManager::getInstance()->getVersion()) &&
 378				 (gSavedSettings.getS32("LastFeatureVersion") != 0))
 379		{
 380			LLNotificationsUtil::add("DisplaySetToRecommendedFeatureChange");
 381		}
 382		else if ( ! lastGPU.empty() && (lastGPU != thisGPU))
 383		{
 384			LLSD subs;
 385			subs["LAST_GPU"] = lastGPU;
 386			subs["THIS_GPU"] = thisGPU;
 387			LLNotificationsUtil::add("DisplaySetToRecommendedGPUChange", subs);
 388		}
 389		else if (!gViewerWindow->getInitAlert().empty())
 390		{
 391			LLNotificationsUtil::add(gViewerWindow->getInitAlert());
 392		}
 393			
 394		//-------------------------------------------------
 395		// Init the SOCKS 5 proxy if the user has configured
 396		// one. We need to do this early in case the user
 397		// is using SOCKS for HTTP so we get the login
 398		// screen and HTTP tables via SOCKS.
 399		//-------------------------------------------------
 400		LLStartUp::startLLProxy();
 401
 402		gSavedSettings.setS32("LastFeatureVersion", LLFeatureManager::getInstance()->getVersion());
 403		gSavedSettings.setString("LastGPUString", thisGPU);
 404
 405		// load dynamic GPU/feature tables from website (S3)
 406		LLFeatureManager::getInstance()->fetchHTTPTables();
 407		
 408		std::string xml_file = LLUI::locateSkin("xui_version.xml");
 409		LLXMLNodePtr root;
 410		bool xml_ok = false;
 411		if (LLXMLNode::parseFile(xml_file, root, NULL))
 412		{
 413			if( (root->hasName("xui_version") ) )
 414			{
 415				std::string value = root->getValue();
 416				F32 version = 0.0f;
 417				LLStringUtil::convertToF32(value, version);
 418				if (version >= 1.0f)
 419				{
 420					xml_ok = true;
 421				}
 422			}
 423		}
 424		if (!xml_ok)
 425		{
 426			// If XML is bad, there's a good possibility that notifications.xml is ALSO bad.
 427			// If that's so, then we'll get a fatal error on attempting to load it, 
 428			// which will display a nontranslatable error message that says so.
 429			// Otherwise, we'll display a reasonable error message that IS translatable.
 430			LLAppViewer::instance()->earlyExit("BadInstallation");
 431		}
 432		//
 433		// Statistics stuff
 434		//
 435
 436		// Load autopilot and stats stuff
 437		gAgentPilot.load();
 438
 439		//gErrorStream.setTime(gSavedSettings.getBOOL("LogTimestamps"));
 440
 441		// Load the throttle settings
 442		gViewerThrottle.load();
 443
 444		if (ll_init_ares() == NULL || !gAres->isInitialized())
 445		{
 446			std::string diagnostic = "Could not start address resolution system";
 447			LL_WARNS("AppInit") << diagnostic << LL_ENDL;
 448			LLAppViewer::instance()->earlyExit("LoginFailedNoNetwork", LLSD().with("DIAGNOSTIC", diagnostic));
 449		}
 450		
 451		//
 452		// Initialize messaging system
 453		//
 454		LL_DEBUGS("AppInit") << "Initializing messaging system..." << LL_ENDL;
 455
 456		std::string message_template_path = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"message_template.msg");
 457
 458		LLFILE* found_template = NULL;
 459		found_template = LLFile::fopen(message_template_path, "r");		/* Flawfinder: ignore */
 460		
 461		#if LL_WINDOWS
 462			// On the windows dev builds, unpackaged, the message_template.msg 
 463			// file will be located in:
 464			// build-vc**/newview/<config>/app_settings
 465			if (!found_template)
 466			{
 467				message_template_path = gDirUtilp->getExpandedFilename(LL_PATH_EXECUTABLE, "app_settings", "message_template.msg");
 468				found_template = LLFile::fopen(message_template_path.c_str(), "r");		/* Flawfinder: ignore */
 469			}	
 470		#elif LL_DARWIN
 471			// On Mac dev builds, message_template.msg lives in:
 472			// indra/build-*/newview/<config>/Second Life/Contents/Resources/app_settings
 473			if (!found_template)
 474			{
 475				message_template_path =
 476					gDirUtilp->getExpandedFilename(LL_PATH_EXECUTABLE,
 477												   "../Resources/app_settings",
 478												   "message_template.msg");
 479				found_template = LLFile::fopen(message_template_path.c_str(), "r");		/* Flawfinder: ignore */
 480			}		
 481		#endif
 482
 483		if (found_template)
 484		{
 485			fclose(found_template);
 486
 487			U32 port = gSavedSettings.getU32("UserConnectionPort");
 488
 489			if ((NET_USE_OS_ASSIGNED_PORT == port) &&   // if nothing specified on command line (-port)
 490			    (gSavedSettings.getBOOL("ConnectionPortEnabled")))
 491			  {
 492			    port = gSavedSettings.getU32("ConnectionPort");
 493			  }
 494
 495			LLHTTPSender::setDefaultSender(new LLNullHTTPSender());
 496
 497			// TODO parameterize 
 498			const F32 circuit_heartbeat_interval = 5;
 499			const F32 circuit_timeout = 100;
 500
 501			const LLUseCircuitCodeResponder* responder = NULL;
 502			bool failure_is_fatal = true;
 503			
 504			if(!start_messaging_system(
 505				   message_template_path,
 506				   port,
 507				   LLVersionInfo::getMajor(),
 508				   LLVersionInfo::getMinor(),
 509				   LLVersionInfo::getPatch(),
 510				   FALSE,
 511				   std::string(),
 512				   responder,
 513				   failure_is_fatal,
 514				   circuit_heartbeat_interval,
 515				   circuit_timeout))
 516			{
 517				std::string diagnostic = llformat(" Error: %d", gMessageSystem->getErrorCode());
 518				LL_WARNS("AppInit") << diagnostic << LL_ENDL;
 519				LLAppViewer::instance()->earlyExit("LoginFailedNoNetwork", LLSD().with("DIAGNOSTIC", diagnostic));
 520			}
 521
 522			#if LL_WINDOWS
 523				// On the windows dev builds, unpackaged, the message.xml file will 
 524				// be located in indra/build-vc**/newview/<config>/app_settings.
 525				std::string message_path = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"message.xml");
 526							
 527				if (!LLFile::isfile(message_path.c_str())) 
 528				{
 529					LLMessageConfig::initClass("viewer", gDirUtilp->getExpandedFilename(LL_PATH_EXECUTABLE, "app_settings", ""));
 530				}
 531				else
 532				{
 533					LLMessageConfig::initClass("viewer", gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, ""));
 534				}
 535			#else			
 536				LLMessageConfig::initClass("viewer", gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, ""));
 537			#endif
 538
 539		}
 540		else
 541		{
 542			LLAppViewer::instance()->earlyExit("MessageTemplateNotFound", LLSD().with("PATH", message_template_path));
 543		}
 544
 545		if(gMessageSystem && gMessageSystem->isOK())
 546		{
 547			// Initialize all of the callbacks in case of bad message
 548			// system data
 549			LLMessageSystem* msg = gMessageSystem;
 550			msg->setExceptionFunc(MX_UNREGISTERED_MESSAGE,
 551								  invalid_message_callback,
 552								  NULL);
 553			msg->setExceptionFunc(MX_PACKET_TOO_SHORT,
 554								  invalid_message_callback,
 555								  NULL);
 556
 557			// running off end of a packet is now valid in the case
 558			// when a reader has a newer message template than
 559			// the sender
 560			/*msg->setExceptionFunc(MX_RAN_OFF_END_OF_PACKET,
 561								  invalid_message_callback,
 562								  NULL);*/
 563			msg->setExceptionFunc(MX_WROTE_PAST_BUFFER_SIZE,
 564								  invalid_message_callback,
 565								  NULL);
 566
 567			if (gSavedSettings.getBOOL("LogMessages"))
 568			{
 569				LL_DEBUGS("AppInit") << "Message logging activated!" << LL_ENDL;
 570				msg->startLogging();
 571			}
 572
 573			// start the xfer system. by default, choke the downloads
 574			// a lot...
 575			const S32 VIEWER_MAX_XFER = 3;
 576			start_xfer_manager(gVFS);
 577			gXferManager->setMaxIncomingXfers(VIEWER_MAX_XFER);
 578			F32 xfer_throttle_bps = gSavedSettings.getF32("XferThrottle");
 579			if (xfer_throttle_bps > 1.f)
 580			{
 581				gXferManager->setUseAckThrottling(TRUE);
 582				gXferManager->setAckThrottleBPS(xfer_throttle_bps);
 583			}
 584			gAssetStorage = new LLViewerAssetStorage(msg, gXferManager, gVFS, gStaticVFS);
 585
 586
 587			F32 dropPercent = gSavedSettings.getF32("PacketDropPercentage");
 588			msg->mPacketRing.setDropPercentage(dropPercent);
 589
 590            F32 inBandwidth = gSavedSettings.getF32("InBandwidth"); 
 591            F32 outBandwidth = gSavedSettings.getF32("OutBandwidth"); 
 592			if (inBandwidth != 0.f)
 593			{
 594				LL_DEBUGS("AppInit") << "Setting packetring incoming bandwidth to " << inBandwidth << LL_ENDL;
 595				msg->mPacketRing.setUseInThrottle(TRUE);
 596				msg->mPacketRing.setInBandwidth(inBandwidth);
 597			}
 598			if (outBandwidth != 0.f)
 599			{
 600				LL_DEBUGS("AppInit") << "Setting packetring outgoing bandwidth to " << outBandwidth << LL_ENDL;
 601				msg->mPacketRing.setUseOutThrottle(TRUE);
 602				msg->mPacketRing.setOutBandwidth(outBandwidth);
 603			}
 604		}
 605
 606		LL_INFOS("AppInit") << "Message System Initialized." << LL_ENDL;
 607
 608		//-------------------------------------------------
 609		// Init audio, which may be needed for prefs dialog
 610		// or audio cues in connection UI.
 611		//-------------------------------------------------
 612
 613		if (FALSE == gSavedSettings.getBOOL("NoAudio"))
 614		{
 615			gAudiop = NULL;
 616
 617#ifdef LL_OPENAL
 618			if (!gAudiop
 619#if !LL_WINDOWS
 620			    && NULL == getenv("LL_BAD_OPENAL_DRIVER")
 621#endif // !LL_WINDOWS
 622			    )
 623			{
 624				gAudiop = (LLAudioEngine *) new LLAudioEngine_OpenAL();
 625			}
 626#endif
 627
 628#ifdef LL_FMOD			
 629			if (!gAudiop
 630#if !LL_WINDOWS
 631			    && NULL == getenv("LL_BAD_FMOD_DRIVER")
 632#endif // !LL_WINDOWS
 633			    )
 634			{
 635				gAudiop = (LLAudioEngine *) new LLAudioEngine_FMOD();
 636			}
 637#endif
 638
 639			if (gAudiop)
 640			{
 641#if LL_WINDOWS
 642				// FMOD on Windows needs the window handle to stop playing audio
 643				// when window is minimized. JC
 644				void* window_handle = (HWND)gViewerWindow->getPlatformWindow();
 645#else
 646				void* window_handle = NULL;
 647#endif
 648				bool init = gAudiop->init(kAUDIO_NUM_SOURCES, window_handle);
 649				if(init)
 650				{
 651					gAudiop->setMuted(TRUE);
 652				}
 653				else
 654				{
 655					LL_WARNS("AppInit") << "Unable to initialize audio engine" << LL_ENDL;
 656					delete gAudiop;
 657					gAudiop = NULL;
 658				}
 659
 660				if (gAudiop)
 661				{
 662					// if the audio engine hasn't set up its own preferred handler for streaming audio then set up the generic streaming audio implementation which uses media plugins
 663					if (NULL == gAudiop->getStreamingAudioImpl())
 664					{
 665						LL_INFOS("AppInit") << "Using media plugins to render streaming audio" << LL_ENDL;
 666						gAudiop->setStreamingAudioImpl(new LLStreamingAudio_MediaPlugins());
 667					}
 668				}
 669			}
 670		}
 671		
 672		LL_INFOS("AppInit") << "Audio Engine Initialized." << LL_ENDL;
 673		
 674		if (LLTimer::knownBadTimer())
 675		{
 676			LL_WARNS("AppInit") << "Unreliable timers detected (may be bad PCI chipset)!!" << LL_ENDL;
 677		}
 678
 679		//
 680		// Log on to system
 681		//
 682		if (gUserCredential.isNull())
 683		{
 684			gUserCredential = gLoginHandler.initializeLoginInfo();
 685		}
 686		// Previous initializeLoginInfo may have generated user credentials.  Re-check them.
 687		if (gUserCredential.isNull())
 688		{
 689			show_connect_box = TRUE;
 690		}
 691		else if (gSavedSettings.getBOOL("AutoLogin"))  
 692		{
 693			gRememberPassword = TRUE;
 694			gSavedSettings.setBOOL("RememberPassword", TRUE);                                                      
 695			show_connect_box = false;    			
 696		}
 697		else 
 698		{
 699			gRememberPassword = gSavedSettings.getBOOL("RememberPassword");
 700			show_connect_box = TRUE;
 701		}
 702		// Go to the next startup state
 703		LLStartUp::setStartupState( STATE_BROWSER_INIT );
 704		return FALSE;
 705	}
 706
 707	
 708	if (STATE_BROWSER_INIT == LLStartUp::getStartupState())
 709	{
 710		LL_DEBUGS("AppInit") << "STATE_BROWSER_INIT" << LL_ENDL;
 711		std::string msg = LLTrans::getString("LoginInitializingBrowser");
 712		set_startup_status(0.03f, msg.c_str(), gAgent.mMOTD.c_str());
 713		display_startup();
 714		// LLViewerMedia::initBrowser();
 715		LLStartUp::setStartupState( STATE_LOGIN_SHOW );
 716		return FALSE;
 717	}
 718
 719
 720	if (STATE_LOGIN_SHOW == LLStartUp::getStartupState())
 721	{
 722		LL_DEBUGS("AppInit") << "Initializing Window" << LL_ENDL;
 723
 724		// if we've gone backwards in the login state machine, to this state where we show the UI
 725		// AND the debug setting to exit in this case is true, then go ahead and bail quickly
 726		if ( mLoginStatePastUI && gSavedSettings.getBOOL("QuitOnLoginActivated") )
 727		{
 728			// no requirement for notification here - just exit
 729			LLAppViewer::instance()->earlyExitNoNotify();
 730		}
 731
 732		gViewerWindow->getWindow()->setCursor(UI_CURSOR_ARROW);
 733
 734		timeout_count = 0;
 735
 736		// Login screen needs menus for preferences, but we can enter
 737		// this startup phase more than once.
 738		if (gLoginMenuBarView == NULL)
 739		{
 740			display_startup();
 741			initialize_edit_menu();
 742			display_startup();
 743			init_menus();
 744			display_startup();
 745		}
 746
 747		if (show_connect_box)
 748		{
 749			// Load all the name information out of the login view
 750			// NOTE: Hits "Attempted getFields with no login view shown" warning, since we don't
 751			// show the login view until login_show() is called below.  
 752			if (gUserCredential.isNull())                                                                          
 753			{                                                  
 754				display_startup();
 755				gUserCredential = gLoginHandler.initializeLoginInfo();                 
 756				display_startup();
 757			}     
 758			if (gHeadlessClient)
 759			{
 760				LL_WARNS("AppInit") << "Waiting at connection box in headless client.  Did you mean to add autologin params?" << LL_ENDL;
 761			}
 762			// Make sure the process dialog doesn't hide things
 763			display_startup();
 764			gViewerWindow->setShowProgress(FALSE);
 765			display_startup();
 766			// Show the login dialog
 767			login_show();
 768			display_startup();
 769			// connect dialog is already shown, so fill in the names
 770			if (gUserCredential.notNull())                                                                         
 771			{                                                                                                      
 772				LLPanelLogin::setFields( gUserCredential, gRememberPassword);                                  
 773			}     
 774			display_startup();
 775			LLPanelLogin::giveFocus();
 776
 777			LLStartUp::setStartupState( STATE_LOGIN_WAIT );		// Wait for user input
 778		}
 779		else
 780		{
 781			// skip directly to message template verification
 782			LLStartUp::setStartupState( STATE_LOGIN_CLEANUP );
 783		}
 784
 785		display_startup();
 786		gViewerWindow->setNormalControlsVisible( FALSE );	
 787		display_startup();
 788		gLoginMenuBarView->setVisible( TRUE );
 789		display_startup();
 790		gLoginMenuBarView->setEnabled( TRUE );
 791		display_startup();
 792		show_debug_menus();
 793		display_startup();
 794
 795		// Hide the splash screen
 796		LLSplashScreen::hide();
 797		display_startup();
 798		// Push our window frontmost
 799		gViewerWindow->getWindow()->show();
 800		display_startup();
 801
 802		// DEV-16927.  The following code removes errant keystrokes that happen while the window is being 
 803		// first made visible.
 804#ifdef _WIN32
 805		MSG msg;
 806		while( PeekMessage( &msg, /*All hWnds owned by this thread */ NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE ) )
 807		{ }
 808		display_startup();
 809#endif
 810		timeout.reset();
 811		return FALSE;
 812	}
 813
 814	if (STATE_LOGIN_WAIT == LLStartUp::getStartupState())
 815	{
 816		// when we get to this state, we've already been past the login UI
 817		// (possiblely automatically) - flag this so we can test in the 
 818		// STATE_LOGIN_SHOW state if we've gone backwards
 819		mLoginStatePastUI = true;
 820
 821		// Don't do anything.  Wait for the login view to call the login_callback,
 822		// which will push us to the next state.
 823		display_startup();
 824		// Sleep so we don't spin the CPU
 825		ms_sleep(1);
 826		return FALSE;
 827	}
 828
 829	if (STATE_LOGIN_CLEANUP == LLStartUp::getStartupState())
 830	{
 831		// Post login screen, we should see if any settings have changed that may
 832		// require us to either start/stop or change the socks proxy. As various communications
 833		// past this point may require the proxy to be up.
 834		if (!LLStartUp::startLLProxy())
 835		{
 836			// Proxy start up failed, we should now bail the state machine
 837			// startLLProxy() will have reported an error to the user
 838			// already, so we just go back to the login screen. The user
 839			// could then change the preferences to fix the issue.
 840
 841			LLStartUp::setStartupState(STATE_LOGIN_SHOW);
 842			return FALSE;
 843		}
 844
 845		// reset the values that could have come in from a slurl
 846		// DEV-42215: Make sure they're not empty -- gUserCredential
 847		// might already have been set from gSavedSettings, and it's too bad
 848		// to overwrite valid values with empty strings.
 849
 850		if (show_connect_box)
 851		{
 852			// TODO if not use viewer auth
 853			// Load all the name information out of the login view
 854			LLPanelLogin::getFields(gUserCredential, gRememberPassword); 
 855			// end TODO
 856	 
 857			// HACK: Try to make not jump on login
 858			gKeyboard->resetKeys();
 859		}
 860
 861		// when we get to this state, we've already been past the login UI
 862		// (possiblely automatically) - flag this so we can test in the 
 863		// STATE_LOGIN_SHOW state if we've gone backwards
 864		mLoginStatePastUI = true;
 865
 866		// save the credentials                                                                                        
 867		std::string userid = "unknown";                                                                                
 868		if(gUserCredential.notNull())                                                                                  
 869		{  
 870			userid = gUserCredential->userID();                                                                    
 871			gSecAPIHandler->saveCredential(gUserCredential, gRememberPassword);  
 872		}
 873		gSavedSettings.setBOOL("RememberPassword", gRememberPassword);                                                 
 874		LL_INFOS("AppInit") << "Attempting login as: " << userid << LL_ENDL;                                           
 875		gDebugInfo["LoginName"] = userid;                                                                              
 876         
 877		// create necessary directories
 878		// *FIX: these mkdir's should error check
 879		gDirUtilp->setLindenUserDir(userid);
 880		LLFile::mkdir(gDirUtilp->getLindenUserDir());
 881
 882		// Set PerAccountSettingsFile to the default value.
 883		std::string per_account_settings_file = LLAppViewer::instance()->getSettingsFilename("Default", "PerAccount");
 884		gSavedSettings.setString("PerAccountSettingsFile",
 885			gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, 
 886				LLAppViewer::instance()->getSettingsFilename("Default", "PerAccount")));
 887
 888		// Note: can't store warnings files per account because some come up before login
 889		
 890		// Overwrite default user settings with user settings								 
 891		LLAppViewer::instance()->loadSettingsFromDirectory("Account");
 892
 893		// Need to set the LastLogoff time here if we don't have one.  LastLogoff is used for "Recent Items" calculation
 894		// and startup time is close enough if we don't have a real value.
 895		if (gSavedPerAccountSettings.getU32("LastLogoff") == 0)
 896		{
 897			gSavedPerAccountSettings.setU32("LastLogoff", time_corrected());
 898		}
 899
 900		//Default the path if one isn't set.
 901		// *NOTE: unable to check variable differ from "InstantMessageLogPath" because it was
 902		// provided in pre 2.0 viewer. See EXT-6661
 903		if (gSavedPerAccountSettings.getString("InstantMessageLogPath").empty())
 904		{
 905			gDirUtilp->setChatLogsDir(gDirUtilp->getOSUserAppDir());
 906			gSavedPerAccountSettings.setString("InstantMessageLogPath", gDirUtilp->getChatLogsDir());
 907		}
 908		else
 909		{
 910			gDirUtilp->setChatLogsDir(gSavedPerAccountSettings.getString("InstantMessageLogPath"));		
 911		}
 912		gDirUtilp->setPerAccountChatLogsDir(userid);  
 913		
 914		LLFile::mkdir(gDirUtilp->getChatLogsDir());
 915		LLFile::mkdir(gDirUtilp->getPerAccountChatLogsDir());
 916
 917
 918		//good a place as any to create user windlight directories
 919		std::string user_windlight_path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight", ""));
 920		LLFile::mkdir(user_windlight_path_name.c_str());		
 921
 922		std::string user_windlight_skies_path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/skies", ""));
 923		LLFile::mkdir(user_windlight_skies_path_name.c_str());
 924
 925		std::string user_windlight_water_path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", ""));
 926		LLFile::mkdir(user_windlight_water_path_name.c_str());
 927
 928		std::string user_windlight_days_path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/days", ""));
 929		LLFile::mkdir(user_windlight_days_path_name.c_str());
 930
 931
 932		if (show_connect_box)
 933		{
 934			LLSLURL slurl;
 935			//LLPanelLogin::closePanel();
 936		}
 937
 938		
 939		// Load URL History File
 940		LLURLHistory::loadFile("url_history.xml");
 941		// Load location history 
 942		LLLocationHistory::getInstance()->load();
 943
 944		// Load Avatars icons cache
 945		LLAvatarIconIDCache::getInstance()->load();
 946		
 947		// Load media plugin cookies
 948		LLViewerMedia::loadCookieFile();
 949
 950		//-------------------------------------------------
 951		// Handle startup progress screen
 952		//-------------------------------------------------
 953
 954		// on startup the user can request to go to their home,
 955		// their last location, or some URL "-url //sim/x/y[/z]"
 956		// All accounts have both a home and a last location, and we don't support
 957		// more locations than that.  Choose the appropriate one.  JC
 958		switch (LLStartUp::getStartSLURL().getType())
 959		  {
 960		  case LLSLURL::LOCATION:
 961		    agent_location_id = START_LOCATION_ID_URL;
 962		    location_which = START_LOCATION_ID_LAST;
 963		    break;
 964		  case LLSLURL::LAST_LOCATION:
 965		    agent_location_id = START_LOCATION_ID_LAST;
 966		    location_which = START_LOCATION_ID_LAST;
 967		    break;
 968		  default:
 969		    agent_location_id = START_LOCATION_ID_HOME;
 970		    location_which = START_LOCATION_ID_HOME;
 971		    break;
 972		  }
 973
 974		gViewerWindow->getWindow()->setCursor(UI_CURSOR_WAIT);
 975
 976		init_start_screen(agent_location_id);
 977
 978		// Display the startup progress bar.
 979		gViewerWindow->setShowProgress(TRUE);
 980		gViewerWindow->setProgressCancelButtonVisible(TRUE, LLTrans::getString("Quit"));
 981
 982		gViewerWindow->revealIntroPanel();
 983
 984		// Poke the VFS, which could potentially block for a while if
 985		// Windows XP is acting up
 986		set_startup_status(0.07f, LLTrans::getString("LoginVerifyingCache"), LLStringUtil::null);
 987		display_startup();
 988
 989		gVFS->pokeFiles();
 990
 991		LLStartUp::setStartupState( STATE_LOGIN_AUTH_INIT );
 992
 993		return FALSE;
 994	}
 995
 996	if(STATE_LOGIN_AUTH_INIT == LLStartUp::getStartupState())
 997	{
 998		gDebugInfo["GridName"] = LLGridManager::getInstance()->getGridLabel();
 999
1000		// Update progress status and the display loop.
1001		auth_desc = LLTrans::getString("LoginInProgress");
1002		set_startup_status(progress, auth_desc, auth_message);
1003		progress += 0.02f;
1004		display_startup();
1005
1006		// Setting initial values...
1007		LLLoginInstance* login = LLLoginInstance::getInstance();
1008		login->setNotificationsInterface(LLNotifications::getInstance());
1009
1010		login->setSerialNumber(LLAppViewer::instance()->getSerialNumber());
1011		login->setLastExecEvent(gLastExecEvent);
1012		login->setUpdaterLauncher(boost::bind(&LLAppViewer::launchUpdater, LLAppViewer::instance()));
1013
1014		// This call to LLLoginInstance::connect() starts the 
1015		// authentication process.
1016		login->connect(gUserCredential);
1017
1018		LLStartUp::setStartupState( STATE_LOGIN_CURL_UNSTUCK );
1019		return FALSE;
1020	}
1021
1022	if(STATE_LOGIN_CURL_UNSTUCK == LLStartUp::getStartupState())
1023	{
1024		// If we get here we have gotten past the potential stall
1025		// in curl, so take "may appear frozen" out of progress bar. JC
1026		auth_desc = LLTrans::getString("LoginInProgressNoFrozen");
1027		set_startup_status(progress, auth_desc, auth_message);
1028
1029		LLStartUp::setStartupState( STATE_LOGIN_PROCESS_RESPONSE );
1030		return FALSE;
1031	}
1032
1033	if(STATE_LOGIN_PROCESS_RESPONSE == LLStartUp::getStartupState()) 
1034	{
1035		// Generic failure message
1036		std::ostringstream emsg;
1037		emsg << LLTrans::getString("LoginFailed") << "\n";
1038		if(LLLoginInstance::getInstance()->authFailure())
1039		{
1040			LL_INFOS("LLStartup") << "Login failed, LLLoginInstance::getResponse(): "
1041			                      << LLLoginInstance::getInstance()->getResponse() << LL_ENDL;
1042			LLSD response = LLLoginInstance::getInstance()->getResponse();
1043			// Still have error conditions that may need some 
1044			// sort of handling - dig up specific message
1045			std::string reason_response = response["reason"];
1046			std::string message_response = response["message"];
1047			std::string message_id = response["message_id"];
1048			std::string message; // actual string to show the user
1049
1050			if(!message_id.empty() && LLTrans::findString(message, message_id, response["message_args"]))
1051			{
1052				// message will be filled in with the template and arguments
1053			}
1054			else if(!message_response.empty())
1055			{
1056				// *HACK: "no_inventory_host" sent as the message itself.
1057				// Remove this clause when server is sending message_id as well.
1058				message = LLAgent::sTeleportErrorMessages[ message_response ];
1059			}
1060
1061			if (message.empty())
1062			{
1063				// Fallback to server-supplied string; necessary since server
1064				// may add strings that this viewer is not yet aware of
1065				message = message_response;
1066			}
1067
1068			emsg << message;
1069
1070
1071			if(reason_response == "key")
1072			{
1073				// Couldn't login because user/password is wrong
1074				// Clear the credential
1075				gUserCredential->clearAuthenticator();
1076			}
1077
1078			if(reason_response == "update" 
1079				|| reason_response == "optional")
1080			{
1081				// In the case of a needed update, quit.
1082				// Its either downloading or declined.
1083				// If optional was skipped this case shouldn't 
1084				// be reached.
1085				LLLoginInstance::getInstance()->disconnect();
1086				LLAppViewer::instance()->forceQuit();
1087			}
1088			else 
1089			{
1090				if (reason_response != "tos") 
1091				{
1092					// Don't pop up a notification in the TOS case because
1093					// LLFloaterTOS::onCancel() already scolded the user.
1094					std::string error_code;
1095					if(response.has("errorcode"))
1096					{
1097						error_code = response["errorcode"].asString();
1098					}
1099					if ((reason_response == "CURLError") && 
1100						(error_code == "SSL_CACERT" || error_code == "SSL_PEER_CERTIFICATE") && 
1101						response.has("certificate"))
1102					{
1103						// This was a certificate error, so grab the certificate
1104						// and throw up the appropriate dialog.
1105						LLPointer<LLCertificate> certificate = gSecAPIHandler->getCertificate(response["certificate"]);
1106						if(certificate)
1107						{
1108							LLSD args = transform_cert_args(certificate);
1109
1110							if(error_code == "SSL_CACERT")
1111							{
1112								// if we are handling an untrusted CA, throw up the dialog                             
1113								// with the 'trust this CA' button.                                                    
1114								LLNotificationsUtil::add("TrustCertificateError", args, response,
1115														trust_cert_done);
1116								
1117								show_connect_box = true;
1118							}
1119							else
1120							{
1121								// the certificate exception returns a unique string for each type of exception.       
1122								// we grab this string via the LLUserAuth object, and use that to grab the localized   
1123								// string.                                                                             
1124								args["REASON"] = LLTrans::getString(message_response);
1125								
1126								LLNotificationsUtil::add("GeneralCertificateError", args, response,
1127														 general_cert_done);
1128								
1129								reset_login();
1130								gSavedSettings.setBOOL("AutoLogin", FALSE);
1131								show_connect_box = true;
1132								
1133							}
1134
1135						}
1136					}
1137					else 
1138					{
1139						// This wasn't a certificate error, so throw up the normal
1140						// notificatioin message.
1141						LLSD args;
1142						args["ERROR_MESSAGE"] = emsg.str();
1143						LL_INFOS("LLStartup") << "Notification: " << args << LL_ENDL;
1144						LLNotificationsUtil::add("ErrorMessage", args, LLSD(), login_alert_done);
1145					}
1146				}
1147				//setup map of datetime strings to codes and slt & local time offset from utc
1148				// *TODO: Does this need to be here?
1149				LLStringOps::setupDatetimeInfo (false);
1150				transition_back_to_login_panel(emsg.str());
1151				show_connect_box = true;
1152			}
1153		}
1154		else if(LLLoginInstance::getInstance()->authSuccess())
1155		{
1156			if(process_login_success_response())
1157			{
1158				// Pass the user information to the voice chat server interface.
1159				LLVoiceClient::getInstance()->userAuthorized(gUserCredential->userID(), gAgentID);
1160				// create the default proximal channel
1161				LLVoiceChannel::initClass();
1162				LLGridManager::getInstance()->setFavorite(); 
1163				LLStartUp::setStartupState( STATE_WORLD_INIT);
1164			}
1165			else
1166			{
1167				LLSD args;
1168				args["ERROR_MESSAGE"] = emsg.str();
1169				LL_INFOS("LLStartup") << "Notification: " << args << LL_ENDL;
1170				LLNotificationsUtil::add("ErrorMessage", args, LLSD(), login_alert_done);
1171				transition_back_to_login_panel(emsg.str());
1172				show_connect_box = true;
1173				return FALSE;
1174			}
1175		}
1176		return FALSE;
1177	}
1178
1179	//---------------------------------------------------------------------
1180	// World Init
1181	//---------------------------------------------------------------------
1182	if (STATE_WORLD_INIT == LLStartUp::getStartupState())
1183	{
1184		set_startup_status(0.30f, LLTrans::getString("LoginInitializingWorld"), gAgent.mMOTD);
1185		display_startup();
1186		// We should have an agent id by this point.
1187		llassert(!(gAgentID == LLUUID::null));
1188
1189		// Finish agent initialization.  (Requires gSavedSettings, builds camera)
1190		gAgent.init();
1191		display_startup();
1192		gAgentCamera.init();
1193		display_startup();
1194		set_underclothes_menu_options();
1195		display_startup();
1196
1197		// Since we connected, save off the settings so the user doesn't have to
1198		// type the name/password again if we crash.
1199		gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
1200		LLUIColorTable::instance().saveUserSettings();
1201
1202		display_startup();
1203
1204		//
1205		// Initialize classes w/graphics stuff.
1206		//
1207		gTextureList.doPrefetchImages();		
1208		display_startup();
1209
1210		LLSurface::initClasses();
1211		display_startup();
1212
1213
1214		LLFace::initClass();
1215		display_startup();
1216
1217		LLDrawable::initClass();
1218		display_startup();
1219
1220		// init the shader managers
1221		LLPostProcess::initClass();
1222		display_startup();
1223
1224		LLViewerObject::initVOClasses();
1225		display_startup();
1226
1227		// Initialize all our tools.  Must be done after saved settings loaded.
1228		// NOTE: This also is where gToolMgr used to be instantiated before being turned into a singleton.
1229		LLToolMgr::getInstance()->initTools();
1230		display_startup();
1231
1232		// Pre-load floaters, like the world map, that are slow to spawn
1233		// due to XML complexity.
1234		gViewerWindow->initWorldUI();
1235		
1236		display_startup();
1237
1238		// This is where we used to initialize gWorldp. Original comment said:
1239		// World initialization must be done after above window init
1240
1241		// User might have overridden far clip
1242		LLWorld::getInstance()->setLandFarClip(gAgentCamera.mDrawDistance);
1243		display_startup();
1244		// Before we create the first region, we need to set the agent's mOriginGlobal
1245		// This is necessary because creating objects before this is set will result in a
1246		// bad mPositionAgent cache.
1247
1248		gAgent.initOriginGlobal(from_region_handle(gFirstSimHandle));
1249		display_startup();
1250
1251		LLWorld::getInstance()->addRegion(gFirstSimHandle, gFirstSim);
1252		display_startup();
1253
1254		LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromHandle(gFirstSimHandle);
1255		LL_INFOS("AppInit") << "Adding initial simulator " << regionp->getOriginGlobal() << LL_ENDL;
1256		
1257		regionp->setSeedCapability(gFirstSimSeedCap);
1258		LL_DEBUGS("AppInit") << "Waiting for seed grant ...." << LL_ENDL;
1259		display_startup();
1260		// Set agent's initial region to be the one we just created.
1261		gAgent.setRegion(regionp);
1262		display_startup();
1263		// Set agent's initial position, which will be read by LLVOAvatar when the avatar
1264		// object is created.  I think this must be done after setting the region.  JC
1265		gAgent.setPositionAgent(agent_start_position_region);
1266
1267		display_startup();
1268		LLStartUp::setStartupState( STATE_MULTIMEDIA_INIT );
1269		
1270		return FALSE;
1271	}
1272
1273
1274	//---------------------------------------------------------------------
1275	// Load QuickTime/GStreamer and other multimedia engines, can be slow.
1276	// Do it while we're waiting on the network for our seed capability. JC
1277	//---------------------------------------------------------------------
1278	if (STATE_MULTIMEDIA_INIT == LLStartUp::getStartupState())
1279	{
1280		LLStartUp::multimediaInit();
1281		LLStartUp::setStartupState( STATE_FONT_INIT );
1282		display_startup();
1283		return FALSE;
1284	}
1285
1286	// Loading fonts takes several seconds
1287	if (STATE_FONT_INIT == LLStartUp::getStartupState())
1288	{
1289		LLStartUp::fontInit();
1290		LLStartUp::setStartupState( STATE_SEED_GRANTED_WAIT );
1291		display_startup();
1292		return FALSE;
1293	}
1294
1295	//---------------------------------------------------------------------
1296	// Wait for Seed Cap Grant
1297	//---------------------------------------------------------------------
1298	if(STATE_SEED_GRANTED_WAIT == LLStartUp::getStartupState())
1299	{
1300		LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromHandle(gFirstSimHandle);
1301		if (regionp->capabilitiesReceived())
1302		{
1303			LLStartUp::setStartupState( STATE_SEED_CAP_GRANTED );
1304		}
1305		else
1306		{
1307			U32 num_retries = regionp->getNumSeedCapRetries();
1308			if (num_retries > 0)
1309			{
1310				LLStringUtil::format_map_t args;
1311				args["[NUMBER]"] = llformat("%d", num_retries + 1);
1312				set_startup_status(0.4f, LLTrans::getString("LoginRetrySeedCapGrant", args), gAgent.mMOTD);
1313			}
1314			else
1315			{
1316				set_startup_status(0.4f, LLTrans::getString("LoginRequestSeedCapGrant"), gAgent.mMOTD);
1317			}
1318		}
1319		display_startup();
1320		return FALSE;
1321	}
1322
1323
1324	//---------------------------------------------------------------------
1325	// Seed Capability Granted
1326	// no newMessage calls should happen before this point
1327	//---------------------------------------------------------------------
1328	if (STATE_SEED_CAP_GRANTED == LLStartUp::getStartupState())
1329	{
1330		display_startup();
1331		update_texture_fetch();
1332		display_startup();
1333
1334		if ( gViewerWindow != NULL)
1335		{	// This isn't the first logon attempt, so show the UI
1336			gViewerWindow->setNormalControlsVisible( TRUE );
1337		}	
1338		gLoginMenuBarView->setVisible( FALSE );
1339		gLoginMenuBarView->setEnabled( FALSE );
1340		display_startup();
1341
1342		// direct logging to the debug console's line buffer
1343		LLError::logToFixedBuffer(gDebugView->mDebugConsolep);
1344		display_startup();
1345		
1346		// set initial visibility of debug console
1347		gDebugView->mDebugConsolep->setVisible(gSavedSettings.getBOOL("ShowDebugConsole"));
1348		display_startup();
1349
1350		//
1351		// Set message handlers
1352		//
1353		LL_INFOS("AppInit") << "Initializing communications..." << LL_ENDL;
1354
1355		// register callbacks for messages. . . do this after initial handshake to make sure that we don't catch any unwanted
1356		register_viewer_callbacks(gMessageSystem);
1357		display_startup();
1358
1359		// Debugging info parameters
1360		gMessageSystem->setMaxMessageTime( 0.5f );			// Spam if decoding all msgs takes more than 500 ms
1361		display_startup();
1362
1363		#ifndef	LL_RELEASE_FOR_DOWNLOAD
1364			gMessageSystem->setTimeDecodes( TRUE );				// Time the decode of each msg
1365			gMessageSystem->setTimeDecodesSpamThreshold( 0.05f );  // Spam if a single msg takes over 50ms to decode
1366		#endif
1367		display_startup();
1368
1369		gXferManager->registerCallbacks(gMessageSystem);
1370		display_startup();
1371
1372		LLStartUp::initNameCache();
1373		display_startup();
1374
1375		// update the voice settings *after* gCacheName initialization
1376		// so that we can construct voice UI that relies on the name cache
1377		LLVoiceClient::getInstance()->updateSettings();
1378		display_startup();
1379
1380		//gCacheName is required for nearby chat history loading
1381		//so I just moved nearby history loading a few states further
1382		if (gSavedPerAccountSettings.getBOOL("LogShowHistory"))
1383		{
1384			LLNearbyChat* nearby_chat = LLNearbyChat::getInstance();
1385			if (nearby_chat) nearby_chat->loadHistory();
1386		}
1387		display_startup();
1388
1389		// *Note: this is where gWorldMap used to be initialized.
1390
1391		// register null callbacks for audio until the audio system is initialized
1392		gMessageSystem->setHandlerFuncFast(_PREHASH_SoundTrigger, null_message_callback, NULL);
1393		gMessageSystem->setHandlerFuncFast(_PREHASH_AttachedSound, null_message_callback, NULL);
1394		display_startup();
1395
1396		//reset statistics
1397		LLViewerStats::getInstance()->resetStats();
1398
1399		display_startup();
1400		//
1401		// Set up region and surface defaults
1402		//
1403
1404
1405		// Sets up the parameters for the first simulator
1406
1407		LL_DEBUGS("AppInit") << "Initializing camera..." << LL_ENDL;
1408		gFrameTime    = totalTime();
1409		F32 last_time = gFrameTimeSeconds;
1410		gFrameTimeSeconds = (S64)(gFrameTime - gStartTime)/SEC_TO_MICROSEC;
1411
1412		gFrameIntervalSeconds = gFrameTimeSeconds - last_time;
1413		if (gFrameIntervalSeconds < 0.f)
1414		{
1415			gFrameIntervalSeconds = 0.f;
1416		}
1417
1418		// Make sure agent knows correct aspect ratio
1419		// FOV limits depend upon aspect ratio so this needs to happen before initializing the FOV below
1420		LLViewerCamera::getInstance()->setViewHeightInPixels(gViewerWindow->getWorldViewHeightRaw());
1421		LLViewerCamera::getInstance()->setAspect(gViewerWindow->getWorldViewAspectRatio());
1422		// Initialize FOV
1423		LLViewerCamera::getInstance()->setDefaultFOV(gSavedSettings.getF32("CameraAngle")); 
1424		display_startup();
1425
1426		// Move agent to starting location. The position handed to us by
1427		// the space server is in global coordinates, but the agent frame
1428		// is in region local coordinates. Therefore, we need to adjust
1429		// the coordinates handed to us to fit in the local region.
1430
1431		gAgent.setPositionAgent(agent_start_position_region);
1432		gAgent.resetAxes(gAgentStartLookAt);
1433		gAgentCamera.stopCameraAnimation();
1434		gAgentCamera.resetCamera();
1435		display_startup();
1436
1437		// Initialize global class data needed for surfaces (i.e. textures)
1438		LL_DEBUGS("AppInit") << "Initializing sky..." << LL_ENDL;
1439		// Initialize all of the viewer object classes for the first time (doing things like texture fetches.
1440		LLGLState::checkStates();
1441		LLGLState::checkTextureChannels();
1442
1443		gSky.init(initial_sun_direction);
1444
1445		LLGLState::checkStates();
1446		LLGLState::checkTextureChannels();
1447
1448		display_startup();
1449
1450		LL_DEBUGS("AppInit") << "Decoding images..." << LL_ENDL;
1451		// For all images pre-loaded into viewer cache, decode them.
1452		// Need to do this AFTER we init the sky
1453		const S32 DECODE_TIME_SEC = 2;
1454		for (int i = 0; i < DECODE_TIME_SEC; i++)
1455		{
1456			F32 frac = (F32)i / (F32)DECODE_TIME_SEC;
1457			set_startup_status(0.45f + frac*0.1f, LLTrans::getString("LoginDecodingImages"), gAgent.mMOTD);
1458			display_startup();
1459			gTextureList.decodeAllImages(1.f);
1460		}
1461		LLStartUp::setStartupState( STATE_WORLD_WAIT );
1462
1463		display_startup();
1464
1465		// JC - Do this as late as possible to increase likelihood Purify
1466		// will run.
1467		LLMessageSystem* msg = gMessageSystem;
1468		if (!msg->mOurCircuitCode)
1469		{
1470			LL_WARNS("AppInit") << "Attempting to connect to simulator with a zero circuit code!" << LL_ENDL;
1471		}
1472
1473		gUseCircuitCallbackCalled = false;
1474
1475		msg->enableCircuit(gFirstSim, TRUE);
1476		// now, use the circuit info to tell simulator about us!
1477		LL_INFOS("AppInit") << "viewer: UserLoginLocationReply() Enabling " << gFirstSim << " with code " << msg->mOurCircuitCode << LL_ENDL;
1478		msg->newMessageFast(_PREHASH_UseCircuitCode);
1479		msg->nextBlockFast(_PREHASH_CircuitCode);
1480		msg->addU32Fast(_PREHASH_Code, msg->mOurCircuitCode);
1481		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
1482		msg->addUUIDFast(_PREHASH_ID, gAgent.getID());
1483		msg->sendReliable(
1484			gFirstSim,
1485			gSavedSettings.getS32("UseCircuitCodeMaxRetries"),
1486			FALSE,
1487			gSavedSettings.getF32("UseCircuitCodeTimeout"),
1488			use_circuit_callback,
1489			NULL);
1490
1491		timeout.reset();
1492		display_startup();
1493
1494		return FALSE;
1495	}
1496
1497	//---------------------------------------------------------------------
1498	// Agent Send
1499	//---------------------------------------------------------------------
1500	if(STATE_WORLD_WAIT == LLStartUp::getStartupState())
1501	{
1502		LL_DEBUGS("AppInit") << "Waiting for simulator ack...." << LL_ENDL;
1503		set_startup_status(0.59f, LLTrans::getString("LoginWaitingForRegionHandshake"), gAgent.mMOTD);
1504		if(gGotUseCircuitCodeAck)
1505		{
1506			LLStartUp::setStartupState( STATE_AGENT_SEND );
1507		}
1508		LLMessageSystem* msg = gMessageSystem;
1509		while (msg->checkAllMessages(gFrameCount, gServicePump))
1510		{
1511			display_startup();
1512		}
1513		msg->processAcks();
1514		display_startup();
1515		return FALSE;
1516	}
1517
1518	//---------------------------------------------------------------------
1519	// Agent Send
1520	//---------------------------------------------------------------------
1521	if (STATE_AGENT_SEND == LLStartUp::getStartupState())
1522	{
1523		LL_DEBUGS("AppInit") << "Connecting to region..." << LL_ENDL;

Large files files are truncated, but you can click here to view the full file