llstartup.cpp 118 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042
  1. /**
  2. * @file llstartup.cpp
  3. * @brief Startup routines. Purely static class.
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright (c) 2004-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llstartup.h"
  34. #include "imageids.h"
  35. #include "llapp.h"
  36. #include "llaudioengine.h"
  37. #if LL_FMOD
  38. # include "llaudioengine_fmod.h"
  39. #endif
  40. #if LL_OPENAL
  41. # include "llaudioengine_openal.h"
  42. #endif
  43. #include "llbase64.h"
  44. #include "llcallbacklist.h"
  45. #include "llcachename.h"
  46. #include "llconsole.h"
  47. #include "lldir.h"
  48. #include "lleconomy.h"
  49. #include "llerrorcontrol.h"
  50. #include "llexperiencecache.h"
  51. #include "llimagebmp.h"
  52. #include "lllandmark.h"
  53. #include "lllocaltextureobject.h"
  54. #include "llmd5.h"
  55. #include "llmemorystream.h"
  56. #include "llmessageconfig.h"
  57. #include "llnamebox.h"
  58. #include "llnameeditor.h"
  59. #include "llnamelistctrl.h"
  60. #include "llnotifications.h"
  61. #include "llprimitive.h"
  62. #include "llproxy.h"
  63. #include "llregionhandle.h"
  64. #include "llsd.h"
  65. #include "llsdserialize.h"
  66. #include "llsdutil.h"
  67. #include "llsdutil_math.h"
  68. #include "llstreamingaudio.h"
  69. #if 0
  70. #include "llthreadpool.h"
  71. #endif
  72. #include "lltrans.h"
  73. #include "llurlhistory.h"
  74. #include "lluserauth.h"
  75. #include "lluserrelations.h"
  76. #include "llversionviewer.h"
  77. #include "llvolumemessage.h"
  78. #include "llxmlrpctransaction.h"
  79. #include "llxorcipher.h"
  80. #include "llagent.h"
  81. #include "llagentpilot.h"
  82. #include "llagentwearables.h"
  83. #include "llappearancemgr.h"
  84. #include "llappcorehttp.h"
  85. #include "llappviewer.h"
  86. #include "llavatarproperties.h"
  87. #include "llavatartracker.h"
  88. #include "llcommandhandler.h"
  89. #include "lldebugview.h"
  90. #include "lldrawable.h"
  91. #include "llenvironment.h"
  92. #include "lleventnotifier.h"
  93. #include "llexperiencelog.h"
  94. #include "llface.h"
  95. #include "llfasttimerview.h"
  96. #include "llfeaturemanager.h"
  97. #include "llfirstuse.h"
  98. #include "llfloateractivespeakers.h"
  99. #include "llfloateravatarpicker.h"
  100. #include "llfloaterbeacons.h"
  101. #include "llfloatercamera.h"
  102. #include "llfloaterchat.h"
  103. #include "hbfloaterdebugtags.h"
  104. #include "llfloaterinventory.h"
  105. #include "llfloaterland.h"
  106. #include "llfloaterminimap.h"
  107. #include "llfloatermove.h"
  108. #include "hbfloaterradar.h"
  109. #include "hbfloatersearch.h"
  110. #include "llfloaterstats.h"
  111. #include "hbfloaterteleporthistory.h"
  112. #include "llfloatertopobjects.h"
  113. #include "llfloatertos.h"
  114. #include "llfloaterworldmap.h"
  115. #include "llgesturemgr.h"
  116. #include "llgridmanager.h"
  117. #include "llgroupmgr.h"
  118. #include "llhudmanager.h"
  119. #include "llinventorymodel.h"
  120. #include "llinventorymodelfetch.h"
  121. #include "llkeyboard.h"
  122. #include "llpanellogin.h"
  123. #include "llmarketplacefunctions.h"
  124. #include "llmutelist.h"
  125. #include "llpanelavatar.h"
  126. #include "llpanelclassified.h" // For LLClassifiedInfo
  127. #include "llpaneldirbrowser.h"
  128. #include "llpaneldirland.h"
  129. #include "llpanelevent.h"
  130. #include "llpanelgrouplandmoney.h"
  131. #include "llpanelgroupnotices.h"
  132. #include "llpipeline.h"
  133. #include "llpreview.h"
  134. #include "llpreviewscript.h" // For LLPreviewScript::loadFunctions()
  135. #include "llproductinforequest.h"
  136. #include "llprogressview.h" // gStartImageWidth and gStartImageHeight
  137. //MK
  138. #include "mkrlinterface.h"
  139. //mk
  140. #include "llselectmgr.h"
  141. #include "llsky.h"
  142. #include "llslurl.h"
  143. #include "llstatusbar.h" // For sendMoneyBalanceRequest()
  144. #include "lltoolmgr.h"
  145. #include "llurldispatcher.h"
  146. #include "hbviewerautomation.h"
  147. #include "llvieweraudio.h"
  148. #include "llviewerassetstorage.h"
  149. #include "llviewercamera.h"
  150. #include "llviewercontrol.h"
  151. #include "llviewerdisplay.h"
  152. #include "llviewergesture.h"
  153. #include "llviewermedia.h"
  154. #include "llviewermenu.h"
  155. #include "llviewermessage.h" // process_*(), invalid_message_callback()
  156. #include "llviewerobjectlist.h"
  157. #include "llviewerparcelmedia.h"
  158. #include "llviewerparcelmgr.h"
  159. #include "llviewerregion.h"
  160. #include "llviewershadermgr.h"
  161. #include "llviewerstats.h"
  162. #include "llviewertexturelist.h"
  163. #include "llviewerthrottle.h"
  164. #include "llviewerwindow.h"
  165. #include "llvoavatarself.h"
  166. #include "llvocache.h"
  167. #include "llvoclouds.h"
  168. #include "llvosky.h" // For gSunTextureID and gMoonTextureID
  169. #include "llvoicechannel.h"
  170. #include "llweb.h"
  171. #include "llworld.h"
  172. #include "llworldmap.h"
  173. #include "llxfermanager.h"
  174. // Exported constants
  175. const std::string SCREEN_HOME_FILENAME = "screen_home.bmp";
  176. const std::string SCREEN_LAST_FILENAME = "screen_last.bmp";
  177. const std::string SCREEN_LAST_BETA_FILENAME = "screen_last-beta.bmp";
  178. constexpr S32 DEFAULT_MAX_AGENT_GROUPS = 25;
  179. constexpr S32 OPENSIM_DEFAULT_MAX_AGENT_GROUPS = 100;
  180. // Exported global
  181. S32 gMaxAgentGroups = DEFAULT_MAX_AGENT_GROUPS;
  182. LLPointer<LLViewerTexture> gStartTexture;
  183. bool gAgentMovementCompleted = false;
  184. std::string gLoginFirstName;
  185. std::string gLoginLastName;
  186. // Local globals
  187. LLHost gAgentSimHost;
  188. bool gGotUseCircuitCodeAck = false;
  189. bool gUseCircuitCallbackCalled = false;
  190. // Static variables
  191. std::string LLStartUp::sInitialOutfit;
  192. std::string LLStartUp::sInitialOutfitGender; // "male" or "female"
  193. EStartupState LLStartUp::sStartupState = STATE_FIRST;
  194. LLSLURL LLStartUp::sLoginSLURL;
  195. LLSLURL LLStartUp::sStartSLURL;
  196. // Defined in llspatialpartition.cpp, used in lloctree.h
  197. extern LLVector4a gOctreeMaxMag;
  198. // Helper function
  199. static std::string xml_escape_string(const std::string& in)
  200. {
  201. std::ostringstream out;
  202. std::string::const_iterator it = in.begin();
  203. std::string::const_iterator end = in.end();
  204. for ( ; it != end; ++it)
  205. {
  206. switch (*it)
  207. {
  208. case '<':
  209. out << "&lt;";
  210. break;
  211. case '>':
  212. out << "&gt;";
  213. break;
  214. case '&':
  215. out << "&amp;";
  216. break;
  217. case '\'':
  218. out << "&apos;";
  219. break;
  220. case '"':
  221. out << "&quot;";
  222. break;
  223. case '\t':
  224. case '\n':
  225. case '\r':
  226. out << *it;
  227. break;
  228. default:
  229. if (*it >= 0 && *it < 20)
  230. {
  231. // Do not output control codes
  232. out << "?";
  233. }
  234. else
  235. {
  236. out << *it;
  237. }
  238. }
  239. }
  240. return out.str();
  241. }
  242. ///////////////////////////////////////////////////////////////////////////////
  243. // LLLoginHandler class
  244. // Handles filling in the login panel information from a SLURL
  245. ///////////////////////////////////////////////////////////////////////////////
  246. class LLLoginHandler final : public LLCommandHandler
  247. {
  248. public:
  249. LLLoginHandler()
  250. : LLCommandHandler("login", UNTRUSTED_ALLOW)
  251. {
  252. }
  253. bool handle(const LLSD&, const LLSD& query_map, LLMediaCtrl*) override;
  254. };
  255. // Must have instance to auto-register with LLCommandHandler
  256. LLLoginHandler gLoginHandler;
  257. //virtual
  258. bool LLLoginHandler::handle(const LLSD&, const LLSD& query_map, LLMediaCtrl*)
  259. {
  260. LL_DEBUGS("Login") << "Parsing: " << ll_pretty_print_sd(query_map)
  261. << LL_ENDL;
  262. if (query_map.has("grid"))
  263. {
  264. LLGridManager* gm = LLGridManager::getInstance();
  265. gm->setGridChoice(query_map["grid"].asString());
  266. }
  267. std::string firstname = query_map["first_name"].asString();
  268. std::string lastname = query_map["last_name"].asString();
  269. std::string password = query_map["password"].asString();
  270. if (password.empty() && !firstname.empty() &&
  271. firstname == gLoginFirstName && lastname == gLoginLastName)
  272. {
  273. password = LLStartUp::getPasswordHashFromSettings();
  274. }
  275. std::string start_loc = query_map["location"].asString();
  276. if (start_loc == "specify")
  277. {
  278. LLStartUp::setStartSLURL(query_map["region"].asString());
  279. }
  280. else if (start_loc == "home")
  281. {
  282. gSavedSettings.setBool("LoginLastLocation", false);
  283. LLStartUp::setStartSLURL(LLSLURL(LLSLURL::SIM_LOCATION_HOME));
  284. }
  285. else if (start_loc == "last")
  286. {
  287. gSavedSettings.setBool("LoginLastLocation", true);
  288. LLStartUp::setStartSLURL(LLSLURL(LLSLURL::SIM_LOCATION_LAST));
  289. }
  290. if (LLStartUp::getStartupState() < STATE_LOGIN_CLEANUP) // On splash page
  291. {
  292. if (!firstname.empty())
  293. {
  294. // Fill in the name, and maybe the password
  295. LL_DEBUGS("Login") << "Using login credentials: User: "
  296. << firstname << " " << lastname
  297. #if LL_DEBUG_LOGIN_PASSWORD
  298. << " - Password hash: " << password
  299. #endif
  300. << LL_ENDL;
  301. LLPanelLogin::setFields(firstname, lastname, password);
  302. }
  303. LLPanelLogin::loadLoginPage();
  304. }
  305. return true;
  306. }
  307. ///////////////////////////////////////////////////////////////////////////////
  308. // LLStartUp class proper
  309. ///////////////////////////////////////////////////////////////////////////////
  310. //static
  311. void LLStartUp::applyUdpBlacklist(const std::string& csv)
  312. {
  313. std::string::size_type start = 0;
  314. std::string::size_type comma = 0;
  315. do
  316. {
  317. comma = csv.find(",", start);
  318. if (comma == std::string::npos)
  319. {
  320. comma = csv.length();
  321. }
  322. std::string item(csv, start, comma-start);
  323. LL_DEBUGS("AppInit") << "udp_blacklist " << item << LL_ENDL;
  324. gMessageSystemp->banUdpMessage(item);
  325. start = comma + 1;
  326. }
  327. while (comma < csv.length());
  328. }
  329. //static
  330. void LLStartUp::shutdownAudioEngine()
  331. {
  332. if (gAudiop)
  333. {
  334. llinfos << "Deleting existing audio engine instance" << llendl;
  335. // Shut down the streaming audio sub-subsystem first, in case it relies
  336. // on not outliving the general audio subsystem.
  337. LLStreamingAudioInterface* sai = gAudiop->getStreamingAudioImpl();
  338. delete sai;
  339. gAudiop->setStreamingAudioImpl(NULL);
  340. // Shut down the audio subsystem
  341. gAudiop->shutdown();
  342. delete gAudiop;
  343. gAudiop = NULL;
  344. }
  345. }
  346. //static
  347. void LLStartUp::startAudioEngine()
  348. {
  349. shutdownAudioEngine();
  350. if (gSavedSettings.getBool("NoAudio")) return;
  351. #if LL_FMOD
  352. if (!gAudiop && !gSavedSettings.getBool("AudioDisableFMOD"))
  353. {
  354. # if LL_LINUX
  355. LLAudioEngine_FMOD::sNoALSA =
  356. gSavedSettings.getBool("FMODDisableALSA");
  357. LLAudioEngine_FMOD::sNoPulseAudio =
  358. gSavedSettings.getBool("FMODDisablePulseAudio");
  359. # endif // LL_LINUX
  360. bool use_profiler = gSavedSettings.getBool("FMODProfilerEnable");
  361. gAudiop = (LLAudioEngine*)new LLAudioEngine_FMOD(use_profiler);
  362. }
  363. #endif // LL_FMOD
  364. #if LL_OPENAL
  365. if (!gAudiop && !gSavedSettings.getBool("AudioDisableOpenAL"))
  366. {
  367. gAudiop = (LLAudioEngine*)new LLAudioEngine_OpenAL();
  368. }
  369. #endif
  370. if (gAudiop)
  371. {
  372. #if LL_WINDOWS
  373. // FMOD Ex on Windows needs the window handle to stop playing audio
  374. // when window is minimized. JC
  375. void* window_handle = (HWND)gViewerWindowp->getPlatformWindow();
  376. #else
  377. void* window_handle = NULL;
  378. #endif
  379. bool init = gAudiop->init(window_handle);
  380. if (init)
  381. {
  382. LLViewerParcelMedia::registerStreamingAudioPlugin();
  383. }
  384. else
  385. {
  386. llwarns << "Unable to initialize audio engine" << llendl;
  387. delete gAudiop;
  388. gAudiop = NULL;
  389. }
  390. }
  391. if (gAudiop)
  392. {
  393. if (isLoggedIn())
  394. {
  395. setup_audio_listener();
  396. }
  397. llinfos << "Audio engine initialized." << llendl;
  398. }
  399. else
  400. {
  401. llwarns << "Failed to create an appropriate audio engine" << llendl;
  402. }
  403. }
  404. static void process_messages()
  405. {
  406. #if LL_USE_FIBER_AWARE_MUTEX
  407. LockMessageChecker lmc(gMessageSystemp);
  408. while (lmc.checkAllMessages(gFrameCount, gServicePumpIOp)) ;
  409. lmc.processAcks();
  410. #else
  411. LLMessageSystem* msg = gMessageSystemp;
  412. while (msg->checkAllMessages(gFrameCount, gServicePumpIOp)) ;
  413. msg->processAcks();
  414. #endif
  415. }
  416. static void call_force_quit()
  417. {
  418. gAppViewerp->forceQuit();
  419. }
  420. static void show_mfa_input(const LLSD&, const LLSD&)
  421. {
  422. LLPanelLogin::showTokenInputLine(true);
  423. }
  424. // Returns false to skip other idle processing. Should only return true when
  425. // all initializations are done.
  426. //static
  427. bool LLStartUp::idleStartup()
  428. {
  429. const F32 precaching_delay = gSavedSettings.getF32("PrecachingDelay");
  430. constexpr F32 TIMEOUT_SECONDS = 5.f;
  431. constexpr S32 MAX_TIMEOUT_COUNT = 3;
  432. constexpr F32 STATE_AGENT_WAIT_TIMEOUT = 240.f; // seconds
  433. constexpr U32 MAX_SEED_CAP_ATTEMPTS_BEFORE_LOGIN = 3;
  434. static LLTimer timeout;
  435. // Until this is encapsulated, this little hack for the auth/transform loop
  436. // will do.
  437. static F32 progress = 0.1f;
  438. static std::string auth_method, auth_desc, auth_message, password;
  439. static std::vector<const char*> requested_options;
  440. static U64 first_sim_handle = 0;
  441. static LLHost first_sim;
  442. static std::string first_sim_seed_cap;
  443. // Default for when no space server:
  444. static LLVector3 agent_start_position_region(10.f, 10.f, 10.f);
  445. static LLVector3 agent_start_look_at(1.0f, 0.f, 0.f);
  446. static std::string agent_start_location = "safe";
  447. // Last location by default
  448. static S32 agent_location_id = START_LOCATION_ID_LAST;
  449. static bool show_connect_box = true;
  450. static U32 first_region_size = (U32)REGION_WIDTH_METERS;
  451. static bool first_grid_login = false;
  452. // *HACK: these are things from the main loop that usually are not done
  453. // until initialization is complete, but need to be done here for things
  454. // to work.
  455. gIdleCallbacks.callFunctions();
  456. gViewerWindowp->handlePerFrameHover();
  457. LLMortician::updateClass();
  458. // Note: removing this line will cause incorrect button size in the login
  459. // screen. - Bao.
  460. gTextureList.updateImages(0.01f);
  461. LLGridManager* gm = LLGridManager::getInstance();
  462. if (getStartupState() == STATE_FIRST)
  463. {
  464. gViewerWindowp->showCursor();
  465. gWindowp->setCursor(UI_CURSOR_WAIT);
  466. #if LL_LINUX
  467. // *HACK: to compute window borders offsets. HB
  468. gWindowp->calculateBordersOffsets();
  469. #endif
  470. // Initialize stuff that does not need data from simulators
  471. S32 last_feature_version = gSavedSettings.getS32("LastFeatureVersion");
  472. if (gFeatureManager.isSafe())
  473. {
  474. gNotifications.add("DisplaySetToSafe");
  475. }
  476. else if (last_feature_version < gFeatureManager.getVersion() &&
  477. last_feature_version != 0)
  478. {
  479. gNotifications.add("DisplaySetToRecommended");
  480. }
  481. else if (!gViewerWindowp->getInitAlert().empty())
  482. {
  483. gNotifications.add(gViewerWindowp->getInitAlert());
  484. }
  485. // Init the SOCKS 5 proxy if the user has configured one. We need to do
  486. // this early in case the user is using SOCKS for HTTP so we get the
  487. // login screen and HTTP tables via SOCKS.
  488. startLLProxy();
  489. gSavedSettings.setS32("LastFeatureVersion",
  490. gFeatureManager.getVersion());
  491. std::string xml_file = LLUI::locateSkin("xui_version.xml");
  492. LLXMLNodePtr root;
  493. bool xml_ok = false;
  494. if (LLXMLNode::parseFile(xml_file, root, NULL))
  495. {
  496. if ((root->hasName("xui_version")))
  497. {
  498. std::string value = root->getValue();
  499. F32 version = 0.f;
  500. LLStringUtil::convertToF32(value, version);
  501. if (version >= 1.f)
  502. {
  503. xml_ok = true;
  504. }
  505. }
  506. }
  507. if (!xml_ok)
  508. {
  509. // If XML is bad, there is a large risk that notifications.xml
  510. // is ALSO bad. If that is so, then we will get a fatal error on
  511. // attempting to load it, which will display a non-translatable
  512. // error message that says so. Otherwise, we will display a
  513. // reasonable error message that IS translatable.
  514. gAppViewerp->earlyExit("BadInstallation");
  515. }
  516. // Statistics stuff
  517. // Load the throttle settings
  518. gViewerThrottle.load();
  519. // Initialize messaging system
  520. LL_DEBUGS("AppInit") << "Initializing messaging system..." << LL_ENDL;
  521. std::string msg_template_path =
  522. gDirUtil.getFullPath(LL_PATH_APP_SETTINGS, "message_template.msg");
  523. LLFILE* found_template = LLFile::open(msg_template_path, "r");
  524. if (found_template)
  525. {
  526. LLFile::close(found_template);
  527. U32 port = gSavedSettings.getU32("UserConnectionPort");
  528. // if nothing specified on command line (-port)
  529. if (port == NET_USE_OS_ASSIGNED_PORT &&
  530. gSavedSettings.getBool("ConnectionPortEnabled"))
  531. {
  532. port = gSavedSettings.getU32("ConnectionPort");
  533. }
  534. // *TODO: parameterize
  535. constexpr F32 HEARTBEAT_INTERVAL = 5;
  536. constexpr F32 TIMEOUT = 100;
  537. const LLUseCircuitCodeResponder* responder = NULL;
  538. if (!start_messaging_system(msg_template_path, port,
  539. LL_VERSION_MAJOR, LL_VERSION_MINOR,
  540. LL_VERSION_BRANCH, responder,
  541. HEARTBEAT_INTERVAL, TIMEOUT))
  542. {
  543. std::string diagnostic =
  544. llformat(" Error: %d", gMessageSystemp->getErrorCode());
  545. llwarns << diagnostic << llendl;
  546. gAppViewerp->earlyExit("LoginFailedNoNetwork",
  547. LLSD().with("DIAGNOSTIC", diagnostic));
  548. }
  549. LLMessageConfig::initClass(gDirUtil.getFullPath(LL_PATH_APP_SETTINGS));
  550. }
  551. else
  552. {
  553. gAppViewerp->earlyExit("MessageTemplateNotFound",
  554. LLSD().with("PATH", msg_template_path));
  555. }
  556. LLMessageSystem* msg = gMessageSystemp;
  557. if (msg && msg->isOK())
  558. {
  559. // Initialize all of the callbacks in case of bad message
  560. // system data
  561. msg->setExceptionFunc(MX_UNREGISTERED_MESSAGE,
  562. invalid_message_callback,
  563. NULL);
  564. msg->setExceptionFunc(MX_PACKET_TOO_SHORT,
  565. invalid_message_callback,
  566. NULL);
  567. #if 0 // Running off end of a packet is now valid in the case when a
  568. // reader has a newer message template than the sender
  569. msg->setExceptionFunc(MX_RAN_OFF_END_OF_PACKET,
  570. invalid_message_callback, NULL);
  571. #else
  572. msg->setExceptionFunc(MX_WROTE_PAST_BUFFER_SIZE,
  573. invalid_message_callback, NULL);
  574. #endif
  575. if (gSavedSettings.getBool("LogMessages"))
  576. {
  577. LL_DEBUGS("AppInit") << "Message logging activated !"
  578. << LL_ENDL;
  579. msg->startLogging();
  580. }
  581. // Start the xfer system.
  582. gXferManagerp = new LLXferManager();
  583. F32 xfer_throttle_bps = gSavedSettings.getF32("XferThrottle");
  584. if (xfer_throttle_bps >= 1.f)
  585. {
  586. gXferManagerp->setUseAckThrottling(true);
  587. gXferManagerp->setAckThrottleBPS(xfer_throttle_bps);
  588. }
  589. else
  590. {
  591. // By default, choke the downloads a lot...
  592. constexpr S32 VIEWER_MAX_XFER = 3;
  593. gXferManagerp->setMaxIncomingXfers(VIEWER_MAX_XFER);
  594. }
  595. gAssetStoragep = new LLViewerAssetStorage(msg, gXferManagerp);
  596. F32 bw = gSavedSettings.getF32("InBandwidth");
  597. if (bw >= 1.f)
  598. {
  599. llinfos << "Setting packetring incoming bandwidth to " << bw
  600. << " bps" << llendl;
  601. msg->mPacketRing.setUseInThrottle(true);
  602. msg->mPacketRing.setInBandwidth(bw);
  603. }
  604. bw = gSavedSettings.getF32("OutBandwidth");
  605. if (bw >= 1.f)
  606. {
  607. llinfos << "Setting packetring outgoing bandwidth to " << bw
  608. << " bps" << llendl;
  609. msg->mPacketRing.setUseOutThrottle(true);
  610. msg->mPacketRing.setOutBandwidth(bw);
  611. }
  612. // Now that gMessageSystemp is up, we can initialize the mute list:
  613. LLMuteList::initClass();
  614. }
  615. llinfos << "Message system initialized." << llendl;
  616. // Init audio, which may be needed for prefs dialog or audio cues in
  617. // connection UI.
  618. startAudioEngine();
  619. // Initialize the world class before we need it
  620. gWorld.initClass();
  621. // Log on to system
  622. if (gSavedSettings.getLLSD("UserLoginInfo").size() == 3)
  623. {
  624. LLSD cmd_line_login = gSavedSettings.getLLSD("UserLoginInfo");
  625. gLoginFirstName = cmd_line_login[0].asString();
  626. gLoginLastName = cmd_line_login[1].asString();
  627. LLMD5 pass((unsigned char*)cmd_line_login[2].asString().c_str());
  628. char md5pass[MD5HEX_STR_BYTES + 1];
  629. pass.hex_digest(md5pass);
  630. password = md5pass;
  631. show_connect_box = false;
  632. gSavedSettings.setBool("AutoLogin", true);
  633. llinfos << "Login credentials obtained from command line"
  634. << llendl;
  635. }
  636. else
  637. {
  638. gLoginFirstName = gSavedSettings.getString("FirstName");
  639. gLoginLastName = gSavedSettings.getString("LastName");
  640. gm->setGridChoice(gSavedSettings.getS32("ServerChoice"));
  641. password = getPasswordHashFromSettings();
  642. show_connect_box = !gSavedSettings.getBool("AutoLogin");
  643. llinfos << "Login credentials obtained from saved settings"
  644. << llendl;
  645. }
  646. LL_DEBUGS("Login") << "Using login credentials: User: "
  647. << gLoginFirstName << " " << gLoginLastName
  648. #if LL_DEBUG_LOGIN_PASSWORD
  649. << " - Password hash: " << password
  650. #endif
  651. << LL_ENDL;
  652. // Fall through immediately to the next state
  653. setStartupState(STATE_BROWSER_INIT);
  654. }
  655. if (getStartupState() == STATE_BROWSER_INIT)
  656. {
  657. std::string msg = LLTrans::getString("LoginInitializingBrowser");
  658. setStartupStatus(0.03f, msg, gAgent.mMOTD);
  659. display_startup();
  660. // Fall through immediately to the next state
  661. setStartupState(STATE_LOGIN_SHOW);
  662. // Initialize voice here too. HB
  663. LLVoiceChannel::initClass();
  664. gVoiceClient.init(gServicePumpIOp);
  665. }
  666. if (getStartupState() == STATE_LOGIN_SHOW)
  667. {
  668. gWindowp->setCursor(UI_CURSOR_ARROW);
  669. // Load URL History File for saved user. Needs to happen *before* login
  670. // panel is displayed.
  671. // Note: it only loads them if it can figure out the saved username.
  672. if (!gLoginFirstName.empty() && !gLoginLastName.empty())
  673. {
  674. gDirUtil.setLindenUserDir(gm->getGridLabel(), gLoginFirstName,
  675. gLoginLastName);
  676. LLFile::mkdir(gDirUtil.getLindenUserDir());
  677. LLURLHistory::loadFile("url_history.xml");
  678. }
  679. // Initialize all our tools. Must be done after saved settings loaded.
  680. gToolMgr.initTools();
  681. // Quickly get something onscreen to look at.
  682. gViewerWindowp->initWorldUI();
  683. if (show_connect_box)
  684. {
  685. // Make sure the progress dialog does not hide things
  686. gViewerWindowp->setShowProgress(false);
  687. // Show the login dialog.
  688. static bool first_attempt = true;
  689. bool have_loginuri = loginShow(first_attempt);
  690. if (first_attempt)
  691. {
  692. // Do not modify login credentials on subsequent attempts
  693. first_attempt = false;
  694. llinfos << "Setting default login credentials" << llendl;
  695. // Connect dialog is already shown, so fill in the names
  696. if (have_loginuri)
  697. {
  698. // We have either a login SLURL or a --loginuri on
  699. // command line that was not recognized as a known
  700. // login entry. Select it.
  701. LLPanelLogin::selectFirstElement();
  702. }
  703. else
  704. {
  705. LLPanelLogin::setFields(gLoginFirstName, gLoginLastName,
  706. password);
  707. LLPanelLogin::giveFocus();
  708. }
  709. }
  710. gSavedSettings.setBool("FirstRunThisInstall", false);
  711. if (gSavedSettings.getBool("FirstRunTPV"))
  712. {
  713. // Show the TPV agreement
  714. setStartupState(STATE_TPV_FIRST_USE);
  715. }
  716. else
  717. {
  718. // Wait for user input
  719. setStartupState(STATE_LOGIN_WAIT);
  720. }
  721. }
  722. else
  723. {
  724. // Skip directly to message template verification
  725. setStartupState(STATE_LOGIN_CLEANUP);
  726. }
  727. // If we got a secondlife:///app/login SLURL, dispatch it now
  728. if (sLoginSLURL.isValid())
  729. {
  730. LLMediaCtrl* web = NULL;
  731. LLURLDispatcher::dispatch(sLoginSLURL.getSLURLString(), "clicked",
  732. web, false);
  733. }
  734. gViewerWindowp->setNormalControlsVisible(false);
  735. gLoginMenuBarViewp->setVisible(true);
  736. gLoginMenuBarViewp->setEnabled(true);
  737. // Push our window frontmost
  738. gWindowp->show();
  739. display_startup();
  740. // DEV-16927. The following code removes errant keystrokes that happen
  741. // while the window is being first made visible.
  742. #ifdef _WIN32
  743. MSG msg;
  744. // All hWnds owned by this thread
  745. while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
  746. #endif
  747. timeout.reset();
  748. return false;
  749. }
  750. if (getStartupState() == STATE_TPV_FIRST_USE)
  751. {
  752. setStartupState(STATE_UPDATE_CHECK);
  753. LLFloaterTOS::show(LLFloaterTOS::TOS_FIRST_TPV_USE);
  754. gFrameSleepTime = 10; // Do not hog the CPU
  755. return false;
  756. }
  757. if (getStartupState() == STATE_LOGIN_WAIT)
  758. {
  759. // Do not do anything. Wait for the login view to call the
  760. // loginCallback(), which will push us to the next state.
  761. gFrameSleepTime = 10; // Do not hog the CPU
  762. return false;
  763. }
  764. if (getStartupState() == STATE_LOGIN_CLEANUP)
  765. {
  766. // Post login screen, we should see if any settings have changed that
  767. // may require us to either start/stop or change the socks proxy.
  768. // As various communications past this point may require the proxy to
  769. // be up.
  770. gFrameSleepTime = 1;
  771. if (!startLLProxy())
  772. {
  773. // Proxy start up failed, we should now bail the state machine
  774. // startLLProxy() will have reported an error to the user already,
  775. // so we just go back to the login screen. The user could then
  776. // change the preferences to fix the issue.
  777. setStartupState(STATE_LOGIN_SHOW);
  778. return false;
  779. }
  780. if (show_connect_box)
  781. {
  782. // Load all the name information out of the login view
  783. LLPanelLogin::getFields(gLoginFirstName, gLoginLastName, password);
  784. // *HACK: try to make not jump on login
  785. if (gKeyboardp)
  786. {
  787. gKeyboardp->resetKeys();
  788. }
  789. }
  790. if (!gLoginFirstName.empty() && !gLoginLastName.empty())
  791. {
  792. llinfos << "Attempting login as: " << gLoginFirstName << " "
  793. << gLoginLastName << llendl;
  794. gDebugInfo["LoginName"] = gLoginFirstName + " " + gLoginLastName;
  795. }
  796. // Create necessary directories. *FIXME: these mkdir should error check
  797. const std::string grid_label = gm->getGridLabel();
  798. gDirUtil.setLindenUserDir(grid_label, gLoginFirstName, gLoginLastName);
  799. LLFile::mkdir(gDirUtil.getLindenUserDir());
  800. // Set PerAccountSettingsFile to the default value.
  801. std::string fname = gAppViewerp->getSettingsFilename("Account",
  802. "PerAccount");
  803. fname = gDirUtil.getFullPath(LL_PATH_PER_ACCOUNT, fname);
  804. gSavedSettings.setString("PerAccountSettingsFile", fname);
  805. // Overwrite default user settings with user settings
  806. gAppViewerp->loadSettingsFromDirectory("Account");
  807. // Need to set the LastLogoff time here if we don't have one.
  808. // LastLogoff is used for "Recent Items" calculation and startup time
  809. // is close enough if we don't have a real value.
  810. if (gSavedPerAccountSettings.getU32("LastLogoff") == 0)
  811. {
  812. first_grid_login = true;
  813. gSavedPerAccountSettings.setU32("LastLogoff", time_corrected());
  814. }
  815. // Recover RestrainedLove's per-account settings.
  816. RLInterface::usePerAccountSettings();
  817. // Default the path if one is not set.
  818. std::string im_logs_path =
  819. gSavedPerAccountSettings.getString("InstantMessageLogPath");
  820. if (im_logs_path.empty())
  821. {
  822. gDirUtil.setChatLogsDir(gDirUtil.getOSUserAppDir());
  823. gSavedPerAccountSettings.setString("InstantMessageLogPath",
  824. gDirUtil.getChatLogsDir());
  825. }
  826. else
  827. {
  828. gDirUtil.setChatLogsDir(im_logs_path);
  829. }
  830. gDirUtil.setPerAccountChatLogsDir(gm->getGridLabel(), gLoginFirstName,
  831. gLoginLastName);
  832. LLFile::mkdir(gDirUtil.getChatLogsDir());
  833. LLFile::mkdir(gDirUtil.getPerAccountChatLogsDir());
  834. // Good as place as any to create user windlight directories
  835. std::string wl_path = gDirUtil.getFullPath(LL_PATH_USER_SETTINGS,
  836. "windlight", "");
  837. LLFile::mkdir(wl_path.c_str());
  838. std::string wl_skies_path = gDirUtil.getFullPath(LL_PATH_USER_SETTINGS,
  839. "windlight", "skies",
  840. "");
  841. LLFile::mkdir(wl_skies_path.c_str());
  842. std::string wl_water_path = gDirUtil.getFullPath(LL_PATH_USER_SETTINGS,
  843. "windlight", "water",
  844. "");
  845. LLFile::mkdir(wl_water_path.c_str());
  846. std::string wl_days_path = gDirUtil.getFullPath(LL_PATH_USER_SETTINGS,
  847. "windlight", "days",
  848. "");
  849. LLFile::mkdir(wl_days_path.c_str());
  850. if (show_connect_box)
  851. {
  852. LLPanelLogin::hide();
  853. }
  854. // Load URL History File
  855. LLURLHistory::loadFile("url_history.xml");
  856. //-------------------------------------------------
  857. // Handle startup progress screen
  858. //-------------------------------------------------
  859. // On startup the user can request to go to their home, their last
  860. // location, or some URL "--url //sim/x/y[/z]". All accounts have both
  861. // a home and a last location, and we do not support more locations
  862. // than that. Choose the appropriate one. JC
  863. switch (getStartSLURL().getType())
  864. {
  865. case LLSLURL::LOCATION:
  866. agent_location_id = START_LOCATION_ID_URL;
  867. break;
  868. case LLSLURL::LAST_LOCATION:
  869. agent_location_id = START_LOCATION_ID_LAST;
  870. break;
  871. case LLSLURL::HOME_LOCATION:
  872. agent_location_id = START_LOCATION_ID_HOME;
  873. break;
  874. default:
  875. if (gSavedSettings.getBool("LoginLastLocation"))
  876. {
  877. agent_location_id = START_LOCATION_ID_LAST;
  878. setStartSLURL(LLSLURL(LLSLURL::SIM_LOCATION_LAST));
  879. }
  880. else
  881. {
  882. agent_location_id = START_LOCATION_ID_HOME;
  883. setStartSLURL(LLSLURL(LLSLURL::SIM_LOCATION_HOME));
  884. }
  885. }
  886. //MK
  887. if (gRLenabled &&
  888. !gSavedPerAccountSettings.getBool("RestrainedLoveTPOK"))
  889. {
  890. gSavedSettings.setBool("LoginLastLocation", true);
  891. // Always last location (actually ignore list)
  892. agent_location_id = START_LOCATION_ID_LAST;
  893. setStartSLURL(LLSLURL(LLSLURL::SIM_LOCATION_LAST));
  894. }
  895. //mk
  896. gWindowp->setCursor(UI_CURSOR_WAIT);
  897. initStartScreen(agent_location_id);
  898. // Display the startup progress bar.
  899. gViewerWindowp->setShowProgress(true);
  900. // *TODO: Translate
  901. const std::string label = "Quit";
  902. gViewerWindowp->setProgressCancelButtonVisible(true, label);
  903. // Skipping over STATE_UPDATE_CHECK because that just waits for input
  904. setStartupState(STATE_LOGIN_AUTH_INIT);
  905. return false;
  906. }
  907. if (getStartupState() == STATE_UPDATE_CHECK)
  908. {
  909. // Wait for user to give input via dialog box
  910. gFrameSleepTime = 10; // Do not hog the CPU
  911. return false;
  912. }
  913. if (getStartupState() == STATE_LOGIN_AUTH_INIT)
  914. {
  915. gFrameSleepTime = 1;
  916. gDebugInfo["GridName"] = gm->getGridLabel();
  917. requested_options.clear();
  918. requested_options.emplace_back("inventory-root");
  919. requested_options.emplace_back("inventory-skeleton");
  920. requested_options.emplace_back("inventory-lib-root");
  921. requested_options.emplace_back("inventory-lib-owner");
  922. requested_options.emplace_back("inventory-skel-lib");
  923. #if 0 // Never used but always kept commented out in LL's sources... HB
  924. requested_options.emplace_back("inventory-skel-targets");
  925. requested_options.emplace_back("inventory-targets");
  926. requested_options.emplace_back("inventory-meat");
  927. requested_options.emplace_back("inventory-meat-lib");
  928. #endif
  929. requested_options.emplace_back("agent_appearance_service");
  930. requested_options.emplace_back("initial-outfit");
  931. requested_options.emplace_back("gestures");
  932. requested_options.emplace_back("event_categories");
  933. requested_options.emplace_back("event_notifications");
  934. requested_options.emplace_back("classified_categories");
  935. requested_options.emplace_back("adult_compliant");
  936. requested_options.emplace_back("buddy-list");
  937. requested_options.emplace_back("ui-config");
  938. requested_options.emplace_back("max_groups"); // OpenSim
  939. requested_options.emplace_back("max-agent-groups"); // SL
  940. requested_options.emplace_back("map-server-url");
  941. requested_options.emplace_back("search-server-url"); // OpenSim
  942. requested_options.emplace_back("voice-config");
  943. requested_options.emplace_back("login-flags");
  944. requested_options.emplace_back("global-textures");
  945. if (gSavedSettings.getBool("ConnectAsGod"))
  946. {
  947. requested_options.emplace_back("god-connect");
  948. }
  949. // Hopefully, LL will, some time, implement this suggestion of mine to
  950. // restore the compatibility with old SL clients missing LLSD array
  951. // support in XML RPC replies... HB
  952. requested_options.emplace_back("account_level_benefits");
  953. auth_method = "login_to_simulator";
  954. LLStringUtil::format_map_t args;
  955. args["[APP_NAME]"] = gSecondLife;
  956. auth_desc = LLTrans::getString("LoginInProgressWait", args);
  957. setStartupState(STATE_XMLRPC_LOGIN);
  958. }
  959. if (getStartupState() == STATE_XMLRPC_LOGIN)
  960. {
  961. gFrameSleepTime = 1;
  962. progress += 0.02f;
  963. display_startup();
  964. std::stringstream start;
  965. //MK
  966. if (gRLenabled &&
  967. !gSavedPerAccountSettings.getBool("RestrainedLoveTPOK"))
  968. {
  969. setStartSLURL(LLSLURL(LLSLURL::SIM_LOCATION_LAST));
  970. }
  971. //mk
  972. LLSLURL start_slurl = getStartSLURL();
  973. LLSLURL::eType start_slurl_type = start_slurl.getType();
  974. switch (start_slurl_type)
  975. {
  976. case LLSLURL::LOCATION:
  977. {
  978. // A startup URL was specified
  979. std::stringstream unescaped_start;
  980. unescaped_start << "uri:"
  981. << start_slurl.getRegion() << "&"
  982. << start_slurl.getPosition().mV[VX] << "&"
  983. << start_slurl.getPosition().mV[VY] << "&"
  984. << start_slurl.getPosition().mV[VZ];
  985. start << xml_escape_string(unescaped_start.str());
  986. break;
  987. }
  988. case LLSLURL::HOME_LOCATION:
  989. start << "home";
  990. gSavedSettings.setBool("LoginLastLocation", false);
  991. break;
  992. case LLSLURL::LAST_LOCATION:
  993. start << "last";
  994. gSavedSettings.setBool("LoginLastLocation", true);
  995. break;
  996. default:
  997. break;
  998. }
  999. std::string grid_uri = gm->getGridURI();
  1000. llinfos << "Authenticating with " << grid_uri << llendl;
  1001. // Determine whether we are connecting to SL or not
  1002. gm->setIsInSecondlife();
  1003. // Set some URLs for LLXMLRPCTransaction, part of the llmessage library
  1004. bool use_mfa;
  1005. if (gIsInSecondLife)
  1006. {
  1007. // MFA support is required now in SL, when the user configured
  1008. // their account to use it. HB
  1009. use_mfa = true;
  1010. LLXMLRPCTransaction::setSupportURL(SUPPORT_URL);
  1011. LLXMLRPCTransaction::setWebsiteURL(SL_GRID_STATUS_URL);
  1012. }
  1013. else
  1014. {
  1015. use_mfa = gSavedSettings.getBool("UseMFAinOS");
  1016. std::string url = gm->getSupportURL();
  1017. if (url.empty())
  1018. {
  1019. url = gm->getWebsiteURL();
  1020. }
  1021. LLXMLRPCTransaction::setSupportURL(url);
  1022. LLXMLRPCTransaction::setWebsiteURL(gm->getWebsiteURL());
  1023. }
  1024. std::string mfa_hash, mfa_token;
  1025. if (use_mfa)
  1026. {
  1027. mfa_hash = getMFAHashFromSettings();
  1028. mfa_token = LLPanelLogin::getToken();
  1029. #if LL_DEBUG_LOGIN_PASSWORD
  1030. LL_DEBUGS("Login") << "MFA hash: " << mfa_hash << " - MFA token: "
  1031. << mfa_token << LL_ENDL;
  1032. #endif
  1033. }
  1034. else
  1035. {
  1036. // Clear any remembered MFA hash
  1037. gSavedPerAccountSettings.setString("MFAHash", "");
  1038. }
  1039. gUserAuth.setMFA(use_mfa, mfa_hash, mfa_token);
  1040. gUserAuth.authenticate(grid_uri, auth_method, gLoginFirstName,
  1041. gLoginLastName, password, start.str(),
  1042. true, gAcceptTOS, gAcceptCriticalMessage,
  1043. gLastExecEvent, requested_options);
  1044. // Set the flag for marking wearable textures as no-delete in OpenSim.
  1045. LLLocalTextureObject::sMarkNoDelete = !gIsInSecondLife;
  1046. // Adjust the prim parameters limits according to the grid's.
  1047. LLPrimitive::setLimits(gIsInSecondLife);
  1048. // In OpenSim, ignore bad ratio in volume params
  1049. LLVolumeMessage::sIgnoreBadRatio = !gIsInSecondLife;
  1050. if (!gIsInSecondLife)
  1051. {
  1052. // In OpenSim, use larger max mag for octrees
  1053. gOctreeMaxMag.splat(4096.f * 4096.f);
  1054. // Use a separate bandwidth setting too (workaround for a
  1055. // server-side overflow bug).
  1056. // This second call to gViewerThrottle.load() will update the
  1057. // bandwidth setting accordingly to gIsInSecondLife value. HB
  1058. gViewerThrottle.load();
  1059. // Add a 60s timeout for untrusted messages in OpenSim, but not
  1060. // when running under Wine which got a bug causing HTTP failures
  1061. // when touching the retries and timeouts. HB
  1062. #if LL_WINDOWS
  1063. if (!gAppViewerp->isRunningUnderWine())
  1064. #endif
  1065. {
  1066. gMessageSystemp->setHttpOptionsWithTimeout(60);
  1067. }
  1068. }
  1069. // Load script functions symbols common to all grids
  1070. LLPreviewScript::loadFunctions("lsl_functions_sl.xml");
  1071. if (!gIsInSecondLife)
  1072. {
  1073. // Load script functions symbols specific to OpenSim/Aurora
  1074. LLPreviewScript::loadFunctions("lsl_functions_os.xml");
  1075. }
  1076. // Adjust HTTP pipelining if needed
  1077. gAppViewerp->getAppCoreHttp().refreshSettings();
  1078. // Allow face wrinkles in OpenSim, i.e. where we can bake them...
  1079. LLTexLayerSet::sAllowFaceWrinkles = !gIsInSecondLife;
  1080. // Allow large texture bakes in OpenSim grids configured for it.
  1081. if (gIsInSecondLife)
  1082. {
  1083. LLControlVariable* controlp =
  1084. gSavedPerAccountSettings.getControl("OSUseLargeAvatarBakes");
  1085. if (controlp)
  1086. {
  1087. controlp->setHiddenFromUser(true);
  1088. }
  1089. }
  1090. else
  1091. {
  1092. LLTexLayerSetInfo::sUseLargeBakes =
  1093. gSavedPerAccountSettings.getBool("OSUseLargeAvatarBakes");
  1094. }
  1095. // Initialize the object cache now that we know which grid we are
  1096. // connected to
  1097. U32 max_size = gSavedSettings.getU32("CacheNumberOfRegionsForObjects");
  1098. LLVOCache::getInstance()->initCache(LL_PATH_CACHE, max_size);
  1099. setStartupState(STATE_LOGIN_NO_DATA_YET);
  1100. return false;
  1101. }
  1102. if (getStartupState() == STATE_LOGIN_NO_DATA_YET)
  1103. {
  1104. LL_DEBUGS_ONCE("AppInit") << "STATE_LOGIN_NO_DATA_YET" << LL_ENDL;
  1105. // If we get here we have gotten past the potential stall in curl, so
  1106. // take "may appear frozen" out of progress bar. JC
  1107. auth_desc = LLTrans::getString("LoginInProgress");
  1108. setStartupStatus(progress, auth_desc, auth_message);
  1109. // Process messages to keep from dropping circuit.
  1110. process_messages();
  1111. LLUserAuth::UserAuthcode error = gUserAuth.authResponse();
  1112. if (LLUserAuth::E_NO_RESPONSE_YET == error)
  1113. {
  1114. LL_DEBUGS_ONCE("AppInit") << "waiting..." << LL_ENDL;
  1115. gFrameSleepTime = 10; // Do not hog the CPU
  1116. return false;
  1117. }
  1118. gFrameSleepTime = 1;
  1119. setStartupState(STATE_LOGIN_DOWNLOADING);
  1120. progress += 0.01f;
  1121. setStartupStatus(progress, auth_desc, auth_message);
  1122. return false;
  1123. }
  1124. if (getStartupState() == STATE_LOGIN_DOWNLOADING)
  1125. {
  1126. // Process messages to keep from dropping circuit.
  1127. process_messages();
  1128. LLUserAuth::UserAuthcode error = gUserAuth.authResponse();
  1129. if (LLUserAuth::E_DOWNLOADING == error)
  1130. {
  1131. LL_DEBUGS("AppInit") << "Downloading..." << LL_ENDL;
  1132. gFrameSleepTime = 10; // Do not hog the CPU
  1133. return false;
  1134. }
  1135. gFrameSleepTime = 1;
  1136. setStartupState(STATE_LOGIN_PROCESS_RESPONSE);
  1137. progress += 0.01f;
  1138. setStartupStatus(progress,
  1139. LLTrans::getString("LoginProcessingResponse"),
  1140. auth_message);
  1141. return false;
  1142. }
  1143. if (getStartupState() == STATE_LOGIN_PROCESS_RESPONSE)
  1144. {
  1145. gFrameSleepTime = 1;
  1146. std::ostringstream emsg;
  1147. bool notify_user = true; // Notify when login error happens
  1148. bool quit = false;
  1149. bool successful_login = false;
  1150. std::string login_response, reason_response, message_response;
  1151. LLUserAuth::UserAuthcode error = gUserAuth.authResponse();
  1152. switch (error)
  1153. {
  1154. case LLUserAuth::E_OK:
  1155. login_response = gUserAuth.getResponseStr("login");
  1156. if (login_response == "true")
  1157. {
  1158. // Yay, login !
  1159. successful_login = true;
  1160. }
  1161. else if (login_response == "indeterminate")
  1162. {
  1163. llinfos << "Indeterminate login..." << llendl;
  1164. gm->setGridURI(gUserAuth.getResponseStr("next_url"));
  1165. auth_method = gUserAuth.getResponseStr("next_method");
  1166. auth_message = gUserAuth.getResponseStr("message");
  1167. if (auth_method.substr(0, 5) == "login")
  1168. {
  1169. auth_desc.assign(LLTrans::getString("LoginAuthenticating"));
  1170. }
  1171. else
  1172. {
  1173. auth_desc.assign(LLTrans::getString("LoginMaintenance"));
  1174. }
  1175. setStartupState(STATE_XMLRPC_LOGIN);
  1176. return false;
  1177. }
  1178. else
  1179. {
  1180. emsg << "Login failed.\n";
  1181. reason_response = gUserAuth.getResponseStr("reason");
  1182. message_response = gUserAuth.getResponseStr("message");
  1183. if (!message_response.empty())
  1184. {
  1185. // *TODO: fix translation for strings returned during
  1186. // login. We need a generic table for translations.
  1187. std::string big_reason =
  1188. LLAgent::sTeleportErrorMessages[message_response];
  1189. if (big_reason.empty())
  1190. {
  1191. emsg << message_response;
  1192. }
  1193. else
  1194. {
  1195. emsg << big_reason;
  1196. }
  1197. }
  1198. if (reason_response == "tos")
  1199. {
  1200. if (show_connect_box)
  1201. {
  1202. LL_DEBUGS("AppInit") << "Need tos agreement"
  1203. << LL_ENDL;
  1204. setStartupState(STATE_UPDATE_CHECK);
  1205. LLFloaterTOS::show(LLFloaterTOS::TOS_TOS,
  1206. message_response);
  1207. gFrameSleepTime = 10; // Do not hog the CPU
  1208. return false;
  1209. }
  1210. else
  1211. {
  1212. quit = true;
  1213. }
  1214. }
  1215. else if (reason_response == "critical")
  1216. {
  1217. if (show_connect_box)
  1218. {
  1219. LL_DEBUGS("AppInit") << "Need critical message"
  1220. << LL_ENDL;
  1221. setStartupState(STATE_UPDATE_CHECK);
  1222. LLFloaterTOS::show(LLFloaterTOS::TOS_CRITICAL_MESSAGE,
  1223. message_response);
  1224. return false;
  1225. }
  1226. else
  1227. {
  1228. quit = true;
  1229. }
  1230. }
  1231. else if (reason_response == "key")
  1232. {
  1233. // Could not login because user/password is wrong.
  1234. password.clear(); // Clear the password
  1235. }
  1236. else if (reason_response == "mfa_challenge")
  1237. {
  1238. // Login failed because the MFA hash is wrong or missing...
  1239. // A new MFA challenge is being performed on a third party
  1240. // device or web site (or hopefully soon, via email), and
  1241. // the user will get a token that they will need to provide
  1242. // us with: enable the MFA token entry on the login screen,
  1243. // and inform the user that they must fill it up before
  1244. // they can try and log in again. HB
  1245. notify_user = false; // We use our own notification...
  1246. gNotifications.add("MFAChallengeRequired", LLSD(), LLSD(),
  1247. show_mfa_input);
  1248. // We also force-enable the MFA usage variable; if we got
  1249. // this login failure response from the login server, then
  1250. // MFA support is/became required on this grid ! HB
  1251. if (!gIsInSecondLife) // Always required in SL already
  1252. {
  1253. gSavedSettings.setBool("UseMFAinOS", true);
  1254. }
  1255. }
  1256. else if (reason_response == "update")
  1257. {
  1258. auth_message = gUserAuth.getResponseStr("message");
  1259. LLSD args;
  1260. args["MESSAGE"] = "(" + auth_message + ")";
  1261. gNotifications.add("NeedUpdate", args);
  1262. setStartupState(STATE_UPDATE_CHECK);
  1263. return false;
  1264. }
  1265. }
  1266. break;
  1267. case LLUserAuth::E_COULDNT_RESOLVE_HOST:
  1268. case LLUserAuth::E_SSL_PEER_CERTIFICATE:
  1269. case LLUserAuth::E_UNHANDLED_ERROR:
  1270. case LLUserAuth::E_SSL_CACERT:
  1271. case LLUserAuth::E_SSL_CONNECT_ERROR:
  1272. default:
  1273. emsg << "Unable to connect to the grid.\n";
  1274. emsg << gUserAuth.errorMessage();
  1275. }
  1276. if (quit)
  1277. {
  1278. gUserAuth.reset();
  1279. gAppViewerp->forceQuit();
  1280. return false;
  1281. }
  1282. // XML-RPC successful login
  1283. if (successful_login)
  1284. {
  1285. std::string text = gUserAuth.getResponseStr("udp_blacklist");
  1286. if (!text.empty())
  1287. {
  1288. applyUdpBlacklist(text);
  1289. }
  1290. // Get "agent benefits" stuff, if present.
  1291. const LLSD& benefits =
  1292. gUserAuth.getResponse("account_level_benefits");
  1293. if (benefits.isDefined())
  1294. {
  1295. std::string account_type = "Base";
  1296. const LLSD& account = gUserAuth.getResponse("account_type");
  1297. if (account.isDefined())
  1298. {
  1299. account_type = account.asString();
  1300. }
  1301. LLEconomy::getInstance()->setBenefits(benefits, account_type);
  1302. update_upload_costs_in_menus();
  1303. }
  1304. // Unpack login data needed by the application
  1305. text = gUserAuth.getResponseStr("agent_id");
  1306. if (text.empty())
  1307. {
  1308. emsg << "Login failed.\nMissing agent Id !";
  1309. }
  1310. else
  1311. {
  1312. gAgentID.set(text);
  1313. gDebugInfo["AgentID"] = text;
  1314. }
  1315. text = gUserAuth.getResponseStr("session_id");
  1316. if (text.empty())
  1317. {
  1318. if (gAgentID.notNull())
  1319. {
  1320. emsg << "Login failed.\nMissing agent session Id !";
  1321. }
  1322. }
  1323. else
  1324. {
  1325. gAgentSessionID.set(text);
  1326. gDebugInfo["SessionID"] = text;
  1327. }
  1328. text = gUserAuth.getResponseStr("secure_session_id");
  1329. if (text.empty())
  1330. {
  1331. llwarns << "Missing secure agent session Id. Asset uploads will fail !"
  1332. << llendl;
  1333. }
  1334. else
  1335. {
  1336. gAgent.mSecureSessionID.set(text);
  1337. }
  1338. text = gUserAuth.getResponseStr("first_name");
  1339. if (!text.empty())
  1340. {
  1341. // Remove quotes from string. Login.cgi sends these to force
  1342. // names that look like numbers into strings.
  1343. gLoginFirstName = text;
  1344. LLStringUtil::replaceChar(gLoginFirstName, '"', ' ');
  1345. LLStringUtil::trim(gLoginFirstName);
  1346. }
  1347. text = gUserAuth.getResponseStr("last_name");
  1348. if (!text.empty())
  1349. {
  1350. gLoginLastName = text;
  1351. }
  1352. // Touch the login data only if we logged in from the login screen
  1353. // and if we are not a second Cool VL Viewer instance (else the
  1354. // risk is that the saved login name is reused for the wrong grid
  1355. // next time).
  1356. if (show_connect_box &&
  1357. !gAppViewerp->isSecondInstanceSiblingViewer())
  1358. {
  1359. // Load the current saved grids logins data
  1360. std::string history_file =
  1361. gDirUtil.getFullPath(LL_PATH_USER_SETTINGS,
  1362. "saved_grids_login.xml");
  1363. LLSavedLogins history_data =
  1364. LLSavedLogins::loadFile(history_file);
  1365. // Delete any old matching entry in the grids logins
  1366. EGridInfo grid_choice = gm->getGridChoice();
  1367. history_data.deleteEntry(grid_choice, gLoginFirstName,
  1368. gLoginLastName, gm->getGridURI());
  1369. if (gSavedSettings.getBool("RememberLogin"))
  1370. {
  1371. // Successful login means the credentails are valid, so
  1372. // save them
  1373. gSavedSettings.setString("FirstName", gLoginFirstName);
  1374. gSavedSettings.setString("LastName", gLoginLastName);
  1375. savePasswordHashToSettings(password);
  1376. // Add our credentials to the saved grids logins
  1377. LLSavedLoginEntry login_entry(grid_choice, gLoginFirstName,
  1378. gLoginLastName, password);
  1379. if (grid_choice == GRID_INFO_OTHER)
  1380. {
  1381. std::string grid_uri = gm->getGridURI();
  1382. if (!grid_uri.empty())
  1383. {
  1384. login_entry.setGridURI(LLURI(grid_uri));
  1385. }
  1386. std::string login_uri = gm->getLoginPageURI();
  1387. if (!login_uri.empty())
  1388. {
  1389. login_entry.setLoginPageURI(LLURI(login_uri));
  1390. }
  1391. std::string helper_uri = gm->getHelperURI();
  1392. if (!helper_uri.empty())
  1393. {
  1394. login_entry.setHelperURI(LLURI(helper_uri));
  1395. }
  1396. }
  1397. history_data.addEntry(login_entry);
  1398. // Reassert and save our grid choice
  1399. gm->setGridChoice(gm->getGridChoice());
  1400. text = gUserAuth.getResponseStr("mfa_hash");
  1401. if (!text.empty())
  1402. {
  1403. saveMFAHashToSettings(text);
  1404. }
  1405. llinfos << "Saved this successful login info." << llendl;
  1406. }
  1407. else
  1408. {
  1409. // Clear any last login data.
  1410. gSavedSettings.setString("FirstName", "");
  1411. gSavedSettings.setString("LastName", "");
  1412. gSavedSettings.setString("HashedPassword", "");
  1413. gSavedPerAccountSettings.setString("MFAHash", "");
  1414. }
  1415. // Save back the login history data to disk
  1416. LLSavedLogins::saveFile(history_data, history_file);
  1417. }
  1418. // This is their actual ability to access content
  1419. text = gUserAuth.getResponseStr("agent_access_max");
  1420. if (!text.empty())
  1421. {
  1422. // agent_access can be 'A', 'M', and 'PG'.
  1423. gAgent.setMaturity(text[0]);
  1424. }
  1425. // This is the value of their preference setting for that content
  1426. // which will always be <= agent_access_max
  1427. text = gUserAuth.getResponseStr("agent_region_access");
  1428. if (!text.empty())
  1429. {
  1430. U8 preferredMaturity = LLAgent::convertTextToMaturity(text[0]);
  1431. gSavedSettings.setU32("PreferredMaturity", preferredMaturity);
  1432. }
  1433. text = gUserAuth.getResponseStr("start_location");
  1434. if (!text.empty()) agent_start_location.assign(text);
  1435. text = gUserAuth.getResponseStr("circuit_code");
  1436. if (!text.empty())
  1437. {
  1438. gMessageSystemp->mOurCircuitCode = strtoul(text.c_str(), NULL,
  1439. 10);
  1440. }
  1441. std::string sim_ip_str = gUserAuth.getResponseStr("sim_ip");
  1442. std::string sim_port_str = gUserAuth.getResponseStr("sim_port");
  1443. if (!sim_ip_str.empty() && !sim_port_str.empty())
  1444. {
  1445. U32 sim_port = strtoul(sim_port_str.c_str(), NULL, 10);
  1446. first_sim.set(sim_ip_str, sim_port);
  1447. if (first_sim.isOk())
  1448. {
  1449. gMessageSystemp->enableCircuit(first_sim, true);
  1450. }
  1451. }
  1452. std::string region_x_str = gUserAuth.getResponseStr("region_x");
  1453. std::string region_y_str = gUserAuth.getResponseStr("region_y");
  1454. if (!region_x_str.empty() && !region_y_str.empty())
  1455. {
  1456. U32 region_x = strtoul(region_x_str.c_str(), NULL, 10);
  1457. U32 region_y = strtoul(region_y_str.c_str(), NULL, 10);
  1458. first_sim_handle = to_region_handle(region_x, region_y);
  1459. }
  1460. // Variable region size support
  1461. region_x_str = gUserAuth.getResponseStr("region_size_x");
  1462. if (!region_x_str.empty())
  1463. {
  1464. first_region_size = atoi(region_x_str.c_str());
  1465. if (first_region_size == 0)
  1466. {
  1467. first_region_size = REGION_WIDTH_METERS;
  1468. }
  1469. }
  1470. // Let's assume regions are square
  1471. U32 region_y_size = first_region_size;
  1472. region_y_str = gUserAuth.getResponseStr("region_size_y");
  1473. if (!region_y_str.empty())
  1474. {
  1475. region_y_size = atoi(region_y_str.c_str());
  1476. if (region_y_size == 0)
  1477. {
  1478. region_y_size = first_region_size;
  1479. }
  1480. }
  1481. if (first_region_size != region_y_size)
  1482. {
  1483. llwarns << "RECTANGULAR REGIONS NOT SUPPORTED: expect a crash !"
  1484. << llendl;
  1485. first_region_size = llmax(first_region_size, region_y_size);
  1486. }
  1487. gViewerParcelMgr.setRegionWidth(first_region_size);
  1488. std::string look_at_str = gUserAuth.getResponseStr("look_at");
  1489. if (!look_at_str.empty())
  1490. {
  1491. size_t len = look_at_str.size();
  1492. LLMemoryStream mstr((U8*)look_at_str.c_str(), len);
  1493. LLSD sd = LLSDSerialize::fromNotation(mstr, len);
  1494. agent_start_look_at = ll_vector3_from_sd(sd);
  1495. }
  1496. text = gUserAuth.getResponseStr("seed_capability");
  1497. if (!text.empty())
  1498. {
  1499. first_sim_seed_cap = text;
  1500. }
  1501. text = gUserAuth.getResponseStr("seconds_since_epoch");
  1502. if (!text.empty())
  1503. {
  1504. U32 server_utc_time = strtoul(text.c_str(), NULL, 10);
  1505. if (server_utc_time)
  1506. {
  1507. time_t now = time(NULL);
  1508. gUTCOffset = server_utc_time - now;
  1509. llinfos << "UTC offset with server: " << gUTCOffset << "s"
  1510. << llendl;
  1511. }
  1512. }
  1513. std::string home_location = gUserAuth.getResponseStr("home");
  1514. if (!home_location.empty())
  1515. {
  1516. size_t len = home_location.size();
  1517. LLMemoryStream mstr((U8*)home_location.c_str(), len);
  1518. LLSD sd = LLSDSerialize::fromNotation(mstr, len);
  1519. S32 region_x = sd["region_handle"][0].asInteger();
  1520. S32 region_y = sd["region_handle"][1].asInteger();
  1521. U64 region_handle = to_region_handle(region_x, region_y);
  1522. LLVector3 position = ll_vector3_from_sd(sd["position"]);
  1523. gAgent.setHomePosRegion(region_handle, position);
  1524. }
  1525. gAgent.mMOTD.assign(gUserAuth.getResponseStr("message"));
  1526. const LLSD& inventory_root =
  1527. gUserAuth.getResponse1stMap("inventory-root");
  1528. if (inventory_root.isDefined() && inventory_root.has("folder_id"))
  1529. {
  1530. LLUUID inv_root_folder_id =
  1531. inventory_root["folder_id"].asUUID();
  1532. gInventory.setRootFolderID(inv_root_folder_id);
  1533. }
  1534. const LLSD& login_flags =
  1535. gUserAuth.getResponse1stMap("login-flags");
  1536. if (login_flags.isDefined())
  1537. {
  1538. std::string flag;
  1539. if (login_flags.has("ever_logged_in"))
  1540. {
  1541. flag = login_flags["ever_logged_in"].asString();
  1542. gAgent.setFirstLogin(flag == "N");
  1543. }
  1544. if (login_flags.has("gendered"))
  1545. {
  1546. flag = login_flags["gendered"].asString();
  1547. if (flag == "Y")
  1548. {
  1549. gAgent.setGenderChosen(true);
  1550. }
  1551. }
  1552. if (login_flags.has("daylight_savings"))
  1553. {
  1554. flag = login_flags["daylight_savings"].asString();
  1555. gPacificDaylightTime = flag == "Y";
  1556. }
  1557. }
  1558. const LLSD& initial_outfit =
  1559. gUserAuth.getResponse1stMap("initial-outfit");
  1560. if (initial_outfit.isDefined())
  1561. {
  1562. if (initial_outfit.has("folder_name"))
  1563. {
  1564. // Initial outfit is a folder in your inventory, must be an
  1565. // exact folder-name match.
  1566. sInitialOutfit = initial_outfit["folder_name"].asString();
  1567. }
  1568. if (initial_outfit.has("gender"))
  1569. {
  1570. sInitialOutfitGender = initial_outfit["gender"].asString();
  1571. }
  1572. }
  1573. const LLSD& global_textures =
  1574. gUserAuth.getResponse1stMap("global-textures");
  1575. if (global_textures.isDefined())
  1576. {
  1577. // Extract sun and moon texture IDs. These are used in the
  1578. // LLVOSky constructor, but I cannot figure out how to pass
  1579. // them in. JC
  1580. if (global_textures.has("sun_texture_id"))
  1581. {
  1582. gSunTextureID = global_textures["sun_texture_id"].asUUID();
  1583. if (gSunTextureID != IMG_SUN)
  1584. {
  1585. llinfos << "Sun texture Id: " << gSunTextureID
  1586. << llendl;
  1587. }
  1588. }
  1589. if (global_textures.has("moon_texture_id"))
  1590. {
  1591. gMoonTextureID =
  1592. global_textures["moon_texture_id"].asUUID();
  1593. if (gMoonTextureID != IMG_MOON)
  1594. {
  1595. llinfos << "Moon texture Id: " << gMoonTextureID
  1596. << llendl;
  1597. }
  1598. }
  1599. if (global_textures.has("cloud_texture_id"))
  1600. {
  1601. gCloudTextureID =
  1602. global_textures["cloud_texture_id"].asUUID();
  1603. if (gCloudTextureID != IMG_CLOUD_POOF)
  1604. {
  1605. llinfos << "Clouds texture Id: " << gCloudTextureID
  1606. << llendl;
  1607. }
  1608. }
  1609. }
  1610. // Set the location of the Agent Appearance service, from which
  1611. // we can request avatar baked textures if they are supported by
  1612. // the current region
  1613. std::string agent_appearance_url =
  1614. gUserAuth.getResponseStr("agent_appearance_service");
  1615. if (!agent_appearance_url.empty())
  1616. {
  1617. LLVOAvatar::sAgentAppearanceServiceURL = agent_appearance_url;
  1618. }
  1619. // Start the process of fetching the OpenID session cookie for this
  1620. // user login
  1621. std::string openid_url = gUserAuth.getResponseStr("openid_url");
  1622. if (!openid_url.empty())
  1623. {
  1624. std::string openid_token =
  1625. gUserAuth.getResponseStr("openid_token");
  1626. LLViewerMedia::openIDSetup(openid_url, openid_token);
  1627. }
  1628. std::string token = gUserAuth.getResponseStr("currency");
  1629. if (!token.empty())
  1630. {
  1631. if (token.length() > 3)
  1632. {
  1633. llwarns << "Grid currency symbol too long, truncating..."
  1634. << llendl;
  1635. token = token.substr(0, 2) + "$";
  1636. }
  1637. llinfos << "Setting grid currency symbol to: " << token
  1638. << llendl;
  1639. LLUIString::setGridCurrency(token);
  1640. }
  1641. else if (gIsInSecondLife)
  1642. {
  1643. llinfos << "Using L$ as the grid currency symbol." << llendl;
  1644. }
  1645. else
  1646. {
  1647. llinfos << "Using OS$ as the grid currency symbol." << llendl;
  1648. LLUIString::setGridCurrency("OS$");
  1649. }
  1650. token = gUserAuth.getResponseStr("real_currency");
  1651. if (!token.empty())
  1652. {
  1653. llinfos << "Setting real currency symbol to: " << token
  1654. << llendl;
  1655. LLUIString::setRealCurrency(token);
  1656. }
  1657. else
  1658. {
  1659. llinfos << "Using US$ as the real currency symbol." << llendl;
  1660. }
  1661. // Translate UI strings that were already built and need their
  1662. // currency symbols translated.
  1663. LLUIString::translatePendingCurrency();
  1664. gMaxAgentGroups =
  1665. LLEconomy::getInstance()->getGroupMembershipLimit();
  1666. if (gMaxAgentGroups > 0)
  1667. {
  1668. llinfos << "gMaxAgentGroups read from account benefits: "
  1669. << gMaxAgentGroups << llendl;
  1670. }
  1671. else
  1672. {
  1673. token = gUserAuth.getResponseStr("max_groups");
  1674. if (!token.empty())
  1675. {
  1676. gMaxAgentGroups = atoi(token.c_str());
  1677. if (gMaxAgentGroups > 0)
  1678. {
  1679. llinfos << "gMaxAgentGroups read from 'max_groups' in login.cgi: "
  1680. << gMaxAgentGroups << llendl;
  1681. }
  1682. else
  1683. {
  1684. llwarns << "Invalid 'max_groups' value in login.cgi: '"
  1685. << token << "'" << llendl;
  1686. }
  1687. }
  1688. }
  1689. if (gMaxAgentGroups <= 0)
  1690. {
  1691. token = gUserAuth.getResponseStr("max-agent-groups");
  1692. if (!token.empty())
  1693. {
  1694. gMaxAgentGroups = atoi(token.c_str());
  1695. if (gMaxAgentGroups > 0)
  1696. {
  1697. llinfos << "gMaxAgentGroups read from 'max-agent-groups' in login.cgi: "
  1698. << gMaxAgentGroups << llendl;
  1699. }
  1700. else
  1701. {
  1702. llwarns << "Invalid 'max-agent-groups' value in login.cgi: '"
  1703. << token << "'" << llendl;
  1704. }
  1705. }
  1706. }
  1707. if (gMaxAgentGroups <= 0)
  1708. {
  1709. gMaxAgentGroups = gIsInSecondLife ? DEFAULT_MAX_AGENT_GROUPS
  1710. : OPENSIM_DEFAULT_MAX_AGENT_GROUPS;
  1711. llinfos << "gMaxAgentGroups set to default: "
  1712. << gMaxAgentGroups << llendl;
  1713. }
  1714. token = gUserAuth.getResponseStr("map-server-url");
  1715. if (token.empty())
  1716. {
  1717. LLWorldMap::setMapServerURL(gSavedSettings.getString("MapServerURL"));
  1718. }
  1719. else
  1720. {
  1721. LLWorldMap::gotMapServerURL(true);
  1722. LLWorldMap::setMapServerURL(token, true);
  1723. llinfos << "Got map server URL: " << token << llendl;
  1724. }
  1725. token = gUserAuth.getResponseStr("search-server-url");
  1726. if (!gIsInSecondLife && !token.empty())
  1727. {
  1728. HBFloaterSearch::setSearchURL(token, true);
  1729. llinfos << "Got search query URL: " << token << llendl;
  1730. }
  1731. // Set up the voice configuration. Ultimately, we should pass this
  1732. // up as part of each voice channel if we need to move to multiple
  1733. // voice servers per grid.
  1734. const LLSD& voice_config = gUserAuth.getResponse("voice-config");
  1735. if (voice_config.has("VoiceServerType"))
  1736. {
  1737. // NOTE: VoiceServerType is a non-persistent setting which is
  1738. // set to "vivox" by default on viewer launch. When the login
  1739. // simulator supports WebRTC, this should set VoiceServerType
  1740. // to "webrtc". HB
  1741. std::string type = voice_config["VoiceServerType"].asString();
  1742. gSavedSettings.setString("VoiceServerType", type);
  1743. llinfos << "Voice server type: " << type << llendl;
  1744. }
  1745. if (gAgentID.notNull() && gAgentSessionID.notNull() &&
  1746. gMessageSystemp->mOurCircuitCode && first_sim.isOk())
  1747. {
  1748. // Pass the user information to the voice chat server interface.
  1749. gVoiceClient.userAuthorized(gLoginFirstName, gLoginLastName,
  1750. gAgentID);
  1751. setStartupState(STATE_WORLD_INIT);
  1752. return false;
  1753. }
  1754. }
  1755. // When auto-logged in, abort after a 5s display of the error message
  1756. // in the progress bar
  1757. if (gSavedSettings.getBool("AutoLogin"))
  1758. {
  1759. // *TODO: translate
  1760. std::string errmsg =
  1761. "Cannot connect. The viewer will auto-close in a few seconds...";
  1762. gViewerWindowp->setProgressString(errmsg);
  1763. doAfterInterval(call_force_quit, 5.f);
  1764. // Jail ourselves in a no-op state until we quit...
  1765. setStartupState(STATE_LOGIN_WAIT);
  1766. return false;
  1767. }
  1768. if (notify_user)
  1769. {
  1770. LLSD args;
  1771. args["ERROR_MESSAGE"] = emsg.str();
  1772. gNotifications.add("ErrorMessage", args, LLSD(), loginAlertDone);
  1773. }
  1774. // Bounce back to the login screen.
  1775. resetLogin();
  1776. show_connect_box = true;
  1777. return false;
  1778. }
  1779. //---------------------------------------------------------------------
  1780. // World init
  1781. //---------------------------------------------------------------------
  1782. if (getStartupState() == STATE_WORLD_INIT)
  1783. {
  1784. gFrameSleepTime = 0;
  1785. setStartupStatus(0.4f, LLTrans::getString("LoginInitializingWorld"),
  1786. gAgent.mMOTD);
  1787. display_startup();
  1788. // We should have an agent id by this point.
  1789. llassert(gAgentID.notNull());
  1790. // Finish agent initialization (requires gSavedSettings, inits camera)
  1791. gAgent.init();
  1792. set_underclothes_menu_options();
  1793. // Since we connected, save off the settings so the user does not have
  1794. // to type the name/password again if we crash.
  1795. gAppViewerp->saveGlobalSettings();
  1796. // Load the teleport history
  1797. gFloaterTeleportHistoryp->loadEntries();
  1798. // Load autopilot stuff
  1799. gAgentPilot.load(gSavedSettings.getString("AutoPilotFile"));
  1800. //
  1801. // Initialize classes w/graphics stuff.
  1802. //
  1803. gTextureList.doPrefetchImages();
  1804. // We used to call LLFace::initClass() here (now empty and removed)
  1805. // We used to call LLDrawable::initClass() here (now empty and removed)
  1806. LLAvatarAppearance::initClass("avatar_lad.xml", "avatar_skeleton.xml");
  1807. LLViewerObject::initVOClasses();
  1808. display_startup();
  1809. // This is where we used to initialize gWorldp. Original comment said:
  1810. // World initialization must be done after above window init
  1811. // User might have overridden far clip
  1812. gWorld.setLandFarClip(gAgent.mDrawDistance);
  1813. // Before we create the first region, we need to set the agent's
  1814. // mOriginGlobal. This is necessary because creating objects before
  1815. // this is set will result in a bad mPositionAgent cache.
  1816. gAgent.initOriginGlobal(from_region_handle(first_sim_handle));
  1817. gWorld.addRegion(first_sim_handle, first_sim, first_region_size);
  1818. LLViewerRegion* regionp = gWorld.getRegionFromHandle(first_sim_handle);
  1819. llinfos << "Adding initial simulator "
  1820. << regionp->getOriginGlobal() << llendl;
  1821. regionp->setSeedCapability(first_sim_seed_cap);
  1822. LL_DEBUGS("AppInit") << "Waiting for seed grant ...." << LL_ENDL;
  1823. // Set agent's initial region to be the one we just created.
  1824. gAgent.setRegion(regionp);
  1825. // Set agent's initial position, which will be read by LLVOAvatar when
  1826. // the avatar object is created. I think this must be done after
  1827. // setting the region. JC
  1828. gAgent.setPositionAgent(agent_start_position_region);
  1829. // Initialize experiences
  1830. gAppViewerp->loadExperienceCache();
  1831. LLExperienceCache* expcache = LLExperienceCache::getInstance();
  1832. expcache->setCapabilityQuery(boost::bind(&LLAgent::getRegionCapability,
  1833. &gAgent, _1));
  1834. LLExperienceLog::getInstance()->initialize();
  1835. display_startup();
  1836. setStartupState(STATE_MULTIMEDIA_INIT);
  1837. return false;
  1838. }
  1839. //---------------------------------------------------------------------
  1840. // Load multimedia engines; can be slow. Do it while we are waiting on
  1841. // the network for our seed capability. JC
  1842. //---------------------------------------------------------------------
  1843. if (getStartupState() == STATE_MULTIMEDIA_INIT)
  1844. {
  1845. multimediaInit();
  1846. setStartupState(STATE_SEED_GRANTED_WAIT);
  1847. return false;
  1848. }
  1849. //---------------------------------------------------------------------
  1850. // Wait for seed cap grant.
  1851. //---------------------------------------------------------------------
  1852. if (getStartupState() == STATE_SEED_GRANTED_WAIT)
  1853. {
  1854. U32 retries = 0;
  1855. LLViewerRegion* regionp = gWorld.getRegionFromHandle(first_sim_handle);
  1856. if (regionp &&
  1857. (regionp->capabilitiesReceived() ||
  1858. // Try to connect despite capabilities' error state...
  1859. regionp->capabilitiesError() ||
  1860. // ... or exhausted retries count.
  1861. (retries = regionp->getNumSeedCapRetries()) >
  1862. MAX_SEED_CAP_ATTEMPTS_BEFORE_LOGIN))
  1863. {
  1864. setStartupState(STATE_SEED_CAP_GRANTED);
  1865. return false;
  1866. }
  1867. if (retries > 1)
  1868. {
  1869. setStartupStatus(0.44f,
  1870. LLTrans::getString("LoginRetrySeedRequest"),
  1871. gAgent.mMOTD);
  1872. }
  1873. else
  1874. {
  1875. setStartupStatus(0.43f, LLTrans::getString("LoginWaitingForSeed"),
  1876. gAgent.mMOTD);
  1877. }
  1878. gFrameSleepTime = 10; // Do not hog the CPU
  1879. return false;
  1880. }
  1881. //---------------------------------------------------------------------
  1882. // Seed capability granted.
  1883. // No newMessage calls should happen before this point.
  1884. //---------------------------------------------------------------------
  1885. if (getStartupState() == STATE_SEED_CAP_GRANTED)
  1886. {
  1887. gFrameSleepTime = 1;
  1888. LLAppViewer::updateTextureFetch();
  1889. if (gViewerWindowp)
  1890. {
  1891. // This is not the first logon attempt, so show the UI
  1892. gViewerWindowp->setNormalControlsVisible(true);
  1893. }
  1894. gLoginMenuBarViewp->setVisible(false);
  1895. gLoginMenuBarViewp->setEnabled(false);
  1896. if (gAudiop)
  1897. {
  1898. gAudiop->setMuted(true); // Do not play the floaters opening sound
  1899. }
  1900. // Adjust the floaters position for first use
  1901. gViewerWindowp->adjustRectanglesForFirstUse();
  1902. // Move the progress view in front of the UI
  1903. gViewerWindowp->moveProgressViewToFront();
  1904. if (gDebugViewp && gDebugViewp->mDebugConsolep)
  1905. {
  1906. LLError::logToFixedBuffer(gDebugViewp->mDebugConsolep);
  1907. // Set initial visibility of debug console
  1908. gDebugViewp->mDebugConsolep->setVisible(gSavedSettings.getBool("ShowDebugConsole"));
  1909. }
  1910. // Load the chat history now, if configured by the user. HB
  1911. if (gSavedPerAccountSettings.getBool("LogShowHistory"))
  1912. {
  1913. LLFloaterChat::getInstance(LLSD())->loadHistory();
  1914. }
  1915. //
  1916. // Set message handlers
  1917. //
  1918. llinfos << "Initializing communications..." << llendl;
  1919. // Register callbacks for messages... Do this after initial handshake
  1920. // to make sure that we don't catch any unwanted
  1921. LLMessageSystem* msg = gMessageSystemp;
  1922. registerViewerCallbacks(msg);
  1923. // Register null callbacks for audio until the audio system is
  1924. // initialized
  1925. msg->setHandlerFuncFast(_PREHASH_SoundTrigger, null_message_callback);
  1926. msg->setHandlerFuncFast(_PREHASH_AttachedSound, null_message_callback);
  1927. // Debugging info parameters
  1928. // Spam if decoding all msgs takes more than 500ms
  1929. msg->setMaxMessageTime(0.5f);
  1930. #if LL_DEBUG
  1931. // Time the decode of each msg
  1932. msg->setTimeDecodes(true);
  1933. // Spam if a single msg takes over 50ms to decode
  1934. msg->setTimeDecodesSpamThreshold(0.05f);
  1935. #endif
  1936. gXferManagerp->registerCallbacks(msg);
  1937. if (!gCacheNamep)
  1938. {
  1939. // Initialize the legacy name cache
  1940. gCacheNamep = new LLCacheName(msg,
  1941. LLTrans::getString("name_loading"),
  1942. LLTrans::getString("name_noboby"),
  1943. LLTrans::getString("name_none"));
  1944. gCacheNamep->addObserver(&callbackCacheName);
  1945. // Load stored cache if possible
  1946. gAppViewerp->loadNameCache();
  1947. // Initialize the new avatar name cache
  1948. LLAvatarNameCache::initClass();
  1949. }
  1950. // Reset statistics
  1951. gViewerStats.resetStats();
  1952. //
  1953. // Set up all of our statistics UI stuff.
  1954. //
  1955. display_startup();
  1956. //
  1957. // Set up region and surface defaults
  1958. //
  1959. // Sets up the parameters for the first simulator
  1960. LL_DEBUGS("AppInit") << "Initializing camera..." << LL_ENDL;
  1961. gFrameTime = LLTimer::totalTime();
  1962. F32 last_time = gFrameTimeSeconds;
  1963. gFrameTimeSeconds = (S64)(gFrameTime - gStartTime) / SEC_TO_MICROSEC;
  1964. gFrameIntervalSeconds = gFrameTimeSeconds - last_time;
  1965. if (gFrameIntervalSeconds < 0.f)
  1966. {
  1967. gFrameIntervalSeconds = 0.f;
  1968. }
  1969. // Make sure agent knows correct aspect ratio. FOV limits depend upon
  1970. // aspect ratio so this needs to happen before initializing the FOV
  1971. // below.
  1972. gViewerCamera.setViewHeightInPixels(gViewerWindowp->getWindowDisplayHeight());
  1973. if (gWindowp->getFullscreen())
  1974. {
  1975. gViewerCamera.setAspect(gViewerWindowp->getDisplayAspectRatio());
  1976. }
  1977. else
  1978. {
  1979. gViewerCamera.setAspect((F32)gViewerWindowp->getWindowWidth() /
  1980. (F32)gViewerWindowp->getWindowHeight());
  1981. }
  1982. // Initialize FOV
  1983. gViewerCamera.setDefaultFOV(gSavedSettings.getF32("CameraAngle"));
  1984. // Move agent to starting location. The position handed to us by the
  1985. // space server is in global coordinates, but the agent frame is in
  1986. // region local coordinates. Therefore, we need to adjust the
  1987. // coordinates handed to us to fit in the local region.
  1988. gAgent.setPositionAgent(agent_start_position_region);
  1989. gAgent.resetAxes(agent_start_look_at);
  1990. gAgent.stopCameraAnimation();
  1991. gAgent.resetCamera();
  1992. // Initialize global class data needed for surfaces (i.e. textures)
  1993. LL_DEBUGS("AppInit") << "Initializing sky..." << LL_ENDL;
  1994. LL_GL_CHECK_STATES;
  1995. gSky.init();
  1996. LL_GL_CHECK_STATES;
  1997. LL_DEBUGS("AppInit") << "Decoding images..." << LL_ENDL;
  1998. // For all images pre-loaded into viewer cache, decode them.
  1999. // Need to do this AFTER we init the sky
  2000. std::string decoding = LLTrans::getString("LoginDecodingImages");
  2001. constexpr S32 DECODE_TIME_SEC = 3;
  2002. for (S32 i = 0; i < DECODE_TIME_SEC; ++i)
  2003. {
  2004. F32 frac = (F32)i / (F32)DECODE_TIME_SEC;
  2005. setStartupStatus(0.45f + frac * 0.1f, decoding, gAgent.mMOTD);
  2006. display_startup();
  2007. if (!gTextureList.decodeAllImages(1.f))
  2008. {
  2009. setStartupStatus(0.55f, decoding, gAgent.mMOTD);
  2010. break;
  2011. }
  2012. }
  2013. setStartupState(STATE_WORLD_WAIT);
  2014. // JC - Do this as late as possible to increase likelihood Purify will
  2015. // run.
  2016. if (!msg->mOurCircuitCode)
  2017. {
  2018. llwarns << "Attempting to connect to simulator with a zero circuit code !"
  2019. << llendl;
  2020. }
  2021. gUseCircuitCallbackCalled = false;
  2022. msg->enableCircuit(first_sim, true);
  2023. // Now, use the circuit info to tell simulator about us !
  2024. llinfos << "Enabling simulator '" << first_sim << "' with code: "
  2025. << msg->mOurCircuitCode << llendl;
  2026. msg->newMessageFast(_PREHASH_UseCircuitCode);
  2027. msg->nextBlockFast(_PREHASH_CircuitCode);
  2028. msg->addU32Fast(_PREHASH_Code, msg->mOurCircuitCode);
  2029. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  2030. msg->addUUIDFast(_PREHASH_ID, gAgentID);
  2031. msg->sendReliable(first_sim, MAX_TIMEOUT_COUNT, false, TIMEOUT_SECONDS,
  2032. useCircuitCallback, NULL);
  2033. timeout.reset();
  2034. return false;
  2035. }
  2036. //---------------------------------------------------------------------
  2037. // World wait.
  2038. //---------------------------------------------------------------------
  2039. if (getStartupState() == STATE_WORLD_WAIT)
  2040. {
  2041. LL_DEBUGS_ONCE("AppInit") << "Waiting for simulator ack...."
  2042. << LL_ENDL;
  2043. setStartupStatus(0.59f,
  2044. LLTrans::getString("LoginWaitingForRegionHandshake"),
  2045. gAgent.mMOTD);
  2046. // Process messages to keep from dropping circuit.
  2047. process_messages();
  2048. if (gGotUseCircuitCodeAck)
  2049. {
  2050. gFrameSleepTime = 1;
  2051. setStartupState(STATE_AGENT_SEND);
  2052. }
  2053. else
  2054. {
  2055. gFrameSleepTime = 10; // Do not hog the CPU
  2056. }
  2057. return false;
  2058. }
  2059. //---------------------------------------------------------------------
  2060. // Agent send.
  2061. //---------------------------------------------------------------------
  2062. if (getStartupState() == STATE_AGENT_SEND)
  2063. {
  2064. gFrameSleepTime = 1;
  2065. LL_DEBUGS_ONCE("AppInit") << "Connecting to region..." << LL_ENDL;
  2066. setStartupStatus(0.6f, LLTrans::getString("LoginConnectingToRegion"),
  2067. gAgent.mMOTD);
  2068. // Register with the message system so it knows we are expecting this
  2069. // message
  2070. LLMessageSystem* msg = gMessageSystemp;
  2071. msg->setHandlerFuncFast(_PREHASH_AgentMovementComplete,
  2072. process_agent_movement_complete);
  2073. LLViewerRegion* regionp = gAgent.getRegion();
  2074. if (regionp)
  2075. {
  2076. send_complete_agent_movement(regionp->getHost());
  2077. gAssetStoragep->setUpstream(regionp->getHost());
  2078. gCacheNamep->setUpstream(regionp->getHost());
  2079. msg->newMessageFast(_PREHASH_EconomyDataRequest);
  2080. gAgent.sendReliableMessage();
  2081. }
  2082. setStartupState(STATE_AGENT_WAIT); // Go to STATE_AGENT_WAIT
  2083. timeout.reset();
  2084. return false;
  2085. }
  2086. //---------------------------------------------------------------------
  2087. // Agent wait.
  2088. //---------------------------------------------------------------------
  2089. if (getStartupState() == STATE_AGENT_WAIT)
  2090. {
  2091. gFrameSleepTime = 1;
  2092. { // Scope guard for LockMessageChecker
  2093. LLMessageSystem* msg = gMessageSystemp;
  2094. #if LL_USE_FIBER_AWARE_MUTEX
  2095. LockMessageChecker lmc(msg);
  2096. while (lmc.checkAllMessages(gFrameCount, gServicePumpIOp))
  2097. #else
  2098. while (msg->checkAllMessages(gFrameCount, gServicePumpIOp))
  2099. #endif
  2100. {
  2101. if (gAgentMovementCompleted)
  2102. {
  2103. // Sometimes we have more than one message in the queue.
  2104. // Break out of this loop and continue processing. If we do
  2105. // not, then this could skip one or more login steps.
  2106. break;
  2107. }
  2108. else
  2109. {
  2110. LL_DEBUGS("AppInit") << "Awaiting AvatarInitComplete, got "
  2111. << msg->getMessageName()
  2112. << LL_ENDL;
  2113. }
  2114. }
  2115. #if LL_USE_FIBER_AWARE_MUTEX
  2116. lmc.processAcks();
  2117. #else
  2118. msg->processAcks();
  2119. #endif
  2120. } // End of scope for LockMessageChecker
  2121. if (gAgentMovementCompleted)
  2122. {
  2123. setStartupState(STATE_INVENTORY_SEND);
  2124. }
  2125. else if (timeout.getElapsedTimeF32() > STATE_AGENT_WAIT_TIMEOUT)
  2126. {
  2127. // Make sure user knows something bad happened.
  2128. // When auto-logged in, abort after a 5s display of the error message
  2129. // in the progress bar
  2130. if (gSavedSettings.getBool("AutoLogin"))
  2131. {
  2132. // *TODO: translate
  2133. std::string errmsg =
  2134. "Cannot connect. The viewer will auto-close in a few seconds...";
  2135. gViewerWindowp->setProgressString(errmsg);
  2136. doAfterInterval(call_force_quit, 5.f);
  2137. // Jail ourselves in a no-op state until we quit...
  2138. setStartupState(STATE_LOGIN_WAIT);
  2139. return false;
  2140. }
  2141. // Make sure user knows something bad happened.
  2142. gNotifications.add("LoginPacketNeverReceived", LLSD(), LLSD(),
  2143. loginAlertStatus);
  2144. llwarns << "Returning to login screen !" << llendl;
  2145. resetLogin();
  2146. }
  2147. else
  2148. {
  2149. gFrameSleepTime = 10; // Do not hog the CPU
  2150. }
  2151. return false;
  2152. }
  2153. //---------------------------------------------------------------------
  2154. // Inventory send.
  2155. //---------------------------------------------------------------------
  2156. if (getStartupState() == STATE_INVENTORY_SEND)
  2157. {
  2158. gFrameSleepTime = 0;
  2159. // Inform simulator of our language preference
  2160. gAgent.updateLanguage();
  2161. // Request mute list
  2162. llinfos << "Requesting Mute list" << llendl;
  2163. LLMuteList::requestFromServer();
  2164. // Get L$ and ownership credit information
  2165. llinfos << "Requesting Money balance" << llendl;
  2166. LLStatusBar::sendMoneyBalanceRequest();
  2167. if (gSavedPerAccountSettings.getBool("ClearInventoryCache"))
  2168. {
  2169. gSavedPerAccountSettings.setBool("ClearInventoryCache", false);
  2170. std::string file = gInventory.getCacheFileName(gAgentID) + ".gz";
  2171. if (LLFile::exists(file))
  2172. {
  2173. llinfos << "Per user request, removing inventory cache file: "
  2174. << file << llendl;
  2175. LLFile::remove(file);
  2176. }
  2177. }
  2178. const LLSD& inv_lib_root =
  2179. gUserAuth.getResponse1stMap("inventory-lib-root");
  2180. if (inv_lib_root.isDefined() && inv_lib_root.has("folder_id"))
  2181. {
  2182. LLUUID id = inv_lib_root["folder_id"].asUUID();
  2183. gInventory.setLibraryRootFolderID(id);
  2184. }
  2185. else
  2186. {
  2187. llwarns << "Cannot find library root inventory folder Id !"
  2188. << llendl;
  2189. }
  2190. const LLSD& inv_lib_owner =
  2191. gUserAuth.getResponse1stMap("inventory-lib-owner");
  2192. if (inv_lib_owner.isDefined() && inv_lib_owner.has("agent_id"))
  2193. {
  2194. LLUUID id = inv_lib_owner["agent_id"].asUUID();
  2195. gInventory.setLibraryOwnerID(id);
  2196. }
  2197. else
  2198. {
  2199. gInventory.setLibraryOwnerID(ALEXANDRIA_LINDEN_ID);
  2200. llwarns << "Cannot find inventory library owner Id. Using Alexandra Linden's Id."
  2201. << llendl;
  2202. }
  2203. const LLSD& inv_skel_lib = gUserAuth.getResponse("inventory-skel-lib");
  2204. if (inv_skel_lib.isDefined() &&
  2205. !gInventory.loadSkeleton(inv_skel_lib,
  2206. gInventory.getLibraryOwnerID()))
  2207. {
  2208. llwarns << "Problem loading inventory-skel-lib" << llendl;
  2209. }
  2210. const LLSD& inv_skeleton = gUserAuth.getResponse("inventory-skeleton");
  2211. if (inv_skeleton.isDefined() &&
  2212. !gInventory.loadSkeleton(inv_skeleton, gAgentID))
  2213. {
  2214. llwarns << "Problem loading inventory-skeleton" << llendl;
  2215. }
  2216. const LLSD& buddy_list = gUserAuth.getResponse("buddy-list");
  2217. if (buddy_list.isDefined())
  2218. {
  2219. LLAvatarTracker::buddy_map_t list;
  2220. LLUUID agent_id;
  2221. S32 has_rights, given_rights;
  2222. for (LLSD::array_const_iterator it = buddy_list.beginArray(),
  2223. end = buddy_list.endArray();
  2224. it != end; ++it)
  2225. {
  2226. const LLSD& entry = *it;
  2227. if (!entry.has("buddy_id"))
  2228. {
  2229. continue;
  2230. }
  2231. agent_id = entry["buddy_id"].asUUID();
  2232. has_rights = given_rights = 0;
  2233. if (entry.has("buddy_rights_has"))
  2234. {
  2235. has_rights = entry["buddy_rights_has"].asInteger();
  2236. }
  2237. if (entry.has("buddy_rights_given"))
  2238. {
  2239. given_rights = entry["buddy_rights_given"].asInteger();
  2240. }
  2241. list[agent_id] = new LLRelationship(given_rights, has_rights,
  2242. false);
  2243. }
  2244. gAvatarTracker.addBuddyList(list);
  2245. }
  2246. const LLSD& ui_config = gUserAuth.getResponse("ui-config");
  2247. if (ui_config.isDefined())
  2248. {
  2249. for (LLSD::array_const_iterator it = ui_config.beginArray(),
  2250. end = ui_config.endArray();
  2251. it != end; ++it)
  2252. {
  2253. const LLSD& entry = *it;
  2254. if (entry.has("allow_first_life") &&
  2255. entry["allow_first_life"].asString() == "Y")
  2256. {
  2257. LLPanelAvatar::sAllowFirstLife = true;
  2258. break;
  2259. }
  2260. }
  2261. }
  2262. const LLSD& event_cats = gUserAuth.getResponse("event_categories");
  2263. if (event_cats.isDefined())
  2264. {
  2265. LLEventInfo::loadCategories(event_cats);
  2266. }
  2267. const LLSD& event_notif = gUserAuth.getResponse("event_notifications");
  2268. if (event_notif.isDefined())
  2269. {
  2270. gEventNotifier.load(event_notif);
  2271. }
  2272. const LLSD& classified_cats =
  2273. gUserAuth.getResponse("classified_categories");
  2274. if (classified_cats.isDefined())
  2275. {
  2276. LLClassifiedInfo::loadCategories(classified_cats);
  2277. }
  2278. gInventory.buildParentChildMap();
  2279. // Set up callbacks
  2280. llinfos << "Registering callbacks" << llendl;
  2281. LLMessageSystem* msg = gMessageSystemp;
  2282. llinfos << "Inventory" << llendl;
  2283. LLInventoryModel::registerCallbacks(msg);
  2284. llinfos << "AvatarTracker" << llendl;
  2285. gAvatarTracker.registerCallbacks(msg);
  2286. llinfos << "Landmark" << llendl;
  2287. LLLandmark::registerCallbacks(msg);
  2288. // Request all group information
  2289. llinfos << "Requesting agent groups data" << llendl;
  2290. gAgent.sendAgentDataUpdateRequest();
  2291. // Create the inventory floater
  2292. llinfos << "Creating inventory floater" << llendl;
  2293. bool shown_at_exit = gSavedSettings.getBool("ShowInventory");
  2294. LLFloaterInventory::showAgentInventory();
  2295. // Hide the inventory floater if it was not shown at exit
  2296. if (!shown_at_exit)
  2297. {
  2298. LLFloaterInventory::toggleVisibility(NULL);
  2299. }
  2300. // Change the window title to include the avatar name.
  2301. gWindowTitle = gSecondLife + " - " + gLoginFirstName + " " +
  2302. gLoginLastName;
  2303. #if LL_DEBUG || LL_NO_FORCE_INLINE
  2304. LLStringUtil::truncate(gWindowTitle, 247);
  2305. gWindowp->setWindowTitle(gWindowTitle + " [DEVEL]");
  2306. #else
  2307. LLStringUtil::truncate(gWindowTitle, 255);
  2308. gWindowp->setWindowTitle(gWindowTitle);
  2309. #endif
  2310. setStartupState(STATE_MISC);
  2311. return false;
  2312. }
  2313. //---------------------------------------------------------------------
  2314. // Misc
  2315. //---------------------------------------------------------------------
  2316. if (getStartupState() == STATE_MISC)
  2317. {
  2318. // Display the floaters that we left open on logout
  2319. bool show_radar = gSavedSettings.getBool("ShowRadar");
  2320. if (show_radar || gSavedSettings.getBool("RadarKeepOpen"))
  2321. {
  2322. // Start the radar updates and bookkeeping
  2323. HBFloaterRadar::showInstance();
  2324. if (!show_radar)
  2325. {
  2326. // Hide the radar if the floater was not visible on last logout
  2327. HBFloaterRadar::hideInstance();
  2328. }
  2329. }
  2330. if (gSavedSettings.getBool("ShowMiniMap"))
  2331. {
  2332. LLFloaterMiniMap::showInstance();
  2333. }
  2334. if (gSavedSettings.getBool("ShowCameraControls"))
  2335. {
  2336. LLFloaterCamera::showInstance();
  2337. }
  2338. if (gSavedSettings.getBool("ShowMovementControls"))
  2339. {
  2340. LLFloaterMove::showInstance();
  2341. }
  2342. if (gSavedSettings.getBool("ShowActiveSpeakers"))
  2343. {
  2344. LLFloaterActiveSpeakers::showInstance();
  2345. }
  2346. if (gSavedSettings.getBool("BeaconAlwaysOn"))
  2347. {
  2348. LLFloaterBeacons::showInstance();
  2349. }
  2350. if (gSavedSettings.getBool("ShowDebugStats"))
  2351. {
  2352. LLFloaterStats::showInstance();
  2353. }
  2354. // We are successfully logged in.
  2355. LLPanelLogin::close();
  2356. std::string nextLoginLocation =
  2357. gSavedSettings.getString("NextLoginLocation");
  2358. if (nextLoginLocation.length())
  2359. {
  2360. // Clear it
  2361. gSavedSettings.setString("NextLoginLocation", "");
  2362. // And make sure it is saved
  2363. gAppViewerp->saveGlobalSettings();
  2364. }
  2365. // JC: Initializing audio requests many sounds for download.
  2366. init_audio();
  2367. // Re-register callbacks for audio, this time with active ones
  2368. LLMessageSystem* msg = gMessageSystemp;
  2369. msg->setHandlerFuncFast(_PREHASH_SoundTrigger, process_sound_trigger);
  2370. msg->setHandlerFuncFast(_PREHASH_PreloadSound, process_preload_sound);
  2371. msg->setHandlerFuncFast(_PREHASH_AttachedSound,
  2372. process_attached_sound);
  2373. msg->setHandlerFuncFast(_PREHASH_AttachedSoundGainChange,
  2374. process_attached_sound_gain_change);
  2375. // JC: Initialize "active" gestures. This may also trigger many gesture
  2376. // downloads, if this is the user's first time on this machine or
  2377. // -purge has been run.
  2378. const LLSD& gesture_options = gUserAuth.getResponse("gestures");
  2379. if (gesture_options.isDefined())
  2380. {
  2381. gGestureManager.load(gesture_options);
  2382. }
  2383. gDisplaySwapBuffers = true;
  2384. LL_DEBUGS("AppInit") << "Initialization complete" << LL_ENDL;
  2385. gRenderStartTime.reset();
  2386. // Make sure we are not paused before calling reset()
  2387. gForegroundTime.pause();
  2388. gForegroundTime.unpause();
  2389. gForegroundTime.reset();
  2390. // Fetch inventory in the background
  2391. LLInventoryModelFetch::getInstance()->start();
  2392. // *HACK: inform simulator of window size. Do this here so it is less
  2393. // likely to race with RegisterNewAgent. JC - 7/20/2002
  2394. gViewerWindowp->sendShapeToSim();
  2395. if (!gAgent.isFirstLogin())
  2396. {
  2397. LLSLURL start_slurl = getStartSLURL();
  2398. LLSLURL::eType start_slurl_type = start_slurl.getType();
  2399. if (!(start_slurl_type == LLSLURL::LOCATION &&
  2400. agent_start_location == "url") &&
  2401. !(start_slurl_type == LLSLURL::LAST_LOCATION &&
  2402. agent_start_location == "last") &&
  2403. !(start_slurl_type == LLSLURL::HOME_LOCATION &&
  2404. agent_start_location == "home"))
  2405. {
  2406. // The reason we show the alert is because we want to reduce
  2407. // confusion for when you log in and your provided location is
  2408. // not your expected location. So, if this is your first login,
  2409. // then you do not have an expectation, thus, do not show this
  2410. // alert.
  2411. LLSD args;
  2412. switch (start_slurl.getType())
  2413. {
  2414. case LLSLURL::LOCATION:
  2415. args["TYPE"] = "desired";
  2416. args["HELP"] = "";
  2417. break;
  2418. case LLSLURL::HOME_LOCATION:
  2419. args["TYPE"] = "home";
  2420. args["HELP"] = "You may want to set a new home location.";
  2421. break;
  2422. default:
  2423. args["TYPE"] = "last";
  2424. args["HELP"] = "";
  2425. }
  2426. gNotifications.add("AvatarMoved", args);
  2427. gAvatarMovedOnLogin = true;
  2428. }
  2429. }
  2430. // DEV-17797. Get null folder. Any items found here moved to Lost and
  2431. // Found
  2432. LLInventoryModelFetch::getInstance()->findLostItems();
  2433. setStartupState(STATE_PRECACHE);
  2434. timeout.reset();
  2435. return false;
  2436. }
  2437. if (getStartupState() == STATE_PRECACHE)
  2438. {
  2439. F32 timeout_frac = timeout.getElapsedTimeF32() / precaching_delay;
  2440. // We now have an inventory skeleton, so if this is a user's first
  2441. // login, we can start setting up their clothing and avatar appearance.
  2442. if (gAgent.isFirstLogin() &&
  2443. !sInitialOutfit.empty() && // registration set up an outfit
  2444. !sInitialOutfitGender.empty() && // and a gender
  2445. isAgentAvatarValid() && // can't wear clothes without object
  2446. !gAgent.isGenderChosen()) // nothing already loading
  2447. {
  2448. // Start loading the wearables, textures, gestures
  2449. loadInitialOutfit(sInitialOutfit, sInitialOutfitGender);
  2450. }
  2451. else if (gIsInSecondLife && isAgentAvatarValid() &&
  2452. !gAgent.isFirstLogin() &&
  2453. !gAgentWearables.initialWearablesUpdateReceived())
  2454. {
  2455. // The initial outfit UDP message is no more relevant/valid in SL, so
  2456. // do not bother waiting for it if not yet received at this point.
  2457. llinfos << "Flagging the deprecated initial outfit message as received"
  2458. << llendl;
  2459. gAgentWearables.setInitialWearablesUpdateReceived();
  2460. }
  2461. // Wait precache-delay and for agent's avatar or a lot longer.
  2462. if ((timeout_frac > 1.f && isAgentAvatarValid()) || timeout_frac > 3.f)
  2463. {
  2464. setStartupState(STATE_WEARABLES_WAIT);
  2465. }
  2466. else
  2467. {
  2468. LLAppViewer::updateTextureFetch();
  2469. setStartupStatus(0.6f + 0.3f * timeout_frac,
  2470. LLTrans::getString("LoginPrecaching"),
  2471. gAgent.mMOTD);
  2472. display_startup();
  2473. }
  2474. return true;
  2475. }
  2476. if (getStartupState() == STATE_WEARABLES_WAIT)
  2477. {
  2478. static LLFrameTimer wearables_timer;
  2479. const F32 wearables_time = wearables_timer.getElapsedTimeF32();
  2480. constexpr F32 MAX_WEARABLES_TIME = 10.f;
  2481. // Fetch inventory in the background (again, just in case the first
  2482. // fetch could not yet complete and maybe got stuck). HB
  2483. LLInventoryModelFetch::getInstance()->start();
  2484. if (!gAgent.isGenderChosen())
  2485. {
  2486. // No point in waiting for clothing, we do not even know what
  2487. // gender we are. Pop a dialog to ask and proceed to draw the
  2488. // world. Note: we might hit this case even if we have an initial
  2489. // outfit, but if the load has not started already then something
  2490. // is wrong so fall back to generic outfits. JC
  2491. gNotifications.add("WelcomeChooseSex", LLSD(), LLSD(),
  2492. callbackChooseGender);
  2493. setStartupState(STATE_CLEANUP);
  2494. return true;
  2495. }
  2496. if (wearables_time > MAX_WEARABLES_TIME)
  2497. {
  2498. gNotifications.add("ClothingLoading");
  2499. gViewerStats.incStat(LLViewerStats::ST_WEARABLES_TOO_LONG);
  2500. setStartupState(STATE_CLEANUP);
  2501. return true;
  2502. }
  2503. if (gAgent.isFirstLogin())
  2504. {
  2505. // Wait for avatar to be completely loaded
  2506. if (isAgentAvatarValid() && gAgentAvatarp->isFullyLoaded())
  2507. {
  2508. LL_DEBUGS("AppInit") << "Avatar fully loaded" << LL_ENDL;
  2509. setStartupState(STATE_CLEANUP);
  2510. return true;
  2511. }
  2512. }
  2513. else if (gAgentWearables.areWearablesLoaded())
  2514. {
  2515. // We have our clothing, proceed.
  2516. LL_DEBUGS("AppInit") << "Wearables loaded" << LL_ENDL;
  2517. setStartupState(STATE_CLEANUP);
  2518. return true;
  2519. }
  2520. LLAppViewer::updateTextureFetch();
  2521. setStartupStatus(0.9f + 0.1f * wearables_time / MAX_WEARABLES_TIME,
  2522. LLTrans::getString("LoginDownloadingClothing"),
  2523. gAgent.mMOTD);
  2524. return true;
  2525. }
  2526. if (getStartupState() == STATE_CLEANUP)
  2527. {
  2528. setStartupStatus(1.f, "", "");
  2529. LLViewerMedia::loadDomainFilterList();
  2530. // Let the map know about the inventory and online friends.
  2531. if (gFloaterWorldMapp)
  2532. {
  2533. gFloaterWorldMapp->observeInventory(&gInventory);
  2534. gFloaterWorldMapp->observeFriends();
  2535. }
  2536. gViewerWindowp->showCursor();
  2537. gWindowp->resetBusyCount();
  2538. gWindowp->setCursor(UI_CURSOR_ARROW);
  2539. LL_DEBUGS("AppInit") << "Done releasing bitmap" << LL_ENDL;
  2540. gViewerWindowp->setShowProgress(false);
  2541. gViewerWindowp->setProgressCancelButtonVisible(false);
  2542. // We are not away from keyboard, even though login might have taken a
  2543. // while. JC
  2544. gAgent.clearAFK();
  2545. // Have the agent start watching the friends list so we can update
  2546. // proxies
  2547. gAgent.observeFriends();
  2548. //MK
  2549. if (gRLenabled)
  2550. {
  2551. // If we were restricted with @standtp before logging out, TP back
  2552. // there
  2553. gRLInterface.restoreLastStandingLoc();
  2554. gRLInterface.backToLastStandingLoc();
  2555. }
  2556. else
  2557. //mk
  2558. {
  2559. // If we have got a startup URL, dispatch it now
  2560. dispatchURL();
  2561. }
  2562. // Retrieve information about the land data (just accessing this the
  2563. // first time will fetch it, then the data is cached for the viewer's
  2564. // lifetime)
  2565. LLProductInfoRequestManager::getInstance()->create();
  2566. // If costs have not been received at this point, set the default ones
  2567. // (issue seen in some OpenSim grids that do not charge for anything).
  2568. if (LLEconomy::getInstance()->getPriceUpload() < 0)
  2569. {
  2570. llwarns << "Costs info not reveived. Setting default costs for: "
  2571. << (gIsInSecondLife ? "Second Life" : "OpenSim") << llendl;
  2572. LLEconomy::getInstance()->setDefaultCosts(gIsInSecondLife);
  2573. update_upload_costs_in_menus();
  2574. }
  2575. // Clean up LLUserAuth global instance.
  2576. gUserAuth.reset();
  2577. setStartupState(STATE_STARTED);
  2578. if (gSavedSettings.getBool("SpeedRez"))
  2579. {
  2580. // Speed up rezzing if requested.
  2581. F32 dist1 = gSavedSettings.getF32("RenderFarClip");
  2582. F32 dist2 = gSavedSettings.getF32("SavedRenderFarClip");
  2583. gSavedDrawDistance = (dist1 >= dist2 ? dist1 : dist2);
  2584. gSavedSettings.setF32("SavedRenderFarClip", gSavedDrawDistance);
  2585. gSavedSettings.setF32("RenderFarClip", 32.0f);
  2586. }
  2587. LLViewerTextureList::sLastTeleportTime = gFrameTimeSeconds;
  2588. // Unmute audio if desired and setup volumes.
  2589. // This is a not-uncommon crash site, so surround it with llinfos
  2590. // output to aid diagnosis.
  2591. llinfos << "Doing first audio_update_volume..." << llendl;
  2592. audio_update_volume();
  2593. llinfos << "Done first audio_update_volume." << llendl;
  2594. // Reset keyboard focus to sane state of pointing at world
  2595. gFocusMgr.setKeyboardFocus(NULL);
  2596. gAppViewerp->handleLoginComplete();
  2597. if (isAgentAvatarValid())
  2598. {
  2599. gAgentAvatarp->scheduleHoverUpdate();
  2600. }
  2601. // Set a fixed Sun position at login, if requested by the user. HB
  2602. F32 login_sun_pos = gSavedSettings.getF32("SunPositionAtLogin");
  2603. if (login_sun_pos >= 0.f && login_sun_pos <= 1.f)
  2604. {
  2605. gSavedSettings.setBool("UseParcelEnvironment", false);
  2606. gEnvironment.setLocalEnvFromDefaultWindlightDay(login_sun_pos);
  2607. }
  2608. else if (!gAgent.hasExtendedEnvironment())
  2609. {
  2610. gSavedSettings.setBool("UseParcelEnvironment", false);
  2611. // Load the default Windlight day settings, and use region time
  2612. gEnvironment.setLocalEnvFromDefaultWindlightDay();
  2613. }
  2614. else
  2615. {
  2616. gSavedSettings.setBool("UseParcelEnvironment", true);
  2617. }
  2618. // Setup the Marketplace, if any.
  2619. LLMarketplace::setup();
  2620. // *HACK: fix bogus OpenSim inventory layouts (happens on first login
  2621. // after account creation, but we cannot rely on gAgent.isFirstLogin()
  2622. // which is always false in OpenSim). HB
  2623. if (!gIsInSecondLife && first_grid_login)
  2624. {
  2625. // Also consolidate the COF, even when not using it.
  2626. bool use_cof = gSavedSettings.getBool("OSUseCOF");
  2627. gSavedSettings.setBool("OSUseCOF", true);
  2628. LLInventoryModel::checkSystemFolders(NULL);
  2629. gSavedSettings.setBool("OSUseCOF", use_cof);
  2630. }
  2631. // Sync voice settings now, and possibly enable voice. HB
  2632. gVoiceClient.updateSettings();
  2633. // Signal our login to the automation script, if any. HB
  2634. if (gAutomationp)
  2635. {
  2636. gAutomationp->onLogin();
  2637. }
  2638. // We can now disable the debug messages if no debug tag was added by
  2639. // the user from the login screen (the user may also re-enable the
  2640. // debug message from the Advanced menu). HB
  2641. LLError::Log::sDebugMessages =
  2642. HBFloaterDebugTags::hasActiveDebugTags();
  2643. // *HACK: force a refresh of objects visibility a few seconds after
  2644. // rezzing the world, to fix pseudo-invisible object cases. Note that a
  2645. // delay is needed (we need more frames to be rendered) and calling
  2646. // handle_objects_visibility() immediately would not have any effect.
  2647. // HB
  2648. schedule_objects_visibility_refresh(AFTER_LOGIN);
  2649. return true;
  2650. }
  2651. llwarns << "Unexpectedly reached end of method at state: "
  2652. << getStartupState() << llendl;
  2653. return true;
  2654. }
  2655. void LLStartUp::refreshLoginPanel()
  2656. {
  2657. LLPanelLogin::clearServers();
  2658. loginShow(true);
  2659. LLPanelLogin::selectFirstElement();
  2660. }
  2661. //static
  2662. bool LLStartUp::loginShow(bool update_servers)
  2663. {
  2664. static bool have_loginuri = false;
  2665. // This creates the LLPanelLogin instance, or shows it if existing already
  2666. LLPanelLogin::show(loginCallback);
  2667. if (!update_servers) return have_loginuri;
  2668. LL_DEBUGS("AppInit") << "Setting Servers" << LL_ENDL;
  2669. // Remember which servers are already listed.
  2670. std::set<EGridInfo> listed;
  2671. std::set<std::string> listed_name; // Only the 'other' grids.
  2672. LLGridManager* gm = LLGridManager::getInstance();
  2673. LLSavedLogins saved_logins = LLPanelLogin::getLoginHistory();
  2674. const LLSavedLogins::list_t& login_entries = saved_logins.getEntries();
  2675. // Add the commandline -loginuri's to the list at the top.
  2676. have_loginuri = false;
  2677. const std::vector<std::string>& cmd_line_uris = gm->getCommandLineURIs();
  2678. for (S32 i = 0, count = cmd_line_uris.size(); i < count; ++i)
  2679. {
  2680. LLURI cli_uri(cmd_line_uris[i]);
  2681. std::string cli_grid_name = cli_uri.hostName();
  2682. LLStringUtil::toLower(cli_grid_name);
  2683. if (listed_name.insert(cli_grid_name).second)
  2684. {
  2685. // If the loginuri already exists in the saved logins then use just
  2686. // its name, otherwise show the full uri.
  2687. bool exists = false;
  2688. for (LLSavedLogins::list_t::const_iterator
  2689. it = login_entries.begin(), end = login_entries.end();
  2690. it != end; ++it)
  2691. {
  2692. if (it->getGridName() == cli_grid_name)
  2693. {
  2694. exists = true;
  2695. break;
  2696. }
  2697. }
  2698. LLPanelLogin::addServer(exists ? cli_grid_name : cmd_line_uris[i],
  2699. GRID_INFO_OTHER);
  2700. // Causes the first server to be added here to be selected:
  2701. have_loginuri = true;
  2702. }
  2703. }
  2704. // Only look at the name for 'other' grids.
  2705. listed.insert(GRID_INFO_OTHER);
  2706. // Add the saved logins, last used grids first.
  2707. for (LLSavedLogins::list_const_rit_t rit = login_entries.rbegin(),
  2708. rend = login_entries.rend();
  2709. rit != rend; ++rit)
  2710. {
  2711. const LLSavedLoginEntry& entry = *rit;
  2712. EGridInfo idx = entry.getGrid();
  2713. std::string grid_name = entry.getGridName();
  2714. // Only show non-duplicate entries: duplicate entries do occur for ALTs
  2715. if (listed.insert(idx).second ||
  2716. (idx == GRID_INFO_OTHER && listed_name.insert(grid_name).second))
  2717. {
  2718. LLPanelLogin::addServer(grid_name, idx);
  2719. }
  2720. }
  2721. // Finally show the other grid servers.
  2722. for (EGridInfo idx = 1; idx < GRID_INFO_OTHER; ++idx)
  2723. {
  2724. if (listed.find(idx) == listed.end())
  2725. {
  2726. LLPanelLogin::addServer(gm->getKnownGridLabel(idx), idx);
  2727. }
  2728. }
  2729. // Remember that the user did not change anything yet.
  2730. gm->setNameEdited(false);
  2731. return have_loginuri;
  2732. }
  2733. // Callback for when login screen is closed.
  2734. //static
  2735. void LLStartUp::loginCallback(S32 option, void*)
  2736. {
  2737. constexpr S32 CONNECT_OPTION = 0;
  2738. constexpr S32 QUIT_OPTION = 1;
  2739. if (option == CONNECT_OPTION)
  2740. {
  2741. setStartupState(STATE_LOGIN_CLEANUP);
  2742. return;
  2743. }
  2744. else if (option == QUIT_OPTION)
  2745. {
  2746. // Next iteration through main loop should shut down the app cleanly.
  2747. gAppViewerp->userQuit();
  2748. if (gAppViewerp->quitRequested())
  2749. {
  2750. LLPanelLogin::close();
  2751. }
  2752. return;
  2753. }
  2754. else
  2755. {
  2756. llwarns << "Unknown login button clicked" << llendl;
  2757. llassert(false);
  2758. }
  2759. }
  2760. //static
  2761. std::string LLStartUp::getPasswordHashFromSettings()
  2762. {
  2763. std::string hashed_password;
  2764. #if 0 // Problem: the user might not want to loose all passwords for all
  2765. // avatars of all grids... If the password was saved for this avatar
  2766. // on this grid, then the viewer was asked to remember it at last
  2767. // login, and after this new login, the password will be remembered or
  2768. // cleared based on the new RememberLogin value anyway. HB
  2769. // Only load password if we also intend to save it (otherwise the user
  2770. // wonders what we are doing behind their back). JC
  2771. if (!gSavedSettings.getBool("RememberLogin"))
  2772. {
  2773. return hashed_password;
  2774. }
  2775. #endif
  2776. hashed_password = gSavedSettings.getString("HashedPassword");
  2777. if (hashed_password.empty())
  2778. {
  2779. return hashed_password;
  2780. }
  2781. hashed_password = LLBase64::decode(hashed_password);
  2782. if (hashed_password.size() != MD5HEX_STR_BYTES)
  2783. {
  2784. llwarns << "Bad base64 saved password hash: "
  2785. << gSavedSettings.getString("HashedPassword") << llendl;
  2786. return "";
  2787. }
  2788. // Decipher with MAC address
  2789. LLXORCipher cipher(gMACAddress, MAC_ADDRESS_BYTES);
  2790. cipher.decrypt((U8*)hashed_password.data(), MD5HEX_STR_BYTES);
  2791. // Check to see if the MAC address generated a bad hashed password. It
  2792. // should be a hex-string or else the mac address has changed. This is a
  2793. // security feature to make sure that if you get someone's settings file,
  2794. // you cannot hack their account.
  2795. if (!LLStringOps::isHexString(hashed_password))
  2796. {
  2797. llwarns << "Invalid hash: MAC address probably changed..." << llendl;
  2798. return "";
  2799. }
  2800. #if LL_DEBUG_LOGIN_PASSWORD
  2801. LL_DEBUGS("Login") << "Returning password hash: " << hashed_password
  2802. << LL_ENDL;
  2803. #endif
  2804. return hashed_password;
  2805. }
  2806. //static
  2807. void LLStartUp::savePasswordHashToSettings(std::string password)
  2808. {
  2809. if (password.size() != MD5HEX_STR_BYTES)
  2810. {
  2811. llwarns << "Incorrect length for password hash: " << password
  2812. << llendl;
  2813. return;
  2814. }
  2815. #if LL_DEBUG_LOGIN_PASSWORD
  2816. LL_DEBUGS("Login") << "Ciphering password hash: " << password
  2817. << LL_ENDL;
  2818. #endif
  2819. U8 buffer[MD5HEX_STR_BYTES + 1];
  2820. LLStringUtil::copy((char*)buffer, password.c_str(), MD5HEX_STR_BYTES + 1);
  2821. LLXORCipher cipher(gMACAddress, MAC_ADDRESS_BYTES);
  2822. cipher.encrypt(buffer, MD5HEX_STR_BYTES);
  2823. password = LLBase64::encode((const char*)buffer, MD5HEX_STR_BYTES);
  2824. #if LL_DEBUG_LOGIN_PASSWORD
  2825. LL_DEBUGS("Login") << "Base64-encoded cipher: " << password << LL_ENDL;
  2826. #endif
  2827. gSavedSettings.setString("HashedPassword", password);
  2828. }
  2829. //static
  2830. std::string LLStartUp::getMFAHashFromSettings()
  2831. {
  2832. if (!gAppViewerp->isSavedMACValid())
  2833. {
  2834. // The saved MAC address changed; we cannot reuse the saved MFA hash.
  2835. gSavedPerAccountSettings.setString("MFAHash", "");
  2836. return "";
  2837. }
  2838. std::string mfa_hash = gSavedPerAccountSettings.getString("MFAHash");
  2839. if (mfa_hash.empty())
  2840. {
  2841. return mfa_hash;
  2842. }
  2843. mfa_hash = LLBase64::decode(mfa_hash);
  2844. // Decipher with MAC address
  2845. LLXORCipher cipher(gMACAddress, MAC_ADDRESS_BYTES);
  2846. cipher.decrypt((U8*)mfa_hash.data(), mfa_hash.size());
  2847. #if LL_DEBUG_LOGIN_PASSWORD
  2848. LL_DEBUGS("Login") << "Returning MFA hash: " << mfa_hash << LL_ENDL;
  2849. #endif
  2850. return mfa_hash;
  2851. }
  2852. //static
  2853. void LLStartUp::saveMFAHashToSettings(std::string mfa_hash)
  2854. {
  2855. if (mfa_hash.empty())
  2856. {
  2857. gSavedPerAccountSettings.setString("MFAHash", mfa_hash);
  2858. return;
  2859. }
  2860. size_t len = mfa_hash.size();
  2861. #if LL_DEBUG_LOGIN_PASSWORD
  2862. LL_DEBUGS("Login") << "Ciphering MFA hash: " << mfa_hash << LL_ENDL;
  2863. #endif
  2864. U8* buffer = new U8[len + 2];
  2865. LLStringUtil::copy((char*)buffer, mfa_hash.c_str(), mfa_hash.size() + 1);
  2866. LLXORCipher cipher(gMACAddress, MAC_ADDRESS_BYTES);
  2867. cipher.encrypt(buffer, mfa_hash.size());
  2868. mfa_hash = LLBase64::encode((const char*)buffer, mfa_hash.size());
  2869. #if LL_DEBUG_LOGIN_PASSWORD
  2870. LL_DEBUGS("Login") << "Base64-encoded cipher: " << mfa_hash << LL_ENDL;
  2871. #endif
  2872. gSavedPerAccountSettings.setString("MFAHash", mfa_hash);
  2873. delete[] buffer;
  2874. }
  2875. //static
  2876. void LLStartUp::setStartupStatus(F32 frac, const std::string& string,
  2877. const std::string& msg)
  2878. {
  2879. gViewerWindowp->setProgressPercent(frac * 100.f);
  2880. gViewerWindowp->setProgressString(string);
  2881. gViewerWindowp->setProgressMessage(msg);
  2882. }
  2883. //static
  2884. bool LLStartUp::loginAlertStatus(const LLSD&, const LLSD&)
  2885. {
  2886. // At this point, sadly, nothing would work, including a login retry, the
  2887. // reason being that the viewer got half-logged in and its status is too
  2888. // unclean to retry and login from scratch.
  2889. llinfos << "Viewer only half-logged in; cannot retry from a clean state. Quitting."
  2890. << llendl;
  2891. gAppViewerp->forceQuit();
  2892. return true;
  2893. }
  2894. //static
  2895. void LLStartUp::useCircuitCallback(void**, S32 result)
  2896. {
  2897. if (!gUseCircuitCallbackCalled && !LLApp::isExiting())
  2898. {
  2899. gUseCircuitCallbackCalled = true;
  2900. if (result)
  2901. {
  2902. // Make sure user knows something bad happened. JC
  2903. llwarns << "Backing up to login screen !" << llendl;
  2904. gNotifications.add("LoginPacketNeverReceived", LLSD(), LLSD(),
  2905. loginAlertStatus);
  2906. resetLogin();
  2907. }
  2908. else
  2909. {
  2910. gGotUseCircuitCodeAck = true;
  2911. }
  2912. }
  2913. }
  2914. //static
  2915. void LLStartUp::callbackCacheName(const LLUUID& id,
  2916. const std::string& fullname,
  2917. bool is_group)
  2918. {
  2919. LL_DEBUGS("NameCache") << "Legacy cache name callback triggered, refreshing name controls"
  2920. << LL_ENDL;
  2921. LLNameListCtrl::refreshAll(id, fullname, is_group);
  2922. LLNameBox::refreshAll(id, fullname, is_group);
  2923. LLNameEditor::refreshAll(id, fullname, is_group);
  2924. // *TODO: Actually be intelligent about the refresh; for now, just brute
  2925. // force refresh the dialogs.
  2926. dialog_refresh_all();
  2927. }
  2928. //static
  2929. void LLStartUp::registerViewerCallbacks(LLMessageSystem* msg)
  2930. {
  2931. if (!msg) // Paranoia
  2932. {
  2933. llerrs << "No message system !" << llendl;
  2934. }
  2935. msg->setHandlerFuncFast(_PREHASH_LayerData, process_layer_data);
  2936. msg->setHandlerFuncFast(_PREHASH_ImageData,
  2937. LLViewerTextureList::receiveImageHeader);
  2938. msg->setHandlerFuncFast(_PREHASH_ImagePacket,
  2939. LLViewerTextureList::receiveImagePacket);
  2940. msg->setHandlerFuncFast(_PREHASH_ObjectUpdate, process_object_update);
  2941. msg->setHandlerFunc(_PREHASH_ObjectUpdateCompressed,
  2942. process_compressed_object_update);
  2943. msg->setHandlerFunc(_PREHASH_ObjectUpdateCached,
  2944. process_cached_object_update);
  2945. msg->setHandlerFuncFast(_PREHASH_ImprovedTerseObjectUpdate,
  2946. process_terse_object_update_improved);
  2947. msg->setHandlerFunc(_PREHASH_SimStats, process_sim_stats);
  2948. msg->setHandlerFuncFast(_PREHASH_HealthMessage, process_health_message);
  2949. msg->setHandlerFuncFast(_PREHASH_EconomyData, process_economy_data);
  2950. msg->setHandlerFunc(_PREHASH_RegionInfo,
  2951. LLViewerRegion::processRegionInfo);
  2952. msg->setHandlerFuncFast(_PREHASH_ChatFromSimulator,
  2953. process_chat_from_simulator);
  2954. msg->setHandlerFuncFast(_PREHASH_KillObject, process_kill_object);
  2955. msg->setHandlerFuncFast(_PREHASH_SimulatorViewerTimeMessage,
  2956. process_time_synch);
  2957. msg->setHandlerFuncFast(_PREHASH_EnableSimulator,
  2958. LLWorld::processEnableSimulator);
  2959. msg->setHandlerFuncFast(_PREHASH_DisableSimulator,
  2960. LLWorld::processDisableSimulator);
  2961. msg->setHandlerFuncFast(_PREHASH_KickUser, process_kick_user);
  2962. msg->setHandlerFunc(_PREHASH_CrossedRegion, process_crossed_region);
  2963. msg->setHandlerFuncFast(_PREHASH_TeleportFinish, process_teleport_finish);
  2964. msg->setHandlerFuncFast(_PREHASH_AlertMessage, process_alert_message);
  2965. msg->setHandlerFunc(_PREHASH_AgentAlertMessage,
  2966. process_agent_alert_message);
  2967. msg->setHandlerFuncFast(_PREHASH_MeanCollisionAlert,
  2968. process_mean_collision_alert_message);
  2969. msg->setHandlerFunc(_PREHASH_ViewerFrozenMessage, process_frozen_message);
  2970. msg->setHandlerFuncFast(_PREHASH_NameValuePair, process_name_value);
  2971. msg->setHandlerFuncFast(_PREHASH_RemoveNameValuePair,
  2972. process_remove_name_value);
  2973. msg->setHandlerFuncFast(_PREHASH_AvatarAnimation,
  2974. process_avatar_animation);
  2975. msg->setHandlerFuncFast(_PREHASH_ObjectAnimation,
  2976. process_object_animation);
  2977. msg->setHandlerFuncFast(_PREHASH_AvatarAppearance,
  2978. process_avatar_appearance);
  2979. msg->setHandlerFunc(_PREHASH_AgentCachedTextureResponse,
  2980. LLAgent::processAgentCachedTextureResponse);
  2981. msg->setHandlerFunc(_PREHASH_RebakeAvatarTextures,
  2982. LLVOAvatarSelf::processRebakeAvatarTextures);
  2983. msg->setHandlerFuncFast(_PREHASH_CameraConstraint,
  2984. process_camera_constraint);
  2985. msg->setHandlerFuncFast(_PREHASH_AvatarSitResponse,
  2986. process_avatar_sit_response);
  2987. msg->setHandlerFunc(_PREHASH_SetFollowCamProperties,
  2988. process_set_follow_cam_properties);
  2989. msg->setHandlerFunc(_PREHASH_ClearFollowCamProperties,
  2990. process_clear_follow_cam_properties);
  2991. msg->setHandlerFuncFast(_PREHASH_ImprovedInstantMessage,
  2992. process_improved_im);
  2993. msg->setHandlerFuncFast(_PREHASH_ScriptQuestion,
  2994. process_script_question);
  2995. msg->setHandlerFuncFast(_PREHASH_ObjectProperties,
  2996. LLSelectMgr::processObjectProperties);
  2997. msg->setHandlerFuncFast(_PREHASH_ObjectPropertiesFamily,
  2998. process_object_properties_family);
  2999. msg->setHandlerFunc(_PREHASH_ForceObjectSelect,
  3000. LLSelectMgr::processForceObjectSelect);
  3001. msg->setHandlerFuncFast(_PREHASH_MoneyBalanceReply,
  3002. process_money_balance_reply);
  3003. msg->setHandlerFuncFast(_PREHASH_CoarseLocationUpdate,
  3004. LLWorld::processCoarseUpdate);
  3005. msg->setHandlerFuncFast(_PREHASH_ReplyTaskInventory,
  3006. LLViewerObject::processTaskInv);
  3007. msg->setHandlerFuncFast(_PREHASH_DerezContainer,
  3008. process_derez_container);
  3009. msg->setHandlerFuncFast(_PREHASH_ScriptRunningReply,
  3010. LLLiveLSLEditor::processScriptRunningReply);
  3011. msg->setHandlerFuncFast(_PREHASH_DeRezAck, process_derez_ack);
  3012. msg->setHandlerFunc(_PREHASH_LogoutReply, process_logout_reply);
  3013. msg->setHandlerFuncFast(_PREHASH_AgentDataUpdate,
  3014. LLAgent::processAgentDataUpdate);
  3015. msg->setHandlerFuncFast(_PREHASH_AgentGroupDataUpdate,
  3016. LLAgent::processAgentGroupDataUpdate);
  3017. msg->setHandlerFunc(_PREHASH_AgentDropGroup, LLAgent::processAgentDropGroup);
  3018. // Land ownership messages
  3019. msg->setHandlerFuncFast(_PREHASH_ParcelOverlay,
  3020. LLViewerParcelMgr::processParcelOverlay);
  3021. msg->setHandlerFuncFast(_PREHASH_ParcelProperties,
  3022. LLViewerParcelMgr::processParcelProperties);
  3023. msg->setHandlerFunc(_PREHASH_ParcelAccessListReply,
  3024. LLViewerParcelMgr::processParcelAccessListReply);
  3025. msg->setHandlerFunc(_PREHASH_ParcelDwellReply,
  3026. LLViewerParcelMgr::processParcelDwellReply);
  3027. msg->setHandlerFunc(_PREHASH_AvatarPropertiesReply,
  3028. LLAvatarProperties::processAvatarPropertiesReply);
  3029. msg->setHandlerFunc(_PREHASH_AvatarInterestsReply,
  3030. LLAvatarProperties::processAvatarInterestsReply);
  3031. msg->setHandlerFunc(_PREHASH_AvatarGroupsReply,
  3032. LLAvatarProperties::processAvatarGroupsReply);
  3033. msg->setHandlerFunc(_PREHASH_AvatarNotesReply,
  3034. LLAvatarProperties::processAvatarNotesReply);
  3035. msg->setHandlerFunc(_PREHASH_AvatarPicksReply,
  3036. LLAvatarProperties::processAvatarPicksReply);
  3037. msg->setHandlerFunc(_PREHASH_AvatarClassifiedReply,
  3038. LLAvatarProperties::processAvatarClassifiedReply);
  3039. msg->setHandlerFuncFast(_PREHASH_CreateGroupReply,
  3040. LLGroupMgr::processCreateGroupReply);
  3041. msg->setHandlerFuncFast(_PREHASH_JoinGroupReply,
  3042. LLGroupMgr::processJoinGroupReply);
  3043. msg->setHandlerFuncFast(_PREHASH_EjectGroupMemberReply,
  3044. LLGroupMgr::processEjectGroupMemberReply);
  3045. msg->setHandlerFuncFast(_PREHASH_LeaveGroupReply,
  3046. LLGroupMgr::processLeaveGroupReply);
  3047. msg->setHandlerFuncFast(_PREHASH_GroupProfileReply,
  3048. LLGroupMgr::processGroupPropertiesReply);
  3049. msg->setHandlerFuncFast(_PREHASH_AgentWearablesUpdate,
  3050. LLAgentWearables::processAgentInitialWearablesUpdate);
  3051. msg->setHandlerFunc(_PREHASH_ScriptControlChange,
  3052. LLAgent::processScriptControlChange);
  3053. msg->setHandlerFuncFast(_PREHASH_ViewerEffect,
  3054. LLHUDManager::processViewerEffect);
  3055. msg->setHandlerFuncFast(_PREHASH_GrantGodlikePowers,
  3056. process_grant_godlike_powers);
  3057. msg->setHandlerFuncFast(_PREHASH_GroupAccountSummaryReply,
  3058. LLPanelGroupLandMoney::processGroupAccountSummaryReply);
  3059. msg->setHandlerFuncFast(_PREHASH_GroupAccountDetailsReply,
  3060. LLPanelGroupLandMoney::processGroupAccountDetailsReply);
  3061. msg->setHandlerFuncFast(_PREHASH_GroupAccountTransactionsReply,
  3062. LLPanelGroupLandMoney::processGroupAccountTransactionsReply);
  3063. msg->setHandlerFuncFast(_PREHASH_UserInfoReply, process_user_info_reply);
  3064. msg->setHandlerFunc(_PREHASH_RegionHandshake,
  3065. LLWorld::processRegionHandshake);
  3066. msg->setHandlerFunc(_PREHASH_TeleportStart, process_teleport_start);
  3067. msg->setHandlerFunc(_PREHASH_TeleportProgress, process_teleport_progress);
  3068. msg->setHandlerFunc(_PREHASH_TeleportFailed, process_teleport_failed);
  3069. msg->setHandlerFunc(_PREHASH_TeleportLocal, process_teleport_local);
  3070. msg->setHandlerFunc(_PREHASH_ScriptTeleportRequest,
  3071. process_script_teleport_request);
  3072. msg->setHandlerFunc(_PREHASH_ImageNotInDatabase,
  3073. LLViewerTextureList::processImageNotInDatabase);
  3074. msg->setHandlerFuncFast(_PREHASH_GroupMembersReply,
  3075. LLGroupMgr::processGroupMembersReply);
  3076. msg->setHandlerFunc(_PREHASH_GroupRoleDataReply,
  3077. LLGroupMgr::processGroupRoleDataReply);
  3078. msg->setHandlerFunc(_PREHASH_GroupRoleMembersReply,
  3079. LLGroupMgr::processGroupRoleMembersReply);
  3080. msg->setHandlerFunc(_PREHASH_GroupTitlesReply,
  3081. LLGroupMgr::processGroupTitlesReply);
  3082. // Special handler as this message is sometimes used for group land.
  3083. msg->setHandlerFunc(_PREHASH_PlacesReply, process_places_reply);
  3084. msg->setHandlerFunc(_PREHASH_GroupNoticesListReply,
  3085. LLPanelGroupNotices::processGroupNoticesListReply);
  3086. msg->setHandlerFunc(_PREHASH_DirPlacesReply,
  3087. LLPanelDirBrowser::processDirPlacesReply);
  3088. msg->setHandlerFunc(_PREHASH_DirPeopleReply,
  3089. LLPanelDirBrowser::processDirPeopleReply);
  3090. msg->setHandlerFunc(_PREHASH_DirEventsReply,
  3091. LLPanelDirBrowser::processDirEventsReply);
  3092. msg->setHandlerFunc(_PREHASH_DirGroupsReply,
  3093. LLPanelDirBrowser::processDirGroupsReply);
  3094. msg->setHandlerFunc(_PREHASH_DirClassifiedReply,
  3095. LLPanelDirBrowser::processDirClassifiedReply);
  3096. msg->setHandlerFunc(_PREHASH_DirLandReply,
  3097. LLPanelDirBrowser::processDirLandReply);
  3098. msg->setHandlerFunc(_PREHASH_AvatarPickerReply,
  3099. LLFloaterAvatarPicker::processAvatarPickerReply);
  3100. msg->setHandlerFunc(_PREHASH_MapLayerReply,
  3101. LLWorldMap::processMapLayerReply);
  3102. msg->setHandlerFunc(_PREHASH_MapBlockReply,
  3103. LLWorldMap::processMapBlockReply);
  3104. msg->setHandlerFunc(_PREHASH_MapItemReply,
  3105. LLWorldMap::processMapItemReply);
  3106. msg->setHandlerFunc(_PREHASH_EventInfoReply,
  3107. LLPanelEvent::processEventInfoReply);
  3108. msg->setHandlerFunc(_PREHASH_PickInfoReply,
  3109. LLAvatarProperties::processPickInfoReply);
  3110. msg->setHandlerFunc(_PREHASH_ClassifiedInfoReply,
  3111. LLAvatarProperties::processClassifiedInfoReply);
  3112. msg->setHandlerFunc(_PREHASH_ParcelInfoReply,
  3113. LLViewerParcelMgr::processParcelInfoReply);
  3114. msg->setHandlerFunc(_PREHASH_ScriptDialog, process_script_dialog);
  3115. msg->setHandlerFunc(_PREHASH_LoadURL, process_load_url);
  3116. msg->setHandlerFunc(_PREHASH_EstateCovenantReply, process_covenant_reply);
  3117. // Calling cards
  3118. msg->setHandlerFunc(_PREHASH_OfferCallingCard, process_offer_callingcard);
  3119. msg->setHandlerFunc(_PREHASH_AcceptCallingCard,
  3120. process_accept_callingcard);
  3121. msg->setHandlerFunc(_PREHASH_DeclineCallingCard,
  3122. process_decline_callingcard);
  3123. msg->setHandlerFunc(_PREHASH_ParcelObjectOwnersReply,
  3124. LLPanelLandObjects::processParcelObjectOwnersReply);
  3125. msg->setHandlerFunc(_PREHASH_InitiateDownload, process_initiate_download);
  3126. msg->setHandlerFunc(_PREHASH_LandStatReply,
  3127. LLFloaterTopObjects::handleLandReply);
  3128. msg->setHandlerFunc(_PREHASH_GenericMessage, process_generic_message);
  3129. msg->setHandlerFunc(_PREHASH_GenericStreamingMessage,
  3130. process_generic_streaming_message);
  3131. msg->setHandlerFunc(_PREHASH_LargeGenericMessage,
  3132. process_large_generic_message);
  3133. msg->setHandlerFuncFast(_PREHASH_FeatureDisabled,
  3134. process_feature_disabled_message);
  3135. }
  3136. // *HACK: Must match names in Library or agent inventory
  3137. const std::string COMMON_GESTURES_FOLDER = "Common Gestures";
  3138. const std::string MALE_GESTURES_FOLDER = "Male Gestures";
  3139. const std::string FEMALE_GESTURES_FOLDER = "Female Gestures";
  3140. const std::string MALE_OUTFIT_FOLDER = "Male Shape & Outfit";
  3141. const std::string FEMALE_OUTFIT_FOLDER = "Female Shape & Outfit";
  3142. constexpr S32 OPT_MALE = 0;
  3143. constexpr S32 OPT_FEMALE = 1;
  3144. //static
  3145. bool LLStartUp::callbackChooseGender(const LLSD& notification,
  3146. const LLSD& response)
  3147. {
  3148. if (LLNotification::getSelectedOption(notification, response) == OPT_MALE)
  3149. {
  3150. loadInitialOutfit(MALE_OUTFIT_FOLDER, "male");
  3151. }
  3152. else
  3153. {
  3154. loadInitialOutfit(FEMALE_OUTFIT_FOLDER, "female");
  3155. }
  3156. return false;
  3157. }
  3158. //static
  3159. void LLStartUp::loadInitialOutfit(const std::string& outfit_folder_name,
  3160. const std::string& gender_name)
  3161. {
  3162. S32 gender = 0;
  3163. std::string gestures;
  3164. if (gender_name == "male")
  3165. {
  3166. gender = OPT_MALE;
  3167. gestures = MALE_GESTURES_FOLDER;
  3168. }
  3169. else
  3170. {
  3171. gender = OPT_FEMALE;
  3172. gestures = FEMALE_GESTURES_FOLDER;
  3173. }
  3174. // Try to find the outfit: if not there, create some default wearables.
  3175. LLInventoryModel::cat_array_t cat_array;
  3176. LLInventoryModel::item_array_t item_array;
  3177. LLNameCategoryCollector has_name(outfit_folder_name);
  3178. gInventory.collectDescendentsIf(LLUUID::null, cat_array, item_array,
  3179. LLInventoryModel::EXCLUDE_TRASH,
  3180. has_name);
  3181. if (cat_array.empty())
  3182. {
  3183. gAgentWearables.createStandardWearables(gender);
  3184. }
  3185. else
  3186. {
  3187. gAppearanceMgr.wearOutfitByName(outfit_folder_name);
  3188. }
  3189. gAppearanceMgr.wearOutfitByName(gestures);
  3190. gAppearanceMgr.wearOutfitByName(COMMON_GESTURES_FOLDER);
  3191. // This is really misnamed -- it means we have started loading an
  3192. // outfit/shape that will give the avatar a gender eventually. JC
  3193. gAgent.setGenderChosen(true);
  3194. }
  3195. // Loads a bitmap to display during load
  3196. // location_id = 0 => last position
  3197. // location_id = 1 => home position
  3198. //static
  3199. void LLStartUp::initStartScreen(S32 location_id)
  3200. {
  3201. if (gStartTexture.notNull())
  3202. {
  3203. gStartTexture = NULL;
  3204. llinfos << "Re-initializing start screen" << llendl;
  3205. }
  3206. LL_DEBUGS("AppInit") << "Loading startup bitmap..." << LL_ENDL;
  3207. std::string temp_str = gDirUtil.getLindenUserDir() + LL_DIR_DELIM_STR;
  3208. if (!gIsInProductionGrid)
  3209. {
  3210. temp_str += SCREEN_LAST_BETA_FILENAME;
  3211. }
  3212. else if ((S32)START_LOCATION_ID_LAST == location_id)
  3213. {
  3214. temp_str += SCREEN_LAST_FILENAME;
  3215. }
  3216. else
  3217. {
  3218. temp_str += SCREEN_HOME_FILENAME;
  3219. }
  3220. LLPointer<LLImageBMP> start_image_bmp = new LLImageBMP;
  3221. if (!start_image_bmp->load(temp_str))
  3222. {
  3223. return;
  3224. }
  3225. llinfos << "Loaded bitmap: " << temp_str << llendl;
  3226. gStartImageWidth = start_image_bmp->getWidth();
  3227. gStartImageHeight = start_image_bmp->getHeight();
  3228. LLPointer<LLImageRaw> raw = new LLImageRaw;
  3229. if (!start_image_bmp->decode(raw))
  3230. {
  3231. llwarns << "Bitmap decode failed" << llendl;
  3232. gStartTexture = NULL;
  3233. return;
  3234. }
  3235. raw->expandToPowerOfTwo();
  3236. gStartTexture = LLViewerTextureManager::getLocalTexture(raw.get(), false);
  3237. }
  3238. //static
  3239. std::string LLStartUp::startupStateToString(EStartupState state)
  3240. {
  3241. #define RTNENUM(E) case E: return #E
  3242. switch (state)
  3243. {
  3244. RTNENUM(STATE_FIRST);
  3245. RTNENUM(STATE_BROWSER_INIT);
  3246. RTNENUM(STATE_LOGIN_SHOW);
  3247. RTNENUM(STATE_TPV_FIRST_USE);
  3248. RTNENUM(STATE_LOGIN_WAIT);
  3249. RTNENUM(STATE_LOGIN_CLEANUP);
  3250. RTNENUM(STATE_UPDATE_CHECK);
  3251. RTNENUM(STATE_LOGIN_AUTH_INIT);
  3252. RTNENUM(STATE_XMLRPC_LOGIN);
  3253. RTNENUM(STATE_LOGIN_NO_DATA_YET);
  3254. RTNENUM(STATE_LOGIN_DOWNLOADING);
  3255. RTNENUM(STATE_LOGIN_PROCESS_RESPONSE);
  3256. RTNENUM(STATE_WORLD_INIT);
  3257. RTNENUM(STATE_MULTIMEDIA_INIT);
  3258. RTNENUM(STATE_SEED_GRANTED_WAIT);
  3259. RTNENUM(STATE_SEED_CAP_GRANTED);
  3260. RTNENUM(STATE_WORLD_WAIT);
  3261. RTNENUM(STATE_AGENT_SEND);
  3262. RTNENUM(STATE_AGENT_WAIT);
  3263. RTNENUM(STATE_INVENTORY_SEND);
  3264. RTNENUM(STATE_MISC);
  3265. RTNENUM(STATE_PRECACHE);
  3266. RTNENUM(STATE_WEARABLES_WAIT);
  3267. RTNENUM(STATE_CLEANUP);
  3268. RTNENUM(STATE_STARTED);
  3269. default:
  3270. return llformat("(state #%d)", state);
  3271. }
  3272. #undef RTNENUM
  3273. }
  3274. //static
  3275. void LLStartUp::setStartupState(EStartupState state)
  3276. {
  3277. llinfos << "Startup state changing from "
  3278. << startupStateToString(sStartupState) << " to "
  3279. << startupStateToString(state) << llendl;
  3280. sStartupState = state;
  3281. }
  3282. //static
  3283. void LLStartUp::resetLogin()
  3284. {
  3285. // Save URL history file. This needs to be done on login failure because it
  3286. // gets read on *every* login attempt
  3287. LLURLHistory::saveFile("url_history.xml");
  3288. LLStartUp::setStartupState(STATE_LOGIN_SHOW);
  3289. if (gViewerWindowp)
  3290. {
  3291. // Hide menus and normal buttons
  3292. gViewerWindowp->setNormalControlsVisible(false);
  3293. gLoginMenuBarViewp->setVisible(true);
  3294. gLoginMenuBarViewp->setEnabled(true);
  3295. }
  3296. // Hide any other stuff
  3297. LLFloaterMiniMap::hideInstance();
  3298. }
  3299. // Initialize all plug-ins except the web browser (which was initialized early,
  3300. // before the login screen). JC
  3301. //static
  3302. void LLStartUp::multimediaInit()
  3303. {
  3304. LL_DEBUGS("AppInit") << "Initializing Multimedia...." << LL_ENDL;
  3305. setStartupStatus(0.42f,
  3306. LLTrans::getString("LoginInitializingMultimedia"),
  3307. gAgent.mMOTD);
  3308. display_startup();
  3309. #if 0 // Done in LLAppViewer::init()
  3310. LLViewerMedia::initClass();
  3311. #endif
  3312. LLViewerParcelMedia::initClass();
  3313. }
  3314. //static
  3315. bool LLStartUp::dispatchURL()
  3316. {
  3317. // OK, if we have gotten this far and have a startup URL
  3318. if (sStartSLURL.isSpatial())
  3319. {
  3320. // If we started with a location, but we are already at that location,
  3321. // do not pop dialogs open.
  3322. LLVector3 pos = gAgent.getPositionAgent();
  3323. LLVector3 slurlpos = sStartSLURL.getPosition();
  3324. F32 dx = pos.mV[VX] - slurlpos.mV[VX];
  3325. F32 dy = pos.mV[VY] - slurlpos.mV[VY];
  3326. constexpr F32 SLOP = 2.f; // meters
  3327. std::string region_name;
  3328. LLViewerRegion* regionp = gAgent.getRegion();
  3329. if (regionp)
  3330. {
  3331. region_name = regionp->getName();
  3332. }
  3333. if (getStartSLURL().getRegion() != region_name ||
  3334. dx * dx > SLOP * SLOP || dy * dy > SLOP * SLOP)
  3335. {
  3336. std::string url = getStartSLURL().getSLURLString();
  3337. LLMediaCtrl* web = NULL;
  3338. LLURLDispatcher::dispatch(url, "clicked", web, false);
  3339. }
  3340. return true;
  3341. }
  3342. return false;
  3343. }
  3344. //static
  3345. S32 LLStartUp::setStartSLURL(const LLSLURL& slurl)
  3346. {
  3347. if (slurl.isSpatial())
  3348. {
  3349. std::string new_start = slurl.getSLURLString();
  3350. LL_DEBUGS("Login") << "Startup SLURL: " << new_start << LL_ENDL;
  3351. sStartSLURL = slurl;
  3352. LLPanelLogin::refreshLocation(); // Updates grid if needed
  3353. // Remember that this is where we wanted to log in... If the login
  3354. // fails, the next attempt will default to the same place.
  3355. gSavedSettings.setString("NextLoginLocation", new_start);
  3356. }
  3357. else if (slurl.getType() == LLSLURL::APP && slurl.getAppCmd() == "login")
  3358. {
  3359. LL_DEBUGS("Login") << "Loging SLURL: " << slurl.getSLURLString()
  3360. << LL_ENDL;
  3361. sLoginSLURL = slurl;
  3362. }
  3363. return (S32)slurl.getType();
  3364. }
  3365. //static
  3366. bool LLStartUp::loginAlertDone(const LLSD&, const LLSD&)
  3367. {
  3368. LLPanelLogin::giveFocus();
  3369. return false;
  3370. }
  3371. /**
  3372. * Read all proxy configuration settings and set up both the HTTP proxy and
  3373. * SOCKS proxy as needed.
  3374. *
  3375. * Any errors that are encountered will result in showing the user a
  3376. * notification.
  3377. *
  3378. * @return Returns true if setup was successful, false if an error was
  3379. * encountered.
  3380. */
  3381. //static
  3382. bool LLStartUp::startLLProxy()
  3383. {
  3384. bool proxy_ok = true;
  3385. std::string proxy_type = gSavedSettings.getString("HttpProxyType");
  3386. // Set up SOCKS proxy, if needed
  3387. if (gSavedSettings.getBool("Socks5ProxyEnabled"))
  3388. {
  3389. // Determine and update LLProxy with the saved authentication system
  3390. std::string auth_type = gSavedSettings.getString("Socks5AuthType");
  3391. if (auth_type.compare("UserPass") == 0)
  3392. {
  3393. std::string socks_user = gSavedSettings.getString("Socks5Username");
  3394. std::string socks_password = gSavedSettings.getString("Socks5Password");
  3395. bool ok = LLProxy::getInstance()->setAuthPassword(socks_user,
  3396. socks_password);
  3397. if (!ok)
  3398. {
  3399. gNotifications.add("SOCKS_BAD_CREDS");
  3400. proxy_ok = false;
  3401. }
  3402. }
  3403. else if (auth_type.compare("None") == 0)
  3404. {
  3405. LLProxy::getInstance()->setAuthNone();
  3406. }
  3407. else
  3408. {
  3409. // Unknown or missing setting.
  3410. llwarns << "Invalid SOCKS 5 authentication type." << llendl;
  3411. gSavedSettings.setString("Socks5AuthType", "None");
  3412. LLProxy::getInstance()->setAuthNone();
  3413. }
  3414. if (proxy_ok)
  3415. {
  3416. // Start the proxy and check for errors. If status != SOCKS_OK,
  3417. // stopSOCKSProxy() will already have been called when
  3418. // startSOCKSProxy() returns.
  3419. LLHost socks_host;
  3420. socks_host.setHostByName(gSavedSettings.getString("Socks5ProxyHost"));
  3421. socks_host.setPort(gSavedSettings.getU32("Socks5ProxyPort"));
  3422. int status = LLProxy::getInstance()->startSOCKSProxy(socks_host);
  3423. if (status != SOCKS_OK)
  3424. {
  3425. LLSD args;
  3426. args["HOST"] = gSavedSettings.getString("Socks5ProxyHost");
  3427. args["PORT"] = (S32)gSavedSettings.getU32("Socks5ProxyPort");
  3428. std::string error_string;
  3429. switch (status)
  3430. {
  3431. case SOCKS_CONNECT_ERROR:
  3432. // TCP Fail
  3433. error_string = "SOCKS_CONNECT_ERROR";
  3434. break;
  3435. case SOCKS_NOT_PERMITTED:
  3436. // SOCKS 5 server rule set refused connection
  3437. error_string = "SOCKS_NOT_PERMITTED";
  3438. break;
  3439. case SOCKS_NOT_ACCEPTABLE:
  3440. // Selected authentication is not acceptable to server
  3441. error_string = "SOCKS_NOT_ACCEPTABLE";
  3442. break;
  3443. case SOCKS_AUTH_FAIL:
  3444. // Authentication failed
  3445. error_string = "SOCKS_AUTH_FAIL";
  3446. break;
  3447. case SOCKS_UDP_FWD_NOT_GRANTED:
  3448. // UDP forward request failed
  3449. error_string = "SOCKS_UDP_FWD_NOT_GRANTED";
  3450. break;
  3451. case SOCKS_HOST_CONNECT_FAILED:
  3452. // Failed to open a TCP channel to the socks server
  3453. error_string = "SOCKS_HOST_CONNECT_FAILED";
  3454. break;
  3455. case SOCKS_INVALID_HOST:
  3456. // Improperly formatted host address or port
  3457. error_string = "SOCKS_INVALID_HOST";
  3458. break;
  3459. default:
  3460. // Something strange happened
  3461. error_string = "SOCKS_UNKNOWN_STATUS";
  3462. llwarns << "Unknown return from LLProxy::startProxy(): "
  3463. << status << llendl;
  3464. break;
  3465. }
  3466. gNotifications.add(error_string, args);
  3467. proxy_ok = false;
  3468. }
  3469. }
  3470. }
  3471. else
  3472. {
  3473. // ensure no UDP proxy is running and it's all cleaned up
  3474. LLProxy::getInstance()->stopSOCKSProxy();
  3475. }
  3476. if (proxy_ok)
  3477. {
  3478. // Determine the HTTP proxy type (if any)
  3479. if (proxy_type.compare("Web") == 0 &&
  3480. gSavedSettings.getBool("BrowserProxyEnabled"))
  3481. {
  3482. LLHost http_host;
  3483. http_host.setHostByName(gSavedSettings.getString("BrowserProxyAddress"));
  3484. http_host.setPort(gSavedSettings.getS32("BrowserProxyPort"));
  3485. if (!LLProxy::getInstance()->enableHTTPProxy(http_host,
  3486. LLPROXY_HTTP))
  3487. {
  3488. LLSD args;
  3489. args["HOST"] = http_host.getIPString();
  3490. args["PORT"] = (S32)http_host.getPort();
  3491. gNotifications.add("PROXY_INVALID_HTTP_HOST", args);
  3492. proxy_ok = false;
  3493. }
  3494. }
  3495. else if (proxy_type.compare("Socks") == 0 &&
  3496. gSavedSettings.getBool("Socks5ProxyEnabled"))
  3497. {
  3498. LLHost socks_host;
  3499. socks_host.setHostByName(gSavedSettings.getString("Socks5ProxyHost"));
  3500. socks_host.setPort(gSavedSettings.getU32("Socks5ProxyPort"));
  3501. if (!LLProxy::getInstance()->enableHTTPProxy(socks_host,
  3502. LLPROXY_SOCKS))
  3503. {
  3504. LLSD args;
  3505. args["HOST"] = socks_host.getIPString();
  3506. args["PORT"] = (S32)socks_host.getPort();
  3507. gNotifications.add("PROXY_INVALID_SOCKS_HOST", args);
  3508. proxy_ok = false;
  3509. }
  3510. }
  3511. else if (proxy_type.compare("None") == 0)
  3512. {
  3513. LLProxy::getInstance()->disableHTTPProxy();
  3514. }
  3515. else
  3516. {
  3517. llwarns << "Invalid other HTTP proxy configuration."<< llendl;
  3518. // Set the missing or wrong configuration back to something valid.
  3519. gSavedSettings.setString("HttpProxyType", "None");
  3520. LLProxy::getInstance()->disableHTTPProxy();
  3521. // Leave proxy_ok alone, since this isn't necessarily fatal.
  3522. }
  3523. }
  3524. return proxy_ok;
  3525. }