1
0

LLClientView.cs 596 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888
  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, 5000);
  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. // fix classifiedFlags maturity
  3619. if((classifiedFlags & 0x4e) == 0) // if none
  3620. classifiedFlags |= 0x4; // pg
  3621. ClassifiedInfoReplyPacket cr =
  3622. (ClassifiedInfoReplyPacket)PacketPool.Instance.GetPacket(
  3623. PacketType.ClassifiedInfoReply);
  3624. cr.AgentData = new ClassifiedInfoReplyPacket.AgentDataBlock();
  3625. cr.AgentData.AgentID = AgentId;
  3626. cr.Data = new ClassifiedInfoReplyPacket.DataBlock();
  3627. cr.Data.ClassifiedID = classifiedID;
  3628. cr.Data.CreatorID = creatorID;
  3629. cr.Data.CreationDate = creationDate;
  3630. cr.Data.ExpirationDate = expirationDate;
  3631. cr.Data.Category = category;
  3632. cr.Data.Name = Utils.StringToBytes(name);
  3633. cr.Data.Desc = Utils.StringToBytes(description);
  3634. cr.Data.ParcelID = parcelID;
  3635. cr.Data.ParentEstate = parentEstate;
  3636. cr.Data.SnapshotID = snapshotID;
  3637. cr.Data.SimName = Utils.StringToBytes(simName);
  3638. cr.Data.PosGlobal = new Vector3d(globalPos);
  3639. cr.Data.ParcelName = Utils.StringToBytes(parcelName);
  3640. cr.Data.ClassifiedFlags = classifiedFlags;
  3641. cr.Data.PriceForListing = price;
  3642. OutPacket(cr, ThrottleOutPacketType.Task);
  3643. }
  3644. public void SendAgentDropGroup(UUID groupID)
  3645. {
  3646. AgentDropGroupPacket dg =
  3647. (AgentDropGroupPacket)PacketPool.Instance.GetPacket(
  3648. PacketType.AgentDropGroup);
  3649. dg.AgentData = new AgentDropGroupPacket.AgentDataBlock();
  3650. dg.AgentData.AgentID = AgentId;
  3651. dg.AgentData.GroupID = groupID;
  3652. OutPacket(dg, ThrottleOutPacketType.Task);
  3653. }
  3654. public void SendAvatarNotesReply(UUID targetID, string text)
  3655. {
  3656. AvatarNotesReplyPacket an =
  3657. (AvatarNotesReplyPacket)PacketPool.Instance.GetPacket(
  3658. PacketType.AvatarNotesReply);
  3659. an.AgentData = new AvatarNotesReplyPacket.AgentDataBlock();
  3660. an.AgentData.AgentID = AgentId;
  3661. an.Data = new AvatarNotesReplyPacket.DataBlock();
  3662. an.Data.TargetID = targetID;
  3663. an.Data.Notes = Utils.StringToBytes(text);
  3664. OutPacket(an, ThrottleOutPacketType.Task);
  3665. }
  3666. public void SendAvatarPicksReply(UUID targetID, Dictionary<UUID, string> picks)
  3667. {
  3668. AvatarPicksReplyPacket ap =
  3669. (AvatarPicksReplyPacket)PacketPool.Instance.GetPacket(
  3670. PacketType.AvatarPicksReply);
  3671. ap.AgentData = new AvatarPicksReplyPacket.AgentDataBlock();
  3672. ap.AgentData.AgentID = AgentId;
  3673. ap.AgentData.TargetID = targetID;
  3674. ap.Data = new AvatarPicksReplyPacket.DataBlock[picks.Count];
  3675. int i = 0;
  3676. foreach (KeyValuePair<UUID, string> pick in picks)
  3677. {
  3678. ap.Data[i] = new AvatarPicksReplyPacket.DataBlock();
  3679. ap.Data[i].PickID = pick.Key;
  3680. ap.Data[i].PickName = Utils.StringToBytes(pick.Value);
  3681. i++;
  3682. }
  3683. OutPacket(ap, ThrottleOutPacketType.Task);
  3684. }
  3685. public void SendAvatarClassifiedReply(UUID targetID, Dictionary<UUID, string> classifieds)
  3686. {
  3687. AvatarClassifiedReplyPacket ac =
  3688. (AvatarClassifiedReplyPacket)PacketPool.Instance.GetPacket(
  3689. PacketType.AvatarClassifiedReply);
  3690. ac.AgentData = new AvatarClassifiedReplyPacket.AgentDataBlock();
  3691. ac.AgentData.AgentID = AgentId;
  3692. ac.AgentData.TargetID = targetID;
  3693. ac.Data = new AvatarClassifiedReplyPacket.DataBlock[classifieds.Count];
  3694. int i = 0;
  3695. foreach (KeyValuePair<UUID, string> classified in classifieds)
  3696. {
  3697. ac.Data[i] = new AvatarClassifiedReplyPacket.DataBlock();
  3698. ac.Data[i].ClassifiedID = classified.Key;
  3699. ac.Data[i].Name = Utils.StringToBytes(classified.Value);
  3700. i++;
  3701. }
  3702. OutPacket(ac, ThrottleOutPacketType.Task);
  3703. }
  3704. public void SendParcelDwellReply(int localID, UUID parcelID, float dwell)
  3705. {
  3706. ParcelDwellReplyPacket pd =
  3707. (ParcelDwellReplyPacket)PacketPool.Instance.GetPacket(
  3708. PacketType.ParcelDwellReply);
  3709. pd.AgentData = new ParcelDwellReplyPacket.AgentDataBlock();
  3710. pd.AgentData.AgentID = AgentId;
  3711. pd.Data = new ParcelDwellReplyPacket.DataBlock();
  3712. pd.Data.LocalID = localID;
  3713. pd.Data.ParcelID = parcelID;
  3714. pd.Data.Dwell = dwell;
  3715. OutPacket(pd, ThrottleOutPacketType.Land);
  3716. }
  3717. public void SendUserInfoReply(bool imViaEmail, bool visible, string email)
  3718. {
  3719. UserInfoReplyPacket ur =
  3720. (UserInfoReplyPacket)PacketPool.Instance.GetPacket(
  3721. PacketType.UserInfoReply);
  3722. string Visible = "hidden";
  3723. if (visible)
  3724. Visible = "default";
  3725. ur.AgentData = new UserInfoReplyPacket.AgentDataBlock();
  3726. ur.AgentData.AgentID = AgentId;
  3727. ur.UserData = new UserInfoReplyPacket.UserDataBlock();
  3728. ur.UserData.IMViaEMail = imViaEmail;
  3729. ur.UserData.DirectoryVisibility = Utils.StringToBytes(Visible);
  3730. ur.UserData.EMail = Utils.StringToBytes(email);
  3731. OutPacket(ur, ThrottleOutPacketType.Task);
  3732. }
  3733. public void SendCreateGroupReply(UUID groupID, bool success, string message)
  3734. {
  3735. CreateGroupReplyPacket createGroupReply = (CreateGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.CreateGroupReply);
  3736. createGroupReply.AgentData =
  3737. new CreateGroupReplyPacket.AgentDataBlock();
  3738. createGroupReply.ReplyData =
  3739. new CreateGroupReplyPacket.ReplyDataBlock();
  3740. createGroupReply.AgentData.AgentID = AgentId;
  3741. createGroupReply.ReplyData.GroupID = groupID;
  3742. createGroupReply.ReplyData.Success = success;
  3743. createGroupReply.ReplyData.Message = Utils.StringToBytes(message);
  3744. OutPacket(createGroupReply, ThrottleOutPacketType.Task);
  3745. }
  3746. public void SendUseCachedMuteList()
  3747. {
  3748. UseCachedMuteListPacket useCachedMuteList = (UseCachedMuteListPacket)PacketPool.Instance.GetPacket(PacketType.UseCachedMuteList);
  3749. useCachedMuteList.AgentData = new UseCachedMuteListPacket.AgentDataBlock();
  3750. useCachedMuteList.AgentData.AgentID = AgentId;
  3751. OutPacket(useCachedMuteList, ThrottleOutPacketType.Task);
  3752. }
  3753. public void SendEmpytMuteList()
  3754. {
  3755. GenericMessagePacket gmp = new GenericMessagePacket();
  3756. gmp.AgentData.AgentID = AgentId;
  3757. gmp.AgentData.SessionID = m_sessionId;
  3758. gmp.AgentData.TransactionID = UUID.Zero;
  3759. gmp.MethodData.Method = Util.StringToBytes256("emptymutelist");
  3760. gmp.ParamList = new GenericMessagePacket.ParamListBlock[1];
  3761. gmp.ParamList[0] = new GenericMessagePacket.ParamListBlock();
  3762. gmp.ParamList[0].Parameter = new byte[0];
  3763. OutPacket(gmp, ThrottleOutPacketType.Task);
  3764. }
  3765. public void SendMuteListUpdate(string filename)
  3766. {
  3767. MuteListUpdatePacket muteListUpdate = (MuteListUpdatePacket)PacketPool.Instance.GetPacket(PacketType.MuteListUpdate);
  3768. muteListUpdate.MuteData = new MuteListUpdatePacket.MuteDataBlock();
  3769. muteListUpdate.MuteData.AgentID = AgentId;
  3770. muteListUpdate.MuteData.Filename = Utils.StringToBytes(filename);
  3771. OutPacket(muteListUpdate, ThrottleOutPacketType.Task);
  3772. }
  3773. 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)
  3774. {
  3775. PickInfoReplyPacket pickInfoReply = (PickInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.PickInfoReply);
  3776. pickInfoReply.AgentData = new PickInfoReplyPacket.AgentDataBlock();
  3777. pickInfoReply.AgentData.AgentID = AgentId;
  3778. pickInfoReply.Data = new PickInfoReplyPacket.DataBlock();
  3779. pickInfoReply.Data.PickID = pickID;
  3780. pickInfoReply.Data.CreatorID = creatorID;
  3781. pickInfoReply.Data.TopPick = topPick;
  3782. pickInfoReply.Data.ParcelID = parcelID;
  3783. pickInfoReply.Data.Name = Utils.StringToBytes(name);
  3784. pickInfoReply.Data.Desc = Utils.StringToBytes(desc);
  3785. pickInfoReply.Data.SnapshotID = snapshotID;
  3786. pickInfoReply.Data.User = Utils.StringToBytes(user);
  3787. pickInfoReply.Data.OriginalName = Utils.StringToBytes(originalName);
  3788. pickInfoReply.Data.SimName = Utils.StringToBytes(simName);
  3789. pickInfoReply.Data.PosGlobal = new Vector3d(posGlobal);
  3790. pickInfoReply.Data.SortOrder = sortOrder;
  3791. pickInfoReply.Data.Enabled = enabled;
  3792. OutPacket(pickInfoReply, ThrottleOutPacketType.Task);
  3793. }
  3794. #endregion Scene/Avatar to Client
  3795. // Gesture
  3796. #region Appearance/ Wearables Methods
  3797. public void SendWearables(AvatarWearable[] wearables, int serial)
  3798. {
  3799. AgentWearablesUpdatePacket aw = (AgentWearablesUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentWearablesUpdate);
  3800. aw.AgentData.AgentID = AgentId;
  3801. aw.AgentData.SerialNum = (uint)serial;
  3802. aw.AgentData.SessionID = m_sessionId;
  3803. int count = 0;
  3804. for (int i = 0; i < wearables.Length; i++)
  3805. count += wearables[i].Count;
  3806. // TODO: don't create new blocks if recycling an old packet
  3807. aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[count];
  3808. AgentWearablesUpdatePacket.WearableDataBlock awb;
  3809. int idx = 0;
  3810. for (int i = 0; i < wearables.Length; i++)
  3811. {
  3812. for (int j = 0; j < wearables[i].Count; j++)
  3813. {
  3814. awb = new AgentWearablesUpdatePacket.WearableDataBlock();
  3815. awb.WearableType = (byte) i;
  3816. awb.AssetID = wearables[i][j].AssetID;
  3817. awb.ItemID = wearables[i][j].ItemID;
  3818. aw.WearableData[idx] = awb;
  3819. idx++;
  3820. // m_log.DebugFormat(
  3821. // "[APPEARANCE]: Sending wearable item/asset {0} {1} (index {2}) for {3}",
  3822. // awb.ItemID, awb.AssetID, i, Name);
  3823. }
  3824. }
  3825. OutPacket(aw, ThrottleOutPacketType.Task);
  3826. }
  3827. static private readonly byte[] AvatarAppearanceHeader = new byte[] {
  3828. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED,
  3829. 0, 0, 0, 0, // sequence number
  3830. 0, // extra
  3831. 0xff, 0xff, 0, 158 // ID 158 (low frequency bigendian) not zeroencoded
  3832. //0xff, 0xff, 0, 1, 158 // ID 158 (low frequency bigendian) zeroencoded
  3833. };
  3834. public void SendAppearance(UUID targetID, byte[] visualParams, byte[] textureEntry, float hover)
  3835. {
  3836. // doing post zero encode, because odds of beeing bad are not that low
  3837. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3838. Buffer.BlockCopy(AvatarAppearanceHeader, 0, buf.Data, 0, 10);
  3839. byte[] data = buf.Data;
  3840. int pos = 10;
  3841. //sender block
  3842. targetID.ToBytes(data, pos); pos += 16;
  3843. data[pos++] = 0;// is trial = false
  3844. // objectdata block ie texture
  3845. int len = textureEntry.Length;
  3846. if (len == 0)
  3847. {
  3848. data[pos++] = 0;
  3849. data[pos++] = 0;
  3850. }
  3851. else
  3852. {
  3853. data[pos++] = (byte)len;
  3854. data[pos++] = (byte)(len >> 8);
  3855. Buffer.BlockCopy(textureEntry, 0, data, pos, len); pos += len;
  3856. }
  3857. // visual parameters
  3858. len = visualParams.Length;
  3859. data[pos++] = (byte)len;
  3860. if(len > 0)
  3861. Buffer.BlockCopy(visualParams, 0, data, pos, len); pos += len;
  3862. // no AppearanceData
  3863. data[pos++] = 0;
  3864. // AppearanceHover vector 3
  3865. data[pos++] = 1;
  3866. Utils.FloatToBytesSafepos(0, data, pos); pos += 4;
  3867. Utils.FloatToBytesSafepos(0, data, pos); pos += 4;
  3868. Utils.FloatToBytesSafepos(hover, data, pos); pos += 4;
  3869. buf.DataLength = pos;
  3870. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, true);
  3871. }
  3872. static private readonly byte[] AvatarAnimationHeader = new byte[] {
  3873. Helpers.MSG_RELIABLE,
  3874. 0, 0, 0, 0, // sequence number
  3875. 0, // extra
  3876. 20 // ID (high frequency)
  3877. };
  3878. public void SendAnimations(UUID[] animations, int[] seqs, UUID sourceAgentId, UUID[] objectIDs)
  3879. {
  3880. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending animations for {0} to {1}", sourceAgentId, Name);
  3881. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3882. byte[] data = buf.Data;
  3883. //setup header
  3884. Buffer.BlockCopy(AvatarAnimationHeader, 0, data, 0, 7);
  3885. //agent block
  3886. sourceAgentId.ToBytes(data, 7);
  3887. // animations count
  3888. data[23] = (byte)animations.Length;
  3889. int pos = 24;
  3890. //self animations
  3891. if (sourceAgentId == AgentId)
  3892. {
  3893. List<int> withobjects = new List<int>(animations.Length);
  3894. List<int> noobjects = new List<int>(animations.Length);
  3895. for (int indx = 0; indx < animations.Length; ++indx)
  3896. {
  3897. if (objectIDs[indx] == sourceAgentId || objectIDs[indx] == UUID.Zero)
  3898. noobjects.Add(indx);
  3899. else
  3900. withobjects.Add(indx);
  3901. }
  3902. int i;
  3903. // first the ones with corresponding objects
  3904. for (int indx = 0; indx < withobjects.Count; ++indx)
  3905. {
  3906. i = withobjects[indx];
  3907. animations[i].ToBytes(data, pos); pos += 16;
  3908. Utils.IntToBytesSafepos(seqs[i], data, pos); pos += 4;
  3909. }
  3910. // then the rest
  3911. for (int indx = 0; indx < noobjects.Count; ++indx)
  3912. {
  3913. i = noobjects[indx];
  3914. animations[i].ToBytes(data, pos); pos += 16;
  3915. Utils.IntToBytesSafepos(seqs[i], data, pos); pos += 4;
  3916. }
  3917. // object ids block
  3918. data[pos++] = (byte)withobjects.Count;
  3919. for (int indx = 0; indx < withobjects.Count; ++indx)
  3920. {
  3921. i = withobjects[indx];
  3922. objectIDs[i].ToBytes(data, pos); pos += 16;
  3923. }
  3924. }
  3925. else
  3926. {
  3927. for(int i = 0; i < animations.Length; ++i)
  3928. {
  3929. animations[i].ToBytes(data, pos); pos += 16;
  3930. Utils.IntToBytesSafepos(seqs[i], data, pos); pos += 4;
  3931. }
  3932. data[pos++] = 0; // no object ids
  3933. }
  3934. data[pos++] = 0; // no physical avatar events
  3935. buf.DataLength = pos;
  3936. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  3937. }
  3938. public void SendObjectAnimations(UUID[] animations, int[] seqs, UUID senderId)
  3939. {
  3940. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending Object animations for {0} to {1}", sourceAgentId, Name);
  3941. if(!m_SupportObjectAnimations)
  3942. return;
  3943. ObjectAnimationPacket ani = (ObjectAnimationPacket)PacketPool.Instance.GetPacket(PacketType.ObjectAnimation);
  3944. // TODO: don't create new blocks if recycling an old packet
  3945. ani.Sender = new ObjectAnimationPacket.SenderBlock();
  3946. ani.Sender.ID = senderId;
  3947. ani.AnimationList = new ObjectAnimationPacket.AnimationListBlock[animations.Length];
  3948. for (int i = 0; i < animations.Length; ++i)
  3949. {
  3950. ani.AnimationList[i] = new ObjectAnimationPacket.AnimationListBlock();
  3951. ani.AnimationList[i].AnimID = animations[i];
  3952. ani.AnimationList[i].AnimSequenceID = seqs[i];
  3953. }
  3954. OutPacket(ani, ThrottleOutPacketType.Task);
  3955. }
  3956. #endregion
  3957. #region Avatar Packet/Data Sending Methods
  3958. /// <summary>
  3959. /// Send an ObjectUpdate packet with information about an avatar
  3960. /// </summary>
  3961. public void SendEntityFullUpdateImmediate(ISceneEntity ent)
  3962. {
  3963. if (ent == null || (!(ent is ScenePresence) && !(ent is SceneObjectPart)))
  3964. return;
  3965. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3966. Buffer.BlockCopy(objectUpdateHeader, 0, buf.Data, 0, 7);
  3967. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  3968. zc.Position = 7;
  3969. zc.AddUInt64(m_scene.RegionInfo.RegionHandle);
  3970. zc.AddUInt16(Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f));
  3971. zc.AddByte(1); // block count
  3972. if (ent is ScenePresence)
  3973. CreateAvatarUpdateBlock(ent as ScenePresence, zc);
  3974. else
  3975. CreatePrimUpdateBlock(ent as SceneObjectPart, (ScenePresence)SceneAgent, zc);
  3976. buf.DataLength = zc.Finish();
  3977. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  3978. }
  3979. public void SendEntityTerseUpdateImmediate(ISceneEntity ent)
  3980. {
  3981. if (ent == null)
  3982. return;
  3983. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  3984. //setup header and regioninfo block
  3985. Buffer.BlockCopy(terseUpdateHeader, 0, buf.Data, 0, 7);
  3986. if (ent is ScenePresence)
  3987. Utils.UInt64ToBytesSafepos(((ScenePresence)ent).RegionHandle, buf.Data, 7);
  3988. else
  3989. Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, buf.Data, 7);
  3990. Utils.UInt16ToBytes(Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f), buf.Data, 15);
  3991. buf.Data[17] = 1;
  3992. int pos = 18;
  3993. CreateImprovedTerseBlock(ent, buf.Data, ref pos, false);
  3994. buf.DataLength = pos;
  3995. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, true);
  3996. }
  3997. //UUID m_courseLocationPrey = UUID.Zero;
  3998. bool m_couseLocationLastEmpty = false;
  3999. static private readonly byte[] CoarseLocationUpdateHeader = new byte[] {
  4000. 0, // no acks plz
  4001. 0, 0, 0, 0, // sequence number
  4002. 0, // extra
  4003. 0xff, 6 // ID 6 (medium frequency)
  4004. };
  4005. public void SendCoarseLocationUpdate(List<UUID> users, List<Vector3> CoarseLocations)
  4006. {
  4007. // We don't need to update inactive clients.
  4008. if (!IsActive)
  4009. return;
  4010. int totalLocations = Math.Min(CoarseLocations.Count, 60);
  4011. if(totalLocations == 0)
  4012. {
  4013. if(m_couseLocationLastEmpty)
  4014. return;
  4015. m_couseLocationLastEmpty = true;
  4016. }
  4017. else
  4018. m_couseLocationLastEmpty = false;
  4019. int totalAgents = Math.Min(users.Count, 60);
  4020. if(totalAgents > totalLocations)
  4021. totalAgents = totalLocations;
  4022. int selfindex = -1;
  4023. int preyindex = -1;
  4024. //bool doprey = m_courseLocationPrey != UUID.Zero;
  4025. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4026. Buffer.BlockCopy(CoarseLocationUpdateHeader, 0, buf.Data, 0, 8);
  4027. byte[] data = buf.Data;
  4028. data[8] = (byte)totalLocations;
  4029. int pos = 9;
  4030. for (int i = 0; i < totalLocations; ++i)
  4031. {
  4032. data[pos++] = (byte)CoarseLocations[i].X;
  4033. data[pos++] = (byte)CoarseLocations[i].Y;
  4034. data[pos++] = CoarseLocations[i].Z > 1024 ? (byte)0 : (byte)(CoarseLocations[i].Z * 0.25f);
  4035. if (i < totalAgents)
  4036. {
  4037. if (users[i] == AgentId)
  4038. selfindex = i;
  4039. //if (doprey && users[i] == m_courseLocationPrey)
  4040. // preyindex = i;
  4041. }
  4042. }
  4043. Utils.Int16ToBytes((short)selfindex, data, pos); pos += 2;
  4044. Utils.Int16ToBytes((short)preyindex, data, pos); pos += 2;
  4045. data[pos++] = (byte)totalAgents;
  4046. for (int i = 0; i < totalAgents; ++i)
  4047. {
  4048. users[i].ToBytes(data, pos);
  4049. pos += 16;
  4050. }
  4051. buf.DataLength = pos;
  4052. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  4053. }
  4054. #endregion Avatar Packet/Data Sending Methods
  4055. #region Primitive Packet/Data Sending Methods
  4056. /// <summary>
  4057. /// Generate one of the object update packets based on PrimUpdateFlags
  4058. /// and broadcast the packet to clients
  4059. /// </summary>
  4060. public void SendEntityUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags)
  4061. {
  4062. if (entity is SceneObjectPart)
  4063. {
  4064. SceneObjectPart p = (SceneObjectPart)entity;
  4065. SceneObjectGroup g = p.ParentGroup;
  4066. if (g.HasPrivateAttachmentPoint && g.OwnerID != AgentId)
  4067. return; // Don't send updates for other people's HUDs
  4068. if((updateFlags ^ PrimUpdateFlags.SendInTransit) == 0)
  4069. {
  4070. List<uint> partIDs = (new List<uint> {p.LocalId});
  4071. lock (m_entityProps.SyncRoot)
  4072. m_entityProps.Remove(partIDs);
  4073. lock (m_entityUpdates.SyncRoot)
  4074. m_entityUpdates.Remove(partIDs);
  4075. return;
  4076. }
  4077. }
  4078. int priority = m_prioritizer.GetUpdatePriority(this, entity);
  4079. lock (m_entityUpdates.SyncRoot)
  4080. m_entityUpdates.Enqueue(priority, EntityUpdatesPool.Get(entity, updateFlags));
  4081. }
  4082. /// <summary>
  4083. /// Requeue an EntityUpdate when it was not acknowledged by the client.
  4084. /// We will update the priority and put it in the correct queue, merging update flags
  4085. /// with any other updates that may be queued for the same entity.
  4086. /// The original update time is used for the merged update.
  4087. /// </summary>
  4088. private void ResendPrimUpdate(EntityUpdate update)
  4089. {
  4090. // If the update exists in priority queue, it will be updated.
  4091. // If it does not exist then it will be added with the current (rather than its original) priority
  4092. int priority = m_prioritizer.GetUpdatePriority(this, update.Entity);
  4093. lock (m_entityUpdates.SyncRoot)
  4094. m_entityUpdates.Enqueue(priority, update);
  4095. }
  4096. /// <summary>
  4097. /// Requeue a list of EntityUpdates when they were not acknowledged by the client.
  4098. /// We will update the priority and put it in the correct queue, merging update flags
  4099. /// with any other updates that may be queued for the same entity.
  4100. /// The original update time is used for the merged update.
  4101. /// </summary>
  4102. private void ResendPrimUpdates(List<EntityUpdate> updates, OutgoingPacket oPacket)
  4103. {
  4104. // m_log.WarnFormat("[CLIENT] resending prim updates {0}, packet sequence number {1}", updates[0].UpdateTime, oPacket.SequenceNumber);
  4105. // Remove the update packet from the list of packets waiting for acknowledgement
  4106. // because we are requeuing the list of updates. They will be resent in new packets
  4107. // with the most recent state and priority.
  4108. m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber);
  4109. if (oPacket.Buffer == null)
  4110. return;
  4111. // Count this as a resent packet since we are going to requeue all of the updates contained in it
  4112. Interlocked.Increment(ref m_udpClient.PacketsResent);
  4113. m_udpServer.PacketsResentCount++;
  4114. foreach (EntityUpdate update in updates)
  4115. ResendPrimUpdate(update);
  4116. }
  4117. static private readonly byte[] objectUpdateHeader = new byte[] {
  4118. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED,
  4119. 0, 0, 0, 0, // sequence number
  4120. 0, // extra
  4121. 12 // ID (high frequency)
  4122. };
  4123. static private readonly byte[] terseUpdateHeader = new byte[] {
  4124. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED, // zero code is not as spec
  4125. 0, 0, 0, 0, // sequence number
  4126. 0, // extra
  4127. 15 // ID (high frequency)
  4128. };
  4129. static private readonly byte[] ObjectAnimationHeader = new byte[] {
  4130. Helpers.MSG_RELIABLE,
  4131. 0, 0, 0, 0, // sequence number
  4132. 0, // extra
  4133. 30 // ID (high frequency)
  4134. };
  4135. static private readonly byte[] CompressedObjectHeader = new byte[] {
  4136. Helpers.MSG_RELIABLE,
  4137. 0, 0, 0, 0, // sequence number
  4138. 0, // extra
  4139. 13 // ID (high frequency)
  4140. };
  4141. static private readonly byte[] ObjectUpdateCachedHeader = new byte[] {
  4142. Helpers.MSG_RELIABLE,
  4143. 0, 0, 0, 0, // sequence number
  4144. 0, // extra
  4145. 14 // ID (high frequency)
  4146. };
  4147. private void ProcessEntityUpdates(int maxUpdatesBytes)
  4148. {
  4149. if (!IsActive)
  4150. return;
  4151. ScenePresence mysp = (ScenePresence)SceneAgent;
  4152. if (mysp == null)
  4153. return;
  4154. List<EntityUpdate> objectUpdates = null;
  4155. List<EntityUpdate> objectUpdateProbes = null;
  4156. List<EntityUpdate> compressedUpdates = null;
  4157. List<EntityUpdate> terseUpdates = null;
  4158. List<SceneObjectPart> ObjectAnimationUpdates = null;
  4159. // Check to see if this is a flush
  4160. if (maxUpdatesBytes <= 0)
  4161. {
  4162. maxUpdatesBytes = Int32.MaxValue;
  4163. }
  4164. EntityUpdate update;
  4165. bool viewerCache = m_supportViewerCache;// && mysp.IsChildAgent; // only on child agents
  4166. bool doCulling = m_scene.ObjectsCullingByDistance;
  4167. float cullingrange = 64.0f;
  4168. Vector3 mypos = Vector3.Zero;
  4169. //bool orderedDequeue = m_scene.UpdatePrioritizationScheme == UpdatePrioritizationSchemes.SimpleAngularDistance;
  4170. bool orderedDequeue = false; // temporary off
  4171. HashSet<SceneObjectGroup> GroupsNeedFullUpdate = new HashSet<SceneObjectGroup>();
  4172. bool useCompressUpdate = false;
  4173. if (doCulling)
  4174. {
  4175. cullingrange = mysp.DrawDistance + m_scene.ReprioritizationDistance + 16f;
  4176. mypos = mysp.AbsolutePosition;
  4177. }
  4178. while (maxUpdatesBytes > 0)
  4179. {
  4180. if (!IsActive)
  4181. return;
  4182. lock (m_entityUpdates.SyncRoot)
  4183. {
  4184. if(orderedDequeue)
  4185. {
  4186. if (!m_entityUpdates.TryOrderedDequeue(out update))
  4187. break;
  4188. }
  4189. else
  4190. {
  4191. if (!m_entityUpdates.TryDequeue(out update))
  4192. break;
  4193. }
  4194. }
  4195. PrimUpdateFlags updateFlags = update.Flags;
  4196. if ((updateFlags & PrimUpdateFlags.Kill) != 0)
  4197. {
  4198. m_killRecord.Add(update.Entity.LocalId);
  4199. maxUpdatesBytes -= 30;
  4200. update.Free();
  4201. continue;
  4202. }
  4203. useCompressUpdate = false;
  4204. bool istree = false;
  4205. if (update.Entity is SceneObjectPart)
  4206. {
  4207. SceneObjectPart part = (SceneObjectPart)update.Entity;
  4208. SceneObjectGroup grp = part.ParentGroup;
  4209. if (grp.inTransit && ((update.Flags & PrimUpdateFlags.SendInTransit) == 0))
  4210. {
  4211. update.Free();
  4212. continue;
  4213. }
  4214. if (grp.IsDeleted)
  4215. {
  4216. // Don't send updates for objects that have been marked deleted.
  4217. // Instead send another kill object, because the first one may have gotten
  4218. // into a race condition
  4219. if (part == grp.RootPart && !m_killRecord.Contains(grp.LocalId))
  4220. {
  4221. m_killRecord.Add(grp.LocalId);
  4222. maxUpdatesBytes -= 30;
  4223. }
  4224. update.Free();
  4225. continue;
  4226. }
  4227. if (grp.IsAttachment)
  4228. {
  4229. // animated attachments are nasty if not supported by viewer
  4230. if(!m_SupportObjectAnimations && grp.RootPart.Shape.MeshFlagEntry)
  4231. {
  4232. update.Free();
  4233. continue;
  4234. }
  4235. // Someone else's HUD, why are we getting these?
  4236. if (grp.OwnerID != AgentId && grp.HasPrivateAttachmentPoint)
  4237. {
  4238. update.Free();
  4239. continue;
  4240. }
  4241. // if owner gone don't update it to anyone
  4242. ScenePresence sp;
  4243. if (!m_scene.TryGetScenePresence(part.OwnerID, out sp))
  4244. {
  4245. update.Free();
  4246. continue;
  4247. }
  4248. // On vehicle crossing, the attachments are received
  4249. // while the avatar is still a child. Don't send
  4250. // updates here because the LocalId has not yet
  4251. // been updated and the viewer will derender the
  4252. // attachments until the avatar becomes root.
  4253. if (sp.IsChildAgent)
  4254. {
  4255. update.Free();
  4256. continue;
  4257. }
  4258. // It's an attachment of a valid avatar, but
  4259. // doesn't seem to be attached, skip
  4260. List<SceneObjectGroup> atts = sp.GetAttachments();
  4261. bool found = false;
  4262. for (int indx = 0; indx < atts.Count; ++indx)
  4263. {
  4264. if (atts[indx] == grp)
  4265. {
  4266. found = true;
  4267. break;
  4268. }
  4269. }
  4270. if (!found)
  4271. {
  4272. update.Free();
  4273. continue;
  4274. }
  4275. if (m_disableFacelights)
  4276. {
  4277. if (grp.RootPart.Shape.State != (byte)AttachmentPoint.LeftHand &&
  4278. grp.RootPart.Shape.State != (byte)AttachmentPoint.RightHand)
  4279. {
  4280. part.Shape.LightEntry = false;
  4281. }
  4282. }
  4283. }
  4284. else if (doCulling)
  4285. {
  4286. if(GroupsNeedFullUpdate.Contains(grp))
  4287. {
  4288. update.Free();
  4289. continue;
  4290. }
  4291. bool inViewGroups = false;
  4292. lock(GroupsInView)
  4293. inViewGroups = GroupsInView.Contains(grp);
  4294. if(!inViewGroups)
  4295. {
  4296. Vector3 partpos = grp.getCenterOffset();
  4297. float dpos = (partpos - mypos).LengthSquared();
  4298. float maxview = grp.GetBoundsRadius() + cullingrange;
  4299. if (dpos > maxview * maxview)
  4300. {
  4301. update.Free();
  4302. continue;
  4303. }
  4304. if (!viewerCache || ((updateFlags & PrimUpdateFlags.UpdateProbe) == 0))
  4305. {
  4306. GroupsNeedFullUpdate.Add(grp);
  4307. update.Free();
  4308. continue;
  4309. }
  4310. }
  4311. }
  4312. if ((updateFlags & PrimUpdateFlags.UpdateProbe) != 0)
  4313. {
  4314. if (objectUpdateProbes == null)
  4315. {
  4316. objectUpdateProbes = new List<EntityUpdate>(32);
  4317. maxUpdatesBytes -= 18;
  4318. }
  4319. objectUpdateProbes.Add(update);
  4320. maxUpdatesBytes -= 12;
  4321. continue;
  4322. }
  4323. if ((updateFlags & PrimUpdateFlags.Animations) != 0)
  4324. {
  4325. if (m_SupportObjectAnimations && part.Animations != null)
  4326. {
  4327. if (ObjectAnimationUpdates == null)
  4328. ObjectAnimationUpdates = new List<SceneObjectPart>(8);
  4329. ObjectAnimationUpdates.Add(part);
  4330. maxUpdatesBytes -= 20 * part.Animations.Count + 24;
  4331. }
  4332. }
  4333. if(viewerCache)
  4334. useCompressUpdate = grp.IsViewerCachable;
  4335. istree = (part.Shape.PCode == (byte)PCode.Grass || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Tree);
  4336. }
  4337. else if (update.Entity is ScenePresence)
  4338. {
  4339. ScenePresence presence = (ScenePresence)update.Entity;
  4340. if (presence.IsDeleted)
  4341. {
  4342. update.Free();
  4343. continue;
  4344. }
  4345. // If ParentUUID is not UUID.Zero and ParentID is 0, this
  4346. // avatar is in the process of crossing regions while
  4347. // sat on an object. In this state, we don't want any
  4348. // updates because they will visually orbit the avatar.
  4349. // Update will be forced once crossing is completed anyway.
  4350. if (presence.ParentUUID != UUID.Zero && presence.ParentID == 0)
  4351. {
  4352. update.Free();
  4353. continue;
  4354. }
  4355. }
  4356. else // what is this update ?
  4357. {
  4358. update.Free();
  4359. continue;
  4360. }
  4361. #region UpdateFlags to packet type conversion
  4362. updateFlags &= PrimUpdateFlags.FullUpdate; // clear other control bits already handled
  4363. if(updateFlags == PrimUpdateFlags.None)
  4364. {
  4365. update.Free();
  4366. continue;
  4367. }
  4368. const PrimUpdateFlags canNotUseImprovedMask = ~(
  4369. PrimUpdateFlags.AttachmentPoint |
  4370. PrimUpdateFlags.Position |
  4371. PrimUpdateFlags.Rotation |
  4372. PrimUpdateFlags.Velocity |
  4373. PrimUpdateFlags.Acceleration |
  4374. PrimUpdateFlags.AngularVelocity |
  4375. PrimUpdateFlags.CollisionPlane |
  4376. PrimUpdateFlags.Textures
  4377. );
  4378. #endregion UpdateFlags to packet type conversion
  4379. #region Block Construction
  4380. if ((updateFlags & canNotUseImprovedMask) == 0)
  4381. {
  4382. if (terseUpdates == null)
  4383. {
  4384. terseUpdates = new List<EntityUpdate>(16);
  4385. maxUpdatesBytes -= 18;
  4386. }
  4387. terseUpdates.Add(update);
  4388. if (update.Entity is ScenePresence)
  4389. maxUpdatesBytes -= 63; // no texture entry
  4390. else
  4391. {
  4392. if ((updateFlags & PrimUpdateFlags.Textures) == 0)
  4393. maxUpdatesBytes -= 47;
  4394. else
  4395. maxUpdatesBytes -= 150; // aprox
  4396. }
  4397. }
  4398. else
  4399. {
  4400. if (update.Entity is ScenePresence)
  4401. {
  4402. maxUpdatesBytes -= 150; // crude estimation
  4403. if (objectUpdates == null)
  4404. {
  4405. objectUpdates = new List<EntityUpdate>(16);
  4406. maxUpdatesBytes -= 18;
  4407. }
  4408. objectUpdates.Add(update);
  4409. }
  4410. else
  4411. {
  4412. if (useCompressUpdate)
  4413. {
  4414. if (istree)
  4415. maxUpdatesBytes -= 64;
  4416. else
  4417. maxUpdatesBytes -= 120; // crude estimation
  4418. if (compressedUpdates == null)
  4419. {
  4420. compressedUpdates = new List<EntityUpdate>(16);
  4421. maxUpdatesBytes -= 18;
  4422. }
  4423. compressedUpdates.Add(update);
  4424. }
  4425. else
  4426. {
  4427. if (istree)
  4428. maxUpdatesBytes -= 70;
  4429. else
  4430. maxUpdatesBytes -= 150; // crude estimation
  4431. if (objectUpdates == null)
  4432. {
  4433. objectUpdates = new List<EntityUpdate>(16);
  4434. maxUpdatesBytes -= 18;
  4435. }
  4436. objectUpdates.Add(update);
  4437. }
  4438. }
  4439. }
  4440. #endregion Block Construction
  4441. }
  4442. #region Packet Sending
  4443. ushort timeDilation;
  4444. if (!IsActive)
  4445. return;
  4446. timeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);
  4447. if(objectUpdates != null)
  4448. {
  4449. //List<EntityUpdate> tau = new List<EntityUpdate>(30);
  4450. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4451. Buffer.BlockCopy(objectUpdateHeader, 0, buf.Data, 0, 7);
  4452. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  4453. zc.Position = 7;
  4454. zc.AddUInt64(m_scene.RegionInfo.RegionHandle);
  4455. zc.AddUInt16(timeDilation);
  4456. zc.AddByte(1); // tmp block count
  4457. int countposition = zc.Position - 1;
  4458. int lastpos = 0;
  4459. int lastzc = 0;
  4460. int count = 0;
  4461. bool shouldCreateSelected = false; //mantis 8639
  4462. EntityUpdate eu;
  4463. for(int indx = 0; indx < objectUpdates.Count; ++indx)
  4464. {
  4465. eu = objectUpdates[indx];
  4466. lastpos = zc.Position;
  4467. lastzc = zc.ZeroCount;
  4468. if (eu.Entity is ScenePresence)
  4469. CreateAvatarUpdateBlock((ScenePresence)eu.Entity, zc);
  4470. else
  4471. {
  4472. SceneObjectPart part = (SceneObjectPart)eu.Entity;
  4473. shouldCreateSelected = part.CreateSelected;
  4474. CreatePrimUpdateBlock(part, mysp, zc);
  4475. }
  4476. if (zc.Position < LLUDPServer.MAXPAYLOAD - 300)
  4477. {
  4478. //tau.Add(eu);
  4479. ++count;
  4480. }
  4481. else
  4482. {
  4483. // we need more packets
  4484. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4485. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, countposition); // start is the same
  4486. buf.Data[countposition] = (byte)count;
  4487. // get pending zeros at cut point
  4488. if(lastzc > 0)
  4489. {
  4490. buf.Data[lastpos++] = 0;
  4491. buf.Data[lastpos++] = (byte)lastzc;
  4492. }
  4493. buf.DataLength = lastpos;
  4494. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4495. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4496. null, false);
  4497. buf = newbuf;
  4498. zc.Data = buf.Data;
  4499. zc.ZeroCount = 0;
  4500. zc.Position = countposition + 1;
  4501. // im lazy now, just do last again
  4502. if (eu.Entity is ScenePresence)
  4503. CreateAvatarUpdateBlock((ScenePresence)eu.Entity, zc);
  4504. else
  4505. {
  4506. if(shouldCreateSelected) //mantis 8639 recover selected state
  4507. ((SceneObjectPart)eu.Entity).CreateSelected = true;
  4508. CreatePrimUpdateBlock((SceneObjectPart)eu.Entity, mysp, zc);
  4509. }
  4510. //tau = new List<EntityUpdate>(30);
  4511. //tau.Add(eu);
  4512. count = 1;
  4513. }
  4514. eu.Free(); //remove if using resend
  4515. }
  4516. if (count > 0)
  4517. {
  4518. buf.Data[countposition] = (byte)count;
  4519. buf.DataLength = zc.Finish();
  4520. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4521. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4522. null, false);
  4523. }
  4524. }
  4525. /* no zero encode compressed updates
  4526. if(compressedUpdates != null)
  4527. {
  4528. List<EntityUpdate> tau = new List<EntityUpdate>(30);
  4529. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4530. byte[] data = buf.Data;
  4531. Buffer.BlockCopy(CompressedObjectHeader, 0, data , 0, 7);
  4532. Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, data, 7); // 15
  4533. Utils.UInt16ToBytes(timeDilation, data, 15); // 17
  4534. int countposition = 17; // blocks count position
  4535. int pos = 18;
  4536. int lastpos = 0;
  4537. int count = 0;
  4538. foreach (EntityUpdate eu in compressedUpdates)
  4539. {
  4540. SceneObjectPart sop = (SceneObjectPart)eu.Entity;
  4541. if (sop.ParentGroup == null || sop.ParentGroup.IsDeleted)
  4542. continue;
  4543. lastpos = pos;
  4544. CreateCompressedUpdateBlock(sop, mysp, data, ref pos);
  4545. if (pos < LLUDPServer.MAXPAYLOAD)
  4546. {
  4547. tau.Add(eu);
  4548. ++count;
  4549. }
  4550. else
  4551. {
  4552. // we need more packets
  4553. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4554. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, countposition); // start is the same
  4555. buf.Data[countposition] = (byte)count;
  4556. buf.DataLength = lastpos;
  4557. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4558. delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4559. buf = newbuf;
  4560. data = buf.Data;
  4561. pos = 18;
  4562. // im lazy now, just do last again
  4563. CreateCompressedUpdateBlock(sop, mysp, data, ref pos);
  4564. tau = new List<EntityUpdate>(30);
  4565. tau.Add(eu);
  4566. count = 1;
  4567. }
  4568. }
  4569. if (count > 0)
  4570. {
  4571. buf.Data[countposition] = (byte)count;
  4572. buf.DataLength = pos;
  4573. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4574. delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4575. }
  4576. }
  4577. */
  4578. if (compressedUpdates != null)
  4579. {
  4580. //List<EntityUpdate> tau = new List<EntityUpdate>(30);
  4581. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4582. byte[] data = buf.Data;
  4583. Buffer.BlockCopy(CompressedObjectHeader, 0, data, 0, 7);
  4584. data[0] |= Helpers.MSG_ZEROCODED;
  4585. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  4586. zc.Position = 7;
  4587. zc.AddUInt64(m_scene.RegionInfo.RegionHandle);
  4588. zc.AddUInt16(timeDilation);
  4589. zc.AddByte(1); // tmp block count
  4590. int countposition = zc.Position - 1;
  4591. int lastpos = 0;
  4592. int lastzc = 0;
  4593. int count = 0;
  4594. bool shouldCreateSelected = false; //mantis 8639
  4595. EntityUpdate eu;
  4596. for (int indx = 0; indx < compressedUpdates.Count; ++indx)
  4597. {
  4598. eu = compressedUpdates[indx];
  4599. SceneObjectPart sop = (SceneObjectPart)eu.Entity;
  4600. if (sop.ParentGroup == null || sop.ParentGroup.IsDeleted)
  4601. continue;
  4602. shouldCreateSelected = sop.CreateSelected;
  4603. lastpos = zc.Position;
  4604. lastzc = zc.ZeroCount;
  4605. CreateCompressedUpdateBlockZC(sop, mysp, zc);
  4606. if (zc.Position < LLUDPServer.MAXPAYLOAD - 200)
  4607. {
  4608. //tau.Add(eu);
  4609. ++count;
  4610. }
  4611. else
  4612. {
  4613. // we need more packets
  4614. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4615. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, countposition); // start is the same
  4616. buf.Data[countposition] = (byte)count;
  4617. // get pending zeros at cut point
  4618. if (lastzc > 0)
  4619. {
  4620. buf.Data[lastpos++] = 0;
  4621. buf.Data[lastpos++] = (byte)lastzc;
  4622. }
  4623. buf.DataLength = lastpos;
  4624. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4625. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4626. null, false);
  4627. buf = newbuf;
  4628. zc.Data = buf.Data;
  4629. data[0] |= Helpers.MSG_ZEROCODED;
  4630. zc.ZeroCount = 0;
  4631. zc.Position = countposition + 1;
  4632. if (shouldCreateSelected) //mantis 8639 recover selected state
  4633. sop.CreateSelected = true;
  4634. // im lazy now, just do last again
  4635. CreateCompressedUpdateBlockZC(sop, mysp, zc);
  4636. //tau = new List<EntityUpdate>(30);
  4637. //tau.Add(eu);
  4638. count = 1;
  4639. }
  4640. eu.Free(); //remove if using resend
  4641. }
  4642. if (count > 0)
  4643. {
  4644. buf.Data[countposition] = (byte)count;
  4645. buf.DataLength = zc.Finish();
  4646. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4647. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  4648. null, false);
  4649. }
  4650. }
  4651. if (objectUpdateProbes != null)
  4652. {
  4653. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4654. byte[] data = buf.Data;
  4655. Buffer.BlockCopy(ObjectUpdateCachedHeader, 0, data, 0, 7);
  4656. Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, data, 7); // 15
  4657. Utils.UInt16ToBytes(timeDilation, data, 15); // 17
  4658. int countposition = 17; // blocks count position
  4659. int pos = 18;
  4660. int count = 0;
  4661. EntityUpdate eu;
  4662. for (int indx = 0; indx < objectUpdateProbes.Count; ++indx)
  4663. {
  4664. eu = objectUpdateProbes[indx];
  4665. SceneObjectPart sop = (SceneObjectPart)eu.Entity;
  4666. if (sop.ParentGroup == null || sop.ParentGroup.IsDeleted)
  4667. continue;
  4668. uint primflags = m_scene.Permissions.GenerateClientFlags(sop, mysp);
  4669. if (mysp.UUID != sop.OwnerID)
  4670. primflags &= ~(uint)PrimFlags.CreateSelected;
  4671. else
  4672. {
  4673. if (sop.CreateSelected)
  4674. primflags |= (uint)PrimFlags.CreateSelected;
  4675. else
  4676. primflags &= ~(uint)PrimFlags.CreateSelected;
  4677. }
  4678. Utils.UIntToBytes(sop.LocalId, data, pos); pos += 4;
  4679. Utils.UIntToBytes((uint)sop.PseudoCRC, data, pos); pos += 4; //WRONG
  4680. Utils.UIntToBytes(primflags, data, pos); pos += 4;
  4681. ++count;
  4682. if (pos > (LLUDPServer.MAXPAYLOAD - 13))
  4683. {
  4684. // we need more packets
  4685. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4686. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, countposition); // start is the same
  4687. buf.Data[countposition] = (byte)count;
  4688. buf.DataLength = pos;
  4689. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false);
  4690. buf = newbuf;
  4691. data = buf.Data;
  4692. pos = 18;
  4693. count = 0;
  4694. }
  4695. eu.Free();
  4696. }
  4697. if (count > 0)
  4698. {
  4699. buf.Data[countposition] = (byte)count;
  4700. buf.DataLength = pos;
  4701. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false);
  4702. }
  4703. }
  4704. if (terseUpdates != null)
  4705. {
  4706. int blocks = terseUpdates.Count;
  4707. //List<EntityUpdate> tau = new List<EntityUpdate>(30);
  4708. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4709. //setup header and regioninfo block
  4710. Buffer.BlockCopy(terseUpdateHeader, 0, buf.Data, 0, 7);
  4711. Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, buf.Data, 7);
  4712. Utils.UInt16ToBytes(timeDilation, buf.Data, 15);
  4713. int pos = 18;
  4714. int lastpos = 0;
  4715. int count = 0;
  4716. EntityUpdate eu;
  4717. for (int indx = 0; indx < terseUpdates.Count; ++indx)
  4718. {
  4719. eu = terseUpdates[indx];
  4720. lastpos = pos;
  4721. CreateImprovedTerseBlock(eu.Entity, buf.Data, ref pos, (eu.Flags & PrimUpdateFlags.Textures) != 0);
  4722. if (pos < LLUDPServer.MAXPAYLOAD)
  4723. {
  4724. //tau.Add(eu);
  4725. ++count;
  4726. --blocks;
  4727. }
  4728. else if (blocks > 0)
  4729. {
  4730. // we need more packets
  4731. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4732. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, 17); // start is the same
  4733. // copy what we done in excess
  4734. int extralen = pos - lastpos;
  4735. if(extralen > 0)
  4736. Buffer.BlockCopy(buf.Data, lastpos, newbuf.Data, 18, extralen);
  4737. pos = 18 + extralen;
  4738. buf.Data[17] = (byte)count;
  4739. buf.DataLength = lastpos;
  4740. // zero encode is not as spec
  4741. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4742. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, true);
  4743. null, true);
  4744. //tau = new List<EntityUpdate>(30);
  4745. //tau.Add(eu);
  4746. count = 1;
  4747. --blocks;
  4748. buf = newbuf;
  4749. }
  4750. eu.Free(); //remove if using resend
  4751. }
  4752. if (count > 0)
  4753. {
  4754. buf.Data[17] = (byte)count;
  4755. buf.DataLength = pos;
  4756. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  4757. //delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, true);
  4758. null, true);
  4759. }
  4760. }
  4761. if (ObjectAnimationUpdates != null)
  4762. {
  4763. SceneObjectPart sop;
  4764. for (int indx = 0; indx < ObjectAnimationUpdates.Count; ++indx)
  4765. {
  4766. sop = ObjectAnimationUpdates[indx];
  4767. if (sop.Animations == null)
  4768. continue;
  4769. SceneObjectGroup sog = sop.ParentGroup;
  4770. if (sog == null || sog.IsDeleted)
  4771. continue;
  4772. SceneObjectPart root = sog.RootPart;
  4773. if (root == null || root.Shape == null || !root.Shape.MeshFlagEntry)
  4774. continue;
  4775. UUID[] ids = null;
  4776. int[] seqs = null;
  4777. int count = sop.GetAnimations(out ids, out seqs);
  4778. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  4779. byte[] data = buf.Data;
  4780. //setup header
  4781. Buffer.BlockCopy(ObjectAnimationHeader, 0, data , 0, 7);
  4782. // sender block
  4783. sop.UUID.ToBytes(data, 7); // 23
  4784. //animations block
  4785. if (count > 255)
  4786. count = 255;
  4787. data[23] = (byte)count;
  4788. int pos = 24;
  4789. for(int i = 0; i < count; i++)
  4790. {
  4791. ids[i].ToBytes(data, pos); pos += 16;
  4792. Utils.IntToBytesSafepos(seqs[i], data, pos); pos += 4;
  4793. }
  4794. buf.DataLength = pos;
  4795. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  4796. }
  4797. }
  4798. #endregion Packet Sending
  4799. #region Handle deleted objects
  4800. if (m_killRecord.Count > 0)
  4801. {
  4802. SendKillObject(m_killRecord);
  4803. m_killRecord.Clear();
  4804. }
  4805. if(GroupsNeedFullUpdate.Count > 0)
  4806. {
  4807. foreach(SceneObjectGroup grp in GroupsNeedFullUpdate)
  4808. {
  4809. lock (GroupsInView)
  4810. GroupsInView.Add(grp);
  4811. PrimUpdateFlags flags = PrimUpdateFlags.CancelKill;
  4812. if(viewerCache && grp.IsViewerCachable)
  4813. flags |= PrimUpdateFlags.UpdateProbe;
  4814. foreach (SceneObjectPart p in grp.Parts)
  4815. SendEntityUpdate(p, flags);
  4816. }
  4817. }
  4818. #endregion
  4819. }
  4820. // hack.. dont use
  4821. /*
  4822. public void SendPartFullUpdate(ISceneEntity ent, uint? parentID)
  4823. {
  4824. if (ent is SceneObjectPart)
  4825. {
  4826. SceneObjectPart part = (SceneObjectPart)ent;
  4827. ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
  4828. packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
  4829. packet.RegionData.TimeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);
  4830. packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
  4831. ObjectUpdatePacket.ObjectDataBlock blk = CreatePrimUpdateBlock(part, mysp);
  4832. if (parentID.HasValue)
  4833. {
  4834. blk.ParentID = parentID.Value;
  4835. }
  4836. packet.ObjectData[0] = blk;
  4837. OutPacket(packet, ThrottleOutPacketType.Task, true);
  4838. }
  4839. // m_log.DebugFormat(
  4840. // "[LLCLIENTVIEW]: Sent {0} updates in ProcessEntityUpdates() for {1} {2} in {3}",
  4841. // updatesThisCall, Name, SceneAgent.IsChildAgent ? "child" : "root", Scene.Name);
  4842. //
  4843. }
  4844. */
  4845. public void ReprioritizeUpdates()
  4846. {
  4847. lock (m_entityUpdates.SyncRoot)
  4848. m_entityUpdates.Reprioritize(UpdatePriorityHandler);
  4849. CheckGroupsInView();
  4850. }
  4851. private bool CheckGroupsInViewBusy = false;
  4852. public void CheckGroupsInView()
  4853. {
  4854. bool doCulling = m_scene.ObjectsCullingByDistance;
  4855. if(!doCulling)
  4856. return;
  4857. if (!IsActive)
  4858. return;
  4859. if (CheckGroupsInViewBusy)
  4860. return;
  4861. ScenePresence mysp = (ScenePresence)SceneAgent;
  4862. if (mysp == null || mysp.IsDeleted)
  4863. return;
  4864. CheckGroupsInViewBusy = true;
  4865. float cullingrange = mysp.DrawDistance + m_scene.ReprioritizationDistance + 16f;
  4866. Vector3 mypos = mysp.AbsolutePosition;
  4867. HashSet<SceneObjectGroup> NewGroupsInView = new HashSet<SceneObjectGroup>();
  4868. HashSet<SceneObjectGroup> GroupsNeedFullUpdate = new HashSet<SceneObjectGroup>();
  4869. List<SceneObjectGroup> kills = new List<SceneObjectGroup>();
  4870. EntityBase[] entities = m_scene.Entities.GetEntities();
  4871. foreach (EntityBase e in entities)
  4872. {
  4873. if (!IsActive)
  4874. return;
  4875. if (e != null && e is SceneObjectGroup)
  4876. {
  4877. SceneObjectGroup grp = (SceneObjectGroup)e;
  4878. if(grp.IsDeleted || grp.IsAttachment )
  4879. continue;
  4880. bool inviewgroups;
  4881. lock (GroupsInView)
  4882. inviewgroups = GroupsInView.Contains(grp);
  4883. //temp handling of sits
  4884. if(grp.GetSittingAvatarsCount() > 0)
  4885. {
  4886. if (!inviewgroups)
  4887. GroupsNeedFullUpdate.Add(grp);
  4888. NewGroupsInView.Add(grp);
  4889. }
  4890. else
  4891. {
  4892. Vector3 grppos = grp.getCenterOffset();
  4893. float dpos = (grppos - mypos).LengthSquared();
  4894. float maxview = grp.GetBoundsRadius() + cullingrange;
  4895. if (dpos > maxview * maxview)
  4896. {
  4897. if(inviewgroups)
  4898. kills.Add(grp);
  4899. }
  4900. else
  4901. {
  4902. if (!inviewgroups)
  4903. GroupsNeedFullUpdate.Add(grp);
  4904. NewGroupsInView.Add(grp);
  4905. }
  4906. }
  4907. }
  4908. }
  4909. lock(GroupsInView)
  4910. GroupsInView = NewGroupsInView;
  4911. if (kills.Count > 0)
  4912. {
  4913. List<uint> partIDs = new List<uint>();
  4914. foreach(SceneObjectGroup grp in kills)
  4915. {
  4916. SendEntityUpdate(grp.RootPart, PrimUpdateFlags.Kill);
  4917. foreach(SceneObjectPart p in grp.Parts)
  4918. {
  4919. if(p != grp.RootPart)
  4920. partIDs.Add(p.LocalId);
  4921. }
  4922. }
  4923. kills.Clear();
  4924. if(partIDs.Count > 0)
  4925. {
  4926. lock (m_entityProps.SyncRoot)
  4927. m_entityProps.Remove(partIDs);
  4928. lock (m_entityUpdates.SyncRoot)
  4929. m_entityUpdates.Remove(partIDs);
  4930. }
  4931. }
  4932. if(GroupsNeedFullUpdate.Count > 0)
  4933. {
  4934. bool sendProbes = m_supportViewerCache && (m_viewerHandShakeFlags & 2) == 0;
  4935. if(sendProbes)
  4936. {
  4937. foreach (SceneObjectGroup grp in GroupsNeedFullUpdate)
  4938. {
  4939. PrimUpdateFlags flags = PrimUpdateFlags.CancelKill;
  4940. if (grp.IsViewerCachable)
  4941. flags |= PrimUpdateFlags.UpdateProbe;
  4942. foreach (SceneObjectPart p in grp.Parts)
  4943. SendEntityUpdate(p, flags);
  4944. }
  4945. }
  4946. else
  4947. {
  4948. m_viewerHandShakeFlags &= ~2U; // nexttime send probes
  4949. PrimUpdateFlags flags = PrimUpdateFlags.CancelKill;
  4950. foreach (SceneObjectGroup grp in GroupsNeedFullUpdate)
  4951. {
  4952. foreach (SceneObjectPart p in grp.Parts)
  4953. SendEntityUpdate(p, flags);
  4954. }
  4955. }
  4956. }
  4957. CheckGroupsInViewBusy = false;
  4958. }
  4959. private bool UpdatePriorityHandler(ref int priority, ISceneEntity entity)
  4960. {
  4961. if (!IsActive)
  4962. return false;
  4963. priority = m_prioritizer.GetUpdatePriority(this, entity);
  4964. return true;
  4965. }
  4966. public void FlushPrimUpdates()
  4967. {
  4968. m_log.WarnFormat("[CLIENT]: Flushing prim updates to " + m_firstName + " " + m_lastName);
  4969. while (m_entityUpdates.Count > 0)
  4970. ProcessEntityUpdates(-1);
  4971. }
  4972. #endregion Primitive Packet/Data Sending Methods
  4973. // These are used to implement an adaptive backoff in the number
  4974. // of updates converted to packets. Since we don't want packets
  4975. // to sit in the queue with old data, only convert enough updates
  4976. // to packets that can be sent in 30ms.
  4977. void HandleQueueEmpty(ThrottleOutPacketTypeFlags categories)
  4978. {
  4979. if(m_scene == null)
  4980. return;
  4981. if ((categories & ThrottleOutPacketTypeFlags.Task) != 0)
  4982. {
  4983. int maxUpdateBytes = m_udpClient.GetCatBytesCanSend(ThrottleOutPacketType.Task, 30);
  4984. if (m_entityUpdates.Count > 0)
  4985. ProcessEntityUpdates(maxUpdateBytes);
  4986. if (m_entityProps.Count > 0)
  4987. ProcessEntityPropertyRequests(maxUpdateBytes);
  4988. }
  4989. if ((categories & ThrottleOutPacketTypeFlags.Texture) != 0)
  4990. ImageManager.ProcessImageQueue(m_udpServer.TextureSendLimit);
  4991. }
  4992. internal bool HandleHasUpdates(ThrottleOutPacketTypeFlags categories)
  4993. {
  4994. if ((categories & ThrottleOutPacketTypeFlags.Task) != 0)
  4995. {
  4996. if (m_entityUpdates.Count > 0)
  4997. return true;
  4998. if (m_entityProps.Count > 0)
  4999. return true;
  5000. }
  5001. if ((categories & ThrottleOutPacketTypeFlags.Texture) != 0)
  5002. {
  5003. if (ImageManager.HasUpdates())
  5004. return true;
  5005. }
  5006. return false;
  5007. }
  5008. public void SendAssetUploadCompleteMessage(sbyte AssetType, bool Success, UUID AssetFullID)
  5009. {
  5010. AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
  5011. newPack.AssetBlock.Type = AssetType;
  5012. newPack.AssetBlock.Success = Success;
  5013. newPack.AssetBlock.UUID = AssetFullID;
  5014. newPack.Header.Zerocoded = true;
  5015. OutPacket(newPack, ThrottleOutPacketType.Asset);
  5016. }
  5017. public void SendXferRequest(ulong XferID, short AssetType, UUID vFileID, byte FilePath, byte[] FileName)
  5018. {
  5019. RequestXferPacket newPack = new RequestXferPacket();
  5020. newPack.XferID.ID = XferID;
  5021. newPack.XferID.VFileType = AssetType;
  5022. newPack.XferID.VFileID = vFileID;
  5023. newPack.XferID.FilePath = FilePath;
  5024. newPack.XferID.Filename = FileName;
  5025. newPack.Header.Zerocoded = true;
  5026. OutPacket(newPack, ThrottleOutPacketType.Asset);
  5027. }
  5028. public void SendConfirmXfer(ulong xferID, uint PacketID)
  5029. {
  5030. ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket();
  5031. newPack.XferID.ID = xferID;
  5032. newPack.XferID.Packet = PacketID;
  5033. newPack.Header.Zerocoded = true;
  5034. OutPacket(newPack, ThrottleOutPacketType.Asset);
  5035. }
  5036. public void SendInitiateDownload(string simFileName, string clientFileName)
  5037. {
  5038. InitiateDownloadPacket newPack = new InitiateDownloadPacket();
  5039. newPack.AgentData.AgentID = AgentId;
  5040. newPack.FileData.SimFilename = Utils.StringToBytes(simFileName);
  5041. newPack.FileData.ViewerFilename = Utils.StringToBytes(clientFileName);
  5042. OutPacket(newPack, ThrottleOutPacketType.Asset);
  5043. }
  5044. public void SendImageFirstPart(
  5045. ushort numParts, UUID ImageUUID, uint ImageSize, byte[] ImageData, byte imageCodec)
  5046. {
  5047. ImageDataPacket im = new ImageDataPacket();
  5048. im.ImageID.Packets = numParts;
  5049. im.ImageID.ID = ImageUUID;
  5050. if (ImageSize > 0)
  5051. im.ImageID.Size = ImageSize;
  5052. im.ImageData.Data = ImageData;
  5053. im.ImageID.Codec = imageCodec;
  5054. im.Header.Zerocoded = true;
  5055. OutPacket(im, ThrottleOutPacketType.Texture);
  5056. }
  5057. public void SendImageNextPart(ushort partNumber, UUID imageUuid, byte[] imageData)
  5058. {
  5059. ImagePacketPacket im = new ImagePacketPacket();
  5060. im.ImageID.Packet = partNumber;
  5061. im.ImageID.ID = imageUuid;
  5062. im.ImageData.Data = imageData;
  5063. OutPacket(im, ThrottleOutPacketType.Texture);
  5064. }
  5065. public void SendImageNotFound(UUID imageid)
  5066. {
  5067. ImageNotInDatabasePacket notFoundPacket
  5068. = (ImageNotInDatabasePacket)PacketPool.Instance.GetPacket(PacketType.ImageNotInDatabase);
  5069. notFoundPacket.ImageID.ID = imageid;
  5070. OutPacket(notFoundPacket, ThrottleOutPacketType.Texture);
  5071. }
  5072. public void SendShutdownConnectionNotice()
  5073. {
  5074. OutPacket(PacketPool.Instance.GetPacket(PacketType.DisableSimulator), ThrottleOutPacketType.Unknown);
  5075. }
  5076. static private readonly byte[] SimStatsHeader = new byte[] {
  5077. 0,
  5078. 0, 0, 0, 0, // sequence number
  5079. 0, // extra
  5080. 0xff, 0xff, 0, 140 // ID 140 (low frequency bigendian)
  5081. };
  5082. public void SendSimStats(SimStats stats)
  5083. {
  5084. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  5085. byte[] data = buf.Data;
  5086. //setup header
  5087. Buffer.BlockCopy(SimStatsHeader, 0, data, 0, 10);
  5088. // Region Block
  5089. Utils.UIntToBytesSafepos(stats.RegionX, data, 10);
  5090. Utils.UIntToBytesSafepos(stats.RegionY, data, 14);
  5091. Utils.UIntToBytesSafepos(stats.RegionFlags, data, 18);
  5092. Utils.UIntToBytesSafepos(stats.ObjectCapacity, data, 22); // 26
  5093. // stats
  5094. data[26] = (byte)stats.StatsBlock.Length;
  5095. int pos = 27;
  5096. stats.StatsBlock[15].StatValue /= 1024; // unack is in KB
  5097. for (int i = 0; i< stats.StatsBlock.Length; ++i)
  5098. {
  5099. Utils.UIntToBytesSafepos(stats.StatsBlock[i].StatID, data, pos); pos += 4;
  5100. Utils.FloatToBytesSafepos(stats.StatsBlock[i].StatValue, data, pos); pos += 4;
  5101. }
  5102. //no PID
  5103. Utils.IntToBytesSafepos(0, data, pos); pos += 4;
  5104. // no regioninfo (extended flags)
  5105. data[pos++] = 0; // = 1;
  5106. //Utils.UInt64ToBytesSafepos(RegionFlagsExtended, data, pos); pos += 8;
  5107. buf.DataLength = pos;
  5108. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  5109. }
  5110. public void SendObjectPropertiesFamilyData(ISceneEntity entity, uint requestFlags)
  5111. {
  5112. lock (m_entityProps.SyncRoot)
  5113. m_entityProps.Enqueue(0, EntityUpdatesPool.Get(entity, (PrimUpdateFlags)requestFlags, true, false));
  5114. }
  5115. private void ResendPropertyUpdate(EntityUpdate update)
  5116. {
  5117. lock (m_entityProps.SyncRoot)
  5118. m_entityProps.Enqueue(0, update);
  5119. }
  5120. private void ResendPropertyUpdates(List<EntityUpdate> updates, OutgoingPacket oPacket)
  5121. {
  5122. // m_log.WarnFormat("[CLIENT] resending object property {0}",updates[0].UpdateTime);
  5123. // Remove the update packet from the list of packets waiting for acknowledgement
  5124. // because we are requeuing the list of updates. They will be resent in new packets
  5125. // with the most recent state.
  5126. m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber);
  5127. // Count this as a resent packet since we are going to requeue all of the updates contained in it
  5128. Interlocked.Increment(ref m_udpClient.PacketsResent);
  5129. // We're not going to worry about interlock yet since its not currently critical that this total count
  5130. // is 100% correct
  5131. m_udpServer.PacketsResentCount++;
  5132. foreach (EntityUpdate update in updates)
  5133. ResendPropertyUpdate(update);
  5134. }
  5135. public void SendObjectPropertiesReply(ISceneEntity entity)
  5136. {
  5137. lock (m_entityProps.SyncRoot)
  5138. m_entityProps.Enqueue(0, EntityUpdatesPool.Get(entity,0,false,true));
  5139. }
  5140. static private readonly byte[] ObjectPropertyUpdateHeader = new byte[] {
  5141. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED,
  5142. 0, 0, 0, 0, // sequence number
  5143. 0, // extra
  5144. 0xff, 9 // ID (medium frequency)
  5145. };
  5146. static private readonly byte[] ObjectFamilyUpdateHeader = new byte[] {
  5147. Helpers.MSG_RELIABLE | Helpers.MSG_ZEROCODED,
  5148. 0, 0, 0, 0, // sequence number
  5149. 0, // extra
  5150. 0xff, 10 // ID (medium frequency)
  5151. };
  5152. private void ProcessEntityPropertyRequests(int maxUpdateBytes)
  5153. {
  5154. List<EntityUpdate> objectPropertiesUpdates = null;
  5155. List<EntityUpdate> objectPropertiesFamilyUpdates = null;
  5156. List<EntityUpdate> used = new List<EntityUpdate>(64);
  5157. List<SceneObjectPart> needPhysics = null;
  5158. // bool orderedDequeue = m_scene.UpdatePrioritizationScheme == UpdatePrioritizationSchemes.SimpleAngularDistance;
  5159. bool orderedDequeue = false; // for now
  5160. EntityUpdate update;
  5161. while (maxUpdateBytes > 0)
  5162. {
  5163. lock (m_entityProps.SyncRoot)
  5164. {
  5165. if(orderedDequeue)
  5166. {
  5167. if (!m_entityProps.TryOrderedDequeue(out update))
  5168. break;
  5169. }
  5170. else
  5171. {
  5172. if (!m_entityProps.TryDequeue(out update))
  5173. break;
  5174. }
  5175. }
  5176. if (update.PropsFlags == 0)
  5177. {
  5178. update.Free();
  5179. continue;
  5180. }
  5181. SceneObjectPart sop = (SceneObjectPart)update.Entity as SceneObjectPart;
  5182. if(sop == null)
  5183. {
  5184. update.Free();
  5185. continue;
  5186. }
  5187. used.Add(update);
  5188. if ((update.PropsFlags & ObjectPropertyUpdateFlags.Family) != 0)
  5189. {
  5190. if(objectPropertiesFamilyUpdates == null)
  5191. objectPropertiesFamilyUpdates = new List<EntityUpdate>();
  5192. objectPropertiesFamilyUpdates.Add(update);
  5193. maxUpdateBytes -= 100;
  5194. }
  5195. if ((update.PropsFlags & ObjectPropertyUpdateFlags.Object) != 0)
  5196. {
  5197. if(needPhysics == null)
  5198. needPhysics = new List<SceneObjectPart>();
  5199. needPhysics.Add(sop);
  5200. if(objectPropertiesUpdates == null)
  5201. objectPropertiesUpdates = new List<EntityUpdate>();
  5202. objectPropertiesUpdates.Add(update);
  5203. maxUpdateBytes -= 200; // aprox
  5204. }
  5205. }
  5206. if (objectPropertiesUpdates != null)
  5207. {
  5208. int blocks = objectPropertiesUpdates.Count;
  5209. //List<EntityUpdate> tau = new List<EntityUpdate>(30);
  5210. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  5211. Buffer.BlockCopy(ObjectPropertyUpdateHeader, 0, buf.Data, 0, 8);
  5212. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  5213. zc.Position = 8;
  5214. zc.AddByte(1); // tmp block count
  5215. int countposition = zc.Position - 1;
  5216. int lastpos = 0;
  5217. int lastzc = 0;
  5218. int count = 0;
  5219. foreach (EntityUpdate eu in objectPropertiesUpdates)
  5220. {
  5221. lastpos = zc.Position;
  5222. lastzc = zc.ZeroCount;
  5223. CreateObjectPropertiesBlock((SceneObjectPart)eu.Entity, zc);
  5224. if (zc.Position < LLUDPServer.MAXPAYLOAD)
  5225. {
  5226. //tau.Add(eu);
  5227. ++count;
  5228. --blocks;
  5229. }
  5230. else if (blocks > 0)
  5231. {
  5232. // we need more packets
  5233. UDPPacketBuffer newbuf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  5234. Buffer.BlockCopy(buf.Data, 0, newbuf.Data, 0, countposition); // start is the same
  5235. buf.Data[countposition] = (byte)count;
  5236. // get pending zeros at cut point
  5237. if (lastzc > 0)
  5238. {
  5239. buf.Data[lastpos++] = 0;
  5240. buf.Data[lastpos++] = (byte)lastzc;
  5241. }
  5242. buf.DataLength = lastpos;
  5243. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  5244. // delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  5245. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  5246. buf = newbuf;
  5247. zc.Data = buf.Data;
  5248. zc.ZeroCount = 0;
  5249. zc.Position = countposition + 1;
  5250. // im lazy now, just do last again
  5251. CreateObjectPropertiesBlock((SceneObjectPart)eu.Entity, zc);
  5252. //tau = new List<EntityUpdate>(30);
  5253. //tau.Add(eu);
  5254. count = 1;
  5255. --blocks;
  5256. }
  5257. }
  5258. if (count > 0)
  5259. {
  5260. buf.Data[countposition] = (byte)count;
  5261. buf.DataLength = zc.Finish();
  5262. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  5263. // delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  5264. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  5265. }
  5266. }
  5267. if (objectPropertiesFamilyUpdates != null)
  5268. {
  5269. foreach (EntityUpdate eu in objectPropertiesFamilyUpdates)
  5270. {
  5271. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  5272. Buffer.BlockCopy(ObjectFamilyUpdateHeader, 0, buf.Data, 0, 8);
  5273. LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data);
  5274. zc.Position = 8;
  5275. CreateObjectPropertiesFamilyBlock((SceneObjectPart)eu.Entity, eu.Flags, zc);
  5276. buf.DataLength = zc.Finish();
  5277. //List<EntityUpdate> tau = new List<EntityUpdate>(1);
  5278. //tau.Add(new ObjectPropertyUpdate((ISceneEntity) eu, (uint)eu.Flags, true, false));
  5279. //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
  5280. // delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
  5281. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
  5282. }
  5283. }
  5284. if (needPhysics != null)
  5285. {
  5286. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  5287. if(eq != null)
  5288. {
  5289. osUTF8 sb = eq.StartEvent("ObjectPhysicsProperties");
  5290. LLSDxmlEncode2.AddArray("ObjectData", sb);
  5291. foreach (SceneObjectPart sop in needPhysics)
  5292. {
  5293. LLSDxmlEncode2.AddMap(sb);
  5294. LLSDxmlEncode2.AddElem("LocalID",(int)sop.LocalId, sb);
  5295. LLSDxmlEncode2.AddElem("Density", sop.Density, sb);
  5296. LLSDxmlEncode2.AddElem("Friction", sop.Friction, sb);
  5297. LLSDxmlEncode2.AddElem("GravityMultiplier", sop.GravityModifier, sb);
  5298. LLSDxmlEncode2.AddElem("Restitution", sop.Restitution, sb);
  5299. LLSDxmlEncode2.AddElem("PhysicsShapeType", (int)sop.PhysicsShapeType, sb);
  5300. LLSDxmlEncode2.AddEndMap(sb);
  5301. }
  5302. LLSDxmlEncode2.AddEndArray(sb);
  5303. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  5304. }
  5305. }
  5306. foreach(EntityUpdate eu in used)
  5307. eu.Free();
  5308. }
  5309. private void CreateObjectPropertiesFamilyBlock(SceneObjectPart sop, PrimUpdateFlags requestFlags, LLUDPZeroEncoder zc)
  5310. {
  5311. SceneObjectPart root = sop.ParentGroup.RootPart;
  5312. zc.AddUInt((uint)requestFlags);
  5313. zc.AddUUID(sop.UUID);
  5314. if (sop.OwnerID == sop.GroupID)
  5315. zc.AddZeros(16);
  5316. else
  5317. zc.AddUUID(sop.OwnerID);
  5318. zc.AddUUID(sop.GroupID);
  5319. zc.AddUInt(root.BaseMask);
  5320. zc.AddUInt(root.OwnerMask);
  5321. zc.AddUInt(root.GroupMask);
  5322. zc.AddUInt(root.EveryoneMask);
  5323. zc.AddUInt(root.NextOwnerMask);
  5324. zc.AddZeros(4); // int ownership cost
  5325. //sale info block
  5326. zc.AddByte(root.ObjectSaleType);
  5327. zc.AddInt(root.SalePrice);
  5328. zc.AddUInt(sop.Category); //Category
  5329. zc.AddUUID(sop.LastOwnerID);
  5330. //name
  5331. zc.AddShortLimitedUTF8(sop.osUTF8Name);
  5332. //Description
  5333. zc.AddShortLimitedUTF8(sop.osUTF8Description);
  5334. }
  5335. private void CreateObjectPropertiesBlock(SceneObjectPart sop, LLUDPZeroEncoder zc)
  5336. {
  5337. SceneObjectPart root = sop.ParentGroup.RootPart;
  5338. zc.AddUUID(sop.UUID);
  5339. zc.AddUUID(sop.CreatorID);
  5340. if (sop.OwnerID == sop.GroupID)
  5341. zc.AddZeros(16);
  5342. else
  5343. zc.AddUUID(sop.OwnerID);
  5344. zc.AddUUID(sop.GroupID);
  5345. zc.AddUInt64((ulong)sop.CreationDate * 1000000UL);
  5346. zc.AddUInt(root.BaseMask);
  5347. zc.AddUInt(root.OwnerMask);
  5348. zc.AddUInt(root.GroupMask);
  5349. zc.AddUInt(root.EveryoneMask);
  5350. zc.AddUInt(root.NextOwnerMask);
  5351. zc.AddZeros(4); // int ownership cost
  5352. //sale info block
  5353. zc.AddByte(root.ObjectSaleType);
  5354. zc.AddInt(root.SalePrice);
  5355. //aggregated perms we may will need to fix this
  5356. zc.AddByte(0); //AggregatePerms
  5357. zc.AddByte(0); //AggregatePermTextures;
  5358. zc.AddByte(0); //AggregatePermTexturesOwner
  5359. //inventory info
  5360. zc.AddUInt(sop.Category); //Category
  5361. zc.AddInt16((short)sop.InventorySerial);
  5362. zc.AddUUID(sop.FromUserInventoryItemID);
  5363. zc.AddUUID(UUID.Zero); //FolderID
  5364. zc.AddUUID(UUID.Zero); //FromTaskID
  5365. zc.AddUUID(sop.LastOwnerID);
  5366. //name
  5367. zc.AddShortLimitedUTF8(sop.osUTF8Name);
  5368. //Description
  5369. zc.AddShortLimitedUTF8(sop.osUTF8Description);
  5370. // touch name
  5371. zc.AddShortLimitedUTF8(sop.osUTF8TouchName);
  5372. // sit name
  5373. zc.AddShortLimitedUTF8(sop.osUTF8SitName);
  5374. //texture ids block
  5375. // still not sending, not clear the impact on viewers, if any.
  5376. // does seem redundant
  5377. // to send we will need proper list of face texture ids without having to unpack texture entry all the time
  5378. zc.AddZeros(1);
  5379. }
  5380. #region Estate Data Sending Methods
  5381. private static bool convertParamStringToBool(byte[] field)
  5382. {
  5383. string s = Utils.BytesToString(field);
  5384. if (s == "1" || s.ToLower() == "y" || s.ToLower() == "yes" || s.ToLower() == "t" || s.ToLower() == "true")
  5385. {
  5386. return true;
  5387. }
  5388. return false;
  5389. }
  5390. public void SendEstateList(UUID invoice, int code, UUID[] Data, uint estateID)
  5391. {
  5392. int TotalnumberIDs = Data.Length;
  5393. int numberIDs;
  5394. int IDIndex = 0;
  5395. do
  5396. {
  5397. if(TotalnumberIDs > 63)
  5398. numberIDs = 63;
  5399. else
  5400. numberIDs = TotalnumberIDs;
  5401. TotalnumberIDs -= numberIDs;
  5402. EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
  5403. packet.AgentData.TransactionID = UUID.Random();
  5404. packet.AgentData.AgentID = AgentId;
  5405. packet.AgentData.SessionID = SessionId;
  5406. packet.MethodData.Invoice = invoice;
  5407. packet.MethodData.Method = Utils.StringToBytes("setaccess");
  5408. EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[6 + numberIDs];
  5409. for (int i = 0; i < (6 + numberIDs); i++)
  5410. {
  5411. returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
  5412. }
  5413. returnblock[0].Parameter = Utils.StringToBytes(estateID.ToString());
  5414. returnblock[1].Parameter = Utils.StringToBytes(code.ToString());
  5415. if((code & 1) != 0) // allowagents
  5416. returnblock[2].Parameter = Utils.StringToBytes(numberIDs.ToString());
  5417. else
  5418. returnblock[2].Parameter = Utils.StringToBytes("0");
  5419. if((code & 2) != 0) // groups
  5420. returnblock[3].Parameter = Utils.StringToBytes(numberIDs.ToString());
  5421. else
  5422. returnblock[3].Parameter = Utils.StringToBytes("0");
  5423. if((code & 4) != 0) // bans
  5424. returnblock[4].Parameter = Utils.StringToBytes(numberIDs.ToString());
  5425. else
  5426. returnblock[4].Parameter = Utils.StringToBytes("0");
  5427. if((code & 8) != 0) // managers
  5428. returnblock[5].Parameter = Utils.StringToBytes(numberIDs.ToString());
  5429. else
  5430. returnblock[5].Parameter = Utils.StringToBytes("0");
  5431. int j = 6;
  5432. for (int i = 0; i < numberIDs; i++)
  5433. {
  5434. returnblock[j].Parameter = Data[IDIndex].GetBytes();
  5435. j++;
  5436. IDIndex++;
  5437. }
  5438. packet.ParamList = returnblock;
  5439. packet.Header.Reliable = true;
  5440. OutPacket(packet, ThrottleOutPacketType.Task);
  5441. } while (TotalnumberIDs > 0);
  5442. }
  5443. public void SendBannedUserList(UUID invoice, EstateBan[] bl, uint estateID)
  5444. {
  5445. List<UUID> BannedUsers = new List<UUID>();
  5446. for (int i = 0; i < bl.Length; i++)
  5447. {
  5448. if (bl[i] == null)
  5449. continue;
  5450. if (bl[i].BannedUserID == UUID.Zero)
  5451. continue;
  5452. BannedUsers.Add(bl[i].BannedUserID);
  5453. }
  5454. SendEstateList(invoice, 4, BannedUsers.ToArray(), estateID);
  5455. }
  5456. public void SendRegionInfoToEstateMenu(RegionInfoForEstateMenuArgs args)
  5457. {
  5458. RegionInfoPacket rinfopack = new RegionInfoPacket();
  5459. RegionInfoPacket.RegionInfoBlock rinfoblk = new RegionInfoPacket.RegionInfoBlock();
  5460. rinfopack.AgentData.AgentID = AgentId;
  5461. rinfopack.AgentData.SessionID = SessionId;
  5462. rinfoblk.BillableFactor = args.billableFactor;
  5463. rinfoblk.EstateID = args.estateID;
  5464. rinfoblk.MaxAgents = (byte)args.maxAgents;
  5465. rinfoblk.ObjectBonusFactor = args.objectBonusFactor;
  5466. rinfoblk.ParentEstateID = args.parentEstateID;
  5467. rinfoblk.PricePerMeter = args.pricePerMeter;
  5468. rinfoblk.RedirectGridX = args.redirectGridX;
  5469. rinfoblk.RedirectGridY = args.redirectGridY;
  5470. rinfoblk.RegionFlags = args.regionFlags;
  5471. rinfoblk.SimAccess = args.simAccess;
  5472. rinfoblk.SunHour = args.sunHour;
  5473. rinfoblk.TerrainLowerLimit = args.terrainLowerLimit;
  5474. rinfoblk.TerrainRaiseLimit = args.terrainRaiseLimit;
  5475. rinfoblk.UseEstateSun = args.useEstateSun;
  5476. rinfoblk.WaterHeight = args.waterHeight;
  5477. rinfoblk.SimName = Utils.StringToBytes(args.simName);
  5478. rinfopack.RegionInfo2 = new RegionInfoPacket.RegionInfo2Block();
  5479. rinfopack.RegionInfo2.HardMaxAgents = (uint)args.AgentCapacity;
  5480. rinfopack.RegionInfo2.HardMaxObjects = (uint)args.ObjectsCapacity;
  5481. rinfopack.RegionInfo2.MaxAgents32 = (uint)args.maxAgents;
  5482. rinfopack.RegionInfo2.ProductName = Util.StringToBytes256(args.regionType);
  5483. rinfopack.RegionInfo2.ProductSKU = Utils.EmptyBytes;
  5484. rinfopack.HasVariableBlocks = true;
  5485. rinfopack.RegionInfo = rinfoblk;
  5486. rinfopack.AgentData = new RegionInfoPacket.AgentDataBlock();
  5487. rinfopack.AgentData.AgentID = AgentId;
  5488. rinfopack.AgentData.SessionID = SessionId;
  5489. rinfopack.RegionInfo3 = new RegionInfoPacket.RegionInfo3Block[0];
  5490. OutPacket(rinfopack, ThrottleOutPacketType.Task);
  5491. }
  5492. public void SendEstateCovenantInformation(UUID covenant)
  5493. {
  5494. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending estate covenant asset id of {0} to {1}", covenant, Name);
  5495. EstateCovenantReplyPacket einfopack = new EstateCovenantReplyPacket();
  5496. EstateCovenantReplyPacket.DataBlock edata = new EstateCovenantReplyPacket.DataBlock();
  5497. edata.CovenantID = covenant;
  5498. edata.CovenantTimestamp = (uint) m_scene.RegionInfo.RegionSettings.CovenantChangedDateTime;
  5499. edata.EstateOwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  5500. edata.EstateName = Utils.StringToBytes(m_scene.RegionInfo.EstateSettings.EstateName);
  5501. einfopack.Data = edata;
  5502. OutPacket(einfopack, ThrottleOutPacketType.Task);
  5503. }
  5504. public void SendDetailedEstateData(
  5505. UUID invoice, string estateName, uint estateID, uint parentEstate, uint estateFlags, uint sunPosition,
  5506. UUID covenant, uint covenantChanged, string abuseEmail, UUID estateOwner)
  5507. {
  5508. // m_log.DebugFormat(
  5509. // "[LLCLIENTVIEW]: Sending detailed estate data to {0} with covenant asset id {1}", Name, covenant);
  5510. EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
  5511. packet.MethodData.Invoice = invoice;
  5512. packet.AgentData.TransactionID = UUID.Random();
  5513. packet.MethodData.Method = Utils.StringToBytes("estateupdateinfo");
  5514. EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[10];
  5515. for (int i = 0; i < 10; i++)
  5516. {
  5517. returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
  5518. }
  5519. //Sending Estate Settings
  5520. returnblock[0].Parameter = Utils.StringToBytes(estateName);
  5521. returnblock[1].Parameter = Utils.StringToBytes(estateOwner.ToString());
  5522. returnblock[2].Parameter = Utils.StringToBytes(estateID.ToString());
  5523. returnblock[3].Parameter = Utils.StringToBytes(estateFlags.ToString());
  5524. returnblock[4].Parameter = Utils.StringToBytes(sunPosition.ToString());
  5525. returnblock[5].Parameter = Utils.StringToBytes(parentEstate.ToString());
  5526. returnblock[6].Parameter = Utils.StringToBytes(covenant.ToString());
  5527. returnblock[7].Parameter = Utils.StringToBytes(covenantChanged.ToString());
  5528. returnblock[8].Parameter = Utils.StringToBytes("1"); // what is this?
  5529. returnblock[9].Parameter = Utils.StringToBytes(abuseEmail);
  5530. packet.ParamList = returnblock;
  5531. //m_log.Debug("[ESTATE]: SIM--->" + packet.ToString());
  5532. OutPacket(packet, ThrottleOutPacketType.Task);
  5533. }
  5534. public void SendTelehubInfo(UUID ObjectID, string ObjectName, Vector3 ObjectPos, Quaternion ObjectRot, List<Vector3> SpawnPoint)
  5535. {
  5536. TelehubInfoPacket packet = (TelehubInfoPacket)PacketPool.Instance.GetPacket(PacketType.TelehubInfo);
  5537. packet.TelehubBlock.ObjectID = ObjectID;
  5538. packet.TelehubBlock.ObjectName = Utils.StringToBytes(ObjectName);
  5539. packet.TelehubBlock.TelehubPos = ObjectPos;
  5540. packet.TelehubBlock.TelehubRot = ObjectRot;
  5541. packet.SpawnPointBlock = new TelehubInfoPacket.SpawnPointBlockBlock[SpawnPoint.Count];
  5542. for (int n = 0; n < SpawnPoint.Count; n++)
  5543. {
  5544. packet.SpawnPointBlock[n] = new TelehubInfoPacket.SpawnPointBlockBlock{SpawnPointPos = SpawnPoint[n]};
  5545. }
  5546. OutPacket(packet, ThrottleOutPacketType.Task);
  5547. }
  5548. #endregion
  5549. #region Land Data Sending Methods
  5550. public void SendLandParcelOverlay(byte[] data, int sequence_id)
  5551. {
  5552. ParcelOverlayPacket packet = (ParcelOverlayPacket)PacketPool.Instance.GetPacket(PacketType.ParcelOverlay);
  5553. packet.ParcelData.Data = data;
  5554. packet.ParcelData.SequenceID = sequence_id;
  5555. // OutPacket(packet, ThrottleOutPacketType.Task);
  5556. OutPacket(packet, ThrottleOutPacketType.Land);
  5557. }
  5558. public void SendLandProperties(
  5559. int sequence_id, bool snap_selection, int request_result, ILandObject lo,
  5560. float simObjectBonusFactor, int parcelObjectCapacity, int simObjectCapacity, uint regionFlags)
  5561. {
  5562. // m_log.DebugFormat("[LLCLIENTVIEW]: Sending land properties for {0} to {1}", lo.LandData.GlobalID, Name);
  5563. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  5564. if (eq == null)
  5565. {
  5566. m_log.Warn("[LLCLIENTVIEW]: No EQ Interface when sending parcel data.");
  5567. return;
  5568. }
  5569. LandData landData = lo.LandData;
  5570. IPrimCounts pc = lo.PrimCounts;
  5571. int cap = 4 * landData.Bitmap.Length / 3 + 2048;
  5572. osUTF8 sb = eq.StartEvent("ParcelProperties", cap);
  5573. LLSDxmlEncode2.AddArrayAndMap("ParcelData", sb);
  5574. LLSDxmlEncode2.AddElem("LocalID", landData.LocalID, sb);
  5575. LLSDxmlEncode2.AddElem("AABBMax", landData.AABBMax, sb);
  5576. LLSDxmlEncode2.AddElem("AABBMin", landData.AABBMin, sb);
  5577. LLSDxmlEncode2.AddElem("Area", landData.Area, sb);
  5578. LLSDxmlEncode2.AddElem("AuctionID", (int)landData.AuctionID, sb);
  5579. LLSDxmlEncode2.AddElem("AuthBuyerID", landData.AuthBuyerID, sb);
  5580. LLSDxmlEncode2.AddElem("Bitmap", landData.Bitmap, sb);
  5581. LLSDxmlEncode2.AddElem("Category", (int)landData.Category, sb);
  5582. LLSDxmlEncode2.AddElem("ClaimDate", Util.ToDateTime(landData.ClaimDate), sb);
  5583. LLSDxmlEncode2.AddElem("ClaimPrice", landData.ClaimPrice, sb);
  5584. LLSDxmlEncode2.AddElem("Desc", landData.Description, sb);
  5585. LLSDxmlEncode2.AddElem("ParcelFlags", landData.Flags, sb);
  5586. LLSDxmlEncode2.AddElem("GroupID", landData.GroupID, sb);
  5587. LLSDxmlEncode2.AddElem("GroupPrims", pc.Group, sb);
  5588. LLSDxmlEncode2.AddElem("IsGroupOwned", landData.IsGroupOwned, sb);
  5589. LLSDxmlEncode2.AddElem("LandingType", (int)landData.LandingType, sb);
  5590. if (landData.Area > 0)
  5591. LLSDxmlEncode2.AddElem("MaxPrims", parcelObjectCapacity, sb);
  5592. else
  5593. LLSDxmlEncode2.AddElem("MaxPrims", (int)0, sb);
  5594. LLSDxmlEncode2.AddElem("MediaID", landData.MediaID, sb);
  5595. LLSDxmlEncode2.AddElem("MediaURL", landData.MediaURL, sb);
  5596. LLSDxmlEncode2.AddElem("MediaAutoScale", landData.MediaAutoScale != 0, sb);
  5597. LLSDxmlEncode2.AddElem("MusicURL", landData.MusicURL, sb);
  5598. LLSDxmlEncode2.AddElem("Name", landData.Name, sb);
  5599. LLSDxmlEncode2.AddElem("OtherCleanTime", landData.OtherCleanTime, sb);
  5600. LLSDxmlEncode2.AddElem("OtherCount", (int)0 , sb); //TODO
  5601. LLSDxmlEncode2.AddElem("OtherPrims", pc.Others, sb);
  5602. LLSDxmlEncode2.AddElem("OwnerID", landData.OwnerID, sb);
  5603. LLSDxmlEncode2.AddElem("OwnerPrims", pc.Owner, sb);
  5604. LLSDxmlEncode2.AddElem("ParcelPrimBonus", simObjectBonusFactor, sb);
  5605. LLSDxmlEncode2.AddElem("PassHours", landData.PassHours, sb);
  5606. LLSDxmlEncode2.AddElem("PassPrice", landData.PassPrice, sb);
  5607. LLSDxmlEncode2.AddElem("PublicCount", (int)0, sb); //TODO
  5608. LLSDxmlEncode2.AddElem("RegionDenyAnonymous", (regionFlags & (uint)RegionFlags.DenyAnonymous) != 0, sb);
  5609. LLSDxmlEncode2.AddElem("RegionDenyIdentified", false, sb);
  5610. LLSDxmlEncode2.AddElem("RegionDenyTransacted", false, sb);
  5611. LLSDxmlEncode2.AddElem("RegionPushOverride", (regionFlags & (uint)RegionFlags.RestrictPushObject) != 0, sb);
  5612. LLSDxmlEncode2.AddElem("RentPrice", (int) 0, sb);;
  5613. LLSDxmlEncode2.AddElem("RequestResult", request_result, sb);
  5614. LLSDxmlEncode2.AddElem("SalePrice", landData.SalePrice, sb);
  5615. LLSDxmlEncode2.AddElem("SelectedPrims", pc.Selected, sb);
  5616. LLSDxmlEncode2.AddElem("SelfCount", (int)0, sb); //TODO
  5617. LLSDxmlEncode2.AddElem("SequenceID", sequence_id, sb);
  5618. if (landData.SimwideArea > 0)
  5619. LLSDxmlEncode2.AddElem("SimWideMaxPrims", lo.GetSimulatorMaxPrimCount(), sb);
  5620. else
  5621. LLSDxmlEncode2.AddElem("SimWideMaxPrims", (int)0, sb);
  5622. LLSDxmlEncode2.AddElem("SimWideTotalPrims", pc.Simulator, sb);
  5623. LLSDxmlEncode2.AddElem("SnapSelection", snap_selection, sb);
  5624. LLSDxmlEncode2.AddElem("SnapshotID", landData.SnapshotID, sb);
  5625. LLSDxmlEncode2.AddElem("Status", (int)landData.Status, sb);
  5626. LLSDxmlEncode2.AddElem("TotalPrims", pc.Total, sb);
  5627. LLSDxmlEncode2.AddElem("UserLocation", landData.UserLocation, sb);
  5628. LLSDxmlEncode2.AddElem("UserLookAt", landData.UserLookAt, sb);
  5629. LLSDxmlEncode2.AddElem("SeeAVs", landData.SeeAVs, sb);
  5630. LLSDxmlEncode2.AddElem("AnyAVSounds", landData.AnyAVSounds, sb);
  5631. LLSDxmlEncode2.AddElem("GroupAVSounds", landData.GroupAVSounds, sb);
  5632. LLSDxmlEncode2.AddEndMapAndArray(sb);
  5633. LLSDxmlEncode2.AddArrayAndMap("MediaData", sb);
  5634. LLSDxmlEncode2.AddElem("MediaDesc", landData.MediaDescription, sb);
  5635. LLSDxmlEncode2.AddElem("MediaHeight", landData.MediaHeight, sb);
  5636. LLSDxmlEncode2.AddElem("MediaWidth", landData.MediaWidth, sb);
  5637. LLSDxmlEncode2.AddElem("MediaLoop", landData.MediaLoop, sb);
  5638. LLSDxmlEncode2.AddElem("MediaType", landData.MediaType, sb);
  5639. LLSDxmlEncode2.AddElem("ObscureMedia", landData.ObscureMedia, sb);
  5640. LLSDxmlEncode2.AddElem("ObscureMusic", landData.ObscureMusic, sb);
  5641. LLSDxmlEncode2.AddEndMapAndArray(sb);
  5642. LLSDxmlEncode2.AddArrayAndMap("AgeVerificationBlock", sb);
  5643. LLSDxmlEncode2.AddElem("RegionDenyAgeUnverified", (regionFlags & (uint)RegionFlags.DenyAgeUnverified) != 0, sb);
  5644. LLSDxmlEncode2.AddEndMapAndArray(sb);
  5645. bool allowenvovr = (regionFlags & (uint)RegionFlags.AllowEnvironmentOverride) != 0;
  5646. int envVersion;
  5647. if(allowenvovr)
  5648. {
  5649. ScenePresence sp = SceneAgent as ScenePresence;
  5650. if(sp != null && sp.EnvironmentVersion > 0)
  5651. envVersion = -1;
  5652. else
  5653. envVersion = landData.EnvironmentVersion;
  5654. }
  5655. else
  5656. envVersion = -1;
  5657. LLSDxmlEncode2.AddArrayAndMap("ParcelEnvironmentBlock", sb);
  5658. LLSDxmlEncode2.AddElem("ParcelEnvironmentVersion", envVersion, sb);
  5659. LLSDxmlEncode2.AddElem("RegionAllowEnvironmentOverride", allowenvovr, sb);
  5660. LLSDxmlEncode2.AddEndMapAndArray(sb);
  5661. bool accessovr = !Scene.RegionInfo.EstateSettings.TaxFree;
  5662. LLSDxmlEncode2.AddArrayAndMap("RegionAllowAccessBlock", sb);
  5663. LLSDxmlEncode2.AddElem("RegionAllowAccessOverride", accessovr, sb);
  5664. LLSDxmlEncode2.AddEndMapAndArray(sb);
  5665. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  5666. }
  5667. public void SendLandAccessListData(List<LandAccessEntry> accessList, uint accessFlag, int localLandID)
  5668. {
  5669. ParcelAccessListReplyPacket replyPacket = (ParcelAccessListReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelAccessListReply);
  5670. replyPacket.Data.AgentID = AgentId;
  5671. replyPacket.Data.Flags = accessFlag;
  5672. replyPacket.Data.LocalID = localLandID;
  5673. replyPacket.Data.SequenceID = 0;
  5674. List<ParcelAccessListReplyPacket.ListBlock> list = new List<ParcelAccessListReplyPacket.ListBlock>();
  5675. foreach (LandAccessEntry entry in accessList)
  5676. {
  5677. ParcelAccessListReplyPacket.ListBlock block = new ParcelAccessListReplyPacket.ListBlock();
  5678. block.Flags = accessFlag;
  5679. block.ID = entry.AgentID;
  5680. block.Time = entry.Expires;
  5681. list.Add(block);
  5682. }
  5683. replyPacket.List = list.ToArray();
  5684. replyPacket.Header.Zerocoded = true;
  5685. OutPacket(replyPacket, ThrottleOutPacketType.Task);
  5686. }
  5687. public void SendForceClientSelectObjects(List<uint> ObjectIDs)
  5688. {
  5689. // m_log.DebugFormat("[LLCLIENTVIEW] sending select with {0} objects", ObjectIDs.Count);
  5690. bool firstCall = true;
  5691. const int MAX_OBJECTS_PER_PACKET = 251;
  5692. ForceObjectSelectPacket pack = (ForceObjectSelectPacket)PacketPool.Instance.GetPacket(PacketType.ForceObjectSelect);
  5693. ForceObjectSelectPacket.DataBlock[] data;
  5694. while (ObjectIDs.Count > 0)
  5695. {
  5696. if (firstCall)
  5697. {
  5698. pack._Header.ResetList = true;
  5699. firstCall = false;
  5700. }
  5701. else
  5702. {
  5703. pack._Header.ResetList = false;
  5704. }
  5705. if (ObjectIDs.Count > MAX_OBJECTS_PER_PACKET)
  5706. {
  5707. data = new ForceObjectSelectPacket.DataBlock[MAX_OBJECTS_PER_PACKET];
  5708. }
  5709. else
  5710. {
  5711. data = new ForceObjectSelectPacket.DataBlock[ObjectIDs.Count];
  5712. }
  5713. int i;
  5714. for (i = 0; i < MAX_OBJECTS_PER_PACKET && ObjectIDs.Count > 0; i++)
  5715. {
  5716. data[i] = new ForceObjectSelectPacket.DataBlock();
  5717. data[i].LocalID = Convert.ToUInt32(ObjectIDs[0]);
  5718. ObjectIDs.RemoveAt(0);
  5719. }
  5720. pack.Data = data;
  5721. pack.Header.Zerocoded = true;
  5722. OutPacket(pack, ThrottleOutPacketType.Task);
  5723. }
  5724. }
  5725. public void SendCameraConstraint(Vector4 ConstraintPlane)
  5726. {
  5727. CameraConstraintPacket cpack = (CameraConstraintPacket)PacketPool.Instance.GetPacket(PacketType.CameraConstraint);
  5728. cpack.CameraCollidePlane = new CameraConstraintPacket.CameraCollidePlaneBlock();
  5729. cpack.CameraCollidePlane.Plane = ConstraintPlane;
  5730. //m_log.DebugFormat("[CLIENTVIEW]: Constraint {0}", ConstraintPlane);
  5731. OutPacket(cpack, ThrottleOutPacketType.Task);
  5732. }
  5733. public void SendLandObjectOwners(LandData land, List<UUID> groups, Dictionary<UUID, int> ownersAndCount)
  5734. {
  5735. int notifyCount = ownersAndCount.Count;
  5736. ParcelObjectOwnersReplyPacket pack = (ParcelObjectOwnersReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelObjectOwnersReply);
  5737. if (notifyCount > 0)
  5738. {
  5739. // if (notifyCount > 32)
  5740. // {
  5741. // m_log.InfoFormat(
  5742. // "[LAND]: More than {0} avatars own prims on this parcel. Only sending back details of first {0}"
  5743. // + " - a developer might want to investigate whether this is a hard limit", 32);
  5744. //
  5745. // notifyCount = 32;
  5746. // }
  5747. ParcelObjectOwnersReplyPacket.DataBlock[] dataBlock
  5748. = new ParcelObjectOwnersReplyPacket.DataBlock[notifyCount];
  5749. int num = 0;
  5750. foreach (UUID owner in ownersAndCount.Keys)
  5751. {
  5752. dataBlock[num] = new ParcelObjectOwnersReplyPacket.DataBlock();
  5753. dataBlock[num].Count = ownersAndCount[owner];
  5754. if (land.GroupID == owner || groups.Contains(owner))
  5755. dataBlock[num].IsGroupOwned = true;
  5756. dataBlock[num].OnlineStatus = true; //TODO: fix me later
  5757. dataBlock[num].OwnerID = owner;
  5758. num++;
  5759. if (num >= notifyCount)
  5760. {
  5761. break;
  5762. }
  5763. }
  5764. pack.Data = dataBlock;
  5765. }
  5766. else
  5767. {
  5768. pack.Data = new ParcelObjectOwnersReplyPacket.DataBlock[0];
  5769. }
  5770. pack.Header.Zerocoded = true;
  5771. this.OutPacket(pack, ThrottleOutPacketType.Task);
  5772. }
  5773. #endregion
  5774. #region Helper Methods
  5775. private void ClampVectorForUint(ref Vector3 v, float max)
  5776. {
  5777. float a,b;
  5778. a = Math.Abs(v.X);
  5779. b = Math.Abs(v.Y);
  5780. if(b > a)
  5781. a = b;
  5782. b= Math.Abs(v.Z);
  5783. if(b > a)
  5784. a = b;
  5785. if (a > max)
  5786. {
  5787. a = max / a;
  5788. v.X *= a;
  5789. v.Y *= a;
  5790. v.Z *= a;
  5791. }
  5792. }
  5793. protected void CreateImprovedTerseBlock(ISceneEntity entity, byte[] data, ref int pos, bool includeTexture)
  5794. {
  5795. #region ScenePresence/SOP Handling
  5796. bool avatar = (entity is ScenePresence);
  5797. uint localID = entity.LocalId;
  5798. uint attachPoint;
  5799. Vector4 collisionPlane;
  5800. Vector3 position, velocity, acceleration, angularVelocity;
  5801. Quaternion rotation;
  5802. byte datasize;
  5803. byte[] te = null;
  5804. if (avatar)
  5805. {
  5806. ScenePresence presence = (ScenePresence)entity;
  5807. position = presence.OffsetPosition;
  5808. velocity = presence.Velocity;
  5809. acceleration = Vector3.Zero;
  5810. rotation = presence.Rotation;
  5811. // tpvs can only see rotations around Z in some cases
  5812. if (!presence.Flying && !presence.IsSatOnObject)
  5813. {
  5814. rotation.X = 0f;
  5815. rotation.Y = 0f;
  5816. }
  5817. rotation.Normalize();
  5818. angularVelocity = presence.AngularVelocity;
  5819. // m_log.DebugFormat(
  5820. // "[LLCLIENTVIEW]: Sending terse update to {0} with position {1} in {2}", Name, presence.OffsetPosition, m_scene.Name);
  5821. attachPoint = presence.State;
  5822. collisionPlane = presence.CollisionPlane;
  5823. datasize = 60;
  5824. }
  5825. else
  5826. {
  5827. SceneObjectPart part = (SceneObjectPart)entity;
  5828. attachPoint = part.ParentGroup.AttachmentPoint;
  5829. attachPoint = ((attachPoint % 16) * 16 + (attachPoint / 16));
  5830. // m_log.DebugFormat(
  5831. // "[LLCLIENTVIEW]: Sending attachPoint {0} for {1} {2} to {3}",
  5832. // attachPoint, part.Name, part.LocalId, Name);
  5833. collisionPlane = Vector4.Zero;
  5834. position = part.RelativePosition;
  5835. velocity = part.Velocity;
  5836. acceleration = part.Acceleration;
  5837. angularVelocity = part.AngularVelocity;
  5838. rotation = part.RotationOffset;
  5839. datasize = 44;
  5840. if(includeTexture)
  5841. te = part.Shape.TextureEntry;
  5842. }
  5843. #endregion ScenePresence/SOP Handling
  5844. //object block size
  5845. data[pos++] = datasize;
  5846. // LocalID
  5847. Utils.UIntToBytes(localID, data, pos);
  5848. pos += 4;
  5849. data[pos++] = (byte)attachPoint;
  5850. // Avatar/CollisionPlane
  5851. if (avatar)
  5852. {
  5853. data[pos++] = 1;
  5854. if (collisionPlane == Vector4.Zero)
  5855. collisionPlane = Vector4.UnitW;
  5856. //m_log.DebugFormat("CollisionPlane: {0}",collisionPlane);
  5857. collisionPlane.ToBytes(data, pos);
  5858. pos += 16;
  5859. }
  5860. else
  5861. {
  5862. data[pos++] = 0;
  5863. }
  5864. // Position
  5865. position.ToBytes(data, pos);
  5866. pos += 12;
  5867. // Velocity
  5868. ClampVectorForUint(ref velocity, 128f);
  5869. Utils.FloatToUInt16Bytes(velocity.X, 128.0f, data, pos); pos += 2;
  5870. Utils.FloatToUInt16Bytes(velocity.Y, 128.0f, data, pos); pos += 2;
  5871. Utils.FloatToUInt16Bytes(velocity.Z, 128.0f, data, pos); pos += 2;
  5872. // Acceleration
  5873. ClampVectorForUint(ref acceleration, 64f);
  5874. Utils.FloatToUInt16Bytes(acceleration.X, 64.0f, data, pos); pos += 2;
  5875. Utils.FloatToUInt16Bytes(acceleration.Y, 64.0f, data, pos); pos += 2;
  5876. Utils.FloatToUInt16Bytes(acceleration.Z, 64.0f, data, pos); pos += 2;
  5877. // Rotation
  5878. Utils.FloatToUInt16Bytes(rotation.X, 1.0f, data, pos); pos += 2;
  5879. Utils.FloatToUInt16Bytes(rotation.Y, 1.0f, data, pos); pos += 2;
  5880. Utils.FloatToUInt16Bytes(rotation.Z, 1.0f, data, pos); pos += 2;
  5881. Utils.FloatToUInt16Bytes(rotation.W, 1.0f, data, pos); pos += 2;
  5882. // Angular Velocity
  5883. ClampVectorForUint(ref angularVelocity, 64f);
  5884. Utils.FloatToUInt16Bytes(angularVelocity.X, 64.0f, data, pos); pos += 2;
  5885. Utils.FloatToUInt16Bytes(angularVelocity.Y, 64.0f, data, pos); pos += 2;
  5886. Utils.FloatToUInt16Bytes(angularVelocity.Z, 64.0f, data, pos); pos += 2;
  5887. // texture entry block size
  5888. if(te == null)
  5889. {
  5890. data[pos++] = 0;
  5891. data[pos++] = 0;
  5892. }
  5893. else
  5894. {
  5895. int len = te.Length & 0x7fff;
  5896. int totlen = len + 4;
  5897. data[pos++] = (byte)totlen;
  5898. data[pos++] = (byte)(totlen >> 8);
  5899. data[pos++] = (byte)len; // wtf ???
  5900. data[pos++] = (byte)(len >> 8);
  5901. data[pos++] = 0;
  5902. data[pos++] = 0;
  5903. Buffer.BlockCopy(te, 0, data, pos, len);
  5904. pos += len;
  5905. }
  5906. // total size 63 or 47 + (texture size + 4)
  5907. }
  5908. protected void CreateAvatarUpdateBlock(ScenePresence data, byte[] dest, ref int pos)
  5909. {
  5910. Quaternion rotation = data.Rotation;
  5911. // tpvs can only see rotations around Z in some cases
  5912. if (!data.Flying && !data.IsSatOnObject)
  5913. {
  5914. rotation.X = 0f;
  5915. rotation.Y = 0f;
  5916. }
  5917. rotation.Normalize();
  5918. //Vector3 velocity = Vector3.Zero;
  5919. //Vector3 acceleration = Vector3.Zero;
  5920. //Vector3 angularvelocity = Vector3.Zero;
  5921. Utils.UIntToBytesSafepos(data.LocalId, dest, pos); pos += 4;
  5922. dest[pos++] = 0; // state
  5923. data.UUID.ToBytes(dest, pos); pos += 16;
  5924. Utils.UIntToBytesSafepos(0 , dest, pos); pos += 4; // crc
  5925. dest[pos++] = (byte)PCode.Avatar;
  5926. dest[pos++] = (byte)Material.Flesh;
  5927. dest[pos++] = 0; // clickaction
  5928. data.Appearance.AvatarSize.ToBytes(dest, pos); pos += 12;
  5929. // objectdata block
  5930. dest[pos++] = 76;
  5931. data.CollisionPlane.ToBytes(dest, pos); pos += 16;
  5932. data.OffsetPosition.ToBytes(dest, pos); pos += 12;
  5933. data.Velocity.ToBytes(dest, pos); pos += 12;
  5934. //acceleration.ToBytes(dest, pos); pos += 12;
  5935. Array.Clear(dest, pos, 12); pos += 12;
  5936. rotation.ToBytes(dest, pos); pos += 12;
  5937. //angularvelocity.ToBytes(dest, pos); pos += 12;
  5938. Array.Clear(dest, pos, 12); pos += 12;
  5939. SceneObjectPart parentPart = data.ParentPart;
  5940. if (parentPart != null)
  5941. {
  5942. Utils.UIntToBytesSafepos(parentPart.ParentGroup.LocalId, dest, pos);
  5943. pos += 4;
  5944. }
  5945. else
  5946. {
  5947. // Utils.UIntToBytesSafepos(0, dest, pos);
  5948. // pos += 4;
  5949. dest[pos++] = 0;
  5950. dest[pos++] = 0;
  5951. dest[pos++] = 0;
  5952. dest[pos++] = 0;
  5953. }
  5954. //Utils.UIntToBytesSafepos(0, dest, pos); pos += 4; //update flags
  5955. dest[pos++] = 0;
  5956. dest[pos++] = 0;
  5957. dest[pos++] = 0;
  5958. dest[pos++] = 0;
  5959. //pbs
  5960. dest[pos++] = 16;
  5961. dest[pos++] = 1;
  5962. //Utils.UInt16ToBytes(0, dest, pos); pos += 2;
  5963. //Utils.UInt16ToBytes(0, dest, pos); pos += 2;
  5964. dest[pos++] = 0;
  5965. dest[pos++] = 0;
  5966. dest[pos++] = 0;
  5967. dest[pos++] = 0;
  5968. dest[pos++] = 100;
  5969. dest[pos++] = 100;
  5970. // rest of pbs is 0 (15), texture entry (2) and texture anim (1)
  5971. const int pbszeros = 15 + 2 + 1;
  5972. Array.Clear(dest, pos, pbszeros); pos += pbszeros;
  5973. //NameValue
  5974. byte[] nv = Utils.StringToBytes("FirstName STRING RW SV " + data.Firstname + "\nLastName STRING RW SV " +
  5975. data.Lastname + "\nTitle STRING RW SV " + data.Grouptitle);
  5976. int len = nv.Length;
  5977. dest[pos++] = (byte)len;
  5978. dest[pos++] = (byte)(len >> 8);
  5979. Buffer.BlockCopy(nv, 0, dest, pos, len); pos += len;
  5980. // data(2), text(1), text color(4), media url(1), PBblock(1), ExtramParams(1),
  5981. // sound id(16), sound owner(16) gain (4), flags (1), radius (4)
  5982. // jointtype(1) joint pivot(12) joint offset(12)
  5983. const int lastzeros = 2 + 1 + 4 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12;
  5984. Array.Clear(dest, pos, lastzeros); pos += lastzeros;
  5985. }
  5986. protected void CreateAvatarUpdateBlock(ScenePresence data, LLUDPZeroEncoder zc)
  5987. {
  5988. Quaternion rotation = data.Rotation;
  5989. // tpvs can only see rotations around Z in some cases
  5990. if (!data.Flying && !data.IsSatOnObject)
  5991. {
  5992. rotation.X = 0f;
  5993. rotation.Y = 0f;
  5994. }
  5995. rotation.Normalize();
  5996. zc.AddUInt(data.LocalId);
  5997. zc.AddByte(0);
  5998. zc.AddUUID(data.UUID);
  5999. zc.AddZeros(4); // crc unused
  6000. zc.AddByte((byte)PCode.Avatar);
  6001. zc.AddByte((byte)Material.Flesh);
  6002. zc.AddByte(0); // clickaction
  6003. zc.AddVector3(data.Appearance.AvatarSize);
  6004. // objectdata block
  6005. zc.AddByte(76); // fixed avatar block size
  6006. zc.AddVector4(data.CollisionPlane);
  6007. zc.AddVector3(data.OffsetPosition);
  6008. zc.AddVector3(data.Velocity);
  6009. //zc.AddVector3(acceleration);
  6010. zc.AddZeros(12);
  6011. zc.AddNormQuat(rotation);
  6012. //zc.AddVector3(angularvelocity);
  6013. zc.AddZeros(12);
  6014. SceneObjectPart parentPart = data.ParentPart;
  6015. if (parentPart != null)
  6016. zc.AddUInt(parentPart.ParentGroup.LocalId);
  6017. else
  6018. zc.AddZeros(4);
  6019. zc.AddZeros(4); //update flags
  6020. //pbs volume data 23
  6021. //texture entry 2
  6022. //texture anim (1)
  6023. const int pbszeros = 23 + 2 + 1;
  6024. zc.AddZeros(pbszeros);
  6025. //NameValue
  6026. byte[] nv = Utils.StringToBytes("FirstName STRING RW SV " + data.Firstname + "\nLastName STRING RW SV " +
  6027. data.Lastname + "\nTitle STRING RW SV " + data.Grouptitle);
  6028. int len = nv.Length;
  6029. zc.AddByte((byte)len);
  6030. zc.AddByte((byte)(len >> 8));
  6031. zc.AddBytes(nv, len);
  6032. // data(2), text(1), text color(4), media url(1), PBblock(1), ExtramParams(1),
  6033. // sound id(16), sound owner(16) gain (4), flags (1), radius (4)
  6034. // jointtype(1) joint pivot(12) joint offset(12)
  6035. const int lastzeros = 2 + 1 + 4 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12;
  6036. zc.AddZeros(lastzeros);
  6037. }
  6038. protected void CreatePrimUpdateBlock(SceneObjectPart part, ScenePresence sp, LLUDPZeroEncoder zc)
  6039. {
  6040. // prepare data
  6041. #region PrimFlags
  6042. // prim/update flags
  6043. PrimFlags primflags = (PrimFlags)m_scene.Permissions.GenerateClientFlags(part, sp);
  6044. // Don't send the CreateSelected flag to everyone
  6045. primflags &= ~PrimFlags.CreateSelected;
  6046. if (sp.UUID == part.OwnerID)
  6047. {
  6048. if (part.CreateSelected)
  6049. {
  6050. // Only send this flag once, then unset it
  6051. primflags |= PrimFlags.CreateSelected;
  6052. part.CreateSelected = false;
  6053. }
  6054. }
  6055. #endregion PrimFlags
  6056. // data block
  6057. byte[] data = null;
  6058. byte state = part.Shape.State;
  6059. PCode pcode = (PCode)part.Shape.PCode;
  6060. //vegetation is special so just do it inline
  6061. if(pcode == PCode.Grass || pcode == PCode.Tree || pcode == PCode.NewTree)
  6062. {
  6063. zc.AddUInt(part.LocalId);
  6064. zc.AddByte(state); // state
  6065. zc.AddUUID(part.UUID);
  6066. zc.AddUInt((uint)part.PseudoCRC);
  6067. zc.AddByte((byte)pcode);
  6068. // material 1
  6069. // clickaction 1
  6070. zc.AddZeros(2);
  6071. zc.AddVector3(part.Shape.Scale);
  6072. // objectdata block
  6073. zc.AddByte(60); // fixed object block size
  6074. zc.AddVector3(part.RelativePosition);
  6075. if (pcode == PCode.Grass)
  6076. zc.AddZeros(48);
  6077. else
  6078. {
  6079. zc.AddZeros(24);
  6080. Quaternion rot = part.RotationOffset;
  6081. rot.Normalize();
  6082. zc.AddNormQuat(rot);
  6083. zc.AddZeros(12);
  6084. }
  6085. zc.AddUInt(part.ParentID);
  6086. zc.AddUInt((uint)primflags); //update flags
  6087. /*
  6088. if (pcode == PCode.Grass)
  6089. {
  6090. //pbs volume data 23
  6091. //texture entry 2
  6092. //texture anim 1
  6093. //name value 2
  6094. // data 1
  6095. // text 5
  6096. // media url 1
  6097. // particle system 1
  6098. // Extraparams 1
  6099. // sound id 16
  6100. // ownwer 16
  6101. // sound gain 4
  6102. // sound flags 1
  6103. // sound radius 4
  6104. // jointtype 1
  6105. // joint pivot 12
  6106. // joint offset 12
  6107. zc.AddZeros(23 + 2 + 1 + 2 + 1 + 5 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12);
  6108. return;
  6109. }
  6110. */
  6111. //pbs volume data 23
  6112. //texture entry 2
  6113. //texture anim 1
  6114. //name value 2
  6115. zc.AddZeros(23 + 2 + 1 + 2);
  6116. //data: the tree type
  6117. zc.AddByte(1);
  6118. zc.AddZeros(1);
  6119. zc.AddByte(state);
  6120. // text 5
  6121. // media url 1
  6122. // particle system 1
  6123. // Extraparams 1
  6124. // sound id 16
  6125. // ownwer 16
  6126. // sound gain 4
  6127. // sound flags 1
  6128. // sound radius 4
  6129. // jointtype 1
  6130. // joint pivot 12
  6131. // joint offset 12
  6132. zc.AddZeros(5 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12);
  6133. return;
  6134. }
  6135. //NameValue and state
  6136. byte[] nv = null;
  6137. if (part.ParentGroup.IsAttachment)
  6138. {
  6139. if (part.IsRoot)
  6140. nv = Util.StringToBytes256("AttachItemID STRING RW SV " + part.ParentGroup.FromItemID);
  6141. int st = (int)part.ParentGroup.AttachmentPoint;
  6142. state = (byte)(((st & 0xf0) >> 4) + ((st & 0x0f) << 4)); ;
  6143. }
  6144. // filter out mesh faces hack
  6145. ushort profileBegin = part.Shape.ProfileBegin;
  6146. ushort profileHollow = part.Shape.ProfileHollow;
  6147. byte profileCurve = part.Shape.ProfileCurve;
  6148. byte pathScaleY = part.Shape.PathScaleY;
  6149. if (part.Shape.SculptType == (byte)SculptType.Mesh) // filter out hack
  6150. {
  6151. profileCurve = (byte)(part.Shape.ProfileCurve & 0x0f);
  6152. // fix old values that confused viewers
  6153. if (profileBegin == 1)
  6154. profileBegin = 9375;
  6155. if (profileHollow == 1)
  6156. profileHollow = 27500;
  6157. // fix torus hole size Y that also confuse some viewers
  6158. if (profileCurve == (byte)ProfileShape.Circle && pathScaleY < 150)
  6159. pathScaleY = 150;
  6160. }
  6161. // do encode the things
  6162. zc.AddUInt(part.LocalId);
  6163. zc.AddByte(state); // state
  6164. zc.AddUUID(part.UUID);
  6165. zc.AddUInt((uint)part.PseudoCRC);
  6166. zc.AddByte((byte)pcode);
  6167. zc.AddByte(part.Material);
  6168. zc.AddByte(part.ClickAction); // clickaction
  6169. zc.AddVector3(part.Shape.Scale);
  6170. // objectdata block
  6171. zc.AddByte(60); // fixed object block size
  6172. zc.AddVector3(part.RelativePosition);
  6173. zc.AddVector3(part.Velocity);
  6174. zc.AddVector3(part.Acceleration);
  6175. Quaternion rotation = part.RotationOffset;
  6176. rotation.Normalize();
  6177. zc.AddNormQuat(rotation);
  6178. zc.AddVector3(part.AngularVelocity);
  6179. zc.AddUInt(part.ParentID);
  6180. zc.AddUInt((uint)primflags); //update flags
  6181. //pbs
  6182. zc.AddByte(part.Shape.PathCurve);
  6183. zc.AddByte(profileCurve);
  6184. zc.AddUInt16(part.Shape.PathBegin);
  6185. zc.AddUInt16(part.Shape.PathEnd);
  6186. zc.AddByte(part.Shape.PathScaleX);
  6187. zc.AddByte(pathScaleY);
  6188. zc.AddByte(part.Shape.PathShearX);
  6189. zc.AddByte(part.Shape.PathShearY);
  6190. zc.AddByte((byte)part.Shape.PathTwist);
  6191. zc.AddByte((byte)part.Shape.PathTwistBegin);
  6192. zc.AddByte((byte)part.Shape.PathRadiusOffset);
  6193. zc.AddByte((byte)part.Shape.PathTaperX);
  6194. zc.AddByte((byte)part.Shape.PathTaperY);
  6195. zc.AddByte(part.Shape.PathRevolutions);
  6196. zc.AddByte((byte)part.Shape.PathSkew);
  6197. zc.AddUInt16(profileBegin);
  6198. zc.AddUInt16(part.Shape.ProfileEnd);
  6199. zc.AddUInt16(profileHollow);
  6200. // texture
  6201. byte[] tentry = part.Shape.TextureEntry;
  6202. if (tentry == null)
  6203. zc.AddZeros(2);
  6204. else
  6205. {
  6206. int len = tentry.Length;
  6207. zc.AddByte((byte)len);
  6208. zc.AddByte((byte)(len >> 8));
  6209. zc.AddBytes(tentry, len);
  6210. }
  6211. // texture animation
  6212. byte[] tanim = part.TextureAnimation;
  6213. if (tanim == null)
  6214. zc.AddZeros(1);
  6215. else
  6216. {
  6217. int len = tanim.Length;
  6218. zc.AddByte((byte)len);
  6219. zc.AddBytes(tanim, len);
  6220. }
  6221. //NameValue
  6222. if(nv == null)
  6223. zc.AddZeros(2);
  6224. else
  6225. {
  6226. int len = nv.Length;
  6227. zc.AddByte((byte)len);
  6228. zc.AddByte((byte)(len >> 8));
  6229. zc.AddBytes(nv, len);
  6230. }
  6231. // data
  6232. if (data == null)
  6233. zc.AddZeros(2);
  6234. else
  6235. {
  6236. int len = data.Length;
  6237. zc.AddByte((byte)len);
  6238. zc.AddByte((byte)(len >> 8));
  6239. zc.AddBytes(data, len);
  6240. }
  6241. //text
  6242. osUTF8 osUTF8PartText = part.osUTF8Text;
  6243. if (osUTF8PartText == null || osUTF8PartText.Length == 0)
  6244. zc.AddZeros(5);
  6245. else
  6246. {
  6247. zc.AddShortLimitedUTF8(osUTF8PartText);
  6248. //textcolor
  6249. byte[] tc = part.GetTextColor().GetBytes(false);
  6250. zc.AddBytes(tc, 4);
  6251. }
  6252. //media url
  6253. zc.AddShortLimitedUTF8(part.osUTFMediaUrl);
  6254. bool hasps = false;
  6255. //particle system
  6256. byte[] ps = part.ParticleSystem;
  6257. if (ps == null || ps.Length < 1)
  6258. zc.AddZeros(1);
  6259. else
  6260. {
  6261. int len = ps.Length;
  6262. zc.AddByte((byte)len);
  6263. zc.AddBytes(ps, len);
  6264. hasps = true;
  6265. }
  6266. //Extraparams
  6267. byte[] ep = part.Shape.ExtraParams;
  6268. if (ep == null || ep.Length < 2)
  6269. zc.AddZeros(1);
  6270. else
  6271. {
  6272. int len = ep.Length;
  6273. zc.AddByte((byte)len);
  6274. zc.AddBytes(ep, len);
  6275. }
  6276. bool hassound = part.Sound != UUID.Zero || part.SoundFlags != 0;
  6277. if (hassound)
  6278. zc.AddUUID(part.Sound);
  6279. else
  6280. zc.AddZeros(16);
  6281. if (hassound || hasps)
  6282. zc.AddUUID(part.OwnerID);
  6283. else
  6284. zc.AddZeros(16);
  6285. if (hassound)
  6286. {
  6287. zc.AddFloat((float)part.SoundGain);
  6288. zc.AddByte(part.SoundFlags);
  6289. zc.AddFloat((float)part.SoundRadius);
  6290. }
  6291. else
  6292. zc.AddZeros(9);
  6293. // jointtype(1) joint pivot(12) joint offset(12)
  6294. const int lastzeros = 1 + 12 + 12;
  6295. zc.AddZeros(lastzeros);
  6296. }
  6297. [Flags]
  6298. private enum CompressedFlags : uint
  6299. {
  6300. None = 0x00,
  6301. /// <summary>Unknown</summary>
  6302. ScratchPad = 0x01,
  6303. /// <summary>Whether the object has a TreeSpecies</summary>
  6304. Tree = 0x02,
  6305. /// <summary>Whether the object has floating text ala llSetText</summary>
  6306. HasText = 0x04,
  6307. /// <summary>Whether the object has an active particle system</summary>
  6308. HasParticlesLegacy = 0x08,
  6309. /// <summary>Whether the object has sound attached to it</summary>
  6310. HasSound = 0x10,
  6311. /// <summary>Whether the object is attached to a root object or not</summary>
  6312. HasParent = 0x20,
  6313. /// <summary>Whether the object has texture animation settings</summary>
  6314. TextureAnimation = 0x40,
  6315. /// <summary>Whether the object has an angular velocity</summary>
  6316. HasAngularVelocity = 0x80,
  6317. /// <summary>Whether the object has a name value pairs string</summary>
  6318. HasNameValues = 0x100,
  6319. /// <summary>Whether the object has a Media URL set</summary>
  6320. MediaURL = 0x200,
  6321. HasParticlesNew = 0x400
  6322. }
  6323. /*
  6324. protected void CreateCompressedUpdateBlock(SceneObjectPart part, ScenePresence sp, byte[] dest, ref int pos)
  6325. {
  6326. // prepare data
  6327. CompressedFlags cflags = CompressedFlags.None;
  6328. // prim/update flags
  6329. PrimFlags primflags = (PrimFlags)m_scene.Permissions.GenerateClientFlags(part, sp);
  6330. // Don't send the CreateSelected flag to everyone
  6331. primflags &= ~PrimFlags.CreateSelected;
  6332. if (sp.UUID == part.OwnerID)
  6333. {
  6334. if (part.CreateSelected)
  6335. {
  6336. // Only send this flag once, then unset it
  6337. primflags |= PrimFlags.CreateSelected;
  6338. part.CreateSelected = false;
  6339. }
  6340. }
  6341. byte state = part.Shape.State;
  6342. PCode pcode = (PCode)part.Shape.PCode;
  6343. bool hastree = false;
  6344. if (pcode == PCode.Grass || pcode == PCode.Tree || pcode == PCode.NewTree)
  6345. {
  6346. cflags |= CompressedFlags.Tree;
  6347. hastree = true;
  6348. }
  6349. //NameValue and state
  6350. byte[] nv = null;
  6351. if (part.ParentGroup.IsAttachment)
  6352. {
  6353. if (part.IsRoot)
  6354. nv = Util.StringToBytes256("AttachItemID STRING RW SV " + part.ParentGroup.FromItemID);
  6355. int st = (int)part.ParentGroup.AttachmentPoint;
  6356. state = (byte)(((st & 0xf0) >> 4) + ((st & 0x0f) << 4)); ;
  6357. }
  6358. bool hastext = part.Text != null && part.Text.Length > 0;
  6359. bool hassound = part.Sound != UUID.Zero || part.SoundFlags != 0;
  6360. bool hasps = part.ParticleSystem != null && part.ParticleSystem.Length > 1;
  6361. bool hastexanim = part.TextureAnimation != null && part.TextureAnimation.Length > 0;
  6362. bool hasangvel = part.AngularVelocity.LengthSquared() > 1e-8f;
  6363. bool hasmediaurl = part.MediaUrl != null && part.MediaUrl.Length > 1;
  6364. bool haspsnew = false;
  6365. if (hastext)
  6366. cflags |= CompressedFlags.HasText;
  6367. if (hasps)
  6368. {
  6369. if(part.ParticleSystem.Length > 86)
  6370. {
  6371. hasps= false;
  6372. cflags |= CompressedFlags.HasParticlesNew;
  6373. haspsnew = true;
  6374. }
  6375. else
  6376. cflags |= CompressedFlags.HasParticlesLegacy;
  6377. }
  6378. if (hassound)
  6379. cflags |= CompressedFlags.HasSound;
  6380. if (part.ParentID != 0)
  6381. cflags |= CompressedFlags.HasParent;
  6382. if (hastexanim)
  6383. cflags |= CompressedFlags.TextureAnimation;
  6384. if (hasangvel)
  6385. cflags |= CompressedFlags.HasAngularVelocity;
  6386. if (hasmediaurl)
  6387. cflags |= CompressedFlags.MediaURL;
  6388. if (nv != null)
  6389. cflags |= CompressedFlags.HasNameValues;
  6390. // filter out mesh faces hack
  6391. ushort profileBegin = part.Shape.ProfileBegin;
  6392. ushort profileHollow = part.Shape.ProfileHollow;
  6393. byte profileCurve = part.Shape.ProfileCurve;
  6394. byte pathScaleY = part.Shape.PathScaleY;
  6395. if (part.Shape.SculptType == (byte)SculptType.Mesh) // filter out hack
  6396. {
  6397. profileCurve = (byte)(part.Shape.ProfileCurve & 0x0f);
  6398. // fix old values that confused viewers
  6399. if (profileBegin == 1)
  6400. profileBegin = 9375;
  6401. if (profileHollow == 1)
  6402. profileHollow = 27500;
  6403. // fix torus hole size Y that also confuse some viewers
  6404. if (profileCurve == (byte)ProfileShape.Circle && pathScaleY < 150)
  6405. pathScaleY = 150;
  6406. }
  6407. // first is primFlags
  6408. Utils.UIntToBytesSafepos((uint)primflags, dest, pos); pos += 4;
  6409. // datablock len to fill later
  6410. int lenpos = pos;
  6411. pos += 2;
  6412. // data block
  6413. part.UUID.ToBytes(dest, pos); pos += 16;
  6414. Utils.UIntToBytesSafepos(part.LocalId, dest, pos); pos += 4;
  6415. dest[pos++] = (byte)pcode;
  6416. dest[pos++] = state;
  6417. Utils.UIntToBytesSafepos((uint)part.ParentGroup.PseudoCRC, dest, pos); pos += 4;
  6418. dest[pos++] = part.Material;
  6419. dest[pos++] = part.ClickAction;
  6420. part.Shape.Scale.ToBytes(dest, pos); pos += 12;
  6421. part.RelativePosition.ToBytes(dest, pos); pos += 12;
  6422. if(pcode == PCode.Grass)
  6423. Vector3.Zero.ToBytes(dest, pos);
  6424. else
  6425. {
  6426. Quaternion rotation = part.RotationOffset;
  6427. rotation.Normalize();
  6428. rotation.ToBytes(dest, pos);
  6429. }
  6430. pos += 12;
  6431. Utils.UIntToBytesSafepos((uint)cflags, dest, pos); pos += 4;
  6432. if (hasps || haspsnew || hassound)
  6433. part.OwnerID.ToBytes(dest, pos);
  6434. else
  6435. UUID.Zero.ToBytes(dest, pos);
  6436. pos += 16;
  6437. if (hasangvel)
  6438. {
  6439. part.AngularVelocity.ToBytes(dest, pos); pos += 12;
  6440. }
  6441. if (part.ParentID != 0)
  6442. {
  6443. Utils.UIntToBytesSafepos(part.ParentID, dest, pos); pos += 4;
  6444. }
  6445. if (hastree)
  6446. dest[pos++] = state;
  6447. if (hastext)
  6448. {
  6449. byte[] text = Util.StringToBytes256(part.Text); // must be null term
  6450. Buffer.BlockCopy(text, 0, dest, pos, text.Length); pos += text.Length;
  6451. byte[] tc = part.GetTextColor().GetBytes(false);
  6452. Buffer.BlockCopy(tc, 0, dest, pos, tc.Length); pos += tc.Length;
  6453. }
  6454. if (hasmediaurl)
  6455. {
  6456. byte[] mu = Util.StringToBytes256(part.MediaUrl); // must be null term
  6457. Buffer.BlockCopy(mu, 0, dest, pos, mu.Length); pos += mu.Length;
  6458. }
  6459. if (hasps)
  6460. {
  6461. byte[] ps = part.ParticleSystem;
  6462. Buffer.BlockCopy(ps, 0, dest, pos, ps.Length); pos += ps.Length;
  6463. }
  6464. byte[] ex = part.Shape.ExtraParams;
  6465. if (ex == null || ex.Length < 2)
  6466. dest[pos++] = 0;
  6467. else
  6468. {
  6469. Buffer.BlockCopy(ex, 0, dest, pos, ex.Length); pos += ex.Length;
  6470. }
  6471. if (hassound)
  6472. {
  6473. part.Sound.ToBytes(dest, pos); pos += 16;
  6474. Utils.FloatToBytesSafepos((float)part.SoundGain, dest, pos); pos += 4;
  6475. dest[pos++] = part.SoundFlags;
  6476. Utils.FloatToBytesSafepos((float)part.SoundRadius, dest, pos); pos += 4;
  6477. }
  6478. if (nv != null)
  6479. {
  6480. Buffer.BlockCopy(nv, 0, dest, pos, nv.Length); pos += nv.Length;
  6481. }
  6482. dest[pos++] = part.Shape.PathCurve;
  6483. Utils.UInt16ToBytes(part.Shape.PathBegin, dest, pos); pos += 2;
  6484. Utils.UInt16ToBytes(part.Shape.PathEnd, dest, pos); pos += 2;
  6485. dest[pos++] = part.Shape.PathScaleX;
  6486. dest[pos++] = pathScaleY;
  6487. dest[pos++] = part.Shape.PathShearX;
  6488. dest[pos++] = part.Shape.PathShearY;
  6489. dest[pos++] = (byte)part.Shape.PathTwist;
  6490. dest[pos++] = (byte)part.Shape.PathTwistBegin;
  6491. dest[pos++] = (byte)part.Shape.PathRadiusOffset;
  6492. dest[pos++] = (byte)part.Shape.PathTaperX;
  6493. dest[pos++] = (byte)part.Shape.PathTaperY;
  6494. dest[pos++] = part.Shape.PathRevolutions;
  6495. dest[pos++] = (byte)part.Shape.PathSkew;
  6496. dest[pos++] = profileCurve;
  6497. Utils.UInt16ToBytes(profileBegin, dest, pos); pos += 2;
  6498. Utils.UInt16ToBytes(part.Shape.ProfileEnd, dest, pos); pos += 2;
  6499. Utils.UInt16ToBytes(profileHollow, dest, pos); pos += 2;
  6500. byte[] te = part.Shape.TextureEntry;
  6501. if (te == null)
  6502. {
  6503. dest[pos++] = 0;
  6504. dest[pos++] = 0;
  6505. dest[pos++] = 0;
  6506. dest[pos++] = 0;
  6507. }
  6508. else
  6509. {
  6510. int len = te.Length & 0x7fff;
  6511. dest[pos++] = (byte)len;
  6512. dest[pos++] = (byte)(len >> 8);
  6513. dest[pos++] = 0;
  6514. dest[pos++] = 0;
  6515. Buffer.BlockCopy(te, 0, dest, pos, len);
  6516. pos += len;
  6517. }
  6518. if (hastexanim)
  6519. {
  6520. byte[] ta = part.TextureAnimation;
  6521. int len = ta.Length & 0x7fff;
  6522. dest[pos++] = (byte)len;
  6523. dest[pos++] = (byte)(len >> 8);
  6524. dest[pos++] = 0;
  6525. dest[pos++] = 0;
  6526. Buffer.BlockCopy(ta, 0, dest, pos, len);
  6527. pos += len;
  6528. }
  6529. if (haspsnew)
  6530. {
  6531. byte[] ps = part.ParticleSystem;
  6532. Buffer.BlockCopy(ps, 0, dest, pos, ps.Length); pos += ps.Length;
  6533. }
  6534. int totlen = pos - lenpos - 2;
  6535. dest[lenpos++] = (byte)totlen;
  6536. dest[lenpos++] = (byte)(totlen >> 8);
  6537. }
  6538. */
  6539. protected void CreateCompressedUpdateBlockZC(SceneObjectPart part, ScenePresence sp, LLUDPZeroEncoder zc)
  6540. {
  6541. // prepare data
  6542. CompressedFlags cflags = CompressedFlags.None;
  6543. // prim/update flags
  6544. PrimFlags primflags = (PrimFlags)m_scene.Permissions.GenerateClientFlags(part, sp);
  6545. // Don't send the CreateSelected flag to everyone
  6546. primflags &= ~PrimFlags.CreateSelected;
  6547. if (sp.UUID == part.OwnerID)
  6548. {
  6549. if (part.CreateSelected)
  6550. {
  6551. // Only send this flag once, then unset it
  6552. primflags |= PrimFlags.CreateSelected;
  6553. part.CreateSelected = false;
  6554. }
  6555. }
  6556. byte state = part.Shape.State;
  6557. PCode pcode = (PCode)part.Shape.PCode;
  6558. // trees and grass are a lot more compact
  6559. if (pcode == PCode.Grass || pcode == PCode.Tree || pcode == PCode.NewTree)
  6560. {
  6561. // first is primFlags
  6562. zc.AddUInt((uint)primflags);
  6563. // datablock len
  6564. zc.AddByte(113);
  6565. zc.AddZeros(1);
  6566. // data block
  6567. zc.AddUUID(part.UUID);
  6568. zc.AddUInt(part.LocalId);
  6569. zc.AddByte((byte)pcode);
  6570. zc.AddByte(state);
  6571. zc.AddUInt((uint)part.PseudoCRC);
  6572. zc.AddZeros(2); // material and click action
  6573. zc.AddVector3(part.Shape.Scale);
  6574. zc.AddVector3(part.RelativePosition);
  6575. if (pcode == PCode.Grass)
  6576. zc.AddZeros(12);
  6577. else
  6578. {
  6579. Quaternion rotation = part.RotationOffset;
  6580. rotation.Normalize();
  6581. zc.AddNormQuat(rotation);
  6582. }
  6583. zc.AddUInt((uint)CompressedFlags.Tree); // cflags
  6584. zc.AddZeros(16); // owner id
  6585. zc.AddByte(state); // tree parameter
  6586. zc.AddZeros(28); //extraparameters 1, pbs 23, texture 4
  6587. return;
  6588. }
  6589. //NameValue and state
  6590. byte[] nv = null;
  6591. if (part.ParentGroup.IsAttachment)
  6592. {
  6593. if (part.IsRoot)
  6594. nv = Util.StringToBytes256("AttachItemID STRING RW SV " + part.ParentGroup.FromItemID);
  6595. int st = (int)part.ParentGroup.AttachmentPoint;
  6596. state = (byte)(((st & 0xf0) >> 4) + ((st & 0x0f) << 4)); ;
  6597. }
  6598. bool hastext = false;
  6599. bool hassound = false;
  6600. bool hasps = false;
  6601. bool hastexanim = false;
  6602. bool hasangvel = false;
  6603. bool hasmediaurl = false;
  6604. bool haspsnew = false;
  6605. int BlockLengh = 111;
  6606. byte[] extraParamBytes = part.Shape.ExtraParams;
  6607. if (extraParamBytes == null || extraParamBytes.Length < 2)
  6608. {
  6609. ++BlockLengh;
  6610. extraParamBytes = null;
  6611. }
  6612. else
  6613. BlockLengh += extraParamBytes.Length;
  6614. byte[] hoverTextColor = null;
  6615. osUTF8 osUTF8PartText = part.osUTF8Text;
  6616. if (osUTF8PartText != null && osUTF8PartText.Length > 0)
  6617. {
  6618. cflags |= CompressedFlags.HasText;
  6619. BlockLengh += osUTF8PartText.Length;
  6620. if (osUTF8PartText[osUTF8PartText.Length - 1] != 0)
  6621. ++BlockLengh;
  6622. hoverTextColor = part.GetTextColor().GetBytes(false);
  6623. BlockLengh += hoverTextColor.Length;
  6624. hastext = true;
  6625. }
  6626. if (part.ParticleSystem != null && part.ParticleSystem.Length > 1)
  6627. {
  6628. BlockLengh += part.ParticleSystem.Length;
  6629. if (part.ParticleSystem.Length > 86)
  6630. {
  6631. hasps = false;
  6632. cflags |= CompressedFlags.HasParticlesNew;
  6633. haspsnew = true;
  6634. }
  6635. else
  6636. {
  6637. cflags |= CompressedFlags.HasParticlesLegacy;
  6638. hasps = true;
  6639. }
  6640. }
  6641. if (part.Sound != UUID.Zero || part.SoundFlags != 0)
  6642. {
  6643. BlockLengh += 25;
  6644. cflags |= CompressedFlags.HasSound;
  6645. hassound = true;
  6646. }
  6647. if (part.ParentID != 0)
  6648. {
  6649. BlockLengh += 4;
  6650. cflags |= CompressedFlags.HasParent;
  6651. }
  6652. if (part.TextureAnimation != null && part.TextureAnimation.Length > 0)
  6653. {
  6654. BlockLengh += part.TextureAnimation.Length + 4;
  6655. cflags |= CompressedFlags.TextureAnimation;
  6656. hastexanim = true;
  6657. }
  6658. if (part.AngularVelocity.LengthSquared() > 1e-8f)
  6659. {
  6660. BlockLengh += 12;
  6661. cflags |= CompressedFlags.HasAngularVelocity;
  6662. hasangvel = true;
  6663. }
  6664. osUTF8 osUTFMediaUrl = part.osUTFMediaUrl;
  6665. if (osUTFMediaUrl != null && osUTFMediaUrl.Length > 0)
  6666. {
  6667. BlockLengh += osUTFMediaUrl.Length;
  6668. if (osUTFMediaUrl[osUTFMediaUrl.Length - 1] != 0)
  6669. ++BlockLengh;
  6670. cflags |= CompressedFlags.MediaURL;
  6671. hasmediaurl = true;
  6672. }
  6673. if (nv != null)
  6674. {
  6675. BlockLengh += nv.Length;
  6676. cflags |= CompressedFlags.HasNameValues;
  6677. }
  6678. byte[] textureEntry = part.Shape.TextureEntry;
  6679. if(textureEntry != null)
  6680. BlockLengh += textureEntry.Length;
  6681. // filter out mesh faces hack
  6682. ushort profileBegin = part.Shape.ProfileBegin;
  6683. ushort profileHollow = part.Shape.ProfileHollow;
  6684. byte profileCurve = part.Shape.ProfileCurve;
  6685. byte pathScaleY = part.Shape.PathScaleY;
  6686. if (part.Shape.SculptType == (byte)SculptType.Mesh) // filter out hack
  6687. {
  6688. profileCurve = (byte)(part.Shape.ProfileCurve & 0x0f);
  6689. // fix old values that confused viewers
  6690. if (profileBegin == 1)
  6691. profileBegin = 9375;
  6692. if (profileHollow == 1)
  6693. profileHollow = 27500;
  6694. // fix torus hole size Y that also confuse some viewers
  6695. if (profileCurve == (byte)ProfileShape.Circle && pathScaleY < 150)
  6696. pathScaleY = 150;
  6697. }
  6698. // first is primFlags
  6699. zc.AddUInt((uint)primflags);
  6700. // datablock len
  6701. zc.AddByte((byte)BlockLengh);
  6702. zc.AddByte((byte)(BlockLengh >> 8));
  6703. // data block
  6704. zc.AddUUID(part.UUID);
  6705. zc.AddUInt(part.LocalId);
  6706. zc.AddByte((byte)pcode);
  6707. zc.AddByte(state);
  6708. zc.AddUInt((uint)part.PseudoCRC);
  6709. zc.AddByte(part.Material);
  6710. zc.AddByte(part.ClickAction);
  6711. zc.AddVector3(part.Shape.Scale);
  6712. zc.AddVector3(part.RelativePosition);
  6713. if (pcode == PCode.Grass)
  6714. zc.AddZeros(12);
  6715. else
  6716. {
  6717. Quaternion rotation = part.RotationOffset;
  6718. rotation.Normalize();
  6719. zc.AddNormQuat(rotation);
  6720. }
  6721. zc.AddUInt((uint)cflags);
  6722. if (hasps || haspsnew || hassound)
  6723. zc.AddUUID(part.OwnerID);
  6724. else
  6725. zc.AddZeros(16);
  6726. if (hasangvel)
  6727. {
  6728. zc.AddVector3(part.AngularVelocity);
  6729. }
  6730. if (part.ParentID != 0)
  6731. {
  6732. zc.AddUInt(part.ParentID);
  6733. }
  6734. if (hastext)
  6735. {
  6736. zc.AddBytes(osUTF8PartText.GetArray(), osUTF8PartText.Length);
  6737. if (osUTF8PartText[osUTF8PartText.Length - 1] != 0)
  6738. zc.AddZeros(1);
  6739. zc.AddBytes(hoverTextColor, hoverTextColor.Length);
  6740. }
  6741. if (hasmediaurl)
  6742. {
  6743. zc.AddBytes(osUTFMediaUrl.GetArray(), osUTFMediaUrl.Length);
  6744. if (osUTFMediaUrl[osUTFMediaUrl.Length - 1] != 0)
  6745. zc.AddZeros(1);
  6746. }
  6747. if (hasps)
  6748. {
  6749. byte[] ps = part.ParticleSystem;
  6750. zc.AddBytes(ps, ps.Length);
  6751. }
  6752. if (extraParamBytes == null)
  6753. zc.AddZeros(1);
  6754. else
  6755. {
  6756. zc.AddBytes(extraParamBytes, extraParamBytes.Length);
  6757. }
  6758. if (hassound)
  6759. {
  6760. zc.AddUUID(part.Sound);
  6761. zc.AddFloat((float)part.SoundGain);
  6762. zc.AddByte(part.SoundFlags);
  6763. zc.AddFloat((float)part.SoundRadius);
  6764. }
  6765. if (nv != null)
  6766. {
  6767. zc.AddBytes(nv, nv.Length);
  6768. }
  6769. zc.AddByte(part.Shape.PathCurve);
  6770. zc.AddUInt16(part.Shape.PathBegin);
  6771. zc.AddUInt16(part.Shape.PathEnd);
  6772. zc.AddByte(part.Shape.PathScaleX);
  6773. zc.AddByte(pathScaleY);
  6774. zc.AddByte(part.Shape.PathShearX);
  6775. zc.AddByte(part.Shape.PathShearY);
  6776. zc.AddByte((byte)part.Shape.PathTwist);
  6777. zc.AddByte((byte)part.Shape.PathTwistBegin);
  6778. zc.AddByte((byte)part.Shape.PathRadiusOffset);
  6779. zc.AddByte((byte)part.Shape.PathTaperX);
  6780. zc.AddByte((byte)part.Shape.PathTaperY);
  6781. zc.AddByte(part.Shape.PathRevolutions);
  6782. zc.AddByte((byte)part.Shape.PathSkew);
  6783. zc.AddByte(profileCurve);
  6784. zc.AddUInt16(profileBegin);
  6785. zc.AddUInt16(part.Shape.ProfileEnd);
  6786. zc.AddUInt16(profileHollow);
  6787. if (textureEntry == null)
  6788. {
  6789. zc.AddZeros(4);
  6790. }
  6791. else
  6792. {
  6793. int len = textureEntry.Length;
  6794. zc.AddByte((byte)len);
  6795. zc.AddByte((byte)(len >> 8));
  6796. zc.AddZeros(2);
  6797. zc.AddBytes(textureEntry, len);
  6798. }
  6799. if (hastexanim)
  6800. {
  6801. byte[] ta = part.TextureAnimation;
  6802. int len = ta.Length;
  6803. zc.AddByte((byte)len);
  6804. zc.AddByte((byte)(len >> 8));
  6805. zc.AddZeros(2);
  6806. zc.AddBytes(ta, len);
  6807. }
  6808. if (haspsnew)
  6809. {
  6810. byte[] ps = part.ParticleSystem;
  6811. zc.AddBytes(ps, ps.Length);
  6812. }
  6813. }
  6814. public void SendNameReply(UUID profileId, string firstname, string lastname)
  6815. {
  6816. UUIDNameReplyPacket packet = (UUIDNameReplyPacket)PacketPool.Instance.GetPacket(PacketType.UUIDNameReply);
  6817. // TODO: don't create new blocks if recycling an old packet
  6818. packet.UUIDNameBlock = new UUIDNameReplyPacket.UUIDNameBlockBlock[1];
  6819. packet.UUIDNameBlock[0] = new UUIDNameReplyPacket.UUIDNameBlockBlock();
  6820. packet.UUIDNameBlock[0].ID = profileId;
  6821. packet.UUIDNameBlock[0].FirstName = Util.StringToBytes256(firstname);
  6822. packet.UUIDNameBlock[0].LastName = Util.StringToBytes256(lastname);
  6823. OutPacket(packet, ThrottleOutPacketType.Task);
  6824. }
  6825. public Dictionary<UUID, ulong> GetGroupPowers()
  6826. {
  6827. lock(m_groupPowers)
  6828. {
  6829. return new Dictionary<UUID, ulong>(m_groupPowers);
  6830. }
  6831. }
  6832. public void SetGroupPowers(Dictionary<UUID, ulong> powers)
  6833. {
  6834. lock(m_groupPowers)
  6835. {
  6836. m_groupPowers.Clear();
  6837. m_groupPowers = powers;
  6838. }
  6839. }
  6840. public ulong GetGroupPowers(UUID groupID)
  6841. {
  6842. lock(m_groupPowers)
  6843. {
  6844. if (m_groupPowers.ContainsKey(groupID))
  6845. return m_groupPowers[groupID];
  6846. }
  6847. return 0;
  6848. }
  6849. #endregion
  6850. protected virtual void RegisterLocalPacketHandlers()
  6851. {
  6852. AddLocalPacketHandler(PacketType.LogoutRequest, HandleLogout);
  6853. // If AgentUpdate is ever handled asynchronously, then we will also need to construct a new AgentUpdateArgs
  6854. // for each AgentUpdate packet.
  6855. AddLocalPacketHandler(PacketType.AgentUpdate, HandleAgentUpdate, false);
  6856. AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect, false);
  6857. AddLocalPacketHandler(PacketType.VelocityInterpolateOff, HandleVelocityInterpolateOff, false);
  6858. AddLocalPacketHandler(PacketType.VelocityInterpolateOn, HandleVelocityInterpolateOn, false);
  6859. AddLocalPacketHandler(PacketType.AgentCachedTexture, HandleAgentTextureCached, false);
  6860. AddLocalPacketHandler(PacketType.MultipleObjectUpdate, HandleMultipleObjUpdate, false);
  6861. AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest, false);
  6862. AddLocalPacketHandler(PacketType.ParcelBuy, HandleParcelBuyRequest, false);
  6863. AddLocalPacketHandler(PacketType.UUIDGroupNameRequest, HandleUUIDGroupNameRequest);
  6864. AddLocalPacketHandler(PacketType.ObjectGroup, HandleObjectGroupRequest);
  6865. AddLocalPacketHandler(PacketType.GenericMessage, HandleGenericMessage);
  6866. AddLocalPacketHandler(PacketType.AvatarPropertiesRequest, HandleAvatarPropertiesRequest);
  6867. AddLocalPacketHandler(PacketType.ChatFromViewer, HandleChatFromViewer);
  6868. AddLocalPacketHandler(PacketType.AvatarPropertiesUpdate, HandlerAvatarPropertiesUpdate);
  6869. AddLocalPacketHandler(PacketType.ScriptDialogReply, HandlerScriptDialogReply);
  6870. AddLocalPacketHandler(PacketType.ImprovedInstantMessage, HandlerImprovedInstantMessage);
  6871. AddLocalPacketHandler(PacketType.AcceptFriendship, HandlerAcceptFriendship);
  6872. AddLocalPacketHandler(PacketType.DeclineFriendship, HandlerDeclineFriendship);
  6873. AddLocalPacketHandler(PacketType.TerminateFriendship, HandlerTerminateFriendship);
  6874. AddLocalPacketHandler(PacketType.RezObject, HandlerRezObject);
  6875. AddLocalPacketHandler(PacketType.DeRezObject, HandlerDeRezObject);
  6876. AddLocalPacketHandler(PacketType.RezRestoreToWorld, HandlerRezRestoreToWorld);
  6877. AddLocalPacketHandler(PacketType.ModifyLand, HandlerModifyLand);
  6878. AddLocalPacketHandler(PacketType.RegionHandshakeReply, HandlerRegionHandshakeReply, false);
  6879. AddLocalPacketHandler(PacketType.AgentWearablesRequest, HandlerAgentWearablesRequest);
  6880. AddLocalPacketHandler(PacketType.AgentSetAppearance, HandlerAgentSetAppearance);
  6881. AddLocalPacketHandler(PacketType.AgentIsNowWearing, HandlerAgentIsNowWearing);
  6882. AddLocalPacketHandler(PacketType.RezSingleAttachmentFromInv, HandlerRezSingleAttachmentFromInv);
  6883. AddLocalPacketHandler(PacketType.RezMultipleAttachmentsFromInv, HandleRezMultipleAttachmentsFromInv);
  6884. AddLocalPacketHandler(PacketType.DetachAttachmentIntoInv, HandleDetachAttachmentIntoInv);
  6885. AddLocalPacketHandler(PacketType.ObjectAttach, HandleObjectAttach);
  6886. AddLocalPacketHandler(PacketType.ObjectDetach, HandleObjectDetach);
  6887. AddLocalPacketHandler(PacketType.ObjectDrop, HandleObjectDrop);
  6888. AddLocalPacketHandler(PacketType.SetAlwaysRun, HandleSetAlwaysRun, false);
  6889. AddLocalPacketHandler(PacketType.CompleteAgentMovement, HandleCompleteAgentMovement);
  6890. AddLocalPacketHandler(PacketType.AgentAnimation, HandleAgentAnimation, false);
  6891. AddLocalPacketHandler(PacketType.AgentRequestSit, HandleAgentRequestSit);
  6892. AddLocalPacketHandler(PacketType.AgentSit, HandleAgentSit);
  6893. AddLocalPacketHandler(PacketType.SoundTrigger, HandleSoundTrigger);
  6894. AddLocalPacketHandler(PacketType.AvatarPickerRequest, HandleAvatarPickerRequest);
  6895. AddLocalPacketHandler(PacketType.AgentDataUpdateRequest, HandleAgentDataUpdateRequest);
  6896. AddLocalPacketHandler(PacketType.UserInfoRequest, HandleUserInfoRequest);
  6897. AddLocalPacketHandler(PacketType.UpdateUserInfo, HandleUpdateUserInfo);
  6898. AddLocalPacketHandler(PacketType.SetStartLocationRequest, HandleSetStartLocationRequest);
  6899. AddLocalPacketHandler(PacketType.AgentThrottle, HandleAgentThrottle, false);
  6900. AddLocalPacketHandler(PacketType.AgentPause, HandleAgentPause, false);
  6901. AddLocalPacketHandler(PacketType.AgentResume, HandleAgentResume, false);
  6902. AddLocalPacketHandler(PacketType.ForceScriptControlRelease, HandleForceScriptControlRelease);
  6903. AddLocalPacketHandler(PacketType.ObjectLink, HandleObjectLink);
  6904. AddLocalPacketHandler(PacketType.ObjectDelink, HandleObjectDelink);
  6905. AddLocalPacketHandler(PacketType.ObjectAdd, HandleObjectAdd);
  6906. AddLocalPacketHandler(PacketType.ObjectShape, HandleObjectShape);
  6907. AddLocalPacketHandler(PacketType.ObjectExtraParams, HandleObjectExtraParams);
  6908. AddLocalPacketHandler(PacketType.ObjectDuplicate, HandleObjectDuplicate);
  6909. AddLocalPacketHandler(PacketType.RequestMultipleObjects, HandleRequestMultipleObjects);
  6910. AddLocalPacketHandler(PacketType.ObjectSelect, HandleObjectSelect);
  6911. AddLocalPacketHandler(PacketType.ObjectDeselect, HandleObjectDeselect);
  6912. AddLocalPacketHandler(PacketType.ObjectPosition, HandleObjectPosition);
  6913. AddLocalPacketHandler(PacketType.ObjectScale, HandleObjectScale);
  6914. AddLocalPacketHandler(PacketType.ObjectRotation, HandleObjectRotation);
  6915. AddLocalPacketHandler(PacketType.ObjectFlagUpdate, HandleObjectFlagUpdate);
  6916. // Handle ObjectImage (TextureEntry) updates synchronously, since when updating multiple prim faces at once,
  6917. // some clients will send out a separate ObjectImage packet for each face
  6918. AddLocalPacketHandler(PacketType.ObjectImage, HandleObjectImage, false);
  6919. AddLocalPacketHandler(PacketType.ObjectGrab, HandleObjectGrab, false);
  6920. AddLocalPacketHandler(PacketType.ObjectGrabUpdate, HandleObjectGrabUpdate, false);
  6921. AddLocalPacketHandler(PacketType.ObjectDeGrab, HandleObjectDeGrab);
  6922. AddLocalPacketHandler(PacketType.ObjectSpinStart, HandleObjectSpinStart, false);
  6923. AddLocalPacketHandler(PacketType.ObjectSpinUpdate, HandleObjectSpinUpdate, false);
  6924. AddLocalPacketHandler(PacketType.ObjectSpinStop, HandleObjectSpinStop, false);
  6925. AddLocalPacketHandler(PacketType.ObjectDescription, HandleObjectDescription, false);
  6926. AddLocalPacketHandler(PacketType.ObjectName, HandleObjectName, false);
  6927. AddLocalPacketHandler(PacketType.ObjectPermissions, HandleObjectPermissions, false);
  6928. AddLocalPacketHandler(PacketType.Undo, HandleUndo, false);
  6929. AddLocalPacketHandler(PacketType.UndoLand, HandleLandUndo, false);
  6930. AddLocalPacketHandler(PacketType.Redo, HandleRedo, false);
  6931. AddLocalPacketHandler(PacketType.ObjectDuplicateOnRay, HandleObjectDuplicateOnRay);
  6932. AddLocalPacketHandler(PacketType.RequestObjectPropertiesFamily, HandleRequestObjectPropertiesFamily, false);
  6933. AddLocalPacketHandler(PacketType.ObjectIncludeInSearch, HandleObjectIncludeInSearch);
  6934. AddLocalPacketHandler(PacketType.ScriptAnswerYes, HandleScriptAnswerYes, false);
  6935. AddLocalPacketHandler(PacketType.ObjectClickAction, HandleObjectClickAction, false);
  6936. AddLocalPacketHandler(PacketType.ObjectMaterial, HandleObjectMaterial, false);
  6937. AddLocalPacketHandler(PacketType.RequestImage, HandleRequestImage, false);
  6938. AddLocalPacketHandler(PacketType.TransferRequest, HandleTransferRequest, false);
  6939. AddLocalPacketHandler(PacketType.AssetUploadRequest, HandleAssetUploadRequest);
  6940. AddLocalPacketHandler(PacketType.RequestXfer, HandleRequestXfer);
  6941. AddLocalPacketHandler(PacketType.SendXferPacket, HandleSendXferPacket);
  6942. AddLocalPacketHandler(PacketType.ConfirmXferPacket, HandleConfirmXferPacket, false);
  6943. AddLocalPacketHandler(PacketType.AbortXfer, HandleAbortXfer);
  6944. AddLocalPacketHandler(PacketType.CreateInventoryFolder, HandleCreateInventoryFolder);
  6945. AddLocalPacketHandler(PacketType.UpdateInventoryFolder, HandleUpdateInventoryFolder);
  6946. AddLocalPacketHandler(PacketType.MoveInventoryFolder, HandleMoveInventoryFolder);
  6947. AddLocalPacketHandler(PacketType.CreateInventoryItem, HandleCreateInventoryItem);
  6948. AddLocalPacketHandler(PacketType.LinkInventoryItem, HandleLinkInventoryItem);
  6949. AddLocalPacketHandler(PacketType.FetchInventory, HandleFetchInventory);
  6950. AddLocalPacketHandler(PacketType.FetchInventoryDescendents, HandleFetchInventoryDescendents);
  6951. AddLocalPacketHandler(PacketType.PurgeInventoryDescendents, HandlePurgeInventoryDescendents);
  6952. AddLocalPacketHandler(PacketType.UpdateInventoryItem, HandleUpdateInventoryItem);
  6953. AddLocalPacketHandler(PacketType.CopyInventoryItem, HandleCopyInventoryItem);
  6954. AddLocalPacketHandler(PacketType.MoveInventoryItem, HandleMoveInventoryItem);
  6955. AddLocalPacketHandler(PacketType.RemoveInventoryItem, HandleRemoveInventoryItem);
  6956. AddLocalPacketHandler(PacketType.RemoveInventoryFolder, HandleRemoveInventoryFolder);
  6957. AddLocalPacketHandler(PacketType.RemoveInventoryObjects, HandleRemoveInventoryObjects);
  6958. AddLocalPacketHandler(PacketType.RequestTaskInventory, HandleRequestTaskInventory);
  6959. AddLocalPacketHandler(PacketType.UpdateTaskInventory, HandleUpdateTaskInventory);
  6960. AddLocalPacketHandler(PacketType.RemoveTaskInventory, HandleRemoveTaskInventory);
  6961. AddLocalPacketHandler(PacketType.MoveTaskInventory, HandleMoveTaskInventory);
  6962. AddLocalPacketHandler(PacketType.RezScript, HandleRezScript);
  6963. AddLocalPacketHandler(PacketType.MapLayerRequest, HandleMapLayerRequest);
  6964. AddLocalPacketHandler(PacketType.MapBlockRequest, HandleMapBlockRequest);
  6965. AddLocalPacketHandler(PacketType.MapNameRequest, HandleMapNameRequest);
  6966. AddLocalPacketHandler(PacketType.TeleportLandmarkRequest, HandleTeleportLandmarkRequest);
  6967. AddLocalPacketHandler(PacketType.TeleportCancel, HandleTeleportCancel);
  6968. AddLocalPacketHandler(PacketType.TeleportLocationRequest, HandleTeleportLocationRequest);
  6969. AddLocalPacketHandler(PacketType.UUIDNameRequest, HandleUUIDNameRequest, false);
  6970. AddLocalPacketHandler(PacketType.RegionHandleRequest, HandleRegionHandleRequest, false);
  6971. AddLocalPacketHandler(PacketType.ParcelInfoRequest, HandleParcelInfoRequest);
  6972. AddLocalPacketHandler(PacketType.ParcelAccessListRequest, HandleParcelAccessListRequest, false);
  6973. AddLocalPacketHandler(PacketType.ParcelAccessListUpdate, HandleParcelAccessListUpdate, false);
  6974. AddLocalPacketHandler(PacketType.ParcelPropertiesRequest, HandleParcelPropertiesRequest, false);
  6975. AddLocalPacketHandler(PacketType.ParcelDivide, HandleParcelDivide);
  6976. AddLocalPacketHandler(PacketType.ParcelJoin, HandleParcelJoin);
  6977. AddLocalPacketHandler(PacketType.ParcelPropertiesUpdate, HandleParcelPropertiesUpdate);
  6978. AddLocalPacketHandler(PacketType.ParcelSelectObjects, HandleParcelSelectObjects);
  6979. AddLocalPacketHandler(PacketType.ParcelObjectOwnersRequest, HandleParcelObjectOwnersRequest);
  6980. AddLocalPacketHandler(PacketType.ParcelGodForceOwner, HandleParcelGodForceOwner);
  6981. AddLocalPacketHandler(PacketType.ParcelRelease, HandleParcelRelease);
  6982. AddLocalPacketHandler(PacketType.ParcelReclaim, HandleParcelReclaim);
  6983. AddLocalPacketHandler(PacketType.ParcelReturnObjects, HandleParcelReturnObjects);
  6984. AddLocalPacketHandler(PacketType.ParcelSetOtherCleanTime, HandleParcelSetOtherCleanTime);
  6985. AddLocalPacketHandler(PacketType.LandStatRequest, HandleLandStatRequest);
  6986. AddLocalPacketHandler(PacketType.ParcelDwellRequest, HandleParcelDwellRequest);
  6987. AddLocalPacketHandler(PacketType.EstateOwnerMessage, HandleEstateOwnerMessage);
  6988. AddLocalPacketHandler(PacketType.RequestRegionInfo, HandleRequestRegionInfo, false);
  6989. AddLocalPacketHandler(PacketType.EstateCovenantRequest, HandleEstateCovenantRequest);
  6990. AddLocalPacketHandler(PacketType.RequestGodlikePowers, HandleRequestGodlikePowers);
  6991. AddLocalPacketHandler(PacketType.GodKickUser, HandleGodKickUser);
  6992. AddLocalPacketHandler(PacketType.MoneyBalanceRequest, HandleMoneyBalanceRequest);
  6993. AddLocalPacketHandler(PacketType.EconomyDataRequest, HandleEconomyDataRequest);
  6994. AddLocalPacketHandler(PacketType.RequestPayPrice, HandleRequestPayPrice);
  6995. AddLocalPacketHandler(PacketType.ObjectSaleInfo, HandleObjectSaleInfo);
  6996. AddLocalPacketHandler(PacketType.ObjectBuy, HandleObjectBuy);
  6997. AddLocalPacketHandler(PacketType.GetScriptRunning, HandleGetScriptRunning);
  6998. AddLocalPacketHandler(PacketType.SetScriptRunning, HandleSetScriptRunning);
  6999. AddLocalPacketHandler(PacketType.ScriptReset, HandleScriptReset);
  7000. AddLocalPacketHandler(PacketType.ActivateGestures, HandleActivateGestures);
  7001. AddLocalPacketHandler(PacketType.DeactivateGestures, HandleDeactivateGestures);
  7002. AddLocalPacketHandler(PacketType.ObjectOwner, HandleObjectOwner);
  7003. AddLocalPacketHandler(PacketType.AgentFOV, HandleAgentFOV, false);
  7004. AddLocalPacketHandler(PacketType.ViewerStats, HandleViewerStats);
  7005. AddLocalPacketHandler(PacketType.MapItemRequest, HandleMapItemRequest, false);
  7006. AddLocalPacketHandler(PacketType.TransferAbort, HandleTransferAbort, false);
  7007. AddLocalPacketHandler(PacketType.MuteListRequest, HandleMuteListRequest, false);
  7008. AddLocalPacketHandler(PacketType.UseCircuitCode, HandleUseCircuitCode);
  7009. AddLocalPacketHandler(PacketType.CreateNewOutfitAttachments, HandleCreateNewOutfitAttachments);
  7010. AddLocalPacketHandler(PacketType.AgentHeightWidth, HandleAgentHeightWidth, false);
  7011. AddLocalPacketHandler(PacketType.InventoryDescendents, HandleInventoryDescendents);
  7012. AddLocalPacketHandler(PacketType.DirPlacesQuery, HandleDirPlacesQuery);
  7013. AddLocalPacketHandler(PacketType.DirFindQuery, HandleDirFindQuery);
  7014. AddLocalPacketHandler(PacketType.DirLandQuery, HandleDirLandQuery);
  7015. AddLocalPacketHandler(PacketType.DirPopularQuery, HandleDirPopularQuery);
  7016. AddLocalPacketHandler(PacketType.DirClassifiedQuery, HandleDirClassifiedQuery);
  7017. AddLocalPacketHandler(PacketType.EventInfoRequest, HandleEventInfoRequest);
  7018. AddLocalPacketHandler(PacketType.OfferCallingCard, HandleOfferCallingCard);
  7019. AddLocalPacketHandler(PacketType.AcceptCallingCard, HandleAcceptCallingCard);
  7020. AddLocalPacketHandler(PacketType.DeclineCallingCard, HandleDeclineCallingCard);
  7021. AddLocalPacketHandler(PacketType.ActivateGroup, HandleActivateGroup);
  7022. AddLocalPacketHandler(PacketType.GroupTitlesRequest, HandleGroupTitlesRequest);
  7023. AddLocalPacketHandler(PacketType.GroupProfileRequest, HandleGroupProfileRequest);
  7024. AddLocalPacketHandler(PacketType.GroupMembersRequest, HandleGroupMembersRequest);
  7025. AddLocalPacketHandler(PacketType.GroupRoleDataRequest, HandleGroupRoleDataRequest);
  7026. AddLocalPacketHandler(PacketType.GroupRoleMembersRequest, HandleGroupRoleMembersRequest);
  7027. AddLocalPacketHandler(PacketType.CreateGroupRequest, HandleCreateGroupRequest);
  7028. AddLocalPacketHandler(PacketType.UpdateGroupInfo, HandleUpdateGroupInfo);
  7029. AddLocalPacketHandler(PacketType.SetGroupAcceptNotices, HandleSetGroupAcceptNotices);
  7030. AddLocalPacketHandler(PacketType.GroupTitleUpdate, HandleGroupTitleUpdate);
  7031. AddLocalPacketHandler(PacketType.ParcelDeedToGroup, HandleParcelDeedToGroup);
  7032. AddLocalPacketHandler(PacketType.GroupNoticesListRequest, HandleGroupNoticesListRequest);
  7033. AddLocalPacketHandler(PacketType.GroupNoticeRequest, HandleGroupNoticeRequest);
  7034. AddLocalPacketHandler(PacketType.GroupRoleUpdate, HandleGroupRoleUpdate);
  7035. AddLocalPacketHandler(PacketType.GroupRoleChanges, HandleGroupRoleChanges);
  7036. AddLocalPacketHandler(PacketType.JoinGroupRequest, HandleJoinGroupRequest);
  7037. AddLocalPacketHandler(PacketType.LeaveGroupRequest, HandleLeaveGroupRequest);
  7038. AddLocalPacketHandler(PacketType.EjectGroupMemberRequest, HandleEjectGroupMemberRequest);
  7039. AddLocalPacketHandler(PacketType.InviteGroupRequest, HandleInviteGroupRequest);
  7040. AddLocalPacketHandler(PacketType.StartLure, HandleStartLure);
  7041. AddLocalPacketHandler(PacketType.TeleportLureRequest, HandleTeleportLureRequest);
  7042. AddLocalPacketHandler(PacketType.ClassifiedInfoRequest, HandleClassifiedInfoRequest);
  7043. AddLocalPacketHandler(PacketType.ClassifiedInfoUpdate, HandleClassifiedInfoUpdate);
  7044. AddLocalPacketHandler(PacketType.ClassifiedDelete, HandleClassifiedDelete);
  7045. AddLocalPacketHandler(PacketType.ClassifiedGodDelete, HandleClassifiedGodDelete);
  7046. AddLocalPacketHandler(PacketType.EventGodDelete, HandleEventGodDelete);
  7047. AddLocalPacketHandler(PacketType.EventNotificationAddRequest, HandleEventNotificationAddRequest);
  7048. AddLocalPacketHandler(PacketType.EventNotificationRemoveRequest, HandleEventNotificationRemoveRequest);
  7049. AddLocalPacketHandler(PacketType.RetrieveInstantMessages, HandleRetrieveInstantMessages);
  7050. AddLocalPacketHandler(PacketType.PickDelete, HandlePickDelete);
  7051. AddLocalPacketHandler(PacketType.PickGodDelete, HandlePickGodDelete);
  7052. AddLocalPacketHandler(PacketType.PickInfoUpdate, HandlePickInfoUpdate);
  7053. AddLocalPacketHandler(PacketType.AvatarNotesUpdate, HandleAvatarNotesUpdate);
  7054. AddLocalPacketHandler(PacketType.AvatarInterestsUpdate, HandleAvatarInterestsUpdate);
  7055. AddLocalPacketHandler(PacketType.GrantUserRights, HandleGrantUserRights);
  7056. AddLocalPacketHandler(PacketType.PlacesQuery, HandlePlacesQuery);
  7057. AddLocalPacketHandler(PacketType.UpdateMuteListEntry, HandleUpdateMuteListEntry);
  7058. AddLocalPacketHandler(PacketType.RemoveMuteListEntry, HandleRemoveMuteListEntry);
  7059. AddLocalPacketHandler(PacketType.UserReport, HandleUserReport);
  7060. AddLocalPacketHandler(PacketType.FindAgent, HandleFindAgent);
  7061. AddLocalPacketHandler(PacketType.TrackAgent, HandleTrackAgent);
  7062. AddLocalPacketHandler(PacketType.GodUpdateRegionInfo, HandleGodUpdateRegionInfoUpdate);
  7063. AddLocalPacketHandler(PacketType.GodlikeMessage, HandleGodlikeMessage);
  7064. AddLocalPacketHandler(PacketType.StateSave, HandleSaveStatePacket);
  7065. AddLocalPacketHandler(PacketType.GroupAccountDetailsRequest, HandleGroupAccountDetailsRequest);
  7066. AddLocalPacketHandler(PacketType.GroupAccountSummaryRequest, HandleGroupAccountSummaryRequest);
  7067. AddLocalPacketHandler(PacketType.GroupAccountTransactionsRequest, HandleGroupTransactionsDetailsRequest);
  7068. AddLocalPacketHandler(PacketType.FreezeUser, HandleFreezeUser);
  7069. AddLocalPacketHandler(PacketType.EjectUser, HandleEjectUser);
  7070. AddLocalPacketHandler(PacketType.ParcelBuyPass, HandleParcelBuyPass);
  7071. AddLocalPacketHandler(PacketType.ParcelGodMarkAsContent, HandleParcelGodMarkAsContent);
  7072. AddLocalPacketHandler(PacketType.GroupActiveProposalsRequest, HandleGroupActiveProposalsRequest);
  7073. AddLocalPacketHandler(PacketType.GroupVoteHistoryRequest, HandleGroupVoteHistoryRequest);
  7074. AddLocalPacketHandler(PacketType.SimWideDeletes, HandleSimWideDeletes);
  7075. AddLocalPacketHandler(PacketType.SendPostcard, HandleSendPostcard);
  7076. AddLocalPacketHandler(PacketType.ChangeInventoryItemFlags, HandleChangeInventoryItemFlags);
  7077. AddLocalPacketHandler(PacketType.RevokePermissions, HandleRevokePermissions);
  7078. AddGenericPacketHandler("autopilot", HandleAutopilot);
  7079. }
  7080. #region Packet Handlers
  7081. public int TotalAgentUpdates { get; set; }
  7082. #region Scene/Avatar
  7083. // Threshold for body rotation to be a significant agent update
  7084. // use the abs of cos
  7085. private const float QDELTABody = 1.0f - 0.00001f;
  7086. private const float QDELTAHead = 1.0f - 0.00001f;
  7087. // Threshold for camera rotation to be a significant agent update
  7088. private const float VDELTA = 0.01f;
  7089. /// <summary>
  7090. /// This checks the update significance against the last update made.
  7091. /// </summary>
  7092. /// <remarks>Can only be called by one thread at a time</remarks>
  7093. /// <returns></returns>
  7094. /// <param name='x'></param>
  7095. public bool CheckAgentUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
  7096. {
  7097. return CheckAgentMovementUpdateSignificance(x) || CheckAgentCameraUpdateSignificance(x);
  7098. }
  7099. /// <summary>
  7100. /// This checks the movement/state update significance against the last update made.
  7101. /// </summary>
  7102. /// <remarks>Can only be called by one thread at a time</remarks>
  7103. /// <returns></returns>
  7104. /// <param name='x'></param>
  7105. private bool CheckAgentMovementUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
  7106. {
  7107. if(
  7108. (x.ControlFlags != m_thisAgentUpdateArgs.ControlFlags) // significant if control flags changed
  7109. // || ((x.ControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0 &&
  7110. // (x.ControlFlags & 0x3f8dfff) != 0) // we need to rotate the av on fly
  7111. || x.ControlFlags != (byte)AgentManager.ControlFlags.NONE// actually all movement controls need to pass
  7112. || (x.Flags != m_thisAgentUpdateArgs.Flags) // significant if Flags changed
  7113. || (x.State != m_thisAgentUpdateArgs.State) // significant if Stats changed
  7114. || (Math.Abs(x.Far - m_thisAgentUpdateArgs.Far) >= 32) // significant if far distance changed
  7115. )
  7116. return true;
  7117. float qdelta = Math.Abs(Quaternion.Dot(x.BodyRotation, m_thisAgentUpdateArgs.BodyRotation));
  7118. if(qdelta < QDELTABody) // significant if body rotation above(below cos) threshold
  7119. return true;
  7120. return false;
  7121. }
  7122. /// <summary>
  7123. /// This checks the camera update significance against the last update made.
  7124. /// </summary>
  7125. /// <remarks>Can only be called by one thread at a time</remarks>
  7126. /// <returns></returns>
  7127. /// <param name='x'></param>
  7128. private bool CheckAgentCameraUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
  7129. {
  7130. if(Math.Abs(x.CameraCenter.X - m_thisAgentUpdateArgs.CameraCenter.X) > VDELTA ||
  7131. Math.Abs(x.CameraCenter.Y - m_thisAgentUpdateArgs.CameraCenter.Y) > VDELTA ||
  7132. Math.Abs(x.CameraCenter.Z - m_thisAgentUpdateArgs.CameraCenter.Z) > VDELTA ||
  7133. Math.Abs(x.CameraAtAxis.X - m_thisAgentUpdateArgs.CameraAtAxis.X) > VDELTA ||
  7134. Math.Abs(x.CameraAtAxis.Y - m_thisAgentUpdateArgs.CameraAtAxis.Y) > VDELTA ||
  7135. // Math.Abs(x.CameraAtAxis.Z - m_thisAgentUpdateArgs.CameraAtAxis.Z) > VDELTA ||
  7136. Math.Abs(x.CameraLeftAxis.X - m_thisAgentUpdateArgs.CameraLeftAxis.X) > VDELTA ||
  7137. Math.Abs(x.CameraLeftAxis.Y - m_thisAgentUpdateArgs.CameraLeftAxis.Y) > VDELTA ||
  7138. // Math.Abs(x.CameraLeftAxis.Z - m_thisAgentUpdateArgs.CameraLeftAxis.Z) > VDELTA ||
  7139. Math.Abs(x.CameraUpAxis.X - m_thisAgentUpdateArgs.CameraUpAxis.X) > VDELTA ||
  7140. Math.Abs(x.CameraUpAxis.Y - m_thisAgentUpdateArgs.CameraUpAxis.Y) > VDELTA
  7141. // Math.Abs(x.CameraLeftAxis.Z - m_thisAgentUpdateArgs.CameraLeftAxis.Z) > VDELTA ||
  7142. )
  7143. return true;
  7144. return false;
  7145. }
  7146. private void HandleAgentUpdate(Packet packet)
  7147. {
  7148. if(OnAgentUpdate == null)
  7149. {
  7150. //PacketPool.Instance.ReturnPacket(packet);
  7151. return;
  7152. }
  7153. AgentUpdatePacket agentUpdate = (AgentUpdatePacket)packet;
  7154. AgentUpdatePacket.AgentDataBlock x = agentUpdate.AgentData;
  7155. if (x.AgentID != AgentId || x.SessionID != SessionId)
  7156. {
  7157. //PacketPool.Instance.ReturnPacket(packet);
  7158. return;
  7159. }
  7160. uint seq = packet.Header.Sequence;
  7161. TotalAgentUpdates++;
  7162. // dont let ignored updates pollute this throttles
  7163. if(SceneAgent == null || SceneAgent.IsChildAgent ||
  7164. SceneAgent.IsInTransit || seq <= m_thisAgentUpdateArgs.lastpacketSequence )
  7165. {
  7166. // throttle reset is done at MoveAgentIntoRegion()
  7167. // called by scenepresence on completemovement
  7168. //PacketPool.Instance.ReturnPacket(packet);
  7169. return;
  7170. }
  7171. m_thisAgentUpdateArgs.lastpacketSequence = seq;
  7172. OnPreAgentUpdate?.Invoke(this, m_thisAgentUpdateArgs);
  7173. bool movement;
  7174. bool camera;
  7175. double now = Util.GetTimeStampMS();
  7176. if(now - m_thisAgentUpdateArgs.lastUpdateTS > 500.0) // at least 2 per sec
  7177. {
  7178. movement = true;
  7179. camera = true;
  7180. }
  7181. else
  7182. {
  7183. movement = CheckAgentMovementUpdateSignificance(x);
  7184. camera = CheckAgentCameraUpdateSignificance(x);
  7185. }
  7186. // Was there a significant movement/state change?
  7187. if (movement)
  7188. {
  7189. m_thisAgentUpdateArgs.BodyRotation = x.BodyRotation;
  7190. m_thisAgentUpdateArgs.ControlFlags = x.ControlFlags;
  7191. m_thisAgentUpdateArgs.Far = x.Far;
  7192. m_thisAgentUpdateArgs.Flags = x.Flags;
  7193. m_thisAgentUpdateArgs.HeadRotation = x.HeadRotation;
  7194. m_thisAgentUpdateArgs.State = x.State;
  7195. m_thisAgentUpdateArgs.NeedsCameraCollision = !camera;
  7196. OnAgentUpdate?.Invoke(this, m_thisAgentUpdateArgs);
  7197. }
  7198. // Was there a significant camera(s) change?
  7199. if (camera)
  7200. {
  7201. m_thisAgentUpdateArgs.CameraAtAxis = x.CameraAtAxis;
  7202. m_thisAgentUpdateArgs.CameraCenter = x.CameraCenter;
  7203. m_thisAgentUpdateArgs.CameraLeftAxis = x.CameraLeftAxis;
  7204. m_thisAgentUpdateArgs.CameraUpAxis = x.CameraUpAxis;
  7205. m_thisAgentUpdateArgs.NeedsCameraCollision = true;
  7206. OnAgentCameraUpdate?.Invoke(this, m_thisAgentUpdateArgs);
  7207. }
  7208. if(movement && camera)
  7209. m_thisAgentUpdateArgs.lastUpdateTS = now;
  7210. //PacketPool.Instance.ReturnPacket(packet);
  7211. }
  7212. private void HandleMoneyTransferRequest(Packet Pack)
  7213. {
  7214. if(OnMoneyTransferRequest == null)
  7215. return;
  7216. MoneyTransferRequestPacket money = (MoneyTransferRequestPacket)Pack;
  7217. // validate the agent owns the agentID and sessionID
  7218. if (money.MoneyData.SourceID == AgentId && money.AgentData.AgentID == AgentId &&
  7219. money.AgentData.SessionID == SessionId)
  7220. {
  7221. OnMoneyTransferRequest?.Invoke(money.MoneyData.SourceID, money.MoneyData.DestID,
  7222. money.MoneyData.Amount, money.MoneyData.TransactionType,
  7223. Util.FieldToString(money.MoneyData.Description));
  7224. }
  7225. }
  7226. private void HandleParcelGodMarkAsContent(Packet packet)
  7227. {
  7228. if(OnParcelGodMark == null)
  7229. return;
  7230. ParcelGodMarkAsContentPacket ParcelGodMarkAsContent = (ParcelGodMarkAsContentPacket)packet;
  7231. if(SessionId != ParcelGodMarkAsContent.AgentData.SessionID || AgentId != ParcelGodMarkAsContent.AgentData.AgentID)
  7232. return;
  7233. OnParcelGodMark?.Invoke(this,
  7234. ParcelGodMarkAsContent.AgentData.AgentID,
  7235. ParcelGodMarkAsContent.ParcelData.LocalID);
  7236. }
  7237. private void HandleFreezeUser(Packet packet)
  7238. {
  7239. if(OnParcelFreezeUser == null)
  7240. return;
  7241. FreezeUserPacket FreezeUser = (FreezeUserPacket)packet;
  7242. if(SessionId != FreezeUser.AgentData.SessionID || AgentId != FreezeUser.AgentData.AgentID)
  7243. return;
  7244. OnParcelFreezeUser?.Invoke(this,
  7245. FreezeUser.AgentData.AgentID,
  7246. FreezeUser.Data.Flags,
  7247. FreezeUser.Data.TargetID);
  7248. }
  7249. private void HandleEjectUser(Packet packet)
  7250. {
  7251. if(OnParcelEjectUser == null)
  7252. return;
  7253. EjectUserPacket EjectUser = (EjectUserPacket)packet;
  7254. if(SessionId != EjectUser.AgentData.SessionID || AgentId != EjectUser.AgentData.AgentID)
  7255. return;
  7256. OnParcelEjectUser?.Invoke(this,
  7257. EjectUser.AgentData.AgentID,
  7258. EjectUser.Data.Flags,
  7259. EjectUser.Data.TargetID);
  7260. }
  7261. private void HandleParcelBuyPass(Packet packet)
  7262. {
  7263. if(OnParcelBuyPass == null)
  7264. return;
  7265. ParcelBuyPassPacket ParcelBuyPass = (ParcelBuyPassPacket)packet;
  7266. if(SessionId != ParcelBuyPass.AgentData.SessionID || AgentId != ParcelBuyPass.AgentData.AgentID)
  7267. return;
  7268. OnParcelBuyPass?.Invoke(this,
  7269. ParcelBuyPass.AgentData.AgentID,
  7270. ParcelBuyPass.ParcelData.LocalID);
  7271. }
  7272. private void HandleParcelBuyRequest(Packet Pack)
  7273. {
  7274. ParcelBuyPacket parcel = (ParcelBuyPacket)Pack;
  7275. if (parcel.AgentData.AgentID == AgentId && parcel.AgentData.SessionID == SessionId)
  7276. {
  7277. OnParcelBuy?.Invoke(parcel.AgentData.AgentID, parcel.Data.GroupID, parcel.Data.Final,
  7278. parcel.Data.IsGroupOwned,
  7279. parcel.Data.RemoveContribution, parcel.Data.LocalID, parcel.ParcelData.Area,
  7280. parcel.ParcelData.Price,
  7281. false);
  7282. }
  7283. }
  7284. private void HandleUUIDGroupNameRequest(Packet Pack)
  7285. {
  7286. if(OnUUIDGroupNameRequest == null)
  7287. return;
  7288. ScenePresence sp = (ScenePresence)SceneAgent;
  7289. if(sp == null || sp.IsDeleted || (sp.IsInTransit && !sp.IsInLocalTransit))
  7290. return;
  7291. UUIDGroupNameRequestPacket upack = (UUIDGroupNameRequestPacket)Pack;
  7292. for (int i = 0; i < upack.UUIDNameBlock.Length; i++)
  7293. {
  7294. OnUUIDGroupNameRequest?.Invoke(upack.UUIDNameBlock[i].ID, this);
  7295. }
  7296. }
  7297. public void HandleGenericMessage(Packet pack)
  7298. {
  7299. if (m_genericPacketHandlers.Count == 0)
  7300. return;
  7301. GenericMessagePacket gmpack = (GenericMessagePacket)pack;
  7302. if (gmpack.AgentData.SessionID != SessionId || gmpack.AgentData.AgentID != AgentId)
  7303. return;
  7304. string method = Util.FieldToString(gmpack.MethodData.Method).ToLower().Trim();
  7305. if (m_genericPacketHandlers.TryGetValue(method, out GenericMessage handlerGenericMessage))
  7306. {
  7307. List<string> msg = new List<string>();
  7308. List<byte[]> msgBytes = new List<byte[]>();
  7309. foreach (GenericMessagePacket.ParamListBlock block in gmpack.ParamList)
  7310. {
  7311. msg.Add(Util.FieldToString(block.Parameter));
  7312. msgBytes.Add(block.Parameter);
  7313. }
  7314. try
  7315. {
  7316. OnBinaryGenericMessage?.Invoke(this, method, msgBytes.ToArray());
  7317. handlerGenericMessage?.Invoke(this, method, msg);
  7318. }
  7319. catch (Exception e)
  7320. {
  7321. m_log.ErrorFormat(
  7322. "[LLCLIENTVIEW]: Exception when handling generic message {0}{1}", e.Message, e.StackTrace);
  7323. }
  7324. }
  7325. }
  7326. public void HandleObjectGroupRequest(Packet Pack)
  7327. {
  7328. if(OnObjectGroupRequest == null)
  7329. return;
  7330. ObjectGroupPacket ogpack = (ObjectGroupPacket)Pack;
  7331. if (ogpack.AgentData.SessionID != SessionId)
  7332. return;
  7333. for (int i = 0; i < ogpack.ObjectData.Length; i++)
  7334. {
  7335. OnObjectGroupRequest?.Invoke(this, ogpack.AgentData.GroupID, ogpack.ObjectData[i].ObjectLocalID, UUID.Zero);
  7336. }
  7337. }
  7338. private void HandleViewerEffect(Packet Pack)
  7339. {
  7340. if(OnViewerEffect == null)
  7341. return;
  7342. ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
  7343. if (viewer.AgentData.SessionID != SessionId || AgentId != viewer.AgentData.AgentID)
  7344. return;
  7345. int length = viewer.Effect.Length;
  7346. List<ViewerEffectEventHandlerArg> args = new List<ViewerEffectEventHandlerArg>(length);
  7347. for (int i = 0; i < length; i++)
  7348. {
  7349. //copy the effects block arguments into the event handler arg.
  7350. ViewerEffectEventHandlerArg argument = new ViewerEffectEventHandlerArg();
  7351. argument.AgentID = viewer.Effect[i].AgentID;
  7352. argument.Color = viewer.Effect[i].Color;
  7353. argument.Duration = viewer.Effect[i].Duration;
  7354. argument.ID = viewer.Effect[i].ID;
  7355. argument.Type = viewer.Effect[i].Type;
  7356. argument.TypeData = viewer.Effect[i].TypeData;
  7357. args.Add(argument);
  7358. }
  7359. OnViewerEffect?.Invoke(this, args);
  7360. }
  7361. private void HandleVelocityInterpolateOff(Packet Pack)
  7362. {
  7363. VelocityInterpolateOffPacket p = (VelocityInterpolateOffPacket)Pack;
  7364. if (p.AgentData.SessionID != SessionId || p.AgentData.AgentID != AgentId)
  7365. return ;
  7366. m_VelocityInterpolate = false;
  7367. }
  7368. private void HandleVelocityInterpolateOn(Packet Pack)
  7369. {
  7370. VelocityInterpolateOnPacket p = (VelocityInterpolateOnPacket)Pack;
  7371. if (p.AgentData.SessionID != SessionId || p.AgentData.AgentID != AgentId)
  7372. return;
  7373. m_VelocityInterpolate = true;
  7374. }
  7375. private void HandleAvatarPropertiesRequest(Packet Pack)
  7376. {
  7377. AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;
  7378. if (avatarProperties.AgentData.SessionID != SessionId || avatarProperties.AgentData.AgentID != AgentId)
  7379. return;
  7380. OnRequestAvatarProperties?.Invoke(this, avatarProperties.AgentData.AvatarID);
  7381. }
  7382. private void HandleChatFromViewer(Packet Pack)
  7383. {
  7384. if (OnChatFromClient == null)
  7385. return;
  7386. ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
  7387. if (inchatpack.AgentData.SessionID != SessionId || inchatpack.AgentData.AgentID != AgentId)
  7388. return;
  7389. string fromName = String.Empty; //ClientAvatar.firstname + " " + ClientAvatar.lastname;
  7390. byte[] message = inchatpack.ChatData.Message;
  7391. byte type = inchatpack.ChatData.Type;
  7392. Vector3 fromPos = new Vector3(); // ClientAvatar.Pos;
  7393. // UUID fromAgentID = AgentId;
  7394. int channel = inchatpack.ChatData.Channel;
  7395. OSChatMessage args = new OSChatMessage();
  7396. args.Channel = channel;
  7397. args.From = fromName;
  7398. args.Message = Utils.BytesToString(message);
  7399. args.Type = (ChatTypeEnum)type;
  7400. args.Position = fromPos;
  7401. args.Scene = Scene;
  7402. args.Sender = this;
  7403. args.SenderUUID = this.AgentId;
  7404. OnChatFromClient?.Invoke(this, args);
  7405. }
  7406. private void HandlerAvatarPropertiesUpdate(Packet Pack)
  7407. {
  7408. if (OnUpdateAvatarProperties == null)
  7409. return;
  7410. AvatarPropertiesUpdatePacket avatarProps = (AvatarPropertiesUpdatePacket)Pack;
  7411. if (avatarProps.AgentData.SessionID != SessionId || avatarProps.AgentData.AgentID != AgentId)
  7412. return;
  7413. AvatarPropertiesUpdatePacket.PropertiesDataBlock Properties = avatarProps.PropertiesData;
  7414. UserProfileData UserProfile = new UserProfileData();
  7415. UserProfile.ID = AgentId;
  7416. UserProfile.AboutText = Utils.BytesToString(Properties.AboutText);
  7417. UserProfile.FirstLifeAboutText = Utils.BytesToString(Properties.FLAboutText);
  7418. UserProfile.FirstLifeImage = Properties.FLImageID;
  7419. UserProfile.Image = Properties.ImageID;
  7420. UserProfile.ProfileUrl = Utils.BytesToString(Properties.ProfileURL);
  7421. UserProfile.UserFlags &= ~3;
  7422. UserProfile.UserFlags |= Properties.AllowPublish ? 1 : 0;
  7423. UserProfile.UserFlags |= Properties.MaturePublish ? 2 : 0;
  7424. OnUpdateAvatarProperties?.Invoke(this, UserProfile);
  7425. }
  7426. private void HandlerScriptDialogReply(Packet Pack)
  7427. {
  7428. if (OnChatFromClient == null)
  7429. return;
  7430. ScriptDialogReplyPacket rdialog = (ScriptDialogReplyPacket)Pack;
  7431. //m_log.DebugFormat("[CLIENT]: Received ScriptDialogReply from {0}", rdialog.Data.ObjectID);
  7432. if (rdialog.AgentData.SessionID != SessionId || rdialog.AgentData.AgentID != AgentId)
  7433. return;
  7434. int ch = rdialog.Data.ChatChannel;
  7435. byte[] msg = rdialog.Data.ButtonLabel;
  7436. OSChatMessage args = new OSChatMessage();
  7437. args.Channel = ch;
  7438. args.From = String.Empty;
  7439. args.Message = Utils.BytesToString(msg);
  7440. args.Type = ChatTypeEnum.Region; //Behaviour in SL is that the response can be heard from any distance
  7441. args.Position = new Vector3();
  7442. args.Scene = Scene;
  7443. args.Sender = this;
  7444. OnChatFromClient?.Invoke(this, args);
  7445. }
  7446. private void HandlerImprovedInstantMessage(Packet Pack)
  7447. {
  7448. if(OnInstantMessage == null)
  7449. return;
  7450. ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack;
  7451. if (msgpack.AgentData.SessionID != SessionId || msgpack.AgentData.AgentID != AgentId)
  7452. return;
  7453. string IMfromName = Util.FieldToString(msgpack.MessageBlock.FromAgentName);
  7454. string IMmessage = Utils.BytesToString(msgpack.MessageBlock.Message);
  7455. GridInstantMessage im = new GridInstantMessage(Scene,
  7456. msgpack.AgentData.AgentID,
  7457. IMfromName,
  7458. msgpack.MessageBlock.ToAgentID,
  7459. msgpack.MessageBlock.Dialog,
  7460. msgpack.MessageBlock.FromGroup,
  7461. IMmessage,
  7462. msgpack.MessageBlock.ID,
  7463. msgpack.MessageBlock.Offline != 0 ? true : false,
  7464. msgpack.MessageBlock.Position,
  7465. msgpack.MessageBlock.BinaryBucket,
  7466. true);
  7467. OnInstantMessage?.Invoke(this, im);
  7468. }
  7469. private void HandlerAcceptFriendship(Packet Pack)
  7470. {
  7471. if(OnApproveFriendRequest == null)
  7472. return;
  7473. AcceptFriendshipPacket afriendpack = (AcceptFriendshipPacket)Pack;
  7474. if (afriendpack.AgentData.SessionID != SessionId || afriendpack.AgentData.AgentID != AgentId)
  7475. return;
  7476. // My guess is this is the folder to stick the calling card into
  7477. List<UUID> callingCardFolders = new List<UUID>();
  7478. UUID transactionID = afriendpack.TransactionBlock.TransactionID;
  7479. for (int fi = 0; fi < afriendpack.FolderData.Length; fi++)
  7480. {
  7481. callingCardFolders.Add(afriendpack.FolderData[fi].FolderID);
  7482. }
  7483. OnApproveFriendRequest?.Invoke(this, transactionID, callingCardFolders);
  7484. }
  7485. private void HandlerDeclineFriendship(Packet Pack)
  7486. {
  7487. DeclineFriendshipPacket dfriendpack = (DeclineFriendshipPacket)Pack;
  7488. if (dfriendpack.AgentData.SessionID != SessionId || dfriendpack.AgentData.AgentID != AgentId)
  7489. return;
  7490. OnDenyFriendRequest?.Invoke(this,
  7491. dfriendpack.TransactionBlock.TransactionID,
  7492. null);
  7493. }
  7494. private void HandlerTerminateFriendship(Packet Pack)
  7495. {
  7496. TerminateFriendshipPacket tfriendpack = (TerminateFriendshipPacket)Pack;
  7497. if (tfriendpack.AgentData.SessionID != SessionId || tfriendpack.AgentData.AgentID != AgentId)
  7498. return;
  7499. UUID exFriendID = tfriendpack.ExBlock.OtherID;
  7500. FriendshipTermination TerminateFriendshipHandler = OnTerminateFriendship;
  7501. TerminateFriendshipHandler?.Invoke(this, exFriendID);
  7502. }
  7503. private void HandleFindAgent(Packet packet)
  7504. {
  7505. FindAgentPacket FindAgent = (FindAgentPacket)packet;
  7506. OnFindAgent?.Invoke(this,FindAgent.AgentBlock.Hunter,FindAgent.AgentBlock.Prey);
  7507. }
  7508. private void HandleTrackAgent(Packet packet)
  7509. {
  7510. TrackAgentPacket TrackAgent = (TrackAgentPacket)packet;
  7511. if(TrackAgent.AgentData.AgentID != AgentId || TrackAgent.AgentData.SessionID != SessionId)
  7512. return;
  7513. OnTrackAgent?.Invoke(this,
  7514. TrackAgent.AgentData.AgentID,
  7515. TrackAgent.TargetData.PreyID);
  7516. }
  7517. private void HandlerRezObject(Packet Pack)
  7518. {
  7519. RezObjectPacket rezPacket = (RezObjectPacket)Pack;
  7520. if (rezPacket.AgentData.SessionID != SessionId || rezPacket.AgentData.AgentID != AgentId)
  7521. return;
  7522. UUID rezGroupID = rezPacket.AgentData.GroupID;
  7523. if(!IsGroupMember(rezGroupID))
  7524. rezGroupID = UUID.Zero;
  7525. OnRezObject?.Invoke(this, rezPacket.InventoryData.ItemID, rezGroupID, rezPacket.RezData.RayEnd,
  7526. rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID,
  7527. rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection,
  7528. rezPacket.RezData.RezSelected, rezPacket.RezData.RemoveItem,
  7529. rezPacket.RezData.FromTaskID);
  7530. }
  7531. private class DeRezObjectInfo
  7532. {
  7533. public int count;
  7534. public List<uint> objectids;
  7535. }
  7536. private Dictionary<UUID, DeRezObjectInfo> m_DeRezObjectDelayed = new Dictionary<UUID, DeRezObjectInfo>();
  7537. private void HandlerDeRezObject(Packet Pack)
  7538. {
  7539. if (OnDeRezObject == null)
  7540. return;
  7541. DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)Pack;
  7542. if (DeRezPacket.AgentData.SessionID != SessionId || DeRezPacket.AgentData.AgentID != AgentId)
  7543. return;
  7544. List<uint> deRezIDs;
  7545. DeRezAction action = (DeRezAction)DeRezPacket.AgentBlock.Destination;
  7546. int numberPackets = DeRezPacket.AgentBlock.PacketCount;
  7547. int curPacket = DeRezPacket.AgentBlock.PacketNumber;
  7548. UUID id = DeRezPacket.AgentBlock.TransactionID;
  7549. if (numberPackets > 1)
  7550. {
  7551. DeRezObjectInfo info;
  7552. if (!m_DeRezObjectDelayed.TryGetValue(id, out info))
  7553. {
  7554. deRezIDs = new List<uint>();
  7555. info = new DeRezObjectInfo();
  7556. info.count = 0;
  7557. info.objectids = deRezIDs;
  7558. m_DeRezObjectDelayed[id] = info;
  7559. }
  7560. else
  7561. {
  7562. deRezIDs = info.objectids;
  7563. }
  7564. foreach (DeRezObjectPacket.ObjectDataBlock data in DeRezPacket.ObjectData)
  7565. {
  7566. deRezIDs.Add(data.ObjectLocalID);
  7567. }
  7568. info.count++;
  7569. if (info.count < numberPackets)
  7570. return;
  7571. m_DeRezObjectDelayed.Remove(id);
  7572. info.objectids = null;
  7573. }
  7574. else
  7575. {
  7576. deRezIDs = new List<uint>();
  7577. foreach (DeRezObjectPacket.ObjectDataBlock data in DeRezPacket.ObjectData)
  7578. {
  7579. deRezIDs.Add(data.ObjectLocalID);
  7580. }
  7581. }
  7582. OnDeRezObject?.Invoke(this, deRezIDs, DeRezPacket.AgentBlock.GroupID,
  7583. action, DeRezPacket.AgentBlock.DestinationID);
  7584. }
  7585. private void HandlerRezRestoreToWorld(Packet Pack)
  7586. {
  7587. RezRestoreToWorldPacket restore = (RezRestoreToWorldPacket)Pack;
  7588. if (restore.AgentData.SessionID != SessionId || restore.AgentData.AgentID != AgentId)
  7589. return;
  7590. OnRezRestoreToWorld?.Invoke(this, restore.InventoryData.ItemID);
  7591. }
  7592. private void HandlerModifyLand(Packet Pack)
  7593. {
  7594. if (OnModifyTerrain == null)
  7595. return;
  7596. ModifyLandPacket modify = (ModifyLandPacket)Pack;
  7597. if (modify.ParcelData.Length == 0)
  7598. return;
  7599. if (modify.AgentData.SessionID != SessionId || modify.AgentData.AgentID != AgentId)
  7600. return;
  7601. //m_log.Info("[LAND]: LAND:" + modify.ToString());
  7602. for (int i = 0; i < modify.ParcelData.Length; i++)
  7603. {
  7604. OnModifyTerrain?.Invoke(AgentId, modify.ModifyBlock.Height, modify.ModifyBlock.Seconds,
  7605. modify.ModifyBlockExtended[i].BrushSize, modify.ModifyBlock.Action,
  7606. modify.ParcelData[i].North, modify.ParcelData[i].West,
  7607. modify.ParcelData[i].South, modify.ParcelData[i].East,
  7608. modify.ParcelData[i].LocalID);
  7609. }
  7610. }
  7611. public uint m_viewerHandShakeFlags = 0;
  7612. private void HandlerRegionHandshakeReply(Packet Pack)
  7613. {
  7614. if (OnRegionHandShakeReply == null)
  7615. return; // silence the warning
  7616. RegionHandshakeReplyPacket rsrpkt = (RegionHandshakeReplyPacket)Pack;
  7617. if(rsrpkt.AgentData.AgentID != m_agentId || rsrpkt.AgentData.SessionID != m_sessionId)
  7618. return;
  7619. if(m_supportViewerCache)
  7620. m_viewerHandShakeFlags = rsrpkt.RegionInfo.Flags;
  7621. else
  7622. m_viewerHandShakeFlags = 0;
  7623. OnRegionHandShakeReply?.Invoke(this);
  7624. }
  7625. private void HandlerAgentWearablesRequest(Packet Pack)
  7626. {
  7627. OnRequestWearables?.Invoke(this);
  7628. OnRequestAvatarsData?.Invoke(this);
  7629. }
  7630. private void HandlerAgentSetAppearance(Packet Pack)
  7631. {
  7632. if(OnSetAppearance == null)
  7633. return;
  7634. AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
  7635. if (appear.AgentData.SessionID != SessionId || appear.AgentData.AgentID != AgentId)
  7636. return;
  7637. try
  7638. {
  7639. Vector3 avSize = appear.AgentData.Size;
  7640. byte[] visualparams = new byte[appear.VisualParam.Length];
  7641. for (int i = 0; i < appear.VisualParam.Length; i++)
  7642. visualparams[i] = appear.VisualParam[i].ParamValue;
  7643. //var b = appear.WearableData[0];
  7644. Primitive.TextureEntry te = null;
  7645. if (appear.ObjectData.TextureEntry.Length > 1)
  7646. te = new Primitive.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length);
  7647. WearableCacheItem[] cacheitems = new WearableCacheItem[appear.WearableData.Length];
  7648. for (int i=0; i<appear.WearableData.Length;i++)
  7649. cacheitems[i] = new WearableCacheItem(){
  7650. CacheId = appear.WearableData[i].CacheID,
  7651. TextureIndex=Convert.ToUInt32(appear.WearableData[i].TextureIndex)
  7652. };
  7653. OnSetAppearance?.Invoke(this, te, visualparams,avSize, cacheitems);
  7654. }
  7655. catch (Exception e)
  7656. {
  7657. m_log.ErrorFormat(
  7658. "[CLIENT VIEW]: AgentSetApperance packet handler threw an exception, {0}",
  7659. e);
  7660. }
  7661. }
  7662. private void HandlerAgentIsNowWearing(Packet Pack)
  7663. {
  7664. if (OnAvatarNowWearing == null)
  7665. return;
  7666. AgentIsNowWearingPacket nowWearing = (AgentIsNowWearingPacket)Pack;
  7667. if (nowWearing.AgentData.SessionID != SessionId || nowWearing.AgentData.AgentID != AgentId)
  7668. return;
  7669. AvatarWearingArgs wearingArgs = new AvatarWearingArgs();
  7670. for (int i = 0; i < nowWearing.WearableData.Length; i++)
  7671. {
  7672. //m_log.DebugFormat("[XXX]: Wearable type {0} item {1}", nowWearing.WearableData[i].WearableType, nowWearing.WearableData[i].ItemID);
  7673. AvatarWearingArgs.Wearable wearable =
  7674. new AvatarWearingArgs.Wearable(nowWearing.WearableData[i].ItemID,
  7675. nowWearing.WearableData[i].WearableType);
  7676. wearingArgs.NowWearing.Add(wearable);
  7677. }
  7678. OnAvatarNowWearing?.Invoke(this, wearingArgs);
  7679. }
  7680. private void HandlerRezSingleAttachmentFromInv(Packet Pack)
  7681. {
  7682. RezSingleAttachmentFromInvPacket rez = (RezSingleAttachmentFromInvPacket)Pack;
  7683. if (rez.AgentData.SessionID != SessionId || rez.AgentData.AgentID != AgentId)
  7684. return;
  7685. OnRezSingleAttachmentFromInv?.Invoke(this, rez.ObjectData.ItemID,
  7686. rez.ObjectData.AttachmentPt);
  7687. }
  7688. private void HandleRezMultipleAttachmentsFromInv(Packet Pack)
  7689. {
  7690. if(OnRezMultipleAttachmentsFromInv == null)
  7691. return;
  7692. RezMultipleAttachmentsFromInvPacket rez = (RezMultipleAttachmentsFromInvPacket)Pack;
  7693. if (rez.AgentData.SessionID != SessionId || rez.AgentData.AgentID != AgentId)
  7694. return;
  7695. List<KeyValuePair<UUID, uint>> rezlist = new List<KeyValuePair<UUID, uint>>();
  7696. foreach (RezMultipleAttachmentsFromInvPacket.ObjectDataBlock obj in rez.ObjectData)
  7697. rezlist.Add(new KeyValuePair<UUID, uint>(obj.ItemID, obj.AttachmentPt));
  7698. OnRezMultipleAttachmentsFromInv?.Invoke(this, rezlist);
  7699. }
  7700. private void HandleDetachAttachmentIntoInv(Packet Pack)
  7701. {
  7702. if (OnDetachAttachmentIntoInv == null)
  7703. return;
  7704. DetachAttachmentIntoInvPacket detachtoInv = (DetachAttachmentIntoInvPacket)Pack;
  7705. if(detachtoInv.ObjectData.AgentID != AgentId)
  7706. return;
  7707. OnDetachAttachmentIntoInv?.Invoke(detachtoInv.ObjectData.ItemID, this);
  7708. }
  7709. private void HandleObjectAttach(Packet Pack)
  7710. {
  7711. if (OnObjectAttach == null)
  7712. return;
  7713. ObjectAttachPacket att = (ObjectAttachPacket)Pack;
  7714. if (att.AgentData.SessionID != SessionId || att.AgentData.AgentID != AgentId)
  7715. return;
  7716. if (att.ObjectData.Length > 0)
  7717. OnObjectAttach?.Invoke(this, att.ObjectData[0].ObjectLocalID, att.AgentData.AttachmentPoint, false);
  7718. }
  7719. private void HandleObjectDetach(Packet Pack)
  7720. {
  7721. if(OnObjectDetach == null)
  7722. return;
  7723. ObjectDetachPacket dett = (ObjectDetachPacket)Pack;
  7724. if (dett.AgentData.SessionID != SessionId || dett.AgentData.AgentID != AgentId)
  7725. return;
  7726. for (int j = 0; j < dett.ObjectData.Length; j++)
  7727. {
  7728. uint obj = dett.ObjectData[j].ObjectLocalID;
  7729. OnObjectDetach?.Invoke(obj, this);
  7730. }
  7731. }
  7732. private void HandleObjectDrop(Packet Pack)
  7733. {
  7734. if(OnObjectDrop == null)
  7735. return;
  7736. ObjectDropPacket dropp = (ObjectDropPacket)Pack;
  7737. if (dropp.AgentData.SessionID != SessionId || dropp.AgentData.AgentID != AgentId)
  7738. return;
  7739. for (int j = 0; j < dropp.ObjectData.Length; j++)
  7740. {
  7741. uint obj = dropp.ObjectData[j].ObjectLocalID;
  7742. OnObjectDrop?.Invoke(obj, this);
  7743. }
  7744. }
  7745. private void HandleSetAlwaysRun(Packet Pack)
  7746. {
  7747. SetAlwaysRunPacket run = (SetAlwaysRunPacket)Pack;
  7748. if (run.AgentData.SessionID != SessionId || run.AgentData.AgentID != AgentId)
  7749. return;
  7750. OnSetAlwaysRun?.Invoke(this, run.AgentData.AlwaysRun);
  7751. }
  7752. private void HandleCompleteAgentMovement(Packet Pack)
  7753. {
  7754. //m_log.DebugFormat("[LLClientView] HandleCompleteAgentMovement");
  7755. CompleteAgentMovementPacket cmp = (CompleteAgentMovementPacket)Pack;
  7756. if(cmp.AgentData.AgentID != m_agentId || cmp.AgentData.SessionID != m_sessionId || cmp.AgentData.CircuitCode != m_circuitCode)
  7757. return;
  7758. OnCompleteMovementToRegion?.Invoke(this, true);
  7759. }
  7760. private void HandleAgentAnimation(Packet Pack)
  7761. {
  7762. if(OnChangeAnim == null)
  7763. return;
  7764. AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
  7765. if (AgentAni.AgentData.SessionID != SessionId || AgentAni.AgentData.AgentID != AgentId)
  7766. return;
  7767. for (int i = 0; i < AgentAni.AnimationList.Length; i++)
  7768. OnChangeAnim?.Invoke(AgentAni.AnimationList[i].AnimID, AgentAni.AnimationList[i].StartAnim, false);
  7769. OnChangeAnim?.Invoke(UUID.Zero, false, true);
  7770. }
  7771. private void HandleAgentRequestSit(Packet Pack)
  7772. {
  7773. if (OnAgentRequestSit == null)
  7774. return;
  7775. AgentRequestSitPacket agentRequestSit = (AgentRequestSitPacket)Pack;
  7776. if (agentRequestSit.AgentData.SessionID != SessionId || agentRequestSit.AgentData.AgentID != AgentId)
  7777. return;
  7778. if (SceneAgent.IsChildAgent)
  7779. {
  7780. SendCantSitBecauseChildAgentResponse();
  7781. return;
  7782. }
  7783. OnAgentRequestSit?.Invoke(this, agentRequestSit.AgentData.AgentID,
  7784. agentRequestSit.TargetObject.TargetID, agentRequestSit.TargetObject.Offset);
  7785. }
  7786. private void HandleAgentSit(Packet Pack)
  7787. {
  7788. if (OnAgentSit == null)
  7789. return;
  7790. AgentSitPacket agentSit = (AgentSitPacket)Pack;
  7791. if (agentSit.AgentData.SessionID != SessionId || agentSit.AgentData.AgentID != AgentId)
  7792. return;
  7793. if (SceneAgent.IsChildAgent)
  7794. {
  7795. SendCantSitBecauseChildAgentResponse();
  7796. return;
  7797. }
  7798. OnAgentSit?.Invoke(this, agentSit.AgentData.AgentID);
  7799. }
  7800. /// <summary>
  7801. /// Used when a child agent gets a sit response which should not be fulfilled.
  7802. /// </summary>
  7803. private void SendCantSitBecauseChildAgentResponse()
  7804. {
  7805. SendAlertMessage("Try moving closer. Can't sit on object because it is not in the same region as you.");
  7806. }
  7807. private void HandleSoundTrigger(Packet Pack)
  7808. {
  7809. SoundTriggerPacket soundTriggerPacket = (SoundTriggerPacket)Pack;
  7810. // UUIDS are sent as zeroes by the client, substitute agent's id
  7811. OnSoundTrigger?.Invoke(soundTriggerPacket.SoundData.SoundID, AgentId,
  7812. AgentId, AgentId,
  7813. soundTriggerPacket.SoundData.Gain, soundTriggerPacket.SoundData.Position,
  7814. soundTriggerPacket.SoundData.Handle);
  7815. }
  7816. private void HandleAvatarPickerRequest(Packet Pack)
  7817. {
  7818. AvatarPickerRequestPacket avRequestQuery = (AvatarPickerRequestPacket)Pack;
  7819. if (avRequestQuery.AgentData.SessionID != SessionId || avRequestQuery.AgentData.AgentID != AgentId)
  7820. return;
  7821. AvatarPickerRequestPacket.AgentDataBlock Requestdata = avRequestQuery.AgentData;
  7822. AvatarPickerRequestPacket.DataBlock querydata = avRequestQuery.Data;
  7823. //m_log.Debug("Agent Sends:" + Utils.BytesToString(querydata.Name));
  7824. OnAvatarPickerRequest?.Invoke(this, Requestdata.AgentID, Requestdata.QueryID,
  7825. Utils.BytesToString(querydata.Name));
  7826. }
  7827. private void HandleAgentDataUpdateRequest(Packet Pack)
  7828. {
  7829. AgentDataUpdateRequestPacket avRequestDataUpdatePacket = (AgentDataUpdateRequestPacket)Pack;
  7830. if (avRequestDataUpdatePacket.AgentData.SessionID != SessionId || avRequestDataUpdatePacket.AgentData.AgentID != AgentId)
  7831. return;
  7832. OnAgentDataUpdateRequest?.Invoke(this, avRequestDataUpdatePacket.AgentData.AgentID, avRequestDataUpdatePacket.AgentData.SessionID);
  7833. }
  7834. private void HandleUserInfoRequest(Packet Pack)
  7835. {
  7836. if (OnUserInfoRequest != null)
  7837. {
  7838. OnUserInfoRequest(this);
  7839. }
  7840. else
  7841. {
  7842. SendUserInfoReply(false, true, "");
  7843. }
  7844. }
  7845. private void HandleUpdateUserInfo(Packet Pack)
  7846. {
  7847. if(OnUpdateUserInfo == null)
  7848. return;
  7849. UpdateUserInfoPacket updateUserInfo = (UpdateUserInfoPacket)Pack;
  7850. if (updateUserInfo.AgentData.SessionID != SessionId || updateUserInfo.AgentData.AgentID != AgentId)
  7851. return;
  7852. bool visible = true;
  7853. string DirectoryVisibility = Utils.BytesToString(updateUserInfo.UserData.DirectoryVisibility);
  7854. if (DirectoryVisibility == "hidden")
  7855. visible = false;
  7856. OnUpdateUserInfo?.Invoke( updateUserInfo.UserData.IMViaEMail, visible, this);
  7857. }
  7858. private void HandleSetStartLocationRequest(Packet Pack)
  7859. {
  7860. SetStartLocationRequestPacket avSetStartLocationRequestPacket = (SetStartLocationRequestPacket)Pack;
  7861. if (avSetStartLocationRequestPacket.AgentData.SessionID != SessionId ||
  7862. avSetStartLocationRequestPacket.AgentData.AgentID != AgentId)
  7863. return;
  7864. float packX = avSetStartLocationRequestPacket.StartLocationData.LocationPos.X;
  7865. float packY = avSetStartLocationRequestPacket.StartLocationData.LocationPos.Y;
  7866. // Linden Client limitation..
  7867. if (packX == 255.5f || packY == 255.5f)
  7868. {
  7869. ScenePresence avatar = null;
  7870. if (((Scene)m_scene).TryGetScenePresence(AgentId, out avatar))
  7871. {
  7872. if (packX == 255.5f)
  7873. {
  7874. avSetStartLocationRequestPacket.StartLocationData.LocationPos.X = avatar.AbsolutePosition.X;
  7875. }
  7876. if (packY == 255.5f)
  7877. {
  7878. avSetStartLocationRequestPacket.StartLocationData.LocationPos.Y = avatar.AbsolutePosition.Y;
  7879. }
  7880. }
  7881. }
  7882. OnSetStartLocationRequest?.Invoke(this, 0, avSetStartLocationRequestPacket.StartLocationData.LocationPos,
  7883. avSetStartLocationRequestPacket.StartLocationData.LocationLookAt,
  7884. avSetStartLocationRequestPacket.StartLocationData.LocationID);
  7885. }
  7886. private void HandleAgentThrottle(Packet Pack)
  7887. {
  7888. AgentThrottlePacket atpack = (AgentThrottlePacket)Pack;
  7889. if (atpack.AgentData.SessionID != SessionId || atpack.AgentData.AgentID != AgentId)
  7890. return;
  7891. m_udpClient.SetThrottles(atpack.Throttle.Throttles);
  7892. OnUpdateThrottles?.Invoke();
  7893. }
  7894. private void HandleAgentPause(Packet Pack)
  7895. {
  7896. m_udpClient.IsPaused = true;
  7897. }
  7898. private void HandleAgentResume(Packet Pack)
  7899. {
  7900. m_udpClient.IsPaused = false;
  7901. m_udpServer.SendPing(m_udpClient);
  7902. }
  7903. private void HandleForceScriptControlRelease(Packet Pack)
  7904. {
  7905. OnForceReleaseControls?.Invoke(this, AgentId);
  7906. }
  7907. #endregion Scene/Avatar
  7908. #region Objects/m_sceneObjects
  7909. private void HandleObjectLink(Packet Pack)
  7910. {
  7911. ObjectLinkPacket link = (ObjectLinkPacket)Pack;
  7912. if (link.AgentData.SessionID != SessionId || link.AgentData.AgentID != AgentId)
  7913. return;
  7914. uint parentprimid = 0;
  7915. List<uint> childrenprims = new List<uint>();
  7916. if (link.ObjectData.Length > 1)
  7917. {
  7918. parentprimid = link.ObjectData[0].ObjectLocalID;
  7919. for (int i = 1; i < link.ObjectData.Length; i++)
  7920. {
  7921. childrenprims.Add(link.ObjectData[i].ObjectLocalID);
  7922. }
  7923. }
  7924. OnLinkObjects?.Invoke(this, parentprimid, childrenprims);
  7925. }
  7926. private void HandleObjectDelink(Packet Pack)
  7927. {
  7928. ObjectDelinkPacket delink = (ObjectDelinkPacket)Pack;
  7929. if (delink.AgentData.SessionID != SessionId || delink.AgentData.AgentID != AgentId)
  7930. return;
  7931. // It appears the prim at index 0 is not always the root prim (for
  7932. // instance, when one prim of a link set has been edited independently
  7933. // of the others). Therefore, we'll pass all the ids onto the delink
  7934. // method for it to decide which is the root.
  7935. List<uint> prims = new List<uint>();
  7936. for (int i = 0; i < delink.ObjectData.Length; i++)
  7937. {
  7938. prims.Add(delink.ObjectData[i].ObjectLocalID);
  7939. }
  7940. OnDelinkObjects?.Invoke(prims, this);
  7941. }
  7942. private void HandleObjectAdd(Packet Pack)
  7943. {
  7944. ObjectAddPacket addPacket = (ObjectAddPacket)Pack;
  7945. if (addPacket.AgentData.SessionID != SessionId || addPacket.AgentData.AgentID != AgentId)
  7946. return;
  7947. ObjectAddPacket.ObjectDataBlock datablk = addPacket.ObjectData;
  7948. PrimitiveBaseShape shape = GetShapeFromAddPacket(addPacket);
  7949. OnAddPrim?.Invoke(AgentId, addPacket.AgentData.GroupID, datablk.RayEnd,
  7950. datablk.Rotation, shape,
  7951. datablk.BypassRaycast, datablk.RayStart, datablk.RayTargetID, datablk.RayEndIsIntersection,
  7952. datablk.AddFlags);
  7953. }
  7954. private void HandleObjectShape(Packet Pack)
  7955. {
  7956. if(OnUpdatePrimShape == null)
  7957. return;
  7958. ObjectShapePacket shapePacket = (ObjectShapePacket)Pack;
  7959. if (shapePacket.AgentData.SessionID != SessionId || shapePacket.AgentData.AgentID != AgentId)
  7960. return;
  7961. for (int i = 0; i < shapePacket.ObjectData.Length; i++)
  7962. {
  7963. UpdateShapeArgs shapeData = new UpdateShapeArgs();
  7964. uint id = shapePacket.ObjectData[i].ObjectLocalID;
  7965. shapeData.ObjectLocalID = id;
  7966. shapeData.PathBegin = shapePacket.ObjectData[i].PathBegin;
  7967. shapeData.PathCurve = shapePacket.ObjectData[i].PathCurve;
  7968. shapeData.PathEnd = shapePacket.ObjectData[i].PathEnd;
  7969. shapeData.PathRadiusOffset = shapePacket.ObjectData[i].PathRadiusOffset;
  7970. shapeData.PathRevolutions = shapePacket.ObjectData[i].PathRevolutions;
  7971. shapeData.PathScaleX = shapePacket.ObjectData[i].PathScaleX;
  7972. shapeData.PathScaleY = shapePacket.ObjectData[i].PathScaleY;
  7973. shapeData.PathShearX = shapePacket.ObjectData[i].PathShearX;
  7974. shapeData.PathShearY = shapePacket.ObjectData[i].PathShearY;
  7975. shapeData.PathSkew = shapePacket.ObjectData[i].PathSkew;
  7976. shapeData.PathTaperX = shapePacket.ObjectData[i].PathTaperX;
  7977. shapeData.PathTaperY = shapePacket.ObjectData[i].PathTaperY;
  7978. shapeData.PathTwist = shapePacket.ObjectData[i].PathTwist;
  7979. shapeData.PathTwistBegin = shapePacket.ObjectData[i].PathTwistBegin;
  7980. shapeData.ProfileBegin = shapePacket.ObjectData[i].ProfileBegin;
  7981. shapeData.ProfileCurve = shapePacket.ObjectData[i].ProfileCurve;
  7982. shapeData.ProfileEnd = shapePacket.ObjectData[i].ProfileEnd;
  7983. shapeData.ProfileHollow = shapePacket.ObjectData[i].ProfileHollow;
  7984. OnUpdatePrimShape?.Invoke(m_agentId, id, shapeData);
  7985. }
  7986. }
  7987. private void HandleObjectExtraParams(Packet Pack)
  7988. {
  7989. ObjectExtraParamsPacket extraPar = (ObjectExtraParamsPacket)Pack;
  7990. if (extraPar.AgentData.SessionID != SessionId || extraPar.AgentData.AgentID != AgentId)
  7991. return;
  7992. ObjectExtraParams handlerUpdateExtraParams = OnUpdateExtraParams;
  7993. if (handlerUpdateExtraParams != null)
  7994. {
  7995. for (int i = 0; i < extraPar.ObjectData.Length; i++)
  7996. {
  7997. OnUpdateExtraParams?.Invoke(m_agentId, extraPar.ObjectData[i].ObjectLocalID,
  7998. extraPar.ObjectData[i].ParamType,
  7999. extraPar.ObjectData[i].ParamInUse, extraPar.ObjectData[i].ParamData);
  8000. }
  8001. }
  8002. }
  8003. private void HandleObjectDuplicate(Packet Pack)
  8004. {
  8005. if(OnObjectDuplicate == null)
  8006. return;
  8007. ObjectDuplicatePacket dupe = (ObjectDuplicatePacket)Pack;
  8008. if (dupe.AgentData.SessionID != SessionId || dupe.AgentData.AgentID != AgentId)
  8009. return;
  8010. // ObjectDuplicatePacket.AgentDataBlock AgentandGroupData = dupe.AgentData;
  8011. for (int i = 0; i < dupe.ObjectData.Length; i++)
  8012. {
  8013. UUID rezGroupID = dupe.AgentData.GroupID;
  8014. if(!IsGroupMember(rezGroupID))
  8015. rezGroupID = UUID.Zero;
  8016. OnObjectDuplicate?.Invoke(dupe.ObjectData[i].ObjectLocalID, dupe.SharedData.Offset,
  8017. dupe.SharedData.DuplicateFlags, AgentId,
  8018. rezGroupID);
  8019. }
  8020. }
  8021. private void HandleRequestMultipleObjects(Packet Pack)
  8022. {
  8023. if (OnObjectRequest == null)
  8024. return;
  8025. RequestMultipleObjectsPacket incomingRequest = (RequestMultipleObjectsPacket)Pack;
  8026. if (incomingRequest.AgentData.SessionID != SessionId || incomingRequest.AgentData.AgentID != AgentId)
  8027. return;
  8028. for (int i = 0; i < incomingRequest.ObjectData.Length; i++)
  8029. OnObjectRequest?.Invoke(incomingRequest.ObjectData[i].ID, this);
  8030. }
  8031. private void HandleObjectSelect(Packet Pack)
  8032. {
  8033. if(OnObjectSelect == null)
  8034. return;
  8035. ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
  8036. if (incomingselect.AgentData.SessionID != SessionId || incomingselect.AgentData.AgentID != AgentId)
  8037. return;
  8038. List<uint> thisSelection = new List<uint>();
  8039. for (int i = 0; i < incomingselect.ObjectData.Length; i++)
  8040. thisSelection.Add(incomingselect.ObjectData[i].ObjectLocalID);
  8041. OnObjectSelect?.Invoke(thisSelection, this);
  8042. }
  8043. private void HandleObjectDeselect(Packet Pack)
  8044. {
  8045. if(OnObjectDeselect == null)
  8046. return;
  8047. ObjectDeselectPacket incomingdeselect = (ObjectDeselectPacket)Pack;
  8048. if (incomingdeselect.AgentData.SessionID != SessionId || incomingdeselect.AgentData.AgentID != AgentId)
  8049. return;
  8050. for (int i = 0; i < incomingdeselect.ObjectData.Length; i++)
  8051. {
  8052. OnObjectDeselect?.Invoke(incomingdeselect.ObjectData[i].ObjectLocalID, this);
  8053. }
  8054. }
  8055. private void HandleObjectPosition(Packet Pack)
  8056. {
  8057. if (OnUpdatePrimGroupPosition == null)
  8058. return;
  8059. // DEPRECATED: but till libsecondlife removes it, people will use it
  8060. ObjectPositionPacket position = (ObjectPositionPacket)Pack;
  8061. if (position.AgentData.SessionID != SessionId || position.AgentData.AgentID != AgentId)
  8062. return;
  8063. for (int i = 0; i < position.ObjectData.Length; i++)
  8064. OnUpdatePrimGroupPosition?.Invoke(position.ObjectData[i].ObjectLocalID, position.ObjectData[i].Position, this);
  8065. }
  8066. private void HandleObjectScale(Packet Pack)
  8067. {
  8068. if (OnUpdatePrimGroupScale == null)
  8069. return;
  8070. // DEPRECATED: but till libsecondlife removes it, people will use it
  8071. ObjectScalePacket scale = (ObjectScalePacket)Pack;
  8072. if (scale.AgentData.SessionID != SessionId || scale.AgentData.AgentID != AgentId)
  8073. return;
  8074. for (int i = 0; i < scale.ObjectData.Length; i++)
  8075. OnUpdatePrimGroupScale?.Invoke(scale.ObjectData[i].ObjectLocalID, scale.ObjectData[i].Scale, this);
  8076. }
  8077. private void HandleObjectRotation(Packet Pack)
  8078. {
  8079. if (OnUpdatePrimGroupRotation == null)
  8080. return;
  8081. // DEPRECATED: but till libsecondlife removes it, people will use it
  8082. ObjectRotationPacket rotation = (ObjectRotationPacket)Pack;
  8083. if (rotation.AgentData.SessionID != SessionId || rotation.AgentData.AgentID != AgentId)
  8084. return;
  8085. for (int i = 0; i < rotation.ObjectData.Length; i++)
  8086. OnUpdatePrimGroupRotation?.Invoke(rotation.ObjectData[i].ObjectLocalID, rotation.ObjectData[i].Rotation, this);
  8087. }
  8088. private void HandleObjectFlagUpdate(Packet Pack)
  8089. {
  8090. if(OnUpdatePrimFlags == null)
  8091. return;
  8092. ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
  8093. if (flags.AgentData.SessionID != SessionId || flags.AgentData.AgentID != AgentId)
  8094. return;
  8095. // byte[] data = Pack.ToBytes();
  8096. // 46,47,48 are special positions within the packet
  8097. // This may change so perhaps we need a better way
  8098. // of storing this (OMV.FlagUpdatePacket.UsePhysics,etc?)
  8099. /*
  8100. bool UsePhysics = (data[46] != 0) ? true : false;
  8101. bool IsTemporary = (data[47] != 0) ? true : false;
  8102. bool IsPhantom = (data[48] != 0) ? true : false;
  8103. handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, this);
  8104. */
  8105. bool UsePhysics = flags.AgentData.UsePhysics;
  8106. bool IsPhantom = flags.AgentData.IsPhantom;
  8107. bool IsTemporary = flags.AgentData.IsTemporary;
  8108. ObjectFlagUpdatePacket.ExtraPhysicsBlock[] blocks = flags.ExtraPhysics;
  8109. ExtraPhysicsData physdata = new ExtraPhysicsData();
  8110. if (blocks == null || blocks.Length == 0)
  8111. {
  8112. physdata.PhysShapeType = PhysShapeType.invalid;
  8113. }
  8114. else
  8115. {
  8116. ObjectFlagUpdatePacket.ExtraPhysicsBlock phsblock = blocks[0];
  8117. physdata.PhysShapeType = (PhysShapeType)phsblock.PhysicsShapeType;
  8118. physdata.Bounce = phsblock.Restitution;
  8119. physdata.Density = phsblock.Density;
  8120. physdata.Friction = phsblock.Friction;
  8121. physdata.GravitationModifier = phsblock.GravityMultiplier;
  8122. }
  8123. OnUpdatePrimFlags?.Invoke(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, physdata, this);
  8124. }
  8125. Dictionary<uint, uint> objImageSeqs = null;
  8126. double lastobjImageSeqsMS = 0.0;
  8127. private void HandleObjectImage(Packet Pack)
  8128. {
  8129. if (OnUpdatePrimTexture == null)
  8130. return;
  8131. ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
  8132. if (imagePack.AgentData.SessionID != SessionId || imagePack.AgentData.AgentID != AgentId)
  8133. return;
  8134. double now = Util.GetTimeStampMS();
  8135. if(objImageSeqs == null || ( now - lastobjImageSeqsMS > 30000.0))
  8136. {
  8137. objImageSeqs = null; // yeah i know superstition...
  8138. objImageSeqs = new Dictionary<uint, uint>(16);
  8139. }
  8140. lastobjImageSeqsMS = now;
  8141. uint seq = Pack.Header.Sequence;
  8142. uint id;
  8143. uint lastseq;
  8144. ObjectImagePacket.ObjectDataBlock o;
  8145. for (int i = 0; i < imagePack.ObjectData.Length; i++)
  8146. {
  8147. o = imagePack.ObjectData[i];
  8148. id = o.ObjectLocalID;
  8149. if(objImageSeqs.TryGetValue(id, out lastseq))
  8150. {
  8151. if(seq <= lastseq)
  8152. continue;
  8153. }
  8154. objImageSeqs[id] = seq;
  8155. OnUpdatePrimTexture?.Invoke(id, o.TextureEntry, this);
  8156. }
  8157. }
  8158. private void HandleObjectGrab(Packet Pack)
  8159. {
  8160. if(OnGrabObject == null)
  8161. return;
  8162. ObjectGrabPacket grab = (ObjectGrabPacket)Pack;
  8163. if (grab.AgentData.SessionID != SessionId || grab.AgentData.AgentID != AgentId)
  8164. return;
  8165. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  8166. if ((grab.SurfaceInfo != null) && (grab.SurfaceInfo.Length > 0))
  8167. {
  8168. foreach (ObjectGrabPacket.SurfaceInfoBlock surfaceInfo in grab.SurfaceInfo)
  8169. {
  8170. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  8171. arg.Binormal = surfaceInfo.Binormal;
  8172. arg.FaceIndex = surfaceInfo.FaceIndex;
  8173. arg.Normal = surfaceInfo.Normal;
  8174. arg.Position = surfaceInfo.Position;
  8175. arg.STCoord = surfaceInfo.STCoord;
  8176. arg.UVCoord = surfaceInfo.UVCoord;
  8177. touchArgs.Add(arg);
  8178. }
  8179. }
  8180. OnGrabObject?.Invoke(grab.ObjectData.LocalID, grab.ObjectData.GrabOffset, this, touchArgs);
  8181. }
  8182. private void HandleObjectGrabUpdate(Packet Pack)
  8183. {
  8184. if (OnGrabUpdate == null)
  8185. return;
  8186. ObjectGrabUpdatePacket grabUpdate = (ObjectGrabUpdatePacket)Pack;
  8187. if (grabUpdate.AgentData.SessionID != SessionId || grabUpdate.AgentData.AgentID != AgentId)
  8188. return;
  8189. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  8190. if ((grabUpdate.SurfaceInfo != null) && (grabUpdate.SurfaceInfo.Length > 0))
  8191. {
  8192. foreach (ObjectGrabUpdatePacket.SurfaceInfoBlock surfaceInfo in grabUpdate.SurfaceInfo)
  8193. {
  8194. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  8195. arg.Binormal = surfaceInfo.Binormal;
  8196. arg.FaceIndex = surfaceInfo.FaceIndex;
  8197. arg.Normal = surfaceInfo.Normal;
  8198. arg.Position = surfaceInfo.Position;
  8199. arg.STCoord = surfaceInfo.STCoord;
  8200. arg.UVCoord = surfaceInfo.UVCoord;
  8201. touchArgs.Add(arg);
  8202. }
  8203. }
  8204. OnGrabUpdate?.Invoke(grabUpdate.ObjectData.ObjectID, grabUpdate.ObjectData.GrabOffsetInitial,
  8205. grabUpdate.ObjectData.GrabPosition, this, touchArgs);
  8206. }
  8207. private void HandleObjectDeGrab(Packet Pack)
  8208. {
  8209. if (OnDeGrabObject == null)
  8210. return;
  8211. ObjectDeGrabPacket deGrab = (ObjectDeGrabPacket)Pack;
  8212. if (deGrab.AgentData.SessionID != SessionId || deGrab.AgentData.AgentID != AgentId)
  8213. return;
  8214. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  8215. if ((deGrab.SurfaceInfo != null) && (deGrab.SurfaceInfo.Length > 0))
  8216. {
  8217. foreach (ObjectDeGrabPacket.SurfaceInfoBlock surfaceInfo in deGrab.SurfaceInfo)
  8218. {
  8219. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  8220. arg.Binormal = surfaceInfo.Binormal;
  8221. arg.FaceIndex = surfaceInfo.FaceIndex;
  8222. arg.Normal = surfaceInfo.Normal;
  8223. arg.Position = surfaceInfo.Position;
  8224. arg.STCoord = surfaceInfo.STCoord;
  8225. arg.UVCoord = surfaceInfo.UVCoord;
  8226. touchArgs.Add(arg);
  8227. }
  8228. }
  8229. OnDeGrabObject?.Invoke(deGrab.ObjectData.LocalID, this, touchArgs);
  8230. }
  8231. private void HandleObjectSpinStart(Packet Pack)
  8232. {
  8233. //m_log.Warn("[CLIENT]: unhandled ObjectSpinStart packet");
  8234. ObjectSpinStartPacket spinStart = (ObjectSpinStartPacket)Pack;
  8235. if (spinStart.AgentData.SessionID != SessionId || spinStart.AgentData.AgentID != AgentId)
  8236. return;
  8237. OnSpinStart?.Invoke(spinStart.ObjectData.ObjectID, this);
  8238. }
  8239. private void HandleObjectSpinUpdate(Packet Pack)
  8240. {
  8241. //m_log.Warn("[CLIENT]: unhandled ObjectSpinUpdate packet");
  8242. ObjectSpinUpdatePacket spinUpdate = (ObjectSpinUpdatePacket)Pack;
  8243. if (spinUpdate.AgentData.SessionID != SessionId || spinUpdate.AgentData.AgentID != AgentId)
  8244. return;
  8245. Vector3 axis;
  8246. float angle;
  8247. spinUpdate.ObjectData.Rotation.GetAxisAngle(out axis, out angle);
  8248. //m_log.Warn("[CLIENT]: ObjectSpinUpdate packet rot axis:" + axis + " angle:" + angle);
  8249. OnSpinUpdate?.Invoke(spinUpdate.ObjectData.ObjectID, spinUpdate.ObjectData.Rotation, this);
  8250. }
  8251. private void HandleObjectSpinStop(Packet Pack)
  8252. {
  8253. //m_log.Warn("[CLIENT]: unhandled ObjectSpinStop packet");
  8254. ObjectSpinStopPacket spinStop = (ObjectSpinStopPacket)Pack;
  8255. if (spinStop.AgentData.SessionID != SessionId || spinStop.AgentData.AgentID != AgentId)
  8256. return;
  8257. OnSpinStop?.Invoke(spinStop.ObjectData.ObjectID, this);
  8258. }
  8259. private void HandleObjectDescription(Packet Pack)
  8260. {
  8261. if(OnObjectDescription == null)
  8262. return;
  8263. ObjectDescriptionPacket objDes = (ObjectDescriptionPacket)Pack;
  8264. if (objDes.AgentData.SessionID != SessionId || objDes.AgentData.AgentID != AgentId)
  8265. return;
  8266. for (int i = 0; i < objDes.ObjectData.Length; i++)
  8267. OnObjectDescription?.Invoke(this, objDes.ObjectData[i].LocalID,
  8268. Util.FieldToString(objDes.ObjectData[i].Description));
  8269. }
  8270. private void HandleObjectName(Packet Pack)
  8271. {
  8272. if(OnObjectName == null)
  8273. return;
  8274. ObjectNamePacket objName = (ObjectNamePacket)Pack;
  8275. if (objName.AgentData.SessionID != SessionId || objName.AgentData.AgentID != AgentId)
  8276. return;
  8277. for (int i = 0; i < objName.ObjectData.Length; i++)
  8278. OnObjectName?.Invoke(this, objName.ObjectData[i].LocalID,
  8279. Util.FieldToString(objName.ObjectData[i].Name));
  8280. }
  8281. private void HandleObjectPermissions(Packet Pack)
  8282. {
  8283. if (OnObjectPermissions == null)
  8284. return;
  8285. ObjectPermissionsPacket newobjPerms = (ObjectPermissionsPacket)Pack;
  8286. UUID SessionID = newobjPerms.AgentData.SessionID;
  8287. if (SessionID != SessionId)
  8288. return;
  8289. UUID AgentID = newobjPerms.AgentData.AgentID;
  8290. if(AgentID != AgentId)
  8291. return;
  8292. for (int i = 0; i < newobjPerms.ObjectData.Length; i++)
  8293. {
  8294. ObjectPermissionsPacket.ObjectDataBlock permChanges = newobjPerms.ObjectData[i];
  8295. byte field = permChanges.Field;
  8296. uint localID = permChanges.ObjectLocalID;
  8297. uint mask = permChanges.Mask;
  8298. byte set = permChanges.Set;
  8299. OnObjectPermissions?.Invoke(this, AgentID, SessionID, field, localID, mask, set);
  8300. }
  8301. // Here's our data,
  8302. // PermField contains the field the info goes into
  8303. // PermField determines which mask we're changing
  8304. //
  8305. // chmask is the mask of the change
  8306. // setTF is whether we're adding it or taking it away
  8307. //
  8308. // objLocalID is the localID of the object.
  8309. // Unfortunately, we have to pass the event the packet because objData is an array
  8310. // That means multiple object perms may be updated in a single packet.
  8311. }
  8312. private void HandleUndo(Packet Pack)
  8313. {
  8314. if(OnUndo == null)
  8315. return;
  8316. UndoPacket undoitem = (UndoPacket)Pack;
  8317. if (undoitem.AgentData.SessionID != SessionId || undoitem.AgentData.AgentID != AgentId)
  8318. return;
  8319. for (int i = 0; i < undoitem.ObjectData.Length; i++)
  8320. OnUndo?.Invoke(this, undoitem.ObjectData[i].ObjectID);
  8321. }
  8322. private void HandleLandUndo(Packet Pack)
  8323. {
  8324. UndoLandPacket undolanditem = (UndoLandPacket)Pack;
  8325. if (undolanditem.AgentData.SessionID != SessionId || undolanditem.AgentData.AgentID != AgentId)
  8326. return;
  8327. OnLandUndo?.Invoke(this);
  8328. }
  8329. private void HandleRedo(Packet Pack)
  8330. {
  8331. if(OnRedo == null)
  8332. return;
  8333. RedoPacket redoitem = (RedoPacket)Pack;
  8334. if (redoitem.AgentData.SessionID != SessionId || redoitem.AgentData.AgentID != AgentId)
  8335. return;
  8336. for (int i = 0; i < redoitem.ObjectData.Length; i++)
  8337. OnRedo?.Invoke(this, redoitem.ObjectData[i].ObjectID);
  8338. }
  8339. private void HandleObjectDuplicateOnRay(Packet Pack)
  8340. {
  8341. if(OnObjectDuplicateOnRay == null)
  8342. return;
  8343. ObjectDuplicateOnRayPacket dupeOnRay = (ObjectDuplicateOnRayPacket)Pack;
  8344. if (dupeOnRay.AgentData.SessionID != SessionId || dupeOnRay.AgentData.AgentID != AgentId)
  8345. return;
  8346. for (int i = 0; i < dupeOnRay.ObjectData.Length; i++)
  8347. {
  8348. UUID rezGroupID = dupeOnRay.AgentData.GroupID;
  8349. if(!IsGroupMember(rezGroupID))
  8350. rezGroupID = UUID.Zero;
  8351. OnObjectDuplicateOnRay?.Invoke(dupeOnRay.ObjectData[i].ObjectLocalID,
  8352. dupeOnRay.AgentData.DuplicateFlags, AgentId, rezGroupID,
  8353. dupeOnRay.AgentData.RayTargetID, dupeOnRay.AgentData.RayEnd,
  8354. dupeOnRay.AgentData.RayStart, dupeOnRay.AgentData.BypassRaycast,
  8355. dupeOnRay.AgentData.RayEndIsIntersection,
  8356. dupeOnRay.AgentData.CopyCenters, dupeOnRay.AgentData.CopyRotates);
  8357. }
  8358. }
  8359. private void HandleRequestObjectPropertiesFamily(Packet Pack)
  8360. {
  8361. //This powers the little tooltip that appears when you move your mouse over an object
  8362. RequestObjectPropertiesFamilyPacket packToolTip = (RequestObjectPropertiesFamilyPacket)Pack;
  8363. if (packToolTip.AgentData.SessionID != SessionId || packToolTip.AgentData.AgentID != AgentId)
  8364. return;
  8365. RequestObjectPropertiesFamilyPacket.ObjectDataBlock packObjBlock = packToolTip.ObjectData;
  8366. OnRequestObjectPropertiesFamily?.Invoke(this, m_agentId, packObjBlock.RequestFlags,
  8367. packObjBlock.ObjectID);
  8368. }
  8369. private void HandleObjectIncludeInSearch(Packet Pack)
  8370. {
  8371. if(OnObjectIncludeInSearch == null)
  8372. return;
  8373. //This lets us set objects to appear in search (stuff like DataSnapshot, etc)
  8374. ObjectIncludeInSearchPacket packInSearch = (ObjectIncludeInSearchPacket)Pack;
  8375. if (packInSearch.AgentData.SessionID != SessionId || packInSearch.AgentData.AgentID != AgentId)
  8376. return;
  8377. foreach (ObjectIncludeInSearchPacket.ObjectDataBlock objData in packInSearch.ObjectData)
  8378. {
  8379. bool inSearch = objData.IncludeInSearch;
  8380. uint localID = objData.ObjectLocalID;
  8381. OnObjectIncludeInSearch?.Invoke(this, inSearch, localID);
  8382. }
  8383. }
  8384. private void HandleScriptAnswerYes(Packet Pack)
  8385. {
  8386. ScriptAnswerYesPacket scriptAnswer = (ScriptAnswerYesPacket)Pack;
  8387. if (scriptAnswer.AgentData.SessionID != SessionId || scriptAnswer.AgentData.AgentID != AgentId)
  8388. return;
  8389. OnScriptAnswer?.Invoke(this, scriptAnswer.Data.TaskID, scriptAnswer.Data.ItemID, scriptAnswer.Data.Questions);
  8390. }
  8391. private void HandleObjectClickAction(Packet Pack)
  8392. {
  8393. if(OnObjectClickAction == null)
  8394. return;
  8395. ObjectClickActionPacket ocpacket = (ObjectClickActionPacket)Pack;
  8396. if (ocpacket.AgentData.SessionID != SessionId || ocpacket.AgentData.AgentID != AgentId)
  8397. return;
  8398. foreach (ObjectClickActionPacket.ObjectDataBlock odata in ocpacket.ObjectData)
  8399. {
  8400. byte action = odata.ClickAction;
  8401. uint localID = odata.ObjectLocalID;
  8402. OnObjectClickAction?.Invoke(this, localID, action.ToString());
  8403. }
  8404. }
  8405. private void HandleObjectMaterial(Packet Pack)
  8406. {
  8407. if(OnObjectMaterial == null)
  8408. return;
  8409. ObjectMaterialPacket ompacket = (ObjectMaterialPacket)Pack;
  8410. if (ompacket.AgentData.SessionID != SessionId || ompacket.AgentData.AgentID != AgentId)
  8411. return;
  8412. foreach (ObjectMaterialPacket.ObjectDataBlock odata in ompacket.ObjectData)
  8413. {
  8414. byte material = odata.Material;
  8415. uint localID = odata.ObjectLocalID;
  8416. OnObjectMaterial?.Invoke(this, localID, material.ToString());
  8417. }
  8418. }
  8419. #endregion Objects/m_sceneObjects
  8420. #region Inventory/Asset/Other related packets
  8421. private void HandleRequestImage(Packet Pack)
  8422. {
  8423. RequestImagePacket imageRequest = (RequestImagePacket)Pack;
  8424. if (imageRequest.AgentData.SessionID != SessionId || imageRequest.AgentData.AgentID != AgentId)
  8425. return;
  8426. //handlerTextureRequest = null;
  8427. for (int i = 0; i < imageRequest.RequestImage.Length; i++)
  8428. {
  8429. TextureRequestArgs args = new TextureRequestArgs();
  8430. RequestImagePacket.RequestImageBlock block = imageRequest.RequestImage[i];
  8431. args.RequestedAssetID = block.Image;
  8432. args.DiscardLevel = block.DiscardLevel;
  8433. args.PacketNumber = block.Packet;
  8434. args.Priority = block.DownloadPriority;
  8435. args.requestSequence = imageRequest.Header.Sequence;
  8436. // NOTE: This is not a built in part of the LLUDP protocol, but we double the
  8437. // priority of avatar textures to get avatars rezzing in faster than the
  8438. // surrounding scene
  8439. if ((ImageType)block.Type == ImageType.Baked)
  8440. args.Priority *= 2.0f;
  8441. ImageManager.EnqueueReq(args);
  8442. }
  8443. }
  8444. /// <summary>
  8445. /// This is the entry point for the UDP route by which the client can retrieve asset data. If the request
  8446. /// is successful then a TransferInfo packet will be sent back, followed by one or more TransferPackets
  8447. /// </summary>
  8448. /// <param name="sender"></param>
  8449. /// <param name="Pack"></param>
  8450. /// <returns>This parameter may be ignored since we appear to return true whatever happens</returns>
  8451. private void HandleTransferRequest(Packet Pack)
  8452. {
  8453. //m_log.Debug("ClientView.ProcessPackets.cs:ProcessInPacket() - Got transfer request");
  8454. TransferRequestPacket transfer = (TransferRequestPacket)Pack;
  8455. UUID taskID = UUID.Zero;
  8456. if (transfer.TransferInfo.SourceType == (int)SourceType.SimInventoryItem)
  8457. {
  8458. if (!(((Scene)m_scene).Permissions.BypassPermissions()))
  8459. {
  8460. // We're spawning a thread because the permissions check can block this thread
  8461. Util.FireAndForget(delegate
  8462. {
  8463. // This requests the asset if needed
  8464. HandleSimInventoryTransferRequestWithPermsCheck(this, transfer);
  8465. }, null, "LLClientView.HandleTransferRequest");
  8466. return;
  8467. }
  8468. }
  8469. else if (transfer.TransferInfo.SourceType == (int)SourceType.SimEstate)
  8470. {
  8471. //TransferRequestPacket does not include covenant uuid?
  8472. //get scene covenant uuid
  8473. taskID = m_scene.RegionInfo.RegionSettings.Covenant;
  8474. }
  8475. // This is non-blocking
  8476. MakeAssetRequest(transfer, taskID);
  8477. }
  8478. private void HandleSimInventoryTransferRequestWithPermsCheck(IClientAPI sender, TransferRequestPacket transfer)
  8479. {
  8480. UUID taskID = new UUID(transfer.TransferInfo.Params, 48);
  8481. UUID itemID = new UUID(transfer.TransferInfo.Params, 64);
  8482. UUID requestID = new UUID(transfer.TransferInfo.Params, 80);
  8483. //m_log.DebugFormat(
  8484. // "[CLIENT]: Got request for asset {0} from item {1} in prim {2} by {3}",
  8485. // requestID, itemID, taskID, Name);
  8486. //m_log.Debug("Transfer Request: " + transfer.ToString());
  8487. // Validate inventory transfers
  8488. // Has to be done here, because AssetCache can't do it
  8489. //
  8490. if (taskID != UUID.Zero) // Prim
  8491. {
  8492. SceneObjectPart part = ((Scene)m_scene).GetSceneObjectPart(taskID);
  8493. if (part == null)
  8494. {
  8495. m_log.WarnFormat(
  8496. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but prim does not exist",
  8497. Name, requestID, itemID, taskID);
  8498. return;
  8499. }
  8500. TaskInventoryItem tii = part.Inventory.GetInventoryItem(itemID);
  8501. if (tii == null)
  8502. {
  8503. m_log.WarnFormat(
  8504. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but item does not exist",
  8505. Name, requestID, itemID, taskID);
  8506. return;
  8507. }
  8508. if (tii.Type == (int)AssetType.LSLText)
  8509. {
  8510. if (!((Scene)m_scene).Permissions.CanEditScript(itemID, taskID, AgentId))
  8511. return;
  8512. }
  8513. else if (tii.Type == (int)AssetType.Notecard)
  8514. {
  8515. if (!((Scene)m_scene).Permissions.CanEditNotecard(itemID, taskID, AgentId))
  8516. return;
  8517. }
  8518. else
  8519. {
  8520. // TODO: Change this code to allow items other than notecards and scripts to be successfully
  8521. // shared with group. In fact, this whole block of permissions checking should move to an IPermissionsModule
  8522. if (part.OwnerID != AgentId)
  8523. {
  8524. m_log.WarnFormat(
  8525. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but the prim is owned by {4}",
  8526. Name, requestID, itemID, taskID, part.OwnerID);
  8527. return;
  8528. }
  8529. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  8530. {
  8531. m_log.WarnFormat(
  8532. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but modify permissions are not set",
  8533. Name, requestID, itemID, taskID);
  8534. return;
  8535. }
  8536. if (tii.OwnerID != AgentId)
  8537. {
  8538. m_log.WarnFormat(
  8539. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but the item is owned by {4}",
  8540. Name, requestID, itemID, taskID, tii.OwnerID);
  8541. return;
  8542. }
  8543. if ((
  8544. tii.CurrentPermissions & ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy | (uint)PermissionMask.Transfer))
  8545. != ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy | (uint)PermissionMask.Transfer))
  8546. {
  8547. m_log.WarnFormat(
  8548. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but item permissions are not modify/copy/transfer",
  8549. Name, requestID, itemID, taskID);
  8550. return;
  8551. }
  8552. if (tii.AssetID != requestID)
  8553. {
  8554. m_log.WarnFormat(
  8555. "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but this does not match item's asset {4}",
  8556. Name, requestID, itemID, taskID, tii.AssetID);
  8557. return;
  8558. }
  8559. }
  8560. }
  8561. else // Agent
  8562. {
  8563. IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
  8564. if (invAccess != null)
  8565. {
  8566. if (!invAccess.CanGetAgentInventoryItem(this, itemID, requestID))
  8567. return;
  8568. }
  8569. else
  8570. {
  8571. return;
  8572. }
  8573. }
  8574. // Permissions out of the way, let's request the asset
  8575. MakeAssetRequest(transfer, taskID);
  8576. }
  8577. private void HandleAssetUploadRequest(Packet Pack)
  8578. {
  8579. AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
  8580. // m_log.Debug("upload request " + request.ToString());
  8581. // m_log.Debug("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToString());
  8582. UUID temp = UUID.Combine(request.AssetBlock.TransactionID, SecureSessionId);
  8583. OnAssetUploadRequest?.Invoke(this, temp,
  8584. request.AssetBlock.TransactionID, request.AssetBlock.Type,
  8585. request.AssetBlock.AssetData, request.AssetBlock.StoreLocal,
  8586. request.AssetBlock.Tempfile);
  8587. }
  8588. private void HandleRequestXfer(Packet Pack)
  8589. {
  8590. RequestXferPacket xferReq = (RequestXferPacket)Pack;
  8591. OnRequestXfer?.Invoke(this, xferReq.XferID.ID, Util.FieldToString(xferReq.XferID.Filename));
  8592. }
  8593. private void HandleSendXferPacket(Packet Pack)
  8594. {
  8595. SendXferPacketPacket xferRec = (SendXferPacketPacket)Pack;
  8596. OnXferReceive?.Invoke(this, xferRec.XferID.ID, xferRec.XferID.Packet, xferRec.DataPacket.Data);
  8597. }
  8598. private void HandleConfirmXferPacket(Packet Pack)
  8599. {
  8600. ConfirmXferPacketPacket confirmXfer = (ConfirmXferPacketPacket)Pack;
  8601. OnConfirmXfer?.Invoke(this, confirmXfer.XferID.ID, confirmXfer.XferID.Packet);
  8602. }
  8603. private void HandleAbortXfer(Packet Pack)
  8604. {
  8605. AbortXferPacket abortXfer = (AbortXferPacket)Pack;
  8606. OnAbortXfer?.Invoke(this, abortXfer.XferID.ID);
  8607. }
  8608. private void HandleCreateInventoryFolder(Packet Pack)
  8609. {
  8610. CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack;
  8611. if (invFolder.AgentData.SessionID != SessionId || invFolder.AgentData.AgentID != AgentId)
  8612. return;
  8613. OnCreateNewInventoryFolder?.Invoke(this, invFolder.FolderData.FolderID,
  8614. (ushort)invFolder.FolderData.Type,
  8615. Util.FieldToString(invFolder.FolderData.Name),
  8616. invFolder.FolderData.ParentID);
  8617. }
  8618. private void HandleUpdateInventoryFolder(Packet Pack)
  8619. {
  8620. if (OnUpdateInventoryFolder == null)
  8621. return;
  8622. UpdateInventoryFolderPacket invFolderx = (UpdateInventoryFolderPacket)Pack;
  8623. if (invFolderx.AgentData.SessionID != SessionId || invFolderx.AgentData.AgentID != AgentId)
  8624. return;
  8625. for (int i = 0; i < invFolderx.FolderData.Length; i++)
  8626. {
  8627. OnUpdateInventoryFolder?.Invoke(this, invFolderx.FolderData[i].FolderID,
  8628. (ushort)invFolderx.FolderData[i].Type,
  8629. Util.FieldToString(invFolderx.FolderData[i].Name),
  8630. invFolderx.FolderData[i].ParentID);
  8631. }
  8632. }
  8633. private void HandleMoveInventoryFolder(Packet Pack)
  8634. {
  8635. if (OnMoveInventoryFolder == null)
  8636. return;
  8637. MoveInventoryFolderPacket invFoldery = (MoveInventoryFolderPacket)Pack;
  8638. if (invFoldery.AgentData.SessionID != SessionId || invFoldery.AgentData.AgentID != AgentId)
  8639. return;
  8640. for (int i = 0; i < invFoldery.InventoryData.Length; i++)
  8641. {
  8642. OnMoveInventoryFolder?.Invoke(this, invFoldery.InventoryData[i].FolderID,
  8643. invFoldery.InventoryData[i].ParentID);
  8644. }
  8645. }
  8646. private void HandleCreateInventoryItem(Packet Pack)
  8647. {
  8648. CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack;
  8649. if (createItem.AgentData.SessionID != SessionId || createItem.AgentData.AgentID != AgentId)
  8650. return;
  8651. OnCreateNewInventoryItem?.Invoke(this, createItem.InventoryBlock.TransactionID,
  8652. createItem.InventoryBlock.FolderID,
  8653. createItem.InventoryBlock.CallbackID,
  8654. Util.FieldToString(createItem.InventoryBlock.Description),
  8655. Util.FieldToString(createItem.InventoryBlock.Name),
  8656. createItem.InventoryBlock.InvType,
  8657. createItem.InventoryBlock.Type,
  8658. createItem.InventoryBlock.WearableType,
  8659. createItem.InventoryBlock.NextOwnerMask,
  8660. Util.UnixTimeSinceEpoch());
  8661. }
  8662. private void HandleLinkInventoryItem(Packet Pack)
  8663. {
  8664. LinkInventoryItemPacket createLink = (LinkInventoryItemPacket)Pack;
  8665. if (createLink.AgentData.SessionID != SessionId || createLink.AgentData.AgentID != AgentId)
  8666. return;
  8667. OnLinkInventoryItem?.Invoke(
  8668. this,
  8669. createLink.InventoryBlock.TransactionID,
  8670. createLink.InventoryBlock.FolderID,
  8671. createLink.InventoryBlock.CallbackID,
  8672. Util.FieldToString(createLink.InventoryBlock.Description),
  8673. Util.FieldToString(createLink.InventoryBlock.Name),
  8674. createLink.InventoryBlock.InvType,
  8675. createLink.InventoryBlock.Type,
  8676. createLink.InventoryBlock.OldItemID);
  8677. }
  8678. private void HandleFetchInventory(Packet Pack)
  8679. {
  8680. if (OnFetchInventory == null)
  8681. return;
  8682. FetchInventoryPacket FetchInventoryx = (FetchInventoryPacket)Pack;
  8683. if (FetchInventoryx.AgentData.SessionID != SessionId || FetchInventoryx.AgentData.AgentID != AgentId)
  8684. return;
  8685. FetchInventoryPacket.InventoryDataBlock[] data = FetchInventoryx.InventoryData;
  8686. UUID[] items = new UUID[data.Length];
  8687. UUID[] owners = new UUID[data.Length];
  8688. for (int i = 0; i < data.Length; ++i)
  8689. {
  8690. items[i] =data[i].ItemID;
  8691. owners[i] = data[i].OwnerID;
  8692. }
  8693. OnFetchInventory?.Invoke(this, items, owners);
  8694. }
  8695. private void HandleFetchInventoryDescendents(Packet Pack)
  8696. {
  8697. FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack;
  8698. if (Fetch.AgentData.SessionID != SessionId || Fetch.AgentData.AgentID != AgentId)
  8699. return;
  8700. FetchInventoryDescendentsPacket.InventoryDataBlock data = Fetch.InventoryData;
  8701. OnFetchInventoryDescendents?.Invoke(this, data.FolderID, data.OwnerID,
  8702. data.FetchFolders, data.FetchItems,
  8703. data.SortOrder);
  8704. }
  8705. private void HandlePurgeInventoryDescendents(Packet Pack)
  8706. {
  8707. PurgeInventoryDescendentsPacket Purge = (PurgeInventoryDescendentsPacket)Pack;
  8708. if (Purge.AgentData.SessionID != SessionId || Purge.AgentData.AgentID != AgentId)
  8709. return;
  8710. OnPurgeInventoryDescendents?.Invoke(this, Purge.InventoryData.FolderID);
  8711. }
  8712. private void HandleUpdateInventoryItem(Packet Pack)
  8713. {
  8714. if (OnUpdateInventoryItem == null)
  8715. return;
  8716. UpdateInventoryItemPacket inventoryItemUpdate = (UpdateInventoryItemPacket)Pack;
  8717. if (inventoryItemUpdate.AgentData.SessionID != SessionId || inventoryItemUpdate.AgentData.AgentID != AgentId)
  8718. return;
  8719. for (int i = 0; i < inventoryItemUpdate.InventoryData.Length; i++)
  8720. {
  8721. InventoryItemBase itemUpd = new InventoryItemBase();
  8722. itemUpd.ID = inventoryItemUpdate.InventoryData[i].ItemID;
  8723. itemUpd.Name = Util.FieldToString(inventoryItemUpdate.InventoryData[i].Name);
  8724. itemUpd.Description = Util.FieldToString(inventoryItemUpdate.InventoryData[i].Description);
  8725. itemUpd.GroupID = inventoryItemUpdate.InventoryData[i].GroupID;
  8726. itemUpd.GroupOwned = inventoryItemUpdate.InventoryData[i].GroupOwned;
  8727. itemUpd.GroupPermissions = inventoryItemUpdate.InventoryData[i].GroupMask;
  8728. itemUpd.NextPermissions = inventoryItemUpdate.InventoryData[i].NextOwnerMask;
  8729. itemUpd.EveryOnePermissions = inventoryItemUpdate.InventoryData[i].EveryoneMask;
  8730. itemUpd.CreationDate = inventoryItemUpdate.InventoryData[i].CreationDate;
  8731. itemUpd.Folder = inventoryItemUpdate.InventoryData[i].FolderID;
  8732. itemUpd.InvType = inventoryItemUpdate.InventoryData[i].InvType;
  8733. itemUpd.SalePrice = inventoryItemUpdate.InventoryData[i].SalePrice;
  8734. itemUpd.SaleType = inventoryItemUpdate.InventoryData[i].SaleType;
  8735. itemUpd.Flags = inventoryItemUpdate.InventoryData[i].Flags;
  8736. OnUpdateInventoryItem?.Invoke(this, inventoryItemUpdate.InventoryData[i].TransactionID,
  8737. inventoryItemUpdate.InventoryData[i].ItemID,
  8738. itemUpd);
  8739. }
  8740. }
  8741. private void HandleCopyInventoryItem(Packet Pack)
  8742. {
  8743. if(OnCopyInventoryItem == null)
  8744. return;
  8745. CopyInventoryItemPacket copyitem = (CopyInventoryItemPacket)Pack;
  8746. if (copyitem.AgentData.SessionID != SessionId || copyitem.AgentData.AgentID != AgentId)
  8747. return;
  8748. foreach (CopyInventoryItemPacket.InventoryDataBlock datablock in copyitem.InventoryData)
  8749. {
  8750. OnCopyInventoryItem?.Invoke(this, datablock.CallbackID, datablock.OldAgentID,
  8751. datablock.OldItemID, datablock.NewFolderID,
  8752. Util.FieldToString(datablock.NewName));
  8753. }
  8754. }
  8755. private void HandleMoveInventoryItem(Packet Pack)
  8756. {
  8757. if (OnMoveInventoryItem == null)
  8758. return;
  8759. MoveInventoryItemPacket moveitem = (MoveInventoryItemPacket)Pack;
  8760. if (moveitem.AgentData.SessionID != SessionId || moveitem.AgentData.AgentID != AgentId)
  8761. return;
  8762. InventoryItemBase itm = null;
  8763. List<InventoryItemBase> items = new List<InventoryItemBase>();
  8764. foreach (MoveInventoryItemPacket.InventoryDataBlock datablock in moveitem.InventoryData)
  8765. {
  8766. itm = new InventoryItemBase(datablock.ItemID, AgentId);
  8767. itm.Folder = datablock.FolderID;
  8768. itm.Name = Util.FieldToString(datablock.NewName);
  8769. // weird, comes out as empty string
  8770. //m_log.DebugFormat("[XXX] new name: {0}", itm.Name);
  8771. items.Add(itm);
  8772. }
  8773. OnMoveInventoryItem?.Invoke(this, items);
  8774. }
  8775. private void HandleRemoveInventoryItem(Packet Pack)
  8776. {
  8777. if(OnRemoveInventoryItem == null)
  8778. return;
  8779. RemoveInventoryItemPacket removeItem = (RemoveInventoryItemPacket)Pack;
  8780. if (removeItem.AgentData.SessionID != SessionId || removeItem.AgentData.AgentID != AgentId)
  8781. return;
  8782. List<UUID> uuids = new List<UUID>();
  8783. foreach (RemoveInventoryItemPacket.InventoryDataBlock datablock in removeItem.InventoryData)
  8784. {
  8785. uuids.Add(datablock.ItemID);
  8786. }
  8787. OnRemoveInventoryItem?.Invoke(this, uuids);
  8788. }
  8789. private void HandleRemoveInventoryFolder(Packet Pack)
  8790. {
  8791. if (OnRemoveInventoryFolder == null)
  8792. return;
  8793. RemoveInventoryFolderPacket removeFolder = (RemoveInventoryFolderPacket)Pack;
  8794. if (removeFolder.AgentData.SessionID != SessionId || removeFolder.AgentData.AgentID != AgentId)
  8795. return;
  8796. List<UUID> uuids = new List<UUID>();
  8797. foreach (RemoveInventoryFolderPacket.FolderDataBlock datablock in removeFolder.FolderData)
  8798. {
  8799. uuids.Add(datablock.FolderID);
  8800. }
  8801. OnRemoveInventoryFolder?.Invoke(this, uuids);
  8802. }
  8803. private void HandleRemoveInventoryObjects(Packet Pack)
  8804. {
  8805. if (OnRemoveInventoryFolder == null || OnRemoveInventoryItem == null)
  8806. return;
  8807. RemoveInventoryObjectsPacket removeObject = (RemoveInventoryObjectsPacket)Pack;
  8808. if (removeObject.AgentData.SessionID != SessionId || removeObject.AgentData.AgentID != AgentId)
  8809. return;
  8810. List<UUID> uuids = new List<UUID>();
  8811. foreach (RemoveInventoryObjectsPacket.FolderDataBlock datablock in removeObject.FolderData)
  8812. uuids.Add(datablock.FolderID);
  8813. OnRemoveInventoryFolder?.Invoke(this, uuids);
  8814. uuids.Clear();
  8815. foreach (RemoveInventoryObjectsPacket.ItemDataBlock datablock in removeObject.ItemData)
  8816. uuids.Add(datablock.ItemID);
  8817. OnRemoveInventoryItem?.Invoke(this, uuids);
  8818. }
  8819. private void HandleRequestTaskInventory(Packet Pack)
  8820. {
  8821. RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
  8822. if (requesttask.AgentData.SessionID != SessionId || requesttask.AgentData.AgentID != AgentId)
  8823. return;
  8824. OnRequestTaskInventory?.Invoke(this, requesttask.InventoryData.LocalID);
  8825. }
  8826. private void HandleUpdateTaskInventory(Packet Pack)
  8827. {
  8828. if (OnUpdateTaskInventory == null)
  8829. return;
  8830. UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
  8831. if (updatetask.UpdateData.Key != 0)
  8832. return; // only do inventory not assets
  8833. if (updatetask.AgentData.SessionID != SessionId || updatetask.AgentData.AgentID != AgentId)
  8834. return;
  8835. TaskInventoryItem newTaskItem = new TaskInventoryItem();
  8836. newTaskItem.ItemID = updatetask.InventoryData.ItemID;
  8837. newTaskItem.ParentID = updatetask.InventoryData.FolderID;
  8838. newTaskItem.CreatorID = updatetask.InventoryData.CreatorID;
  8839. newTaskItem.OwnerID = updatetask.InventoryData.OwnerID;
  8840. newTaskItem.GroupID = updatetask.InventoryData.GroupID;
  8841. newTaskItem.BasePermissions = updatetask.InventoryData.BaseMask;
  8842. newTaskItem.CurrentPermissions = updatetask.InventoryData.OwnerMask;
  8843. newTaskItem.GroupPermissions = updatetask.InventoryData.GroupMask;
  8844. newTaskItem.EveryonePermissions = updatetask.InventoryData.EveryoneMask;
  8845. newTaskItem.NextPermissions = updatetask.InventoryData.NextOwnerMask;
  8846. // Unused? Clicking share with group sets GroupPermissions instead, so perhaps this is something
  8847. // different
  8848. //newTaskItem.GroupOwned=updatetask.InventoryData.GroupOwned;
  8849. newTaskItem.Type = updatetask.InventoryData.Type;
  8850. newTaskItem.InvType = updatetask.InventoryData.InvType;
  8851. newTaskItem.Flags = updatetask.InventoryData.Flags;
  8852. //newTaskItem.SaleType=updatetask.InventoryData.SaleType;
  8853. //newTaskItem.SalePrice=updatetask.InventoryData.SalePrice;
  8854. newTaskItem.Name = Util.FieldToString(updatetask.InventoryData.Name);
  8855. newTaskItem.Description = Util.FieldToString(updatetask.InventoryData.Description);
  8856. newTaskItem.CreationDate = (uint)updatetask.InventoryData.CreationDate;
  8857. OnUpdateTaskInventory?.Invoke(this, updatetask.InventoryData.TransactionID,
  8858. newTaskItem, updatetask.UpdateData.LocalID);
  8859. }
  8860. private void HandleRemoveTaskInventory(Packet Pack)
  8861. {
  8862. RemoveTaskInventoryPacket removeTask = (RemoveTaskInventoryPacket)Pack;
  8863. if (removeTask.AgentData.SessionID != SessionId || removeTask.AgentData.AgentID != AgentId)
  8864. return;
  8865. OnRemoveTaskItem?.Invoke(this, removeTask.InventoryData.ItemID, removeTask.InventoryData.LocalID);
  8866. }
  8867. private void HandleMoveTaskInventory(Packet Pack)
  8868. {
  8869. MoveTaskInventoryPacket moveTaskInventoryPacket = (MoveTaskInventoryPacket)Pack;
  8870. if (moveTaskInventoryPacket.AgentData.SessionID != SessionId || moveTaskInventoryPacket.AgentData.AgentID != AgentId)
  8871. return;
  8872. OnMoveTaskItem?.Invoke(
  8873. this, moveTaskInventoryPacket.AgentData.FolderID,
  8874. moveTaskInventoryPacket.InventoryData.LocalID,
  8875. moveTaskInventoryPacket.InventoryData.ItemID);
  8876. }
  8877. private void HandleRezScript(Packet Pack)
  8878. {
  8879. if(OnRezScript == null)
  8880. return;
  8881. //m_log.Debug(Pack.ToString());
  8882. RezScriptPacket rezScriptx = (RezScriptPacket)Pack;
  8883. if (rezScriptx.AgentData.SessionID != SessionId || rezScriptx.AgentData.AgentID != AgentId)
  8884. return;
  8885. InventoryItemBase item = new InventoryItemBase();
  8886. item.ID = rezScriptx.InventoryBlock.ItemID;
  8887. item.Folder = rezScriptx.InventoryBlock.FolderID;
  8888. item.CreatorId = rezScriptx.InventoryBlock.CreatorID.ToString();
  8889. item.Owner = rezScriptx.InventoryBlock.OwnerID;
  8890. item.BasePermissions = rezScriptx.InventoryBlock.BaseMask;
  8891. item.CurrentPermissions = rezScriptx.InventoryBlock.OwnerMask;
  8892. item.EveryOnePermissions = rezScriptx.InventoryBlock.EveryoneMask;
  8893. item.NextPermissions = rezScriptx.InventoryBlock.NextOwnerMask;
  8894. item.GroupPermissions = rezScriptx.InventoryBlock.GroupMask;
  8895. item.GroupOwned = rezScriptx.InventoryBlock.GroupOwned;
  8896. item.GroupID = rezScriptx.InventoryBlock.GroupID;
  8897. item.AssetType = rezScriptx.InventoryBlock.Type;
  8898. item.InvType = rezScriptx.InventoryBlock.InvType;
  8899. item.Flags = rezScriptx.InventoryBlock.Flags;
  8900. item.SaleType = rezScriptx.InventoryBlock.SaleType;
  8901. item.SalePrice = rezScriptx.InventoryBlock.SalePrice;
  8902. item.Name = Util.FieldToString(rezScriptx.InventoryBlock.Name);
  8903. item.Description = Util.FieldToString(rezScriptx.InventoryBlock.Description);
  8904. item.CreationDate = rezScriptx.InventoryBlock.CreationDate;
  8905. OnRezScript?.Invoke(this, item, rezScriptx.InventoryBlock.TransactionID, rezScriptx.UpdateBlock.ObjectLocalID);
  8906. }
  8907. private void HandleMapLayerRequest(Packet Pack)
  8908. {
  8909. RequestMapLayer();
  8910. }
  8911. private void HandleMapBlockRequest(Packet Pack)
  8912. {
  8913. MapBlockRequestPacket MapRequest = (MapBlockRequestPacket)Pack;
  8914. if (MapRequest.AgentData.SessionID != SessionId || MapRequest.AgentData.AgentID != AgentId)
  8915. return;
  8916. OnRequestMapBlocks?.Invoke(this, MapRequest.PositionData.MinX, MapRequest.PositionData.MinY,
  8917. MapRequest.PositionData.MaxX, MapRequest.PositionData.MaxY, MapRequest.AgentData.Flags);
  8918. }
  8919. private void HandleMapNameRequest(Packet Pack)
  8920. {
  8921. MapNameRequestPacket map = (MapNameRequestPacket)Pack;
  8922. if (map.AgentData.SessionID != SessionId || map.AgentData.AgentID != AgentId)
  8923. return;
  8924. string mapName = (map.NameData.Name.Length == 0) ? m_scene.RegionInfo.RegionName :
  8925. Util.UTF8.GetString(map.NameData.Name, 0, map.NameData.Name.Length - 1);
  8926. OnMapNameRequest?.Invoke(this, mapName, map.AgentData.Flags);
  8927. }
  8928. private void HandleTeleportLandmarkRequest(Packet Pack)
  8929. {
  8930. TeleportLandmarkRequestPacket tpReq = (TeleportLandmarkRequestPacket)Pack;
  8931. if (tpReq.Info.SessionID != SessionId || tpReq.Info.AgentID != AgentId)
  8932. return;
  8933. UUID lmid = tpReq.Info.LandmarkID;
  8934. AssetLandmark lm;
  8935. if (lmid != UUID.Zero)
  8936. {
  8937. //AssetBase lma = m_assetCache.GetAsset(lmid, false);
  8938. AssetBase lma = m_assetService.Get(lmid.ToString());
  8939. if (lma == null)
  8940. {
  8941. // Failed to find landmark
  8942. // Let's try to search in the user's home asset server
  8943. lma = FindAssetInUserAssetServer(lmid.ToString());
  8944. if (lma == null)
  8945. {
  8946. // Really doesn't exist
  8947. m_log.WarnFormat("[llClient]: landmark asset {0} not found",lmid.ToString());
  8948. SendTeleportFailed("Could not find the landmark asset data");
  8949. return;
  8950. }
  8951. }
  8952. try
  8953. {
  8954. lm = new AssetLandmark(lma);
  8955. }
  8956. catch (NullReferenceException)
  8957. {
  8958. // asset not found generates null ref inside the assetlandmark constructor.
  8959. SendTeleportFailed("Could not find the landmark asset data");
  8960. return;
  8961. }
  8962. }
  8963. else
  8964. {
  8965. // Teleport home request
  8966. OnTeleportHomeRequest?.Invoke(AgentId, this);
  8967. return;
  8968. }
  8969. OnTeleportLandmarkRequest?.Invoke(this, lm);
  8970. }
  8971. private void HandleTeleportCancel(Packet Pack)
  8972. {
  8973. TeleportCancelPacket pkt = (TeleportCancelPacket) Pack;
  8974. if(pkt.Info.AgentID != AgentId || pkt.Info.SessionID != SessionId)
  8975. return;
  8976. OnTeleportCancel?.Invoke(this);
  8977. }
  8978. private AssetBase FindAssetInUserAssetServer(string id)
  8979. {
  8980. AgentCircuitData aCircuit = ((Scene)Scene).AuthenticateHandler.GetAgentCircuitData(CircuitCode);
  8981. if (aCircuit != null && aCircuit.ServiceURLs != null && aCircuit.ServiceURLs.ContainsKey("AssetServerURI"))
  8982. {
  8983. string assetServer = aCircuit.ServiceURLs["AssetServerURI"].ToString();
  8984. if (!string.IsNullOrEmpty(assetServer))
  8985. return ((Scene)Scene).AssetService.Get(id, assetServer, false);
  8986. }
  8987. return null;
  8988. }
  8989. private void HandleTeleportLocationRequest(Packet Pack)
  8990. {
  8991. if(OnTeleportLocationRequest == null)
  8992. {
  8993. SendTeleportFailed("Could not process the teleport");
  8994. return;
  8995. }
  8996. TeleportLocationRequestPacket tpLocReq = (TeleportLocationRequestPacket)Pack;
  8997. if (tpLocReq.AgentData.SessionID != SessionId || tpLocReq.AgentData.AgentID != AgentId)
  8998. return;
  8999. // Adjust teleport location to base of a larger region if requested to teleport to a sub-region
  9000. uint locX, locY;
  9001. Util.RegionHandleToWorldLoc(tpLocReq.Info.RegionHandle, out locX, out locY);
  9002. if ((locX >= m_scene.RegionInfo.WorldLocX)
  9003. && (locX < (m_scene.RegionInfo.WorldLocX + m_scene.RegionInfo.RegionSizeX))
  9004. && (locY >= m_scene.RegionInfo.WorldLocY)
  9005. && (locY < (m_scene.RegionInfo.WorldLocY + m_scene.RegionInfo.RegionSizeY)))
  9006. {
  9007. tpLocReq.Info.RegionHandle = m_scene.RegionInfo.RegionHandle;
  9008. tpLocReq.Info.Position.X += locX - m_scene.RegionInfo.WorldLocX;
  9009. tpLocReq.Info.Position.Y += locY - m_scene.RegionInfo.WorldLocY;
  9010. }
  9011. OnTeleportLocationRequest?.Invoke(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position,
  9012. tpLocReq.Info.LookAt, 16);
  9013. }
  9014. #endregion Inventory/Asset/Other related packets
  9015. private void HandleUUIDNameRequest(Packet Pack)
  9016. {
  9017. if(OnNameFromUUIDRequest == null)
  9018. return;
  9019. ScenePresence sp = (ScenePresence)SceneAgent;
  9020. if(sp == null || sp.IsDeleted || (sp.IsInTransit && !sp.IsInLocalTransit))
  9021. return;
  9022. UUIDNameRequestPacket incoming = (UUIDNameRequestPacket)Pack;
  9023. foreach (UUIDNameRequestPacket.UUIDNameBlockBlock UUIDBlock in incoming.UUIDNameBlock)
  9024. OnNameFromUUIDRequest?.Invoke(UUIDBlock.ID, this);
  9025. }
  9026. #region Parcel related packets
  9027. private void HandleRegionHandleRequest(Packet Pack)
  9028. {
  9029. RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack;
  9030. OnRegionHandleRequest?.Invoke(this, rhrPack.RequestBlock.RegionID);
  9031. }
  9032. private void HandleParcelInfoRequest(Packet Pack)
  9033. {
  9034. if(OnParcelInfoRequest == null)
  9035. return;
  9036. ParcelInfoRequestPacket pirPack = (ParcelInfoRequestPacket)Pack;
  9037. if (pirPack.AgentData.SessionID != SessionId || pirPack.AgentData.AgentID != AgentId)
  9038. return;
  9039. OnParcelInfoRequest?.Invoke(this, pirPack.Data.ParcelID);
  9040. }
  9041. private void HandleParcelAccessListRequest(Packet Pack)
  9042. {
  9043. ParcelAccessListRequestPacket requestPacket = (ParcelAccessListRequestPacket)Pack;
  9044. if (requestPacket.AgentData.SessionID != SessionId || requestPacket.AgentData.AgentID != AgentId)
  9045. return;
  9046. OnParcelAccessListRequest?.Invoke(requestPacket.AgentData.AgentID, requestPacket.AgentData.SessionID,
  9047. requestPacket.Data.Flags, requestPacket.Data.SequenceID,
  9048. requestPacket.Data.LocalID, this);
  9049. }
  9050. private void HandleParcelAccessListUpdate(Packet Pack)
  9051. {
  9052. if(OnParcelAccessListUpdateRequest == null)
  9053. return;
  9054. ParcelAccessListUpdatePacket updatePacket = (ParcelAccessListUpdatePacket)Pack;
  9055. if (updatePacket.AgentData.SessionID != SessionId || updatePacket.AgentData.AgentID != AgentId)
  9056. return;
  9057. // viewers do send estimated number of packets and sequenceID, but don't seem reliable.
  9058. List<LandAccessEntry> entries = new List<LandAccessEntry>();
  9059. foreach (ParcelAccessListUpdatePacket.ListBlock block in updatePacket.List)
  9060. {
  9061. LandAccessEntry entry = new LandAccessEntry();
  9062. entry.AgentID = block.ID;
  9063. entry.Flags = (AccessList)block.Flags;
  9064. entry.Expires = block.Time;
  9065. entries.Add(entry);
  9066. }
  9067. OnParcelAccessListUpdateRequest?.Invoke(updatePacket.AgentData.AgentID,
  9068. updatePacket.Data.Flags,
  9069. updatePacket.Data.TransactionID,
  9070. updatePacket.Data.LocalID,
  9071. entries, this);
  9072. }
  9073. private void HandleParcelPropertiesRequest(Packet Pack)
  9074. {
  9075. ParcelPropertiesRequestPacket propertiesRequest = (ParcelPropertiesRequestPacket)Pack;
  9076. if (propertiesRequest.AgentData.SessionID != SessionId || propertiesRequest.AgentData.AgentID != AgentId)
  9077. return;
  9078. ParcelPropertiesRequestPacket.ParcelDataBlock pdb = propertiesRequest.ParcelData;
  9079. OnParcelPropertiesRequest?.Invoke((int)Math.Round(pdb.West), (int)Math.Round(pdb.South),
  9080. (int)Math.Round(pdb.East), (int)Math.Round(pdb.North),
  9081. pdb.SequenceID, pdb.SnapSelection, this);
  9082. }
  9083. private void HandleParcelDivide(Packet Pack)
  9084. {
  9085. ParcelDividePacket landDivide = (ParcelDividePacket)Pack;
  9086. if (landDivide.AgentData.SessionID != SessionId || landDivide.AgentData.AgentID != AgentId)
  9087. return;
  9088. OnParcelDivideRequest?.Invoke((int)Math.Round(landDivide.ParcelData.West),
  9089. (int)Math.Round(landDivide.ParcelData.South),
  9090. (int)Math.Round(landDivide.ParcelData.East),
  9091. (int)Math.Round(landDivide.ParcelData.North), this);
  9092. }
  9093. private void HandleParcelJoin(Packet Pack)
  9094. {
  9095. ParcelJoinPacket landJoin = (ParcelJoinPacket)Pack;
  9096. if (landJoin.AgentData.SessionID != SessionId || landJoin.AgentData.AgentID != AgentId)
  9097. return;
  9098. OnParcelJoinRequest?.Invoke((int)Math.Round(landJoin.ParcelData.West),
  9099. (int)Math.Round(landJoin.ParcelData.South),
  9100. (int)Math.Round(landJoin.ParcelData.East),
  9101. (int)Math.Round(landJoin.ParcelData.North), this);
  9102. }
  9103. private void HandleParcelPropertiesUpdate(Packet Pack)
  9104. {
  9105. if (OnParcelPropertiesUpdateRequest == null)
  9106. return;
  9107. ParcelPropertiesUpdatePacket parcelPropertiesPacket = (ParcelPropertiesUpdatePacket)Pack;
  9108. if (parcelPropertiesPacket.AgentData.SessionID != SessionId || parcelPropertiesPacket.AgentData.AgentID != AgentId)
  9109. return;
  9110. LandUpdateArgs args = new LandUpdateArgs();
  9111. args.AuthBuyerID = parcelPropertiesPacket.ParcelData.AuthBuyerID;
  9112. args.Category = (ParcelCategory)parcelPropertiesPacket.ParcelData.Category;
  9113. args.Desc = Utils.BytesToString(parcelPropertiesPacket.ParcelData.Desc);
  9114. args.GroupID = parcelPropertiesPacket.ParcelData.GroupID;
  9115. args.LandingType = parcelPropertiesPacket.ParcelData.LandingType;
  9116. args.MediaAutoScale = parcelPropertiesPacket.ParcelData.MediaAutoScale;
  9117. args.MediaID = parcelPropertiesPacket.ParcelData.MediaID;
  9118. args.MediaURL = Utils.BytesToString(parcelPropertiesPacket.ParcelData.MediaURL);
  9119. args.MusicURL = Utils.BytesToString(parcelPropertiesPacket.ParcelData.MusicURL);
  9120. args.Name = Utils.BytesToString(parcelPropertiesPacket.ParcelData.Name);
  9121. args.ParcelFlags = parcelPropertiesPacket.ParcelData.ParcelFlags;
  9122. args.PassHours = parcelPropertiesPacket.ParcelData.PassHours;
  9123. args.PassPrice = parcelPropertiesPacket.ParcelData.PassPrice;
  9124. args.SalePrice = parcelPropertiesPacket.ParcelData.SalePrice;
  9125. args.SnapshotID = parcelPropertiesPacket.ParcelData.SnapshotID;
  9126. args.UserLocation = parcelPropertiesPacket.ParcelData.UserLocation;
  9127. args.UserLookAt = parcelPropertiesPacket.ParcelData.UserLookAt;
  9128. OnParcelPropertiesUpdateRequest?.Invoke(args, parcelPropertiesPacket.ParcelData.LocalID, this);
  9129. }
  9130. private void HandleParcelSelectObjects(Packet Pack)
  9131. {
  9132. if(OnParcelSelectObjects == null)
  9133. return;
  9134. ParcelSelectObjectsPacket selectPacket = (ParcelSelectObjectsPacket)Pack;
  9135. if (selectPacket.AgentData.SessionID != SessionId || selectPacket.AgentData.AgentID != AgentId)
  9136. return;
  9137. List<UUID> returnIDs = new List<UUID>();
  9138. foreach (ParcelSelectObjectsPacket.ReturnIDsBlock rb in selectPacket.ReturnIDs)
  9139. {
  9140. returnIDs.Add(rb.ReturnID);
  9141. }
  9142. OnParcelSelectObjects?.Invoke(selectPacket.ParcelData.LocalID,
  9143. Convert.ToInt32(selectPacket.ParcelData.ReturnType), returnIDs, this);
  9144. }
  9145. private void HandleParcelObjectOwnersRequest(Packet Pack)
  9146. {
  9147. ParcelObjectOwnersRequestPacket reqPacket = (ParcelObjectOwnersRequestPacket)Pack;
  9148. if (reqPacket.AgentData.SessionID != SessionId || reqPacket.AgentData.AgentID != AgentId)
  9149. return;
  9150. OnParcelObjectOwnerRequest?.Invoke(reqPacket.ParcelData.LocalID, this);
  9151. }
  9152. private void HandleParcelGodForceOwner(Packet Pack)
  9153. {
  9154. ParcelGodForceOwnerPacket godForceOwnerPacket = (ParcelGodForceOwnerPacket)Pack;
  9155. if (godForceOwnerPacket.AgentData.SessionID != SessionId || godForceOwnerPacket.AgentData.AgentID != AgentId)
  9156. return;
  9157. OnParcelGodForceOwner?.Invoke(godForceOwnerPacket.Data.LocalID, godForceOwnerPacket.Data.OwnerID, this);
  9158. }
  9159. private void HandleParcelRelease(Packet Pack)
  9160. {
  9161. ParcelReleasePacket releasePacket = (ParcelReleasePacket)Pack;
  9162. if (releasePacket.AgentData.SessionID != SessionId || releasePacket.AgentData.AgentID != AgentId)
  9163. return;
  9164. OnParcelAbandonRequest?.Invoke(releasePacket.Data.LocalID, this);
  9165. }
  9166. private void HandleParcelReclaim(Packet Pack)
  9167. {
  9168. ParcelReclaimPacket reclaimPacket = (ParcelReclaimPacket)Pack;
  9169. if (reclaimPacket.AgentData.SessionID != SessionId || reclaimPacket.AgentData.AgentID != AgentId)
  9170. return;
  9171. OnParcelReclaim?.Invoke(reclaimPacket.Data.LocalID, this);
  9172. }
  9173. private void HandleParcelReturnObjects(Packet Pack)
  9174. {
  9175. if(OnParcelReturnObjectsRequest == null)
  9176. return;
  9177. ParcelReturnObjectsPacket parcelReturnObjects = (ParcelReturnObjectsPacket)Pack;
  9178. if (parcelReturnObjects.AgentData.SessionID != SessionId || parcelReturnObjects.AgentData.AgentID != AgentId)
  9179. return;
  9180. UUID[] puserselectedOwnerIDs = new UUID[parcelReturnObjects.OwnerIDs.Length];
  9181. for (int parceliterator = 0; parceliterator < parcelReturnObjects.OwnerIDs.Length; parceliterator++)
  9182. puserselectedOwnerIDs[parceliterator] = parcelReturnObjects.OwnerIDs[parceliterator].OwnerID;
  9183. UUID[] puserselectedTaskIDs = new UUID[parcelReturnObjects.TaskIDs.Length];
  9184. for (int parceliterator = 0; parceliterator < parcelReturnObjects.TaskIDs.Length; parceliterator++)
  9185. puserselectedTaskIDs[parceliterator] = parcelReturnObjects.TaskIDs[parceliterator].TaskID;
  9186. OnParcelReturnObjectsRequest?.Invoke(parcelReturnObjects.ParcelData.LocalID, parcelReturnObjects.ParcelData.ReturnType, puserselectedOwnerIDs, puserselectedTaskIDs, this);
  9187. }
  9188. private void HandleParcelSetOtherCleanTime(Packet Pack)
  9189. {
  9190. ParcelSetOtherCleanTimePacket parcelSetOtherCleanTimePacket = (ParcelSetOtherCleanTimePacket)Pack;
  9191. if (parcelSetOtherCleanTimePacket.AgentData.SessionID != SessionId || parcelSetOtherCleanTimePacket.AgentData.AgentID != AgentId)
  9192. return;
  9193. OnParcelSetOtherCleanTime?.Invoke(this,
  9194. parcelSetOtherCleanTimePacket.ParcelData.LocalID,
  9195. parcelSetOtherCleanTimePacket.ParcelData.OtherCleanTime);
  9196. }
  9197. private void HandleLandStatRequest(Packet Pack)
  9198. {
  9199. LandStatRequestPacket lsrp = (LandStatRequestPacket)Pack;
  9200. if (lsrp.AgentData.SessionID != SessionId || lsrp.AgentData.AgentID != AgentId)
  9201. return;
  9202. OnLandStatRequest?.Invoke(lsrp.RequestData.ParcelLocalID, lsrp.RequestData.ReportType, lsrp.RequestData.RequestFlags, Utils.BytesToString(lsrp.RequestData.Filter), this);
  9203. }
  9204. private void HandleParcelDwellRequest(Packet Pack)
  9205. {
  9206. ParcelDwellRequestPacket dwellrq = (ParcelDwellRequestPacket)Pack;
  9207. if (dwellrq.AgentData.SessionID != SessionId || dwellrq.AgentData.AgentID != AgentId)
  9208. return;
  9209. OnParcelDwellRequest?.Invoke(dwellrq.Data.LocalID, this);
  9210. }
  9211. #endregion Parcel related packets
  9212. #region Estate Packets
  9213. private static double m_lastMapRegenTime = Double.MinValue;
  9214. private void HandleEstateOwnerMessage(Packet Pack)
  9215. {
  9216. EstateOwnerMessagePacket messagePacket = (EstateOwnerMessagePacket)Pack;
  9217. if (messagePacket.AgentData.SessionID != SessionId || messagePacket.AgentData.AgentID != AgentId)
  9218. return;
  9219. string method = Utils.BytesToString(messagePacket.MethodData.Method);
  9220. switch (method)
  9221. {
  9222. case "getinfo":
  9223. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9224. {
  9225. OnDetailedEstateDataRequest?.Invoke(this, messagePacket.MethodData.Invoice);
  9226. }
  9227. return;
  9228. case "setregioninfo":
  9229. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9230. {
  9231. OnSetEstateFlagsRequest?.Invoke(convertParamStringToBool(messagePacket.ParamList[0].Parameter), convertParamStringToBool(messagePacket.ParamList[1].Parameter),
  9232. convertParamStringToBool(messagePacket.ParamList[2].Parameter), !convertParamStringToBool(messagePacket.ParamList[3].Parameter),
  9233. Convert.ToInt16(Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[4].Parameter), Culture.NumberFormatInfo)),
  9234. (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[5].Parameter), Culture.NumberFormatInfo),
  9235. Convert.ToInt16(Utils.BytesToString(messagePacket.ParamList[6].Parameter)),
  9236. convertParamStringToBool(messagePacket.ParamList[7].Parameter), convertParamStringToBool(messagePacket.ParamList[8].Parameter));
  9237. }
  9238. return;
  9239. // case "texturebase":
  9240. // if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  9241. // {
  9242. // foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9243. // {
  9244. // string s = Utils.BytesToString(block.Parameter);
  9245. // string[] splitField = s.Split(' ');
  9246. // if (splitField.Length == 2)
  9247. // {
  9248. // UUID tempUUID = new UUID(splitField[1]);
  9249. // OnSetEstateTerrainBaseTexture(this, Convert.ToInt16(splitField[0]), tempUUID);
  9250. // }
  9251. // }
  9252. // }
  9253. // break;
  9254. case "texturedetail":
  9255. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9256. {
  9257. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9258. {
  9259. string s = Utils.BytesToString(block.Parameter);
  9260. string[] splitField = s.Split(' ');
  9261. if (splitField.Length == 2)
  9262. {
  9263. Int16 corner = Convert.ToInt16(splitField[0]);
  9264. UUID textureUUID = new UUID(splitField[1]);
  9265. OnSetEstateTerrainDetailTexture?.Invoke(this, corner, textureUUID);
  9266. }
  9267. }
  9268. }
  9269. return;
  9270. case "textureheights":
  9271. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9272. {
  9273. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9274. {
  9275. string s = Utils.BytesToString(block.Parameter);
  9276. string[] splitField = s.Split(' ');
  9277. if (splitField.Length == 3)
  9278. {
  9279. Int16 corner = Convert.ToInt16(splitField[0]);
  9280. float lowValue = (float)Convert.ToDecimal(splitField[1], Culture.NumberFormatInfo);
  9281. float highValue = (float)Convert.ToDecimal(splitField[2], Culture.NumberFormatInfo);
  9282. OnSetEstateTerrainTextureHeights?.Invoke(this, corner, lowValue, highValue);
  9283. }
  9284. }
  9285. }
  9286. return;
  9287. case "texturecommit":
  9288. OnCommitEstateTerrainTextureRequest?.Invoke(this);
  9289. return;
  9290. case "setregionterrain":
  9291. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9292. {
  9293. if (messagePacket.ParamList.Length != 9)
  9294. {
  9295. m_log.Error("EstateOwnerMessage: SetRegionTerrain method has a ParamList of invalid length");
  9296. }
  9297. else
  9298. {
  9299. try
  9300. {
  9301. string tmp = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  9302. if (!tmp.Contains(".")) tmp += ".00";
  9303. float WaterHeight = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
  9304. tmp = Utils.BytesToString(messagePacket.ParamList[1].Parameter);
  9305. if (!tmp.Contains(".")) tmp += ".00";
  9306. float TerrainRaiseLimit = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
  9307. tmp = Utils.BytesToString(messagePacket.ParamList[2].Parameter);
  9308. if (!tmp.Contains(".")) tmp += ".00";
  9309. float TerrainLowerLimit = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
  9310. bool UseEstateSun = convertParamStringToBool(messagePacket.ParamList[3].Parameter);
  9311. bool UseFixedSun = convertParamStringToBool(messagePacket.ParamList[4].Parameter);
  9312. float SunHour = (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[5].Parameter), Culture.NumberFormatInfo);
  9313. bool UseGlobal = convertParamStringToBool(messagePacket.ParamList[6].Parameter);
  9314. bool EstateFixedSun = convertParamStringToBool(messagePacket.ParamList[7].Parameter);
  9315. float EstateSunHour = (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[8].Parameter), Culture.NumberFormatInfo);
  9316. OnSetRegionTerrainSettings?.Invoke(WaterHeight, TerrainRaiseLimit, TerrainLowerLimit, UseEstateSun, UseFixedSun, SunHour, UseGlobal, EstateFixedSun, EstateSunHour);
  9317. }
  9318. catch (Exception ex)
  9319. {
  9320. m_log.Error("EstateOwnerMessage: Exception while setting terrain settings: \n" + messagePacket + "\n" + ex);
  9321. }
  9322. }
  9323. }
  9324. return;
  9325. case "restart":
  9326. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9327. {
  9328. // There's only 1 block in the estateResetSim.. and that's the number of seconds till restart.
  9329. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9330. {
  9331. float timeSeconds;
  9332. Utils.TryParseSingle(Utils.BytesToString(block.Parameter), out timeSeconds);
  9333. timeSeconds = (int)timeSeconds;
  9334. OnEstateRestartSimRequest?.Invoke(this, (int)timeSeconds);
  9335. }
  9336. }
  9337. return;
  9338. case "estatechangecovenantid":
  9339. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9340. {
  9341. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  9342. {
  9343. UUID newCovenantID = new UUID(Utils.BytesToString(block.Parameter));
  9344. OnEstateChangeCovenantRequest?.Invoke(this, newCovenantID);
  9345. }
  9346. }
  9347. return;
  9348. case "estateaccessdelta": // Estate access delta manages the banlist and allow list too.
  9349. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9350. {
  9351. int estateAccessType = Convert.ToInt16(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9352. OnUpdateEstateAccessDeltaRequest?.Invoke(this, messagePacket.MethodData.Invoice, estateAccessType, new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter)));
  9353. }
  9354. return;
  9355. case "simulatormessage":
  9356. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9357. {
  9358. UUID invoice = messagePacket.MethodData.Invoice;
  9359. UUID SenderID = new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  9360. string SenderName = Utils.BytesToString(messagePacket.ParamList[3].Parameter);
  9361. string Message = Utils.BytesToString(messagePacket.ParamList[4].Parameter);
  9362. UUID sessionID = messagePacket.AgentData.SessionID;
  9363. OnSimulatorBlueBoxMessageRequest?.Invoke(this, invoice, SenderID, sessionID, SenderName, Message);
  9364. }
  9365. return;
  9366. case "instantmessage":
  9367. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9368. {
  9369. if (messagePacket.ParamList.Length < 2)
  9370. return;
  9371. UUID invoice = messagePacket.MethodData.Invoice;
  9372. UUID sessionID = messagePacket.AgentData.SessionID;
  9373. UUID SenderID;
  9374. string SenderName;
  9375. string Message;
  9376. if (messagePacket.ParamList.Length < 5)
  9377. {
  9378. SenderID = AgentId;
  9379. SenderName = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  9380. Message = Utils.BytesToString(messagePacket.ParamList[1].Parameter);
  9381. }
  9382. else
  9383. {
  9384. SenderID = new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  9385. SenderName = Utils.BytesToString(messagePacket.ParamList[3].Parameter);
  9386. Message = Utils.BytesToString(messagePacket.ParamList[4].Parameter);
  9387. }
  9388. OnEstateBlueBoxMessageRequest?.Invoke(this, invoice, SenderID, sessionID, SenderName, Message);
  9389. }
  9390. return;
  9391. case "setregiondebug":
  9392. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9393. {
  9394. UUID invoice = messagePacket.MethodData.Invoice;
  9395. UUID SenderID = messagePacket.AgentData.AgentID;
  9396. bool scripted = convertParamStringToBool(messagePacket.ParamList[0].Parameter);
  9397. bool collisionEvents = convertParamStringToBool(messagePacket.ParamList[1].Parameter);
  9398. bool physics = convertParamStringToBool(messagePacket.ParamList[2].Parameter);
  9399. OnEstateDebugRegionRequest?.Invoke(this, invoice, SenderID, scripted, collisionEvents, physics);
  9400. }
  9401. return;
  9402. case "teleporthomeuser":
  9403. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9404. {
  9405. UUID invoice = messagePacket.MethodData.Invoice;
  9406. UUID SenderID = messagePacket.AgentData.AgentID;
  9407. UUID Prey;
  9408. if(UUID.TryParse(Utils.BytesToString(messagePacket.ParamList[1].Parameter), out Prey))
  9409. OnEstateTeleportOneUserHomeRequest?.Invoke(this, invoice, SenderID, Prey, false);
  9410. }
  9411. return;
  9412. case "teleporthomeallusers":
  9413. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9414. {
  9415. UUID invoice = messagePacket.MethodData.Invoice;
  9416. UUID SenderID = messagePacket.AgentData.AgentID;
  9417. OnEstateTeleportAllUsersHomeRequest?.Invoke(this, invoice, SenderID);
  9418. }
  9419. return;
  9420. case "colliders":
  9421. OnLandStatRequest?.Invoke(0, 1, 0, "", this);
  9422. return;
  9423. case "scripts":
  9424. OnLandStatRequest?.Invoke(0, 0, 0, "", this);
  9425. return;
  9426. case "terrain":
  9427. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9428. {
  9429. if (messagePacket.ParamList.Length > 0)
  9430. {
  9431. string p0 = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  9432. if (p0 == "bake")
  9433. {
  9434. OnBakeTerrain?.Invoke(this);
  9435. }
  9436. else if (p0 == "download filename")
  9437. {
  9438. if (messagePacket.ParamList.Length > 1)
  9439. {
  9440. OnRequestTerrain?.Invoke(this, Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9441. }
  9442. }
  9443. else if (p0 == "upload filename")
  9444. {
  9445. if (messagePacket.ParamList.Length > 1)
  9446. {
  9447. OnUploadTerrain?.Invoke(this, Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9448. }
  9449. }
  9450. }
  9451. }
  9452. return;
  9453. case "estatechangeinfo":
  9454. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9455. {
  9456. UUID invoice = messagePacket.MethodData.Invoice;
  9457. UUID SenderID = messagePacket.AgentData.AgentID;
  9458. UInt32 param1 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9459. UInt32 param2 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  9460. OnEstateChangeInfo?.Invoke(this, invoice, SenderID, param1, param2);
  9461. }
  9462. return;
  9463. case "telehub":
  9464. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9465. {
  9466. UUID invoice = messagePacket.MethodData.Invoice;
  9467. UUID SenderID = messagePacket.AgentData.AgentID;
  9468. UInt32 param1 = 0u;
  9469. string command = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  9470. if (command != "info ui")
  9471. {
  9472. try
  9473. {
  9474. param1 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  9475. }
  9476. catch
  9477. {
  9478. }
  9479. }
  9480. OnEstateManageTelehub?.Invoke(this, invoice, SenderID, command, param1);
  9481. }
  9482. return;
  9483. case "refreshmapvisibility":
  9484. if (m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9485. {
  9486. IWorldMapModule mapModule = Scene.RequestModuleInterface<IWorldMapModule>();
  9487. if (mapModule == null)
  9488. {
  9489. SendAlertMessage("Terrain map generator not avaiable");
  9490. return;
  9491. }
  9492. if (m_lastMapRegenTime == Double.MaxValue)
  9493. {
  9494. SendAlertMessage("Terrain map generation still in progress");
  9495. return;
  9496. }
  9497. double now = Util.GetTimeStamp();
  9498. if (now - m_lastMapRegenTime < 120) // 2 minutes global cool down
  9499. {
  9500. SendAlertMessage("Please wait at least 2 minutes between map generation commands");
  9501. return;
  9502. }
  9503. m_lastMapRegenTime = Double.MaxValue;
  9504. m_scene.RegenerateMaptileAndReregister(this, null);
  9505. SendAlertMessage("Terrain map generated");
  9506. m_lastMapRegenTime = now;
  9507. }
  9508. return;
  9509. case "kickestate":
  9510. if(m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  9511. {
  9512. UUID invoice = messagePacket.MethodData.Invoice;
  9513. UUID SenderID = messagePacket.AgentData.AgentID;
  9514. UUID Prey;
  9515. UUID.TryParse(Utils.BytesToString(messagePacket.ParamList[0].Parameter), out Prey);
  9516. OnEstateTeleportOneUserHomeRequest?.Invoke(this, invoice, SenderID, Prey, true);
  9517. }
  9518. return;
  9519. default:
  9520. m_log.WarnFormat(
  9521. "[LLCLIENTVIEW]: EstateOwnerMessage: Unknown method {0} requested for {1} in {2}",
  9522. method, Name, Scene.Name);
  9523. for (int i = 0; i < messagePacket.ParamList.Length; i++)
  9524. {
  9525. EstateOwnerMessagePacket.ParamListBlock block = messagePacket.ParamList[i];
  9526. string data = (string)Utils.BytesToString(block.Parameter);
  9527. m_log.DebugFormat("[LLCLIENTVIEW]: Param {0}={1}", i, data);
  9528. }
  9529. return;
  9530. }
  9531. //int parcelID, uint reportType, uint requestflags, string filter
  9532. //lsrp.RequestData.ParcelLocalID;
  9533. //lsrp.RequestData.ReportType; // 1 = colliders, 0 = scripts
  9534. //lsrp.RequestData.RequestFlags;
  9535. //lsrp.RequestData.Filter;
  9536. }
  9537. private void HandleRequestRegionInfo(Packet Pack)
  9538. {
  9539. RequestRegionInfoPacket.AgentDataBlock mPacket = ((RequestRegionInfoPacket)Pack).AgentData;
  9540. if (mPacket.SessionID != SessionId || mPacket.AgentID != AgentId)
  9541. return;
  9542. OnRegionInfoRequest?.Invoke(this);
  9543. }
  9544. private void HandleEstateCovenantRequest(Packet Pack)
  9545. {
  9546. EstateCovenantRequestPacket.AgentDataBlock epack = ((EstateCovenantRequestPacket)Pack).AgentData;
  9547. if (epack.SessionID != SessionId || epack.AgentID != AgentId)
  9548. return;
  9549. OnEstateCovenantRequest?.Invoke(this);
  9550. }
  9551. #endregion Estate Packets
  9552. #region GodPackets
  9553. private void HandleRequestGodlikePowers(Packet Pack)
  9554. {
  9555. RequestGodlikePowersPacket rglpPack = (RequestGodlikePowersPacket)Pack;
  9556. RequestGodlikePowersPacket.AgentDataBlock ablock = rglpPack.AgentData;
  9557. if (ablock.SessionID != SessionId || ablock.AgentID != AgentId)
  9558. return;
  9559. RequestGodlikePowersPacket.RequestBlockBlock rblock = rglpPack.RequestBlock;
  9560. UUID token = rblock.Token;
  9561. OnRequestGodlikePowers?.Invoke(ablock.AgentID, ablock.SessionID, token, rblock.Godlike);
  9562. }
  9563. private void HandleGodUpdateRegionInfoUpdate(Packet packet)
  9564. {
  9565. GodUpdateRegionInfoPacket GodUpdateRegionInfo = (GodUpdateRegionInfoPacket)packet;
  9566. if (GodUpdateRegionInfo.AgentData.SessionID != SessionId || GodUpdateRegionInfo.AgentData.AgentID != AgentId)
  9567. return;
  9568. OnGodUpdateRegionInfoUpdate?.Invoke(this,
  9569. GodUpdateRegionInfo.RegionInfo.BillableFactor,
  9570. GodUpdateRegionInfo.RegionInfo.EstateID,
  9571. GodUpdateRegionInfo.RegionInfo.RegionFlags,
  9572. GodUpdateRegionInfo.RegionInfo.SimName,
  9573. GodUpdateRegionInfo.RegionInfo.RedirectGridX,
  9574. GodUpdateRegionInfo.RegionInfo.RedirectGridY);
  9575. }
  9576. private void HandleSimWideDeletes(Packet packet)
  9577. {
  9578. SimWideDeletesPacket SimWideDeletesRequest = (SimWideDeletesPacket)packet;
  9579. if(SimWideDeletesRequest.AgentData.AgentID != AgentId || SimWideDeletesRequest.AgentData.SessionID != SessionId)
  9580. return;
  9581. OnSimWideDeletes?.Invoke(this, SimWideDeletesRequest.AgentData.AgentID,(int)SimWideDeletesRequest.DataBlock.Flags,SimWideDeletesRequest.DataBlock.TargetID);
  9582. }
  9583. private void HandleGodlikeMessage(Packet packet)
  9584. {
  9585. GodlikeMessagePacket GodlikeMessage = (GodlikeMessagePacket)packet;
  9586. if (GodlikeMessage.AgentData.SessionID != SessionId || GodlikeMessage.AgentData.AgentID != AgentId)
  9587. return;
  9588. onGodlikeMessage?.Invoke(this,
  9589. GodlikeMessage.MethodData.Invoice,
  9590. GodlikeMessage.MethodData.Method,
  9591. GodlikeMessage.ParamList[0].Parameter);
  9592. }
  9593. private void HandleSaveStatePacket(Packet packet)
  9594. {
  9595. StateSavePacket SaveStateMessage = (StateSavePacket)packet;
  9596. if (SaveStateMessage.AgentData.SessionID != SessionId || SaveStateMessage.AgentData.AgentID != AgentId)
  9597. return;
  9598. OnSaveState?.Invoke(this,SaveStateMessage.AgentData.AgentID);
  9599. }
  9600. private void HandleGodKickUser(Packet Pack)
  9601. {
  9602. GodKickUserPacket gkupack = (GodKickUserPacket)Pack;
  9603. if (gkupack.UserInfo.GodSessionID != SessionId || gkupack.UserInfo.GodID != AgentId)
  9604. return;
  9605. OnGodKickUser?.Invoke(gkupack.UserInfo.GodID, gkupack.UserInfo.AgentID, gkupack.UserInfo.KickFlags, gkupack.UserInfo.Reason);
  9606. }
  9607. #endregion GodPackets
  9608. #region Economy/Transaction Packets
  9609. private void HandleMoneyBalanceRequest(Packet Pack)
  9610. {
  9611. MoneyBalanceRequestPacket moneybalancerequestpacket = (MoneyBalanceRequestPacket)Pack;
  9612. if (moneybalancerequestpacket.AgentData.SessionID != SessionId || moneybalancerequestpacket.AgentData.AgentID != AgentId)
  9613. return;
  9614. OnMoneyBalanceRequest?.Invoke(this, moneybalancerequestpacket.AgentData.AgentID, moneybalancerequestpacket.AgentData.SessionID, moneybalancerequestpacket.MoneyData.TransactionID);
  9615. }
  9616. private void HandleEconomyDataRequest(Packet Pack)
  9617. {
  9618. OnEconomyDataRequest?.Invoke(this);
  9619. }
  9620. private void HandleRequestPayPrice(Packet Pack)
  9621. {
  9622. RequestPayPricePacket requestPayPricePacket = (RequestPayPricePacket)Pack;
  9623. OnRequestPayPrice?.Invoke(this, requestPayPricePacket.ObjectData.ObjectID);
  9624. }
  9625. private void HandleObjectSaleInfo(Packet Pack)
  9626. {
  9627. if(OnObjectSaleInfo == null)
  9628. return;
  9629. ObjectSaleInfoPacket objectSaleInfoPacket = (ObjectSaleInfoPacket)Pack;
  9630. if (objectSaleInfoPacket.AgentData.SessionID != SessionId || objectSaleInfoPacket.AgentData.AgentID != AgentId)
  9631. return;
  9632. foreach (ObjectSaleInfoPacket.ObjectDataBlock d in objectSaleInfoPacket.ObjectData)
  9633. {
  9634. OnObjectSaleInfo?.Invoke(this,
  9635. AgentId,
  9636. SessionId,
  9637. d.LocalID,
  9638. d.SaleType,
  9639. d.SalePrice);
  9640. }
  9641. }
  9642. private void HandleObjectBuy(Packet Pack)
  9643. {
  9644. if(OnObjectBuy == null)
  9645. return;
  9646. ObjectBuyPacket objectBuyPacket = (ObjectBuyPacket)Pack;
  9647. if (objectBuyPacket.AgentData.SessionID != SessionId || objectBuyPacket.AgentData.AgentID != AgentId)
  9648. return;
  9649. foreach (ObjectBuyPacket.ObjectDataBlock d in objectBuyPacket.ObjectData)
  9650. {
  9651. OnObjectBuy?.Invoke(this,
  9652. objectBuyPacket.AgentData.AgentID,
  9653. objectBuyPacket.AgentData.SessionID,
  9654. objectBuyPacket.AgentData.GroupID,
  9655. objectBuyPacket.AgentData.CategoryID,
  9656. d.ObjectLocalID,
  9657. d.SaleType,
  9658. d.SalePrice);
  9659. }
  9660. }
  9661. #endregion Economy/Transaction Packets
  9662. #region Script Packets
  9663. private void HandleGetScriptRunning(Packet Pack)
  9664. {
  9665. GetScriptRunningPacket scriptRunning = (GetScriptRunningPacket)Pack;
  9666. OnGetScriptRunning?.Invoke(this, scriptRunning.Script.ObjectID, scriptRunning.Script.ItemID);
  9667. }
  9668. private void HandleSetScriptRunning(Packet Pack)
  9669. {
  9670. SetScriptRunningPacket setScriptRunning = (SetScriptRunningPacket)Pack;
  9671. if (setScriptRunning.AgentData.SessionID != SessionId || setScriptRunning.AgentData.AgentID != AgentId)
  9672. return;
  9673. OnSetScriptRunning?.Invoke(this, setScriptRunning.Script.ObjectID, setScriptRunning.Script.ItemID, setScriptRunning.Script.Running);
  9674. }
  9675. private void HandleScriptReset(Packet Pack)
  9676. {
  9677. ScriptResetPacket scriptResetPacket = (ScriptResetPacket)Pack;
  9678. if (scriptResetPacket.AgentData.SessionID != SessionId || scriptResetPacket.AgentData.AgentID != AgentId)
  9679. return;
  9680. OnScriptReset?.Invoke(this, scriptResetPacket.Script.ObjectID, scriptResetPacket.Script.ItemID);
  9681. }
  9682. #endregion Script Packets
  9683. #region Gesture Managment
  9684. private void HandleActivateGestures(Packet Pack)
  9685. {
  9686. if(OnActivateGesture == null)
  9687. return;
  9688. ActivateGesturesPacket activateGesturePacket = (ActivateGesturesPacket)Pack;
  9689. if (activateGesturePacket.AgentData.SessionID != SessionId || activateGesturePacket.AgentData.AgentID != AgentId)
  9690. return;
  9691. ActivateGesturesPacket.DataBlock[] data = activateGesturePacket.Data;
  9692. for (int i= 0; i < data.Length; ++i)
  9693. {
  9694. OnActivateGesture?.Invoke(this,
  9695. data[i].AssetID,
  9696. data[i].ItemID);
  9697. }
  9698. }
  9699. private void HandleDeactivateGestures(Packet Pack)
  9700. {
  9701. if(OnDeactivateGesture == null)
  9702. return;
  9703. DeactivateGesturesPacket deactivateGesturePacket = (DeactivateGesturesPacket)Pack;
  9704. if (deactivateGesturePacket.AgentData.SessionID != SessionId || deactivateGesturePacket.AgentData.AgentID != AgentId)
  9705. return;
  9706. DeactivateGesturesPacket.DataBlock[] data = deactivateGesturePacket.Data;
  9707. for (int i = 0; i < data.Length; ++i)
  9708. {
  9709. OnDeactivateGesture?.Invoke(this, data[i].ItemID);
  9710. }
  9711. }
  9712. #endregion Gesture Managment
  9713. private void HandleObjectOwner(Packet Pack)
  9714. {
  9715. if (OnObjectOwner == null)
  9716. return;
  9717. ObjectOwnerPacket objectOwnerPacket = (ObjectOwnerPacket)Pack;
  9718. if (objectOwnerPacket.AgentData.SessionID != SessionId || objectOwnerPacket.AgentData.AgentID != AgentId)
  9719. return;
  9720. List<uint> localIDs = new List<uint>();
  9721. foreach (ObjectOwnerPacket.ObjectDataBlock d in objectOwnerPacket.ObjectData)
  9722. localIDs.Add(d.ObjectLocalID);
  9723. OnObjectOwner?.Invoke(this, objectOwnerPacket.HeaderData.OwnerID, objectOwnerPacket.HeaderData.GroupID, localIDs);
  9724. }
  9725. private void HandleAgentFOV(Packet Pack)
  9726. {
  9727. AgentFOVPacket fovPacket = (AgentFOVPacket)Pack;
  9728. if(fovPacket.AgentData.AgentID != AgentId || fovPacket.AgentData.SessionID != SessionId)
  9729. return;
  9730. if (fovPacket.FOVBlock.GenCounter > m_agentFOVCounter)
  9731. {
  9732. m_agentFOVCounter = fovPacket.FOVBlock.GenCounter;
  9733. OnAgentFOV?.Invoke(this, fovPacket.FOVBlock.VerticalAngle);
  9734. }
  9735. }
  9736. #region unimplemented handlers
  9737. private void HandleViewerStats(Packet Pack)
  9738. {
  9739. // TODO: handle this packet
  9740. //m_log.Warn("[CLIENT]: unhandled ViewerStats packet");
  9741. }
  9742. private void HandleMapItemRequest(Packet Pack)
  9743. {
  9744. MapItemRequestPacket mirpk = (MapItemRequestPacket)Pack;
  9745. if (mirpk.AgentData.SessionID != SessionId || mirpk.AgentData.AgentID != AgentId)
  9746. return;
  9747. //m_log.Debug(mirpk.ToString());
  9748. try
  9749. {
  9750. OnMapItemRequest?.Invoke(this, mirpk.AgentData.Flags, mirpk.AgentData.EstateID,
  9751. mirpk.AgentData.Godlike, mirpk.RequestData.ItemType,
  9752. mirpk.RequestData.RegionHandle);
  9753. }
  9754. catch( Exception e)
  9755. {
  9756. m_log.ErrorFormat("{0} HandleMapItemRequest exception: {1} : {2}", LogHeader, e.Message, e.StackTrace);
  9757. }
  9758. }
  9759. private void HandleTransferAbort(Packet Pack)
  9760. {
  9761. }
  9762. private void HandleMuteListRequest(Packet Pack)
  9763. {
  9764. MuteListRequestPacket muteListRequest = (MuteListRequestPacket)Pack;
  9765. if (muteListRequest.AgentData.SessionID != SessionId || muteListRequest.AgentData.AgentID != AgentId)
  9766. return;
  9767. if (OnMuteListRequest != null)
  9768. {
  9769. OnMuteListRequest?.Invoke(this, muteListRequest.MuteData.MuteCRC);
  9770. }
  9771. else
  9772. {
  9773. if(muteListRequest.MuteData.MuteCRC == 0)
  9774. SendEmpytMuteList();
  9775. else
  9776. SendUseCachedMuteList();
  9777. }
  9778. }
  9779. private void HandleUpdateMuteListEntry(Packet packet)
  9780. {
  9781. UpdateMuteListEntryPacket UpdateMuteListEntry = (UpdateMuteListEntryPacket)packet;
  9782. if (UpdateMuteListEntry.AgentData.SessionID != SessionId || UpdateMuteListEntry.AgentData.AgentID != AgentId)
  9783. return;
  9784. OnUpdateMuteListEntry?.Invoke(this, UpdateMuteListEntry.MuteData.MuteID,
  9785. Utils.BytesToString(UpdateMuteListEntry.MuteData.MuteName),
  9786. UpdateMuteListEntry.MuteData.MuteType,
  9787. UpdateMuteListEntry.MuteData.MuteFlags);
  9788. }
  9789. private void HandleRemoveMuteListEntry(Packet packet)
  9790. {
  9791. RemoveMuteListEntryPacket RemoveMuteListEntry = (RemoveMuteListEntryPacket)packet;
  9792. if (RemoveMuteListEntry.AgentData.SessionID != SessionId || RemoveMuteListEntry.AgentData.AgentID != AgentId)
  9793. return;
  9794. OnRemoveMuteListEntry?.Invoke(this,
  9795. RemoveMuteListEntry.MuteData.MuteID,
  9796. Utils.BytesToString(RemoveMuteListEntry.MuteData.MuteName));
  9797. }
  9798. private void HandleUserReport(Packet packet)
  9799. {
  9800. UserReportPacket UserReport = (UserReportPacket)packet;
  9801. if (UserReport.AgentData.SessionID != SessionId || UserReport.AgentData.AgentID != AgentId)
  9802. return;
  9803. OnUserReport?.Invoke(this,
  9804. Utils.BytesToString(UserReport.ReportData.AbuseRegionName),
  9805. UserReport.ReportData.AbuserID,
  9806. UserReport.ReportData.Category,
  9807. UserReport.ReportData.CheckFlags,
  9808. Utils.BytesToString(UserReport.ReportData.Details),
  9809. UserReport.ReportData.ObjectID,
  9810. UserReport.ReportData.Position,
  9811. UserReport.ReportData.ReportType,
  9812. UserReport.ReportData.ScreenshotID,
  9813. Utils.BytesToString(UserReport.ReportData.Summary),
  9814. UserReport.AgentData.AgentID);
  9815. }
  9816. private void HandleSendPostcard(Packet packet)
  9817. {
  9818. // SendPostcardPacket SendPostcard =
  9819. // (SendPostcardPacket)packet;
  9820. OnSendPostcard?.Invoke(this);
  9821. }
  9822. private void HandleChangeInventoryItemFlags(Packet packet)
  9823. {
  9824. if(OnChangeInventoryItemFlags == null)
  9825. return;
  9826. ChangeInventoryItemFlagsPacket ChangeInventoryItemFlags = (ChangeInventoryItemFlagsPacket)packet;
  9827. if (ChangeInventoryItemFlags.AgentData.SessionID != SessionId || ChangeInventoryItemFlags.AgentData.AgentID != AgentId)
  9828. return;
  9829. foreach(ChangeInventoryItemFlagsPacket.InventoryDataBlock b in ChangeInventoryItemFlags.InventoryData)
  9830. OnChangeInventoryItemFlags?.Invoke(this, b.ItemID, b.Flags);
  9831. }
  9832. private void HandleUseCircuitCode(Packet Pack)
  9833. {
  9834. /*
  9835. UseCircuitCodePacket uccp = (UseCircuitCodePacket)Pack;
  9836. if(uccp.CircuitCode.ID == m_agentId &&
  9837. uccp.CircuitCode.SessionID == m_sessionId &&
  9838. uccp.CircuitCode.Code == m_circuitCode &&
  9839. SceneAgent != null &&
  9840. !((ScenePresence)SceneAgent).IsDeleted
  9841. )
  9842. SendRegionHandshake(); // possible someone returning
  9843. */
  9844. }
  9845. private void HandleCreateNewOutfitAttachments(Packet Pack)
  9846. {
  9847. if(OnMoveItemsAndLeaveCopy == null)
  9848. return;
  9849. CreateNewOutfitAttachmentsPacket packet = (CreateNewOutfitAttachmentsPacket)Pack;
  9850. if (packet.AgentData.SessionID != SessionId || packet.AgentData.AgentID != AgentId)
  9851. return;
  9852. List<InventoryItemBase> items = new List<InventoryItemBase>();
  9853. foreach (CreateNewOutfitAttachmentsPacket.ObjectDataBlock n in packet.ObjectData)
  9854. {
  9855. InventoryItemBase b = new InventoryItemBase();
  9856. b.ID = n.OldItemID;
  9857. b.Folder = n.OldFolderID;
  9858. items.Add(b);
  9859. }
  9860. OnMoveItemsAndLeaveCopy?.Invoke(this, items, packet.HeaderData.NewFolderID);
  9861. }
  9862. private void HandleAgentHeightWidth(Packet Pack)
  9863. {
  9864. }
  9865. private void HandleInventoryDescendents(Packet Pack)
  9866. {
  9867. }
  9868. #endregion unimplemented handlers
  9869. #region Dir handlers
  9870. private void HandleDirPlacesQuery(Packet Pack)
  9871. {
  9872. DirPlacesQueryPacket dirPlacesQueryPacket = (DirPlacesQueryPacket)Pack;
  9873. if (dirPlacesQueryPacket.AgentData.SessionID != SessionId || dirPlacesQueryPacket.AgentData.AgentID != AgentId)
  9874. return;
  9875. OnDirPlacesQuery?.Invoke(this,
  9876. dirPlacesQueryPacket.QueryData.QueryID,
  9877. Utils.BytesToString(
  9878. dirPlacesQueryPacket.QueryData.QueryText),
  9879. (int)dirPlacesQueryPacket.QueryData.QueryFlags,
  9880. (int)dirPlacesQueryPacket.QueryData.Category,
  9881. Utils.BytesToString(
  9882. dirPlacesQueryPacket.QueryData.SimName),
  9883. dirPlacesQueryPacket.QueryData.QueryStart);
  9884. }
  9885. private void HandleDirFindQuery(Packet Pack)
  9886. {
  9887. DirFindQueryPacket dirFindQueryPacket = (DirFindQueryPacket)Pack;
  9888. if (dirFindQueryPacket.AgentData.SessionID != SessionId || dirFindQueryPacket.AgentData.AgentID != AgentId)
  9889. return;
  9890. OnDirFindQuery?.Invoke(this,
  9891. dirFindQueryPacket.QueryData.QueryID,
  9892. Utils.BytesToString(
  9893. dirFindQueryPacket.QueryData.QueryText).Trim(),
  9894. dirFindQueryPacket.QueryData.QueryFlags,
  9895. dirFindQueryPacket.QueryData.QueryStart);
  9896. }
  9897. private void HandleDirLandQuery(Packet Pack)
  9898. {
  9899. DirLandQueryPacket dirLandQueryPacket = (DirLandQueryPacket)Pack;
  9900. if (dirLandQueryPacket.AgentData.SessionID != SessionId || dirLandQueryPacket.AgentData.AgentID != AgentId)
  9901. return;
  9902. OnDirLandQuery?.Invoke(this,
  9903. dirLandQueryPacket.QueryData.QueryID,
  9904. dirLandQueryPacket.QueryData.QueryFlags,
  9905. dirLandQueryPacket.QueryData.SearchType,
  9906. dirLandQueryPacket.QueryData.Price,
  9907. dirLandQueryPacket.QueryData.Area,
  9908. dirLandQueryPacket.QueryData.QueryStart);
  9909. }
  9910. private void HandleDirPopularQuery(Packet Pack)
  9911. {
  9912. DirPopularQueryPacket dirPopularQueryPacket = (DirPopularQueryPacket)Pack;
  9913. if (dirPopularQueryPacket.AgentData.SessionID != SessionId || dirPopularQueryPacket.AgentData.AgentID != AgentId)
  9914. return;
  9915. OnDirPopularQuery?.Invoke(this,
  9916. dirPopularQueryPacket.QueryData.QueryID,
  9917. dirPopularQueryPacket.QueryData.QueryFlags);
  9918. }
  9919. private void HandleDirClassifiedQuery(Packet Pack)
  9920. {
  9921. DirClassifiedQueryPacket dirClassifiedQueryPacket = (DirClassifiedQueryPacket)Pack;
  9922. if (dirClassifiedQueryPacket.AgentData.SessionID != SessionId || dirClassifiedQueryPacket.AgentData.AgentID != AgentId)
  9923. return;
  9924. OnDirClassifiedQuery?.Invoke(this,
  9925. dirClassifiedQueryPacket.QueryData.QueryID,
  9926. Utils.BytesToString(
  9927. dirClassifiedQueryPacket.QueryData.QueryText),
  9928. dirClassifiedQueryPacket.QueryData.QueryFlags,
  9929. dirClassifiedQueryPacket.QueryData.Category,
  9930. dirClassifiedQueryPacket.QueryData.QueryStart);
  9931. }
  9932. private void HandleEventInfoRequest(Packet Pack)
  9933. {
  9934. EventInfoRequestPacket eventInfoRequestPacket = (EventInfoRequestPacket)Pack;
  9935. if (eventInfoRequestPacket.AgentData.SessionID != SessionId || eventInfoRequestPacket.AgentData.AgentID != AgentId)
  9936. return;
  9937. OnEventInfoRequest?.Invoke(this, eventInfoRequestPacket.EventData.EventID);
  9938. }
  9939. #endregion
  9940. #region Calling Card
  9941. private void HandleOfferCallingCard(Packet Pack)
  9942. {
  9943. OfferCallingCardPacket offerCallingCardPacket = (OfferCallingCardPacket)Pack;
  9944. if (offerCallingCardPacket.AgentData.SessionID != SessionId || offerCallingCardPacket.AgentData.AgentID != AgentId)
  9945. return;
  9946. OnOfferCallingCard?.Invoke(this,
  9947. offerCallingCardPacket.AgentBlock.DestID,
  9948. offerCallingCardPacket.AgentBlock.TransactionID);
  9949. }
  9950. private void HandleAcceptCallingCard(Packet Pack)
  9951. {
  9952. AcceptCallingCardPacket acceptCallingCardPacket = (AcceptCallingCardPacket)Pack;
  9953. if (acceptCallingCardPacket.AgentData.SessionID != SessionId || acceptCallingCardPacket.AgentData.AgentID != AgentId)
  9954. return;
  9955. // according to http://wiki.secondlife.com/wiki/AcceptCallingCard FolderData should
  9956. // contain exactly one entry
  9957. if (acceptCallingCardPacket.FolderData.Length > 0)
  9958. {
  9959. OnAcceptCallingCard?.Invoke(this,
  9960. acceptCallingCardPacket.TransactionBlock.TransactionID,
  9961. acceptCallingCardPacket.FolderData[0].FolderID);
  9962. }
  9963. }
  9964. private void HandleDeclineCallingCard(Packet Pack)
  9965. {
  9966. DeclineCallingCardPacket declineCallingCardPacket = (DeclineCallingCardPacket)Pack;
  9967. if (declineCallingCardPacket.AgentData.SessionID != SessionId || declineCallingCardPacket.AgentData.AgentID != AgentId)
  9968. return;
  9969. OnDeclineCallingCard?.Invoke(this,
  9970. declineCallingCardPacket.TransactionBlock.TransactionID);
  9971. }
  9972. #endregion Calling Card
  9973. #region Groups
  9974. private void HandleActivateGroup(Packet Pack)
  9975. {
  9976. if (m_GroupsModule == null)
  9977. return;
  9978. ActivateGroupPacket activateGroupPacket = (ActivateGroupPacket)Pack;
  9979. if (activateGroupPacket.AgentData.SessionID != SessionId || activateGroupPacket.AgentData.AgentID != AgentId)
  9980. return;
  9981. m_GroupsModule.ActivateGroup(this, activateGroupPacket.AgentData.GroupID);
  9982. }
  9983. private void HandleGroupVoteHistoryRequest(Packet packet)
  9984. {
  9985. GroupVoteHistoryRequestPacket GroupVoteHistoryRequest = (GroupVoteHistoryRequestPacket)packet;
  9986. if (GroupVoteHistoryRequest.AgentData.SessionID != SessionId || GroupVoteHistoryRequest.AgentData.AgentID != AgentId)
  9987. return;
  9988. OnGroupVoteHistoryRequest?.Invoke(this, AgentId, SessionId, GroupVoteHistoryRequest.GroupData.GroupID, GroupVoteHistoryRequest.TransactionData.TransactionID);
  9989. }
  9990. private void HandleGroupActiveProposalsRequest(Packet packet)
  9991. {
  9992. GroupActiveProposalsRequestPacket GroupActiveProposalsRequest = (GroupActiveProposalsRequestPacket)packet;
  9993. if (GroupActiveProposalsRequest.AgentData.SessionID != SessionId || GroupActiveProposalsRequest.AgentData.AgentID != AgentId)
  9994. return;
  9995. OnGroupActiveProposalsRequest?.Invoke(this, AgentId, SessionId, GroupActiveProposalsRequest.GroupData.GroupID, GroupActiveProposalsRequest.TransactionData.TransactionID);
  9996. }
  9997. private void HandleGroupAccountDetailsRequest(Packet packet)
  9998. {
  9999. GroupAccountDetailsRequestPacket GroupAccountDetailsRequest = (GroupAccountDetailsRequestPacket)packet;
  10000. if (GroupAccountDetailsRequest.AgentData.SessionID != SessionId || GroupAccountDetailsRequest.AgentData.AgentID != AgentId)
  10001. return;
  10002. OnGroupAccountDetailsRequest?.Invoke(this, AgentId, GroupAccountDetailsRequest.AgentData.GroupID, GroupAccountDetailsRequest.MoneyData.RequestID, SessionId);
  10003. }
  10004. private void HandleGroupAccountSummaryRequest(Packet packet)
  10005. {
  10006. GroupAccountSummaryRequestPacket GroupAccountSummaryRequest = (GroupAccountSummaryRequestPacket)packet;
  10007. if (GroupAccountSummaryRequest.AgentData.SessionID != SessionId || GroupAccountSummaryRequest.AgentData.AgentID != AgentId)
  10008. return;
  10009. OnGroupAccountSummaryRequest?.Invoke(this, AgentId,GroupAccountSummaryRequest.AgentData.GroupID);
  10010. }
  10011. private void HandleGroupTransactionsDetailsRequest(Packet packet)
  10012. {
  10013. GroupAccountTransactionsRequestPacket GroupAccountTransactionsRequest = (GroupAccountTransactionsRequestPacket)packet;
  10014. if (GroupAccountTransactionsRequest.AgentData.SessionID != SessionId || GroupAccountTransactionsRequest.AgentData.AgentID != AgentId)
  10015. return;
  10016. OnGroupAccountTransactionsRequest?.Invoke(this, AgentId,GroupAccountTransactionsRequest.AgentData.GroupID,GroupAccountTransactionsRequest.MoneyData.RequestID, SessionId);
  10017. }
  10018. private void HandleGroupTitlesRequest(Packet Pack)
  10019. {
  10020. if (m_GroupsModule == null)
  10021. return;
  10022. GroupTitlesRequestPacket groupTitlesRequest = (GroupTitlesRequestPacket)Pack;
  10023. if (groupTitlesRequest.AgentData.SessionID != SessionId || groupTitlesRequest.AgentData.AgentID != AgentId)
  10024. return;
  10025. GroupTitlesReplyPacket groupTitlesReply = (GroupTitlesReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupTitlesReply);
  10026. groupTitlesReply.AgentData = new GroupTitlesReplyPacket.AgentDataBlock();
  10027. groupTitlesReply.AgentData.AgentID = AgentId;
  10028. groupTitlesReply.AgentData.GroupID = groupTitlesRequest.AgentData.GroupID;
  10029. groupTitlesReply.AgentData.RequestID = groupTitlesRequest.AgentData.RequestID;
  10030. List<GroupTitlesData> titles = m_GroupsModule.GroupTitlesRequest(this,
  10031. groupTitlesRequest.AgentData.GroupID);
  10032. groupTitlesReply.GroupData = new GroupTitlesReplyPacket.GroupDataBlock[titles.Count];
  10033. int i = 0;
  10034. foreach (GroupTitlesData d in titles)
  10035. {
  10036. groupTitlesReply.GroupData[i] = new GroupTitlesReplyPacket.GroupDataBlock();
  10037. groupTitlesReply.GroupData[i].Title = Util.StringToBytes256(d.Name);
  10038. groupTitlesReply.GroupData[i].RoleID = d.UUID;
  10039. groupTitlesReply.GroupData[i].Selected = d.Selected;
  10040. i++;
  10041. }
  10042. OutPacket(groupTitlesReply, ThrottleOutPacketType.Task);
  10043. }
  10044. UUID lastGroupProfileRequestID = UUID.Zero;
  10045. double lastGroupProfileRequestTS = Util.GetTimeStampMS();
  10046. private void HandleGroupProfileRequest(Packet Pack)
  10047. {
  10048. if(m_GroupsModule == null)
  10049. return;
  10050. GroupProfileRequestPacket groupProfileRequest = (GroupProfileRequestPacket)Pack;
  10051. if (groupProfileRequest.AgentData.SessionID != SessionId || groupProfileRequest.AgentData.AgentID != AgentId)
  10052. return;
  10053. UUID grpID = groupProfileRequest.GroupData.GroupID;
  10054. double ts = Util.GetTimeStampMS();
  10055. if(grpID == lastGroupProfileRequestID && ts - lastGroupProfileRequestTS < 10000)
  10056. return;
  10057. lastGroupProfileRequestID = grpID;
  10058. lastGroupProfileRequestTS = ts;
  10059. GroupProfileReplyPacket groupProfileReply = (GroupProfileReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupProfileReply);
  10060. groupProfileReply.AgentData = new GroupProfileReplyPacket.AgentDataBlock();
  10061. groupProfileReply.GroupData = new GroupProfileReplyPacket.GroupDataBlock();
  10062. groupProfileReply.AgentData.AgentID = AgentId;
  10063. GroupProfileData d = m_GroupsModule.GroupProfileRequest(this, groupProfileRequest.GroupData.GroupID);
  10064. if(d.GroupID == UUID.Zero) // don't send broken data
  10065. return;
  10066. groupProfileReply.GroupData.GroupID = d.GroupID;
  10067. groupProfileReply.GroupData.Name = Util.StringToBytes256(d.Name);
  10068. groupProfileReply.GroupData.Charter = Util.StringToBytes1024(d.Charter);
  10069. groupProfileReply.GroupData.ShowInList = d.ShowInList;
  10070. groupProfileReply.GroupData.MemberTitle = Util.StringToBytes256(d.MemberTitle);
  10071. groupProfileReply.GroupData.PowersMask = d.PowersMask;
  10072. groupProfileReply.GroupData.InsigniaID = d.InsigniaID;
  10073. groupProfileReply.GroupData.FounderID = d.FounderID;
  10074. groupProfileReply.GroupData.MembershipFee = d.MembershipFee;
  10075. groupProfileReply.GroupData.OpenEnrollment = d.OpenEnrollment;
  10076. groupProfileReply.GroupData.Money = d.Money;
  10077. groupProfileReply.GroupData.GroupMembershipCount = d.GroupMembershipCount;
  10078. groupProfileReply.GroupData.GroupRolesCount = d.GroupRolesCount;
  10079. groupProfileReply.GroupData.AllowPublish = d.AllowPublish;
  10080. groupProfileReply.GroupData.MaturePublish = d.MaturePublish;
  10081. groupProfileReply.GroupData.OwnerRole = d.OwnerRole;
  10082. if (m_scene.Permissions.IsGod(AgentId) && (!IsGroupMember(groupProfileRequest.GroupData.GroupID)))
  10083. {
  10084. ScenePresence p;
  10085. if (m_scene.TryGetScenePresence(AgentId, out p))
  10086. {
  10087. if (p.IsViewerUIGod)
  10088. {
  10089. groupProfileReply.GroupData.OpenEnrollment = true;
  10090. groupProfileReply.GroupData.MembershipFee = 0;
  10091. }
  10092. }
  10093. }
  10094. OutPacket(groupProfileReply, ThrottleOutPacketType.Task);
  10095. if(grpID == lastGroupProfileRequestID)
  10096. lastGroupProfileRequestTS = Util.GetTimeStampMS() - 7000;
  10097. }
  10098. private void HandleGroupMembersRequest(Packet Pack)
  10099. {
  10100. if (m_GroupsModule == null)
  10101. return;
  10102. GroupMembersRequestPacket groupMembersRequestPacket =
  10103. (GroupMembersRequestPacket)Pack;
  10104. if (groupMembersRequestPacket.AgentData.SessionID != SessionId || groupMembersRequestPacket.AgentData.AgentID != AgentId)
  10105. return;
  10106. List<GroupMembersData> members =
  10107. m_GroupsModule.GroupMembersRequest(this, groupMembersRequestPacket.GroupData.GroupID);
  10108. int memberCount = members.Count;
  10109. int indx = 0;
  10110. while (indx < memberCount)
  10111. {
  10112. int blockCount = memberCount - indx;
  10113. if (blockCount > 25)
  10114. blockCount = 25;
  10115. GroupMembersReplyPacket groupMembersReply = (GroupMembersReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupMembersReply);
  10116. groupMembersReply.AgentData = new GroupMembersReplyPacket.AgentDataBlock();
  10117. groupMembersReply.GroupData = new GroupMembersReplyPacket.GroupDataBlock();
  10118. groupMembersReply.MemberData = new GroupMembersReplyPacket.MemberDataBlock[blockCount];
  10119. groupMembersReply.AgentData.AgentID = AgentId;
  10120. groupMembersReply.GroupData.GroupID = groupMembersRequestPacket.GroupData.GroupID;
  10121. groupMembersReply.GroupData.RequestID = groupMembersRequestPacket.GroupData.RequestID;
  10122. groupMembersReply.GroupData.MemberCount = memberCount;
  10123. for (int i = 0; i < blockCount; i++)
  10124. {
  10125. GroupMembersData m = members[indx++];
  10126. groupMembersReply.MemberData[i] = new GroupMembersReplyPacket.MemberDataBlock();
  10127. groupMembersReply.MemberData[i].AgentID = m.AgentID;
  10128. groupMembersReply.MemberData[i].Contribution = m.Contribution;
  10129. groupMembersReply.MemberData[i].OnlineStatus = Util.StringToBytes256(m.OnlineStatus);
  10130. groupMembersReply.MemberData[i].AgentPowers = m.AgentPowers;
  10131. groupMembersReply.MemberData[i].Title = Util.StringToBytes256(m.Title);
  10132. groupMembersReply.MemberData[i].IsOwner = m.IsOwner;
  10133. }
  10134. OutPacket(groupMembersReply, ThrottleOutPacketType.Task);
  10135. }
  10136. }
  10137. private void HandleGroupRoleDataRequest(Packet Pack)
  10138. {
  10139. if (m_GroupsModule == null)
  10140. return;
  10141. GroupRoleDataRequestPacket groupRolesRequest = (GroupRoleDataRequestPacket)Pack;
  10142. if (groupRolesRequest.AgentData.SessionID != SessionId || groupRolesRequest.AgentData.AgentID != AgentId)
  10143. return;
  10144. GroupRoleDataReplyPacket groupRolesReply = (GroupRoleDataReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupRoleDataReply);
  10145. groupRolesReply.AgentData = new GroupRoleDataReplyPacket.AgentDataBlock();
  10146. groupRolesReply.AgentData.AgentID = AgentId;
  10147. groupRolesReply.GroupData = new GroupRoleDataReplyPacket.GroupDataBlock();
  10148. groupRolesReply.GroupData.GroupID = groupRolesRequest.GroupData.GroupID;
  10149. groupRolesReply.GroupData.RequestID = groupRolesRequest.GroupData.RequestID;
  10150. List<GroupRolesData> titles = m_GroupsModule.GroupRoleDataRequest(this,
  10151. groupRolesRequest.GroupData.GroupID);
  10152. groupRolesReply.GroupData.RoleCount = titles.Count;
  10153. groupRolesReply.RoleData = new GroupRoleDataReplyPacket.RoleDataBlock[titles.Count];
  10154. int i = 0;
  10155. foreach (GroupRolesData d in titles)
  10156. {
  10157. groupRolesReply.RoleData[i] = new GroupRoleDataReplyPacket.RoleDataBlock();
  10158. groupRolesReply.RoleData[i].RoleID = d.RoleID;
  10159. groupRolesReply.RoleData[i].Name = Util.StringToBytes256(d.Name);
  10160. groupRolesReply.RoleData[i].Title = Util.StringToBytes256(d.Title);
  10161. groupRolesReply.RoleData[i].Description = Util.StringToBytes1024(d.Description);
  10162. groupRolesReply.RoleData[i].Powers = d.Powers;
  10163. groupRolesReply.RoleData[i].Members = (uint)d.Members;
  10164. i++;
  10165. }
  10166. OutPacket(groupRolesReply, ThrottleOutPacketType.Task);
  10167. }
  10168. private void HandleGroupRoleMembersRequest(Packet Pack)
  10169. {
  10170. if (m_GroupsModule == null)
  10171. return;
  10172. GroupRoleMembersRequestPacket groupRoleMembersRequest = (GroupRoleMembersRequestPacket)Pack;
  10173. if (groupRoleMembersRequest.AgentData.SessionID != SessionId || groupRoleMembersRequest.AgentData.AgentID != AgentId)
  10174. return;
  10175. List<GroupRoleMembersData> mappings = m_GroupsModule.GroupRoleMembersRequest(this,
  10176. groupRoleMembersRequest.GroupData.GroupID);
  10177. int mappingsCount = mappings.Count;
  10178. while (mappings.Count > 0)
  10179. {
  10180. int pairs = mappings.Count;
  10181. if (pairs > 32)
  10182. pairs = 32;
  10183. GroupRoleMembersReplyPacket groupRoleMembersReply = (GroupRoleMembersReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupRoleMembersReply);
  10184. groupRoleMembersReply.AgentData = new GroupRoleMembersReplyPacket.AgentDataBlock();
  10185. groupRoleMembersReply.AgentData.AgentID = AgentId;
  10186. groupRoleMembersReply.AgentData.GroupID = groupRoleMembersRequest.GroupData.GroupID;
  10187. groupRoleMembersReply.AgentData.RequestID = groupRoleMembersRequest.GroupData.RequestID;
  10188. groupRoleMembersReply.AgentData.TotalPairs = (uint)mappingsCount;
  10189. groupRoleMembersReply.MemberData = new GroupRoleMembersReplyPacket.MemberDataBlock[pairs];
  10190. for (int i = 0; i < pairs; i++)
  10191. {
  10192. GroupRoleMembersData d = mappings[0];
  10193. mappings.RemoveAt(0);
  10194. groupRoleMembersReply.MemberData[i] = new GroupRoleMembersReplyPacket.MemberDataBlock();
  10195. groupRoleMembersReply.MemberData[i].RoleID = d.RoleID;
  10196. groupRoleMembersReply.MemberData[i].MemberID = d.MemberID;
  10197. }
  10198. OutPacket(groupRoleMembersReply, ThrottleOutPacketType.Task);
  10199. }
  10200. }
  10201. private void HandleCreateGroupRequest(Packet Pack)
  10202. {
  10203. if (m_GroupsModule == null)
  10204. return;
  10205. CreateGroupRequestPacket createGroupRequest = (CreateGroupRequestPacket)Pack;
  10206. if (createGroupRequest.AgentData.SessionID != SessionId || createGroupRequest.AgentData.AgentID != AgentId)
  10207. return;
  10208. m_GroupsModule.CreateGroup(this,
  10209. Utils.BytesToString(createGroupRequest.GroupData.Name),
  10210. Utils.BytesToString(createGroupRequest.GroupData.Charter),
  10211. createGroupRequest.GroupData.ShowInList,
  10212. createGroupRequest.GroupData.InsigniaID,
  10213. createGroupRequest.GroupData.MembershipFee,
  10214. createGroupRequest.GroupData.OpenEnrollment,
  10215. createGroupRequest.GroupData.AllowPublish,
  10216. createGroupRequest.GroupData.MaturePublish);
  10217. }
  10218. private void HandleUpdateGroupInfo(Packet Pack)
  10219. {
  10220. if (m_GroupsModule == null)
  10221. return;
  10222. UpdateGroupInfoPacket updateGroupInfo = (UpdateGroupInfoPacket)Pack;
  10223. if (updateGroupInfo.AgentData.SessionID != SessionId || updateGroupInfo.AgentData.AgentID != AgentId)
  10224. return;
  10225. m_GroupsModule.UpdateGroupInfo(this,
  10226. updateGroupInfo.GroupData.GroupID,
  10227. Utils.BytesToString(updateGroupInfo.GroupData.Charter),
  10228. updateGroupInfo.GroupData.ShowInList,
  10229. updateGroupInfo.GroupData.InsigniaID,
  10230. updateGroupInfo.GroupData.MembershipFee,
  10231. updateGroupInfo.GroupData.OpenEnrollment,
  10232. updateGroupInfo.GroupData.AllowPublish,
  10233. updateGroupInfo.GroupData.MaturePublish);
  10234. }
  10235. private void HandleSetGroupAcceptNotices(Packet Pack)
  10236. {
  10237. if (m_GroupsModule == null)
  10238. return;
  10239. SetGroupAcceptNoticesPacket setGroupAcceptNotices = (SetGroupAcceptNoticesPacket)Pack;
  10240. if (setGroupAcceptNotices.AgentData.SessionID != SessionId || setGroupAcceptNotices.AgentData.AgentID != AgentId)
  10241. return;
  10242. m_GroupsModule.SetGroupAcceptNotices(this,
  10243. setGroupAcceptNotices.Data.GroupID,
  10244. setGroupAcceptNotices.Data.AcceptNotices,
  10245. setGroupAcceptNotices.NewData.ListInProfile);
  10246. }
  10247. private void HandleGroupTitleUpdate(Packet Pack)
  10248. {
  10249. GroupTitleUpdatePacket groupTitleUpdate = (GroupTitleUpdatePacket)Pack;
  10250. if (groupTitleUpdate.AgentData.SessionID != SessionId || groupTitleUpdate.AgentData.AgentID != AgentId)
  10251. return;
  10252. m_GroupsModule.GroupTitleUpdate(this,
  10253. groupTitleUpdate.AgentData.GroupID,
  10254. groupTitleUpdate.AgentData.TitleRoleID);
  10255. }
  10256. private void HandleParcelDeedToGroup(Packet Pack)
  10257. {
  10258. if (m_GroupsModule == null)
  10259. return;
  10260. ParcelDeedToGroupPacket parcelDeedToGroup = (ParcelDeedToGroupPacket)Pack;
  10261. if (parcelDeedToGroup.AgentData.SessionID != SessionId || parcelDeedToGroup.AgentData.AgentID != AgentId)
  10262. return;
  10263. OnParcelDeedToGroup?.Invoke(parcelDeedToGroup.Data.LocalID, parcelDeedToGroup.Data.GroupID, this);
  10264. }
  10265. private void HandleGroupNoticesListRequest(Packet Pack)
  10266. {
  10267. if (m_GroupsModule == null)
  10268. return;
  10269. GroupNoticesListRequestPacket groupNoticesListRequest = (GroupNoticesListRequestPacket)Pack;
  10270. if (groupNoticesListRequest.AgentData.SessionID != SessionId || groupNoticesListRequest.AgentData.AgentID != AgentId)
  10271. return;
  10272. GroupNoticeData[] gn = m_GroupsModule.GroupNoticesListRequest(this,
  10273. groupNoticesListRequest.Data.GroupID);
  10274. GroupNoticesListReplyPacket groupNoticesListReply = (GroupNoticesListReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupNoticesListReply);
  10275. groupNoticesListReply.AgentData = new GroupNoticesListReplyPacket.AgentDataBlock();
  10276. groupNoticesListReply.AgentData.AgentID = AgentId;
  10277. groupNoticesListReply.AgentData.GroupID = groupNoticesListRequest.Data.GroupID;
  10278. groupNoticesListReply.Data = new GroupNoticesListReplyPacket.DataBlock[gn.Length];
  10279. int i = 0;
  10280. foreach (GroupNoticeData g in gn)
  10281. {
  10282. groupNoticesListReply.Data[i] = new GroupNoticesListReplyPacket.DataBlock();
  10283. groupNoticesListReply.Data[i].NoticeID = g.NoticeID;
  10284. groupNoticesListReply.Data[i].Timestamp = g.Timestamp;
  10285. groupNoticesListReply.Data[i].FromName = Util.StringToBytes256(g.FromName);
  10286. groupNoticesListReply.Data[i].Subject = Util.StringToBytes256(g.Subject);
  10287. groupNoticesListReply.Data[i].HasAttachment = g.HasAttachment;
  10288. groupNoticesListReply.Data[i].AssetType = g.AssetType;
  10289. i++;
  10290. }
  10291. OutPacket(groupNoticesListReply, ThrottleOutPacketType.Task);
  10292. }
  10293. private void HandleGroupNoticeRequest(Packet Pack)
  10294. {
  10295. if (m_GroupsModule == null)
  10296. return;
  10297. GroupNoticeRequestPacket groupNoticeRequest = (GroupNoticeRequestPacket)Pack;
  10298. if (groupNoticeRequest.AgentData.SessionID != SessionId || groupNoticeRequest.AgentData.AgentID != AgentId)
  10299. return;
  10300. m_GroupsModule.GroupNoticeRequest(this, groupNoticeRequest.Data.GroupNoticeID);
  10301. }
  10302. private void HandleGroupRoleUpdate(Packet Pack)
  10303. {
  10304. if (m_GroupsModule == null)
  10305. return;
  10306. GroupRoleUpdatePacket groupRoleUpdate = (GroupRoleUpdatePacket)Pack;
  10307. if (groupRoleUpdate.AgentData.SessionID != SessionId || groupRoleUpdate.AgentData.AgentID != AgentId)
  10308. return;
  10309. foreach (GroupRoleUpdatePacket.RoleDataBlock d in groupRoleUpdate.RoleData)
  10310. {
  10311. m_GroupsModule.GroupRoleUpdate(this,
  10312. groupRoleUpdate.AgentData.GroupID,
  10313. d.RoleID,
  10314. Utils.BytesToString(d.Name),
  10315. Utils.BytesToString(d.Description),
  10316. Utils.BytesToString(d.Title),
  10317. d.Powers,
  10318. d.UpdateType);
  10319. }
  10320. m_GroupsModule.NotifyChange(groupRoleUpdate.AgentData.GroupID);
  10321. }
  10322. private void HandleGroupRoleChanges(Packet Pack)
  10323. {
  10324. if (m_GroupsModule == null)
  10325. return;
  10326. GroupRoleChangesPacket groupRoleChanges = (GroupRoleChangesPacket)Pack;
  10327. if (groupRoleChanges.AgentData.SessionID != SessionId || groupRoleChanges.AgentData.AgentID != AgentId)
  10328. return;
  10329. foreach (GroupRoleChangesPacket.RoleChangeBlock d in groupRoleChanges.RoleChange)
  10330. {
  10331. m_GroupsModule.GroupRoleChanges(this,
  10332. groupRoleChanges.AgentData.GroupID,
  10333. d.RoleID,
  10334. d.MemberID,
  10335. d.Change);
  10336. }
  10337. m_GroupsModule.NotifyChange(groupRoleChanges.AgentData.GroupID);
  10338. }
  10339. private void HandleJoinGroupRequest(Packet Pack)
  10340. {
  10341. if (m_GroupsModule == null)
  10342. return;
  10343. JoinGroupRequestPacket joinGroupRequest = (JoinGroupRequestPacket)Pack;
  10344. if (joinGroupRequest.AgentData.SessionID != SessionId || joinGroupRequest.AgentData.AgentID != AgentId)
  10345. return;
  10346. m_GroupsModule.JoinGroupRequest(this, joinGroupRequest.GroupData.GroupID);
  10347. }
  10348. private void HandleLeaveGroupRequest(Packet Pack)
  10349. {
  10350. if (m_GroupsModule == null)
  10351. return;
  10352. LeaveGroupRequestPacket leaveGroupRequest = (LeaveGroupRequestPacket)Pack;
  10353. if (leaveGroupRequest.AgentData.SessionID != SessionId || leaveGroupRequest.AgentData.AgentID != AgentId)
  10354. return;
  10355. m_GroupsModule.LeaveGroupRequest(this, leaveGroupRequest.GroupData.GroupID);
  10356. }
  10357. private void HandleEjectGroupMemberRequest(Packet Pack)
  10358. {
  10359. if (m_GroupsModule == null)
  10360. return;
  10361. EjectGroupMemberRequestPacket ejectGroupMemberRequest = (EjectGroupMemberRequestPacket)Pack;
  10362. if (ejectGroupMemberRequest.AgentData.SessionID != SessionId || ejectGroupMemberRequest.AgentData.AgentID != AgentId)
  10363. return;
  10364. foreach (EjectGroupMemberRequestPacket.EjectDataBlock e in ejectGroupMemberRequest.EjectData)
  10365. {
  10366. m_GroupsModule.EjectGroupMemberRequest(this,
  10367. ejectGroupMemberRequest.GroupData.GroupID,
  10368. e.EjecteeID);
  10369. }
  10370. }
  10371. private void HandleInviteGroupRequest(Packet Pack)
  10372. {
  10373. if (m_GroupsModule == null)
  10374. return;
  10375. InviteGroupRequestPacket inviteGroupRequest = (InviteGroupRequestPacket)Pack;
  10376. if (inviteGroupRequest.AgentData.SessionID != SessionId || inviteGroupRequest.AgentData.AgentID != AgentId)
  10377. return;
  10378. foreach (InviteGroupRequestPacket.InviteDataBlock b in inviteGroupRequest.InviteData)
  10379. {
  10380. m_GroupsModule.InviteGroupRequest(this,
  10381. inviteGroupRequest.GroupData.GroupID,
  10382. b.InviteeID,
  10383. b.RoleID);
  10384. }
  10385. }
  10386. #endregion Groups
  10387. private void HandleStartLure(Packet Pack)
  10388. {
  10389. if(OnStartLure == null)
  10390. return;
  10391. StartLurePacket startLureRequest = (StartLurePacket)Pack;
  10392. if (startLureRequest.AgentData.SessionID != SessionId || startLureRequest.AgentData.AgentID != AgentId)
  10393. return;
  10394. for (int i = 0 ; i < startLureRequest.TargetData.Length ; i++)
  10395. {
  10396. OnStartLure?.Invoke(startLureRequest.Info.LureType,
  10397. Utils.BytesToString(
  10398. startLureRequest.Info.Message),
  10399. startLureRequest.TargetData[i].TargetID,
  10400. this);
  10401. }
  10402. }
  10403. private void HandleTeleportLureRequest(Packet Pack)
  10404. {
  10405. TeleportLureRequestPacket teleportLureRequest = (TeleportLureRequestPacket)Pack;
  10406. if (teleportLureRequest.Info.SessionID != SessionId || teleportLureRequest.Info.AgentID != AgentId)
  10407. return;
  10408. OnTeleportLureRequest?.Invoke(
  10409. teleportLureRequest.Info.LureID,
  10410. teleportLureRequest.Info.TeleportFlags,
  10411. this);
  10412. }
  10413. private void HandleClassifiedInfoRequest(Packet Pack)
  10414. {
  10415. ClassifiedInfoRequestPacket classifiedInfoRequest = (ClassifiedInfoRequestPacket)Pack;
  10416. if (classifiedInfoRequest.AgentData.SessionID != SessionId || classifiedInfoRequest.AgentData.AgentID != AgentId)
  10417. return;
  10418. OnClassifiedInfoRequest?.Invoke(
  10419. classifiedInfoRequest.Data.ClassifiedID,
  10420. this);
  10421. }
  10422. private void HandleClassifiedInfoUpdate(Packet Pack)
  10423. {
  10424. ClassifiedInfoUpdatePacket classifiedInfoUpdate = (ClassifiedInfoUpdatePacket)Pack;
  10425. if (classifiedInfoUpdate.AgentData.SessionID != SessionId || classifiedInfoUpdate.AgentData.AgentID != AgentId)
  10426. return;
  10427. // fix classifiedFlags maturity
  10428. byte classifiedFlags = classifiedInfoUpdate.Data.ClassifiedFlags;
  10429. if ((classifiedFlags & 0x4e) == 0) // if none
  10430. classifiedFlags |= 0x4; // pg
  10431. OnClassifiedInfoUpdate?.Invoke(
  10432. classifiedInfoUpdate.Data.ClassifiedID,
  10433. classifiedInfoUpdate.Data.Category,
  10434. Utils.BytesToString(
  10435. classifiedInfoUpdate.Data.Name),
  10436. Utils.BytesToString(
  10437. classifiedInfoUpdate.Data.Desc),
  10438. classifiedInfoUpdate.Data.ParcelID,
  10439. classifiedInfoUpdate.Data.ParentEstate,
  10440. classifiedInfoUpdate.Data.SnapshotID,
  10441. new Vector3(
  10442. classifiedInfoUpdate.Data.PosGlobal),
  10443. classifiedFlags,
  10444. classifiedInfoUpdate.Data.PriceForListing,
  10445. this);
  10446. }
  10447. private void HandleClassifiedDelete(Packet Pack)
  10448. {
  10449. ClassifiedDeletePacket classifiedDelete = (ClassifiedDeletePacket)Pack;
  10450. if (classifiedDelete.AgentData.SessionID != SessionId || classifiedDelete.AgentData.AgentID != AgentId)
  10451. return;
  10452. OnClassifiedDelete?.Invoke(
  10453. classifiedDelete.Data.ClassifiedID,
  10454. this);
  10455. }
  10456. private void HandleClassifiedGodDelete(Packet Pack)
  10457. {
  10458. ClassifiedGodDeletePacket classifiedGodDelete = (ClassifiedGodDeletePacket)Pack;
  10459. if (classifiedGodDelete.AgentData.SessionID != SessionId || classifiedGodDelete.AgentData.AgentID != AgentId)
  10460. return;
  10461. OnClassifiedGodDelete?.Invoke(
  10462. classifiedGodDelete.Data.ClassifiedID,
  10463. classifiedGodDelete.Data.QueryID,
  10464. this);
  10465. }
  10466. private void HandleEventGodDelete(Packet Pack)
  10467. {
  10468. EventGodDeletePacket eventGodDelete = (EventGodDeletePacket)Pack;
  10469. if (eventGodDelete.AgentData.SessionID != SessionId || eventGodDelete.AgentData.AgentID != AgentId)
  10470. return;
  10471. OnEventGodDelete?.Invoke(
  10472. eventGodDelete.EventData.EventID,
  10473. eventGodDelete.QueryData.QueryID,
  10474. Utils.BytesToString(
  10475. eventGodDelete.QueryData.QueryText),
  10476. eventGodDelete.QueryData.QueryFlags,
  10477. eventGodDelete.QueryData.QueryStart,
  10478. this);
  10479. }
  10480. private void HandleEventNotificationAddRequest(Packet Pack)
  10481. {
  10482. EventNotificationAddRequestPacket eventNotificationAdd = (EventNotificationAddRequestPacket)Pack;
  10483. if (eventNotificationAdd.AgentData.SessionID != SessionId || eventNotificationAdd.AgentData.AgentID != AgentId)
  10484. return;
  10485. OnEventNotificationAddRequest?.Invoke(eventNotificationAdd.EventData.EventID, this);
  10486. }
  10487. private void HandleEventNotificationRemoveRequest(Packet Pack)
  10488. {
  10489. EventNotificationRemoveRequestPacket eventNotificationRemove = (EventNotificationRemoveRequestPacket)Pack;
  10490. if (eventNotificationRemove.AgentData.SessionID != SessionId || eventNotificationRemove.AgentData.AgentID != AgentId)
  10491. return;
  10492. OnEventNotificationRemoveRequest?.Invoke(eventNotificationRemove.EventData.EventID, this);
  10493. }
  10494. private void HandleRetrieveInstantMessages(Packet Pack)
  10495. {
  10496. RetrieveInstantMessagesPacket rimpInstantMessagePack = (RetrieveInstantMessagesPacket)Pack;
  10497. if (rimpInstantMessagePack.AgentData.SessionID != SessionId || rimpInstantMessagePack.AgentData.AgentID != AgentId)
  10498. return;
  10499. OnRetrieveInstantMessages?.Invoke(this);
  10500. }
  10501. private void HandlePickDelete(Packet Pack)
  10502. {
  10503. PickDeletePacket pickDelete = (PickDeletePacket)Pack;
  10504. if (pickDelete.AgentData.SessionID != SessionId || pickDelete.AgentData.AgentID != AgentId)
  10505. return;
  10506. OnPickDelete?.Invoke(this, pickDelete.Data.PickID);
  10507. }
  10508. private void HandlePickGodDelete(Packet Pack)
  10509. {
  10510. PickGodDeletePacket pickGodDelete = (PickGodDeletePacket)Pack;
  10511. if (pickGodDelete.AgentData.SessionID != SessionId || pickGodDelete.AgentData.AgentID != AgentId)
  10512. return;
  10513. OnPickGodDelete?.Invoke(this,
  10514. pickGodDelete.AgentData.AgentID,
  10515. pickGodDelete.Data.PickID,
  10516. pickGodDelete.Data.QueryID);
  10517. }
  10518. private void HandlePickInfoUpdate(Packet Pack)
  10519. {
  10520. PickInfoUpdatePacket pickInfoUpdate = (PickInfoUpdatePacket)Pack;
  10521. if (pickInfoUpdate.AgentData.SessionID != SessionId || pickInfoUpdate.AgentData.AgentID != AgentId)
  10522. return;
  10523. OnPickInfoUpdate?.Invoke(this,
  10524. pickInfoUpdate.Data.PickID,
  10525. pickInfoUpdate.Data.CreatorID,
  10526. pickInfoUpdate.Data.TopPick,
  10527. Utils.BytesToString(pickInfoUpdate.Data.Name),
  10528. Utils.BytesToString(pickInfoUpdate.Data.Desc),
  10529. pickInfoUpdate.Data.SnapshotID,
  10530. pickInfoUpdate.Data.SortOrder,
  10531. pickInfoUpdate.Data.Enabled);
  10532. }
  10533. private void HandleAvatarNotesUpdate(Packet Pack)
  10534. {
  10535. AvatarNotesUpdatePacket avatarNotesUpdate = (AvatarNotesUpdatePacket)Pack;
  10536. if (avatarNotesUpdate.AgentData.SessionID != SessionId || avatarNotesUpdate.AgentData.AgentID != AgentId)
  10537. return;
  10538. OnAvatarNotesUpdate?.Invoke(this,
  10539. avatarNotesUpdate.Data.TargetID,
  10540. Utils.BytesToString(avatarNotesUpdate.Data.Notes));
  10541. }
  10542. private void HandleAvatarInterestsUpdate(Packet Pack)
  10543. {
  10544. AvatarInterestsUpdatePacket avatarInterestUpdate = (AvatarInterestsUpdatePacket)Pack;
  10545. if (avatarInterestUpdate.AgentData.SessionID != SessionId || avatarInterestUpdate.AgentData.AgentID != AgentId)
  10546. return;
  10547. OnAvatarInterestUpdate?.Invoke(this,
  10548. avatarInterestUpdate.PropertiesData.WantToMask,
  10549. Utils.BytesToString(avatarInterestUpdate.PropertiesData.WantToText),
  10550. avatarInterestUpdate.PropertiesData.SkillsMask,
  10551. Utils.BytesToString(avatarInterestUpdate.PropertiesData.SkillsText),
  10552. Utils.BytesToString(avatarInterestUpdate.PropertiesData.LanguagesText));
  10553. }
  10554. private void HandleGrantUserRights(Packet Pack)
  10555. {
  10556. GrantUserRightsPacket GrantUserRights = (GrantUserRightsPacket)Pack;
  10557. if (GrantUserRights.AgentData.SessionID != SessionId || GrantUserRights.AgentData.AgentID != AgentId)
  10558. return;
  10559. OnGrantUserRights?.Invoke(this,
  10560. GrantUserRights.Rights[0].AgentRelated,
  10561. GrantUserRights.Rights[0].RelatedRights);
  10562. }
  10563. private double m_nextRevokePermissionsTime = Double.MinValue;
  10564. private uint m_lastRevokePermissionsSeq = uint.MinValue;
  10565. private void HandleRevokePermissions(Packet Pack)
  10566. {
  10567. RevokePermissionsPacket pkt = (RevokePermissionsPacket)Pack;
  10568. if (pkt.AgentData.SessionID != SessionId || pkt .AgentData.AgentID != AgentId)
  10569. return;
  10570. uint thisSeq = pkt.Header.Sequence;
  10571. if (thisSeq == m_lastRevokePermissionsSeq)
  10572. return;
  10573. m_lastRevokePermissionsSeq = thisSeq;
  10574. ScenePresence sp = (ScenePresence)SceneAgent;
  10575. if(sp != null && !sp.IsDeleted && !sp.IsInTransit)
  10576. {
  10577. UUID objectID = pkt.Data.ObjectID;
  10578. double now = Util.GetTimeStampMS();
  10579. if (now < m_nextRevokePermissionsTime)
  10580. return;
  10581. if (objectID == m_scene.RegionInfo.RegionID)
  10582. m_nextRevokePermissionsTime = now + 2000;
  10583. else
  10584. m_nextRevokePermissionsTime = now + 50;
  10585. uint permissions = pkt.Data.ObjectPermissions;
  10586. sp.HandleRevokePermissions(objectID , permissions);
  10587. }
  10588. }
  10589. private void HandlePlacesQuery(Packet Pack)
  10590. {
  10591. PlacesQueryPacket placesQueryPacket = (PlacesQueryPacket)Pack;
  10592. if (placesQueryPacket.AgentData.SessionID != SessionId || placesQueryPacket.AgentData.AgentID != AgentId)
  10593. return;
  10594. OnPlacesQuery?.Invoke(placesQueryPacket.AgentData.QueryID,
  10595. placesQueryPacket.TransactionData.TransactionID,
  10596. Utils.BytesToString(
  10597. placesQueryPacket.QueryData.QueryText),
  10598. placesQueryPacket.QueryData.QueryFlags,
  10599. (byte)placesQueryPacket.QueryData.Category,
  10600. Utils.BytesToString(
  10601. placesQueryPacket.QueryData.SimName),
  10602. this);
  10603. }
  10604. #endregion Packet Handlers
  10605. public void SendScriptQuestion(UUID taskID, string taskName, string ownerName, UUID itemID, int question)
  10606. {
  10607. ScriptQuestionPacket scriptQuestion = (ScriptQuestionPacket)PacketPool.Instance.GetPacket(PacketType.ScriptQuestion);
  10608. scriptQuestion.Data = new ScriptQuestionPacket.DataBlock();
  10609. // TODO: don't create new blocks if recycling an old packet
  10610. scriptQuestion.Data.TaskID = taskID;
  10611. scriptQuestion.Data.ItemID = itemID;
  10612. scriptQuestion.Data.Questions = question;
  10613. scriptQuestion.Data.ObjectName = Util.StringToBytes256(taskName);
  10614. scriptQuestion.Data.ObjectOwner = Util.StringToBytes256(ownerName);
  10615. OutPacket(scriptQuestion, ThrottleOutPacketType.Task);
  10616. }
  10617. /// <summary>
  10618. /// Handler called when we receive a logout packet.
  10619. /// </summary>
  10620. /// <param name="client"></param>
  10621. /// <param name="packet"></param>
  10622. /// <returns></returns>
  10623. protected virtual void HandleLogout(Packet packet)
  10624. {
  10625. if (packet.Type == PacketType.LogoutRequest)
  10626. {
  10627. if (((LogoutRequestPacket)packet).AgentData.SessionID != SessionId)
  10628. return;
  10629. }
  10630. Logout(this);
  10631. }
  10632. /// <summary>
  10633. ///
  10634. /// </summary>
  10635. /// <param name="client"></param>
  10636. /// <returns></returns>
  10637. protected virtual void Logout(IClientAPI client)
  10638. {
  10639. m_log.InfoFormat("[CLIENT]: Got a logout request for {0} in {1}", Name, Scene.RegionInfo.RegionName);
  10640. OnLogout?.Invoke(client);
  10641. }
  10642. /// <summary>
  10643. /// </summary>
  10644. /// <remarks>
  10645. /// At the moment, we always reply that there is no cached texture.
  10646. /// </remarks>
  10647. /// <param name="simclient"></param>
  10648. /// <param name="packet"></param>
  10649. /// <returns></returns>
  10650. protected void HandleAgentTextureCached(Packet packet)
  10651. {
  10652. //m_log.Debug("texture cached: " + packet.ToString());
  10653. AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet;
  10654. AgentCachedTextureResponsePacket cachedresp =
  10655. (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
  10656. if (cachedtex.AgentData.SessionID != SessionId || cachedtex.AgentData.AgentID != AgentId)
  10657. return;
  10658. // TODO: don't create new blocks if recycling an old packet
  10659. cachedresp.AgentData.AgentID = AgentId;
  10660. cachedresp.AgentData.SessionID = m_sessionId;
  10661. cachedresp.AgentData.SerialNum = cachedtex.AgentData.SerialNum;
  10662. cachedresp.WearableData =
  10663. new AgentCachedTextureResponsePacket.WearableDataBlock[cachedtex.WearableData.Length];
  10664. int cacheHits = 0;
  10665. // 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
  10666. WearableCacheItem[] cacheItems = null;
  10667. ScenePresence p = m_scene.GetScenePresence(AgentId);
  10668. if (p != null && p.Appearance != null)
  10669. {
  10670. cacheItems = p.Appearance.WearableCacheItems;
  10671. }
  10672. int maxWearablesLoop = cachedtex.WearableData.Length;
  10673. if (cacheItems != null)
  10674. {
  10675. if (maxWearablesLoop > cacheItems.Length)
  10676. maxWearablesLoop = cacheItems.Length;
  10677. for (int i = 0; i < maxWearablesLoop; i++)
  10678. {
  10679. int idx = cachedtex.WearableData[i].TextureIndex;
  10680. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  10681. cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
  10682. cachedresp.WearableData[i].HostName = new byte[0];
  10683. if (cachedtex.WearableData[i].ID == cacheItems[idx].CacheId)
  10684. {
  10685. cachedresp.WearableData[i].TextureID = cacheItems[idx].TextureID;
  10686. cacheHits++;
  10687. }
  10688. else
  10689. {
  10690. cachedresp.WearableData[i].TextureID = UUID.Zero;
  10691. }
  10692. }
  10693. }
  10694. else
  10695. {
  10696. for (int i = 0; i < maxWearablesLoop; i++)
  10697. {
  10698. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  10699. cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
  10700. cachedresp.WearableData[i].TextureID = UUID.Zero;
  10701. cachedresp.WearableData[i].HostName = new byte[0];
  10702. }
  10703. }
  10704. //m_log.DebugFormat("texture cached: hits {0}", cacheHits);
  10705. cachedresp.Header.Zerocoded = true;
  10706. OutPacket(cachedresp, ThrottleOutPacketType.Task);
  10707. }
  10708. /// <summary>
  10709. /// Send a response back to a client when it asks the asset server (via the region server) if it has
  10710. /// its appearance texture cached.
  10711. /// </summary>
  10712. /// <param name="avatar"></param>
  10713. /// <param name="serial"></param>
  10714. /// <param name="cachedTextures"></param>
  10715. /// <returns></returns>
  10716. public void SendCachedTextureResponse(ISceneEntity avatar, int serial, List<CachedTextureResponseArg> cachedTextures)
  10717. {
  10718. ScenePresence presence = avatar as ScenePresence;
  10719. if (presence == null)
  10720. return;
  10721. AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
  10722. // TODO: don't create new blocks if recycling an old packet
  10723. cachedresp.AgentData.AgentID = m_agentId;
  10724. cachedresp.AgentData.SessionID = m_sessionId;
  10725. cachedresp.AgentData.SerialNum = serial;
  10726. cachedresp.WearableData = new AgentCachedTextureResponsePacket.WearableDataBlock[cachedTextures.Count];
  10727. for (int i = 0; i < cachedTextures.Count; i++)
  10728. {
  10729. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  10730. cachedresp.WearableData[i].TextureIndex = (byte)cachedTextures[i].BakedTextureIndex;
  10731. cachedresp.WearableData[i].TextureID = cachedTextures[i].BakedTextureID;
  10732. cachedresp.WearableData[i].HostName = new byte[0];
  10733. }
  10734. cachedresp.Header.Zerocoded = true;
  10735. OutPacket(cachedresp, ThrottleOutPacketType.Task);
  10736. }
  10737. protected void HandleMultipleObjUpdate(Packet packet)
  10738. {
  10739. MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
  10740. if (multipleupdate.AgentData.SessionID != SessionId || multipleupdate.AgentData.AgentID != AgentId)
  10741. return;
  10742. // m_log.DebugFormat(
  10743. // "[CLIENT]: Incoming MultipleObjectUpdatePacket contained {0} blocks", multipleupdate.ObjectData.Length);
  10744. Scene tScene = (Scene)m_scene;
  10745. for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
  10746. {
  10747. MultipleObjectUpdatePacket.ObjectDataBlock block = multipleupdate.ObjectData[i];
  10748. // Can't act on Null Data
  10749. if (block.Data != null)
  10750. {
  10751. uint localId = block.ObjectLocalID;
  10752. SceneObjectPart part = tScene.GetSceneObjectPart(localId);
  10753. if (part == null)
  10754. {
  10755. // It's a ghost! tell the client to delete it from view.
  10756. SendKillObject(new List<uint> { localId });
  10757. }
  10758. else
  10759. {
  10760. ClientChangeObject updatehandler = onClientChangeObject;
  10761. if (updatehandler != null)
  10762. {
  10763. ObjectChangeData udata = new ObjectChangeData();
  10764. /*ubit from ll JIRA:
  10765. * 0x01 position
  10766. * 0x02 rotation
  10767. * 0x04 scale
  10768. * 0x08 LINK_SET
  10769. * 0x10 UNIFORM for scale
  10770. */
  10771. // translate to internal changes
  10772. // not all cases .. just the ones older code did
  10773. switch (block.Type)
  10774. {
  10775. case 1: //change position sp
  10776. udata.position = new Vector3(block.Data, 0);
  10777. udata.change = ObjectChangeType.primP;
  10778. updatehandler(localId, udata, this);
  10779. break;
  10780. case 2: // rotation sp
  10781. udata.rotation = new Quaternion(block.Data, 0, true);
  10782. udata.change = ObjectChangeType.primR;
  10783. updatehandler(localId, udata, this);
  10784. break;
  10785. case 3: // position plus rotation
  10786. udata.position = new Vector3(block.Data, 0);
  10787. udata.rotation = new Quaternion(block.Data, 12, true);
  10788. udata.change = ObjectChangeType.primPR;
  10789. updatehandler(localId, udata, this);
  10790. break;
  10791. case 4: // scale sp
  10792. udata.scale = new Vector3(block.Data, 0);
  10793. udata.change = ObjectChangeType.primS;
  10794. updatehandler(localId, udata, this);
  10795. break;
  10796. case 0x14: // uniform scale sp
  10797. udata.scale = new Vector3(block.Data, 0);
  10798. udata.change = ObjectChangeType.primUS;
  10799. updatehandler(localId, udata, this);
  10800. break;
  10801. case 5: // scale and position sp
  10802. udata.position = new Vector3(block.Data, 0);
  10803. udata.scale = new Vector3(block.Data, 12);
  10804. udata.change = ObjectChangeType.primPS;
  10805. updatehandler(localId, udata, this);
  10806. break;
  10807. case 0x15: //uniform scale and position
  10808. udata.position = new Vector3(block.Data, 0);
  10809. udata.scale = new Vector3(block.Data, 12);
  10810. udata.change = ObjectChangeType.primPUS;
  10811. updatehandler(localId, udata, this);
  10812. break;
  10813. // now group related (bit 4)
  10814. case 9: //( 8 + 1 )group position
  10815. udata.position = new Vector3(block.Data, 0);
  10816. udata.change = ObjectChangeType.groupP;
  10817. updatehandler(localId, udata, this);
  10818. break;
  10819. case 0x0A: // (8 + 2) group rotation
  10820. udata.rotation = new Quaternion(block.Data, 0, true);
  10821. udata.change = ObjectChangeType.groupR;
  10822. updatehandler(localId, udata, this);
  10823. break;
  10824. case 0x0B: //( 8 + 2 + 1) group rotation and position
  10825. udata.position = new Vector3(block.Data, 0);
  10826. udata.rotation = new Quaternion(block.Data, 12, true);
  10827. udata.change = ObjectChangeType.groupPR;
  10828. updatehandler(localId, udata, this);
  10829. break;
  10830. case 0x0C: // (8 + 4) group scale
  10831. // only afects root prim and only sent by viewer editor object tab scaling
  10832. // mouse edition only allows uniform scaling
  10833. // SL MAY CHANGE THIS in viewers
  10834. udata.scale = new Vector3(block.Data, 0);
  10835. udata.change = ObjectChangeType.groupS;
  10836. updatehandler(localId, udata, this);
  10837. break;
  10838. case 0x0D: //(8 + 4 + 1) group scale and position
  10839. // exception as above
  10840. udata.position = new Vector3(block.Data, 0);
  10841. udata.scale = new Vector3(block.Data, 12);
  10842. udata.change = ObjectChangeType.groupPS;
  10843. updatehandler(localId, udata, this);
  10844. break;
  10845. case 0x1C: // (0x10 + 8 + 4 ) group scale UNIFORM
  10846. udata.scale = new Vector3(block.Data, 0);
  10847. udata.change = ObjectChangeType.groupUS;
  10848. updatehandler(localId, udata, this);
  10849. break;
  10850. case 0x1D: // (UNIFORM + GROUP + SCALE + POS)
  10851. udata.position = new Vector3(block.Data, 0);
  10852. udata.scale = new Vector3(block.Data, 12);
  10853. udata.change = ObjectChangeType.groupPUS;
  10854. updatehandler(localId, udata, this);
  10855. break;
  10856. default:
  10857. m_log.Debug("[CLIENT]: MultipleObjUpdate recieved an unknown packet type: " + (block.Type));
  10858. break;
  10859. }
  10860. }
  10861. }
  10862. }
  10863. }
  10864. }
  10865. public void RequestMapLayer()
  10866. {
  10867. //should be getting the map layer from the grid server
  10868. //send a layer covering the 800,800 - 1200,1200 area (should be covering the requested area)
  10869. MapLayerReplyPacket mapReply = (MapLayerReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapLayerReply);
  10870. // TODO: don't create new blocks if recycling an old packet
  10871. mapReply.AgentData.AgentID = AgentId;
  10872. mapReply.AgentData.Flags = 0;
  10873. mapReply.LayerData = new MapLayerReplyPacket.LayerDataBlock[1];
  10874. mapReply.LayerData[0] = new MapLayerReplyPacket.LayerDataBlock();
  10875. mapReply.LayerData[0].Bottom = 0;
  10876. mapReply.LayerData[0].Left = 0;
  10877. mapReply.LayerData[0].Top = 30000;
  10878. mapReply.LayerData[0].Right = 30000;
  10879. mapReply.LayerData[0].ImageID = new UUID("00000000-0000-1111-9999-000000000006");
  10880. mapReply.Header.Zerocoded = true;
  10881. OutPacket(mapReply, ThrottleOutPacketType.Land);
  10882. }
  10883. public void RequestMapBlocksX(int minX, int minY, int maxX, int maxY)
  10884. {
  10885. /*
  10886. IList simMapProfiles = m_gridServer.RequestMapBlocks(minX, minY, maxX, maxY);
  10887. MapBlockReplyPacket mbReply = new MapBlockReplyPacket();
  10888. mbReply.AgentData.AgentId = AgentId;
  10889. int len;
  10890. if (simMapProfiles == null)
  10891. len = 0;
  10892. else
  10893. len = simMapProfiles.Count;
  10894. mbReply.Data = new MapBlockReplyPacket.DataBlock[len];
  10895. int iii;
  10896. for (iii = 0; iii < len; iii++)
  10897. {
  10898. Hashtable mp = (Hashtable)simMapProfiles[iii];
  10899. mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock();
  10900. mbReply.Data[iii].Name = Util.UTF8.GetBytes((string)mp["name"]);
  10901. mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]);
  10902. mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]);
  10903. mbReply.Data[iii].MapImageID = new UUID((string)mp["map-image-id"]);
  10904. mbReply.Data[iii].RegionFlags = System.Convert.ToUInt32(mp["region-flags"]);
  10905. mbReply.Data[iii].WaterHeight = System.Convert.ToByte(mp["water-height"]);
  10906. mbReply.Data[iii].X = System.Convert.ToUInt16(mp["x"]);
  10907. mbReply.Data[iii].Y = System.Convert.ToUInt16(mp["y"]);
  10908. }
  10909. this.OutPacket(mbReply, ThrottleOutPacketType.Land);
  10910. */
  10911. }
  10912. /// <summary>
  10913. /// Sets the throttles from values supplied by the client
  10914. /// </summary>
  10915. /// <param name="throttles"></param>
  10916. public void SetChildAgentThrottle(byte[] throttles)
  10917. {
  10918. SetChildAgentThrottle(throttles, 1.0f);
  10919. }
  10920. public void SetChildAgentThrottle(byte[] throttles,float factor)
  10921. {
  10922. m_udpClient.SetThrottles(throttles, factor);
  10923. GenericCall2 handler = OnUpdateThrottles;
  10924. if (handler != null)
  10925. {
  10926. handler();
  10927. }
  10928. }
  10929. /// <summary>
  10930. /// Sets the throttles from values supplied caller
  10931. /// </summary>
  10932. /// <param name="throttles"></param>
  10933. public void SetAgentThrottleSilent(int throttle, int setting)
  10934. {
  10935. m_udpClient.ForceThrottleSetting(throttle,setting);
  10936. }
  10937. public int GetAgentThrottleSilent(int throttle)
  10938. {
  10939. return m_udpClient.GetThrottleSetting(throttle);
  10940. }
  10941. /// <summary>
  10942. /// Get the current throttles for this client as a packed byte array
  10943. /// </summary>
  10944. /// <param name="multiplier">Unused</param>
  10945. /// <returns></returns>
  10946. public byte[] GetThrottlesPacked(float multiplier)
  10947. {
  10948. return m_udpClient.GetThrottlesPacked(multiplier);
  10949. }
  10950. /// <summary>
  10951. /// Cruft?
  10952. /// </summary>
  10953. public virtual void InPacket(object NewPack)
  10954. {
  10955. throw new NotImplementedException();
  10956. }
  10957. /// <summary>
  10958. /// This is the starting point for sending a simulator packet out to the client
  10959. /// </summary>
  10960. /// <param name="packet">Packet to send</param>
  10961. /// <param name="throttlePacketType">Throttling category for the packet</param>
  10962. protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType)
  10963. {
  10964. #region BinaryStats
  10965. LLUDPServer.LogPacketHeader(false, m_circuitCode, 0, packet.Type, (ushort)packet.Length);
  10966. #endregion BinaryStats
  10967. OutPacket(packet, throttlePacketType, true, null);
  10968. }
  10969. /// <summary>
  10970. /// This is the starting point for sending a simulator packet out to the client
  10971. /// </summary>
  10972. /// <param name="packet">Packet to send</param>
  10973. /// <param name="throttlePacketType">Throttling category for the packet</param>
  10974. /// <param name="doAutomaticSplitting">True to automatically split oversized
  10975. /// packets (the default), or false to disable splitting if the calling code
  10976. /// handles splitting manually</param>
  10977. protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting)
  10978. {
  10979. OutPacket(packet, throttlePacketType, doAutomaticSplitting, null);
  10980. }
  10981. /// <summary>
  10982. /// This is the starting point for sending a simulator packet out to the client
  10983. /// </summary>
  10984. /// <param name="packet">Packet to send</param>
  10985. /// <param name="throttlePacketType">Throttling category for the packet</param>
  10986. /// <param name="doAutomaticSplitting">True to automatically split oversized
  10987. /// packets (the default), or false to disable splitting if the calling code
  10988. /// handles splitting manually</param>
  10989. /// <param name="method">The method to be called in the event this packet is reliable
  10990. /// and unacknowledged. The server will provide normal resend capability if you do not
  10991. /// provide your own method.</param>
  10992. protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting, UnackedPacketMethod method)
  10993. {
  10994. if (m_outPacketsToDrop != null)
  10995. {
  10996. if (m_outPacketsToDrop.Contains(packet.Type.ToString()))
  10997. {
  10998. PacketPool.Instance.ReturnPacket(packet);
  10999. return;
  11000. }
  11001. }
  11002. if (DebugPacketLevel > 0)
  11003. {
  11004. bool logPacket = true;
  11005. if (DebugPacketLevel <= 255
  11006. && (packet.Type == PacketType.SimStats || packet.Type == PacketType.SimulatorViewerTimeMessage))
  11007. logPacket = false;
  11008. if (DebugPacketLevel <= 200
  11009. && (packet.Type == PacketType.ImagePacket
  11010. || packet.Type == PacketType.ImageData
  11011. || packet.Type == PacketType.LayerData
  11012. || packet.Type == PacketType.CoarseLocationUpdate))
  11013. logPacket = false;
  11014. if (DebugPacketLevel <= 100 && (packet.Type == PacketType.AvatarAnimation || packet.Type == PacketType.ViewerEffect))
  11015. logPacket = false;
  11016. if (DebugPacketLevel <= 50
  11017. && (packet.Type == PacketType.ImprovedTerseObjectUpdate || packet.Type == PacketType.ObjectUpdate))
  11018. logPacket = false;
  11019. if (DebugPacketLevel <= 25 && packet.Type == PacketType.ObjectPropertiesFamily)
  11020. logPacket = false;
  11021. if (logPacket)
  11022. m_log.DebugFormat(
  11023. "[CLIENT]: PACKET OUT to {0} ({1}) in {2} - {3}",
  11024. Name, SceneAgent.IsChildAgent ? "child" : "root ", m_scene.RegionInfo.RegionName, packet.Type);
  11025. }
  11026. m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, doAutomaticSplitting, method);
  11027. }
  11028. protected void HandleAutopilot(Object sender, string method, List<String> args)
  11029. {
  11030. if(OnAutoPilotGo == null)
  11031. return;
  11032. float locx = 0;
  11033. float locy = 0;
  11034. float locz = 0;
  11035. uint regionX = 0;
  11036. uint regionY = 0;
  11037. Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out regionX, out regionY);
  11038. locx = (float)(Convert.ToDouble(args[0]) - (double)regionX);
  11039. locy = (float)(Convert.ToDouble(args[1]) - (double)regionY);
  11040. locz = Convert.ToSingle(args[2]);
  11041. OnAutoPilotGo?.Invoke(new Vector3(locx, locy, locz), false, true);
  11042. }
  11043. /// <summary>
  11044. /// Entryway from the client to the simulator. All UDP packets from the client will end up here
  11045. /// </summary>
  11046. /// <param name="Pack">OpenMetaverse.packet</param>
  11047. public void ProcessInPacket(Packet packet)
  11048. {
  11049. if (m_inPacketsToDrop != null)
  11050. if (m_inPacketsToDrop.Contains(packet.Type.ToString()))
  11051. return;
  11052. if (DebugPacketLevel > 0)
  11053. {
  11054. bool logPacket = true;
  11055. if (DebugPacketLevel <= 255 && packet.Type == PacketType.AgentUpdate)
  11056. logPacket = false;
  11057. if (DebugPacketLevel <= 200 && packet.Type == PacketType.RequestImage)
  11058. logPacket = false;
  11059. if (DebugPacketLevel <= 100 && (packet.Type == PacketType.ViewerEffect || packet.Type == PacketType.AgentAnimation))
  11060. logPacket = false;
  11061. if (DebugPacketLevel <= 25 && packet.Type == PacketType.RequestObjectPropertiesFamily)
  11062. logPacket = false;
  11063. if (logPacket)
  11064. m_log.DebugFormat(
  11065. "[CLIENT]: PACKET IN from {0} ({1}) in {2} - {3}",
  11066. Name, SceneAgent.IsChildAgent ? "child" : "root ", Scene.Name, packet.Type);
  11067. }
  11068. if (!ProcessPacketMethod(packet))
  11069. m_log.WarnFormat(
  11070. "[CLIENT]: Unhandled packet {0} from {1} ({2}) in {3}. Ignoring.",
  11071. packet.Type, Name, SceneAgent.IsChildAgent ? "child" : "root ", Scene.Name);
  11072. }
  11073. private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)
  11074. {
  11075. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  11076. shape.PCode = addPacket.ObjectData.PCode;
  11077. shape.State = addPacket.ObjectData.State;
  11078. shape.LastAttachPoint = addPacket.ObjectData.State;
  11079. shape.PathBegin = addPacket.ObjectData.PathBegin;
  11080. shape.PathEnd = addPacket.ObjectData.PathEnd;
  11081. shape.PathScaleX = addPacket.ObjectData.PathScaleX;
  11082. shape.PathScaleY = addPacket.ObjectData.PathScaleY;
  11083. shape.PathShearX = addPacket.ObjectData.PathShearX;
  11084. shape.PathShearY = addPacket.ObjectData.PathShearY;
  11085. shape.PathSkew = addPacket.ObjectData.PathSkew;
  11086. shape.ProfileBegin = addPacket.ObjectData.ProfileBegin;
  11087. shape.ProfileEnd = addPacket.ObjectData.ProfileEnd;
  11088. shape.Scale = addPacket.ObjectData.Scale;
  11089. shape.PathCurve = addPacket.ObjectData.PathCurve;
  11090. shape.ProfileCurve = addPacket.ObjectData.ProfileCurve;
  11091. shape.ProfileHollow = addPacket.ObjectData.ProfileHollow;
  11092. shape.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
  11093. shape.PathRevolutions = addPacket.ObjectData.PathRevolutions;
  11094. shape.PathTaperX = addPacket.ObjectData.PathTaperX;
  11095. shape.PathTaperY = addPacket.ObjectData.PathTaperY;
  11096. shape.PathTwist = addPacket.ObjectData.PathTwist;
  11097. shape.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
  11098. Primitive.TextureEntry ntex = new Primitive.TextureEntry(new UUID("89556747-24cb-43ed-920b-47caed15465f"));
  11099. shape.TextureEntry = ntex.GetBytes();
  11100. //shape.Textures = ntex;
  11101. return shape;
  11102. }
  11103. public ClientInfo GetClientInfo()
  11104. {
  11105. ClientInfo info = m_udpClient.GetClientInfo();
  11106. info.proxyEP = null;
  11107. if (info.agentcircuit == null)
  11108. info.agentcircuit = RequestClientInfo();
  11109. return info;
  11110. }
  11111. public void SetClientInfo(ClientInfo info)
  11112. {
  11113. m_udpClient.SetClientInfo(info);
  11114. }
  11115. #region Media Parcel Members
  11116. public void SendParcelMediaCommand(uint flags, ParcelMediaCommandEnum command, float time)
  11117. {
  11118. ParcelMediaCommandMessagePacket commandMessagePacket = new ParcelMediaCommandMessagePacket();
  11119. commandMessagePacket.CommandBlock.Flags = flags;
  11120. commandMessagePacket.CommandBlock.Command = (uint)command;
  11121. commandMessagePacket.CommandBlock.Time = time;
  11122. OutPacket(commandMessagePacket, ThrottleOutPacketType.Task);
  11123. }
  11124. public void SendParcelMediaUpdate(string mediaUrl, UUID mediaTextureID,
  11125. byte autoScale, string mediaType, string mediaDesc, int mediaWidth, int mediaHeight,
  11126. byte mediaLoop)
  11127. {
  11128. ParcelMediaUpdatePacket updatePacket = new ParcelMediaUpdatePacket();
  11129. updatePacket.DataBlock.MediaURL = Util.StringToBytes256(mediaUrl);
  11130. updatePacket.DataBlock.MediaID = mediaTextureID;
  11131. updatePacket.DataBlock.MediaAutoScale = autoScale;
  11132. updatePacket.DataBlockExtended.MediaType = Util.StringToBytes256(mediaType);
  11133. updatePacket.DataBlockExtended.MediaDesc = Util.StringToBytes256(mediaDesc);
  11134. updatePacket.DataBlockExtended.MediaWidth = mediaWidth;
  11135. updatePacket.DataBlockExtended.MediaHeight = mediaHeight;
  11136. updatePacket.DataBlockExtended.MediaLoop = mediaLoop;
  11137. OutPacket(updatePacket, ThrottleOutPacketType.Task);
  11138. }
  11139. #endregion
  11140. #region Camera
  11141. public void SendSetFollowCamProperties(UUID objectID, SortedDictionary<int, float> parameters)
  11142. {
  11143. SetFollowCamPropertiesPacket packet = (SetFollowCamPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.SetFollowCamProperties);
  11144. packet.ObjectData.ObjectID = objectID;
  11145. SetFollowCamPropertiesPacket.CameraPropertyBlock[] camPropBlock = new SetFollowCamPropertiesPacket.CameraPropertyBlock[parameters.Count];
  11146. uint idx = 0;
  11147. foreach (KeyValuePair<int, float> pair in parameters)
  11148. {
  11149. SetFollowCamPropertiesPacket.CameraPropertyBlock block = new SetFollowCamPropertiesPacket.CameraPropertyBlock();
  11150. block.Type = pair.Key;
  11151. block.Value = pair.Value;
  11152. camPropBlock[idx++] = block;
  11153. }
  11154. packet.CameraProperty = camPropBlock;
  11155. OutPacket(packet, ThrottleOutPacketType.Task);
  11156. }
  11157. public void SendClearFollowCamProperties(UUID objectID)
  11158. {
  11159. ClearFollowCamPropertiesPacket packet = (ClearFollowCamPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ClearFollowCamProperties);
  11160. packet.ObjectData.ObjectID = objectID;
  11161. OutPacket(packet, ThrottleOutPacketType.Task);
  11162. }
  11163. #endregion
  11164. public void SetClientOption(string option, string value)
  11165. {
  11166. switch (option)
  11167. {
  11168. default:
  11169. break;
  11170. }
  11171. }
  11172. public string GetClientOption(string option)
  11173. {
  11174. switch (option)
  11175. {
  11176. default:
  11177. break;
  11178. }
  11179. return string.Empty;
  11180. }
  11181. #region IClientCore
  11182. private readonly Dictionary<Type, object> m_clientInterfaces = new Dictionary<Type, object>();
  11183. /// <summary>
  11184. /// Register an interface on this client, should only be called in the constructor.
  11185. /// </summary>
  11186. /// <typeparam name="T"></typeparam>
  11187. /// <param name="iface"></param>
  11188. protected void RegisterInterface<T>(T iface)
  11189. {
  11190. lock (m_clientInterfaces)
  11191. {
  11192. if (!m_clientInterfaces.ContainsKey(typeof(T)))
  11193. {
  11194. m_clientInterfaces.Add(typeof(T), iface);
  11195. }
  11196. }
  11197. }
  11198. public bool TryGet<T>(out T iface)
  11199. {
  11200. if(m_clientInterfaces.TryGetValue(typeof(T), out object o))
  11201. {
  11202. iface = (T)o;
  11203. return true;
  11204. }
  11205. iface = default(T);
  11206. return false;
  11207. }
  11208. public T Get<T>()
  11209. {
  11210. return (T)m_clientInterfaces[typeof(T)];
  11211. }
  11212. public void Disconnect(string reason)
  11213. {
  11214. Kick(reason);
  11215. Thread.Sleep(1000);
  11216. Disconnect();
  11217. }
  11218. public void Disconnect()
  11219. {
  11220. Close();
  11221. }
  11222. #endregion
  11223. public void RefreshGroupMembership()
  11224. {
  11225. lock(m_groupPowers)
  11226. {
  11227. GroupMembershipData activeMembership = null;
  11228. if (m_GroupsModule != null)
  11229. {
  11230. GroupMembershipData[] GroupMembership =
  11231. m_GroupsModule.GetMembershipData(AgentId);
  11232. m_groupPowers.Clear();
  11233. if (GroupMembership != null)
  11234. {
  11235. for (int i = 0; i < GroupMembership.Length; i++)
  11236. {
  11237. m_groupPowers[GroupMembership[i].GroupID] = GroupMembership[i].GroupPowers;
  11238. }
  11239. }
  11240. activeMembership = m_GroupsModule.GetActiveMembershipData(AgentId);
  11241. if(activeMembership != null)
  11242. {
  11243. if(!m_groupPowers.ContainsKey(activeMembership.GroupID))
  11244. activeMembership = null;
  11245. else
  11246. {
  11247. m_activeGroupID = activeMembership.GroupID;
  11248. m_activeGroupName = activeMembership.GroupName;
  11249. m_activeGroupPowers = ActiveGroupPowers;
  11250. }
  11251. }
  11252. }
  11253. if(activeMembership == null)
  11254. {
  11255. m_activeGroupID = UUID.Zero;
  11256. m_activeGroupName = "";
  11257. m_activeGroupPowers = 0;
  11258. }
  11259. }
  11260. }
  11261. public void UpdateGroupMembership(GroupMembershipData[] data)
  11262. {
  11263. lock(m_groupPowers)
  11264. {
  11265. m_groupPowers.Clear();
  11266. if (data != null)
  11267. {
  11268. for (int i = 0; i < data.Length; i++)
  11269. m_groupPowers[data[i].GroupID] = data[i].GroupPowers;
  11270. }
  11271. }
  11272. }
  11273. public void GroupMembershipRemove(UUID GroupID)
  11274. {
  11275. lock(m_groupPowers)
  11276. {
  11277. if(m_groupPowers.ContainsKey(GroupID))
  11278. m_groupPowers.Remove(GroupID);
  11279. }
  11280. }
  11281. public void GroupMembershipAddReplace(UUID GroupID,ulong GroupPowers)
  11282. {
  11283. lock(m_groupPowers)
  11284. {
  11285. m_groupPowers[GroupID] = GroupPowers;
  11286. }
  11287. }
  11288. public string Report()
  11289. {
  11290. return m_udpClient.GetStats();
  11291. }
  11292. public string XReport(string uptime, string version)
  11293. {
  11294. return String.Empty;
  11295. }
  11296. public OSDMap OReport(string uptime, string version)
  11297. {
  11298. return new OSDMap();
  11299. }
  11300. /// <summary>
  11301. /// Make an asset request to the asset service in response to a client request.
  11302. /// </summary>
  11303. /// <param name="transferRequest"></param>
  11304. /// <param name="taskID"></param>
  11305. protected void MakeAssetRequest(TransferRequestPacket transferRequest, UUID taskID)
  11306. {
  11307. UUID requestID = UUID.Zero;
  11308. int sourceType = transferRequest.TransferInfo.SourceType;
  11309. if (sourceType == (int)SourceType.Asset)
  11310. {
  11311. requestID = new UUID(transferRequest.TransferInfo.Params, 0);
  11312. }
  11313. else if (sourceType == (int)SourceType.SimInventoryItem)
  11314. {
  11315. requestID = new UUID(transferRequest.TransferInfo.Params, 80);
  11316. }
  11317. else if (sourceType == (int)SourceType.SimEstate)
  11318. {
  11319. requestID = taskID;
  11320. }
  11321. // m_log.DebugFormat(
  11322. // "[LLCLIENTVIEW]: Received transfer request for {0} in {1} type {2} by {3}",
  11323. // requestID, taskID, (SourceType)sourceType, Name);
  11324. //Note, the bool returned from the below function is useless since it is always false.
  11325. m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived);
  11326. }
  11327. /// <summary>
  11328. /// When we get a reply back from the asset service in response to a client request, send back the data.
  11329. /// </summary>
  11330. /// <param name="id"></param>
  11331. /// <param name="sender"></param>
  11332. /// <param name="asset"></param>
  11333. protected void AssetReceived(string id, Object sender, AssetBase asset)
  11334. {
  11335. TransferRequestPacket transferRequest = (TransferRequestPacket)sender;
  11336. UUID requestID = UUID.Zero;
  11337. byte source = (byte)SourceType.Asset;
  11338. AssetRequestToClient req = new AssetRequestToClient();
  11339. if (asset == null)
  11340. {
  11341. // Try the user's asset server
  11342. IInventoryAccessModule inventoryAccessModule = Scene.RequestModuleInterface<IInventoryAccessModule>();
  11343. string assetServerURL = string.Empty;
  11344. if (inventoryAccessModule.IsForeignUser(AgentId, out assetServerURL) && !string.IsNullOrEmpty(assetServerURL))
  11345. {
  11346. if (!assetServerURL.EndsWith("/") && !assetServerURL.EndsWith("="))
  11347. assetServerURL = assetServerURL + "/";
  11348. //m_log.DebugFormat("[LLCLIENTVIEW]: asset {0} not found in local storage. Trying user's storage.", assetServerURL + id);
  11349. asset = m_scene.AssetService.Get(assetServerURL + id);
  11350. }
  11351. if (asset == null)
  11352. {
  11353. req.AssetInf = null;
  11354. req.AssetRequestSource = source;
  11355. req.IsTextureRequest = false;
  11356. req.NumPackets = 0;
  11357. req.Params = transferRequest.TransferInfo.Params;
  11358. req.RequestAssetID = requestID;
  11359. req.TransferRequestID = transferRequest.TransferInfo.TransferID;
  11360. SendAssetNotFound(req);
  11361. return;
  11362. }
  11363. }
  11364. if (transferRequest.TransferInfo.SourceType == (int)SourceType.Asset)
  11365. {
  11366. requestID = new UUID(transferRequest.TransferInfo.Params, 0);
  11367. }
  11368. else if (transferRequest.TransferInfo.SourceType == (int)SourceType.SimInventoryItem)
  11369. {
  11370. requestID = new UUID(transferRequest.TransferInfo.Params, 80);
  11371. source = (byte)SourceType.SimInventoryItem;
  11372. //m_log.Debug("asset request " + requestID);
  11373. }
  11374. // Scripts cannot be retrieved by direct request
  11375. if (transferRequest.TransferInfo.SourceType == (int)SourceType.Asset && asset.Type == 10)
  11376. return;
  11377. // The asset is known to exist and is in our cache, so add it to the AssetRequests list
  11378. req.AssetInf = asset;
  11379. req.AssetRequestSource = source;
  11380. req.IsTextureRequest = false;
  11381. req.NumPackets = CalculateNumPackets(asset.Data);
  11382. req.Params = transferRequest.TransferInfo.Params;
  11383. req.RequestAssetID = requestID;
  11384. req.TransferRequestID = transferRequest.TransferInfo.TransferID;
  11385. SendAsset(req);
  11386. }
  11387. /// <summary>
  11388. /// Calculate the number of packets required to send the asset to the client.
  11389. /// </summary>
  11390. /// <param name="data"></param>
  11391. /// <returns></returns>
  11392. private static int CalculateNumPackets(byte[] data)
  11393. {
  11394. // const uint m_maxPacketSize = 600;
  11395. uint m_maxPacketSize = MaxTransferBytesPerPacket;
  11396. int numPackets = 1;
  11397. if (data == null)
  11398. return 0;
  11399. if (data.LongLength > m_maxPacketSize)
  11400. {
  11401. // over max number of bytes so split up file
  11402. long restData = data.LongLength - m_maxPacketSize;
  11403. int restPackets = (int)((restData + m_maxPacketSize - 1) / m_maxPacketSize);
  11404. numPackets += restPackets;
  11405. }
  11406. return numPackets;
  11407. }
  11408. public void SendRebakeAvatarTextures(UUID textureID)
  11409. {
  11410. RebakeAvatarTexturesPacket pack =
  11411. (RebakeAvatarTexturesPacket)PacketPool.Instance.GetPacket(PacketType.RebakeAvatarTextures);
  11412. pack.TextureData = new RebakeAvatarTexturesPacket.TextureDataBlock();
  11413. pack.TextureData.TextureID = textureID;
  11414. OutPacket(pack, ThrottleOutPacketType.Task);
  11415. }
  11416. public struct PacketProcessor
  11417. {
  11418. /// <summary>
  11419. /// Packet handling method.
  11420. /// </summary>
  11421. public PacketMethod method;
  11422. /// <summary>
  11423. /// Should this packet be handled asynchronously?
  11424. /// </summary>
  11425. public bool Async;
  11426. }
  11427. public void SendAvatarInterestsReply(UUID avatarID, uint wantMask, string wantText, uint skillsMask, string skillsText, string languages)
  11428. {
  11429. AvatarInterestsReplyPacket packet = (AvatarInterestsReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarInterestsReply);
  11430. packet.AgentData = new AvatarInterestsReplyPacket.AgentDataBlock();
  11431. packet.AgentData.AgentID = AgentId;
  11432. packet.AgentData.AvatarID = avatarID;
  11433. packet.PropertiesData = new AvatarInterestsReplyPacket.PropertiesDataBlock();
  11434. packet.PropertiesData.WantToMask = wantMask;
  11435. packet.PropertiesData.WantToText = Utils.StringToBytes(wantText);
  11436. packet.PropertiesData.SkillsMask = skillsMask;
  11437. packet.PropertiesData.SkillsText = Utils.StringToBytes(skillsText);
  11438. packet.PropertiesData.LanguagesText = Utils.StringToBytes(languages);
  11439. OutPacket(packet, ThrottleOutPacketType.Task);
  11440. }
  11441. public void SendChangeUserRights(UUID agentID, UUID friendID, int rights)
  11442. {
  11443. ChangeUserRightsPacket packet = (ChangeUserRightsPacket)PacketPool.Instance.GetPacket(PacketType.ChangeUserRights);
  11444. packet.AgentData = new ChangeUserRightsPacket.AgentDataBlock();
  11445. packet.AgentData.AgentID = agentID;
  11446. packet.Rights = new ChangeUserRightsPacket.RightsBlock[1];
  11447. packet.Rights[0] = new ChangeUserRightsPacket.RightsBlock();
  11448. packet.Rights[0].AgentRelated = friendID;
  11449. packet.Rights[0].RelatedRights = rights;
  11450. OutPacket(packet, ThrottleOutPacketType.Task);
  11451. }
  11452. public void SendTextBoxRequest(string message, int chatChannel, string objectname, UUID ownerID, string ownerFirstName, string ownerLastName, UUID objectId)
  11453. {
  11454. ScriptDialogPacket dialog = (ScriptDialogPacket)PacketPool.Instance.GetPacket(PacketType.ScriptDialog);
  11455. dialog.Data.ObjectID = objectId;
  11456. dialog.Data.ChatChannel = chatChannel;
  11457. dialog.Data.ImageID = UUID.Zero;
  11458. dialog.Data.ObjectName = Util.StringToBytes256(objectname);
  11459. // this is the username of the *owner*
  11460. dialog.Data.FirstName = Util.StringToBytes256(ownerFirstName);
  11461. dialog.Data.LastName = Util.StringToBytes256(ownerLastName);
  11462. dialog.Data.Message = Util.StringToBytes(message,512);
  11463. ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[1];
  11464. buttons[0] = new ScriptDialogPacket.ButtonsBlock();
  11465. buttons[0].ButtonLabel = Util.StringToBytes256("!!llTextBox!!");
  11466. dialog.Buttons = buttons;
  11467. dialog.OwnerData = new ScriptDialogPacket.OwnerDataBlock[1];
  11468. dialog.OwnerData[0] = new ScriptDialogPacket.OwnerDataBlock();
  11469. dialog.OwnerData[0].OwnerID = ownerID;
  11470. OutPacket(dialog, ThrottleOutPacketType.Task);
  11471. }
  11472. public void SendAgentTerseUpdate(ISceneEntity p)
  11473. {
  11474. if (p is ScenePresence)
  11475. {
  11476. UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
  11477. //setup header and regioninfo block
  11478. Buffer.BlockCopy(terseUpdateHeader, 0, buf.Data, 0, 7);
  11479. Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, buf.Data, 7);
  11480. Utils.UInt16ToBytes(Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f), buf.Data, 15);
  11481. buf.Data[17] = 1;
  11482. int pos = 18;
  11483. CreateImprovedTerseBlock(p, buf.Data, ref pos, false);
  11484. buf.DataLength = pos;
  11485. m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, true);
  11486. }
  11487. }
  11488. public void SendPlacesReply(UUID queryID, UUID transactionID,
  11489. PlacesReplyData[] data)
  11490. {
  11491. PlacesReplyPacket reply = null;
  11492. PlacesReplyPacket.QueryDataBlock[] dataBlocks =
  11493. new PlacesReplyPacket.QueryDataBlock[0];
  11494. for (int i = 0 ; i < data.Length ; i++)
  11495. {
  11496. PlacesReplyPacket.QueryDataBlock block =
  11497. new PlacesReplyPacket.QueryDataBlock();
  11498. block.OwnerID = data[i].OwnerID;
  11499. block.Name = Util.StringToBytes256(data[i].Name);
  11500. block.Desc = Util.StringToBytes1024(data[i].Desc);
  11501. block.ActualArea = data[i].ActualArea;
  11502. block.BillableArea = data[i].BillableArea;
  11503. block.Flags = data[i].Flags;
  11504. block.GlobalX = data[i].GlobalX;
  11505. block.GlobalY = data[i].GlobalY;
  11506. block.GlobalZ = data[i].GlobalZ;
  11507. block.SimName = Util.StringToBytes256(data[i].SimName);
  11508. block.SnapshotID = data[i].SnapshotID;
  11509. block.Dwell = data[i].Dwell;
  11510. block.Price = data[i].Price;
  11511. if (reply != null && reply.Length + block.Length > 1400)
  11512. {
  11513. OutPacket(reply, ThrottleOutPacketType.Task);
  11514. reply = null;
  11515. dataBlocks = new PlacesReplyPacket.QueryDataBlock[0];
  11516. }
  11517. if (reply == null)
  11518. {
  11519. reply = (PlacesReplyPacket)PacketPool.Instance.GetPacket(PacketType.PlacesReply);
  11520. reply.AgentData = new PlacesReplyPacket.AgentDataBlock();
  11521. reply.AgentData.AgentID = AgentId;
  11522. reply.AgentData.QueryID = queryID;
  11523. reply.TransactionData = new PlacesReplyPacket.TransactionDataBlock();
  11524. reply.TransactionData.TransactionID = transactionID;
  11525. reply.QueryData = dataBlocks;
  11526. }
  11527. Array.Resize(ref dataBlocks, dataBlocks.Length + 1);
  11528. dataBlocks[dataBlocks.Length - 1] = block;
  11529. reply.QueryData = dataBlocks;
  11530. }
  11531. if (reply != null)
  11532. OutPacket(reply, ThrottleOutPacketType.Task);
  11533. }
  11534. public void SendRemoveInventoryItems(UUID[] items)
  11535. {
  11536. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  11537. if (eq == null)
  11538. {
  11539. m_log.DebugFormat("[LLCLIENT]: Null event queue");
  11540. return;
  11541. }
  11542. osUTF8 sb = eq.StartEvent("RemoveInventoryItem");
  11543. LLSDxmlEncode2.AddArrayAndMap("AgentData", sb);
  11544. LLSDxmlEncode2.AddElem("AgentID", AgentId, sb);
  11545. LLSDxmlEncode2.AddElem("SessionID", SessionId, sb);
  11546. LLSDxmlEncode2.AddEndMapAndArray(sb);
  11547. LLSDxmlEncode2.AddArray("InventoryData", sb);
  11548. foreach (UUID item in items)
  11549. {
  11550. LLSDxmlEncode2.AddMap(sb);
  11551. LLSDxmlEncode2.AddElem("ItemID",item, sb);
  11552. LLSDxmlEncode2.AddEndMap(sb);
  11553. }
  11554. LLSDxmlEncode2.AddEndArray(sb);
  11555. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  11556. }
  11557. public void SendRemoveInventoryFolders(UUID[] folders)
  11558. {
  11559. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  11560. if (eq == null)
  11561. {
  11562. m_log.DebugFormat("[LLCLIENT]: Null event queue");
  11563. return;
  11564. }
  11565. osUTF8 sb = eq.StartEvent("RemoveInventoryFolder");
  11566. LLSDxmlEncode2.AddArrayAndMap("AgentData", sb);
  11567. LLSDxmlEncode2.AddElem("AgentID", AgentId, sb);
  11568. LLSDxmlEncode2.AddElem("SessionID", SessionId, sb);
  11569. LLSDxmlEncode2.AddEndMapAndArray(sb);
  11570. LLSDxmlEncode2.AddArray("FolderData", sb);
  11571. foreach (UUID folder in folders)
  11572. {
  11573. LLSDxmlEncode2.AddMap(sb);
  11574. LLSDxmlEncode2.AddElem("FolderID", folder, sb);
  11575. LLSDxmlEncode2.AddEndMap(sb);
  11576. }
  11577. LLSDxmlEncode2.AddEndArray(sb);
  11578. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  11579. }
  11580. public void SendBulkUpdateInventory(InventoryFolderBase[] folders, InventoryItemBase[] items)
  11581. {
  11582. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  11583. if (eq == null)
  11584. {
  11585. m_log.DebugFormat("[LLCLIENT]: Null event queue");
  11586. return;
  11587. }
  11588. osUTF8 sb = eq.StartEvent("BulkUpdateInventory");
  11589. LLSDxmlEncode2.AddArrayAndMap("AgentData", sb);
  11590. LLSDxmlEncode2.AddElem("AgentID", AgentId, sb);
  11591. LLSDxmlEncode2.AddElem("TransactionID", UUID.Random(), sb);
  11592. LLSDxmlEncode2.AddEndMapAndArray(sb);
  11593. if(folders.Length == 0)
  11594. {
  11595. LLSDxmlEncode2.AddEmptyArray("FolderData", sb);
  11596. }
  11597. else
  11598. {
  11599. LLSDxmlEncode2.AddArray("FolderData", sb);
  11600. foreach (InventoryFolderBase folder in folders)
  11601. {
  11602. LLSDxmlEncode2.AddMap(sb);
  11603. LLSDxmlEncode2.AddElem("FolderID", folder.ID, sb);
  11604. LLSDxmlEncode2.AddElem("ParentID", folder.ParentID, sb);
  11605. LLSDxmlEncode2.AddElem("Type", (int)folder.Type, sb);
  11606. LLSDxmlEncode2.AddElem("Name", folder.Name, sb);
  11607. LLSDxmlEncode2.AddEndMap(sb);
  11608. }
  11609. LLSDxmlEncode2.AddEndArray(sb);
  11610. }
  11611. if(items.Length == 0)
  11612. {
  11613. LLSDxmlEncode2.AddEmptyArray("ItemData", sb);
  11614. }
  11615. else
  11616. {
  11617. LLSDxmlEncode2.AddArray("ItemData", sb);
  11618. foreach (InventoryItemBase item in items)
  11619. {
  11620. LLSDxmlEncode2.AddMap(sb);
  11621. LLSDxmlEncode2.AddElem("ItemID", item.ID, sb);
  11622. LLSDxmlEncode2.AddElem("CallbackID", (uint)0, sb);
  11623. LLSDxmlEncode2.AddElem("FolderID", item.Folder, sb);
  11624. LLSDxmlEncode2.AddElem("CreatorID", item.CreatorIdAsUuid, sb);
  11625. LLSDxmlEncode2.AddElem("OwnerID", item.Owner, sb);
  11626. LLSDxmlEncode2.AddElem("GroupID", item.GroupID, sb);
  11627. LLSDxmlEncode2.AddElem("BaseMask", item.BasePermissions, sb);
  11628. LLSDxmlEncode2.AddElem("OwnerMask", item.CurrentPermissions, sb);
  11629. LLSDxmlEncode2.AddElem("GroupMask", item.GroupPermissions, sb);
  11630. LLSDxmlEncode2.AddElem("EveryoneMask", item.EveryOnePermissions, sb);
  11631. LLSDxmlEncode2.AddElem("NextOwnerMask", item.NextPermissions, sb);
  11632. LLSDxmlEncode2.AddElem("GroupOwned", item.GroupOwned, sb);
  11633. LLSDxmlEncode2.AddElem("AssetID", item.AssetID, sb);
  11634. LLSDxmlEncode2.AddElem("Type", item.AssetType, sb);
  11635. LLSDxmlEncode2.AddElem("InvType", item.InvType, sb);
  11636. LLSDxmlEncode2.AddElem("Flags", item.Flags, sb);
  11637. LLSDxmlEncode2.AddElem("SaleType", item.SaleType, sb);
  11638. LLSDxmlEncode2.AddElem("SalePrice", item.SalePrice, sb);
  11639. LLSDxmlEncode2.AddElem("Name", item.Name, sb);
  11640. LLSDxmlEncode2.AddElem("Description", item.Description, sb);
  11641. LLSDxmlEncode2.AddElem("CreationDate", item.CreationDate, sb);
  11642. LLSDxmlEncode2.AddElem("CRC",
  11643. Helpers.InventoryCRC(1000, 0, (sbyte)item.InvType,
  11644. (sbyte)item.AssetType, item.AssetID,
  11645. item.GroupID, 100,
  11646. item.Owner, item.CreatorIdAsUuid,
  11647. item.ID, item.Folder,
  11648. (uint)PermissionMask.All, 1, (uint)PermissionMask.All, (uint)PermissionMask.All,
  11649. (uint)PermissionMask.All),
  11650. sb);
  11651. LLSDxmlEncode2.AddEndMap(sb);
  11652. }
  11653. LLSDxmlEncode2.AddEndArray(sb);
  11654. }
  11655. eq.Enqueue(eq.EndEventToBytes(sb), AgentId);
  11656. }
  11657. private HashSet<string> m_outPacketsToDrop;
  11658. public bool AddOutPacketToDropSet(string packetName)
  11659. {
  11660. if (m_outPacketsToDrop == null)
  11661. m_outPacketsToDrop = new HashSet<string>();
  11662. return m_outPacketsToDrop.Add(packetName);
  11663. }
  11664. public bool RemoveOutPacketFromDropSet(string packetName)
  11665. {
  11666. if (m_outPacketsToDrop == null)
  11667. return false;
  11668. return m_outPacketsToDrop.Remove(packetName);
  11669. }
  11670. public HashSet<string> GetOutPacketDropSet()
  11671. {
  11672. return new HashSet<string>(m_outPacketsToDrop);
  11673. }
  11674. private HashSet<string> m_inPacketsToDrop;
  11675. public bool AddInPacketToDropSet(string packetName)
  11676. {
  11677. if (m_inPacketsToDrop == null)
  11678. m_inPacketsToDrop = new HashSet<string>();
  11679. return m_inPacketsToDrop.Add(packetName);
  11680. }
  11681. public bool RemoveInPacketFromDropSet(string packetName)
  11682. {
  11683. if (m_inPacketsToDrop == null)
  11684. return false;
  11685. return m_inPacketsToDrop.Remove(packetName);
  11686. }
  11687. public HashSet<string> GetInPacketDropSet()
  11688. {
  11689. return new HashSet<string>(m_inPacketsToDrop);
  11690. }
  11691. public uint GetViewerCaps()
  11692. {
  11693. m_SupportObjectAnimations = false;
  11694. uint ret;
  11695. if(m_supportViewerCache)
  11696. ret = m_viewerHandShakeFlags;
  11697. else
  11698. ret = (m_viewerHandShakeFlags & 4) | 2; // disable probes
  11699. if (m_scene.CapsModule != null)
  11700. {
  11701. Caps cap = m_scene.CapsModule.GetCapsForUser(CircuitCode);
  11702. if(cap != null)
  11703. {
  11704. if((cap.Flags & Caps.CapsFlags.SentSeeds) != 0)
  11705. ret |= 0x1000;
  11706. if ((cap.Flags & Caps.CapsFlags.ObjectAnim) != 0)
  11707. {
  11708. m_SupportObjectAnimations = true;
  11709. ret |= 0x2000;
  11710. }
  11711. if ((cap.Flags & Caps.CapsFlags.WLEnv) != 0)
  11712. ret |= 0x4000;
  11713. if ((cap.Flags & Caps.CapsFlags.AdvEnv) != 0)
  11714. ret |= 0x8000;
  11715. }
  11716. }
  11717. return ret;
  11718. }
  11719. }
  11720. }