LLClientView.cs 595 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877
  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 void PacketMethod(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 AgentDataUpdate 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. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  302. private static string LogHeader = "[LLCLIENTVIEW]";
  303. /// <summary>
  304. /// Handles UDP texture download.
  305. /// </summary>
  306. public LLImageManager ImageManager { get; private set; }
  307. public JobEngine m_asyncPacketProcess;
  308. private readonly LLUDPServer m_udpServer;
  309. private readonly LLUDPClient m_udpClient;
  310. private readonly UUID m_sessionId;
  311. private readonly UUID m_secureSessionId;
  312. protected readonly UUID m_agentId;
  313. protected readonly UUID m_scopeId;
  314. private readonly uint m_circuitCode;
  315. private readonly byte[] m_regionChannelVersion = Utils.EmptyBytes;
  316. private readonly IGroupsModule m_GroupsModule;
  317. // private int m_cachedTextureSerial;
  318. private PriorityQueue m_entityUpdates;
  319. private PriorityQueue m_entityProps;
  320. private Prioritizer m_prioritizer;
  321. private bool m_disableFacelights;
  322. // needs optimization
  323. private HashSet<SceneObjectGroup> GroupsInView = new HashSet<SceneObjectGroup>();
  324. #pragma warning disable 0414
  325. private bool m_VelocityInterpolate;
  326. #pragma warning restore 0414
  327. private const uint MaxTransferBytesPerPacket = 600;
  328. private bool m_SupportObjectAnimations;
  329. /// <value>
  330. /// Maintain a record of all the objects killed. This allows us to stop an update being sent from the
  331. /// thread servicing the m_primFullUpdates queue after a kill. If this happens the object persists as an
  332. /// ownerless phantom.
  333. ///
  334. /// All manipulation of this set has to occur under an m_entityUpdates.SyncRoot lock
  335. ///
  336. /// </value>
  337. protected List<uint> m_killRecord;
  338. //protected HashSet<uint> m_attachmentsSent;
  339. private bool m_SendLogoutPacketWhenClosing = true;
  340. /// <summary>
  341. /// We retain a single AgentUpdateArgs so that we can constantly reuse it rather than construct a new one for
  342. /// every single incoming AgentUpdate. Every client sends 10 AgentUpdate UDP messages per second, even if it
  343. /// is doing absolutely nothing.
  344. /// </summary>
  345. /// <remarks>
  346. /// This does mean that agent updates must be processed synchronously, at least for each client, and called methods
  347. /// cannot retain a reference to it outside of that method.
  348. /// </remarks>
  349. private AgentUpdateArgs m_thisAgentUpdateArgs = new AgentUpdateArgs();
  350. protected Dictionary<PacketType, PacketProcessor> m_packetHandlers = new Dictionary<PacketType, PacketProcessor>();
  351. protected Dictionary<string, GenericMessage> m_genericPacketHandlers = new Dictionary<string, GenericMessage>(); //PauPaw:Local Generic Message handlers
  352. protected Scene m_scene;
  353. protected string m_firstName;
  354. protected string m_lastName;
  355. protected Vector3 m_startpos;
  356. protected UUID m_activeGroupID;
  357. protected string m_activeGroupName = String.Empty;
  358. protected ulong m_activeGroupPowers;
  359. protected Dictionary<UUID, ulong> m_groupPowers = new Dictionary<UUID, ulong>();
  360. protected int m_terrainCheckerCount;
  361. protected uint m_agentFOVCounter;
  362. protected IAssetService m_assetService;
  363. protected bool m_supportViewerCache = false;
  364. #endregion Class Members
  365. #region Properties
  366. public LLUDPClient UDPClient { get { return m_udpClient; } }
  367. public LLUDPServer UDPServer { get { return m_udpServer; } }
  368. public IPEndPoint RemoteEndPoint { get { return m_udpClient.RemoteEndPoint; } }
  369. public UUID SecureSessionId { get { return m_secureSessionId; } }
  370. public IScene Scene { get { return m_scene; } }
  371. public UUID SessionId { get { return m_sessionId; } }
  372. public Vector3 StartPos
  373. {
  374. get { return m_startpos; }
  375. set { m_startpos = value; }
  376. }
  377. public float StartFar { get; set; }
  378. public UUID AgentId { get { return m_agentId; } }
  379. public UUID ScopeId { get { return m_scopeId; } }
  380. public ISceneAgent SceneAgent { get; set; }
  381. public UUID ActiveGroupId { get { return m_activeGroupID; } set { m_activeGroupID = value; } }
  382. public string ActiveGroupName { get { return m_activeGroupName; } set { m_activeGroupName = value; } }
  383. public ulong ActiveGroupPowers { get { return m_activeGroupPowers; } set { m_activeGroupPowers = value; } }
  384. public bool IsGroupMember(UUID groupID) { return m_groupPowers.ContainsKey(groupID); }
  385. public int PingTimeMS
  386. {
  387. get
  388. {
  389. if (UDPClient != null)
  390. return UDPClient.PingTimeMS;
  391. return 0;
  392. }
  393. }
  394. /// <summary>
  395. /// Entity update queues
  396. /// </summary>
  397. public PriorityQueue EntityUpdateQueue { get { return m_entityUpdates; } }
  398. /// <summary>
  399. /// First name of the agent/avatar represented by the client
  400. /// </summary>
  401. public string FirstName { get { return m_firstName; } }
  402. /// <summary>
  403. /// Last name of the agent/avatar represented by the client
  404. /// </summary>
  405. public string LastName { get { return m_lastName; } }
  406. /// <summary>
  407. /// Full name of the client (first name and last name)
  408. /// </summary>
  409. public string Name { get { return FirstName + " " + LastName; } }
  410. public uint CircuitCode { get { return m_circuitCode; } }
  411. protected int m_animationSequenceNumber = (int)(Util.GetTimeStampTicks() & 0x5fffafL);
  412. public int NextAnimationSequenceNumber
  413. {
  414. get
  415. {
  416. int ret = Interlocked.Increment(ref m_animationSequenceNumber);
  417. if (ret <= 0)
  418. {
  419. m_animationSequenceNumber = (int)(Util.GetTimeStampTicks() & 0xafff5fL);
  420. ret = Interlocked.Increment(ref m_animationSequenceNumber);
  421. }
  422. return ret;
  423. }
  424. set
  425. {
  426. m_animationSequenceNumber = value;
  427. }
  428. }
  429. /// <summary>
  430. /// As well as it's function in IClientAPI, in LLClientView we are locking on this property in order to
  431. /// prevent race conditions by different threads calling Close().
  432. /// </summary>
  433. public bool IsActive { get; set; }
  434. /// <summary>
  435. /// Used to synchronise threads when client is being closed.
  436. /// </summary>
  437. public object CloseSyncLock { get;} = new object();
  438. public bool IsLoggingOut { get; set; }
  439. public bool DisableFacelights
  440. {
  441. get { return m_disableFacelights; }
  442. set { m_disableFacelights = value; }
  443. }
  444. public List<uint> SelectedObjects {get; private set;}
  445. public bool SendLogoutPacketWhenClosing { set { m_SendLogoutPacketWhenClosing = value; } }
  446. #endregion Properties
  447. // ~LLClientView()
  448. // {
  449. // m_log.DebugFormat("{0} Destructor called for {1}, circuit code {2}", LogHeader, Name, CircuitCode);
  450. // }
  451. /// <summary>
  452. /// Constructor
  453. /// </summary>
  454. public LLClientView(Scene scene, LLUDPServer udpServer, LLUDPClient udpClient, AuthenticateResponse sessionInfo,
  455. UUID agentId, UUID sessionId, uint circuitCode)
  456. {
  457. // DebugPacketLevel = 1;
  458. SelectedObjects = new List<uint>();
  459. RegisterInterface<IClientIM>(this);
  460. RegisterInterface<IClientInventory>(this);
  461. RegisterInterface<IClientChat>(this);
  462. m_scene = scene;
  463. int pcap = 512;
  464. if(pcap > m_scene.Entities.Count)
  465. pcap = m_scene.Entities.Count;
  466. m_entityUpdates = new PriorityQueue(pcap);
  467. m_entityProps = new PriorityQueue(pcap);
  468. m_killRecord = new List<uint>();
  469. // m_attachmentsSent = new HashSet<uint>();
  470. m_assetService = m_scene.RequestModuleInterface<IAssetService>();
  471. m_GroupsModule = scene.RequestModuleInterface<IGroupsModule>();
  472. ImageManager = new LLImageManager(this, m_assetService, Scene.RequestModuleInterface<IJ2KDecoder>());
  473. m_regionChannelVersion = Util.StringToBytes1024(scene.GetSimulatorVersion());
  474. m_agentId = agentId;
  475. m_sessionId = sessionId;
  476. m_secureSessionId = sessionInfo.LoginInfo.SecureSession;
  477. m_circuitCode = circuitCode;
  478. m_firstName = sessionInfo.LoginInfo.First;
  479. m_lastName = sessionInfo.LoginInfo.Last;
  480. m_startpos = sessionInfo.LoginInfo.StartPos;
  481. StartFar = sessionInfo.LoginInfo.StartFar;
  482. m_udpServer = udpServer;
  483. m_udpClient = udpClient;
  484. m_udpClient.OnQueueEmpty += HandleQueueEmpty;
  485. m_udpClient.HasUpdates += HandleHasUpdates;
  486. m_udpClient.OnPacketStats += PopulateStats;
  487. m_prioritizer = new Prioritizer(m_scene);
  488. // Pick up agent scope which, for gods, can be different from the region scope
  489. IUserAccountService userAccountService = m_scene.RequestModuleInterface<IUserAccountService>();
  490. var myself = userAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_agentId);
  491. RegisterLocalPacketHandlers();
  492. string name = string.Format("AsyncInUDP-{0}",m_agentId.ToString());
  493. m_asyncPacketProcess = new JobEngine(name, name, 10000);
  494. IsActive = true;
  495. m_supportViewerCache = m_udpServer.SupportViewerObjectsCache;
  496. }
  497. #region Client Methods
  498. /// <summary>
  499. /// Close down the client view
  500. /// </summary>
  501. public void Close()
  502. {
  503. Close(true, false);
  504. }
  505. public void Close(bool sendStop, bool force)
  506. {
  507. // We lock here to prevent race conditions between two threads calling close simultaneously (e.g.
  508. // a simultaneous relog just as a client is being closed out due to no packet ack from the old connection.
  509. lock (CloseSyncLock)
  510. {
  511. // We still perform a force close inside the sync lock since this is intended to attempt close where
  512. // there is some unidentified connection problem, not where we have issues due to deadlock
  513. if (!IsActive && !force)
  514. {
  515. m_log.DebugFormat( "{0} Not attempting to close inactive client {1} in {2} since force flag is not set",
  516. LogHeader, Name, m_scene.Name);
  517. return;
  518. }
  519. IsActive = false;
  520. CloseWithoutChecks(sendStop);
  521. }
  522. }
  523. /// <summary>
  524. /// Closes down the client view without first checking whether it is active.
  525. /// </summary>
  526. /// <remarks>
  527. /// This exists because LLUDPServer has to set IsActive = false in earlier synchronous code before calling
  528. /// CloseWithoutIsActiveCheck asynchronously.
  529. ///
  530. /// Callers must lock ClosingSyncLock before calling.
  531. /// </remarks>
  532. public void CloseWithoutChecks(bool sendStop)
  533. {
  534. m_log.DebugFormat(
  535. "[CLIENT]: Close has been called for {0} attached to scene {1}",
  536. Name, m_scene.RegionInfo.RegionName);
  537. if (sendStop)
  538. {
  539. // Send the STOP packet
  540. DisableSimulatorPacket disable = (DisableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
  541. OutPacket(disable, ThrottleOutPacketType.Unknown);
  542. }
  543. // Fire the callback for this connection closing
  544. if (OnConnectionClosed != null)
  545. OnConnectionClosed(this);
  546. m_asyncPacketProcess.Stop();
  547. // Flush all of the packets out of the UDP server for this client
  548. if (m_udpServer != null)
  549. m_udpServer.Flush(m_udpClient);
  550. // Remove ourselves from the scene
  551. m_scene.RemoveClient(AgentId, true);
  552. SceneAgent = null;
  553. // We can't reach into other scenes and close the connection
  554. // We need to do this over grid communications
  555. //m_scene.CloseAllAgents(CircuitCode);
  556. // Disable UDP handling for this client
  557. m_udpClient.OnQueueEmpty -= HandleQueueEmpty;
  558. m_udpClient.HasUpdates -= HandleHasUpdates;
  559. m_udpClient.OnPacketStats -= PopulateStats;
  560. m_udpClient.Shutdown();
  561. // Shutdown the image manager
  562. ImageManager.Close();
  563. ImageManager = null;
  564. m_entityUpdates.Close();
  565. m_entityProps.Close();
  566. m_killRecord.Clear();
  567. GroupsInView.Clear();
  568. if(m_scene.GetNumberOfClients() == 0)
  569. {
  570. GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
  571. GC.Collect();
  572. GC.WaitForPendingFinalizers();
  573. GC.Collect();
  574. GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.Default;
  575. }
  576. }
  577. public void Kick(string message)
  578. {
  579. if (!SceneAgent.IsChildAgent)
  580. {
  581. KickUserPacket kupack = (KickUserPacket)PacketPool.Instance.GetPacket(PacketType.KickUser);
  582. kupack.UserInfo.AgentID = AgentId;
  583. kupack.UserInfo.SessionID = SessionId;
  584. kupack.TargetBlock.TargetIP = 0;
  585. kupack.TargetBlock.TargetPort = 0;
  586. kupack.UserInfo.Reason = Util.StringToBytes256(message);
  587. OutPacket(kupack, ThrottleOutPacketType.Task);
  588. // You must sleep here or users get no message!
  589. Thread.Sleep(500);
  590. }
  591. }
  592. public void Stop()
  593. {
  594. }
  595. #endregion Client Methods
  596. #region Packet Handling
  597. public void PopulateStats(int inPackets, int outPackets, int unAckedBytes)
  598. {
  599. OnNetworkStatsUpdate?.Invoke(inPackets, outPackets, unAckedBytes);
  600. }
  601. /// <summary>
  602. /// Add a handler for the given packet type.
  603. /// </summary>
  604. /// <remarks>
  605. /// The packet is handled on its own thread. If packets must be handled in the order in which they
  606. /// are received then please use the synchronous version of this method.
  607. /// </remarks>
  608. /// <param name="packetType"></param>
  609. /// <param name="handler"></param>
  610. /// <returns>true if the handler was added. This is currently always the case.</returns>
  611. public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
  612. {
  613. return AddLocalPacketHandler(packetType, handler, true);
  614. }
  615. /// <summary>
  616. /// Add a handler for the given packet type.
  617. /// </summary>
  618. /// <param name="packetType"></param>
  619. /// <param name="handler"></param>
  620. /// <param name="doAsync">
  621. /// If true, when the packet is received it is handled on its own thread rather than on the main inward bound
  622. /// packet handler thread. This vastly increases respnosiveness but some packets need to be handled
  623. /// synchronously.
  624. /// </param>
  625. /// <returns>true if the handler was added. This is currently always the case.</returns>
  626. public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler, bool doAsync)
  627. {
  628. lock (m_packetHandlers)
  629. {
  630. if (!m_packetHandlers.ContainsKey(packetType))
  631. {
  632. m_packetHandlers.Add(packetType, new PacketProcessor() { method = handler, Async = doAsync});
  633. return true;
  634. }
  635. }
  636. return false;
  637. }
  638. public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)
  639. {
  640. MethodName = MethodName.ToLower().Trim();
  641. bool result = false;
  642. lock (m_genericPacketHandlers)
  643. {
  644. if (!m_genericPacketHandlers.ContainsKey(MethodName))
  645. {
  646. m_genericPacketHandlers.Add(MethodName, handler);
  647. result = true;
  648. }
  649. }
  650. return result;
  651. }
  652. /// <summary>
  653. /// Try to process a packet using registered packet handlers
  654. /// </summary>
  655. /// <param name="packet"></param>
  656. /// <returns>True if a handler was found which successfully processed the packet.</returns>
  657. protected bool ProcessPacketMethod(Packet packet)
  658. {
  659. if (m_packetHandlers.TryGetValue(packet.Type, out PacketProcessor pprocessor))
  660. {
  661. if (pprocessor.Async)
  662. {
  663. m_asyncPacketProcess.QueueJob(packet.Type.ToString(), () =>
  664. {
  665. try
  666. {
  667. pprocessor.method(packet);
  668. }
  669. catch (Exception e)
  670. {
  671. // Make sure that we see any exception caused by the asynchronous operation.
  672. m_log.Error(string.Format(
  673. "[LLCLIENTVIEW]: Caught exception while processing {0} for {1} ", packet, Name),e);
  674. }
  675. });
  676. }
  677. else
  678. {
  679. pprocessor.method(packet);
  680. }
  681. return true;
  682. }
  683. return false;
  684. }
  685. #endregion Packet Handling
  686. # region Setup
  687. public virtual void Start()
  688. {
  689. m_asyncPacketProcess.Start();
  690. m_scene.AddNewAgent(this, PresenceType.User);
  691. // RefreshGroupMembership();
  692. }
  693. # endregion
  694. public void ActivateGesture(UUID assetId, UUID gestureId)
  695. {
  696. }
  697. public void DeactivateGesture(UUID assetId, UUID gestureId)
  698. {
  699. }
  700. // Sound
  701. public void SoundTrigger(UUID soundId, UUID owerid, UUID Objectid, UUID ParentId, float Gain, Vector3 Position, UInt64 Handle)
  702. {
  703. }
  704. #region Scene/Avatar to Client
  705. // temporary here ( from estatemanagermodule)
  706. private uint GetRegionFlags()
  707. {
  708. RegionFlags flags = RegionFlags.None;
  709. if (Scene.RegionInfo.RegionSettings.AllowDamage)
  710. flags |= RegionFlags.AllowDamage;
  711. if (Scene.RegionInfo.EstateSettings.AllowLandmark)
  712. flags |= RegionFlags.AllowLandmark;
  713. if (Scene.RegionInfo.EstateSettings.AllowSetHome)
  714. flags |= RegionFlags.AllowSetHome;
  715. if (Scene.RegionInfo.EstateSettings.ResetHomeOnTeleport)
  716. flags |= RegionFlags.ResetHomeOnTeleport;
  717. if (Scene.RegionInfo.RegionSettings.FixedSun)
  718. flags |= RegionFlags.SunFixed;
  719. // allow access override (was taxfree)
  720. if (!Scene.RegionInfo.EstateSettings.TaxFree) // this is now wrong means !ALLOW_ACCESS_OVERRIDE
  721. flags |= RegionFlags.AllowParcelAccessOverride;
  722. if (Scene.RegionInfo.RegionSettings.BlockTerraform)
  723. flags |= RegionFlags.BlockTerraform;
  724. if (!Scene.RegionInfo.RegionSettings.AllowLandResell)
  725. flags |= RegionFlags.BlockLandResell;
  726. if (Scene.RegionInfo.RegionSettings.Sandbox)
  727. flags |= RegionFlags.Sandbox;
  728. // nulllayer not used
  729. if (Scene.RegionInfo.RegionSettings.Casino)
  730. flags |= RegionFlags.SkipAgentAction; // redefined
  731. if (Scene.RegionInfo.RegionSettings.GodBlockSearch)
  732. flags |= RegionFlags.SkipUpdateInterestList; // redefined
  733. if (Scene.RegionInfo.RegionSettings.DisableCollisions)
  734. flags |= RegionFlags.SkipCollisions;
  735. if (Scene.RegionInfo.RegionSettings.DisableScripts)
  736. flags |= RegionFlags.SkipScripts;
  737. if (Scene.RegionInfo.RegionSettings.DisablePhysics)
  738. flags |= RegionFlags.SkipPhysics;
  739. if (Scene.RegionInfo.EstateSettings.PublicAccess)
  740. flags |= RegionFlags.ExternallyVisible; // ???? need revision
  741. //MainlandVisible -> allow return enc object
  742. //PublicAllowed -> allow return enc estate object
  743. if (Scene.RegionInfo.EstateSettings.BlockDwell)
  744. flags |= RegionFlags.BlockDwell;
  745. if (Scene.RegionInfo.RegionSettings.BlockFly)
  746. flags |= RegionFlags.NoFly;
  747. if (Scene.RegionInfo.EstateSettings.AllowDirectTeleport)
  748. flags |= RegionFlags.AllowDirectTeleport;
  749. if (Scene.RegionInfo.EstateSettings.EstateSkipScripts)
  750. flags |= RegionFlags.EstateSkipScripts;
  751. if (Scene.RegionInfo.RegionSettings.RestrictPushing)
  752. flags |= RegionFlags.RestrictPushObject;
  753. if (Scene.RegionInfo.EstateSettings.DenyAnonymous)
  754. flags |= RegionFlags.DenyAnonymous;
  755. //DenyIdentified unused
  756. //DenyTransacted unused
  757. if (Scene.RegionInfo.RegionSettings.AllowLandJoinDivide)
  758. flags |= RegionFlags.AllowParcelChanges;
  759. //AbuseEmailToEstateOwner -> block flyover
  760. if (Scene.RegionInfo.EstateSettings.AllowVoice)
  761. flags |= RegionFlags.AllowVoice;
  762. if (Scene.RegionInfo.RegionSettings.BlockShowInSearch)
  763. flags |= RegionFlags.BlockParcelSearch;
  764. if (Scene.RegionInfo.EstateSettings.DenyMinors)
  765. flags |= RegionFlags.DenyAgeUnverified;
  766. if(Scene.RegionInfo.EstateSettings.AllowEnvironmentOverride)
  767. flags |= RegionFlags.AllowEnvironmentOverride;
  768. return (uint)flags;
  769. }
  770. // Region handshake may need a more detailed look
  771. static private readonly byte[] RegionHandshakeHeader = new byte[] {
  772. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED,
  773. 0, 0, 0, 0, // sequence number
  774. 0, // extra
  775. //0xff, 0xff, 0, 148 // ID 148 (low frequency bigendian)
  776. 0xff, 0xff, 0, 1, 148 // ID 148 (low frequency bigendian) zero encoded
  777. };
  778. public void SendRegionHandshake()
  779. {
  780. RegionInfo regionInfo = m_scene.RegionInfo;
  781. RegionSettings regionSettings = regionInfo.RegionSettings;
  782. EstateSettings es = regionInfo.EstateSettings;
  783. bool isEstateManager = m_scene.Permissions.IsEstateManager(AgentId); // go by oficial path
  784. uint regionFlags = GetRegionFlags();
  785. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  786. Buffer.BlockCopy(RegionHandshakeHeader, 0, buf.Data, 0, 11);
  787. // inline zeroencode
  788. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  789. zc.Position = 11;
  790. //RegionInfo Block
  791. //RegionFlags U32
  792. zc.AddUInt(regionFlags);
  793. //SimAccess U8
  794. zc.AddByte(regionInfo.AccessLevel);
  795. //SimName
  796. zc.AddShortString(regionInfo.RegionName, 255);
  797. //SimOwner
  798. zc.AddUUID(es.EstateOwner);
  799. //IsEstateManager
  800. zc.AddByte((byte)(isEstateManager ? 1 : 0));
  801. //WaterHeight
  802. zc.AddFloat((float)regionSettings.WaterHeight); // why is this a double ??
  803. //BillableFactor
  804. zc.AddFloat(es.BillableFactor);
  805. //CacheID
  806. zc.AddUUID(regionSettings.CacheID);
  807. //TerrainBase0
  808. //TerrainBase1
  809. //TerrainBase2
  810. //TerrainBase3
  811. // this seem not obsolete, sending zero uuids
  812. // we should send the basic low resolution default ?
  813. zc.AddZeros(16 * 4);
  814. //TerrainDetail0
  815. zc.AddUUID(regionSettings.TerrainTexture1);
  816. //TerrainDetail1
  817. zc.AddUUID(regionSettings.TerrainTexture2);
  818. //TerrainDetail2
  819. zc.AddUUID(regionSettings.TerrainTexture3);
  820. //TerrainDetail3
  821. zc.AddUUID(regionSettings.TerrainTexture4);
  822. //TerrainStartHeight00
  823. zc.AddFloat((float)regionSettings.Elevation1SW);
  824. //TerrainStartHeight01
  825. zc.AddFloat((float)regionSettings.Elevation1NW);
  826. //TerrainStartHeight10
  827. zc.AddFloat((float)regionSettings.Elevation1SE);
  828. //TerrainStartHeight11
  829. zc.AddFloat((float)regionSettings.Elevation1NE);
  830. //TerrainHeightRange00
  831. zc.AddFloat((float)regionSettings.Elevation2SW);
  832. //TerrainHeightRange01
  833. zc.AddFloat((float)regionSettings.Elevation2NW);
  834. //TerrainHeightRange10
  835. zc.AddFloat((float)regionSettings.Elevation2SE);
  836. //TerrainHeightRange11
  837. zc.AddFloat((float)regionSettings.Elevation2NE);
  838. //RegionInfo2 block
  839. //region ID
  840. zc.AddUUID(regionInfo.RegionID);
  841. //RegionInfo3 block
  842. //CPUClassID
  843. zc.AddInt(9);
  844. //CPURatio
  845. zc.AddInt(1);
  846. // ColoName (string)
  847. // ProductSKU (string)
  848. // both empty strings
  849. zc.AddZeros(2);
  850. //ProductName
  851. zc.AddShortString(regionInfo.RegionType, 255);
  852. //RegionInfo4 block
  853. //RegionFlagsExtended
  854. //zc.AddZeros(1); // if we dont have this else
  855. zc.AddByte(1);
  856. zc.AddUInt64(regionFlags); // we have nothing other base flags
  857. //RegionProtocols
  858. // bit 0 signals server side texture baking
  859. // bit 63 signals more than 6 baked textures support"
  860. zc.AddUInt64(1UL << 63);
  861. buf.DataLength = zc.Finish();
  862. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Unknown);
  863. }
  864. static private readonly byte[] AgentMovementCompleteHeader = new byte[] {
  865. Helpers.MSG_RELIABLE,
  866. 0, 0, 0, 0, // sequence number
  867. 0, // extra
  868. 0xff, 0xff, 0, 250 // ID 250 (low frequency bigendian)
  869. };
  870. public void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look)
  871. {
  872. // reset agent update args
  873. m_thisAgentUpdateArgs.CameraAtAxis.X = float.MinValue;
  874. m_thisAgentUpdateArgs.lastUpdateTS = 0;
  875. m_thisAgentUpdateArgs.ControlFlags = 0;
  876. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  877. byte[] data = buf.Data;
  878. //setup header
  879. Buffer.BlockCopy(AgentMovementCompleteHeader, 0, data, 0, 10);
  880. //AgentData block
  881. AgentId.ToBytes(data, 10); // 26
  882. SessionId.ToBytes(data, 26); // 42
  883. //Data block
  884. if ((pos.X == 0) && (pos.Y == 0) && (pos.Z == 0))
  885. m_startpos.ToBytes(data, 42); //54
  886. else
  887. pos.ToBytes(data, 42); //54
  888. look.ToBytes(data, 54); // 66
  889. Utils.UInt64ToBytesSafepos(regInfo.RegionHandle, data, 66); // 74
  890. Utils.UIntToBytesSafepos((uint)Util.UnixTimeSinceEpoch(), data, 74); //78
  891. //SimData
  892. int len = m_regionChannelVersion.Length;
  893. if(len == 0)
  894. {
  895. data[78] = 0;
  896. data[79] = 0;
  897. }
  898. else
  899. {
  900. data[78] = (byte)len;
  901. data[79] = (byte)(len >> 8);
  902. Buffer.BlockCopy(m_regionChannelVersion, 0, data, 80, len);
  903. }
  904. buf.DataLength = 80 + len;
  905. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Unknown);
  906. }
  907. static private readonly byte[] ChatFromSimulatorHeader = new byte[] {
  908. Helpers.MSG_RELIABLE,
  909. 0, 0, 0, 0, // sequence number
  910. 0, // extra
  911. 0xff, 0xff, 0, 139 // ID 139 (low frequency bigendian)
  912. };
  913. public void SendChatMessage(string message, byte chattype, Vector3 fromPos, string fromName,
  914. UUID sourceID, UUID ownerID, byte sourcetype, byte audible)
  915. {
  916. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  917. byte[] data = buf.Data;
  918. //setup header
  919. Buffer.BlockCopy(ChatFromSimulatorHeader, 0, data, 0, 10);
  920. int pos = 11;
  921. int len = Util.osUTF8Getbytes(fromName, data, 11, 255, true);
  922. data[10] = (byte)len;
  923. if (len > 0)
  924. pos += len;
  925. sourceID.ToBytes(data, pos); pos += 16;
  926. ownerID.ToBytes(data, pos); pos += 16;
  927. data[pos++] = sourcetype;
  928. data[pos++] = chattype;
  929. data[pos++] = audible;
  930. fromPos.ToBytes(data, pos); pos += 12;
  931. byte[] msg = Util.StringToBytes1024(message);
  932. len = msg.Length;
  933. if (len == 0)
  934. {
  935. data[pos++] = 0;
  936. data[pos++] = 0;
  937. }
  938. else
  939. {
  940. data[pos++] = (byte)len;
  941. data[pos++] = (byte)(len >> 8);
  942. Buffer.BlockCopy(msg, 0, data, pos, len); pos += len;
  943. }
  944. buf.DataLength = pos;
  945. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Unknown);
  946. }
  947. /// <summary>
  948. /// Send an instant message to this client
  949. /// </summary>
  950. //
  951. static private readonly byte[] ImprovedInstantMessageHeader = new byte[] {
  952. Helpers.MSG_RELIABLE, //| Helpers.MSG_ZEROCODED, not doing spec zeroencode on this
  953. 0, 0, 0, 0, // sequence number
  954. 0, // extra
  955. 0xff, 0xff, 0, 254 // ID 139 (low frequency bigendian)
  956. };
  957. public void SendInstantMessage(GridInstantMessage im)
  958. {
  959. UUID fromAgentID = new UUID(im.fromAgentID);
  960. UUID toAgentID = new UUID(im.toAgentID);
  961. if (!m_scene.Permissions.CanInstantMessage(fromAgentID, toAgentID))
  962. return;
  963. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  964. byte[] data = buf.Data;
  965. //setup header
  966. Buffer.BlockCopy(ImprovedInstantMessageHeader, 0, data, 0, 10);
  967. //agentdata block
  968. fromAgentID.ToBytes(data, 10); // 26
  969. UUID.Zero.ToBytes(data, 26); // 42 sessionID zero?? TO check
  970. int pos = 42;
  971. //MessageBlock
  972. data[pos++] = (byte)((im.fromGroup) ? 1 : 0);
  973. toAgentID.ToBytes(data, pos); pos += 16;
  974. Utils.UIntToBytesSafepos(im.ParentEstateID, data, pos); pos += 4;
  975. (new UUID(im.RegionID)).ToBytes(data, pos); pos += 16;
  976. (im.Position).ToBytes(data, pos); pos += 12;
  977. data[pos++] = im.offline;
  978. data[pos++] = im.dialog;
  979. // this is odd
  980. if (im.imSessionID == UUID.Zero.Guid)
  981. (fromAgentID ^ toAgentID).ToBytes(data, pos);
  982. else
  983. (new UUID(im.imSessionID)).ToBytes(data, pos);
  984. pos += 16;
  985. Utils.UIntToBytesSafepos(im.timestamp, data, pos); pos += 4;
  986. int len = Util.osUTF8Getbytes(im.fromAgentName, data, pos + 1, 255, true);
  987. data[pos++] = (byte)len;
  988. if (len > 0)
  989. pos += len;
  990. len = Util.osUTF8Getbytes(im.message, data, pos + 2, 1024, true);
  991. if (len == 0)
  992. {
  993. data[pos++] = 0;
  994. data[pos++] = 0;
  995. }
  996. else
  997. {
  998. data[pos++] = (byte)len;
  999. data[pos++] = (byte)(len >> 8);
  1000. pos += len;
  1001. }
  1002. byte[] tmp = im.binaryBucket;
  1003. if(tmp == null)
  1004. {
  1005. data[pos++] = 0;
  1006. data[pos++] = 0;
  1007. }
  1008. else
  1009. {
  1010. len = tmp.Length;
  1011. if (len == 0)
  1012. {
  1013. data[pos++] = 0;
  1014. data[pos++] = 0;
  1015. }
  1016. else
  1017. {
  1018. data[pos++] = (byte)len;
  1019. data[pos++] = (byte)(len >> 8);
  1020. Buffer.BlockCopy(tmp, 0, data, pos, len); pos += len;
  1021. }
  1022. }
  1023. //EstateBlock does not seem in use TODO
  1024. //Utils.UIntToBytesSafepos(m_scene.RegionInfo.EstateSettings.EstateID, data, pos); pos += 4;
  1025. data[pos++] = 0;
  1026. data[pos++] = 0;
  1027. data[pos++] = 0;
  1028. data[pos++] = 0;
  1029. buf.DataLength = pos;
  1030. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Unknown, null, false, true);
  1031. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Unknown);
  1032. }
  1033. static private readonly byte[] GenericMessageHeader = new byte[] {
  1034. Helpers.MSG_RELIABLE, //| Helpers.MSG_ZEROCODED, not doing spec zeroencode on this
  1035. 0, 0, 0, 0, // sequence number
  1036. 0, // extra
  1037. 0xff, 0xff, 1, 5 // ID 261 (low frequency bigendian)
  1038. };
  1039. public void SendGenericMessage(string method, UUID invoice, List<string> message)
  1040. {
  1041. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1042. byte[] data = buf.Data;
  1043. //setup header
  1044. Buffer.BlockCopy(GenericMessageHeader, 0, data, 0, 10);
  1045. //agentdata block
  1046. m_agentId.ToBytes(data, 10); // 26
  1047. m_sessionId.ToBytes(data, 26); // 42 sessionID zero?? TO check
  1048. UUID.Zero.ToBytes(data, 42); // 58
  1049. int pos = 58;
  1050. //method block
  1051. int len = Util.osUTF8Getbytes(method, data, pos + 1, 255, true);
  1052. data[pos++] = (byte)len;
  1053. if (len > 0)
  1054. pos += len;
  1055. invoice.ToBytes(data, pos); pos += 16;
  1056. //ParamList block
  1057. if (message.Count == 0)
  1058. {
  1059. data[pos++] = 0;
  1060. buf.DataLength = pos;
  1061. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, true);
  1062. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  1063. return;
  1064. }
  1065. int countpos = pos;
  1066. ++pos;
  1067. int count = 0;
  1068. for(int indx = 0; indx < message.Count; ++indx)
  1069. {
  1070. len = Util.osUTF8Getbytes(message[indx], data, pos + 1, 255, true);
  1071. data[pos++] = (byte)len;
  1072. if (len > 0)
  1073. pos += len;
  1074. if (pos > LLUDPServer.MAXPAYLOAD - 100)
  1075. {
  1076. data[countpos] = (byte)count;
  1077. buf.DataLength = pos;
  1078. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, true);
  1079. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  1080. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1081. Buffer.BlockCopy(data, 0, newbuf.Data, 0, countpos);
  1082. buf = newbuf;
  1083. data = buf.Data;
  1084. pos = countpos + 1;
  1085. count = 1;
  1086. }
  1087. else
  1088. ++count;
  1089. }
  1090. if (count > 0)
  1091. {
  1092. data[countpos] = (byte)count;
  1093. buf.DataLength = pos;
  1094. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, true);
  1095. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  1096. }
  1097. }
  1098. public void SendGenericMessage(string method, UUID invoice, List<byte[]> message)
  1099. {
  1100. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1101. byte[] data = buf.Data;
  1102. //setup header
  1103. Buffer.BlockCopy(GenericMessageHeader, 0, data, 0, 10);
  1104. //agentdata block
  1105. m_agentId.ToBytes(data, 10); // 26
  1106. m_sessionId.ToBytes(data, 26); // 42 sessionID zero?? TO check
  1107. UUID.Zero.ToBytes(data, 42); // 58
  1108. int pos = 58;
  1109. //method block
  1110. int len = Util.osUTF8Getbytes(method, data, pos + 1, 255, true);
  1111. data[pos++] = (byte)len;
  1112. if (len > 0)
  1113. pos += len;
  1114. invoice.ToBytes(data, pos); pos += 16;
  1115. //ParamList block
  1116. if (message.Count == 0)
  1117. {
  1118. data[pos++] = 0;
  1119. buf.DataLength = pos;
  1120. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, true);
  1121. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  1122. return;
  1123. }
  1124. int countpos = pos;
  1125. ++pos;
  1126. byte[] val;
  1127. int count = 0;
  1128. for (int indx = 0; indx < message.Count; ++indx)
  1129. {
  1130. val = message[indx];
  1131. len = val.Length;
  1132. if(len > 255)
  1133. len = 255;
  1134. if (pos + len >= LLUDPServer.MAXPAYLOAD)
  1135. {
  1136. data[countpos] = (byte)count;
  1137. buf.DataLength = pos;
  1138. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, true);
  1139. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  1140. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1141. Buffer.BlockCopy(data, 0, newbuf.Data, 0, countpos);
  1142. buf = newbuf;
  1143. data = buf.Data;
  1144. pos = countpos + 1;
  1145. count = 1;
  1146. }
  1147. else
  1148. ++count;
  1149. data[pos++] = (byte)len;
  1150. if (len > 0)
  1151. Buffer.BlockCopy(val, 0, data, pos, len); pos += len;
  1152. }
  1153. if (count > 0)
  1154. {
  1155. data[countpos] = (byte)count;
  1156. buf.DataLength = pos;
  1157. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, true);
  1158. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  1159. }
  1160. }
  1161. public void SendGroupActiveProposals(UUID groupID, UUID transactionID, GroupActiveProposals[] Proposals)
  1162. {
  1163. int i = 0;
  1164. foreach (GroupActiveProposals Proposal in Proposals)
  1165. {
  1166. GroupActiveProposalItemReplyPacket GAPIRP = new GroupActiveProposalItemReplyPacket();
  1167. GAPIRP.AgentData.AgentID = AgentId;
  1168. GAPIRP.AgentData.GroupID = groupID;
  1169. GAPIRP.TransactionData.TransactionID = transactionID;
  1170. GAPIRP.TransactionData.TotalNumItems = ((uint)i+1);
  1171. GroupActiveProposalItemReplyPacket.ProposalDataBlock ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock();
  1172. GAPIRP.ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock[1];
  1173. ProposalData.VoteCast = Utils.StringToBytes("false");
  1174. ProposalData.VoteID = new UUID(Proposal.VoteID);
  1175. ProposalData.VoteInitiator = new UUID(Proposal.VoteInitiator);
  1176. ProposalData.Majority = (float)Convert.ToInt32(Proposal.Majority);
  1177. ProposalData.Quorum = Convert.ToInt32(Proposal.Quorum);
  1178. ProposalData.TerseDateID = Utils.StringToBytes(Proposal.TerseDateID);
  1179. ProposalData.StartDateTime = Utils.StringToBytes(Proposal.StartDateTime);
  1180. ProposalData.EndDateTime = Utils.StringToBytes(Proposal.EndDateTime);
  1181. ProposalData.ProposalText = Utils.StringToBytes(Proposal.ProposalText);
  1182. ProposalData.AlreadyVoted = false;
  1183. GAPIRP.ProposalData[i] = ProposalData;
  1184. OutPacket(GAPIRP, ThrottleOutPacketType.Task);
  1185. i++;
  1186. }
  1187. if (Proposals.Length == 0)
  1188. {
  1189. GroupActiveProposalItemReplyPacket GAPIRP = new GroupActiveProposalItemReplyPacket();
  1190. GAPIRP.AgentData.AgentID = AgentId;
  1191. GAPIRP.AgentData.GroupID = groupID;
  1192. GAPIRP.TransactionData.TransactionID = transactionID;
  1193. GAPIRP.TransactionData.TotalNumItems = 1;
  1194. GroupActiveProposalItemReplyPacket.ProposalDataBlock ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock();
  1195. GAPIRP.ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock[1];
  1196. ProposalData.VoteCast = Utils.StringToBytes("false");
  1197. ProposalData.VoteID = UUID.Zero;
  1198. ProposalData.VoteInitiator = UUID.Zero;
  1199. ProposalData.Majority = 0;
  1200. ProposalData.Quorum = 0;
  1201. ProposalData.TerseDateID = Utils.StringToBytes("");
  1202. ProposalData.StartDateTime = Utils.StringToBytes("");
  1203. ProposalData.EndDateTime = Utils.StringToBytes("");
  1204. ProposalData.ProposalText = Utils.StringToBytes("");
  1205. ProposalData.AlreadyVoted = false;
  1206. GAPIRP.ProposalData[0] = ProposalData;
  1207. OutPacket(GAPIRP, ThrottleOutPacketType.Task);
  1208. }
  1209. }
  1210. public void SendGroupVoteHistory(UUID groupID, UUID transactionID, GroupVoteHistory[] Votes)
  1211. {
  1212. int i = 0;
  1213. foreach (GroupVoteHistory Vote in Votes)
  1214. {
  1215. GroupVoteHistoryItemReplyPacket GVHIRP = new GroupVoteHistoryItemReplyPacket();
  1216. GVHIRP.AgentData.AgentID = AgentId;
  1217. GVHIRP.AgentData.GroupID = groupID;
  1218. GVHIRP.TransactionData.TransactionID = transactionID;
  1219. GVHIRP.TransactionData.TotalNumItems = ((uint)i+1);
  1220. GVHIRP.HistoryItemData.VoteID = new UUID(Vote.VoteID);
  1221. GVHIRP.HistoryItemData.VoteInitiator = new UUID(Vote.VoteInitiator);
  1222. GVHIRP.HistoryItemData.Majority = (float)Convert.ToInt32(Vote.Majority);
  1223. GVHIRP.HistoryItemData.Quorum = Convert.ToInt32(Vote.Quorum);
  1224. GVHIRP.HistoryItemData.TerseDateID = Utils.StringToBytes(Vote.TerseDateID);
  1225. GVHIRP.HistoryItemData.StartDateTime = Utils.StringToBytes(Vote.StartDateTime);
  1226. GVHIRP.HistoryItemData.EndDateTime = Utils.StringToBytes(Vote.EndDateTime);
  1227. GVHIRP.HistoryItemData.VoteType = Utils.StringToBytes(Vote.VoteType);
  1228. GVHIRP.HistoryItemData.VoteResult = Utils.StringToBytes(Vote.VoteResult);
  1229. GVHIRP.HistoryItemData.ProposalText = Utils.StringToBytes(Vote.ProposalText);
  1230. GroupVoteHistoryItemReplyPacket.VoteItemBlock VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock();
  1231. GVHIRP.VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock[1];
  1232. VoteItem.CandidateID = UUID.Zero;
  1233. VoteItem.NumVotes = 0; //TODO: FIX THIS!!!
  1234. VoteItem.VoteCast = Utils.StringToBytes("Yes");
  1235. GVHIRP.VoteItem[i] = VoteItem;
  1236. OutPacket(GVHIRP, ThrottleOutPacketType.Task);
  1237. i++;
  1238. }
  1239. if (Votes.Length == 0)
  1240. {
  1241. GroupVoteHistoryItemReplyPacket GVHIRP = new GroupVoteHistoryItemReplyPacket();
  1242. GVHIRP.AgentData.AgentID = AgentId;
  1243. GVHIRP.AgentData.GroupID = groupID;
  1244. GVHIRP.TransactionData.TransactionID = transactionID;
  1245. GVHIRP.TransactionData.TotalNumItems = 0;
  1246. GVHIRP.HistoryItemData.VoteID = UUID.Zero;
  1247. GVHIRP.HistoryItemData.VoteInitiator = UUID.Zero;
  1248. GVHIRP.HistoryItemData.Majority = 0;
  1249. GVHIRP.HistoryItemData.Quorum = 0;
  1250. GVHIRP.HistoryItemData.TerseDateID = Utils.StringToBytes("");
  1251. GVHIRP.HistoryItemData.StartDateTime = Utils.StringToBytes("");
  1252. GVHIRP.HistoryItemData.EndDateTime = Utils.StringToBytes("");
  1253. GVHIRP.HistoryItemData.VoteType = Utils.StringToBytes("");
  1254. GVHIRP.HistoryItemData.VoteResult = Utils.StringToBytes("");
  1255. GVHIRP.HistoryItemData.ProposalText = Utils.StringToBytes("");
  1256. GroupVoteHistoryItemReplyPacket.VoteItemBlock VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock();
  1257. GVHIRP.VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock[1];
  1258. VoteItem.CandidateID = UUID.Zero;
  1259. VoteItem.NumVotes = 0; //TODO: FIX THIS!!!
  1260. VoteItem.VoteCast = Utils.StringToBytes("No");
  1261. GVHIRP.VoteItem[0] = VoteItem;
  1262. OutPacket(GVHIRP, ThrottleOutPacketType.Task);
  1263. }
  1264. }
  1265. public void SendGroupAccountingDetails(IClientAPI sender,UUID groupID, UUID transactionID, UUID sessionID, int amt)
  1266. {
  1267. GroupAccountDetailsReplyPacket GADRP = new GroupAccountDetailsReplyPacket();
  1268. GADRP.AgentData = new GroupAccountDetailsReplyPacket.AgentDataBlock();
  1269. GADRP.AgentData.AgentID = sender.AgentId;
  1270. GADRP.AgentData.GroupID = groupID;
  1271. GADRP.HistoryData = new GroupAccountDetailsReplyPacket.HistoryDataBlock[1];
  1272. GroupAccountDetailsReplyPacket.HistoryDataBlock History = new GroupAccountDetailsReplyPacket.HistoryDataBlock();
  1273. GADRP.MoneyData = new GroupAccountDetailsReplyPacket.MoneyDataBlock();
  1274. GADRP.MoneyData.CurrentInterval = 0;
  1275. GADRP.MoneyData.IntervalDays = 7;
  1276. GADRP.MoneyData.RequestID = transactionID;
  1277. GADRP.MoneyData.StartDate = Utils.StringToBytes(DateTime.Today.ToString());
  1278. History.Amount = amt;
  1279. History.Description = Utils.StringToBytes("");
  1280. GADRP.HistoryData[0] = History;
  1281. OutPacket(GADRP, ThrottleOutPacketType.Task);
  1282. }
  1283. public void SendGroupAccountingSummary(IClientAPI sender,UUID groupID, uint moneyAmt, int totalTier, int usedTier)
  1284. {
  1285. GroupAccountSummaryReplyPacket GASRP =
  1286. (GroupAccountSummaryReplyPacket)PacketPool.Instance.GetPacket(
  1287. PacketType.GroupAccountSummaryReply);
  1288. GASRP.AgentData = new GroupAccountSummaryReplyPacket.AgentDataBlock();
  1289. GASRP.AgentData.AgentID = sender.AgentId;
  1290. GASRP.AgentData.GroupID = groupID;
  1291. GASRP.MoneyData = new GroupAccountSummaryReplyPacket.MoneyDataBlock();
  1292. GASRP.MoneyData.Balance = (int)moneyAmt;
  1293. GASRP.MoneyData.TotalCredits = totalTier;
  1294. GASRP.MoneyData.TotalDebits = usedTier;
  1295. GASRP.MoneyData.StartDate = new byte[1];
  1296. GASRP.MoneyData.CurrentInterval = 1;
  1297. GASRP.MoneyData.GroupTaxCurrent = 0;
  1298. GASRP.MoneyData.GroupTaxEstimate = 0;
  1299. GASRP.MoneyData.IntervalDays = 0;
  1300. GASRP.MoneyData.LandTaxCurrent = 0;
  1301. GASRP.MoneyData.LandTaxEstimate = 0;
  1302. GASRP.MoneyData.LastTaxDate = new byte[1];
  1303. GASRP.MoneyData.LightTaxCurrent = 0;
  1304. GASRP.MoneyData.TaxDate = new byte[1];
  1305. GASRP.MoneyData.RequestID = sender.AgentId;
  1306. GASRP.MoneyData.ParcelDirFeeEstimate = 0;
  1307. GASRP.MoneyData.ParcelDirFeeCurrent = 0;
  1308. GASRP.MoneyData.ObjectTaxEstimate = 0;
  1309. GASRP.MoneyData.NonExemptMembers = 0;
  1310. GASRP.MoneyData.ObjectTaxCurrent = 0;
  1311. GASRP.MoneyData.LightTaxEstimate = 0;
  1312. OutPacket(GASRP, ThrottleOutPacketType.Task);
  1313. }
  1314. public void SendGroupTransactionsSummaryDetails(IClientAPI sender,UUID groupID, UUID transactionID, UUID sessionID, int amt)
  1315. {
  1316. GroupAccountTransactionsReplyPacket GATRP =
  1317. (GroupAccountTransactionsReplyPacket)PacketPool.Instance.GetPacket(
  1318. PacketType.GroupAccountTransactionsReply);
  1319. GATRP.AgentData = new GroupAccountTransactionsReplyPacket.AgentDataBlock();
  1320. GATRP.AgentData.AgentID = sender.AgentId;
  1321. GATRP.AgentData.GroupID = groupID;
  1322. GATRP.MoneyData = new GroupAccountTransactionsReplyPacket.MoneyDataBlock();
  1323. GATRP.MoneyData.CurrentInterval = 0;
  1324. GATRP.MoneyData.IntervalDays = 7;
  1325. GATRP.MoneyData.RequestID = transactionID;
  1326. GATRP.MoneyData.StartDate = Utils.StringToBytes(DateTime.Today.ToString());
  1327. GATRP.HistoryData = new GroupAccountTransactionsReplyPacket.HistoryDataBlock[1];
  1328. GroupAccountTransactionsReplyPacket.HistoryDataBlock History = new GroupAccountTransactionsReplyPacket.HistoryDataBlock();
  1329. History.Amount = 0;
  1330. History.Item = Utils.StringToBytes("");
  1331. History.Time = Utils.StringToBytes("");
  1332. History.Type = 0;
  1333. History.User = Utils.StringToBytes("");
  1334. GATRP.HistoryData[0] = History;
  1335. OutPacket(GATRP, ThrottleOutPacketType.Task);
  1336. }
  1337. public virtual bool CanSendLayerData()
  1338. {
  1339. int n = m_udpClient.GetPacketsQueuedCount(ThrottleOutPacketType.Land);
  1340. if ( n > 128)
  1341. return false;
  1342. return true;
  1343. }
  1344. /// <summary>
  1345. /// Send the region heightmap to the client
  1346. /// This method is only called when not doing intellegent terrain patch sending and
  1347. /// is only called when the scene presence is initially created and sends all of the
  1348. /// region's patches to the client.
  1349. /// </summary>
  1350. /// <param name="map">heightmap</param>
  1351. public virtual void SendLayerData()
  1352. {
  1353. Util.FireAndForget(DoSendLayerData, null, "LLClientView.DoSendLayerData");
  1354. }
  1355. /// <summary>
  1356. /// Send terrain layer information to the client.
  1357. /// </summary>
  1358. /// <param name="o"></param>
  1359. private void DoSendLayerData(object o)
  1360. {
  1361. TerrainData map = m_scene.Heightmap.GetTerrainData();
  1362. try
  1363. {
  1364. // Send LayerData in a spiral pattern. Fun!
  1365. SendLayerTopRight(0, 0, map.SizeX / Constants.TerrainPatchSize - 1, map.SizeY / Constants.TerrainPatchSize - 1);
  1366. }
  1367. catch (Exception e)
  1368. {
  1369. m_log.Error("[CLIENT]: SendLayerData() Failed with exception: " + e.Message, e);
  1370. }
  1371. }
  1372. private void SendLayerTopRight(int x1, int y1, int x2, int y2)
  1373. {
  1374. int[] p = new int[2];
  1375. // Row
  1376. p[1] = y1;
  1377. for (int i = x1; i <= x2; ++i)
  1378. {
  1379. p[0] = i;
  1380. SendLayerData(p);
  1381. }
  1382. // Column
  1383. p[0] = x2;
  1384. for (int j = y1 + 1; j <= y2; ++j)
  1385. {
  1386. p[1] = j;
  1387. SendLayerData(p);
  1388. }
  1389. if (x2 - x1 > 0 && y2 - y1 > 0)
  1390. SendLayerBottomLeft(x1, y1 + 1, x2 - 1, y2);
  1391. }
  1392. void SendLayerBottomLeft(int x1, int y1, int x2, int y2)
  1393. {
  1394. int[] p = new int[2];
  1395. // Row in reverse
  1396. p[1] = y2;
  1397. for (int i = x2; i >= x1; --i)
  1398. {
  1399. p[0] = i;
  1400. SendLayerData(p);
  1401. }
  1402. // Column in reverse
  1403. p[0] = x1;
  1404. for (int j = y2 - 1; j >= y1; --j)
  1405. {
  1406. p[1] = j;
  1407. SendLayerData(p);
  1408. }
  1409. if (x2 - x1 > 0 && y2 - y1 > 0)
  1410. SendLayerTopRight(x1 + 1, y1, x2, y2 - 1);
  1411. }
  1412. static private readonly byte[] TerrainPacketHeader = new byte[] {
  1413. Helpers.MSG_RELIABLE, // zero code is not as spec
  1414. 0, 0, 0, 0, // sequence number
  1415. 0, // extra
  1416. 11, // ID (high frequency)
  1417. };
  1418. private const int END_OF_PATCHES = 97;
  1419. private const int STRIDE = 264;
  1420. public void SendLayerData(int[] map)
  1421. {
  1422. if(map == null)
  1423. return;
  1424. try
  1425. {
  1426. TerrainData terrData = m_scene.Heightmap.GetTerrainData();
  1427. byte landPacketType = (terrData.SizeX > Constants.RegionSize || terrData.SizeY > Constants.RegionSize) ?
  1428. (byte)TerrainPatch.LayerType.LandExtended : (byte)TerrainPatch.LayerType.Land;
  1429. int numberPatchs = map.Length / 2;
  1430. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1431. byte[] data = buf.Data;
  1432. Buffer.BlockCopy(TerrainPacketHeader, 0, data, 0, 7);
  1433. data[7] = landPacketType;
  1434. //data[8] and data[9] == datablock size to fill later
  1435. data[10] = 0; // BitPack needs this on reused packets
  1436. // start data
  1437. BitPack bitpack = new BitPack(data, 10);
  1438. bitpack.PackBits(STRIDE, 16);
  1439. bitpack.PackBitsFromByte(16);
  1440. bitpack.PackBitsFromByte(landPacketType);
  1441. int s;
  1442. int datasize = 0;
  1443. for (int i = 0; i < numberPatchs; i++)
  1444. {
  1445. s = 2 * i;
  1446. OpenSimTerrainCompressor.CreatePatchFromTerrainData(bitpack, terrData, map[s], map[s + 1]);
  1447. if (bitpack.BytePos > 900 && i != numberPatchs - 1)
  1448. {
  1449. //finish this packet
  1450. bitpack.PackBitsFromByte(END_OF_PATCHES);
  1451. // fix the datablock lenght
  1452. datasize = bitpack.BytePos - 9;
  1453. data[8] = (byte)datasize;
  1454. data[9] = (byte)(datasize >> 8);
  1455. buf.DataLength = bitpack.BytePos + 1;
  1456. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
  1457. // start another
  1458. buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1459. data = buf.Data;
  1460. Buffer.BlockCopy(TerrainPacketHeader, 0, data, 0, 7);
  1461. data[7] = landPacketType;
  1462. //data[8] and data[9] == datablock size to fill later
  1463. data[10] = 0; // BitPack needs this
  1464. // start data
  1465. bitpack = new BitPack(data, 10);
  1466. bitpack.PackBits(STRIDE, 16);
  1467. bitpack.PackBitsFromByte(16);
  1468. bitpack.PackBitsFromByte(landPacketType);
  1469. }
  1470. }
  1471. bitpack.PackBitsFromByte(END_OF_PATCHES);
  1472. datasize = bitpack.BytePos - 9;
  1473. data[8] = (byte)datasize;
  1474. data[9] = (byte)(datasize >> 8);
  1475. buf.DataLength = bitpack.BytePos + 1;
  1476. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
  1477. }
  1478. catch (Exception e)
  1479. {
  1480. m_log.Error("[CLIENT]: SendLayerData() Failed with exception: " + e.Message, e);
  1481. }
  1482. }
  1483. private void DebugSendingPatches(string pWho, int[] pX, int[] pY)
  1484. {
  1485. if (m_log.IsDebugEnabled)
  1486. {
  1487. int numPatches = pX.Length;
  1488. string Xs = "";
  1489. string Ys = "";
  1490. for (int pp = 0; pp < numPatches; pp++)
  1491. {
  1492. Xs += String.Format("{0}", (int)pX[pp]) + ",";
  1493. Ys += String.Format("{0}", (int)pY[pp]) + ",";
  1494. }
  1495. m_log.DebugFormat("{0} {1}: numPatches={2}, X={3}, Y={4}", LogHeader, pWho, numPatches, Xs, Ys);
  1496. }
  1497. }
  1498. // wind caching
  1499. private static Dictionary<ulong,int> lastWindVersion = new Dictionary<ulong,int>();
  1500. private static Dictionary<ulong,List<LayerDataPacket>> lastWindPackets =
  1501. new Dictionary<ulong,List<LayerDataPacket>>();
  1502. /// <summary>
  1503. /// Send the wind matrix to the client
  1504. /// </summary>
  1505. /// <param name="windSpeeds">16x16 array of wind speeds</param>
  1506. public virtual void SendWindData(int version, Vector2[] windSpeeds)
  1507. {
  1508. // Vector2[] windSpeeds = (Vector2[])o;
  1509. ulong handle = this.Scene.RegionInfo.RegionHandle;
  1510. bool isNewData;
  1511. lock(lastWindPackets)
  1512. {
  1513. if(!lastWindVersion.ContainsKey(handle) ||
  1514. !lastWindPackets.ContainsKey(handle))
  1515. {
  1516. lastWindVersion[handle] = 0;
  1517. lastWindPackets[handle] = new List<LayerDataPacket>();
  1518. isNewData = true;
  1519. }
  1520. else
  1521. isNewData = lastWindVersion[handle] != version;
  1522. }
  1523. if(isNewData)
  1524. {
  1525. TerrainPatch[] patches = new TerrainPatch[2];
  1526. patches[0] = new TerrainPatch { Data = new float[16 * 16] };
  1527. patches[1] = new TerrainPatch { Data = new float[16 * 16] };
  1528. for (int x = 0; x < 16 * 16; x++)
  1529. {
  1530. patches[0].Data[x] = windSpeeds[x].X;
  1531. patches[1].Data[x] = windSpeeds[x].Y;
  1532. }
  1533. // neither we or viewers have extended wind
  1534. byte layerType = (byte)TerrainPatch.LayerType.Wind;
  1535. LayerDataPacket layerpack =
  1536. OpenSimTerrainCompressor.CreateLayerDataPacketStandardSize(
  1537. patches, layerType);
  1538. layerpack.Header.Zerocoded = true;
  1539. lock(lastWindPackets)
  1540. {
  1541. lastWindPackets[handle].Clear();
  1542. lastWindPackets[handle].Add(layerpack);
  1543. lastWindVersion[handle] = version;
  1544. }
  1545. }
  1546. lock(lastWindPackets)
  1547. foreach(LayerDataPacket pkt in lastWindPackets[handle])
  1548. OutPacket(pkt, ThrottleOutPacketType.Wind);
  1549. }
  1550. // cloud caching
  1551. private static Dictionary<ulong,int> lastCloudVersion = new Dictionary<ulong,int>();
  1552. private static Dictionary<ulong,List<LayerDataPacket>> lastCloudPackets =
  1553. new Dictionary<ulong,List<LayerDataPacket>>();
  1554. /// <summary>
  1555. /// Send the cloud matrix to the client
  1556. /// </summary>
  1557. /// <param name="windSpeeds">16x16 array of cloud densities</param>
  1558. public virtual void SendCloudData(int version, float[] cloudDensity)
  1559. {
  1560. ulong handle = this.Scene.RegionInfo.RegionHandle;
  1561. bool isNewData;
  1562. lock(lastWindPackets)
  1563. {
  1564. if(!lastCloudVersion.ContainsKey(handle) ||
  1565. !lastCloudPackets.ContainsKey(handle))
  1566. {
  1567. lastCloudVersion[handle] = 0;
  1568. lastCloudPackets[handle] = new List<LayerDataPacket>();
  1569. isNewData = true;
  1570. }
  1571. else
  1572. isNewData = lastCloudVersion[handle] != version;
  1573. }
  1574. if(isNewData)
  1575. {
  1576. TerrainPatch[] patches = new TerrainPatch[1];
  1577. patches[0] = new TerrainPatch();
  1578. patches[0].Data = new float[16 * 16];
  1579. for (int y = 0; y < 16; y++)
  1580. {
  1581. for (int x = 0; x < 16; x++)
  1582. {
  1583. patches[0].Data[y * 16 + x] = cloudDensity[y * 16 + x];
  1584. }
  1585. }
  1586. // neither we or viewers have extended clouds
  1587. byte layerType = (byte)TerrainPatch.LayerType.Cloud;
  1588. LayerDataPacket layerpack =
  1589. OpenSimTerrainCompressor.CreateLayerDataPacketStandardSize(
  1590. patches, layerType);
  1591. layerpack.Header.Zerocoded = true;
  1592. lock(lastCloudPackets)
  1593. {
  1594. lastCloudPackets[handle].Clear();
  1595. lastCloudPackets[handle].Add(layerpack);
  1596. lastCloudVersion[handle] = version;
  1597. }
  1598. }
  1599. lock(lastCloudPackets)
  1600. foreach(LayerDataPacket pkt in lastCloudPackets[handle])
  1601. OutPacket(pkt, ThrottleOutPacketType.Cloud);
  1602. }
  1603. /// <summary>
  1604. /// Tell the client that the given neighbour region is ready to receive a child agent.
  1605. /// </summary>
  1606. public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourEndPoint)
  1607. {
  1608. IPAddress neighbourIP = neighbourEndPoint.Address;
  1609. ushort neighbourPort = (ushort)neighbourEndPoint.Port;
  1610. EnableSimulatorPacket enablesimpacket = (EnableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.EnableSimulator);
  1611. // TODO: don't create new blocks if recycling an old packet
  1612. enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock();
  1613. enablesimpacket.SimulatorInfo.Handle = neighbourHandle;
  1614. byte[] byteIP = neighbourIP.GetAddressBytes();
  1615. enablesimpacket.SimulatorInfo.IP = (uint)byteIP[3] << 24;
  1616. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[2] << 16;
  1617. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[1] << 8;
  1618. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[0];
  1619. enablesimpacket.SimulatorInfo.Port = neighbourPort;
  1620. enablesimpacket.Header.Reliable = true; // ESP's should be reliable.
  1621. OutPacket(enablesimpacket, ThrottleOutPacketType.Task);
  1622. }
  1623. public AgentCircuitData RequestClientInfo()
  1624. {
  1625. AgentCircuitData agentData = new AgentCircuitData();
  1626. agentData.AgentID = AgentId;
  1627. agentData.SessionID = m_sessionId;
  1628. agentData.SecureSessionID = SecureSessionId;
  1629. agentData.circuitcode = m_circuitCode;
  1630. agentData.child = false;
  1631. agentData.firstname = m_firstName;
  1632. agentData.lastname = m_lastName;
  1633. ICapabilitiesModule capsModule = m_scene.RequestModuleInterface<ICapabilitiesModule>();
  1634. if (capsModule == null) // can happen when shutting down.
  1635. return agentData;
  1636. agentData.CapsPath = capsModule.GetCapsPath(m_agentId);
  1637. agentData.ChildrenCapSeeds = new Dictionary<ulong, string>(capsModule.GetChildrenSeeds(m_agentId));
  1638. return agentData;
  1639. }
  1640. public virtual void CrossRegion(ulong newRegionHandle, Vector3 pos, Vector3 lookAt, IPEndPoint externalIPEndPoint,
  1641. string capsURL)
  1642. {
  1643. Vector3 look = new Vector3(lookAt.X * 10, lookAt.Y * 10, lookAt.Z * 10);
  1644. //CrossedRegionPacket newSimPack = (CrossedRegionPacket)PacketPool.Instance.GetPacket(PacketType.CrossedRegion);
  1645. CrossedRegionPacket newSimPack = new CrossedRegionPacket();
  1646. // TODO: don't create new blocks if recycling an old packet
  1647. newSimPack.AgentData = new CrossedRegionPacket.AgentDataBlock();
  1648. newSimPack.AgentData.AgentID = AgentId;
  1649. newSimPack.AgentData.SessionID = m_sessionId;
  1650. newSimPack.Info = new CrossedRegionPacket.InfoBlock();
  1651. newSimPack.Info.Position = pos;
  1652. newSimPack.Info.LookAt = look;
  1653. newSimPack.RegionData = new CrossedRegionPacket.RegionDataBlock();
  1654. newSimPack.RegionData.RegionHandle = newRegionHandle;
  1655. byte[] byteIP = externalIPEndPoint.Address.GetAddressBytes();
  1656. newSimPack.RegionData.SimIP = (uint)byteIP[3] << 24;
  1657. newSimPack.RegionData.SimIP += (uint)byteIP[2] << 16;
  1658. newSimPack.RegionData.SimIP += (uint)byteIP[1] << 8;
  1659. newSimPack.RegionData.SimIP += (uint)byteIP[0];
  1660. newSimPack.RegionData.SimPort = (ushort)externalIPEndPoint.Port;
  1661. newSimPack.RegionData.SeedCapability = Util.StringToBytes256(capsURL);
  1662. // Hack to get this out immediately and skip throttles
  1663. OutPacket(newSimPack, ThrottleOutPacketType.Unknown);
  1664. }
  1665. static private readonly byte[] MapBlockItemHeader = new byte[] {
  1666. Helpers.MSG_RELIABLE,
  1667. 0, 0, 0, 0, // sequence number
  1668. 0, // extra
  1669. 0xff, 0xff, 1, 155 // ID 411 (low frequency bigendian)
  1670. };
  1671. public void SendMapItemReply(mapItemReply[] replies, uint mapitemtype, uint flags)
  1672. {
  1673. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1674. byte[] data = buf.Data;
  1675. //setup header and agentinfo block
  1676. Buffer.BlockCopy(MapBlockItemHeader, 0, data, 0, 10);
  1677. AgentId.ToBytes(data, 10); // 26
  1678. Utils.UIntToBytesSafepos(flags, data, 26); // 30
  1679. //RequestData block
  1680. Utils.UIntToBytesSafepos(mapitemtype, data, 30); // 34
  1681. int countpos = 34;
  1682. int pos = 35;
  1683. int lastpos = 0;
  1684. int capacity = LLUDPServer.MAXPAYLOAD - pos;
  1685. int count = 0;
  1686. mapItemReply mr;
  1687. for (int k = 0; k < replies.Length; ++k)
  1688. {
  1689. lastpos = pos;
  1690. mr = replies[k];
  1691. Utils.UIntToBytesSafepos(mr.x, data, pos); pos += 4;
  1692. Utils.UIntToBytesSafepos(mr.y, data, pos); pos += 4;
  1693. mr.id.ToBytes(data, pos); pos += 16;
  1694. Utils.IntToBytesSafepos(mr.Extra, data, pos); pos += 4;
  1695. Utils.IntToBytesSafepos(mr.Extra2, data, pos); pos += 4;
  1696. int len = Util.osUTF8Getbytes(mr.name, data, pos + 1, 255, true);
  1697. data[pos++] = (byte)len;
  1698. if (len > 0)
  1699. pos += len;
  1700. if (pos < capacity)
  1701. ++count;
  1702. else
  1703. {
  1704. // prepare next packet
  1705. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1706. Buffer.BlockCopy(data, 0, newbuf.Data, 0, 34);
  1707. // copy the block we already did
  1708. int alreadyDone = pos - lastpos;
  1709. Buffer.BlockCopy(data, lastpos, newbuf.Data, 35, alreadyDone); // 34 is datablock size
  1710. // finish current
  1711. data[countpos] = (byte)count;
  1712. buf.DataLength = lastpos;
  1713. // send it
  1714. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
  1715. buf = newbuf;
  1716. data = buf.Data;
  1717. pos = alreadyDone + 35;
  1718. capacity = LLUDPServer.MAXPAYLOAD - pos;
  1719. count = 1;
  1720. }
  1721. }
  1722. if (count > 0)
  1723. {
  1724. data[countpos] = (byte)count;
  1725. buf.DataLength = pos;
  1726. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
  1727. }
  1728. }
  1729. static private readonly byte[] MapBlockReplyHeader = new byte[] {
  1730. Helpers.MSG_RELIABLE,
  1731. 0, 0, 0, 0, // sequence number
  1732. 0, // extra
  1733. 0xff, 0xff, 1, 153 // ID 409 (low frequency bigendian)
  1734. };
  1735. public void SendMapBlock(List<MapBlockData> mapBlocks, uint flags)
  1736. {
  1737. ushort[] sizes = new ushort[2 * mapBlocks.Count];
  1738. bool needSizes = false;
  1739. int sizesptr = 0;
  1740. // check if we will need sizes block and get them aside
  1741. int count = 0;
  1742. ushort ut;
  1743. MapBlockData md;
  1744. for (int indx = 0; indx < mapBlocks.Count; ++indx)
  1745. {
  1746. md = mapBlocks[indx];
  1747. ut = md.SizeX;
  1748. sizes[count++] = ut;
  1749. if (ut > 256)
  1750. needSizes = true;
  1751. ut = md.SizeY;
  1752. sizes[count++] = ut;
  1753. if (ut > 256)
  1754. needSizes = true;
  1755. }
  1756. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1757. byte[] data = buf.Data;
  1758. //setup header and agentinfo block
  1759. Buffer.BlockCopy(MapBlockReplyHeader, 0, data, 0, 10);
  1760. AgentId.ToBytes(data, 10); // 26
  1761. Utils.UIntToBytesSafepos(flags, data, 26); // 30
  1762. int countpos = 30;
  1763. int pos = 31;
  1764. int lastpos = 0;
  1765. int capacity = LLUDPServer.MAXPAYLOAD - pos;
  1766. count = 0;
  1767. for (int indx = 0; indx < mapBlocks.Count; ++indx)
  1768. {
  1769. md = mapBlocks[indx];
  1770. lastpos = pos;
  1771. Utils.UInt16ToBytes(md.X, data, pos); pos += 2;
  1772. Utils.UInt16ToBytes(md.Y, data, pos); pos += 2;
  1773. int len = Util.osUTF8Getbytes(md.Name, data, pos + 1, 255, true);
  1774. data[pos++] = (byte)len;
  1775. if (len > 0)
  1776. pos += len;
  1777. data[pos++] = md.Access;
  1778. Utils.UIntToBytesSafepos(md.RegionFlags, data, pos); pos += 4;
  1779. data[pos++] = md.WaterHeight;
  1780. data[pos++] = md.Agents;
  1781. md.MapImageId.ToBytes(data, pos); pos += 16;
  1782. if(needSizes)
  1783. capacity -= 4; // 2 shorts per entry
  1784. if(pos < capacity)
  1785. ++count;
  1786. else
  1787. {
  1788. // prepare next packet
  1789. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  1790. Buffer.BlockCopy(data, 0, newbuf.Data, 0, 30);
  1791. // copy the block we already did
  1792. int alreadyDone = pos - lastpos;
  1793. Buffer.BlockCopy(data, lastpos, newbuf.Data, 31, alreadyDone); // 30 is datablock size
  1794. // finish current
  1795. data[countpos] = (byte)count;
  1796. if (needSizes)
  1797. {
  1798. data[lastpos++] = (byte)count;
  1799. while (--count >= 0)
  1800. {
  1801. Utils.UInt16ToBytes(sizes[sizesptr++], data, lastpos); lastpos += 2;
  1802. Utils.UInt16ToBytes(sizes[sizesptr++], data, lastpos); lastpos += 2;
  1803. }
  1804. }
  1805. else
  1806. data[lastpos++] = 0;
  1807. buf.DataLength = lastpos;
  1808. // send it
  1809. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
  1810. buf = newbuf;
  1811. data = buf.Data;
  1812. pos = alreadyDone + 31;
  1813. capacity = LLUDPServer.MAXPAYLOAD - pos;
  1814. if (needSizes)
  1815. capacity -= 4; // 2 shorts per entry
  1816. count = 1;
  1817. }
  1818. }
  1819. if (count > 0)
  1820. {
  1821. data[countpos] = (byte)count;
  1822. if (needSizes)
  1823. {
  1824. data[pos++] = (byte)count;
  1825. while (--count >= 0)
  1826. {
  1827. Utils.UInt16ToBytes(sizes[sizesptr++], data, pos); pos += 2;
  1828. Utils.UInt16ToBytes(sizes[sizesptr++], data, pos); pos += 2;
  1829. }
  1830. }
  1831. else
  1832. data[pos++] = 0;
  1833. buf.DataLength = pos;
  1834. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
  1835. }
  1836. }
  1837. public void SendLocalTeleport(Vector3 position, Vector3 lookAt, uint flags)
  1838. {
  1839. TeleportLocalPacket tpLocal = (TeleportLocalPacket)PacketPool.Instance.GetPacket(PacketType.TeleportLocal);
  1840. tpLocal.Info.AgentID = AgentId;
  1841. tpLocal.Info.TeleportFlags = flags;
  1842. tpLocal.Info.LocationID = 2;
  1843. tpLocal.Info.LookAt = lookAt;
  1844. tpLocal.Info.Position = position;
  1845. // Hack to get this out immediately and skip throttles
  1846. OutPacket(tpLocal, ThrottleOutPacketType.Unknown);
  1847. }
  1848. public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint newRegionEndPoint, uint locationID,
  1849. uint flags, string capsURL)
  1850. {
  1851. //TeleportFinishPacket teleport = (TeleportFinishPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFinish);
  1852. TeleportFinishPacket teleport = new TeleportFinishPacket();
  1853. teleport.Info.AgentID = AgentId;
  1854. teleport.Info.RegionHandle = regionHandle;
  1855. teleport.Info.SimAccess = simAccess;
  1856. teleport.Info.SeedCapability = Util.StringToBytes256(capsURL);
  1857. IPAddress oIP = newRegionEndPoint.Address;
  1858. byte[] byteIP = oIP.GetAddressBytes();
  1859. uint ip = (uint)byteIP[3] << 24;
  1860. ip += (uint)byteIP[2] << 16;
  1861. ip += (uint)byteIP[1] << 8;
  1862. ip += (uint)byteIP[0];
  1863. teleport.Info.SimIP = ip;
  1864. teleport.Info.SimPort = (ushort)newRegionEndPoint.Port;
  1865. teleport.Info.LocationID = 4;
  1866. teleport.Info.TeleportFlags = 1 << 4;
  1867. // Hack to get this out immediately and skip throttles.
  1868. OutPacket(teleport, ThrottleOutPacketType.Unknown);
  1869. }
  1870. /// <summary>
  1871. /// Inform the client that a teleport attempt has failed
  1872. /// </summary>
  1873. public void SendTeleportFailed(string reason)
  1874. {
  1875. TeleportFailedPacket tpFailed = (TeleportFailedPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFailed);
  1876. tpFailed.Info.AgentID = AgentId;
  1877. tpFailed.Info.Reason = Util.StringToBytes256(reason);
  1878. tpFailed.AlertInfo = new TeleportFailedPacket.AlertInfoBlock[0];
  1879. // Hack to get this out immediately and skip throttles
  1880. OutPacket(tpFailed, ThrottleOutPacketType.Unknown);
  1881. }
  1882. /// <summary>
  1883. ///
  1884. /// </summary>
  1885. public void SendTeleportStart(uint flags)
  1886. {
  1887. TeleportStartPacket tpStart = (TeleportStartPacket)PacketPool.Instance.GetPacket(PacketType.TeleportStart);
  1888. //TeleportStartPacket tpStart = new TeleportStartPacket();
  1889. tpStart.Info.TeleportFlags = flags; //16; // Teleport via location
  1890. // Hack to get this out immediately and skip throttles
  1891. OutPacket(tpStart, ThrottleOutPacketType.Unknown);
  1892. }
  1893. public void SendTeleportProgress(uint flags, string message)
  1894. {
  1895. TeleportProgressPacket tpProgress = (TeleportProgressPacket)PacketPool.Instance.GetPacket(PacketType.TeleportProgress);
  1896. tpProgress.AgentData.AgentID = this.AgentId;
  1897. tpProgress.Info.TeleportFlags = flags;
  1898. tpProgress.Info.Message = Util.StringToBytes256(message);
  1899. // Hack to get this out immediately and skip throttles
  1900. OutPacket(tpProgress, ThrottleOutPacketType.Unknown);
  1901. }
  1902. 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)
  1903. {
  1904. MoneyBalanceReplyPacket money = (MoneyBalanceReplyPacket)PacketPool.Instance.GetPacket(PacketType.MoneyBalanceReply);
  1905. money.MoneyData.AgentID = AgentId;
  1906. money.MoneyData.TransactionID = transaction;
  1907. money.MoneyData.TransactionSuccess = success;
  1908. money.MoneyData.Description = description;
  1909. money.MoneyData.MoneyBalance = balance;
  1910. money.TransactionInfo.TransactionType = transactionType;
  1911. money.TransactionInfo.SourceID = sourceID;
  1912. money.TransactionInfo.IsSourceGroup = sourceIsGroup;
  1913. money.TransactionInfo.DestID = destID;
  1914. money.TransactionInfo.IsDestGroup = destIsGroup;
  1915. money.TransactionInfo.Amount = amount;
  1916. money.TransactionInfo.ItemDescription = Util.StringToBytes256(item);
  1917. OutPacket(money, ThrottleOutPacketType.Task);
  1918. }
  1919. public void SendPayPrice(UUID objectID, int[] payPrice)
  1920. {
  1921. if (payPrice[0] == 0 &&
  1922. payPrice[1] == 0 &&
  1923. payPrice[2] == 0 &&
  1924. payPrice[3] == 0 &&
  1925. payPrice[4] == 0)
  1926. return;
  1927. PayPriceReplyPacket payPriceReply = (PayPriceReplyPacket)PacketPool.Instance.GetPacket(PacketType.PayPriceReply);
  1928. payPriceReply.ObjectData.ObjectID = objectID;
  1929. payPriceReply.ObjectData.DefaultPayPrice = payPrice[0];
  1930. payPriceReply.ButtonData = new PayPriceReplyPacket.ButtonDataBlock[4];
  1931. payPriceReply.ButtonData[0] = new PayPriceReplyPacket.ButtonDataBlock();
  1932. payPriceReply.ButtonData[0].PayButton = payPrice[1];
  1933. payPriceReply.ButtonData[1] = new PayPriceReplyPacket.ButtonDataBlock();
  1934. payPriceReply.ButtonData[1].PayButton = payPrice[2];
  1935. payPriceReply.ButtonData[2] = new PayPriceReplyPacket.ButtonDataBlock();
  1936. payPriceReply.ButtonData[2].PayButton = payPrice[3];
  1937. payPriceReply.ButtonData[3] = new PayPriceReplyPacket.ButtonDataBlock();
  1938. payPriceReply.ButtonData[3].PayButton = payPrice[4];
  1939. OutPacket(payPriceReply, ThrottleOutPacketType.Task);
  1940. }
  1941. public void SendKillObject(List<uint> localIDs)
  1942. {
  1943. // foreach (uint id in localIDs)
  1944. // m_log.DebugFormat("[CLIENT]: Sending KillObjectPacket to {0} for {1} in {2}", Name, id, regionHandle);
  1945. // remove pending entities to reduce looping chances.
  1946. lock (m_entityProps.SyncRoot)
  1947. m_entityProps.Remove(localIDs);
  1948. lock (m_entityUpdates.SyncRoot)
  1949. m_entityUpdates.Remove(localIDs);
  1950. KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
  1951. int perpacket = localIDs.Count;
  1952. if(perpacket > 200)
  1953. perpacket = 200;
  1954. int nsent = 0;
  1955. kill.ObjectData = new KillObjectPacket.ObjectDataBlock[perpacket];
  1956. for (int i = 0 ; i < localIDs.Count ; i++ )
  1957. {
  1958. kill.ObjectData[nsent] = new KillObjectPacket.ObjectDataBlock();
  1959. kill.ObjectData[nsent].ID = localIDs[i];
  1960. if(++nsent >= 200)
  1961. {
  1962. OutPacket(kill, ThrottleOutPacketType.Task);
  1963. perpacket = localIDs.Count - i - 1;
  1964. if(perpacket == 0)
  1965. break;
  1966. if(perpacket > 200)
  1967. perpacket = 200;
  1968. kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
  1969. kill.ObjectData = new KillObjectPacket.ObjectDataBlock[perpacket];
  1970. nsent = 0;
  1971. }
  1972. }
  1973. if(nsent != 0)
  1974. {
  1975. OutPacket(kill, ThrottleOutPacketType.Task);
  1976. }
  1977. }
  1978. /// <summary>
  1979. /// Send information about the items contained in a folder to the client.
  1980. /// </summary>
  1981. /// <remarks>
  1982. /// XXX This method needs some refactoring loving
  1983. /// </remarks>
  1984. /// <param name="ownerID">The owner of the folder</param>
  1985. /// <param name="folderID">The id of the folder</param>
  1986. /// <param name="items">The items contained in the folder identified by folderID</param>
  1987. /// <param name="folders"></param>
  1988. /// <param name="fetchFolders">Do we need to send folder information?</param>
  1989. /// <param name="fetchItems">Do we need to send item information?</param>
  1990. public void SendInventoryFolderDetails(UUID ownerID, UUID folderID, List<InventoryItemBase> items,
  1991. List<InventoryFolderBase> folders, int version, int descendents,
  1992. bool fetchFolders, bool fetchItems)
  1993. {
  1994. // An inventory descendents packet consists of a single agent section and an inventory details
  1995. // section for each inventory item. The size of each inventory item is approximately 550 bytes.
  1996. // limit to what may fit on MTU
  1997. int MAX_ITEMS_PER_PACKET = 5;
  1998. int MAX_FOLDERS_PER_PACKET = 6;
  1999. int totalItems = fetchItems ? items.Count : 0;
  2000. int totalFolders = fetchFolders ? folders.Count : 0;
  2001. int itemsSent = 0;
  2002. int foldersSent = 0;
  2003. int foldersToSend = 0;
  2004. int itemsToSend = 0;
  2005. InventoryDescendentsPacket currentPacket = null;
  2006. // Handle empty folders
  2007. //
  2008. if (totalItems == 0 && totalFolders == 0)
  2009. currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, descendents, 0, 0);
  2010. // To preserve SL compatibility, we will NOT combine folders and items in one packet
  2011. //
  2012. while (itemsSent < totalItems || foldersSent < totalFolders)
  2013. {
  2014. if (currentPacket == null) // Start a new packet
  2015. {
  2016. foldersToSend = totalFolders - foldersSent;
  2017. if (foldersToSend > MAX_FOLDERS_PER_PACKET)
  2018. foldersToSend = MAX_FOLDERS_PER_PACKET;
  2019. if (foldersToSend == 0)
  2020. {
  2021. itemsToSend = totalItems - itemsSent;
  2022. if (itemsToSend > MAX_ITEMS_PER_PACKET)
  2023. itemsToSend = MAX_ITEMS_PER_PACKET;
  2024. }
  2025. currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, descendents, foldersToSend, itemsToSend);
  2026. }
  2027. if (foldersToSend-- > 0)
  2028. currentPacket.FolderData[foldersSent % MAX_FOLDERS_PER_PACKET] = CreateFolderDataBlock(folders[foldersSent++]);
  2029. else if (itemsToSend-- > 0)
  2030. currentPacket.ItemData[itemsSent % MAX_ITEMS_PER_PACKET] = CreateItemDataBlock(items[itemsSent++]);
  2031. else
  2032. {
  2033. // m_log.DebugFormat(
  2034. // "[LLCLIENTVIEW]: Sending inventory folder details packet to {0} for folder {1}", Name, folderID);
  2035. OutPacket(currentPacket, ThrottleOutPacketType.Asset, false);
  2036. currentPacket = null;
  2037. }
  2038. }
  2039. if (currentPacket != null)
  2040. {
  2041. // m_log.DebugFormat(
  2042. // "[LLCLIENTVIEW]: Sending inventory folder details packet to {0} for folder {1}", Name, folderID);
  2043. OutPacket(currentPacket, ThrottleOutPacketType.Asset, false);
  2044. }
  2045. }
  2046. private InventoryDescendentsPacket.FolderDataBlock CreateFolderDataBlock(InventoryFolderBase folder)
  2047. {
  2048. InventoryDescendentsPacket.FolderDataBlock newBlock = new InventoryDescendentsPacket.FolderDataBlock();
  2049. newBlock.FolderID = folder.ID;
  2050. newBlock.Name = Util.StringToBytes256(folder.Name);
  2051. newBlock.ParentID = folder.ParentID;
  2052. newBlock.Type = (sbyte)folder.Type;
  2053. //if (newBlock.Type == InventoryItemBase.SUITCASE_FOLDER_TYPE)
  2054. // newBlock.Type = InventoryItemBase.SUITCASE_FOLDER_FAKE_TYPE;
  2055. return newBlock;
  2056. }
  2057. private InventoryDescendentsPacket.ItemDataBlock CreateItemDataBlock(InventoryItemBase item)
  2058. {
  2059. InventoryDescendentsPacket.ItemDataBlock newBlock = new InventoryDescendentsPacket.ItemDataBlock();
  2060. newBlock.ItemID = item.ID;
  2061. newBlock.AssetID = item.AssetID;
  2062. newBlock.CreatorID = item.CreatorIdAsUuid;
  2063. newBlock.BaseMask = item.BasePermissions;
  2064. newBlock.Description = Util.StringToBytes256(item.Description);
  2065. newBlock.EveryoneMask = item.EveryOnePermissions;
  2066. newBlock.OwnerMask = item.CurrentPermissions;
  2067. newBlock.FolderID = item.Folder;
  2068. newBlock.InvType = (sbyte)item.InvType;
  2069. newBlock.Name = Util.StringToBytes256(item.Name);
  2070. newBlock.NextOwnerMask = item.NextPermissions;
  2071. newBlock.OwnerID = item.Owner;
  2072. newBlock.Type = (sbyte)item.AssetType;
  2073. newBlock.GroupID = item.GroupID;
  2074. newBlock.GroupOwned = item.GroupOwned;
  2075. newBlock.GroupMask = item.GroupPermissions;
  2076. newBlock.CreationDate = item.CreationDate;
  2077. newBlock.SalePrice = item.SalePrice;
  2078. newBlock.SaleType = item.SaleType;
  2079. newBlock.Flags = item.Flags & 0x2000ff;
  2080. newBlock.CRC =
  2081. Helpers.InventoryCRC(newBlock.CreationDate, newBlock.SaleType,
  2082. newBlock.InvType, newBlock.Type,
  2083. newBlock.AssetID, newBlock.GroupID,
  2084. newBlock.SalePrice,
  2085. newBlock.OwnerID, newBlock.CreatorID,
  2086. newBlock.ItemID, newBlock.FolderID,
  2087. newBlock.EveryoneMask,
  2088. newBlock.Flags, newBlock.OwnerMask,
  2089. newBlock.GroupMask, newBlock.NextOwnerMask);
  2090. return newBlock;
  2091. }
  2092. private void AddNullFolderBlockToDecendentsPacket(ref InventoryDescendentsPacket packet)
  2093. {
  2094. packet.FolderData = new InventoryDescendentsPacket.FolderDataBlock[1];
  2095. packet.FolderData[0] = new InventoryDescendentsPacket.FolderDataBlock();
  2096. packet.FolderData[0].FolderID = UUID.Zero;
  2097. packet.FolderData[0].ParentID = UUID.Zero;
  2098. packet.FolderData[0].Type = -1;
  2099. packet.FolderData[0].Name = new byte[0];
  2100. }
  2101. private void AddNullItemBlockToDescendentsPacket(ref InventoryDescendentsPacket packet)
  2102. {
  2103. packet.ItemData = new InventoryDescendentsPacket.ItemDataBlock[1];
  2104. packet.ItemData[0] = new InventoryDescendentsPacket.ItemDataBlock();
  2105. packet.ItemData[0].ItemID = UUID.Zero;
  2106. packet.ItemData[0].AssetID = UUID.Zero;
  2107. packet.ItemData[0].CreatorID = UUID.Zero;
  2108. packet.ItemData[0].BaseMask = 0;
  2109. packet.ItemData[0].Description = new byte[0];
  2110. packet.ItemData[0].EveryoneMask = 0;
  2111. packet.ItemData[0].OwnerMask = 0;
  2112. packet.ItemData[0].FolderID = UUID.Zero;
  2113. packet.ItemData[0].InvType = (sbyte)0;
  2114. packet.ItemData[0].Name = new byte[0];
  2115. packet.ItemData[0].NextOwnerMask = 0;
  2116. packet.ItemData[0].OwnerID = UUID.Zero;
  2117. packet.ItemData[0].Type = -1;
  2118. packet.ItemData[0].GroupID = UUID.Zero;
  2119. packet.ItemData[0].GroupOwned = false;
  2120. packet.ItemData[0].GroupMask = 0;
  2121. packet.ItemData[0].CreationDate = 0;
  2122. packet.ItemData[0].SalePrice = 0;
  2123. packet.ItemData[0].SaleType = 0;
  2124. packet.ItemData[0].Flags = 0;
  2125. // No need to add CRC
  2126. }
  2127. private InventoryDescendentsPacket CreateInventoryDescendentsPacket(UUID ownerID, UUID folderID, int version, int descendents, int folders, int items)
  2128. {
  2129. InventoryDescendentsPacket descend = (InventoryDescendentsPacket)PacketPool.Instance.GetPacket(PacketType.InventoryDescendents);
  2130. descend.Header.Zerocoded = true;
  2131. descend.AgentData.AgentID = AgentId;
  2132. descend.AgentData.OwnerID = ownerID;
  2133. descend.AgentData.FolderID = folderID;
  2134. descend.AgentData.Version = version;
  2135. descend.AgentData.Descendents = descendents;
  2136. if (folders > 0)
  2137. descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders];
  2138. else
  2139. AddNullFolderBlockToDecendentsPacket(ref descend);
  2140. if (items > 0)
  2141. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items];
  2142. else
  2143. AddNullItemBlockToDescendentsPacket(ref descend);
  2144. return descend;
  2145. }
  2146. public void SendInventoryItemDetails(InventoryItemBase[] items)
  2147. {
  2148. // Fudge this value. It's only needed to make the CRC anyway
  2149. const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff;
  2150. FetchInventoryReplyPacket inventoryReply = (FetchInventoryReplyPacket)PacketPool.Instance.GetPacket(PacketType.FetchInventoryReply);
  2151. inventoryReply.AgentData.AgentID = AgentId;
  2152. int total = items.Length;
  2153. int count = 0;
  2154. for(int i = 0; i < items.Length; ++i)
  2155. {
  2156. if(count == 0)
  2157. {
  2158. if(total < 10)
  2159. {
  2160. inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[total];
  2161. total = 0;
  2162. }
  2163. else
  2164. {
  2165. inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[10];
  2166. total -= 10;
  2167. }
  2168. }
  2169. inventoryReply.InventoryData[count] = new FetchInventoryReplyPacket.InventoryDataBlock();
  2170. FetchInventoryReplyPacket.InventoryDataBlock data = inventoryReply.InventoryData[count];
  2171. data.ItemID = items[i].ID;
  2172. data.AssetID = items[i].AssetID;
  2173. data.CreatorID = items[i].CreatorIdAsUuid;
  2174. data.BaseMask = items[i].BasePermissions;
  2175. data.CreationDate = items[i].CreationDate;
  2176. data.Description = Util.StringToBytes256(items[i].Description);
  2177. data.EveryoneMask = items[i].EveryOnePermissions;
  2178. data.FolderID = items[i].Folder;
  2179. data.InvType = (sbyte)items[i].InvType;
  2180. data.Name = Util.StringToBytes256(items[i].Name);
  2181. data.NextOwnerMask = items[i].NextPermissions;
  2182. data.OwnerID = items[i].Owner;
  2183. data.OwnerMask = items[i].CurrentPermissions;
  2184. data.Type = (sbyte)items[i].AssetType;
  2185. data.GroupID = items[i].GroupID;
  2186. data.GroupOwned = items[i].GroupOwned;
  2187. data.GroupMask = items[i].GroupPermissions;
  2188. data.Flags = items[i].Flags;
  2189. data.SalePrice = items[i].SalePrice;
  2190. data.SaleType = items[i].SaleType;
  2191. data.CRC = Helpers.InventoryCRC(
  2192. 1000, 0, data.InvType, data.Type, data.AssetID,
  2193. data.GroupID, 100, data.OwnerID, data.CreatorID,
  2194. data.ItemID, data.FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  2195. FULL_MASK_PERMISSIONS);
  2196. ++count;
  2197. if(count == 10 || total == 0)
  2198. {
  2199. inventoryReply.Header.Zerocoded = true;
  2200. OutPacket(inventoryReply, ThrottleOutPacketType.Asset);
  2201. if(total == 0)
  2202. break;
  2203. count = 0;
  2204. }
  2205. }
  2206. }
  2207. protected void SendBulkUpdateInventoryFolder(InventoryFolderBase folderBase, UUID? transationID)
  2208. {
  2209. // We will use the same transaction id for all the separate packets to be sent out in this update.
  2210. UUID transactionId = transationID ?? UUID.Random();
  2211. List<BulkUpdateInventoryPacket.FolderDataBlock> folderDataBlocks
  2212. = new List<BulkUpdateInventoryPacket.FolderDataBlock>();
  2213. SendBulkUpdateInventoryFolderRecursive(folderBase, ref folderDataBlocks, transactionId);
  2214. if (folderDataBlocks.Count > 0)
  2215. {
  2216. // We'll end up with some unsent folder blocks if there were some empty folders at the end of the list
  2217. // Send these now
  2218. BulkUpdateInventoryPacket bulkUpdate
  2219. = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
  2220. bulkUpdate.Header.Zerocoded = true;
  2221. bulkUpdate.AgentData.AgentID = AgentId;
  2222. bulkUpdate.AgentData.TransactionID = transactionId;
  2223. bulkUpdate.FolderData = folderDataBlocks.ToArray();
  2224. List<BulkUpdateInventoryPacket.ItemDataBlock> foo = new List<BulkUpdateInventoryPacket.ItemDataBlock>();
  2225. bulkUpdate.ItemData = foo.ToArray();
  2226. //m_log.Debug("SendBulkUpdateInventory :" + bulkUpdate);
  2227. OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
  2228. }
  2229. }
  2230. /// <summary>
  2231. /// Recursively construct bulk update packets to send folders and items
  2232. /// </summary>
  2233. /// <param name="folder"></param>
  2234. /// <param name="folderDataBlocks"></param>
  2235. /// <param name="transactionId"></param>
  2236. private void SendBulkUpdateInventoryFolderRecursive(
  2237. InventoryFolderBase folder, ref List<BulkUpdateInventoryPacket.FolderDataBlock> folderDataBlocks,
  2238. UUID transactionId)
  2239. {
  2240. folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder));
  2241. const int MAX_ITEMS_PER_PACKET = 5;
  2242. IInventoryService invService = m_scene.RequestModuleInterface<IInventoryService>();
  2243. // If there are any items then we have to start sending them off in this packet - the next folder will have
  2244. // to be in its own bulk update packet. Also, we can only fit 5 items in a packet (at least this was the limit
  2245. // being used on the Linden grid at 20081203).
  2246. InventoryCollection contents = invService.GetFolderContent(AgentId, folder.ID); // folder.RequestListOfItems();
  2247. List<InventoryItemBase> items = contents.Items;
  2248. while (items.Count > 0)
  2249. {
  2250. BulkUpdateInventoryPacket bulkUpdate
  2251. = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
  2252. bulkUpdate.Header.Zerocoded = true;
  2253. bulkUpdate.AgentData.AgentID = AgentId;
  2254. bulkUpdate.AgentData.TransactionID = transactionId;
  2255. bulkUpdate.FolderData = folderDataBlocks.ToArray();
  2256. int itemsToSend = (items.Count > MAX_ITEMS_PER_PACKET ? MAX_ITEMS_PER_PACKET : items.Count);
  2257. bulkUpdate.ItemData = new BulkUpdateInventoryPacket.ItemDataBlock[itemsToSend];
  2258. for (int i = 0; i < itemsToSend; i++)
  2259. {
  2260. // Remove from the end of the list so that we don't incur a performance penalty
  2261. bulkUpdate.ItemData[i] = GenerateBulkUpdateItemDataBlock(items[items.Count - 1]);
  2262. items.RemoveAt(items.Count - 1);
  2263. }
  2264. //m_log.Debug("SendBulkUpdateInventoryRecursive :" + bulkUpdate);
  2265. OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
  2266. folderDataBlocks = new List<BulkUpdateInventoryPacket.FolderDataBlock>();
  2267. // If we're going to be sending another items packet then it needs to contain just the folder to which those
  2268. // items belong.
  2269. if (items.Count > 0)
  2270. folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder));
  2271. }
  2272. List<InventoryFolderBase> subFolders = contents.Folders;
  2273. for (int indx = 0; indx < subFolders.Count; ++indx)
  2274. {
  2275. SendBulkUpdateInventoryFolderRecursive(subFolders[indx], ref folderDataBlocks, transactionId);
  2276. }
  2277. }
  2278. /// <summary>
  2279. /// Generate a bulk update inventory data block for the given folder
  2280. /// </summary>
  2281. /// <param name="folder"></param>
  2282. /// <returns></returns>
  2283. private BulkUpdateInventoryPacket.FolderDataBlock GenerateBulkUpdateFolderDataBlock(InventoryFolderBase folder)
  2284. {
  2285. BulkUpdateInventoryPacket.FolderDataBlock folderBlock = new BulkUpdateInventoryPacket.FolderDataBlock();
  2286. folderBlock.FolderID = folder.ID;
  2287. folderBlock.ParentID = folder.ParentID;
  2288. folderBlock.Type = (sbyte)folder.Type;
  2289. // Leaving this here for now, just in case we need to do this for a while
  2290. //if (folderBlock.Type == InventoryItemBase.SUITCASE_FOLDER_TYPE)
  2291. // folderBlock.Type = InventoryItemBase.SUITCASE_FOLDER_FAKE_TYPE;
  2292. folderBlock.Name = Util.StringToBytes256(folder.Name);
  2293. return folderBlock;
  2294. }
  2295. /// <summary>
  2296. /// Generate a bulk update inventory data block for the given item
  2297. /// </summary>
  2298. /// <param name="item"></param>
  2299. /// <returns></returns>
  2300. private BulkUpdateInventoryPacket.ItemDataBlock GenerateBulkUpdateItemDataBlock(InventoryItemBase item)
  2301. {
  2302. BulkUpdateInventoryPacket.ItemDataBlock itemBlock = new BulkUpdateInventoryPacket.ItemDataBlock();
  2303. itemBlock.ItemID = item.ID;
  2304. itemBlock.AssetID = item.AssetID;
  2305. itemBlock.CreatorID = item.CreatorIdAsUuid;
  2306. itemBlock.BaseMask = item.BasePermissions;
  2307. itemBlock.Description = Util.StringToBytes256(item.Description);
  2308. itemBlock.EveryoneMask = item.EveryOnePermissions;
  2309. itemBlock.FolderID = item.Folder;
  2310. itemBlock.InvType = (sbyte)item.InvType;
  2311. itemBlock.Name = Util.StringToBytes256(item.Name);
  2312. itemBlock.NextOwnerMask = item.NextPermissions;
  2313. itemBlock.OwnerID = item.Owner;
  2314. itemBlock.OwnerMask = item.CurrentPermissions;
  2315. itemBlock.Type = (sbyte)item.AssetType;
  2316. itemBlock.GroupID = item.GroupID;
  2317. itemBlock.GroupOwned = item.GroupOwned;
  2318. itemBlock.GroupMask = item.GroupPermissions;
  2319. itemBlock.Flags = item.Flags & 0x2000ff;
  2320. itemBlock.SalePrice = item.SalePrice;
  2321. itemBlock.SaleType = item.SaleType;
  2322. itemBlock.CreationDate = item.CreationDate;
  2323. itemBlock.CRC =
  2324. Helpers.InventoryCRC(
  2325. 1000, 0, itemBlock.InvType,
  2326. itemBlock.Type, itemBlock.AssetID,
  2327. itemBlock.GroupID, 100,
  2328. itemBlock.OwnerID, itemBlock.CreatorID,
  2329. itemBlock.ItemID, itemBlock.FolderID,
  2330. (uint)PermissionMask.All, 1, (uint)PermissionMask.All, (uint)PermissionMask.All,
  2331. (uint)PermissionMask.All);
  2332. return itemBlock;
  2333. }
  2334. public void SendBulkUpdateInventory(InventoryNodeBase node, UUID? transationID = null)
  2335. {
  2336. if (node is InventoryItemBase)
  2337. SendBulkUpdateInventoryItem((InventoryItemBase)node, transationID);
  2338. else if (node is InventoryFolderBase)
  2339. SendBulkUpdateInventoryFolder((InventoryFolderBase)node, transationID);
  2340. else if (node != null)
  2341. m_log.ErrorFormat("[CLIENT]: {0} sent unknown inventory node named {1}", Name, node.Name);
  2342. else
  2343. m_log.ErrorFormat("[CLIENT]: {0} sent null inventory node", Name);
  2344. }
  2345. protected void SendBulkUpdateInventoryItem(InventoryItemBase item, UUID? transationID = null)
  2346. {
  2347. const uint FULL_MASK_PERMISSIONS = (uint)0x7ffffff;
  2348. BulkUpdateInventoryPacket bulkUpdate
  2349. = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
  2350. bulkUpdate.AgentData.AgentID = AgentId;
  2351. bulkUpdate.AgentData.TransactionID = transationID ?? UUID.Random();
  2352. bulkUpdate.FolderData = new BulkUpdateInventoryPacket.FolderDataBlock[1];
  2353. bulkUpdate.FolderData[0] = new BulkUpdateInventoryPacket.FolderDataBlock();
  2354. bulkUpdate.FolderData[0].FolderID = UUID.Zero;
  2355. bulkUpdate.FolderData[0].ParentID = UUID.Zero;
  2356. bulkUpdate.FolderData[0].Type = -1;
  2357. bulkUpdate.FolderData[0].Name = new byte[0];
  2358. bulkUpdate.ItemData = new BulkUpdateInventoryPacket.ItemDataBlock[1];
  2359. bulkUpdate.ItemData[0] = new BulkUpdateInventoryPacket.ItemDataBlock();
  2360. bulkUpdate.ItemData[0].ItemID = item.ID;
  2361. bulkUpdate.ItemData[0].AssetID = item.AssetID;
  2362. bulkUpdate.ItemData[0].CreatorID = item.CreatorIdAsUuid;
  2363. bulkUpdate.ItemData[0].BaseMask = item.BasePermissions;
  2364. bulkUpdate.ItemData[0].CreationDate = item.CreationDate;
  2365. bulkUpdate.ItemData[0].Description = Util.StringToBytes256(item.Description);
  2366. bulkUpdate.ItemData[0].EveryoneMask = item.EveryOnePermissions;
  2367. bulkUpdate.ItemData[0].FolderID = item.Folder;
  2368. bulkUpdate.ItemData[0].InvType = (sbyte)item.InvType;
  2369. bulkUpdate.ItemData[0].Name = Util.StringToBytes256(item.Name);
  2370. bulkUpdate.ItemData[0].NextOwnerMask = item.NextPermissions;
  2371. bulkUpdate.ItemData[0].OwnerID = item.Owner;
  2372. bulkUpdate.ItemData[0].OwnerMask = item.CurrentPermissions;
  2373. bulkUpdate.ItemData[0].Type = (sbyte)item.AssetType;
  2374. bulkUpdate.ItemData[0].GroupID = item.GroupID;
  2375. bulkUpdate.ItemData[0].GroupOwned = item.GroupOwned;
  2376. bulkUpdate.ItemData[0].GroupMask = item.GroupPermissions;
  2377. bulkUpdate.ItemData[0].Flags = item.Flags & 0x2000ff;
  2378. bulkUpdate.ItemData[0].SalePrice = item.SalePrice;
  2379. bulkUpdate.ItemData[0].SaleType = item.SaleType;
  2380. bulkUpdate.ItemData[0].CRC =
  2381. Helpers.InventoryCRC(1000, 0, bulkUpdate.ItemData[0].InvType,
  2382. bulkUpdate.ItemData[0].Type, bulkUpdate.ItemData[0].AssetID,
  2383. bulkUpdate.ItemData[0].GroupID, 100,
  2384. bulkUpdate.ItemData[0].OwnerID, bulkUpdate.ItemData[0].CreatorID,
  2385. bulkUpdate.ItemData[0].ItemID, bulkUpdate.ItemData[0].FolderID,
  2386. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  2387. FULL_MASK_PERMISSIONS);
  2388. bulkUpdate.Header.Zerocoded = true;
  2389. OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
  2390. }
  2391. public void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId)
  2392. {
  2393. SendInventoryItemCreateUpdate(Item, UUID.Zero, callbackId);
  2394. }
  2395. /// <see>IClientAPI.SendInventoryItemCreateUpdate(InventoryItemBase)</see>
  2396. public void SendInventoryItemCreateUpdate(InventoryItemBase Item, UUID transactionID, uint callbackId)
  2397. {
  2398. const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff;
  2399. UpdateCreateInventoryItemPacket InventoryReply
  2400. = (UpdateCreateInventoryItemPacket)PacketPool.Instance.GetPacket(
  2401. PacketType.UpdateCreateInventoryItem);
  2402. // TODO: don't create new blocks if recycling an old packet
  2403. InventoryReply.AgentData.AgentID = AgentId;
  2404. InventoryReply.AgentData.SimApproved = true;
  2405. InventoryReply.AgentData.TransactionID = transactionID;
  2406. InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
  2407. InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
  2408. InventoryReply.InventoryData[0].ItemID = Item.ID;
  2409. InventoryReply.InventoryData[0].AssetID = Item.AssetID;
  2410. InventoryReply.InventoryData[0].CreatorID = Item.CreatorIdAsUuid;
  2411. InventoryReply.InventoryData[0].BaseMask = Item.BasePermissions;
  2412. InventoryReply.InventoryData[0].Description = Util.StringToBytes256(Item.Description);
  2413. InventoryReply.InventoryData[0].EveryoneMask = Item.EveryOnePermissions;
  2414. InventoryReply.InventoryData[0].FolderID = Item.Folder;
  2415. InventoryReply.InventoryData[0].InvType = (sbyte)Item.InvType;
  2416. InventoryReply.InventoryData[0].Name = Util.StringToBytes256(Item.Name);
  2417. InventoryReply.InventoryData[0].NextOwnerMask = Item.NextPermissions;
  2418. InventoryReply.InventoryData[0].OwnerID = Item.Owner;
  2419. InventoryReply.InventoryData[0].OwnerMask = Item.CurrentPermissions;
  2420. InventoryReply.InventoryData[0].Type = (sbyte)Item.AssetType;
  2421. InventoryReply.InventoryData[0].CallbackID = callbackId;
  2422. InventoryReply.InventoryData[0].GroupID = Item.GroupID;
  2423. InventoryReply.InventoryData[0].GroupOwned = Item.GroupOwned;
  2424. InventoryReply.InventoryData[0].GroupMask = Item.GroupPermissions;
  2425. InventoryReply.InventoryData[0].Flags = Item.Flags & 0x2000ff;
  2426. InventoryReply.InventoryData[0].SalePrice = Item.SalePrice;
  2427. InventoryReply.InventoryData[0].SaleType = Item.SaleType;
  2428. InventoryReply.InventoryData[0].CreationDate = Item.CreationDate;
  2429. InventoryReply.InventoryData[0].CRC =
  2430. Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType,
  2431. InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID,
  2432. InventoryReply.InventoryData[0].GroupID, 100,
  2433. InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID,
  2434. InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID,
  2435. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  2436. FULL_MASK_PERMISSIONS);
  2437. InventoryReply.Header.Zerocoded = true;
  2438. OutPacket(InventoryReply, ThrottleOutPacketType.Asset);
  2439. }
  2440. public void SendRemoveInventoryItem(UUID itemID)
  2441. {
  2442. RemoveInventoryItemPacket remove = (RemoveInventoryItemPacket)PacketPool.Instance.GetPacket(PacketType.RemoveInventoryItem);
  2443. // TODO: don't create new blocks if recycling an old packet
  2444. remove.AgentData.AgentID = AgentId;
  2445. remove.AgentData.SessionID = m_sessionId;
  2446. remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1];
  2447. remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock();
  2448. remove.InventoryData[0].ItemID = itemID;
  2449. remove.Header.Zerocoded = true;
  2450. OutPacket(remove, ThrottleOutPacketType.Asset);
  2451. }
  2452. /*
  2453. private uint adjustControls(int input)
  2454. {
  2455. uint ret = (uint)input;
  2456. uint masked = ret & 0x0f;
  2457. masked <<= 19;
  2458. ret |= masked;
  2459. return ret;
  2460. }
  2461. */
  2462. public void SendTakeControls(int controls, bool passToAgent, bool TakeControls)
  2463. {
  2464. ScriptControlChangePacket scriptcontrol = (ScriptControlChangePacket)PacketPool.Instance.GetPacket(PacketType.ScriptControlChange);
  2465. ScriptControlChangePacket.DataBlock[] data = new ScriptControlChangePacket.DataBlock[1];
  2466. ScriptControlChangePacket.DataBlock ddata = new ScriptControlChangePacket.DataBlock();
  2467. // ddata.Controls = adjustControls(controls);
  2468. ddata.Controls = (uint)controls;
  2469. ddata.PassToAgent = passToAgent;
  2470. ddata.TakeControls = TakeControls;
  2471. data[0] = ddata;
  2472. scriptcontrol.Data = data;
  2473. OutPacket(scriptcontrol, ThrottleOutPacketType.Task);
  2474. }
  2475. static private readonly byte[] ReplyTaskInventoryHeader = new byte[] {
  2476. Helpers.MSG_RELIABLE, //| Helpers.MSG_ZEROCODED, not doing spec zeroencode on this
  2477. 0, 0, 0, 0, // sequence number
  2478. 0, // extra
  2479. 0xff, 0xff, 1, 34 // ID 90 (low frequency bigendian)
  2480. };
  2481. public void SendTaskInventory(UUID taskID, short serial, byte[] fileName)
  2482. {
  2483. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  2484. byte[] data = buf.Data;
  2485. //setup header
  2486. Buffer.BlockCopy(ReplyTaskInventoryHeader, 0, data, 0, 10);
  2487. taskID.ToBytes(data, 10); // 26
  2488. Utils.Int16ToBytes(serial, data, 26); // 28
  2489. data[28] = (byte)fileName.Length;
  2490. if(data[28] > 0)
  2491. Buffer.BlockCopy(fileName, 0, data, 29, data[28]);
  2492. buf.DataLength = 29 + data[28];
  2493. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, true);
  2494. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  2495. }
  2496. static private readonly byte[] SendXferPacketHeader = new byte[] {
  2497. 0, //Helpers.MSG_RELIABLE, Xfer control must provide reliabialty
  2498. 0, 0, 0, 0, // sequence number
  2499. 0, // extra
  2500. 18 // ID (high frequency bigendian)
  2501. };
  2502. public void SendXferPacket(ulong xferID, uint packet,
  2503. byte[] XferData, int XferDataOffset, int XferDatapktLen, bool isTaskInventory)
  2504. {
  2505. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  2506. byte[] data = buf.Data;
  2507. //setup header
  2508. Buffer.BlockCopy(SendXferPacketHeader, 0, data, 0, 7);
  2509. Utils.UInt64ToBytesSafepos(xferID, data, 7); // 15
  2510. Utils.UIntToBytesSafepos(packet, data, 15); // 19
  2511. int len = XferDatapktLen;
  2512. if (XferDataOffset == 0) // first packet needs to send the total xfer data len
  2513. len += 4;
  2514. if (len > LLUDPServer.MAXPAYLOAD) // should never happen
  2515. len = LLUDPServer.MAXPAYLOAD;
  2516. if (len == 0)
  2517. {
  2518. data[19] = 0;
  2519. data[20] = 0;
  2520. }
  2521. else
  2522. {
  2523. data[19] = (byte)len;
  2524. data[20] = (byte)(len >> 8);
  2525. if(XferDataOffset == 0)
  2526. {
  2527. // need to send total xfer data len
  2528. Utils.IntToBytesSafepos(XferData.Length, data, 21);
  2529. if (XferDatapktLen > 0)
  2530. Buffer.BlockCopy(XferData, XferDataOffset, data, 25, XferDatapktLen);
  2531. }
  2532. else
  2533. Buffer.BlockCopy(XferData, XferDataOffset, data, 21, XferDatapktLen);
  2534. }
  2535. buf.DataLength = 21 + len;
  2536. m_udpServer.SendUDPPacket(m_udpClient, buf, isTaskInventory ? ThrottleOutPacketType.Task : ThrottleOutPacketType.Asset);
  2537. }
  2538. static private readonly byte[] AbortXferHeader = new byte[] {
  2539. Helpers.MSG_RELIABLE,
  2540. 0, 0, 0, 0, // sequence number
  2541. 0, // extra
  2542. 0xff, 0xff, 0, 157 // ID 157 (low frequency bigendian)
  2543. };
  2544. public void SendAbortXferPacket(ulong xferID)
  2545. {
  2546. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  2547. byte[] data = buf.Data;
  2548. //setup header
  2549. Buffer.BlockCopy(AbortXferHeader, 0, data, 0, 10);
  2550. Utils.UInt64ToBytesSafepos(xferID, data, 10); // 18
  2551. Utils.IntToBytesSafepos(0, data, 18); // 22 reason TODO
  2552. buf.DataLength = 22;
  2553. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Asset);
  2554. }
  2555. public void SendEconomyData(float EnergyEfficiency, int ObjectCapacity, int ObjectCount, int PriceEnergyUnit,
  2556. int PriceGroupCreate, int PriceObjectClaim, float PriceObjectRent, float PriceObjectScaleFactor,
  2557. int PriceParcelClaim, float PriceParcelClaimFactor, int PriceParcelRent, int PricePublicObjectDecay,
  2558. int PricePublicObjectDelete, int PriceRentLight, int PriceUpload, int TeleportMinPrice, float TeleportPriceExponent)
  2559. {
  2560. EconomyDataPacket economyData = (EconomyDataPacket)PacketPool.Instance.GetPacket(PacketType.EconomyData);
  2561. economyData.Info.EnergyEfficiency = EnergyEfficiency;
  2562. economyData.Info.ObjectCapacity = ObjectCapacity;
  2563. economyData.Info.ObjectCount = ObjectCount;
  2564. economyData.Info.PriceEnergyUnit = PriceEnergyUnit;
  2565. economyData.Info.PriceGroupCreate = PriceGroupCreate;
  2566. economyData.Info.PriceObjectClaim = PriceObjectClaim;
  2567. economyData.Info.PriceObjectRent = PriceObjectRent;
  2568. economyData.Info.PriceObjectScaleFactor = PriceObjectScaleFactor;
  2569. economyData.Info.PriceParcelClaim = PriceParcelClaim;
  2570. economyData.Info.PriceParcelClaimFactor = PriceParcelClaimFactor;
  2571. economyData.Info.PriceParcelRent = PriceParcelRent;
  2572. economyData.Info.PricePublicObjectDecay = PricePublicObjectDecay;
  2573. economyData.Info.PricePublicObjectDelete = PricePublicObjectDelete;
  2574. economyData.Info.PriceRentLight = PriceRentLight;
  2575. economyData.Info.PriceUpload = PriceUpload;
  2576. economyData.Info.TeleportMinPrice = TeleportMinPrice;
  2577. economyData.Info.TeleportPriceExponent = TeleportPriceExponent;
  2578. economyData.Header.Reliable = true;
  2579. OutPacket(economyData, ThrottleOutPacketType.Task);
  2580. }
  2581. static private readonly byte[] AvatarPickerReplyHeader = new byte[] {
  2582. Helpers.MSG_RELIABLE,
  2583. 0, 0, 0, 0, // sequence number
  2584. 0, // extra
  2585. 0xff, 0xff, 0, 28 // ID 28 (low frequency bigendian)
  2586. };
  2587. public void SendAvatarPickerReply(UUID QueryID, List<UserData> users)
  2588. {
  2589. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  2590. byte[] data = buf.Data;
  2591. //setup header
  2592. Buffer.BlockCopy(AvatarPickerReplyHeader, 0, data, 0, 10);
  2593. AgentId.ToBytes(data, 10); //26
  2594. QueryID.ToBytes(data, 26); //42
  2595. if (users.Count == 0)
  2596. {
  2597. data[42] = 0;
  2598. buf.DataLength = 43;
  2599. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  2600. return;
  2601. }
  2602. int pos = 43;
  2603. int count = 0;
  2604. for(int u = 0; u < users.Count; ++u)
  2605. {
  2606. UserData user = users[u];
  2607. user.Id.ToBytes(data,pos);
  2608. pos+= 16;
  2609. byte[] tmp = Utils.StringToBytes(user.FirstName);
  2610. data[pos++] = (byte)tmp.Length;
  2611. if(tmp.Length > 0)
  2612. {
  2613. Buffer.BlockCopy(tmp, 0, data, pos, tmp.Length);
  2614. pos += tmp.Length;
  2615. }
  2616. tmp = Utils.StringToBytes(user.LastName);
  2617. data[pos++] = (byte)tmp.Length;
  2618. if (tmp.Length > 0)
  2619. {
  2620. Buffer.BlockCopy(tmp, 0, data, pos, tmp.Length);
  2621. pos += tmp.Length;
  2622. }
  2623. ++count;
  2624. if (pos >= LLUDPServer.MAXPAYLOAD - 120)
  2625. {
  2626. data[42] = (byte)count;
  2627. buf.DataLength = pos;
  2628. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  2629. if (u < users.Count - 1)
  2630. {
  2631. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  2632. byte[] newdata = newbuf.Data;
  2633. Buffer.BlockCopy(data, 0, newdata, 0, 42);
  2634. buf = newbuf;
  2635. data = newdata;
  2636. pos = 43;
  2637. }
  2638. count = 0;
  2639. }
  2640. }
  2641. if(count > 0)
  2642. {
  2643. data[42] = (byte)count;
  2644. buf.DataLength = pos;
  2645. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  2646. }
  2647. }
  2648. public void SendAgentDataUpdate(UUID agentid, UUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname, string grouptitle)
  2649. {
  2650. if (agentid == AgentId)
  2651. {
  2652. ActiveGroupId = activegroupid;
  2653. ActiveGroupName = groupname;
  2654. ActiveGroupPowers = grouppowers;
  2655. }
  2656. AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate);
  2657. sendAgentDataUpdate.AgentData.ActiveGroupID = activegroupid;
  2658. sendAgentDataUpdate.AgentData.AgentID = agentid;
  2659. sendAgentDataUpdate.AgentData.FirstName = Util.StringToBytes256(firstname);
  2660. sendAgentDataUpdate.AgentData.GroupName = Util.StringToBytes256(groupname);
  2661. sendAgentDataUpdate.AgentData.GroupPowers = grouppowers;
  2662. sendAgentDataUpdate.AgentData.GroupTitle = Util.StringToBytes256(grouptitle);
  2663. sendAgentDataUpdate.AgentData.LastName = Util.StringToBytes256(lastname);
  2664. OutPacket(sendAgentDataUpdate, ThrottleOutPacketType.Task);
  2665. }
  2666. /// <summary>
  2667. /// Send an alert message to the client. This pops up a brief duration information box at a corner
  2668. /// </summary>
  2669. /// <param name="message"></param>
  2670. public void SendAlertMessage(string message)
  2671. {
  2672. AlertMessagePacket alertPack = (AlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AlertMessage);
  2673. //alertPack.AgentInfo = new AlertMessagePacket.AgentInfoBlock[1];
  2674. //alertPack.AgentInfo[0] = new AlertMessagePacket.AgentInfoBlock();
  2675. //alertPack.AgentInfo[0].AgentID = AgentId;
  2676. alertPack.AlertData = new AlertMessagePacket.AlertDataBlock();
  2677. alertPack.AlertData.Message = Util.StringToBytes256(message);
  2678. alertPack.AlertInfo = new AlertMessagePacket.AlertInfoBlock[0];
  2679. OutPacket(alertPack, ThrottleOutPacketType.Task);
  2680. }
  2681. public void SendAlertMessage(string message, string info)
  2682. {
  2683. AlertMessagePacket alertPack = (AlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AlertMessage);
  2684. //alertPack.AgentInfo = new AlertMessagePacket.AgentInfoBlock[1];
  2685. //alertPack.AgentInfo[0] = new AlertMessagePacket.AgentInfoBlock();
  2686. //alertPack.AgentInfo[0].AgentID = AgentId;
  2687. alertPack.AlertData = new AlertMessagePacket.AlertDataBlock();
  2688. alertPack.AlertData.Message = Util.StringToBytes256(message);
  2689. alertPack.AlertInfo = new AlertMessagePacket.AlertInfoBlock[1];
  2690. alertPack.AlertInfo[0] = new AlertMessagePacket.AlertInfoBlock();
  2691. alertPack.AlertInfo[0].Message = Util.StringToBytes256(info);
  2692. alertPack.AlertInfo[0].ExtraParams = new Byte[0];
  2693. OutPacket(alertPack, ThrottleOutPacketType.Task);
  2694. }
  2695. /// <summary>
  2696. /// Send an agent alert message to the client.
  2697. /// </summary>
  2698. /// <param name="message"></param>
  2699. /// <param name="modal">On the linden client, if this true then it displays a one button text box placed in the
  2700. /// middle of the window. If false, the message is displayed in a brief duration blue information box (as for
  2701. /// the AlertMessage packet).</param>
  2702. public void SendAgentAlertMessage(string message, bool modal)
  2703. {
  2704. // Prepend a slash to make the message come up in the top right
  2705. // again.
  2706. // Allow special formats to be sent from aware modules.
  2707. if (!modal && !message.StartsWith("ALERT: ") && !message.StartsWith("NOTIFY: ") && message != "Home position set." && message != "You died and have been teleported to your home location")
  2708. message = "/" + message;
  2709. AgentAlertMessagePacket alertPack = (AgentAlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AgentAlertMessage);
  2710. alertPack.AgentData.AgentID = AgentId;
  2711. alertPack.AlertData.Message = Util.StringToBytes256(message);
  2712. alertPack.AlertData.Modal = modal;
  2713. OutPacket(alertPack, ThrottleOutPacketType.Task);
  2714. }
  2715. public void SendLoadURL(string objectname, UUID objectID, UUID ownerID, bool groupOwned, string message,
  2716. string url)
  2717. {
  2718. LoadURLPacket loadURL = (LoadURLPacket)PacketPool.Instance.GetPacket(PacketType.LoadURL);
  2719. loadURL.Data.ObjectName = Util.StringToBytes256(objectname);
  2720. loadURL.Data.ObjectID = objectID;
  2721. loadURL.Data.OwnerID = ownerID;
  2722. loadURL.Data.OwnerIsGroup = groupOwned;
  2723. loadURL.Data.Message = Util.StringToBytes256(message);
  2724. loadURL.Data.URL = Util.StringToBytes256(url);
  2725. OutPacket(loadURL, ThrottleOutPacketType.Task);
  2726. }
  2727. public void SendDialog(
  2728. string objectname, UUID objectID, UUID ownerID, string ownerFirstName, string ownerLastName, string msg,
  2729. UUID textureID, int ch, string[] buttonlabels)
  2730. {
  2731. ScriptDialogPacket dialog = (ScriptDialogPacket)PacketPool.Instance.GetPacket(PacketType.ScriptDialog);
  2732. dialog.Data.ObjectID = objectID;
  2733. dialog.Data.ObjectName = Util.StringToBytes256(objectname);
  2734. // this is the username of the *owner*
  2735. dialog.Data.FirstName = Util.StringToBytes256(ownerFirstName);
  2736. dialog.Data.LastName = Util.StringToBytes256(ownerLastName);
  2737. dialog.Data.Message = Util.StringToBytes(msg,512);
  2738. dialog.Data.ImageID = textureID;
  2739. dialog.Data.ChatChannel = ch;
  2740. ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[buttonlabels.Length];
  2741. for (int i = 0; i < buttonlabels.Length; i++)
  2742. {
  2743. buttons[i] = new ScriptDialogPacket.ButtonsBlock();
  2744. buttons[i].ButtonLabel = Util.StringToBytes(buttonlabels[i],24);
  2745. }
  2746. dialog.Buttons = buttons;
  2747. dialog.OwnerData = new ScriptDialogPacket.OwnerDataBlock[1];
  2748. dialog.OwnerData[0] = new ScriptDialogPacket.OwnerDataBlock();
  2749. dialog.OwnerData[0].OwnerID = ownerID;
  2750. OutPacket(dialog, ThrottleOutPacketType.Task);
  2751. }
  2752. public void SendPreLoadSound(UUID objectID, UUID ownerID, UUID soundID)
  2753. {
  2754. PreloadSoundPacket preSound = (PreloadSoundPacket)PacketPool.Instance.GetPacket(PacketType.PreloadSound);
  2755. // TODO: don't create new blocks if recycling an old packet
  2756. preSound.DataBlock = new PreloadSoundPacket.DataBlockBlock[1];
  2757. preSound.DataBlock[0] = new PreloadSoundPacket.DataBlockBlock();
  2758. preSound.DataBlock[0].ObjectID = objectID;
  2759. preSound.DataBlock[0].OwnerID = ownerID;
  2760. preSound.DataBlock[0].SoundID = soundID;
  2761. preSound.Header.Zerocoded = true;
  2762. OutPacket(preSound, ThrottleOutPacketType.Task);
  2763. }
  2764. public void SendPlayAttachedSound(UUID soundID, UUID objectID, UUID ownerID, float gain, byte flags)
  2765. {
  2766. AttachedSoundPacket sound = (AttachedSoundPacket)PacketPool.Instance.GetPacket(PacketType.AttachedSound);
  2767. sound.DataBlock.SoundID = soundID;
  2768. sound.DataBlock.ObjectID = objectID;
  2769. sound.DataBlock.OwnerID = ownerID;
  2770. sound.DataBlock.Gain = gain;
  2771. sound.DataBlock.Flags = flags;
  2772. OutPacket(sound, ThrottleOutPacketType.Task);
  2773. }
  2774. public void SendTransferAbort(TransferRequestPacket transferRequest)
  2775. {
  2776. TransferAbortPacket abort = (TransferAbortPacket)PacketPool.Instance.GetPacket(PacketType.TransferAbort);
  2777. abort.TransferInfo.TransferID = transferRequest.TransferInfo.TransferID;
  2778. abort.TransferInfo.ChannelType = transferRequest.TransferInfo.ChannelType;
  2779. m_log.Debug("[Assets] Aborting transfer; asset request failed");
  2780. OutPacket(abort, ThrottleOutPacketType.Task);
  2781. }
  2782. public void SendTriggeredSound(UUID soundID, UUID ownerID, UUID objectID, UUID parentID, ulong handle, Vector3 position, float gain)
  2783. {
  2784. SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger);
  2785. sound.SoundData.SoundID = soundID;
  2786. sound.SoundData.OwnerID = ownerID;
  2787. sound.SoundData.ObjectID = objectID;
  2788. sound.SoundData.ParentID = parentID;
  2789. sound.SoundData.Handle = handle;
  2790. sound.SoundData.Position = position;
  2791. sound.SoundData.Gain = gain;
  2792. OutPacket(sound, ThrottleOutPacketType.Task);
  2793. }
  2794. public void SendAttachedSoundGainChange(UUID objectID, float gain)
  2795. {
  2796. AttachedSoundGainChangePacket sound = (AttachedSoundGainChangePacket)PacketPool.Instance.GetPacket(PacketType.AttachedSoundGainChange);
  2797. sound.DataBlock.ObjectID = objectID;
  2798. sound.DataBlock.Gain = gain;
  2799. OutPacket(sound, ThrottleOutPacketType.Task);
  2800. }
  2801. public void SendViewerTime(Vector3 sunDir, float sunphase)
  2802. {
  2803. SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
  2804. viewertime.TimeInfo.UsecSinceStart = Util.UnixTimeSinceEpoch_uS();
  2805. viewertime.TimeInfo.SunDirection = sunDir;
  2806. viewertime.TimeInfo.SunPhase = sunphase;
  2807. viewertime.TimeInfo.SunAngVelocity = Vector3.Zero; //legacy
  2808. viewertime.TimeInfo.SecPerDay = 14400; // legacy
  2809. viewertime.TimeInfo.SecPerYear = 158400; // legacy
  2810. viewertime.Header.Reliable = false;
  2811. viewertime.Header.Zerocoded = true;
  2812. OutPacket(viewertime, ThrottleOutPacketType.Task);
  2813. }
  2814. public void SendViewerEffect(ViewerEffectPacket.EffectBlock[] effectBlocks)
  2815. {
  2816. ViewerEffectPacket packet = (ViewerEffectPacket)PacketPool.Instance.GetPacket(PacketType.ViewerEffect);
  2817. // packet.AgentData.AgentID = AgentId;
  2818. // packet.AgentData.SessionID = SessionId;
  2819. packet.Effect = effectBlocks;
  2820. // OutPacket(packet, ThrottleOutPacketType.State);
  2821. OutPacket(packet, ThrottleOutPacketType.Task);
  2822. }
  2823. public void SendAvatarProperties(UUID avatarID, string aboutText, string bornOn, Byte[] membershipType,
  2824. string flAbout, uint flags, UUID flImageID, UUID imageID, string profileURL,
  2825. UUID partnerID)
  2826. {
  2827. AvatarPropertiesReplyPacket avatarReply = (AvatarPropertiesReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPropertiesReply);
  2828. avatarReply.AgentData.AgentID = AgentId;
  2829. avatarReply.AgentData.AvatarID = avatarID;
  2830. if (aboutText != null)
  2831. avatarReply.PropertiesData.AboutText = Util.StringToBytes1024(aboutText);
  2832. else
  2833. avatarReply.PropertiesData.AboutText = Utils.EmptyBytes;
  2834. avatarReply.PropertiesData.BornOn = Util.StringToBytes256(bornOn);
  2835. avatarReply.PropertiesData.CharterMember = membershipType;
  2836. if (flAbout != null)
  2837. avatarReply.PropertiesData.FLAboutText = Util.StringToBytes256(flAbout);
  2838. else
  2839. avatarReply.PropertiesData.FLAboutText = Utils.EmptyBytes;
  2840. avatarReply.PropertiesData.Flags = flags;
  2841. avatarReply.PropertiesData.FLImageID = flImageID;
  2842. avatarReply.PropertiesData.ImageID = imageID;
  2843. avatarReply.PropertiesData.ProfileURL = Util.StringToBytes256(profileURL);
  2844. avatarReply.PropertiesData.PartnerID = partnerID;
  2845. OutPacket(avatarReply, ThrottleOutPacketType.Task);
  2846. }
  2847. /// <summary>
  2848. /// Send the client an Estate message blue box pop-down with a single OK button
  2849. /// </summary>
  2850. /// <param name="FromAvatarID"></param>
  2851. /// <param name="fromSessionID"></param>
  2852. /// <param name="FromAvatarName"></param>
  2853. /// <param name="Message"></param>
  2854. public void SendBlueBoxMessage(UUID FromAvatarID, String FromAvatarName, String Message)
  2855. {
  2856. if (!SceneAgent.IsChildAgent)
  2857. SendInstantMessage(new GridInstantMessage(null, FromAvatarID, FromAvatarName, AgentId, 1, Message, false, new Vector3()));
  2858. //SendInstantMessage(FromAvatarID, fromSessionID, Message, AgentId, SessionId, FromAvatarName, (byte)21,(uint) Util.UnixTimeSinceEpoch());
  2859. }
  2860. public void SendLogoutPacket()
  2861. {
  2862. // I know this is a bit of a hack, however there are times when you don't
  2863. // want to send this, but still need to do the rest of the shutdown process
  2864. // this method gets called from the packet server.. which makes it practically
  2865. // impossible to do any other way.
  2866. if (m_SendLogoutPacketWhenClosing)
  2867. {
  2868. LogoutReplyPacket logReply = (LogoutReplyPacket)PacketPool.Instance.GetPacket(PacketType.LogoutReply);
  2869. // TODO: don't create new blocks if recycling an old packet
  2870. logReply.AgentData.AgentID = AgentId;
  2871. logReply.AgentData.SessionID = SessionId;
  2872. logReply.InventoryData = new LogoutReplyPacket.InventoryDataBlock[1];
  2873. logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock();
  2874. logReply.InventoryData[0].ItemID = UUID.Zero;
  2875. OutPacket(logReply, ThrottleOutPacketType.Task);
  2876. }
  2877. }
  2878. public void SendHealth(float health)
  2879. {
  2880. HealthMessagePacket healthpacket = (HealthMessagePacket)PacketPool.Instance.GetPacket(PacketType.HealthMessage);
  2881. healthpacket.HealthData.Health = health;
  2882. OutPacket(healthpacket, ThrottleOutPacketType.Task);
  2883. }
  2884. public void SendAgentOnline(UUID[] agentIDs)
  2885. {
  2886. OnlineNotificationPacket onp = new OnlineNotificationPacket();
  2887. OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[agentIDs.Length];
  2888. for (int i = 0; i < agentIDs.Length; i++)
  2889. {
  2890. OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock();
  2891. onpbl.AgentID = agentIDs[i];
  2892. onpb[i] = onpbl;
  2893. }
  2894. onp.AgentBlock = onpb;
  2895. onp.Header.Reliable = true;
  2896. OutPacket(onp, ThrottleOutPacketType.Task);
  2897. }
  2898. public void SendAgentOffline(UUID[] agentIDs)
  2899. {
  2900. OfflineNotificationPacket offp = new OfflineNotificationPacket();
  2901. OfflineNotificationPacket.AgentBlockBlock[] offpb = new OfflineNotificationPacket.AgentBlockBlock[agentIDs.Length];
  2902. for (int i = 0; i < agentIDs.Length; i++)
  2903. {
  2904. OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock();
  2905. onpbl.AgentID = agentIDs[i];
  2906. offpb[i] = onpbl;
  2907. }
  2908. offp.AgentBlock = offpb;
  2909. offp.Header.Reliable = true;
  2910. OutPacket(offp, ThrottleOutPacketType.Task);
  2911. }
  2912. public void SendFindAgent(UUID HunterID, UUID PreyID, double GlobalX, double GlobalY)
  2913. {
  2914. FindAgentPacket fap = new FindAgentPacket();
  2915. fap.AgentBlock.Hunter = HunterID;
  2916. fap.AgentBlock.Prey = PreyID;
  2917. fap.AgentBlock.SpaceIP = 0;
  2918. fap.LocationBlock = new FindAgentPacket.LocationBlockBlock[1];
  2919. fap.LocationBlock[0] = new FindAgentPacket.LocationBlockBlock();
  2920. fap.LocationBlock[0].GlobalX = GlobalX;
  2921. fap.LocationBlock[0].GlobalY = GlobalY;
  2922. OutPacket(fap, ThrottleOutPacketType.Task);
  2923. }
  2924. public void SendSitResponse(UUID TargetID, Vector3 OffsetPos,
  2925. Quaternion SitOrientation, bool autopilot,
  2926. Vector3 CameraAtOffset, Vector3 CameraEyeOffset, bool ForceMouseLook)
  2927. {
  2928. AvatarSitResponsePacket avatarSitResponse = new AvatarSitResponsePacket();
  2929. avatarSitResponse.SitObject.ID = TargetID;
  2930. avatarSitResponse.SitTransform.CameraAtOffset = CameraAtOffset;
  2931. avatarSitResponse.SitTransform.CameraEyeOffset = CameraEyeOffset;
  2932. avatarSitResponse.SitTransform.ForceMouselook = ForceMouseLook;
  2933. avatarSitResponse.SitTransform.AutoPilot = autopilot;
  2934. avatarSitResponse.SitTransform.SitPosition = OffsetPos;
  2935. avatarSitResponse.SitTransform.SitRotation = SitOrientation;
  2936. OutPacket(avatarSitResponse, ThrottleOutPacketType.Task);
  2937. }
  2938. public void SendAdminResponse(UUID Token, uint AdminLevel)
  2939. {
  2940. GrantGodlikePowersPacket respondPacket = new GrantGodlikePowersPacket();
  2941. GrantGodlikePowersPacket.GrantDataBlock gdb = new GrantGodlikePowersPacket.GrantDataBlock();
  2942. GrantGodlikePowersPacket.AgentDataBlock adb = new GrantGodlikePowersPacket.AgentDataBlock();
  2943. adb.AgentID = AgentId;
  2944. adb.SessionID = SessionId; // More security
  2945. gdb.GodLevel = (byte)AdminLevel;
  2946. gdb.Token = Token;
  2947. //respondPacket.AgentData = (GrantGodlikePowersPacket.AgentDataBlock)ablock;
  2948. respondPacket.GrantData = gdb;
  2949. respondPacket.AgentData = adb;
  2950. OutPacket(respondPacket, ThrottleOutPacketType.Task);
  2951. }
  2952. public void SendGroupMembership(GroupMembershipData[] GroupMembership)
  2953. {
  2954. UpdateGroupMembership(GroupMembership);
  2955. SendAgentGroupDataUpdate(AgentId,GroupMembership);
  2956. }
  2957. public void SendSelectedPartsProprieties(List<ISceneEntity> parts)
  2958. {
  2959. /* not in use
  2960. // udp part
  2961. ObjectPropertiesPacket packet =
  2962. (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties);
  2963. ObjectPropertiesPacket.ObjectDataBlock[] ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[parts.Count];
  2964. int i = 0;
  2965. foreach(SceneObjectPart sop in parts)
  2966. ObjectData[i++] = CreateObjectPropertiesBlock(sop);
  2967. packet.ObjectData = ObjectData;
  2968. packet.Header.Zerocoded = true;
  2969. // udp send splits this mega packets correctly
  2970. // mb later will avoid that to reduce gc stress
  2971. OutPacket(packet, ThrottleOutPacketType.Task, true);
  2972. // caps physics part
  2973. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  2974. if(eq == null)
  2975. return;
  2976. OSDArray array = new OSDArray();
  2977. foreach(SceneObjectPart sop in parts)
  2978. {
  2979. OSDMap physinfo = new OSDMap(6);
  2980. physinfo["LocalID"] = sop.LocalId;
  2981. physinfo["Density"] = sop.Density;
  2982. physinfo["Friction"] = sop.Friction;
  2983. physinfo["GravityMultiplier"] = sop.GravityModifier;
  2984. physinfo["Restitution"] = sop.Restitution;
  2985. physinfo["PhysicsShapeType"] = (int)sop.PhysicsShapeType;
  2986. array.Add(physinfo);
  2987. }
  2988. OSDMap llsdBody = new OSDMap(1);
  2989. llsdBody.Add("ObjectData", array);
  2990. eq.Enqueue(BuildEvent("ObjectPhysicsProperties", llsdBody),AgentId);
  2991. */
  2992. }
  2993. public void SendPartPhysicsProprieties(ISceneEntity entity)
  2994. {
  2995. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  2996. if (eq == null)
  2997. return;
  2998. SceneObjectPart part = (SceneObjectPart)entity;
  2999. if (part == null)
  3000. return;
  3001. uint localid = part.LocalId;
  3002. byte physshapetype = part.PhysicsShapeType;
  3003. float density = part.Density;
  3004. float friction = part.Friction;
  3005. float bounce = part.Restitution;
  3006. float gravmod = part.GravityModifier;
  3007. eq.partPhysicsProperties(localid, physshapetype, density, friction, bounce, gravmod,AgentId);
  3008. }
  3009. public void SendGroupNameReply(UUID groupLLUID, string GroupName)
  3010. {
  3011. UUIDGroupNameReplyPacket pack = new UUIDGroupNameReplyPacket();
  3012. UUIDGroupNameReplyPacket.UUIDNameBlockBlock[] uidnameblock = new UUIDGroupNameReplyPacket.UUIDNameBlockBlock[1];
  3013. UUIDGroupNameReplyPacket.UUIDNameBlockBlock uidnamebloc = new UUIDGroupNameReplyPacket.UUIDNameBlockBlock();
  3014. uidnamebloc.ID = groupLLUID;
  3015. uidnamebloc.GroupName = Util.StringToBytes256(GroupName);
  3016. uidnameblock[0] = uidnamebloc;
  3017. pack.UUIDNameBlock = uidnameblock;
  3018. OutPacket(pack, ThrottleOutPacketType.Task);
  3019. }
  3020. public void SendLandStatReply(uint reportType, uint requestFlags, uint resultCount, LandStatReportItem[] lsrpia)
  3021. {
  3022. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  3023. if (eq == null)
  3024. {
  3025. LandStatReplyPacket lsrp = new LandStatReplyPacket();
  3026. // LandStatReplyPacket.RequestDataBlock lsreqdpb = new LandStatReplyPacket.RequestDataBlock();
  3027. LandStatReplyPacket.ReportDataBlock[] lsrepdba = new LandStatReplyPacket.ReportDataBlock[lsrpia.Length];
  3028. //LandStatReplyPacket.ReportDataBlock lsrepdb = new LandStatReplyPacket.ReportDataBlock();
  3029. // lsrepdb.
  3030. lsrp.RequestData.ReportType = reportType;
  3031. lsrp.RequestData.RequestFlags = requestFlags;
  3032. lsrp.RequestData.TotalObjectCount = resultCount;
  3033. for (int i = 0; i < lsrpia.Length; i++)
  3034. {
  3035. LandStatReplyPacket.ReportDataBlock lsrepdb = new LandStatReplyPacket.ReportDataBlock();
  3036. lsrepdb.LocationX = lsrpia[i].LocationX;
  3037. lsrepdb.LocationY = lsrpia[i].LocationY;
  3038. lsrepdb.LocationZ = lsrpia[i].LocationZ;
  3039. lsrepdb.Score = lsrpia[i].Score;
  3040. lsrepdb.TaskID = lsrpia[i].TaskID;
  3041. lsrepdb.TaskLocalID = lsrpia[i].TaskLocalID;
  3042. lsrepdb.TaskName = Util.StringToBytes256(lsrpia[i].TaskName);
  3043. lsrepdb.OwnerName = Util.StringToBytes256(lsrpia[i].OwnerName);
  3044. lsrepdba[i] = lsrepdb;
  3045. }
  3046. lsrp.ReportData = lsrepdba;
  3047. OutPacket(lsrp, ThrottleOutPacketType.Task);
  3048. }
  3049. else
  3050. {
  3051. osUTF8 sb = eq.StartEvent("LandStatReply");
  3052. LLSDxmlEncode2.AddArrayAndMap("RequestData", sb);
  3053. LLSDxmlEncode2.AddElem("ReportType", reportType, sb);
  3054. LLSDxmlEncode2.AddElem("RequestFlags", requestFlags, sb);
  3055. LLSDxmlEncode2.AddElem("TotalObjectCount", (uint)lsrpia.Length, sb);
  3056. LLSDxmlEncode2.AddEndMapAndArray(sb);
  3057. if (lsrpia.Length > 0)
  3058. {
  3059. LLSDxmlEncode2.AddArray("ReportData", sb);
  3060. foreach (var item in lsrpia)
  3061. {
  3062. LLSDxmlEncode2.AddMap(sb);
  3063. LLSDxmlEncode2.AddElem("LocationX", item.LocationX, sb);
  3064. LLSDxmlEncode2.AddElem("LocationY", item.LocationY, sb);
  3065. LLSDxmlEncode2.AddElem("LocationZ", item.LocationZ, sb);
  3066. LLSDxmlEncode2.AddElem("OwnerName", item.OwnerName, sb);
  3067. LLSDxmlEncode2.AddElem("Score", item.Score, sb);
  3068. LLSDxmlEncode2.AddElem("TaskID", item.TaskID, sb);
  3069. LLSDxmlEncode2.AddElem("TaskLocalID", item.TaskLocalID, sb);
  3070. LLSDxmlEncode2.AddElem("TaskName", item.TaskName, sb);
  3071. LLSDxmlEncode2.AddEndMap(sb);
  3072. }
  3073. LLSDxmlEncode2.AddEndArray(sb);
  3074. LLSDxmlEncode2.AddArray("DataExtended", sb);
  3075. foreach (var item in lsrpia)
  3076. {
  3077. LLSDxmlEncode2.AddMap(sb);
  3078. LLSDxmlEncode2.AddElem("MonoScore", 0.0f, sb);
  3079. LLSDxmlEncode2.AddElem("OwnerID", item.OwnerID, sb);
  3080. LLSDxmlEncode2.AddElem("ParcelName", item.Parcel, sb);
  3081. LLSDxmlEncode2.AddElem("PublicURLs", item.Urls, sb);
  3082. LLSDxmlEncode2.AddElem("Size", (float)item.Bytes, sb);
  3083. LLSDxmlEncode2.AddElem("TimeStamp", item.Time, sb);
  3084. LLSDxmlEncode2.AddEndMap(sb);
  3085. }
  3086. LLSDxmlEncode2.AddEndArray(sb);
  3087. }
  3088. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  3089. }
  3090. }
  3091. public void SendScriptRunningReply(UUID objectID, UUID itemID, bool running)
  3092. {
  3093. ScriptRunningReplyPacket scriptRunningReply = new ScriptRunningReplyPacket();
  3094. scriptRunningReply.Script.ObjectID = objectID;
  3095. scriptRunningReply.Script.ItemID = itemID;
  3096. scriptRunningReply.Script.Running = running;
  3097. OutPacket(scriptRunningReply, ThrottleOutPacketType.Task);
  3098. }
  3099. public void SendAsset(AssetRequestToClient req)
  3100. {
  3101. if (req.AssetInf == null)
  3102. {
  3103. m_log.ErrorFormat("{0} Cannot send asset {1} ({2}), asset is null",
  3104. LogHeader);
  3105. return;
  3106. }
  3107. if (req.AssetInf.Data == null)
  3108. {
  3109. m_log.ErrorFormat("{0} Cannot send asset {1} ({2}), asset data is null",
  3110. LogHeader, req.AssetInf.ID, req.AssetInf.Metadata.ContentType);
  3111. return;
  3112. }
  3113. bool isWearable = false;
  3114. isWearable = ((AssetType) req.AssetInf.Type ==
  3115. AssetType.Bodypart || (AssetType) req.AssetInf.Type == AssetType.Clothing);
  3116. //m_log.Debug("sending asset " + req.RequestAssetID + ", iswearable: " + isWearable);
  3117. //if (isWearable)
  3118. // m_log.Debug((AssetType)req.AssetInf.Type);
  3119. TransferInfoPacket Transfer = new TransferInfoPacket();
  3120. Transfer.TransferInfo.ChannelType = 2;
  3121. Transfer.TransferInfo.Status = 0;
  3122. Transfer.TransferInfo.TargetType = 0;
  3123. if (req.AssetRequestSource == 2)
  3124. {
  3125. Transfer.TransferInfo.Params = new byte[20];
  3126. Array.Copy(req.RequestAssetID.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
  3127. int assType = req.AssetInf.Type;
  3128. Array.Copy(Utils.IntToBytes(assType), 0, Transfer.TransferInfo.Params, 16, 4);
  3129. }
  3130. else if (req.AssetRequestSource == 3)
  3131. {
  3132. Transfer.TransferInfo.Params = req.Params;
  3133. // Transfer.TransferInfo.Params = new byte[100];
  3134. //Array.Copy(req.RequestUser.AgentId.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
  3135. //Array.Copy(req.RequestUser.SessionId.GetBytes(), 0, Transfer.TransferInfo.Params, 16, 16);
  3136. }
  3137. Transfer.TransferInfo.Size = req.AssetInf.Data.Length;
  3138. Transfer.TransferInfo.TransferID = req.TransferRequestID;
  3139. Transfer.Header.Zerocoded = true;
  3140. OutPacket(Transfer, ThrottleOutPacketType.Asset);
  3141. if (req.NumPackets == 1)
  3142. {
  3143. TransferPacketPacket TransferPacket = new TransferPacketPacket();
  3144. TransferPacket.TransferData.Packet = 0;
  3145. TransferPacket.TransferData.ChannelType = 2;
  3146. TransferPacket.TransferData.TransferID = req.TransferRequestID;
  3147. TransferPacket.TransferData.Data = req.AssetInf.Data;
  3148. TransferPacket.TransferData.Status = 1;
  3149. TransferPacket.Header.Zerocoded = true;
  3150. OutPacket(TransferPacket, ThrottleOutPacketType.Asset);
  3151. }
  3152. else
  3153. {
  3154. int processedLength = 0;
  3155. // int maxChunkSize = Settings.MAX_PACKET_SIZE - 100;
  3156. int maxChunkSize = (int) MaxTransferBytesPerPacket;
  3157. int packetNumber = 0;
  3158. while (processedLength < req.AssetInf.Data.Length)
  3159. {
  3160. TransferPacketPacket TransferPacket = new TransferPacketPacket();
  3161. TransferPacket.TransferData.Packet = packetNumber;
  3162. TransferPacket.TransferData.ChannelType = 2;
  3163. TransferPacket.TransferData.TransferID = req.TransferRequestID;
  3164. int chunkSize = Math.Min(req.AssetInf.Data.Length - processedLength, maxChunkSize);
  3165. byte[] chunk = new byte[chunkSize];
  3166. Array.Copy(req.AssetInf.Data, processedLength, chunk, 0, chunk.Length);
  3167. TransferPacket.TransferData.Data = chunk;
  3168. // 0 indicates more packets to come, 1 indicates last packet
  3169. if (req.AssetInf.Data.Length - processedLength > maxChunkSize)
  3170. {
  3171. TransferPacket.TransferData.Status = 0;
  3172. }
  3173. else
  3174. {
  3175. TransferPacket.TransferData.Status = 1;
  3176. }
  3177. TransferPacket.Header.Zerocoded = true;
  3178. OutPacket(TransferPacket, ThrottleOutPacketType.Asset);
  3179. processedLength += chunkSize;
  3180. packetNumber++;
  3181. }
  3182. }
  3183. }
  3184. public void SendAssetNotFound(AssetRequestToClient req)
  3185. {
  3186. TransferInfoPacket Transfer = new TransferInfoPacket();
  3187. Transfer.TransferInfo.ChannelType = 2;
  3188. Transfer.TransferInfo.Status = -2;
  3189. Transfer.TransferInfo.TargetType = 0;
  3190. Transfer.TransferInfo.Params = req.Params;
  3191. Transfer.TransferInfo.Size = 0;
  3192. Transfer.TransferInfo.TransferID = req.TransferRequestID;
  3193. Transfer.Header.Zerocoded = true;
  3194. OutPacket(Transfer, ThrottleOutPacketType.Asset);
  3195. }
  3196. public void SendTexture(AssetBase TextureAsset)
  3197. {
  3198. }
  3199. public void SendRegionHandle(UUID regionID, ulong handle)
  3200. {
  3201. RegionIDAndHandleReplyPacket reply = (RegionIDAndHandleReplyPacket)PacketPool.Instance.GetPacket(PacketType.RegionIDAndHandleReply);
  3202. reply.ReplyBlock.RegionID = regionID;
  3203. reply.ReplyBlock.RegionHandle = handle;
  3204. OutPacket(reply, ThrottleOutPacketType.Land);
  3205. }
  3206. public void SendParcelInfo(RegionInfo info, LandData land, UUID parcelID, uint x, uint y)
  3207. {
  3208. ParcelInfoReplyPacket reply = (ParcelInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelInfoReply);
  3209. reply.AgentData.AgentID = m_agentId;
  3210. reply.Data.ParcelID = parcelID;
  3211. reply.Data.OwnerID = land.OwnerID;
  3212. reply.Data.Name = Utils.StringToBytes(land.Name);
  3213. if (land.Description != null && land.Description != String.Empty)
  3214. reply.Data.Desc = Utils.StringToBytes(land.Description.Substring(0, land.Description.Length > 254 ? 254: land.Description.Length));
  3215. else
  3216. reply.Data.Desc = new Byte[0];
  3217. reply.Data.ActualArea = land.Area;
  3218. reply.Data.BillableArea = land.Area; // TODO: what is this?
  3219. reply.Data.Flags = (byte)Util.ConvertAccessLevelToMaturity((byte)info.AccessLevel);
  3220. if((land.Flags & (uint)ParcelFlags.ForSale) != 0)
  3221. reply.Data.Flags |= (byte)((1 << 7));
  3222. if (land.IsGroupOwned)
  3223. reply.Data.Flags |= 0x04;
  3224. Vector3 pos = land.UserLocation;
  3225. if (pos.Equals(Vector3.Zero))
  3226. {
  3227. pos = (land.AABBMax + land.AABBMin) * 0.5f;
  3228. }
  3229. reply.Data.GlobalX = info.RegionLocX + x;
  3230. reply.Data.GlobalY = info.RegionLocY + y;
  3231. reply.Data.GlobalZ = pos.Z;
  3232. reply.Data.SimName = Utils.StringToBytes(info.RegionName);
  3233. reply.Data.SnapshotID = land.SnapshotID;
  3234. reply.Data.Dwell = land.Dwell;
  3235. reply.Data.SalePrice = land.SalePrice;
  3236. reply.Data.AuctionID = (int)land.AuctionID;
  3237. OutPacket(reply, ThrottleOutPacketType.Land);
  3238. }
  3239. public void SendScriptTeleportRequest(string objName, string simName, Vector3 pos, Vector3 lookAt)
  3240. {
  3241. ScriptTeleportRequestPacket packet = (ScriptTeleportRequestPacket)PacketPool.Instance.GetPacket(PacketType.ScriptTeleportRequest);
  3242. packet.Data.ObjectName = Utils.StringToBytes(objName);
  3243. packet.Data.SimName = Utils.StringToBytes(simName);
  3244. packet.Data.SimPosition = pos;
  3245. packet.Data.LookAt = lookAt;
  3246. OutPacket(packet, ThrottleOutPacketType.Task);
  3247. }
  3248. public void SendDirPlacesReply(UUID queryID, DirPlacesReplyData[] data)
  3249. {
  3250. DirPlacesReplyPacket packet = (DirPlacesReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPlacesReply);
  3251. packet.AgentData = new DirPlacesReplyPacket.AgentDataBlock();
  3252. packet.QueryData = new DirPlacesReplyPacket.QueryDataBlock[1];
  3253. packet.QueryData[0] = new DirPlacesReplyPacket.QueryDataBlock();
  3254. packet.AgentData.AgentID = AgentId;
  3255. packet.QueryData[0].QueryID = queryID;
  3256. DirPlacesReplyPacket.QueryRepliesBlock[] replies =
  3257. new DirPlacesReplyPacket.QueryRepliesBlock[0];
  3258. DirPlacesReplyPacket.StatusDataBlock[] status =
  3259. new DirPlacesReplyPacket.StatusDataBlock[0];
  3260. packet.QueryReplies = replies;
  3261. packet.StatusData = status;
  3262. foreach (DirPlacesReplyData d in data)
  3263. {
  3264. int idx = replies.Length;
  3265. Array.Resize(ref replies, idx + 1);
  3266. Array.Resize(ref status, idx + 1);
  3267. replies[idx] = new DirPlacesReplyPacket.QueryRepliesBlock();
  3268. status[idx] = new DirPlacesReplyPacket.StatusDataBlock();
  3269. replies[idx].ParcelID = d.parcelID;
  3270. replies[idx].Name = Utils.StringToBytes(d.name);
  3271. replies[idx].ForSale = d.forSale;
  3272. replies[idx].Auction = d.auction;
  3273. replies[idx].Dwell = d.dwell;
  3274. status[idx].Status = d.Status;
  3275. packet.QueryReplies = replies;
  3276. packet.StatusData = status;
  3277. if (packet.Length >= 1000)
  3278. {
  3279. OutPacket(packet, ThrottleOutPacketType.Task);
  3280. packet = (DirPlacesReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPlacesReply);
  3281. packet.AgentData = new DirPlacesReplyPacket.AgentDataBlock();
  3282. packet.QueryData = new DirPlacesReplyPacket.QueryDataBlock[1];
  3283. packet.QueryData[0] = new DirPlacesReplyPacket.QueryDataBlock();
  3284. packet.AgentData.AgentID = AgentId;
  3285. packet.QueryData[0].QueryID = queryID;
  3286. replies = new DirPlacesReplyPacket.QueryRepliesBlock[0];
  3287. status = new DirPlacesReplyPacket.StatusDataBlock[0];
  3288. }
  3289. }
  3290. if (replies.Length > 0 || data.Length == 0)
  3291. OutPacket(packet, ThrottleOutPacketType.Task);
  3292. }
  3293. public void SendDirPeopleReply(UUID queryID, DirPeopleReplyData[] data)
  3294. {
  3295. DirPeopleReplyPacket packet = (DirPeopleReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPeopleReply);
  3296. packet.AgentData = new DirPeopleReplyPacket.AgentDataBlock();
  3297. packet.AgentData.AgentID = AgentId;
  3298. packet.QueryData = new DirPeopleReplyPacket.QueryDataBlock();
  3299. packet.QueryData.QueryID = queryID;
  3300. packet.QueryReplies = new DirPeopleReplyPacket.QueryRepliesBlock[
  3301. data.Length];
  3302. int i = 0;
  3303. foreach (DirPeopleReplyData d in data)
  3304. {
  3305. packet.QueryReplies[i] = new DirPeopleReplyPacket.QueryRepliesBlock();
  3306. packet.QueryReplies[i].AgentID = d.agentID;
  3307. packet.QueryReplies[i].FirstName =
  3308. Utils.StringToBytes(d.firstName);
  3309. packet.QueryReplies[i].LastName =
  3310. Utils.StringToBytes(d.lastName);
  3311. packet.QueryReplies[i].Group =
  3312. Utils.StringToBytes(d.group);
  3313. packet.QueryReplies[i].Online = d.online;
  3314. packet.QueryReplies[i].Reputation = d.reputation;
  3315. i++;
  3316. }
  3317. OutPacket(packet, ThrottleOutPacketType.Task);
  3318. }
  3319. public void SendDirEventsReply(UUID queryID, DirEventsReplyData[] data)
  3320. {
  3321. DirEventsReplyPacket packet = (DirEventsReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirEventsReply);
  3322. packet.AgentData = new DirEventsReplyPacket.AgentDataBlock();
  3323. packet.AgentData.AgentID = AgentId;
  3324. packet.QueryData = new DirEventsReplyPacket.QueryDataBlock();
  3325. packet.QueryData.QueryID = queryID;
  3326. packet.QueryReplies = new DirEventsReplyPacket.QueryRepliesBlock[
  3327. data.Length];
  3328. packet.StatusData = new DirEventsReplyPacket.StatusDataBlock[
  3329. data.Length];
  3330. int i = 0;
  3331. foreach (DirEventsReplyData d in data)
  3332. {
  3333. packet.QueryReplies[i] = new DirEventsReplyPacket.QueryRepliesBlock();
  3334. packet.StatusData[i] = new DirEventsReplyPacket.StatusDataBlock();
  3335. packet.QueryReplies[i].OwnerID = d.ownerID;
  3336. packet.QueryReplies[i].Name =
  3337. Utils.StringToBytes(d.name);
  3338. packet.QueryReplies[i].EventID = d.eventID;
  3339. packet.QueryReplies[i].Date =
  3340. Utils.StringToBytes(d.date);
  3341. packet.QueryReplies[i].UnixTime = d.unixTime;
  3342. packet.QueryReplies[i].EventFlags = d.eventFlags;
  3343. packet.StatusData[i].Status = d.Status;
  3344. i++;
  3345. }
  3346. OutPacket(packet, ThrottleOutPacketType.Task);
  3347. }
  3348. public void SendDirGroupsReply(UUID queryID, DirGroupsReplyData[] data)
  3349. {
  3350. DirGroupsReplyPacket packet = (DirGroupsReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirGroupsReply);
  3351. packet.AgentData = new DirGroupsReplyPacket.AgentDataBlock();
  3352. packet.AgentData.AgentID = AgentId;
  3353. packet.QueryData = new DirGroupsReplyPacket.QueryDataBlock();
  3354. packet.QueryData.QueryID = queryID;
  3355. packet.QueryReplies = new DirGroupsReplyPacket.QueryRepliesBlock[data.Length];
  3356. int i = 0;
  3357. foreach (DirGroupsReplyData d in data)
  3358. {
  3359. packet.QueryReplies[i] = new DirGroupsReplyPacket.QueryRepliesBlock();
  3360. packet.QueryReplies[i].GroupID = d.groupID;
  3361. packet.QueryReplies[i].GroupName = Util.StringToBytes(d.groupName, 35);
  3362. packet.QueryReplies[i].Members = d.members;
  3363. packet.QueryReplies[i].SearchOrder = d.searchOrder;
  3364. ++i;
  3365. }
  3366. OutPacket(packet, ThrottleOutPacketType.Task);
  3367. }
  3368. public void SendDirClassifiedReply(UUID queryID, DirClassifiedReplyData[] data)
  3369. {
  3370. DirClassifiedReplyPacket packet = (DirClassifiedReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirClassifiedReply);
  3371. packet.AgentData = new DirClassifiedReplyPacket.AgentDataBlock();
  3372. packet.AgentData.AgentID = AgentId;
  3373. packet.QueryData = new DirClassifiedReplyPacket.QueryDataBlock();
  3374. packet.QueryData.QueryID = queryID;
  3375. packet.QueryReplies = new DirClassifiedReplyPacket.QueryRepliesBlock[
  3376. data.Length];
  3377. packet.StatusData = new DirClassifiedReplyPacket.StatusDataBlock[
  3378. data.Length];
  3379. int i = 0;
  3380. foreach (DirClassifiedReplyData d in data)
  3381. {
  3382. packet.QueryReplies[i] = new DirClassifiedReplyPacket.QueryRepliesBlock();
  3383. packet.StatusData[i] = new DirClassifiedReplyPacket.StatusDataBlock();
  3384. packet.QueryReplies[i].ClassifiedID = d.classifiedID;
  3385. packet.QueryReplies[i].Name =
  3386. Utils.StringToBytes(d.name);
  3387. packet.QueryReplies[i].ClassifiedFlags = d.classifiedFlags;
  3388. packet.QueryReplies[i].CreationDate = d.creationDate;
  3389. packet.QueryReplies[i].ExpirationDate = d.expirationDate;
  3390. packet.QueryReplies[i].PriceForListing = d.price;
  3391. packet.StatusData[i].Status = d.Status;
  3392. i++;
  3393. }
  3394. OutPacket(packet, ThrottleOutPacketType.Task);
  3395. }
  3396. public void SendDirLandReply(UUID queryID, DirLandReplyData[] data)
  3397. {
  3398. DirLandReplyPacket packet = (DirLandReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirLandReply);
  3399. packet.AgentData = new DirLandReplyPacket.AgentDataBlock();
  3400. packet.AgentData.AgentID = AgentId;
  3401. packet.QueryData = new DirLandReplyPacket.QueryDataBlock();
  3402. packet.QueryData.QueryID = queryID;
  3403. packet.QueryReplies = new DirLandReplyPacket.QueryRepliesBlock[
  3404. data.Length];
  3405. int i = 0;
  3406. foreach (DirLandReplyData d in data)
  3407. {
  3408. packet.QueryReplies[i] = new DirLandReplyPacket.QueryRepliesBlock();
  3409. packet.QueryReplies[i].ParcelID = d.parcelID;
  3410. packet.QueryReplies[i].Name =
  3411. Utils.StringToBytes(d.name);
  3412. packet.QueryReplies[i].Auction = d.auction;
  3413. packet.QueryReplies[i].ForSale = d.forSale;
  3414. packet.QueryReplies[i].SalePrice = d.salePrice;
  3415. packet.QueryReplies[i].ActualArea = d.actualArea;
  3416. i++;
  3417. }
  3418. OutPacket(packet, ThrottleOutPacketType.Task);
  3419. }
  3420. public void SendDirPopularReply(UUID queryID, DirPopularReplyData[] data)
  3421. {
  3422. DirPopularReplyPacket packet = (DirPopularReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPopularReply);
  3423. packet.AgentData = new DirPopularReplyPacket.AgentDataBlock();
  3424. packet.AgentData.AgentID = AgentId;
  3425. packet.QueryData = new DirPopularReplyPacket.QueryDataBlock();
  3426. packet.QueryData.QueryID = queryID;
  3427. packet.QueryReplies = new DirPopularReplyPacket.QueryRepliesBlock[
  3428. data.Length];
  3429. int i = 0;
  3430. foreach (DirPopularReplyData d in data)
  3431. {
  3432. packet.QueryReplies[i] = new DirPopularReplyPacket.QueryRepliesBlock();
  3433. packet.QueryReplies[i].ParcelID = d.parcelID;
  3434. packet.QueryReplies[i].Name =
  3435. Utils.StringToBytes(d.name);
  3436. packet.QueryReplies[i].Dwell = d.dwell;
  3437. i++;
  3438. }
  3439. OutPacket(packet, ThrottleOutPacketType.Task);
  3440. }
  3441. public void SendEventInfoReply(EventData data)
  3442. {
  3443. EventInfoReplyPacket packet = (EventInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.EventInfoReply);
  3444. packet.AgentData = new EventInfoReplyPacket.AgentDataBlock();
  3445. packet.AgentData.AgentID = AgentId;
  3446. packet.EventData = new EventInfoReplyPacket.EventDataBlock();
  3447. packet.EventData.EventID = data.eventID;
  3448. packet.EventData.Creator = Utils.StringToBytes(data.creator);
  3449. packet.EventData.Name = Utils.StringToBytes(data.name);
  3450. packet.EventData.Category = Utils.StringToBytes(data.category);
  3451. packet.EventData.Desc = Utils.StringToBytes(data.description);
  3452. packet.EventData.Date = Utils.StringToBytes(data.date);
  3453. packet.EventData.DateUTC = data.dateUTC;
  3454. packet.EventData.Duration = data.duration;
  3455. packet.EventData.Cover = data.cover;
  3456. packet.EventData.Amount = data.amount;
  3457. packet.EventData.SimName = Utils.StringToBytes(data.simName);
  3458. packet.EventData.GlobalPos = new Vector3d(data.globalPos);
  3459. packet.EventData.EventFlags = data.eventFlags;
  3460. OutPacket(packet, ThrottleOutPacketType.Task);
  3461. }
  3462. public void SendOfferCallingCard(UUID srcID, UUID transactionID)
  3463. {
  3464. // a bit special, as this uses AgentID to store the source instead
  3465. // of the destination. The destination (the receiver) goes into destID
  3466. OfferCallingCardPacket p = (OfferCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.OfferCallingCard);
  3467. p.AgentData.AgentID = srcID;
  3468. p.AgentData.SessionID = UUID.Zero;
  3469. p.AgentBlock.DestID = AgentId;
  3470. p.AgentBlock.TransactionID = transactionID;
  3471. OutPacket(p, ThrottleOutPacketType.Task);
  3472. }
  3473. public void SendAcceptCallingCard(UUID transactionID)
  3474. {
  3475. AcceptCallingCardPacket p = (AcceptCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.AcceptCallingCard);
  3476. p.AgentData.AgentID = AgentId;
  3477. p.AgentData.SessionID = UUID.Zero;
  3478. p.FolderData = new AcceptCallingCardPacket.FolderDataBlock[1];
  3479. p.FolderData[0] = new AcceptCallingCardPacket.FolderDataBlock();
  3480. p.FolderData[0].FolderID = UUID.Zero;
  3481. OutPacket(p, ThrottleOutPacketType.Task);
  3482. }
  3483. public void SendDeclineCallingCard(UUID transactionID)
  3484. {
  3485. DeclineCallingCardPacket p = (DeclineCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.DeclineCallingCard);
  3486. p.AgentData.AgentID = AgentId;
  3487. p.AgentData.SessionID = UUID.Zero;
  3488. p.TransactionBlock.TransactionID = transactionID;
  3489. OutPacket(p, ThrottleOutPacketType.Task);
  3490. }
  3491. public void SendTerminateFriend(UUID exFriendID)
  3492. {
  3493. TerminateFriendshipPacket p = (TerminateFriendshipPacket)PacketPool.Instance.GetPacket(PacketType.TerminateFriendship);
  3494. p.AgentData.AgentID = AgentId;
  3495. p.AgentData.SessionID = SessionId;
  3496. p.ExBlock.OtherID = exFriendID;
  3497. OutPacket(p, ThrottleOutPacketType.Task);
  3498. }
  3499. public void SendAvatarGroupsReply(UUID avatarID, GroupMembershipData[] data)
  3500. {
  3501. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  3502. if (eq == null)
  3503. return;
  3504. // message template has a GroupData field AcceptNotices ignored by viewers
  3505. // and a array NewGroupData also ignored
  3506. osUTF8 sb = eq.StartEvent("AvatarGroupsReply");
  3507. LLSDxmlEncode2.AddArrayAndMap("AgentData", sb);
  3508. LLSDxmlEncode2.AddElem("AgentID", AgentId, sb);
  3509. LLSDxmlEncode2.AddElem("AvatarID", avatarID, sb);
  3510. LLSDxmlEncode2.AddEndMapAndArray(sb);
  3511. bool notSameAvatar = avatarID != AgentId;
  3512. if(data.Length == 0)
  3513. LLSDxmlEncode2.AddEmptyArray("GroupData", sb);
  3514. else
  3515. {
  3516. LLSDxmlEncode2.AddArray("GroupData", sb);
  3517. GroupMembershipData m;
  3518. for (int indx = 0; indx < data.Length; ++indx)
  3519. {
  3520. m = data[indx];
  3521. if(notSameAvatar && !m.ListInProfile)
  3522. continue;
  3523. LLSDxmlEncode2.AddMap(sb);
  3524. LLSDxmlEncode2.AddElem("GroupPowers", m.GroupPowers, sb);
  3525. LLSDxmlEncode2.AddElem("GroupTitle", m.GroupTitle, sb);
  3526. LLSDxmlEncode2.AddElem("GroupID",m.GroupID, sb);
  3527. LLSDxmlEncode2.AddElem("GroupName", m.GroupName, sb);
  3528. LLSDxmlEncode2.AddElem("GroupInsigniaID", m.GroupPicture, sb);
  3529. LLSDxmlEncode2.AddEndMap(sb);
  3530. }
  3531. LLSDxmlEncode2.AddEndArray(sb);
  3532. }
  3533. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  3534. }
  3535. public void SendAgentGroupDataUpdate(UUID avatarID, GroupMembershipData[] data)
  3536. {
  3537. if(avatarID != AgentId)
  3538. m_log.Debug("[CLIENT]: SendAgentGroupDataUpdate avatarID != AgentId");
  3539. IEventQueue eq = this.Scene.RequestModuleInterface<IEventQueue>();
  3540. if(eq != null)
  3541. {
  3542. eq.GroupMembershipData(avatarID,data);
  3543. }
  3544. else
  3545. {
  3546. // use UDP if no caps
  3547. AgentGroupDataUpdatePacket Groupupdate = new AgentGroupDataUpdatePacket();
  3548. AgentGroupDataUpdatePacket.GroupDataBlock[] Groups = new AgentGroupDataUpdatePacket.GroupDataBlock[data.Length];
  3549. for (int i = 0; i < data.Length; ++i)
  3550. {
  3551. AgentGroupDataUpdatePacket.GroupDataBlock Group = new AgentGroupDataUpdatePacket.GroupDataBlock();
  3552. Group.AcceptNotices = data[i].AcceptNotices;
  3553. Group.Contribution = data[i].Contribution;
  3554. Group.GroupID = data[i].GroupID;
  3555. Group.GroupInsigniaID = data[i].GroupPicture;
  3556. Group.GroupName = Util.StringToBytes256(data[i].GroupName);
  3557. Group.GroupPowers = data[i].GroupPowers;
  3558. Groups[i] = Group;
  3559. }
  3560. Groupupdate.GroupData = Groups;
  3561. Groupupdate.AgentData = new AgentGroupDataUpdatePacket.AgentDataBlock();
  3562. Groupupdate.AgentData.AgentID = avatarID;
  3563. OutPacket(Groupupdate, ThrottleOutPacketType.Task);
  3564. }
  3565. }
  3566. public void SendJoinGroupReply(UUID groupID, bool success)
  3567. {
  3568. JoinGroupReplyPacket p = (JoinGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.JoinGroupReply);
  3569. p.AgentData = new JoinGroupReplyPacket.AgentDataBlock();
  3570. p.AgentData.AgentID = AgentId;
  3571. p.GroupData = new JoinGroupReplyPacket.GroupDataBlock();
  3572. p.GroupData.GroupID = groupID;
  3573. p.GroupData.Success = success;
  3574. OutPacket(p, ThrottleOutPacketType.Task);
  3575. }
  3576. public void SendEjectGroupMemberReply(UUID agentID, UUID groupID, bool success)
  3577. {
  3578. EjectGroupMemberReplyPacket p = (EjectGroupMemberReplyPacket)PacketPool.Instance.GetPacket(PacketType.EjectGroupMemberReply);
  3579. p.AgentData = new EjectGroupMemberReplyPacket.AgentDataBlock();
  3580. p.AgentData.AgentID = agentID;
  3581. p.GroupData = new EjectGroupMemberReplyPacket.GroupDataBlock();
  3582. p.GroupData.GroupID = groupID;
  3583. p.EjectData = new EjectGroupMemberReplyPacket.EjectDataBlock();
  3584. p.EjectData.Success = success;
  3585. OutPacket(p, ThrottleOutPacketType.Task);
  3586. }
  3587. public void SendLeaveGroupReply(UUID groupID, bool success)
  3588. {
  3589. LeaveGroupReplyPacket p = (LeaveGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.LeaveGroupReply);
  3590. p.AgentData = new LeaveGroupReplyPacket.AgentDataBlock();
  3591. p.AgentData.AgentID = AgentId;
  3592. p.GroupData = new LeaveGroupReplyPacket.GroupDataBlock();
  3593. p.GroupData.GroupID = groupID;
  3594. p.GroupData.Success = success;
  3595. OutPacket(p, ThrottleOutPacketType.Task);
  3596. }
  3597. public void SendAvatarClassifiedReply(UUID targetID, UUID[] classifiedID, string[] name)
  3598. {
  3599. if (classifiedID.Length != name.Length)
  3600. return;
  3601. AvatarClassifiedReplyPacket ac =
  3602. (AvatarClassifiedReplyPacket)PacketPool.Instance.GetPacket(
  3603. PacketType.AvatarClassifiedReply);
  3604. ac.AgentData = new AvatarClassifiedReplyPacket.AgentDataBlock();
  3605. ac.AgentData.AgentID = AgentId;
  3606. ac.AgentData.TargetID = targetID;
  3607. ac.Data = new AvatarClassifiedReplyPacket.DataBlock[classifiedID.Length];
  3608. int i;
  3609. for (i = 0; i < classifiedID.Length; i++)
  3610. {
  3611. ac.Data[i].ClassifiedID = classifiedID[i];
  3612. ac.Data[i].Name = Utils.StringToBytes(name[i]);
  3613. }
  3614. OutPacket(ac, ThrottleOutPacketType.Task);
  3615. }
  3616. 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)
  3617. {
  3618. ClassifiedInfoReplyPacket cr =
  3619. (ClassifiedInfoReplyPacket)PacketPool.Instance.GetPacket(
  3620. PacketType.ClassifiedInfoReply);
  3621. cr.AgentData = new ClassifiedInfoReplyPacket.AgentDataBlock();
  3622. cr.AgentData.AgentID = AgentId;
  3623. cr.Data = new ClassifiedInfoReplyPacket.DataBlock();
  3624. cr.Data.ClassifiedID = classifiedID;
  3625. cr.Data.CreatorID = creatorID;
  3626. cr.Data.CreationDate = creationDate;
  3627. cr.Data.ExpirationDate = expirationDate;
  3628. cr.Data.Category = category;
  3629. cr.Data.Name = Utils.StringToBytes(name);
  3630. cr.Data.Desc = Utils.StringToBytes(description);
  3631. cr.Data.ParcelID = parcelID;
  3632. cr.Data.ParentEstate = parentEstate;
  3633. cr.Data.SnapshotID = snapshotID;
  3634. cr.Data.SimName = Utils.StringToBytes(simName);
  3635. cr.Data.PosGlobal = new Vector3d(globalPos);
  3636. cr.Data.ParcelName = Utils.StringToBytes(parcelName);
  3637. cr.Data.ClassifiedFlags = classifiedFlags;
  3638. cr.Data.PriceForListing = price;
  3639. OutPacket(cr, ThrottleOutPacketType.Task);
  3640. }
  3641. public void SendAgentDropGroup(UUID groupID)
  3642. {
  3643. AgentDropGroupPacket dg =
  3644. (AgentDropGroupPacket)PacketPool.Instance.GetPacket(
  3645. PacketType.AgentDropGroup);
  3646. dg.AgentData = new AgentDropGroupPacket.AgentDataBlock();
  3647. dg.AgentData.AgentID = AgentId;
  3648. dg.AgentData.GroupID = groupID;
  3649. OutPacket(dg, ThrottleOutPacketType.Task);
  3650. }
  3651. public void SendAvatarNotesReply(UUID targetID, string text)
  3652. {
  3653. AvatarNotesReplyPacket an =
  3654. (AvatarNotesReplyPacket)PacketPool.Instance.GetPacket(
  3655. PacketType.AvatarNotesReply);
  3656. an.AgentData = new AvatarNotesReplyPacket.AgentDataBlock();
  3657. an.AgentData.AgentID = AgentId;
  3658. an.Data = new AvatarNotesReplyPacket.DataBlock();
  3659. an.Data.TargetID = targetID;
  3660. an.Data.Notes = Utils.StringToBytes(text);
  3661. OutPacket(an, ThrottleOutPacketType.Task);
  3662. }
  3663. public void SendAvatarPicksReply(UUID targetID, Dictionary<UUID, string> picks)
  3664. {
  3665. AvatarPicksReplyPacket ap =
  3666. (AvatarPicksReplyPacket)PacketPool.Instance.GetPacket(
  3667. PacketType.AvatarPicksReply);
  3668. ap.AgentData = new AvatarPicksReplyPacket.AgentDataBlock();
  3669. ap.AgentData.AgentID = AgentId;
  3670. ap.AgentData.TargetID = targetID;
  3671. ap.Data = new AvatarPicksReplyPacket.DataBlock[picks.Count];
  3672. int i = 0;
  3673. foreach (KeyValuePair<UUID, string> pick in picks)
  3674. {
  3675. ap.Data[i] = new AvatarPicksReplyPacket.DataBlock();
  3676. ap.Data[i].PickID = pick.Key;
  3677. ap.Data[i].PickName = Utils.StringToBytes(pick.Value);
  3678. i++;
  3679. }
  3680. OutPacket(ap, ThrottleOutPacketType.Task);
  3681. }
  3682. public void SendAvatarClassifiedReply(UUID targetID, Dictionary<UUID, string> classifieds)
  3683. {
  3684. AvatarClassifiedReplyPacket ac =
  3685. (AvatarClassifiedReplyPacket)PacketPool.Instance.GetPacket(
  3686. PacketType.AvatarClassifiedReply);
  3687. ac.AgentData = new AvatarClassifiedReplyPacket.AgentDataBlock();
  3688. ac.AgentData.AgentID = AgentId;
  3689. ac.AgentData.TargetID = targetID;
  3690. ac.Data = new AvatarClassifiedReplyPacket.DataBlock[classifieds.Count];
  3691. int i = 0;
  3692. foreach (KeyValuePair<UUID, string> classified in classifieds)
  3693. {
  3694. ac.Data[i] = new AvatarClassifiedReplyPacket.DataBlock();
  3695. ac.Data[i].ClassifiedID = classified.Key;
  3696. ac.Data[i].Name = Utils.StringToBytes(classified.Value);
  3697. i++;
  3698. }
  3699. OutPacket(ac, ThrottleOutPacketType.Task);
  3700. }
  3701. public void SendParcelDwellReply(int localID, UUID parcelID, float dwell)
  3702. {
  3703. ParcelDwellReplyPacket pd =
  3704. (ParcelDwellReplyPacket)PacketPool.Instance.GetPacket(
  3705. PacketType.ParcelDwellReply);
  3706. pd.AgentData = new ParcelDwellReplyPacket.AgentDataBlock();
  3707. pd.AgentData.AgentID = AgentId;
  3708. pd.Data = new ParcelDwellReplyPacket.DataBlock();
  3709. pd.Data.LocalID = localID;
  3710. pd.Data.ParcelID = parcelID;
  3711. pd.Data.Dwell = dwell;
  3712. OutPacket(pd, ThrottleOutPacketType.Land);
  3713. }
  3714. public void SendUserInfoReply(bool imViaEmail, bool visible, string email)
  3715. {
  3716. UserInfoReplyPacket ur =
  3717. (UserInfoReplyPacket)PacketPool.Instance.GetPacket(
  3718. PacketType.UserInfoReply);
  3719. string Visible = "hidden";
  3720. if (visible)
  3721. Visible = "default";
  3722. ur.AgentData = new UserInfoReplyPacket.AgentDataBlock();
  3723. ur.AgentData.AgentID = AgentId;
  3724. ur.UserData = new UserInfoReplyPacket.UserDataBlock();
  3725. ur.UserData.IMViaEMail = imViaEmail;
  3726. ur.UserData.DirectoryVisibility = Utils.StringToBytes(Visible);
  3727. ur.UserData.EMail = Utils.StringToBytes(email);
  3728. OutPacket(ur, ThrottleOutPacketType.Task);
  3729. }
  3730. public void SendCreateGroupReply(UUID groupID, bool success, string message)
  3731. {
  3732. CreateGroupReplyPacket createGroupReply = (CreateGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.CreateGroupReply);
  3733. createGroupReply.AgentData =
  3734. new CreateGroupReplyPacket.AgentDataBlock();
  3735. createGroupReply.ReplyData =
  3736. new CreateGroupReplyPacket.ReplyDataBlock();
  3737. createGroupReply.AgentData.AgentID = AgentId;
  3738. createGroupReply.ReplyData.GroupID = groupID;
  3739. createGroupReply.ReplyData.Success = success;
  3740. createGroupReply.ReplyData.Message = Utils.StringToBytes(message);
  3741. OutPacket(createGroupReply, ThrottleOutPacketType.Task);
  3742. }
  3743. public void SendUseCachedMuteList()
  3744. {
  3745. UseCachedMuteListPacket useCachedMuteList = (UseCachedMuteListPacket)PacketPool.Instance.GetPacket(PacketType.UseCachedMuteList);
  3746. useCachedMuteList.AgentData = new UseCachedMuteListPacket.AgentDataBlock();
  3747. useCachedMuteList.AgentData.AgentID = AgentId;
  3748. OutPacket(useCachedMuteList, ThrottleOutPacketType.Task);
  3749. }
  3750. public void SendEmpytMuteList()
  3751. {
  3752. GenericMessagePacket gmp = new GenericMessagePacket();
  3753. gmp.AgentData.AgentID = AgentId;
  3754. gmp.AgentData.SessionID = m_sessionId;
  3755. gmp.AgentData.TransactionID = UUID.Zero;
  3756. gmp.MethodData.Method = Util.StringToBytes256("emptymutelist");
  3757. gmp.ParamList = new GenericMessagePacket.ParamListBlock[1];
  3758. gmp.ParamList[0] = new GenericMessagePacket.ParamListBlock();
  3759. gmp.ParamList[0].Parameter = new byte[0];
  3760. OutPacket(gmp, ThrottleOutPacketType.Task);
  3761. }
  3762. public void SendMuteListUpdate(string filename)
  3763. {
  3764. MuteListUpdatePacket muteListUpdate = (MuteListUpdatePacket)PacketPool.Instance.GetPacket(PacketType.MuteListUpdate);
  3765. muteListUpdate.MuteData = new MuteListUpdatePacket.MuteDataBlock();
  3766. muteListUpdate.MuteData.AgentID = AgentId;
  3767. muteListUpdate.MuteData.Filename = Utils.StringToBytes(filename);
  3768. OutPacket(muteListUpdate, ThrottleOutPacketType.Task);
  3769. }
  3770. 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)
  3771. {
  3772. PickInfoReplyPacket pickInfoReply = (PickInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.PickInfoReply);
  3773. pickInfoReply.AgentData = new PickInfoReplyPacket.AgentDataBlock();
  3774. pickInfoReply.AgentData.AgentID = AgentId;
  3775. pickInfoReply.Data = new PickInfoReplyPacket.DataBlock();
  3776. pickInfoReply.Data.PickID = pickID;
  3777. pickInfoReply.Data.CreatorID = creatorID;
  3778. pickInfoReply.Data.TopPick = topPick;
  3779. pickInfoReply.Data.ParcelID = parcelID;
  3780. pickInfoReply.Data.Name = Utils.StringToBytes(name);
  3781. pickInfoReply.Data.Desc = Utils.StringToBytes(desc);
  3782. pickInfoReply.Data.SnapshotID = snapshotID;
  3783. pickInfoReply.Data.User = Utils.StringToBytes(user);
  3784. pickInfoReply.Data.OriginalName = Utils.StringToBytes(originalName);
  3785. pickInfoReply.Data.SimName = Utils.StringToBytes(simName);
  3786. pickInfoReply.Data.PosGlobal = new Vector3d(posGlobal);
  3787. pickInfoReply.Data.SortOrder = sortOrder;
  3788. pickInfoReply.Data.Enabled = enabled;
  3789. OutPacket(pickInfoReply, ThrottleOutPacketType.Task);
  3790. }
  3791. #endregion Scene/Avatar to Client
  3792. // Gesture
  3793. #region Appearance/ Wearables Methods
  3794. public void SendWearables(AvatarWearable[] wearables, int serial)
  3795. {
  3796. AgentWearablesUpdatePacket aw = (AgentWearablesUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentWearablesUpdate);
  3797. aw.AgentData.AgentID = AgentId;
  3798. aw.AgentData.SerialNum = (uint)serial;
  3799. aw.AgentData.SessionID = m_sessionId;
  3800. int count = 0;
  3801. for (int i = 0; i < wearables.Length; i++)
  3802. count += wearables[i].Count;
  3803. // TODO: don't create new blocks if recycling an old packet
  3804. aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[count];
  3805. AgentWearablesUpdatePacket.WearableDataBlock awb;
  3806. int idx = 0;
  3807. for (int i = 0; i < wearables.Length; i++)
  3808. {
  3809. for (int j = 0; j < wearables[i].Count; j++)
  3810. {
  3811. awb = new AgentWearablesUpdatePacket.WearableDataBlock();
  3812. awb.WearableType = (byte) i;
  3813. awb.AssetID = wearables[i][j].AssetID;
  3814. awb.ItemID = wearables[i][j].ItemID;
  3815. aw.WearableData[idx] = awb;
  3816. idx++;
  3817. // m_log.DebugFormat(
  3818. // "[APPEARANCE]: Sending wearable item/asset {0} {1} (index {2}) for {3}",
  3819. // awb.ItemID, awb.AssetID, i, Name);
  3820. }
  3821. }
  3822. OutPacket(aw, ThrottleOutPacketType.Task);
  3823. }
  3824. static private readonly byte[] AvatarAppearanceHeader = new byte[] {
  3825. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED,
  3826. 0, 0, 0, 0, // sequence number
  3827. 0, // extra
  3828. 0xff, 0xff, 0, 158 // ID 158 (low frequency bigendian) not zeroencoded
  3829. //0xff, 0xff, 0, 1, 158 // ID 158 (low frequency bigendian) zeroencoded
  3830. };
  3831. public void SendAppearance(UUID targetID, byte[] visualParams, byte[] textureEntry, float hover)
  3832. {
  3833. // doing post zero encode, because odds of beeing bad are not that low
  3834. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3835. Buffer.BlockCopy(AvatarAppearanceHeader, 0, buf.Data, 0, 10);
  3836. byte[] data = buf.Data;
  3837. int pos = 10;
  3838. //sender block
  3839. targetID.ToBytes(data, pos); pos += 16;
  3840. data[pos++] = 0;// is trial = false
  3841. // objectdata block ie texture
  3842. int len = textureEntry.Length;
  3843. if (len == 0)
  3844. {
  3845. data[pos++] = 0;
  3846. data[pos++] = 0;
  3847. }
  3848. else
  3849. {
  3850. data[pos++] = (byte)len;
  3851. data[pos++] = (byte)(len >> 8);
  3852. Buffer.BlockCopy(textureEntry, 0, data, pos, len); pos += len;
  3853. }
  3854. // visual parameters
  3855. len = visualParams.Length;
  3856. data[pos++] = (byte)len;
  3857. if(len > 0)
  3858. Buffer.BlockCopy(visualParams, 0, data, pos, len); pos += len;
  3859. // no AppearanceData
  3860. data[pos++] = 0;
  3861. // AppearanceHover vector 3
  3862. data[pos++] = 1;
  3863. Utils.FloatToBytesSafepos(0, data, pos); pos += 4;
  3864. Utils.FloatToBytesSafepos(0, data, pos); pos += 4;
  3865. Utils.FloatToBytesSafepos(hover, data, pos); pos += 4;
  3866. buf.DataLength = pos;
  3867. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, true);
  3868. }
  3869. static private readonly byte[] AvatarAnimationHeader = new byte[] {
  3870. Helpers.MSG_RELIABLE,
  3871. 0, 0, 0, 0, // sequence number
  3872. 0, // extra
  3873. 20 // ID (high frequency)
  3874. };
  3875. public void SendAnimations(UUID[] animations, int[] seqs, UUID sourceAgentId, UUID[] objectIDs)
  3876. {
  3877. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending animations for {0} to {1}", sourceAgentId, Name);
  3878. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3879. byte[] data = buf.Data;
  3880. //setup header
  3881. Buffer.BlockCopy(AvatarAnimationHeader, 0, data, 0, 7);
  3882. //agent block
  3883. sourceAgentId.ToBytes(data, 7);
  3884. // animations count
  3885. data[23] = (byte)animations.Length;
  3886. int pos = 24;
  3887. //self animations
  3888. if (sourceAgentId == AgentId)
  3889. {
  3890. List<int> withobjects = new List<int>(animations.Length);
  3891. List<int> noobjects = new List<int>(animations.Length);
  3892. for (int indx = 0; indx < animations.Length; ++indx)
  3893. {
  3894. if (objectIDs[indx] == sourceAgentId || objectIDs[indx] == UUID.Zero)
  3895. noobjects.Add(indx);
  3896. else
  3897. withobjects.Add(indx);
  3898. }
  3899. int i;
  3900. // first the ones with corresponding objects
  3901. for (int indx = 0; indx < withobjects.Count; ++indx)
  3902. {
  3903. i = withobjects[indx];
  3904. animations[i].ToBytes(data, pos); pos += 16;
  3905. Utils.IntToBytesSafepos(seqs[i], data, pos); pos += 4;
  3906. }
  3907. // then the rest
  3908. for (int indx = 0; indx < noobjects.Count; ++indx)
  3909. {
  3910. i = noobjects[indx];
  3911. animations[i].ToBytes(data, pos); pos += 16;
  3912. Utils.IntToBytesSafepos(seqs[i], data, pos); pos += 4;
  3913. }
  3914. // object ids block
  3915. data[pos++] = (byte)withobjects.Count;
  3916. for (int indx = 0; indx < withobjects.Count; ++indx)
  3917. {
  3918. i = withobjects[indx];
  3919. objectIDs[i].ToBytes(data, pos); pos += 16;
  3920. }
  3921. }
  3922. else
  3923. {
  3924. for(int i = 0; i < animations.Length; ++i)
  3925. {
  3926. animations[i].ToBytes(data, pos); pos += 16;
  3927. Utils.IntToBytesSafepos(seqs[i], data, pos); pos += 4;
  3928. }
  3929. data[pos++] = 0; // no object ids
  3930. }
  3931. data[pos++] = 0; // no physical avatar events
  3932. buf.DataLength = pos;
  3933. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  3934. }
  3935. public void SendObjectAnimations(UUID[] animations, int[] seqs, UUID senderId)
  3936. {
  3937. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending Object animations for {0} to {1}", sourceAgentId, Name);
  3938. if(!m_SupportObjectAnimations)
  3939. return;
  3940. ObjectAnimationPacket ani = (ObjectAnimationPacket)PacketPool.Instance.GetPacket(PacketType.ObjectAnimation);
  3941. // TODO: don't create new blocks if recycling an old packet
  3942. ani.Sender = new ObjectAnimationPacket.SenderBlock();
  3943. ani.Sender.ID = senderId;
  3944. ani.AnimationList = new ObjectAnimationPacket.AnimationListBlock[animations.Length];
  3945. for (int i = 0; i < animations.Length; ++i)
  3946. {
  3947. ani.AnimationList[i] = new ObjectAnimationPacket.AnimationListBlock();
  3948. ani.AnimationList[i].AnimID = animations[i];
  3949. ani.AnimationList[i].AnimSequenceID = seqs[i];
  3950. }
  3951. OutPacket(ani, ThrottleOutPacketType.Task);
  3952. }
  3953. #endregion
  3954. #region Avatar Packet/Data Sending Methods
  3955. /// <summary>
  3956. /// Send an ObjectUpdate packet with information about an avatar
  3957. /// </summary>
  3958. public void SendEntityFullUpdateImmediate(ISceneEntity ent)
  3959. {
  3960. if (ent == null || (!(ent is ScenePresence) && !(ent is SceneObjectPart)))
  3961. return;
  3962. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3963. Buffer.BlockCopy(objectUpdateHeader, 0, buf.Data, 0, 7);
  3964. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  3965. zc.Position = 7;
  3966. zc.AddUInt64(m_scene.RegionInfo.RegionHandle);
  3967. zc.AddUInt16(Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f));
  3968. zc.AddByte(1); // block count
  3969. if (ent is ScenePresence)
  3970. CreateAvatarUpdateBlock(ent as ScenePresence, zc);
  3971. else
  3972. CreatePrimUpdateBlock(ent as SceneObjectPart, (ScenePresence)SceneAgent, zc);
  3973. buf.DataLength = zc.Finish();
  3974. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  3975. }
  3976. public void SendEntityTerseUpdateImmediate(ISceneEntity ent)
  3977. {
  3978. if (ent == null)
  3979. return;
  3980. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3981. //setup header and regioninfo block
  3982. Buffer.BlockCopy(terseUpdateHeader, 0, buf.Data, 0, 7);
  3983. if (ent is ScenePresence)
  3984. Utils.UInt64ToBytesSafepos(((ScenePresence)ent).RegionHandle, buf.Data, 7);
  3985. else
  3986. Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, buf.Data, 7);
  3987. Utils.UInt16ToBytes(Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f), buf.Data, 15);
  3988. buf.Data[17] = 1;
  3989. int pos = 18;
  3990. CreateImprovedTerseBlock(ent, buf.Data, ref pos, false);
  3991. buf.DataLength = pos;
  3992. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, true);
  3993. }
  3994. //UUID m_courseLocationPrey = UUID.Zero;
  3995. bool m_couseLocationLastEmpty = false;
  3996. static private readonly byte[] CoarseLocationUpdateHeader = new byte[] {
  3997. 0, // no acks plz
  3998. 0, 0, 0, 0, // sequence number
  3999. 0, // extra
  4000. 0xff, 6 // ID 6 (medium frequency)
  4001. };
  4002. public void SendCoarseLocationUpdate(List<UUID> users, List<Vector3> CoarseLocations)
  4003. {
  4004. // We don't need to update inactive clients.
  4005. if (!IsActive)
  4006. return;
  4007. int totalLocations = Math.Min(CoarseLocations.Count, 60);
  4008. if(totalLocations == 0)
  4009. {
  4010. if(m_couseLocationLastEmpty)
  4011. return;
  4012. m_couseLocationLastEmpty = true;
  4013. }
  4014. else
  4015. m_couseLocationLastEmpty = false;
  4016. int totalAgents = Math.Min(users.Count, 60);
  4017. if(totalAgents > totalLocations)
  4018. totalAgents = totalLocations;
  4019. int selfindex = -1;
  4020. int preyindex = -1;
  4021. //bool doprey = m_courseLocationPrey != UUID.Zero;
  4022. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4023. Buffer.BlockCopy(CoarseLocationUpdateHeader, 0, buf.Data, 0, 8);
  4024. byte[] data = buf.Data;
  4025. data[8] = (byte)totalLocations;
  4026. int pos = 9;
  4027. for (int i = 0; i < totalLocations; ++i)
  4028. {
  4029. data[pos++] = (byte)CoarseLocations[i].X;
  4030. data[pos++] = (byte)CoarseLocations[i].Y;
  4031. data[pos++] = CoarseLocations[i].Z > 1024 ? (byte)0 : (byte)(CoarseLocations[i].Z * 0.25f);
  4032. if (i < totalAgents)
  4033. {
  4034. if (users[i] == AgentId)
  4035. selfindex = i;
  4036. //if (doprey && users[i] == m_courseLocationPrey)
  4037. // preyindex = i;
  4038. }
  4039. }
  4040. Utils.Int16ToBytes((short)selfindex, data, pos); pos += 2;
  4041. Utils.Int16ToBytes((short)preyindex, data, pos); pos += 2;
  4042. data[pos++] = (byte)totalAgents;
  4043. for (int i = 0; i < totalAgents; ++i)
  4044. {
  4045. users[i].ToBytes(data, pos);
  4046. pos += 16;
  4047. }
  4048. buf.DataLength = pos;
  4049. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  4050. }
  4051. #endregion Avatar Packet/Data Sending Methods
  4052. #region Primitive Packet/Data Sending Methods
  4053. /// <summary>
  4054. /// Generate one of the object update packets based on PrimUpdateFlags
  4055. /// and broadcast the packet to clients
  4056. /// </summary>
  4057. public void SendEntityUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags)
  4058. {
  4059. if (entity is SceneObjectPart)
  4060. {
  4061. SceneObjectPart p = (SceneObjectPart)entity;
  4062. SceneObjectGroup g = p.ParentGroup;
  4063. if (g.HasPrivateAttachmentPoint && g.OwnerID != AgentId)
  4064. return; // Don't send updates for other people's HUDs
  4065. if((updateFlags ^ PrimUpdateFlags.SendInTransit) == 0)
  4066. {
  4067. List<uint> partIDs = (new List<uint> {p.LocalId});
  4068. lock (m_entityProps.SyncRoot)
  4069. m_entityProps.Remove(partIDs);
  4070. lock (m_entityUpdates.SyncRoot)
  4071. m_entityUpdates.Remove(partIDs);
  4072. return;
  4073. }
  4074. }
  4075. int priority = m_prioritizer.GetUpdatePriority(this, entity);
  4076. lock (m_entityUpdates.SyncRoot)
  4077. m_entityUpdates.Enqueue(priority, EntityUpdatesPool.Get(entity, updateFlags));
  4078. }
  4079. /// <summary>
  4080. /// Requeue an EntityUpdate when it was not acknowledged by the client.
  4081. /// We will update the priority and put it in the correct queue, merging update flags
  4082. /// with any other updates that may be queued for the same entity.
  4083. /// The original update time is used for the merged update.
  4084. /// </summary>
  4085. private void ResendPrimUpdate(EntityUpdate update)
  4086. {
  4087. // If the update exists in priority queue, it will be updated.
  4088. // If it does not exist then it will be added with the current (rather than its original) priority
  4089. int priority = m_prioritizer.GetUpdatePriority(this, update.Entity);
  4090. lock (m_entityUpdates.SyncRoot)
  4091. m_entityUpdates.Enqueue(priority, update);
  4092. }
  4093. /// <summary>
  4094. /// Requeue a list of EntityUpdates when they were not acknowledged by the client.
  4095. /// We will update the priority and put it in the correct queue, merging update flags
  4096. /// with any other updates that may be queued for the same entity.
  4097. /// The original update time is used for the merged update.
  4098. /// </summary>
  4099. private void ResendPrimUpdates(List<EntityUpdate> updates, OutgoingPacket oPacket)
  4100. {
  4101. // m_log.WarnFormat("[CLIENT] resending prim updates {0}, packet sequence number {1}", updates[0].UpdateTime, oPacket.SequenceNumber);
  4102. // Remove the update packet from the list of packets waiting for acknowledgement
  4103. // because we are requeuing the list of updates. They will be resent in new packets
  4104. // with the most recent state and priority.
  4105. m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber);
  4106. if (oPacket.Buffer == null)
  4107. return;
  4108. // Count this as a resent packet since we are going to requeue all of the updates contained in it
  4109. Interlocked.Increment(ref m_udpClient.PacketsResent);
  4110. m_udpServer.PacketsResentCount++;
  4111. foreach (EntityUpdate update in updates)
  4112. ResendPrimUpdate(update);
  4113. }
  4114. static private readonly byte[] objectUpdateHeader = new byte[] {
  4115. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED,
  4116. 0, 0, 0, 0, // sequence number
  4117. 0, // extra
  4118. 12 // ID (high frequency)
  4119. };
  4120. static private readonly byte[] terseUpdateHeader = new byte[] {
  4121. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED, // zero code is not as spec
  4122. 0, 0, 0, 0, // sequence number
  4123. 0, // extra
  4124. 15 // ID (high frequency)
  4125. };
  4126. static private readonly byte[] ObjectAnimationHeader = new byte[] {
  4127. Helpers.MSG_RELIABLE,
  4128. 0, 0, 0, 0, // sequence number
  4129. 0, // extra
  4130. 30 // ID (high frequency)
  4131. };
  4132. static private readonly byte[] CompressedObjectHeader = new byte[] {
  4133. Helpers.MSG_RELIABLE,
  4134. 0, 0, 0, 0, // sequence number
  4135. 0, // extra
  4136. 13 // ID (high frequency)
  4137. };
  4138. static private readonly byte[] ObjectUpdateCachedHeader = new byte[] {
  4139. Helpers.MSG_RELIABLE,
  4140. 0, 0, 0, 0, // sequence number
  4141. 0, // extra
  4142. 14 // ID (high frequency)
  4143. };
  4144. private void ProcessEntityUpdates(int maxUpdatesBytes)
  4145. {
  4146. if (!IsActive)
  4147. return;
  4148. ScenePresence mysp = (ScenePresence)SceneAgent;
  4149. if (mysp == null)
  4150. return;
  4151. List<EntityUpdate> objectUpdates = null;
  4152. List<EntityUpdate> objectUpdateProbes = null;
  4153. List<EntityUpdate> compressedUpdates = null;
  4154. List<EntityUpdate> terseUpdates = null;
  4155. List<SceneObjectPart> ObjectAnimationUpdates = null;
  4156. // Check to see if this is a flush
  4157. if (maxUpdatesBytes <= 0)
  4158. {
  4159. maxUpdatesBytes = Int32.MaxValue;
  4160. }
  4161. EntityUpdate update;
  4162. bool viewerCache = m_supportViewerCache;// && mysp.IsChildAgent; // only on child agents
  4163. bool doCulling = m_scene.ObjectsCullingByDistance;
  4164. float cullingrange = 64.0f;
  4165. Vector3 mypos = Vector3.Zero;
  4166. //bool orderedDequeue = m_scene.UpdatePrioritizationScheme == UpdatePrioritizationSchemes.SimpleAngularDistance;
  4167. bool orderedDequeue = false; // temporary off
  4168. HashSet<SceneObjectGroup> GroupsNeedFullUpdate = new HashSet<SceneObjectGroup>();
  4169. bool useCompressUpdate = false;
  4170. if (doCulling)
  4171. {
  4172. cullingrange = mysp.DrawDistance + m_scene.ReprioritizationDistance + 16f;
  4173. mypos = mysp.AbsolutePosition;
  4174. }
  4175. while (maxUpdatesBytes > 0)
  4176. {
  4177. if (!IsActive)
  4178. return;
  4179. lock (m_entityUpdates.SyncRoot)
  4180. {
  4181. if(orderedDequeue)
  4182. {
  4183. if (!m_entityUpdates.TryOrderedDequeue(out update))
  4184. break;
  4185. }
  4186. else
  4187. {
  4188. if (!m_entityUpdates.TryDequeue(out update))
  4189. break;
  4190. }
  4191. }
  4192. PrimUpdateFlags updateFlags = update.Flags;
  4193. if ((updateFlags & PrimUpdateFlags.Kill) != 0)
  4194. {
  4195. m_killRecord.Add(update.Entity.LocalId);
  4196. maxUpdatesBytes -= 30;
  4197. update.Free();
  4198. continue;
  4199. }
  4200. useCompressUpdate = false;
  4201. bool istree = false;
  4202. if (update.Entity is SceneObjectPart)
  4203. {
  4204. SceneObjectPart part = (SceneObjectPart)update.Entity;
  4205. SceneObjectGroup grp = part.ParentGroup;
  4206. if (grp.inTransit && ((update.Flags & PrimUpdateFlags.SendInTransit) == 0))
  4207. {
  4208. update.Free();
  4209. continue;
  4210. }
  4211. if (grp.IsDeleted)
  4212. {
  4213. // Don't send updates for objects that have been marked deleted.
  4214. // Instead send another kill object, because the first one may have gotten
  4215. // into a race condition
  4216. if (part == grp.RootPart && !m_killRecord.Contains(grp.LocalId))
  4217. {
  4218. m_killRecord.Add(grp.LocalId);
  4219. maxUpdatesBytes -= 30;
  4220. }
  4221. update.Free();
  4222. continue;
  4223. }
  4224. if (grp.IsAttachment)
  4225. {
  4226. // animated attachments are nasty if not supported by viewer
  4227. if(!m_SupportObjectAnimations && grp.RootPart.Shape.MeshFlagEntry)
  4228. {
  4229. update.Free();
  4230. continue;
  4231. }
  4232. // Someone else's HUD, why are we getting these?
  4233. if (grp.OwnerID != AgentId && grp.HasPrivateAttachmentPoint)
  4234. {
  4235. update.Free();
  4236. continue;
  4237. }
  4238. // if owner gone don't update it to anyone
  4239. ScenePresence sp;
  4240. if (!m_scene.TryGetScenePresence(part.OwnerID, out sp))
  4241. {
  4242. update.Free();
  4243. continue;
  4244. }
  4245. // On vehicle crossing, the attachments are received
  4246. // while the avatar is still a child. Don't send
  4247. // updates here because the LocalId has not yet
  4248. // been updated and the viewer will derender the
  4249. // attachments until the avatar becomes root.
  4250. if (sp.IsChildAgent)
  4251. {
  4252. update.Free();
  4253. continue;
  4254. }
  4255. // It's an attachment of a valid avatar, but
  4256. // doesn't seem to be attached, skip
  4257. List<SceneObjectGroup> atts = sp.GetAttachments();
  4258. bool found = false;
  4259. for (int indx = 0; indx < atts.Count; ++indx)
  4260. {
  4261. if (atts[indx] == grp)
  4262. {
  4263. found = true;
  4264. break;
  4265. }
  4266. }
  4267. if (!found)
  4268. {
  4269. update.Free();
  4270. continue;
  4271. }
  4272. if (m_disableFacelights)
  4273. {
  4274. if (grp.RootPart.Shape.State != (byte)AttachmentPoint.LeftHand &&
  4275. grp.RootPart.Shape.State != (byte)AttachmentPoint.RightHand)
  4276. {
  4277. part.Shape.LightEntry = false;
  4278. }
  4279. }
  4280. }
  4281. else if (doCulling)
  4282. {
  4283. if(GroupsNeedFullUpdate.Contains(grp))
  4284. {
  4285. update.Free();
  4286. continue;
  4287. }
  4288. bool inViewGroups = false;
  4289. lock(GroupsInView)
  4290. inViewGroups = GroupsInView.Contains(grp);
  4291. if(!inViewGroups)
  4292. {
  4293. Vector3 partpos = grp.getCenterOffset();
  4294. float dpos = (partpos - mypos).LengthSquared();
  4295. float maxview = grp.GetBoundsRadius() + cullingrange;
  4296. if (dpos > maxview * maxview)
  4297. {
  4298. update.Free();
  4299. continue;
  4300. }
  4301. if (!viewerCache || ((updateFlags & PrimUpdateFlags.UpdateProbe) == 0))
  4302. {
  4303. GroupsNeedFullUpdate.Add(grp);
  4304. update.Free();
  4305. continue;
  4306. }
  4307. }
  4308. }
  4309. if ((updateFlags & PrimUpdateFlags.UpdateProbe) != 0)
  4310. {
  4311. if (objectUpdateProbes == null)
  4312. {
  4313. objectUpdateProbes = new List<EntityUpdate>(32);
  4314. maxUpdatesBytes -= 18;
  4315. }
  4316. objectUpdateProbes.Add(update);
  4317. maxUpdatesBytes -= 12;
  4318. continue;
  4319. }
  4320. if ((updateFlags & PrimUpdateFlags.Animations) != 0)
  4321. {
  4322. if (m_SupportObjectAnimations && part.Animations != null)
  4323. {
  4324. if (ObjectAnimationUpdates == null)
  4325. ObjectAnimationUpdates = new List<SceneObjectPart>(8);
  4326. ObjectAnimationUpdates.Add(part);
  4327. maxUpdatesBytes -= 20 * part.Animations.Count + 24;
  4328. }
  4329. }
  4330. if(viewerCache)
  4331. useCompressUpdate = grp.IsViewerCachable;
  4332. istree = (part.Shape.PCode == (byte)PCode.Grass || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Tree);
  4333. }
  4334. else if (update.Entity is ScenePresence)
  4335. {
  4336. ScenePresence presence = (ScenePresence)update.Entity;
  4337. if (presence.IsDeleted)
  4338. {
  4339. update.Free();
  4340. continue;
  4341. }
  4342. // If ParentUUID is not UUID.Zero and ParentID is 0, this
  4343. // avatar is in the process of crossing regions while
  4344. // sat on an object. In this state, we don't want any
  4345. // updates because they will visually orbit the avatar.
  4346. // Update will be forced once crossing is completed anyway.
  4347. if (presence.ParentUUID != UUID.Zero && presence.ParentID == 0)
  4348. {
  4349. update.Free();
  4350. continue;
  4351. }
  4352. }
  4353. else // what is this update ?
  4354. {
  4355. update.Free();
  4356. continue;
  4357. }
  4358. #region UpdateFlags to packet type conversion
  4359. updateFlags &= PrimUpdateFlags.FullUpdate; // clear other control bits already handled
  4360. if(updateFlags == PrimUpdateFlags.None)
  4361. {
  4362. update.Free();
  4363. continue;
  4364. }
  4365. const PrimUpdateFlags canNotUseImprovedMask = ~(
  4366. PrimUpdateFlags.AttachmentPoint |
  4367. PrimUpdateFlags.Position |
  4368. PrimUpdateFlags.Rotation |
  4369. PrimUpdateFlags.Velocity |
  4370. PrimUpdateFlags.Acceleration |
  4371. PrimUpdateFlags.AngularVelocity |
  4372. PrimUpdateFlags.CollisionPlane |
  4373. PrimUpdateFlags.Textures
  4374. );
  4375. #endregion UpdateFlags to packet type conversion
  4376. #region Block Construction
  4377. if ((updateFlags & canNotUseImprovedMask) == 0)
  4378. {
  4379. if (terseUpdates == null)
  4380. {
  4381. terseUpdates = new List<EntityUpdate>(16);
  4382. maxUpdatesBytes -= 18;
  4383. }
  4384. terseUpdates.Add(update);
  4385. if (update.Entity is ScenePresence)
  4386. maxUpdatesBytes -= 63; // no texture entry
  4387. else
  4388. {
  4389. if ((updateFlags & PrimUpdateFlags.Textures) == 0)
  4390. maxUpdatesBytes -= 47;
  4391. else
  4392. maxUpdatesBytes -= 150; // aprox
  4393. }
  4394. }
  4395. else
  4396. {
  4397. if (update.Entity is ScenePresence)
  4398. {
  4399. maxUpdatesBytes -= 150; // crude estimation
  4400. if (objectUpdates == null)
  4401. {
  4402. objectUpdates = new List<EntityUpdate>(16);
  4403. maxUpdatesBytes -= 18;
  4404. }
  4405. objectUpdates.Add(update);
  4406. }
  4407. else
  4408. {
  4409. if (useCompressUpdate)
  4410. {
  4411. if (istree)
  4412. maxUpdatesBytes -= 64;
  4413. else
  4414. maxUpdatesBytes -= 120; // crude estimation
  4415. if (compressedUpdates == null)
  4416. {
  4417. compressedUpdates = new List<EntityUpdate>(16);
  4418. maxUpdatesBytes -= 18;
  4419. }
  4420. compressedUpdates.Add(update);
  4421. }
  4422. else
  4423. {
  4424. if (istree)
  4425. maxUpdatesBytes -= 70;
  4426. else
  4427. maxUpdatesBytes -= 150; // crude estimation
  4428. if (objectUpdates == null)
  4429. {
  4430. objectUpdates = new List<EntityUpdate>(16);
  4431. maxUpdatesBytes -= 18;
  4432. }
  4433. objectUpdates.Add(update);
  4434. }
  4435. }
  4436. }
  4437. #endregion Block Construction
  4438. }
  4439. #region Packet Sending
  4440. ushort timeDilation;
  4441. if (!IsActive)
  4442. return;
  4443. timeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);
  4444. if(objectUpdates != null)
  4445. {
  4446. //List<EntityUpdate> tau = new List<EntityUpdate>(30);
  4447. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4448. Buffer.BlockCopy(objectUpdateHeader, 0, buf.Data, 0, 7);
  4449. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  4450. zc.Position = 7;
  4451. zc.AddUInt64(m_scene.RegionInfo.RegionHandle);
  4452. zc.AddUInt16(timeDilation);
  4453. zc.AddByte(1); // tmp block count
  4454. int countposition = zc.Position - 1;
  4455. int lastpos = 0;
  4456. int lastzc = 0;
  4457. int count = 0;
  4458. bool shouldCreateSelected = false; //mantis 8639
  4459. EntityUpdate eu;
  4460. for(int indx = 0; indx < objectUpdates.Count; ++indx)
  4461. {
  4462. eu = objectUpdates[indx];
  4463. lastpos = zc.Position;
  4464. lastzc = zc.ZeroCount;
  4465. if (eu.Entity is ScenePresence)
  4466. CreateAvatarUpdateBlock((ScenePresence)eu.Entity, zc);
  4467. else
  4468. {
  4469. SceneObjectPart part = (SceneObjectPart)eu.Entity;
  4470. shouldCreateSelected = part.CreateSelected;
  4471. CreatePrimUpdateBlock(part, mysp, zc);
  4472. }
  4473. if (zc.Position < LLUDPServer.MAXPAYLOAD - 300)
  4474. {
  4475. //tau.Add(eu);
  4476. ++count;
  4477. }
  4478. else
  4479. {
  4480. // we need more packets
  4481. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4482. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, countposition); // start is the same
  4483. buf.Data[countposition] = (byte)count;
  4484. // get pending zeros at cut point
  4485. if(lastzc > 0)
  4486. {
  4487. buf.Data[lastpos++] = 0;
  4488. buf.Data[lastpos++] = (byte)lastzc;
  4489. }
  4490. buf.DataLength = lastpos;
  4491. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4492. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4493. null, false);
  4494. buf = newbuf;
  4495. zc.Data = buf.Data;
  4496. zc.ZeroCount = 0;
  4497. zc.Position = countposition + 1;
  4498. // im lazy now, just do last again
  4499. if (eu.Entity is ScenePresence)
  4500. CreateAvatarUpdateBlock((ScenePresence)eu.Entity, zc);
  4501. else
  4502. {
  4503. if(shouldCreateSelected) //mantis 8639 recover selected state
  4504. ((SceneObjectPart)eu.Entity).CreateSelected = true;
  4505. CreatePrimUpdateBlock((SceneObjectPart)eu.Entity, mysp, zc);
  4506. }
  4507. //tau = new List<EntityUpdate>(30);
  4508. //tau.Add(eu);
  4509. count = 1;
  4510. }
  4511. eu.Free(); //remove if using resend
  4512. }
  4513. if (count > 0)
  4514. {
  4515. buf.Data[countposition] = (byte)count;
  4516. buf.DataLength = zc.Finish();
  4517. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4518. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4519. null, false);
  4520. }
  4521. }
  4522. /* no zero encode compressed updates
  4523. if(compressedUpdates != null)
  4524. {
  4525. List<EntityUpdate> tau = new List<EntityUpdate>(30);
  4526. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4527. byte[] data = buf.Data;
  4528. Buffer.BlockCopy(CompressedObjectHeader, 0, data , 0, 7);
  4529. Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, data, 7); // 15
  4530. Utils.UInt16ToBytes(timeDilation, data, 15); // 17
  4531. int countposition = 17; // blocks count position
  4532. int pos = 18;
  4533. int lastpos = 0;
  4534. int count = 0;
  4535. foreach (EntityUpdate eu in compressedUpdates)
  4536. {
  4537. SceneObjectPart sop = (SceneObjectPart)eu.Entity;
  4538. if (sop.ParentGroup == null || sop.ParentGroup.IsDeleted)
  4539. continue;
  4540. lastpos = pos;
  4541. CreateCompressedUpdateBlock(sop, mysp, data, ref pos);
  4542. if (pos < LLUDPServer.MAXPAYLOAD)
  4543. {
  4544. tau.Add(eu);
  4545. ++count;
  4546. }
  4547. else
  4548. {
  4549. // we need more packets
  4550. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4551. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, countposition); // start is the same
  4552. buf.Data[countposition] = (byte)count;
  4553. buf.DataLength = lastpos;
  4554. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4555. delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4556. buf = newbuf;
  4557. data = buf.Data;
  4558. pos = 18;
  4559. // im lazy now, just do last again
  4560. CreateCompressedUpdateBlock(sop, mysp, data, ref pos);
  4561. tau = new List<EntityUpdate>(30);
  4562. tau.Add(eu);
  4563. count = 1;
  4564. }
  4565. }
  4566. if (count > 0)
  4567. {
  4568. buf.Data[countposition] = (byte)count;
  4569. buf.DataLength = pos;
  4570. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4571. delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4572. }
  4573. }
  4574. */
  4575. if (compressedUpdates != null)
  4576. {
  4577. //List<EntityUpdate> tau = new List<EntityUpdate>(30);
  4578. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4579. byte[] data = buf.Data;
  4580. Buffer.BlockCopy(CompressedObjectHeader, 0, data, 0, 7);
  4581. data[0] |= Helpers.MSG_ZEROCODED;
  4582. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  4583. zc.Position = 7;
  4584. zc.AddUInt64(m_scene.RegionInfo.RegionHandle);
  4585. zc.AddUInt16(timeDilation);
  4586. zc.AddByte(1); // tmp block count
  4587. int countposition = zc.Position - 1;
  4588. int lastpos = 0;
  4589. int lastzc = 0;
  4590. int count = 0;
  4591. bool shouldCreateSelected = false; //mantis 8639
  4592. EntityUpdate eu;
  4593. for (int indx = 0; indx < compressedUpdates.Count; ++indx)
  4594. {
  4595. eu = compressedUpdates[indx];
  4596. SceneObjectPart sop = (SceneObjectPart)eu.Entity;
  4597. if (sop.ParentGroup == null || sop.ParentGroup.IsDeleted)
  4598. continue;
  4599. shouldCreateSelected = sop.CreateSelected;
  4600. lastpos = zc.Position;
  4601. lastzc = zc.ZeroCount;
  4602. CreateCompressedUpdateBlockZC(sop, mysp, zc);
  4603. if (zc.Position < LLUDPServer.MAXPAYLOAD - 200)
  4604. {
  4605. //tau.Add(eu);
  4606. ++count;
  4607. }
  4608. else
  4609. {
  4610. // we need more packets
  4611. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4612. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, countposition); // start is the same
  4613. buf.Data[countposition] = (byte)count;
  4614. // get pending zeros at cut point
  4615. if (lastzc > 0)
  4616. {
  4617. buf.Data[lastpos++] = 0;
  4618. buf.Data[lastpos++] = (byte)lastzc;
  4619. }
  4620. buf.DataLength = lastpos;
  4621. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4622. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4623. null, false);
  4624. buf = newbuf;
  4625. zc.Data = buf.Data;
  4626. data[0] |= Helpers.MSG_ZEROCODED;
  4627. zc.ZeroCount = 0;
  4628. zc.Position = countposition + 1;
  4629. if (shouldCreateSelected) //mantis 8639 recover selected state
  4630. sop.CreateSelected = true;
  4631. // im lazy now, just do last again
  4632. CreateCompressedUpdateBlockZC(sop, mysp, zc);
  4633. //tau = new List<EntityUpdate>(30);
  4634. //tau.Add(eu);
  4635. count = 1;
  4636. }
  4637. eu.Free(); //remove if using resend
  4638. }
  4639. if (count > 0)
  4640. {
  4641. buf.Data[countposition] = (byte)count;
  4642. buf.DataLength = zc.Finish();
  4643. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4644. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4645. null, false);
  4646. }
  4647. }
  4648. if (objectUpdateProbes != null)
  4649. {
  4650. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4651. byte[] data = buf.Data;
  4652. Buffer.BlockCopy(ObjectUpdateCachedHeader, 0, data, 0, 7);
  4653. Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, data, 7); // 15
  4654. Utils.UInt16ToBytes(timeDilation, data, 15); // 17
  4655. int countposition = 17; // blocks count position
  4656. int pos = 18;
  4657. int count = 0;
  4658. EntityUpdate eu;
  4659. for (int indx = 0; indx < objectUpdateProbes.Count; ++indx)
  4660. {
  4661. eu = objectUpdateProbes[indx];
  4662. SceneObjectPart sop = (SceneObjectPart)eu.Entity;
  4663. if (sop.ParentGroup == null || sop.ParentGroup.IsDeleted)
  4664. continue;
  4665. uint primflags = m_scene.Permissions.GenerateClientFlags(sop, mysp);
  4666. if (mysp.UUID != sop.OwnerID)
  4667. primflags &= ~(uint)PrimFlags.CreateSelected;
  4668. else
  4669. {
  4670. if (sop.CreateSelected)
  4671. primflags |= (uint)PrimFlags.CreateSelected;
  4672. else
  4673. primflags &= ~(uint)PrimFlags.CreateSelected;
  4674. }
  4675. Utils.UIntToBytes(sop.LocalId, data, pos); pos += 4;
  4676. Utils.UIntToBytes((uint)sop.PseudoCRC, data, pos); pos += 4; //WRONG
  4677. Utils.UIntToBytes(primflags, data, pos); pos += 4;
  4678. ++count;
  4679. if (pos > (LLUDPServer.MAXPAYLOAD - 13))
  4680. {
  4681. // we need more packets
  4682. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4683. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, countposition); // start is the same
  4684. buf.Data[countposition] = (byte)count;
  4685. buf.DataLength = pos;
  4686. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false);
  4687. buf = newbuf;
  4688. data = buf.Data;
  4689. pos = 18;
  4690. count = 0;
  4691. }
  4692. eu.Free();
  4693. }
  4694. if (count > 0)
  4695. {
  4696. buf.Data[countposition] = (byte)count;
  4697. buf.DataLength = pos;
  4698. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false);
  4699. }
  4700. }
  4701. if (terseUpdates != null)
  4702. {
  4703. int blocks = terseUpdates.Count;
  4704. //List<EntityUpdate> tau = new List<EntityUpdate>(30);
  4705. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4706. //setup header and regioninfo block
  4707. Buffer.BlockCopy(terseUpdateHeader, 0, buf.Data, 0, 7);
  4708. Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, buf.Data, 7);
  4709. Utils.UInt16ToBytes(timeDilation, buf.Data, 15);
  4710. int pos = 18;
  4711. int lastpos = 0;
  4712. int count = 0;
  4713. EntityUpdate eu;
  4714. for (int indx = 0; indx < terseUpdates.Count; ++indx)
  4715. {
  4716. eu = terseUpdates[indx];
  4717. lastpos = pos;
  4718. CreateImprovedTerseBlock(eu.Entity, buf.Data, ref pos, (eu.Flags & PrimUpdateFlags.Textures) != 0);
  4719. if (pos < LLUDPServer.MAXPAYLOAD)
  4720. {
  4721. //tau.Add(eu);
  4722. ++count;
  4723. --blocks;
  4724. }
  4725. else if (blocks > 0)
  4726. {
  4727. // we need more packets
  4728. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4729. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, 17); // start is the same
  4730. // copy what we done in excess
  4731. int extralen = pos - lastpos;
  4732. if(extralen > 0)
  4733. Buffer.BlockCopy(buf.Data, lastpos, newbuf.Data, 18, extralen);
  4734. pos = 18 + extralen;
  4735. buf.Data[17] = (byte)count;
  4736. buf.DataLength = lastpos;
  4737. // zero encode is not as spec
  4738. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4739. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, true);
  4740. null, true);
  4741. //tau = new List<EntityUpdate>(30);
  4742. //tau.Add(eu);
  4743. count = 1;
  4744. --blocks;
  4745. buf = newbuf;
  4746. }
  4747. eu.Free(); //remove if using resend
  4748. }
  4749. if (count > 0)
  4750. {
  4751. buf.Data[17] = (byte)count;
  4752. buf.DataLength = pos;
  4753. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4754. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, true);
  4755. null, true);
  4756. }
  4757. }
  4758. if (ObjectAnimationUpdates != null)
  4759. {
  4760. SceneObjectPart sop;
  4761. for (int indx = 0; indx < ObjectAnimationUpdates.Count; ++indx)
  4762. {
  4763. sop = ObjectAnimationUpdates[indx];
  4764. if (sop.Animations == null)
  4765. continue;
  4766. SceneObjectGroup sog = sop.ParentGroup;
  4767. if (sog == null || sog.IsDeleted)
  4768. continue;
  4769. SceneObjectPart root = sog.RootPart;
  4770. if (root == null || root.Shape == null || !root.Shape.MeshFlagEntry)
  4771. continue;
  4772. UUID[] ids = null;
  4773. int[] seqs = null;
  4774. int count = sop.GetAnimations(out ids, out seqs);
  4775. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4776. byte[] data = buf.Data;
  4777. //setup header
  4778. Buffer.BlockCopy(ObjectAnimationHeader, 0, data , 0, 7);
  4779. // sender block
  4780. sop.UUID.ToBytes(data, 7); // 23
  4781. //animations block
  4782. if (count > 255)
  4783. count = 255;
  4784. data[23] = (byte)count;
  4785. int pos = 24;
  4786. for(int i = 0; i < count; i++)
  4787. {
  4788. ids[i].ToBytes(data, pos); pos += 16;
  4789. Utils.IntToBytesSafepos(seqs[i], data, pos); pos += 4;
  4790. }
  4791. buf.DataLength = pos;
  4792. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  4793. }
  4794. }
  4795. #endregion Packet Sending
  4796. #region Handle deleted objects
  4797. if (m_killRecord.Count > 0)
  4798. {
  4799. SendKillObject(m_killRecord);
  4800. m_killRecord.Clear();
  4801. }
  4802. if(GroupsNeedFullUpdate.Count > 0)
  4803. {
  4804. foreach(SceneObjectGroup grp in GroupsNeedFullUpdate)
  4805. {
  4806. lock (GroupsInView)
  4807. GroupsInView.Add(grp);
  4808. PrimUpdateFlags flags = PrimUpdateFlags.CancelKill;
  4809. if(viewerCache && grp.IsViewerCachable)
  4810. flags |= PrimUpdateFlags.UpdateProbe;
  4811. foreach (SceneObjectPart p in grp.Parts)
  4812. SendEntityUpdate(p, flags);
  4813. }
  4814. }
  4815. #endregion
  4816. }
  4817. // hack.. dont use
  4818. /*
  4819. public void SendPartFullUpdate(ISceneEntity ent, uint? parentID)
  4820. {
  4821. if (ent is SceneObjectPart)
  4822. {
  4823. SceneObjectPart part = (SceneObjectPart)ent;
  4824. ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
  4825. packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
  4826. packet.RegionData.TimeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);
  4827. packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
  4828. ObjectUpdatePacket.ObjectDataBlock blk = CreatePrimUpdateBlock(part, mysp);
  4829. if (parentID.HasValue)
  4830. {
  4831. blk.ParentID = parentID.Value;
  4832. }
  4833. packet.ObjectData[0] = blk;
  4834. OutPacket(packet, ThrottleOutPacketType.Task, true);
  4835. }
  4836. // m_log.DebugFormat(
  4837. // "[LLCLIENTVIEW]: Sent {0} updates in ProcessEntityUpdates() for {1} {2} in {3}",
  4838. // updatesThisCall, Name, SceneAgent.IsChildAgent ? "child" : "root", Scene.Name);
  4839. //
  4840. }
  4841. */
  4842. public void ReprioritizeUpdates()
  4843. {
  4844. lock (m_entityUpdates.SyncRoot)
  4845. m_entityUpdates.Reprioritize(UpdatePriorityHandler);
  4846. CheckGroupsInView();
  4847. }
  4848. private bool CheckGroupsInViewBusy = false;
  4849. public void CheckGroupsInView()
  4850. {
  4851. bool doCulling = m_scene.ObjectsCullingByDistance;
  4852. if(!doCulling)
  4853. return;
  4854. if (!IsActive)
  4855. return;
  4856. if (CheckGroupsInViewBusy)
  4857. return;
  4858. ScenePresence mysp = (ScenePresence)SceneAgent;
  4859. if (mysp == null || mysp.IsDeleted)
  4860. return;
  4861. CheckGroupsInViewBusy = true;
  4862. float cullingrange = mysp.DrawDistance + m_scene.ReprioritizationDistance + 16f;
  4863. Vector3 mypos = mysp.AbsolutePosition;
  4864. HashSet<SceneObjectGroup> NewGroupsInView = new HashSet<SceneObjectGroup>();
  4865. HashSet<SceneObjectGroup> GroupsNeedFullUpdate = new HashSet<SceneObjectGroup>();
  4866. List<SceneObjectGroup> kills = new List<SceneObjectGroup>();
  4867. EntityBase[] entities = m_scene.Entities.GetEntities();
  4868. foreach (EntityBase e in entities)
  4869. {
  4870. if (!IsActive)
  4871. return;
  4872. if (e != null && e is SceneObjectGroup)
  4873. {
  4874. SceneObjectGroup grp = (SceneObjectGroup)e;
  4875. if(grp.IsDeleted || grp.IsAttachment )
  4876. continue;
  4877. bool inviewgroups;
  4878. lock (GroupsInView)
  4879. inviewgroups = GroupsInView.Contains(grp);
  4880. //temp handling of sits
  4881. if(grp.GetSittingAvatarsCount() > 0)
  4882. {
  4883. if (!inviewgroups)
  4884. GroupsNeedFullUpdate.Add(grp);
  4885. NewGroupsInView.Add(grp);
  4886. }
  4887. else
  4888. {
  4889. Vector3 grppos = grp.getCenterOffset();
  4890. float dpos = (grppos - mypos).LengthSquared();
  4891. float maxview = grp.GetBoundsRadius() + cullingrange;
  4892. if (dpos > maxview * maxview)
  4893. {
  4894. if(inviewgroups)
  4895. kills.Add(grp);
  4896. }
  4897. else
  4898. {
  4899. if (!inviewgroups)
  4900. GroupsNeedFullUpdate.Add(grp);
  4901. NewGroupsInView.Add(grp);
  4902. }
  4903. }
  4904. }
  4905. }
  4906. lock(GroupsInView)
  4907. GroupsInView = NewGroupsInView;
  4908. if (kills.Count > 0)
  4909. {
  4910. List<uint> partIDs = new List<uint>();
  4911. foreach(SceneObjectGroup grp in kills)
  4912. {
  4913. SendEntityUpdate(grp.RootPart, PrimUpdateFlags.Kill);
  4914. foreach(SceneObjectPart p in grp.Parts)
  4915. {
  4916. if(p != grp.RootPart)
  4917. partIDs.Add(p.LocalId);
  4918. }
  4919. }
  4920. kills.Clear();
  4921. if(partIDs.Count > 0)
  4922. {
  4923. lock (m_entityProps.SyncRoot)
  4924. m_entityProps.Remove(partIDs);
  4925. lock (m_entityUpdates.SyncRoot)
  4926. m_entityUpdates.Remove(partIDs);
  4927. }
  4928. }
  4929. if(GroupsNeedFullUpdate.Count > 0)
  4930. {
  4931. bool sendProbes = m_supportViewerCache && (m_viewerHandShakeFlags & 2) == 0;
  4932. if(sendProbes)
  4933. {
  4934. foreach (SceneObjectGroup grp in GroupsNeedFullUpdate)
  4935. {
  4936. PrimUpdateFlags flags = PrimUpdateFlags.CancelKill;
  4937. if (grp.IsViewerCachable)
  4938. flags |= PrimUpdateFlags.UpdateProbe;
  4939. foreach (SceneObjectPart p in grp.Parts)
  4940. SendEntityUpdate(p, flags);
  4941. }
  4942. }
  4943. else
  4944. {
  4945. m_viewerHandShakeFlags &= ~2U; // nexttime send probes
  4946. PrimUpdateFlags flags = PrimUpdateFlags.CancelKill;
  4947. foreach (SceneObjectGroup grp in GroupsNeedFullUpdate)
  4948. {
  4949. foreach (SceneObjectPart p in grp.Parts)
  4950. SendEntityUpdate(p, flags);
  4951. }
  4952. }
  4953. }
  4954. CheckGroupsInViewBusy = false;
  4955. }
  4956. private bool UpdatePriorityHandler(ref int priority, ISceneEntity entity)
  4957. {
  4958. if (!IsActive)
  4959. return false;
  4960. priority = m_prioritizer.GetUpdatePriority(this, entity);
  4961. return true;
  4962. }
  4963. public void FlushPrimUpdates()
  4964. {
  4965. m_log.WarnFormat("[CLIENT]: Flushing prim updates to " + m_firstName + " " + m_lastName);
  4966. while (m_entityUpdates.Count > 0)
  4967. ProcessEntityUpdates(-1);
  4968. }
  4969. #endregion Primitive Packet/Data Sending Methods
  4970. // These are used to implement an adaptive backoff in the number
  4971. // of updates converted to packets. Since we don't want packets
  4972. // to sit in the queue with old data, only convert enough updates
  4973. // to packets that can be sent in 30ms.
  4974. void HandleQueueEmpty(ThrottleOutPacketTypeFlags categories)
  4975. {
  4976. if(m_scene == null)
  4977. return;
  4978. if ((categories & ThrottleOutPacketTypeFlags.Task) != 0)
  4979. {
  4980. int maxUpdateBytes = m_udpClient.GetCatBytesCanSend(ThrottleOutPacketType.Task, 30);
  4981. if (m_entityUpdates.Count > 0)
  4982. ProcessEntityUpdates(maxUpdateBytes);
  4983. if (m_entityProps.Count > 0)
  4984. ProcessEntityPropertyRequests(maxUpdateBytes);
  4985. }
  4986. if ((categories & ThrottleOutPacketTypeFlags.Texture) != 0)
  4987. ImageManager.ProcessImageQueue(m_udpServer.TextureSendLimit);
  4988. }
  4989. internal bool HandleHasUpdates(ThrottleOutPacketTypeFlags categories)
  4990. {
  4991. if ((categories & ThrottleOutPacketTypeFlags.Task) != 0)
  4992. {
  4993. if (m_entityUpdates.Count > 0)
  4994. return true;
  4995. if (m_entityProps.Count > 0)
  4996. return true;
  4997. }
  4998. if ((categories & ThrottleOutPacketTypeFlags.Texture) != 0)
  4999. {
  5000. if (ImageManager.HasUpdates())
  5001. return true;
  5002. }
  5003. return false;
  5004. }
  5005. public void SendAssetUploadCompleteMessage(sbyte AssetType, bool Success, UUID AssetFullID)
  5006. {
  5007. AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
  5008. newPack.AssetBlock.Type = AssetType;
  5009. newPack.AssetBlock.Success = Success;
  5010. newPack.AssetBlock.UUID = AssetFullID;
  5011. newPack.Header.Zerocoded = true;
  5012. OutPacket(newPack, ThrottleOutPacketType.Asset);
  5013. }
  5014. public void SendXferRequest(ulong XferID, short AssetType, UUID vFileID, byte FilePath, byte[] FileName)
  5015. {
  5016. RequestXferPacket newPack = new RequestXferPacket();
  5017. newPack.XferID.ID = XferID;
  5018. newPack.XferID.VFileType = AssetType;
  5019. newPack.XferID.VFileID = vFileID;
  5020. newPack.XferID.FilePath = FilePath;
  5021. newPack.XferID.Filename = FileName;
  5022. newPack.Header.Zerocoded = true;
  5023. OutPacket(newPack, ThrottleOutPacketType.Asset);
  5024. }
  5025. public void SendConfirmXfer(ulong xferID, uint PacketID)
  5026. {
  5027. ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket();
  5028. newPack.XferID.ID = xferID;
  5029. newPack.XferID.Packet = PacketID;
  5030. newPack.Header.Zerocoded = true;
  5031. OutPacket(newPack, ThrottleOutPacketType.Asset);
  5032. }
  5033. public void SendInitiateDownload(string simFileName, string clientFileName)
  5034. {
  5035. InitiateDownloadPacket newPack = new InitiateDownloadPacket();
  5036. newPack.AgentData.AgentID = AgentId;
  5037. newPack.FileData.SimFilename = Utils.StringToBytes(simFileName);
  5038. newPack.FileData.ViewerFilename = Utils.StringToBytes(clientFileName);
  5039. OutPacket(newPack, ThrottleOutPacketType.Asset);
  5040. }
  5041. public void SendImageFirstPart(
  5042. ushort numParts, UUID ImageUUID, uint ImageSize, byte[] ImageData, byte imageCodec)
  5043. {
  5044. ImageDataPacket im = new ImageDataPacket();
  5045. im.ImageID.Packets = numParts;
  5046. im.ImageID.ID = ImageUUID;
  5047. if (ImageSize > 0)
  5048. im.ImageID.Size = ImageSize;
  5049. im.ImageData.Data = ImageData;
  5050. im.ImageID.Codec = imageCodec;
  5051. im.Header.Zerocoded = true;
  5052. OutPacket(im, ThrottleOutPacketType.Texture);
  5053. }
  5054. public void SendImageNextPart(ushort partNumber, UUID imageUuid, byte[] imageData)
  5055. {
  5056. ImagePacketPacket im = new ImagePacketPacket();
  5057. im.ImageID.Packet = partNumber;
  5058. im.ImageID.ID = imageUuid;
  5059. im.ImageData.Data = imageData;
  5060. OutPacket(im, ThrottleOutPacketType.Texture);
  5061. }
  5062. public void SendImageNotFound(UUID imageid)
  5063. {
  5064. ImageNotInDatabasePacket notFoundPacket
  5065. = (ImageNotInDatabasePacket)PacketPool.Instance.GetPacket(PacketType.ImageNotInDatabase);
  5066. notFoundPacket.ImageID.ID = imageid;
  5067. OutPacket(notFoundPacket, ThrottleOutPacketType.Texture);
  5068. }
  5069. public void SendShutdownConnectionNotice()
  5070. {
  5071. OutPacket(PacketPool.Instance.GetPacket(PacketType.DisableSimulator), ThrottleOutPacketType.Unknown);
  5072. }
  5073. static private readonly byte[] SimStatsHeader = new byte[] {
  5074. 0,
  5075. 0, 0, 0, 0, // sequence number
  5076. 0, // extra
  5077. 0xff, 0xff, 0, 140 // ID 140 (low frequency bigendian)
  5078. };
  5079. public void SendSimStats(SimStats stats)
  5080. {
  5081. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  5082. byte[] data = buf.Data;
  5083. //setup header
  5084. Buffer.BlockCopy(SimStatsHeader, 0, data, 0, 10);
  5085. // Region Block
  5086. Utils.UIntToBytesSafepos(stats.RegionX, data, 10);
  5087. Utils.UIntToBytesSafepos(stats.RegionY, data, 14);
  5088. Utils.UIntToBytesSafepos(stats.RegionFlags, data, 18);
  5089. Utils.UIntToBytesSafepos(stats.ObjectCapacity, data, 22); // 26
  5090. // stats
  5091. data[26] = (byte)stats.StatsBlock.Length;
  5092. int pos = 27;
  5093. stats.StatsBlock[15].StatValue /= 1024; // unack is in KB
  5094. for (int i = 0; i< stats.StatsBlock.Length; ++i)
  5095. {
  5096. Utils.UIntToBytesSafepos(stats.StatsBlock[i].StatID, data, pos); pos += 4;
  5097. Utils.FloatToBytesSafepos(stats.StatsBlock[i].StatValue, data, pos); pos += 4;
  5098. }
  5099. //no PID
  5100. Utils.IntToBytesSafepos(0, data, pos); pos += 4;
  5101. // no regioninfo (extended flags)
  5102. data[pos++] = 0; // = 1;
  5103. //Utils.UInt64ToBytesSafepos(RegionFlagsExtended, data, pos); pos += 8;
  5104. buf.DataLength = pos;
  5105. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  5106. }
  5107. public void SendObjectPropertiesFamilyData(ISceneEntity entity, uint requestFlags)
  5108. {
  5109. lock (m_entityProps.SyncRoot)
  5110. m_entityProps.Enqueue(0, EntityUpdatesPool.Get(entity, (PrimUpdateFlags)requestFlags, true, false));
  5111. }
  5112. private void ResendPropertyUpdate(EntityUpdate update)
  5113. {
  5114. lock (m_entityProps.SyncRoot)
  5115. m_entityProps.Enqueue(0, update);
  5116. }
  5117. private void ResendPropertyUpdates(List<EntityUpdate> updates, OutgoingPacket oPacket)
  5118. {
  5119. // m_log.WarnFormat("[CLIENT] resending object property {0}",updates[0].UpdateTime);
  5120. // Remove the update packet from the list of packets waiting for acknowledgement
  5121. // because we are requeuing the list of updates. They will be resent in new packets
  5122. // with the most recent state.
  5123. m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber);
  5124. // Count this as a resent packet since we are going to requeue all of the updates contained in it
  5125. Interlocked.Increment(ref m_udpClient.PacketsResent);
  5126. // We're not going to worry about interlock yet since its not currently critical that this total count
  5127. // is 100% correct
  5128. m_udpServer.PacketsResentCount++;
  5129. foreach (EntityUpdate update in updates)
  5130. ResendPropertyUpdate(update);
  5131. }
  5132. public void SendObjectPropertiesReply(ISceneEntity entity)
  5133. {
  5134. lock (m_entityProps.SyncRoot)
  5135. m_entityProps.Enqueue(0, EntityUpdatesPool.Get(entity,0,false,true));
  5136. }
  5137. static private readonly byte[] ObjectPropertyUpdateHeader = new byte[] {
  5138. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED,
  5139. 0, 0, 0, 0, // sequence number
  5140. 0, // extra
  5141. 0xff, 9 // ID (medium frequency)
  5142. };
  5143. static private readonly byte[] ObjectFamilyUpdateHeader = new byte[] {
  5144. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED,
  5145. 0, 0, 0, 0, // sequence number
  5146. 0, // extra
  5147. 0xff, 10 // ID (medium frequency)
  5148. };
  5149. private void ProcessEntityPropertyRequests(int maxUpdateBytes)
  5150. {
  5151. List<EntityUpdate> objectPropertiesUpdates = null;
  5152. List<EntityUpdate> objectPropertiesFamilyUpdates = null;
  5153. List<EntityUpdate> used = new List<EntityUpdate>(64);
  5154. List<SceneObjectPart> needPhysics = null;
  5155. // bool orderedDequeue = m_scene.UpdatePrioritizationScheme == UpdatePrioritizationSchemes.SimpleAngularDistance;
  5156. bool orderedDequeue = false; // for now
  5157. EntityUpdate update;
  5158. while (maxUpdateBytes > 0)
  5159. {
  5160. lock (m_entityProps.SyncRoot)
  5161. {
  5162. if(orderedDequeue)
  5163. {
  5164. if (!m_entityProps.TryOrderedDequeue(out update))
  5165. break;
  5166. }
  5167. else
  5168. {
  5169. if (!m_entityProps.TryDequeue(out update))
  5170. break;
  5171. }
  5172. }
  5173. if (update.PropsFlags == 0)
  5174. {
  5175. update.Free();
  5176. continue;
  5177. }
  5178. SceneObjectPart sop = (SceneObjectPart)update.Entity as SceneObjectPart;
  5179. if(sop == null)
  5180. {
  5181. update.Free();
  5182. continue;
  5183. }
  5184. used.Add(update);
  5185. if ((update.PropsFlags & ObjectPropertyUpdateFlags.Family) != 0)
  5186. {
  5187. if(objectPropertiesFamilyUpdates == null)
  5188. objectPropertiesFamilyUpdates = new List<EntityUpdate>();
  5189. objectPropertiesFamilyUpdates.Add(update);
  5190. maxUpdateBytes -= 100;
  5191. }
  5192. if ((update.PropsFlags & ObjectPropertyUpdateFlags.Object) != 0)
  5193. {
  5194. if(needPhysics == null)
  5195. needPhysics = new List<SceneObjectPart>();
  5196. needPhysics.Add(sop);
  5197. if(objectPropertiesUpdates == null)
  5198. objectPropertiesUpdates = new List<EntityUpdate>();
  5199. objectPropertiesUpdates.Add(update);
  5200. maxUpdateBytes -= 200; // aprox
  5201. }
  5202. }
  5203. if (objectPropertiesUpdates != null)
  5204. {
  5205. int blocks = objectPropertiesUpdates.Count;
  5206. //List<EntityUpdate> tau = new List<EntityUpdate>(30);
  5207. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  5208. Buffer.BlockCopy(ObjectPropertyUpdateHeader, 0, buf.Data, 0, 8);
  5209. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  5210. zc.Position = 8;
  5211. zc.AddByte(1); // tmp block count
  5212. int countposition = zc.Position - 1;
  5213. int lastpos = 0;
  5214. int lastzc = 0;
  5215. int count = 0;
  5216. foreach (EntityUpdate eu in objectPropertiesUpdates)
  5217. {
  5218. lastpos = zc.Position;
  5219. lastzc = zc.ZeroCount;
  5220. CreateObjectPropertiesBlock((SceneObjectPart)eu.Entity, zc);
  5221. if (zc.Position < LLUDPServer.MAXPAYLOAD)
  5222. {
  5223. //tau.Add(eu);
  5224. ++count;
  5225. --blocks;
  5226. }
  5227. else if (blocks > 0)
  5228. {
  5229. // we need more packets
  5230. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  5231. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, countposition); // start is the same
  5232. buf.Data[countposition] = (byte)count;
  5233. // get pending zeros at cut point
  5234. if (lastzc > 0)
  5235. {
  5236. buf.Data[lastpos++] = 0;
  5237. buf.Data[lastpos++] = (byte)lastzc;
  5238. }
  5239. buf.DataLength = lastpos;
  5240. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  5241. // delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  5242. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  5243. buf = newbuf;
  5244. zc.Data = buf.Data;
  5245. zc.ZeroCount = 0;
  5246. zc.Position = countposition + 1;
  5247. // im lazy now, just do last again
  5248. CreateObjectPropertiesBlock((SceneObjectPart)eu.Entity, zc);
  5249. //tau = new List<EntityUpdate>(30);
  5250. //tau.Add(eu);
  5251. count = 1;
  5252. --blocks;
  5253. }
  5254. }
  5255. if (count > 0)
  5256. {
  5257. buf.Data[countposition] = (byte)count;
  5258. buf.DataLength = zc.Finish();
  5259. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  5260. // delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  5261. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  5262. }
  5263. }
  5264. if (objectPropertiesFamilyUpdates != null)
  5265. {
  5266. foreach (EntityUpdate eu in objectPropertiesFamilyUpdates)
  5267. {
  5268. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  5269. Buffer.BlockCopy(ObjectFamilyUpdateHeader, 0, buf.Data, 0, 8);
  5270. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  5271. zc.Position = 8;
  5272. CreateObjectPropertiesFamilyBlock((SceneObjectPart)eu.Entity, eu.Flags, zc);
  5273. buf.DataLength = zc.Finish();
  5274. //List<EntityUpdate> tau = new List<EntityUpdate>(1);
  5275. //tau.Add(new ObjectPropertyUpdate((ISceneEntity) eu, (uint)eu.Flags, true, false));
  5276. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  5277. // delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  5278. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  5279. }
  5280. }
  5281. if (needPhysics != null)
  5282. {
  5283. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  5284. if(eq != null)
  5285. {
  5286. osUTF8 sb = eq.StartEvent("ObjectPhysicsProperties");
  5287. LLSDxmlEncode2.AddArray("ObjectData", sb);
  5288. foreach (SceneObjectPart sop in needPhysics)
  5289. {
  5290. LLSDxmlEncode2.AddMap(sb);
  5291. LLSDxmlEncode2.AddElem("LocalID",(int)sop.LocalId, sb);
  5292. LLSDxmlEncode2.AddElem("Density", sop.Density, sb);
  5293. LLSDxmlEncode2.AddElem("Friction", sop.Friction, sb);
  5294. LLSDxmlEncode2.AddElem("GravityMultiplier", sop.GravityModifier, sb);
  5295. LLSDxmlEncode2.AddElem("Restitution", sop.Restitution, sb);
  5296. LLSDxmlEncode2.AddElem("PhysicsShapeType", (int)sop.PhysicsShapeType, sb);
  5297. LLSDxmlEncode2.AddEndMap(sb);
  5298. }
  5299. LLSDxmlEncode2.AddEndArray(sb);
  5300. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  5301. }
  5302. }
  5303. foreach(EntityUpdate eu in used)
  5304. eu.Free();
  5305. }
  5306. private void CreateObjectPropertiesFamilyBlock(SceneObjectPart sop, PrimUpdateFlags requestFlags, LLUDPZeroEncoder zc)
  5307. {
  5308. SceneObjectPart root = sop.ParentGroup.RootPart;
  5309. zc.AddUInt((uint)requestFlags);
  5310. zc.AddUUID(sop.UUID);
  5311. if (sop.OwnerID == sop.GroupID)
  5312. zc.AddZeros(16);
  5313. else
  5314. zc.AddUUID(sop.OwnerID);
  5315. zc.AddUUID(sop.GroupID);
  5316. zc.AddUInt(root.BaseMask);
  5317. zc.AddUInt(root.OwnerMask);
  5318. zc.AddUInt(root.GroupMask);
  5319. zc.AddUInt(root.EveryoneMask);
  5320. zc.AddUInt(root.NextOwnerMask);
  5321. zc.AddZeros(4); // int ownership cost
  5322. //sale info block
  5323. zc.AddByte(root.ObjectSaleType);
  5324. zc.AddInt(root.SalePrice);
  5325. zc.AddUInt(sop.Category); //Category
  5326. zc.AddUUID(sop.LastOwnerID);
  5327. //name
  5328. zc.AddShortLimitedUTF8(sop.osUTF8Name);
  5329. //Description
  5330. zc.AddShortLimitedUTF8(sop.osUTF8Description);
  5331. }
  5332. private void CreateObjectPropertiesBlock(SceneObjectPart sop, LLUDPZeroEncoder zc)
  5333. {
  5334. SceneObjectPart root = sop.ParentGroup.RootPart;
  5335. zc.AddUUID(sop.UUID);
  5336. zc.AddUUID(sop.CreatorID);
  5337. if (sop.OwnerID == sop.GroupID)
  5338. zc.AddZeros(16);
  5339. else
  5340. zc.AddUUID(sop.OwnerID);
  5341. zc.AddUUID(sop.GroupID);
  5342. zc.AddUInt64((ulong)sop.CreationDate * 1000000UL);
  5343. zc.AddUInt(root.BaseMask);
  5344. zc.AddUInt(root.OwnerMask);
  5345. zc.AddUInt(root.GroupMask);
  5346. zc.AddUInt(root.EveryoneMask);
  5347. zc.AddUInt(root.NextOwnerMask);
  5348. zc.AddZeros(4); // int ownership cost
  5349. //sale info block
  5350. zc.AddByte(root.ObjectSaleType);
  5351. zc.AddInt(root.SalePrice);
  5352. //aggregated perms we may will need to fix this
  5353. zc.AddByte(0); //AggregatePerms
  5354. zc.AddByte(0); //AggregatePermTextures;
  5355. zc.AddByte(0); //AggregatePermTexturesOwner
  5356. //inventory info
  5357. zc.AddUInt(sop.Category); //Category
  5358. zc.AddInt16((short)sop.InventorySerial);
  5359. zc.AddUUID(sop.FromUserInventoryItemID);
  5360. zc.AddUUID(UUID.Zero); //FolderID
  5361. zc.AddUUID(UUID.Zero); //FromTaskID
  5362. zc.AddUUID(sop.LastOwnerID);
  5363. //name
  5364. zc.AddShortLimitedUTF8(sop.osUTF8Name);
  5365. //Description
  5366. zc.AddShortLimitedUTF8(sop.osUTF8Description);
  5367. // touch name
  5368. zc.AddShortLimitedUTF8(sop.osUTF8TouchName);
  5369. // sit name
  5370. zc.AddShortLimitedUTF8(sop.osUTF8SitName);
  5371. //texture ids block
  5372. // still not sending, not clear the impact on viewers, if any.
  5373. // does seem redundant
  5374. // to send we will need proper list of face texture ids without having to unpack texture entry all the time
  5375. zc.AddZeros(1);
  5376. }
  5377. #region Estate Data Sending Methods
  5378. private static bool convertParamStringToBool(byte[] field)
  5379. {
  5380. string s = Utils.BytesToString(field);
  5381. if (s == "1" || s.ToLower() == "y" || s.ToLower() == "yes" || s.ToLower() == "t" || s.ToLower() == "true")
  5382. {
  5383. return true;
  5384. }
  5385. return false;
  5386. }
  5387. public void SendEstateList(UUID invoice, int code, UUID[] Data, uint estateID)
  5388. {
  5389. int TotalnumberIDs = Data.Length;
  5390. int numberIDs;
  5391. int IDIndex = 0;
  5392. do
  5393. {
  5394. if(TotalnumberIDs > 63)
  5395. numberIDs = 63;
  5396. else
  5397. numberIDs = TotalnumberIDs;
  5398. TotalnumberIDs -= numberIDs;
  5399. EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
  5400. packet.AgentData.TransactionID = UUID.Random();
  5401. packet.AgentData.AgentID = AgentId;
  5402. packet.AgentData.SessionID = SessionId;
  5403. packet.MethodData.Invoice = invoice;
  5404. packet.MethodData.Method = Utils.StringToBytes("setaccess");
  5405. EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[6 + numberIDs];
  5406. for (int i = 0; i < (6 + numberIDs); i++)
  5407. {
  5408. returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
  5409. }
  5410. returnblock[0].Parameter = Utils.StringToBytes(estateID.ToString());
  5411. returnblock[1].Parameter = Utils.StringToBytes(code.ToString());
  5412. if((code & 1) != 0) // allowagents
  5413. returnblock[2].Parameter = Utils.StringToBytes(numberIDs.ToString());
  5414. else
  5415. returnblock[2].Parameter = Utils.StringToBytes("0");
  5416. if((code & 2) != 0) // groups
  5417. returnblock[3].Parameter = Utils.StringToBytes(numberIDs.ToString());
  5418. else
  5419. returnblock[3].Parameter = Utils.StringToBytes("0");
  5420. if((code & 4) != 0) // bans
  5421. returnblock[4].Parameter = Utils.StringToBytes(numberIDs.ToString());
  5422. else
  5423. returnblock[4].Parameter = Utils.StringToBytes("0");
  5424. if((code & 8) != 0) // managers
  5425. returnblock[5].Parameter = Utils.StringToBytes(numberIDs.ToString());
  5426. else
  5427. returnblock[5].Parameter = Utils.StringToBytes("0");
  5428. int j = 6;
  5429. for (int i = 0; i < numberIDs; i++)
  5430. {
  5431. returnblock[j].Parameter = Data[IDIndex].GetBytes();
  5432. j++;
  5433. IDIndex++;
  5434. }
  5435. packet.ParamList = returnblock;
  5436. packet.Header.Reliable = true;
  5437. OutPacket(packet, ThrottleOutPacketType.Task);
  5438. } while (TotalnumberIDs > 0);
  5439. }
  5440. public void SendBannedUserList(UUID invoice, EstateBan[] bl, uint estateID)
  5441. {
  5442. List<UUID> BannedUsers = new List<UUID>();
  5443. for (int i = 0; i < bl.Length; i++)
  5444. {
  5445. if (bl[i] == null)
  5446. continue;
  5447. if (bl[i].BannedUserID == UUID.Zero)
  5448. continue;
  5449. BannedUsers.Add(bl[i].BannedUserID);
  5450. }
  5451. SendEstateList(invoice, 4, BannedUsers.ToArray(), estateID);
  5452. }
  5453. public void SendRegionInfoToEstateMenu(RegionInfoForEstateMenuArgs args)
  5454. {
  5455. RegionInfoPacket rinfopack = new RegionInfoPacket();
  5456. RegionInfoPacket.RegionInfoBlock rinfoblk = new RegionInfoPacket.RegionInfoBlock();
  5457. rinfopack.AgentData.AgentID = AgentId;
  5458. rinfopack.AgentData.SessionID = SessionId;
  5459. rinfoblk.BillableFactor = args.billableFactor;
  5460. rinfoblk.EstateID = args.estateID;
  5461. rinfoblk.MaxAgents = (byte)args.maxAgents;
  5462. rinfoblk.ObjectBonusFactor = args.objectBonusFactor;
  5463. rinfoblk.ParentEstateID = args.parentEstateID;
  5464. rinfoblk.PricePerMeter = args.pricePerMeter;
  5465. rinfoblk.RedirectGridX = args.redirectGridX;
  5466. rinfoblk.RedirectGridY = args.redirectGridY;
  5467. rinfoblk.RegionFlags = args.regionFlags;
  5468. rinfoblk.SimAccess = args.simAccess;
  5469. rinfoblk.SunHour = args.sunHour;
  5470. rinfoblk.TerrainLowerLimit = args.terrainLowerLimit;
  5471. rinfoblk.TerrainRaiseLimit = args.terrainRaiseLimit;
  5472. rinfoblk.UseEstateSun = args.useEstateSun;
  5473. rinfoblk.WaterHeight = args.waterHeight;
  5474. rinfoblk.SimName = Utils.StringToBytes(args.simName);
  5475. rinfopack.RegionInfo2 = new RegionInfoPacket.RegionInfo2Block();
  5476. rinfopack.RegionInfo2.HardMaxAgents = (uint)args.AgentCapacity;
  5477. rinfopack.RegionInfo2.HardMaxObjects = (uint)args.ObjectsCapacity;
  5478. rinfopack.RegionInfo2.MaxAgents32 = (uint)args.maxAgents;
  5479. rinfopack.RegionInfo2.ProductName = Util.StringToBytes256(args.regionType);
  5480. rinfopack.RegionInfo2.ProductSKU = Utils.EmptyBytes;
  5481. rinfopack.HasVariableBlocks = true;
  5482. rinfopack.RegionInfo = rinfoblk;
  5483. rinfopack.AgentData = new RegionInfoPacket.AgentDataBlock();
  5484. rinfopack.AgentData.AgentID = AgentId;
  5485. rinfopack.AgentData.SessionID = SessionId;
  5486. rinfopack.RegionInfo3 = new RegionInfoPacket.RegionInfo3Block[0];
  5487. OutPacket(rinfopack, ThrottleOutPacketType.Task);
  5488. }
  5489. public void SendEstateCovenantInformation(UUID covenant)
  5490. {
  5491. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending estate covenant asset id of {0} to {1}", covenant, Name);
  5492. EstateCovenantReplyPacket einfopack = new EstateCovenantReplyPacket();
  5493. EstateCovenantReplyPacket.DataBlock edata = new EstateCovenantReplyPacket.DataBlock();
  5494. edata.CovenantID = covenant;
  5495. edata.CovenantTimestamp = (uint) m_scene.RegionInfo.RegionSettings.CovenantChangedDateTime;
  5496. edata.EstateOwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  5497. edata.EstateName = Utils.StringToBytes(m_scene.RegionInfo.EstateSettings.EstateName);
  5498. einfopack.Data = edata;
  5499. OutPacket(einfopack, ThrottleOutPacketType.Task);
  5500. }
  5501. public void SendDetailedEstateData(
  5502. UUID invoice, string estateName, uint estateID, uint parentEstate, uint estateFlags, uint sunPosition,
  5503. UUID covenant, uint covenantChanged, string abuseEmail, UUID estateOwner)
  5504. {
  5505. // m_log.DebugFormat(
  5506. // "[LLCLIENTVIEW]: Sending detailed estate data to {0} with covenant asset id {1}", Name, covenant);
  5507. EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
  5508. packet.MethodData.Invoice = invoice;
  5509. packet.AgentData.TransactionID = UUID.Random();
  5510. packet.MethodData.Method = Utils.StringToBytes("estateupdateinfo");
  5511. EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[10];
  5512. for (int i = 0; i < 10; i++)
  5513. {
  5514. returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
  5515. }
  5516. //Sending Estate Settings
  5517. returnblock[0].Parameter = Utils.StringToBytes(estateName);
  5518. returnblock[1].Parameter = Utils.StringToBytes(estateOwner.ToString());
  5519. returnblock[2].Parameter = Utils.StringToBytes(estateID.ToString());
  5520. returnblock[3].Parameter = Utils.StringToBytes(estateFlags.ToString());
  5521. returnblock[4].Parameter = Utils.StringToBytes(sunPosition.ToString());
  5522. returnblock[5].Parameter = Utils.StringToBytes(parentEstate.ToString());
  5523. returnblock[6].Parameter = Utils.StringToBytes(covenant.ToString());
  5524. returnblock[7].Parameter = Utils.StringToBytes(covenantChanged.ToString());
  5525. returnblock[8].Parameter = Utils.StringToBytes("1"); // what is this?
  5526. returnblock[9].Parameter = Utils.StringToBytes(abuseEmail);
  5527. packet.ParamList = returnblock;
  5528. //m_log.Debug("[ESTATE]: SIM--->" + packet.ToString());
  5529. OutPacket(packet, ThrottleOutPacketType.Task);
  5530. }
  5531. public void SendTelehubInfo(UUID ObjectID, string ObjectName, Vector3 ObjectPos, Quaternion ObjectRot, List<Vector3> SpawnPoint)
  5532. {
  5533. TelehubInfoPacket packet = (TelehubInfoPacket)PacketPool.Instance.GetPacket(PacketType.TelehubInfo);
  5534. packet.TelehubBlock.ObjectID = ObjectID;
  5535. packet.TelehubBlock.ObjectName = Utils.StringToBytes(ObjectName);
  5536. packet.TelehubBlock.TelehubPos = ObjectPos;
  5537. packet.TelehubBlock.TelehubRot = ObjectRot;
  5538. packet.SpawnPointBlock = new TelehubInfoPacket.SpawnPointBlockBlock[SpawnPoint.Count];
  5539. for (int n = 0; n < SpawnPoint.Count; n++)
  5540. {
  5541. packet.SpawnPointBlock[n] = new TelehubInfoPacket.SpawnPointBlockBlock{SpawnPointPos = SpawnPoint[n]};
  5542. }
  5543. OutPacket(packet, ThrottleOutPacketType.Task);
  5544. }
  5545. #endregion
  5546. #region Land Data Sending Methods
  5547. public void SendLandParcelOverlay(byte[] data, int sequence_id)
  5548. {
  5549. ParcelOverlayPacket packet = (ParcelOverlayPacket)PacketPool.Instance.GetPacket(PacketType.ParcelOverlay);
  5550. packet.ParcelData.Data = data;
  5551. packet.ParcelData.SequenceID = sequence_id;
  5552. // OutPacket(packet, ThrottleOutPacketType.Task);
  5553. OutPacket(packet, ThrottleOutPacketType.Land);
  5554. }
  5555. public void SendLandProperties(
  5556. int sequence_id, bool snap_selection, int request_result, ILandObject lo,
  5557. float simObjectBonusFactor, int parcelObjectCapacity, int simObjectCapacity, uint regionFlags)
  5558. {
  5559. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending land properties for {0} to {1}", lo.LandData.GlobalID, Name);
  5560. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  5561. if (eq == null)
  5562. {
  5563. m_log.Warn("[LLCLIENTVIEW]: No EQ Interface when sending parcel data.");
  5564. return;
  5565. }
  5566. LandData landData = lo.LandData;
  5567. IPrimCounts pc = lo.PrimCounts;
  5568. int cap = 4 * landData.Bitmap.Length / 3 + 2048;
  5569. osUTF8 sb = eq.StartEvent("ParcelProperties", cap);
  5570. LLSDxmlEncode2.AddArrayAndMap("ParcelData", sb);
  5571. LLSDxmlEncode2.AddElem("LocalID", landData.LocalID, sb);
  5572. LLSDxmlEncode2.AddElem("AABBMax", landData.AABBMax, sb);
  5573. LLSDxmlEncode2.AddElem("AABBMin", landData.AABBMin, sb);
  5574. LLSDxmlEncode2.AddElem("Area", landData.Area, sb);
  5575. LLSDxmlEncode2.AddElem("AuctionID", (int)landData.AuctionID, sb);
  5576. LLSDxmlEncode2.AddElem("AuthBuyerID", landData.AuthBuyerID, sb);
  5577. LLSDxmlEncode2.AddElem("Bitmap", landData.Bitmap, sb);
  5578. LLSDxmlEncode2.AddElem("Category", (int)landData.Category, sb);
  5579. LLSDxmlEncode2.AddElem("ClaimDate", Util.ToDateTime(landData.ClaimDate), sb);
  5580. LLSDxmlEncode2.AddElem("ClaimPrice", landData.ClaimPrice, sb);
  5581. LLSDxmlEncode2.AddElem("Desc", landData.Description, sb);
  5582. LLSDxmlEncode2.AddElem("ParcelFlags", landData.Flags, sb);
  5583. LLSDxmlEncode2.AddElem("GroupID", landData.GroupID, sb);
  5584. LLSDxmlEncode2.AddElem("GroupPrims", pc.Group, sb);
  5585. LLSDxmlEncode2.AddElem("IsGroupOwned", landData.IsGroupOwned, sb);
  5586. LLSDxmlEncode2.AddElem("LandingType", (int)landData.LandingType, sb);
  5587. if (landData.Area > 0)
  5588. LLSDxmlEncode2.AddElem("MaxPrims", parcelObjectCapacity, sb);
  5589. else
  5590. LLSDxmlEncode2.AddElem("MaxPrims", (int)0, sb);
  5591. LLSDxmlEncode2.AddElem("MediaID", landData.MediaID, sb);
  5592. LLSDxmlEncode2.AddElem("MediaURL", landData.MediaURL, sb);
  5593. LLSDxmlEncode2.AddElem("MediaAutoScale", landData.MediaAutoScale != 0, sb);
  5594. LLSDxmlEncode2.AddElem("MusicURL", landData.MusicURL, sb);
  5595. LLSDxmlEncode2.AddElem("Name", landData.Name, sb);
  5596. LLSDxmlEncode2.AddElem("OtherCleanTime", landData.OtherCleanTime, sb);
  5597. LLSDxmlEncode2.AddElem("OtherCount", (int)0 , sb); //TODO
  5598. LLSDxmlEncode2.AddElem("OtherPrims", pc.Others, sb);
  5599. LLSDxmlEncode2.AddElem("OwnerID", landData.OwnerID, sb);
  5600. LLSDxmlEncode2.AddElem("OwnerPrims", pc.Owner, sb);
  5601. LLSDxmlEncode2.AddElem("ParcelPrimBonus", simObjectBonusFactor, sb);
  5602. LLSDxmlEncode2.AddElem("PassHours", landData.PassHours, sb);
  5603. LLSDxmlEncode2.AddElem("PassPrice", landData.PassPrice, sb);
  5604. LLSDxmlEncode2.AddElem("PublicCount", (int)0, sb); //TODO
  5605. LLSDxmlEncode2.AddElem("RegionDenyAnonymous", (regionFlags & (uint)RegionFlags.DenyAnonymous) != 0, sb);
  5606. LLSDxmlEncode2.AddElem("RegionDenyIdentified", false, sb);
  5607. LLSDxmlEncode2.AddElem("RegionDenyTransacted", false, sb);
  5608. LLSDxmlEncode2.AddElem("RegionPushOverride", (regionFlags & (uint)RegionFlags.RestrictPushObject) != 0, sb);
  5609. LLSDxmlEncode2.AddElem("RentPrice", (int) 0, sb);;
  5610. LLSDxmlEncode2.AddElem("RequestResult", request_result, sb);
  5611. LLSDxmlEncode2.AddElem("SalePrice", landData.SalePrice, sb);
  5612. LLSDxmlEncode2.AddElem("SelectedPrims", pc.Selected, sb);
  5613. LLSDxmlEncode2.AddElem("SelfCount", (int)0, sb); //TODO
  5614. LLSDxmlEncode2.AddElem("SequenceID", sequence_id, sb);
  5615. if (landData.SimwideArea > 0)
  5616. LLSDxmlEncode2.AddElem("SimWideMaxPrims", lo.GetSimulatorMaxPrimCount(), sb);
  5617. else
  5618. LLSDxmlEncode2.AddElem("SimWideMaxPrims", (int)0, sb);
  5619. LLSDxmlEncode2.AddElem("SimWideTotalPrims", pc.Simulator, sb);
  5620. LLSDxmlEncode2.AddElem("SnapSelection", snap_selection, sb);
  5621. LLSDxmlEncode2.AddElem("SnapshotID", landData.SnapshotID, sb);
  5622. LLSDxmlEncode2.AddElem("Status", (int)landData.Status, sb);
  5623. LLSDxmlEncode2.AddElem("TotalPrims", pc.Total, sb);
  5624. LLSDxmlEncode2.AddElem("UserLocation", landData.UserLocation, sb);
  5625. LLSDxmlEncode2.AddElem("UserLookAt", landData.UserLookAt, sb);
  5626. LLSDxmlEncode2.AddElem("SeeAVs", landData.SeeAVs, sb);
  5627. LLSDxmlEncode2.AddElem("AnyAVSounds", landData.AnyAVSounds, sb);
  5628. LLSDxmlEncode2.AddElem("GroupAVSounds", landData.GroupAVSounds, sb);
  5629. LLSDxmlEncode2.AddEndMapAndArray(sb);
  5630. LLSDxmlEncode2.AddArrayAndMap("MediaData", sb);
  5631. LLSDxmlEncode2.AddElem("MediaDesc", landData.MediaDescription, sb);
  5632. LLSDxmlEncode2.AddElem("MediaHeight", landData.MediaHeight, sb);
  5633. LLSDxmlEncode2.AddElem("MediaWidth", landData.MediaWidth, sb);
  5634. LLSDxmlEncode2.AddElem("MediaLoop", landData.MediaLoop, sb);
  5635. LLSDxmlEncode2.AddElem("MediaType", landData.MediaType, sb);
  5636. LLSDxmlEncode2.AddElem("ObscureMedia", landData.ObscureMedia, sb);
  5637. LLSDxmlEncode2.AddElem("ObscureMusic", landData.ObscureMusic, sb);
  5638. LLSDxmlEncode2.AddEndMapAndArray(sb);
  5639. LLSDxmlEncode2.AddArrayAndMap("AgeVerificationBlock", sb);
  5640. LLSDxmlEncode2.AddElem("RegionDenyAgeUnverified", (regionFlags & (uint)RegionFlags.DenyAgeUnverified) != 0, sb);
  5641. LLSDxmlEncode2.AddEndMapAndArray(sb);
  5642. bool allowenvovr = (regionFlags & (uint)RegionFlags.AllowEnvironmentOverride) != 0;
  5643. int envVersion;
  5644. if(allowenvovr)
  5645. {
  5646. ScenePresence sp = SceneAgent as ScenePresence;
  5647. if(sp != null && sp.EnvironmentVersion > 0)
  5648. envVersion = -1;
  5649. else
  5650. envVersion = landData.EnvironmentVersion;
  5651. }
  5652. else
  5653. envVersion = -1;
  5654. LLSDxmlEncode2.AddArrayAndMap("ParcelEnvironmentBlock", sb);
  5655. LLSDxmlEncode2.AddElem("ParcelEnvironmentVersion", envVersion, sb);
  5656. LLSDxmlEncode2.AddElem("RegionAllowEnvironmentOverride", allowenvovr, sb);
  5657. LLSDxmlEncode2.AddEndMapAndArray(sb);
  5658. bool accessovr = !Scene.RegionInfo.EstateSettings.TaxFree;
  5659. LLSDxmlEncode2.AddArrayAndMap("RegionAllowAccessBlock", sb);
  5660. LLSDxmlEncode2.AddElem("RegionAllowAccessOverride", accessovr, sb);
  5661. LLSDxmlEncode2.AddEndMapAndArray(sb);
  5662. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  5663. }
  5664. public void SendLandAccessListData(List<LandAccessEntry> accessList, uint accessFlag, int localLandID)
  5665. {
  5666. ParcelAccessListReplyPacket replyPacket = (ParcelAccessListReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelAccessListReply);
  5667. replyPacket.Data.AgentID = AgentId;
  5668. replyPacket.Data.Flags = accessFlag;
  5669. replyPacket.Data.LocalID = localLandID;
  5670. replyPacket.Data.SequenceID = 0;
  5671. List<ParcelAccessListReplyPacket.ListBlock> list = new List<ParcelAccessListReplyPacket.ListBlock>();
  5672. foreach (LandAccessEntry entry in accessList)
  5673. {
  5674. ParcelAccessListReplyPacket.ListBlock block = new ParcelAccessListReplyPacket.ListBlock();
  5675. block.Flags = accessFlag;
  5676. block.ID = entry.AgentID;
  5677. block.Time = entry.Expires;
  5678. list.Add(block);
  5679. }
  5680. replyPacket.List = list.ToArray();
  5681. replyPacket.Header.Zerocoded = true;
  5682. OutPacket(replyPacket, ThrottleOutPacketType.Task);
  5683. }
  5684. public void SendForceClientSelectObjects(List<uint> ObjectIDs)
  5685. {
  5686. // m_log.DebugFormat("[LLCLIENTVIEW] sending select with {0} objects", ObjectIDs.Count);
  5687. bool firstCall = true;
  5688. const int MAX_OBJECTS_PER_PACKET = 251;
  5689. ForceObjectSelectPacket pack = (ForceObjectSelectPacket)PacketPool.Instance.GetPacket(PacketType.ForceObjectSelect);
  5690. ForceObjectSelectPacket.DataBlock[] data;
  5691. while (ObjectIDs.Count > 0)
  5692. {
  5693. if (firstCall)
  5694. {
  5695. pack._Header.ResetList = true;
  5696. firstCall = false;
  5697. }
  5698. else
  5699. {
  5700. pack._Header.ResetList = false;
  5701. }
  5702. if (ObjectIDs.Count > MAX_OBJECTS_PER_PACKET)
  5703. {
  5704. data = new ForceObjectSelectPacket.DataBlock[MAX_OBJECTS_PER_PACKET];
  5705. }
  5706. else
  5707. {
  5708. data = new ForceObjectSelectPacket.DataBlock[ObjectIDs.Count];
  5709. }
  5710. int i;
  5711. for (i = 0; i < MAX_OBJECTS_PER_PACKET && ObjectIDs.Count > 0; i++)
  5712. {
  5713. data[i] = new ForceObjectSelectPacket.DataBlock();
  5714. data[i].LocalID = Convert.ToUInt32(ObjectIDs[0]);
  5715. ObjectIDs.RemoveAt(0);
  5716. }
  5717. pack.Data = data;
  5718. pack.Header.Zerocoded = true;
  5719. OutPacket(pack, ThrottleOutPacketType.Task);
  5720. }
  5721. }
  5722. public void SendCameraConstraint(Vector4 ConstraintPlane)
  5723. {
  5724. CameraConstraintPacket cpack = (CameraConstraintPacket)PacketPool.Instance.GetPacket(PacketType.CameraConstraint);
  5725. cpack.CameraCollidePlane = new CameraConstraintPacket.CameraCollidePlaneBlock();
  5726. cpack.CameraCollidePlane.Plane = ConstraintPlane;
  5727. //m_log.DebugFormat("[CLIENTVIEW]: Constraint {0}", ConstraintPlane);
  5728. OutPacket(cpack, ThrottleOutPacketType.Task);
  5729. }
  5730. public void SendLandObjectOwners(LandData land, List<UUID> groups, Dictionary<UUID, int> ownersAndCount)
  5731. {
  5732. int notifyCount = ownersAndCount.Count;
  5733. ParcelObjectOwnersReplyPacket pack = (ParcelObjectOwnersReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelObjectOwnersReply);
  5734. if (notifyCount > 0)
  5735. {
  5736. // if (notifyCount > 32)
  5737. // {
  5738. // m_log.InfoFormat(
  5739. // "[LAND]: More than {0} avatars own prims on this parcel. Only sending back details of first {0}"
  5740. // + " - a developer might want to investigate whether this is a hard limit", 32);
  5741. //
  5742. // notifyCount = 32;
  5743. // }
  5744. ParcelObjectOwnersReplyPacket.DataBlock[] dataBlock
  5745. = new ParcelObjectOwnersReplyPacket.DataBlock[notifyCount];
  5746. int num = 0;
  5747. foreach (UUID owner in ownersAndCount.Keys)
  5748. {
  5749. dataBlock[num] = new ParcelObjectOwnersReplyPacket.DataBlock();
  5750. dataBlock[num].Count = ownersAndCount[owner];
  5751. if (land.GroupID == owner || groups.Contains(owner))
  5752. dataBlock[num].IsGroupOwned = true;
  5753. dataBlock[num].OnlineStatus = true; //TODO: fix me later
  5754. dataBlock[num].OwnerID = owner;
  5755. num++;
  5756. if (num >= notifyCount)
  5757. {
  5758. break;
  5759. }
  5760. }
  5761. pack.Data = dataBlock;
  5762. }
  5763. else
  5764. {
  5765. pack.Data = new ParcelObjectOwnersReplyPacket.DataBlock[0];
  5766. }
  5767. pack.Header.Zerocoded = true;
  5768. this.OutPacket(pack, ThrottleOutPacketType.Task);
  5769. }
  5770. #endregion
  5771. #region Helper Methods
  5772. private void ClampVectorForUint(ref Vector3 v, float max)
  5773. {
  5774. float a,b;
  5775. a = Math.Abs(v.X);
  5776. b = Math.Abs(v.Y);
  5777. if(b > a)
  5778. a = b;
  5779. b= Math.Abs(v.Z);
  5780. if(b > a)
  5781. a = b;
  5782. if (a > max)
  5783. {
  5784. a = max / a;
  5785. v.X *= a;
  5786. v.Y *= a;
  5787. v.Z *= a;
  5788. }
  5789. }
  5790. protected void CreateImprovedTerseBlock(ISceneEntity entity, byte[] data, ref int pos, bool includeTexture)
  5791. {
  5792. #region ScenePresence/SOP Handling
  5793. bool avatar = (entity is ScenePresence);
  5794. uint localID = entity.LocalId;
  5795. uint attachPoint;
  5796. Vector4 collisionPlane;
  5797. Vector3 position, velocity, acceleration, angularVelocity;
  5798. Quaternion rotation;
  5799. byte datasize;
  5800. byte[] te = null;
  5801. if (avatar)
  5802. {
  5803. ScenePresence presence = (ScenePresence)entity;
  5804. position = presence.OffsetPosition;
  5805. velocity = presence.Velocity;
  5806. acceleration = Vector3.Zero;
  5807. rotation = presence.Rotation;
  5808. // tpvs can only see rotations around Z in some cases
  5809. if (!presence.Flying && !presence.IsSatOnObject)
  5810. {
  5811. rotation.X = 0f;
  5812. rotation.Y = 0f;
  5813. }
  5814. rotation.Normalize();
  5815. angularVelocity = presence.AngularVelocity;
  5816. // m_log.DebugFormat(
  5817. // "[LLCLIENTVIEW]: Sending terse update to {0} with position {1} in {2}", Name, presence.OffsetPosition, m_scene.Name);
  5818. attachPoint = presence.State;
  5819. collisionPlane = presence.CollisionPlane;
  5820. datasize = 60;
  5821. }
  5822. else
  5823. {
  5824. SceneObjectPart part = (SceneObjectPart)entity;
  5825. attachPoint = part.ParentGroup.AttachmentPoint;
  5826. attachPoint = ((attachPoint % 16) * 16 + (attachPoint / 16));
  5827. // m_log.DebugFormat(
  5828. // "[LLCLIENTVIEW]: Sending attachPoint {0} for {1} {2} to {3}",
  5829. // attachPoint, part.Name, part.LocalId, Name);
  5830. collisionPlane = Vector4.Zero;
  5831. position = part.RelativePosition;
  5832. velocity = part.Velocity;
  5833. acceleration = part.Acceleration;
  5834. angularVelocity = part.AngularVelocity;
  5835. rotation = part.RotationOffset;
  5836. datasize = 44;
  5837. if(includeTexture)
  5838. te = part.Shape.TextureEntry;
  5839. }
  5840. #endregion ScenePresence/SOP Handling
  5841. //object block size
  5842. data[pos++] = datasize;
  5843. // LocalID
  5844. Utils.UIntToBytes(localID, data, pos);
  5845. pos += 4;
  5846. data[pos++] = (byte)attachPoint;
  5847. // Avatar/CollisionPlane
  5848. if (avatar)
  5849. {
  5850. data[pos++] = 1;
  5851. if (collisionPlane == Vector4.Zero)
  5852. collisionPlane = Vector4.UnitW;
  5853. //m_log.DebugFormat("CollisionPlane: {0}",collisionPlane);
  5854. collisionPlane.ToBytes(data, pos);
  5855. pos += 16;
  5856. }
  5857. else
  5858. {
  5859. data[pos++] = 0;
  5860. }
  5861. // Position
  5862. position.ToBytes(data, pos);
  5863. pos += 12;
  5864. // Velocity
  5865. ClampVectorForUint(ref velocity, 128f);
  5866. Utils.FloatToUInt16Bytes(velocity.X, 128.0f, data, pos); pos += 2;
  5867. Utils.FloatToUInt16Bytes(velocity.Y, 128.0f, data, pos); pos += 2;
  5868. Utils.FloatToUInt16Bytes(velocity.Z, 128.0f, data, pos); pos += 2;
  5869. // Acceleration
  5870. ClampVectorForUint(ref acceleration, 64f);
  5871. Utils.FloatToUInt16Bytes(acceleration.X, 64.0f, data, pos); pos += 2;
  5872. Utils.FloatToUInt16Bytes(acceleration.Y, 64.0f, data, pos); pos += 2;
  5873. Utils.FloatToUInt16Bytes(acceleration.Z, 64.0f, data, pos); pos += 2;
  5874. // Rotation
  5875. Utils.FloatToUInt16Bytes(rotation.X, 1.0f, data, pos); pos += 2;
  5876. Utils.FloatToUInt16Bytes(rotation.Y, 1.0f, data, pos); pos += 2;
  5877. Utils.FloatToUInt16Bytes(rotation.Z, 1.0f, data, pos); pos += 2;
  5878. Utils.FloatToUInt16Bytes(rotation.W, 1.0f, data, pos); pos += 2;
  5879. // Angular Velocity
  5880. ClampVectorForUint(ref angularVelocity, 64f);
  5881. Utils.FloatToUInt16Bytes(angularVelocity.X, 64.0f, data, pos); pos += 2;
  5882. Utils.FloatToUInt16Bytes(angularVelocity.Y, 64.0f, data, pos); pos += 2;
  5883. Utils.FloatToUInt16Bytes(angularVelocity.Z, 64.0f, data, pos); pos += 2;
  5884. // texture entry block size
  5885. if(te == null)
  5886. {
  5887. data[pos++] = 0;
  5888. data[pos++] = 0;
  5889. }
  5890. else
  5891. {
  5892. int len = te.Length & 0x7fff;
  5893. int totlen = len + 4;
  5894. data[pos++] = (byte)totlen;
  5895. data[pos++] = (byte)(totlen >> 8);
  5896. data[pos++] = (byte)len; // wtf ???
  5897. data[pos++] = (byte)(len >> 8);
  5898. data[pos++] = 0;
  5899. data[pos++] = 0;
  5900. Buffer.BlockCopy(te, 0, data, pos, len);
  5901. pos += len;
  5902. }
  5903. // total size 63 or 47 + (texture size + 4)
  5904. }
  5905. protected void CreateAvatarUpdateBlock(ScenePresence data, byte[] dest, ref int pos)
  5906. {
  5907. Quaternion rotation = data.Rotation;
  5908. // tpvs can only see rotations around Z in some cases
  5909. if (!data.Flying && !data.IsSatOnObject)
  5910. {
  5911. rotation.X = 0f;
  5912. rotation.Y = 0f;
  5913. }
  5914. rotation.Normalize();
  5915. //Vector3 velocity = Vector3.Zero;
  5916. //Vector3 acceleration = Vector3.Zero;
  5917. //Vector3 angularvelocity = Vector3.Zero;
  5918. Utils.UIntToBytesSafepos(data.LocalId, dest, pos); pos += 4;
  5919. dest[pos++] = 0; // state
  5920. data.UUID.ToBytes(dest, pos); pos += 16;
  5921. Utils.UIntToBytesSafepos(0 , dest, pos); pos += 4; // crc
  5922. dest[pos++] = (byte)PCode.Avatar;
  5923. dest[pos++] = (byte)Material.Flesh;
  5924. dest[pos++] = 0; // clickaction
  5925. data.Appearance.AvatarSize.ToBytes(dest, pos); pos += 12;
  5926. // objectdata block
  5927. dest[pos++] = 76;
  5928. data.CollisionPlane.ToBytes(dest, pos); pos += 16;
  5929. data.OffsetPosition.ToBytes(dest, pos); pos += 12;
  5930. data.Velocity.ToBytes(dest, pos); pos += 12;
  5931. //acceleration.ToBytes(dest, pos); pos += 12;
  5932. Array.Clear(dest, pos, 12); pos += 12;
  5933. rotation.ToBytes(dest, pos); pos += 12;
  5934. //angularvelocity.ToBytes(dest, pos); pos += 12;
  5935. Array.Clear(dest, pos, 12); pos += 12;
  5936. SceneObjectPart parentPart = data.ParentPart;
  5937. if (parentPart != null)
  5938. {
  5939. Utils.UIntToBytesSafepos(parentPart.ParentGroup.LocalId, dest, pos);
  5940. pos += 4;
  5941. }
  5942. else
  5943. {
  5944. // Utils.UIntToBytesSafepos(0, dest, pos);
  5945. // pos += 4;
  5946. dest[pos++] = 0;
  5947. dest[pos++] = 0;
  5948. dest[pos++] = 0;
  5949. dest[pos++] = 0;
  5950. }
  5951. //Utils.UIntToBytesSafepos(0, dest, pos); pos += 4; //update flags
  5952. dest[pos++] = 0;
  5953. dest[pos++] = 0;
  5954. dest[pos++] = 0;
  5955. dest[pos++] = 0;
  5956. //pbs
  5957. dest[pos++] = 16;
  5958. dest[pos++] = 1;
  5959. //Utils.UInt16ToBytes(0, dest, pos); pos += 2;
  5960. //Utils.UInt16ToBytes(0, dest, pos); pos += 2;
  5961. dest[pos++] = 0;
  5962. dest[pos++] = 0;
  5963. dest[pos++] = 0;
  5964. dest[pos++] = 0;
  5965. dest[pos++] = 100;
  5966. dest[pos++] = 100;
  5967. // rest of pbs is 0 (15), texture entry (2) and texture anim (1)
  5968. const int pbszeros = 15 + 2 + 1;
  5969. Array.Clear(dest, pos, pbszeros); pos += pbszeros;
  5970. //NameValue
  5971. byte[] nv = Utils.StringToBytes("FirstName STRING RW SV " + data.Firstname + "\nLastName STRING RW SV " +
  5972. data.Lastname + "\nTitle STRING RW SV " + data.Grouptitle);
  5973. int len = nv.Length;
  5974. dest[pos++] = (byte)len;
  5975. dest[pos++] = (byte)(len >> 8);
  5976. Buffer.BlockCopy(nv, 0, dest, pos, len); pos += len;
  5977. // data(2), text(1), text color(4), media url(1), PBblock(1), ExtramParams(1),
  5978. // sound id(16), sound owner(16) gain (4), flags (1), radius (4)
  5979. // jointtype(1) joint pivot(12) joint offset(12)
  5980. const int lastzeros = 2 + 1 + 4 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12;
  5981. Array.Clear(dest, pos, lastzeros); pos += lastzeros;
  5982. }
  5983. protected void CreateAvatarUpdateBlock(ScenePresence data, LLUDPZeroEncoder zc)
  5984. {
  5985. Quaternion rotation = data.Rotation;
  5986. // tpvs can only see rotations around Z in some cases
  5987. if (!data.Flying && !data.IsSatOnObject)
  5988. {
  5989. rotation.X = 0f;
  5990. rotation.Y = 0f;
  5991. }
  5992. rotation.Normalize();
  5993. zc.AddUInt(data.LocalId);
  5994. zc.AddByte(0);
  5995. zc.AddUUID(data.UUID);
  5996. zc.AddZeros(4); // crc unused
  5997. zc.AddByte((byte)PCode.Avatar);
  5998. zc.AddByte((byte)Material.Flesh);
  5999. zc.AddByte(0); // clickaction
  6000. zc.AddVector3(data.Appearance.AvatarSize);
  6001. // objectdata block
  6002. zc.AddByte(76); // fixed avatar block size
  6003. zc.AddVector4(data.CollisionPlane);
  6004. zc.AddVector3(data.OffsetPosition);
  6005. zc.AddVector3(data.Velocity);
  6006. //zc.AddVector3(acceleration);
  6007. zc.AddZeros(12);
  6008. zc.AddNormQuat(rotation);
  6009. //zc.AddVector3(angularvelocity);
  6010. zc.AddZeros(12);
  6011. SceneObjectPart parentPart = data.ParentPart;
  6012. if (parentPart != null)
  6013. zc.AddUInt(parentPart.ParentGroup.LocalId);
  6014. else
  6015. zc.AddZeros(4);
  6016. zc.AddZeros(4); //update flags
  6017. //pbs volume data 23
  6018. //texture entry 2
  6019. //texture anim (1)
  6020. const int pbszeros = 23 + 2 + 1;
  6021. zc.AddZeros(pbszeros);
  6022. //NameValue
  6023. byte[] nv = Utils.StringToBytes("FirstName STRING RW SV " + data.Firstname + "\nLastName STRING RW SV " +
  6024. data.Lastname + "\nTitle STRING RW SV " + data.Grouptitle);
  6025. int len = nv.Length;
  6026. zc.AddByte((byte)len);
  6027. zc.AddByte((byte)(len >> 8));
  6028. zc.AddBytes(nv, len);
  6029. // data(2), text(1), text color(4), media url(1), PBblock(1), ExtramParams(1),
  6030. // sound id(16), sound owner(16) gain (4), flags (1), radius (4)
  6031. // jointtype(1) joint pivot(12) joint offset(12)
  6032. const int lastzeros = 2 + 1 + 4 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12;
  6033. zc.AddZeros(lastzeros);
  6034. }
  6035. protected void CreatePrimUpdateBlock(SceneObjectPart part, ScenePresence sp, LLUDPZeroEncoder zc)
  6036. {
  6037. // prepare data
  6038. #region PrimFlags
  6039. // prim/update flags
  6040. PrimFlags primflags = (PrimFlags)m_scene.Permissions.GenerateClientFlags(part, sp);
  6041. // Don't send the CreateSelected flag to everyone
  6042. primflags &= ~PrimFlags.CreateSelected;
  6043. if (sp.UUID == part.OwnerID)
  6044. {
  6045. if (part.CreateSelected)
  6046. {
  6047. // Only send this flag once, then unset it
  6048. primflags |= PrimFlags.CreateSelected;
  6049. part.CreateSelected = false;
  6050. }
  6051. }
  6052. #endregion PrimFlags
  6053. // data block
  6054. byte[] data = null;
  6055. byte state = part.Shape.State;
  6056. PCode pcode = (PCode)part.Shape.PCode;
  6057. //vegetation is special so just do it inline
  6058. if(pcode == PCode.Grass || pcode == PCode.Tree || pcode == PCode.NewTree)
  6059. {
  6060. zc.AddUInt(part.LocalId);
  6061. zc.AddByte(state); // state
  6062. zc.AddUUID(part.UUID);
  6063. zc.AddUInt((uint)part.PseudoCRC);
  6064. zc.AddByte((byte)pcode);
  6065. // material 1
  6066. // clickaction 1
  6067. zc.AddZeros(2);
  6068. zc.AddVector3(part.Shape.Scale);
  6069. // objectdata block
  6070. zc.AddByte(60); // fixed object block size
  6071. zc.AddVector3(part.RelativePosition);
  6072. if (pcode == PCode.Grass)
  6073. zc.AddZeros(48);
  6074. else
  6075. {
  6076. zc.AddZeros(24);
  6077. Quaternion rot = part.RotationOffset;
  6078. rot.Normalize();
  6079. zc.AddNormQuat(rot);
  6080. zc.AddZeros(12);
  6081. }
  6082. zc.AddUInt(part.ParentID);
  6083. zc.AddUInt((uint)primflags); //update flags
  6084. /*
  6085. if (pcode == PCode.Grass)
  6086. {
  6087. //pbs volume data 23
  6088. //texture entry 2
  6089. //texture anim 1
  6090. //name value 2
  6091. // data 1
  6092. // text 5
  6093. // media url 1
  6094. // particle system 1
  6095. // Extraparams 1
  6096. // sound id 16
  6097. // ownwer 16
  6098. // sound gain 4
  6099. // sound flags 1
  6100. // sound radius 4
  6101. // jointtype 1
  6102. // joint pivot 12
  6103. // joint offset 12
  6104. zc.AddZeros(23 + 2 + 1 + 2 + 1 + 5 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12);
  6105. return;
  6106. }
  6107. */
  6108. //pbs volume data 23
  6109. //texture entry 2
  6110. //texture anim 1
  6111. //name value 2
  6112. zc.AddZeros(23 + 2 + 1 + 2);
  6113. //data: the tree type
  6114. zc.AddByte(1);
  6115. zc.AddZeros(1);
  6116. zc.AddByte(state);
  6117. // text 5
  6118. // media url 1
  6119. // particle system 1
  6120. // Extraparams 1
  6121. // sound id 16
  6122. // ownwer 16
  6123. // sound gain 4
  6124. // sound flags 1
  6125. // sound radius 4
  6126. // jointtype 1
  6127. // joint pivot 12
  6128. // joint offset 12
  6129. zc.AddZeros(5 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12);
  6130. return;
  6131. }
  6132. //NameValue and state
  6133. byte[] nv = null;
  6134. if (part.ParentGroup.IsAttachment)
  6135. {
  6136. if (part.IsRoot)
  6137. nv = Util.StringToBytes256("AttachItemID STRING RW SV " + part.ParentGroup.FromItemID);
  6138. int st = (int)part.ParentGroup.AttachmentPoint;
  6139. state = (byte)(((st & 0xf0) >> 4) + ((st & 0x0f) << 4)); ;
  6140. }
  6141. // filter out mesh faces hack
  6142. ushort profileBegin = part.Shape.ProfileBegin;
  6143. ushort profileHollow = part.Shape.ProfileHollow;
  6144. byte profileCurve = part.Shape.ProfileCurve;
  6145. byte pathScaleY = part.Shape.PathScaleY;
  6146. if (part.Shape.SculptType == (byte)SculptType.Mesh) // filter out hack
  6147. {
  6148. profileCurve = (byte)(part.Shape.ProfileCurve & 0x0f);
  6149. // fix old values that confused viewers
  6150. if (profileBegin == 1)
  6151. profileBegin = 9375;
  6152. if (profileHollow == 1)
  6153. profileHollow = 27500;
  6154. // fix torus hole size Y that also confuse some viewers
  6155. if (profileCurve == (byte)ProfileShape.Circle && pathScaleY < 150)
  6156. pathScaleY = 150;
  6157. }
  6158. // do encode the things
  6159. zc.AddUInt(part.LocalId);
  6160. zc.AddByte(state); // state
  6161. zc.AddUUID(part.UUID);
  6162. zc.AddUInt((uint)part.PseudoCRC);
  6163. zc.AddByte((byte)pcode);
  6164. zc.AddByte(part.Material);
  6165. zc.AddByte(part.ClickAction); // clickaction
  6166. zc.AddVector3(part.Shape.Scale);
  6167. // objectdata block
  6168. zc.AddByte(60); // fixed object block size
  6169. zc.AddVector3(part.RelativePosition);
  6170. zc.AddVector3(part.Velocity);
  6171. zc.AddVector3(part.Acceleration);
  6172. Quaternion rotation = part.RotationOffset;
  6173. rotation.Normalize();
  6174. zc.AddNormQuat(rotation);
  6175. zc.AddVector3(part.AngularVelocity);
  6176. zc.AddUInt(part.ParentID);
  6177. zc.AddUInt((uint)primflags); //update flags
  6178. //pbs
  6179. zc.AddByte(part.Shape.PathCurve);
  6180. zc.AddByte(profileCurve);
  6181. zc.AddUInt16(part.Shape.PathBegin);
  6182. zc.AddUInt16(part.Shape.PathEnd);
  6183. zc.AddByte(part.Shape.PathScaleX);
  6184. zc.AddByte(pathScaleY);
  6185. zc.AddByte(part.Shape.PathShearX);
  6186. zc.AddByte(part.Shape.PathShearY);
  6187. zc.AddByte((byte)part.Shape.PathTwist);
  6188. zc.AddByte((byte)part.Shape.PathTwistBegin);
  6189. zc.AddByte((byte)part.Shape.PathRadiusOffset);
  6190. zc.AddByte((byte)part.Shape.PathTaperX);
  6191. zc.AddByte((byte)part.Shape.PathTaperY);
  6192. zc.AddByte(part.Shape.PathRevolutions);
  6193. zc.AddByte((byte)part.Shape.PathSkew);
  6194. zc.AddUInt16(profileBegin);
  6195. zc.AddUInt16(part.Shape.ProfileEnd);
  6196. zc.AddUInt16(profileHollow);
  6197. // texture
  6198. byte[] tentry = part.Shape.TextureEntry;
  6199. if (tentry == null)
  6200. zc.AddZeros(2);
  6201. else
  6202. {
  6203. int len = tentry.Length;
  6204. zc.AddByte((byte)len);
  6205. zc.AddByte((byte)(len >> 8));
  6206. zc.AddBytes(tentry, len);
  6207. }
  6208. // texture animation
  6209. byte[] tanim = part.TextureAnimation;
  6210. if (tanim == null)
  6211. zc.AddZeros(1);
  6212. else
  6213. {
  6214. int len = tanim.Length;
  6215. zc.AddByte((byte)len);
  6216. zc.AddBytes(tanim, len);
  6217. }
  6218. //NameValue
  6219. if(nv == null)
  6220. zc.AddZeros(2);
  6221. else
  6222. {
  6223. int len = nv.Length;
  6224. zc.AddByte((byte)len);
  6225. zc.AddByte((byte)(len >> 8));
  6226. zc.AddBytes(nv, len);
  6227. }
  6228. // data
  6229. if (data == null)
  6230. zc.AddZeros(2);
  6231. else
  6232. {
  6233. int len = data.Length;
  6234. zc.AddByte((byte)len);
  6235. zc.AddByte((byte)(len >> 8));
  6236. zc.AddBytes(data, len);
  6237. }
  6238. //text
  6239. osUTF8 osUTF8PartText = part.osUTF8Text;
  6240. if (osUTF8PartText == null || osUTF8PartText.Length == 0)
  6241. zc.AddZeros(5);
  6242. else
  6243. {
  6244. zc.AddShortLimitedUTF8(osUTF8PartText);
  6245. //textcolor
  6246. byte[] tc = part.GetTextColor().GetBytes(false);
  6247. zc.AddBytes(tc, 4);
  6248. }
  6249. //media url
  6250. zc.AddShortLimitedUTF8(part.osUTFMediaUrl);
  6251. bool hasps = false;
  6252. //particle system
  6253. byte[] ps = part.ParticleSystem;
  6254. if (ps == null || ps.Length < 1)
  6255. zc.AddZeros(1);
  6256. else
  6257. {
  6258. int len = ps.Length;
  6259. zc.AddByte((byte)len);
  6260. zc.AddBytes(ps, len);
  6261. hasps = true;
  6262. }
  6263. //Extraparams
  6264. byte[] ep = part.Shape.ExtraParams;
  6265. if (ep == null || ep.Length < 2)
  6266. zc.AddZeros(1);
  6267. else
  6268. {
  6269. int len = ep.Length;
  6270. zc.AddByte((byte)len);
  6271. zc.AddBytes(ep, len);
  6272. }
  6273. bool hassound = part.Sound != UUID.Zero || part.SoundFlags != 0;
  6274. if (hassound)
  6275. zc.AddUUID(part.Sound);
  6276. else
  6277. zc.AddZeros(16);
  6278. if (hassound || hasps)
  6279. zc.AddUUID(part.OwnerID);
  6280. else
  6281. zc.AddZeros(16);
  6282. if (hassound)
  6283. {
  6284. zc.AddFloat((float)part.SoundGain);
  6285. zc.AddByte(part.SoundFlags);
  6286. zc.AddFloat((float)part.SoundRadius);
  6287. }
  6288. else
  6289. zc.AddZeros(9);
  6290. // jointtype(1) joint pivot(12) joint offset(12)
  6291. const int lastzeros = 1 + 12 + 12;
  6292. zc.AddZeros(lastzeros);
  6293. }
  6294. [Flags]
  6295. private enum CompressedFlags : uint
  6296. {
  6297. None = 0x00,
  6298. /// <summary>Unknown</summary>
  6299. ScratchPad = 0x01,
  6300. /// <summary>Whether the object has a TreeSpecies</summary>
  6301. Tree = 0x02,
  6302. /// <summary>Whether the object has floating text ala llSetText</summary>
  6303. HasText = 0x04,
  6304. /// <summary>Whether the object has an active particle system</summary>
  6305. HasParticlesLegacy = 0x08,
  6306. /// <summary>Whether the object has sound attached to it</summary>
  6307. HasSound = 0x10,
  6308. /// <summary>Whether the object is attached to a root object or not</summary>
  6309. HasParent = 0x20,
  6310. /// <summary>Whether the object has texture animation settings</summary>
  6311. TextureAnimation = 0x40,
  6312. /// <summary>Whether the object has an angular velocity</summary>
  6313. HasAngularVelocity = 0x80,
  6314. /// <summary>Whether the object has a name value pairs string</summary>
  6315. HasNameValues = 0x100,
  6316. /// <summary>Whether the object has a Media URL set</summary>
  6317. MediaURL = 0x200,
  6318. HasParticlesNew = 0x400
  6319. }
  6320. /*
  6321. protected void CreateCompressedUpdateBlock(SceneObjectPart part, ScenePresence sp, byte[] dest, ref int pos)
  6322. {
  6323. // prepare data
  6324. CompressedFlags cflags = CompressedFlags.None;
  6325. // prim/update flags
  6326. PrimFlags primflags = (PrimFlags)m_scene.Permissions.GenerateClientFlags(part, sp);
  6327. // Don't send the CreateSelected flag to everyone
  6328. primflags &= ~PrimFlags.CreateSelected;
  6329. if (sp.UUID == part.OwnerID)
  6330. {
  6331. if (part.CreateSelected)
  6332. {
  6333. // Only send this flag once, then unset it
  6334. primflags |= PrimFlags.CreateSelected;
  6335. part.CreateSelected = false;
  6336. }
  6337. }
  6338. byte state = part.Shape.State;
  6339. PCode pcode = (PCode)part.Shape.PCode;
  6340. bool hastree = false;
  6341. if (pcode == PCode.Grass || pcode == PCode.Tree || pcode == PCode.NewTree)
  6342. {
  6343. cflags |= CompressedFlags.Tree;
  6344. hastree = true;
  6345. }
  6346. //NameValue and state
  6347. byte[] nv = null;
  6348. if (part.ParentGroup.IsAttachment)
  6349. {
  6350. if (part.IsRoot)
  6351. nv = Util.StringToBytes256("AttachItemID STRING RW SV " + part.ParentGroup.FromItemID);
  6352. int st = (int)part.ParentGroup.AttachmentPoint;
  6353. state = (byte)(((st & 0xf0) >> 4) + ((st & 0x0f) << 4)); ;
  6354. }
  6355. bool hastext = part.Text != null && part.Text.Length > 0;
  6356. bool hassound = part.Sound != UUID.Zero || part.SoundFlags != 0;
  6357. bool hasps = part.ParticleSystem != null && part.ParticleSystem.Length > 1;
  6358. bool hastexanim = part.TextureAnimation != null && part.TextureAnimation.Length > 0;
  6359. bool hasangvel = part.AngularVelocity.LengthSquared() > 1e-8f;
  6360. bool hasmediaurl = part.MediaUrl != null && part.MediaUrl.Length > 1;
  6361. bool haspsnew = false;
  6362. if (hastext)
  6363. cflags |= CompressedFlags.HasText;
  6364. if (hasps)
  6365. {
  6366. if(part.ParticleSystem.Length > 86)
  6367. {
  6368. hasps= false;
  6369. cflags |= CompressedFlags.HasParticlesNew;
  6370. haspsnew = true;
  6371. }
  6372. else
  6373. cflags |= CompressedFlags.HasParticlesLegacy;
  6374. }
  6375. if (hassound)
  6376. cflags |= CompressedFlags.HasSound;
  6377. if (part.ParentID != 0)
  6378. cflags |= CompressedFlags.HasParent;
  6379. if (hastexanim)
  6380. cflags |= CompressedFlags.TextureAnimation;
  6381. if (hasangvel)
  6382. cflags |= CompressedFlags.HasAngularVelocity;
  6383. if (hasmediaurl)
  6384. cflags |= CompressedFlags.MediaURL;
  6385. if (nv != null)
  6386. cflags |= CompressedFlags.HasNameValues;
  6387. // filter out mesh faces hack
  6388. ushort profileBegin = part.Shape.ProfileBegin;
  6389. ushort profileHollow = part.Shape.ProfileHollow;
  6390. byte profileCurve = part.Shape.ProfileCurve;
  6391. byte pathScaleY = part.Shape.PathScaleY;
  6392. if (part.Shape.SculptType == (byte)SculptType.Mesh) // filter out hack
  6393. {
  6394. profileCurve = (byte)(part.Shape.ProfileCurve & 0x0f);
  6395. // fix old values that confused viewers
  6396. if (profileBegin == 1)
  6397. profileBegin = 9375;
  6398. if (profileHollow == 1)
  6399. profileHollow = 27500;
  6400. // fix torus hole size Y that also confuse some viewers
  6401. if (profileCurve == (byte)ProfileShape.Circle && pathScaleY < 150)
  6402. pathScaleY = 150;
  6403. }
  6404. // first is primFlags
  6405. Utils.UIntToBytesSafepos((uint)primflags, dest, pos); pos += 4;
  6406. // datablock len to fill later
  6407. int lenpos = pos;
  6408. pos += 2;
  6409. // data block
  6410. part.UUID.ToBytes(dest, pos); pos += 16;
  6411. Utils.UIntToBytesSafepos(part.LocalId, dest, pos); pos += 4;
  6412. dest[pos++] = (byte)pcode;
  6413. dest[pos++] = state;
  6414. Utils.UIntToBytesSafepos((uint)part.ParentGroup.PseudoCRC, dest, pos); pos += 4;
  6415. dest[pos++] = part.Material;
  6416. dest[pos++] = part.ClickAction;
  6417. part.Shape.Scale.ToBytes(dest, pos); pos += 12;
  6418. part.RelativePosition.ToBytes(dest, pos); pos += 12;
  6419. if(pcode == PCode.Grass)
  6420. Vector3.Zero.ToBytes(dest, pos);
  6421. else
  6422. {
  6423. Quaternion rotation = part.RotationOffset;
  6424. rotation.Normalize();
  6425. rotation.ToBytes(dest, pos);
  6426. }
  6427. pos += 12;
  6428. Utils.UIntToBytesSafepos((uint)cflags, dest, pos); pos += 4;
  6429. if (hasps || haspsnew || hassound)
  6430. part.OwnerID.ToBytes(dest, pos);
  6431. else
  6432. UUID.Zero.ToBytes(dest, pos);
  6433. pos += 16;
  6434. if (hasangvel)
  6435. {
  6436. part.AngularVelocity.ToBytes(dest, pos); pos += 12;
  6437. }
  6438. if (part.ParentID != 0)
  6439. {
  6440. Utils.UIntToBytesSafepos(part.ParentID, dest, pos); pos += 4;
  6441. }
  6442. if (hastree)
  6443. dest[pos++] = state;
  6444. if (hastext)
  6445. {
  6446. byte[] text = Util.StringToBytes256(part.Text); // must be null term
  6447. Buffer.BlockCopy(text, 0, dest, pos, text.Length); pos += text.Length;
  6448. byte[] tc = part.GetTextColor().GetBytes(false);
  6449. Buffer.BlockCopy(tc, 0, dest, pos, tc.Length); pos += tc.Length;
  6450. }
  6451. if (hasmediaurl)
  6452. {
  6453. byte[] mu = Util.StringToBytes256(part.MediaUrl); // must be null term
  6454. Buffer.BlockCopy(mu, 0, dest, pos, mu.Length); pos += mu.Length;
  6455. }
  6456. if (hasps)
  6457. {
  6458. byte[] ps = part.ParticleSystem;
  6459. Buffer.BlockCopy(ps, 0, dest, pos, ps.Length); pos += ps.Length;
  6460. }
  6461. byte[] ex = part.Shape.ExtraParams;
  6462. if (ex == null || ex.Length < 2)
  6463. dest[pos++] = 0;
  6464. else
  6465. {
  6466. Buffer.BlockCopy(ex, 0, dest, pos, ex.Length); pos += ex.Length;
  6467. }
  6468. if (hassound)
  6469. {
  6470. part.Sound.ToBytes(dest, pos); pos += 16;
  6471. Utils.FloatToBytesSafepos((float)part.SoundGain, dest, pos); pos += 4;
  6472. dest[pos++] = part.SoundFlags;
  6473. Utils.FloatToBytesSafepos((float)part.SoundRadius, dest, pos); pos += 4;
  6474. }
  6475. if (nv != null)
  6476. {
  6477. Buffer.BlockCopy(nv, 0, dest, pos, nv.Length); pos += nv.Length;
  6478. }
  6479. dest[pos++] = part.Shape.PathCurve;
  6480. Utils.UInt16ToBytes(part.Shape.PathBegin, dest, pos); pos += 2;
  6481. Utils.UInt16ToBytes(part.Shape.PathEnd, dest, pos); pos += 2;
  6482. dest[pos++] = part.Shape.PathScaleX;
  6483. dest[pos++] = pathScaleY;
  6484. dest[pos++] = part.Shape.PathShearX;
  6485. dest[pos++] = part.Shape.PathShearY;
  6486. dest[pos++] = (byte)part.Shape.PathTwist;
  6487. dest[pos++] = (byte)part.Shape.PathTwistBegin;
  6488. dest[pos++] = (byte)part.Shape.PathRadiusOffset;
  6489. dest[pos++] = (byte)part.Shape.PathTaperX;
  6490. dest[pos++] = (byte)part.Shape.PathTaperY;
  6491. dest[pos++] = part.Shape.PathRevolutions;
  6492. dest[pos++] = (byte)part.Shape.PathSkew;
  6493. dest[pos++] = profileCurve;
  6494. Utils.UInt16ToBytes(profileBegin, dest, pos); pos += 2;
  6495. Utils.UInt16ToBytes(part.Shape.ProfileEnd, dest, pos); pos += 2;
  6496. Utils.UInt16ToBytes(profileHollow, dest, pos); pos += 2;
  6497. byte[] te = part.Shape.TextureEntry;
  6498. if (te == null)
  6499. {
  6500. dest[pos++] = 0;
  6501. dest[pos++] = 0;
  6502. dest[pos++] = 0;
  6503. dest[pos++] = 0;
  6504. }
  6505. else
  6506. {
  6507. int len = te.Length & 0x7fff;
  6508. dest[pos++] = (byte)len;
  6509. dest[pos++] = (byte)(len >> 8);
  6510. dest[pos++] = 0;
  6511. dest[pos++] = 0;
  6512. Buffer.BlockCopy(te, 0, dest, pos, len);
  6513. pos += len;
  6514. }
  6515. if (hastexanim)
  6516. {
  6517. byte[] ta = part.TextureAnimation;
  6518. int len = ta.Length & 0x7fff;
  6519. dest[pos++] = (byte)len;
  6520. dest[pos++] = (byte)(len >> 8);
  6521. dest[pos++] = 0;
  6522. dest[pos++] = 0;
  6523. Buffer.BlockCopy(ta, 0, dest, pos, len);
  6524. pos += len;
  6525. }
  6526. if (haspsnew)
  6527. {
  6528. byte[] ps = part.ParticleSystem;
  6529. Buffer.BlockCopy(ps, 0, dest, pos, ps.Length); pos += ps.Length;
  6530. }
  6531. int totlen = pos - lenpos - 2;
  6532. dest[lenpos++] = (byte)totlen;
  6533. dest[lenpos++] = (byte)(totlen >> 8);
  6534. }
  6535. */
  6536. protected void CreateCompressedUpdateBlockZC(SceneObjectPart part, ScenePresence sp, LLUDPZeroEncoder zc)
  6537. {
  6538. // prepare data
  6539. CompressedFlags cflags = CompressedFlags.None;
  6540. // prim/update flags
  6541. PrimFlags primflags = (PrimFlags)m_scene.Permissions.GenerateClientFlags(part, sp);
  6542. // Don't send the CreateSelected flag to everyone
  6543. primflags &= ~PrimFlags.CreateSelected;
  6544. if (sp.UUID == part.OwnerID)
  6545. {
  6546. if (part.CreateSelected)
  6547. {
  6548. // Only send this flag once, then unset it
  6549. primflags |= PrimFlags.CreateSelected;
  6550. part.CreateSelected = false;
  6551. }
  6552. }
  6553. byte state = part.Shape.State;
  6554. PCode pcode = (PCode)part.Shape.PCode;
  6555. // trees and grass are a lot more compact
  6556. if (pcode == PCode.Grass || pcode == PCode.Tree || pcode == PCode.NewTree)
  6557. {
  6558. // first is primFlags
  6559. zc.AddUInt((uint)primflags);
  6560. // datablock len
  6561. zc.AddByte(113);
  6562. zc.AddZeros(1);
  6563. // data block
  6564. zc.AddUUID(part.UUID);
  6565. zc.AddUInt(part.LocalId);
  6566. zc.AddByte((byte)pcode);
  6567. zc.AddByte(state);
  6568. zc.AddUInt((uint)part.PseudoCRC);
  6569. zc.AddZeros(2); // material and click action
  6570. zc.AddVector3(part.Shape.Scale);
  6571. zc.AddVector3(part.RelativePosition);
  6572. if (pcode == PCode.Grass)
  6573. zc.AddZeros(12);
  6574. else
  6575. {
  6576. Quaternion rotation = part.RotationOffset;
  6577. rotation.Normalize();
  6578. zc.AddNormQuat(rotation);
  6579. }
  6580. zc.AddUInt((uint)CompressedFlags.Tree); // cflags
  6581. zc.AddZeros(16); // owner id
  6582. zc.AddByte(state); // tree parameter
  6583. zc.AddZeros(28); //extraparameters 1, pbs 23, texture 4
  6584. return;
  6585. }
  6586. //NameValue and state
  6587. byte[] nv = null;
  6588. if (part.ParentGroup.IsAttachment)
  6589. {
  6590. if (part.IsRoot)
  6591. nv = Util.StringToBytes256("AttachItemID STRING RW SV " + part.ParentGroup.FromItemID);
  6592. int st = (int)part.ParentGroup.AttachmentPoint;
  6593. state = (byte)(((st & 0xf0) >> 4) + ((st & 0x0f) << 4)); ;
  6594. }
  6595. bool hastext = false;
  6596. bool hassound = false;
  6597. bool hasps = false;
  6598. bool hastexanim = false;
  6599. bool hasangvel = false;
  6600. bool hasmediaurl = false;
  6601. bool haspsnew = false;
  6602. int BlockLengh = 111;
  6603. byte[] extraParamBytes = part.Shape.ExtraParams;
  6604. if (extraParamBytes == null || extraParamBytes.Length < 2)
  6605. {
  6606. ++BlockLengh;
  6607. extraParamBytes = null;
  6608. }
  6609. else
  6610. BlockLengh += extraParamBytes.Length;
  6611. byte[] hoverTextColor = null;
  6612. osUTF8 osUTF8PartText = part.osUTF8Text;
  6613. if (osUTF8PartText != null && osUTF8PartText.Length > 0)
  6614. {
  6615. cflags |= CompressedFlags.HasText;
  6616. BlockLengh += osUTF8PartText.Length;
  6617. if (osUTF8PartText[osUTF8PartText.Length - 1] != 0)
  6618. ++BlockLengh;
  6619. hoverTextColor = part.GetTextColor().GetBytes(false);
  6620. BlockLengh += hoverTextColor.Length;
  6621. hastext = true;
  6622. }
  6623. if (part.ParticleSystem != null && part.ParticleSystem.Length > 1)
  6624. {
  6625. BlockLengh += part.ParticleSystem.Length;
  6626. if (part.ParticleSystem.Length > 86)
  6627. {
  6628. hasps = false;
  6629. cflags |= CompressedFlags.HasParticlesNew;
  6630. haspsnew = true;
  6631. }
  6632. else
  6633. {
  6634. cflags |= CompressedFlags.HasParticlesLegacy;
  6635. hasps = true;
  6636. }
  6637. }
  6638. if (part.Sound != UUID.Zero || part.SoundFlags != 0)
  6639. {
  6640. BlockLengh += 25;
  6641. cflags |= CompressedFlags.HasSound;
  6642. hassound = true;
  6643. }
  6644. if (part.ParentID != 0)
  6645. {
  6646. BlockLengh += 4;
  6647. cflags |= CompressedFlags.HasParent;
  6648. }
  6649. if (part.TextureAnimation != null && part.TextureAnimation.Length > 0)
  6650. {
  6651. BlockLengh += part.TextureAnimation.Length + 4;
  6652. cflags |= CompressedFlags.TextureAnimation;
  6653. hastexanim = true;
  6654. }
  6655. if (part.AngularVelocity.LengthSquared() > 1e-8f)
  6656. {
  6657. BlockLengh += 12;
  6658. cflags |= CompressedFlags.HasAngularVelocity;
  6659. hasangvel = true;
  6660. }
  6661. osUTF8 osUTFMediaUrl = part.osUTFMediaUrl;
  6662. if (osUTFMediaUrl != null && osUTFMediaUrl.Length > 0)
  6663. {
  6664. BlockLengh += osUTFMediaUrl.Length;
  6665. if (osUTFMediaUrl[osUTFMediaUrl.Length - 1] != 0)
  6666. ++BlockLengh;
  6667. cflags |= CompressedFlags.MediaURL;
  6668. hasmediaurl = true;
  6669. }
  6670. if (nv != null)
  6671. {
  6672. BlockLengh += nv.Length;
  6673. cflags |= CompressedFlags.HasNameValues;
  6674. }
  6675. byte[] textureEntry = part.Shape.TextureEntry;
  6676. if(textureEntry != null)
  6677. BlockLengh += textureEntry.Length;
  6678. // filter out mesh faces hack
  6679. ushort profileBegin = part.Shape.ProfileBegin;
  6680. ushort profileHollow = part.Shape.ProfileHollow;
  6681. byte profileCurve = part.Shape.ProfileCurve;
  6682. byte pathScaleY = part.Shape.PathScaleY;
  6683. if (part.Shape.SculptType == (byte)SculptType.Mesh) // filter out hack
  6684. {
  6685. profileCurve = (byte)(part.Shape.ProfileCurve & 0x0f);
  6686. // fix old values that confused viewers
  6687. if (profileBegin == 1)
  6688. profileBegin = 9375;
  6689. if (profileHollow == 1)
  6690. profileHollow = 27500;
  6691. // fix torus hole size Y that also confuse some viewers
  6692. if (profileCurve == (byte)ProfileShape.Circle && pathScaleY < 150)
  6693. pathScaleY = 150;
  6694. }
  6695. // first is primFlags
  6696. zc.AddUInt((uint)primflags);
  6697. // datablock len
  6698. zc.AddByte((byte)BlockLengh);
  6699. zc.AddByte((byte)(BlockLengh >> 8));
  6700. // data block
  6701. zc.AddUUID(part.UUID);
  6702. zc.AddUInt(part.LocalId);
  6703. zc.AddByte((byte)pcode);
  6704. zc.AddByte(state);
  6705. zc.AddUInt((uint)part.PseudoCRC);
  6706. zc.AddByte(part.Material);
  6707. zc.AddByte(part.ClickAction);
  6708. zc.AddVector3(part.Shape.Scale);
  6709. zc.AddVector3(part.RelativePosition);
  6710. if (pcode == PCode.Grass)
  6711. zc.AddZeros(12);
  6712. else
  6713. {
  6714. Quaternion rotation = part.RotationOffset;
  6715. rotation.Normalize();
  6716. zc.AddNormQuat(rotation);
  6717. }
  6718. zc.AddUInt((uint)cflags);
  6719. if (hasps || haspsnew || hassound)
  6720. zc.AddUUID(part.OwnerID);
  6721. else
  6722. zc.AddZeros(16);
  6723. if (hasangvel)
  6724. {
  6725. zc.AddVector3(part.AngularVelocity);
  6726. }
  6727. if (part.ParentID != 0)
  6728. {
  6729. zc.AddUInt(part.ParentID);
  6730. }
  6731. if (hastext)
  6732. {
  6733. zc.AddBytes(osUTF8PartText.GetArray(), osUTF8PartText.Length);
  6734. if (osUTF8PartText[osUTF8PartText.Length - 1] != 0)
  6735. zc.AddZeros(1);
  6736. zc.AddBytes(hoverTextColor, hoverTextColor.Length);
  6737. }
  6738. if (hasmediaurl)
  6739. {
  6740. zc.AddBytes(osUTFMediaUrl.GetArray(), osUTFMediaUrl.Length);
  6741. if (osUTFMediaUrl[osUTFMediaUrl.Length - 1] != 0)
  6742. zc.AddZeros(1);
  6743. }
  6744. if (hasps)
  6745. {
  6746. byte[] ps = part.ParticleSystem;
  6747. zc.AddBytes(ps, ps.Length);
  6748. }
  6749. if (extraParamBytes == null)
  6750. zc.AddZeros(1);
  6751. else
  6752. {
  6753. zc.AddBytes(extraParamBytes, extraParamBytes.Length);
  6754. }
  6755. if (hassound)
  6756. {
  6757. zc.AddUUID(part.Sound);
  6758. zc.AddFloat((float)part.SoundGain);
  6759. zc.AddByte(part.SoundFlags);
  6760. zc.AddFloat((float)part.SoundRadius);
  6761. }
  6762. if (nv != null)
  6763. {
  6764. zc.AddBytes(nv, nv.Length);
  6765. }
  6766. zc.AddByte(part.Shape.PathCurve);
  6767. zc.AddUInt16(part.Shape.PathBegin);
  6768. zc.AddUInt16(part.Shape.PathEnd);
  6769. zc.AddByte(part.Shape.PathScaleX);
  6770. zc.AddByte(pathScaleY);
  6771. zc.AddByte(part.Shape.PathShearX);
  6772. zc.AddByte(part.Shape.PathShearY);
  6773. zc.AddByte((byte)part.Shape.PathTwist);
  6774. zc.AddByte((byte)part.Shape.PathTwistBegin);
  6775. zc.AddByte((byte)part.Shape.PathRadiusOffset);
  6776. zc.AddByte((byte)part.Shape.PathTaperX);
  6777. zc.AddByte((byte)part.Shape.PathTaperY);
  6778. zc.AddByte(part.Shape.PathRevolutions);
  6779. zc.AddByte((byte)part.Shape.PathSkew);
  6780. zc.AddByte(profileCurve);
  6781. zc.AddUInt16(profileBegin);
  6782. zc.AddUInt16(part.Shape.ProfileEnd);
  6783. zc.AddUInt16(profileHollow);
  6784. if (textureEntry == null)
  6785. {
  6786. zc.AddZeros(4);
  6787. }
  6788. else
  6789. {
  6790. int len = textureEntry.Length;
  6791. zc.AddByte((byte)len);
  6792. zc.AddByte((byte)(len >> 8));
  6793. zc.AddZeros(2);
  6794. zc.AddBytes(textureEntry, len);
  6795. }
  6796. if (hastexanim)
  6797. {
  6798. byte[] ta = part.TextureAnimation;
  6799. int len = ta.Length;
  6800. zc.AddByte((byte)len);
  6801. zc.AddByte((byte)(len >> 8));
  6802. zc.AddZeros(2);
  6803. zc.AddBytes(ta, len);
  6804. }
  6805. if (haspsnew)
  6806. {
  6807. byte[] ps = part.ParticleSystem;
  6808. zc.AddBytes(ps, ps.Length);
  6809. }
  6810. }
  6811. public void SendNameReply(UUID profileId, string firstname, string lastname)
  6812. {
  6813. UUIDNameReplyPacket packet = (UUIDNameReplyPacket)PacketPool.Instance.GetPacket(PacketType.UUIDNameReply);
  6814. // TODO: don't create new blocks if recycling an old packet
  6815. packet.UUIDNameBlock = new UUIDNameReplyPacket.UUIDNameBlockBlock[1];
  6816. packet.UUIDNameBlock[0] = new UUIDNameReplyPacket.UUIDNameBlockBlock();
  6817. packet.UUIDNameBlock[0].ID = profileId;
  6818. packet.UUIDNameBlock[0].FirstName = Util.StringToBytes256(firstname);
  6819. packet.UUIDNameBlock[0].LastName = Util.StringToBytes256(lastname);
  6820. OutPacket(packet, ThrottleOutPacketType.Task);
  6821. }
  6822. public Dictionary<UUID, ulong> GetGroupPowers()
  6823. {
  6824. lock(m_groupPowers)
  6825. {
  6826. return new Dictionary<UUID, ulong>(m_groupPowers);
  6827. }
  6828. }
  6829. public void SetGroupPowers(Dictionary<UUID, ulong> powers)
  6830. {
  6831. lock(m_groupPowers)
  6832. {
  6833. m_groupPowers.Clear();
  6834. m_groupPowers = powers;
  6835. }
  6836. }
  6837. public ulong GetGroupPowers(UUID groupID)
  6838. {
  6839. lock(m_groupPowers)
  6840. {
  6841. if (m_groupPowers.ContainsKey(groupID))
  6842. return m_groupPowers[groupID];
  6843. }
  6844. return 0;
  6845. }
  6846. #endregion
  6847. protected virtual void RegisterLocalPacketHandlers()
  6848. {
  6849. AddLocalPacketHandler(PacketType.LogoutRequest, HandleLogout);
  6850. // If AgentUpdate is ever handled asynchronously, then we will also need to construct a new AgentUpdateArgs
  6851. // for each AgentUpdate packet.
  6852. AddLocalPacketHandler(PacketType.AgentUpdate, HandleAgentUpdate, false);
  6853. AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect, false);
  6854. AddLocalPacketHandler(PacketType.VelocityInterpolateOff, HandleVelocityInterpolateOff, false);
  6855. AddLocalPacketHandler(PacketType.VelocityInterpolateOn, HandleVelocityInterpolateOn, false);
  6856. AddLocalPacketHandler(PacketType.AgentCachedTexture, HandleAgentTextureCached, false);
  6857. AddLocalPacketHandler(PacketType.MultipleObjectUpdate, HandleMultipleObjUpdate, false);
  6858. AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest, false);
  6859. AddLocalPacketHandler(PacketType.ParcelBuy, HandleParcelBuyRequest, false);
  6860. AddLocalPacketHandler(PacketType.UUIDGroupNameRequest, HandleUUIDGroupNameRequest);
  6861. AddLocalPacketHandler(PacketType.ObjectGroup, HandleObjectGroupRequest);
  6862. AddLocalPacketHandler(PacketType.GenericMessage, HandleGenericMessage);
  6863. AddLocalPacketHandler(PacketType.AvatarPropertiesRequest, HandleAvatarPropertiesRequest);
  6864. AddLocalPacketHandler(PacketType.ChatFromViewer, HandleChatFromViewer);
  6865. AddLocalPacketHandler(PacketType.AvatarPropertiesUpdate, HandlerAvatarPropertiesUpdate);
  6866. AddLocalPacketHandler(PacketType.ScriptDialogReply, HandlerScriptDialogReply);
  6867. AddLocalPacketHandler(PacketType.ImprovedInstantMessage, HandlerImprovedInstantMessage);
  6868. AddLocalPacketHandler(PacketType.AcceptFriendship, HandlerAcceptFriendship);
  6869. AddLocalPacketHandler(PacketType.DeclineFriendship, HandlerDeclineFriendship);
  6870. AddLocalPacketHandler(PacketType.TerminateFriendship, HandlerTerminateFriendship);
  6871. AddLocalPacketHandler(PacketType.RezObject, HandlerRezObject);
  6872. AddLocalPacketHandler(PacketType.DeRezObject, HandlerDeRezObject);
  6873. AddLocalPacketHandler(PacketType.RezRestoreToWorld, HandlerRezRestoreToWorld);
  6874. AddLocalPacketHandler(PacketType.ModifyLand, HandlerModifyLand);
  6875. AddLocalPacketHandler(PacketType.RegionHandshakeReply, HandlerRegionHandshakeReply, false);
  6876. AddLocalPacketHandler(PacketType.AgentWearablesRequest, HandlerAgentWearablesRequest);
  6877. AddLocalPacketHandler(PacketType.AgentSetAppearance, HandlerAgentSetAppearance);
  6878. AddLocalPacketHandler(PacketType.AgentIsNowWearing, HandlerAgentIsNowWearing);
  6879. AddLocalPacketHandler(PacketType.RezSingleAttachmentFromInv, HandlerRezSingleAttachmentFromInv);
  6880. AddLocalPacketHandler(PacketType.RezMultipleAttachmentsFromInv, HandleRezMultipleAttachmentsFromInv);
  6881. AddLocalPacketHandler(PacketType.DetachAttachmentIntoInv, HandleDetachAttachmentIntoInv);
  6882. AddLocalPacketHandler(PacketType.ObjectAttach, HandleObjectAttach);
  6883. AddLocalPacketHandler(PacketType.ObjectDetach, HandleObjectDetach);
  6884. AddLocalPacketHandler(PacketType.ObjectDrop, HandleObjectDrop);
  6885. AddLocalPacketHandler(PacketType.SetAlwaysRun, HandleSetAlwaysRun, false);
  6886. AddLocalPacketHandler(PacketType.CompleteAgentMovement, HandleCompleteAgentMovement);
  6887. AddLocalPacketHandler(PacketType.AgentAnimation, HandleAgentAnimation, false);
  6888. AddLocalPacketHandler(PacketType.AgentRequestSit, HandleAgentRequestSit);
  6889. AddLocalPacketHandler(PacketType.AgentSit, HandleAgentSit);
  6890. AddLocalPacketHandler(PacketType.SoundTrigger, HandleSoundTrigger);
  6891. AddLocalPacketHandler(PacketType.AvatarPickerRequest, HandleAvatarPickerRequest);
  6892. AddLocalPacketHandler(PacketType.AgentDataUpdateRequest, HandleAgentDataUpdateRequest);
  6893. AddLocalPacketHandler(PacketType.UserInfoRequest, HandleUserInfoRequest);
  6894. AddLocalPacketHandler(PacketType.UpdateUserInfo, HandleUpdateUserInfo);
  6895. AddLocalPacketHandler(PacketType.SetStartLocationRequest, HandleSetStartLocationRequest);
  6896. AddLocalPacketHandler(PacketType.AgentThrottle, HandleAgentThrottle, false);
  6897. AddLocalPacketHandler(PacketType.AgentPause, HandleAgentPause, false);
  6898. AddLocalPacketHandler(PacketType.AgentResume, HandleAgentResume, false);
  6899. AddLocalPacketHandler(PacketType.ForceScriptControlRelease, HandleForceScriptControlRelease);
  6900. AddLocalPacketHandler(PacketType.ObjectLink, HandleObjectLink);
  6901. AddLocalPacketHandler(PacketType.ObjectDelink, HandleObjectDelink);
  6902. AddLocalPacketHandler(PacketType.ObjectAdd, HandleObjectAdd);
  6903. AddLocalPacketHandler(PacketType.ObjectShape, HandleObjectShape);
  6904. AddLocalPacketHandler(PacketType.ObjectExtraParams, HandleObjectExtraParams);
  6905. AddLocalPacketHandler(PacketType.ObjectDuplicate, HandleObjectDuplicate);
  6906. AddLocalPacketHandler(PacketType.RequestMultipleObjects, HandleRequestMultipleObjects);
  6907. AddLocalPacketHandler(PacketType.ObjectSelect, HandleObjectSelect);
  6908. AddLocalPacketHandler(PacketType.ObjectDeselect, HandleObjectDeselect);
  6909. AddLocalPacketHandler(PacketType.ObjectPosition, HandleObjectPosition);
  6910. AddLocalPacketHandler(PacketType.ObjectScale, HandleObjectScale);
  6911. AddLocalPacketHandler(PacketType.ObjectRotation, HandleObjectRotation);
  6912. AddLocalPacketHandler(PacketType.ObjectFlagUpdate, HandleObjectFlagUpdate);
  6913. // Handle ObjectImage (TextureEntry) updates synchronously, since when updating multiple prim faces at once,
  6914. // some clients will send out a separate ObjectImage packet for each face
  6915. AddLocalPacketHandler(PacketType.ObjectImage, HandleObjectImage, false);
  6916. AddLocalPacketHandler(PacketType.ObjectGrab, HandleObjectGrab, false);
  6917. AddLocalPacketHandler(PacketType.ObjectGrabUpdate, HandleObjectGrabUpdate, false);
  6918. AddLocalPacketHandler(PacketType.ObjectDeGrab, HandleObjectDeGrab);
  6919. AddLocalPacketHandler(PacketType.ObjectSpinStart, HandleObjectSpinStart, false);
  6920. AddLocalPacketHandler(PacketType.ObjectSpinUpdate, HandleObjectSpinUpdate, false);
  6921. AddLocalPacketHandler(PacketType.ObjectSpinStop, HandleObjectSpinStop, false);
  6922. AddLocalPacketHandler(PacketType.ObjectDescription, HandleObjectDescription, false);
  6923. AddLocalPacketHandler(PacketType.ObjectName, HandleObjectName, false);
  6924. AddLocalPacketHandler(PacketType.ObjectPermissions, HandleObjectPermissions, false);
  6925. AddLocalPacketHandler(PacketType.Undo, HandleUndo, false);
  6926. AddLocalPacketHandler(PacketType.UndoLand, HandleLandUndo, false);
  6927. AddLocalPacketHandler(PacketType.Redo, HandleRedo, false);
  6928. AddLocalPacketHandler(PacketType.ObjectDuplicateOnRay, HandleObjectDuplicateOnRay);
  6929. AddLocalPacketHandler(PacketType.RequestObjectPropertiesFamily, HandleRequestObjectPropertiesFamily, false);
  6930. AddLocalPacketHandler(PacketType.ObjectIncludeInSearch, HandleObjectIncludeInSearch);
  6931. AddLocalPacketHandler(PacketType.ScriptAnswerYes, HandleScriptAnswerYes, false);
  6932. AddLocalPacketHandler(PacketType.ObjectClickAction, HandleObjectClickAction, false);
  6933. AddLocalPacketHandler(PacketType.ObjectMaterial, HandleObjectMaterial, false);
  6934. AddLocalPacketHandler(PacketType.RequestImage, HandleRequestImage, false);
  6935. AddLocalPacketHandler(PacketType.TransferRequest, HandleTransferRequest, false);
  6936. AddLocalPacketHandler(PacketType.AssetUploadRequest, HandleAssetUploadRequest);
  6937. AddLocalPacketHandler(PacketType.RequestXfer, HandleRequestXfer);
  6938. AddLocalPacketHandler(PacketType.SendXferPacket, HandleSendXferPacket);
  6939. AddLocalPacketHandler(PacketType.ConfirmXferPacket, HandleConfirmXferPacket, false);
  6940. AddLocalPacketHandler(PacketType.AbortXfer, HandleAbortXfer);
  6941. AddLocalPacketHandler(PacketType.CreateInventoryFolder, HandleCreateInventoryFolder);
  6942. AddLocalPacketHandler(PacketType.UpdateInventoryFolder, HandleUpdateInventoryFolder);
  6943. AddLocalPacketHandler(PacketType.MoveInventoryFolder, HandleMoveInventoryFolder);
  6944. AddLocalPacketHandler(PacketType.CreateInventoryItem, HandleCreateInventoryItem);
  6945. AddLocalPacketHandler(PacketType.LinkInventoryItem, HandleLinkInventoryItem);
  6946. AddLocalPacketHandler(PacketType.FetchInventory, HandleFetchInventory);
  6947. AddLocalPacketHandler(PacketType.FetchInventoryDescendents, HandleFetchInventoryDescendents);
  6948. AddLocalPacketHandler(PacketType.PurgeInventoryDescendents, HandlePurgeInventoryDescendents);
  6949. AddLocalPacketHandler(PacketType.UpdateInventoryItem, HandleUpdateInventoryItem);
  6950. AddLocalPacketHandler(PacketType.CopyInventoryItem, HandleCopyInventoryItem);
  6951. AddLocalPacketHandler(PacketType.MoveInventoryItem, HandleMoveInventoryItem);
  6952. AddLocalPacketHandler(PacketType.RemoveInventoryItem, HandleRemoveInventoryItem);
  6953. AddLocalPacketHandler(PacketType.RemoveInventoryFolder, HandleRemoveInventoryFolder);
  6954. AddLocalPacketHandler(PacketType.RemoveInventoryObjects, HandleRemoveInventoryObjects);
  6955. AddLocalPacketHandler(PacketType.RequestTaskInventory, HandleRequestTaskInventory);
  6956. AddLocalPacketHandler(PacketType.UpdateTaskInventory, HandleUpdateTaskInventory);
  6957. AddLocalPacketHandler(PacketType.RemoveTaskInventory, HandleRemoveTaskInventory);
  6958. AddLocalPacketHandler(PacketType.MoveTaskInventory, HandleMoveTaskInventory);
  6959. AddLocalPacketHandler(PacketType.RezScript, HandleRezScript);
  6960. AddLocalPacketHandler(PacketType.MapLayerRequest, HandleMapLayerRequest);
  6961. AddLocalPacketHandler(PacketType.MapBlockRequest, HandleMapBlockRequest);
  6962. AddLocalPacketHandler(PacketType.MapNameRequest, HandleMapNameRequest);
  6963. AddLocalPacketHandler(PacketType.TeleportLandmarkRequest, HandleTeleportLandmarkRequest);
  6964. AddLocalPacketHandler(PacketType.TeleportCancel, HandleTeleportCancel);
  6965. AddLocalPacketHandler(PacketType.TeleportLocationRequest, HandleTeleportLocationRequest);
  6966. AddLocalPacketHandler(PacketType.UUIDNameRequest, HandleUUIDNameRequest, false);
  6967. AddLocalPacketHandler(PacketType.RegionHandleRequest, HandleRegionHandleRequest, false);
  6968. AddLocalPacketHandler(PacketType.ParcelInfoRequest, HandleParcelInfoRequest);
  6969. AddLocalPacketHandler(PacketType.ParcelAccessListRequest, HandleParcelAccessListRequest, false);
  6970. AddLocalPacketHandler(PacketType.ParcelAccessListUpdate, HandleParcelAccessListUpdate, false);
  6971. AddLocalPacketHandler(PacketType.ParcelPropertiesRequest, HandleParcelPropertiesRequest, false);
  6972. AddLocalPacketHandler(PacketType.ParcelDivide, HandleParcelDivide);
  6973. AddLocalPacketHandler(PacketType.ParcelJoin, HandleParcelJoin);
  6974. AddLocalPacketHandler(PacketType.ParcelPropertiesUpdate, HandleParcelPropertiesUpdate);
  6975. AddLocalPacketHandler(PacketType.ParcelSelectObjects, HandleParcelSelectObjects);
  6976. AddLocalPacketHandler(PacketType.ParcelObjectOwnersRequest, HandleParcelObjectOwnersRequest);
  6977. AddLocalPacketHandler(PacketType.ParcelGodForceOwner, HandleParcelGodForceOwner);
  6978. AddLocalPacketHandler(PacketType.ParcelRelease, HandleParcelRelease);
  6979. AddLocalPacketHandler(PacketType.ParcelReclaim, HandleParcelReclaim);
  6980. AddLocalPacketHandler(PacketType.ParcelReturnObjects, HandleParcelReturnObjects);
  6981. AddLocalPacketHandler(PacketType.ParcelSetOtherCleanTime, HandleParcelSetOtherCleanTime);
  6982. AddLocalPacketHandler(PacketType.LandStatRequest, HandleLandStatRequest);
  6983. AddLocalPacketHandler(PacketType.ParcelDwellRequest, HandleParcelDwellRequest);
  6984. AddLocalPacketHandler(PacketType.EstateOwnerMessage, HandleEstateOwnerMessage);
  6985. AddLocalPacketHandler(PacketType.RequestRegionInfo, HandleRequestRegionInfo, false);
  6986. AddLocalPacketHandler(PacketType.EstateCovenantRequest, HandleEstateCovenantRequest);
  6987. AddLocalPacketHandler(PacketType.RequestGodlikePowers, HandleRequestGodlikePowers);
  6988. AddLocalPacketHandler(PacketType.GodKickUser, HandleGodKickUser);
  6989. AddLocalPacketHandler(PacketType.MoneyBalanceRequest, HandleMoneyBalanceRequest);
  6990. AddLocalPacketHandler(PacketType.EconomyDataRequest, HandleEconomyDataRequest);
  6991. AddLocalPacketHandler(PacketType.RequestPayPrice, HandleRequestPayPrice);
  6992. AddLocalPacketHandler(PacketType.ObjectSaleInfo, HandleObjectSaleInfo);
  6993. AddLocalPacketHandler(PacketType.ObjectBuy, HandleObjectBuy);
  6994. AddLocalPacketHandler(PacketType.GetScriptRunning, HandleGetScriptRunning);
  6995. AddLocalPacketHandler(PacketType.SetScriptRunning, HandleSetScriptRunning);
  6996. AddLocalPacketHandler(PacketType.ScriptReset, HandleScriptReset);
  6997. AddLocalPacketHandler(PacketType.ActivateGestures, HandleActivateGestures);
  6998. AddLocalPacketHandler(PacketType.DeactivateGestures, HandleDeactivateGestures);
  6999. AddLocalPacketHandler(PacketType.ObjectOwner, HandleObjectOwner);
  7000. AddLocalPacketHandler(PacketType.AgentFOV, HandleAgentFOV, false);
  7001. AddLocalPacketHandler(PacketType.ViewerStats, HandleViewerStats);
  7002. AddLocalPacketHandler(PacketType.MapItemRequest, HandleMapItemRequest, false);
  7003. AddLocalPacketHandler(PacketType.TransferAbort, HandleTransferAbort, false);
  7004. AddLocalPacketHandler(PacketType.MuteListRequest, HandleMuteListRequest, false);
  7005. AddLocalPacketHandler(PacketType.UseCircuitCode, HandleUseCircuitCode);
  7006. AddLocalPacketHandler(PacketType.CreateNewOutfitAttachments, HandleCreateNewOutfitAttachments);
  7007. AddLocalPacketHandler(PacketType.AgentHeightWidth, HandleAgentHeightWidth, false);
  7008. AddLocalPacketHandler(PacketType.InventoryDescendents, HandleInventoryDescendents);
  7009. AddLocalPacketHandler(PacketType.DirPlacesQuery, HandleDirPlacesQuery);
  7010. AddLocalPacketHandler(PacketType.DirFindQuery, HandleDirFindQuery);
  7011. AddLocalPacketHandler(PacketType.DirLandQuery, HandleDirLandQuery);
  7012. AddLocalPacketHandler(PacketType.DirPopularQuery, HandleDirPopularQuery);
  7013. AddLocalPacketHandler(PacketType.DirClassifiedQuery, HandleDirClassifiedQuery);
  7014. AddLocalPacketHandler(PacketType.EventInfoRequest, HandleEventInfoRequest);
  7015. AddLocalPacketHandler(PacketType.OfferCallingCard, HandleOfferCallingCard);
  7016. AddLocalPacketHandler(PacketType.AcceptCallingCard, HandleAcceptCallingCard);
  7017. AddLocalPacketHandler(PacketType.DeclineCallingCard, HandleDeclineCallingCard);
  7018. AddLocalPacketHandler(PacketType.ActivateGroup, HandleActivateGroup);
  7019. AddLocalPacketHandler(PacketType.GroupTitlesRequest, HandleGroupTitlesRequest);
  7020. AddLocalPacketHandler(PacketType.GroupProfileRequest, HandleGroupProfileRequest);
  7021. AddLocalPacketHandler(PacketType.GroupMembersRequest, HandleGroupMembersRequest);
  7022. AddLocalPacketHandler(PacketType.GroupRoleDataRequest, HandleGroupRoleDataRequest);
  7023. AddLocalPacketHandler(PacketType.GroupRoleMembersRequest, HandleGroupRoleMembersRequest);
  7024. AddLocalPacketHandler(PacketType.CreateGroupRequest, HandleCreateGroupRequest);
  7025. AddLocalPacketHandler(PacketType.UpdateGroupInfo, HandleUpdateGroupInfo);
  7026. AddLocalPacketHandler(PacketType.SetGroupAcceptNotices, HandleSetGroupAcceptNotices);
  7027. AddLocalPacketHandler(PacketType.GroupTitleUpdate, HandleGroupTitleUpdate);
  7028. AddLocalPacketHandler(PacketType.ParcelDeedToGroup, HandleParcelDeedToGroup);
  7029. AddLocalPacketHandler(PacketType.GroupNoticesListRequest, HandleGroupNoticesListRequest);
  7030. AddLocalPacketHandler(PacketType.GroupNoticeRequest, HandleGroupNoticeRequest);
  7031. AddLocalPacketHandler(PacketType.GroupRoleUpdate, HandleGroupRoleUpdate);
  7032. AddLocalPacketHandler(PacketType.GroupRoleChanges, HandleGroupRoleChanges);
  7033. AddLocalPacketHandler(PacketType.JoinGroupRequest, HandleJoinGroupRequest);
  7034. AddLocalPacketHandler(PacketType.LeaveGroupRequest, HandleLeaveGroupRequest);
  7035. AddLocalPacketHandler(PacketType.EjectGroupMemberRequest, HandleEjectGroupMemberRequest);
  7036. AddLocalPacketHandler(PacketType.InviteGroupRequest, HandleInviteGroupRequest);
  7037. AddLocalPacketHandler(PacketType.StartLure, HandleStartLure);
  7038. AddLocalPacketHandler(PacketType.TeleportLureRequest, HandleTeleportLureRequest);
  7039. AddLocalPacketHandler(PacketType.ClassifiedInfoRequest, HandleClassifiedInfoRequest);
  7040. AddLocalPacketHandler(PacketType.ClassifiedInfoUpdate, HandleClassifiedInfoUpdate);
  7041. AddLocalPacketHandler(PacketType.ClassifiedDelete, HandleClassifiedDelete);
  7042. AddLocalPacketHandler(PacketType.ClassifiedGodDelete, HandleClassifiedGodDelete);
  7043. AddLocalPacketHandler(PacketType.EventGodDelete, HandleEventGodDelete);
  7044. AddLocalPacketHandler(PacketType.EventNotificationAddRequest, HandleEventNotificationAddRequest);
  7045. AddLocalPacketHandler(PacketType.EventNotificationRemoveRequest, HandleEventNotificationRemoveRequest);
  7046. AddLocalPacketHandler(PacketType.RetrieveInstantMessages, HandleRetrieveInstantMessages);
  7047. AddLocalPacketHandler(PacketType.PickDelete, HandlePickDelete);
  7048. AddLocalPacketHandler(PacketType.PickGodDelete, HandlePickGodDelete);
  7049. AddLocalPacketHandler(PacketType.PickInfoUpdate, HandlePickInfoUpdate);
  7050. AddLocalPacketHandler(PacketType.AvatarNotesUpdate, HandleAvatarNotesUpdate);
  7051. AddLocalPacketHandler(PacketType.AvatarInterestsUpdate, HandleAvatarInterestsUpdate);
  7052. AddLocalPacketHandler(PacketType.GrantUserRights, HandleGrantUserRights);
  7053. AddLocalPacketHandler(PacketType.PlacesQuery, HandlePlacesQuery);
  7054. AddLocalPacketHandler(PacketType.UpdateMuteListEntry, HandleUpdateMuteListEntry);
  7055. AddLocalPacketHandler(PacketType.RemoveMuteListEntry, HandleRemoveMuteListEntry);
  7056. AddLocalPacketHandler(PacketType.UserReport, HandleUserReport);
  7057. AddLocalPacketHandler(PacketType.FindAgent, HandleFindAgent);
  7058. AddLocalPacketHandler(PacketType.TrackAgent, HandleTrackAgent);
  7059. AddLocalPacketHandler(PacketType.GodUpdateRegionInfo, HandleGodUpdateRegionInfoUpdate);
  7060. AddLocalPacketHandler(PacketType.GodlikeMessage, HandleGodlikeMessage);
  7061. AddLocalPacketHandler(PacketType.StateSave, HandleSaveStatePacket);
  7062. AddLocalPacketHandler(PacketType.GroupAccountDetailsRequest, HandleGroupAccountDetailsRequest);
  7063. AddLocalPacketHandler(PacketType.GroupAccountSummaryRequest, HandleGroupAccountSummaryRequest);
  7064. AddLocalPacketHandler(PacketType.GroupAccountTransactionsRequest, HandleGroupTransactionsDetailsRequest);
  7065. AddLocalPacketHandler(PacketType.FreezeUser, HandleFreezeUser);
  7066. AddLocalPacketHandler(PacketType.EjectUser, HandleEjectUser);
  7067. AddLocalPacketHandler(PacketType.ParcelBuyPass, HandleParcelBuyPass);
  7068. AddLocalPacketHandler(PacketType.ParcelGodMarkAsContent, HandleParcelGodMarkAsContent);
  7069. AddLocalPacketHandler(PacketType.GroupActiveProposalsRequest, HandleGroupActiveProposalsRequest);
  7070. AddLocalPacketHandler(PacketType.GroupVoteHistoryRequest, HandleGroupVoteHistoryRequest);
  7071. AddLocalPacketHandler(PacketType.SimWideDeletes, HandleSimWideDeletes);
  7072. AddLocalPacketHandler(PacketType.SendPostcard, HandleSendPostcard);
  7073. AddLocalPacketHandler(PacketType.ChangeInventoryItemFlags, HandleChangeInventoryItemFlags);
  7074. AddLocalPacketHandler(PacketType.RevokePermissions, HandleRevokePermissions);
  7075. AddGenericPacketHandler("autopilot", HandleAutopilot);
  7076. }
  7077. #region Packet Handlers
  7078. public int TotalAgentUpdates { get; set; }
  7079. #region Scene/Avatar
  7080. // Threshold for body rotation to be a significant agent update
  7081. // use the abs of cos
  7082. private const float QDELTABody = 1.0f - 0.00001f;
  7083. private const float QDELTAHead = 1.0f - 0.00001f;
  7084. // Threshold for camera rotation to be a significant agent update
  7085. private const float VDELTA = 0.01f;
  7086. /// <summary>
  7087. /// This checks the update significance against the last update made.
  7088. /// </summary>
  7089. /// <remarks>Can only be called by one thread at a time</remarks>
  7090. /// <returns></returns>
  7091. /// <param name='x'></param>
  7092. public bool CheckAgentUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
  7093. {
  7094. return CheckAgentMovementUpdateSignificance(x) || CheckAgentCameraUpdateSignificance(x);
  7095. }
  7096. /// <summary>
  7097. /// This checks the movement/state update significance against the last update made.
  7098. /// </summary>
  7099. /// <remarks>Can only be called by one thread at a time</remarks>
  7100. /// <returns></returns>
  7101. /// <param name='x'></param>
  7102. private bool CheckAgentMovementUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
  7103. {
  7104. if(
  7105. (x.ControlFlags != m_thisAgentUpdateArgs.ControlFlags) // significant if control flags changed
  7106. // || ((x.ControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0 &&
  7107. // (x.ControlFlags & 0x3f8dfff) != 0) // we need to rotate the av on fly
  7108. || x.ControlFlags != (byte)AgentManager.ControlFlags.NONE// actually all movement controls need to pass
  7109. || (x.Flags != m_thisAgentUpdateArgs.Flags) // significant if Flags changed
  7110. || (x.State != m_thisAgentUpdateArgs.State) // significant if Stats changed
  7111. || (Math.Abs(x.Far - m_thisAgentUpdateArgs.Far) >= 32) // significant if far distance changed
  7112. )
  7113. return true;
  7114. float qdelta = Math.Abs(Quaternion.Dot(x.BodyRotation, m_thisAgentUpdateArgs.BodyRotation));
  7115. if(qdelta < QDELTABody) // significant if body rotation above(below cos) threshold
  7116. return true;
  7117. return false;
  7118. }
  7119. /// <summary>
  7120. /// This checks the camera update significance against the last update made.
  7121. /// </summary>
  7122. /// <remarks>Can only be called by one thread at a time</remarks>
  7123. /// <returns></returns>
  7124. /// <param name='x'></param>
  7125. private bool CheckAgentCameraUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
  7126. {
  7127. if(Math.Abs(x.CameraCenter.X - m_thisAgentUpdateArgs.CameraCenter.X) > VDELTA ||
  7128. Math.Abs(x.CameraCenter.Y - m_thisAgentUpdateArgs.CameraCenter.Y) > VDELTA ||
  7129. Math.Abs(x.CameraCenter.Z - m_thisAgentUpdateArgs.CameraCenter.Z) > VDELTA ||
  7130. Math.Abs(x.CameraAtAxis.X - m_thisAgentUpdateArgs.CameraAtAxis.X) > VDELTA ||
  7131. Math.Abs(x.CameraAtAxis.Y - m_thisAgentUpdateArgs.CameraAtAxis.Y) > VDELTA ||
  7132. // Math.Abs(x.CameraAtAxis.Z - m_thisAgentUpdateArgs.CameraAtAxis.Z) > VDELTA ||
  7133. Math.Abs(x.CameraLeftAxis.X - m_thisAgentUpdateArgs.CameraLeftAxis.X) > VDELTA ||
  7134. Math.Abs(x.CameraLeftAxis.Y - m_thisAgentUpdateArgs.CameraLeftAxis.Y) > VDELTA ||
  7135. // Math.Abs(x.CameraLeftAxis.Z - m_thisAgentUpdateArgs.CameraLeftAxis.Z) > VDELTA ||
  7136. Math.Abs(x.CameraUpAxis.X - m_thisAgentUpdateArgs.CameraUpAxis.X) > VDELTA ||
  7137. Math.Abs(x.CameraUpAxis.Y - m_thisAgentUpdateArgs.CameraUpAxis.Y) > VDELTA
  7138. // Math.Abs(x.CameraLeftAxis.Z - m_thisAgentUpdateArgs.CameraLeftAxis.Z) > VDELTA ||
  7139. )
  7140. return true;
  7141. return false;
  7142. }
  7143. private void HandleAgentUpdate(Packet packet)
  7144. {
  7145. if(OnAgentUpdate == null)
  7146. {
  7147. PacketPool.Instance.ReturnPacket(packet);
  7148. return;
  7149. }
  7150. AgentUpdatePacket agentUpdate = (AgentUpdatePacket)packet;
  7151. AgentUpdatePacket.AgentDataBlock x = agentUpdate.AgentData;
  7152. if (x.AgentID != AgentId || x.SessionID != SessionId)
  7153. {
  7154. PacketPool.Instance.ReturnPacket(packet);
  7155. return;
  7156. }
  7157. uint seq = packet.Header.Sequence;
  7158. TotalAgentUpdates++;
  7159. // dont let ignored updates pollute this throttles
  7160. if(SceneAgent == null || SceneAgent.IsChildAgent ||
  7161. SceneAgent.IsInTransit || seq <= m_thisAgentUpdateArgs.lastpacketSequence )
  7162. {
  7163. // throttle reset is done at MoveAgentIntoRegion()
  7164. // called by scenepresence on completemovement
  7165. PacketPool.Instance.ReturnPacket(packet);
  7166. return;
  7167. }
  7168. m_thisAgentUpdateArgs.lastpacketSequence = seq;
  7169. OnPreAgentUpdate?.Invoke(this, m_thisAgentUpdateArgs);
  7170. bool movement;
  7171. bool camera;
  7172. double now = Util.GetTimeStampMS();
  7173. if(now - m_thisAgentUpdateArgs.lastUpdateTS > 500.0) // at least 2 per sec
  7174. {
  7175. movement = true;
  7176. camera = true;
  7177. }
  7178. else
  7179. {
  7180. movement = CheckAgentMovementUpdateSignificance(x);
  7181. camera = CheckAgentCameraUpdateSignificance(x);
  7182. }
  7183. // Was there a significant movement/state change?
  7184. if (movement)
  7185. {
  7186. m_thisAgentUpdateArgs.BodyRotation = x.BodyRotation;
  7187. m_thisAgentUpdateArgs.ControlFlags = x.ControlFlags;
  7188. m_thisAgentUpdateArgs.Far = x.Far;
  7189. m_thisAgentUpdateArgs.Flags = x.Flags;
  7190. m_thisAgentUpdateArgs.HeadRotation = x.HeadRotation;
  7191. m_thisAgentUpdateArgs.State = x.State;
  7192. m_thisAgentUpdateArgs.NeedsCameraCollision = !camera;
  7193. OnAgentUpdate?.Invoke(this, m_thisAgentUpdateArgs);
  7194. }
  7195. // Was there a significant camera(s) change?
  7196. if (camera)
  7197. {
  7198. m_thisAgentUpdateArgs.CameraAtAxis = x.CameraAtAxis;
  7199. m_thisAgentUpdateArgs.CameraCenter = x.CameraCenter;
  7200. m_thisAgentUpdateArgs.CameraLeftAxis = x.CameraLeftAxis;
  7201. m_thisAgentUpdateArgs.CameraUpAxis = x.CameraUpAxis;
  7202. m_thisAgentUpdateArgs.NeedsCameraCollision = true;
  7203. OnAgentCameraUpdate?.Invoke(this, m_thisAgentUpdateArgs);
  7204. }
  7205. if(movement && camera)
  7206. m_thisAgentUpdateArgs.lastUpdateTS = now;
  7207. PacketPool.Instance.ReturnPacket(packet);
  7208. }
  7209. private void HandleMoneyTransferRequest(Packet Pack)
  7210. {
  7211. if(OnMoneyTransferRequest == null)
  7212. return;
  7213. MoneyTransferRequestPacket money = (MoneyTransferRequestPacket)Pack;
  7214. // validate the agent owns the agentID and sessionID
  7215. if (money.MoneyData.SourceID == AgentId && money.AgentData.AgentID == AgentId &&
  7216. money.AgentData.SessionID == SessionId)
  7217. {
  7218. OnMoneyTransferRequest?.Invoke(money.MoneyData.SourceID, money.MoneyData.DestID,
  7219. money.MoneyData.Amount, money.MoneyData.TransactionType,
  7220. Util.FieldToString(money.MoneyData.Description));
  7221. }
  7222. }
  7223. private void HandleParcelGodMarkAsContent(Packet packet)
  7224. {
  7225. if(OnParcelGodMark == null)
  7226. return;
  7227. ParcelGodMarkAsContentPacket ParcelGodMarkAsContent = (ParcelGodMarkAsContentPacket)packet;
  7228. if(SessionId != ParcelGodMarkAsContent.AgentData.SessionID || AgentId != ParcelGodMarkAsContent.AgentData.AgentID)
  7229. return;
  7230. OnParcelGodMark?.Invoke(this,
  7231. ParcelGodMarkAsContent.AgentData.AgentID,
  7232. ParcelGodMarkAsContent.ParcelData.LocalID);
  7233. }
  7234. private void HandleFreezeUser(Packet packet)
  7235. {
  7236. if(OnParcelFreezeUser == null)
  7237. return;
  7238. FreezeUserPacket FreezeUser = (FreezeUserPacket)packet;
  7239. if(SessionId != FreezeUser.AgentData.SessionID || AgentId != FreezeUser.AgentData.AgentID)
  7240. return;
  7241. OnParcelFreezeUser?.Invoke(this,
  7242. FreezeUser.AgentData.AgentID,
  7243. FreezeUser.Data.Flags,
  7244. FreezeUser.Data.TargetID);
  7245. }
  7246. private void HandleEjectUser(Packet packet)
  7247. {
  7248. if(OnParcelEjectUser == null)
  7249. return;
  7250. EjectUserPacket EjectUser = (EjectUserPacket)packet;
  7251. if(SessionId != EjectUser.AgentData.SessionID || AgentId != EjectUser.AgentData.AgentID)
  7252. return;
  7253. OnParcelEjectUser?.Invoke(this,
  7254. EjectUser.AgentData.AgentID,
  7255. EjectUser.Data.Flags,
  7256. EjectUser.Data.TargetID);
  7257. }
  7258. private void HandleParcelBuyPass(Packet packet)
  7259. {
  7260. if(OnParcelBuyPass == null)
  7261. return;
  7262. ParcelBuyPassPacket ParcelBuyPass = (ParcelBuyPassPacket)packet;
  7263. if(SessionId != ParcelBuyPass.AgentData.SessionID || AgentId != ParcelBuyPass.AgentData.AgentID)
  7264. return;
  7265. OnParcelBuyPass?.Invoke(this,
  7266. ParcelBuyPass.AgentData.AgentID,
  7267. ParcelBuyPass.ParcelData.LocalID);
  7268. }
  7269. private void HandleParcelBuyRequest(Packet Pack)
  7270. {
  7271. ParcelBuyPacket parcel = (ParcelBuyPacket)Pack;
  7272. if (parcel.AgentData.AgentID == AgentId && parcel.AgentData.SessionID == SessionId)
  7273. {
  7274. OnParcelBuy?.Invoke(parcel.AgentData.AgentID, parcel.Data.GroupID, parcel.Data.Final,
  7275. parcel.Data.IsGroupOwned,
  7276. parcel.Data.RemoveContribution, parcel.Data.LocalID, parcel.ParcelData.Area,
  7277. parcel.ParcelData.Price,
  7278. false);
  7279. }
  7280. }
  7281. private void HandleUUIDGroupNameRequest(Packet Pack)
  7282. {
  7283. if(OnUUIDGroupNameRequest == null)
  7284. return;
  7285. ScenePresence sp = (ScenePresence)SceneAgent;
  7286. if(sp == null || sp.IsDeleted || (sp.IsInTransit && !sp.IsInLocalTransit))
  7287. return;
  7288. UUIDGroupNameRequestPacket upack = (UUIDGroupNameRequestPacket)Pack;
  7289. for (int i = 0; i < upack.UUIDNameBlock.Length; i++)
  7290. {
  7291. OnUUIDGroupNameRequest?.Invoke(upack.UUIDNameBlock[i].ID, this);
  7292. }
  7293. }
  7294. public void HandleGenericMessage(Packet pack)
  7295. {
  7296. if (m_genericPacketHandlers.Count == 0)
  7297. return;
  7298. GenericMessagePacket gmpack = (GenericMessagePacket)pack;
  7299. if (gmpack.AgentData.SessionID != SessionId || gmpack.AgentData.AgentID != AgentId)
  7300. return;
  7301. string method = Util.FieldToString(gmpack.MethodData.Method).ToLower().Trim();
  7302. if (m_genericPacketHandlers.TryGetValue(method, out GenericMessage handlerGenericMessage))
  7303. {
  7304. List<string> msg = new List<string>();
  7305. List<byte[]> msgBytes = new List<byte[]>();
  7306. foreach (GenericMessagePacket.ParamListBlock block in gmpack.ParamList)
  7307. {
  7308. msg.Add(Util.FieldToString(block.Parameter));
  7309. msgBytes.Add(block.Parameter);
  7310. }
  7311. try
  7312. {
  7313. OnBinaryGenericMessage?.Invoke(this, method, msgBytes.ToArray());
  7314. handlerGenericMessage?.Invoke(this, method, msg);
  7315. }
  7316. catch (Exception e)
  7317. {
  7318. m_log.ErrorFormat(
  7319. "[LLCLIENTVIEW]: Exception when handling generic message {0}{1}", e.Message, e.StackTrace);
  7320. }
  7321. }
  7322. }
  7323. public void HandleObjectGroupRequest(Packet Pack)
  7324. {
  7325. if(OnObjectGroupRequest == null)
  7326. return;
  7327. ObjectGroupPacket ogpack = (ObjectGroupPacket)Pack;
  7328. if (ogpack.AgentData.SessionID != SessionId)
  7329. return;
  7330. for (int i = 0; i < ogpack.ObjectData.Length; i++)
  7331. {
  7332. OnObjectGroupRequest?.Invoke(this, ogpack.AgentData.GroupID, ogpack.ObjectData[i].ObjectLocalID, UUID.Zero);
  7333. }
  7334. }
  7335. private void HandleViewerEffect(Packet Pack)
  7336. {
  7337. if(OnViewerEffect == null)
  7338. return;
  7339. ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
  7340. if (viewer.AgentData.SessionID != SessionId || AgentId != viewer.AgentData.AgentID)
  7341. return;
  7342. int length = viewer.Effect.Length;
  7343. List<ViewerEffectEventHandlerArg> args = new List<ViewerEffectEventHandlerArg>(length);
  7344. for (int i = 0; i < length; i++)
  7345. {
  7346. //copy the effects block arguments into the event handler arg.
  7347. ViewerEffectEventHandlerArg argument = new ViewerEffectEventHandlerArg();
  7348. argument.AgentID = viewer.Effect[i].AgentID;
  7349. argument.Color = viewer.Effect[i].Color;
  7350. argument.Duration = viewer.Effect[i].Duration;
  7351. argument.ID = viewer.Effect[i].ID;
  7352. argument.Type = viewer.Effect[i].Type;
  7353. argument.TypeData = viewer.Effect[i].TypeData;
  7354. args.Add(argument);
  7355. }
  7356. OnViewerEffect?.Invoke(this, args);
  7357. }
  7358. private void HandleVelocityInterpolateOff(Packet Pack)
  7359. {
  7360. VelocityInterpolateOffPacket p = (VelocityInterpolateOffPacket)Pack;
  7361. if (p.AgentData.SessionID != SessionId || p.AgentData.AgentID != AgentId)
  7362. return ;
  7363. m_VelocityInterpolate = false;
  7364. }
  7365. private void HandleVelocityInterpolateOn(Packet Pack)
  7366. {
  7367. VelocityInterpolateOnPacket p = (VelocityInterpolateOnPacket)Pack;
  7368. if (p.AgentData.SessionID != SessionId || p.AgentData.AgentID != AgentId)
  7369. return;
  7370. m_VelocityInterpolate = true;
  7371. }
  7372. private void HandleAvatarPropertiesRequest(Packet Pack)
  7373. {
  7374. AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;
  7375. if (avatarProperties.AgentData.SessionID != SessionId || avatarProperties.AgentData.AgentID != AgentId)
  7376. return;
  7377. OnRequestAvatarProperties?.Invoke(this, avatarProperties.AgentData.AvatarID);
  7378. }
  7379. private void HandleChatFromViewer(Packet Pack)
  7380. {
  7381. if (OnChatFromClient == null)
  7382. return;
  7383. ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
  7384. if (inchatpack.AgentData.SessionID != SessionId || inchatpack.AgentData.AgentID != AgentId)
  7385. return;
  7386. string fromName = String.Empty; //ClientAvatar.firstname + " " + ClientAvatar.lastname;
  7387. byte[] message = inchatpack.ChatData.Message;
  7388. byte type = inchatpack.ChatData.Type;
  7389. Vector3 fromPos = new Vector3(); // ClientAvatar.Pos;
  7390. // UUID fromAgentID = AgentId;
  7391. int channel = inchatpack.ChatData.Channel;
  7392. OSChatMessage args = new OSChatMessage();
  7393. args.Channel = channel;
  7394. args.From = fromName;
  7395. args.Message = Utils.BytesToString(message);
  7396. args.Type = (ChatTypeEnum)type;
  7397. args.Position = fromPos;
  7398. args.Scene = Scene;
  7399. args.Sender = this;
  7400. args.SenderUUID = this.AgentId;
  7401. OnChatFromClient?.Invoke(this, args);
  7402. }
  7403. private void HandlerAvatarPropertiesUpdate(Packet Pack)
  7404. {
  7405. if (OnUpdateAvatarProperties == null)
  7406. return;
  7407. AvatarPropertiesUpdatePacket avatarProps = (AvatarPropertiesUpdatePacket)Pack;
  7408. if (avatarProps.AgentData.SessionID != SessionId || avatarProps.AgentData.AgentID != AgentId)
  7409. return;
  7410. AvatarPropertiesUpdatePacket.PropertiesDataBlock Properties = avatarProps.PropertiesData;
  7411. UserProfileData UserProfile = new UserProfileData();
  7412. UserProfile.ID = AgentId;
  7413. UserProfile.AboutText = Utils.BytesToString(Properties.AboutText);
  7414. UserProfile.FirstLifeAboutText = Utils.BytesToString(Properties.FLAboutText);
  7415. UserProfile.FirstLifeImage = Properties.FLImageID;
  7416. UserProfile.Image = Properties.ImageID;
  7417. UserProfile.ProfileUrl = Utils.BytesToString(Properties.ProfileURL);
  7418. UserProfile.UserFlags &= ~3;
  7419. UserProfile.UserFlags |= Properties.AllowPublish ? 1 : 0;
  7420. UserProfile.UserFlags |= Properties.MaturePublish ? 2 : 0;
  7421. OnUpdateAvatarProperties?.Invoke(this, UserProfile);
  7422. }
  7423. private void HandlerScriptDialogReply(Packet Pack)
  7424. {
  7425. if (OnChatFromClient == null)
  7426. return;
  7427. ScriptDialogReplyPacket rdialog = (ScriptDialogReplyPacket)Pack;
  7428. //m_log.DebugFormat("[CLIENT]: Received ScriptDialogReply from {0}", rdialog.Data.ObjectID);
  7429. if (rdialog.AgentData.SessionID != SessionId || rdialog.AgentData.AgentID != AgentId)
  7430. return;
  7431. int ch = rdialog.Data.ChatChannel;
  7432. byte[] msg = rdialog.Data.ButtonLabel;
  7433. OSChatMessage args = new OSChatMessage();
  7434. args.Channel = ch;
  7435. args.From = String.Empty;
  7436. args.Message = Utils.BytesToString(msg);
  7437. args.Type = ChatTypeEnum.Region; //Behaviour in SL is that the response can be heard from any distance
  7438. args.Position = new Vector3();
  7439. args.Scene = Scene;
  7440. args.Sender = this;
  7441. OnChatFromClient?.Invoke(this, args);
  7442. }
  7443. private void HandlerImprovedInstantMessage(Packet Pack)
  7444. {
  7445. if(OnInstantMessage == null)
  7446. return;
  7447. ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack;
  7448. if (msgpack.AgentData.SessionID != SessionId || msgpack.AgentData.AgentID != AgentId)
  7449. return;
  7450. string IMfromName = Util.FieldToString(msgpack.MessageBlock.FromAgentName);
  7451. string IMmessage = Utils.BytesToString(msgpack.MessageBlock.Message);
  7452. GridInstantMessage im = new GridInstantMessage(Scene,
  7453. msgpack.AgentData.AgentID,
  7454. IMfromName,
  7455. msgpack.MessageBlock.ToAgentID,
  7456. msgpack.MessageBlock.Dialog,
  7457. msgpack.MessageBlock.FromGroup,
  7458. IMmessage,
  7459. msgpack.MessageBlock.ID,
  7460. msgpack.MessageBlock.Offline != 0 ? true : false,
  7461. msgpack.MessageBlock.Position,
  7462. msgpack.MessageBlock.BinaryBucket,
  7463. true);
  7464. OnInstantMessage?.Invoke(this, im);
  7465. }
  7466. private void HandlerAcceptFriendship(Packet Pack)
  7467. {
  7468. if(OnApproveFriendRequest == null)
  7469. return;
  7470. AcceptFriendshipPacket afriendpack = (AcceptFriendshipPacket)Pack;
  7471. if (afriendpack.AgentData.SessionID != SessionId || afriendpack.AgentData.AgentID != AgentId)
  7472. return;
  7473. // My guess is this is the folder to stick the calling card into
  7474. List<UUID> callingCardFolders = new List<UUID>();
  7475. UUID transactionID = afriendpack.TransactionBlock.TransactionID;
  7476. for (int fi = 0; fi < afriendpack.FolderData.Length; fi++)
  7477. {
  7478. callingCardFolders.Add(afriendpack.FolderData[fi].FolderID);
  7479. }
  7480. OnApproveFriendRequest?.Invoke(this, transactionID, callingCardFolders);
  7481. }
  7482. private void HandlerDeclineFriendship(Packet Pack)
  7483. {
  7484. DeclineFriendshipPacket dfriendpack = (DeclineFriendshipPacket)Pack;
  7485. if (dfriendpack.AgentData.SessionID != SessionId || dfriendpack.AgentData.AgentID != AgentId)
  7486. return;
  7487. OnDenyFriendRequest?.Invoke(this,
  7488. dfriendpack.TransactionBlock.TransactionID,
  7489. null);
  7490. }
  7491. private void HandlerTerminateFriendship(Packet Pack)
  7492. {
  7493. TerminateFriendshipPacket tfriendpack = (TerminateFriendshipPacket)Pack;
  7494. if (tfriendpack.AgentData.SessionID != SessionId || tfriendpack.AgentData.AgentID != AgentId)
  7495. return;
  7496. UUID exFriendID = tfriendpack.ExBlock.OtherID;
  7497. FriendshipTermination TerminateFriendshipHandler = OnTerminateFriendship;
  7498. TerminateFriendshipHandler?.Invoke(this, exFriendID);
  7499. }
  7500. private void HandleFindAgent(Packet packet)
  7501. {
  7502. FindAgentPacket FindAgent = (FindAgentPacket)packet;
  7503. OnFindAgent?.Invoke(this,FindAgent.AgentBlock.Hunter,FindAgent.AgentBlock.Prey);
  7504. }
  7505. private void HandleTrackAgent(Packet packet)
  7506. {
  7507. TrackAgentPacket TrackAgent = (TrackAgentPacket)packet;
  7508. if(TrackAgent.AgentData.AgentID != AgentId || TrackAgent.AgentData.SessionID != SessionId)
  7509. return;
  7510. OnTrackAgent?.Invoke(this,
  7511. TrackAgent.AgentData.AgentID,
  7512. TrackAgent.TargetData.PreyID);
  7513. }
  7514. private void HandlerRezObject(Packet Pack)
  7515. {
  7516. RezObjectPacket rezPacket = (RezObjectPacket)Pack;
  7517. if (rezPacket.AgentData.SessionID != SessionId || rezPacket.AgentData.AgentID != AgentId)
  7518. return;
  7519. UUID rezGroupID = rezPacket.AgentData.GroupID;
  7520. if(!IsGroupMember(rezGroupID))
  7521. rezGroupID = UUID.Zero;
  7522. OnRezObject?.Invoke(this, rezPacket.InventoryData.ItemID, rezGroupID, rezPacket.RezData.RayEnd,
  7523. rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID,
  7524. rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection,
  7525. rezPacket.RezData.RezSelected, rezPacket.RezData.RemoveItem,
  7526. rezPacket.RezData.FromTaskID);
  7527. }
  7528. private class DeRezObjectInfo
  7529. {
  7530. public int count;
  7531. public List<uint> objectids;
  7532. }
  7533. private Dictionary<UUID, DeRezObjectInfo> m_DeRezObjectDelayed = new Dictionary<UUID, DeRezObjectInfo>();
  7534. private void HandlerDeRezObject(Packet Pack)
  7535. {
  7536. if (OnDeRezObject == null)
  7537. return;
  7538. DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)Pack;
  7539. if (DeRezPacket.AgentData.SessionID != SessionId || DeRezPacket.AgentData.AgentID != AgentId)
  7540. return;
  7541. List<uint> deRezIDs;
  7542. DeRezAction action = (DeRezAction)DeRezPacket.AgentBlock.Destination;
  7543. int numberPackets = DeRezPacket.AgentBlock.PacketCount;
  7544. int curPacket = DeRezPacket.AgentBlock.PacketNumber;
  7545. UUID id = DeRezPacket.AgentBlock.TransactionID;
  7546. if (numberPackets > 1)
  7547. {
  7548. DeRezObjectInfo info;
  7549. if (!m_DeRezObjectDelayed.TryGetValue(id, out info))
  7550. {
  7551. deRezIDs = new List<uint>();
  7552. info = new DeRezObjectInfo();
  7553. info.count = 0;
  7554. info.objectids = deRezIDs;
  7555. m_DeRezObjectDelayed[id] = info;
  7556. }
  7557. else
  7558. {
  7559. deRezIDs = info.objectids;
  7560. }
  7561. foreach (DeRezObjectPacket.ObjectDataBlock data in DeRezPacket.ObjectData)
  7562. {
  7563. deRezIDs.Add(data.ObjectLocalID);
  7564. }
  7565. info.count++;
  7566. if (info.count < numberPackets)
  7567. return;
  7568. m_DeRezObjectDelayed.Remove(id);
  7569. info.objectids = null;
  7570. }
  7571. else
  7572. {
  7573. deRezIDs = new List<uint>();
  7574. foreach (DeRezObjectPacket.ObjectDataBlock data in DeRezPacket.ObjectData)
  7575. {
  7576. deRezIDs.Add(data.ObjectLocalID);
  7577. }
  7578. }
  7579. OnDeRezObject?.Invoke(this, deRezIDs, DeRezPacket.AgentBlock.GroupID,
  7580. action, DeRezPacket.AgentBlock.DestinationID);
  7581. }
  7582. private void HandlerRezRestoreToWorld(Packet Pack)
  7583. {
  7584. RezRestoreToWorldPacket restore = (RezRestoreToWorldPacket)Pack;
  7585. if (restore.AgentData.SessionID != SessionId || restore.AgentData.AgentID != AgentId)
  7586. return;
  7587. OnRezRestoreToWorld?.Invoke(this, restore.InventoryData.ItemID);
  7588. }
  7589. private void HandlerModifyLand(Packet Pack)
  7590. {
  7591. if (OnModifyTerrain == null)
  7592. return;
  7593. ModifyLandPacket modify = (ModifyLandPacket)Pack;
  7594. if (modify.ParcelData.Length == 0)
  7595. return;
  7596. if (modify.AgentData.SessionID != SessionId || modify.AgentData.AgentID != AgentId)
  7597. return;
  7598. //m_log.Info("[LAND]: LAND:" + modify.ToString());
  7599. for (int i = 0; i < modify.ParcelData.Length; i++)
  7600. {
  7601. OnModifyTerrain?.Invoke(AgentId, modify.ModifyBlock.Height, modify.ModifyBlock.Seconds,
  7602. modify.ModifyBlockExtended[i].BrushSize, modify.ModifyBlock.Action,
  7603. modify.ParcelData[i].North, modify.ParcelData[i].West,
  7604. modify.ParcelData[i].South, modify.ParcelData[i].East,
  7605. modify.ParcelData[i].LocalID);
  7606. }
  7607. }
  7608. public uint m_viewerHandShakeFlags = 0;
  7609. private void HandlerRegionHandshakeReply(Packet Pack)
  7610. {
  7611. if (OnRegionHandShakeReply == null)
  7612. return; // silence the warning
  7613. RegionHandshakeReplyPacket rsrpkt = (RegionHandshakeReplyPacket)Pack;
  7614. if(rsrpkt.AgentData.AgentID != m_agentId || rsrpkt.AgentData.SessionID != m_sessionId)
  7615. return;
  7616. if(m_supportViewerCache)
  7617. m_viewerHandShakeFlags = rsrpkt.RegionInfo.Flags;
  7618. else
  7619. m_viewerHandShakeFlags = 0;
  7620. OnRegionHandShakeReply?.Invoke(this);
  7621. }
  7622. private void HandlerAgentWearablesRequest(Packet Pack)
  7623. {
  7624. OnRequestWearables?.Invoke(this);
  7625. OnRequestAvatarsData?.Invoke(this);
  7626. }
  7627. private void HandlerAgentSetAppearance(Packet Pack)
  7628. {
  7629. if(OnSetAppearance == null)
  7630. return;
  7631. AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
  7632. if (appear.AgentData.SessionID != SessionId || appear.AgentData.AgentID != AgentId)
  7633. return;
  7634. try
  7635. {
  7636. Vector3 avSize = appear.AgentData.Size;
  7637. byte[] visualparams = new byte[appear.VisualParam.Length];
  7638. for (int i = 0; i < appear.VisualParam.Length; i++)
  7639. visualparams[i] = appear.VisualParam[i].ParamValue;
  7640. //var b = appear.WearableData[0];
  7641. Primitive.TextureEntry te = null;
  7642. if (appear.ObjectData.TextureEntry.Length > 1)
  7643. te = new Primitive.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length);
  7644. WearableCacheItem[] cacheitems = new WearableCacheItem[appear.WearableData.Length];
  7645. for (int i=0; i<appear.WearableData.Length;i++)
  7646. cacheitems[i] = new WearableCacheItem(){
  7647. CacheId = appear.WearableData[i].CacheID,
  7648. TextureIndex=Convert.ToUInt32(appear.WearableData[i].TextureIndex)
  7649. };
  7650. OnSetAppearance?.Invoke(this, te, visualparams,avSize, cacheitems);
  7651. }
  7652. catch (Exception e)
  7653. {
  7654. m_log.ErrorFormat(
  7655. "[CLIENT VIEW]: AgentSetApperance packet handler threw an exception, {0}",
  7656. e);
  7657. }
  7658. }
  7659. private void HandlerAgentIsNowWearing(Packet Pack)
  7660. {
  7661. if (OnAvatarNowWearing == null)
  7662. return;
  7663. AgentIsNowWearingPacket nowWearing = (AgentIsNowWearingPacket)Pack;
  7664. if (nowWearing.AgentData.SessionID != SessionId || nowWearing.AgentData.AgentID != AgentId)
  7665. return;
  7666. AvatarWearingArgs wearingArgs = new AvatarWearingArgs();
  7667. for (int i = 0; i < nowWearing.WearableData.Length; i++)
  7668. {
  7669. //m_log.DebugFormat("[XXX]: Wearable type {0} item {1}", nowWearing.WearableData[i].WearableType, nowWearing.WearableData[i].ItemID);
  7670. AvatarWearingArgs.Wearable wearable =
  7671. new AvatarWearingArgs.Wearable(nowWearing.WearableData[i].ItemID,
  7672. nowWearing.WearableData[i].WearableType);
  7673. wearingArgs.NowWearing.Add(wearable);
  7674. }
  7675. OnAvatarNowWearing?.Invoke(this, wearingArgs);
  7676. }
  7677. private void HandlerRezSingleAttachmentFromInv(Packet Pack)
  7678. {
  7679. RezSingleAttachmentFromInvPacket rez = (RezSingleAttachmentFromInvPacket)Pack;
  7680. if (rez.AgentData.SessionID != SessionId || rez.AgentData.AgentID != AgentId)
  7681. return;
  7682. OnRezSingleAttachmentFromInv?.Invoke(this, rez.ObjectData.ItemID,
  7683. rez.ObjectData.AttachmentPt);
  7684. }
  7685. private void HandleRezMultipleAttachmentsFromInv(Packet Pack)
  7686. {
  7687. if(OnRezMultipleAttachmentsFromInv == null)
  7688. return;
  7689. RezMultipleAttachmentsFromInvPacket rez = (RezMultipleAttachmentsFromInvPacket)Pack;
  7690. if (rez.AgentData.SessionID != SessionId || rez.AgentData.AgentID != AgentId)
  7691. return;
  7692. List<KeyValuePair<UUID, uint>> rezlist = new List<KeyValuePair<UUID, uint>>();
  7693. foreach (RezMultipleAttachmentsFromInvPacket.ObjectDataBlock obj in rez.ObjectData)
  7694. rezlist.Add(new KeyValuePair<UUID, uint>(obj.ItemID, obj.AttachmentPt));
  7695. OnRezMultipleAttachmentsFromInv?.Invoke(this, rezlist);
  7696. }
  7697. private void HandleDetachAttachmentIntoInv(Packet Pack)
  7698. {
  7699. if (OnDetachAttachmentIntoInv == null)
  7700. return;
  7701. DetachAttachmentIntoInvPacket detachtoInv = (DetachAttachmentIntoInvPacket)Pack;
  7702. if(detachtoInv.ObjectData.AgentID != AgentId)
  7703. return;
  7704. OnDetachAttachmentIntoInv?.Invoke(detachtoInv.ObjectData.ItemID, this);
  7705. }
  7706. private void HandleObjectAttach(Packet Pack)
  7707. {
  7708. if (OnObjectAttach == null)
  7709. return;
  7710. ObjectAttachPacket att = (ObjectAttachPacket)Pack;
  7711. if (att.AgentData.SessionID != SessionId || att.AgentData.AgentID != AgentId)
  7712. return;
  7713. if (att.ObjectData.Length > 0)
  7714. OnObjectAttach?.Invoke(this, att.ObjectData[0].ObjectLocalID, att.AgentData.AttachmentPoint, false);
  7715. }
  7716. private void HandleObjectDetach(Packet Pack)
  7717. {
  7718. if(OnObjectDetach == null)
  7719. return;
  7720. ObjectDetachPacket dett = (ObjectDetachPacket)Pack;
  7721. if (dett.AgentData.SessionID != SessionId || dett.AgentData.AgentID != AgentId)
  7722. return;
  7723. for (int j = 0; j < dett.ObjectData.Length; j++)
  7724. {
  7725. uint obj = dett.ObjectData[j].ObjectLocalID;
  7726. OnObjectDetach?.Invoke(obj, this);
  7727. }
  7728. }
  7729. private void HandleObjectDrop(Packet Pack)
  7730. {
  7731. if(OnObjectDrop == null)
  7732. return;
  7733. ObjectDropPacket dropp = (ObjectDropPacket)Pack;
  7734. if (dropp.AgentData.SessionID != SessionId || dropp.AgentData.AgentID != AgentId)
  7735. return;
  7736. for (int j = 0; j < dropp.ObjectData.Length; j++)
  7737. {
  7738. uint obj = dropp.ObjectData[j].ObjectLocalID;
  7739. OnObjectDrop?.Invoke(obj, this);
  7740. }
  7741. }
  7742. private void HandleSetAlwaysRun(Packet Pack)
  7743. {
  7744. SetAlwaysRunPacket run = (SetAlwaysRunPacket)Pack;
  7745. if (run.AgentData.SessionID != SessionId || run.AgentData.AgentID != AgentId)
  7746. return;
  7747. OnSetAlwaysRun?.Invoke(this, run.AgentData.AlwaysRun);
  7748. }
  7749. private void HandleCompleteAgentMovement(Packet Pack)
  7750. {
  7751. //m_log.DebugFormat("[LLClientView] HandleCompleteAgentMovement");
  7752. CompleteAgentMovementPacket cmp = (CompleteAgentMovementPacket)Pack;
  7753. if(cmp.AgentData.AgentID != m_agentId || cmp.AgentData.SessionID != m_sessionId || cmp.AgentData.CircuitCode != m_circuitCode)
  7754. return;
  7755. OnCompleteMovementToRegion?.Invoke(this, true);
  7756. }
  7757. private void HandleAgentAnimation(Packet Pack)
  7758. {
  7759. if(OnChangeAnim == null)
  7760. return;
  7761. AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
  7762. if (AgentAni.AgentData.SessionID != SessionId || AgentAni.AgentData.AgentID != AgentId)
  7763. return;
  7764. for (int i = 0; i < AgentAni.AnimationList.Length; i++)
  7765. OnChangeAnim?.Invoke(AgentAni.AnimationList[i].AnimID, AgentAni.AnimationList[i].StartAnim, false);
  7766. OnChangeAnim?.Invoke(UUID.Zero, false, true);
  7767. }
  7768. private void HandleAgentRequestSit(Packet Pack)
  7769. {
  7770. if (OnAgentRequestSit == null)
  7771. return;
  7772. AgentRequestSitPacket agentRequestSit = (AgentRequestSitPacket)Pack;
  7773. if (agentRequestSit.AgentData.SessionID != SessionId || agentRequestSit.AgentData.AgentID != AgentId)
  7774. return;
  7775. if (SceneAgent.IsChildAgent)
  7776. {
  7777. SendCantSitBecauseChildAgentResponse();
  7778. return;
  7779. }
  7780. OnAgentRequestSit?.Invoke(this, agentRequestSit.AgentData.AgentID,
  7781. agentRequestSit.TargetObject.TargetID, agentRequestSit.TargetObject.Offset);
  7782. }
  7783. private void HandleAgentSit(Packet Pack)
  7784. {
  7785. if (OnAgentSit == null)
  7786. return;
  7787. AgentSitPacket agentSit = (AgentSitPacket)Pack;
  7788. if (agentSit.AgentData.SessionID != SessionId || agentSit.AgentData.AgentID != AgentId)
  7789. return;
  7790. if (SceneAgent.IsChildAgent)
  7791. {
  7792. SendCantSitBecauseChildAgentResponse();
  7793. return;
  7794. }
  7795. OnAgentSit?.Invoke(this, agentSit.AgentData.AgentID);
  7796. }
  7797. /// <summary>
  7798. /// Used when a child agent gets a sit response which should not be fulfilled.
  7799. /// </summary>
  7800. private void SendCantSitBecauseChildAgentResponse()
  7801. {
  7802. SendAlertMessage("Try moving closer. Can't sit on object because it is not in the same region as you.");
  7803. }
  7804. private void HandleSoundTrigger(Packet Pack)
  7805. {
  7806. SoundTriggerPacket soundTriggerPacket = (SoundTriggerPacket)Pack;
  7807. // UUIDS are sent as zeroes by the client, substitute agent's id
  7808. OnSoundTrigger?.Invoke(soundTriggerPacket.SoundData.SoundID, AgentId,
  7809. AgentId, AgentId,
  7810. soundTriggerPacket.SoundData.Gain, soundTriggerPacket.SoundData.Position,
  7811. soundTriggerPacket.SoundData.Handle);
  7812. }
  7813. private void HandleAvatarPickerRequest(Packet Pack)
  7814. {
  7815. AvatarPickerRequestPacket avRequestQuery = (AvatarPickerRequestPacket)Pack;
  7816. if (avRequestQuery.AgentData.SessionID != SessionId || avRequestQuery.AgentData.AgentID != AgentId)
  7817. return;
  7818. AvatarPickerRequestPacket.AgentDataBlock Requestdata = avRequestQuery.AgentData;
  7819. AvatarPickerRequestPacket.DataBlock querydata = avRequestQuery.Data;
  7820. //m_log.Debug("Agent Sends:" + Utils.BytesToString(querydata.Name));
  7821. OnAvatarPickerRequest?.Invoke(this, Requestdata.AgentID, Requestdata.QueryID,
  7822. Utils.BytesToString(querydata.Name));
  7823. }
  7824. private void HandleAgentDataUpdateRequest(Packet Pack)
  7825. {
  7826. AgentDataUpdateRequestPacket avRequestDataUpdatePacket = (AgentDataUpdateRequestPacket)Pack;
  7827. if (avRequestDataUpdatePacket.AgentData.SessionID != SessionId || avRequestDataUpdatePacket.AgentData.AgentID != AgentId)
  7828. return;
  7829. OnAgentDataUpdateRequest?.Invoke(this, avRequestDataUpdatePacket.AgentData.AgentID, avRequestDataUpdatePacket.AgentData.SessionID);
  7830. }
  7831. private void HandleUserInfoRequest(Packet Pack)
  7832. {
  7833. if (OnUserInfoRequest != null)
  7834. {
  7835. OnUserInfoRequest(this);
  7836. }
  7837. else
  7838. {
  7839. SendUserInfoReply(false, true, "");
  7840. }
  7841. }
  7842. private void HandleUpdateUserInfo(Packet Pack)
  7843. {
  7844. if(OnUpdateUserInfo == null)
  7845. return;
  7846. UpdateUserInfoPacket updateUserInfo = (UpdateUserInfoPacket)Pack;
  7847. if (updateUserInfo.AgentData.SessionID != SessionId || updateUserInfo.AgentData.AgentID != AgentId)
  7848. return;
  7849. bool visible = true;
  7850. string DirectoryVisibility = Utils.BytesToString(updateUserInfo.UserData.DirectoryVisibility);
  7851. if (DirectoryVisibility == "hidden")
  7852. visible = false;
  7853. OnUpdateUserInfo?.Invoke( updateUserInfo.UserData.IMViaEMail, visible, this);
  7854. }
  7855. private void HandleSetStartLocationRequest(Packet Pack)
  7856. {
  7857. SetStartLocationRequestPacket avSetStartLocationRequestPacket = (SetStartLocationRequestPacket)Pack;
  7858. if (avSetStartLocationRequestPacket.AgentData.SessionID != SessionId ||
  7859. avSetStartLocationRequestPacket.AgentData.AgentID != AgentId)
  7860. return;
  7861. float packX = avSetStartLocationRequestPacket.StartLocationData.LocationPos.X;
  7862. float packY = avSetStartLocationRequestPacket.StartLocationData.LocationPos.Y;
  7863. // Linden Client limitation..
  7864. if (packX == 255.5f || packY == 255.5f)
  7865. {
  7866. ScenePresence avatar = null;
  7867. if (((Scene)m_scene).TryGetScenePresence(AgentId, out avatar))
  7868. {
  7869. if (packX == 255.5f)
  7870. {
  7871. avSetStartLocationRequestPacket.StartLocationData.LocationPos.X = avatar.AbsolutePosition.X;
  7872. }
  7873. if (packY == 255.5f)
  7874. {
  7875. avSetStartLocationRequestPacket.StartLocationData.LocationPos.Y = avatar.AbsolutePosition.Y;
  7876. }
  7877. }
  7878. }
  7879. OnSetStartLocationRequest?.Invoke(this, 0, avSetStartLocationRequestPacket.StartLocationData.LocationPos,
  7880. avSetStartLocationRequestPacket.StartLocationData.LocationLookAt,
  7881. avSetStartLocationRequestPacket.StartLocationData.LocationID);
  7882. }
  7883. private void HandleAgentThrottle(Packet Pack)
  7884. {
  7885. AgentThrottlePacket atpack = (AgentThrottlePacket)Pack;
  7886. if (atpack.AgentData.SessionID != SessionId || atpack.AgentData.AgentID != AgentId)
  7887. return;
  7888. m_udpClient.SetThrottles(atpack.Throttle.Throttles);
  7889. OnUpdateThrottles?.Invoke();
  7890. }
  7891. private void HandleAgentPause(Packet Pack)
  7892. {
  7893. m_udpClient.IsPaused = true;
  7894. }
  7895. private void HandleAgentResume(Packet Pack)
  7896. {
  7897. m_udpClient.IsPaused = false;
  7898. m_udpServer.SendPing(m_udpClient);
  7899. }
  7900. private void HandleForceScriptControlRelease(Packet Pack)
  7901. {
  7902. OnForceReleaseControls?.Invoke(this, AgentId);
  7903. }
  7904. #endregion Scene/Avatar
  7905. #region Objects/m_sceneObjects
  7906. private void HandleObjectLink(Packet Pack)
  7907. {
  7908. ObjectLinkPacket link = (ObjectLinkPacket)Pack;
  7909. if (link.AgentData.SessionID != SessionId || link.AgentData.AgentID != AgentId)
  7910. return;
  7911. uint parentprimid = 0;
  7912. List<uint> childrenprims = new List<uint>();
  7913. if (link.ObjectData.Length > 1)
  7914. {
  7915. parentprimid = link.ObjectData[0].ObjectLocalID;
  7916. for (int i = 1; i < link.ObjectData.Length; i++)
  7917. {
  7918. childrenprims.Add(link.ObjectData[i].ObjectLocalID);
  7919. }
  7920. }
  7921. OnLinkObjects?.Invoke(this, parentprimid, childrenprims);
  7922. }
  7923. private void HandleObjectDelink(Packet Pack)
  7924. {
  7925. ObjectDelinkPacket delink = (ObjectDelinkPacket)Pack;
  7926. if (delink.AgentData.SessionID != SessionId || delink.AgentData.AgentID != AgentId)
  7927. return;
  7928. // It appears the prim at index 0 is not always the root prim (for
  7929. // instance, when one prim of a link set has been edited independently
  7930. // of the others). Therefore, we'll pass all the ids onto the delink
  7931. // method for it to decide which is the root.
  7932. List<uint> prims = new List<uint>();
  7933. for (int i = 0; i < delink.ObjectData.Length; i++)
  7934. {
  7935. prims.Add(delink.ObjectData[i].ObjectLocalID);
  7936. }
  7937. OnDelinkObjects?.Invoke(prims, this);
  7938. }
  7939. private void HandleObjectAdd(Packet Pack)
  7940. {
  7941. ObjectAddPacket addPacket = (ObjectAddPacket)Pack;
  7942. if (addPacket.AgentData.SessionID != SessionId || addPacket.AgentData.AgentID != AgentId)
  7943. return;
  7944. ObjectAddPacket.ObjectDataBlock datablk = addPacket.ObjectData;
  7945. PrimitiveBaseShape shape = GetShapeFromAddPacket(addPacket);
  7946. OnAddPrim?.Invoke(AgentId, addPacket.AgentData.GroupID, datablk.RayEnd,
  7947. datablk.Rotation, shape,
  7948. datablk.BypassRaycast, datablk.RayStart, datablk.RayTargetID, datablk.RayEndIsIntersection,
  7949. datablk.AddFlags);
  7950. }
  7951. private void HandleObjectShape(Packet Pack)
  7952. {
  7953. if(OnUpdatePrimShape == null)
  7954. return;
  7955. ObjectShapePacket shapePacket = (ObjectShapePacket)Pack;
  7956. if (shapePacket.AgentData.SessionID != SessionId || shapePacket.AgentData.AgentID != AgentId)
  7957. return;
  7958. for (int i = 0; i < shapePacket.ObjectData.Length; i++)
  7959. {
  7960. UpdateShapeArgs shapeData = new UpdateShapeArgs();
  7961. uint id = shapePacket.ObjectData[i].ObjectLocalID;
  7962. shapeData.ObjectLocalID = id;
  7963. shapeData.PathBegin = shapePacket.ObjectData[i].PathBegin;
  7964. shapeData.PathCurve = shapePacket.ObjectData[i].PathCurve;
  7965. shapeData.PathEnd = shapePacket.ObjectData[i].PathEnd;
  7966. shapeData.PathRadiusOffset = shapePacket.ObjectData[i].PathRadiusOffset;
  7967. shapeData.PathRevolutions = shapePacket.ObjectData[i].PathRevolutions;
  7968. shapeData.PathScaleX = shapePacket.ObjectData[i].PathScaleX;
  7969. shapeData.PathScaleY = shapePacket.ObjectData[i].PathScaleY;
  7970. shapeData.PathShearX = shapePacket.ObjectData[i].PathShearX;
  7971. shapeData.PathShearY = shapePacket.ObjectData[i].PathShearY;
  7972. shapeData.PathSkew = shapePacket.ObjectData[i].PathSkew;
  7973. shapeData.PathTaperX = shapePacket.ObjectData[i].PathTaperX;
  7974. shapeData.PathTaperY = shapePacket.ObjectData[i].PathTaperY;
  7975. shapeData.PathTwist = shapePacket.ObjectData[i].PathTwist;
  7976. shapeData.PathTwistBegin = shapePacket.ObjectData[i].PathTwistBegin;
  7977. shapeData.ProfileBegin = shapePacket.ObjectData[i].ProfileBegin;
  7978. shapeData.ProfileCurve = shapePacket.ObjectData[i].ProfileCurve;
  7979. shapeData.ProfileEnd = shapePacket.ObjectData[i].ProfileEnd;
  7980. shapeData.ProfileHollow = shapePacket.ObjectData[i].ProfileHollow;
  7981. OnUpdatePrimShape?.Invoke(m_agentId, id, shapeData);
  7982. }
  7983. }
  7984. private void HandleObjectExtraParams(Packet Pack)
  7985. {
  7986. ObjectExtraParamsPacket extraPar = (ObjectExtraParamsPacket)Pack;
  7987. if (extraPar.AgentData.SessionID != SessionId || extraPar.AgentData.AgentID != AgentId)
  7988. return;
  7989. ObjectExtraParams handlerUpdateExtraParams = OnUpdateExtraParams;
  7990. if (handlerUpdateExtraParams != null)
  7991. {
  7992. for (int i = 0; i < extraPar.ObjectData.Length; i++)
  7993. {
  7994. OnUpdateExtraParams?.Invoke(m_agentId, extraPar.ObjectData[i].ObjectLocalID,
  7995. extraPar.ObjectData[i].ParamType,
  7996. extraPar.ObjectData[i].ParamInUse, extraPar.ObjectData[i].ParamData);
  7997. }
  7998. }
  7999. }
  8000. private void HandleObjectDuplicate(Packet Pack)
  8001. {
  8002. if(OnObjectDuplicate == null)
  8003. return;
  8004. ObjectDuplicatePacket dupe = (ObjectDuplicatePacket)Pack;
  8005. if (dupe.AgentData.SessionID != SessionId || dupe.AgentData.AgentID != AgentId)
  8006. return;
  8007. // ObjectDuplicatePacket.AgentDataBlock AgentandGroupData = dupe.AgentData;
  8008. for (int i = 0; i < dupe.ObjectData.Length; i++)
  8009. {
  8010. UUID rezGroupID = dupe.AgentData.GroupID;
  8011. if(!IsGroupMember(rezGroupID))
  8012. rezGroupID = UUID.Zero;
  8013. OnObjectDuplicate?.Invoke(dupe.ObjectData[i].ObjectLocalID, dupe.SharedData.Offset,
  8014. dupe.SharedData.DuplicateFlags, AgentId,
  8015. rezGroupID);
  8016. }
  8017. }
  8018. private void HandleRequestMultipleObjects(Packet Pack)
  8019. {
  8020. if (OnObjectRequest == null)
  8021. return;
  8022. RequestMultipleObjectsPacket incomingRequest = (RequestMultipleObjectsPacket)Pack;
  8023. if (incomingRequest.AgentData.SessionID != SessionId || incomingRequest.AgentData.AgentID != AgentId)
  8024. return;
  8025. for (int i = 0; i < incomingRequest.ObjectData.Length; i++)
  8026. OnObjectRequest?.Invoke(incomingRequest.ObjectData[i].ID, this);
  8027. }
  8028. private void HandleObjectSelect(Packet Pack)
  8029. {
  8030. if(OnObjectSelect == null)
  8031. return;
  8032. ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
  8033. if (incomingselect.AgentData.SessionID != SessionId || incomingselect.AgentData.AgentID != AgentId)
  8034. return;
  8035. List<uint> thisSelection = new List<uint>();
  8036. for (int i = 0; i < incomingselect.ObjectData.Length; i++)
  8037. thisSelection.Add(incomingselect.ObjectData[i].ObjectLocalID);
  8038. OnObjectSelect?.Invoke(thisSelection, this);
  8039. }
  8040. private void HandleObjectDeselect(Packet Pack)
  8041. {
  8042. if(OnObjectDeselect == null)
  8043. return;
  8044. ObjectDeselectPacket incomingdeselect = (ObjectDeselectPacket)Pack;
  8045. if (incomingdeselect.AgentData.SessionID != SessionId || incomingdeselect.AgentData.AgentID != AgentId)
  8046. return;
  8047. for (int i = 0; i < incomingdeselect.ObjectData.Length; i++)
  8048. {
  8049. OnObjectDeselect?.Invoke(incomingdeselect.ObjectData[i].ObjectLocalID, this);
  8050. }
  8051. }
  8052. private void HandleObjectPosition(Packet Pack)
  8053. {
  8054. if (OnUpdatePrimGroupPosition == null)
  8055. return;
  8056. // DEPRECATED: but till libsecondlife removes it, people will use it
  8057. ObjectPositionPacket position = (ObjectPositionPacket)Pack;
  8058. if (position.AgentData.SessionID != SessionId || position.AgentData.AgentID != AgentId)
  8059. return;
  8060. for (int i = 0; i < position.ObjectData.Length; i++)
  8061. OnUpdatePrimGroupPosition?.Invoke(position.ObjectData[i].ObjectLocalID, position.ObjectData[i].Position, this);
  8062. }
  8063. private void HandleObjectScale(Packet Pack)
  8064. {
  8065. if (OnUpdatePrimGroupScale == null)
  8066. return;
  8067. // DEPRECATED: but till libsecondlife removes it, people will use it
  8068. ObjectScalePacket scale = (ObjectScalePacket)Pack;
  8069. if (scale.AgentData.SessionID != SessionId || scale.AgentData.AgentID != AgentId)
  8070. return;
  8071. for (int i = 0; i < scale.ObjectData.Length; i++)
  8072. OnUpdatePrimGroupScale?.Invoke(scale.ObjectData[i].ObjectLocalID, scale.ObjectData[i].Scale, this);
  8073. }
  8074. private void HandleObjectRotation(Packet Pack)
  8075. {
  8076. if (OnUpdatePrimGroupRotation == null)
  8077. return;
  8078. // DEPRECATED: but till libsecondlife removes it, people will use it
  8079. ObjectRotationPacket rotation = (ObjectRotationPacket)Pack;
  8080. if (rotation.AgentData.SessionID != SessionId || rotation.AgentData.AgentID != AgentId)
  8081. return;
  8082. for (int i = 0; i < rotation.ObjectData.Length; i++)
  8083. OnUpdatePrimGroupRotation?.Invoke(rotation.ObjectData[i].ObjectLocalID, rotation.ObjectData[i].Rotation, this);
  8084. }
  8085. private void HandleObjectFlagUpdate(Packet Pack)
  8086. {
  8087. if(OnUpdatePrimFlags == null)
  8088. return;
  8089. ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
  8090. if (flags.AgentData.SessionID != SessionId || flags.AgentData.AgentID != AgentId)
  8091. return;
  8092. // byte[] data = Pack.ToBytes();
  8093. // 46,47,48 are special positions within the packet
  8094. // This may change so perhaps we need a better way
  8095. // of storing this (OMV.FlagUpdatePacket.UsePhysics,etc?)
  8096. /*
  8097. bool UsePhysics = (data[46] != 0) ? true : false;
  8098. bool IsTemporary = (data[47] != 0) ? true : false;
  8099. bool IsPhantom = (data[48] != 0) ? true : false;
  8100. handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, this);
  8101. */
  8102. bool UsePhysics = flags.AgentData.UsePhysics;
  8103. bool IsPhantom = flags.AgentData.IsPhantom;
  8104. bool IsTemporary = flags.AgentData.IsTemporary;
  8105. ObjectFlagUpdatePacket.ExtraPhysicsBlock[] blocks = flags.ExtraPhysics;
  8106. ExtraPhysicsData physdata = new ExtraPhysicsData();
  8107. if (blocks == null || blocks.Length == 0)
  8108. {
  8109. physdata.PhysShapeType = PhysShapeType.invalid;
  8110. }
  8111. else
  8112. {
  8113. ObjectFlagUpdatePacket.ExtraPhysicsBlock phsblock = blocks[0];
  8114. physdata.PhysShapeType = (PhysShapeType)phsblock.PhysicsShapeType;
  8115. physdata.Bounce = phsblock.Restitution;
  8116. physdata.Density = phsblock.Density;
  8117. physdata.Friction = phsblock.Friction;
  8118. physdata.GravitationModifier = phsblock.GravityMultiplier;
  8119. }
  8120. OnUpdatePrimFlags?.Invoke(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, physdata, this);
  8121. }
  8122. Dictionary<uint, uint> objImageSeqs = null;
  8123. double lastobjImageSeqsMS = 0.0;
  8124. private void HandleObjectImage(Packet Pack)
  8125. {
  8126. if (OnUpdatePrimTexture == null)
  8127. return;
  8128. ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
  8129. if (imagePack.AgentData.SessionID != SessionId || imagePack.AgentData.AgentID != AgentId)
  8130. return;
  8131. double now = Util.GetTimeStampMS();
  8132. if(objImageSeqs == null || ( now - lastobjImageSeqsMS > 30000.0))
  8133. {
  8134. objImageSeqs = null; // yeah i know superstition...
  8135. objImageSeqs = new Dictionary<uint, uint>(16);
  8136. }
  8137. lastobjImageSeqsMS = now;
  8138. uint seq = Pack.Header.Sequence;
  8139. uint id;
  8140. uint lastseq;
  8141. ObjectImagePacket.ObjectDataBlock o;
  8142. for (int i = 0; i < imagePack.ObjectData.Length; i++)
  8143. {
  8144. o = imagePack.ObjectData[i];
  8145. id = o.ObjectLocalID;
  8146. if(objImageSeqs.TryGetValue(id, out lastseq))
  8147. {
  8148. if(seq <= lastseq)
  8149. continue;
  8150. }
  8151. objImageSeqs[id] = seq;
  8152. OnUpdatePrimTexture?.Invoke(id, o.TextureEntry, this);
  8153. }
  8154. }
  8155. private void HandleObjectGrab(Packet Pack)
  8156. {
  8157. if(OnGrabObject == null)
  8158. return;
  8159. ObjectGrabPacket grab = (ObjectGrabPacket)Pack;
  8160. if (grab.AgentData.SessionID != SessionId || grab.AgentData.AgentID != AgentId)
  8161. return;
  8162. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  8163. if ((grab.SurfaceInfo != null) && (grab.SurfaceInfo.Length > 0))
  8164. {
  8165. foreach (ObjectGrabPacket.SurfaceInfoBlock surfaceInfo in grab.SurfaceInfo)
  8166. {
  8167. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  8168. arg.Binormal = surfaceInfo.Binormal;
  8169. arg.FaceIndex = surfaceInfo.FaceIndex;
  8170. arg.Normal = surfaceInfo.Normal;
  8171. arg.Position = surfaceInfo.Position;
  8172. arg.STCoord = surfaceInfo.STCoord;
  8173. arg.UVCoord = surfaceInfo.UVCoord;
  8174. touchArgs.Add(arg);
  8175. }
  8176. }
  8177. OnGrabObject?.Invoke(grab.ObjectData.LocalID, grab.ObjectData.GrabOffset, this, touchArgs);
  8178. }
  8179. private void HandleObjectGrabUpdate(Packet Pack)
  8180. {
  8181. if (OnGrabUpdate == null)
  8182. return;
  8183. ObjectGrabUpdatePacket grabUpdate = (ObjectGrabUpdatePacket)Pack;
  8184. if (grabUpdate.AgentData.SessionID != SessionId || grabUpdate.AgentData.AgentID != AgentId)
  8185. return;
  8186. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  8187. if ((grabUpdate.SurfaceInfo != null) && (grabUpdate.SurfaceInfo.Length > 0))
  8188. {
  8189. foreach (ObjectGrabUpdatePacket.SurfaceInfoBlock surfaceInfo in grabUpdate.SurfaceInfo)
  8190. {
  8191. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  8192. arg.Binormal = surfaceInfo.Binormal;
  8193. arg.FaceIndex = surfaceInfo.FaceIndex;
  8194. arg.Normal = surfaceInfo.Normal;
  8195. arg.Position = surfaceInfo.Position;
  8196. arg.STCoord = surfaceInfo.STCoord;
  8197. arg.UVCoord = surfaceInfo.UVCoord;
  8198. touchArgs.Add(arg);
  8199. }
  8200. }
  8201. OnGrabUpdate?.Invoke(grabUpdate.ObjectData.ObjectID, grabUpdate.ObjectData.GrabOffsetInitial,
  8202. grabUpdate.ObjectData.GrabPosition, this, touchArgs);
  8203. }
  8204. private void HandleObjectDeGrab(Packet Pack)
  8205. {
  8206. if (OnDeGrabObject == null)
  8207. return;
  8208. ObjectDeGrabPacket deGrab = (ObjectDeGrabPacket)Pack;
  8209. if (deGrab.AgentData.SessionID != SessionId || deGrab.AgentData.AgentID != AgentId)
  8210. return;
  8211. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  8212. if ((deGrab.SurfaceInfo != null) && (deGrab.SurfaceInfo.Length > 0))
  8213. {
  8214. foreach (ObjectDeGrabPacket.SurfaceInfoBlock surfaceInfo in deGrab.SurfaceInfo)
  8215. {
  8216. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  8217. arg.Binormal = surfaceInfo.Binormal;
  8218. arg.FaceIndex = surfaceInfo.FaceIndex;
  8219. arg.Normal = surfaceInfo.Normal;
  8220. arg.Position = surfaceInfo.Position;
  8221. arg.STCoord = surfaceInfo.STCoord;
  8222. arg.UVCoord = surfaceInfo.UVCoord;
  8223. touchArgs.Add(arg);
  8224. }
  8225. }
  8226. OnDeGrabObject?.Invoke(deGrab.ObjectData.LocalID, this, touchArgs);
  8227. }
  8228. private void HandleObjectSpinStart(Packet Pack)
  8229. {
  8230. //m_log.Warn("[CLIENT]: unhandled ObjectSpinStart packet");
  8231. ObjectSpinStartPacket spinStart = (ObjectSpinStartPacket)Pack;
  8232. if (spinStart.AgentData.SessionID != SessionId || spinStart.AgentData.AgentID != AgentId)
  8233. return;
  8234. OnSpinStart?.Invoke(spinStart.ObjectData.ObjectID, this);
  8235. }
  8236. private void HandleObjectSpinUpdate(Packet Pack)
  8237. {
  8238. //m_log.Warn("[CLIENT]: unhandled ObjectSpinUpdate packet");
  8239. ObjectSpinUpdatePacket spinUpdate = (ObjectSpinUpdatePacket)Pack;
  8240. if (spinUpdate.AgentData.SessionID != SessionId || spinUpdate.AgentData.AgentID != AgentId)
  8241. return;
  8242. Vector3 axis;
  8243. float angle;
  8244. spinUpdate.ObjectData.Rotation.GetAxisAngle(out axis, out angle);
  8245. //m_log.Warn("[CLIENT]: ObjectSpinUpdate packet rot axis:" + axis + " angle:" + angle);
  8246. OnSpinUpdate?.Invoke(spinUpdate.ObjectData.ObjectID, spinUpdate.ObjectData.Rotation, this);
  8247. }
  8248. private void HandleObjectSpinStop(Packet Pack)
  8249. {
  8250. //m_log.Warn("[CLIENT]: unhandled ObjectSpinStop packet");
  8251. ObjectSpinStopPacket spinStop = (ObjectSpinStopPacket)Pack;
  8252. if (spinStop.AgentData.SessionID != SessionId || spinStop.AgentData.AgentID != AgentId)
  8253. return;
  8254. OnSpinStop?.Invoke(spinStop.ObjectData.ObjectID, this);
  8255. }
  8256. private void HandleObjectDescription(Packet Pack)
  8257. {
  8258. if(OnObjectDescription == null)
  8259. return;
  8260. ObjectDescriptionPacket objDes = (ObjectDescriptionPacket)Pack;
  8261. if (objDes.AgentData.SessionID != SessionId || objDes.AgentData.AgentID != AgentId)
  8262. return;
  8263. for (int i = 0; i < objDes.ObjectData.Length; i++)
  8264. OnObjectDescription?.Invoke(this, objDes.ObjectData[i].LocalID,
  8265. Util.FieldToString(objDes.ObjectData[i].Description));
  8266. }
  8267. private void HandleObjectName(Packet Pack)
  8268. {
  8269. if(OnObjectName == null)
  8270. return;
  8271. ObjectNamePacket objName = (ObjectNamePacket)Pack;
  8272. if (objName.AgentData.SessionID != SessionId || objName.AgentData.AgentID != AgentId)
  8273. return;
  8274. for (int i = 0; i < objName.ObjectData.Length; i++)
  8275. OnObjectName?.Invoke(this, objName.ObjectData[i].LocalID,
  8276. Util.FieldToString(objName.ObjectData[i].Name));
  8277. }
  8278. private void HandleObjectPermissions(Packet Pack)
  8279. {
  8280. if (OnObjectPermissions == null)
  8281. return;
  8282. ObjectPermissionsPacket newobjPerms = (ObjectPermissionsPacket)Pack;
  8283. UUID SessionID = newobjPerms.AgentData.SessionID;
  8284. if (SessionID != SessionId)
  8285. return;
  8286. UUID AgentID = newobjPerms.AgentData.AgentID;
  8287. if(AgentID != AgentId)
  8288. return;
  8289. for (int i = 0; i < newobjPerms.ObjectData.Length; i++)
  8290. {
  8291. ObjectPermissionsPacket.ObjectDataBlock permChanges = newobjPerms.ObjectData[i];
  8292. byte field = permChanges.Field;
  8293. uint localID = permChanges.ObjectLocalID;
  8294. uint mask = permChanges.Mask;
  8295. byte set = permChanges.Set;
  8296. OnObjectPermissions?.Invoke(this, AgentID, SessionID, field, localID, mask, set);
  8297. }
  8298. // Here's our data,
  8299. // PermField contains the field the info goes into
  8300. // PermField determines which mask we're changing
  8301. //
  8302. // chmask is the mask of the change
  8303. // setTF is whether we're adding it or taking it away
  8304. //
  8305. // objLocalID is the localID of the object.
  8306. // Unfortunately, we have to pass the event the packet because objData is an array
  8307. // That means multiple object perms may be updated in a single packet.
  8308. }
  8309. private void HandleUndo(Packet Pack)
  8310. {
  8311. if(OnUndo == null)
  8312. return;
  8313. UndoPacket undoitem = (UndoPacket)Pack;
  8314. if (undoitem.AgentData.SessionID != SessionId || undoitem.AgentData.AgentID != AgentId)
  8315. return;
  8316. for (int i = 0; i < undoitem.ObjectData.Length; i++)
  8317. OnUndo?.Invoke(this, undoitem.ObjectData[i].ObjectID);
  8318. }
  8319. private void HandleLandUndo(Packet Pack)
  8320. {
  8321. UndoLandPacket undolanditem = (UndoLandPacket)Pack;
  8322. if (undolanditem.AgentData.SessionID != SessionId || undolanditem.AgentData.AgentID != AgentId)
  8323. return;
  8324. OnLandUndo?.Invoke(this);
  8325. }
  8326. private void HandleRedo(Packet Pack)
  8327. {
  8328. if(OnRedo == null)
  8329. return;
  8330. RedoPacket redoitem = (RedoPacket)Pack;
  8331. if (redoitem.AgentData.SessionID != SessionId || redoitem.AgentData.AgentID != AgentId)
  8332. return;
  8333. for (int i = 0; i < redoitem.ObjectData.Length; i++)
  8334. OnRedo?.Invoke(this, redoitem.ObjectData[i].ObjectID);
  8335. }
  8336. private void HandleObjectDuplicateOnRay(Packet Pack)
  8337. {
  8338. if(OnObjectDuplicateOnRay == null)
  8339. return;
  8340. ObjectDuplicateOnRayPacket dupeOnRay = (ObjectDuplicateOnRayPacket)Pack;
  8341. if (dupeOnRay.AgentData.SessionID != SessionId || dupeOnRay.AgentData.AgentID != AgentId)
  8342. return;
  8343. for (int i = 0; i < dupeOnRay.ObjectData.Length; i++)
  8344. {
  8345. UUID rezGroupID = dupeOnRay.AgentData.GroupID;
  8346. if(!IsGroupMember(rezGroupID))
  8347. rezGroupID = UUID.Zero;
  8348. OnObjectDuplicateOnRay?.Invoke(dupeOnRay.ObjectData[i].ObjectLocalID,
  8349. dupeOnRay.AgentData.DuplicateFlags, AgentId, rezGroupID,
  8350. dupeOnRay.AgentData.RayTargetID, dupeOnRay.AgentData.RayEnd,
  8351. dupeOnRay.AgentData.RayStart, dupeOnRay.AgentData.BypassRaycast,
  8352. dupeOnRay.AgentData.RayEndIsIntersection,
  8353. dupeOnRay.AgentData.CopyCenters, dupeOnRay.AgentData.CopyRotates);
  8354. }
  8355. }
  8356. private void HandleRequestObjectPropertiesFamily(Packet Pack)
  8357. {
  8358. //This powers the little tooltip that appears when you move your mouse over an object
  8359. RequestObjectPropertiesFamilyPacket packToolTip = (RequestObjectPropertiesFamilyPacket)Pack;
  8360. if (packToolTip.AgentData.SessionID != SessionId || packToolTip.AgentData.AgentID != AgentId)
  8361. return;
  8362. RequestObjectPropertiesFamilyPacket.ObjectDataBlock packObjBlock = packToolTip.ObjectData;
  8363. OnRequestObjectPropertiesFamily?.Invoke(this, m_agentId, packObjBlock.RequestFlags,
  8364. packObjBlock.ObjectID);
  8365. }
  8366. private void HandleObjectIncludeInSearch(Packet Pack)
  8367. {
  8368. if(OnObjectIncludeInSearch == null)
  8369. return;
  8370. //This lets us set objects to appear in search (stuff like DataSnapshot, etc)
  8371. ObjectIncludeInSearchPacket packInSearch = (ObjectIncludeInSearchPacket)Pack;
  8372. if (packInSearch.AgentData.SessionID != SessionId || packInSearch.AgentData.AgentID != AgentId)
  8373. return;
  8374. foreach (ObjectIncludeInSearchPacket.ObjectDataBlock objData in packInSearch.ObjectData)
  8375. {
  8376. bool inSearch = objData.IncludeInSearch;
  8377. uint localID = objData.ObjectLocalID;
  8378. OnObjectIncludeInSearch?.Invoke(this, inSearch, localID);
  8379. }
  8380. }
  8381. private void HandleScriptAnswerYes(Packet Pack)
  8382. {
  8383. ScriptAnswerYesPacket scriptAnswer = (ScriptAnswerYesPacket)Pack;
  8384. if (scriptAnswer.AgentData.SessionID != SessionId || scriptAnswer.AgentData.AgentID != AgentId)
  8385. return;
  8386. OnScriptAnswer?.Invoke(this, scriptAnswer.Data.TaskID, scriptAnswer.Data.ItemID, scriptAnswer.Data.Questions);
  8387. }
  8388. private void HandleObjectClickAction(Packet Pack)
  8389. {
  8390. if(OnObjectClickAction == null)
  8391. return;
  8392. ObjectClickActionPacket ocpacket = (ObjectClickActionPacket)Pack;
  8393. if (ocpacket.AgentData.SessionID != SessionId || ocpacket.AgentData.AgentID != AgentId)
  8394. return;
  8395. foreach (ObjectClickActionPacket.ObjectDataBlock odata in ocpacket.ObjectData)
  8396. {
  8397. byte action = odata.ClickAction;
  8398. uint localID = odata.ObjectLocalID;
  8399. OnObjectClickAction?.Invoke(this, localID, action.ToString());
  8400. }
  8401. }
  8402. private void HandleObjectMaterial(Packet Pack)
  8403. {
  8404. if(OnObjectMaterial == null)
  8405. return;
  8406. ObjectMaterialPacket ompacket = (ObjectMaterialPacket)Pack;
  8407. if (ompacket.AgentData.SessionID != SessionId || ompacket.AgentData.AgentID != AgentId)
  8408. return;
  8409. foreach (ObjectMaterialPacket.ObjectDataBlock odata in ompacket.ObjectData)
  8410. {
  8411. byte material = odata.Material;
  8412. uint localID = odata.ObjectLocalID;
  8413. OnObjectMaterial?.Invoke(this, localID, material.ToString());
  8414. }
  8415. }
  8416. #endregion Objects/m_sceneObjects
  8417. #region Inventory/Asset/Other related packets
  8418. private void HandleRequestImage(Packet Pack)
  8419. {
  8420. RequestImagePacket imageRequest = (RequestImagePacket)Pack;
  8421. if (imageRequest.AgentData.SessionID != SessionId || imageRequest.AgentData.AgentID != AgentId)
  8422. return;
  8423. //handlerTextureRequest = null;
  8424. for (int i = 0; i < imageRequest.RequestImage.Length; i++)
  8425. {
  8426. TextureRequestArgs args = new TextureRequestArgs();
  8427. RequestImagePacket.RequestImageBlock block = imageRequest.RequestImage[i];
  8428. args.RequestedAssetID = block.Image;
  8429. args.DiscardLevel = block.DiscardLevel;
  8430. args.PacketNumber = block.Packet;
  8431. args.Priority = block.DownloadPriority;
  8432. args.requestSequence = imageRequest.Header.Sequence;
  8433. // NOTE: This is not a built in part of the LLUDP protocol, but we double the
  8434. // priority of avatar textures to get avatars rezzing in faster than the
  8435. // surrounding scene
  8436. if ((ImageType)block.Type == ImageType.Baked)
  8437. args.Priority *= 2.0f;
  8438. ImageManager.EnqueueReq(args);
  8439. }
  8440. }
  8441. /// <summary>
  8442. /// This is the entry point for the UDP route by which the client can retrieve asset data. If the request
  8443. /// is successful then a TransferInfo packet will be sent back, followed by one or more TransferPackets
  8444. /// </summary>
  8445. /// <param name="sender"></param>
  8446. /// <param name="Pack"></param>
  8447. /// <returns>This parameter may be ignored since we appear to return true whatever happens</returns>
  8448. private void HandleTransferRequest(Packet Pack)
  8449. {
  8450. //m_log.Debug("ClientView.ProcessPackets.cs:ProcessInPacket() - Got transfer request");
  8451. TransferRequestPacket transfer = (TransferRequestPacket)Pack;
  8452. UUID taskID = UUID.Zero;
  8453. if (transfer.TransferInfo.SourceType == (int)SourceType.SimInventoryItem)
  8454. {
  8455. if (!(((Scene)m_scene).Permissions.BypassPermissions()))
  8456. {
  8457. // We're spawning a thread because the permissions check can block this thread
  8458. Util.FireAndForget(delegate
  8459. {
  8460. // This requests the asset if needed
  8461. HandleSimInventoryTransferRequestWithPermsCheck(this, transfer);
  8462. }, null, "LLClientView.HandleTransferRequest");
  8463. return;
  8464. }
  8465. }
  8466. else if (transfer.TransferInfo.SourceType == (int)SourceType.SimEstate)
  8467. {
  8468. //TransferRequestPacket does not include covenant uuid?
  8469. //get scene covenant uuid
  8470. taskID = m_scene.RegionInfo.RegionSettings.Covenant;
  8471. }
  8472. // This is non-blocking
  8473. MakeAssetRequest(transfer, taskID);
  8474. }
  8475. private void HandleSimInventoryTransferRequestWithPermsCheck(IClientAPI sender, TransferRequestPacket transfer)
  8476. {
  8477. UUID taskID = new UUID(transfer.TransferInfo.Params, 48);
  8478. UUID itemID = new UUID(transfer.TransferInfo.Params, 64);
  8479. UUID requestID = new UUID(transfer.TransferInfo.Params, 80);
  8480. //m_log.DebugFormat(
  8481. // "[CLIENT]: Got request for asset {0} from item {1} in prim {2} by {3}",
  8482. // requestID, itemID, taskID, Name);
  8483. //m_log.Debug("Transfer Request: " + transfer.ToString());
  8484. // Validate inventory transfers
  8485. // Has to be done here, because AssetCache can't do it
  8486. //
  8487. if (taskID != UUID.Zero) // Prim
  8488. {
  8489. SceneObjectPart part = ((Scene)m_scene).GetSceneObjectPart(taskID);
  8490. if (part == null)
  8491. {
  8492. m_log.WarnFormat(
  8493. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but prim does not exist",
  8494. Name, requestID, itemID, taskID);
  8495. return;
  8496. }
  8497. TaskInventoryItem tii = part.Inventory.GetInventoryItem(itemID);
  8498. if (tii == null)
  8499. {
  8500. m_log.WarnFormat(
  8501. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but item does not exist",
  8502. Name, requestID, itemID, taskID);
  8503. return;
  8504. }
  8505. if (tii.Type == (int)AssetType.LSLText)
  8506. {
  8507. if (!((Scene)m_scene).Permissions.CanEditScript(itemID, taskID, AgentId))
  8508. return;
  8509. }
  8510. else if (tii.Type == (int)AssetType.Notecard)
  8511. {
  8512. if (!((Scene)m_scene).Permissions.CanEditNotecard(itemID, taskID, AgentId))
  8513. return;
  8514. }
  8515. else
  8516. {
  8517. // TODO: Change this code to allow items other than notecards and scripts to be successfully
  8518. // shared with group. In fact, this whole block of permissions checking should move to an IPermissionsModule
  8519. if (part.OwnerID != AgentId)
  8520. {
  8521. m_log.WarnFormat(
  8522. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but the prim is owned by {4}",
  8523. Name, requestID, itemID, taskID, part.OwnerID);
  8524. return;
  8525. }
  8526. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  8527. {
  8528. m_log.WarnFormat(
  8529. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but modify permissions are not set",
  8530. Name, requestID, itemID, taskID);
  8531. return;
  8532. }
  8533. if (tii.OwnerID != AgentId)
  8534. {
  8535. m_log.WarnFormat(
  8536. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but the item is owned by {4}",
  8537. Name, requestID, itemID, taskID, tii.OwnerID);
  8538. return;
  8539. }
  8540. if ((
  8541. tii.CurrentPermissions & ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy | (uint)PermissionMask.Transfer))
  8542. != ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy | (uint)PermissionMask.Transfer))
  8543. {
  8544. m_log.WarnFormat(
  8545. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but item permissions are not modify/copy/transfer",
  8546. Name, requestID, itemID, taskID);
  8547. return;
  8548. }
  8549. if (tii.AssetID != requestID)
  8550. {
  8551. m_log.WarnFormat(
  8552. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but this does not match item's asset {4}",
  8553. Name, requestID, itemID, taskID, tii.AssetID);
  8554. return;
  8555. }
  8556. }
  8557. }
  8558. else // Agent
  8559. {
  8560. IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
  8561. if (invAccess != null)
  8562. {
  8563. if (!invAccess.CanGetAgentInventoryItem(this, itemID, requestID))
  8564. return;
  8565. }
  8566. else
  8567. {
  8568. return;
  8569. }
  8570. }
  8571. // Permissions out of the way, let's request the asset
  8572. MakeAssetRequest(transfer, taskID);
  8573. }
  8574. private void HandleAssetUploadRequest(Packet Pack)
  8575. {
  8576. AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
  8577. // m_log.Debug("upload request " + request.ToString());
  8578. // m_log.Debug("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToString());
  8579. UUID temp = UUID.Combine(request.AssetBlock.TransactionID, SecureSessionId);
  8580. OnAssetUploadRequest?.Invoke(this, temp,
  8581. request.AssetBlock.TransactionID, request.AssetBlock.Type,
  8582. request.AssetBlock.AssetData, request.AssetBlock.StoreLocal,
  8583. request.AssetBlock.Tempfile);
  8584. }
  8585. private void HandleRequestXfer(Packet Pack)
  8586. {
  8587. RequestXferPacket xferReq = (RequestXferPacket)Pack;
  8588. OnRequestXfer?.Invoke(this, xferReq.XferID.ID, Util.FieldToString(xferReq.XferID.Filename));
  8589. }
  8590. private void HandleSendXferPacket(Packet Pack)
  8591. {
  8592. SendXferPacketPacket xferRec = (SendXferPacketPacket)Pack;
  8593. OnXferReceive?.Invoke(this, xferRec.XferID.ID, xferRec.XferID.Packet, xferRec.DataPacket.Data);
  8594. }
  8595. private void HandleConfirmXferPacket(Packet Pack)
  8596. {
  8597. ConfirmXferPacketPacket confirmXfer = (ConfirmXferPacketPacket)Pack;
  8598. OnConfirmXfer?.Invoke(this, confirmXfer.XferID.ID, confirmXfer.XferID.Packet);
  8599. }
  8600. private void HandleAbortXfer(Packet Pack)
  8601. {
  8602. AbortXferPacket abortXfer = (AbortXferPacket)Pack;
  8603. OnAbortXfer?.Invoke(this, abortXfer.XferID.ID);
  8604. }
  8605. private void HandleCreateInventoryFolder(Packet Pack)
  8606. {
  8607. CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack;
  8608. if (invFolder.AgentData.SessionID != SessionId || invFolder.AgentData.AgentID != AgentId)
  8609. return;
  8610. OnCreateNewInventoryFolder?.Invoke(this, invFolder.FolderData.FolderID,
  8611. (ushort)invFolder.FolderData.Type,
  8612. Util.FieldToString(invFolder.FolderData.Name),
  8613. invFolder.FolderData.ParentID);
  8614. }
  8615. private void HandleUpdateInventoryFolder(Packet Pack)
  8616. {
  8617. if (OnUpdateInventoryFolder == null)
  8618. return;
  8619. UpdateInventoryFolderPacket invFolderx = (UpdateInventoryFolderPacket)Pack;
  8620. if (invFolderx.AgentData.SessionID != SessionId || invFolderx.AgentData.AgentID != AgentId)
  8621. return;
  8622. for (int i = 0; i < invFolderx.FolderData.Length; i++)
  8623. {
  8624. OnUpdateInventoryFolder?.Invoke(this, invFolderx.FolderData[i].FolderID,
  8625. (ushort)invFolderx.FolderData[i].Type,
  8626. Util.FieldToString(invFolderx.FolderData[i].Name),
  8627. invFolderx.FolderData[i].ParentID);
  8628. }
  8629. }
  8630. private void HandleMoveInventoryFolder(Packet Pack)
  8631. {
  8632. if (OnMoveInventoryFolder == null)
  8633. return;
  8634. MoveInventoryFolderPacket invFoldery = (MoveInventoryFolderPacket)Pack;
  8635. if (invFoldery.AgentData.SessionID != SessionId || invFoldery.AgentData.AgentID != AgentId)
  8636. return;
  8637. for (int i = 0; i < invFoldery.InventoryData.Length; i++)
  8638. {
  8639. OnMoveInventoryFolder?.Invoke(this, invFoldery.InventoryData[i].FolderID,
  8640. invFoldery.InventoryData[i].ParentID);
  8641. }
  8642. }
  8643. private void HandleCreateInventoryItem(Packet Pack)
  8644. {
  8645. CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack;
  8646. if (createItem.AgentData.SessionID != SessionId || createItem.AgentData.AgentID != AgentId)
  8647. return;
  8648. OnCreateNewInventoryItem?.Invoke(this, createItem.InventoryBlock.TransactionID,
  8649. createItem.InventoryBlock.FolderID,
  8650. createItem.InventoryBlock.CallbackID,
  8651. Util.FieldToString(createItem.InventoryBlock.Description),
  8652. Util.FieldToString(createItem.InventoryBlock.Name),
  8653. createItem.InventoryBlock.InvType,
  8654. createItem.InventoryBlock.Type,
  8655. createItem.InventoryBlock.WearableType,
  8656. createItem.InventoryBlock.NextOwnerMask,
  8657. Util.UnixTimeSinceEpoch());
  8658. }
  8659. private void HandleLinkInventoryItem(Packet Pack)
  8660. {
  8661. LinkInventoryItemPacket createLink = (LinkInventoryItemPacket)Pack;
  8662. if (createLink.AgentData.SessionID != SessionId || createLink.AgentData.AgentID != AgentId)
  8663. return;
  8664. OnLinkInventoryItem?.Invoke(
  8665. this,
  8666. createLink.InventoryBlock.TransactionID,
  8667. createLink.InventoryBlock.FolderID,
  8668. createLink.InventoryBlock.CallbackID,
  8669. Util.FieldToString(createLink.InventoryBlock.Description),
  8670. Util.FieldToString(createLink.InventoryBlock.Name),
  8671. createLink.InventoryBlock.InvType,
  8672. createLink.InventoryBlock.Type,
  8673. createLink.InventoryBlock.OldItemID);
  8674. }
  8675. private void HandleFetchInventory(Packet Pack)
  8676. {
  8677. if (OnFetchInventory == null)
  8678. return;
  8679. FetchInventoryPacket FetchInventoryx = (FetchInventoryPacket)Pack;
  8680. if (FetchInventoryx.AgentData.SessionID != SessionId || FetchInventoryx.AgentData.AgentID != AgentId)
  8681. return;
  8682. FetchInventoryPacket.InventoryDataBlock[] data = FetchInventoryx.InventoryData;
  8683. UUID[] items = new UUID[data.Length];
  8684. UUID[] owners = new UUID[data.Length];
  8685. for (int i = 0; i < data.Length; ++i)
  8686. {
  8687. items[i] =data[i].ItemID;
  8688. owners[i] = data[i].OwnerID;
  8689. }
  8690. OnFetchInventory?.Invoke(this, items, owners);
  8691. }
  8692. private void HandleFetchInventoryDescendents(Packet Pack)
  8693. {
  8694. FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack;
  8695. if (Fetch.AgentData.SessionID != SessionId || Fetch.AgentData.AgentID != AgentId)
  8696. return;
  8697. FetchInventoryDescendentsPacket.InventoryDataBlock data = Fetch.InventoryData;
  8698. OnFetchInventoryDescendents?.Invoke(this, data.FolderID, data.OwnerID,
  8699. data.FetchFolders, data.FetchItems,
  8700. data.SortOrder);
  8701. }
  8702. private void HandlePurgeInventoryDescendents(Packet Pack)
  8703. {
  8704. PurgeInventoryDescendentsPacket Purge = (PurgeInventoryDescendentsPacket)Pack;
  8705. if (Purge.AgentData.SessionID != SessionId || Purge.AgentData.AgentID != AgentId)
  8706. return;
  8707. OnPurgeInventoryDescendents?.Invoke(this, Purge.InventoryData.FolderID);
  8708. }
  8709. private void HandleUpdateInventoryItem(Packet Pack)
  8710. {
  8711. if (OnUpdateInventoryItem == null)
  8712. return;
  8713. UpdateInventoryItemPacket inventoryItemUpdate = (UpdateInventoryItemPacket)Pack;
  8714. if (inventoryItemUpdate.AgentData.SessionID != SessionId || inventoryItemUpdate.AgentData.AgentID != AgentId)
  8715. return;
  8716. for (int i = 0; i < inventoryItemUpdate.InventoryData.Length; i++)
  8717. {
  8718. InventoryItemBase itemUpd = new InventoryItemBase();
  8719. itemUpd.ID = inventoryItemUpdate.InventoryData[i].ItemID;
  8720. itemUpd.Name = Util.FieldToString(inventoryItemUpdate.InventoryData[i].Name);
  8721. itemUpd.Description = Util.FieldToString(inventoryItemUpdate.InventoryData[i].Description);
  8722. itemUpd.GroupID = inventoryItemUpdate.InventoryData[i].GroupID;
  8723. itemUpd.GroupOwned = inventoryItemUpdate.InventoryData[i].GroupOwned;
  8724. itemUpd.GroupPermissions = inventoryItemUpdate.InventoryData[i].GroupMask;
  8725. itemUpd.NextPermissions = inventoryItemUpdate.InventoryData[i].NextOwnerMask;
  8726. itemUpd.EveryOnePermissions = inventoryItemUpdate.InventoryData[i].EveryoneMask;
  8727. itemUpd.CreationDate = inventoryItemUpdate.InventoryData[i].CreationDate;
  8728. itemUpd.Folder = inventoryItemUpdate.InventoryData[i].FolderID;
  8729. itemUpd.InvType = inventoryItemUpdate.InventoryData[i].InvType;
  8730. itemUpd.SalePrice = inventoryItemUpdate.InventoryData[i].SalePrice;
  8731. itemUpd.SaleType = inventoryItemUpdate.InventoryData[i].SaleType;
  8732. itemUpd.Flags = inventoryItemUpdate.InventoryData[i].Flags;
  8733. OnUpdateInventoryItem?.Invoke(this, inventoryItemUpdate.InventoryData[i].TransactionID,
  8734. inventoryItemUpdate.InventoryData[i].ItemID,
  8735. itemUpd);
  8736. }
  8737. }
  8738. private void HandleCopyInventoryItem(Packet Pack)
  8739. {
  8740. if(OnCopyInventoryItem == null)
  8741. return;
  8742. CopyInventoryItemPacket copyitem = (CopyInventoryItemPacket)Pack;
  8743. if (copyitem.AgentData.SessionID != SessionId || copyitem.AgentData.AgentID != AgentId)
  8744. return;
  8745. foreach (CopyInventoryItemPacket.InventoryDataBlock datablock in copyitem.InventoryData)
  8746. {
  8747. OnCopyInventoryItem?.Invoke(this, datablock.CallbackID, datablock.OldAgentID,
  8748. datablock.OldItemID, datablock.NewFolderID,
  8749. Util.FieldToString(datablock.NewName));
  8750. }
  8751. }
  8752. private void HandleMoveInventoryItem(Packet Pack)
  8753. {
  8754. if (OnMoveInventoryItem == null)
  8755. return;
  8756. MoveInventoryItemPacket moveitem = (MoveInventoryItemPacket)Pack;
  8757. if (moveitem.AgentData.SessionID != SessionId || moveitem.AgentData.AgentID != AgentId)
  8758. return;
  8759. InventoryItemBase itm = null;
  8760. List<InventoryItemBase> items = new List<InventoryItemBase>();
  8761. foreach (MoveInventoryItemPacket.InventoryDataBlock datablock in moveitem.InventoryData)
  8762. {
  8763. itm = new InventoryItemBase(datablock.ItemID, AgentId);
  8764. itm.Folder = datablock.FolderID;
  8765. itm.Name = Util.FieldToString(datablock.NewName);
  8766. // weird, comes out as empty string
  8767. //m_log.DebugFormat("[XXX] new name: {0}", itm.Name);
  8768. items.Add(itm);
  8769. }
  8770. OnMoveInventoryItem?.Invoke(this, items);
  8771. }
  8772. private void HandleRemoveInventoryItem(Packet Pack)
  8773. {
  8774. if(OnRemoveInventoryItem == null)
  8775. return;
  8776. RemoveInventoryItemPacket removeItem = (RemoveInventoryItemPacket)Pack;
  8777. if (removeItem.AgentData.SessionID != SessionId || removeItem.AgentData.AgentID != AgentId)
  8778. return;
  8779. List<UUID> uuids = new List<UUID>();
  8780. foreach (RemoveInventoryItemPacket.InventoryDataBlock datablock in removeItem.InventoryData)
  8781. {
  8782. uuids.Add(datablock.ItemID);
  8783. }
  8784. OnRemoveInventoryItem?.Invoke(this, uuids);
  8785. }
  8786. private void HandleRemoveInventoryFolder(Packet Pack)
  8787. {
  8788. if (OnRemoveInventoryFolder == null)
  8789. return;
  8790. RemoveInventoryFolderPacket removeFolder = (RemoveInventoryFolderPacket)Pack;
  8791. if (removeFolder.AgentData.SessionID != SessionId || removeFolder.AgentData.AgentID != AgentId)
  8792. return;
  8793. List<UUID> uuids = new List<UUID>();
  8794. foreach (RemoveInventoryFolderPacket.FolderDataBlock datablock in removeFolder.FolderData)
  8795. {
  8796. uuids.Add(datablock.FolderID);
  8797. }
  8798. OnRemoveInventoryFolder?.Invoke(this, uuids);
  8799. }
  8800. private void HandleRemoveInventoryObjects(Packet Pack)
  8801. {
  8802. if (OnRemoveInventoryFolder == null || OnRemoveInventoryItem == null)
  8803. return;
  8804. RemoveInventoryObjectsPacket removeObject = (RemoveInventoryObjectsPacket)Pack;
  8805. if (removeObject.AgentData.SessionID != SessionId || removeObject.AgentData.AgentID != AgentId)
  8806. return;
  8807. List<UUID> uuids = new List<UUID>();
  8808. foreach (RemoveInventoryObjectsPacket.FolderDataBlock datablock in removeObject.FolderData)
  8809. uuids.Add(datablock.FolderID);
  8810. OnRemoveInventoryFolder?.Invoke(this, uuids);
  8811. uuids.Clear();
  8812. foreach (RemoveInventoryObjectsPacket.ItemDataBlock datablock in removeObject.ItemData)
  8813. uuids.Add(datablock.ItemID);
  8814. OnRemoveInventoryItem?.Invoke(this, uuids);
  8815. }
  8816. private void HandleRequestTaskInventory(Packet Pack)
  8817. {
  8818. RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
  8819. if (requesttask.AgentData.SessionID != SessionId || requesttask.AgentData.AgentID != AgentId)
  8820. return;
  8821. OnRequestTaskInventory?.Invoke(this, requesttask.InventoryData.LocalID);
  8822. }
  8823. private void HandleUpdateTaskInventory(Packet Pack)
  8824. {
  8825. if (OnUpdateTaskInventory == null)
  8826. return;
  8827. UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
  8828. if (updatetask.UpdateData.Key != 0)
  8829. return; // only do inventory not assets
  8830. if (updatetask.AgentData.SessionID != SessionId || updatetask.AgentData.AgentID != AgentId)
  8831. return;
  8832. TaskInventoryItem newTaskItem = new TaskInventoryItem();
  8833. newTaskItem.ItemID = updatetask.InventoryData.ItemID;
  8834. newTaskItem.ParentID = updatetask.InventoryData.FolderID;
  8835. newTaskItem.CreatorID = updatetask.InventoryData.CreatorID;
  8836. newTaskItem.OwnerID = updatetask.InventoryData.OwnerID;
  8837. newTaskItem.GroupID = updatetask.InventoryData.GroupID;
  8838. newTaskItem.BasePermissions = updatetask.InventoryData.BaseMask;
  8839. newTaskItem.CurrentPermissions = updatetask.InventoryData.OwnerMask;
  8840. newTaskItem.GroupPermissions = updatetask.InventoryData.GroupMask;
  8841. newTaskItem.EveryonePermissions = updatetask.InventoryData.EveryoneMask;
  8842. newTaskItem.NextPermissions = updatetask.InventoryData.NextOwnerMask;
  8843. // Unused? Clicking share with group sets GroupPermissions instead, so perhaps this is something
  8844. // different
  8845. //newTaskItem.GroupOwned=updatetask.InventoryData.GroupOwned;
  8846. newTaskItem.Type = updatetask.InventoryData.Type;
  8847. newTaskItem.InvType = updatetask.InventoryData.InvType;
  8848. newTaskItem.Flags = updatetask.InventoryData.Flags;
  8849. //newTaskItem.SaleType=updatetask.InventoryData.SaleType;
  8850. //newTaskItem.SalePrice=updatetask.InventoryData.SalePrice;
  8851. newTaskItem.Name = Util.FieldToString(updatetask.InventoryData.Name);
  8852. newTaskItem.Description = Util.FieldToString(updatetask.InventoryData.Description);
  8853. newTaskItem.CreationDate = (uint)updatetask.InventoryData.CreationDate;
  8854. OnUpdateTaskInventory?.Invoke(this, updatetask.InventoryData.TransactionID,
  8855. newTaskItem, updatetask.UpdateData.LocalID);
  8856. }
  8857. private void HandleRemoveTaskInventory(Packet Pack)
  8858. {
  8859. RemoveTaskInventoryPacket removeTask = (RemoveTaskInventoryPacket)Pack;
  8860. if (removeTask.AgentData.SessionID != SessionId || removeTask.AgentData.AgentID != AgentId)
  8861. return;
  8862. OnRemoveTaskItem?.Invoke(this, removeTask.InventoryData.ItemID, removeTask.InventoryData.LocalID);
  8863. }
  8864. private void HandleMoveTaskInventory(Packet Pack)
  8865. {
  8866. MoveTaskInventoryPacket moveTaskInventoryPacket = (MoveTaskInventoryPacket)Pack;
  8867. if (moveTaskInventoryPacket.AgentData.SessionID != SessionId || moveTaskInventoryPacket.AgentData.AgentID != AgentId)
  8868. return;
  8869. OnMoveTaskItem?.Invoke(
  8870. this, moveTaskInventoryPacket.AgentData.FolderID,
  8871. moveTaskInventoryPacket.InventoryData.LocalID,
  8872. moveTaskInventoryPacket.InventoryData.ItemID);
  8873. }
  8874. private void HandleRezScript(Packet Pack)
  8875. {
  8876. if(OnRezScript == null)
  8877. return;
  8878. //m_log.Debug(Pack.ToString());
  8879. RezScriptPacket rezScriptx = (RezScriptPacket)Pack;
  8880. if (rezScriptx.AgentData.SessionID != SessionId || rezScriptx.AgentData.AgentID != AgentId)
  8881. return;
  8882. InventoryItemBase item = new InventoryItemBase();
  8883. item.ID = rezScriptx.InventoryBlock.ItemID;
  8884. item.Folder = rezScriptx.InventoryBlock.FolderID;
  8885. item.CreatorId = rezScriptx.InventoryBlock.CreatorID.ToString();
  8886. item.Owner = rezScriptx.InventoryBlock.OwnerID;
  8887. item.BasePermissions = rezScriptx.InventoryBlock.BaseMask;
  8888. item.CurrentPermissions = rezScriptx.InventoryBlock.OwnerMask;
  8889. item.EveryOnePermissions = rezScriptx.InventoryBlock.EveryoneMask;
  8890. item.NextPermissions = rezScriptx.InventoryBlock.NextOwnerMask;
  8891. item.GroupPermissions = rezScriptx.InventoryBlock.GroupMask;
  8892. item.GroupOwned = rezScriptx.InventoryBlock.GroupOwned;
  8893. item.GroupID = rezScriptx.InventoryBlock.GroupID;
  8894. item.AssetType = rezScriptx.InventoryBlock.Type;
  8895. item.InvType = rezScriptx.InventoryBlock.InvType;
  8896. item.Flags = rezScriptx.InventoryBlock.Flags;
  8897. item.SaleType = rezScriptx.InventoryBlock.SaleType;
  8898. item.SalePrice = rezScriptx.InventoryBlock.SalePrice;
  8899. item.Name = Util.FieldToString(rezScriptx.InventoryBlock.Name);
  8900. item.Description = Util.FieldToString(rezScriptx.InventoryBlock.Description);
  8901. item.CreationDate = rezScriptx.InventoryBlock.CreationDate;
  8902. OnRezScript?.Invoke(this, item, rezScriptx.InventoryBlock.TransactionID, rezScriptx.UpdateBlock.ObjectLocalID);
  8903. }
  8904. private void HandleMapLayerRequest(Packet Pack)
  8905. {
  8906. RequestMapLayer();
  8907. }
  8908. private void HandleMapBlockRequest(Packet Pack)
  8909. {
  8910. MapBlockRequestPacket MapRequest = (MapBlockRequestPacket)Pack;
  8911. if (MapRequest.AgentData.SessionID != SessionId || MapRequest.AgentData.AgentID != AgentId)
  8912. return;
  8913. OnRequestMapBlocks?.Invoke(this, MapRequest.PositionData.MinX, MapRequest.PositionData.MinY,
  8914. MapRequest.PositionData.MaxX, MapRequest.PositionData.MaxY, MapRequest.AgentData.Flags);
  8915. }
  8916. private void HandleMapNameRequest(Packet Pack)
  8917. {
  8918. MapNameRequestPacket map = (MapNameRequestPacket)Pack;
  8919. if (map.AgentData.SessionID != SessionId || map.AgentData.AgentID != AgentId)
  8920. return;
  8921. string mapName = (map.NameData.Name.Length == 0) ? m_scene.RegionInfo.RegionName :
  8922. Util.UTF8.GetString(map.NameData.Name, 0, map.NameData.Name.Length - 1);
  8923. OnMapNameRequest?.Invoke(this, mapName, map.AgentData.Flags);
  8924. }
  8925. private void HandleTeleportLandmarkRequest(Packet Pack)
  8926. {
  8927. TeleportLandmarkRequestPacket tpReq = (TeleportLandmarkRequestPacket)Pack;
  8928. if (tpReq.Info.SessionID != SessionId || tpReq.Info.AgentID != AgentId)
  8929. return;
  8930. UUID lmid = tpReq.Info.LandmarkID;
  8931. AssetLandmark lm;
  8932. if (lmid != UUID.Zero)
  8933. {
  8934. //AssetBase lma = m_assetCache.GetAsset(lmid, false);
  8935. AssetBase lma = m_assetService.Get(lmid.ToString());
  8936. if (lma == null)
  8937. {
  8938. // Failed to find landmark
  8939. // Let's try to search in the user's home asset server
  8940. lma = FindAssetInUserAssetServer(lmid.ToString());
  8941. if (lma == null)
  8942. {
  8943. // Really doesn't exist
  8944. m_log.WarnFormat("[llClient]: landmark asset {0} not found",lmid.ToString());
  8945. SendTeleportFailed("Could not find the landmark asset data");
  8946. return;
  8947. }
  8948. }
  8949. try
  8950. {
  8951. lm = new AssetLandmark(lma);
  8952. }
  8953. catch (NullReferenceException)
  8954. {
  8955. // asset not found generates null ref inside the assetlandmark constructor.
  8956. SendTeleportFailed("Could not find the landmark asset data");
  8957. return;
  8958. }
  8959. }
  8960. else
  8961. {
  8962. // Teleport home request
  8963. OnTeleportHomeRequest?.Invoke(AgentId, this);
  8964. return;
  8965. }
  8966. OnTeleportLandmarkRequest?.Invoke(this, lm);
  8967. }
  8968. private void HandleTeleportCancel(Packet Pack)
  8969. {
  8970. TeleportCancelPacket pkt = (TeleportCancelPacket) Pack;
  8971. if(pkt.Info.AgentID != AgentId || pkt.Info.SessionID != SessionId)
  8972. return;
  8973. OnTeleportCancel?.Invoke(this);
  8974. }
  8975. private AssetBase FindAssetInUserAssetServer(string id)
  8976. {
  8977. AgentCircuitData aCircuit = ((Scene)Scene).AuthenticateHandler.GetAgentCircuitData(CircuitCode);
  8978. if (aCircuit != null && aCircuit.ServiceURLs != null && aCircuit.ServiceURLs.ContainsKey("AssetServerURI"))
  8979. {
  8980. string assetServer = aCircuit.ServiceURLs["AssetServerURI"].ToString();
  8981. if (!string.IsNullOrEmpty(assetServer))
  8982. return ((Scene)Scene).AssetService.Get(id, assetServer, false);
  8983. }
  8984. return null;
  8985. }
  8986. private void HandleTeleportLocationRequest(Packet Pack)
  8987. {
  8988. if(OnTeleportLocationRequest == null)
  8989. {
  8990. SendTeleportFailed("Could not process the teleport");
  8991. return;
  8992. }
  8993. TeleportLocationRequestPacket tpLocReq = (TeleportLocationRequestPacket)Pack;
  8994. if (tpLocReq.AgentData.SessionID != SessionId || tpLocReq.AgentData.AgentID != AgentId)
  8995. return;
  8996. // Adjust teleport location to base of a larger region if requested to teleport to a sub-region
  8997. uint locX, locY;
  8998. Util.RegionHandleToWorldLoc(tpLocReq.Info.RegionHandle, out locX, out locY);
  8999. if ((locX >= m_scene.RegionInfo.WorldLocX)
  9000. && (locX < (m_scene.RegionInfo.WorldLocX + m_scene.RegionInfo.RegionSizeX))
  9001. && (locY >= m_scene.RegionInfo.WorldLocY)
  9002. && (locY < (m_scene.RegionInfo.WorldLocY + m_scene.RegionInfo.RegionSizeY)))
  9003. {
  9004. tpLocReq.Info.RegionHandle = m_scene.RegionInfo.RegionHandle;
  9005. tpLocReq.Info.Position.X += locX - m_scene.RegionInfo.WorldLocX;
  9006. tpLocReq.Info.Position.Y += locY - m_scene.RegionInfo.WorldLocY;
  9007. }
  9008. OnTeleportLocationRequest?.Invoke(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position,
  9009. tpLocReq.Info.LookAt, 16);
  9010. }
  9011. #endregion Inventory/Asset/Other related packets
  9012. private void HandleUUIDNameRequest(Packet Pack)
  9013. {
  9014. if(OnNameFromUUIDRequest == null)
  9015. return;
  9016. ScenePresence sp = (ScenePresence)SceneAgent;
  9017. if(sp == null || sp.IsDeleted || (sp.IsInTransit && !sp.IsInLocalTransit))
  9018. return;
  9019. UUIDNameRequestPacket incoming = (UUIDNameRequestPacket)Pack;
  9020. foreach (UUIDNameRequestPacket.UUIDNameBlockBlock UUIDBlock in incoming.UUIDNameBlock)
  9021. OnNameFromUUIDRequest?.Invoke(UUIDBlock.ID, this);
  9022. }
  9023. #region Parcel related packets
  9024. private void HandleRegionHandleRequest(Packet Pack)
  9025. {
  9026. RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack;
  9027. OnRegionHandleRequest?.Invoke(this, rhrPack.RequestBlock.RegionID);
  9028. }
  9029. private void HandleParcelInfoRequest(Packet Pack)
  9030. {
  9031. if(OnParcelInfoRequest == null)
  9032. return;
  9033. ParcelInfoRequestPacket pirPack = (ParcelInfoRequestPacket)Pack;
  9034. if (pirPack.AgentData.SessionID != SessionId || pirPack.AgentData.AgentID != AgentId)
  9035. return;
  9036. OnParcelInfoRequest?.Invoke(this, pirPack.Data.ParcelID);
  9037. }
  9038. private void HandleParcelAccessListRequest(Packet Pack)
  9039. {
  9040. ParcelAccessListRequestPacket requestPacket = (ParcelAccessListRequestPacket)Pack;
  9041. if (requestPacket.AgentData.SessionID != SessionId || requestPacket.AgentData.AgentID != AgentId)
  9042. return;
  9043. OnParcelAccessListRequest?.Invoke(requestPacket.AgentData.AgentID, requestPacket.AgentData.SessionID,
  9044. requestPacket.Data.Flags, requestPacket.Data.SequenceID,
  9045. requestPacket.Data.LocalID, this);
  9046. }
  9047. private void HandleParcelAccessListUpdate(Packet Pack)
  9048. {
  9049. if(OnParcelAccessListUpdateRequest == null)
  9050. return;
  9051. ParcelAccessListUpdatePacket updatePacket = (ParcelAccessListUpdatePacket)Pack;
  9052. if (updatePacket.AgentData.SessionID != SessionId || updatePacket.AgentData.AgentID != AgentId)
  9053. return;
  9054. // viewers do send estimated number of packets and sequenceID, but don't seem reliable.
  9055. List<LandAccessEntry> entries = new List<LandAccessEntry>();
  9056. foreach (ParcelAccessListUpdatePacket.ListBlock block in updatePacket.List)
  9057. {
  9058. LandAccessEntry entry = new LandAccessEntry();
  9059. entry.AgentID = block.ID;
  9060. entry.Flags = (AccessList)block.Flags;
  9061. entry.Expires = block.Time;
  9062. entries.Add(entry);
  9063. }
  9064. OnParcelAccessListUpdateRequest?.Invoke(updatePacket.AgentData.AgentID,
  9065. updatePacket.Data.Flags,
  9066. updatePacket.Data.TransactionID,
  9067. updatePacket.Data.LocalID,
  9068. entries, this);
  9069. }
  9070. private void HandleParcelPropertiesRequest(Packet Pack)
  9071. {
  9072. ParcelPropertiesRequestPacket propertiesRequest = (ParcelPropertiesRequestPacket)Pack;
  9073. if (propertiesRequest.AgentData.SessionID != SessionId || propertiesRequest.AgentData.AgentID != AgentId)
  9074. return;
  9075. ParcelPropertiesRequestPacket.ParcelDataBlock pdb = propertiesRequest.ParcelData;
  9076. OnParcelPropertiesRequest?.Invoke((int)Math.Round(pdb.West), (int)Math.Round(pdb.South),
  9077. (int)Math.Round(pdb.East), (int)Math.Round(pdb.North),
  9078. pdb.SequenceID, pdb.SnapSelection, this);
  9079. }
  9080. private void HandleParcelDivide(Packet Pack)
  9081. {
  9082. ParcelDividePacket landDivide = (ParcelDividePacket)Pack;
  9083. if (landDivide.AgentData.SessionID != SessionId || landDivide.AgentData.AgentID != AgentId)
  9084. return;
  9085. OnParcelDivideRequest?.Invoke((int)Math.Round(landDivide.ParcelData.West),
  9086. (int)Math.Round(landDivide.ParcelData.South),
  9087. (int)Math.Round(landDivide.ParcelData.East),
  9088. (int)Math.Round(landDivide.ParcelData.North), this);
  9089. }
  9090. private void HandleParcelJoin(Packet Pack)
  9091. {
  9092. ParcelJoinPacket landJoin = (ParcelJoinPacket)Pack;
  9093. if (landJoin.AgentData.SessionID != SessionId || landJoin.AgentData.AgentID != AgentId)
  9094. return;
  9095. OnParcelJoinRequest?.Invoke((int)Math.Round(landJoin.ParcelData.West),
  9096. (int)Math.Round(landJoin.ParcelData.South),
  9097. (int)Math.Round(landJoin.ParcelData.East),
  9098. (int)Math.Round(landJoin.ParcelData.North), this);
  9099. }
  9100. private void HandleParcelPropertiesUpdate(Packet Pack)
  9101. {
  9102. if (OnParcelPropertiesUpdateRequest == null)
  9103. return;
  9104. ParcelPropertiesUpdatePacket parcelPropertiesPacket = (ParcelPropertiesUpdatePacket)Pack;
  9105. if (parcelPropertiesPacket.AgentData.SessionID != SessionId || parcelPropertiesPacket.AgentData.AgentID != AgentId)
  9106. return;
  9107. LandUpdateArgs args = new LandUpdateArgs();
  9108. args.AuthBuyerID = parcelPropertiesPacket.ParcelData.AuthBuyerID;
  9109. args.Category = (ParcelCategory)parcelPropertiesPacket.ParcelData.Category;
  9110. args.Desc = Utils.BytesToString(parcelPropertiesPacket.ParcelData.Desc);
  9111. args.GroupID = parcelPropertiesPacket.ParcelData.GroupID;
  9112. args.LandingType = parcelPropertiesPacket.ParcelData.LandingType;
  9113. args.MediaAutoScale = parcelPropertiesPacket.ParcelData.MediaAutoScale;
  9114. args.MediaID = parcelPropertiesPacket.ParcelData.MediaID;
  9115. args.MediaURL = Utils.BytesToString(parcelPropertiesPacket.ParcelData.MediaURL);
  9116. args.MusicURL = Utils.BytesToString(parcelPropertiesPacket.ParcelData.MusicURL);
  9117. args.Name = Utils.BytesToString(parcelPropertiesPacket.ParcelData.Name);
  9118. args.ParcelFlags = parcelPropertiesPacket.ParcelData.ParcelFlags;
  9119. args.PassHours = parcelPropertiesPacket.ParcelData.PassHours;
  9120. args.PassPrice = parcelPropertiesPacket.ParcelData.PassPrice;
  9121. args.SalePrice = parcelPropertiesPacket.ParcelData.SalePrice;
  9122. args.SnapshotID = parcelPropertiesPacket.ParcelData.SnapshotID;
  9123. args.UserLocation = parcelPropertiesPacket.ParcelData.UserLocation;
  9124. args.UserLookAt = parcelPropertiesPacket.ParcelData.UserLookAt;
  9125. OnParcelPropertiesUpdateRequest?.Invoke(args, parcelPropertiesPacket.ParcelData.LocalID, this);
  9126. }
  9127. private void HandleParcelSelectObjects(Packet Pack)
  9128. {
  9129. if(OnParcelSelectObjects == null)
  9130. return;
  9131. ParcelSelectObjectsPacket selectPacket = (ParcelSelectObjectsPacket)Pack;
  9132. if (selectPacket.AgentData.SessionID != SessionId || selectPacket.AgentData.AgentID != AgentId)
  9133. return;
  9134. List<UUID> returnIDs = new List<UUID>();
  9135. foreach (ParcelSelectObjectsPacket.ReturnIDsBlock rb in selectPacket.ReturnIDs)
  9136. {
  9137. returnIDs.Add(rb.ReturnID);
  9138. }
  9139. OnParcelSelectObjects?.Invoke(selectPacket.ParcelData.LocalID,
  9140. Convert.ToInt32(selectPacket.ParcelData.ReturnType), returnIDs, this);
  9141. }
  9142. private void HandleParcelObjectOwnersRequest(Packet Pack)
  9143. {
  9144. ParcelObjectOwnersRequestPacket reqPacket = (ParcelObjectOwnersRequestPacket)Pack;
  9145. if (reqPacket.AgentData.SessionID != SessionId || reqPacket.AgentData.AgentID != AgentId)
  9146. return;
  9147. OnParcelObjectOwnerRequest?.Invoke(reqPacket.ParcelData.LocalID, this);
  9148. }
  9149. private void HandleParcelGodForceOwner(Packet Pack)
  9150. {
  9151. ParcelGodForceOwnerPacket godForceOwnerPacket = (ParcelGodForceOwnerPacket)Pack;
  9152. if (godForceOwnerPacket.AgentData.SessionID != SessionId || godForceOwnerPacket.AgentData.AgentID != AgentId)
  9153. return;
  9154. OnParcelGodForceOwner?.Invoke(godForceOwnerPacket.Data.LocalID, godForceOwnerPacket.Data.OwnerID, this);
  9155. }
  9156. private void HandleParcelRelease(Packet Pack)
  9157. {
  9158. ParcelReleasePacket releasePacket = (ParcelReleasePacket)Pack;
  9159. if (releasePacket.AgentData.SessionID != SessionId || releasePacket.AgentData.AgentID != AgentId)
  9160. return;
  9161. OnParcelAbandonRequest?.Invoke(releasePacket.Data.LocalID, this);
  9162. }
  9163. private void HandleParcelReclaim(Packet Pack)
  9164. {
  9165. ParcelReclaimPacket reclaimPacket = (ParcelReclaimPacket)Pack;
  9166. if (reclaimPacket.AgentData.SessionID != SessionId || reclaimPacket.AgentData.AgentID != AgentId)
  9167. return;
  9168. OnParcelReclaim?.Invoke(reclaimPacket.Data.LocalID, this);
  9169. }
  9170. private void HandleParcelReturnObjects(Packet Pack)
  9171. {
  9172. if(OnParcelReturnObjectsRequest == null)
  9173. return;
  9174. ParcelReturnObjectsPacket parcelReturnObjects = (ParcelReturnObjectsPacket)Pack;
  9175. if (parcelReturnObjects.AgentData.SessionID != SessionId || parcelReturnObjects.AgentData.AgentID != AgentId)
  9176. return;
  9177. UUID[] puserselectedOwnerIDs = new UUID[parcelReturnObjects.OwnerIDs.Length];
  9178. for (int parceliterator = 0; parceliterator < parcelReturnObjects.OwnerIDs.Length; parceliterator++)
  9179. puserselectedOwnerIDs[parceliterator] = parcelReturnObjects.OwnerIDs[parceliterator].OwnerID;
  9180. UUID[] puserselectedTaskIDs = new UUID[parcelReturnObjects.TaskIDs.Length];
  9181. for (int parceliterator = 0; parceliterator < parcelReturnObjects.TaskIDs.Length; parceliterator++)
  9182. puserselectedTaskIDs[parceliterator] = parcelReturnObjects.TaskIDs[parceliterator].TaskID;
  9183. OnParcelReturnObjectsRequest?.Invoke(parcelReturnObjects.ParcelData.LocalID, parcelReturnObjects.ParcelData.ReturnType, puserselectedOwnerIDs, puserselectedTaskIDs, this);
  9184. }
  9185. private void HandleParcelSetOtherCleanTime(Packet Pack)
  9186. {
  9187. ParcelSetOtherCleanTimePacket parcelSetOtherCleanTimePacket = (ParcelSetOtherCleanTimePacket)Pack;
  9188. if (parcelSetOtherCleanTimePacket.AgentData.SessionID != SessionId || parcelSetOtherCleanTimePacket.AgentData.AgentID != AgentId)
  9189. return;
  9190. OnParcelSetOtherCleanTime?.Invoke(this,
  9191. parcelSetOtherCleanTimePacket.ParcelData.LocalID,
  9192. parcelSetOtherCleanTimePacket.ParcelData.OtherCleanTime);
  9193. }
  9194. private void HandleLandStatRequest(Packet Pack)
  9195. {
  9196. LandStatRequestPacket lsrp = (LandStatRequestPacket)Pack;
  9197. if (lsrp.AgentData.SessionID != SessionId || lsrp.AgentData.AgentID != AgentId)
  9198. return;
  9199. OnLandStatRequest?.Invoke(lsrp.RequestData.ParcelLocalID, lsrp.RequestData.ReportType, lsrp.RequestData.RequestFlags, Utils.BytesToString(lsrp.RequestData.Filter), this);
  9200. }
  9201. private void HandleParcelDwellRequest(Packet Pack)
  9202. {
  9203. ParcelDwellRequestPacket dwellrq = (ParcelDwellRequestPacket)Pack;
  9204. if (dwellrq.AgentData.SessionID != SessionId || dwellrq.AgentData.AgentID != AgentId)
  9205. return;
  9206. OnParcelDwellRequest?.Invoke(dwellrq.Data.LocalID, this);
  9207. }
  9208. #endregion Parcel related packets
  9209. #region Estate Packets
  9210. private static double m_lastMapRegenTime = Double.MinValue;
  9211. private void HandleEstateOwnerMessage(Packet Pack)
  9212. {
  9213. EstateOwnerMessagePacket messagePacket = (EstateOwnerMessagePacket)Pack;
  9214. if (messagePacket.AgentData.SessionID != SessionId || messagePacket.AgentData.AgentID != AgentId)
  9215. return;
  9216. string method = Utils.BytesToString(messagePacket.MethodData.Method);
  9217. switch (method)
  9218. {
  9219. case "getinfo":
  9220. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9221. {
  9222. OnDetailedEstateDataRequest?.Invoke(this, messagePacket.MethodData.Invoice);
  9223. }
  9224. return;
  9225. case "setregioninfo":
  9226. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9227. {
  9228. OnSetEstateFlagsRequest?.Invoke(convertParamStringToBool(messagePacket.ParamList[0].Parameter), convertParamStringToBool(messagePacket.ParamList[1].Parameter),
  9229. convertParamStringToBool(messagePacket.ParamList[2].Parameter), !convertParamStringToBool(messagePacket.ParamList[3].Parameter),
  9230. Convert.ToInt16(Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[4].Parameter), Culture.NumberFormatInfo)),
  9231. (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[5].Parameter), Culture.NumberFormatInfo),
  9232. Convert.ToInt16(Utils.BytesToString(messagePacket.ParamList[6].Parameter)),
  9233. convertParamStringToBool(messagePacket.ParamList[7].Parameter), convertParamStringToBool(messagePacket.ParamList[8].Parameter));
  9234. }
  9235. return;
  9236. // case "texturebase":
  9237. // if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9238. // {
  9239. // foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9240. // {
  9241. // string s = Utils.BytesToString(block.Parameter);
  9242. // string[] splitField = s.Split(' ');
  9243. // if (splitField.Length == 2)
  9244. // {
  9245. // UUID tempUUID = new UUID(splitField[1]);
  9246. // OnSetEstateTerrainBaseTexture(this, Convert.ToInt16(splitField[0]), tempUUID);
  9247. // }
  9248. // }
  9249. // }
  9250. // break;
  9251. case "texturedetail":
  9252. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9253. {
  9254. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9255. {
  9256. string s = Utils.BytesToString(block.Parameter);
  9257. string[] splitField = s.Split(' ');
  9258. if (splitField.Length == 2)
  9259. {
  9260. Int16 corner = Convert.ToInt16(splitField[0]);
  9261. UUID textureUUID = new UUID(splitField[1]);
  9262. OnSetEstateTerrainDetailTexture?.Invoke(this, corner, textureUUID);
  9263. }
  9264. }
  9265. }
  9266. return;
  9267. case "textureheights":
  9268. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9269. {
  9270. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9271. {
  9272. string s = Utils.BytesToString(block.Parameter);
  9273. string[] splitField = s.Split(' ');
  9274. if (splitField.Length == 3)
  9275. {
  9276. Int16 corner = Convert.ToInt16(splitField[0]);
  9277. float lowValue = (float)Convert.ToDecimal(splitField[1], Culture.NumberFormatInfo);
  9278. float highValue = (float)Convert.ToDecimal(splitField[2], Culture.NumberFormatInfo);
  9279. OnSetEstateTerrainTextureHeights?.Invoke(this, corner, lowValue, highValue);
  9280. }
  9281. }
  9282. }
  9283. return;
  9284. case "texturecommit":
  9285. OnCommitEstateTerrainTextureRequest?.Invoke(this);
  9286. return;
  9287. case "setregionterrain":
  9288. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9289. {
  9290. if (messagePacket.ParamList.Length != 9)
  9291. {
  9292. m_log.Error("EstateOwnerMessage: SetRegionTerrain method has a ParamList of invalid length");
  9293. }
  9294. else
  9295. {
  9296. try
  9297. {
  9298. string tmp = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  9299. if (!tmp.Contains(".")) tmp += ".00";
  9300. float WaterHeight = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
  9301. tmp = Utils.BytesToString(messagePacket.ParamList[1].Parameter);
  9302. if (!tmp.Contains(".")) tmp += ".00";
  9303. float TerrainRaiseLimit = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
  9304. tmp = Utils.BytesToString(messagePacket.ParamList[2].Parameter);
  9305. if (!tmp.Contains(".")) tmp += ".00";
  9306. float TerrainLowerLimit = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
  9307. bool UseEstateSun = convertParamStringToBool(messagePacket.ParamList[3].Parameter);
  9308. bool UseFixedSun = convertParamStringToBool(messagePacket.ParamList[4].Parameter);
  9309. float SunHour = (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[5].Parameter), Culture.NumberFormatInfo);
  9310. bool UseGlobal = convertParamStringToBool(messagePacket.ParamList[6].Parameter);
  9311. bool EstateFixedSun = convertParamStringToBool(messagePacket.ParamList[7].Parameter);
  9312. float EstateSunHour = (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[8].Parameter), Culture.NumberFormatInfo);
  9313. OnSetRegionTerrainSettings?.Invoke(WaterHeight, TerrainRaiseLimit, TerrainLowerLimit, UseEstateSun, UseFixedSun, SunHour, UseGlobal, EstateFixedSun, EstateSunHour);
  9314. }
  9315. catch (Exception ex)
  9316. {
  9317. m_log.Error("EstateOwnerMessage: Exception while setting terrain settings: \n" + messagePacket + "\n" + ex);
  9318. }
  9319. }
  9320. }
  9321. return;
  9322. case "restart":
  9323. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9324. {
  9325. // There's only 1 block in the estateResetSim.. and that's the number of seconds till restart.
  9326. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9327. {
  9328. float timeSeconds;
  9329. Utils.TryParseSingle(Utils.BytesToString(block.Parameter), out timeSeconds);
  9330. timeSeconds = (int)timeSeconds;
  9331. OnEstateRestartSimRequest?.Invoke(this, (int)timeSeconds);
  9332. }
  9333. }
  9334. return;
  9335. case "estatechangecovenantid":
  9336. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9337. {
  9338. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9339. {
  9340. UUID newCovenantID = new UUID(Utils.BytesToString(block.Parameter));
  9341. OnEstateChangeCovenantRequest?.Invoke(this, newCovenantID);
  9342. }
  9343. }
  9344. return;
  9345. case "estateaccessdelta": // Estate access delta manages the banlist and allow list too.
  9346. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9347. {
  9348. int estateAccessType = Convert.ToInt16(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9349. OnUpdateEstateAccessDeltaRequest?.Invoke(this, messagePacket.MethodData.Invoice, estateAccessType, new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter)));
  9350. }
  9351. return;
  9352. case "simulatormessage":
  9353. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9354. {
  9355. UUID invoice = messagePacket.MethodData.Invoice;
  9356. UUID SenderID = new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  9357. string SenderName = Utils.BytesToString(messagePacket.ParamList[3].Parameter);
  9358. string Message = Utils.BytesToString(messagePacket.ParamList[4].Parameter);
  9359. UUID sessionID = messagePacket.AgentData.SessionID;
  9360. OnSimulatorBlueBoxMessageRequest?.Invoke(this, invoice, SenderID, sessionID, SenderName, Message);
  9361. }
  9362. return;
  9363. case "instantmessage":
  9364. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9365. {
  9366. if (messagePacket.ParamList.Length < 2)
  9367. return;
  9368. UUID invoice = messagePacket.MethodData.Invoice;
  9369. UUID sessionID = messagePacket.AgentData.SessionID;
  9370. UUID SenderID;
  9371. string SenderName;
  9372. string Message;
  9373. if (messagePacket.ParamList.Length < 5)
  9374. {
  9375. SenderID = AgentId;
  9376. SenderName = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  9377. Message = Utils.BytesToString(messagePacket.ParamList[1].Parameter);
  9378. }
  9379. else
  9380. {
  9381. SenderID = new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  9382. SenderName = Utils.BytesToString(messagePacket.ParamList[3].Parameter);
  9383. Message = Utils.BytesToString(messagePacket.ParamList[4].Parameter);
  9384. }
  9385. OnEstateBlueBoxMessageRequest?.Invoke(this, invoice, SenderID, sessionID, SenderName, Message);
  9386. }
  9387. return;
  9388. case "setregiondebug":
  9389. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9390. {
  9391. UUID invoice = messagePacket.MethodData.Invoice;
  9392. UUID SenderID = messagePacket.AgentData.AgentID;
  9393. bool scripted = convertParamStringToBool(messagePacket.ParamList[0].Parameter);
  9394. bool collisionEvents = convertParamStringToBool(messagePacket.ParamList[1].Parameter);
  9395. bool physics = convertParamStringToBool(messagePacket.ParamList[2].Parameter);
  9396. OnEstateDebugRegionRequest?.Invoke(this, invoice, SenderID, scripted, collisionEvents, physics);
  9397. }
  9398. return;
  9399. case "teleporthomeuser":
  9400. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9401. {
  9402. UUID invoice = messagePacket.MethodData.Invoice;
  9403. UUID SenderID = messagePacket.AgentData.AgentID;
  9404. UUID Prey;
  9405. if(UUID.TryParse(Utils.BytesToString(messagePacket.ParamList[1].Parameter), out Prey))
  9406. OnEstateTeleportOneUserHomeRequest?.Invoke(this, invoice, SenderID, Prey, false);
  9407. }
  9408. return;
  9409. case "teleporthomeallusers":
  9410. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9411. {
  9412. UUID invoice = messagePacket.MethodData.Invoice;
  9413. UUID SenderID = messagePacket.AgentData.AgentID;
  9414. OnEstateTeleportAllUsersHomeRequest?.Invoke(this, invoice, SenderID);
  9415. }
  9416. return;
  9417. case "colliders":
  9418. OnLandStatRequest?.Invoke(0, 1, 0, "", this);
  9419. return;
  9420. case "scripts":
  9421. OnLandStatRequest?.Invoke(0, 0, 0, "", this);
  9422. return;
  9423. case "terrain":
  9424. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9425. {
  9426. if (messagePacket.ParamList.Length > 0)
  9427. {
  9428. string p0 = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  9429. if (p0 == "bake")
  9430. {
  9431. OnBakeTerrain?.Invoke(this);
  9432. }
  9433. else if (p0 == "download filename")
  9434. {
  9435. if (messagePacket.ParamList.Length > 1)
  9436. {
  9437. OnRequestTerrain?.Invoke(this, Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9438. }
  9439. }
  9440. else if (p0 == "upload filename")
  9441. {
  9442. if (messagePacket.ParamList.Length > 1)
  9443. {
  9444. OnUploadTerrain?.Invoke(this, Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9445. }
  9446. }
  9447. }
  9448. }
  9449. return;
  9450. case "estatechangeinfo":
  9451. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9452. {
  9453. UUID invoice = messagePacket.MethodData.Invoice;
  9454. UUID SenderID = messagePacket.AgentData.AgentID;
  9455. UInt32 param1 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9456. UInt32 param2 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  9457. OnEstateChangeInfo?.Invoke(this, invoice, SenderID, param1, param2);
  9458. }
  9459. return;
  9460. case "telehub":
  9461. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9462. {
  9463. UUID invoice = messagePacket.MethodData.Invoice;
  9464. UUID SenderID = messagePacket.AgentData.AgentID;
  9465. UInt32 param1 = 0u;
  9466. string command = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  9467. if (command != "info ui")
  9468. {
  9469. try
  9470. {
  9471. param1 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9472. }
  9473. catch
  9474. {
  9475. }
  9476. }
  9477. OnEstateManageTelehub?.Invoke(this, invoice, SenderID, command, param1);
  9478. }
  9479. return;
  9480. case "refreshmapvisibility":
  9481. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9482. {
  9483. IWorldMapModule mapModule = Scene.RequestModuleInterface<IWorldMapModule>();
  9484. if (mapModule == null)
  9485. {
  9486. SendAlertMessage("Terrain map generator not avaiable");
  9487. return;
  9488. }
  9489. if (m_lastMapRegenTime == Double.MaxValue)
  9490. {
  9491. SendAlertMessage("Terrain map generation still in progress");
  9492. return;
  9493. }
  9494. double now = Util.GetTimeStamp();
  9495. if (now - m_lastMapRegenTime < 120) // 2 minutes global cool down
  9496. {
  9497. SendAlertMessage("Please wait at least 2 minutes between map generation commands");
  9498. return;
  9499. }
  9500. m_lastMapRegenTime = Double.MaxValue;
  9501. m_scene.RegenerateMaptileAndReregister(this, null);
  9502. SendAlertMessage("Terrain map generated");
  9503. m_lastMapRegenTime = now;
  9504. }
  9505. return;
  9506. case "kickestate":
  9507. if(m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9508. {
  9509. UUID invoice = messagePacket.MethodData.Invoice;
  9510. UUID SenderID = messagePacket.AgentData.AgentID;
  9511. UUID Prey;
  9512. UUID.TryParse(Utils.BytesToString(messagePacket.ParamList[0].Parameter), out Prey);
  9513. OnEstateTeleportOneUserHomeRequest?.Invoke(this, invoice, SenderID, Prey, true);
  9514. }
  9515. return;
  9516. default:
  9517. m_log.WarnFormat(
  9518. "[LLCLIENTVIEW]: EstateOwnerMessage: Unknown method {0} requested for {1} in {2}",
  9519. method, Name, Scene.Name);
  9520. for (int i = 0; i < messagePacket.ParamList.Length; i++)
  9521. {
  9522. EstateOwnerMessagePacket.ParamListBlock block = messagePacket.ParamList[i];
  9523. string data = (string)Utils.BytesToString(block.Parameter);
  9524. m_log.DebugFormat("[LLCLIENTVIEW]: Param {0}={1}", i, data);
  9525. }
  9526. return;
  9527. }
  9528. //int parcelID, uint reportType, uint requestflags, string filter
  9529. //lsrp.RequestData.ParcelLocalID;
  9530. //lsrp.RequestData.ReportType; // 1 = colliders, 0 = scripts
  9531. //lsrp.RequestData.RequestFlags;
  9532. //lsrp.RequestData.Filter;
  9533. }
  9534. private void HandleRequestRegionInfo(Packet Pack)
  9535. {
  9536. RequestRegionInfoPacket.AgentDataBlock mPacket = ((RequestRegionInfoPacket)Pack).AgentData;
  9537. if (mPacket.SessionID != SessionId || mPacket.AgentID != AgentId)
  9538. return;
  9539. OnRegionInfoRequest?.Invoke(this);
  9540. }
  9541. private void HandleEstateCovenantRequest(Packet Pack)
  9542. {
  9543. EstateCovenantRequestPacket.AgentDataBlock epack = ((EstateCovenantRequestPacket)Pack).AgentData;
  9544. if (epack.SessionID != SessionId || epack.AgentID != AgentId)
  9545. return;
  9546. OnEstateCovenantRequest?.Invoke(this);
  9547. }
  9548. #endregion Estate Packets
  9549. #region GodPackets
  9550. private void HandleRequestGodlikePowers(Packet Pack)
  9551. {
  9552. RequestGodlikePowersPacket rglpPack = (RequestGodlikePowersPacket)Pack;
  9553. RequestGodlikePowersPacket.AgentDataBlock ablock = rglpPack.AgentData;
  9554. if (ablock.SessionID != SessionId || ablock.AgentID != AgentId)
  9555. return;
  9556. RequestGodlikePowersPacket.RequestBlockBlock rblock = rglpPack.RequestBlock;
  9557. UUID token = rblock.Token;
  9558. OnRequestGodlikePowers?.Invoke(ablock.AgentID, ablock.SessionID, token, rblock.Godlike);
  9559. }
  9560. private void HandleGodUpdateRegionInfoUpdate(Packet packet)
  9561. {
  9562. GodUpdateRegionInfoPacket GodUpdateRegionInfo = (GodUpdateRegionInfoPacket)packet;
  9563. if (GodUpdateRegionInfo.AgentData.SessionID != SessionId || GodUpdateRegionInfo.AgentData.AgentID != AgentId)
  9564. return;
  9565. OnGodUpdateRegionInfoUpdate?.Invoke(this,
  9566. GodUpdateRegionInfo.RegionInfo.BillableFactor,
  9567. GodUpdateRegionInfo.RegionInfo.EstateID,
  9568. GodUpdateRegionInfo.RegionInfo.RegionFlags,
  9569. GodUpdateRegionInfo.RegionInfo.SimName,
  9570. GodUpdateRegionInfo.RegionInfo.RedirectGridX,
  9571. GodUpdateRegionInfo.RegionInfo.RedirectGridY);
  9572. }
  9573. private void HandleSimWideDeletes(Packet packet)
  9574. {
  9575. SimWideDeletesPacket SimWideDeletesRequest = (SimWideDeletesPacket)packet;
  9576. if(SimWideDeletesRequest.AgentData.AgentID != AgentId || SimWideDeletesRequest.AgentData.SessionID != SessionId)
  9577. return;
  9578. OnSimWideDeletes?.Invoke(this, SimWideDeletesRequest.AgentData.AgentID,(int)SimWideDeletesRequest.DataBlock.Flags,SimWideDeletesRequest.DataBlock.TargetID);
  9579. }
  9580. private void HandleGodlikeMessage(Packet packet)
  9581. {
  9582. GodlikeMessagePacket GodlikeMessage = (GodlikeMessagePacket)packet;
  9583. if (GodlikeMessage.AgentData.SessionID != SessionId || GodlikeMessage.AgentData.AgentID != AgentId)
  9584. return;
  9585. onGodlikeMessage?.Invoke(this,
  9586. GodlikeMessage.MethodData.Invoice,
  9587. GodlikeMessage.MethodData.Method,
  9588. GodlikeMessage.ParamList[0].Parameter);
  9589. }
  9590. private void HandleSaveStatePacket(Packet packet)
  9591. {
  9592. StateSavePacket SaveStateMessage = (StateSavePacket)packet;
  9593. if (SaveStateMessage.AgentData.SessionID != SessionId || SaveStateMessage.AgentData.AgentID != AgentId)
  9594. return;
  9595. OnSaveState?.Invoke(this,SaveStateMessage.AgentData.AgentID);
  9596. }
  9597. private void HandleGodKickUser(Packet Pack)
  9598. {
  9599. GodKickUserPacket gkupack = (GodKickUserPacket)Pack;
  9600. if (gkupack.UserInfo.GodSessionID != SessionId || gkupack.UserInfo.GodID != AgentId)
  9601. return;
  9602. OnGodKickUser?.Invoke(gkupack.UserInfo.GodID, gkupack.UserInfo.AgentID, gkupack.UserInfo.KickFlags, gkupack.UserInfo.Reason);
  9603. }
  9604. #endregion GodPackets
  9605. #region Economy/Transaction Packets
  9606. private void HandleMoneyBalanceRequest(Packet Pack)
  9607. {
  9608. MoneyBalanceRequestPacket moneybalancerequestpacket = (MoneyBalanceRequestPacket)Pack;
  9609. if (moneybalancerequestpacket.AgentData.SessionID != SessionId || moneybalancerequestpacket.AgentData.AgentID != AgentId)
  9610. return;
  9611. OnMoneyBalanceRequest?.Invoke(this, moneybalancerequestpacket.AgentData.AgentID, moneybalancerequestpacket.AgentData.SessionID, moneybalancerequestpacket.MoneyData.TransactionID);
  9612. }
  9613. private void HandleEconomyDataRequest(Packet Pack)
  9614. {
  9615. OnEconomyDataRequest?.Invoke(this);
  9616. }
  9617. private void HandleRequestPayPrice(Packet Pack)
  9618. {
  9619. RequestPayPricePacket requestPayPricePacket = (RequestPayPricePacket)Pack;
  9620. OnRequestPayPrice?.Invoke(this, requestPayPricePacket.ObjectData.ObjectID);
  9621. }
  9622. private void HandleObjectSaleInfo(Packet Pack)
  9623. {
  9624. if(OnObjectSaleInfo == null)
  9625. return;
  9626. ObjectSaleInfoPacket objectSaleInfoPacket = (ObjectSaleInfoPacket)Pack;
  9627. if (objectSaleInfoPacket.AgentData.SessionID != SessionId || objectSaleInfoPacket.AgentData.AgentID != AgentId)
  9628. return;
  9629. foreach (ObjectSaleInfoPacket.ObjectDataBlock d in objectSaleInfoPacket.ObjectData)
  9630. {
  9631. OnObjectSaleInfo?.Invoke(this,
  9632. AgentId,
  9633. SessionId,
  9634. d.LocalID,
  9635. d.SaleType,
  9636. d.SalePrice);
  9637. }
  9638. }
  9639. private void HandleObjectBuy(Packet Pack)
  9640. {
  9641. if(OnObjectBuy == null)
  9642. return;
  9643. ObjectBuyPacket objectBuyPacket = (ObjectBuyPacket)Pack;
  9644. if (objectBuyPacket.AgentData.SessionID != SessionId || objectBuyPacket.AgentData.AgentID != AgentId)
  9645. return;
  9646. foreach (ObjectBuyPacket.ObjectDataBlock d in objectBuyPacket.ObjectData)
  9647. {
  9648. OnObjectBuy?.Invoke(this,
  9649. objectBuyPacket.AgentData.AgentID,
  9650. objectBuyPacket.AgentData.SessionID,
  9651. objectBuyPacket.AgentData.GroupID,
  9652. objectBuyPacket.AgentData.CategoryID,
  9653. d.ObjectLocalID,
  9654. d.SaleType,
  9655. d.SalePrice);
  9656. }
  9657. }
  9658. #endregion Economy/Transaction Packets
  9659. #region Script Packets
  9660. private void HandleGetScriptRunning(Packet Pack)
  9661. {
  9662. GetScriptRunningPacket scriptRunning = (GetScriptRunningPacket)Pack;
  9663. OnGetScriptRunning?.Invoke(this, scriptRunning.Script.ObjectID, scriptRunning.Script.ItemID);
  9664. }
  9665. private void HandleSetScriptRunning(Packet Pack)
  9666. {
  9667. SetScriptRunningPacket setScriptRunning = (SetScriptRunningPacket)Pack;
  9668. if (setScriptRunning.AgentData.SessionID != SessionId || setScriptRunning.AgentData.AgentID != AgentId)
  9669. return;
  9670. OnSetScriptRunning?.Invoke(this, setScriptRunning.Script.ObjectID, setScriptRunning.Script.ItemID, setScriptRunning.Script.Running);
  9671. }
  9672. private void HandleScriptReset(Packet Pack)
  9673. {
  9674. ScriptResetPacket scriptResetPacket = (ScriptResetPacket)Pack;
  9675. if (scriptResetPacket.AgentData.SessionID != SessionId || scriptResetPacket.AgentData.AgentID != AgentId)
  9676. return;
  9677. OnScriptReset?.Invoke(this, scriptResetPacket.Script.ObjectID, scriptResetPacket.Script.ItemID);
  9678. }
  9679. #endregion Script Packets
  9680. #region Gesture Managment
  9681. private void HandleActivateGestures(Packet Pack)
  9682. {
  9683. if(OnActivateGesture == null)
  9684. return;
  9685. ActivateGesturesPacket activateGesturePacket = (ActivateGesturesPacket)Pack;
  9686. if (activateGesturePacket.AgentData.SessionID != SessionId || activateGesturePacket.AgentData.AgentID != AgentId)
  9687. return;
  9688. ActivateGesturesPacket.DataBlock[] data = activateGesturePacket.Data;
  9689. for (int i= 0; i < data.Length; ++i)
  9690. {
  9691. OnActivateGesture?.Invoke(this,
  9692. data[i].AssetID,
  9693. data[i].ItemID);
  9694. }
  9695. }
  9696. private void HandleDeactivateGestures(Packet Pack)
  9697. {
  9698. if(OnDeactivateGesture == null)
  9699. return;
  9700. DeactivateGesturesPacket deactivateGesturePacket = (DeactivateGesturesPacket)Pack;
  9701. if (deactivateGesturePacket.AgentData.SessionID != SessionId || deactivateGesturePacket.AgentData.AgentID != AgentId)
  9702. return;
  9703. DeactivateGesturesPacket.DataBlock[] data = deactivateGesturePacket.Data;
  9704. for (int i = 0; i < data.Length; ++i)
  9705. {
  9706. OnDeactivateGesture?.Invoke(this, data[i].ItemID);
  9707. }
  9708. }
  9709. #endregion Gesture Managment
  9710. private void HandleObjectOwner(Packet Pack)
  9711. {
  9712. if (OnObjectOwner == null)
  9713. return;
  9714. ObjectOwnerPacket objectOwnerPacket = (ObjectOwnerPacket)Pack;
  9715. if (objectOwnerPacket.AgentData.SessionID != SessionId || objectOwnerPacket.AgentData.AgentID != AgentId)
  9716. return;
  9717. List<uint> localIDs = new List<uint>();
  9718. foreach (ObjectOwnerPacket.ObjectDataBlock d in objectOwnerPacket.ObjectData)
  9719. localIDs.Add(d.ObjectLocalID);
  9720. OnObjectOwner?.Invoke(this, objectOwnerPacket.HeaderData.OwnerID, objectOwnerPacket.HeaderData.GroupID, localIDs);
  9721. }
  9722. private void HandleAgentFOV(Packet Pack)
  9723. {
  9724. AgentFOVPacket fovPacket = (AgentFOVPacket)Pack;
  9725. if(fovPacket.AgentData.AgentID != AgentId || fovPacket.AgentData.SessionID != SessionId)
  9726. return;
  9727. if (fovPacket.FOVBlock.GenCounter > m_agentFOVCounter)
  9728. {
  9729. m_agentFOVCounter = fovPacket.FOVBlock.GenCounter;
  9730. OnAgentFOV?.Invoke(this, fovPacket.FOVBlock.VerticalAngle);
  9731. }
  9732. }
  9733. #region unimplemented handlers
  9734. private void HandleViewerStats(Packet Pack)
  9735. {
  9736. // TODO: handle this packet
  9737. //m_log.Warn("[CLIENT]: unhandled ViewerStats packet");
  9738. }
  9739. private void HandleMapItemRequest(Packet Pack)
  9740. {
  9741. MapItemRequestPacket mirpk = (MapItemRequestPacket)Pack;
  9742. if (mirpk.AgentData.SessionID != SessionId || mirpk.AgentData.AgentID != AgentId)
  9743. return;
  9744. //m_log.Debug(mirpk.ToString());
  9745. try
  9746. {
  9747. OnMapItemRequest?.Invoke(this, mirpk.AgentData.Flags, mirpk.AgentData.EstateID,
  9748. mirpk.AgentData.Godlike, mirpk.RequestData.ItemType,
  9749. mirpk.RequestData.RegionHandle);
  9750. }
  9751. catch( Exception e)
  9752. {
  9753. m_log.ErrorFormat("{0} HandleMapItemRequest exception: {1} : {2}", LogHeader, e.Message, e.StackTrace);
  9754. }
  9755. }
  9756. private void HandleTransferAbort(Packet Pack)
  9757. {
  9758. }
  9759. private void HandleMuteListRequest(Packet Pack)
  9760. {
  9761. MuteListRequestPacket muteListRequest = (MuteListRequestPacket)Pack;
  9762. if (muteListRequest.AgentData.SessionID != SessionId || muteListRequest.AgentData.AgentID != AgentId)
  9763. return;
  9764. if (OnMuteListRequest != null)
  9765. {
  9766. OnMuteListRequest?.Invoke(this, muteListRequest.MuteData.MuteCRC);
  9767. }
  9768. else
  9769. {
  9770. if(muteListRequest.MuteData.MuteCRC == 0)
  9771. SendEmpytMuteList();
  9772. else
  9773. SendUseCachedMuteList();
  9774. }
  9775. }
  9776. private void HandleUpdateMuteListEntry(Packet packet)
  9777. {
  9778. UpdateMuteListEntryPacket UpdateMuteListEntry = (UpdateMuteListEntryPacket)packet;
  9779. if (UpdateMuteListEntry.AgentData.SessionID != SessionId || UpdateMuteListEntry.AgentData.AgentID != AgentId)
  9780. return;
  9781. OnUpdateMuteListEntry?.Invoke(this, UpdateMuteListEntry.MuteData.MuteID,
  9782. Utils.BytesToString(UpdateMuteListEntry.MuteData.MuteName),
  9783. UpdateMuteListEntry.MuteData.MuteType,
  9784. UpdateMuteListEntry.MuteData.MuteFlags);
  9785. }
  9786. private void HandleRemoveMuteListEntry(Packet packet)
  9787. {
  9788. RemoveMuteListEntryPacket RemoveMuteListEntry = (RemoveMuteListEntryPacket)packet;
  9789. if (RemoveMuteListEntry.AgentData.SessionID != SessionId || RemoveMuteListEntry.AgentData.AgentID != AgentId)
  9790. return;
  9791. OnRemoveMuteListEntry?.Invoke(this,
  9792. RemoveMuteListEntry.MuteData.MuteID,
  9793. Utils.BytesToString(RemoveMuteListEntry.MuteData.MuteName));
  9794. }
  9795. private void HandleUserReport(Packet packet)
  9796. {
  9797. UserReportPacket UserReport = (UserReportPacket)packet;
  9798. if (UserReport.AgentData.SessionID != SessionId || UserReport.AgentData.AgentID != AgentId)
  9799. return;
  9800. OnUserReport?.Invoke(this,
  9801. Utils.BytesToString(UserReport.ReportData.AbuseRegionName),
  9802. UserReport.ReportData.AbuserID,
  9803. UserReport.ReportData.Category,
  9804. UserReport.ReportData.CheckFlags,
  9805. Utils.BytesToString(UserReport.ReportData.Details),
  9806. UserReport.ReportData.ObjectID,
  9807. UserReport.ReportData.Position,
  9808. UserReport.ReportData.ReportType,
  9809. UserReport.ReportData.ScreenshotID,
  9810. Utils.BytesToString(UserReport.ReportData.Summary),
  9811. UserReport.AgentData.AgentID);
  9812. }
  9813. private void HandleSendPostcard(Packet packet)
  9814. {
  9815. // SendPostcardPacket SendPostcard =
  9816. // (SendPostcardPacket)packet;
  9817. OnSendPostcard?.Invoke(this);
  9818. }
  9819. private void HandleChangeInventoryItemFlags(Packet packet)
  9820. {
  9821. if(OnChangeInventoryItemFlags == null)
  9822. return;
  9823. ChangeInventoryItemFlagsPacket ChangeInventoryItemFlags = (ChangeInventoryItemFlagsPacket)packet;
  9824. if (ChangeInventoryItemFlags.AgentData.SessionID != SessionId || ChangeInventoryItemFlags.AgentData.AgentID != AgentId)
  9825. return;
  9826. foreach(ChangeInventoryItemFlagsPacket.InventoryDataBlock b in ChangeInventoryItemFlags.InventoryData)
  9827. OnChangeInventoryItemFlags?.Invoke(this, b.ItemID, b.Flags);
  9828. }
  9829. private void HandleUseCircuitCode(Packet Pack)
  9830. {
  9831. /*
  9832. UseCircuitCodePacket uccp = (UseCircuitCodePacket)Pack;
  9833. if(uccp.CircuitCode.ID == m_agentId &&
  9834. uccp.CircuitCode.SessionID == m_sessionId &&
  9835. uccp.CircuitCode.Code == m_circuitCode &&
  9836. SceneAgent != null &&
  9837. !((ScenePresence)SceneAgent).IsDeleted
  9838. )
  9839. SendRegionHandshake(); // possible someone returning
  9840. */
  9841. }
  9842. private void HandleCreateNewOutfitAttachments(Packet Pack)
  9843. {
  9844. if(OnMoveItemsAndLeaveCopy == null)
  9845. return;
  9846. CreateNewOutfitAttachmentsPacket packet = (CreateNewOutfitAttachmentsPacket)Pack;
  9847. if (packet.AgentData.SessionID != SessionId || packet.AgentData.AgentID != AgentId)
  9848. return;
  9849. List<InventoryItemBase> items = new List<InventoryItemBase>();
  9850. foreach (CreateNewOutfitAttachmentsPacket.ObjectDataBlock n in packet.ObjectData)
  9851. {
  9852. InventoryItemBase b = new InventoryItemBase();
  9853. b.ID = n.OldItemID;
  9854. b.Folder = n.OldFolderID;
  9855. items.Add(b);
  9856. }
  9857. OnMoveItemsAndLeaveCopy?.Invoke(this, items, packet.HeaderData.NewFolderID);
  9858. }
  9859. private void HandleAgentHeightWidth(Packet Pack)
  9860. {
  9861. }
  9862. private void HandleInventoryDescendents(Packet Pack)
  9863. {
  9864. }
  9865. #endregion unimplemented handlers
  9866. #region Dir handlers
  9867. private void HandleDirPlacesQuery(Packet Pack)
  9868. {
  9869. DirPlacesQueryPacket dirPlacesQueryPacket = (DirPlacesQueryPacket)Pack;
  9870. if (dirPlacesQueryPacket.AgentData.SessionID != SessionId || dirPlacesQueryPacket.AgentData.AgentID != AgentId)
  9871. return;
  9872. OnDirPlacesQuery?.Invoke(this,
  9873. dirPlacesQueryPacket.QueryData.QueryID,
  9874. Utils.BytesToString(
  9875. dirPlacesQueryPacket.QueryData.QueryText),
  9876. (int)dirPlacesQueryPacket.QueryData.QueryFlags,
  9877. (int)dirPlacesQueryPacket.QueryData.Category,
  9878. Utils.BytesToString(
  9879. dirPlacesQueryPacket.QueryData.SimName),
  9880. dirPlacesQueryPacket.QueryData.QueryStart);
  9881. }
  9882. private void HandleDirFindQuery(Packet Pack)
  9883. {
  9884. DirFindQueryPacket dirFindQueryPacket = (DirFindQueryPacket)Pack;
  9885. if (dirFindQueryPacket.AgentData.SessionID != SessionId || dirFindQueryPacket.AgentData.AgentID != AgentId)
  9886. return;
  9887. OnDirFindQuery?.Invoke(this,
  9888. dirFindQueryPacket.QueryData.QueryID,
  9889. Utils.BytesToString(
  9890. dirFindQueryPacket.QueryData.QueryText).Trim(),
  9891. dirFindQueryPacket.QueryData.QueryFlags,
  9892. dirFindQueryPacket.QueryData.QueryStart);
  9893. }
  9894. private void HandleDirLandQuery(Packet Pack)
  9895. {
  9896. DirLandQueryPacket dirLandQueryPacket = (DirLandQueryPacket)Pack;
  9897. if (dirLandQueryPacket.AgentData.SessionID != SessionId || dirLandQueryPacket.AgentData.AgentID != AgentId)
  9898. return;
  9899. OnDirLandQuery?.Invoke(this,
  9900. dirLandQueryPacket.QueryData.QueryID,
  9901. dirLandQueryPacket.QueryData.QueryFlags,
  9902. dirLandQueryPacket.QueryData.SearchType,
  9903. dirLandQueryPacket.QueryData.Price,
  9904. dirLandQueryPacket.QueryData.Area,
  9905. dirLandQueryPacket.QueryData.QueryStart);
  9906. }
  9907. private void HandleDirPopularQuery(Packet Pack)
  9908. {
  9909. DirPopularQueryPacket dirPopularQueryPacket = (DirPopularQueryPacket)Pack;
  9910. if (dirPopularQueryPacket.AgentData.SessionID != SessionId || dirPopularQueryPacket.AgentData.AgentID != AgentId)
  9911. return;
  9912. OnDirPopularQuery?.Invoke(this,
  9913. dirPopularQueryPacket.QueryData.QueryID,
  9914. dirPopularQueryPacket.QueryData.QueryFlags);
  9915. }
  9916. private void HandleDirClassifiedQuery(Packet Pack)
  9917. {
  9918. DirClassifiedQueryPacket dirClassifiedQueryPacket = (DirClassifiedQueryPacket)Pack;
  9919. if (dirClassifiedQueryPacket.AgentData.SessionID != SessionId || dirClassifiedQueryPacket.AgentData.AgentID != AgentId)
  9920. return;
  9921. OnDirClassifiedQuery?.Invoke(this,
  9922. dirClassifiedQueryPacket.QueryData.QueryID,
  9923. Utils.BytesToString(
  9924. dirClassifiedQueryPacket.QueryData.QueryText),
  9925. dirClassifiedQueryPacket.QueryData.QueryFlags,
  9926. dirClassifiedQueryPacket.QueryData.Category,
  9927. dirClassifiedQueryPacket.QueryData.QueryStart);
  9928. }
  9929. private void HandleEventInfoRequest(Packet Pack)
  9930. {
  9931. EventInfoRequestPacket eventInfoRequestPacket = (EventInfoRequestPacket)Pack;
  9932. if (eventInfoRequestPacket.AgentData.SessionID != SessionId || eventInfoRequestPacket.AgentData.AgentID != AgentId)
  9933. return;
  9934. OnEventInfoRequest?.Invoke(this, eventInfoRequestPacket.EventData.EventID);
  9935. }
  9936. #endregion
  9937. #region Calling Card
  9938. private void HandleOfferCallingCard(Packet Pack)
  9939. {
  9940. OfferCallingCardPacket offerCallingCardPacket = (OfferCallingCardPacket)Pack;
  9941. if (offerCallingCardPacket.AgentData.SessionID != SessionId || offerCallingCardPacket.AgentData.AgentID != AgentId)
  9942. return;
  9943. OnOfferCallingCard?.Invoke(this,
  9944. offerCallingCardPacket.AgentBlock.DestID,
  9945. offerCallingCardPacket.AgentBlock.TransactionID);
  9946. }
  9947. private void HandleAcceptCallingCard(Packet Pack)
  9948. {
  9949. AcceptCallingCardPacket acceptCallingCardPacket = (AcceptCallingCardPacket)Pack;
  9950. if (acceptCallingCardPacket.AgentData.SessionID != SessionId || acceptCallingCardPacket.AgentData.AgentID != AgentId)
  9951. return;
  9952. // according to http://wiki.secondlife.com/wiki/AcceptCallingCard FolderData should
  9953. // contain exactly one entry
  9954. if (acceptCallingCardPacket.FolderData.Length > 0)
  9955. {
  9956. OnAcceptCallingCard?.Invoke(this,
  9957. acceptCallingCardPacket.TransactionBlock.TransactionID,
  9958. acceptCallingCardPacket.FolderData[0].FolderID);
  9959. }
  9960. }
  9961. private void HandleDeclineCallingCard(Packet Pack)
  9962. {
  9963. DeclineCallingCardPacket declineCallingCardPacket = (DeclineCallingCardPacket)Pack;
  9964. if (declineCallingCardPacket.AgentData.SessionID != SessionId || declineCallingCardPacket.AgentData.AgentID != AgentId)
  9965. return;
  9966. OnDeclineCallingCard?.Invoke(this,
  9967. declineCallingCardPacket.TransactionBlock.TransactionID);
  9968. }
  9969. #endregion Calling Card
  9970. #region Groups
  9971. private void HandleActivateGroup(Packet Pack)
  9972. {
  9973. if (m_GroupsModule == null)
  9974. return;
  9975. ActivateGroupPacket activateGroupPacket = (ActivateGroupPacket)Pack;
  9976. if (activateGroupPacket.AgentData.SessionID != SessionId || activateGroupPacket.AgentData.AgentID != AgentId)
  9977. return;
  9978. m_GroupsModule.ActivateGroup(this, activateGroupPacket.AgentData.GroupID);
  9979. }
  9980. private void HandleGroupVoteHistoryRequest(Packet packet)
  9981. {
  9982. GroupVoteHistoryRequestPacket GroupVoteHistoryRequest = (GroupVoteHistoryRequestPacket)packet;
  9983. if (GroupVoteHistoryRequest.AgentData.SessionID != SessionId || GroupVoteHistoryRequest.AgentData.AgentID != AgentId)
  9984. return;
  9985. OnGroupVoteHistoryRequest?.Invoke(this, AgentId, SessionId, GroupVoteHistoryRequest.GroupData.GroupID, GroupVoteHistoryRequest.TransactionData.TransactionID);
  9986. }
  9987. private void HandleGroupActiveProposalsRequest(Packet packet)
  9988. {
  9989. GroupActiveProposalsRequestPacket GroupActiveProposalsRequest = (GroupActiveProposalsRequestPacket)packet;
  9990. if (GroupActiveProposalsRequest.AgentData.SessionID != SessionId || GroupActiveProposalsRequest.AgentData.AgentID != AgentId)
  9991. return;
  9992. OnGroupActiveProposalsRequest?.Invoke(this, AgentId, SessionId, GroupActiveProposalsRequest.GroupData.GroupID, GroupActiveProposalsRequest.TransactionData.TransactionID);
  9993. }
  9994. private void HandleGroupAccountDetailsRequest(Packet packet)
  9995. {
  9996. GroupAccountDetailsRequestPacket GroupAccountDetailsRequest = (GroupAccountDetailsRequestPacket)packet;
  9997. if (GroupAccountDetailsRequest.AgentData.SessionID != SessionId || GroupAccountDetailsRequest.AgentData.AgentID != AgentId)
  9998. return;
  9999. OnGroupAccountDetailsRequest?.Invoke(this, AgentId, GroupAccountDetailsRequest.AgentData.GroupID, GroupAccountDetailsRequest.MoneyData.RequestID, SessionId);
  10000. }
  10001. private void HandleGroupAccountSummaryRequest(Packet packet)
  10002. {
  10003. GroupAccountSummaryRequestPacket GroupAccountSummaryRequest = (GroupAccountSummaryRequestPacket)packet;
  10004. if (GroupAccountSummaryRequest.AgentData.SessionID != SessionId || GroupAccountSummaryRequest.AgentData.AgentID != AgentId)
  10005. return;
  10006. OnGroupAccountSummaryRequest?.Invoke(this, AgentId,GroupAccountSummaryRequest.AgentData.GroupID);
  10007. }
  10008. private void HandleGroupTransactionsDetailsRequest(Packet packet)
  10009. {
  10010. GroupAccountTransactionsRequestPacket GroupAccountTransactionsRequest = (GroupAccountTransactionsRequestPacket)packet;
  10011. if (GroupAccountTransactionsRequest.AgentData.SessionID != SessionId || GroupAccountTransactionsRequest.AgentData.AgentID != AgentId)
  10012. return;
  10013. OnGroupAccountTransactionsRequest?.Invoke(this, AgentId,GroupAccountTransactionsRequest.AgentData.GroupID,GroupAccountTransactionsRequest.MoneyData.RequestID, SessionId);
  10014. }
  10015. private void HandleGroupTitlesRequest(Packet Pack)
  10016. {
  10017. if (m_GroupsModule == null)
  10018. return;
  10019. GroupTitlesRequestPacket groupTitlesRequest = (GroupTitlesRequestPacket)Pack;
  10020. if (groupTitlesRequest.AgentData.SessionID != SessionId || groupTitlesRequest.AgentData.AgentID != AgentId)
  10021. return;
  10022. GroupTitlesReplyPacket groupTitlesReply = (GroupTitlesReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupTitlesReply);
  10023. groupTitlesReply.AgentData = new GroupTitlesReplyPacket.AgentDataBlock();
  10024. groupTitlesReply.AgentData.AgentID = AgentId;
  10025. groupTitlesReply.AgentData.GroupID = groupTitlesRequest.AgentData.GroupID;
  10026. groupTitlesReply.AgentData.RequestID = groupTitlesRequest.AgentData.RequestID;
  10027. List<GroupTitlesData> titles = m_GroupsModule.GroupTitlesRequest(this,
  10028. groupTitlesRequest.AgentData.GroupID);
  10029. groupTitlesReply.GroupData = new GroupTitlesReplyPacket.GroupDataBlock[titles.Count];
  10030. int i = 0;
  10031. foreach (GroupTitlesData d in titles)
  10032. {
  10033. groupTitlesReply.GroupData[i] = new GroupTitlesReplyPacket.GroupDataBlock();
  10034. groupTitlesReply.GroupData[i].Title = Util.StringToBytes256(d.Name);
  10035. groupTitlesReply.GroupData[i].RoleID = d.UUID;
  10036. groupTitlesReply.GroupData[i].Selected = d.Selected;
  10037. i++;
  10038. }
  10039. OutPacket(groupTitlesReply, ThrottleOutPacketType.Task);
  10040. }
  10041. UUID lastGroupProfileRequestID = UUID.Zero;
  10042. double lastGroupProfileRequestTS = Util.GetTimeStampMS();
  10043. private void HandleGroupProfileRequest(Packet Pack)
  10044. {
  10045. if(m_GroupsModule == null)
  10046. return;
  10047. GroupProfileRequestPacket groupProfileRequest = (GroupProfileRequestPacket)Pack;
  10048. if (groupProfileRequest.AgentData.SessionID != SessionId || groupProfileRequest.AgentData.AgentID != AgentId)
  10049. return;
  10050. UUID grpID = groupProfileRequest.GroupData.GroupID;
  10051. double ts = Util.GetTimeStampMS();
  10052. if(grpID == lastGroupProfileRequestID && ts - lastGroupProfileRequestTS < 10000)
  10053. return;
  10054. lastGroupProfileRequestID = grpID;
  10055. lastGroupProfileRequestTS = ts;
  10056. GroupProfileReplyPacket groupProfileReply = (GroupProfileReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupProfileReply);
  10057. groupProfileReply.AgentData = new GroupProfileReplyPacket.AgentDataBlock();
  10058. groupProfileReply.GroupData = new GroupProfileReplyPacket.GroupDataBlock();
  10059. groupProfileReply.AgentData.AgentID = AgentId;
  10060. GroupProfileData d = m_GroupsModule.GroupProfileRequest(this, groupProfileRequest.GroupData.GroupID);
  10061. if(d.GroupID == UUID.Zero) // don't send broken data
  10062. return;
  10063. groupProfileReply.GroupData.GroupID = d.GroupID;
  10064. groupProfileReply.GroupData.Name = Util.StringToBytes256(d.Name);
  10065. groupProfileReply.GroupData.Charter = Util.StringToBytes1024(d.Charter);
  10066. groupProfileReply.GroupData.ShowInList = d.ShowInList;
  10067. groupProfileReply.GroupData.MemberTitle = Util.StringToBytes256(d.MemberTitle);
  10068. groupProfileReply.GroupData.PowersMask = d.PowersMask;
  10069. groupProfileReply.GroupData.InsigniaID = d.InsigniaID;
  10070. groupProfileReply.GroupData.FounderID = d.FounderID;
  10071. groupProfileReply.GroupData.MembershipFee = d.MembershipFee;
  10072. groupProfileReply.GroupData.OpenEnrollment = d.OpenEnrollment;
  10073. groupProfileReply.GroupData.Money = d.Money;
  10074. groupProfileReply.GroupData.GroupMembershipCount = d.GroupMembershipCount;
  10075. groupProfileReply.GroupData.GroupRolesCount = d.GroupRolesCount;
  10076. groupProfileReply.GroupData.AllowPublish = d.AllowPublish;
  10077. groupProfileReply.GroupData.MaturePublish = d.MaturePublish;
  10078. groupProfileReply.GroupData.OwnerRole = d.OwnerRole;
  10079. if (m_scene.Permissions.IsGod(AgentId) && (!IsGroupMember(groupProfileRequest.GroupData.GroupID)))
  10080. {
  10081. ScenePresence p;
  10082. if (m_scene.TryGetScenePresence(AgentId, out p))
  10083. {
  10084. if (p.IsViewerUIGod)
  10085. {
  10086. groupProfileReply.GroupData.OpenEnrollment = true;
  10087. groupProfileReply.GroupData.MembershipFee = 0;
  10088. }
  10089. }
  10090. }
  10091. OutPacket(groupProfileReply, ThrottleOutPacketType.Task);
  10092. if(grpID == lastGroupProfileRequestID)
  10093. lastGroupProfileRequestTS = Util.GetTimeStampMS() - 7000;
  10094. }
  10095. private void HandleGroupMembersRequest(Packet Pack)
  10096. {
  10097. if (m_GroupsModule == null)
  10098. return;
  10099. GroupMembersRequestPacket groupMembersRequestPacket =
  10100. (GroupMembersRequestPacket)Pack;
  10101. if (groupMembersRequestPacket.AgentData.SessionID != SessionId || groupMembersRequestPacket.AgentData.AgentID != AgentId)
  10102. return;
  10103. List<GroupMembersData> members =
  10104. m_GroupsModule.GroupMembersRequest(this, groupMembersRequestPacket.GroupData.GroupID);
  10105. int memberCount = members.Count;
  10106. int indx = 0;
  10107. while (indx < memberCount)
  10108. {
  10109. int blockCount = memberCount - indx;
  10110. if (blockCount > 25)
  10111. blockCount = 25;
  10112. GroupMembersReplyPacket groupMembersReply = (GroupMembersReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupMembersReply);
  10113. groupMembersReply.AgentData = new GroupMembersReplyPacket.AgentDataBlock();
  10114. groupMembersReply.GroupData = new GroupMembersReplyPacket.GroupDataBlock();
  10115. groupMembersReply.MemberData = new GroupMembersReplyPacket.MemberDataBlock[blockCount];
  10116. groupMembersReply.AgentData.AgentID = AgentId;
  10117. groupMembersReply.GroupData.GroupID = groupMembersRequestPacket.GroupData.GroupID;
  10118. groupMembersReply.GroupData.RequestID = groupMembersRequestPacket.GroupData.RequestID;
  10119. groupMembersReply.GroupData.MemberCount = memberCount;
  10120. for (int i = 0; i < blockCount; i++)
  10121. {
  10122. GroupMembersData m = members[indx++];
  10123. groupMembersReply.MemberData[i] = new GroupMembersReplyPacket.MemberDataBlock();
  10124. groupMembersReply.MemberData[i].AgentID = m.AgentID;
  10125. groupMembersReply.MemberData[i].Contribution = m.Contribution;
  10126. groupMembersReply.MemberData[i].OnlineStatus = Util.StringToBytes256(m.OnlineStatus);
  10127. groupMembersReply.MemberData[i].AgentPowers = m.AgentPowers;
  10128. groupMembersReply.MemberData[i].Title = Util.StringToBytes256(m.Title);
  10129. groupMembersReply.MemberData[i].IsOwner = m.IsOwner;
  10130. }
  10131. OutPacket(groupMembersReply, ThrottleOutPacketType.Task);
  10132. }
  10133. }
  10134. private void HandleGroupRoleDataRequest(Packet Pack)
  10135. {
  10136. if (m_GroupsModule == null)
  10137. return;
  10138. GroupRoleDataRequestPacket groupRolesRequest = (GroupRoleDataRequestPacket)Pack;
  10139. if (groupRolesRequest.AgentData.SessionID != SessionId || groupRolesRequest.AgentData.AgentID != AgentId)
  10140. return;
  10141. GroupRoleDataReplyPacket groupRolesReply = (GroupRoleDataReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupRoleDataReply);
  10142. groupRolesReply.AgentData = new GroupRoleDataReplyPacket.AgentDataBlock();
  10143. groupRolesReply.AgentData.AgentID = AgentId;
  10144. groupRolesReply.GroupData = new GroupRoleDataReplyPacket.GroupDataBlock();
  10145. groupRolesReply.GroupData.GroupID = groupRolesRequest.GroupData.GroupID;
  10146. groupRolesReply.GroupData.RequestID = groupRolesRequest.GroupData.RequestID;
  10147. List<GroupRolesData> titles = m_GroupsModule.GroupRoleDataRequest(this,
  10148. groupRolesRequest.GroupData.GroupID);
  10149. groupRolesReply.GroupData.RoleCount = titles.Count;
  10150. groupRolesReply.RoleData = new GroupRoleDataReplyPacket.RoleDataBlock[titles.Count];
  10151. int i = 0;
  10152. foreach (GroupRolesData d in titles)
  10153. {
  10154. groupRolesReply.RoleData[i] = new GroupRoleDataReplyPacket.RoleDataBlock();
  10155. groupRolesReply.RoleData[i].RoleID = d.RoleID;
  10156. groupRolesReply.RoleData[i].Name = Util.StringToBytes256(d.Name);
  10157. groupRolesReply.RoleData[i].Title = Util.StringToBytes256(d.Title);
  10158. groupRolesReply.RoleData[i].Description = Util.StringToBytes1024(d.Description);
  10159. groupRolesReply.RoleData[i].Powers = d.Powers;
  10160. groupRolesReply.RoleData[i].Members = (uint)d.Members;
  10161. i++;
  10162. }
  10163. OutPacket(groupRolesReply, ThrottleOutPacketType.Task);
  10164. }
  10165. private void HandleGroupRoleMembersRequest(Packet Pack)
  10166. {
  10167. if (m_GroupsModule == null)
  10168. return;
  10169. GroupRoleMembersRequestPacket groupRoleMembersRequest = (GroupRoleMembersRequestPacket)Pack;
  10170. if (groupRoleMembersRequest.AgentData.SessionID != SessionId || groupRoleMembersRequest.AgentData.AgentID != AgentId)
  10171. return;
  10172. List<GroupRoleMembersData> mappings = m_GroupsModule.GroupRoleMembersRequest(this,
  10173. groupRoleMembersRequest.GroupData.GroupID);
  10174. int mappingsCount = mappings.Count;
  10175. while (mappings.Count > 0)
  10176. {
  10177. int pairs = mappings.Count;
  10178. if (pairs > 32)
  10179. pairs = 32;
  10180. GroupRoleMembersReplyPacket groupRoleMembersReply = (GroupRoleMembersReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupRoleMembersReply);
  10181. groupRoleMembersReply.AgentData = new GroupRoleMembersReplyPacket.AgentDataBlock();
  10182. groupRoleMembersReply.AgentData.AgentID = AgentId;
  10183. groupRoleMembersReply.AgentData.GroupID = groupRoleMembersRequest.GroupData.GroupID;
  10184. groupRoleMembersReply.AgentData.RequestID = groupRoleMembersRequest.GroupData.RequestID;
  10185. groupRoleMembersReply.AgentData.TotalPairs = (uint)mappingsCount;
  10186. groupRoleMembersReply.MemberData = new GroupRoleMembersReplyPacket.MemberDataBlock[pairs];
  10187. for (int i = 0; i < pairs; i++)
  10188. {
  10189. GroupRoleMembersData d = mappings[0];
  10190. mappings.RemoveAt(0);
  10191. groupRoleMembersReply.MemberData[i] = new GroupRoleMembersReplyPacket.MemberDataBlock();
  10192. groupRoleMembersReply.MemberData[i].RoleID = d.RoleID;
  10193. groupRoleMembersReply.MemberData[i].MemberID = d.MemberID;
  10194. }
  10195. OutPacket(groupRoleMembersReply, ThrottleOutPacketType.Task);
  10196. }
  10197. }
  10198. private void HandleCreateGroupRequest(Packet Pack)
  10199. {
  10200. if (m_GroupsModule == null)
  10201. return;
  10202. CreateGroupRequestPacket createGroupRequest = (CreateGroupRequestPacket)Pack;
  10203. if (createGroupRequest.AgentData.SessionID != SessionId || createGroupRequest.AgentData.AgentID != AgentId)
  10204. return;
  10205. m_GroupsModule.CreateGroup(this,
  10206. Utils.BytesToString(createGroupRequest.GroupData.Name),
  10207. Utils.BytesToString(createGroupRequest.GroupData.Charter),
  10208. createGroupRequest.GroupData.ShowInList,
  10209. createGroupRequest.GroupData.InsigniaID,
  10210. createGroupRequest.GroupData.MembershipFee,
  10211. createGroupRequest.GroupData.OpenEnrollment,
  10212. createGroupRequest.GroupData.AllowPublish,
  10213. createGroupRequest.GroupData.MaturePublish);
  10214. }
  10215. private void HandleUpdateGroupInfo(Packet Pack)
  10216. {
  10217. if (m_GroupsModule == null)
  10218. return;
  10219. UpdateGroupInfoPacket updateGroupInfo = (UpdateGroupInfoPacket)Pack;
  10220. if (updateGroupInfo.AgentData.SessionID != SessionId || updateGroupInfo.AgentData.AgentID != AgentId)
  10221. return;
  10222. m_GroupsModule.UpdateGroupInfo(this,
  10223. updateGroupInfo.GroupData.GroupID,
  10224. Utils.BytesToString(updateGroupInfo.GroupData.Charter),
  10225. updateGroupInfo.GroupData.ShowInList,
  10226. updateGroupInfo.GroupData.InsigniaID,
  10227. updateGroupInfo.GroupData.MembershipFee,
  10228. updateGroupInfo.GroupData.OpenEnrollment,
  10229. updateGroupInfo.GroupData.AllowPublish,
  10230. updateGroupInfo.GroupData.MaturePublish);
  10231. }
  10232. private void HandleSetGroupAcceptNotices(Packet Pack)
  10233. {
  10234. if (m_GroupsModule == null)
  10235. return;
  10236. SetGroupAcceptNoticesPacket setGroupAcceptNotices = (SetGroupAcceptNoticesPacket)Pack;
  10237. if (setGroupAcceptNotices.AgentData.SessionID != SessionId || setGroupAcceptNotices.AgentData.AgentID != AgentId)
  10238. return;
  10239. m_GroupsModule.SetGroupAcceptNotices(this,
  10240. setGroupAcceptNotices.Data.GroupID,
  10241. setGroupAcceptNotices.Data.AcceptNotices,
  10242. setGroupAcceptNotices.NewData.ListInProfile);
  10243. }
  10244. private void HandleGroupTitleUpdate(Packet Pack)
  10245. {
  10246. GroupTitleUpdatePacket groupTitleUpdate = (GroupTitleUpdatePacket)Pack;
  10247. if (groupTitleUpdate.AgentData.SessionID != SessionId || groupTitleUpdate.AgentData.AgentID != AgentId)
  10248. return;
  10249. m_GroupsModule.GroupTitleUpdate(this,
  10250. groupTitleUpdate.AgentData.GroupID,
  10251. groupTitleUpdate.AgentData.TitleRoleID);
  10252. }
  10253. private void HandleParcelDeedToGroup(Packet Pack)
  10254. {
  10255. if (m_GroupsModule == null)
  10256. return;
  10257. ParcelDeedToGroupPacket parcelDeedToGroup = (ParcelDeedToGroupPacket)Pack;
  10258. if (parcelDeedToGroup.AgentData.SessionID != SessionId || parcelDeedToGroup.AgentData.AgentID != AgentId)
  10259. return;
  10260. OnParcelDeedToGroup?.Invoke(parcelDeedToGroup.Data.LocalID, parcelDeedToGroup.Data.GroupID, this);
  10261. }
  10262. private void HandleGroupNoticesListRequest(Packet Pack)
  10263. {
  10264. if (m_GroupsModule == null)
  10265. return;
  10266. GroupNoticesListRequestPacket groupNoticesListRequest = (GroupNoticesListRequestPacket)Pack;
  10267. if (groupNoticesListRequest.AgentData.SessionID != SessionId || groupNoticesListRequest.AgentData.AgentID != AgentId)
  10268. return;
  10269. GroupNoticeData[] gn = m_GroupsModule.GroupNoticesListRequest(this,
  10270. groupNoticesListRequest.Data.GroupID);
  10271. GroupNoticesListReplyPacket groupNoticesListReply = (GroupNoticesListReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupNoticesListReply);
  10272. groupNoticesListReply.AgentData = new GroupNoticesListReplyPacket.AgentDataBlock();
  10273. groupNoticesListReply.AgentData.AgentID = AgentId;
  10274. groupNoticesListReply.AgentData.GroupID = groupNoticesListRequest.Data.GroupID;
  10275. groupNoticesListReply.Data = new GroupNoticesListReplyPacket.DataBlock[gn.Length];
  10276. int i = 0;
  10277. foreach (GroupNoticeData g in gn)
  10278. {
  10279. groupNoticesListReply.Data[i] = new GroupNoticesListReplyPacket.DataBlock();
  10280. groupNoticesListReply.Data[i].NoticeID = g.NoticeID;
  10281. groupNoticesListReply.Data[i].Timestamp = g.Timestamp;
  10282. groupNoticesListReply.Data[i].FromName = Util.StringToBytes256(g.FromName);
  10283. groupNoticesListReply.Data[i].Subject = Util.StringToBytes256(g.Subject);
  10284. groupNoticesListReply.Data[i].HasAttachment = g.HasAttachment;
  10285. groupNoticesListReply.Data[i].AssetType = g.AssetType;
  10286. i++;
  10287. }
  10288. OutPacket(groupNoticesListReply, ThrottleOutPacketType.Task);
  10289. }
  10290. private void HandleGroupNoticeRequest(Packet Pack)
  10291. {
  10292. if (m_GroupsModule == null)
  10293. return;
  10294. GroupNoticeRequestPacket groupNoticeRequest = (GroupNoticeRequestPacket)Pack;
  10295. if (groupNoticeRequest.AgentData.SessionID != SessionId || groupNoticeRequest.AgentData.AgentID != AgentId)
  10296. return;
  10297. m_GroupsModule.GroupNoticeRequest(this, groupNoticeRequest.Data.GroupNoticeID);
  10298. }
  10299. private void HandleGroupRoleUpdate(Packet Pack)
  10300. {
  10301. if (m_GroupsModule == null)
  10302. return;
  10303. GroupRoleUpdatePacket groupRoleUpdate = (GroupRoleUpdatePacket)Pack;
  10304. if (groupRoleUpdate.AgentData.SessionID != SessionId || groupRoleUpdate.AgentData.AgentID != AgentId)
  10305. return;
  10306. foreach (GroupRoleUpdatePacket.RoleDataBlock d in groupRoleUpdate.RoleData)
  10307. {
  10308. m_GroupsModule.GroupRoleUpdate(this,
  10309. groupRoleUpdate.AgentData.GroupID,
  10310. d.RoleID,
  10311. Utils.BytesToString(d.Name),
  10312. Utils.BytesToString(d.Description),
  10313. Utils.BytesToString(d.Title),
  10314. d.Powers,
  10315. d.UpdateType);
  10316. }
  10317. m_GroupsModule.NotifyChange(groupRoleUpdate.AgentData.GroupID);
  10318. }
  10319. private void HandleGroupRoleChanges(Packet Pack)
  10320. {
  10321. if (m_GroupsModule == null)
  10322. return;
  10323. GroupRoleChangesPacket groupRoleChanges = (GroupRoleChangesPacket)Pack;
  10324. if (groupRoleChanges.AgentData.SessionID != SessionId || groupRoleChanges.AgentData.AgentID != AgentId)
  10325. return;
  10326. foreach (GroupRoleChangesPacket.RoleChangeBlock d in groupRoleChanges.RoleChange)
  10327. {
  10328. m_GroupsModule.GroupRoleChanges(this,
  10329. groupRoleChanges.AgentData.GroupID,
  10330. d.RoleID,
  10331. d.MemberID,
  10332. d.Change);
  10333. }
  10334. m_GroupsModule.NotifyChange(groupRoleChanges.AgentData.GroupID);
  10335. }
  10336. private void HandleJoinGroupRequest(Packet Pack)
  10337. {
  10338. if (m_GroupsModule == null)
  10339. return;
  10340. JoinGroupRequestPacket joinGroupRequest = (JoinGroupRequestPacket)Pack;
  10341. if (joinGroupRequest.AgentData.SessionID != SessionId || joinGroupRequest.AgentData.AgentID != AgentId)
  10342. return;
  10343. m_GroupsModule.JoinGroupRequest(this, joinGroupRequest.GroupData.GroupID);
  10344. }
  10345. private void HandleLeaveGroupRequest(Packet Pack)
  10346. {
  10347. if (m_GroupsModule == null)
  10348. return;
  10349. LeaveGroupRequestPacket leaveGroupRequest = (LeaveGroupRequestPacket)Pack;
  10350. if (leaveGroupRequest.AgentData.SessionID != SessionId || leaveGroupRequest.AgentData.AgentID != AgentId)
  10351. return;
  10352. m_GroupsModule.LeaveGroupRequest(this, leaveGroupRequest.GroupData.GroupID);
  10353. }
  10354. private void HandleEjectGroupMemberRequest(Packet Pack)
  10355. {
  10356. if (m_GroupsModule == null)
  10357. return;
  10358. EjectGroupMemberRequestPacket ejectGroupMemberRequest = (EjectGroupMemberRequestPacket)Pack;
  10359. if (ejectGroupMemberRequest.AgentData.SessionID != SessionId || ejectGroupMemberRequest.AgentData.AgentID != AgentId)
  10360. return;
  10361. foreach (EjectGroupMemberRequestPacket.EjectDataBlock e in ejectGroupMemberRequest.EjectData)
  10362. {
  10363. m_GroupsModule.EjectGroupMemberRequest(this,
  10364. ejectGroupMemberRequest.GroupData.GroupID,
  10365. e.EjecteeID);
  10366. }
  10367. }
  10368. private void HandleInviteGroupRequest(Packet Pack)
  10369. {
  10370. if (m_GroupsModule == null)
  10371. return;
  10372. InviteGroupRequestPacket inviteGroupRequest = (InviteGroupRequestPacket)Pack;
  10373. if (inviteGroupRequest.AgentData.SessionID != SessionId || inviteGroupRequest.AgentData.AgentID != AgentId)
  10374. return;
  10375. foreach (InviteGroupRequestPacket.InviteDataBlock b in inviteGroupRequest.InviteData)
  10376. {
  10377. m_GroupsModule.InviteGroupRequest(this,
  10378. inviteGroupRequest.GroupData.GroupID,
  10379. b.InviteeID,
  10380. b.RoleID);
  10381. }
  10382. }
  10383. #endregion Groups
  10384. private void HandleStartLure(Packet Pack)
  10385. {
  10386. if(OnStartLure == null)
  10387. return;
  10388. StartLurePacket startLureRequest = (StartLurePacket)Pack;
  10389. if (startLureRequest.AgentData.SessionID != SessionId || startLureRequest.AgentData.AgentID != AgentId)
  10390. return;
  10391. for (int i = 0 ; i < startLureRequest.TargetData.Length ; i++)
  10392. {
  10393. OnStartLure?.Invoke(startLureRequest.Info.LureType,
  10394. Utils.BytesToString(
  10395. startLureRequest.Info.Message),
  10396. startLureRequest.TargetData[i].TargetID,
  10397. this);
  10398. }
  10399. }
  10400. private void HandleTeleportLureRequest(Packet Pack)
  10401. {
  10402. TeleportLureRequestPacket teleportLureRequest = (TeleportLureRequestPacket)Pack;
  10403. if (teleportLureRequest.Info.SessionID != SessionId || teleportLureRequest.Info.AgentID != AgentId)
  10404. return;
  10405. OnTeleportLureRequest?.Invoke(
  10406. teleportLureRequest.Info.LureID,
  10407. teleportLureRequest.Info.TeleportFlags,
  10408. this);
  10409. }
  10410. private void HandleClassifiedInfoRequest(Packet Pack)
  10411. {
  10412. ClassifiedInfoRequestPacket classifiedInfoRequest = (ClassifiedInfoRequestPacket)Pack;
  10413. if (classifiedInfoRequest.AgentData.SessionID != SessionId || classifiedInfoRequest.AgentData.AgentID != AgentId)
  10414. return;
  10415. OnClassifiedInfoRequest?.Invoke(
  10416. classifiedInfoRequest.Data.ClassifiedID,
  10417. this);
  10418. }
  10419. private void HandleClassifiedInfoUpdate(Packet Pack)
  10420. {
  10421. ClassifiedInfoUpdatePacket classifiedInfoUpdate = (ClassifiedInfoUpdatePacket)Pack;
  10422. if (classifiedInfoUpdate.AgentData.SessionID != SessionId || classifiedInfoUpdate.AgentData.AgentID != AgentId)
  10423. return;
  10424. OnClassifiedInfoUpdate?.Invoke(
  10425. classifiedInfoUpdate.Data.ClassifiedID,
  10426. classifiedInfoUpdate.Data.Category,
  10427. Utils.BytesToString(
  10428. classifiedInfoUpdate.Data.Name),
  10429. Utils.BytesToString(
  10430. classifiedInfoUpdate.Data.Desc),
  10431. classifiedInfoUpdate.Data.ParcelID,
  10432. classifiedInfoUpdate.Data.ParentEstate,
  10433. classifiedInfoUpdate.Data.SnapshotID,
  10434. new Vector3(
  10435. classifiedInfoUpdate.Data.PosGlobal),
  10436. classifiedInfoUpdate.Data.ClassifiedFlags,
  10437. classifiedInfoUpdate.Data.PriceForListing,
  10438. this);
  10439. }
  10440. private void HandleClassifiedDelete(Packet Pack)
  10441. {
  10442. ClassifiedDeletePacket classifiedDelete = (ClassifiedDeletePacket)Pack;
  10443. if (classifiedDelete.AgentData.SessionID != SessionId || classifiedDelete.AgentData.AgentID != AgentId)
  10444. return;
  10445. OnClassifiedDelete?.Invoke(
  10446. classifiedDelete.Data.ClassifiedID,
  10447. this);
  10448. }
  10449. private void HandleClassifiedGodDelete(Packet Pack)
  10450. {
  10451. ClassifiedGodDeletePacket classifiedGodDelete = (ClassifiedGodDeletePacket)Pack;
  10452. if (classifiedGodDelete.AgentData.SessionID != SessionId || classifiedGodDelete.AgentData.AgentID != AgentId)
  10453. return;
  10454. OnClassifiedGodDelete?.Invoke(
  10455. classifiedGodDelete.Data.ClassifiedID,
  10456. classifiedGodDelete.Data.QueryID,
  10457. this);
  10458. }
  10459. private void HandleEventGodDelete(Packet Pack)
  10460. {
  10461. EventGodDeletePacket eventGodDelete = (EventGodDeletePacket)Pack;
  10462. if (eventGodDelete.AgentData.SessionID != SessionId || eventGodDelete.AgentData.AgentID != AgentId)
  10463. return;
  10464. OnEventGodDelete?.Invoke(
  10465. eventGodDelete.EventData.EventID,
  10466. eventGodDelete.QueryData.QueryID,
  10467. Utils.BytesToString(
  10468. eventGodDelete.QueryData.QueryText),
  10469. eventGodDelete.QueryData.QueryFlags,
  10470. eventGodDelete.QueryData.QueryStart,
  10471. this);
  10472. }
  10473. private void HandleEventNotificationAddRequest(Packet Pack)
  10474. {
  10475. EventNotificationAddRequestPacket eventNotificationAdd = (EventNotificationAddRequestPacket)Pack;
  10476. if (eventNotificationAdd.AgentData.SessionID != SessionId || eventNotificationAdd.AgentData.AgentID != AgentId)
  10477. return;
  10478. OnEventNotificationAddRequest?.Invoke(eventNotificationAdd.EventData.EventID, this);
  10479. }
  10480. private void HandleEventNotificationRemoveRequest(Packet Pack)
  10481. {
  10482. EventNotificationRemoveRequestPacket eventNotificationRemove = (EventNotificationRemoveRequestPacket)Pack;
  10483. if (eventNotificationRemove.AgentData.SessionID != SessionId || eventNotificationRemove.AgentData.AgentID != AgentId)
  10484. return;
  10485. OnEventNotificationRemoveRequest?.Invoke(eventNotificationRemove.EventData.EventID, this);
  10486. }
  10487. private void HandleRetrieveInstantMessages(Packet Pack)
  10488. {
  10489. RetrieveInstantMessagesPacket rimpInstantMessagePack = (RetrieveInstantMessagesPacket)Pack;
  10490. if (rimpInstantMessagePack.AgentData.SessionID != SessionId || rimpInstantMessagePack.AgentData.AgentID != AgentId)
  10491. return;
  10492. OnRetrieveInstantMessages?.Invoke(this);
  10493. }
  10494. private void HandlePickDelete(Packet Pack)
  10495. {
  10496. PickDeletePacket pickDelete = (PickDeletePacket)Pack;
  10497. if (pickDelete.AgentData.SessionID != SessionId || pickDelete.AgentData.AgentID != AgentId)
  10498. return;
  10499. OnPickDelete?.Invoke(this, pickDelete.Data.PickID);
  10500. }
  10501. private void HandlePickGodDelete(Packet Pack)
  10502. {
  10503. PickGodDeletePacket pickGodDelete = (PickGodDeletePacket)Pack;
  10504. if (pickGodDelete.AgentData.SessionID != SessionId || pickGodDelete.AgentData.AgentID != AgentId)
  10505. return;
  10506. OnPickGodDelete?.Invoke(this,
  10507. pickGodDelete.AgentData.AgentID,
  10508. pickGodDelete.Data.PickID,
  10509. pickGodDelete.Data.QueryID);
  10510. }
  10511. private void HandlePickInfoUpdate(Packet Pack)
  10512. {
  10513. PickInfoUpdatePacket pickInfoUpdate = (PickInfoUpdatePacket)Pack;
  10514. if (pickInfoUpdate.AgentData.SessionID != SessionId || pickInfoUpdate.AgentData.AgentID != AgentId)
  10515. return;
  10516. OnPickInfoUpdate?.Invoke(this,
  10517. pickInfoUpdate.Data.PickID,
  10518. pickInfoUpdate.Data.CreatorID,
  10519. pickInfoUpdate.Data.TopPick,
  10520. Utils.BytesToString(pickInfoUpdate.Data.Name),
  10521. Utils.BytesToString(pickInfoUpdate.Data.Desc),
  10522. pickInfoUpdate.Data.SnapshotID,
  10523. pickInfoUpdate.Data.SortOrder,
  10524. pickInfoUpdate.Data.Enabled);
  10525. }
  10526. private void HandleAvatarNotesUpdate(Packet Pack)
  10527. {
  10528. AvatarNotesUpdatePacket avatarNotesUpdate = (AvatarNotesUpdatePacket)Pack;
  10529. if (avatarNotesUpdate.AgentData.SessionID != SessionId || avatarNotesUpdate.AgentData.AgentID != AgentId)
  10530. return;
  10531. OnAvatarNotesUpdate?.Invoke(this,
  10532. avatarNotesUpdate.Data.TargetID,
  10533. Utils.BytesToString(avatarNotesUpdate.Data.Notes));
  10534. }
  10535. private void HandleAvatarInterestsUpdate(Packet Pack)
  10536. {
  10537. AvatarInterestsUpdatePacket avatarInterestUpdate = (AvatarInterestsUpdatePacket)Pack;
  10538. if (avatarInterestUpdate.AgentData.SessionID != SessionId || avatarInterestUpdate.AgentData.AgentID != AgentId)
  10539. return;
  10540. OnAvatarInterestUpdate?.Invoke(this,
  10541. avatarInterestUpdate.PropertiesData.WantToMask,
  10542. Utils.BytesToString(avatarInterestUpdate.PropertiesData.WantToText),
  10543. avatarInterestUpdate.PropertiesData.SkillsMask,
  10544. Utils.BytesToString(avatarInterestUpdate.PropertiesData.SkillsText),
  10545. Utils.BytesToString(avatarInterestUpdate.PropertiesData.LanguagesText));
  10546. }
  10547. private void HandleGrantUserRights(Packet Pack)
  10548. {
  10549. GrantUserRightsPacket GrantUserRights = (GrantUserRightsPacket)Pack;
  10550. if (GrantUserRights.AgentData.SessionID != SessionId || GrantUserRights.AgentData.AgentID != AgentId)
  10551. return;
  10552. OnGrantUserRights?.Invoke(this,
  10553. GrantUserRights.Rights[0].AgentRelated,
  10554. GrantUserRights.Rights[0].RelatedRights);
  10555. }
  10556. private double m_nextRevokePermissionsTime = Double.MinValue;
  10557. private uint m_lastRevokePermissionsSeq = uint.MinValue;
  10558. private void HandleRevokePermissions(Packet Pack)
  10559. {
  10560. RevokePermissionsPacket pkt = (RevokePermissionsPacket)Pack;
  10561. if (pkt.AgentData.SessionID != SessionId || pkt .AgentData.AgentID != AgentId)
  10562. return;
  10563. uint thisSeq = pkt.Header.Sequence;
  10564. if (thisSeq == m_lastRevokePermissionsSeq)
  10565. return;
  10566. m_lastRevokePermissionsSeq = thisSeq;
  10567. ScenePresence sp = (ScenePresence)SceneAgent;
  10568. if(sp != null && !sp.IsDeleted && !sp.IsInTransit)
  10569. {
  10570. UUID objectID = pkt.Data.ObjectID;
  10571. double now = Util.GetTimeStampMS();
  10572. if (now < m_nextRevokePermissionsTime)
  10573. return;
  10574. if (objectID == m_scene.RegionInfo.RegionID)
  10575. m_nextRevokePermissionsTime = now + 2000;
  10576. else
  10577. m_nextRevokePermissionsTime = now + 50;
  10578. uint permissions = pkt.Data.ObjectPermissions;
  10579. sp.HandleRevokePermissions(objectID , permissions);
  10580. }
  10581. }
  10582. private void HandlePlacesQuery(Packet Pack)
  10583. {
  10584. PlacesQueryPacket placesQueryPacket = (PlacesQueryPacket)Pack;
  10585. if (placesQueryPacket.AgentData.SessionID != SessionId || placesQueryPacket.AgentData.AgentID != AgentId)
  10586. return;
  10587. OnPlacesQuery?.Invoke(placesQueryPacket.AgentData.QueryID,
  10588. placesQueryPacket.TransactionData.TransactionID,
  10589. Utils.BytesToString(
  10590. placesQueryPacket.QueryData.QueryText),
  10591. placesQueryPacket.QueryData.QueryFlags,
  10592. (byte)placesQueryPacket.QueryData.Category,
  10593. Utils.BytesToString(
  10594. placesQueryPacket.QueryData.SimName),
  10595. this);
  10596. }
  10597. #endregion Packet Handlers
  10598. public void SendScriptQuestion(UUID taskID, string taskName, string ownerName, UUID itemID, int question)
  10599. {
  10600. ScriptQuestionPacket scriptQuestion = (ScriptQuestionPacket)PacketPool.Instance.GetPacket(PacketType.ScriptQuestion);
  10601. scriptQuestion.Data = new ScriptQuestionPacket.DataBlock();
  10602. // TODO: don't create new blocks if recycling an old packet
  10603. scriptQuestion.Data.TaskID = taskID;
  10604. scriptQuestion.Data.ItemID = itemID;
  10605. scriptQuestion.Data.Questions = question;
  10606. scriptQuestion.Data.ObjectName = Util.StringToBytes256(taskName);
  10607. scriptQuestion.Data.ObjectOwner = Util.StringToBytes256(ownerName);
  10608. OutPacket(scriptQuestion, ThrottleOutPacketType.Task);
  10609. }
  10610. /// <summary>
  10611. /// Handler called when we receive a logout packet.
  10612. /// </summary>
  10613. /// <param name="client"></param>
  10614. /// <param name="packet"></param>
  10615. /// <returns></returns>
  10616. protected virtual void HandleLogout(Packet packet)
  10617. {
  10618. if (packet.Type == PacketType.LogoutRequest)
  10619. {
  10620. if (((LogoutRequestPacket)packet).AgentData.SessionID != SessionId)
  10621. return;
  10622. }
  10623. Logout(this);
  10624. }
  10625. /// <summary>
  10626. ///
  10627. /// </summary>
  10628. /// <param name="client"></param>
  10629. /// <returns></returns>
  10630. protected virtual void Logout(IClientAPI client)
  10631. {
  10632. m_log.InfoFormat("[CLIENT]: Got a logout request for {0} in {1}", Name, Scene.RegionInfo.RegionName);
  10633. OnLogout?.Invoke(client);
  10634. }
  10635. /// <summary>
  10636. /// </summary>
  10637. /// <remarks>
  10638. /// At the moment, we always reply that there is no cached texture.
  10639. /// </remarks>
  10640. /// <param name="simclient"></param>
  10641. /// <param name="packet"></param>
  10642. /// <returns></returns>
  10643. protected void HandleAgentTextureCached(Packet packet)
  10644. {
  10645. //m_log.Debug("texture cached: " + packet.ToString());
  10646. AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet;
  10647. AgentCachedTextureResponsePacket cachedresp =
  10648. (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
  10649. if (cachedtex.AgentData.SessionID != SessionId || cachedtex.AgentData.AgentID != AgentId)
  10650. return;
  10651. // TODO: don't create new blocks if recycling an old packet
  10652. cachedresp.AgentData.AgentID = AgentId;
  10653. cachedresp.AgentData.SessionID = m_sessionId;
  10654. cachedresp.AgentData.SerialNum = cachedtex.AgentData.SerialNum;
  10655. cachedresp.WearableData =
  10656. new AgentCachedTextureResponsePacket.WearableDataBlock[cachedtex.WearableData.Length];
  10657. int cacheHits = 0;
  10658. // 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
  10659. WearableCacheItem[] cacheItems = null;
  10660. ScenePresence p = m_scene.GetScenePresence(AgentId);
  10661. if (p != null && p.Appearance != null)
  10662. {
  10663. cacheItems = p.Appearance.WearableCacheItems;
  10664. }
  10665. int maxWearablesLoop = cachedtex.WearableData.Length;
  10666. if (cacheItems != null)
  10667. {
  10668. if (maxWearablesLoop > cacheItems.Length)
  10669. maxWearablesLoop = cacheItems.Length;
  10670. for (int i = 0; i < maxWearablesLoop; i++)
  10671. {
  10672. int idx = cachedtex.WearableData[i].TextureIndex;
  10673. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  10674. cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
  10675. cachedresp.WearableData[i].HostName = new byte[0];
  10676. if (cachedtex.WearableData[i].ID == cacheItems[idx].CacheId)
  10677. {
  10678. cachedresp.WearableData[i].TextureID = cacheItems[idx].TextureID;
  10679. cacheHits++;
  10680. }
  10681. else
  10682. {
  10683. cachedresp.WearableData[i].TextureID = UUID.Zero;
  10684. }
  10685. }
  10686. }
  10687. else
  10688. {
  10689. for (int i = 0; i < maxWearablesLoop; i++)
  10690. {
  10691. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  10692. cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
  10693. cachedresp.WearableData[i].TextureID = UUID.Zero;
  10694. cachedresp.WearableData[i].HostName = new byte[0];
  10695. }
  10696. }
  10697. //m_log.DebugFormat("texture cached: hits {0}", cacheHits);
  10698. cachedresp.Header.Zerocoded = true;
  10699. OutPacket(cachedresp, ThrottleOutPacketType.Task);
  10700. }
  10701. /// <summary>
  10702. /// Send a response back to a client when it asks the asset server (via the region server) if it has
  10703. /// its appearance texture cached.
  10704. /// </summary>
  10705. /// <param name="avatar"></param>
  10706. /// <param name="serial"></param>
  10707. /// <param name="cachedTextures"></param>
  10708. /// <returns></returns>
  10709. public void SendCachedTextureResponse(ISceneEntity avatar, int serial, List<CachedTextureResponseArg> cachedTextures)
  10710. {
  10711. ScenePresence presence = avatar as ScenePresence;
  10712. if (presence == null)
  10713. return;
  10714. AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
  10715. // TODO: don't create new blocks if recycling an old packet
  10716. cachedresp.AgentData.AgentID = m_agentId;
  10717. cachedresp.AgentData.SessionID = m_sessionId;
  10718. cachedresp.AgentData.SerialNum = serial;
  10719. cachedresp.WearableData = new AgentCachedTextureResponsePacket.WearableDataBlock[cachedTextures.Count];
  10720. for (int i = 0; i < cachedTextures.Count; i++)
  10721. {
  10722. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  10723. cachedresp.WearableData[i].TextureIndex = (byte)cachedTextures[i].BakedTextureIndex;
  10724. cachedresp.WearableData[i].TextureID = cachedTextures[i].BakedTextureID;
  10725. cachedresp.WearableData[i].HostName = new byte[0];
  10726. }
  10727. cachedresp.Header.Zerocoded = true;
  10728. OutPacket(cachedresp, ThrottleOutPacketType.Task);
  10729. }
  10730. protected void HandleMultipleObjUpdate(Packet packet)
  10731. {
  10732. MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
  10733. if (multipleupdate.AgentData.SessionID != SessionId || multipleupdate.AgentData.AgentID != AgentId)
  10734. return;
  10735. // m_log.DebugFormat(
  10736. // "[CLIENT]: Incoming MultipleObjectUpdatePacket contained {0} blocks", multipleupdate.ObjectData.Length);
  10737. Scene tScene = (Scene)m_scene;
  10738. for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
  10739. {
  10740. MultipleObjectUpdatePacket.ObjectDataBlock block = multipleupdate.ObjectData[i];
  10741. // Can't act on Null Data
  10742. if (block.Data != null)
  10743. {
  10744. uint localId = block.ObjectLocalID;
  10745. SceneObjectPart part = tScene.GetSceneObjectPart(localId);
  10746. if (part == null)
  10747. {
  10748. // It's a ghost! tell the client to delete it from view.
  10749. SendKillObject(new List<uint> { localId });
  10750. }
  10751. else
  10752. {
  10753. ClientChangeObject updatehandler = onClientChangeObject;
  10754. if (updatehandler != null)
  10755. {
  10756. ObjectChangeData udata = new ObjectChangeData();
  10757. /*ubit from ll JIRA:
  10758. * 0x01 position
  10759. * 0x02 rotation
  10760. * 0x04 scale
  10761. * 0x08 LINK_SET
  10762. * 0x10 UNIFORM for scale
  10763. */
  10764. // translate to internal changes
  10765. // not all cases .. just the ones older code did
  10766. switch (block.Type)
  10767. {
  10768. case 1: //change position sp
  10769. udata.position = new Vector3(block.Data, 0);
  10770. udata.change = ObjectChangeType.primP;
  10771. updatehandler(localId, udata, this);
  10772. break;
  10773. case 2: // rotation sp
  10774. udata.rotation = new Quaternion(block.Data, 0, true);
  10775. udata.change = ObjectChangeType.primR;
  10776. updatehandler(localId, udata, this);
  10777. break;
  10778. case 3: // position plus rotation
  10779. udata.position = new Vector3(block.Data, 0);
  10780. udata.rotation = new Quaternion(block.Data, 12, true);
  10781. udata.change = ObjectChangeType.primPR;
  10782. updatehandler(localId, udata, this);
  10783. break;
  10784. case 4: // scale sp
  10785. udata.scale = new Vector3(block.Data, 0);
  10786. udata.change = ObjectChangeType.primS;
  10787. updatehandler(localId, udata, this);
  10788. break;
  10789. case 0x14: // uniform scale sp
  10790. udata.scale = new Vector3(block.Data, 0);
  10791. udata.change = ObjectChangeType.primUS;
  10792. updatehandler(localId, udata, this);
  10793. break;
  10794. case 5: // scale and position sp
  10795. udata.position = new Vector3(block.Data, 0);
  10796. udata.scale = new Vector3(block.Data, 12);
  10797. udata.change = ObjectChangeType.primPS;
  10798. updatehandler(localId, udata, this);
  10799. break;
  10800. case 0x15: //uniform scale and position
  10801. udata.position = new Vector3(block.Data, 0);
  10802. udata.scale = new Vector3(block.Data, 12);
  10803. udata.change = ObjectChangeType.primPUS;
  10804. updatehandler(localId, udata, this);
  10805. break;
  10806. // now group related (bit 4)
  10807. case 9: //( 8 + 1 )group position
  10808. udata.position = new Vector3(block.Data, 0);
  10809. udata.change = ObjectChangeType.groupP;
  10810. updatehandler(localId, udata, this);
  10811. break;
  10812. case 0x0A: // (8 + 2) group rotation
  10813. udata.rotation = new Quaternion(block.Data, 0, true);
  10814. udata.change = ObjectChangeType.groupR;
  10815. updatehandler(localId, udata, this);
  10816. break;
  10817. case 0x0B: //( 8 + 2 + 1) group rotation and position
  10818. udata.position = new Vector3(block.Data, 0);
  10819. udata.rotation = new Quaternion(block.Data, 12, true);
  10820. udata.change = ObjectChangeType.groupPR;
  10821. updatehandler(localId, udata, this);
  10822. break;
  10823. case 0x0C: // (8 + 4) group scale
  10824. // only afects root prim and only sent by viewer editor object tab scaling
  10825. // mouse edition only allows uniform scaling
  10826. // SL MAY CHANGE THIS in viewers
  10827. udata.scale = new Vector3(block.Data, 0);
  10828. udata.change = ObjectChangeType.groupS;
  10829. updatehandler(localId, udata, this);
  10830. break;
  10831. case 0x0D: //(8 + 4 + 1) group scale and position
  10832. // exception as above
  10833. udata.position = new Vector3(block.Data, 0);
  10834. udata.scale = new Vector3(block.Data, 12);
  10835. udata.change = ObjectChangeType.groupPS;
  10836. updatehandler(localId, udata, this);
  10837. break;
  10838. case 0x1C: // (0x10 + 8 + 4 ) group scale UNIFORM
  10839. udata.scale = new Vector3(block.Data, 0);
  10840. udata.change = ObjectChangeType.groupUS;
  10841. updatehandler(localId, udata, this);
  10842. break;
  10843. case 0x1D: // (UNIFORM + GROUP + SCALE + POS)
  10844. udata.position = new Vector3(block.Data, 0);
  10845. udata.scale = new Vector3(block.Data, 12);
  10846. udata.change = ObjectChangeType.groupPUS;
  10847. updatehandler(localId, udata, this);
  10848. break;
  10849. default:
  10850. m_log.Debug("[CLIENT]: MultipleObjUpdate recieved an unknown packet type: " + (block.Type));
  10851. break;
  10852. }
  10853. }
  10854. }
  10855. }
  10856. }
  10857. }
  10858. public void RequestMapLayer()
  10859. {
  10860. //should be getting the map layer from the grid server
  10861. //send a layer covering the 800,800 - 1200,1200 area (should be covering the requested area)
  10862. MapLayerReplyPacket mapReply = (MapLayerReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapLayerReply);
  10863. // TODO: don't create new blocks if recycling an old packet
  10864. mapReply.AgentData.AgentID = AgentId;
  10865. mapReply.AgentData.Flags = 0;
  10866. mapReply.LayerData = new MapLayerReplyPacket.LayerDataBlock[1];
  10867. mapReply.LayerData[0] = new MapLayerReplyPacket.LayerDataBlock();
  10868. mapReply.LayerData[0].Bottom = 0;
  10869. mapReply.LayerData[0].Left = 0;
  10870. mapReply.LayerData[0].Top = 30000;
  10871. mapReply.LayerData[0].Right = 30000;
  10872. mapReply.LayerData[0].ImageID = new UUID("00000000-0000-1111-9999-000000000006");
  10873. mapReply.Header.Zerocoded = true;
  10874. OutPacket(mapReply, ThrottleOutPacketType.Land);
  10875. }
  10876. public void RequestMapBlocksX(int minX, int minY, int maxX, int maxY)
  10877. {
  10878. /*
  10879. IList simMapProfiles = m_gridServer.RequestMapBlocks(minX, minY, maxX, maxY);
  10880. MapBlockReplyPacket mbReply = new MapBlockReplyPacket();
  10881. mbReply.AgentData.AgentId = AgentId;
  10882. int len;
  10883. if (simMapProfiles == null)
  10884. len = 0;
  10885. else
  10886. len = simMapProfiles.Count;
  10887. mbReply.Data = new MapBlockReplyPacket.DataBlock[len];
  10888. int iii;
  10889. for (iii = 0; iii < len; iii++)
  10890. {
  10891. Hashtable mp = (Hashtable)simMapProfiles[iii];
  10892. mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock();
  10893. mbReply.Data[iii].Name = Util.UTF8.GetBytes((string)mp["name"]);
  10894. mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]);
  10895. mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]);
  10896. mbReply.Data[iii].MapImageID = new UUID((string)mp["map-image-id"]);
  10897. mbReply.Data[iii].RegionFlags = System.Convert.ToUInt32(mp["region-flags"]);
  10898. mbReply.Data[iii].WaterHeight = System.Convert.ToByte(mp["water-height"]);
  10899. mbReply.Data[iii].X = System.Convert.ToUInt16(mp["x"]);
  10900. mbReply.Data[iii].Y = System.Convert.ToUInt16(mp["y"]);
  10901. }
  10902. this.OutPacket(mbReply, ThrottleOutPacketType.Land);
  10903. */
  10904. }
  10905. /// <summary>
  10906. /// Sets the throttles from values supplied by the client
  10907. /// </summary>
  10908. /// <param name="throttles"></param>
  10909. public void SetChildAgentThrottle(byte[] throttles)
  10910. {
  10911. SetChildAgentThrottle(throttles, 1.0f);
  10912. }
  10913. public void SetChildAgentThrottle(byte[] throttles,float factor)
  10914. {
  10915. m_udpClient.SetThrottles(throttles, factor);
  10916. GenericCall2 handler = OnUpdateThrottles;
  10917. if (handler != null)
  10918. {
  10919. handler();
  10920. }
  10921. }
  10922. /// <summary>
  10923. /// Sets the throttles from values supplied caller
  10924. /// </summary>
  10925. /// <param name="throttles"></param>
  10926. public void SetAgentThrottleSilent(int throttle, int setting)
  10927. {
  10928. m_udpClient.ForceThrottleSetting(throttle,setting);
  10929. }
  10930. public int GetAgentThrottleSilent(int throttle)
  10931. {
  10932. return m_udpClient.GetThrottleSetting(throttle);
  10933. }
  10934. /// <summary>
  10935. /// Get the current throttles for this client as a packed byte array
  10936. /// </summary>
  10937. /// <param name="multiplier">Unused</param>
  10938. /// <returns></returns>
  10939. public byte[] GetThrottlesPacked(float multiplier)
  10940. {
  10941. return m_udpClient.GetThrottlesPacked(multiplier);
  10942. }
  10943. /// <summary>
  10944. /// Cruft?
  10945. /// </summary>
  10946. public virtual void InPacket(object NewPack)
  10947. {
  10948. throw new NotImplementedException();
  10949. }
  10950. /// <summary>
  10951. /// This is the starting point for sending a simulator packet out to the client
  10952. /// </summary>
  10953. /// <param name="packet">Packet to send</param>
  10954. /// <param name="throttlePacketType">Throttling category for the packet</param>
  10955. protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType)
  10956. {
  10957. #region BinaryStats
  10958. LLUDPServer.LogPacketHeader(false, m_circuitCode, 0, packet.Type, (ushort)packet.Length);
  10959. #endregion BinaryStats
  10960. OutPacket(packet, throttlePacketType, true, null);
  10961. }
  10962. /// <summary>
  10963. /// This is the starting point for sending a simulator packet out to the client
  10964. /// </summary>
  10965. /// <param name="packet">Packet to send</param>
  10966. /// <param name="throttlePacketType">Throttling category for the packet</param>
  10967. /// <param name="doAutomaticSplitting">True to automatically split oversized
  10968. /// packets (the default), or false to disable splitting if the calling code
  10969. /// handles splitting manually</param>
  10970. protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting)
  10971. {
  10972. OutPacket(packet, throttlePacketType, doAutomaticSplitting, null);
  10973. }
  10974. /// <summary>
  10975. /// This is the starting point for sending a simulator packet out to the client
  10976. /// </summary>
  10977. /// <param name="packet">Packet to send</param>
  10978. /// <param name="throttlePacketType">Throttling category for the packet</param>
  10979. /// <param name="doAutomaticSplitting">True to automatically split oversized
  10980. /// packets (the default), or false to disable splitting if the calling code
  10981. /// handles splitting manually</param>
  10982. /// <param name="method">The method to be called in the event this packet is reliable
  10983. /// and unacknowledged. The server will provide normal resend capability if you do not
  10984. /// provide your own method.</param>
  10985. protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting, UnackedPacketMethod method)
  10986. {
  10987. if (m_outPacketsToDrop != null)
  10988. {
  10989. if (m_outPacketsToDrop.Contains(packet.Type.ToString()))
  10990. {
  10991. PacketPool.Instance.ReturnPacket(packet);
  10992. return;
  10993. }
  10994. }
  10995. if (DebugPacketLevel > 0)
  10996. {
  10997. bool logPacket = true;
  10998. if (DebugPacketLevel <= 255
  10999. && (packet.Type == PacketType.SimStats || packet.Type == PacketType.SimulatorViewerTimeMessage))
  11000. logPacket = false;
  11001. if (DebugPacketLevel <= 200
  11002. && (packet.Type == PacketType.ImagePacket
  11003. || packet.Type == PacketType.ImageData
  11004. || packet.Type == PacketType.LayerData
  11005. || packet.Type == PacketType.CoarseLocationUpdate))
  11006. logPacket = false;
  11007. if (DebugPacketLevel <= 100 && (packet.Type == PacketType.AvatarAnimation || packet.Type == PacketType.ViewerEffect))
  11008. logPacket = false;
  11009. if (DebugPacketLevel <= 50
  11010. && (packet.Type == PacketType.ImprovedTerseObjectUpdate || packet.Type == PacketType.ObjectUpdate))
  11011. logPacket = false;
  11012. if (DebugPacketLevel <= 25 && packet.Type == PacketType.ObjectPropertiesFamily)
  11013. logPacket = false;
  11014. if (logPacket)
  11015. m_log.DebugFormat(
  11016. "[CLIENT]: PACKET OUT to {0} ({1}) in {2} - {3}",
  11017. Name, SceneAgent.IsChildAgent ? "child" : "root ", m_scene.RegionInfo.RegionName, packet.Type);
  11018. }
  11019. m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, doAutomaticSplitting, method);
  11020. }
  11021. protected void HandleAutopilot(Object sender, string method, List<String> args)
  11022. {
  11023. if(OnAutoPilotGo == null)
  11024. return;
  11025. float locx = 0;
  11026. float locy = 0;
  11027. float locz = 0;
  11028. uint regionX = 0;
  11029. uint regionY = 0;
  11030. Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out regionX, out regionY);
  11031. locx = (float)(Convert.ToDouble(args[0]) - (double)regionX);
  11032. locy = (float)(Convert.ToDouble(args[1]) - (double)regionY);
  11033. locz = Convert.ToSingle(args[2]);
  11034. OnAutoPilotGo?.Invoke(new Vector3(locx, locy, locz), false, true);
  11035. }
  11036. /// <summary>
  11037. /// Entryway from the client to the simulator. All UDP packets from the client will end up here
  11038. /// </summary>
  11039. /// <param name="Pack">OpenMetaverse.packet</param>
  11040. public void ProcessInPacket(Packet packet)
  11041. {
  11042. if (m_inPacketsToDrop != null)
  11043. if (m_inPacketsToDrop.Contains(packet.Type.ToString()))
  11044. return;
  11045. if (DebugPacketLevel > 0)
  11046. {
  11047. bool logPacket = true;
  11048. if (DebugPacketLevel <= 255 && packet.Type == PacketType.AgentUpdate)
  11049. logPacket = false;
  11050. if (DebugPacketLevel <= 200 && packet.Type == PacketType.RequestImage)
  11051. logPacket = false;
  11052. if (DebugPacketLevel <= 100 && (packet.Type == PacketType.ViewerEffect || packet.Type == PacketType.AgentAnimation))
  11053. logPacket = false;
  11054. if (DebugPacketLevel <= 25 && packet.Type == PacketType.RequestObjectPropertiesFamily)
  11055. logPacket = false;
  11056. if (logPacket)
  11057. m_log.DebugFormat(
  11058. "[CLIENT]: PACKET IN from {0} ({1}) in {2} - {3}",
  11059. Name, SceneAgent.IsChildAgent ? "child" : "root ", Scene.Name, packet.Type);
  11060. }
  11061. if (!ProcessPacketMethod(packet))
  11062. m_log.WarnFormat(
  11063. "[CLIENT]: Unhandled packet {0} from {1} ({2}) in {3}. Ignoring.",
  11064. packet.Type, Name, SceneAgent.IsChildAgent ? "child" : "root ", Scene.Name);
  11065. }
  11066. private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)
  11067. {
  11068. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  11069. shape.PCode = addPacket.ObjectData.PCode;
  11070. shape.State = addPacket.ObjectData.State;
  11071. shape.LastAttachPoint = addPacket.ObjectData.State;
  11072. shape.PathBegin = addPacket.ObjectData.PathBegin;
  11073. shape.PathEnd = addPacket.ObjectData.PathEnd;
  11074. shape.PathScaleX = addPacket.ObjectData.PathScaleX;
  11075. shape.PathScaleY = addPacket.ObjectData.PathScaleY;
  11076. shape.PathShearX = addPacket.ObjectData.PathShearX;
  11077. shape.PathShearY = addPacket.ObjectData.PathShearY;
  11078. shape.PathSkew = addPacket.ObjectData.PathSkew;
  11079. shape.ProfileBegin = addPacket.ObjectData.ProfileBegin;
  11080. shape.ProfileEnd = addPacket.ObjectData.ProfileEnd;
  11081. shape.Scale = addPacket.ObjectData.Scale;
  11082. shape.PathCurve = addPacket.ObjectData.PathCurve;
  11083. shape.ProfileCurve = addPacket.ObjectData.ProfileCurve;
  11084. shape.ProfileHollow = addPacket.ObjectData.ProfileHollow;
  11085. shape.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
  11086. shape.PathRevolutions = addPacket.ObjectData.PathRevolutions;
  11087. shape.PathTaperX = addPacket.ObjectData.PathTaperX;
  11088. shape.PathTaperY = addPacket.ObjectData.PathTaperY;
  11089. shape.PathTwist = addPacket.ObjectData.PathTwist;
  11090. shape.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
  11091. Primitive.TextureEntry ntex = new Primitive.TextureEntry(new UUID("89556747-24cb-43ed-920b-47caed15465f"));
  11092. shape.TextureEntry = ntex.GetBytes();
  11093. //shape.Textures = ntex;
  11094. return shape;
  11095. }
  11096. public ClientInfo GetClientInfo()
  11097. {
  11098. ClientInfo info = m_udpClient.GetClientInfo();
  11099. info.proxyEP = null;
  11100. if (info.agentcircuit == null)
  11101. info.agentcircuit = RequestClientInfo();
  11102. return info;
  11103. }
  11104. public void SetClientInfo(ClientInfo info)
  11105. {
  11106. m_udpClient.SetClientInfo(info);
  11107. }
  11108. #region Media Parcel Members
  11109. public void SendParcelMediaCommand(uint flags, ParcelMediaCommandEnum command, float time)
  11110. {
  11111. ParcelMediaCommandMessagePacket commandMessagePacket = new ParcelMediaCommandMessagePacket();
  11112. commandMessagePacket.CommandBlock.Flags = flags;
  11113. commandMessagePacket.CommandBlock.Command = (uint)command;
  11114. commandMessagePacket.CommandBlock.Time = time;
  11115. OutPacket(commandMessagePacket, ThrottleOutPacketType.Task);
  11116. }
  11117. public void SendParcelMediaUpdate(string mediaUrl, UUID mediaTextureID,
  11118. byte autoScale, string mediaType, string mediaDesc, int mediaWidth, int mediaHeight,
  11119. byte mediaLoop)
  11120. {
  11121. ParcelMediaUpdatePacket updatePacket = new ParcelMediaUpdatePacket();
  11122. updatePacket.DataBlock.MediaURL = Util.StringToBytes256(mediaUrl);
  11123. updatePacket.DataBlock.MediaID = mediaTextureID;
  11124. updatePacket.DataBlock.MediaAutoScale = autoScale;
  11125. updatePacket.DataBlockExtended.MediaType = Util.StringToBytes256(mediaType);
  11126. updatePacket.DataBlockExtended.MediaDesc = Util.StringToBytes256(mediaDesc);
  11127. updatePacket.DataBlockExtended.MediaWidth = mediaWidth;
  11128. updatePacket.DataBlockExtended.MediaHeight = mediaHeight;
  11129. updatePacket.DataBlockExtended.MediaLoop = mediaLoop;
  11130. OutPacket(updatePacket, ThrottleOutPacketType.Task);
  11131. }
  11132. #endregion
  11133. #region Camera
  11134. public void SendSetFollowCamProperties(UUID objectID, SortedDictionary<int, float> parameters)
  11135. {
  11136. SetFollowCamPropertiesPacket packet = (SetFollowCamPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.SetFollowCamProperties);
  11137. packet.ObjectData.ObjectID = objectID;
  11138. SetFollowCamPropertiesPacket.CameraPropertyBlock[] camPropBlock = new SetFollowCamPropertiesPacket.CameraPropertyBlock[parameters.Count];
  11139. uint idx = 0;
  11140. foreach (KeyValuePair<int, float> pair in parameters)
  11141. {
  11142. SetFollowCamPropertiesPacket.CameraPropertyBlock block = new SetFollowCamPropertiesPacket.CameraPropertyBlock();
  11143. block.Type = pair.Key;
  11144. block.Value = pair.Value;
  11145. camPropBlock[idx++] = block;
  11146. }
  11147. packet.CameraProperty = camPropBlock;
  11148. OutPacket(packet, ThrottleOutPacketType.Task);
  11149. }
  11150. public void SendClearFollowCamProperties(UUID objectID)
  11151. {
  11152. ClearFollowCamPropertiesPacket packet = (ClearFollowCamPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ClearFollowCamProperties);
  11153. packet.ObjectData.ObjectID = objectID;
  11154. OutPacket(packet, ThrottleOutPacketType.Task);
  11155. }
  11156. #endregion
  11157. public void SetClientOption(string option, string value)
  11158. {
  11159. switch (option)
  11160. {
  11161. default:
  11162. break;
  11163. }
  11164. }
  11165. public string GetClientOption(string option)
  11166. {
  11167. switch (option)
  11168. {
  11169. default:
  11170. break;
  11171. }
  11172. return string.Empty;
  11173. }
  11174. #region IClientCore
  11175. private readonly Dictionary<Type, object> m_clientInterfaces = new Dictionary<Type, object>();
  11176. /// <summary>
  11177. /// Register an interface on this client, should only be called in the constructor.
  11178. /// </summary>
  11179. /// <typeparam name="T"></typeparam>
  11180. /// <param name="iface"></param>
  11181. protected void RegisterInterface<T>(T iface)
  11182. {
  11183. lock (m_clientInterfaces)
  11184. {
  11185. if (!m_clientInterfaces.ContainsKey(typeof(T)))
  11186. {
  11187. m_clientInterfaces.Add(typeof(T), iface);
  11188. }
  11189. }
  11190. }
  11191. public bool TryGet<T>(out T iface)
  11192. {
  11193. if(m_clientInterfaces.TryGetValue(typeof(T), out object o))
  11194. {
  11195. iface = (T)o;
  11196. return true;
  11197. }
  11198. iface = default(T);
  11199. return false;
  11200. }
  11201. public T Get<T>()
  11202. {
  11203. return (T)m_clientInterfaces[typeof(T)];
  11204. }
  11205. public void Disconnect(string reason)
  11206. {
  11207. Kick(reason);
  11208. Thread.Sleep(1000);
  11209. Disconnect();
  11210. }
  11211. public void Disconnect()
  11212. {
  11213. Close();
  11214. }
  11215. #endregion
  11216. public void RefreshGroupMembership()
  11217. {
  11218. lock(m_groupPowers)
  11219. {
  11220. GroupMembershipData activeMembership = null;
  11221. if (m_GroupsModule != null)
  11222. {
  11223. GroupMembershipData[] GroupMembership =
  11224. m_GroupsModule.GetMembershipData(AgentId);
  11225. m_groupPowers.Clear();
  11226. if (GroupMembership != null)
  11227. {
  11228. for (int i = 0; i < GroupMembership.Length; i++)
  11229. {
  11230. m_groupPowers[GroupMembership[i].GroupID] = GroupMembership[i].GroupPowers;
  11231. }
  11232. }
  11233. activeMembership = m_GroupsModule.GetActiveMembershipData(AgentId);
  11234. if(activeMembership != null)
  11235. {
  11236. if(!m_groupPowers.ContainsKey(activeMembership.GroupID))
  11237. activeMembership = null;
  11238. else
  11239. {
  11240. m_activeGroupID = activeMembership.GroupID;
  11241. m_activeGroupName = activeMembership.GroupName;
  11242. m_activeGroupPowers = ActiveGroupPowers;
  11243. }
  11244. }
  11245. }
  11246. if(activeMembership == null)
  11247. {
  11248. m_activeGroupID = UUID.Zero;
  11249. m_activeGroupName = "";
  11250. m_activeGroupPowers = 0;
  11251. }
  11252. }
  11253. }
  11254. public void UpdateGroupMembership(GroupMembershipData[] data)
  11255. {
  11256. lock(m_groupPowers)
  11257. {
  11258. m_groupPowers.Clear();
  11259. if (data != null)
  11260. {
  11261. for (int i = 0; i < data.Length; i++)
  11262. m_groupPowers[data[i].GroupID] = data[i].GroupPowers;
  11263. }
  11264. }
  11265. }
  11266. public void GroupMembershipRemove(UUID GroupID)
  11267. {
  11268. lock(m_groupPowers)
  11269. {
  11270. if(m_groupPowers.ContainsKey(GroupID))
  11271. m_groupPowers.Remove(GroupID);
  11272. }
  11273. }
  11274. public void GroupMembershipAddReplace(UUID GroupID,ulong GroupPowers)
  11275. {
  11276. lock(m_groupPowers)
  11277. {
  11278. m_groupPowers[GroupID] = GroupPowers;
  11279. }
  11280. }
  11281. public string Report()
  11282. {
  11283. return m_udpClient.GetStats();
  11284. }
  11285. public string XReport(string uptime, string version)
  11286. {
  11287. return String.Empty;
  11288. }
  11289. public OSDMap OReport(string uptime, string version)
  11290. {
  11291. return new OSDMap();
  11292. }
  11293. /// <summary>
  11294. /// Make an asset request to the asset service in response to a client request.
  11295. /// </summary>
  11296. /// <param name="transferRequest"></param>
  11297. /// <param name="taskID"></param>
  11298. protected void MakeAssetRequest(TransferRequestPacket transferRequest, UUID taskID)
  11299. {
  11300. UUID requestID = UUID.Zero;
  11301. int sourceType = transferRequest.TransferInfo.SourceType;
  11302. if (sourceType == (int)SourceType.Asset)
  11303. {
  11304. requestID = new UUID(transferRequest.TransferInfo.Params, 0);
  11305. }
  11306. else if (sourceType == (int)SourceType.SimInventoryItem)
  11307. {
  11308. requestID = new UUID(transferRequest.TransferInfo.Params, 80);
  11309. }
  11310. else if (sourceType == (int)SourceType.SimEstate)
  11311. {
  11312. requestID = taskID;
  11313. }
  11314. // m_log.DebugFormat(
  11315. // "[LLCLIENTVIEW]: Received transfer request for {0} in {1} type {2} by {3}",
  11316. // requestID, taskID, (SourceType)sourceType, Name);
  11317. //Note, the bool returned from the below function is useless since it is always false.
  11318. m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived);
  11319. }
  11320. /// <summary>
  11321. /// When we get a reply back from the asset service in response to a client request, send back the data.
  11322. /// </summary>
  11323. /// <param name="id"></param>
  11324. /// <param name="sender"></param>
  11325. /// <param name="asset"></param>
  11326. protected void AssetReceived(string id, Object sender, AssetBase asset)
  11327. {
  11328. TransferRequestPacket transferRequest = (TransferRequestPacket)sender;
  11329. UUID requestID = UUID.Zero;
  11330. byte source = (byte)SourceType.Asset;
  11331. AssetRequestToClient req = new AssetRequestToClient();
  11332. if (asset == null)
  11333. {
  11334. // Try the user's asset server
  11335. IInventoryAccessModule inventoryAccessModule = Scene.RequestModuleInterface<IInventoryAccessModule>();
  11336. string assetServerURL = string.Empty;
  11337. if (inventoryAccessModule.IsForeignUser(AgentId, out assetServerURL) && !string.IsNullOrEmpty(assetServerURL))
  11338. {
  11339. if (!assetServerURL.EndsWith("/") && !assetServerURL.EndsWith("="))
  11340. assetServerURL = assetServerURL + "/";
  11341. //m_log.DebugFormat("[LLCLIENTVIEW]: asset {0} not found in local storage. Trying user's storage.", assetServerURL + id);
  11342. asset = m_scene.AssetService.Get(assetServerURL + id);
  11343. }
  11344. if (asset == null)
  11345. {
  11346. req.AssetInf = null;
  11347. req.AssetRequestSource = source;
  11348. req.IsTextureRequest = false;
  11349. req.NumPackets = 0;
  11350. req.Params = transferRequest.TransferInfo.Params;
  11351. req.RequestAssetID = requestID;
  11352. req.TransferRequestID = transferRequest.TransferInfo.TransferID;
  11353. SendAssetNotFound(req);
  11354. return;
  11355. }
  11356. }
  11357. if (transferRequest.TransferInfo.SourceType == (int)SourceType.Asset)
  11358. {
  11359. requestID = new UUID(transferRequest.TransferInfo.Params, 0);
  11360. }
  11361. else if (transferRequest.TransferInfo.SourceType == (int)SourceType.SimInventoryItem)
  11362. {
  11363. requestID = new UUID(transferRequest.TransferInfo.Params, 80);
  11364. source = (byte)SourceType.SimInventoryItem;
  11365. //m_log.Debug("asset request " + requestID);
  11366. }
  11367. // Scripts cannot be retrieved by direct request
  11368. if (transferRequest.TransferInfo.SourceType == (int)SourceType.Asset && asset.Type == 10)
  11369. return;
  11370. // The asset is known to exist and is in our cache, so add it to the AssetRequests list
  11371. req.AssetInf = asset;
  11372. req.AssetRequestSource = source;
  11373. req.IsTextureRequest = false;
  11374. req.NumPackets = CalculateNumPackets(asset.Data);
  11375. req.Params = transferRequest.TransferInfo.Params;
  11376. req.RequestAssetID = requestID;
  11377. req.TransferRequestID = transferRequest.TransferInfo.TransferID;
  11378. SendAsset(req);
  11379. }
  11380. /// <summary>
  11381. /// Calculate the number of packets required to send the asset to the client.
  11382. /// </summary>
  11383. /// <param name="data"></param>
  11384. /// <returns></returns>
  11385. private static int CalculateNumPackets(byte[] data)
  11386. {
  11387. // const uint m_maxPacketSize = 600;
  11388. uint m_maxPacketSize = MaxTransferBytesPerPacket;
  11389. int numPackets = 1;
  11390. if (data == null)
  11391. return 0;
  11392. if (data.LongLength > m_maxPacketSize)
  11393. {
  11394. // over max number of bytes so split up file
  11395. long restData = data.LongLength - m_maxPacketSize;
  11396. int restPackets = (int)((restData + m_maxPacketSize - 1) / m_maxPacketSize);
  11397. numPackets += restPackets;
  11398. }
  11399. return numPackets;
  11400. }
  11401. public void SendRebakeAvatarTextures(UUID textureID)
  11402. {
  11403. RebakeAvatarTexturesPacket pack =
  11404. (RebakeAvatarTexturesPacket)PacketPool.Instance.GetPacket(PacketType.RebakeAvatarTextures);
  11405. pack.TextureData = new RebakeAvatarTexturesPacket.TextureDataBlock();
  11406. pack.TextureData.TextureID = textureID;
  11407. OutPacket(pack, ThrottleOutPacketType.Task);
  11408. }
  11409. public struct PacketProcessor
  11410. {
  11411. /// <summary>
  11412. /// Packet handling method.
  11413. /// </summary>
  11414. public PacketMethod method;
  11415. /// <summary>
  11416. /// Should this packet be handled asynchronously?
  11417. /// </summary>
  11418. public bool Async;
  11419. }
  11420. public void SendAvatarInterestsReply(UUID avatarID, uint wantMask, string wantText, uint skillsMask, string skillsText, string languages)
  11421. {
  11422. AvatarInterestsReplyPacket packet = (AvatarInterestsReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarInterestsReply);
  11423. packet.AgentData = new AvatarInterestsReplyPacket.AgentDataBlock();
  11424. packet.AgentData.AgentID = AgentId;
  11425. packet.AgentData.AvatarID = avatarID;
  11426. packet.PropertiesData = new AvatarInterestsReplyPacket.PropertiesDataBlock();
  11427. packet.PropertiesData.WantToMask = wantMask;
  11428. packet.PropertiesData.WantToText = Utils.StringToBytes(wantText);
  11429. packet.PropertiesData.SkillsMask = skillsMask;
  11430. packet.PropertiesData.SkillsText = Utils.StringToBytes(skillsText);
  11431. packet.PropertiesData.LanguagesText = Utils.StringToBytes(languages);
  11432. OutPacket(packet, ThrottleOutPacketType.Task);
  11433. }
  11434. public void SendChangeUserRights(UUID agentID, UUID friendID, int rights)
  11435. {
  11436. ChangeUserRightsPacket packet = (ChangeUserRightsPacket)PacketPool.Instance.GetPacket(PacketType.ChangeUserRights);
  11437. packet.AgentData = new ChangeUserRightsPacket.AgentDataBlock();
  11438. packet.AgentData.AgentID = agentID;
  11439. packet.Rights = new ChangeUserRightsPacket.RightsBlock[1];
  11440. packet.Rights[0] = new ChangeUserRightsPacket.RightsBlock();
  11441. packet.Rights[0].AgentRelated = friendID;
  11442. packet.Rights[0].RelatedRights = rights;
  11443. OutPacket(packet, ThrottleOutPacketType.Task);
  11444. }
  11445. public void SendTextBoxRequest(string message, int chatChannel, string objectname, UUID ownerID, string ownerFirstName, string ownerLastName, UUID objectId)
  11446. {
  11447. ScriptDialogPacket dialog = (ScriptDialogPacket)PacketPool.Instance.GetPacket(PacketType.ScriptDialog);
  11448. dialog.Data.ObjectID = objectId;
  11449. dialog.Data.ChatChannel = chatChannel;
  11450. dialog.Data.ImageID = UUID.Zero;
  11451. dialog.Data.ObjectName = Util.StringToBytes256(objectname);
  11452. // this is the username of the *owner*
  11453. dialog.Data.FirstName = Util.StringToBytes256(ownerFirstName);
  11454. dialog.Data.LastName = Util.StringToBytes256(ownerLastName);
  11455. dialog.Data.Message = Util.StringToBytes(message,512);
  11456. ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[1];
  11457. buttons[0] = new ScriptDialogPacket.ButtonsBlock();
  11458. buttons[0].ButtonLabel = Util.StringToBytes256("!!llTextBox!!");
  11459. dialog.Buttons = buttons;
  11460. dialog.OwnerData = new ScriptDialogPacket.OwnerDataBlock[1];
  11461. dialog.OwnerData[0] = new ScriptDialogPacket.OwnerDataBlock();
  11462. dialog.OwnerData[0].OwnerID = ownerID;
  11463. OutPacket(dialog, ThrottleOutPacketType.Task);
  11464. }
  11465. public void SendAgentTerseUpdate(ISceneEntity p)
  11466. {
  11467. if (p is ScenePresence)
  11468. {
  11469. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  11470. //setup header and regioninfo block
  11471. Buffer.BlockCopy(terseUpdateHeader, 0, buf.Data, 0, 7);
  11472. Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, buf.Data, 7);
  11473. Utils.UInt16ToBytes(Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f), buf.Data, 15);
  11474. buf.Data[17] = 1;
  11475. int pos = 18;
  11476. CreateImprovedTerseBlock(p, buf.Data, ref pos, false);
  11477. buf.DataLength = pos;
  11478. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, true);
  11479. }
  11480. }
  11481. public void SendPlacesReply(UUID queryID, UUID transactionID,
  11482. PlacesReplyData[] data)
  11483. {
  11484. PlacesReplyPacket reply = null;
  11485. PlacesReplyPacket.QueryDataBlock[] dataBlocks =
  11486. new PlacesReplyPacket.QueryDataBlock[0];
  11487. for (int i = 0 ; i < data.Length ; i++)
  11488. {
  11489. PlacesReplyPacket.QueryDataBlock block =
  11490. new PlacesReplyPacket.QueryDataBlock();
  11491. block.OwnerID = data[i].OwnerID;
  11492. block.Name = Util.StringToBytes256(data[i].Name);
  11493. block.Desc = Util.StringToBytes1024(data[i].Desc);
  11494. block.ActualArea = data[i].ActualArea;
  11495. block.BillableArea = data[i].BillableArea;
  11496. block.Flags = data[i].Flags;
  11497. block.GlobalX = data[i].GlobalX;
  11498. block.GlobalY = data[i].GlobalY;
  11499. block.GlobalZ = data[i].GlobalZ;
  11500. block.SimName = Util.StringToBytes256(data[i].SimName);
  11501. block.SnapshotID = data[i].SnapshotID;
  11502. block.Dwell = data[i].Dwell;
  11503. block.Price = data[i].Price;
  11504. if (reply != null && reply.Length + block.Length > 1400)
  11505. {
  11506. OutPacket(reply, ThrottleOutPacketType.Task);
  11507. reply = null;
  11508. dataBlocks = new PlacesReplyPacket.QueryDataBlock[0];
  11509. }
  11510. if (reply == null)
  11511. {
  11512. reply = (PlacesReplyPacket)PacketPool.Instance.GetPacket(PacketType.PlacesReply);
  11513. reply.AgentData = new PlacesReplyPacket.AgentDataBlock();
  11514. reply.AgentData.AgentID = AgentId;
  11515. reply.AgentData.QueryID = queryID;
  11516. reply.TransactionData = new PlacesReplyPacket.TransactionDataBlock();
  11517. reply.TransactionData.TransactionID = transactionID;
  11518. reply.QueryData = dataBlocks;
  11519. }
  11520. Array.Resize(ref dataBlocks, dataBlocks.Length + 1);
  11521. dataBlocks[dataBlocks.Length - 1] = block;
  11522. reply.QueryData = dataBlocks;
  11523. }
  11524. if (reply != null)
  11525. OutPacket(reply, ThrottleOutPacketType.Task);
  11526. }
  11527. public void SendRemoveInventoryItems(UUID[] items)
  11528. {
  11529. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  11530. if (eq == null)
  11531. {
  11532. m_log.DebugFormat("[LLCLIENT]: Null event queue");
  11533. return;
  11534. }
  11535. osUTF8 sb = eq.StartEvent("RemoveInventoryItem");
  11536. LLSDxmlEncode2.AddArrayAndMap("AgentData", sb);
  11537. LLSDxmlEncode2.AddElem("AgentID", AgentId, sb);
  11538. LLSDxmlEncode2.AddElem("SessionID", SessionId, sb);
  11539. LLSDxmlEncode2.AddEndMapAndArray(sb);
  11540. LLSDxmlEncode2.AddArray("InventoryData", sb);
  11541. foreach (UUID item in items)
  11542. {
  11543. LLSDxmlEncode2.AddMap(sb);
  11544. LLSDxmlEncode2.AddElem("ItemID",item, sb);
  11545. LLSDxmlEncode2.AddEndMap(sb);
  11546. }
  11547. LLSDxmlEncode2.AddEndArray(sb);
  11548. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  11549. }
  11550. public void SendRemoveInventoryFolders(UUID[] folders)
  11551. {
  11552. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  11553. if (eq == null)
  11554. {
  11555. m_log.DebugFormat("[LLCLIENT]: Null event queue");
  11556. return;
  11557. }
  11558. osUTF8 sb = eq.StartEvent("RemoveInventoryFolder");
  11559. LLSDxmlEncode2.AddArrayAndMap("AgentData", sb);
  11560. LLSDxmlEncode2.AddElem("AgentID", AgentId, sb);
  11561. LLSDxmlEncode2.AddElem("SessionID", SessionId, sb);
  11562. LLSDxmlEncode2.AddEndMapAndArray(sb);
  11563. LLSDxmlEncode2.AddArray("FolderData", sb);
  11564. foreach (UUID folder in folders)
  11565. {
  11566. LLSDxmlEncode2.AddMap(sb);
  11567. LLSDxmlEncode2.AddElem("FolderID", folder, sb);
  11568. LLSDxmlEncode2.AddEndMap(sb);
  11569. }
  11570. LLSDxmlEncode2.AddEndArray(sb);
  11571. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  11572. }
  11573. public void SendBulkUpdateInventory(InventoryFolderBase[] folders, InventoryItemBase[] items)
  11574. {
  11575. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  11576. if (eq == null)
  11577. {
  11578. m_log.DebugFormat("[LLCLIENT]: Null event queue");
  11579. return;
  11580. }
  11581. osUTF8 sb = eq.StartEvent("BulkUpdateInventory");
  11582. LLSDxmlEncode2.AddArrayAndMap("AgentData", sb);
  11583. LLSDxmlEncode2.AddElem("AgentID", AgentId, sb);
  11584. LLSDxmlEncode2.AddElem("TransactionID", UUID.Random(), sb);
  11585. LLSDxmlEncode2.AddEndMapAndArray(sb);
  11586. if(folders.Length == 0)
  11587. {
  11588. LLSDxmlEncode2.AddEmptyArray("FolderData", sb);
  11589. }
  11590. else
  11591. {
  11592. LLSDxmlEncode2.AddArray("FolderData", sb);
  11593. foreach (InventoryFolderBase folder in folders)
  11594. {
  11595. LLSDxmlEncode2.AddMap(sb);
  11596. LLSDxmlEncode2.AddElem("FolderID", folder.ID, sb);
  11597. LLSDxmlEncode2.AddElem("ParentID", folder.ParentID, sb);
  11598. LLSDxmlEncode2.AddElem("Type", (int)folder.Type, sb);
  11599. LLSDxmlEncode2.AddElem("Name", folder.Name, sb);
  11600. LLSDxmlEncode2.AddEndMap(sb);
  11601. }
  11602. LLSDxmlEncode2.AddEndArray(sb);
  11603. }
  11604. if(items.Length == 0)
  11605. {
  11606. LLSDxmlEncode2.AddEmptyArray("ItemData", sb);
  11607. }
  11608. else
  11609. {
  11610. LLSDxmlEncode2.AddArray("ItemData", sb);
  11611. foreach (InventoryItemBase item in items)
  11612. {
  11613. LLSDxmlEncode2.AddMap(sb);
  11614. LLSDxmlEncode2.AddElem("ItemID", item.ID, sb);
  11615. LLSDxmlEncode2.AddElem("CallbackID", (uint)0, sb);
  11616. LLSDxmlEncode2.AddElem("FolderID", item.Folder, sb);
  11617. LLSDxmlEncode2.AddElem("CreatorID", item.CreatorIdAsUuid, sb);
  11618. LLSDxmlEncode2.AddElem("OwnerID", item.Owner, sb);
  11619. LLSDxmlEncode2.AddElem("GroupID", item.GroupID, sb);
  11620. LLSDxmlEncode2.AddElem("BaseMask", item.BasePermissions, sb);
  11621. LLSDxmlEncode2.AddElem("OwnerMask", item.CurrentPermissions, sb);
  11622. LLSDxmlEncode2.AddElem("GroupMask", item.GroupPermissions, sb);
  11623. LLSDxmlEncode2.AddElem("EveryoneMask", item.EveryOnePermissions, sb);
  11624. LLSDxmlEncode2.AddElem("NextOwnerMask", item.NextPermissions, sb);
  11625. LLSDxmlEncode2.AddElem("GroupOwned", item.GroupOwned, sb);
  11626. LLSDxmlEncode2.AddElem("AssetID", item.AssetID, sb);
  11627. LLSDxmlEncode2.AddElem("Type", item.AssetType, sb);
  11628. LLSDxmlEncode2.AddElem("InvType", item.InvType, sb);
  11629. LLSDxmlEncode2.AddElem("Flags", item.Flags, sb);
  11630. LLSDxmlEncode2.AddElem("SaleType", item.SaleType, sb);
  11631. LLSDxmlEncode2.AddElem("SalePrice", item.SalePrice, sb);
  11632. LLSDxmlEncode2.AddElem("Name", item.Name, sb);
  11633. LLSDxmlEncode2.AddElem("Description", item.Description, sb);
  11634. LLSDxmlEncode2.AddElem("CreationDate", item.CreationDate, sb);
  11635. LLSDxmlEncode2.AddElem("CRC",
  11636. Helpers.InventoryCRC(1000, 0, (sbyte)item.InvType,
  11637. (sbyte)item.AssetType, item.AssetID,
  11638. item.GroupID, 100,
  11639. item.Owner, item.CreatorIdAsUuid,
  11640. item.ID, item.Folder,
  11641. (uint)PermissionMask.All, 1, (uint)PermissionMask.All, (uint)PermissionMask.All,
  11642. (uint)PermissionMask.All),
  11643. sb);
  11644. LLSDxmlEncode2.AddEndMap(sb);
  11645. }
  11646. LLSDxmlEncode2.AddEndArray(sb);
  11647. }
  11648. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  11649. }
  11650. private HashSet<string> m_outPacketsToDrop;
  11651. public bool AddOutPacketToDropSet(string packetName)
  11652. {
  11653. if (m_outPacketsToDrop == null)
  11654. m_outPacketsToDrop = new HashSet<string>();
  11655. return m_outPacketsToDrop.Add(packetName);
  11656. }
  11657. public bool RemoveOutPacketFromDropSet(string packetName)
  11658. {
  11659. if (m_outPacketsToDrop == null)
  11660. return false;
  11661. return m_outPacketsToDrop.Remove(packetName);
  11662. }
  11663. public HashSet<string> GetOutPacketDropSet()
  11664. {
  11665. return new HashSet<string>(m_outPacketsToDrop);
  11666. }
  11667. private HashSet<string> m_inPacketsToDrop;
  11668. public bool AddInPacketToDropSet(string packetName)
  11669. {
  11670. if (m_inPacketsToDrop == null)
  11671. m_inPacketsToDrop = new HashSet<string>();
  11672. return m_inPacketsToDrop.Add(packetName);
  11673. }
  11674. public bool RemoveInPacketFromDropSet(string packetName)
  11675. {
  11676. if (m_inPacketsToDrop == null)
  11677. return false;
  11678. return m_inPacketsToDrop.Remove(packetName);
  11679. }
  11680. public HashSet<string> GetInPacketDropSet()
  11681. {
  11682. return new HashSet<string>(m_inPacketsToDrop);
  11683. }
  11684. public uint GetViewerCaps()
  11685. {
  11686. m_SupportObjectAnimations = false;
  11687. uint ret;
  11688. if(m_supportViewerCache)
  11689. ret = m_viewerHandShakeFlags;
  11690. else
  11691. ret = (m_viewerHandShakeFlags & 4) | 2; // disable probes
  11692. if (m_scene.CapsModule != null)
  11693. {
  11694. Caps cap = m_scene.CapsModule.GetCapsForUser(CircuitCode);
  11695. if(cap != null)
  11696. {
  11697. if((cap.Flags & Caps.CapsFlags.SentSeeds) != 0)
  11698. ret |= 0x1000;
  11699. if ((cap.Flags & Caps.CapsFlags.ObjectAnim) != 0)
  11700. {
  11701. m_SupportObjectAnimations = true;
  11702. ret |= 0x2000;
  11703. }
  11704. if ((cap.Flags & Caps.CapsFlags.WLEnv) != 0)
  11705. ret |= 0x4000;
  11706. if ((cap.Flags & Caps.CapsFlags.AdvEnv) != 0)
  11707. ret |= 0x8000;
  11708. }
  11709. }
  11710. return ret;
  11711. }
  11712. }
  11713. }