PageRenderTime 141ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1

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

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