llstartup.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llstartup.h"
00035 
00036 #if LL_WINDOWS
00037 #       include <process.h>             // _spawnl()
00038 #else
00039 #       include <sys/stat.h>            // mkdir()
00040 #endif
00041 
00042 #include "audioengine.h"
00043 
00044 #if LL_FMOD
00045 #include "audioengine_fmod.h"
00046 #endif
00047 
00048 #include "llares.h"
00049 #include "llcachename.h"
00050 #include "llviewercontrol.h"
00051 #include "lldir.h"
00052 #include "llerrorcontrol.h"
00053 #include "llfiltersd2xmlrpc.h"
00054 #include "llfocusmgr.h"
00055 #include "llhttpsender.h"
00056 #include "imageids.h"
00057 #include "lllandmark.h"
00058 #include "llloginflags.h"
00059 #include "llmd5.h"
00060 #include "llmemorystream.h"
00061 #include "llmessageconfig.h"
00062 #include "llmoveview.h"
00063 #include "llregionhandle.h"
00064 #include "llsd.h"
00065 #include "llsdserialize.h"
00066 #include "llsdutil.h"
00067 #include "llsecondlifeurls.h"
00068 #include "llstring.h"
00069 #include "lluserrelations.h"
00070 #include "llversionviewer.h"
00071 #include "llvfs.h"
00072 #include "llxorcipher.h"        // saved password, MAC address
00073 #include "message.h"
00074 #include "v3math.h"
00075 
00076 #include "llagent.h"
00077 #include "llagentpilot.h"
00078 #include "llfloateravatarpicker.h"
00079 #include "llcallbacklist.h"
00080 #include "llcallingcard.h"
00081 #include "llcolorscheme.h"
00082 #include "llconsole.h"
00083 #include "llcontainerview.h"
00084 #include "llfloaterstats.h"
00085 #include "lldebugview.h"
00086 #include "lldrawable.h"
00087 #include "lleventnotifier.h"
00088 #include "llface.h"
00089 #include "llfeaturemanager.h"
00090 #include "llfirstuse.h"
00091 #include "llfloateractivespeakers.h"
00092 #include "llfloatercamera.h"
00093 #include "llfloaterchat.h"
00094 #include "llfloatergesture.h"
00095 #include "llfloaterhud.h"
00096 #include "llfloaterland.h"
00097 #include "llfloatertopobjects.h"
00098 #include "llfloatertos.h"
00099 #include "llfloaterworldmap.h"
00100 #include "llframestats.h"
00101 #include "llframestatview.h"
00102 #include "llgesturemgr.h"
00103 #include "llgroupmgr.h"
00104 #include "llhudeffecttrail.h"
00105 #include "llhudmanager.h"
00106 #include "llhttpclient.h"
00107 #include "llimagebmp.h"
00108 #include "llinventorymodel.h"
00109 #include "llinventoryview.h"
00110 #include "llkeyboard.h"
00111 #include "llpanellogin.h"
00112 #include "llmutelist.h"
00113 #include "llnotify.h"
00114 #include "llpanelavatar.h"
00115 #include "llpaneldirbrowser.h"
00116 #include "llpaneldirland.h"
00117 #include "llpanelevent.h"
00118 #include "llpanelclassified.h"
00119 #include "llpanelpick.h"
00120 #include "llpanelplace.h"
00121 #include "llpanelgrouplandmoney.h"
00122 #include "llpanelgroupnotices.h"
00123 #include "llpreview.h"
00124 #include "llpreviewscript.h"
00125 #include "llsecondlifeurls.h"
00126 #include "llselectmgr.h"
00127 #include "llsky.h"
00128 #include "llsrv.h"
00129 #include "llstatview.h"
00130 #include "lltrans.h"
00131 #include "llsurface.h"
00132 #include "lltexturecache.h"
00133 #include "lltexturefetch.h"
00134 #include "lltoolmgr.h"
00135 #include "llui.h"
00136 #include "llurldispatcher.h"
00137 #include "llurlsimstring.h"
00138 #include "llurlhistory.h"
00139 #include "llurlwhitelist.h"
00140 #include "lluserauth.h"
00141 #include "llvieweraudio.h"
00142 #include "llviewerassetstorage.h"
00143 #include "llviewercamera.h"
00144 #include "llviewerdisplay.h"
00145 #include "llviewergenericmessage.h"
00146 #include "llviewergesture.h"
00147 #include "llviewerimagelist.h"
00148 #include "llviewermedia.h"
00149 #include "llviewermenu.h"
00150 #include "llviewermessage.h"
00151 #include "llviewernetwork.h"
00152 #include "llviewerobjectlist.h"
00153 #include "llviewerparcelmedia.h"
00154 #include "llviewerparcelmgr.h"
00155 #include "llviewerregion.h"
00156 #include "llviewerstats.h"
00157 #include "llviewerthrottle.h"
00158 #include "llviewerwindow.h"
00159 #include "llvoavatar.h"
00160 #include "llvoclouds.h"
00161 #include "llweb.h"
00162 #include "llworld.h"
00163 #include "llworldmap.h"
00164 #include "llxfermanager.h"
00165 #include "pipeline.h"
00166 #include "llappviewer.h"
00167 #include "llfasttimerview.h"
00168 #include "llfloatermap.h"
00169 #include "llweb.h"
00170 #include "llvoiceclient.h"
00171 #include "llnamelistctrl.h"
00172 #include "llnamebox.h"
00173 #include "llnameeditor.h"
00174 #include "llpostprocess.h"
00175 #include "llwlparammanager.h"
00176 #include "llwaterparammanager.h"
00177 
00178 #if LL_WINDOWS
00179 #include "llwindebug.h"
00180 #include "lldxhardware.h"
00181 #endif
00182 
00183 //
00184 // exported globals
00185 //
00186 BOOL gAgentMovementCompleted = FALSE;
00187 
00188 const char* SCREEN_HOME_FILENAME = "screen_home.bmp";
00189 const char* SCREEN_LAST_FILENAME = "screen_last.bmp";
00190 
00191 //
00192 // Imported globals
00193 //
00194 extern S32 gStartImageWidth;
00195 extern S32 gStartImageHeight;
00196 
00197 //
00198 // local globals
00199 //
00200 
00201 LLPointer<LLImageGL> gStartImageGL;
00202 
00203 static LLHost gAgentSimHost;
00204 static BOOL gSkipOptionalUpdate = FALSE;
00205 
00206 static bool gGotUseCircuitCodeAck = false;
00207 LLString gInitialOutfit;
00208 LLString gInitialOutfitGender;  // "male" or "female"
00209 
00210 static bool gUseCircuitCallbackCalled = false;
00211 
00212 S32 LLStartUp::gStartupState = STATE_FIRST;
00213 
00214 
00215 //
00216 // local function declaration
00217 //
00218 
00219 void login_show();
00220 void login_callback(S32 option, void* userdata);
00221 LLString load_password_from_disk();
00222 void save_password_to_disk(const char* hashed_password);
00223 BOOL is_hex_string(U8* str, S32 len);
00224 void show_first_run_dialog();
00225 void first_run_dialog_callback(S32 option, void* userdata);
00226 void set_startup_status(const F32 frac, const char* string, const char* msg);
00227 void login_alert_status(S32 option, void* user_data);
00228 void update_app(BOOL mandatory, const std::string& message);
00229 void update_dialog_callback(S32 option, void *userdata);
00230 void login_packet_failed(void**, S32 result);
00231 void use_circuit_callback(void**, S32 result);
00232 void register_viewer_callbacks(LLMessageSystem* msg);
00233 void init_stat_view();
00234 void asset_callback_nothing(LLVFS*, const LLUUID&, LLAssetType::EType, void*, S32);
00235 void dialog_choose_gender_first_start();
00236 void callback_choose_gender(S32 option, void* userdata);
00237 void init_start_screen(S32 location_id);
00238 void release_start_screen();
00239 void reset_login();
00240 
00241 void callback_cache_name(const LLUUID& id, const char* firstname, const char* lastname, BOOL is_group, void* data)
00242 {
00243         LLNameListCtrl::refreshAll(id, firstname, lastname, is_group);
00244         LLNameBox::refreshAll(id, firstname, lastname, is_group);
00245         LLNameEditor::refreshAll(id, firstname, lastname, is_group);
00246         
00247         // TODO: Actually be intelligent about the refresh.
00248         // For now, just brute force refresh the dialogs.
00249         dialog_refresh_all();
00250 }
00251 
00252 //
00253 // exported functionality
00254 //
00255 
00256 //
00257 // local classes
00258 //
00259 
00260 namespace
00261 {
00262         class LLNullHTTPSender : public LLHTTPSender
00263         {
00264                 virtual void send(const LLHost& host, 
00265                                                   const char* message, const LLSD& body, 
00266                                                   LLHTTPClient::ResponderPtr response) const
00267                 {
00268                         LL_WARNS("AppInit") << " attemped to send " << message << " to " << host
00269                                         << " with null sender" << LL_ENDL;
00270                 }
00271         };
00272 }
00273 
00274 class LLGestureInventoryFetchObserver : public LLInventoryFetchObserver
00275 {
00276 public:
00277         LLGestureInventoryFetchObserver() {}
00278         virtual void done()
00279         {
00280                 // we've downloaded all the items, so repaint the dialog
00281                 LLFloaterGesture::refreshAll();
00282 
00283                 gInventory.removeObserver(this);
00284                 delete this;
00285         }
00286 };
00287 
00288 void update_texture_fetch()
00289 {
00290         LLAppViewer::getTextureCache()->update(1); // unpauses the texture cache thread
00291         LLAppViewer::getImageDecodeThread()->update(1); // unpauses the image thread
00292         LLAppViewer::getTextureFetch()->update(1); // unpauses the texture fetch thread
00293         gImageList.updateImages(0.10f);
00294 }
00295 
00296 static std::vector<std::string> sAuthUris;
00297 static S32 sAuthUriNum = -1;
00298 
00299 // Returns FALSE to skip other idle processing. Should only return
00300 // TRUE when all initialization done.
00301 BOOL idle_startup()
00302 {
00303         LLMemType mt1(LLMemType::MTYPE_STARTUP);
00304         
00305         const F32 PRECACHING_DELAY = gSavedSettings.getF32("PrecachingDelay");
00306         const F32 TIMEOUT_SECONDS = 5.f;
00307         const S32 MAX_TIMEOUT_COUNT = 3;
00308         static LLTimer timeout;
00309         static S32 timeout_count = 0;
00310 
00311         static LLTimer login_time;
00312 
00313         // until this is encapsulated, this little hack for the
00314         // auth/transform loop will do.
00315         static F32 progress = 0.10f;
00316 
00317         static std::string auth_method;
00318         static std::string auth_desc;
00319         static std::string auth_message;
00320         static LLString firstname;
00321         static LLString lastname;
00322         static LLUUID web_login_key;
00323         static LLString password;
00324         static std::vector<const char*> requested_options;
00325 
00326         static U64 first_sim_handle = 0;
00327         static LLHost first_sim;
00328         static std::string first_sim_seed_cap;
00329 
00330         static LLVector3 initial_sun_direction(1.f, 0.f, 0.f);
00331         static LLVector3 agent_start_position_region(10.f, 10.f, 10.f);         // default for when no space server
00332         static LLVector3 agent_start_look_at(1.0f, 0.f, 0.f);
00333         static std::string agent_start_location = "safe";
00334 
00335         // last location by default
00336         static S32  agent_location_id = START_LOCATION_ID_LAST;
00337         static S32  location_which = START_LOCATION_ID_LAST;
00338 
00339         static BOOL show_connect_box = TRUE;
00340         static BOOL remember_password = TRUE;
00341 
00342         static BOOL stipend_since_login = FALSE;
00343 
00344         static BOOL samename = FALSE;
00345 
00346         BOOL do_normal_idle = FALSE;
00347 
00348         // HACK: These are things from the main loop that usually aren't done
00349         // until initialization is complete, but need to be done here for things
00350         // to work.
00351         gIdleCallbacks.callFunctions();
00352         gViewerWindow->handlePerFrameHover();
00353         LLMortician::updateClass();
00354 
00355         if (gNoRender)
00356         {
00357                 // HACK, skip optional updates if you're running drones
00358                 gSkipOptionalUpdate = TRUE;
00359         }
00360         else
00361         {
00362                 // Update images?
00363                 gImageList.updateImages(0.01f);
00364         }
00365 
00366         if ( STATE_FIRST == LLStartUp::getStartupState() )
00367         {
00368                 gViewerWindow->showCursor();
00369                 gViewerWindow->getWindow()->setCursor(UI_CURSOR_WAIT);
00370 
00372                 //
00373                 // Initialize stuff that doesn't need data from simulators
00374                 //
00375 
00376                 if (LLFeatureManager::getInstance()->isSafe())
00377                 {
00378                         gViewerWindow->alertXml("DisplaySetToSafe");
00379                 }
00380                 else if ((gSavedSettings.getS32("LastFeatureVersion") < LLFeatureManager::getInstance()->getVersion()) &&
00381                                  (gSavedSettings.getS32("LastFeatureVersion") != 0))
00382                 {
00383                         gViewerWindow->alertXml("DisplaySetToRecommended");
00384                 }
00385                 else if (!gViewerWindow->getInitAlert().empty())
00386                 {
00387                         gViewerWindow->alertXml(gViewerWindow->getInitAlert());
00388                 }
00389                         
00390                 gSavedSettings.setS32("LastFeatureVersion", LLFeatureManager::getInstance()->getVersion());
00391 
00392                 LLString xml_file = LLUI::locateSkin("xui_version.xml");
00393                 LLXMLNodePtr root;
00394                 bool xml_ok = false;
00395                 if (LLXMLNode::parseFile(xml_file, root, NULL))
00396                 {
00397                         if( (root->hasName("xui_version") ) )
00398                         {
00399                                 LLString value = root->getValue();
00400                                 F32 version = 0.0f;
00401                                 LLString::convertToF32(value, version);
00402                                 if (version >= 1.0f)
00403                                 {
00404                                         xml_ok = true;
00405                                 }
00406                         }
00407                 }
00408                 if (!xml_ok)
00409                 {
00410                         // *TODO:translate (maybe - very unlikely error message)
00411                         // Note: alerts.xml may be invalid - if this gets translated it will need to be in the code
00412                         LLString bad_xui_msg = "An error occured while updating Second Life. Please download the latest version from www.secondlife.com.";
00413             LLAppViewer::instance()->earlyExit(bad_xui_msg);
00414                 }
00415                 //
00416                 // Statistics stuff
00417                 //
00418 
00419                 // Load autopilot and stats stuff
00420                 gAgentPilot.load(gSavedSettings.getString("StatsPilotFile").c_str());
00421                 gFrameStats.setFilename(gSavedSettings.getString("StatsFile"));
00422                 gFrameStats.setSummaryFilename(gSavedSettings.getString("StatsSummaryFile"));
00423 
00424                 //gErrorStream.setTime(gSavedSettings.getBOOL("LogTimestamps"));
00425 
00426                 // Load the throttle settings
00427                 gViewerThrottle.load();
00428 
00429                 if (ll_init_ares() == NULL)
00430                 {
00431                         LL_ERRS("AppInit") << "Could not start address resolution system" << LL_ENDL;
00432                 }
00433                 
00434                 //
00435                 // Initialize messaging system
00436                 //
00437                 LL_DEBUGS("AppInit") << "Initializing messaging system..." << LL_ENDL;
00438 
00439                 std::string message_template_path = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"message_template.msg");
00440 
00441                 LLFILE* found_template = NULL;
00442                 found_template = LLFile::fopen(message_template_path.c_str(), "r");             /* Flawfinder: ignore */
00443                 if (found_template)
00444                 {
00445                         fclose(found_template);
00446 
00447                         U32 port = gSavedSettings.getU32("UserConnectionPort");
00448 
00449                         if ((NET_USE_OS_ASSIGNED_PORT == port) &&   // if nothing specified on command line (-port)
00450                             (gSavedSettings.getBOOL("ConnectionPortEnabled")))
00451                           {
00452                             port = gSavedSettings.getU32("ConnectionPort");
00453                           }
00454 
00455                         LLHTTPSender::setDefaultSender(new LLNullHTTPSender());
00456                         if(!start_messaging_system(
00457                                    message_template_path,
00458                                    port,
00459                                    LL_VERSION_MAJOR,
00460                                    LL_VERSION_MINOR,
00461                                    LL_VERSION_PATCH,
00462                                    FALSE,
00463                                    std::string()))
00464                         {
00465                                 std::string msg = llformat("Unable to start networking, error %d", gMessageSystem->getErrorCode());
00466                                 LLAppViewer::instance()->earlyExit(msg);
00467                         }
00468                         LLMessageConfig::initClass("viewer", gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, ""));
00469                 }
00470                 else
00471                 {
00472                         LLAppViewer::instance()->earlyExit("Unable to initialize communications.");
00473                 }
00474 
00475                 if(gMessageSystem && gMessageSystem->isOK())
00476                 {
00477                         // Initialize all of the callbacks in case of bad message
00478                         // system data
00479                         LLMessageSystem* msg = gMessageSystem;
00480                         msg->setExceptionFunc(MX_UNREGISTERED_MESSAGE,
00481                                                                   invalid_message_callback,
00482                                                                   NULL);
00483                         msg->setExceptionFunc(MX_PACKET_TOO_SHORT,
00484                                                                   invalid_message_callback,
00485                                                                   NULL);
00486 
00487                         // running off end of a packet is now valid in the case
00488                         // when a reader has a newer message template than
00489                         // the sender
00490                         /*msg->setExceptionFunc(MX_RAN_OFF_END_OF_PACKET,
00491                                                                   invalid_message_callback,
00492                                                                   NULL);*/
00493                         msg->setExceptionFunc(MX_WROTE_PAST_BUFFER_SIZE,
00494                                                                   invalid_message_callback,
00495                                                                   NULL);
00496 
00497                         if (gSavedSettings.getBOOL("LogMessages"))
00498                         {
00499                                 LL_DEBUGS("AppInit") << "Message logging activated!" << LL_ENDL;
00500                                 msg->startLogging();
00501                         }
00502 
00503                         // start the xfer system. by default, choke the downloads
00504                         // a lot...
00505                         const S32 VIEWER_MAX_XFER = 3;
00506                         start_xfer_manager(gVFS);
00507                         gXferManager->setMaxIncomingXfers(VIEWER_MAX_XFER);
00508                         F32 xfer_throttle_bps = gSavedSettings.getF32("XferThrottle");
00509                         if (xfer_throttle_bps > 1.f)
00510                         {
00511                                 gXferManager->setUseAckThrottling(TRUE);
00512                                 gXferManager->setAckThrottleBPS(xfer_throttle_bps);
00513                         }
00514                         gAssetStorage = new LLViewerAssetStorage(msg, gXferManager, gVFS);
00515 
00516 
00517                         F32 dropPercent = gSavedSettings.getF32("PacketDropPercentage");
00518                         msg->mPacketRing.setDropPercentage(dropPercent);
00519 
00520             F32 inBandwidth = gSavedSettings.getF32("InBandwidth"); 
00521             F32 outBandwidth = gSavedSettings.getF32("OutBandwidth"); 
00522                         if (inBandwidth != 0.f)
00523                         {
00524                                 LL_DEBUGS("AppInit") << "Setting packetring incoming bandwidth to " << inBandwidth << LL_ENDL;
00525                                 msg->mPacketRing.setUseInThrottle(TRUE);
00526                                 msg->mPacketRing.setInBandwidth(inBandwidth);
00527                         }
00528                         if (outBandwidth != 0.f)
00529                         {
00530                                 LL_DEBUGS("AppInit") << "Setting packetring outgoing bandwidth to " << outBandwidth << LL_ENDL;
00531                                 msg->mPacketRing.setUseOutThrottle(TRUE);
00532                                 msg->mPacketRing.setOutBandwidth(outBandwidth);
00533                         }
00534                 }
00535 
00536                 //-------------------------------------------------
00537                 // Init audio, which may be needed for prefs dialog
00538                 // or audio cues in connection UI.
00539                 //-------------------------------------------------
00540 
00541                 if (FALSE == gSavedSettings.getBOOL("NoAudio"))
00542                 {
00543 #if LL_FMOD
00544                         gAudiop = (LLAudioEngine *) new LLAudioEngine_FMOD();
00545 #else
00546                         gAudiop = NULL;
00547 #endif
00548 
00549                         if (gAudiop)
00550                         {
00551 #if LL_WINDOWS
00552                                 // FMOD on Windows needs the window handle to stop playing audio
00553                                 // when window is minimized. JC
00554                                 void* window_handle = (HWND)gViewerWindow->getPlatformWindow();
00555 #else
00556                                 void* window_handle = NULL;
00557 #endif
00558                                 BOOL init = gAudiop->init(kAUDIO_NUM_SOURCES, window_handle);
00559                                 if(!init)
00560                                 {
00561                                         LL_WARNS("AppInit") << "Unable to initialize audio engine" << LL_ENDL;
00562                                 }
00563                                 gAudiop->setMuted(TRUE);
00564                         }
00565                 }
00566 
00567                 if (LLTimer::knownBadTimer())
00568                 {
00569                         LL_WARNS("AppInit") << "Unreliable timers detected (may be bad PCI chipset)!!" << LL_ENDL;
00570                 }
00571 
00572                 //
00573                 // Log on to system
00574                 //
00575                 if ((!gLoginHandler.mFirstName.empty() &&
00576                          !gLoginHandler.mLastName.empty() &&
00577                          !gLoginHandler.mWebLoginKey.isNull())          
00578                         || gLoginHandler.parseDirectLogin(LLStartUp::sSLURLCommand) )
00579                 {
00580                         firstname = gLoginHandler.mFirstName;
00581                         lastname = gLoginHandler.mLastName;
00582                         web_login_key = gLoginHandler.mWebLoginKey;
00583 
00584                         show_connect_box = FALSE;
00585                 }
00586         else if(gSavedSettings.getLLSD("UserLoginInfo").size() == 3)
00587         {
00588             LLSD cmd_line_login = gSavedSettings.getLLSD("UserLoginInfo");
00589                         firstname = cmd_line_login[0].asString();
00590                         lastname = cmd_line_login[1].asString();
00591 
00592                         LLMD5 pass((unsigned char*)cmd_line_login[2].asString().c_str());
00593                         char md5pass[33];               /* Flawfinder: ignore */
00594                         pass.hex_digest(md5pass);
00595                         password = md5pass;
00596                         remember_password = gSavedSettings.getBOOL("RememberPassword");
00597                         
00598 #ifdef USE_VIEWER_AUTH
00599                         show_connect_box = TRUE;
00600 #else
00601                         show_connect_box = FALSE;
00602 #endif
00603                         gSavedSettings.setBOOL("AutoLogin", TRUE);
00604         }
00605                 else if (gSavedSettings.getBOOL("AutoLogin"))
00606                 {
00607                         firstname = gSavedSettings.getString("FirstName");
00608                         lastname = gSavedSettings.getString("LastName");
00609                         password = load_password_from_disk();
00610                         gSavedSettings.setBOOL("RememberPassword", TRUE);
00611                         remember_password = TRUE;
00612                         
00613 #ifdef USE_VIEWER_AUTH
00614                         show_connect_box = TRUE;
00615 #else
00616                         show_connect_box = FALSE;
00617 #endif
00618                 }
00619                 else
00620                 {
00621                         // if not automatically logging in, display login dialog
00622                         // a valid grid is selected
00623                         firstname = gSavedSettings.getString("FirstName");
00624                         lastname = gSavedSettings.getString("LastName");
00625                         password = load_password_from_disk();
00626                         remember_password = gSavedSettings.getBOOL("RememberPassword");
00627                         show_connect_box = TRUE;
00628                 }
00629 
00630 
00631                 // Go to the next startup state
00632                 LLStartUp::setStartupState( STATE_MEDIA_INIT );
00633                 return do_normal_idle;
00634         }
00635 
00636         
00637         //---------------------------------------------------------------------
00638         // LLMediaEngine Init
00639         //---------------------------------------------------------------------
00640         if (STATE_MEDIA_INIT == LLStartUp::getStartupState())
00641         {
00642                 LL_DEBUGS("AppInit") << "Initializing Multimedia...." << LL_ENDL;
00643                 set_startup_status(0.03f, "Initializing Multimedia...", gAgent.mMOTD.c_str());
00644                 display_startup();
00645                 LLViewerMedia::initClass();
00646                 LLViewerParcelMedia::initClass();
00647 
00648                 if (gViewerWindow)
00649                 {
00650                         audio_update_volume(true);
00651                 }
00652 
00653                 LLStartUp::setStartupState( STATE_LOGIN_SHOW );
00654                 return do_normal_idle;
00655         }
00656 
00657         if (STATE_LOGIN_SHOW == LLStartUp::getStartupState())
00658         {               
00659 
00660                 LL_DEBUGS("AppInit") << "Initializing Window" << LL_ENDL;
00661                 
00662                 gViewerWindow->getWindow()->setCursor(UI_CURSOR_ARROW);
00663                 // Push our window frontmost
00664                 gViewerWindow->getWindow()->show();
00665 
00666                 timeout_count = 0;
00667 
00668                 if (show_connect_box)
00669                 {
00670                         // Load all the name information out of the login view
00671                         // NOTE: Hits "Attempted getFields with no login view shown" warning, since we don't
00672                         // show the login view until login_show() is called below.  
00673                         // LLPanelLogin::getFields(firstname, lastname, password, remember_password);
00674 
00675                         if (gNoRender)
00676                         {
00677                                 LL_ERRS("AppInit") << "Need to autologin or use command line with norender!" << LL_ENDL;
00678                         }
00679                         // Make sure the process dialog doesn't hide things
00680                         gViewerWindow->setShowProgress(FALSE);
00681 
00682                         // Show the login dialog
00683                         login_show();
00684                         // connect dialog is already shown, so fill in the names
00685                         LLPanelLogin::setFields( firstname, lastname, password, remember_password );
00686 
00687                         LLPanelLogin::giveFocus();
00688 
00689                         gSavedSettings.setBOOL("FirstRunThisInstall", FALSE);
00690 
00691                         LLStartUp::setStartupState( STATE_LOGIN_WAIT );         // Wait for user input
00692                 }
00693                 else
00694                 {
00695                         // skip directly to message template verification
00696                         LLStartUp::setStartupState( STATE_LOGIN_CLEANUP );
00697                 }
00698 
00699                 // *NOTE: This is where LLViewerParcelMgr::getInstance() used to get allocated before becoming LLViewerParcelMgr::getInstance().
00700 
00701                 // *NOTE: This is where gHUDManager used to bet allocated before becoming LLHUDManager::getInstance().
00702 
00703                 // *NOTE: This is where gMuteList used to get allocated before becoming LLMuteList::getInstance().
00704 
00705                 // Initialize UI
00706                 if (!gNoRender)
00707                 {
00708                         // Initialize all our tools.  Must be done after saved settings loaded.
00709                         // NOTE: This also is where gToolMgr used to be instantiated before being turned into a singleton.
00710                         LLToolMgr::getInstance()->initTools();
00711 
00712                         // Quickly get something onscreen to look at.
00713                         gViewerWindow->initWorldUI();
00714                 }
00715                 
00716                 gViewerWindow->setNormalControlsVisible( FALSE );       
00717                 gLoginMenuBarView->setVisible( TRUE );
00718                 gLoginMenuBarView->setEnabled( TRUE );
00719 
00720                 timeout.reset();
00721                 return do_normal_idle;
00722         }
00723 
00724         if (STATE_LOGIN_WAIT == LLStartUp::getStartupState())
00725         {
00726                 // Don't do anything.  Wait for the login view to call the login_callback,
00727                 // which will push us to the next state.
00728 
00729                 // Sleep so we don't spin the CPU
00730                 ms_sleep(1);
00731                 return do_normal_idle;
00732         }
00733 
00734         if (STATE_LOGIN_CLEANUP == LLStartUp::getStartupState())
00735         {
00736                 //reset the values that could have come in from a slurl
00737                 if (!gLoginHandler.mWebLoginKey.isNull())
00738                 {
00739                         firstname = gLoginHandler.mFirstName;
00740                         lastname = gLoginHandler.mLastName;
00741                         web_login_key = gLoginHandler.mWebLoginKey;
00742                 }
00743                                 
00744                 if (show_connect_box)
00745                 {
00746                         // TODO if not use viewer auth
00747                         // Load all the name information out of the login view
00748                         LLPanelLogin::getFields(firstname, lastname, password, remember_password);
00749                         // end TODO
00750          
00751                         // HACK: Try to make not jump on login
00752                         gKeyboard->resetKeys();
00753                 }
00754 
00755                 if (!firstname.empty() && !lastname.empty())
00756                 {
00757                         gSavedSettings.setString("FirstName", firstname);
00758                         gSavedSettings.setString("LastName", lastname);
00759 
00760                         if (remember_password)
00761                         {
00762                                    save_password_to_disk(password.c_str());
00763                         }
00764                         else
00765                         {
00766                                    save_password_to_disk(NULL);
00767                         }
00768                         gSavedSettings.setBOOL("RememberPassword", remember_password);
00769 
00770                         LL_INFOS("AppInit") << "Attempting login as: " << firstname << " " << lastname << LL_ENDL;
00771                         gDebugInfo["LoginName"] = firstname + " " + lastname;   
00772                 }
00773 
00774                 // create necessary directories
00775                 // *FIX: these mkdir's should error check
00776                 gDirUtilp->setLindenUserDir(firstname.c_str(), lastname.c_str());
00777         LLFile::mkdir(gDirUtilp->getLindenUserDir().c_str());
00778 
00779         // Set PerAccountSettingsFile to the default value.
00780                 gSavedSettings.setString("PerAccountSettingsFile",
00781                         gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, 
00782                                 LLAppViewer::instance()->getSettingsFileName("PerAccount")
00783                                 )
00784                         );
00785 
00786                 // Overwrite default user settings with user settings                                                            
00787                 LLAppViewer::instance()->loadSettingsFromDirectory(LL_PATH_PER_SL_ACCOUNT);
00788 
00789                 // Need to set the LastLogoff time here if we don't have one.  LastLogoff is used for "Recent Items" calculation
00790                 // and startup time is close enough if we don't have a real value.
00791                 if (gSavedPerAccountSettings.getU32("LastLogoff") == 0)
00792                 {
00793                         gSavedPerAccountSettings.setU32("LastLogoff", time_corrected());
00794                 }
00795 
00796                 //Default the path if one isn't set.
00797                 if (gSavedPerAccountSettings.getString("InstantMessageLogPath").empty())
00798                 {
00799                         gDirUtilp->setChatLogsDir(gDirUtilp->getOSUserAppDir());
00800                         gSavedPerAccountSettings.setString("InstantMessageLogPath",gDirUtilp->getChatLogsDir());
00801                 }
00802                 else
00803                 {
00804                         gDirUtilp->setChatLogsDir(gSavedPerAccountSettings.getString("InstantMessageLogPath"));         
00805                 }
00806                 
00807                 gDirUtilp->setPerAccountChatLogsDir(firstname.c_str(), lastname.c_str());
00808 
00809                 LLFile::mkdir(gDirUtilp->getChatLogsDir().c_str());
00810                 LLFile::mkdir(gDirUtilp->getPerAccountChatLogsDir().c_str());
00811 
00812                 if (show_connect_box)
00813                 {
00814                         // TODO only set loginuri based on server choice if ! USE_VIEWER_AUTH
00815                         LLString server_label;
00816                         S32 domain_name_index;
00817                         BOOL user_picked_server = LLPanelLogin::getServer( server_label, domain_name_index );
00818                         gGridChoice = (EGridInfo) domain_name_index;
00819                         gSavedSettings.setS32("ServerChoice", gGridChoice);
00820                         if (gGridChoice == GRID_INFO_OTHER)
00821                         {
00822                                 gGridName = server_label;/* Flawfinder: ignore */
00823                         }
00824                         
00825                         if ( user_picked_server )
00826                         {   // User picked a grid from the popup, so clear the stored urls and they will be re-generated from gGridChoice
00827                                 sAuthUris.clear();
00828                                 LLAppViewer::instance()->resetURIs();
00829                         }
00830                         
00831                         LLString location;
00832                         LLPanelLogin::getLocation( location );
00833                         LLURLSimString::setString( location );
00834                         // END TODO
00835                         LLPanelLogin::close();
00836                 }
00837 
00838                 
00839                 //For HTML parsing in text boxes.
00840                 LLTextEditor::setLinkColor( gSavedSettings.getColor4("HTMLLinkColor") );
00841                 LLTextEditor::setURLCallbacks ( &LLWeb::loadURL,
00842                                 &LLURLDispatcher::dispatchFromTextEditor,
00843                                 &LLURLDispatcher::dispatchFromTextEditor   );
00844 
00845                 // Load URL History File
00846                 LLURLHistory::loadFile("url_history.xml");
00847 
00848                 //-------------------------------------------------
00849                 // Handle startup progress screen
00850                 //-------------------------------------------------
00851 
00852                 // on startup the user can request to go to their home,
00853                 // their last location, or some URL "-url //sim/x/y[/z]"
00854                 // All accounts have both a home and a last location, and we don't support
00855                 // more locations than that.  Choose the appropriate one.  JC
00856                 if (LLURLSimString::parse())
00857                 {
00858                         // a startup URL was specified
00859                         agent_location_id = START_LOCATION_ID_URL;
00860 
00861                         // doesn't really matter what location_which is, since
00862                         // agent_start_look_at will be overwritten when the
00863                         // UserLoginLocationReply arrives
00864                         location_which = START_LOCATION_ID_LAST;
00865                 }
00866                 else if (gSavedSettings.getBOOL("LoginLastLocation"))
00867                 {
00868                         agent_location_id = START_LOCATION_ID_LAST;     // last location
00869                         location_which = START_LOCATION_ID_LAST;
00870                 }
00871                 else
00872                 {
00873                         agent_location_id = START_LOCATION_ID_HOME;     // home
00874                         location_which = START_LOCATION_ID_HOME;
00875                 }
00876 
00877                 gViewerWindow->getWindow()->setCursor(UI_CURSOR_WAIT);
00878 
00879                 if (!gNoRender)
00880                 {
00881                         init_start_screen(agent_location_id);
00882                 }
00883 
00884                 // Display the startup progress bar.
00885                 gViewerWindow->setShowProgress(TRUE);
00886                 gViewerWindow->setProgressCancelButtonVisible(TRUE, "Quit");
00887 
00888                 // Poke the VFS, which could potentially block for a while if
00889                 // Windows XP is acting up
00890                 set_startup_status(0.07f, LLTrans::getString("LoginVerifyingCache").c_str(), NULL);
00891                 display_startup();
00892 
00893                 gVFS->pokeFiles();
00894 
00895                 // color init must be after saved settings loaded
00896                 init_colors();
00897 
00898                 // skipping over STATE_UPDATE_CHECK because that just waits for input
00899                 LLStartUp::setStartupState( STATE_LOGIN_AUTH_INIT );
00900 
00901                 return do_normal_idle;
00902         }
00903 
00904         if (STATE_UPDATE_CHECK == LLStartUp::getStartupState())
00905         {
00906                 // wait for user to give input via dialog box
00907                 return do_normal_idle;
00908         }
00909 
00910         if(STATE_LOGIN_AUTH_INIT == LLStartUp::getStartupState())
00911         {
00912 //#define LL_MINIMIAL_REQUESTED_OPTIONS
00913                 gDebugInfo["GridName"] = gGridInfo[gGridChoice].mLabel;
00914 
00915                 // *Note: this is where gUserAuth used to be created.
00916                 requested_options.clear();
00917                 requested_options.push_back("inventory-root");
00918                 requested_options.push_back("inventory-skeleton");
00919                 //requested_options.push_back("inventory-meat");
00920                 //requested_options.push_back("inventory-skel-targets");
00921 #if (!defined LL_MINIMIAL_REQUESTED_OPTIONS)
00922                 if(FALSE == gSavedSettings.getBOOL("NoInventoryLibrary"))
00923                 {
00924                         requested_options.push_back("inventory-lib-root");
00925                         requested_options.push_back("inventory-lib-owner");
00926                         requested_options.push_back("inventory-skel-lib");
00927                 //      requested_options.push_back("inventory-meat-lib");
00928                 }
00929 
00930                 requested_options.push_back("initial-outfit");
00931                 requested_options.push_back("gestures");
00932                 requested_options.push_back("event_categories");
00933                 requested_options.push_back("event_notifications");
00934                 requested_options.push_back("classified_categories");
00935                 //requested_options.push_back("inventory-targets");
00936                 requested_options.push_back("buddy-list");
00937                 requested_options.push_back("ui-config");
00938 #endif
00939                 requested_options.push_back("tutorial_setting");
00940                 requested_options.push_back("login-flags");
00941                 requested_options.push_back("global-textures");
00942                 if(gSavedSettings.getBOOL("ConnectAsGod"))
00943                 {
00944                         gSavedSettings.setBOOL("UseDebugMenus", TRUE);
00945                         requested_options.push_back("god-connect");
00946                 }
00947                 const std::vector<std::string>& uris = LLAppViewer::instance()->getLoginURIs();
00948                 std::vector<std::string>::const_iterator iter, end;
00949                 for (iter = uris.begin(), end = uris.end(); iter != end; ++iter)
00950                 {
00951                         std::vector<std::string> rewritten;
00952                         rewritten = LLSRV::rewriteURI(*iter);
00953                         sAuthUris.insert(sAuthUris.end(),
00954                                                          rewritten.begin(), rewritten.end());
00955                 }
00956                 sAuthUriNum = 0;
00957                 auth_method = "login_to_simulator";
00958                 
00959                 LLString::format_map_t args;
00960                 args["[APP_NAME]"] = LLAppViewer::instance()->getSecondLifeTitle();
00961                 auth_desc = LLTrans::getString("LoginInProgress", args).c_str();
00962                 LLStartUp::setStartupState( STATE_LOGIN_AUTHENTICATE );
00963         }
00964 
00965         if (STATE_LOGIN_AUTHENTICATE == LLStartUp::getStartupState())
00966         {
00967                 LL_DEBUGS("AppInit") << "STATE_LOGIN_AUTHENTICATE" << LL_ENDL;
00968                 set_startup_status(progress, auth_desc.c_str(), auth_message.c_str());
00969                 progress += 0.02f;
00970                 display_startup();
00971                 
00972                 std::stringstream start;
00973                 if (LLURLSimString::parse())
00974                 {
00975                         // a startup URL was specified
00976                         std::stringstream unescaped_start;
00977                         unescaped_start << "uri:" 
00978                                                         << LLURLSimString::sInstance.mSimName << "&" 
00979                                                         << LLURLSimString::sInstance.mX << "&" 
00980                                                         << LLURLSimString::sInstance.mY << "&" 
00981                                                         << LLURLSimString::sInstance.mZ;
00982                         start << xml_escape_string(unescaped_start.str().c_str());
00983                         
00984                 }
00985                 else if (gSavedSettings.getBOOL("LoginLastLocation"))
00986                 {
00987                         start << "last";
00988                 }
00989                 else
00990                 {
00991                         start << "home";
00992                 }
00993 
00994                 char hashed_mac_string[MD5HEX_STR_SIZE];                /* Flawfinder: ignore */
00995                 LLMD5 hashed_mac;
00996                 hashed_mac.update( gMACAddress, MAC_ADDRESS_BYTES );
00997                 hashed_mac.finalize();
00998                 hashed_mac.hex_digest(hashed_mac_string);
00999 
01000                 // TODO if statement here to use web_login_key
01001                 sAuthUriNum = llclamp(sAuthUriNum, 0, (S32)sAuthUris.size()-1);
01002                 LLUserAuth::getInstance()->authenticate(
01003                         sAuthUris[sAuthUriNum].c_str(),
01004                         auth_method.c_str(),
01005                         firstname.c_str(),
01006                         lastname.c_str(),
01007                         // web_login_key,
01008                         password.c_str(),
01009                         start.str().c_str(),
01010                         gSkipOptionalUpdate,
01011                         gAcceptTOS,
01012                         gAcceptCriticalMessage,
01013                         gLastExecEvent,
01014                         requested_options,
01015                         hashed_mac_string,
01016                         LLAppViewer::instance()->getSerialNumber());
01017 
01018                 // reset globals
01019                 gAcceptTOS = FALSE;
01020                 gAcceptCriticalMessage = FALSE;
01021                 LLStartUp::setStartupState( STATE_LOGIN_NO_DATA_YET );
01022                 return do_normal_idle;
01023         }
01024 
01025         if(STATE_LOGIN_NO_DATA_YET == LLStartUp::getStartupState())
01026         {
01027                 LL_DEBUGS("AppInit") << "STATE_LOGIN_NO_DATA_YET" << LL_ENDL;
01028                 // If we get here we have gotten past the potential stall
01029                 // in curl, so take "may appear frozen" out of progress bar. JC
01030                 auth_desc = "Logging in...";
01031                 set_startup_status(progress, auth_desc.c_str(), auth_message.c_str());
01032                 // Process messages to keep from dropping circuit.
01033                 LLMessageSystem* msg = gMessageSystem;
01034                 while (msg->checkAllMessages(gFrameCount, gServicePump))
01035                 {
01036                 }
01037                 msg->processAcks();
01038                 LLUserAuth::UserAuthcode error = LLUserAuth::getInstance()->authResponse();
01039                 if(LLUserAuth::E_NO_RESPONSE_YET == error)
01040                 {
01041                         LL_DEBUGS("AppInit") << "waiting..." << LL_ENDL;
01042                         return do_normal_idle;
01043                 }
01044                 LLStartUp::setStartupState( STATE_LOGIN_DOWNLOADING );
01045                 progress += 0.01f;
01046                 set_startup_status(progress, auth_desc.c_str(), auth_message.c_str());
01047                 return do_normal_idle;
01048         }
01049 
01050         if(STATE_LOGIN_DOWNLOADING == LLStartUp::getStartupState())
01051         {
01052                 LL_DEBUGS("AppInit") << "STATE_LOGIN_DOWNLOADING" << LL_ENDL;
01053                 // Process messages to keep from dropping circuit.
01054                 LLMessageSystem* msg = gMessageSystem;
01055                 while (msg->checkAllMessages(gFrameCount, gServicePump))
01056                 {
01057                 }
01058                 msg->processAcks();
01059                 LLUserAuth::UserAuthcode error = LLUserAuth::getInstance()->authResponse();
01060                 if(LLUserAuth::E_DOWNLOADING == error)
01061                 {
01062                         LL_DEBUGS("AppInit") << "downloading..." << LL_ENDL;
01063                         return do_normal_idle;
01064                 }
01065                 LLStartUp::setStartupState( STATE_LOGIN_PROCESS_RESPONSE );
01066                 progress += 0.01f;
01067                 set_startup_status(progress, LLTrans::getString("LoginProcessingResponse").c_str(), auth_message.c_str());
01068                 return do_normal_idle;
01069         }
01070 
01071         if(STATE_LOGIN_PROCESS_RESPONSE == LLStartUp::getStartupState())
01072         {
01073                 LL_DEBUGS("AppInit") << "STATE_LOGIN_PROCESS_RESPONSE" << LL_ENDL;
01074                 std::ostringstream emsg;
01075                 BOOL quit = FALSE;
01076                 const char* login_response = NULL;
01077                 const char* reason_response = NULL;
01078                 const char* message_response = NULL;
01079                 BOOL successful_login = FALSE;
01080                 LLUserAuth::UserAuthcode error = LLUserAuth::getInstance()->authResponse();
01081                 // reset globals
01082                 gAcceptTOS = FALSE;
01083                 gAcceptCriticalMessage = FALSE;
01084                 switch(error)
01085                 {
01086                 case LLUserAuth::E_OK:
01087                         login_response = LLUserAuth::getInstance()->getResponse("login");
01088                         if(login_response && (0 == strcmp(login_response, "true")))
01089                         {
01090                                 // Yay, login!
01091                                 successful_login = TRUE;
01092                         }
01093                         else if(login_response && (0 == strcmp(login_response, "indeterminate")))
01094                         {
01095                                 LL_INFOS("AppInit") << "Indeterminate login..." << LL_ENDL;
01096                                 sAuthUris = LLSRV::rewriteURI(LLUserAuth::getInstance()->getResponse("next_url"));
01097                                 sAuthUriNum = 0;
01098                                 auth_method = LLUserAuth::getInstance()->getResponse("next_method");
01099                                 auth_message = LLUserAuth::getInstance()->getResponse("message");
01100                                 if(auth_method.substr(0, 5) == "login")
01101                                 {
01102                                         auth_desc.assign(LLTrans::getString("LoginAuthenticating").c_str());
01103                                 }
01104                                 else
01105                                 {
01106                                         auth_desc.assign(LLTrans::getString("LoginMaintenance").c_str());
01107                                 }
01108                                 // ignoring the duration & options array for now.
01109                                 // Go back to authenticate.
01110                                 LLStartUp::setStartupState( STATE_LOGIN_AUTHENTICATE );
01111                                 return do_normal_idle;
01112                         }
01113                         else
01114                         {
01115                                 emsg << "Login failed.\n";
01116                                 reason_response = LLUserAuth::getInstance()->getResponse("reason");
01117                                 message_response = LLUserAuth::getInstance()->getResponse("message");
01118 
01119                                 if (gHideLinks && reason_response && (0 == strcmp(reason_response, "disabled")))
01120                                 {
01121                                         emsg << gDisabledMessage;
01122                                 }
01123                                 else if (message_response)
01124                                 {
01125                                         // XUI: fix translation for strings returned during login
01126                                         // We need a generic table for translations
01127                                         LLString big_reason = LLAgent::sTeleportErrorMessages[ message_response ];
01128                                         if ( big_reason.size() == 0 )
01129                                         {
01130                                                 emsg << message_response;
01131                                         }
01132                                         else
01133                                         {
01134                                                 emsg << big_reason;
01135                                         }
01136                                 }
01137 
01138                                 if(reason_response && (0 == strcmp(reason_response, "tos")))
01139                                 {
01140                                         if (show_connect_box)
01141                                         {
01142                                                 LL_DEBUGS("AppInit") << "Need tos agreement" << LL_ENDL;
01143                                                 LLStartUp::setStartupState( STATE_UPDATE_CHECK );
01144                                                 LLFloaterTOS* tos_dialog = LLFloaterTOS::show(LLFloaterTOS::TOS_TOS,
01145                                                                                                                                         message_response);
01146                                                 tos_dialog->startModal();
01147                                                 // LLFloaterTOS deletes itself.
01148                                                 return FALSE;
01149                                         }
01150                                         else
01151                                         {
01152                                                 quit = TRUE;
01153                                         }
01154                                 }
01155                                 if(reason_response && (0 == strcmp(reason_response, "critical")))
01156                                 {
01157                                         if (show_connect_box)
01158                                         {
01159                                                 LL_DEBUGS("AppInit") << "Need critical message" << LL_ENDL;
01160                                                 LLStartUp::setStartupState( STATE_UPDATE_CHECK );
01161                                                 LLFloaterTOS* tos_dialog = LLFloaterTOS::show(LLFloaterTOS::TOS_CRITICAL_MESSAGE,
01162                                                                                                                                         message_response);
01163                                                 tos_dialog->startModal();
01164                                                 // LLFloaterTOS deletes itself.
01165                                                 return FALSE;
01166                                         }
01167                                         else
01168                                         {
01169                                                 quit = TRUE;
01170                                         }
01171                                 }
01172                                 if(reason_response && (0 == strcmp(reason_response, "key")))
01173                                 {
01174                                         // Couldn't login because user/password is wrong
01175                                         // Clear the password
01176                                         password = "";
01177                                 }
01178                                 if(reason_response && (0 == strcmp(reason_response, "update")))
01179                                 {
01180                                         auth_message = LLUserAuth::getInstance()->getResponse("message");
01181                                         if (show_connect_box)
01182                                         {
01183                                                 update_app(TRUE, auth_message);
01184                                                 LLStartUp::setStartupState( STATE_UPDATE_CHECK );
01185                                                 return FALSE;
01186                                         }
01187                                         else
01188                                         {
01189                                                 quit = TRUE;
01190                                         }
01191                                 }
01192                                 if(reason_response && (0 == strcmp(reason_response, "optional")))
01193                                 {
01194                                         LL_DEBUGS("AppInit") << "Login got optional update" << LL_ENDL;
01195                                         auth_message = LLUserAuth::getInstance()->getResponse("message");
01196                                         if (show_connect_box)
01197                                         {
01198                                                 update_app(FALSE, auth_message);
01199                                                 LLStartUp::setStartupState( STATE_UPDATE_CHECK );
01200                                                 gSkipOptionalUpdate = TRUE;
01201                                                 return FALSE;
01202                                         }
01203                                 }
01204                         }
01205                         break;
01206                 case LLUserAuth::E_COULDNT_RESOLVE_HOST:
01207                 case LLUserAuth::E_SSL_PEER_CERTIFICATE:
01208                 case LLUserAuth::E_UNHANDLED_ERROR:
01209                 case LLUserAuth::E_SSL_CACERT:
01210                 case LLUserAuth::E_SSL_CONNECT_ERROR:
01211                 default:
01212                         if (sAuthUriNum >= (int) sAuthUris.size() - 1)
01213                         {
01214                                 emsg << "Unable to connect to " << LLAppViewer::instance()->getSecondLifeTitle() << ".\n";
01215                                 emsg << LLUserAuth::getInstance()->errorMessage();
01216                         } else {
01217                                 sAuthUriNum++;
01218                                 std::ostringstream s;
01219                                 LLString::format_map_t args;
01220                                 args["[NUMBER]"] = sAuthUriNum + 1;
01221                                 auth_desc = LLTrans::getString("LoginAttempt", args).c_str();
01222                                 LLStartUp::setStartupState( STATE_LOGIN_AUTHENTICATE );
01223                                 return do_normal_idle;
01224                         }
01225                         break;
01226                 }
01227 
01228                 // Version update and we're not showing the dialog
01229                 if(quit)
01230                 {
01231                         LLUserAuth::getInstance()->reset();
01232                         LLAppViewer::instance()->forceQuit();
01233                         return FALSE;
01234                 }
01235 
01236                 if(successful_login)
01237                 {
01238                         // unpack login data needed by the application
01239                         const char* text;
01240                         text = LLUserAuth::getInstance()->getResponse("agent_id");
01241                         if(text) gAgentID.set(text);
01242                         gDebugInfo["AgentID"] = text;
01243                         
01244                         text = LLUserAuth::getInstance()->getResponse("session_id");
01245                         if(text) gAgentSessionID.set(text);
01246                         gDebugInfo["SessionID"] = text;
01247                         
01248                         text = LLUserAuth::getInstance()->getResponse("secure_session_id");
01249                         if(text) gAgent.mSecureSessionID.set(text);
01250 
01251                         text = LLUserAuth::getInstance()->getResponse("first_name");
01252                         if(text) 
01253                         {
01254                                 // Remove quotes from string.  Login.cgi sends these to force
01255                                 // names that look like numbers into strings.
01256                                 firstname.assign(text);
01257                                 LLString::replaceChar(firstname, '"', ' ');
01258                                 LLString::trim(firstname);
01259                         }
01260                         text = LLUserAuth::getInstance()->getResponse("last_name");
01261                         if(text) lastname.assign(text);
01262                         gSavedSettings.setString("FirstName", firstname);
01263                         gSavedSettings.setString("LastName", lastname);
01264 
01265                         if (remember_password)
01266                         {
01267                                    save_password_to_disk(password.c_str());
01268                         }
01269                         else
01270                         {
01271                                    save_password_to_disk(NULL);
01272                         }
01273                         gSavedSettings.setBOOL("RememberPassword", remember_password);
01274                         gSavedSettings.setBOOL("LoginLastLocation", gSavedSettings.getBOOL("LoginLastLocation"));
01275 
01276                         text = LLUserAuth::getInstance()->getResponse("agent_access");
01277                         if(text && (text[0] == 'M'))
01278                         {
01279                                 gAgent.setTeen(false);
01280                         }
01281                         else
01282                         {
01283                                 gAgent.setTeen(true);
01284                         }
01285 
01286                         text = LLUserAuth::getInstance()->getResponse("start_location");
01287                         if(text) agent_start_location.assign(text);
01288                         text = LLUserAuth::getInstance()->getResponse("circuit_code");
01289                         if(text)
01290                         {
01291                                 gMessageSystem->mOurCircuitCode = strtoul(text, NULL, 10);
01292                         }
01293                         const char* sim_ip_str = LLUserAuth::getInstance()->getResponse("sim_ip");
01294                         const char* sim_port_str = LLUserAuth::getInstance()->getResponse("sim_port");
01295                         if(sim_ip_str && sim_port_str)
01296                         {
01297                                 U32 sim_port = strtoul(sim_port_str, NULL, 10);
01298                                 first_sim.set(sim_ip_str, sim_port);
01299                                 if (first_sim.isOk())
01300                                 {
01301                                         gMessageSystem->enableCircuit(first_sim, TRUE);
01302                                 }
01303                         }
01304                         const char* region_x_str = LLUserAuth::getInstance()->getResponse("region_x");
01305                         const char* region_y_str = LLUserAuth::getInstance()->getResponse("region_y");
01306                         if(region_x_str && region_y_str)
01307                         {
01308                                 U32 region_x = strtoul(region_x_str, NULL, 10);
01309                                 U32 region_y = strtoul(region_y_str, NULL, 10);
01310                                 first_sim_handle = to_region_handle(region_x, region_y);
01311                         }
01312                         
01313                         const char* look_at_str = LLUserAuth::getInstance()->getResponse("look_at");
01314                         if (look_at_str)
01315                         {
01316 #if !LL_WINDOWS && !LL_DARWIN
01317                                 size_t len = strnlen(look_at_str, MAX_STRING);
01318 #else
01319                                 size_t len = strlen(look_at_str);
01320 #endif
01321                                 LLMemoryStream mstr((U8*)look_at_str, len);
01322                                 LLSD sd = LLSDSerialize::fromNotation(mstr, len);
01323                                 agent_start_look_at = ll_vector3_from_sd(sd);
01324                         }
01325 
01326                         text = LLUserAuth::getInstance()->getResponse("seed_capability");
01327                         if (text) first_sim_seed_cap = text;
01328                                                 
01329                         text = LLUserAuth::getInstance()->getResponse("seconds_since_epoch");
01330                         if(text)
01331                         {
01332                                 U32 server_utc_time = strtoul(text, NULL, 10);
01333                                 if(server_utc_time)
01334                                 {
01335                                         time_t now = time(NULL);
01336                                         gUTCOffset = (server_utc_time - now);
01337                                 }
01338                         }
01339 
01340                         const char* home_location = LLUserAuth::getInstance()->getResponse("home");
01341                         if(home_location)
01342                         {
01343 #if !LL_WINDOWS && !LL_DARWIN
01344                                 size_t len = strnlen(home_location, MAX_STRING);
01345 #else
01346                                 size_t len = strlen(home_location);
01347 #endif
01348                                 LLMemoryStream mstr((U8*)home_location, len);
01349                                 LLSD sd = LLSDSerialize::fromNotation(mstr, len);
01350                                 S32 region_x = sd["region_handle"][0].asInteger();
01351                                 S32 region_y = sd["region_handle"][1].asInteger();
01352                                 U64 region_handle = to_region_handle(region_x, region_y);
01353                                 LLVector3 position = ll_vector3_from_sd(sd["position"]);
01354                                 gAgent.setHomePosRegion(region_handle, position);
01355                         }
01356 
01357                         gAgent.mMOTD.assign(LLUserAuth::getInstance()->getResponse("message"));
01358                         LLUserAuth::options_t options;
01359                         if(LLUserAuth::getInstance()->getOptions("inventory-root", options))
01360                         {
01361                                 LLUserAuth::response_t::iterator it;
01362                                 it = options[0].find("folder_id");
01363                                 if(it != options[0].end())
01364                                 {
01365                                         gAgent.mInventoryRootID.set((*it).second.c_str());
01366                                         //gInventory.mock(gAgent.getInventoryRootID());
01367                                 }
01368                         }
01369 
01370                         options.clear();
01371                         if(LLUserAuth::getInstance()->getOptions("login-flags", options))
01372                         {
01373                                 LLUserAuth::response_t::iterator it;
01374                                 LLUserAuth::response_t::iterator no_flag = options[0].end();
01375                                 it = options[0].find("ever_logged_in");
01376                                 if(it != no_flag)
01377                                 {
01378                                         if((*it).second == "N") gAgent.setFirstLogin(TRUE);
01379                                         else gAgent.setFirstLogin(FALSE);
01380                                 }
01381                                 it = options[0].find("stipend_since_login");
01382                                 if(it != no_flag)
01383                                 {
01384                                         if((*it).second == "Y") stipend_since_login = TRUE;
01385                                 }
01386                                 it = options[0].find("gendered");
01387                                 if(it != no_flag)
01388                                 {
01389                                         if((*it).second == "Y") gAgent.setGenderChosen(TRUE);
01390                                 }
01391                                 it = options[0].find("daylight_savings");
01392                                 if(it != no_flag)
01393                                 {
01394                                         if((*it).second == "Y")  gPacificDaylightTime = TRUE;
01395                                         else gPacificDaylightTime = FALSE;
01396                                 }
01397                         }
01398                         options.clear();
01399                         if (LLUserAuth::getInstance()->getOptions("initial-outfit", options)
01400                                 && !options.empty())
01401                         {
01402                                 LLUserAuth::response_t::iterator it;
01403                                 LLUserAuth::response_t::iterator it_end = options[0].end();
01404                                 it = options[0].find("folder_name");
01405                                 if(it != it_end)
01406                                 {
01407                                         gInitialOutfit = (*it).second;
01408                                 }
01409                                 it = options[0].find("gender");
01410                                 if (it != it_end)
01411                                 {
01412                                         gInitialOutfitGender = (*it).second;
01413                                 }
01414                         }
01415 
01416                         options.clear();
01417                         if(LLUserAuth::getInstance()->getOptions("global-textures", options))
01418                         {
01419                                 // Extract sun and moon texture IDs.  These are used
01420                                 // in the LLVOSky constructor, but I can't figure out
01421                                 // how to pass them in.  JC
01422                                 LLUserAuth::response_t::iterator it;
01423                                 LLUserAuth::response_t::iterator no_texture = options[0].end();
01424                                 it = options[0].find("sun_texture_id");
01425                                 if(it != no_texture)
01426                                 {
01427                                         gSunTextureID.set((*it).second.c_str());
01428                                 }
01429                                 it = options[0].find("moon_texture_id");
01430                                 if(it != no_texture)
01431                                 {
01432                                         gMoonTextureID.set((*it).second.c_str());
01433                                 }
01434                                 it = options[0].find("cloud_texture_id");
01435                                 if(it != no_texture)
01436                                 {
01437                                         gCloudTextureID.set((*it).second.c_str());
01438                                 }
01439                         }
01440 
01441 
01442                         // JC: gesture loading done below, when we have an asset system
01443                         // in place.  Don't delete/clear user_credentials until then.
01444 
01445                         if(gAgentID.notNull()
01446                            && gAgentSessionID.notNull()
01447                            && gMessageSystem->mOurCircuitCode
01448                            && first_sim.isOk()
01449                            && gAgent.mInventoryRootID.notNull())
01450                         {
01451                                 LLStartUp::setStartupState( STATE_WORLD_INIT );
01452                         }
01453                         else
01454                         {
01455                                 if (gNoRender)
01456                                 {
01457                                         LL_WARNS("AppInit") << "Bad login - missing return values" << LL_ENDL;
01458                                         LL_WARNS("AppInit") << emsg << LL_ENDL;
01459                                         exit(0);
01460                                 }
01461                                 // Bounce back to the login screen.
01462                                 LLStringBase<char>::format_map_t args;
01463                                 args["[ERROR_MESSAGE]"] = emsg.str();
01464                                 gViewerWindow->alertXml("ErrorMessage", args, login_alert_done);
01465                                 reset_login();
01466                                 gSavedSettings.setBOOL("AutoLogin", FALSE);
01467                                 show_connect_box = TRUE;
01468                         }
01469                         
01470                         // Pass the user information to the voice chat server interface.
01471                         gVoiceClient->userAuthorized(firstname, lastname, gAgentID);
01472                 }
01473                 else
01474                 {
01475                         if (gNoRender)
01476                         {
01477                                 LL_WARNS("AppInit") << "Failed to login!" << LL_ENDL;
01478                                 LL_WARNS("AppInit") << emsg << LL_ENDL;
01479                                 exit(0);
01480                         }
01481                         // Bounce back to the login screen.
01482                         LLStringBase<char>::format_map_t args;
01483                         args["[ERROR_MESSAGE]"] = emsg.str();
01484                         gViewerWindow->alertXml("ErrorMessage", args, login_alert_done);
01485                         reset_login();
01486                         gSavedSettings.setBOOL("AutoLogin", FALSE);
01487                         show_connect_box = TRUE;
01488                         // Don't save an incorrect password to disk.
01489                         save_password_to_disk(NULL);
01490                 }
01491                 return do_normal_idle;
01492         }
01493 
01494         //---------------------------------------------------------------------
01495         // World Init
01496         //---------------------------------------------------------------------
01497         if (STATE_WORLD_INIT == LLStartUp::getStartupState())
01498         {
01499                 set_startup_status(0.40f, LLTrans::getString("LoginInitializingWorld").c_str(), gAgent.mMOTD.c_str());
01500                 display_startup();
01501                 // We should have an agent id by this point.
01502                 llassert(!(gAgentID == LLUUID::null));
01503 
01504                 // Finish agent initialization.  (Requires gSavedSettings, builds camera)
01505                 gAgent.init();
01506                 set_underclothes_menu_options();
01507 
01508                 // Since we connected, save off the settings so the user doesn't have to
01509                 // type the name/password again if we crash.
01510                 gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
01511 
01512                 //
01513                 // Initialize classes w/graphics stuff.
01514                 //
01515                 gImageList.doPrefetchImages();          
01516                 LLSurface::initClasses();
01517 
01518                 LLFace::initClass();
01519 
01520                 LLDrawable::initClass();
01521 
01522                 // init the shader managers
01523                 LLPostProcess::initClass();
01524                 LLWLParamManager::initClass();
01525                 LLWaterParamManager::initClass();
01526 
01527                 // RN: don't initialize VO classes in drone mode, they are too closely tied to rendering
01528                 LLViewerObject::initVOClasses();
01529 
01530                 display_startup();
01531 
01532                 // This is where we used to initialize gWorldp. Original comment said:
01533                 // World initialization must be done after above window init
01534 
01535                 // User might have overridden far clip
01536                 LLWorld::getInstance()->setLandFarClip( gAgent.mDrawDistance );
01537 
01538                 // Before we create the first region, we need to set the agent's mOriginGlobal
01539                 // This is necessary because creating objects before this is set will result in a
01540                 // bad mPositionAgent cache.
01541 
01542                 gAgent.initOriginGlobal(from_region_handle(first_sim_handle));
01543 
01544                 LLWorld::getInstance()->addRegion(first_sim_handle, first_sim);
01545 
01546                 LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromHandle(first_sim_handle);
01547                 LL_INFOS("AppInit") << "Adding initial simulator " << regionp->getOriginGlobal() << LL_ENDL;
01548                 
01549                 LLStartUp::setStartupState( STATE_SEED_GRANTED_WAIT );
01550                 regionp->setSeedCapability(first_sim_seed_cap);
01551                 LL_DEBUGS("AppInit") << "Waiting for seed grant ...." << LL_ENDL;
01552                 
01553                 // Set agent's initial region to be the one we just created.
01554                 gAgent.setRegion(regionp);
01555 
01556                 // Set agent's initial position, which will be read by LLVOAvatar when the avatar
01557                 // object is created.  I think this must be done after setting the region.  JC
01558                 gAgent.setPositionAgent(agent_start_position_region);
01559 
01560                 display_startup();
01561                 return do_normal_idle;
01562         }
01563 
01564 
01565         //---------------------------------------------------------------------
01566         // Wait for Seed Cap Grant
01567         //---------------------------------------------------------------------
01568         if(STATE_SEED_GRANTED_WAIT == LLStartUp::getStartupState())
01569         {
01570                 return do_normal_idle;
01571         }
01572 
01573 
01574         //---------------------------------------------------------------------
01575         // Seed Capability Granted
01576         // no newMessage calls should happen before this point
01577         //---------------------------------------------------------------------
01578         if (STATE_SEED_CAP_GRANTED == LLStartUp::getStartupState())
01579         {
01580                 update_texture_fetch();
01581 
01582                 if ( gViewerWindow != NULL)
01583                 {       // This isn't the first logon attempt, so show the UI
01584                         gViewerWindow->setNormalControlsVisible( TRUE );
01585                 }       
01586                 gLoginMenuBarView->setVisible( FALSE );
01587                 gLoginMenuBarView->setEnabled( FALSE );
01588 
01589                 gFloaterMap->setVisible( gSavedSettings.getBOOL("ShowMiniMap") );
01590 
01591                 if (gSavedSettings.getBOOL("ShowCameraControls"))
01592                 {
01593                         LLFloaterCamera::showInstance();
01594                 }
01595                 if (gSavedSettings.getBOOL("ShowMovementControls"))
01596                 {
01597                         LLFloaterMove::showInstance();
01598                 }
01599 
01600                 if (gSavedSettings.getBOOL("ShowActiveSpeakers"))
01601                 {
01602                         LLFloaterActiveSpeakers::showInstance();
01603                 }
01604 
01605                 if (!gNoRender)
01606                 {
01607                         // Move the progress view in front of the UI
01608                         gViewerWindow->moveProgressViewToFront();
01609 
01610                         LLError::logToFixedBuffer(gDebugView->mDebugConsolep);
01611                         // set initial visibility of debug console
01612                         gDebugView->mDebugConsolep->setVisible(gSavedSettings.getBOOL("ShowDebugConsole"));
01613                         gDebugView->mFloaterStatsp->setVisible(gSavedSettings.getBOOL("ShowDebugStats"));
01614                 }
01615 
01616                 //
01617                 // Set message handlers
01618                 //
01619                 LL_INFOS("AppInit") << "Initializing communications..." << LL_ENDL;
01620 
01621                 // register callbacks for messages. . . do this after initial handshake to make sure that we don't catch any unwanted
01622                 register_viewer_callbacks(gMessageSystem);
01623 
01624                 // Debugging info parameters
01625                 gMessageSystem->setMaxMessageTime( 0.5f );                      // Spam if decoding all msgs takes more than 500 ms
01626 
01627                 #ifndef LL_RELEASE_FOR_DOWNLOAD
01628                         gMessageSystem->setTimeDecodes( TRUE );                         // Time the decode of each msg
01629                         gMessageSystem->setTimeDecodesSpamThreshold( 0.05f );  // Spam if a single msg takes over 50ms to decode
01630                 #endif
01631 
01632                 gXferManager->registerCallbacks(gMessageSystem);
01633 
01634                 if ( gCacheName == NULL )
01635                 {
01636                         gCacheName = new LLCacheName(gMessageSystem);
01637                         gCacheName->addObserver(callback_cache_name);
01638         
01639                         // Load stored cache if possible
01640             LLAppViewer::instance()->loadNameCache();
01641                 }
01642 
01643                 // *Note: this is where gWorldMap used to be initialized.
01644 
01645                 // register null callbacks for audio until the audio system is initialized
01646                 gMessageSystem->setHandlerFuncFast(_PREHASH_SoundTrigger, null_message_callback, NULL);
01647                 gMessageSystem->setHandlerFuncFast(_PREHASH_AttachedSound, null_message_callback, NULL);
01648 
01649                 //reset statistics
01650                 LLViewerStats::getInstance()->resetStats();
01651 
01652                 if (!gNoRender)
01653                 {
01654                         //
01655                         // Set up all of our statistics UI stuff.
01656                         //
01657                         init_stat_view();
01658                 }
01659 
01660                 display_startup();
01661                 //
01662                 // Set up region and surface defaults
01663                 //
01664 
01665 
01666                 // Sets up the parameters for the first simulator
01667 
01668                 LL_DEBUGS("AppInit") << "Initializing camera..." << LL_ENDL;
01669                 gFrameTime    = totalTime();
01670                 F32 last_time = gFrameTimeSeconds;
01671                 gFrameTimeSeconds = (S64)(gFrameTime - gStartTime)/SEC_TO_MICROSEC;
01672 
01673                 gFrameIntervalSeconds = gFrameTimeSeconds - last_time;
01674                 if (gFrameIntervalSeconds < 0.f)
01675                 {
01676                         gFrameIntervalSeconds = 0.f;
01677                 }
01678 
01679                 // Make sure agent knows correct aspect ratio
01680                 LLViewerCamera::getInstance()->setViewHeightInPixels(gViewerWindow->getWindowDisplayHeight());
01681                 if (gViewerWindow->mWindow->getFullscreen())
01682                 {
01683                         LLViewerCamera::getInstance()->setAspect(gViewerWindow->getDisplayAspectRatio());
01684                 }
01685                 else
01686                 {
01687                         LLViewerCamera::getInstance()->setAspect( (F32) gViewerWindow->getWindowWidth() / (F32) gViewerWindow->getWindowHeight());
01688                 }
01689 
01690                 // Move agent to starting location. The position handed to us by
01691                 // the space server is in global coordinates, but the agent frame
01692                 // is in region local coordinates. Therefore, we need to adjust
01693                 // the coordinates handed to us to fit in the local region.
01694 
01695                 gAgent.setPositionAgent(agent_start_position_region);
01696                 gAgent.resetAxes(agent_start_look_at);
01697                 gAgent.stopCameraAnimation();
01698                 gAgent.resetCamera();
01699 
01700                 // Initialize global class data needed for surfaces (i.e. textures)
01701                 if (!gNoRender)
01702                 {
01703                         LL_DEBUGS("AppInit") << "Initializing sky..." << LL_ENDL;
01704                         // Initialize all of the viewer object classes for the first time (doing things like texture fetches.
01705                         gSky.init(initial_sun_direction);
01706                 }
01707 
01708                 LL_DEBUGS("AppInit") << "Decoding images..." << LL_ENDL;
01709                 // For all images pre-loaded into viewer cache, decode them.
01710                 // Need to do this AFTER we init the sky
01711                 const S32 DECODE_TIME_SEC = 2;
01712                 for (int i = 0; i < DECODE_TIME_SEC; i++)
01713                 {
01714                         F32 frac = (F32)i / (F32)DECODE_TIME_SEC;
01715                         set_startup_status(0.45f + frac*0.1f, LLTrans::getString("LoginDecodingImages").c_str(), gAgent.mMOTD.c_str());
01716                         display_startup();
01717                         gImageList.decodeAllImages(1.f);
01718                 }
01719                 LLStartUp::setStartupState( STATE_WORLD_WAIT );
01720 
01721                 // JC - Do this as late as possible to increase likelihood Purify
01722                 // will run.
01723                 LLMessageSystem* msg = gMessageSystem;
01724                 if (!msg->mOurCircuitCode)
01725                 {
01726                         LL_WARNS("AppInit") << "Attempting to connect to simulator with a zero circuit code!" << LL_ENDL;
01727                 }
01728 
01729                 gUseCircuitCallbackCalled = FALSE;
01730 
01731                 msg->enableCircuit(first_sim, TRUE);
01732                 // now, use the circuit info to tell simulator about us!
01733                 LL_INFOS("AppInit") << "viewer: UserLoginLocationReply() Enabling " << first_sim << " with code " << msg->mOurCircuitCode << LL_ENDL;
01734                 msg->newMessageFast(_PREHASH_UseCircuitCode);
01735                 msg->nextBlockFast(_PREHASH_CircuitCode);
01736                 msg->addU32Fast(_PREHASH_Code, msg->mOurCircuitCode);
01737                 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
01738                 msg->addUUIDFast(_PREHASH_ID, gAgent.getID());
01739                 msg->sendReliable(
01740                         first_sim,
01741                         MAX_TIMEOUT_COUNT,
01742                         FALSE,
01743                         TIMEOUT_SECONDS,
01744                         use_circuit_callback,
01745                         NULL);
01746 
01747                 timeout.reset();
01748 
01749                 return do_normal_idle;
01750         }
01751 
01752         //---------------------------------------------------------------------
01753 
01754 
01755         // Agent Send
01756         //---------------------------------------------------------------------
01757         if(STATE_WORLD_WAIT == LLStartUp::getStartupState())
01758         {
01759                 LL_DEBUGS("AppInit") << "Waiting for simulator ack...." << LL_ENDL;
01760                 set_startup_status(0.59f, LLTrans::getString("LoginWaitingForRegionHandshake").c_str(), gAgent.mMOTD.c_str());
01761                 if(gGotUseCircuitCodeAck)
01762                 {
01763                         LLStartUp::setStartupState( STATE_AGENT_SEND );
01764                 }
01765                 LLMessageSystem* msg = gMessageSystem;
01766                 while (msg->checkAllMessages(gFrameCount, gServicePump))
01767                 {
01768                 }
01769                 msg->processAcks();
01770                 return do_normal_idle;
01771         }
01772 
01773         //---------------------------------------------------------------------
01774         // Agent Send
01775         //---------------------------------------------------------------------
01776         if (STATE_AGENT_SEND == LLStartUp::getStartupState())
01777         {
01778                 LL_DEBUGS("AppInit") << "Connecting to region..." << LL_ENDL;
01779                 set_startup_status(0.60f, LLTrans::getString("LoginConnectingToRegion").c_str(), gAgent.mMOTD.c_str());
01780                 // register with the message system so it knows we're
01781                 // expecting this message
01782                 LLMessageSystem* msg = gMessageSystem;
01783                 msg->setHandlerFuncFast(
01784                         _PREHASH_AgentMovementComplete,
01785                         process_agent_movement_complete);
01786                 LLViewerRegion* regionp = gAgent.getRegion();
01787                 if(regionp)
01788                 {
01789                         send_complete_agent_movement(regionp->getHost());
01790                         gAssetStorage->setUpstream(regionp->getHost());
01791                         gCacheName->setUpstream(regionp->getHost());
01792                         msg->newMessageFast(_PREHASH_EconomyDataRequest);
01793                         gAgent.sendReliableMessage();
01794                 }
01795 
01796                 // Create login effect
01797                 // But not on first login, because you can't see your avatar then
01798                 if (!gAgent.isFirstLogin())
01799                 {
01800                         LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
01801                         effectp->setPositionGlobal(gAgent.getPositionGlobal());
01802                         effectp->setColor(LLColor4U(gAgent.getEffectColor()));
01803                         LLHUDManager::getInstance()->sendEffects();
01804                 }
01805 
01806                 LLStartUp::setStartupState( STATE_AGENT_WAIT );         // Go to STATE_AGENT_WAIT
01807 
01808                 timeout.reset();
01809                 return do_normal_idle;
01810         }
01811 
01812         //---------------------------------------------------------------------
01813         // Agent Wait
01814         //---------------------------------------------------------------------
01815         if (STATE_AGENT_WAIT == LLStartUp::getStartupState())
01816         {
01817                 LLMessageSystem* msg = gMessageSystem;
01818                 while (msg->checkAllMessages(gFrameCount, gServicePump))
01819                 {
01820                         if (gAgentMovementCompleted)
01821                         {
01822                                 // Sometimes we have more than one message in the
01823                                 // queue. break out of this loop and continue
01824                                 // processing. If we don't, then this could skip one
01825                                 // or more login steps.
01826                                 break;
01827                         }
01828                         else
01829                         {
01830                                 LL_DEBUGS("AppInit") << "Awaiting AvatarInitComplete, got "
01831                                 << msg->getMessageName() << LL_ENDL;
01832                         }
01833                 }
01834                 msg->processAcks();
01835 
01836                 if (gAgentMovementCompleted)
01837                 {
01838                         LLStartUp::setStartupState( STATE_INVENTORY_SEND );
01839                 }
01840 
01841                 return do_normal_idle;
01842         }
01843 
01844         //---------------------------------------------------------------------
01845         // Inventory Send
01846         //---------------------------------------------------------------------
01847         if (STATE_INVENTORY_SEND == LLStartUp::getStartupState())
01848         {
01849                 // unpack thin inventory
01850                 LLUserAuth::options_t options;
01851                 options.clear();
01852                 //bool dump_buffer = false;
01853                 
01854                 if(LLUserAuth::getInstance()->getOptions("inventory-lib-root", options)
01855                         && !options.empty())
01856                 {
01857                         // should only be one
01858                         LLUserAuth::response_t::iterator it;
01859                         it = options[0].find("folder_id");
01860                         if(it != options[0].end())
01861                         {
01862                                 gInventoryLibraryRoot.set((*it).second.c_str());
01863                         }
01864                 }
01865                 options.clear();
01866                 if(LLUserAuth::getInstance()->getOptions("inventory-lib-owner", options)
01867                         && !options.empty())
01868                 {
01869                         // should only be one
01870                         LLUserAuth::response_t::iterator it;
01871                         it = options[0].find("agent_id");
01872                         if(it != options[0].end())
01873                         {
01874                                 gInventoryLibraryOwner.set((*it).second.c_str());
01875                         }
01876                 }
01877                 options.clear();
01878                 if(LLUserAuth::getInstance()->getOptions("inventory-skel-lib", options)
01879                         && gInventoryLibraryOwner.notNull())
01880                 {
01881                         if(!gInventory.loadSkeleton(options, gInventoryLibraryOwner))
01882                         {
01883                                 LL_WARNS("AppInit") << "Problem loading inventory-skel-lib" << LL_ENDL;
01884                         }
01885                 }
01886                 options.clear();
01887                 if(LLUserAuth::getInstance()->getOptions("inventory-skeleton", options))
01888                 {
01889                         if(!gInventory.loadSkeleton(options, gAgent.getID()))
01890                         {
01891                                 LL_WARNS("AppInit") << "Problem loading inventory-skel-targets" << LL_ENDL;
01892                         }
01893                 }
01894 
01895                 options.clear();
01896                 if(LLUserAuth::getInstance()->getOptions("buddy-list", options))
01897                 {
01898                         LLUserAuth::options_t::iterator it = options.begin();
01899                         LLUserAuth::options_t::iterator end = options.end();
01900                         LLAvatarTracker::buddy_map_t list;
01901                         LLUUID agent_id;
01902                         S32 has_rights = 0, given_rights = 0;
01903                         for (; it != end; ++it)
01904                         {
01905                                 LLUserAuth::response_t::const_iterator option_it;
01906                                 option_it = (*it).find("buddy_id");
01907                                 if(option_it != (*it).end())
01908                                 {
01909                                         agent_id.set((*option_it).second.c_str());
01910                                 }
01911                                 option_it = (*it).find("buddy_rights_has");
01912                                 if(option_it != (*it).end())
01913                                 {
01914                                         has_rights = atoi((*option_it).second.c_str());
01915                                 }
01916                                 option_it = (*it).find("buddy_rights_given");
01917                                 if(option_it != (*it).end())
01918                                 {
01919                                         given_rights = atoi((*option_it).second.c_str());
01920                                 }
01921                                 list[agent_id] = new LLRelationship(given_rights, has_rights, false);
01922                         }
01923                         LLAvatarTracker::instance().addBuddyList(list);
01924                 }
01925 
01926                 options.clear();
01927                 if(LLUserAuth::getInstance()->getOptions("ui-config", options))
01928                 {
01929                         LLUserAuth::options_t::iterator it = options.begin();
01930                         LLUserAuth::options_t::iterator end = options.end();
01931                         for (; it != end; ++it)
01932                         {
01933                                 LLUserAuth::response_t::const_iterator option_it;
01934                                 option_it = (*it).find("allow_first_life");
01935                                 if(option_it != (*it).end())
01936                                 {
01937                                         if (option_it->second == "Y")
01938                                         {
01939                                                 LLPanelAvatar::sAllowFirstLife = TRUE;
01940                                         }
01941                                 }
01942                         }
01943                 }
01944                 options.clear();
01945                 if(LLUserAuth::getInstance()->getOptions("tutorial_setting", options))
01946                 {
01947                         LLUserAuth::options_t::iterator it = options.begin();
01948                         LLUserAuth::options_t::iterator end = options.end();
01949                         for (; it != end; ++it)
01950                         {
01951                                 LLUserAuth::response_t::const_iterator option_it;
01952                                 option_it = (*it).find("tutorial_url");
01953                                 if(option_it != (*it).end())
01954                                 {
01955                                         LLFloaterHUD::sTutorialUrl = option_it->second;
01956                                 }
01957                                 option_it = (*it).find("use_tutorial");
01958                                 if(option_it != (*it).end())
01959                                 {
01960                                         if (option_it->second == "true")
01961                                         {
01962                                                 LLFloaterHUD::show();
01963                                         }
01964                                 }
01965                         }
01966                 }
01967 
01968                 options.clear();
01969                 if(LLUserAuth::getInstance()->getOptions("event_categories", options))
01970                 {
01971                         LLEventInfo::loadCategories(options);
01972                 }
01973                 if(LLUserAuth::getInstance()->getOptions("event_notifications", options))
01974                 {
01975                         gEventNotifier.load(options);
01976                 }
01977                 options.clear();
01978                 if(LLUserAuth::getInstance()->getOptions("classified_categories", options))
01979                 {
01980                         LLClassifiedInfo::loadCategories(options);
01981                 }
01982                 gInventory.buildParentChildMap();
01983                 gInventory.addChangedMask(LLInventoryObserver::ALL, LLUUID::null);
01984                 gInventory.notifyObservers();
01985 
01986                 // set up callbacks
01987                 LLMessageSystem* msg = gMessageSystem;
01988                 LLInventoryModel::registerCallbacks(msg);
01989                 LLAvatarTracker::instance().registerCallbacks(msg);
01990                 LLLandmark::registerCallbacks(msg);
01991 
01992                 // request mute list
01993                 LLMuteList::getInstance()->requestFromServer(gAgent.getID());
01994 
01995                 // Get L$ and ownership credit information
01996                 msg->newMessageFast(_PREHASH_MoneyBalanceRequest);
01997                 msg->nextBlockFast(_PREHASH_AgentData);
01998                 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
01999                 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
02000                 msg->nextBlockFast(_PREHASH_MoneyData);
02001                 msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null );
02002                 gAgent.sendReliableMessage();
02003 
02004                 // request all group information
02005                 gAgent.sendAgentDataUpdateRequest();
02006 
02007                 BOOL shown_at_exit = gSavedSettings.getBOOL("ShowInventory");
02008 
02009                 // Create the inventory views
02010                 LLInventoryView::showAgentInventory();
02011 
02012                 // Hide the inventory if it wasn't shown at exit
02013                 if(!shown_at_exit)
02014                 {
02015                         LLInventoryView::toggleVisibility(NULL);
02016                 }
02017 
02018                 LLStartUp::setStartupState( STATE_MISC );
02019                 return do_normal_idle;
02020         }
02021 
02022 
02023         //---------------------------------------------------------------------
02024         // Misc
02025         //---------------------------------------------------------------------
02026         if (STATE_MISC == LLStartUp::getStartupState())
02027         {
02028                 // We have a region, and just did a big inventory download.
02029                 // We can estimate the user's connection speed, and set their
02030                 // max bandwidth accordingly.  JC
02031                 if (gSavedSettings.getBOOL("FirstLoginThisInstall"))
02032                 {
02033                         // This is actually a pessimistic computation, because TCP may not have enough
02034                         // time to ramp up on the (small) default inventory file to truly measure max
02035                         // bandwidth. JC
02036                         F64 rate_bps = LLUserAuth::getInstance()->getLastTransferRateBPS();
02037                         const F32 FAST_RATE_BPS = 600.f * 1024.f;
02038                         const F32 FASTER_RATE_BPS = 750.f * 1024.f;
02039                         F32 max_bandwidth = gViewerThrottle.getMaxBandwidth();
02040                         if (rate_bps > FASTER_RATE_BPS
02041                                 && rate_bps > max_bandwidth)
02042                         {
02043                                 LL_DEBUGS("AppInit") << "Fast network connection, increasing max bandwidth to " 
02044                                         << FASTER_RATE_BPS/1024.f 
02045                                         << " kbps" << LL_ENDL;
02046                                 gViewerThrottle.setMaxBandwidth(FASTER_RATE_BPS / 1024.f);
02047                         }
02048                         else if (rate_bps > FAST_RATE_BPS
02049                                 && rate_bps > max_bandwidth)
02050                         {
02051                                 LL_DEBUGS("AppInit") << "Fast network connection, increasing max bandwidth to " 
02052                                         << FAST_RATE_BPS/1024.f 
02053                                         << " kbps" << LL_ENDL;
02054                                 gViewerThrottle.setMaxBandwidth(FAST_RATE_BPS / 1024.f);
02055                         }
02056                 }
02057 
02058                 // We're successfully logged in.
02059                 gSavedSettings.setBOOL("FirstLoginThisInstall", FALSE);
02060 
02061 
02062                 // based on the comments, we've successfully logged in so we can delete the 'forced'
02063                 // URL that the updater set in settings.ini (in a mostly paranoid fashion)
02064                 LLString nextLoginLocation = gSavedSettings.getString( "NextLoginLocation" );
02065                 if ( nextLoginLocation.length() )
02066                 {
02067                         // clear it
02068                         gSavedSettings.setString( "NextLoginLocation", "" );
02069 
02070                         // and make sure it's saved
02071                         gSavedSettings.saveToFile( gSavedSettings.getString("ClientSettingsFile") , TRUE );
02072                 };
02073 
02074                 if (!gNoRender)
02075                 {
02076                         // JC: Initializing audio requests many sounds for download.
02077                         init_audio();
02078 
02079                         // JC: Initialize "active" gestures.  This may also trigger
02080                         // many gesture downloads, if this is the user's first
02081                         // time on this machine or -purge has been run.
02082                         LLUserAuth::options_t gesture_options;
02083                         if (LLUserAuth::getInstance()->getOptions("gestures", gesture_options))
02084                         {
02085                                 LL_DEBUGS("AppInit") << "Gesture Manager loading " << gesture_options.size()
02086                                         << LL_ENDL;
02087                                 std::vector<LLUUID> item_ids;
02088                                 LLUserAuth::options_t::iterator resp_it;
02089                                 for (resp_it = gesture_options.begin();
02090                                          resp_it != gesture_options.end();
02091                                          ++resp_it)
02092                                 {
02093                                         const LLUserAuth::response_t& response = *resp_it;
02094                                         LLUUID item_id;
02095                                         LLUUID asset_id;
02096                                         LLUserAuth::response_t::const_iterator option_it;
02097 
02098                                         option_it = response.find("item_id");
02099                                         if (option_it != response.end())
02100                                         {
02101                                                 const std::string& uuid_string = (*option_it).second;
02102                                                 item_id.set(uuid_string.c_str());
02103                                         }
02104                                         option_it = response.find("asset_id");
02105                                         if (option_it != response.end())
02106                                         {
02107                                                 const std::string& uuid_string = (*option_it).second;
02108                                                 asset_id.set(uuid_string.c_str());
02109                                         }
02110 
02111                                         if (item_id.notNull() && asset_id.notNull())
02112                                         {
02113                                                 // Could schedule and delay these for later.
02114                                                 const BOOL no_inform_server = FALSE;
02115                                                 const BOOL no_deactivate_similar = FALSE;
02116                                                 gGestureManager.activateGestureWithAsset(item_id, asset_id,
02117                                                                                                                                  no_inform_server,
02118                                                                                                                                  no_deactivate_similar);
02119                                                 // We need to fetch the inventory items for these gestures
02120                                                 // so we have the names to populate the UI.
02121                                                 item_ids.push_back(item_id);
02122                                         }
02123                                 }
02124 
02125                                 LLGestureInventoryFetchObserver* fetch = new LLGestureInventoryFetchObserver();
02126                                 fetch->fetchItems(item_ids);
02127                                 // deletes itself when done
02128                                 gInventory.addObserver(fetch);
02129                         }
02130                 }
02131                 gDisplaySwapBuffers = TRUE;
02132 
02133                 LLMessageSystem* msg = gMessageSystem;
02134                 msg->setHandlerFuncFast(_PREHASH_SoundTrigger,                          process_sound_trigger);
02135                 msg->setHandlerFuncFast(_PREHASH_PreloadSound,                          process_preload_sound);
02136                 msg->setHandlerFuncFast(_PREHASH_AttachedSound,                         process_attached_sound);
02137                 msg->setHandlerFuncFast(_PREHASH_AttachedSoundGainChange,       process_attached_sound_gain_change);
02138 
02139                 LL_DEBUGS("AppInit") << "Initialization complete" << LL_ENDL;
02140 
02141                 gRenderStartTime.reset();
02142                 gForegroundTime.reset();
02143 
02144                 // HACK: Inform simulator of window size.
02145                 // Do this here so it's less likely to race with RegisterNewAgent.
02146                 // TODO: Put this into RegisterNewAgent
02147                 // JC - 7/20/2002
02148                 gViewerWindow->sendShapeToSim();
02149 
02150                 // Ignore stipend information for now.  Money history is on the web site.
02151                 // if needed, show the L$ history window
02152                 //if (stipend_since_login && !gNoRender)
02153                 //{
02154                 //}
02155 
02156                 if (!gAgent.isFirstLogin())
02157                 {
02158                         bool url_ok = LLURLSimString::sInstance.parse();
02159                         if (!((agent_start_location == "url" && url_ok) ||
02160                   (!url_ok && ((agent_start_location == "last" && gSavedSettings.getBOOL("LoginLastLocation")) ||
02161                                                            (agent_start_location == "home" && !gSavedSettings.getBOOL("LoginLastLocation"))))))
02162                         {
02163                                 // The reason we show the alert is because we want to
02164                                 // reduce confusion for when you log in and your provided
02165                                 // location is not your expected location. So, if this is
02166                                 // your first login, then you do not have an expectation,
02167                                 // thus, do not show this alert.
02168                                 LLString::format_map_t args;
02169                                 if (url_ok)
02170                                 {
02171                                         args["[TYPE]"] = "desired";
02172                                         args["[HELP]"] = "";
02173                                 }
02174                                 else if (gSavedSettings.getBOOL("LoginLastLocation"))
02175                                 {
02176                                         args["[TYPE]"] = "last";
02177                                         args["[HELP]"] = "";
02178                                 }
02179                                 else
02180                                 {
02181                                         args["[TYPE]"] = "home";
02182                                         args["[HELP]"] = "You may want to set a new home location.";
02183                                 }
02184                                 gViewerWindow->alertXml("AvatarMoved", args);
02185                         }
02186                         else
02187                         {
02188                                 if (samename)
02189                                 {
02190                                         // restore old camera pos
02191                                         gAgent.setFocusOnAvatar(FALSE, FALSE);
02192                                         gAgent.setCameraPosAndFocusGlobal(gSavedSettings.getVector3d("CameraPosOnLogout"), gSavedSettings.getVector3d("FocusPosOnLogout"), LLUUID::null);
02193                                         BOOL limit_hit = FALSE;
02194                                         gAgent.calcCameraPositionTargetGlobal(&limit_hit);
02195                                         if (limit_hit)
02196                                         {
02197                                                 gAgent.setFocusOnAvatar(TRUE, FALSE);
02198                                         }
02199                                         gAgent.stopCameraAnimation();
02200                                 }
02201                         }
02202                 }
02203 
02204                 LLStartUp::setStartupState( STATE_PRECACHE );
02205                 timeout.reset();
02206                 return do_normal_idle;
02207         }
02208 
02209         if (STATE_PRECACHE == LLStartUp::getStartupState())
02210         {
02211                 do_normal_idle = TRUE;
02212                 
02213                 F32 timeout_frac = timeout.getElapsedTimeF32()/PRECACHING_DELAY;
02214                 // wait precache-delay and for agent's avatar or a lot longer.
02215                 if(((timeout_frac > 1.f) && gAgent.getAvatarObject())
02216                    || (timeout_frac > 3.f))
02217                 {
02218                         LLStartUp::setStartupState( STATE_WEARABLES_WAIT );
02219                 }
02220                 else
02221                 {
02222                         update_texture_fetch();
02223                         set_startup_status(0.60f + 0.40f * timeout_frac,
02224                                 "Loading world...",
02225                                         gAgent.mMOTD.c_str());
02226                 }
02227 
02228                 return do_normal_idle;
02229         }
02230 
02231         if (STATE_WEARABLES_WAIT == LLStartUp::getStartupState())
02232         {
02233                 do_normal_idle = TRUE;
02234 
02235                 static LLFrameTimer wearables_timer;
02236 
02237                 const F32 wearables_time = wearables_timer.getElapsedTimeF32();
02238                 const F32 MAX_WEARABLES_TIME = 10.f;
02239 
02240                 if(gAgent.getWearablesLoaded() || !gAgent.isGenderChosen())
02241                 {
02242                         LLStartUp::setStartupState( STATE_CLEANUP );
02243                 }
02244                 else if (wearables_time > MAX_WEARABLES_TIME)
02245                 {
02246                         gViewerWindow->alertXml("ClothingLoading");
02247                         LLViewerStats::getInstance()->incStat(LLViewerStats::ST_WEARABLES_TOO_LONG);
02248                         LLStartUp::setStartupState( STATE_CLEANUP );
02249                 }
02250                 else
02251                 {
02252                         update_texture_fetch();
02253                         set_startup_status(0.f + 0.25f * wearables_time / MAX_WEARABLES_TIME,
02254                                                          LLTrans::getString("LoginDownloadingClothing").c_str(),
02255                                                          gAgent.mMOTD.c_str());
02256                 }
02257                 return do_normal_idle;
02258         }
02259 
02260         if (STATE_CLEANUP == LLStartUp::getStartupState())
02261         {
02262                 set_startup_status(1.0, "", NULL);
02263 
02264                 do_normal_idle = TRUE;
02265 
02266                 // Let the map know about the inventory.
02267                 if(gFloaterWorldMap)
02268                 {
02269                         gFloaterWorldMap->observeInventory(&gInventory);
02270                         gFloaterWorldMap->observeFriends();
02271                 }
02272 
02273                 gViewerWindow->showCursor();
02274                 gViewerWindow->getWindow()->resetBusyCount();
02275                 gViewerWindow->getWindow()->setCursor(UI_CURSOR_ARROW);
02276                 LL_DEBUGS("AppInit") << "Done releasing bitmap" << LL_ENDL;
02277                 gViewerWindow->setShowProgress(FALSE);
02278                 gViewerWindow->setProgressCancelButtonVisible(FALSE, "");
02279 
02280                 // We're not away from keyboard, even though login might have taken
02281                 // a while. JC
02282                 gAgent.clearAFK();
02283 
02284                 // Have the agent start watching the friends list so we can update proxies
02285                 gAgent.observeFriends();
02286                 if (gSavedSettings.getBOOL("LoginAsGod"))
02287                 {
02288                         gAgent.requestEnterGodMode();
02289                 }
02290                 
02291                 // On first start, ask user for gender
02292                 dialog_choose_gender_first_start();
02293 
02294                 // Start automatic replay if the flag is set.
02295                 if (gSavedSettings.getBOOL("StatsAutoRun"))
02296                 {
02297                         LLUUID id;
02298                         LL_DEBUGS("AppInit") << "Starting automatic playback" << LL_ENDL;
02299                         gAgentPilot.startPlayback();
02300                 }
02301 
02302                 // If we've got a startup URL, dispatch it
02303                 LLStartUp::dispatchURL();
02304 
02305                 // Clean up the userauth stuff.
02306                 LLUserAuth::getInstance()->reset();
02307 
02308                 LLStartUp::setStartupState( STATE_STARTED );
02309 
02310                 // Unmute audio if desired and setup volumes.
02311                 // Unmute audio if desired and setup volumes.
02312                 // This is a not-uncommon crash site, so surround it with
02313                 // llinfos output to aid diagnosis.
02314                 LL_INFOS("AppInit") << "Doing first audio_update_volume..." << LL_ENDL;
02315                 audio_update_volume();
02316                 LL_INFOS("AppInit") << "Done first audio_update_volume." << LL_ENDL;
02317 
02318                 // reset keyboard focus to sane state of pointing at world
02319                 gFocusMgr.setKeyboardFocus(NULL);
02320 
02321 #if 0 // sjb: enable for auto-enabling timer display 
02322                 gDebugView->mFastTimerView->setVisible(TRUE);
02323 #endif
02324 
02325                 LLAppViewer::instance()->startMainloopTimeout();
02326 
02327                 return do_normal_idle;
02328         }
02329 
02330         LL_WARNS("AppInit") << "Reached end of idle_startup for state " << LLStartUp::getStartupState() << LL_ENDL;
02331         return do_normal_idle;
02332 }
02333 
02334 //
02335 // local function definition
02336 //
02337 
02338 void login_show()
02339 {
02340         LL_INFOS("AppInit") << "Initializing Login Screen" << LL_ENDL;
02341 
02342 #ifdef LL_RELEASE_FOR_DOWNLOAD
02343         BOOL bUseDebugLogin = gSavedSettings.getBOOL("UseDebugLogin");
02344 #else
02345         BOOL bUseDebugLogin = TRUE;
02346 #endif
02347 
02348         LLPanelLogin::show(     gViewerWindow->getVirtualWindowRect(),
02349                                                 bUseDebugLogin,
02350                                                 login_callback, NULL );
02351 
02352         // UI textures have been previously loaded in doPreloadImages()
02353         
02354         LL_DEBUGS("AppInit") << "Setting Servers" << LL_ENDL;
02355 
02356         if( GRID_INFO_OTHER == gGridChoice )
02357         {
02358                    LLPanelLogin::addServer( gGridName.c_str(), GRID_INFO_OTHER );
02359         }
02360         else
02361         {
02362                    LLPanelLogin::addServer( gGridInfo[gGridChoice].mLabel, gGridChoice );
02363         }
02364 
02365         // Arg!  We hate loops!
02366         LLPanelLogin::addServer( gGridInfo[GRID_INFO_ADITI].mLabel,        GRID_INFO_ADITI );
02367         LLPanelLogin::addServer( gGridInfo[GRID_INFO_AGNI].mLabel, GRID_INFO_AGNI );
02368         LLPanelLogin::addServer( gGridInfo[GRID_INFO_ARUNA].mLabel,        GRID_INFO_ARUNA );
02369         LLPanelLogin::addServer( gGridInfo[GRID_INFO_DURGA].mLabel,        GRID_INFO_DURGA );
02370         LLPanelLogin::addServer( gGridInfo[GRID_INFO_GANGA].mLabel,        GRID_INFO_GANGA );
02371         LLPanelLogin::addServer( gGridInfo[GRID_INFO_MITRA].mLabel,       GRID_INFO_MITRA );
02372         LLPanelLogin::addServer( gGridInfo[GRID_INFO_MOHINI].mLabel,       GRID_INFO_MOHINI );
02373         LLPanelLogin::addServer( gGridInfo[GRID_INFO_NANDI].mLabel,       GRID_INFO_NANDI );
02374         LLPanelLogin::addServer( gGridInfo[GRID_INFO_RADHA].mLabel,       GRID_INFO_RADHA );
02375         LLPanelLogin::addServer( gGridInfo[GRID_INFO_RAVI].mLabel,       GRID_INFO_RAVI );
02376         LLPanelLogin::addServer( gGridInfo[GRID_INFO_SIVA].mLabel, GRID_INFO_SIVA );
02377         LLPanelLogin::addServer( gGridInfo[GRID_INFO_SHAKTI].mLabel,       GRID_INFO_SHAKTI );
02378         LLPanelLogin::addServer( gGridInfo[GRID_INFO_SOMA].mLabel, GRID_INFO_SOMA );
02379         LLPanelLogin::addServer( gGridInfo[GRID_INFO_UMA].mLabel,  GRID_INFO_UMA );
02380         LLPanelLogin::addServer( gGridInfo[GRID_INFO_VAAK].mLabel, GRID_INFO_VAAK );
02381         LLPanelLogin::addServer( gGridInfo[GRID_INFO_YAMI].mLabel, GRID_INFO_YAMI );
02382         LLPanelLogin::addServer( gGridInfo[GRID_INFO_LOCAL].mLabel,        GRID_INFO_LOCAL );
02383 }
02384 
02385 // Callback for when login screen is closed.  Option 0 = connect, option 1 = quit.
02386 void login_callback(S32 option, void *userdata)
02387 {
02388         const S32 CONNECT_OPTION = 0;
02389         const S32 QUIT_OPTION = 1;
02390 
02391         if (CONNECT_OPTION == option)
02392         {
02393                 LLStartUp::setStartupState( STATE_LOGIN_CLEANUP );
02394                 return;
02395         }
02396         else if (QUIT_OPTION == option)
02397         {
02398                 // Make sure we don't save the password if the user is trying to clear it.
02399                 LLString first, last, password;
02400                 BOOL remember = TRUE;
02401                 LLPanelLogin::getFields(first, last, password, remember);
02402                 if (!remember)
02403                 {
02404                         // turn off the setting and write out to disk
02405                         gSavedSettings.setBOOL("RememberPassword", FALSE);
02406                         gSavedSettings.saveToFile( gSavedSettings.getString("ClientSettingsFile") , TRUE );
02407 
02408                         // stomp the saved password on disk
02409                         save_password_to_disk(NULL);
02410                 }
02411 
02412                 // Next iteration through main loop should shut down the app cleanly.
02413                 LLAppViewer::instance()->userQuit();
02414                 
02415                 if (LLAppViewer::instance()->quitRequested())
02416                 {
02417                         LLPanelLogin::close();
02418                 }
02419                 return;
02420         }
02421         else
02422         {
02423                 LL_WARNS("AppInit") << "Unknown login button clicked" << LL_ENDL;
02424         }
02425 }
02426 
02427 LLString load_password_from_disk()
02428 {
02429         LLString hashed_password("");
02430 
02431         // Look for legacy "marker" password from settings.ini
02432         hashed_password = gSavedSettings.getString("Marker");
02433         if (!hashed_password.empty())
02434         {
02435                 // Stomp the Marker entry.
02436                 gSavedSettings.setString("Marker", "");
02437 
02438                 // Return that password.
02439                 return hashed_password;
02440         }
02441 
02442         std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS,
02443                                                                                                            "password.dat");
02444         LLFILE* fp = LLFile::fopen(filepath.c_str(), "rb");             /* Flawfinder: ignore */
02445         if (!fp)
02446         {
02447                 return hashed_password;
02448         }
02449 
02450         // UUID is 16 bytes, written into ASCII is 32 characters
02451         // without trailing \0
02452         const S32 HASHED_LENGTH = 32;
02453         U8 buffer[HASHED_LENGTH+1];
02454 
02455         if (1 != fread(buffer, HASHED_LENGTH, 1, fp))
02456         {
02457                 return hashed_password;
02458         }
02459 
02460         fclose(fp);
02461 
02462         // Decipher with MAC address
02463         LLXORCipher cipher(gMACAddress, 6);
02464         cipher.decrypt(buffer, HASHED_LENGTH);
02465 
02466         buffer[HASHED_LENGTH] = '\0';
02467 
02468         // Check to see if the mac address generated a bad hashed
02469         // password. It should be a hex-string or else the mac adress has
02470         // changed. This is a security feature to make sure that if you
02471         // get someone's password.dat file, you cannot hack their account.
02472         if(is_hex_string(buffer, HASHED_LENGTH))
02473         {
02474                 hashed_password.assign((char*)buffer);
02475         }
02476 
02477         return hashed_password;
02478 }
02479 
02480 void save_password_to_disk(const char* hashed_password)
02481 {
02482         std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS,
02483                                                                                                            "password.dat");
02484         if (!hashed_password)
02485         {
02486                 // No password, remove the file.
02487                 LLFile::remove(filepath.c_str());
02488         }
02489         else
02490         {
02491                 LLFILE* fp = LLFile::fopen(filepath.c_str(), "wb");             /* Flawfinder: ignore */
02492                 if (!fp)
02493                 {
02494                         return;
02495                 }
02496 
02497                 // Encipher with MAC address
02498                 const S32 HASHED_LENGTH = 32;
02499                 U8 buffer[HASHED_LENGTH+1];
02500 
02501                 LLString::copy((char*)buffer, hashed_password, HASHED_LENGTH+1);
02502 
02503                 LLXORCipher cipher(gMACAddress, 6);
02504                 cipher.encrypt(buffer, HASHED_LENGTH);
02505 
02506                 if (fwrite(buffer, HASHED_LENGTH, 1, fp) != 1)
02507                 {
02508                         LL_WARNS("AppInit") << "Short write" << LL_ENDL;
02509                 }
02510 
02511                 fclose(fp);
02512         }
02513 }
02514 
02515 BOOL is_hex_string(U8* str, S32 len)
02516 {
02517         BOOL rv = TRUE;
02518         U8* c = str;
02519         while(rv && len--)
02520         {
02521                 switch(*c)
02522                 {
02523                 case '0':
02524                 case '1':
02525                 case '2':
02526                 case '3':
02527                 case '4':
02528                 case '5':
02529                 case '6':
02530                 case '7':
02531                 case '8':
02532                 case '9':
02533                 case 'a':
02534                 case 'b':
02535                 case 'c':
02536                 case 'd':
02537                 case 'e':
02538                 case 'f':
02539                         ++c;
02540                         break;
02541                 default:
02542                         rv = FALSE;
02543                         break;
02544                 }
02545         }
02546         return rv;
02547 }
02548 
02549 void show_first_run_dialog()
02550 {
02551         gViewerWindow->alertXml("FirstRun", first_run_dialog_callback, NULL);
02552 }
02553 
02554 void first_run_dialog_callback(S32 option, void* userdata)
02555 {
02556         if (0 == option)
02557         {
02558                 LL_DEBUGS("AppInit") << "First run dialog cancelling" << LL_ENDL;
02559                 LLWeb::loadURL( CREATE_ACCOUNT_URL );
02560         }
02561 
02562         LLPanelLogin::giveFocus();
02563 }
02564 
02565 
02566 
02567 void set_startup_status(const F32 frac, const char *string, const char* msg)
02568 {
02569         gViewerWindow->setProgressPercent(frac*100);
02570         gViewerWindow->setProgressString(string);
02571 
02572         gViewerWindow->setProgressMessage(msg);
02573 }
02574 
02575 void login_alert_status(S32 option, void* user_data)
02576 {
02577     // Buttons
02578     switch( option )
02579     {
02580         case 0:     // OK
02581             break;
02582         case 1:     // Help
02583             LLWeb::loadURL( SUPPORT_URL );
02584             break;
02585         case 2:     // Teleport
02586             // Restart the login process, starting at our home locaton
02587             LLURLSimString::setString(LLURLSimString::sLocationStringHome);
02588             LLStartUp::setStartupState( STATE_LOGIN_CLEANUP );
02589             break;
02590         default:
02591             LL_WARNS("AppInit") << "Missing case in login_alert_status switch" << LL_ENDL;
02592     }
02593 
02594         LLPanelLogin::giveFocus();
02595 }
02596 
02597 void update_app(BOOL mandatory, const std::string& auth_msg)
02598 {
02599         // store off config state, as we might quit soon
02600         gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);        
02601 
02602         std::ostringstream message;
02603 
02604         //*TODO:translate
02605         std::string msg;
02606         if (!auth_msg.empty())
02607         {
02608                 msg = "(" + auth_msg + ") \n";
02609         }
02610         LLStringBase<char>::format_map_t args;
02611         args["[MESSAGE]"] = msg;
02612         
02613         // represent a bool as a null/non-null pointer
02614         void *mandatoryp = mandatory ? &mandatory : NULL;
02615 
02616 #if LL_WINDOWS
02617         if (mandatory)
02618         {
02619                 gViewerWindow->alertXml("DownloadWindowsMandatory", args,
02620                                                                 update_dialog_callback,
02621                                                                 mandatoryp);
02622         }
02623         else
02624         {
02625 #if LL_RELEASE_FOR_DOWNLOAD
02626                 gViewerWindow->alertXml("DownloadWindowsReleaseForDownload", args,
02627                                                                 update_dialog_callback,
02628                                                                 mandatoryp);
02629 #else
02630                 gViewerWindow->alertXml("DownloadWindows", args,
02631                                                                 update_dialog_callback,
02632                                                                 mandatoryp);
02633 #endif
02634         }
02635 #else
02636         if (mandatory)
02637         {
02638                 gViewerWindow->alertXml("DownloadMacMandatory", args,
02639                                                                 update_dialog_callback,
02640                                                                 mandatoryp);
02641         }
02642         else
02643         {
02644 #if LL_RELEASE_FOR_DOWNLOAD
02645                 gViewerWindow->alertXml("DownloadMacReleaseForDownload", args,
02646                                                                 update_dialog_callback,
02647                                                                 mandatoryp);
02648 #else
02649                 gViewerWindow->alertXml("DownloadMac", args,
02650                                                                 update_dialog_callback,
02651                                                                 mandatoryp);
02652 #endif
02653         }
02654 #endif
02655 
02656 }
02657 
02658 
02659 void update_dialog_callback(S32 option, void *userdata)
02660 {
02661         std::string update_exe_path;
02662         BOOL mandatory = userdata != NULL;
02663 
02664 #if !LL_RELEASE_FOR_DOWNLOAD
02665         if (option == 2)
02666         {
02667                 LLStartUp::setStartupState( STATE_LOGIN_AUTH_INIT ); 
02668                 return;
02669         }
02670 #endif
02671         
02672         if (option == 1)
02673         {
02674                 // ...user doesn't want to do it
02675                 if (mandatory)
02676                 {
02677                         LLAppViewer::instance()->forceQuit();
02678                         // Bump them back to the login screen.
02679                         //reset_login();
02680                 }
02681                 else
02682                 {
02683                         LLStartUp::setStartupState( STATE_LOGIN_AUTH_INIT );
02684                 }
02685                 return;
02686         }
02687         
02688         LLSD query_map = LLSD::emptyMap();
02689         // *TODO place os string in a global constant
02690 #if LL_WINDOWS  
02691         query_map["os"] = "win";
02692 #elif LL_DARWIN
02693         query_map["os"] = "mac";
02694 #elif LL_LINUX
02695         query_map["os"] = "lnx";
02696 #endif
02697         // *TODO change userserver to be grid on both viewer and sim, since
02698         // userserver no longer exists.
02699         query_map["userserver"] = gGridName;
02700         query_map["channel"] = gSavedSettings.getString("VersionChannelName");
02701         // *TODO constantize this guy
02702         LLURI update_url = LLURI::buildHTTP("secondlife.com", 80, "update.php", query_map);
02703         
02704 #if LL_WINDOWS
02705         update_exe_path = gDirUtilp->getTempFilename();
02706         if (update_exe_path.empty())
02707         {
02708                 // We're hosed, bail
02709                 LL_WARNS("AppInit") << "LLDir::getTempFilename() failed" << LL_ENDL;
02710                 LLAppViewer::instance()->forceQuit();
02711                 return;
02712         }
02713 
02714         update_exe_path += ".exe";
02715 
02716         std::string updater_source = gDirUtilp->getAppRODataDir();
02717         updater_source += gDirUtilp->getDirDelimiter();
02718         updater_source += "updater.exe";
02719 
02720         LL_DEBUGS("AppInit") << "Calling CopyFile source: " << updater_source.c_str()
02721                         << " dest: " << update_exe_path
02722                         << LL_ENDL;
02723 
02724 
02725         if (!CopyFileA(updater_source.c_str(), update_exe_path.c_str(), FALSE))
02726         {
02727                 LL_WARNS("AppInit") << "Unable to copy the updater!" << LL_ENDL;
02728                 LLAppViewer::instance()->forceQuit();
02729                 return;
02730         }
02731 
02732         // if a sim name was passed in via command line parameter (typically through a SLURL)
02733         if ( LLURLSimString::sInstance.mSimString.length() )
02734         {
02735                 // record the location to start at next time
02736                 gSavedSettings.setString( "NextLoginLocation", LLURLSimString::sInstance.mSimString ); 
02737         };
02738 
02739         std::ostringstream params;
02740         params << "-url \"" << update_url.asString() << "\"";
02741         if (gHideLinks)
02742         {
02743                 // Figure out the program name.
02744                 const char* data_dir = gDirUtilp->getAppRODataDir().c_str();
02745                 // Roll back from the end, stopping at the first '\'
02746                 const char* program_name = data_dir + strlen(data_dir);         /* Flawfinder: ignore */
02747                 while ( (data_dir != --program_name) &&
02748                                 *(program_name) != '\\');
02749                 
02750                 if ( *(program_name) == '\\')
02751                 {
02752                         // We found a '\'.
02753                         program_name++;
02754                 }
02755                 else
02756                 {
02757                         // Oops.
02758                         program_name = "SecondLife";
02759                 }
02760 
02761                 params << " -silent -name \"" << LLAppViewer::instance()->getSecondLifeTitle() << "\"";
02762                 params << " -program \"" << program_name << "\"";
02763         }
02764 
02765         LL_DEBUGS("AppInit") << "Calling updater: " << update_exe_path << " " << params.str() << LL_ENDL;
02766 
02767         //Explicitly remove the marker file, otherwise we pass the lock onto the child process and things get weird.
02768         LLAppViewer::instance()->removeMarkerFile(); // In case updater fails
02769         
02770         // Use spawn() to run asynchronously
02771         int retval = _spawnl(_P_NOWAIT, update_exe_path.c_str(), update_exe_path.c_str(), params.str().c_str(), NULL);
02772         LL_DEBUGS("AppInit") << "Spawn returned " << retval << LL_ENDL;
02773 
02774 #elif LL_DARWIN
02775         // if a sim name was passed in via command line parameter (typically through a SLURL)
02776         if ( LLURLSimString::sInstance.mSimString.length() )
02777         {
02778                 // record the location to start at next time
02779                 gSavedSettings.setString( "NextLoginLocation", LLURLSimString::sInstance.mSimString ); 
02780         };
02781         
02782         update_exe_path = "'";
02783         update_exe_path += gDirUtilp->getAppRODataDir();
02784         update_exe_path += "/AutoUpdater.app/Contents/MacOS/AutoUpdater' -url \"";
02785         update_exe_path += update_url.asString();
02786         update_exe_path += "\" -name \"";
02787         update_exe_path += LLAppViewer::instance()->getSecondLifeTitle();
02788         update_exe_path += "\" &";
02789 
02790         LL_DEBUGS("AppInit") << "Calling updater: " << update_exe_path << LL_ENDL;
02791         
02792         // *REMOVE:Mani The following call is handled through ~LLAppViewer.
02793         // remove_marker_file(); // In case updater fails
02794 
02795         // Run the auto-updater.
02796         system(update_exe_path.c_str());                /* Flawfinder: ignore */
02797         
02798 #elif LL_LINUX
02799         OSMessageBox("Automatic updating is not yet implemented for Linux.\n"
02800                 "Please download the latest version from www.secondlife.com.",
02801                 NULL, OSMB_OK);
02802 
02803         // *REMOVE:Mani The following call is handled through ~LLAppViewer.
02804         // remove_marker_file();
02805         
02806 #endif
02807         LLAppViewer::instance()->forceQuit();
02808 }
02809 
02810 void use_circuit_callback(void**, S32 result)
02811 {
02812         // bail if we're quitting.
02813         if(LLApp::isExiting()) return;
02814         if( !gUseCircuitCallbackCalled )
02815         {
02816                 gUseCircuitCallbackCalled = true;
02817                 if (result)
02818                 {
02819                         // Make sure user knows something bad happened. JC
02820                         LL_WARNS("AppInit") << "Backing up to login screen!" << LL_ENDL;
02821                         gViewerWindow->alertXml("LoginPacketNeverReceived",
02822                                 login_alert_status, NULL);
02823                         reset_login();
02824                 }
02825                 else
02826                 {
02827                         gGotUseCircuitCodeAck = true;
02828                 }
02829         }
02830 }
02831 
02832 void register_viewer_callbacks(LLMessageSystem* msg)
02833 {
02834         msg->setHandlerFuncFast(_PREHASH_LayerData,                             process_layer_data );
02835         msg->setHandlerFuncFast(_PREHASH_ImageData,                             LLViewerImageList::receiveImageHeader );
02836         msg->setHandlerFuncFast(_PREHASH_ImagePacket,                           LLViewerImageList::receiveImagePacket );
02837         msg->setHandlerFuncFast(_PREHASH_ObjectUpdate,                          process_object_update );
02838         msg->setHandlerFunc("ObjectUpdateCompressed",                           process_compressed_object_update );
02839         msg->setHandlerFunc("ObjectUpdateCached",                                       process_cached_object_update );
02840         msg->setHandlerFuncFast(_PREHASH_ImprovedTerseObjectUpdate, process_terse_object_update_improved );
02841         msg->setHandlerFunc("SimStats",                         process_sim_stats);
02842         msg->setHandlerFuncFast(_PREHASH_HealthMessage,                 process_health_message );
02843         msg->setHandlerFuncFast(_PREHASH_EconomyData,                           process_economy_data);
02844         msg->setHandlerFunc("RegionInfo", LLViewerRegion::processRegionInfo);
02845 
02846         msg->setHandlerFuncFast(_PREHASH_ChatFromSimulator,             process_chat_from_simulator);
02847         msg->setHandlerFuncFast(_PREHASH_KillObject,                            process_kill_object,    NULL);
02848         msg->setHandlerFuncFast(_PREHASH_SimulatorViewerTimeMessage,    process_time_synch,             NULL);
02849         msg->setHandlerFuncFast(_PREHASH_EnableSimulator,                       process_enable_simulator);
02850         msg->setHandlerFuncFast(_PREHASH_DisableSimulator,                      process_disable_simulator);
02851         msg->setHandlerFuncFast(_PREHASH_KickUser,                                      process_kick_user,              NULL);
02852 
02853         msg->setHandlerFunc("CrossedRegion", process_crossed_region);
02854         msg->setHandlerFuncFast(_PREHASH_TeleportFinish, process_teleport_finish);
02855 
02856         msg->setHandlerFuncFast(_PREHASH_AlertMessage,             process_alert_message);
02857         msg->setHandlerFunc("AgentAlertMessage", process_agent_alert_message);
02858         msg->setHandlerFuncFast(_PREHASH_MeanCollisionAlert,             process_mean_collision_alert_message,  NULL);
02859         msg->setHandlerFunc("ViewerFrozenMessage",             process_frozen_message);
02860 
02861         msg->setHandlerFuncFast(_PREHASH_NameValuePair,                 process_name_value);
02862         msg->setHandlerFuncFast(_PREHASH_RemoveNameValuePair,   process_remove_name_value);
02863         msg->setHandlerFuncFast(_PREHASH_AvatarAnimation,               process_avatar_animation);
02864         msg->setHandlerFuncFast(_PREHASH_AvatarAppearance,              process_avatar_appearance);
02865         msg->setHandlerFunc("AgentCachedTextureResponse",       LLAgent::processAgentCachedTextureResponse);
02866         msg->setHandlerFunc("RebakeAvatarTextures", LLVOAvatar::processRebakeAvatarTextures);
02867         msg->setHandlerFuncFast(_PREHASH_CameraConstraint,              process_camera_constraint);
02868         msg->setHandlerFuncFast(_PREHASH_AvatarSitResponse,             process_avatar_sit_response);
02869         msg->setHandlerFunc("SetFollowCamProperties",                   process_set_follow_cam_properties);
02870         msg->setHandlerFunc("ClearFollowCamProperties",                 process_clear_follow_cam_properties);
02871 
02872         msg->setHandlerFuncFast(_PREHASH_ImprovedInstantMessage,        process_improved_im);
02873         msg->setHandlerFuncFast(_PREHASH_ScriptQuestion,                        process_script_question);
02874         msg->setHandlerFuncFast(_PREHASH_ObjectProperties,                      LLSelectMgr::processObjectProperties, NULL);
02875         msg->setHandlerFuncFast(_PREHASH_ObjectPropertiesFamily,        LLSelectMgr::processObjectPropertiesFamily, NULL);
02876         msg->setHandlerFunc("ForceObjectSelect", LLSelectMgr::processForceObjectSelect);
02877 
02878         msg->setHandlerFuncFast(_PREHASH_MoneyBalanceReply,             process_money_balance_reply,    NULL);
02879         msg->setHandlerFuncFast(_PREHASH_CoarseLocationUpdate,          LLWorld::processCoarseUpdate, NULL);
02880         msg->setHandlerFuncFast(_PREHASH_ReplyTaskInventory,            LLViewerObject::processTaskInv, NULL);
02881         msg->setHandlerFuncFast(_PREHASH_DerezContainer,                        process_derez_container, NULL);
02882         msg->setHandlerFuncFast(_PREHASH_ScriptRunningReply,
02883                                                 &LLLiveLSLEditor::processScriptRunningReply);
02884 
02885         msg->setHandlerFuncFast(_PREHASH_DeRezAck, process_derez_ack);
02886 
02887         msg->setHandlerFunc("LogoutReply", process_logout_reply);
02888 
02889         //msg->setHandlerFuncFast(_PREHASH_AddModifyAbility,
02890         //                                      &LLAgent::processAddModifyAbility);
02891         //msg->setHandlerFuncFast(_PREHASH_RemoveModifyAbility,
02892         //                                      &LLAgent::processRemoveModifyAbility);
02893         msg->setHandlerFuncFast(_PREHASH_AgentDataUpdate,
02894                                                 &LLAgent::processAgentDataUpdate);
02895         msg->setHandlerFuncFast(_PREHASH_AgentGroupDataUpdate,
02896                                                 &LLAgent::processAgentGroupDataUpdate);
02897         msg->setHandlerFunc("AgentDropGroup",
02898                                                 &LLAgent::processAgentDropGroup);
02899         // land ownership messages
02900         msg->setHandlerFuncFast(_PREHASH_ParcelOverlay,
02901                                                 LLViewerParcelMgr::processParcelOverlay);
02902         msg->setHandlerFuncFast(_PREHASH_ParcelProperties,
02903                                                 LLViewerParcelMgr::processParcelProperties);
02904         msg->setHandlerFunc("ParcelAccessListReply",
02905                 LLViewerParcelMgr::processParcelAccessListReply);
02906         msg->setHandlerFunc("ParcelDwellReply",
02907                 LLViewerParcelMgr::processParcelDwellReply);
02908 
02909         msg->setHandlerFunc("AvatarPropertiesReply",
02910                                                 LLPanelAvatar::processAvatarPropertiesReply);
02911         msg->setHandlerFunc("AvatarInterestsReply",
02912                                                 LLPanelAvatar::processAvatarInterestsReply);
02913         msg->setHandlerFunc("AvatarGroupsReply",
02914                                                 LLPanelAvatar::processAvatarGroupsReply);
02915         // ratings deprecated
02916         //msg->setHandlerFuncFast(_PREHASH_AvatarStatisticsReply,
02917         //                                      LLPanelAvatar::processAvatarStatisticsReply);
02918         msg->setHandlerFunc("AvatarNotesReply",
02919                                                 LLPanelAvatar::processAvatarNotesReply);
02920         msg->setHandlerFunc("AvatarPicksReply",
02921                                                 LLPanelAvatar::processAvatarPicksReply);
02922         msg->setHandlerFunc("AvatarClassifiedReply",
02923                                                 LLPanelAvatar::processAvatarClassifiedReply);
02924 
02925         msg->setHandlerFuncFast(_PREHASH_CreateGroupReply,
02926                                                 LLGroupMgr::processCreateGroupReply);
02927         msg->setHandlerFuncFast(_PREHASH_JoinGroupReply,
02928                                                 LLGroupMgr::processJoinGroupReply);
02929         msg->setHandlerFuncFast(_PREHASH_EjectGroupMemberReply,
02930                                                 LLGroupMgr::processEjectGroupMemberReply);
02931         msg->setHandlerFuncFast(_PREHASH_LeaveGroupReply,
02932                                                 LLGroupMgr::processLeaveGroupReply);
02933         msg->setHandlerFuncFast(_PREHASH_GroupProfileReply,
02934                                                 LLGroupMgr::processGroupPropertiesReply);
02935 
02936         // ratings deprecated
02937         // msg->setHandlerFuncFast(_PREHASH_ReputationIndividualReply,
02938         //                                      LLFloaterRate::processReputationIndividualReply);
02939 
02940         msg->setHandlerFuncFast(_PREHASH_AgentWearablesUpdate,
02941                                                 LLAgent::processAgentInitialWearablesUpdate );
02942 
02943         msg->setHandlerFunc("ScriptControlChange",
02944                                                 LLAgent::processScriptControlChange );
02945 
02946         msg->setHandlerFuncFast(_PREHASH_ViewerEffect, LLHUDManager::processViewerEffect);
02947 
02948         msg->setHandlerFuncFast(_PREHASH_GrantGodlikePowers, process_grant_godlike_powers);
02949 
02950         msg->setHandlerFuncFast(_PREHASH_GroupAccountSummaryReply,
02951                                                         LLPanelGroupLandMoney::processGroupAccountSummaryReply);
02952         msg->setHandlerFuncFast(_PREHASH_GroupAccountDetailsReply,
02953                                                         LLPanelGroupLandMoney::processGroupAccountDetailsReply);
02954         msg->setHandlerFuncFast(_PREHASH_GroupAccountTransactionsReply,
02955                                                         LLPanelGroupLandMoney::processGroupAccountTransactionsReply);
02956 
02957         msg->setHandlerFuncFast(_PREHASH_UserInfoReply,
02958                 process_user_info_reply);
02959 
02960         msg->setHandlerFunc("RegionHandshake", process_region_handshake, NULL);
02961 
02962         msg->setHandlerFunc("TeleportStart", process_teleport_start );
02963         msg->setHandlerFunc("TeleportProgress", process_teleport_progress);
02964         msg->setHandlerFunc("TeleportFailed", process_teleport_failed, NULL);
02965         msg->setHandlerFunc("TeleportLocal", process_teleport_local, NULL);
02966 
02967         msg->setHandlerFunc("ImageNotInDatabase", LLViewerImageList::processImageNotInDatabase, NULL);
02968 
02969         msg->setHandlerFuncFast(_PREHASH_GroupMembersReply,
02970                                                 LLGroupMgr::processGroupMembersReply);
02971         msg->setHandlerFunc("GroupRoleDataReply",
02972                                                 LLGroupMgr::processGroupRoleDataReply);
02973         msg->setHandlerFunc("GroupRoleMembersReply",
02974                                                 LLGroupMgr::processGroupRoleMembersReply);
02975         msg->setHandlerFunc("GroupTitlesReply",
02976                                                 LLGroupMgr::processGroupTitlesReply);
02977         // Special handler as this message is sometimes used for group land.
02978         msg->setHandlerFunc("PlacesReply", process_places_reply);
02979         msg->setHandlerFunc("GroupNoticesListReply", LLPanelGroupNotices::processGroupNoticesListReply);
02980 
02981         msg->setHandlerFunc("DirPlacesReply", LLPanelDirBrowser::processDirPlacesReply);
02982         msg->setHandlerFunc("DirPeopleReply", LLPanelDirBrowser::processDirPeopleReply);
02983         msg->setHandlerFunc("DirEventsReply", LLPanelDirBrowser::processDirEventsReply);
02984         msg->setHandlerFunc("DirGroupsReply", LLPanelDirBrowser::processDirGroupsReply);
02985         //msg->setHandlerFunc("DirPicksReply",  LLPanelDirBrowser::processDirPicksReply);
02986         msg->setHandlerFunc("DirClassifiedReply",  LLPanelDirBrowser::processDirClassifiedReply);
02987         msg->setHandlerFunc("DirLandReply",   LLPanelDirBrowser::processDirLandReply);
02988         //msg->setHandlerFunc("DirPopularReply",LLPanelDirBrowser::processDirPopularReply);
02989 
02990         msg->setHandlerFunc("AvatarPickerReply", LLFloaterAvatarPicker::processAvatarPickerReply);
02991 
02992         msg->setHandlerFunc("MapLayerReply", LLWorldMap::processMapLayerReply);
02993         msg->setHandlerFunc("MapBlockReply", LLWorldMap::processMapBlockReply);
02994         msg->setHandlerFunc("MapItemReply", LLWorldMap::processMapItemReply);
02995 
02996         msg->setHandlerFunc("EventInfoReply", LLPanelEvent::processEventInfoReply);
02997         msg->setHandlerFunc("PickInfoReply", LLPanelPick::processPickInfoReply);
02998         msg->setHandlerFunc("ClassifiedInfoReply", LLPanelClassified::processClassifiedInfoReply);
02999         msg->setHandlerFunc("ParcelInfoReply", LLPanelPlace::processParcelInfoReply);
03000         msg->setHandlerFunc("ScriptDialog", process_script_dialog);
03001         msg->setHandlerFunc("LoadURL", process_load_url);
03002         msg->setHandlerFunc("ScriptTeleportRequest", process_script_teleport_request);
03003         msg->setHandlerFunc("EstateCovenantReply", process_covenant_reply);
03004 
03005         // calling cards
03006         msg->setHandlerFunc("OfferCallingCard", process_offer_callingcard);
03007         msg->setHandlerFunc("AcceptCallingCard", process_accept_callingcard);
03008         msg->setHandlerFunc("DeclineCallingCard", process_decline_callingcard);
03009 
03010         msg->setHandlerFunc("ParcelObjectOwnersReply", LLPanelLandObjects::processParcelObjectOwnersReply);
03011 
03012         msg->setHandlerFunc("InitiateDownload", process_initiate_download);
03013         msg->setHandlerFunc("LandStatReply", LLFloaterTopObjects::handle_land_reply);
03014         msg->setHandlerFunc("GenericMessage", process_generic_message);
03015 
03016         msg->setHandlerFuncFast(_PREHASH_FeatureDisabled, process_feature_disabled_message);
03017 }
03018 
03019 
03020 void init_stat_view()
03021 {
03022         LLFrameStatView *frameviewp = gDebugView->mFrameStatView;
03023         frameviewp->setup(gFrameStats);
03024         frameviewp->mShowPercent = FALSE;
03025 
03026         LLRect rect;
03027         LLStatBar *stat_barp;
03028         rect = gDebugView->mFloaterStatsp->getRect();
03029 
03030         //
03031         // Viewer advanced stats
03032         //
03033         LLStatView *stat_viewp = NULL;
03034 
03035         //
03036         // Viewer Basic
03037         //
03038         stat_viewp = new LLStatView("basic stat view", "Basic", "OpenDebugStatBasic", rect);
03039         gDebugView->mFloaterStatsp->addStatView(stat_viewp);
03040 
03041         stat_barp = stat_viewp->addStat("FPS", &(LLViewerStats::getInstance()->mFPSStat));
03042         stat_barp->setUnitLabel(" fps");
03043         stat_barp->mMinBar = 0.f;
03044         stat_barp->mMaxBar = 45.f;
03045         stat_barp->mTickSpacing = 7.5f;
03046         stat_barp->mLabelSpacing = 15.f;
03047         stat_barp->mPrecision = 1;
03048         stat_barp->mDisplayBar = TRUE;
03049         stat_barp->mDisplayHistory = TRUE;
03050 
03051         stat_barp = stat_viewp->addStat("Bandwidth", &(LLViewerStats::getInstance()->mKBitStat));
03052         stat_barp->setUnitLabel(" kbps");
03053         stat_barp->mMinBar = 0.f;
03054         stat_barp->mMaxBar = 900.f;
03055         stat_barp->mTickSpacing = 100.f;
03056         stat_barp->mLabelSpacing = 300.f;
03057         stat_barp->mDisplayBar = TRUE;
03058         stat_barp->mDisplayHistory = FALSE;
03059 
03060         stat_barp = stat_viewp->addStat("Packet Loss", &(LLViewerStats::getInstance()->mPacketsLostPercentStat));
03061         stat_barp->setUnitLabel(" %");
03062         stat_barp->mMinBar = 0.f;
03063         stat_barp->mMaxBar = 5.f;
03064         stat_barp->mTickSpacing = 1.f;
03065         stat_barp->mLabelSpacing = 1.f;
03066         stat_barp->mDisplayBar = FALSE;
03067         stat_barp->mPerSec = FALSE;
03068         stat_barp->mDisplayMean = TRUE;
03069         stat_barp->mPrecision = 1;
03070 
03071         stat_barp = stat_viewp->addStat("Ping Sim", &(LLViewerStats::getInstance()->mSimPingStat));
03072         stat_barp->setUnitLabel(" msec");
03073         stat_barp->mMinBar = 0.f;
03074         stat_barp->mMaxBar = 1000.f;
03075         stat_barp->mTickSpacing = 100.f;
03076         stat_barp->mLabelSpacing = 200.f;
03077         stat_barp->mDisplayBar = FALSE;
03078         stat_barp->mPerSec = FALSE;
03079         stat_barp->mDisplayMean = FALSE;
03080 
03081 
03082         stat_viewp = new LLStatView("advanced stat view", "Advanced", "OpenDebugStatAdvanced", rect);
03083         gDebugView->mFloaterStatsp->addStatView(stat_viewp);
03084 
03085 
03086         LLStatView *render_statviewp;
03087         render_statviewp = new LLStatView("render stat view", "Render", "OpenDebugStatRender", rect);
03088         stat_viewp->addChildAtEnd(render_statviewp);
03089 
03090         stat_barp = render_statviewp->addStat("KTris Drawn", &(gPipeline.mTrianglesDrawnStat));
03091         stat_barp->setUnitLabel("/fr");
03092         stat_barp->mMinBar = 0.f;
03093         stat_barp->mMaxBar = 500.f;
03094         stat_barp->mTickSpacing = 100.f;
03095         stat_barp->mLabelSpacing = 500.f;
03096         stat_barp->mPrecision = 1;
03097         stat_barp->mPerSec = FALSE;
03098 
03099         stat_barp = render_statviewp->addStat("KTris Drawn", &(gPipeline.mTrianglesDrawnStat));
03100         stat_barp->setUnitLabel("/sec");
03101         stat_barp->mMinBar = 0.f;
03102         stat_barp->mMaxBar = 3000.f;
03103         stat_barp->mTickSpacing = 250.f;
03104         stat_barp->mLabelSpacing = 1000.f;
03105         stat_barp->mPrecision = 1;
03106 
03107         stat_barp = render_statviewp->addStat("Total Objs", &(gObjectList.mNumObjectsStat));
03108         stat_barp->mMinBar = 0.f;
03109         stat_barp->mMaxBar = 10000.f;
03110         stat_barp->mTickSpacing = 2500.f;
03111         stat_barp->mLabelSpacing = 5000.f;
03112         stat_barp->mPerSec = FALSE;
03113         stat_barp->mDisplayBar = FALSE;
03114 
03115         stat_barp = render_statviewp->addStat("New Objs", &(gObjectList.mNumNewObjectsStat));
03116         stat_barp->setLabel("New Objs");
03117         stat_barp->setUnitLabel("/sec");
03118         stat_barp->mMinBar = 0.f;
03119         stat_barp->mMaxBar = 1000.f;
03120         stat_barp->mTickSpacing = 100.f;
03121         stat_barp->mLabelSpacing = 500.f;
03122         stat_barp->mPerSec = TRUE;
03123         stat_barp->mDisplayBar = FALSE;
03124 
03125 
03126         // Texture statistics
03127         LLStatView *texture_statviewp;
03128         texture_statviewp = new LLStatView("texture stat view", "Texture", "", rect);
03129         render_statviewp->addChildAtEnd(texture_statviewp);
03130 
03131         stat_barp = texture_statviewp->addStat("Count", &(gImageList.sNumImagesStat));
03132         stat_barp->setUnitLabel("");
03133         stat_barp->mMinBar = 0.f;
03134         stat_barp->mMaxBar = 8000.f;
03135         stat_barp->mTickSpacing = 2000.f;
03136         stat_barp->mLabelSpacing = 4000.f;
03137         stat_barp->mPerSec = FALSE;
03138         stat_barp->mDisplayBar = FALSE;
03139 
03140         stat_barp = texture_statviewp->addStat("Raw Count", &(gImageList.sNumRawImagesStat));
03141         stat_barp->setUnitLabel("");
03142         stat_barp->mMinBar = 0.f;
03143         stat_barp->mMaxBar = 8000.f;
03144         stat_barp->mTickSpacing = 2000.f;
03145         stat_barp->mLabelSpacing = 4000.f;
03146         stat_barp->mPerSec = FALSE;
03147         stat_barp->mDisplayBar = FALSE;
03148 
03149         stat_barp = texture_statviewp->addStat("GL Mem", &(gImageList.sGLTexMemStat));
03150         stat_barp->setUnitLabel("");
03151         stat_barp->mMinBar = 0.f;
03152         stat_barp->mMaxBar = 400.f;
03153         stat_barp->mTickSpacing = 100.f;
03154         stat_barp->mLabelSpacing = 200.f;
03155         stat_barp->mPrecision = 1;
03156         stat_barp->mPerSec = FALSE;
03157 
03158         stat_barp = texture_statviewp->addStat("Formatted Mem", &(gImageList.sFormattedMemStat));
03159         stat_barp->setUnitLabel("");
03160         stat_barp->mMinBar = 0.f;
03161         stat_barp->mMaxBar = 400.f;
03162         stat_barp->mTickSpacing = 100.f;
03163         stat_barp->mLabelSpacing = 200.f;
03164         stat_barp->mPrecision = 1;
03165         stat_barp->mPerSec = FALSE;
03166 
03167         stat_barp = texture_statviewp->addStat("Raw Mem", &(gImageList.sRawMemStat));
03168         stat_barp->setUnitLabel("");
03169         stat_barp->mMinBar = 0.f;
03170         stat_barp->mMaxBar = 400.f;
03171         stat_barp->mTickSpacing = 100.f;
03172         stat_barp->mLabelSpacing = 200.f;
03173         stat_barp->mPrecision = 1;
03174         stat_barp->mPerSec = FALSE;
03175 
03176         stat_barp = texture_statviewp->addStat("Bound Mem", &(gImageList.sGLBoundMemStat));
03177         stat_barp->setUnitLabel("");
03178         stat_barp->mMinBar = 0.f;
03179         stat_barp->mMaxBar = 400.f;
03180         stat_barp->mTickSpacing = 100.f;
03181         stat_barp->mLabelSpacing = 200.f;
03182         stat_barp->mPrecision = 1;
03183         stat_barp->mPerSec = FALSE;
03184 
03185         
03186         // Network statistics
03187         LLStatView *net_statviewp;
03188         net_statviewp = new LLStatView("network stat view", "Network", "OpenDebugStatNet", rect);
03189         stat_viewp->addChildAtEnd(net_statviewp);
03190 
03191         stat_barp = net_statviewp->addStat("Packets In", &(LLViewerStats::getInstance()->mPacketsInStat));
03192         stat_barp->setUnitLabel("/sec");
03193         stat_barp->mDisplayBar = FALSE;
03194 
03195         stat_barp = net_statviewp->addStat("Packets Out", &(LLViewerStats::getInstance()->mPacketsOutStat));
03196         stat_barp->setUnitLabel("/sec");
03197         stat_barp->mDisplayBar = FALSE;
03198 
03199         stat_barp = net_statviewp->addStat("Objects", &(LLViewerStats::getInstance()->mObjectKBitStat));
03200         stat_barp->setUnitLabel(" kbps");
03201         stat_barp->mDisplayBar = FALSE;
03202 
03203         stat_barp = net_statviewp->addStat("Texture", &(LLViewerStats::getInstance()->mTextureKBitStat));
03204         stat_barp->setUnitLabel(" kbps");
03205         stat_barp->mDisplayBar = FALSE;
03206 
03207         stat_barp = net_statviewp->addStat("Asset", &(LLViewerStats::getInstance()->mAssetKBitStat));
03208         stat_barp->setUnitLabel(" kbps");
03209         stat_barp->mDisplayBar = FALSE;
03210 
03211         stat_barp = net_statviewp->addStat("Layers", &(LLViewerStats::getInstance()->mLayersKBitStat));
03212         stat_barp->setUnitLabel(" kbps");
03213         stat_barp->mDisplayBar = FALSE;
03214 
03215         stat_barp = net_statviewp->addStat("Actual In", &(LLViewerStats::getInstance()->mActualInKBitStat));
03216         stat_barp->setUnitLabel(" kbps");
03217         stat_barp->mMinBar = 0.f;
03218         stat_barp->mMaxBar = 1024.f;
03219         stat_barp->mTickSpacing = 128.f;
03220         stat_barp->mLabelSpacing = 256.f;
03221         stat_barp->mDisplayBar = TRUE;
03222         stat_barp->mDisplayHistory = FALSE;
03223 
03224         stat_barp = net_statviewp->addStat("Actual Out", &(LLViewerStats::getInstance()->mActualOutKBitStat));
03225         stat_barp->setUnitLabel(" kbps");
03226         stat_barp->mMinBar = 0.f;
03227         stat_barp->mMaxBar = 512.f;
03228         stat_barp->mTickSpacing = 128.f;
03229         stat_barp->mLabelSpacing = 256.f;
03230         stat_barp->mDisplayBar = TRUE;
03231         stat_barp->mDisplayHistory = FALSE;
03232 
03233         stat_barp = net_statviewp->addStat("VFS Pending Ops", &(LLViewerStats::getInstance()->mVFSPendingOperations));
03234         stat_barp->setUnitLabel(" ");
03235         stat_barp->mPerSec = FALSE;
03236         stat_barp->mDisplayBar = FALSE;
03237 
03238 
03239         // Simulator stats
03240         LLStatView *sim_statviewp = new LLStatView("sim stat view", "Simulator", "OpenDebugStatSim", rect);
03241         gDebugView->mFloaterStatsp->addStatView(sim_statviewp);
03242 
03243         stat_barp = sim_statviewp->addStat("Time Dilation", &(LLViewerStats::getInstance()->mSimTimeDilation));
03244         stat_barp->mPrecision = 2;
03245         stat_barp->mMinBar = 0.f;
03246         stat_barp->mMaxBar = 1.f;
03247         stat_barp->mTickSpacing = 0.25f;
03248         stat_barp->mLabelSpacing = 0.5f;
03249         stat_barp->mPerSec = FALSE;
03250         stat_barp->mDisplayBar = FALSE;
03251         stat_barp->mDisplayMean = FALSE;
03252 
03253         stat_barp = sim_statviewp->addStat("Sim FPS", &(LLViewerStats::getInstance()->mSimFPS));
03254         stat_barp->mMinBar = 0.f;
03255         stat_barp->mMaxBar = 200.f;
03256         stat_barp->mTickSpacing = 20.f;
03257         stat_barp->mLabelSpacing = 100.f;
03258         stat_barp->mPerSec = FALSE;
03259         stat_barp->mDisplayBar = FALSE;
03260         stat_barp->mDisplayMean = FALSE;
03261 
03262         stat_barp = sim_statviewp->addStat("Physics FPS", &(LLViewerStats::getInstance()->mSimPhysicsFPS));
03263         stat_barp->mPrecision = 1;
03264         stat_barp->mMinBar = 0.f;
03265         stat_barp->mMaxBar = 66.f;
03266         stat_barp->mTickSpacing = 33.f;
03267         stat_barp->mLabelSpacing = 33.f;
03268         stat_barp->mPerSec = FALSE;
03269         stat_barp->mDisplayBar = FALSE;
03270         stat_barp->mDisplayMean = FALSE;
03271 
03272         LLStatView *phys_details_viewp;
03273         phys_details_viewp = new LLStatView("phys detail view", "Physics Details", "", rect);
03274         sim_statviewp->addChildAtEnd(phys_details_viewp);
03275 
03276         stat_barp = phys_details_viewp->addStat("Pinned Objects", &(LLViewerStats::getInstance()->mPhysicsPinnedTasks));
03277         stat_barp->mPrecision = 0;
03278         stat_barp->mMinBar = 0.f;
03279         stat_barp->mMaxBar = 500.f;
03280         stat_barp->mTickSpacing = 10.f;
03281         stat_barp->mLabelSpacing = 40.f;
03282         stat_barp->mPerSec = FALSE;
03283         stat_barp->mDisplayBar = FALSE;
03284         stat_barp->mDisplayMean = FALSE;
03285 
03286         stat_barp = phys_details_viewp->addStat("Low LOD Objects", &(LLViewerStats::getInstance()->mPhysicsLODTasks));
03287         stat_barp->mPrecision = 0;
03288         stat_barp->mMinBar = 0.f;
03289         stat_barp->mMaxBar = 500.f;
03290         stat_barp->mTickSpacing = 10.f;
03291         stat_barp->mLabelSpacing = 40.f;
03292         stat_barp->mPerSec = FALSE;
03293         stat_barp->mDisplayBar = FALSE;
03294         stat_barp->mDisplayMean = FALSE;
03295 
03296         stat_barp = phys_details_viewp->addStat("Memory Allocated", &(LLViewerStats::getInstance()->mPhysicsMemoryAllocated));
03297         stat_barp->setUnitLabel(" MB");
03298         stat_barp->mPrecision = 0;
03299         stat_barp->mMinBar = 0.f;
03300         stat_barp->mMaxBar = 1024.f;
03301         stat_barp->mTickSpacing = 128.f;
03302         stat_barp->mLabelSpacing = 256.f;
03303         stat_barp->mPerSec = FALSE;
03304         stat_barp->mDisplayBar = FALSE;
03305         stat_barp->mDisplayMean = FALSE;
03306 
03307         stat_barp = sim_statviewp->addStat("Agent Updates/Sec", &(LLViewerStats::getInstance()->mSimAgentUPS));
03308         stat_barp->mPrecision = 1;
03309         stat_barp->mMinBar = 0.f;
03310         stat_barp->mMaxBar = 100.f;
03311         stat_barp->mTickSpacing = 25.f;
03312         stat_barp->mLabelSpacing = 50.f;
03313         stat_barp->mPerSec = FALSE;
03314         stat_barp->mDisplayBar = FALSE;
03315         stat_barp->mDisplayMean = FALSE;
03316 
03317         stat_barp = sim_statviewp->addStat("Main Agents", &(LLViewerStats::getInstance()->mSimMainAgents));
03318         stat_barp->mPrecision = 0;
03319         stat_barp->mMinBar = 0.f;
03320         stat_barp->mMaxBar = 80.f;
03321         stat_barp->mTickSpacing = 10.f;
03322         stat_barp->mLabelSpacing = 40.f;
03323         stat_barp->mPerSec = FALSE;
03324         stat_barp->mDisplayBar = FALSE;
03325         stat_barp->mDisplayMean = FALSE;
03326 
03327         stat_barp = sim_statviewp->addStat("Child Agents", &(LLViewerStats::getInstance()->mSimChildAgents));
03328         stat_barp->mPrecision = 0;
03329         stat_barp->mMinBar = 0.f;
03330         stat_barp->mMaxBar = 40.f;
03331         stat_barp->mTickSpacing = 5.f;
03332         stat_barp->mLabelSpacing = 10.f;
03333         stat_barp->mPerSec = FALSE;
03334         stat_barp->mDisplayBar = FALSE;
03335         stat_barp->mDisplayMean = FALSE;
03336 
03337         stat_barp = sim_statviewp->addStat("Objects", &(LLViewerStats::getInstance()->mSimObjects));
03338         stat_barp->mPrecision = 0;
03339         stat_barp->mMinBar = 0.f;
03340         stat_barp->mMaxBar = 30000.f;
03341         stat_barp->mTickSpacing = 5000.f;
03342         stat_barp->mLabelSpacing = 10000.f;
03343         stat_barp->mPerSec = FALSE;
03344         stat_barp->mDisplayBar = FALSE;
03345         stat_barp->mDisplayMean = FALSE;
03346 
03347         stat_barp = sim_statviewp->addStat("Active Objects", &(LLViewerStats::getInstance()->mSimActiveObjects));
03348         stat_barp->mPrecision = 0;
03349         stat_barp->mMinBar = 0.f;
03350         stat_barp->mMaxBar = 800.f;
03351         stat_barp->mTickSpacing = 100.f;
03352         stat_barp->mLabelSpacing = 200.f;
03353         stat_barp->mPerSec = FALSE;
03354         stat_barp->mDisplayBar = FALSE;
03355         stat_barp->mDisplayMean = FALSE;
03356 
03357         stat_barp = sim_statviewp->addStat("Active Scripts", &(LLViewerStats::getInstance()->mSimActiveScripts));
03358         stat_barp->mPrecision = 0;
03359         stat_barp->mMinBar = 0.f;
03360         stat_barp->mMaxBar = 800.f;
03361         stat_barp->mTickSpacing = 100.f;
03362         stat_barp->mLabelSpacing = 200.f;
03363         stat_barp->mPerSec = FALSE;
03364         stat_barp->mDisplayBar = FALSE;
03365         stat_barp->mDisplayMean = FALSE;
03366 
03367         stat_barp = sim_statviewp->addStat("Script Perf", &(LLViewerStats::getInstance()->mSimLSLIPS));
03368         stat_barp->setUnitLabel(" ips");
03369         stat_barp->mPrecision = 0;
03370         stat_barp->mMinBar = 0.f;
03371         stat_barp->mMaxBar = 100000.f;
03372         stat_barp->mTickSpacing = 25000.f;
03373         stat_barp->mLabelSpacing = 50000.f;
03374         stat_barp->mPerSec = FALSE;
03375         stat_barp->mDisplayBar = FALSE;
03376         stat_barp->mDisplayMean = FALSE;
03377 
03378         stat_barp = sim_statviewp->addStat("Packets In", &(LLViewerStats::getInstance()->mSimInPPS));
03379         stat_barp->setUnitLabel(" pps");
03380         stat_barp->mPrecision = 0;
03381         stat_barp->mMinBar = 0.f;
03382         stat_barp->mMaxBar = 2000.f;
03383         stat_barp->mTickSpacing = 250.f;
03384         stat_barp->mLabelSpacing = 1000.f;
03385         stat_barp->mPerSec = FALSE;
03386         stat_barp->mDisplayBar = FALSE;
03387         stat_barp->mDisplayMean = FALSE;
03388 
03389         stat_barp = sim_statviewp->addStat("Packets Out", &(LLViewerStats::getInstance()->mSimOutPPS));
03390         stat_barp->setUnitLabel(" pps");
03391         stat_barp->mPrecision = 0;
03392         stat_barp->mMinBar = 0.f;
03393         stat_barp->mMaxBar = 2000.f;
03394         stat_barp->mTickSpacing = 250.f;
03395         stat_barp->mLabelSpacing = 1000.f;
03396         stat_barp->mPerSec = FALSE;
03397         stat_barp->mDisplayBar = FALSE;
03398         stat_barp->mDisplayMean = FALSE;
03399 
03400         stat_barp = sim_statviewp->addStat("Pending Downloads", &(LLViewerStats::getInstance()->mSimPendingDownloads));
03401         stat_barp->mPrecision = 0;
03402         stat_barp->mMinBar = 0.f;
03403         stat_barp->mMaxBar = 800.f;
03404         stat_barp->mTickSpacing = 100.f;
03405         stat_barp->mLabelSpacing = 200.f;
03406         stat_barp->mPerSec = FALSE;
03407         stat_barp->mDisplayBar = FALSE;
03408         stat_barp->mDisplayMean = FALSE;
03409 
03410         stat_barp = sim_statviewp->addStat("Pending Uploads", &(LLViewerStats::getInstance()->mSimPendingUploads));
03411         stat_barp->mPrecision = 0;
03412         stat_barp->mMinBar = 0.f;
03413         stat_barp->mMaxBar = 100.f;
03414         stat_barp->mTickSpacing = 25.f;
03415         stat_barp->mLabelSpacing = 50.f;
03416         stat_barp->mPerSec = FALSE;
03417         stat_barp->mDisplayBar = FALSE;
03418         stat_barp->mDisplayMean = FALSE;
03419 
03420         stat_barp = sim_statviewp->addStat("Total Unacked Bytes", &(LLViewerStats::getInstance()->mSimTotalUnackedBytes));
03421         stat_barp->setUnitLabel(" kb");
03422         stat_barp->mPrecision = 0;
03423         stat_barp->mMinBar = 0.f;
03424         stat_barp->mMaxBar = 100000.f;
03425         stat_barp->mTickSpacing = 25000.f;
03426         stat_barp->mLabelSpacing = 50000.f;
03427         stat_barp->mPerSec = FALSE;
03428         stat_barp->mDisplayBar = FALSE;
03429         stat_barp->mDisplayMean = FALSE;
03430 
03431         LLStatView *sim_time_viewp;
03432         sim_time_viewp = new LLStatView("sim perf view", "Time (ms)", "", rect);
03433         sim_statviewp->addChildAtEnd(sim_time_viewp);
03434 
03435         stat_barp = sim_time_viewp->addStat("Total Frame Time", &(LLViewerStats::getInstance()->mSimFrameMsec));
03436         stat_barp->setUnitLabel("ms");
03437         stat_barp->mPrecision = 1;
03438         stat_barp->mMinBar = 0.f;
03439         stat_barp->mMaxBar = 40.f;
03440         stat_barp->mTickSpacing = 10.f;
03441         stat_barp->mLabelSpacing = 20.f;
03442         stat_barp->mPerSec = FALSE;
03443         stat_barp->mDisplayBar = FALSE;
03444         stat_barp->mDisplayMean = FALSE;
03445 
03446         stat_barp = sim_time_viewp->addStat("Net Time", &(LLViewerStats::getInstance()->mSimNetMsec));
03447         stat_barp->setUnitLabel("ms");
03448         stat_barp->mPrecision = 1;
03449         stat_barp->mMinBar = 0.f;
03450         stat_barp->mMaxBar = 40.f;
03451         stat_barp->mTickSpacing = 10.f;
03452         stat_barp->mLabelSpacing = 20.f;
03453         stat_barp->mPerSec = FALSE;
03454         stat_barp->mDisplayBar = FALSE;
03455         stat_barp->mDisplayMean = FALSE;
03456 
03457         stat_barp = sim_time_viewp->addStat("Sim Time (Physics)", &(LLViewerStats::getInstance()->mSimSimPhysicsMsec));
03458         stat_barp->setUnitLabel("ms");
03459         stat_barp->mPrecision = 1;
03460         stat_barp->mMinBar = 0.f;
03461         stat_barp->mMaxBar = 40.f;
03462         stat_barp->mTickSpacing = 10.f;
03463         stat_barp->mLabelSpacing = 20.f;
03464         stat_barp->mPerSec = FALSE;
03465         stat_barp->mDisplayBar = FALSE;
03466         stat_barp->mDisplayMean = FALSE;
03467 
03468         LLStatView *physics_time_viewp;
03469         physics_time_viewp = new LLStatView("physics perf view", "Physics Details (ms)", "", rect);
03470         sim_time_viewp->addChildAtEnd(physics_time_viewp);
03471         {
03472                 stat_barp = physics_time_viewp->addStat("Physics Step", &(LLViewerStats::getInstance()->mSimSimPhysicsStepMsec));
03473                 stat_barp->setUnitLabel("ms");
03474                 stat_barp->mPrecision = 1;
03475                 stat_barp->mMinBar = 0.f;
03476                 stat_barp->mMaxBar = 40.f;
03477                 stat_barp->mTickSpacing = 10.f;
03478                 stat_barp->mLabelSpacing = 20.f;
03479                 stat_barp->mPerSec = FALSE;
03480                 stat_barp->mDisplayBar = FALSE;
03481                 stat_barp->mDisplayMean = FALSE;
03482 
03483                 stat_barp = physics_time_viewp->addStat("Update Shapes", &(LLViewerStats::getInstance()->mSimSimPhysicsShapeUpdateMsec));
03484                 stat_barp->setUnitLabel("ms");
03485                 stat_barp->mPrecision = 1;
03486                 stat_barp->mMinBar = 0.f;
03487                 stat_barp->mMaxBar = 40.f;
03488                 stat_barp->mTickSpacing = 10.f;
03489                 stat_barp->mLabelSpacing = 20.f;
03490                 stat_barp->mPerSec = FALSE;
03491                 stat_barp->mDisplayBar = FALSE;
03492                 stat_barp->mDisplayMean = FALSE;
03493 
03494                 stat_barp = physics_time_viewp->addStat("Other", &(LLViewerStats::getInstance()->mSimSimPhysicsOtherMsec));
03495                 stat_barp->setUnitLabel("ms");
03496                 stat_barp->mPrecision = 1;
03497                 stat_barp->mMinBar = 0.f;
03498                 stat_barp->mMaxBar = 40.f;
03499                 stat_barp->mTickSpacing = 10.f;
03500                 stat_barp->mLabelSpacing = 20.f;
03501                 stat_barp->mPerSec = FALSE;
03502                 stat_barp->mDisplayBar = FALSE;
03503                 stat_barp->mDisplayMean = FALSE;
03504         }
03505 
03506         stat_barp = sim_time_viewp->addStat("Sim Time (Other)", &(LLViewerStats::getInstance()->mSimSimOtherMsec));
03507         stat_barp->setUnitLabel("ms");
03508         stat_barp->mPrecision = 1;
03509         stat_barp->mMinBar = 0.f;
03510         stat_barp->mMaxBar = 40.f;
03511         stat_barp->mTickSpacing = 10.f;
03512         stat_barp->mLabelSpacing = 20.f;
03513         stat_barp->mPerSec = FALSE;
03514         stat_barp->mDisplayBar = FALSE;
03515         stat_barp->mDisplayMean = FALSE;
03516 
03517         stat_barp = sim_time_viewp->addStat("Agent Time", &(LLViewerStats::getInstance()->mSimAgentMsec));
03518         stat_barp->setUnitLabel("ms");
03519         stat_barp->mPrecision = 1;
03520         stat_barp->mMinBar = 0.f;
03521         stat_barp->mMaxBar = 40.f;
03522         stat_barp->mTickSpacing = 10.f;
03523         stat_barp->mLabelSpacing = 20.f;
03524         stat_barp->mPerSec = FALSE;
03525         stat_barp->mDisplayBar = FALSE;
03526         stat_barp->mDisplayMean = FALSE;
03527 
03528         stat_barp = sim_time_viewp->addStat("Images Time", &(LLViewerStats::getInstance()->mSimImagesMsec));
03529         stat_barp->setUnitLabel("ms");
03530         stat_barp->mPrecision = 1;
03531         stat_barp->mMinBar = 0.f;
03532         stat_barp->mMaxBar = 40.f;
03533         stat_barp->mTickSpacing = 10.f;
03534         stat_barp->mLabelSpacing = 20.f;
03535         stat_barp->mPerSec = FALSE;
03536         stat_barp->mDisplayBar = FALSE;
03537         stat_barp->mDisplayMean = FALSE;
03538 
03539         stat_barp = sim_time_viewp->addStat("Script Time", &(LLViewerStats::getInstance()->mSimScriptMsec));
03540         stat_barp->setUnitLabel("ms");
03541         stat_barp->mPrecision = 1;
03542         stat_barp->mMinBar = 0.f;
03543         stat_barp->mMaxBar = 40.f;
03544         stat_barp->mTickSpacing = 10.f;
03545         stat_barp->mLabelSpacing = 20.f;
03546         stat_barp->mPerSec = FALSE;
03547         stat_barp->mDisplayBar = FALSE;
03548         stat_barp->mDisplayMean = FALSE;
03549 
03550         LLRect r = gDebugView->mFloaterStatsp->getRect();
03551 
03552         // Reshape based on the parameters we set.
03553         gDebugView->mFloaterStatsp->reshape(r.getWidth(), r.getHeight());
03554 }
03555 
03556 void asset_callback_nothing(LLVFS*, const LLUUID&, LLAssetType::EType, void*, S32)
03557 {
03558         // nothing
03559 }
03560 
03561 // *HACK: Must match name in Library or agent inventory
03562 const char* COMMON_GESTURES_FOLDER = "Common Gestures";
03563 const char* MALE_GESTURES_FOLDER = "Male Gestures";
03564 const char* FEMALE_GESTURES_FOLDER = "Female Gestures";
03565 const char* MALE_OUTFIT_FOLDER = "Male Shape & Outfit";
03566 const char* FEMALE_OUTFIT_FOLDER = "Female Shape & Outfit";
03567 const S32 OPT_USE_INITIAL_OUTFIT = -2;
03568 const S32 OPT_CLOSED_WINDOW = -1;
03569 const S32 OPT_MALE = 0;
03570 const S32 OPT_FEMALE = 1;
03571 
03572 void callback_choose_gender(S32 option, void* userdata)
03573 {
03574         S32 gender = OPT_FEMALE;
03575         const char* outfit = FEMALE_OUTFIT_FOLDER;
03576         const char* gestures = FEMALE_GESTURES_FOLDER;
03577         const char* common_gestures = COMMON_GESTURES_FOLDER;
03578         if (!gInitialOutfit.empty())
03579         {
03580                 outfit = gInitialOutfit.c_str();
03581                 if (gInitialOutfitGender == "male")
03582                 {
03583                         gender = OPT_MALE;
03584                         gestures = MALE_GESTURES_FOLDER;
03585                 }
03586                 else
03587                 {
03588                         gender = OPT_FEMALE;
03589                         gestures = FEMALE_GESTURES_FOLDER;
03590                 }
03591         }
03592         else
03593         {
03594                 switch(option)
03595                 {
03596                 case OPT_MALE:
03597                         gender = OPT_MALE;
03598                         outfit = MALE_OUTFIT_FOLDER;
03599                         gestures = MALE_GESTURES_FOLDER;
03600                         break;
03601 
03602                 case OPT_FEMALE:
03603                 case OPT_CLOSED_WINDOW:
03604                 default:
03605                         gender = OPT_FEMALE;
03606                         outfit = FEMALE_OUTFIT_FOLDER;
03607                         gestures = FEMALE_GESTURES_FOLDER;
03608                         break;
03609                 }
03610         }
03611 
03612         // try to find the outfit - if not there, create some default
03613         // wearables.
03614         LLInventoryModel::cat_array_t cat_array;
03615         LLInventoryModel::item_array_t item_array;
03616         LLNameCategoryCollector has_name(outfit);
03617         gInventory.collectDescendentsIf(LLUUID::null,
03618                                                                         cat_array,
03619                                                                         item_array,
03620                                                                         LLInventoryModel::EXCLUDE_TRASH,
03621                                                                         has_name);
03622         if (0 == cat_array.count())
03623         {
03624                 gAgent.createStandardWearables(gender);
03625         }
03626         else
03627         {
03628                 wear_outfit_by_name(outfit);
03629         }
03630         wear_outfit_by_name(gestures);
03631         wear_outfit_by_name(common_gestures);
03632 
03633         typedef std::map<LLUUID, LLMultiGesture*> item_map_t;
03634         item_map_t::iterator gestureIterator;
03635 
03636         // Must be here so they aren't invisible if they close the window.
03637         gAgent.setGenderChosen(TRUE);
03638 }
03639 
03640 void dialog_choose_gender_first_start()
03641 {
03642         if (!gNoRender
03643                 && (!gAgent.isGenderChosen()))
03644         {
03645                 if (!gInitialOutfit.empty())
03646                 {
03647                         gViewerWindow->alertXml("WelcomeNoClothes",
03648                                 callback_choose_gender, NULL);
03649                 }
03650                 else
03651                 {       
03652                         gViewerWindow->alertXml("WelcomeChooseSex",
03653                                 callback_choose_gender, NULL);
03654                         
03655                 }
03656         }
03657 }
03658 
03659 // Loads a bitmap to display during load
03660 // location_id = 0 => last position
03661 // location_id = 1 => home position
03662 void init_start_screen(S32 location_id)
03663 {
03664         if (gStartImageGL.notNull())
03665         {
03666                 gStartImageGL = NULL;
03667                 LL_INFOS("AppInit") << "re-initializing start screen" << LL_ENDL;
03668         }
03669 
03670         LL_DEBUGS("AppInit") << "Loading startup bitmap..." << LL_ENDL;
03671 
03672         LLString temp_str = gDirUtilp->getLindenUserDir() + gDirUtilp->getDirDelimiter();
03673 
03674         if ((S32)START_LOCATION_ID_LAST == location_id)
03675         {
03676                 temp_str += SCREEN_LAST_FILENAME;
03677         }
03678         else
03679         {
03680                 temp_str += SCREEN_HOME_FILENAME;
03681         }
03682 
03683         LLPointer<LLImageBMP> start_image_bmp = new LLImageBMP;
03684         
03685         // Turn off start screen to get around the occasional readback 
03686         // driver bug
03687         if(!gSavedSettings.getBOOL("UseStartScreen"))
03688         {
03689                 LL_INFOS("AppInit")  << "Bitmap load disabled" << LL_ENDL;
03690                 return;
03691         }
03692         else if(!start_image_bmp->load(temp_str) )
03693         {
03694                 LL_WARNS("AppInit") << "Bitmap load failed" << LL_ENDL;
03695                 return;
03696         }
03697 
03698         gStartImageGL = new LLImageGL(FALSE);
03699         gStartImageWidth = start_image_bmp->getWidth();
03700         gStartImageHeight = start_image_bmp->getHeight();
03701 
03702         LLPointer<LLImageRaw> raw = new LLImageRaw;
03703         if (!start_image_bmp->decode(raw, 0.0f))
03704         {
03705                 LL_WARNS("AppInit") << "Bitmap decode failed" << LL_ENDL;
03706                 gStartImageGL = NULL;
03707                 return;
03708         }
03709 
03710         raw->expandToPowerOfTwo();
03711         gStartImageGL->createGLTexture(0, raw);
03712 }
03713 
03714 
03715 // frees the bitmap
03716 void release_start_screen()
03717 {
03718         LL_DEBUGS("AppInit") << "Releasing bitmap..." << LL_ENDL;
03719         gStartImageGL = NULL;
03720 }
03721 
03722 
03723 // static
03724 void LLStartUp::setStartupState( S32 state )
03725 {
03726         LL_INFOS("AppInit") << "Startup state changing from " << gStartupState << " to " << state << LL_ENDL;
03727         gStartupState = state;
03728 }
03729 
03730 
03731 void reset_login()
03732 {
03733         LLStartUp::setStartupState( STATE_LOGIN_SHOW );
03734 
03735         if ( gViewerWindow )
03736         {       // Hide menus and normal buttons
03737                 gViewerWindow->setNormalControlsVisible( FALSE );
03738                 gLoginMenuBarView->setVisible( TRUE );
03739                 gLoginMenuBarView->setEnabled( TRUE );
03740         }
03741 
03742         // Hide any other stuff
03743         if ( gFloaterMap )
03744                 gFloaterMap->setVisible( FALSE );
03745 }
03746 
03747 //---------------------------------------------------------------------------
03748 
03749 std::string LLStartUp::sSLURLCommand;
03750 
03751 bool LLStartUp::canGoFullscreen()
03752 {
03753         return gStartupState >= STATE_WORLD_INIT;
03754 }
03755 
03756 bool LLStartUp::dispatchURL()
03757 {
03758         // ok, if we've gotten this far and have a startup URL
03759         if (!sSLURLCommand.empty())
03760         {
03761                 const bool from_external_browser = true;
03762                 LLURLDispatcher::dispatch(sSLURLCommand, from_external_browser);
03763         }
03764         else if (LLURLSimString::parse())
03765         {
03766                 // If we started with a location, but we're already
03767                 // at that location, don't pop dialogs open.
03768                 LLVector3 pos = gAgent.getPositionAgent();
03769                 F32 dx = pos.mV[VX] - (F32)LLURLSimString::sInstance.mX;
03770                 F32 dy = pos.mV[VY] - (F32)LLURLSimString::sInstance.mY;
03771                 const F32 SLOP = 2.f;   // meters
03772 
03773                 if( LLURLSimString::sInstance.mSimName != gAgent.getRegion()->getName()
03774                         || (dx*dx > SLOP*SLOP)
03775                         || (dy*dy > SLOP*SLOP) )
03776                 {
03777                         std::string url = LLURLSimString::getURL();
03778                         const bool from_external_browser = true;
03779                         LLURLDispatcher::dispatch(url, from_external_browser);
03780                 }
03781                 return true;
03782         }
03783         return false;
03784 }
03785 
03786 void login_alert_done(S32 option, void* user_data)
03787 {
03788         LLPanelLogin::giveFocus();
03789 }

Generated on Fri May 16 08:34:02 2008 for SecondLife by  doxygen 1.5.5