llviewermessage.cpp 182 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714
  1. /**
  2. * @file llviewermessage.cpp
  3. * @brief Dumping ground for viewer-side message system callbacks.
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-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 <deque>
  34. #include "llviewermessage.h"
  35. #include "llanimationstates.h" // For ANIM_AGENT_PUPPET_MOTION
  36. #include "llaudioengine.h"
  37. #include "llassetstorage.h"
  38. #include "llcachename.h"
  39. #include "llcallbacklist.h"
  40. #include "llconsole.h"
  41. #include "lldbstrings.h"
  42. #include "lldir.h"
  43. #include "lldispatcher.h"
  44. #include "lleconomy.h"
  45. #include "llevents.h"
  46. #include "lleventtimer.h"
  47. #include "llexperiencecache.h"
  48. #include "llfasttimer.h"
  49. #include "llfilesystem.h"
  50. #include "llmaterialtable.h"
  51. #include "llmd5.h"
  52. #include "llmenugl.h"
  53. #include "llregionflags.h"
  54. #include "llregionhandle.h"
  55. #include "llscriptpermissions.h"
  56. #include "llsdserialize.h"
  57. #include "llteleportflags.h"
  58. #include "lltracker.h"
  59. #include "lltrans.h"
  60. #include "lltransactionflags.h"
  61. #include "lluploaddialog.h"
  62. #include "llxfermanager.h"
  63. #include "llmessage.h"
  64. #include "sound_ids.h"
  65. #include "llagent.h"
  66. #include "llagentpilot.h"
  67. #include "llappearancemgr.h"
  68. #include "llappviewer.h"
  69. #include "llavatartracker.h"
  70. #include "lldrawpool.h"
  71. #include "llexperiencelog.h" // For PUMP_EXPERIENCE
  72. #include "llfirstuse.h"
  73. #include "llfloateractivespeakers.h"
  74. #include "hbfloaterareasearch.h"
  75. #include "hbfloaterbump.h"
  76. #include "llfloaterbuycurrency.h"
  77. #include "llfloaterbuyland.h"
  78. #include "llfloaterchat.h"
  79. #include "llfloatergroupinfo.h"
  80. #include "llfloaterim.h"
  81. #include "llfloaterinventory.h"
  82. #include "llfloaterland.h"
  83. #include "llfloaterlandholdings.h"
  84. #include "llfloatermute.h"
  85. #include "llfloaterpostcard.h"
  86. #include "llfloaterpreference.h"
  87. #include "llfloaterregioninfo.h"
  88. #include "hbfloatersearch.h"
  89. #include "hbfloatersoundslist.h"
  90. #include "hbfloaterteleporthistory.h"
  91. #include "llfloaterworldmap.h"
  92. #include "llfolderview.h"
  93. #include "llfollowcam.h"
  94. #include "llgltfmateriallist.h"
  95. #include "llgridmanager.h"
  96. #include "llgroupnotify.h"
  97. #include "llhudeffect.h"
  98. #include "llhudeffectspiral.h"
  99. #include "llimmgr.h"
  100. #include "llinventoryactions.h"
  101. #include "llinventorymodel.h"
  102. #include "llmarketplacefunctions.h"
  103. #include "llmutelist.h"
  104. #include "llnotify.h"
  105. #include "llpanelgrouplandmoney.h"
  106. #include "llpipeline.h"
  107. #include "llpuppetmodule.h"
  108. #include "llpuppetmotion.h"
  109. //MK
  110. #include "mkrlinterface.h"
  111. //mk
  112. #include "llselectmgr.h"
  113. #include "llslurl.h"
  114. #include "llstartup.h"
  115. #include "llsky.h"
  116. #include "llstatusbar.h"
  117. #include "lltool.h"
  118. #include "lltoolbar.h"
  119. #include "lltoolmgr.h"
  120. #include "llurldispatcher.h"
  121. #include "llvieweraudio.h"
  122. #include "hbviewerautomation.h"
  123. #include "llviewercamera.h"
  124. #include "llviewercontrol.h"
  125. #include "llviewerdisplay.h"
  126. #include "llviewerinventory.h"
  127. #include "llviewerjoystick.h"
  128. #include "llviewermenu.h"
  129. #include "llviewerobject.h"
  130. #include "llviewerobjectlist.h"
  131. #include "llviewerparcelmgr.h"
  132. #include "llviewerpartsource.h"
  133. #include "llviewerregion.h"
  134. #include "llviewerstats.h"
  135. #include "llviewertexteditor.h"
  136. #include "llviewerthrottle.h"
  137. #include "llviewerwindow.h"
  138. #include "llvlmanager.h"
  139. #include "llvoavatarpuppet.h"
  140. #include "llvoavatarself.h"
  141. #include "llweb.h"
  142. #include "llwlskyparammgr.h"
  143. #include "llwlwaterparammgr.h"
  144. #include "llworld.h"
  145. #include "llworldmap.h"
  146. // Set to 1 to automatically accept and open offered scripts: since those are
  147. // most often closed sources (no-mod), and a "giver" script also often offers
  148. // itself (wrongly) when opening scripted boxes, I find it more annoying than
  149. // anything else, so it is disabled in the Cool VL Viewer. *TODO, maybe: add
  150. // two debug settings to also auto-accepting and/or auto-opening scripts ? HB
  151. #define HB_AUTO_ACCEPT_OPEN_SCRIPTS 0
  152. //
  153. // Constants
  154. //
  155. // Determine how quickly residents' scripts can issue question dialogs. Allow
  156. // bursts of up to 5 dialogs in 10 seconds. 10*2=20 seconds recovery if
  157. // throttle kicks in
  158. constexpr U32 LLREQUEST_PERMISSION_THROTTLE_LIMIT = 5; // Requests
  159. constexpr F32 LLREQUEST_PERMISSION_THROTTLE_INTERVAL = 10.f; // Seconds
  160. // Generic message dispatcher
  161. LLDispatcher gGenericDispatcher;
  162. // Inventory offer throttle globals
  163. LLFrameTimer gThrottleTimer;
  164. constexpr U32 OFFER_THROTTLE_MAX_COUNT = 5; // Number of items per time period
  165. constexpr F32 OFFER_THROTTLE_TIME = 10.f; // Time period in seconds
  166. // Agent Update Flags (U8)
  167. constexpr U8 AU_FLAGS_NONE = 0x00;
  168. constexpr U8 AU_FLAGS_HIDETITLE = 0x01;
  169. constexpr U8 AU_FLAGS_CLIENT_AUTOPILOT = 0x02;
  170. // Script permissions
  171. static const std::string SCRIPT_QUESTIONS[SCRIPT_PERMISSION_EOF] = {
  172. "ScriptTakeMoney",
  173. "ActOnControlInputs",
  174. "RemapControlInputs",
  175. "AnimateYourAvatar",
  176. "AttachToYourAvatar",
  177. "ReleaseOwnership",
  178. "LinkAndDelink",
  179. "AddAndRemoveJoints",
  180. "ChangePermissions",
  181. "TrackYourCamera",
  182. "ControlYourCamera",
  183. "TeleportYourAgent",
  184. "JoinAnExperience",
  185. "SilentEstateManagement",
  186. "OverrideAgentAnimations",
  187. "ScriptReturnObjects",
  188. "ForceSitAvatar",
  189. "ChangeEnvSettings"
  190. };
  191. static const bool SCRIPT_QUESTION_IS_CAUTION[SCRIPT_PERMISSION_EOF] = {
  192. true, // ScriptTakeMoney
  193. false, // ActOnControlInputs
  194. false, // RemapControlInputs
  195. false, // AnimateYourAvatar
  196. false, // AttachToYourAvatar
  197. false, // ReleaseOwnership
  198. false, // LinkAndDelink
  199. false, // AddAndRemoveJoints
  200. false, // ChangePermissions
  201. false, // TrackYourCamera
  202. false, // ControlYourCamera
  203. false, // TeleportYourAgent
  204. false, // JoinAnExperience
  205. false, // SilentEstateManagement
  206. false, // OverrideAgentAnimations
  207. false, // ScriptReturnObjects
  208. false, // ForceSitAvatar
  209. false // ChangeEnvSettings
  210. };
  211. ///////////////////////////////////////////////////////////////////////////////
  212. // LLKeyThrottle template. It used to be in llcommon/llkeythrottle.h, but since
  213. // it is only used here, there is no point in keeping it in a separate file...
  214. ///////////////////////////////////////////////////////////////////////////////
  215. // LLKeyThrottle keeps track of the number of action occurences with a key
  216. // value for a type over a given time period. If the rate set in the
  217. // constructor is exceeed, the key is considered blocked. The transition from
  218. // unblocked to blocked is noted so the responsible agent can be informed. This
  219. // transition takes twice the look back window to clear.
  220. // Forward declaration so LLKeyThrottleImpl can befriend it
  221. template <class T> class LLKeyThrottle;
  222. // Implementation utility class - use LLKeyThrottle, not this
  223. template <class T>
  224. class LLKeyThrottleImpl
  225. {
  226. friend class LLKeyThrottle<T>;
  227. protected:
  228. LLKeyThrottleImpl()
  229. : mPrevMap(NULL),
  230. mCurrMap(NULL),
  231. mCountLimit(0),
  232. mIntervalLength(1),
  233. mStartTime(0)
  234. {
  235. }
  236. LL_INLINE static U64 getTime()
  237. {
  238. return LLFrameTimer::getTotalTime();
  239. }
  240. LL_INLINE static U64 getFrame() // Return the current frame number
  241. {
  242. return (U64)LLFrameTimer::getFrameCount();
  243. }
  244. protected:
  245. struct Entry
  246. {
  247. Entry()
  248. : mCount(0),
  249. mBlocked(false)
  250. {
  251. }
  252. U32 mCount;
  253. bool mBlocked;
  254. };
  255. typedef std::map<T, Entry> entry_map_t;
  256. entry_map_t* mPrevMap;
  257. entry_map_t* mCurrMap;
  258. // Each map covers this time period (usec or frame number)
  259. U64 mIntervalLength;
  260. // Start of the time period (usec or frame number); mCurrMap started
  261. // counting at this time while mPrevMap covers the previous interval.
  262. U64 mStartTime;
  263. // Maximum number of keys allowed per interval
  264. U32 mCountLimit;
  265. };
  266. template<class T>
  267. class LLKeyThrottle
  268. {
  269. public:
  270. // realtime = false for frame-based throttle, true for usec real-time
  271. // throttle
  272. LLKeyThrottle(U32 limit, F32 interval, bool realtime = true)
  273. : mImpl(*new LLKeyThrottleImpl<T>)
  274. {
  275. setParameters(limit, interval, realtime);
  276. }
  277. ~LLKeyThrottle()
  278. {
  279. delete mImpl.mPrevMap;
  280. delete mImpl.mCurrMap;
  281. delete &mImpl;
  282. }
  283. enum State
  284. {
  285. THROTTLE_OK, // Rate not exceeded, let pass
  286. THROTTLE_NEWLY_BLOCKED, // Rate exceed for the first time
  287. THROTTLE_BLOCKED, // Rate exceed, block key
  288. };
  289. F64 getActionCount(const T& id)
  290. {
  291. U64 now = 0;
  292. if (mIsRealtime)
  293. {
  294. now = LLKeyThrottleImpl<T>::getTime();
  295. }
  296. else
  297. {
  298. now = LLKeyThrottleImpl<T>::getFrame();
  299. }
  300. if (now >= mImpl.mStartTime + mImpl.mIntervalLength)
  301. {
  302. if (now < mImpl.mStartTime + 2 * mImpl.mIntervalLength)
  303. {
  304. // Prune old data
  305. delete mImpl.mPrevMap;
  306. mImpl.mPrevMap = mImpl.mCurrMap;
  307. mImpl.mCurrMap =
  308. new typename LLKeyThrottleImpl<T>::entry_map_t;
  309. mImpl.mStartTime += mImpl.mIntervalLength;
  310. }
  311. else
  312. {
  313. // Lots of time has passed, all data is stale
  314. delete mImpl.mPrevMap;
  315. delete mImpl.mCurrMap;
  316. mImpl.mPrevMap =
  317. new typename LLKeyThrottleImpl<T>::entry_map_t;
  318. mImpl.mCurrMap =
  319. new typename LLKeyThrottleImpl<T>::entry_map_t;
  320. mImpl.mStartTime = now;
  321. }
  322. }
  323. U32 prev_cnt = 0;
  324. typename LLKeyThrottleImpl<T>::entry_map_t::const_iterator prev =
  325. mImpl.mPrevMap->find(id);
  326. if (prev != mImpl.mPrevMap->end())
  327. {
  328. prev_cnt = prev->second.mCount;
  329. }
  330. typename LLKeyThrottleImpl<T>::Entry& curr = (*mImpl.mCurrMap)[id];
  331. // Compute current, windowed rate
  332. F64 time_in_current = (F64)(now - mImpl.mStartTime) /
  333. mImpl.mIntervalLength;
  334. return curr.mCount + prev_cnt * (1.0 - time_in_current);
  335. }
  336. // Call each time the key wants use
  337. State noteAction(const T& id, S32 weight = 1)
  338. {
  339. U64 now;
  340. if (mIsRealtime)
  341. {
  342. now = LLKeyThrottleImpl<T>::getTime();
  343. }
  344. else
  345. {
  346. now = LLKeyThrottleImpl<T>::getFrame();
  347. }
  348. if (now >= mImpl.mStartTime + mImpl.mIntervalLength)
  349. {
  350. if (now < mImpl.mStartTime + 2 * mImpl.mIntervalLength)
  351. {
  352. // Prune old data
  353. delete mImpl.mPrevMap;
  354. mImpl.mPrevMap = mImpl.mCurrMap;
  355. mImpl.mCurrMap =
  356. new typename LLKeyThrottleImpl<T>::entry_map_t;
  357. mImpl.mStartTime += mImpl.mIntervalLength;
  358. }
  359. else
  360. {
  361. // Lots of time has passed, all data is stale
  362. delete mImpl.mPrevMap;
  363. delete mImpl.mCurrMap;
  364. mImpl.mPrevMap =
  365. new typename LLKeyThrottleImpl<T>::entry_map_t;
  366. mImpl.mCurrMap =
  367. new typename LLKeyThrottleImpl<T>::entry_map_t;
  368. mImpl.mStartTime = now;
  369. }
  370. }
  371. U32 prev_cnt = 0;
  372. bool prev_blocked = false;
  373. typename LLKeyThrottleImpl<T>::entry_map_t::const_iterator prev =
  374. mImpl.mPrevMap->find(id);
  375. if (prev != mImpl.mPrevMap->end())
  376. {
  377. prev_cnt = prev->second.mCount;
  378. prev_blocked = prev->second.mBlocked;
  379. }
  380. typename LLKeyThrottleImpl<T>::Entry& curr = (*mImpl.mCurrMap)[id];
  381. // curr.mCount is the number of keys in this current 'time slice' from
  382. // the beginning of it until now prev_cnt is the number of keys in the
  383. // previous time slice scaled to be one full time slice back from the
  384. // current (now) time.
  385. curr.mCount += weight;
  386. // Compute current, windowed rate
  387. F64 time_in_current = ((F64)(now - mImpl.mStartTime) /
  388. mImpl.mIntervalLength);
  389. F64 average_cnt = curr.mCount + prev_cnt * (1.0 - time_in_current);
  390. bool was_blocked = curr.mBlocked;
  391. curr.mBlocked |= average_cnt > mImpl.mCountLimit;
  392. if (!prev_blocked && !curr.mBlocked)
  393. {
  394. return THROTTLE_OK;
  395. }
  396. if (!prev_blocked && !was_blocked)
  397. {
  398. return THROTTLE_NEWLY_BLOCKED;
  399. }
  400. return THROTTLE_BLOCKED;
  401. }
  402. // Call to force throttle conditions for id
  403. void throttleAction(const T& id)
  404. {
  405. noteAction(id);
  406. typename LLKeyThrottleImpl<T>::Entry& curr = (*mImpl.mCurrMap)[id];
  407. curr.mCount = llmax(mImpl.mCountLimit, curr.mCount);
  408. curr.mBlocked = true;
  409. }
  410. // Returns true if key is blocked
  411. bool isThrottled(const T& id) const
  412. {
  413. if (mImpl.mCurrMap->empty() && mImpl.mPrevMap->empty())
  414. {
  415. // Most of the time we will fall in here
  416. return false;
  417. }
  418. // NOTE, we ignore the case where id is in the map but the map is
  419. // stale. You might think that we'd stop throttling things in such a
  420. // case, however it may be that a "god" has disabled scripts in the
  421. // region or estate and we probably want to report the state of the Id
  422. // when the scripting engine was paused.
  423. typename LLKeyThrottleImpl<T>::entry_map_t::const_iterator entry =
  424. mImpl.mCurrMap->find(id);
  425. if (entry != mImpl.mCurrMap->end())
  426. {
  427. return entry->second.mBlocked;
  428. }
  429. entry = mImpl.mPrevMap->find(id);
  430. return entry != mImpl.mPrevMap->end() && entry->second.mBlocked;
  431. }
  432. // Gets the throttling parameters
  433. void getParameters(U32& out_limit, F32& out_interval, bool& out_realtime)
  434. {
  435. out_limit = mImpl.mCountLimit;
  436. out_interval = mImpl.mIntervalLength;
  437. out_realtime = mIsRealtime;
  438. }
  439. // Sets the throttling behavior
  440. void setParameters(U32 limit, F32 interval, bool realtime = true)
  441. {
  442. // 'limit' is the maximum number of keys allowed per interval (in
  443. // seconds or frames)
  444. mIsRealtime = realtime;
  445. mImpl.mCountLimit = limit;
  446. if (mIsRealtime)
  447. {
  448. mImpl.mIntervalLength = (U64)(interval * USEC_PER_SEC);
  449. mImpl.mStartTime = LLKeyThrottleImpl<T>::getTime();
  450. }
  451. else
  452. {
  453. mImpl.mIntervalLength = (U64)interval;
  454. mImpl.mStartTime = LLKeyThrottleImpl<T>::getFrame();
  455. }
  456. if (mImpl.mIntervalLength == 0)
  457. {
  458. // Do not allow zero intervals
  459. mImpl.mIntervalLength = 1;
  460. }
  461. delete mImpl.mPrevMap;
  462. mImpl.mPrevMap = new typename LLKeyThrottleImpl<T>::entry_map_t;
  463. delete mImpl.mCurrMap;
  464. mImpl.mCurrMap = new typename LLKeyThrottleImpl<T>::entry_map_t;
  465. }
  466. protected:
  467. LLKeyThrottleImpl<T>& mImpl;
  468. // true to be time based (default), FALSE for frame based:
  469. bool mIsRealtime;
  470. };
  471. ///////////////////////////////////////////////////////////////////////////////
  472. // Functions
  473. ///////////////////////////////////////////////////////////////////////////////
  474. void give_money(const LLUUID& uuid, LLViewerRegion* region, S32 amount,
  475. bool is_group, S32 trx_type, const std::string& desc)
  476. {
  477. if (amount <= 0 || !region) return;
  478. if (uuid.isNull())
  479. {
  480. llwarns << "Cannot give money to to null UUID target !" << llendl;
  481. return;
  482. }
  483. llinfos << "give_money(" << uuid << "," << amount << ")"<< llendl;
  484. if (can_afford_transaction(amount))
  485. {
  486. #if 0
  487. gStatusBarp->debitBalance(amount);
  488. #endif
  489. LLMessageSystem* msg = gMessageSystemp;
  490. msg->newMessageFast(_PREHASH_MoneyTransferRequest);
  491. msg->nextBlockFast(_PREHASH_AgentData);
  492. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  493. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  494. msg->nextBlockFast(_PREHASH_MoneyData);
  495. msg->addUUIDFast(_PREHASH_SourceID, gAgentID);
  496. msg->addUUIDFast(_PREHASH_DestID, uuid);
  497. msg->addU8Fast(_PREHASH_Flags,
  498. pack_transaction_flags(false, is_group));
  499. msg->addS32Fast(_PREHASH_Amount, amount);
  500. msg->addU8Fast(_PREHASH_AggregatePermNextOwner,
  501. (U8)LLAggregatePermissions::AP_EMPTY);
  502. msg->addU8Fast(_PREHASH_AggregatePermInventory,
  503. (U8)LLAggregatePermissions::AP_EMPTY);
  504. msg->addS32Fast(_PREHASH_TransactionType, trx_type);
  505. msg->addStringFast(_PREHASH_Description, desc);
  506. msg->sendReliable(region->getHost());
  507. }
  508. else
  509. {
  510. LLFloaterBuyCurrency::buyCurrency("Giving", amount);
  511. }
  512. }
  513. void send_complete_agent_movement(const LLHost& sim_host)
  514. {
  515. LLMessageSystem* msg = gMessageSystemp;
  516. msg->newMessageFast(_PREHASH_CompleteAgentMovement);
  517. msg->nextBlockFast(_PREHASH_AgentData);
  518. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  519. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  520. msg->addU32Fast(_PREHASH_CircuitCode, msg->mOurCircuitCode);
  521. msg->sendReliable(sim_host);
  522. // Close any old notification about a restarting sim
  523. LLNotifyBox::closeLastNotifyRestart();
  524. // Inform interested floaters that we arrived in a new region (no need to
  525. // use boost signals or any other complex mechanism since these are static
  526. // methods used to clear static caches not depending on an actually open
  527. // and live floater).
  528. HBFloaterAreaSearch::newRegion();
  529. HBFloaterSoundsList::newRegion();
  530. }
  531. void process_logout_reply(LLMessageSystem* msg, void**)
  532. {
  533. // The server has told us it is ok to quit.
  534. LL_DEBUGS("Messaging") << "Logout reply" << LL_ENDL;
  535. LLUUID agent_id;
  536. msg->getUUID(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  537. LLUUID session_id;
  538. msg->getUUID(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
  539. if (agent_id != gAgentID || session_id != gAgentSessionID)
  540. {
  541. llwarns << "Bogus Logout Reply" << llendl;
  542. }
  543. LLInventoryModel::update_map_t parents;
  544. S32 count = msg->getNumberOfBlocksFast(_PREHASH_InventoryData);
  545. for (S32 i = 0; i < count; ++i)
  546. {
  547. LLUUID item_id;
  548. msg->getUUIDFast(_PREHASH_InventoryData, _PREHASH_ItemID, item_id, i);
  549. if (count == 1 && item_id.isNull())
  550. {
  551. // Detect dummy item. Indicates an empty list.
  552. break;
  553. }
  554. // We do not need to track the asset ids, just account for an updated
  555. // inventory version.
  556. llinfos << "Processing item: " << item_id << llendl;
  557. LLInventoryItem* item = gInventory.getItem(item_id);
  558. if (item)
  559. {
  560. parents[item->getParentUUID()] = 0;
  561. gInventory.addChangedMask(LLInventoryObserver::INTERNAL, item_id);
  562. }
  563. else
  564. {
  565. llinfos << "Item not found: " << item_id << llendl;
  566. }
  567. }
  568. gAppViewerp->forceQuit();
  569. }
  570. void process_layer_data(LLMessageSystem* msg, void**)
  571. {
  572. LLViewerRegion* regionp;
  573. regionp = gWorld.getRegion(msg->getSender());
  574. if (!regionp)
  575. {
  576. return;
  577. }
  578. S8 type;
  579. msg->getS8Fast(_PREHASH_LayerID, _PREHASH_Type, type);
  580. S32 size = msg->getSizeFast(_PREHASH_LayerData, _PREHASH_Data);
  581. if (size == 0)
  582. {
  583. llwarns << "Layer data has zero size." << llendl;
  584. return;
  585. }
  586. if (size < 0)
  587. {
  588. // getSizeFast() is probably trying to tell us about an error
  589. llwarns << "getSizeFast() returned negative result: " << size
  590. << llendl;
  591. return;
  592. }
  593. if (type == CLOUD_LAYER_CODE)
  594. {
  595. static LLCachedControl<bool> sparse_clouds(gSavedSettings,
  596. "SparseClassicClouds");
  597. if (!LLCloudLayer::needClassicClouds())
  598. {
  599. // The user does not want classic clouds, or the clouds are past
  600. // the draw distance.
  601. regionp->mCloudLayer.resetDensity();
  602. return;
  603. }
  604. else if (sparse_clouds && !regionp->mCloudLayer.shouldUpdateDensity())
  605. {
  606. // We already updated this region's layer during the past second
  607. // and the user wishes to sparse update messages.
  608. return;
  609. }
  610. }
  611. U8* datap = new U8[size];
  612. msg->getBinaryDataFast(_PREHASH_LayerData, _PREHASH_Data, datap, size);
  613. LLVLData* vl_datap = new LLVLData(regionp, type, datap, size);
  614. if (msg->getReceiveCompressedSize())
  615. {
  616. gVLManager.addLayerData(vl_datap, msg->getReceiveCompressedSize());
  617. }
  618. else
  619. {
  620. gVLManager.addLayerData(vl_datap, msg->getReceiveSize());
  621. }
  622. if (!regionp->mGotClouds)
  623. {
  624. if (type == CLOUD_LAYER_CODE)
  625. {
  626. // The server is providing us with cloud data for this region.
  627. regionp->mGotClouds = true;
  628. }
  629. else if (type == WIND_LAYER_CODE)
  630. {
  631. if (!LLCloudLayer::needClassicClouds())
  632. {
  633. // The user does not want classic clouds or the clouds are past
  634. // the draw distance: remove them.
  635. regionp->mCloudLayer.resetDensity();
  636. }
  637. else if (regionp->mFirstWindLayerReceivedTime == 0.f)
  638. {
  639. // Remember the time when we first received a wind layer data
  640. // packet
  641. regionp->mFirstWindLayerReceivedTime = gFrameTimeSeconds;
  642. }
  643. else if (gFrameTimeSeconds -
  644. regionp->mFirstWindLayerReceivedTime >= 3.f)
  645. {
  646. // Over three seconds elapsed since the fist wind data layer
  647. // was received and we still did not get any cloud layer data;
  648. // the server is obviously not sending classic clouds data...
  649. // Generate or update the random cloud cover probability matrix
  650. // at each new wind layer data.
  651. regionp->mCloudLayer.generateDensity();
  652. }
  653. }
  654. }
  655. }
  656. void process_derez_ack(LLMessageSystem*, void**)
  657. {
  658. if (gWindowp)
  659. {
  660. gWindowp->decBusyCount();
  661. }
  662. }
  663. void process_places_reply(LLMessageSystem* msg, void** data)
  664. {
  665. LLUUID query_id;
  666. msg->getUUID(_PREHASH_AgentData, _PREHASH_QueryID, query_id);
  667. if (query_id.isNull())
  668. {
  669. LLFloaterLandHoldings::processPlacesReply(msg, data);
  670. }
  671. else if (gAgent.isInGroup(query_id))
  672. {
  673. LLPanelGroupLandMoney::processPlacesReply(msg, data);
  674. }
  675. else
  676. {
  677. llwarns << "Got invalid PlacesReply message" << llendl;
  678. }
  679. }
  680. void send_sound_trigger(const LLUUID& sound_id, F32 gain)
  681. {
  682. if (sound_id.isNull() || !gAgent.getRegion())
  683. {
  684. // Disconnected agent or zero guids do not get sent (no sound)
  685. return;
  686. }
  687. LLMessageSystem* msg = gMessageSystemp;
  688. msg->newMessageFast(_PREHASH_SoundTrigger);
  689. msg->nextBlockFast(_PREHASH_SoundData);
  690. msg->addUUIDFast(_PREHASH_SoundID, sound_id);
  691. // Client untrusted, ids set on sim
  692. msg->addUUIDFast(_PREHASH_OwnerID, LLUUID::null);
  693. msg->addUUIDFast(_PREHASH_ObjectID, LLUUID::null);
  694. msg->addUUIDFast(_PREHASH_ParentID, LLUUID::null);
  695. msg->addU64Fast(_PREHASH_Handle, gAgent.getRegionHandle());
  696. LLVector3 position = gAgent.getPositionAgent();
  697. msg->addVector3Fast(_PREHASH_Position, position);
  698. msg->addF32Fast(_PREHASH_Gain, gain);
  699. gAgent.sendMessage();
  700. }
  701. //-----------------------------------------------------------------------------
  702. // Instant Message
  703. //-----------------------------------------------------------------------------
  704. class LLOpenAgentOffer final : public LLInventoryFetchObserver
  705. {
  706. protected:
  707. LOG_CLASS(LLOpenAgentOffer);
  708. public:
  709. LLOpenAgentOffer(const std::string& from_name)
  710. : mFromName(from_name),
  711. mRetried(false)
  712. {
  713. }
  714. void fetchItems(const uuid_vec_t& ids) override
  715. {
  716. mFetchedItems = ids;
  717. LLInventoryFetchObserver::fetchItems(ids);
  718. }
  719. void done() override
  720. {
  721. size_t incomplete = mIncomplete.size();
  722. if (incomplete)
  723. {
  724. llwarns << "Incomplete fetch for " << incomplete << " items."
  725. << llendl;
  726. }
  727. uuid_vec_t* completed_vecp = &mComplete;
  728. if (mComplete.empty() && incomplete != mFetchedItems.size())
  729. {
  730. llwarns << "Observer for " << mFromName
  731. << "'s offer done with empty completed items list."
  732. << llendl;
  733. if (!mRetried)
  734. {
  735. llinfos << "Retrying offered items fetch for "
  736. << mFromName << llendl;
  737. mRetried = true;
  738. LLInventoryFetchObserver::fetchItems(mFetchedItems);
  739. return;
  740. }
  741. llinfos << "Trying to open items nonetheless for " << mFromName
  742. << llendl;
  743. completed_vecp = &mFetchedItems;
  744. }
  745. open_inventory_offer(*completed_vecp, mFromName);
  746. gInventory.removeObserver(this);
  747. delete this;
  748. }
  749. private:
  750. uuid_vec_t mFetchedItems;
  751. std::string mFromName;
  752. bool mRetried;
  753. };
  754. // Unlike the FetchObserver for AgentOffer, we only make one instance of the
  755. // AddedObserver for TaskOffers and it never dies. We do this because we do not
  756. // know the UUID of task offers until they are accepted, we do not know what to
  757. // watch for, so instead we just watch for all additions.
  758. class LLOpenTaskOffer : public LLInventoryAddedObserver
  759. {
  760. protected:
  761. void done() override
  762. {
  763. open_inventory_offer(mAdded, "added inventory observer");
  764. mAdded.clear();
  765. }
  766. };
  767. // One global task offer observer instance to bind them
  768. LLOpenTaskOffer* gNewInventoryObserverp = NULL;
  769. void start_new_inventory_observer()
  770. {
  771. if (!gNewInventoryObserverp)
  772. {
  773. // Observer is deleted by gInventory
  774. gNewInventoryObserverp = new LLOpenTaskOffer;
  775. gInventory.addObserver(gNewInventoryObserverp);
  776. }
  777. }
  778. void stop_new_inventory_observer()
  779. {
  780. if (gNewInventoryObserverp)
  781. {
  782. gInventory.removeObserver(gNewInventoryObserverp);
  783. delete gNewInventoryObserverp;
  784. gNewInventoryObserverp = NULL;
  785. }
  786. }
  787. class LLDiscardAgentOffer final : public LLInventoryFetchComboObserver
  788. {
  789. protected:
  790. LOG_CLASS(LLDiscardAgentOffer);
  791. public:
  792. LLDiscardAgentOffer(const LLUUID& folder_id, const LLUUID& object_id)
  793. : mFolderID(folder_id),
  794. mObjectID(object_id)
  795. {
  796. }
  797. void done() override
  798. {
  799. LL_DEBUGS("InventoryOffer") << "Discard done, Scheduling removal of item: "
  800. << mObjectID << LL_ENDL;
  801. // We are invoked from LLInventoryModel::notifyObservers(); should we
  802. // try to remove the inventory item now, it would cause a nested call
  803. // to notifyObservers() call, which would not work. So defer moving the
  804. // item to trash until viewer gets idle (in a moment).
  805. // Note: I migrated this code from the now removed LLDeferredTaskList
  806. // mechanism (that was only used here) to standard idle callbacks.
  807. doOnIdleOneTime(boost::bind(&LLDiscardAgentOffer::oneShotIdleCallback,
  808. this));
  809. gInventory.removeObserver(this);
  810. }
  811. private:
  812. void oneShotIdleCallback()
  813. {
  814. LL_DEBUGS("InventoryOffer") << "Removing item: " << mObjectID
  815. << LL_ENDL;
  816. gInventory.removeItem(mObjectID);
  817. // Commit suicide.
  818. delete this;
  819. }
  820. private:
  821. LLUUID mFolderID;
  822. LLUUID mObjectID;
  823. };
  824. // Returns true if we are OK, false if we are throttled. Set check_only to true
  825. // if you want to know the throttle status without registering a hit
  826. bool check_offer_throttle(const std::string& from_name, bool check_only)
  827. {
  828. static U32 throttle_count;
  829. static bool throttle_logged;
  830. LLChat chat;
  831. std::string log_message;
  832. if (!gSavedSettings.getBool("ShowNewInventory"))
  833. {
  834. return false;
  835. }
  836. if (check_only)
  837. {
  838. return gThrottleTimer.hasExpired();
  839. }
  840. if (gThrottleTimer.checkExpirationAndReset(OFFER_THROTTLE_TIME))
  841. {
  842. LL_DEBUGS("InventoryOffer") << "Throttle expired." << LL_ENDL;
  843. throttle_count = 1;
  844. throttle_logged = false;
  845. return true;
  846. }
  847. else // Has not yet expired
  848. {
  849. LL_DEBUGS("InventoryOffer") << "Throttle not expired, count: "
  850. << throttle_count << LL_ENDL;
  851. // When downloading the initial inventory we get a lot of new items
  852. // coming in and cannot tell that from spam.
  853. if (LLStartUp::isLoggedIn() &&
  854. throttle_count >= OFFER_THROTTLE_MAX_COUNT)
  855. {
  856. if (!throttle_logged)
  857. {
  858. // Use the name of the last item giver, who is probably the
  859. // person spamming you.
  860. std::ostringstream message;
  861. message << gSecondLife;
  862. if (!from_name.empty())
  863. {
  864. message << ": Items coming in too fast from " << from_name;
  865. }
  866. else
  867. {
  868. message << ": Items coming in too fast";
  869. }
  870. message << ", automatic preview disabled for "
  871. << OFFER_THROTTLE_TIME << " seconds.";
  872. chat.mText = message.str();
  873. // This is relatively important, so actually put it on screen
  874. LLFloaterChat::addChat(chat, false, false);
  875. throttle_logged = true;
  876. }
  877. return false;
  878. }
  879. else
  880. {
  881. ++throttle_count;
  882. return true;
  883. }
  884. }
  885. }
  886. void open_inventory_offer(const uuid_vec_t& items,
  887. const std::string& from_name)
  888. {
  889. LL_DEBUGS("InventoryOffer") << "Offer from: " << from_name
  890. << " - Number of items to process: "
  891. << items.size() << LL_ENDL;
  892. if (items.empty())
  893. {
  894. return;
  895. }
  896. const LLUUID& trash_id = gInventory.getTrashID();
  897. const LLUUID& laf_id = gInventory.getLostAndFoundID();
  898. bool user_is_away = gAwayTimer.getStarted();
  899. bool throttled = false;
  900. bool show_new_inventory = gSavedSettings.getBool("ShowInInventory");
  901. LLUUID show_item;
  902. for (U32 i = 0, count = items.size(); i < count; ++i)
  903. {
  904. const LLUUID& item_id = items[i];
  905. // NOTE: this *must* be LLViewerInventoryItem and NOT LLInventoryItem,
  906. // because we must call the proper virtual method for the tests using
  907. // getInventoryType() below. HB
  908. LLViewerInventoryItem* itemp = gInventory.getItem(item_id);
  909. if (!itemp)
  910. {
  911. // This could be a folder, which we do not care about. HB
  912. if (!gInventory.getCategory(item_id))
  913. {
  914. llinfos << "Received item " << item_id
  915. << " not found in inventory... Temporary attachment ?"
  916. << llendl;
  917. }
  918. continue;
  919. }
  920. if (itemp->getIsLinkType() || // Ignore created links. HB
  921. gInventory.isObjectDescendentOf(item_id, trash_id))
  922. {
  923. continue;
  924. }
  925. LLAssetType::EType asset_type = itemp->getType();
  926. LL_DEBUGS("InventoryOffer") << "Checking auto-open condition for item: "
  927. << item_id << " - Asset type: "
  928. << asset_type << LL_ENDL;
  929. if (asset_type == LLAssetType::AT_NOTECARD ||
  930. #if HB_AUTO_ACCEPT_OPEN_SCRIPTS
  931. asset_type == LLAssetType::AT_LSL_TEXT ||
  932. #endif
  933. asset_type == LLAssetType::AT_LANDMARK ||
  934. asset_type == LLAssetType::AT_TEXTURE ||
  935. #if 0 // *TODO: after PBR editor is implemented. HB
  936. asset_type == LLAssetType::AT_MATERIAL ||
  937. #endif
  938. asset_type == LLAssetType::AT_SOUND ||
  939. asset_type == LLAssetType::AT_ANIMATION)
  940. {
  941. llinfos << "Auto-opening item: " << item_id << llendl;
  942. if (check_offer_throttle(from_name, throttled))
  943. {
  944. switch (asset_type)
  945. {
  946. case LLAssetType::AT_NOTECARD:
  947. open_notecard(itemp, "Note: " + itemp->getName(), true,
  948. LLUUID::null, false);
  949. break;
  950. #if HB_AUTO_ACCEPT_OPEN_SCRIPTS
  951. case LLAssetType::AT_LSL_TEXT:
  952. open_script(item_id, "Script: " + itemp->getName(),
  953. false);
  954. break;
  955. #endif
  956. case LLAssetType::AT_LANDMARK:
  957. open_landmark(itemp, "Landmark: " + itemp->getName(),
  958. true, false);
  959. break;
  960. case LLAssetType::AT_TEXTURE:
  961. open_texture(item_id, "Texture: " + itemp->getName(),
  962. true, LLUUID::null, false);
  963. break;
  964. #if 0 // *TODO: after PBR editor is implemented. HB
  965. case LLAssetType::AT_MATERIAL:
  966. // Implement open_material() and call it here.
  967. break;
  968. #endif
  969. case LLAssetType::AT_SOUND:
  970. open_sound(item_id, "Sound: " + itemp->getName(),
  971. LLUUID::null, false);
  972. break;
  973. case LLAssetType::AT_ANIMATION:
  974. open_animation(item_id,
  975. "Animation: " + itemp->getName(), 0,
  976. LLUUID::null, false);
  977. break;
  978. default:
  979. break;
  980. }
  981. }
  982. else // If we are throttled, do not display them
  983. {
  984. // Only do a simple check for next time, without spamming in
  985. // chat about the throttling...
  986. throttled = true;
  987. }
  988. }
  989. // Do not show item if not asked, or if the originator name is empty,
  990. // or when the item is a calling card.
  991. if (!show_new_inventory || from_name.empty() ||
  992. asset_type == LLAssetType::AT_CALLINGCARD)
  993. {
  994. continue;
  995. }
  996. // Do not show when the item is a newly attached object, or newly worn
  997. // wearable, or newly activated gesture since *existing* inventory
  998. // items are reported as "new" when attached/worn/activated. HB
  999. LLInventoryType::EType type = itemp->getInventoryType();
  1000. if (type == LLInventoryType::IT_ATTACHMENT ||
  1001. type == LLInventoryType::IT_WEARABLE ||
  1002. type == LLInventoryType::IT_GESTURE)
  1003. {
  1004. continue;
  1005. }
  1006. // Do not select lost and found items if the user is active
  1007. if (!user_is_away && gInventory.isObjectDescendentOf(item_id, laf_id))
  1008. {
  1009. continue;
  1010. }
  1011. // Store the item UUID for later.
  1012. show_item = item_id;
  1013. LL_DEBUGS("InventoryOffer") << "Auto-show registered for item: "
  1014. << item_id << LL_ENDL;
  1015. }
  1016. if (show_item.isNull())
  1017. {
  1018. return;
  1019. }
  1020. LLFloaterInventory::showAgentInventory();
  1021. LLFloaterInventory* floaterp = LLFloaterInventory::getActiveFloater();
  1022. if (floaterp)
  1023. {
  1024. // Highlight item
  1025. LL_DEBUGS("InventoryOffer") << "Showing item: " << show_item
  1026. << LL_ENDL;
  1027. LLFocusableElement* focus_ctrl = gFocusMgr.getKeyboardFocus();
  1028. floaterp->getPanel()->setSelection(show_item, TAKE_FOCUS_NO);
  1029. gFocusMgr.setKeyboardFocus(focus_ctrl);
  1030. }
  1031. }
  1032. // Purge the message queue of any previously queued inventory offers from the
  1033. // same source.
  1034. class OfferMatcher : public LLNotifyBoxView::Matcher
  1035. {
  1036. public:
  1037. OfferMatcher(const LLUUID& to_block)
  1038. : mBlockedId(to_block)
  1039. {
  1040. }
  1041. bool matches(const LLNotificationPtr notif) const
  1042. {
  1043. const std::string& name = notif->getName();
  1044. if (name == "ObjectGiveItem" || name == "ObjectGiveItemOurs" ||
  1045. name == "ObjectGiveItemUnknownUser" || name == "UserGiveItem")
  1046. {
  1047. return notif->getPayload()["from_id"].asUUID() == mBlockedId;
  1048. }
  1049. return false;
  1050. }
  1051. private:
  1052. LLUUID mBlockedId;
  1053. };
  1054. void inventory_offer_mute_callback(const LLUUID& blocked_id,
  1055. const std::string& full_name, bool is_group)
  1056. {
  1057. std::string from_name = full_name;
  1058. LLMute::EType type;
  1059. if (is_group)
  1060. {
  1061. type = LLMute::GROUP;
  1062. }
  1063. else
  1064. {
  1065. type = LLMute::AGENT;
  1066. }
  1067. LLMute mute(blocked_id, from_name, type);
  1068. if (LLMuteList::add(mute))
  1069. {
  1070. LLFloaterMute::selectMute(mute.mID);
  1071. }
  1072. gNotifyBoxViewp->purgeMessagesMatching(OfferMatcher(blocked_id));
  1073. }
  1074. LLOfferInfo::LLOfferInfo(const LLSD& sd)
  1075. {
  1076. mIM = (EInstantMessage)sd["im_type"].asInteger();
  1077. mFromID = sd["from_id"].asUUID();
  1078. mLogInChat = !sd.has("log_in_chat") || sd["log_in_chat"].asBoolean();
  1079. mFromGroup = sd["from_group"].asBoolean();
  1080. mFromObject = sd["from_object"].asBoolean();
  1081. mTransactionID = sd["transaction_id"].asUUID();
  1082. mFolderID = sd["folder_id"].asUUID();
  1083. mObjectID = sd["object_id"].asUUID();
  1084. mType = LLAssetType::lookup(sd["type"].asString().c_str());
  1085. mFromName = sd["from_name"].asString();
  1086. mDesc = sd["description"].asString();
  1087. if (sd.has("slurl"))
  1088. {
  1089. mSLURL = sd["slurl"].asString();
  1090. }
  1091. else
  1092. {
  1093. extractSLURL();
  1094. }
  1095. mHost = LLHost(sd["sender"].asString());
  1096. }
  1097. LLOfferInfo::LLOfferInfo(const LLOfferInfo& other)
  1098. {
  1099. mIM = other.mIM;
  1100. mFromID = other.mFromID;
  1101. mLogInChat = other.mLogInChat;
  1102. mFromGroup = other.mFromGroup;
  1103. mFromObject = other.mFromObject;
  1104. mTransactionID = other.mTransactionID;
  1105. mFolderID = other.mFolderID;
  1106. mObjectID = other.mObjectID;
  1107. mType = other.mType;
  1108. mFromName = other.mFromName;
  1109. mDesc = other.mDesc;
  1110. mHost = other.mHost;
  1111. }
  1112. LLSD LLOfferInfo::asLLSD()
  1113. {
  1114. LLSD sd;
  1115. sd["im_type"] = mIM;
  1116. sd["from_id"] = mFromID;
  1117. sd["log_in_chat"] = mLogInChat;
  1118. sd["from_group"] = mFromGroup;
  1119. sd["from_object"] = mFromObject;
  1120. sd["transaction_id"] = mTransactionID;
  1121. sd["folder_id"] = mFolderID;
  1122. sd["object_id"] = mObjectID;
  1123. sd["type"] = LLAssetType::lookup(mType);
  1124. sd["from_name"] = mFromName;
  1125. sd["description"] = mDesc;
  1126. sd["slurl"] = mSLURL;
  1127. sd["sender"] = mHost.getIPandPort();
  1128. return sd;
  1129. }
  1130. void LLOfferInfo::extractSLURL()
  1131. {
  1132. std::string msg = mDesc;
  1133. size_t i = msg.find("http://");
  1134. if (i != std::string::npos)
  1135. {
  1136. // Remove the SLURL from mDesc
  1137. LLStringUtil::truncate(mDesc, i);
  1138. // Remember the SLURL
  1139. mSLURL = msg.substr(i);
  1140. // Also strip the opening parenthesis from mDesc. Note that the message
  1141. // used to be "... (slurl)" in old servers, and now is "... ( slurl )":
  1142. // make it so both cases are covered, just in the event things would
  1143. // change again...
  1144. i = mDesc.rfind('(');
  1145. if (i != std::string::npos)
  1146. {
  1147. LLStringUtil::truncate(mDesc, i);
  1148. LLStringUtil::trimTail(mDesc);
  1149. }
  1150. // Strip the closing parenthesis and possible trailing space from mSLURL
  1151. i = mSLURL.rfind(')');
  1152. if (i != std::string::npos)
  1153. {
  1154. LLStringUtil::truncate(mSLURL, i);
  1155. LLStringUtil::trimTail(mSLURL);
  1156. }
  1157. }
  1158. }
  1159. void LLOfferInfo::sendReceiveResponse(bool accept)
  1160. {
  1161. LLMessageSystem* msg = gMessageSystemp;
  1162. if (!msg)
  1163. {
  1164. return;
  1165. }
  1166. msg->newMessageFast(_PREHASH_ImprovedInstantMessage);
  1167. msg->nextBlockFast(_PREHASH_AgentData);
  1168. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1169. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1170. msg->nextBlockFast(_PREHASH_MessageBlock);
  1171. msg->addBoolFast(_PREHASH_FromGroup, false);
  1172. msg->addUUIDFast(_PREHASH_ToAgentID, mFromID);
  1173. msg->addU8Fast(_PREHASH_Offline, IM_ONLINE);
  1174. msg->addUUIDFast(_PREHASH_ID, mTransactionID);
  1175. msg->addU32Fast(_PREHASH_Timestamp, NO_TIMESTAMP); // No timestamp needed
  1176. std::string name;
  1177. gAgent.buildFullname(name);
  1178. msg->addStringFast(_PREHASH_FromAgentName, name);
  1179. msg->addStringFast(_PREHASH_Message, "");
  1180. msg->addU32Fast(_PREHASH_ParentEstateID, 0);
  1181. msg->addUUIDFast(_PREHASH_RegionID, LLUUID::null);
  1182. msg->addVector3Fast(_PREHASH_Position, gAgent.getPositionAgent());
  1183. if (accept)
  1184. {
  1185. // ACCEPT. The math for the dialog works, because the accept for
  1186. // inventory_offered, task_inventory_offer or group_notice_inventory is
  1187. // 1 greater than the offer integer value.
  1188. // Generates IM_INVENTORY_ACCEPTED, IM_TASK_INVENTORY_ACCEPTED, or
  1189. // IM_GROUP_NOTICE_INVENTORY_ACCEPTED.
  1190. msg->addU8Fast(_PREHASH_Dialog, (U8)(mIM + 1));
  1191. msg->addBinaryDataFast(_PREHASH_BinaryBucket, &(mFolderID.mData),
  1192. sizeof(mFolderID.mData));
  1193. }
  1194. else
  1195. {
  1196. // Decline for inventory_offered, task_inventory_offer or
  1197. // group_notice_inventory is 2 greater than the offer integer value.
  1198. msg->addU8Fast(_PREHASH_Dialog, (U8)(mIM + 2));
  1199. msg->addBinaryDataFast(_PREHASH_BinaryBucket, EMPTY_BINARY_BUCKET,
  1200. EMPTY_BINARY_BUCKET_SIZE);
  1201. }
  1202. // Send the message
  1203. msg->sendReliable(mHost);
  1204. }
  1205. bool LLOfferInfo::inventoryOfferCallback(const LLSD& notification,
  1206. const LLSD& response)
  1207. {
  1208. LLChat chat;
  1209. std::string log_message;
  1210. S32 button = LLNotification::getSelectedOption(notification, response);
  1211. // For muting, we need to add the mute, then decline the offer.
  1212. // This must be done here because:
  1213. // * callback may be called immediately,
  1214. // * adding the mute sends a message,
  1215. // * we cannot build two messages at once.
  1216. if (button == IOR_MUTE && gCacheNamep)
  1217. {
  1218. gCacheNamep->get(mFromID, mFromGroup, inventory_offer_mute_callback);
  1219. }
  1220. LLInventoryObserver* opener = NULL;
  1221. LLViewerInventoryCategory* catp =
  1222. (LLViewerInventoryCategory*)gInventory.getCategory(mObjectID);
  1223. LLViewerInventoryItem* itemp = NULL;
  1224. if (!catp)
  1225. {
  1226. itemp = (LLViewerInventoryItem*)gInventory.getItem(mObjectID);
  1227. }
  1228. // *TODO:translate
  1229. std::string from_string; // Used in the pop-up.
  1230. std::string chat_history; // Used in chat history.
  1231. if (mFromObject)
  1232. {
  1233. from_string = "An object named '" + mFromName + "'";
  1234. chat_history = mFromName;
  1235. if (!mSLURL.empty()
  1236. //MK
  1237. && !(gRLenabled && gRLInterface.mContainsShowloc))
  1238. //mk
  1239. {
  1240. chat_history += " (" + mSLURL + ")";
  1241. }
  1242. std::string owner_info;
  1243. if (mFromGroup)
  1244. {
  1245. std::string group_name;
  1246. if (gCacheNamep && gCacheNamep->getGroupName(mFromID, group_name))
  1247. {
  1248. owner_info = " owned by the group '" + group_name + "'";
  1249. }
  1250. else
  1251. {
  1252. owner_info = " owned by an unknown group";
  1253. }
  1254. }
  1255. else
  1256. {
  1257. std::string first_name, last_name;
  1258. if (gCacheNamep &&
  1259. gCacheNamep->getName(mFromID, first_name, last_name))
  1260. {
  1261. owner_info = " owned by " + first_name + " " + last_name;
  1262. }
  1263. else
  1264. {
  1265. owner_info = " owned by an unknown user";
  1266. }
  1267. }
  1268. from_string += owner_info;
  1269. chat_history += owner_info;
  1270. }
  1271. else
  1272. {
  1273. from_string = chat_history = mFromName;
  1274. }
  1275. bool busy = false;
  1276. //MK
  1277. std::string folder_name = mDesc;
  1278. if (gRLenabled)
  1279. {
  1280. // mDesc looks like '#RLV/~foldername'
  1281. // => we need to parse in order to find the folder name
  1282. size_t i1 = folder_name.find("'");
  1283. size_t i2 = folder_name.rfind("'");
  1284. if (i1 != std::string::npos && i2 > i1 + 1)
  1285. {
  1286. folder_name = folder_name.substr(i1 + 1, i2 - 1);
  1287. }
  1288. if (gRLInterface.mContainsShownames ||
  1289. gRLInterface.mContainsShownametags)
  1290. {
  1291. chat_history = gRLInterface.getDummyName(chat_history);
  1292. }
  1293. #if RL_ALLOW_ATTACH_DETACH_RECENTLY_RECEIVED_ITEMS
  1294. // Remember received folder name
  1295. if (folder_name.find(RL_RLV_REDIR_FOLDER_PREFIX) != 0)
  1296. {
  1297. gRLInterface.mReceivedInventoryFolders.emplace(folder_name);
  1298. }
  1299. #endif
  1300. }
  1301. //mk
  1302. switch (button)
  1303. {
  1304. case IOR_ACCEPT:
  1305. sendReceiveResponse(true);
  1306. // Do not spam them if they are getting flooded
  1307. if (check_offer_throttle(mFromName, true))
  1308. {
  1309. log_message = chat_history + " gave you " + mDesc + ".";
  1310. chat.mText = log_message;
  1311. LLFloaterChat::addChatHistory(chat);
  1312. }
  1313. // We will want to open this item when it comes back.
  1314. LL_DEBUGS("InventoryOffer") << "Initializing an opener for tid: "
  1315. << mTransactionID << LL_ENDL;
  1316. switch (mIM)
  1317. {
  1318. case IM_INVENTORY_OFFERED:
  1319. {
  1320. LL_DEBUGS("InventoryOffer") << "Offer accepted."
  1321. << LL_ENDL;
  1322. // This is an offer from an agent. In this case, the
  1323. // backend has already copied the items into your
  1324. // inventory, so we can fetch it out of our inventory.
  1325. uuid_vec_t items;
  1326. items.emplace_back(mObjectID);
  1327. if (catp || (itemp && itemp->isFinished()))
  1328. {
  1329. open_inventory_offer(items, from_string);
  1330. }
  1331. else
  1332. {
  1333. LLOpenAgentOffer* open_agent_offer =
  1334. new LLOpenAgentOffer(from_string);
  1335. open_agent_offer->fetchItems(items);
  1336. opener = open_agent_offer;
  1337. }
  1338. break;
  1339. }
  1340. case IM_TASK_INVENTORY_OFFERED:
  1341. case IM_GROUP_NOTICE:
  1342. case IM_GROUP_NOTICE_REQUESTED:
  1343. // This is an offer from a task or group. We do not use a
  1344. // new instance of an opener. We instead use the singular
  1345. // observer LLOpenTaskOffer. Since it already exists, we do
  1346. // not need to actually do anything
  1347. LL_DEBUGS("InventoryOffer") << "Routed via LLOpenTaskOffer"
  1348. << LL_ENDL;
  1349. break;
  1350. default:
  1351. llwarns << "Unknown offer type: " << mIM << llendl;
  1352. }
  1353. //MK
  1354. if (gRLenabled)
  1355. {
  1356. std::string report;
  1357. if (gRLInterface.getRlvShare() &&
  1358. mFolderID == gRLInterface.getRlvShare()->getUUID())
  1359. {
  1360. report = "accepted_in_rlv inv_offer ";
  1361. }
  1362. else
  1363. {
  1364. report = "accepted_in_inv inv_offer ";
  1365. }
  1366. gRLInterface.notify(report + folder_name);
  1367. #if RL_ALLOW_ATTACH_DETACH_RECENTLY_RECEIVED_ITEMS
  1368. // Remember received folder name
  1369. gRLInterface.mReceivedInventoryFolders.emplace(folder_name);
  1370. #endif
  1371. }
  1372. //mk
  1373. break;
  1374. case IOR_BUSY:
  1375. // Busy falls through to decline. Says to make busy message.
  1376. busy = true;
  1377. case IOR_MUTE:
  1378. case IOR_MUTED:
  1379. // MUTE falls through to decline
  1380. case IOR_DECLINE:
  1381. default:
  1382. LL_DEBUGS("InventoryOffer") << "Offer declined." << LL_ENDL;
  1383. // Close button probably (or any of the fall-throughs from above)
  1384. sendReceiveResponse(false);
  1385. if (mLogInChat && button != IOR_MUTED)
  1386. {
  1387. log_message = "You decline " + mDesc + " from " + mFromName;
  1388. if (!mSLURL.empty()
  1389. //MK
  1390. && !(gRLenabled && gRLInterface.mContainsShowloc))
  1391. //mk
  1392. {
  1393. log_message += " (" + mSLURL + ")";
  1394. }
  1395. chat.mText = log_message + ".";
  1396. LLFloaterChat::addChatHistory(chat);
  1397. }
  1398. // If it is from an agent, we have to fetch the item to throw it
  1399. // away. If it is from a task or group, just denying the request
  1400. // will suffice to discard the item.
  1401. if (mIM == IM_INVENTORY_OFFERED)
  1402. {
  1403. uuid_vec_t folders, items;
  1404. items.emplace_back(mObjectID);
  1405. LLDiscardAgentOffer* discard_agent_offer =
  1406. new LLDiscardAgentOffer(mFolderID, mObjectID);
  1407. discard_agent_offer->fetch(folders, items);
  1408. if ((catp && gInventory.isCategoryComplete(mObjectID)) ||
  1409. (itemp && itemp->isFinished()))
  1410. {
  1411. discard_agent_offer->done();
  1412. }
  1413. else
  1414. {
  1415. opener = discard_agent_offer;
  1416. }
  1417. }
  1418. if (busy && !mFromGroup && !mFromObject)
  1419. {
  1420. busy_message(mFromID);
  1421. }
  1422. //MK
  1423. if (gRLenabled)
  1424. {
  1425. gRLInterface.notify("declined inv_offer " + folder_name);
  1426. }
  1427. //mk
  1428. }
  1429. if (opener)
  1430. {
  1431. gInventory.addObserver(opener);
  1432. }
  1433. // Allow these to stack up, but once you deal with one, reset the position.
  1434. if (gFloaterViewp)
  1435. {
  1436. gFloaterViewp->resetStartingFloaterPosition();
  1437. }
  1438. delete this;
  1439. return false;
  1440. }
  1441. void LLOfferInfo::inventoryOfferHandler()
  1442. {
  1443. bool muted = false;
  1444. std::string name;
  1445. bool name_found = false;
  1446. if (mFromObject)
  1447. {
  1448. // Name cache callbacks do not store userdata, so cannot save off the
  1449. // LLOfferInfo. Argh.
  1450. if (mFromGroup)
  1451. {
  1452. if (gCacheNamep && gCacheNamep->getGroupName(mFromID, name))
  1453. {
  1454. name_found = true;
  1455. }
  1456. }
  1457. else if (gCacheNamep && gCacheNamep->getFullName(mFromID, name))
  1458. {
  1459. name_found = true;
  1460. }
  1461. // Search for mutes by object name (the object UUID is alas unknown)
  1462. muted = LLMuteList::isMuted(LLUUID::null, mFromName, 0,
  1463. LLMute::OBJECT);
  1464. if (!muted)
  1465. {
  1466. if (name_found)
  1467. {
  1468. // Search for mutes by owner's group or agent UUID and name
  1469. muted = LLMuteList::isMuted(mFromID, name);
  1470. }
  1471. else
  1472. {
  1473. // Search for mutes by owner's group or agent UUID
  1474. muted = LLMuteList::isMuted(mFromID);
  1475. }
  1476. }
  1477. }
  1478. else
  1479. {
  1480. name = mFromName;
  1481. if (LLAvatarName::sOmitResidentAsLastName)
  1482. {
  1483. name = LLCacheName::cleanFullName(name);
  1484. }
  1485. // Search for mutes by group or agent id or name
  1486. muted = LLMuteList::isMuted(mFromID, name);
  1487. }
  1488. // If muted, do not even go through the messaging stuff. Just curtail the
  1489. // offer here.
  1490. if (muted)
  1491. {
  1492. static F32 last_notification = 0.f;
  1493. // Do not spam with such messages...
  1494. llinfos_once << "Declining inventory offer from muted object/agent: "
  1495. << mFromName << llendl;
  1496. if (gFrameTimeSeconds - last_notification > 30.f)
  1497. {
  1498. LLSD args;
  1499. args["NAME"] = mFromName;
  1500. gNotifications.add("MutedObjectOfferDeclined", args);
  1501. last_notification = gFrameTimeSeconds;
  1502. }
  1503. // Not IOR_MUTE, since this would auto-mute agents owning an object we
  1504. // muted...
  1505. forceResponse(IOR_MUTED);
  1506. return;
  1507. }
  1508. // Avoid the Accept/Discard dialog if the user so desires. JC
  1509. if (gSavedSettings.getBool("AutoAcceptNewInventory") &&
  1510. (mType == LLAssetType::AT_NOTECARD ||
  1511. #if HB_AUTO_ACCEPT_OPEN_SCRIPTS
  1512. mType == LLAssetType::AT_LSL_TEXT ||
  1513. #endif
  1514. mType == LLAssetType::AT_LANDMARK ||
  1515. mType == LLAssetType::AT_TEXTURE ||
  1516. mType == LLAssetType::AT_SOUND ||
  1517. mType == LLAssetType::AT_ANIMATION))
  1518. {
  1519. LL_DEBUGS("InventoryOffer") << "Auto accepting offer." << LL_ENDL;
  1520. // For certain types, just accept the items into the inventory and
  1521. // possibly open them on receipt depending upon "ShowNewInventory".
  1522. forceResponse(IOR_ACCEPT);
  1523. return;
  1524. }
  1525. LLSD args;
  1526. args["OBJECTNAME"] = mDesc;
  1527. LLSD payload;
  1528. // Must protect against a NULL return from lookupHumanReadable()
  1529. std::string typestr = ll_safe_string(LLAssetType::lookupHumanReadable(mType));
  1530. if (typestr.empty())
  1531. {
  1532. llwarns << "Bad/unknown asset type: " << mType << llendl;
  1533. args["OBJECTTYPE"] = "";
  1534. // This seems safest, rather than propagating bogosity
  1535. llwarns << "Forcing an inventory-decline for probably-bad asset type."
  1536. << llendl;
  1537. forceResponse(IOR_DECLINE);
  1538. return;
  1539. }
  1540. args["OBJECTTYPE"] = typestr;
  1541. payload["from_id"] = mFromID;
  1542. args["OBJECTFROMNAME"] = mFromName;
  1543. args["NAME"] = name;
  1544. LLNotification::Params p("ObjectGiveItem");
  1545. p.substitutions(args).payload(payload).functor(boost::bind(&LLOfferInfo::inventoryOfferCallback,
  1546. this, _1, _2));
  1547. if (mFromObject)
  1548. {
  1549. if (mFromID == gAgentID)
  1550. {
  1551. p.name = "ObjectGiveItemOurs";
  1552. }
  1553. else if (name_found)
  1554. {
  1555. p.name = "ObjectGiveItem";
  1556. }
  1557. else
  1558. {
  1559. p.name = "ObjectGiveItemUnknownUser";
  1560. }
  1561. }
  1562. else
  1563. {
  1564. p.name = "UserGiveItem";
  1565. }
  1566. gNotifications.add(p);
  1567. }
  1568. bool lure_callback(const LLSD& notification, const LLSD& response)
  1569. {
  1570. LLUUID from_id = notification["payload"]["from_id"].asUUID();
  1571. LLUUID lure_id = notification["payload"]["lure_id"].asUUID();
  1572. S32 option = 0;
  1573. if (response.isInteger())
  1574. {
  1575. option = response.asInteger();
  1576. }
  1577. else
  1578. {
  1579. option = LLNotification::getSelectedOption(notification, response);
  1580. }
  1581. if (option == 0) // Accept
  1582. {
  1583. bool godlike = notification["payload"]["godlike"].asBoolean();
  1584. gAgent.teleportViaLure(lure_id, godlike);
  1585. }
  1586. else // Decline
  1587. {
  1588. send_simple_im(from_id, LLStringUtil::null, IM_LURE_DECLINED, lure_id);
  1589. }
  1590. return false;
  1591. }
  1592. static LLNotificationFunctorRegistration lure_callback_reg("TeleportOffered",
  1593. lure_callback);
  1594. void send_lures(const LLSD& notification, const LLSD& response,
  1595. bool censor_message)
  1596. {
  1597. std::string text = response["message"].asString();
  1598. //MK
  1599. if (censor_message && gRLenabled)
  1600. {
  1601. if (gRLInterface.containsWithoutException("sendim"))
  1602. {
  1603. text = "(Hidden)";
  1604. }
  1605. else
  1606. {
  1607. for (LLSD::array_const_iterator
  1608. it = notification["payload"]["ids"].beginArray();
  1609. it != notification["payload"]["ids"].endArray(); ++it)
  1610. {
  1611. if (gRLInterface.containsSubstr("sendimto:" +
  1612. it->asUUID().asString()))
  1613. {
  1614. text = "(Hidden)";
  1615. break;
  1616. }
  1617. }
  1618. }
  1619. }
  1620. //mk
  1621. LLMessageSystem* msg = gMessageSystemp;
  1622. msg->newMessageFast(_PREHASH_StartLure);
  1623. msg->nextBlockFast(_PREHASH_AgentData);
  1624. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1625. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1626. msg->nextBlockFast(_PREHASH_Info);
  1627. msg->addU8Fast(_PREHASH_LureType, (U8)0); // sim will fill this in.
  1628. msg->addStringFast(_PREHASH_Message, text);
  1629. for (LLSD::array_const_iterator
  1630. it = notification["payload"]["ids"].beginArray();
  1631. it != notification["payload"]["ids"].endArray(); ++it)
  1632. {
  1633. msg->nextBlockFast(_PREHASH_TargetData);
  1634. msg->addUUIDFast(_PREHASH_TargetID, it->asUUID());
  1635. }
  1636. gAgent.sendReliableMessage();
  1637. }
  1638. bool teleport_request_callback(const LLSD& notification, const LLSD& response)
  1639. {
  1640. LLUUID from_id = notification["payload"]["from_id"].asUUID();
  1641. if (from_id.isNull())
  1642. {
  1643. llwarns << "from_id is NULL" << llendl;
  1644. return false;
  1645. }
  1646. std::string from_name;
  1647. if (!gCacheNamep || !gCacheNamep->getFullName(from_id, from_name))
  1648. {
  1649. return false;
  1650. }
  1651. if (LLMuteList::isMuted(from_id, from_name) &&
  1652. !LLMuteList::isLinden(from_name))
  1653. {
  1654. return false;
  1655. }
  1656. S32 option = 0;
  1657. if (response.isInteger())
  1658. {
  1659. option = response.asInteger();
  1660. }
  1661. else
  1662. {
  1663. option = LLNotification::getSelectedOption(notification, response);
  1664. }
  1665. if (option == 0) // Accepted
  1666. {
  1667. LLSD dummy_notification;
  1668. dummy_notification["payload"]["ids"][0] = from_id;
  1669. LLSD dummy_response;
  1670. dummy_response["message"] = response["message"];
  1671. send_lures(dummy_notification, dummy_response, false);
  1672. }
  1673. return false;
  1674. }
  1675. static LLNotificationFunctorRegistration teleport_request_callback_reg("TeleportRequest",
  1676. teleport_request_callback);
  1677. bool goto_url_callback(const LLSD& notification, const LLSD& response)
  1678. {
  1679. if (LLNotification::getSelectedOption(notification, response) == 1)
  1680. {
  1681. LLWeb::loadURL(notification["payload"]["url"].asString());
  1682. }
  1683. return false;
  1684. }
  1685. static LLNotificationFunctorRegistration goto_url_callback_reg("GotoURL",
  1686. goto_url_callback);
  1687. void process_improved_im(LLMessageSystem* msg, void**)
  1688. {
  1689. if (!gIMMgrp)
  1690. {
  1691. return;
  1692. }
  1693. // *TODO:translate - need to fix the full name to first/last (maybe)
  1694. LLUUID from_id;
  1695. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, from_id);
  1696. bool from_group;
  1697. msg->getBoolFast(_PREHASH_MessageBlock, _PREHASH_FromGroup, from_group);
  1698. LLUUID to_id;
  1699. msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_ToAgentID, to_id);
  1700. U8 offline;
  1701. msg->getU8Fast(_PREHASH_MessageBlock, _PREHASH_Offline, offline);
  1702. U8 d = 0;
  1703. msg->getU8Fast(_PREHASH_MessageBlock, _PREHASH_Dialog, d);
  1704. EInstantMessage dialog = (EInstantMessage)d;
  1705. LLUUID session_id;
  1706. msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_ID, session_id);
  1707. U32 timestamp;
  1708. msg->getU32Fast(_PREHASH_MessageBlock, _PREHASH_Timestamp, timestamp);
  1709. std::string name;
  1710. msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_FromAgentName, name);
  1711. std::string message;
  1712. msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_Message, message);
  1713. U32 estate_id = 0;
  1714. msg->getU32Fast(_PREHASH_MessageBlock, _PREHASH_ParentEstateID, estate_id);
  1715. LLUUID region_id;
  1716. msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_RegionID, region_id);
  1717. LLVector3 position;
  1718. msg->getVector3Fast(_PREHASH_MessageBlock, _PREHASH_Position, position);
  1719. U8 binary_bucket[MTUBYTES];
  1720. msg->getBinaryDataFast(_PREHASH_MessageBlock, _PREHASH_BinaryBucket,
  1721. binary_bucket, 0, 0, MTUBYTES);
  1722. S32 bucket_size = msg->getSizeFast(_PREHASH_MessageBlock,
  1723. _PREHASH_BinaryBucket);
  1724. LLHost sender = msg->getSender();
  1725. gIMMgrp->processNewMessage(from_id, from_group, to_id, offline, dialog,
  1726. session_id, timestamp, name, message, estate_id,
  1727. region_id, position, binary_bucket, bucket_size,
  1728. sender);
  1729. }
  1730. void busy_message(const LLUUID& from_id)
  1731. {
  1732. if (gAgent.getBusy())
  1733. {
  1734. std::string my_name;
  1735. gAgent.buildFullname(my_name);
  1736. std::string response = "Busy mode auto-response: ";
  1737. response += gSavedPerAccountSettings.getText("BusyModeResponse");
  1738. pack_instant_message(gAgentID, false, gAgentSessionID, from_id,
  1739. my_name, response, IM_ONLINE,
  1740. IM_BUSY_AUTO_RESPONSE);
  1741. gAgent.sendReliableMessage();
  1742. }
  1743. }
  1744. bool callingcard_offer_callback(const LLSD& notification, const LLSD& response)
  1745. {
  1746. S32 option = LLNotification::getSelectedOption(notification, response);
  1747. if (option != 0 && option != 1)
  1748. {
  1749. // Close button probably, possibly timed out
  1750. return false;
  1751. }
  1752. LLMessageSystem* msg = gMessageSystemp;
  1753. if (!msg) return false; // Paranoia
  1754. LLUUID tid = notification["payload"]["transaction_id"].asUUID();
  1755. LLHost sender(notification["payload"]["sender"].asString());
  1756. if (option == 0) // Accept
  1757. {
  1758. msg->newMessageFast(_PREHASH_AcceptCallingCard);
  1759. msg->nextBlockFast(_PREHASH_AgentData);
  1760. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1761. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1762. msg->nextBlockFast(_PREHASH_TransactionBlock);
  1763. msg->addUUIDFast(_PREHASH_TransactionID, tid);
  1764. const LLUUID& fid =
  1765. gInventory.findCategoryUUIDForType(LLFolderType::FT_CALLINGCARD);
  1766. msg->nextBlockFast(_PREHASH_FolderData);
  1767. msg->addUUIDFast(_PREHASH_FolderID, fid);
  1768. msg->sendReliable(sender);
  1769. }
  1770. else // Decline
  1771. {
  1772. msg->newMessageFast(_PREHASH_DeclineCallingCard);
  1773. msg->nextBlockFast(_PREHASH_AgentData);
  1774. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1775. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1776. msg->nextBlockFast(_PREHASH_TransactionBlock);
  1777. msg->addUUIDFast(_PREHASH_TransactionID, tid);
  1778. msg->sendReliable(sender);
  1779. busy_message(notification["payload"]["source_id"].asUUID());
  1780. }
  1781. return false;
  1782. }
  1783. static LLNotificationFunctorRegistration callingcard_offer_cb_reg("OfferCallingCard",
  1784. callingcard_offer_callback);
  1785. void process_offer_callingcard(LLMessageSystem* msg, void**)
  1786. {
  1787. LLUUID source_id;
  1788. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, source_id);
  1789. LLUUID tid;
  1790. msg->getUUIDFast(_PREHASH_AgentBlock, _PREHASH_TransactionID, tid);
  1791. // Someone has offered to form a friendship
  1792. LL_DEBUGS("InventoryOffer") << "Callingcard offer from source: "
  1793. << source_id << LL_ENDL;
  1794. LLSD payload;
  1795. payload["transaction_id"] = tid;
  1796. payload["source_id"] = source_id;
  1797. payload["sender"] = msg->getSender().getIPandPort();
  1798. LLViewerObject* source = gObjectList.findObject(source_id);
  1799. LLSD args;
  1800. std::string source_name;
  1801. if (source && source->isAvatar())
  1802. {
  1803. LLNameValue* nvfirst = source->getNVPair("FirstName");
  1804. LLNameValue* nvlast = source->getNVPair("LastName");
  1805. if (nvfirst && nvlast)
  1806. {
  1807. source_name = LLCacheName::buildFullName(nvfirst->getString(),
  1808. nvlast->getString());
  1809. args["NAME"] = source_name;
  1810. }
  1811. }
  1812. if (source_name.empty())
  1813. {
  1814. llwarns << "Calling card offer from an unknown source. Ignored."
  1815. << llendl;
  1816. }
  1817. else if (gAgent.getBusy() ||
  1818. LLMuteList::isMuted(source_id, source_name, LLMute::flagTextChat))
  1819. {
  1820. // Automatically decline offer
  1821. gNotifications.forceResponse(LLNotification::Params("OfferCallingCard").payload(payload),
  1822. 1);
  1823. }
  1824. else
  1825. {
  1826. gNotifications.add("OfferCallingCard", args, payload);
  1827. }
  1828. }
  1829. void process_accept_callingcard(LLMessageSystem*, void**)
  1830. {
  1831. gNotifications.add("CallingCardAccepted");
  1832. }
  1833. void process_decline_callingcard(LLMessageSystem*, void**)
  1834. {
  1835. gNotifications.add("CallingCardDeclined");
  1836. }
  1837. void add_floater_chat(LLChat& chat, bool history)
  1838. {
  1839. if (history)
  1840. {
  1841. // Just add to history
  1842. LLFloaterChat::addChatHistory(chat);
  1843. }
  1844. else
  1845. {
  1846. // Show on screen and add to history
  1847. LLFloaterChat::addChat(chat, false, false);
  1848. }
  1849. }
  1850. void process_chat_from_simulator(LLMessageSystem* msg, void**)
  1851. {
  1852. LLChat chat;
  1853. std::string from_name;
  1854. msg->getString(_PREHASH_ChatData, _PREHASH_FromName, from_name);
  1855. chat.mFromName = from_name;
  1856. LLUUID from_id;
  1857. msg->getUUID(_PREHASH_ChatData, _PREHASH_SourceID, from_id);
  1858. chat.mFromID = from_id;
  1859. // Object owner for objects
  1860. LLUUID owner_id;
  1861. msg->getUUID(_PREHASH_ChatData, _PREHASH_OwnerID, owner_id);
  1862. chat.mOwnerID = owner_id;
  1863. U8 chat_source;
  1864. msg->getU8Fast(_PREHASH_ChatData, _PREHASH_SourceType, chat_source);
  1865. chat.mSourceType = (EChatSourceType)chat_source;
  1866. U8 chat_type;
  1867. msg->getU8(_PREHASH_ChatData, _PREHASH_ChatType, chat_type);
  1868. chat.mChatType = (EChatType)chat_type;
  1869. U8 chat_audible;
  1870. msg->getU8Fast(_PREHASH_ChatData, _PREHASH_Audible, chat_audible);
  1871. chat.mAudible = (EChatAudible)chat_audible;
  1872. chat.mTime = LLFrameTimer::getElapsedSeconds();
  1873. bool is_busy = gAgent.getBusy();
  1874. bool is_muted = LLMuteList::isMuted(from_id, from_name,
  1875. LLMute::flagTextChat) ||
  1876. LLMuteList::isMuted(owner_id, LLMute::flagTextChat);
  1877. bool is_linden = chat.mSourceType != CHAT_SOURCE_OBJECT &&
  1878. LLMuteList::isLinden(from_name);
  1879. bool is_audible = CHAT_AUDIBLE_FULLY == chat.mAudible;
  1880. bool is_owned_by_me = false;
  1881. bool twirly = false;
  1882. LLViewerObject* chatter = gObjectList.findObject(from_id);
  1883. if (chatter)
  1884. {
  1885. chat.mPosAgent = chatter->getPositionAgent();
  1886. // Make swirly things only for talking objects (not for script debug
  1887. // messages, though)
  1888. if (chat.mSourceType == CHAT_SOURCE_OBJECT &&
  1889. chat.mChatType != CHAT_TYPE_DEBUG_MSG &&
  1890. gSavedSettings.getBool("EffectScriptChatParticles"))
  1891. {
  1892. twirly = true;
  1893. }
  1894. // Record last audible utterance
  1895. if (is_audible && (is_linden || (!is_muted && !is_busy)))
  1896. {
  1897. if (chat.mChatType != CHAT_TYPE_START &&
  1898. chat.mChatType != CHAT_TYPE_STOP)
  1899. {
  1900. gAgent.heardChat(chat.mFromID);
  1901. }
  1902. }
  1903. is_owned_by_me = chatter->permYouOwner();
  1904. // Keep track of the owner's Id for the chatter object.
  1905. if (chatter->mOwnerID.isNull() && owner_id.notNull())
  1906. {
  1907. chatter->mOwnerID = owner_id;
  1908. }
  1909. }
  1910. U32 links_for_chatting_objects =
  1911. gSavedSettings.getU32("LinksForChattingObjects");
  1912. if (links_for_chatting_objects != 0 &&
  1913. chat.mSourceType == CHAT_SOURCE_OBJECT &&
  1914. //MK
  1915. (!gRLenabled || !gRLInterface.mContainsShownames) &&
  1916. //mk
  1917. (!is_owned_by_me || links_for_chatting_objects == 2))
  1918. {
  1919. LLSD query_string;
  1920. query_string["name"] = from_name;
  1921. query_string["owner"] = owner_id;
  1922. //MK
  1923. if (!gRLenabled || !gRLInterface.mContainsShowloc)
  1924. {
  1925. //mk
  1926. LLViewerObject* obj;
  1927. // Compute the object SLURL.
  1928. if (chatter)
  1929. {
  1930. obj = chatter;
  1931. }
  1932. else
  1933. {
  1934. // It is a HUD: use the object owner instead.
  1935. obj = gObjectList.findObject(owner_id);
  1936. }
  1937. if (obj)
  1938. {
  1939. LLVector3 pos = obj->getPositionRegion();
  1940. S32 x = ll_round((F32)fmod((F64)pos.mV[VX],
  1941. (F64)REGION_WIDTH_METERS));
  1942. S32 y = ll_round((F32)fmod((F64)pos.mV[VY],
  1943. (F64)REGION_WIDTH_METERS));
  1944. S32 z = ll_round((F32)pos.mV[VZ]);
  1945. std::ostringstream location;
  1946. location << obj->getRegion()->getName() << "/" << x << "/" << y
  1947. << "/" << z;
  1948. query_string["slurl"] = location.str();
  1949. }
  1950. //MK
  1951. }
  1952. //mk
  1953. std::ostringstream link;
  1954. link << "secondlife:///app/objectim/" << from_id
  1955. << LLURI::mapToQueryString(query_string);
  1956. chat.mURL = link.str();
  1957. }
  1958. if (is_audible)
  1959. {
  1960. if (chatter && chatter->isAvatar())
  1961. {
  1962. //MK
  1963. if (!gRLenabled || !gRLInterface.mContainsShownames)
  1964. {
  1965. //mk
  1966. if (LLAvatarName::sOmitResidentAsLastName)
  1967. {
  1968. from_name = LLCacheName::cleanFullName(from_name);
  1969. }
  1970. if (LLAvatarNameCache::useDisplayNames())
  1971. {
  1972. LLAvatarName avatar_name;
  1973. if (LLAvatarNameCache::get(from_id, &avatar_name))
  1974. {
  1975. if (LLAvatarNameCache::useDisplayNames() == 2)
  1976. {
  1977. from_name = avatar_name.mDisplayName;
  1978. }
  1979. else
  1980. {
  1981. from_name = avatar_name.getNames();
  1982. }
  1983. }
  1984. chat.mFromName = from_name;
  1985. }
  1986. //MK
  1987. }
  1988. //mk
  1989. }
  1990. bool visible_in_chat_bubble = false;
  1991. std::string verb;
  1992. std::string mesg;
  1993. msg->getStringFast(_PREHASH_ChatData, _PREHASH_Message, mesg);
  1994. bool ircstyle = false;
  1995. //MK
  1996. if (gRLenabled && chat.mChatType != CHAT_TYPE_OWNER &&
  1997. chat.mChatType != CHAT_TYPE_DIRECT)
  1998. {
  1999. if ((chatter &&
  2000. // Avatar, object or attachment that does not belong to me...
  2001. (chatter->isAvatar() || !chatter->isAttachment() ||
  2002. !chatter->permYouOwner())) ||
  2003. // or this may be a HUD (visible only to the other party) or an
  2004. // unrezzed avatar or object...
  2005. !chatter)
  2006. {
  2007. if (gRLInterface.containsWithoutException("recvchat",
  2008. from_id.asString()) ||
  2009. gRLInterface.contains("recvchatfrom:" +
  2010. from_id.asString()) ||
  2011. gRLInterface.contains("recvchatfrom:" +
  2012. owner_id.asString()))
  2013. {
  2014. chat.mFromName = from_name;
  2015. chat.mText = gRLInterface.crunchEmote(mesg, 20);
  2016. if (!gSavedSettings.getBool("RestrainedLoveShowEllipsis") &&
  2017. chat.mText == "...")
  2018. {
  2019. return;
  2020. }
  2021. mesg = chat.mText;
  2022. }
  2023. if (gRLInterface.containsWithoutException("recvemote",
  2024. from_id.asString()) ||
  2025. gRLInterface.contains("recvemotefrom:" +
  2026. from_id.asString()) ||
  2027. gRLInterface.contains("recvemotefrom:" +
  2028. owner_id.asString()))
  2029. {
  2030. std::string prefix = mesg.substr(0, 4);
  2031. if (prefix == "/me " || prefix == "/me'")
  2032. {
  2033. chat.mFromName = from_name;
  2034. if (gSavedSettings.getBool("RestrainedLoveShowEllipsis"))
  2035. {
  2036. chat.mText = "/me ...";
  2037. }
  2038. else
  2039. {
  2040. return;
  2041. }
  2042. mesg = chat.mText;
  2043. }
  2044. }
  2045. if (from_id != gAgentID && gRLInterface.mContainsShownames)
  2046. {
  2047. // Also scramble the name of the chatter (replace with a
  2048. // dummy name)
  2049. if (chatter && chatter->isAvatar())
  2050. {
  2051. std::string uuid_str = chatter->getID().asString();
  2052. if (gRLInterface.containsWithoutException("shownames",
  2053. uuid_str))
  2054. {
  2055. from_name = gRLInterface.getDummyName(from_name,
  2056. chat.mAudible);
  2057. }
  2058. }
  2059. else
  2060. {
  2061. from_name = gRLInterface.getCensoredMessage(from_name);
  2062. }
  2063. chat.mFromName = from_name;
  2064. }
  2065. }
  2066. else if (gRLInterface.mContainsShownames)
  2067. {
  2068. // This is an object, but it could fake an avatar name
  2069. from_name = gRLInterface.getCensoredMessage(from_name);
  2070. chat.mFromName = from_name;
  2071. }
  2072. }
  2073. //mk
  2074. // Look for IRC-style emotes here so chatbubbles work
  2075. std::string prefix = mesg.substr(0, 4);
  2076. if (prefix == "/me " || prefix == "/me'")
  2077. {
  2078. chat.mText = from_name;
  2079. mesg = mesg.substr(3);
  2080. ircstyle = true;
  2081. }
  2082. chat.mText += mesg;
  2083. // Look for the start of typing so we can put "..." in the bubbles.
  2084. if (chat.mChatType == CHAT_TYPE_START)
  2085. {
  2086. LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, true);
  2087. // Might not have the avatar constructed yet, eg on login.
  2088. if (chatter && chatter->isAvatar())
  2089. {
  2090. ((LLVOAvatar*)chatter)->startTyping();
  2091. }
  2092. return;
  2093. }
  2094. else if (chat.mChatType == CHAT_TYPE_STOP)
  2095. {
  2096. LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, false);
  2097. // Might not have the avatar constructed yet, eg on login.
  2098. if (chatter && chatter->isAvatar())
  2099. {
  2100. ((LLVOAvatar*)chatter)->stopTyping();
  2101. }
  2102. return;
  2103. }
  2104. // We have a real utterance now, so can stop showing "..." and proceed.
  2105. if (chatter && chatter->isAvatar())
  2106. {
  2107. LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, false);
  2108. ((LLVOAvatar*)chatter)->stopTyping();
  2109. if (!is_muted && !is_busy)
  2110. {
  2111. visible_in_chat_bubble = gSavedSettings.getBool("UseChatBubbles");
  2112. ((LLVOAvatar*)chatter)->addChat(chat);
  2113. }
  2114. }
  2115. // Look for IRC-style emotes
  2116. if (ircstyle)
  2117. {
  2118. // Do nothing, ircstyle is fixed above for chat bubbles
  2119. }
  2120. else
  2121. {
  2122. switch (chat.mChatType)
  2123. {
  2124. case CHAT_TYPE_WHISPER:
  2125. verb = " " + LLTrans::getString("whisper") + " ";
  2126. break;
  2127. case CHAT_TYPE_OWNER:
  2128. //MK
  2129. // This is the actual handling of the commands sent by owned
  2130. // objects
  2131. {
  2132. if (gRLenabled && mesg.length() > 2 &&
  2133. mesg[0] == RL_PREFIX && mesg[1] != ' ')
  2134. {
  2135. std::string command = mesg.substr(1);
  2136. LLStringUtil::toLower(command);
  2137. gRLInterface.queueCommands(from_id, chat.mFromName,
  2138. command);
  2139. return;
  2140. }
  2141. else
  2142. {
  2143. if (HBViewerAutomation::checkLuaCommand(mesg, from_id,
  2144. chat.mFromName))
  2145. {
  2146. return;
  2147. }
  2148. if (gRLenabled)
  2149. {
  2150. if (gRLInterface.mContainsShowloc)
  2151. {
  2152. // Hide every occurrence of the Region and Parcel
  2153. // names if the location restriction is active
  2154. mesg = gRLInterface.getCensoredLocation(mesg);
  2155. }
  2156. if (gRLInterface.mContainsShownames)
  2157. {
  2158. mesg = gRLInterface.getCensoredMessage(mesg);
  2159. from_name =
  2160. gRLInterface.getCensoredMessage(from_name);
  2161. chat.mFromName = from_name;
  2162. }
  2163. }
  2164. verb = ": ";
  2165. }
  2166. break;
  2167. }
  2168. //mk
  2169. case CHAT_TYPE_DEBUG_MSG:
  2170. case CHAT_TYPE_NORMAL:
  2171. case CHAT_TYPE_DIRECT:
  2172. verb = ": ";
  2173. break;
  2174. case CHAT_TYPE_SHOUT:
  2175. verb = " " + LLTrans::getString("shout") + " ";
  2176. break;
  2177. case CHAT_TYPE_START:
  2178. case CHAT_TYPE_STOP:
  2179. llwarns << "Got chat type start/stop in main chat processing."
  2180. << llendl;
  2181. break;
  2182. default:
  2183. llwarns << "Unknown type " << chat.mChatType << " in chat !"
  2184. << llendl;
  2185. verb = " say, ";
  2186. }
  2187. //MK
  2188. if (gRLenabled && gRLInterface.mContainsShownames &&
  2189. (!chatter || (chatter && !chatter->isAvatar())))
  2190. {
  2191. // Censor object chat but not avatar chat
  2192. mesg = gRLInterface.getCensoredMessage(mesg);
  2193. }
  2194. //mk
  2195. chat.mText = from_name + verb + mesg;
  2196. }
  2197. if (twirly)
  2198. {
  2199. LLPointer<LLViewerPartSourceChat> psc =
  2200. new LLViewerPartSourceChat(chatter->getPositionAgent());
  2201. psc->setSourceObject(chatter);
  2202. psc->setColor(LLColor4::white);
  2203. // We set the particles to be owned by the object's owner, just in
  2204. // case they should be muted by the mute list
  2205. psc->setOwnerUUID(owner_id);
  2206. gViewerPartSim.addPartSource(psc);
  2207. }
  2208. if (chatter)
  2209. {
  2210. chat.mPosAgent = chatter->getPositionAgent();
  2211. }
  2212. // truth table:
  2213. // LINDEN BUSY MUTED OWNED_BY_YOU TASK DISPLAY STORE IN HISTORY
  2214. // F F F F * Yes Yes
  2215. // F F F T * Yes Yes
  2216. // F F T F * No No
  2217. // F F T T * No No
  2218. // F T F F * No Yes
  2219. // F T F T * Yes Yes
  2220. // F T T F * No No
  2221. // F T T T * No No
  2222. // T * * * F Yes Yes
  2223. chat.mMuted = is_muted && !is_linden;
  2224. if (!visible_in_chat_bubble &&
  2225. (is_linden || !is_busy || is_owned_by_me))
  2226. {
  2227. // Show on screen and add to history
  2228. add_floater_chat(chat, false);
  2229. }
  2230. else
  2231. {
  2232. // Just add to the chat history
  2233. add_floater_chat(chat, true);
  2234. }
  2235. if (gAutomationp && !chat.mMuted && from_id != gAgentID &&
  2236. chat.mChatType != CHAT_TYPE_DEBUG_MSG &&
  2237. chat.mChatType != CHAT_TYPE_START &&
  2238. chat.mChatType != CHAT_TYPE_STOP)
  2239. {
  2240. gAutomationp->onReceivedChat(chat.mChatType, from_id,
  2241. chat.mFromName, chat.mText);
  2242. }
  2243. }
  2244. }
  2245. // The simulator we are on is informing the viewer that the agent is starting
  2246. // to teleport (perhaps to another sim, perhaps to the same sim). If we
  2247. // initiated the teleport process by sending TeleportRequest, then this info is
  2248. // redundant, but if the sim initiated the teleport (via a script call, being
  2249. // killed, etc) then this info is news to us.
  2250. void process_teleport_start(LLMessageSystem* msg, void**)
  2251. {
  2252. U32 teleport_flags = 0x0;
  2253. msg->getU32(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
  2254. LL_DEBUGS("Teleport") << "Got TeleportStart with TeleportFlags="
  2255. << teleport_flags << ". gTeleportDisplay: "
  2256. << gTeleportDisplay << ", gAgent.mTeleportState: "
  2257. << gAgent.getTeleportState() << LL_ENDL;
  2258. if (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL)
  2259. {
  2260. gViewerWindowp->setProgressCancelButtonVisible(false);
  2261. }
  2262. else
  2263. {
  2264. // *TODO: Translate
  2265. gViewerWindowp->setProgressCancelButtonVisible(true, "Cancel");
  2266. }
  2267. //MK
  2268. if (gRLenabled && !gRLInterface.getAllowCancelTp())
  2269. {
  2270. gViewerWindowp->setProgressCancelButtonVisible(false);
  2271. }
  2272. //mk
  2273. // Note: could add data here to differentiate between normal teleport and
  2274. // death.
  2275. if (!gAgent.teleportInProgress())
  2276. {
  2277. gAgent.setTeleportState(LLAgent::TELEPORT_START);
  2278. make_ui_sound("UISndTeleportOut");
  2279. llinfos << "Teleport initiated by remote TeleportStart message with TeleportFlags: "
  2280. << teleport_flags << llendl;
  2281. }
  2282. }
  2283. void process_teleport_progress(LLMessageSystem* msg, void**)
  2284. {
  2285. LLUUID agent_id;
  2286. msg->getUUID(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  2287. if (gAgentID != agent_id || !gAgent.teleportInProgress())
  2288. {
  2289. llwarns << "Unexpected teleport progress message." << llendl;
  2290. return;
  2291. }
  2292. U32 teleport_flags = 0x0;
  2293. msg->getU32(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
  2294. if (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL
  2295. //MK
  2296. || (gRLenabled && !gRLInterface.getAllowCancelTp()))
  2297. //mk
  2298. {
  2299. gViewerWindowp->setProgressCancelButtonVisible(false);
  2300. }
  2301. else
  2302. {
  2303. // *TODO: Translate
  2304. gViewerWindowp->setProgressCancelButtonVisible(true, "Cancel");
  2305. }
  2306. std::string buffer;
  2307. msg->getString(_PREHASH_Info, _PREHASH_Message, buffer);
  2308. LL_DEBUGS("Teleport") << "Teleport progress: " << buffer << LL_ENDL;
  2309. // Sorta hacky... Default to using simulator raw messages if we do not find
  2310. // the coresponding mapping in our progress mappings.
  2311. std::string message = buffer;
  2312. if (LLAgent::sTeleportProgressMessages.find(buffer) !=
  2313. LLAgent::sTeleportProgressMessages.end())
  2314. {
  2315. message = LLAgent::sTeleportProgressMessages[buffer];
  2316. }
  2317. gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages[message]);
  2318. }
  2319. class LLFetchInWelcomeArea : public LLInventoryFetchDescendentsObserver
  2320. {
  2321. public:
  2322. LLFetchInWelcomeArea()
  2323. {
  2324. }
  2325. void done() override
  2326. {
  2327. LLIsType is_landmark(LLAssetType::AT_LANDMARK);
  2328. LLIsType is_card(LLAssetType::AT_CALLINGCARD);
  2329. LLInventoryModel::cat_array_t card_cats;
  2330. LLInventoryModel::item_array_t card_items;
  2331. LLInventoryModel::cat_array_t land_cats;
  2332. LLInventoryModel::item_array_t land_items;
  2333. for (U32 i = 0, count = mCompleteFolders.size(); i < count; ++i)
  2334. {
  2335. const LLUUID& id = mCompleteFolders[i];
  2336. gInventory.collectDescendentsIf(id, land_cats, land_items,
  2337. LLInventoryModel::EXCLUDE_TRASH,
  2338. is_landmark);
  2339. gInventory.collectDescendentsIf(id, card_cats, card_items,
  2340. LLInventoryModel::EXCLUDE_TRASH,
  2341. is_card);
  2342. }
  2343. if (land_items.size() > 0)
  2344. {
  2345. // Show notification that they can now teleport to landmarks. Use a
  2346. // random landmark from the inventory
  2347. S32 random_land = ll_rand(land_items.size() - 1);
  2348. LLSD args;
  2349. args["NAME"] = land_items[random_land]->getName();
  2350. gNotifications.add("TeleportToLandmark", args);
  2351. }
  2352. if (card_items.size() > 0)
  2353. {
  2354. // Show notification that they can now contact people. Use a random
  2355. // calling card from the inventory
  2356. S32 random_card = ll_rand(card_items.size() - 1);
  2357. LLSD args;
  2358. args["NAME"] = card_items[random_card]->getName();
  2359. gNotifications.add("TeleportToPerson", args);
  2360. }
  2361. gInventory.removeObserver(this);
  2362. delete this;
  2363. }
  2364. };
  2365. class LLPostTeleportNotifiers final : public LLEventTimer
  2366. {
  2367. public:
  2368. LLPostTeleportNotifiers()
  2369. : LLEventTimer(2.f)
  2370. {
  2371. }
  2372. ~LLPostTeleportNotifiers() override
  2373. {
  2374. }
  2375. // Method to be called at the supplied frequency
  2376. bool tick() override;
  2377. };
  2378. bool LLPostTeleportNotifiers::tick()
  2379. {
  2380. if (gAgent.teleportInProgress())
  2381. {
  2382. return false;
  2383. }
  2384. // Get calling cards and land marks available to the user arriving.
  2385. uuid_vec_t folders;
  2386. LLUUID folder_id =
  2387. gInventory.findCategoryUUIDForType(LLFolderType::FT_CALLINGCARD);
  2388. if (folder_id.notNull())
  2389. {
  2390. folders.emplace_back(folder_id);
  2391. }
  2392. folder_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK);
  2393. if (folder_id.notNull())
  2394. {
  2395. folders.emplace_back(folder_id);
  2396. }
  2397. if (!folders.empty())
  2398. {
  2399. LLFetchInWelcomeArea* fetcher = new LLFetchInWelcomeArea;
  2400. fetcher->fetchDescendents(folders);
  2401. if (fetcher->isFinished())
  2402. {
  2403. fetcher->done();
  2404. }
  2405. else
  2406. {
  2407. gInventory.addObserver(fetcher);
  2408. }
  2409. }
  2410. return true;
  2411. }
  2412. // Teleport notification from the simulator. We are going to pretend to be a
  2413. // new agent
  2414. void process_teleport_finish(LLMessageSystem* msg, void**)
  2415. {
  2416. if (gAgent.getTeleportState() >= LLAgent::TELEPORT_MOVING)
  2417. {
  2418. llwarns << "Received redundant TeleportFinish message." << llendl;
  2419. if (gSavedSettings.getBool("HardenedMessaging"))
  2420. {
  2421. return;
  2422. }
  2423. }
  2424. //MK
  2425. if (gRLenabled && !gRLInterface.getAllowCancelTp())
  2426. {
  2427. // Cancel button was forcibly hidden by the RLV code ("@tpto") => allow
  2428. // it to show again for next time
  2429. gRLInterface.setAllowCancelTp(true);
  2430. }
  2431. //mk
  2432. LL_DEBUGS("Teleport") << "Got teleport location message" << LL_ENDL;
  2433. LLUUID agent_id;
  2434. msg->getUUIDFast(_PREHASH_Info, _PREHASH_AgentID, agent_id);
  2435. if (agent_id != gAgentID)
  2436. {
  2437. llwarns << "Got teleport notification for wrong agent !" << llendl;
  2438. return;
  2439. }
  2440. // Teleport is finished; it cannot be cancelled now.
  2441. gViewerWindowp->setProgressCancelButtonVisible(false);
  2442. // Force a vertex buffer reset
  2443. gPipeline.doResetVertexBuffers(true);
  2444. // Do teleport effect for where you are leaving.
  2445. LLHUDEffectSpiral::swirlAtPosition(gAgent.getPositionGlobal(), -1.f, true);
  2446. U32 location_id;
  2447. msg->getU32Fast(_PREHASH_Info, _PREHASH_LocationID, location_id);
  2448. U32 sim_ip;
  2449. msg->getIPAddrFast(_PREHASH_Info, _PREHASH_SimIP, sim_ip);
  2450. U16 sim_port;
  2451. msg->getIPPortFast(_PREHASH_Info, _PREHASH_SimPort, sim_port);
  2452. #if 0
  2453. LLVector3 pos, look_at;
  2454. msg->getVector3Fast(_PREHASH_Info, _PREHASH_Position, pos);
  2455. msg->getVector3Fast(_PREHASH_Info, _PREHASH_LookAt, look_at);
  2456. #endif
  2457. U64 region_handle;
  2458. msg->getU64Fast(_PREHASH_Info, _PREHASH_RegionHandle, region_handle);
  2459. U32 teleport_flags;
  2460. msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
  2461. std::string seed_cap;
  2462. msg->getStringFast(_PREHASH_Info, _PREHASH_SeedCapability, seed_cap);
  2463. // Update home location if we are teleporting out of prelude - specific to
  2464. // teleporting to welcome area
  2465. if ((teleport_flags & TELEPORT_FLAGS_SET_HOME_TO_TARGET) &&
  2466. !gAgent.isGodlike())
  2467. {
  2468. LLVector3 pos;
  2469. gAgent.setHomePosRegion(region_handle, pos);
  2470. // Create a timer that will send notices when teleporting is all
  2471. // finished. Since this is based on the LLEventTimer class, it will be
  2472. // managed by that class and not orphaned or leaked.
  2473. new LLPostTeleportNotifiers();
  2474. }
  2475. LLHost sim_host(sim_ip, sim_port);
  2476. // Viewer trusts the simulator.
  2477. gMessageSystemp->enableCircuit(sim_host, true);
  2478. // Variable region size support
  2479. U32 region_size_x = REGION_WIDTH_METERS;
  2480. U32 region_size_y = REGION_WIDTH_METERS;
  2481. if (!gIsInSecondLife)
  2482. {
  2483. msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeX, region_size_x);
  2484. if (region_size_x == 0)
  2485. {
  2486. region_size_x = REGION_WIDTH_METERS;
  2487. }
  2488. msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeY, region_size_y);
  2489. if (region_size_y == 0)
  2490. {
  2491. region_size_y = region_size_x;
  2492. }
  2493. if (region_size_x > REGION_WIDTH_METERS ||
  2494. region_size_y > REGION_WIDTH_METERS)
  2495. {
  2496. llinfos << "Arriving in a VARREGION... Cross your fingers !"
  2497. << llendl;
  2498. }
  2499. }
  2500. if (region_size_x != region_size_y)
  2501. {
  2502. llwarns << "RECTANGULAR REGIONS NOT SUPPORTED: expect a crash !"
  2503. << llendl;
  2504. region_size_x = llmax(region_size_x, region_size_y);
  2505. }
  2506. LLViewerRegion* regionp =
  2507. gWorld.addRegion(region_handle, sim_host, region_size_x);
  2508. gWLSkyParamMgr.processLightshareReset();
  2509. gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages["contacting"]);
  2510. llinfos << "Enabling: " << sim_host << " - With code: "
  2511. << msg->mOurCircuitCode << llendl;
  2512. // Now, use the circuit info to tell simulator about us !
  2513. msg->newMessageFast(_PREHASH_UseCircuitCode);
  2514. msg->nextBlockFast(_PREHASH_CircuitCode);
  2515. msg->addU32Fast(_PREHASH_Code, msg->getOurCircuitCode());
  2516. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  2517. msg->addUUIDFast(_PREHASH_ID, gAgentID);
  2518. msg->sendReliable(sim_host);
  2519. send_complete_agent_movement(sim_host);
  2520. gAgent.setTeleportState(LLAgent::TELEPORT_MOVING);
  2521. regionp->setSeedCapability(seed_cap);
  2522. // Now do teleport effect (TeleportEnd) for where you are going.
  2523. LLHUDEffectSpiral::swirlAtPosition(gAgent.getPositionGlobal(), -1.f, true);
  2524. }
  2525. void process_agent_movement_complete(LLMessageSystem* msg, void**)
  2526. {
  2527. gShiftFrame = true;
  2528. gAgentMovementCompleted = true;
  2529. LLUUID agent_id;
  2530. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  2531. LLUUID session_id;
  2532. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
  2533. if (gAgentID != agent_id || gAgentSessionID != session_id)
  2534. {
  2535. llwarns << "Incorrect agent or session Id; ignored." << llendl;
  2536. return;
  2537. }
  2538. // Check timestamp to make sure the movement completion makes sense.
  2539. static U32 last_move_time = 0;
  2540. U32 timestamp;
  2541. msg->getU32(_PREHASH_Data, _PREHASH_Timestamp, timestamp);
  2542. if (timestamp < last_move_time)
  2543. {
  2544. llwarns << "Timestamp for move is in the past." << llendl;
  2545. if (gSavedSettings.getBool("HardenedMessaging"))
  2546. {
  2547. return;
  2548. }
  2549. }
  2550. last_move_time = timestamp;
  2551. LLVector3 agent_pos;
  2552. msg->getVector3Fast(_PREHASH_Data, _PREHASH_Position, agent_pos);
  2553. LLVector3 look_at;
  2554. msg->getVector3Fast(_PREHASH_Data, _PREHASH_LookAt, look_at);
  2555. U64 region_handle;
  2556. msg->getU64Fast(_PREHASH_Data, _PREHASH_RegionHandle, region_handle);
  2557. msg->getString(_PREHASH_SimData, _PREHASH_ChannelVersion,
  2558. gLastVersionChannel);
  2559. // Could happen if you were immediately god-teleported away on login, maybe
  2560. // other cases. Continue, but warn, excepted if encountered at normal login
  2561. // time (since it *always* happens at this time).
  2562. if (!isAgentAvatarValid() &&
  2563. LLStartUp::getStartupState() >= STATE_INVENTORY_SEND)
  2564. {
  2565. llwarns << "NULL avatar !" << llendl;
  2566. }
  2567. F32 x, y;
  2568. from_region_handle(region_handle, &x, &y);
  2569. LLViewerRegion* regionp = gWorld.getRegionFromHandle(region_handle);
  2570. if (!regionp || !gAgent.getRegion())
  2571. {
  2572. if (gAgent.getRegion())
  2573. {
  2574. llwarns << "Current region: "
  2575. << gAgent.getRegion()->getOriginGlobal() << llendl;
  2576. }
  2577. llwarns << "Agent being sent to invalid home region: " << x << ":" << y
  2578. << " - current pos " << gAgent.getPositionGlobal() << llendl;
  2579. gAppViewerp->forceDisconnect("You were sent to an invalid region.");
  2580. return;
  2581. }
  2582. llinfos << "Changing home region to " << x << ":" << y << llendl;
  2583. // Set our upstream host the new simulator and shuffle things as
  2584. // appropriate.
  2585. LLVector3 shift_vector =
  2586. regionp->getPosRegionFromGlobal(gAgent.getRegion()->getOriginGlobal());
  2587. // *HACK: prevent octree insertion failures when TPing far, far away...
  2588. constexpr F32 EXTRA_LONG_TP = 2048.f * REGION_WIDTH_METERS;
  2589. if (shift_vector.length() > EXTRA_LONG_TP)
  2590. {
  2591. regionp->deletePartitions();
  2592. regionp->initPartitions();
  2593. gAgent.setRegion(regionp);
  2594. gObjectList.shiftObjects(shift_vector);
  2595. // Kill objects in the regions we left behind
  2596. for (LLWorld::region_list_t::const_iterator
  2597. it = gWorld.getRegionList().begin(),
  2598. end = gWorld.getRegionList().end();
  2599. it != end; ++it)
  2600. {
  2601. LLViewerRegion* regp = *it;
  2602. if (regp != regionp)
  2603. {
  2604. gObjectList.killObjects(regp);
  2605. }
  2606. }
  2607. }
  2608. else
  2609. {
  2610. gAgent.setRegion(regionp);
  2611. gObjectList.shiftObjects(shift_vector);
  2612. }
  2613. if (gAssetStoragep)
  2614. {
  2615. gAssetStoragep->setUpstream(msg->getSender());
  2616. }
  2617. if (gCacheNamep)
  2618. {
  2619. gCacheNamep->setUpstream(msg->getSender());
  2620. }
  2621. gViewerThrottle.sendToSim();
  2622. if (gViewerWindowp)
  2623. {
  2624. gViewerWindowp->sendShapeToSim();
  2625. }
  2626. // If this is an AgentMovementComplete message that happened as the result
  2627. // of a teleport, then we need to do things like chat the URL and reset the
  2628. // camera.
  2629. bool is_teleport = gAgent.getTeleportState() == LLAgent::TELEPORT_MOVING;
  2630. if (is_teleport)
  2631. {
  2632. if (gAgent.getTeleportKeepsLookAt())
  2633. {
  2634. // *NOTE: the LookAt data we get from the sim here does not
  2635. // seem to be useful, so get it from the camera instead
  2636. look_at = gViewerCamera.getAtAxis();
  2637. }
  2638. // Force the camera back onto the agent, do not animate.
  2639. gAgent.setFocusOnAvatar(true, false);
  2640. gAgent.slamLookAt(look_at);
  2641. gAgent.updateCamera();
  2642. // IMPORTANT: setRegion() must be called before changing to TP state
  2643. // TELEPORT_START_ARRIVAL, so that the appropriate actions are taken.
  2644. gAgent.setTeleportState(LLAgent::TELEPORT_START_ARRIVAL);
  2645. // Set the appearance on teleport since the new sim does not know what
  2646. // you look like.
  2647. gAgent.sendAgentSetAppearance();
  2648. if (isAgentAvatarValid())
  2649. {
  2650. if (gSavedSettings.getBool("TeleportHistoryInChat")
  2651. //MK
  2652. && (!gRLenabled || !gRLInterface.mContainsShowloc))
  2653. //mk
  2654. {
  2655. // Chat the "back" SLURL. (DEV-4907)
  2656. LLChat chat("Teleport completed from " +
  2657. gAgent.getTeleportSourceSLURL());
  2658. chat.mSourceType = CHAT_SOURCE_SYSTEM;
  2659. LLFloaterChat::addChatHistory(chat);
  2660. }
  2661. if (gFloaterTeleportHistoryp &&
  2662. gSavedSettings.getBool("TeleportHistoryDeparture"))
  2663. {
  2664. // Add the departure location, using the "current" parcel name
  2665. // (which is in fact still the old parcel name since the new
  2666. // parcel properties message was not yet received at this
  2667. // point).
  2668. gFloaterTeleportHistoryp->addSourceEntry(gAgent.getTeleportSourceSLURL(),
  2669. gViewerParcelMgr.getAgentParcelName());
  2670. }
  2671. // Set the new position
  2672. gAgentAvatarp->setPositionAgent(agent_pos);
  2673. gAgentAvatarp->clearChat();
  2674. gAgentAvatarp->slamPosition();
  2675. }
  2676. // Add teleport destination to the list of visited places
  2677. if (gFloaterTeleportHistoryp)
  2678. {
  2679. gFloaterTeleportHistoryp->addPendingEntry(regionp->getName(),
  2680. agent_pos);
  2681. }
  2682. }
  2683. else
  2684. {
  2685. // This is likely just the initial logging in phase.
  2686. LL_DEBUGS("Teleport") << "Resetting to TELEPORT_NONE" << LL_ENDL;
  2687. gAgent.setTeleportState(LLAgent::TELEPORT_NONE);
  2688. if (!LLStartUp::isLoggedIn())
  2689. {
  2690. // This is initial log-in, not a region crossing: set the camera
  2691. // looking ahead of the AV so send_agent_update() below will report
  2692. // the correct location to the server.
  2693. LLVector3 look_at_point = agent_pos +
  2694. look_at.rotVec(gAgent.getQuat());
  2695. gViewerCamera.lookAt(agent_pos, look_at_point, LLVector3::z_axis);
  2696. }
  2697. }
  2698. if (gTracker.isTracking())
  2699. {
  2700. // Check distance to beacon, if < 5m, remove beacon
  2701. LLVector3d beacon_pos = gTracker.getTrackedPositionGlobal();
  2702. LLVector3 beacon_dir(agent_pos.mV[VX] -
  2703. (F32)fmod(beacon_pos.mdV[VX], 256.0),
  2704. agent_pos.mV[VY] -
  2705. (F32)fmod(beacon_pos.mdV[VY], 256.0), 0.f);
  2706. if (beacon_dir.lengthSquared() < 25.f)
  2707. {
  2708. // Do not stop tracking landmarks here, so they can properly be
  2709. // marked as visited in LLTracker()
  2710. if (gTracker.getTrackingStatus() != LLTracker::TRACKING_LANDMARK)
  2711. {
  2712. gTracker.stopTracking();
  2713. }
  2714. }
  2715. else if (is_teleport && !gAgent.getTeleportKeepsLookAt())
  2716. {
  2717. // Look at the beacon
  2718. LLVector3 global_agent_pos = agent_pos;
  2719. global_agent_pos[0] += x;
  2720. global_agent_pos[1] += y;
  2721. look_at = (LLVector3)beacon_pos - global_agent_pos;
  2722. look_at.normalize();
  2723. gAgent.slamLookAt(look_at);
  2724. }
  2725. }
  2726. #if 0 // *TODO: put back a check for flying status ! DK 12/19/05
  2727. // Sim tells us whether the new position is off the ground
  2728. if (teleport_flags & TELEPORT_FLAGS_IS_FLYING)
  2729. {
  2730. gAgent.setFlying(true);
  2731. }
  2732. else
  2733. {
  2734. gAgent.setFlying(false);
  2735. }
  2736. #endif
  2737. send_agent_update(true, true);
  2738. if (gAgent.getRegion()->getBlockFly())
  2739. {
  2740. gAgent.setFlying(gAgent.canFly());
  2741. }
  2742. // Force simulator to recognize busy state
  2743. if (gAgent.getBusy())
  2744. {
  2745. gAgent.setBusy();
  2746. }
  2747. else
  2748. {
  2749. gAgent.clearBusy();
  2750. }
  2751. if (isAgentAvatarValid())
  2752. {
  2753. gAgentAvatarp->mFootPlane.clear();
  2754. }
  2755. // Send walk-vs-run status
  2756. gAgent.sendWalkRun(gAgent.getRunning() || gAgent.getAlwaysRun());
  2757. }
  2758. void process_crossed_region(LLMessageSystem* msg, void**)
  2759. {
  2760. LLUUID agent_id;
  2761. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  2762. LLUUID session_id;
  2763. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
  2764. if (agent_id != gAgentID || gAgentSessionID != session_id)
  2765. {
  2766. llwarns << "Incorrect agent or session Id. Ignoring message." << llendl;
  2767. return;
  2768. }
  2769. U64 region_handle;
  2770. msg->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle, region_handle);
  2771. if (region_handle && region_handle == gAgent.getRegionHandle())
  2772. {
  2773. llwarns << "Received redundant CrossedRegion message (already there)."
  2774. << llendl;
  2775. if (gSavedSettings.getBool("HardenedMessaging"))
  2776. {
  2777. return;
  2778. }
  2779. }
  2780. llinfos << "Crossing region boundary" << llendl;
  2781. if (isAgentAvatarValid())
  2782. {
  2783. gAgentAvatarp->resetRegionCrossingTimer();
  2784. }
  2785. U32 sim_ip;
  2786. msg->getIPAddrFast(_PREHASH_RegionData, _PREHASH_SimIP, sim_ip);
  2787. U16 sim_port;
  2788. msg->getIPPortFast(_PREHASH_RegionData, _PREHASH_SimPort, sim_port);
  2789. LLHost sim_host(sim_ip, sim_port);
  2790. std::string seed_cap;
  2791. msg->getStringFast(_PREHASH_RegionData, _PREHASH_SeedCapability, seed_cap);
  2792. send_complete_agent_movement(sim_host);
  2793. // Variable region size support
  2794. U32 region_size_x = REGION_WIDTH_METERS;
  2795. U32 region_size_y = REGION_WIDTH_METERS;
  2796. if (!gIsInSecondLife)
  2797. {
  2798. msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeX, region_size_x);
  2799. if (region_size_x == 0)
  2800. {
  2801. region_size_x = REGION_WIDTH_METERS;
  2802. }
  2803. msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeY, region_size_y);
  2804. if (region_size_y == 0)
  2805. {
  2806. region_size_y = region_size_x;
  2807. }
  2808. if (region_size_x > REGION_WIDTH_METERS ||
  2809. region_size_y > REGION_WIDTH_METERS)
  2810. {
  2811. llinfos << "Arriving in a VARREGION... Cross your fingers !"
  2812. << llendl;
  2813. }
  2814. }
  2815. if (region_size_x != region_size_y)
  2816. {
  2817. llwarns << "RECTANGULAR REGIONS NOT SUPPORTED: expect a crash !"
  2818. << llendl;
  2819. region_size_x = llmax(region_size_x, region_size_y);
  2820. }
  2821. LLViewerRegion* regionp = gWorld.addRegion(region_handle, sim_host,
  2822. region_size_x);
  2823. regionp->setSeedCapability(seed_cap);
  2824. }
  2825. // Sends avatar and camera information to simulator. Sent roughly once per
  2826. // frame, or 20 times per second, whichever is less often.
  2827. // ~2.5 degrees -- if its less than this we need to update head_rot:
  2828. constexpr F32 THRESHOLD_HEAD_ROT_QDOT = 0.9997f;
  2829. // ~0.5 degrees -- if its greater than this then no need to update head_rot
  2830. // between these values we delay the updates (but no more than one second):
  2831. constexpr F32 MAX_HEAD_ROT_QDOT = 0.99999f;
  2832. void send_agent_update(bool force_send, bool send_reliable)
  2833. {
  2834. if (gAgent.teleportInProgress() || !gAgent.getRegion())
  2835. {
  2836. // We do not care if they want to send an agent update, they are not
  2837. // allowed to until the target simulator is ready to receive them.
  2838. return;
  2839. }
  2840. // We have already requested to log out. Do not send agent updates.
  2841. if (gAppViewerp->logoutRequestSent())
  2842. {
  2843. return;
  2844. }
  2845. constexpr F32 TRANSLATE_THRESHOLD = 0.01f;
  2846. // Rotation threshold: 0.2 deg.
  2847. // Note: this is (intentionally ?) using the small angle sine approximation
  2848. // to test for rotation. Plus, there is an extra 0.5 in the mix since the
  2849. // perpendicular between last_camera_at and getAtAxis() bisects
  2850. // cam_rot_change. Thus, we are actually testing against 0.2 degrees.
  2851. constexpr F32 ROTATION_THRESHOLD = 0.1f * 2.f * F_PI / 360.f;
  2852. // *HACK: number of times to repeat data on motionless agent:
  2853. constexpr U8 DUP_MSGS = 1;
  2854. // Store data on last sent update so that if no changes, no send
  2855. static LLVector3 last_camera_pos_agent, last_camera_at,
  2856. last_camera_left, last_camera_up, cam_center_chg,
  2857. cam_rot_chg;
  2858. static LLQuaternion last_head_rot;
  2859. static U32 last_control_flags = 0;
  2860. static U8 last_render_state;
  2861. static U8 duplicate_count = 0;
  2862. static F32 head_rot_chg = 1.0;
  2863. static U8 last_flags;
  2864. LLMessageSystem* msg = gMessageSystemp;
  2865. LLVector3 camera_pos_agent; // local to avatar's region
  2866. LLVector3 camera_at_axis, camera_left_axis, camera_up_axis;
  2867. LLQuaternion body_rotation = gAgent.getFrameAgent().getQuaternion();
  2868. LLQuaternion head_rotation = gAgent.getHeadRotation();
  2869. static LLCachedControl<bool> spoof_mouse_look(gSavedSettings,
  2870. "SpoofMouseLook");
  2871. if (spoof_mouse_look)
  2872. {
  2873. // In mouse look the camera is at the agent's position and follows the
  2874. // agent's head movements... Let's spoof that too.
  2875. camera_pos_agent = gAgent.getPositionAgent();
  2876. camera_at_axis = gAgent.getAtAxis();
  2877. camera_left_axis = gAgent.getLeftAxis();
  2878. camera_up_axis = gAgent.getUpAxis();
  2879. }
  2880. else
  2881. {
  2882. camera_pos_agent = gAgent.getCameraPositionAgent();
  2883. camera_at_axis = gViewerCamera.getAtAxis();
  2884. camera_left_axis = gViewerCamera.getLeftAxis();
  2885. camera_up_axis = gViewerCamera.getUpAxis();
  2886. }
  2887. U8 render_state = gAgent.getRenderState();
  2888. U32 control_flag_change = 0;
  2889. U8 flag_change = 0;
  2890. cam_center_chg = last_camera_pos_agent - camera_pos_agent;
  2891. cam_rot_chg = last_camera_at - camera_at_axis;
  2892. // If a modifier key is held down, turn off LBUTTON and ML_LBUTTON so that
  2893. // using the camera (alt-key) does not trigger a control event.
  2894. U32 control_flags = gAgent.getControlFlags();
  2895. if (spoof_mouse_look)
  2896. {
  2897. // Let's the scripts believe we are in mouse-look even when not
  2898. control_flags |= AGENT_CONTROL_MOUSELOOK;
  2899. }
  2900. MASK key_mask = gKeyboardp ? gKeyboardp->currentMask(true) : 0;
  2901. if (key_mask & MASK_ALT || key_mask & MASK_CONTROL)
  2902. {
  2903. control_flags &= ~(AGENT_CONTROL_LBUTTON_DOWN |
  2904. AGENT_CONTROL_ML_LBUTTON_DOWN);
  2905. control_flags |= AGENT_CONTROL_LBUTTON_UP |
  2906. AGENT_CONTROL_ML_LBUTTON_UP;
  2907. }
  2908. control_flag_change = last_control_flags ^ control_flags;
  2909. U8 flags = AU_FLAGS_NONE;
  2910. if (gAgent.isGroupTitleHidden())
  2911. {
  2912. flags |= AU_FLAGS_HIDETITLE;
  2913. }
  2914. if (gAgentPilot.isActive())
  2915. {
  2916. flags |= AU_FLAGS_CLIENT_AUTOPILOT;
  2917. }
  2918. flag_change = last_flags ^ flags;
  2919. head_rot_chg = dot(last_head_rot, head_rotation);
  2920. if (force_send || control_flag_change != 0 || flag_change != 0 ||
  2921. last_render_state != render_state ||
  2922. head_rot_chg < THRESHOLD_HEAD_ROT_QDOT ||
  2923. cam_center_chg.length() > TRANSLATE_THRESHOLD ||
  2924. cam_rot_chg.length() > ROTATION_THRESHOLD)
  2925. {
  2926. duplicate_count = 0;
  2927. }
  2928. else
  2929. {
  2930. ++duplicate_count;
  2931. if (head_rot_chg < MAX_HEAD_ROT_QDOT &&
  2932. duplicate_count < AGENT_UPDATES_PER_SECOND)
  2933. {
  2934. // The head_rotation is sent for updating things like attached
  2935. // guns. We only trigger a new update when head_rotation deviates
  2936. // beyond some threshold from the last update, however this can
  2937. // break fine adjustments when trying to aim an attached gun, so
  2938. // what we do here (where we would normally skip sending an update
  2939. // when nothing has changed) is gradually reduce the threshold to
  2940. // allow a better update to eventually get sent... should update to
  2941. // within 0.5 degrees in less than a second.
  2942. if (head_rot_chg < THRESHOLD_HEAD_ROT_QDOT +
  2943. (MAX_HEAD_ROT_QDOT - THRESHOLD_HEAD_ROT_QDOT) *
  2944. duplicate_count / AGENT_UPDATES_PER_SECOND)
  2945. {
  2946. duplicate_count = 0;
  2947. }
  2948. else
  2949. {
  2950. return;
  2951. }
  2952. }
  2953. else
  2954. {
  2955. return;
  2956. }
  2957. }
  2958. if (duplicate_count < DUP_MSGS && !gDisconnected)
  2959. {
  2960. // Build the message
  2961. msg->newMessageFast(_PREHASH_AgentUpdate);
  2962. msg->nextBlockFast(_PREHASH_AgentData);
  2963. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  2964. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  2965. msg->addQuatFast(_PREHASH_BodyRotation, body_rotation);
  2966. msg->addQuatFast(_PREHASH_HeadRotation, head_rotation);
  2967. msg->addU8Fast(_PREHASH_State, render_state);
  2968. msg->addU8Fast(_PREHASH_Flags, flags);
  2969. msg->addVector3Fast(_PREHASH_CameraCenter, camera_pos_agent);
  2970. msg->addVector3Fast(_PREHASH_CameraAtAxis, camera_at_axis);
  2971. msg->addVector3Fast(_PREHASH_CameraLeftAxis, camera_left_axis);
  2972. msg->addVector3Fast(_PREHASH_CameraUpAxis, camera_up_axis);
  2973. msg->addF32Fast(_PREHASH_Far, gAgent.mDrawDistance);
  2974. msg->addU32Fast(_PREHASH_ControlFlags, control_flags);
  2975. if (gDebugClicks)
  2976. {
  2977. if (control_flags & AGENT_CONTROL_LBUTTON_DOWN)
  2978. {
  2979. llinfos << "AgentUpdate left button down" << llendl;
  2980. }
  2981. if (control_flags & AGENT_CONTROL_LBUTTON_UP)
  2982. {
  2983. llinfos << "AgentUpdate left button up" << llendl;
  2984. }
  2985. }
  2986. gAgent.enableControlFlagReset();
  2987. if (!send_reliable)
  2988. {
  2989. gAgent.sendMessage();
  2990. }
  2991. else
  2992. {
  2993. gAgent.sendReliableMessage();
  2994. }
  2995. // Copy the old data
  2996. last_head_rot = head_rotation;
  2997. last_render_state = render_state;
  2998. last_camera_pos_agent = camera_pos_agent;
  2999. last_camera_at = camera_at_axis;
  3000. last_camera_left = camera_left_axis;
  3001. last_camera_up = camera_up_axis;
  3002. last_control_flags = control_flags;
  3003. last_flags = flags;
  3004. }
  3005. }
  3006. // Kept for OpenSim compatibility. HB
  3007. void process_time_synch(LLMessageSystem* msg, void**)
  3008. {
  3009. if (gAgent.hasExtendedEnvironment())
  3010. {
  3011. return;
  3012. }
  3013. msg->getF32Fast(_PREHASH_TimeInfo, _PREHASH_SunPhase,
  3014. LLWLAnimator::sSunPhase);
  3015. LLVector3 sun_direction;
  3016. msg->getVector3Fast(_PREHASH_TimeInfo, _PREHASH_SunDirection,
  3017. sun_direction);
  3018. LLVector3 sun_ang_velocity;
  3019. msg->getVector3Fast(_PREHASH_TimeInfo, _PREHASH_SunAngVelocity,
  3020. sun_ang_velocity);
  3021. if (!gSky.getOverrideSun())
  3022. {
  3023. gSky.setSunTargetDirection(sun_direction, sun_ang_velocity);
  3024. gSky.setSunDirection(sun_direction, sun_ang_velocity);
  3025. }
  3026. // Propagate to current environment. HB
  3027. gWLSkyParamMgr.propagateParameters();
  3028. gWLWaterParamMgr.propagateParameters();
  3029. }
  3030. void process_sound_trigger(LLMessageSystem* msg, void**)
  3031. {
  3032. if (!gAudiop) return;
  3033. LLUUID sound_id;
  3034. msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_SoundID, sound_id);
  3035. LLUUID owner_id;
  3036. msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_OwnerID, owner_id);
  3037. LLUUID object_id;
  3038. msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ObjectID, object_id);
  3039. LLUUID parent_id;
  3040. msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ParentID, parent_id);
  3041. U64 region_handle = 0;
  3042. msg->getU64Fast(_PREHASH_SoundData, _PREHASH_Handle, region_handle);
  3043. LLVector3 pos_local;
  3044. msg->getVector3Fast(_PREHASH_SoundData, _PREHASH_Position, pos_local);
  3045. F32 gain = 0;
  3046. msg->getF32Fast(_PREHASH_SoundData, _PREHASH_Gain, gain);
  3047. // Adjust sound location to true global coords
  3048. LLVector3d pos_global = from_region_handle(region_handle);
  3049. pos_global.mdV[VX] += pos_local.mV[VX];
  3050. pos_global.mdV[VY] += pos_local.mV[VY];
  3051. pos_global.mdV[VZ] += pos_local.mV[VZ];
  3052. // Do not play a trigger sound if you cannot hear it due to parcel "local
  3053. // audio only" setting or to maturity rating
  3054. if (!gViewerParcelMgr.canHearSound(pos_global) ||
  3055. !gAgent.canAccessMaturityInRegion(region_handle))
  3056. {
  3057. return;
  3058. }
  3059. // Do not play sounds from others' gestures if they are not enabled.
  3060. // NOTE: we always play *our* sounds, since send_sound_trigger() is used
  3061. // in the viewer for such purposes as sound preview in inventory.
  3062. static LLCachedControl<bool> gesture_sounds(gSavedSettings,
  3063. "EnableGestureSounds");
  3064. if (!gesture_sounds && object_id == owner_id && owner_id != gAgentID)
  3065. {
  3066. return;
  3067. }
  3068. static LLCachedControl<bool> collision_sounds(gSavedSettings,
  3069. "EnableCollisionSounds");
  3070. if (!collision_sounds && gMaterialTable.isCollisionSound(sound_id))
  3071. {
  3072. return;
  3073. }
  3074. // Check for mutes
  3075. if (LLMuteList::isMuted(owner_id, LLMute::flagObjectSounds) ||
  3076. LLMuteList::isMuted(object_id) ||
  3077. (parent_id.notNull() && LLMuteList::isMuted(parent_id)))
  3078. {
  3079. // Muted resident, object or parent (the latter check should be
  3080. // unnecessary now that the mutes act on root prims, but we still
  3081. // check this in case we got an old mute list with child objects
  3082. // in it instead of the corresponding root objects).
  3083. return;
  3084. }
  3085. gAudiop->triggerSound(sound_id, owner_id, gain,
  3086. LLAudioEngine::AUDIO_TYPE_SFX, pos_global);
  3087. }
  3088. void process_preload_sound(LLMessageSystem* msg, void**)
  3089. {
  3090. if (!gAudiop) return;
  3091. LLUUID sound_id;
  3092. msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_SoundID, sound_id);
  3093. LLUUID object_id;
  3094. msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
  3095. LLUUID owner_id;
  3096. msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
  3097. LLViewerObject* objectp = gObjectList.findObject(object_id);
  3098. if (!objectp || LLMuteList::isMuted(object_id) ||
  3099. LLMuteList::isMuted(owner_id, LLMute::flagObjectSounds))
  3100. {
  3101. // Unknown object or muted object/object owner.
  3102. return;
  3103. }
  3104. LLAudioSource* sourcep = objectp->getAudioSource(owner_id);
  3105. if (!sourcep) return;
  3106. // Only play sounds from regions matching current agent maturity
  3107. LLVector3d pos_global = objectp->getPositionGlobal();
  3108. if (gAgent.canAccessMaturityAtGlobal(pos_global))
  3109. {
  3110. // Add audioData starts a transfer internally. Note that we do not
  3111. // actually do any loading of the audio data into a buffer at this
  3112. // point, as it would not actually help us out.
  3113. LLAudioData* datap = gAudiop->getAudioData(sound_id);
  3114. sourcep->addAudioData(datap, false);
  3115. }
  3116. }
  3117. // Returns false when the object is not yet in the viewer objects list
  3118. bool set_attached_sound(const LLUUID& object_id, const LLUUID& sound_id,
  3119. const LLUUID& owner_id, F32 gain, U8 flags)
  3120. {
  3121. LLViewerObject* objectp = gObjectList.findObject(object_id);
  3122. if (!objectp)
  3123. {
  3124. return false;
  3125. }
  3126. if (objectp->isDead())
  3127. {
  3128. // Do not bother setting sounds on dead objects
  3129. return true;
  3130. }
  3131. if (LLMuteList::isMuted(object_id) ||
  3132. LLMuteList::isMuted(owner_id, LLMute::flagObjectSounds))
  3133. {
  3134. // Muted object/object owner.
  3135. return true;
  3136. }
  3137. // Only play sounds from regions matching current agent maturity
  3138. LLVector3d pos = objectp->getPositionGlobal();
  3139. if (gAgent.canAccessMaturityAtGlobal(pos))
  3140. {
  3141. objectp->setAttachedSound(sound_id, owner_id, gain, flags);
  3142. }
  3143. return true;
  3144. }
  3145. constexpr F32 POSTPONED_SOUND_MAX_DELAY = 15.f;
  3146. class LLPostponedSoundData
  3147. {
  3148. protected:
  3149. LOG_CLASS(LLPostponedSoundData);
  3150. public:
  3151. // Default constructor for unordered map: DO NOT USE otherwise
  3152. LL_INLINE LLPostponedSoundData()
  3153. {
  3154. }
  3155. static void addPostponedSound(const LLUUID& object_id,
  3156. const LLUUID& sound_id,
  3157. const LLUUID& owner_id,
  3158. F32 gain, U8 flags);
  3159. // Global, fast expiration check based on last postponed sound time stamp
  3160. LL_INLINE static void expirationCheck()
  3161. {
  3162. if (sLastExpiration > 0.f && gFrameTimeSeconds >= sLastExpiration)
  3163. {
  3164. sNewlyCreatedOjects.clear();
  3165. sPostponedSounds.clear();
  3166. sLastExpiration = 0.f;
  3167. }
  3168. }
  3169. LL_INLINE static void addNewlyCreatedOject(const LLUUID& object_id)
  3170. {
  3171. sNewlyCreatedOjects.emplace(object_id);
  3172. }
  3173. static void updateAttachedSounds();
  3174. private:
  3175. // Private because addPostponedSound() must be used to add new data
  3176. LL_INLINE LLPostponedSoundData(const LLUUID& sound_id,
  3177. const LLUUID& owner_id, F32 gain, U8 flags)
  3178. : mSoundId(sound_id),
  3179. mOwnerId(owner_id),
  3180. mGain(gain),
  3181. mFlags(flags),
  3182. mExpirationTime(gFrameTimeSeconds + POSTPONED_SOUND_MAX_DELAY)
  3183. {
  3184. sLastExpiration = mExpirationTime;
  3185. }
  3186. private:
  3187. LLUUID mSoundId;
  3188. LLUUID mOwnerId;
  3189. F32 mExpirationTime;
  3190. F32 mGain;
  3191. U8 mFlags;
  3192. static F32 sLastExpiration;
  3193. typedef fast_hmap<LLUUID, LLPostponedSoundData> data_map_t;
  3194. static data_map_t sPostponedSounds;
  3195. // Maintaining a list of newly created objects prevents having to scan
  3196. // (99% of the time fruitlessly) the viewer objects list for *each* object
  3197. // registered in sPostponedSounds: if a new object with the right UUID is
  3198. // not in sNewlyCreatedOjects, then it is not yet either in the viewer
  3199. // objects list. sNewlyCreatedOjects is cleared on each call to
  3200. // updateAttachedSounds() and is therefore a very short list of UUIDs,
  3201. // unlike the viewer objects list which contains thousands of entries...
  3202. static uuid_list_t sNewlyCreatedOjects;
  3203. };
  3204. // Static members
  3205. F32 LLPostponedSoundData::sLastExpiration = 0.f;
  3206. LLPostponedSoundData::data_map_t LLPostponedSoundData::sPostponedSounds;
  3207. uuid_list_t LLPostponedSoundData::sNewlyCreatedOjects;
  3208. //static
  3209. void LLPostponedSoundData::addPostponedSound(const LLUUID& object_id,
  3210. const LLUUID& sound_id,
  3211. const LLUUID& owner_id,
  3212. F32 gain, U8 flags)
  3213. {
  3214. data_map_t::iterator it = sPostponedSounds.find(object_id);
  3215. if (it == sPostponedSounds.end())
  3216. {
  3217. LL_DEBUGS("Messaging") << "Postponing sound " << sound_id
  3218. << " for not yet rezzed object " << object_id
  3219. << LL_ENDL;
  3220. sPostponedSounds[object_id] = LLPostponedSoundData(sound_id, owner_id,
  3221. gain, flags);
  3222. return;
  3223. }
  3224. LLPostponedSoundData& data = it->second;
  3225. if (data.mSoundId != sound_id)
  3226. {
  3227. LL_DEBUGS("Messaging") << "Updating data to postponed sound "
  3228. << sound_id << " for not yet rezzed object "
  3229. << object_id << LL_ENDL;
  3230. data.mSoundId = sound_id;
  3231. data.mOwnerId = owner_id;
  3232. data.mGain = gain;
  3233. data.mFlags = flags;
  3234. }
  3235. sLastExpiration = data.mExpirationTime = gFrameTimeSeconds +
  3236. POSTPONED_SOUND_MAX_DELAY;
  3237. }
  3238. //static
  3239. void LLPostponedSoundData::updateAttachedSounds()
  3240. {
  3241. if (sNewlyCreatedOjects.empty())
  3242. {
  3243. return;
  3244. }
  3245. expirationCheck();
  3246. if (sPostponedSounds.empty())
  3247. {
  3248. return;
  3249. }
  3250. data_map_t::iterator iter = sPostponedSounds.begin();
  3251. data_map_t::iterator end = sPostponedSounds.end();
  3252. while (iter != end)
  3253. {
  3254. data_map_t::iterator curiter = iter++;
  3255. LLPostponedSoundData& data = curiter->second;
  3256. if (gFrameTimeSeconds >= data.mExpirationTime)
  3257. {
  3258. sPostponedSounds.erase(curiter);
  3259. continue;
  3260. }
  3261. const LLUUID& object_id = curiter->first;
  3262. if (!sNewlyCreatedOjects.count(object_id))
  3263. {
  3264. continue;
  3265. }
  3266. if (set_attached_sound(object_id, data.mSoundId, data.mOwnerId,
  3267. data.mGain, data.mFlags))
  3268. {
  3269. llinfos << "Postponed sound " << data.mSoundId
  3270. << " attached to object " << object_id << llendl;
  3271. sPostponedSounds.erase(curiter);
  3272. }
  3273. }
  3274. sNewlyCreatedOjects.clear();
  3275. }
  3276. // Called by LLViewerObjectList::processObjectUpdate(), when a new object is
  3277. // created.
  3278. void add_newly_created_object(const LLUUID& object_id)
  3279. {
  3280. LLPostponedSoundData::addNewlyCreatedOject(object_id);
  3281. }
  3282. void process_attached_sound(LLMessageSystem* msg, void**)
  3283. {
  3284. LLUUID sound_id;
  3285. msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_SoundID, sound_id);
  3286. LLUUID object_id;
  3287. msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
  3288. LLUUID owner_id;
  3289. msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
  3290. F32 gain = 0;
  3291. msg->getF32Fast(_PREHASH_DataBlock, _PREHASH_Gain, gain);
  3292. U8 flags;
  3293. msg->getU8Fast(_PREHASH_DataBlock, _PREHASH_Flags, flags);
  3294. LLPostponedSoundData::expirationCheck();
  3295. if (!set_attached_sound(object_id, sound_id, owner_id, gain, flags) &&
  3296. sound_id.notNull())
  3297. {
  3298. LLPostponedSoundData::addPostponedSound(object_id, sound_id, owner_id,
  3299. gain, flags);
  3300. }
  3301. }
  3302. void process_attached_sound_gain_change(LLMessageSystem* msg, void**)
  3303. {
  3304. LLUUID object_guid;
  3305. msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_guid);
  3306. LLViewerObject* objectp = gObjectList.findObject(object_guid);
  3307. if (objectp)
  3308. {
  3309. F32 gain = 0;
  3310. msg->getF32Fast(_PREHASH_DataBlock, _PREHASH_Gain, gain);
  3311. objectp->adjustAudioGain(gain);
  3312. }
  3313. }
  3314. void process_object_update(LLMessageSystem* msg, void** data)
  3315. {
  3316. // Update the data counters
  3317. if (msg->getReceiveCompressedSize())
  3318. {
  3319. gObjectBits += msg->getReceiveCompressedSize() * 8;
  3320. }
  3321. else
  3322. {
  3323. gObjectBits += msg->getReceiveSize() * 8;
  3324. }
  3325. // Update the object...
  3326. gObjectList.processObjectUpdate(msg, data, OUT_FULL);
  3327. LLPostponedSoundData::updateAttachedSounds();
  3328. }
  3329. void process_compressed_object_update(LLMessageSystem* msg, void** data)
  3330. {
  3331. // Update the data counters
  3332. if (msg->getReceiveCompressedSize())
  3333. {
  3334. gObjectBits += msg->getReceiveCompressedSize() * 8;
  3335. }
  3336. else
  3337. {
  3338. gObjectBits += msg->getReceiveSize() * 8;
  3339. }
  3340. // Update the object...
  3341. gObjectList.processCompressedObjectUpdate(msg, data, OUT_FULL_COMPRESSED);
  3342. LLPostponedSoundData::updateAttachedSounds();
  3343. }
  3344. void process_cached_object_update(LLMessageSystem* msg, void** data)
  3345. {
  3346. // Update the data counters
  3347. if (msg->getReceiveCompressedSize())
  3348. {
  3349. gObjectBits += msg->getReceiveCompressedSize() * 8;
  3350. }
  3351. else
  3352. {
  3353. gObjectBits += msg->getReceiveSize() * 8;
  3354. }
  3355. // Update the object...
  3356. gObjectList.processCachedObjectUpdate(msg, data, OUT_FULL_CACHED);
  3357. }
  3358. void process_terse_object_update_improved(LLMessageSystem* msg, void** data)
  3359. {
  3360. if (msg->getReceiveCompressedSize())
  3361. {
  3362. gObjectBits += msg->getReceiveCompressedSize() * 8;
  3363. }
  3364. else
  3365. {
  3366. gObjectBits += msg->getReceiveSize() * 8;
  3367. }
  3368. gObjectList.processCompressedObjectUpdate(msg, data, OUT_TERSE_IMPROVED);
  3369. LLPostponedSoundData::updateAttachedSounds();
  3370. }
  3371. void process_object_properties_family(LLMessageSystem* msg, void**)
  3372. {
  3373. // Send the result to the corresponding requesters.
  3374. LLSelectMgr::processObjectPropertiesFamily(msg, NULL);
  3375. HBFloaterAreaSearch::processObjectPropertiesFamily(msg);
  3376. HBFloaterSoundsList::processObjectPropertiesFamily(msg);
  3377. HBViewerAutomation::processObjectPropertiesFamily(msg);
  3378. }
  3379. void process_kill_object(LLMessageSystem* msg, void**)
  3380. {
  3381. LL_FAST_TIMER(FTM_PROCESS_OBJECTS);
  3382. U32 ip = msg->getSenderIP();
  3383. U32 port = msg->getSenderPort();
  3384. LLHost host(ip, port);
  3385. LLViewerRegion* regionp = gWorld.getRegion(host);
  3386. if (!regionp) return;
  3387. LLViewerRegion* agent_region = gAgent.getRegion();
  3388. bool non_agent_region = agent_region && regionp != agent_region;
  3389. bool need_cof_resync = false;
  3390. LLUUID id;
  3391. bool delete_object = LLViewerRegion::sVOCacheCullingEnabled;
  3392. S32 num_objects = msg->getNumberOfBlocksFast(_PREHASH_ObjectData);
  3393. for (S32 i = 0; i < num_objects; ++i)
  3394. {
  3395. U32 local_id;
  3396. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_ID, local_id, i);
  3397. gObjectList.getUUIDFromLocal(id, local_id, ip, port);
  3398. if (id.isNull())
  3399. {
  3400. continue;
  3401. }
  3402. if (id == gAgentID) // Never kill our own avatar !
  3403. {
  3404. LL_DEBUGS("Messaging") << "Received kill-object message from "
  3405. << (non_agent_region ? "non-agent"
  3406. : "agent")
  3407. << " region for our agent Id. Ignoring."
  3408. << LL_ENDL;
  3409. continue;
  3410. }
  3411. LLViewerObject* objectp = gObjectList.findObject(id);
  3412. if (!objectp)
  3413. {
  3414. continue;
  3415. }
  3416. static LLCachedControl<bool> filter_kill(gSavedSettings,
  3417. "IgnoreOuterRegionAttachKill");
  3418. if (objectp->isAttachment() &&
  3419. LLVOAvatar::findAvatarFromAttachment(objectp) == gAgentAvatarp)
  3420. {
  3421. if (filter_kill && non_agent_region)
  3422. {
  3423. LL_DEBUGS("Attachment") << "Received kill-object message from non-agent region for agent attachment: "
  3424. << objectp->getID() << ". Ignoring."
  3425. << LL_ENDL;
  3426. need_cof_resync = gIsInSecondLife;
  3427. continue;
  3428. }
  3429. gObjectList.registerKilledAttachment(id);
  3430. LL_DEBUGS("Attachment") << "Received kill object order for agent attachment: "
  3431. << objectp->getID()
  3432. << " - Delete object from cache = "
  3433. << (delete_object ? "true" : "false")
  3434. << LL_ENDL;
  3435. }
  3436. // Display green bubble on kill
  3437. if (gShowObjectUpdates)
  3438. {
  3439. gPipeline.addDebugBlip(objectp->getPositionAgent(),
  3440. LLColor4::green);
  3441. }
  3442. // Do the kill
  3443. gSelectMgr.removeObjectFromSelections(id);
  3444. gObjectList.killObject(objectp);
  3445. if (delete_object)
  3446. {
  3447. regionp->killCacheEntry(local_id);
  3448. }
  3449. }
  3450. if (need_cof_resync)
  3451. {
  3452. gAppearanceMgr.incrementCofVersion();
  3453. gAppearanceMgr.resetCOFUpdateTimer();
  3454. }
  3455. }
  3456. void process_health_message(LLMessageSystem* msg, void**)
  3457. {
  3458. F32 health;
  3459. msg->getF32Fast(_PREHASH_HealthData, _PREHASH_Health, health);
  3460. if (gStatusBarp)
  3461. {
  3462. gStatusBarp->setHealth((S32)health);
  3463. }
  3464. }
  3465. void process_sim_stats(LLMessageSystem* msg, void**)
  3466. {
  3467. S32 count = msg->getNumberOfBlocks(_PREHASH_Stat);
  3468. U32 stat_id;
  3469. F32 stat_value;
  3470. for (S32 i = 0; i < count; ++i)
  3471. {
  3472. msg->getU32(_PREHASH_Stat, _PREHASH_StatID, stat_id, i);
  3473. msg->getF32(_PREHASH_Stat, _PREHASH_StatValue, stat_value, i);
  3474. gViewerStats.addSample(stat_id, stat_value);
  3475. }
  3476. // Various hacks that are not statistics, but are being handled here.
  3477. U32 max_tasks;
  3478. msg->getU32(_PREHASH_Region, _PREHASH_ObjectCapacity, max_tasks);
  3479. U64 region_flags = 0;
  3480. if (msg->has(_PREHASH_RegionInfo))
  3481. {
  3482. msg->getU64(_PREHASH_RegionInfo, _PREHASH_RegionFlagsExtended,
  3483. region_flags);
  3484. }
  3485. else
  3486. {
  3487. U32 flags = 0;
  3488. msg->getU32(_PREHASH_Region, _PREHASH_RegionFlags, flags);
  3489. region_flags = flags;
  3490. }
  3491. LLViewerRegion* regionp = gAgent.getRegion();
  3492. if (regionp)
  3493. {
  3494. bool was_flying = gAgent.getFlying();
  3495. regionp->setRegionFlags(region_flags);
  3496. regionp->setMaxTasks(max_tasks);
  3497. // *HACK: this makes agent drop from the sky if flying and the region
  3498. // is set to no fly.
  3499. if (was_flying && regionp->getBlockFly())
  3500. {
  3501. gAgent.setFlying(gAgent.canFly());
  3502. }
  3503. }
  3504. }
  3505. #if LL_PUPPETRY
  3506. static void handle_puppetry_data(LLMessageSystem* msg, LLVOAvatar* avatarp,
  3507. S32 num_physav_blocks)
  3508. {
  3509. LLPuppetMotion* motionp = avatarp->getPuppetMotion();
  3510. if (!motionp)
  3511. {
  3512. return;
  3513. }
  3514. for (S32 i = 0; i < num_physav_blocks; ++i)
  3515. {
  3516. S32 data_size = msg->getSizeFast(_PREHASH_PhysicalAvatarEventList,
  3517. i, _PREHASH_TypeData);
  3518. if (data_size > 0)
  3519. {
  3520. motionp->unpackEvents(msg, i);
  3521. }
  3522. }
  3523. if (!motionp->isActive() && motionp->needsUpdate())
  3524. {
  3525. avatarp->startMotion(ANIM_AGENT_PUPPET_MOTION);
  3526. }
  3527. }
  3528. #endif
  3529. void process_avatar_animation(LLMessageSystem* msg, void**)
  3530. {
  3531. LLUUID uuid;
  3532. msg->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
  3533. LLVOAvatar* avatarp = gObjectList.findAvatar(uuid);
  3534. if (!avatarp)
  3535. {
  3536. // No agent by this Id...
  3537. llwarns_once << "Received animation state for unknown avatar " << uuid
  3538. << llendl;
  3539. return;
  3540. }
  3541. // Clear animation flags
  3542. avatarp->mSignaledAnimations.clear();
  3543. S32 num_blocks = msg->getNumberOfBlocksFast(_PREHASH_AnimationList);
  3544. if (num_blocks <= 0) return;
  3545. S32 num_source_blocks =
  3546. msg->getNumberOfBlocksFast(_PREHASH_AnimationSourceList);
  3547. #if LL_PUPPETRY
  3548. S32 num_physav_blocks =
  3549. #endif
  3550. msg->getNumberOfBlocksFast(_PREHASH_PhysicalAvatarEventList);
  3551. LLUUID animation_id;
  3552. S32 anim_sequence_id;
  3553. if (avatarp->isSelf())
  3554. {
  3555. LLUUID object_id;
  3556. for (S32 i = 0; i < num_blocks; ++i)
  3557. {
  3558. msg->getUUIDFast(_PREHASH_AnimationList, _PREHASH_AnimID,
  3559. animation_id, i);
  3560. msg->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID,
  3561. anim_sequence_id, i);
  3562. LL_DEBUGS("Messaging") << "Anim sequence ID: " << anim_sequence_id
  3563. << LL_ENDL;
  3564. avatarp->mSignaledAnimations[animation_id] = anim_sequence_id;
  3565. if (i < num_source_blocks)
  3566. {
  3567. msg->getUUIDFast(_PREHASH_AnimationSourceList,
  3568. _PREHASH_ObjectID, object_id, i);
  3569. LLViewerObject* object = gObjectList.findObject(object_id);
  3570. if (object)
  3571. {
  3572. object->setFlagsWithoutUpdate(FLAGS_ANIM_SOURCE, true);
  3573. bool anim_found = false;
  3574. for (LLVOAvatar::anim_src_map_it_t
  3575. it = avatarp->mAnimationSources.find(object_id),
  3576. end = avatarp->mAnimationSources.end();
  3577. it != end; ++it)
  3578. {
  3579. if (it->first != object_id)
  3580. {
  3581. // Elements with the same key are always
  3582. // contiguous, bail if we went past the end of this
  3583. // object's animations.
  3584. break;
  3585. }
  3586. if (it->second == animation_id)
  3587. {
  3588. anim_found = true;
  3589. break;
  3590. }
  3591. }
  3592. if (!anim_found)
  3593. {
  3594. avatarp->mAnimationSources.emplace(object_id,
  3595. animation_id);
  3596. }
  3597. }
  3598. }
  3599. }
  3600. #if LL_PUPPETRY
  3601. if (LLPuppetMotion::enabled() &&
  3602. LLPuppetModule::getInstance()->getEcho())
  3603. {
  3604. handle_puppetry_data(msg, avatarp, num_physav_blocks);
  3605. }
  3606. #endif
  3607. }
  3608. else
  3609. {
  3610. for (S32 i = 0; i < num_blocks; ++i)
  3611. {
  3612. msg->getUUIDFast(_PREHASH_AnimationList, _PREHASH_AnimID,
  3613. animation_id, i);
  3614. msg->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID,
  3615. anim_sequence_id, i);
  3616. avatarp->mSignaledAnimations[animation_id] = anim_sequence_id;
  3617. }
  3618. #if LL_PUPPETRY
  3619. if (LLPuppetMotion::enabled())
  3620. {
  3621. // Extract and process puppetry data from message
  3622. handle_puppetry_data(msg, avatarp, num_physav_blocks);
  3623. }
  3624. #endif
  3625. }
  3626. avatarp->processAnimationStateChanges();
  3627. }
  3628. void process_object_animation(LLMessageSystem* msg, void**)
  3629. {
  3630. LLUUID uuid;
  3631. msg->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
  3632. S32 num_blocks = msg->getNumberOfBlocksFast(_PREHASH_AnimationList);
  3633. LL_DEBUGS("Messaging") << "Handling object animation requests for object: "
  3634. << uuid << " - num_blocks = " << num_blocks
  3635. << LL_ENDL;
  3636. LLVOAvatar::anim_map_t signaled_anims;
  3637. LLUUID animation_id;
  3638. S32 anim_sequence_id;
  3639. for (S32 i = 0; i < num_blocks; ++i)
  3640. {
  3641. msg->getUUIDFast(_PREHASH_AnimationList, _PREHASH_AnimID, animation_id,
  3642. i);
  3643. msg->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID,
  3644. anim_sequence_id, i);
  3645. signaled_anims[animation_id] = anim_sequence_id;
  3646. LL_DEBUGS("Messaging") << " - got request for animation: "
  3647. << animation_id << LL_ENDL;
  3648. }
  3649. LLVOAvatarPuppet::getSignaledAnimMap()[uuid] = signaled_anims;
  3650. LL_DEBUGS("Puppets") << "Object animation requests handlded." << LL_ENDL;
  3651. LLViewerObject* objp = gObjectList.findObject(uuid);
  3652. if (!objp || objp->isDead())
  3653. {
  3654. // This case is fairly common (on login and TPs, i.e. when not all
  3655. // objects data has been received) and not critical at all. Changed to
  3656. // a debug message to avoid log spam. HB
  3657. LL_DEBUGS("Messaging") << "Received animation state for unknown object: "
  3658. << uuid << LL_ENDL;
  3659. return;
  3660. }
  3661. LLVOVolume* volp = objp->asVolume();
  3662. if (!volp)
  3663. {
  3664. llwarns_once << "Received animation state for non-volume object: "
  3665. << uuid << llendl;
  3666. return;
  3667. }
  3668. if (!volp->isAnimatedObject())
  3669. {
  3670. llwarns_once << "Received animation state for non-animated object: "
  3671. << uuid << llendl;
  3672. return;
  3673. }
  3674. volp->updatePuppetAvatar();
  3675. LLVOAvatarPuppet* avatarp = volp->getPuppetAvatar();
  3676. if (!avatarp)
  3677. {
  3678. llinfos_once << "No puppet avatar for object: " << uuid
  3679. << ". Ignoring." << llendl;
  3680. return;
  3681. }
  3682. if (!avatarp->mPlaying)
  3683. {
  3684. avatarp->mPlaying = true;
  3685. if (avatarp->mRootVolp)
  3686. {
  3687. #if 0
  3688. if (!avatarp->mRootVolp->isAnySelected())
  3689. #endif
  3690. {
  3691. avatarp->updateVolumeGeom();
  3692. avatarp->mRootVolp->recursiveMarkForUpdate();
  3693. }
  3694. }
  3695. }
  3696. avatarp->updateAnimations();
  3697. }
  3698. void process_avatar_appearance(LLMessageSystem* msg, void**)
  3699. {
  3700. LLUUID uuid;
  3701. msg->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
  3702. LLVOAvatar* avatarp = gObjectList.findAvatar(uuid);
  3703. if (avatarp)
  3704. {
  3705. avatarp->processAvatarAppearance(msg);
  3706. }
  3707. else
  3708. {
  3709. llwarns << "Avatar appearance message received for unknown avatar "
  3710. << uuid << llendl;
  3711. }
  3712. }
  3713. void process_camera_constraint(LLMessageSystem* msg, void**)
  3714. {
  3715. LLVector4 plane;
  3716. msg->getVector4Fast(_PREHASH_CameraCollidePlane, _PREHASH_Plane, plane);
  3717. gAgent.setCameraCollidePlane(plane);
  3718. }
  3719. void near_sit_object(bool success, void*)
  3720. {
  3721. if (success)
  3722. {
  3723. // Send message to sit on object
  3724. LLMessageSystem* msg = gMessageSystemp;
  3725. msg->newMessageFast(_PREHASH_AgentSit);
  3726. msg->nextBlockFast(_PREHASH_AgentData);
  3727. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  3728. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  3729. gAgent.sendReliableMessage();
  3730. }
  3731. }
  3732. void process_avatar_sit_response(LLMessageSystem* msg, void**)
  3733. {
  3734. if (!isAgentAvatarValid())
  3735. {
  3736. return;
  3737. }
  3738. LLUUID seat_id;
  3739. msg->getUUIDFast(_PREHASH_SitObject, _PREHASH_ID, seat_id);
  3740. bool use_autopilot;
  3741. msg->getBoolFast(_PREHASH_SitTransform, _PREHASH_AutoPilot, use_autopilot);
  3742. LLVector3 sit_pos;
  3743. msg->getVector3Fast(_PREHASH_SitTransform, _PREHASH_SitPosition, sit_pos);
  3744. LLQuaternion sit_rot;
  3745. msg->getQuatFast(_PREHASH_SitTransform, _PREHASH_SitRotation, sit_rot);
  3746. LLVector3 camera_eye;
  3747. msg->getVector3Fast(_PREHASH_SitTransform, _PREHASH_CameraEyeOffset,
  3748. camera_eye);
  3749. LLVector3 camera_at;
  3750. msg->getVector3Fast(_PREHASH_SitTransform, _PREHASH_CameraAtOffset,
  3751. camera_at);
  3752. bool force_mouselook;
  3753. msg->getBoolFast(_PREHASH_SitTransform, _PREHASH_ForceMouselook,
  3754. force_mouselook);
  3755. if (dist_vec_squared(camera_eye, camera_at) > 0.0001f)
  3756. {
  3757. gAgent.setSitCamera(seat_id, camera_eye, camera_at);
  3758. }
  3759. gAgent.mForceMouselook = force_mouselook;
  3760. LLViewerObject* object = gObjectList.findObject(seat_id);
  3761. if (!object)
  3762. {
  3763. llwarns << "Received sit approval for unknown object " << seat_id
  3764. << llendl;
  3765. return;
  3766. }
  3767. // If not allowed to use the auto-pilot, bail now.
  3768. if (!use_autopilot)
  3769. {
  3770. return;
  3771. }
  3772. // If we are not already sitting on this object, we may autopilot
  3773. if (!gAgentAvatarp->mIsSitting ||
  3774. gAgentAvatarp->getRoot() != object->getRoot())
  3775. {
  3776. LLVector3 sit_spot = object->getPositionAgent() +
  3777. sit_pos * object->getRotation();
  3778. gAgentPilot.startAutoPilotGlobal(gAgent.getPosGlobalFromAgent(sit_spot),
  3779. "Sit", &sit_rot, near_sit_object,
  3780. NULL, 0.5f, gAgent.getFlying());
  3781. }
  3782. }
  3783. void process_clear_follow_cam_properties(LLMessageSystem* msg, void**)
  3784. {
  3785. LLUUID source_id;
  3786. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, source_id);
  3787. LLFollowCamMgr::removeFollowCamParams(source_id);
  3788. }
  3789. void process_set_follow_cam_properties(LLMessageSystem* msg, void**)
  3790. {
  3791. S32 type;
  3792. F32 value;
  3793. bool setting_pos = false;
  3794. bool setting_focus = false;
  3795. bool setting_focus_offset = false;
  3796. LLVector3 position, focus, focus_offset;
  3797. LLUUID source_id;
  3798. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, source_id);
  3799. LLViewerObject* objectp = gObjectList.findObject(source_id);
  3800. if (objectp)
  3801. {
  3802. objectp->setFlagsWithoutUpdate(FLAGS_CAMERA_SOURCE, true);
  3803. }
  3804. S32 num_objects = msg->getNumberOfBlocks(_PREHASH_CameraProperty);
  3805. for (S32 block_index = 0; block_index < num_objects; ++block_index)
  3806. {
  3807. msg->getS32(_PREHASH_CameraProperty, _PREHASH_Type, type, block_index);
  3808. msg->getF32(_PREHASH_CameraProperty, _PREHASH_Value, value,
  3809. block_index);
  3810. switch (type)
  3811. {
  3812. case FOLLOWCAM_PITCH:
  3813. LLFollowCamMgr::setPitch(source_id, value);
  3814. break;
  3815. case FOLLOWCAM_FOCUS_OFFSET_X:
  3816. focus_offset.mV[VX] = value;
  3817. setting_focus_offset = true;
  3818. break;
  3819. case FOLLOWCAM_FOCUS_OFFSET_Y:
  3820. focus_offset.mV[VY] = value;
  3821. setting_focus_offset = true;
  3822. break;
  3823. case FOLLOWCAM_FOCUS_OFFSET_Z:
  3824. focus_offset.mV[VZ] = value;
  3825. setting_focus_offset = true;
  3826. break;
  3827. case FOLLOWCAM_POSITION_LAG:
  3828. LLFollowCamMgr::setPositionLag(source_id, value);
  3829. break;
  3830. case FOLLOWCAM_FOCUS_LAG:
  3831. LLFollowCamMgr::setFocusLag(source_id, value);
  3832. break;
  3833. case FOLLOWCAM_DISTANCE:
  3834. LLFollowCamMgr::setDistance(source_id, value);
  3835. break;
  3836. case FOLLOWCAM_BEHINDNESS_ANGLE:
  3837. LLFollowCamMgr::setBehindnessAngle(source_id, value);
  3838. break;
  3839. case FOLLOWCAM_BEHINDNESS_LAG:
  3840. LLFollowCamMgr::setBehindnessLag(source_id, value);
  3841. break;
  3842. case FOLLOWCAM_POSITION_THRESHOLD:
  3843. LLFollowCamMgr::setPositionThreshold(source_id, value);
  3844. break;
  3845. case FOLLOWCAM_FOCUS_THRESHOLD:
  3846. LLFollowCamMgr::setFocusThreshold(source_id, value);
  3847. break;
  3848. case FOLLOWCAM_ACTIVE:
  3849. LLFollowCamMgr::setCameraActive(source_id, value != 0.f);
  3850. break;
  3851. case FOLLOWCAM_POSITION_X:
  3852. setting_pos = true;
  3853. position.mV[0] = value;
  3854. break;
  3855. case FOLLOWCAM_POSITION_Y:
  3856. setting_pos = true;
  3857. position.mV[1] = value;
  3858. break;
  3859. case FOLLOWCAM_POSITION_Z:
  3860. setting_pos = true;
  3861. position.mV[2] = value;
  3862. break;
  3863. case FOLLOWCAM_FOCUS_X:
  3864. setting_focus = true;
  3865. focus.mV[0] = value;
  3866. break;
  3867. case FOLLOWCAM_FOCUS_Y:
  3868. setting_focus = true;
  3869. focus.mV[1] = value;
  3870. break;
  3871. case FOLLOWCAM_FOCUS_Z:
  3872. setting_focus = true;
  3873. focus.mV[2] = value;
  3874. break;
  3875. case FOLLOWCAM_POSITION_LOCKED:
  3876. LLFollowCamMgr::setPositionLocked(source_id, value != 0.f);
  3877. break;
  3878. case FOLLOWCAM_FOCUS_LOCKED:
  3879. LLFollowCamMgr::setFocusLocked(source_id, value != 0.f);
  3880. break;
  3881. default:
  3882. break;
  3883. }
  3884. }
  3885. if (setting_pos)
  3886. {
  3887. LLFollowCamMgr::setPosition(source_id, position);
  3888. }
  3889. if (setting_focus)
  3890. {
  3891. LLFollowCamMgr::setFocus(source_id, focus);
  3892. }
  3893. if (setting_focus_offset)
  3894. {
  3895. LLFollowCamMgr::setFocusOffset(source_id, focus_offset);
  3896. }
  3897. }
  3898. void process_name_value(LLMessageSystem* msg, void**)
  3899. {
  3900. LLUUID id;
  3901. msg->getUUIDFast(_PREHASH_TaskData, _PREHASH_ID, id);
  3902. LLViewerObject* object = gObjectList.findObject(id);
  3903. if (object)
  3904. {
  3905. std::string temp_str;
  3906. S32 num_blocks;
  3907. num_blocks = msg->getNumberOfBlocksFast(_PREHASH_NameValueData);
  3908. for (S32 i = 0; i < num_blocks; ++i)
  3909. {
  3910. msg->getStringFast(_PREHASH_NameValueData, _PREHASH_NVPair,
  3911. temp_str, i);
  3912. llinfos << "Added to object Name Value: " << temp_str << llendl;
  3913. object->addNVPair(temp_str);
  3914. }
  3915. }
  3916. else
  3917. {
  3918. llinfos << "Cannot find object " << id << " to add name value pair"
  3919. << llendl;
  3920. }
  3921. }
  3922. void process_remove_name_value(LLMessageSystem* msg, void**)
  3923. {
  3924. LLUUID id;
  3925. msg->getUUIDFast(_PREHASH_TaskData, _PREHASH_ID, id);
  3926. LLViewerObject* object = gObjectList.findObject(id);
  3927. if (object)
  3928. {
  3929. std::string temp_str;
  3930. S32 num_blocks;
  3931. num_blocks = msg->getNumberOfBlocksFast(_PREHASH_NameValueData);
  3932. for (S32 i = 0; i < num_blocks; ++i)
  3933. {
  3934. msg->getStringFast(_PREHASH_NameValueData, _PREHASH_NVPair,
  3935. temp_str, i);
  3936. llinfos << "Removed from object Name Value: " << temp_str
  3937. << llendl;
  3938. object->removeNVPair(temp_str);
  3939. }
  3940. }
  3941. else
  3942. {
  3943. llinfos << "Cannot find object " << id << " to remove name value pair"
  3944. << llendl;
  3945. }
  3946. }
  3947. void process_kick_user(LLMessageSystem* msg, void**)
  3948. {
  3949. std::string message;
  3950. msg->getStringFast(_PREHASH_UserInfo, _PREHASH_Reason, message);
  3951. gAppViewerp->forceDisconnect(message);
  3952. }
  3953. void set_god_level(U8 god_level)
  3954. {
  3955. U8 old_god_level = gAgent.getGodLevel();
  3956. gAgent.setGodLevel(god_level);
  3957. if (gIMMgrp)
  3958. {
  3959. gIMMgrp->refresh();
  3960. }
  3961. gViewerParcelMgr.notifySelectionObservers();
  3962. // Some classifieds change visibility on god mode
  3963. HBFloaterSearch::requestClassifieds();
  3964. // God mode changes region visibility
  3965. gWorldMap.reset();
  3966. gWorldMap.setCurrentLayer(0);
  3967. // Inventory in items may change in god mode
  3968. gObjectList.dirtyAllObjectInventory();
  3969. if (gViewerWindowp)
  3970. {
  3971. gViewerWindowp->setMenuBackgroundColor();
  3972. }
  3973. LLSD args;
  3974. if (god_level > GOD_NOT)
  3975. {
  3976. args["LEVEL"] = llformat("%d", (S32)god_level);
  3977. gNotifications.add("EnteringGodMode", args);
  3978. }
  3979. else
  3980. {
  3981. args["LEVEL"] = llformat("%d", (S32)old_god_level);
  3982. gNotifications.add("LeavingGodMode", args);
  3983. }
  3984. // Changing god-level can affect which menus we see
  3985. show_debug_menus();
  3986. }
  3987. void process_grant_godlike_powers(LLMessageSystem* msg, void**)
  3988. {
  3989. LLUUID agent_id;
  3990. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  3991. LLUUID session_id;
  3992. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
  3993. if (agent_id == gAgentID && session_id == gAgentSessionID)
  3994. {
  3995. U8 god_level;
  3996. msg->getU8Fast(_PREHASH_GrantData, _PREHASH_GodLevel, god_level);
  3997. set_god_level(god_level);
  3998. }
  3999. else
  4000. {
  4001. llwarns << "Grant godlike received for wrong agent: " << agent_id
  4002. << ". Ignored." << llendl;
  4003. }
  4004. }
  4005. static std::string reason_from_transaction_type(S32 transaction_type,
  4006. const std::string& item_desc)
  4007. {
  4008. // *NOTE: The keys for the reason strings are unusual because an earlier
  4009. // version of the code used English language strings extracted from hard-
  4010. // coded server English descriptions. Keeping them so we do not have to
  4011. // re-localize them.
  4012. switch (transaction_type)
  4013. {
  4014. case TRANS_OBJECT_SALE:
  4015. {
  4016. LLStringUtil::format_map_t arg;
  4017. arg["ITEM"] = item_desc;
  4018. return LLTrans::getString("for item", arg);
  4019. }
  4020. case TRANS_LAND_SALE:
  4021. return LLTrans::getString("for a parcel of land");
  4022. case TRANS_LAND_PASS_SALE:
  4023. return LLTrans::getString("for a land access pass");
  4024. case TRANS_GROUP_LAND_DEED:
  4025. return LLTrans::getString("for deeding land");
  4026. case TRANS_GROUP_CREATE:
  4027. return LLTrans::getString("to create a group");
  4028. case TRANS_GROUP_JOIN:
  4029. return LLTrans::getString("to join a group");
  4030. case TRANS_UPLOAD_CHARGE:
  4031. return LLTrans::getString("to upload");
  4032. case TRANS_CLASSIFIED_CHARGE:
  4033. return LLTrans::getString("to publish a classified ad");
  4034. case TRANS_GIFT:
  4035. return item_desc == "Payment" ? std::string() : item_desc;
  4036. // These have no reason to display, but are expected and should not
  4037. // generate warnings
  4038. case TRANS_PAY_OBJECT:
  4039. case TRANS_OBJECT_PAYS:
  4040. return "";
  4041. default:
  4042. llwarns << "Unknown transaction type " << transaction_type
  4043. << llendl;
  4044. return "";
  4045. }
  4046. }
  4047. static void money_balance_group_notify(const LLUUID& group_id,
  4048. const std::string& name,
  4049. bool is_group,
  4050. LLSD args,
  4051. std::string message)
  4052. {
  4053. args["NAME"] = name;
  4054. message = LLTrans::getString(message);
  4055. LLStringUtil::format(message, args);
  4056. args.clear();
  4057. args["MESSAGE"] = message;
  4058. gNotifications.add("SystemMessage", args);
  4059. }
  4060. static void money_balance_avatar_notify(const LLUUID& agent_id,
  4061. const LLAvatarName& av_name,
  4062. LLSD args, std::string message)
  4063. {
  4064. if (LLAvatarNameCache::useDisplayNames())
  4065. {
  4066. args["NAME"] = av_name.getNames();
  4067. }
  4068. else
  4069. {
  4070. args["NAME"] = av_name.getLegacyName();
  4071. }
  4072. message = LLTrans::getString(message);
  4073. LLStringUtil::format(message, args);
  4074. args.clear();
  4075. args["MESSAGE"] = message;
  4076. gNotifications.add("SystemMessage", args);
  4077. }
  4078. // Added in server 1.40 and viewer 2.1, support for localization and agent Ids
  4079. // for name lookup.
  4080. static void process_money_balance_reply_extended(LLMessageSystem* msg,
  4081. std::string desc)
  4082. {
  4083. S32 transaction_type = 0;
  4084. msg->getS32(_PREHASH_TransactionInfo, _PREHASH_TransactionType,
  4085. transaction_type);
  4086. LLUUID source_id;
  4087. msg->getUUID(_PREHASH_TransactionInfo, _PREHASH_SourceID, source_id);
  4088. bool is_source_group = false;
  4089. msg->getBool(_PREHASH_TransactionInfo, _PREHASH_IsSourceGroup,
  4090. is_source_group);
  4091. LLUUID dest_id;
  4092. msg->getUUID(_PREHASH_TransactionInfo, _PREHASH_DestID, dest_id);
  4093. bool is_dest_group = false;
  4094. msg->getBool(_PREHASH_TransactionInfo, _PREHASH_IsDestGroup,
  4095. is_dest_group);
  4096. S32 amount = 0;
  4097. msg->getS32(_PREHASH_TransactionInfo, _PREHASH_Amount, amount);
  4098. std::string item_description;
  4099. msg->getString(_PREHASH_TransactionInfo, _PREHASH_ItemDescription,
  4100. item_description);
  4101. bool success = false;
  4102. msg->getBool(_PREHASH_MoneyData, _PREHASH_TransactionSuccess, success);
  4103. llinfos << "MoneyBalanceReply source " << source_id << " dest " << dest_id
  4104. << " type " << transaction_type << " item " << item_description
  4105. << llendl;
  4106. LLSD args;
  4107. if (source_id.isNull() && dest_id.isNull())
  4108. {
  4109. // this is a pure balance update, use the already built message
  4110. args["MESSAGE"] = desc;
  4111. gNotifications.add("SystemMessage", args);
  4112. return;
  4113. }
  4114. std::string reason = reason_from_transaction_type(transaction_type,
  4115. item_description);
  4116. args["REASON"] = reason; // could be empty
  4117. args["AMOUNT"] = llformat("%d", amount);
  4118. // Need to delay until name looked up, so need to know whether it is a
  4119. // group or not
  4120. bool is_name_group = false;
  4121. LLUUID name_id;
  4122. std::string message;
  4123. if (source_id == gAgentID)
  4124. {
  4125. // You paid someone...
  4126. is_name_group = is_dest_group;
  4127. name_id = dest_id;
  4128. if (!reason.empty())
  4129. {
  4130. if (dest_id.notNull())
  4131. {
  4132. message = success ? "you_paid_ldollars"
  4133. : "you_paid_failure_ldollars";
  4134. if (transaction_type == TRANS_GIFT)
  4135. {
  4136. message += "_gift";
  4137. }
  4138. }
  4139. else
  4140. {
  4141. // Transaction fee to the system, eg, to create a group
  4142. message = success ? "you_paid_ldollars_no_name"
  4143. : "you_paid_failure_ldollars_no_name";
  4144. }
  4145. }
  4146. else if (dest_id.notNull())
  4147. {
  4148. message = success ? "you_paid_ldollars_no_reason"
  4149. : "you_paid_failure_ldollars_no_reason";
  4150. }
  4151. else
  4152. {
  4153. // No target, no reason, you just paid money
  4154. message = success ? "you_paid_ldollars_no_info"
  4155. : "you_paid_failure_ldollars_no_info";
  4156. }
  4157. }
  4158. else
  4159. {
  4160. // ...someone paid you
  4161. is_name_group = is_source_group;
  4162. name_id = source_id;
  4163. if (!reason.empty() && !LLMuteList::isMuted(source_id))
  4164. {
  4165. message ="paid_you_ldollars";
  4166. if (transaction_type == TRANS_GIFT)
  4167. {
  4168. message += "_gift";
  4169. }
  4170. }
  4171. else
  4172. {
  4173. message = "paid_you_ldollars_no_reason";
  4174. }
  4175. }
  4176. // Wait until the name is available before showing the notification
  4177. if (!is_name_group)
  4178. {
  4179. LLAvatarNameCache::get(name_id,
  4180. boost::bind(&money_balance_avatar_notify, _1,
  4181. _2, args, message));
  4182. }
  4183. else if (gCacheNamep)
  4184. {
  4185. gCacheNamep->get(name_id, true,
  4186. boost::bind(&money_balance_group_notify, _1, _2, _3,
  4187. args, message));
  4188. }
  4189. }
  4190. void process_money_balance_reply(LLMessageSystem* msg, void**)
  4191. {
  4192. S32 balance = 0;
  4193. msg->getS32(_PREHASH_MoneyData, _PREHASH_MoneyBalance, balance);
  4194. S32 credit = 0;
  4195. msg->getS32(_PREHASH_MoneyData, _PREHASH_SquareMetersCredit, credit);
  4196. S32 committed = 0;
  4197. msg->getS32(_PREHASH_MoneyData, _PREHASH_SquareMetersCommitted, committed);
  4198. std::string desc;
  4199. msg->getStringFast(_PREHASH_MoneyData, _PREHASH_Description, desc);
  4200. llinfos << "L$, credit, committed: " << balance << " " << credit << " "
  4201. << committed << llendl;
  4202. S32 old_balance = -1;
  4203. if (gStatusBarp)
  4204. {
  4205. old_balance = gStatusBarp->getBalance();
  4206. // This is an update, not the first transmission of balance
  4207. if (old_balance != 0)
  4208. {
  4209. // This is actually an update
  4210. if (balance > old_balance)
  4211. {
  4212. LLFirstUse::useBalanceIncrease(balance - old_balance);
  4213. }
  4214. else if (balance < old_balance)
  4215. {
  4216. LLFirstUse::useBalanceDecrease(balance - old_balance);
  4217. }
  4218. }
  4219. gStatusBarp->setBalance(balance);
  4220. gStatusBarp->setLandCredit(credit);
  4221. gStatusBarp->setLandCommitted(committed);
  4222. }
  4223. LLUUID tid;
  4224. msg->getUUID(_PREHASH_MoneyData, _PREHASH_TransactionID, tid);
  4225. static std::deque<LLUUID> recent;
  4226. if (gSavedSettings.getBool("NotifyMoneyChange") &&
  4227. std::find(recent.rbegin(), recent.rend(), tid) == recent.rend())
  4228. {
  4229. // Confirm the transaction to the user, since they might have missed
  4230. // something during an event, or this may be an out-world transaction.
  4231. if (desc.empty())
  4232. {
  4233. // Out-world transaction.
  4234. if (balance == old_balance || old_balance <= 0)
  4235. {
  4236. return;
  4237. }
  4238. if (balance > old_balance)
  4239. {
  4240. desc = LLTrans::getString("money_balance_increased");
  4241. }
  4242. else
  4243. {
  4244. desc = LLTrans::getString("money_balance_decreased");
  4245. }
  4246. LLSD args;
  4247. args["AMOUNT"] = abs(balance - old_balance);
  4248. LLStringUtil::format(desc, args);
  4249. }
  4250. // Once the 'recent' container gets large enough, chop some off the
  4251. // beginning.
  4252. constexpr U32 MAX_LOOKBACK = 30;
  4253. constexpr S32 POP_FRONT_SIZE = 12;
  4254. if (recent.size() > MAX_LOOKBACK)
  4255. {
  4256. LL_DEBUGS("Messaging") << "Removing oldest transaction records"
  4257. << LL_ENDL;
  4258. recent.erase(recent.begin(), recent.begin() + POP_FRONT_SIZE);
  4259. }
  4260. LL_DEBUGS("Messaging") << "Pushing back transaction " << tid
  4261. << LL_ENDL;
  4262. recent.emplace_back(tid);
  4263. if (msg->has(_PREHASH_TransactionInfo))
  4264. {
  4265. // ...message has extended info for localization
  4266. process_money_balance_reply_extended(msg, desc);
  4267. }
  4268. else
  4269. {
  4270. // Old grids will not supply the TransactionInfo block, so we can
  4271. // just use the hard-coded English string.
  4272. LLSD args;
  4273. args["MESSAGE"] = desc;
  4274. gNotifications.add("SystemMessage", args);
  4275. }
  4276. }
  4277. }
  4278. bool handle_special_notification_callback(const LLSD& notification,
  4279. const LLSD& response)
  4280. {
  4281. if (LLNotification::getSelectedOption(notification, response) == 0)
  4282. {
  4283. // Set the preference to the maturity of the region we are calling
  4284. U32 maturity = notification["payload"]["_region_access"].asInteger();
  4285. gSavedSettings.setU32("PreferredMaturity", maturity);
  4286. gAgent.sendMaturityPreferenceToServer(maturity);
  4287. }
  4288. return false;
  4289. }
  4290. // Some of the server notifications need special handling. This is where we do
  4291. // that.
  4292. bool handle_special_notification(std::string notif_name, LLSD& data)
  4293. {
  4294. if (data.has("_region_access"))
  4295. {
  4296. U8 region_access = (U8)data["_region_access"].asInteger();
  4297. std::string maturity = LLViewerRegion::accessToString(region_access);
  4298. LLStringUtil::toLower(maturity);
  4299. data["REGIONMATURITY"] = maturity;
  4300. // We are going to throw the LLSD in there in case anyone ever wants to
  4301. // use it
  4302. gNotifications.add(notif_name + "_Notify", data);
  4303. if (region_access == SIM_ACCESS_MATURE)
  4304. {
  4305. if (gAgent.isTeen())
  4306. {
  4307. gNotifications.add(notif_name + "_KB", data);
  4308. return true;
  4309. }
  4310. else if (gAgent.prefersPG())
  4311. {
  4312. gNotifications.add(notif_name + "_Change", data, data,
  4313. handle_special_notification_callback);
  4314. return true;
  4315. }
  4316. }
  4317. else if (region_access == SIM_ACCESS_ADULT)
  4318. {
  4319. if (!gAgent.isAdult())
  4320. {
  4321. gNotifications.add(notif_name + "_KB", data);
  4322. return true;
  4323. }
  4324. else if (gAgent.prefersPG() || gAgent.prefersMature())
  4325. {
  4326. gNotifications.add(notif_name + "_Change", data, data,
  4327. handle_special_notification_callback);
  4328. return true;
  4329. }
  4330. }
  4331. }
  4332. return false;
  4333. }
  4334. bool handle_trusted_experiences_notification(const LLSD& data)
  4335. {
  4336. if (data.has("trusted_experiences"))
  4337. {
  4338. std::ostringstream str;
  4339. const LLSD& experiences = data["trusted_experiences"];
  4340. for (LLSD::array_const_iterator it = experiences.beginArray(),
  4341. end = experiences.endArray();
  4342. it != end; ++it)
  4343. {
  4344. str << LLSLURL("experience", it->asUUID(),
  4345. "profile").getSLURLString() << "\n";
  4346. }
  4347. std::string str_list = str.str();
  4348. if (!str_list.empty())
  4349. {
  4350. LLSD args;
  4351. args["EXPERIENCE_LIST"] = (LLSD)str_list;
  4352. gNotifications.add("TrustedExperiencesAvailable", args);
  4353. return true;
  4354. }
  4355. }
  4356. return false;
  4357. }
  4358. bool attempt_standard_notification(LLMessageSystem* msgsystem)
  4359. {
  4360. // If we have additional alert data
  4361. if (msgsystem->has(_PREHASH_AlertInfo) &&
  4362. msgsystem->getNumberOfBlocksFast(_PREHASH_AlertInfo) > 0)
  4363. {
  4364. // Notification was specified using the new mechanism, so we can just
  4365. // handle it here
  4366. std::string notif_name;
  4367. msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message,
  4368. notif_name);
  4369. if (!gNotifications.templateExists(notif_name))
  4370. {
  4371. return false;
  4372. }
  4373. std::string raw_data;
  4374. LLSD data;
  4375. msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_ExtraParams,
  4376. raw_data);
  4377. if (raw_data.length())
  4378. {
  4379. std::istringstream streamed(raw_data);
  4380. if (!LLSDSerialize::deserialize(data, streamed, raw_data.length()))
  4381. {
  4382. llwarns << "Attempted to read notification parameter data into LLSD but failed: "
  4383. << raw_data << llendl;
  4384. }
  4385. }
  4386. if (notif_name == "RegionEntryAccessBlocked" ||
  4387. notif_name == "LandClaimAccessBlocked" ||
  4388. notif_name == "LandBuyAccessBlocked")
  4389. {
  4390. /*-----------------------------------------------------------------
  4391. (Commented so a grep will find the notification strings, since
  4392. we construct them on the fly; if you add additional notifications,
  4393. please update the comment.)
  4394. Could throw any of the following notifications:
  4395. RegionEntryAccessBlocked
  4396. RegionEntryAccessBlocked_Notify
  4397. RegionEntryAccessBlocked_Change
  4398. RegionEntryAccessBlocked_KB
  4399. LandClaimAccessBlocked
  4400. LandClaimAccessBlocked_Notify
  4401. LandClaimAccessBlocked_Change
  4402. LandClaimAccessBlocked_KB
  4403. LandBuyAccessBlocked
  4404. LandBuyAccessBlocked_Notify
  4405. LandBuyAccessBlocked_Change
  4406. LandBuyAccessBlocked_KB
  4407. -----------------------------------------------------------------*/
  4408. if (handle_special_notification(notif_name, data))
  4409. {
  4410. return true;
  4411. }
  4412. }
  4413. // Special Marketplace update notification
  4414. if (notif_name == "SLM_UPDATE_FOLDER")
  4415. {
  4416. return LLMarketplace::processUpdateNotification(data);
  4417. }
  4418. gNotifications.add(notif_name, data);
  4419. return true;
  4420. }
  4421. return false;
  4422. }
  4423. void process_agent_alert_message(LLMessageSystem* msgsystem, void**)
  4424. {
  4425. // Make sure the cursor is back to the usual default since the alert is
  4426. // probably due to some kind of error.
  4427. gWindowp->resetBusyCount();
  4428. if (!attempt_standard_notification(msgsystem))
  4429. {
  4430. bool modal = false;
  4431. msgsystem->getBool(_PREHASH_AlertData, _PREHASH_Modal, modal);
  4432. std::string buffer;
  4433. msgsystem->getStringFast(_PREHASH_AlertData, _PREHASH_Message, buffer);
  4434. process_alert_core(buffer, modal);
  4435. }
  4436. }
  4437. // The only difference between this routine and the previous is the fact that
  4438. // for this routine, the modal parameter is always false. Sadly, for the
  4439. // message handled by this routine, there is no _PREHASH_Modal parameter on the
  4440. // message, and there is no API to tell if a message has the given parameter or
  4441. // not. So we cannot handle the messages with the same handler.
  4442. void process_alert_message(LLMessageSystem* msgsystem, void**)
  4443. {
  4444. // Make sure the cursor is back to the usual default since the alert is
  4445. // probably due to some kind of error.
  4446. gWindowp->resetBusyCount();
  4447. if (!attempt_standard_notification(msgsystem))
  4448. {
  4449. constexpr bool modal = false;
  4450. std::string buffer;
  4451. msgsystem->getStringFast(_PREHASH_AlertData, _PREHASH_Message, buffer);
  4452. process_alert_core(buffer, modal);
  4453. }
  4454. }
  4455. void process_alert_core(const std::string& message, bool modal)
  4456. {
  4457. // *HACK: handle callbacks for specific alerts
  4458. if (message == "You died and have been teleported to your home location")
  4459. {
  4460. gViewerStats.incStat(LLViewerStats::ST_KILLED_COUNT);
  4461. }
  4462. else if (message == "Home position set.")
  4463. {
  4464. // Save the home location image to disk
  4465. std::string snap_filename = gDirUtil.getLindenUserDir();
  4466. snap_filename += LL_DIR_DELIM_STR + SCREEN_HOME_FILENAME;
  4467. gViewerWindowp->saveSnapshot(snap_filename,
  4468. gViewerWindowp->getWindowDisplayWidth(),
  4469. gViewerWindowp->getWindowDisplayHeight(),
  4470. false, false);
  4471. }
  4472. static const std::string ALERT_PREFIX("ALERT: ");
  4473. static const std::string NOTIFY_PREFIX("NOTIFY: ");
  4474. if (message.find(ALERT_PREFIX) == 0)
  4475. {
  4476. // Allow the server to spawn a named alert so that server alerts can be
  4477. // translated out of English.
  4478. gNotifications.add(message.substr(ALERT_PREFIX.length()));
  4479. }
  4480. else if (message.find(NOTIFY_PREFIX) == 0)
  4481. {
  4482. // Allow the server to spawn a named notification so that server
  4483. // notifications can be translated out of English.
  4484. gNotifications.add(message.substr(NOTIFY_PREFIX.length()));
  4485. }
  4486. else if (message[0] == '/') // System message
  4487. {
  4488. std::string text(message.substr(1));
  4489. std::string prefix;
  4490. if (text.length() > 17)
  4491. {
  4492. prefix = text.substr(0, 17);
  4493. }
  4494. LLSD args;
  4495. if (prefix == "RESTART_X_MINUTES")
  4496. {
  4497. S32 mins = 0;
  4498. LLStringUtil::convertToS32(text.substr(18), mins);
  4499. args["MINUTES"] = llformat("%d", mins);
  4500. gNotifications.add("RegionRestartMinutes", args);
  4501. }
  4502. else if (prefix == "RESTART_X_SECONDS")
  4503. {
  4504. S32 secs = 0;
  4505. LLStringUtil::convertToS32(text.substr(18), secs);
  4506. args["SECONDS"] = llformat("%d", secs);
  4507. gNotifications.add("RegionRestartSeconds", args);
  4508. }
  4509. else
  4510. {
  4511. // *TODO:translate
  4512. args["MESSAGE"] = text;
  4513. gNotifications.add("SystemMessage", args);
  4514. }
  4515. }
  4516. else if (modal)
  4517. {
  4518. // *TODO:translate
  4519. LLSD args;
  4520. args["ERROR_MESSAGE"] = message;
  4521. gNotifications.add("ErrorMessage", args);
  4522. }
  4523. else if (message != "Autopilot canceled") // Do not spam us with that !
  4524. {
  4525. // *TODO:translate
  4526. LLSD args;
  4527. args["MESSAGE"] = message;
  4528. gNotifications.add("SystemMessageTip", args);
  4529. }
  4530. }
  4531. void process_mean_collision_alert_message(LLMessageSystem* msgsystem, void**)
  4532. {
  4533. if (gAgent.inPrelude())
  4534. {
  4535. // In prelude, bumping is OK. This dialog is rather confusing to
  4536. // newbies, so we do not show it. Drop the packet on the floor.
  4537. return;
  4538. }
  4539. LLUUID id;
  4540. U32 time;
  4541. U8 type;
  4542. F32 mag;
  4543. S32 count = msgsystem->getNumberOfBlocks(_PREHASH_MeanCollision);
  4544. for (S32 i = 0; i < count; ++i)
  4545. {
  4546. msgsystem->getUUIDFast(_PREHASH_MeanCollision, _PREHASH_Perp, id);
  4547. msgsystem->getU32Fast(_PREHASH_MeanCollision, _PREHASH_Time, time);
  4548. msgsystem->getF32Fast(_PREHASH_MeanCollision, _PREHASH_Mag, mag);
  4549. msgsystem->getU8Fast(_PREHASH_MeanCollision, _PREHASH_Type, type);
  4550. HBFloaterBump::addMeanCollision(id, time, (EMeanCollisionType)type,
  4551. mag);
  4552. if (gAutomationp)
  4553. {
  4554. gAutomationp->onAgentPush(id, type, mag);
  4555. }
  4556. }
  4557. }
  4558. void process_frozen_message(LLMessageSystem* msgsystem, void**)
  4559. {
  4560. // Make sure the cursor is back to the usual default since the alert is
  4561. // probably due to some kind of error.
  4562. gWindowp->resetBusyCount();
  4563. bool b_frozen;
  4564. msgsystem->getBool(_PREHASH_FrozenData, _PREHASH_Data, b_frozen);
  4565. if (b_frozen)
  4566. {
  4567. // *TODO: make being frozen change view
  4568. llwarns << "You have been frozen !" << llendl;
  4569. }
  4570. else
  4571. {
  4572. llinfos << "You have been un-frozen." << llendl;
  4573. }
  4574. }
  4575. void process_economy_data(LLMessageSystem* msg, void**)
  4576. {
  4577. LLEconomy::getInstance()->processEconomyData(msg);
  4578. update_upload_costs_in_menus();
  4579. }
  4580. void notify_cautioned_script_question(const LLSD& notification,
  4581. const LLSD& response,
  4582. S32 orig_questions, bool granted)
  4583. {
  4584. // Only continue if at least some permissions were requested
  4585. if (orig_questions)
  4586. {
  4587. // Check to see if the person we are asking
  4588. // "'[OBJECTNAME]', an object owned by '[OWNERNAME]',
  4589. // located in [REGIONNAME] at [REGIONPOS],
  4590. // has been <granted|denied> permission to: [PERMISSIONS]."
  4591. LLUIString notice(LLTrans::getString(granted ? "ScriptQuestionCautionChatGranted"
  4592. : "ScriptQuestionCautionChatDenied"));
  4593. std::string object_name =
  4594. notification["payload"]["object_name"].asString();
  4595. std::string owner_name =
  4596. notification["payload"]["owner_name"].asString();
  4597. //MK
  4598. if (gRLenabled &&
  4599. (gRLInterface.mContainsShownames ||
  4600. gRLInterface.mContainsShownametags))
  4601. {
  4602. object_name = gRLInterface.getCensoredMessage(object_name);
  4603. owner_name = gRLInterface.getDummyName(owner_name);
  4604. }
  4605. //mk
  4606. // Always include the object name and owner name
  4607. notice.setArg("[OBJECTNAME]", object_name);
  4608. notice.setArg("[OWNERNAME]", owner_name);
  4609. // Try to lookup viewerobject that corresponds to the object that
  4610. // requested permissions (here, taskid->requesting object id)
  4611. bool foundpos = false;
  4612. LLViewerObject* vobj =
  4613. gObjectList.findObject(notification["payload"]["task_id"].asUUID());
  4614. if (vobj)
  4615. {
  4616. // Found the viewerobject, get its position in its region
  4617. LLVector3 objpos(vobj->getPosition());
  4618. // Try to lookup the name of the region the object is in
  4619. LLViewerRegion* regionp = vobj->getRegion();
  4620. if (regionp)
  4621. {
  4622. // Got the region, so include the region and 3d coordinates of
  4623. // the object
  4624. //MK
  4625. if (gRLenabled && gRLInterface.mContainsShowloc)
  4626. {
  4627. notice.setArg("[REGIONNAME]", "(Region hidden)");
  4628. }
  4629. else
  4630. {
  4631. //mk
  4632. notice.setArg("[REGIONNAME]", regionp->getName());
  4633. //MK
  4634. }
  4635. //mk
  4636. std::string formatpos = llformat("%.1f, %.1f,%.1f",
  4637. objpos[VX], objpos[VY],
  4638. objpos[VZ]);
  4639. notice.setArg("[REGIONPOS]", formatpos);
  4640. foundpos = true;
  4641. }
  4642. }
  4643. if (!foundpos)
  4644. {
  4645. // Unable to determine location of the object
  4646. notice.setArg("[REGIONNAME]", "(unknown region)");
  4647. notice.setArg("[REGIONPOS]", "(unknown position)");
  4648. }
  4649. // Check each permission that was requested, and list each permission
  4650. // that has been flagged as a caution permission
  4651. bool caution = false;
  4652. S32 count = 0;
  4653. std::string perms;
  4654. for (S32 i = 0; i < SCRIPT_PERMISSION_EOF; ++i)
  4655. {
  4656. if ((orig_questions & LSCRIPTRunTimePermissionBits[i]) &&
  4657. SCRIPT_QUESTION_IS_CAUTION[i])
  4658. {
  4659. ++count;
  4660. caution = true;
  4661. // Add a comma before the permission description if it is not
  4662. // the first permission added to the list or the last
  4663. // permission to check
  4664. if (count > 1 && i < SCRIPT_PERMISSION_EOF)
  4665. {
  4666. perms.append(", ");
  4667. }
  4668. perms.append(LLTrans::getString(SCRIPT_QUESTIONS[i]));
  4669. }
  4670. }
  4671. notice.setArg("[PERMISSIONS]", perms);
  4672. // Log a chat message as long as at least one requested permission
  4673. // is a caution permission
  4674. if (caution)
  4675. {
  4676. LLChat chat(notice.getString());
  4677. LLFloaterChat::addChat(chat, false, false);
  4678. }
  4679. }
  4680. }
  4681. // Purge the message queue of any previously queued requests from the same
  4682. // source. DEV-4879
  4683. class QuestionMatcher : public LLNotifyBoxView::Matcher
  4684. {
  4685. public:
  4686. QuestionMatcher(const LLUUID& to_block)
  4687. : mBlockedId(to_block)
  4688. {
  4689. }
  4690. bool matches(const LLNotificationPtr notif) const
  4691. {
  4692. // We do not test for ScriptQuestionOurs neither for
  4693. // ScriptQuestionCaution because these come from our objects which are
  4694. // not mutable (if we got a Mute, it can only come from someone else's
  4695. // object via ScriptQuestion)
  4696. const std::string& name = notif->getName();
  4697. if (name == "ScriptQuestion")
  4698. {
  4699. return notif->getPayload()["task_id"].asUUID() == mBlockedId;
  4700. }
  4701. return false;
  4702. }
  4703. private:
  4704. LLUUID mBlockedId;
  4705. };
  4706. void script_question_mute(const LLUUID& task_id,
  4707. const std::string& object_name)
  4708. {
  4709. LLMute mute(task_id, object_name, LLMute::OBJECT);
  4710. LLMuteList::add(mute);
  4711. LLFloaterMute::selectMute(mute.mID);
  4712. // Should do this via the channel
  4713. gNotifyBoxViewp->purgeMessagesMatching(QuestionMatcher(task_id));
  4714. }
  4715. void block_experience(const LLUUID& exp_id, const LLSD& result)
  4716. {
  4717. LLSD permission;
  4718. permission["permission"] = "Block";
  4719. LLSD data;
  4720. data[exp_id.asString()] = permission;
  4721. data["experience"] = exp_id;
  4722. gEventPumps.obtain(PUMP_EXPERIENCE).post(data);
  4723. }
  4724. bool script_question_cb(const LLSD& notification, const LLSD& response)
  4725. {
  4726. S32 orig = notification["payload"]["questions"].asInteger();
  4727. S32 new_questions = orig;
  4728. if (response["Details"])
  4729. {
  4730. // Respawn notification...
  4731. gNotifications.add(notification["name"], notification["substitutions"],
  4732. notification["payload"]);
  4733. // ... with description on top
  4734. gNotifications.add("DebitPermissionDetails");
  4735. return false;
  4736. }
  4737. LLUUID exp_id;
  4738. if (notification["payload"].has("experience"))
  4739. {
  4740. exp_id = notification["payload"]["experience"].asUUID();
  4741. }
  4742. // Check whether permissions were granted or denied
  4743. bool allowed = true;
  4744. if (LLNotification::getSelectedOption(notification, response) != 0)
  4745. {
  4746. // The "yes/accept" button is the first button in the template, making
  4747. // it button 0; if any other button was clicked, the permissions were
  4748. // denied.
  4749. new_questions = 0;
  4750. allowed = false;
  4751. }
  4752. else if (exp_id.notNull())
  4753. {
  4754. LLSD permission;
  4755. permission["permission"] = "Allow";
  4756. LLSD data;
  4757. data[exp_id.asString()] = permission;
  4758. data["experience"] = exp_id;
  4759. gEventPumps.obtain(PUMP_EXPERIENCE).post(data);
  4760. }
  4761. LLUUID task_id = notification["payload"]["task_id"].asUUID();
  4762. LLUUID item_id = notification["payload"]["item_id"].asUUID();
  4763. // Reply with the permissions granted or denied
  4764. LLMessageSystem* msg = gMessageSystemp;
  4765. msg->newMessageFast(_PREHASH_ScriptAnswerYes);
  4766. msg->nextBlockFast(_PREHASH_AgentData);
  4767. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4768. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4769. msg->nextBlockFast(_PREHASH_Data);
  4770. msg->addUUIDFast(_PREHASH_TaskID, task_id);
  4771. msg->addUUIDFast(_PREHASH_ItemID, item_id);
  4772. msg->addS32Fast(_PREHASH_Questions, new_questions);
  4773. msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
  4774. // Only log a chat message if caution prompts are enabled
  4775. if (gSavedSettings.getBool("PermissionsCautionEnabled"))
  4776. {
  4777. // Log a chat message, if appropriate
  4778. notify_cautioned_script_question(notification, response, orig,
  4779. allowed);
  4780. }
  4781. if (response["client_side_mute"]) // Mute from ScriptQuestion
  4782. {
  4783. std::string name = notification["payload"]["object_name"].asString();
  4784. script_question_mute(task_id, name);
  4785. }
  4786. if (response["BlockExperience"] && exp_id.notNull())
  4787. {
  4788. LLExperienceCache* cachep = LLExperienceCache::getInstance();
  4789. cachep->setExperiencePermission(exp_id, "Block",
  4790. boost::bind(&block_experience,
  4791. exp_id, _1));
  4792. }
  4793. return false;
  4794. }
  4795. static LLNotificationFunctorRegistration script_question_cb_reg_1("ScriptQuestion",
  4796. script_question_cb);
  4797. static LLNotificationFunctorRegistration script_question_cb_reg_2("ScriptQuestionOurs",
  4798. script_question_cb);
  4799. static LLNotificationFunctorRegistration script_question_cb_reg_3("ScriptQuestionCaution",
  4800. script_question_cb);
  4801. static LLNotificationFunctorRegistration script_question_cb_reg_4("ScriptQuestionExperience",
  4802. script_question_cb);
  4803. void process_script_experience_details(const LLSD& experience_details,
  4804. LLSD args, LLSD payload)
  4805. {
  4806. if (experience_details[LLExperienceCache::PROPERTIES].asInteger() &
  4807. LLExperienceCache::PROPERTY_GRID)
  4808. {
  4809. args["GRID_WIDE"] = LLTrans::getString("Grid-Scope");
  4810. }
  4811. else
  4812. {
  4813. args["GRID_WIDE"] = LLTrans::getString("Land-Scope");
  4814. }
  4815. std::string experience =
  4816. LLSLURL("experience",
  4817. experience_details[LLExperienceCache::EXPERIENCE_ID].asUUID(),
  4818. "profile").getSLURLString();
  4819. args["EXPERIENCE"] = experience;
  4820. gNotifications.add("ScriptQuestionExperience", args, payload);
  4821. }
  4822. void process_script_question(LLMessageSystem* msg, void**)
  4823. {
  4824. // *TODO:translate owner name -> [FIRST] [LAST]
  4825. // taskid -> object key of object requesting permissions
  4826. LLUUID taskid;
  4827. msg->getUUIDFast(_PREHASH_Data, _PREHASH_TaskID, taskid);
  4828. // itemid -> script asset key of script requesting permissions
  4829. LLUUID itemid;
  4830. msg->getUUIDFast(_PREHASH_Data, _PREHASH_ItemID, itemid);
  4831. std::string object_name;
  4832. msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, object_name);
  4833. std::string owner_name;
  4834. msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectOwner, owner_name);
  4835. S32 questions;
  4836. msg->getS32Fast(_PREHASH_Data, _PREHASH_Questions, questions);
  4837. LLUUID experienceid;
  4838. if (msg->has(_PREHASH_Experience))
  4839. {
  4840. msg->getUUIDFast(_PREHASH_Experience, _PREHASH_ExperienceID,
  4841. experienceid);
  4842. }
  4843. // Special case. If the objects are owned by this agent, throttle per-
  4844. // object instead of per-owner. It is common for residents to reset a ton
  4845. // of scripts that re-request permissions, as with tier boxes. UUIDs cannot
  4846. // be valid agent names and vice-versa, so we will reuse the same namespace
  4847. // for both throttle types.
  4848. std::string throttle_name = owner_name;
  4849. std::string self_name;
  4850. gAgent.getName(self_name);
  4851. bool is_ours = owner_name == self_name ||
  4852. (gIsInSecondLife && owner_name == self_name + " Resident");
  4853. if (is_ours)
  4854. {
  4855. throttle_name = taskid.asString();
  4856. }
  4857. // Do not display permission requests if this object is muted by Id, by
  4858. // name, or by owner name (agent or group)
  4859. if (LLMuteList::isMuted(taskid, object_name) ||
  4860. LLMuteList::isMuted(LLUUID::null, owner_name, 0, LLMute::AGENT) ||
  4861. LLMuteList::isMuted(LLUUID::null, owner_name, 0, LLMute::GROUP))
  4862. {
  4863. return;
  4864. }
  4865. //MK
  4866. bool auto_acceptable_permission = false;
  4867. if (gRLenabled && gRLInterface.contains("acceptpermission"))
  4868. {
  4869. U32 perms =
  4870. LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_TAKE_CONTROLS] |
  4871. LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_TRIGGER_ANIMATION] |
  4872. LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_ATTACH];
  4873. auto_acceptable_permission = (questions & perms);
  4874. // Security check: if there is any other permission contained in this
  4875. // package, we cannot automatically grant anything
  4876. if (auto_acceptable_permission)
  4877. {
  4878. U32 other_perms = questions & ~perms;
  4879. if (other_perms)
  4880. {
  4881. auto_acceptable_permission = false;
  4882. }
  4883. // Cannot accept animation permission if not sitting
  4884. if (isAgentAvatarValid() && !gAgentAvatarp->mIsSitting &&
  4885. (questions &
  4886. LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_TRIGGER_ANIMATION]))
  4887. {
  4888. auto_acceptable_permission = false;
  4889. }
  4890. // Never auto-accept temp-attach requests from others' objects,
  4891. // unless RestrainedLoveAutoTempAttach is TRUE.
  4892. if (!is_ours &&
  4893. (questions &
  4894. LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_ATTACH]) &&
  4895. !gSavedSettings.getBool("RestrainedLoveRelaxedTempAttach"))
  4896. {
  4897. auto_acceptable_permission = false;
  4898. }
  4899. }
  4900. }
  4901. //mk
  4902. // Throttle excessive requests from any specific user's scripts
  4903. typedef LLKeyThrottle<std::string> LLStringThrottle;
  4904. static LLStringThrottle throttling(LLREQUEST_PERMISSION_THROTTLE_LIMIT,
  4905. LLREQUEST_PERMISSION_THROTTLE_INTERVAL);
  4906. //MK
  4907. // Do not throttle automatically accepted permissions
  4908. if (!auto_acceptable_permission)
  4909. //mk
  4910. {
  4911. switch (throttling.noteAction(throttle_name))
  4912. {
  4913. case LLStringThrottle::THROTTLE_NEWLY_BLOCKED:
  4914. llinfos << "Throttled script question for script pertaining to: "
  4915. << owner_name << llendl;
  4916. return;
  4917. case LLStringThrottle::THROTTLE_BLOCKED:
  4918. // Escape altogether until we recover
  4919. return;
  4920. case LLStringThrottle::THROTTLE_OK:
  4921. break;
  4922. }
  4923. }
  4924. std::string script_question;
  4925. if (questions)
  4926. {
  4927. bool is_owner_linden = LLMuteList::isLinden(owner_name);
  4928. bool caution = false;
  4929. LLSD args;
  4930. args["OBJECTNAME"] = object_name;
  4931. args["NAME"] = owner_name;
  4932. // Check the received permission flags against each permission
  4933. S32 known_questions = 0;
  4934. for (S32 i = 0; i < SCRIPT_PERMISSION_EOF; ++i)
  4935. {
  4936. if (questions & LSCRIPTRunTimePermissionBits[i])
  4937. {
  4938. known_questions |= LSCRIPTRunTimePermissionBits[i];
  4939. // Check whether permission question should cause special
  4940. // caution dialog
  4941. if (!is_owner_linden)
  4942. {
  4943. caution |= SCRIPT_QUESTION_IS_CAUTION[i];
  4944. }
  4945. script_question += " " +
  4946. LLTrans::getString(SCRIPT_QUESTIONS[i]) +
  4947. "\n";
  4948. }
  4949. }
  4950. args["QUESTIONS"] = script_question;
  4951. LLSD payload;
  4952. payload["task_id"] = taskid;
  4953. payload["item_id"] = itemid;
  4954. payload["sender"] = msg->getSender().getIPandPort();
  4955. payload["object_name"] = object_name;
  4956. payload["owner_name"] = owner_name;
  4957. if (known_questions != questions)
  4958. {
  4959. llwarns << "Object \"" << object_name << "\" (" << taskid
  4960. << ") owned by " << owner_name
  4961. << " requested an unknown permission, that therefore cannot be granted."
  4962. << llendl;
  4963. if (!known_questions)
  4964. {
  4965. // No known question so give up now.
  4966. return;
  4967. }
  4968. }
  4969. payload["questions"] = known_questions;
  4970. //MK
  4971. if (auto_acceptable_permission &&
  4972. !(caution && gSavedSettings.getBool("PermissionsCautionEnabled")))
  4973. {
  4974. // Reply with the permissions granted
  4975. gNotifications.forceResponse(LLNotification::Params("ScriptQuestion").payload(payload), 0/*YES*/);
  4976. return;
  4977. }
  4978. //mk
  4979. std::string dialog_name = is_ours ? "ScriptQuestionOurs"
  4980. : "ScriptQuestion";
  4981. // Check whether cautions are even enabled or not
  4982. if (caution && gSavedSettings.getBool("PermissionsCautionEnabled"))
  4983. {
  4984. // Display the caution permissions prompt
  4985. dialog_name = "ScriptQuestionCaution";
  4986. }
  4987. else if (experienceid.notNull())
  4988. {
  4989. payload["experience"] = experienceid;
  4990. LLExperienceCache* exp = LLExperienceCache::getInstance();
  4991. exp->get(experienceid,
  4992. boost::bind(process_script_experience_details, _1, args,
  4993. payload));
  4994. return;
  4995. }
  4996. gNotifications.add(dialog_name, args, payload);
  4997. }
  4998. }
  4999. void process_derez_container(LLMessageSystem* msg, void**)
  5000. {
  5001. llwarns << "Deprecated message callback. Ignored." << llendl;
  5002. }
  5003. // Helper function to format the time.
  5004. std::string formatted_time(time_t the_time)
  5005. {
  5006. static LLCachedControl<std::string> fmt(gSavedSettings, "TimestampFormat");
  5007. std::string timestr;
  5008. timeToFormattedString(the_time, std::string(fmt).c_str(), timestr);
  5009. #if 0 // The original code used to truncate to 24 characters... Seems useless
  5010. // and too restrictive to me... HB
  5011. if (timestr.size() > 24)
  5012. {
  5013. timestr.erase(23);
  5014. }
  5015. #endif
  5016. return timestr;
  5017. }
  5018. void process_teleport_failed(LLMessageSystem* msg, void**)
  5019. {
  5020. std::string reason;
  5021. std::string big_reason;
  5022. LLSD args;
  5023. // Let the interested parties know that teleport failed.
  5024. gViewerParcelMgr.onTeleportFailed();
  5025. // If we have additional alert data
  5026. if (msg->has(_PREHASH_AlertInfo) &&
  5027. msg->getSizeFast(_PREHASH_AlertInfo, _PREHASH_Message) > 0)
  5028. {
  5029. // Get the message ID
  5030. msg->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message, reason);
  5031. big_reason = LLAgent::sTeleportErrorMessages[reason];
  5032. if (big_reason.size() > 0)
  5033. {
  5034. // Substitute verbose reason from the local map
  5035. args["REASON"] = big_reason;
  5036. }
  5037. else
  5038. {
  5039. // Nothing found in the map - use what the server returned in the
  5040. // original message block
  5041. msg->getStringFast(_PREHASH_Info, _PREHASH_Reason, reason);
  5042. args["REASON"] = reason;
  5043. }
  5044. LLSD llsd_block;
  5045. std::string llsd_raw;
  5046. msg->getStringFast(_PREHASH_AlertInfo, _PREHASH_ExtraParams, llsd_raw);
  5047. if (llsd_raw.length())
  5048. {
  5049. std::istringstream llsd_data(llsd_raw);
  5050. if (!LLSDSerialize::deserialize(llsd_block, llsd_data,
  5051. llsd_raw.length()))
  5052. {
  5053. llwarns << "Attempted to read alert parameter data into LLSD but failed: "
  5054. << llsd_raw << llendl;
  5055. }
  5056. // Change notification name in this special case
  5057. else if (handle_trusted_experiences_notification(llsd_block) ||
  5058. handle_special_notification("RegionEntryAccessBlocked",
  5059. llsd_block))
  5060. {
  5061. if (gAgent.teleportInProgress())
  5062. {
  5063. LL_DEBUGS("Teleport") << "Resetting to TELEPORT_NONE"
  5064. << LL_ENDL;
  5065. gAgent.setTeleportState(LLAgent::TELEPORT_NONE);
  5066. }
  5067. return;
  5068. }
  5069. }
  5070. }
  5071. else
  5072. {
  5073. msg->getStringFast(_PREHASH_Info, _PREHASH_Reason, reason);
  5074. big_reason = LLAgent::sTeleportErrorMessages[reason];
  5075. if (big_reason.size() > 0)
  5076. {
  5077. // Substitute verbose reason from the local map
  5078. args["REASON"] = big_reason;
  5079. }
  5080. else
  5081. {
  5082. // Nothing found in the map - use what the server returned
  5083. args["REASON"] = reason;
  5084. }
  5085. }
  5086. if (gAgent.teleportInProgress())
  5087. {
  5088. LL_DEBUGS("Teleport") << "Resetting to TELEPORT_NONE" << LL_ENDL;
  5089. gAgent.setTeleportState(LLAgent::TELEPORT_NONE, reason);
  5090. }
  5091. gNotifications.add("CouldNotTeleportReason", args);
  5092. }
  5093. void process_teleport_local(LLMessageSystem* msg, void**)
  5094. {
  5095. LL_DEBUGS("Teleport") << "Processing local teleport message" << LL_ENDL;
  5096. LLUUID agent_id;
  5097. msg->getUUIDFast(_PREHASH_Info, _PREHASH_AgentID, agent_id);
  5098. if (agent_id != gAgentID)
  5099. {
  5100. llwarns << "Got teleport notification for wrong agent !" << llendl;
  5101. return;
  5102. }
  5103. U32 location_id;
  5104. LLVector3 pos, look_at;
  5105. U32 teleport_flags;
  5106. msg->getU32Fast(_PREHASH_Info, _PREHASH_LocationID, location_id);
  5107. msg->getVector3Fast(_PREHASH_Info, _PREHASH_Position, pos);
  5108. msg->getVector3Fast(_PREHASH_Info, _PREHASH_LookAt, look_at);
  5109. msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
  5110. // Sim tells us whether the new position is off the ground
  5111. if (teleport_flags & TELEPORT_FLAGS_IS_FLYING)
  5112. {
  5113. gAgent.setFlying(true);
  5114. }
  5115. else
  5116. {
  5117. gAgent.setFlying(false);
  5118. }
  5119. gAgent.setPositionAgent(pos);
  5120. gAgent.slamLookAt(look_at);
  5121. if (!(gAgent.getTeleportKeepsLookAt() &&
  5122. LLViewerJoystick::getInstance()->getOverrideCamera()))
  5123. {
  5124. gAgent.resetView(true, true);
  5125. }
  5126. // Send camera update to new region
  5127. gAgent.updateCamera();
  5128. // Do this *after* the agent position is set and camera update is done
  5129. // (see above), so that the setTeleportState() method can use the new
  5130. // position... HB.
  5131. if (gAgent.teleportInProgress())
  5132. {
  5133. if (gAgent.getTeleportState() == LLAgent::TELEPORT_LOCAL)
  5134. {
  5135. // To prevent TeleportStart messages re-activating the progress
  5136. // screen right after tp, keep the teleport state and let progress
  5137. // screen clear it after a short delay (progress screen is active
  5138. // but not visible) *TODO: remove when SVC-5290 is fixed
  5139. gTeleportDisplayTimer.reset();
  5140. gTeleportDisplay = true;
  5141. }
  5142. else
  5143. {
  5144. LL_DEBUGS("Teleport") << "Resetting to TELEPORT_NONE" << LL_ENDL;
  5145. gAgent.setTeleportState(LLAgent::TELEPORT_NONE);
  5146. }
  5147. }
  5148. send_agent_update(true, true);
  5149. // Let the interested parties know we've teleported.
  5150. // *HACK: Agent position seems to get reset (to render position ?) on each
  5151. // frame, so we have to pass the new position manually. - Vadim
  5152. gViewerParcelMgr.onTeleportFinished(true,
  5153. gAgent.getPosGlobalFromAgent(pos));
  5154. }
  5155. void send_simple_im(const LLUUID& to_id,
  5156. const std::string& message,
  5157. EInstantMessage dialog,
  5158. const LLUUID& id)
  5159. {
  5160. std::string my_name;
  5161. gAgent.buildFullname(my_name);
  5162. send_improved_im(to_id, my_name, message, IM_ONLINE, dialog, id,
  5163. NO_TIMESTAMP, (U8*)EMPTY_BINARY_BUCKET,
  5164. EMPTY_BINARY_BUCKET_SIZE);
  5165. }
  5166. void send_group_notice(const LLUUID& group_id,
  5167. const std::string& subject,
  5168. const std::string& message,
  5169. const LLInventoryItem* item)
  5170. {
  5171. // Put this notice into an instant message form. This will mean converting
  5172. // the item to a binary bucket and the subject/message into a single field.
  5173. std::string my_name;
  5174. gAgent.buildFullname(my_name);
  5175. // Combine subject + message into a single string.
  5176. std::ostringstream subject_and_message;
  5177. // *TODO: turn all existing |'s into ||'s in subject and message.
  5178. subject_and_message << subject << "|" << message;
  5179. // Create an empty binary bucket.
  5180. U8 bin_bucket[MAX_INVENTORY_BUFFER_SIZE];
  5181. U8* bucket_to_send = bin_bucket;
  5182. bin_bucket[0] = '\0';
  5183. S32 bin_bucket_size = EMPTY_BINARY_BUCKET_SIZE;
  5184. // If there is an item being sent, pack it into the binary bucket.
  5185. if (item)
  5186. {
  5187. LLSD item_def;
  5188. item_def["item_id"] = item->getUUID();
  5189. item_def["owner_id"] = item->getPermissions().getOwner();
  5190. std::ostringstream ostr;
  5191. LLSDSerialize::serialize(item_def, ostr, LLSDSerialize::LLSD_XML);
  5192. bin_bucket_size = ostr.str().copy((char*)bin_bucket,
  5193. ostr.str().size());
  5194. bin_bucket[bin_bucket_size] = '\0';
  5195. }
  5196. else
  5197. {
  5198. bucket_to_send = (U8*) EMPTY_BINARY_BUCKET;
  5199. }
  5200. send_improved_im(group_id, my_name, subject_and_message.str(), IM_ONLINE,
  5201. IM_GROUP_NOTICE, LLUUID::null, NO_TIMESTAMP,
  5202. bucket_to_send, bin_bucket_size);
  5203. }
  5204. bool handle_lure_callback(const LLSD& notification, const LLSD& response)
  5205. {
  5206. constexpr S32 OFFER_RECIPIENT_LIMIT = 250;
  5207. if (notification["payload"]["ids"].size() > OFFER_RECIPIENT_LIMIT)
  5208. {
  5209. // More than OFFER_RECIPIENT_LIMIT targets will overload the message
  5210. // producing an llerror.
  5211. LLSD args;
  5212. args["OFFERS"] = notification["payload"]["ids"].size();
  5213. args["LIMIT"] = OFFER_RECIPIENT_LIMIT;
  5214. gNotifications.add("TooManyTeleportOffers", args);
  5215. return false;
  5216. }
  5217. if (LLNotification::getSelectedOption(notification, response) == 0)
  5218. {
  5219. send_lures(notification, response);
  5220. }
  5221. return false;
  5222. }
  5223. // Prompt for a message to the invited user.
  5224. void handle_lure(const uuid_vec_t& ids)
  5225. {
  5226. if (ids.size() == 0)
  5227. {
  5228. return;
  5229. }
  5230. LLSD edit_args;
  5231. //MK
  5232. if (gRLenabled && gRLInterface.mContainsShowloc)
  5233. {
  5234. edit_args["REGION"] = "(Hidden)";
  5235. }
  5236. else
  5237. //mk
  5238. if (gAgent.getRegion())
  5239. {
  5240. edit_args["REGION"] = gAgent.getRegion()->getName();
  5241. }
  5242. else
  5243. {
  5244. edit_args["REGION"] = "Unknown region";
  5245. }
  5246. LLSD payload;
  5247. for (uuid_vec_t::const_iterator it = ids.begin(), end = ids.end();
  5248. it != end; ++it)
  5249. {
  5250. payload["ids"].append(*it);
  5251. }
  5252. if (gAgent.isGodlike())
  5253. {
  5254. gNotifications.add("OfferTeleportFromGod", edit_args, payload,
  5255. handle_lure_callback);
  5256. }
  5257. else
  5258. {
  5259. gNotifications.add("OfferTeleport", edit_args, payload,
  5260. handle_lure_callback);
  5261. }
  5262. }
  5263. void send_improved_im(const LLUUID& to_id, const std::string& name,
  5264. const std::string& message, U8 offline,
  5265. EInstantMessage dialog, const LLUUID& id, U32 timestamp,
  5266. const U8* binary_bucket, S32 binary_bucket_size)
  5267. {
  5268. pack_instant_message(gAgentID, false, gAgentSessionID, to_id, name,
  5269. message, offline, dialog, id, 0, LLUUID::null,
  5270. gAgent.getPositionAgent(), timestamp, binary_bucket,
  5271. binary_bucket_size);
  5272. gAgent.sendReliableMessage();
  5273. }
  5274. void send_places_query(const LLUUID& query_id, const LLUUID& trans_id,
  5275. const std::string& query_text, U32 query_flags,
  5276. S32 category, const std::string& sim_name)
  5277. {
  5278. LLMessageSystem* msg = gMessageSystemp;
  5279. msg->newMessage("PlacesQuery");
  5280. msg->nextBlock(_PREHASH_AgentData);
  5281. msg->addUUID(_PREHASH_AgentID, gAgentID);
  5282. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  5283. msg->addUUID(_PREHASH_QueryID, query_id);
  5284. msg->nextBlock(_PREHASH_TransactionData);
  5285. msg->addUUID(_PREHASH_TransactionID, trans_id);
  5286. msg->nextBlock(_PREHASH_QueryData);
  5287. msg->addString(_PREHASH_QueryText, query_text);
  5288. msg->addU32(_PREHASH_QueryFlags, query_flags);
  5289. msg->addS8(_PREHASH_Category, (S8)category);
  5290. msg->addString(_PREHASH_SimName, sim_name);
  5291. gAgent.sendReliableMessage();
  5292. }
  5293. void process_user_info_reply(LLMessageSystem* msg, void**)
  5294. {
  5295. LLUUID agent_id;
  5296. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  5297. if (agent_id != gAgentID)
  5298. {
  5299. llwarns << "process_user_info_reply - wrong agent id." << llendl;
  5300. }
  5301. bool im_via_email;
  5302. msg->getBoolFast(_PREHASH_UserData, _PREHASH_IMViaEMail, im_via_email);
  5303. std::string email;
  5304. msg->getStringFast(_PREHASH_UserData, _PREHASH_EMail, email);
  5305. std::string dir_visibility;
  5306. msg->getString(_PREHASH_UserData, _PREHASH_DirectoryVisibility,
  5307. dir_visibility);
  5308. LLFloaterPreference::updateUserInfo(dir_visibility, im_via_email, email);
  5309. LLFloaterPostcard::updateUserInfo(email);
  5310. }
  5311. //---------------------------------------------------------------------------
  5312. // Script Dialog
  5313. //---------------------------------------------------------------------------
  5314. constexpr S32 SCRIPT_DIALOG_MAX_BUTTONS = 12;
  5315. bool callback_script_dialog(const LLSD& notification, const LLSD& response)
  5316. {
  5317. LLNotificationForm form(notification["form"]);
  5318. std::string button = LLNotification::getSelectedOptionName(response);
  5319. S32 button_idx = LLNotification::getSelectedOption(notification, response);
  5320. LLUUID object_id = notification["payload"]["object_id"].asUUID();
  5321. if (button_idx == -2) // Clicked "Mute"
  5322. {
  5323. std::string object_name =
  5324. notification["payload"]["object_name"].asString();
  5325. LLMute mute(object_id, object_name, LLMute::OBJECT);
  5326. if (LLMuteList::add(mute))
  5327. {
  5328. LLFloaterMute::selectMute(mute.mID);
  5329. }
  5330. }
  5331. else if (button_idx != -1) // Did not click "Ignore"
  5332. {
  5333. if (notification["payload"].has("textbox"))
  5334. {
  5335. button = response["message"].asString();
  5336. }
  5337. S32 channel = notification["payload"]["chat_channel"].asInteger();
  5338. //MK
  5339. if (!channel && gRLenabled &&
  5340. (gRLInterface.containsSubstr("redirchat:") ||
  5341. gRLInterface.containsSubstr("sendchat")))
  5342. {
  5343. return false;
  5344. }
  5345. //mk
  5346. LL_DEBUGS("Messaging") << "Sending dialog reply to object "
  5347. << object_id << " on channel " << channel
  5348. << " with button index " << button_idx
  5349. << " and message: " << button << LL_ENDL;
  5350. LLMessageSystem* msg = gMessageSystemp;
  5351. msg->newMessage(_PREHASH_ScriptDialogReply);
  5352. msg->nextBlock(_PREHASH_AgentData);
  5353. msg->addUUID(_PREHASH_AgentID, gAgentID);
  5354. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  5355. msg->nextBlock(_PREHASH_Data);
  5356. msg->addUUID(_PREHASH_ObjectID, object_id);
  5357. msg->addS32(_PREHASH_ChatChannel, channel);
  5358. msg->addS32(_PREHASH_ButtonIndex, button_idx);
  5359. msg->addString(_PREHASH_ButtonLabel, button);
  5360. msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
  5361. }
  5362. return false;
  5363. }
  5364. static LLNotificationFunctorRegistration callback_script_dialog_reg_1("ScriptDialog",
  5365. callback_script_dialog);
  5366. static LLNotificationFunctorRegistration callback_script_dialog_reg_2("ScriptDialogOurs",
  5367. callback_script_dialog);
  5368. static LLNotificationFunctorRegistration callback_script_dialog_reg_3("ScriptTextBox",
  5369. callback_script_dialog);
  5370. static LLNotificationFunctorRegistration callback_script_dialog_reg_4("ScriptTextBoxOurs",
  5371. callback_script_dialog);
  5372. // Purge the message queue from any previously queued script dialog from the
  5373. // same source, with the same channel.
  5374. class ScriptDialogMatcher : public LLNotifyBoxView::Matcher
  5375. {
  5376. public:
  5377. ScriptDialogMatcher(const std::string& dialog, const LLUUID& object_id,
  5378. S32 channel)
  5379. : mName(dialog),
  5380. mObjectId(object_id),
  5381. mChannel(channel)
  5382. {
  5383. }
  5384. bool matches(const LLNotificationPtr notif) const
  5385. {
  5386. static LLCachedControl<bool> ignore_channel(gSavedSettings,
  5387. "ScriptDialogUnique");
  5388. return notif->getName() == mName &&
  5389. notif->getPayload()["object_id"].asUUID() == mObjectId &&
  5390. (ignore_channel ||
  5391. notif->getPayload()["chat_channel"].asInteger() == mChannel);
  5392. }
  5393. private:
  5394. S32 mChannel;
  5395. LLUUID mObjectId;
  5396. std::string mName;
  5397. };
  5398. void process_script_dialog(LLMessageSystem* msg, void**)
  5399. {
  5400. LLUUID object_id;
  5401. msg->getUUID(_PREHASH_Data, _PREHASH_ObjectID, object_id);
  5402. std::string first_name;
  5403. msg->getString(_PREHASH_Data, _PREHASH_FirstName, first_name);
  5404. if (first_name == "(??\?)")
  5405. {
  5406. first_name.clear();
  5407. }
  5408. std::string last_name;
  5409. msg->getString(_PREHASH_Data, _PREHASH_LastName, last_name);
  5410. if (last_name == "(??\?)")
  5411. {
  5412. last_name.clear();
  5413. }
  5414. std::string object_name;
  5415. msg->getString(_PREHASH_Data, _PREHASH_ObjectName, object_name);
  5416. std::string message;
  5417. msg->getString(_PREHASH_Data, _PREHASH_Message, message);
  5418. S32 chat_channel;
  5419. msg->getS32(_PREHASH_Data, _PREHASH_ChatChannel, chat_channel);
  5420. #if 0 // Unused for now
  5421. LLUUID image_id;
  5422. msg->getUUID(_PREHASH_Data, _PREHASH_ImageID, image_id);
  5423. #endif
  5424. LLUUID owner_id;
  5425. // Get the owner Id if it is part of the message (new ScriptDialog message)
  5426. if (gMessageSystemp->getNumberOfBlocks(_PREHASH_OwnerData) > 0)
  5427. {
  5428. msg->getUUID(_PREHASH_OwnerData, _PREHASH_OwnerID, owner_id);
  5429. }
  5430. LLViewerObject* vobj = gObjectList.findObject(object_id);
  5431. // Keep track of the owner's Id for that object.
  5432. if (vobj && vobj->mOwnerID.isNull() && owner_id.notNull())
  5433. {
  5434. vobj->mOwnerID = owner_id;
  5435. }
  5436. // Ignore dialogs coming from muted objects or pertaining to muted
  5437. // residents.
  5438. bool is_ours = vobj && vobj->permYouOwner();
  5439. if (!is_ours) // Do not apply to objects we own
  5440. {
  5441. // Check for mutes by object id and by name
  5442. bool muted = LLMuteList::isMuted(object_id, object_name);
  5443. // Check for mutes by owner
  5444. if (!muted)
  5445. {
  5446. if (owner_id.notNull())
  5447. {
  5448. // Check for mutes by owner id
  5449. muted = LLMuteList::isMuted(owner_id);
  5450. }
  5451. else if (!last_name.empty())
  5452. {
  5453. // Check for mutes by group or owner name (id is unknown to us)
  5454. if (first_name.empty())
  5455. {
  5456. muted = LLMuteList::isMuted(LLUUID::null, last_name, 0,
  5457. LLMute::GROUP);
  5458. }
  5459. else
  5460. {
  5461. muted = LLMuteList::isMuted(LLUUID::null,
  5462. first_name + " " + last_name,
  5463. 0, LLMute::AGENT);
  5464. }
  5465. }
  5466. }
  5467. if (muted)
  5468. {
  5469. // Do not spam the log with such messages...
  5470. llinfos_once << "Muting scripted object dialog(s) from: "
  5471. << first_name << " " << last_name << "'s "
  5472. << object_name << llendl;
  5473. return;
  5474. }
  5475. }
  5476. LLSD payload;
  5477. payload["sender"] = msg->getSender().getIPandPort();
  5478. payload["object_id"] = object_id;
  5479. payload["chat_channel"] = chat_channel;
  5480. payload["object_name"] = object_name;
  5481. // Build up custom form
  5482. S32 button_count = msg->getNumberOfBlocks(_PREHASH_Buttons);
  5483. if (button_count > SCRIPT_DIALOG_MAX_BUTTONS)
  5484. {
  5485. llwarns << "Too many script dialog buttons - omitting some" << llendl;
  5486. button_count = SCRIPT_DIALOG_MAX_BUTTONS;
  5487. }
  5488. LLNotificationForm form; // Used only for llDialog()
  5489. bool is_text_box = false;
  5490. if (button_count)
  5491. {
  5492. for (S32 i = 0; i < button_count; ++i)
  5493. {
  5494. std::string label;
  5495. msg->getString(_PREHASH_Buttons, _PREHASH_ButtonLabel, label, i);
  5496. if (label == "!!llTextBox!!")
  5497. {
  5498. is_text_box = true;
  5499. // Do not bother with the rest of the buttons in 'form': it is
  5500. // not used for llTextBox()...
  5501. break;
  5502. }
  5503. form.addElement("button", label);
  5504. }
  5505. }
  5506. else // This should not happen...
  5507. {
  5508. form.addElement("button", LLStringUtil::null);
  5509. }
  5510. LLSD args;
  5511. args["TITLE"] = object_name;
  5512. args["MESSAGE"] = message;
  5513. std::string name;
  5514. if (first_name.empty())
  5515. {
  5516. name = last_name;
  5517. }
  5518. else
  5519. {
  5520. name = first_name;
  5521. if (!last_name.empty())
  5522. {
  5523. name += " " + last_name;
  5524. }
  5525. if (LLAvatarName::sOmitResidentAsLastName)
  5526. {
  5527. name = LLCacheName::cleanFullName(name);
  5528. }
  5529. }
  5530. if (name.empty())
  5531. {
  5532. name = "Unknown owner";
  5533. }
  5534. args["NAME"] = name;
  5535. bool anti_spam = gSavedSettings.getBool("ScriptDialogAntiSpam");
  5536. std::string dialog;
  5537. if (is_text_box)
  5538. {
  5539. payload["textbox"] = "true";
  5540. dialog = is_ours ? "ScriptTextBoxOurs" : "ScriptTextBox";
  5541. if (anti_spam)
  5542. {
  5543. gNotifyBoxViewp->purgeMessagesMatching(ScriptDialogMatcher(dialog,
  5544. object_id,
  5545. chat_channel));
  5546. }
  5547. gNotifications.add(dialog, args, payload);
  5548. }
  5549. else
  5550. {
  5551. dialog = is_ours ? "ScriptDialogOurs" : "ScriptDialog";
  5552. if (anti_spam)
  5553. {
  5554. gNotifyBoxViewp->purgeMessagesMatching(ScriptDialogMatcher(dialog,
  5555. object_id,
  5556. chat_channel));
  5557. }
  5558. gNotifications.add(LLNotification::Params(dialog).substitutions(args).payload(payload).form_elements(form.asLLSD()));
  5559. }
  5560. }
  5561. //---------------------------------------------------------------------------
  5562. std::vector<LLSD> gLoadUrlList;
  5563. bool callback_load_url(const LLSD& notification, const LLSD& response)
  5564. {
  5565. S32 option = LLNotification::getSelectedOption(notification, response);
  5566. if (option == 0) // Goto page
  5567. {
  5568. LLWeb::loadURL(notification["payload"]["url"].asString());
  5569. }
  5570. else if (option == 2) // Mute
  5571. {
  5572. LLUUID id = notification["payload"]["object_id"].asUUID();
  5573. std::string name = notification["payload"]["object_name"].asString();
  5574. LLMute mute(id, name, LLMute::OBJECT);
  5575. if (LLMuteList::add(mute))
  5576. {
  5577. LLFloaterMute::selectMute(mute.mID);
  5578. }
  5579. }
  5580. return false;
  5581. }
  5582. static LLNotificationFunctorRegistration callback_load_url_reg1("LoadWebPage",
  5583. callback_load_url);
  5584. static LLNotificationFunctorRegistration callback_load_url_reg2("LoadWebPageOurs",
  5585. callback_load_url);
  5586. // We have got the name of the person who owns the object hurling the url.
  5587. // Display confirmation dialog.
  5588. void callback_load_url_name(const LLUUID& id, const std::string& full_name,
  5589. bool is_group)
  5590. {
  5591. std::vector<LLSD>::iterator it;
  5592. for (it = gLoadUrlList.begin(); it != gLoadUrlList.end(); )
  5593. {
  5594. LLSD load_url_info = *it;
  5595. if (load_url_info["owner_id"].asUUID() == id)
  5596. {
  5597. it = gLoadUrlList.erase(it);
  5598. // Check for mutes.
  5599. if (LLMuteList::isMuted(id, full_name, 0,
  5600. is_group ? LLMute::GROUP : LLMute::AGENT))
  5601. {
  5602. // Do not spam the log with such messages...
  5603. llinfos_once << "Ignoring load_url from muted owner "
  5604. << full_name << llendl;
  5605. continue;
  5606. }
  5607. std::string owner_name;
  5608. if (is_group)
  5609. {
  5610. owner_name = full_name + " (group)";
  5611. }
  5612. else
  5613. {
  5614. owner_name = full_name;
  5615. }
  5616. LLSD args;
  5617. args["URL"] = load_url_info["url"].asString();
  5618. args["MESSAGE"] = load_url_info["message"].asString();;
  5619. args["OBJECTNAME"] = load_url_info["object_name"].asString();
  5620. args["NAME"] = owner_name;
  5621. std::string dialog = id == gAgentID ? "LoadWebPageOurs"
  5622. : "LoadWebPage";
  5623. gNotifications.add(dialog, args, load_url_info);
  5624. }
  5625. else
  5626. {
  5627. ++it;
  5628. }
  5629. }
  5630. }
  5631. void process_load_url(LLMessageSystem* msg, void**)
  5632. {
  5633. char object_name[256];
  5634. msg->getString(_PREHASH_Data, _PREHASH_ObjectName, 256, object_name);
  5635. LLUUID object_id;
  5636. msg->getUUID(_PREHASH_Data, _PREHASH_ObjectID, object_id);
  5637. LLUUID owner_id;
  5638. msg->getUUID(_PREHASH_Data, _PREHASH_OwnerID, owner_id);
  5639. bool owner_is_group;
  5640. msg->getBool(_PREHASH_Data, _PREHASH_OwnerIsGroup, owner_is_group);
  5641. char message[256];
  5642. msg->getString(_PREHASH_Data, _PREHASH_Message, 256, message);
  5643. char url[256];
  5644. msg->getString(_PREHASH_Data, _PREHASH_URL, 256, url);
  5645. LLSD payload;
  5646. payload["object_id"] = object_id;
  5647. payload["owner_id"] = owner_id;
  5648. payload["owner_is_group"] = owner_is_group;
  5649. payload["object_name"] = object_name;
  5650. payload["message"] = message;
  5651. payload["url"] = url;
  5652. // URL is safety checked in load_url above
  5653. // Check if object or owner is muted
  5654. if (LLMuteList::isMuted(owner_id))
  5655. {
  5656. llinfos_once << "Ignoring load_url from muted object owner: "
  5657. << owner_id << llendl;
  5658. return;
  5659. }
  5660. if (LLMuteList::isMuted(object_id, object_name))
  5661. {
  5662. llinfos_once << "Ignoring load_url from muted object: " << object_name
  5663. << llendl;
  5664. return;
  5665. }
  5666. // Add to list of pending name lookups
  5667. gLoadUrlList.emplace_back(payload);
  5668. if (gCacheNamep)
  5669. {
  5670. gCacheNamep->get(owner_id, owner_is_group, callback_load_url_name);
  5671. }
  5672. }
  5673. void callback_download_complete(void** data, S32 result, LLExtStat)
  5674. {
  5675. std::string* filepath = (std::string*)data;
  5676. LLSD args;
  5677. args["DOWNLOAD_PATH"] = *filepath;
  5678. gNotifications.add("FinishedRawDownload", args);
  5679. delete filepath;
  5680. }
  5681. void process_initiate_download(LLMessageSystem* msg, void**)
  5682. {
  5683. if (!gXferManagerp)
  5684. {
  5685. llwarns << "Transfer manager gone. Aborted." << llendl;
  5686. return;
  5687. }
  5688. LLUUID agent_id;
  5689. msg->getUUID(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  5690. if (agent_id != gAgentID)
  5691. {
  5692. llwarns << "Initiate download for wrong agent" << llendl;
  5693. return;
  5694. }
  5695. std::string sim_filename;
  5696. std::string viewer_filename;
  5697. msg->getString("FileData", "SimFilename", sim_filename);
  5698. msg->getString("FileData", "ViewerFilename", viewer_filename);
  5699. if (!gXferManagerp->validateFileForRequest(viewer_filename))
  5700. {
  5701. llwarns << "SECURITY: Unauthorized download to local file '"
  5702. << viewer_filename << "'. Aborted !" << llendl;
  5703. return;
  5704. }
  5705. gXferManagerp->requestFile(viewer_filename, sim_filename, LL_PATH_NONE,
  5706. msg->getSender(), false, // do not delete remote
  5707. callback_download_complete,
  5708. (void**)new std::string(viewer_filename));
  5709. }
  5710. void process_script_teleport_request(LLMessageSystem* msg, void**)
  5711. {
  5712. std::string object_name;
  5713. msg->getString(_PREHASH_Data, _PREHASH_ObjectName, object_name);
  5714. std::string sim_name;
  5715. msg->getString(_PREHASH_Data, _PREHASH_SimName, sim_name);
  5716. LLVector3 pos;
  5717. msg->getVector3(_PREHASH_Data, _PREHASH_SimPosition, pos);
  5718. LLVector3 look_at;
  5719. msg->getVector3(_PREHASH_Data, _PREHASH_LookAt, look_at);
  5720. #if 1 // 0 to re-enable parcel browser for llMapDestination()
  5721. if (gFloaterWorldMapp)
  5722. {
  5723. llinfos << "Object '" << object_name << "' is offering TP to region '"
  5724. << sim_name << "' at position " << pos << llendl;
  5725. gFloaterWorldMapp->trackURL(sim_name, (S32)pos.mV[VX], (S32)pos.mV[VY],
  5726. (S32)pos.mV[VZ]);
  5727. LLFloaterWorldMap::show(NULL, true);
  5728. }
  5729. #else
  5730. LLURLDispatcher::dispatch(LLURLDispatcher::buildSLURL(sim_name,
  5731. (S32)pos.mV[VX],
  5732. (S32)pos.mV[VY],
  5733. (S32)pos.mV[VZ]),
  5734. false);
  5735. #endif
  5736. }
  5737. void callbackCacheEstateOwnerName(const LLUUID& id,
  5738. const std::string& fullname,
  5739. bool is_group)
  5740. {
  5741. std::string name;
  5742. if (id.isNull())
  5743. {
  5744. name = "(none)";
  5745. }
  5746. else
  5747. {
  5748. name = fullname;
  5749. }
  5750. LLPanelEstateInfo::updateEstateOwnerName(name);
  5751. LLPanelEstateCovenant::updateEstateOwnerName(name);
  5752. LLPanelLandCovenant::updateEstateOwnerName(name);
  5753. LLFloaterBuyLand::updateEstateOwnerName(name);
  5754. }
  5755. void onCovenantLoadComplete(const LLUUID& asset_uuid, LLAssetType::EType type,
  5756. void*, S32 status, LLExtStat)
  5757. {
  5758. LL_DEBUGS("Messaging") << "Covenant loaded" << LL_ENDL;
  5759. std::string covenant_text;
  5760. if (status == 0)
  5761. {
  5762. LLFileSystem file(asset_uuid);
  5763. S32 file_length = file.getSize();
  5764. char* buffer = new char[file_length + 1];
  5765. if (buffer == NULL)
  5766. {
  5767. llerrs << "Memory Allocation failed" << llendl;
  5768. return;
  5769. }
  5770. file.read((U8*)buffer, file_length);
  5771. // Put a EOS at the end
  5772. buffer[file_length] = 0;
  5773. if (file_length > 19 && !strncmp(buffer, "Linden text version", 19))
  5774. {
  5775. LLViewerTextEditor* editor;
  5776. editor = new LLViewerTextEditor(std::string("temp"),
  5777. LLRect(0, 0, 0, 0),
  5778. file_length + 1);
  5779. if (!editor->importBuffer(buffer, file_length + 1))
  5780. {
  5781. llwarns << "Problem importing estate covenant." << llendl;
  5782. covenant_text = "Problem importing estate covenant.";
  5783. }
  5784. else
  5785. {
  5786. // Version 0 (just text, does not include version number)
  5787. covenant_text = editor->getText();
  5788. }
  5789. delete[] buffer;
  5790. delete editor;
  5791. }
  5792. else
  5793. {
  5794. covenant_text = "Problem importing estate covenant: covenant file format error.";
  5795. llwarns << covenant_text << llendl;
  5796. }
  5797. }
  5798. else
  5799. {
  5800. gViewerStats.incStat(LLViewerStats::ST_DOWNLOAD_FAILED);
  5801. if (LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status ||
  5802. LL_ERR_FILE_EMPTY == status)
  5803. {
  5804. covenant_text = "Estate covenant notecard is missing from database.";
  5805. }
  5806. else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
  5807. {
  5808. covenant_text = "Insufficient permissions to view estate covenant.";
  5809. }
  5810. else
  5811. {
  5812. covenant_text = "Unable to load estate covenant at this time.";
  5813. }
  5814. llwarns << "Problem loading notecard: " << covenant_text << llendl;
  5815. }
  5816. LLPanelEstateCovenant::updateCovenantText(covenant_text, asset_uuid);
  5817. LLPanelLandCovenant::updateCovenantText(covenant_text);
  5818. LLFloaterBuyLand::updateCovenantText(covenant_text, asset_uuid);
  5819. }
  5820. void process_covenant_reply(LLMessageSystem* msg, void**)
  5821. {
  5822. LLUUID covenant_id, estate_owner_id;
  5823. std::string estate_name;
  5824. U32 covenant_timestamp;
  5825. msg->getUUID(_PREHASH_Data, _PREHASH_CovenantID, covenant_id);
  5826. msg->getU32(_PREHASH_Data, _PREHASH_CovenantTimestamp, covenant_timestamp);
  5827. msg->getString(_PREHASH_Data, _PREHASH_EstateName, estate_name);
  5828. msg->getUUID(_PREHASH_Data, _PREHASH_EstateOwnerID, estate_owner_id);
  5829. LLPanelEstateInfo::updateEstateName(estate_name);
  5830. LLPanelEstateCovenant::updateEstateName(estate_name);
  5831. LLPanelLandCovenant::updateEstateName(estate_name);
  5832. LLFloaterBuyLand::updateEstateName(estate_name);
  5833. // Standard message, not from system
  5834. std::string last_modified;
  5835. if (covenant_timestamp == 0)
  5836. {
  5837. last_modified = LLTrans::getString("covenant_never_modified");
  5838. }
  5839. else
  5840. {
  5841. last_modified = LLTrans::getString("covenant_modified") + " " +
  5842. formatted_time((time_t)covenant_timestamp);
  5843. }
  5844. LLPanelEstateCovenant::updateLastModified(last_modified);
  5845. LLPanelLandCovenant::updateLastModified(last_modified);
  5846. LLFloaterBuyLand::updateLastModified(last_modified);
  5847. if (gCacheNamep)
  5848. {
  5849. gCacheNamep->get(estate_owner_id, false, callbackCacheEstateOwnerName);
  5850. }
  5851. // Load the actual covenant asset data
  5852. if (covenant_id.notNull())
  5853. {
  5854. constexpr bool high_priority = true;
  5855. gAssetStoragep->getEstateAsset(gAgent.getRegionHost(), gAgentID,
  5856. gAgentSessionID, covenant_id,
  5857. LLAssetType::AT_NOTECARD, ET_Covenant,
  5858. onCovenantLoadComplete, NULL,
  5859. high_priority);
  5860. }
  5861. else
  5862. {
  5863. std::string covenant_text;
  5864. if (estate_owner_id.isNull()) // Mainland
  5865. {
  5866. covenant_text = LLTrans::getString("no_covenant_for_mainland");
  5867. }
  5868. else // Privately owned estate
  5869. {
  5870. covenant_text = LLTrans::getString("no_covenant_for_estate");
  5871. }
  5872. LLPanelEstateCovenant::updateCovenantText(covenant_text, covenant_id);
  5873. LLPanelLandCovenant::updateCovenantText(covenant_text);
  5874. LLFloaterBuyLand::updateCovenantText(covenant_text, covenant_id);
  5875. }
  5876. }
  5877. // Handles black-listed feature simulator response.
  5878. void process_feature_disabled_message(LLMessageSystem* msg, void**)
  5879. {
  5880. LLUUID agent_id;
  5881. msg->getUUIDFast(_PREHASH_FailureInfo, _PREHASH_AgentID, agent_id);
  5882. if (agent_id != gAgentID)
  5883. {
  5884. return; // Not for us !...
  5885. }
  5886. std::string message;
  5887. msg->getStringFast(_PREHASH_FailureInfo, _PREHASH_ErrorMessage,
  5888. message, 0);
  5889. LLUUID trans_id;
  5890. msg->getUUIDFast(_PREHASH_FailureInfo, _PREHASH_TransactionID,
  5891. trans_id);
  5892. llwarns << "Blacklisted feature response:" << message
  5893. << " - Transaction id: " << trans_id << llendl;
  5894. }
  5895. // ------------------------------------------------------------
  5896. // Message system exception callbacks
  5897. // ------------------------------------------------------------
  5898. void invalid_message_callback(LLMessageSystem*, void*, EMessageException)
  5899. {
  5900. gAppViewerp->badNetworkHandler();
  5901. }
  5902. void LLOfferInfo::forceResponse(InventoryOfferResponse response)
  5903. {
  5904. LLNotification::Params params("UserGiveItem");
  5905. params.functor(boost::bind(&LLOfferInfo::inventoryOfferCallback, this,
  5906. _1, _2));
  5907. // NOTE: keep UserGiveItem options in sync !
  5908. // 0 = accept = IOR_ACCEPT, 1 = decline = IOR_DECLINE, 2 = mute = IOR_MUTE.
  5909. // For IOR_BUSY and IOR_MUTED, we pass "decline" to the UserGiveItem
  5910. // notification.
  5911. S32 option = response <= IOR_MUTE ? response : 1;
  5912. LL_DEBUGS("InventoryOffer") << "Forcing response: " << option << LL_ENDL;
  5913. gNotifications.forceResponse(params, option);
  5914. }
  5915. // Generic message (formerly in llviewergenericmessage.cpp)
  5916. void send_generic_message(const char* method,
  5917. const std::vector<std::string>& strings,
  5918. const LLUUID& invoice)
  5919. {
  5920. LLMessageSystem* msg = gMessageSystemp;
  5921. msg->newMessage(_PREHASH_GenericMessage);
  5922. msg->nextBlockFast(_PREHASH_AgentData);
  5923. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  5924. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  5925. msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); // Not used
  5926. msg->nextBlock(_PREHASH_MethodData);
  5927. msg->addString(_PREHASH_Method, method);
  5928. msg->addUUID(_PREHASH_Invoice, invoice);
  5929. if (strings.empty())
  5930. {
  5931. msg->nextBlock(_PREHASH_ParamList);
  5932. msg->addString(_PREHASH_Parameter, NULL);
  5933. }
  5934. else
  5935. {
  5936. for (std::vector<std::string>::const_iterator it = strings.begin(),
  5937. end = strings.end();
  5938. it != end; ++it)
  5939. {
  5940. msg->nextBlock(_PREHASH_ParamList);
  5941. msg->addString(_PREHASH_Parameter, *it);
  5942. }
  5943. }
  5944. gAgent.sendReliableMessage();
  5945. }
  5946. void process_generic_message(LLMessageSystem* msg, void**)
  5947. {
  5948. std::string method;
  5949. msg->getStringFast(_PREHASH_MethodData, _PREHASH_Method, method);
  5950. if (method == "Windlight")
  5951. {
  5952. gWLSkyParamMgr.processLightshareMessage(msg);
  5953. return;
  5954. }
  5955. else if (method == "WindlightReset")
  5956. {
  5957. gWLSkyParamMgr.processLightshareReset();
  5958. return;
  5959. }
  5960. LLUUID agent_id;
  5961. msg->getUUID(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  5962. if (agent_id != gAgentID)
  5963. {
  5964. llwarns << "GenericMessage for wrong agent" << llendl;
  5965. return;
  5966. }
  5967. std::string request;
  5968. LLUUID invoice;
  5969. LLDispatcher::sparam_t strings;
  5970. LLDispatcher::unpackMessage(msg, request, invoice, strings);
  5971. if (!gGenericDispatcher.dispatch(request, invoice, strings))
  5972. {
  5973. llwarns << "GenericMessage " << request << " failed to dispatch"
  5974. << llendl;
  5975. }
  5976. }
  5977. void process_generic_streaming_message(LLMessageSystem* msg, void**)
  5978. {
  5979. LLGenericStreamingMessage data;
  5980. data.unpack(msg);
  5981. if (data.mMethod ==
  5982. LLGenericStreamingMessage::METHOD_GLTF_MATERIAL_OVERRIDE)
  5983. {
  5984. gGLTFMaterialList.applyOverrideMessage(msg, data.mData);
  5985. }
  5986. else
  5987. {
  5988. llwarns_once << "Unknown generic streaming message method: "
  5989. << (S32)data.mMethod << llendl;
  5990. }
  5991. }
  5992. void process_large_generic_message(LLMessageSystem* msg, void**)
  5993. {
  5994. LLUUID agent_id;
  5995. msg->getUUID(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  5996. if (agent_id != gAgentID)
  5997. {
  5998. llwarns << "LargeGenericMessage for wrong agent" << llendl;
  5999. return;
  6000. }
  6001. std::string request;
  6002. LLUUID invoice;
  6003. LLDispatcher::sparam_t strings;
  6004. LLDispatcher::unpackLargeMessage(msg, request, invoice, strings);
  6005. if (!gGenericDispatcher.dispatch(request, invoice, strings))
  6006. {
  6007. llwarns << "LargeGenericMessage " << request << " failed to dispatch"
  6008. << llendl;
  6009. }
  6010. }