LLClientView.cs 303 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200
  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 OpenSim 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.Net.Sockets;
  31. using System.Reflection;
  32. using System.Text;
  33. using System.Threading;
  34. using System.Timers;
  35. using Axiom.Math;
  36. using libsecondlife;
  37. using libsecondlife.Packets;
  38. using log4net;
  39. using OpenSim.Framework;
  40. using OpenSim.Framework.Communications.Cache;
  41. using OpenSim.Region.ClientStack.LindenUDP;
  42. using OpenSim.Region.Environment.Scenes;
  43. using Timer=System.Timers.Timer;
  44. namespace OpenSim.Region.ClientStack.LindenUDP
  45. {
  46. public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
  47. public class PacketDupeLimiter
  48. {
  49. public PacketType pktype;
  50. public int timeIn;
  51. public uint packetId;
  52. public PacketDupeLimiter()
  53. {
  54. }
  55. }
  56. /// <summary>
  57. /// Handles new client connections
  58. /// Constructor takes a single Packet and authenticates everything
  59. /// </summary>
  60. public class LLClientView : IClientAPI
  61. {
  62. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  63. // ~ClientView()
  64. // {
  65. // m_log.Info("[CLIENTVIEW]: Destructor called");
  66. // }
  67. /* static variables */
  68. public static TerrainManager TerrainManager;
  69. public delegate bool SynchronizeClientHandler(IScene scene, Packet packet, LLUUID agentID, ThrottleOutPacketType throttlePacketType);
  70. public static SynchronizeClientHandler SynchronizeClient = null;
  71. /* private variables */
  72. private readonly LLUUID m_sessionId;
  73. private LLUUID m_secureSessionId = LLUUID.Zero;
  74. //private AgentAssetUpload UploadAssets;
  75. private int m_debug = 0;
  76. private readonly AssetCache m_assetCache;
  77. // private InventoryCache m_inventoryCache;
  78. private int m_cachedTextureSerial = 0;
  79. private Timer m_clientPingTimer;
  80. private bool m_clientBlocked = false;
  81. private int m_packetsReceived = 0;
  82. private int m_lastPacketsReceivedSentToScene = 0;
  83. private int m_unAckedBytes = 0;
  84. private int m_packetsSent = 0;
  85. private int m_lastPacketsSentSentToScene = 0;
  86. private int m_clearDuplicatePacketTrackingOlderThenXSeconds = 30;
  87. private int m_probesWithNoIngressPackets = 0;
  88. private int m_lastPacketsReceived = 0;
  89. private byte[] ZeroOutBuffer = new byte[4096];
  90. private readonly LLUUID m_agentId;
  91. private readonly uint m_circuitCode;
  92. private int m_moneyBalance;
  93. private Dictionary<uint, PacketDupeLimiter> m_dupeLimiter = new Dictionary<uint, PacketDupeLimiter>();
  94. private int m_animationSequenceNumber = 1;
  95. private byte[] m_channelVersion = Helpers.StringToField("OpenSimulator 0.5"); // Dummy value needed by libSL
  96. private Dictionary<string, LLUUID> m_defaultAnimations = new Dictionary<string, LLUUID>();
  97. /* protected variables */
  98. protected static Dictionary<PacketType, PacketMethod> PacketHandlers =
  99. new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
  100. protected Dictionary<PacketType, PacketMethod> m_packetHandlers = new Dictionary<PacketType, PacketMethod>();
  101. protected IScene m_scene;
  102. protected AgentCircuitManager m_authenticateSessionsHandler;
  103. protected LLPacketQueue m_packetQueue;
  104. protected Dictionary<uint, uint> m_pendingAcks = new Dictionary<uint, uint>();
  105. protected Dictionary<uint, Packet> m_needAck = new Dictionary<uint, Packet>();
  106. protected Timer m_ackTimer;
  107. protected uint m_sequence = 0;
  108. protected object m_sequenceLock = new object();
  109. protected const int MAX_APPENDED_ACKS = 10;
  110. protected const int RESEND_TIMEOUT = 4000;
  111. protected const int MAX_SEQUENCE = 0xFFFFFF;
  112. protected LLPacketServer m_networkServer;
  113. /* public variables */
  114. protected string m_firstName;
  115. protected string m_lastName;
  116. protected Thread m_clientThread;
  117. protected LLVector3 m_startpos;
  118. protected EndPoint m_userEndPoint;
  119. protected EndPoint m_proxyEndPoint;
  120. protected LLUUID m_activeGroupID = LLUUID.Zero;
  121. protected string m_activeGroupName = String.Empty;
  122. protected ulong m_activeGroupPowers = 0;
  123. /* Instantiated Designated Event Delegates */
  124. //- used so we don't create new objects for each incoming packet and then toss it out later */
  125. private RequestAvatarProperties handlerRequestAvatarProperties = null; //OnRequestAvatarProperties;
  126. private UpdateAvatarProperties handlerUpdateAvatarProperties = null; // OnUpdateAvatarProperties;
  127. private ChatFromViewer handlerChatFromViewer = null; //OnChatFromViewer;
  128. private ChatFromViewer handlerChatFromViewer2 = null; //OnChatFromViewer;
  129. private ImprovedInstantMessage handlerInstantMessage = null; //OnInstantMessage;
  130. private FriendActionDelegate handlerApproveFriendRequest = null; //OnApproveFriendRequest;
  131. private FriendshipTermination handlerTerminateFriendship = null; //OnTerminateFriendship;
  132. private RezObject handlerRezObject = null; //OnRezObject;
  133. private GenericCall4 handlerDeRezObject = null; //OnDeRezObject;
  134. private ModifyTerrain handlerModifyTerrain = null;
  135. private Action<IClientAPI> handlerRegionHandShakeReply = null; //OnRegionHandShakeReply;
  136. private GenericCall2 handlerRequestWearables = null; //OnRequestWearables;
  137. private Action<IClientAPI> handlerRequestAvatarsData = null; //OnRequestAvatarsData;
  138. private SetAppearance handlerSetAppearance = null; //OnSetAppearance;
  139. private AvatarNowWearing handlerAvatarNowWearing = null; //OnAvatarNowWearing;
  140. private RezSingleAttachmentFromInv handlerRezSingleAttachment = null; //OnRezSingleAttachmentFromInv;
  141. private UUIDNameRequest handlerDetachAttachmentIntoInv = null; // Detach attachment!
  142. private ObjectAttach handlerObjectAttach = null; //OnObjectAttach;
  143. private SetAlwaysRun handlerSetAlwaysRun = null; //OnSetAlwaysRun;
  144. private GenericCall2 handlerCompleteMovementToRegion = null; //OnCompleteMovementToRegion;
  145. private UpdateAgent handlerAgentUpdate = null; //OnAgentUpdate;
  146. private StartAnim handlerStartAnim = null;
  147. private StopAnim handlerStopAnim = null;
  148. private AgentRequestSit handlerAgentRequestSit = null; //OnAgentRequestSit;
  149. private AgentSit handlerAgentSit = null; //OnAgentSit;
  150. private AvatarPickerRequest handlerAvatarPickerRequest = null; //OnAvatarPickerRequest;
  151. private FetchInventory handlerAgentDataUpdateRequest = null; //OnAgentDataUpdateRequest;
  152. private FetchInventory handlerUserInfoRequest = null; //OnUserInfoRequest;
  153. private TeleportLocationRequest handlerSetStartLocationRequest = null; //OnSetStartLocationRequest;
  154. private TeleportLandmarkRequest handlerTeleportLandmarkRequest = null; //OnTeleportLandmarkRequest;
  155. private LinkObjects handlerLinkObjects = null; //OnLinkObjects;
  156. private DelinkObjects handlerDelinkObjects = null; //OnDelinkObjects;
  157. private AddNewPrim handlerAddPrim = null; //OnAddPrim;
  158. private UpdateShape handlerUpdatePrimShape = null; //null;
  159. private ObjectExtraParams handlerUpdateExtraParams = null; //OnUpdateExtraParams;
  160. private ObjectDuplicate handlerObjectDuplicate = null;
  161. private ObjectDuplicateOnRay handlerObjectDuplicateOnRay = null;
  162. private ObjectSelect handlerObjectSelect = null;
  163. private ObjectDeselect handlerObjectDeselect = null;
  164. private ObjectIncludeInSearch handlerObjectIncludeInSearch = null;
  165. private UpdatePrimFlags handlerUpdatePrimFlags = null; //OnUpdatePrimFlags;
  166. private UpdatePrimTexture handlerUpdatePrimTexture = null;
  167. private UpdateVector handlerGrabObject = null; //OnGrabObject;
  168. private MoveObject handlerGrabUpdate = null; //OnGrabUpdate;
  169. private ObjectSelect handlerDeGrabObject = null; //OnDeGrabObject;
  170. private GenericCall7 handlerObjectDescription = null;
  171. private GenericCall7 handlerObjectName = null;
  172. private ObjectPermissions handlerObjectPermissions = null;
  173. private RequestObjectPropertiesFamily handlerRequestObjectPropertiesFamily = null; //OnRequestObjectPropertiesFamily;
  174. private TextureRequest handlerTextureRequest = null;
  175. private UDPAssetUploadRequest handlerAssetUploadRequest = null; //OnAssetUploadRequest;
  176. private RequestXfer handlerRequestXfer = null; //OnRequestXfer;
  177. private XferReceive handlerXferReceive = null; //OnXferReceive;
  178. private ConfirmXfer handlerConfirmXfer = null; //OnConfirmXfer;
  179. private CreateInventoryFolder handlerCreateInventoryFolder = null; //OnCreateNewInventoryFolder;
  180. private UpdateInventoryFolder handlerUpdateInventoryFolder = null;
  181. private MoveInventoryFolder handlerMoveInventoryFolder = null;
  182. private CreateNewInventoryItem handlerCreateNewInventoryItem = null; //OnCreateNewInventoryItem;
  183. private FetchInventory handlerFetchInventory = null;
  184. private FetchInventoryDescendents handlerFetchInventoryDescendents = null; //OnFetchInventoryDescendents;
  185. private PurgeInventoryDescendents handlerPurgeInventoryDescendents = null; //OnPurgeInventoryDescendents;
  186. private UpdateInventoryItem handlerUpdateInventoryItem = null;
  187. private CopyInventoryItem handlerCopyInventoryItem = null;
  188. private MoveInventoryItem handlerMoveInventoryItem = null;
  189. private RemoveInventoryItem handlerRemoveInventoryItem = null;
  190. private RemoveInventoryFolder handlerRemoveInventoryFolder = null;
  191. private RequestTaskInventory handlerRequestTaskInventory = null; //OnRequestTaskInventory;
  192. private UpdateTaskInventory handlerUpdateTaskInventory = null; //OnUpdateTaskInventory;
  193. private MoveTaskInventory handlerMoveTaskItem = null;
  194. private RemoveTaskInventory handlerRemoveTaskItem = null; //OnRemoveTaskItem;
  195. private RezScript handlerRezScript = null; //OnRezScript;
  196. private RequestMapBlocks handlerRequestMapBlocks = null; //OnRequestMapBlocks;
  197. private RequestMapName handlerMapNameRequest = null; //OnMapNameRequest;
  198. private TeleportLocationRequest handlerTeleportLocationRequest = null; //OnTeleportLocationRequest;
  199. private MoneyBalanceRequest handlerMoneyBalanceRequest = null; //OnMoneyBalanceRequest;
  200. private UUIDNameRequest handlerNameRequest = null;
  201. private ParcelAccessListRequest handlerParcelAccessListRequest = null; //OnParcelAccessListRequest;
  202. private ParcelAccessListUpdateRequest handlerParcelAccessListUpdateRequest = null; //OnParcelAccessListUpdateRequest;
  203. private ParcelPropertiesRequest handlerParcelPropertiesRequest = null; //OnParcelPropertiesRequest;
  204. private ParcelDivideRequest handlerParcelDivideRequest = null; //OnParcelDivideRequest;
  205. private ParcelJoinRequest handlerParcelJoinRequest = null; //OnParcelJoinRequest;
  206. private ParcelPropertiesUpdateRequest handlerParcelPropertiesUpdateRequest = null; //OnParcelPropertiesUpdateRequest;
  207. private ParcelSelectObjects handlerParcelSelectObjects = null; //OnParcelSelectObjects;
  208. private ParcelObjectOwnerRequest handlerParcelObjectOwnerRequest = null; //OnParcelObjectOwnerRequest;
  209. private ParcelAbandonRequest handlerParcelAbandonRequest = null;
  210. private ParcelReturnObjectsRequest handlerParcelReturnObjectsRequest = null;
  211. private RegionInfoRequest handlerRegionInfoRequest = null; //OnRegionInfoRequest;
  212. private EstateCovenantRequest handlerEstateCovenantRequest = null; //OnEstateCovenantRequest;
  213. private RequestGodlikePowers handlerReqGodlikePowers = null; //OnRequestGodlikePowers;
  214. private GodKickUser handlerGodKickUser = null; //OnGodKickUser;
  215. private ViewerEffectEventHandler handlerViewerEffect = null; //OnViewerEffect;
  216. private Action<IClientAPI> handlerLogout = null; //OnLogout;
  217. private MoneyTransferRequest handlerMoneyTransferRequest = null; //OnMoneyTransferRequest;
  218. private ParcelBuy handlerParcelBuy = null;
  219. private EconomyDataRequest handlerEconomoyDataRequest = null;
  220. private UpdateVector handlerUpdatePrimSinglePosition = null; //OnUpdatePrimSinglePosition;
  221. private UpdatePrimSingleRotation handlerUpdatePrimSingleRotation = null; //OnUpdatePrimSingleRotation;
  222. private UpdateVector handlerUpdatePrimScale = null; //OnUpdatePrimScale;
  223. private UpdateVector handlerUpdatePrimGroupScale = null; //OnUpdateGroupScale;
  224. private UpdateVector handlerUpdateVector = null; //OnUpdatePrimGroupPosition;
  225. private UpdatePrimRotation handlerUpdatePrimRotation = null; //OnUpdatePrimGroupRotation;
  226. private UpdatePrimGroupRotation handlerUpdatePrimGroupRotation = null; //OnUpdatePrimGroupMouseRotation;
  227. private PacketStats handlerPacketStats = null; // OnPacketStats;#
  228. private RequestAsset handlerRequestAsset = null; // OnRequestAsset;
  229. private UUIDNameRequest handlerTeleportHomeRequest = null;
  230. private ScriptAnswer handlerScriptAnswer = null;
  231. private RequestPayPrice handlerRequestPayPrice = null;
  232. private ObjectDeselect handlerObjectDetach = null;
  233. private AgentSit handlerOnUndo = null;
  234. private ForceReleaseControls handlerForceReleaseControls = null;
  235. private GodLandStatRequest handlerLandStatRequest = null;
  236. private UUIDNameRequest handlerUUIDGroupNameRequest = null;
  237. private RequestObjectPropertiesFamily handlerObjectGroupRequest = null;
  238. private ScriptReset handlerScriptReset = null;
  239. /* Properties */
  240. public LLUUID SecureSessionId
  241. {
  242. get { return m_secureSessionId; }
  243. }
  244. public IScene Scene
  245. {
  246. get { return m_scene; }
  247. }
  248. public LLUUID SessionId
  249. {
  250. get { return m_sessionId; }
  251. }
  252. public LLVector3 StartPos
  253. {
  254. get { return m_startpos; }
  255. set { m_startpos = value; }
  256. }
  257. public LLUUID AgentId
  258. {
  259. get { return m_agentId; }
  260. }
  261. public LLUUID ActiveGroupId
  262. {
  263. get { return m_activeGroupID; }
  264. }
  265. public string ActiveGroupName
  266. {
  267. get { return m_activeGroupName; }
  268. }
  269. public ulong ActiveGroupPowers
  270. {
  271. get { return m_activeGroupPowers; }
  272. }
  273. /// <summary>
  274. /// This is a utility method used by single states to not duplicate kicks and blue card of death messages.
  275. /// </summary>
  276. public bool ChildAgentStatus()
  277. {
  278. return m_scene.PresenceChildStatus(AgentId);
  279. }
  280. /// <summary>
  281. /// First name of the agent/avatar represented by the client
  282. /// </summary>
  283. public string FirstName
  284. {
  285. get { return m_firstName; }
  286. }
  287. /// <summary>
  288. /// Last name of the agent/avatar represented by the client
  289. /// </summary>
  290. public string LastName
  291. {
  292. get { return m_lastName; }
  293. }
  294. /// <summary>
  295. /// Full name of the client (first name and last name)
  296. /// </summary>
  297. public string Name
  298. {
  299. get { return FirstName + " " + LastName; }
  300. }
  301. public uint CircuitCode
  302. {
  303. get { return m_circuitCode; }
  304. }
  305. public int MoneyBalance
  306. {
  307. get { return m_moneyBalance; }
  308. }
  309. public int NextAnimationSequenceNumber
  310. {
  311. get { return m_animationSequenceNumber++; }
  312. }
  313. /* METHODS */
  314. public LLClientView(EndPoint remoteEP, IScene scene, AssetCache assetCache, LLPacketServer packServer,
  315. AgentCircuitManager authenSessions, LLUUID agentId, LLUUID sessionId, uint circuitCode, EndPoint proxyEP)
  316. {
  317. m_moneyBalance = 1000;
  318. m_channelVersion = Helpers.StringToField("OpenSimulator Server " + scene.GetSimulatorVersion());
  319. InitDefaultAnimations();
  320. m_scene = scene;
  321. m_assetCache = assetCache;
  322. m_networkServer = packServer;
  323. // m_inventoryCache = inventoryCache;
  324. m_authenticateSessionsHandler = authenSessions;
  325. m_log.Info("[CLIENT]: Started up new client thread to handle incoming request");
  326. m_agentId = agentId;
  327. m_sessionId = sessionId;
  328. m_circuitCode = circuitCode;
  329. m_userEndPoint = remoteEP;
  330. m_proxyEndPoint = proxyEP;
  331. m_startpos = m_authenticateSessionsHandler.GetPosition(circuitCode);
  332. // While working on this, the BlockingQueue had me fooled for a bit.
  333. // The Blocking queue causes the thread to stop until there's something
  334. // in it to process. It's an on-purpose threadlock though because
  335. // without it, the clientloop will suck up all sim resources.
  336. m_packetQueue = new LLPacketQueue(agentId);
  337. RegisterLocalPacketHandlers();
  338. m_clientThread = new Thread(new ThreadStart(AuthUser));
  339. m_clientThread.Name = "ClientThread";
  340. m_clientThread.IsBackground = true;
  341. m_clientThread.Start();
  342. ThreadTracker.Add(m_clientThread);
  343. }
  344. public void SetDebug(int newDebug)
  345. {
  346. m_debug = newDebug;
  347. }
  348. # region Client Methods
  349. private void CloseCleanup(bool shutdownCircuit)
  350. {
  351. m_scene.RemoveClient(AgentId);
  352. //m_log.InfoFormat("[CLIENTVIEW] Memory pre GC {0}", System.GC.GetTotalMemory(false));
  353. //m_log.InfoFormat("[CLIENTVIEW] Memory post GC {0}", System.GC.GetTotalMemory(true));
  354. // Send the STOP packet
  355. DisableSimulatorPacket disable = (DisableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
  356. OutPacket(disable, ThrottleOutPacketType.Unknown);
  357. m_packetQueue.Close();
  358. Thread.Sleep(2000);
  359. // Shut down timers
  360. m_ackTimer.Stop();
  361. m_clientPingTimer.Stop();
  362. // This is just to give the client a reasonable chance of
  363. // flushing out all it's packets. There should probably
  364. // be a better mechanism here
  365. // We can't reach into other scenes and close the connection
  366. // We need to do this over grid communications
  367. //m_scene.CloseAllAgents(CircuitCode);
  368. // If we're not shutting down the circuit, then this is the last time we'll go here.
  369. // If we are shutting down the circuit, the UDP Server will come back here with
  370. // ShutDownCircuit = false
  371. if (!(shutdownCircuit))
  372. {
  373. GC.Collect();
  374. m_clientThread.Abort();
  375. }
  376. }
  377. /// <summary>
  378. /// Close down the client view. This *must* be the last method called, since the last #
  379. /// statement of CloseCleanup() aborts the thread.
  380. /// </summary>
  381. /// <param name="shutdownCircuit"></param>
  382. public void Close(bool shutdownCircuit)
  383. {
  384. // Pull Client out of Region
  385. m_log.Info("[CLIENT]: Close has been called");
  386. m_packetQueue.Flush();
  387. //raiseevent on the packet server to Shutdown the circuit
  388. if (shutdownCircuit)
  389. {
  390. OnConnectionClosed(this);
  391. }
  392. CloseCleanup(shutdownCircuit);
  393. }
  394. public void Kick(string message)
  395. {
  396. if (!ChildAgentStatus())
  397. {
  398. KickUserPacket kupack = (KickUserPacket)PacketPool.Instance.GetPacket(PacketType.KickUser);
  399. kupack.UserInfo.AgentID = AgentId;
  400. kupack.UserInfo.SessionID = SessionId;
  401. kupack.TargetBlock.TargetIP = (uint)0;
  402. kupack.TargetBlock.TargetPort = (ushort)0;
  403. kupack.UserInfo.Reason = Helpers.StringToField(message);
  404. OutPacket(kupack, ThrottleOutPacketType.Task);
  405. // You must sleep here or users get no message!
  406. Thread.Sleep(500);
  407. }
  408. }
  409. public void Stop()
  410. {
  411. // Shut down timers
  412. m_ackTimer.Stop();
  413. m_clientPingTimer.Stop();
  414. }
  415. public void Restart()
  416. {
  417. // re-construct
  418. m_pendingAcks = new Dictionary<uint, uint>();
  419. m_needAck = new Dictionary<uint, Packet>();
  420. m_sequence += 1000000;
  421. m_ackTimer = new Timer(750);
  422. m_ackTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
  423. m_ackTimer.Start();
  424. m_clientPingTimer = new Timer(5000);
  425. m_clientPingTimer.Elapsed += new ElapsedEventHandler(CheckClientConnectivity);
  426. m_clientPingTimer.Enabled = true;
  427. }
  428. public void Terminate()
  429. {
  430. // disable blocking queue
  431. m_packetQueue.Enqueue(null);
  432. // wait for thread stoped
  433. m_clientThread.Join();
  434. // delete circuit code
  435. m_networkServer.CloseClient(this);
  436. }
  437. #endregion
  438. # region Packet Handling
  439. public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
  440. {
  441. bool result = false;
  442. lock (PacketHandlers)
  443. {
  444. if (!PacketHandlers.ContainsKey(packetType))
  445. {
  446. PacketHandlers.Add(packetType, handler);
  447. result = true;
  448. }
  449. }
  450. return result;
  451. }
  452. public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
  453. {
  454. bool result = false;
  455. lock (m_packetHandlers)
  456. {
  457. if (!m_packetHandlers.ContainsKey(packetType))
  458. {
  459. m_packetHandlers.Add(packetType, handler);
  460. result = true;
  461. }
  462. }
  463. return result;
  464. }
  465. /// <summary>
  466. /// Try to process a packet using registered packet handlers
  467. /// </summary>
  468. /// <param name="packet"></param>
  469. /// <returns>True if a handler was found which successfully processed the packet.</returns>
  470. protected virtual bool ProcessPacketMethod(Packet packet)
  471. {
  472. bool result = false;
  473. bool found = false;
  474. PacketMethod method;
  475. if (m_packetHandlers.TryGetValue(packet.Type, out method))
  476. {
  477. //there is a local handler for this packet type
  478. result = method(this, packet);
  479. }
  480. else
  481. {
  482. //there is not a local handler so see if there is a Global handler
  483. lock (PacketHandlers)
  484. {
  485. found = PacketHandlers.TryGetValue(packet.Type, out method);
  486. }
  487. if (found)
  488. {
  489. result = method(this, packet);
  490. }
  491. }
  492. return result;
  493. }
  494. protected void DebugPacket(string direction, Packet packet)
  495. {
  496. if (m_debug > 0)
  497. {
  498. string info = String.Empty;
  499. if (m_debug < 255 && packet.Type == PacketType.AgentUpdate)
  500. return;
  501. if (m_debug < 254 && packet.Type == PacketType.ViewerEffect)
  502. return;
  503. if (m_debug < 253 && (
  504. packet.Type == PacketType.CompletePingCheck ||
  505. packet.Type == PacketType.StartPingCheck
  506. ))
  507. return;
  508. if (m_debug < 252 && packet.Type == PacketType.PacketAck)
  509. return;
  510. if (m_debug > 1)
  511. {
  512. info = packet.ToString();
  513. }
  514. else
  515. {
  516. info = packet.Type.ToString();
  517. }
  518. Console.WriteLine(m_circuitCode + ":" + direction + ": " + info);
  519. }
  520. }
  521. protected virtual void ClientLoop()
  522. {
  523. m_log.Info("[CLIENT]: Entered loop");
  524. while (true)
  525. {
  526. LLQueItem nextPacket = m_packetQueue.Dequeue();
  527. if (nextPacket == null)
  528. {
  529. m_log.Error("Got a NULL packet in Client Loop, bailing out of our client loop");
  530. break;
  531. }
  532. if (nextPacket.Incoming)
  533. {
  534. if (nextPacket.Packet.Type != PacketType.AgentUpdate)
  535. {
  536. m_packetsReceived++;
  537. }
  538. DebugPacket("IN", nextPacket.Packet);
  539. ProcessInPacket(nextPacket.Packet);
  540. }
  541. else
  542. {
  543. DebugPacket("OUT", nextPacket.Packet);
  544. ProcessOutPacket(nextPacket.Packet);
  545. }
  546. }
  547. }
  548. # endregion
  549. protected void CheckClientConnectivity(object sender, ElapsedEventArgs e)
  550. {
  551. if (m_packetsReceived == m_lastPacketsReceived)
  552. {
  553. m_probesWithNoIngressPackets++;
  554. if ((m_probesWithNoIngressPackets > 30 && !m_clientBlocked) || (m_probesWithNoIngressPackets > 90 && m_clientBlocked))
  555. {
  556. if (OnConnectionClosed != null)
  557. {
  558. OnConnectionClosed(this);
  559. }
  560. }
  561. else
  562. {
  563. // this will normally trigger at least one packet (ping response)
  564. SendStartPingCheck(0);
  565. }
  566. }
  567. else
  568. {
  569. // Something received in the meantime - we can reset the counters
  570. m_probesWithNoIngressPackets = 0;
  571. m_lastPacketsReceived = m_packetsReceived;
  572. }
  573. //SendPacketStats();
  574. }
  575. # region Setup
  576. protected virtual void InitNewClient()
  577. {
  578. //this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
  579. // Establish our two timers. We could probably get this down to one
  580. m_ackTimer = new Timer(750);
  581. m_ackTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
  582. m_ackTimer.Start();
  583. m_clientPingTimer = new Timer(5000);
  584. m_clientPingTimer.Elapsed += new ElapsedEventHandler(CheckClientConnectivity);
  585. m_clientPingTimer.Enabled = true;
  586. m_log.Info("[CLIENT]: Adding viewer agent to scene");
  587. m_scene.AddNewClient(this, true);
  588. }
  589. protected virtual void AuthUser()
  590. {
  591. // AuthenticateResponse sessionInfo = m_gridServer.AuthenticateSession(m_cirpack.m_circuitCode.m_sessionId, m_cirpack.m_circuitCode.ID, m_cirpack.m_circuitCode.Code);
  592. AuthenticateResponse sessionInfo =
  593. m_authenticateSessionsHandler.AuthenticateSession(m_sessionId, m_agentId,
  594. m_circuitCode);
  595. if (!sessionInfo.Authorised)
  596. {
  597. //session/circuit not authorised
  598. m_log.Info("[CLIENT]: New user request denied to " + m_userEndPoint.ToString());
  599. m_packetQueue.Close();
  600. m_clientThread.Abort();
  601. }
  602. else
  603. {
  604. m_log.Info("[CLIENT]: Got authenticated connection from " + m_userEndPoint.ToString());
  605. //session is authorised
  606. m_firstName = sessionInfo.LoginInfo.First;
  607. m_lastName = sessionInfo.LoginInfo.Last;
  608. if (sessionInfo.LoginInfo.SecureSession != LLUUID.Zero)
  609. {
  610. m_secureSessionId = sessionInfo.LoginInfo.SecureSession;
  611. }
  612. // This sets up all the timers
  613. InitNewClient();
  614. ClientLoop();
  615. }
  616. }
  617. # endregion
  618. // Previously ClientView.API partial class
  619. public event Action<IClientAPI> OnLogout;
  620. public event ObjectPermissions OnObjectPermissions;
  621. public event Action<IClientAPI> OnConnectionClosed;
  622. public event ViewerEffectEventHandler OnViewerEffect;
  623. public event ImprovedInstantMessage OnInstantMessage;
  624. public event ChatFromViewer OnChatFromViewer;
  625. public event TextureRequest OnRequestTexture;
  626. public event RezObject OnRezObject;
  627. public event GenericCall4 OnDeRezObject;
  628. public event ModifyTerrain OnModifyTerrain;
  629. public event Action<IClientAPI> OnRegionHandShakeReply;
  630. public event GenericCall2 OnRequestWearables;
  631. public event SetAppearance OnSetAppearance;
  632. public event AvatarNowWearing OnAvatarNowWearing;
  633. public event RezSingleAttachmentFromInv OnRezSingleAttachmentFromInv;
  634. public event UUIDNameRequest OnDetachAttachmentIntoInv;
  635. public event ObjectAttach OnObjectAttach;
  636. public event ObjectDeselect OnObjectDetach;
  637. public event GenericCall2 OnCompleteMovementToRegion;
  638. public event UpdateAgent OnAgentUpdate;
  639. public event AgentRequestSit OnAgentRequestSit;
  640. public event AgentSit OnAgentSit;
  641. public event AvatarPickerRequest OnAvatarPickerRequest;
  642. public event StartAnim OnStartAnim;
  643. public event StopAnim OnStopAnim;
  644. public event Action<IClientAPI> OnRequestAvatarsData;
  645. public event LinkObjects OnLinkObjects;
  646. public event DelinkObjects OnDelinkObjects;
  647. public event UpdateVector OnGrabObject;
  648. public event ObjectSelect OnDeGrabObject;
  649. public event ObjectDuplicate OnObjectDuplicate;
  650. public event ObjectDuplicateOnRay OnObjectDuplicateOnRay;
  651. public event MoveObject OnGrabUpdate;
  652. public event AddNewPrim OnAddPrim;
  653. public event RequestGodlikePowers OnRequestGodlikePowers;
  654. public event GodKickUser OnGodKickUser;
  655. public event ObjectExtraParams OnUpdateExtraParams;
  656. public event UpdateShape OnUpdatePrimShape;
  657. public event ObjectSelect OnObjectSelect;
  658. public event ObjectDeselect OnObjectDeselect;
  659. public event GenericCall7 OnObjectDescription;
  660. public event GenericCall7 OnObjectName;
  661. public event ObjectIncludeInSearch OnObjectIncludeInSearch;
  662. public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
  663. public event UpdatePrimFlags OnUpdatePrimFlags;
  664. public event UpdatePrimTexture OnUpdatePrimTexture;
  665. public event UpdateVector OnUpdatePrimGroupPosition;
  666. public event UpdateVector OnUpdatePrimSinglePosition;
  667. public event UpdatePrimRotation OnUpdatePrimGroupRotation;
  668. public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
  669. public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
  670. public event UpdateVector OnUpdatePrimScale;
  671. public event UpdateVector OnUpdatePrimGroupScale;
  672. public event StatusChange OnChildAgentStatus;
  673. public event GenericCall2 OnStopMovement;
  674. public event Action<LLUUID> OnRemoveAvatar;
  675. public event RequestMapBlocks OnRequestMapBlocks;
  676. public event RequestMapName OnMapNameRequest;
  677. public event TeleportLocationRequest OnTeleportLocationRequest;
  678. public event TeleportLandmarkRequest OnTeleportLandmarkRequest;
  679. public event DisconnectUser OnDisconnectUser;
  680. public event RequestAvatarProperties OnRequestAvatarProperties;
  681. public event SetAlwaysRun OnSetAlwaysRun;
  682. public event FetchInventory OnAgentDataUpdateRequest;
  683. public event FetchInventory OnUserInfoRequest;
  684. public event TeleportLocationRequest OnSetStartLocationRequest;
  685. public event UpdateAvatarProperties OnUpdateAvatarProperties;
  686. public event CreateNewInventoryItem OnCreateNewInventoryItem;
  687. public event CreateInventoryFolder OnCreateNewInventoryFolder;
  688. public event UpdateInventoryFolder OnUpdateInventoryFolder;
  689. public event MoveInventoryFolder OnMoveInventoryFolder;
  690. public event FetchInventoryDescendents OnFetchInventoryDescendents;
  691. public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
  692. public event FetchInventory OnFetchInventory;
  693. public event RequestTaskInventory OnRequestTaskInventory;
  694. public event UpdateInventoryItem OnUpdateInventoryItem;
  695. public event CopyInventoryItem OnCopyInventoryItem;
  696. public event MoveInventoryItem OnMoveInventoryItem;
  697. public event RemoveInventoryItem OnRemoveInventoryItem;
  698. public event RemoveInventoryFolder OnRemoveInventoryFolder;
  699. public event UDPAssetUploadRequest OnAssetUploadRequest;
  700. public event XferReceive OnXferReceive;
  701. public event RequestXfer OnRequestXfer;
  702. public event ConfirmXfer OnConfirmXfer;
  703. public event RezScript OnRezScript;
  704. public event UpdateTaskInventory OnUpdateTaskInventory;
  705. public event MoveTaskInventory OnMoveTaskItem;
  706. public event RemoveTaskInventory OnRemoveTaskItem;
  707. public event RequestAsset OnRequestAsset;
  708. public event UUIDNameRequest OnNameFromUUIDRequest;
  709. public event ParcelAccessListRequest OnParcelAccessListRequest;
  710. public event ParcelAccessListUpdateRequest OnParcelAccessListUpdateRequest;
  711. public event ParcelPropertiesRequest OnParcelPropertiesRequest;
  712. public event ParcelDivideRequest OnParcelDivideRequest;
  713. public event ParcelJoinRequest OnParcelJoinRequest;
  714. public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
  715. public event ParcelSelectObjects OnParcelSelectObjects;
  716. public event ParcelObjectOwnerRequest OnParcelObjectOwnerRequest;
  717. public event ParcelAbandonRequest OnParcelAbandonRequest;
  718. public event ParcelReturnObjectsRequest OnParcelReturnObjectsRequest;
  719. public event RegionInfoRequest OnRegionInfoRequest;
  720. public event EstateCovenantRequest OnEstateCovenantRequest;
  721. public event FriendActionDelegate OnApproveFriendRequest;
  722. public event FriendActionDelegate OnDenyFriendRequest;
  723. public event FriendshipTermination OnTerminateFriendship;
  724. public event PacketStats OnPacketStats;
  725. public event MoneyTransferRequest OnMoneyTransferRequest;
  726. public event EconomyDataRequest OnEconomyDataRequest;
  727. public event MoneyBalanceRequest OnMoneyBalanceRequest;
  728. public event ParcelBuy OnParcelBuy;
  729. public event UUIDNameRequest OnTeleportHomeRequest;
  730. public event UUIDNameRequest OnUUIDGroupNameRequest;
  731. public event ScriptAnswer OnScriptAnswer;
  732. public event RequestPayPrice OnRequestPayPrice;
  733. public event AgentSit OnUndo;
  734. public event ForceReleaseControls OnForceReleaseControls;
  735. public event GodLandStatRequest OnLandStatRequest;
  736. public event RequestObjectPropertiesFamily OnObjectGroupRequest;
  737. public event DetailedEstateDataRequest OnDetailedEstateDataRequest;
  738. public event SetEstateFlagsRequest OnSetEstateFlagsRequest;
  739. public event SetEstateTerrainBaseTexture OnSetEstateTerrainBaseTexture;
  740. public event SetEstateTerrainDetailTexture OnSetEstateTerrainDetailTexture;
  741. public event SetEstateTerrainTextureHeights OnSetEstateTerrainTextureHeights;
  742. public event CommitEstateTerrainTextureRequest OnCommitEstateTerrainTextureRequest;
  743. public event SetRegionTerrainSettings OnSetRegionTerrainSettings;
  744. public event EstateRestartSimRequest OnEstateRestartSimRequest;
  745. public event EstateChangeCovenantRequest OnEstateChangeCovenantRequest;
  746. public event UpdateEstateAccessDeltaRequest OnUpdateEstateAccessDeltaRequest;
  747. public event SimulatorBlueBoxMessageRequest OnSimulatorBlueBoxMessageRequest;
  748. public event EstateBlueBoxMessageRequest OnEstateBlueBoxMessageRequest;
  749. public event EstateDebugRegionRequest OnEstateDebugRegionRequest;
  750. public event EstateTeleportOneUserHomeRequest OnEstateTeleportOneUserHomeRequest;
  751. public event ScriptReset OnScriptReset;
  752. #region Scene/Avatar to Client
  753. /// <summary>
  754. ///
  755. /// </summary>
  756. /// <param name="regionInfo"></param>
  757. public void SendRegionHandshake(RegionInfo regionInfo, RegionHandshakeArgs args)
  758. {
  759. RegionHandshakePacket handshake = (RegionHandshakePacket)PacketPool.Instance.GetPacket(PacketType.RegionHandshake);
  760. handshake.RegionInfo.BillableFactor = args.billableFactor;
  761. handshake.RegionInfo.IsEstateManager = args.isEstateManager;
  762. handshake.RegionInfo.TerrainHeightRange00 = args.terrainHeightRange0;
  763. handshake.RegionInfo.TerrainHeightRange01 = args.terrainHeightRange1;
  764. handshake.RegionInfo.TerrainHeightRange10 = args.terrainHeightRange2;
  765. handshake.RegionInfo.TerrainHeightRange11 = args.terrainHeightRange3;
  766. handshake.RegionInfo.TerrainStartHeight00 = args.terrainStartHeight0;
  767. handshake.RegionInfo.TerrainStartHeight01 = args.terrainStartHeight1;
  768. handshake.RegionInfo.TerrainStartHeight10 = args.terrainStartHeight2;
  769. handshake.RegionInfo.TerrainStartHeight11 = args.terrainStartHeight3;
  770. handshake.RegionInfo.SimAccess = args.simAccess;
  771. handshake.RegionInfo.WaterHeight = args.waterHeight;
  772. handshake.RegionInfo.RegionFlags = args.regionFlags;
  773. handshake.RegionInfo.SimName = Helpers.StringToField(args.regionName);
  774. handshake.RegionInfo.SimOwner = args.SimOwner;
  775. handshake.RegionInfo.TerrainBase0 = args.terrainBase0;
  776. handshake.RegionInfo.TerrainBase1 = args.terrainBase1;
  777. handshake.RegionInfo.TerrainBase2 = args.terrainBase2;
  778. handshake.RegionInfo.TerrainBase3 = args.terrainBase3;
  779. handshake.RegionInfo.TerrainDetail0 = args.terrainDetail0;
  780. handshake.RegionInfo.TerrainDetail1 = args.terrainDetail1;
  781. handshake.RegionInfo.TerrainDetail2 = args.terrainDetail2;
  782. handshake.RegionInfo.TerrainDetail3 = args.terrainDetail3;
  783. handshake.RegionInfo.CacheID = LLUUID.Random(); //I guess this is for the client to remember an old setting?
  784. OutPacket(handshake, ThrottleOutPacketType.Task);
  785. }
  786. /// <summary>
  787. ///
  788. /// </summary>
  789. /// <param name="regInfo"></param>
  790. public void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look)
  791. {
  792. AgentMovementCompletePacket mov = (AgentMovementCompletePacket)PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete);
  793. mov.SimData.ChannelVersion = m_channelVersion;
  794. mov.AgentData.SessionID = m_sessionId;
  795. mov.AgentData.AgentID = AgentId;
  796. mov.Data.RegionHandle = regInfo.RegionHandle;
  797. mov.Data.Timestamp = 1172750370; // TODO - dynamicalise this
  798. if ((pos.X == 0) && (pos.Y == 0) && (pos.Z == 0))
  799. {
  800. mov.Data.Position = m_startpos;
  801. }
  802. else
  803. {
  804. mov.Data.Position = pos;
  805. }
  806. mov.Data.LookAt = look;
  807. // Hack to get this out immediately and skip the throttles
  808. OutPacket(mov, ThrottleOutPacketType.Unknown);
  809. }
  810. /// <summary>
  811. ///
  812. /// </summary>
  813. /// <param name="message"></param>
  814. /// <param name="type"></param>
  815. /// <param name="fromPos"></param>
  816. /// <param name="fromName"></param>
  817. /// <param name="fromAgentID"></param>
  818. public void SendChatMessage(string message, byte type, LLVector3 fromPos, string fromName,
  819. LLUUID fromAgentID, byte source, byte audible)
  820. {
  821. SendChatMessage(Helpers.StringToField(message), type, fromPos, fromName, fromAgentID, source, audible);
  822. }
  823. public void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName,
  824. LLUUID fromAgentID, byte source, byte audible)
  825. {
  826. ChatFromSimulatorPacket reply = (ChatFromSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.ChatFromSimulator);
  827. reply.ChatData.Audible = audible;
  828. reply.ChatData.Message = message;
  829. reply.ChatData.ChatType = type;
  830. reply.ChatData.SourceType = source;
  831. reply.ChatData.Position = fromPos;
  832. reply.ChatData.FromName = Helpers.StringToField(fromName);
  833. reply.ChatData.OwnerID = fromAgentID;
  834. reply.ChatData.SourceID = fromAgentID;
  835. OutPacket(reply, ThrottleOutPacketType.Task);
  836. }
  837. /// <summary>
  838. /// Send an instant message to this client
  839. /// </summary>
  840. /// <param name="message"></param>
  841. /// <param name="target"></param>
  842. public void SendInstantMessage(LLUUID fromAgent, LLUUID fromAgentSession, string message, LLUUID toAgent,
  843. LLUUID imSessionID, string fromName, byte dialog, uint timeStamp)
  844. {
  845. SendInstantMessage(
  846. fromAgent, fromAgentSession, message, toAgent,
  847. imSessionID, fromName, dialog, timeStamp, new byte[0]);
  848. }
  849. /// <summary>
  850. /// Send an instant message to this client
  851. /// </summary>
  852. /// <param name="message"></param>
  853. /// <param name="target"></param>
  854. public void SendInstantMessage(LLUUID fromAgent, LLUUID fromAgentSession, string message, LLUUID toAgent,
  855. LLUUID imSessionID, string fromName, byte dialog, uint timeStamp,
  856. byte[] binaryBucket)
  857. {
  858. if (((Scene)(this.m_scene)).ExternalChecks.ExternalChecksCanInstantMessage(fromAgent, toAgent))
  859. {
  860. ImprovedInstantMessagePacket msg
  861. = (ImprovedInstantMessagePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedInstantMessage);
  862. msg.AgentData.AgentID = fromAgent;
  863. msg.AgentData.SessionID = fromAgentSession;
  864. msg.MessageBlock.FromAgentName = Helpers.StringToField(fromName);
  865. msg.MessageBlock.Dialog = dialog;
  866. msg.MessageBlock.FromGroup = false;
  867. msg.MessageBlock.ID = imSessionID;
  868. msg.MessageBlock.Offline = 0;
  869. msg.MessageBlock.ParentEstateID = 0;
  870. msg.MessageBlock.Position = new LLVector3();
  871. msg.MessageBlock.RegionID = LLUUID.Random();
  872. msg.MessageBlock.Timestamp = timeStamp;
  873. msg.MessageBlock.ToAgentID = toAgent;
  874. msg.MessageBlock.Message = Helpers.StringToField(message);
  875. msg.MessageBlock.BinaryBucket = binaryBucket;
  876. OutPacket(msg, ThrottleOutPacketType.Task);
  877. }
  878. }
  879. /// <summary>
  880. /// Send the region heightmap to the client
  881. /// </summary>
  882. /// <param name="map">heightmap</param>
  883. public virtual void SendLayerData(float[] map)
  884. {
  885. ThreadPool.QueueUserWorkItem(new WaitCallback(DoSendLayerData), (object)map);
  886. //try
  887. //{
  888. // int[] patches = new int[4];
  889. // for (int y = 0; y < 16; y++)
  890. // {
  891. // for (int x = 0; x < 16; x += 4)
  892. // {
  893. // patches[0] = x + 0 + y * 16;
  894. // patches[1] = x + 1 + y * 16;
  895. // patches[2] = x + 2 + y * 16;
  896. // patches[3] = x + 3 + y * 16;
  897. // Packet layerpack = LLClientView.TerrainManager.CreateLandPacket(map, patches);
  898. // OutPacket(layerpack, ThrottleOutPacketType.Land);
  899. // }
  900. // }
  901. //}
  902. //catch (Exception e)
  903. //{
  904. // m_log.Warn("[client]: " +
  905. // "ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString());
  906. //}
  907. }
  908. private void DoSendLayerData(object o)
  909. {
  910. float[] map = (float[])o;
  911. try
  912. {
  913. for (int y = 0; y < 16; y++)
  914. {
  915. for (int x = 0; x < 16; x += 4)
  916. {
  917. SendLayerPacket(map, y, x);
  918. Thread.Sleep(150);
  919. }
  920. }
  921. }
  922. catch (Exception e)
  923. {
  924. m_log.Warn("[client]: " +
  925. "ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString());
  926. }
  927. }
  928. private void SendLayerPacket(float[] map, int y, int x)
  929. {
  930. int[] patches = new int[4];
  931. patches[0] = x + 0 + y * 16;
  932. patches[1] = x + 1 + y * 16;
  933. patches[2] = x + 2 + y * 16;
  934. patches[3] = x + 3 + y * 16;
  935. Packet layerpack = LLClientView.TerrainManager.CreateLandPacket(map, patches);
  936. OutPacket(layerpack, ThrottleOutPacketType.Land);
  937. }
  938. /// <summary>
  939. /// Sends a specified patch to a client
  940. /// </summary>
  941. /// <param name="px">Patch coordinate (x) 0..16</param>
  942. /// <param name="py">Patch coordinate (y) 0..16</param>
  943. /// <param name="map">heightmap</param>
  944. public void SendLayerData(int px, int py, float[] map)
  945. {
  946. try
  947. {
  948. int[] patches = new int[1];
  949. int patchx, patchy;
  950. patchx = px;
  951. patchy = py;
  952. patches[0] = patchx + 0 + patchy * 16;
  953. Packet layerpack = LLClientView.TerrainManager.CreateLandPacket(map, patches);
  954. layerpack.Header.Zerocoded = true;
  955. OutPacket(layerpack, ThrottleOutPacketType.Land);
  956. }
  957. catch (Exception e)
  958. {
  959. m_log.Warn("[client]: " +
  960. "ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString());
  961. }
  962. }
  963. /// <summary>
  964. ///
  965. /// </summary>
  966. /// <param name="neighbourHandle"></param>
  967. /// <param name="neighbourIP"></param>
  968. /// <param name="neighbourPort"></param>
  969. public void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourEndPoint)
  970. {
  971. IPAddress neighbourIP = neighbourEndPoint.Address;
  972. ushort neighbourPort = (ushort)neighbourEndPoint.Port;
  973. EnableSimulatorPacket enablesimpacket = (EnableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.EnableSimulator);
  974. // TODO: don't create new blocks if recycling an old packet
  975. enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock();
  976. enablesimpacket.SimulatorInfo.Handle = neighbourHandle;
  977. byte[] byteIP = neighbourIP.GetAddressBytes();
  978. enablesimpacket.SimulatorInfo.IP = (uint)byteIP[3] << 24;
  979. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[2] << 16;
  980. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[1] << 8;
  981. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[0];
  982. enablesimpacket.SimulatorInfo.Port = neighbourPort;
  983. OutPacket(enablesimpacket, ThrottleOutPacketType.Task);
  984. }
  985. /// <summary>
  986. ///
  987. /// </summary>
  988. /// <returns></returns>
  989. public AgentCircuitData RequestClientInfo()
  990. {
  991. AgentCircuitData agentData = new AgentCircuitData();
  992. agentData.AgentID = AgentId;
  993. agentData.SessionID = m_sessionId;
  994. agentData.SecureSessionID = SecureSessionId;
  995. agentData.circuitcode = m_circuitCode;
  996. agentData.child = false;
  997. agentData.firstname = m_firstName;
  998. agentData.lastname = m_lastName;
  999. agentData.CapsPath = m_scene.GetCapsPath(m_agentId);
  1000. return agentData;
  1001. }
  1002. public void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt, IPEndPoint externalIPEndPoint,
  1003. string capsURL)
  1004. {
  1005. LLVector3 look = new LLVector3(lookAt.X * 10, lookAt.Y * 10, lookAt.Z * 10);
  1006. //CrossedRegionPacket newSimPack = (CrossedRegionPacket)PacketPool.Instance.GetPacket(PacketType.CrossedRegion);
  1007. CrossedRegionPacket newSimPack = new CrossedRegionPacket();
  1008. // TODO: don't create new blocks if recycling an old packet
  1009. newSimPack.AgentData = new CrossedRegionPacket.AgentDataBlock();
  1010. newSimPack.AgentData.AgentID = AgentId;
  1011. newSimPack.AgentData.SessionID = m_sessionId;
  1012. newSimPack.Info = new CrossedRegionPacket.InfoBlock();
  1013. newSimPack.Info.Position = pos;
  1014. newSimPack.Info.LookAt = look;
  1015. newSimPack.RegionData = new CrossedRegionPacket.RegionDataBlock();
  1016. newSimPack.RegionData.RegionHandle = newRegionHandle;
  1017. byte[] byteIP = externalIPEndPoint.Address.GetAddressBytes();
  1018. newSimPack.RegionData.SimIP = (uint)byteIP[3] << 24;
  1019. newSimPack.RegionData.SimIP += (uint)byteIP[2] << 16;
  1020. newSimPack.RegionData.SimIP += (uint)byteIP[1] << 8;
  1021. newSimPack.RegionData.SimIP += (uint)byteIP[0];
  1022. newSimPack.RegionData.SimPort = (ushort)externalIPEndPoint.Port;
  1023. newSimPack.RegionData.SeedCapability = Helpers.StringToField(capsURL);
  1024. // Hack to get this out immediately and skip throttles
  1025. OutPacket(newSimPack, ThrottleOutPacketType.Unknown);
  1026. }
  1027. public void SendMapBlock(List<MapBlockData> mapBlocks)
  1028. {
  1029. MapBlockReplyPacket mapReply = (MapBlockReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapBlockReply);
  1030. // TODO: don't create new blocks if recycling an old packet
  1031. mapReply.AgentData.AgentID = AgentId;
  1032. mapReply.Data = new MapBlockReplyPacket.DataBlock[mapBlocks.Count];
  1033. mapReply.AgentData.Flags = 0;
  1034. for (int i = 0; i < mapBlocks.Count; i++)
  1035. {
  1036. mapReply.Data[i] = new MapBlockReplyPacket.DataBlock();
  1037. mapReply.Data[i].MapImageID = mapBlocks[i].MapImageId;
  1038. mapReply.Data[i].X = mapBlocks[i].X;
  1039. mapReply.Data[i].Y = mapBlocks[i].Y;
  1040. mapReply.Data[i].WaterHeight = mapBlocks[i].WaterHeight;
  1041. mapReply.Data[i].Name = Helpers.StringToField(mapBlocks[i].Name);
  1042. mapReply.Data[i].RegionFlags = mapBlocks[i].RegionFlags;
  1043. mapReply.Data[i].Access = mapBlocks[i].Access;
  1044. mapReply.Data[i].Agents = mapBlocks[i].Agents;
  1045. }
  1046. OutPacket(mapReply, ThrottleOutPacketType.Land);
  1047. }
  1048. public void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags)
  1049. {
  1050. TeleportLocalPacket tpLocal = (TeleportLocalPacket)PacketPool.Instance.GetPacket(PacketType.TeleportLocal);
  1051. tpLocal.Info.AgentID = AgentId;
  1052. tpLocal.Info.TeleportFlags = flags;
  1053. tpLocal.Info.LocationID = 2;
  1054. tpLocal.Info.LookAt = lookAt;
  1055. tpLocal.Info.Position = position;
  1056. // Hack to get this out immediately and skip throttles
  1057. OutPacket(tpLocal, ThrottleOutPacketType.Unknown);
  1058. }
  1059. public void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint newRegionEndPoint, uint locationID,
  1060. uint flags, string capsURL)
  1061. {
  1062. //TeleportFinishPacket teleport = (TeleportFinishPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFinish);
  1063. TeleportFinishPacket teleport = new TeleportFinishPacket();
  1064. teleport.Info.AgentID = AgentId;
  1065. teleport.Info.RegionHandle = regionHandle;
  1066. teleport.Info.SimAccess = simAccess;
  1067. teleport.Info.SeedCapability = Helpers.StringToField(capsURL);
  1068. IPAddress oIP = newRegionEndPoint.Address;
  1069. byte[] byteIP = oIP.GetAddressBytes();
  1070. uint ip = (uint)byteIP[3] << 24;
  1071. ip += (uint)byteIP[2] << 16;
  1072. ip += (uint)byteIP[1] << 8;
  1073. ip += (uint)byteIP[0];
  1074. teleport.Info.SimIP = ip;
  1075. teleport.Info.SimPort = (ushort)newRegionEndPoint.Port;
  1076. teleport.Info.LocationID = 4;
  1077. teleport.Info.TeleportFlags = 1 << 4;
  1078. // Hack to get this out immediately and skip throttles.
  1079. OutPacket(teleport, ThrottleOutPacketType.Unknown);
  1080. }
  1081. /// <summary>
  1082. ///
  1083. /// </summary>
  1084. public void SendTeleportFailed(string reason)
  1085. {
  1086. TeleportFailedPacket tpFailed = (TeleportFailedPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFailed);
  1087. tpFailed.Info.AgentID = AgentId;
  1088. tpFailed.Info.Reason = Helpers.StringToField(reason);
  1089. // Hack to get this out immediately and skip throttles
  1090. OutPacket(tpFailed, ThrottleOutPacketType.Unknown);
  1091. }
  1092. /// <summary>
  1093. ///
  1094. /// </summary>
  1095. public void SendTeleportLocationStart()
  1096. {
  1097. //TeleportStartPacket tpStart = (TeleportStartPacket)PacketPool.Instance.GetPacket(PacketType.TeleportStart);
  1098. TeleportStartPacket tpStart = new TeleportStartPacket();
  1099. tpStart.Info.TeleportFlags = 16; // Teleport via location
  1100. // Hack to get this out immediately and skip throttles
  1101. OutPacket(tpStart, ThrottleOutPacketType.Unknown);
  1102. }
  1103. public void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance)
  1104. {
  1105. MoneyBalanceReplyPacket money = (MoneyBalanceReplyPacket)PacketPool.Instance.GetPacket(PacketType.MoneyBalanceReply);
  1106. money.MoneyData.AgentID = AgentId;
  1107. money.MoneyData.TransactionID = transaction;
  1108. money.MoneyData.TransactionSuccess = success;
  1109. money.MoneyData.Description = description;
  1110. money.MoneyData.MoneyBalance = balance;
  1111. OutPacket(money, ThrottleOutPacketType.Task);
  1112. }
  1113. public void SendPayPrice(LLUUID objectID, int[] payPrice)
  1114. {
  1115. if (payPrice[0] == 0 &&
  1116. payPrice[1] == 0 &&
  1117. payPrice[2] == 0 &&
  1118. payPrice[3] == 0 &&
  1119. payPrice[4] == 0)
  1120. return;
  1121. PayPriceReplyPacket payPriceReply = (PayPriceReplyPacket)PacketPool.Instance.GetPacket(PacketType.PayPriceReply);
  1122. payPriceReply.ObjectData.ObjectID = objectID;
  1123. payPriceReply.ObjectData.DefaultPayPrice = payPrice[0];
  1124. payPriceReply.ButtonData=new PayPriceReplyPacket.ButtonDataBlock[4];
  1125. payPriceReply.ButtonData[0]=new PayPriceReplyPacket.ButtonDataBlock();
  1126. payPriceReply.ButtonData[0].PayButton = payPrice[1];
  1127. payPriceReply.ButtonData[1]=new PayPriceReplyPacket.ButtonDataBlock();
  1128. payPriceReply.ButtonData[1].PayButton = payPrice[2];
  1129. payPriceReply.ButtonData[2]=new PayPriceReplyPacket.ButtonDataBlock();
  1130. payPriceReply.ButtonData[2].PayButton = payPrice[3];
  1131. payPriceReply.ButtonData[3]=new PayPriceReplyPacket.ButtonDataBlock();
  1132. payPriceReply.ButtonData[3].PayButton = payPrice[4];
  1133. OutPacket(payPriceReply, ThrottleOutPacketType.Task);
  1134. }
  1135. public void SendStartPingCheck(byte seq)
  1136. {
  1137. StartPingCheckPacket pc = (StartPingCheckPacket)PacketPool.Instance.GetPacket(PacketType.StartPingCheck);
  1138. pc.PingID.PingID = seq;
  1139. pc.Header.Reliable = false;
  1140. OutPacket(pc, ThrottleOutPacketType.Unknown);
  1141. }
  1142. public void SendKillObject(ulong regionHandle, uint localID)
  1143. {
  1144. KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
  1145. // TODO: don't create new blocks if recycling an old packet
  1146. kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
  1147. kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
  1148. kill.ObjectData[0].ID = localID;
  1149. kill.Header.Reliable = false;
  1150. kill.Header.Zerocoded = true;
  1151. OutPacket(kill, ThrottleOutPacketType.Task);
  1152. }
  1153. /// <summary>
  1154. /// Send information about the items contained in a folder to the client.
  1155. ///
  1156. /// XXX This method needs some refactoring loving
  1157. /// </summary>
  1158. /// <param name="ownerID">The owner of the folder</param>
  1159. /// <param name="folderID">The id of the folder</param>
  1160. /// <param name="items">The items contained in the folder identified by folderID</param>
  1161. /// <param name="fetchFolders">Do we need to send folder information?</param>
  1162. /// <param name="fetchItems">Do we need to send item information?</param>
  1163. public void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items,
  1164. List<InventoryFolderBase> folders,
  1165. bool fetchFolders, bool fetchItems)
  1166. {
  1167. // An inventory descendents packet consists of a single agent section and an inventory details
  1168. // section for each inventory item. The size of each inventory item is approximately 550 bytes.
  1169. // In theory, UDP has a maximum packet size of 64k, so it should be possible to send descendent
  1170. // packets containing metadata for in excess of 100 items. But in practice, there may be other
  1171. // factors (e.g. firewalls) restraining the maximum UDP packet size. See,
  1172. //
  1173. // http://opensimulator.org/mantis/view.php?id=226
  1174. //
  1175. // for one example of this kind of thing. In fact, the Linden servers appear to only send about
  1176. // 6 to 7 items at a time, so let's stick with 6
  1177. int MAX_ITEMS_PER_PACKET = 6;
  1178. //Ckrinke This variable is not used, so comment out to remove the warning from the compiler (3-21-08)
  1179. //Ckrinke uint FULL_MASK_PERMISSIONS = 2147483647;
  1180. if (fetchItems)
  1181. {
  1182. InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1183. if (items.Count < MAX_ITEMS_PER_PACKET)
  1184. {
  1185. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count];
  1186. descend.AgentData.Descendents = items.Count;
  1187. }
  1188. else
  1189. {
  1190. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET];
  1191. descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
  1192. }
  1193. // Even if we aren't fetching the folders, we still need to include the folder count
  1194. // in the total number of descendents. Failure to do so will cause subtle bugs such
  1195. // as the failure of textures which haven't been expanded in inventory to show up
  1196. // in the texture prim edit selection panel.
  1197. if (!fetchFolders)
  1198. {
  1199. descend.AgentData.Descendents += folders.Count;
  1200. }
  1201. int count = 0;
  1202. int i = 0;
  1203. foreach (InventoryItemBase item in items)
  1204. {
  1205. descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock();
  1206. descend.ItemData[i].ItemID = item.ID;
  1207. descend.ItemData[i].AssetID = item.AssetID;
  1208. descend.ItemData[i].CreatorID = item.Creator;
  1209. descend.ItemData[i].BaseMask = item.BasePermissions;
  1210. descend.ItemData[i].Description = Helpers.StringToField(item.Description);
  1211. descend.ItemData[i].EveryoneMask = item.EveryOnePermissions;
  1212. descend.ItemData[i].OwnerMask = item.CurrentPermissions;
  1213. descend.ItemData[i].FolderID = item.Folder;
  1214. descend.ItemData[i].InvType = (sbyte)item.InvType;
  1215. descend.ItemData[i].Name = Helpers.StringToField(item.Name);
  1216. descend.ItemData[i].NextOwnerMask = item.NextPermissions;
  1217. descend.ItemData[i].OwnerID = item.Owner;
  1218. descend.ItemData[i].Type = (sbyte)item.AssetType;
  1219. //descend.ItemData[i].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
  1220. descend.ItemData[i].GroupID = item.GroupID;
  1221. descend.ItemData[i].GroupOwned = item.GroupOwned;
  1222. descend.ItemData[i].GroupMask = 0;
  1223. descend.ItemData[i].CreationDate = item.CreationDate;
  1224. descend.ItemData[i].SalePrice = item.SalePrice;
  1225. descend.ItemData[i].SaleType = item.SaleType;
  1226. descend.ItemData[i].Flags = item.Flags;
  1227. descend.ItemData[i].CRC =
  1228. Helpers.InventoryCRC(descend.ItemData[i].CreationDate, descend.ItemData[i].SaleType,
  1229. descend.ItemData[i].InvType, descend.ItemData[i].Type,
  1230. descend.ItemData[i].AssetID, descend.ItemData[i].GroupID,
  1231. descend.ItemData[i].SalePrice,
  1232. descend.ItemData[i].OwnerID, descend.ItemData[i].CreatorID,
  1233. descend.ItemData[i].ItemID, descend.ItemData[i].FolderID,
  1234. descend.ItemData[i].EveryoneMask,
  1235. descend.ItemData[i].Flags, descend.ItemData[i].OwnerMask,
  1236. descend.ItemData[i].GroupMask, item.CurrentPermissions);
  1237. i++;
  1238. count++;
  1239. if (i == MAX_ITEMS_PER_PACKET)
  1240. {
  1241. descend.Header.Zerocoded = true;
  1242. OutPacket(descend, ThrottleOutPacketType.Asset);
  1243. if ((items.Count - count) > 0)
  1244. {
  1245. descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1246. if ((items.Count - count) < MAX_ITEMS_PER_PACKET)
  1247. {
  1248. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count - count];
  1249. descend.AgentData.Descendents = items.Count - count;
  1250. }
  1251. else
  1252. {
  1253. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET];
  1254. descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
  1255. }
  1256. i = 0;
  1257. }
  1258. }
  1259. }
  1260. if (i < MAX_ITEMS_PER_PACKET)
  1261. {
  1262. OutPacket(descend, ThrottleOutPacketType.Asset);
  1263. }
  1264. }
  1265. //send subfolders
  1266. if (fetchFolders)
  1267. {
  1268. InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1269. if (folders.Count < MAX_ITEMS_PER_PACKET)
  1270. {
  1271. descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders.Count];
  1272. descend.AgentData.Descendents = folders.Count;
  1273. }
  1274. else
  1275. {
  1276. descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET];
  1277. descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
  1278. }
  1279. // Not sure if this scenario ever actually occurs, but nonetheless we include the items
  1280. // count even if we're not sending item data for the same reasons as above.
  1281. if (!fetchItems)
  1282. {
  1283. descend.AgentData.Descendents += items.Count;
  1284. }
  1285. int i = 0;
  1286. int count = 0;
  1287. foreach (InventoryFolderBase folder in folders)
  1288. {
  1289. descend.FolderData[i] = new InventoryDescendentsPacket.FolderDataBlock();
  1290. descend.FolderData[i].FolderID = folder.ID;
  1291. descend.FolderData[i].Name = Helpers.StringToField(folder.Name);
  1292. descend.FolderData[i].ParentID = folder.ParentID;
  1293. descend.FolderData[i].Type = (sbyte) folder.Type;
  1294. i++;
  1295. count++;
  1296. if (i == MAX_ITEMS_PER_PACKET)
  1297. {
  1298. OutPacket(descend, ThrottleOutPacketType.Asset);
  1299. if ((folders.Count - count) > 0)
  1300. {
  1301. descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1302. if ((folders.Count - count) < MAX_ITEMS_PER_PACKET)
  1303. {
  1304. descend.FolderData =
  1305. new InventoryDescendentsPacket.FolderDataBlock[folders.Count - count];
  1306. descend.AgentData.Descendents = folders.Count - count;
  1307. }
  1308. else
  1309. {
  1310. descend.FolderData =
  1311. new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET];
  1312. descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
  1313. }
  1314. i = 0;
  1315. }
  1316. }
  1317. }
  1318. if (i < MAX_ITEMS_PER_PACKET)
  1319. {
  1320. OutPacket(descend, ThrottleOutPacketType.Asset);
  1321. }
  1322. }
  1323. }
  1324. private InventoryDescendentsPacket CreateInventoryDescendentsPacket(LLUUID ownerID, LLUUID folderID)
  1325. {
  1326. InventoryDescendentsPacket descend = (InventoryDescendentsPacket)PacketPool.Instance.GetPacket(PacketType.InventoryDescendents);
  1327. descend.Header.Zerocoded = true;
  1328. descend.AgentData.AgentID = AgentId;
  1329. descend.AgentData.OwnerID = ownerID;
  1330. descend.AgentData.FolderID = folderID;
  1331. descend.AgentData.Version = 1;
  1332. return descend;
  1333. }
  1334. public void SendInventoryItemDetails(LLUUID ownerID, InventoryItemBase item)
  1335. {
  1336. uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
  1337. FetchInventoryReplyPacket inventoryReply = (FetchInventoryReplyPacket)PacketPool.Instance.GetPacket(PacketType.FetchInventoryReply);
  1338. // TODO: don't create new blocks if recycling an old packet
  1339. inventoryReply.AgentData.AgentID = AgentId;
  1340. inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1];
  1341. inventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock();
  1342. inventoryReply.InventoryData[0].ItemID = item.ID;
  1343. inventoryReply.InventoryData[0].AssetID = item.AssetID;
  1344. inventoryReply.InventoryData[0].CreatorID = item.Creator;
  1345. inventoryReply.InventoryData[0].BaseMask = item.BasePermissions;
  1346. inventoryReply.InventoryData[0].CreationDate =
  1347. (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  1348. inventoryReply.InventoryData[0].Description = Helpers.StringToField(item.Description);
  1349. inventoryReply.InventoryData[0].EveryoneMask = item.EveryOnePermissions;
  1350. inventoryReply.InventoryData[0].FolderID = item.Folder;
  1351. inventoryReply.InventoryData[0].InvType = (sbyte)item.InvType;
  1352. inventoryReply.InventoryData[0].Name = Helpers.StringToField(item.Name);
  1353. inventoryReply.InventoryData[0].NextOwnerMask = item.NextPermissions;
  1354. inventoryReply.InventoryData[0].OwnerID = item.Owner;
  1355. inventoryReply.InventoryData[0].OwnerMask = item.CurrentPermissions;
  1356. inventoryReply.InventoryData[0].Type = (sbyte)item.AssetType;
  1357. //inventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
  1358. inventoryReply.InventoryData[0].GroupID = item.GroupID;
  1359. inventoryReply.InventoryData[0].GroupOwned = item.GroupOwned;
  1360. inventoryReply.InventoryData[0].GroupMask = 0;
  1361. inventoryReply.InventoryData[0].Flags = item.Flags;
  1362. inventoryReply.InventoryData[0].SalePrice = item.SalePrice;
  1363. inventoryReply.InventoryData[0].SaleType = item.SaleType;
  1364. inventoryReply.InventoryData[0].CRC =
  1365. Helpers.InventoryCRC(1000, 0, inventoryReply.InventoryData[0].InvType,
  1366. inventoryReply.InventoryData[0].Type, inventoryReply.InventoryData[0].AssetID,
  1367. inventoryReply.InventoryData[0].GroupID, 100,
  1368. inventoryReply.InventoryData[0].OwnerID, inventoryReply.InventoryData[0].CreatorID,
  1369. inventoryReply.InventoryData[0].ItemID, inventoryReply.InventoryData[0].FolderID,
  1370. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  1371. FULL_MASK_PERMISSIONS);
  1372. inventoryReply.Header.Zerocoded = true;
  1373. OutPacket(inventoryReply, ThrottleOutPacketType.Asset);
  1374. }
  1375. /// <see>IClientAPI.SendBulkUpdateInventory(InventoryItemBase)</see>
  1376. public void SendBulkUpdateInventory(InventoryItemBase item)
  1377. {
  1378. uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
  1379. BulkUpdateInventoryPacket bulkUpdate
  1380. = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
  1381. bulkUpdate.AgentData.AgentID = AgentId;
  1382. bulkUpdate.AgentData.TransactionID = LLUUID.Random();
  1383. bulkUpdate.FolderData = new BulkUpdateInventoryPacket.FolderDataBlock[1];
  1384. bulkUpdate.FolderData[0] = new BulkUpdateInventoryPacket.FolderDataBlock();
  1385. bulkUpdate.FolderData[0].FolderID = LLUUID.Zero;
  1386. bulkUpdate.FolderData[0].ParentID = LLUUID.Zero;
  1387. bulkUpdate.FolderData[0].Type = -1;
  1388. bulkUpdate.FolderData[0].Name = new byte[0];
  1389. bulkUpdate.ItemData = new BulkUpdateInventoryPacket.ItemDataBlock[1];
  1390. bulkUpdate.ItemData[0] = new BulkUpdateInventoryPacket.ItemDataBlock();
  1391. bulkUpdate.ItemData[0].ItemID = item.ID;
  1392. bulkUpdate.ItemData[0].AssetID = item.AssetID;
  1393. bulkUpdate.ItemData[0].CreatorID = item.Creator;
  1394. bulkUpdate.ItemData[0].BaseMask = item.BasePermissions;
  1395. bulkUpdate.ItemData[0].CreationDate = 1000;
  1396. bulkUpdate.ItemData[0].Description = Helpers.StringToField(item.Description);
  1397. bulkUpdate.ItemData[0].EveryoneMask = item.EveryOnePermissions;
  1398. bulkUpdate.ItemData[0].FolderID = item.Folder;
  1399. bulkUpdate.ItemData[0].InvType = (sbyte)item.InvType;
  1400. bulkUpdate.ItemData[0].Name = Helpers.StringToField(item.Name);
  1401. bulkUpdate.ItemData[0].NextOwnerMask = item.NextPermissions;
  1402. bulkUpdate.ItemData[0].OwnerID = item.Owner;
  1403. bulkUpdate.ItemData[0].OwnerMask = item.CurrentPermissions;
  1404. bulkUpdate.ItemData[0].Type = (sbyte)item.AssetType;
  1405. //bulkUpdate.ItemData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
  1406. bulkUpdate.ItemData[0].GroupID = item.GroupID;
  1407. bulkUpdate.ItemData[0].GroupOwned = item.GroupOwned;
  1408. bulkUpdate.ItemData[0].GroupMask = 0;
  1409. bulkUpdate.ItemData[0].Flags = item.Flags;
  1410. bulkUpdate.ItemData[0].SalePrice = item.SalePrice;
  1411. bulkUpdate.ItemData[0].SaleType = item.SaleType;
  1412. bulkUpdate.ItemData[0].CRC =
  1413. Helpers.InventoryCRC(1000, 0, bulkUpdate.ItemData[0].InvType,
  1414. bulkUpdate.ItemData[0].Type, bulkUpdate.ItemData[0].AssetID,
  1415. bulkUpdate.ItemData[0].GroupID, 100,
  1416. bulkUpdate.ItemData[0].OwnerID, bulkUpdate.ItemData[0].CreatorID,
  1417. bulkUpdate.ItemData[0].ItemID, bulkUpdate.ItemData[0].FolderID,
  1418. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  1419. FULL_MASK_PERMISSIONS);
  1420. bulkUpdate.Header.Zerocoded = true;
  1421. OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
  1422. }
  1423. /// <see>IClientAPI.SendInventoryItemCreateUpdate(InventoryItemBase)</see>
  1424. public void SendInventoryItemCreateUpdate(InventoryItemBase Item)
  1425. {
  1426. uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
  1427. UpdateCreateInventoryItemPacket InventoryReply
  1428. = (UpdateCreateInventoryItemPacket)PacketPool.Instance.GetPacket(
  1429. PacketType.UpdateCreateInventoryItem);
  1430. // TODO: don't create new blocks if recycling an old packet
  1431. InventoryReply.AgentData.AgentID = AgentId;
  1432. InventoryReply.AgentData.SimApproved = true;
  1433. InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
  1434. InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
  1435. InventoryReply.InventoryData[0].ItemID = Item.ID;
  1436. InventoryReply.InventoryData[0].AssetID = Item.AssetID;
  1437. InventoryReply.InventoryData[0].CreatorID = Item.Creator;
  1438. InventoryReply.InventoryData[0].BaseMask = Item.BasePermissions;
  1439. InventoryReply.InventoryData[0].Description = Helpers.StringToField(Item.Description);
  1440. InventoryReply.InventoryData[0].EveryoneMask = Item.EveryOnePermissions;
  1441. InventoryReply.InventoryData[0].FolderID = Item.Folder;
  1442. InventoryReply.InventoryData[0].InvType = (sbyte)Item.InvType;
  1443. InventoryReply.InventoryData[0].Name = Helpers.StringToField(Item.Name);
  1444. InventoryReply.InventoryData[0].NextOwnerMask = Item.NextPermissions;
  1445. InventoryReply.InventoryData[0].OwnerID = Item.Owner;
  1446. InventoryReply.InventoryData[0].OwnerMask = Item.CurrentPermissions;
  1447. InventoryReply.InventoryData[0].Type = (sbyte)Item.AssetType;
  1448. //InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
  1449. InventoryReply.InventoryData[0].GroupID = Item.GroupID;
  1450. InventoryReply.InventoryData[0].GroupOwned = Item.GroupOwned;
  1451. InventoryReply.InventoryData[0].GroupMask = 0;
  1452. InventoryReply.InventoryData[0].Flags = Item.Flags;
  1453. InventoryReply.InventoryData[0].SalePrice = Item.SalePrice;
  1454. InventoryReply.InventoryData[0].SaleType = Item.SaleType;
  1455. InventoryReply.InventoryData[0].CRC =
  1456. Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType,
  1457. InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID,
  1458. InventoryReply.InventoryData[0].GroupID, 100,
  1459. InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID,
  1460. InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID,
  1461. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  1462. FULL_MASK_PERMISSIONS);
  1463. InventoryReply.Header.Zerocoded = true;
  1464. OutPacket(InventoryReply, ThrottleOutPacketType.Asset);
  1465. }
  1466. public void SendRemoveInventoryItem(LLUUID itemID)
  1467. {
  1468. RemoveInventoryItemPacket remove = (RemoveInventoryItemPacket)PacketPool.Instance.GetPacket(PacketType.RemoveInventoryItem);
  1469. // TODO: don't create new blocks if recycling an old packet
  1470. remove.AgentData.AgentID = AgentId;
  1471. remove.AgentData.SessionID = m_sessionId;
  1472. remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1];
  1473. remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock();
  1474. remove.InventoryData[0].ItemID = itemID;
  1475. remove.Header.Zerocoded = true;
  1476. OutPacket(remove, ThrottleOutPacketType.Asset);
  1477. }
  1478. public void SendTakeControls(int controls, bool passToAgent, bool TakeControls)
  1479. {
  1480. ScriptControlChangePacket scriptcontrol = (ScriptControlChangePacket)PacketPool.Instance.GetPacket(PacketType.ScriptControlChange);
  1481. ScriptControlChangePacket.DataBlock[] data = new ScriptControlChangePacket.DataBlock[1];
  1482. ScriptControlChangePacket.DataBlock ddata = new ScriptControlChangePacket.DataBlock();
  1483. ddata.Controls = (uint)controls;
  1484. ddata.PassToAgent = passToAgent;
  1485. ddata.TakeControls = TakeControls;
  1486. data[0] = ddata;
  1487. scriptcontrol.Data = data;
  1488. OutPacket(scriptcontrol, ThrottleOutPacketType.Task);
  1489. }
  1490. public void SendTaskInventory(LLUUID taskID, short serial, byte[] fileName)
  1491. {
  1492. ReplyTaskInventoryPacket replytask = (ReplyTaskInventoryPacket)PacketPool.Instance.GetPacket(PacketType.ReplyTaskInventory);
  1493. replytask.InventoryData.TaskID = taskID;
  1494. replytask.InventoryData.Serial = serial;
  1495. replytask.InventoryData.Filename = fileName;
  1496. OutPacket(replytask, ThrottleOutPacketType.Asset);
  1497. }
  1498. public void SendXferPacket(ulong xferID, uint packet, byte[] data)
  1499. {
  1500. SendXferPacketPacket sendXfer = (SendXferPacketPacket)PacketPool.Instance.GetPacket(PacketType.SendXferPacket);
  1501. sendXfer.XferID.ID = xferID;
  1502. sendXfer.XferID.Packet = packet;
  1503. sendXfer.DataPacket.Data = data;
  1504. OutPacket(sendXfer, ThrottleOutPacketType.Task);
  1505. }
  1506. public void SendEconomyData(float EnergyEfficiency, int ObjectCapacity, int ObjectCount, int PriceEnergyUnit,
  1507. int PriceGroupCreate, int PriceObjectClaim, float PriceObjectRent, float PriceObjectScaleFactor,
  1508. int PriceParcelClaim, float PriceParcelClaimFactor, int PriceParcelRent, int PricePublicObjectDecay,
  1509. int PricePublicObjectDelete, int PriceRentLight, int PriceUpload, int TeleportMinPrice, float TeleportPriceExponent)
  1510. {
  1511. EconomyDataPacket economyData = (EconomyDataPacket)PacketPool.Instance.GetPacket(PacketType.EconomyData);
  1512. economyData.Info.EnergyEfficiency = EnergyEfficiency;
  1513. economyData.Info.ObjectCapacity = ObjectCapacity;
  1514. economyData.Info.ObjectCount = ObjectCount;
  1515. economyData.Info.PriceEnergyUnit = PriceEnergyUnit;
  1516. economyData.Info.PriceGroupCreate = PriceGroupCreate;
  1517. economyData.Info.PriceObjectClaim = PriceObjectClaim;
  1518. economyData.Info.PriceObjectRent = PriceObjectRent;
  1519. economyData.Info.PriceObjectScaleFactor = PriceObjectScaleFactor;
  1520. economyData.Info.PriceParcelClaim = PriceParcelClaim;
  1521. economyData.Info.PriceParcelClaimFactor = PriceParcelClaimFactor;
  1522. economyData.Info.PriceParcelRent = PriceParcelRent;
  1523. economyData.Info.PricePublicObjectDecay = PricePublicObjectDecay;
  1524. economyData.Info.PricePublicObjectDelete = PricePublicObjectDelete;
  1525. economyData.Info.PriceRentLight = PriceRentLight;
  1526. economyData.Info.PriceUpload = PriceUpload;
  1527. economyData.Info.TeleportMinPrice = TeleportMinPrice;
  1528. economyData.Info.TeleportPriceExponent = TeleportPriceExponent;
  1529. economyData.Header.Reliable = true;
  1530. OutPacket(economyData, ThrottleOutPacketType.Unknown);
  1531. }
  1532. public void SendAvatarPickerReply(AvatarPickerReplyAgentDataArgs AgentData, List<AvatarPickerReplyDataArgs> Data)
  1533. {
  1534. //construct the AvatarPickerReply packet.
  1535. AvatarPickerReplyPacket replyPacket = new AvatarPickerReplyPacket();
  1536. replyPacket.AgentData.AgentID = AgentData.AgentID;
  1537. replyPacket.AgentData.QueryID = AgentData.QueryID;
  1538. //int i = 0;
  1539. List<AvatarPickerReplyPacket.DataBlock> data_block = new List<AvatarPickerReplyPacket.DataBlock>();
  1540. foreach (AvatarPickerReplyDataArgs arg in Data)
  1541. {
  1542. AvatarPickerReplyPacket.DataBlock db = new AvatarPickerReplyPacket.DataBlock();
  1543. db.AvatarID = arg.AvatarID;
  1544. db.FirstName = arg.FirstName;
  1545. db.LastName = arg.LastName;
  1546. data_block.Add(db);
  1547. }
  1548. replyPacket.Data = data_block.ToArray();
  1549. OutPacket(replyPacket, ThrottleOutPacketType.Task);
  1550. }
  1551. public void SendAgentDataUpdate(LLUUID agentid, LLUUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname, string grouptitle)
  1552. {
  1553. m_activeGroupID = activegroupid;
  1554. m_activeGroupName = groupname;
  1555. m_activeGroupPowers = grouppowers;
  1556. AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate);
  1557. sendAgentDataUpdate.AgentData.ActiveGroupID = activegroupid;
  1558. sendAgentDataUpdate.AgentData.AgentID = agentid;
  1559. sendAgentDataUpdate.AgentData.FirstName = Helpers.StringToField(firstname);
  1560. sendAgentDataUpdate.AgentData.GroupName = Helpers.StringToField(groupname);
  1561. sendAgentDataUpdate.AgentData.GroupPowers = grouppowers;
  1562. sendAgentDataUpdate.AgentData.GroupTitle = Helpers.StringToField(grouptitle);
  1563. sendAgentDataUpdate.AgentData.LastName = Helpers.StringToField(lastname);
  1564. OutPacket(sendAgentDataUpdate, ThrottleOutPacketType.Task);
  1565. }
  1566. /// <summary>
  1567. /// Send an alert message to the client. On the Linden client (tested 1.19.1.4), this pops up a brief duration
  1568. /// blue information box in the bottom right hand corner.
  1569. /// </summary>
  1570. /// <param name="message"></param>
  1571. public void SendAlertMessage(string message)
  1572. {
  1573. AlertMessagePacket alertPack = (AlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AlertMessage);
  1574. alertPack.AlertData.Message = Helpers.StringToField(message);
  1575. OutPacket(alertPack, ThrottleOutPacketType.Task);
  1576. }
  1577. /// <summary>
  1578. /// Send an agent alert message to the client.
  1579. /// </summary>
  1580. /// <param name="message"></param>
  1581. /// <param name="modal">On the linden client, if this true then it displays a one button text box placed in the
  1582. /// middle of the window. If false, the message is displayed in a brief duration blue information box (as for
  1583. /// the AlertMessage packet).</param>
  1584. public void SendAgentAlertMessage(string message, bool modal)
  1585. {
  1586. AgentAlertMessagePacket alertPack = (AgentAlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AgentAlertMessage);
  1587. alertPack.AgentData.AgentID = AgentId;
  1588. alertPack.AlertData.Message = Helpers.StringToField(message);
  1589. alertPack.AlertData.Modal = modal;
  1590. OutPacket(alertPack, ThrottleOutPacketType.Task);
  1591. }
  1592. public void SendLoadURL(string objectname, LLUUID objectID, LLUUID ownerID, bool groupOwned, string message,
  1593. string url)
  1594. {
  1595. LoadURLPacket loadURL = (LoadURLPacket)PacketPool.Instance.GetPacket(PacketType.LoadURL);
  1596. loadURL.Data.ObjectName = Helpers.StringToField(objectname);
  1597. loadURL.Data.ObjectID = objectID;
  1598. loadURL.Data.OwnerID = ownerID;
  1599. loadURL.Data.OwnerIsGroup = groupOwned;
  1600. loadURL.Data.Message = Helpers.StringToField(message);
  1601. loadURL.Data.URL = Helpers.StringToField(url);
  1602. OutPacket(loadURL, ThrottleOutPacketType.Task);
  1603. }
  1604. public void SendDialog(string objectname, LLUUID objectID, LLUUID ownerID, string msg, LLUUID textureID, int ch, string[] buttonlabels)
  1605. {
  1606. ScriptDialogPacket dialog = (ScriptDialogPacket)PacketPool.Instance.GetPacket(PacketType.ScriptDialog);
  1607. dialog.Data.ObjectID = objectID;
  1608. dialog.Data.ObjectName = Helpers.StringToField(objectname);
  1609. dialog.Data.FirstName = Helpers.StringToField(this.FirstName);
  1610. dialog.Data.LastName = Helpers.StringToField(this.LastName);
  1611. dialog.Data.Message = Helpers.StringToField(msg);
  1612. dialog.Data.ImageID = textureID;
  1613. dialog.Data.ChatChannel = ch;
  1614. ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[buttonlabels.Length];
  1615. for (int i = 0; i < buttonlabels.Length; i++)
  1616. {
  1617. buttons[i] = new ScriptDialogPacket.ButtonsBlock();
  1618. buttons[i].ButtonLabel = Helpers.StringToField(buttonlabels[i]);
  1619. }
  1620. dialog.Buttons = buttons;
  1621. OutPacket(dialog, ThrottleOutPacketType.Task);
  1622. }
  1623. public void SendPreLoadSound(LLUUID objectID, LLUUID ownerID, LLUUID soundID)
  1624. {
  1625. PreloadSoundPacket preSound = (PreloadSoundPacket)PacketPool.Instance.GetPacket(PacketType.PreloadSound);
  1626. // TODO: don't create new blocks if recycling an old packet
  1627. preSound.DataBlock = new PreloadSoundPacket.DataBlockBlock[1];
  1628. preSound.DataBlock[0] = new PreloadSoundPacket.DataBlockBlock();
  1629. preSound.DataBlock[0].ObjectID = objectID;
  1630. preSound.DataBlock[0].OwnerID = ownerID;
  1631. preSound.DataBlock[0].SoundID = soundID;
  1632. preSound.Header.Zerocoded = true;
  1633. OutPacket(preSound, ThrottleOutPacketType.Task);
  1634. }
  1635. public void SendPlayAttachedSound(LLUUID soundID, LLUUID objectID, LLUUID ownerID, float gain, byte flags)
  1636. {
  1637. AttachedSoundPacket sound = (AttachedSoundPacket)PacketPool.Instance.GetPacket(PacketType.AttachedSound);
  1638. sound.DataBlock.SoundID = soundID;
  1639. sound.DataBlock.ObjectID = objectID;
  1640. sound.DataBlock.OwnerID = ownerID;
  1641. sound.DataBlock.Gain = gain;
  1642. sound.DataBlock.Flags = flags;
  1643. OutPacket(sound, ThrottleOutPacketType.Task);
  1644. }
  1645. public void SendTriggeredSound(LLUUID soundID, LLUUID ownerID, LLUUID objectID, LLUUID parentID, ulong handle, LLVector3 position, float gain)
  1646. {
  1647. SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger);
  1648. sound.SoundData.SoundID = soundID;
  1649. sound.SoundData.OwnerID = ownerID;
  1650. sound.SoundData.ObjectID = objectID;
  1651. sound.SoundData.ParentID = parentID;
  1652. sound.SoundData.Handle = handle;
  1653. sound.SoundData.Position = position;
  1654. sound.SoundData.Gain = gain;
  1655. OutPacket(sound, ThrottleOutPacketType.Task);
  1656. }
  1657. public void SendAttachedSoundGainChange(LLUUID objectID, float gain)
  1658. {
  1659. AttachedSoundGainChangePacket sound = (AttachedSoundGainChangePacket)PacketPool.Instance.GetPacket(PacketType.AttachedSoundGainChange);
  1660. sound.DataBlock.ObjectID = objectID;
  1661. sound.DataBlock.Gain = gain;
  1662. OutPacket(sound, ThrottleOutPacketType.Task);
  1663. }
  1664. public void SendSunPos(LLVector3 Position, LLVector3 Velocity, ulong CurrentTime, uint SecondsPerSunCycle, uint SecondsPerYear, float OrbitalPosition)
  1665. {
  1666. SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
  1667. viewertime.TimeInfo.SunDirection = Position;
  1668. viewertime.TimeInfo.SunAngVelocity = Velocity;
  1669. viewertime.TimeInfo.UsecSinceStart = CurrentTime;
  1670. viewertime.TimeInfo.SecPerDay = SecondsPerSunCycle;
  1671. viewertime.TimeInfo.SecPerYear = SecondsPerYear;
  1672. viewertime.TimeInfo.SunPhase = OrbitalPosition;
  1673. viewertime.Header.Reliable = false;
  1674. viewertime.Header.Zerocoded = true;
  1675. OutPacket(viewertime, ThrottleOutPacketType.Task);
  1676. }
  1677. // Currently Deprecated
  1678. public void SendViewerTime(int phase)
  1679. {
  1680. /*
  1681. Console.WriteLine("SunPhase: {0}", phase);
  1682. SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
  1683. //viewertime.TimeInfo.SecPerDay = 86400;
  1684. //viewertime.TimeInfo.SecPerYear = 31536000;
  1685. viewertime.TimeInfo.SecPerDay = 1000;
  1686. viewertime.TimeInfo.SecPerYear = 365000;
  1687. viewertime.TimeInfo.SunPhase = 1;
  1688. int sunPhase = (phase + 2) / 2;
  1689. if ((sunPhase < 6) || (sunPhase > 36))
  1690. {
  1691. viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f);
  1692. Console.WriteLine("sending night");
  1693. }
  1694. else
  1695. {
  1696. if (sunPhase < 12)
  1697. {
  1698. sunPhase = 12;
  1699. }
  1700. sunPhase = sunPhase - 12;
  1701. float yValue = 0.1f * (sunPhase);
  1702. Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
  1703. if (yValue > 1.2f)
  1704. {
  1705. yValue = yValue - 1.2f;
  1706. }
  1707. yValue = Util.Clip(yValue, 0, 1);
  1708. if (sunPhase < 14)
  1709. {
  1710. yValue = 1 - yValue;
  1711. }
  1712. if (sunPhase < 12)
  1713. {
  1714. yValue *= -1;
  1715. }
  1716. viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f);
  1717. Console.WriteLine("sending sun update " + yValue);
  1718. }
  1719. viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f);
  1720. viewertime.TimeInfo.UsecSinceStart = (ulong)Util.UnixTimeSinceEpoch();
  1721. viewertime.Header.Reliable = false;
  1722. OutPacket(viewertime, ThrottleOutPacketType.Task);
  1723. */
  1724. }
  1725. public void SendAvatarProperties(LLUUID avatarID, string aboutText, string bornOn, string charterMember,
  1726. string flAbout, uint flags, LLUUID flImageID, LLUUID imageID, string profileURL,
  1727. LLUUID partnerID)
  1728. {
  1729. AvatarPropertiesReplyPacket avatarReply = (AvatarPropertiesReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPropertiesReply);
  1730. avatarReply.AgentData.AgentID = AgentId;
  1731. avatarReply.AgentData.AvatarID = avatarID;
  1732. if (aboutText != null)
  1733. avatarReply.PropertiesData.AboutText = Helpers.StringToField(aboutText);
  1734. else
  1735. avatarReply.PropertiesData.AboutText = Helpers.StringToField("");
  1736. avatarReply.PropertiesData.BornOn = Helpers.StringToField(bornOn);
  1737. avatarReply.PropertiesData.CharterMember = Helpers.StringToField(charterMember);
  1738. if (flAbout != null)
  1739. avatarReply.PropertiesData.FLAboutText = Helpers.StringToField(flAbout);
  1740. else
  1741. avatarReply.PropertiesData.FLAboutText = Helpers.StringToField("");
  1742. avatarReply.PropertiesData.Flags = 0;
  1743. avatarReply.PropertiesData.FLImageID = flImageID;
  1744. avatarReply.PropertiesData.ImageID = imageID;
  1745. avatarReply.PropertiesData.ProfileURL = Helpers.StringToField(profileURL);
  1746. avatarReply.PropertiesData.PartnerID = partnerID;
  1747. OutPacket(avatarReply, ThrottleOutPacketType.Task);
  1748. }
  1749. #endregion
  1750. #region Appearance/ Wearables Methods
  1751. /// <summary>
  1752. ///
  1753. /// </summary>
  1754. /// <param name="wearables"></param>
  1755. public void SendWearables(AvatarWearable[] wearables, int serial)
  1756. {
  1757. AgentWearablesUpdatePacket aw = (AgentWearablesUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentWearablesUpdate);
  1758. aw.AgentData.AgentID = AgentId;
  1759. aw.AgentData.SerialNum = (uint)serial;
  1760. aw.AgentData.SessionID = m_sessionId;
  1761. // TODO: don't create new blocks if recycling an old packet
  1762. aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
  1763. AgentWearablesUpdatePacket.WearableDataBlock awb;
  1764. for (int i = 0; i < wearables.Length; i++)
  1765. {
  1766. awb = new AgentWearablesUpdatePacket.WearableDataBlock();
  1767. awb.WearableType = (byte)i;
  1768. awb.AssetID = wearables[i].AssetID;
  1769. awb.ItemID = wearables[i].ItemID;
  1770. aw.WearableData[i] = awb;
  1771. }
  1772. OutPacket(aw, ThrottleOutPacketType.Task);
  1773. }
  1774. /// <summary>
  1775. ///
  1776. /// </summary>
  1777. /// <param name="agentID"></param>
  1778. /// <param name="visualParams"></param>
  1779. /// <param name="textureEntry"></param>
  1780. public void SendAppearance(LLUUID agentID, byte[] visualParams, byte[] textureEntry)
  1781. {
  1782. AvatarAppearancePacket avp = (AvatarAppearancePacket)PacketPool.Instance.GetPacket(PacketType.AvatarAppearance);
  1783. // TODO: don't create new blocks if recycling an old packet
  1784. avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
  1785. avp.ObjectData.TextureEntry = textureEntry;
  1786. AvatarAppearancePacket.VisualParamBlock avblock = null;
  1787. for (int i = 0; i < visualParams.Length; i++)
  1788. {
  1789. avblock = new AvatarAppearancePacket.VisualParamBlock();
  1790. avblock.ParamValue = visualParams[i];
  1791. avp.VisualParam[i] = avblock;
  1792. }
  1793. avp.Sender.IsTrial = false;
  1794. avp.Sender.ID = agentID;
  1795. OutPacket(avp, ThrottleOutPacketType.Task);
  1796. }
  1797. public void SendAnimations(LLUUID[] animations, int[] seqs, LLUUID sourceAgentId)
  1798. {
  1799. AvatarAnimationPacket ani = (AvatarAnimationPacket)PacketPool.Instance.GetPacket(PacketType.AvatarAnimation);
  1800. // TODO: don't create new blocks if recycling an old packet
  1801. ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1];
  1802. ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock();
  1803. ani.AnimationSourceList[0].ObjectID = sourceAgentId;
  1804. ani.Sender = new AvatarAnimationPacket.SenderBlock();
  1805. ani.Sender.ID = sourceAgentId;
  1806. ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[animations.Length];
  1807. for (int i = 0; i < animations.Length; ++i)
  1808. {
  1809. ani.AnimationList[i] = new AvatarAnimationPacket.AnimationListBlock();
  1810. ani.AnimationList[i].AnimID = animations[i];
  1811. ani.AnimationList[i].AnimSequenceID = seqs[i];
  1812. }
  1813. ani.Header.Reliable = false;
  1814. OutPacket(ani, ThrottleOutPacketType.Task);
  1815. }
  1816. #endregion
  1817. #region Avatar Packet/data sending Methods
  1818. /// <summary>
  1819. /// send a objectupdate packet with information about the clients avatar
  1820. /// </summary>
  1821. /// <param name="regionInfo"></param>
  1822. /// <param name="firstName"></param>
  1823. /// <param name="lastName"></param>
  1824. /// <param name="avatarID"></param>
  1825. /// <param name="avatarLocalID"></param>
  1826. /// <param name="Pos"></param>
  1827. public void SendAvatarData(ulong regionHandle, string firstName, string lastName, LLUUID avatarID,
  1828. uint avatarLocalID, LLVector3 Pos, byte[] textureEntry, uint parentID)
  1829. {
  1830. ObjectUpdatePacket objupdate = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
  1831. // TODO: don't create new blocks if recycling an old packet
  1832. objupdate.RegionData.RegionHandle = regionHandle;
  1833. objupdate.RegionData.TimeDilation = ushort.MaxValue;
  1834. objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
  1835. objupdate.ObjectData[0] = CreateDefaultAvatarPacket(textureEntry);
  1836. //give this avatar object a local id and assign the user a name
  1837. objupdate.ObjectData[0].ID = avatarLocalID;
  1838. objupdate.ObjectData[0].FullID = avatarID;
  1839. objupdate.ObjectData[0].ParentID = parentID;
  1840. objupdate.ObjectData[0].NameValue =
  1841. Helpers.StringToField("FirstName STRING RW SV " + firstName + "\nLastName STRING RW SV " + lastName);
  1842. LLVector3 pos2 = new LLVector3((float)Pos.X, (float)Pos.Y, (float)Pos.Z);
  1843. byte[] pb = pos2.GetBytes();
  1844. Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
  1845. objupdate.Header.Zerocoded = true;
  1846. OutPacket(objupdate, ThrottleOutPacketType.Task);
  1847. }
  1848. /// <summary>
  1849. ///
  1850. /// </summary>
  1851. /// <param name="regionHandle"></param>
  1852. /// <param name="timeDilation"></param>
  1853. /// <param name="localID"></param>
  1854. /// <param name="position"></param>
  1855. /// <param name="velocity"></param>
  1856. public void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
  1857. LLVector3 velocity, LLQuaternion rotation)
  1858. {
  1859. if (rotation.X == rotation.Y && rotation.Y == rotation.Z && rotation.Z == rotation.W && rotation.W == 0)
  1860. rotation = LLQuaternion.Identity;
  1861. ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock =
  1862. CreateAvatarImprovedBlock(localID, position, velocity, rotation);
  1863. ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
  1864. // TODO: don't create new blocks if recycling an old packet
  1865. terse.RegionData.RegionHandle = regionHandle;
  1866. terse.RegionData.TimeDilation = timeDilation;
  1867. terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
  1868. terse.ObjectData[0] = terseBlock;
  1869. terse.Header.Reliable = false;
  1870. terse.Header.Zerocoded = true;
  1871. OutPacket(terse, ThrottleOutPacketType.Task);
  1872. }
  1873. public void SendCoarseLocationUpdate(List<LLVector3> CoarseLocations)
  1874. {
  1875. CoarseLocationUpdatePacket loc = (CoarseLocationUpdatePacket)PacketPool.Instance.GetPacket(PacketType.CoarseLocationUpdate);
  1876. // TODO: don't create new blocks if recycling an old packet
  1877. int total = CoarseLocations.Count;
  1878. CoarseLocationUpdatePacket.IndexBlock ib =
  1879. new CoarseLocationUpdatePacket.IndexBlock();
  1880. loc.Location = new CoarseLocationUpdatePacket.LocationBlock[total];
  1881. for (int i = 0; i < total; i++)
  1882. {
  1883. CoarseLocationUpdatePacket.LocationBlock lb =
  1884. new CoarseLocationUpdatePacket.LocationBlock();
  1885. lb.X = (byte)CoarseLocations[i].X;
  1886. lb.Y = (byte)CoarseLocations[i].Y;
  1887. lb.Z = (byte)(CoarseLocations[i].Z / 4);
  1888. loc.Location[i] = lb;
  1889. }
  1890. ib.You = -1;
  1891. ib.Prey = -1;
  1892. loc.Index = ib;
  1893. loc.Header.Reliable = false;
  1894. loc.Header.Zerocoded = true;
  1895. OutPacket(loc, ThrottleOutPacketType.Task);
  1896. }
  1897. #endregion
  1898. #region Primitive Packet/data Sending Methods
  1899. /// <summary>
  1900. ///
  1901. /// </summary>
  1902. /// <param name="localID"></param>
  1903. /// <param name="rotation"></param>
  1904. /// <param name="attachPoint"></param>
  1905. public void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint)
  1906. {
  1907. ObjectAttachPacket attach = (ObjectAttachPacket)PacketPool.Instance.GetPacket(PacketType.ObjectAttach);
  1908. Console.WriteLine("Attach object!");
  1909. // TODO: don't create new blocks if recycling an old packet
  1910. attach.AgentData.AgentID = AgentId;
  1911. attach.AgentData.SessionID = m_sessionId;
  1912. attach.AgentData.AttachmentPoint = attachPoint;
  1913. attach.ObjectData = new ObjectAttachPacket.ObjectDataBlock[1];
  1914. attach.ObjectData[0] = new ObjectAttachPacket.ObjectDataBlock();
  1915. attach.ObjectData[0].ObjectLocalID = localID;
  1916. attach.ObjectData[0].Rotation = rotation;
  1917. attach.Header.Zerocoded = true;
  1918. OutPacket(attach, ThrottleOutPacketType.Task);
  1919. }
  1920. public void SendPrimitiveToClient(
  1921. ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape,
  1922. LLVector3 pos, LLVector3 vel, LLVector3 acc, LLQuaternion rotation, LLVector3 rvel,
  1923. uint flags, LLUUID objectID, LLUUID ownerID, string text, byte[] color,
  1924. uint parentID, byte[] particleSystem, byte clickAction)
  1925. {
  1926. byte[] textureanim = new byte[0];
  1927. SendPrimitiveToClient(regionHandle, timeDilation, localID, primShape, pos, vel,
  1928. acc, rotation, rvel, flags,
  1929. objectID, ownerID, text, color, parentID, particleSystem,
  1930. clickAction, textureanim, false,(uint)0, LLUUID.Zero, LLUUID.Zero,0,0,0);
  1931. }
  1932. public void SendPrimitiveToClient(
  1933. ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape,
  1934. LLVector3 pos, LLVector3 velocity, LLVector3 acceleration, LLQuaternion rotation, LLVector3 rotational_velocity,
  1935. uint flags,
  1936. LLUUID objectID, LLUUID ownerID, string text, byte[] color, uint parentID, byte[] particleSystem,
  1937. byte clickAction, byte[] textureanim, bool attachment, uint AttachPoint, LLUUID AssetId, LLUUID SoundId, double SoundGain, byte SoundFlags, double SoundRadius)
  1938. {
  1939. if (rotation.X == rotation.Y && rotation.Y == rotation.Z && rotation.Z == rotation.W && rotation.W == 0)
  1940. rotation = LLQuaternion.Identity;
  1941. ObjectUpdatePacket outPacket = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
  1942. // TODO: don't create new blocks if recycling an old packet
  1943. outPacket.RegionData.RegionHandle = regionHandle;
  1944. outPacket.RegionData.TimeDilation = timeDilation;
  1945. outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
  1946. outPacket.ObjectData[0] = CreatePrimUpdateBlock(primShape, flags);
  1947. outPacket.ObjectData[0].ID = localID;
  1948. outPacket.ObjectData[0].FullID = objectID;
  1949. outPacket.ObjectData[0].OwnerID = ownerID;
  1950. // Anything more than 255 will cause libsecondlife to barf
  1951. if (text.Length > 255)
  1952. {
  1953. text = text.Remove(255);
  1954. }
  1955. outPacket.ObjectData[0].Text = Helpers.StringToField(text);
  1956. outPacket.ObjectData[0].TextColor[0] = color[0];
  1957. outPacket.ObjectData[0].TextColor[1] = color[1];
  1958. outPacket.ObjectData[0].TextColor[2] = color[2];
  1959. outPacket.ObjectData[0].TextColor[3] = color[3];
  1960. outPacket.ObjectData[0].ParentID = parentID;
  1961. outPacket.ObjectData[0].PSBlock = particleSystem;
  1962. outPacket.ObjectData[0].ClickAction = clickAction;
  1963. outPacket.ObjectData[0].Flags = 0;
  1964. if (attachment)
  1965. {
  1966. // Necessary???
  1967. outPacket.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 2);
  1968. outPacket.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
  1969. // Item from inventory???
  1970. outPacket.ObjectData[0].NameValue =
  1971. Helpers.StringToField("AttachItemID STRING RW SV " + AssetId.UUID);
  1972. outPacket.ObjectData[0].State = (byte)((AttachPoint % 16) * 16 + (AttachPoint / 16));
  1973. }
  1974. // Xantor 20080528: Send sound info as well
  1975. outPacket.ObjectData[0].Sound = SoundId;
  1976. outPacket.ObjectData[0].OwnerID = ownerID;
  1977. outPacket.ObjectData[0].Gain = (float) SoundGain;
  1978. outPacket.ObjectData[0].Radius = (float) SoundRadius;
  1979. outPacket.ObjectData[0].Flags = SoundFlags;
  1980. byte[] pb = pos.GetBytes();
  1981. Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length);
  1982. byte[] vel = velocity.GetBytes();
  1983. Array.Copy(vel, 0, outPacket.ObjectData[0].ObjectData, pb.Length, vel.Length);
  1984. byte[] rot = rotation.GetBytes();
  1985. Array.Copy(rot, 0, outPacket.ObjectData[0].ObjectData, 36, rot.Length);
  1986. byte[] rvel = rotational_velocity.GetBytes();
  1987. Array.Copy(rvel, 0, outPacket.ObjectData[0].ObjectData, 36 + rot.Length, rvel.Length);
  1988. if (textureanim.Length > 0)
  1989. {
  1990. outPacket.ObjectData[0].TextureAnim = textureanim;
  1991. }
  1992. outPacket.Header.Zerocoded = true;
  1993. OutPacket(outPacket, ThrottleOutPacketType.Task);
  1994. }
  1995. /// <summary>
  1996. ///
  1997. /// </summary>
  1998. /// <param name="regionHandle"></param>
  1999. /// <param name="timeDilation"></param>
  2000. /// <param name="localID"></param>
  2001. /// <param name="position"></param>
  2002. /// <param name="rotation"></param>
  2003. public void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
  2004. LLQuaternion rotation, LLVector3 velocity, LLVector3 rotationalvelocity, byte state, LLUUID AssetId)
  2005. {
  2006. if (rotation.X == rotation.Y && rotation.Y == rotation.Z && rotation.Z == rotation.W && rotation.W == 0)
  2007. rotation = LLQuaternion.Identity;
  2008. ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
  2009. // TODO: don't create new blocks if recycling an old packet
  2010. terse.RegionData.RegionHandle = regionHandle;
  2011. terse.RegionData.TimeDilation = timeDilation;
  2012. terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
  2013. terse.ObjectData[0] = CreatePrimImprovedBlock(localID, position, rotation, velocity, rotationalvelocity, state); // AssetID should fall into here probably somehow...
  2014. terse.Header.Reliable = false;
  2015. terse.Header.Zerocoded = true;
  2016. OutPacket(terse, ThrottleOutPacketType.Task);
  2017. }
  2018. public void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
  2019. LLQuaternion rotation, LLVector3 velocity, LLVector3 rotationalvelocity)
  2020. {
  2021. if (rotation.X == rotation.Y && rotation.Y == rotation.Z && rotation.Z == rotation.W && rotation.W == 0)
  2022. rotation = LLQuaternion.Identity;
  2023. ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
  2024. // TODO: don't create new blocks if recycling an old packet
  2025. terse.RegionData.RegionHandle = regionHandle;
  2026. terse.RegionData.TimeDilation = timeDilation;
  2027. terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
  2028. terse.ObjectData[0] = CreatePrimImprovedBlock(localID, position, rotation, velocity, rotationalvelocity, 0);
  2029. terse.Header.Reliable = false;
  2030. terse.Header.Zerocoded = true;
  2031. OutPacket(terse, ThrottleOutPacketType.Task);
  2032. }
  2033. public void SendAssetUploadCompleteMessage(sbyte AssetType, bool Success, LLUUID AssetFullID)
  2034. {
  2035. AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
  2036. newPack.AssetBlock.Type = AssetType;
  2037. newPack.AssetBlock.Success = Success;
  2038. newPack.AssetBlock.UUID = AssetFullID;
  2039. newPack.Header.Zerocoded = true;
  2040. OutPacket(newPack, ThrottleOutPacketType.Asset);
  2041. }
  2042. public void SendXferRequest(ulong XferID, short AssetType, LLUUID vFileID, byte FilePath, byte[] FileName)
  2043. {
  2044. RequestXferPacket newPack = new RequestXferPacket();
  2045. newPack.XferID.ID = XferID;
  2046. newPack.XferID.VFileType = AssetType;
  2047. newPack.XferID.VFileID = vFileID;
  2048. newPack.XferID.FilePath = FilePath;
  2049. newPack.XferID.Filename = FileName;
  2050. newPack.Header.Zerocoded = true;
  2051. OutPacket(newPack, ThrottleOutPacketType.Asset);
  2052. }
  2053. public void SendConfirmXfer(ulong xferID, uint PacketID)
  2054. {
  2055. ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket();
  2056. newPack.XferID.ID = xferID;
  2057. newPack.XferID.Packet = PacketID;
  2058. newPack.Header.Zerocoded = true;
  2059. OutPacket(newPack, ThrottleOutPacketType.Asset);
  2060. }
  2061. public void SendImagePart(ushort numParts, LLUUID ImageUUID, uint ImageSize, byte[] ImageData, byte imageCodec)
  2062. {
  2063. ImageDataPacket im = new ImageDataPacket();
  2064. im.Header.Reliable = false;
  2065. im.ImageID.Packets = numParts;
  2066. im.ImageID.ID = ImageUUID;
  2067. if (ImageSize > 0)
  2068. im.ImageID.Size = ImageSize;
  2069. im.ImageData.Data = ImageData;
  2070. im.ImageID.Codec = imageCodec;
  2071. im.Header.Zerocoded = true;
  2072. OutPacket(im, ThrottleOutPacketType.Texture);
  2073. }
  2074. public void SendShutdownConnectionNotice()
  2075. {
  2076. OutPacket(PacketPool.Instance.GetPacket(PacketType.DisableSimulator), ThrottleOutPacketType.Unknown);
  2077. }
  2078. public void SendSimStats(Packet pack)
  2079. {
  2080. pack.Header.Reliable = false;
  2081. OutPacket(pack, ThrottleOutPacketType.Task);
  2082. }
  2083. public void SendObjectPropertiesFamilyData(uint RequestFlags, LLUUID ObjectUUID, LLUUID OwnerID, LLUUID GroupID,
  2084. uint BaseMask, uint OwnerMask, uint GroupMask, uint EveryoneMask,
  2085. uint NextOwnerMask, int OwnershipCost, byte SaleType,int SalePrice, uint Category,
  2086. LLUUID LastOwnerID, string ObjectName, string Description)
  2087. {
  2088. ObjectPropertiesFamilyPacket objPropFamilyPack = (ObjectPropertiesFamilyPacket)PacketPool.Instance.GetPacket(PacketType.ObjectPropertiesFamily);
  2089. // TODO: don't create new blocks if recycling an old packet
  2090. ObjectPropertiesFamilyPacket.ObjectDataBlock objPropDB = new ObjectPropertiesFamilyPacket.ObjectDataBlock();
  2091. objPropDB.RequestFlags = RequestFlags;
  2092. objPropDB.ObjectID = ObjectUUID;
  2093. objPropDB.OwnerID = OwnerID;
  2094. objPropDB.GroupID = GroupID;
  2095. objPropDB.BaseMask = BaseMask;
  2096. objPropDB.OwnerMask = OwnerMask;
  2097. objPropDB.GroupMask = GroupMask;
  2098. objPropDB.EveryoneMask = EveryoneMask;
  2099. objPropDB.NextOwnerMask = NextOwnerMask;
  2100. // TODO: More properties are needed in SceneObjectPart!
  2101. objPropDB.OwnershipCost = OwnershipCost;
  2102. objPropDB.SaleType = SaleType;
  2103. objPropDB.SalePrice = SalePrice;
  2104. objPropDB.Category = Category;
  2105. objPropDB.LastOwnerID = LastOwnerID;
  2106. objPropDB.Name = Helpers.StringToField(ObjectName);
  2107. objPropDB.Description = Helpers.StringToField(Description);
  2108. objPropFamilyPack.ObjectData = objPropDB;
  2109. objPropFamilyPack.Header.Zerocoded = true;
  2110. OutPacket(objPropFamilyPack, ThrottleOutPacketType.Task);
  2111. }
  2112. public void SendObjectPropertiesReply(LLUUID ItemID, ulong CreationDate, LLUUID CreatorUUID, LLUUID FolderUUID, LLUUID FromTaskUUID,
  2113. LLUUID GroupUUID, short InventorySerial, LLUUID LastOwnerUUID, LLUUID ObjectUUID,
  2114. LLUUID OwnerUUID, string TouchTitle, byte[] TextureID, string SitTitle, string ItemName,
  2115. string ItemDescription, uint OwnerMask, uint NextOwnerMask, uint GroupMask, uint EveryoneMask,
  2116. uint BaseMask)
  2117. {
  2118. ObjectPropertiesPacket proper = (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties);
  2119. // TODO: don't create new blocks if recycling an old packet
  2120. proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
  2121. proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
  2122. proper.ObjectData[0].ItemID = ItemID;
  2123. proper.ObjectData[0].CreationDate = CreationDate;
  2124. proper.ObjectData[0].CreatorID = CreatorUUID;
  2125. proper.ObjectData[0].FolderID = FolderUUID;
  2126. proper.ObjectData[0].FromTaskID = FromTaskUUID;
  2127. proper.ObjectData[0].GroupID = GroupUUID;
  2128. proper.ObjectData[0].InventorySerial = InventorySerial;
  2129. proper.ObjectData[0].LastOwnerID = LastOwnerUUID;
  2130. // proper.ObjectData[0].LastOwnerID = LLUUID.Zero;
  2131. proper.ObjectData[0].ObjectID = ObjectUUID;
  2132. proper.ObjectData[0].OwnerID = OwnerUUID;
  2133. proper.ObjectData[0].TouchName = Helpers.StringToField(TouchTitle);
  2134. proper.ObjectData[0].TextureID = TextureID;
  2135. proper.ObjectData[0].SitName = Helpers.StringToField(SitTitle);
  2136. proper.ObjectData[0].Name = Helpers.StringToField(ItemName);
  2137. proper.ObjectData[0].Description = Helpers.StringToField(ItemDescription);
  2138. proper.ObjectData[0].OwnerMask = OwnerMask;
  2139. proper.ObjectData[0].NextOwnerMask = NextOwnerMask;
  2140. proper.ObjectData[0].GroupMask = GroupMask;
  2141. proper.ObjectData[0].EveryoneMask = EveryoneMask;
  2142. proper.ObjectData[0].BaseMask = BaseMask;
  2143. // proper.ObjectData[0].AggregatePerms = 53;
  2144. // proper.ObjectData[0].AggregatePermTextures = 0;
  2145. // proper.ObjectData[0].AggregatePermTexturesOwner = 0;
  2146. proper.Header.Zerocoded = true;
  2147. OutPacket(proper, ThrottleOutPacketType.Task);
  2148. }
  2149. #endregion
  2150. #region Estate Data Sending Methods
  2151. private bool convertParamStringToBool(byte[] field)
  2152. {
  2153. string s = Helpers.FieldToUTF8String(field);
  2154. if (s == "1" || s.ToLower() == "y" || s.ToLower() == "yes" || s.ToLower() == "t" || s.ToLower() == "true")
  2155. {
  2156. return true;
  2157. }
  2158. return false;
  2159. }
  2160. public void sendEstateManagersList(LLUUID invoice, LLUUID[] EstateManagers, uint estateID)
  2161. {
  2162. EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
  2163. packet.AgentData.TransactionID = LLUUID.Random();
  2164. packet.AgentData.AgentID = this.AgentId;
  2165. packet.AgentData.SessionID = this.SessionId;
  2166. packet.MethodData.Invoice = invoice;
  2167. packet.MethodData.Method = Helpers.StringToField("setaccess");
  2168. EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[6 + EstateManagers.Length];
  2169. for (int i = 0; i < (6 + EstateManagers.Length); i++)
  2170. {
  2171. returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
  2172. }
  2173. int j = 0;
  2174. returnblock[j].Parameter = Helpers.StringToField(estateID.ToString()); j++;
  2175. returnblock[j].Parameter = Helpers.StringToField(((int)Constants.EstateAccessCodex.EstateManagers).ToString()); j++;
  2176. returnblock[j].Parameter = Helpers.StringToField("0"); j++;
  2177. returnblock[j].Parameter = Helpers.StringToField("0"); j++;
  2178. returnblock[j].Parameter = Helpers.StringToField("0"); j++;
  2179. returnblock[j].Parameter = Helpers.StringToField(EstateManagers.Length.ToString()); j++;
  2180. for (int i = 0; i < EstateManagers.Length; i++)
  2181. {
  2182. returnblock[j].Parameter = EstateManagers[i].GetBytes(); j++;
  2183. }
  2184. packet.ParamList = returnblock;
  2185. packet.Header.Reliable = false;
  2186. this.OutPacket(packet, ThrottleOutPacketType.Task);
  2187. }
  2188. public void sendRegionInfoToEstateMenu(RegionInfoForEstateMenuArgs args)
  2189. {
  2190. RegionInfoPacket rinfopack = new RegionInfoPacket();
  2191. RegionInfoPacket.RegionInfoBlock rinfoblk = new RegionInfoPacket.RegionInfoBlock();
  2192. rinfopack.AgentData.AgentID = this.AgentId;
  2193. rinfopack.AgentData.SessionID = this.SessionId;
  2194. rinfoblk.BillableFactor =args.billableFactor;
  2195. rinfoblk.EstateID = args.estateID;
  2196. rinfoblk.MaxAgents = args.maxAgents;
  2197. rinfoblk.ObjectBonusFactor =args.objectBonusFactor;
  2198. rinfoblk.ParentEstateID = args.parentEstateID;
  2199. rinfoblk.PricePerMeter = args.pricePerMeter;
  2200. rinfoblk.RedirectGridX = args.redirectGridX;
  2201. rinfoblk.RedirectGridY = args.redirectGridY;
  2202. rinfoblk.RegionFlags = args.regionFlags;
  2203. rinfoblk.SimAccess = args.simAccess;
  2204. rinfoblk.SunHour = args.sunHour;
  2205. rinfoblk.TerrainLowerLimit = args.terrainLowerLimit;
  2206. rinfoblk.TerrainRaiseLimit = args.terrainRaiseLimit;
  2207. rinfoblk.UseEstateSun = args.useEstateSun;
  2208. rinfoblk.WaterHeight = args.waterHeight;
  2209. rinfoblk.SimName = Helpers.StringToField(args.simName);
  2210. rinfopack.RegionInfo = rinfoblk;
  2211. this.OutPacket(rinfopack, ThrottleOutPacketType.Task);
  2212. }
  2213. public void sendEstateCovenantInformation()
  2214. {
  2215. EstateCovenantReplyPacket einfopack = new EstateCovenantReplyPacket();
  2216. EstateCovenantReplyPacket.DataBlock edata = new EstateCovenantReplyPacket.DataBlock();
  2217. edata.CovenantID = m_scene.RegionInfo.CovenantID;
  2218. edata.CovenantTimestamp = 0;
  2219. edata.EstateOwnerID = m_scene.RegionInfo.MasterAvatarAssignedUUID;
  2220. edata.EstateName =
  2221. Helpers.StringToField(m_scene.RegionInfo.MasterAvatarFirstName + " " + m_scene.RegionInfo.MasterAvatarLastName);
  2222. einfopack.Data = edata;
  2223. this.OutPacket(einfopack, ThrottleOutPacketType.Task);
  2224. }
  2225. public void sendDetailedEstateData(LLUUID invoice, string estateName, uint estateID)
  2226. {
  2227. EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
  2228. packet.MethodData.Invoice = invoice;
  2229. packet.AgentData.TransactionID = LLUUID.Random();
  2230. packet.MethodData.Method = Helpers.StringToField("estateupdateinfo");
  2231. EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[9];
  2232. for (int i = 0; i < 9; i++)
  2233. {
  2234. returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
  2235. }
  2236. //Sending Estate Settings
  2237. returnblock[0].Parameter = Helpers.StringToField(estateName);
  2238. returnblock[1].Parameter = Helpers.StringToField(m_scene.RegionInfo.MasterAvatarAssignedUUID.ToString());
  2239. returnblock[2].Parameter = Helpers.StringToField(estateID.ToString());
  2240. // TODO: Resolve Magic numbers here
  2241. returnblock[3].Parameter = Helpers.StringToField("269516800");
  2242. returnblock[4].Parameter = Helpers.StringToField("0");
  2243. returnblock[5].Parameter = Helpers.StringToField("1");
  2244. returnblock[6].Parameter = Helpers.StringToField(m_scene.RegionInfo.RegionID.ToString());
  2245. returnblock[7].Parameter = Helpers.StringToField("1160895077");
  2246. returnblock[8].Parameter = Helpers.StringToField("1");
  2247. packet.ParamList = returnblock;
  2248. packet.Header.Reliable = false;
  2249. //System.Console.WriteLine("[ESTATE]: SIM--->" + packet.ToString());
  2250. this.OutPacket(packet, ThrottleOutPacketType.Task);
  2251. }
  2252. #endregion
  2253. #region Land Data Sending Methods
  2254. public void sendLandParcelOverlay(byte[] data, int sequence_id)
  2255. {
  2256. ParcelOverlayPacket packet;
  2257. packet = (ParcelOverlayPacket)PacketPool.Instance.GetPacket(PacketType.ParcelOverlay);
  2258. packet.ParcelData.Data = data;
  2259. packet.ParcelData.SequenceID = sequence_id;
  2260. packet.Header.Zerocoded = true;
  2261. this.OutPacket(packet, ThrottleOutPacketType.Task);
  2262. }
  2263. public void sendLandProperties(IClientAPI remote_client,int sequence_id, bool snap_selection, int request_result, LandData landData, float simObjectBonusFactor, int simObjectCapacity, uint regionFlags)
  2264. {
  2265. ParcelPropertiesPacket updatePacket = (ParcelPropertiesPacket) PacketPool.Instance.GetPacket(PacketType.ParcelProperties);
  2266. // TODO: don't create new blocks if recycling an old packet
  2267. updatePacket.ParcelData.AABBMax = landData.AABBMax;
  2268. updatePacket.ParcelData.AABBMin = landData.AABBMin;
  2269. updatePacket.ParcelData.Area = landData.area;
  2270. updatePacket.ParcelData.AuctionID = landData.auctionID;
  2271. updatePacket.ParcelData.AuthBuyerID = landData.authBuyerID; //unemplemented
  2272. updatePacket.ParcelData.Bitmap = landData.landBitmapByteArray;
  2273. updatePacket.ParcelData.Desc = Helpers.StringToField(landData.landDesc);
  2274. updatePacket.ParcelData.Category = (byte) landData.category;
  2275. updatePacket.ParcelData.ClaimDate = landData.claimDate;
  2276. updatePacket.ParcelData.ClaimPrice = landData.claimPrice;
  2277. updatePacket.ParcelData.GroupID = landData.groupID;
  2278. updatePacket.ParcelData.GroupPrims = landData.groupPrims;
  2279. updatePacket.ParcelData.IsGroupOwned = landData.isGroupOwned;
  2280. updatePacket.ParcelData.LandingType = (byte) landData.landingType;
  2281. updatePacket.ParcelData.LocalID = landData.localID;
  2282. if (landData.area > 0)
  2283. {
  2284. updatePacket.ParcelData.MaxPrims =
  2285. Convert.ToInt32(
  2286. Math.Round((Convert.ToDecimal(landData.area) / Convert.ToDecimal(65536)) * simObjectCapacity *
  2287. Convert.ToDecimal(simObjectBonusFactor)));
  2288. }
  2289. else
  2290. {
  2291. updatePacket.ParcelData.MaxPrims = 0;
  2292. }
  2293. updatePacket.ParcelData.MediaAutoScale = landData.mediaAutoScale;
  2294. updatePacket.ParcelData.MediaID = landData.mediaID;
  2295. updatePacket.ParcelData.MediaURL = Helpers.StringToField(landData.mediaURL);
  2296. updatePacket.ParcelData.MusicURL = Helpers.StringToField(landData.musicURL);
  2297. updatePacket.ParcelData.Name = Helpers.StringToField(landData.landName);
  2298. updatePacket.ParcelData.OtherCleanTime = 0; //unemplemented
  2299. updatePacket.ParcelData.OtherCount = 0; //unemplemented
  2300. updatePacket.ParcelData.OtherPrims = landData.otherPrims;
  2301. updatePacket.ParcelData.OwnerID = landData.ownerID;
  2302. updatePacket.ParcelData.OwnerPrims = landData.ownerPrims;
  2303. updatePacket.ParcelData.ParcelFlags = landData.landFlags;
  2304. updatePacket.ParcelData.ParcelPrimBonus = simObjectBonusFactor;
  2305. updatePacket.ParcelData.PassHours = landData.passHours;
  2306. updatePacket.ParcelData.PassPrice = landData.passPrice;
  2307. updatePacket.ParcelData.PublicCount = 0; //unemplemented
  2308. updatePacket.ParcelData.RegionDenyAnonymous = ((regionFlags & (uint) Simulator.RegionFlags.DenyAnonymous) >
  2309. 0);
  2310. updatePacket.ParcelData.RegionDenyIdentified = ((regionFlags & (uint) Simulator.RegionFlags.DenyIdentified) >
  2311. 0);
  2312. updatePacket.ParcelData.RegionDenyTransacted = ((regionFlags & (uint) Simulator.RegionFlags.DenyTransacted) >
  2313. 0);
  2314. updatePacket.ParcelData.RegionPushOverride = ((regionFlags & (uint) Simulator.RegionFlags.RestrictPushObject) >
  2315. 0);
  2316. updatePacket.ParcelData.RentPrice = 0;
  2317. updatePacket.ParcelData.RequestResult = request_result;
  2318. updatePacket.ParcelData.SalePrice = landData.salePrice;
  2319. updatePacket.ParcelData.SelectedPrims = landData.selectedPrims;
  2320. updatePacket.ParcelData.SelfCount = 0; //unemplemented
  2321. updatePacket.ParcelData.SequenceID = sequence_id;
  2322. if (landData.simwideArea > 0)
  2323. {
  2324. updatePacket.ParcelData.SimWideMaxPrims =
  2325. Convert.ToInt32(
  2326. Math.Round((Convert.ToDecimal(landData.simwideArea) / Convert.ToDecimal(65536)) * simObjectCapacity *
  2327. Convert.ToDecimal(simObjectBonusFactor)));
  2328. }
  2329. else
  2330. {
  2331. updatePacket.ParcelData.SimWideMaxPrims = 0;
  2332. }
  2333. updatePacket.ParcelData.SimWideTotalPrims = landData.simwidePrims;
  2334. updatePacket.ParcelData.SnapSelection = snap_selection;
  2335. updatePacket.ParcelData.SnapshotID = landData.snapshotID;
  2336. updatePacket.ParcelData.Status = (byte) landData.landStatus;
  2337. updatePacket.ParcelData.TotalPrims = landData.ownerPrims + landData.groupPrims + landData.otherPrims +
  2338. landData.selectedPrims;
  2339. updatePacket.ParcelData.UserLocation = landData.userLocation;
  2340. updatePacket.ParcelData.UserLookAt = landData.userLookAt;
  2341. updatePacket.Header.Zerocoded = true;
  2342. remote_client.OutPacket((Packet) updatePacket, ThrottleOutPacketType.Task);
  2343. }
  2344. public void sendLandAccessListData(List<LLUUID> avatars, uint accessFlag, int localLandID)
  2345. {
  2346. ParcelAccessListReplyPacket replyPacket = (ParcelAccessListReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelAccessListReply);
  2347. replyPacket.Data.AgentID = this.AgentId;
  2348. replyPacket.Data.Flags = accessFlag;
  2349. replyPacket.Data.LocalID = localLandID;
  2350. replyPacket.Data.SequenceID = 0;
  2351. List<ParcelAccessListReplyPacket.ListBlock> list = new List<ParcelAccessListReplyPacket.ListBlock>();
  2352. foreach (LLUUID avatar in avatars)
  2353. {
  2354. ParcelAccessListReplyPacket.ListBlock block = new ParcelAccessListReplyPacket.ListBlock();
  2355. block.Flags = accessFlag;
  2356. block.ID = avatar;
  2357. block.Time = 0;
  2358. }
  2359. replyPacket.List = list.ToArray();
  2360. replyPacket.Header.Zerocoded = true;
  2361. this.OutPacket((Packet)replyPacket, ThrottleOutPacketType.Task);
  2362. }
  2363. public void sendForceClientSelectObjects(List<uint> ObjectIDs)
  2364. {
  2365. bool firstCall = true;
  2366. int MAX_OBJECTS_PER_PACKET = 251;
  2367. ForceObjectSelectPacket pack = (ForceObjectSelectPacket)PacketPool.Instance.GetPacket(PacketType.ForceObjectSelect);
  2368. ForceObjectSelectPacket.DataBlock[] data;
  2369. while (ObjectIDs.Count > 0)
  2370. {
  2371. if (firstCall)
  2372. {
  2373. pack._Header.ResetList = true;
  2374. firstCall = false;
  2375. }
  2376. else
  2377. {
  2378. pack._Header.ResetList = false;
  2379. }
  2380. if (ObjectIDs.Count > MAX_OBJECTS_PER_PACKET)
  2381. {
  2382. data = new ForceObjectSelectPacket.DataBlock[MAX_OBJECTS_PER_PACKET];
  2383. }
  2384. else
  2385. {
  2386. data = new ForceObjectSelectPacket.DataBlock[ObjectIDs.Count];
  2387. }
  2388. int i;
  2389. for (i = 0; i < MAX_OBJECTS_PER_PACKET && ObjectIDs.Count > 0; i++)
  2390. {
  2391. data[i] = new ForceObjectSelectPacket.DataBlock();
  2392. data[i].LocalID = Convert.ToUInt32(ObjectIDs[0]);
  2393. ObjectIDs.RemoveAt(0);
  2394. }
  2395. pack.Data = data;
  2396. pack.Header.Zerocoded = true;
  2397. this.OutPacket((Packet)pack, ThrottleOutPacketType.Task);
  2398. }
  2399. }
  2400. public void sendLandObjectOwners(Dictionary<LLUUID, int> ownersAndCount)
  2401. {
  2402. int notifyCount = ownersAndCount.Count;
  2403. ParcelObjectOwnersReplyPacket pack = (ParcelObjectOwnersReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelObjectOwnersReply);
  2404. if (notifyCount > 0)
  2405. {
  2406. if (notifyCount > 32)
  2407. {
  2408. m_log.InfoFormat(
  2409. "[LAND]: More than {0} avatars own prims on this parcel. Only sending back details of first {0}"
  2410. + " - a developer might want to investigate whether this is a hard limit", 32);
  2411. notifyCount = 32;
  2412. }
  2413. ParcelObjectOwnersReplyPacket.DataBlock[] dataBlock
  2414. = new ParcelObjectOwnersReplyPacket.DataBlock[notifyCount];
  2415. int num = 0;
  2416. foreach (LLUUID owner in ownersAndCount.Keys)
  2417. {
  2418. dataBlock[num] = new ParcelObjectOwnersReplyPacket.DataBlock();
  2419. dataBlock[num].Count = ownersAndCount[owner];
  2420. dataBlock[num].IsGroupOwned = false; //TODO: fix me when group support is added
  2421. dataBlock[num].OnlineStatus = true; //TODO: fix me later
  2422. dataBlock[num].OwnerID = owner;
  2423. num++;
  2424. if (num >= notifyCount)
  2425. {
  2426. break;
  2427. }
  2428. }
  2429. pack.Data = dataBlock;
  2430. }
  2431. pack.Header.Zerocoded = true;
  2432. this.OutPacket(pack, ThrottleOutPacketType.Task);
  2433. }
  2434. #endregion
  2435. #region Helper Methods
  2436. protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateAvatarImprovedBlock(uint localID, LLVector3 pos,
  2437. LLVector3 velocity,
  2438. LLQuaternion rotation)
  2439. {
  2440. byte[] bytes = new byte[60];
  2441. int i = 0;
  2442. ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
  2443. dat.TextureEntry = new byte[0]; // AvatarTemplate.TextureEntry;
  2444. uint ID = localID;
  2445. bytes[i++] = (byte)(ID % 256);
  2446. bytes[i++] = (byte)((ID >> 8) % 256);
  2447. bytes[i++] = (byte)((ID >> 16) % 256);
  2448. bytes[i++] = (byte)((ID >> 24) % 256);
  2449. bytes[i++] = 0;
  2450. bytes[i++] = 1;
  2451. i += 14;
  2452. bytes[i++] = 128;
  2453. bytes[i++] = 63;
  2454. byte[] pb = pos.GetBytes();
  2455. Array.Copy(pb, 0, bytes, i, pb.Length);
  2456. i += 12;
  2457. ushort InternVelocityX;
  2458. ushort InternVelocityY;
  2459. ushort InternVelocityZ;
  2460. Vector3 internDirec = new Vector3(0, 0, 0);
  2461. internDirec = new Vector3(velocity.X, velocity.Y, velocity.Z);
  2462. internDirec = internDirec / 128.0f;
  2463. internDirec.x += 1;
  2464. internDirec.y += 1;
  2465. internDirec.z += 1;
  2466. InternVelocityX = (ushort)(32768 * internDirec.x);
  2467. InternVelocityY = (ushort)(32768 * internDirec.y);
  2468. InternVelocityZ = (ushort)(32768 * internDirec.z);
  2469. ushort ac = 32767;
  2470. bytes[i++] = (byte)(InternVelocityX % 256);
  2471. bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
  2472. bytes[i++] = (byte)(InternVelocityY % 256);
  2473. bytes[i++] = (byte)((InternVelocityY >> 8) % 256);
  2474. bytes[i++] = (byte)(InternVelocityZ % 256);
  2475. bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
  2476. //accel
  2477. bytes[i++] = (byte)(ac % 256);
  2478. bytes[i++] = (byte)((ac >> 8) % 256);
  2479. bytes[i++] = (byte)(ac % 256);
  2480. bytes[i++] = (byte)((ac >> 8) % 256);
  2481. bytes[i++] = (byte)(ac % 256);
  2482. bytes[i++] = (byte)((ac >> 8) % 256);
  2483. //rotation
  2484. ushort rw, rx, ry, rz;
  2485. rw = (ushort)(32768 * (rotation.W + 1));
  2486. rx = (ushort)(32768 * (rotation.X + 1));
  2487. ry = (ushort)(32768 * (rotation.Y + 1));
  2488. rz = (ushort)(32768 * (rotation.Z + 1));
  2489. //rot
  2490. bytes[i++] = (byte)(rx % 256);
  2491. bytes[i++] = (byte)((rx >> 8) % 256);
  2492. bytes[i++] = (byte)(ry % 256);
  2493. bytes[i++] = (byte)((ry >> 8) % 256);
  2494. bytes[i++] = (byte)(rz % 256);
  2495. bytes[i++] = (byte)((rz >> 8) % 256);
  2496. bytes[i++] = (byte)(rw % 256);
  2497. bytes[i++] = (byte)((rw >> 8) % 256);
  2498. //rotation vel
  2499. bytes[i++] = (byte)(ac % 256);
  2500. bytes[i++] = (byte)((ac >> 8) % 256);
  2501. bytes[i++] = (byte)(ac % 256);
  2502. bytes[i++] = (byte)((ac >> 8) % 256);
  2503. bytes[i++] = (byte)(ac % 256);
  2504. bytes[i++] = (byte)((ac >> 8) % 256);
  2505. dat.Data = bytes;
  2506. return (dat);
  2507. }
  2508. /// <summary>
  2509. ///
  2510. /// </summary>
  2511. /// <param name="localID"></param>
  2512. /// <param name="position"></param>
  2513. /// <param name="rotation"></param>
  2514. /// <returns></returns>
  2515. protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreatePrimImprovedBlock(uint localID,
  2516. LLVector3 position,
  2517. LLQuaternion rotation,
  2518. LLVector3 velocity,
  2519. LLVector3 rotationalvelocity,
  2520. byte state)
  2521. {
  2522. uint ID = localID;
  2523. byte[] bytes = new byte[60];
  2524. int i = 0;
  2525. ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
  2526. dat.TextureEntry = new byte[0];
  2527. bytes[i++] = (byte)(ID % 256);
  2528. bytes[i++] = (byte)((ID >> 8) % 256);
  2529. bytes[i++] = (byte)((ID >> 16) % 256);
  2530. bytes[i++] = (byte)((ID >> 24) % 256);
  2531. bytes[i++] = state;
  2532. bytes[i++] = 0;
  2533. byte[] pb = position.GetBytes();
  2534. Array.Copy(pb, 0, bytes, i, pb.Length);
  2535. i += 12;
  2536. ushort ac = 32767;
  2537. ushort velx, vely, velz;
  2538. Vector3 vel = new Vector3(velocity.X, velocity.Y, velocity.Z);
  2539. vel = vel / 128.0f;
  2540. vel.x += 1;
  2541. vel.y += 1;
  2542. vel.z += 1;
  2543. //vel
  2544. velx = (ushort)(32768 * (vel.x));
  2545. vely = (ushort)(32768 * (vel.y));
  2546. velz = (ushort)(32768 * (vel.z));
  2547. bytes[i++] = (byte)(velx % 256);
  2548. bytes[i++] = (byte)((velx >> 8) % 256);
  2549. bytes[i++] = (byte)(vely % 256);
  2550. bytes[i++] = (byte)((vely >> 8) % 256);
  2551. bytes[i++] = (byte)(velz % 256);
  2552. bytes[i++] = (byte)((velz >> 8) % 256);
  2553. //accel
  2554. bytes[i++] = (byte)(ac % 256);
  2555. bytes[i++] = (byte)((ac >> 8) % 256);
  2556. bytes[i++] = (byte)(ac % 256);
  2557. bytes[i++] = (byte)((ac >> 8) % 256);
  2558. bytes[i++] = (byte)(ac % 256);
  2559. bytes[i++] = (byte)((ac >> 8) % 256);
  2560. ushort rw, rx, ry, rz;
  2561. rw = (ushort)(32768 * (rotation.W + 1));
  2562. rx = (ushort)(32768 * (rotation.X + 1));
  2563. ry = (ushort)(32768 * (rotation.Y + 1));
  2564. rz = (ushort)(32768 * (rotation.Z + 1));
  2565. //rot
  2566. bytes[i++] = (byte)(rx % 256);
  2567. bytes[i++] = (byte)((rx >> 8) % 256);
  2568. bytes[i++] = (byte)(ry % 256);
  2569. bytes[i++] = (byte)((ry >> 8) % 256);
  2570. bytes[i++] = (byte)(rz % 256);
  2571. bytes[i++] = (byte)((rz >> 8) % 256);
  2572. bytes[i++] = (byte)(rw % 256);
  2573. bytes[i++] = (byte)((rw >> 8) % 256);
  2574. //rotation vel
  2575. ushort rvelx, rvely, rvelz;
  2576. Vector3 rvel = new Vector3(rotationalvelocity.X, rotationalvelocity.Y, rotationalvelocity.Z);
  2577. rvel = rvel / 128.0f;
  2578. rvel.x += 1;
  2579. rvel.y += 1;
  2580. rvel.z += 1;
  2581. //vel
  2582. rvelx = (ushort)(32768 * (rvel.x));
  2583. rvely = (ushort)(32768 * (rvel.y));
  2584. rvelz = (ushort)(32768 * (rvel.z));
  2585. bytes[i++] = (byte)(rvelx % 256);
  2586. bytes[i++] = (byte)((rvelx >> 8) % 256);
  2587. bytes[i++] = (byte)(rvely % 256);
  2588. bytes[i++] = (byte)((rvely >> 8) % 256);
  2589. bytes[i++] = (byte)(rvelz % 256);
  2590. bytes[i++] = (byte)((rvelz >> 8) % 256);
  2591. dat.Data = bytes;
  2592. return dat;
  2593. }
  2594. /// <summary>
  2595. /// Create the ObjectDataBlock for a ObjectUpdatePacket (for a Primitive)
  2596. /// </summary>
  2597. /// <param name="primData"></param>
  2598. /// <returns></returns>
  2599. protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(PrimitiveBaseShape primShape, uint flags)
  2600. {
  2601. ObjectUpdatePacket.ObjectDataBlock objupdate = new ObjectUpdatePacket.ObjectDataBlock();
  2602. SetDefaultPrimPacketValues(objupdate);
  2603. objupdate.UpdateFlags = flags;
  2604. SetPrimPacketShapeData(objupdate, primShape);
  2605. if ((primShape.PCode == (byte)PCode.NewTree) || (primShape.PCode == (byte)PCode.Tree) || (primShape.PCode == (byte)PCode.Grass))
  2606. {
  2607. objupdate.Data = new byte[1];
  2608. objupdate.Data[0] = primShape.State;
  2609. }
  2610. return objupdate;
  2611. }
  2612. protected void SetPrimPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData, PrimitiveBaseShape primData)
  2613. {
  2614. objectData.TextureEntry = primData.TextureEntry;
  2615. objectData.PCode = primData.PCode;
  2616. objectData.State = primData.State;
  2617. objectData.PathBegin = primData.PathBegin;
  2618. objectData.PathEnd = primData.PathEnd;
  2619. objectData.PathScaleX = primData.PathScaleX;
  2620. objectData.PathScaleY = primData.PathScaleY;
  2621. objectData.PathShearX = primData.PathShearX;
  2622. objectData.PathShearY = primData.PathShearY;
  2623. objectData.PathSkew = primData.PathSkew;
  2624. objectData.ProfileBegin = primData.ProfileBegin;
  2625. objectData.ProfileEnd = primData.ProfileEnd;
  2626. objectData.Scale = primData.Scale;
  2627. objectData.PathCurve = primData.PathCurve;
  2628. objectData.ProfileCurve = primData.ProfileCurve;
  2629. objectData.ProfileHollow = primData.ProfileHollow;
  2630. objectData.PathRadiusOffset = primData.PathRadiusOffset;
  2631. objectData.PathRevolutions = primData.PathRevolutions;
  2632. objectData.PathTaperX = primData.PathTaperX;
  2633. objectData.PathTaperY = primData.PathTaperY;
  2634. objectData.PathTwist = primData.PathTwist;
  2635. objectData.PathTwistBegin = primData.PathTwistBegin;
  2636. objectData.ExtraParams = primData.ExtraParams;
  2637. }
  2638. /// <summary>
  2639. /// Set some default values in a ObjectUpdatePacket
  2640. /// </summary>
  2641. /// <param name="objdata"></param>
  2642. protected void SetDefaultPrimPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
  2643. {
  2644. objdata.PSBlock = new byte[0];
  2645. objdata.ExtraParams = new byte[1];
  2646. objdata.MediaURL = new byte[0];
  2647. objdata.NameValue = new byte[0];
  2648. objdata.Text = new byte[0];
  2649. objdata.TextColor = new byte[4];
  2650. objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
  2651. objdata.JointPivot = new LLVector3(0, 0, 0);
  2652. objdata.Material = 3;
  2653. objdata.TextureAnim = new byte[0];
  2654. objdata.Sound = LLUUID.Zero;
  2655. objdata.State = 0;
  2656. objdata.Data = new byte[0];
  2657. objdata.ObjectData = new byte[60];
  2658. objdata.ObjectData[46] = 128;
  2659. objdata.ObjectData[47] = 63;
  2660. }
  2661. /// <summary>
  2662. ///
  2663. /// </summary>
  2664. /// <returns></returns>
  2665. public ObjectUpdatePacket.ObjectDataBlock CreateDefaultAvatarPacket(byte[] textureEntry)
  2666. {
  2667. ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock();
  2668. // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
  2669. SetDefaultAvatarPacketValues(ref objdata);
  2670. objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
  2671. objdata.PathCurve = 16;
  2672. objdata.ProfileCurve = 1;
  2673. objdata.PathScaleX = 100;
  2674. objdata.PathScaleY = 100;
  2675. objdata.ParentID = 0;
  2676. objdata.OwnerID = LLUUID.Zero;
  2677. objdata.Scale = new LLVector3(1, 1, 1);
  2678. objdata.PCode = (byte)PCode.Avatar;
  2679. if (textureEntry != null)
  2680. {
  2681. objdata.TextureEntry = textureEntry;
  2682. }
  2683. LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
  2684. pos.X = 100f;
  2685. objdata.ID = 8880000;
  2686. objdata.NameValue = Helpers.StringToField("FirstName STRING RW SV Test \nLastName STRING RW SV User ");
  2687. //LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
  2688. //objdata.FullID=user.AgentId;
  2689. byte[] pb = pos.GetBytes();
  2690. Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
  2691. return objdata;
  2692. }
  2693. /// <summary>
  2694. ///
  2695. /// </summary>
  2696. /// <param name="objdata"></param>
  2697. protected void SetDefaultAvatarPacketValues(ref ObjectUpdatePacket.ObjectDataBlock objdata)
  2698. {
  2699. objdata.PSBlock = new byte[0];
  2700. objdata.ExtraParams = new byte[1];
  2701. objdata.MediaURL = new byte[0];
  2702. objdata.NameValue = new byte[0];
  2703. objdata.Text = new byte[0];
  2704. objdata.TextColor = new byte[4];
  2705. objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
  2706. objdata.JointPivot = new LLVector3(0, 0, 0);
  2707. objdata.Material = 4;
  2708. objdata.TextureAnim = new byte[0];
  2709. objdata.Sound = LLUUID.Zero;
  2710. LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
  2711. objdata.TextureEntry = ntex.ToBytes();
  2712. objdata.State = 0;
  2713. objdata.Data = new byte[0];
  2714. objdata.ObjectData = new byte[76];
  2715. objdata.ObjectData[15] = 128;
  2716. objdata.ObjectData[16] = 63;
  2717. objdata.ObjectData[56] = 128;
  2718. objdata.ObjectData[61] = 102;
  2719. objdata.ObjectData[62] = 40;
  2720. objdata.ObjectData[63] = 61;
  2721. objdata.ObjectData[64] = 189;
  2722. }
  2723. public void SendNameReply(LLUUID profileId, string firstname, string lastname)
  2724. {
  2725. UUIDNameReplyPacket packet = (UUIDNameReplyPacket)PacketPool.Instance.GetPacket(PacketType.UUIDNameReply);
  2726. // TODO: don't create new blocks if recycling an old packet
  2727. packet.UUIDNameBlock = new UUIDNameReplyPacket.UUIDNameBlockBlock[1];
  2728. packet.UUIDNameBlock[0] = new UUIDNameReplyPacket.UUIDNameBlockBlock();
  2729. packet.UUIDNameBlock[0].ID = profileId;
  2730. packet.UUIDNameBlock[0].FirstName = Helpers.StringToField(firstname);
  2731. packet.UUIDNameBlock[0].LastName = Helpers.StringToField(lastname);
  2732. OutPacket(packet, ThrottleOutPacketType.Task);
  2733. }
  2734. #endregion
  2735. protected virtual void RegisterLocalPacketHandlers()
  2736. {
  2737. AddLocalPacketHandler(PacketType.LogoutRequest, Logout);
  2738. AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect);
  2739. AddLocalPacketHandler(PacketType.AgentCachedTexture, AgentTextureCached);
  2740. AddLocalPacketHandler(PacketType.MultipleObjectUpdate, MultipleObjUpdate);
  2741. AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest);
  2742. AddLocalPacketHandler(PacketType.ParcelBuy, HandleParcelBuyRequest);
  2743. AddLocalPacketHandler(PacketType.UUIDGroupNameRequest, HandleUUIDGroupNameRequest);
  2744. AddLocalPacketHandler(PacketType.ObjectGroup, HandleObjectGroupRequest);
  2745. }
  2746. private bool HandleMoneyTransferRequest(IClientAPI sender, Packet Pack)
  2747. {
  2748. MoneyTransferRequestPacket money = (MoneyTransferRequestPacket)Pack;
  2749. // validate the agent owns the agentID and sessionID
  2750. if (money.MoneyData.SourceID == sender.AgentId && money.AgentData.AgentID == sender.AgentId && money.AgentData.SessionID == sender.SessionId)
  2751. {
  2752. handlerMoneyTransferRequest = OnMoneyTransferRequest;
  2753. if (handlerMoneyTransferRequest != null)
  2754. {
  2755. handlerMoneyTransferRequest(money.MoneyData.SourceID, money.MoneyData.DestID,
  2756. money.MoneyData.Amount, money.MoneyData.TransactionType,
  2757. Util.FieldToString(money.MoneyData.Description));
  2758. }
  2759. return true;
  2760. }
  2761. else
  2762. {
  2763. return false;
  2764. }
  2765. }
  2766. private bool HandleParcelBuyRequest(IClientAPI sender, Packet Pack)
  2767. {
  2768. ParcelBuyPacket parcel = (ParcelBuyPacket)Pack;
  2769. if (parcel.AgentData.AgentID == AgentId && parcel.AgentData.SessionID == this.SessionId)
  2770. {
  2771. handlerParcelBuy = OnParcelBuy;
  2772. if (handlerParcelBuy != null)
  2773. {
  2774. handlerParcelBuy(parcel.AgentData.AgentID, parcel.Data.GroupID, parcel.Data.Final, parcel.Data.IsGroupOwned,
  2775. parcel.Data.RemoveContribution, parcel.Data.LocalID, parcel.ParcelData.Area, parcel.ParcelData.Price,
  2776. false);
  2777. }
  2778. return true;
  2779. }
  2780. else
  2781. {
  2782. return false;
  2783. }
  2784. }
  2785. private bool HandleUUIDGroupNameRequest(IClientAPI sender, Packet Pack)
  2786. {
  2787. UUIDGroupNameRequestPacket upack = (UUIDGroupNameRequestPacket) Pack;
  2788. for (int i=0;i< upack.UUIDNameBlock.Length; i++)
  2789. {
  2790. handlerUUIDGroupNameRequest = OnUUIDGroupNameRequest;
  2791. if (handlerUUIDGroupNameRequest != null)
  2792. {
  2793. handlerUUIDGroupNameRequest(upack.UUIDNameBlock[i].ID,this);
  2794. }
  2795. }
  2796. return true;
  2797. }
  2798. public bool HandleObjectGroupRequest(IClientAPI sender, Packet Pack)
  2799. {
  2800. ObjectGroupPacket ogpack = (ObjectGroupPacket)Pack;
  2801. handlerObjectGroupRequest = OnObjectGroupRequest;
  2802. if (handlerObjectGroupRequest != null)
  2803. {
  2804. for (int i = 0; i < ogpack.ObjectData.Length; i++)
  2805. {
  2806. handlerObjectGroupRequest(this, ogpack.AgentData.GroupID, ogpack.ObjectData[i].ObjectLocalID, LLUUID.Zero);
  2807. }
  2808. }
  2809. return true;
  2810. }
  2811. private bool HandleViewerEffect(IClientAPI sender, Packet Pack)
  2812. {
  2813. ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
  2814. handlerViewerEffect = OnViewerEffect;
  2815. if (handlerViewerEffect != null)
  2816. {
  2817. int length = viewer.Effect.Length;
  2818. List<ViewerEffectEventHandlerArg> args = new List<ViewerEffectEventHandlerArg>(length);
  2819. for (int i = 0; i < length; i++)
  2820. {
  2821. //copy the effects block arguments into the event handler arg.
  2822. ViewerEffectEventHandlerArg argument = new ViewerEffectEventHandlerArg();
  2823. argument.AgentID = viewer.Effect[i].AgentID;
  2824. argument.Color = viewer.Effect[i].Color;
  2825. argument.Duration = viewer.Effect[i].Duration;
  2826. argument.ID = viewer.Effect[i].ID;
  2827. argument.Type = viewer.Effect[i].Type;
  2828. argument.TypeData = viewer.Effect[i].TypeData;
  2829. args.Add(argument);
  2830. }
  2831. handlerViewerEffect(sender, args);
  2832. }
  2833. return true;
  2834. }
  2835. public void SendScriptQuestion(LLUUID taskID, string taskName, string ownerName, LLUUID itemID, int question)
  2836. {
  2837. ScriptQuestionPacket scriptQuestion = (ScriptQuestionPacket)PacketPool.Instance.GetPacket(PacketType.ScriptQuestion);
  2838. scriptQuestion.Data = new ScriptQuestionPacket.DataBlock();
  2839. // TODO: don't create new blocks if recycling an old packet
  2840. scriptQuestion.Data.TaskID = taskID;
  2841. scriptQuestion.Data.ItemID = itemID;
  2842. scriptQuestion.Data.Questions = question;
  2843. scriptQuestion.Data.ObjectName = Helpers.StringToField(taskName);
  2844. scriptQuestion.Data.ObjectOwner = Helpers.StringToField(ownerName);
  2845. OutPacket(scriptQuestion, ThrottleOutPacketType.Task);
  2846. }
  2847. private void InitDefaultAnimations()
  2848. {
  2849. }
  2850. public LLUUID GetDefaultAnimation(string name)
  2851. {
  2852. if (m_defaultAnimations.ContainsKey(name))
  2853. return m_defaultAnimations[name];
  2854. return LLUUID.Zero;
  2855. }
  2856. protected virtual bool Logout(IClientAPI client, Packet packet)
  2857. {
  2858. m_log.Info("[CLIENT]: Got a logout request");
  2859. handlerLogout = OnLogout;
  2860. if (handlerLogout != null)
  2861. {
  2862. handlerLogout(client);
  2863. }
  2864. return true;
  2865. }
  2866. /// <summary>
  2867. /// Send a response back to a client when it asks the asset server (via the region server) if it has
  2868. /// its appearance texture cached.
  2869. ///
  2870. /// At the moment, we always reply that there is no cached texture.
  2871. /// </summary>
  2872. /// <param name="simclient"></param>
  2873. /// <param name="packet"></param>
  2874. /// <returns></returns>
  2875. protected bool AgentTextureCached(IClientAPI simclient, Packet packet)
  2876. {
  2877. //Console.WriteLine("texture cached: " + packet.ToString());
  2878. AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet;
  2879. AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
  2880. // TODO: don't create new blocks if recycling an old packet
  2881. cachedresp.AgentData.AgentID = AgentId;
  2882. cachedresp.AgentData.SessionID = m_sessionId;
  2883. cachedresp.AgentData.SerialNum = m_cachedTextureSerial;
  2884. m_cachedTextureSerial++;
  2885. cachedresp.WearableData =
  2886. new AgentCachedTextureResponsePacket.WearableDataBlock[cachedtex.WearableData.Length];
  2887. for (int i = 0; i < cachedtex.WearableData.Length; i++)
  2888. {
  2889. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  2890. cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
  2891. cachedresp.WearableData[i].TextureID = LLUUID.Zero;
  2892. cachedresp.WearableData[i].HostName = new byte[0];
  2893. }
  2894. // Temporarily throw these packets on to the wind queue, so we can identify whether these
  2895. // are somehow the source of the packet bloat.
  2896. cachedresp.Header.Zerocoded = true;
  2897. OutPacket(cachedresp, ThrottleOutPacketType.Wind);
  2898. return true;
  2899. }
  2900. protected bool MultipleObjUpdate(IClientAPI simClient, Packet packet)
  2901. {
  2902. MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
  2903. // Console.WriteLine("new multi update packet " + multipleupdate.ToString());
  2904. Scene tScene = (Scene)m_scene;
  2905. for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
  2906. {
  2907. MultipleObjectUpdatePacket.ObjectDataBlock block = multipleupdate.ObjectData[i];
  2908. // Can't act on Null Data
  2909. if (block.Data != null)
  2910. {
  2911. uint localId = block.ObjectLocalID;
  2912. SceneObjectPart part = tScene.GetSceneObjectPart(localId);
  2913. if (part == null)
  2914. {
  2915. // It's a ghost! tell the client to delete it from view.
  2916. simClient.SendKillObject(Scene.RegionInfo.RegionHandle,
  2917. localId);
  2918. }
  2919. else
  2920. {
  2921. LLUUID partId = part.UUID;
  2922. UpdatePrimRotation handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
  2923. UpdatePrimGroupRotation handlerUpdatePrimGroupRotation = OnUpdatePrimGroupMouseRotation;
  2924. switch (block.Type)
  2925. {
  2926. case 1:
  2927. LLVector3 pos1 = new LLVector3(block.Data, 0);
  2928. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  2929. if (handlerUpdatePrimSinglePosition != null)
  2930. {
  2931. // Console.WriteLine("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
  2932. handlerUpdatePrimSinglePosition(localId, pos1, this);
  2933. }
  2934. break;
  2935. case 2:
  2936. LLQuaternion rot1 = new LLQuaternion(block.Data, 0, true);
  2937. handlerUpdatePrimSingleRotation = OnUpdatePrimSingleRotation;
  2938. if (handlerUpdatePrimSingleRotation != null)
  2939. {
  2940. //Console.WriteLine("new tab rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  2941. handlerUpdatePrimSingleRotation(localId, rot1, this);
  2942. }
  2943. break;
  2944. case 3:
  2945. LLQuaternion rot2 = new LLQuaternion(block.Data, 12, true);
  2946. handlerUpdatePrimSingleRotation = OnUpdatePrimSingleRotation;
  2947. if (handlerUpdatePrimSingleRotation != null)
  2948. {
  2949. //Console.WriteLine("new mouse rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  2950. handlerUpdatePrimSingleRotation(localId, rot2, this);
  2951. }
  2952. break;
  2953. case 5:
  2954. LLVector3 scale1 = new LLVector3(block.Data, 12);
  2955. LLVector3 pos11 = new LLVector3(block.Data, 0);
  2956. handlerUpdatePrimScale = OnUpdatePrimScale;
  2957. if (handlerUpdatePrimScale != null)
  2958. {
  2959. // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  2960. handlerUpdatePrimScale(localId, scale1, this);
  2961. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  2962. if (handlerUpdatePrimSinglePosition != null)
  2963. {
  2964. handlerUpdatePrimSinglePosition(localId, pos11, this);
  2965. }
  2966. }
  2967. break;
  2968. case 9:
  2969. LLVector3 pos2 = new LLVector3(block.Data, 0);
  2970. handlerUpdateVector = OnUpdatePrimGroupPosition;
  2971. if (handlerUpdateVector != null)
  2972. {
  2973. handlerUpdateVector(localId, pos2, this);
  2974. }
  2975. break;
  2976. case 10:
  2977. LLQuaternion rot3 = new LLQuaternion(block.Data, 0, true);
  2978. handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
  2979. if (handlerUpdatePrimRotation != null)
  2980. {
  2981. // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  2982. handlerUpdatePrimRotation(localId, rot3, this);
  2983. }
  2984. break;
  2985. case 11:
  2986. LLVector3 pos3 = new LLVector3(block.Data, 0);
  2987. LLQuaternion rot4 = new LLQuaternion(block.Data, 12, true);
  2988. handlerUpdatePrimGroupRotation = OnUpdatePrimGroupMouseRotation;
  2989. if (handlerUpdatePrimGroupRotation != null)
  2990. {
  2991. //Console.WriteLine("new rotation position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
  2992. // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  2993. handlerUpdatePrimGroupRotation(localId, pos3, rot4, this);
  2994. }
  2995. break;
  2996. case 13:
  2997. LLVector3 scale2 = new LLVector3(block.Data, 12);
  2998. LLVector3 pos4 = new LLVector3(block.Data, 0);
  2999. handlerUpdatePrimScale = OnUpdatePrimScale;
  3000. if (handlerUpdatePrimScale != null)
  3001. {
  3002. //Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  3003. handlerUpdatePrimScale(localId, scale2, this);
  3004. // Change the position based on scale (for bug number 246)
  3005. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  3006. // Console.WriteLine("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
  3007. if (handlerUpdatePrimSinglePosition != null)
  3008. {
  3009. handlerUpdatePrimSinglePosition(localId, pos4, this);
  3010. }
  3011. }
  3012. break;
  3013. case 29:
  3014. LLVector3 scale5 = new LLVector3(block.Data, 12);
  3015. LLVector3 pos5 = new LLVector3(block.Data, 0);
  3016. handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale;
  3017. if (handlerUpdatePrimGroupScale != null)
  3018. {
  3019. // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  3020. handlerUpdatePrimGroupScale(localId, scale5, this);
  3021. handlerUpdateVector = OnUpdatePrimGroupPosition;
  3022. if (handlerUpdateVector != null)
  3023. {
  3024. handlerUpdateVector(localId, pos5, this);
  3025. }
  3026. }
  3027. break;
  3028. case 21:
  3029. LLVector3 scale6 = new LLVector3(block.Data, 12);
  3030. LLVector3 pos6 = new LLVector3(block.Data, 0);
  3031. handlerUpdatePrimScale = OnUpdatePrimScale;
  3032. if (handlerUpdatePrimScale != null)
  3033. {
  3034. // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  3035. handlerUpdatePrimScale(localId, scale6, this);
  3036. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  3037. if (handlerUpdatePrimSinglePosition != null)
  3038. {
  3039. handlerUpdatePrimSinglePosition(localId, pos6, this);
  3040. }
  3041. }
  3042. break;
  3043. }
  3044. }
  3045. }
  3046. }
  3047. return true;
  3048. }
  3049. public void RequestMapLayer()
  3050. {
  3051. //should be getting the map layer from the grid server
  3052. //send a layer covering the 800,800 - 1200,1200 area (should be covering the requested area)
  3053. MapLayerReplyPacket mapReply = (MapLayerReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapLayerReply);
  3054. // TODO: don't create new blocks if recycling an old packet
  3055. mapReply.AgentData.AgentID = AgentId;
  3056. mapReply.AgentData.Flags = 0;
  3057. mapReply.LayerData = new MapLayerReplyPacket.LayerDataBlock[1];
  3058. mapReply.LayerData[0] = new MapLayerReplyPacket.LayerDataBlock();
  3059. mapReply.LayerData[0].Bottom = 0;
  3060. mapReply.LayerData[0].Left = 0;
  3061. mapReply.LayerData[0].Top = 30000;
  3062. mapReply.LayerData[0].Right = 30000;
  3063. mapReply.LayerData[0].ImageID = new LLUUID("00000000-0000-1111-9999-000000000006");
  3064. mapReply.Header.Zerocoded = true;
  3065. OutPacket(mapReply, ThrottleOutPacketType.Land);
  3066. }
  3067. public void RequestMapBlocksX(int minX, int minY, int maxX, int maxY)
  3068. {
  3069. /*
  3070. IList simMapProfiles = m_gridServer.RequestMapBlocks(minX, minY, maxX, maxY);
  3071. MapBlockReplyPacket mbReply = new MapBlockReplyPacket();
  3072. mbReply.AgentData.AgentId = this.AgentId;
  3073. int len;
  3074. if (simMapProfiles == null)
  3075. len = 0;
  3076. else
  3077. len = simMapProfiles.Count;
  3078. mbReply.Data = new MapBlockReplyPacket.DataBlock[len];
  3079. int iii;
  3080. for (iii = 0; iii < len; iii++)
  3081. {
  3082. Hashtable mp = (Hashtable)simMapProfiles[iii];
  3083. mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock();
  3084. mbReply.Data[iii].Name = System.Text.Encoding.UTF8.GetBytes((string)mp["name"]);
  3085. mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]);
  3086. mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]);
  3087. mbReply.Data[iii].MapImageID = new LLUUID((string)mp["map-image-id"]);
  3088. mbReply.Data[iii].RegionFlags = System.Convert.ToUInt32(mp["region-flags"]);
  3089. mbReply.Data[iii].WaterHeight = System.Convert.ToByte(mp["water-height"]);
  3090. mbReply.Data[iii].X = System.Convert.ToUInt16(mp["x"]);
  3091. mbReply.Data[iii].Y = System.Convert.ToUInt16(mp["y"]);
  3092. }
  3093. this.OutPacket(mbReply, ThrottleOutPacketType.Land);
  3094. */
  3095. }
  3096. public byte[] GetThrottlesPacked(float multiplier)
  3097. {
  3098. return m_packetQueue.GetThrottlesPacked(multiplier);
  3099. }
  3100. public void SetChildAgentThrottle(byte[] throttles)
  3101. {
  3102. m_packetQueue.SetThrottleFromClient(throttles);
  3103. }
  3104. // Previously ClientView.m_packetQueue
  3105. // A thread safe sequence number allocator.
  3106. protected uint NextSeqNum()
  3107. {
  3108. // Set the sequence number
  3109. uint seq = 1;
  3110. lock (m_sequenceLock)
  3111. {
  3112. if (m_sequence >= MAX_SEQUENCE)
  3113. {
  3114. m_sequence = 1;
  3115. }
  3116. else
  3117. {
  3118. m_sequence++;
  3119. }
  3120. seq = m_sequence;
  3121. }
  3122. return seq;
  3123. }
  3124. protected void AddAck(Packet Pack)
  3125. {
  3126. lock (m_needAck)
  3127. {
  3128. if (!m_needAck.ContainsKey(Pack.Header.Sequence))
  3129. {
  3130. try
  3131. {
  3132. m_needAck.Add(Pack.Header.Sequence, Pack);
  3133. m_unAckedBytes += Pack.ToBytes().Length;
  3134. }
  3135. //BUG: severity=major - This looks like a framework bug!?
  3136. catch (Exception) // HACKY
  3137. {
  3138. // Ignore
  3139. // Seems to throw a exception here occasionally
  3140. // of 'duplicate key' despite being locked.
  3141. // !?!?!?
  3142. }
  3143. }
  3144. else
  3145. {
  3146. // Client.Log("Attempted to add a duplicate sequence number (" +
  3147. // packet.Header.m_sequence + ") to the m_needAck dictionary for packet type " +
  3148. // packet.Type.ToString(), Helpers.LogLevel.Warning);
  3149. }
  3150. }
  3151. }
  3152. protected virtual void SetPendingAcks(ref Packet Pack)
  3153. {
  3154. // Append any ACKs that need to be sent out to this packet
  3155. lock (m_pendingAcks)
  3156. {
  3157. // TODO: If we are over MAX_APPENDED_ACKS we should drain off some of these
  3158. if (m_pendingAcks.Count > 0 && m_pendingAcks.Count < MAX_APPENDED_ACKS)
  3159. {
  3160. Pack.Header.AckList = new uint[m_pendingAcks.Count];
  3161. int i = 0;
  3162. foreach (uint ack in m_pendingAcks.Values)
  3163. {
  3164. Pack.Header.AckList[i] = ack;
  3165. i++;
  3166. }
  3167. m_pendingAcks.Clear();
  3168. Pack.Header.AppendedAcks = true;
  3169. }
  3170. }
  3171. }
  3172. protected virtual void ProcessOutPacket(Packet Pack)
  3173. {
  3174. // Keep track of when this packet was sent out
  3175. Pack.TickCount = System.Environment.TickCount;
  3176. if (!Pack.Header.Resent)
  3177. {
  3178. Pack.Header.Sequence = NextSeqNum();
  3179. if (Pack.Header.Reliable) //DIRTY HACK
  3180. {
  3181. AddAck(Pack); // this adds the need to ack this packet later
  3182. if (Pack.Type != PacketType.PacketAck && Pack.Type != PacketType.LogoutRequest)
  3183. {
  3184. SetPendingAcks(ref Pack);
  3185. }
  3186. }
  3187. }
  3188. // Actually make the byte array and send it
  3189. try
  3190. {
  3191. byte[] sendbuffer = Pack.ToBytes();
  3192. PacketPool.Instance.ReturnPacket(Pack);
  3193. if (Pack.Header.Zerocoded)
  3194. {
  3195. int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
  3196. m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, m_circuitCode);
  3197. }
  3198. else
  3199. {
  3200. //Need some extra space in case we need to add proxy information to the message later
  3201. Buffer.BlockCopy(sendbuffer, 0, ZeroOutBuffer, 0, sendbuffer.Length);
  3202. m_networkServer.SendPacketTo(ZeroOutBuffer, sendbuffer.Length, SocketFlags.None, m_circuitCode);
  3203. }
  3204. }
  3205. catch (Exception e)
  3206. {
  3207. m_log.Warn("[client]: " +
  3208. "ClientView.m_packetQueue.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " +
  3209. m_userEndPoint.ToString() + " - killing thread");
  3210. m_log.Error(e.ToString());
  3211. Close(true);
  3212. }
  3213. }
  3214. public virtual void InPacket(Packet NewPack)
  3215. {
  3216. if (!m_packetProcessingEnabled && NewPack.Type != PacketType.LogoutRequest)
  3217. {
  3218. PacketPool.Instance.ReturnPacket(NewPack);
  3219. return;
  3220. }
  3221. // Handle appended ACKs
  3222. if (NewPack != null)
  3223. {
  3224. if (NewPack.Header.AppendedAcks)
  3225. {
  3226. lock (m_needAck)
  3227. {
  3228. foreach (uint ackedPacketId in NewPack.Header.AckList)
  3229. {
  3230. Packet ackedPacket;
  3231. if (m_needAck.TryGetValue(ackedPacketId, out ackedPacket))
  3232. {
  3233. m_unAckedBytes -= ackedPacket.ToBytes().Length;
  3234. m_needAck.Remove(ackedPacketId);
  3235. }
  3236. }
  3237. }
  3238. }
  3239. // Handle PacketAck packets
  3240. if (NewPack.Type == PacketType.PacketAck)
  3241. {
  3242. PacketAckPacket ackPacket = (PacketAckPacket)NewPack;
  3243. lock (m_needAck)
  3244. {
  3245. foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets)
  3246. {
  3247. uint ackedPackId = block.ID;
  3248. Packet ackedPacket;
  3249. if (m_needAck.TryGetValue(ackedPackId, out ackedPacket))
  3250. {
  3251. m_unAckedBytes -= ackedPacket.ToBytes().Length;
  3252. m_needAck.Remove(ackedPackId);
  3253. }
  3254. }
  3255. }
  3256. }
  3257. else if ((NewPack.Type == PacketType.StartPingCheck))
  3258. {
  3259. //reply to pingcheck
  3260. StartPingCheckPacket startPing = (StartPingCheckPacket)NewPack;
  3261. CompletePingCheckPacket endPing = (CompletePingCheckPacket)PacketPool.Instance.GetPacket(PacketType.CompletePingCheck);
  3262. endPing.PingID.PingID = startPing.PingID.PingID;
  3263. OutPacket(endPing, ThrottleOutPacketType.Task);
  3264. }
  3265. else
  3266. {
  3267. LLQueItem item = new LLQueItem();
  3268. item.Packet = NewPack;
  3269. item.Incoming = true;
  3270. m_packetQueue.Enqueue(item);
  3271. }
  3272. }
  3273. }
  3274. public virtual void OutPacket(Packet NewPack, ThrottleOutPacketType throttlePacketType)
  3275. {
  3276. if ((SynchronizeClient != null) && (!IsActive))
  3277. {
  3278. // Sending packet to active client's server.
  3279. if (SynchronizeClient(m_scene, NewPack, m_agentId, throttlePacketType))
  3280. {
  3281. return;
  3282. }
  3283. }
  3284. LLQueItem item = new LLQueItem();
  3285. item.Packet = NewPack;
  3286. item.Incoming = false;
  3287. item.throttleType = throttlePacketType; // Packet throttle type
  3288. m_packetQueue.Enqueue(item);
  3289. m_packetsSent++;
  3290. }
  3291. # region Low Level Packet Methods
  3292. protected void ack_pack(Packet Pack)
  3293. {
  3294. if (Pack.Header.Reliable)
  3295. {
  3296. PacketAckPacket ack_it = (PacketAckPacket)PacketPool.Instance.GetPacket(PacketType.PacketAck);
  3297. // TODO: don't create new blocks if recycling an old packet
  3298. ack_it.Packets = new PacketAckPacket.PacketsBlock[1];
  3299. ack_it.Packets[0] = new PacketAckPacket.PacketsBlock();
  3300. ack_it.Packets[0].ID = Pack.Header.Sequence;
  3301. ack_it.Header.Reliable = false;
  3302. OutPacket(ack_it, ThrottleOutPacketType.Unknown);
  3303. }
  3304. /*
  3305. if (Pack.Header.Reliable)
  3306. {
  3307. lock (m_pendingAcks)
  3308. {
  3309. uint sequence = (uint)Pack.Header.m_sequence;
  3310. if (!m_pendingAcks.ContainsKey(sequence)) { m_pendingAcks[sequence] = sequence; }
  3311. }
  3312. }*/
  3313. }
  3314. protected void ResendUnacked()
  3315. {
  3316. int now = System.Environment.TickCount;
  3317. lock (m_needAck)
  3318. {
  3319. foreach (Packet packet in m_needAck.Values)
  3320. {
  3321. if ((now - packet.TickCount > RESEND_TIMEOUT) && (!packet.Header.Resent))
  3322. {
  3323. //m_log.Debug("[NETWORK]: Resending " + packet.Type.ToString() + " packet, " +
  3324. //(now - packet.TickCount) + "ms have passed");
  3325. packet.Header.Resent = true;
  3326. OutPacket(packet, ThrottleOutPacketType.Resend);
  3327. }
  3328. }
  3329. }
  3330. }
  3331. protected void SendAcks()
  3332. {
  3333. lock (m_pendingAcks)
  3334. {
  3335. if (m_pendingAcks.Count > 0)
  3336. {
  3337. if (m_pendingAcks.Count > 250)
  3338. {
  3339. // FIXME: Handle the odd case where we have too many pending ACKs queued up
  3340. m_log.Info("[NETWORK]: Too many ACKs queued up!");
  3341. return;
  3342. }
  3343. //m_log.Info("[NETWORK]: Sending PacketAck");
  3344. int i = 0;
  3345. PacketAckPacket acks = (PacketAckPacket)PacketPool.Instance.GetPacket(PacketType.PacketAck);
  3346. // TODO: don't create new blocks if recycling an old packet
  3347. acks.Packets = new PacketAckPacket.PacketsBlock[m_pendingAcks.Count];
  3348. foreach (uint ack in m_pendingAcks.Values)
  3349. {
  3350. acks.Packets[i] = new PacketAckPacket.PacketsBlock();
  3351. acks.Packets[i].ID = ack;
  3352. i++;
  3353. }
  3354. acks.Header.Reliable = false;
  3355. OutPacket(acks, ThrottleOutPacketType.Unknown);
  3356. m_pendingAcks.Clear();
  3357. }
  3358. }
  3359. }
  3360. protected void AckTimer_Elapsed(object sender, ElapsedEventArgs ea)
  3361. {
  3362. SendAcks();
  3363. ResendUnacked();
  3364. SendPacketStats();
  3365. }
  3366. protected void SendPacketStats()
  3367. {
  3368. handlerPacketStats = OnPacketStats;
  3369. if (handlerPacketStats != null)
  3370. {
  3371. handlerPacketStats(m_packetsReceived - m_lastPacketsReceivedSentToScene, m_packetsSent - m_lastPacketsSentSentToScene, m_unAckedBytes);
  3372. m_lastPacketsReceivedSentToScene = m_packetsReceived;
  3373. m_lastPacketsSentSentToScene = m_packetsSent;
  3374. }
  3375. }
  3376. protected void ClearOldPacketDupeTracking()
  3377. {
  3378. lock (m_dupeLimiter)
  3379. {
  3380. List<uint> toEliminate = new List<uint>();
  3381. try
  3382. {
  3383. foreach (uint seq in m_dupeLimiter.Keys)
  3384. {
  3385. PacketDupeLimiter pkdata = null;
  3386. m_dupeLimiter.TryGetValue(seq, out pkdata);
  3387. if (pkdata != null)
  3388. {
  3389. // doing a foreach loop, so we don't want to modify the dictionary while we're searching it
  3390. if (Util.UnixTimeSinceEpoch() - pkdata.timeIn > m_clearDuplicatePacketTrackingOlderThenXSeconds)
  3391. toEliminate.Add(seq);
  3392. }
  3393. }
  3394. }
  3395. catch (InvalidOperationException)
  3396. {
  3397. m_log.Info("[PACKET]: Unable to clear dupe check packet data");
  3398. }
  3399. // remove the dupe packets that we detected in the loop above.
  3400. uint[] seqsToRemove = toEliminate.ToArray();
  3401. for (int i = 0; i<seqsToRemove.Length; i++)
  3402. {
  3403. if (m_dupeLimiter.ContainsKey(seqsToRemove[i]))
  3404. m_dupeLimiter.Remove(seqsToRemove[i]);
  3405. }
  3406. }
  3407. }
  3408. #endregion
  3409. // Previously ClientView.ProcessPackets
  3410. public bool AddMoney(int debit)
  3411. {
  3412. if (m_moneyBalance + debit >= 0)
  3413. {
  3414. m_moneyBalance += debit;
  3415. SendMoneyBalance(LLUUID.Zero, true, Helpers.StringToField("Poof Poof!"), m_moneyBalance);
  3416. return true;
  3417. }
  3418. else
  3419. {
  3420. return false;
  3421. }
  3422. }
  3423. private bool m_packetProcessingEnabled = true;
  3424. public bool IsActive {
  3425. get { return m_packetProcessingEnabled; }
  3426. set { m_packetProcessingEnabled = value; }
  3427. }
  3428. protected void ProcessInPacket(Packet Pack)
  3429. {
  3430. ack_pack(Pack);
  3431. lock (m_dupeLimiter)
  3432. {
  3433. if (m_dupeLimiter.ContainsKey(Pack.Header.Sequence))
  3434. {
  3435. m_log.Info("[CLIENT]: Warning Duplicate packet detected" + Pack.Type.ToString() + " Dropping.");
  3436. return;
  3437. }
  3438. else
  3439. {
  3440. PacketDupeLimiter pkdedupe = new PacketDupeLimiter();
  3441. pkdedupe.packetId = Pack.Header.ID;
  3442. pkdedupe.pktype = Pack.Type;
  3443. pkdedupe.timeIn = Util.UnixTimeSinceEpoch();
  3444. m_dupeLimiter.Add(Pack.Header.Sequence, pkdedupe);
  3445. }
  3446. }
  3447. //m_log.Info("Sequence"
  3448. if (ProcessPacketMethod(Pack))
  3449. {
  3450. //there is a handler registered that handled this packet type
  3451. return;
  3452. }
  3453. else
  3454. {
  3455. switch (Pack.Type)
  3456. {
  3457. #region Scene/Avatar
  3458. case PacketType.AvatarPropertiesRequest:
  3459. AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;
  3460. handlerRequestAvatarProperties = OnRequestAvatarProperties;
  3461. if (handlerRequestAvatarProperties != null)
  3462. {
  3463. handlerRequestAvatarProperties(this, avatarProperties.AgentData.AvatarID);
  3464. }
  3465. break;
  3466. case PacketType.ChatFromViewer:
  3467. ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
  3468. string fromName = String.Empty; //ClientAvatar.firstname + " " + ClientAvatar.lastname;
  3469. byte[] message = inchatpack.ChatData.Message;
  3470. byte type = inchatpack.ChatData.Type;
  3471. LLVector3 fromPos = new LLVector3(); // ClientAvatar.Pos;
  3472. LLUUID fromAgentID = AgentId;
  3473. int channel = inchatpack.ChatData.Channel;
  3474. if (OnChatFromViewer != null)
  3475. {
  3476. ChatFromViewerArgs args = new ChatFromViewerArgs();
  3477. args.Channel = channel;
  3478. args.From = fromName;
  3479. args.Message = Helpers.FieldToUTF8String(message);
  3480. args.Type = (ChatTypeEnum)type;
  3481. args.Position = fromPos;
  3482. args.Scene = Scene;
  3483. args.Sender = this;
  3484. handlerChatFromViewer = OnChatFromViewer;
  3485. if (handlerChatFromViewer != null)
  3486. handlerChatFromViewer(this, args);
  3487. }
  3488. break;
  3489. case PacketType.AvatarPropertiesUpdate:
  3490. AvatarPropertiesUpdatePacket Packet = (AvatarPropertiesUpdatePacket)Pack;
  3491. handlerUpdateAvatarProperties = OnUpdateAvatarProperties;
  3492. if (handlerUpdateAvatarProperties != null)
  3493. {
  3494. AvatarPropertiesUpdatePacket.PropertiesDataBlock Properties = Packet.PropertiesData;
  3495. UserProfileData UserProfile = new UserProfileData();
  3496. UserProfile.ID = AgentId;
  3497. UserProfile.AboutText = Helpers.FieldToUTF8String(Properties.AboutText);
  3498. UserProfile.FirstLifeAboutText = Helpers.FieldToUTF8String(Properties.FLAboutText);
  3499. UserProfile.FirstLifeImage = Properties.FLImageID;
  3500. UserProfile.Image = Properties.ImageID;
  3501. handlerUpdateAvatarProperties(this, UserProfile);
  3502. }
  3503. break;
  3504. case PacketType.ScriptDialogReply:
  3505. ScriptDialogReplyPacket rdialog = (ScriptDialogReplyPacket)Pack;
  3506. int ch = rdialog.Data.ChatChannel;
  3507. byte[] msg = rdialog.Data.ButtonLabel;
  3508. if (OnChatFromViewer != null)
  3509. {
  3510. ChatFromViewerArgs args = new ChatFromViewerArgs();
  3511. args.Channel = ch;
  3512. args.From = String.Empty;
  3513. args.Message = Helpers.FieldToUTF8String(msg);
  3514. args.Type = ChatTypeEnum.Shout;
  3515. args.Position = new LLVector3();
  3516. args.Scene = Scene;
  3517. args.Sender = this;
  3518. handlerChatFromViewer2 = OnChatFromViewer;
  3519. if (handlerChatFromViewer2 != null)
  3520. handlerChatFromViewer2(this, args);
  3521. }
  3522. break;
  3523. case PacketType.ImprovedInstantMessage:
  3524. ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack;
  3525. string IMfromName = Util.FieldToString(msgpack.MessageBlock.FromAgentName);
  3526. string IMmessage = Helpers.FieldToUTF8String(msgpack.MessageBlock.Message);
  3527. handlerInstantMessage = OnInstantMessage;
  3528. if (handlerInstantMessage != null)
  3529. {
  3530. handlerInstantMessage(this, msgpack.AgentData.AgentID, msgpack.AgentData.SessionID,
  3531. msgpack.MessageBlock.ToAgentID, msgpack.MessageBlock.ID,
  3532. msgpack.MessageBlock.Timestamp, IMfromName, IMmessage,
  3533. msgpack.MessageBlock.Dialog, msgpack.MessageBlock.FromGroup,
  3534. msgpack.MessageBlock.Offline, msgpack.MessageBlock.ParentEstateID,
  3535. msgpack.MessageBlock.Position, msgpack.MessageBlock.RegionID,
  3536. msgpack.MessageBlock.BinaryBucket);
  3537. }
  3538. break;
  3539. case PacketType.AcceptFriendship:
  3540. AcceptFriendshipPacket afriendpack = (AcceptFriendshipPacket)Pack;
  3541. // My guess is this is the folder to stick the calling card into
  3542. List<LLUUID> callingCardFolders = new List<LLUUID>();
  3543. LLUUID agentID = afriendpack.AgentData.AgentID;
  3544. LLUUID transactionID = afriendpack.TransactionBlock.TransactionID;
  3545. for (int fi = 0; fi < afriendpack.FolderData.Length; fi++)
  3546. {
  3547. callingCardFolders.Add(afriendpack.FolderData[fi].FolderID);
  3548. }
  3549. handlerApproveFriendRequest = OnApproveFriendRequest;
  3550. if (handlerApproveFriendRequest != null)
  3551. {
  3552. handlerApproveFriendRequest(this, agentID, transactionID, callingCardFolders);
  3553. }
  3554. break;
  3555. case PacketType.TerminateFriendship:
  3556. TerminateFriendshipPacket tfriendpack = (TerminateFriendshipPacket)Pack;
  3557. LLUUID listOwnerAgentID = tfriendpack.AgentData.AgentID;
  3558. LLUUID exFriendID = tfriendpack.ExBlock.OtherID;
  3559. handlerTerminateFriendship = OnTerminateFriendship;
  3560. if (handlerTerminateFriendship != null)
  3561. {
  3562. handlerTerminateFriendship(this, listOwnerAgentID, exFriendID);
  3563. }
  3564. break;
  3565. case PacketType.RezObject:
  3566. RezObjectPacket rezPacket = (RezObjectPacket)Pack;
  3567. handlerRezObject = OnRezObject;
  3568. if (handlerRezObject != null)
  3569. {
  3570. //rezPacket.RezData.BypassRaycast;
  3571. //rezPacket.RezData.RayEnd;
  3572. //rezPacket.RezData.RayEndIsIntersection;
  3573. //rezPacket.RezData.RayStart;
  3574. //rezPacket.RezData.RayTargetID;
  3575. //rezPacket.RezData.RemoveItem;
  3576. //rezPacket.RezData.RezSelected;
  3577. //rezPacket.RezData.FromTaskID;
  3578. //m_log.Info("[REZData]: " + rezPacket.ToString());
  3579. handlerRezObject(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd,
  3580. rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID,
  3581. rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection,
  3582. rezPacket.RezData.EveryoneMask, rezPacket.RezData.GroupMask,
  3583. rezPacket.RezData.NextOwnerMask, rezPacket.RezData.ItemFlags,
  3584. rezPacket.RezData.RezSelected, rezPacket.RezData.RemoveItem,
  3585. rezPacket.RezData.FromTaskID);
  3586. }
  3587. break;
  3588. case PacketType.DeRezObject:
  3589. handlerDeRezObject = OnDeRezObject;
  3590. if (handlerDeRezObject != null)
  3591. {
  3592. handlerDeRezObject(Pack, this);
  3593. }
  3594. break;
  3595. case PacketType.ModifyLand:
  3596. ModifyLandPacket modify = (ModifyLandPacket)Pack;
  3597. //m_log.Info("[LAND]: LAND:" + modify.ToString());
  3598. if (modify.ParcelData.Length > 0)
  3599. {
  3600. if (OnModifyTerrain != null)
  3601. {
  3602. for (int i = 0; i < modify.ParcelData.Length; i++)
  3603. {
  3604. handlerModifyTerrain = OnModifyTerrain;
  3605. if (handlerModifyTerrain != null)
  3606. {
  3607. handlerModifyTerrain(modify.ModifyBlock.Height, modify.ModifyBlock.Seconds,
  3608. modify.ModifyBlock.BrushSize,
  3609. modify.ModifyBlock.Action, modify.ParcelData[i].North,
  3610. modify.ParcelData[i].West, modify.ParcelData[i].South,
  3611. modify.ParcelData[i].East, this);
  3612. }
  3613. }
  3614. }
  3615. }
  3616. break;
  3617. case PacketType.RegionHandshakeReply:
  3618. handlerRegionHandShakeReply = OnRegionHandShakeReply;
  3619. if (handlerRegionHandShakeReply != null)
  3620. {
  3621. handlerRegionHandShakeReply(this);
  3622. }
  3623. break;
  3624. case PacketType.AgentWearablesRequest:
  3625. handlerRequestWearables = OnRequestWearables;
  3626. if (handlerRequestWearables != null)
  3627. {
  3628. handlerRequestWearables();
  3629. }
  3630. handlerRequestAvatarsData = OnRequestAvatarsData;
  3631. if (handlerRequestAvatarsData != null)
  3632. {
  3633. handlerRequestAvatarsData(this);
  3634. }
  3635. break;
  3636. case PacketType.AgentSetAppearance:
  3637. AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
  3638. handlerSetAppearance = OnSetAppearance;
  3639. if (handlerSetAppearance != null)
  3640. {
  3641. // Temporarily protect ourselves from the mantis #951 failure.
  3642. // However, we could do this for several other handlers where a failure isn't terminal
  3643. // for the client session anyway, in order to protect ourselves against bad code in plugins
  3644. try
  3645. {
  3646. List<byte> visualparams = new List<byte>();
  3647. foreach (AgentSetAppearancePacket.VisualParamBlock x in appear.VisualParam)
  3648. {
  3649. visualparams.Add(x.ParamValue);
  3650. }
  3651. handlerSetAppearance(appear.ObjectData.TextureEntry, visualparams);
  3652. }
  3653. catch (Exception e)
  3654. {
  3655. m_log.ErrorFormat(
  3656. "[CLIENT VIEW]: AgentSetApperance packet handler threw an exception, {0}",
  3657. e);
  3658. }
  3659. }
  3660. break;
  3661. case PacketType.AgentIsNowWearing:
  3662. if (OnAvatarNowWearing != null)
  3663. {
  3664. AgentIsNowWearingPacket nowWearing = (AgentIsNowWearingPacket)Pack;
  3665. AvatarWearingArgs wearingArgs = new AvatarWearingArgs();
  3666. for (int i = 0; i < nowWearing.WearableData.Length; i++)
  3667. {
  3668. AvatarWearingArgs.Wearable wearable =
  3669. new AvatarWearingArgs.Wearable(nowWearing.WearableData[i].ItemID,
  3670. nowWearing.WearableData[i].WearableType);
  3671. wearingArgs.NowWearing.Add(wearable);
  3672. }
  3673. handlerAvatarNowWearing = OnAvatarNowWearing;
  3674. if (handlerAvatarNowWearing != null)
  3675. {
  3676. handlerAvatarNowWearing(this, wearingArgs);
  3677. }
  3678. }
  3679. break;
  3680. case PacketType.RezSingleAttachmentFromInv:
  3681. handlerRezSingleAttachment = OnRezSingleAttachmentFromInv;
  3682. if (handlerRezSingleAttachment != null)
  3683. {
  3684. RezSingleAttachmentFromInvPacket rez = (RezSingleAttachmentFromInvPacket)Pack;
  3685. handlerRezSingleAttachment(this, rez.ObjectData.ItemID,
  3686. rez.ObjectData.AttachmentPt, rez.ObjectData.ItemFlags, rez.ObjectData.NextOwnerMask);
  3687. }
  3688. break;
  3689. case PacketType.DetachAttachmentIntoInv:
  3690. handlerDetachAttachmentIntoInv = OnDetachAttachmentIntoInv;
  3691. if (handlerDetachAttachmentIntoInv != null)
  3692. {
  3693. DetachAttachmentIntoInvPacket detachtoInv = (DetachAttachmentIntoInvPacket)Pack;
  3694. LLUUID itemID = detachtoInv.ObjectData.ItemID;
  3695. LLUUID ATTACH_agentID = detachtoInv.ObjectData.AgentID;
  3696. handlerDetachAttachmentIntoInv(itemID, this);
  3697. }
  3698. break;
  3699. case PacketType.ObjectAttach:
  3700. if (OnObjectAttach != null)
  3701. {
  3702. ObjectAttachPacket att = (ObjectAttachPacket)Pack;
  3703. handlerObjectAttach = OnObjectAttach;
  3704. if (handlerObjectAttach != null)
  3705. {
  3706. if (att.ObjectData.Length > 0)
  3707. {
  3708. handlerObjectAttach(this, att.ObjectData[0].ObjectLocalID, att.AgentData.AttachmentPoint, att.ObjectData[0].Rotation);
  3709. }
  3710. }
  3711. }
  3712. break;
  3713. case PacketType.ObjectDetach:
  3714. ObjectDetachPacket dett = (ObjectDetachPacket)Pack;
  3715. for (int j = 0; j < dett.ObjectData.Length; j++)
  3716. {
  3717. uint obj = dett.ObjectData[j].ObjectLocalID;
  3718. handlerObjectDetach = OnObjectDetach;
  3719. if (handlerObjectDetach != null)
  3720. {
  3721. handlerObjectDetach(obj,this);
  3722. }
  3723. }
  3724. break;
  3725. case PacketType.SetAlwaysRun:
  3726. SetAlwaysRunPacket run = (SetAlwaysRunPacket)Pack;
  3727. handlerSetAlwaysRun = OnSetAlwaysRun;
  3728. if (handlerSetAlwaysRun != null)
  3729. handlerSetAlwaysRun(this, run.AgentData.AlwaysRun);
  3730. break;
  3731. case PacketType.CompleteAgentMovement:
  3732. handlerCompleteMovementToRegion = OnCompleteMovementToRegion;
  3733. if (handlerCompleteMovementToRegion != null)
  3734. {
  3735. handlerCompleteMovementToRegion();
  3736. }
  3737. handlerCompleteMovementToRegion = null;
  3738. break;
  3739. case PacketType.AgentUpdate:
  3740. if (OnAgentUpdate != null)
  3741. {
  3742. AgentUpdatePacket agenUpdate = (AgentUpdatePacket)Pack;
  3743. AgentUpdatePacket.AgentDataBlock x = agenUpdate.AgentData;
  3744. AgentUpdateArgs arg = new AgentUpdateArgs();
  3745. arg.AgentID = x.AgentID;
  3746. arg.BodyRotation = x.BodyRotation;
  3747. arg.CameraAtAxis = x.CameraAtAxis;
  3748. arg.CameraCenter = x.CameraCenter;
  3749. arg.CameraLeftAxis = x.CameraLeftAxis;
  3750. arg.CameraUpAxis = x.CameraUpAxis;
  3751. arg.ControlFlags = x.ControlFlags;
  3752. arg.Far = x.Far;
  3753. arg.Flags = x.Flags;
  3754. arg.HeadRotation = x.HeadRotation;
  3755. arg.SessionID = x.SessionID;
  3756. arg.State = x.State;
  3757. handlerAgentUpdate = OnAgentUpdate;
  3758. if (handlerAgentUpdate != null)
  3759. OnAgentUpdate(this, arg);
  3760. handlerAgentUpdate = null;
  3761. //agenUpdate.AgentData.ControlFlags, agenUpdate.AgentData.BodyRotationa);
  3762. }
  3763. break;
  3764. case PacketType.AgentAnimation:
  3765. AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
  3766. handlerStartAnim = null;
  3767. handlerStopAnim = null;
  3768. for (int i = 0; i < AgentAni.AnimationList.Length; i++)
  3769. {
  3770. if (AgentAni.AnimationList[i].StartAnim)
  3771. {
  3772. handlerStartAnim = OnStartAnim;
  3773. if (handlerStartAnim != null)
  3774. {
  3775. handlerStartAnim(this, AgentAni.AnimationList[i].AnimID);
  3776. }
  3777. }
  3778. else
  3779. {
  3780. handlerStopAnim = OnStopAnim;
  3781. if (handlerStopAnim != null)
  3782. {
  3783. handlerStopAnim(this, AgentAni.AnimationList[i].AnimID);
  3784. }
  3785. }
  3786. }
  3787. break;
  3788. case PacketType.AgentRequestSit:
  3789. if (OnAgentRequestSit != null)
  3790. {
  3791. AgentRequestSitPacket agentRequestSit = (AgentRequestSitPacket)Pack;
  3792. handlerAgentRequestSit = OnAgentRequestSit;
  3793. if (handlerAgentRequestSit != null)
  3794. handlerAgentRequestSit(this, agentRequestSit.AgentData.AgentID,
  3795. agentRequestSit.TargetObject.TargetID, agentRequestSit.TargetObject.Offset);
  3796. }
  3797. break;
  3798. case PacketType.AgentSit:
  3799. if (OnAgentSit != null)
  3800. {
  3801. AgentSitPacket agentSit = (AgentSitPacket)Pack;
  3802. handlerAgentSit = OnAgentSit;
  3803. if (handlerAgentSit != null)
  3804. {
  3805. OnAgentSit(this, agentSit.AgentData.AgentID);
  3806. }
  3807. }
  3808. break;
  3809. case PacketType.AvatarPickerRequest:
  3810. AvatarPickerRequestPacket avRequestQuery = (AvatarPickerRequestPacket)Pack;
  3811. AvatarPickerRequestPacket.AgentDataBlock Requestdata = avRequestQuery.AgentData;
  3812. AvatarPickerRequestPacket.DataBlock querydata = avRequestQuery.Data;
  3813. //Console.WriteLine("Agent Sends:" + Helpers.FieldToUTF8String(querydata.Name));
  3814. handlerAvatarPickerRequest = OnAvatarPickerRequest;
  3815. if (handlerAvatarPickerRequest != null)
  3816. {
  3817. handlerAvatarPickerRequest(this, Requestdata.AgentID, Requestdata.QueryID,
  3818. Helpers.FieldToUTF8String(querydata.Name));
  3819. }
  3820. break;
  3821. case PacketType.AgentDataUpdateRequest:
  3822. AgentDataUpdateRequestPacket avRequestDataUpdatePacket = (AgentDataUpdateRequestPacket)Pack;
  3823. handlerAgentDataUpdateRequest = OnAgentDataUpdateRequest;
  3824. if (handlerAgentDataUpdateRequest != null)
  3825. {
  3826. handlerAgentDataUpdateRequest(this, avRequestDataUpdatePacket.AgentData.AgentID, avRequestDataUpdatePacket.AgentData.SessionID);
  3827. }
  3828. break;
  3829. case PacketType.UserInfoRequest:
  3830. UserInfoRequestPacket avUserInfoRequestPacket = (UserInfoRequestPacket)Pack;
  3831. handlerUserInfoRequest = OnUserInfoRequest;
  3832. if (handlerUserInfoRequest != null)
  3833. {
  3834. handlerUserInfoRequest(this, avUserInfoRequestPacket.AgentData.AgentID, avUserInfoRequestPacket.AgentData.SessionID);
  3835. }
  3836. break;
  3837. case PacketType.SetStartLocationRequest:
  3838. SetStartLocationRequestPacket avSetStartLocationRequestPacket = (SetStartLocationRequestPacket)Pack;
  3839. if (avSetStartLocationRequestPacket.AgentData.AgentID == AgentId && avSetStartLocationRequestPacket.AgentData.SessionID == SessionId)
  3840. {
  3841. handlerSetStartLocationRequest = OnSetStartLocationRequest;
  3842. if (handlerSetStartLocationRequest != null)
  3843. {
  3844. handlerSetStartLocationRequest(this, 0, avSetStartLocationRequestPacket.StartLocationData.LocationPos,
  3845. avSetStartLocationRequestPacket.StartLocationData.LocationLookAt,
  3846. avSetStartLocationRequestPacket.StartLocationData.LocationID);
  3847. }
  3848. }
  3849. break;
  3850. case PacketType.AgentThrottle:
  3851. AgentThrottlePacket atpack = (AgentThrottlePacket)Pack;
  3852. m_packetQueue.SetThrottleFromClient(atpack.Throttle.Throttles);
  3853. break;
  3854. case PacketType.AgentPause:
  3855. m_probesWithNoIngressPackets = 0;
  3856. m_clientBlocked = true;
  3857. break;
  3858. case PacketType.AgentResume:
  3859. m_probesWithNoIngressPackets = 0;
  3860. m_clientBlocked = false;
  3861. SendStartPingCheck(0);
  3862. break;
  3863. case PacketType.ForceScriptControlRelease:
  3864. handlerForceReleaseControls = OnForceReleaseControls;
  3865. if (handlerForceReleaseControls != null)
  3866. {
  3867. handlerForceReleaseControls(this, AgentId);
  3868. }
  3869. break;
  3870. #endregion
  3871. #region Objects/m_sceneObjects
  3872. case PacketType.ObjectLink:
  3873. ObjectLinkPacket link = (ObjectLinkPacket)Pack;
  3874. uint parentprimid = 0;
  3875. List<uint> childrenprims = new List<uint>();
  3876. if (link.ObjectData.Length > 1)
  3877. {
  3878. parentprimid = link.ObjectData[0].ObjectLocalID;
  3879. for (int i = 1; i < link.ObjectData.Length; i++)
  3880. {
  3881. childrenprims.Add(link.ObjectData[i].ObjectLocalID);
  3882. }
  3883. }
  3884. handlerLinkObjects = OnLinkObjects;
  3885. if (handlerLinkObjects != null)
  3886. {
  3887. handlerLinkObjects(this, parentprimid, childrenprims);
  3888. }
  3889. break;
  3890. case PacketType.ObjectDelink:
  3891. ObjectDelinkPacket delink = (ObjectDelinkPacket)Pack;
  3892. // It appears the prim at index 0 is not always the root prim (for
  3893. // instance, when one prim of a link set has been edited independently
  3894. // of the others). Therefore, we'll pass all the ids onto the delink
  3895. // method for it to decide which is the root.
  3896. List<uint> prims = new List<uint>();
  3897. for (int i = 0; i < delink.ObjectData.Length; i++)
  3898. {
  3899. prims.Add(delink.ObjectData[i].ObjectLocalID);
  3900. }
  3901. handlerDelinkObjects = OnDelinkObjects;
  3902. if (handlerDelinkObjects != null)
  3903. {
  3904. handlerDelinkObjects(prims);
  3905. }
  3906. break;
  3907. case PacketType.ObjectAdd:
  3908. if (OnAddPrim != null)
  3909. {
  3910. ObjectAddPacket addPacket = (ObjectAddPacket)Pack;
  3911. PrimitiveBaseShape shape = GetShapeFromAddPacket(addPacket);
  3912. // m_log.Info("[REZData]: " + addPacket.ToString());
  3913. //BypassRaycast: 1
  3914. //RayStart: <69.79469, 158.2652, 98.40343>
  3915. //RayEnd: <61.97724, 141.995, 92.58341>
  3916. //RayTargetID: 00000000-0000-0000-0000-000000000000
  3917. //Check to see if adding the prim is allowed; useful for any module wanting to restrict the
  3918. //object from rezing initially
  3919. handlerAddPrim = OnAddPrim;
  3920. if (handlerAddPrim != null)
  3921. handlerAddPrim(AgentId, addPacket.ObjectData.RayEnd, addPacket.ObjectData.Rotation, shape, addPacket.ObjectData.BypassRaycast, addPacket.ObjectData.RayStart, addPacket.ObjectData.RayTargetID, addPacket.ObjectData.RayEndIsIntersection);
  3922. }
  3923. break;
  3924. case PacketType.ObjectShape:
  3925. ObjectShapePacket shapePacket = (ObjectShapePacket)Pack;
  3926. handlerUpdatePrimShape = null;
  3927. for (int i = 0; i < shapePacket.ObjectData.Length; i++)
  3928. {
  3929. handlerUpdatePrimShape = OnUpdatePrimShape;
  3930. if (handlerUpdatePrimShape != null)
  3931. {
  3932. UpdateShapeArgs shapeData = new UpdateShapeArgs();
  3933. shapeData.ObjectLocalID = shapePacket.ObjectData[i].ObjectLocalID;
  3934. shapeData.PathBegin = shapePacket.ObjectData[i].PathBegin;
  3935. shapeData.PathCurve = shapePacket.ObjectData[i].PathCurve;
  3936. shapeData.PathEnd = shapePacket.ObjectData[i].PathEnd;
  3937. shapeData.PathRadiusOffset = shapePacket.ObjectData[i].PathRadiusOffset;
  3938. shapeData.PathRevolutions = shapePacket.ObjectData[i].PathRevolutions;
  3939. shapeData.PathScaleX = shapePacket.ObjectData[i].PathScaleX;
  3940. shapeData.PathScaleY = shapePacket.ObjectData[i].PathScaleY;
  3941. shapeData.PathShearX = shapePacket.ObjectData[i].PathShearX;
  3942. shapeData.PathShearY = shapePacket.ObjectData[i].PathShearY;
  3943. shapeData.PathSkew = shapePacket.ObjectData[i].PathSkew;
  3944. shapeData.PathTaperX = shapePacket.ObjectData[i].PathTaperX;
  3945. shapeData.PathTaperY = shapePacket.ObjectData[i].PathTaperY;
  3946. shapeData.PathTwist = shapePacket.ObjectData[i].PathTwist;
  3947. shapeData.PathTwistBegin = shapePacket.ObjectData[i].PathTwistBegin;
  3948. shapeData.ProfileBegin = shapePacket.ObjectData[i].ProfileBegin;
  3949. shapeData.ProfileCurve = shapePacket.ObjectData[i].ProfileCurve;
  3950. shapeData.ProfileEnd = shapePacket.ObjectData[i].ProfileEnd;
  3951. shapeData.ProfileHollow = shapePacket.ObjectData[i].ProfileHollow;
  3952. handlerUpdatePrimShape(m_agentId, shapePacket.ObjectData[i].ObjectLocalID,
  3953. shapeData);
  3954. }
  3955. }
  3956. break;
  3957. case PacketType.ObjectExtraParams:
  3958. ObjectExtraParamsPacket extraPar = (ObjectExtraParamsPacket)Pack;
  3959. handlerUpdateExtraParams = OnUpdateExtraParams;
  3960. if (handlerUpdateExtraParams != null)
  3961. {
  3962. handlerUpdateExtraParams(m_agentId, extraPar.ObjectData[0].ObjectLocalID,
  3963. extraPar.ObjectData[0].ParamType,
  3964. extraPar.ObjectData[0].ParamInUse, extraPar.ObjectData[0].ParamData);
  3965. }
  3966. break;
  3967. case PacketType.ObjectDuplicate:
  3968. ObjectDuplicatePacket dupe = (ObjectDuplicatePacket)Pack;
  3969. ObjectDuplicatePacket.AgentDataBlock AgentandGroupData = dupe.AgentData;
  3970. handlerObjectDuplicate = null;
  3971. for (int i = 0; i < dupe.ObjectData.Length; i++)
  3972. {
  3973. handlerObjectDuplicate = OnObjectDuplicate;
  3974. if (handlerObjectDuplicate != null)
  3975. {
  3976. handlerObjectDuplicate(dupe.ObjectData[i].ObjectLocalID, dupe.SharedData.Offset,
  3977. dupe.SharedData.DuplicateFlags, AgentandGroupData.AgentID,
  3978. AgentandGroupData.GroupID);
  3979. }
  3980. }
  3981. break;
  3982. case PacketType.ObjectSelect:
  3983. ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
  3984. handlerObjectSelect = null;
  3985. for (int i = 0; i < incomingselect.ObjectData.Length; i++)
  3986. {
  3987. handlerObjectSelect = OnObjectSelect;
  3988. if (handlerObjectSelect != null)
  3989. {
  3990. handlerObjectSelect(incomingselect.ObjectData[i].ObjectLocalID, this);
  3991. }
  3992. }
  3993. break;
  3994. case PacketType.ObjectDeselect:
  3995. ObjectDeselectPacket incomingdeselect = (ObjectDeselectPacket)Pack;
  3996. handlerObjectDeselect = null;
  3997. for (int i = 0; i < incomingdeselect.ObjectData.Length; i++)
  3998. {
  3999. handlerObjectDeselect = OnObjectDeselect;
  4000. if (handlerObjectDeselect != null)
  4001. {
  4002. OnObjectDeselect(incomingdeselect.ObjectData[i].ObjectLocalID, this);
  4003. }
  4004. }
  4005. break;
  4006. case PacketType.ObjectPosition:
  4007. // DEPRECATED: but till libsecondlife removes it, people will use it
  4008. ObjectPositionPacket position = (ObjectPositionPacket)Pack;
  4009. for (int i=0; i<position.ObjectData.Length; i++)
  4010. {
  4011. handlerUpdateVector = OnUpdatePrimGroupPosition;
  4012. if (handlerUpdateVector != null)
  4013. handlerUpdateVector(position.ObjectData[i].ObjectLocalID, position.ObjectData[i].Position, this);
  4014. }
  4015. break;
  4016. case PacketType.ObjectScale:
  4017. // DEPRECATED: but till libsecondlife removes it, people will use it
  4018. ObjectScalePacket scale = (ObjectScalePacket)Pack;
  4019. for (int i=0; i<scale.ObjectData.Length; i++)
  4020. {
  4021. handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale;
  4022. if (handlerUpdatePrimGroupScale != null)
  4023. handlerUpdatePrimGroupScale(scale.ObjectData[i].ObjectLocalID, scale.ObjectData[i].Scale, this);
  4024. }
  4025. break;
  4026. case PacketType.ObjectRotation:
  4027. // DEPRECATED: but till libsecondlife removes it, people will use it
  4028. ObjectRotationPacket rotation = (ObjectRotationPacket)Pack;
  4029. for (int i=0; i<rotation.ObjectData.Length; i++)
  4030. {
  4031. handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
  4032. if (handlerUpdatePrimRotation != null)
  4033. handlerUpdatePrimRotation(rotation.ObjectData[i].ObjectLocalID, rotation.ObjectData[i].Rotation, this);
  4034. }
  4035. break;
  4036. case PacketType.ObjectFlagUpdate:
  4037. ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
  4038. handlerUpdatePrimFlags = OnUpdatePrimFlags;
  4039. if (handlerUpdatePrimFlags != null)
  4040. {
  4041. handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, Pack, this);
  4042. }
  4043. break;
  4044. case PacketType.ObjectImage:
  4045. ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
  4046. handlerUpdatePrimTexture = null;
  4047. for (int i = 0; i < imagePack.ObjectData.Length; i++)
  4048. {
  4049. handlerUpdatePrimTexture = OnUpdatePrimTexture;
  4050. if (handlerUpdatePrimTexture != null)
  4051. {
  4052. handlerUpdatePrimTexture(imagePack.ObjectData[i].ObjectLocalID,
  4053. imagePack.ObjectData[i].TextureEntry, this);
  4054. }
  4055. }
  4056. break;
  4057. case PacketType.ObjectGrab:
  4058. ObjectGrabPacket grab = (ObjectGrabPacket)Pack;
  4059. handlerGrabObject = OnGrabObject;
  4060. if (handlerGrabObject != null)
  4061. {
  4062. handlerGrabObject(grab.ObjectData.LocalID, grab.ObjectData.GrabOffset, this);
  4063. }
  4064. break;
  4065. case PacketType.ObjectGrabUpdate:
  4066. ObjectGrabUpdatePacket grabUpdate = (ObjectGrabUpdatePacket)Pack;
  4067. handlerGrabUpdate = OnGrabUpdate;
  4068. if (handlerGrabUpdate != null)
  4069. {
  4070. handlerGrabUpdate(grabUpdate.ObjectData.ObjectID, grabUpdate.ObjectData.GrabOffsetInitial,
  4071. grabUpdate.ObjectData.GrabPosition, this);
  4072. }
  4073. break;
  4074. case PacketType.ObjectDeGrab:
  4075. ObjectDeGrabPacket deGrab = (ObjectDeGrabPacket)Pack;
  4076. handlerDeGrabObject = OnDeGrabObject;
  4077. if (handlerDeGrabObject != null)
  4078. {
  4079. handlerDeGrabObject(deGrab.ObjectData.LocalID, this);
  4080. }
  4081. break;
  4082. case PacketType.ObjectDescription:
  4083. ObjectDescriptionPacket objDes = (ObjectDescriptionPacket)Pack;
  4084. handlerObjectDescription = null;
  4085. for (int i = 0; i < objDes.ObjectData.Length; i++)
  4086. {
  4087. handlerObjectDescription = OnObjectDescription;
  4088. if (handlerObjectDescription != null)
  4089. {
  4090. handlerObjectDescription(this, objDes.ObjectData[i].LocalID,
  4091. Util.FieldToString(objDes.ObjectData[i].Description));
  4092. }
  4093. }
  4094. break;
  4095. case PacketType.ObjectName:
  4096. ObjectNamePacket objName = (ObjectNamePacket)Pack;
  4097. handlerObjectName = null;
  4098. for (int i = 0; i < objName.ObjectData.Length; i++)
  4099. {
  4100. handlerObjectName = OnObjectName;
  4101. if (handlerObjectName != null)
  4102. {
  4103. handlerObjectName(this, objName.ObjectData[i].LocalID,
  4104. Util.FieldToString(objName.ObjectData[i].Name));
  4105. }
  4106. }
  4107. break;
  4108. case PacketType.ObjectPermissions:
  4109. if (OnObjectPermissions != null)
  4110. {
  4111. ObjectPermissionsPacket newobjPerms = (ObjectPermissionsPacket)Pack;
  4112. LLUUID AgentID = newobjPerms.AgentData.AgentID;
  4113. LLUUID SessionID = newobjPerms.AgentData.SessionID;
  4114. handlerObjectPermissions = null;
  4115. for (int i = 0; i < newobjPerms.ObjectData.Length; i++)
  4116. {
  4117. ObjectPermissionsPacket.ObjectDataBlock permChanges = newobjPerms.ObjectData[i];
  4118. byte field = permChanges.Field;
  4119. uint localID = permChanges.ObjectLocalID;
  4120. uint mask = permChanges.Mask;
  4121. byte set = permChanges.Set;
  4122. handlerObjectPermissions = OnObjectPermissions;
  4123. if (handlerObjectPermissions != null)
  4124. handlerObjectPermissions(this, AgentID, SessionID, field, localID, mask, set);
  4125. }
  4126. }
  4127. // Here's our data,
  4128. // PermField contains the field the info goes into
  4129. // PermField determines which mask we're changing
  4130. //
  4131. // chmask is the mask of the change
  4132. // setTF is whether we're adding it or taking it away
  4133. //
  4134. // objLocalID is the localID of the object.
  4135. // Unfortunately, we have to pass the event the packet because objData is an array
  4136. // That means multiple object perms may be updated in a single packet.
  4137. break;
  4138. case PacketType.Undo:
  4139. UndoPacket undoitem = (UndoPacket)Pack;
  4140. if (undoitem.ObjectData.Length > 0)
  4141. {
  4142. for (int i = 0; i < undoitem.ObjectData.Length; i++)
  4143. {
  4144. LLUUID objiD = undoitem.ObjectData[i].ObjectID;
  4145. handlerOnUndo = OnUndo;
  4146. if (handlerOnUndo != null)
  4147. {
  4148. handlerOnUndo(this, objiD);
  4149. }
  4150. }
  4151. }
  4152. break;
  4153. case PacketType.ObjectDuplicateOnRay:
  4154. ObjectDuplicateOnRayPacket dupeOnRay = (ObjectDuplicateOnRayPacket)Pack;
  4155. handlerObjectDuplicateOnRay = null;
  4156. for (int i = 0; i < dupeOnRay.ObjectData.Length; i++)
  4157. {
  4158. handlerObjectDuplicateOnRay = OnObjectDuplicateOnRay;
  4159. if (handlerObjectDuplicateOnRay != null)
  4160. {
  4161. handlerObjectDuplicateOnRay(dupeOnRay.ObjectData[i].ObjectLocalID, dupeOnRay.AgentData.DuplicateFlags,
  4162. dupeOnRay.AgentData.AgentID, dupeOnRay.AgentData.GroupID, dupeOnRay.AgentData.RayTargetID, dupeOnRay.AgentData.RayEnd,
  4163. dupeOnRay.AgentData.RayStart, dupeOnRay.AgentData.BypassRaycast, dupeOnRay.AgentData.RayEndIsIntersection,
  4164. dupeOnRay.AgentData.CopyCenters, dupeOnRay.AgentData.CopyRotates);
  4165. }
  4166. }
  4167. break;
  4168. case PacketType.RequestObjectPropertiesFamily:
  4169. //This powers the little tooltip that appears when you move your mouse over an object
  4170. RequestObjectPropertiesFamilyPacket packToolTip = (RequestObjectPropertiesFamilyPacket)Pack;
  4171. RequestObjectPropertiesFamilyPacket.ObjectDataBlock packObjBlock = packToolTip.ObjectData;
  4172. handlerRequestObjectPropertiesFamily = OnRequestObjectPropertiesFamily;
  4173. if (handlerRequestObjectPropertiesFamily != null)
  4174. {
  4175. handlerRequestObjectPropertiesFamily(this, m_agentId, packObjBlock.RequestFlags,
  4176. packObjBlock.ObjectID);
  4177. }
  4178. break;
  4179. case PacketType.ObjectIncludeInSearch:
  4180. //This lets us set objects to appear in search (stuff like DataSnapshot, etc)
  4181. ObjectIncludeInSearchPacket packInSearch = (ObjectIncludeInSearchPacket)Pack;
  4182. handlerObjectIncludeInSearch = null;
  4183. foreach (ObjectIncludeInSearchPacket.ObjectDataBlock objData in packInSearch.ObjectData)
  4184. {
  4185. bool inSearch = objData.IncludeInSearch;
  4186. uint localID = objData.ObjectLocalID;
  4187. handlerObjectIncludeInSearch = OnObjectIncludeInSearch;
  4188. if (handlerObjectIncludeInSearch != null)
  4189. {
  4190. handlerObjectIncludeInSearch(this, inSearch, localID);
  4191. }
  4192. }
  4193. break;
  4194. case PacketType.ScriptAnswerYes:
  4195. ScriptAnswerYesPacket scriptAnswer = (ScriptAnswerYesPacket)Pack;
  4196. handlerScriptAnswer = OnScriptAnswer;
  4197. if (handlerScriptAnswer != null)
  4198. {
  4199. handlerScriptAnswer(this, scriptAnswer.Data.TaskID, scriptAnswer.Data.ItemID, scriptAnswer.Data.Questions);
  4200. }
  4201. break;
  4202. #endregion
  4203. #region Inventory/Asset/Other related packets
  4204. case PacketType.RequestImage:
  4205. RequestImagePacket imageRequest = (RequestImagePacket)Pack;
  4206. //Console.WriteLine("image request: " + Pack.ToString());
  4207. handlerTextureRequest = null;
  4208. for (int i = 0; i < imageRequest.RequestImage.Length; i++)
  4209. {
  4210. if (OnRequestTexture != null)
  4211. {
  4212. TextureRequestArgs args = new TextureRequestArgs();
  4213. args.RequestedAssetID = imageRequest.RequestImage[i].Image;
  4214. args.DiscardLevel = imageRequest.RequestImage[i].DiscardLevel;
  4215. args.PacketNumber = imageRequest.RequestImage[i].Packet;
  4216. args.Priority = imageRequest.RequestImage[i].DownloadPriority;
  4217. handlerTextureRequest = OnRequestTexture;
  4218. if (handlerTextureRequest != null)
  4219. OnRequestTexture(this, args);
  4220. }
  4221. }
  4222. break;
  4223. case PacketType.TransferRequest:
  4224. //Console.WriteLine("ClientView.ProcessPackets.cs:ProcessInPacket() - Got transfer request");
  4225. TransferRequestPacket transfer = (TransferRequestPacket)Pack;
  4226. m_assetCache.AddAssetRequest(this, transfer);
  4227. /* RequestAsset = OnRequestAsset;
  4228. if (RequestAsset != null)
  4229. {
  4230. RequestAsset(this, transfer);
  4231. }*/
  4232. break;
  4233. case PacketType.AssetUploadRequest:
  4234. AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
  4235. // Console.WriteLine("upload request " + Pack.ToString());
  4236. // Console.WriteLine("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToString());
  4237. LLUUID temp = LLUUID.Combine(request.AssetBlock.TransactionID, SecureSessionId);
  4238. handlerAssetUploadRequest = OnAssetUploadRequest;
  4239. if (handlerAssetUploadRequest != null)
  4240. {
  4241. handlerAssetUploadRequest(this, temp,
  4242. request.AssetBlock.TransactionID, request.AssetBlock.Type,
  4243. request.AssetBlock.AssetData, request.AssetBlock.StoreLocal,
  4244. request.AssetBlock.Tempfile);
  4245. }
  4246. break;
  4247. case PacketType.RequestXfer:
  4248. RequestXferPacket xferReq = (RequestXferPacket)Pack;
  4249. handlerRequestXfer = OnRequestXfer;
  4250. if (handlerRequestXfer != null)
  4251. {
  4252. handlerRequestXfer(this, xferReq.XferID.ID, Util.FieldToString(xferReq.XferID.Filename));
  4253. }
  4254. break;
  4255. case PacketType.SendXferPacket:
  4256. SendXferPacketPacket xferRec = (SendXferPacketPacket)Pack;
  4257. handlerXferReceive = OnXferReceive;
  4258. if (handlerXferReceive != null)
  4259. {
  4260. handlerXferReceive(this, xferRec.XferID.ID, xferRec.XferID.Packet, xferRec.DataPacket.Data);
  4261. }
  4262. break;
  4263. case PacketType.ConfirmXferPacket:
  4264. ConfirmXferPacketPacket confirmXfer = (ConfirmXferPacketPacket)Pack;
  4265. handlerConfirmXfer = OnConfirmXfer;
  4266. if (handlerConfirmXfer != null)
  4267. {
  4268. handlerConfirmXfer(this, confirmXfer.XferID.ID, confirmXfer.XferID.Packet);
  4269. }
  4270. break;
  4271. case PacketType.CreateInventoryFolder:
  4272. CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack;
  4273. handlerCreateInventoryFolder = OnCreateNewInventoryFolder;
  4274. if (handlerCreateInventoryFolder != null)
  4275. {
  4276. handlerCreateInventoryFolder(this, invFolder.FolderData.FolderID,
  4277. (ushort)invFolder.FolderData.Type,
  4278. Util.FieldToString(invFolder.FolderData.Name),
  4279. invFolder.FolderData.ParentID);
  4280. }
  4281. break;
  4282. case PacketType.UpdateInventoryFolder:
  4283. if (OnUpdateInventoryFolder != null)
  4284. {
  4285. UpdateInventoryFolderPacket invFolderx = (UpdateInventoryFolderPacket)Pack;
  4286. handlerUpdateInventoryFolder = null;
  4287. for (int i = 0; i < invFolderx.FolderData.Length; i++)
  4288. {
  4289. handlerUpdateInventoryFolder = OnUpdateInventoryFolder;
  4290. if (handlerUpdateInventoryFolder != null)
  4291. {
  4292. OnUpdateInventoryFolder(this, invFolderx.FolderData[i].FolderID,
  4293. (ushort)invFolderx.FolderData[i].Type,
  4294. Util.FieldToString(invFolderx.FolderData[i].Name),
  4295. invFolderx.FolderData[i].ParentID);
  4296. }
  4297. }
  4298. }
  4299. break;
  4300. case PacketType.MoveInventoryFolder:
  4301. if (OnMoveInventoryFolder != null)
  4302. {
  4303. MoveInventoryFolderPacket invFoldery = (MoveInventoryFolderPacket)Pack;
  4304. handlerMoveInventoryFolder = null;
  4305. for (int i = 0; i < invFoldery.InventoryData.Length; i++)
  4306. {
  4307. handlerMoveInventoryFolder = OnMoveInventoryFolder;
  4308. if (handlerMoveInventoryFolder != null)
  4309. {
  4310. OnMoveInventoryFolder(this, invFoldery.InventoryData[i].FolderID,
  4311. invFoldery.InventoryData[i].ParentID);
  4312. }
  4313. }
  4314. }
  4315. break;
  4316. case PacketType.CreateInventoryItem:
  4317. CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack;
  4318. handlerCreateNewInventoryItem = OnCreateNewInventoryItem;
  4319. if (handlerCreateNewInventoryItem != null)
  4320. {
  4321. handlerCreateNewInventoryItem(this, createItem.InventoryBlock.TransactionID,
  4322. createItem.InventoryBlock.FolderID,
  4323. createItem.InventoryBlock.CallbackID,
  4324. Util.FieldToString(createItem.InventoryBlock.Description),
  4325. Util.FieldToString(createItem.InventoryBlock.Name),
  4326. createItem.InventoryBlock.InvType,
  4327. createItem.InventoryBlock.Type,
  4328. createItem.InventoryBlock.WearableType,
  4329. createItem.InventoryBlock.NextOwnerMask);
  4330. }
  4331. break;
  4332. case PacketType.FetchInventory:
  4333. if (OnFetchInventory != null)
  4334. {
  4335. FetchInventoryPacket FetchInventoryx = (FetchInventoryPacket)Pack;
  4336. handlerFetchInventory = null;
  4337. for (int i = 0; i < FetchInventoryx.InventoryData.Length; i++)
  4338. {
  4339. handlerFetchInventory = OnFetchInventory;
  4340. if (handlerFetchInventory != null)
  4341. {
  4342. OnFetchInventory(this, FetchInventoryx.InventoryData[i].ItemID,
  4343. FetchInventoryx.InventoryData[i].OwnerID);
  4344. }
  4345. }
  4346. }
  4347. break;
  4348. case PacketType.FetchInventoryDescendents:
  4349. FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack;
  4350. handlerFetchInventoryDescendents = OnFetchInventoryDescendents;
  4351. if (handlerFetchInventoryDescendents != null)
  4352. {
  4353. handlerFetchInventoryDescendents(this, Fetch.InventoryData.FolderID, Fetch.InventoryData.OwnerID,
  4354. Fetch.InventoryData.FetchFolders, Fetch.InventoryData.FetchItems,
  4355. Fetch.InventoryData.SortOrder);
  4356. }
  4357. break;
  4358. case PacketType.PurgeInventoryDescendents:
  4359. PurgeInventoryDescendentsPacket Purge = (PurgeInventoryDescendentsPacket)Pack;
  4360. handlerPurgeInventoryDescendents = OnPurgeInventoryDescendents;
  4361. if (handlerPurgeInventoryDescendents != null)
  4362. {
  4363. handlerPurgeInventoryDescendents(this, Purge.InventoryData.FolderID);
  4364. }
  4365. break;
  4366. case PacketType.UpdateInventoryItem:
  4367. UpdateInventoryItemPacket update = (UpdateInventoryItemPacket)Pack;
  4368. if (OnUpdateInventoryItem != null)
  4369. {
  4370. handlerUpdateInventoryItem = null;
  4371. for (int i = 0; i < update.InventoryData.Length; i++)
  4372. {
  4373. handlerUpdateInventoryItem = OnUpdateInventoryItem;
  4374. if (handlerUpdateInventoryItem != null)
  4375. {
  4376. InventoryItemBase itemUpd = new InventoryItemBase();
  4377. itemUpd.ID = update.InventoryData[i].ItemID;
  4378. itemUpd.Name = Util.FieldToString(update.InventoryData[i].Name);
  4379. itemUpd.Description = Util.FieldToString(update.InventoryData[i].Description);
  4380. itemUpd.GroupID = update.InventoryData[i].GroupID;
  4381. itemUpd.GroupOwned = update.InventoryData[i].GroupOwned;
  4382. itemUpd.NextPermissions = update.InventoryData[i].NextOwnerMask;
  4383. itemUpd.EveryOnePermissions = update.InventoryData[i].EveryoneMask;
  4384. itemUpd.CreationDate = update.InventoryData[i].CreationDate;
  4385. itemUpd.Folder = update.InventoryData[i].FolderID;
  4386. itemUpd.InvType = update.InventoryData[i].InvType;
  4387. itemUpd.SalePrice = update.InventoryData[i].SalePrice;
  4388. itemUpd.SaleType = update.InventoryData[i].SaleType;
  4389. itemUpd.Flags = update.InventoryData[i].Flags;
  4390. /*
  4391. OnUpdateInventoryItem(this, update.InventoryData[i].TransactionID,
  4392. update.InventoryData[i].ItemID,
  4393. Util.FieldToString(update.InventoryData[i].Name),
  4394. Util.FieldToString(update.InventoryData[i].Description),
  4395. update.InventoryData[i].NextOwnerMask);
  4396. */
  4397. OnUpdateInventoryItem(this, update.InventoryData[i].TransactionID,
  4398. update.InventoryData[i].ItemID,
  4399. itemUpd);
  4400. }
  4401. }
  4402. }
  4403. //Console.WriteLine(Pack.ToString());
  4404. /*for (int i = 0; i < update.InventoryData.Length; i++)
  4405. {
  4406. if (update.InventoryData[i].TransactionID != LLUUID.Zero)
  4407. {
  4408. AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionId));
  4409. if (asset != null)
  4410. {
  4411. // Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToString() + " already in cache");
  4412. m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
  4413. }
  4414. else
  4415. {
  4416. asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID);
  4417. if (asset != null)
  4418. {
  4419. //Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToString() + " to cache");
  4420. m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
  4421. }
  4422. else
  4423. {
  4424. //Console.WriteLine("trying to update inventory item, but asset is null");
  4425. }
  4426. }
  4427. }
  4428. else
  4429. {
  4430. m_inventoryCache.UpdateInventoryItemDetails(this, update.InventoryData[i].ItemID, update.InventoryData[i]); ;
  4431. }
  4432. }*/
  4433. break;
  4434. case PacketType.CopyInventoryItem:
  4435. CopyInventoryItemPacket copyitem = (CopyInventoryItemPacket)Pack;
  4436. handlerCopyInventoryItem = null;
  4437. if (OnCopyInventoryItem != null)
  4438. {
  4439. foreach (CopyInventoryItemPacket.InventoryDataBlock datablock in copyitem.InventoryData)
  4440. {
  4441. handlerCopyInventoryItem = OnCopyInventoryItem;
  4442. if (handlerCopyInventoryItem != null)
  4443. {
  4444. handlerCopyInventoryItem(this, datablock.CallbackID, datablock.OldAgentID,
  4445. datablock.OldItemID, datablock.NewFolderID,
  4446. Util.FieldToString(datablock.NewName));
  4447. }
  4448. }
  4449. }
  4450. break;
  4451. case PacketType.MoveInventoryItem:
  4452. MoveInventoryItemPacket moveitem = (MoveInventoryItemPacket)Pack;
  4453. if (OnMoveInventoryItem != null)
  4454. {
  4455. handlerMoveInventoryItem = null;
  4456. foreach (MoveInventoryItemPacket.InventoryDataBlock datablock in moveitem.InventoryData)
  4457. {
  4458. handlerMoveInventoryItem = OnMoveInventoryItem;
  4459. if (handlerMoveInventoryItem != null)
  4460. {
  4461. handlerMoveInventoryItem(this, datablock.FolderID, datablock.ItemID, datablock.Length,
  4462. Util.FieldToString(datablock.NewName));
  4463. }
  4464. }
  4465. }
  4466. break;
  4467. case PacketType.RemoveInventoryItem:
  4468. RemoveInventoryItemPacket removeItem = (RemoveInventoryItemPacket)Pack;
  4469. if (OnRemoveInventoryItem != null)
  4470. {
  4471. handlerRemoveInventoryItem = null;
  4472. foreach (RemoveInventoryItemPacket.InventoryDataBlock datablock in removeItem.InventoryData)
  4473. {
  4474. handlerRemoveInventoryItem = OnRemoveInventoryItem;
  4475. if (handlerRemoveInventoryItem != null)
  4476. {
  4477. handlerRemoveInventoryItem(this, datablock.ItemID);
  4478. }
  4479. }
  4480. }
  4481. break;
  4482. case PacketType.RemoveInventoryFolder:
  4483. RemoveInventoryFolderPacket removeFolder = (RemoveInventoryFolderPacket)Pack;
  4484. if (OnRemoveInventoryFolder != null)
  4485. {
  4486. handlerRemoveInventoryFolder = null;
  4487. foreach (RemoveInventoryFolderPacket.FolderDataBlock datablock in removeFolder.FolderData)
  4488. {
  4489. handlerRemoveInventoryFolder = OnRemoveInventoryFolder;
  4490. if (handlerRemoveInventoryFolder != null)
  4491. {
  4492. handlerRemoveInventoryFolder(this, datablock.FolderID);
  4493. }
  4494. }
  4495. }
  4496. break;
  4497. case PacketType.RequestTaskInventory:
  4498. RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
  4499. handlerRequestTaskInventory = OnRequestTaskInventory;
  4500. if (handlerRequestTaskInventory != null)
  4501. {
  4502. handlerRequestTaskInventory(this, requesttask.InventoryData.LocalID);
  4503. }
  4504. break;
  4505. case PacketType.UpdateTaskInventory:
  4506. UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
  4507. if (OnUpdateTaskInventory != null)
  4508. {
  4509. if (updatetask.UpdateData.Key == 0)
  4510. {
  4511. handlerUpdateTaskInventory = OnUpdateTaskInventory;
  4512. if (handlerUpdateTaskInventory != null)
  4513. {
  4514. TaskInventoryItem newTaskItem=new TaskInventoryItem();
  4515. newTaskItem.ItemID=updatetask.InventoryData.ItemID;
  4516. newTaskItem.ParentID=updatetask.InventoryData.FolderID;
  4517. newTaskItem.CreatorID=updatetask.InventoryData.CreatorID;
  4518. newTaskItem.OwnerID=updatetask.InventoryData.OwnerID;
  4519. newTaskItem.GroupID=updatetask.InventoryData.GroupID;
  4520. newTaskItem.BaseMask=updatetask.InventoryData.BaseMask;
  4521. newTaskItem.OwnerMask=updatetask.InventoryData.OwnerMask;
  4522. newTaskItem.GroupMask=updatetask.InventoryData.GroupMask;
  4523. newTaskItem.EveryoneMask=updatetask.InventoryData.EveryoneMask;
  4524. newTaskItem.NextOwnerMask=updatetask.InventoryData.NextOwnerMask;
  4525. //newTaskItem.GroupOwned=updatetask.InventoryData.GroupOwned;
  4526. newTaskItem.Type=updatetask.InventoryData.Type;
  4527. newTaskItem.InvType=updatetask.InventoryData.InvType;
  4528. newTaskItem.Flags=updatetask.InventoryData.Flags;
  4529. //newTaskItem.SaleType=updatetask.InventoryData.SaleType;
  4530. //newTaskItem.SalePrice=updatetask.InventoryData.SalePrice;;
  4531. newTaskItem.Name=Util.FieldToString(updatetask.InventoryData.Name);
  4532. newTaskItem.Description=Util.FieldToString(updatetask.InventoryData.Description);
  4533. newTaskItem.CreationDate=(uint)updatetask.InventoryData.CreationDate;
  4534. handlerUpdateTaskInventory(this, updatetask.InventoryData.TransactionID,
  4535. newTaskItem, updatetask.UpdateData.LocalID);
  4536. }
  4537. }
  4538. }
  4539. break;
  4540. case PacketType.RemoveTaskInventory:
  4541. RemoveTaskInventoryPacket removeTask = (RemoveTaskInventoryPacket)Pack;
  4542. handlerRemoveTaskItem = OnRemoveTaskItem;
  4543. if (handlerRemoveTaskItem != null)
  4544. {
  4545. handlerRemoveTaskItem(this, removeTask.InventoryData.ItemID, removeTask.InventoryData.LocalID);
  4546. }
  4547. break;
  4548. case PacketType.MoveTaskInventory:
  4549. MoveTaskInventoryPacket moveTaskInventoryPacket = (MoveTaskInventoryPacket)Pack;
  4550. handlerMoveTaskItem = OnMoveTaskItem;
  4551. if (handlerMoveTaskItem != null)
  4552. {
  4553. handlerMoveTaskItem(
  4554. this, moveTaskInventoryPacket.AgentData.FolderID,
  4555. moveTaskInventoryPacket.InventoryData.LocalID,
  4556. moveTaskInventoryPacket.InventoryData.ItemID);
  4557. }
  4558. break;
  4559. case PacketType.RezScript:
  4560. //Console.WriteLine(Pack.ToString());
  4561. RezScriptPacket rezScriptx = (RezScriptPacket)Pack;
  4562. handlerRezScript = OnRezScript;
  4563. InventoryItemBase item=new InventoryItemBase();
  4564. item.ID=rezScriptx.InventoryBlock.ItemID;
  4565. item.Folder=rezScriptx.InventoryBlock.FolderID;
  4566. item.Creator=rezScriptx.InventoryBlock.CreatorID;
  4567. item.Owner=rezScriptx.InventoryBlock.OwnerID;
  4568. item.BasePermissions=rezScriptx.InventoryBlock.BaseMask;
  4569. item.CurrentPermissions=rezScriptx.InventoryBlock.OwnerMask;
  4570. item.EveryOnePermissions=rezScriptx.InventoryBlock.EveryoneMask;
  4571. item.NextPermissions=rezScriptx.InventoryBlock.NextOwnerMask;
  4572. item.GroupOwned=rezScriptx.InventoryBlock.GroupOwned;
  4573. item.GroupID=rezScriptx.InventoryBlock.GroupID;
  4574. item.AssetType=rezScriptx.InventoryBlock.Type;
  4575. item.InvType=rezScriptx.InventoryBlock.InvType;
  4576. item.Flags=rezScriptx.InventoryBlock.Flags;
  4577. item.SaleType=rezScriptx.InventoryBlock.SaleType;
  4578. item.SalePrice=rezScriptx.InventoryBlock.SalePrice;
  4579. item.Name=Util.FieldToString(rezScriptx.InventoryBlock.Name);
  4580. item.Description=Util.FieldToString(rezScriptx.InventoryBlock.Description);
  4581. item.CreationDate=(int)rezScriptx.InventoryBlock.CreationDate;
  4582. if (handlerRezScript != null)
  4583. {
  4584. handlerRezScript(this, item, rezScriptx.InventoryBlock.TransactionID, rezScriptx.UpdateBlock.ObjectLocalID);
  4585. }
  4586. break;
  4587. case PacketType.MapLayerRequest:
  4588. RequestMapLayer();
  4589. break;
  4590. case PacketType.MapBlockRequest:
  4591. MapBlockRequestPacket MapRequest = (MapBlockRequestPacket)Pack;
  4592. handlerRequestMapBlocks = OnRequestMapBlocks;
  4593. if (handlerRequestMapBlocks != null)
  4594. {
  4595. handlerRequestMapBlocks(this, MapRequest.PositionData.MinX, MapRequest.PositionData.MinY,
  4596. MapRequest.PositionData.MaxX, MapRequest.PositionData.MaxY);
  4597. }
  4598. break;
  4599. case PacketType.MapNameRequest:
  4600. MapNameRequestPacket map = (MapNameRequestPacket)Pack;
  4601. string mapName = UTF8Encoding.UTF8.GetString(map.NameData.Name, 0,
  4602. map.NameData.Name.Length - 1);
  4603. handlerMapNameRequest = OnMapNameRequest;
  4604. if (handlerMapNameRequest != null)
  4605. {
  4606. handlerMapNameRequest(this, mapName);
  4607. }
  4608. break;
  4609. case PacketType.TeleportLandmarkRequest:
  4610. TeleportLandmarkRequestPacket tpReq = (TeleportLandmarkRequestPacket)Pack;
  4611. LLUUID lmid = tpReq.Info.LandmarkID;
  4612. AssetLandmark lm;
  4613. if (lmid != LLUUID.Zero)
  4614. {
  4615. AssetBase lma = m_assetCache.GetAsset(lmid, false);
  4616. if (lma == null)
  4617. {
  4618. // Failed to find landmark
  4619. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  4620. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  4621. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  4622. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  4623. }
  4624. try
  4625. {
  4626. lm = new AssetLandmark(lma);
  4627. }
  4628. catch (NullReferenceException)
  4629. {
  4630. // asset not found generates null ref inside the assetlandmark constructor.
  4631. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  4632. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  4633. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  4634. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  4635. break;
  4636. }
  4637. }
  4638. else
  4639. {
  4640. // Teleport home request
  4641. handlerTeleportHomeRequest = OnTeleportHomeRequest;
  4642. if (handlerTeleportHomeRequest != null)
  4643. {
  4644. handlerTeleportHomeRequest(this.AgentId,this);
  4645. }
  4646. break;
  4647. }
  4648. handlerTeleportLandmarkRequest = OnTeleportLandmarkRequest;
  4649. if (handlerTeleportLandmarkRequest != null)
  4650. {
  4651. handlerTeleportLandmarkRequest(this, lm.RegionHandle, lm.Position);
  4652. }
  4653. else
  4654. {
  4655. //no event handler so cancel request
  4656. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  4657. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  4658. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  4659. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  4660. }
  4661. break;
  4662. case PacketType.TeleportLocationRequest:
  4663. TeleportLocationRequestPacket tpLocReq = (TeleportLocationRequestPacket)Pack;
  4664. // Console.WriteLine(tpLocReq.ToString());
  4665. handlerTeleportLocationRequest = OnTeleportLocationRequest;
  4666. if (handlerTeleportLocationRequest != null)
  4667. {
  4668. handlerTeleportLocationRequest(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position,
  4669. tpLocReq.Info.LookAt, 16);
  4670. }
  4671. else
  4672. {
  4673. //no event handler so cancel request
  4674. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  4675. tpCancel.Info.SessionID = tpLocReq.AgentData.SessionID;
  4676. tpCancel.Info.AgentID = tpLocReq.AgentData.AgentID;
  4677. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  4678. }
  4679. break;
  4680. #endregion
  4681. case PacketType.UUIDNameRequest:
  4682. UUIDNameRequestPacket incoming = (UUIDNameRequestPacket)Pack;
  4683. foreach (UUIDNameRequestPacket.UUIDNameBlockBlock UUIDBlock in incoming.UUIDNameBlock)
  4684. {
  4685. handlerNameRequest = OnNameFromUUIDRequest;
  4686. if (handlerNameRequest != null)
  4687. {
  4688. handlerNameRequest(UUIDBlock.ID, this);
  4689. }
  4690. }
  4691. break;
  4692. #region Parcel related packets
  4693. case PacketType.ParcelAccessListRequest:
  4694. ParcelAccessListRequestPacket requestPacket = (ParcelAccessListRequestPacket)Pack;
  4695. handlerParcelAccessListRequest = OnParcelAccessListRequest;
  4696. if (handlerParcelAccessListRequest != null)
  4697. {
  4698. handlerParcelAccessListRequest(requestPacket.AgentData.AgentID, requestPacket.AgentData.SessionID,
  4699. requestPacket.Data.Flags, requestPacket.Data.SequenceID,
  4700. requestPacket.Data.LocalID, this);
  4701. }
  4702. break;
  4703. case PacketType.ParcelAccessListUpdate:
  4704. ParcelAccessListUpdatePacket updatePacket = (ParcelAccessListUpdatePacket)Pack;
  4705. List<ParcelManager.ParcelAccessEntry> entries = new List<ParcelManager.ParcelAccessEntry>();
  4706. foreach (ParcelAccessListUpdatePacket.ListBlock block in updatePacket.List)
  4707. {
  4708. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  4709. entry.AgentID = block.ID;
  4710. entry.Flags = (ParcelManager.AccessList)block.Flags;
  4711. entry.Time = new DateTime();
  4712. entries.Add(entry);
  4713. }
  4714. handlerParcelAccessListUpdateRequest = OnParcelAccessListUpdateRequest;
  4715. if (handlerParcelAccessListUpdateRequest != null)
  4716. {
  4717. handlerParcelAccessListUpdateRequest(updatePacket.AgentData.AgentID,
  4718. updatePacket.AgentData.SessionID, updatePacket.Data.Flags,
  4719. updatePacket.Data.LocalID, entries, this);
  4720. }
  4721. break;
  4722. case PacketType.ParcelPropertiesRequest:
  4723. ParcelPropertiesRequestPacket propertiesRequest = (ParcelPropertiesRequestPacket)Pack;
  4724. handlerParcelPropertiesRequest = OnParcelPropertiesRequest;
  4725. if (handlerParcelPropertiesRequest != null)
  4726. {
  4727. handlerParcelPropertiesRequest((int)Math.Round(propertiesRequest.ParcelData.West),
  4728. (int)Math.Round(propertiesRequest.ParcelData.South),
  4729. (int)Math.Round(propertiesRequest.ParcelData.East),
  4730. (int)Math.Round(propertiesRequest.ParcelData.North),
  4731. propertiesRequest.ParcelData.SequenceID,
  4732. propertiesRequest.ParcelData.SnapSelection, this);
  4733. }
  4734. break;
  4735. case PacketType.ParcelDivide:
  4736. ParcelDividePacket landDivide = (ParcelDividePacket)Pack;
  4737. handlerParcelDivideRequest = OnParcelDivideRequest;
  4738. if (handlerParcelDivideRequest != null)
  4739. {
  4740. handlerParcelDivideRequest((int)Math.Round(landDivide.ParcelData.West),
  4741. (int)Math.Round(landDivide.ParcelData.South),
  4742. (int)Math.Round(landDivide.ParcelData.East),
  4743. (int)Math.Round(landDivide.ParcelData.North), this);
  4744. }
  4745. break;
  4746. case PacketType.ParcelJoin:
  4747. ParcelJoinPacket landJoin = (ParcelJoinPacket)Pack;
  4748. handlerParcelJoinRequest = OnParcelJoinRequest;
  4749. if (handlerParcelJoinRequest != null)
  4750. {
  4751. handlerParcelJoinRequest((int)Math.Round(landJoin.ParcelData.West),
  4752. (int)Math.Round(landJoin.ParcelData.South),
  4753. (int)Math.Round(landJoin.ParcelData.East),
  4754. (int)Math.Round(landJoin.ParcelData.North), this);
  4755. }
  4756. break;
  4757. case PacketType.ParcelPropertiesUpdate:
  4758. ParcelPropertiesUpdatePacket parcelPropertiesPacket = (ParcelPropertiesUpdatePacket)Pack;
  4759. handlerParcelPropertiesUpdateRequest = OnParcelPropertiesUpdateRequest;
  4760. if (handlerParcelPropertiesUpdateRequest != null)
  4761. {
  4762. LandUpdateArgs args = new LandUpdateArgs();
  4763. args.AuthBuyerID = parcelPropertiesPacket.ParcelData.AuthBuyerID;
  4764. args.Category = (Parcel.ParcelCategory)parcelPropertiesPacket.ParcelData.Category;
  4765. args.Desc = Helpers.FieldToUTF8String(parcelPropertiesPacket.ParcelData.Desc);
  4766. args.GroupID = parcelPropertiesPacket.ParcelData.GroupID;
  4767. args.LandingType = parcelPropertiesPacket.ParcelData.LandingType;
  4768. args.MediaAutoScale = parcelPropertiesPacket.ParcelData.MediaAutoScale;
  4769. args.MediaID = parcelPropertiesPacket.ParcelData.MediaID;
  4770. args.MediaURL = Helpers.FieldToUTF8String(parcelPropertiesPacket.ParcelData.MediaURL);
  4771. args.MusicURL = Helpers.FieldToUTF8String(parcelPropertiesPacket.ParcelData.MusicURL);
  4772. args.Name = Helpers.FieldToUTF8String(parcelPropertiesPacket.ParcelData.Name);
  4773. args.ParcelFlags = parcelPropertiesPacket.ParcelData.ParcelFlags;
  4774. args.PassHours = parcelPropertiesPacket.ParcelData.PassHours;
  4775. args.PassPrice = parcelPropertiesPacket.ParcelData.PassPrice;
  4776. args.SalePrice = parcelPropertiesPacket.ParcelData.SalePrice;
  4777. args.SnapshotID = parcelPropertiesPacket.ParcelData.SnapshotID;
  4778. args.UserLocation = parcelPropertiesPacket.ParcelData.UserLocation;
  4779. args.UserLookAt = parcelPropertiesPacket.ParcelData.UserLookAt;
  4780. handlerParcelPropertiesUpdateRequest(args, parcelPropertiesPacket.ParcelData.LocalID, this);
  4781. }
  4782. break;
  4783. case PacketType.ParcelSelectObjects:
  4784. ParcelSelectObjectsPacket selectPacket = (ParcelSelectObjectsPacket)Pack;
  4785. handlerParcelSelectObjects = OnParcelSelectObjects;
  4786. if (handlerParcelSelectObjects != null)
  4787. {
  4788. handlerParcelSelectObjects(selectPacket.ParcelData.LocalID,
  4789. Convert.ToInt32(selectPacket.ParcelData.ReturnType), this);
  4790. }
  4791. break;
  4792. case PacketType.ParcelObjectOwnersRequest:
  4793. //Console.WriteLine(Pack.ToString());
  4794. ParcelObjectOwnersRequestPacket reqPacket = (ParcelObjectOwnersRequestPacket)Pack;
  4795. handlerParcelObjectOwnerRequest = OnParcelObjectOwnerRequest;
  4796. if (handlerParcelObjectOwnerRequest != null)
  4797. {
  4798. handlerParcelObjectOwnerRequest(reqPacket.ParcelData.LocalID, this);
  4799. }
  4800. break;
  4801. case PacketType.ParcelRelease:
  4802. ParcelReleasePacket releasePacket = (ParcelReleasePacket)Pack;
  4803. handlerParcelAbandonRequest = OnParcelAbandonRequest;
  4804. if (handlerParcelAbandonRequest != null)
  4805. {
  4806. handlerParcelAbandonRequest(releasePacket.Data.LocalID, this);
  4807. }
  4808. break;
  4809. case PacketType.ParcelReturnObjects:
  4810. ParcelReturnObjectsPacket parcelReturnObjects = (ParcelReturnObjectsPacket)Pack;
  4811. LLUUID[] puserselectedOwnerIDs = new LLUUID[parcelReturnObjects.OwnerIDs.Length];
  4812. for (int parceliterator = 0; parceliterator < parcelReturnObjects.OwnerIDs.Length; parceliterator++)
  4813. puserselectedOwnerIDs[parceliterator] = parcelReturnObjects.OwnerIDs[parceliterator].OwnerID;
  4814. LLUUID[] puserselectedTaskIDs = new LLUUID[parcelReturnObjects.TaskIDs.Length];
  4815. for (int parceliterator = 0; parceliterator < parcelReturnObjects.TaskIDs.Length; parceliterator++)
  4816. puserselectedTaskIDs[parceliterator] = parcelReturnObjects.TaskIDs[parceliterator].TaskID;
  4817. handlerParcelReturnObjectsRequest = OnParcelReturnObjectsRequest;
  4818. if (handlerParcelReturnObjectsRequest != null)
  4819. {
  4820. handlerParcelReturnObjectsRequest(parcelReturnObjects.ParcelData.LocalID,parcelReturnObjects.ParcelData.ReturnType,puserselectedOwnerIDs,puserselectedTaskIDs, this);
  4821. }
  4822. break;
  4823. #endregion
  4824. #region Estate Packets
  4825. case PacketType.EstateOwnerMessage:
  4826. EstateOwnerMessagePacket messagePacket = (EstateOwnerMessagePacket)Pack;
  4827. switch (Helpers.FieldToUTF8String(messagePacket.MethodData.Method))
  4828. {
  4829. case "getinfo":
  4830. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4831. {
  4832. OnDetailedEstateDataRequest(this, messagePacket.MethodData.Invoice);
  4833. }
  4834. break;
  4835. case "setregioninfo":
  4836. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4837. {
  4838. OnSetEstateFlagsRequest(convertParamStringToBool(messagePacket.ParamList[0].Parameter),convertParamStringToBool(messagePacket.ParamList[1].Parameter),
  4839. convertParamStringToBool(messagePacket.ParamList[2].Parameter), !convertParamStringToBool(messagePacket.ParamList[3].Parameter),
  4840. Convert.ToInt16(Convert.ToDecimal(Helpers.FieldToUTF8String(messagePacket.ParamList[4].Parameter))),
  4841. (float)Convert.ToDecimal(Helpers.FieldToUTF8String(messagePacket.ParamList[5].Parameter)),
  4842. Convert.ToInt16(Helpers.FieldToUTF8String(messagePacket.ParamList[6].Parameter)),
  4843. convertParamStringToBool(messagePacket.ParamList[7].Parameter),convertParamStringToBool(messagePacket.ParamList[8].Parameter));
  4844. }
  4845. break;
  4846. case "texturebase":
  4847. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4848. {
  4849. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  4850. {
  4851. string s = Helpers.FieldToUTF8String(block.Parameter);
  4852. string[] splitField = s.Split(' ');
  4853. if (splitField.Length == 2)
  4854. {
  4855. LLUUID tempUUID = new LLUUID(splitField[1]);
  4856. OnSetEstateTerrainBaseTexture(this, Convert.ToInt16(splitField[0]), tempUUID);
  4857. }
  4858. }
  4859. }
  4860. break;
  4861. case "texturedetail":
  4862. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4863. {
  4864. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  4865. {
  4866. string s = Helpers.FieldToUTF8String(block.Parameter);
  4867. string[] splitField = s.Split(' ');
  4868. if (splitField.Length == 2)
  4869. {
  4870. Int16 corner = Convert.ToInt16(splitField[0]);
  4871. LLUUID textureUUID = new LLUUID(splitField[1]);
  4872. OnSetEstateTerrainDetailTexture(this, corner,textureUUID);
  4873. }
  4874. }
  4875. }
  4876. break;
  4877. case "textureheights":
  4878. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4879. {
  4880. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  4881. {
  4882. string s = Helpers.FieldToUTF8String(block.Parameter);
  4883. string[] splitField = s.Split(' ');
  4884. if (splitField.Length == 3)
  4885. {
  4886. Int16 corner = Convert.ToInt16(splitField[0]);
  4887. float lowValue = (float)Convert.ToDecimal(splitField[1]);
  4888. float highValue = (float)Convert.ToDecimal(splitField[2]);
  4889. OnSetEstateTerrainTextureHeights(this,corner,lowValue,highValue);
  4890. }
  4891. }
  4892. }
  4893. break;
  4894. case "texturecommit":
  4895. OnCommitEstateTerrainTextureRequest(this);
  4896. break;
  4897. case "setregionterrain":
  4898. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4899. {
  4900. if (messagePacket.ParamList.Length != 9)
  4901. {
  4902. m_log.Error("EstateOwnerMessage: SetRegionTerrain method has a ParamList of invalid length");
  4903. }
  4904. else
  4905. {
  4906. try
  4907. {
  4908. string tmp;
  4909. tmp = Helpers.FieldToUTF8String(messagePacket.ParamList[0].Parameter);
  4910. if (!tmp.Contains(".")) tmp += ".00";
  4911. float WaterHeight = (float)Convert.ToDecimal(tmp);
  4912. tmp = Helpers.FieldToUTF8String(messagePacket.ParamList[1].Parameter);
  4913. if (!tmp.Contains(".")) tmp += ".00";
  4914. float TerrainRaiseLimit = (float)Convert.ToDecimal(tmp);
  4915. tmp = Helpers.FieldToUTF8String(messagePacket.ParamList[2].Parameter);
  4916. if (!tmp.Contains(".")) tmp += ".00";
  4917. float TerrainLowerLimit = (float)Convert.ToDecimal(tmp);
  4918. bool UseFixedSun = convertParamStringToBool(messagePacket.ParamList[4].Parameter);
  4919. float SunHour = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(messagePacket.ParamList[5].Parameter));
  4920. OnSetRegionTerrainSettings(WaterHeight, TerrainRaiseLimit, TerrainLowerLimit, UseFixedSun, SunHour);
  4921. }
  4922. catch (Exception ex)
  4923. {
  4924. m_log.Error("EstateOwnerMessage: Exception while setting terrain settings: \n" + messagePacket.ToString() + "\n" + ex.ToString());
  4925. }
  4926. }
  4927. }
  4928. break;
  4929. case "restart":
  4930. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4931. {
  4932. // There's only 1 block in the estateResetSim.. and that's the number of seconds till restart.
  4933. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  4934. {
  4935. float timeSeconds = 0;
  4936. Helpers.TryParse(Helpers.FieldToUTF8String(block.Parameter), out timeSeconds);
  4937. timeSeconds = (int)timeSeconds;
  4938. OnEstateRestartSimRequest(this, (int)timeSeconds);
  4939. }
  4940. }
  4941. break;
  4942. case "estatechangecovenantid":
  4943. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4944. {
  4945. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  4946. {
  4947. LLUUID newCovenantID = new LLUUID(Helpers.FieldToUTF8String(block.Parameter));
  4948. OnEstateChangeCovenantRequest(this, newCovenantID);
  4949. }
  4950. }
  4951. break;
  4952. case "estateaccessdelta": // Estate access delta manages the banlist and allow list too.
  4953. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4954. {
  4955. int estateAccessType = Convert.ToInt16(Helpers.FieldToUTF8String(messagePacket.ParamList[1].Parameter));
  4956. OnUpdateEstateAccessDeltaRequest(this, messagePacket.MethodData.Invoice,estateAccessType,new LLUUID(Helpers.FieldToUTF8String(messagePacket.ParamList[2].Parameter)));
  4957. }
  4958. break;
  4959. case "simulatormessage":
  4960. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4961. {
  4962. LLUUID invoice = messagePacket.MethodData.Invoice;
  4963. LLUUID SenderID = new LLUUID(Helpers.FieldToUTF8String(messagePacket.ParamList[2].Parameter));
  4964. string SenderName = Helpers.FieldToUTF8String(messagePacket.ParamList[3].Parameter);
  4965. string Message = Helpers.FieldToUTF8String(messagePacket.ParamList[4].Parameter);
  4966. LLUUID sessionID = messagePacket.AgentData.SessionID;
  4967. OnSimulatorBlueBoxMessageRequest(this,invoice,SenderID, sessionID, SenderName,Message);
  4968. }
  4969. break;
  4970. case "instantmessage":
  4971. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4972. {
  4973. LLUUID invoice = messagePacket.MethodData.Invoice;
  4974. LLUUID SenderID = new LLUUID(Helpers.FieldToUTF8String(messagePacket.ParamList[2].Parameter));
  4975. string SenderName = Helpers.FieldToUTF8String(messagePacket.ParamList[3].Parameter);
  4976. string Message = Helpers.FieldToUTF8String(messagePacket.ParamList[4].Parameter);
  4977. LLUUID sessionID = messagePacket.AgentData.SessionID;
  4978. OnEstateBlueBoxMessageRequest(this,invoice,SenderID, sessionID, SenderName,Message);
  4979. }
  4980. break;
  4981. case "setregiondebug":
  4982. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4983. {
  4984. LLUUID invoice = messagePacket.MethodData.Invoice;
  4985. LLUUID SenderID = messagePacket.AgentData.AgentID;
  4986. bool scripted = convertParamStringToBool(messagePacket.ParamList[0].Parameter);
  4987. bool collisionEvents = convertParamStringToBool(messagePacket.ParamList[1].Parameter);
  4988. bool physics = convertParamStringToBool(messagePacket.ParamList[2].Parameter);
  4989. OnEstateDebugRegionRequest(this, invoice,SenderID,scripted,collisionEvents,physics);
  4990. }
  4991. break;
  4992. case "teleporthomeuser":
  4993. if (((Scene)m_scene).ExternalChecks.ExternalChecksCanIssueEstateCommand(this.AgentId))
  4994. {
  4995. LLUUID invoice = messagePacket.MethodData.Invoice;
  4996. LLUUID SenderID = messagePacket.AgentData.AgentID;
  4997. LLUUID Prey = LLUUID.Zero;
  4998. Helpers.TryParse(Helpers.FieldToUTF8String(messagePacket.ParamList[1].Parameter), out Prey);
  4999. OnEstateTeleportOneUserHomeRequest(this,invoice,SenderID,Prey);
  5000. }
  5001. break;
  5002. case "colliders":
  5003. handlerLandStatRequest = OnLandStatRequest;
  5004. if (handlerLandStatRequest != null)
  5005. {
  5006. handlerLandStatRequest(0, 1, 0, "", this);
  5007. }
  5008. break;
  5009. case "scripts":
  5010. handlerLandStatRequest = OnLandStatRequest;
  5011. if (handlerLandStatRequest != null)
  5012. {
  5013. handlerLandStatRequest(0, 0, 0, "", this);
  5014. }
  5015. break;
  5016. default:
  5017. m_log.Error("EstateOwnerMessage: Unknown method requested\n" + messagePacket.ToString());
  5018. break;
  5019. }
  5020. break;
  5021. case PacketType.LandStatRequest:
  5022. LandStatRequestPacket lsrp = (LandStatRequestPacket)Pack;
  5023. handlerLandStatRequest = OnLandStatRequest;
  5024. if (handlerLandStatRequest != null)
  5025. {
  5026. handlerLandStatRequest(lsrp.RequestData.ParcelLocalID,lsrp.RequestData.ReportType,lsrp.RequestData.RequestFlags,Helpers.FieldToUTF8String(lsrp.RequestData.Filter),this);
  5027. }
  5028. //int parcelID, uint reportType, uint requestflags, string filter
  5029. //lsrp.RequestData.ParcelLocalID;
  5030. //lsrp.RequestData.ReportType; // 1 = colliders, 0 = scripts
  5031. //lsrp.RequestData.RequestFlags;
  5032. //lsrp.RequestData.Filter;
  5033. break;
  5034. case PacketType.RequestRegionInfo:
  5035. RequestRegionInfoPacket.AgentDataBlock mPacket = ((RequestRegionInfoPacket)Pack).AgentData;
  5036. handlerRegionInfoRequest = OnRegionInfoRequest;
  5037. if (handlerRegionInfoRequest != null)
  5038. {
  5039. handlerRegionInfoRequest(this);
  5040. }
  5041. break;
  5042. case PacketType.EstateCovenantRequest:
  5043. EstateCovenantRequestPacket.AgentDataBlock epack =
  5044. ((EstateCovenantRequestPacket)Pack).AgentData;
  5045. handlerEstateCovenantRequest = OnEstateCovenantRequest;
  5046. if (handlerEstateCovenantRequest != null)
  5047. {
  5048. handlerEstateCovenantRequest(this);
  5049. }
  5050. break;
  5051. #endregion
  5052. #region GodPackets
  5053. case PacketType.RequestGodlikePowers:
  5054. RequestGodlikePowersPacket rglpPack = (RequestGodlikePowersPacket)Pack;
  5055. RequestGodlikePowersPacket.RequestBlockBlock rblock = rglpPack.RequestBlock;
  5056. LLUUID token = rblock.Token;
  5057. RequestGodlikePowersPacket.AgentDataBlock ablock = rglpPack.AgentData;
  5058. handlerReqGodlikePowers = OnRequestGodlikePowers;
  5059. if (handlerReqGodlikePowers != null)
  5060. {
  5061. handlerReqGodlikePowers(ablock.AgentID, ablock.SessionID, token, rblock.Godlike, this);
  5062. }
  5063. break;
  5064. case PacketType.GodKickUser:
  5065. m_log.Warn("[CLIENT]: unhandled GodKickUser packet");
  5066. GodKickUserPacket gkupack = (GodKickUserPacket)Pack;
  5067. if (gkupack.UserInfo.GodSessionID == SessionId && AgentId == gkupack.UserInfo.GodID)
  5068. {
  5069. handlerGodKickUser = OnGodKickUser;
  5070. if (handlerGodKickUser != null)
  5071. {
  5072. handlerGodKickUser(gkupack.UserInfo.GodID, gkupack.UserInfo.GodSessionID,
  5073. gkupack.UserInfo.AgentID, (uint)0, gkupack.UserInfo.Reason);
  5074. }
  5075. }
  5076. else
  5077. {
  5078. SendAgentAlertMessage("Kick request denied", false);
  5079. }
  5080. //KickUserPacket kupack = new KickUserPacket();
  5081. //KickUserPacket.UserInfoBlock kupackib = kupack.UserInfo;
  5082. //kupack.UserInfo.AgentID = gkupack.UserInfo.AgentID;
  5083. //kupack.UserInfo.SessionID = gkupack.UserInfo.GodSessionID;
  5084. //kupack.TargetBlock.TargetIP = (uint)0;
  5085. //kupack.TargetBlock.TargetPort = (ushort)0;
  5086. //kupack.UserInfo.Reason = gkupack.UserInfo.Reason;
  5087. //OutPacket(kupack, ThrottleOutPacketType.Task);
  5088. break;
  5089. #endregion
  5090. #region Economy/Transaction Packets
  5091. case PacketType.MoneyBalanceRequest:
  5092. MoneyBalanceRequestPacket moneybalancerequestpacket = (MoneyBalanceRequestPacket)Pack;
  5093. handlerMoneyBalanceRequest = OnMoneyBalanceRequest;
  5094. if (handlerMoneyBalanceRequest != null)
  5095. {
  5096. handlerMoneyBalanceRequest(this, moneybalancerequestpacket.AgentData.AgentID, moneybalancerequestpacket.AgentData.SessionID, moneybalancerequestpacket.MoneyData.TransactionID);
  5097. }
  5098. break;
  5099. case PacketType.EconomyDataRequest:
  5100. handlerEconomoyDataRequest = OnEconomyDataRequest;
  5101. if (handlerEconomoyDataRequest != null)
  5102. {
  5103. handlerEconomoyDataRequest(AgentId);
  5104. }
  5105. // TODO: handle this packet
  5106. //m_log.Warn("[CLIENT]: unhandled EconomyDataRequest packet");
  5107. break;
  5108. case PacketType.RequestPayPrice:
  5109. RequestPayPricePacket requestPayPricePacket = (RequestPayPricePacket)Pack;
  5110. handlerRequestPayPrice = OnRequestPayPrice;
  5111. if (handlerRequestPayPrice != null)
  5112. {
  5113. handlerRequestPayPrice(this, requestPayPricePacket.ObjectData.ObjectID);
  5114. }
  5115. break;
  5116. #endregion
  5117. #region unimplemented handlers
  5118. case PacketType.StartPingCheck:
  5119. // Send the client the ping response back
  5120. // Pass the same PingID in the matching packet
  5121. // Handled In the packet processing
  5122. //m_log.Debug("[CLIENT]: possibly unhandled StartPingCheck packet");
  5123. break;
  5124. case PacketType.CompletePingCheck:
  5125. // TODO: Perhaps this should be processed on the Sim to determine whether or not to drop a dead client
  5126. //m_log.Warn("[CLIENT]: unhandled CompletePingCheck packet");
  5127. break;
  5128. case PacketType.ScriptReset:
  5129. ScriptResetPacket scriptResetPacket = (ScriptResetPacket)Pack;
  5130. handlerScriptReset = OnScriptReset;
  5131. if (handlerScriptReset != null)
  5132. {
  5133. handlerScriptReset(this, scriptResetPacket.Script.ObjectID, scriptResetPacket.Script.ItemID);
  5134. }
  5135. break;
  5136. case PacketType.ViewerStats:
  5137. // TODO: handle this packet
  5138. m_log.Warn("[CLIENT]: unhandled ViewerStats packet");
  5139. break;
  5140. case PacketType.CreateGroupRequest:
  5141. // TODO: handle this packet
  5142. m_log.Warn("[CLIENT]: unhandled CreateGroupRequest packet");
  5143. break;
  5144. case PacketType.GenericMessage:
  5145. // TODO: handle this packet
  5146. m_log.Warn("[CLIENT]: unhandled GenericMessage packet");
  5147. break;
  5148. case PacketType.MapItemRequest:
  5149. // TODO: handle this packet
  5150. m_log.Warn("[CLIENT]: unhandled MapItemRequest packet");
  5151. break;
  5152. case PacketType.TransferAbort:
  5153. // TODO: handle this packet
  5154. m_log.Warn("[CLIENT]: unhandled TransferAbort packet");
  5155. break;
  5156. case PacketType.MuteListRequest:
  5157. // TODO: handle this packet
  5158. m_log.Warn("[CLIENT]: unhandled MuteListRequest packet");
  5159. break;
  5160. case PacketType.ParcelDwellRequest:
  5161. // TODO: handle this packet
  5162. m_log.Warn("[CLIENT]: unhandled ParcelDwellRequest packet");
  5163. break;
  5164. case PacketType.UseCircuitCode:
  5165. // TODO: Don't display this one, we handle it at a lower level
  5166. //m_log.Warn("[CLIENT]: unhandled UseCircuitCode packet");
  5167. break;
  5168. case PacketType.AgentHeightWidth:
  5169. // TODO: handle this packet
  5170. m_log.Warn("[CLIENT]: unhandled AgentHeightWidth packet");
  5171. break;
  5172. case PacketType.ObjectSpinStop:
  5173. // TODO: handle this packet
  5174. m_log.Warn("[CLIENT]: unhandled ObjectSpinStop packet");
  5175. break;
  5176. case PacketType.SoundTrigger:
  5177. // TODO: handle this packet
  5178. m_log.Warn("[CLIENT]: unhandled SoundTrigger packet");
  5179. break;
  5180. case PacketType.InventoryDescendents:
  5181. // TODO: handle this packet
  5182. m_log.Warn("[CLIENT]: unhandled InventoryDescent packet");
  5183. break;
  5184. case PacketType.GetScriptRunning:
  5185. m_log.Warn("[CLIENT]: unhandled GetScriptRunning packet");
  5186. break;
  5187. default:
  5188. m_log.Warn("[CLIENT]: unhandled packet " + Pack.ToString());
  5189. break;
  5190. #endregion
  5191. }
  5192. }
  5193. PacketPool.Instance.ReturnPacket(Pack);
  5194. }
  5195. private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)
  5196. {
  5197. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  5198. shape.PCode = addPacket.ObjectData.PCode;
  5199. shape.State = addPacket.ObjectData.State;
  5200. shape.PathBegin = addPacket.ObjectData.PathBegin;
  5201. shape.PathEnd = addPacket.ObjectData.PathEnd;
  5202. shape.PathScaleX = addPacket.ObjectData.PathScaleX;
  5203. shape.PathScaleY = addPacket.ObjectData.PathScaleY;
  5204. shape.PathShearX = addPacket.ObjectData.PathShearX;
  5205. shape.PathShearY = addPacket.ObjectData.PathShearY;
  5206. shape.PathSkew = addPacket.ObjectData.PathSkew;
  5207. shape.ProfileBegin = addPacket.ObjectData.ProfileBegin;
  5208. shape.ProfileEnd = addPacket.ObjectData.ProfileEnd;
  5209. shape.Scale = addPacket.ObjectData.Scale;
  5210. shape.PathCurve = addPacket.ObjectData.PathCurve;
  5211. shape.ProfileCurve = addPacket.ObjectData.ProfileCurve;
  5212. shape.ProfileHollow = addPacket.ObjectData.ProfileHollow;
  5213. shape.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
  5214. shape.PathRevolutions = addPacket.ObjectData.PathRevolutions;
  5215. shape.PathTaperX = addPacket.ObjectData.PathTaperX;
  5216. shape.PathTaperY = addPacket.ObjectData.PathTaperY;
  5217. shape.PathTwist = addPacket.ObjectData.PathTwist;
  5218. shape.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
  5219. LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("89556747-24cb-43ed-920b-47caed15465f"));
  5220. shape.TextureEntry = ntex.ToBytes();
  5221. //shape.Textures = ntex;
  5222. return shape;
  5223. }
  5224. public void SendBlueBoxMessage(LLUUID FromAvatarID, LLUUID fromSessionID, String FromAvatarName, String Message)
  5225. {
  5226. if (!ChildAgentStatus())
  5227. SendInstantMessage(FromAvatarID, fromSessionID, Message, AgentId, SessionId, FromAvatarName, (byte)1, (uint)Util.UnixTimeSinceEpoch());
  5228. //SendInstantMessage(FromAvatarID, fromSessionID, Message, AgentId, SessionId, FromAvatarName, (byte)21,(uint) Util.UnixTimeSinceEpoch());
  5229. }
  5230. public void SendLogoutPacket()
  5231. {
  5232. LogoutReplyPacket logReply = (LogoutReplyPacket)PacketPool.Instance.GetPacket(PacketType.LogoutReply);
  5233. // TODO: don't create new blocks if recycling an old packet
  5234. logReply.AgentData.AgentID = AgentId;
  5235. logReply.AgentData.SessionID = SessionId;
  5236. logReply.InventoryData = new LogoutReplyPacket.InventoryDataBlock[1];
  5237. logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock();
  5238. logReply.InventoryData[0].ItemID = LLUUID.Zero;
  5239. OutPacket(logReply, ThrottleOutPacketType.Task);
  5240. }
  5241. public void SendHealth(float health)
  5242. {
  5243. HealthMessagePacket healthpacket = (HealthMessagePacket)PacketPool.Instance.GetPacket(PacketType.HealthMessage);
  5244. healthpacket.HealthData.Health = health;
  5245. OutPacket(healthpacket, ThrottleOutPacketType.Task);
  5246. }
  5247. public void SendAgentOnline(LLUUID[] agentIDs)
  5248. {
  5249. OnlineNotificationPacket onp = new OnlineNotificationPacket();
  5250. OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[agentIDs.Length];
  5251. for (int i = 0; i < agentIDs.Length; i++)
  5252. {
  5253. OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock();
  5254. onpbl.AgentID = agentIDs[i];
  5255. onpb[i] = onpbl;
  5256. }
  5257. onp.AgentBlock = onpb;
  5258. OutPacket(onp, ThrottleOutPacketType.Task);
  5259. }
  5260. public void SendAgentOffline(LLUUID[] agentIDs)
  5261. {
  5262. OfflineNotificationPacket offp = new OfflineNotificationPacket();
  5263. OfflineNotificationPacket.AgentBlockBlock[] offpb = new OfflineNotificationPacket.AgentBlockBlock[agentIDs.Length];
  5264. for (int i = 0; i < agentIDs.Length; i++)
  5265. {
  5266. OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock();
  5267. onpbl.AgentID = agentIDs[i];
  5268. offpb[i] = onpbl;
  5269. }
  5270. offp.AgentBlock = offpb;
  5271. OutPacket(offp, ThrottleOutPacketType.Task);
  5272. }
  5273. public void SendSitResponse(LLUUID TargetID, LLVector3 OffsetPos, LLQuaternion SitOrientation, bool autopilot,
  5274. LLVector3 CameraAtOffset, LLVector3 CameraEyeOffset, bool ForceMouseLook)
  5275. {
  5276. AvatarSitResponsePacket avatarSitResponse = new AvatarSitResponsePacket();
  5277. avatarSitResponse.SitObject.ID = TargetID;
  5278. if (CameraAtOffset != LLVector3.Zero)
  5279. {
  5280. avatarSitResponse.SitTransform.CameraAtOffset = CameraAtOffset;
  5281. avatarSitResponse.SitTransform.CameraEyeOffset = CameraEyeOffset;
  5282. }
  5283. avatarSitResponse.SitTransform.ForceMouselook = ForceMouseLook;
  5284. avatarSitResponse.SitTransform.AutoPilot = autopilot;
  5285. avatarSitResponse.SitTransform.SitPosition = OffsetPos;
  5286. avatarSitResponse.SitTransform.SitRotation = SitOrientation;
  5287. OutPacket(avatarSitResponse, ThrottleOutPacketType.Task);
  5288. }
  5289. public void SendAdminResponse(LLUUID Token, uint AdminLevel)
  5290. {
  5291. GrantGodlikePowersPacket respondPacket = new GrantGodlikePowersPacket();
  5292. GrantGodlikePowersPacket.GrantDataBlock gdb = new GrantGodlikePowersPacket.GrantDataBlock();
  5293. GrantGodlikePowersPacket.AgentDataBlock adb = new GrantGodlikePowersPacket.AgentDataBlock();
  5294. adb.AgentID = AgentId;
  5295. adb.SessionID = SessionId; // More security
  5296. gdb.GodLevel = (byte)AdminLevel;
  5297. gdb.Token = Token;
  5298. //respondPacket.AgentData = (GrantGodlikePowersPacket.AgentDataBlock)ablock;
  5299. respondPacket.GrantData = gdb;
  5300. respondPacket.AgentData = adb;
  5301. OutPacket(respondPacket, ThrottleOutPacketType.Task);
  5302. }
  5303. public void SendGroupMembership(GroupData[] GroupMembership)
  5304. {
  5305. AgentGroupDataUpdatePacket Groupupdate = new AgentGroupDataUpdatePacket();
  5306. AgentGroupDataUpdatePacket.GroupDataBlock[] Groups = new AgentGroupDataUpdatePacket.GroupDataBlock[GroupMembership.Length];
  5307. for (int i = 0; i < GroupMembership.Length; i++)
  5308. {
  5309. AgentGroupDataUpdatePacket.GroupDataBlock Group = new AgentGroupDataUpdatePacket.GroupDataBlock();
  5310. Group.AcceptNotices = GroupMembership[i].AcceptNotices;
  5311. Group.Contribution = GroupMembership[i].contribution;
  5312. Group.GroupID = GroupMembership[i].GroupID;
  5313. Group.GroupInsigniaID = GroupMembership[i].GroupPicture;
  5314. Group.GroupName = Helpers.StringToField(GroupMembership[i].groupName);
  5315. Group.GroupPowers = GroupMembership[i].groupPowers;
  5316. Groups[i] = Group;
  5317. Groupupdate.GroupData = Groups;
  5318. }
  5319. Groupupdate.AgentData.AgentID = AgentId;
  5320. OutPacket(Groupupdate, ThrottleOutPacketType.Task);
  5321. }
  5322. public void SendGroupNameReply(LLUUID groupLLUID, string GroupName)
  5323. {
  5324. UUIDGroupNameReplyPacket pack = new UUIDGroupNameReplyPacket();
  5325. UUIDGroupNameReplyPacket.UUIDNameBlockBlock[] uidnameblock = new UUIDGroupNameReplyPacket.UUIDNameBlockBlock[1];
  5326. UUIDGroupNameReplyPacket.UUIDNameBlockBlock uidnamebloc = new UUIDGroupNameReplyPacket.UUIDNameBlockBlock();
  5327. uidnamebloc.ID = groupLLUID;
  5328. uidnamebloc.GroupName = Helpers.StringToField(GroupName);
  5329. uidnameblock[0] = uidnamebloc;
  5330. pack.UUIDNameBlock = uidnameblock;
  5331. OutPacket(pack, ThrottleOutPacketType.Task);
  5332. }
  5333. public void SendLandStatReply(uint reportType, uint requestFlags, uint resultCount, LandStatReportItem[] lsrpia)
  5334. {
  5335. LandStatReplyPacket lsrp = new LandStatReplyPacket();
  5336. LandStatReplyPacket.RequestDataBlock lsreqdpb = new LandStatReplyPacket.RequestDataBlock();
  5337. LandStatReplyPacket.ReportDataBlock[] lsrepdba = new LandStatReplyPacket.ReportDataBlock[lsrpia.Length];
  5338. //LandStatReplyPacket.ReportDataBlock lsrepdb = new LandStatReplyPacket.ReportDataBlock();
  5339. // lsrepdb.
  5340. lsrp.RequestData.ReportType = reportType;
  5341. lsrp.RequestData.RequestFlags = requestFlags;
  5342. lsrp.RequestData.TotalObjectCount = resultCount;
  5343. for (int i = 0; i < lsrpia.Length; i++)
  5344. {
  5345. LandStatReplyPacket.ReportDataBlock lsrepdb = new LandStatReplyPacket.ReportDataBlock();
  5346. lsrepdb.LocationX = lsrpia[i].LocationX;
  5347. lsrepdb.LocationY = lsrpia[i].LocationY;
  5348. lsrepdb.LocationZ = lsrpia[i].LocationZ;
  5349. lsrepdb.Score = lsrpia[i].Score;
  5350. lsrepdb.TaskID = lsrpia[i].TaskID;
  5351. lsrepdb.TaskLocalID = lsrpia[i].TaskLocalID;
  5352. lsrepdb.TaskName = Helpers.StringToField(lsrpia[i].TaskName);
  5353. lsrepdb.OwnerName = Helpers.StringToField(lsrpia[i].OwnerName);
  5354. lsrepdba[i] = lsrepdb;
  5355. }
  5356. lsrp.ReportData = lsrepdba;
  5357. OutPacket(lsrp, ThrottleOutPacketType.Task);
  5358. }
  5359. public ClientInfo GetClientInfo()
  5360. {
  5361. //MainLog.Instance.Verbose("CLIENT", "GetClientInfo BGN");
  5362. ClientInfo info = new ClientInfo();
  5363. info.userEP = this.m_userEndPoint;
  5364. info.proxyEP = this.m_proxyEndPoint;
  5365. info.agentcircuit = new sAgentCircuitData(RequestClientInfo());
  5366. info.pendingAcks = m_pendingAcks;
  5367. info.needAck = new Dictionary<uint,byte[]>();
  5368. lock (m_needAck)
  5369. {
  5370. foreach (uint key in m_needAck.Keys)
  5371. {
  5372. info.needAck.Add(key, m_needAck[key].ToBytes());
  5373. }
  5374. }
  5375. /* pending
  5376. QueItem[] queitems = m_packetQueue.GetQueueArray();
  5377. MainLog.Instance.Verbose("CLIENT", "Queue Count : [{0}]", queitems.Length);
  5378. for (int i = 0; i < queitems.Length; i++)
  5379. {
  5380. if (queitems[i].Incoming == false)
  5381. {
  5382. info.out_packets.Add(queitems[i].Packet.ToBytes());
  5383. MainLog.Instance.Verbose("CLIENT", "Add OutPacket [{0}]", queitems[i].Packet.Type.ToString());
  5384. }
  5385. }
  5386. */
  5387. info.sequence = m_sequence;
  5388. //MainLog.Instance.Verbose("CLIENT", "GetClientInfo END");
  5389. return info;
  5390. }
  5391. public void SetClientInfo(ClientInfo info)
  5392. {
  5393. m_pendingAcks = info.pendingAcks;
  5394. m_needAck = new Dictionary<uint,Packet>();
  5395. Packet packet = null;
  5396. int packetEnd = 0;
  5397. byte[] zero = new byte[3000];
  5398. foreach (uint key in info.needAck.Keys)
  5399. {
  5400. byte[] buff = info.needAck[key];
  5401. packetEnd = buff.Length - 1;
  5402. try
  5403. {
  5404. packet = PacketPool.Instance.GetPacket(buff, ref packetEnd, zero);
  5405. }
  5406. catch (Exception)
  5407. {
  5408. }
  5409. m_needAck.Add(key, packet);
  5410. }
  5411. m_sequence = info.sequence;
  5412. }
  5413. }
  5414. }