1
0

LLClientView.cs 616 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Net;
  30. using System.Reflection;
  31. using System.Runtime;
  32. using System.Text;
  33. using System.Threading;
  34. using log4net;
  35. using OpenMetaverse;
  36. using OpenMetaverse.Packets;
  37. using OpenMetaverse.Messages.Linden;
  38. using OpenMetaverse.StructuredData;
  39. using OpenSim.Framework;
  40. using OpenSim.Framework.Client;
  41. using OpenSim.Framework.Monitoring;
  42. using OpenSim.Region.Framework.Interfaces;
  43. using OpenSim.Region.Framework.Scenes;
  44. using OpenSim.Services.Interfaces;
  45. using AssetLandmark = OpenSim.Framework.AssetLandmark;
  46. using Caps = OpenSim.Framework.Capabilities.Caps;
  47. using PermissionMask = OpenSim.Framework.PermissionMask;
  48. using RegionFlags = OpenMetaverse.RegionFlags;
  49. namespace OpenSim.Region.ClientStack.LindenUDP
  50. {
  51. public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
  52. /// <summary>
  53. /// Handles new client connections
  54. /// Constructor takes a single Packet and authenticates everything
  55. /// </summary>
  56. public class LLClientView : IClientAPI, IClientCore, IClientIM, IClientChat, IClientInventory, IStatsCollector, IClientIPEndpoint
  57. {
  58. /// <value>
  59. /// Debug packet level. See OpenSim.RegisterConsoleCommands() for more details.
  60. /// </value>
  61. public int DebugPacketLevel { get; set; }
  62. #region Events
  63. public event BinaryGenericMessage OnBinaryGenericMessage;
  64. public event Action<IClientAPI> OnLogout;
  65. public event ObjectPermissions OnObjectPermissions;
  66. public event Action<IClientAPI> OnConnectionClosed;
  67. public event ViewerEffectEventHandler OnViewerEffect;
  68. public event ImprovedInstantMessage OnInstantMessage;
  69. public event ChatMessage OnChatFromClient;
  70. public event RezObject OnRezObject;
  71. public event DeRezObject OnDeRezObject;
  72. public event RezRestoreToWorld OnRezRestoreToWorld;
  73. public event ModifyTerrain OnModifyTerrain;
  74. public event Action<IClientAPI> OnRegionHandShakeReply;
  75. public event GenericCall1 OnRequestWearables;
  76. public event SetAppearance OnSetAppearance;
  77. public event AvatarNowWearing OnAvatarNowWearing;
  78. public event RezSingleAttachmentFromInv OnRezSingleAttachmentFromInv;
  79. public event RezMultipleAttachmentsFromInv OnRezMultipleAttachmentsFromInv;
  80. public event UUIDNameRequest OnDetachAttachmentIntoInv;
  81. public event ObjectAttach OnObjectAttach;
  82. public event ObjectDeselect OnObjectDetach;
  83. public event ObjectDrop OnObjectDrop;
  84. public event Action<IClientAPI, bool> OnCompleteMovementToRegion;
  85. public event UpdateAgent OnPreAgentUpdate;
  86. public event UpdateAgent OnAgentUpdate;
  87. public event UpdateAgent OnAgentCameraUpdate;
  88. public event AgentRequestSit OnAgentRequestSit;
  89. public event AgentSit OnAgentSit;
  90. public event AvatarPickerRequest OnAvatarPickerRequest;
  91. public event ChangeAnim OnChangeAnim;
  92. public event Action<IClientAPI> OnRequestAvatarsData;
  93. public event LinkObjects OnLinkObjects;
  94. public event DelinkObjects OnDelinkObjects;
  95. public event GrabObject OnGrabObject;
  96. public event DeGrabObject OnDeGrabObject;
  97. public event SpinStart OnSpinStart;
  98. public event SpinStop OnSpinStop;
  99. public event ObjectDuplicate OnObjectDuplicate;
  100. public event ObjectDuplicateOnRay OnObjectDuplicateOnRay;
  101. public event MoveObject OnGrabUpdate;
  102. public event SpinObject OnSpinUpdate;
  103. public event AddNewPrim OnAddPrim;
  104. public event RequestGodlikePowers OnRequestGodlikePowers;
  105. public event GodKickUser OnGodKickUser;
  106. public event ObjectExtraParams OnUpdateExtraParams;
  107. public event UpdateShape OnUpdatePrimShape;
  108. public event ObjectRequest OnObjectRequest;
  109. public event ObjectSelect OnObjectSelect;
  110. public event ObjectDeselect OnObjectDeselect;
  111. public event GenericCall7 OnObjectDescription;
  112. public event GenericCall7 OnObjectName;
  113. public event GenericCall7 OnObjectClickAction;
  114. public event GenericCall7 OnObjectMaterial;
  115. public event ObjectIncludeInSearch OnObjectIncludeInSearch;
  116. public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
  117. public event UpdatePrimFlags OnUpdatePrimFlags;
  118. public event UpdatePrimTexture OnUpdatePrimTexture;
  119. public event ClientChangeObject onClientChangeObject;
  120. public event UpdateVector OnUpdatePrimGroupPosition;
  121. public event UpdatePrimRotation OnUpdatePrimGroupRotation;
  122. public event UpdateVector OnUpdatePrimGroupScale;
  123. public event RequestMapBlocks OnRequestMapBlocks;
  124. public event RequestMapName OnMapNameRequest;
  125. public event TeleportLocationRequest OnTeleportLocationRequest;
  126. public event TeleportLandmarkRequest OnTeleportLandmarkRequest;
  127. public event TeleportCancel OnTeleportCancel;
  128. public event RequestAvatarProperties OnRequestAvatarProperties;
  129. public event SetAlwaysRun OnSetAlwaysRun;
  130. public event FetchInventory OnAgentDataUpdateRequest;
  131. public event TeleportLocationRequest OnSetStartLocationRequest;
  132. public event UpdateAvatarProperties OnUpdateAvatarProperties;
  133. public event CreateNewInventoryItem OnCreateNewInventoryItem;
  134. public event LinkInventoryItem OnLinkInventoryItem;
  135. public event CreateInventoryFolder OnCreateNewInventoryFolder;
  136. public event UpdateInventoryFolder OnUpdateInventoryFolder;
  137. public event MoveInventoryFolder OnMoveInventoryFolder;
  138. public event FetchInventoryDescendents OnFetchInventoryDescendents;
  139. public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
  140. public event FetchInventory OnFetchInventory;
  141. public event RequestTaskInventory OnRequestTaskInventory;
  142. public event UpdateInventoryItem OnUpdateInventoryItem;
  143. public event CopyInventoryItem OnCopyInventoryItem;
  144. public event MoveItemsAndLeaveCopy OnMoveItemsAndLeaveCopy;
  145. public event MoveInventoryItem OnMoveInventoryItem;
  146. public event RemoveInventoryItem OnRemoveInventoryItem;
  147. public event RemoveInventoryFolder OnRemoveInventoryFolder;
  148. public event UDPAssetUploadRequest OnAssetUploadRequest;
  149. public event XferReceive OnXferReceive;
  150. public event RequestXfer OnRequestXfer;
  151. public event ConfirmXfer OnConfirmXfer;
  152. public event AbortXfer OnAbortXfer;
  153. public event RequestTerrain OnRequestTerrain;
  154. public event RezScript OnRezScript;
  155. public event UpdateTaskInventory OnUpdateTaskInventory;
  156. public event MoveTaskInventory OnMoveTaskItem;
  157. public event RemoveTaskInventory OnRemoveTaskItem;
  158. public event UUIDNameRequest OnNameFromUUIDRequest;
  159. public event ParcelAccessListRequest OnParcelAccessListRequest;
  160. public event ParcelAccessListUpdateRequest OnParcelAccessListUpdateRequest;
  161. public event ParcelPropertiesRequest OnParcelPropertiesRequest;
  162. public event ParcelDivideRequest OnParcelDivideRequest;
  163. public event ParcelJoinRequest OnParcelJoinRequest;
  164. public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
  165. public event ParcelSelectObjects OnParcelSelectObjects;
  166. public event ParcelObjectOwnerRequest OnParcelObjectOwnerRequest;
  167. public event ParcelAbandonRequest OnParcelAbandonRequest;
  168. public event ParcelGodForceOwner OnParcelGodForceOwner;
  169. public event ParcelReclaim OnParcelReclaim;
  170. public event ParcelReturnObjectsRequest OnParcelReturnObjectsRequest;
  171. public event ParcelDeedToGroup OnParcelDeedToGroup;
  172. public event RegionInfoRequest OnRegionInfoRequest;
  173. public event EstateCovenantRequest OnEstateCovenantRequest;
  174. public event FriendActionDelegate OnApproveFriendRequest;
  175. public event FriendActionDelegate OnDenyFriendRequest;
  176. public event FriendshipTermination OnTerminateFriendship;
  177. public event GrantUserFriendRights OnGrantUserRights;
  178. public event MoneyTransferRequest OnMoneyTransferRequest;
  179. public event EconomyDataRequest OnEconomyDataRequest;
  180. public event MoneyBalanceRequest OnMoneyBalanceRequest;
  181. public event ParcelBuy OnParcelBuy;
  182. public event UUIDNameRequest OnTeleportHomeRequest;
  183. public event UUIDNameRequest OnUUIDGroupNameRequest;
  184. public event ScriptAnswer OnScriptAnswer;
  185. public event RequestPayPrice OnRequestPayPrice;
  186. public event ObjectSaleInfo OnObjectSaleInfo;
  187. public event ObjectBuy OnObjectBuy;
  188. public event AgentSit OnUndo;
  189. public event AgentSit OnRedo;
  190. public event LandUndo OnLandUndo;
  191. public event ForceReleaseControls OnForceReleaseControls;
  192. public event GodLandStatRequest OnLandStatRequest;
  193. public event RequestObjectPropertiesFamily OnObjectGroupRequest;
  194. public event DetailedEstateDataRequest OnDetailedEstateDataRequest;
  195. public event SetEstateFlagsRequest OnSetEstateFlagsRequest;
  196. public event SetEstateTerrainDetailTexture OnSetEstateTerrainDetailTexture;
  197. public event SetEstateTerrainTextureHeights OnSetEstateTerrainTextureHeights;
  198. public event CommitEstateTerrainTextureRequest OnCommitEstateTerrainTextureRequest;
  199. public event SetRegionTerrainSettings OnSetRegionTerrainSettings;
  200. public event BakeTerrain OnBakeTerrain;
  201. public event RequestTerrain OnUploadTerrain;
  202. public event EstateChangeInfo OnEstateChangeInfo;
  203. public event EstateManageTelehub OnEstateManageTelehub;
  204. public event EstateRestartSimRequest OnEstateRestartSimRequest;
  205. public event EstateChangeCovenantRequest OnEstateChangeCovenantRequest;
  206. public event UpdateEstateAccessDeltaRequest OnUpdateEstateAccessDeltaRequest;
  207. public event SimulatorBlueBoxMessageRequest OnSimulatorBlueBoxMessageRequest;
  208. public event EstateBlueBoxMessageRequest OnEstateBlueBoxMessageRequest;
  209. public event EstateDebugRegionRequest OnEstateDebugRegionRequest;
  210. public event EstateTeleportOneUserHomeRequest OnEstateTeleportOneUserHomeRequest;
  211. public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest;
  212. public event RegionHandleRequest OnRegionHandleRequest;
  213. public event ParcelInfoRequest OnParcelInfoRequest;
  214. public event ScriptReset OnScriptReset;
  215. public event GetScriptRunning OnGetScriptRunning;
  216. public event SetScriptRunning OnSetScriptRunning;
  217. public event Action<Vector3, bool, bool> OnAutoPilotGo;
  218. public event ActivateGesture OnActivateGesture;
  219. public event DeactivateGesture OnDeactivateGesture;
  220. public event ObjectOwner OnObjectOwner;
  221. public event DirPlacesQuery OnDirPlacesQuery;
  222. public event DirFindQuery OnDirFindQuery;
  223. public event DirLandQuery OnDirLandQuery;
  224. public event DirPopularQuery OnDirPopularQuery;
  225. public event DirClassifiedQuery OnDirClassifiedQuery;
  226. public event EventInfoRequest OnEventInfoRequest;
  227. public event ParcelSetOtherCleanTime OnParcelSetOtherCleanTime;
  228. public event MapItemRequest OnMapItemRequest;
  229. public event OfferCallingCard OnOfferCallingCard;
  230. public event AcceptCallingCard OnAcceptCallingCard;
  231. public event DeclineCallingCard OnDeclineCallingCard;
  232. public event SoundTrigger OnSoundTrigger;
  233. public event StartLure OnStartLure;
  234. public event TeleportLureRequest OnTeleportLureRequest;
  235. public event NetworkStats OnNetworkStatsUpdate;
  236. public event ClassifiedInfoRequest OnClassifiedInfoRequest;
  237. public event ClassifiedInfoUpdate OnClassifiedInfoUpdate;
  238. public event ClassifiedDelete OnClassifiedDelete;
  239. public event ClassifiedGodDelete OnClassifiedGodDelete;
  240. public event EventNotificationAddRequest OnEventNotificationAddRequest;
  241. public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest;
  242. public event EventGodDelete OnEventGodDelete;
  243. public event ParcelDwellRequest OnParcelDwellRequest;
  244. public event UserInfoRequest OnUserInfoRequest;
  245. public event UpdateUserInfo OnUpdateUserInfo;
  246. public event RetrieveInstantMessages OnRetrieveInstantMessages;
  247. public event PickDelete OnPickDelete;
  248. public event PickGodDelete OnPickGodDelete;
  249. public event PickInfoUpdate OnPickInfoUpdate;
  250. public event AvatarNotesUpdate OnAvatarNotesUpdate;
  251. public event MuteListRequest OnMuteListRequest;
  252. public event AvatarInterestUpdate OnAvatarInterestUpdate;
  253. public event PlacesQuery OnPlacesQuery;
  254. public event AgentFOV OnAgentFOV;
  255. public event FindAgentUpdate OnFindAgent;
  256. public event TrackAgentUpdate OnTrackAgent;
  257. public event NewUserReport OnUserReport;
  258. public event SaveStateHandler OnSaveState;
  259. public event GroupAccountSummaryRequest OnGroupAccountSummaryRequest;
  260. public event GroupAccountDetailsRequest OnGroupAccountDetailsRequest;
  261. public event GroupAccountTransactionsRequest OnGroupAccountTransactionsRequest;
  262. public event FreezeUserUpdate OnParcelFreezeUser;
  263. public event EjectUserUpdate OnParcelEjectUser;
  264. public event ParcelBuyPass OnParcelBuyPass;
  265. public event ParcelGodMark OnParcelGodMark;
  266. public event GroupActiveProposalsRequest OnGroupActiveProposalsRequest;
  267. public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest;
  268. public event SimWideDeletesDelegate OnSimWideDeletes;
  269. public event SendPostcard OnSendPostcard;
  270. public event ChangeInventoryItemFlags OnChangeInventoryItemFlags;
  271. public event MuteListEntryUpdate OnUpdateMuteListEntry;
  272. public event MuteListEntryRemove OnRemoveMuteListEntry;
  273. public event GodlikeMessage onGodlikeMessage;
  274. public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate;
  275. public event GenericCall2 OnUpdateThrottles;
  276. #pragma warning disable 0067
  277. // still unused
  278. public event GenericMessage OnGenericMessage;
  279. public event TextureRequest OnRequestTexture;
  280. public event StatusChange OnChildAgentStatus;
  281. public event GenericCall2 OnStopMovement;
  282. public event Action<UUID> OnRemoveAvatar;
  283. public event DisconnectUser OnDisconnectUser;
  284. public event RequestAsset OnRequestAsset;
  285. public event BuyObjectInventory OnBuyObjectInventory;
  286. public event SetEstateTerrainBaseTexture OnSetEstateTerrainBaseTexture;
  287. public event TerrainUnacked OnUnackedTerrain;
  288. public event CachedTextureRequest OnCachedTextureRequest;
  289. public event UpdateVector OnUpdatePrimSinglePosition;
  290. public event StartAnim OnStartAnim;
  291. public event StopAnim OnStopAnim;
  292. public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
  293. public event UpdatePrimSingleRotationPosition OnUpdatePrimSingleRotationPosition;
  294. public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
  295. public event UpdateVector OnUpdatePrimScale;
  296. #pragma warning restore 0067
  297. #endregion Events
  298. #region Class Members
  299. // LLClientView Only
  300. public delegate void BinaryGenericMessage(Object sender, string method, byte[][] args);
  301. /// <summary>Used to adjust Sun Orbit values so Linden based viewers properly position sun</summary>
  302. private const float m_sunPainDaHalfOrbitalCutoff = 4.712388980384689858f;
  303. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  304. private static string LogHeader = "[LLCLIENTVIEW]";
  305. /// <summary>
  306. /// Handles UDP texture download.
  307. /// </summary>
  308. public LLImageManager ImageManager { get; private set; }
  309. public JobEngine m_asyncPacketProcess;
  310. private readonly LLUDPServer m_udpServer;
  311. private readonly LLUDPClient m_udpClient;
  312. private readonly UUID m_sessionId;
  313. private readonly UUID m_secureSessionId;
  314. protected readonly UUID m_agentId;
  315. private readonly uint m_circuitCode;
  316. private readonly byte[] m_channelVersion = Utils.EmptyBytes;
  317. private readonly IGroupsModule m_GroupsModule;
  318. // private int m_cachedTextureSerial;
  319. private PriorityQueue m_entityUpdates;
  320. private PriorityQueue m_entityProps;
  321. private Prioritizer m_prioritizer;
  322. private bool m_disableFacelights;
  323. // needs optimization
  324. private HashSet<SceneObjectGroup> GroupsInView = new HashSet<SceneObjectGroup>();
  325. #pragma warning disable 0414
  326. private bool m_VelocityInterpolate;
  327. #pragma warning restore 0414
  328. private const uint MaxTransferBytesPerPacket = 600;
  329. private bool m_SupportObjectAnimations;
  330. /// <value>
  331. /// Maintain a record of all the objects killed. This allows us to stop an update being sent from the
  332. /// thread servicing the m_primFullUpdates queue after a kill. If this happens the object persists as an
  333. /// ownerless phantom.
  334. ///
  335. /// All manipulation of this set has to occur under an m_entityUpdates.SyncRoot lock
  336. ///
  337. /// </value>
  338. protected List<uint> m_killRecord;
  339. // protected HashSet<uint> m_attachmentsSent;
  340. private bool m_deliverPackets = true;
  341. private bool m_SendLogoutPacketWhenClosing = true;
  342. /// <summary>
  343. /// We retain a single AgentUpdateArgs so that we can constantly reuse it rather than construct a new one for
  344. /// every single incoming AgentUpdate. Every client sends 10 AgentUpdate UDP messages per second, even if it
  345. /// is doing absolutely nothing.
  346. /// </summary>
  347. /// <remarks>
  348. /// This does mean that agent updates must be processed synchronously, at least for each client, and called methods
  349. /// cannot retain a reference to it outside of that method.
  350. /// </remarks>
  351. private AgentUpdateArgs m_thisAgentUpdateArgs = new AgentUpdateArgs();
  352. protected Dictionary<PacketType, PacketProcessor> m_packetHandlers = new Dictionary<PacketType, PacketProcessor>();
  353. protected Dictionary<string, GenericMessage> m_genericPacketHandlers = new Dictionary<string, GenericMessage>(); //PauPaw:Local Generic Message handlers
  354. protected Scene m_scene;
  355. protected string m_firstName;
  356. protected string m_lastName;
  357. protected Vector3 m_startpos;
  358. protected UUID m_activeGroupID;
  359. protected string m_activeGroupName = String.Empty;
  360. protected ulong m_activeGroupPowers;
  361. protected Dictionary<UUID, ulong> m_groupPowers = new Dictionary<UUID, ulong>();
  362. protected int m_terrainCheckerCount;
  363. protected uint m_agentFOVCounter;
  364. protected IAssetService m_assetService;
  365. #endregion Class Members
  366. #region Properties
  367. public LLUDPClient UDPClient { get { return m_udpClient; } }
  368. public LLUDPServer UDPServer { get { return m_udpServer; } }
  369. public IPEndPoint RemoteEndPoint { get { return m_udpClient.RemoteEndPoint; } }
  370. public UUID SecureSessionId { get { return m_secureSessionId; } }
  371. public IScene Scene { get { return m_scene; } }
  372. public UUID SessionId { get { return m_sessionId; } }
  373. public Vector3 StartPos
  374. {
  375. get { return m_startpos; }
  376. set { m_startpos = value; }
  377. }
  378. public bool DeliverPackets
  379. {
  380. get { return m_deliverPackets; }
  381. set {
  382. m_deliverPackets = value;
  383. m_udpClient.m_deliverPackets = value;
  384. }
  385. }
  386. public UUID AgentId { get { return m_agentId; } }
  387. public ISceneAgent SceneAgent { get; set; }
  388. public UUID ActiveGroupId { get { return m_activeGroupID; } set { m_activeGroupID = value; } }
  389. public string ActiveGroupName { get { return m_activeGroupName; } set { m_activeGroupName = value; } }
  390. public ulong ActiveGroupPowers { get { return m_activeGroupPowers; } set { m_activeGroupPowers = value; } }
  391. public bool IsGroupMember(UUID groupID) { return m_groupPowers.ContainsKey(groupID); }
  392. public int PingTimeMS
  393. {
  394. get
  395. {
  396. if (UDPClient != null)
  397. return UDPClient.PingTimeMS;
  398. return 0;
  399. }
  400. }
  401. /// <summary>
  402. /// Entity update queues
  403. /// </summary>
  404. public PriorityQueue EntityUpdateQueue { get { return m_entityUpdates; } }
  405. /// <summary>
  406. /// First name of the agent/avatar represented by the client
  407. /// </summary>
  408. public string FirstName { get { return m_firstName; } }
  409. /// <summary>
  410. /// Last name of the agent/avatar represented by the client
  411. /// </summary>
  412. public string LastName { get { return m_lastName; } }
  413. /// <summary>
  414. /// Full name of the client (first name and last name)
  415. /// </summary>
  416. public string Name { get { return FirstName + " " + LastName; } }
  417. public uint CircuitCode { get { return m_circuitCode; } }
  418. protected int m_animationSequenceNumber = (int)(Util.GetTimeStampTicks() & 0x5fffafL);
  419. public int NextAnimationSequenceNumber
  420. {
  421. get
  422. {
  423. int ret = Interlocked.Increment(ref m_animationSequenceNumber);
  424. if (ret <= 0)
  425. {
  426. m_animationSequenceNumber = (int)(Util.GetTimeStampTicks() & 0xafff5fL);
  427. ret = Interlocked.Increment(ref m_animationSequenceNumber);
  428. }
  429. return ret;
  430. }
  431. set
  432. {
  433. m_animationSequenceNumber = value;
  434. }
  435. }
  436. /// <summary>
  437. /// As well as it's function in IClientAPI, in LLClientView we are locking on this property in order to
  438. /// prevent race conditions by different threads calling Close().
  439. /// </summary>
  440. public bool IsActive { get; set; }
  441. /// <summary>
  442. /// Used to synchronise threads when client is being closed.
  443. /// </summary>
  444. public Object CloseSyncLock { get; private set; }
  445. public bool IsLoggingOut { get; set; }
  446. public bool DisableFacelights
  447. {
  448. get { return m_disableFacelights; }
  449. set { m_disableFacelights = value; }
  450. }
  451. public List<uint> SelectedObjects {get; private set;}
  452. public bool SendLogoutPacketWhenClosing { set { m_SendLogoutPacketWhenClosing = value; } }
  453. #endregion Properties
  454. // ~LLClientView()
  455. // {
  456. // m_log.DebugFormat("{0} Destructor called for {1}, circuit code {2}", LogHeader, Name, CircuitCode);
  457. // }
  458. /// <summary>
  459. /// Constructor
  460. /// </summary>
  461. public LLClientView(Scene scene, LLUDPServer udpServer, LLUDPClient udpClient, AuthenticateResponse sessionInfo,
  462. UUID agentId, UUID sessionId, uint circuitCode)
  463. {
  464. // DebugPacketLevel = 1;
  465. CloseSyncLock = new Object();
  466. SelectedObjects = new List<uint>();
  467. RegisterInterface<IClientIM>(this);
  468. RegisterInterface<IClientInventory>(this);
  469. RegisterInterface<IClientChat>(this);
  470. m_scene = scene;
  471. int pcap = 512;
  472. if(pcap > m_scene.Entities.Count)
  473. pcap = m_scene.Entities.Count;
  474. m_entityUpdates = new PriorityQueue(pcap);
  475. m_entityProps = new PriorityQueue(pcap);
  476. m_killRecord = new List<uint>();
  477. // m_attachmentsSent = new HashSet<uint>();
  478. m_assetService = m_scene.RequestModuleInterface<IAssetService>();
  479. m_GroupsModule = scene.RequestModuleInterface<IGroupsModule>();
  480. ImageManager = new LLImageManager(this, m_assetService, Scene.RequestModuleInterface<IJ2KDecoder>());
  481. m_channelVersion = Util.StringToBytes256(scene.GetSimulatorVersion());
  482. m_agentId = agentId;
  483. m_sessionId = sessionId;
  484. m_secureSessionId = sessionInfo.LoginInfo.SecureSession;
  485. m_circuitCode = circuitCode;
  486. m_firstName = sessionInfo.LoginInfo.First;
  487. m_lastName = sessionInfo.LoginInfo.Last;
  488. m_startpos = sessionInfo.LoginInfo.StartPos;
  489. m_udpServer = udpServer;
  490. m_udpClient = udpClient;
  491. m_udpClient.OnQueueEmpty += HandleQueueEmpty;
  492. m_udpClient.HasUpdates += HandleHasUpdates;
  493. m_udpClient.OnPacketStats += PopulateStats;
  494. m_prioritizer = new Prioritizer(m_scene);
  495. RegisterLocalPacketHandlers();
  496. string name = string.Format("AsyncInUDP-{0}",m_agentId.ToString());
  497. m_asyncPacketProcess = new JobEngine(name, name, 10000);
  498. IsActive = true;
  499. }
  500. #region Client Methods
  501. /// <summary>
  502. /// Close down the client view
  503. /// </summary>
  504. public void Close()
  505. {
  506. Close(true, false);
  507. }
  508. public void Close(bool sendStop, bool force)
  509. {
  510. // We lock here to prevent race conditions between two threads calling close simultaneously (e.g.
  511. // a simultaneous relog just as a client is being closed out due to no packet ack from the old connection.
  512. lock (CloseSyncLock)
  513. {
  514. // We still perform a force close inside the sync lock since this is intended to attempt close where
  515. // there is some unidentified connection problem, not where we have issues due to deadlock
  516. if (!IsActive && !force)
  517. {
  518. m_log.DebugFormat( "{0} Not attempting to close inactive client {1} in {2} since force flag is not set",
  519. LogHeader, Name, m_scene.Name);
  520. return;
  521. }
  522. IsActive = false;
  523. CloseWithoutChecks(sendStop);
  524. }
  525. }
  526. /// <summary>
  527. /// Closes down the client view without first checking whether it is active.
  528. /// </summary>
  529. /// <remarks>
  530. /// This exists because LLUDPServer has to set IsActive = false in earlier synchronous code before calling
  531. /// CloseWithoutIsActiveCheck asynchronously.
  532. ///
  533. /// Callers must lock ClosingSyncLock before calling.
  534. /// </remarks>
  535. public void CloseWithoutChecks(bool sendStop)
  536. {
  537. m_log.DebugFormat(
  538. "[CLIENT]: Close has been called for {0} attached to scene {1}",
  539. Name, m_scene.RegionInfo.RegionName);
  540. if (sendStop)
  541. {
  542. // Send the STOP packet
  543. DisableSimulatorPacket disable = (DisableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
  544. OutPacket(disable, ThrottleOutPacketType.Unknown);
  545. }
  546. // Fire the callback for this connection closing
  547. if (OnConnectionClosed != null)
  548. OnConnectionClosed(this);
  549. m_asyncPacketProcess.Stop();
  550. // Flush all of the packets out of the UDP server for this client
  551. if (m_udpServer != null)
  552. m_udpServer.Flush(m_udpClient);
  553. // Remove ourselves from the scene
  554. m_scene.RemoveClient(AgentId, true);
  555. SceneAgent = null;
  556. // We can't reach into other scenes and close the connection
  557. // We need to do this over grid communications
  558. //m_scene.CloseAllAgents(CircuitCode);
  559. // Disable UDP handling for this client
  560. m_udpClient.OnQueueEmpty -= HandleQueueEmpty;
  561. m_udpClient.HasUpdates -= HandleHasUpdates;
  562. m_udpClient.OnPacketStats -= PopulateStats;
  563. m_udpClient.Shutdown();
  564. // Shutdown the image manager
  565. ImageManager.Close();
  566. ImageManager = null;
  567. m_entityUpdates.Close();
  568. m_entityProps.Close();
  569. m_killRecord.Clear();
  570. GroupsInView.Clear();
  571. if(m_scene.GetNumberOfClients() == 0)
  572. {
  573. GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
  574. GC.Collect();
  575. GC.WaitForPendingFinalizers();
  576. GC.Collect();
  577. GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.Default;
  578. }
  579. }
  580. public void Kick(string message)
  581. {
  582. if (!SceneAgent.IsChildAgent)
  583. {
  584. KickUserPacket kupack = (KickUserPacket)PacketPool.Instance.GetPacket(PacketType.KickUser);
  585. kupack.UserInfo.AgentID = AgentId;
  586. kupack.UserInfo.SessionID = SessionId;
  587. kupack.TargetBlock.TargetIP = 0;
  588. kupack.TargetBlock.TargetPort = 0;
  589. kupack.UserInfo.Reason = Util.StringToBytes256(message);
  590. OutPacket(kupack, ThrottleOutPacketType.Task);
  591. // You must sleep here or users get no message!
  592. Thread.Sleep(500);
  593. }
  594. }
  595. public void Stop()
  596. {
  597. }
  598. #endregion Client Methods
  599. #region Packet Handling
  600. public void PopulateStats(int inPackets, int outPackets, int unAckedBytes)
  601. {
  602. NetworkStats handlerNetworkStatsUpdate = OnNetworkStatsUpdate;
  603. if (handlerNetworkStatsUpdate != null)
  604. {
  605. handlerNetworkStatsUpdate(inPackets, outPackets, unAckedBytes);
  606. }
  607. }
  608. /// <summary>
  609. /// Add a handler for the given packet type.
  610. /// </summary>
  611. /// <remarks>
  612. /// The packet is handled on its own thread. If packets must be handled in the order in which they
  613. /// are received then please use the synchronous version of this method.
  614. /// </remarks>
  615. /// <param name="packetType"></param>
  616. /// <param name="handler"></param>
  617. /// <returns>true if the handler was added. This is currently always the case.</returns>
  618. public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
  619. {
  620. return AddLocalPacketHandler(packetType, handler, true);
  621. }
  622. /// <summary>
  623. /// Add a handler for the given packet type.
  624. /// </summary>
  625. /// <param name="packetType"></param>
  626. /// <param name="handler"></param>
  627. /// <param name="doAsync">
  628. /// If true, when the packet is received it is handled on its own thread rather than on the main inward bound
  629. /// packet handler thread. This vastly increases respnosiveness but some packets need to be handled
  630. /// synchronously.
  631. /// </param>
  632. /// <returns>true if the handler was added. This is currently always the case.</returns>
  633. public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler, bool doAsync)
  634. {
  635. bool result = false;
  636. lock (m_packetHandlers)
  637. {
  638. if (!m_packetHandlers.ContainsKey(packetType))
  639. {
  640. m_packetHandlers.Add(
  641. packetType, new PacketProcessor() { method = handler, Async = doAsync});
  642. result = true;
  643. }
  644. }
  645. return result;
  646. }
  647. public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)
  648. {
  649. MethodName = MethodName.ToLower().Trim();
  650. bool result = false;
  651. lock (m_genericPacketHandlers)
  652. {
  653. if (!m_genericPacketHandlers.ContainsKey(MethodName))
  654. {
  655. m_genericPacketHandlers.Add(MethodName, handler);
  656. result = true;
  657. }
  658. }
  659. return result;
  660. }
  661. /// <summary>
  662. /// Try to process a packet using registered packet handlers
  663. /// </summary>
  664. /// <param name="packet"></param>
  665. /// <returns>True if a handler was found which successfully processed the packet.</returns>
  666. protected bool ProcessPacketMethod(Packet packet)
  667. {
  668. bool result = false;
  669. PacketProcessor pprocessor;
  670. if (m_packetHandlers.TryGetValue(packet.Type, out pprocessor))
  671. {
  672. //there is a local handler for this packet type
  673. if (pprocessor.Async)
  674. {
  675. object obj = new AsyncPacketProcess(this, pprocessor.method, packet);
  676. m_asyncPacketProcess.QueueJob(packet.Type.ToString(), () => ProcessSpecificPacketAsync(obj));
  677. result = true;
  678. }
  679. else
  680. {
  681. result = pprocessor.method(this, packet);
  682. }
  683. }
  684. return result;
  685. }
  686. public void ProcessSpecificPacketAsync(object state)
  687. {
  688. AsyncPacketProcess packetObject = (AsyncPacketProcess)state;
  689. try
  690. {
  691. packetObject.result = packetObject.Method(packetObject.ClientView, packetObject.Pack);
  692. }
  693. catch (Exception e)
  694. {
  695. // Make sure that we see any exception caused by the asynchronous operation.
  696. m_log.Error(
  697. string.Format(
  698. "[LLCLIENTVIEW]: Caught exception while processing {0} for {1} ", packetObject.Pack, Name),
  699. e);
  700. }
  701. }
  702. #endregion Packet Handling
  703. # region Setup
  704. public virtual void Start()
  705. {
  706. m_asyncPacketProcess.Start();
  707. m_scene.AddNewAgent(this, PresenceType.User);
  708. // RefreshGroupMembership();
  709. }
  710. # endregion
  711. public void ActivateGesture(UUID assetId, UUID gestureId)
  712. {
  713. }
  714. public void DeactivateGesture(UUID assetId, UUID gestureId)
  715. {
  716. }
  717. // Sound
  718. public void SoundTrigger(UUID soundId, UUID owerid, UUID Objectid, UUID ParentId, float Gain, Vector3 Position, UInt64 Handle)
  719. {
  720. }
  721. #region Scene/Avatar to Client
  722. public void SendRegionHandshake(RegionInfo regionInfo, RegionHandshakeArgs args)
  723. {
  724. RegionHandshakePacket handshake = (RegionHandshakePacket)PacketPool.Instance.GetPacket(PacketType.RegionHandshake);
  725. handshake.RegionInfo = new RegionHandshakePacket.RegionInfoBlock();
  726. handshake.RegionInfo.BillableFactor = args.billableFactor;
  727. handshake.RegionInfo.IsEstateManager = args.isEstateManager;
  728. handshake.RegionInfo.TerrainHeightRange00 = args.terrainHeightRange0;
  729. handshake.RegionInfo.TerrainHeightRange01 = args.terrainHeightRange1;
  730. handshake.RegionInfo.TerrainHeightRange10 = args.terrainHeightRange2;
  731. handshake.RegionInfo.TerrainHeightRange11 = args.terrainHeightRange3;
  732. handshake.RegionInfo.TerrainStartHeight00 = args.terrainStartHeight0;
  733. handshake.RegionInfo.TerrainStartHeight01 = args.terrainStartHeight1;
  734. handshake.RegionInfo.TerrainStartHeight10 = args.terrainStartHeight2;
  735. handshake.RegionInfo.TerrainStartHeight11 = args.terrainStartHeight3;
  736. handshake.RegionInfo.SimAccess = args.simAccess;
  737. handshake.RegionInfo.WaterHeight = args.waterHeight;
  738. handshake.RegionInfo.RegionFlags = args.regionFlags;
  739. handshake.RegionInfo.SimName = Util.StringToBytes256(args.regionName);
  740. handshake.RegionInfo.SimOwner = args.SimOwner;
  741. handshake.RegionInfo.TerrainBase0 = args.terrainBase0;
  742. handshake.RegionInfo.TerrainBase1 = args.terrainBase1;
  743. handshake.RegionInfo.TerrainBase2 = args.terrainBase2;
  744. handshake.RegionInfo.TerrainBase3 = args.terrainBase3;
  745. handshake.RegionInfo.TerrainDetail0 = args.terrainDetail0;
  746. handshake.RegionInfo.TerrainDetail1 = args.terrainDetail1;
  747. handshake.RegionInfo.TerrainDetail2 = args.terrainDetail2;
  748. handshake.RegionInfo.TerrainDetail3 = args.terrainDetail3;
  749. handshake.RegionInfo.CacheID = UUID.Random(); //I guess this is for the client to remember an old setting?
  750. handshake.RegionInfo2 = new RegionHandshakePacket.RegionInfo2Block();
  751. handshake.RegionInfo2.RegionID = regionInfo.RegionID;
  752. handshake.RegionInfo3 = new RegionHandshakePacket.RegionInfo3Block();
  753. handshake.RegionInfo3.CPUClassID = 9;
  754. handshake.RegionInfo3.CPURatio = 1;
  755. handshake.RegionInfo3.ColoName = Utils.EmptyBytes;
  756. handshake.RegionInfo3.ProductName = Util.StringToBytes256(regionInfo.RegionType);
  757. handshake.RegionInfo3.ProductSKU = Utils.EmptyBytes;
  758. handshake.RegionInfo4 = new RegionHandshakePacket.RegionInfo4Block[1];
  759. handshake.RegionInfo4[0] = new RegionHandshakePacket.RegionInfo4Block();
  760. handshake.RegionInfo4[0].RegionFlagsExtended = args.regionFlags;
  761. handshake.RegionInfo4[0].RegionProtocols = 0; // 1 here would indicate that SSB is supported
  762. OutPacket(handshake, ThrottleOutPacketType.Unknown);
  763. }
  764. public void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look)
  765. {
  766. m_thisAgentUpdateArgs.CameraAtAxis.X = float.MinValue;
  767. m_thisAgentUpdateArgs.lastUpdateTS = 0;
  768. m_thisAgentUpdateArgs.ControlFlags = 0;
  769. AgentMovementCompletePacket mov = (AgentMovementCompletePacket)PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete);
  770. mov.SimData.ChannelVersion = m_channelVersion;
  771. mov.AgentData.SessionID = m_sessionId;
  772. mov.AgentData.AgentID = AgentId;
  773. mov.Data.RegionHandle = regInfo.RegionHandle;
  774. mov.Data.Timestamp = (uint)Util.UnixTimeSinceEpoch();
  775. if ((pos.X == 0) && (pos.Y == 0) && (pos.Z == 0))
  776. {
  777. mov.Data.Position = m_startpos;
  778. }
  779. else
  780. {
  781. mov.Data.Position = pos;
  782. }
  783. mov.Data.LookAt = look;
  784. // Hack to get this out immediately and skip the throttles
  785. OutPacket(mov, ThrottleOutPacketType.Unknown);
  786. }
  787. public void SendChatMessage(
  788. string message, byte type, Vector3 fromPos, string fromName,
  789. UUID fromAgentID, UUID ownerID, byte source, byte audible)
  790. {
  791. ChatFromSimulatorPacket reply = (ChatFromSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.ChatFromSimulator);
  792. reply.ChatData.Audible = audible;
  793. reply.ChatData.Message = Util.StringToBytes1024(message);
  794. reply.ChatData.ChatType = type;
  795. reply.ChatData.SourceType = source;
  796. reply.ChatData.Position = fromPos;
  797. reply.ChatData.FromName = Util.StringToBytes256(fromName);
  798. reply.ChatData.OwnerID = ownerID;
  799. reply.ChatData.SourceID = fromAgentID;
  800. OutPacket(reply, ThrottleOutPacketType.Unknown);
  801. }
  802. /// <summary>
  803. /// Send an instant message to this client
  804. /// </summary>
  805. //
  806. public void SendInstantMessage(GridInstantMessage im)
  807. {
  808. if (((Scene)(m_scene)).Permissions.CanInstantMessage(new UUID(im.fromAgentID), new UUID(im.toAgentID)))
  809. {
  810. ImprovedInstantMessagePacket msg
  811. = (ImprovedInstantMessagePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedInstantMessage);
  812. msg.AgentData.AgentID = new UUID(im.fromAgentID);
  813. msg.AgentData.SessionID = UUID.Zero;
  814. msg.MessageBlock.FromAgentName = Util.StringToBytes256(im.fromAgentName);
  815. msg.MessageBlock.Dialog = im.dialog;
  816. msg.MessageBlock.FromGroup = im.fromGroup;
  817. // this is odd
  818. if (im.imSessionID == UUID.Zero.Guid)
  819. msg.MessageBlock.ID = new UUID(im.fromAgentID) ^ new UUID(im.toAgentID);
  820. else
  821. msg.MessageBlock.ID = new UUID(im.imSessionID);
  822. msg.MessageBlock.Offline = im.offline;
  823. msg.MessageBlock.ParentEstateID = im.ParentEstateID;
  824. msg.MessageBlock.Position = im.Position;
  825. msg.MessageBlock.RegionID = new UUID(im.RegionID);
  826. msg.MessageBlock.Timestamp = im.timestamp;
  827. msg.MessageBlock.ToAgentID = new UUID(im.toAgentID);
  828. msg.MessageBlock.Message = Util.StringToBytes1024(im.message);
  829. msg.MessageBlock.BinaryBucket = im.binaryBucket;
  830. OutPacket(msg, ThrottleOutPacketType.Task);
  831. }
  832. }
  833. public void SendGenericMessage(string method, UUID invoice, List<string> message)
  834. {
  835. GenericMessagePacket gmp = new GenericMessagePacket();
  836. gmp.AgentData.AgentID = AgentId;
  837. gmp.AgentData.SessionID = m_sessionId;
  838. gmp.AgentData.TransactionID = invoice;
  839. gmp.MethodData.Method = Util.StringToBytes256(method);
  840. gmp.ParamList = new GenericMessagePacket.ParamListBlock[message.Count];
  841. int i = 0;
  842. foreach (string val in message)
  843. {
  844. gmp.ParamList[i] = new GenericMessagePacket.ParamListBlock();
  845. gmp.ParamList[i++].Parameter = Util.StringToBytes256(val);
  846. }
  847. OutPacket(gmp, ThrottleOutPacketType.Task);
  848. }
  849. public void SendGenericMessage(string method, UUID invoice, List<byte[]> message)
  850. {
  851. GenericMessagePacket gmp = new GenericMessagePacket();
  852. gmp.AgentData.AgentID = AgentId;
  853. gmp.AgentData.SessionID = m_sessionId;
  854. gmp.AgentData.TransactionID = invoice;
  855. gmp.MethodData.Method = Util.StringToBytes256(method);
  856. gmp.ParamList = new GenericMessagePacket.ParamListBlock[message.Count];
  857. int i = 0;
  858. foreach (byte[] val in message)
  859. {
  860. gmp.ParamList[i] = new GenericMessagePacket.ParamListBlock();
  861. gmp.ParamList[i++].Parameter = val;
  862. }
  863. OutPacket(gmp, ThrottleOutPacketType.Task);
  864. }
  865. public void SendGroupActiveProposals(UUID groupID, UUID transactionID, GroupActiveProposals[] Proposals)
  866. {
  867. int i = 0;
  868. foreach (GroupActiveProposals Proposal in Proposals)
  869. {
  870. GroupActiveProposalItemReplyPacket GAPIRP = new GroupActiveProposalItemReplyPacket();
  871. GAPIRP.AgentData.AgentID = AgentId;
  872. GAPIRP.AgentData.GroupID = groupID;
  873. GAPIRP.TransactionData.TransactionID = transactionID;
  874. GAPIRP.TransactionData.TotalNumItems = ((uint)i+1);
  875. GroupActiveProposalItemReplyPacket.ProposalDataBlock ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock();
  876. GAPIRP.ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock[1];
  877. ProposalData.VoteCast = Utils.StringToBytes("false");
  878. ProposalData.VoteID = new UUID(Proposal.VoteID);
  879. ProposalData.VoteInitiator = new UUID(Proposal.VoteInitiator);
  880. ProposalData.Majority = (float)Convert.ToInt32(Proposal.Majority);
  881. ProposalData.Quorum = Convert.ToInt32(Proposal.Quorum);
  882. ProposalData.TerseDateID = Utils.StringToBytes(Proposal.TerseDateID);
  883. ProposalData.StartDateTime = Utils.StringToBytes(Proposal.StartDateTime);
  884. ProposalData.EndDateTime = Utils.StringToBytes(Proposal.EndDateTime);
  885. ProposalData.ProposalText = Utils.StringToBytes(Proposal.ProposalText);
  886. ProposalData.AlreadyVoted = false;
  887. GAPIRP.ProposalData[i] = ProposalData;
  888. OutPacket(GAPIRP, ThrottleOutPacketType.Task);
  889. i++;
  890. }
  891. if (Proposals.Length == 0)
  892. {
  893. GroupActiveProposalItemReplyPacket GAPIRP = new GroupActiveProposalItemReplyPacket();
  894. GAPIRP.AgentData.AgentID = AgentId;
  895. GAPIRP.AgentData.GroupID = groupID;
  896. GAPIRP.TransactionData.TransactionID = transactionID;
  897. GAPIRP.TransactionData.TotalNumItems = 1;
  898. GroupActiveProposalItemReplyPacket.ProposalDataBlock ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock();
  899. GAPIRP.ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock[1];
  900. ProposalData.VoteCast = Utils.StringToBytes("false");
  901. ProposalData.VoteID = UUID.Zero;
  902. ProposalData.VoteInitiator = UUID.Zero;
  903. ProposalData.Majority = 0;
  904. ProposalData.Quorum = 0;
  905. ProposalData.TerseDateID = Utils.StringToBytes("");
  906. ProposalData.StartDateTime = Utils.StringToBytes("");
  907. ProposalData.EndDateTime = Utils.StringToBytes("");
  908. ProposalData.ProposalText = Utils.StringToBytes("");
  909. ProposalData.AlreadyVoted = false;
  910. GAPIRP.ProposalData[0] = ProposalData;
  911. OutPacket(GAPIRP, ThrottleOutPacketType.Task);
  912. }
  913. }
  914. public void SendGroupVoteHistory(UUID groupID, UUID transactionID, GroupVoteHistory[] Votes)
  915. {
  916. int i = 0;
  917. foreach (GroupVoteHistory Vote in Votes)
  918. {
  919. GroupVoteHistoryItemReplyPacket GVHIRP = new GroupVoteHistoryItemReplyPacket();
  920. GVHIRP.AgentData.AgentID = AgentId;
  921. GVHIRP.AgentData.GroupID = groupID;
  922. GVHIRP.TransactionData.TransactionID = transactionID;
  923. GVHIRP.TransactionData.TotalNumItems = ((uint)i+1);
  924. GVHIRP.HistoryItemData.VoteID = new UUID(Vote.VoteID);
  925. GVHIRP.HistoryItemData.VoteInitiator = new UUID(Vote.VoteInitiator);
  926. GVHIRP.HistoryItemData.Majority = (float)Convert.ToInt32(Vote.Majority);
  927. GVHIRP.HistoryItemData.Quorum = Convert.ToInt32(Vote.Quorum);
  928. GVHIRP.HistoryItemData.TerseDateID = Utils.StringToBytes(Vote.TerseDateID);
  929. GVHIRP.HistoryItemData.StartDateTime = Utils.StringToBytes(Vote.StartDateTime);
  930. GVHIRP.HistoryItemData.EndDateTime = Utils.StringToBytes(Vote.EndDateTime);
  931. GVHIRP.HistoryItemData.VoteType = Utils.StringToBytes(Vote.VoteType);
  932. GVHIRP.HistoryItemData.VoteResult = Utils.StringToBytes(Vote.VoteResult);
  933. GVHIRP.HistoryItemData.ProposalText = Utils.StringToBytes(Vote.ProposalText);
  934. GroupVoteHistoryItemReplyPacket.VoteItemBlock VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock();
  935. GVHIRP.VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock[1];
  936. VoteItem.CandidateID = UUID.Zero;
  937. VoteItem.NumVotes = 0; //TODO: FIX THIS!!!
  938. VoteItem.VoteCast = Utils.StringToBytes("Yes");
  939. GVHIRP.VoteItem[i] = VoteItem;
  940. OutPacket(GVHIRP, ThrottleOutPacketType.Task);
  941. i++;
  942. }
  943. if (Votes.Length == 0)
  944. {
  945. GroupVoteHistoryItemReplyPacket GVHIRP = new GroupVoteHistoryItemReplyPacket();
  946. GVHIRP.AgentData.AgentID = AgentId;
  947. GVHIRP.AgentData.GroupID = groupID;
  948. GVHIRP.TransactionData.TransactionID = transactionID;
  949. GVHIRP.TransactionData.TotalNumItems = 0;
  950. GVHIRP.HistoryItemData.VoteID = UUID.Zero;
  951. GVHIRP.HistoryItemData.VoteInitiator = UUID.Zero;
  952. GVHIRP.HistoryItemData.Majority = 0;
  953. GVHIRP.HistoryItemData.Quorum = 0;
  954. GVHIRP.HistoryItemData.TerseDateID = Utils.StringToBytes("");
  955. GVHIRP.HistoryItemData.StartDateTime = Utils.StringToBytes("");
  956. GVHIRP.HistoryItemData.EndDateTime = Utils.StringToBytes("");
  957. GVHIRP.HistoryItemData.VoteType = Utils.StringToBytes("");
  958. GVHIRP.HistoryItemData.VoteResult = Utils.StringToBytes("");
  959. GVHIRP.HistoryItemData.ProposalText = Utils.StringToBytes("");
  960. GroupVoteHistoryItemReplyPacket.VoteItemBlock VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock();
  961. GVHIRP.VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock[1];
  962. VoteItem.CandidateID = UUID.Zero;
  963. VoteItem.NumVotes = 0; //TODO: FIX THIS!!!
  964. VoteItem.VoteCast = Utils.StringToBytes("No");
  965. GVHIRP.VoteItem[0] = VoteItem;
  966. OutPacket(GVHIRP, ThrottleOutPacketType.Task);
  967. }
  968. }
  969. public void SendGroupAccountingDetails(IClientAPI sender,UUID groupID, UUID transactionID, UUID sessionID, int amt)
  970. {
  971. GroupAccountDetailsReplyPacket GADRP = new GroupAccountDetailsReplyPacket();
  972. GADRP.AgentData = new GroupAccountDetailsReplyPacket.AgentDataBlock();
  973. GADRP.AgentData.AgentID = sender.AgentId;
  974. GADRP.AgentData.GroupID = groupID;
  975. GADRP.HistoryData = new GroupAccountDetailsReplyPacket.HistoryDataBlock[1];
  976. GroupAccountDetailsReplyPacket.HistoryDataBlock History = new GroupAccountDetailsReplyPacket.HistoryDataBlock();
  977. GADRP.MoneyData = new GroupAccountDetailsReplyPacket.MoneyDataBlock();
  978. GADRP.MoneyData.CurrentInterval = 0;
  979. GADRP.MoneyData.IntervalDays = 7;
  980. GADRP.MoneyData.RequestID = transactionID;
  981. GADRP.MoneyData.StartDate = Utils.StringToBytes(DateTime.Today.ToString());
  982. History.Amount = amt;
  983. History.Description = Utils.StringToBytes("");
  984. GADRP.HistoryData[0] = History;
  985. OutPacket(GADRP, ThrottleOutPacketType.Task);
  986. }
  987. public void SendGroupAccountingSummary(IClientAPI sender,UUID groupID, uint moneyAmt, int totalTier, int usedTier)
  988. {
  989. GroupAccountSummaryReplyPacket GASRP =
  990. (GroupAccountSummaryReplyPacket)PacketPool.Instance.GetPacket(
  991. PacketType.GroupAccountSummaryReply);
  992. GASRP.AgentData = new GroupAccountSummaryReplyPacket.AgentDataBlock();
  993. GASRP.AgentData.AgentID = sender.AgentId;
  994. GASRP.AgentData.GroupID = groupID;
  995. GASRP.MoneyData = new GroupAccountSummaryReplyPacket.MoneyDataBlock();
  996. GASRP.MoneyData.Balance = (int)moneyAmt;
  997. GASRP.MoneyData.TotalCredits = totalTier;
  998. GASRP.MoneyData.TotalDebits = usedTier;
  999. GASRP.MoneyData.StartDate = new byte[1];
  1000. GASRP.MoneyData.CurrentInterval = 1;
  1001. GASRP.MoneyData.GroupTaxCurrent = 0;
  1002. GASRP.MoneyData.GroupTaxEstimate = 0;
  1003. GASRP.MoneyData.IntervalDays = 0;
  1004. GASRP.MoneyData.LandTaxCurrent = 0;
  1005. GASRP.MoneyData.LandTaxEstimate = 0;
  1006. GASRP.MoneyData.LastTaxDate = new byte[1];
  1007. GASRP.MoneyData.LightTaxCurrent = 0;
  1008. GASRP.MoneyData.TaxDate = new byte[1];
  1009. GASRP.MoneyData.RequestID = sender.AgentId;
  1010. GASRP.MoneyData.ParcelDirFeeEstimate = 0;
  1011. GASRP.MoneyData.ParcelDirFeeCurrent = 0;
  1012. GASRP.MoneyData.ObjectTaxEstimate = 0;
  1013. GASRP.MoneyData.NonExemptMembers = 0;
  1014. GASRP.MoneyData.ObjectTaxCurrent = 0;
  1015. GASRP.MoneyData.LightTaxEstimate = 0;
  1016. OutPacket(GASRP, ThrottleOutPacketType.Task);
  1017. }
  1018. public void SendGroupTransactionsSummaryDetails(IClientAPI sender,UUID groupID, UUID transactionID, UUID sessionID, int amt)
  1019. {
  1020. GroupAccountTransactionsReplyPacket GATRP =
  1021. (GroupAccountTransactionsReplyPacket)PacketPool.Instance.GetPacket(
  1022. PacketType.GroupAccountTransactionsReply);
  1023. GATRP.AgentData = new GroupAccountTransactionsReplyPacket.AgentDataBlock();
  1024. GATRP.AgentData.AgentID = sender.AgentId;
  1025. GATRP.AgentData.GroupID = groupID;
  1026. GATRP.MoneyData = new GroupAccountTransactionsReplyPacket.MoneyDataBlock();
  1027. GATRP.MoneyData.CurrentInterval = 0;
  1028. GATRP.MoneyData.IntervalDays = 7;
  1029. GATRP.MoneyData.RequestID = transactionID;
  1030. GATRP.MoneyData.StartDate = Utils.StringToBytes(DateTime.Today.ToString());
  1031. GATRP.HistoryData = new GroupAccountTransactionsReplyPacket.HistoryDataBlock[1];
  1032. GroupAccountTransactionsReplyPacket.HistoryDataBlock History = new GroupAccountTransactionsReplyPacket.HistoryDataBlock();
  1033. History.Amount = 0;
  1034. History.Item = Utils.StringToBytes("");
  1035. History.Time = Utils.StringToBytes("");
  1036. History.Type = 0;
  1037. History.User = Utils.StringToBytes("");
  1038. GATRP.HistoryData[0] = History;
  1039. OutPacket(GATRP, ThrottleOutPacketType.Task);
  1040. }
  1041. public virtual bool CanSendLayerData()
  1042. {
  1043. int n = m_udpClient.GetPacketsQueuedCount(ThrottleOutPacketType.Land);
  1044. if ( n > 128)
  1045. return false;
  1046. return true;
  1047. }
  1048. /// <summary>
  1049. /// Send the region heightmap to the client
  1050. /// This method is only called when not doing intellegent terrain patch sending and
  1051. /// is only called when the scene presence is initially created and sends all of the
  1052. /// region's patches to the client.
  1053. /// </summary>
  1054. /// <param name="map">heightmap</param>
  1055. public virtual void SendLayerData()
  1056. {
  1057. Util.FireAndForget(DoSendLayerData, null, "LLClientView.DoSendLayerData");
  1058. }
  1059. /// <summary>
  1060. /// Send terrain layer information to the client.
  1061. /// </summary>
  1062. /// <param name="o"></param>
  1063. private void DoSendLayerData(object o)
  1064. {
  1065. TerrainData map = m_scene.Heightmap.GetTerrainData();
  1066. try
  1067. {
  1068. // Send LayerData in a spiral pattern. Fun!
  1069. SendLayerTopRight(0, 0, map.SizeX / Constants.TerrainPatchSize - 1, map.SizeY / Constants.TerrainPatchSize - 1);
  1070. }
  1071. catch (Exception e)
  1072. {
  1073. m_log.Error("[CLIENT]: SendLayerData() Failed with exception: " + e.Message, e);
  1074. }
  1075. }
  1076. private void SendLayerTopRight(int x1, int y1, int x2, int y2)
  1077. {
  1078. int[] p = new int[2];
  1079. // Row
  1080. p[1] = y1;
  1081. for (int i = x1; i <= x2; ++i)
  1082. {
  1083. p[0] = i;
  1084. SendLayerData(p);
  1085. }
  1086. // Column
  1087. p[0] = x2;
  1088. for (int j = y1 + 1; j <= y2; ++j)
  1089. {
  1090. p[1] = j;
  1091. SendLayerData(p);
  1092. }
  1093. if (x2 - x1 > 0 && y2 - y1 > 0)
  1094. SendLayerBottomLeft(x1, y1 + 1, x2 - 1, y2);
  1095. }
  1096. void SendLayerBottomLeft(int x1, int y1, int x2, int y2)
  1097. {
  1098. int[] p = new int[2];
  1099. // Row in reverse
  1100. p[1] = y2;
  1101. for (int i = x2; i >= x1; --i)
  1102. {
  1103. p[0] = i;
  1104. SendLayerData(p);
  1105. }
  1106. // Column in reverse
  1107. p[0] = x1;
  1108. for (int j = y2 - 1; j >= y1; --j)
  1109. {
  1110. p[1] = j;
  1111. SendLayerData(p);
  1112. }
  1113. if (x2 - x1 > 0 && y2 - y1 > 0)
  1114. SendLayerTopRight(x1 + 1, y1, x2, y2 - 1);
  1115. }
  1116. static private readonly byte[] TerrainPacketHeader = new byte[] {
  1117. Helpers.MSG_RELIABLE, // zero code is not as spec
  1118. 0, 0, 0, 0, // sequence number
  1119. 0, // extra
  1120. 11, // ID (high frequency)
  1121. };
  1122. private const int END_OF_PATCHES = 97;
  1123. private const int STRIDE = 264;
  1124. public void SendLayerData(int[] map)
  1125. {
  1126. if(map == null)
  1127. return;
  1128. try
  1129. {
  1130. TerrainData terrData = m_scene.Heightmap.GetTerrainData();
  1131. byte landPacketType = (terrData.SizeX > Constants.RegionSize || terrData.SizeY > Constants.RegionSize) ?
  1132. (byte)TerrainPatch.LayerType.LandExtended : (byte)TerrainPatch.LayerType.Land;
  1133. int numberPatchs = map.Length / 2;
  1134. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1135. byte[] data = buf.Data;
  1136. Buffer.BlockCopy(TerrainPacketHeader, 0, data, 0, 7);
  1137. data[7] = landPacketType;
  1138. //data[8] and data[9] == datablock size to fill later
  1139. data[10] = 0; // BitPack needs this on reused packets
  1140. // start data
  1141. BitPack bitpack = new BitPack(data, 10);
  1142. bitpack.PackBits(STRIDE, 16);
  1143. bitpack.PackBitsFromByte(16);
  1144. bitpack.PackBitsFromByte(landPacketType);
  1145. int s;
  1146. int datasize = 0;
  1147. for (int i = 0; i < numberPatchs; i++)
  1148. {
  1149. s = 2 * i;
  1150. OpenSimTerrainCompressor.CreatePatchFromTerrainData(bitpack, terrData, map[s], map[s + 1]);
  1151. if (bitpack.BytePos > 950 && i != numberPatchs - 1)
  1152. {
  1153. //finish this packet
  1154. bitpack.PackBitsFromByte(END_OF_PATCHES);
  1155. // fix the datablock lenght
  1156. datasize = bitpack.BytePos - 9;
  1157. data[8] = (byte)datasize;
  1158. data[9] = (byte)(datasize >> 8);
  1159. buf.DataLength = bitpack.BytePos + 1;
  1160. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land, null, false, false);
  1161. // start another
  1162. buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1163. data = buf.Data;
  1164. Buffer.BlockCopy(TerrainPacketHeader, 0, data, 0, 7);
  1165. data[7] = landPacketType;
  1166. //data[8] and data[9] == datablock size to fill later
  1167. data[10] = 0; // BitPack needs this
  1168. // start data
  1169. bitpack = new BitPack(data, 10);
  1170. bitpack.PackBits(STRIDE, 16);
  1171. bitpack.PackBitsFromByte(16);
  1172. bitpack.PackBitsFromByte(landPacketType);
  1173. }
  1174. }
  1175. bitpack.PackBitsFromByte(END_OF_PATCHES);
  1176. datasize = bitpack.BytePos - 9;
  1177. data[8] = (byte)datasize;
  1178. data[9] = (byte)(datasize >> 8);
  1179. buf.DataLength = bitpack.BytePos + 1;
  1180. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land, null, false, false);
  1181. }
  1182. catch (Exception e)
  1183. {
  1184. m_log.Error("[CLIENT]: SendLayerData() Failed with exception: " + e.Message, e);
  1185. }
  1186. }
  1187. private void DebugSendingPatches(string pWho, int[] pX, int[] pY)
  1188. {
  1189. if (m_log.IsDebugEnabled)
  1190. {
  1191. int numPatches = pX.Length;
  1192. string Xs = "";
  1193. string Ys = "";
  1194. for (int pp = 0; pp < numPatches; pp++)
  1195. {
  1196. Xs += String.Format("{0}", (int)pX[pp]) + ",";
  1197. Ys += String.Format("{0}", (int)pY[pp]) + ",";
  1198. }
  1199. m_log.DebugFormat("{0} {1}: numPatches={2}, X={3}, Y={4}", LogHeader, pWho, numPatches, Xs, Ys);
  1200. }
  1201. }
  1202. // wind caching
  1203. private static Dictionary<ulong,int> lastWindVersion = new Dictionary<ulong,int>();
  1204. private static Dictionary<ulong,List<LayerDataPacket>> lastWindPackets =
  1205. new Dictionary<ulong,List<LayerDataPacket>>();
  1206. /// <summary>
  1207. /// Send the wind matrix to the client
  1208. /// </summary>
  1209. /// <param name="windSpeeds">16x16 array of wind speeds</param>
  1210. public virtual void SendWindData(int version, Vector2[] windSpeeds)
  1211. {
  1212. // Vector2[] windSpeeds = (Vector2[])o;
  1213. ulong handle = this.Scene.RegionInfo.RegionHandle;
  1214. bool isNewData;
  1215. lock(lastWindPackets)
  1216. {
  1217. if(!lastWindVersion.ContainsKey(handle) ||
  1218. !lastWindPackets.ContainsKey(handle))
  1219. {
  1220. lastWindVersion[handle] = 0;
  1221. lastWindPackets[handle] = new List<LayerDataPacket>();
  1222. isNewData = true;
  1223. }
  1224. else
  1225. isNewData = lastWindVersion[handle] != version;
  1226. }
  1227. if(isNewData)
  1228. {
  1229. TerrainPatch[] patches = new TerrainPatch[2];
  1230. patches[0] = new TerrainPatch { Data = new float[16 * 16] };
  1231. patches[1] = new TerrainPatch { Data = new float[16 * 16] };
  1232. for (int x = 0; x < 16 * 16; x++)
  1233. {
  1234. patches[0].Data[x] = windSpeeds[x].X;
  1235. patches[1].Data[x] = windSpeeds[x].Y;
  1236. }
  1237. // neither we or viewers have extended wind
  1238. byte layerType = (byte)TerrainPatch.LayerType.Wind;
  1239. LayerDataPacket layerpack =
  1240. OpenSimTerrainCompressor.CreateLayerDataPacketStandardSize(
  1241. patches, layerType);
  1242. layerpack.Header.Zerocoded = true;
  1243. lock(lastWindPackets)
  1244. {
  1245. lastWindPackets[handle].Clear();
  1246. lastWindPackets[handle].Add(layerpack);
  1247. lastWindVersion[handle] = version;
  1248. }
  1249. }
  1250. lock(lastWindPackets)
  1251. foreach(LayerDataPacket pkt in lastWindPackets[handle])
  1252. OutPacket(pkt, ThrottleOutPacketType.Wind);
  1253. }
  1254. // cloud caching
  1255. private static Dictionary<ulong,int> lastCloudVersion = new Dictionary<ulong,int>();
  1256. private static Dictionary<ulong,List<LayerDataPacket>> lastCloudPackets =
  1257. new Dictionary<ulong,List<LayerDataPacket>>();
  1258. /// <summary>
  1259. /// Send the cloud matrix to the client
  1260. /// </summary>
  1261. /// <param name="windSpeeds">16x16 array of cloud densities</param>
  1262. public virtual void SendCloudData(int version, float[] cloudDensity)
  1263. {
  1264. ulong handle = this.Scene.RegionInfo.RegionHandle;
  1265. bool isNewData;
  1266. lock(lastWindPackets)
  1267. {
  1268. if(!lastCloudVersion.ContainsKey(handle) ||
  1269. !lastCloudPackets.ContainsKey(handle))
  1270. {
  1271. lastCloudVersion[handle] = 0;
  1272. lastCloudPackets[handle] = new List<LayerDataPacket>();
  1273. isNewData = true;
  1274. }
  1275. else
  1276. isNewData = lastCloudVersion[handle] != version;
  1277. }
  1278. if(isNewData)
  1279. {
  1280. TerrainPatch[] patches = new TerrainPatch[1];
  1281. patches[0] = new TerrainPatch();
  1282. patches[0].Data = new float[16 * 16];
  1283. for (int y = 0; y < 16; y++)
  1284. {
  1285. for (int x = 0; x < 16; x++)
  1286. {
  1287. patches[0].Data[y * 16 + x] = cloudDensity[y * 16 + x];
  1288. }
  1289. }
  1290. // neither we or viewers have extended clouds
  1291. byte layerType = (byte)TerrainPatch.LayerType.Cloud;
  1292. LayerDataPacket layerpack =
  1293. OpenSimTerrainCompressor.CreateLayerDataPacketStandardSize(
  1294. patches, layerType);
  1295. layerpack.Header.Zerocoded = true;
  1296. lock(lastCloudPackets)
  1297. {
  1298. lastCloudPackets[handle].Clear();
  1299. lastCloudPackets[handle].Add(layerpack);
  1300. lastCloudVersion[handle] = version;
  1301. }
  1302. }
  1303. lock(lastCloudPackets)
  1304. foreach(LayerDataPacket pkt in lastCloudPackets[handle])
  1305. OutPacket(pkt, ThrottleOutPacketType.Cloud);
  1306. }
  1307. /// <summary>
  1308. /// Tell the client that the given neighbour region is ready to receive a child agent.
  1309. /// </summary>
  1310. public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourEndPoint)
  1311. {
  1312. IPAddress neighbourIP = neighbourEndPoint.Address;
  1313. ushort neighbourPort = (ushort)neighbourEndPoint.Port;
  1314. EnableSimulatorPacket enablesimpacket = (EnableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.EnableSimulator);
  1315. // TODO: don't create new blocks if recycling an old packet
  1316. enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock();
  1317. enablesimpacket.SimulatorInfo.Handle = neighbourHandle;
  1318. byte[] byteIP = neighbourIP.GetAddressBytes();
  1319. enablesimpacket.SimulatorInfo.IP = (uint)byteIP[3] << 24;
  1320. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[2] << 16;
  1321. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[1] << 8;
  1322. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[0];
  1323. enablesimpacket.SimulatorInfo.Port = neighbourPort;
  1324. enablesimpacket.Header.Reliable = true; // ESP's should be reliable.
  1325. OutPacket(enablesimpacket, ThrottleOutPacketType.Task);
  1326. }
  1327. public AgentCircuitData RequestClientInfo()
  1328. {
  1329. AgentCircuitData agentData = new AgentCircuitData();
  1330. agentData.AgentID = AgentId;
  1331. agentData.SessionID = m_sessionId;
  1332. agentData.SecureSessionID = SecureSessionId;
  1333. agentData.circuitcode = m_circuitCode;
  1334. agentData.child = false;
  1335. agentData.firstname = m_firstName;
  1336. agentData.lastname = m_lastName;
  1337. ICapabilitiesModule capsModule = m_scene.RequestModuleInterface<ICapabilitiesModule>();
  1338. if (capsModule == null) // can happen when shutting down.
  1339. return agentData;
  1340. agentData.CapsPath = capsModule.GetCapsPath(m_agentId);
  1341. agentData.ChildrenCapSeeds = new Dictionary<ulong, string>(capsModule.GetChildrenSeeds(m_agentId));
  1342. return agentData;
  1343. }
  1344. public virtual void CrossRegion(ulong newRegionHandle, Vector3 pos, Vector3 lookAt, IPEndPoint externalIPEndPoint,
  1345. string capsURL)
  1346. {
  1347. Vector3 look = new Vector3(lookAt.X * 10, lookAt.Y * 10, lookAt.Z * 10);
  1348. //CrossedRegionPacket newSimPack = (CrossedRegionPacket)PacketPool.Instance.GetPacket(PacketType.CrossedRegion);
  1349. CrossedRegionPacket newSimPack = new CrossedRegionPacket();
  1350. // TODO: don't create new blocks if recycling an old packet
  1351. newSimPack.AgentData = new CrossedRegionPacket.AgentDataBlock();
  1352. newSimPack.AgentData.AgentID = AgentId;
  1353. newSimPack.AgentData.SessionID = m_sessionId;
  1354. newSimPack.Info = new CrossedRegionPacket.InfoBlock();
  1355. newSimPack.Info.Position = pos;
  1356. newSimPack.Info.LookAt = look;
  1357. newSimPack.RegionData = new CrossedRegionPacket.RegionDataBlock();
  1358. newSimPack.RegionData.RegionHandle = newRegionHandle;
  1359. byte[] byteIP = externalIPEndPoint.Address.GetAddressBytes();
  1360. newSimPack.RegionData.SimIP = (uint)byteIP[3] << 24;
  1361. newSimPack.RegionData.SimIP += (uint)byteIP[2] << 16;
  1362. newSimPack.RegionData.SimIP += (uint)byteIP[1] << 8;
  1363. newSimPack.RegionData.SimIP += (uint)byteIP[0];
  1364. newSimPack.RegionData.SimPort = (ushort)externalIPEndPoint.Port;
  1365. newSimPack.RegionData.SeedCapability = Util.StringToBytes256(capsURL);
  1366. // Hack to get this out immediately and skip throttles
  1367. OutPacket(newSimPack, ThrottleOutPacketType.Unknown);
  1368. }
  1369. internal void SendMapBlockSplit(List<MapBlockData> mapBlocks, uint flag)
  1370. {
  1371. MapBlockReplyPacket mapReply = (MapBlockReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapBlockReply);
  1372. // TODO: don't create new blocks if recycling an old packet
  1373. MapBlockData[] mapBlocks2 = mapBlocks.ToArray();
  1374. mapReply.AgentData.AgentID = AgentId;
  1375. mapReply.Data = new MapBlockReplyPacket.DataBlock[mapBlocks2.Length];
  1376. mapReply.Size = new MapBlockReplyPacket.SizeBlock[mapBlocks2.Length];
  1377. mapReply.AgentData.Flags = flag;
  1378. for (int i = 0; i < mapBlocks2.Length; i++)
  1379. {
  1380. mapReply.Data[i] = new MapBlockReplyPacket.DataBlock();
  1381. mapReply.Data[i].MapImageID = mapBlocks2[i].MapImageId;
  1382. //m_log.Warn(mapBlocks2[i].MapImageId.ToString());
  1383. mapReply.Data[i].X = mapBlocks2[i].X;
  1384. mapReply.Data[i].Y = mapBlocks2[i].Y;
  1385. mapReply.Data[i].WaterHeight = mapBlocks2[i].WaterHeight;
  1386. mapReply.Data[i].Name = Utils.StringToBytes(mapBlocks2[i].Name);
  1387. mapReply.Data[i].RegionFlags = mapBlocks2[i].RegionFlags;
  1388. mapReply.Data[i].Access = mapBlocks2[i].Access;
  1389. mapReply.Data[i].Agents = mapBlocks2[i].Agents;
  1390. mapReply.Size[i] = new MapBlockReplyPacket.SizeBlock();
  1391. mapReply.Size[i].SizeX = mapBlocks2[i].SizeX;
  1392. mapReply.Size[i].SizeY = mapBlocks2[i].SizeY;
  1393. }
  1394. OutPacket(mapReply, ThrottleOutPacketType.Land);
  1395. }
  1396. public void SendMapBlock(List<MapBlockData> mapBlocks, uint flag)
  1397. {
  1398. MapBlockData[] mapBlocks2 = mapBlocks.ToArray();
  1399. int maxsend = 10;
  1400. //int packets = Math.Ceiling(mapBlocks2.Length / maxsend);
  1401. List<MapBlockData> sendingBlocks = new List<MapBlockData>();
  1402. for (int i = 0; i < mapBlocks2.Length; i++)
  1403. {
  1404. sendingBlocks.Add(mapBlocks2[i]);
  1405. if (((i + 1) == mapBlocks2.Length) || (((i + 1) % maxsend) == 0))
  1406. {
  1407. SendMapBlockSplit(sendingBlocks, flag);
  1408. sendingBlocks = new List<MapBlockData>();
  1409. }
  1410. }
  1411. }
  1412. public void SendLocalTeleport(Vector3 position, Vector3 lookAt, uint flags)
  1413. {
  1414. TeleportLocalPacket tpLocal = (TeleportLocalPacket)PacketPool.Instance.GetPacket(PacketType.TeleportLocal);
  1415. tpLocal.Info.AgentID = AgentId;
  1416. tpLocal.Info.TeleportFlags = flags;
  1417. tpLocal.Info.LocationID = 2;
  1418. tpLocal.Info.LookAt = lookAt;
  1419. tpLocal.Info.Position = position;
  1420. // Hack to get this out immediately and skip throttles
  1421. OutPacket(tpLocal, ThrottleOutPacketType.Unknown);
  1422. }
  1423. public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint newRegionEndPoint, uint locationID,
  1424. uint flags, string capsURL)
  1425. {
  1426. //TeleportFinishPacket teleport = (TeleportFinishPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFinish);
  1427. TeleportFinishPacket teleport = new TeleportFinishPacket();
  1428. teleport.Info.AgentID = AgentId;
  1429. teleport.Info.RegionHandle = regionHandle;
  1430. teleport.Info.SimAccess = simAccess;
  1431. teleport.Info.SeedCapability = Util.StringToBytes256(capsURL);
  1432. IPAddress oIP = newRegionEndPoint.Address;
  1433. byte[] byteIP = oIP.GetAddressBytes();
  1434. uint ip = (uint)byteIP[3] << 24;
  1435. ip += (uint)byteIP[2] << 16;
  1436. ip += (uint)byteIP[1] << 8;
  1437. ip += (uint)byteIP[0];
  1438. teleport.Info.SimIP = ip;
  1439. teleport.Info.SimPort = (ushort)newRegionEndPoint.Port;
  1440. teleport.Info.LocationID = 4;
  1441. teleport.Info.TeleportFlags = 1 << 4;
  1442. // Hack to get this out immediately and skip throttles.
  1443. OutPacket(teleport, ThrottleOutPacketType.Unknown);
  1444. }
  1445. /// <summary>
  1446. /// Inform the client that a teleport attempt has failed
  1447. /// </summary>
  1448. public void SendTeleportFailed(string reason)
  1449. {
  1450. TeleportFailedPacket tpFailed = (TeleportFailedPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFailed);
  1451. tpFailed.Info.AgentID = AgentId;
  1452. tpFailed.Info.Reason = Util.StringToBytes256(reason);
  1453. tpFailed.AlertInfo = new TeleportFailedPacket.AlertInfoBlock[0];
  1454. // Hack to get this out immediately and skip throttles
  1455. OutPacket(tpFailed, ThrottleOutPacketType.Unknown);
  1456. }
  1457. /// <summary>
  1458. ///
  1459. /// </summary>
  1460. public void SendTeleportStart(uint flags)
  1461. {
  1462. TeleportStartPacket tpStart = (TeleportStartPacket)PacketPool.Instance.GetPacket(PacketType.TeleportStart);
  1463. //TeleportStartPacket tpStart = new TeleportStartPacket();
  1464. tpStart.Info.TeleportFlags = flags; //16; // Teleport via location
  1465. // Hack to get this out immediately and skip throttles
  1466. OutPacket(tpStart, ThrottleOutPacketType.Unknown);
  1467. }
  1468. public void SendTeleportProgress(uint flags, string message)
  1469. {
  1470. TeleportProgressPacket tpProgress = (TeleportProgressPacket)PacketPool.Instance.GetPacket(PacketType.TeleportProgress);
  1471. tpProgress.AgentData.AgentID = this.AgentId;
  1472. tpProgress.Info.TeleportFlags = flags;
  1473. tpProgress.Info.Message = Util.StringToBytes256(message);
  1474. // Hack to get this out immediately and skip throttles
  1475. OutPacket(tpProgress, ThrottleOutPacketType.Unknown);
  1476. }
  1477. public void SendMoneyBalance(UUID transaction, bool success, byte[] description, int balance, int transactionType, UUID sourceID, bool sourceIsGroup, UUID destID, bool destIsGroup, int amount, string item)
  1478. {
  1479. MoneyBalanceReplyPacket money = (MoneyBalanceReplyPacket)PacketPool.Instance.GetPacket(PacketType.MoneyBalanceReply);
  1480. money.MoneyData.AgentID = AgentId;
  1481. money.MoneyData.TransactionID = transaction;
  1482. money.MoneyData.TransactionSuccess = success;
  1483. money.MoneyData.Description = description;
  1484. money.MoneyData.MoneyBalance = balance;
  1485. money.TransactionInfo.TransactionType = transactionType;
  1486. money.TransactionInfo.SourceID = sourceID;
  1487. money.TransactionInfo.IsSourceGroup = sourceIsGroup;
  1488. money.TransactionInfo.DestID = destID;
  1489. money.TransactionInfo.IsDestGroup = destIsGroup;
  1490. money.TransactionInfo.Amount = amount;
  1491. money.TransactionInfo.ItemDescription = Util.StringToBytes256(item);
  1492. OutPacket(money, ThrottleOutPacketType.Task);
  1493. }
  1494. public void SendPayPrice(UUID objectID, int[] payPrice)
  1495. {
  1496. if (payPrice[0] == 0 &&
  1497. payPrice[1] == 0 &&
  1498. payPrice[2] == 0 &&
  1499. payPrice[3] == 0 &&
  1500. payPrice[4] == 0)
  1501. return;
  1502. PayPriceReplyPacket payPriceReply = (PayPriceReplyPacket)PacketPool.Instance.GetPacket(PacketType.PayPriceReply);
  1503. payPriceReply.ObjectData.ObjectID = objectID;
  1504. payPriceReply.ObjectData.DefaultPayPrice = payPrice[0];
  1505. payPriceReply.ButtonData = new PayPriceReplyPacket.ButtonDataBlock[4];
  1506. payPriceReply.ButtonData[0] = new PayPriceReplyPacket.ButtonDataBlock();
  1507. payPriceReply.ButtonData[0].PayButton = payPrice[1];
  1508. payPriceReply.ButtonData[1] = new PayPriceReplyPacket.ButtonDataBlock();
  1509. payPriceReply.ButtonData[1].PayButton = payPrice[2];
  1510. payPriceReply.ButtonData[2] = new PayPriceReplyPacket.ButtonDataBlock();
  1511. payPriceReply.ButtonData[2].PayButton = payPrice[3];
  1512. payPriceReply.ButtonData[3] = new PayPriceReplyPacket.ButtonDataBlock();
  1513. payPriceReply.ButtonData[3].PayButton = payPrice[4];
  1514. OutPacket(payPriceReply, ThrottleOutPacketType.Task);
  1515. }
  1516. public void SendStartPingCheck(byte seq)
  1517. {
  1518. StartPingCheckPacket pc = (StartPingCheckPacket)PacketPool.Instance.GetPacket(PacketType.StartPingCheck);
  1519. pc.Header.Reliable = false;
  1520. pc.PingID.PingID = seq;
  1521. // We *could* get OldestUnacked, but it would hurt performance and not provide any benefit
  1522. pc.PingID.OldestUnacked = 0;
  1523. OutPacket(pc, ThrottleOutPacketType.Unknown);
  1524. UDPClient.m_lastStartpingTimeMS = Util.EnvironmentTickCount();
  1525. }
  1526. public void SendKillObject(List<uint> localIDs)
  1527. {
  1528. // foreach (uint id in localIDs)
  1529. // m_log.DebugFormat("[CLIENT]: Sending KillObjectPacket to {0} for {1} in {2}", Name, id, regionHandle);
  1530. // remove pending entities to reduce looping chances.
  1531. lock (m_entityProps.SyncRoot)
  1532. m_entityProps.Remove(localIDs);
  1533. lock (m_entityUpdates.SyncRoot)
  1534. m_entityUpdates.Remove(localIDs);
  1535. KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
  1536. int perpacket = localIDs.Count;
  1537. if(perpacket > 200)
  1538. perpacket = 200;
  1539. int nsent = 0;
  1540. kill.ObjectData = new KillObjectPacket.ObjectDataBlock[perpacket];
  1541. for (int i = 0 ; i < localIDs.Count ; i++ )
  1542. {
  1543. kill.ObjectData[nsent] = new KillObjectPacket.ObjectDataBlock();
  1544. kill.ObjectData[nsent].ID = localIDs[i];
  1545. if(++nsent >= 200)
  1546. {
  1547. OutPacket(kill, ThrottleOutPacketType.Task);
  1548. perpacket = localIDs.Count - i - 1;
  1549. if(perpacket == 0)
  1550. break;
  1551. if(perpacket > 200)
  1552. perpacket = 200;
  1553. kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
  1554. kill.ObjectData = new KillObjectPacket.ObjectDataBlock[perpacket];
  1555. nsent = 0;
  1556. }
  1557. }
  1558. if(nsent != 0)
  1559. {
  1560. OutPacket(kill, ThrottleOutPacketType.Task);
  1561. }
  1562. }
  1563. /// <summary>
  1564. /// Send information about the items contained in a folder to the client.
  1565. /// </summary>
  1566. /// <remarks>
  1567. /// XXX This method needs some refactoring loving
  1568. /// </remarks>
  1569. /// <param name="ownerID">The owner of the folder</param>
  1570. /// <param name="folderID">The id of the folder</param>
  1571. /// <param name="items">The items contained in the folder identified by folderID</param>
  1572. /// <param name="folders"></param>
  1573. /// <param name="fetchFolders">Do we need to send folder information?</param>
  1574. /// <param name="fetchItems">Do we need to send item information?</param>
  1575. public void SendInventoryFolderDetails(UUID ownerID, UUID folderID, List<InventoryItemBase> items,
  1576. List<InventoryFolderBase> folders, int version,
  1577. bool fetchFolders, bool fetchItems)
  1578. {
  1579. // An inventory descendents packet consists of a single agent section and an inventory details
  1580. // section for each inventory item. The size of each inventory item is approximately 550 bytes.
  1581. // In theory, UDP has a maximum packet size of 64k, so it should be possible to send descendent
  1582. // packets containing metadata for in excess of 100 items. But in practice, there may be other
  1583. // factors (e.g. firewalls) restraining the maximum UDP packet size. See,
  1584. //
  1585. // http://opensimulator.org/mantis/view.php?id=226
  1586. //
  1587. // for one example of this kind of thing. In fact, the Linden servers appear to only send about
  1588. // 6 to 7 items at a time, so let's stick with 6
  1589. int MAX_ITEMS_PER_PACKET = 5;
  1590. int MAX_FOLDERS_PER_PACKET = 6;
  1591. int totalItems = fetchItems ? items.Count : 0;
  1592. int totalFolders = fetchFolders ? folders.Count : 0;
  1593. int itemsSent = 0;
  1594. int foldersSent = 0;
  1595. int foldersToSend = 0;
  1596. int itemsToSend = 0;
  1597. InventoryDescendentsPacket currentPacket = null;
  1598. // Handle empty folders
  1599. //
  1600. if (totalItems == 0 && totalFolders == 0)
  1601. currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, items.Count + folders.Count, 0, 0);
  1602. // To preserve SL compatibility, we will NOT combine folders and items in one packet
  1603. //
  1604. while (itemsSent < totalItems || foldersSent < totalFolders)
  1605. {
  1606. if (currentPacket == null) // Start a new packet
  1607. {
  1608. foldersToSend = totalFolders - foldersSent;
  1609. if (foldersToSend > MAX_FOLDERS_PER_PACKET)
  1610. foldersToSend = MAX_FOLDERS_PER_PACKET;
  1611. if (foldersToSend == 0)
  1612. {
  1613. itemsToSend = totalItems - itemsSent;
  1614. if (itemsToSend > MAX_ITEMS_PER_PACKET)
  1615. itemsToSend = MAX_ITEMS_PER_PACKET;
  1616. }
  1617. currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, items.Count + folders.Count, foldersToSend, itemsToSend);
  1618. }
  1619. if (foldersToSend-- > 0)
  1620. currentPacket.FolderData[foldersSent % MAX_FOLDERS_PER_PACKET] = CreateFolderDataBlock(folders[foldersSent++]);
  1621. else if (itemsToSend-- > 0)
  1622. currentPacket.ItemData[itemsSent % MAX_ITEMS_PER_PACKET] = CreateItemDataBlock(items[itemsSent++]);
  1623. else
  1624. {
  1625. // m_log.DebugFormat(
  1626. // "[LLCLIENTVIEW]: Sending inventory folder details packet to {0} for folder {1}", Name, folderID);
  1627. OutPacket(currentPacket, ThrottleOutPacketType.Asset, false);
  1628. currentPacket = null;
  1629. }
  1630. }
  1631. if (currentPacket != null)
  1632. {
  1633. // m_log.DebugFormat(
  1634. // "[LLCLIENTVIEW]: Sending inventory folder details packet to {0} for folder {1}", Name, folderID);
  1635. OutPacket(currentPacket, ThrottleOutPacketType.Asset, false);
  1636. }
  1637. }
  1638. private InventoryDescendentsPacket.FolderDataBlock CreateFolderDataBlock(InventoryFolderBase folder)
  1639. {
  1640. InventoryDescendentsPacket.FolderDataBlock newBlock = new InventoryDescendentsPacket.FolderDataBlock();
  1641. newBlock.FolderID = folder.ID;
  1642. newBlock.Name = Util.StringToBytes256(folder.Name);
  1643. newBlock.ParentID = folder.ParentID;
  1644. newBlock.Type = (sbyte)folder.Type;
  1645. //if (newBlock.Type == InventoryItemBase.SUITCASE_FOLDER_TYPE)
  1646. // newBlock.Type = InventoryItemBase.SUITCASE_FOLDER_FAKE_TYPE;
  1647. return newBlock;
  1648. }
  1649. private InventoryDescendentsPacket.ItemDataBlock CreateItemDataBlock(InventoryItemBase item)
  1650. {
  1651. InventoryDescendentsPacket.ItemDataBlock newBlock = new InventoryDescendentsPacket.ItemDataBlock();
  1652. newBlock.ItemID = item.ID;
  1653. newBlock.AssetID = item.AssetID;
  1654. newBlock.CreatorID = item.CreatorIdAsUuid;
  1655. newBlock.BaseMask = item.BasePermissions;
  1656. newBlock.Description = Util.StringToBytes256(item.Description);
  1657. newBlock.EveryoneMask = item.EveryOnePermissions;
  1658. newBlock.OwnerMask = item.CurrentPermissions;
  1659. newBlock.FolderID = item.Folder;
  1660. newBlock.InvType = (sbyte)item.InvType;
  1661. newBlock.Name = Util.StringToBytes256(item.Name);
  1662. newBlock.NextOwnerMask = item.NextPermissions;
  1663. newBlock.OwnerID = item.Owner;
  1664. newBlock.Type = (sbyte)item.AssetType;
  1665. newBlock.GroupID = item.GroupID;
  1666. newBlock.GroupOwned = item.GroupOwned;
  1667. newBlock.GroupMask = item.GroupPermissions;
  1668. newBlock.CreationDate = item.CreationDate;
  1669. newBlock.SalePrice = item.SalePrice;
  1670. newBlock.SaleType = item.SaleType;
  1671. newBlock.Flags = item.Flags & 0x2000ff;
  1672. newBlock.CRC =
  1673. Helpers.InventoryCRC(newBlock.CreationDate, newBlock.SaleType,
  1674. newBlock.InvType, newBlock.Type,
  1675. newBlock.AssetID, newBlock.GroupID,
  1676. newBlock.SalePrice,
  1677. newBlock.OwnerID, newBlock.CreatorID,
  1678. newBlock.ItemID, newBlock.FolderID,
  1679. newBlock.EveryoneMask,
  1680. newBlock.Flags, newBlock.OwnerMask,
  1681. newBlock.GroupMask, newBlock.NextOwnerMask);
  1682. return newBlock;
  1683. }
  1684. private void AddNullFolderBlockToDecendentsPacket(ref InventoryDescendentsPacket packet)
  1685. {
  1686. packet.FolderData = new InventoryDescendentsPacket.FolderDataBlock[1];
  1687. packet.FolderData[0] = new InventoryDescendentsPacket.FolderDataBlock();
  1688. packet.FolderData[0].FolderID = UUID.Zero;
  1689. packet.FolderData[0].ParentID = UUID.Zero;
  1690. packet.FolderData[0].Type = -1;
  1691. packet.FolderData[0].Name = new byte[0];
  1692. }
  1693. private void AddNullItemBlockToDescendentsPacket(ref InventoryDescendentsPacket packet)
  1694. {
  1695. packet.ItemData = new InventoryDescendentsPacket.ItemDataBlock[1];
  1696. packet.ItemData[0] = new InventoryDescendentsPacket.ItemDataBlock();
  1697. packet.ItemData[0].ItemID = UUID.Zero;
  1698. packet.ItemData[0].AssetID = UUID.Zero;
  1699. packet.ItemData[0].CreatorID = UUID.Zero;
  1700. packet.ItemData[0].BaseMask = 0;
  1701. packet.ItemData[0].Description = new byte[0];
  1702. packet.ItemData[0].EveryoneMask = 0;
  1703. packet.ItemData[0].OwnerMask = 0;
  1704. packet.ItemData[0].FolderID = UUID.Zero;
  1705. packet.ItemData[0].InvType = (sbyte)0;
  1706. packet.ItemData[0].Name = new byte[0];
  1707. packet.ItemData[0].NextOwnerMask = 0;
  1708. packet.ItemData[0].OwnerID = UUID.Zero;
  1709. packet.ItemData[0].Type = -1;
  1710. packet.ItemData[0].GroupID = UUID.Zero;
  1711. packet.ItemData[0].GroupOwned = false;
  1712. packet.ItemData[0].GroupMask = 0;
  1713. packet.ItemData[0].CreationDate = 0;
  1714. packet.ItemData[0].SalePrice = 0;
  1715. packet.ItemData[0].SaleType = 0;
  1716. packet.ItemData[0].Flags = 0;
  1717. // No need to add CRC
  1718. }
  1719. private InventoryDescendentsPacket CreateInventoryDescendentsPacket(UUID ownerID, UUID folderID, int version, int descendents, int folders, int items)
  1720. {
  1721. InventoryDescendentsPacket descend = (InventoryDescendentsPacket)PacketPool.Instance.GetPacket(PacketType.InventoryDescendents);
  1722. descend.Header.Zerocoded = true;
  1723. descend.AgentData.AgentID = AgentId;
  1724. descend.AgentData.OwnerID = ownerID;
  1725. descend.AgentData.FolderID = folderID;
  1726. descend.AgentData.Version = version;
  1727. descend.AgentData.Descendents = descendents;
  1728. if (folders > 0)
  1729. descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders];
  1730. else
  1731. AddNullFolderBlockToDecendentsPacket(ref descend);
  1732. if (items > 0)
  1733. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items];
  1734. else
  1735. AddNullItemBlockToDescendentsPacket(ref descend);
  1736. return descend;
  1737. }
  1738. public void SendInventoryItemDetails(UUID ownerID, InventoryItemBase item)
  1739. {
  1740. // Fudge this value. It's only needed to make the CRC anyway
  1741. const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff;
  1742. FetchInventoryReplyPacket inventoryReply = (FetchInventoryReplyPacket)PacketPool.Instance.GetPacket(PacketType.FetchInventoryReply);
  1743. // TODO: don't create new blocks if recycling an old packet
  1744. inventoryReply.AgentData.AgentID = AgentId;
  1745. inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1];
  1746. inventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock();
  1747. inventoryReply.InventoryData[0].ItemID = item.ID;
  1748. inventoryReply.InventoryData[0].AssetID = item.AssetID;
  1749. inventoryReply.InventoryData[0].CreatorID = item.CreatorIdAsUuid;
  1750. inventoryReply.InventoryData[0].BaseMask = item.BasePermissions;
  1751. inventoryReply.InventoryData[0].CreationDate = item.CreationDate;
  1752. inventoryReply.InventoryData[0].Description = Util.StringToBytes256(item.Description);
  1753. inventoryReply.InventoryData[0].EveryoneMask = item.EveryOnePermissions;
  1754. inventoryReply.InventoryData[0].FolderID = item.Folder;
  1755. inventoryReply.InventoryData[0].InvType = (sbyte)item.InvType;
  1756. inventoryReply.InventoryData[0].Name = Util.StringToBytes256(item.Name);
  1757. inventoryReply.InventoryData[0].NextOwnerMask = item.NextPermissions;
  1758. inventoryReply.InventoryData[0].OwnerID = item.Owner;
  1759. inventoryReply.InventoryData[0].OwnerMask = item.CurrentPermissions;
  1760. inventoryReply.InventoryData[0].Type = (sbyte)item.AssetType;
  1761. inventoryReply.InventoryData[0].GroupID = item.GroupID;
  1762. inventoryReply.InventoryData[0].GroupOwned = item.GroupOwned;
  1763. inventoryReply.InventoryData[0].GroupMask = item.GroupPermissions;
  1764. inventoryReply.InventoryData[0].Flags = item.Flags;
  1765. inventoryReply.InventoryData[0].SalePrice = item.SalePrice;
  1766. inventoryReply.InventoryData[0].SaleType = item.SaleType;
  1767. inventoryReply.InventoryData[0].CRC =
  1768. Helpers.InventoryCRC(
  1769. 1000, 0, inventoryReply.InventoryData[0].InvType,
  1770. inventoryReply.InventoryData[0].Type, inventoryReply.InventoryData[0].AssetID,
  1771. inventoryReply.InventoryData[0].GroupID, 100,
  1772. inventoryReply.InventoryData[0].OwnerID, inventoryReply.InventoryData[0].CreatorID,
  1773. inventoryReply.InventoryData[0].ItemID, inventoryReply.InventoryData[0].FolderID,
  1774. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  1775. FULL_MASK_PERMISSIONS);
  1776. inventoryReply.Header.Zerocoded = true;
  1777. OutPacket(inventoryReply, ThrottleOutPacketType.Asset);
  1778. }
  1779. protected void SendBulkUpdateInventoryFolder(InventoryFolderBase folderBase)
  1780. {
  1781. // We will use the same transaction id for all the separate packets to be sent out in this update.
  1782. UUID transactionId = UUID.Random();
  1783. List<BulkUpdateInventoryPacket.FolderDataBlock> folderDataBlocks
  1784. = new List<BulkUpdateInventoryPacket.FolderDataBlock>();
  1785. SendBulkUpdateInventoryFolderRecursive(folderBase, ref folderDataBlocks, transactionId);
  1786. if (folderDataBlocks.Count > 0)
  1787. {
  1788. // We'll end up with some unsent folder blocks if there were some empty folders at the end of the list
  1789. // Send these now
  1790. BulkUpdateInventoryPacket bulkUpdate
  1791. = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
  1792. bulkUpdate.Header.Zerocoded = true;
  1793. bulkUpdate.AgentData.AgentID = AgentId;
  1794. bulkUpdate.AgentData.TransactionID = transactionId;
  1795. bulkUpdate.FolderData = folderDataBlocks.ToArray();
  1796. List<BulkUpdateInventoryPacket.ItemDataBlock> foo = new List<BulkUpdateInventoryPacket.ItemDataBlock>();
  1797. bulkUpdate.ItemData = foo.ToArray();
  1798. //m_log.Debug("SendBulkUpdateInventory :" + bulkUpdate);
  1799. OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
  1800. }
  1801. }
  1802. /// <summary>
  1803. /// Recursively construct bulk update packets to send folders and items
  1804. /// </summary>
  1805. /// <param name="folder"></param>
  1806. /// <param name="folderDataBlocks"></param>
  1807. /// <param name="transactionId"></param>
  1808. private void SendBulkUpdateInventoryFolderRecursive(
  1809. InventoryFolderBase folder, ref List<BulkUpdateInventoryPacket.FolderDataBlock> folderDataBlocks,
  1810. UUID transactionId)
  1811. {
  1812. folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder));
  1813. const int MAX_ITEMS_PER_PACKET = 5;
  1814. IInventoryService invService = m_scene.RequestModuleInterface<IInventoryService>();
  1815. // If there are any items then we have to start sending them off in this packet - the next folder will have
  1816. // to be in its own bulk update packet. Also, we can only fit 5 items in a packet (at least this was the limit
  1817. // being used on the Linden grid at 20081203).
  1818. InventoryCollection contents = invService.GetFolderContent(AgentId, folder.ID); // folder.RequestListOfItems();
  1819. List<InventoryItemBase> items = contents.Items;
  1820. while (items.Count > 0)
  1821. {
  1822. BulkUpdateInventoryPacket bulkUpdate
  1823. = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
  1824. bulkUpdate.Header.Zerocoded = true;
  1825. bulkUpdate.AgentData.AgentID = AgentId;
  1826. bulkUpdate.AgentData.TransactionID = transactionId;
  1827. bulkUpdate.FolderData = folderDataBlocks.ToArray();
  1828. int itemsToSend = (items.Count > MAX_ITEMS_PER_PACKET ? MAX_ITEMS_PER_PACKET : items.Count);
  1829. bulkUpdate.ItemData = new BulkUpdateInventoryPacket.ItemDataBlock[itemsToSend];
  1830. for (int i = 0; i < itemsToSend; i++)
  1831. {
  1832. // Remove from the end of the list so that we don't incur a performance penalty
  1833. bulkUpdate.ItemData[i] = GenerateBulkUpdateItemDataBlock(items[items.Count - 1]);
  1834. items.RemoveAt(items.Count - 1);
  1835. }
  1836. //m_log.Debug("SendBulkUpdateInventoryRecursive :" + bulkUpdate);
  1837. OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
  1838. folderDataBlocks = new List<BulkUpdateInventoryPacket.FolderDataBlock>();
  1839. // If we're going to be sending another items packet then it needs to contain just the folder to which those
  1840. // items belong.
  1841. if (items.Count > 0)
  1842. folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder));
  1843. }
  1844. List<InventoryFolderBase> subFolders = contents.Folders;
  1845. foreach (InventoryFolderBase subFolder in subFolders)
  1846. {
  1847. SendBulkUpdateInventoryFolderRecursive(subFolder, ref folderDataBlocks, transactionId);
  1848. }
  1849. }
  1850. /// <summary>
  1851. /// Generate a bulk update inventory data block for the given folder
  1852. /// </summary>
  1853. /// <param name="folder"></param>
  1854. /// <returns></returns>
  1855. private BulkUpdateInventoryPacket.FolderDataBlock GenerateBulkUpdateFolderDataBlock(InventoryFolderBase folder)
  1856. {
  1857. BulkUpdateInventoryPacket.FolderDataBlock folderBlock = new BulkUpdateInventoryPacket.FolderDataBlock();
  1858. folderBlock.FolderID = folder.ID;
  1859. folderBlock.ParentID = folder.ParentID;
  1860. folderBlock.Type = (sbyte)folder.Type;
  1861. // Leaving this here for now, just in case we need to do this for a while
  1862. //if (folderBlock.Type == InventoryItemBase.SUITCASE_FOLDER_TYPE)
  1863. // folderBlock.Type = InventoryItemBase.SUITCASE_FOLDER_FAKE_TYPE;
  1864. folderBlock.Name = Util.StringToBytes256(folder.Name);
  1865. return folderBlock;
  1866. }
  1867. /// <summary>
  1868. /// Generate a bulk update inventory data block for the given item
  1869. /// </summary>
  1870. /// <param name="item"></param>
  1871. /// <returns></returns>
  1872. private BulkUpdateInventoryPacket.ItemDataBlock GenerateBulkUpdateItemDataBlock(InventoryItemBase item)
  1873. {
  1874. BulkUpdateInventoryPacket.ItemDataBlock itemBlock = new BulkUpdateInventoryPacket.ItemDataBlock();
  1875. itemBlock.ItemID = item.ID;
  1876. itemBlock.AssetID = item.AssetID;
  1877. itemBlock.CreatorID = item.CreatorIdAsUuid;
  1878. itemBlock.BaseMask = item.BasePermissions;
  1879. itemBlock.Description = Util.StringToBytes256(item.Description);
  1880. itemBlock.EveryoneMask = item.EveryOnePermissions;
  1881. itemBlock.FolderID = item.Folder;
  1882. itemBlock.InvType = (sbyte)item.InvType;
  1883. itemBlock.Name = Util.StringToBytes256(item.Name);
  1884. itemBlock.NextOwnerMask = item.NextPermissions;
  1885. itemBlock.OwnerID = item.Owner;
  1886. itemBlock.OwnerMask = item.CurrentPermissions;
  1887. itemBlock.Type = (sbyte)item.AssetType;
  1888. itemBlock.GroupID = item.GroupID;
  1889. itemBlock.GroupOwned = item.GroupOwned;
  1890. itemBlock.GroupMask = item.GroupPermissions;
  1891. itemBlock.Flags = item.Flags & 0x2000ff;
  1892. itemBlock.SalePrice = item.SalePrice;
  1893. itemBlock.SaleType = item.SaleType;
  1894. itemBlock.CreationDate = item.CreationDate;
  1895. itemBlock.CRC =
  1896. Helpers.InventoryCRC(
  1897. 1000, 0, itemBlock.InvType,
  1898. itemBlock.Type, itemBlock.AssetID,
  1899. itemBlock.GroupID, 100,
  1900. itemBlock.OwnerID, itemBlock.CreatorID,
  1901. itemBlock.ItemID, itemBlock.FolderID,
  1902. (uint)PermissionMask.All, 1, (uint)PermissionMask.All, (uint)PermissionMask.All,
  1903. (uint)PermissionMask.All);
  1904. return itemBlock;
  1905. }
  1906. public void SendBulkUpdateInventory(InventoryNodeBase node)
  1907. {
  1908. if (node is InventoryItemBase)
  1909. SendBulkUpdateInventoryItem((InventoryItemBase)node);
  1910. else if (node is InventoryFolderBase)
  1911. SendBulkUpdateInventoryFolder((InventoryFolderBase)node);
  1912. else if (node != null)
  1913. m_log.ErrorFormat("[CLIENT]: {0} sent unknown inventory node named {1}", Name, node.Name);
  1914. else
  1915. m_log.ErrorFormat("[CLIENT]: {0} sent null inventory node", Name);
  1916. }
  1917. protected void SendBulkUpdateInventoryItem(InventoryItemBase item)
  1918. {
  1919. const uint FULL_MASK_PERMISSIONS = (uint)0x7ffffff;
  1920. BulkUpdateInventoryPacket bulkUpdate
  1921. = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
  1922. bulkUpdate.AgentData.AgentID = AgentId;
  1923. bulkUpdate.AgentData.TransactionID = UUID.Random();
  1924. bulkUpdate.FolderData = new BulkUpdateInventoryPacket.FolderDataBlock[1];
  1925. bulkUpdate.FolderData[0] = new BulkUpdateInventoryPacket.FolderDataBlock();
  1926. bulkUpdate.FolderData[0].FolderID = UUID.Zero;
  1927. bulkUpdate.FolderData[0].ParentID = UUID.Zero;
  1928. bulkUpdate.FolderData[0].Type = -1;
  1929. bulkUpdate.FolderData[0].Name = new byte[0];
  1930. bulkUpdate.ItemData = new BulkUpdateInventoryPacket.ItemDataBlock[1];
  1931. bulkUpdate.ItemData[0] = new BulkUpdateInventoryPacket.ItemDataBlock();
  1932. bulkUpdate.ItemData[0].ItemID = item.ID;
  1933. bulkUpdate.ItemData[0].AssetID = item.AssetID;
  1934. bulkUpdate.ItemData[0].CreatorID = item.CreatorIdAsUuid;
  1935. bulkUpdate.ItemData[0].BaseMask = item.BasePermissions;
  1936. bulkUpdate.ItemData[0].CreationDate = item.CreationDate;
  1937. bulkUpdate.ItemData[0].Description = Util.StringToBytes256(item.Description);
  1938. bulkUpdate.ItemData[0].EveryoneMask = item.EveryOnePermissions;
  1939. bulkUpdate.ItemData[0].FolderID = item.Folder;
  1940. bulkUpdate.ItemData[0].InvType = (sbyte)item.InvType;
  1941. bulkUpdate.ItemData[0].Name = Util.StringToBytes256(item.Name);
  1942. bulkUpdate.ItemData[0].NextOwnerMask = item.NextPermissions;
  1943. bulkUpdate.ItemData[0].OwnerID = item.Owner;
  1944. bulkUpdate.ItemData[0].OwnerMask = item.CurrentPermissions;
  1945. bulkUpdate.ItemData[0].Type = (sbyte)item.AssetType;
  1946. bulkUpdate.ItemData[0].GroupID = item.GroupID;
  1947. bulkUpdate.ItemData[0].GroupOwned = item.GroupOwned;
  1948. bulkUpdate.ItemData[0].GroupMask = item.GroupPermissions;
  1949. bulkUpdate.ItemData[0].Flags = item.Flags & 0x2000ff;
  1950. bulkUpdate.ItemData[0].SalePrice = item.SalePrice;
  1951. bulkUpdate.ItemData[0].SaleType = item.SaleType;
  1952. bulkUpdate.ItemData[0].CRC =
  1953. Helpers.InventoryCRC(1000, 0, bulkUpdate.ItemData[0].InvType,
  1954. bulkUpdate.ItemData[0].Type, bulkUpdate.ItemData[0].AssetID,
  1955. bulkUpdate.ItemData[0].GroupID, 100,
  1956. bulkUpdate.ItemData[0].OwnerID, bulkUpdate.ItemData[0].CreatorID,
  1957. bulkUpdate.ItemData[0].ItemID, bulkUpdate.ItemData[0].FolderID,
  1958. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  1959. FULL_MASK_PERMISSIONS);
  1960. bulkUpdate.Header.Zerocoded = true;
  1961. OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
  1962. }
  1963. public void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId)
  1964. {
  1965. SendInventoryItemCreateUpdate(Item, UUID.Zero, callbackId);
  1966. }
  1967. /// <see>IClientAPI.SendInventoryItemCreateUpdate(InventoryItemBase)</see>
  1968. public void SendInventoryItemCreateUpdate(InventoryItemBase Item, UUID transactionID, uint callbackId)
  1969. {
  1970. const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff;
  1971. UpdateCreateInventoryItemPacket InventoryReply
  1972. = (UpdateCreateInventoryItemPacket)PacketPool.Instance.GetPacket(
  1973. PacketType.UpdateCreateInventoryItem);
  1974. // TODO: don't create new blocks if recycling an old packet
  1975. InventoryReply.AgentData.AgentID = AgentId;
  1976. InventoryReply.AgentData.SimApproved = true;
  1977. InventoryReply.AgentData.TransactionID = transactionID;
  1978. InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
  1979. InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
  1980. InventoryReply.InventoryData[0].ItemID = Item.ID;
  1981. InventoryReply.InventoryData[0].AssetID = Item.AssetID;
  1982. InventoryReply.InventoryData[0].CreatorID = Item.CreatorIdAsUuid;
  1983. InventoryReply.InventoryData[0].BaseMask = Item.BasePermissions;
  1984. InventoryReply.InventoryData[0].Description = Util.StringToBytes256(Item.Description);
  1985. InventoryReply.InventoryData[0].EveryoneMask = Item.EveryOnePermissions;
  1986. InventoryReply.InventoryData[0].FolderID = Item.Folder;
  1987. InventoryReply.InventoryData[0].InvType = (sbyte)Item.InvType;
  1988. InventoryReply.InventoryData[0].Name = Util.StringToBytes256(Item.Name);
  1989. InventoryReply.InventoryData[0].NextOwnerMask = Item.NextPermissions;
  1990. InventoryReply.InventoryData[0].OwnerID = Item.Owner;
  1991. InventoryReply.InventoryData[0].OwnerMask = Item.CurrentPermissions;
  1992. InventoryReply.InventoryData[0].Type = (sbyte)Item.AssetType;
  1993. InventoryReply.InventoryData[0].CallbackID = callbackId;
  1994. InventoryReply.InventoryData[0].GroupID = Item.GroupID;
  1995. InventoryReply.InventoryData[0].GroupOwned = Item.GroupOwned;
  1996. InventoryReply.InventoryData[0].GroupMask = Item.GroupPermissions;
  1997. InventoryReply.InventoryData[0].Flags = Item.Flags & 0x2000ff;
  1998. InventoryReply.InventoryData[0].SalePrice = Item.SalePrice;
  1999. InventoryReply.InventoryData[0].SaleType = Item.SaleType;
  2000. InventoryReply.InventoryData[0].CreationDate = Item.CreationDate;
  2001. InventoryReply.InventoryData[0].CRC =
  2002. Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType,
  2003. InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID,
  2004. InventoryReply.InventoryData[0].GroupID, 100,
  2005. InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID,
  2006. InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID,
  2007. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  2008. FULL_MASK_PERMISSIONS);
  2009. InventoryReply.Header.Zerocoded = true;
  2010. OutPacket(InventoryReply, ThrottleOutPacketType.Asset);
  2011. }
  2012. public void SendRemoveInventoryItem(UUID itemID)
  2013. {
  2014. RemoveInventoryItemPacket remove = (RemoveInventoryItemPacket)PacketPool.Instance.GetPacket(PacketType.RemoveInventoryItem);
  2015. // TODO: don't create new blocks if recycling an old packet
  2016. remove.AgentData.AgentID = AgentId;
  2017. remove.AgentData.SessionID = m_sessionId;
  2018. remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1];
  2019. remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock();
  2020. remove.InventoryData[0].ItemID = itemID;
  2021. remove.Header.Zerocoded = true;
  2022. OutPacket(remove, ThrottleOutPacketType.Asset);
  2023. }
  2024. /*
  2025. private uint adjustControls(int input)
  2026. {
  2027. uint ret = (uint)input;
  2028. uint masked = ret & 0x0f;
  2029. masked <<= 19;
  2030. ret |= masked;
  2031. return ret;
  2032. }
  2033. */
  2034. public void SendTakeControls(int controls, bool passToAgent, bool TakeControls)
  2035. {
  2036. ScriptControlChangePacket scriptcontrol = (ScriptControlChangePacket)PacketPool.Instance.GetPacket(PacketType.ScriptControlChange);
  2037. ScriptControlChangePacket.DataBlock[] data = new ScriptControlChangePacket.DataBlock[1];
  2038. ScriptControlChangePacket.DataBlock ddata = new ScriptControlChangePacket.DataBlock();
  2039. // ddata.Controls = adjustControls(controls);
  2040. ddata.Controls = (uint)controls;
  2041. ddata.PassToAgent = passToAgent;
  2042. ddata.TakeControls = TakeControls;
  2043. data[0] = ddata;
  2044. scriptcontrol.Data = data;
  2045. OutPacket(scriptcontrol, ThrottleOutPacketType.Task);
  2046. }
  2047. public void SendTaskInventory(UUID taskID, short serial, byte[] fileName)
  2048. {
  2049. ReplyTaskInventoryPacket replytask = (ReplyTaskInventoryPacket)PacketPool.Instance.GetPacket(PacketType.ReplyTaskInventory);
  2050. replytask.InventoryData.TaskID = taskID;
  2051. replytask.InventoryData.Serial = serial;
  2052. replytask.InventoryData.Filename = fileName;
  2053. // OutPacket(replytask, ThrottleOutPacketType.Task);
  2054. OutPacket(replytask, ThrottleOutPacketType.Asset);
  2055. }
  2056. public void SendXferPacket(ulong xferID, uint packet, byte[] data, bool isTaskInventory)
  2057. {
  2058. ThrottleOutPacketType type = ThrottleOutPacketType.Asset;
  2059. // if (isTaskInventory)
  2060. // type = ThrottleOutPacketType.Task;
  2061. SendXferPacketPacket sendXfer = (SendXferPacketPacket)PacketPool.Instance.GetPacket(PacketType.SendXferPacket);
  2062. sendXfer.XferID.ID = xferID;
  2063. sendXfer.XferID.Packet = packet;
  2064. sendXfer.DataPacket.Data = data;
  2065. OutPacket(sendXfer, type);
  2066. }
  2067. public void SendAbortXferPacket(ulong xferID)
  2068. {
  2069. AbortXferPacket xferItem = (AbortXferPacket)PacketPool.Instance.GetPacket(PacketType.AbortXfer);
  2070. xferItem.XferID.ID = xferID;
  2071. OutPacket(xferItem, ThrottleOutPacketType.Asset);
  2072. }
  2073. public void SendEconomyData(float EnergyEfficiency, int ObjectCapacity, int ObjectCount, int PriceEnergyUnit,
  2074. int PriceGroupCreate, int PriceObjectClaim, float PriceObjectRent, float PriceObjectScaleFactor,
  2075. int PriceParcelClaim, float PriceParcelClaimFactor, int PriceParcelRent, int PricePublicObjectDecay,
  2076. int PricePublicObjectDelete, int PriceRentLight, int PriceUpload, int TeleportMinPrice, float TeleportPriceExponent)
  2077. {
  2078. EconomyDataPacket economyData = (EconomyDataPacket)PacketPool.Instance.GetPacket(PacketType.EconomyData);
  2079. economyData.Info.EnergyEfficiency = EnergyEfficiency;
  2080. economyData.Info.ObjectCapacity = ObjectCapacity;
  2081. economyData.Info.ObjectCount = ObjectCount;
  2082. economyData.Info.PriceEnergyUnit = PriceEnergyUnit;
  2083. economyData.Info.PriceGroupCreate = PriceGroupCreate;
  2084. economyData.Info.PriceObjectClaim = PriceObjectClaim;
  2085. economyData.Info.PriceObjectRent = PriceObjectRent;
  2086. economyData.Info.PriceObjectScaleFactor = PriceObjectScaleFactor;
  2087. economyData.Info.PriceParcelClaim = PriceParcelClaim;
  2088. economyData.Info.PriceParcelClaimFactor = PriceParcelClaimFactor;
  2089. economyData.Info.PriceParcelRent = PriceParcelRent;
  2090. economyData.Info.PricePublicObjectDecay = PricePublicObjectDecay;
  2091. economyData.Info.PricePublicObjectDelete = PricePublicObjectDelete;
  2092. economyData.Info.PriceRentLight = PriceRentLight;
  2093. economyData.Info.PriceUpload = PriceUpload;
  2094. economyData.Info.TeleportMinPrice = TeleportMinPrice;
  2095. economyData.Info.TeleportPriceExponent = TeleportPriceExponent;
  2096. economyData.Header.Reliable = true;
  2097. OutPacket(economyData, ThrottleOutPacketType.Task);
  2098. }
  2099. public void SendAvatarPickerReply(AvatarPickerReplyAgentDataArgs AgentData, List<AvatarPickerReplyDataArgs> Data)
  2100. {
  2101. //construct the AvatarPickerReply packet.
  2102. AvatarPickerReplyPacket replyPacket = new AvatarPickerReplyPacket();
  2103. replyPacket.AgentData.AgentID = AgentData.AgentID;
  2104. replyPacket.AgentData.QueryID = AgentData.QueryID;
  2105. //int i = 0;
  2106. List<AvatarPickerReplyPacket.DataBlock> data_block = new List<AvatarPickerReplyPacket.DataBlock>();
  2107. foreach (AvatarPickerReplyDataArgs arg in Data)
  2108. {
  2109. AvatarPickerReplyPacket.DataBlock db = new AvatarPickerReplyPacket.DataBlock();
  2110. db.AvatarID = arg.AvatarID;
  2111. db.FirstName = arg.FirstName;
  2112. db.LastName = arg.LastName;
  2113. data_block.Add(db);
  2114. }
  2115. replyPacket.Data = data_block.ToArray();
  2116. OutPacket(replyPacket, ThrottleOutPacketType.Task);
  2117. }
  2118. public void SendAgentDataUpdate(UUID agentid, UUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname, string grouptitle)
  2119. {
  2120. if (agentid == AgentId)
  2121. {
  2122. ActiveGroupId = activegroupid;
  2123. ActiveGroupName = groupname;
  2124. ActiveGroupPowers = grouppowers;
  2125. }
  2126. AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate);
  2127. sendAgentDataUpdate.AgentData.ActiveGroupID = activegroupid;
  2128. sendAgentDataUpdate.AgentData.AgentID = agentid;
  2129. sendAgentDataUpdate.AgentData.FirstName = Util.StringToBytes256(firstname);
  2130. sendAgentDataUpdate.AgentData.GroupName = Util.StringToBytes256(groupname);
  2131. sendAgentDataUpdate.AgentData.GroupPowers = grouppowers;
  2132. sendAgentDataUpdate.AgentData.GroupTitle = Util.StringToBytes256(grouptitle);
  2133. sendAgentDataUpdate.AgentData.LastName = Util.StringToBytes256(lastname);
  2134. OutPacket(sendAgentDataUpdate, ThrottleOutPacketType.Task);
  2135. }
  2136. /// <summary>
  2137. /// Send an alert message to the client. This pops up a brief duration information box at a corner
  2138. /// </summary>
  2139. /// <param name="message"></param>
  2140. public void SendAlertMessage(string message)
  2141. {
  2142. AlertMessagePacket alertPack = (AlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AlertMessage);
  2143. alertPack.AgentInfo = new AlertMessagePacket.AgentInfoBlock[1];
  2144. alertPack.AgentInfo[0] = new AlertMessagePacket.AgentInfoBlock();
  2145. alertPack.AgentInfo[0].AgentID = AgentId;
  2146. alertPack.AlertData = new AlertMessagePacket.AlertDataBlock();
  2147. alertPack.AlertData.Message = Util.StringToBytes256(message);
  2148. alertPack.AlertInfo = new AlertMessagePacket.AlertInfoBlock[0];
  2149. OutPacket(alertPack, ThrottleOutPacketType.Task);
  2150. }
  2151. public void SendAlertMessage(string message, string info)
  2152. {
  2153. AlertMessagePacket alertPack = (AlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AlertMessage);
  2154. alertPack.AgentInfo = new AlertMessagePacket.AgentInfoBlock[1];
  2155. alertPack.AgentInfo[0] = new AlertMessagePacket.AgentInfoBlock();
  2156. alertPack.AgentInfo[0].AgentID = AgentId;
  2157. alertPack.AlertData = new AlertMessagePacket.AlertDataBlock();
  2158. alertPack.AlertData.Message = Util.StringToBytes256(message);
  2159. alertPack.AlertInfo = new AlertMessagePacket.AlertInfoBlock[1];
  2160. alertPack.AlertInfo[0] = new AlertMessagePacket.AlertInfoBlock();
  2161. alertPack.AlertInfo[0].Message = Util.StringToBytes256(info);
  2162. alertPack.AlertInfo[0].ExtraParams = new Byte[0];
  2163. OutPacket(alertPack, ThrottleOutPacketType.Task);
  2164. }
  2165. /// <summary>
  2166. /// Send an agent alert message to the client.
  2167. /// </summary>
  2168. /// <param name="message"></param>
  2169. /// <param name="modal">On the linden client, if this true then it displays a one button text box placed in the
  2170. /// middle of the window. If false, the message is displayed in a brief duration blue information box (as for
  2171. /// the AlertMessage packet).</param>
  2172. public void SendAgentAlertMessage(string message, bool modal)
  2173. {
  2174. // Prepend a slash to make the message come up in the top right
  2175. // again.
  2176. // Allow special formats to be sent from aware modules.
  2177. if (!modal && !message.StartsWith("ALERT: ") && !message.StartsWith("NOTIFY: ") && message != "Home position set." && message != "You died and have been teleported to your home location")
  2178. message = "/" + message;
  2179. AgentAlertMessagePacket alertPack = (AgentAlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AgentAlertMessage);
  2180. alertPack.AgentData.AgentID = AgentId;
  2181. alertPack.AlertData.Message = Util.StringToBytes256(message);
  2182. alertPack.AlertData.Modal = modal;
  2183. OutPacket(alertPack, ThrottleOutPacketType.Task);
  2184. }
  2185. public void SendLoadURL(string objectname, UUID objectID, UUID ownerID, bool groupOwned, string message,
  2186. string url)
  2187. {
  2188. LoadURLPacket loadURL = (LoadURLPacket)PacketPool.Instance.GetPacket(PacketType.LoadURL);
  2189. loadURL.Data.ObjectName = Util.StringToBytes256(objectname);
  2190. loadURL.Data.ObjectID = objectID;
  2191. loadURL.Data.OwnerID = ownerID;
  2192. loadURL.Data.OwnerIsGroup = groupOwned;
  2193. loadURL.Data.Message = Util.StringToBytes256(message);
  2194. loadURL.Data.URL = Util.StringToBytes256(url);
  2195. OutPacket(loadURL, ThrottleOutPacketType.Task);
  2196. }
  2197. public void SendDialog(
  2198. string objectname, UUID objectID, UUID ownerID, string ownerFirstName, string ownerLastName, string msg,
  2199. UUID textureID, int ch, string[] buttonlabels)
  2200. {
  2201. ScriptDialogPacket dialog = (ScriptDialogPacket)PacketPool.Instance.GetPacket(PacketType.ScriptDialog);
  2202. dialog.Data.ObjectID = objectID;
  2203. dialog.Data.ObjectName = Util.StringToBytes256(objectname);
  2204. // this is the username of the *owner*
  2205. dialog.Data.FirstName = Util.StringToBytes256(ownerFirstName);
  2206. dialog.Data.LastName = Util.StringToBytes256(ownerLastName);
  2207. dialog.Data.Message = Util.StringToBytes(msg,512);
  2208. dialog.Data.ImageID = textureID;
  2209. dialog.Data.ChatChannel = ch;
  2210. ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[buttonlabels.Length];
  2211. for (int i = 0; i < buttonlabels.Length; i++)
  2212. {
  2213. buttons[i] = new ScriptDialogPacket.ButtonsBlock();
  2214. buttons[i].ButtonLabel = Util.StringToBytes(buttonlabels[i],24);
  2215. }
  2216. dialog.Buttons = buttons;
  2217. dialog.OwnerData = new ScriptDialogPacket.OwnerDataBlock[1];
  2218. dialog.OwnerData[0] = new ScriptDialogPacket.OwnerDataBlock();
  2219. dialog.OwnerData[0].OwnerID = ownerID;
  2220. OutPacket(dialog, ThrottleOutPacketType.Task);
  2221. }
  2222. public void SendPreLoadSound(UUID objectID, UUID ownerID, UUID soundID)
  2223. {
  2224. PreloadSoundPacket preSound = (PreloadSoundPacket)PacketPool.Instance.GetPacket(PacketType.PreloadSound);
  2225. // TODO: don't create new blocks if recycling an old packet
  2226. preSound.DataBlock = new PreloadSoundPacket.DataBlockBlock[1];
  2227. preSound.DataBlock[0] = new PreloadSoundPacket.DataBlockBlock();
  2228. preSound.DataBlock[0].ObjectID = objectID;
  2229. preSound.DataBlock[0].OwnerID = ownerID;
  2230. preSound.DataBlock[0].SoundID = soundID;
  2231. preSound.Header.Zerocoded = true;
  2232. OutPacket(preSound, ThrottleOutPacketType.Task);
  2233. }
  2234. public void SendPlayAttachedSound(UUID soundID, UUID objectID, UUID ownerID, float gain, byte flags)
  2235. {
  2236. AttachedSoundPacket sound = (AttachedSoundPacket)PacketPool.Instance.GetPacket(PacketType.AttachedSound);
  2237. sound.DataBlock.SoundID = soundID;
  2238. sound.DataBlock.ObjectID = objectID;
  2239. sound.DataBlock.OwnerID = ownerID;
  2240. sound.DataBlock.Gain = gain;
  2241. sound.DataBlock.Flags = flags;
  2242. OutPacket(sound, ThrottleOutPacketType.Task);
  2243. }
  2244. public void SendTransferAbort(TransferRequestPacket transferRequest)
  2245. {
  2246. TransferAbortPacket abort = (TransferAbortPacket)PacketPool.Instance.GetPacket(PacketType.TransferAbort);
  2247. abort.TransferInfo.TransferID = transferRequest.TransferInfo.TransferID;
  2248. abort.TransferInfo.ChannelType = transferRequest.TransferInfo.ChannelType;
  2249. m_log.Debug("[Assets] Aborting transfer; asset request failed");
  2250. OutPacket(abort, ThrottleOutPacketType.Task);
  2251. }
  2252. public void SendTriggeredSound(UUID soundID, UUID ownerID, UUID objectID, UUID parentID, ulong handle, Vector3 position, float gain)
  2253. {
  2254. SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger);
  2255. sound.SoundData.SoundID = soundID;
  2256. sound.SoundData.OwnerID = ownerID;
  2257. sound.SoundData.ObjectID = objectID;
  2258. sound.SoundData.ParentID = parentID;
  2259. sound.SoundData.Handle = handle;
  2260. sound.SoundData.Position = position;
  2261. sound.SoundData.Gain = gain;
  2262. OutPacket(sound, ThrottleOutPacketType.Task);
  2263. }
  2264. public void SendAttachedSoundGainChange(UUID objectID, float gain)
  2265. {
  2266. AttachedSoundGainChangePacket sound = (AttachedSoundGainChangePacket)PacketPool.Instance.GetPacket(PacketType.AttachedSoundGainChange);
  2267. sound.DataBlock.ObjectID = objectID;
  2268. sound.DataBlock.Gain = gain;
  2269. OutPacket(sound, ThrottleOutPacketType.Task);
  2270. }
  2271. public void SendSunPos(Vector3 Position, Vector3 Velocity, ulong CurrentTime, uint SecondsPerSunCycle, uint SecondsPerYear, float OrbitalPosition)
  2272. {
  2273. // Viewers based on the Linden viwer code, do wacky things for oribital positions from Midnight to Sunrise
  2274. // So adjust for that
  2275. // Contributed by: Godfrey
  2276. if (OrbitalPosition > m_sunPainDaHalfOrbitalCutoff) // things get weird from midnight to sunrise
  2277. {
  2278. OrbitalPosition = (OrbitalPosition - m_sunPainDaHalfOrbitalCutoff) * 0.6666666667f + m_sunPainDaHalfOrbitalCutoff;
  2279. }
  2280. SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
  2281. viewertime.TimeInfo.SunDirection = Position;
  2282. viewertime.TimeInfo.SunAngVelocity = Velocity;
  2283. // Sun module used to add 6 hours to adjust for linden sun hour, adding here
  2284. // to prevent existing code from breaking if it assumed that 6 hours were included.
  2285. // 21600 == 6 hours * 60 minutes * 60 Seconds
  2286. viewertime.TimeInfo.UsecSinceStart = CurrentTime + 21600;
  2287. viewertime.TimeInfo.SecPerDay = SecondsPerSunCycle;
  2288. viewertime.TimeInfo.SecPerYear = SecondsPerYear;
  2289. viewertime.TimeInfo.SunPhase = OrbitalPosition;
  2290. viewertime.Header.Reliable = false;
  2291. viewertime.Header.Zerocoded = true;
  2292. OutPacket(viewertime, ThrottleOutPacketType.Task);
  2293. }
  2294. // Currently Deprecated
  2295. public void SendViewerTime(int phase)
  2296. {
  2297. /*
  2298. Console.WriteLine("SunPhase: {0}", phase);
  2299. SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
  2300. //viewertime.TimeInfo.SecPerDay = 86400;
  2301. //viewertime.TimeInfo.SecPerYear = 31536000;
  2302. viewertime.TimeInfo.SecPerDay = 1000;
  2303. viewertime.TimeInfo.SecPerYear = 365000;
  2304. viewertime.TimeInfo.SunPhase = 1;
  2305. int sunPhase = (phase + 2) / 2;
  2306. if ((sunPhase < 6) || (sunPhase > 36))
  2307. {
  2308. viewertime.TimeInfo.SunDirection = new Vector3(0f, 0.8f, -0.8f);
  2309. Console.WriteLine("sending night");
  2310. }
  2311. else
  2312. {
  2313. if (sunPhase < 12)
  2314. {
  2315. sunPhase = 12;
  2316. }
  2317. sunPhase = sunPhase - 12;
  2318. float yValue = 0.1f * (sunPhase);
  2319. Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
  2320. if (yValue > 1.2f)
  2321. {
  2322. yValue = yValue - 1.2f;
  2323. }
  2324. yValue = Util.Clip(yValue, 0, 1);
  2325. if (sunPhase < 14)
  2326. {
  2327. yValue = 1 - yValue;
  2328. }
  2329. if (sunPhase < 12)
  2330. {
  2331. yValue *= -1;
  2332. }
  2333. viewertime.TimeInfo.SunDirection = new Vector3(0f, yValue, 0.3f);
  2334. Console.WriteLine("sending sun update " + yValue);
  2335. }
  2336. viewertime.TimeInfo.SunAngVelocity = new Vector3(0, 0.0f, 10.0f);
  2337. viewertime.TimeInfo.UsecSinceStart = (ulong)Util.UnixTimeSinceEpoch();
  2338. viewertime.Header.Reliable = false;
  2339. OutPacket(viewertime, ThrottleOutPacketType.Task);
  2340. */
  2341. }
  2342. public void SendViewerEffect(ViewerEffectPacket.EffectBlock[] effectBlocks)
  2343. {
  2344. ViewerEffectPacket packet = (ViewerEffectPacket)PacketPool.Instance.GetPacket(PacketType.ViewerEffect);
  2345. // packet.AgentData.AgentID = AgentId;
  2346. // packet.AgentData.SessionID = SessionId;
  2347. packet.Effect = effectBlocks;
  2348. // OutPacket(packet, ThrottleOutPacketType.State);
  2349. OutPacket(packet, ThrottleOutPacketType.Task);
  2350. }
  2351. public void SendAvatarProperties(UUID avatarID, string aboutText, string bornOn, Byte[] membershipType,
  2352. string flAbout, uint flags, UUID flImageID, UUID imageID, string profileURL,
  2353. UUID partnerID)
  2354. {
  2355. AvatarPropertiesReplyPacket avatarReply = (AvatarPropertiesReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPropertiesReply);
  2356. avatarReply.AgentData.AgentID = AgentId;
  2357. avatarReply.AgentData.AvatarID = avatarID;
  2358. if (aboutText != null)
  2359. avatarReply.PropertiesData.AboutText = Util.StringToBytes1024(aboutText);
  2360. else
  2361. avatarReply.PropertiesData.AboutText = Utils.EmptyBytes;
  2362. avatarReply.PropertiesData.BornOn = Util.StringToBytes256(bornOn);
  2363. avatarReply.PropertiesData.CharterMember = membershipType;
  2364. if (flAbout != null)
  2365. avatarReply.PropertiesData.FLAboutText = Util.StringToBytes256(flAbout);
  2366. else
  2367. avatarReply.PropertiesData.FLAboutText = Utils.EmptyBytes;
  2368. avatarReply.PropertiesData.Flags = flags;
  2369. avatarReply.PropertiesData.FLImageID = flImageID;
  2370. avatarReply.PropertiesData.ImageID = imageID;
  2371. avatarReply.PropertiesData.ProfileURL = Util.StringToBytes256(profileURL);
  2372. avatarReply.PropertiesData.PartnerID = partnerID;
  2373. OutPacket(avatarReply, ThrottleOutPacketType.Task);
  2374. }
  2375. /// <summary>
  2376. /// Send the client an Estate message blue box pop-down with a single OK button
  2377. /// </summary>
  2378. /// <param name="FromAvatarID"></param>
  2379. /// <param name="fromSessionID"></param>
  2380. /// <param name="FromAvatarName"></param>
  2381. /// <param name="Message"></param>
  2382. public void SendBlueBoxMessage(UUID FromAvatarID, String FromAvatarName, String Message)
  2383. {
  2384. if (!SceneAgent.IsChildAgent)
  2385. SendInstantMessage(new GridInstantMessage(null, FromAvatarID, FromAvatarName, AgentId, 1, Message, false, new Vector3()));
  2386. //SendInstantMessage(FromAvatarID, fromSessionID, Message, AgentId, SessionId, FromAvatarName, (byte)21,(uint) Util.UnixTimeSinceEpoch());
  2387. }
  2388. public void SendLogoutPacket()
  2389. {
  2390. // I know this is a bit of a hack, however there are times when you don't
  2391. // want to send this, but still need to do the rest of the shutdown process
  2392. // this method gets called from the packet server.. which makes it practically
  2393. // impossible to do any other way.
  2394. if (m_SendLogoutPacketWhenClosing)
  2395. {
  2396. LogoutReplyPacket logReply = (LogoutReplyPacket)PacketPool.Instance.GetPacket(PacketType.LogoutReply);
  2397. // TODO: don't create new blocks if recycling an old packet
  2398. logReply.AgentData.AgentID = AgentId;
  2399. logReply.AgentData.SessionID = SessionId;
  2400. logReply.InventoryData = new LogoutReplyPacket.InventoryDataBlock[1];
  2401. logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock();
  2402. logReply.InventoryData[0].ItemID = UUID.Zero;
  2403. OutPacket(logReply, ThrottleOutPacketType.Task);
  2404. }
  2405. }
  2406. public void SendHealth(float health)
  2407. {
  2408. HealthMessagePacket healthpacket = (HealthMessagePacket)PacketPool.Instance.GetPacket(PacketType.HealthMessage);
  2409. healthpacket.HealthData.Health = health;
  2410. OutPacket(healthpacket, ThrottleOutPacketType.Task);
  2411. }
  2412. public void SendAgentOnline(UUID[] agentIDs)
  2413. {
  2414. OnlineNotificationPacket onp = new OnlineNotificationPacket();
  2415. OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[agentIDs.Length];
  2416. for (int i = 0; i < agentIDs.Length; i++)
  2417. {
  2418. OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock();
  2419. onpbl.AgentID = agentIDs[i];
  2420. onpb[i] = onpbl;
  2421. }
  2422. onp.AgentBlock = onpb;
  2423. onp.Header.Reliable = true;
  2424. OutPacket(onp, ThrottleOutPacketType.Task);
  2425. }
  2426. public void SendAgentOffline(UUID[] agentIDs)
  2427. {
  2428. OfflineNotificationPacket offp = new OfflineNotificationPacket();
  2429. OfflineNotificationPacket.AgentBlockBlock[] offpb = new OfflineNotificationPacket.AgentBlockBlock[agentIDs.Length];
  2430. for (int i = 0; i < agentIDs.Length; i++)
  2431. {
  2432. OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock();
  2433. onpbl.AgentID = agentIDs[i];
  2434. offpb[i] = onpbl;
  2435. }
  2436. offp.AgentBlock = offpb;
  2437. offp.Header.Reliable = true;
  2438. OutPacket(offp, ThrottleOutPacketType.Task);
  2439. }
  2440. public void SendFindAgent(UUID HunterID, UUID PreyID, double GlobalX, double GlobalY)
  2441. {
  2442. FindAgentPacket fap = new FindAgentPacket();
  2443. fap.AgentBlock.Hunter = HunterID;
  2444. fap.AgentBlock.Prey = PreyID;
  2445. fap.AgentBlock.SpaceIP = 0;
  2446. fap.LocationBlock = new FindAgentPacket.LocationBlockBlock[1];
  2447. fap.LocationBlock[0] = new FindAgentPacket.LocationBlockBlock();
  2448. fap.LocationBlock[0].GlobalX = GlobalX;
  2449. fap.LocationBlock[0].GlobalY = GlobalY;
  2450. OutPacket(fap, ThrottleOutPacketType.Task);
  2451. }
  2452. public void SendSitResponse(UUID TargetID, Vector3 OffsetPos,
  2453. Quaternion SitOrientation, bool autopilot,
  2454. Vector3 CameraAtOffset, Vector3 CameraEyeOffset, bool ForceMouseLook)
  2455. {
  2456. AvatarSitResponsePacket avatarSitResponse = new AvatarSitResponsePacket();
  2457. avatarSitResponse.SitObject.ID = TargetID;
  2458. avatarSitResponse.SitTransform.CameraAtOffset = CameraAtOffset;
  2459. avatarSitResponse.SitTransform.CameraEyeOffset = CameraEyeOffset;
  2460. avatarSitResponse.SitTransform.ForceMouselook = ForceMouseLook;
  2461. avatarSitResponse.SitTransform.AutoPilot = autopilot;
  2462. avatarSitResponse.SitTransform.SitPosition = OffsetPos;
  2463. avatarSitResponse.SitTransform.SitRotation = SitOrientation;
  2464. OutPacket(avatarSitResponse, ThrottleOutPacketType.Task);
  2465. }
  2466. public void SendAdminResponse(UUID Token, uint AdminLevel)
  2467. {
  2468. GrantGodlikePowersPacket respondPacket = new GrantGodlikePowersPacket();
  2469. GrantGodlikePowersPacket.GrantDataBlock gdb = new GrantGodlikePowersPacket.GrantDataBlock();
  2470. GrantGodlikePowersPacket.AgentDataBlock adb = new GrantGodlikePowersPacket.AgentDataBlock();
  2471. adb.AgentID = AgentId;
  2472. adb.SessionID = SessionId; // More security
  2473. gdb.GodLevel = (byte)AdminLevel;
  2474. gdb.Token = Token;
  2475. //respondPacket.AgentData = (GrantGodlikePowersPacket.AgentDataBlock)ablock;
  2476. respondPacket.GrantData = gdb;
  2477. respondPacket.AgentData = adb;
  2478. OutPacket(respondPacket, ThrottleOutPacketType.Task);
  2479. }
  2480. public void SendGroupMembership(GroupMembershipData[] GroupMembership)
  2481. {
  2482. UpdateGroupMembership(GroupMembership);
  2483. SendAgentGroupDataUpdate(AgentId,GroupMembership);
  2484. }
  2485. public void SendSelectedPartsProprieties(List<ISceneEntity> parts)
  2486. {
  2487. /* not in use
  2488. // udp part
  2489. ObjectPropertiesPacket packet =
  2490. (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties);
  2491. ObjectPropertiesPacket.ObjectDataBlock[] ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[parts.Count];
  2492. int i = 0;
  2493. foreach(SceneObjectPart sop in parts)
  2494. ObjectData[i++] = CreateObjectPropertiesBlock(sop);
  2495. packet.ObjectData = ObjectData;
  2496. packet.Header.Zerocoded = true;
  2497. // udp send splits this mega packets correctly
  2498. // mb later will avoid that to reduce gc stress
  2499. OutPacket(packet, ThrottleOutPacketType.Task, true);
  2500. // caps physics part
  2501. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  2502. if(eq == null)
  2503. return;
  2504. OSDArray array = new OSDArray();
  2505. foreach(SceneObjectPart sop in parts)
  2506. {
  2507. OSDMap physinfo = new OSDMap(6);
  2508. physinfo["LocalID"] = sop.LocalId;
  2509. physinfo["Density"] = sop.Density;
  2510. physinfo["Friction"] = sop.Friction;
  2511. physinfo["GravityMultiplier"] = sop.GravityModifier;
  2512. physinfo["Restitution"] = sop.Restitution;
  2513. physinfo["PhysicsShapeType"] = (int)sop.PhysicsShapeType;
  2514. array.Add(physinfo);
  2515. }
  2516. OSDMap llsdBody = new OSDMap(1);
  2517. llsdBody.Add("ObjectData", array);
  2518. eq.Enqueue(BuildEvent("ObjectPhysicsProperties", llsdBody),AgentId);
  2519. */
  2520. }
  2521. public void SendPartPhysicsProprieties(ISceneEntity entity)
  2522. {
  2523. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  2524. if (eq == null)
  2525. return;
  2526. SceneObjectPart part = (SceneObjectPart)entity;
  2527. if (part == null)
  2528. return;
  2529. uint localid = part.LocalId;
  2530. byte physshapetype = part.PhysicsShapeType;
  2531. float density = part.Density;
  2532. float friction = part.Friction;
  2533. float bounce = part.Restitution;
  2534. float gravmod = part.GravityModifier;
  2535. eq.partPhysicsProperties(localid, physshapetype, density, friction, bounce, gravmod,AgentId);
  2536. }
  2537. public void SendGroupNameReply(UUID groupLLUID, string GroupName)
  2538. {
  2539. UUIDGroupNameReplyPacket pack = new UUIDGroupNameReplyPacket();
  2540. UUIDGroupNameReplyPacket.UUIDNameBlockBlock[] uidnameblock = new UUIDGroupNameReplyPacket.UUIDNameBlockBlock[1];
  2541. UUIDGroupNameReplyPacket.UUIDNameBlockBlock uidnamebloc = new UUIDGroupNameReplyPacket.UUIDNameBlockBlock();
  2542. uidnamebloc.ID = groupLLUID;
  2543. uidnamebloc.GroupName = Util.StringToBytes256(GroupName);
  2544. uidnameblock[0] = uidnamebloc;
  2545. pack.UUIDNameBlock = uidnameblock;
  2546. OutPacket(pack, ThrottleOutPacketType.Task);
  2547. }
  2548. public void SendLandStatReply(uint reportType, uint requestFlags, uint resultCount, LandStatReportItem[] lsrpia)
  2549. {
  2550. LandStatReplyPacket lsrp = new LandStatReplyPacket();
  2551. // LandStatReplyPacket.RequestDataBlock lsreqdpb = new LandStatReplyPacket.RequestDataBlock();
  2552. LandStatReplyPacket.ReportDataBlock[] lsrepdba = new LandStatReplyPacket.ReportDataBlock[lsrpia.Length];
  2553. //LandStatReplyPacket.ReportDataBlock lsrepdb = new LandStatReplyPacket.ReportDataBlock();
  2554. // lsrepdb.
  2555. lsrp.RequestData.ReportType = reportType;
  2556. lsrp.RequestData.RequestFlags = requestFlags;
  2557. lsrp.RequestData.TotalObjectCount = resultCount;
  2558. for (int i = 0; i < lsrpia.Length; i++)
  2559. {
  2560. LandStatReplyPacket.ReportDataBlock lsrepdb = new LandStatReplyPacket.ReportDataBlock();
  2561. lsrepdb.LocationX = lsrpia[i].LocationX;
  2562. lsrepdb.LocationY = lsrpia[i].LocationY;
  2563. lsrepdb.LocationZ = lsrpia[i].LocationZ;
  2564. lsrepdb.Score = lsrpia[i].Score;
  2565. lsrepdb.TaskID = lsrpia[i].TaskID;
  2566. lsrepdb.TaskLocalID = lsrpia[i].TaskLocalID;
  2567. lsrepdb.TaskName = Util.StringToBytes256(lsrpia[i].TaskName);
  2568. lsrepdb.OwnerName = Util.StringToBytes256(lsrpia[i].OwnerName);
  2569. lsrepdba[i] = lsrepdb;
  2570. }
  2571. lsrp.ReportData = lsrepdba;
  2572. OutPacket(lsrp, ThrottleOutPacketType.Task);
  2573. }
  2574. public void SendScriptRunningReply(UUID objectID, UUID itemID, bool running)
  2575. {
  2576. ScriptRunningReplyPacket scriptRunningReply = new ScriptRunningReplyPacket();
  2577. scriptRunningReply.Script.ObjectID = objectID;
  2578. scriptRunningReply.Script.ItemID = itemID;
  2579. scriptRunningReply.Script.Running = running;
  2580. OutPacket(scriptRunningReply, ThrottleOutPacketType.Task);
  2581. }
  2582. public void SendAsset(AssetRequestToClient req)
  2583. {
  2584. if (req.AssetInf == null)
  2585. {
  2586. m_log.ErrorFormat("{0} Cannot send asset {1} ({2}), asset is null",
  2587. LogHeader);
  2588. return;
  2589. }
  2590. if (req.AssetInf.Data == null)
  2591. {
  2592. m_log.ErrorFormat("{0} Cannot send asset {1} ({2}), asset data is null",
  2593. LogHeader, req.AssetInf.ID, req.AssetInf.Metadata.ContentType);
  2594. return;
  2595. }
  2596. bool isWearable = false;
  2597. isWearable = ((AssetType) req.AssetInf.Type ==
  2598. AssetType.Bodypart || (AssetType) req.AssetInf.Type == AssetType.Clothing);
  2599. //m_log.Debug("sending asset " + req.RequestAssetID + ", iswearable: " + isWearable);
  2600. //if (isWearable)
  2601. // m_log.Debug((AssetType)req.AssetInf.Type);
  2602. TransferInfoPacket Transfer = new TransferInfoPacket();
  2603. Transfer.TransferInfo.ChannelType = 2;
  2604. Transfer.TransferInfo.Status = 0;
  2605. Transfer.TransferInfo.TargetType = 0;
  2606. if (req.AssetRequestSource == 2)
  2607. {
  2608. Transfer.TransferInfo.Params = new byte[20];
  2609. Array.Copy(req.RequestAssetID.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
  2610. int assType = req.AssetInf.Type;
  2611. Array.Copy(Utils.IntToBytes(assType), 0, Transfer.TransferInfo.Params, 16, 4);
  2612. }
  2613. else if (req.AssetRequestSource == 3)
  2614. {
  2615. Transfer.TransferInfo.Params = req.Params;
  2616. // Transfer.TransferInfo.Params = new byte[100];
  2617. //Array.Copy(req.RequestUser.AgentId.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
  2618. //Array.Copy(req.RequestUser.SessionId.GetBytes(), 0, Transfer.TransferInfo.Params, 16, 16);
  2619. }
  2620. Transfer.TransferInfo.Size = req.AssetInf.Data.Length;
  2621. Transfer.TransferInfo.TransferID = req.TransferRequestID;
  2622. Transfer.Header.Zerocoded = true;
  2623. OutPacket(Transfer, isWearable ? ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority : ThrottleOutPacketType.Asset);
  2624. if (req.NumPackets == 1)
  2625. {
  2626. TransferPacketPacket TransferPacket = new TransferPacketPacket();
  2627. TransferPacket.TransferData.Packet = 0;
  2628. TransferPacket.TransferData.ChannelType = 2;
  2629. TransferPacket.TransferData.TransferID = req.TransferRequestID;
  2630. TransferPacket.TransferData.Data = req.AssetInf.Data;
  2631. TransferPacket.TransferData.Status = 1;
  2632. TransferPacket.Header.Zerocoded = true;
  2633. OutPacket(TransferPacket, isWearable ? ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority : ThrottleOutPacketType.Asset);
  2634. }
  2635. else
  2636. {
  2637. int processedLength = 0;
  2638. // int maxChunkSize = Settings.MAX_PACKET_SIZE - 100;
  2639. int maxChunkSize = (int) MaxTransferBytesPerPacket;
  2640. int packetNumber = 0;
  2641. while (processedLength < req.AssetInf.Data.Length)
  2642. {
  2643. TransferPacketPacket TransferPacket = new TransferPacketPacket();
  2644. TransferPacket.TransferData.Packet = packetNumber;
  2645. TransferPacket.TransferData.ChannelType = 2;
  2646. TransferPacket.TransferData.TransferID = req.TransferRequestID;
  2647. int chunkSize = Math.Min(req.AssetInf.Data.Length - processedLength, maxChunkSize);
  2648. byte[] chunk = new byte[chunkSize];
  2649. Array.Copy(req.AssetInf.Data, processedLength, chunk, 0, chunk.Length);
  2650. TransferPacket.TransferData.Data = chunk;
  2651. // 0 indicates more packets to come, 1 indicates last packet
  2652. if (req.AssetInf.Data.Length - processedLength > maxChunkSize)
  2653. {
  2654. TransferPacket.TransferData.Status = 0;
  2655. }
  2656. else
  2657. {
  2658. TransferPacket.TransferData.Status = 1;
  2659. }
  2660. TransferPacket.Header.Zerocoded = true;
  2661. OutPacket(TransferPacket, isWearable ? ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority : ThrottleOutPacketType.Asset);
  2662. processedLength += chunkSize;
  2663. packetNumber++;
  2664. }
  2665. }
  2666. }
  2667. public void SendAssetNotFound(AssetRequestToClient req)
  2668. {
  2669. TransferInfoPacket Transfer = new TransferInfoPacket();
  2670. Transfer.TransferInfo.ChannelType = 2;
  2671. Transfer.TransferInfo.Status = -2;
  2672. Transfer.TransferInfo.TargetType = 0;
  2673. Transfer.TransferInfo.Params = req.Params;
  2674. Transfer.TransferInfo.Size = 0;
  2675. Transfer.TransferInfo.TransferID = req.TransferRequestID;
  2676. Transfer.Header.Zerocoded = true;
  2677. OutPacket(Transfer, ThrottleOutPacketType.Asset);
  2678. }
  2679. public void SendTexture(AssetBase TextureAsset)
  2680. {
  2681. }
  2682. public void SendRegionHandle(UUID regionID, ulong handle)
  2683. {
  2684. RegionIDAndHandleReplyPacket reply = (RegionIDAndHandleReplyPacket)PacketPool.Instance.GetPacket(PacketType.RegionIDAndHandleReply);
  2685. reply.ReplyBlock.RegionID = regionID;
  2686. reply.ReplyBlock.RegionHandle = handle;
  2687. OutPacket(reply, ThrottleOutPacketType.Land);
  2688. }
  2689. public void SendParcelInfo(RegionInfo info, LandData land, UUID parcelID, uint x, uint y)
  2690. {
  2691. ParcelInfoReplyPacket reply = (ParcelInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelInfoReply);
  2692. reply.AgentData.AgentID = m_agentId;
  2693. reply.Data.ParcelID = parcelID;
  2694. reply.Data.OwnerID = land.OwnerID;
  2695. reply.Data.Name = Utils.StringToBytes(land.Name);
  2696. if (land.Description != null && land.Description != String.Empty)
  2697. reply.Data.Desc = Utils.StringToBytes(land.Description.Substring(0, land.Description.Length > 254 ? 254: land.Description.Length));
  2698. else
  2699. reply.Data.Desc = new Byte[0];
  2700. reply.Data.ActualArea = land.Area;
  2701. reply.Data.BillableArea = land.Area; // TODO: what is this?
  2702. reply.Data.Flags = (byte)Util.ConvertAccessLevelToMaturity((byte)info.AccessLevel);
  2703. if((land.Flags & (uint)ParcelFlags.ForSale) != 0)
  2704. reply.Data.Flags |= (byte)((1 << 7));
  2705. Vector3 pos = land.UserLocation;
  2706. if (pos.Equals(Vector3.Zero))
  2707. {
  2708. pos = (land.AABBMax + land.AABBMin) * 0.5f;
  2709. }
  2710. reply.Data.GlobalX = info.RegionLocX + x;
  2711. reply.Data.GlobalY = info.RegionLocY + y;
  2712. reply.Data.GlobalZ = pos.Z;
  2713. reply.Data.SimName = Utils.StringToBytes(info.RegionName);
  2714. reply.Data.SnapshotID = land.SnapshotID;
  2715. reply.Data.Dwell = land.Dwell;
  2716. reply.Data.SalePrice = land.SalePrice;
  2717. reply.Data.AuctionID = (int)land.AuctionID;
  2718. OutPacket(reply, ThrottleOutPacketType.Land);
  2719. }
  2720. public void SendScriptTeleportRequest(string objName, string simName, Vector3 pos, Vector3 lookAt)
  2721. {
  2722. ScriptTeleportRequestPacket packet = (ScriptTeleportRequestPacket)PacketPool.Instance.GetPacket(PacketType.ScriptTeleportRequest);
  2723. packet.Data.ObjectName = Utils.StringToBytes(objName);
  2724. packet.Data.SimName = Utils.StringToBytes(simName);
  2725. packet.Data.SimPosition = pos;
  2726. packet.Data.LookAt = lookAt;
  2727. OutPacket(packet, ThrottleOutPacketType.Task);
  2728. }
  2729. public void SendDirPlacesReply(UUID queryID, DirPlacesReplyData[] data)
  2730. {
  2731. DirPlacesReplyPacket packet = (DirPlacesReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPlacesReply);
  2732. packet.AgentData = new DirPlacesReplyPacket.AgentDataBlock();
  2733. packet.QueryData = new DirPlacesReplyPacket.QueryDataBlock[1];
  2734. packet.QueryData[0] = new DirPlacesReplyPacket.QueryDataBlock();
  2735. packet.AgentData.AgentID = AgentId;
  2736. packet.QueryData[0].QueryID = queryID;
  2737. DirPlacesReplyPacket.QueryRepliesBlock[] replies =
  2738. new DirPlacesReplyPacket.QueryRepliesBlock[0];
  2739. DirPlacesReplyPacket.StatusDataBlock[] status =
  2740. new DirPlacesReplyPacket.StatusDataBlock[0];
  2741. packet.QueryReplies = replies;
  2742. packet.StatusData = status;
  2743. foreach (DirPlacesReplyData d in data)
  2744. {
  2745. int idx = replies.Length;
  2746. Array.Resize(ref replies, idx + 1);
  2747. Array.Resize(ref status, idx + 1);
  2748. replies[idx] = new DirPlacesReplyPacket.QueryRepliesBlock();
  2749. status[idx] = new DirPlacesReplyPacket.StatusDataBlock();
  2750. replies[idx].ParcelID = d.parcelID;
  2751. replies[idx].Name = Utils.StringToBytes(d.name);
  2752. replies[idx].ForSale = d.forSale;
  2753. replies[idx].Auction = d.auction;
  2754. replies[idx].Dwell = d.dwell;
  2755. status[idx].Status = d.Status;
  2756. packet.QueryReplies = replies;
  2757. packet.StatusData = status;
  2758. if (packet.Length >= 1000)
  2759. {
  2760. OutPacket(packet, ThrottleOutPacketType.Task);
  2761. packet = (DirPlacesReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPlacesReply);
  2762. packet.AgentData = new DirPlacesReplyPacket.AgentDataBlock();
  2763. packet.QueryData = new DirPlacesReplyPacket.QueryDataBlock[1];
  2764. packet.QueryData[0] = new DirPlacesReplyPacket.QueryDataBlock();
  2765. packet.AgentData.AgentID = AgentId;
  2766. packet.QueryData[0].QueryID = queryID;
  2767. replies = new DirPlacesReplyPacket.QueryRepliesBlock[0];
  2768. status = new DirPlacesReplyPacket.StatusDataBlock[0];
  2769. }
  2770. }
  2771. if (replies.Length > 0 || data.Length == 0)
  2772. OutPacket(packet, ThrottleOutPacketType.Task);
  2773. }
  2774. public void SendDirPeopleReply(UUID queryID, DirPeopleReplyData[] data)
  2775. {
  2776. DirPeopleReplyPacket packet = (DirPeopleReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPeopleReply);
  2777. packet.AgentData = new DirPeopleReplyPacket.AgentDataBlock();
  2778. packet.AgentData.AgentID = AgentId;
  2779. packet.QueryData = new DirPeopleReplyPacket.QueryDataBlock();
  2780. packet.QueryData.QueryID = queryID;
  2781. packet.QueryReplies = new DirPeopleReplyPacket.QueryRepliesBlock[
  2782. data.Length];
  2783. int i = 0;
  2784. foreach (DirPeopleReplyData d in data)
  2785. {
  2786. packet.QueryReplies[i] = new DirPeopleReplyPacket.QueryRepliesBlock();
  2787. packet.QueryReplies[i].AgentID = d.agentID;
  2788. packet.QueryReplies[i].FirstName =
  2789. Utils.StringToBytes(d.firstName);
  2790. packet.QueryReplies[i].LastName =
  2791. Utils.StringToBytes(d.lastName);
  2792. packet.QueryReplies[i].Group =
  2793. Utils.StringToBytes(d.group);
  2794. packet.QueryReplies[i].Online = d.online;
  2795. packet.QueryReplies[i].Reputation = d.reputation;
  2796. i++;
  2797. }
  2798. OutPacket(packet, ThrottleOutPacketType.Task);
  2799. }
  2800. public void SendDirEventsReply(UUID queryID, DirEventsReplyData[] data)
  2801. {
  2802. DirEventsReplyPacket packet = (DirEventsReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirEventsReply);
  2803. packet.AgentData = new DirEventsReplyPacket.AgentDataBlock();
  2804. packet.AgentData.AgentID = AgentId;
  2805. packet.QueryData = new DirEventsReplyPacket.QueryDataBlock();
  2806. packet.QueryData.QueryID = queryID;
  2807. packet.QueryReplies = new DirEventsReplyPacket.QueryRepliesBlock[
  2808. data.Length];
  2809. packet.StatusData = new DirEventsReplyPacket.StatusDataBlock[
  2810. data.Length];
  2811. int i = 0;
  2812. foreach (DirEventsReplyData d in data)
  2813. {
  2814. packet.QueryReplies[i] = new DirEventsReplyPacket.QueryRepliesBlock();
  2815. packet.StatusData[i] = new DirEventsReplyPacket.StatusDataBlock();
  2816. packet.QueryReplies[i].OwnerID = d.ownerID;
  2817. packet.QueryReplies[i].Name =
  2818. Utils.StringToBytes(d.name);
  2819. packet.QueryReplies[i].EventID = d.eventID;
  2820. packet.QueryReplies[i].Date =
  2821. Utils.StringToBytes(d.date);
  2822. packet.QueryReplies[i].UnixTime = d.unixTime;
  2823. packet.QueryReplies[i].EventFlags = d.eventFlags;
  2824. packet.StatusData[i].Status = d.Status;
  2825. i++;
  2826. }
  2827. OutPacket(packet, ThrottleOutPacketType.Task);
  2828. }
  2829. public void SendDirGroupsReply(UUID queryID, DirGroupsReplyData[] data)
  2830. {
  2831. DirGroupsReplyPacket packet = (DirGroupsReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirGroupsReply);
  2832. packet.AgentData = new DirGroupsReplyPacket.AgentDataBlock();
  2833. packet.AgentData.AgentID = AgentId;
  2834. packet.QueryData = new DirGroupsReplyPacket.QueryDataBlock();
  2835. packet.QueryData.QueryID = queryID;
  2836. packet.QueryReplies = new DirGroupsReplyPacket.QueryRepliesBlock[
  2837. data.Length];
  2838. int i = 0;
  2839. foreach (DirGroupsReplyData d in data)
  2840. {
  2841. packet.QueryReplies[i] = new DirGroupsReplyPacket.QueryRepliesBlock();
  2842. packet.QueryReplies[i].GroupID = d.groupID;
  2843. packet.QueryReplies[i].GroupName =
  2844. Utils.StringToBytes(d.groupName);
  2845. packet.QueryReplies[i].Members = d.members;
  2846. packet.QueryReplies[i].SearchOrder = d.searchOrder;
  2847. i++;
  2848. }
  2849. OutPacket(packet, ThrottleOutPacketType.Task);
  2850. }
  2851. public void SendDirClassifiedReply(UUID queryID, DirClassifiedReplyData[] data)
  2852. {
  2853. DirClassifiedReplyPacket packet = (DirClassifiedReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirClassifiedReply);
  2854. packet.AgentData = new DirClassifiedReplyPacket.AgentDataBlock();
  2855. packet.AgentData.AgentID = AgentId;
  2856. packet.QueryData = new DirClassifiedReplyPacket.QueryDataBlock();
  2857. packet.QueryData.QueryID = queryID;
  2858. packet.QueryReplies = new DirClassifiedReplyPacket.QueryRepliesBlock[
  2859. data.Length];
  2860. packet.StatusData = new DirClassifiedReplyPacket.StatusDataBlock[
  2861. data.Length];
  2862. int i = 0;
  2863. foreach (DirClassifiedReplyData d in data)
  2864. {
  2865. packet.QueryReplies[i] = new DirClassifiedReplyPacket.QueryRepliesBlock();
  2866. packet.StatusData[i] = new DirClassifiedReplyPacket.StatusDataBlock();
  2867. packet.QueryReplies[i].ClassifiedID = d.classifiedID;
  2868. packet.QueryReplies[i].Name =
  2869. Utils.StringToBytes(d.name);
  2870. packet.QueryReplies[i].ClassifiedFlags = d.classifiedFlags;
  2871. packet.QueryReplies[i].CreationDate = d.creationDate;
  2872. packet.QueryReplies[i].ExpirationDate = d.expirationDate;
  2873. packet.QueryReplies[i].PriceForListing = d.price;
  2874. packet.StatusData[i].Status = d.Status;
  2875. i++;
  2876. }
  2877. OutPacket(packet, ThrottleOutPacketType.Task);
  2878. }
  2879. public void SendDirLandReply(UUID queryID, DirLandReplyData[] data)
  2880. {
  2881. DirLandReplyPacket packet = (DirLandReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirLandReply);
  2882. packet.AgentData = new DirLandReplyPacket.AgentDataBlock();
  2883. packet.AgentData.AgentID = AgentId;
  2884. packet.QueryData = new DirLandReplyPacket.QueryDataBlock();
  2885. packet.QueryData.QueryID = queryID;
  2886. packet.QueryReplies = new DirLandReplyPacket.QueryRepliesBlock[
  2887. data.Length];
  2888. int i = 0;
  2889. foreach (DirLandReplyData d in data)
  2890. {
  2891. packet.QueryReplies[i] = new DirLandReplyPacket.QueryRepliesBlock();
  2892. packet.QueryReplies[i].ParcelID = d.parcelID;
  2893. packet.QueryReplies[i].Name =
  2894. Utils.StringToBytes(d.name);
  2895. packet.QueryReplies[i].Auction = d.auction;
  2896. packet.QueryReplies[i].ForSale = d.forSale;
  2897. packet.QueryReplies[i].SalePrice = d.salePrice;
  2898. packet.QueryReplies[i].ActualArea = d.actualArea;
  2899. i++;
  2900. }
  2901. OutPacket(packet, ThrottleOutPacketType.Task);
  2902. }
  2903. public void SendDirPopularReply(UUID queryID, DirPopularReplyData[] data)
  2904. {
  2905. DirPopularReplyPacket packet = (DirPopularReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPopularReply);
  2906. packet.AgentData = new DirPopularReplyPacket.AgentDataBlock();
  2907. packet.AgentData.AgentID = AgentId;
  2908. packet.QueryData = new DirPopularReplyPacket.QueryDataBlock();
  2909. packet.QueryData.QueryID = queryID;
  2910. packet.QueryReplies = new DirPopularReplyPacket.QueryRepliesBlock[
  2911. data.Length];
  2912. int i = 0;
  2913. foreach (DirPopularReplyData d in data)
  2914. {
  2915. packet.QueryReplies[i] = new DirPopularReplyPacket.QueryRepliesBlock();
  2916. packet.QueryReplies[i].ParcelID = d.parcelID;
  2917. packet.QueryReplies[i].Name =
  2918. Utils.StringToBytes(d.name);
  2919. packet.QueryReplies[i].Dwell = d.dwell;
  2920. i++;
  2921. }
  2922. OutPacket(packet, ThrottleOutPacketType.Task);
  2923. }
  2924. public void SendEventInfoReply(EventData data)
  2925. {
  2926. EventInfoReplyPacket packet = (EventInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.EventInfoReply);
  2927. packet.AgentData = new EventInfoReplyPacket.AgentDataBlock();
  2928. packet.AgentData.AgentID = AgentId;
  2929. packet.EventData = new EventInfoReplyPacket.EventDataBlock();
  2930. packet.EventData.EventID = data.eventID;
  2931. packet.EventData.Creator = Utils.StringToBytes(data.creator);
  2932. packet.EventData.Name = Utils.StringToBytes(data.name);
  2933. packet.EventData.Category = Utils.StringToBytes(data.category);
  2934. packet.EventData.Desc = Utils.StringToBytes(data.description);
  2935. packet.EventData.Date = Utils.StringToBytes(data.date);
  2936. packet.EventData.DateUTC = data.dateUTC;
  2937. packet.EventData.Duration = data.duration;
  2938. packet.EventData.Cover = data.cover;
  2939. packet.EventData.Amount = data.amount;
  2940. packet.EventData.SimName = Utils.StringToBytes(data.simName);
  2941. packet.EventData.GlobalPos = new Vector3d(data.globalPos);
  2942. packet.EventData.EventFlags = data.eventFlags;
  2943. OutPacket(packet, ThrottleOutPacketType.Task);
  2944. }
  2945. public void SendMapItemReply(mapItemReply[] replies, uint mapitemtype, uint flags)
  2946. {
  2947. MapItemReplyPacket mirplk = new MapItemReplyPacket();
  2948. mirplk.AgentData.AgentID = AgentId;
  2949. mirplk.RequestData.ItemType = mapitemtype;
  2950. mirplk.Data = new MapItemReplyPacket.DataBlock[replies.Length];
  2951. for (int i = 0; i < replies.Length; i++)
  2952. {
  2953. MapItemReplyPacket.DataBlock mrdata = new MapItemReplyPacket.DataBlock();
  2954. mrdata.X = replies[i].x;
  2955. mrdata.Y = replies[i].y;
  2956. mrdata.ID = replies[i].id;
  2957. mrdata.Extra = replies[i].Extra;
  2958. mrdata.Extra2 = replies[i].Extra2;
  2959. mrdata.Name = Utils.StringToBytes(replies[i].name);
  2960. mirplk.Data[i] = mrdata;
  2961. }
  2962. //m_log.Debug(mirplk.ToString());
  2963. OutPacket(mirplk, ThrottleOutPacketType.Task);
  2964. }
  2965. public void SendOfferCallingCard(UUID srcID, UUID transactionID)
  2966. {
  2967. // a bit special, as this uses AgentID to store the source instead
  2968. // of the destination. The destination (the receiver) goes into destID
  2969. OfferCallingCardPacket p = (OfferCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.OfferCallingCard);
  2970. p.AgentData.AgentID = srcID;
  2971. p.AgentData.SessionID = UUID.Zero;
  2972. p.AgentBlock.DestID = AgentId;
  2973. p.AgentBlock.TransactionID = transactionID;
  2974. OutPacket(p, ThrottleOutPacketType.Task);
  2975. }
  2976. public void SendAcceptCallingCard(UUID transactionID)
  2977. {
  2978. AcceptCallingCardPacket p = (AcceptCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.AcceptCallingCard);
  2979. p.AgentData.AgentID = AgentId;
  2980. p.AgentData.SessionID = UUID.Zero;
  2981. p.FolderData = new AcceptCallingCardPacket.FolderDataBlock[1];
  2982. p.FolderData[0] = new AcceptCallingCardPacket.FolderDataBlock();
  2983. p.FolderData[0].FolderID = UUID.Zero;
  2984. OutPacket(p, ThrottleOutPacketType.Task);
  2985. }
  2986. public void SendDeclineCallingCard(UUID transactionID)
  2987. {
  2988. DeclineCallingCardPacket p = (DeclineCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.DeclineCallingCard);
  2989. p.AgentData.AgentID = AgentId;
  2990. p.AgentData.SessionID = UUID.Zero;
  2991. p.TransactionBlock.TransactionID = transactionID;
  2992. OutPacket(p, ThrottleOutPacketType.Task);
  2993. }
  2994. public void SendTerminateFriend(UUID exFriendID)
  2995. {
  2996. TerminateFriendshipPacket p = (TerminateFriendshipPacket)PacketPool.Instance.GetPacket(PacketType.TerminateFriendship);
  2997. p.AgentData.AgentID = AgentId;
  2998. p.AgentData.SessionID = SessionId;
  2999. p.ExBlock.OtherID = exFriendID;
  3000. OutPacket(p, ThrottleOutPacketType.Task);
  3001. }
  3002. public void SendAvatarGroupsReply(UUID avatarID, GroupMembershipData[] data)
  3003. {
  3004. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  3005. if (eq == null)
  3006. return;
  3007. // message template has a GroupData field AcceptNotices ignored by viewers
  3008. // and a array NewGroupData also ignored
  3009. StringBuilder sb = eq.StartEvent("AvatarGroupsReply");
  3010. LLSDxmlEncode.AddArrayAndMap("AgentData", sb);
  3011. LLSDxmlEncode.AddElem("AgentID", AgentId, sb);
  3012. LLSDxmlEncode.AddElem("AvatarID", avatarID, sb);
  3013. LLSDxmlEncode.AddEndMapAndArray(sb);
  3014. if(data.Length == 0)
  3015. LLSDxmlEncode.AddEmptyArray("GroupData", sb);
  3016. else
  3017. {
  3018. LLSDxmlEncode.AddArray("GroupData", sb);
  3019. foreach (GroupMembershipData m in data)
  3020. {
  3021. LLSDxmlEncode.AddMap(sb);
  3022. LLSDxmlEncode.AddElem("GroupPowers", m.GroupPowers, sb);
  3023. LLSDxmlEncode.AddElem("GroupTitle", m.GroupTitle, sb);
  3024. LLSDxmlEncode.AddElem("GroupID",m.GroupID, sb);
  3025. LLSDxmlEncode.AddElem("GroupName", m.GroupName, sb);
  3026. LLSDxmlEncode.AddElem("GroupInsigniaID", m.GroupPicture, sb);
  3027. LLSDxmlEncode.AddEndMap(sb);
  3028. }
  3029. LLSDxmlEncode.AddEndArray(sb);
  3030. }
  3031. OSD ev = new OSDllsdxml(eq.EndEvent(sb));
  3032. eq.Enqueue(ev, AgentId);
  3033. }
  3034. public void SendAgentGroupDataUpdate(UUID avatarID, GroupMembershipData[] data)
  3035. {
  3036. if(avatarID != AgentId)
  3037. m_log.Debug("[CLIENT]: SendAgentGroupDataUpdate avatarID != AgentId");
  3038. IEventQueue eq = this.Scene.RequestModuleInterface<IEventQueue>();
  3039. if(eq != null)
  3040. {
  3041. eq.GroupMembershipData(avatarID,data);
  3042. }
  3043. else
  3044. {
  3045. // use UDP if no caps
  3046. AgentGroupDataUpdatePacket Groupupdate = new AgentGroupDataUpdatePacket();
  3047. AgentGroupDataUpdatePacket.GroupDataBlock[] Groups = new AgentGroupDataUpdatePacket.GroupDataBlock[data.Length];
  3048. for (int i = 0; i < data.Length; i++)
  3049. {
  3050. AgentGroupDataUpdatePacket.GroupDataBlock Group = new AgentGroupDataUpdatePacket.GroupDataBlock();
  3051. Group.AcceptNotices = data[i].AcceptNotices;
  3052. Group.Contribution = data[i].Contribution;
  3053. Group.GroupID = data[i].GroupID;
  3054. Group.GroupInsigniaID = data[i].GroupPicture;
  3055. Group.GroupName = Util.StringToBytes256(data[i].GroupName);
  3056. Group.GroupPowers = data[i].GroupPowers;
  3057. Groups[i] = Group;
  3058. }
  3059. Groupupdate.GroupData = Groups;
  3060. Groupupdate.AgentData = new AgentGroupDataUpdatePacket.AgentDataBlock();
  3061. Groupupdate.AgentData.AgentID = avatarID;
  3062. OutPacket(Groupupdate, ThrottleOutPacketType.Task);
  3063. }
  3064. }
  3065. public void SendJoinGroupReply(UUID groupID, bool success)
  3066. {
  3067. JoinGroupReplyPacket p = (JoinGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.JoinGroupReply);
  3068. p.AgentData = new JoinGroupReplyPacket.AgentDataBlock();
  3069. p.AgentData.AgentID = AgentId;
  3070. p.GroupData = new JoinGroupReplyPacket.GroupDataBlock();
  3071. p.GroupData.GroupID = groupID;
  3072. p.GroupData.Success = success;
  3073. OutPacket(p, ThrottleOutPacketType.Task);
  3074. }
  3075. public void SendEjectGroupMemberReply(UUID agentID, UUID groupID, bool success)
  3076. {
  3077. EjectGroupMemberReplyPacket p = (EjectGroupMemberReplyPacket)PacketPool.Instance.GetPacket(PacketType.EjectGroupMemberReply);
  3078. p.AgentData = new EjectGroupMemberReplyPacket.AgentDataBlock();
  3079. p.AgentData.AgentID = agentID;
  3080. p.GroupData = new EjectGroupMemberReplyPacket.GroupDataBlock();
  3081. p.GroupData.GroupID = groupID;
  3082. p.EjectData = new EjectGroupMemberReplyPacket.EjectDataBlock();
  3083. p.EjectData.Success = success;
  3084. OutPacket(p, ThrottleOutPacketType.Task);
  3085. }
  3086. public void SendLeaveGroupReply(UUID groupID, bool success)
  3087. {
  3088. LeaveGroupReplyPacket p = (LeaveGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.LeaveGroupReply);
  3089. p.AgentData = new LeaveGroupReplyPacket.AgentDataBlock();
  3090. p.AgentData.AgentID = AgentId;
  3091. p.GroupData = new LeaveGroupReplyPacket.GroupDataBlock();
  3092. p.GroupData.GroupID = groupID;
  3093. p.GroupData.Success = success;
  3094. OutPacket(p, ThrottleOutPacketType.Task);
  3095. }
  3096. public void SendAvatarClassifiedReply(UUID targetID, UUID[] classifiedID, string[] name)
  3097. {
  3098. if (classifiedID.Length != name.Length)
  3099. return;
  3100. AvatarClassifiedReplyPacket ac =
  3101. (AvatarClassifiedReplyPacket)PacketPool.Instance.GetPacket(
  3102. PacketType.AvatarClassifiedReply);
  3103. ac.AgentData = new AvatarClassifiedReplyPacket.AgentDataBlock();
  3104. ac.AgentData.AgentID = AgentId;
  3105. ac.AgentData.TargetID = targetID;
  3106. ac.Data = new AvatarClassifiedReplyPacket.DataBlock[classifiedID.Length];
  3107. int i;
  3108. for (i = 0; i < classifiedID.Length; i++)
  3109. {
  3110. ac.Data[i].ClassifiedID = classifiedID[i];
  3111. ac.Data[i].Name = Utils.StringToBytes(name[i]);
  3112. }
  3113. OutPacket(ac, ThrottleOutPacketType.Task);
  3114. }
  3115. public void SendClassifiedInfoReply(UUID classifiedID, UUID creatorID, uint creationDate, uint expirationDate, uint category, string name, string description, UUID parcelID, uint parentEstate, UUID snapshotID, string simName, Vector3 globalPos, string parcelName, byte classifiedFlags, int price)
  3116. {
  3117. ClassifiedInfoReplyPacket cr =
  3118. (ClassifiedInfoReplyPacket)PacketPool.Instance.GetPacket(
  3119. PacketType.ClassifiedInfoReply);
  3120. cr.AgentData = new ClassifiedInfoReplyPacket.AgentDataBlock();
  3121. cr.AgentData.AgentID = AgentId;
  3122. cr.Data = new ClassifiedInfoReplyPacket.DataBlock();
  3123. cr.Data.ClassifiedID = classifiedID;
  3124. cr.Data.CreatorID = creatorID;
  3125. cr.Data.CreationDate = creationDate;
  3126. cr.Data.ExpirationDate = expirationDate;
  3127. cr.Data.Category = category;
  3128. cr.Data.Name = Utils.StringToBytes(name);
  3129. cr.Data.Desc = Utils.StringToBytes(description);
  3130. cr.Data.ParcelID = parcelID;
  3131. cr.Data.ParentEstate = parentEstate;
  3132. cr.Data.SnapshotID = snapshotID;
  3133. cr.Data.SimName = Utils.StringToBytes(simName);
  3134. cr.Data.PosGlobal = new Vector3d(globalPos);
  3135. cr.Data.ParcelName = Utils.StringToBytes(parcelName);
  3136. cr.Data.ClassifiedFlags = classifiedFlags;
  3137. cr.Data.PriceForListing = price;
  3138. OutPacket(cr, ThrottleOutPacketType.Task);
  3139. }
  3140. public void SendAgentDropGroup(UUID groupID)
  3141. {
  3142. AgentDropGroupPacket dg =
  3143. (AgentDropGroupPacket)PacketPool.Instance.GetPacket(
  3144. PacketType.AgentDropGroup);
  3145. dg.AgentData = new AgentDropGroupPacket.AgentDataBlock();
  3146. dg.AgentData.AgentID = AgentId;
  3147. dg.AgentData.GroupID = groupID;
  3148. OutPacket(dg, ThrottleOutPacketType.Task);
  3149. }
  3150. public void SendAvatarNotesReply(UUID targetID, string text)
  3151. {
  3152. AvatarNotesReplyPacket an =
  3153. (AvatarNotesReplyPacket)PacketPool.Instance.GetPacket(
  3154. PacketType.AvatarNotesReply);
  3155. an.AgentData = new AvatarNotesReplyPacket.AgentDataBlock();
  3156. an.AgentData.AgentID = AgentId;
  3157. an.Data = new AvatarNotesReplyPacket.DataBlock();
  3158. an.Data.TargetID = targetID;
  3159. an.Data.Notes = Utils.StringToBytes(text);
  3160. OutPacket(an, ThrottleOutPacketType.Task);
  3161. }
  3162. public void SendAvatarPicksReply(UUID targetID, Dictionary<UUID, string> picks)
  3163. {
  3164. AvatarPicksReplyPacket ap =
  3165. (AvatarPicksReplyPacket)PacketPool.Instance.GetPacket(
  3166. PacketType.AvatarPicksReply);
  3167. ap.AgentData = new AvatarPicksReplyPacket.AgentDataBlock();
  3168. ap.AgentData.AgentID = AgentId;
  3169. ap.AgentData.TargetID = targetID;
  3170. ap.Data = new AvatarPicksReplyPacket.DataBlock[picks.Count];
  3171. int i = 0;
  3172. foreach (KeyValuePair<UUID, string> pick in picks)
  3173. {
  3174. ap.Data[i] = new AvatarPicksReplyPacket.DataBlock();
  3175. ap.Data[i].PickID = pick.Key;
  3176. ap.Data[i].PickName = Utils.StringToBytes(pick.Value);
  3177. i++;
  3178. }
  3179. OutPacket(ap, ThrottleOutPacketType.Task);
  3180. }
  3181. public void SendAvatarClassifiedReply(UUID targetID, Dictionary<UUID, string> classifieds)
  3182. {
  3183. AvatarClassifiedReplyPacket ac =
  3184. (AvatarClassifiedReplyPacket)PacketPool.Instance.GetPacket(
  3185. PacketType.AvatarClassifiedReply);
  3186. ac.AgentData = new AvatarClassifiedReplyPacket.AgentDataBlock();
  3187. ac.AgentData.AgentID = AgentId;
  3188. ac.AgentData.TargetID = targetID;
  3189. ac.Data = new AvatarClassifiedReplyPacket.DataBlock[classifieds.Count];
  3190. int i = 0;
  3191. foreach (KeyValuePair<UUID, string> classified in classifieds)
  3192. {
  3193. ac.Data[i] = new AvatarClassifiedReplyPacket.DataBlock();
  3194. ac.Data[i].ClassifiedID = classified.Key;
  3195. ac.Data[i].Name = Utils.StringToBytes(classified.Value);
  3196. i++;
  3197. }
  3198. OutPacket(ac, ThrottleOutPacketType.Task);
  3199. }
  3200. public void SendParcelDwellReply(int localID, UUID parcelID, float dwell)
  3201. {
  3202. ParcelDwellReplyPacket pd =
  3203. (ParcelDwellReplyPacket)PacketPool.Instance.GetPacket(
  3204. PacketType.ParcelDwellReply);
  3205. pd.AgentData = new ParcelDwellReplyPacket.AgentDataBlock();
  3206. pd.AgentData.AgentID = AgentId;
  3207. pd.Data = new ParcelDwellReplyPacket.DataBlock();
  3208. pd.Data.LocalID = localID;
  3209. pd.Data.ParcelID = parcelID;
  3210. pd.Data.Dwell = dwell;
  3211. OutPacket(pd, ThrottleOutPacketType.Land);
  3212. }
  3213. public void SendUserInfoReply(bool imViaEmail, bool visible, string email)
  3214. {
  3215. UserInfoReplyPacket ur =
  3216. (UserInfoReplyPacket)PacketPool.Instance.GetPacket(
  3217. PacketType.UserInfoReply);
  3218. string Visible = "hidden";
  3219. if (visible)
  3220. Visible = "default";
  3221. ur.AgentData = new UserInfoReplyPacket.AgentDataBlock();
  3222. ur.AgentData.AgentID = AgentId;
  3223. ur.UserData = new UserInfoReplyPacket.UserDataBlock();
  3224. ur.UserData.IMViaEMail = imViaEmail;
  3225. ur.UserData.DirectoryVisibility = Utils.StringToBytes(Visible);
  3226. ur.UserData.EMail = Utils.StringToBytes(email);
  3227. OutPacket(ur, ThrottleOutPacketType.Task);
  3228. }
  3229. public void SendCreateGroupReply(UUID groupID, bool success, string message)
  3230. {
  3231. CreateGroupReplyPacket createGroupReply = (CreateGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.CreateGroupReply);
  3232. createGroupReply.AgentData =
  3233. new CreateGroupReplyPacket.AgentDataBlock();
  3234. createGroupReply.ReplyData =
  3235. new CreateGroupReplyPacket.ReplyDataBlock();
  3236. createGroupReply.AgentData.AgentID = AgentId;
  3237. createGroupReply.ReplyData.GroupID = groupID;
  3238. createGroupReply.ReplyData.Success = success;
  3239. createGroupReply.ReplyData.Message = Utils.StringToBytes(message);
  3240. OutPacket(createGroupReply, ThrottleOutPacketType.Task);
  3241. }
  3242. public void SendUseCachedMuteList()
  3243. {
  3244. UseCachedMuteListPacket useCachedMuteList = (UseCachedMuteListPacket)PacketPool.Instance.GetPacket(PacketType.UseCachedMuteList);
  3245. useCachedMuteList.AgentData = new UseCachedMuteListPacket.AgentDataBlock();
  3246. useCachedMuteList.AgentData.AgentID = AgentId;
  3247. OutPacket(useCachedMuteList, ThrottleOutPacketType.Task);
  3248. }
  3249. public void SendEmpytMuteList()
  3250. {
  3251. GenericMessagePacket gmp = new GenericMessagePacket();
  3252. gmp.AgentData.AgentID = AgentId;
  3253. gmp.AgentData.SessionID = m_sessionId;
  3254. gmp.AgentData.TransactionID = UUID.Zero;
  3255. gmp.MethodData.Method = Util.StringToBytes256("emptymutelist");
  3256. gmp.ParamList = new GenericMessagePacket.ParamListBlock[1];
  3257. gmp.ParamList[0] = new GenericMessagePacket.ParamListBlock();
  3258. gmp.ParamList[0].Parameter = new byte[0];
  3259. OutPacket(gmp, ThrottleOutPacketType.Task);
  3260. }
  3261. public void SendMuteListUpdate(string filename)
  3262. {
  3263. MuteListUpdatePacket muteListUpdate = (MuteListUpdatePacket)PacketPool.Instance.GetPacket(PacketType.MuteListUpdate);
  3264. muteListUpdate.MuteData = new MuteListUpdatePacket.MuteDataBlock();
  3265. muteListUpdate.MuteData.AgentID = AgentId;
  3266. muteListUpdate.MuteData.Filename = Utils.StringToBytes(filename);
  3267. OutPacket(muteListUpdate, ThrottleOutPacketType.Task);
  3268. }
  3269. public void SendPickInfoReply(UUID pickID, UUID creatorID, bool topPick, UUID parcelID, string name, string desc, UUID snapshotID, string user, string originalName, string simName, Vector3 posGlobal, int sortOrder, bool enabled)
  3270. {
  3271. PickInfoReplyPacket pickInfoReply = (PickInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.PickInfoReply);
  3272. pickInfoReply.AgentData = new PickInfoReplyPacket.AgentDataBlock();
  3273. pickInfoReply.AgentData.AgentID = AgentId;
  3274. pickInfoReply.Data = new PickInfoReplyPacket.DataBlock();
  3275. pickInfoReply.Data.PickID = pickID;
  3276. pickInfoReply.Data.CreatorID = creatorID;
  3277. pickInfoReply.Data.TopPick = topPick;
  3278. pickInfoReply.Data.ParcelID = parcelID;
  3279. pickInfoReply.Data.Name = Utils.StringToBytes(name);
  3280. pickInfoReply.Data.Desc = Utils.StringToBytes(desc);
  3281. pickInfoReply.Data.SnapshotID = snapshotID;
  3282. pickInfoReply.Data.User = Utils.StringToBytes(user);
  3283. pickInfoReply.Data.OriginalName = Utils.StringToBytes(originalName);
  3284. pickInfoReply.Data.SimName = Utils.StringToBytes(simName);
  3285. pickInfoReply.Data.PosGlobal = new Vector3d(posGlobal);
  3286. pickInfoReply.Data.SortOrder = sortOrder;
  3287. pickInfoReply.Data.Enabled = enabled;
  3288. OutPacket(pickInfoReply, ThrottleOutPacketType.Task);
  3289. }
  3290. #endregion Scene/Avatar to Client
  3291. // Gesture
  3292. #region Appearance/ Wearables Methods
  3293. public void SendWearables(AvatarWearable[] wearables, int serial)
  3294. {
  3295. AgentWearablesUpdatePacket aw = (AgentWearablesUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentWearablesUpdate);
  3296. aw.AgentData.AgentID = AgentId;
  3297. aw.AgentData.SerialNum = (uint)serial;
  3298. aw.AgentData.SessionID = m_sessionId;
  3299. int count = 0;
  3300. for (int i = 0; i < wearables.Length; i++)
  3301. count += wearables[i].Count;
  3302. // TODO: don't create new blocks if recycling an old packet
  3303. aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[count];
  3304. AgentWearablesUpdatePacket.WearableDataBlock awb;
  3305. int idx = 0;
  3306. for (int i = 0; i < wearables.Length; i++)
  3307. {
  3308. for (int j = 0; j < wearables[i].Count; j++)
  3309. {
  3310. awb = new AgentWearablesUpdatePacket.WearableDataBlock();
  3311. awb.WearableType = (byte) i;
  3312. awb.AssetID = wearables[i][j].AssetID;
  3313. awb.ItemID = wearables[i][j].ItemID;
  3314. aw.WearableData[idx] = awb;
  3315. idx++;
  3316. // m_log.DebugFormat(
  3317. // "[APPEARANCE]: Sending wearable item/asset {0} {1} (index {2}) for {3}",
  3318. // awb.ItemID, awb.AssetID, i, Name);
  3319. }
  3320. }
  3321. OutPacket(aw, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority);
  3322. }
  3323. public void SendAppearance(UUID agentID, byte[] visualParams, byte[] textureEntry)
  3324. {
  3325. // m_log.DebugFormat(
  3326. // "[LLCLIENTVIEW]: Sending avatar appearance for {0} with {1} bytes to {2} {3}",
  3327. // agentID, textureEntry.Length, Name, AgentId);
  3328. AvatarAppearancePacket avp = (AvatarAppearancePacket)PacketPool.Instance.GetPacket(PacketType.AvatarAppearance);
  3329. // TODO: don't create new blocks if recycling an old packet
  3330. avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[visualParams.Length];
  3331. avp.ObjectData.TextureEntry = textureEntry;
  3332. AvatarAppearancePacket.VisualParamBlock avblock = null;
  3333. for (int i = 0; i < visualParams.Length; i++)
  3334. {
  3335. avblock = new AvatarAppearancePacket.VisualParamBlock();
  3336. avblock.ParamValue = visualParams[i];
  3337. avp.VisualParam[i] = avblock;
  3338. }
  3339. avp.Sender.IsTrial = false;
  3340. avp.Sender.ID = agentID;
  3341. avp.AppearanceData = new AvatarAppearancePacket.AppearanceDataBlock[0];
  3342. avp.AppearanceHover = new AvatarAppearancePacket.AppearanceHoverBlock[0];
  3343. // this need be use in future ?
  3344. // avp.AppearanceData[0].AppearanceVersion = 0;
  3345. // avp.AppearanceData[0].CofVersion = 0;
  3346. //m_log.DebugFormat("[CLIENT]: Sending appearance for {0} to {1}", agentID.ToString(), AgentId.ToString());
  3347. OutPacket(avp, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority);
  3348. }
  3349. /*
  3350. public void SendAnimations(UUID[] animations, int[] seqs, UUID sourceAgentId, UUID[] objectIDs)
  3351. {
  3352. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending animations for {0} to {1}", sourceAgentId, Name);
  3353. AvatarAnimationPacket ani = (AvatarAnimationPacket)PacketPool.Instance.GetPacket(PacketType.AvatarAnimation);
  3354. // TODO: don't create new blocks if recycling an old packet
  3355. ani.Sender = new AvatarAnimationPacket.SenderBlock();
  3356. ani.Sender.ID = sourceAgentId;
  3357. ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[animations.Length];
  3358. ani.PhysicalAvatarEventList = new AvatarAnimationPacket.PhysicalAvatarEventListBlock[0];
  3359. //self animations
  3360. if (sourceAgentId == AgentId)
  3361. {
  3362. List<int> withobjects = new List<int>(animations.Length);
  3363. List<int> noobjects = new List<int>(animations.Length);
  3364. for(int i = 0; i < animations.Length; ++i)
  3365. {
  3366. if(objectIDs[i] == sourceAgentId || objectIDs[i] == UUID.Zero)
  3367. noobjects.Add(i);
  3368. else
  3369. withobjects.Add(i);
  3370. }
  3371. ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[withobjects.Count];
  3372. int k = 0;
  3373. foreach (int i in withobjects)
  3374. {
  3375. ani.AnimationList[k] = new AvatarAnimationPacket.AnimationListBlock();
  3376. ani.AnimationList[k].AnimID = animations[i];
  3377. ani.AnimationList[k].AnimSequenceID = seqs[i];
  3378. ani.AnimationSourceList[k] = new AvatarAnimationPacket.AnimationSourceListBlock();
  3379. ani.AnimationSourceList[k].ObjectID = objectIDs[i];
  3380. k++;
  3381. }
  3382. foreach (int i in noobjects)
  3383. {
  3384. ani.AnimationList[k] = new AvatarAnimationPacket.AnimationListBlock();
  3385. ani.AnimationList[k].AnimID = animations[i];
  3386. ani.AnimationList[k].AnimSequenceID = seqs[i];
  3387. k++;
  3388. }
  3389. }
  3390. else
  3391. {
  3392. ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[0];
  3393. for (int i = 0; i < animations.Length; ++i)
  3394. {
  3395. ani.AnimationList[i] = new AvatarAnimationPacket.AnimationListBlock();
  3396. ani.AnimationList[i].AnimID = animations[i];
  3397. ani.AnimationList[i].AnimSequenceID = seqs[i];
  3398. }
  3399. }
  3400. OutPacket(ani, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority);
  3401. }
  3402. */
  3403. static private readonly byte[] AvatarAnimationHeader = new byte[] {
  3404. Helpers.MSG_RELIABLE,
  3405. 0, 0, 0, 0, // sequence number
  3406. 0, // extra
  3407. 20 // ID (high frequency)
  3408. };
  3409. public void SendAnimations(UUID[] animations, int[] seqs, UUID sourceAgentId, UUID[] objectIDs)
  3410. {
  3411. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending animations for {0} to {1}", sourceAgentId, Name);
  3412. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3413. byte[] data = buf.Data;
  3414. //setup header
  3415. Buffer.BlockCopy(AvatarAnimationHeader, 0, data, 0, 7);
  3416. //agent block
  3417. sourceAgentId.ToBytes(data, 7);
  3418. // animations count
  3419. data[23] = (byte)animations.Length;
  3420. int pos = 24;
  3421. //self animations
  3422. if (sourceAgentId == AgentId)
  3423. {
  3424. List<int> withobjects = new List<int>(animations.Length);
  3425. List<int> noobjects = new List<int>(animations.Length);
  3426. for (int i = 0; i < animations.Length; ++i)
  3427. {
  3428. if (objectIDs[i] == sourceAgentId || objectIDs[i] == UUID.Zero)
  3429. noobjects.Add(i);
  3430. else
  3431. withobjects.Add(i);
  3432. }
  3433. // first the ones with corresponding objects
  3434. foreach (int i in withobjects)
  3435. {
  3436. animations[i].ToBytes(data, pos); pos += 16;
  3437. Utils.IntToBytesSafepos(seqs[i], data, pos); pos += 4;
  3438. }
  3439. // then the rest
  3440. foreach (int i in noobjects)
  3441. {
  3442. animations[i].ToBytes(data, pos); pos += 16;
  3443. Utils.IntToBytesSafepos(seqs[i], data, pos); pos += 4;
  3444. }
  3445. // object ids block
  3446. data[pos++] = (byte)withobjects.Count;
  3447. foreach (int i in withobjects)
  3448. {
  3449. objectIDs[i].ToBytes(data, pos); pos += 16;
  3450. }
  3451. }
  3452. else
  3453. {
  3454. for(int i = 0; i < animations.Length; ++i)
  3455. {
  3456. animations[i].ToBytes(data, pos); pos += 16;
  3457. Utils.IntToBytesSafepos(seqs[i], data, pos); pos += 4;
  3458. }
  3459. data[pos++] = 0; // no object ids
  3460. }
  3461. data[pos++] = 0; // no physical avatar events
  3462. buf.DataLength = pos;
  3463. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority,
  3464. null, false, false);
  3465. }
  3466. public void SendObjectAnimations(UUID[] animations, int[] seqs, UUID senderId)
  3467. {
  3468. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending Object animations for {0} to {1}", sourceAgentId, Name);
  3469. if(!m_SupportObjectAnimations)
  3470. return;
  3471. ObjectAnimationPacket ani = (ObjectAnimationPacket)PacketPool.Instance.GetPacket(PacketType.ObjectAnimation);
  3472. // TODO: don't create new blocks if recycling an old packet
  3473. ani.Sender = new ObjectAnimationPacket.SenderBlock();
  3474. ani.Sender.ID = senderId;
  3475. ani.AnimationList = new ObjectAnimationPacket.AnimationListBlock[animations.Length];
  3476. for (int i = 0; i < animations.Length; ++i)
  3477. {
  3478. ani.AnimationList[i] = new ObjectAnimationPacket.AnimationListBlock();
  3479. ani.AnimationList[i].AnimID = animations[i];
  3480. ani.AnimationList[i].AnimSequenceID = seqs[i];
  3481. }
  3482. OutPacket(ani, ThrottleOutPacketType.Task);
  3483. }
  3484. #endregion
  3485. #region Avatar Packet/Data Sending Methods
  3486. /// <summary>
  3487. /// Send an ObjectUpdate packet with information about an avatar
  3488. /// </summary>
  3489. public void SendEntityFullUpdateImmediate(ISceneEntity ent)
  3490. {
  3491. if (ent == null || (!(ent is ScenePresence) && !(ent is SceneObjectPart)))
  3492. return;
  3493. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3494. Buffer.BlockCopy(objectUpdateHeader, 0, buf.Data, 0, 7);
  3495. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  3496. zc.Position = 7;
  3497. zc.AddUInt64(m_scene.RegionInfo.RegionHandle);
  3498. zc.AddUInt16(Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f));
  3499. zc.AddByte(1); // block count
  3500. ThrottleOutPacketType ptype = ThrottleOutPacketType.Task;
  3501. if (ent is ScenePresence)
  3502. {
  3503. CreateAvatarUpdateBlock(ent as ScenePresence, zc);
  3504. ptype |= ThrottleOutPacketType.HighPriority;
  3505. }
  3506. else
  3507. CreatePrimUpdateBlock(ent as SceneObjectPart, (ScenePresence)SceneAgent, zc);
  3508. buf.DataLength = zc.Finish();
  3509. m_udpServer.SendUDPPacket(m_udpClient, buf, ptype , null, false, false);
  3510. }
  3511. public void SendEntityTerseUpdateImmediate(ISceneEntity ent)
  3512. {
  3513. // m_log.DebugFormat(
  3514. // "[LLCLIENTVIEW]: Sending immediate object update for avatar {0} {1} to {2} {3}",
  3515. // avatar.Name, avatar.UUID, Name, AgentId);
  3516. if (ent == null)
  3517. return;
  3518. ImprovedTerseObjectUpdatePacket objupdate =
  3519. (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
  3520. objupdate.Header.Zerocoded = true;
  3521. objupdate.RegionData.TimeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);
  3522. objupdate.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
  3523. if(ent is ScenePresence)
  3524. {
  3525. ScenePresence presence = ent as ScenePresence;
  3526. objupdate.RegionData.RegionHandle = presence.RegionHandle;
  3527. objupdate.ObjectData[0] = CreateImprovedTerseBlock(ent);
  3528. }
  3529. else if(ent is SceneObjectPart)
  3530. {
  3531. SceneObjectPart part = ent as SceneObjectPart;
  3532. objupdate.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
  3533. objupdate.ObjectData[0] = CreateImprovedTerseBlock(ent);
  3534. }
  3535. OutPacket(objupdate, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority);
  3536. // We need to record the avatar local id since the root prim of an attachment points to this.
  3537. // m_attachmentsSent.Add(avatar.LocalId);
  3538. }
  3539. public void SendCoarseLocationUpdate(List<UUID> users, List<Vector3> CoarseLocations)
  3540. {
  3541. // We don't need to update inactive clients.
  3542. if (!IsActive)
  3543. return;
  3544. CoarseLocationUpdatePacket loc = (CoarseLocationUpdatePacket)PacketPool.Instance.GetPacket(PacketType.CoarseLocationUpdate);
  3545. loc.Header.Reliable = false;
  3546. // Each packet can only hold around 60 avatar positions and the client clears the mini-map each time
  3547. // a CoarseLocationUpdate packet is received. Oh well.
  3548. int total = Math.Min(CoarseLocations.Count, 60);
  3549. CoarseLocationUpdatePacket.IndexBlock ib = new CoarseLocationUpdatePacket.IndexBlock();
  3550. loc.Location = new CoarseLocationUpdatePacket.LocationBlock[total];
  3551. loc.AgentData = new CoarseLocationUpdatePacket.AgentDataBlock[total];
  3552. int selfindex = -1;
  3553. for (int i = 0; i < total; i++)
  3554. {
  3555. CoarseLocationUpdatePacket.LocationBlock lb =
  3556. new CoarseLocationUpdatePacket.LocationBlock();
  3557. lb.X = (byte)CoarseLocations[i].X;
  3558. lb.Y = (byte)CoarseLocations[i].Y;
  3559. lb.Z = CoarseLocations[i].Z > 1024 ? (byte)0 : (byte)(CoarseLocations[i].Z * 0.25f);
  3560. loc.Location[i] = lb;
  3561. loc.AgentData[i] = new CoarseLocationUpdatePacket.AgentDataBlock();
  3562. loc.AgentData[i].AgentID = users[i];
  3563. if (users[i] == AgentId)
  3564. selfindex = i;
  3565. }
  3566. ib.You = (short)selfindex;
  3567. ib.Prey = -1;
  3568. loc.Index = ib;
  3569. OutPacket(loc, ThrottleOutPacketType.Task);
  3570. }
  3571. #endregion Avatar Packet/Data Sending Methods
  3572. #region Primitive Packet/Data Sending Methods
  3573. /// <summary>
  3574. /// Generate one of the object update packets based on PrimUpdateFlags
  3575. /// and broadcast the packet to clients
  3576. /// </summary>
  3577. public void SendEntityUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags)
  3578. {
  3579. /*
  3580. if (entity.UUID == m_agentId && !updateFlags.HasFlag(PrimUpdateFlags.FullUpdate))
  3581. {
  3582. ImprovedTerseObjectUpdatePacket packet
  3583. = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
  3584. packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
  3585. packet.RegionData.TimeDilation = Utils.FloatToUInt16(1, 0.0f, 1.0f);
  3586. packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
  3587. packet.ObjectData[0] = CreateImprovedTerseBlock(entity, false);
  3588. OutPacket(packet, ThrottleOutPacketType.Unknown, true);
  3589. return;
  3590. }
  3591. */
  3592. if (entity is SceneObjectPart)
  3593. {
  3594. SceneObjectPart p = (SceneObjectPart)entity;
  3595. SceneObjectGroup g = p.ParentGroup;
  3596. if (g.HasPrivateAttachmentPoint && g.OwnerID != AgentId)
  3597. return; // Don't send updates for other people's HUDs
  3598. if((updateFlags ^ PrimUpdateFlags.SendInTransit) == 0)
  3599. {
  3600. List<uint> partIDs = (new List<uint> {p.LocalId});
  3601. lock (m_entityProps.SyncRoot)
  3602. m_entityProps.Remove(partIDs);
  3603. lock (m_entityUpdates.SyncRoot)
  3604. m_entityUpdates.Remove(partIDs);
  3605. return;
  3606. }
  3607. }
  3608. //double priority = m_prioritizer.GetUpdatePriority(this, entity);
  3609. uint priority = m_prioritizer.GetUpdatePriority(this, entity);
  3610. lock (m_entityUpdates.SyncRoot)
  3611. m_entityUpdates.Enqueue(priority, new EntityUpdate(entity, updateFlags));
  3612. }
  3613. /// <summary>
  3614. /// Requeue an EntityUpdate when it was not acknowledged by the client.
  3615. /// We will update the priority and put it in the correct queue, merging update flags
  3616. /// with any other updates that may be queued for the same entity.
  3617. /// The original update time is used for the merged update.
  3618. /// </summary>
  3619. private void ResendPrimUpdate(EntityUpdate update)
  3620. {
  3621. // If the update exists in priority queue, it will be updated.
  3622. // If it does not exist then it will be added with the current (rather than its original) priority
  3623. uint priority = m_prioritizer.GetUpdatePriority(this, update.Entity);
  3624. lock (m_entityUpdates.SyncRoot)
  3625. m_entityUpdates.Enqueue(priority, update);
  3626. }
  3627. /// <summary>
  3628. /// Requeue a list of EntityUpdates when they were not acknowledged by the client.
  3629. /// We will update the priority and put it in the correct queue, merging update flags
  3630. /// with any other updates that may be queued for the same entity.
  3631. /// The original update time is used for the merged update.
  3632. /// </summary>
  3633. private void ResendPrimUpdates(List<EntityUpdate> updates, OutgoingPacket oPacket)
  3634. {
  3635. // m_log.WarnFormat("[CLIENT] resending prim updates {0}, packet sequence number {1}", updates[0].UpdateTime, oPacket.SequenceNumber);
  3636. // Remove the update packet from the list of packets waiting for acknowledgement
  3637. // because we are requeuing the list of updates. They will be resent in new packets
  3638. // with the most recent state and priority.
  3639. m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber);
  3640. // Count this as a resent packet since we are going to requeue all of the updates contained in it
  3641. Interlocked.Increment(ref m_udpClient.PacketsResent);
  3642. // We're not going to worry about interlock yet since its not currently critical that this total count
  3643. // is 100% correct
  3644. m_udpServer.PacketsResentCount++;
  3645. foreach (EntityUpdate update in updates)
  3646. ResendPrimUpdate(update);
  3647. }
  3648. static private readonly byte[] objectUpdateHeader = new byte[] {
  3649. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED,
  3650. 0, 0, 0, 0, // sequence number
  3651. 0, // extra
  3652. 12 // ID (high frequency)
  3653. };
  3654. static private readonly byte[] terseUpdateHeader = new byte[] {
  3655. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED, // zero code is not as spec
  3656. 0, 0, 0, 0, // sequence number
  3657. 0, // extra
  3658. 15 // ID (high frequency)
  3659. };
  3660. private void ProcessEntityUpdates(int maxUpdatesBytes)
  3661. {
  3662. if (!IsActive)
  3663. return;
  3664. ScenePresence mysp = (ScenePresence)SceneAgent;
  3665. if (mysp == null)
  3666. return;
  3667. // List<ObjectUpdateCompressedPacket.ObjectDataBlock> compressedUpdateBlocks = null;
  3668. List<EntityUpdate> objectUpdates = null;
  3669. // List<EntityUpdate> compressedUpdates = null;
  3670. List<EntityUpdate> terseUpdates = null;
  3671. List<SceneObjectPart> ObjectAnimationUpdates = null;
  3672. // Check to see if this is a flush
  3673. if (maxUpdatesBytes <= 0)
  3674. {
  3675. maxUpdatesBytes = Int32.MaxValue;
  3676. }
  3677. EntityUpdate update;
  3678. bool doCulling = m_scene.ObjectsCullingByDistance;
  3679. float cullingrange = 64.0f;
  3680. Vector3 mypos = Vector3.Zero;
  3681. //bool orderedDequeue = m_scene.UpdatePrioritizationScheme == UpdatePrioritizationSchemes.SimpleAngularDistance;
  3682. bool orderedDequeue = false; // temporary off
  3683. HashSet<SceneObjectGroup> GroupsNeedFullUpdate = new HashSet<SceneObjectGroup>();
  3684. if (doCulling)
  3685. {
  3686. cullingrange = mysp.DrawDistance + m_scene.ReprioritizationDistance + 16f;
  3687. mypos = mysp.AbsolutePosition;
  3688. }
  3689. while (maxUpdatesBytes > 0)
  3690. {
  3691. if (!IsActive)
  3692. return;
  3693. lock (m_entityUpdates.SyncRoot)
  3694. {
  3695. if(orderedDequeue)
  3696. {
  3697. if (!m_entityUpdates.TryOrderedDequeue(out update))
  3698. break;
  3699. }
  3700. else
  3701. {
  3702. if (!m_entityUpdates.TryDequeue(out update))
  3703. break;
  3704. }
  3705. }
  3706. PrimUpdateFlags updateFlags = (PrimUpdateFlags)update.Flags;
  3707. if(updateFlags.HasFlag(PrimUpdateFlags.Kill))
  3708. {
  3709. m_killRecord.Add(update.Entity.LocalId);
  3710. maxUpdatesBytes -= 30;
  3711. continue;
  3712. }
  3713. if (update.Entity is SceneObjectPart)
  3714. {
  3715. SceneObjectPart part = (SceneObjectPart)update.Entity;
  3716. SceneObjectGroup grp = part.ParentGroup;
  3717. if (grp.inTransit && !update.Flags.HasFlag(PrimUpdateFlags.SendInTransit))
  3718. continue;
  3719. if (grp.IsDeleted)
  3720. {
  3721. // Don't send updates for objects that have been marked deleted.
  3722. // Instead send another kill object, because the first one may have gotten
  3723. // into a race condition
  3724. if (part == grp.RootPart && !m_killRecord.Contains(grp.LocalId))
  3725. {
  3726. m_killRecord.Add(grp.LocalId);
  3727. maxUpdatesBytes -= 30;
  3728. }
  3729. continue;
  3730. }
  3731. if (grp.IsAttachment)
  3732. {
  3733. // animated attachments are nasty if not supported by viewer
  3734. if(!m_SupportObjectAnimations && grp.RootPart.Shape.MeshFlagEntry)
  3735. continue;
  3736. // Someone else's HUD, why are we getting these?
  3737. if (grp.OwnerID != AgentId && grp.HasPrivateAttachmentPoint)
  3738. continue;
  3739. // if owner gone don't update it to anyone
  3740. ScenePresence sp;
  3741. if (!m_scene.TryGetScenePresence(part.OwnerID, out sp))
  3742. continue;
  3743. // On vehicle crossing, the attachments are received
  3744. // while the avatar is still a child. Don't send
  3745. // updates here because the LocalId has not yet
  3746. // been updated and the viewer will derender the
  3747. // attachments until the avatar becomes root.
  3748. if (sp.IsChildAgent)
  3749. continue;
  3750. // It's an attachment of a valid avatar, but
  3751. // doesn't seem to be attached, skip
  3752. List<SceneObjectGroup> atts = sp.GetAttachments();
  3753. bool found = false;
  3754. foreach (SceneObjectGroup att in atts)
  3755. {
  3756. if (att == grp)
  3757. {
  3758. found = true;
  3759. break;
  3760. }
  3761. }
  3762. if (!found)
  3763. continue;
  3764. if (m_disableFacelights)
  3765. {
  3766. if (grp.RootPart.Shape.State != (byte)AttachmentPoint.LeftHand &&
  3767. grp.RootPart.Shape.State != (byte)AttachmentPoint.RightHand)
  3768. {
  3769. part.Shape.LightEntry = false;
  3770. }
  3771. }
  3772. }
  3773. else if (doCulling)
  3774. {
  3775. if(GroupsNeedFullUpdate.Contains(grp))
  3776. continue;
  3777. bool inViewGroups = false;
  3778. lock(GroupsInView)
  3779. inViewGroups = GroupsInView.Contains(grp);
  3780. if(!inViewGroups)
  3781. {
  3782. Vector3 partpos = grp.getCenterOffset();
  3783. float dpos = (partpos - mypos).LengthSquared();
  3784. float maxview = grp.GetBoundsRadius() + cullingrange;
  3785. if (dpos > maxview * maxview)
  3786. continue;
  3787. GroupsNeedFullUpdate.Add(grp);
  3788. continue;
  3789. }
  3790. }
  3791. }
  3792. else if (update.Entity is ScenePresence)
  3793. {
  3794. ScenePresence presence = (ScenePresence)update.Entity;
  3795. if (presence.IsDeleted)
  3796. continue;
  3797. // If ParentUUID is not UUID.Zero and ParentID is 0, this
  3798. // avatar is in the process of crossing regions while
  3799. // sat on an object. In this state, we don't want any
  3800. // updates because they will visually orbit the avatar.
  3801. // Update will be forced once crossing is completed anyway.
  3802. if (presence.ParentUUID != UUID.Zero && presence.ParentID == 0)
  3803. continue;
  3804. }
  3805. else // what is this update ?
  3806. continue;
  3807. #region UpdateFlags to packet type conversion
  3808. // bool canUseCompressed = true;
  3809. if (update.Entity is SceneObjectPart)
  3810. {
  3811. if (m_SupportObjectAnimations && updateFlags.HasFlag(PrimUpdateFlags.Animations))
  3812. {
  3813. SceneObjectPart sop = (SceneObjectPart)update.Entity;
  3814. if ( sop.Animations != null)
  3815. {
  3816. if(ObjectAnimationUpdates == null)
  3817. ObjectAnimationUpdates = new List<SceneObjectPart>();
  3818. ObjectAnimationUpdates.Add(sop);
  3819. maxUpdatesBytes -= 20 * sop.Animations.Count + 24;
  3820. }
  3821. }
  3822. }
  3823. else
  3824. {
  3825. // canUseCompressed = false;
  3826. }
  3827. updateFlags &= PrimUpdateFlags.FullUpdate; // clear other control bits already handled
  3828. if(updateFlags == PrimUpdateFlags.None)
  3829. continue;
  3830. /*
  3831. const PrimUpdateFlags canNotUseCompressedMask =
  3832. PrimUpdateFlags.Velocity | PrimUpdateFlags.Acceleration |
  3833. PrimUpdateFlags.CollisionPlane | PrimUpdateFlags.Joint;
  3834. if ((updateFlags & canNotUseCompressedMask) != 0)
  3835. {
  3836. canUseCompressed = false;
  3837. }
  3838. */
  3839. const PrimUpdateFlags canNotUseImprovedMask = ~(
  3840. PrimUpdateFlags.AttachmentPoint |
  3841. PrimUpdateFlags.Position |
  3842. PrimUpdateFlags.Rotation |
  3843. PrimUpdateFlags.Velocity |
  3844. PrimUpdateFlags.Acceleration |
  3845. PrimUpdateFlags.AngularVelocity |
  3846. PrimUpdateFlags.CollisionPlane |
  3847. PrimUpdateFlags.Textures
  3848. );
  3849. #endregion UpdateFlags to packet type conversion
  3850. #region Block Construction
  3851. // TODO: Remove this once we can build compressed updates
  3852. /*
  3853. if (canUseCompressed)
  3854. {
  3855. ObjectUpdateCompressedPacket.ObjectDataBlock ablock =
  3856. CreateCompressedUpdateBlock((SceneObjectPart)update.Entity, updateFlags);
  3857. compressedUpdateBlocks.Add(ablock);
  3858. compressedUpdates.Value.Add(update);
  3859. maxUpdatesBytes -= ablock.Length;
  3860. }
  3861. else if (canUseImproved)
  3862. */
  3863. if ((updateFlags & canNotUseImprovedMask) == 0)
  3864. {
  3865. if (terseUpdates == null)
  3866. {
  3867. terseUpdates = new List<EntityUpdate>();
  3868. maxUpdatesBytes -= 18;
  3869. }
  3870. terseUpdates.Add(update);
  3871. if (update.Entity is ScenePresence)
  3872. maxUpdatesBytes -= 63; // no texture entry
  3873. else
  3874. {
  3875. if ((updateFlags & PrimUpdateFlags.Textures) == 0)
  3876. maxUpdatesBytes -= 47;
  3877. else
  3878. maxUpdatesBytes -= 150; // aprox
  3879. }
  3880. }
  3881. else
  3882. {
  3883. if (update.Entity is ScenePresence)
  3884. maxUpdatesBytes -= 150; // crude estimation
  3885. else
  3886. maxUpdatesBytes -= 300;
  3887. if(objectUpdates == null)
  3888. {
  3889. objectUpdates = new List<EntityUpdate>();
  3890. maxUpdatesBytes -= 18;
  3891. }
  3892. objectUpdates.Add(update);
  3893. }
  3894. #endregion Block Construction
  3895. }
  3896. #region Packet Sending
  3897. ushort timeDilation;
  3898. if (!IsActive)
  3899. return;
  3900. timeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);
  3901. if(objectUpdates != null)
  3902. {
  3903. int blocks = objectUpdates.Count;
  3904. List<EntityUpdate> tau = new List<EntityUpdate>(30);
  3905. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3906. Buffer.BlockCopy(objectUpdateHeader, 0, buf.Data, 0, 7);
  3907. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  3908. zc.Position = 7;
  3909. zc.AddUInt64(m_scene.RegionInfo.RegionHandle);
  3910. zc.AddUInt16(Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f));
  3911. zc.AddByte(1); // tmp block count
  3912. int countposition = zc.Position - 1;
  3913. int lastpos = 0;
  3914. int lastzc = 0;
  3915. int count = 0;
  3916. foreach (EntityUpdate eu in objectUpdates)
  3917. {
  3918. lastpos = zc.Position;
  3919. lastzc = zc.ZeroCount;
  3920. if (eu.Entity is ScenePresence)
  3921. CreateAvatarUpdateBlock((ScenePresence)eu.Entity, zc);
  3922. else
  3923. CreatePrimUpdateBlock((SceneObjectPart)eu.Entity, mysp, zc);
  3924. if (zc.Position < LLUDPServer.MAXPAYLOAD)
  3925. {
  3926. tau.Add(eu);
  3927. ++count;
  3928. --blocks;
  3929. }
  3930. else if (blocks > 0)
  3931. {
  3932. // we need more packets
  3933. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3934. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, countposition); // start is the same
  3935. buf.Data[countposition] = (byte)count;
  3936. // get pending zeros at cut point
  3937. if(lastzc > 0)
  3938. {
  3939. buf.Data[lastpos++] = 0;
  3940. buf.Data[lastpos++] = (byte)lastzc;
  3941. }
  3942. buf.DataLength = lastpos;
  3943. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  3944. delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  3945. buf = newbuf;
  3946. zc.Data = buf.Data;
  3947. zc.ZeroCount = 0;
  3948. zc.Position = countposition + 1;
  3949. // im lazy now, just do last again
  3950. if (eu.Entity is ScenePresence)
  3951. CreateAvatarUpdateBlock((ScenePresence)eu.Entity, zc);
  3952. else
  3953. CreatePrimUpdateBlock((SceneObjectPart)eu.Entity, mysp, zc);
  3954. tau = new List<EntityUpdate>(30);
  3955. tau.Add(eu);
  3956. count = 1;
  3957. --blocks;
  3958. }
  3959. }
  3960. if (count > 0)
  3961. {
  3962. buf.Data[countposition] = (byte)count;
  3963. buf.DataLength = zc.Finish();
  3964. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  3965. delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  3966. }
  3967. }
  3968. /*
  3969. if (compressedUpdateBlocks != null)
  3970. {
  3971. ObjectUpdateCompressedPacket packet = (ObjectUpdateCompressedPacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdateCompressed);
  3972. packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
  3973. packet.RegionData.TimeDilation = timeDilation;
  3974. packet.ObjectData = compressedUpdateBlocks.ToArray();
  3975. compressedUpdateBlocks.Clear();
  3976. OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(compressedUpdates, oPacket); });
  3977. }
  3978. */
  3979. if (terseUpdates != null)
  3980. {
  3981. int blocks = terseUpdates.Count;
  3982. List<EntityUpdate> tau = new List<EntityUpdate>(30);
  3983. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3984. //setup header and regioninfo block
  3985. Buffer.BlockCopy(terseUpdateHeader, 0, buf.Data, 0, 7);
  3986. Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, buf.Data, 7);
  3987. Utils.UInt16ToBytes(timeDilation, buf.Data, 15);
  3988. int pos = 18;
  3989. int lastpos = 0;
  3990. int count = 0;
  3991. foreach (EntityUpdate eu in terseUpdates)
  3992. {
  3993. lastpos = pos;
  3994. CreateImprovedTerseBlock(eu.Entity, buf.Data, ref pos, (eu.Flags & PrimUpdateFlags.Textures) != 0);
  3995. if (pos < LLUDPServer.MAXPAYLOAD)
  3996. {
  3997. tau.Add(eu);
  3998. ++count;
  3999. --blocks;
  4000. }
  4001. else if (blocks > 0)
  4002. {
  4003. // we need more packets
  4004. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4005. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, 17); // start is the same
  4006. // copy what we done in excess
  4007. int extralen = pos - lastpos;
  4008. if(extralen > 0)
  4009. Buffer.BlockCopy(buf.Data, lastpos, newbuf.Data, 18, extralen);
  4010. pos = 18 + extralen;
  4011. buf.Data[17] = (byte)count;
  4012. buf.DataLength = lastpos;
  4013. // zero encode is not as spec
  4014. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4015. delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, true);
  4016. tau = new List<EntityUpdate>(30);
  4017. tau.Add(eu);
  4018. count = 1;
  4019. --blocks;
  4020. buf = newbuf;
  4021. }
  4022. }
  4023. if (count > 0)
  4024. {
  4025. buf.Data[17] = (byte)count;
  4026. buf.DataLength = pos;
  4027. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4028. delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, true);
  4029. }
  4030. }
  4031. if (ObjectAnimationUpdates != null)
  4032. {
  4033. foreach (SceneObjectPart sop in ObjectAnimationUpdates)
  4034. {
  4035. if (sop.Animations == null)
  4036. continue;
  4037. SceneObjectGroup sog = sop.ParentGroup;
  4038. if (sog == null || sog.IsDeleted)
  4039. continue;
  4040. SceneObjectPart root = sog.RootPart;
  4041. if (root == null || root.Shape == null || !root.Shape.MeshFlagEntry)
  4042. continue;
  4043. UUID[] ids = null;
  4044. int[] seqs = null;
  4045. int count = sop.GetAnimations(out ids, out seqs);
  4046. ObjectAnimationPacket ani = (ObjectAnimationPacket)PacketPool.Instance.GetPacket(PacketType.ObjectAnimation);
  4047. ani.Sender = new ObjectAnimationPacket.SenderBlock();
  4048. ani.Sender.ID = sop.UUID;
  4049. ani.AnimationList = new ObjectAnimationPacket.AnimationListBlock[count];
  4050. for(int i = 0; i< count; i++)
  4051. {
  4052. ani.AnimationList[i] = new ObjectAnimationPacket.AnimationListBlock();
  4053. ani.AnimationList[i].AnimID = ids[i];
  4054. ani.AnimationList[i].AnimSequenceID = seqs[i];
  4055. }
  4056. OutPacket(ani, ThrottleOutPacketType.Task, true);
  4057. }
  4058. }
  4059. #endregion Packet Sending
  4060. #region Handle deleted objects
  4061. if (m_killRecord.Count > 0)
  4062. {
  4063. SendKillObject(m_killRecord);
  4064. m_killRecord.Clear();
  4065. }
  4066. if(GroupsNeedFullUpdate.Count > 0)
  4067. {
  4068. foreach(SceneObjectGroup grp in GroupsNeedFullUpdate)
  4069. {
  4070. lock (GroupsInView)
  4071. GroupsInView.Add(grp);
  4072. foreach (SceneObjectPart p in grp.Parts)
  4073. SendEntityUpdate(p, PrimUpdateFlags.CancelKill);
  4074. }
  4075. }
  4076. #endregion
  4077. }
  4078. // hack.. dont use
  4079. /*
  4080. public void SendPartFullUpdate(ISceneEntity ent, uint? parentID)
  4081. {
  4082. if (ent is SceneObjectPart)
  4083. {
  4084. SceneObjectPart part = (SceneObjectPart)ent;
  4085. ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
  4086. packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
  4087. packet.RegionData.TimeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);
  4088. packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
  4089. ObjectUpdatePacket.ObjectDataBlock blk = CreatePrimUpdateBlock(part, mysp);
  4090. if (parentID.HasValue)
  4091. {
  4092. blk.ParentID = parentID.Value;
  4093. }
  4094. packet.ObjectData[0] = blk;
  4095. OutPacket(packet, ThrottleOutPacketType.Task, true);
  4096. }
  4097. // m_log.DebugFormat(
  4098. // "[LLCLIENTVIEW]: Sent {0} updates in ProcessEntityUpdates() for {1} {2} in {3}",
  4099. // updatesThisCall, Name, SceneAgent.IsChildAgent ? "child" : "root", Scene.Name);
  4100. //
  4101. }
  4102. */
  4103. public void ReprioritizeUpdates()
  4104. {
  4105. lock (m_entityUpdates.SyncRoot)
  4106. m_entityUpdates.Reprioritize(UpdatePriorityHandler);
  4107. CheckGroupsInView();
  4108. }
  4109. private bool CheckGroupsInViewBusy = false;
  4110. public void CheckGroupsInView()
  4111. {
  4112. bool doCulling = m_scene.ObjectsCullingByDistance;
  4113. if(!doCulling)
  4114. return;
  4115. if (!IsActive)
  4116. return;
  4117. if (CheckGroupsInViewBusy)
  4118. return;
  4119. ScenePresence mysp = (ScenePresence)SceneAgent;
  4120. if (mysp == null || mysp.IsDeleted)
  4121. return;
  4122. CheckGroupsInViewBusy = true;
  4123. float cullingrange = mysp.DrawDistance + m_scene.ReprioritizationDistance + 16f;
  4124. Vector3 mypos = mysp.AbsolutePosition;
  4125. HashSet<SceneObjectGroup> NewGroupsInView = new HashSet<SceneObjectGroup>();
  4126. HashSet<SceneObjectGroup> GroupsNeedFullUpdate = new HashSet<SceneObjectGroup>();
  4127. List<SceneObjectGroup> kills = new List<SceneObjectGroup>();
  4128. EntityBase[] entities = m_scene.Entities.GetEntities();
  4129. foreach (EntityBase e in entities)
  4130. {
  4131. if (!IsActive)
  4132. return;
  4133. if (e != null && e is SceneObjectGroup)
  4134. {
  4135. SceneObjectGroup grp = (SceneObjectGroup)e;
  4136. if(grp.IsDeleted || grp.IsAttachment)
  4137. continue;
  4138. bool inviewgroups;
  4139. lock (GroupsInView)
  4140. inviewgroups = GroupsInView.Contains(grp);
  4141. Vector3 grppos = grp.getCenterOffset();
  4142. float dpos = (grppos - mypos).LengthSquared();
  4143. float maxview = grp.GetBoundsRadius() + cullingrange;
  4144. if (dpos > maxview * maxview)
  4145. {
  4146. if(inviewgroups)
  4147. kills.Add(grp);
  4148. }
  4149. else
  4150. {
  4151. if(!inviewgroups)
  4152. GroupsNeedFullUpdate.Add(grp);
  4153. NewGroupsInView.Add(grp);
  4154. }
  4155. }
  4156. }
  4157. lock(GroupsInView)
  4158. GroupsInView = NewGroupsInView;
  4159. if (kills.Count > 0)
  4160. {
  4161. List<uint> partIDs = new List<uint>();
  4162. foreach(SceneObjectGroup grp in kills)
  4163. {
  4164. SendEntityUpdate(grp.RootPart, PrimUpdateFlags.Kill);
  4165. foreach(SceneObjectPart p in grp.Parts)
  4166. {
  4167. if(p != grp.RootPart)
  4168. partIDs.Add(p.LocalId);
  4169. }
  4170. }
  4171. kills.Clear();
  4172. if(partIDs.Count > 0)
  4173. {
  4174. lock (m_entityProps.SyncRoot)
  4175. m_entityProps.Remove(partIDs);
  4176. lock (m_entityUpdates.SyncRoot)
  4177. m_entityUpdates.Remove(partIDs);
  4178. }
  4179. }
  4180. if(GroupsNeedFullUpdate.Count > 0)
  4181. {
  4182. foreach(SceneObjectGroup grp in GroupsNeedFullUpdate)
  4183. {
  4184. foreach(SceneObjectPart p in grp.Parts)
  4185. SendEntityUpdate(p, PrimUpdateFlags.CancelKill);
  4186. }
  4187. }
  4188. CheckGroupsInViewBusy = false;
  4189. }
  4190. private bool UpdatePriorityHandler(ref uint priority, ISceneEntity entity)
  4191. {
  4192. if (entity == null)
  4193. return false;
  4194. priority = m_prioritizer.GetUpdatePriority(this, entity);
  4195. return true;
  4196. }
  4197. public void FlushPrimUpdates()
  4198. {
  4199. m_log.WarnFormat("[CLIENT]: Flushing prim updates to " + m_firstName + " " + m_lastName);
  4200. while (m_entityUpdates.Count > 0)
  4201. ProcessEntityUpdates(-1);
  4202. }
  4203. #endregion Primitive Packet/Data Sending Methods
  4204. // These are used to implement an adaptive backoff in the number
  4205. // of updates converted to packets. Since we don't want packets
  4206. // to sit in the queue with old data, only convert enough updates
  4207. // to packets that can be sent in 30ms.
  4208. void HandleQueueEmpty(ThrottleOutPacketTypeFlags categories)
  4209. {
  4210. if(m_scene == null)
  4211. return;
  4212. if ((categories & ThrottleOutPacketTypeFlags.Task) != 0)
  4213. {
  4214. int maxUpdateBytes = m_udpClient.GetCatBytesCanSend(ThrottleOutPacketType.Task, 30);
  4215. if (m_entityUpdates.Count > 0)
  4216. ProcessEntityUpdates(maxUpdateBytes);
  4217. if (m_entityProps.Count > 0)
  4218. ProcessEntityPropertyRequests(maxUpdateBytes);
  4219. }
  4220. if ((categories & ThrottleOutPacketTypeFlags.Texture) != 0)
  4221. ImageManager.ProcessImageQueue(m_udpServer.TextureSendLimit);
  4222. }
  4223. internal bool HandleHasUpdates(ThrottleOutPacketTypeFlags categories)
  4224. {
  4225. if ((categories & ThrottleOutPacketTypeFlags.Task) != 0)
  4226. {
  4227. if (m_entityUpdates.Count > 0)
  4228. return true;
  4229. if (m_entityProps.Count > 0)
  4230. return true;
  4231. }
  4232. if ((categories & ThrottleOutPacketTypeFlags.Texture) != 0)
  4233. {
  4234. if (ImageManager.HasUpdates())
  4235. return true;
  4236. }
  4237. return false;
  4238. }
  4239. public void SendAssetUploadCompleteMessage(sbyte AssetType, bool Success, UUID AssetFullID)
  4240. {
  4241. AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
  4242. newPack.AssetBlock.Type = AssetType;
  4243. newPack.AssetBlock.Success = Success;
  4244. newPack.AssetBlock.UUID = AssetFullID;
  4245. newPack.Header.Zerocoded = true;
  4246. OutPacket(newPack, ThrottleOutPacketType.Asset);
  4247. }
  4248. public void SendXferRequest(ulong XferID, short AssetType, UUID vFileID, byte FilePath, byte[] FileName)
  4249. {
  4250. RequestXferPacket newPack = new RequestXferPacket();
  4251. newPack.XferID.ID = XferID;
  4252. newPack.XferID.VFileType = AssetType;
  4253. newPack.XferID.VFileID = vFileID;
  4254. newPack.XferID.FilePath = FilePath;
  4255. newPack.XferID.Filename = FileName;
  4256. newPack.Header.Zerocoded = true;
  4257. OutPacket(newPack, ThrottleOutPacketType.Asset);
  4258. }
  4259. public void SendConfirmXfer(ulong xferID, uint PacketID)
  4260. {
  4261. ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket();
  4262. newPack.XferID.ID = xferID;
  4263. newPack.XferID.Packet = PacketID;
  4264. newPack.Header.Zerocoded = true;
  4265. OutPacket(newPack, ThrottleOutPacketType.Asset);
  4266. }
  4267. public void SendInitiateDownload(string simFileName, string clientFileName)
  4268. {
  4269. InitiateDownloadPacket newPack = new InitiateDownloadPacket();
  4270. newPack.AgentData.AgentID = AgentId;
  4271. newPack.FileData.SimFilename = Utils.StringToBytes(simFileName);
  4272. newPack.FileData.ViewerFilename = Utils.StringToBytes(clientFileName);
  4273. OutPacket(newPack, ThrottleOutPacketType.Asset);
  4274. }
  4275. public void SendImageFirstPart(
  4276. ushort numParts, UUID ImageUUID, uint ImageSize, byte[] ImageData, byte imageCodec)
  4277. {
  4278. ImageDataPacket im = new ImageDataPacket();
  4279. im.ImageID.Packets = numParts;
  4280. im.ImageID.ID = ImageUUID;
  4281. if (ImageSize > 0)
  4282. im.ImageID.Size = ImageSize;
  4283. im.ImageData.Data = ImageData;
  4284. im.ImageID.Codec = imageCodec;
  4285. im.Header.Zerocoded = true;
  4286. OutPacket(im, ThrottleOutPacketType.Texture);
  4287. }
  4288. public void SendImageNextPart(ushort partNumber, UUID imageUuid, byte[] imageData)
  4289. {
  4290. ImagePacketPacket im = new ImagePacketPacket();
  4291. im.ImageID.Packet = partNumber;
  4292. im.ImageID.ID = imageUuid;
  4293. im.ImageData.Data = imageData;
  4294. OutPacket(im, ThrottleOutPacketType.Texture);
  4295. }
  4296. public void SendImageNotFound(UUID imageid)
  4297. {
  4298. ImageNotInDatabasePacket notFoundPacket
  4299. = (ImageNotInDatabasePacket)PacketPool.Instance.GetPacket(PacketType.ImageNotInDatabase);
  4300. notFoundPacket.ImageID.ID = imageid;
  4301. OutPacket(notFoundPacket, ThrottleOutPacketType.Texture);
  4302. }
  4303. public void SendShutdownConnectionNotice()
  4304. {
  4305. OutPacket(PacketPool.Instance.GetPacket(PacketType.DisableSimulator), ThrottleOutPacketType.Unknown);
  4306. }
  4307. public void SendSimStats(SimStats stats)
  4308. {
  4309. SimStatsPacket pack = new SimStatsPacket();
  4310. pack.Region = new SimStatsPacket.RegionBlock();
  4311. pack.Region.RegionX = stats.RegionX;
  4312. pack.Region.RegionY = stats.RegionY;
  4313. pack.Region.RegionFlags = stats.RegionFlags;
  4314. pack.Region.ObjectCapacity = stats.ObjectCapacity;
  4315. //pack.Region = //stats.RegionBlock;
  4316. pack.Stat = stats.StatsBlock;
  4317. pack.Header.Reliable = false;
  4318. pack.RegionInfo = new SimStatsPacket.RegionInfoBlock[0];
  4319. OutPacket(pack, ThrottleOutPacketType.Task);
  4320. }
  4321. private class ObjectPropertyUpdate : EntityUpdate
  4322. {
  4323. internal bool SendFamilyProps;
  4324. internal bool SendObjectProps;
  4325. public ObjectPropertyUpdate(ISceneEntity entity, uint flags, bool sendfam, bool sendobj)
  4326. : base(entity,(PrimUpdateFlags)flags)
  4327. {
  4328. SendFamilyProps = sendfam;
  4329. SendObjectProps = sendobj;
  4330. }
  4331. public void Update(ObjectPropertyUpdate update)
  4332. {
  4333. SendFamilyProps = SendFamilyProps || update.SendFamilyProps;
  4334. SendObjectProps = SendObjectProps || update.SendObjectProps;
  4335. // other properties may need to be updated by base class
  4336. base.Update(update);
  4337. }
  4338. }
  4339. public void SendObjectPropertiesFamilyData(ISceneEntity entity, uint requestFlags)
  4340. {
  4341. uint priority = 0; // time based ordering only
  4342. lock (m_entityProps.SyncRoot)
  4343. m_entityProps.Enqueue(priority, new ObjectPropertyUpdate(entity, requestFlags, true, false));
  4344. }
  4345. private void ResendPropertyUpdate(ObjectPropertyUpdate update)
  4346. {
  4347. uint priority = 0;
  4348. lock (m_entityProps.SyncRoot)
  4349. m_entityProps.Enqueue(priority, update);
  4350. }
  4351. private void ResendPropertyUpdates(List<ObjectPropertyUpdate> updates, OutgoingPacket oPacket)
  4352. {
  4353. // m_log.WarnFormat("[CLIENT] resending object property {0}",updates[0].UpdateTime);
  4354. // Remove the update packet from the list of packets waiting for acknowledgement
  4355. // because we are requeuing the list of updates. They will be resent in new packets
  4356. // with the most recent state.
  4357. m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber);
  4358. // Count this as a resent packet since we are going to requeue all of the updates contained in it
  4359. Interlocked.Increment(ref m_udpClient.PacketsResent);
  4360. // We're not going to worry about interlock yet since its not currently critical that this total count
  4361. // is 100% correct
  4362. m_udpServer.PacketsResentCount++;
  4363. foreach (ObjectPropertyUpdate update in updates)
  4364. ResendPropertyUpdate(update);
  4365. }
  4366. public void SendObjectPropertiesReply(ISceneEntity entity)
  4367. {
  4368. uint priority = 0; // time based ordering only
  4369. lock (m_entityProps.SyncRoot)
  4370. m_entityProps.Enqueue(priority, new ObjectPropertyUpdate(entity,0,false,true));
  4371. }
  4372. private void ProcessEntityPropertyRequests(int maxUpdateBytes)
  4373. {
  4374. List<ObjectPropertiesFamilyPacket.ObjectDataBlock> objectFamilyBlocks = null;
  4375. List<ObjectPropertiesPacket.ObjectDataBlock> objectPropertiesBlocks = null;
  4376. List<SceneObjectPart> needPhysics = null;
  4377. bool orderedDequeue = m_scene.UpdatePrioritizationScheme == UpdatePrioritizationSchemes.SimpleAngularDistance;
  4378. EntityUpdate iupdate;
  4379. while (maxUpdateBytes > 0)
  4380. {
  4381. lock (m_entityProps.SyncRoot)
  4382. {
  4383. if(orderedDequeue)
  4384. {
  4385. if (!m_entityProps.TryOrderedDequeue(out iupdate))
  4386. break;
  4387. }
  4388. else
  4389. {
  4390. if (!m_entityProps.TryDequeue(out iupdate))
  4391. break;
  4392. }
  4393. }
  4394. ObjectPropertyUpdate update = (ObjectPropertyUpdate)iupdate;
  4395. if (update.SendFamilyProps)
  4396. {
  4397. if (update.Entity is SceneObjectPart)
  4398. {
  4399. SceneObjectPart sop = (SceneObjectPart)update.Entity;
  4400. ObjectPropertiesFamilyPacket.ObjectDataBlock objPropDB = CreateObjectPropertiesFamilyBlock(sop,update.Flags);
  4401. if(objectFamilyBlocks == null)
  4402. objectFamilyBlocks = new List<ObjectPropertiesFamilyPacket.ObjectDataBlock>();
  4403. objectFamilyBlocks.Add(objPropDB);
  4404. maxUpdateBytes -= objPropDB.Length;
  4405. }
  4406. }
  4407. if (update.SendObjectProps)
  4408. {
  4409. if (update.Entity is SceneObjectPart)
  4410. {
  4411. SceneObjectPart sop = (SceneObjectPart)update.Entity;
  4412. if(needPhysics == null)
  4413. needPhysics = new List<SceneObjectPart>();
  4414. needPhysics.Add(sop);
  4415. ObjectPropertiesPacket.ObjectDataBlock objPropDB = CreateObjectPropertiesBlock(sop);
  4416. if(objectPropertiesBlocks == null)
  4417. objectPropertiesBlocks = new List<ObjectPropertiesPacket.ObjectDataBlock>();
  4418. objectPropertiesBlocks.Add(objPropDB);
  4419. maxUpdateBytes -= objPropDB.Length;
  4420. }
  4421. }
  4422. }
  4423. if (objectPropertiesBlocks != null)
  4424. {
  4425. ObjectPropertiesPacket packet = (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties);
  4426. packet.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[objectPropertiesBlocks.Count];
  4427. for (int i = 0; i < objectPropertiesBlocks.Count; i++)
  4428. packet.ObjectData[i] = objectPropertiesBlocks[i];
  4429. // Pass in the delegate so that if this packet needs to be resent, we send the current properties
  4430. // of the object rather than the properties when the packet was created
  4431. // HACK : Remove intelligent resending until it's fixed in core
  4432. //OutPacket(packet, ThrottleOutPacketType.Task, true,
  4433. // delegate(OutgoingPacket oPacket)
  4434. // {
  4435. // ResendPropertyUpdates(propertyUpdates.Value, oPacket);
  4436. // });
  4437. OutPacket(packet, ThrottleOutPacketType.Task, true);
  4438. }
  4439. if (objectFamilyBlocks != null)
  4440. {
  4441. // one packet per object block... uggh...
  4442. for (int i = 0; i < objectFamilyBlocks.Count; i++)
  4443. {
  4444. ObjectPropertiesFamilyPacket packet =
  4445. (ObjectPropertiesFamilyPacket)PacketPool.Instance.GetPacket(PacketType.ObjectPropertiesFamily);
  4446. packet.ObjectData = objectFamilyBlocks[i];
  4447. // Pass in the delegate so that if this packet needs to be resent, we send the current properties
  4448. // of the object rather than the properties when the packet was created
  4449. // List<ObjectPropertyUpdate> updates = new List<ObjectPropertyUpdate>();
  4450. // updates.Add(familyUpdates.Value[i]);
  4451. // HACK : Remove intelligent resending until it's fixed in core
  4452. //OutPacket(packet, ThrottleOutPacketType.Task, true,
  4453. // delegate(OutgoingPacket oPacket)
  4454. // {
  4455. // ResendPropertyUpdates(updates, oPacket);
  4456. // });
  4457. OutPacket(packet, ThrottleOutPacketType.Task, true);
  4458. }
  4459. }
  4460. if(needPhysics != null)
  4461. {
  4462. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  4463. if(eq != null)
  4464. {
  4465. StringBuilder sb = eq.StartEvent("ObjectPhysicsProperties");
  4466. LLSDxmlEncode.AddArray("ObjectData", sb);
  4467. foreach (SceneObjectPart sop in needPhysics)
  4468. {
  4469. LLSDxmlEncode.AddMap(sb);
  4470. LLSDxmlEncode.AddElem("LocalID",(int)sop.LocalId, sb);
  4471. LLSDxmlEncode.AddElem("Density", sop.Density, sb);
  4472. LLSDxmlEncode.AddElem("Friction", sop.Friction, sb);
  4473. LLSDxmlEncode.AddElem("GravityMultiplier", sop.GravityModifier, sb);
  4474. LLSDxmlEncode.AddElem("Restitution", sop.Restitution, sb);
  4475. LLSDxmlEncode.AddElem("PhysicsShapeType", (int)sop.PhysicsShapeType, sb);
  4476. LLSDxmlEncode.AddEndMap(sb);
  4477. }
  4478. LLSDxmlEncode.AddEndArray(sb);
  4479. OSDllsdxml ev = new OSDllsdxml(eq.EndEvent(sb));
  4480. eq.Enqueue(ev, AgentId);
  4481. }
  4482. }
  4483. }
  4484. private ObjectPropertiesFamilyPacket.ObjectDataBlock CreateObjectPropertiesFamilyBlock(SceneObjectPart sop, PrimUpdateFlags requestFlags)
  4485. {
  4486. ObjectPropertiesFamilyPacket.ObjectDataBlock block = new ObjectPropertiesFamilyPacket.ObjectDataBlock();
  4487. block.RequestFlags = (uint)requestFlags;
  4488. block.ObjectID = sop.UUID;
  4489. if (sop.OwnerID == sop.GroupID)
  4490. block.OwnerID = UUID.Zero;
  4491. else
  4492. block.OwnerID = sop.OwnerID;
  4493. block.GroupID = sop.GroupID;
  4494. block.BaseMask = sop.BaseMask;
  4495. block.OwnerMask = sop.OwnerMask;
  4496. block.GroupMask = sop.GroupMask;
  4497. block.EveryoneMask = sop.EveryoneMask;
  4498. block.NextOwnerMask = sop.NextOwnerMask;
  4499. // TODO: More properties are needed in SceneObjectPart!
  4500. block.OwnershipCost = sop.OwnershipCost;
  4501. block.SaleType = sop.ObjectSaleType;
  4502. block.SalePrice = sop.SalePrice;
  4503. block.Category = sop.Category;
  4504. block.LastOwnerID = sop.LastOwnerID;
  4505. block.Name = Util.StringToBytes256(sop.Name);
  4506. block.Description = Util.StringToBytes256(sop.Description);
  4507. return block;
  4508. }
  4509. private ObjectPropertiesPacket.ObjectDataBlock CreateObjectPropertiesBlock(SceneObjectPart sop)
  4510. {
  4511. //ObjectPropertiesPacket proper = (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties);
  4512. // TODO: don't create new blocks if recycling an old packet
  4513. ObjectPropertiesPacket.ObjectDataBlock block =
  4514. new ObjectPropertiesPacket.ObjectDataBlock();
  4515. block.ObjectID = sop.UUID;
  4516. block.Name = Util.StringToBytes256(sop.Name);
  4517. block.Description = Util.StringToBytes256(sop.Description);
  4518. block.CreationDate = (ulong)sop.CreationDate * 1000000; // viewer wants date in microseconds
  4519. block.CreatorID = sop.CreatorID;
  4520. block.GroupID = sop.GroupID;
  4521. block.LastOwnerID = sop.LastOwnerID;
  4522. if (sop.OwnerID == sop.GroupID)
  4523. block.OwnerID = UUID.Zero;
  4524. else
  4525. block.OwnerID = sop.OwnerID;
  4526. block.ItemID = sop.FromUserInventoryItemID;
  4527. block.FolderID = UUID.Zero; // sog.FromFolderID ??
  4528. block.FromTaskID = UUID.Zero; // ???
  4529. block.InventorySerial = (short)sop.InventorySerial;
  4530. SceneObjectPart root = sop.ParentGroup.RootPart;
  4531. block.TouchName = Util.StringToBytes256(root.TouchName);
  4532. // SL 3.3.4, at least, appears to read this information as a concatenated byte[] stream of UUIDs but
  4533. // it's not yet clear whether this is actually used. If this is done in the future then a pre-cached
  4534. // copy is really needed since it's less efficient to be constantly recreating this byte array.
  4535. // using (MemoryStream memStream = new MemoryStream())
  4536. // {
  4537. // using (BinaryWriter binWriter = new BinaryWriter(memStream))
  4538. // {
  4539. // for (int i = 0; i < sop.GetNumberOfSides(); i++)
  4540. // {
  4541. // Primitive.TextureEntryFace teFace = sop.Shape.Textures.FaceTextures[i];
  4542. //
  4543. // UUID textureID;
  4544. //
  4545. // if (teFace != null)
  4546. // textureID = teFace.TextureID;
  4547. // else
  4548. // textureID = sop.Shape.Textures.DefaultTexture.TextureID;
  4549. //
  4550. // binWriter.Write(textureID.GetBytes());
  4551. // }
  4552. //
  4553. // block.TextureID = memStream.ToArray();
  4554. // }
  4555. // }
  4556. block.TextureID = new byte[0]; // TextureID ???
  4557. block.SitName = Util.StringToBytes256(root.SitName);
  4558. block.OwnerMask = root.OwnerMask;
  4559. block.NextOwnerMask = root.NextOwnerMask;
  4560. block.GroupMask = root.GroupMask;
  4561. block.EveryoneMask = root.EveryoneMask;
  4562. block.BaseMask = root.BaseMask;
  4563. block.SaleType = root.ObjectSaleType;
  4564. block.SalePrice = root.SalePrice;
  4565. return block;
  4566. }
  4567. #region Estate Data Sending Methods
  4568. private static bool convertParamStringToBool(byte[] field)
  4569. {
  4570. string s = Utils.BytesToString(field);
  4571. if (s == "1" || s.ToLower() == "y" || s.ToLower() == "yes" || s.ToLower() == "t" || s.ToLower() == "true")
  4572. {
  4573. return true;
  4574. }
  4575. return false;
  4576. }
  4577. public void SendEstateList(UUID invoice, int code, UUID[] Data, uint estateID)
  4578. {
  4579. int TotalnumberIDs = Data.Length;
  4580. int numberIDs;
  4581. int IDIndex = 0;
  4582. do
  4583. {
  4584. if(TotalnumberIDs > 63)
  4585. numberIDs = 63;
  4586. else
  4587. numberIDs = TotalnumberIDs;
  4588. TotalnumberIDs -= numberIDs;
  4589. EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
  4590. packet.AgentData.TransactionID = UUID.Random();
  4591. packet.AgentData.AgentID = AgentId;
  4592. packet.AgentData.SessionID = SessionId;
  4593. packet.MethodData.Invoice = invoice;
  4594. packet.MethodData.Method = Utils.StringToBytes("setaccess");
  4595. EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[6 + numberIDs];
  4596. for (int i = 0; i < (6 + numberIDs); i++)
  4597. {
  4598. returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
  4599. }
  4600. returnblock[0].Parameter = Utils.StringToBytes(estateID.ToString());
  4601. returnblock[1].Parameter = Utils.StringToBytes(code.ToString());
  4602. if((code & 1) != 0) // allowagents
  4603. returnblock[2].Parameter = Utils.StringToBytes(numberIDs.ToString());
  4604. else
  4605. returnblock[2].Parameter = Utils.StringToBytes("0");
  4606. if((code & 2) != 0) // groups
  4607. returnblock[3].Parameter = Utils.StringToBytes(numberIDs.ToString());
  4608. else
  4609. returnblock[3].Parameter = Utils.StringToBytes("0");
  4610. if((code & 4) != 0) // bans
  4611. returnblock[4].Parameter = Utils.StringToBytes(numberIDs.ToString());
  4612. else
  4613. returnblock[4].Parameter = Utils.StringToBytes("0");
  4614. if((code & 8) != 0) // managers
  4615. returnblock[5].Parameter = Utils.StringToBytes(numberIDs.ToString());
  4616. else
  4617. returnblock[5].Parameter = Utils.StringToBytes("0");
  4618. int j = 6;
  4619. for (int i = 0; i < numberIDs; i++)
  4620. {
  4621. returnblock[j].Parameter = Data[IDIndex].GetBytes();
  4622. j++;
  4623. IDIndex++;
  4624. }
  4625. packet.ParamList = returnblock;
  4626. packet.Header.Reliable = true;
  4627. OutPacket(packet, ThrottleOutPacketType.Task);
  4628. } while (TotalnumberIDs > 0);
  4629. }
  4630. public void SendBannedUserList(UUID invoice, EstateBan[] bl, uint estateID)
  4631. {
  4632. List<UUID> BannedUsers = new List<UUID>();
  4633. for (int i = 0; i < bl.Length; i++)
  4634. {
  4635. if (bl[i] == null)
  4636. continue;
  4637. if (bl[i].BannedUserID == UUID.Zero)
  4638. continue;
  4639. BannedUsers.Add(bl[i].BannedUserID);
  4640. }
  4641. SendEstateList(invoice, 4, BannedUsers.ToArray(), estateID);
  4642. }
  4643. public void SendRegionInfoToEstateMenu(RegionInfoForEstateMenuArgs args)
  4644. {
  4645. RegionInfoPacket rinfopack = new RegionInfoPacket();
  4646. RegionInfoPacket.RegionInfoBlock rinfoblk = new RegionInfoPacket.RegionInfoBlock();
  4647. rinfopack.AgentData.AgentID = AgentId;
  4648. rinfopack.AgentData.SessionID = SessionId;
  4649. rinfoblk.BillableFactor = args.billableFactor;
  4650. rinfoblk.EstateID = args.estateID;
  4651. rinfoblk.MaxAgents = args.maxAgents;
  4652. rinfoblk.ObjectBonusFactor = args.objectBonusFactor;
  4653. rinfoblk.ParentEstateID = args.parentEstateID;
  4654. rinfoblk.PricePerMeter = args.pricePerMeter;
  4655. rinfoblk.RedirectGridX = args.redirectGridX;
  4656. rinfoblk.RedirectGridY = args.redirectGridY;
  4657. rinfoblk.RegionFlags = args.regionFlags;
  4658. rinfoblk.SimAccess = args.simAccess;
  4659. rinfoblk.SunHour = args.sunHour;
  4660. rinfoblk.TerrainLowerLimit = args.terrainLowerLimit;
  4661. rinfoblk.TerrainRaiseLimit = args.terrainRaiseLimit;
  4662. rinfoblk.UseEstateSun = args.useEstateSun;
  4663. rinfoblk.WaterHeight = args.waterHeight;
  4664. rinfoblk.SimName = Utils.StringToBytes(args.simName);
  4665. rinfopack.RegionInfo2 = new RegionInfoPacket.RegionInfo2Block();
  4666. rinfopack.RegionInfo2.HardMaxAgents = uint.MaxValue;
  4667. rinfopack.RegionInfo2.HardMaxObjects = uint.MaxValue;
  4668. rinfopack.RegionInfo2.MaxAgents32 = uint.MaxValue;
  4669. rinfopack.RegionInfo2.ProductName = Util.StringToBytes256(args.regionType);
  4670. rinfopack.RegionInfo2.ProductSKU = Utils.EmptyBytes;
  4671. rinfopack.HasVariableBlocks = true;
  4672. rinfopack.RegionInfo = rinfoblk;
  4673. rinfopack.AgentData = new RegionInfoPacket.AgentDataBlock();
  4674. rinfopack.AgentData.AgentID = AgentId;
  4675. rinfopack.AgentData.SessionID = SessionId;
  4676. rinfopack.RegionInfo3 = new RegionInfoPacket.RegionInfo3Block[0];
  4677. OutPacket(rinfopack, ThrottleOutPacketType.Task);
  4678. }
  4679. public void SendEstateCovenantInformation(UUID covenant)
  4680. {
  4681. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending estate covenant asset id of {0} to {1}", covenant, Name);
  4682. EstateCovenantReplyPacket einfopack = new EstateCovenantReplyPacket();
  4683. EstateCovenantReplyPacket.DataBlock edata = new EstateCovenantReplyPacket.DataBlock();
  4684. edata.CovenantID = covenant;
  4685. edata.CovenantTimestamp = (uint) m_scene.RegionInfo.RegionSettings.CovenantChangedDateTime;
  4686. edata.EstateOwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  4687. edata.EstateName = Utils.StringToBytes(m_scene.RegionInfo.EstateSettings.EstateName);
  4688. einfopack.Data = edata;
  4689. OutPacket(einfopack, ThrottleOutPacketType.Task);
  4690. }
  4691. public void SendDetailedEstateData(
  4692. UUID invoice, string estateName, uint estateID, uint parentEstate, uint estateFlags, uint sunPosition,
  4693. UUID covenant, uint covenantChanged, string abuseEmail, UUID estateOwner)
  4694. {
  4695. // m_log.DebugFormat(
  4696. // "[LLCLIENTVIEW]: Sending detailed estate data to {0} with covenant asset id {1}", Name, covenant);
  4697. EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
  4698. packet.MethodData.Invoice = invoice;
  4699. packet.AgentData.TransactionID = UUID.Random();
  4700. packet.MethodData.Method = Utils.StringToBytes("estateupdateinfo");
  4701. EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[10];
  4702. for (int i = 0; i < 10; i++)
  4703. {
  4704. returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
  4705. }
  4706. //Sending Estate Settings
  4707. returnblock[0].Parameter = Utils.StringToBytes(estateName);
  4708. returnblock[1].Parameter = Utils.StringToBytes(estateOwner.ToString());
  4709. returnblock[2].Parameter = Utils.StringToBytes(estateID.ToString());
  4710. returnblock[3].Parameter = Utils.StringToBytes(estateFlags.ToString());
  4711. returnblock[4].Parameter = Utils.StringToBytes(sunPosition.ToString());
  4712. returnblock[5].Parameter = Utils.StringToBytes(parentEstate.ToString());
  4713. returnblock[6].Parameter = Utils.StringToBytes(covenant.ToString());
  4714. returnblock[7].Parameter = Utils.StringToBytes(covenantChanged.ToString());
  4715. returnblock[8].Parameter = Utils.StringToBytes("1"); // what is this?
  4716. returnblock[9].Parameter = Utils.StringToBytes(abuseEmail);
  4717. packet.ParamList = returnblock;
  4718. //m_log.Debug("[ESTATE]: SIM--->" + packet.ToString());
  4719. OutPacket(packet, ThrottleOutPacketType.Task);
  4720. }
  4721. public void SendTelehubInfo(UUID ObjectID, string ObjectName, Vector3 ObjectPos, Quaternion ObjectRot, List<Vector3> SpawnPoint)
  4722. {
  4723. TelehubInfoPacket packet = (TelehubInfoPacket)PacketPool.Instance.GetPacket(PacketType.TelehubInfo);
  4724. packet.TelehubBlock.ObjectID = ObjectID;
  4725. packet.TelehubBlock.ObjectName = Utils.StringToBytes(ObjectName);
  4726. packet.TelehubBlock.TelehubPos = ObjectPos;
  4727. packet.TelehubBlock.TelehubRot = ObjectRot;
  4728. packet.SpawnPointBlock = new TelehubInfoPacket.SpawnPointBlockBlock[SpawnPoint.Count];
  4729. for (int n = 0; n < SpawnPoint.Count; n++)
  4730. {
  4731. packet.SpawnPointBlock[n] = new TelehubInfoPacket.SpawnPointBlockBlock{SpawnPointPos = SpawnPoint[n]};
  4732. }
  4733. OutPacket(packet, ThrottleOutPacketType.Task);
  4734. }
  4735. #endregion
  4736. #region Land Data Sending Methods
  4737. public void SendLandParcelOverlay(byte[] data, int sequence_id)
  4738. {
  4739. ParcelOverlayPacket packet = (ParcelOverlayPacket)PacketPool.Instance.GetPacket(PacketType.ParcelOverlay);
  4740. packet.ParcelData.Data = data;
  4741. packet.ParcelData.SequenceID = sequence_id;
  4742. // OutPacket(packet, ThrottleOutPacketType.Task);
  4743. OutPacket(packet, ThrottleOutPacketType.Land);
  4744. }
  4745. public void SendLandProperties(
  4746. int sequence_id, bool snap_selection, int request_result, ILandObject lo,
  4747. float simObjectBonusFactor, int parcelObjectCapacity, int simObjectCapacity, uint regionFlags)
  4748. {
  4749. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending land properties for {0} to {1}", lo.LandData.GlobalID, Name);
  4750. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  4751. if (eq == null)
  4752. {
  4753. m_log.Warn("[LLCLIENTVIEW]: No EQ Interface when sending parcel data.");
  4754. return;
  4755. }
  4756. LandData landData = lo.LandData;
  4757. IPrimCounts pc = lo.PrimCounts;
  4758. StringBuilder sb = eq.StartEvent("ParcelProperties");
  4759. LLSDxmlEncode.AddArrayAndMap("ParcelData", sb);
  4760. LLSDxmlEncode.AddElem("LocalID", landData.LocalID, sb);
  4761. LLSDxmlEncode.AddElem("AABBMax", landData.AABBMax, sb);
  4762. LLSDxmlEncode.AddElem("AABBMin", landData.AABBMin, sb);
  4763. LLSDxmlEncode.AddElem("Area", landData.Area, sb);
  4764. LLSDxmlEncode.AddElem("AuctionID", (int)landData.AuctionID, sb);
  4765. LLSDxmlEncode.AddElem("AuthBuyerID", landData.AuthBuyerID, sb);
  4766. LLSDxmlEncode.AddElem("Bitmap", landData.Bitmap, sb);
  4767. LLSDxmlEncode.AddElem("Category", (int)landData.Category, sb);
  4768. LLSDxmlEncode.AddElem("ClaimDate", Util.ToDateTime(landData.ClaimDate), sb);
  4769. LLSDxmlEncode.AddElem("ClaimPrice", landData.ClaimPrice, sb);
  4770. LLSDxmlEncode.AddElem("Desc", landData.Description, sb);
  4771. LLSDxmlEncode.AddElem("ParcelFlags", landData.Flags, sb);
  4772. LLSDxmlEncode.AddElem("GroupID", landData.GroupID, sb);
  4773. LLSDxmlEncode.AddElem("GroupPrims", pc.Group, sb);
  4774. LLSDxmlEncode.AddElem("IsGroupOwned", landData.IsGroupOwned, sb);
  4775. LLSDxmlEncode.AddElem("LandingType", (int)landData.LandingType, sb);
  4776. if (landData.Area > 0)
  4777. LLSDxmlEncode.AddElem("MaxPrims", parcelObjectCapacity, sb);
  4778. else
  4779. LLSDxmlEncode.AddElem("MaxPrims", (int)0, sb);
  4780. LLSDxmlEncode.AddElem("MediaID", landData.MediaID, sb);
  4781. LLSDxmlEncode.AddElem("MediaURL", landData.MediaURL, sb);
  4782. LLSDxmlEncode.AddElem("MediaAutoScale", landData.MediaAutoScale != 0, sb);
  4783. LLSDxmlEncode.AddElem("MusicURL", landData.MusicURL, sb);
  4784. LLSDxmlEncode.AddElem("Name", landData.Name, sb);
  4785. LLSDxmlEncode.AddElem("OtherCleanTime", landData.OtherCleanTime, sb);
  4786. LLSDxmlEncode.AddElem("OtherCount", (int)0 , sb); //TODO
  4787. LLSDxmlEncode.AddElem("OtherPrims", pc.Others, sb);
  4788. LLSDxmlEncode.AddElem("OwnerID", landData.OwnerID, sb);
  4789. LLSDxmlEncode.AddElem("OwnerPrims", pc.Owner, sb);
  4790. LLSDxmlEncode.AddElem("ParcelPrimBonus", simObjectBonusFactor, sb);
  4791. LLSDxmlEncode.AddElem("PassHours", landData.PassHours, sb);
  4792. LLSDxmlEncode.AddElem("PassPrice", landData.PassPrice, sb);
  4793. LLSDxmlEncode.AddElem("PublicCount", (int)0, sb); //TODO
  4794. LLSDxmlEncode.AddElem("RegionDenyAnonymous", (regionFlags & (uint)RegionFlags.DenyAnonymous) != 0, sb);
  4795. //LLSDxmlEncode.AddElem("RegionDenyIdentified", (regionFlags & (uint)RegionFlags.DenyIdentified) != 0, sb);
  4796. LLSDxmlEncode.AddElem("RegionDenyIdentified", false, sb);
  4797. //LLSDxmlEncode.AddElem("RegionDenyTransacted", (regionFlags & (uint)RegionFlags.DenyTransacted) != 0, sb);
  4798. LLSDxmlEncode.AddElem("RegionDenyTransacted", false, sb);
  4799. LLSDxmlEncode.AddElem("RegionPushOverride", (regionFlags & (uint)RegionFlags.RestrictPushObject) != 0, sb);
  4800. LLSDxmlEncode.AddElem("RentPrice", (int) 0, sb);;
  4801. LLSDxmlEncode.AddElem("RequestResult", request_result, sb);
  4802. LLSDxmlEncode.AddElem("SalePrice", landData.SalePrice, sb);
  4803. LLSDxmlEncode.AddElem("SelectedPrims", pc.Selected, sb);
  4804. LLSDxmlEncode.AddElem("SelfCount", (int)0, sb); //TODO
  4805. LLSDxmlEncode.AddElem("SequenceID", sequence_id, sb);
  4806. if (landData.SimwideArea > 0)
  4807. LLSDxmlEncode.AddElem("SimWideMaxPrims", lo.GetSimulatorMaxPrimCount(), sb);
  4808. else
  4809. LLSDxmlEncode.AddElem("SimWideMaxPrims", (int)0, sb);
  4810. LLSDxmlEncode.AddElem("SimWideTotalPrims", pc.Simulator, sb);
  4811. LLSDxmlEncode.AddElem("SnapSelection", snap_selection, sb);
  4812. LLSDxmlEncode.AddElem("SnapshotID", landData.SnapshotID, sb);
  4813. LLSDxmlEncode.AddElem("Status", (int)landData.Status, sb);
  4814. LLSDxmlEncode.AddElem("TotalPrims", pc.Total, sb);
  4815. LLSDxmlEncode.AddElem("UserLocation", landData.UserLocation, sb);
  4816. LLSDxmlEncode.AddElem("UserLookAt", landData.UserLookAt, sb);
  4817. LLSDxmlEncode.AddElem("SeeAVs", landData.SeeAVs, sb);
  4818. LLSDxmlEncode.AddElem("AnyAVSounds", landData.AnyAVSounds, sb);
  4819. LLSDxmlEncode.AddElem("GroupAVSounds", landData.GroupAVSounds, sb);
  4820. LLSDxmlEncode.AddEndMapAndArray(sb);
  4821. LLSDxmlEncode.AddArrayAndMap("MediaData", sb);
  4822. LLSDxmlEncode.AddElem("MediaDesc", landData.MediaDescription, sb);
  4823. LLSDxmlEncode.AddElem("MediaHeight", landData.MediaHeight, sb);
  4824. LLSDxmlEncode.AddElem("MediaWidth", landData.MediaWidth, sb);
  4825. LLSDxmlEncode.AddElem("MediaLoop", landData.MediaLoop, sb);
  4826. LLSDxmlEncode.AddElem("MediaType", landData.MediaType, sb);
  4827. LLSDxmlEncode.AddElem("ObscureMedia", landData.ObscureMedia, sb);
  4828. LLSDxmlEncode.AddElem("ObscureMusic", landData.ObscureMusic, sb);
  4829. LLSDxmlEncode.AddEndMapAndArray(sb);
  4830. LLSDxmlEncode.AddArrayAndMap("AgeVerificationBlock", sb);
  4831. //LLSDxmlEncode.AddElem("RegionDenyAgeUnverified", (regionFlags & (uint)RegionFlags.DenyAgeUnverified) != 0, sb);
  4832. LLSDxmlEncode.AddElem("RegionDenyAgeUnverified", false, sb);
  4833. LLSDxmlEncode.AddEndMapAndArray(sb);
  4834. OSDllsdxml ev = new OSDllsdxml(eq.EndEvent(sb));
  4835. eq.Enqueue(ev, AgentId);
  4836. }
  4837. public void SendLandAccessListData(List<LandAccessEntry> accessList, uint accessFlag, int localLandID)
  4838. {
  4839. ParcelAccessListReplyPacket replyPacket = (ParcelAccessListReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelAccessListReply);
  4840. replyPacket.Data.AgentID = AgentId;
  4841. replyPacket.Data.Flags = accessFlag;
  4842. replyPacket.Data.LocalID = localLandID;
  4843. replyPacket.Data.SequenceID = 0;
  4844. List<ParcelAccessListReplyPacket.ListBlock> list = new List<ParcelAccessListReplyPacket.ListBlock>();
  4845. foreach (LandAccessEntry entry in accessList)
  4846. {
  4847. ParcelAccessListReplyPacket.ListBlock block = new ParcelAccessListReplyPacket.ListBlock();
  4848. block.Flags = accessFlag;
  4849. block.ID = entry.AgentID;
  4850. block.Time = entry.Expires;
  4851. list.Add(block);
  4852. }
  4853. replyPacket.List = list.ToArray();
  4854. replyPacket.Header.Zerocoded = true;
  4855. OutPacket(replyPacket, ThrottleOutPacketType.Task);
  4856. }
  4857. public void SendForceClientSelectObjects(List<uint> ObjectIDs)
  4858. {
  4859. // m_log.DebugFormat("[LLCLIENTVIEW] sending select with {0} objects", ObjectIDs.Count);
  4860. bool firstCall = true;
  4861. const int MAX_OBJECTS_PER_PACKET = 251;
  4862. ForceObjectSelectPacket pack = (ForceObjectSelectPacket)PacketPool.Instance.GetPacket(PacketType.ForceObjectSelect);
  4863. ForceObjectSelectPacket.DataBlock[] data;
  4864. while (ObjectIDs.Count > 0)
  4865. {
  4866. if (firstCall)
  4867. {
  4868. pack._Header.ResetList = true;
  4869. firstCall = false;
  4870. }
  4871. else
  4872. {
  4873. pack._Header.ResetList = false;
  4874. }
  4875. if (ObjectIDs.Count > MAX_OBJECTS_PER_PACKET)
  4876. {
  4877. data = new ForceObjectSelectPacket.DataBlock[MAX_OBJECTS_PER_PACKET];
  4878. }
  4879. else
  4880. {
  4881. data = new ForceObjectSelectPacket.DataBlock[ObjectIDs.Count];
  4882. }
  4883. int i;
  4884. for (i = 0; i < MAX_OBJECTS_PER_PACKET && ObjectIDs.Count > 0; i++)
  4885. {
  4886. data[i] = new ForceObjectSelectPacket.DataBlock();
  4887. data[i].LocalID = Convert.ToUInt32(ObjectIDs[0]);
  4888. ObjectIDs.RemoveAt(0);
  4889. }
  4890. pack.Data = data;
  4891. pack.Header.Zerocoded = true;
  4892. OutPacket(pack, ThrottleOutPacketType.Task);
  4893. }
  4894. }
  4895. public void SendCameraConstraint(Vector4 ConstraintPlane)
  4896. {
  4897. CameraConstraintPacket cpack = (CameraConstraintPacket)PacketPool.Instance.GetPacket(PacketType.CameraConstraint);
  4898. cpack.CameraCollidePlane = new CameraConstraintPacket.CameraCollidePlaneBlock();
  4899. cpack.CameraCollidePlane.Plane = ConstraintPlane;
  4900. //m_log.DebugFormat("[CLIENTVIEW]: Constraint {0}", ConstraintPlane);
  4901. OutPacket(cpack, ThrottleOutPacketType.Task);
  4902. }
  4903. public void SendLandObjectOwners(LandData land, List<UUID> groups, Dictionary<UUID, int> ownersAndCount)
  4904. {
  4905. int notifyCount = ownersAndCount.Count;
  4906. ParcelObjectOwnersReplyPacket pack = (ParcelObjectOwnersReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelObjectOwnersReply);
  4907. if (notifyCount > 0)
  4908. {
  4909. // if (notifyCount > 32)
  4910. // {
  4911. // m_log.InfoFormat(
  4912. // "[LAND]: More than {0} avatars own prims on this parcel. Only sending back details of first {0}"
  4913. // + " - a developer might want to investigate whether this is a hard limit", 32);
  4914. //
  4915. // notifyCount = 32;
  4916. // }
  4917. ParcelObjectOwnersReplyPacket.DataBlock[] dataBlock
  4918. = new ParcelObjectOwnersReplyPacket.DataBlock[notifyCount];
  4919. int num = 0;
  4920. foreach (UUID owner in ownersAndCount.Keys)
  4921. {
  4922. dataBlock[num] = new ParcelObjectOwnersReplyPacket.DataBlock();
  4923. dataBlock[num].Count = ownersAndCount[owner];
  4924. if (land.GroupID == owner || groups.Contains(owner))
  4925. dataBlock[num].IsGroupOwned = true;
  4926. dataBlock[num].OnlineStatus = true; //TODO: fix me later
  4927. dataBlock[num].OwnerID = owner;
  4928. num++;
  4929. if (num >= notifyCount)
  4930. {
  4931. break;
  4932. }
  4933. }
  4934. pack.Data = dataBlock;
  4935. }
  4936. else
  4937. {
  4938. pack.Data = new ParcelObjectOwnersReplyPacket.DataBlock[0];
  4939. }
  4940. pack.Header.Zerocoded = true;
  4941. this.OutPacket(pack, ThrottleOutPacketType.Task);
  4942. }
  4943. #endregion
  4944. #region Helper Methods
  4945. private void ClampVectorForUint(ref Vector3 v, float max)
  4946. {
  4947. float a,b;
  4948. a = Math.Abs(v.X);
  4949. b = Math.Abs(v.Y);
  4950. if(b > a)
  4951. a = b;
  4952. b= Math.Abs(v.Z);
  4953. if(b > a)
  4954. a = b;
  4955. if (a > max)
  4956. {
  4957. a = max / a;
  4958. v.X *= a;
  4959. v.Y *= a;
  4960. v.Z *= a;
  4961. }
  4962. }
  4963. protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedTerseBlock(ISceneEntity entity)
  4964. {
  4965. #region ScenePresence/SOP Handling
  4966. bool avatar = (entity is ScenePresence);
  4967. uint localID = entity.LocalId;
  4968. uint attachPoint;
  4969. Vector4 collisionPlane;
  4970. Vector3 position, velocity, acceleration, angularVelocity;
  4971. Quaternion rotation;
  4972. if (avatar)
  4973. {
  4974. ScenePresence presence = (ScenePresence)entity;
  4975. position = presence.OffsetPosition;
  4976. velocity = presence.Velocity;
  4977. acceleration = Vector3.Zero;
  4978. rotation = presence.Rotation;
  4979. // tpvs can only see rotations around Z in some cases
  4980. if(!presence.Flying && !presence.IsSatOnObject)
  4981. {
  4982. rotation.X = 0f;
  4983. rotation.Y = 0f;
  4984. }
  4985. rotation.Normalize();
  4986. angularVelocity = presence.AngularVelocity;
  4987. // m_log.DebugFormat(
  4988. // "[LLCLIENTVIEW]: Sending terse update to {0} with position {1} in {2}", Name, presence.OffsetPosition, m_scene.Name);
  4989. attachPoint = presence.State;
  4990. collisionPlane = presence.CollisionPlane;
  4991. }
  4992. else
  4993. {
  4994. SceneObjectPart part = (SceneObjectPart)entity;
  4995. attachPoint = part.ParentGroup.AttachmentPoint;
  4996. attachPoint = ((attachPoint % 16) * 16 + (attachPoint / 16));
  4997. // m_log.DebugFormat(
  4998. // "[LLCLIENTVIEW]: Sending attachPoint {0} for {1} {2} to {3}",
  4999. // attachPoint, part.Name, part.LocalId, Name);
  5000. collisionPlane = Vector4.Zero;
  5001. position = part.RelativePosition;
  5002. velocity = part.Velocity;
  5003. acceleration = part.Acceleration;
  5004. angularVelocity = part.AngularVelocity;
  5005. rotation = part.RotationOffset;
  5006. }
  5007. #endregion ScenePresence/SOP Handling
  5008. int pos = 0;
  5009. byte[] data = new byte[(avatar ? 60 : 44)];
  5010. // LocalID
  5011. Utils.UIntToBytes(localID, data, pos);
  5012. pos += 4;
  5013. // Avatar/CollisionPlane
  5014. data[pos++] = (byte) attachPoint;
  5015. if (avatar)
  5016. {
  5017. data[pos++] = 1;
  5018. if (collisionPlane == Vector4.Zero)
  5019. collisionPlane = Vector4.UnitW;
  5020. //m_log.DebugFormat("CollisionPlane: {0}",collisionPlane);
  5021. collisionPlane.ToBytes(data, pos);
  5022. pos += 16;
  5023. }
  5024. else
  5025. {
  5026. ++pos;
  5027. }
  5028. // Position
  5029. position.ToBytes(data, pos);
  5030. pos += 12;
  5031. // Velocity
  5032. ClampVectorForUint(ref velocity, 128f);
  5033. Utils.FloatToUInt16Bytes(velocity.X, 128.0f, data, pos); pos += 2;
  5034. Utils.FloatToUInt16Bytes(velocity.Y, 128.0f, data, pos); pos += 2;
  5035. Utils.FloatToUInt16Bytes(velocity.Z, 128.0f, data, pos); pos += 2;
  5036. // Acceleration
  5037. ClampVectorForUint(ref acceleration, 64f);
  5038. Utils.FloatToUInt16Bytes(acceleration.X, 64.0f, data, pos); pos += 2;
  5039. Utils.FloatToUInt16Bytes(acceleration.Y, 64.0f, data, pos); pos += 2;
  5040. Utils.FloatToUInt16Bytes(acceleration.Z, 64.0f, data, pos); pos += 2;
  5041. // Rotation
  5042. Utils.FloatToUInt16Bytes(rotation.X, 1.0f, data, pos); pos += 2;
  5043. Utils.FloatToUInt16Bytes(rotation.Y, 1.0f, data, pos); pos += 2;
  5044. Utils.FloatToUInt16Bytes(rotation.Z, 1.0f, data, pos); pos += 2;
  5045. Utils.FloatToUInt16Bytes(rotation.W, 1.0f, data, pos); pos += 2;
  5046. // Angular Velocity
  5047. ClampVectorForUint(ref angularVelocity, 64f);
  5048. Utils.FloatToUInt16Bytes(angularVelocity.X, 64.0f, data, pos); pos += 2;
  5049. Utils.FloatToUInt16Bytes(angularVelocity.Y, 64.0f, data, pos); pos += 2;
  5050. Utils.FloatToUInt16Bytes(angularVelocity.Z, 64.0f, data, pos); pos += 2;
  5051. ImprovedTerseObjectUpdatePacket.ObjectDataBlock block
  5052. = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
  5053. block.Data = data;
  5054. block.TextureEntry = Utils.EmptyBytes;
  5055. return block;
  5056. }
  5057. protected void CreateImprovedTerseBlock(ISceneEntity entity, byte[] data, ref int pos, bool includeTexture)
  5058. {
  5059. #region ScenePresence/SOP Handling
  5060. bool avatar = (entity is ScenePresence);
  5061. uint localID = entity.LocalId;
  5062. uint attachPoint;
  5063. Vector4 collisionPlane;
  5064. Vector3 position, velocity, acceleration, angularVelocity;
  5065. Quaternion rotation;
  5066. byte datasize;
  5067. byte[] te = null;
  5068. if (avatar)
  5069. {
  5070. ScenePresence presence = (ScenePresence)entity;
  5071. position = presence.OffsetPosition;
  5072. velocity = presence.Velocity;
  5073. acceleration = Vector3.Zero;
  5074. rotation = presence.Rotation;
  5075. // tpvs can only see rotations around Z in some cases
  5076. if (!presence.Flying && !presence.IsSatOnObject)
  5077. {
  5078. rotation.X = 0f;
  5079. rotation.Y = 0f;
  5080. }
  5081. rotation.Normalize();
  5082. angularVelocity = presence.AngularVelocity;
  5083. // m_log.DebugFormat(
  5084. // "[LLCLIENTVIEW]: Sending terse update to {0} with position {1} in {2}", Name, presence.OffsetPosition, m_scene.Name);
  5085. attachPoint = presence.State;
  5086. collisionPlane = presence.CollisionPlane;
  5087. datasize = 60;
  5088. }
  5089. else
  5090. {
  5091. SceneObjectPart part = (SceneObjectPart)entity;
  5092. attachPoint = part.ParentGroup.AttachmentPoint;
  5093. attachPoint = ((attachPoint % 16) * 16 + (attachPoint / 16));
  5094. // m_log.DebugFormat(
  5095. // "[LLCLIENTVIEW]: Sending attachPoint {0} for {1} {2} to {3}",
  5096. // attachPoint, part.Name, part.LocalId, Name);
  5097. collisionPlane = Vector4.Zero;
  5098. position = part.RelativePosition;
  5099. velocity = part.Velocity;
  5100. acceleration = part.Acceleration;
  5101. angularVelocity = part.AngularVelocity;
  5102. rotation = part.RotationOffset;
  5103. datasize = 44;
  5104. if(includeTexture)
  5105. te = part.Shape.TextureEntry;
  5106. }
  5107. #endregion ScenePresence/SOP Handling
  5108. //object block size
  5109. data[pos++] = datasize;
  5110. // LocalID
  5111. Utils.UIntToBytes(localID, data, pos);
  5112. pos += 4;
  5113. data[pos++] = (byte)attachPoint;
  5114. // Avatar/CollisionPlane
  5115. if (avatar)
  5116. {
  5117. data[pos++] = 1;
  5118. if (collisionPlane == Vector4.Zero)
  5119. collisionPlane = Vector4.UnitW;
  5120. //m_log.DebugFormat("CollisionPlane: {0}",collisionPlane);
  5121. collisionPlane.ToBytes(data, pos);
  5122. pos += 16;
  5123. }
  5124. else
  5125. {
  5126. data[pos++] = 0;
  5127. }
  5128. // Position
  5129. position.ToBytes(data, pos);
  5130. pos += 12;
  5131. // Velocity
  5132. ClampVectorForUint(ref velocity, 128f);
  5133. Utils.FloatToUInt16Bytes(velocity.X, 128.0f, data, pos); pos += 2;
  5134. Utils.FloatToUInt16Bytes(velocity.Y, 128.0f, data, pos); pos += 2;
  5135. Utils.FloatToUInt16Bytes(velocity.Z, 128.0f, data, pos); pos += 2;
  5136. // Acceleration
  5137. ClampVectorForUint(ref acceleration, 64f);
  5138. Utils.FloatToUInt16Bytes(acceleration.X, 64.0f, data, pos); pos += 2;
  5139. Utils.FloatToUInt16Bytes(acceleration.Y, 64.0f, data, pos); pos += 2;
  5140. Utils.FloatToUInt16Bytes(acceleration.Z, 64.0f, data, pos); pos += 2;
  5141. // Rotation
  5142. Utils.FloatToUInt16Bytes(rotation.X, 1.0f, data, pos); pos += 2;
  5143. Utils.FloatToUInt16Bytes(rotation.Y, 1.0f, data, pos); pos += 2;
  5144. Utils.FloatToUInt16Bytes(rotation.Z, 1.0f, data, pos); pos += 2;
  5145. Utils.FloatToUInt16Bytes(rotation.W, 1.0f, data, pos); pos += 2;
  5146. // Angular Velocity
  5147. ClampVectorForUint(ref angularVelocity, 64f);
  5148. Utils.FloatToUInt16Bytes(angularVelocity.X, 64.0f, data, pos); pos += 2;
  5149. Utils.FloatToUInt16Bytes(angularVelocity.Y, 64.0f, data, pos); pos += 2;
  5150. Utils.FloatToUInt16Bytes(angularVelocity.Z, 64.0f, data, pos); pos += 2;
  5151. // texture entry block size
  5152. if(te == null)
  5153. {
  5154. data[pos++] = 0;
  5155. data[pos++] = 0;
  5156. }
  5157. else
  5158. {
  5159. int len = te.Length & 0x7fff;
  5160. int totlen = len + 4;
  5161. data[pos++] = (byte)totlen;
  5162. data[pos++] = (byte)(totlen >> 8);
  5163. data[pos++] = (byte)len; // wtf ???
  5164. data[pos++] = (byte)(len >> 8);
  5165. data[pos++] = 0;
  5166. data[pos++] = 0;
  5167. Buffer.BlockCopy(te, 0, data, pos, len);
  5168. pos += len;
  5169. }
  5170. // total size 63 or 47 + (texture size + 4)
  5171. }
  5172. protected ObjectUpdatePacket.ObjectDataBlock CreateAvatarUpdateBlock(ScenePresence data)
  5173. {
  5174. Quaternion rotation = data.Rotation;
  5175. // tpvs can only see rotations around Z in some cases
  5176. if(!data.Flying && !data.IsSatOnObject)
  5177. {
  5178. rotation.X = 0f;
  5179. rotation.Y = 0f;
  5180. }
  5181. rotation.Normalize();
  5182. // m_log.DebugFormat(
  5183. // "[LLCLIENTVIEW]: Sending full update to {0} with pos {1}, vel {2} in {3}", Name, data.OffsetPosition, data.Velocity, m_scene.Name);
  5184. byte[] objectData = new byte[76];
  5185. //Vector3 velocity = Vector3.Zero;
  5186. Vector3 acceleration = Vector3.Zero;
  5187. Vector3 angularvelocity = Vector3.Zero;
  5188. data.CollisionPlane.ToBytes(objectData, 0);
  5189. data.OffsetPosition.ToBytes(objectData, 16);
  5190. data.Velocity.ToBytes(objectData, 28);
  5191. acceleration.ToBytes(objectData, 40);
  5192. rotation.ToBytes(objectData, 52);
  5193. angularvelocity.ToBytes(objectData, 64);
  5194. ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock();
  5195. update.Data = Utils.EmptyBytes;
  5196. update.ExtraParams = Utils.EmptyBytes;
  5197. update.FullID = data.UUID;
  5198. update.ID = data.LocalId;
  5199. update.Material = (byte)Material.Flesh;
  5200. update.MediaURL = Utils.EmptyBytes;
  5201. update.NameValue = Utils.StringToBytes("FirstName STRING RW SV " + data.Firstname + "\nLastName STRING RW SV " +
  5202. data.Lastname + "\nTitle STRING RW SV " + data.Grouptitle);
  5203. update.ObjectData = objectData;
  5204. SceneObjectPart parentPart = data.ParentPart;
  5205. if (parentPart != null)
  5206. update.ParentID = parentPart.ParentGroup.LocalId;
  5207. else
  5208. update.ParentID = 0;
  5209. update.PathCurve = 16;
  5210. update.PathScaleX = 100;
  5211. update.PathScaleY = 100;
  5212. update.PCode = (byte)PCode.Avatar;
  5213. update.ProfileCurve = 1;
  5214. update.PSBlock = Utils.EmptyBytes;
  5215. update.Scale = data.Appearance.AvatarSize;
  5216. // update.Scale.Z -= 0.2f;
  5217. update.Text = Utils.EmptyBytes;
  5218. update.TextColor = new byte[4];
  5219. // Don't send texture anim for avatars - this has no meaning for them.
  5220. update.TextureAnim = Utils.EmptyBytes;
  5221. // Don't send texture entry for avatars here - this is accomplished via the AvatarAppearance packet
  5222. update.TextureEntry = Utils.EmptyBytes;
  5223. update.UpdateFlags = 0;
  5224. return update;
  5225. }
  5226. protected void CreateAvatarUpdateBlock(ScenePresence data, byte[] dest, ref int pos)
  5227. {
  5228. Quaternion rotation = data.Rotation;
  5229. // tpvs can only see rotations around Z in some cases
  5230. if (!data.Flying && !data.IsSatOnObject)
  5231. {
  5232. rotation.X = 0f;
  5233. rotation.Y = 0f;
  5234. }
  5235. rotation.Normalize();
  5236. //Vector3 velocity = Vector3.Zero;
  5237. //Vector3 acceleration = Vector3.Zero;
  5238. //Vector3 angularvelocity = Vector3.Zero;
  5239. Utils.UIntToBytesSafepos(data.LocalId, dest, pos); pos += 4;
  5240. dest[pos++] = 0; // state
  5241. data.UUID.ToBytes(dest, pos); pos += 16;
  5242. Utils.UIntToBytesSafepos(0 , dest, pos); pos += 4; // crc
  5243. dest[pos++] = (byte)PCode.Avatar;
  5244. dest[pos++] = (byte)Material.Flesh;
  5245. dest[pos++] = 0; // clickaction
  5246. data.Appearance.AvatarSize.ToBytes(dest, pos); pos += 12;
  5247. // objectdata block
  5248. dest[pos++] = 76;
  5249. data.CollisionPlane.ToBytes(dest, pos); pos += 16;
  5250. data.OffsetPosition.ToBytes(dest, pos); pos += 12;
  5251. data.Velocity.ToBytes(dest, pos); pos += 12;
  5252. //acceleration.ToBytes(dest, pos); pos += 12;
  5253. Array.Clear(dest, pos, 12); pos += 12;
  5254. rotation.ToBytes(dest, pos); pos += 12;
  5255. //angularvelocity.ToBytes(dest, pos); pos += 12;
  5256. Array.Clear(dest, pos, 12); pos += 12;
  5257. SceneObjectPart parentPart = data.ParentPart;
  5258. if (parentPart != null)
  5259. {
  5260. Utils.UIntToBytesSafepos(parentPart.ParentGroup.LocalId, dest, pos);
  5261. pos += 4;
  5262. }
  5263. else
  5264. {
  5265. // Utils.UIntToBytesSafepos(0, dest, pos);
  5266. // pos += 4;
  5267. dest[pos++] = 0;
  5268. dest[pos++] = 0;
  5269. dest[pos++] = 0;
  5270. dest[pos++] = 0;
  5271. }
  5272. //Utils.UIntToBytesSafepos(0, dest, pos); pos += 4; //update flags
  5273. dest[pos++] = 0;
  5274. dest[pos++] = 0;
  5275. dest[pos++] = 0;
  5276. dest[pos++] = 0;
  5277. //pbs
  5278. dest[pos++] = 16;
  5279. dest[pos++] = 1;
  5280. //Utils.UInt16ToBytes(0, dest, pos); pos += 2;
  5281. //Utils.UInt16ToBytes(0, dest, pos); pos += 2;
  5282. dest[pos++] = 0;
  5283. dest[pos++] = 0;
  5284. dest[pos++] = 0;
  5285. dest[pos++] = 0;
  5286. dest[pos++] = 100;
  5287. dest[pos++] = 100;
  5288. // rest of pbs is 0 (15), texture entry (2) and texture anim (1)
  5289. const int pbszeros = 15 + 2 + 1;
  5290. Array.Clear(dest, pos, pbszeros); pos += pbszeros;
  5291. //NameValue
  5292. byte[] nv = Utils.StringToBytes("FirstName STRING RW SV " + data.Firstname + "\nLastName STRING RW SV " +
  5293. data.Lastname + "\nTitle STRING RW SV " + data.Grouptitle);
  5294. int len = nv.Length;
  5295. dest[pos++] = (byte)len;
  5296. dest[pos++] = (byte)(len >> 8);
  5297. Buffer.BlockCopy(nv, 0, dest, pos, len); pos += len;
  5298. // data(2), text(1), text color(4), media url(1), PBblock(1), ExtramParams(1),
  5299. // sound id(16), sound owner(16) gain (4), flags (1), radius (4)
  5300. // jointtype(1) joint pivot(12) joint offset(12)
  5301. const int lastzeros = 2 + 1 + 4 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12;
  5302. Array.Clear(dest, pos, lastzeros); pos += lastzeros;
  5303. }
  5304. protected void CreateAvatarUpdateBlock(ScenePresence data, LLUDPZeroEncoder zc)
  5305. {
  5306. Quaternion rotation = data.Rotation;
  5307. // tpvs can only see rotations around Z in some cases
  5308. if (!data.Flying && !data.IsSatOnObject)
  5309. {
  5310. rotation.X = 0f;
  5311. rotation.Y = 0f;
  5312. }
  5313. rotation.Normalize();
  5314. zc.AddUInt(data.LocalId);
  5315. zc.AddByte(0);
  5316. zc.AddUUID(data.UUID);
  5317. zc.AddZeros(4); // crc unused
  5318. zc.AddByte((byte)PCode.Avatar);
  5319. zc.AddByte((byte)Material.Flesh);
  5320. zc.AddByte(0); // clickaction
  5321. zc.AddVector3(data.Appearance.AvatarSize);
  5322. // objectdata block
  5323. zc.AddByte(76); // fixed avatar block size
  5324. zc.AddVector4(data.CollisionPlane);
  5325. zc.AddVector3(data.OffsetPosition);
  5326. zc.AddVector3(data.Velocity);
  5327. //zc.AddVector3(acceleration);
  5328. zc.AddZeros(12);
  5329. zc.AddNormQuat(rotation);
  5330. //zc.AddVector3(angularvelocity);
  5331. zc.AddZeros(12);
  5332. SceneObjectPart parentPart = data.ParentPart;
  5333. if (parentPart != null)
  5334. zc.AddUInt(parentPart.ParentGroup.LocalId);
  5335. else
  5336. zc.AddZeros(4);
  5337. zc.AddZeros(4); //update flags
  5338. //pbs volume data 23
  5339. //texture entry 2
  5340. //texture anim (1)
  5341. const int pbszeros = 23 + 2 + 1;
  5342. zc.AddZeros(pbszeros);
  5343. //NameValue
  5344. byte[] nv = Utils.StringToBytes("FirstName STRING RW SV " + data.Firstname + "\nLastName STRING RW SV " +
  5345. data.Lastname + "\nTitle STRING RW SV " + data.Grouptitle);
  5346. int len = nv.Length;
  5347. zc.AddByte((byte)len);
  5348. zc.AddByte((byte)(len >> 8));
  5349. zc.AddBytes(nv, len);
  5350. // data(2), text(1), text color(4), media url(1), PBblock(1), ExtramParams(1),
  5351. // sound id(16), sound owner(16) gain (4), flags (1), radius (4)
  5352. // jointtype(1) joint pivot(12) joint offset(12)
  5353. const int lastzeros = 2 + 1 + 4 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12;
  5354. zc.AddZeros(lastzeros);
  5355. }
  5356. protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(SceneObjectPart part, ScenePresence sp)
  5357. {
  5358. byte[] objectData = new byte[60];
  5359. part.RelativePosition.ToBytes(objectData, 0);
  5360. part.Velocity.ToBytes(objectData, 12);
  5361. part.Acceleration.ToBytes(objectData, 24);
  5362. Quaternion rotation = part.RotationOffset;
  5363. rotation.Normalize();
  5364. rotation.ToBytes(objectData, 36);
  5365. part.AngularVelocity.ToBytes(objectData, 48);
  5366. ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock();
  5367. update.ClickAction = (byte)part.ClickAction;
  5368. update.CRC = 0;
  5369. update.ExtraParams = part.Shape.ExtraParams ?? Utils.EmptyBytes;
  5370. update.FullID = part.UUID;
  5371. update.ID = part.LocalId;
  5372. //update.JointAxisOrAnchor = Vector3.Zero; // These are deprecated
  5373. //update.JointPivot = Vector3.Zero;
  5374. //update.JointType = 0;
  5375. update.Material = part.Material;
  5376. if (part.ParentGroup.IsAttachment)
  5377. {
  5378. if (part.IsRoot)
  5379. {
  5380. update.NameValue = Util.StringToBytes256("AttachItemID STRING RW SV " + part.ParentGroup.FromItemID);
  5381. }
  5382. else
  5383. update.NameValue = Utils.EmptyBytes;
  5384. int st = (int)part.ParentGroup.AttachmentPoint;
  5385. update.State = (byte)(((st & 0xf0) >> 4) + ((st & 0x0f) << 4)); ;
  5386. }
  5387. else
  5388. {
  5389. update.NameValue = Utils.EmptyBytes;
  5390. update.State = part.Shape.State; // not sure about this
  5391. }
  5392. update.ObjectData = objectData;
  5393. update.ParentID = part.ParentID;
  5394. update.PathBegin = part.Shape.PathBegin;
  5395. update.PathCurve = part.Shape.PathCurve;
  5396. update.PathEnd = part.Shape.PathEnd;
  5397. update.PathRadiusOffset = part.Shape.PathRadiusOffset;
  5398. update.PathRevolutions = part.Shape.PathRevolutions;
  5399. update.PathScaleX = part.Shape.PathScaleX;
  5400. update.PathScaleY = part.Shape.PathScaleY;
  5401. update.PathShearX = part.Shape.PathShearX;
  5402. update.PathShearY = part.Shape.PathShearY;
  5403. update.PathSkew = part.Shape.PathSkew;
  5404. update.PathTaperX = part.Shape.PathTaperX;
  5405. update.PathTaperY = part.Shape.PathTaperY;
  5406. update.PathTwist = part.Shape.PathTwist;
  5407. update.PathTwistBegin = part.Shape.PathTwistBegin;
  5408. update.PCode = part.Shape.PCode;
  5409. update.ProfileBegin = part.Shape.ProfileBegin;
  5410. update.ProfileCurve = part.Shape.ProfileCurve;
  5411. ushort profileBegin = part.Shape.ProfileBegin;
  5412. ushort profileHollow = part.Shape.ProfileHollow;
  5413. if(part.Shape.SculptType == (byte)SculptType.Mesh) // filter out hack
  5414. {
  5415. update.ProfileCurve = (byte)(part.Shape.ProfileCurve & 0x0f);
  5416. // fix old values that confused viewers
  5417. if(profileBegin == 1)
  5418. profileBegin = 9375;
  5419. if(profileHollow == 1)
  5420. profileHollow = 27500;
  5421. // fix torus hole size Y that also confuse some viewers
  5422. if(update.ProfileCurve == (byte)ProfileShape.Circle && update.PathScaleY < 150)
  5423. update.PathScaleY = 150;
  5424. }
  5425. else
  5426. {
  5427. update.ProfileCurve = part.Shape.ProfileCurve;
  5428. }
  5429. update.ProfileHollow = profileHollow;
  5430. update.ProfileBegin = profileBegin;
  5431. update.ProfileEnd = part.Shape.ProfileEnd;
  5432. update.PSBlock = part.ParticleSystem ?? Utils.EmptyBytes;
  5433. update.TextColor = part.GetTextColor().GetBytes(false);
  5434. update.TextureAnim = part.TextureAnimation ?? Utils.EmptyBytes;
  5435. update.TextureEntry = part.Shape.TextureEntry ?? Utils.EmptyBytes;
  5436. update.Scale = part.Shape.Scale;
  5437. update.Text = Util.StringToBytes(part.Text, 255);
  5438. update.MediaURL = Util.StringToBytes(part.MediaUrl, 255);
  5439. #region PrimFlags
  5440. PrimFlags flags = (PrimFlags)m_scene.Permissions.GenerateClientFlags(part, sp);
  5441. // Don't send the CreateSelected flag to everyone
  5442. flags &= ~PrimFlags.CreateSelected;
  5443. if (sp.UUID == part.OwnerID)
  5444. {
  5445. if (part.CreateSelected)
  5446. {
  5447. // Only send this flag once, then unset it
  5448. flags |= PrimFlags.CreateSelected;
  5449. part.CreateSelected = false;
  5450. }
  5451. }
  5452. // m_log.DebugFormat(
  5453. // "[LLCLIENTVIEW]: Constructing client update for part {0} {1} with flags {2}, localId {3}",
  5454. // data.Name, update.FullID, flags, update.ID);
  5455. update.UpdateFlags = (uint)flags;
  5456. #endregion PrimFlags
  5457. bool hassound = part.Sound != UUID.Zero || part.SoundFlags != 0;
  5458. if (hassound)
  5459. {
  5460. update.Sound = part.Sound;
  5461. update.Gain = (float)part.SoundGain;
  5462. update.Radius = (float)part.SoundRadius;
  5463. update.Flags = part.SoundFlags;
  5464. }
  5465. if(hassound || update.PSBlock.Length > 1)
  5466. update.OwnerID = part.OwnerID;
  5467. switch ((PCode)part.Shape.PCode)
  5468. {
  5469. case PCode.Grass:
  5470. case PCode.Tree:
  5471. case PCode.NewTree:
  5472. update.Data = new byte[] { part.Shape.State };
  5473. break;
  5474. default:
  5475. update.Data = Utils.EmptyBytes;
  5476. break;
  5477. }
  5478. return update;
  5479. }
  5480. protected void CreatePrimUpdateBlock(SceneObjectPart part, ScenePresence sp, LLUDPZeroEncoder zc)
  5481. {
  5482. // prepare data
  5483. #region PrimFlags
  5484. // prim/update flags
  5485. PrimFlags primflags = (PrimFlags)m_scene.Permissions.GenerateClientFlags(part, sp);
  5486. // Don't send the CreateSelected flag to everyone
  5487. primflags &= ~PrimFlags.CreateSelected;
  5488. if (sp.UUID == part.OwnerID)
  5489. {
  5490. if (part.CreateSelected)
  5491. {
  5492. // Only send this flag once, then unset it
  5493. primflags |= PrimFlags.CreateSelected;
  5494. part.CreateSelected = false;
  5495. }
  5496. }
  5497. #endregion PrimFlags
  5498. // data block
  5499. byte[] data = null;
  5500. byte state = part.Shape.State;
  5501. PCode pcode = (PCode)part.Shape.PCode;
  5502. //vegetation is special so just do it inline
  5503. if(pcode == PCode.Grass || pcode == PCode.Tree || pcode == PCode.NewTree)
  5504. {
  5505. zc.AddUInt(part.LocalId);
  5506. zc.AddByte(state); // state
  5507. zc.AddUUID(part.UUID);
  5508. zc.AddZeros(4); // crc unused
  5509. zc.AddByte((byte)pcode);
  5510. // material 1
  5511. // clickaction 1
  5512. zc.AddZeros(2);
  5513. zc.AddVector3(part.Shape.Scale);
  5514. // objectdata block
  5515. zc.AddByte(60); // fixed object block size
  5516. zc.AddVector3(part.RelativePosition);
  5517. if (pcode == PCode.Grass)
  5518. zc.AddZeros(48);
  5519. else
  5520. {
  5521. zc.AddZeros(24);
  5522. Quaternion rot = part.RotationOffset;
  5523. rot.Normalize();
  5524. zc.AddNormQuat(rot);
  5525. zc.AddZeros(12);
  5526. }
  5527. zc.AddUInt(part.ParentID);
  5528. zc.AddUInt((uint)primflags); //update flags
  5529. /*
  5530. if (pcode == PCode.Grass)
  5531. {
  5532. //pbs volume data 23
  5533. //texture entry 2
  5534. //texture anim 1
  5535. //name value 2
  5536. // data 1
  5537. // text 5
  5538. // media url 1
  5539. // particle system 1
  5540. // Extraparams 1
  5541. // sound id 16
  5542. // ownwer 16
  5543. // sound gain 4
  5544. // sound flags 1
  5545. // sound radius 4
  5546. // jointtype 1
  5547. // joint pivot 12
  5548. // joint offset 12
  5549. zc.AddZeros(23 + 2 + 1 + 2 + 1 + 5 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12);
  5550. return;
  5551. }
  5552. */
  5553. //pbs volume data 23
  5554. //texture entry 2
  5555. //texture anim 1
  5556. //name value 2
  5557. zc.AddZeros(23 + 2 + 1 + 2);
  5558. //data: the tree type
  5559. zc.AddByte(1);
  5560. zc.AddZeros(1);
  5561. zc.AddByte(state);
  5562. // text 5
  5563. // media url 1
  5564. // particle system 1
  5565. // Extraparams 1
  5566. // sound id 16
  5567. // ownwer 16
  5568. // sound gain 4
  5569. // sound flags 1
  5570. // sound radius 4
  5571. // jointtype 1
  5572. // joint pivot 12
  5573. // joint offset 12
  5574. zc.AddZeros(5 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12);
  5575. return;
  5576. }
  5577. //NameValue and state
  5578. byte[] nv = null;
  5579. if (part.ParentGroup.IsAttachment)
  5580. {
  5581. if (part.IsRoot)
  5582. nv = Util.StringToBytes256("AttachItemID STRING RW SV " + part.ParentGroup.FromItemID);
  5583. int st = (int)part.ParentGroup.AttachmentPoint;
  5584. state = (byte)(((st & 0xf0) >> 4) + ((st & 0x0f) << 4)); ;
  5585. }
  5586. // filter out mesh faces hack
  5587. ushort profileBegin = part.Shape.ProfileBegin;
  5588. ushort profileHollow = part.Shape.ProfileHollow;
  5589. byte profileCurve = part.Shape.ProfileCurve;
  5590. byte pathScaleY = part.Shape.PathScaleY;
  5591. if (part.Shape.SculptType == (byte)SculptType.Mesh) // filter out hack
  5592. {
  5593. profileCurve = (byte)(part.Shape.ProfileCurve & 0x0f);
  5594. // fix old values that confused viewers
  5595. if (profileBegin == 1)
  5596. profileBegin = 9375;
  5597. if (profileHollow == 1)
  5598. profileHollow = 27500;
  5599. // fix torus hole size Y that also confuse some viewers
  5600. if (profileCurve == (byte)ProfileShape.Circle && pathScaleY < 150)
  5601. pathScaleY = 150;
  5602. }
  5603. // do encode the things
  5604. zc.AddUInt(part.LocalId);
  5605. zc.AddByte(state); // state
  5606. zc.AddUUID(part.UUID);
  5607. zc.AddZeros(4); // crc unused
  5608. zc.AddByte((byte)pcode);
  5609. zc.AddByte(part.Material);
  5610. zc.AddByte(part.ClickAction); // clickaction
  5611. zc.AddVector3(part.Shape.Scale);
  5612. // objectdata block
  5613. zc.AddByte(60); // fixed object block size
  5614. zc.AddVector3(part.RelativePosition);
  5615. zc.AddVector3(part.Velocity);
  5616. zc.AddVector3(part.Acceleration);
  5617. Quaternion rotation = part.RotationOffset;
  5618. rotation.Normalize();
  5619. zc.AddNormQuat(rotation);
  5620. zc.AddVector3(part.AngularVelocity);
  5621. zc.AddUInt(part.ParentID);
  5622. zc.AddUInt((uint)primflags); //update flags
  5623. //pbs
  5624. zc.AddByte(part.Shape.PathCurve);
  5625. zc.AddByte(profileCurve);
  5626. zc.AddUInt16(part.Shape.PathBegin);
  5627. zc.AddUInt16(part.Shape.PathEnd);
  5628. zc.AddByte(part.Shape.PathScaleX);
  5629. zc.AddByte(pathScaleY);
  5630. zc.AddByte(part.Shape.PathShearX);
  5631. zc.AddByte(part.Shape.PathShearY);
  5632. zc.AddByte((byte)part.Shape.PathTwist);
  5633. zc.AddByte((byte)part.Shape.PathTwistBegin);
  5634. zc.AddByte((byte)part.Shape.PathRadiusOffset);
  5635. zc.AddByte((byte)part.Shape.PathTaperX);
  5636. zc.AddByte((byte)part.Shape.PathTaperY);
  5637. zc.AddByte(part.Shape.PathRevolutions);
  5638. zc.AddByte((byte)part.Shape.PathSkew);
  5639. zc.AddUInt16(profileBegin);
  5640. zc.AddUInt16(part.Shape.ProfileEnd);
  5641. zc.AddUInt16(profileHollow);
  5642. // texture
  5643. byte[] tentry = part.Shape.TextureEntry;
  5644. if (tentry == null)
  5645. zc.AddZeros(2);
  5646. else
  5647. {
  5648. int len = tentry.Length;
  5649. zc.AddByte((byte)len);
  5650. zc.AddByte((byte)(len >> 8));
  5651. zc.AddBytes(tentry, len);
  5652. }
  5653. // texture animation
  5654. byte[] tanim = part.TextureAnimation;
  5655. if (tanim == null)
  5656. zc.AddZeros(1);
  5657. else
  5658. {
  5659. int len = tanim.Length;
  5660. zc.AddByte((byte)len);
  5661. zc.AddBytes(tanim, len);
  5662. }
  5663. //NameValue
  5664. if(nv == null)
  5665. zc.AddZeros(2);
  5666. else
  5667. {
  5668. int len = nv.Length;
  5669. zc.AddByte((byte)len);
  5670. zc.AddByte((byte)(len >> 8));
  5671. zc.AddBytes(nv, len);
  5672. }
  5673. // data
  5674. if (data == null)
  5675. zc.AddZeros(2);
  5676. else
  5677. {
  5678. int len = data.Length;
  5679. zc.AddByte((byte)len);
  5680. zc.AddByte((byte)(len >> 8));
  5681. zc.AddBytes(data, len);
  5682. }
  5683. //text
  5684. if (part.Text == null || part.Text.Length == 0)
  5685. zc.AddZeros(5);
  5686. else
  5687. {
  5688. byte[] tbuf = Util.StringToBytes(part.Text, 254);
  5689. int len = tbuf.Length;
  5690. zc.AddByte((byte)len);
  5691. zc.AddBytes(tbuf, len);
  5692. //textcolor
  5693. byte[] tc = part.GetTextColor().GetBytes(false);
  5694. zc.AddBytes(tc, 4);
  5695. }
  5696. //media url
  5697. if (part.MediaUrl == null || part.MediaUrl.Length == 0)
  5698. zc.AddZeros(1);
  5699. else
  5700. {
  5701. byte[] tbuf = Util.StringToBytes(part.MediaUrl, 255);
  5702. int len = tbuf.Length;
  5703. zc.AddByte((byte)len);
  5704. zc.AddBytes(tbuf, len);
  5705. }
  5706. bool hasps = false;
  5707. //particle system
  5708. byte[] ps = part.ParticleSystem;
  5709. if (ps == null || ps.Length < 1)
  5710. zc.AddZeros(1);
  5711. else
  5712. {
  5713. int len = ps.Length;
  5714. zc.AddByte((byte)len);
  5715. zc.AddBytes(ps, len);
  5716. hasps = true;
  5717. }
  5718. //Extraparams
  5719. byte[] ep = part.Shape.ExtraParams;
  5720. if (ep == null || ep.Length < 2)
  5721. zc.AddZeros(1);
  5722. else
  5723. {
  5724. int len = ep.Length;
  5725. zc.AddByte((byte)len);
  5726. zc.AddBytes(ep, len);
  5727. }
  5728. bool hassound = part.Sound != UUID.Zero || part.SoundFlags != 0;
  5729. if (hassound)
  5730. zc.AddUUID(part.Sound);
  5731. else
  5732. zc.AddZeros(16);
  5733. if (hassound || hasps)
  5734. zc.AddUUID(part.OwnerID);
  5735. else
  5736. zc.AddZeros(16);
  5737. if (hassound)
  5738. {
  5739. zc.AddFloat((float)part.SoundGain);
  5740. zc.AddByte(part.SoundFlags);
  5741. zc.AddFloat((float)part.SoundRadius);
  5742. }
  5743. else
  5744. zc.AddZeros(9);
  5745. // jointtype(1) joint pivot(12) joint offset(12)
  5746. const int lastzeros = 1 + 12 + 12;
  5747. zc.AddZeros(lastzeros);
  5748. }
  5749. protected ObjectUpdateCompressedPacket.ObjectDataBlock CreateCompressedUpdateBlock(SceneObjectPart part, PrimUpdateFlags updateFlags)
  5750. {
  5751. // TODO: Implement this
  5752. return null;
  5753. }
  5754. public void SendNameReply(UUID profileId, string firstname, string lastname)
  5755. {
  5756. UUIDNameReplyPacket packet = (UUIDNameReplyPacket)PacketPool.Instance.GetPacket(PacketType.UUIDNameReply);
  5757. // TODO: don't create new blocks if recycling an old packet
  5758. packet.UUIDNameBlock = new UUIDNameReplyPacket.UUIDNameBlockBlock[1];
  5759. packet.UUIDNameBlock[0] = new UUIDNameReplyPacket.UUIDNameBlockBlock();
  5760. packet.UUIDNameBlock[0].ID = profileId;
  5761. packet.UUIDNameBlock[0].FirstName = Util.StringToBytes256(firstname);
  5762. packet.UUIDNameBlock[0].LastName = Util.StringToBytes256(lastname);
  5763. OutPacket(packet, ThrottleOutPacketType.Task);
  5764. }
  5765. public Dictionary<UUID, ulong> GetGroupPowers()
  5766. {
  5767. lock(m_groupPowers)
  5768. {
  5769. return new Dictionary<UUID, ulong>(m_groupPowers);
  5770. }
  5771. }
  5772. public void SetGroupPowers(Dictionary<UUID, ulong> powers)
  5773. {
  5774. lock(m_groupPowers)
  5775. {
  5776. m_groupPowers.Clear();
  5777. m_groupPowers = powers;
  5778. }
  5779. }
  5780. public ulong GetGroupPowers(UUID groupID)
  5781. {
  5782. lock(m_groupPowers)
  5783. {
  5784. if (m_groupPowers.ContainsKey(groupID))
  5785. return m_groupPowers[groupID];
  5786. }
  5787. return 0;
  5788. }
  5789. #endregion
  5790. /// <summary>
  5791. /// This is a different way of processing packets then ProcessInPacket
  5792. /// </summary>
  5793. protected virtual void RegisterLocalPacketHandlers()
  5794. {
  5795. AddLocalPacketHandler(PacketType.LogoutRequest, HandleLogout);
  5796. // If AgentUpdate is ever handled asynchronously, then we will also need to construct a new AgentUpdateArgs
  5797. // for each AgentUpdate packet.
  5798. AddLocalPacketHandler(PacketType.AgentUpdate, HandleAgentUpdate, false);
  5799. AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect, false);
  5800. AddLocalPacketHandler(PacketType.VelocityInterpolateOff, HandleVelocityInterpolateOff, false);
  5801. AddLocalPacketHandler(PacketType.VelocityInterpolateOn, HandleVelocityInterpolateOn, false);
  5802. AddLocalPacketHandler(PacketType.AgentCachedTexture, HandleAgentTextureCached, false);
  5803. AddLocalPacketHandler(PacketType.MultipleObjectUpdate, HandleMultipleObjUpdate, false);
  5804. AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest, false);
  5805. AddLocalPacketHandler(PacketType.ParcelBuy, HandleParcelBuyRequest, false);
  5806. AddLocalPacketHandler(PacketType.UUIDGroupNameRequest, HandleUUIDGroupNameRequest);
  5807. AddLocalPacketHandler(PacketType.ObjectGroup, HandleObjectGroupRequest);
  5808. AddLocalPacketHandler(PacketType.GenericMessage, HandleGenericMessage);
  5809. AddLocalPacketHandler(PacketType.AvatarPropertiesRequest, HandleAvatarPropertiesRequest);
  5810. AddLocalPacketHandler(PacketType.ChatFromViewer, HandleChatFromViewer);
  5811. AddLocalPacketHandler(PacketType.AvatarPropertiesUpdate, HandlerAvatarPropertiesUpdate);
  5812. AddLocalPacketHandler(PacketType.ScriptDialogReply, HandlerScriptDialogReply);
  5813. AddLocalPacketHandler(PacketType.ImprovedInstantMessage, HandlerImprovedInstantMessage);
  5814. AddLocalPacketHandler(PacketType.AcceptFriendship, HandlerAcceptFriendship);
  5815. AddLocalPacketHandler(PacketType.DeclineFriendship, HandlerDeclineFriendship);
  5816. AddLocalPacketHandler(PacketType.TerminateFriendship, HandlerTerminateFriendship);
  5817. AddLocalPacketHandler(PacketType.RezObject, HandlerRezObject);
  5818. AddLocalPacketHandler(PacketType.DeRezObject, HandlerDeRezObject);
  5819. AddLocalPacketHandler(PacketType.RezRestoreToWorld, HandlerRezRestoreToWorld);
  5820. AddLocalPacketHandler(PacketType.ModifyLand, HandlerModifyLand);
  5821. AddLocalPacketHandler(PacketType.RegionHandshakeReply, HandlerRegionHandshakeReply, false);
  5822. AddLocalPacketHandler(PacketType.AgentWearablesRequest, HandlerAgentWearablesRequest);
  5823. AddLocalPacketHandler(PacketType.AgentSetAppearance, HandlerAgentSetAppearance);
  5824. AddLocalPacketHandler(PacketType.AgentIsNowWearing, HandlerAgentIsNowWearing);
  5825. AddLocalPacketHandler(PacketType.RezSingleAttachmentFromInv, HandlerRezSingleAttachmentFromInv);
  5826. AddLocalPacketHandler(PacketType.RezMultipleAttachmentsFromInv, HandleRezMultipleAttachmentsFromInv);
  5827. AddLocalPacketHandler(PacketType.DetachAttachmentIntoInv, HandleDetachAttachmentIntoInv);
  5828. AddLocalPacketHandler(PacketType.ObjectAttach, HandleObjectAttach);
  5829. AddLocalPacketHandler(PacketType.ObjectDetach, HandleObjectDetach);
  5830. AddLocalPacketHandler(PacketType.ObjectDrop, HandleObjectDrop);
  5831. AddLocalPacketHandler(PacketType.SetAlwaysRun, HandleSetAlwaysRun, false);
  5832. AddLocalPacketHandler(PacketType.CompleteAgentMovement, HandleCompleteAgentMovement);
  5833. AddLocalPacketHandler(PacketType.AgentAnimation, HandleAgentAnimation, false);
  5834. AddLocalPacketHandler(PacketType.AgentRequestSit, HandleAgentRequestSit);
  5835. AddLocalPacketHandler(PacketType.AgentSit, HandleAgentSit);
  5836. AddLocalPacketHandler(PacketType.SoundTrigger, HandleSoundTrigger);
  5837. AddLocalPacketHandler(PacketType.AvatarPickerRequest, HandleAvatarPickerRequest);
  5838. AddLocalPacketHandler(PacketType.AgentDataUpdateRequest, HandleAgentDataUpdateRequest);
  5839. AddLocalPacketHandler(PacketType.UserInfoRequest, HandleUserInfoRequest);
  5840. AddLocalPacketHandler(PacketType.UpdateUserInfo, HandleUpdateUserInfo);
  5841. AddLocalPacketHandler(PacketType.SetStartLocationRequest, HandleSetStartLocationRequest);
  5842. AddLocalPacketHandler(PacketType.AgentThrottle, HandleAgentThrottle, false);
  5843. AddLocalPacketHandler(PacketType.AgentPause, HandleAgentPause, false);
  5844. AddLocalPacketHandler(PacketType.AgentResume, HandleAgentResume, false);
  5845. AddLocalPacketHandler(PacketType.ForceScriptControlRelease, HandleForceScriptControlRelease);
  5846. AddLocalPacketHandler(PacketType.ObjectLink, HandleObjectLink);
  5847. AddLocalPacketHandler(PacketType.ObjectDelink, HandleObjectDelink);
  5848. AddLocalPacketHandler(PacketType.ObjectAdd, HandleObjectAdd);
  5849. AddLocalPacketHandler(PacketType.ObjectShape, HandleObjectShape);
  5850. AddLocalPacketHandler(PacketType.ObjectExtraParams, HandleObjectExtraParams);
  5851. AddLocalPacketHandler(PacketType.ObjectDuplicate, HandleObjectDuplicate);
  5852. AddLocalPacketHandler(PacketType.RequestMultipleObjects, HandleRequestMultipleObjects);
  5853. AddLocalPacketHandler(PacketType.ObjectSelect, HandleObjectSelect);
  5854. AddLocalPacketHandler(PacketType.ObjectDeselect, HandleObjectDeselect);
  5855. AddLocalPacketHandler(PacketType.ObjectPosition, HandleObjectPosition);
  5856. AddLocalPacketHandler(PacketType.ObjectScale, HandleObjectScale);
  5857. AddLocalPacketHandler(PacketType.ObjectRotation, HandleObjectRotation);
  5858. AddLocalPacketHandler(PacketType.ObjectFlagUpdate, HandleObjectFlagUpdate);
  5859. // Handle ObjectImage (TextureEntry) updates synchronously, since when updating multiple prim faces at once,
  5860. // some clients will send out a separate ObjectImage packet for each face
  5861. AddLocalPacketHandler(PacketType.ObjectImage, HandleObjectImage, false);
  5862. AddLocalPacketHandler(PacketType.ObjectGrab, HandleObjectGrab, false);
  5863. AddLocalPacketHandler(PacketType.ObjectGrabUpdate, HandleObjectGrabUpdate, false);
  5864. AddLocalPacketHandler(PacketType.ObjectDeGrab, HandleObjectDeGrab);
  5865. AddLocalPacketHandler(PacketType.ObjectSpinStart, HandleObjectSpinStart, false);
  5866. AddLocalPacketHandler(PacketType.ObjectSpinUpdate, HandleObjectSpinUpdate, false);
  5867. AddLocalPacketHandler(PacketType.ObjectSpinStop, HandleObjectSpinStop, false);
  5868. AddLocalPacketHandler(PacketType.ObjectDescription, HandleObjectDescription, false);
  5869. AddLocalPacketHandler(PacketType.ObjectName, HandleObjectName, false);
  5870. AddLocalPacketHandler(PacketType.ObjectPermissions, HandleObjectPermissions, false);
  5871. AddLocalPacketHandler(PacketType.Undo, HandleUndo, false);
  5872. AddLocalPacketHandler(PacketType.UndoLand, HandleLandUndo, false);
  5873. AddLocalPacketHandler(PacketType.Redo, HandleRedo, false);
  5874. AddLocalPacketHandler(PacketType.ObjectDuplicateOnRay, HandleObjectDuplicateOnRay);
  5875. AddLocalPacketHandler(PacketType.RequestObjectPropertiesFamily, HandleRequestObjectPropertiesFamily, false);
  5876. AddLocalPacketHandler(PacketType.ObjectIncludeInSearch, HandleObjectIncludeInSearch);
  5877. AddLocalPacketHandler(PacketType.ScriptAnswerYes, HandleScriptAnswerYes, false);
  5878. AddLocalPacketHandler(PacketType.ObjectClickAction, HandleObjectClickAction, false);
  5879. AddLocalPacketHandler(PacketType.ObjectMaterial, HandleObjectMaterial, false);
  5880. AddLocalPacketHandler(PacketType.RequestImage, HandleRequestImage, false);
  5881. AddLocalPacketHandler(PacketType.TransferRequest, HandleTransferRequest, false);
  5882. AddLocalPacketHandler(PacketType.AssetUploadRequest, HandleAssetUploadRequest);
  5883. AddLocalPacketHandler(PacketType.RequestXfer, HandleRequestXfer);
  5884. AddLocalPacketHandler(PacketType.SendXferPacket, HandleSendXferPacket);
  5885. AddLocalPacketHandler(PacketType.ConfirmXferPacket, HandleConfirmXferPacket);
  5886. AddLocalPacketHandler(PacketType.AbortXfer, HandleAbortXfer);
  5887. AddLocalPacketHandler(PacketType.CreateInventoryFolder, HandleCreateInventoryFolder);
  5888. AddLocalPacketHandler(PacketType.UpdateInventoryFolder, HandleUpdateInventoryFolder);
  5889. AddLocalPacketHandler(PacketType.MoveInventoryFolder, HandleMoveInventoryFolder);
  5890. AddLocalPacketHandler(PacketType.CreateInventoryItem, HandleCreateInventoryItem);
  5891. AddLocalPacketHandler(PacketType.LinkInventoryItem, HandleLinkInventoryItem);
  5892. AddLocalPacketHandler(PacketType.FetchInventory, HandleFetchInventory);
  5893. AddLocalPacketHandler(PacketType.FetchInventoryDescendents, HandleFetchInventoryDescendents);
  5894. AddLocalPacketHandler(PacketType.PurgeInventoryDescendents, HandlePurgeInventoryDescendents);
  5895. AddLocalPacketHandler(PacketType.UpdateInventoryItem, HandleUpdateInventoryItem);
  5896. AddLocalPacketHandler(PacketType.CopyInventoryItem, HandleCopyInventoryItem);
  5897. AddLocalPacketHandler(PacketType.MoveInventoryItem, HandleMoveInventoryItem);
  5898. AddLocalPacketHandler(PacketType.RemoveInventoryItem, HandleRemoveInventoryItem);
  5899. AddLocalPacketHandler(PacketType.RemoveInventoryFolder, HandleRemoveInventoryFolder);
  5900. AddLocalPacketHandler(PacketType.RemoveInventoryObjects, HandleRemoveInventoryObjects);
  5901. AddLocalPacketHandler(PacketType.RequestTaskInventory, HandleRequestTaskInventory);
  5902. AddLocalPacketHandler(PacketType.UpdateTaskInventory, HandleUpdateTaskInventory);
  5903. AddLocalPacketHandler(PacketType.RemoveTaskInventory, HandleRemoveTaskInventory);
  5904. AddLocalPacketHandler(PacketType.MoveTaskInventory, HandleMoveTaskInventory);
  5905. AddLocalPacketHandler(PacketType.RezScript, HandleRezScript);
  5906. AddLocalPacketHandler(PacketType.MapLayerRequest, HandleMapLayerRequest);
  5907. AddLocalPacketHandler(PacketType.MapBlockRequest, HandleMapBlockRequest);
  5908. AddLocalPacketHandler(PacketType.MapNameRequest, HandleMapNameRequest);
  5909. AddLocalPacketHandler(PacketType.TeleportLandmarkRequest, HandleTeleportLandmarkRequest);
  5910. AddLocalPacketHandler(PacketType.TeleportCancel, HandleTeleportCancel);
  5911. AddLocalPacketHandler(PacketType.TeleportLocationRequest, HandleTeleportLocationRequest);
  5912. AddLocalPacketHandler(PacketType.UUIDNameRequest, HandleUUIDNameRequest, false);
  5913. AddLocalPacketHandler(PacketType.RegionHandleRequest, HandleRegionHandleRequest, false);
  5914. AddLocalPacketHandler(PacketType.ParcelInfoRequest, HandleParcelInfoRequest);
  5915. AddLocalPacketHandler(PacketType.ParcelAccessListRequest, HandleParcelAccessListRequest, false);
  5916. AddLocalPacketHandler(PacketType.ParcelAccessListUpdate, HandleParcelAccessListUpdate, false);
  5917. AddLocalPacketHandler(PacketType.ParcelPropertiesRequest, HandleParcelPropertiesRequest, false);
  5918. AddLocalPacketHandler(PacketType.ParcelDivide, HandleParcelDivide);
  5919. AddLocalPacketHandler(PacketType.ParcelJoin, HandleParcelJoin);
  5920. AddLocalPacketHandler(PacketType.ParcelPropertiesUpdate, HandleParcelPropertiesUpdate);
  5921. AddLocalPacketHandler(PacketType.ParcelSelectObjects, HandleParcelSelectObjects);
  5922. AddLocalPacketHandler(PacketType.ParcelObjectOwnersRequest, HandleParcelObjectOwnersRequest);
  5923. AddLocalPacketHandler(PacketType.ParcelGodForceOwner, HandleParcelGodForceOwner);
  5924. AddLocalPacketHandler(PacketType.ParcelRelease, HandleParcelRelease);
  5925. AddLocalPacketHandler(PacketType.ParcelReclaim, HandleParcelReclaim);
  5926. AddLocalPacketHandler(PacketType.ParcelReturnObjects, HandleParcelReturnObjects);
  5927. AddLocalPacketHandler(PacketType.ParcelSetOtherCleanTime, HandleParcelSetOtherCleanTime);
  5928. AddLocalPacketHandler(PacketType.LandStatRequest, HandleLandStatRequest);
  5929. AddLocalPacketHandler(PacketType.ParcelDwellRequest, HandleParcelDwellRequest);
  5930. AddLocalPacketHandler(PacketType.EstateOwnerMessage, HandleEstateOwnerMessage);
  5931. AddLocalPacketHandler(PacketType.RequestRegionInfo, HandleRequestRegionInfo, false);
  5932. AddLocalPacketHandler(PacketType.EstateCovenantRequest, HandleEstateCovenantRequest);
  5933. AddLocalPacketHandler(PacketType.RequestGodlikePowers, HandleRequestGodlikePowers);
  5934. AddLocalPacketHandler(PacketType.GodKickUser, HandleGodKickUser);
  5935. AddLocalPacketHandler(PacketType.MoneyBalanceRequest, HandleMoneyBalanceRequest);
  5936. AddLocalPacketHandler(PacketType.EconomyDataRequest, HandleEconomyDataRequest);
  5937. AddLocalPacketHandler(PacketType.RequestPayPrice, HandleRequestPayPrice);
  5938. AddLocalPacketHandler(PacketType.ObjectSaleInfo, HandleObjectSaleInfo);
  5939. AddLocalPacketHandler(PacketType.ObjectBuy, HandleObjectBuy);
  5940. AddLocalPacketHandler(PacketType.GetScriptRunning, HandleGetScriptRunning);
  5941. AddLocalPacketHandler(PacketType.SetScriptRunning, HandleSetScriptRunning);
  5942. AddLocalPacketHandler(PacketType.ScriptReset, HandleScriptReset);
  5943. AddLocalPacketHandler(PacketType.ActivateGestures, HandleActivateGestures);
  5944. AddLocalPacketHandler(PacketType.DeactivateGestures, HandleDeactivateGestures);
  5945. AddLocalPacketHandler(PacketType.ObjectOwner, HandleObjectOwner);
  5946. AddLocalPacketHandler(PacketType.AgentFOV, HandleAgentFOV, false);
  5947. AddLocalPacketHandler(PacketType.ViewerStats, HandleViewerStats);
  5948. AddLocalPacketHandler(PacketType.MapItemRequest, HandleMapItemRequest, false);
  5949. AddLocalPacketHandler(PacketType.TransferAbort, HandleTransferAbort, false);
  5950. AddLocalPacketHandler(PacketType.MuteListRequest, HandleMuteListRequest, false);
  5951. AddLocalPacketHandler(PacketType.UseCircuitCode, HandleUseCircuitCode);
  5952. AddLocalPacketHandler(PacketType.CreateNewOutfitAttachments, HandleCreateNewOutfitAttachments);
  5953. AddLocalPacketHandler(PacketType.AgentHeightWidth, HandleAgentHeightWidth, false);
  5954. AddLocalPacketHandler(PacketType.InventoryDescendents, HandleInventoryDescendents);
  5955. AddLocalPacketHandler(PacketType.DirPlacesQuery, HandleDirPlacesQuery);
  5956. AddLocalPacketHandler(PacketType.DirFindQuery, HandleDirFindQuery);
  5957. AddLocalPacketHandler(PacketType.DirLandQuery, HandleDirLandQuery);
  5958. AddLocalPacketHandler(PacketType.DirPopularQuery, HandleDirPopularQuery);
  5959. AddLocalPacketHandler(PacketType.DirClassifiedQuery, HandleDirClassifiedQuery);
  5960. AddLocalPacketHandler(PacketType.EventInfoRequest, HandleEventInfoRequest);
  5961. AddLocalPacketHandler(PacketType.OfferCallingCard, HandleOfferCallingCard);
  5962. AddLocalPacketHandler(PacketType.AcceptCallingCard, HandleAcceptCallingCard);
  5963. AddLocalPacketHandler(PacketType.DeclineCallingCard, HandleDeclineCallingCard);
  5964. AddLocalPacketHandler(PacketType.ActivateGroup, HandleActivateGroup);
  5965. AddLocalPacketHandler(PacketType.GroupTitlesRequest, HandleGroupTitlesRequest);
  5966. AddLocalPacketHandler(PacketType.GroupProfileRequest, HandleGroupProfileRequest);
  5967. AddLocalPacketHandler(PacketType.GroupMembersRequest, HandleGroupMembersRequest);
  5968. AddLocalPacketHandler(PacketType.GroupRoleDataRequest, HandleGroupRoleDataRequest);
  5969. AddLocalPacketHandler(PacketType.GroupRoleMembersRequest, HandleGroupRoleMembersRequest);
  5970. AddLocalPacketHandler(PacketType.CreateGroupRequest, HandleCreateGroupRequest);
  5971. AddLocalPacketHandler(PacketType.UpdateGroupInfo, HandleUpdateGroupInfo);
  5972. AddLocalPacketHandler(PacketType.SetGroupAcceptNotices, HandleSetGroupAcceptNotices);
  5973. AddLocalPacketHandler(PacketType.GroupTitleUpdate, HandleGroupTitleUpdate);
  5974. AddLocalPacketHandler(PacketType.ParcelDeedToGroup, HandleParcelDeedToGroup);
  5975. AddLocalPacketHandler(PacketType.GroupNoticesListRequest, HandleGroupNoticesListRequest);
  5976. AddLocalPacketHandler(PacketType.GroupNoticeRequest, HandleGroupNoticeRequest);
  5977. AddLocalPacketHandler(PacketType.GroupRoleUpdate, HandleGroupRoleUpdate);
  5978. AddLocalPacketHandler(PacketType.GroupRoleChanges, HandleGroupRoleChanges);
  5979. AddLocalPacketHandler(PacketType.JoinGroupRequest, HandleJoinGroupRequest);
  5980. AddLocalPacketHandler(PacketType.LeaveGroupRequest, HandleLeaveGroupRequest);
  5981. AddLocalPacketHandler(PacketType.EjectGroupMemberRequest, HandleEjectGroupMemberRequest);
  5982. AddLocalPacketHandler(PacketType.InviteGroupRequest, HandleInviteGroupRequest);
  5983. AddLocalPacketHandler(PacketType.StartLure, HandleStartLure);
  5984. AddLocalPacketHandler(PacketType.TeleportLureRequest, HandleTeleportLureRequest);
  5985. AddLocalPacketHandler(PacketType.ClassifiedInfoRequest, HandleClassifiedInfoRequest);
  5986. AddLocalPacketHandler(PacketType.ClassifiedInfoUpdate, HandleClassifiedInfoUpdate);
  5987. AddLocalPacketHandler(PacketType.ClassifiedDelete, HandleClassifiedDelete);
  5988. AddLocalPacketHandler(PacketType.ClassifiedGodDelete, HandleClassifiedGodDelete);
  5989. AddLocalPacketHandler(PacketType.EventGodDelete, HandleEventGodDelete);
  5990. AddLocalPacketHandler(PacketType.EventNotificationAddRequest, HandleEventNotificationAddRequest);
  5991. AddLocalPacketHandler(PacketType.EventNotificationRemoveRequest, HandleEventNotificationRemoveRequest);
  5992. AddLocalPacketHandler(PacketType.RetrieveInstantMessages, HandleRetrieveInstantMessages);
  5993. AddLocalPacketHandler(PacketType.PickDelete, HandlePickDelete);
  5994. AddLocalPacketHandler(PacketType.PickGodDelete, HandlePickGodDelete);
  5995. AddLocalPacketHandler(PacketType.PickInfoUpdate, HandlePickInfoUpdate);
  5996. AddLocalPacketHandler(PacketType.AvatarNotesUpdate, HandleAvatarNotesUpdate);
  5997. AddLocalPacketHandler(PacketType.AvatarInterestsUpdate, HandleAvatarInterestsUpdate);
  5998. AddLocalPacketHandler(PacketType.GrantUserRights, HandleGrantUserRights);
  5999. AddLocalPacketHandler(PacketType.PlacesQuery, HandlePlacesQuery);
  6000. AddLocalPacketHandler(PacketType.UpdateMuteListEntry, HandleUpdateMuteListEntry);
  6001. AddLocalPacketHandler(PacketType.RemoveMuteListEntry, HandleRemoveMuteListEntry);
  6002. AddLocalPacketHandler(PacketType.UserReport, HandleUserReport);
  6003. AddLocalPacketHandler(PacketType.FindAgent, HandleFindAgent);
  6004. AddLocalPacketHandler(PacketType.TrackAgent, HandleTrackAgent);
  6005. AddLocalPacketHandler(PacketType.GodUpdateRegionInfo, HandleGodUpdateRegionInfoUpdate);
  6006. AddLocalPacketHandler(PacketType.GodlikeMessage, HandleGodlikeMessage);
  6007. AddLocalPacketHandler(PacketType.StateSave, HandleSaveStatePacket);
  6008. AddLocalPacketHandler(PacketType.GroupAccountDetailsRequest, HandleGroupAccountDetailsRequest);
  6009. AddLocalPacketHandler(PacketType.GroupAccountSummaryRequest, HandleGroupAccountSummaryRequest);
  6010. AddLocalPacketHandler(PacketType.GroupAccountTransactionsRequest, HandleGroupTransactionsDetailsRequest);
  6011. AddLocalPacketHandler(PacketType.FreezeUser, HandleFreezeUser);
  6012. AddLocalPacketHandler(PacketType.EjectUser, HandleEjectUser);
  6013. AddLocalPacketHandler(PacketType.ParcelBuyPass, HandleParcelBuyPass);
  6014. AddLocalPacketHandler(PacketType.ParcelGodMarkAsContent, HandleParcelGodMarkAsContent);
  6015. AddLocalPacketHandler(PacketType.GroupActiveProposalsRequest, HandleGroupActiveProposalsRequest);
  6016. AddLocalPacketHandler(PacketType.GroupVoteHistoryRequest, HandleGroupVoteHistoryRequest);
  6017. AddLocalPacketHandler(PacketType.SimWideDeletes, HandleSimWideDeletes);
  6018. AddLocalPacketHandler(PacketType.SendPostcard, HandleSendPostcard);
  6019. AddLocalPacketHandler(PacketType.ChangeInventoryItemFlags, HandleChangeInventoryItemFlags);
  6020. AddLocalPacketHandler(PacketType.RevokePermissions, HandleRevokePermissions);
  6021. AddGenericPacketHandler("autopilot", HandleAutopilot);
  6022. }
  6023. #region Packet Handlers
  6024. public int TotalAgentUpdates { get; set; }
  6025. #region Scene/Avatar
  6026. // Threshold for body rotation to be a significant agent update
  6027. // use the abs of cos
  6028. private const float QDELTABody = 1.0f - 0.00001f;
  6029. private const float QDELTAHead = 1.0f - 0.00001f;
  6030. // Threshold for camera rotation to be a significant agent update
  6031. private const float VDELTA = 0.01f;
  6032. /// <summary>
  6033. /// This checks the update significance against the last update made.
  6034. /// </summary>
  6035. /// <remarks>Can only be called by one thread at a time</remarks>
  6036. /// <returns></returns>
  6037. /// <param name='x'></param>
  6038. public bool CheckAgentUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
  6039. {
  6040. return CheckAgentMovementUpdateSignificance(x) || CheckAgentCameraUpdateSignificance(x);
  6041. }
  6042. /// <summary>
  6043. /// This checks the movement/state update significance against the last update made.
  6044. /// </summary>
  6045. /// <remarks>Can only be called by one thread at a time</remarks>
  6046. /// <returns></returns>
  6047. /// <param name='x'></param>
  6048. private bool CheckAgentMovementUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
  6049. {
  6050. if(
  6051. (x.ControlFlags != m_thisAgentUpdateArgs.ControlFlags) // significant if control flags changed
  6052. // || ((x.ControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0 &&
  6053. // (x.ControlFlags & 0x3f8dfff) != 0) // we need to rotate the av on fly
  6054. || x.ControlFlags != (byte)AgentManager.ControlFlags.NONE// actually all movement controls need to pass
  6055. || (x.Flags != m_thisAgentUpdateArgs.Flags) // significant if Flags changed
  6056. || (x.State != m_thisAgentUpdateArgs.State) // significant if Stats changed
  6057. || (Math.Abs(x.Far - m_thisAgentUpdateArgs.Far) >= 32) // significant if far distance changed
  6058. )
  6059. return true;
  6060. float qdelta = Math.Abs(Quaternion.Dot(x.BodyRotation, m_thisAgentUpdateArgs.BodyRotation));
  6061. if(qdelta < QDELTABody) // significant if body rotation above(below cos) threshold
  6062. return true;
  6063. return false;
  6064. }
  6065. /// <summary>
  6066. /// This checks the camera update significance against the last update made.
  6067. /// </summary>
  6068. /// <remarks>Can only be called by one thread at a time</remarks>
  6069. /// <returns></returns>
  6070. /// <param name='x'></param>
  6071. private bool CheckAgentCameraUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
  6072. {
  6073. if(Math.Abs(x.CameraCenter.X - m_thisAgentUpdateArgs.CameraCenter.X) > VDELTA ||
  6074. Math.Abs(x.CameraCenter.Y - m_thisAgentUpdateArgs.CameraCenter.Y) > VDELTA ||
  6075. Math.Abs(x.CameraCenter.Z - m_thisAgentUpdateArgs.CameraCenter.Z) > VDELTA ||
  6076. Math.Abs(x.CameraAtAxis.X - m_thisAgentUpdateArgs.CameraAtAxis.X) > VDELTA ||
  6077. Math.Abs(x.CameraAtAxis.Y - m_thisAgentUpdateArgs.CameraAtAxis.Y) > VDELTA ||
  6078. // Math.Abs(x.CameraAtAxis.Z - m_thisAgentUpdateArgs.CameraAtAxis.Z) > VDELTA ||
  6079. Math.Abs(x.CameraLeftAxis.X - m_thisAgentUpdateArgs.CameraLeftAxis.X) > VDELTA ||
  6080. Math.Abs(x.CameraLeftAxis.Y - m_thisAgentUpdateArgs.CameraLeftAxis.Y) > VDELTA ||
  6081. // Math.Abs(x.CameraLeftAxis.Z - m_thisAgentUpdateArgs.CameraLeftAxis.Z) > VDELTA ||
  6082. Math.Abs(x.CameraUpAxis.X - m_thisAgentUpdateArgs.CameraUpAxis.X) > VDELTA ||
  6083. Math.Abs(x.CameraUpAxis.Y - m_thisAgentUpdateArgs.CameraUpAxis.Y) > VDELTA
  6084. // Math.Abs(x.CameraLeftAxis.Z - m_thisAgentUpdateArgs.CameraLeftAxis.Z) > VDELTA ||
  6085. )
  6086. return true;
  6087. return false;
  6088. }
  6089. private bool HandleAgentUpdate(IClientAPI sender, Packet packet)
  6090. {
  6091. if(OnAgentUpdate == null)
  6092. {
  6093. PacketPool.Instance.ReturnPacket(packet);
  6094. return false;
  6095. }
  6096. AgentUpdatePacket agentUpdate = (AgentUpdatePacket)packet;
  6097. AgentUpdatePacket.AgentDataBlock x = agentUpdate.AgentData;
  6098. if (x.AgentID != AgentId || x.SessionID != SessionId)
  6099. {
  6100. PacketPool.Instance.ReturnPacket(packet);
  6101. return false;
  6102. }
  6103. uint seq = packet.Header.Sequence;
  6104. TotalAgentUpdates++;
  6105. // dont let ignored updates pollute this throttles
  6106. if(SceneAgent == null || SceneAgent.IsChildAgent ||
  6107. SceneAgent.IsInTransit || seq <= m_thisAgentUpdateArgs.lastpacketSequence )
  6108. {
  6109. // throttle reset is done at MoveAgentIntoRegion()
  6110. // called by scenepresence on completemovement
  6111. PacketPool.Instance.ReturnPacket(packet);
  6112. return true;
  6113. }
  6114. m_thisAgentUpdateArgs.lastpacketSequence = seq;
  6115. if (OnPreAgentUpdate != null)
  6116. OnPreAgentUpdate(this, m_thisAgentUpdateArgs);
  6117. bool movement;
  6118. bool camera;
  6119. double now = Util.GetTimeStampMS();
  6120. if(now - m_thisAgentUpdateArgs.lastUpdateTS > 500.0) // at least 2 per sec
  6121. {
  6122. movement = true;
  6123. camera = true;
  6124. }
  6125. else
  6126. {
  6127. movement = CheckAgentMovementUpdateSignificance(x);
  6128. camera = CheckAgentCameraUpdateSignificance(x);
  6129. }
  6130. // Was there a significant movement/state change?
  6131. if (movement)
  6132. {
  6133. m_thisAgentUpdateArgs.BodyRotation = x.BodyRotation;
  6134. m_thisAgentUpdateArgs.ControlFlags = x.ControlFlags;
  6135. m_thisAgentUpdateArgs.Far = x.Far;
  6136. m_thisAgentUpdateArgs.Flags = x.Flags;
  6137. m_thisAgentUpdateArgs.HeadRotation = x.HeadRotation;
  6138. m_thisAgentUpdateArgs.State = x.State;
  6139. m_thisAgentUpdateArgs.NeedsCameraCollision = !camera;
  6140. if (OnAgentUpdate != null)
  6141. OnAgentUpdate(this, m_thisAgentUpdateArgs);
  6142. }
  6143. // Was there a significant camera(s) change?
  6144. if (camera)
  6145. {
  6146. m_thisAgentUpdateArgs.CameraAtAxis = x.CameraAtAxis;
  6147. m_thisAgentUpdateArgs.CameraCenter = x.CameraCenter;
  6148. m_thisAgentUpdateArgs.CameraLeftAxis = x.CameraLeftAxis;
  6149. m_thisAgentUpdateArgs.CameraUpAxis = x.CameraUpAxis;
  6150. m_thisAgentUpdateArgs.NeedsCameraCollision = true;
  6151. if (OnAgentCameraUpdate != null)
  6152. OnAgentCameraUpdate(this, m_thisAgentUpdateArgs);
  6153. }
  6154. if(movement && camera)
  6155. m_thisAgentUpdateArgs.lastUpdateTS = now;
  6156. PacketPool.Instance.ReturnPacket(packet);
  6157. return true;
  6158. }
  6159. private bool HandleMoneyTransferRequest(IClientAPI sender, Packet Pack)
  6160. {
  6161. MoneyTransferRequestPacket money = (MoneyTransferRequestPacket)Pack;
  6162. // validate the agent owns the agentID and sessionID
  6163. if (money.MoneyData.SourceID == sender.AgentId && money.AgentData.AgentID == sender.AgentId &&
  6164. money.AgentData.SessionID == sender.SessionId)
  6165. {
  6166. MoneyTransferRequest handlerMoneyTransferRequest = OnMoneyTransferRequest;
  6167. if (handlerMoneyTransferRequest != null)
  6168. {
  6169. handlerMoneyTransferRequest(money.MoneyData.SourceID, money.MoneyData.DestID,
  6170. money.MoneyData.Amount, money.MoneyData.TransactionType,
  6171. Util.FieldToString(money.MoneyData.Description));
  6172. }
  6173. return true;
  6174. }
  6175. return false;
  6176. }
  6177. private bool HandleParcelGodMarkAsContent(IClientAPI client, Packet Packet)
  6178. {
  6179. ParcelGodMarkAsContentPacket ParcelGodMarkAsContent =
  6180. (ParcelGodMarkAsContentPacket)Packet;
  6181. if(SessionId != ParcelGodMarkAsContent.AgentData.SessionID || AgentId != ParcelGodMarkAsContent.AgentData.AgentID)
  6182. return false;
  6183. ParcelGodMark ParcelGodMarkAsContentHandler = OnParcelGodMark;
  6184. if (ParcelGodMarkAsContentHandler != null)
  6185. {
  6186. ParcelGodMarkAsContentHandler(this,
  6187. ParcelGodMarkAsContent.AgentData.AgentID,
  6188. ParcelGodMarkAsContent.ParcelData.LocalID);
  6189. return true;
  6190. }
  6191. return false;
  6192. }
  6193. private bool HandleFreezeUser(IClientAPI client, Packet Packet)
  6194. {
  6195. FreezeUserPacket FreezeUser = (FreezeUserPacket)Packet;
  6196. if(SessionId != FreezeUser.AgentData.SessionID || AgentId != FreezeUser.AgentData.AgentID)
  6197. return false;
  6198. FreezeUserUpdate FreezeUserHandler = OnParcelFreezeUser;
  6199. if (FreezeUserHandler != null)
  6200. {
  6201. FreezeUserHandler(this,
  6202. FreezeUser.AgentData.AgentID,
  6203. FreezeUser.Data.Flags,
  6204. FreezeUser.Data.TargetID);
  6205. return true;
  6206. }
  6207. return false;
  6208. }
  6209. private bool HandleEjectUser(IClientAPI client, Packet Packet)
  6210. {
  6211. EjectUserPacket EjectUser =
  6212. (EjectUserPacket)Packet;
  6213. if(SessionId != EjectUser.AgentData.SessionID || AgentId != EjectUser.AgentData.AgentID)
  6214. return false;
  6215. EjectUserUpdate EjectUserHandler = OnParcelEjectUser;
  6216. if (EjectUserHandler != null)
  6217. {
  6218. EjectUserHandler(this,
  6219. EjectUser.AgentData.AgentID,
  6220. EjectUser.Data.Flags,
  6221. EjectUser.Data.TargetID);
  6222. return true;
  6223. }
  6224. return false;
  6225. }
  6226. private bool HandleParcelBuyPass(IClientAPI client, Packet Packet)
  6227. {
  6228. ParcelBuyPassPacket ParcelBuyPass =
  6229. (ParcelBuyPassPacket)Packet;
  6230. if(SessionId != ParcelBuyPass.AgentData.SessionID || AgentId != ParcelBuyPass.AgentData.AgentID)
  6231. return false;
  6232. ParcelBuyPass ParcelBuyPassHandler = OnParcelBuyPass;
  6233. if (ParcelBuyPassHandler != null)
  6234. {
  6235. ParcelBuyPassHandler(this,
  6236. ParcelBuyPass.AgentData.AgentID,
  6237. ParcelBuyPass.ParcelData.LocalID);
  6238. return true;
  6239. }
  6240. return false;
  6241. }
  6242. private bool HandleParcelBuyRequest(IClientAPI sender, Packet Pack)
  6243. {
  6244. ParcelBuyPacket parcel = (ParcelBuyPacket)Pack;
  6245. if (parcel.AgentData.AgentID == AgentId && parcel.AgentData.SessionID == SessionId)
  6246. {
  6247. ParcelBuy handlerParcelBuy = OnParcelBuy;
  6248. if (handlerParcelBuy != null)
  6249. {
  6250. handlerParcelBuy(parcel.AgentData.AgentID, parcel.Data.GroupID, parcel.Data.Final,
  6251. parcel.Data.IsGroupOwned,
  6252. parcel.Data.RemoveContribution, parcel.Data.LocalID, parcel.ParcelData.Area,
  6253. parcel.ParcelData.Price,
  6254. false);
  6255. }
  6256. return true;
  6257. }
  6258. return false;
  6259. }
  6260. private bool HandleUUIDGroupNameRequest(IClientAPI sender, Packet Pack)
  6261. {
  6262. ScenePresence sp = (ScenePresence)SceneAgent;
  6263. if(sp == null || sp.IsDeleted || (sp.IsInTransit && !sp.IsInLocalTransit))
  6264. return true;
  6265. UUIDGroupNameRequestPacket upack = (UUIDGroupNameRequestPacket)Pack;
  6266. for (int i = 0; i < upack.UUIDNameBlock.Length; i++)
  6267. {
  6268. UUIDNameRequest handlerUUIDGroupNameRequest = OnUUIDGroupNameRequest;
  6269. if (handlerUUIDGroupNameRequest != null)
  6270. {
  6271. handlerUUIDGroupNameRequest(upack.UUIDNameBlock[i].ID, this);
  6272. }
  6273. }
  6274. return true;
  6275. }
  6276. public bool HandleGenericMessage(IClientAPI sender, Packet pack)
  6277. {
  6278. GenericMessagePacket gmpack = (GenericMessagePacket)pack;
  6279. if (m_genericPacketHandlers.Count == 0) return false;
  6280. if (gmpack.AgentData.SessionID != SessionId) return false;
  6281. GenericMessage handlerGenericMessage = null;
  6282. string method = Util.FieldToString(gmpack.MethodData.Method).ToLower().Trim();
  6283. if (m_genericPacketHandlers.TryGetValue(method, out handlerGenericMessage))
  6284. {
  6285. List<string> msg = new List<string>();
  6286. List<byte[]> msgBytes = new List<byte[]>();
  6287. if (handlerGenericMessage != null)
  6288. {
  6289. foreach (GenericMessagePacket.ParamListBlock block in gmpack.ParamList)
  6290. {
  6291. msg.Add(Util.FieldToString(block.Parameter));
  6292. msgBytes.Add(block.Parameter);
  6293. }
  6294. try
  6295. {
  6296. if (OnBinaryGenericMessage != null)
  6297. {
  6298. OnBinaryGenericMessage(this, method, msgBytes.ToArray());
  6299. }
  6300. handlerGenericMessage(sender, method, msg);
  6301. return true;
  6302. }
  6303. catch (Exception e)
  6304. {
  6305. m_log.ErrorFormat(
  6306. "[LLCLIENTVIEW]: Exeception when handling generic message {0}{1}", e.Message, e.StackTrace);
  6307. }
  6308. }
  6309. }
  6310. //m_log.Debug("[LLCLIENTVIEW]: Not handling GenericMessage with method-type of: " + method);
  6311. return false;
  6312. }
  6313. public bool HandleObjectGroupRequest(IClientAPI sender, Packet Pack)
  6314. {
  6315. ObjectGroupPacket ogpack = (ObjectGroupPacket)Pack;
  6316. if (ogpack.AgentData.SessionID != SessionId) return false;
  6317. RequestObjectPropertiesFamily handlerObjectGroupRequest = OnObjectGroupRequest;
  6318. if (handlerObjectGroupRequest != null)
  6319. {
  6320. for (int i = 0; i < ogpack.ObjectData.Length; i++)
  6321. {
  6322. handlerObjectGroupRequest(this, ogpack.AgentData.GroupID, ogpack.ObjectData[i].ObjectLocalID, UUID.Zero);
  6323. }
  6324. }
  6325. return true;
  6326. }
  6327. private bool HandleViewerEffect(IClientAPI sender, Packet Pack)
  6328. {
  6329. ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
  6330. if (viewer.AgentData.SessionID != SessionId) return false;
  6331. ViewerEffectEventHandler handlerViewerEffect = OnViewerEffect;
  6332. if (handlerViewerEffect != null)
  6333. {
  6334. int length = viewer.Effect.Length;
  6335. List<ViewerEffectEventHandlerArg> args = new List<ViewerEffectEventHandlerArg>(length);
  6336. for (int i = 0; i < length; i++)
  6337. {
  6338. //copy the effects block arguments into the event handler arg.
  6339. ViewerEffectEventHandlerArg argument = new ViewerEffectEventHandlerArg();
  6340. argument.AgentID = viewer.Effect[i].AgentID;
  6341. argument.Color = viewer.Effect[i].Color;
  6342. argument.Duration = viewer.Effect[i].Duration;
  6343. argument.ID = viewer.Effect[i].ID;
  6344. argument.Type = viewer.Effect[i].Type;
  6345. argument.TypeData = viewer.Effect[i].TypeData;
  6346. args.Add(argument);
  6347. }
  6348. handlerViewerEffect(sender, args);
  6349. }
  6350. return true;
  6351. }
  6352. private bool HandleVelocityInterpolateOff(IClientAPI sender, Packet Pack)
  6353. {
  6354. VelocityInterpolateOffPacket p = (VelocityInterpolateOffPacket)Pack;
  6355. if (p.AgentData.SessionID != SessionId ||
  6356. p.AgentData.AgentID != AgentId)
  6357. return true;
  6358. m_VelocityInterpolate = false;
  6359. return true;
  6360. }
  6361. private bool HandleVelocityInterpolateOn(IClientAPI sender, Packet Pack)
  6362. {
  6363. VelocityInterpolateOnPacket p = (VelocityInterpolateOnPacket)Pack;
  6364. if (p.AgentData.SessionID != SessionId ||
  6365. p.AgentData.AgentID != AgentId)
  6366. return true;
  6367. m_VelocityInterpolate = true;
  6368. return true;
  6369. }
  6370. private bool HandleAvatarPropertiesRequest(IClientAPI sender, Packet Pack)
  6371. {
  6372. AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;
  6373. #region Packet Session and User Check
  6374. if (avatarProperties.AgentData.SessionID != SessionId ||
  6375. avatarProperties.AgentData.AgentID != AgentId)
  6376. return true;
  6377. #endregion
  6378. RequestAvatarProperties handlerRequestAvatarProperties = OnRequestAvatarProperties;
  6379. if (handlerRequestAvatarProperties != null)
  6380. {
  6381. handlerRequestAvatarProperties(this, avatarProperties.AgentData.AvatarID);
  6382. }
  6383. return true;
  6384. }
  6385. private bool HandleChatFromViewer(IClientAPI sender, Packet Pack)
  6386. {
  6387. ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
  6388. #region Packet Session and User Check
  6389. if (inchatpack.AgentData.SessionID != SessionId ||
  6390. inchatpack.AgentData.AgentID != AgentId)
  6391. return true;
  6392. #endregion
  6393. string fromName = String.Empty; //ClientAvatar.firstname + " " + ClientAvatar.lastname;
  6394. byte[] message = inchatpack.ChatData.Message;
  6395. byte type = inchatpack.ChatData.Type;
  6396. Vector3 fromPos = new Vector3(); // ClientAvatar.Pos;
  6397. // UUID fromAgentID = AgentId;
  6398. int channel = inchatpack.ChatData.Channel;
  6399. if (OnChatFromClient != null)
  6400. {
  6401. OSChatMessage args = new OSChatMessage();
  6402. args.Channel = channel;
  6403. args.From = fromName;
  6404. args.Message = Utils.BytesToString(message);
  6405. args.Type = (ChatTypeEnum)type;
  6406. args.Position = fromPos;
  6407. args.Scene = Scene;
  6408. args.Sender = this;
  6409. args.SenderUUID = this.AgentId;
  6410. ChatMessage handlerChatFromClient = OnChatFromClient;
  6411. if (handlerChatFromClient != null)
  6412. handlerChatFromClient(this, args);
  6413. }
  6414. return true;
  6415. }
  6416. private bool HandlerAvatarPropertiesUpdate(IClientAPI sender, Packet Pack)
  6417. {
  6418. AvatarPropertiesUpdatePacket avatarProps = (AvatarPropertiesUpdatePacket)Pack;
  6419. #region Packet Session and User Check
  6420. if (avatarProps.AgentData.SessionID != SessionId ||
  6421. avatarProps.AgentData.AgentID != AgentId)
  6422. return true;
  6423. #endregion
  6424. UpdateAvatarProperties handlerUpdateAvatarProperties = OnUpdateAvatarProperties;
  6425. if (handlerUpdateAvatarProperties != null)
  6426. {
  6427. AvatarPropertiesUpdatePacket.PropertiesDataBlock Properties = avatarProps.PropertiesData;
  6428. UserProfileData UserProfile = new UserProfileData();
  6429. UserProfile.ID = AgentId;
  6430. UserProfile.AboutText = Utils.BytesToString(Properties.AboutText);
  6431. UserProfile.FirstLifeAboutText = Utils.BytesToString(Properties.FLAboutText);
  6432. UserProfile.FirstLifeImage = Properties.FLImageID;
  6433. UserProfile.Image = Properties.ImageID;
  6434. UserProfile.ProfileUrl = Utils.BytesToString(Properties.ProfileURL);
  6435. UserProfile.UserFlags &= ~3;
  6436. UserProfile.UserFlags |= Properties.AllowPublish ? 1 : 0;
  6437. UserProfile.UserFlags |= Properties.MaturePublish ? 2 : 0;
  6438. handlerUpdateAvatarProperties(this, UserProfile);
  6439. }
  6440. return true;
  6441. }
  6442. private bool HandlerScriptDialogReply(IClientAPI sender, Packet Pack)
  6443. {
  6444. ScriptDialogReplyPacket rdialog = (ScriptDialogReplyPacket)Pack;
  6445. //m_log.DebugFormat("[CLIENT]: Received ScriptDialogReply from {0}", rdialog.Data.ObjectID);
  6446. #region Packet Session and User Check
  6447. if (rdialog.AgentData.SessionID != SessionId ||
  6448. rdialog.AgentData.AgentID != AgentId)
  6449. return true;
  6450. #endregion
  6451. int ch = rdialog.Data.ChatChannel;
  6452. byte[] msg = rdialog.Data.ButtonLabel;
  6453. if (OnChatFromClient != null)
  6454. {
  6455. OSChatMessage args = new OSChatMessage();
  6456. args.Channel = ch;
  6457. args.From = String.Empty;
  6458. args.Message = Utils.BytesToString(msg);
  6459. args.Type = ChatTypeEnum.Region; //Behaviour in SL is that the response can be heard from any distance
  6460. args.Position = new Vector3();
  6461. args.Scene = Scene;
  6462. args.Sender = this;
  6463. ChatMessage handlerChatFromClient2 = OnChatFromClient;
  6464. if (handlerChatFromClient2 != null)
  6465. handlerChatFromClient2(this, args);
  6466. }
  6467. return true;
  6468. }
  6469. private bool HandlerImprovedInstantMessage(IClientAPI sender, Packet Pack)
  6470. {
  6471. ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack;
  6472. #region Packet Session and User Check
  6473. if (msgpack.AgentData.SessionID != SessionId ||
  6474. msgpack.AgentData.AgentID != AgentId)
  6475. return true;
  6476. #endregion
  6477. string IMfromName = Util.FieldToString(msgpack.MessageBlock.FromAgentName);
  6478. string IMmessage = Utils.BytesToString(msgpack.MessageBlock.Message);
  6479. ImprovedInstantMessage handlerInstantMessage = OnInstantMessage;
  6480. if (handlerInstantMessage != null)
  6481. {
  6482. GridInstantMessage im = new GridInstantMessage(Scene,
  6483. msgpack.AgentData.AgentID,
  6484. IMfromName,
  6485. msgpack.MessageBlock.ToAgentID,
  6486. msgpack.MessageBlock.Dialog,
  6487. msgpack.MessageBlock.FromGroup,
  6488. IMmessage,
  6489. msgpack.MessageBlock.ID,
  6490. msgpack.MessageBlock.Offline != 0 ? true : false,
  6491. msgpack.MessageBlock.Position,
  6492. msgpack.MessageBlock.BinaryBucket,
  6493. true);
  6494. handlerInstantMessage(this, im);
  6495. }
  6496. return true;
  6497. }
  6498. private bool HandlerAcceptFriendship(IClientAPI sender, Packet Pack)
  6499. {
  6500. AcceptFriendshipPacket afriendpack = (AcceptFriendshipPacket)Pack;
  6501. #region Packet Session and User Check
  6502. if (afriendpack.AgentData.SessionID != SessionId ||
  6503. afriendpack.AgentData.AgentID != AgentId)
  6504. return true;
  6505. #endregion
  6506. // My guess is this is the folder to stick the calling card into
  6507. List<UUID> callingCardFolders = new List<UUID>();
  6508. UUID transactionID = afriendpack.TransactionBlock.TransactionID;
  6509. for (int fi = 0; fi < afriendpack.FolderData.Length; fi++)
  6510. {
  6511. callingCardFolders.Add(afriendpack.FolderData[fi].FolderID);
  6512. }
  6513. FriendActionDelegate handlerApproveFriendRequest = OnApproveFriendRequest;
  6514. if (handlerApproveFriendRequest != null)
  6515. {
  6516. handlerApproveFriendRequest(this, transactionID, callingCardFolders);
  6517. }
  6518. return true;
  6519. }
  6520. private bool HandlerDeclineFriendship(IClientAPI sender, Packet Pack)
  6521. {
  6522. DeclineFriendshipPacket dfriendpack = (DeclineFriendshipPacket)Pack;
  6523. #region Packet Session and User Check
  6524. if (dfriendpack.AgentData.SessionID != SessionId ||
  6525. dfriendpack.AgentData.AgentID != AgentId)
  6526. return true;
  6527. #endregion
  6528. if (OnDenyFriendRequest != null)
  6529. {
  6530. OnDenyFriendRequest(this,
  6531. dfriendpack.TransactionBlock.TransactionID,
  6532. null);
  6533. }
  6534. return true;
  6535. }
  6536. private bool HandlerTerminateFriendship(IClientAPI sender, Packet Pack)
  6537. {
  6538. TerminateFriendshipPacket tfriendpack = (TerminateFriendshipPacket)Pack;
  6539. #region Packet Session and User Check
  6540. if (tfriendpack.AgentData.SessionID != SessionId ||
  6541. tfriendpack.AgentData.AgentID != AgentId)
  6542. return true;
  6543. #endregion
  6544. UUID exFriendID = tfriendpack.ExBlock.OtherID;
  6545. FriendshipTermination TerminateFriendshipHandler = OnTerminateFriendship;
  6546. if (TerminateFriendshipHandler != null)
  6547. {
  6548. TerminateFriendshipHandler(this, exFriendID);
  6549. return true;
  6550. }
  6551. return false;
  6552. }
  6553. private bool HandleFindAgent(IClientAPI client, Packet Packet)
  6554. {
  6555. FindAgentPacket FindAgent =
  6556. (FindAgentPacket)Packet;
  6557. FindAgentUpdate FindAgentHandler = OnFindAgent;
  6558. if (FindAgentHandler != null)
  6559. {
  6560. FindAgentHandler(this,FindAgent.AgentBlock.Hunter,FindAgent.AgentBlock.Prey);
  6561. return true;
  6562. }
  6563. return false;
  6564. }
  6565. private bool HandleTrackAgent(IClientAPI client, Packet Packet)
  6566. {
  6567. TrackAgentPacket TrackAgent =
  6568. (TrackAgentPacket)Packet;
  6569. TrackAgentUpdate TrackAgentHandler = OnTrackAgent;
  6570. if (TrackAgentHandler != null)
  6571. {
  6572. TrackAgentHandler(this,
  6573. TrackAgent.AgentData.AgentID,
  6574. TrackAgent.TargetData.PreyID);
  6575. return true;
  6576. }
  6577. return false;
  6578. }
  6579. private bool HandlerRezObject(IClientAPI sender, Packet Pack)
  6580. {
  6581. RezObjectPacket rezPacket = (RezObjectPacket)Pack;
  6582. #region Packet Session and User Check
  6583. if (rezPacket.AgentData.SessionID != SessionId ||
  6584. rezPacket.AgentData.AgentID != AgentId)
  6585. return true;
  6586. #endregion
  6587. RezObject handlerRezObject = OnRezObject;
  6588. if (handlerRezObject != null)
  6589. {
  6590. UUID rezGroupID = rezPacket.AgentData.GroupID;
  6591. if(!IsGroupMember(rezGroupID))
  6592. rezGroupID = UUID.Zero;
  6593. handlerRezObject(this, rezPacket.InventoryData.ItemID, rezGroupID, rezPacket.RezData.RayEnd,
  6594. rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID,
  6595. rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection,
  6596. rezPacket.RezData.RezSelected, rezPacket.RezData.RemoveItem,
  6597. rezPacket.RezData.FromTaskID);
  6598. }
  6599. return true;
  6600. }
  6601. private class DeRezObjectInfo
  6602. {
  6603. public int count;
  6604. public List<uint> objectids;
  6605. }
  6606. private Dictionary<UUID, DeRezObjectInfo> m_DeRezObjectDelayed = new Dictionary<UUID, DeRezObjectInfo>();
  6607. private bool HandlerDeRezObject(IClientAPI sender, Packet Pack)
  6608. {
  6609. DeRezObject handlerDeRezObject = OnDeRezObject;
  6610. if (handlerDeRezObject == null)
  6611. return true;
  6612. DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)Pack;
  6613. #region Packet Session and User Check
  6614. if (DeRezPacket.AgentData.SessionID != SessionId ||
  6615. DeRezPacket.AgentData.AgentID != AgentId)
  6616. return true;
  6617. #endregion
  6618. List<uint> deRezIDs;
  6619. DeRezAction action = (DeRezAction)DeRezPacket.AgentBlock.Destination;
  6620. int numberPackets = DeRezPacket.AgentBlock.PacketCount;
  6621. int curPacket = DeRezPacket.AgentBlock.PacketNumber;
  6622. UUID id = DeRezPacket.AgentBlock.TransactionID;
  6623. if (numberPackets > 1)
  6624. {
  6625. DeRezObjectInfo info;
  6626. if (!m_DeRezObjectDelayed.TryGetValue(id, out info))
  6627. {
  6628. deRezIDs = new List<uint>();
  6629. info = new DeRezObjectInfo();
  6630. info.count = 0;
  6631. info.objectids = deRezIDs;
  6632. m_DeRezObjectDelayed[id] = info;
  6633. }
  6634. else
  6635. {
  6636. deRezIDs = info.objectids;
  6637. }
  6638. foreach (DeRezObjectPacket.ObjectDataBlock data in DeRezPacket.ObjectData)
  6639. {
  6640. deRezIDs.Add(data.ObjectLocalID);
  6641. }
  6642. info.count++;
  6643. if (info.count < numberPackets)
  6644. return true;
  6645. m_DeRezObjectDelayed.Remove(id);
  6646. info.objectids = null;
  6647. }
  6648. else
  6649. {
  6650. deRezIDs = new List<uint>();
  6651. foreach (DeRezObjectPacket.ObjectDataBlock data in DeRezPacket.ObjectData)
  6652. {
  6653. deRezIDs.Add(data.ObjectLocalID);
  6654. }
  6655. }
  6656. if (handlerDeRezObject != null)
  6657. handlerDeRezObject(this, deRezIDs, DeRezPacket.AgentBlock.GroupID,
  6658. action, DeRezPacket.AgentBlock.DestinationID);
  6659. return true;
  6660. }
  6661. private bool HandlerRezRestoreToWorld(IClientAPI sender, Packet Pack)
  6662. {
  6663. RezRestoreToWorldPacket restore = (RezRestoreToWorldPacket)Pack;
  6664. #region Packet Session and User Check
  6665. if (restore.AgentData.SessionID != SessionId ||
  6666. restore.AgentData.AgentID != AgentId)
  6667. return true;
  6668. #endregion
  6669. RezRestoreToWorld handlerRezRestoreToWorld = OnRezRestoreToWorld;
  6670. if (handlerRezRestoreToWorld != null)
  6671. handlerRezRestoreToWorld(this, restore.InventoryData.ItemID);
  6672. return true;
  6673. }
  6674. private bool HandlerModifyLand(IClientAPI sender, Packet Pack)
  6675. {
  6676. ModifyLandPacket modify = (ModifyLandPacket)Pack;
  6677. #region Packet Session and User Check
  6678. if (modify.AgentData.SessionID != SessionId ||
  6679. modify.AgentData.AgentID != AgentId)
  6680. return true;
  6681. #endregion
  6682. //m_log.Info("[LAND]: LAND:" + modify.ToString());
  6683. if (modify.ParcelData.Length > 0)
  6684. {
  6685. // Note: the ModifyTerrain event handler sends out updated packets before the end of this event. Therefore,
  6686. // a simple boolean value should work and perhaps queue up just a few terrain patch packets at the end of the edit.
  6687. if (OnModifyTerrain != null)
  6688. {
  6689. for (int i = 0; i < modify.ParcelData.Length; i++)
  6690. {
  6691. ModifyTerrain handlerModifyTerrain = OnModifyTerrain;
  6692. if (handlerModifyTerrain != null)
  6693. {
  6694. handlerModifyTerrain(AgentId, modify.ModifyBlock.Height, modify.ModifyBlock.Seconds,
  6695. modify.ModifyBlock.BrushSize,
  6696. modify.ModifyBlock.Action, modify.ParcelData[i].North,
  6697. modify.ParcelData[i].West, modify.ParcelData[i].South,
  6698. modify.ParcelData[i].East, AgentId);
  6699. }
  6700. }
  6701. }
  6702. }
  6703. return true;
  6704. }
  6705. private bool HandlerRegionHandshakeReply(IClientAPI sender, Packet Pack)
  6706. {
  6707. Action<IClientAPI> handlerRegionHandShakeReply = OnRegionHandShakeReply;
  6708. if (handlerRegionHandShakeReply != null)
  6709. {
  6710. handlerRegionHandShakeReply(this);
  6711. }
  6712. return true;
  6713. }
  6714. private bool HandlerAgentWearablesRequest(IClientAPI sender, Packet Pack)
  6715. {
  6716. GenericCall1 handlerRequestWearables = OnRequestWearables;
  6717. if (handlerRequestWearables != null)
  6718. {
  6719. handlerRequestWearables(sender);
  6720. }
  6721. Action<IClientAPI> handlerRequestAvatarsData = OnRequestAvatarsData;
  6722. if (handlerRequestAvatarsData != null)
  6723. {
  6724. handlerRequestAvatarsData(this);
  6725. }
  6726. return true;
  6727. }
  6728. private bool HandlerAgentSetAppearance(IClientAPI sender, Packet Pack)
  6729. {
  6730. AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
  6731. #region Packet Session and User Check
  6732. if (appear.AgentData.SessionID != SessionId ||
  6733. appear.AgentData.AgentID != AgentId)
  6734. return true;
  6735. #endregion
  6736. SetAppearance handlerSetAppearance = OnSetAppearance;
  6737. if (handlerSetAppearance != null)
  6738. {
  6739. // Temporarily protect ourselves from the mantis #951 failure.
  6740. // However, we could do this for several other handlers where a failure isn't terminal
  6741. // for the client session anyway, in order to protect ourselves against bad code in plugins
  6742. Vector3 avSize = appear.AgentData.Size;
  6743. try
  6744. {
  6745. byte[] visualparams = new byte[appear.VisualParam.Length];
  6746. for (int i = 0; i < appear.VisualParam.Length; i++)
  6747. visualparams[i] = appear.VisualParam[i].ParamValue;
  6748. //var b = appear.WearableData[0];
  6749. Primitive.TextureEntry te = null;
  6750. if (appear.ObjectData.TextureEntry.Length > 1)
  6751. te = new Primitive.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length);
  6752. WearableCacheItem[] cacheitems = new WearableCacheItem[appear.WearableData.Length];
  6753. for (int i=0; i<appear.WearableData.Length;i++)
  6754. cacheitems[i] = new WearableCacheItem(){
  6755. CacheId = appear.WearableData[i].CacheID,
  6756. TextureIndex=Convert.ToUInt32(appear.WearableData[i].TextureIndex)
  6757. };
  6758. handlerSetAppearance(sender, te, visualparams,avSize, cacheitems);
  6759. }
  6760. catch (Exception e)
  6761. {
  6762. m_log.ErrorFormat(
  6763. "[CLIENT VIEW]: AgentSetApperance packet handler threw an exception, {0}",
  6764. e);
  6765. }
  6766. }
  6767. return true;
  6768. }
  6769. private bool HandlerAgentIsNowWearing(IClientAPI sender, Packet Pack)
  6770. {
  6771. if (OnAvatarNowWearing != null)
  6772. {
  6773. AgentIsNowWearingPacket nowWearing = (AgentIsNowWearingPacket)Pack;
  6774. #region Packet Session and User Check
  6775. if (nowWearing.AgentData.SessionID != SessionId ||
  6776. nowWearing.AgentData.AgentID != AgentId)
  6777. return true;
  6778. #endregion
  6779. AvatarWearingArgs wearingArgs = new AvatarWearingArgs();
  6780. for (int i = 0; i < nowWearing.WearableData.Length; i++)
  6781. {
  6782. //m_log.DebugFormat("[XXX]: Wearable type {0} item {1}", nowWearing.WearableData[i].WearableType, nowWearing.WearableData[i].ItemID);
  6783. AvatarWearingArgs.Wearable wearable =
  6784. new AvatarWearingArgs.Wearable(nowWearing.WearableData[i].ItemID,
  6785. nowWearing.WearableData[i].WearableType);
  6786. wearingArgs.NowWearing.Add(wearable);
  6787. }
  6788. AvatarNowWearing handlerAvatarNowWearing = OnAvatarNowWearing;
  6789. if (handlerAvatarNowWearing != null)
  6790. {
  6791. handlerAvatarNowWearing(this, wearingArgs);
  6792. }
  6793. }
  6794. return true;
  6795. }
  6796. private bool HandlerRezSingleAttachmentFromInv(IClientAPI sender, Packet Pack)
  6797. {
  6798. RezSingleAttachmentFromInv handlerRezSingleAttachment = OnRezSingleAttachmentFromInv;
  6799. if (handlerRezSingleAttachment != null)
  6800. {
  6801. RezSingleAttachmentFromInvPacket rez = (RezSingleAttachmentFromInvPacket)Pack;
  6802. #region Packet Session and User Check
  6803. if (rez.AgentData.SessionID != SessionId ||
  6804. rez.AgentData.AgentID != AgentId)
  6805. return true;
  6806. #endregion
  6807. handlerRezSingleAttachment(this, rez.ObjectData.ItemID,
  6808. rez.ObjectData.AttachmentPt);
  6809. }
  6810. return true;
  6811. }
  6812. private bool HandleRezMultipleAttachmentsFromInv(IClientAPI sender, Packet Pack)
  6813. {
  6814. RezMultipleAttachmentsFromInv handlerRezMultipleAttachments = OnRezMultipleAttachmentsFromInv;
  6815. if (handlerRezMultipleAttachments != null)
  6816. {
  6817. List<KeyValuePair<UUID, uint>> rezlist = new List<KeyValuePair<UUID, uint>>();
  6818. foreach (RezMultipleAttachmentsFromInvPacket.ObjectDataBlock obj in ((RezMultipleAttachmentsFromInvPacket)Pack).ObjectData)
  6819. rezlist.Add(new KeyValuePair<UUID, uint>(obj.ItemID, obj.AttachmentPt));
  6820. handlerRezMultipleAttachments(this, rezlist);
  6821. }
  6822. return true;
  6823. }
  6824. private bool HandleDetachAttachmentIntoInv(IClientAPI sender, Packet Pack)
  6825. {
  6826. UUIDNameRequest handlerDetachAttachmentIntoInv = OnDetachAttachmentIntoInv;
  6827. if (handlerDetachAttachmentIntoInv != null)
  6828. {
  6829. DetachAttachmentIntoInvPacket detachtoInv = (DetachAttachmentIntoInvPacket)Pack;
  6830. #region Packet Session and User Check
  6831. // UNSUPPORTED ON THIS PACKET
  6832. #endregion
  6833. UUID itemID = detachtoInv.ObjectData.ItemID;
  6834. // UUID ATTACH_agentID = detachtoInv.ObjectData.AgentID;
  6835. handlerDetachAttachmentIntoInv(itemID, this);
  6836. }
  6837. return true;
  6838. }
  6839. private bool HandleObjectAttach(IClientAPI sender, Packet Pack)
  6840. {
  6841. if (OnObjectAttach != null)
  6842. {
  6843. ObjectAttachPacket att = (ObjectAttachPacket)Pack;
  6844. #region Packet Session and User Check
  6845. if (att.AgentData.SessionID != SessionId ||
  6846. att.AgentData.AgentID != AgentId)
  6847. return true;
  6848. #endregion
  6849. ObjectAttach handlerObjectAttach = OnObjectAttach;
  6850. if (handlerObjectAttach != null)
  6851. {
  6852. if (att.ObjectData.Length > 0)
  6853. {
  6854. handlerObjectAttach(this, att.ObjectData[0].ObjectLocalID, att.AgentData.AttachmentPoint, false);
  6855. }
  6856. }
  6857. }
  6858. return true;
  6859. }
  6860. private bool HandleObjectDetach(IClientAPI sender, Packet Pack)
  6861. {
  6862. ObjectDetachPacket dett = (ObjectDetachPacket)Pack;
  6863. #region Packet Session and User Check
  6864. if (dett.AgentData.SessionID != SessionId ||
  6865. dett.AgentData.AgentID != AgentId)
  6866. return true;
  6867. #endregion
  6868. for (int j = 0; j < dett.ObjectData.Length; j++)
  6869. {
  6870. uint obj = dett.ObjectData[j].ObjectLocalID;
  6871. ObjectDeselect handlerObjectDetach = OnObjectDetach;
  6872. if (handlerObjectDetach != null)
  6873. {
  6874. handlerObjectDetach(obj, this);
  6875. }
  6876. }
  6877. return true;
  6878. }
  6879. private bool HandleObjectDrop(IClientAPI sender, Packet Pack)
  6880. {
  6881. ObjectDropPacket dropp = (ObjectDropPacket)Pack;
  6882. #region Packet Session and User Check
  6883. if (dropp.AgentData.SessionID != SessionId ||
  6884. dropp.AgentData.AgentID != AgentId)
  6885. return true;
  6886. #endregion
  6887. for (int j = 0; j < dropp.ObjectData.Length; j++)
  6888. {
  6889. uint obj = dropp.ObjectData[j].ObjectLocalID;
  6890. ObjectDrop handlerObjectDrop = OnObjectDrop;
  6891. if (handlerObjectDrop != null)
  6892. {
  6893. handlerObjectDrop(obj, this);
  6894. }
  6895. }
  6896. return true;
  6897. }
  6898. private bool HandleSetAlwaysRun(IClientAPI sender, Packet Pack)
  6899. {
  6900. SetAlwaysRunPacket run = (SetAlwaysRunPacket)Pack;
  6901. #region Packet Session and User Check
  6902. if (run.AgentData.SessionID != SessionId ||
  6903. run.AgentData.AgentID != AgentId)
  6904. return true;
  6905. #endregion
  6906. SetAlwaysRun handlerSetAlwaysRun = OnSetAlwaysRun;
  6907. if (handlerSetAlwaysRun != null)
  6908. handlerSetAlwaysRun(this, run.AgentData.AlwaysRun);
  6909. return true;
  6910. }
  6911. private bool HandleCompleteAgentMovement(IClientAPI sender, Packet Pack)
  6912. {
  6913. m_log.DebugFormat("[LLClientView] HandleCompleteAgentMovement");
  6914. Action<IClientAPI, bool> handlerCompleteMovementToRegion = OnCompleteMovementToRegion;
  6915. if (handlerCompleteMovementToRegion != null)
  6916. {
  6917. handlerCompleteMovementToRegion(sender, true);
  6918. }
  6919. else
  6920. m_log.Debug("HandleCompleteAgentMovement NULL handler");
  6921. handlerCompleteMovementToRegion = null;
  6922. return true;
  6923. }
  6924. private bool HandleAgentAnimation(IClientAPI sender, Packet Pack)
  6925. {
  6926. AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
  6927. #region Packet Session and User Check
  6928. if (AgentAni.AgentData.SessionID != SessionId ||
  6929. AgentAni.AgentData.AgentID != AgentId)
  6930. return true;
  6931. #endregion
  6932. ChangeAnim handlerChangeAnim = null;
  6933. for (int i = 0; i < AgentAni.AnimationList.Length; i++)
  6934. {
  6935. handlerChangeAnim = OnChangeAnim;
  6936. if (handlerChangeAnim != null)
  6937. {
  6938. handlerChangeAnim(AgentAni.AnimationList[i].AnimID, AgentAni.AnimationList[i].StartAnim, false);
  6939. }
  6940. }
  6941. handlerChangeAnim = OnChangeAnim;
  6942. if (handlerChangeAnim != null)
  6943. {
  6944. handlerChangeAnim(UUID.Zero, false, true);
  6945. }
  6946. return true;
  6947. }
  6948. private bool HandleAgentRequestSit(IClientAPI sender, Packet Pack)
  6949. {
  6950. if (OnAgentRequestSit != null)
  6951. {
  6952. AgentRequestSitPacket agentRequestSit = (AgentRequestSitPacket)Pack;
  6953. #region Packet Session and User Check
  6954. if (agentRequestSit.AgentData.SessionID != SessionId ||
  6955. agentRequestSit.AgentData.AgentID != AgentId)
  6956. return true;
  6957. #endregion
  6958. if (SceneAgent.IsChildAgent)
  6959. {
  6960. SendCantSitBecauseChildAgentResponse();
  6961. return true;
  6962. }
  6963. AgentRequestSit handlerAgentRequestSit = OnAgentRequestSit;
  6964. if (handlerAgentRequestSit != null)
  6965. handlerAgentRequestSit(this, agentRequestSit.AgentData.AgentID,
  6966. agentRequestSit.TargetObject.TargetID, agentRequestSit.TargetObject.Offset);
  6967. }
  6968. return true;
  6969. }
  6970. private bool HandleAgentSit(IClientAPI sender, Packet Pack)
  6971. {
  6972. if (OnAgentSit != null)
  6973. {
  6974. AgentSitPacket agentSit = (AgentSitPacket)Pack;
  6975. #region Packet Session and User Check
  6976. if (agentSit.AgentData.SessionID != SessionId ||
  6977. agentSit.AgentData.AgentID != AgentId)
  6978. return true;
  6979. #endregion
  6980. if (SceneAgent.IsChildAgent)
  6981. {
  6982. SendCantSitBecauseChildAgentResponse();
  6983. return true;
  6984. }
  6985. AgentSit handlerAgentSit = OnAgentSit;
  6986. if (handlerAgentSit != null)
  6987. {
  6988. OnAgentSit(this, agentSit.AgentData.AgentID);
  6989. }
  6990. }
  6991. return true;
  6992. }
  6993. /// <summary>
  6994. /// Used when a child agent gets a sit response which should not be fulfilled.
  6995. /// </summary>
  6996. private void SendCantSitBecauseChildAgentResponse()
  6997. {
  6998. SendAlertMessage("Try moving closer. Can't sit on object because it is not in the same region as you.");
  6999. }
  7000. private bool HandleSoundTrigger(IClientAPI sender, Packet Pack)
  7001. {
  7002. SoundTriggerPacket soundTriggerPacket = (SoundTriggerPacket)Pack;
  7003. #region Packet Session and User Check
  7004. #endregion
  7005. SoundTrigger handlerSoundTrigger = OnSoundTrigger;
  7006. if (handlerSoundTrigger != null)
  7007. {
  7008. // UUIDS are sent as zeroes by the client, substitute agent's id
  7009. handlerSoundTrigger(soundTriggerPacket.SoundData.SoundID, AgentId,
  7010. AgentId, AgentId,
  7011. soundTriggerPacket.SoundData.Gain, soundTriggerPacket.SoundData.Position,
  7012. soundTriggerPacket.SoundData.Handle);
  7013. }
  7014. return true;
  7015. }
  7016. private bool HandleAvatarPickerRequest(IClientAPI sender, Packet Pack)
  7017. {
  7018. AvatarPickerRequestPacket avRequestQuery = (AvatarPickerRequestPacket)Pack;
  7019. #region Packet Session and User Check
  7020. if (avRequestQuery.AgentData.SessionID != SessionId ||
  7021. avRequestQuery.AgentData.AgentID != AgentId)
  7022. return true;
  7023. #endregion
  7024. AvatarPickerRequestPacket.AgentDataBlock Requestdata = avRequestQuery.AgentData;
  7025. AvatarPickerRequestPacket.DataBlock querydata = avRequestQuery.Data;
  7026. //m_log.Debug("Agent Sends:" + Utils.BytesToString(querydata.Name));
  7027. AvatarPickerRequest handlerAvatarPickerRequest = OnAvatarPickerRequest;
  7028. if (handlerAvatarPickerRequest != null)
  7029. {
  7030. handlerAvatarPickerRequest(this, Requestdata.AgentID, Requestdata.QueryID,
  7031. Utils.BytesToString(querydata.Name));
  7032. }
  7033. return true;
  7034. }
  7035. private bool HandleAgentDataUpdateRequest(IClientAPI sender, Packet Pack)
  7036. {
  7037. AgentDataUpdateRequestPacket avRequestDataUpdatePacket = (AgentDataUpdateRequestPacket)Pack;
  7038. #region Packet Session and User Check
  7039. if (avRequestDataUpdatePacket.AgentData.SessionID != SessionId ||
  7040. avRequestDataUpdatePacket.AgentData.AgentID != AgentId)
  7041. return true;
  7042. #endregion
  7043. FetchInventory handlerAgentDataUpdateRequest = OnAgentDataUpdateRequest;
  7044. if (handlerAgentDataUpdateRequest != null)
  7045. {
  7046. handlerAgentDataUpdateRequest(this, avRequestDataUpdatePacket.AgentData.AgentID, avRequestDataUpdatePacket.AgentData.SessionID);
  7047. }
  7048. return true;
  7049. }
  7050. private bool HandleUserInfoRequest(IClientAPI sender, Packet Pack)
  7051. {
  7052. UserInfoRequest handlerUserInfoRequest = OnUserInfoRequest;
  7053. if (handlerUserInfoRequest != null)
  7054. {
  7055. handlerUserInfoRequest(this);
  7056. }
  7057. else
  7058. {
  7059. SendUserInfoReply(false, true, "");
  7060. }
  7061. return true;
  7062. }
  7063. private bool HandleUpdateUserInfo(IClientAPI sender, Packet Pack)
  7064. {
  7065. UpdateUserInfoPacket updateUserInfo = (UpdateUserInfoPacket)Pack;
  7066. #region Packet Session and User Check
  7067. if (updateUserInfo.AgentData.SessionID != SessionId ||
  7068. updateUserInfo.AgentData.AgentID != AgentId)
  7069. return true;
  7070. #endregion
  7071. UpdateUserInfo handlerUpdateUserInfo = OnUpdateUserInfo;
  7072. if (handlerUpdateUserInfo != null)
  7073. {
  7074. bool visible = true;
  7075. string DirectoryVisibility =
  7076. Utils.BytesToString(updateUserInfo.UserData.DirectoryVisibility);
  7077. if (DirectoryVisibility == "hidden")
  7078. visible = false;
  7079. handlerUpdateUserInfo(
  7080. updateUserInfo.UserData.IMViaEMail,
  7081. visible, this);
  7082. }
  7083. return true;
  7084. }
  7085. private bool HandleSetStartLocationRequest(IClientAPI sender, Packet Pack)
  7086. {
  7087. SetStartLocationRequestPacket avSetStartLocationRequestPacket = (SetStartLocationRequestPacket)Pack;
  7088. #region Packet Session and User Check
  7089. if (avSetStartLocationRequestPacket.AgentData.SessionID != SessionId ||
  7090. avSetStartLocationRequestPacket.AgentData.AgentID != AgentId)
  7091. return true;
  7092. #endregion
  7093. if (avSetStartLocationRequestPacket.AgentData.AgentID == AgentId && avSetStartLocationRequestPacket.AgentData.SessionID == SessionId)
  7094. {
  7095. // Linden Client limitation..
  7096. if (avSetStartLocationRequestPacket.StartLocationData.LocationPos.X == 255.5f
  7097. || avSetStartLocationRequestPacket.StartLocationData.LocationPos.Y == 255.5f)
  7098. {
  7099. ScenePresence avatar = null;
  7100. if (((Scene)m_scene).TryGetScenePresence(AgentId, out avatar))
  7101. {
  7102. if (avSetStartLocationRequestPacket.StartLocationData.LocationPos.X == 255.5f)
  7103. {
  7104. avSetStartLocationRequestPacket.StartLocationData.LocationPos.X = avatar.AbsolutePosition.X;
  7105. }
  7106. if (avSetStartLocationRequestPacket.StartLocationData.LocationPos.Y == 255.5f)
  7107. {
  7108. avSetStartLocationRequestPacket.StartLocationData.LocationPos.Y = avatar.AbsolutePosition.Y;
  7109. }
  7110. }
  7111. }
  7112. TeleportLocationRequest handlerSetStartLocationRequest = OnSetStartLocationRequest;
  7113. if (handlerSetStartLocationRequest != null)
  7114. {
  7115. handlerSetStartLocationRequest(this, 0, avSetStartLocationRequestPacket.StartLocationData.LocationPos,
  7116. avSetStartLocationRequestPacket.StartLocationData.LocationLookAt,
  7117. avSetStartLocationRequestPacket.StartLocationData.LocationID);
  7118. }
  7119. }
  7120. return true;
  7121. }
  7122. private bool HandleAgentThrottle(IClientAPI sender, Packet Pack)
  7123. {
  7124. AgentThrottlePacket atpack = (AgentThrottlePacket)Pack;
  7125. #region Packet Session and User Check
  7126. if (atpack.AgentData.SessionID != SessionId ||
  7127. atpack.AgentData.AgentID != AgentId)
  7128. return true;
  7129. #endregion
  7130. m_udpClient.SetThrottles(atpack.Throttle.Throttles);
  7131. GenericCall2 handler = OnUpdateThrottles;
  7132. if (handler != null)
  7133. {
  7134. handler();
  7135. }
  7136. return true;
  7137. }
  7138. private bool HandleAgentPause(IClientAPI sender, Packet Pack)
  7139. {
  7140. m_udpClient.IsPaused = true;
  7141. return true;
  7142. }
  7143. private bool HandleAgentResume(IClientAPI sender, Packet Pack)
  7144. {
  7145. m_udpClient.IsPaused = false;
  7146. SendStartPingCheck(m_udpClient.CurrentPingSequence++);
  7147. return true;
  7148. }
  7149. private bool HandleForceScriptControlRelease(IClientAPI sender, Packet Pack)
  7150. {
  7151. ForceReleaseControls handlerForceReleaseControls = OnForceReleaseControls;
  7152. if (handlerForceReleaseControls != null)
  7153. {
  7154. handlerForceReleaseControls(this, AgentId);
  7155. }
  7156. return true;
  7157. }
  7158. #endregion Scene/Avatar
  7159. #region Objects/m_sceneObjects
  7160. private bool HandleObjectLink(IClientAPI sender, Packet Pack)
  7161. {
  7162. ObjectLinkPacket link = (ObjectLinkPacket)Pack;
  7163. #region Packet Session and User Check
  7164. if (link.AgentData.SessionID != SessionId ||
  7165. link.AgentData.AgentID != AgentId)
  7166. return true;
  7167. #endregion
  7168. uint parentprimid = 0;
  7169. List<uint> childrenprims = new List<uint>();
  7170. if (link.ObjectData.Length > 1)
  7171. {
  7172. parentprimid = link.ObjectData[0].ObjectLocalID;
  7173. for (int i = 1; i < link.ObjectData.Length; i++)
  7174. {
  7175. childrenprims.Add(link.ObjectData[i].ObjectLocalID);
  7176. }
  7177. }
  7178. LinkObjects handlerLinkObjects = OnLinkObjects;
  7179. if (handlerLinkObjects != null)
  7180. {
  7181. handlerLinkObjects(this, parentprimid, childrenprims);
  7182. }
  7183. return true;
  7184. }
  7185. private bool HandleObjectDelink(IClientAPI sender, Packet Pack)
  7186. {
  7187. ObjectDelinkPacket delink = (ObjectDelinkPacket)Pack;
  7188. #region Packet Session and User Check
  7189. if (delink.AgentData.SessionID != SessionId ||
  7190. delink.AgentData.AgentID != AgentId)
  7191. return true;
  7192. #endregion
  7193. // It appears the prim at index 0 is not always the root prim (for
  7194. // instance, when one prim of a link set has been edited independently
  7195. // of the others). Therefore, we'll pass all the ids onto the delink
  7196. // method for it to decide which is the root.
  7197. List<uint> prims = new List<uint>();
  7198. for (int i = 0; i < delink.ObjectData.Length; i++)
  7199. {
  7200. prims.Add(delink.ObjectData[i].ObjectLocalID);
  7201. }
  7202. DelinkObjects handlerDelinkObjects = OnDelinkObjects;
  7203. if (handlerDelinkObjects != null)
  7204. {
  7205. handlerDelinkObjects(prims, this);
  7206. }
  7207. return true;
  7208. }
  7209. private bool HandleObjectAdd(IClientAPI sender, Packet Pack)
  7210. {
  7211. if (OnAddPrim != null)
  7212. {
  7213. ObjectAddPacket addPacket = (ObjectAddPacket)Pack;
  7214. #region Packet Session and User Check
  7215. if (addPacket.AgentData.SessionID != SessionId ||
  7216. addPacket.AgentData.AgentID != AgentId)
  7217. return true;
  7218. #endregion
  7219. PrimitiveBaseShape shape = GetShapeFromAddPacket(addPacket);
  7220. // m_log.Info("[REZData]: " + addPacket.ToString());
  7221. //BypassRaycast: 1
  7222. //RayStart: <69.79469, 158.2652, 98.40343>
  7223. //RayEnd: <61.97724, 141.995, 92.58341>
  7224. //RayTargetID: 00000000-0000-0000-0000-000000000000
  7225. //Check to see if adding the prim is allowed; useful for any module wanting to restrict the
  7226. //object from rezing initially
  7227. AddNewPrim handlerAddPrim = OnAddPrim;
  7228. if (handlerAddPrim != null)
  7229. handlerAddPrim(AgentId, addPacket.AgentData.GroupID, addPacket.ObjectData.RayEnd, addPacket.ObjectData.Rotation, shape, addPacket.ObjectData.BypassRaycast, addPacket.ObjectData.RayStart, addPacket.ObjectData.RayTargetID, addPacket.ObjectData.RayEndIsIntersection);
  7230. }
  7231. return true;
  7232. }
  7233. private bool HandleObjectShape(IClientAPI sender, Packet Pack)
  7234. {
  7235. ObjectShapePacket shapePacket = (ObjectShapePacket)Pack;
  7236. #region Packet Session and User Check
  7237. if (shapePacket.AgentData.SessionID != SessionId ||
  7238. shapePacket.AgentData.AgentID != AgentId)
  7239. return true;
  7240. #endregion
  7241. UpdateShape handlerUpdatePrimShape = null;
  7242. for (int i = 0; i < shapePacket.ObjectData.Length; i++)
  7243. {
  7244. handlerUpdatePrimShape = OnUpdatePrimShape;
  7245. if (handlerUpdatePrimShape != null)
  7246. {
  7247. UpdateShapeArgs shapeData = new UpdateShapeArgs();
  7248. shapeData.ObjectLocalID = shapePacket.ObjectData[i].ObjectLocalID;
  7249. shapeData.PathBegin = shapePacket.ObjectData[i].PathBegin;
  7250. shapeData.PathCurve = shapePacket.ObjectData[i].PathCurve;
  7251. shapeData.PathEnd = shapePacket.ObjectData[i].PathEnd;
  7252. shapeData.PathRadiusOffset = shapePacket.ObjectData[i].PathRadiusOffset;
  7253. shapeData.PathRevolutions = shapePacket.ObjectData[i].PathRevolutions;
  7254. shapeData.PathScaleX = shapePacket.ObjectData[i].PathScaleX;
  7255. shapeData.PathScaleY = shapePacket.ObjectData[i].PathScaleY;
  7256. shapeData.PathShearX = shapePacket.ObjectData[i].PathShearX;
  7257. shapeData.PathShearY = shapePacket.ObjectData[i].PathShearY;
  7258. shapeData.PathSkew = shapePacket.ObjectData[i].PathSkew;
  7259. shapeData.PathTaperX = shapePacket.ObjectData[i].PathTaperX;
  7260. shapeData.PathTaperY = shapePacket.ObjectData[i].PathTaperY;
  7261. shapeData.PathTwist = shapePacket.ObjectData[i].PathTwist;
  7262. shapeData.PathTwistBegin = shapePacket.ObjectData[i].PathTwistBegin;
  7263. shapeData.ProfileBegin = shapePacket.ObjectData[i].ProfileBegin;
  7264. shapeData.ProfileCurve = shapePacket.ObjectData[i].ProfileCurve;
  7265. shapeData.ProfileEnd = shapePacket.ObjectData[i].ProfileEnd;
  7266. shapeData.ProfileHollow = shapePacket.ObjectData[i].ProfileHollow;
  7267. handlerUpdatePrimShape(m_agentId, shapePacket.ObjectData[i].ObjectLocalID,
  7268. shapeData);
  7269. }
  7270. }
  7271. return true;
  7272. }
  7273. private bool HandleObjectExtraParams(IClientAPI sender, Packet Pack)
  7274. {
  7275. ObjectExtraParamsPacket extraPar = (ObjectExtraParamsPacket)Pack;
  7276. #region Packet Session and User Check
  7277. if (extraPar.AgentData.SessionID != SessionId ||
  7278. extraPar.AgentData.AgentID != AgentId)
  7279. return true;
  7280. #endregion
  7281. ObjectExtraParams handlerUpdateExtraParams = OnUpdateExtraParams;
  7282. if (handlerUpdateExtraParams != null)
  7283. {
  7284. for (int i = 0; i < extraPar.ObjectData.Length; i++)
  7285. {
  7286. handlerUpdateExtraParams(m_agentId, extraPar.ObjectData[i].ObjectLocalID,
  7287. extraPar.ObjectData[i].ParamType,
  7288. extraPar.ObjectData[i].ParamInUse, extraPar.ObjectData[i].ParamData);
  7289. }
  7290. }
  7291. return true;
  7292. }
  7293. private bool HandleObjectDuplicate(IClientAPI sender, Packet Pack)
  7294. {
  7295. ObjectDuplicatePacket dupe = (ObjectDuplicatePacket)Pack;
  7296. #region Packet Session and User Check
  7297. if (dupe.AgentData.SessionID != SessionId ||
  7298. dupe.AgentData.AgentID != AgentId)
  7299. return true;
  7300. #endregion
  7301. // ObjectDuplicatePacket.AgentDataBlock AgentandGroupData = dupe.AgentData;
  7302. ObjectDuplicate handlerObjectDuplicate = null;
  7303. handlerObjectDuplicate = OnObjectDuplicate;
  7304. if (handlerObjectDuplicate != null)
  7305. {
  7306. for (int i = 0; i < dupe.ObjectData.Length; i++)
  7307. {
  7308. UUID rezGroupID = dupe.AgentData.GroupID;
  7309. if(!IsGroupMember(rezGroupID))
  7310. rezGroupID = UUID.Zero;
  7311. handlerObjectDuplicate(dupe.ObjectData[i].ObjectLocalID, dupe.SharedData.Offset,
  7312. dupe.SharedData.DuplicateFlags, AgentId,
  7313. rezGroupID);
  7314. }
  7315. }
  7316. return true;
  7317. }
  7318. private bool HandleRequestMultipleObjects(IClientAPI sender, Packet Pack)
  7319. {
  7320. RequestMultipleObjectsPacket incomingRequest = (RequestMultipleObjectsPacket)Pack;
  7321. #region Packet Session and User Check
  7322. if (incomingRequest.AgentData.SessionID != SessionId ||
  7323. incomingRequest.AgentData.AgentID != AgentId)
  7324. return true;
  7325. #endregion
  7326. ObjectRequest handlerObjectRequest = null;
  7327. for (int i = 0; i < incomingRequest.ObjectData.Length; i++)
  7328. {
  7329. handlerObjectRequest = OnObjectRequest;
  7330. if (handlerObjectRequest != null)
  7331. {
  7332. handlerObjectRequest(incomingRequest.ObjectData[i].ID, this);
  7333. }
  7334. }
  7335. return true;
  7336. }
  7337. private bool HandleObjectSelect(IClientAPI sender, Packet Pack)
  7338. {
  7339. ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
  7340. #region Packet Session and User Check
  7341. if (incomingselect.AgentData.SessionID != SessionId ||
  7342. incomingselect.AgentData.AgentID != AgentId)
  7343. return true;
  7344. #endregion
  7345. List<uint> thisSelection = new List<uint>();
  7346. ObjectSelect handlerObjectSelect = null;
  7347. uint objID;
  7348. handlerObjectSelect = OnObjectSelect;
  7349. if (handlerObjectSelect != null)
  7350. {
  7351. for (int i = 0; i < incomingselect.ObjectData.Length; i++)
  7352. {
  7353. objID = incomingselect.ObjectData[i].ObjectLocalID;
  7354. thisSelection.Add(objID);
  7355. }
  7356. handlerObjectSelect(thisSelection, this);
  7357. }
  7358. return true;
  7359. }
  7360. private bool HandleObjectDeselect(IClientAPI sender, Packet Pack)
  7361. {
  7362. ObjectDeselectPacket incomingdeselect = (ObjectDeselectPacket)Pack;
  7363. #region Packet Session and User Check
  7364. if (incomingdeselect.AgentData.SessionID != SessionId ||
  7365. incomingdeselect.AgentData.AgentID != AgentId)
  7366. return true;
  7367. #endregion
  7368. ObjectDeselect handlerObjectDeselect = null;
  7369. uint objID;
  7370. for (int i = 0; i < incomingdeselect.ObjectData.Length; i++)
  7371. {
  7372. objID = incomingdeselect.ObjectData[i].ObjectLocalID;
  7373. handlerObjectDeselect = OnObjectDeselect;
  7374. if (handlerObjectDeselect != null)
  7375. {
  7376. OnObjectDeselect(objID, this);
  7377. }
  7378. }
  7379. return true;
  7380. }
  7381. private bool HandleObjectPosition(IClientAPI sender, Packet Pack)
  7382. {
  7383. // DEPRECATED: but till libsecondlife removes it, people will use it
  7384. ObjectPositionPacket position = (ObjectPositionPacket)Pack;
  7385. #region Packet Session and User Check
  7386. if (position.AgentData.SessionID != SessionId ||
  7387. position.AgentData.AgentID != AgentId)
  7388. return true;
  7389. #endregion
  7390. for (int i = 0; i < position.ObjectData.Length; i++)
  7391. {
  7392. UpdateVector handlerUpdateVector = OnUpdatePrimGroupPosition;
  7393. if (handlerUpdateVector != null)
  7394. handlerUpdateVector(position.ObjectData[i].ObjectLocalID, position.ObjectData[i].Position, this);
  7395. }
  7396. return true;
  7397. }
  7398. private bool HandleObjectScale(IClientAPI sender, Packet Pack)
  7399. {
  7400. // DEPRECATED: but till libsecondlife removes it, people will use it
  7401. ObjectScalePacket scale = (ObjectScalePacket)Pack;
  7402. #region Packet Session and User Check
  7403. if (scale.AgentData.SessionID != SessionId ||
  7404. scale.AgentData.AgentID != AgentId)
  7405. return true;
  7406. #endregion
  7407. for (int i = 0; i < scale.ObjectData.Length; i++)
  7408. {
  7409. UpdateVector handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale;
  7410. if (handlerUpdatePrimGroupScale != null)
  7411. handlerUpdatePrimGroupScale(scale.ObjectData[i].ObjectLocalID, scale.ObjectData[i].Scale, this);
  7412. }
  7413. return true;
  7414. }
  7415. private bool HandleObjectRotation(IClientAPI sender, Packet Pack)
  7416. {
  7417. // DEPRECATED: but till libsecondlife removes it, people will use it
  7418. ObjectRotationPacket rotation = (ObjectRotationPacket)Pack;
  7419. #region Packet Session and User Check
  7420. if (rotation.AgentData.SessionID != SessionId ||
  7421. rotation.AgentData.AgentID != AgentId)
  7422. return true;
  7423. #endregion
  7424. for (int i = 0; i < rotation.ObjectData.Length; i++)
  7425. {
  7426. UpdatePrimRotation handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
  7427. if (handlerUpdatePrimRotation != null)
  7428. handlerUpdatePrimRotation(rotation.ObjectData[i].ObjectLocalID, rotation.ObjectData[i].Rotation, this);
  7429. }
  7430. return true;
  7431. }
  7432. private bool HandleObjectFlagUpdate(IClientAPI sender, Packet Pack)
  7433. {
  7434. ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
  7435. #region Packet Session and User Check
  7436. if (flags.AgentData.SessionID != SessionId ||
  7437. flags.AgentData.AgentID != AgentId)
  7438. return true;
  7439. #endregion
  7440. UpdatePrimFlags handlerUpdatePrimFlags = OnUpdatePrimFlags;
  7441. if (handlerUpdatePrimFlags != null)
  7442. {
  7443. // byte[] data = Pack.ToBytes();
  7444. // 46,47,48 are special positions within the packet
  7445. // This may change so perhaps we need a better way
  7446. // of storing this (OMV.FlagUpdatePacket.UsePhysics,etc?)
  7447. /*
  7448. bool UsePhysics = (data[46] != 0) ? true : false;
  7449. bool IsTemporary = (data[47] != 0) ? true : false;
  7450. bool IsPhantom = (data[48] != 0) ? true : false;
  7451. handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, this);
  7452. */
  7453. bool UsePhysics = flags.AgentData.UsePhysics;
  7454. bool IsPhantom = flags.AgentData.IsPhantom;
  7455. bool IsTemporary = flags.AgentData.IsTemporary;
  7456. ObjectFlagUpdatePacket.ExtraPhysicsBlock[] blocks = flags.ExtraPhysics;
  7457. ExtraPhysicsData physdata = new ExtraPhysicsData();
  7458. if (blocks == null || blocks.Length == 0)
  7459. {
  7460. physdata.PhysShapeType = PhysShapeType.invalid;
  7461. }
  7462. else
  7463. {
  7464. ObjectFlagUpdatePacket.ExtraPhysicsBlock phsblock = blocks[0];
  7465. physdata.PhysShapeType = (PhysShapeType)phsblock.PhysicsShapeType;
  7466. physdata.Bounce = phsblock.Restitution;
  7467. physdata.Density = phsblock.Density;
  7468. physdata.Friction = phsblock.Friction;
  7469. physdata.GravitationModifier = phsblock.GravityMultiplier;
  7470. }
  7471. handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, physdata, this);
  7472. }
  7473. return true;
  7474. }
  7475. Dictionary<uint, uint> objImageSeqs = null;
  7476. double lastobjImageSeqsMS = 0.0;
  7477. private bool HandleObjectImage(IClientAPI sender, Packet Pack)
  7478. {
  7479. ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
  7480. UpdatePrimTexture handlerUpdatePrimTexture = OnUpdatePrimTexture;
  7481. if (handlerUpdatePrimTexture == null)
  7482. return true;
  7483. double now = Util.GetTimeStampMS();
  7484. if(objImageSeqs == null || ( now - lastobjImageSeqsMS > 30000.0))
  7485. {
  7486. objImageSeqs = null; // yeah i know superstition...
  7487. objImageSeqs = new Dictionary<uint, uint>(16);
  7488. }
  7489. lastobjImageSeqsMS = now;
  7490. uint seq = Pack.Header.Sequence;
  7491. uint id;
  7492. uint lastseq;
  7493. ObjectImagePacket.ObjectDataBlock o;
  7494. for (int i = 0; i < imagePack.ObjectData.Length; i++)
  7495. {
  7496. o = imagePack.ObjectData[i];
  7497. id = o.ObjectLocalID;
  7498. if(objImageSeqs.TryGetValue(id, out lastseq))
  7499. {
  7500. if(seq <= lastseq)
  7501. continue;
  7502. }
  7503. objImageSeqs[id] = seq;
  7504. handlerUpdatePrimTexture(id, o.TextureEntry, this);
  7505. }
  7506. return true;
  7507. }
  7508. private bool HandleObjectGrab(IClientAPI sender, Packet Pack)
  7509. {
  7510. ObjectGrabPacket grab = (ObjectGrabPacket)Pack;
  7511. #region Packet Session and User Check
  7512. if (grab.AgentData.SessionID != SessionId ||
  7513. grab.AgentData.AgentID != AgentId)
  7514. return true;
  7515. #endregion
  7516. GrabObject handlerGrabObject = OnGrabObject;
  7517. if (handlerGrabObject != null)
  7518. {
  7519. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  7520. if ((grab.SurfaceInfo != null) && (grab.SurfaceInfo.Length > 0))
  7521. {
  7522. foreach (ObjectGrabPacket.SurfaceInfoBlock surfaceInfo in grab.SurfaceInfo)
  7523. {
  7524. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  7525. arg.Binormal = surfaceInfo.Binormal;
  7526. arg.FaceIndex = surfaceInfo.FaceIndex;
  7527. arg.Normal = surfaceInfo.Normal;
  7528. arg.Position = surfaceInfo.Position;
  7529. arg.STCoord = surfaceInfo.STCoord;
  7530. arg.UVCoord = surfaceInfo.UVCoord;
  7531. touchArgs.Add(arg);
  7532. }
  7533. }
  7534. handlerGrabObject(grab.ObjectData.LocalID, grab.ObjectData.GrabOffset, this, touchArgs);
  7535. }
  7536. return true;
  7537. }
  7538. private bool HandleObjectGrabUpdate(IClientAPI sender, Packet Pack)
  7539. {
  7540. ObjectGrabUpdatePacket grabUpdate = (ObjectGrabUpdatePacket)Pack;
  7541. #region Packet Session and User Check
  7542. if (grabUpdate.AgentData.SessionID != SessionId ||
  7543. grabUpdate.AgentData.AgentID != AgentId)
  7544. return true;
  7545. #endregion
  7546. MoveObject handlerGrabUpdate = OnGrabUpdate;
  7547. if (handlerGrabUpdate != null)
  7548. {
  7549. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  7550. if ((grabUpdate.SurfaceInfo != null) && (grabUpdate.SurfaceInfo.Length > 0))
  7551. {
  7552. foreach (ObjectGrabUpdatePacket.SurfaceInfoBlock surfaceInfo in grabUpdate.SurfaceInfo)
  7553. {
  7554. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  7555. arg.Binormal = surfaceInfo.Binormal;
  7556. arg.FaceIndex = surfaceInfo.FaceIndex;
  7557. arg.Normal = surfaceInfo.Normal;
  7558. arg.Position = surfaceInfo.Position;
  7559. arg.STCoord = surfaceInfo.STCoord;
  7560. arg.UVCoord = surfaceInfo.UVCoord;
  7561. touchArgs.Add(arg);
  7562. }
  7563. }
  7564. handlerGrabUpdate(grabUpdate.ObjectData.ObjectID, grabUpdate.ObjectData.GrabOffsetInitial,
  7565. grabUpdate.ObjectData.GrabPosition, this, touchArgs);
  7566. }
  7567. return true;
  7568. }
  7569. private bool HandleObjectDeGrab(IClientAPI sender, Packet Pack)
  7570. {
  7571. ObjectDeGrabPacket deGrab = (ObjectDeGrabPacket)Pack;
  7572. #region Packet Session and User Check
  7573. if (deGrab.AgentData.SessionID != SessionId ||
  7574. deGrab.AgentData.AgentID != AgentId)
  7575. return true;
  7576. #endregion
  7577. DeGrabObject handlerDeGrabObject = OnDeGrabObject;
  7578. if (handlerDeGrabObject != null)
  7579. {
  7580. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  7581. if ((deGrab.SurfaceInfo != null) && (deGrab.SurfaceInfo.Length > 0))
  7582. {
  7583. foreach (ObjectDeGrabPacket.SurfaceInfoBlock surfaceInfo in deGrab.SurfaceInfo)
  7584. {
  7585. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  7586. arg.Binormal = surfaceInfo.Binormal;
  7587. arg.FaceIndex = surfaceInfo.FaceIndex;
  7588. arg.Normal = surfaceInfo.Normal;
  7589. arg.Position = surfaceInfo.Position;
  7590. arg.STCoord = surfaceInfo.STCoord;
  7591. arg.UVCoord = surfaceInfo.UVCoord;
  7592. touchArgs.Add(arg);
  7593. }
  7594. }
  7595. handlerDeGrabObject(deGrab.ObjectData.LocalID, this, touchArgs);
  7596. }
  7597. return true;
  7598. }
  7599. private bool HandleObjectSpinStart(IClientAPI sender, Packet Pack)
  7600. {
  7601. //m_log.Warn("[CLIENT]: unhandled ObjectSpinStart packet");
  7602. ObjectSpinStartPacket spinStart = (ObjectSpinStartPacket)Pack;
  7603. #region Packet Session and User Check
  7604. if (spinStart.AgentData.SessionID != SessionId ||
  7605. spinStart.AgentData.AgentID != AgentId)
  7606. return true;
  7607. #endregion
  7608. SpinStart handlerSpinStart = OnSpinStart;
  7609. if (handlerSpinStart != null)
  7610. {
  7611. handlerSpinStart(spinStart.ObjectData.ObjectID, this);
  7612. }
  7613. return true;
  7614. }
  7615. private bool HandleObjectSpinUpdate(IClientAPI sender, Packet Pack)
  7616. {
  7617. //m_log.Warn("[CLIENT]: unhandled ObjectSpinUpdate packet");
  7618. ObjectSpinUpdatePacket spinUpdate = (ObjectSpinUpdatePacket)Pack;
  7619. #region Packet Session and User Check
  7620. if (spinUpdate.AgentData.SessionID != SessionId ||
  7621. spinUpdate.AgentData.AgentID != AgentId)
  7622. return true;
  7623. #endregion
  7624. Vector3 axis;
  7625. float angle;
  7626. spinUpdate.ObjectData.Rotation.GetAxisAngle(out axis, out angle);
  7627. //m_log.Warn("[CLIENT]: ObjectSpinUpdate packet rot axis:" + axis + " angle:" + angle);
  7628. SpinObject handlerSpinUpdate = OnSpinUpdate;
  7629. if (handlerSpinUpdate != null)
  7630. {
  7631. handlerSpinUpdate(spinUpdate.ObjectData.ObjectID, spinUpdate.ObjectData.Rotation, this);
  7632. }
  7633. return true;
  7634. }
  7635. private bool HandleObjectSpinStop(IClientAPI sender, Packet Pack)
  7636. {
  7637. //m_log.Warn("[CLIENT]: unhandled ObjectSpinStop packet");
  7638. ObjectSpinStopPacket spinStop = (ObjectSpinStopPacket)Pack;
  7639. #region Packet Session and User Check
  7640. if (spinStop.AgentData.SessionID != SessionId ||
  7641. spinStop.AgentData.AgentID != AgentId)
  7642. return true;
  7643. #endregion
  7644. SpinStop handlerSpinStop = OnSpinStop;
  7645. if (handlerSpinStop != null)
  7646. {
  7647. handlerSpinStop(spinStop.ObjectData.ObjectID, this);
  7648. }
  7649. return true;
  7650. }
  7651. private bool HandleObjectDescription(IClientAPI sender, Packet Pack)
  7652. {
  7653. ObjectDescriptionPacket objDes = (ObjectDescriptionPacket)Pack;
  7654. #region Packet Session and User Check
  7655. if (objDes.AgentData.SessionID != SessionId ||
  7656. objDes.AgentData.AgentID != AgentId)
  7657. return true;
  7658. #endregion
  7659. GenericCall7 handlerObjectDescription = null;
  7660. for (int i = 0; i < objDes.ObjectData.Length; i++)
  7661. {
  7662. handlerObjectDescription = OnObjectDescription;
  7663. if (handlerObjectDescription != null)
  7664. {
  7665. handlerObjectDescription(this, objDes.ObjectData[i].LocalID,
  7666. Util.FieldToString(objDes.ObjectData[i].Description));
  7667. }
  7668. }
  7669. return true;
  7670. }
  7671. private bool HandleObjectName(IClientAPI sender, Packet Pack)
  7672. {
  7673. ObjectNamePacket objName = (ObjectNamePacket)Pack;
  7674. #region Packet Session and User Check
  7675. if (objName.AgentData.SessionID != SessionId ||
  7676. objName.AgentData.AgentID != AgentId)
  7677. return true;
  7678. #endregion
  7679. GenericCall7 handlerObjectName = null;
  7680. for (int i = 0; i < objName.ObjectData.Length; i++)
  7681. {
  7682. handlerObjectName = OnObjectName;
  7683. if (handlerObjectName != null)
  7684. {
  7685. handlerObjectName(this, objName.ObjectData[i].LocalID,
  7686. Util.FieldToString(objName.ObjectData[i].Name));
  7687. }
  7688. }
  7689. return true;
  7690. }
  7691. private bool HandleObjectPermissions(IClientAPI sender, Packet Pack)
  7692. {
  7693. if (OnObjectPermissions != null)
  7694. {
  7695. ObjectPermissionsPacket newobjPerms = (ObjectPermissionsPacket)Pack;
  7696. #region Packet Session and User Check
  7697. if (newobjPerms.AgentData.SessionID != SessionId ||
  7698. newobjPerms.AgentData.AgentID != AgentId)
  7699. return true;
  7700. #endregion
  7701. UUID AgentID = newobjPerms.AgentData.AgentID;
  7702. UUID SessionID = newobjPerms.AgentData.SessionID;
  7703. ObjectPermissions handlerObjectPermissions = null;
  7704. for (int i = 0; i < newobjPerms.ObjectData.Length; i++)
  7705. {
  7706. ObjectPermissionsPacket.ObjectDataBlock permChanges = newobjPerms.ObjectData[i];
  7707. byte field = permChanges.Field;
  7708. uint localID = permChanges.ObjectLocalID;
  7709. uint mask = permChanges.Mask;
  7710. byte set = permChanges.Set;
  7711. handlerObjectPermissions = OnObjectPermissions;
  7712. if (handlerObjectPermissions != null)
  7713. handlerObjectPermissions(this, AgentID, SessionID, field, localID, mask, set);
  7714. }
  7715. }
  7716. // Here's our data,
  7717. // PermField contains the field the info goes into
  7718. // PermField determines which mask we're changing
  7719. //
  7720. // chmask is the mask of the change
  7721. // setTF is whether we're adding it or taking it away
  7722. //
  7723. // objLocalID is the localID of the object.
  7724. // Unfortunately, we have to pass the event the packet because objData is an array
  7725. // That means multiple object perms may be updated in a single packet.
  7726. return true;
  7727. }
  7728. private bool HandleUndo(IClientAPI sender, Packet Pack)
  7729. {
  7730. UndoPacket undoitem = (UndoPacket)Pack;
  7731. #region Packet Session and User Check
  7732. if (undoitem.AgentData.SessionID != SessionId ||
  7733. undoitem.AgentData.AgentID != AgentId)
  7734. return true;
  7735. #endregion
  7736. if (undoitem.ObjectData.Length > 0)
  7737. {
  7738. for (int i = 0; i < undoitem.ObjectData.Length; i++)
  7739. {
  7740. UUID objiD = undoitem.ObjectData[i].ObjectID;
  7741. AgentSit handlerOnUndo = OnUndo;
  7742. if (handlerOnUndo != null)
  7743. {
  7744. handlerOnUndo(this, objiD);
  7745. }
  7746. }
  7747. }
  7748. return true;
  7749. }
  7750. private bool HandleLandUndo(IClientAPI sender, Packet Pack)
  7751. {
  7752. UndoLandPacket undolanditem = (UndoLandPacket)Pack;
  7753. #region Packet Session and User Check
  7754. if (undolanditem.AgentData.SessionID != SessionId ||
  7755. undolanditem.AgentData.AgentID != AgentId)
  7756. return true;
  7757. #endregion
  7758. LandUndo handlerOnUndo = OnLandUndo;
  7759. if (handlerOnUndo != null)
  7760. {
  7761. handlerOnUndo(this);
  7762. }
  7763. return true;
  7764. }
  7765. private bool HandleRedo(IClientAPI sender, Packet Pack)
  7766. {
  7767. RedoPacket redoitem = (RedoPacket)Pack;
  7768. #region Packet Session and User Check
  7769. if (redoitem.AgentData.SessionID != SessionId ||
  7770. redoitem.AgentData.AgentID != AgentId)
  7771. return true;
  7772. #endregion
  7773. if (redoitem.ObjectData.Length > 0)
  7774. {
  7775. for (int i = 0; i < redoitem.ObjectData.Length; i++)
  7776. {
  7777. UUID objiD = redoitem.ObjectData[i].ObjectID;
  7778. AgentSit handlerOnRedo = OnRedo;
  7779. if (handlerOnRedo != null)
  7780. {
  7781. handlerOnRedo(this, objiD);
  7782. }
  7783. }
  7784. }
  7785. return true;
  7786. }
  7787. private bool HandleObjectDuplicateOnRay(IClientAPI sender, Packet Pack)
  7788. {
  7789. ObjectDuplicateOnRayPacket dupeOnRay = (ObjectDuplicateOnRayPacket)Pack;
  7790. #region Packet Session and User Check
  7791. if (dupeOnRay.AgentData.SessionID != SessionId ||
  7792. dupeOnRay.AgentData.AgentID != AgentId)
  7793. return true;
  7794. #endregion
  7795. ObjectDuplicateOnRay handlerObjectDuplicateOnRay = null;
  7796. for (int i = 0; i < dupeOnRay.ObjectData.Length; i++)
  7797. {
  7798. handlerObjectDuplicateOnRay = OnObjectDuplicateOnRay;
  7799. if (handlerObjectDuplicateOnRay != null)
  7800. {
  7801. UUID rezGroupID = dupeOnRay.AgentData.GroupID;
  7802. if(!IsGroupMember(rezGroupID))
  7803. rezGroupID = UUID.Zero;
  7804. handlerObjectDuplicateOnRay(dupeOnRay.ObjectData[i].ObjectLocalID,
  7805. dupeOnRay.AgentData.DuplicateFlags, AgentId, rezGroupID,
  7806. dupeOnRay.AgentData.RayTargetID, dupeOnRay.AgentData.RayEnd,
  7807. dupeOnRay.AgentData.RayStart, dupeOnRay.AgentData.BypassRaycast,
  7808. dupeOnRay.AgentData.RayEndIsIntersection,
  7809. dupeOnRay.AgentData.CopyCenters, dupeOnRay.AgentData.CopyRotates);
  7810. }
  7811. }
  7812. return true;
  7813. }
  7814. private bool HandleRequestObjectPropertiesFamily(IClientAPI sender, Packet Pack)
  7815. {
  7816. //This powers the little tooltip that appears when you move your mouse over an object
  7817. RequestObjectPropertiesFamilyPacket packToolTip = (RequestObjectPropertiesFamilyPacket)Pack;
  7818. #region Packet Session and User Check
  7819. if (packToolTip.AgentData.SessionID != SessionId ||
  7820. packToolTip.AgentData.AgentID != AgentId)
  7821. return true;
  7822. #endregion
  7823. RequestObjectPropertiesFamilyPacket.ObjectDataBlock packObjBlock = packToolTip.ObjectData;
  7824. RequestObjectPropertiesFamily handlerRequestObjectPropertiesFamily = OnRequestObjectPropertiesFamily;
  7825. if (handlerRequestObjectPropertiesFamily != null)
  7826. {
  7827. handlerRequestObjectPropertiesFamily(this, m_agentId, packObjBlock.RequestFlags,
  7828. packObjBlock.ObjectID);
  7829. }
  7830. return true;
  7831. }
  7832. private bool HandleObjectIncludeInSearch(IClientAPI sender, Packet Pack)
  7833. {
  7834. //This lets us set objects to appear in search (stuff like DataSnapshot, etc)
  7835. ObjectIncludeInSearchPacket packInSearch = (ObjectIncludeInSearchPacket)Pack;
  7836. ObjectIncludeInSearch handlerObjectIncludeInSearch = null;
  7837. #region Packet Session and User Check
  7838. if (packInSearch.AgentData.SessionID != SessionId ||
  7839. packInSearch.AgentData.AgentID != AgentId)
  7840. return true;
  7841. #endregion
  7842. foreach (ObjectIncludeInSearchPacket.ObjectDataBlock objData in packInSearch.ObjectData)
  7843. {
  7844. bool inSearch = objData.IncludeInSearch;
  7845. uint localID = objData.ObjectLocalID;
  7846. handlerObjectIncludeInSearch = OnObjectIncludeInSearch;
  7847. if (handlerObjectIncludeInSearch != null)
  7848. {
  7849. handlerObjectIncludeInSearch(this, inSearch, localID);
  7850. }
  7851. }
  7852. return true;
  7853. }
  7854. private bool HandleScriptAnswerYes(IClientAPI sender, Packet Pack)
  7855. {
  7856. ScriptAnswerYesPacket scriptAnswer = (ScriptAnswerYesPacket)Pack;
  7857. #region Packet Session and User Check
  7858. if (scriptAnswer.AgentData.SessionID != SessionId ||
  7859. scriptAnswer.AgentData.AgentID != AgentId)
  7860. return true;
  7861. #endregion
  7862. ScriptAnswer handlerScriptAnswer = OnScriptAnswer;
  7863. if (handlerScriptAnswer != null)
  7864. {
  7865. handlerScriptAnswer(this, scriptAnswer.Data.TaskID, scriptAnswer.Data.ItemID, scriptAnswer.Data.Questions);
  7866. }
  7867. return true;
  7868. }
  7869. private bool HandleObjectClickAction(IClientAPI sender, Packet Pack)
  7870. {
  7871. ObjectClickActionPacket ocpacket = (ObjectClickActionPacket)Pack;
  7872. #region Packet Session and User Check
  7873. if (ocpacket.AgentData.SessionID != SessionId ||
  7874. ocpacket.AgentData.AgentID != AgentId)
  7875. return true;
  7876. #endregion
  7877. GenericCall7 handlerObjectClickAction = OnObjectClickAction;
  7878. if (handlerObjectClickAction != null)
  7879. {
  7880. foreach (ObjectClickActionPacket.ObjectDataBlock odata in ocpacket.ObjectData)
  7881. {
  7882. byte action = odata.ClickAction;
  7883. uint localID = odata.ObjectLocalID;
  7884. handlerObjectClickAction(this, localID, action.ToString());
  7885. }
  7886. }
  7887. return true;
  7888. }
  7889. private bool HandleObjectMaterial(IClientAPI sender, Packet Pack)
  7890. {
  7891. ObjectMaterialPacket ompacket = (ObjectMaterialPacket)Pack;
  7892. #region Packet Session and User Check
  7893. if (ompacket.AgentData.SessionID != SessionId ||
  7894. ompacket.AgentData.AgentID != AgentId)
  7895. return true;
  7896. #endregion
  7897. GenericCall7 handlerObjectMaterial = OnObjectMaterial;
  7898. if (handlerObjectMaterial != null)
  7899. {
  7900. foreach (ObjectMaterialPacket.ObjectDataBlock odata in ompacket.ObjectData)
  7901. {
  7902. byte material = odata.Material;
  7903. uint localID = odata.ObjectLocalID;
  7904. handlerObjectMaterial(this, localID, material.ToString());
  7905. }
  7906. }
  7907. return true;
  7908. }
  7909. #endregion Objects/m_sceneObjects
  7910. #region Inventory/Asset/Other related packets
  7911. private bool HandleRequestImage(IClientAPI sender, Packet Pack)
  7912. {
  7913. RequestImagePacket imageRequest = (RequestImagePacket)Pack;
  7914. //m_log.Debug("image request: " + Pack.ToString());
  7915. #region Packet Session and User Check
  7916. if (imageRequest.AgentData.SessionID != SessionId ||
  7917. imageRequest.AgentData.AgentID != AgentId)
  7918. return true;
  7919. #endregion
  7920. //handlerTextureRequest = null;
  7921. for (int i = 0; i < imageRequest.RequestImage.Length; i++)
  7922. {
  7923. TextureRequestArgs args = new TextureRequestArgs();
  7924. RequestImagePacket.RequestImageBlock block = imageRequest.RequestImage[i];
  7925. args.RequestedAssetID = block.Image;
  7926. args.DiscardLevel = block.DiscardLevel;
  7927. args.PacketNumber = block.Packet;
  7928. args.Priority = block.DownloadPriority;
  7929. args.requestSequence = imageRequest.Header.Sequence;
  7930. // NOTE: This is not a built in part of the LLUDP protocol, but we double the
  7931. // priority of avatar textures to get avatars rezzing in faster than the
  7932. // surrounding scene
  7933. if ((ImageType)block.Type == ImageType.Baked)
  7934. args.Priority *= 2.0f;
  7935. ImageManager.EnqueueReq(args);
  7936. }
  7937. return true;
  7938. }
  7939. /// <summary>
  7940. /// This is the entry point for the UDP route by which the client can retrieve asset data. If the request
  7941. /// is successful then a TransferInfo packet will be sent back, followed by one or more TransferPackets
  7942. /// </summary>
  7943. /// <param name="sender"></param>
  7944. /// <param name="Pack"></param>
  7945. /// <returns>This parameter may be ignored since we appear to return true whatever happens</returns>
  7946. private bool HandleTransferRequest(IClientAPI sender, Packet Pack)
  7947. {
  7948. //m_log.Debug("ClientView.ProcessPackets.cs:ProcessInPacket() - Got transfer request");
  7949. TransferRequestPacket transfer = (TransferRequestPacket)Pack;
  7950. UUID taskID = UUID.Zero;
  7951. if (transfer.TransferInfo.SourceType == (int)SourceType.SimInventoryItem)
  7952. {
  7953. if (!(((Scene)m_scene).Permissions.BypassPermissions()))
  7954. {
  7955. // We're spawning a thread because the permissions check can block this thread
  7956. Util.FireAndForget(delegate
  7957. {
  7958. // This requests the asset if needed
  7959. HandleSimInventoryTransferRequestWithPermsCheck(sender, transfer);
  7960. }, null, "LLClientView.HandleTransferRequest");
  7961. return true;
  7962. }
  7963. }
  7964. else if (transfer.TransferInfo.SourceType == (int)SourceType.SimEstate)
  7965. {
  7966. //TransferRequestPacket does not include covenant uuid?
  7967. //get scene covenant uuid
  7968. taskID = m_scene.RegionInfo.RegionSettings.Covenant;
  7969. }
  7970. // This is non-blocking
  7971. MakeAssetRequest(transfer, taskID);
  7972. return true;
  7973. }
  7974. private void HandleSimInventoryTransferRequestWithPermsCheck(IClientAPI sender, TransferRequestPacket transfer)
  7975. {
  7976. UUID taskID = new UUID(transfer.TransferInfo.Params, 48);
  7977. UUID itemID = new UUID(transfer.TransferInfo.Params, 64);
  7978. UUID requestID = new UUID(transfer.TransferInfo.Params, 80);
  7979. //m_log.DebugFormat(
  7980. // "[CLIENT]: Got request for asset {0} from item {1} in prim {2} by {3}",
  7981. // requestID, itemID, taskID, Name);
  7982. //m_log.Debug("Transfer Request: " + transfer.ToString());
  7983. // Validate inventory transfers
  7984. // Has to be done here, because AssetCache can't do it
  7985. //
  7986. if (taskID != UUID.Zero) // Prim
  7987. {
  7988. SceneObjectPart part = ((Scene)m_scene).GetSceneObjectPart(taskID);
  7989. if (part == null)
  7990. {
  7991. m_log.WarnFormat(
  7992. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but prim does not exist",
  7993. Name, requestID, itemID, taskID);
  7994. return;
  7995. }
  7996. TaskInventoryItem tii = part.Inventory.GetInventoryItem(itemID);
  7997. if (tii == null)
  7998. {
  7999. m_log.WarnFormat(
  8000. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but item does not exist",
  8001. Name, requestID, itemID, taskID);
  8002. return;
  8003. }
  8004. if (tii.Type == (int)AssetType.LSLText)
  8005. {
  8006. if (!((Scene)m_scene).Permissions.CanEditScript(itemID, taskID, AgentId))
  8007. return;
  8008. }
  8009. else if (tii.Type == (int)AssetType.Notecard)
  8010. {
  8011. if (!((Scene)m_scene).Permissions.CanEditNotecard(itemID, taskID, AgentId))
  8012. return;
  8013. }
  8014. else
  8015. {
  8016. // TODO: Change this code to allow items other than notecards and scripts to be successfully
  8017. // shared with group. In fact, this whole block of permissions checking should move to an IPermissionsModule
  8018. if (part.OwnerID != AgentId)
  8019. {
  8020. m_log.WarnFormat(
  8021. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but the prim is owned by {4}",
  8022. Name, requestID, itemID, taskID, part.OwnerID);
  8023. return;
  8024. }
  8025. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  8026. {
  8027. m_log.WarnFormat(
  8028. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but modify permissions are not set",
  8029. Name, requestID, itemID, taskID);
  8030. return;
  8031. }
  8032. if (tii.OwnerID != AgentId)
  8033. {
  8034. m_log.WarnFormat(
  8035. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but the item is owned by {4}",
  8036. Name, requestID, itemID, taskID, tii.OwnerID);
  8037. return;
  8038. }
  8039. if ((
  8040. tii.CurrentPermissions & ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy | (uint)PermissionMask.Transfer))
  8041. != ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy | (uint)PermissionMask.Transfer))
  8042. {
  8043. m_log.WarnFormat(
  8044. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but item permissions are not modify/copy/transfer",
  8045. Name, requestID, itemID, taskID);
  8046. return;
  8047. }
  8048. if (tii.AssetID != requestID)
  8049. {
  8050. m_log.WarnFormat(
  8051. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but this does not match item's asset {4}",
  8052. Name, requestID, itemID, taskID, tii.AssetID);
  8053. return;
  8054. }
  8055. }
  8056. }
  8057. else // Agent
  8058. {
  8059. IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
  8060. if (invAccess != null)
  8061. {
  8062. if (!invAccess.CanGetAgentInventoryItem(this, itemID, requestID))
  8063. return;
  8064. }
  8065. else
  8066. {
  8067. return;
  8068. }
  8069. }
  8070. // Permissions out of the way, let's request the asset
  8071. MakeAssetRequest(transfer, taskID);
  8072. }
  8073. private bool HandleAssetUploadRequest(IClientAPI sender, Packet Pack)
  8074. {
  8075. AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
  8076. // m_log.Debug("upload request " + request.ToString());
  8077. // m_log.Debug("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToString());
  8078. UUID temp = UUID.Combine(request.AssetBlock.TransactionID, SecureSessionId);
  8079. UDPAssetUploadRequest handlerAssetUploadRequest = OnAssetUploadRequest;
  8080. if (handlerAssetUploadRequest != null)
  8081. {
  8082. handlerAssetUploadRequest(this, temp,
  8083. request.AssetBlock.TransactionID, request.AssetBlock.Type,
  8084. request.AssetBlock.AssetData, request.AssetBlock.StoreLocal,
  8085. request.AssetBlock.Tempfile);
  8086. }
  8087. return true;
  8088. }
  8089. private bool HandleRequestXfer(IClientAPI sender, Packet Pack)
  8090. {
  8091. RequestXferPacket xferReq = (RequestXferPacket)Pack;
  8092. RequestXfer handlerRequestXfer = OnRequestXfer;
  8093. if (handlerRequestXfer != null)
  8094. {
  8095. handlerRequestXfer(this, xferReq.XferID.ID, Util.FieldToString(xferReq.XferID.Filename));
  8096. }
  8097. return true;
  8098. }
  8099. private bool HandleSendXferPacket(IClientAPI sender, Packet Pack)
  8100. {
  8101. SendXferPacketPacket xferRec = (SendXferPacketPacket)Pack;
  8102. XferReceive handlerXferReceive = OnXferReceive;
  8103. if (handlerXferReceive != null)
  8104. {
  8105. handlerXferReceive(this, xferRec.XferID.ID, xferRec.XferID.Packet, xferRec.DataPacket.Data);
  8106. }
  8107. return true;
  8108. }
  8109. private bool HandleConfirmXferPacket(IClientAPI sender, Packet Pack)
  8110. {
  8111. ConfirmXferPacketPacket confirmXfer = (ConfirmXferPacketPacket)Pack;
  8112. ConfirmXfer handlerConfirmXfer = OnConfirmXfer;
  8113. if (handlerConfirmXfer != null)
  8114. {
  8115. handlerConfirmXfer(this, confirmXfer.XferID.ID, confirmXfer.XferID.Packet);
  8116. }
  8117. return true;
  8118. }
  8119. private bool HandleAbortXfer(IClientAPI sender, Packet Pack)
  8120. {
  8121. AbortXferPacket abortXfer = (AbortXferPacket)Pack;
  8122. AbortXfer handlerAbortXfer = OnAbortXfer;
  8123. if (handlerAbortXfer != null)
  8124. {
  8125. handlerAbortXfer(this, abortXfer.XferID.ID);
  8126. }
  8127. return true;
  8128. }
  8129. private bool HandleCreateInventoryFolder(IClientAPI sender, Packet Pack)
  8130. {
  8131. CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack;
  8132. #region Packet Session and User Check
  8133. if (invFolder.AgentData.SessionID != SessionId ||
  8134. invFolder.AgentData.AgentID != AgentId)
  8135. return true;
  8136. #endregion
  8137. CreateInventoryFolder handlerCreateInventoryFolder = OnCreateNewInventoryFolder;
  8138. if (handlerCreateInventoryFolder != null)
  8139. {
  8140. handlerCreateInventoryFolder(this, invFolder.FolderData.FolderID,
  8141. (ushort)invFolder.FolderData.Type,
  8142. Util.FieldToString(invFolder.FolderData.Name),
  8143. invFolder.FolderData.ParentID);
  8144. }
  8145. return true;
  8146. }
  8147. private bool HandleUpdateInventoryFolder(IClientAPI sender, Packet Pack)
  8148. {
  8149. if (OnUpdateInventoryFolder != null)
  8150. {
  8151. UpdateInventoryFolderPacket invFolderx = (UpdateInventoryFolderPacket)Pack;
  8152. #region Packet Session and User Check
  8153. if (invFolderx.AgentData.SessionID != SessionId ||
  8154. invFolderx.AgentData.AgentID != AgentId)
  8155. return true;
  8156. #endregion
  8157. UpdateInventoryFolder handlerUpdateInventoryFolder = null;
  8158. for (int i = 0; i < invFolderx.FolderData.Length; i++)
  8159. {
  8160. handlerUpdateInventoryFolder = OnUpdateInventoryFolder;
  8161. if (handlerUpdateInventoryFolder != null)
  8162. {
  8163. OnUpdateInventoryFolder(this, invFolderx.FolderData[i].FolderID,
  8164. (ushort)invFolderx.FolderData[i].Type,
  8165. Util.FieldToString(invFolderx.FolderData[i].Name),
  8166. invFolderx.FolderData[i].ParentID);
  8167. }
  8168. }
  8169. }
  8170. return true;
  8171. }
  8172. private bool HandleMoveInventoryFolder(IClientAPI sender, Packet Pack)
  8173. {
  8174. if (OnMoveInventoryFolder != null)
  8175. {
  8176. MoveInventoryFolderPacket invFoldery = (MoveInventoryFolderPacket)Pack;
  8177. #region Packet Session and User Check
  8178. if (invFoldery.AgentData.SessionID != SessionId ||
  8179. invFoldery.AgentData.AgentID != AgentId)
  8180. return true;
  8181. #endregion
  8182. MoveInventoryFolder handlerMoveInventoryFolder = null;
  8183. for (int i = 0; i < invFoldery.InventoryData.Length; i++)
  8184. {
  8185. handlerMoveInventoryFolder = OnMoveInventoryFolder;
  8186. if (handlerMoveInventoryFolder != null)
  8187. {
  8188. OnMoveInventoryFolder(this, invFoldery.InventoryData[i].FolderID,
  8189. invFoldery.InventoryData[i].ParentID);
  8190. }
  8191. }
  8192. }
  8193. return true;
  8194. }
  8195. private bool HandleCreateInventoryItem(IClientAPI sender, Packet Pack)
  8196. {
  8197. CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack;
  8198. #region Packet Session and User Check
  8199. if (createItem.AgentData.SessionID != SessionId ||
  8200. createItem.AgentData.AgentID != AgentId)
  8201. return true;
  8202. #endregion
  8203. CreateNewInventoryItem handlerCreateNewInventoryItem = OnCreateNewInventoryItem;
  8204. if (handlerCreateNewInventoryItem != null)
  8205. {
  8206. handlerCreateNewInventoryItem(this, createItem.InventoryBlock.TransactionID,
  8207. createItem.InventoryBlock.FolderID,
  8208. createItem.InventoryBlock.CallbackID,
  8209. Util.FieldToString(createItem.InventoryBlock.Description),
  8210. Util.FieldToString(createItem.InventoryBlock.Name),
  8211. createItem.InventoryBlock.InvType,
  8212. createItem.InventoryBlock.Type,
  8213. createItem.InventoryBlock.WearableType,
  8214. createItem.InventoryBlock.NextOwnerMask,
  8215. Util.UnixTimeSinceEpoch());
  8216. }
  8217. return true;
  8218. }
  8219. private bool HandleLinkInventoryItem(IClientAPI sender, Packet Pack)
  8220. {
  8221. LinkInventoryItemPacket createLink = (LinkInventoryItemPacket)Pack;
  8222. #region Packet Session and User Check
  8223. if (createLink.AgentData.SessionID != SessionId ||
  8224. createLink.AgentData.AgentID != AgentId)
  8225. return true;
  8226. #endregion
  8227. LinkInventoryItem linkInventoryItem = OnLinkInventoryItem;
  8228. if (linkInventoryItem != null)
  8229. {
  8230. linkInventoryItem(
  8231. this,
  8232. createLink.InventoryBlock.TransactionID,
  8233. createLink.InventoryBlock.FolderID,
  8234. createLink.InventoryBlock.CallbackID,
  8235. Util.FieldToString(createLink.InventoryBlock.Description),
  8236. Util.FieldToString(createLink.InventoryBlock.Name),
  8237. createLink.InventoryBlock.InvType,
  8238. createLink.InventoryBlock.Type,
  8239. createLink.InventoryBlock.OldItemID);
  8240. }
  8241. return true;
  8242. }
  8243. private bool HandleFetchInventory(IClientAPI sender, Packet Pack)
  8244. {
  8245. if (OnFetchInventory != null)
  8246. {
  8247. FetchInventoryPacket FetchInventoryx = (FetchInventoryPacket)Pack;
  8248. #region Packet Session and User Check
  8249. if (FetchInventoryx.AgentData.SessionID != SessionId ||
  8250. FetchInventoryx.AgentData.AgentID != AgentId)
  8251. return true;
  8252. #endregion
  8253. FetchInventory handlerFetchInventory = null;
  8254. for (int i = 0; i < FetchInventoryx.InventoryData.Length; i++)
  8255. {
  8256. handlerFetchInventory = OnFetchInventory;
  8257. if (handlerFetchInventory != null)
  8258. {
  8259. OnFetchInventory(this, FetchInventoryx.InventoryData[i].ItemID,
  8260. FetchInventoryx.InventoryData[i].OwnerID);
  8261. }
  8262. }
  8263. }
  8264. return true;
  8265. }
  8266. private bool HandleFetchInventoryDescendents(IClientAPI sender, Packet Pack)
  8267. {
  8268. FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack;
  8269. #region Packet Session and User Check
  8270. if (Fetch.AgentData.SessionID != SessionId ||
  8271. Fetch.AgentData.AgentID != AgentId)
  8272. return true;
  8273. #endregion
  8274. FetchInventoryDescendents handlerFetchInventoryDescendents = OnFetchInventoryDescendents;
  8275. if (handlerFetchInventoryDescendents != null)
  8276. {
  8277. handlerFetchInventoryDescendents(this, Fetch.InventoryData.FolderID, Fetch.InventoryData.OwnerID,
  8278. Fetch.InventoryData.FetchFolders, Fetch.InventoryData.FetchItems,
  8279. Fetch.InventoryData.SortOrder);
  8280. }
  8281. return true;
  8282. }
  8283. private bool HandlePurgeInventoryDescendents(IClientAPI sender, Packet Pack)
  8284. {
  8285. PurgeInventoryDescendentsPacket Purge = (PurgeInventoryDescendentsPacket)Pack;
  8286. #region Packet Session and User Check
  8287. if (Purge.AgentData.SessionID != SessionId ||
  8288. Purge.AgentData.AgentID != AgentId)
  8289. return true;
  8290. #endregion
  8291. PurgeInventoryDescendents handlerPurgeInventoryDescendents = OnPurgeInventoryDescendents;
  8292. if (handlerPurgeInventoryDescendents != null)
  8293. {
  8294. handlerPurgeInventoryDescendents(this, Purge.InventoryData.FolderID);
  8295. }
  8296. return true;
  8297. }
  8298. private bool HandleUpdateInventoryItem(IClientAPI sender, Packet Pack)
  8299. {
  8300. UpdateInventoryItemPacket inventoryItemUpdate = (UpdateInventoryItemPacket)Pack;
  8301. #region Packet Session and User Check
  8302. if (inventoryItemUpdate.AgentData.SessionID != SessionId ||
  8303. inventoryItemUpdate.AgentData.AgentID != AgentId)
  8304. return true;
  8305. #endregion
  8306. if (OnUpdateInventoryItem != null)
  8307. {
  8308. UpdateInventoryItem handlerUpdateInventoryItem = null;
  8309. for (int i = 0; i < inventoryItemUpdate.InventoryData.Length; i++)
  8310. {
  8311. handlerUpdateInventoryItem = OnUpdateInventoryItem;
  8312. if (handlerUpdateInventoryItem != null)
  8313. {
  8314. InventoryItemBase itemUpd = new InventoryItemBase();
  8315. itemUpd.ID = inventoryItemUpdate.InventoryData[i].ItemID;
  8316. itemUpd.Name = Util.FieldToString(inventoryItemUpdate.InventoryData[i].Name);
  8317. itemUpd.Description = Util.FieldToString(inventoryItemUpdate.InventoryData[i].Description);
  8318. itemUpd.GroupID = inventoryItemUpdate.InventoryData[i].GroupID;
  8319. itemUpd.GroupOwned = inventoryItemUpdate.InventoryData[i].GroupOwned;
  8320. itemUpd.GroupPermissions = inventoryItemUpdate.InventoryData[i].GroupMask;
  8321. itemUpd.NextPermissions = inventoryItemUpdate.InventoryData[i].NextOwnerMask;
  8322. itemUpd.EveryOnePermissions = inventoryItemUpdate.InventoryData[i].EveryoneMask;
  8323. itemUpd.CreationDate = inventoryItemUpdate.InventoryData[i].CreationDate;
  8324. itemUpd.Folder = inventoryItemUpdate.InventoryData[i].FolderID;
  8325. itemUpd.InvType = inventoryItemUpdate.InventoryData[i].InvType;
  8326. itemUpd.SalePrice = inventoryItemUpdate.InventoryData[i].SalePrice;
  8327. itemUpd.SaleType = inventoryItemUpdate.InventoryData[i].SaleType;
  8328. itemUpd.Flags = inventoryItemUpdate.InventoryData[i].Flags;
  8329. OnUpdateInventoryItem(this, inventoryItemUpdate.InventoryData[i].TransactionID,
  8330. inventoryItemUpdate.InventoryData[i].ItemID,
  8331. itemUpd);
  8332. }
  8333. }
  8334. }
  8335. return true;
  8336. }
  8337. private bool HandleCopyInventoryItem(IClientAPI sender, Packet Pack)
  8338. {
  8339. CopyInventoryItemPacket copyitem = (CopyInventoryItemPacket)Pack;
  8340. #region Packet Session and User Check
  8341. if (copyitem.AgentData.SessionID != SessionId ||
  8342. copyitem.AgentData.AgentID != AgentId)
  8343. return true;
  8344. #endregion
  8345. CopyInventoryItem handlerCopyInventoryItem = null;
  8346. if (OnCopyInventoryItem != null)
  8347. {
  8348. foreach (CopyInventoryItemPacket.InventoryDataBlock datablock in copyitem.InventoryData)
  8349. {
  8350. handlerCopyInventoryItem = OnCopyInventoryItem;
  8351. if (handlerCopyInventoryItem != null)
  8352. {
  8353. handlerCopyInventoryItem(this, datablock.CallbackID, datablock.OldAgentID,
  8354. datablock.OldItemID, datablock.NewFolderID,
  8355. Util.FieldToString(datablock.NewName));
  8356. }
  8357. }
  8358. }
  8359. return true;
  8360. }
  8361. private bool HandleMoveInventoryItem(IClientAPI sender, Packet Pack)
  8362. {
  8363. MoveInventoryItemPacket moveitem = (MoveInventoryItemPacket)Pack;
  8364. #region Packet Session and User Check
  8365. if (moveitem.AgentData.SessionID != SessionId ||
  8366. moveitem.AgentData.AgentID != AgentId)
  8367. return true;
  8368. #endregion
  8369. if (OnMoveInventoryItem != null)
  8370. {
  8371. MoveInventoryItem handlerMoveInventoryItem = null;
  8372. InventoryItemBase itm = null;
  8373. List<InventoryItemBase> items = new List<InventoryItemBase>();
  8374. foreach (MoveInventoryItemPacket.InventoryDataBlock datablock in moveitem.InventoryData)
  8375. {
  8376. itm = new InventoryItemBase(datablock.ItemID, AgentId);
  8377. itm.Folder = datablock.FolderID;
  8378. itm.Name = Util.FieldToString(datablock.NewName);
  8379. // weird, comes out as empty string
  8380. //m_log.DebugFormat("[XXX] new name: {0}", itm.Name);
  8381. items.Add(itm);
  8382. }
  8383. handlerMoveInventoryItem = OnMoveInventoryItem;
  8384. if (handlerMoveInventoryItem != null)
  8385. {
  8386. handlerMoveInventoryItem(this, items);
  8387. }
  8388. }
  8389. return true;
  8390. }
  8391. private bool HandleRemoveInventoryItem(IClientAPI sender, Packet Pack)
  8392. {
  8393. RemoveInventoryItemPacket removeItem = (RemoveInventoryItemPacket)Pack;
  8394. #region Packet Session and User Check
  8395. if (removeItem.AgentData.SessionID != SessionId ||
  8396. removeItem.AgentData.AgentID != AgentId)
  8397. return true;
  8398. #endregion
  8399. if (OnRemoveInventoryItem != null)
  8400. {
  8401. RemoveInventoryItem handlerRemoveInventoryItem = null;
  8402. List<UUID> uuids = new List<UUID>();
  8403. foreach (RemoveInventoryItemPacket.InventoryDataBlock datablock in removeItem.InventoryData)
  8404. {
  8405. uuids.Add(datablock.ItemID);
  8406. }
  8407. handlerRemoveInventoryItem = OnRemoveInventoryItem;
  8408. if (handlerRemoveInventoryItem != null)
  8409. {
  8410. handlerRemoveInventoryItem(this, uuids);
  8411. }
  8412. }
  8413. return true;
  8414. }
  8415. private bool HandleRemoveInventoryFolder(IClientAPI sender, Packet Pack)
  8416. {
  8417. RemoveInventoryFolderPacket removeFolder = (RemoveInventoryFolderPacket)Pack;
  8418. #region Packet Session and User Check
  8419. if (removeFolder.AgentData.SessionID != SessionId ||
  8420. removeFolder.AgentData.AgentID != AgentId)
  8421. return true;
  8422. #endregion
  8423. if (OnRemoveInventoryFolder != null)
  8424. {
  8425. RemoveInventoryFolder handlerRemoveInventoryFolder = null;
  8426. List<UUID> uuids = new List<UUID>();
  8427. foreach (RemoveInventoryFolderPacket.FolderDataBlock datablock in removeFolder.FolderData)
  8428. {
  8429. uuids.Add(datablock.FolderID);
  8430. }
  8431. handlerRemoveInventoryFolder = OnRemoveInventoryFolder;
  8432. if (handlerRemoveInventoryFolder != null)
  8433. {
  8434. handlerRemoveInventoryFolder(this, uuids);
  8435. }
  8436. }
  8437. return true;
  8438. }
  8439. private bool HandleRemoveInventoryObjects(IClientAPI sender, Packet Pack)
  8440. {
  8441. RemoveInventoryObjectsPacket removeObject = (RemoveInventoryObjectsPacket)Pack;
  8442. #region Packet Session and User Check
  8443. if (removeObject.AgentData.SessionID != SessionId ||
  8444. removeObject.AgentData.AgentID != AgentId)
  8445. return true;
  8446. #endregion
  8447. if (OnRemoveInventoryFolder != null)
  8448. {
  8449. RemoveInventoryFolder handlerRemoveInventoryFolder = null;
  8450. List<UUID> uuids = new List<UUID>();
  8451. foreach (RemoveInventoryObjectsPacket.FolderDataBlock datablock in removeObject.FolderData)
  8452. {
  8453. uuids.Add(datablock.FolderID);
  8454. }
  8455. handlerRemoveInventoryFolder = OnRemoveInventoryFolder;
  8456. if (handlerRemoveInventoryFolder != null)
  8457. {
  8458. handlerRemoveInventoryFolder(this, uuids);
  8459. }
  8460. }
  8461. if (OnRemoveInventoryItem != null)
  8462. {
  8463. RemoveInventoryItem handlerRemoveInventoryItem = null;
  8464. List<UUID> uuids = new List<UUID>();
  8465. foreach (RemoveInventoryObjectsPacket.ItemDataBlock datablock in removeObject.ItemData)
  8466. {
  8467. uuids.Add(datablock.ItemID);
  8468. }
  8469. handlerRemoveInventoryItem = OnRemoveInventoryItem;
  8470. if (handlerRemoveInventoryItem != null)
  8471. {
  8472. handlerRemoveInventoryItem(this, uuids);
  8473. }
  8474. }
  8475. return true;
  8476. }
  8477. private bool HandleRequestTaskInventory(IClientAPI sender, Packet Pack)
  8478. {
  8479. RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
  8480. #region Packet Session and User Check
  8481. if (requesttask.AgentData.SessionID != SessionId ||
  8482. requesttask.AgentData.AgentID != AgentId)
  8483. return true;
  8484. #endregion
  8485. RequestTaskInventory handlerRequestTaskInventory = OnRequestTaskInventory;
  8486. if (handlerRequestTaskInventory != null)
  8487. {
  8488. handlerRequestTaskInventory(this, requesttask.InventoryData.LocalID);
  8489. }
  8490. return true;
  8491. }
  8492. private bool HandleUpdateTaskInventory(IClientAPI sender, Packet Pack)
  8493. {
  8494. UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
  8495. #region Packet Session and User Check
  8496. if (updatetask.AgentData.SessionID != SessionId ||
  8497. updatetask.AgentData.AgentID != AgentId)
  8498. return true;
  8499. #endregion
  8500. if (OnUpdateTaskInventory != null)
  8501. {
  8502. if (updatetask.UpdateData.Key == 0)
  8503. {
  8504. UpdateTaskInventory handlerUpdateTaskInventory = OnUpdateTaskInventory;
  8505. if (handlerUpdateTaskInventory != null)
  8506. {
  8507. TaskInventoryItem newTaskItem = new TaskInventoryItem();
  8508. newTaskItem.ItemID = updatetask.InventoryData.ItemID;
  8509. newTaskItem.ParentID = updatetask.InventoryData.FolderID;
  8510. newTaskItem.CreatorID = updatetask.InventoryData.CreatorID;
  8511. newTaskItem.OwnerID = updatetask.InventoryData.OwnerID;
  8512. newTaskItem.GroupID = updatetask.InventoryData.GroupID;
  8513. newTaskItem.BasePermissions = updatetask.InventoryData.BaseMask;
  8514. newTaskItem.CurrentPermissions = updatetask.InventoryData.OwnerMask;
  8515. newTaskItem.GroupPermissions = updatetask.InventoryData.GroupMask;
  8516. newTaskItem.EveryonePermissions = updatetask.InventoryData.EveryoneMask;
  8517. newTaskItem.NextPermissions = updatetask.InventoryData.NextOwnerMask;
  8518. // Unused? Clicking share with group sets GroupPermissions instead, so perhaps this is something
  8519. // different
  8520. //newTaskItem.GroupOwned=updatetask.InventoryData.GroupOwned;
  8521. newTaskItem.Type = updatetask.InventoryData.Type;
  8522. newTaskItem.InvType = updatetask.InventoryData.InvType;
  8523. newTaskItem.Flags = updatetask.InventoryData.Flags;
  8524. //newTaskItem.SaleType=updatetask.InventoryData.SaleType;
  8525. //newTaskItem.SalePrice=updatetask.InventoryData.SalePrice;
  8526. newTaskItem.Name = Util.FieldToString(updatetask.InventoryData.Name);
  8527. newTaskItem.Description = Util.FieldToString(updatetask.InventoryData.Description);
  8528. newTaskItem.CreationDate = (uint)updatetask.InventoryData.CreationDate;
  8529. handlerUpdateTaskInventory(this, updatetask.InventoryData.TransactionID,
  8530. newTaskItem, updatetask.UpdateData.LocalID);
  8531. }
  8532. }
  8533. }
  8534. return true;
  8535. }
  8536. private bool HandleRemoveTaskInventory(IClientAPI sender, Packet Pack)
  8537. {
  8538. RemoveTaskInventoryPacket removeTask = (RemoveTaskInventoryPacket)Pack;
  8539. #region Packet Session and User Check
  8540. if (removeTask.AgentData.SessionID != SessionId ||
  8541. removeTask.AgentData.AgentID != AgentId)
  8542. return true;
  8543. #endregion
  8544. RemoveTaskInventory handlerRemoveTaskItem = OnRemoveTaskItem;
  8545. if (handlerRemoveTaskItem != null)
  8546. {
  8547. handlerRemoveTaskItem(this, removeTask.InventoryData.ItemID, removeTask.InventoryData.LocalID);
  8548. }
  8549. return true;
  8550. }
  8551. private bool HandleMoveTaskInventory(IClientAPI sender, Packet Pack)
  8552. {
  8553. MoveTaskInventoryPacket moveTaskInventoryPacket = (MoveTaskInventoryPacket)Pack;
  8554. #region Packet Session and User Check
  8555. if (moveTaskInventoryPacket.AgentData.SessionID != SessionId ||
  8556. moveTaskInventoryPacket.AgentData.AgentID != AgentId)
  8557. return true;
  8558. #endregion
  8559. MoveTaskInventory handlerMoveTaskItem = OnMoveTaskItem;
  8560. if (handlerMoveTaskItem != null)
  8561. {
  8562. handlerMoveTaskItem(
  8563. this, moveTaskInventoryPacket.AgentData.FolderID,
  8564. moveTaskInventoryPacket.InventoryData.LocalID,
  8565. moveTaskInventoryPacket.InventoryData.ItemID);
  8566. }
  8567. return true;
  8568. }
  8569. private bool HandleRezScript(IClientAPI sender, Packet Pack)
  8570. {
  8571. //m_log.Debug(Pack.ToString());
  8572. RezScriptPacket rezScriptx = (RezScriptPacket)Pack;
  8573. #region Packet Session and User Check
  8574. if (rezScriptx.AgentData.SessionID != SessionId ||
  8575. rezScriptx.AgentData.AgentID != AgentId)
  8576. return true;
  8577. #endregion
  8578. RezScript handlerRezScript = OnRezScript;
  8579. InventoryItemBase item = new InventoryItemBase();
  8580. item.ID = rezScriptx.InventoryBlock.ItemID;
  8581. item.Folder = rezScriptx.InventoryBlock.FolderID;
  8582. item.CreatorId = rezScriptx.InventoryBlock.CreatorID.ToString();
  8583. item.Owner = rezScriptx.InventoryBlock.OwnerID;
  8584. item.BasePermissions = rezScriptx.InventoryBlock.BaseMask;
  8585. item.CurrentPermissions = rezScriptx.InventoryBlock.OwnerMask;
  8586. item.EveryOnePermissions = rezScriptx.InventoryBlock.EveryoneMask;
  8587. item.NextPermissions = rezScriptx.InventoryBlock.NextOwnerMask;
  8588. item.GroupPermissions = rezScriptx.InventoryBlock.GroupMask;
  8589. item.GroupOwned = rezScriptx.InventoryBlock.GroupOwned;
  8590. item.GroupID = rezScriptx.InventoryBlock.GroupID;
  8591. item.AssetType = rezScriptx.InventoryBlock.Type;
  8592. item.InvType = rezScriptx.InventoryBlock.InvType;
  8593. item.Flags = rezScriptx.InventoryBlock.Flags;
  8594. item.SaleType = rezScriptx.InventoryBlock.SaleType;
  8595. item.SalePrice = rezScriptx.InventoryBlock.SalePrice;
  8596. item.Name = Util.FieldToString(rezScriptx.InventoryBlock.Name);
  8597. item.Description = Util.FieldToString(rezScriptx.InventoryBlock.Description);
  8598. item.CreationDate = rezScriptx.InventoryBlock.CreationDate;
  8599. if (handlerRezScript != null)
  8600. {
  8601. handlerRezScript(this, item, rezScriptx.InventoryBlock.TransactionID, rezScriptx.UpdateBlock.ObjectLocalID);
  8602. }
  8603. return true;
  8604. }
  8605. private bool HandleMapLayerRequest(IClientAPI sender, Packet Pack)
  8606. {
  8607. RequestMapLayer();
  8608. return true;
  8609. }
  8610. private bool HandleMapBlockRequest(IClientAPI sender, Packet Pack)
  8611. {
  8612. MapBlockRequestPacket MapRequest = (MapBlockRequestPacket)Pack;
  8613. #region Packet Session and User Check
  8614. if (MapRequest.AgentData.SessionID != SessionId ||
  8615. MapRequest.AgentData.AgentID != AgentId)
  8616. return true;
  8617. #endregion
  8618. RequestMapBlocks handlerRequestMapBlocks = OnRequestMapBlocks;
  8619. if (handlerRequestMapBlocks != null)
  8620. {
  8621. handlerRequestMapBlocks(this, MapRequest.PositionData.MinX, MapRequest.PositionData.MinY,
  8622. MapRequest.PositionData.MaxX, MapRequest.PositionData.MaxY, MapRequest.AgentData.Flags);
  8623. }
  8624. return true;
  8625. }
  8626. private bool HandleMapNameRequest(IClientAPI sender, Packet Pack)
  8627. {
  8628. MapNameRequestPacket map = (MapNameRequestPacket)Pack;
  8629. #region Packet Session and User Check
  8630. if (map.AgentData.SessionID != SessionId ||
  8631. map.AgentData.AgentID != AgentId)
  8632. return true;
  8633. #endregion
  8634. string mapName = (map.NameData.Name.Length == 0) ? m_scene.RegionInfo.RegionName :
  8635. Util.UTF8.GetString(map.NameData.Name, 0, map.NameData.Name.Length - 1);
  8636. RequestMapName handlerMapNameRequest = OnMapNameRequest;
  8637. if (handlerMapNameRequest != null)
  8638. {
  8639. handlerMapNameRequest(this, mapName, map.AgentData.Flags);
  8640. }
  8641. return true;
  8642. }
  8643. private bool HandleTeleportLandmarkRequest(IClientAPI sender, Packet Pack)
  8644. {
  8645. TeleportLandmarkRequestPacket tpReq = (TeleportLandmarkRequestPacket)Pack;
  8646. #region Packet Session and User Check
  8647. if (tpReq.Info.SessionID != SessionId ||
  8648. tpReq.Info.AgentID != AgentId)
  8649. return true;
  8650. #endregion
  8651. UUID lmid = tpReq.Info.LandmarkID;
  8652. AssetLandmark lm;
  8653. if (lmid != UUID.Zero)
  8654. {
  8655. //AssetBase lma = m_assetCache.GetAsset(lmid, false);
  8656. AssetBase lma = m_assetService.Get(lmid.ToString());
  8657. if (lma == null)
  8658. {
  8659. // Failed to find landmark
  8660. // Let's try to search in the user's home asset server
  8661. lma = FindAssetInUserAssetServer(lmid.ToString());
  8662. if (lma == null)
  8663. {
  8664. // Really doesn't exist
  8665. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  8666. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  8667. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  8668. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  8669. }
  8670. }
  8671. try
  8672. {
  8673. lm = new AssetLandmark(lma);
  8674. }
  8675. catch (NullReferenceException)
  8676. {
  8677. // asset not found generates null ref inside the assetlandmark constructor.
  8678. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  8679. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  8680. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  8681. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  8682. return true;
  8683. }
  8684. }
  8685. else
  8686. {
  8687. // Teleport home request
  8688. UUIDNameRequest handlerTeleportHomeRequest = OnTeleportHomeRequest;
  8689. if (handlerTeleportHomeRequest != null)
  8690. {
  8691. handlerTeleportHomeRequest(AgentId, this);
  8692. }
  8693. return true;
  8694. }
  8695. TeleportLandmarkRequest handlerTeleportLandmarkRequest = OnTeleportLandmarkRequest;
  8696. if (handlerTeleportLandmarkRequest != null)
  8697. {
  8698. handlerTeleportLandmarkRequest(this, lm);
  8699. }
  8700. else
  8701. {
  8702. //no event handler so cancel request
  8703. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  8704. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  8705. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  8706. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  8707. }
  8708. return true;
  8709. }
  8710. private bool HandleTeleportCancel(IClientAPI sender, Packet Pack)
  8711. {
  8712. TeleportCancel handlerTeleportCancel = OnTeleportCancel;
  8713. if (handlerTeleportCancel != null)
  8714. {
  8715. handlerTeleportCancel(this);
  8716. }
  8717. return true;
  8718. }
  8719. private AssetBase FindAssetInUserAssetServer(string id)
  8720. {
  8721. AgentCircuitData aCircuit = ((Scene)Scene).AuthenticateHandler.GetAgentCircuitData(CircuitCode);
  8722. if (aCircuit != null && aCircuit.ServiceURLs != null && aCircuit.ServiceURLs.ContainsKey("AssetServerURI"))
  8723. {
  8724. string assetServer = aCircuit.ServiceURLs["AssetServerURI"].ToString();
  8725. if (!string.IsNullOrEmpty(assetServer))
  8726. return ((Scene)Scene).AssetService.Get(assetServer + "/" + id);
  8727. }
  8728. return null;
  8729. }
  8730. private bool HandleTeleportLocationRequest(IClientAPI sender, Packet Pack)
  8731. {
  8732. TeleportLocationRequestPacket tpLocReq = (TeleportLocationRequestPacket)Pack;
  8733. // m_log.Debug(tpLocReq.ToString());
  8734. #region Packet Session and User Check
  8735. if (tpLocReq.AgentData.SessionID != SessionId ||
  8736. tpLocReq.AgentData.AgentID != AgentId)
  8737. return true;
  8738. #endregion
  8739. TeleportLocationRequest handlerTeleportLocationRequest = OnTeleportLocationRequest;
  8740. if (handlerTeleportLocationRequest != null)
  8741. {
  8742. // Adjust teleport location to base of a larger region if requested to teleport to a sub-region
  8743. uint locX, locY;
  8744. Util.RegionHandleToWorldLoc(tpLocReq.Info.RegionHandle, out locX, out locY);
  8745. if ((locX >= m_scene.RegionInfo.WorldLocX)
  8746. && (locX < (m_scene.RegionInfo.WorldLocX + m_scene.RegionInfo.RegionSizeX))
  8747. && (locY >= m_scene.RegionInfo.WorldLocY)
  8748. && (locY < (m_scene.RegionInfo.WorldLocY + m_scene.RegionInfo.RegionSizeY)))
  8749. {
  8750. tpLocReq.Info.RegionHandle = m_scene.RegionInfo.RegionHandle;
  8751. tpLocReq.Info.Position.X += locX - m_scene.RegionInfo.WorldLocX;
  8752. tpLocReq.Info.Position.Y += locY - m_scene.RegionInfo.WorldLocY;
  8753. }
  8754. handlerTeleportLocationRequest(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position,
  8755. tpLocReq.Info.LookAt, 16);
  8756. }
  8757. else
  8758. {
  8759. //no event handler so cancel request
  8760. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  8761. tpCancel.Info.SessionID = tpLocReq.AgentData.SessionID;
  8762. tpCancel.Info.AgentID = tpLocReq.AgentData.AgentID;
  8763. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  8764. }
  8765. return true;
  8766. }
  8767. #endregion Inventory/Asset/Other related packets
  8768. private bool HandleUUIDNameRequest(IClientAPI sender, Packet Pack)
  8769. {
  8770. ScenePresence sp = (ScenePresence)SceneAgent;
  8771. if(sp == null || sp.IsDeleted || (sp.IsInTransit && !sp.IsInLocalTransit))
  8772. return true;
  8773. UUIDNameRequestPacket incoming = (UUIDNameRequestPacket)Pack;
  8774. foreach (UUIDNameRequestPacket.UUIDNameBlockBlock UUIDBlock in incoming.UUIDNameBlock)
  8775. {
  8776. UUIDNameRequest handlerNameRequest = OnNameFromUUIDRequest;
  8777. if (handlerNameRequest != null)
  8778. {
  8779. handlerNameRequest(UUIDBlock.ID, this);
  8780. }
  8781. }
  8782. return true;
  8783. }
  8784. #region Parcel related packets
  8785. private bool HandleRegionHandleRequest(IClientAPI sender, Packet Pack)
  8786. {
  8787. RegionHandleRequest handlerRegionHandleRequest = OnRegionHandleRequest;
  8788. if (handlerRegionHandleRequest != null)
  8789. {
  8790. RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack;
  8791. handlerRegionHandleRequest(this, rhrPack.RequestBlock.RegionID);
  8792. }
  8793. return true;
  8794. }
  8795. private bool HandleParcelInfoRequest(IClientAPI sender, Packet Pack)
  8796. {
  8797. ParcelInfoRequestPacket pirPack = (ParcelInfoRequestPacket)Pack;
  8798. #region Packet Session and User Check
  8799. if (pirPack.AgentData.SessionID != SessionId ||
  8800. pirPack.AgentData.AgentID != AgentId)
  8801. return true;
  8802. #endregion
  8803. ParcelInfoRequest handlerParcelInfoRequest = OnParcelInfoRequest;
  8804. if (handlerParcelInfoRequest != null)
  8805. {
  8806. handlerParcelInfoRequest(this, pirPack.Data.ParcelID);
  8807. }
  8808. return true;
  8809. }
  8810. private bool HandleParcelAccessListRequest(IClientAPI sender, Packet Pack)
  8811. {
  8812. ParcelAccessListRequestPacket requestPacket = (ParcelAccessListRequestPacket)Pack;
  8813. #region Packet Session and User Check
  8814. if (requestPacket.AgentData.SessionID != SessionId ||
  8815. requestPacket.AgentData.AgentID != AgentId)
  8816. return true;
  8817. #endregion
  8818. ParcelAccessListRequest handlerParcelAccessListRequest = OnParcelAccessListRequest;
  8819. if (handlerParcelAccessListRequest != null)
  8820. {
  8821. handlerParcelAccessListRequest(requestPacket.AgentData.AgentID, requestPacket.AgentData.SessionID,
  8822. requestPacket.Data.Flags, requestPacket.Data.SequenceID,
  8823. requestPacket.Data.LocalID, this);
  8824. }
  8825. return true;
  8826. }
  8827. private bool HandleParcelAccessListUpdate(IClientAPI sender, Packet Pack)
  8828. {
  8829. if(OnParcelAccessListUpdateRequest == null)
  8830. return true;
  8831. ParcelAccessListUpdatePacket updatePacket = (ParcelAccessListUpdatePacket)Pack;
  8832. #region Packet Session and User Check
  8833. if (updatePacket.AgentData.SessionID != SessionId ||
  8834. updatePacket.AgentData.AgentID != AgentId)
  8835. return true;
  8836. #endregion
  8837. // viewers do send estimated number of packets and sequenceID, but don't seem reliable.
  8838. List<LandAccessEntry> entries = new List<LandAccessEntry>();
  8839. foreach (ParcelAccessListUpdatePacket.ListBlock block in updatePacket.List)
  8840. {
  8841. LandAccessEntry entry = new LandAccessEntry();
  8842. entry.AgentID = block.ID;
  8843. entry.Flags = (AccessList)block.Flags;
  8844. entry.Expires = block.Time;
  8845. entries.Add(entry);
  8846. }
  8847. ParcelAccessListUpdateRequest handlerParcelAccessListUpdateRequest = OnParcelAccessListUpdateRequest;
  8848. if (handlerParcelAccessListUpdateRequest != null)
  8849. {
  8850. handlerParcelAccessListUpdateRequest(updatePacket.AgentData.AgentID,
  8851. updatePacket.Data.Flags,
  8852. updatePacket.Data.TransactionID,
  8853. updatePacket.Data.LocalID,
  8854. entries, this);
  8855. }
  8856. return true;
  8857. }
  8858. private bool HandleParcelPropertiesRequest(IClientAPI sender, Packet Pack)
  8859. {
  8860. ParcelPropertiesRequestPacket propertiesRequest = (ParcelPropertiesRequestPacket)Pack;
  8861. #region Packet Session and User Check
  8862. if (propertiesRequest.AgentData.SessionID != SessionId ||
  8863. propertiesRequest.AgentData.AgentID != AgentId)
  8864. return true;
  8865. #endregion
  8866. ParcelPropertiesRequest handlerParcelPropertiesRequest = OnParcelPropertiesRequest;
  8867. if (handlerParcelPropertiesRequest != null)
  8868. {
  8869. handlerParcelPropertiesRequest((int)Math.Round(propertiesRequest.ParcelData.West),
  8870. (int)Math.Round(propertiesRequest.ParcelData.South),
  8871. (int)Math.Round(propertiesRequest.ParcelData.East),
  8872. (int)Math.Round(propertiesRequest.ParcelData.North),
  8873. propertiesRequest.ParcelData.SequenceID,
  8874. propertiesRequest.ParcelData.SnapSelection, this);
  8875. }
  8876. return true;
  8877. }
  8878. private bool HandleParcelDivide(IClientAPI sender, Packet Pack)
  8879. {
  8880. ParcelDividePacket landDivide = (ParcelDividePacket)Pack;
  8881. #region Packet Session and User Check
  8882. if (landDivide.AgentData.SessionID != SessionId ||
  8883. landDivide.AgentData.AgentID != AgentId)
  8884. return true;
  8885. #endregion
  8886. ParcelDivideRequest handlerParcelDivideRequest = OnParcelDivideRequest;
  8887. if (handlerParcelDivideRequest != null)
  8888. {
  8889. handlerParcelDivideRequest((int)Math.Round(landDivide.ParcelData.West),
  8890. (int)Math.Round(landDivide.ParcelData.South),
  8891. (int)Math.Round(landDivide.ParcelData.East),
  8892. (int)Math.Round(landDivide.ParcelData.North), this);
  8893. }
  8894. return true;
  8895. }
  8896. private bool HandleParcelJoin(IClientAPI sender, Packet Pack)
  8897. {
  8898. ParcelJoinPacket landJoin = (ParcelJoinPacket)Pack;
  8899. #region Packet Session and User Check
  8900. if (landJoin.AgentData.SessionID != SessionId ||
  8901. landJoin.AgentData.AgentID != AgentId)
  8902. return true;
  8903. #endregion
  8904. ParcelJoinRequest handlerParcelJoinRequest = OnParcelJoinRequest;
  8905. if (handlerParcelJoinRequest != null)
  8906. {
  8907. handlerParcelJoinRequest((int)Math.Round(landJoin.ParcelData.West),
  8908. (int)Math.Round(landJoin.ParcelData.South),
  8909. (int)Math.Round(landJoin.ParcelData.East),
  8910. (int)Math.Round(landJoin.ParcelData.North), this);
  8911. }
  8912. return true;
  8913. }
  8914. private bool HandleParcelPropertiesUpdate(IClientAPI sender, Packet Pack)
  8915. {
  8916. ParcelPropertiesUpdatePacket parcelPropertiesPacket = (ParcelPropertiesUpdatePacket)Pack;
  8917. #region Packet Session and User Check
  8918. if (parcelPropertiesPacket.AgentData.SessionID != SessionId ||
  8919. parcelPropertiesPacket.AgentData.AgentID != AgentId)
  8920. return true;
  8921. #endregion
  8922. ParcelPropertiesUpdateRequest handlerParcelPropertiesUpdateRequest = OnParcelPropertiesUpdateRequest;
  8923. if (handlerParcelPropertiesUpdateRequest != null)
  8924. {
  8925. LandUpdateArgs args = new LandUpdateArgs();
  8926. args.AuthBuyerID = parcelPropertiesPacket.ParcelData.AuthBuyerID;
  8927. args.Category = (ParcelCategory)parcelPropertiesPacket.ParcelData.Category;
  8928. args.Desc = Utils.BytesToString(parcelPropertiesPacket.ParcelData.Desc);
  8929. args.GroupID = parcelPropertiesPacket.ParcelData.GroupID;
  8930. args.LandingType = parcelPropertiesPacket.ParcelData.LandingType;
  8931. args.MediaAutoScale = parcelPropertiesPacket.ParcelData.MediaAutoScale;
  8932. args.MediaID = parcelPropertiesPacket.ParcelData.MediaID;
  8933. args.MediaURL = Utils.BytesToString(parcelPropertiesPacket.ParcelData.MediaURL);
  8934. args.MusicURL = Utils.BytesToString(parcelPropertiesPacket.ParcelData.MusicURL);
  8935. args.Name = Utils.BytesToString(parcelPropertiesPacket.ParcelData.Name);
  8936. args.ParcelFlags = parcelPropertiesPacket.ParcelData.ParcelFlags;
  8937. args.PassHours = parcelPropertiesPacket.ParcelData.PassHours;
  8938. args.PassPrice = parcelPropertiesPacket.ParcelData.PassPrice;
  8939. args.SalePrice = parcelPropertiesPacket.ParcelData.SalePrice;
  8940. args.SnapshotID = parcelPropertiesPacket.ParcelData.SnapshotID;
  8941. args.UserLocation = parcelPropertiesPacket.ParcelData.UserLocation;
  8942. args.UserLookAt = parcelPropertiesPacket.ParcelData.UserLookAt;
  8943. handlerParcelPropertiesUpdateRequest(args, parcelPropertiesPacket.ParcelData.LocalID, this);
  8944. }
  8945. return true;
  8946. }
  8947. private bool HandleParcelSelectObjects(IClientAPI sender, Packet Pack)
  8948. {
  8949. ParcelSelectObjectsPacket selectPacket = (ParcelSelectObjectsPacket)Pack;
  8950. #region Packet Session and User Check
  8951. if (selectPacket.AgentData.SessionID != SessionId ||
  8952. selectPacket.AgentData.AgentID != AgentId)
  8953. return true;
  8954. #endregion
  8955. List<UUID> returnIDs = new List<UUID>();
  8956. foreach (ParcelSelectObjectsPacket.ReturnIDsBlock rb in
  8957. selectPacket.ReturnIDs)
  8958. {
  8959. returnIDs.Add(rb.ReturnID);
  8960. }
  8961. ParcelSelectObjects handlerParcelSelectObjects = OnParcelSelectObjects;
  8962. if (handlerParcelSelectObjects != null)
  8963. {
  8964. handlerParcelSelectObjects(selectPacket.ParcelData.LocalID,
  8965. Convert.ToInt32(selectPacket.ParcelData.ReturnType), returnIDs, this);
  8966. }
  8967. return true;
  8968. }
  8969. private bool HandleParcelObjectOwnersRequest(IClientAPI sender, Packet Pack)
  8970. {
  8971. ParcelObjectOwnersRequestPacket reqPacket = (ParcelObjectOwnersRequestPacket)Pack;
  8972. #region Packet Session and User Check
  8973. if (reqPacket.AgentData.SessionID != SessionId ||
  8974. reqPacket.AgentData.AgentID != AgentId)
  8975. return true;
  8976. #endregion
  8977. ParcelObjectOwnerRequest handlerParcelObjectOwnerRequest = OnParcelObjectOwnerRequest;
  8978. if (handlerParcelObjectOwnerRequest != null)
  8979. {
  8980. handlerParcelObjectOwnerRequest(reqPacket.ParcelData.LocalID, this);
  8981. }
  8982. return true;
  8983. }
  8984. private bool HandleParcelGodForceOwner(IClientAPI sender, Packet Pack)
  8985. {
  8986. ParcelGodForceOwnerPacket godForceOwnerPacket = (ParcelGodForceOwnerPacket)Pack;
  8987. #region Packet Session and User Check
  8988. if (godForceOwnerPacket.AgentData.SessionID != SessionId ||
  8989. godForceOwnerPacket.AgentData.AgentID != AgentId)
  8990. return true;
  8991. #endregion
  8992. ParcelGodForceOwner handlerParcelGodForceOwner = OnParcelGodForceOwner;
  8993. if (handlerParcelGodForceOwner != null)
  8994. {
  8995. handlerParcelGodForceOwner(godForceOwnerPacket.Data.LocalID, godForceOwnerPacket.Data.OwnerID, this);
  8996. }
  8997. return true;
  8998. }
  8999. private bool HandleParcelRelease(IClientAPI sender, Packet Pack)
  9000. {
  9001. ParcelReleasePacket releasePacket = (ParcelReleasePacket)Pack;
  9002. #region Packet Session and User Check
  9003. if (releasePacket.AgentData.SessionID != SessionId ||
  9004. releasePacket.AgentData.AgentID != AgentId)
  9005. return true;
  9006. #endregion
  9007. ParcelAbandonRequest handlerParcelAbandonRequest = OnParcelAbandonRequest;
  9008. if (handlerParcelAbandonRequest != null)
  9009. {
  9010. handlerParcelAbandonRequest(releasePacket.Data.LocalID, this);
  9011. }
  9012. return true;
  9013. }
  9014. private bool HandleParcelReclaim(IClientAPI sender, Packet Pack)
  9015. {
  9016. ParcelReclaimPacket reclaimPacket = (ParcelReclaimPacket)Pack;
  9017. #region Packet Session and User Check
  9018. if (reclaimPacket.AgentData.SessionID != SessionId ||
  9019. reclaimPacket.AgentData.AgentID != AgentId)
  9020. return true;
  9021. #endregion
  9022. ParcelReclaim handlerParcelReclaim = OnParcelReclaim;
  9023. if (handlerParcelReclaim != null)
  9024. {
  9025. handlerParcelReclaim(reclaimPacket.Data.LocalID, this);
  9026. }
  9027. return true;
  9028. }
  9029. private bool HandleParcelReturnObjects(IClientAPI sender, Packet Pack)
  9030. {
  9031. ParcelReturnObjectsPacket parcelReturnObjects = (ParcelReturnObjectsPacket)Pack;
  9032. #region Packet Session and User Check
  9033. if (parcelReturnObjects.AgentData.SessionID != SessionId ||
  9034. parcelReturnObjects.AgentData.AgentID != AgentId)
  9035. return true;
  9036. #endregion
  9037. UUID[] puserselectedOwnerIDs = new UUID[parcelReturnObjects.OwnerIDs.Length];
  9038. for (int parceliterator = 0; parceliterator < parcelReturnObjects.OwnerIDs.Length; parceliterator++)
  9039. puserselectedOwnerIDs[parceliterator] = parcelReturnObjects.OwnerIDs[parceliterator].OwnerID;
  9040. UUID[] puserselectedTaskIDs = new UUID[parcelReturnObjects.TaskIDs.Length];
  9041. for (int parceliterator = 0; parceliterator < parcelReturnObjects.TaskIDs.Length; parceliterator++)
  9042. puserselectedTaskIDs[parceliterator] = parcelReturnObjects.TaskIDs[parceliterator].TaskID;
  9043. ParcelReturnObjectsRequest handlerParcelReturnObjectsRequest = OnParcelReturnObjectsRequest;
  9044. if (handlerParcelReturnObjectsRequest != null)
  9045. {
  9046. handlerParcelReturnObjectsRequest(parcelReturnObjects.ParcelData.LocalID, parcelReturnObjects.ParcelData.ReturnType, puserselectedOwnerIDs, puserselectedTaskIDs, this);
  9047. }
  9048. return true;
  9049. }
  9050. private bool HandleParcelSetOtherCleanTime(IClientAPI sender, Packet Pack)
  9051. {
  9052. ParcelSetOtherCleanTimePacket parcelSetOtherCleanTimePacket = (ParcelSetOtherCleanTimePacket)Pack;
  9053. #region Packet Session and User Check
  9054. if (parcelSetOtherCleanTimePacket.AgentData.SessionID != SessionId ||
  9055. parcelSetOtherCleanTimePacket.AgentData.AgentID != AgentId)
  9056. return true;
  9057. #endregion
  9058. ParcelSetOtherCleanTime handlerParcelSetOtherCleanTime = OnParcelSetOtherCleanTime;
  9059. if (handlerParcelSetOtherCleanTime != null)
  9060. {
  9061. handlerParcelSetOtherCleanTime(this,
  9062. parcelSetOtherCleanTimePacket.ParcelData.LocalID,
  9063. parcelSetOtherCleanTimePacket.ParcelData.OtherCleanTime);
  9064. }
  9065. return true;
  9066. }
  9067. private bool HandleLandStatRequest(IClientAPI sender, Packet Pack)
  9068. {
  9069. LandStatRequestPacket lsrp = (LandStatRequestPacket)Pack;
  9070. #region Packet Session and User Check
  9071. if (lsrp.AgentData.SessionID != SessionId ||
  9072. lsrp.AgentData.AgentID != AgentId)
  9073. return true;
  9074. #endregion
  9075. GodLandStatRequest handlerLandStatRequest = OnLandStatRequest;
  9076. if (handlerLandStatRequest != null)
  9077. {
  9078. handlerLandStatRequest(lsrp.RequestData.ParcelLocalID, lsrp.RequestData.ReportType, lsrp.RequestData.RequestFlags, Utils.BytesToString(lsrp.RequestData.Filter), this);
  9079. }
  9080. return true;
  9081. }
  9082. private bool HandleParcelDwellRequest(IClientAPI sender, Packet Pack)
  9083. {
  9084. ParcelDwellRequestPacket dwellrq =
  9085. (ParcelDwellRequestPacket)Pack;
  9086. #region Packet Session and User Check
  9087. if (dwellrq.AgentData.SessionID != SessionId ||
  9088. dwellrq.AgentData.AgentID != AgentId)
  9089. return true;
  9090. #endregion
  9091. ParcelDwellRequest handlerParcelDwellRequest = OnParcelDwellRequest;
  9092. if (handlerParcelDwellRequest != null)
  9093. {
  9094. handlerParcelDwellRequest(dwellrq.Data.LocalID, this);
  9095. }
  9096. return true;
  9097. }
  9098. #endregion Parcel related packets
  9099. #region Estate Packets
  9100. private static double m_lastMapRegenTime = Double.MinValue;
  9101. private bool HandleEstateOwnerMessage(IClientAPI sender, Packet Pack)
  9102. {
  9103. EstateOwnerMessagePacket messagePacket = (EstateOwnerMessagePacket)Pack;
  9104. // m_log.InfoFormat("[LLCLIENTVIEW]: Packet: {0}", Utils.BytesToString(messagePacket.MethodData.Method));
  9105. GodLandStatRequest handlerLandStatRequest;
  9106. #region Packet Session and User Check
  9107. if (messagePacket.AgentData.SessionID != SessionId ||
  9108. messagePacket.AgentData.AgentID != AgentId)
  9109. return true;
  9110. #endregion
  9111. string method = Utils.BytesToString(messagePacket.MethodData.Method);
  9112. switch (method)
  9113. {
  9114. case "getinfo":
  9115. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9116. {
  9117. OnDetailedEstateDataRequest(this, messagePacket.MethodData.Invoice);
  9118. }
  9119. return true;
  9120. case "setregioninfo":
  9121. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9122. {
  9123. OnSetEstateFlagsRequest(convertParamStringToBool(messagePacket.ParamList[0].Parameter), convertParamStringToBool(messagePacket.ParamList[1].Parameter),
  9124. convertParamStringToBool(messagePacket.ParamList[2].Parameter), !convertParamStringToBool(messagePacket.ParamList[3].Parameter),
  9125. Convert.ToInt16(Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[4].Parameter), Culture.NumberFormatInfo)),
  9126. (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[5].Parameter), Culture.NumberFormatInfo),
  9127. Convert.ToInt16(Utils.BytesToString(messagePacket.ParamList[6].Parameter)),
  9128. convertParamStringToBool(messagePacket.ParamList[7].Parameter), convertParamStringToBool(messagePacket.ParamList[8].Parameter));
  9129. }
  9130. return true;
  9131. // case "texturebase":
  9132. // if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9133. // {
  9134. // foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9135. // {
  9136. // string s = Utils.BytesToString(block.Parameter);
  9137. // string[] splitField = s.Split(' ');
  9138. // if (splitField.Length == 2)
  9139. // {
  9140. // UUID tempUUID = new UUID(splitField[1]);
  9141. // OnSetEstateTerrainBaseTexture(this, Convert.ToInt16(splitField[0]), tempUUID);
  9142. // }
  9143. // }
  9144. // }
  9145. // break;
  9146. case "texturedetail":
  9147. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9148. {
  9149. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9150. {
  9151. string s = Utils.BytesToString(block.Parameter);
  9152. string[] splitField = s.Split(' ');
  9153. if (splitField.Length == 2)
  9154. {
  9155. Int16 corner = Convert.ToInt16(splitField[0]);
  9156. UUID textureUUID = new UUID(splitField[1]);
  9157. OnSetEstateTerrainDetailTexture(this, corner, textureUUID);
  9158. }
  9159. }
  9160. }
  9161. return true;
  9162. case "textureheights":
  9163. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9164. {
  9165. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9166. {
  9167. string s = Utils.BytesToString(block.Parameter);
  9168. string[] splitField = s.Split(' ');
  9169. if (splitField.Length == 3)
  9170. {
  9171. Int16 corner = Convert.ToInt16(splitField[0]);
  9172. float lowValue = (float)Convert.ToDecimal(splitField[1], Culture.NumberFormatInfo);
  9173. float highValue = (float)Convert.ToDecimal(splitField[2], Culture.NumberFormatInfo);
  9174. OnSetEstateTerrainTextureHeights(this, corner, lowValue, highValue);
  9175. }
  9176. }
  9177. }
  9178. return true;
  9179. case "texturecommit":
  9180. OnCommitEstateTerrainTextureRequest(this);
  9181. return true;
  9182. case "setregionterrain":
  9183. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9184. {
  9185. if (messagePacket.ParamList.Length != 9)
  9186. {
  9187. m_log.Error("EstateOwnerMessage: SetRegionTerrain method has a ParamList of invalid length");
  9188. }
  9189. else
  9190. {
  9191. try
  9192. {
  9193. string tmp = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  9194. if (!tmp.Contains(".")) tmp += ".00";
  9195. float WaterHeight = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
  9196. tmp = Utils.BytesToString(messagePacket.ParamList[1].Parameter);
  9197. if (!tmp.Contains(".")) tmp += ".00";
  9198. float TerrainRaiseLimit = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
  9199. tmp = Utils.BytesToString(messagePacket.ParamList[2].Parameter);
  9200. if (!tmp.Contains(".")) tmp += ".00";
  9201. float TerrainLowerLimit = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
  9202. bool UseEstateSun = convertParamStringToBool(messagePacket.ParamList[3].Parameter);
  9203. bool UseFixedSun = convertParamStringToBool(messagePacket.ParamList[4].Parameter);
  9204. float SunHour = (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[5].Parameter), Culture.NumberFormatInfo);
  9205. bool UseGlobal = convertParamStringToBool(messagePacket.ParamList[6].Parameter);
  9206. bool EstateFixedSun = convertParamStringToBool(messagePacket.ParamList[7].Parameter);
  9207. float EstateSunHour = (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[8].Parameter), Culture.NumberFormatInfo);
  9208. OnSetRegionTerrainSettings(WaterHeight, TerrainRaiseLimit, TerrainLowerLimit, UseEstateSun, UseFixedSun, SunHour, UseGlobal, EstateFixedSun, EstateSunHour);
  9209. }
  9210. catch (Exception ex)
  9211. {
  9212. m_log.Error("EstateOwnerMessage: Exception while setting terrain settings: \n" + messagePacket + "\n" + ex);
  9213. }
  9214. }
  9215. }
  9216. return true;
  9217. case "restart":
  9218. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9219. {
  9220. // There's only 1 block in the estateResetSim.. and that's the number of seconds till restart.
  9221. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9222. {
  9223. float timeSeconds;
  9224. Utils.TryParseSingle(Utils.BytesToString(block.Parameter), out timeSeconds);
  9225. timeSeconds = (int)timeSeconds;
  9226. OnEstateRestartSimRequest(this, (int)timeSeconds);
  9227. }
  9228. }
  9229. return true;
  9230. case "estatechangecovenantid":
  9231. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9232. {
  9233. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9234. {
  9235. UUID newCovenantID = new UUID(Utils.BytesToString(block.Parameter));
  9236. OnEstateChangeCovenantRequest(this, newCovenantID);
  9237. }
  9238. }
  9239. return true;
  9240. case "estateaccessdelta": // Estate access delta manages the banlist and allow list too.
  9241. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9242. {
  9243. int estateAccessType = Convert.ToInt16(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9244. OnUpdateEstateAccessDeltaRequest(this, messagePacket.MethodData.Invoice, estateAccessType, new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter)));
  9245. }
  9246. return true;
  9247. case "simulatormessage":
  9248. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9249. {
  9250. UUID invoice = messagePacket.MethodData.Invoice;
  9251. UUID SenderID = new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  9252. string SenderName = Utils.BytesToString(messagePacket.ParamList[3].Parameter);
  9253. string Message = Utils.BytesToString(messagePacket.ParamList[4].Parameter);
  9254. UUID sessionID = messagePacket.AgentData.SessionID;
  9255. OnSimulatorBlueBoxMessageRequest(this, invoice, SenderID, sessionID, SenderName, Message);
  9256. }
  9257. return true;
  9258. case "instantmessage":
  9259. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9260. {
  9261. if (messagePacket.ParamList.Length < 2)
  9262. return true;
  9263. UUID invoice = messagePacket.MethodData.Invoice;
  9264. UUID sessionID = messagePacket.AgentData.SessionID;
  9265. UUID SenderID;
  9266. string SenderName;
  9267. string Message;
  9268. if (messagePacket.ParamList.Length < 5)
  9269. {
  9270. SenderID = AgentId;
  9271. SenderName = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  9272. Message = Utils.BytesToString(messagePacket.ParamList[1].Parameter);
  9273. }
  9274. else
  9275. {
  9276. SenderID = new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  9277. SenderName = Utils.BytesToString(messagePacket.ParamList[3].Parameter);
  9278. Message = Utils.BytesToString(messagePacket.ParamList[4].Parameter);
  9279. }
  9280. OnEstateBlueBoxMessageRequest(this, invoice, SenderID, sessionID, SenderName, Message);
  9281. }
  9282. return true;
  9283. case "setregiondebug":
  9284. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9285. {
  9286. UUID invoice = messagePacket.MethodData.Invoice;
  9287. UUID SenderID = messagePacket.AgentData.AgentID;
  9288. bool scripted = convertParamStringToBool(messagePacket.ParamList[0].Parameter);
  9289. bool collisionEvents = convertParamStringToBool(messagePacket.ParamList[1].Parameter);
  9290. bool physics = convertParamStringToBool(messagePacket.ParamList[2].Parameter);
  9291. OnEstateDebugRegionRequest(this, invoice, SenderID, scripted, collisionEvents, physics);
  9292. }
  9293. return true;
  9294. case "teleporthomeuser":
  9295. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9296. {
  9297. UUID invoice = messagePacket.MethodData.Invoice;
  9298. UUID SenderID = messagePacket.AgentData.AgentID;
  9299. UUID Prey;
  9300. UUID.TryParse(Utils.BytesToString(messagePacket.ParamList[1].Parameter), out Prey);
  9301. OnEstateTeleportOneUserHomeRequest(this, invoice, SenderID, Prey, false);
  9302. }
  9303. return true;
  9304. case "teleporthomeallusers":
  9305. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9306. {
  9307. UUID invoice = messagePacket.MethodData.Invoice;
  9308. UUID SenderID = messagePacket.AgentData.AgentID;
  9309. OnEstateTeleportAllUsersHomeRequest(this, invoice, SenderID);
  9310. }
  9311. return true;
  9312. case "colliders":
  9313. handlerLandStatRequest = OnLandStatRequest;
  9314. if (handlerLandStatRequest != null)
  9315. {
  9316. handlerLandStatRequest(0, 1, 0, "", this);
  9317. }
  9318. return true;
  9319. case "scripts":
  9320. handlerLandStatRequest = OnLandStatRequest;
  9321. if (handlerLandStatRequest != null)
  9322. {
  9323. handlerLandStatRequest(0, 0, 0, "", this);
  9324. }
  9325. return true;
  9326. case "terrain":
  9327. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9328. {
  9329. if (messagePacket.ParamList.Length > 0)
  9330. {
  9331. if (Utils.BytesToString(messagePacket.ParamList[0].Parameter) == "bake")
  9332. {
  9333. BakeTerrain handlerBakeTerrain = OnBakeTerrain;
  9334. if (handlerBakeTerrain != null)
  9335. {
  9336. handlerBakeTerrain(this);
  9337. }
  9338. }
  9339. if (Utils.BytesToString(messagePacket.ParamList[0].Parameter) == "download filename")
  9340. {
  9341. if (messagePacket.ParamList.Length > 1)
  9342. {
  9343. RequestTerrain handlerRequestTerrain = OnRequestTerrain;
  9344. if (handlerRequestTerrain != null)
  9345. {
  9346. handlerRequestTerrain(this, Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9347. }
  9348. }
  9349. }
  9350. if (Utils.BytesToString(messagePacket.ParamList[0].Parameter) == "upload filename")
  9351. {
  9352. if (messagePacket.ParamList.Length > 1)
  9353. {
  9354. RequestTerrain handlerUploadTerrain = OnUploadTerrain;
  9355. if (handlerUploadTerrain != null)
  9356. {
  9357. handlerUploadTerrain(this, Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9358. }
  9359. }
  9360. }
  9361. }
  9362. }
  9363. return true;
  9364. case "estatechangeinfo":
  9365. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9366. {
  9367. UUID invoice = messagePacket.MethodData.Invoice;
  9368. UUID SenderID = messagePacket.AgentData.AgentID;
  9369. UInt32 param1 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9370. UInt32 param2 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  9371. EstateChangeInfo handlerEstateChangeInfo = OnEstateChangeInfo;
  9372. if (handlerEstateChangeInfo != null)
  9373. {
  9374. handlerEstateChangeInfo(this, invoice, SenderID, param1, param2);
  9375. }
  9376. }
  9377. return true;
  9378. case "telehub":
  9379. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9380. {
  9381. UUID invoice = messagePacket.MethodData.Invoice;
  9382. UUID SenderID = messagePacket.AgentData.AgentID;
  9383. UInt32 param1 = 0u;
  9384. string command = (string)Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  9385. if (command != "info ui")
  9386. {
  9387. try
  9388. {
  9389. param1 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9390. }
  9391. catch
  9392. {
  9393. }
  9394. }
  9395. EstateManageTelehub handlerEstateManageTelehub = OnEstateManageTelehub;
  9396. if (handlerEstateManageTelehub != null)
  9397. {
  9398. handlerEstateManageTelehub(this, invoice, SenderID, command, param1);
  9399. }
  9400. }
  9401. return true;
  9402. case "refreshmapvisibility":
  9403. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9404. {
  9405. IWorldMapModule mapModule = Scene.RequestModuleInterface<IWorldMapModule>();
  9406. if (mapModule == null)
  9407. {
  9408. SendAlertMessage("Terrain map generator not avaiable");
  9409. return true;
  9410. }
  9411. if (m_lastMapRegenTime == Double.MaxValue)
  9412. {
  9413. SendAlertMessage("Terrain map generation still in progress");
  9414. return true;
  9415. }
  9416. double now = Util.GetTimeStamp();
  9417. if (now - m_lastMapRegenTime < 120) // 2 minutes global cool down
  9418. {
  9419. SendAlertMessage("Please wait at least 2 minutes between map generation commands");
  9420. return true;
  9421. }
  9422. m_lastMapRegenTime = Double.MaxValue;
  9423. mapModule.GenerateMaptile();
  9424. SendAlertMessage("Terrain map generated");
  9425. m_lastMapRegenTime = now;
  9426. }
  9427. return true;
  9428. case "kickestate":
  9429. if(((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9430. {
  9431. UUID invoice = messagePacket.MethodData.Invoice;
  9432. UUID SenderID = messagePacket.AgentData.AgentID;
  9433. UUID Prey;
  9434. UUID.TryParse(Utils.BytesToString(messagePacket.ParamList[0].Parameter), out Prey);
  9435. OnEstateTeleportOneUserHomeRequest(this, invoice, SenderID, Prey, true);
  9436. }
  9437. return true;
  9438. default:
  9439. m_log.WarnFormat(
  9440. "[LLCLIENTVIEW]: EstateOwnerMessage: Unknown method {0} requested for {1} in {2}",
  9441. method, Name, Scene.Name);
  9442. for (int i = 0; i < messagePacket.ParamList.Length; i++)
  9443. {
  9444. EstateOwnerMessagePacket.ParamListBlock block = messagePacket.ParamList[i];
  9445. string data = (string)Utils.BytesToString(block.Parameter);
  9446. m_log.DebugFormat("[LLCLIENTVIEW]: Param {0}={1}", i, data);
  9447. }
  9448. return true;
  9449. }
  9450. //int parcelID, uint reportType, uint requestflags, string filter
  9451. //lsrp.RequestData.ParcelLocalID;
  9452. //lsrp.RequestData.ReportType; // 1 = colliders, 0 = scripts
  9453. //lsrp.RequestData.RequestFlags;
  9454. //lsrp.RequestData.Filter;
  9455. }
  9456. private bool HandleRequestRegionInfo(IClientAPI sender, Packet Pack)
  9457. {
  9458. RequestRegionInfoPacket.AgentDataBlock mPacket = ((RequestRegionInfoPacket)Pack).AgentData;
  9459. #region Packet Session and User Check
  9460. if (mPacket.SessionID != SessionId ||
  9461. mPacket.AgentID != AgentId)
  9462. return true;
  9463. #endregion
  9464. RegionInfoRequest handlerRegionInfoRequest = OnRegionInfoRequest;
  9465. if (handlerRegionInfoRequest != null)
  9466. {
  9467. handlerRegionInfoRequest(this);
  9468. }
  9469. return true;
  9470. }
  9471. private bool HandleEstateCovenantRequest(IClientAPI sender, Packet Pack)
  9472. {
  9473. //EstateCovenantRequestPacket.AgentDataBlock epack =
  9474. // ((EstateCovenantRequestPacket)Pack).AgentData;
  9475. EstateCovenantRequest handlerEstateCovenantRequest = OnEstateCovenantRequest;
  9476. if (handlerEstateCovenantRequest != null)
  9477. {
  9478. handlerEstateCovenantRequest(this);
  9479. }
  9480. return true;
  9481. }
  9482. #endregion Estate Packets
  9483. #region GodPackets
  9484. private bool HandleRequestGodlikePowers(IClientAPI sender, Packet Pack)
  9485. {
  9486. RequestGodlikePowersPacket rglpPack = (RequestGodlikePowersPacket)Pack;
  9487. if (rglpPack.AgentData.SessionID != SessionId ||
  9488. rglpPack.AgentData.AgentID != AgentId)
  9489. return true;
  9490. RequestGodlikePowersPacket.RequestBlockBlock rblock = rglpPack.RequestBlock;
  9491. UUID token = rblock.Token;
  9492. RequestGodlikePowersPacket.AgentDataBlock ablock = rglpPack.AgentData;
  9493. RequestGodlikePowers handlerReqGodlikePowers = OnRequestGodlikePowers;
  9494. if (handlerReqGodlikePowers != null)
  9495. {
  9496. handlerReqGodlikePowers(ablock.AgentID, ablock.SessionID, token, rblock.Godlike);
  9497. }
  9498. return true;
  9499. }
  9500. private bool HandleGodUpdateRegionInfoUpdate(IClientAPI client, Packet Packet)
  9501. {
  9502. GodUpdateRegionInfoPacket GodUpdateRegionInfo =
  9503. (GodUpdateRegionInfoPacket)Packet;
  9504. if (GodUpdateRegionInfo.AgentData.SessionID != SessionId ||
  9505. GodUpdateRegionInfo.AgentData.AgentID != AgentId)
  9506. return true;
  9507. GodUpdateRegionInfoUpdate handlerGodUpdateRegionInfo = OnGodUpdateRegionInfoUpdate;
  9508. if (handlerGodUpdateRegionInfo != null)
  9509. {
  9510. handlerGodUpdateRegionInfo(this,
  9511. GodUpdateRegionInfo.RegionInfo.BillableFactor,
  9512. GodUpdateRegionInfo.RegionInfo.EstateID,
  9513. GodUpdateRegionInfo.RegionInfo.RegionFlags,
  9514. GodUpdateRegionInfo.RegionInfo.SimName,
  9515. GodUpdateRegionInfo.RegionInfo.RedirectGridX,
  9516. GodUpdateRegionInfo.RegionInfo.RedirectGridY);
  9517. return true;
  9518. }
  9519. return false;
  9520. }
  9521. private bool HandleSimWideDeletes(IClientAPI client, Packet Packet)
  9522. {
  9523. SimWideDeletesPacket SimWideDeletesRequest =
  9524. (SimWideDeletesPacket)Packet;
  9525. SimWideDeletesDelegate handlerSimWideDeletesRequest = OnSimWideDeletes;
  9526. if (handlerSimWideDeletesRequest != null)
  9527. {
  9528. handlerSimWideDeletesRequest(this, SimWideDeletesRequest.AgentData.AgentID,(int)SimWideDeletesRequest.DataBlock.Flags,SimWideDeletesRequest.DataBlock.TargetID);
  9529. return true;
  9530. }
  9531. return false;
  9532. }
  9533. private bool HandleGodlikeMessage(IClientAPI client, Packet Packet)
  9534. {
  9535. GodlikeMessagePacket GodlikeMessage =
  9536. (GodlikeMessagePacket)Packet;
  9537. if (GodlikeMessage.AgentData.SessionID != SessionId ||
  9538. GodlikeMessage.AgentData.AgentID != AgentId)
  9539. return true;
  9540. GodlikeMessage handlerGodlikeMessage = onGodlikeMessage;
  9541. if (handlerGodlikeMessage != null)
  9542. {
  9543. handlerGodlikeMessage(this,
  9544. GodlikeMessage.MethodData.Invoice,
  9545. GodlikeMessage.MethodData.Method,
  9546. GodlikeMessage.ParamList[0].Parameter);
  9547. return true;
  9548. }
  9549. return false;
  9550. }
  9551. private bool HandleSaveStatePacket(IClientAPI client, Packet Packet)
  9552. {
  9553. StateSavePacket SaveStateMessage =
  9554. (StateSavePacket)Packet;
  9555. if (SaveStateMessage.AgentData.SessionID != SessionId ||
  9556. SaveStateMessage.AgentData.AgentID != AgentId)
  9557. return true;
  9558. SaveStateHandler handlerSaveStatePacket = OnSaveState;
  9559. if (handlerSaveStatePacket != null)
  9560. {
  9561. handlerSaveStatePacket(this,SaveStateMessage.AgentData.AgentID);
  9562. return true;
  9563. }
  9564. return false;
  9565. }
  9566. private bool HandleGodKickUser(IClientAPI sender, Packet Pack)
  9567. {
  9568. GodKickUserPacket gkupack = (GodKickUserPacket)Pack;
  9569. if (gkupack.UserInfo.GodSessionID != SessionId ||
  9570. gkupack.UserInfo.GodID != AgentId)
  9571. return true;
  9572. GodKickUser handlerGodKickUser = OnGodKickUser;
  9573. if (handlerGodKickUser != null)
  9574. {
  9575. handlerGodKickUser(gkupack.UserInfo.GodID, gkupack.UserInfo.AgentID, gkupack.UserInfo.KickFlags, gkupack.UserInfo.Reason);
  9576. }
  9577. return true;
  9578. }
  9579. #endregion GodPackets
  9580. #region Economy/Transaction Packets
  9581. private bool HandleMoneyBalanceRequest(IClientAPI sender, Packet Pack)
  9582. {
  9583. MoneyBalanceRequestPacket moneybalancerequestpacket = (MoneyBalanceRequestPacket)Pack;
  9584. #region Packet Session and User Check
  9585. if (moneybalancerequestpacket.AgentData.SessionID != SessionId ||
  9586. moneybalancerequestpacket.AgentData.AgentID != AgentId)
  9587. return true;
  9588. #endregion
  9589. MoneyBalanceRequest handlerMoneyBalanceRequest = OnMoneyBalanceRequest;
  9590. if (handlerMoneyBalanceRequest != null)
  9591. {
  9592. handlerMoneyBalanceRequest(this, moneybalancerequestpacket.AgentData.AgentID, moneybalancerequestpacket.AgentData.SessionID, moneybalancerequestpacket.MoneyData.TransactionID);
  9593. }
  9594. return true;
  9595. }
  9596. private bool HandleEconomyDataRequest(IClientAPI sender, Packet Pack)
  9597. {
  9598. EconomyDataRequest handlerEconomoyDataRequest = OnEconomyDataRequest;
  9599. if (handlerEconomoyDataRequest != null)
  9600. {
  9601. handlerEconomoyDataRequest(this);
  9602. }
  9603. return true;
  9604. }
  9605. private bool HandleRequestPayPrice(IClientAPI sender, Packet Pack)
  9606. {
  9607. RequestPayPricePacket requestPayPricePacket = (RequestPayPricePacket)Pack;
  9608. RequestPayPrice handlerRequestPayPrice = OnRequestPayPrice;
  9609. if (handlerRequestPayPrice != null)
  9610. {
  9611. handlerRequestPayPrice(this, requestPayPricePacket.ObjectData.ObjectID);
  9612. }
  9613. return true;
  9614. }
  9615. private bool HandleObjectSaleInfo(IClientAPI sender, Packet Pack)
  9616. {
  9617. ObjectSaleInfoPacket objectSaleInfoPacket = (ObjectSaleInfoPacket)Pack;
  9618. #region Packet Session and User Check
  9619. if (objectSaleInfoPacket.AgentData.SessionID != SessionId ||
  9620. objectSaleInfoPacket.AgentData.AgentID != AgentId)
  9621. return true;
  9622. #endregion
  9623. ObjectSaleInfo handlerObjectSaleInfo = OnObjectSaleInfo;
  9624. if (handlerObjectSaleInfo != null)
  9625. {
  9626. foreach (ObjectSaleInfoPacket.ObjectDataBlock d
  9627. in objectSaleInfoPacket.ObjectData)
  9628. {
  9629. handlerObjectSaleInfo(this,
  9630. objectSaleInfoPacket.AgentData.AgentID,
  9631. objectSaleInfoPacket.AgentData.SessionID,
  9632. d.LocalID,
  9633. d.SaleType,
  9634. d.SalePrice);
  9635. }
  9636. }
  9637. return true;
  9638. }
  9639. private bool HandleObjectBuy(IClientAPI sender, Packet Pack)
  9640. {
  9641. ObjectBuyPacket objectBuyPacket = (ObjectBuyPacket)Pack;
  9642. #region Packet Session and User Check
  9643. if (objectBuyPacket.AgentData.SessionID != SessionId ||
  9644. objectBuyPacket.AgentData.AgentID != AgentId)
  9645. return true;
  9646. #endregion
  9647. ObjectBuy handlerObjectBuy = OnObjectBuy;
  9648. if (handlerObjectBuy != null)
  9649. {
  9650. foreach (ObjectBuyPacket.ObjectDataBlock d
  9651. in objectBuyPacket.ObjectData)
  9652. {
  9653. handlerObjectBuy(this,
  9654. objectBuyPacket.AgentData.AgentID,
  9655. objectBuyPacket.AgentData.SessionID,
  9656. objectBuyPacket.AgentData.GroupID,
  9657. objectBuyPacket.AgentData.CategoryID,
  9658. d.ObjectLocalID,
  9659. d.SaleType,
  9660. d.SalePrice);
  9661. }
  9662. }
  9663. return true;
  9664. }
  9665. #endregion Economy/Transaction Packets
  9666. #region Script Packets
  9667. private bool HandleGetScriptRunning(IClientAPI sender, Packet Pack)
  9668. {
  9669. GetScriptRunningPacket scriptRunning = (GetScriptRunningPacket)Pack;
  9670. GetScriptRunning handlerGetScriptRunning = OnGetScriptRunning;
  9671. if (handlerGetScriptRunning != null)
  9672. {
  9673. handlerGetScriptRunning(this, scriptRunning.Script.ObjectID, scriptRunning.Script.ItemID);
  9674. }
  9675. return true;
  9676. }
  9677. private bool HandleSetScriptRunning(IClientAPI sender, Packet Pack)
  9678. {
  9679. SetScriptRunningPacket setScriptRunning = (SetScriptRunningPacket)Pack;
  9680. #region Packet Session and User Check
  9681. if (setScriptRunning.AgentData.SessionID != SessionId ||
  9682. setScriptRunning.AgentData.AgentID != AgentId)
  9683. return true;
  9684. #endregion
  9685. SetScriptRunning handlerSetScriptRunning = OnSetScriptRunning;
  9686. if (handlerSetScriptRunning != null)
  9687. {
  9688. handlerSetScriptRunning(this, setScriptRunning.Script.ObjectID, setScriptRunning.Script.ItemID, setScriptRunning.Script.Running);
  9689. }
  9690. return true;
  9691. }
  9692. private bool HandleScriptReset(IClientAPI sender, Packet Pack)
  9693. {
  9694. ScriptResetPacket scriptResetPacket = (ScriptResetPacket)Pack;
  9695. #region Packet Session and User Check
  9696. if (scriptResetPacket.AgentData.SessionID != SessionId ||
  9697. scriptResetPacket.AgentData.AgentID != AgentId)
  9698. return true;
  9699. #endregion
  9700. ScriptReset handlerScriptReset = OnScriptReset;
  9701. if (handlerScriptReset != null)
  9702. {
  9703. handlerScriptReset(this, scriptResetPacket.Script.ObjectID, scriptResetPacket.Script.ItemID);
  9704. }
  9705. return true;
  9706. }
  9707. #endregion Script Packets
  9708. #region Gesture Managment
  9709. private bool HandleActivateGestures(IClientAPI sender, Packet Pack)
  9710. {
  9711. ActivateGesturesPacket activateGesturePacket = (ActivateGesturesPacket)Pack;
  9712. #region Packet Session and User Check
  9713. if (activateGesturePacket.AgentData.SessionID != SessionId ||
  9714. activateGesturePacket.AgentData.AgentID != AgentId)
  9715. return true;
  9716. #endregion
  9717. ActivateGesture handlerActivateGesture = OnActivateGesture;
  9718. if (handlerActivateGesture != null)
  9719. {
  9720. handlerActivateGesture(this,
  9721. activateGesturePacket.Data[0].AssetID,
  9722. activateGesturePacket.Data[0].ItemID);
  9723. }
  9724. else m_log.Error("Null pointer for activateGesture");
  9725. return true;
  9726. }
  9727. private bool HandleDeactivateGestures(IClientAPI sender, Packet Pack)
  9728. {
  9729. DeactivateGesturesPacket deactivateGesturePacket = (DeactivateGesturesPacket)Pack;
  9730. #region Packet Session and User Check
  9731. if (deactivateGesturePacket.AgentData.SessionID != SessionId ||
  9732. deactivateGesturePacket.AgentData.AgentID != AgentId)
  9733. return true;
  9734. #endregion
  9735. DeactivateGesture handlerDeactivateGesture = OnDeactivateGesture;
  9736. if (handlerDeactivateGesture != null)
  9737. {
  9738. handlerDeactivateGesture(this, deactivateGesturePacket.Data[0].ItemID);
  9739. }
  9740. return true;
  9741. }
  9742. private bool HandleObjectOwner(IClientAPI sender, Packet Pack)
  9743. {
  9744. ObjectOwnerPacket objectOwnerPacket = (ObjectOwnerPacket)Pack;
  9745. #region Packet Session and User Check
  9746. if (objectOwnerPacket.AgentData.SessionID != SessionId ||
  9747. objectOwnerPacket.AgentData.AgentID != AgentId)
  9748. return true;
  9749. #endregion
  9750. List<uint> localIDs = new List<uint>();
  9751. foreach (ObjectOwnerPacket.ObjectDataBlock d in objectOwnerPacket.ObjectData)
  9752. localIDs.Add(d.ObjectLocalID);
  9753. ObjectOwner handlerObjectOwner = OnObjectOwner;
  9754. if (handlerObjectOwner != null)
  9755. {
  9756. handlerObjectOwner(this, objectOwnerPacket.HeaderData.OwnerID, objectOwnerPacket.HeaderData.GroupID, localIDs);
  9757. }
  9758. return true;
  9759. }
  9760. #endregion Gesture Managment
  9761. private bool HandleAgentFOV(IClientAPI sender, Packet Pack)
  9762. {
  9763. AgentFOVPacket fovPacket = (AgentFOVPacket)Pack;
  9764. if (fovPacket.FOVBlock.GenCounter > m_agentFOVCounter)
  9765. {
  9766. m_agentFOVCounter = fovPacket.FOVBlock.GenCounter;
  9767. AgentFOV handlerAgentFOV = OnAgentFOV;
  9768. if (handlerAgentFOV != null)
  9769. {
  9770. handlerAgentFOV(this, fovPacket.FOVBlock.VerticalAngle);
  9771. }
  9772. }
  9773. return true;
  9774. }
  9775. #region unimplemented handlers
  9776. private bool HandleViewerStats(IClientAPI sender, Packet Pack)
  9777. {
  9778. // TODO: handle this packet
  9779. //m_log.Warn("[CLIENT]: unhandled ViewerStats packet");
  9780. return true;
  9781. }
  9782. private bool HandleMapItemRequest(IClientAPI sender, Packet Pack)
  9783. {
  9784. MapItemRequestPacket mirpk = (MapItemRequestPacket)Pack;
  9785. #region Packet Session and User Check
  9786. if (mirpk.AgentData.SessionID != SessionId ||
  9787. mirpk.AgentData.AgentID != AgentId)
  9788. return true;
  9789. #endregion
  9790. //m_log.Debug(mirpk.ToString());
  9791. MapItemRequest handlerMapItemRequest = OnMapItemRequest;
  9792. if (handlerMapItemRequest != null)
  9793. {
  9794. try
  9795. {
  9796. handlerMapItemRequest(this, mirpk.AgentData.Flags, mirpk.AgentData.EstateID,
  9797. mirpk.AgentData.Godlike, mirpk.RequestData.ItemType,
  9798. mirpk.RequestData.RegionHandle);
  9799. }
  9800. catch( Exception e)
  9801. {
  9802. m_log.ErrorFormat("{0} HandleMapItemRequest exception: {1}", LogHeader, e.Message);
  9803. }
  9804. }
  9805. return true;
  9806. }
  9807. private bool HandleTransferAbort(IClientAPI sender, Packet Pack)
  9808. {
  9809. return true;
  9810. }
  9811. private bool HandleMuteListRequest(IClientAPI sender, Packet Pack)
  9812. {
  9813. MuteListRequestPacket muteListRequest =
  9814. (MuteListRequestPacket)Pack;
  9815. #region Packet Session and User Check
  9816. if (muteListRequest.AgentData.SessionID != SessionId ||
  9817. muteListRequest.AgentData.AgentID != AgentId)
  9818. return true;
  9819. #endregion
  9820. MuteListRequest handlerMuteListRequest = OnMuteListRequest;
  9821. if (handlerMuteListRequest != null)
  9822. {
  9823. handlerMuteListRequest(this, muteListRequest.MuteData.MuteCRC);
  9824. }
  9825. else
  9826. {
  9827. if(muteListRequest.MuteData.MuteCRC == 0)
  9828. SendEmpytMuteList();
  9829. else
  9830. SendUseCachedMuteList();
  9831. }
  9832. return true;
  9833. }
  9834. private bool HandleUpdateMuteListEntry(IClientAPI client, Packet Packet)
  9835. {
  9836. UpdateMuteListEntryPacket UpdateMuteListEntry =
  9837. (UpdateMuteListEntryPacket)Packet;
  9838. MuteListEntryUpdate handlerUpdateMuteListEntry = OnUpdateMuteListEntry;
  9839. if (handlerUpdateMuteListEntry != null)
  9840. {
  9841. handlerUpdateMuteListEntry(this, UpdateMuteListEntry.MuteData.MuteID,
  9842. Utils.BytesToString(UpdateMuteListEntry.MuteData.MuteName),
  9843. UpdateMuteListEntry.MuteData.MuteType,
  9844. UpdateMuteListEntry.MuteData.MuteFlags);
  9845. return true;
  9846. }
  9847. return false;
  9848. }
  9849. private bool HandleRemoveMuteListEntry(IClientAPI client, Packet Packet)
  9850. {
  9851. RemoveMuteListEntryPacket RemoveMuteListEntry =
  9852. (RemoveMuteListEntryPacket)Packet;
  9853. MuteListEntryRemove handlerRemoveMuteListEntry = OnRemoveMuteListEntry;
  9854. if (handlerRemoveMuteListEntry != null)
  9855. {
  9856. handlerRemoveMuteListEntry(this,
  9857. RemoveMuteListEntry.MuteData.MuteID,
  9858. Utils.BytesToString(RemoveMuteListEntry.MuteData.MuteName));
  9859. return true;
  9860. }
  9861. return false;
  9862. }
  9863. private bool HandleUserReport(IClientAPI client, Packet Packet)
  9864. {
  9865. UserReportPacket UserReport =
  9866. (UserReportPacket)Packet;
  9867. NewUserReport handlerUserReport = OnUserReport;
  9868. if (handlerUserReport != null)
  9869. {
  9870. handlerUserReport(this,
  9871. Utils.BytesToString(UserReport.ReportData.AbuseRegionName),
  9872. UserReport.ReportData.AbuserID,
  9873. UserReport.ReportData.Category,
  9874. UserReport.ReportData.CheckFlags,
  9875. Utils.BytesToString(UserReport.ReportData.Details),
  9876. UserReport.ReportData.ObjectID,
  9877. UserReport.ReportData.Position,
  9878. UserReport.ReportData.ReportType,
  9879. UserReport.ReportData.ScreenshotID,
  9880. Utils.BytesToString(UserReport.ReportData.Summary),
  9881. UserReport.AgentData.AgentID);
  9882. return true;
  9883. }
  9884. return false;
  9885. }
  9886. private bool HandleSendPostcard(IClientAPI client, Packet packet)
  9887. {
  9888. // SendPostcardPacket SendPostcard =
  9889. // (SendPostcardPacket)packet;
  9890. SendPostcard handlerSendPostcard = OnSendPostcard;
  9891. if (handlerSendPostcard != null)
  9892. {
  9893. handlerSendPostcard(this);
  9894. return true;
  9895. }
  9896. return false;
  9897. }
  9898. private bool HandleChangeInventoryItemFlags(IClientAPI client, Packet packet)
  9899. {
  9900. ChangeInventoryItemFlagsPacket ChangeInventoryItemFlags =
  9901. (ChangeInventoryItemFlagsPacket)packet;
  9902. ChangeInventoryItemFlags handlerChangeInventoryItemFlags = OnChangeInventoryItemFlags;
  9903. if (handlerChangeInventoryItemFlags != null)
  9904. {
  9905. foreach(ChangeInventoryItemFlagsPacket.InventoryDataBlock b in ChangeInventoryItemFlags.InventoryData)
  9906. handlerChangeInventoryItemFlags(this, b.ItemID, b.Flags);
  9907. return true;
  9908. }
  9909. return false;
  9910. }
  9911. private bool HandleUseCircuitCode(IClientAPI sender, Packet Pack)
  9912. {
  9913. return true;
  9914. }
  9915. private bool HandleCreateNewOutfitAttachments(IClientAPI sender, Packet Pack)
  9916. {
  9917. CreateNewOutfitAttachmentsPacket packet = (CreateNewOutfitAttachmentsPacket)Pack;
  9918. #region Packet Session and User Check
  9919. if (packet.AgentData.SessionID != SessionId ||
  9920. packet.AgentData.AgentID != AgentId)
  9921. return true;
  9922. #endregion
  9923. MoveItemsAndLeaveCopy handlerMoveItemsAndLeaveCopy = null;
  9924. List<InventoryItemBase> items = new List<InventoryItemBase>();
  9925. foreach (CreateNewOutfitAttachmentsPacket.ObjectDataBlock n in packet.ObjectData)
  9926. {
  9927. InventoryItemBase b = new InventoryItemBase();
  9928. b.ID = n.OldItemID;
  9929. b.Folder = n.OldFolderID;
  9930. items.Add(b);
  9931. }
  9932. handlerMoveItemsAndLeaveCopy = OnMoveItemsAndLeaveCopy;
  9933. if (handlerMoveItemsAndLeaveCopy != null)
  9934. {
  9935. handlerMoveItemsAndLeaveCopy(this, items, packet.HeaderData.NewFolderID);
  9936. }
  9937. return true;
  9938. }
  9939. private bool HandleAgentHeightWidth(IClientAPI sender, Packet Pack)
  9940. {
  9941. return true;
  9942. }
  9943. private bool HandleInventoryDescendents(IClientAPI sender, Packet Pack)
  9944. {
  9945. return true;
  9946. }
  9947. #endregion unimplemented handlers
  9948. #region Dir handlers
  9949. private bool HandleDirPlacesQuery(IClientAPI sender, Packet Pack)
  9950. {
  9951. DirPlacesQueryPacket dirPlacesQueryPacket = (DirPlacesQueryPacket)Pack;
  9952. //m_log.Debug(dirPlacesQueryPacket.ToString());
  9953. #region Packet Session and User Check
  9954. if (dirPlacesQueryPacket.AgentData.SessionID != SessionId ||
  9955. dirPlacesQueryPacket.AgentData.AgentID != AgentId)
  9956. return true;
  9957. #endregion
  9958. DirPlacesQuery handlerDirPlacesQuery = OnDirPlacesQuery;
  9959. if (handlerDirPlacesQuery != null)
  9960. {
  9961. handlerDirPlacesQuery(this,
  9962. dirPlacesQueryPacket.QueryData.QueryID,
  9963. Utils.BytesToString(
  9964. dirPlacesQueryPacket.QueryData.QueryText),
  9965. (int)dirPlacesQueryPacket.QueryData.QueryFlags,
  9966. (int)dirPlacesQueryPacket.QueryData.Category,
  9967. Utils.BytesToString(
  9968. dirPlacesQueryPacket.QueryData.SimName),
  9969. dirPlacesQueryPacket.QueryData.QueryStart);
  9970. }
  9971. return true;
  9972. }
  9973. private bool HandleDirFindQuery(IClientAPI sender, Packet Pack)
  9974. {
  9975. DirFindQueryPacket dirFindQueryPacket = (DirFindQueryPacket)Pack;
  9976. #region Packet Session and User Check
  9977. if (dirFindQueryPacket.AgentData.SessionID != SessionId ||
  9978. dirFindQueryPacket.AgentData.AgentID != AgentId)
  9979. return true;
  9980. #endregion
  9981. DirFindQuery handlerDirFindQuery = OnDirFindQuery;
  9982. if (handlerDirFindQuery != null)
  9983. {
  9984. handlerDirFindQuery(this,
  9985. dirFindQueryPacket.QueryData.QueryID,
  9986. Utils.BytesToString(
  9987. dirFindQueryPacket.QueryData.QueryText).Trim(),
  9988. dirFindQueryPacket.QueryData.QueryFlags,
  9989. dirFindQueryPacket.QueryData.QueryStart);
  9990. }
  9991. return true;
  9992. }
  9993. private bool HandleDirLandQuery(IClientAPI sender, Packet Pack)
  9994. {
  9995. DirLandQueryPacket dirLandQueryPacket = (DirLandQueryPacket)Pack;
  9996. #region Packet Session and User Check
  9997. if (dirLandQueryPacket.AgentData.SessionID != SessionId ||
  9998. dirLandQueryPacket.AgentData.AgentID != AgentId)
  9999. return true;
  10000. #endregion
  10001. DirLandQuery handlerDirLandQuery = OnDirLandQuery;
  10002. if (handlerDirLandQuery != null)
  10003. {
  10004. handlerDirLandQuery(this,
  10005. dirLandQueryPacket.QueryData.QueryID,
  10006. dirLandQueryPacket.QueryData.QueryFlags,
  10007. dirLandQueryPacket.QueryData.SearchType,
  10008. dirLandQueryPacket.QueryData.Price,
  10009. dirLandQueryPacket.QueryData.Area,
  10010. dirLandQueryPacket.QueryData.QueryStart);
  10011. }
  10012. return true;
  10013. }
  10014. private bool HandleDirPopularQuery(IClientAPI sender, Packet Pack)
  10015. {
  10016. DirPopularQueryPacket dirPopularQueryPacket = (DirPopularQueryPacket)Pack;
  10017. #region Packet Session and User Check
  10018. if (dirPopularQueryPacket.AgentData.SessionID != SessionId ||
  10019. dirPopularQueryPacket.AgentData.AgentID != AgentId)
  10020. return true;
  10021. #endregion
  10022. DirPopularQuery handlerDirPopularQuery = OnDirPopularQuery;
  10023. if (handlerDirPopularQuery != null)
  10024. {
  10025. handlerDirPopularQuery(this,
  10026. dirPopularQueryPacket.QueryData.QueryID,
  10027. dirPopularQueryPacket.QueryData.QueryFlags);
  10028. }
  10029. return true;
  10030. }
  10031. private bool HandleDirClassifiedQuery(IClientAPI sender, Packet Pack)
  10032. {
  10033. DirClassifiedQueryPacket dirClassifiedQueryPacket = (DirClassifiedQueryPacket)Pack;
  10034. #region Packet Session and User Check
  10035. if (dirClassifiedQueryPacket.AgentData.SessionID != SessionId ||
  10036. dirClassifiedQueryPacket.AgentData.AgentID != AgentId)
  10037. return true;
  10038. #endregion
  10039. DirClassifiedQuery handlerDirClassifiedQuery = OnDirClassifiedQuery;
  10040. if (handlerDirClassifiedQuery != null)
  10041. {
  10042. handlerDirClassifiedQuery(this,
  10043. dirClassifiedQueryPacket.QueryData.QueryID,
  10044. Utils.BytesToString(
  10045. dirClassifiedQueryPacket.QueryData.QueryText),
  10046. dirClassifiedQueryPacket.QueryData.QueryFlags,
  10047. dirClassifiedQueryPacket.QueryData.Category,
  10048. dirClassifiedQueryPacket.QueryData.QueryStart);
  10049. }
  10050. return true;
  10051. }
  10052. private bool HandleEventInfoRequest(IClientAPI sender, Packet Pack)
  10053. {
  10054. EventInfoRequestPacket eventInfoRequestPacket = (EventInfoRequestPacket)Pack;
  10055. #region Packet Session and User Check
  10056. if (eventInfoRequestPacket.AgentData.SessionID != SessionId ||
  10057. eventInfoRequestPacket.AgentData.AgentID != AgentId)
  10058. return true;
  10059. #endregion
  10060. if (OnEventInfoRequest != null)
  10061. {
  10062. OnEventInfoRequest(this, eventInfoRequestPacket.EventData.EventID);
  10063. }
  10064. return true;
  10065. }
  10066. #endregion
  10067. #region Calling Card
  10068. private bool HandleOfferCallingCard(IClientAPI sender, Packet Pack)
  10069. {
  10070. OfferCallingCardPacket offerCallingCardPacket = (OfferCallingCardPacket)Pack;
  10071. #region Packet Session and User Check
  10072. if (offerCallingCardPacket.AgentData.SessionID != SessionId ||
  10073. offerCallingCardPacket.AgentData.AgentID != AgentId)
  10074. return true;
  10075. #endregion
  10076. if (OnOfferCallingCard != null)
  10077. {
  10078. OnOfferCallingCard(this,
  10079. offerCallingCardPacket.AgentBlock.DestID,
  10080. offerCallingCardPacket.AgentBlock.TransactionID);
  10081. }
  10082. return true;
  10083. }
  10084. private bool HandleAcceptCallingCard(IClientAPI sender, Packet Pack)
  10085. {
  10086. AcceptCallingCardPacket acceptCallingCardPacket = (AcceptCallingCardPacket)Pack;
  10087. #region Packet Session and User Check
  10088. if (acceptCallingCardPacket.AgentData.SessionID != SessionId ||
  10089. acceptCallingCardPacket.AgentData.AgentID != AgentId)
  10090. return true;
  10091. #endregion
  10092. // according to http://wiki.secondlife.com/wiki/AcceptCallingCard FolderData should
  10093. // contain exactly one entry
  10094. if (OnAcceptCallingCard != null && acceptCallingCardPacket.FolderData.Length > 0)
  10095. {
  10096. OnAcceptCallingCard(this,
  10097. acceptCallingCardPacket.TransactionBlock.TransactionID,
  10098. acceptCallingCardPacket.FolderData[0].FolderID);
  10099. }
  10100. return true;
  10101. }
  10102. private bool HandleDeclineCallingCard(IClientAPI sender, Packet Pack)
  10103. {
  10104. DeclineCallingCardPacket declineCallingCardPacket = (DeclineCallingCardPacket)Pack;
  10105. #region Packet Session and User Check
  10106. if (declineCallingCardPacket.AgentData.SessionID != SessionId ||
  10107. declineCallingCardPacket.AgentData.AgentID != AgentId)
  10108. return true;
  10109. #endregion
  10110. if (OnDeclineCallingCard != null)
  10111. {
  10112. OnDeclineCallingCard(this,
  10113. declineCallingCardPacket.TransactionBlock.TransactionID);
  10114. }
  10115. return true;
  10116. }
  10117. #endregion Calling Card
  10118. #region Groups
  10119. private bool HandleActivateGroup(IClientAPI sender, Packet Pack)
  10120. {
  10121. ActivateGroupPacket activateGroupPacket = (ActivateGroupPacket)Pack;
  10122. #region Packet Session and User Check
  10123. if (activateGroupPacket.AgentData.SessionID != SessionId ||
  10124. activateGroupPacket.AgentData.AgentID != AgentId)
  10125. return true;
  10126. #endregion
  10127. if (m_GroupsModule != null)
  10128. {
  10129. m_GroupsModule.ActivateGroup(this, activateGroupPacket.AgentData.GroupID);
  10130. }
  10131. return true;
  10132. }
  10133. private bool HandleGroupVoteHistoryRequest(IClientAPI client, Packet Packet)
  10134. {
  10135. GroupVoteHistoryRequestPacket GroupVoteHistoryRequest =
  10136. (GroupVoteHistoryRequestPacket)Packet;
  10137. GroupVoteHistoryRequest handlerGroupVoteHistoryRequest = OnGroupVoteHistoryRequest;
  10138. if (handlerGroupVoteHistoryRequest != null)
  10139. {
  10140. handlerGroupVoteHistoryRequest(this, GroupVoteHistoryRequest.AgentData.AgentID,GroupVoteHistoryRequest.AgentData.SessionID,GroupVoteHistoryRequest.GroupData.GroupID,GroupVoteHistoryRequest.TransactionData.TransactionID);
  10141. return true;
  10142. }
  10143. return false;
  10144. }
  10145. private bool HandleGroupActiveProposalsRequest(IClientAPI client, Packet Packet)
  10146. {
  10147. GroupActiveProposalsRequestPacket GroupActiveProposalsRequest =
  10148. (GroupActiveProposalsRequestPacket)Packet;
  10149. GroupActiveProposalsRequest handlerGroupActiveProposalsRequest = OnGroupActiveProposalsRequest;
  10150. if (handlerGroupActiveProposalsRequest != null)
  10151. {
  10152. handlerGroupActiveProposalsRequest(this, GroupActiveProposalsRequest.AgentData.AgentID,GroupActiveProposalsRequest.AgentData.SessionID,GroupActiveProposalsRequest.GroupData.GroupID,GroupActiveProposalsRequest.TransactionData.TransactionID);
  10153. return true;
  10154. }
  10155. return false;
  10156. }
  10157. private bool HandleGroupAccountDetailsRequest(IClientAPI client, Packet Packet)
  10158. {
  10159. GroupAccountDetailsRequestPacket GroupAccountDetailsRequest =
  10160. (GroupAccountDetailsRequestPacket)Packet;
  10161. GroupAccountDetailsRequest handlerGroupAccountDetailsRequest = OnGroupAccountDetailsRequest;
  10162. if (handlerGroupAccountDetailsRequest != null)
  10163. {
  10164. handlerGroupAccountDetailsRequest(this, GroupAccountDetailsRequest.AgentData.AgentID,GroupAccountDetailsRequest.AgentData.GroupID,GroupAccountDetailsRequest.MoneyData.RequestID,GroupAccountDetailsRequest.AgentData.SessionID);
  10165. return true;
  10166. }
  10167. return false;
  10168. }
  10169. private bool HandleGroupAccountSummaryRequest(IClientAPI client, Packet Packet)
  10170. {
  10171. GroupAccountSummaryRequestPacket GroupAccountSummaryRequest =
  10172. (GroupAccountSummaryRequestPacket)Packet;
  10173. GroupAccountSummaryRequest handlerGroupAccountSummaryRequest = OnGroupAccountSummaryRequest;
  10174. if (handlerGroupAccountSummaryRequest != null)
  10175. {
  10176. handlerGroupAccountSummaryRequest(this, GroupAccountSummaryRequest.AgentData.AgentID,GroupAccountSummaryRequest.AgentData.GroupID);
  10177. return true;
  10178. }
  10179. return false;
  10180. }
  10181. private bool HandleGroupTransactionsDetailsRequest(IClientAPI client, Packet Packet)
  10182. {
  10183. GroupAccountTransactionsRequestPacket GroupAccountTransactionsRequest =
  10184. (GroupAccountTransactionsRequestPacket)Packet;
  10185. GroupAccountTransactionsRequest handlerGroupAccountTransactionsRequest = OnGroupAccountTransactionsRequest;
  10186. if (handlerGroupAccountTransactionsRequest != null)
  10187. {
  10188. handlerGroupAccountTransactionsRequest(this, GroupAccountTransactionsRequest.AgentData.AgentID,GroupAccountTransactionsRequest.AgentData.GroupID,GroupAccountTransactionsRequest.MoneyData.RequestID,GroupAccountTransactionsRequest.AgentData.SessionID);
  10189. return true;
  10190. }
  10191. return false;
  10192. }
  10193. private bool HandleGroupTitlesRequest(IClientAPI sender, Packet Pack)
  10194. {
  10195. GroupTitlesRequestPacket groupTitlesRequest =
  10196. (GroupTitlesRequestPacket)Pack;
  10197. #region Packet Session and User Check
  10198. if (groupTitlesRequest.AgentData.SessionID != SessionId ||
  10199. groupTitlesRequest.AgentData.AgentID != AgentId)
  10200. return true;
  10201. #endregion
  10202. if (m_GroupsModule != null)
  10203. {
  10204. GroupTitlesReplyPacket groupTitlesReply = (GroupTitlesReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupTitlesReply);
  10205. groupTitlesReply.AgentData =
  10206. new GroupTitlesReplyPacket.AgentDataBlock();
  10207. groupTitlesReply.AgentData.AgentID = AgentId;
  10208. groupTitlesReply.AgentData.GroupID =
  10209. groupTitlesRequest.AgentData.GroupID;
  10210. groupTitlesReply.AgentData.RequestID =
  10211. groupTitlesRequest.AgentData.RequestID;
  10212. List<GroupTitlesData> titles =
  10213. m_GroupsModule.GroupTitlesRequest(this,
  10214. groupTitlesRequest.AgentData.GroupID);
  10215. groupTitlesReply.GroupData =
  10216. new GroupTitlesReplyPacket.GroupDataBlock[titles.Count];
  10217. int i = 0;
  10218. foreach (GroupTitlesData d in titles)
  10219. {
  10220. groupTitlesReply.GroupData[i] =
  10221. new GroupTitlesReplyPacket.GroupDataBlock();
  10222. groupTitlesReply.GroupData[i].Title =
  10223. Util.StringToBytes256(d.Name);
  10224. groupTitlesReply.GroupData[i].RoleID =
  10225. d.UUID;
  10226. groupTitlesReply.GroupData[i].Selected =
  10227. d.Selected;
  10228. i++;
  10229. }
  10230. OutPacket(groupTitlesReply, ThrottleOutPacketType.Task);
  10231. }
  10232. return true;
  10233. }
  10234. UUID lastGroupProfileRequestID = UUID.Zero;
  10235. double lastGroupProfileRequestTS = Util.GetTimeStampMS();
  10236. private bool HandleGroupProfileRequest(IClientAPI sender, Packet Pack)
  10237. {
  10238. if(m_GroupsModule == null)
  10239. return true;
  10240. GroupProfileRequestPacket groupProfileRequest =
  10241. (GroupProfileRequestPacket)Pack;
  10242. #region Packet Session and User Check
  10243. if (groupProfileRequest.AgentData.SessionID != SessionId ||
  10244. groupProfileRequest.AgentData.AgentID != AgentId)
  10245. return true;
  10246. #endregion
  10247. UUID grpID = groupProfileRequest.GroupData.GroupID;
  10248. double ts = Util.GetTimeStampMS();
  10249. if(grpID == lastGroupProfileRequestID && ts - lastGroupProfileRequestTS < 10000)
  10250. return true;
  10251. lastGroupProfileRequestID = grpID;
  10252. lastGroupProfileRequestTS = ts;
  10253. GroupProfileReplyPacket groupProfileReply = (GroupProfileReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupProfileReply);
  10254. groupProfileReply.AgentData = new GroupProfileReplyPacket.AgentDataBlock();
  10255. groupProfileReply.GroupData = new GroupProfileReplyPacket.GroupDataBlock();
  10256. groupProfileReply.AgentData.AgentID = AgentId;
  10257. GroupProfileData d = m_GroupsModule.GroupProfileRequest(this,
  10258. groupProfileRequest.GroupData.GroupID);
  10259. if(d.GroupID == UUID.Zero) // don't send broken data
  10260. return true;
  10261. groupProfileReply.GroupData.GroupID = d.GroupID;
  10262. groupProfileReply.GroupData.Name = Util.StringToBytes256(d.Name);
  10263. groupProfileReply.GroupData.Charter = Util.StringToBytes1024(d.Charter);
  10264. groupProfileReply.GroupData.ShowInList = d.ShowInList;
  10265. groupProfileReply.GroupData.MemberTitle = Util.StringToBytes256(d.MemberTitle);
  10266. groupProfileReply.GroupData.PowersMask = d.PowersMask;
  10267. groupProfileReply.GroupData.InsigniaID = d.InsigniaID;
  10268. groupProfileReply.GroupData.FounderID = d.FounderID;
  10269. groupProfileReply.GroupData.MembershipFee = d.MembershipFee;
  10270. groupProfileReply.GroupData.OpenEnrollment = d.OpenEnrollment;
  10271. groupProfileReply.GroupData.Money = d.Money;
  10272. groupProfileReply.GroupData.GroupMembershipCount = d.GroupMembershipCount;
  10273. groupProfileReply.GroupData.GroupRolesCount = d.GroupRolesCount;
  10274. groupProfileReply.GroupData.AllowPublish = d.AllowPublish;
  10275. groupProfileReply.GroupData.MaturePublish = d.MaturePublish;
  10276. groupProfileReply.GroupData.OwnerRole = d.OwnerRole;
  10277. Scene scene = (Scene)m_scene;
  10278. if (scene.Permissions.IsGod(sender.AgentId) && (!sender.IsGroupMember(groupProfileRequest.GroupData.GroupID)))
  10279. {
  10280. ScenePresence p;
  10281. if (scene.TryGetScenePresence(sender.AgentId, out p))
  10282. {
  10283. if (p.IsViewerUIGod)
  10284. {
  10285. groupProfileReply.GroupData.OpenEnrollment = true;
  10286. groupProfileReply.GroupData.MembershipFee = 0;
  10287. }
  10288. }
  10289. }
  10290. OutPacket(groupProfileReply, ThrottleOutPacketType.Task);
  10291. if(grpID == lastGroupProfileRequestID)
  10292. lastGroupProfileRequestTS = Util.GetTimeStampMS() - 7000;
  10293. return true;
  10294. }
  10295. private bool HandleGroupMembersRequest(IClientAPI sender, Packet Pack)
  10296. {
  10297. GroupMembersRequestPacket groupMembersRequestPacket =
  10298. (GroupMembersRequestPacket)Pack;
  10299. #region Packet Session and User Check
  10300. if (groupMembersRequestPacket.AgentData.SessionID != SessionId ||
  10301. groupMembersRequestPacket.AgentData.AgentID != AgentId)
  10302. return true;
  10303. #endregion
  10304. if (m_GroupsModule != null)
  10305. {
  10306. List<GroupMembersData> members =
  10307. m_GroupsModule.GroupMembersRequest(this, groupMembersRequestPacket.GroupData.GroupID);
  10308. int memberCount = members.Count;
  10309. int indx = 0;
  10310. while (indx < memberCount)
  10311. {
  10312. int blockCount = memberCount - indx;
  10313. if (blockCount > 25)
  10314. blockCount = 25;
  10315. GroupMembersReplyPacket groupMembersReply = (GroupMembersReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupMembersReply);
  10316. groupMembersReply.AgentData =
  10317. new GroupMembersReplyPacket.AgentDataBlock();
  10318. groupMembersReply.GroupData =
  10319. new GroupMembersReplyPacket.GroupDataBlock();
  10320. groupMembersReply.MemberData =
  10321. new GroupMembersReplyPacket.MemberDataBlock[
  10322. blockCount];
  10323. groupMembersReply.AgentData.AgentID = AgentId;
  10324. groupMembersReply.GroupData.GroupID =
  10325. groupMembersRequestPacket.GroupData.GroupID;
  10326. groupMembersReply.GroupData.RequestID =
  10327. groupMembersRequestPacket.GroupData.RequestID;
  10328. groupMembersReply.GroupData.MemberCount = memberCount;
  10329. for (int i = 0; i < blockCount; i++)
  10330. {
  10331. GroupMembersData m = members[indx++];
  10332. groupMembersReply.MemberData[i] =
  10333. new GroupMembersReplyPacket.MemberDataBlock();
  10334. groupMembersReply.MemberData[i].AgentID =
  10335. m.AgentID;
  10336. groupMembersReply.MemberData[i].Contribution =
  10337. m.Contribution;
  10338. groupMembersReply.MemberData[i].OnlineStatus =
  10339. Util.StringToBytes256(m.OnlineStatus);
  10340. groupMembersReply.MemberData[i].AgentPowers =
  10341. m.AgentPowers;
  10342. groupMembersReply.MemberData[i].Title =
  10343. Util.StringToBytes256(m.Title);
  10344. groupMembersReply.MemberData[i].IsOwner =
  10345. m.IsOwner;
  10346. }
  10347. OutPacket(groupMembersReply, ThrottleOutPacketType.Task);
  10348. }
  10349. }
  10350. return true;
  10351. }
  10352. private bool HandleGroupRoleDataRequest(IClientAPI sender, Packet Pack)
  10353. {
  10354. GroupRoleDataRequestPacket groupRolesRequest =
  10355. (GroupRoleDataRequestPacket)Pack;
  10356. #region Packet Session and User Check
  10357. if (groupRolesRequest.AgentData.SessionID != SessionId ||
  10358. groupRolesRequest.AgentData.AgentID != AgentId)
  10359. return true;
  10360. #endregion
  10361. if (m_GroupsModule != null)
  10362. {
  10363. GroupRoleDataReplyPacket groupRolesReply = (GroupRoleDataReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupRoleDataReply);
  10364. groupRolesReply.AgentData =
  10365. new GroupRoleDataReplyPacket.AgentDataBlock();
  10366. groupRolesReply.AgentData.AgentID = AgentId;
  10367. groupRolesReply.GroupData =
  10368. new GroupRoleDataReplyPacket.GroupDataBlock();
  10369. groupRolesReply.GroupData.GroupID =
  10370. groupRolesRequest.GroupData.GroupID;
  10371. groupRolesReply.GroupData.RequestID =
  10372. groupRolesRequest.GroupData.RequestID;
  10373. List<GroupRolesData> titles =
  10374. m_GroupsModule.GroupRoleDataRequest(this,
  10375. groupRolesRequest.GroupData.GroupID);
  10376. groupRolesReply.GroupData.RoleCount =
  10377. titles.Count;
  10378. groupRolesReply.RoleData =
  10379. new GroupRoleDataReplyPacket.RoleDataBlock[titles.Count];
  10380. int i = 0;
  10381. foreach (GroupRolesData d in titles)
  10382. {
  10383. groupRolesReply.RoleData[i] =
  10384. new GroupRoleDataReplyPacket.RoleDataBlock();
  10385. groupRolesReply.RoleData[i].RoleID =
  10386. d.RoleID;
  10387. groupRolesReply.RoleData[i].Name =
  10388. Util.StringToBytes256(d.Name);
  10389. groupRolesReply.RoleData[i].Title =
  10390. Util.StringToBytes256(d.Title);
  10391. groupRolesReply.RoleData[i].Description =
  10392. Util.StringToBytes1024(d.Description);
  10393. groupRolesReply.RoleData[i].Powers =
  10394. d.Powers;
  10395. groupRolesReply.RoleData[i].Members =
  10396. (uint)d.Members;
  10397. i++;
  10398. }
  10399. OutPacket(groupRolesReply, ThrottleOutPacketType.Task);
  10400. }
  10401. return true;
  10402. }
  10403. private bool HandleGroupRoleMembersRequest(IClientAPI sender, Packet Pack)
  10404. {
  10405. GroupRoleMembersRequestPacket groupRoleMembersRequest =
  10406. (GroupRoleMembersRequestPacket)Pack;
  10407. #region Packet Session and User Check
  10408. if (groupRoleMembersRequest.AgentData.SessionID != SessionId ||
  10409. groupRoleMembersRequest.AgentData.AgentID != AgentId)
  10410. return true;
  10411. #endregion
  10412. if (m_GroupsModule != null)
  10413. {
  10414. List<GroupRoleMembersData> mappings =
  10415. m_GroupsModule.GroupRoleMembersRequest(this,
  10416. groupRoleMembersRequest.GroupData.GroupID);
  10417. int mappingsCount = mappings.Count;
  10418. while (mappings.Count > 0)
  10419. {
  10420. int pairs = mappings.Count;
  10421. if (pairs > 32)
  10422. pairs = 32;
  10423. GroupRoleMembersReplyPacket groupRoleMembersReply = (GroupRoleMembersReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupRoleMembersReply);
  10424. groupRoleMembersReply.AgentData =
  10425. new GroupRoleMembersReplyPacket.AgentDataBlock();
  10426. groupRoleMembersReply.AgentData.AgentID =
  10427. AgentId;
  10428. groupRoleMembersReply.AgentData.GroupID =
  10429. groupRoleMembersRequest.GroupData.GroupID;
  10430. groupRoleMembersReply.AgentData.RequestID =
  10431. groupRoleMembersRequest.GroupData.RequestID;
  10432. groupRoleMembersReply.AgentData.TotalPairs =
  10433. (uint)mappingsCount;
  10434. groupRoleMembersReply.MemberData =
  10435. new GroupRoleMembersReplyPacket.MemberDataBlock[pairs];
  10436. for (int i = 0; i < pairs; i++)
  10437. {
  10438. GroupRoleMembersData d = mappings[0];
  10439. mappings.RemoveAt(0);
  10440. groupRoleMembersReply.MemberData[i] =
  10441. new GroupRoleMembersReplyPacket.MemberDataBlock();
  10442. groupRoleMembersReply.MemberData[i].RoleID =
  10443. d.RoleID;
  10444. groupRoleMembersReply.MemberData[i].MemberID =
  10445. d.MemberID;
  10446. }
  10447. OutPacket(groupRoleMembersReply, ThrottleOutPacketType.Task);
  10448. }
  10449. }
  10450. return true;
  10451. }
  10452. private bool HandleCreateGroupRequest(IClientAPI sender, Packet Pack)
  10453. {
  10454. CreateGroupRequestPacket createGroupRequest =
  10455. (CreateGroupRequestPacket)Pack;
  10456. #region Packet Session and User Check
  10457. if (createGroupRequest.AgentData.SessionID != SessionId ||
  10458. createGroupRequest.AgentData.AgentID != AgentId)
  10459. return true;
  10460. #endregion
  10461. if (m_GroupsModule != null)
  10462. {
  10463. m_GroupsModule.CreateGroup(this,
  10464. Utils.BytesToString(createGroupRequest.GroupData.Name),
  10465. Utils.BytesToString(createGroupRequest.GroupData.Charter),
  10466. createGroupRequest.GroupData.ShowInList,
  10467. createGroupRequest.GroupData.InsigniaID,
  10468. createGroupRequest.GroupData.MembershipFee,
  10469. createGroupRequest.GroupData.OpenEnrollment,
  10470. createGroupRequest.GroupData.AllowPublish,
  10471. createGroupRequest.GroupData.MaturePublish);
  10472. }
  10473. return true;
  10474. }
  10475. private bool HandleUpdateGroupInfo(IClientAPI sender, Packet Pack)
  10476. {
  10477. UpdateGroupInfoPacket updateGroupInfo =
  10478. (UpdateGroupInfoPacket)Pack;
  10479. #region Packet Session and User Check
  10480. if (updateGroupInfo.AgentData.SessionID != SessionId ||
  10481. updateGroupInfo.AgentData.AgentID != AgentId)
  10482. return true;
  10483. #endregion
  10484. if (m_GroupsModule != null)
  10485. {
  10486. m_GroupsModule.UpdateGroupInfo(this,
  10487. updateGroupInfo.GroupData.GroupID,
  10488. Utils.BytesToString(updateGroupInfo.GroupData.Charter),
  10489. updateGroupInfo.GroupData.ShowInList,
  10490. updateGroupInfo.GroupData.InsigniaID,
  10491. updateGroupInfo.GroupData.MembershipFee,
  10492. updateGroupInfo.GroupData.OpenEnrollment,
  10493. updateGroupInfo.GroupData.AllowPublish,
  10494. updateGroupInfo.GroupData.MaturePublish);
  10495. }
  10496. return true;
  10497. }
  10498. private bool HandleSetGroupAcceptNotices(IClientAPI sender, Packet Pack)
  10499. {
  10500. SetGroupAcceptNoticesPacket setGroupAcceptNotices =
  10501. (SetGroupAcceptNoticesPacket)Pack;
  10502. #region Packet Session and User Check
  10503. if (setGroupAcceptNotices.AgentData.SessionID != SessionId ||
  10504. setGroupAcceptNotices.AgentData.AgentID != AgentId)
  10505. return true;
  10506. #endregion
  10507. if (m_GroupsModule != null)
  10508. {
  10509. m_GroupsModule.SetGroupAcceptNotices(this,
  10510. setGroupAcceptNotices.Data.GroupID,
  10511. setGroupAcceptNotices.Data.AcceptNotices,
  10512. setGroupAcceptNotices.NewData.ListInProfile);
  10513. }
  10514. return true;
  10515. }
  10516. private bool HandleGroupTitleUpdate(IClientAPI sender, Packet Pack)
  10517. {
  10518. GroupTitleUpdatePacket groupTitleUpdate =
  10519. (GroupTitleUpdatePacket)Pack;
  10520. #region Packet Session and User Check
  10521. if (groupTitleUpdate.AgentData.SessionID != SessionId ||
  10522. groupTitleUpdate.AgentData.AgentID != AgentId)
  10523. return true;
  10524. #endregion
  10525. if (m_GroupsModule != null)
  10526. {
  10527. m_GroupsModule.GroupTitleUpdate(this,
  10528. groupTitleUpdate.AgentData.GroupID,
  10529. groupTitleUpdate.AgentData.TitleRoleID);
  10530. }
  10531. return true;
  10532. }
  10533. private bool HandleParcelDeedToGroup(IClientAPI sender, Packet Pack)
  10534. {
  10535. ParcelDeedToGroupPacket parcelDeedToGroup = (ParcelDeedToGroupPacket)Pack;
  10536. if (m_GroupsModule != null)
  10537. {
  10538. ParcelDeedToGroup handlerParcelDeedToGroup = OnParcelDeedToGroup;
  10539. if (handlerParcelDeedToGroup != null)
  10540. {
  10541. handlerParcelDeedToGroup(parcelDeedToGroup.Data.LocalID, parcelDeedToGroup.Data.GroupID, this);
  10542. }
  10543. }
  10544. return true;
  10545. }
  10546. private bool HandleGroupNoticesListRequest(IClientAPI sender, Packet Pack)
  10547. {
  10548. GroupNoticesListRequestPacket groupNoticesListRequest =
  10549. (GroupNoticesListRequestPacket)Pack;
  10550. #region Packet Session and User Check
  10551. if (groupNoticesListRequest.AgentData.SessionID != SessionId ||
  10552. groupNoticesListRequest.AgentData.AgentID != AgentId)
  10553. return true;
  10554. #endregion
  10555. if (m_GroupsModule != null)
  10556. {
  10557. GroupNoticeData[] gn =
  10558. m_GroupsModule.GroupNoticesListRequest(this,
  10559. groupNoticesListRequest.Data.GroupID);
  10560. GroupNoticesListReplyPacket groupNoticesListReply = (GroupNoticesListReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupNoticesListReply);
  10561. groupNoticesListReply.AgentData =
  10562. new GroupNoticesListReplyPacket.AgentDataBlock();
  10563. groupNoticesListReply.AgentData.AgentID = AgentId;
  10564. groupNoticesListReply.AgentData.GroupID = groupNoticesListRequest.Data.GroupID;
  10565. groupNoticesListReply.Data = new GroupNoticesListReplyPacket.DataBlock[gn.Length];
  10566. int i = 0;
  10567. foreach (GroupNoticeData g in gn)
  10568. {
  10569. groupNoticesListReply.Data[i] = new GroupNoticesListReplyPacket.DataBlock();
  10570. groupNoticesListReply.Data[i].NoticeID =
  10571. g.NoticeID;
  10572. groupNoticesListReply.Data[i].Timestamp =
  10573. g.Timestamp;
  10574. groupNoticesListReply.Data[i].FromName =
  10575. Util.StringToBytes256(g.FromName);
  10576. groupNoticesListReply.Data[i].Subject =
  10577. Util.StringToBytes256(g.Subject);
  10578. groupNoticesListReply.Data[i].HasAttachment =
  10579. g.HasAttachment;
  10580. groupNoticesListReply.Data[i].AssetType =
  10581. g.AssetType;
  10582. i++;
  10583. }
  10584. OutPacket(groupNoticesListReply, ThrottleOutPacketType.Task);
  10585. }
  10586. return true;
  10587. }
  10588. private bool HandleGroupNoticeRequest(IClientAPI sender, Packet Pack)
  10589. {
  10590. GroupNoticeRequestPacket groupNoticeRequest =
  10591. (GroupNoticeRequestPacket)Pack;
  10592. #region Packet Session and User Check
  10593. if (groupNoticeRequest.AgentData.SessionID != SessionId ||
  10594. groupNoticeRequest.AgentData.AgentID != AgentId)
  10595. return true;
  10596. #endregion
  10597. if (m_GroupsModule != null)
  10598. {
  10599. m_GroupsModule.GroupNoticeRequest(this,
  10600. groupNoticeRequest.Data.GroupNoticeID);
  10601. }
  10602. return true;
  10603. }
  10604. private bool HandleGroupRoleUpdate(IClientAPI sender, Packet Pack)
  10605. {
  10606. GroupRoleUpdatePacket groupRoleUpdate =
  10607. (GroupRoleUpdatePacket)Pack;
  10608. #region Packet Session and User Check
  10609. if (groupRoleUpdate.AgentData.SessionID != SessionId ||
  10610. groupRoleUpdate.AgentData.AgentID != AgentId)
  10611. return true;
  10612. #endregion
  10613. if (m_GroupsModule != null)
  10614. {
  10615. foreach (GroupRoleUpdatePacket.RoleDataBlock d in
  10616. groupRoleUpdate.RoleData)
  10617. {
  10618. m_GroupsModule.GroupRoleUpdate(this,
  10619. groupRoleUpdate.AgentData.GroupID,
  10620. d.RoleID,
  10621. Utils.BytesToString(d.Name),
  10622. Utils.BytesToString(d.Description),
  10623. Utils.BytesToString(d.Title),
  10624. d.Powers,
  10625. d.UpdateType);
  10626. }
  10627. m_GroupsModule.NotifyChange(groupRoleUpdate.AgentData.GroupID);
  10628. }
  10629. return true;
  10630. }
  10631. private bool HandleGroupRoleChanges(IClientAPI sender, Packet Pack)
  10632. {
  10633. GroupRoleChangesPacket groupRoleChanges =
  10634. (GroupRoleChangesPacket)Pack;
  10635. #region Packet Session and User Check
  10636. if (groupRoleChanges.AgentData.SessionID != SessionId ||
  10637. groupRoleChanges.AgentData.AgentID != AgentId)
  10638. return true;
  10639. #endregion
  10640. if (m_GroupsModule != null)
  10641. {
  10642. foreach (GroupRoleChangesPacket.RoleChangeBlock d in
  10643. groupRoleChanges.RoleChange)
  10644. {
  10645. m_GroupsModule.GroupRoleChanges(this,
  10646. groupRoleChanges.AgentData.GroupID,
  10647. d.RoleID,
  10648. d.MemberID,
  10649. d.Change);
  10650. }
  10651. m_GroupsModule.NotifyChange(groupRoleChanges.AgentData.GroupID);
  10652. }
  10653. return true;
  10654. }
  10655. private bool HandleJoinGroupRequest(IClientAPI sender, Packet Pack)
  10656. {
  10657. JoinGroupRequestPacket joinGroupRequest =
  10658. (JoinGroupRequestPacket)Pack;
  10659. #region Packet Session and User Check
  10660. if (joinGroupRequest.AgentData.SessionID != SessionId ||
  10661. joinGroupRequest.AgentData.AgentID != AgentId)
  10662. return true;
  10663. #endregion
  10664. if (m_GroupsModule != null)
  10665. {
  10666. m_GroupsModule.JoinGroupRequest(this,
  10667. joinGroupRequest.GroupData.GroupID);
  10668. }
  10669. return true;
  10670. }
  10671. private bool HandleLeaveGroupRequest(IClientAPI sender, Packet Pack)
  10672. {
  10673. LeaveGroupRequestPacket leaveGroupRequest =
  10674. (LeaveGroupRequestPacket)Pack;
  10675. #region Packet Session and User Check
  10676. if (leaveGroupRequest.AgentData.SessionID != SessionId ||
  10677. leaveGroupRequest.AgentData.AgentID != AgentId)
  10678. return true;
  10679. #endregion
  10680. if (m_GroupsModule != null)
  10681. {
  10682. m_GroupsModule.LeaveGroupRequest(this,
  10683. leaveGroupRequest.GroupData.GroupID);
  10684. }
  10685. return true;
  10686. }
  10687. private bool HandleEjectGroupMemberRequest(IClientAPI sender, Packet Pack)
  10688. {
  10689. EjectGroupMemberRequestPacket ejectGroupMemberRequest =
  10690. (EjectGroupMemberRequestPacket)Pack;
  10691. #region Packet Session and User Check
  10692. if (ejectGroupMemberRequest.AgentData.SessionID != SessionId ||
  10693. ejectGroupMemberRequest.AgentData.AgentID != AgentId)
  10694. return true;
  10695. #endregion
  10696. if (m_GroupsModule != null)
  10697. {
  10698. foreach (EjectGroupMemberRequestPacket.EjectDataBlock e
  10699. in ejectGroupMemberRequest.EjectData)
  10700. {
  10701. m_GroupsModule.EjectGroupMemberRequest(this,
  10702. ejectGroupMemberRequest.GroupData.GroupID,
  10703. e.EjecteeID);
  10704. }
  10705. }
  10706. return true;
  10707. }
  10708. private bool HandleInviteGroupRequest(IClientAPI sender, Packet Pack)
  10709. {
  10710. InviteGroupRequestPacket inviteGroupRequest =
  10711. (InviteGroupRequestPacket)Pack;
  10712. #region Packet Session and User Check
  10713. if (inviteGroupRequest.AgentData.SessionID != SessionId ||
  10714. inviteGroupRequest.AgentData.AgentID != AgentId)
  10715. return true;
  10716. #endregion
  10717. if (m_GroupsModule != null)
  10718. {
  10719. foreach (InviteGroupRequestPacket.InviteDataBlock b in
  10720. inviteGroupRequest.InviteData)
  10721. {
  10722. m_GroupsModule.InviteGroupRequest(this,
  10723. inviteGroupRequest.GroupData.GroupID,
  10724. b.InviteeID,
  10725. b.RoleID);
  10726. }
  10727. }
  10728. return true;
  10729. }
  10730. #endregion Groups
  10731. private bool HandleStartLure(IClientAPI sender, Packet Pack)
  10732. {
  10733. StartLurePacket startLureRequest = (StartLurePacket)Pack;
  10734. #region Packet Session and User Check
  10735. if (startLureRequest.AgentData.SessionID != SessionId ||
  10736. startLureRequest.AgentData.AgentID != AgentId)
  10737. return true;
  10738. #endregion
  10739. StartLure handlerStartLure = OnStartLure;
  10740. if (handlerStartLure != null)
  10741. {
  10742. for (int i = 0 ; i < startLureRequest.TargetData.Length ; i++)
  10743. {
  10744. handlerStartLure(startLureRequest.Info.LureType,
  10745. Utils.BytesToString(
  10746. startLureRequest.Info.Message),
  10747. startLureRequest.TargetData[i].TargetID,
  10748. this);
  10749. }
  10750. }
  10751. return true;
  10752. }
  10753. private bool HandleTeleportLureRequest(IClientAPI sender, Packet Pack)
  10754. {
  10755. TeleportLureRequestPacket teleportLureRequest =
  10756. (TeleportLureRequestPacket)Pack;
  10757. #region Packet Session and User Check
  10758. if (teleportLureRequest.Info.SessionID != SessionId ||
  10759. teleportLureRequest.Info.AgentID != AgentId)
  10760. return true;
  10761. #endregion
  10762. TeleportLureRequest handlerTeleportLureRequest = OnTeleportLureRequest;
  10763. if (handlerTeleportLureRequest != null)
  10764. handlerTeleportLureRequest(
  10765. teleportLureRequest.Info.LureID,
  10766. teleportLureRequest.Info.TeleportFlags,
  10767. this);
  10768. return true;
  10769. }
  10770. private bool HandleClassifiedInfoRequest(IClientAPI sender, Packet Pack)
  10771. {
  10772. ClassifiedInfoRequestPacket classifiedInfoRequest =
  10773. (ClassifiedInfoRequestPacket)Pack;
  10774. #region Packet Session and User Check
  10775. if (classifiedInfoRequest.AgentData.SessionID != SessionId ||
  10776. classifiedInfoRequest.AgentData.AgentID != AgentId)
  10777. return true;
  10778. #endregion
  10779. ClassifiedInfoRequest handlerClassifiedInfoRequest = OnClassifiedInfoRequest;
  10780. if (handlerClassifiedInfoRequest != null)
  10781. handlerClassifiedInfoRequest(
  10782. classifiedInfoRequest.Data.ClassifiedID,
  10783. this);
  10784. return true;
  10785. }
  10786. private bool HandleClassifiedInfoUpdate(IClientAPI sender, Packet Pack)
  10787. {
  10788. ClassifiedInfoUpdatePacket classifiedInfoUpdate =
  10789. (ClassifiedInfoUpdatePacket)Pack;
  10790. #region Packet Session and User Check
  10791. if (classifiedInfoUpdate.AgentData.SessionID != SessionId ||
  10792. classifiedInfoUpdate.AgentData.AgentID != AgentId)
  10793. return true;
  10794. #endregion
  10795. ClassifiedInfoUpdate handlerClassifiedInfoUpdate = OnClassifiedInfoUpdate;
  10796. if (handlerClassifiedInfoUpdate != null)
  10797. handlerClassifiedInfoUpdate(
  10798. classifiedInfoUpdate.Data.ClassifiedID,
  10799. classifiedInfoUpdate.Data.Category,
  10800. Utils.BytesToString(
  10801. classifiedInfoUpdate.Data.Name),
  10802. Utils.BytesToString(
  10803. classifiedInfoUpdate.Data.Desc),
  10804. classifiedInfoUpdate.Data.ParcelID,
  10805. classifiedInfoUpdate.Data.ParentEstate,
  10806. classifiedInfoUpdate.Data.SnapshotID,
  10807. new Vector3(
  10808. classifiedInfoUpdate.Data.PosGlobal),
  10809. classifiedInfoUpdate.Data.ClassifiedFlags,
  10810. classifiedInfoUpdate.Data.PriceForListing,
  10811. this);
  10812. return true;
  10813. }
  10814. private bool HandleClassifiedDelete(IClientAPI sender, Packet Pack)
  10815. {
  10816. ClassifiedDeletePacket classifiedDelete =
  10817. (ClassifiedDeletePacket)Pack;
  10818. #region Packet Session and User Check
  10819. if (classifiedDelete.AgentData.SessionID != SessionId ||
  10820. classifiedDelete.AgentData.AgentID != AgentId)
  10821. return true;
  10822. #endregion
  10823. ClassifiedDelete handlerClassifiedDelete = OnClassifiedDelete;
  10824. if (handlerClassifiedDelete != null)
  10825. handlerClassifiedDelete(
  10826. classifiedDelete.Data.ClassifiedID,
  10827. this);
  10828. return true;
  10829. }
  10830. private bool HandleClassifiedGodDelete(IClientAPI sender, Packet Pack)
  10831. {
  10832. ClassifiedGodDeletePacket classifiedGodDelete =
  10833. (ClassifiedGodDeletePacket)Pack;
  10834. #region Packet Session and User Check
  10835. if (classifiedGodDelete.AgentData.SessionID != SessionId ||
  10836. classifiedGodDelete.AgentData.AgentID != AgentId)
  10837. return true;
  10838. #endregion
  10839. ClassifiedGodDelete handlerClassifiedGodDelete = OnClassifiedGodDelete;
  10840. if (handlerClassifiedGodDelete != null)
  10841. handlerClassifiedGodDelete(
  10842. classifiedGodDelete.Data.ClassifiedID,
  10843. classifiedGodDelete.Data.QueryID,
  10844. this);
  10845. return true;
  10846. }
  10847. private bool HandleEventGodDelete(IClientAPI sender, Packet Pack)
  10848. {
  10849. EventGodDeletePacket eventGodDelete =
  10850. (EventGodDeletePacket)Pack;
  10851. #region Packet Session and User Check
  10852. if (eventGodDelete.AgentData.SessionID != SessionId ||
  10853. eventGodDelete.AgentData.AgentID != AgentId)
  10854. return true;
  10855. #endregion
  10856. EventGodDelete handlerEventGodDelete = OnEventGodDelete;
  10857. if (handlerEventGodDelete != null)
  10858. handlerEventGodDelete(
  10859. eventGodDelete.EventData.EventID,
  10860. eventGodDelete.QueryData.QueryID,
  10861. Utils.BytesToString(
  10862. eventGodDelete.QueryData.QueryText),
  10863. eventGodDelete.QueryData.QueryFlags,
  10864. eventGodDelete.QueryData.QueryStart,
  10865. this);
  10866. return true;
  10867. }
  10868. private bool HandleEventNotificationAddRequest(IClientAPI sender, Packet Pack)
  10869. {
  10870. EventNotificationAddRequestPacket eventNotificationAdd =
  10871. (EventNotificationAddRequestPacket)Pack;
  10872. #region Packet Session and User Check
  10873. if (eventNotificationAdd.AgentData.SessionID != SessionId ||
  10874. eventNotificationAdd.AgentData.AgentID != AgentId)
  10875. return true;
  10876. #endregion
  10877. EventNotificationAddRequest handlerEventNotificationAddRequest = OnEventNotificationAddRequest;
  10878. if (handlerEventNotificationAddRequest != null)
  10879. handlerEventNotificationAddRequest(
  10880. eventNotificationAdd.EventData.EventID, this);
  10881. return true;
  10882. }
  10883. private bool HandleEventNotificationRemoveRequest(IClientAPI sender, Packet Pack)
  10884. {
  10885. EventNotificationRemoveRequestPacket eventNotificationRemove =
  10886. (EventNotificationRemoveRequestPacket)Pack;
  10887. #region Packet Session and User Check
  10888. if (eventNotificationRemove.AgentData.SessionID != SessionId ||
  10889. eventNotificationRemove.AgentData.AgentID != AgentId)
  10890. return true;
  10891. #endregion
  10892. EventNotificationRemoveRequest handlerEventNotificationRemoveRequest = OnEventNotificationRemoveRequest;
  10893. if (handlerEventNotificationRemoveRequest != null)
  10894. handlerEventNotificationRemoveRequest(
  10895. eventNotificationRemove.EventData.EventID, this);
  10896. return true;
  10897. }
  10898. private bool HandleRetrieveInstantMessages(IClientAPI sender, Packet Pack)
  10899. {
  10900. RetrieveInstantMessagesPacket rimpInstantMessagePack = (RetrieveInstantMessagesPacket)Pack;
  10901. #region Packet Session and User Check
  10902. if (rimpInstantMessagePack.AgentData.SessionID != SessionId ||
  10903. rimpInstantMessagePack.AgentData.AgentID != AgentId)
  10904. return true;
  10905. #endregion
  10906. RetrieveInstantMessages handlerRetrieveInstantMessages = OnRetrieveInstantMessages;
  10907. if (handlerRetrieveInstantMessages != null)
  10908. handlerRetrieveInstantMessages(this);
  10909. return true;
  10910. }
  10911. private bool HandlePickDelete(IClientAPI sender, Packet Pack)
  10912. {
  10913. PickDeletePacket pickDelete =
  10914. (PickDeletePacket)Pack;
  10915. #region Packet Session and User Check
  10916. if (pickDelete.AgentData.SessionID != SessionId ||
  10917. pickDelete.AgentData.AgentID != AgentId)
  10918. return true;
  10919. #endregion
  10920. PickDelete handlerPickDelete = OnPickDelete;
  10921. if (handlerPickDelete != null)
  10922. handlerPickDelete(this, pickDelete.Data.PickID);
  10923. return true;
  10924. }
  10925. private bool HandlePickGodDelete(IClientAPI sender, Packet Pack)
  10926. {
  10927. PickGodDeletePacket pickGodDelete =
  10928. (PickGodDeletePacket)Pack;
  10929. #region Packet Session and User Check
  10930. if (pickGodDelete.AgentData.SessionID != SessionId ||
  10931. pickGodDelete.AgentData.AgentID != AgentId)
  10932. return true;
  10933. #endregion
  10934. PickGodDelete handlerPickGodDelete = OnPickGodDelete;
  10935. if (handlerPickGodDelete != null)
  10936. handlerPickGodDelete(this,
  10937. pickGodDelete.AgentData.AgentID,
  10938. pickGodDelete.Data.PickID,
  10939. pickGodDelete.Data.QueryID);
  10940. return true;
  10941. }
  10942. private bool HandlePickInfoUpdate(IClientAPI sender, Packet Pack)
  10943. {
  10944. PickInfoUpdatePacket pickInfoUpdate =
  10945. (PickInfoUpdatePacket)Pack;
  10946. #region Packet Session and User Check
  10947. if (pickInfoUpdate.AgentData.SessionID != SessionId ||
  10948. pickInfoUpdate.AgentData.AgentID != AgentId)
  10949. return true;
  10950. #endregion
  10951. PickInfoUpdate handlerPickInfoUpdate = OnPickInfoUpdate;
  10952. if (handlerPickInfoUpdate != null)
  10953. handlerPickInfoUpdate(this,
  10954. pickInfoUpdate.Data.PickID,
  10955. pickInfoUpdate.Data.CreatorID,
  10956. pickInfoUpdate.Data.TopPick,
  10957. Utils.BytesToString(pickInfoUpdate.Data.Name),
  10958. Utils.BytesToString(pickInfoUpdate.Data.Desc),
  10959. pickInfoUpdate.Data.SnapshotID,
  10960. pickInfoUpdate.Data.SortOrder,
  10961. pickInfoUpdate.Data.Enabled);
  10962. return true;
  10963. }
  10964. private bool HandleAvatarNotesUpdate(IClientAPI sender, Packet Pack)
  10965. {
  10966. AvatarNotesUpdatePacket avatarNotesUpdate =
  10967. (AvatarNotesUpdatePacket)Pack;
  10968. #region Packet Session and User Check
  10969. if (avatarNotesUpdate.AgentData.SessionID != SessionId ||
  10970. avatarNotesUpdate.AgentData.AgentID != AgentId)
  10971. return true;
  10972. #endregion
  10973. AvatarNotesUpdate handlerAvatarNotesUpdate = OnAvatarNotesUpdate;
  10974. if (handlerAvatarNotesUpdate != null)
  10975. handlerAvatarNotesUpdate(this,
  10976. avatarNotesUpdate.Data.TargetID,
  10977. Utils.BytesToString(avatarNotesUpdate.Data.Notes));
  10978. return true;
  10979. }
  10980. private bool HandleAvatarInterestsUpdate(IClientAPI sender, Packet Pack)
  10981. {
  10982. AvatarInterestsUpdatePacket avatarInterestUpdate =
  10983. (AvatarInterestsUpdatePacket)Pack;
  10984. #region Packet Session and User Check
  10985. if (avatarInterestUpdate.AgentData.SessionID != SessionId ||
  10986. avatarInterestUpdate.AgentData.AgentID != AgentId)
  10987. return true;
  10988. #endregion
  10989. AvatarInterestUpdate handlerAvatarInterestUpdate = OnAvatarInterestUpdate;
  10990. if (handlerAvatarInterestUpdate != null)
  10991. handlerAvatarInterestUpdate(this,
  10992. avatarInterestUpdate.PropertiesData.WantToMask,
  10993. Utils.BytesToString(avatarInterestUpdate.PropertiesData.WantToText),
  10994. avatarInterestUpdate.PropertiesData.SkillsMask,
  10995. Utils.BytesToString(avatarInterestUpdate.PropertiesData.SkillsText),
  10996. Utils.BytesToString(avatarInterestUpdate.PropertiesData.LanguagesText));
  10997. return true;
  10998. }
  10999. private bool HandleGrantUserRights(IClientAPI sender, Packet Pack)
  11000. {
  11001. GrantUserRightsPacket GrantUserRights =
  11002. (GrantUserRightsPacket)Pack;
  11003. #region Packet Session and User Check
  11004. if (GrantUserRights.AgentData.SessionID != SessionId ||
  11005. GrantUserRights.AgentData.AgentID != AgentId)
  11006. return true;
  11007. #endregion
  11008. GrantUserFriendRights GrantUserRightsHandler = OnGrantUserRights;
  11009. if (GrantUserRightsHandler != null)
  11010. GrantUserRightsHandler(this,
  11011. GrantUserRights.Rights[0].AgentRelated,
  11012. GrantUserRights.Rights[0].RelatedRights);
  11013. return true;
  11014. }
  11015. private bool HandleRevokePermissions(IClientAPI sender, Packet Pack)
  11016. {
  11017. RevokePermissionsPacket pkt = (RevokePermissionsPacket)Pack;
  11018. if (pkt.AgentData.SessionID != SessionId ||
  11019. pkt .AgentData.AgentID != AgentId)
  11020. return true;
  11021. // don't use multidelegate "event"
  11022. ScenePresence sp = (ScenePresence)SceneAgent;
  11023. if(sp != null && !sp.IsDeleted && !sp.IsInTransit)
  11024. {
  11025. UUID objectID = pkt.Data.ObjectID;
  11026. uint permissions = pkt.Data.ObjectPermissions;
  11027. sp.HandleRevokePermissions(objectID , permissions);
  11028. }
  11029. return true;
  11030. }
  11031. private bool HandlePlacesQuery(IClientAPI sender, Packet Pack)
  11032. {
  11033. PlacesQueryPacket placesQueryPacket =
  11034. (PlacesQueryPacket)Pack;
  11035. PlacesQuery handlerPlacesQuery = OnPlacesQuery;
  11036. if (handlerPlacesQuery != null)
  11037. handlerPlacesQuery(placesQueryPacket.AgentData.QueryID,
  11038. placesQueryPacket.TransactionData.TransactionID,
  11039. Utils.BytesToString(
  11040. placesQueryPacket.QueryData.QueryText),
  11041. placesQueryPacket.QueryData.QueryFlags,
  11042. (byte)placesQueryPacket.QueryData.Category,
  11043. Utils.BytesToString(
  11044. placesQueryPacket.QueryData.SimName),
  11045. this);
  11046. return true;
  11047. }
  11048. #endregion Packet Handlers
  11049. public void SendScriptQuestion(UUID taskID, string taskName, string ownerName, UUID itemID, int question)
  11050. {
  11051. ScriptQuestionPacket scriptQuestion = (ScriptQuestionPacket)PacketPool.Instance.GetPacket(PacketType.ScriptQuestion);
  11052. scriptQuestion.Data = new ScriptQuestionPacket.DataBlock();
  11053. // TODO: don't create new blocks if recycling an old packet
  11054. scriptQuestion.Data.TaskID = taskID;
  11055. scriptQuestion.Data.ItemID = itemID;
  11056. scriptQuestion.Data.Questions = question;
  11057. scriptQuestion.Data.ObjectName = Util.StringToBytes256(taskName);
  11058. scriptQuestion.Data.ObjectOwner = Util.StringToBytes256(ownerName);
  11059. OutPacket(scriptQuestion, ThrottleOutPacketType.Task);
  11060. }
  11061. /// <summary>
  11062. /// Handler called when we receive a logout packet.
  11063. /// </summary>
  11064. /// <param name="client"></param>
  11065. /// <param name="packet"></param>
  11066. /// <returns></returns>
  11067. protected virtual bool HandleLogout(IClientAPI client, Packet packet)
  11068. {
  11069. if (packet.Type == PacketType.LogoutRequest)
  11070. {
  11071. if (((LogoutRequestPacket)packet).AgentData.SessionID != SessionId) return false;
  11072. }
  11073. return Logout(client);
  11074. }
  11075. /// <summary>
  11076. ///
  11077. /// </summary>
  11078. /// <param name="client"></param>
  11079. /// <returns></returns>
  11080. protected virtual bool Logout(IClientAPI client)
  11081. {
  11082. m_log.InfoFormat("[CLIENT]: Got a logout request for {0} in {1}", Name, Scene.RegionInfo.RegionName);
  11083. Action<IClientAPI> handlerLogout = OnLogout;
  11084. if (handlerLogout != null)
  11085. {
  11086. handlerLogout(client);
  11087. }
  11088. return true;
  11089. }
  11090. /// <summary>
  11091. /// </summary>
  11092. /// <remarks>
  11093. /// At the moment, we always reply that there is no cached texture.
  11094. /// </remarks>
  11095. /// <param name="simclient"></param>
  11096. /// <param name="packet"></param>
  11097. /// <returns></returns>
  11098. protected bool HandleAgentTextureCached(IClientAPI simclient, Packet packet)
  11099. {
  11100. //m_log.Debug("texture cached: " + packet.ToString());
  11101. AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet;
  11102. AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
  11103. if (cachedtex.AgentData.SessionID != SessionId)
  11104. return false;
  11105. // TODO: don't create new blocks if recycling an old packet
  11106. cachedresp.AgentData.AgentID = AgentId;
  11107. cachedresp.AgentData.SessionID = m_sessionId;
  11108. cachedresp.AgentData.SerialNum = cachedtex.AgentData.SerialNum;
  11109. cachedresp.WearableData =
  11110. new AgentCachedTextureResponsePacket.WearableDataBlock[cachedtex.WearableData.Length];
  11111. int cacheHits = 0;
  11112. // We need to make sure the asset stored in the bake is available on this server also by it's assetid before we map it to a Cacheid
  11113. WearableCacheItem[] cacheItems = null;
  11114. ScenePresence p = m_scene.GetScenePresence(AgentId);
  11115. if (p != null && p.Appearance != null)
  11116. {
  11117. cacheItems = p.Appearance.WearableCacheItems;
  11118. }
  11119. int maxWearablesLoop = cachedtex.WearableData.Length;
  11120. if (cacheItems != null)
  11121. {
  11122. if (maxWearablesLoop > cacheItems.Length)
  11123. maxWearablesLoop = cacheItems.Length;
  11124. for (int i = 0; i < maxWearablesLoop; i++)
  11125. {
  11126. int idx = cachedtex.WearableData[i].TextureIndex;
  11127. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  11128. cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
  11129. cachedresp.WearableData[i].HostName = new byte[0];
  11130. if (cachedtex.WearableData[i].ID == cacheItems[idx].CacheId)
  11131. {
  11132. cachedresp.WearableData[i].TextureID = cacheItems[idx].TextureID;
  11133. cacheHits++;
  11134. }
  11135. else
  11136. {
  11137. cachedresp.WearableData[i].TextureID = UUID.Zero;
  11138. }
  11139. }
  11140. }
  11141. else
  11142. {
  11143. for (int i = 0; i < maxWearablesLoop; i++)
  11144. {
  11145. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  11146. cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
  11147. cachedresp.WearableData[i].TextureID = UUID.Zero;
  11148. cachedresp.WearableData[i].HostName = new byte[0];
  11149. }
  11150. }
  11151. //m_log.DebugFormat("texture cached: hits {0}", cacheHits);
  11152. cachedresp.Header.Zerocoded = true;
  11153. OutPacket(cachedresp, ThrottleOutPacketType.Task);
  11154. return true;
  11155. }
  11156. /// <summary>
  11157. /// Send a response back to a client when it asks the asset server (via the region server) if it has
  11158. /// its appearance texture cached.
  11159. /// </summary>
  11160. /// <param name="avatar"></param>
  11161. /// <param name="serial"></param>
  11162. /// <param name="cachedTextures"></param>
  11163. /// <returns></returns>
  11164. public void SendCachedTextureResponse(ISceneEntity avatar, int serial, List<CachedTextureResponseArg> cachedTextures)
  11165. {
  11166. ScenePresence presence = avatar as ScenePresence;
  11167. if (presence == null)
  11168. return;
  11169. AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
  11170. // TODO: don't create new blocks if recycling an old packet
  11171. cachedresp.AgentData.AgentID = m_agentId;
  11172. cachedresp.AgentData.SessionID = m_sessionId;
  11173. cachedresp.AgentData.SerialNum = serial;
  11174. cachedresp.WearableData = new AgentCachedTextureResponsePacket.WearableDataBlock[cachedTextures.Count];
  11175. for (int i = 0; i < cachedTextures.Count; i++)
  11176. {
  11177. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  11178. cachedresp.WearableData[i].TextureIndex = (byte)cachedTextures[i].BakedTextureIndex;
  11179. cachedresp.WearableData[i].TextureID = cachedTextures[i].BakedTextureID;
  11180. cachedresp.WearableData[i].HostName = new byte[0];
  11181. }
  11182. cachedresp.Header.Zerocoded = true;
  11183. OutPacket(cachedresp, ThrottleOutPacketType.Task);
  11184. }
  11185. protected bool HandleMultipleObjUpdate(IClientAPI simClient, Packet packet)
  11186. {
  11187. MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
  11188. if (multipleupdate.AgentData.SessionID != SessionId)
  11189. return false;
  11190. // m_log.DebugFormat(
  11191. // "[CLIENT]: Incoming MultipleObjectUpdatePacket contained {0} blocks", multipleupdate.ObjectData.Length);
  11192. Scene tScene = (Scene)m_scene;
  11193. for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
  11194. {
  11195. MultipleObjectUpdatePacket.ObjectDataBlock block = multipleupdate.ObjectData[i];
  11196. // Can't act on Null Data
  11197. if (block.Data != null)
  11198. {
  11199. uint localId = block.ObjectLocalID;
  11200. SceneObjectPart part = tScene.GetSceneObjectPart(localId);
  11201. if (part == null)
  11202. {
  11203. // It's a ghost! tell the client to delete it from view.
  11204. simClient.SendKillObject(new List<uint> { localId });
  11205. }
  11206. else
  11207. {
  11208. ClientChangeObject updatehandler = onClientChangeObject;
  11209. if (updatehandler != null)
  11210. {
  11211. ObjectChangeData udata = new ObjectChangeData();
  11212. /*ubit from ll JIRA:
  11213. * 0x01 position
  11214. * 0x02 rotation
  11215. * 0x04 scale
  11216. * 0x08 LINK_SET
  11217. * 0x10 UNIFORM for scale
  11218. */
  11219. // translate to internal changes
  11220. // not all cases .. just the ones older code did
  11221. switch (block.Type)
  11222. {
  11223. case 1: //change position sp
  11224. udata.position = new Vector3(block.Data, 0);
  11225. udata.change = ObjectChangeType.primP;
  11226. updatehandler(localId, udata, this);
  11227. break;
  11228. case 2: // rotation sp
  11229. udata.rotation = new Quaternion(block.Data, 0, true);
  11230. udata.change = ObjectChangeType.primR;
  11231. updatehandler(localId, udata, this);
  11232. break;
  11233. case 3: // position plus rotation
  11234. udata.position = new Vector3(block.Data, 0);
  11235. udata.rotation = new Quaternion(block.Data, 12, true);
  11236. udata.change = ObjectChangeType.primPR;
  11237. updatehandler(localId, udata, this);
  11238. break;
  11239. case 4: // scale sp
  11240. udata.scale = new Vector3(block.Data, 0);
  11241. udata.change = ObjectChangeType.primS;
  11242. updatehandler(localId, udata, this);
  11243. break;
  11244. case 0x14: // uniform scale sp
  11245. udata.scale = new Vector3(block.Data, 0);
  11246. udata.change = ObjectChangeType.primUS;
  11247. updatehandler(localId, udata, this);
  11248. break;
  11249. case 5: // scale and position sp
  11250. udata.position = new Vector3(block.Data, 0);
  11251. udata.scale = new Vector3(block.Data, 12);
  11252. udata.change = ObjectChangeType.primPS;
  11253. updatehandler(localId, udata, this);
  11254. break;
  11255. case 0x15: //uniform scale and position
  11256. udata.position = new Vector3(block.Data, 0);
  11257. udata.scale = new Vector3(block.Data, 12);
  11258. udata.change = ObjectChangeType.primPUS;
  11259. updatehandler(localId, udata, this);
  11260. break;
  11261. // now group related (bit 4)
  11262. case 9: //( 8 + 1 )group position
  11263. udata.position = new Vector3(block.Data, 0);
  11264. udata.change = ObjectChangeType.groupP;
  11265. updatehandler(localId, udata, this);
  11266. break;
  11267. case 0x0A: // (8 + 2) group rotation
  11268. udata.rotation = new Quaternion(block.Data, 0, true);
  11269. udata.change = ObjectChangeType.groupR;
  11270. updatehandler(localId, udata, this);
  11271. break;
  11272. case 0x0B: //( 8 + 2 + 1) group rotation and position
  11273. udata.position = new Vector3(block.Data, 0);
  11274. udata.rotation = new Quaternion(block.Data, 12, true);
  11275. udata.change = ObjectChangeType.groupPR;
  11276. updatehandler(localId, udata, this);
  11277. break;
  11278. case 0x0C: // (8 + 4) group scale
  11279. // only afects root prim and only sent by viewer editor object tab scaling
  11280. // mouse edition only allows uniform scaling
  11281. // SL MAY CHANGE THIS in viewers
  11282. udata.scale = new Vector3(block.Data, 0);
  11283. udata.change = ObjectChangeType.groupS;
  11284. updatehandler(localId, udata, this);
  11285. break;
  11286. case 0x0D: //(8 + 4 + 1) group scale and position
  11287. // exception as above
  11288. udata.position = new Vector3(block.Data, 0);
  11289. udata.scale = new Vector3(block.Data, 12);
  11290. udata.change = ObjectChangeType.groupPS;
  11291. updatehandler(localId, udata, this);
  11292. break;
  11293. case 0x1C: // (0x10 + 8 + 4 ) group scale UNIFORM
  11294. udata.scale = new Vector3(block.Data, 0);
  11295. udata.change = ObjectChangeType.groupUS;
  11296. updatehandler(localId, udata, this);
  11297. break;
  11298. case 0x1D: // (UNIFORM + GROUP + SCALE + POS)
  11299. udata.position = new Vector3(block.Data, 0);
  11300. udata.scale = new Vector3(block.Data, 12);
  11301. udata.change = ObjectChangeType.groupPUS;
  11302. updatehandler(localId, udata, this);
  11303. break;
  11304. default:
  11305. m_log.Debug("[CLIENT]: MultipleObjUpdate recieved an unknown packet type: " + (block.Type));
  11306. break;
  11307. }
  11308. }
  11309. }
  11310. }
  11311. }
  11312. return true;
  11313. }
  11314. public void RequestMapLayer()
  11315. {
  11316. //should be getting the map layer from the grid server
  11317. //send a layer covering the 800,800 - 1200,1200 area (should be covering the requested area)
  11318. MapLayerReplyPacket mapReply = (MapLayerReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapLayerReply);
  11319. // TODO: don't create new blocks if recycling an old packet
  11320. mapReply.AgentData.AgentID = AgentId;
  11321. mapReply.AgentData.Flags = 0;
  11322. mapReply.LayerData = new MapLayerReplyPacket.LayerDataBlock[1];
  11323. mapReply.LayerData[0] = new MapLayerReplyPacket.LayerDataBlock();
  11324. mapReply.LayerData[0].Bottom = 0;
  11325. mapReply.LayerData[0].Left = 0;
  11326. mapReply.LayerData[0].Top = 30000;
  11327. mapReply.LayerData[0].Right = 30000;
  11328. mapReply.LayerData[0].ImageID = new UUID("00000000-0000-1111-9999-000000000006");
  11329. mapReply.Header.Zerocoded = true;
  11330. OutPacket(mapReply, ThrottleOutPacketType.Land);
  11331. }
  11332. public void RequestMapBlocksX(int minX, int minY, int maxX, int maxY)
  11333. {
  11334. /*
  11335. IList simMapProfiles = m_gridServer.RequestMapBlocks(minX, minY, maxX, maxY);
  11336. MapBlockReplyPacket mbReply = new MapBlockReplyPacket();
  11337. mbReply.AgentData.AgentId = AgentId;
  11338. int len;
  11339. if (simMapProfiles == null)
  11340. len = 0;
  11341. else
  11342. len = simMapProfiles.Count;
  11343. mbReply.Data = new MapBlockReplyPacket.DataBlock[len];
  11344. int iii;
  11345. for (iii = 0; iii < len; iii++)
  11346. {
  11347. Hashtable mp = (Hashtable)simMapProfiles[iii];
  11348. mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock();
  11349. mbReply.Data[iii].Name = Util.UTF8.GetBytes((string)mp["name"]);
  11350. mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]);
  11351. mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]);
  11352. mbReply.Data[iii].MapImageID = new UUID((string)mp["map-image-id"]);
  11353. mbReply.Data[iii].RegionFlags = System.Convert.ToUInt32(mp["region-flags"]);
  11354. mbReply.Data[iii].WaterHeight = System.Convert.ToByte(mp["water-height"]);
  11355. mbReply.Data[iii].X = System.Convert.ToUInt16(mp["x"]);
  11356. mbReply.Data[iii].Y = System.Convert.ToUInt16(mp["y"]);
  11357. }
  11358. this.OutPacket(mbReply, ThrottleOutPacketType.Land);
  11359. */
  11360. }
  11361. /// <summary>
  11362. /// Sets the throttles from values supplied by the client
  11363. /// </summary>
  11364. /// <param name="throttles"></param>
  11365. public void SetChildAgentThrottle(byte[] throttles)
  11366. {
  11367. SetChildAgentThrottle(throttles, 1.0f);
  11368. }
  11369. public void SetChildAgentThrottle(byte[] throttles,float factor)
  11370. {
  11371. m_udpClient.SetThrottles(throttles, factor);
  11372. GenericCall2 handler = OnUpdateThrottles;
  11373. if (handler != null)
  11374. {
  11375. handler();
  11376. }
  11377. }
  11378. /// <summary>
  11379. /// Sets the throttles from values supplied caller
  11380. /// </summary>
  11381. /// <param name="throttles"></param>
  11382. public void SetAgentThrottleSilent(int throttle, int setting)
  11383. {
  11384. m_udpClient.ForceThrottleSetting(throttle,setting);
  11385. }
  11386. public int GetAgentThrottleSilent(int throttle)
  11387. {
  11388. return m_udpClient.GetThrottleSetting(throttle);
  11389. }
  11390. /// <summary>
  11391. /// Get the current throttles for this client as a packed byte array
  11392. /// </summary>
  11393. /// <param name="multiplier">Unused</param>
  11394. /// <returns></returns>
  11395. public byte[] GetThrottlesPacked(float multiplier)
  11396. {
  11397. return m_udpClient.GetThrottlesPacked(multiplier);
  11398. }
  11399. /// <summary>
  11400. /// Cruft?
  11401. /// </summary>
  11402. public virtual void InPacket(object NewPack)
  11403. {
  11404. throw new NotImplementedException();
  11405. }
  11406. /// <summary>
  11407. /// This is the starting point for sending a simulator packet out to the client
  11408. /// </summary>
  11409. /// <param name="packet">Packet to send</param>
  11410. /// <param name="throttlePacketType">Throttling category for the packet</param>
  11411. protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType)
  11412. {
  11413. #region BinaryStats
  11414. LLUDPServer.LogPacketHeader(false, m_circuitCode, 0, packet.Type, (ushort)packet.Length);
  11415. #endregion BinaryStats
  11416. OutPacket(packet, throttlePacketType, true);
  11417. }
  11418. /// <summary>
  11419. /// This is the starting point for sending a simulator packet out to the client
  11420. /// </summary>
  11421. /// <param name="packet">Packet to send</param>
  11422. /// <param name="throttlePacketType">Throttling category for the packet</param>
  11423. /// <param name="doAutomaticSplitting">True to automatically split oversized
  11424. /// packets (the default), or false to disable splitting if the calling code
  11425. /// handles splitting manually</param>
  11426. protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting)
  11427. {
  11428. OutPacket(packet, throttlePacketType, doAutomaticSplitting, null);
  11429. }
  11430. /// <summary>
  11431. /// This is the starting point for sending a simulator packet out to the client
  11432. /// </summary>
  11433. /// <param name="packet">Packet to send</param>
  11434. /// <param name="throttlePacketType">Throttling category for the packet</param>
  11435. /// <param name="doAutomaticSplitting">True to automatically split oversized
  11436. /// packets (the default), or false to disable splitting if the calling code
  11437. /// handles splitting manually</param>
  11438. /// <param name="method">The method to be called in the event this packet is reliable
  11439. /// and unacknowledged. The server will provide normal resend capability if you do not
  11440. /// provide your own method.</param>
  11441. protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting, UnackedPacketMethod method)
  11442. {
  11443. if (m_outPacketsToDrop != null)
  11444. {
  11445. if (m_outPacketsToDrop.Contains(packet.Type.ToString()))
  11446. {
  11447. PacketPool.Instance.ReturnPacket(packet);
  11448. return;
  11449. }
  11450. }
  11451. if (DebugPacketLevel > 0)
  11452. {
  11453. bool logPacket = true;
  11454. if (DebugPacketLevel <= 255
  11455. && (packet.Type == PacketType.SimStats || packet.Type == PacketType.SimulatorViewerTimeMessage))
  11456. logPacket = false;
  11457. if (DebugPacketLevel <= 200
  11458. && (packet.Type == PacketType.ImagePacket
  11459. || packet.Type == PacketType.ImageData
  11460. || packet.Type == PacketType.LayerData
  11461. || packet.Type == PacketType.CoarseLocationUpdate))
  11462. logPacket = false;
  11463. if (DebugPacketLevel <= 100 && (packet.Type == PacketType.AvatarAnimation || packet.Type == PacketType.ViewerEffect))
  11464. logPacket = false;
  11465. if (DebugPacketLevel <= 50
  11466. && (packet.Type == PacketType.ImprovedTerseObjectUpdate || packet.Type == PacketType.ObjectUpdate))
  11467. logPacket = false;
  11468. if (DebugPacketLevel <= 25 && packet.Type == PacketType.ObjectPropertiesFamily)
  11469. logPacket = false;
  11470. if (logPacket)
  11471. m_log.DebugFormat(
  11472. "[CLIENT]: PACKET OUT to {0} ({1}) in {2} - {3}",
  11473. Name, SceneAgent.IsChildAgent ? "child" : "root ", m_scene.RegionInfo.RegionName, packet.Type);
  11474. }
  11475. m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, doAutomaticSplitting, method);
  11476. }
  11477. protected void HandleAutopilot(Object sender, string method, List<String> args)
  11478. {
  11479. float locx = 0;
  11480. float locy = 0;
  11481. float locz = 0;
  11482. uint regionX = 0;
  11483. uint regionY = 0;
  11484. Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out regionX, out regionY);
  11485. locx = (float)(Convert.ToDouble(args[0]) - (double)regionX);
  11486. locy = (float)(Convert.ToDouble(args[1]) - (double)regionY);
  11487. locz = Convert.ToSingle(args[2]);
  11488. Action<Vector3, bool, bool> handlerAutoPilotGo = OnAutoPilotGo;
  11489. if (handlerAutoPilotGo != null)
  11490. handlerAutoPilotGo(new Vector3(locx, locy, locz), false, false);
  11491. }
  11492. /// <summary>
  11493. /// Entryway from the client to the simulator. All UDP packets from the client will end up here
  11494. /// </summary>
  11495. /// <param name="Pack">OpenMetaverse.packet</param>
  11496. public void ProcessInPacket(Packet packet)
  11497. {
  11498. if (m_inPacketsToDrop != null)
  11499. if (m_inPacketsToDrop.Contains(packet.Type.ToString()))
  11500. return;
  11501. if (DebugPacketLevel > 0)
  11502. {
  11503. bool logPacket = true;
  11504. if (DebugPacketLevel <= 255 && packet.Type == PacketType.AgentUpdate)
  11505. logPacket = false;
  11506. if (DebugPacketLevel <= 200 && packet.Type == PacketType.RequestImage)
  11507. logPacket = false;
  11508. if (DebugPacketLevel <= 100 && (packet.Type == PacketType.ViewerEffect || packet.Type == PacketType.AgentAnimation))
  11509. logPacket = false;
  11510. if (DebugPacketLevel <= 25 && packet.Type == PacketType.RequestObjectPropertiesFamily)
  11511. logPacket = false;
  11512. if (logPacket)
  11513. m_log.DebugFormat(
  11514. "[CLIENT]: PACKET IN from {0} ({1}) in {2} - {3}",
  11515. Name, SceneAgent.IsChildAgent ? "child" : "root ", Scene.Name, packet.Type);
  11516. }
  11517. if (!ProcessPacketMethod(packet))
  11518. m_log.WarnFormat(
  11519. "[CLIENT]: Unhandled packet {0} from {1} ({2}) in {3}. Ignoring.",
  11520. packet.Type, Name, SceneAgent.IsChildAgent ? "child" : "root ", Scene.Name);
  11521. }
  11522. private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)
  11523. {
  11524. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  11525. shape.PCode = addPacket.ObjectData.PCode;
  11526. shape.State = addPacket.ObjectData.State;
  11527. shape.LastAttachPoint = addPacket.ObjectData.State;
  11528. shape.PathBegin = addPacket.ObjectData.PathBegin;
  11529. shape.PathEnd = addPacket.ObjectData.PathEnd;
  11530. shape.PathScaleX = addPacket.ObjectData.PathScaleX;
  11531. shape.PathScaleY = addPacket.ObjectData.PathScaleY;
  11532. shape.PathShearX = addPacket.ObjectData.PathShearX;
  11533. shape.PathShearY = addPacket.ObjectData.PathShearY;
  11534. shape.PathSkew = addPacket.ObjectData.PathSkew;
  11535. shape.ProfileBegin = addPacket.ObjectData.ProfileBegin;
  11536. shape.ProfileEnd = addPacket.ObjectData.ProfileEnd;
  11537. shape.Scale = addPacket.ObjectData.Scale;
  11538. shape.PathCurve = addPacket.ObjectData.PathCurve;
  11539. shape.ProfileCurve = addPacket.ObjectData.ProfileCurve;
  11540. shape.ProfileHollow = addPacket.ObjectData.ProfileHollow;
  11541. shape.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
  11542. shape.PathRevolutions = addPacket.ObjectData.PathRevolutions;
  11543. shape.PathTaperX = addPacket.ObjectData.PathTaperX;
  11544. shape.PathTaperY = addPacket.ObjectData.PathTaperY;
  11545. shape.PathTwist = addPacket.ObjectData.PathTwist;
  11546. shape.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
  11547. Primitive.TextureEntry ntex = new Primitive.TextureEntry(new UUID("89556747-24cb-43ed-920b-47caed15465f"));
  11548. shape.TextureEntry = ntex.GetBytes();
  11549. //shape.Textures = ntex;
  11550. return shape;
  11551. }
  11552. public ClientInfo GetClientInfo()
  11553. {
  11554. ClientInfo info = m_udpClient.GetClientInfo();
  11555. info.proxyEP = null;
  11556. if (info.agentcircuit == null)
  11557. info.agentcircuit = RequestClientInfo();
  11558. return info;
  11559. }
  11560. public void SetClientInfo(ClientInfo info)
  11561. {
  11562. m_udpClient.SetClientInfo(info);
  11563. }
  11564. #region Media Parcel Members
  11565. public void SendParcelMediaCommand(uint flags, ParcelMediaCommandEnum command, float time)
  11566. {
  11567. ParcelMediaCommandMessagePacket commandMessagePacket = new ParcelMediaCommandMessagePacket();
  11568. commandMessagePacket.CommandBlock.Flags = flags;
  11569. commandMessagePacket.CommandBlock.Command = (uint)command;
  11570. commandMessagePacket.CommandBlock.Time = time;
  11571. OutPacket(commandMessagePacket, ThrottleOutPacketType.Task);
  11572. }
  11573. public void SendParcelMediaUpdate(string mediaUrl, UUID mediaTextureID,
  11574. byte autoScale, string mediaType, string mediaDesc, int mediaWidth, int mediaHeight,
  11575. byte mediaLoop)
  11576. {
  11577. ParcelMediaUpdatePacket updatePacket = new ParcelMediaUpdatePacket();
  11578. updatePacket.DataBlock.MediaURL = Util.StringToBytes256(mediaUrl);
  11579. updatePacket.DataBlock.MediaID = mediaTextureID;
  11580. updatePacket.DataBlock.MediaAutoScale = autoScale;
  11581. updatePacket.DataBlockExtended.MediaType = Util.StringToBytes256(mediaType);
  11582. updatePacket.DataBlockExtended.MediaDesc = Util.StringToBytes256(mediaDesc);
  11583. updatePacket.DataBlockExtended.MediaWidth = mediaWidth;
  11584. updatePacket.DataBlockExtended.MediaHeight = mediaHeight;
  11585. updatePacket.DataBlockExtended.MediaLoop = mediaLoop;
  11586. OutPacket(updatePacket, ThrottleOutPacketType.Task);
  11587. }
  11588. #endregion
  11589. #region Camera
  11590. public void SendSetFollowCamProperties(UUID objectID, SortedDictionary<int, float> parameters)
  11591. {
  11592. SetFollowCamPropertiesPacket packet = (SetFollowCamPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.SetFollowCamProperties);
  11593. packet.ObjectData.ObjectID = objectID;
  11594. SetFollowCamPropertiesPacket.CameraPropertyBlock[] camPropBlock = new SetFollowCamPropertiesPacket.CameraPropertyBlock[parameters.Count];
  11595. uint idx = 0;
  11596. foreach (KeyValuePair<int, float> pair in parameters)
  11597. {
  11598. SetFollowCamPropertiesPacket.CameraPropertyBlock block = new SetFollowCamPropertiesPacket.CameraPropertyBlock();
  11599. block.Type = pair.Key;
  11600. block.Value = pair.Value;
  11601. camPropBlock[idx++] = block;
  11602. }
  11603. packet.CameraProperty = camPropBlock;
  11604. OutPacket(packet, ThrottleOutPacketType.Task);
  11605. }
  11606. public void SendClearFollowCamProperties(UUID objectID)
  11607. {
  11608. ClearFollowCamPropertiesPacket packet = (ClearFollowCamPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ClearFollowCamProperties);
  11609. packet.ObjectData.ObjectID = objectID;
  11610. OutPacket(packet, ThrottleOutPacketType.Task);
  11611. }
  11612. #endregion
  11613. public void SetClientOption(string option, string value)
  11614. {
  11615. switch (option)
  11616. {
  11617. default:
  11618. break;
  11619. }
  11620. }
  11621. public string GetClientOption(string option)
  11622. {
  11623. switch (option)
  11624. {
  11625. default:
  11626. break;
  11627. }
  11628. return string.Empty;
  11629. }
  11630. #region IClientCore
  11631. private readonly Dictionary<Type, object> m_clientInterfaces = new Dictionary<Type, object>();
  11632. /// <summary>
  11633. /// Register an interface on this client, should only be called in the constructor.
  11634. /// </summary>
  11635. /// <typeparam name="T"></typeparam>
  11636. /// <param name="iface"></param>
  11637. protected void RegisterInterface<T>(T iface)
  11638. {
  11639. lock (m_clientInterfaces)
  11640. {
  11641. if (!m_clientInterfaces.ContainsKey(typeof(T)))
  11642. {
  11643. m_clientInterfaces.Add(typeof(T), iface);
  11644. }
  11645. }
  11646. }
  11647. public bool TryGet<T>(out T iface)
  11648. {
  11649. if (m_clientInterfaces.ContainsKey(typeof(T)))
  11650. {
  11651. iface = (T)m_clientInterfaces[typeof(T)];
  11652. return true;
  11653. }
  11654. iface = default(T);
  11655. return false;
  11656. }
  11657. public T Get<T>()
  11658. {
  11659. return (T)m_clientInterfaces[typeof(T)];
  11660. }
  11661. public void Disconnect(string reason)
  11662. {
  11663. Kick(reason);
  11664. Thread.Sleep(1000);
  11665. Disconnect();
  11666. }
  11667. public void Disconnect()
  11668. {
  11669. Close();
  11670. }
  11671. #endregion
  11672. public void RefreshGroupMembership()
  11673. {
  11674. lock(m_groupPowers)
  11675. {
  11676. GroupMembershipData activeMembership = null;
  11677. if (m_GroupsModule != null)
  11678. {
  11679. GroupMembershipData[] GroupMembership =
  11680. m_GroupsModule.GetMembershipData(AgentId);
  11681. m_groupPowers.Clear();
  11682. if (GroupMembership != null)
  11683. {
  11684. for (int i = 0; i < GroupMembership.Length; i++)
  11685. {
  11686. m_groupPowers[GroupMembership[i].GroupID] = GroupMembership[i].GroupPowers;
  11687. }
  11688. }
  11689. activeMembership = m_GroupsModule.GetActiveMembershipData(AgentId);
  11690. if(activeMembership != null)
  11691. {
  11692. if(!m_groupPowers.ContainsKey(activeMembership.GroupID))
  11693. activeMembership = null;
  11694. else
  11695. {
  11696. m_activeGroupID = activeMembership.GroupID;
  11697. m_activeGroupName = activeMembership.GroupName;
  11698. m_activeGroupPowers = ActiveGroupPowers;
  11699. }
  11700. }
  11701. }
  11702. if(activeMembership == null)
  11703. {
  11704. m_activeGroupID = UUID.Zero;
  11705. m_activeGroupName = "";
  11706. m_activeGroupPowers = 0;
  11707. }
  11708. }
  11709. }
  11710. public void UpdateGroupMembership(GroupMembershipData[] data)
  11711. {
  11712. lock(m_groupPowers)
  11713. {
  11714. m_groupPowers.Clear();
  11715. if (data != null)
  11716. {
  11717. for (int i = 0; i < data.Length; i++)
  11718. m_groupPowers[data[i].GroupID] = data[i].GroupPowers;
  11719. }
  11720. }
  11721. }
  11722. public void GroupMembershipRemove(UUID GroupID)
  11723. {
  11724. lock(m_groupPowers)
  11725. {
  11726. if(m_groupPowers.ContainsKey(GroupID))
  11727. m_groupPowers.Remove(GroupID);
  11728. }
  11729. }
  11730. public void GroupMembershipAddReplace(UUID GroupID,ulong GroupPowers)
  11731. {
  11732. lock(m_groupPowers)
  11733. {
  11734. m_groupPowers[GroupID] = GroupPowers;
  11735. }
  11736. }
  11737. public string Report()
  11738. {
  11739. return m_udpClient.GetStats();
  11740. }
  11741. public string XReport(string uptime, string version)
  11742. {
  11743. return String.Empty;
  11744. }
  11745. public OSDMap OReport(string uptime, string version)
  11746. {
  11747. return new OSDMap();
  11748. }
  11749. /// <summary>
  11750. /// Make an asset request to the asset service in response to a client request.
  11751. /// </summary>
  11752. /// <param name="transferRequest"></param>
  11753. /// <param name="taskID"></param>
  11754. protected void MakeAssetRequest(TransferRequestPacket transferRequest, UUID taskID)
  11755. {
  11756. UUID requestID = UUID.Zero;
  11757. int sourceType = transferRequest.TransferInfo.SourceType;
  11758. if (sourceType == (int)SourceType.Asset)
  11759. {
  11760. requestID = new UUID(transferRequest.TransferInfo.Params, 0);
  11761. }
  11762. else if (sourceType == (int)SourceType.SimInventoryItem)
  11763. {
  11764. requestID = new UUID(transferRequest.TransferInfo.Params, 80);
  11765. }
  11766. else if (sourceType == (int)SourceType.SimEstate)
  11767. {
  11768. requestID = taskID;
  11769. }
  11770. // m_log.DebugFormat(
  11771. // "[LLCLIENTVIEW]: Received transfer request for {0} in {1} type {2} by {3}",
  11772. // requestID, taskID, (SourceType)sourceType, Name);
  11773. //Note, the bool returned from the below function is useless since it is always false.
  11774. m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived);
  11775. }
  11776. /// <summary>
  11777. /// When we get a reply back from the asset service in response to a client request, send back the data.
  11778. /// </summary>
  11779. /// <param name="id"></param>
  11780. /// <param name="sender"></param>
  11781. /// <param name="asset"></param>
  11782. protected void AssetReceived(string id, Object sender, AssetBase asset)
  11783. {
  11784. TransferRequestPacket transferRequest = (TransferRequestPacket)sender;
  11785. UUID requestID = UUID.Zero;
  11786. byte source = (byte)SourceType.Asset;
  11787. AssetRequestToClient req = new AssetRequestToClient();
  11788. if (asset == null)
  11789. {
  11790. // Try the user's asset server
  11791. IInventoryAccessModule inventoryAccessModule = Scene.RequestModuleInterface<IInventoryAccessModule>();
  11792. string assetServerURL = string.Empty;
  11793. if (inventoryAccessModule.IsForeignUser(AgentId, out assetServerURL) && !string.IsNullOrEmpty(assetServerURL))
  11794. {
  11795. if (!assetServerURL.EndsWith("/") && !assetServerURL.EndsWith("="))
  11796. assetServerURL = assetServerURL + "/";
  11797. //m_log.DebugFormat("[LLCLIENTVIEW]: asset {0} not found in local storage. Trying user's storage.", assetServerURL + id);
  11798. asset = m_scene.AssetService.Get(assetServerURL + id);
  11799. }
  11800. if (asset == null)
  11801. {
  11802. req.AssetInf = null;
  11803. req.AssetRequestSource = source;
  11804. req.IsTextureRequest = false;
  11805. req.NumPackets = 0;
  11806. req.Params = transferRequest.TransferInfo.Params;
  11807. req.RequestAssetID = requestID;
  11808. req.TransferRequestID = transferRequest.TransferInfo.TransferID;
  11809. SendAssetNotFound(req);
  11810. return;
  11811. }
  11812. }
  11813. if (transferRequest.TransferInfo.SourceType == (int)SourceType.Asset)
  11814. {
  11815. requestID = new UUID(transferRequest.TransferInfo.Params, 0);
  11816. }
  11817. else if (transferRequest.TransferInfo.SourceType == (int)SourceType.SimInventoryItem)
  11818. {
  11819. requestID = new UUID(transferRequest.TransferInfo.Params, 80);
  11820. source = (byte)SourceType.SimInventoryItem;
  11821. //m_log.Debug("asset request " + requestID);
  11822. }
  11823. // Scripts cannot be retrieved by direct request
  11824. if (transferRequest.TransferInfo.SourceType == (int)SourceType.Asset && asset.Type == 10)
  11825. return;
  11826. // The asset is known to exist and is in our cache, so add it to the AssetRequests list
  11827. req.AssetInf = asset;
  11828. req.AssetRequestSource = source;
  11829. req.IsTextureRequest = false;
  11830. req.NumPackets = CalculateNumPackets(asset.Data);
  11831. req.Params = transferRequest.TransferInfo.Params;
  11832. req.RequestAssetID = requestID;
  11833. req.TransferRequestID = transferRequest.TransferInfo.TransferID;
  11834. SendAsset(req);
  11835. }
  11836. /// <summary>
  11837. /// Calculate the number of packets required to send the asset to the client.
  11838. /// </summary>
  11839. /// <param name="data"></param>
  11840. /// <returns></returns>
  11841. private static int CalculateNumPackets(byte[] data)
  11842. {
  11843. // const uint m_maxPacketSize = 600;
  11844. uint m_maxPacketSize = MaxTransferBytesPerPacket;
  11845. int numPackets = 1;
  11846. if (data == null)
  11847. return 0;
  11848. if (data.LongLength > m_maxPacketSize)
  11849. {
  11850. // over max number of bytes so split up file
  11851. long restData = data.LongLength - m_maxPacketSize;
  11852. int restPackets = (int)((restData + m_maxPacketSize - 1) / m_maxPacketSize);
  11853. numPackets += restPackets;
  11854. }
  11855. return numPackets;
  11856. }
  11857. public void SendRebakeAvatarTextures(UUID textureID)
  11858. {
  11859. RebakeAvatarTexturesPacket pack =
  11860. (RebakeAvatarTexturesPacket)PacketPool.Instance.GetPacket(PacketType.RebakeAvatarTextures);
  11861. pack.TextureData = new RebakeAvatarTexturesPacket.TextureDataBlock();
  11862. pack.TextureData.TextureID = textureID;
  11863. OutPacket(pack, ThrottleOutPacketType.Task);
  11864. }
  11865. public struct PacketProcessor
  11866. {
  11867. /// <summary>
  11868. /// Packet handling method.
  11869. /// </summary>
  11870. public PacketMethod method { get; set; }
  11871. /// <summary>
  11872. /// Should this packet be handled asynchronously?
  11873. /// </summary>
  11874. public bool Async { get; set; }
  11875. }
  11876. public class AsyncPacketProcess
  11877. {
  11878. public bool result = false;
  11879. public readonly LLClientView ClientView = null;
  11880. public readonly Packet Pack = null;
  11881. public readonly PacketMethod Method = null;
  11882. public AsyncPacketProcess(LLClientView pClientview, PacketMethod pMethod, Packet pPack)
  11883. {
  11884. ClientView = pClientview;
  11885. Method = pMethod;
  11886. Pack = pPack;
  11887. }
  11888. }
  11889. public void SendAvatarInterestsReply(UUID avatarID, uint wantMask, string wantText, uint skillsMask, string skillsText, string languages)
  11890. {
  11891. AvatarInterestsReplyPacket packet = (AvatarInterestsReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarInterestsReply);
  11892. packet.AgentData = new AvatarInterestsReplyPacket.AgentDataBlock();
  11893. packet.AgentData.AgentID = AgentId;
  11894. packet.AgentData.AvatarID = avatarID;
  11895. packet.PropertiesData = new AvatarInterestsReplyPacket.PropertiesDataBlock();
  11896. packet.PropertiesData.WantToMask = wantMask;
  11897. packet.PropertiesData.WantToText = Utils.StringToBytes(wantText);
  11898. packet.PropertiesData.SkillsMask = skillsMask;
  11899. packet.PropertiesData.SkillsText = Utils.StringToBytes(skillsText);
  11900. packet.PropertiesData.LanguagesText = Utils.StringToBytes(languages);
  11901. OutPacket(packet, ThrottleOutPacketType.Task);
  11902. }
  11903. public void SendChangeUserRights(UUID agentID, UUID friendID, int rights)
  11904. {
  11905. ChangeUserRightsPacket packet = (ChangeUserRightsPacket)PacketPool.Instance.GetPacket(PacketType.ChangeUserRights);
  11906. packet.AgentData = new ChangeUserRightsPacket.AgentDataBlock();
  11907. packet.AgentData.AgentID = agentID;
  11908. packet.Rights = new ChangeUserRightsPacket.RightsBlock[1];
  11909. packet.Rights[0] = new ChangeUserRightsPacket.RightsBlock();
  11910. packet.Rights[0].AgentRelated = friendID;
  11911. packet.Rights[0].RelatedRights = rights;
  11912. OutPacket(packet, ThrottleOutPacketType.Task);
  11913. }
  11914. public void SendTextBoxRequest(string message, int chatChannel, string objectname, UUID ownerID, string ownerFirstName, string ownerLastName, UUID objectId)
  11915. {
  11916. ScriptDialogPacket dialog = (ScriptDialogPacket)PacketPool.Instance.GetPacket(PacketType.ScriptDialog);
  11917. dialog.Data.ObjectID = objectId;
  11918. dialog.Data.ChatChannel = chatChannel;
  11919. dialog.Data.ImageID = UUID.Zero;
  11920. dialog.Data.ObjectName = Util.StringToBytes256(objectname);
  11921. // this is the username of the *owner*
  11922. dialog.Data.FirstName = Util.StringToBytes256(ownerFirstName);
  11923. dialog.Data.LastName = Util.StringToBytes256(ownerLastName);
  11924. dialog.Data.Message = Util.StringToBytes(message,512);
  11925. ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[1];
  11926. buttons[0] = new ScriptDialogPacket.ButtonsBlock();
  11927. buttons[0].ButtonLabel = Util.StringToBytes256("!!llTextBox!!");
  11928. dialog.Buttons = buttons;
  11929. dialog.OwnerData = new ScriptDialogPacket.OwnerDataBlock[1];
  11930. dialog.OwnerData[0] = new ScriptDialogPacket.OwnerDataBlock();
  11931. dialog.OwnerData[0].OwnerID = ownerID;
  11932. OutPacket(dialog, ThrottleOutPacketType.Task);
  11933. }
  11934. public void SendAgentTerseUpdate(ISceneEntity p)
  11935. {
  11936. if (p is ScenePresence)
  11937. {
  11938. // m_log.DebugFormat(
  11939. // "[LLCLIENTVIEW]: Immediately sending terse agent update for {0} to {1} in {2}",
  11940. // p.Name, Name, Scene.Name);
  11941. // It turns out to get the agent to stop flying, you have to feed it stop flying velocities
  11942. // There's no explicit message to send the client to tell it to stop flying.. it relies on the
  11943. // velocity, collision plane and avatar height
  11944. // Add 1/6 the avatar's height to it's position so it doesn't shoot into the air
  11945. // when the avatar stands up
  11946. ImprovedTerseObjectUpdatePacket.ObjectDataBlock block =
  11947. CreateImprovedTerseBlock(p);
  11948. // const float TIME_DILATION = 1.0f;
  11949. ushort timeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);;
  11950. ImprovedTerseObjectUpdatePacket packet
  11951. = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(
  11952. PacketType.ImprovedTerseObjectUpdate);
  11953. packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
  11954. packet.RegionData.TimeDilation = timeDilation;
  11955. packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
  11956. packet.ObjectData[0] = block;
  11957. OutPacket(packet, ThrottleOutPacketType.Task, true);
  11958. }
  11959. //ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId,
  11960. // AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient)));
  11961. }
  11962. public void SendPlacesReply(UUID queryID, UUID transactionID,
  11963. PlacesReplyData[] data)
  11964. {
  11965. PlacesReplyPacket reply = null;
  11966. PlacesReplyPacket.QueryDataBlock[] dataBlocks =
  11967. new PlacesReplyPacket.QueryDataBlock[0];
  11968. for (int i = 0 ; i < data.Length ; i++)
  11969. {
  11970. PlacesReplyPacket.QueryDataBlock block =
  11971. new PlacesReplyPacket.QueryDataBlock();
  11972. block.OwnerID = data[i].OwnerID;
  11973. block.Name = Util.StringToBytes256(data[i].Name);
  11974. block.Desc = Util.StringToBytes1024(data[i].Desc);
  11975. block.ActualArea = data[i].ActualArea;
  11976. block.BillableArea = data[i].BillableArea;
  11977. block.Flags = data[i].Flags;
  11978. block.GlobalX = data[i].GlobalX;
  11979. block.GlobalY = data[i].GlobalY;
  11980. block.GlobalZ = data[i].GlobalZ;
  11981. block.SimName = Util.StringToBytes256(data[i].SimName);
  11982. block.SnapshotID = data[i].SnapshotID;
  11983. block.Dwell = data[i].Dwell;
  11984. block.Price = data[i].Price;
  11985. if (reply != null && reply.Length + block.Length > 1400)
  11986. {
  11987. OutPacket(reply, ThrottleOutPacketType.Task);
  11988. reply = null;
  11989. dataBlocks = new PlacesReplyPacket.QueryDataBlock[0];
  11990. }
  11991. if (reply == null)
  11992. {
  11993. reply = (PlacesReplyPacket)PacketPool.Instance.GetPacket(PacketType.PlacesReply);
  11994. reply.AgentData = new PlacesReplyPacket.AgentDataBlock();
  11995. reply.AgentData.AgentID = AgentId;
  11996. reply.AgentData.QueryID = queryID;
  11997. reply.TransactionData = new PlacesReplyPacket.TransactionDataBlock();
  11998. reply.TransactionData.TransactionID = transactionID;
  11999. reply.QueryData = dataBlocks;
  12000. }
  12001. Array.Resize(ref dataBlocks, dataBlocks.Length + 1);
  12002. dataBlocks[dataBlocks.Length - 1] = block;
  12003. reply.QueryData = dataBlocks;
  12004. }
  12005. if (reply != null)
  12006. OutPacket(reply, ThrottleOutPacketType.Task);
  12007. }
  12008. public void SendRemoveInventoryItems(UUID[] items)
  12009. {
  12010. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  12011. if (eq == null)
  12012. {
  12013. m_log.DebugFormat("[LLCLIENT]: Null event queue");
  12014. return;
  12015. }
  12016. StringBuilder sb = eq.StartEvent("RemoveInventoryItem");
  12017. LLSDxmlEncode.AddArrayAndMap("AgentData", sb);
  12018. LLSDxmlEncode.AddElem("AgentID", AgentId, sb);
  12019. LLSDxmlEncode.AddElem("SessionID", SessionId, sb);
  12020. LLSDxmlEncode.AddEndMapAndArray(sb);
  12021. LLSDxmlEncode.AddArray("InventoryData", sb);
  12022. foreach (UUID item in items)
  12023. {
  12024. LLSDxmlEncode.AddMap(sb);
  12025. LLSDxmlEncode.AddElem("ItemID",item, sb);
  12026. LLSDxmlEncode.AddEndMap(sb);
  12027. }
  12028. LLSDxmlEncode.AddEndArray(sb);
  12029. OSD ev = new OSDllsdxml(eq.EndEvent(sb));
  12030. eq.Enqueue(ev, AgentId);
  12031. }
  12032. public void SendRemoveInventoryFolders(UUID[] folders)
  12033. {
  12034. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  12035. if (eq == null)
  12036. {
  12037. m_log.DebugFormat("[LLCLIENT]: Null event queue");
  12038. return;
  12039. }
  12040. StringBuilder sb = eq.StartEvent("RemoveInventoryFolder");
  12041. LLSDxmlEncode.AddArrayAndMap("AgentData", sb);
  12042. LLSDxmlEncode.AddElem("AgentID", AgentId, sb);
  12043. LLSDxmlEncode.AddElem("SessionID", SessionId, sb);
  12044. LLSDxmlEncode.AddEndMapAndArray(sb);
  12045. LLSDxmlEncode.AddArray("FolderData", sb);
  12046. foreach (UUID folder in folders)
  12047. {
  12048. LLSDxmlEncode.AddMap(sb);
  12049. LLSDxmlEncode.AddElem("FolderID", folder, sb);
  12050. LLSDxmlEncode.AddEndMap(sb);
  12051. }
  12052. LLSDxmlEncode.AddEndArray(sb);
  12053. OSD ev = new OSDllsdxml(eq.EndEvent(sb));
  12054. eq.Enqueue(ev, AgentId);
  12055. }
  12056. public void SendBulkUpdateInventory(InventoryFolderBase[] folders, InventoryItemBase[] items)
  12057. {
  12058. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  12059. if (eq == null)
  12060. {
  12061. m_log.DebugFormat("[LLCLIENT]: Null event queue");
  12062. return;
  12063. }
  12064. StringBuilder sb = eq.StartEvent("BulkUpdateInventory");
  12065. LLSDxmlEncode.AddArrayAndMap("AgentData", sb);
  12066. LLSDxmlEncode.AddElem("AgentID", AgentId, sb);
  12067. LLSDxmlEncode.AddElem("TransactionID", UUID.Random(), sb);
  12068. LLSDxmlEncode.AddEndMapAndArray(sb);
  12069. if(folders.Length == 0)
  12070. {
  12071. LLSDxmlEncode.AddEmptyArray("FolderData", sb);
  12072. }
  12073. else
  12074. {
  12075. LLSDxmlEncode.AddArray("FolderData", sb);
  12076. foreach (InventoryFolderBase folder in folders)
  12077. {
  12078. LLSDxmlEncode.AddMap(sb);
  12079. LLSDxmlEncode.AddElem("FolderID", folder.ID, sb);
  12080. LLSDxmlEncode.AddElem("ParentID", folder.ParentID, sb);
  12081. LLSDxmlEncode.AddElem("Type", (int)folder.Type, sb);
  12082. LLSDxmlEncode.AddElem("Name", folder.Name, sb);
  12083. LLSDxmlEncode.AddEndMap(sb);
  12084. }
  12085. LLSDxmlEncode.AddEndArray(sb);
  12086. }
  12087. if(items.Length == 0)
  12088. {
  12089. LLSDxmlEncode.AddEmptyArray("ItemData", sb);
  12090. }
  12091. else
  12092. {
  12093. LLSDxmlEncode.AddArray("ItemData", sb);
  12094. foreach (InventoryItemBase item in items)
  12095. {
  12096. LLSDxmlEncode.AddMap(sb);
  12097. LLSDxmlEncode.AddElem("ItemID", item.ID, sb);
  12098. LLSDxmlEncode.AddElem("CallbackID", (uint)0, sb);
  12099. LLSDxmlEncode.AddElem("FolderID", item.Folder, sb);
  12100. LLSDxmlEncode.AddElem("CreatorID", item.CreatorIdAsUuid, sb);
  12101. LLSDxmlEncode.AddElem("OwnerID", item.Owner, sb);
  12102. LLSDxmlEncode.AddElem("GroupID", item.GroupID, sb);
  12103. LLSDxmlEncode.AddElem("BaseMask", item.BasePermissions, sb);
  12104. LLSDxmlEncode.AddElem("OwnerMask", item.CurrentPermissions, sb);
  12105. LLSDxmlEncode.AddElem("GroupMask", item.GroupPermissions, sb);
  12106. LLSDxmlEncode.AddElem("EveryoneMask", item.EveryOnePermissions, sb);
  12107. LLSDxmlEncode.AddElem("NextOwnerMask", item.NextPermissions, sb);
  12108. LLSDxmlEncode.AddElem("GroupOwned", item.GroupOwned, sb);
  12109. LLSDxmlEncode.AddElem("AssetID", item.AssetID, sb);
  12110. LLSDxmlEncode.AddElem("Type", item.AssetType, sb);
  12111. LLSDxmlEncode.AddElem("InvType", item.InvType, sb);
  12112. LLSDxmlEncode.AddElem("Flags", item.Flags, sb);
  12113. LLSDxmlEncode.AddElem("SaleType", item.SaleType, sb);
  12114. LLSDxmlEncode.AddElem("SalePrice", item.SalePrice, sb);
  12115. LLSDxmlEncode.AddElem("Name", item.Name, sb);
  12116. LLSDxmlEncode.AddElem("Description", item.Description, sb);
  12117. LLSDxmlEncode.AddElem("CreationDate", item.CreationDate, sb);
  12118. LLSDxmlEncode.AddElem("CRC",
  12119. Helpers.InventoryCRC(1000, 0, (sbyte)item.InvType,
  12120. (sbyte)item.AssetType, item.AssetID,
  12121. item.GroupID, 100,
  12122. item.Owner, item.CreatorIdAsUuid,
  12123. item.ID, item.Folder,
  12124. (uint)PermissionMask.All, 1, (uint)PermissionMask.All, (uint)PermissionMask.All,
  12125. (uint)PermissionMask.All),
  12126. sb);
  12127. LLSDxmlEncode.AddEndMap(sb);
  12128. }
  12129. LLSDxmlEncode.AddEndArray(sb);
  12130. }
  12131. OSD ev = new OSDllsdxml(eq.EndEvent(sb));
  12132. eq.Enqueue(ev, AgentId);
  12133. }
  12134. private HashSet<string> m_outPacketsToDrop;
  12135. public bool AddOutPacketToDropSet(string packetName)
  12136. {
  12137. if (m_outPacketsToDrop == null)
  12138. m_outPacketsToDrop = new HashSet<string>();
  12139. return m_outPacketsToDrop.Add(packetName);
  12140. }
  12141. public bool RemoveOutPacketFromDropSet(string packetName)
  12142. {
  12143. if (m_outPacketsToDrop == null)
  12144. return false;
  12145. return m_outPacketsToDrop.Remove(packetName);
  12146. }
  12147. public HashSet<string> GetOutPacketDropSet()
  12148. {
  12149. return new HashSet<string>(m_outPacketsToDrop);
  12150. }
  12151. private HashSet<string> m_inPacketsToDrop;
  12152. public bool AddInPacketToDropSet(string packetName)
  12153. {
  12154. if (m_inPacketsToDrop == null)
  12155. m_inPacketsToDrop = new HashSet<string>();
  12156. return m_inPacketsToDrop.Add(packetName);
  12157. }
  12158. public bool RemoveInPacketFromDropSet(string packetName)
  12159. {
  12160. if (m_inPacketsToDrop == null)
  12161. return false;
  12162. return m_inPacketsToDrop.Remove(packetName);
  12163. }
  12164. public HashSet<string> GetInPacketDropSet()
  12165. {
  12166. return new HashSet<string>(m_inPacketsToDrop);
  12167. }
  12168. public void CheckViewerCaps()
  12169. {
  12170. m_SupportObjectAnimations = false;
  12171. if (m_scene.CapsModule != null)
  12172. {
  12173. Caps cap = m_scene.CapsModule.GetCapsForUser(CircuitCode);
  12174. if (cap != null && (cap.Flags & Caps.CapsFlags.ObjectAnim) != 0)
  12175. m_SupportObjectAnimations = true;
  12176. }
  12177. }
  12178. }
  12179. }