LLClientView.cs 501 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using System.Reflection;
  32. using System.Text;
  33. using System.Threading;
  34. using System.Timers;
  35. using System.Xml;
  36. using log4net;
  37. using OpenMetaverse;
  38. using OpenMetaverse.Packets;
  39. using OpenSim.Framework;
  40. using OpenSim.Framework.Client;
  41. using OpenSim.Framework.Communications.Cache;
  42. using OpenSim.Framework.Statistics;
  43. using OpenSim.Region.Framework.Interfaces;
  44. using OpenSim.Region.Framework.Scenes;
  45. using OpenSim.Services.Interfaces;
  46. using Timer=System.Timers.Timer;
  47. using AssetLandmark = OpenSim.Framework.AssetLandmark;
  48. using Nini.Config;
  49. namespace OpenSim.Region.ClientStack.LindenUDP
  50. {
  51. public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
  52. /// <summary>
  53. /// Handles new client connections
  54. /// Constructor takes a single Packet and authenticates everything
  55. /// </summary>
  56. public class LLClientView : IClientAPI, IClientCore, IClientIM, IClientChat, IClientIPEndpoint, IStatsCollector
  57. {
  58. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  59. /* static variables */
  60. public static SynchronizeClientHandler SynchronizeClient;
  61. /* private variables */
  62. private readonly UUID m_sessionId;
  63. private readonly UUID m_secureSessionId = UUID.Zero;
  64. private int m_debugPacketLevel;
  65. //private readonly IAssetCache m_assetCache;
  66. private int m_cachedTextureSerial;
  67. private Timer m_clientPingTimer;
  68. private Timer m_avatarTerseUpdateTimer;
  69. private List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> m_avatarTerseUpdates = new List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>();
  70. private Timer m_primTerseUpdateTimer;
  71. private List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> m_primTerseUpdates = new List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>();
  72. private Timer m_primFullUpdateTimer;
  73. private List<ObjectUpdatePacket.ObjectDataBlock> m_primFullUpdates =
  74. new List<ObjectUpdatePacket.ObjectDataBlock>();
  75. private Timer m_textureRequestTimer;
  76. private bool m_clientBlocked;
  77. private int m_probesWithNoIngressPackets;
  78. private readonly UUID m_agentId;
  79. private readonly uint m_circuitCode;
  80. private int m_moneyBalance;
  81. private readonly ILLPacketHandler m_PacketHandler;
  82. private int m_animationSequenceNumber = 1;
  83. private readonly byte[] m_channelVersion = Utils.StringToBytes("OpenSimulator Server"); // Dummy value needed by libSL
  84. private readonly Dictionary<string, UUID> m_defaultAnimations = new Dictionary<string, UUID>();
  85. private bool m_SendLogoutPacketWhenClosing = true;
  86. private int m_inPacketsChecked;
  87. // Used to adjust Sun Orbit values so Linden based viewers properly position sun
  88. private const float m_sunPainDaHalfOrbitalCutoff = 4.712388980384689858f;
  89. /* protected variables */
  90. protected static Dictionary<PacketType, PacketMethod> PacketHandlers =
  91. new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
  92. protected Dictionary<PacketType, PacketMethod> m_packetHandlers = new Dictionary<PacketType, PacketMethod>();
  93. protected Dictionary<string, GenericMessage> m_genericPacketHandlers = new Dictionary<string, GenericMessage>(); //PauPaw:Local Generic Message handlers
  94. protected IScene m_scene;
  95. protected LLPacketServer m_networkServer;
  96. protected LLImageManager m_imageManager;
  97. /* public variables */
  98. protected string m_firstName;
  99. protected string m_lastName;
  100. protected Thread m_clientThread;
  101. protected Vector3 m_startpos;
  102. protected EndPoint m_userEndPoint;
  103. protected EndPoint m_proxyEndPoint;
  104. protected UUID m_activeGroupID = UUID.Zero;
  105. protected string m_activeGroupName = String.Empty;
  106. protected ulong m_activeGroupPowers;
  107. protected Dictionary<UUID,ulong> m_groupPowers = new Dictionary<UUID, ulong>();
  108. protected int m_avatarTerseUpdateRate = 50;
  109. protected int m_avatarTerseUpdatesPerPacket = 5;
  110. // LL uses these limits, apparently. Compressed terse would be
  111. // 23, but we don't have that yet
  112. //
  113. protected int m_primTerseUpdatesPerPacket = 10;
  114. protected int m_primFullUpdatesPerPacket = 14;
  115. protected int m_primTerseUpdateRate = 10;
  116. protected int m_primFullUpdateRate = 14;
  117. protected int m_textureRequestRate = 100;
  118. protected int m_textureSendLimit = 10;
  119. protected int m_textureDataLimit = 5;
  120. protected int m_packetMTU = 1400;
  121. protected IAssetService m_assetService;
  122. // LLClientView Only
  123. public delegate void BinaryGenericMessage(Object sender, string method, byte[][] args);
  124. /* Instantiated Designated Event Delegates */
  125. //- used so we don't create new objects for each incoming packet and then toss it out later */
  126. private GenericMessage handlerGenericMessage;
  127. private RequestAvatarProperties handlerRequestAvatarProperties; //OnRequestAvatarProperties;
  128. private UpdateAvatarProperties handlerUpdateAvatarProperties; // OnUpdateAvatarProperties;
  129. private ChatMessage handlerChatFromClient; //OnChatFromClient;
  130. private ChatMessage handlerChatFromClient2; //OnChatFromClient;
  131. private ImprovedInstantMessage handlerInstantMessage; //OnInstantMessage;
  132. private FriendActionDelegate handlerApproveFriendRequest; //OnApproveFriendRequest;
  133. private FriendshipTermination handlerTerminateFriendship; //OnTerminateFriendship;
  134. private RezObject handlerRezObject; //OnRezObject;
  135. private DeRezObject handlerDeRezObject; //OnDeRezObject;
  136. private ModifyTerrain handlerModifyTerrain;
  137. private BakeTerrain handlerBakeTerrain;
  138. private EstateChangeInfo handlerEstateChangeInfo;
  139. private Action<IClientAPI> handlerRegionHandShakeReply; //OnRegionHandShakeReply;
  140. private GenericCall2 handlerRequestWearables; //OnRequestWearables;
  141. private Action<IClientAPI> handlerRequestAvatarsData; //OnRequestAvatarsData;
  142. private SetAppearance handlerSetAppearance; //OnSetAppearance;
  143. private AvatarNowWearing handlerAvatarNowWearing; //OnAvatarNowWearing;
  144. private RezSingleAttachmentFromInv handlerRezSingleAttachment; //OnRezSingleAttachmentFromInv;
  145. private RezMultipleAttachmentsFromInv handlerRezMultipleAttachments; //OnRezMultipleAttachmentsFromInv;
  146. private UUIDNameRequest handlerDetachAttachmentIntoInv; // Detach attachment!
  147. private ObjectAttach handlerObjectAttach; //OnObjectAttach;
  148. private SetAlwaysRun handlerSetAlwaysRun; //OnSetAlwaysRun;
  149. private GenericCall2 handlerCompleteMovementToRegion; //OnCompleteMovementToRegion;
  150. private UpdateAgent handlerAgentUpdate; //OnAgentUpdate;
  151. private StartAnim handlerStartAnim;
  152. private StopAnim handlerStopAnim;
  153. private AgentRequestSit handlerAgentRequestSit; //OnAgentRequestSit;
  154. private AgentSit handlerAgentSit; //OnAgentSit;
  155. private AvatarPickerRequest handlerAvatarPickerRequest; //OnAvatarPickerRequest;
  156. private FetchInventory handlerAgentDataUpdateRequest; //OnAgentDataUpdateRequest;
  157. private TeleportLocationRequest handlerSetStartLocationRequest; //OnSetStartLocationRequest;
  158. private TeleportLandmarkRequest handlerTeleportLandmarkRequest; //OnTeleportLandmarkRequest;
  159. private LinkObjects handlerLinkObjects; //OnLinkObjects;
  160. private DelinkObjects handlerDelinkObjects; //OnDelinkObjects;
  161. private AddNewPrim handlerAddPrim; //OnAddPrim;
  162. private UpdateShape handlerUpdatePrimShape; //null;
  163. private ObjectExtraParams handlerUpdateExtraParams; //OnUpdateExtraParams;
  164. private ObjectDuplicate handlerObjectDuplicate;
  165. private ObjectDuplicateOnRay handlerObjectDuplicateOnRay;
  166. private ObjectRequest handlerObjectRequest;
  167. private ObjectSelect handlerObjectSelect;
  168. private ObjectDeselect handlerObjectDeselect;
  169. private ObjectIncludeInSearch handlerObjectIncludeInSearch;
  170. private UpdatePrimFlags handlerUpdatePrimFlags; //OnUpdatePrimFlags;
  171. private UpdatePrimTexture handlerUpdatePrimTexture;
  172. private GrabObject handlerGrabObject; //OnGrabObject;
  173. private MoveObject handlerGrabUpdate; //OnGrabUpdate;
  174. private DeGrabObject handlerDeGrabObject; //OnDeGrabObject;
  175. private SpinStart handlerSpinStart; //OnSpinStart;
  176. private SpinObject handlerSpinUpdate; //OnSpinUpdate;
  177. private SpinStop handlerSpinStop; //OnSpinStop;
  178. private GenericCall7 handlerObjectDescription;
  179. private GenericCall7 handlerObjectName;
  180. private GenericCall7 handlerObjectClickAction;
  181. private GenericCall7 handlerObjectMaterial;
  182. private ObjectPermissions handlerObjectPermissions;
  183. private RequestObjectPropertiesFamily handlerRequestObjectPropertiesFamily; //OnRequestObjectPropertiesFamily;
  184. //private TextureRequest handlerTextureRequest;
  185. private UDPAssetUploadRequest handlerAssetUploadRequest; //OnAssetUploadRequest;
  186. private RequestXfer handlerRequestXfer; //OnRequestXfer;
  187. private XferReceive handlerXferReceive; //OnXferReceive;
  188. private ConfirmXfer handlerConfirmXfer; //OnConfirmXfer;
  189. private AbortXfer handlerAbortXfer;
  190. private CreateInventoryFolder handlerCreateInventoryFolder; //OnCreateNewInventoryFolder;
  191. private UpdateInventoryFolder handlerUpdateInventoryFolder;
  192. private MoveInventoryFolder handlerMoveInventoryFolder;
  193. private CreateNewInventoryItem handlerCreateNewInventoryItem; //OnCreateNewInventoryItem;
  194. private FetchInventory handlerFetchInventory;
  195. private FetchInventoryDescendents handlerFetchInventoryDescendents; //OnFetchInventoryDescendents;
  196. private PurgeInventoryDescendents handlerPurgeInventoryDescendents; //OnPurgeInventoryDescendents;
  197. private UpdateInventoryItem handlerUpdateInventoryItem;
  198. private CopyInventoryItem handlerCopyInventoryItem;
  199. private MoveInventoryItem handlerMoveInventoryItem;
  200. private RemoveInventoryItem handlerRemoveInventoryItem;
  201. private RemoveInventoryFolder handlerRemoveInventoryFolder;
  202. private RequestTaskInventory handlerRequestTaskInventory; //OnRequestTaskInventory;
  203. private UpdateTaskInventory handlerUpdateTaskInventory; //OnUpdateTaskInventory;
  204. private MoveTaskInventory handlerMoveTaskItem;
  205. private RemoveTaskInventory handlerRemoveTaskItem; //OnRemoveTaskItem;
  206. private RezScript handlerRezScript; //OnRezScript;
  207. private RequestMapBlocks handlerRequestMapBlocks; //OnRequestMapBlocks;
  208. private RequestMapName handlerMapNameRequest; //OnMapNameRequest;
  209. private TeleportLocationRequest handlerTeleportLocationRequest; //OnTeleportLocationRequest;
  210. private MoneyBalanceRequest handlerMoneyBalanceRequest; //OnMoneyBalanceRequest;
  211. private UUIDNameRequest handlerNameRequest;
  212. private ParcelAccessListRequest handlerParcelAccessListRequest; //OnParcelAccessListRequest;
  213. private ParcelAccessListUpdateRequest handlerParcelAccessListUpdateRequest; //OnParcelAccessListUpdateRequest;
  214. private ParcelPropertiesRequest handlerParcelPropertiesRequest; //OnParcelPropertiesRequest;
  215. private ParcelDivideRequest handlerParcelDivideRequest; //OnParcelDivideRequest;
  216. private ParcelJoinRequest handlerParcelJoinRequest; //OnParcelJoinRequest;
  217. private ParcelPropertiesUpdateRequest handlerParcelPropertiesUpdateRequest; //OnParcelPropertiesUpdateRequest;
  218. private ParcelSelectObjects handlerParcelSelectObjects; //OnParcelSelectObjects;
  219. private ParcelObjectOwnerRequest handlerParcelObjectOwnerRequest; //OnParcelObjectOwnerRequest;
  220. private ParcelAbandonRequest handlerParcelAbandonRequest;
  221. private ParcelGodForceOwner handlerParcelGodForceOwner;
  222. private ParcelReclaim handlerParcelReclaim;
  223. private RequestTerrain handlerRequestTerrain;
  224. private RequestTerrain handlerUploadTerrain;
  225. private ParcelReturnObjectsRequest handlerParcelReturnObjectsRequest;
  226. private RegionInfoRequest handlerRegionInfoRequest; //OnRegionInfoRequest;
  227. private EstateCovenantRequest handlerEstateCovenantRequest; //OnEstateCovenantRequest;
  228. private RequestGodlikePowers handlerReqGodlikePowers; //OnRequestGodlikePowers;
  229. private GodKickUser handlerGodKickUser; //OnGodKickUser;
  230. private ViewerEffectEventHandler handlerViewerEffect; //OnViewerEffect;
  231. private Action<IClientAPI> handlerLogout; //OnLogout;
  232. private MoneyTransferRequest handlerMoneyTransferRequest; //OnMoneyTransferRequest;
  233. private ParcelBuy handlerParcelBuy;
  234. private EconomyDataRequest handlerEconomoyDataRequest;
  235. private UpdateVector handlerUpdatePrimSinglePosition; //OnUpdatePrimSinglePosition;
  236. private UpdatePrimSingleRotation handlerUpdatePrimSingleRotation; //OnUpdatePrimSingleRotation;
  237. private UpdatePrimSingleRotationPosition handlerUpdatePrimSingleRotationPosition; //OnUpdatePrimSingleRotation;
  238. private UpdateVector handlerUpdatePrimScale; //OnUpdatePrimScale;
  239. private UpdateVector handlerUpdatePrimGroupScale; //OnUpdateGroupScale;
  240. private UpdateVector handlerUpdateVector; //OnUpdatePrimGroupPosition;
  241. private UpdatePrimRotation handlerUpdatePrimRotation; //OnUpdatePrimGroupRotation;
  242. // private UpdatePrimGroupRotation handlerUpdatePrimGroupRotation; //OnUpdatePrimGroupMouseRotation;
  243. // private RequestAsset handlerRequestAsset; // OnRequestAsset;
  244. private UUIDNameRequest handlerTeleportHomeRequest;
  245. private RegionHandleRequest handlerRegionHandleRequest; // OnRegionHandleRequest
  246. private ParcelInfoRequest handlerParcelInfoRequest; // OnParcelInfoRequest
  247. private ScriptAnswer handlerScriptAnswer;
  248. private RequestPayPrice handlerRequestPayPrice;
  249. private ObjectSaleInfo handlerObjectSaleInfo;
  250. private ObjectBuy handlerObjectBuy;
  251. //private BuyObjectInventory handlerBuyObjectInventory;
  252. private ObjectDeselect handlerObjectDetach;
  253. private ObjectDrop handlerObjectDrop;
  254. private AgentSit handlerOnUndo;
  255. private ForceReleaseControls handlerForceReleaseControls;
  256. private GodLandStatRequest handlerLandStatRequest;
  257. private UUIDNameRequest handlerUUIDGroupNameRequest;
  258. private ParcelDeedToGroup handlerParcelDeedToGroup;
  259. private RequestObjectPropertiesFamily handlerObjectGroupRequest;
  260. private ScriptReset handlerScriptReset;
  261. private GetScriptRunning handlerGetScriptRunning;
  262. private SetScriptRunning handlerSetScriptRunning;
  263. private UpdateVector handlerAutoPilotGo;
  264. //Gesture
  265. private ActivateGesture handlerActivateGesture;
  266. private DeactivateGesture handlerDeactivateGesture;
  267. //Sound
  268. private SoundTrigger handlerSoundTrigger;
  269. private ObjectOwner handlerObjectOwner;
  270. private DirPlacesQuery handlerDirPlacesQuery;
  271. private DirFindQuery handlerDirFindQuery;
  272. private DirLandQuery handlerDirLandQuery;
  273. private DirPopularQuery handlerDirPopularQuery;
  274. private DirClassifiedQuery handlerDirClassifiedQuery;
  275. private ParcelSetOtherCleanTime handlerParcelSetOtherCleanTime;
  276. private MapItemRequest handlerMapItemRequest;
  277. private StartLure handlerStartLure;
  278. private TeleportLureRequest handlerTeleportLureRequest;
  279. private NetworkStats handlerNetworkStatsUpdate;
  280. private ClassifiedInfoRequest handlerClassifiedInfoRequest;
  281. private ClassifiedInfoUpdate handlerClassifiedInfoUpdate;
  282. private ClassifiedDelete handlerClassifiedDelete;
  283. private ClassifiedDelete handlerClassifiedGodDelete;
  284. private EventNotificationAddRequest handlerEventNotificationAddRequest;
  285. private EventNotificationRemoveRequest handlerEventNotificationRemoveRequest;
  286. private EventGodDelete handlerEventGodDelete;
  287. private ParcelDwellRequest handlerParcelDwellRequest;
  288. private UserInfoRequest handlerUserInfoRequest;
  289. private UpdateUserInfo handlerUpdateUserInfo;
  290. private RetrieveInstantMessages handlerRetrieveInstantMessages;
  291. private PickDelete handlerPickDelete;
  292. private PickGodDelete handlerPickGodDelete;
  293. private PickInfoUpdate handlerPickInfoUpdate;
  294. private AvatarNotesUpdate handlerAvatarNotesUpdate;
  295. private MuteListRequest handlerMuteListRequest;
  296. //private AvatarInterestUpdate handlerAvatarInterestUpdate;
  297. private PlacesQuery handlerPlacesQuery;
  298. private readonly IGroupsModule m_GroupsModule;
  299. private AgentUpdateArgs lastarg = null;
  300. //private TerrainUnacked handlerUnackedTerrain = null;
  301. //**
  302. /* Properties */
  303. public UUID SecureSessionId
  304. {
  305. get { return m_secureSessionId; }
  306. }
  307. public IScene Scene
  308. {
  309. get { return m_scene; }
  310. }
  311. public UUID SessionId
  312. {
  313. get { return m_sessionId; }
  314. }
  315. public Vector3 StartPos
  316. {
  317. get { return m_startpos; }
  318. set { m_startpos = value; }
  319. }
  320. public UUID AgentId
  321. {
  322. get { return m_agentId; }
  323. }
  324. public UUID ActiveGroupId
  325. {
  326. get { return m_activeGroupID; }
  327. }
  328. public string ActiveGroupName
  329. {
  330. get { return m_activeGroupName; }
  331. }
  332. public ulong ActiveGroupPowers
  333. {
  334. get { return m_activeGroupPowers; }
  335. }
  336. public bool IsGroupMember(UUID groupID)
  337. {
  338. return m_groupPowers.ContainsKey(groupID);
  339. }
  340. public ulong GetGroupPowers(UUID groupID)
  341. {
  342. if (groupID == m_activeGroupID)
  343. return m_activeGroupPowers;
  344. if (m_groupPowers.ContainsKey(groupID))
  345. return m_groupPowers[groupID];
  346. return 0;
  347. }
  348. /// <summary>
  349. /// This is a utility method used by single states to not duplicate kicks and blue card of death messages.
  350. /// </summary>
  351. public bool ChildAgentStatus()
  352. {
  353. return m_scene.PresenceChildStatus(AgentId);
  354. }
  355. /// <summary>
  356. /// First name of the agent/avatar represented by the client
  357. /// </summary>
  358. public string FirstName
  359. {
  360. get { return m_firstName; }
  361. }
  362. /// <summary>
  363. /// Last name of the agent/avatar represented by the client
  364. /// </summary>
  365. public string LastName
  366. {
  367. get { return m_lastName; }
  368. }
  369. /// <summary>
  370. /// Full name of the client (first name and last name)
  371. /// </summary>
  372. public string Name
  373. {
  374. get { return FirstName + " " + LastName; }
  375. }
  376. public uint CircuitCode
  377. {
  378. get { return m_circuitCode; }
  379. }
  380. public int MoneyBalance
  381. {
  382. get { return m_moneyBalance; }
  383. }
  384. public int NextAnimationSequenceNumber
  385. {
  386. get { return m_animationSequenceNumber++; }
  387. }
  388. public ILLPacketHandler PacketHandler
  389. {
  390. get { return m_PacketHandler; }
  391. }
  392. bool m_IsActive = true;
  393. public bool IsActive
  394. {
  395. get { return m_IsActive; }
  396. set { m_IsActive = value; }
  397. }
  398. public bool SendLogoutPacketWhenClosing
  399. {
  400. set { m_SendLogoutPacketWhenClosing = value; }
  401. }
  402. /* METHODS */
  403. /// <summary>
  404. /// Constructor
  405. /// </summary>
  406. public LLClientView(
  407. EndPoint remoteEP, IScene scene, LLPacketServer packServer,
  408. AuthenticateResponse sessionInfo, UUID agentId, UUID sessionId, uint circuitCode, EndPoint proxyEP,
  409. ClientStackUserSettings userSettings)
  410. {
  411. // Should be called first?
  412. RegisterInterfaces();
  413. m_GroupsModule = scene.RequestModuleInterface<IGroupsModule>();
  414. m_moneyBalance = 1000;
  415. m_channelVersion = Utils.StringToBytes(scene.GetSimulatorVersion());
  416. InitDefaultAnimations();
  417. m_scene = scene;
  418. //m_assetCache = assetCache;
  419. m_assetService = m_scene.RequestModuleInterface<IAssetService>();
  420. m_networkServer = packServer;
  421. m_agentId = agentId;
  422. m_sessionId = sessionId;
  423. m_circuitCode = circuitCode;
  424. m_userEndPoint = remoteEP;
  425. m_proxyEndPoint = proxyEP;
  426. m_firstName = sessionInfo.LoginInfo.First;
  427. m_lastName = sessionInfo.LoginInfo.Last;
  428. m_startpos = sessionInfo.LoginInfo.StartPos;
  429. if (sessionInfo.LoginInfo.SecureSession != UUID.Zero)
  430. {
  431. m_secureSessionId = sessionInfo.LoginInfo.SecureSession;
  432. }
  433. // While working on this, the BlockingQueue had me fooled for a bit.
  434. // The Blocking queue causes the thread to stop until there's something
  435. // in it to process. It's an on-purpose threadlock though because
  436. // without it, the clientloop will suck up all sim resources.
  437. m_PacketHandler = new LLPacketHandler(this, m_networkServer, userSettings);
  438. m_PacketHandler.SynchronizeClient = SynchronizeClient;
  439. m_PacketHandler.OnPacketStats += PopulateStats;
  440. if (scene.Config != null)
  441. {
  442. IConfig clientConfig = scene.Config.Configs["LLClient"];
  443. if (clientConfig != null)
  444. {
  445. m_PacketHandler.ReliableIsImportant =
  446. clientConfig.GetBoolean("ReliableIsImportant",
  447. false);
  448. m_PacketHandler.MaxReliableResends = clientConfig.GetInt("MaxReliableResends",
  449. m_PacketHandler.MaxReliableResends);
  450. m_primTerseUpdatesPerPacket = clientConfig.GetInt("TerseUpdatesPerPacket",
  451. m_primTerseUpdatesPerPacket);
  452. m_primFullUpdatesPerPacket = clientConfig.GetInt("FullUpdatesPerPacket",
  453. m_primFullUpdatesPerPacket);
  454. m_primTerseUpdateRate = clientConfig.GetInt("TerseUpdateRate",
  455. m_primTerseUpdateRate);
  456. m_primFullUpdateRate = clientConfig.GetInt("FullUpdateRate",
  457. m_primFullUpdateRate);
  458. m_textureRequestRate = clientConfig.GetInt("TextureRequestRate",
  459. m_textureRequestRate);
  460. m_textureSendLimit = clientConfig.GetInt("TextureSendLimit",
  461. m_textureSendLimit);
  462. m_textureDataLimit = clientConfig.GetInt("TextureDataLimit",
  463. m_textureDataLimit);
  464. m_packetMTU = clientConfig.GetInt("PacketMTU", 1400);
  465. }
  466. }
  467. RegisterLocalPacketHandlers();
  468. m_imageManager = new LLImageManager(this, m_assetService, Scene.RequestModuleInterface<IJ2KDecoder>());
  469. }
  470. public void SetDebugPacketLevel(int newDebugPacketLevel)
  471. {
  472. m_debugPacketLevel = newDebugPacketLevel;
  473. }
  474. # region Client Methods
  475. private void CloseCleanup(bool shutdownCircuit)
  476. {
  477. m_scene.RemoveClient(AgentId);
  478. //m_log.InfoFormat("[CLIENTVIEW] Memory pre GC {0}", System.GC.GetTotalMemory(false));
  479. //m_log.InfoFormat("[CLIENTVIEW] Memory post GC {0}", System.GC.GetTotalMemory(true));
  480. // Send the STOP packet
  481. DisableSimulatorPacket disable = (DisableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
  482. OutPacket(disable, ThrottleOutPacketType.Unknown);
  483. Thread.Sleep(2000);
  484. // Shut down timers
  485. if (m_clientPingTimer.Enabled) m_clientPingTimer.Stop();
  486. if (m_avatarTerseUpdateTimer.Enabled) m_avatarTerseUpdateTimer.Stop();
  487. if (m_primTerseUpdateTimer.Enabled) m_primTerseUpdateTimer.Stop();
  488. if (m_primFullUpdateTimer.Enabled) m_primFullUpdateTimer.Stop();
  489. if (m_textureRequestTimer.Enabled) m_textureRequestTimer.Stop();
  490. // This is just to give the client a reasonable chance of
  491. // flushing out all it's packets. There should probably
  492. // be a better mechanism here
  493. // We can't reach into other scenes and close the connection
  494. // We need to do this over grid communications
  495. //m_scene.CloseAllAgents(CircuitCode);
  496. // If we're not shutting down the circuit, then this is the last time we'll go here.
  497. // If we are shutting down the circuit, the UDP Server will come back here with
  498. // ShutDownCircuit = false
  499. if (!(shutdownCircuit))
  500. {
  501. GC.Collect();
  502. m_imageManager = null;
  503. // Sends a KillPacket object, with which, the
  504. // blockingqueue dequeues and sees it's a killpacket
  505. // and terminates within the context of the client thread.
  506. // This ensures that it's done from within the context
  507. // of the client thread regardless of where Close() is called.
  508. KillEndDone();
  509. }
  510. }
  511. /// <summary>
  512. /// Close down the client view. This *must* be the last method called, since the last #
  513. /// statement of CloseCleanup() aborts the thread.
  514. /// </summary>
  515. /// <param name="shutdownCircuit"></param>
  516. public void Close(bool shutdownCircuit)
  517. {
  518. m_clientPingTimer.Enabled = false;
  519. m_log.DebugFormat(
  520. "[CLIENT]: Close has been called with shutdownCircuit = {0} for {1} attached to scene {2}",
  521. shutdownCircuit, Name, m_scene.RegionInfo.RegionName);
  522. if (m_imageManager != null)
  523. m_imageManager.Close();
  524. if (m_PacketHandler != null)
  525. m_PacketHandler.Flush();
  526. // raise an event on the packet server to Shutdown the circuit
  527. // Now, if we raise the event then the packet server will call this method itself, so don't try cleanup
  528. // here otherwise we'll end up calling it twice.
  529. // FIXME: In truth, I might be wrong but this whole business of calling this method twice (with different args) looks
  530. // horribly tangly. Hopefully it should be possible to greatly simplify it.
  531. if (shutdownCircuit)
  532. {
  533. if (OnConnectionClosed != null)
  534. OnConnectionClosed(this);
  535. }
  536. else
  537. {
  538. CloseCleanup(shutdownCircuit);
  539. }
  540. }
  541. public void Kick(string message)
  542. {
  543. if (!ChildAgentStatus())
  544. {
  545. KickUserPacket kupack = (KickUserPacket)PacketPool.Instance.GetPacket(PacketType.KickUser);
  546. kupack.UserInfo.AgentID = AgentId;
  547. kupack.UserInfo.SessionID = SessionId;
  548. kupack.TargetBlock.TargetIP = 0;
  549. kupack.TargetBlock.TargetPort = 0;
  550. kupack.UserInfo.Reason = Utils.StringToBytes(message);
  551. OutPacket(kupack, ThrottleOutPacketType.Task);
  552. // You must sleep here or users get no message!
  553. Thread.Sleep(500);
  554. }
  555. }
  556. public void Stop()
  557. {
  558. // Shut down timers
  559. if (m_clientPingTimer.Enabled) m_clientPingTimer.Stop();
  560. if (m_avatarTerseUpdateTimer.Enabled) m_avatarTerseUpdateTimer.Stop();
  561. if (m_primTerseUpdateTimer.Enabled) m_primTerseUpdateTimer.Stop();
  562. if (m_primFullUpdateTimer.Enabled) m_primFullUpdateTimer.Stop();
  563. if (m_textureRequestTimer.Enabled) m_textureRequestTimer.Stop();
  564. }
  565. public void Restart()
  566. {
  567. // re-construct
  568. m_PacketHandler.Clear();
  569. m_clientPingTimer = new Timer(5000);
  570. m_clientPingTimer.Elapsed += CheckClientConnectivity;
  571. m_clientPingTimer.Enabled = true;
  572. m_avatarTerseUpdateTimer = new Timer(m_avatarTerseUpdateRate);
  573. m_avatarTerseUpdateTimer.Elapsed += new ElapsedEventHandler(ProcessAvatarTerseUpdates);
  574. m_avatarTerseUpdateTimer.AutoReset = false;
  575. m_primTerseUpdateTimer = new Timer(m_primTerseUpdateRate);
  576. m_primTerseUpdateTimer.Elapsed += new ElapsedEventHandler(ProcessPrimTerseUpdates);
  577. m_primTerseUpdateTimer.AutoReset = false;
  578. m_primFullUpdateTimer = new Timer(m_primFullUpdateRate);
  579. m_primFullUpdateTimer.Elapsed += new ElapsedEventHandler(ProcessPrimFullUpdates);
  580. m_primFullUpdateTimer.AutoReset = false;
  581. m_textureRequestTimer = new Timer(m_textureRequestRate);
  582. m_textureRequestTimer.Elapsed += new ElapsedEventHandler(ProcessTextureRequests);
  583. m_textureRequestTimer.AutoReset = false;
  584. }
  585. public void Terminate()
  586. {
  587. m_PacketHandler.OnPacketStats -= PopulateStats;
  588. m_PacketHandler.Stop();
  589. // wait for thread stoped
  590. m_clientThread.Join();
  591. // delete circuit code
  592. m_networkServer.CloseClient(this);
  593. }
  594. #endregion
  595. # region Packet Handling
  596. public void PopulateStats(int inPackets, int outPackets, int unAckedBytes)
  597. {
  598. handlerNetworkStatsUpdate = OnNetworkStatsUpdate;
  599. if (handlerNetworkStatsUpdate != null)
  600. {
  601. handlerNetworkStatsUpdate(inPackets, outPackets, unAckedBytes);
  602. }
  603. }
  604. public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
  605. {
  606. bool result = false;
  607. lock (PacketHandlers)
  608. {
  609. if (!PacketHandlers.ContainsKey(packetType))
  610. {
  611. PacketHandlers.Add(packetType, handler);
  612. result = true;
  613. }
  614. }
  615. return result;
  616. }
  617. public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
  618. {
  619. bool result = false;
  620. lock (m_packetHandlers)
  621. {
  622. if (!m_packetHandlers.ContainsKey(packetType))
  623. {
  624. m_packetHandlers.Add(packetType, handler);
  625. result = true;
  626. }
  627. }
  628. return result;
  629. }
  630. public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)
  631. {
  632. MethodName = MethodName.ToLower().Trim();
  633. bool result = false;
  634. lock (m_genericPacketHandlers)
  635. {
  636. if (!m_genericPacketHandlers.ContainsKey(MethodName))
  637. {
  638. m_genericPacketHandlers.Add(MethodName, handler);
  639. result = true;
  640. }
  641. }
  642. return result;
  643. }
  644. /// <summary>
  645. /// Try to process a packet using registered packet handlers
  646. /// </summary>
  647. /// <param name="packet"></param>
  648. /// <returns>True if a handler was found which successfully processed the packet.</returns>
  649. protected virtual bool ProcessPacketMethod(Packet packet)
  650. {
  651. bool result = false;
  652. PacketMethod method;
  653. if (m_packetHandlers.TryGetValue(packet.Type, out method))
  654. {
  655. //there is a local handler for this packet type
  656. result = method(this, packet);
  657. }
  658. else
  659. {
  660. //there is not a local handler so see if there is a Global handler
  661. bool found;
  662. lock (PacketHandlers)
  663. {
  664. found = PacketHandlers.TryGetValue(packet.Type, out method);
  665. }
  666. if (found)
  667. {
  668. result = method(this, packet);
  669. }
  670. }
  671. return result;
  672. }
  673. protected void DebugPacket(string direction, Packet packet)
  674. {
  675. string info;
  676. if (m_debugPacketLevel < 255 && packet.Type == PacketType.AgentUpdate)
  677. return;
  678. if (m_debugPacketLevel < 254 && packet.Type == PacketType.ViewerEffect)
  679. return;
  680. if (m_debugPacketLevel < 253 && (
  681. packet.Type == PacketType.CompletePingCheck ||
  682. packet.Type == PacketType.StartPingCheck
  683. ))
  684. return;
  685. if (m_debugPacketLevel < 252 && packet.Type == PacketType.PacketAck)
  686. return;
  687. if (m_debugPacketLevel > 1)
  688. {
  689. info = packet.ToString();
  690. }
  691. else
  692. {
  693. info = packet.Type.ToString();
  694. }
  695. Console.WriteLine(m_circuitCode + ":" + direction + ": " + info);
  696. }
  697. /// <summary>
  698. /// Main packet processing loop for the UDP component of the client session. Both incoming and outgoing
  699. /// packets are processed here.
  700. /// </summary>
  701. protected virtual void ClientLoop()
  702. {
  703. m_log.DebugFormat(
  704. "[CLIENT]: Entered main packet processing loop for {0} in {1}", Name, Scene.RegionInfo.RegionName);
  705. while (IsActive)
  706. {
  707. LLQueItem nextPacket = m_PacketHandler.PacketQueue.Dequeue();
  708. if (nextPacket.Incoming)
  709. {
  710. if (m_debugPacketLevel > 0)
  711. DebugPacket("IN", nextPacket.Packet);
  712. m_PacketHandler.ProcessInPacket(nextPacket);
  713. }
  714. else
  715. {
  716. if (m_debugPacketLevel > 0)
  717. DebugPacket("OUT", nextPacket.Packet);
  718. m_PacketHandler.ProcessOutPacket(nextPacket);
  719. }
  720. }
  721. }
  722. # endregion
  723. protected int m_terrainCheckerCount;
  724. /// <summary>
  725. /// Event handler for check client timer
  726. /// Checks to ensure that the client is still connected. If the client has failed to respond to many pings
  727. /// in succession then close down the connection.
  728. /// </summary>
  729. /// <param name="sender"></param>
  730. /// <param name="e"></param>
  731. protected void CheckClientConnectivity(object sender, ElapsedEventArgs e)
  732. {
  733. if (m_PacketHandler.PacketsReceived == m_inPacketsChecked)
  734. {
  735. // no packet came in since the last time we checked...
  736. m_probesWithNoIngressPackets++;
  737. if ((m_probesWithNoIngressPackets > 30 && !m_clientBlocked) // agent active
  738. || (m_probesWithNoIngressPackets > 90 && m_clientBlocked)) // agent paused
  739. {
  740. m_clientPingTimer.Enabled = false;
  741. m_log.WarnFormat(
  742. "[CLIENT]: Client for agent {0} {1} has stopped responding to pings. Closing connection",
  743. Name, AgentId);
  744. if (OnConnectionClosed != null)
  745. {
  746. OnConnectionClosed(this);
  747. }
  748. }
  749. else
  750. {
  751. // this will normally trigger at least one packet (ping response)
  752. SendStartPingCheck(0);
  753. }
  754. }
  755. else
  756. {
  757. // Something received in the meantime - we can reset the counters
  758. m_probesWithNoIngressPackets = 0;
  759. // ... and store the current number of packets received to find out if another one got in on the next cycle
  760. m_inPacketsChecked = m_PacketHandler.PacketsReceived;
  761. }
  762. }
  763. # region Setup
  764. /// <summary>
  765. /// Starts up the timers to check the client and resend unacked packets
  766. /// Adds the client to the OpenSim.Region.Framework.Scenes.Scene
  767. /// </summary>
  768. protected virtual void InitNewClient()
  769. {
  770. //this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
  771. // Ping the client regularly to check that it's still there
  772. m_clientPingTimer = new Timer(5000);
  773. m_clientPingTimer.Elapsed += CheckClientConnectivity;
  774. m_clientPingTimer.Enabled = true;
  775. m_avatarTerseUpdateTimer = new Timer(m_avatarTerseUpdateRate);
  776. m_avatarTerseUpdateTimer.Elapsed += new ElapsedEventHandler(ProcessAvatarTerseUpdates);
  777. m_avatarTerseUpdateTimer.AutoReset = false;
  778. m_primTerseUpdateTimer = new Timer(m_primTerseUpdateRate);
  779. m_primTerseUpdateTimer.Elapsed += new ElapsedEventHandler(ProcessPrimTerseUpdates);
  780. m_primTerseUpdateTimer.AutoReset = false;
  781. m_primFullUpdateTimer = new Timer(m_primFullUpdateRate);
  782. m_primFullUpdateTimer.Elapsed += new ElapsedEventHandler(ProcessPrimFullUpdates);
  783. m_primFullUpdateTimer.AutoReset = false;
  784. m_textureRequestTimer = new Timer(m_textureRequestRate);
  785. m_textureRequestTimer.Elapsed += new ElapsedEventHandler(ProcessTextureRequests);
  786. m_textureRequestTimer.AutoReset = false;
  787. m_scene.AddNewClient(this);
  788. RefreshGroupMembership();
  789. }
  790. public virtual void Start()
  791. {
  792. m_clientThread = new Thread(RunUserSession);
  793. m_clientThread.Name = "ClientThread";
  794. m_clientThread.IsBackground = true;
  795. m_clientThread.Start();
  796. ThreadTracker.Add(m_clientThread);
  797. }
  798. /// <summary>
  799. /// Run a user session. This method lies at the base of the entire client thread.
  800. /// </summary>
  801. protected virtual void RunUserSession()
  802. {
  803. //tell this thread we are using the culture set up for the sim (currently hardcoded to en_US)
  804. //otherwise it will override this and use the system default
  805. Culture.SetCurrentCulture();
  806. try
  807. {
  808. // This sets up all the timers
  809. InitNewClient();
  810. ClientLoop();
  811. }
  812. catch (Exception e)
  813. {
  814. if (e is ThreadAbortException)
  815. throw;
  816. if (StatsManager.SimExtraStats != null)
  817. StatsManager.SimExtraStats.AddAbnormalClientThreadTermination();
  818. // Don't let a failure in an individual client thread crash the whole sim.
  819. m_log.ErrorFormat(
  820. "[CLIENT]: Client thread for {0} {1} crashed. Logging them out.", Name, AgentId);
  821. m_log.Error(e.ToString());
  822. try
  823. {
  824. // Make an attempt to alert the user that their session has crashed
  825. AgentAlertMessagePacket packet
  826. = BuildAgentAlertPacket(
  827. "Unfortunately the session for this client on the server has crashed.\n"
  828. + "Any further actions taken will not be processed.\n"
  829. + "Please relog", true);
  830. LLQueItem item = new LLQueItem();
  831. item.Packet = packet;
  832. item.Sequence = packet.Header.Sequence;
  833. m_PacketHandler.ProcessOutPacket(item);
  834. // There may be a better way to do this. Perhaps kick? Not sure this propogates notifications to
  835. // listeners yet, though.
  836. Logout(this);
  837. }
  838. catch (Exception e2)
  839. {
  840. if (e2 is ThreadAbortException)
  841. throw;
  842. m_log.ErrorFormat("[CLIENT]: Further exception thrown on forced session logout. {0}", e2);
  843. }
  844. }
  845. }
  846. protected virtual void TextureRequestHandler()
  847. {
  848. m_log.DebugFormat("[TRH] Thread started");
  849. while (m_imageManager != null)
  850. {
  851. try
  852. {
  853. while (m_imageManager != null)
  854. {
  855. }
  856. }
  857. catch (Exception e)
  858. {
  859. m_log.WarnFormat("[TRH] Exception in handler loop: {0}", e.Message);
  860. m_log.Debug(e);
  861. }
  862. }
  863. m_log.DebugFormat("[TRH] Thread terminated");
  864. }
  865. # endregion
  866. // Previously ClientView.API partial class
  867. public event GenericMessage OnGenericMessage;
  868. public event BinaryGenericMessage OnBinaryGenericMessage;
  869. public event Action<IClientAPI> OnLogout;
  870. public event ObjectPermissions OnObjectPermissions;
  871. public event Action<IClientAPI> OnConnectionClosed;
  872. public event ViewerEffectEventHandler OnViewerEffect;
  873. public event ImprovedInstantMessage OnInstantMessage;
  874. public event ChatMessage OnChatFromClient;
  875. public event TextureRequest OnRequestTexture;
  876. public event RezObject OnRezObject;
  877. public event DeRezObject OnDeRezObject;
  878. public event ModifyTerrain OnModifyTerrain;
  879. public event Action<IClientAPI> OnRegionHandShakeReply;
  880. public event GenericCall2 OnRequestWearables;
  881. public event SetAppearance OnSetAppearance;
  882. public event AvatarNowWearing OnAvatarNowWearing;
  883. public event RezSingleAttachmentFromInv OnRezSingleAttachmentFromInv;
  884. public event RezMultipleAttachmentsFromInv OnRezMultipleAttachmentsFromInv;
  885. public event UUIDNameRequest OnDetachAttachmentIntoInv;
  886. public event ObjectAttach OnObjectAttach;
  887. public event ObjectDeselect OnObjectDetach;
  888. public event ObjectDrop OnObjectDrop;
  889. public event GenericCall2 OnCompleteMovementToRegion;
  890. public event UpdateAgent OnAgentUpdate;
  891. public event AgentRequestSit OnAgentRequestSit;
  892. public event AgentSit OnAgentSit;
  893. public event AvatarPickerRequest OnAvatarPickerRequest;
  894. public event StartAnim OnStartAnim;
  895. public event StopAnim OnStopAnim;
  896. public event Action<IClientAPI> OnRequestAvatarsData;
  897. public event LinkObjects OnLinkObjects;
  898. public event DelinkObjects OnDelinkObjects;
  899. public event GrabObject OnGrabObject;
  900. public event DeGrabObject OnDeGrabObject;
  901. public event SpinStart OnSpinStart;
  902. public event SpinStop OnSpinStop;
  903. public event ObjectDuplicate OnObjectDuplicate;
  904. public event ObjectDuplicateOnRay OnObjectDuplicateOnRay;
  905. public event MoveObject OnGrabUpdate;
  906. public event SpinObject OnSpinUpdate;
  907. public event AddNewPrim OnAddPrim;
  908. public event RequestGodlikePowers OnRequestGodlikePowers;
  909. public event GodKickUser OnGodKickUser;
  910. public event ObjectExtraParams OnUpdateExtraParams;
  911. public event UpdateShape OnUpdatePrimShape;
  912. public event ObjectRequest OnObjectRequest;
  913. public event ObjectSelect OnObjectSelect;
  914. public event ObjectDeselect OnObjectDeselect;
  915. public event GenericCall7 OnObjectDescription;
  916. public event GenericCall7 OnObjectName;
  917. public event GenericCall7 OnObjectClickAction;
  918. public event GenericCall7 OnObjectMaterial;
  919. public event ObjectIncludeInSearch OnObjectIncludeInSearch;
  920. public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
  921. public event UpdatePrimFlags OnUpdatePrimFlags;
  922. public event UpdatePrimTexture OnUpdatePrimTexture;
  923. public event UpdateVector OnUpdatePrimGroupPosition;
  924. public event UpdateVector OnUpdatePrimSinglePosition;
  925. public event UpdatePrimRotation OnUpdatePrimGroupRotation;
  926. public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
  927. public event UpdatePrimSingleRotationPosition OnUpdatePrimSingleRotationPosition;
  928. public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
  929. public event UpdateVector OnUpdatePrimScale;
  930. public event UpdateVector OnUpdatePrimGroupScale;
  931. public event StatusChange OnChildAgentStatus;
  932. public event GenericCall2 OnStopMovement;
  933. public event Action<UUID> OnRemoveAvatar;
  934. public event RequestMapBlocks OnRequestMapBlocks;
  935. public event RequestMapName OnMapNameRequest;
  936. public event TeleportLocationRequest OnTeleportLocationRequest;
  937. public event TeleportLandmarkRequest OnTeleportLandmarkRequest;
  938. public event DisconnectUser OnDisconnectUser;
  939. public event RequestAvatarProperties OnRequestAvatarProperties;
  940. public event SetAlwaysRun OnSetAlwaysRun;
  941. public event FetchInventory OnAgentDataUpdateRequest;
  942. public event TeleportLocationRequest OnSetStartLocationRequest;
  943. public event UpdateAvatarProperties OnUpdateAvatarProperties;
  944. public event CreateNewInventoryItem OnCreateNewInventoryItem;
  945. public event CreateInventoryFolder OnCreateNewInventoryFolder;
  946. public event UpdateInventoryFolder OnUpdateInventoryFolder;
  947. public event MoveInventoryFolder OnMoveInventoryFolder;
  948. public event FetchInventoryDescendents OnFetchInventoryDescendents;
  949. public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
  950. public event FetchInventory OnFetchInventory;
  951. public event RequestTaskInventory OnRequestTaskInventory;
  952. public event UpdateInventoryItem OnUpdateInventoryItem;
  953. public event CopyInventoryItem OnCopyInventoryItem;
  954. public event MoveInventoryItem OnMoveInventoryItem;
  955. public event RemoveInventoryItem OnRemoveInventoryItem;
  956. public event RemoveInventoryFolder OnRemoveInventoryFolder;
  957. public event UDPAssetUploadRequest OnAssetUploadRequest;
  958. public event XferReceive OnXferReceive;
  959. public event RequestXfer OnRequestXfer;
  960. public event ConfirmXfer OnConfirmXfer;
  961. public event AbortXfer OnAbortXfer;
  962. public event RequestTerrain OnRequestTerrain;
  963. public event RezScript OnRezScript;
  964. public event UpdateTaskInventory OnUpdateTaskInventory;
  965. public event MoveTaskInventory OnMoveTaskItem;
  966. public event RemoveTaskInventory OnRemoveTaskItem;
  967. public event RequestAsset OnRequestAsset;
  968. public event UUIDNameRequest OnNameFromUUIDRequest;
  969. public event ParcelAccessListRequest OnParcelAccessListRequest;
  970. public event ParcelAccessListUpdateRequest OnParcelAccessListUpdateRequest;
  971. public event ParcelPropertiesRequest OnParcelPropertiesRequest;
  972. public event ParcelDivideRequest OnParcelDivideRequest;
  973. public event ParcelJoinRequest OnParcelJoinRequest;
  974. public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
  975. public event ParcelSelectObjects OnParcelSelectObjects;
  976. public event ParcelObjectOwnerRequest OnParcelObjectOwnerRequest;
  977. public event ParcelAbandonRequest OnParcelAbandonRequest;
  978. public event ParcelGodForceOwner OnParcelGodForceOwner;
  979. public event ParcelReclaim OnParcelReclaim;
  980. public event ParcelReturnObjectsRequest OnParcelReturnObjectsRequest;
  981. public event ParcelDeedToGroup OnParcelDeedToGroup;
  982. public event RegionInfoRequest OnRegionInfoRequest;
  983. public event EstateCovenantRequest OnEstateCovenantRequest;
  984. public event FriendActionDelegate OnApproveFriendRequest;
  985. public event FriendActionDelegate OnDenyFriendRequest;
  986. public event FriendshipTermination OnTerminateFriendship;
  987. public event MoneyTransferRequest OnMoneyTransferRequest;
  988. public event EconomyDataRequest OnEconomyDataRequest;
  989. public event MoneyBalanceRequest OnMoneyBalanceRequest;
  990. public event ParcelBuy OnParcelBuy;
  991. public event UUIDNameRequest OnTeleportHomeRequest;
  992. public event UUIDNameRequest OnUUIDGroupNameRequest;
  993. public event ScriptAnswer OnScriptAnswer;
  994. public event RequestPayPrice OnRequestPayPrice;
  995. public event ObjectSaleInfo OnObjectSaleInfo;
  996. public event ObjectBuy OnObjectBuy;
  997. public event BuyObjectInventory OnBuyObjectInventory;
  998. public event AgentSit OnUndo;
  999. public event ForceReleaseControls OnForceReleaseControls;
  1000. public event GodLandStatRequest OnLandStatRequest;
  1001. public event RequestObjectPropertiesFamily OnObjectGroupRequest;
  1002. public event DetailedEstateDataRequest OnDetailedEstateDataRequest;
  1003. public event SetEstateFlagsRequest OnSetEstateFlagsRequest;
  1004. public event SetEstateTerrainBaseTexture OnSetEstateTerrainBaseTexture;
  1005. public event SetEstateTerrainDetailTexture OnSetEstateTerrainDetailTexture;
  1006. public event SetEstateTerrainTextureHeights OnSetEstateTerrainTextureHeights;
  1007. public event CommitEstateTerrainTextureRequest OnCommitEstateTerrainTextureRequest;
  1008. public event SetRegionTerrainSettings OnSetRegionTerrainSettings;
  1009. public event BakeTerrain OnBakeTerrain;
  1010. public event RequestTerrain OnUploadTerrain;
  1011. public event EstateChangeInfo OnEstateChangeInfo;
  1012. public event EstateRestartSimRequest OnEstateRestartSimRequest;
  1013. public event EstateChangeCovenantRequest OnEstateChangeCovenantRequest;
  1014. public event UpdateEstateAccessDeltaRequest OnUpdateEstateAccessDeltaRequest;
  1015. public event SimulatorBlueBoxMessageRequest OnSimulatorBlueBoxMessageRequest;
  1016. public event EstateBlueBoxMessageRequest OnEstateBlueBoxMessageRequest;
  1017. public event EstateDebugRegionRequest OnEstateDebugRegionRequest;
  1018. public event EstateTeleportOneUserHomeRequest OnEstateTeleportOneUserHomeRequest;
  1019. public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest;
  1020. public event RegionHandleRequest OnRegionHandleRequest;
  1021. public event ParcelInfoRequest OnParcelInfoRequest;
  1022. public event ScriptReset OnScriptReset;
  1023. public event GetScriptRunning OnGetScriptRunning;
  1024. public event SetScriptRunning OnSetScriptRunning;
  1025. public event UpdateVector OnAutoPilotGo;
  1026. public event TerrainUnacked OnUnackedTerrain;
  1027. public event ActivateGesture OnActivateGesture;
  1028. public event DeactivateGesture OnDeactivateGesture;
  1029. public event ObjectOwner OnObjectOwner;
  1030. public event DirPlacesQuery OnDirPlacesQuery;
  1031. public event DirFindQuery OnDirFindQuery;
  1032. public event DirLandQuery OnDirLandQuery;
  1033. public event DirPopularQuery OnDirPopularQuery;
  1034. public event DirClassifiedQuery OnDirClassifiedQuery;
  1035. public event EventInfoRequest OnEventInfoRequest;
  1036. public event ParcelSetOtherCleanTime OnParcelSetOtherCleanTime;
  1037. public event MapItemRequest OnMapItemRequest;
  1038. public event OfferCallingCard OnOfferCallingCard;
  1039. public event AcceptCallingCard OnAcceptCallingCard;
  1040. public event DeclineCallingCard OnDeclineCallingCard;
  1041. public event SoundTrigger OnSoundTrigger;
  1042. public event StartLure OnStartLure;
  1043. public event TeleportLureRequest OnTeleportLureRequest;
  1044. public event NetworkStats OnNetworkStatsUpdate;
  1045. public event ClassifiedInfoRequest OnClassifiedInfoRequest;
  1046. public event ClassifiedInfoUpdate OnClassifiedInfoUpdate;
  1047. public event ClassifiedDelete OnClassifiedDelete;
  1048. public event ClassifiedDelete OnClassifiedGodDelete;
  1049. public event EventNotificationAddRequest OnEventNotificationAddRequest;
  1050. public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest;
  1051. public event EventGodDelete OnEventGodDelete;
  1052. public event ParcelDwellRequest OnParcelDwellRequest;
  1053. public event UserInfoRequest OnUserInfoRequest;
  1054. public event UpdateUserInfo OnUpdateUserInfo;
  1055. public event RetrieveInstantMessages OnRetrieveInstantMessages;
  1056. public event PickDelete OnPickDelete;
  1057. public event PickGodDelete OnPickGodDelete;
  1058. public event PickInfoUpdate OnPickInfoUpdate;
  1059. public event AvatarNotesUpdate OnAvatarNotesUpdate;
  1060. public event MuteListRequest OnMuteListRequest;
  1061. //public event AvatarInterestUpdate OnAvatarInterestUpdate;
  1062. public event PlacesQuery OnPlacesQuery;
  1063. public void ActivateGesture(UUID assetId, UUID gestureId)
  1064. {
  1065. }
  1066. public void DeactivateGesture(UUID assetId, UUID gestureId)
  1067. {
  1068. }
  1069. // Sound
  1070. public void SoundTrigger(UUID soundId, UUID owerid, UUID Objectid,UUID ParentId,float Gain, Vector3 Position,UInt64 Handle)
  1071. {
  1072. }
  1073. #region Scene/Avatar to Client
  1074. public void SendRegionHandshake(RegionInfo regionInfo, RegionHandshakeArgs args)
  1075. {
  1076. RegionHandshakePacket handshake = (RegionHandshakePacket)PacketPool.Instance.GetPacket(PacketType.RegionHandshake);
  1077. handshake.RegionInfo = new RegionHandshakePacket.RegionInfoBlock();
  1078. handshake.RegionInfo.BillableFactor = args.billableFactor;
  1079. handshake.RegionInfo.IsEstateManager = args.isEstateManager;
  1080. handshake.RegionInfo.TerrainHeightRange00 = args.terrainHeightRange0;
  1081. handshake.RegionInfo.TerrainHeightRange01 = args.terrainHeightRange1;
  1082. handshake.RegionInfo.TerrainHeightRange10 = args.terrainHeightRange2;
  1083. handshake.RegionInfo.TerrainHeightRange11 = args.terrainHeightRange3;
  1084. handshake.RegionInfo.TerrainStartHeight00 = args.terrainStartHeight0;
  1085. handshake.RegionInfo.TerrainStartHeight01 = args.terrainStartHeight1;
  1086. handshake.RegionInfo.TerrainStartHeight10 = args.terrainStartHeight2;
  1087. handshake.RegionInfo.TerrainStartHeight11 = args.terrainStartHeight3;
  1088. handshake.RegionInfo.SimAccess = args.simAccess;
  1089. handshake.RegionInfo.WaterHeight = args.waterHeight;
  1090. handshake.RegionInfo.RegionFlags = args.regionFlags;
  1091. handshake.RegionInfo.SimName = Utils.StringToBytes(args.regionName);
  1092. handshake.RegionInfo.SimOwner = args.SimOwner;
  1093. handshake.RegionInfo.TerrainBase0 = args.terrainBase0;
  1094. handshake.RegionInfo.TerrainBase1 = args.terrainBase1;
  1095. handshake.RegionInfo.TerrainBase2 = args.terrainBase2;
  1096. handshake.RegionInfo.TerrainBase3 = args.terrainBase3;
  1097. handshake.RegionInfo.TerrainDetail0 = args.terrainDetail0;
  1098. handshake.RegionInfo.TerrainDetail1 = args.terrainDetail1;
  1099. handshake.RegionInfo.TerrainDetail2 = args.terrainDetail2;
  1100. handshake.RegionInfo.TerrainDetail3 = args.terrainDetail3;
  1101. handshake.RegionInfo.CacheID = UUID.Random(); //I guess this is for the client to remember an old setting?
  1102. handshake.RegionInfo2 = new RegionHandshakePacket.RegionInfo2Block();
  1103. handshake.RegionInfo2.RegionID = regionInfo.RegionID;
  1104. handshake.RegionInfo3 = new RegionHandshakePacket.RegionInfo3Block();
  1105. handshake.RegionInfo3.CPUClassID = 9;
  1106. handshake.RegionInfo3.CPURatio = 1;
  1107. handshake.RegionInfo3.ColoName = Utils.EmptyBytes;
  1108. handshake.RegionInfo3.ProductName = Utils.EmptyBytes;
  1109. handshake.RegionInfo3.ProductSKU = Utils.EmptyBytes;
  1110. OutPacket(handshake, ThrottleOutPacketType.Task);
  1111. }
  1112. /// <summary>
  1113. ///
  1114. /// </summary>
  1115. public void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look)
  1116. {
  1117. AgentMovementCompletePacket mov = (AgentMovementCompletePacket)PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete);
  1118. mov.SimData.ChannelVersion = m_channelVersion;
  1119. mov.AgentData.SessionID = m_sessionId;
  1120. mov.AgentData.AgentID = AgentId;
  1121. mov.Data.RegionHandle = regInfo.RegionHandle;
  1122. mov.Data.Timestamp = (uint)Util.UnixTimeSinceEpoch();
  1123. if ((pos.X == 0) && (pos.Y == 0) && (pos.Z == 0))
  1124. {
  1125. mov.Data.Position = m_startpos;
  1126. }
  1127. else
  1128. {
  1129. mov.Data.Position = pos;
  1130. }
  1131. mov.Data.LookAt = look;
  1132. // Hack to get this out immediately and skip the throttles
  1133. OutPacket(mov, ThrottleOutPacketType.Unknown);
  1134. }
  1135. public void SendChatMessage(string message, byte type, Vector3 fromPos, string fromName,
  1136. UUID fromAgentID, byte source, byte audible)
  1137. {
  1138. ChatFromSimulatorPacket reply = (ChatFromSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.ChatFromSimulator);
  1139. reply.ChatData.Audible = audible;
  1140. reply.ChatData.Message = Utils.StringToBytes(message);
  1141. reply.ChatData.ChatType = type;
  1142. reply.ChatData.SourceType = source;
  1143. reply.ChatData.Position = fromPos;
  1144. reply.ChatData.FromName = Utils.StringToBytes(fromName);
  1145. reply.ChatData.OwnerID = fromAgentID;
  1146. reply.ChatData.SourceID = fromAgentID;
  1147. OutPacket(reply, ThrottleOutPacketType.Task);
  1148. }
  1149. /// <summary>
  1150. /// Send an instant message to this client
  1151. /// </summary>
  1152. //
  1153. // Don't remove transaction ID! Groups and item gives need to set it!
  1154. public void SendInstantMessage(GridInstantMessage im)
  1155. {
  1156. if (((Scene)(m_scene)).Permissions.CanInstantMessage(new UUID(im.fromAgentID), new UUID(im.toAgentID)))
  1157. {
  1158. ImprovedInstantMessagePacket msg
  1159. = (ImprovedInstantMessagePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedInstantMessage);
  1160. msg.AgentData.AgentID = new UUID(im.fromAgentID);
  1161. msg.AgentData.SessionID = UUID.Zero;
  1162. msg.MessageBlock.FromAgentName = Utils.StringToBytes(im.fromAgentName);
  1163. msg.MessageBlock.Dialog = im.dialog;
  1164. msg.MessageBlock.FromGroup = im.fromGroup;
  1165. if (im.imSessionID == UUID.Zero.Guid)
  1166. msg.MessageBlock.ID = new UUID(im.fromAgentID) ^ new UUID(im.toAgentID);
  1167. else
  1168. msg.MessageBlock.ID = new UUID(im.imSessionID);
  1169. msg.MessageBlock.Offline = im.offline;
  1170. msg.MessageBlock.ParentEstateID = im.ParentEstateID;
  1171. msg.MessageBlock.Position = im.Position;
  1172. msg.MessageBlock.RegionID = new UUID(im.RegionID);
  1173. msg.MessageBlock.Timestamp = im.timestamp;
  1174. msg.MessageBlock.ToAgentID = new UUID(im.toAgentID);
  1175. // Cap the message length at 1099. There is a limit in ImprovedInstantMessagePacket
  1176. // the limit is 1100 but a 0 byte gets added to mark the end of the string
  1177. if (im.message != null && im.message.Length > 1099)
  1178. msg.MessageBlock.Message = Utils.StringToBytes(im.message.Substring(0, 1099));
  1179. else
  1180. msg.MessageBlock.Message = Utils.StringToBytes(im.message);
  1181. msg.MessageBlock.BinaryBucket = im.binaryBucket;
  1182. if (im.message.StartsWith("[grouptest]"))
  1183. { // this block is test code for implementing group IM - delete when group IM is finished
  1184. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  1185. if (eq != null)
  1186. {
  1187. im.dialog = 17;
  1188. //eq.ChatterboxInvitation(
  1189. // new UUID("00000000-68f9-1111-024e-222222111123"),
  1190. // "OpenSimulator Testing", im.fromAgentID, im.message, im.toAgentID, im.fromAgentName, im.dialog, 0,
  1191. // false, 0, new Vector3(), 1, im.imSessionID, im.fromGroup, im.binaryBucket);
  1192. eq.ChatterboxInvitation(
  1193. new UUID("00000000-68f9-1111-024e-222222111123"),
  1194. "OpenSimulator Testing", new UUID(im.fromAgentID), im.message, new UUID(im.toAgentID), im.fromAgentName, im.dialog, 0,
  1195. false, 0, new Vector3(), 1, new UUID(im.imSessionID), im.fromGroup, Utils.StringToBytes("OpenSimulator Testing"));
  1196. eq.ChatterBoxSessionAgentListUpdates(
  1197. new UUID("00000000-68f9-1111-024e-222222111123"),
  1198. new UUID(im.fromAgentID), new UUID(im.toAgentID), false, false, false);
  1199. }
  1200. Console.WriteLine("SendInstantMessage: " + msg);
  1201. }
  1202. else
  1203. OutPacket(msg, ThrottleOutPacketType.Task);
  1204. }
  1205. }
  1206. public void SendGenericMessage(string method, List<string> message)
  1207. {
  1208. GenericMessagePacket gmp = new GenericMessagePacket();
  1209. gmp.MethodData.Method = Utils.StringToBytes(method);
  1210. gmp.ParamList = new GenericMessagePacket.ParamListBlock[message.Count];
  1211. int i = 0;
  1212. foreach (string val in message)
  1213. {
  1214. gmp.ParamList[i] = new GenericMessagePacket.ParamListBlock();
  1215. gmp.ParamList[i++].Parameter = Utils.StringToBytes(val);
  1216. }
  1217. OutPacket(gmp, ThrottleOutPacketType.Task);
  1218. }
  1219. /// <summary>
  1220. /// Send the region heightmap to the client
  1221. /// </summary>
  1222. /// <param name="map">heightmap</param>
  1223. public virtual void SendLayerData(float[] map)
  1224. {
  1225. ThreadPool.QueueUserWorkItem(DoSendLayerData, map);
  1226. }
  1227. /// <summary>
  1228. /// Send terrain layer information to the client.
  1229. /// </summary>
  1230. /// <param name="o"></param>
  1231. private void DoSendLayerData(object o)
  1232. {
  1233. float[] map = (float[])o;
  1234. try
  1235. {
  1236. for (int y = 0; y < 16; y++)
  1237. {
  1238. // For some terrains, sending more than one terrain patch at once results in a libsecondlife exception
  1239. // see http://opensimulator.org/mantis/view.php?id=1662
  1240. //for (int x = 0; x < 16; x += 4)
  1241. //{
  1242. // SendLayerPacket(map, y, x);
  1243. // Thread.Sleep(150);
  1244. //}
  1245. for (int x = 0; x < 16; x++)
  1246. {
  1247. SendLayerData(x, y, LLHeightFieldMoronize(map));
  1248. Thread.Sleep(35);
  1249. }
  1250. }
  1251. }
  1252. catch (Exception e)
  1253. {
  1254. m_log.Warn("[CLIENT]: ClientView.API.cs: SendLayerData() - Failed with exception " + e);
  1255. }
  1256. }
  1257. /// <summary>
  1258. /// Sends a set of four patches (x, x+1, ..., x+3) to the client
  1259. /// </summary>
  1260. /// <param name="map">heightmap</param>
  1261. /// <param name="px">X coordinate for patches 0..12</param>
  1262. /// <param name="py">Y coordinate for patches 0..15</param>
  1263. // private void SendLayerPacket(float[] map, int y, int x)
  1264. // {
  1265. // int[] patches = new int[4];
  1266. // patches[0] = x + 0 + y * 16;
  1267. // patches[1] = x + 1 + y * 16;
  1268. // patches[2] = x + 2 + y * 16;
  1269. // patches[3] = x + 3 + y * 16;
  1270. // Packet layerpack = LLClientView.TerrainManager.CreateLandPacket(map, patches);
  1271. // OutPacket(layerpack, ThrottleOutPacketType.Land);
  1272. // }
  1273. /// <summary>
  1274. /// Sends a specified patch to a client
  1275. /// </summary>
  1276. /// <param name="px">Patch coordinate (x) 0..15</param>
  1277. /// <param name="py">Patch coordinate (y) 0..15</param>
  1278. /// <param name="map">heightmap</param>
  1279. public void SendLayerData(int px, int py, float[] map)
  1280. {
  1281. try
  1282. {
  1283. int[] patches = new int[1];
  1284. int patchx, patchy;
  1285. patchx = px;
  1286. patchy = py;
  1287. patches[0] = patchx + 0 + patchy * 16;
  1288. LayerDataPacket layerpack = TerrainCompressor.CreateLandPacket(((map.Length==65536)? map : LLHeightFieldMoronize(map)), patches);
  1289. layerpack.Header.Zerocoded = true;
  1290. OutPacket(layerpack, ThrottleOutPacketType.Land);
  1291. }
  1292. catch (Exception e)
  1293. {
  1294. m_log.Warn("[client]: ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString());
  1295. }
  1296. }
  1297. /// <summary>
  1298. /// Munges heightfield into the LLUDP backed in restricted heightfield.
  1299. /// </summary>
  1300. /// <param name="map">float array in the base; Constants.RegionSize</param>
  1301. /// <returns>float array in the base 256</returns>
  1302. internal float[] LLHeightFieldMoronize(float[] map)
  1303. {
  1304. if (map.Length == 65536)
  1305. return map;
  1306. else
  1307. {
  1308. float[] returnmap = new float[65536];
  1309. if (map.Length < 65535)
  1310. {
  1311. // rebase the vector stride to 256
  1312. for (int i = 0; i < Constants.RegionSize; i++)
  1313. Array.Copy(map, i * (int)Constants.RegionSize, returnmap, i * 256, (int)Constants.RegionSize);
  1314. }
  1315. else
  1316. {
  1317. for (int i = 0; i < 256; i++)
  1318. Array.Copy(map, i * (int)Constants.RegionSize, returnmap, i * 256, 256);
  1319. }
  1320. //Array.Copy(map,0,returnmap,0,(map.Length < 65536)? map.Length : 65536);
  1321. return returnmap;
  1322. }
  1323. }
  1324. /// <summary>
  1325. /// Send the wind matrix to the client
  1326. /// </summary>
  1327. /// <param name="windSpeeds">16x16 array of wind speeds</param>
  1328. public virtual void SendWindData(Vector2[] windSpeeds)
  1329. {
  1330. ThreadPool.QueueUserWorkItem(new WaitCallback(DoSendWindData), (object)windSpeeds);
  1331. }
  1332. /// <summary>
  1333. /// Send the cloud matrix to the client
  1334. /// </summary>
  1335. /// <param name="windSpeeds">16x16 array of cloud densities</param>
  1336. public virtual void SendCloudData(float[] cloudDensity)
  1337. {
  1338. ThreadPool.QueueUserWorkItem(new WaitCallback(DoSendCloudData), (object)cloudDensity);
  1339. }
  1340. /// <summary>
  1341. /// Send wind layer information to the client.
  1342. /// </summary>
  1343. /// <param name="o"></param>
  1344. private void DoSendWindData(object o)
  1345. {
  1346. Vector2[] windSpeeds = (Vector2[])o;
  1347. TerrainPatch[] patches = new TerrainPatch[2];
  1348. patches[0] = new TerrainPatch();
  1349. patches[0].Data = new float[16 * 16];
  1350. patches[1] = new TerrainPatch();
  1351. patches[1].Data = new float[16 * 16];
  1352. for (int y = 0; y < 16; y++)
  1353. {
  1354. for (int x = 0; x < 16; x++)
  1355. {
  1356. patches[0].Data[y * 16 + x] = windSpeeds[y * 16 + x].X;
  1357. patches[1].Data[y * 16 + x] = windSpeeds[y * 16 + x].Y;
  1358. }
  1359. }
  1360. LayerDataPacket layerpack = TerrainCompressor.CreateLayerDataPacket(patches, TerrainPatch.LayerType.Wind);
  1361. layerpack.Header.Zerocoded = true;
  1362. OutPacket(layerpack, ThrottleOutPacketType.Wind);
  1363. }
  1364. /// <summary>
  1365. /// Send cloud layer information to the client.
  1366. /// </summary>
  1367. /// <param name="o"></param>
  1368. private void DoSendCloudData(object o)
  1369. {
  1370. float[] cloudCover = (float[])o;
  1371. TerrainPatch[] patches = new TerrainPatch[1];
  1372. patches[0] = new TerrainPatch();
  1373. patches[0].Data = new float[16 * 16];
  1374. for (int y = 0; y < 16; y++)
  1375. {
  1376. for (int x = 0; x < 16; x++)
  1377. {
  1378. patches[0].Data[y * 16 + x] = cloudCover[y * 16 + x];
  1379. }
  1380. }
  1381. LayerDataPacket layerpack = TerrainCompressor.CreateLayerDataPacket(patches, TerrainPatch.LayerType.Cloud);
  1382. layerpack.Header.Zerocoded = true;
  1383. OutPacket(layerpack, ThrottleOutPacketType.Cloud);
  1384. }
  1385. /// <summary>
  1386. /// Tell the client that the given neighbour region is ready to receive a child agent.
  1387. /// </summary>
  1388. public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourEndPoint)
  1389. {
  1390. IPAddress neighbourIP = neighbourEndPoint.Address;
  1391. ushort neighbourPort = (ushort)neighbourEndPoint.Port;
  1392. EnableSimulatorPacket enablesimpacket = (EnableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.EnableSimulator);
  1393. // TODO: don't create new blocks if recycling an old packet
  1394. enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock();
  1395. enablesimpacket.SimulatorInfo.Handle = neighbourHandle;
  1396. byte[] byteIP = neighbourIP.GetAddressBytes();
  1397. enablesimpacket.SimulatorInfo.IP = (uint)byteIP[3] << 24;
  1398. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[2] << 16;
  1399. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[1] << 8;
  1400. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[0];
  1401. enablesimpacket.SimulatorInfo.Port = neighbourPort;
  1402. OutPacket(enablesimpacket, ThrottleOutPacketType.Task);
  1403. }
  1404. public AgentCircuitData RequestClientInfo()
  1405. {
  1406. AgentCircuitData agentData = new AgentCircuitData();
  1407. agentData.AgentID = AgentId;
  1408. agentData.SessionID = m_sessionId;
  1409. agentData.SecureSessionID = SecureSessionId;
  1410. agentData.circuitcode = m_circuitCode;
  1411. agentData.child = false;
  1412. agentData.firstname = m_firstName;
  1413. agentData.lastname = m_lastName;
  1414. ICapabilitiesModule capsModule = m_scene.RequestModuleInterface<ICapabilitiesModule>();
  1415. if (capsModule == null) // can happen when shutting down.
  1416. return agentData;
  1417. agentData.CapsPath = capsModule.GetCapsPath(m_agentId);
  1418. agentData.ChildrenCapSeeds = new Dictionary<ulong,string>(capsModule.GetChildrenSeeds(m_agentId));
  1419. return agentData;
  1420. }
  1421. public virtual void CrossRegion(ulong newRegionHandle, Vector3 pos, Vector3 lookAt, IPEndPoint externalIPEndPoint,
  1422. string capsURL)
  1423. {
  1424. Vector3 look = new Vector3(lookAt.X * 10, lookAt.Y * 10, lookAt.Z * 10);
  1425. //CrossedRegionPacket newSimPack = (CrossedRegionPacket)PacketPool.Instance.GetPacket(PacketType.CrossedRegion);
  1426. CrossedRegionPacket newSimPack = new CrossedRegionPacket();
  1427. // TODO: don't create new blocks if recycling an old packet
  1428. newSimPack.AgentData = new CrossedRegionPacket.AgentDataBlock();
  1429. newSimPack.AgentData.AgentID = AgentId;
  1430. newSimPack.AgentData.SessionID = m_sessionId;
  1431. newSimPack.Info = new CrossedRegionPacket.InfoBlock();
  1432. newSimPack.Info.Position = pos;
  1433. newSimPack.Info.LookAt = look;
  1434. newSimPack.RegionData = new CrossedRegionPacket.RegionDataBlock();
  1435. newSimPack.RegionData.RegionHandle = newRegionHandle;
  1436. byte[] byteIP = externalIPEndPoint.Address.GetAddressBytes();
  1437. newSimPack.RegionData.SimIP = (uint)byteIP[3] << 24;
  1438. newSimPack.RegionData.SimIP += (uint)byteIP[2] << 16;
  1439. newSimPack.RegionData.SimIP += (uint)byteIP[1] << 8;
  1440. newSimPack.RegionData.SimIP += (uint)byteIP[0];
  1441. newSimPack.RegionData.SimPort = (ushort)externalIPEndPoint.Port;
  1442. newSimPack.RegionData.SeedCapability = Utils.StringToBytes(capsURL);
  1443. // Hack to get this out immediately and skip throttles
  1444. OutPacket(newSimPack, ThrottleOutPacketType.Unknown);
  1445. }
  1446. internal void SendMapBlockSplit(List<MapBlockData> mapBlocks, uint flag)
  1447. {
  1448. MapBlockReplyPacket mapReply = (MapBlockReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapBlockReply);
  1449. // TODO: don't create new blocks if recycling an old packet
  1450. MapBlockData[] mapBlocks2 = mapBlocks.ToArray();
  1451. mapReply.AgentData.AgentID = AgentId;
  1452. mapReply.Data = new MapBlockReplyPacket.DataBlock[mapBlocks2.Length];
  1453. mapReply.AgentData.Flags = flag;
  1454. for (int i = 0; i < mapBlocks2.Length; i++)
  1455. {
  1456. mapReply.Data[i] = new MapBlockReplyPacket.DataBlock();
  1457. mapReply.Data[i].MapImageID = mapBlocks2[i].MapImageId;
  1458. //m_log.Warn(mapBlocks2[i].MapImageId.ToString());
  1459. mapReply.Data[i].X = mapBlocks2[i].X;
  1460. mapReply.Data[i].Y = mapBlocks2[i].Y;
  1461. mapReply.Data[i].WaterHeight = mapBlocks2[i].WaterHeight;
  1462. mapReply.Data[i].Name = Utils.StringToBytes(mapBlocks2[i].Name);
  1463. mapReply.Data[i].RegionFlags = mapBlocks2[i].RegionFlags;
  1464. mapReply.Data[i].Access = mapBlocks2[i].Access;
  1465. mapReply.Data[i].Agents = mapBlocks2[i].Agents;
  1466. }
  1467. OutPacket(mapReply, ThrottleOutPacketType.Land);
  1468. }
  1469. public void SendMapBlock(List<MapBlockData> mapBlocks, uint flag)
  1470. {
  1471. MapBlockData[] mapBlocks2 = mapBlocks.ToArray();
  1472. int maxsend = 10;
  1473. //int packets = Math.Ceiling(mapBlocks2.Length / maxsend);
  1474. List<MapBlockData> sendingBlocks = new List<MapBlockData>();
  1475. for (int i = 0; i < mapBlocks2.Length; i++)
  1476. {
  1477. sendingBlocks.Add(mapBlocks2[i]);
  1478. if (((i + 1) == mapBlocks2.Length) || (((i + 1) % maxsend) == 0))
  1479. {
  1480. SendMapBlockSplit(sendingBlocks, flag);
  1481. sendingBlocks = new List<MapBlockData>();
  1482. }
  1483. }
  1484. }
  1485. public void SendLocalTeleport(Vector3 position, Vector3 lookAt, uint flags)
  1486. {
  1487. TeleportLocalPacket tpLocal = (TeleportLocalPacket)PacketPool.Instance.GetPacket(PacketType.TeleportLocal);
  1488. tpLocal.Info.AgentID = AgentId;
  1489. tpLocal.Info.TeleportFlags = flags;
  1490. tpLocal.Info.LocationID = 2;
  1491. tpLocal.Info.LookAt = lookAt;
  1492. tpLocal.Info.Position = position;
  1493. // Hack to get this out immediately and skip throttles
  1494. OutPacket(tpLocal, ThrottleOutPacketType.Unknown);
  1495. }
  1496. public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint newRegionEndPoint, uint locationID,
  1497. uint flags, string capsURL)
  1498. {
  1499. //TeleportFinishPacket teleport = (TeleportFinishPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFinish);
  1500. TeleportFinishPacket teleport = new TeleportFinishPacket();
  1501. teleport.Info.AgentID = AgentId;
  1502. teleport.Info.RegionHandle = regionHandle;
  1503. teleport.Info.SimAccess = simAccess;
  1504. teleport.Info.SeedCapability = Utils.StringToBytes(capsURL);
  1505. IPAddress oIP = newRegionEndPoint.Address;
  1506. byte[] byteIP = oIP.GetAddressBytes();
  1507. uint ip = (uint)byteIP[3] << 24;
  1508. ip += (uint)byteIP[2] << 16;
  1509. ip += (uint)byteIP[1] << 8;
  1510. ip += (uint)byteIP[0];
  1511. teleport.Info.SimIP = ip;
  1512. teleport.Info.SimPort = (ushort)newRegionEndPoint.Port;
  1513. teleport.Info.LocationID = 4;
  1514. teleport.Info.TeleportFlags = 1 << 4;
  1515. // Hack to get this out immediately and skip throttles.
  1516. OutPacket(teleport, ThrottleOutPacketType.Unknown);
  1517. }
  1518. /// <summary>
  1519. /// Inform the client that a teleport attempt has failed
  1520. /// </summary>
  1521. public void SendTeleportFailed(string reason)
  1522. {
  1523. TeleportFailedPacket tpFailed = (TeleportFailedPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFailed);
  1524. tpFailed.Info.AgentID = AgentId;
  1525. tpFailed.Info.Reason = Utils.StringToBytes(reason);
  1526. tpFailed.AlertInfo = new TeleportFailedPacket.AlertInfoBlock[0];
  1527. // Hack to get this out immediately and skip throttles
  1528. OutPacket(tpFailed, ThrottleOutPacketType.Unknown);
  1529. }
  1530. /// <summary>
  1531. ///
  1532. /// </summary>
  1533. public void SendTeleportLocationStart()
  1534. {
  1535. //TeleportStartPacket tpStart = (TeleportStartPacket)PacketPool.Instance.GetPacket(PacketType.TeleportStart);
  1536. TeleportStartPacket tpStart = new TeleportStartPacket();
  1537. tpStart.Info.TeleportFlags = 16; // Teleport via location
  1538. // Hack to get this out immediately and skip throttles
  1539. OutPacket(tpStart, ThrottleOutPacketType.Unknown);
  1540. }
  1541. public void SendMoneyBalance(UUID transaction, bool success, byte[] description, int balance)
  1542. {
  1543. MoneyBalanceReplyPacket money = (MoneyBalanceReplyPacket)PacketPool.Instance.GetPacket(PacketType.MoneyBalanceReply);
  1544. money.MoneyData.AgentID = AgentId;
  1545. money.MoneyData.TransactionID = transaction;
  1546. money.MoneyData.TransactionSuccess = success;
  1547. money.MoneyData.Description = description;
  1548. money.MoneyData.MoneyBalance = balance;
  1549. OutPacket(money, ThrottleOutPacketType.Task);
  1550. }
  1551. public void SendPayPrice(UUID objectID, int[] payPrice)
  1552. {
  1553. if (payPrice[0] == 0 &&
  1554. payPrice[1] == 0 &&
  1555. payPrice[2] == 0 &&
  1556. payPrice[3] == 0 &&
  1557. payPrice[4] == 0)
  1558. return;
  1559. PayPriceReplyPacket payPriceReply = (PayPriceReplyPacket)PacketPool.Instance.GetPacket(PacketType.PayPriceReply);
  1560. payPriceReply.ObjectData.ObjectID = objectID;
  1561. payPriceReply.ObjectData.DefaultPayPrice = payPrice[0];
  1562. payPriceReply.ButtonData = new PayPriceReplyPacket.ButtonDataBlock[4];
  1563. payPriceReply.ButtonData[0] = new PayPriceReplyPacket.ButtonDataBlock();
  1564. payPriceReply.ButtonData[0].PayButton = payPrice[1];
  1565. payPriceReply.ButtonData[1] = new PayPriceReplyPacket.ButtonDataBlock();
  1566. payPriceReply.ButtonData[1].PayButton = payPrice[2];
  1567. payPriceReply.ButtonData[2] = new PayPriceReplyPacket.ButtonDataBlock();
  1568. payPriceReply.ButtonData[2].PayButton = payPrice[3];
  1569. payPriceReply.ButtonData[3] = new PayPriceReplyPacket.ButtonDataBlock();
  1570. payPriceReply.ButtonData[3].PayButton = payPrice[4];
  1571. OutPacket(payPriceReply, ThrottleOutPacketType.Task);
  1572. }
  1573. public void SendStartPingCheck(byte seq)
  1574. {
  1575. StartPingCheckPacket pc = (StartPingCheckPacket)PacketPool.Instance.GetPacket(PacketType.StartPingCheck);
  1576. pc.PingID.PingID = seq;
  1577. pc.Header.Reliable = false;
  1578. OutPacket(pc, ThrottleOutPacketType.Unknown);
  1579. }
  1580. public void SendKillObject(ulong regionHandle, uint localID)
  1581. {
  1582. KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
  1583. // TODO: don't create new blocks if recycling an old packet
  1584. kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
  1585. kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
  1586. kill.ObjectData[0].ID = localID;
  1587. kill.Header.Reliable = true;
  1588. kill.Header.Zerocoded = true;
  1589. OutPacket(kill, ThrottleOutPacketType.Task);
  1590. }
  1591. /// <summary>
  1592. /// Send information about the items contained in a folder to the client.
  1593. ///
  1594. /// XXX This method needs some refactoring loving
  1595. /// </summary>
  1596. /// <param name="ownerID">The owner of the folder</param>
  1597. /// <param name="folderID">The id of the folder</param>
  1598. /// <param name="items">The items contained in the folder identified by folderID</param>
  1599. /// <param name="folders"></param>
  1600. /// <param name="fetchFolders">Do we need to send folder information?</param>
  1601. /// <param name="fetchItems">Do we need to send item information?</param>
  1602. public void SendInventoryFolderDetails(UUID ownerID, UUID folderID, List<InventoryItemBase> items,
  1603. List<InventoryFolderBase> folders,
  1604. bool fetchFolders, bool fetchItems)
  1605. {
  1606. // An inventory descendents packet consists of a single agent section and an inventory details
  1607. // section for each inventory item. The size of each inventory item is approximately 550 bytes.
  1608. // In theory, UDP has a maximum packet size of 64k, so it should be possible to send descendent
  1609. // packets containing metadata for in excess of 100 items. But in practice, there may be other
  1610. // factors (e.g. firewalls) restraining the maximum UDP packet size. See,
  1611. //
  1612. // http://opensimulator.org/mantis/view.php?id=226
  1613. //
  1614. // for one example of this kind of thing. In fact, the Linden servers appear to only send about
  1615. // 6 to 7 items at a time, so let's stick with 6
  1616. int MAX_ITEMS_PER_PACKET = 6;
  1617. //Ckrinke This variable is not used, so comment out to remove the warning from the compiler (3-21-08)
  1618. //Ckrinke uint FULL_MASK_PERMISSIONS = 2147483647;
  1619. int itemsSent = 0;
  1620. if (fetchItems)
  1621. {
  1622. InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1623. if (items.Count < MAX_ITEMS_PER_PACKET)
  1624. {
  1625. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count];
  1626. }
  1627. else
  1628. {
  1629. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET];
  1630. }
  1631. // Descendents must contain the *total* number of descendents (plus folders, whether we
  1632. // fetch them or not), not the number of entries we send in this packet. For consistency,
  1633. // I'll use it for folder-requests, too, although I wasn't able to get one with
  1634. // FetchFolders = true.
  1635. // TODO this should be checked with FetchFolders = true
  1636. descend.AgentData.Descendents = items.Count + folders.Count;
  1637. int count = 0;
  1638. int i = 0;
  1639. foreach (InventoryItemBase item in items)
  1640. {
  1641. descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock();
  1642. descend.ItemData[i].ItemID = item.ID;
  1643. descend.ItemData[i].AssetID = item.AssetID;
  1644. descend.ItemData[i].CreatorID = item.CreatorIdAsUuid;
  1645. descend.ItemData[i].BaseMask = item.BasePermissions;
  1646. descend.ItemData[i].Description = LLUtil.StringToPacketBytes(item.Description);
  1647. descend.ItemData[i].EveryoneMask = item.EveryOnePermissions;
  1648. descend.ItemData[i].OwnerMask = item.CurrentPermissions;
  1649. descend.ItemData[i].FolderID = item.Folder;
  1650. descend.ItemData[i].InvType = (sbyte)item.InvType;
  1651. descend.ItemData[i].Name = LLUtil.StringToPacketBytes(item.Name);
  1652. descend.ItemData[i].NextOwnerMask = item.NextPermissions;
  1653. descend.ItemData[i].OwnerID = item.Owner;
  1654. descend.ItemData[i].Type = (sbyte)item.AssetType;
  1655. descend.ItemData[i].GroupID = item.GroupID;
  1656. descend.ItemData[i].GroupOwned = item.GroupOwned;
  1657. descend.ItemData[i].GroupMask = item.GroupPermissions;
  1658. descend.ItemData[i].CreationDate = item.CreationDate;
  1659. descend.ItemData[i].SalePrice = item.SalePrice;
  1660. descend.ItemData[i].SaleType = item.SaleType;
  1661. descend.ItemData[i].Flags = item.Flags;
  1662. descend.ItemData[i].CRC =
  1663. Helpers.InventoryCRC(descend.ItemData[i].CreationDate, descend.ItemData[i].SaleType,
  1664. descend.ItemData[i].InvType, descend.ItemData[i].Type,
  1665. descend.ItemData[i].AssetID, descend.ItemData[i].GroupID,
  1666. descend.ItemData[i].SalePrice,
  1667. descend.ItemData[i].OwnerID, descend.ItemData[i].CreatorID,
  1668. descend.ItemData[i].ItemID, descend.ItemData[i].FolderID,
  1669. descend.ItemData[i].EveryoneMask,
  1670. descend.ItemData[i].Flags, descend.ItemData[i].OwnerMask,
  1671. descend.ItemData[i].GroupMask, item.CurrentPermissions);
  1672. i++;
  1673. count++;
  1674. itemsSent++;
  1675. if (i == MAX_ITEMS_PER_PACKET)
  1676. {
  1677. descend.Header.Zerocoded = true;
  1678. AddNullFolderBlockToDecendentsPacket(ref descend);
  1679. OutPacket(descend, ThrottleOutPacketType.Asset);
  1680. if ((items.Count - count) > 0)
  1681. {
  1682. descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1683. if ((items.Count - count) < MAX_ITEMS_PER_PACKET)
  1684. {
  1685. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count - count];
  1686. }
  1687. else
  1688. {
  1689. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET];
  1690. }
  1691. descend.AgentData.Descendents = items.Count + folders.Count;
  1692. i = 0;
  1693. }
  1694. }
  1695. }
  1696. if (0 < i && i < MAX_ITEMS_PER_PACKET)
  1697. {
  1698. AddNullFolderBlockToDecendentsPacket(ref descend);
  1699. OutPacket(descend, ThrottleOutPacketType.Asset);
  1700. }
  1701. }
  1702. //send subfolders
  1703. if (fetchFolders)
  1704. {
  1705. InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1706. if (folders.Count < MAX_ITEMS_PER_PACKET)
  1707. {
  1708. descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders.Count];
  1709. }
  1710. else
  1711. {
  1712. descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET];
  1713. }
  1714. // Not sure if this scenario ever actually occurs, but nonetheless we include the items
  1715. // count even if we're not sending item data for the same reasons as above.
  1716. descend.AgentData.Descendents = items.Count + folders.Count;
  1717. int i = 0;
  1718. int count = 0;
  1719. foreach (InventoryFolderBase folder in folders)
  1720. {
  1721. descend.FolderData[i] = new InventoryDescendentsPacket.FolderDataBlock();
  1722. descend.FolderData[i].FolderID = folder.ID;
  1723. descend.FolderData[i].Name = LLUtil.StringToPacketBytes(folder.Name);
  1724. descend.FolderData[i].ParentID = folder.ParentID;
  1725. descend.FolderData[i].Type = (sbyte)folder.Type;
  1726. i++;
  1727. count++;
  1728. itemsSent++;
  1729. if (i == MAX_ITEMS_PER_PACKET)
  1730. {
  1731. AddNullItemBlockToDescendentsPacket(ref descend);
  1732. OutPacket(descend, ThrottleOutPacketType.Asset);
  1733. if ((folders.Count - count) > 0)
  1734. {
  1735. descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1736. if ((folders.Count - count) < MAX_ITEMS_PER_PACKET)
  1737. {
  1738. descend.FolderData =
  1739. new InventoryDescendentsPacket.FolderDataBlock[folders.Count - count];
  1740. }
  1741. else
  1742. {
  1743. descend.FolderData =
  1744. new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET];
  1745. }
  1746. descend.AgentData.Descendents = items.Count + folders.Count;
  1747. i = 0;
  1748. }
  1749. }
  1750. }
  1751. if (0 < i && i < MAX_ITEMS_PER_PACKET)
  1752. {
  1753. AddNullItemBlockToDescendentsPacket(ref descend);
  1754. OutPacket(descend, ThrottleOutPacketType.Asset);
  1755. }
  1756. }
  1757. if (itemsSent == 0)
  1758. {
  1759. // no items found.
  1760. InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1761. descend.AgentData.Descendents = 0;
  1762. AddNullItemBlockToDescendentsPacket(ref descend);
  1763. AddNullFolderBlockToDecendentsPacket(ref descend);
  1764. OutPacket(descend, ThrottleOutPacketType.Asset);
  1765. }
  1766. }
  1767. private void AddNullFolderBlockToDecendentsPacket(ref InventoryDescendentsPacket packet)
  1768. {
  1769. packet.FolderData = new InventoryDescendentsPacket.FolderDataBlock[1];
  1770. packet.FolderData[0] = new InventoryDescendentsPacket.FolderDataBlock();
  1771. packet.FolderData[0].FolderID = UUID.Zero;
  1772. packet.FolderData[0].ParentID = UUID.Zero;
  1773. packet.FolderData[0].Type = -1;
  1774. packet.FolderData[0].Name = new byte[0];
  1775. }
  1776. private void AddNullItemBlockToDescendentsPacket(ref InventoryDescendentsPacket packet)
  1777. {
  1778. packet.ItemData = new InventoryDescendentsPacket.ItemDataBlock[1];
  1779. packet.ItemData[0] = new InventoryDescendentsPacket.ItemDataBlock();
  1780. packet.ItemData[0].ItemID = UUID.Zero;
  1781. packet.ItemData[0].AssetID = UUID.Zero;
  1782. packet.ItemData[0].CreatorID = UUID.Zero;
  1783. packet.ItemData[0].BaseMask = 0;
  1784. packet.ItemData[0].Description = new byte[0];
  1785. packet.ItemData[0].EveryoneMask = 0;
  1786. packet.ItemData[0].OwnerMask = 0;
  1787. packet.ItemData[0].FolderID = UUID.Zero;
  1788. packet.ItemData[0].InvType = (sbyte)0;
  1789. packet.ItemData[0].Name = new byte[0];
  1790. packet.ItemData[0].NextOwnerMask = 0;
  1791. packet.ItemData[0].OwnerID = UUID.Zero;
  1792. packet.ItemData[0].Type = -1;
  1793. packet.ItemData[0].GroupID = UUID.Zero;
  1794. packet.ItemData[0].GroupOwned = false;
  1795. packet.ItemData[0].GroupMask = 0;
  1796. packet.ItemData[0].CreationDate = 0;
  1797. packet.ItemData[0].SalePrice = 0;
  1798. packet.ItemData[0].SaleType = 0;
  1799. packet.ItemData[0].Flags = 0;
  1800. // No need to add CRC
  1801. }
  1802. private InventoryDescendentsPacket CreateInventoryDescendentsPacket(UUID ownerID, UUID folderID)
  1803. {
  1804. InventoryDescendentsPacket descend = (InventoryDescendentsPacket)PacketPool.Instance.GetPacket(PacketType.InventoryDescendents);
  1805. descend.Header.Zerocoded = true;
  1806. descend.AgentData.AgentID = AgentId;
  1807. descend.AgentData.OwnerID = ownerID;
  1808. descend.AgentData.FolderID = folderID;
  1809. descend.AgentData.Version = 1;
  1810. return descend;
  1811. }
  1812. public void SendInventoryItemDetails(UUID ownerID, InventoryItemBase item)
  1813. {
  1814. const uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
  1815. FetchInventoryReplyPacket inventoryReply = (FetchInventoryReplyPacket)PacketPool.Instance.GetPacket(PacketType.FetchInventoryReply);
  1816. // TODO: don't create new blocks if recycling an old packet
  1817. inventoryReply.AgentData.AgentID = AgentId;
  1818. inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1];
  1819. inventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock();
  1820. inventoryReply.InventoryData[0].ItemID = item.ID;
  1821. inventoryReply.InventoryData[0].AssetID = item.AssetID;
  1822. inventoryReply.InventoryData[0].CreatorID = item.CreatorIdAsUuid;
  1823. inventoryReply.InventoryData[0].BaseMask = item.BasePermissions;
  1824. inventoryReply.InventoryData[0].CreationDate = item.CreationDate;
  1825. inventoryReply.InventoryData[0].Description = LLUtil.StringToPacketBytes(item.Description);
  1826. inventoryReply.InventoryData[0].EveryoneMask = item.EveryOnePermissions;
  1827. inventoryReply.InventoryData[0].FolderID = item.Folder;
  1828. inventoryReply.InventoryData[0].InvType = (sbyte)item.InvType;
  1829. inventoryReply.InventoryData[0].Name = LLUtil.StringToPacketBytes(item.Name);
  1830. inventoryReply.InventoryData[0].NextOwnerMask = item.NextPermissions;
  1831. inventoryReply.InventoryData[0].OwnerID = item.Owner;
  1832. inventoryReply.InventoryData[0].OwnerMask = item.CurrentPermissions;
  1833. inventoryReply.InventoryData[0].Type = (sbyte)item.AssetType;
  1834. inventoryReply.InventoryData[0].GroupID = item.GroupID;
  1835. inventoryReply.InventoryData[0].GroupOwned = item.GroupOwned;
  1836. inventoryReply.InventoryData[0].GroupMask = item.GroupPermissions;
  1837. inventoryReply.InventoryData[0].Flags = item.Flags;
  1838. inventoryReply.InventoryData[0].SalePrice = item.SalePrice;
  1839. inventoryReply.InventoryData[0].SaleType = item.SaleType;
  1840. inventoryReply.InventoryData[0].CRC =
  1841. Helpers.InventoryCRC(
  1842. 1000, 0, inventoryReply.InventoryData[0].InvType,
  1843. inventoryReply.InventoryData[0].Type, inventoryReply.InventoryData[0].AssetID,
  1844. inventoryReply.InventoryData[0].GroupID, 100,
  1845. inventoryReply.InventoryData[0].OwnerID, inventoryReply.InventoryData[0].CreatorID,
  1846. inventoryReply.InventoryData[0].ItemID, inventoryReply.InventoryData[0].FolderID,
  1847. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  1848. FULL_MASK_PERMISSIONS);
  1849. inventoryReply.Header.Zerocoded = true;
  1850. OutPacket(inventoryReply, ThrottleOutPacketType.Asset);
  1851. }
  1852. protected void SendBulkUpdateInventoryFolder(InventoryFolderBase folderBase)
  1853. {
  1854. // XXX: Nasty temporary move that will be resolved shortly
  1855. InventoryFolderImpl folder = (InventoryFolderImpl)folderBase;
  1856. // We will use the same transaction id for all the separate packets to be sent out in this update.
  1857. UUID transactionId = UUID.Random();
  1858. List<BulkUpdateInventoryPacket.FolderDataBlock> folderDataBlocks
  1859. = new List<BulkUpdateInventoryPacket.FolderDataBlock>();
  1860. SendBulkUpdateInventoryFolderRecursive(folder, ref folderDataBlocks, transactionId);
  1861. if (folderDataBlocks.Count > 0)
  1862. {
  1863. // We'll end up with some unsent folder blocks if there were some empty folders at the end of the list
  1864. // Send these now
  1865. BulkUpdateInventoryPacket bulkUpdate
  1866. = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
  1867. bulkUpdate.Header.Zerocoded = true;
  1868. bulkUpdate.AgentData.AgentID = AgentId;
  1869. bulkUpdate.AgentData.TransactionID = transactionId;
  1870. bulkUpdate.FolderData = folderDataBlocks.ToArray();
  1871. //m_log.Debug("SendBulkUpdateInventory :" + bulkUpdate);
  1872. OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
  1873. }
  1874. }
  1875. /// <summary>
  1876. /// Recursively construct bulk update packets to send folders and items
  1877. /// </summary>
  1878. /// <param name="folder"></param>
  1879. /// <param name="folderDataBlocks"></param>
  1880. /// <param name="transactionId"></param>
  1881. private void SendBulkUpdateInventoryFolderRecursive(
  1882. InventoryFolderImpl folder, ref List<BulkUpdateInventoryPacket.FolderDataBlock> folderDataBlocks,
  1883. UUID transactionId)
  1884. {
  1885. folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder));
  1886. const int MAX_ITEMS_PER_PACKET = 5;
  1887. // If there are any items then we have to start sending them off in this packet - the next folder will have
  1888. // to be in its own bulk update packet. Also, we can only fit 5 items in a packet (at least this was the limit
  1889. // being used on the Linden grid at 20081203).
  1890. List<InventoryItemBase> items = folder.RequestListOfItems();
  1891. while (items.Count > 0)
  1892. {
  1893. BulkUpdateInventoryPacket bulkUpdate
  1894. = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
  1895. bulkUpdate.Header.Zerocoded = true;
  1896. bulkUpdate.AgentData.AgentID = AgentId;
  1897. bulkUpdate.AgentData.TransactionID = transactionId;
  1898. bulkUpdate.FolderData = folderDataBlocks.ToArray();
  1899. int itemsToSend = (items.Count > MAX_ITEMS_PER_PACKET ? MAX_ITEMS_PER_PACKET : items.Count);
  1900. bulkUpdate.ItemData = new BulkUpdateInventoryPacket.ItemDataBlock[itemsToSend];
  1901. for (int i = 0; i < itemsToSend; i++)
  1902. {
  1903. // Remove from the end of the list so that we don't incur a performance penalty
  1904. bulkUpdate.ItemData[i] = GenerateBulkUpdateItemDataBlock(items[items.Count - 1]);
  1905. items.RemoveAt(items.Count - 1);
  1906. }
  1907. //m_log.Debug("SendBulkUpdateInventoryRecursive :" + bulkUpdate);
  1908. OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
  1909. folderDataBlocks = new List<BulkUpdateInventoryPacket.FolderDataBlock>();
  1910. // If we're going to be sending another items packet then it needs to contain just the folder to which those
  1911. // items belong.
  1912. if (items.Count > 0)
  1913. folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder));
  1914. }
  1915. List<InventoryFolderImpl> subFolders = folder.RequestListOfFolderImpls();
  1916. foreach (InventoryFolderImpl subFolder in subFolders)
  1917. {
  1918. SendBulkUpdateInventoryFolderRecursive(subFolder, ref folderDataBlocks, transactionId);
  1919. }
  1920. }
  1921. /// <summary>
  1922. /// Generate a bulk update inventory data block for the given folder
  1923. /// </summary>
  1924. /// <param name="folder"></param>
  1925. /// <returns></returns>
  1926. private BulkUpdateInventoryPacket.FolderDataBlock GenerateBulkUpdateFolderDataBlock(InventoryFolderBase folder)
  1927. {
  1928. BulkUpdateInventoryPacket.FolderDataBlock folderBlock = new BulkUpdateInventoryPacket.FolderDataBlock();
  1929. folderBlock.FolderID = folder.ID;
  1930. folderBlock.ParentID = folder.ParentID;
  1931. folderBlock.Type = -1;
  1932. folderBlock.Name = LLUtil.StringToPacketBytes(folder.Name);
  1933. return folderBlock;
  1934. }
  1935. /// <summary>
  1936. /// Generate a bulk update inventory data block for the given item
  1937. /// </summary>
  1938. /// <param name="item"></param>
  1939. /// <returns></returns>
  1940. private BulkUpdateInventoryPacket.ItemDataBlock GenerateBulkUpdateItemDataBlock(InventoryItemBase item)
  1941. {
  1942. BulkUpdateInventoryPacket.ItemDataBlock itemBlock = new BulkUpdateInventoryPacket.ItemDataBlock();
  1943. itemBlock.ItemID = item.ID;
  1944. itemBlock.AssetID = item.AssetID;
  1945. itemBlock.CreatorID = item.CreatorIdAsUuid;
  1946. itemBlock.BaseMask = item.BasePermissions;
  1947. itemBlock.Description = LLUtil.StringToPacketBytes(item.Description);
  1948. itemBlock.EveryoneMask = item.EveryOnePermissions;
  1949. itemBlock.FolderID = item.Folder;
  1950. itemBlock.InvType = (sbyte)item.InvType;
  1951. itemBlock.Name = LLUtil.StringToPacketBytes(item.Name);
  1952. itemBlock.NextOwnerMask = item.NextPermissions;
  1953. itemBlock.OwnerID = item.Owner;
  1954. itemBlock.OwnerMask = item.CurrentPermissions;
  1955. itemBlock.Type = (sbyte)item.AssetType;
  1956. itemBlock.GroupID = item.GroupID;
  1957. itemBlock.GroupOwned = item.GroupOwned;
  1958. itemBlock.GroupMask = item.GroupPermissions;
  1959. itemBlock.Flags = item.Flags;
  1960. itemBlock.SalePrice = item.SalePrice;
  1961. itemBlock.SaleType = item.SaleType;
  1962. itemBlock.CreationDate = item.CreationDate;
  1963. itemBlock.CRC =
  1964. Helpers.InventoryCRC(
  1965. 1000, 0, itemBlock.InvType,
  1966. itemBlock.Type, itemBlock.AssetID,
  1967. itemBlock.GroupID, 100,
  1968. itemBlock.OwnerID, itemBlock.CreatorID,
  1969. itemBlock.ItemID, itemBlock.FolderID,
  1970. (uint)PermissionMask.All, 1, (uint)PermissionMask.All, (uint)PermissionMask.All,
  1971. (uint)PermissionMask.All);
  1972. return itemBlock;
  1973. }
  1974. public void SendBulkUpdateInventory(InventoryNodeBase node)
  1975. {
  1976. if (node is InventoryItemBase)
  1977. SendBulkUpdateInventoryItem((InventoryItemBase)node);
  1978. else if (node is InventoryFolderBase)
  1979. SendBulkUpdateInventoryFolder((InventoryFolderBase)node);
  1980. else
  1981. m_log.ErrorFormat("[CLIENT]: Client for {0} sent unknown inventory node named {1}", Name, node.Name);
  1982. }
  1983. protected void SendBulkUpdateInventoryItem(InventoryItemBase item)
  1984. {
  1985. const uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
  1986. BulkUpdateInventoryPacket bulkUpdate
  1987. = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
  1988. bulkUpdate.AgentData.AgentID = AgentId;
  1989. bulkUpdate.AgentData.TransactionID = UUID.Random();
  1990. bulkUpdate.FolderData = new BulkUpdateInventoryPacket.FolderDataBlock[1];
  1991. bulkUpdate.FolderData[0] = new BulkUpdateInventoryPacket.FolderDataBlock();
  1992. bulkUpdate.FolderData[0].FolderID = UUID.Zero;
  1993. bulkUpdate.FolderData[0].ParentID = UUID.Zero;
  1994. bulkUpdate.FolderData[0].Type = -1;
  1995. bulkUpdate.FolderData[0].Name = new byte[0];
  1996. bulkUpdate.ItemData = new BulkUpdateInventoryPacket.ItemDataBlock[1];
  1997. bulkUpdate.ItemData[0] = new BulkUpdateInventoryPacket.ItemDataBlock();
  1998. bulkUpdate.ItemData[0].ItemID = item.ID;
  1999. bulkUpdate.ItemData[0].AssetID = item.AssetID;
  2000. bulkUpdate.ItemData[0].CreatorID = item.CreatorIdAsUuid;
  2001. bulkUpdate.ItemData[0].BaseMask = item.BasePermissions;
  2002. bulkUpdate.ItemData[0].CreationDate = item.CreationDate;
  2003. bulkUpdate.ItemData[0].Description = LLUtil.StringToPacketBytes(item.Description);
  2004. bulkUpdate.ItemData[0].EveryoneMask = item.EveryOnePermissions;
  2005. bulkUpdate.ItemData[0].FolderID = item.Folder;
  2006. bulkUpdate.ItemData[0].InvType = (sbyte)item.InvType;
  2007. bulkUpdate.ItemData[0].Name = LLUtil.StringToPacketBytes(item.Name);
  2008. bulkUpdate.ItemData[0].NextOwnerMask = item.NextPermissions;
  2009. bulkUpdate.ItemData[0].OwnerID = item.Owner;
  2010. bulkUpdate.ItemData[0].OwnerMask = item.CurrentPermissions;
  2011. bulkUpdate.ItemData[0].Type = (sbyte)item.AssetType;
  2012. bulkUpdate.ItemData[0].GroupID = item.GroupID;
  2013. bulkUpdate.ItemData[0].GroupOwned = item.GroupOwned;
  2014. bulkUpdate.ItemData[0].GroupMask = item.GroupPermissions;
  2015. bulkUpdate.ItemData[0].Flags = item.Flags;
  2016. bulkUpdate.ItemData[0].SalePrice = item.SalePrice;
  2017. bulkUpdate.ItemData[0].SaleType = item.SaleType;
  2018. bulkUpdate.ItemData[0].CRC =
  2019. Helpers.InventoryCRC(1000, 0, bulkUpdate.ItemData[0].InvType,
  2020. bulkUpdate.ItemData[0].Type, bulkUpdate.ItemData[0].AssetID,
  2021. bulkUpdate.ItemData[0].GroupID, 100,
  2022. bulkUpdate.ItemData[0].OwnerID, bulkUpdate.ItemData[0].CreatorID,
  2023. bulkUpdate.ItemData[0].ItemID, bulkUpdate.ItemData[0].FolderID,
  2024. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  2025. FULL_MASK_PERMISSIONS);
  2026. bulkUpdate.Header.Zerocoded = true;
  2027. OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
  2028. }
  2029. /// <see>IClientAPI.SendInventoryItemCreateUpdate(InventoryItemBase)</see>
  2030. public void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId)
  2031. {
  2032. const uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
  2033. UpdateCreateInventoryItemPacket InventoryReply
  2034. = (UpdateCreateInventoryItemPacket)PacketPool.Instance.GetPacket(
  2035. PacketType.UpdateCreateInventoryItem);
  2036. // TODO: don't create new blocks if recycling an old packet
  2037. InventoryReply.AgentData.AgentID = AgentId;
  2038. InventoryReply.AgentData.SimApproved = true;
  2039. InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
  2040. InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
  2041. InventoryReply.InventoryData[0].ItemID = Item.ID;
  2042. InventoryReply.InventoryData[0].AssetID = Item.AssetID;
  2043. InventoryReply.InventoryData[0].CreatorID = Item.CreatorIdAsUuid;
  2044. InventoryReply.InventoryData[0].BaseMask = Item.BasePermissions;
  2045. InventoryReply.InventoryData[0].Description = LLUtil.StringToPacketBytes(Item.Description);
  2046. InventoryReply.InventoryData[0].EveryoneMask = Item.EveryOnePermissions;
  2047. InventoryReply.InventoryData[0].FolderID = Item.Folder;
  2048. InventoryReply.InventoryData[0].InvType = (sbyte)Item.InvType;
  2049. InventoryReply.InventoryData[0].Name = LLUtil.StringToPacketBytes(Item.Name);
  2050. InventoryReply.InventoryData[0].NextOwnerMask = Item.NextPermissions;
  2051. InventoryReply.InventoryData[0].OwnerID = Item.Owner;
  2052. InventoryReply.InventoryData[0].OwnerMask = Item.CurrentPermissions;
  2053. InventoryReply.InventoryData[0].Type = (sbyte)Item.AssetType;
  2054. InventoryReply.InventoryData[0].CallbackID = callbackId;
  2055. InventoryReply.InventoryData[0].GroupID = Item.GroupID;
  2056. InventoryReply.InventoryData[0].GroupOwned = Item.GroupOwned;
  2057. InventoryReply.InventoryData[0].GroupMask = Item.GroupPermissions;
  2058. InventoryReply.InventoryData[0].Flags = Item.Flags;
  2059. InventoryReply.InventoryData[0].SalePrice = Item.SalePrice;
  2060. InventoryReply.InventoryData[0].SaleType = Item.SaleType;
  2061. InventoryReply.InventoryData[0].CreationDate = Item.CreationDate;
  2062. InventoryReply.InventoryData[0].CRC =
  2063. Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType,
  2064. InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID,
  2065. InventoryReply.InventoryData[0].GroupID, 100,
  2066. InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID,
  2067. InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID,
  2068. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  2069. FULL_MASK_PERMISSIONS);
  2070. InventoryReply.Header.Zerocoded = true;
  2071. OutPacket(InventoryReply, ThrottleOutPacketType.Asset);
  2072. }
  2073. public void SendRemoveInventoryItem(UUID itemID)
  2074. {
  2075. RemoveInventoryItemPacket remove = (RemoveInventoryItemPacket)PacketPool.Instance.GetPacket(PacketType.RemoveInventoryItem);
  2076. // TODO: don't create new blocks if recycling an old packet
  2077. remove.AgentData.AgentID = AgentId;
  2078. remove.AgentData.SessionID = m_sessionId;
  2079. remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1];
  2080. remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock();
  2081. remove.InventoryData[0].ItemID = itemID;
  2082. remove.Header.Zerocoded = true;
  2083. OutPacket(remove, ThrottleOutPacketType.Asset);
  2084. }
  2085. public void SendTakeControls(int controls, bool passToAgent, bool TakeControls)
  2086. {
  2087. ScriptControlChangePacket scriptcontrol = (ScriptControlChangePacket)PacketPool.Instance.GetPacket(PacketType.ScriptControlChange);
  2088. ScriptControlChangePacket.DataBlock[] data = new ScriptControlChangePacket.DataBlock[1];
  2089. ScriptControlChangePacket.DataBlock ddata = new ScriptControlChangePacket.DataBlock();
  2090. ddata.Controls = (uint)controls;
  2091. ddata.PassToAgent = passToAgent;
  2092. ddata.TakeControls = TakeControls;
  2093. data[0] = ddata;
  2094. scriptcontrol.Data = data;
  2095. OutPacket(scriptcontrol, ThrottleOutPacketType.Task);
  2096. }
  2097. public void SendTaskInventory(UUID taskID, short serial, byte[] fileName)
  2098. {
  2099. ReplyTaskInventoryPacket replytask = (ReplyTaskInventoryPacket)PacketPool.Instance.GetPacket(PacketType.ReplyTaskInventory);
  2100. replytask.InventoryData.TaskID = taskID;
  2101. replytask.InventoryData.Serial = serial;
  2102. replytask.InventoryData.Filename = fileName;
  2103. OutPacket(replytask, ThrottleOutPacketType.Asset);
  2104. }
  2105. public void SendXferPacket(ulong xferID, uint packet, byte[] data)
  2106. {
  2107. SendXferPacketPacket sendXfer = (SendXferPacketPacket)PacketPool.Instance.GetPacket(PacketType.SendXferPacket);
  2108. sendXfer.XferID.ID = xferID;
  2109. sendXfer.XferID.Packet = packet;
  2110. sendXfer.DataPacket.Data = data;
  2111. OutPacket(sendXfer, ThrottleOutPacketType.Task);
  2112. }
  2113. public void SendEconomyData(float EnergyEfficiency, int ObjectCapacity, int ObjectCount, int PriceEnergyUnit,
  2114. int PriceGroupCreate, int PriceObjectClaim, float PriceObjectRent, float PriceObjectScaleFactor,
  2115. int PriceParcelClaim, float PriceParcelClaimFactor, int PriceParcelRent, int PricePublicObjectDecay,
  2116. int PricePublicObjectDelete, int PriceRentLight, int PriceUpload, int TeleportMinPrice, float TeleportPriceExponent)
  2117. {
  2118. EconomyDataPacket economyData = (EconomyDataPacket)PacketPool.Instance.GetPacket(PacketType.EconomyData);
  2119. economyData.Info.EnergyEfficiency = EnergyEfficiency;
  2120. economyData.Info.ObjectCapacity = ObjectCapacity;
  2121. economyData.Info.ObjectCount = ObjectCount;
  2122. economyData.Info.PriceEnergyUnit = PriceEnergyUnit;
  2123. economyData.Info.PriceGroupCreate = PriceGroupCreate;
  2124. economyData.Info.PriceObjectClaim = PriceObjectClaim;
  2125. economyData.Info.PriceObjectRent = PriceObjectRent;
  2126. economyData.Info.PriceObjectScaleFactor = PriceObjectScaleFactor;
  2127. economyData.Info.PriceParcelClaim = PriceParcelClaim;
  2128. economyData.Info.PriceParcelClaimFactor = PriceParcelClaimFactor;
  2129. economyData.Info.PriceParcelRent = PriceParcelRent;
  2130. economyData.Info.PricePublicObjectDecay = PricePublicObjectDecay;
  2131. economyData.Info.PricePublicObjectDelete = PricePublicObjectDelete;
  2132. economyData.Info.PriceRentLight = PriceRentLight;
  2133. economyData.Info.PriceUpload = PriceUpload;
  2134. economyData.Info.TeleportMinPrice = TeleportMinPrice;
  2135. economyData.Info.TeleportPriceExponent = TeleportPriceExponent;
  2136. economyData.Header.Reliable = true;
  2137. OutPacket(economyData, ThrottleOutPacketType.Unknown);
  2138. }
  2139. public void SendAvatarPickerReply(AvatarPickerReplyAgentDataArgs AgentData, List<AvatarPickerReplyDataArgs> Data)
  2140. {
  2141. //construct the AvatarPickerReply packet.
  2142. AvatarPickerReplyPacket replyPacket = new AvatarPickerReplyPacket();
  2143. replyPacket.AgentData.AgentID = AgentData.AgentID;
  2144. replyPacket.AgentData.QueryID = AgentData.QueryID;
  2145. //int i = 0;
  2146. List<AvatarPickerReplyPacket.DataBlock> data_block = new List<AvatarPickerReplyPacket.DataBlock>();
  2147. foreach (AvatarPickerReplyDataArgs arg in Data)
  2148. {
  2149. AvatarPickerReplyPacket.DataBlock db = new AvatarPickerReplyPacket.DataBlock();
  2150. db.AvatarID = arg.AvatarID;
  2151. db.FirstName = arg.FirstName;
  2152. db.LastName = arg.LastName;
  2153. data_block.Add(db);
  2154. }
  2155. replyPacket.Data = data_block.ToArray();
  2156. OutPacket(replyPacket, ThrottleOutPacketType.Task);
  2157. }
  2158. public void SendAgentDataUpdate(UUID agentid, UUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname, string grouptitle)
  2159. {
  2160. m_activeGroupID = activegroupid;
  2161. m_activeGroupName = groupname;
  2162. m_activeGroupPowers = grouppowers;
  2163. AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate);
  2164. sendAgentDataUpdate.AgentData.ActiveGroupID = activegroupid;
  2165. sendAgentDataUpdate.AgentData.AgentID = agentid;
  2166. sendAgentDataUpdate.AgentData.FirstName = Utils.StringToBytes(firstname);
  2167. sendAgentDataUpdate.AgentData.GroupName = Utils.StringToBytes(groupname);
  2168. sendAgentDataUpdate.AgentData.GroupPowers = grouppowers;
  2169. sendAgentDataUpdate.AgentData.GroupTitle = Utils.StringToBytes(grouptitle);
  2170. sendAgentDataUpdate.AgentData.LastName = Utils.StringToBytes(lastname);
  2171. OutPacket(sendAgentDataUpdate, ThrottleOutPacketType.Task);
  2172. }
  2173. /// <summary>
  2174. /// Send an alert message to the client. On the Linden client (tested 1.19.1.4), this pops up a brief duration
  2175. /// blue information box in the bottom right hand corner.
  2176. /// </summary>
  2177. /// <param name="message"></param>
  2178. public void SendAlertMessage(string message)
  2179. {
  2180. AlertMessagePacket alertPack = (AlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AlertMessage);
  2181. alertPack.AlertData = new AlertMessagePacket.AlertDataBlock();
  2182. alertPack.AlertData.Message = Utils.StringToBytes(message);
  2183. alertPack.AlertInfo = new AlertMessagePacket.AlertInfoBlock[0];
  2184. OutPacket(alertPack, ThrottleOutPacketType.Task);
  2185. }
  2186. /// <summary>
  2187. /// Send an agent alert message to the client.
  2188. /// </summary>
  2189. /// <param name="message"></param>
  2190. /// <param name="modal">On the linden client, if this true then it displays a one button text box placed in the
  2191. /// middle of the window. If false, the message is displayed in a brief duration blue information box (as for
  2192. /// the AlertMessage packet).</param>
  2193. public void SendAgentAlertMessage(string message, bool modal)
  2194. {
  2195. OutPacket(BuildAgentAlertPacket(message, modal), ThrottleOutPacketType.Task);
  2196. }
  2197. /// <summary>
  2198. /// Construct an agent alert packet
  2199. /// </summary>
  2200. /// <param name="message"></param>
  2201. /// <param name="modal"></param>
  2202. /// <returns></returns>
  2203. protected AgentAlertMessagePacket BuildAgentAlertPacket(string message, bool modal)
  2204. {
  2205. AgentAlertMessagePacket alertPack = (AgentAlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AgentAlertMessage);
  2206. alertPack.AgentData.AgentID = AgentId;
  2207. alertPack.AlertData.Message = Utils.StringToBytes(message);
  2208. alertPack.AlertData.Modal = modal;
  2209. return alertPack;
  2210. }
  2211. public void SendLoadURL(string objectname, UUID objectID, UUID ownerID, bool groupOwned, string message,
  2212. string url)
  2213. {
  2214. LoadURLPacket loadURL = (LoadURLPacket)PacketPool.Instance.GetPacket(PacketType.LoadURL);
  2215. loadURL.Data.ObjectName = Utils.StringToBytes(objectname);
  2216. loadURL.Data.ObjectID = objectID;
  2217. loadURL.Data.OwnerID = ownerID;
  2218. loadURL.Data.OwnerIsGroup = groupOwned;
  2219. loadURL.Data.Message = Utils.StringToBytes(message);
  2220. loadURL.Data.URL = Utils.StringToBytes(url);
  2221. OutPacket(loadURL, ThrottleOutPacketType.Task);
  2222. }
  2223. public void SendDialog(string objectname, UUID objectID, string ownerFirstName, string ownerLastName, string msg, UUID textureID, int ch, string[] buttonlabels)
  2224. {
  2225. ScriptDialogPacket dialog = (ScriptDialogPacket)PacketPool.Instance.GetPacket(PacketType.ScriptDialog);
  2226. dialog.Data.ObjectID = objectID;
  2227. dialog.Data.ObjectName = Utils.StringToBytes(objectname);
  2228. // this is the username of the *owner*
  2229. dialog.Data.FirstName = Utils.StringToBytes(ownerFirstName);
  2230. dialog.Data.LastName = Utils.StringToBytes(ownerLastName);
  2231. dialog.Data.Message = Utils.StringToBytes(msg);
  2232. dialog.Data.ImageID = textureID;
  2233. dialog.Data.ChatChannel = ch;
  2234. ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[buttonlabels.Length];
  2235. for (int i = 0; i < buttonlabels.Length; i++)
  2236. {
  2237. buttons[i] = new ScriptDialogPacket.ButtonsBlock();
  2238. buttons[i].ButtonLabel = Utils.StringToBytes(buttonlabels[i]);
  2239. }
  2240. dialog.Buttons = buttons;
  2241. OutPacket(dialog, ThrottleOutPacketType.Task);
  2242. }
  2243. public void SendPreLoadSound(UUID objectID, UUID ownerID, UUID soundID)
  2244. {
  2245. PreloadSoundPacket preSound = (PreloadSoundPacket)PacketPool.Instance.GetPacket(PacketType.PreloadSound);
  2246. // TODO: don't create new blocks if recycling an old packet
  2247. preSound.DataBlock = new PreloadSoundPacket.DataBlockBlock[1];
  2248. preSound.DataBlock[0] = new PreloadSoundPacket.DataBlockBlock();
  2249. preSound.DataBlock[0].ObjectID = objectID;
  2250. preSound.DataBlock[0].OwnerID = ownerID;
  2251. preSound.DataBlock[0].SoundID = soundID;
  2252. preSound.Header.Zerocoded = true;
  2253. OutPacket(preSound, ThrottleOutPacketType.Task);
  2254. }
  2255. public void SendPlayAttachedSound(UUID soundID, UUID objectID, UUID ownerID, float gain, byte flags)
  2256. {
  2257. AttachedSoundPacket sound = (AttachedSoundPacket)PacketPool.Instance.GetPacket(PacketType.AttachedSound);
  2258. sound.DataBlock.SoundID = soundID;
  2259. sound.DataBlock.ObjectID = objectID;
  2260. sound.DataBlock.OwnerID = ownerID;
  2261. sound.DataBlock.Gain = gain;
  2262. sound.DataBlock.Flags = flags;
  2263. OutPacket(sound, ThrottleOutPacketType.Task);
  2264. }
  2265. public void SendTriggeredSound(UUID soundID, UUID ownerID, UUID objectID, UUID parentID, ulong handle, Vector3 position, float gain)
  2266. {
  2267. SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger);
  2268. sound.SoundData.SoundID = soundID;
  2269. sound.SoundData.OwnerID = ownerID;
  2270. sound.SoundData.ObjectID = objectID;
  2271. sound.SoundData.ParentID = parentID;
  2272. sound.SoundData.Handle = handle;
  2273. sound.SoundData.Position = position;
  2274. sound.SoundData.Gain = gain;
  2275. OutPacket(sound, ThrottleOutPacketType.Task);
  2276. }
  2277. public void SendAttachedSoundGainChange(UUID objectID, float gain)
  2278. {
  2279. AttachedSoundGainChangePacket sound = (AttachedSoundGainChangePacket)PacketPool.Instance.GetPacket(PacketType.AttachedSoundGainChange);
  2280. sound.DataBlock.ObjectID = objectID;
  2281. sound.DataBlock.Gain = gain;
  2282. OutPacket(sound, ThrottleOutPacketType.Task);
  2283. }
  2284. public void SendSunPos(Vector3 Position, Vector3 Velocity, ulong CurrentTime, uint SecondsPerSunCycle, uint SecondsPerYear, float OrbitalPosition)
  2285. {
  2286. // Viewers based on the Linden viwer code, do wacky things for oribital positions from Midnight to Sunrise
  2287. // So adjust for that
  2288. // Contributed by: Godfrey
  2289. if (OrbitalPosition > m_sunPainDaHalfOrbitalCutoff) // things get weird from midnight to sunrise
  2290. {
  2291. OrbitalPosition = (OrbitalPosition - m_sunPainDaHalfOrbitalCutoff) * 0.6666666667f + m_sunPainDaHalfOrbitalCutoff;
  2292. }
  2293. SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
  2294. viewertime.TimeInfo.SunDirection = Position;
  2295. viewertime.TimeInfo.SunAngVelocity = Velocity;
  2296. // Sun module used to add 6 hours to adjust for linden sun hour, adding here
  2297. // to prevent existing code from breaking if it assumed that 6 hours were included.
  2298. // 21600 == 6 hours * 60 minutes * 60 Seconds
  2299. viewertime.TimeInfo.UsecSinceStart = CurrentTime + 21600;
  2300. viewertime.TimeInfo.SecPerDay = SecondsPerSunCycle;
  2301. viewertime.TimeInfo.SecPerYear = SecondsPerYear;
  2302. viewertime.TimeInfo.SunPhase = OrbitalPosition;
  2303. viewertime.Header.Reliable = false;
  2304. viewertime.Header.Zerocoded = true;
  2305. OutPacket(viewertime, ThrottleOutPacketType.Task);
  2306. }
  2307. // Currently Deprecated
  2308. public void SendViewerTime(int phase)
  2309. {
  2310. /*
  2311. Console.WriteLine("SunPhase: {0}", phase);
  2312. SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
  2313. //viewertime.TimeInfo.SecPerDay = 86400;
  2314. //viewertime.TimeInfo.SecPerYear = 31536000;
  2315. viewertime.TimeInfo.SecPerDay = 1000;
  2316. viewertime.TimeInfo.SecPerYear = 365000;
  2317. viewertime.TimeInfo.SunPhase = 1;
  2318. int sunPhase = (phase + 2) / 2;
  2319. if ((sunPhase < 6) || (sunPhase > 36))
  2320. {
  2321. viewertime.TimeInfo.SunDirection = new Vector3(0f, 0.8f, -0.8f);
  2322. Console.WriteLine("sending night");
  2323. }
  2324. else
  2325. {
  2326. if (sunPhase < 12)
  2327. {
  2328. sunPhase = 12;
  2329. }
  2330. sunPhase = sunPhase - 12;
  2331. float yValue = 0.1f * (sunPhase);
  2332. Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
  2333. if (yValue > 1.2f)
  2334. {
  2335. yValue = yValue - 1.2f;
  2336. }
  2337. yValue = Util.Clip(yValue, 0, 1);
  2338. if (sunPhase < 14)
  2339. {
  2340. yValue = 1 - yValue;
  2341. }
  2342. if (sunPhase < 12)
  2343. {
  2344. yValue *= -1;
  2345. }
  2346. viewertime.TimeInfo.SunDirection = new Vector3(0f, yValue, 0.3f);
  2347. Console.WriteLine("sending sun update " + yValue);
  2348. }
  2349. viewertime.TimeInfo.SunAngVelocity = new Vector3(0, 0.0f, 10.0f);
  2350. viewertime.TimeInfo.UsecSinceStart = (ulong)Util.UnixTimeSinceEpoch();
  2351. viewertime.Header.Reliable = false;
  2352. OutPacket(viewertime, ThrottleOutPacketType.Task);
  2353. */
  2354. }
  2355. public void SendViewerEffect(ViewerEffectPacket.EffectBlock[] effectBlocks)
  2356. {
  2357. ViewerEffectPacket packet = (ViewerEffectPacket)PacketPool.Instance.GetPacket(PacketType.ViewerEffect);
  2358. packet.Effect = effectBlocks;
  2359. packet.AgentData.AgentID = AgentId;
  2360. packet.AgentData.SessionID = SessionId;
  2361. packet.Header.Reliable = false;
  2362. packet.Header.Zerocoded = true;
  2363. OutPacket(packet, ThrottleOutPacketType.Task);
  2364. }
  2365. public void SendAvatarProperties(UUID avatarID, string aboutText, string bornOn, Byte[] charterMember,
  2366. string flAbout, uint flags, UUID flImageID, UUID imageID, string profileURL,
  2367. UUID partnerID)
  2368. {
  2369. AvatarPropertiesReplyPacket avatarReply = (AvatarPropertiesReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPropertiesReply);
  2370. avatarReply.AgentData.AgentID = AgentId;
  2371. avatarReply.AgentData.AvatarID = avatarID;
  2372. if (aboutText != null)
  2373. avatarReply.PropertiesData.AboutText = Utils.StringToBytes(aboutText);
  2374. else
  2375. avatarReply.PropertiesData.AboutText = Utils.StringToBytes("");
  2376. avatarReply.PropertiesData.BornOn = Utils.StringToBytes(bornOn);
  2377. avatarReply.PropertiesData.CharterMember = charterMember;
  2378. if (flAbout != null)
  2379. avatarReply.PropertiesData.FLAboutText = Utils.StringToBytes(flAbout);
  2380. else
  2381. avatarReply.PropertiesData.FLAboutText = Utils.StringToBytes("");
  2382. avatarReply.PropertiesData.Flags = flags;
  2383. avatarReply.PropertiesData.FLImageID = flImageID;
  2384. avatarReply.PropertiesData.ImageID = imageID;
  2385. avatarReply.PropertiesData.ProfileURL = Utils.StringToBytes(profileURL);
  2386. avatarReply.PropertiesData.PartnerID = partnerID;
  2387. OutPacket(avatarReply, ThrottleOutPacketType.Task);
  2388. }
  2389. #endregion
  2390. // Gesture
  2391. #region Appearance/ Wearables Methods
  2392. public void SendWearables(AvatarWearable[] wearables, int serial)
  2393. {
  2394. AgentWearablesUpdatePacket aw = (AgentWearablesUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentWearablesUpdate);
  2395. aw.AgentData.AgentID = AgentId;
  2396. aw.AgentData.SerialNum = (uint)serial;
  2397. aw.AgentData.SessionID = m_sessionId;
  2398. // TODO: don't create new blocks if recycling an old packet
  2399. aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
  2400. AgentWearablesUpdatePacket.WearableDataBlock awb;
  2401. for (int i = 0; i < wearables.Length; i++)
  2402. {
  2403. awb = new AgentWearablesUpdatePacket.WearableDataBlock();
  2404. awb.WearableType = (byte)i;
  2405. awb.AssetID = wearables[i].AssetID;
  2406. awb.ItemID = wearables[i].ItemID;
  2407. aw.WearableData[i] = awb;
  2408. // m_log.DebugFormat(
  2409. // "[APPEARANCE]: Sending wearable item/asset {0} {1} (index {2}) for {3}",
  2410. // awb.ItemID, awb.AssetID, i, Name);
  2411. }
  2412. OutPacket(aw, ThrottleOutPacketType.Task);
  2413. }
  2414. public void SendAppearance(UUID agentID, byte[] visualParams, byte[] textureEntry)
  2415. {
  2416. AvatarAppearancePacket avp = (AvatarAppearancePacket)PacketPool.Instance.GetPacket(PacketType.AvatarAppearance);
  2417. // TODO: don't create new blocks if recycling an old packet
  2418. avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
  2419. avp.ObjectData.TextureEntry = textureEntry;
  2420. AvatarAppearancePacket.VisualParamBlock avblock = null;
  2421. for (int i = 0; i < visualParams.Length; i++)
  2422. {
  2423. avblock = new AvatarAppearancePacket.VisualParamBlock();
  2424. avblock.ParamValue = visualParams[i];
  2425. avp.VisualParam[i] = avblock;
  2426. }
  2427. avp.Sender.IsTrial = false;
  2428. avp.Sender.ID = agentID;
  2429. OutPacket(avp, ThrottleOutPacketType.Task);
  2430. }
  2431. public void SendAnimations(UUID[] animations, int[] seqs, UUID sourceAgentId, UUID[] objectIDs)
  2432. {
  2433. //m_log.DebugFormat("[CLIENT]: Sending animations to {0}", Name);
  2434. AvatarAnimationPacket ani = (AvatarAnimationPacket)PacketPool.Instance.GetPacket(PacketType.AvatarAnimation);
  2435. // TODO: don't create new blocks if recycling an old packet
  2436. ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[animations.Length];
  2437. ani.Sender = new AvatarAnimationPacket.SenderBlock();
  2438. ani.Sender.ID = sourceAgentId;
  2439. ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[animations.Length];
  2440. ani.PhysicalAvatarEventList = new AvatarAnimationPacket.PhysicalAvatarEventListBlock[0];
  2441. for (int i = 0; i < animations.Length; ++i)
  2442. {
  2443. ani.AnimationList[i] = new AvatarAnimationPacket.AnimationListBlock();
  2444. ani.AnimationList[i].AnimID = animations[i];
  2445. ani.AnimationList[i].AnimSequenceID = seqs[i];
  2446. ani.AnimationSourceList[i] = new AvatarAnimationPacket.AnimationSourceListBlock();
  2447. ani.AnimationSourceList[i].ObjectID = objectIDs[i];
  2448. if (objectIDs[i] == UUID.Zero)
  2449. ani.AnimationSourceList[i].ObjectID = sourceAgentId;
  2450. }
  2451. ani.Header.Reliable = false;
  2452. OutPacket(ani, ThrottleOutPacketType.Task);
  2453. }
  2454. #endregion
  2455. #region Avatar Packet/data sending Methods
  2456. /// <summary>
  2457. /// send a objectupdate packet with information about the clients avatar
  2458. /// </summary>
  2459. public void SendAvatarData(ulong regionHandle, string firstName, string lastName, string grouptitle, UUID avatarID,
  2460. uint avatarLocalID, Vector3 Pos, byte[] textureEntry, uint parentID, Quaternion rotation)
  2461. {
  2462. ObjectUpdatePacket objupdate = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
  2463. // TODO: don't create new blocks if recycling an old packet
  2464. objupdate.RegionData.RegionHandle = regionHandle;
  2465. objupdate.RegionData.TimeDilation = ushort.MaxValue;
  2466. objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
  2467. objupdate.ObjectData[0] = CreateDefaultAvatarPacket(textureEntry);
  2468. //give this avatar object a local id and assign the user a name
  2469. objupdate.ObjectData[0].ID = avatarLocalID;
  2470. objupdate.ObjectData[0].FullID = avatarID;
  2471. objupdate.ObjectData[0].ParentID = parentID;
  2472. objupdate.ObjectData[0].NameValue =
  2473. Utils.StringToBytes("FirstName STRING RW SV " + firstName + "\nLastName STRING RW SV " + lastName + "\nTitle STRING RW SV " + grouptitle);
  2474. Vector3 pos2 = new Vector3(Pos.X, Pos.Y, Pos.Z);
  2475. byte[] pb = pos2.GetBytes();
  2476. Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
  2477. byte[] rot = rotation.GetBytes();
  2478. Array.Copy(rot, 0, objupdate.ObjectData[0].ObjectData, 52, rot.Length);
  2479. objupdate.Header.Zerocoded = true;
  2480. OutPacket(objupdate, ThrottleOutPacketType.Task);
  2481. }
  2482. /// <summary>
  2483. /// Send a terse positional/rotation/velocity update about an avatar
  2484. /// to the client. This avatar can be that of the client itself.
  2485. /// </summary>
  2486. public virtual void SendAvatarTerseUpdate(ulong regionHandle,
  2487. ushort timeDilation, uint localID, Vector3 position,
  2488. Vector3 velocity, Quaternion rotation, UUID agentid)
  2489. {
  2490. if (rotation.X == rotation.Y &&
  2491. rotation.Y == rotation.Z &&
  2492. rotation.Z == rotation.W && rotation.W == 0)
  2493. rotation = Quaternion.Identity;
  2494. ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock =
  2495. CreateAvatarImprovedBlock(localID, position, velocity,rotation);
  2496. lock (m_avatarTerseUpdates)
  2497. {
  2498. m_avatarTerseUpdates.Add(terseBlock);
  2499. // If packet is full or own movement packet, send it.
  2500. if (m_avatarTerseUpdates.Count >= m_avatarTerseUpdatesPerPacket)
  2501. {
  2502. ProcessAvatarTerseUpdates(this, null);
  2503. }
  2504. else if (m_avatarTerseUpdates.Count == 1)
  2505. {
  2506. m_avatarTerseUpdateTimer.Start();
  2507. }
  2508. }
  2509. }
  2510. private void ProcessAvatarTerseUpdates(object sender, ElapsedEventArgs e)
  2511. {
  2512. lock (m_avatarTerseUpdates)
  2513. {
  2514. ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
  2515. terse.RegionData = new ImprovedTerseObjectUpdatePacket.RegionDataBlock();
  2516. terse.RegionData.RegionHandle = Scene.RegionInfo.RegionHandle;
  2517. terse.RegionData.TimeDilation =
  2518. (ushort)(Scene.TimeDilation * ushort.MaxValue);
  2519. int max = m_avatarTerseUpdatesPerPacket;
  2520. if (max > m_avatarTerseUpdates.Count)
  2521. max = m_avatarTerseUpdates.Count;
  2522. int count = 0;
  2523. int size = 0;
  2524. byte[] zerobuffer = new byte[1024];
  2525. byte[] blockbuffer = new byte[1024];
  2526. for (count = 0 ; count < max ; count++)
  2527. {
  2528. int length = 0;
  2529. m_avatarTerseUpdates[count].ToBytes(blockbuffer, ref length);
  2530. length = Helpers.ZeroEncode(blockbuffer, length, zerobuffer);
  2531. if (size + length > m_packetMTU)
  2532. break;
  2533. size += length;
  2534. }
  2535. terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[count];
  2536. for (int i = 0 ; i < count ; i++)
  2537. {
  2538. terse.ObjectData[i] = m_avatarTerseUpdates[0];
  2539. m_avatarTerseUpdates.RemoveAt(0);
  2540. }
  2541. terse.Header.Reliable = false;
  2542. terse.Header.Zerocoded = true;
  2543. OutPacket(terse, ThrottleOutPacketType.Task);
  2544. if (m_avatarTerseUpdates.Count == 0)
  2545. m_avatarTerseUpdateTimer.Stop();
  2546. }
  2547. }
  2548. public void SendCoarseLocationUpdate(List<UUID> users, List<Vector3> CoarseLocations)
  2549. {
  2550. if (!IsActive) return; // We don't need to update inactive clients.
  2551. CoarseLocationUpdatePacket loc = (CoarseLocationUpdatePacket)PacketPool.Instance.GetPacket(PacketType.CoarseLocationUpdate);
  2552. // TODO: don't create new blocks if recycling an old packet
  2553. int total = CoarseLocations.Count;
  2554. CoarseLocationUpdatePacket.IndexBlock ib =
  2555. new CoarseLocationUpdatePacket.IndexBlock();
  2556. loc.Location = new CoarseLocationUpdatePacket.LocationBlock[total];
  2557. loc.AgentData = new CoarseLocationUpdatePacket.AgentDataBlock[total];
  2558. for (int i = 0; i < total; i++)
  2559. {
  2560. CoarseLocationUpdatePacket.LocationBlock lb =
  2561. new CoarseLocationUpdatePacket.LocationBlock();
  2562. lb.X = (byte)CoarseLocations[i].X;
  2563. lb.Y = (byte)CoarseLocations[i].Y;
  2564. lb.Z = CoarseLocations[i].Z > 1024 ? (byte)0 : (byte)(CoarseLocations[i].Z * 0.25);
  2565. loc.Location[i] = lb;
  2566. loc.AgentData[i] = new CoarseLocationUpdatePacket.AgentDataBlock();
  2567. loc.AgentData[i].AgentID = users[i];
  2568. }
  2569. ib.You = -1;
  2570. ib.Prey = -1;
  2571. loc.Index = ib;
  2572. loc.Header.Reliable = false;
  2573. loc.Header.Zerocoded = true;
  2574. OutPacket(loc, ThrottleOutPacketType.Task);
  2575. }
  2576. #endregion
  2577. #region Primitive Packet/data Sending Methods
  2578. /// <summary>
  2579. ///
  2580. /// </summary>
  2581. /// <param name="localID"></param>
  2582. /// <param name="rotation"></param>
  2583. /// <param name="attachPoint"></param>
  2584. public void AttachObject(uint localID, Quaternion rotation, byte attachPoint, UUID ownerID)
  2585. {
  2586. if (attachPoint > 30 && ownerID != AgentId) // Someone else's HUD
  2587. return;
  2588. ObjectAttachPacket attach = (ObjectAttachPacket)PacketPool.Instance.GetPacket(PacketType.ObjectAttach);
  2589. // TODO: don't create new blocks if recycling an old packet
  2590. attach.AgentData.AgentID = AgentId;
  2591. attach.AgentData.SessionID = m_sessionId;
  2592. attach.AgentData.AttachmentPoint = attachPoint;
  2593. attach.ObjectData = new ObjectAttachPacket.ObjectDataBlock[1];
  2594. attach.ObjectData[0] = new ObjectAttachPacket.ObjectDataBlock();
  2595. attach.ObjectData[0].ObjectLocalID = localID;
  2596. attach.ObjectData[0].Rotation = rotation;
  2597. attach.Header.Zerocoded = true;
  2598. OutPacket(attach, ThrottleOutPacketType.Task);
  2599. }
  2600. public void SendPrimitiveToClient(
  2601. ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape,
  2602. Vector3 pos, Vector3 vel, Vector3 acc, Quaternion rotation, Vector3 rvel,
  2603. uint flags, UUID objectID, UUID ownerID, string text, byte[] color,
  2604. uint parentID, byte[] particleSystem, byte clickAction, byte material)
  2605. {
  2606. byte[] textureanim = new byte[0];
  2607. SendPrimitiveToClient(regionHandle, timeDilation, localID, primShape, pos, vel,
  2608. acc, rotation, rvel, flags,
  2609. objectID, ownerID, text, color, parentID, particleSystem,
  2610. clickAction, material, textureanim, false, 0, UUID.Zero, UUID.Zero, 0, 0, 0);
  2611. }
  2612. public void SendPrimitiveToClient(
  2613. ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape,
  2614. Vector3 pos, Vector3 velocity, Vector3 acceleration, Quaternion rotation, Vector3 rotational_velocity,
  2615. uint flags,
  2616. UUID objectID, UUID ownerID, string text, byte[] color, uint parentID, byte[] particleSystem,
  2617. byte clickAction, byte material, byte[] textureanim, bool attachment, uint AttachPoint, UUID AssetId, UUID SoundId, double SoundGain, byte SoundFlags, double SoundRadius)
  2618. {
  2619. if (AttachPoint > 30 && ownerID != AgentId) // Someone else's HUD
  2620. return;
  2621. if (primShape.PCode == 9 && primShape.State != 0 && parentID == 0)
  2622. return;
  2623. if (rotation.X == rotation.Y && rotation.Y == rotation.Z && rotation.Z == rotation.W && rotation.W == 0)
  2624. rotation = Quaternion.Identity;
  2625. ObjectUpdatePacket.ObjectDataBlock objectData = CreatePrimUpdateBlock(primShape, flags);
  2626. objectData.ID = localID;
  2627. objectData.FullID = objectID;
  2628. objectData.OwnerID = ownerID;
  2629. objectData.Text = LLUtil.StringToPacketBytes(text);
  2630. objectData.TextColor[0] = color[0];
  2631. objectData.TextColor[1] = color[1];
  2632. objectData.TextColor[2] = color[2];
  2633. objectData.TextColor[3] = color[3];
  2634. objectData.ParentID = parentID;
  2635. objectData.PSBlock = particleSystem;
  2636. objectData.ClickAction = clickAction;
  2637. objectData.Material = material;
  2638. objectData.Flags = 0;
  2639. if (attachment)
  2640. {
  2641. // Necessary???
  2642. objectData.JointAxisOrAnchor = new Vector3(0, 0, 2);
  2643. objectData.JointPivot = new Vector3(0, 0, 0);
  2644. // Item from inventory???
  2645. objectData.NameValue =
  2646. Utils.StringToBytes("AttachItemID STRING RW SV " + AssetId.Guid);
  2647. objectData.State = (byte)((AttachPoint % 16) * 16 + (AttachPoint / 16));
  2648. }
  2649. // Xantor 20080528: Send sound info as well
  2650. // Xantor 20080530: Zero out everything if there's no SoundId, so zerocompression will work again
  2651. objectData.Sound = SoundId;
  2652. if (SoundId == UUID.Zero)
  2653. {
  2654. objectData.OwnerID = UUID.Zero;
  2655. objectData.Gain = 0.0f;
  2656. objectData.Radius = 0.0f;
  2657. objectData.Flags = 0;
  2658. }
  2659. else
  2660. {
  2661. objectData.OwnerID = ownerID;
  2662. objectData.Gain = (float)SoundGain;
  2663. objectData.Radius = (float)SoundRadius;
  2664. objectData.Flags = SoundFlags;
  2665. }
  2666. byte[] pb = pos.GetBytes();
  2667. Array.Copy(pb, 0, objectData.ObjectData, 0, pb.Length);
  2668. byte[] vel = velocity.GetBytes();
  2669. Array.Copy(vel, 0, objectData.ObjectData, pb.Length, vel.Length);
  2670. byte[] rot = rotation.GetBytes();
  2671. Array.Copy(rot, 0, objectData.ObjectData, 36, rot.Length);
  2672. byte[] rvel = rotational_velocity.GetBytes();
  2673. Array.Copy(rvel, 0, objectData.ObjectData, 36 + rot.Length, rvel.Length);
  2674. if (textureanim.Length > 0)
  2675. {
  2676. objectData.TextureAnim = textureanim;
  2677. }
  2678. lock (m_primFullUpdates)
  2679. {
  2680. if (m_primFullUpdates.Count == 0)
  2681. m_primFullUpdateTimer.Start();
  2682. m_primFullUpdates.Add(objectData);
  2683. if (m_primFullUpdates.Count >= m_primFullUpdatesPerPacket)
  2684. ProcessPrimFullUpdates(this, null);
  2685. }
  2686. }
  2687. // Unlike the other timers, this one is only started after
  2688. // the first request is seen.
  2689. void ProcessTextureRequests(object sender, ElapsedEventArgs e)
  2690. {
  2691. if (m_imageManager != null)
  2692. {
  2693. if (m_imageManager.ProcessImageQueue(m_textureSendLimit,
  2694. m_textureDataLimit))
  2695. {
  2696. m_textureRequestTimer.Start();
  2697. }
  2698. }
  2699. }
  2700. void ProcessPrimFullUpdates(object sender, ElapsedEventArgs e)
  2701. {
  2702. lock (m_primFullUpdates)
  2703. {
  2704. if (m_primFullUpdates.Count == 0 && m_primFullUpdateTimer.Enabled)
  2705. {
  2706. m_primFullUpdateTimer.Stop();
  2707. return;
  2708. }
  2709. ObjectUpdatePacket outPacket =
  2710. (ObjectUpdatePacket)PacketPool.Instance.GetPacket(
  2711. PacketType.ObjectUpdate);
  2712. outPacket.RegionData.RegionHandle =
  2713. Scene.RegionInfo.RegionHandle;
  2714. outPacket.RegionData.TimeDilation =
  2715. (ushort)(Scene.TimeDilation * ushort.MaxValue);
  2716. int max = m_primFullUpdates.Count;
  2717. if (max > m_primFullUpdatesPerPacket)
  2718. max = m_primFullUpdatesPerPacket;
  2719. int count = 0;
  2720. int size = 0;
  2721. byte[] zerobuffer = new byte[1024];
  2722. byte[] blockbuffer = new byte[1024];
  2723. for (count = 0 ; count < max ; count++)
  2724. {
  2725. int length = 0;
  2726. m_primFullUpdates[count].ToBytes(blockbuffer, ref length);
  2727. length = Helpers.ZeroEncode(blockbuffer, length, zerobuffer);
  2728. if (size + length > m_packetMTU)
  2729. break;
  2730. size += length;
  2731. }
  2732. outPacket.ObjectData =
  2733. new ObjectUpdatePacket.ObjectDataBlock[count];
  2734. for (int index = 0 ; index < count ; index++)
  2735. {
  2736. outPacket.ObjectData[index] = m_primFullUpdates[0];
  2737. m_primFullUpdates.RemoveAt(0);
  2738. }
  2739. outPacket.Header.Zerocoded = true;
  2740. OutPacket(outPacket, ThrottleOutPacketType.Task | ThrottleOutPacketType.LowPriority);
  2741. if (m_primFullUpdates.Count == 0 && m_primFullUpdateTimer.Enabled)
  2742. m_primFullUpdateTimer.Stop();
  2743. }
  2744. }
  2745. /// <summary>
  2746. ///
  2747. /// </summary>
  2748. public void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, Vector3 position,
  2749. Quaternion rotation, Vector3 velocity, Vector3 rotationalvelocity, byte state, UUID AssetId, UUID ownerID, int attachPoint)
  2750. {
  2751. if (attachPoint > 30 && ownerID != AgentId) // Someone else's HUD
  2752. return;
  2753. if (rotation.X == rotation.Y && rotation.Y == rotation.Z && rotation.Z == rotation.W && rotation.W == 0)
  2754. rotation = Quaternion.Identity;
  2755. ImprovedTerseObjectUpdatePacket.ObjectDataBlock objectData =
  2756. CreatePrimImprovedBlock(localID, position, rotation,
  2757. velocity, rotationalvelocity, state);
  2758. lock (m_primTerseUpdates)
  2759. {
  2760. if (m_primTerseUpdates.Count == 0)
  2761. m_primTerseUpdateTimer.Start();
  2762. m_primTerseUpdates.Add(objectData);
  2763. if (m_primTerseUpdates.Count >= m_primTerseUpdatesPerPacket)
  2764. ProcessPrimTerseUpdates(this, null);
  2765. }
  2766. }
  2767. void ProcessPrimTerseUpdates(object sender, ElapsedEventArgs e)
  2768. {
  2769. lock (m_primTerseUpdates)
  2770. {
  2771. if (m_primTerseUpdates.Count == 0)
  2772. {
  2773. m_primTerseUpdateTimer.Stop();
  2774. return;
  2775. }
  2776. ImprovedTerseObjectUpdatePacket outPacket =
  2777. (ImprovedTerseObjectUpdatePacket)
  2778. PacketPool.Instance.GetPacket(
  2779. PacketType.ImprovedTerseObjectUpdate);
  2780. outPacket.RegionData.RegionHandle =
  2781. Scene.RegionInfo.RegionHandle;
  2782. outPacket.RegionData.TimeDilation =
  2783. (ushort)(Scene.TimeDilation * ushort.MaxValue);
  2784. int max = m_primTerseUpdates.Count;
  2785. if (max > m_primTerseUpdatesPerPacket)
  2786. max = m_primTerseUpdatesPerPacket;
  2787. int count = 0;
  2788. int size = 0;
  2789. byte[] zerobuffer = new byte[1024];
  2790. byte[] blockbuffer = new byte[1024];
  2791. for (count = 0 ; count < max ; count++)
  2792. {
  2793. int length = 0;
  2794. m_primTerseUpdates[count].ToBytes(blockbuffer, ref length);
  2795. length = Helpers.ZeroEncode(blockbuffer, length, zerobuffer);
  2796. if (size + length > m_packetMTU)
  2797. break;
  2798. size += length;
  2799. }
  2800. outPacket.ObjectData =
  2801. new ImprovedTerseObjectUpdatePacket.
  2802. ObjectDataBlock[count];
  2803. for (int index = 0 ; index < count ; index++)
  2804. {
  2805. outPacket.ObjectData[index] = m_primTerseUpdates[0];
  2806. m_primTerseUpdates.RemoveAt(0);
  2807. }
  2808. outPacket.Header.Reliable = false;
  2809. outPacket.Header.Zerocoded = true;
  2810. OutPacket(outPacket, ThrottleOutPacketType.Task | ThrottleOutPacketType.LowPriority);
  2811. if (m_primTerseUpdates.Count == 0)
  2812. m_primTerseUpdateTimer.Stop();
  2813. }
  2814. }
  2815. public void FlushPrimUpdates()
  2816. {
  2817. while (m_primFullUpdates.Count > 0)
  2818. {
  2819. ProcessPrimFullUpdates(this, null);
  2820. }
  2821. while (m_primTerseUpdates.Count > 0)
  2822. {
  2823. ProcessPrimTerseUpdates(this, null);
  2824. }
  2825. while (m_avatarTerseUpdates.Count > 0)
  2826. {
  2827. ProcessAvatarTerseUpdates(this, null);
  2828. }
  2829. }
  2830. public void SendAssetUploadCompleteMessage(sbyte AssetType, bool Success, UUID AssetFullID)
  2831. {
  2832. AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
  2833. newPack.AssetBlock.Type = AssetType;
  2834. newPack.AssetBlock.Success = Success;
  2835. newPack.AssetBlock.UUID = AssetFullID;
  2836. newPack.Header.Zerocoded = true;
  2837. OutPacket(newPack, ThrottleOutPacketType.Asset);
  2838. }
  2839. public void SendXferRequest(ulong XferID, short AssetType, UUID vFileID, byte FilePath, byte[] FileName)
  2840. {
  2841. RequestXferPacket newPack = new RequestXferPacket();
  2842. newPack.XferID.ID = XferID;
  2843. newPack.XferID.VFileType = AssetType;
  2844. newPack.XferID.VFileID = vFileID;
  2845. newPack.XferID.FilePath = FilePath;
  2846. newPack.XferID.Filename = FileName;
  2847. newPack.Header.Zerocoded = true;
  2848. OutPacket(newPack, ThrottleOutPacketType.Asset);
  2849. }
  2850. public void SendConfirmXfer(ulong xferID, uint PacketID)
  2851. {
  2852. ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket();
  2853. newPack.XferID.ID = xferID;
  2854. newPack.XferID.Packet = PacketID;
  2855. newPack.Header.Zerocoded = true;
  2856. OutPacket(newPack, ThrottleOutPacketType.Asset);
  2857. }
  2858. public void SendInitiateDownload(string simFileName, string clientFileName)
  2859. {
  2860. InitiateDownloadPacket newPack = new InitiateDownloadPacket();
  2861. newPack.AgentData.AgentID = AgentId;
  2862. newPack.FileData.SimFilename = Utils.StringToBytes(simFileName);
  2863. newPack.FileData.ViewerFilename = Utils.StringToBytes(clientFileName);
  2864. OutPacket(newPack, ThrottleOutPacketType.Asset);
  2865. }
  2866. public void SendImageFirstPart(
  2867. ushort numParts, UUID ImageUUID, uint ImageSize, byte[] ImageData, byte imageCodec)
  2868. {
  2869. ImageDataPacket im = new ImageDataPacket();
  2870. im.Header.Reliable = false;
  2871. im.ImageID.Packets = numParts;
  2872. im.ImageID.ID = ImageUUID;
  2873. if (ImageSize > 0)
  2874. im.ImageID.Size = ImageSize;
  2875. im.ImageData.Data = ImageData;
  2876. im.ImageID.Codec = imageCodec;
  2877. im.Header.Zerocoded = true;
  2878. OutPacket(im, ThrottleOutPacketType.Texture);
  2879. }
  2880. public void SendImageNextPart(ushort partNumber, UUID imageUuid, byte[] imageData)
  2881. {
  2882. ImagePacketPacket im = new ImagePacketPacket();
  2883. im.Header.Reliable = false;
  2884. im.ImageID.Packet = partNumber;
  2885. im.ImageID.ID = imageUuid;
  2886. im.ImageData.Data = imageData;
  2887. OutPacket(im, ThrottleOutPacketType.Texture);
  2888. }
  2889. public void SendImageNotFound(UUID imageid)
  2890. {
  2891. ImageNotInDatabasePacket notFoundPacket
  2892. = (ImageNotInDatabasePacket)PacketPool.Instance.GetPacket(PacketType.ImageNotInDatabase);
  2893. notFoundPacket.ImageID.ID = imageid;
  2894. OutPacket(notFoundPacket, ThrottleOutPacketType.Texture);
  2895. }
  2896. public void SendShutdownConnectionNotice()
  2897. {
  2898. OutPacket(PacketPool.Instance.GetPacket(PacketType.DisableSimulator), ThrottleOutPacketType.Unknown);
  2899. }
  2900. public void SendSimStats(SimStats stats)
  2901. {
  2902. SimStatsPacket pack = new SimStatsPacket();
  2903. pack.Region = new SimStatsPacket.RegionBlock();
  2904. pack.Region.RegionX = stats.RegionX;
  2905. pack.Region.RegionY = stats.RegionY;
  2906. pack.Region.RegionFlags = stats.RegionFlags;
  2907. pack.Region.ObjectCapacity = stats.ObjectCapacity;
  2908. //pack.Region = //stats.RegionBlock;
  2909. pack.Stat = stats.StatsBlock;
  2910. pack.Header.Reliable = false;
  2911. OutPacket(pack, ThrottleOutPacketType.Task);
  2912. }
  2913. public void SendObjectPropertiesFamilyData(uint RequestFlags, UUID ObjectUUID, UUID OwnerID, UUID GroupID,
  2914. uint BaseMask, uint OwnerMask, uint GroupMask, uint EveryoneMask,
  2915. uint NextOwnerMask, int OwnershipCost, byte SaleType, int SalePrice, uint Category,
  2916. UUID LastOwnerID, string ObjectName, string Description)
  2917. {
  2918. ObjectPropertiesFamilyPacket objPropFamilyPack = (ObjectPropertiesFamilyPacket)PacketPool.Instance.GetPacket(PacketType.ObjectPropertiesFamily);
  2919. // TODO: don't create new blocks if recycling an old packet
  2920. ObjectPropertiesFamilyPacket.ObjectDataBlock objPropDB = new ObjectPropertiesFamilyPacket.ObjectDataBlock();
  2921. objPropDB.RequestFlags = RequestFlags;
  2922. objPropDB.ObjectID = ObjectUUID;
  2923. if (OwnerID == GroupID)
  2924. objPropDB.OwnerID = UUID.Zero;
  2925. else
  2926. objPropDB.OwnerID = OwnerID;
  2927. objPropDB.GroupID = GroupID;
  2928. objPropDB.BaseMask = BaseMask;
  2929. objPropDB.OwnerMask = OwnerMask;
  2930. objPropDB.GroupMask = GroupMask;
  2931. objPropDB.EveryoneMask = EveryoneMask;
  2932. objPropDB.NextOwnerMask = NextOwnerMask;
  2933. // TODO: More properties are needed in SceneObjectPart!
  2934. objPropDB.OwnershipCost = OwnershipCost;
  2935. objPropDB.SaleType = SaleType;
  2936. objPropDB.SalePrice = SalePrice;
  2937. objPropDB.Category = Category;
  2938. objPropDB.LastOwnerID = LastOwnerID;
  2939. objPropDB.Name = LLUtil.StringToPacketBytes(ObjectName);
  2940. objPropDB.Description = LLUtil.StringToPacketBytes(Description);
  2941. objPropFamilyPack.ObjectData = objPropDB;
  2942. objPropFamilyPack.Header.Zerocoded = true;
  2943. OutPacket(objPropFamilyPack, ThrottleOutPacketType.Task);
  2944. }
  2945. public void SendObjectPropertiesReply(
  2946. UUID ItemID, ulong CreationDate, UUID CreatorUUID, UUID FolderUUID, UUID FromTaskUUID,
  2947. UUID GroupUUID, short InventorySerial, UUID LastOwnerUUID, UUID ObjectUUID,
  2948. UUID OwnerUUID, string TouchTitle, byte[] TextureID, string SitTitle, string ItemName,
  2949. string ItemDescription, uint OwnerMask, uint NextOwnerMask, uint GroupMask, uint EveryoneMask,
  2950. uint BaseMask, byte saleType, int salePrice)
  2951. {
  2952. ObjectPropertiesPacket proper = (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties);
  2953. // TODO: don't create new blocks if recycling an old packet
  2954. proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
  2955. proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
  2956. proper.ObjectData[0].ItemID = ItemID;
  2957. proper.ObjectData[0].CreationDate = CreationDate;
  2958. proper.ObjectData[0].CreatorID = CreatorUUID;
  2959. proper.ObjectData[0].FolderID = FolderUUID;
  2960. proper.ObjectData[0].FromTaskID = FromTaskUUID;
  2961. proper.ObjectData[0].GroupID = GroupUUID;
  2962. proper.ObjectData[0].InventorySerial = InventorySerial;
  2963. proper.ObjectData[0].LastOwnerID = LastOwnerUUID;
  2964. // proper.ObjectData[0].LastOwnerID = UUID.Zero;
  2965. proper.ObjectData[0].ObjectID = ObjectUUID;
  2966. if (OwnerUUID == GroupUUID)
  2967. proper.ObjectData[0].OwnerID = UUID.Zero;
  2968. else
  2969. proper.ObjectData[0].OwnerID = OwnerUUID;
  2970. proper.ObjectData[0].TouchName = LLUtil.StringToPacketBytes(TouchTitle);
  2971. proper.ObjectData[0].TextureID = TextureID;
  2972. proper.ObjectData[0].SitName = LLUtil.StringToPacketBytes(SitTitle);
  2973. proper.ObjectData[0].Name = LLUtil.StringToPacketBytes(ItemName);
  2974. proper.ObjectData[0].Description = LLUtil.StringToPacketBytes(ItemDescription);
  2975. proper.ObjectData[0].OwnerMask = OwnerMask;
  2976. proper.ObjectData[0].NextOwnerMask = NextOwnerMask;
  2977. proper.ObjectData[0].GroupMask = GroupMask;
  2978. proper.ObjectData[0].EveryoneMask = EveryoneMask;
  2979. proper.ObjectData[0].BaseMask = BaseMask;
  2980. // proper.ObjectData[0].AggregatePerms = 53;
  2981. // proper.ObjectData[0].AggregatePermTextures = 0;
  2982. // proper.ObjectData[0].AggregatePermTexturesOwner = 0;
  2983. proper.ObjectData[0].SaleType = saleType;
  2984. proper.ObjectData[0].SalePrice = salePrice;
  2985. proper.Header.Zerocoded = true;
  2986. OutPacket(proper, ThrottleOutPacketType.Task);
  2987. }
  2988. #endregion
  2989. #region Estate Data Sending Methods
  2990. private static bool convertParamStringToBool(byte[] field)
  2991. {
  2992. string s = Utils.BytesToString(field);
  2993. if (s == "1" || s.ToLower() == "y" || s.ToLower() == "yes" || s.ToLower() == "t" || s.ToLower() == "true")
  2994. {
  2995. return true;
  2996. }
  2997. return false;
  2998. }
  2999. public void SendEstateManagersList(UUID invoice, UUID[] EstateManagers, uint estateID)
  3000. {
  3001. EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
  3002. packet.AgentData.TransactionID = UUID.Random();
  3003. packet.AgentData.AgentID = AgentId;
  3004. packet.AgentData.SessionID = SessionId;
  3005. packet.MethodData.Invoice = invoice;
  3006. packet.MethodData.Method = Utils.StringToBytes("setaccess");
  3007. EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[6 + EstateManagers.Length];
  3008. for (int i = 0; i < (6 + EstateManagers.Length); i++)
  3009. {
  3010. returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
  3011. }
  3012. int j = 0;
  3013. returnblock[j].Parameter = Utils.StringToBytes(estateID.ToString()); j++;
  3014. returnblock[j].Parameter = Utils.StringToBytes(((int)Constants.EstateAccessCodex.EstateManagers).ToString()); j++;
  3015. returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
  3016. returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
  3017. returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
  3018. returnblock[j].Parameter = Utils.StringToBytes(EstateManagers.Length.ToString()); j++;
  3019. for (int i = 0; i < EstateManagers.Length; i++)
  3020. {
  3021. returnblock[j].Parameter = EstateManagers[i].GetBytes(); j++;
  3022. }
  3023. packet.ParamList = returnblock;
  3024. packet.Header.Reliable = false;
  3025. OutPacket(packet, ThrottleOutPacketType.Task);
  3026. }
  3027. public void SendBannedUserList(UUID invoice, EstateBan[] bl, uint estateID)
  3028. {
  3029. List<UUID>BannedUsers = new List<UUID>();
  3030. for (int i = 0; i < bl.Length; i++)
  3031. {
  3032. if (bl[i] == null)
  3033. continue;
  3034. if (bl[i].BannedUserID == UUID.Zero)
  3035. continue;
  3036. BannedUsers.Add(bl[i].BannedUserID);
  3037. }
  3038. EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
  3039. packet.AgentData.TransactionID = UUID.Random();
  3040. packet.AgentData.AgentID = AgentId;
  3041. packet.AgentData.SessionID = SessionId;
  3042. packet.MethodData.Invoice = invoice;
  3043. packet.MethodData.Method = Utils.StringToBytes("setaccess");
  3044. EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[6 + BannedUsers.Count];
  3045. for (int i = 0; i < (6 + BannedUsers.Count); i++)
  3046. {
  3047. returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
  3048. }
  3049. int j = 0;
  3050. returnblock[j].Parameter = Utils.StringToBytes(estateID.ToString()); j++;
  3051. returnblock[j].Parameter = Utils.StringToBytes(((int)Constants.EstateAccessCodex.EstateBans).ToString()); j++;
  3052. returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
  3053. returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
  3054. returnblock[j].Parameter = Utils.StringToBytes(BannedUsers.Count.ToString()); j++;
  3055. returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
  3056. foreach (UUID banned in BannedUsers)
  3057. {
  3058. returnblock[j].Parameter = banned.GetBytes(); j++;
  3059. }
  3060. packet.ParamList = returnblock;
  3061. packet.Header.Reliable = false;
  3062. OutPacket(packet, ThrottleOutPacketType.Task);
  3063. }
  3064. public void SendRegionInfoToEstateMenu(RegionInfoForEstateMenuArgs args)
  3065. {
  3066. RegionInfoPacket rinfopack = new RegionInfoPacket();
  3067. RegionInfoPacket.RegionInfoBlock rinfoblk = new RegionInfoPacket.RegionInfoBlock();
  3068. rinfopack.AgentData.AgentID = AgentId;
  3069. rinfopack.AgentData.SessionID = SessionId;
  3070. rinfoblk.BillableFactor = args.billableFactor;
  3071. rinfoblk.EstateID = args.estateID;
  3072. rinfoblk.MaxAgents = args.maxAgents;
  3073. rinfoblk.ObjectBonusFactor = args.objectBonusFactor;
  3074. rinfoblk.ParentEstateID = args.parentEstateID;
  3075. rinfoblk.PricePerMeter = args.pricePerMeter;
  3076. rinfoblk.RedirectGridX = args.redirectGridX;
  3077. rinfoblk.RedirectGridY = args.redirectGridY;
  3078. rinfoblk.RegionFlags = args.regionFlags;
  3079. rinfoblk.SimAccess = args.simAccess;
  3080. rinfoblk.SunHour = args.sunHour;
  3081. rinfoblk.TerrainLowerLimit = args.terrainLowerLimit;
  3082. rinfoblk.TerrainRaiseLimit = args.terrainRaiseLimit;
  3083. rinfoblk.UseEstateSun = args.useEstateSun;
  3084. rinfoblk.WaterHeight = args.waterHeight;
  3085. rinfoblk.SimName = Utils.StringToBytes(args.simName);
  3086. rinfopack.RegionInfo2 = new RegionInfoPacket.RegionInfo2Block();
  3087. rinfopack.RegionInfo2.HardMaxAgents = uint.MaxValue;
  3088. rinfopack.RegionInfo2.HardMaxObjects = uint.MaxValue;
  3089. rinfopack.RegionInfo2.MaxAgents32 = uint.MaxValue;
  3090. rinfopack.RegionInfo2.ProductName = Utils.EmptyBytes;
  3091. rinfopack.RegionInfo2.ProductSKU = Utils.EmptyBytes;
  3092. rinfopack.HasVariableBlocks = true;
  3093. rinfopack.RegionInfo = rinfoblk;
  3094. rinfopack.AgentData = new RegionInfoPacket.AgentDataBlock();
  3095. rinfopack.AgentData.AgentID = AgentId;
  3096. rinfopack.AgentData.SessionID = SessionId;
  3097. OutPacket(rinfopack, ThrottleOutPacketType.Task);
  3098. }
  3099. public void SendEstateCovenantInformation(UUID covenant)
  3100. {
  3101. EstateCovenantReplyPacket einfopack = new EstateCovenantReplyPacket();
  3102. EstateCovenantReplyPacket.DataBlock edata = new EstateCovenantReplyPacket.DataBlock();
  3103. edata.CovenantID = covenant;
  3104. edata.CovenantTimestamp = 0;
  3105. if (m_scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero)
  3106. edata.EstateOwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  3107. else
  3108. edata.EstateOwnerID = m_scene.RegionInfo.MasterAvatarAssignedUUID;
  3109. edata.EstateName = Utils.StringToBytes(m_scene.RegionInfo.EstateSettings.EstateName);
  3110. einfopack.Data = edata;
  3111. OutPacket(einfopack, ThrottleOutPacketType.Task);
  3112. }
  3113. public void SendDetailedEstateData(UUID invoice, string estateName, uint estateID, uint parentEstate, uint estateFlags, uint sunPosition, UUID covenant, string abuseEmail, UUID estateOwner)
  3114. {
  3115. EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
  3116. packet.MethodData.Invoice = invoice;
  3117. packet.AgentData.TransactionID = UUID.Random();
  3118. packet.MethodData.Method = Utils.StringToBytes("estateupdateinfo");
  3119. EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[10];
  3120. for (int i = 0; i < 10; i++)
  3121. {
  3122. returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
  3123. }
  3124. //Sending Estate Settings
  3125. returnblock[0].Parameter = Utils.StringToBytes(estateName);
  3126. // TODO: remove this cruft once MasterAvatar is fully deprecated
  3127. //
  3128. returnblock[1].Parameter = Utils.StringToBytes(estateOwner.ToString());
  3129. returnblock[2].Parameter = Utils.StringToBytes(estateID.ToString());
  3130. returnblock[3].Parameter = Utils.StringToBytes(estateFlags.ToString());
  3131. returnblock[4].Parameter = Utils.StringToBytes(sunPosition.ToString());
  3132. returnblock[5].Parameter = Utils.StringToBytes(parentEstate.ToString());
  3133. returnblock[6].Parameter = Utils.StringToBytes(covenant.ToString());
  3134. returnblock[7].Parameter = Utils.StringToBytes("1160895077"); // what is this?
  3135. returnblock[8].Parameter = Utils.StringToBytes("1"); // what is this?
  3136. returnblock[9].Parameter = Utils.StringToBytes(abuseEmail);
  3137. packet.ParamList = returnblock;
  3138. packet.Header.Reliable = false;
  3139. //m_log.Debug("[ESTATE]: SIM--->" + packet.ToString());
  3140. OutPacket(packet, ThrottleOutPacketType.Task);
  3141. }
  3142. #endregion
  3143. #region Land Data Sending Methods
  3144. public void SendLandParcelOverlay(byte[] data, int sequence_id)
  3145. {
  3146. ParcelOverlayPacket packet = (ParcelOverlayPacket)PacketPool.Instance.GetPacket(PacketType.ParcelOverlay);
  3147. packet.ParcelData.Data = data;
  3148. packet.ParcelData.SequenceID = sequence_id;
  3149. packet.Header.Zerocoded = true;
  3150. OutPacket(packet, ThrottleOutPacketType.Task);
  3151. }
  3152. public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, LandData landData, float simObjectBonusFactor, int parcelObjectCapacity, int simObjectCapacity, uint regionFlags)
  3153. {
  3154. ParcelPropertiesPacket updatePacket = (ParcelPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ParcelProperties);
  3155. // TODO: don't create new blocks if recycling an old packet
  3156. updatePacket.ParcelData.AABBMax = landData.AABBMax;
  3157. updatePacket.ParcelData.AABBMin = landData.AABBMin;
  3158. updatePacket.ParcelData.Area = landData.Area;
  3159. updatePacket.ParcelData.AuctionID = landData.AuctionID;
  3160. updatePacket.ParcelData.AuthBuyerID = landData.AuthBuyerID;
  3161. updatePacket.ParcelData.Bitmap = landData.Bitmap;
  3162. updatePacket.ParcelData.Desc = Utils.StringToBytes(landData.Description);
  3163. updatePacket.ParcelData.Category = (byte)landData.Category;
  3164. updatePacket.ParcelData.ClaimDate = landData.ClaimDate;
  3165. updatePacket.ParcelData.ClaimPrice = landData.ClaimPrice;
  3166. updatePacket.ParcelData.GroupID = landData.GroupID;
  3167. updatePacket.ParcelData.GroupPrims = landData.GroupPrims;
  3168. updatePacket.ParcelData.IsGroupOwned = landData.IsGroupOwned;
  3169. updatePacket.ParcelData.LandingType = landData.LandingType;
  3170. updatePacket.ParcelData.LocalID = landData.LocalID;
  3171. if (landData.Area > 0)
  3172. {
  3173. updatePacket.ParcelData.MaxPrims = parcelObjectCapacity;
  3174. }
  3175. else
  3176. {
  3177. updatePacket.ParcelData.MaxPrims = 0;
  3178. }
  3179. updatePacket.ParcelData.MediaAutoScale = landData.MediaAutoScale;
  3180. updatePacket.ParcelData.MediaID = landData.MediaID;
  3181. updatePacket.ParcelData.MediaURL = LLUtil.StringToPacketBytes(landData.MediaURL);
  3182. updatePacket.ParcelData.MusicURL = LLUtil.StringToPacketBytes(landData.MusicURL);
  3183. updatePacket.ParcelData.Name = Utils.StringToBytes(landData.Name);
  3184. updatePacket.ParcelData.OtherCleanTime = landData.OtherCleanTime;
  3185. updatePacket.ParcelData.OtherCount = 0; //unemplemented
  3186. updatePacket.ParcelData.OtherPrims = landData.OtherPrims;
  3187. updatePacket.ParcelData.OwnerID = landData.OwnerID;
  3188. updatePacket.ParcelData.OwnerPrims = landData.OwnerPrims;
  3189. updatePacket.ParcelData.ParcelFlags = landData.Flags;
  3190. updatePacket.ParcelData.ParcelPrimBonus = simObjectBonusFactor;
  3191. updatePacket.ParcelData.PassHours = landData.PassHours;
  3192. updatePacket.ParcelData.PassPrice = landData.PassPrice;
  3193. updatePacket.ParcelData.PublicCount = 0; //unemplemented
  3194. updatePacket.ParcelData.RegionDenyAnonymous = ((regionFlags & (uint)RegionFlags.DenyAnonymous) >
  3195. 0);
  3196. updatePacket.ParcelData.RegionDenyIdentified = ((regionFlags & (uint)RegionFlags.DenyIdentified) >
  3197. 0);
  3198. updatePacket.ParcelData.RegionDenyTransacted = ((regionFlags & (uint)RegionFlags.DenyTransacted) >
  3199. 0);
  3200. updatePacket.ParcelData.RegionPushOverride = ((regionFlags & (uint)RegionFlags.RestrictPushObject) >
  3201. 0);
  3202. updatePacket.ParcelData.RentPrice = 0;
  3203. updatePacket.ParcelData.RequestResult = request_result;
  3204. updatePacket.ParcelData.SalePrice = landData.SalePrice;
  3205. updatePacket.ParcelData.SelectedPrims = landData.SelectedPrims;
  3206. updatePacket.ParcelData.SelfCount = 0; //unemplemented
  3207. updatePacket.ParcelData.SequenceID = sequence_id;
  3208. if (landData.SimwideArea > 0)
  3209. {
  3210. updatePacket.ParcelData.SimWideMaxPrims = parcelObjectCapacity;
  3211. }
  3212. else
  3213. {
  3214. updatePacket.ParcelData.SimWideMaxPrims = 0;
  3215. }
  3216. updatePacket.ParcelData.SimWideTotalPrims = landData.SimwidePrims;
  3217. updatePacket.ParcelData.SnapSelection = snap_selection;
  3218. updatePacket.ParcelData.SnapshotID = landData.SnapshotID;
  3219. updatePacket.ParcelData.Status = (byte)landData.Status;
  3220. updatePacket.ParcelData.TotalPrims = landData.OwnerPrims + landData.GroupPrims + landData.OtherPrims +
  3221. landData.SelectedPrims;
  3222. updatePacket.ParcelData.UserLocation = landData.UserLocation;
  3223. updatePacket.ParcelData.UserLookAt = landData.UserLookAt;
  3224. updatePacket.Header.Zerocoded = true;
  3225. try
  3226. {
  3227. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  3228. if (eq != null)
  3229. {
  3230. eq.ParcelProperties(updatePacket, this.AgentId);
  3231. }
  3232. }
  3233. catch (Exception ex)
  3234. {
  3235. m_log.Error("Unable to send parcel data via eventqueue - exception: " + ex.ToString());
  3236. m_log.Warn("sending parcel data via UDP");
  3237. OutPacket(updatePacket, ThrottleOutPacketType.Task);
  3238. }
  3239. }
  3240. public void SendLandAccessListData(List<UUID> avatars, uint accessFlag, int localLandID)
  3241. {
  3242. ParcelAccessListReplyPacket replyPacket = (ParcelAccessListReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelAccessListReply);
  3243. replyPacket.Data.AgentID = AgentId;
  3244. replyPacket.Data.Flags = accessFlag;
  3245. replyPacket.Data.LocalID = localLandID;
  3246. replyPacket.Data.SequenceID = 0;
  3247. List<ParcelAccessListReplyPacket.ListBlock> list = new List<ParcelAccessListReplyPacket.ListBlock>();
  3248. foreach (UUID avatar in avatars)
  3249. {
  3250. ParcelAccessListReplyPacket.ListBlock block = new ParcelAccessListReplyPacket.ListBlock();
  3251. block.Flags = accessFlag;
  3252. block.ID = avatar;
  3253. block.Time = 0;
  3254. list.Add(block);
  3255. }
  3256. replyPacket.List = list.ToArray();
  3257. replyPacket.Header.Zerocoded = true;
  3258. OutPacket(replyPacket, ThrottleOutPacketType.Task);
  3259. }
  3260. public void SendForceClientSelectObjects(List<uint> ObjectIDs)
  3261. {
  3262. bool firstCall = true;
  3263. const int MAX_OBJECTS_PER_PACKET = 251;
  3264. ForceObjectSelectPacket pack = (ForceObjectSelectPacket)PacketPool.Instance.GetPacket(PacketType.ForceObjectSelect);
  3265. ForceObjectSelectPacket.DataBlock[] data;
  3266. while (ObjectIDs.Count > 0)
  3267. {
  3268. if (firstCall)
  3269. {
  3270. pack._Header.ResetList = true;
  3271. firstCall = false;
  3272. }
  3273. else
  3274. {
  3275. pack._Header.ResetList = false;
  3276. }
  3277. if (ObjectIDs.Count > MAX_OBJECTS_PER_PACKET)
  3278. {
  3279. data = new ForceObjectSelectPacket.DataBlock[MAX_OBJECTS_PER_PACKET];
  3280. }
  3281. else
  3282. {
  3283. data = new ForceObjectSelectPacket.DataBlock[ObjectIDs.Count];
  3284. }
  3285. int i;
  3286. for (i = 0; i < MAX_OBJECTS_PER_PACKET && ObjectIDs.Count > 0; i++)
  3287. {
  3288. data[i] = new ForceObjectSelectPacket.DataBlock();
  3289. data[i].LocalID = Convert.ToUInt32(ObjectIDs[0]);
  3290. ObjectIDs.RemoveAt(0);
  3291. }
  3292. pack.Data = data;
  3293. pack.Header.Zerocoded = true;
  3294. OutPacket(pack, ThrottleOutPacketType.Task);
  3295. }
  3296. }
  3297. public void SendCameraConstraint(Vector4 ConstraintPlane)
  3298. {
  3299. CameraConstraintPacket cpack = (CameraConstraintPacket)PacketPool.Instance.GetPacket(PacketType.CameraConstraint);
  3300. cpack.CameraCollidePlane = new CameraConstraintPacket.CameraCollidePlaneBlock();
  3301. cpack.CameraCollidePlane.Plane = ConstraintPlane;
  3302. //m_log.DebugFormat("[CLIENTVIEW]: Constraint {0}", ConstraintPlane);
  3303. OutPacket(cpack, ThrottleOutPacketType.Task);
  3304. }
  3305. public void SendLandObjectOwners(LandData land, List<UUID> groups, Dictionary<UUID, int> ownersAndCount)
  3306. {
  3307. int notifyCount = ownersAndCount.Count;
  3308. ParcelObjectOwnersReplyPacket pack = (ParcelObjectOwnersReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelObjectOwnersReply);
  3309. if (notifyCount > 0)
  3310. {
  3311. if (notifyCount > 32)
  3312. {
  3313. m_log.InfoFormat(
  3314. "[LAND]: More than {0} avatars own prims on this parcel. Only sending back details of first {0}"
  3315. + " - a developer might want to investigate whether this is a hard limit", 32);
  3316. notifyCount = 32;
  3317. }
  3318. ParcelObjectOwnersReplyPacket.DataBlock[] dataBlock
  3319. = new ParcelObjectOwnersReplyPacket.DataBlock[notifyCount];
  3320. int num = 0;
  3321. foreach (UUID owner in ownersAndCount.Keys)
  3322. {
  3323. dataBlock[num] = new ParcelObjectOwnersReplyPacket.DataBlock();
  3324. dataBlock[num].Count = ownersAndCount[owner];
  3325. if (land.GroupID == owner || groups.Contains(owner))
  3326. dataBlock[num].IsGroupOwned = true;
  3327. dataBlock[num].OnlineStatus = true; //TODO: fix me later
  3328. dataBlock[num].OwnerID = owner;
  3329. num++;
  3330. if (num >= notifyCount)
  3331. {
  3332. break;
  3333. }
  3334. }
  3335. pack.Data = dataBlock;
  3336. }
  3337. pack.Header.Zerocoded = true;
  3338. this.OutPacket(pack, ThrottleOutPacketType.Task);
  3339. }
  3340. #endregion
  3341. #region Helper Methods
  3342. protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateAvatarImprovedBlock(uint localID, Vector3 pos,
  3343. Vector3 velocity,
  3344. Quaternion rotation)
  3345. {
  3346. byte[] bytes = new byte[60];
  3347. int i = 0;
  3348. ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = PacketPool.GetDataBlock<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>();
  3349. dat.TextureEntry = new byte[0]; // AvatarTemplate.TextureEntry;
  3350. uint ID = localID;
  3351. bytes[i++] = (byte)(ID % 256);
  3352. bytes[i++] = (byte)((ID >> 8) % 256);
  3353. bytes[i++] = (byte)((ID >> 16) % 256);
  3354. bytes[i++] = (byte)((ID >> 24) % 256);
  3355. bytes[i++] = 0;
  3356. bytes[i++] = 1;
  3357. i += 14;
  3358. bytes[i++] = 128;
  3359. bytes[i++] = 63;
  3360. byte[] pb = pos.GetBytes();
  3361. Array.Copy(pb, 0, bytes, i, pb.Length);
  3362. i += 12;
  3363. Vector3 internDirec = new Vector3(velocity.X, velocity.Y, velocity.Z);
  3364. internDirec = internDirec / 128.0f;
  3365. internDirec.X += 1;
  3366. internDirec.Y += 1;
  3367. internDirec.Z += 1;
  3368. ushort InternVelocityX = (ushort)(32768 * internDirec.X);
  3369. ushort InternVelocityY = (ushort)(32768 * internDirec.Y);
  3370. ushort InternVelocityZ = (ushort)(32768 * internDirec.Z);
  3371. ushort ac = 32767;
  3372. bytes[i++] = (byte)(InternVelocityX % 256);
  3373. bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
  3374. bytes[i++] = (byte)(InternVelocityY % 256);
  3375. bytes[i++] = (byte)((InternVelocityY >> 8) % 256);
  3376. bytes[i++] = (byte)(InternVelocityZ % 256);
  3377. bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
  3378. //accel
  3379. bytes[i++] = (byte)(ac % 256);
  3380. bytes[i++] = (byte)((ac >> 8) % 256);
  3381. bytes[i++] = (byte)(ac % 256);
  3382. bytes[i++] = (byte)((ac >> 8) % 256);
  3383. bytes[i++] = (byte)(ac % 256);
  3384. bytes[i++] = (byte)((ac >> 8) % 256);
  3385. //rotation
  3386. ushort rw, rx, ry, rz;
  3387. rw = (ushort)(32768 * (rotation.W + 1));
  3388. rx = (ushort)(32768 * (rotation.X + 1));
  3389. ry = (ushort)(32768 * (rotation.Y + 1));
  3390. rz = (ushort)(32768 * (rotation.Z + 1));
  3391. //rot
  3392. bytes[i++] = (byte)(rx % 256);
  3393. bytes[i++] = (byte)((rx >> 8) % 256);
  3394. bytes[i++] = (byte)(ry % 256);
  3395. bytes[i++] = (byte)((ry >> 8) % 256);
  3396. bytes[i++] = (byte)(rz % 256);
  3397. bytes[i++] = (byte)((rz >> 8) % 256);
  3398. bytes[i++] = (byte)(rw % 256);
  3399. bytes[i++] = (byte)((rw >> 8) % 256);
  3400. //rotation vel
  3401. bytes[i++] = (byte)(ac % 256);
  3402. bytes[i++] = (byte)((ac >> 8) % 256);
  3403. bytes[i++] = (byte)(ac % 256);
  3404. bytes[i++] = (byte)((ac >> 8) % 256);
  3405. bytes[i++] = (byte)(ac % 256);
  3406. bytes[i++] = (byte)((ac >> 8) % 256);
  3407. dat.Data = bytes;
  3408. return (dat);
  3409. }
  3410. /// <summary>
  3411. ///
  3412. /// </summary>
  3413. /// <param name="localID"></param>
  3414. /// <param name="position"></param>
  3415. /// <param name="rotation"></param>
  3416. /// <returns></returns>
  3417. protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreatePrimImprovedBlock(uint localID,
  3418. Vector3 position,
  3419. Quaternion rotation,
  3420. Vector3 velocity,
  3421. Vector3 rotationalvelocity,
  3422. byte state)
  3423. {
  3424. uint ID = localID;
  3425. byte[] bytes = new byte[60];
  3426. int i = 0;
  3427. ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = PacketPool.GetDataBlock<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>();
  3428. dat.TextureEntry = new byte[0];
  3429. bytes[i++] = (byte)(ID % 256);
  3430. bytes[i++] = (byte)((ID >> 8) % 256);
  3431. bytes[i++] = (byte)((ID >> 16) % 256);
  3432. bytes[i++] = (byte)((ID >> 24) % 256);
  3433. bytes[i++] = (byte)(((state & 0xf0) >> 4) | ((state & 0x0f) << 4));
  3434. bytes[i++] = 0;
  3435. byte[] pb = position.GetBytes();
  3436. Array.Copy(pb, 0, bytes, i, pb.Length);
  3437. i += 12;
  3438. ushort ac = 32767;
  3439. ushort velx, vely, velz;
  3440. Vector3 vel = new Vector3(velocity.X, velocity.Y, velocity.Z);
  3441. vel = vel / 128.0f;
  3442. vel.X += 1;
  3443. vel.Y += 1;
  3444. vel.Z += 1;
  3445. //vel
  3446. velx = (ushort)(32768 * (vel.X));
  3447. vely = (ushort)(32768 * (vel.Y));
  3448. velz = (ushort)(32768 * (vel.Z));
  3449. bytes[i++] = (byte)(velx % 256);
  3450. bytes[i++] = (byte)((velx >> 8) % 256);
  3451. bytes[i++] = (byte)(vely % 256);
  3452. bytes[i++] = (byte)((vely >> 8) % 256);
  3453. bytes[i++] = (byte)(velz % 256);
  3454. bytes[i++] = (byte)((velz >> 8) % 256);
  3455. //accel
  3456. bytes[i++] = (byte)(ac % 256);
  3457. bytes[i++] = (byte)((ac >> 8) % 256);
  3458. bytes[i++] = (byte)(ac % 256);
  3459. bytes[i++] = (byte)((ac >> 8) % 256);
  3460. bytes[i++] = (byte)(ac % 256);
  3461. bytes[i++] = (byte)((ac >> 8) % 256);
  3462. ushort rw, rx, ry, rz;
  3463. rw = (ushort)(32768 * (rotation.W + 1));
  3464. rx = (ushort)(32768 * (rotation.X + 1));
  3465. ry = (ushort)(32768 * (rotation.Y + 1));
  3466. rz = (ushort)(32768 * (rotation.Z + 1));
  3467. //rot
  3468. bytes[i++] = (byte)(rx % 256);
  3469. bytes[i++] = (byte)((rx >> 8) % 256);
  3470. bytes[i++] = (byte)(ry % 256);
  3471. bytes[i++] = (byte)((ry >> 8) % 256);
  3472. bytes[i++] = (byte)(rz % 256);
  3473. bytes[i++] = (byte)((rz >> 8) % 256);
  3474. bytes[i++] = (byte)(rw % 256);
  3475. bytes[i++] = (byte)((rw >> 8) % 256);
  3476. //rotation vel
  3477. Vector3 rvel = new Vector3(rotationalvelocity.X, rotationalvelocity.Y, rotationalvelocity.Z);
  3478. rvel = rvel / 128.0f;
  3479. rvel.X += 1;
  3480. rvel.Y += 1;
  3481. rvel.Z += 1;
  3482. //vel
  3483. ushort rvelx = (ushort)(32768 * (rvel.X));
  3484. ushort rvely = (ushort)(32768 * (rvel.Y));
  3485. ushort rvelz = (ushort)(32768 * (rvel.Z));
  3486. bytes[i++] = (byte)(rvelx % 256);
  3487. bytes[i++] = (byte)((rvelx >> 8) % 256);
  3488. bytes[i++] = (byte)(rvely % 256);
  3489. bytes[i++] = (byte)((rvely >> 8) % 256);
  3490. bytes[i++] = (byte)(rvelz % 256);
  3491. bytes[i++] = (byte)((rvelz >> 8) % 256);
  3492. dat.Data = bytes;
  3493. return dat;
  3494. }
  3495. /// <summary>
  3496. /// Create the ObjectDataBlock for a ObjectUpdatePacket (for a Primitive)
  3497. /// </summary>
  3498. /// <param name="primData"></param>
  3499. /// <returns></returns>
  3500. protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(PrimitiveBaseShape primShape, uint flags)
  3501. {
  3502. ObjectUpdatePacket.ObjectDataBlock objupdate = PacketPool.GetDataBlock<ObjectUpdatePacket.ObjectDataBlock>();
  3503. SetDefaultPrimPacketValues(objupdate);
  3504. objupdate.UpdateFlags = flags;
  3505. SetPrimPacketShapeData(objupdate, primShape);
  3506. if ((primShape.PCode == (byte)PCode.NewTree) || (primShape.PCode == (byte)PCode.Tree) || (primShape.PCode == (byte)PCode.Grass))
  3507. {
  3508. objupdate.Data = new byte[1];
  3509. objupdate.Data[0] = primShape.State;
  3510. }
  3511. return objupdate;
  3512. }
  3513. protected void SetPrimPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData, PrimitiveBaseShape primData)
  3514. {
  3515. objectData.TextureEntry = primData.TextureEntry;
  3516. objectData.PCode = primData.PCode;
  3517. objectData.State = primData.State;
  3518. objectData.PathBegin = primData.PathBegin;
  3519. objectData.PathEnd = primData.PathEnd;
  3520. objectData.PathScaleX = primData.PathScaleX;
  3521. objectData.PathScaleY = primData.PathScaleY;
  3522. objectData.PathShearX = primData.PathShearX;
  3523. objectData.PathShearY = primData.PathShearY;
  3524. objectData.PathSkew = primData.PathSkew;
  3525. objectData.ProfileBegin = primData.ProfileBegin;
  3526. objectData.ProfileEnd = primData.ProfileEnd;
  3527. objectData.Scale = primData.Scale;
  3528. objectData.PathCurve = primData.PathCurve;
  3529. objectData.ProfileCurve = primData.ProfileCurve;
  3530. objectData.ProfileHollow = primData.ProfileHollow;
  3531. objectData.PathRadiusOffset = primData.PathRadiusOffset;
  3532. objectData.PathRevolutions = primData.PathRevolutions;
  3533. objectData.PathTaperX = primData.PathTaperX;
  3534. objectData.PathTaperY = primData.PathTaperY;
  3535. objectData.PathTwist = primData.PathTwist;
  3536. objectData.PathTwistBegin = primData.PathTwistBegin;
  3537. objectData.ExtraParams = primData.ExtraParams;
  3538. }
  3539. /// <summary>
  3540. /// Set some default values in a ObjectUpdatePacket
  3541. /// </summary>
  3542. /// <param name="objdata"></param>
  3543. protected void SetDefaultPrimPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
  3544. {
  3545. objdata.PSBlock = new byte[0];
  3546. objdata.ExtraParams = new byte[1];
  3547. objdata.MediaURL = new byte[0];
  3548. objdata.NameValue = new byte[0];
  3549. objdata.Text = new byte[0];
  3550. objdata.TextColor = new byte[4];
  3551. objdata.JointAxisOrAnchor = new Vector3(0, 0, 0);
  3552. objdata.JointPivot = new Vector3(0, 0, 0);
  3553. objdata.Material = 3;
  3554. objdata.TextureAnim = new byte[0];
  3555. objdata.Sound = UUID.Zero;
  3556. objdata.State = 0;
  3557. objdata.Data = new byte[0];
  3558. objdata.ObjectData = new byte[60];
  3559. objdata.ObjectData[46] = 128;
  3560. objdata.ObjectData[47] = 63;
  3561. }
  3562. /// <summary>
  3563. ///
  3564. /// </summary>
  3565. /// <returns></returns>
  3566. public ObjectUpdatePacket.ObjectDataBlock CreateDefaultAvatarPacket(byte[] textureEntry)
  3567. {
  3568. ObjectUpdatePacket.ObjectDataBlock objdata = PacketPool.GetDataBlock<ObjectUpdatePacket.ObjectDataBlock>();
  3569. // new OpenMetaverse.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
  3570. SetDefaultAvatarPacketValues(ref objdata);
  3571. objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
  3572. objdata.PathCurve = 16;
  3573. objdata.ProfileCurve = 1;
  3574. objdata.PathScaleX = 100;
  3575. objdata.PathScaleY = 100;
  3576. objdata.ParentID = 0;
  3577. objdata.OwnerID = UUID.Zero;
  3578. objdata.Scale = new Vector3(1, 1, 1);
  3579. objdata.PCode = (byte)PCode.Avatar;
  3580. if (textureEntry != null)
  3581. {
  3582. objdata.TextureEntry = textureEntry;
  3583. }
  3584. Vector3 pos = new Vector3(objdata.ObjectData, 16);
  3585. pos.X = 100f;
  3586. objdata.ID = 8880000;
  3587. objdata.NameValue = Utils.StringToBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User ");
  3588. //Vector3 pos2 = new Vector3(100f, 100f, 23f);
  3589. //objdata.FullID=user.AgentId;
  3590. byte[] pb = pos.GetBytes();
  3591. Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
  3592. return objdata;
  3593. }
  3594. /// <summary>
  3595. ///
  3596. /// </summary>
  3597. /// <param name="objdata"></param>
  3598. protected void SetDefaultAvatarPacketValues(ref ObjectUpdatePacket.ObjectDataBlock objdata)
  3599. {
  3600. objdata.PSBlock = new byte[0];
  3601. objdata.ExtraParams = new byte[1];
  3602. objdata.MediaURL = new byte[0];
  3603. objdata.NameValue = new byte[0];
  3604. objdata.Text = new byte[0];
  3605. objdata.TextColor = new byte[4];
  3606. objdata.JointAxisOrAnchor = new Vector3(0, 0, 0);
  3607. objdata.JointPivot = new Vector3(0, 0, 0);
  3608. objdata.Material = 4;
  3609. objdata.TextureAnim = new byte[0];
  3610. objdata.Sound = UUID.Zero;
  3611. Primitive.TextureEntry ntex = new Primitive.TextureEntry(new UUID("00000000-0000-0000-5005-000000000005"));
  3612. objdata.TextureEntry = ntex.GetBytes();
  3613. objdata.State = 0;
  3614. objdata.Data = new byte[0];
  3615. objdata.ObjectData = new byte[76];
  3616. objdata.ObjectData[15] = 128;
  3617. objdata.ObjectData[16] = 63;
  3618. objdata.ObjectData[56] = 128;
  3619. objdata.ObjectData[61] = 102;
  3620. objdata.ObjectData[62] = 40;
  3621. objdata.ObjectData[63] = 61;
  3622. objdata.ObjectData[64] = 189;
  3623. }
  3624. public void SendNameReply(UUID profileId, string firstname, string lastname)
  3625. {
  3626. UUIDNameReplyPacket packet = (UUIDNameReplyPacket)PacketPool.Instance.GetPacket(PacketType.UUIDNameReply);
  3627. // TODO: don't create new blocks if recycling an old packet
  3628. packet.UUIDNameBlock = new UUIDNameReplyPacket.UUIDNameBlockBlock[1];
  3629. packet.UUIDNameBlock[0] = new UUIDNameReplyPacket.UUIDNameBlockBlock();
  3630. packet.UUIDNameBlock[0].ID = profileId;
  3631. packet.UUIDNameBlock[0].FirstName = Utils.StringToBytes(firstname);
  3632. packet.UUIDNameBlock[0].LastName = Utils.StringToBytes(lastname);
  3633. OutPacket(packet, ThrottleOutPacketType.Task);
  3634. }
  3635. #endregion
  3636. /// <summary>
  3637. /// This is a different way of processing packets then ProcessInPacket
  3638. /// </summary>
  3639. protected virtual void RegisterLocalPacketHandlers()
  3640. {
  3641. AddLocalPacketHandler(PacketType.LogoutRequest, Logout);
  3642. AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect);
  3643. AddLocalPacketHandler(PacketType.AgentCachedTexture, AgentTextureCached);
  3644. AddLocalPacketHandler(PacketType.MultipleObjectUpdate, MultipleObjUpdate);
  3645. AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest);
  3646. AddLocalPacketHandler(PacketType.ParcelBuy, HandleParcelBuyRequest);
  3647. AddLocalPacketHandler(PacketType.UUIDGroupNameRequest, HandleUUIDGroupNameRequest);
  3648. AddLocalPacketHandler(PacketType.ObjectGroup, HandleObjectGroupRequest);
  3649. AddLocalPacketHandler(PacketType.GenericMessage, HandleGenericMessage);
  3650. }
  3651. private bool HandleMoneyTransferRequest(IClientAPI sender, Packet Pack)
  3652. {
  3653. MoneyTransferRequestPacket money = (MoneyTransferRequestPacket) Pack;
  3654. // validate the agent owns the agentID and sessionID
  3655. if (money.MoneyData.SourceID == sender.AgentId && money.AgentData.AgentID == sender.AgentId &&
  3656. money.AgentData.SessionID == sender.SessionId)
  3657. {
  3658. handlerMoneyTransferRequest = OnMoneyTransferRequest;
  3659. if (handlerMoneyTransferRequest != null)
  3660. {
  3661. handlerMoneyTransferRequest(money.MoneyData.SourceID, money.MoneyData.DestID,
  3662. money.MoneyData.Amount, money.MoneyData.TransactionType,
  3663. Util.FieldToString(money.MoneyData.Description));
  3664. }
  3665. return true;
  3666. }
  3667. return false;
  3668. }
  3669. private bool HandleParcelBuyRequest(IClientAPI sender, Packet Pack)
  3670. {
  3671. ParcelBuyPacket parcel = (ParcelBuyPacket) Pack;
  3672. if (parcel.AgentData.AgentID == AgentId && parcel.AgentData.SessionID == SessionId)
  3673. {
  3674. handlerParcelBuy = OnParcelBuy;
  3675. if (handlerParcelBuy != null)
  3676. {
  3677. handlerParcelBuy(parcel.AgentData.AgentID, parcel.Data.GroupID, parcel.Data.Final,
  3678. parcel.Data.IsGroupOwned,
  3679. parcel.Data.RemoveContribution, parcel.Data.LocalID, parcel.ParcelData.Area,
  3680. parcel.ParcelData.Price,
  3681. false);
  3682. }
  3683. return true;
  3684. }
  3685. return false;
  3686. }
  3687. private bool HandleUUIDGroupNameRequest(IClientAPI sender, Packet Pack)
  3688. {
  3689. UUIDGroupNameRequestPacket upack = (UUIDGroupNameRequestPacket)Pack;
  3690. for (int i = 0; i < upack.UUIDNameBlock.Length; i++)
  3691. {
  3692. handlerUUIDGroupNameRequest = OnUUIDGroupNameRequest;
  3693. if (handlerUUIDGroupNameRequest != null)
  3694. {
  3695. handlerUUIDGroupNameRequest(upack.UUIDNameBlock[i].ID, this);
  3696. }
  3697. }
  3698. return true;
  3699. }
  3700. public bool HandleGenericMessage(IClientAPI sender, Packet pack)
  3701. {
  3702. GenericMessagePacket gmpack = (GenericMessagePacket) pack;
  3703. if (m_genericPacketHandlers.Count == 0) return false;
  3704. if (gmpack.AgentData.SessionID != SessionId) return false;
  3705. handlerGenericMessage = null;
  3706. string method = Util.FieldToString(gmpack.MethodData.Method).ToLower().Trim();
  3707. if (m_genericPacketHandlers.TryGetValue(method, out handlerGenericMessage))
  3708. {
  3709. List<string> msg = new List<string>();
  3710. List<byte[]> msgBytes = new List<byte[]>();
  3711. if (handlerGenericMessage != null)
  3712. {
  3713. foreach (GenericMessagePacket.ParamListBlock block in gmpack.ParamList)
  3714. {
  3715. msg.Add(Util.FieldToString(block.Parameter));
  3716. msgBytes.Add(block.Parameter);
  3717. }
  3718. try
  3719. {
  3720. if (OnBinaryGenericMessage != null)
  3721. {
  3722. OnBinaryGenericMessage(this, method, msgBytes.ToArray());
  3723. }
  3724. handlerGenericMessage(sender, method, msg);
  3725. return true;
  3726. }
  3727. catch (Exception e)
  3728. {
  3729. m_log.Error("[GENERICMESSAGE] " + e);
  3730. }
  3731. }
  3732. }
  3733. m_log.Error("[GENERICMESSAGE] Not handling GenericMessage with method-type of: " + method);
  3734. return false;
  3735. }
  3736. public bool HandleObjectGroupRequest(IClientAPI sender, Packet Pack)
  3737. {
  3738. ObjectGroupPacket ogpack = (ObjectGroupPacket)Pack;
  3739. if (ogpack.AgentData.SessionID != SessionId) return false;
  3740. handlerObjectGroupRequest = OnObjectGroupRequest;
  3741. if (handlerObjectGroupRequest != null)
  3742. {
  3743. for (int i = 0; i < ogpack.ObjectData.Length; i++)
  3744. {
  3745. handlerObjectGroupRequest(this, ogpack.AgentData.GroupID, ogpack.ObjectData[i].ObjectLocalID, UUID.Zero);
  3746. }
  3747. }
  3748. return true;
  3749. }
  3750. private bool HandleViewerEffect(IClientAPI sender, Packet Pack)
  3751. {
  3752. ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
  3753. if (viewer.AgentData.SessionID != SessionId) return false;
  3754. handlerViewerEffect = OnViewerEffect;
  3755. if (handlerViewerEffect != null)
  3756. {
  3757. int length = viewer.Effect.Length;
  3758. List<ViewerEffectEventHandlerArg> args = new List<ViewerEffectEventHandlerArg>(length);
  3759. for (int i = 0; i < length; i++)
  3760. {
  3761. //copy the effects block arguments into the event handler arg.
  3762. ViewerEffectEventHandlerArg argument = new ViewerEffectEventHandlerArg();
  3763. argument.AgentID = viewer.Effect[i].AgentID;
  3764. argument.Color = viewer.Effect[i].Color;
  3765. argument.Duration = viewer.Effect[i].Duration;
  3766. argument.ID = viewer.Effect[i].ID;
  3767. argument.Type = viewer.Effect[i].Type;
  3768. argument.TypeData = viewer.Effect[i].TypeData;
  3769. args.Add(argument);
  3770. }
  3771. handlerViewerEffect(sender, args);
  3772. }
  3773. return true;
  3774. }
  3775. public void SendScriptQuestion(UUID taskID, string taskName, string ownerName, UUID itemID, int question)
  3776. {
  3777. ScriptQuestionPacket scriptQuestion = (ScriptQuestionPacket)PacketPool.Instance.GetPacket(PacketType.ScriptQuestion);
  3778. scriptQuestion.Data = new ScriptQuestionPacket.DataBlock();
  3779. // TODO: don't create new blocks if recycling an old packet
  3780. scriptQuestion.Data.TaskID = taskID;
  3781. scriptQuestion.Data.ItemID = itemID;
  3782. scriptQuestion.Data.Questions = question;
  3783. scriptQuestion.Data.ObjectName = Utils.StringToBytes(taskName);
  3784. scriptQuestion.Data.ObjectOwner = Utils.StringToBytes(ownerName);
  3785. OutPacket(scriptQuestion, ThrottleOutPacketType.Task);
  3786. }
  3787. private void InitDefaultAnimations()
  3788. {
  3789. using (XmlTextReader reader = new XmlTextReader("data/avataranimations.xml"))
  3790. {
  3791. XmlDocument doc = new XmlDocument();
  3792. doc.Load(reader);
  3793. if (doc.DocumentElement != null)
  3794. foreach (XmlNode nod in doc.DocumentElement.ChildNodes)
  3795. {
  3796. if (nod.Attributes["name"] != null)
  3797. {
  3798. string name = nod.Attributes["name"].Value.ToLower();
  3799. string id = nod.InnerText;
  3800. m_defaultAnimations.Add(name, (UUID)id);
  3801. }
  3802. }
  3803. }
  3804. }
  3805. public UUID GetDefaultAnimation(string name)
  3806. {
  3807. if (m_defaultAnimations.ContainsKey(name))
  3808. return m_defaultAnimations[name];
  3809. return UUID.Zero;
  3810. }
  3811. /// <summary>
  3812. /// Handler called when we receive a logout packet.
  3813. /// </summary>
  3814. /// <param name="client"></param>
  3815. /// <param name="packet"></param>
  3816. /// <returns></returns>
  3817. protected virtual bool Logout(IClientAPI client, Packet packet)
  3818. {
  3819. if (packet.Type == PacketType.LogoutRequest)
  3820. {
  3821. if (((LogoutRequestPacket)packet).AgentData.SessionID != SessionId) return false;
  3822. }
  3823. return Logout(client);
  3824. }
  3825. /// <summary>
  3826. ///
  3827. /// </summary>
  3828. /// <param name="client"></param>
  3829. /// <returns></returns>
  3830. protected virtual bool Logout(IClientAPI client)
  3831. {
  3832. m_log.InfoFormat("[CLIENT]: Got a logout request for {0} in {1}", Name, Scene.RegionInfo.RegionName);
  3833. handlerLogout = OnLogout;
  3834. if (handlerLogout != null)
  3835. {
  3836. handlerLogout(client);
  3837. }
  3838. return true;
  3839. }
  3840. /// <summary>
  3841. /// Send a response back to a client when it asks the asset server (via the region server) if it has
  3842. /// its appearance texture cached.
  3843. ///
  3844. /// At the moment, we always reply that there is no cached texture.
  3845. /// </summary>
  3846. /// <param name="simclient"></param>
  3847. /// <param name="packet"></param>
  3848. /// <returns></returns>
  3849. protected bool AgentTextureCached(IClientAPI simclient, Packet packet)
  3850. {
  3851. //m_log.Debug("texture cached: " + packet.ToString());
  3852. AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet;
  3853. AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
  3854. if (cachedtex.AgentData.SessionID != SessionId) return false;
  3855. // TODO: don't create new blocks if recycling an old packet
  3856. cachedresp.AgentData.AgentID = AgentId;
  3857. cachedresp.AgentData.SessionID = m_sessionId;
  3858. cachedresp.AgentData.SerialNum = m_cachedTextureSerial;
  3859. m_cachedTextureSerial++;
  3860. cachedresp.WearableData =
  3861. new AgentCachedTextureResponsePacket.WearableDataBlock[cachedtex.WearableData.Length];
  3862. for (int i = 0; i < cachedtex.WearableData.Length; i++)
  3863. {
  3864. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  3865. cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
  3866. cachedresp.WearableData[i].TextureID = UUID.Zero;
  3867. cachedresp.WearableData[i].HostName = new byte[0];
  3868. }
  3869. cachedresp.Header.Zerocoded = true;
  3870. OutPacket(cachedresp, ThrottleOutPacketType.Task);
  3871. return true;
  3872. }
  3873. protected bool MultipleObjUpdate(IClientAPI simClient, Packet packet)
  3874. {
  3875. MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
  3876. if (multipleupdate.AgentData.SessionID != SessionId) return false;
  3877. // m_log.Debug("new multi update packet " + multipleupdate.ToString());
  3878. Scene tScene = (Scene)m_scene;
  3879. for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
  3880. {
  3881. MultipleObjectUpdatePacket.ObjectDataBlock block = multipleupdate.ObjectData[i];
  3882. // Can't act on Null Data
  3883. if (block.Data != null)
  3884. {
  3885. uint localId = block.ObjectLocalID;
  3886. SceneObjectPart part = tScene.GetSceneObjectPart(localId);
  3887. if (part == null)
  3888. {
  3889. // It's a ghost! tell the client to delete it from view.
  3890. simClient.SendKillObject(Scene.RegionInfo.RegionHandle,
  3891. localId);
  3892. }
  3893. else
  3894. {
  3895. // UUID partId = part.UUID;
  3896. UpdatePrimGroupRotation handlerUpdatePrimGroupRotation;
  3897. switch (block.Type)
  3898. {
  3899. case 1:
  3900. Vector3 pos1 = new Vector3(block.Data, 0);
  3901. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  3902. if (handlerUpdatePrimSinglePosition != null)
  3903. {
  3904. // m_log.Debug("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
  3905. handlerUpdatePrimSinglePosition(localId, pos1, this);
  3906. }
  3907. break;
  3908. case 2:
  3909. Quaternion rot1 = new Quaternion(block.Data, 0, true);
  3910. handlerUpdatePrimSingleRotation = OnUpdatePrimSingleRotation;
  3911. if (handlerUpdatePrimSingleRotation != null)
  3912. {
  3913. // m_log.Info("new tab rotation is " + rot1.X + " , " + rot1.Y + " , " + rot1.Z + " , " + rot1.W);
  3914. handlerUpdatePrimSingleRotation(localId, rot1, this);
  3915. }
  3916. break;
  3917. case 3:
  3918. Vector3 rotPos = new Vector3(block.Data, 0);
  3919. Quaternion rot2 = new Quaternion(block.Data, 12, true);
  3920. handlerUpdatePrimSingleRotationPosition = OnUpdatePrimSingleRotationPosition;
  3921. if (handlerUpdatePrimSingleRotationPosition != null)
  3922. {
  3923. // m_log.Debug("new mouse rotation position is " + rotPos.X + " , " + rotPos.Y + " , " + rotPos.Z);
  3924. // m_log.Info("new mouse rotation is " + rot2.X + " , " + rot2.Y + " , " + rot2.Z + " , " + rot2.W);
  3925. handlerUpdatePrimSingleRotationPosition(localId, rot2, rotPos, this);
  3926. }
  3927. break;
  3928. case 4:
  3929. case 20:
  3930. Vector3 scale4 = new Vector3(block.Data, 0);
  3931. handlerUpdatePrimScale = OnUpdatePrimScale;
  3932. if (handlerUpdatePrimScale != null)
  3933. {
  3934. // m_log.Debug("new scale is " + scale4.X + " , " + scale4.Y + " , " + scale4.Z);
  3935. handlerUpdatePrimScale(localId, scale4, this);
  3936. }
  3937. break;
  3938. case 5:
  3939. Vector3 scale1 = new Vector3(block.Data, 12);
  3940. Vector3 pos11 = new Vector3(block.Data, 0);
  3941. handlerUpdatePrimScale = OnUpdatePrimScale;
  3942. if (handlerUpdatePrimScale != null)
  3943. {
  3944. // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  3945. handlerUpdatePrimScale(localId, scale1, this);
  3946. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  3947. if (handlerUpdatePrimSinglePosition != null)
  3948. {
  3949. handlerUpdatePrimSinglePosition(localId, pos11, this);
  3950. }
  3951. }
  3952. break;
  3953. case 9:
  3954. Vector3 pos2 = new Vector3(block.Data, 0);
  3955. handlerUpdateVector = OnUpdatePrimGroupPosition;
  3956. if (handlerUpdateVector != null)
  3957. {
  3958. handlerUpdateVector(localId, pos2, this);
  3959. }
  3960. break;
  3961. case 10:
  3962. Quaternion rot3 = new Quaternion(block.Data, 0, true);
  3963. handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
  3964. if (handlerUpdatePrimRotation != null)
  3965. {
  3966. // Console.WriteLine("new rotation is " + rot3.X + " , " + rot3.Y + " , " + rot3.Z + " , " + rot3.W);
  3967. handlerUpdatePrimRotation(localId, rot3, this);
  3968. }
  3969. break;
  3970. case 11:
  3971. Vector3 pos3 = new Vector3(block.Data, 0);
  3972. Quaternion rot4 = new Quaternion(block.Data, 12, true);
  3973. handlerUpdatePrimGroupRotation = OnUpdatePrimGroupMouseRotation;
  3974. if (handlerUpdatePrimGroupRotation != null)
  3975. {
  3976. // m_log.Debug("new rotation position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
  3977. // m_log.Debug("new group mouse rotation is " + rot4.X + " , " + rot4.Y + " , " + rot4.Z + " , " + rot4.W);
  3978. handlerUpdatePrimGroupRotation(localId, pos3, rot4, this);
  3979. }
  3980. break;
  3981. case 12:
  3982. case 28:
  3983. Vector3 scale7 = new Vector3(block.Data, 0);
  3984. handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale;
  3985. if (handlerUpdatePrimGroupScale != null)
  3986. {
  3987. // m_log.Debug("new scale is " + scale7.X + " , " + scale7.Y + " , " + scale7.Z);
  3988. handlerUpdatePrimGroupScale(localId, scale7, this);
  3989. }
  3990. break;
  3991. case 13:
  3992. Vector3 scale2 = new Vector3(block.Data, 12);
  3993. Vector3 pos4 = new Vector3(block.Data, 0);
  3994. handlerUpdatePrimScale = OnUpdatePrimScale;
  3995. if (handlerUpdatePrimScale != null)
  3996. {
  3997. //m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  3998. handlerUpdatePrimScale(localId, scale2, this);
  3999. // Change the position based on scale (for bug number 246)
  4000. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  4001. // m_log.Debug("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
  4002. if (handlerUpdatePrimSinglePosition != null)
  4003. {
  4004. handlerUpdatePrimSinglePosition(localId, pos4, this);
  4005. }
  4006. }
  4007. break;
  4008. case 29:
  4009. Vector3 scale5 = new Vector3(block.Data, 12);
  4010. Vector3 pos5 = new Vector3(block.Data, 0);
  4011. handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale;
  4012. if (handlerUpdatePrimGroupScale != null)
  4013. {
  4014. // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  4015. handlerUpdatePrimGroupScale(localId, scale5, this);
  4016. handlerUpdateVector = OnUpdatePrimGroupPosition;
  4017. if (handlerUpdateVector != null)
  4018. {
  4019. handlerUpdateVector(localId, pos5, this);
  4020. }
  4021. }
  4022. break;
  4023. case 21:
  4024. Vector3 scale6 = new Vector3(block.Data, 12);
  4025. Vector3 pos6 = new Vector3(block.Data, 0);
  4026. handlerUpdatePrimScale = OnUpdatePrimScale;
  4027. if (handlerUpdatePrimScale != null)
  4028. {
  4029. // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  4030. handlerUpdatePrimScale(localId, scale6, this);
  4031. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  4032. if (handlerUpdatePrimSinglePosition != null)
  4033. {
  4034. handlerUpdatePrimSinglePosition(localId, pos6, this);
  4035. }
  4036. }
  4037. break;
  4038. default:
  4039. m_log.Debug("[CLIENT] MultipleObjUpdate recieved an unknown packet type: " + (block.Type));
  4040. break;
  4041. }
  4042. }
  4043. }
  4044. }
  4045. return true;
  4046. }
  4047. public void RequestMapLayer()
  4048. {
  4049. //should be getting the map layer from the grid server
  4050. //send a layer covering the 800,800 - 1200,1200 area (should be covering the requested area)
  4051. MapLayerReplyPacket mapReply = (MapLayerReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapLayerReply);
  4052. // TODO: don't create new blocks if recycling an old packet
  4053. mapReply.AgentData.AgentID = AgentId;
  4054. mapReply.AgentData.Flags = 0;
  4055. mapReply.LayerData = new MapLayerReplyPacket.LayerDataBlock[1];
  4056. mapReply.LayerData[0] = new MapLayerReplyPacket.LayerDataBlock();
  4057. mapReply.LayerData[0].Bottom = 0;
  4058. mapReply.LayerData[0].Left = 0;
  4059. mapReply.LayerData[0].Top = 30000;
  4060. mapReply.LayerData[0].Right = 30000;
  4061. mapReply.LayerData[0].ImageID = new UUID("00000000-0000-1111-9999-000000000006");
  4062. mapReply.Header.Zerocoded = true;
  4063. OutPacket(mapReply, ThrottleOutPacketType.Land);
  4064. }
  4065. public void RequestMapBlocksX(int minX, int minY, int maxX, int maxY)
  4066. {
  4067. /*
  4068. IList simMapProfiles = m_gridServer.RequestMapBlocks(minX, minY, maxX, maxY);
  4069. MapBlockReplyPacket mbReply = new MapBlockReplyPacket();
  4070. mbReply.AgentData.AgentId = AgentId;
  4071. int len;
  4072. if (simMapProfiles == null)
  4073. len = 0;
  4074. else
  4075. len = simMapProfiles.Count;
  4076. mbReply.Data = new MapBlockReplyPacket.DataBlock[len];
  4077. int iii;
  4078. for (iii = 0; iii < len; iii++)
  4079. {
  4080. Hashtable mp = (Hashtable)simMapProfiles[iii];
  4081. mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock();
  4082. mbReply.Data[iii].Name = System.Text.Encoding.UTF8.GetBytes((string)mp["name"]);
  4083. mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]);
  4084. mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]);
  4085. mbReply.Data[iii].MapImageID = new UUID((string)mp["map-image-id"]);
  4086. mbReply.Data[iii].RegionFlags = System.Convert.ToUInt32(mp["region-flags"]);
  4087. mbReply.Data[iii].WaterHeight = System.Convert.ToByte(mp["water-height"]);
  4088. mbReply.Data[iii].X = System.Convert.ToUInt16(mp["x"]);
  4089. mbReply.Data[iii].Y = System.Convert.ToUInt16(mp["y"]);
  4090. }
  4091. this.OutPacket(mbReply, ThrottleOutPacketType.Land);
  4092. */
  4093. }
  4094. /// <summary>
  4095. /// returns a byte array of the client set throttles Gets multiplied by the multiplier
  4096. ///
  4097. /// </summary>
  4098. /// <param name="multiplier">non 1 multiplier for subdividing the throttles between individual regions</param>
  4099. /// <returns></returns>
  4100. public byte[] GetThrottlesPacked(float multiplier)
  4101. {
  4102. return m_PacketHandler.PacketQueue.GetThrottlesPacked(multiplier);
  4103. }
  4104. /// <summary>
  4105. /// sets the throttles from values supplied by the client
  4106. /// </summary>
  4107. /// <param name="throttles"></param>
  4108. public void SetChildAgentThrottle(byte[] throttles)
  4109. {
  4110. m_PacketHandler.PacketQueue.SetThrottleFromClient(throttles);
  4111. }
  4112. /// <summary>
  4113. /// Method gets called when a new packet has arrived from the UDP
  4114. /// server. This happens after it's been decoded into a libsl object.
  4115. /// </summary>
  4116. /// <param name="NewPack">object containing the packet.</param>
  4117. public virtual void InPacket(object NewPack)
  4118. {
  4119. // Cast NewPack to Packet.
  4120. m_PacketHandler.InPacket((Packet) NewPack);
  4121. }
  4122. /// <summary>
  4123. /// This is the starting point for sending a simulator packet out to the client.
  4124. ///
  4125. /// Please do not call this from outside the LindenUDP client stack.
  4126. /// </summary>
  4127. /// <param name="NewPack"></param>
  4128. /// <param name="throttlePacketType">Corresponds to the type of data that is going out. Enum</param>
  4129. public void OutPacket(Packet NewPack, ThrottleOutPacketType throttlePacketType)
  4130. {
  4131. m_PacketHandler.OutPacket(NewPack, throttlePacketType);
  4132. }
  4133. public bool AddMoney(int debit)
  4134. {
  4135. if (m_moneyBalance + debit >= 0)
  4136. {
  4137. m_moneyBalance += debit;
  4138. SendMoneyBalance(UUID.Zero, true, Utils.StringToBytes("Poof Poof!"), m_moneyBalance);
  4139. return true;
  4140. }
  4141. return false;
  4142. }
  4143. /// <summary>
  4144. /// Breaks down the genericMessagePacket into specific events
  4145. /// </summary>
  4146. /// <param name="gmMethod"></param>
  4147. /// <param name="gmInvoice"></param>
  4148. /// <param name="gmParams"></param>
  4149. public void DecipherGenericMessage(string gmMethod, UUID gmInvoice, GenericMessagePacket.ParamListBlock[] gmParams)
  4150. {
  4151. switch (gmMethod)
  4152. {
  4153. case "autopilot":
  4154. float locx;
  4155. float locy;
  4156. float locz;
  4157. try
  4158. {
  4159. uint regionX;
  4160. uint regionY;
  4161. Utils.LongToUInts(Scene.RegionInfo.RegionHandle, out regionX, out regionY);
  4162. locx = Convert.ToSingle(Utils.BytesToString(gmParams[0].Parameter)) - regionX;
  4163. locy = Convert.ToSingle(Utils.BytesToString(gmParams[1].Parameter)) - regionY;
  4164. locz = Convert.ToSingle(Utils.BytesToString(gmParams[2].Parameter));
  4165. }
  4166. catch (InvalidCastException)
  4167. {
  4168. m_log.Error("[CLIENT]: Invalid autopilot request");
  4169. return;
  4170. }
  4171. handlerAutoPilotGo = OnAutoPilotGo;
  4172. if (handlerAutoPilotGo != null)
  4173. {
  4174. handlerAutoPilotGo(0, new Vector3(locx, locy, locz), this);
  4175. }
  4176. m_log.InfoFormat("[CLIENT]: Client Requests autopilot to position <{0},{1},{2}>", locx, locy, locz);
  4177. break;
  4178. default:
  4179. m_log.Debug("[CLIENT]: Unknown Generic Message, Method: " + gmMethod + ". Invoice: " + gmInvoice + ". Dumping Params:");
  4180. for (int hi = 0; hi < gmParams.Length; hi++)
  4181. {
  4182. Console.WriteLine(gmParams[hi].ToString());
  4183. }
  4184. //gmpack.MethodData.
  4185. break;
  4186. }
  4187. }
  4188. /// <summary>
  4189. /// Entryway from the client to the simulator. All UDP packets from the client will end up here
  4190. /// </summary>
  4191. /// <param name="Pack">OpenMetaverse.packet</param>
  4192. public void ProcessInPacket(Packet Pack)
  4193. {
  4194. if (ProcessPacketMethod(Pack))
  4195. {
  4196. return;
  4197. }
  4198. const bool m_checkPackets = true;
  4199. // Main packet processing conditional
  4200. switch (Pack.Type)
  4201. {
  4202. #region Scene/Avatar
  4203. case PacketType.AvatarPropertiesRequest:
  4204. AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;
  4205. #region Packet Session and User Check
  4206. if (m_checkPackets)
  4207. {
  4208. if (avatarProperties.AgentData.SessionID != SessionId ||
  4209. avatarProperties.AgentData.AgentID != AgentId)
  4210. break;
  4211. }
  4212. #endregion
  4213. handlerRequestAvatarProperties = OnRequestAvatarProperties;
  4214. if (handlerRequestAvatarProperties != null)
  4215. {
  4216. handlerRequestAvatarProperties(this, avatarProperties.AgentData.AvatarID);
  4217. }
  4218. break;
  4219. case PacketType.ChatFromViewer:
  4220. ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
  4221. #region Packet Session and User Check
  4222. if (m_checkPackets)
  4223. {
  4224. if (inchatpack.AgentData.SessionID != SessionId ||
  4225. inchatpack.AgentData.AgentID != AgentId)
  4226. break;
  4227. }
  4228. #endregion
  4229. string fromName = String.Empty; //ClientAvatar.firstname + " " + ClientAvatar.lastname;
  4230. byte[] message = inchatpack.ChatData.Message;
  4231. byte type = inchatpack.ChatData.Type;
  4232. Vector3 fromPos = new Vector3(); // ClientAvatar.Pos;
  4233. // UUID fromAgentID = AgentId;
  4234. int channel = inchatpack.ChatData.Channel;
  4235. if (OnChatFromClient != null)
  4236. {
  4237. OSChatMessage args = new OSChatMessage();
  4238. args.Channel = channel;
  4239. args.From = fromName;
  4240. args.Message = Utils.BytesToString(message);
  4241. args.Type = (ChatTypeEnum)type;
  4242. args.Position = fromPos;
  4243. args.Scene = Scene;
  4244. args.Sender = this;
  4245. args.SenderUUID = this.AgentId;
  4246. handlerChatFromClient = OnChatFromClient;
  4247. if (handlerChatFromClient != null)
  4248. handlerChatFromClient(this, args);
  4249. }
  4250. break;
  4251. case PacketType.AvatarPropertiesUpdate:
  4252. AvatarPropertiesUpdatePacket avatarProps = (AvatarPropertiesUpdatePacket)Pack;
  4253. #region Packet Session and User Check
  4254. if (m_checkPackets)
  4255. {
  4256. if (avatarProps.AgentData.SessionID != SessionId ||
  4257. avatarProps.AgentData.AgentID != AgentId)
  4258. break;
  4259. }
  4260. #endregion
  4261. handlerUpdateAvatarProperties = OnUpdateAvatarProperties;
  4262. if (handlerUpdateAvatarProperties != null)
  4263. {
  4264. AvatarPropertiesUpdatePacket.PropertiesDataBlock Properties = avatarProps.PropertiesData;
  4265. UserProfileData UserProfile = new UserProfileData();
  4266. UserProfile.ID = AgentId;
  4267. UserProfile.AboutText = Utils.BytesToString(Properties.AboutText);
  4268. UserProfile.FirstLifeAboutText = Utils.BytesToString(Properties.FLAboutText);
  4269. UserProfile.FirstLifeImage = Properties.FLImageID;
  4270. UserProfile.Image = Properties.ImageID;
  4271. UserProfile.ProfileUrl = Utils.BytesToString(Properties.ProfileURL);
  4272. handlerUpdateAvatarProperties(this, UserProfile);
  4273. }
  4274. break;
  4275. case PacketType.ScriptDialogReply:
  4276. ScriptDialogReplyPacket rdialog = (ScriptDialogReplyPacket)Pack;
  4277. #region Packet Session and User Check
  4278. if (m_checkPackets)
  4279. {
  4280. if (rdialog.AgentData.SessionID != SessionId ||
  4281. rdialog.AgentData.AgentID != AgentId)
  4282. break;
  4283. }
  4284. #endregion
  4285. int ch = rdialog.Data.ChatChannel;
  4286. byte[] msg = rdialog.Data.ButtonLabel;
  4287. if (OnChatFromClient != null)
  4288. {
  4289. OSChatMessage args = new OSChatMessage();
  4290. args.Channel = ch;
  4291. args.From = String.Empty;
  4292. args.Message = Utils.BytesToString(msg);
  4293. args.Type = ChatTypeEnum.Shout;
  4294. args.Position = new Vector3();
  4295. args.Scene = Scene;
  4296. args.Sender = this;
  4297. handlerChatFromClient2 = OnChatFromClient;
  4298. if (handlerChatFromClient2 != null)
  4299. handlerChatFromClient2(this, args);
  4300. }
  4301. break;
  4302. case PacketType.ImprovedInstantMessage:
  4303. ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack;
  4304. #region Packet Session and User Check
  4305. if (m_checkPackets)
  4306. {
  4307. if (msgpack.AgentData.SessionID != SessionId ||
  4308. msgpack.AgentData.AgentID != AgentId)
  4309. break;
  4310. }
  4311. #endregion
  4312. string IMfromName = Util.FieldToString(msgpack.MessageBlock.FromAgentName);
  4313. string IMmessage = Utils.BytesToString(msgpack.MessageBlock.Message);
  4314. handlerInstantMessage = OnInstantMessage;
  4315. if (handlerInstantMessage != null)
  4316. {
  4317. GridInstantMessage im = new GridInstantMessage(Scene,
  4318. msgpack.AgentData.AgentID,
  4319. IMfromName,
  4320. msgpack.MessageBlock.ToAgentID,
  4321. msgpack.MessageBlock.Dialog,
  4322. msgpack.MessageBlock.FromGroup,
  4323. IMmessage,
  4324. msgpack.MessageBlock.ID,
  4325. msgpack.MessageBlock.Offline != 0 ? true : false,
  4326. msgpack.MessageBlock.Position,
  4327. msgpack.MessageBlock.BinaryBucket);
  4328. handlerInstantMessage(this, im);
  4329. }
  4330. break;
  4331. case PacketType.AcceptFriendship:
  4332. AcceptFriendshipPacket afriendpack = (AcceptFriendshipPacket)Pack;
  4333. #region Packet Session and User Check
  4334. if (m_checkPackets)
  4335. {
  4336. if (afriendpack.AgentData.SessionID != SessionId ||
  4337. afriendpack.AgentData.AgentID != AgentId)
  4338. break;
  4339. }
  4340. #endregion
  4341. // My guess is this is the folder to stick the calling card into
  4342. List<UUID> callingCardFolders = new List<UUID>();
  4343. UUID agentID = afriendpack.AgentData.AgentID;
  4344. UUID transactionID = afriendpack.TransactionBlock.TransactionID;
  4345. for (int fi = 0; fi < afriendpack.FolderData.Length; fi++)
  4346. {
  4347. callingCardFolders.Add(afriendpack.FolderData[fi].FolderID);
  4348. }
  4349. handlerApproveFriendRequest = OnApproveFriendRequest;
  4350. if (handlerApproveFriendRequest != null)
  4351. {
  4352. handlerApproveFriendRequest(this, agentID, transactionID, callingCardFolders);
  4353. }
  4354. break;
  4355. case PacketType.DeclineFriendship:
  4356. DeclineFriendshipPacket dfriendpack = (DeclineFriendshipPacket)Pack;
  4357. #region Packet Session and User Check
  4358. if (m_checkPackets)
  4359. {
  4360. if (dfriendpack.AgentData.SessionID != SessionId ||
  4361. dfriendpack.AgentData.AgentID != AgentId)
  4362. break;
  4363. }
  4364. #endregion
  4365. if (OnDenyFriendRequest != null)
  4366. {
  4367. OnDenyFriendRequest(this,
  4368. dfriendpack.AgentData.AgentID,
  4369. dfriendpack.TransactionBlock.TransactionID,
  4370. null);
  4371. }
  4372. break;
  4373. case PacketType.TerminateFriendship:
  4374. TerminateFriendshipPacket tfriendpack = (TerminateFriendshipPacket)Pack;
  4375. #region Packet Session and User Check
  4376. if (m_checkPackets)
  4377. {
  4378. if (tfriendpack.AgentData.SessionID != SessionId ||
  4379. tfriendpack.AgentData.AgentID != AgentId)
  4380. break;
  4381. }
  4382. #endregion
  4383. UUID listOwnerAgentID = tfriendpack.AgentData.AgentID;
  4384. UUID exFriendID = tfriendpack.ExBlock.OtherID;
  4385. handlerTerminateFriendship = OnTerminateFriendship;
  4386. if (handlerTerminateFriendship != null)
  4387. {
  4388. handlerTerminateFriendship(this, listOwnerAgentID, exFriendID);
  4389. }
  4390. break;
  4391. case PacketType.RezObject:
  4392. RezObjectPacket rezPacket = (RezObjectPacket)Pack;
  4393. #region Packet Session and User Check
  4394. if (m_checkPackets)
  4395. {
  4396. if (rezPacket.AgentData.SessionID != SessionId ||
  4397. rezPacket.AgentData.AgentID != AgentId)
  4398. break;
  4399. }
  4400. #endregion
  4401. handlerRezObject = OnRezObject;
  4402. if (handlerRezObject != null)
  4403. {
  4404. handlerRezObject(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd,
  4405. rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID,
  4406. rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection,
  4407. rezPacket.RezData.RezSelected, rezPacket.RezData.RemoveItem,
  4408. rezPacket.RezData.FromTaskID);
  4409. }
  4410. break;
  4411. case PacketType.DeRezObject:
  4412. DeRezObjectPacket DeRezPacket = (DeRezObjectPacket) Pack;
  4413. #region Packet Session and User Check
  4414. if (m_checkPackets)
  4415. {
  4416. if (DeRezPacket.AgentData.SessionID != SessionId ||
  4417. DeRezPacket.AgentData.AgentID != AgentId)
  4418. break;
  4419. }
  4420. #endregion
  4421. handlerDeRezObject = OnDeRezObject;
  4422. if (handlerDeRezObject != null)
  4423. {
  4424. List<uint> deRezIDs = new List<uint>();
  4425. foreach (DeRezObjectPacket.ObjectDataBlock data in
  4426. DeRezPacket.ObjectData)
  4427. {
  4428. deRezIDs.Add(data.ObjectLocalID);
  4429. }
  4430. // It just so happens that the values on the DeRezAction enumerator match the Destination
  4431. // values given by a Second Life client
  4432. handlerDeRezObject(this, deRezIDs,
  4433. DeRezPacket.AgentBlock.GroupID,
  4434. (DeRezAction)DeRezPacket.AgentBlock.Destination,
  4435. DeRezPacket.AgentBlock.DestinationID);
  4436. }
  4437. break;
  4438. case PacketType.ModifyLand:
  4439. ModifyLandPacket modify = (ModifyLandPacket)Pack;
  4440. #region Packet Session and User Check
  4441. if (m_checkPackets)
  4442. {
  4443. if (modify.AgentData.SessionID != SessionId ||
  4444. modify.AgentData.AgentID != AgentId)
  4445. break;
  4446. }
  4447. #endregion
  4448. //m_log.Info("[LAND]: LAND:" + modify.ToString());
  4449. if (modify.ParcelData.Length > 0)
  4450. {
  4451. if (OnModifyTerrain != null)
  4452. {
  4453. for (int i = 0; i < modify.ParcelData.Length; i++)
  4454. {
  4455. handlerModifyTerrain = OnModifyTerrain;
  4456. if (handlerModifyTerrain != null)
  4457. {
  4458. handlerModifyTerrain(AgentId, modify.ModifyBlock.Height, modify.ModifyBlock.Seconds,
  4459. modify.ModifyBlock.BrushSize,
  4460. modify.ModifyBlock.Action, modify.ParcelData[i].North,
  4461. modify.ParcelData[i].West, modify.ParcelData[i].South,
  4462. modify.ParcelData[i].East, AgentId);
  4463. }
  4464. }
  4465. }
  4466. }
  4467. break;
  4468. case PacketType.RegionHandshakeReply:
  4469. handlerRegionHandShakeReply = OnRegionHandShakeReply;
  4470. if (handlerRegionHandShakeReply != null)
  4471. {
  4472. handlerRegionHandShakeReply(this);
  4473. }
  4474. break;
  4475. case PacketType.AgentWearablesRequest:
  4476. handlerRequestWearables = OnRequestWearables;
  4477. if (handlerRequestWearables != null)
  4478. {
  4479. handlerRequestWearables();
  4480. }
  4481. handlerRequestAvatarsData = OnRequestAvatarsData;
  4482. if (handlerRequestAvatarsData != null)
  4483. {
  4484. handlerRequestAvatarsData(this);
  4485. }
  4486. break;
  4487. case PacketType.AgentSetAppearance:
  4488. AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
  4489. #region Packet Session and User Check
  4490. if (m_checkPackets)
  4491. {
  4492. if (appear.AgentData.SessionID != SessionId ||
  4493. appear.AgentData.AgentID != AgentId)
  4494. break;
  4495. }
  4496. #endregion
  4497. handlerSetAppearance = OnSetAppearance;
  4498. if (handlerSetAppearance != null)
  4499. {
  4500. // Temporarily protect ourselves from the mantis #951 failure.
  4501. // However, we could do this for several other handlers where a failure isn't terminal
  4502. // for the client session anyway, in order to protect ourselves against bad code in plugins
  4503. try
  4504. {
  4505. List<byte> visualparams = new List<byte>();
  4506. foreach (AgentSetAppearancePacket.VisualParamBlock x in appear.VisualParam)
  4507. {
  4508. visualparams.Add(x.ParamValue);
  4509. }
  4510. handlerSetAppearance(appear.ObjectData.TextureEntry, visualparams);
  4511. }
  4512. catch (Exception e)
  4513. {
  4514. m_log.ErrorFormat(
  4515. "[CLIENT VIEW]: AgentSetApperance packet handler threw an exception, {0}",
  4516. e);
  4517. }
  4518. }
  4519. break;
  4520. case PacketType.AgentIsNowWearing:
  4521. if (OnAvatarNowWearing != null)
  4522. {
  4523. AgentIsNowWearingPacket nowWearing = (AgentIsNowWearingPacket)Pack;
  4524. #region Packet Session and User Check
  4525. if (m_checkPackets)
  4526. {
  4527. if (nowWearing.AgentData.SessionID != SessionId ||
  4528. nowWearing.AgentData.AgentID != AgentId)
  4529. break;
  4530. }
  4531. #endregion
  4532. AvatarWearingArgs wearingArgs = new AvatarWearingArgs();
  4533. for (int i = 0; i < nowWearing.WearableData.Length; i++)
  4534. {
  4535. AvatarWearingArgs.Wearable wearable =
  4536. new AvatarWearingArgs.Wearable(nowWearing.WearableData[i].ItemID,
  4537. nowWearing.WearableData[i].WearableType);
  4538. wearingArgs.NowWearing.Add(wearable);
  4539. }
  4540. handlerAvatarNowWearing = OnAvatarNowWearing;
  4541. if (handlerAvatarNowWearing != null)
  4542. {
  4543. handlerAvatarNowWearing(this, wearingArgs);
  4544. }
  4545. }
  4546. break;
  4547. case PacketType.RezSingleAttachmentFromInv:
  4548. handlerRezSingleAttachment = OnRezSingleAttachmentFromInv;
  4549. if (handlerRezSingleAttachment != null)
  4550. {
  4551. RezSingleAttachmentFromInvPacket rez = (RezSingleAttachmentFromInvPacket)Pack;
  4552. #region Packet Session and User Check
  4553. if (m_checkPackets)
  4554. {
  4555. if (rez.AgentData.SessionID != SessionId ||
  4556. rez.AgentData.AgentID != AgentId)
  4557. break;
  4558. }
  4559. #endregion
  4560. handlerRezSingleAttachment(this, rez.ObjectData.ItemID,
  4561. rez.ObjectData.AttachmentPt);
  4562. }
  4563. break;
  4564. case PacketType.RezMultipleAttachmentsFromInv:
  4565. handlerRezMultipleAttachments = OnRezMultipleAttachmentsFromInv;
  4566. if (handlerRezMultipleAttachments != null)
  4567. {
  4568. RezMultipleAttachmentsFromInvPacket rez = (RezMultipleAttachmentsFromInvPacket)Pack;
  4569. handlerRezMultipleAttachments(this, rez.HeaderData,
  4570. rez.ObjectData);
  4571. }
  4572. break;
  4573. case PacketType.DetachAttachmentIntoInv:
  4574. handlerDetachAttachmentIntoInv = OnDetachAttachmentIntoInv;
  4575. if (handlerDetachAttachmentIntoInv != null)
  4576. {
  4577. DetachAttachmentIntoInvPacket detachtoInv = (DetachAttachmentIntoInvPacket)Pack;
  4578. #region Packet Session and User Check
  4579. // UNSUPPORTED ON THIS PACKET
  4580. #endregion
  4581. UUID itemID = detachtoInv.ObjectData.ItemID;
  4582. // UUID ATTACH_agentID = detachtoInv.ObjectData.AgentID;
  4583. handlerDetachAttachmentIntoInv(itemID, this);
  4584. }
  4585. break;
  4586. case PacketType.ObjectAttach:
  4587. if (OnObjectAttach != null)
  4588. {
  4589. ObjectAttachPacket att = (ObjectAttachPacket)Pack;
  4590. #region Packet Session and User Check
  4591. if (m_checkPackets)
  4592. {
  4593. if (att.AgentData.SessionID != SessionId ||
  4594. att.AgentData.AgentID != AgentId)
  4595. break;
  4596. }
  4597. #endregion
  4598. handlerObjectAttach = OnObjectAttach;
  4599. if (handlerObjectAttach != null)
  4600. {
  4601. if (att.ObjectData.Length > 0)
  4602. {
  4603. handlerObjectAttach(this, att.ObjectData[0].ObjectLocalID, att.AgentData.AttachmentPoint, att.ObjectData[0].Rotation, false);
  4604. }
  4605. }
  4606. }
  4607. break;
  4608. case PacketType.ObjectDetach:
  4609. ObjectDetachPacket dett = (ObjectDetachPacket)Pack;
  4610. #region Packet Session and User Check
  4611. if (m_checkPackets)
  4612. {
  4613. if (dett.AgentData.SessionID != SessionId ||
  4614. dett.AgentData.AgentID != AgentId)
  4615. break;
  4616. }
  4617. #endregion
  4618. for (int j = 0; j < dett.ObjectData.Length; j++)
  4619. {
  4620. uint obj = dett.ObjectData[j].ObjectLocalID;
  4621. handlerObjectDetach = OnObjectDetach;
  4622. if (handlerObjectDetach != null)
  4623. {
  4624. handlerObjectDetach(obj, this);
  4625. }
  4626. }
  4627. break;
  4628. case PacketType.ObjectDrop:
  4629. ObjectDropPacket dropp = (ObjectDropPacket)Pack;
  4630. #region Packet Session and User Check
  4631. if (m_checkPackets)
  4632. {
  4633. if (dropp.AgentData.SessionID != SessionId ||
  4634. dropp.AgentData.AgentID != AgentId)
  4635. break;
  4636. }
  4637. #endregion
  4638. for (int j = 0; j < dropp.ObjectData.Length; j++)
  4639. {
  4640. uint obj = dropp.ObjectData[j].ObjectLocalID;
  4641. handlerObjectDrop = OnObjectDrop;
  4642. if (handlerObjectDrop != null)
  4643. {
  4644. handlerObjectDrop(obj, this);
  4645. }
  4646. }
  4647. break;
  4648. case PacketType.SetAlwaysRun:
  4649. SetAlwaysRunPacket run = (SetAlwaysRunPacket)Pack;
  4650. #region Packet Session and User Check
  4651. if (m_checkPackets)
  4652. {
  4653. if (run.AgentData.SessionID != SessionId ||
  4654. run.AgentData.AgentID != AgentId)
  4655. break;
  4656. }
  4657. #endregion
  4658. handlerSetAlwaysRun = OnSetAlwaysRun;
  4659. if (handlerSetAlwaysRun != null)
  4660. handlerSetAlwaysRun(this, run.AgentData.AlwaysRun);
  4661. break;
  4662. case PacketType.CompleteAgentMovement:
  4663. handlerCompleteMovementToRegion = OnCompleteMovementToRegion;
  4664. if (handlerCompleteMovementToRegion != null)
  4665. {
  4666. handlerCompleteMovementToRegion();
  4667. }
  4668. handlerCompleteMovementToRegion = null;
  4669. break;
  4670. case PacketType.AgentUpdate:
  4671. if (OnAgentUpdate != null)
  4672. {
  4673. bool update = false;
  4674. AgentUpdatePacket agenUpdate = (AgentUpdatePacket)Pack;
  4675. #region Packet Session and User Check
  4676. if (m_checkPackets)
  4677. {
  4678. if (agenUpdate.AgentData.SessionID != SessionId ||
  4679. agenUpdate.AgentData.AgentID != AgentId)
  4680. break;
  4681. }
  4682. #endregion
  4683. AgentUpdatePacket.AgentDataBlock x = agenUpdate.AgentData;
  4684. // We can only check when we have something to check
  4685. // against.
  4686. if (lastarg != null)
  4687. {
  4688. update =
  4689. (
  4690. (x.BodyRotation != lastarg.BodyRotation) ||
  4691. (x.CameraAtAxis != lastarg.CameraAtAxis) ||
  4692. (x.CameraCenter != lastarg.CameraCenter) ||
  4693. (x.CameraLeftAxis != lastarg.CameraLeftAxis) ||
  4694. (x.CameraUpAxis != lastarg.CameraUpAxis) ||
  4695. (x.ControlFlags != lastarg.ControlFlags) ||
  4696. (x.Far != lastarg.Far) ||
  4697. (x.Flags != lastarg.Flags) ||
  4698. (x.State != lastarg.State) ||
  4699. (x.HeadRotation != lastarg.HeadRotation) ||
  4700. (x.SessionID != lastarg.SessionID) ||
  4701. (x.AgentID != lastarg.AgentID)
  4702. );
  4703. }
  4704. else
  4705. update = true;
  4706. // These should be ordered from most-likely to
  4707. // least likely to change. I've made an initial
  4708. // guess at that.
  4709. if (update)
  4710. {
  4711. AgentUpdateArgs arg = new AgentUpdateArgs();
  4712. arg.AgentID = x.AgentID;
  4713. arg.BodyRotation = x.BodyRotation;
  4714. arg.CameraAtAxis = x.CameraAtAxis;
  4715. arg.CameraCenter = x.CameraCenter;
  4716. arg.CameraLeftAxis = x.CameraLeftAxis;
  4717. arg.CameraUpAxis = x.CameraUpAxis;
  4718. arg.ControlFlags = x.ControlFlags;
  4719. arg.Far = x.Far;
  4720. arg.Flags = x.Flags;
  4721. arg.HeadRotation = x.HeadRotation;
  4722. arg.SessionID = x.SessionID;
  4723. arg.State = x.State;
  4724. handlerAgentUpdate = OnAgentUpdate;
  4725. lastarg = arg; // save this set of arguments for nexttime
  4726. if (handlerAgentUpdate != null)
  4727. OnAgentUpdate(this, arg);
  4728. handlerAgentUpdate = null;
  4729. }
  4730. }
  4731. break;
  4732. case PacketType.AgentAnimation:
  4733. AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
  4734. #region Packet Session and User Check
  4735. if (m_checkPackets)
  4736. {
  4737. if (AgentAni.AgentData.SessionID != SessionId ||
  4738. AgentAni.AgentData.AgentID != AgentId)
  4739. break;
  4740. }
  4741. #endregion
  4742. handlerStartAnim = null;
  4743. handlerStopAnim = null;
  4744. for (int i = 0; i < AgentAni.AnimationList.Length; i++)
  4745. {
  4746. if (AgentAni.AnimationList[i].StartAnim)
  4747. {
  4748. handlerStartAnim = OnStartAnim;
  4749. if (handlerStartAnim != null)
  4750. {
  4751. handlerStartAnim(this, AgentAni.AnimationList[i].AnimID);
  4752. }
  4753. }
  4754. else
  4755. {
  4756. handlerStopAnim = OnStopAnim;
  4757. if (handlerStopAnim != null)
  4758. {
  4759. handlerStopAnim(this, AgentAni.AnimationList[i].AnimID);
  4760. }
  4761. }
  4762. }
  4763. break;
  4764. case PacketType.AgentRequestSit:
  4765. if (OnAgentRequestSit != null)
  4766. {
  4767. AgentRequestSitPacket agentRequestSit = (AgentRequestSitPacket)Pack;
  4768. #region Packet Session and User Check
  4769. if (m_checkPackets)
  4770. {
  4771. if (agentRequestSit.AgentData.SessionID != SessionId ||
  4772. agentRequestSit.AgentData.AgentID != AgentId)
  4773. break;
  4774. }
  4775. #endregion
  4776. handlerAgentRequestSit = OnAgentRequestSit;
  4777. if (handlerAgentRequestSit != null)
  4778. handlerAgentRequestSit(this, agentRequestSit.AgentData.AgentID,
  4779. agentRequestSit.TargetObject.TargetID, agentRequestSit.TargetObject.Offset);
  4780. }
  4781. break;
  4782. case PacketType.AgentSit:
  4783. if (OnAgentSit != null)
  4784. {
  4785. AgentSitPacket agentSit = (AgentSitPacket)Pack;
  4786. #region Packet Session and User Check
  4787. if (m_checkPackets)
  4788. {
  4789. if (agentSit.AgentData.SessionID != SessionId ||
  4790. agentSit.AgentData.AgentID != AgentId)
  4791. break;
  4792. }
  4793. #endregion
  4794. handlerAgentSit = OnAgentSit;
  4795. if (handlerAgentSit != null)
  4796. {
  4797. OnAgentSit(this, agentSit.AgentData.AgentID);
  4798. }
  4799. }
  4800. break;
  4801. case PacketType.SoundTrigger:
  4802. SoundTriggerPacket soundTriggerPacket = (SoundTriggerPacket)Pack;
  4803. #region Packet Session and User Check
  4804. if (m_checkPackets)
  4805. {
  4806. // UNSUPPORTED ON THIS PACKET
  4807. }
  4808. #endregion
  4809. handlerSoundTrigger = OnSoundTrigger;
  4810. if (handlerSoundTrigger != null)
  4811. {
  4812. handlerSoundTrigger(soundTriggerPacket.SoundData.SoundID, soundTriggerPacket.SoundData.OwnerID,
  4813. soundTriggerPacket.SoundData.ObjectID, soundTriggerPacket.SoundData.ParentID,
  4814. soundTriggerPacket.SoundData.Gain, soundTriggerPacket.SoundData.Position,
  4815. soundTriggerPacket.SoundData.Handle);
  4816. }
  4817. break;
  4818. case PacketType.AvatarPickerRequest:
  4819. AvatarPickerRequestPacket avRequestQuery = (AvatarPickerRequestPacket)Pack;
  4820. #region Packet Session and User Check
  4821. if (m_checkPackets)
  4822. {
  4823. if (avRequestQuery.AgentData.SessionID != SessionId ||
  4824. avRequestQuery.AgentData.AgentID != AgentId)
  4825. break;
  4826. }
  4827. #endregion
  4828. AvatarPickerRequestPacket.AgentDataBlock Requestdata = avRequestQuery.AgentData;
  4829. AvatarPickerRequestPacket.DataBlock querydata = avRequestQuery.Data;
  4830. //m_log.Debug("Agent Sends:" + Utils.BytesToString(querydata.Name));
  4831. handlerAvatarPickerRequest = OnAvatarPickerRequest;
  4832. if (handlerAvatarPickerRequest != null)
  4833. {
  4834. handlerAvatarPickerRequest(this, Requestdata.AgentID, Requestdata.QueryID,
  4835. Utils.BytesToString(querydata.Name));
  4836. }
  4837. break;
  4838. case PacketType.AgentDataUpdateRequest:
  4839. AgentDataUpdateRequestPacket avRequestDataUpdatePacket = (AgentDataUpdateRequestPacket)Pack;
  4840. #region Packet Session and User Check
  4841. if (m_checkPackets)
  4842. {
  4843. if (avRequestDataUpdatePacket.AgentData.SessionID != SessionId ||
  4844. avRequestDataUpdatePacket.AgentData.AgentID != AgentId)
  4845. break;
  4846. }
  4847. #endregion
  4848. handlerAgentDataUpdateRequest = OnAgentDataUpdateRequest;
  4849. if (handlerAgentDataUpdateRequest != null)
  4850. {
  4851. handlerAgentDataUpdateRequest(this, avRequestDataUpdatePacket.AgentData.AgentID, avRequestDataUpdatePacket.AgentData.SessionID);
  4852. }
  4853. break;
  4854. case PacketType.UserInfoRequest:
  4855. handlerUserInfoRequest = OnUserInfoRequest;
  4856. if (handlerUserInfoRequest != null)
  4857. {
  4858. handlerUserInfoRequest(this);
  4859. }
  4860. else
  4861. {
  4862. SendUserInfoReply(false, true, "");
  4863. }
  4864. break;
  4865. case PacketType.UpdateUserInfo:
  4866. UpdateUserInfoPacket updateUserInfo = (UpdateUserInfoPacket)Pack;
  4867. #region Packet Session and User Check
  4868. if (m_checkPackets)
  4869. {
  4870. if (updateUserInfo.AgentData.SessionID != SessionId ||
  4871. updateUserInfo.AgentData.AgentID != AgentId)
  4872. break;
  4873. }
  4874. #endregion
  4875. handlerUpdateUserInfo = OnUpdateUserInfo;
  4876. if (handlerUpdateUserInfo != null)
  4877. {
  4878. bool visible = true;
  4879. string DirectoryVisibility =
  4880. Utils.BytesToString(updateUserInfo.UserData.DirectoryVisibility);
  4881. if (DirectoryVisibility == "hidden")
  4882. visible = false;
  4883. handlerUpdateUserInfo(
  4884. updateUserInfo.UserData.IMViaEMail,
  4885. visible, this);
  4886. }
  4887. break;
  4888. case PacketType.SetStartLocationRequest:
  4889. SetStartLocationRequestPacket avSetStartLocationRequestPacket = (SetStartLocationRequestPacket)Pack;
  4890. #region Packet Session and User Check
  4891. if (m_checkPackets)
  4892. {
  4893. if (avSetStartLocationRequestPacket.AgentData.SessionID != SessionId ||
  4894. avSetStartLocationRequestPacket.AgentData.AgentID != AgentId)
  4895. break;
  4896. }
  4897. #endregion
  4898. if (avSetStartLocationRequestPacket.AgentData.AgentID == AgentId && avSetStartLocationRequestPacket.AgentData.SessionID == SessionId)
  4899. {
  4900. handlerSetStartLocationRequest = OnSetStartLocationRequest;
  4901. if (handlerSetStartLocationRequest != null)
  4902. {
  4903. handlerSetStartLocationRequest(this, 0, avSetStartLocationRequestPacket.StartLocationData.LocationPos,
  4904. avSetStartLocationRequestPacket.StartLocationData.LocationLookAt,
  4905. avSetStartLocationRequestPacket.StartLocationData.LocationID);
  4906. }
  4907. }
  4908. break;
  4909. case PacketType.AgentThrottle:
  4910. AgentThrottlePacket atpack = (AgentThrottlePacket)Pack;
  4911. #region Packet Session and User Check
  4912. if (m_checkPackets)
  4913. {
  4914. if (atpack.AgentData.SessionID != SessionId ||
  4915. atpack.AgentData.AgentID != AgentId)
  4916. break;
  4917. }
  4918. #endregion
  4919. m_PacketHandler.PacketQueue.SetThrottleFromClient(atpack.Throttle.Throttles);
  4920. break;
  4921. case PacketType.AgentPause:
  4922. m_probesWithNoIngressPackets = 0;
  4923. m_clientBlocked = true;
  4924. break;
  4925. case PacketType.AgentResume:
  4926. m_probesWithNoIngressPackets = 0;
  4927. m_clientBlocked = false;
  4928. SendStartPingCheck(0);
  4929. break;
  4930. case PacketType.ForceScriptControlRelease:
  4931. handlerForceReleaseControls = OnForceReleaseControls;
  4932. if (handlerForceReleaseControls != null)
  4933. {
  4934. handlerForceReleaseControls(this, AgentId);
  4935. }
  4936. break;
  4937. #endregion
  4938. #region Objects/m_sceneObjects
  4939. case PacketType.ObjectLink:
  4940. ObjectLinkPacket link = (ObjectLinkPacket)Pack;
  4941. #region Packet Session and User Check
  4942. if (m_checkPackets)
  4943. {
  4944. if (link.AgentData.SessionID != SessionId ||
  4945. link.AgentData.AgentID != AgentId)
  4946. break;
  4947. }
  4948. #endregion
  4949. uint parentprimid = 0;
  4950. List<uint> childrenprims = new List<uint>();
  4951. if (link.ObjectData.Length > 1)
  4952. {
  4953. parentprimid = link.ObjectData[0].ObjectLocalID;
  4954. for (int i = 1; i < link.ObjectData.Length; i++)
  4955. {
  4956. childrenprims.Add(link.ObjectData[i].ObjectLocalID);
  4957. }
  4958. }
  4959. handlerLinkObjects = OnLinkObjects;
  4960. if (handlerLinkObjects != null)
  4961. {
  4962. handlerLinkObjects(this, parentprimid, childrenprims);
  4963. }
  4964. break;
  4965. case PacketType.ObjectDelink:
  4966. ObjectDelinkPacket delink = (ObjectDelinkPacket)Pack;
  4967. #region Packet Session and User Check
  4968. if (m_checkPackets)
  4969. {
  4970. if (delink.AgentData.SessionID != SessionId ||
  4971. delink.AgentData.AgentID != AgentId)
  4972. break;
  4973. }
  4974. #endregion
  4975. // It appears the prim at index 0 is not always the root prim (for
  4976. // instance, when one prim of a link set has been edited independently
  4977. // of the others). Therefore, we'll pass all the ids onto the delink
  4978. // method for it to decide which is the root.
  4979. List<uint> prims = new List<uint>();
  4980. for (int i = 0; i < delink.ObjectData.Length; i++)
  4981. {
  4982. prims.Add(delink.ObjectData[i].ObjectLocalID);
  4983. }
  4984. handlerDelinkObjects = OnDelinkObjects;
  4985. if (handlerDelinkObjects != null)
  4986. {
  4987. handlerDelinkObjects(prims);
  4988. }
  4989. break;
  4990. case PacketType.ObjectAdd:
  4991. if (OnAddPrim != null)
  4992. {
  4993. ObjectAddPacket addPacket = (ObjectAddPacket)Pack;
  4994. #region Packet Session and User Check
  4995. if (m_checkPackets)
  4996. {
  4997. if (addPacket.AgentData.SessionID != SessionId ||
  4998. addPacket.AgentData.AgentID != AgentId)
  4999. break;
  5000. }
  5001. #endregion
  5002. PrimitiveBaseShape shape = GetShapeFromAddPacket(addPacket);
  5003. // m_log.Info("[REZData]: " + addPacket.ToString());
  5004. //BypassRaycast: 1
  5005. //RayStart: <69.79469, 158.2652, 98.40343>
  5006. //RayEnd: <61.97724, 141.995, 92.58341>
  5007. //RayTargetID: 00000000-0000-0000-0000-000000000000
  5008. //Check to see if adding the prim is allowed; useful for any module wanting to restrict the
  5009. //object from rezing initially
  5010. handlerAddPrim = OnAddPrim;
  5011. if (handlerAddPrim != null)
  5012. handlerAddPrim(AgentId, ActiveGroupId, addPacket.ObjectData.RayEnd, addPacket.ObjectData.Rotation, shape, addPacket.ObjectData.BypassRaycast, addPacket.ObjectData.RayStart, addPacket.ObjectData.RayTargetID, addPacket.ObjectData.RayEndIsIntersection);
  5013. }
  5014. break;
  5015. case PacketType.ObjectShape:
  5016. ObjectShapePacket shapePacket = (ObjectShapePacket)Pack;
  5017. #region Packet Session and User Check
  5018. if (m_checkPackets)
  5019. {
  5020. if (shapePacket.AgentData.SessionID != SessionId ||
  5021. shapePacket.AgentData.AgentID != AgentId)
  5022. break;
  5023. }
  5024. #endregion
  5025. handlerUpdatePrimShape = null;
  5026. for (int i = 0; i < shapePacket.ObjectData.Length; i++)
  5027. {
  5028. handlerUpdatePrimShape = OnUpdatePrimShape;
  5029. if (handlerUpdatePrimShape != null)
  5030. {
  5031. UpdateShapeArgs shapeData = new UpdateShapeArgs();
  5032. shapeData.ObjectLocalID = shapePacket.ObjectData[i].ObjectLocalID;
  5033. shapeData.PathBegin = shapePacket.ObjectData[i].PathBegin;
  5034. shapeData.PathCurve = shapePacket.ObjectData[i].PathCurve;
  5035. shapeData.PathEnd = shapePacket.ObjectData[i].PathEnd;
  5036. shapeData.PathRadiusOffset = shapePacket.ObjectData[i].PathRadiusOffset;
  5037. shapeData.PathRevolutions = shapePacket.ObjectData[i].PathRevolutions;
  5038. shapeData.PathScaleX = shapePacket.ObjectData[i].PathScaleX;
  5039. shapeData.PathScaleY = shapePacket.ObjectData[i].PathScaleY;
  5040. shapeData.PathShearX = shapePacket.ObjectData[i].PathShearX;
  5041. shapeData.PathShearY = shapePacket.ObjectData[i].PathShearY;
  5042. shapeData.PathSkew = shapePacket.ObjectData[i].PathSkew;
  5043. shapeData.PathTaperX = shapePacket.ObjectData[i].PathTaperX;
  5044. shapeData.PathTaperY = shapePacket.ObjectData[i].PathTaperY;
  5045. shapeData.PathTwist = shapePacket.ObjectData[i].PathTwist;
  5046. shapeData.PathTwistBegin = shapePacket.ObjectData[i].PathTwistBegin;
  5047. shapeData.ProfileBegin = shapePacket.ObjectData[i].ProfileBegin;
  5048. shapeData.ProfileCurve = shapePacket.ObjectData[i].ProfileCurve;
  5049. shapeData.ProfileEnd = shapePacket.ObjectData[i].ProfileEnd;
  5050. shapeData.ProfileHollow = shapePacket.ObjectData[i].ProfileHollow;
  5051. handlerUpdatePrimShape(m_agentId, shapePacket.ObjectData[i].ObjectLocalID,
  5052. shapeData);
  5053. }
  5054. }
  5055. break;
  5056. case PacketType.ObjectExtraParams:
  5057. ObjectExtraParamsPacket extraPar = (ObjectExtraParamsPacket)Pack;
  5058. #region Packet Session and User Check
  5059. if (m_checkPackets)
  5060. {
  5061. if (extraPar.AgentData.SessionID != SessionId ||
  5062. extraPar.AgentData.AgentID != AgentId)
  5063. break;
  5064. }
  5065. #endregion
  5066. handlerUpdateExtraParams = OnUpdateExtraParams;
  5067. if (handlerUpdateExtraParams != null)
  5068. {
  5069. for (int i = 0 ; i < extraPar.ObjectData.Length ; i++)
  5070. {
  5071. handlerUpdateExtraParams(m_agentId, extraPar.ObjectData[i].ObjectLocalID,
  5072. extraPar.ObjectData[i].ParamType,
  5073. extraPar.ObjectData[i].ParamInUse, extraPar.ObjectData[i].ParamData);
  5074. }
  5075. }
  5076. break;
  5077. case PacketType.ObjectDuplicate:
  5078. ObjectDuplicatePacket dupe = (ObjectDuplicatePacket)Pack;
  5079. #region Packet Session and User Check
  5080. if (m_checkPackets)
  5081. {
  5082. if (dupe.AgentData.SessionID != SessionId ||
  5083. dupe.AgentData.AgentID != AgentId)
  5084. break;
  5085. }
  5086. #endregion
  5087. ObjectDuplicatePacket.AgentDataBlock AgentandGroupData = dupe.AgentData;
  5088. handlerObjectDuplicate = null;
  5089. for (int i = 0; i < dupe.ObjectData.Length; i++)
  5090. {
  5091. handlerObjectDuplicate = OnObjectDuplicate;
  5092. if (handlerObjectDuplicate != null)
  5093. {
  5094. handlerObjectDuplicate(dupe.ObjectData[i].ObjectLocalID, dupe.SharedData.Offset,
  5095. dupe.SharedData.DuplicateFlags, AgentandGroupData.AgentID,
  5096. AgentandGroupData.GroupID);
  5097. }
  5098. }
  5099. break;
  5100. case PacketType.RequestMultipleObjects:
  5101. RequestMultipleObjectsPacket incomingRequest = (RequestMultipleObjectsPacket)Pack;
  5102. #region Packet Session and User Check
  5103. if (m_checkPackets)
  5104. {
  5105. if (incomingRequest.AgentData.SessionID != SessionId ||
  5106. incomingRequest.AgentData.AgentID != AgentId)
  5107. break;
  5108. }
  5109. #endregion
  5110. handlerObjectRequest = null;
  5111. for (int i = 0; i < incomingRequest.ObjectData.Length; i++)
  5112. {
  5113. handlerObjectRequest = OnObjectRequest;
  5114. if (handlerObjectRequest != null)
  5115. {
  5116. handlerObjectRequest(incomingRequest.ObjectData[i].ID, this);
  5117. }
  5118. }
  5119. break;
  5120. case PacketType.ObjectSelect:
  5121. ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
  5122. #region Packet Session and User Check
  5123. if (m_checkPackets)
  5124. {
  5125. if (incomingselect.AgentData.SessionID != SessionId ||
  5126. incomingselect.AgentData.AgentID != AgentId)
  5127. break;
  5128. }
  5129. #endregion
  5130. handlerObjectSelect = null;
  5131. for (int i = 0; i < incomingselect.ObjectData.Length; i++)
  5132. {
  5133. handlerObjectSelect = OnObjectSelect;
  5134. if (handlerObjectSelect != null)
  5135. {
  5136. handlerObjectSelect(incomingselect.ObjectData[i].ObjectLocalID, this);
  5137. }
  5138. }
  5139. break;
  5140. case PacketType.ObjectDeselect:
  5141. ObjectDeselectPacket incomingdeselect = (ObjectDeselectPacket)Pack;
  5142. #region Packet Session and User Check
  5143. if (m_checkPackets)
  5144. {
  5145. if (incomingdeselect.AgentData.SessionID != SessionId ||
  5146. incomingdeselect.AgentData.AgentID != AgentId)
  5147. break;
  5148. }
  5149. #endregion
  5150. handlerObjectDeselect = null;
  5151. for (int i = 0; i < incomingdeselect.ObjectData.Length; i++)
  5152. {
  5153. handlerObjectDeselect = OnObjectDeselect;
  5154. if (handlerObjectDeselect != null)
  5155. {
  5156. OnObjectDeselect(incomingdeselect.ObjectData[i].ObjectLocalID, this);
  5157. }
  5158. }
  5159. break;
  5160. case PacketType.ObjectPosition:
  5161. // DEPRECATED: but till libsecondlife removes it, people will use it
  5162. ObjectPositionPacket position = (ObjectPositionPacket)Pack;
  5163. #region Packet Session and User Check
  5164. if (m_checkPackets)
  5165. {
  5166. if (position.AgentData.SessionID != SessionId ||
  5167. position.AgentData.AgentID != AgentId)
  5168. break;
  5169. }
  5170. #endregion
  5171. for (int i = 0; i < position.ObjectData.Length; i++)
  5172. {
  5173. handlerUpdateVector = OnUpdatePrimGroupPosition;
  5174. if (handlerUpdateVector != null)
  5175. handlerUpdateVector(position.ObjectData[i].ObjectLocalID, position.ObjectData[i].Position, this);
  5176. }
  5177. break;
  5178. case PacketType.ObjectScale:
  5179. // DEPRECATED: but till libsecondlife removes it, people will use it
  5180. ObjectScalePacket scale = (ObjectScalePacket)Pack;
  5181. #region Packet Session and User Check
  5182. if (m_checkPackets)
  5183. {
  5184. if (scale.AgentData.SessionID != SessionId ||
  5185. scale.AgentData.AgentID != AgentId)
  5186. break;
  5187. }
  5188. #endregion
  5189. for (int i = 0; i < scale.ObjectData.Length; i++)
  5190. {
  5191. handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale;
  5192. if (handlerUpdatePrimGroupScale != null)
  5193. handlerUpdatePrimGroupScale(scale.ObjectData[i].ObjectLocalID, scale.ObjectData[i].Scale, this);
  5194. }
  5195. break;
  5196. case PacketType.ObjectRotation:
  5197. // DEPRECATED: but till libsecondlife removes it, people will use it
  5198. ObjectRotationPacket rotation = (ObjectRotationPacket)Pack;
  5199. #region Packet Session and User Check
  5200. if (m_checkPackets)
  5201. {
  5202. if (rotation.AgentData.SessionID != SessionId ||
  5203. rotation.AgentData.AgentID != AgentId)
  5204. break;
  5205. }
  5206. #endregion
  5207. for (int i = 0; i < rotation.ObjectData.Length; i++)
  5208. {
  5209. handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
  5210. if (handlerUpdatePrimRotation != null)
  5211. handlerUpdatePrimRotation(rotation.ObjectData[i].ObjectLocalID, rotation.ObjectData[i].Rotation, this);
  5212. }
  5213. break;
  5214. case PacketType.ObjectFlagUpdate:
  5215. ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
  5216. #region Packet Session and User Check
  5217. if (m_checkPackets)
  5218. {
  5219. if (flags.AgentData.SessionID != SessionId ||
  5220. flags.AgentData.AgentID != AgentId)
  5221. break;
  5222. }
  5223. #endregion
  5224. handlerUpdatePrimFlags = OnUpdatePrimFlags;
  5225. if (handlerUpdatePrimFlags != null)
  5226. {
  5227. byte[] data = Pack.ToBytes();
  5228. // 46,47,48 are special positions within the packet
  5229. // This may change so perhaps we need a better way
  5230. // of storing this (OMV.FlagUpdatePacket.UsePhysics,etc?)
  5231. bool UsePhysics = (data[46] != 0) ? true : false;
  5232. bool IsTemporary = (data[47] != 0) ? true : false;
  5233. bool IsPhantom = (data[48] != 0) ? true : false;
  5234. handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, this);
  5235. }
  5236. break;
  5237. case PacketType.ObjectImage:
  5238. ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
  5239. handlerUpdatePrimTexture = null;
  5240. for (int i = 0; i < imagePack.ObjectData.Length; i++)
  5241. {
  5242. handlerUpdatePrimTexture = OnUpdatePrimTexture;
  5243. if (handlerUpdatePrimTexture != null)
  5244. {
  5245. handlerUpdatePrimTexture(imagePack.ObjectData[i].ObjectLocalID,
  5246. imagePack.ObjectData[i].TextureEntry, this);
  5247. }
  5248. }
  5249. break;
  5250. case PacketType.ObjectGrab:
  5251. ObjectGrabPacket grab = (ObjectGrabPacket)Pack;
  5252. #region Packet Session and User Check
  5253. if (m_checkPackets)
  5254. {
  5255. if (grab.AgentData.SessionID != SessionId ||
  5256. grab.AgentData.AgentID != AgentId)
  5257. break;
  5258. }
  5259. #endregion
  5260. handlerGrabObject = OnGrabObject;
  5261. if (handlerGrabObject != null)
  5262. {
  5263. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  5264. if ((grab.SurfaceInfo != null) && (grab.SurfaceInfo.Length > 0))
  5265. {
  5266. foreach (ObjectGrabPacket.SurfaceInfoBlock surfaceInfo in grab.SurfaceInfo)
  5267. {
  5268. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  5269. arg.Binormal = surfaceInfo.Binormal;
  5270. arg.FaceIndex = surfaceInfo.FaceIndex;
  5271. arg.Normal = surfaceInfo.Normal;
  5272. arg.Position = surfaceInfo.Position;
  5273. arg.STCoord = surfaceInfo.STCoord;
  5274. arg.UVCoord = surfaceInfo.UVCoord;
  5275. touchArgs.Add(arg);
  5276. }
  5277. }
  5278. handlerGrabObject(grab.ObjectData.LocalID, grab.ObjectData.GrabOffset, this, touchArgs);
  5279. }
  5280. break;
  5281. case PacketType.ObjectGrabUpdate:
  5282. ObjectGrabUpdatePacket grabUpdate = (ObjectGrabUpdatePacket)Pack;
  5283. #region Packet Session and User Check
  5284. if (m_checkPackets)
  5285. {
  5286. if (grabUpdate.AgentData.SessionID != SessionId ||
  5287. grabUpdate.AgentData.AgentID != AgentId)
  5288. break;
  5289. }
  5290. #endregion
  5291. handlerGrabUpdate = OnGrabUpdate;
  5292. if (handlerGrabUpdate != null)
  5293. {
  5294. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  5295. if ((grabUpdate.SurfaceInfo != null) && (grabUpdate.SurfaceInfo.Length > 0))
  5296. {
  5297. foreach (ObjectGrabUpdatePacket.SurfaceInfoBlock surfaceInfo in grabUpdate.SurfaceInfo)
  5298. {
  5299. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  5300. arg.Binormal = surfaceInfo.Binormal;
  5301. arg.FaceIndex = surfaceInfo.FaceIndex;
  5302. arg.Normal = surfaceInfo.Normal;
  5303. arg.Position = surfaceInfo.Position;
  5304. arg.STCoord = surfaceInfo.STCoord;
  5305. arg.UVCoord = surfaceInfo.UVCoord;
  5306. touchArgs.Add(arg);
  5307. }
  5308. }
  5309. handlerGrabUpdate(grabUpdate.ObjectData.ObjectID, grabUpdate.ObjectData.GrabOffsetInitial,
  5310. grabUpdate.ObjectData.GrabPosition, this, touchArgs);
  5311. }
  5312. break;
  5313. case PacketType.ObjectDeGrab:
  5314. ObjectDeGrabPacket deGrab = (ObjectDeGrabPacket)Pack;
  5315. #region Packet Session and User Check
  5316. if (m_checkPackets)
  5317. {
  5318. if (deGrab.AgentData.SessionID != SessionId ||
  5319. deGrab.AgentData.AgentID != AgentId)
  5320. break;
  5321. }
  5322. #endregion
  5323. handlerDeGrabObject = OnDeGrabObject;
  5324. if (handlerDeGrabObject != null)
  5325. {
  5326. List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
  5327. if ((deGrab.SurfaceInfo != null) && (deGrab.SurfaceInfo.Length > 0))
  5328. {
  5329. foreach (ObjectDeGrabPacket.SurfaceInfoBlock surfaceInfo in deGrab.SurfaceInfo)
  5330. {
  5331. SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
  5332. arg.Binormal = surfaceInfo.Binormal;
  5333. arg.FaceIndex = surfaceInfo.FaceIndex;
  5334. arg.Normal = surfaceInfo.Normal;
  5335. arg.Position = surfaceInfo.Position;
  5336. arg.STCoord = surfaceInfo.STCoord;
  5337. arg.UVCoord = surfaceInfo.UVCoord;
  5338. touchArgs.Add(arg);
  5339. }
  5340. }
  5341. handlerDeGrabObject(deGrab.ObjectData.LocalID, this, touchArgs);
  5342. }
  5343. break;
  5344. case PacketType.ObjectSpinStart:
  5345. //m_log.Warn("[CLIENT]: unhandled ObjectSpinStart packet");
  5346. ObjectSpinStartPacket spinStart = (ObjectSpinStartPacket)Pack;
  5347. #region Packet Session and User Check
  5348. if (m_checkPackets)
  5349. {
  5350. if (spinStart.AgentData.SessionID != SessionId ||
  5351. spinStart.AgentData.AgentID != AgentId)
  5352. break;
  5353. }
  5354. #endregion
  5355. handlerSpinStart = OnSpinStart;
  5356. if (handlerSpinStart != null)
  5357. {
  5358. handlerSpinStart(spinStart.ObjectData.ObjectID, this);
  5359. }
  5360. break;
  5361. case PacketType.ObjectSpinUpdate:
  5362. //m_log.Warn("[CLIENT]: unhandled ObjectSpinUpdate packet");
  5363. ObjectSpinUpdatePacket spinUpdate = (ObjectSpinUpdatePacket)Pack;
  5364. #region Packet Session and User Check
  5365. if (m_checkPackets)
  5366. {
  5367. if (spinUpdate.AgentData.SessionID != SessionId ||
  5368. spinUpdate.AgentData.AgentID != AgentId)
  5369. break;
  5370. }
  5371. #endregion
  5372. Vector3 axis;
  5373. float angle;
  5374. spinUpdate.ObjectData.Rotation.GetAxisAngle(out axis, out angle);
  5375. //m_log.Warn("[CLIENT]: ObjectSpinUpdate packet rot axis:" + axis + " angle:" + angle);
  5376. handlerSpinUpdate = OnSpinUpdate;
  5377. if (handlerSpinUpdate != null)
  5378. {
  5379. handlerSpinUpdate(spinUpdate.ObjectData.ObjectID, spinUpdate.ObjectData.Rotation, this);
  5380. }
  5381. break;
  5382. case PacketType.ObjectSpinStop:
  5383. //m_log.Warn("[CLIENT]: unhandled ObjectSpinStop packet");
  5384. ObjectSpinStopPacket spinStop = (ObjectSpinStopPacket)Pack;
  5385. #region Packet Session and User Check
  5386. if (m_checkPackets)
  5387. {
  5388. if (spinStop.AgentData.SessionID != SessionId ||
  5389. spinStop.AgentData.AgentID != AgentId)
  5390. break;
  5391. }
  5392. #endregion
  5393. handlerSpinStop = OnSpinStop;
  5394. if (handlerSpinStop != null)
  5395. {
  5396. handlerSpinStop(spinStop.ObjectData.ObjectID, this);
  5397. }
  5398. break;
  5399. case PacketType.ObjectDescription:
  5400. ObjectDescriptionPacket objDes = (ObjectDescriptionPacket)Pack;
  5401. #region Packet Session and User Check
  5402. if (m_checkPackets)
  5403. {
  5404. if (objDes.AgentData.SessionID != SessionId ||
  5405. objDes.AgentData.AgentID != AgentId)
  5406. break;
  5407. }
  5408. #endregion
  5409. handlerObjectDescription = null;
  5410. for (int i = 0; i < objDes.ObjectData.Length; i++)
  5411. {
  5412. handlerObjectDescription = OnObjectDescription;
  5413. if (handlerObjectDescription != null)
  5414. {
  5415. handlerObjectDescription(this, objDes.ObjectData[i].LocalID,
  5416. Util.FieldToString(objDes.ObjectData[i].Description));
  5417. }
  5418. }
  5419. break;
  5420. case PacketType.ObjectName:
  5421. ObjectNamePacket objName = (ObjectNamePacket)Pack;
  5422. #region Packet Session and User Check
  5423. if (m_checkPackets)
  5424. {
  5425. if (objName.AgentData.SessionID != SessionId ||
  5426. objName.AgentData.AgentID != AgentId)
  5427. break;
  5428. }
  5429. #endregion
  5430. handlerObjectName = null;
  5431. for (int i = 0; i < objName.ObjectData.Length; i++)
  5432. {
  5433. handlerObjectName = OnObjectName;
  5434. if (handlerObjectName != null)
  5435. {
  5436. handlerObjectName(this, objName.ObjectData[i].LocalID,
  5437. Util.FieldToString(objName.ObjectData[i].Name));
  5438. }
  5439. }
  5440. break;
  5441. case PacketType.ObjectPermissions:
  5442. if (OnObjectPermissions != null)
  5443. {
  5444. ObjectPermissionsPacket newobjPerms = (ObjectPermissionsPacket)Pack;
  5445. #region Packet Session and User Check
  5446. if (m_checkPackets)
  5447. {
  5448. if (newobjPerms.AgentData.SessionID != SessionId ||
  5449. newobjPerms.AgentData.AgentID != AgentId)
  5450. break;
  5451. }
  5452. #endregion
  5453. UUID AgentID = newobjPerms.AgentData.AgentID;
  5454. UUID SessionID = newobjPerms.AgentData.SessionID;
  5455. handlerObjectPermissions = null;
  5456. for (int i = 0; i < newobjPerms.ObjectData.Length; i++)
  5457. {
  5458. ObjectPermissionsPacket.ObjectDataBlock permChanges = newobjPerms.ObjectData[i];
  5459. byte field = permChanges.Field;
  5460. uint localID = permChanges.ObjectLocalID;
  5461. uint mask = permChanges.Mask;
  5462. byte set = permChanges.Set;
  5463. handlerObjectPermissions = OnObjectPermissions;
  5464. if (handlerObjectPermissions != null)
  5465. handlerObjectPermissions(this, AgentID, SessionID, field, localID, mask, set);
  5466. }
  5467. }
  5468. // Here's our data,
  5469. // PermField contains the field the info goes into
  5470. // PermField determines which mask we're changing
  5471. //
  5472. // chmask is the mask of the change
  5473. // setTF is whether we're adding it or taking it away
  5474. //
  5475. // objLocalID is the localID of the object.
  5476. // Unfortunately, we have to pass the event the packet because objData is an array
  5477. // That means multiple object perms may be updated in a single packet.
  5478. break;
  5479. case PacketType.Undo:
  5480. UndoPacket undoitem = (UndoPacket)Pack;
  5481. #region Packet Session and User Check
  5482. if (m_checkPackets)
  5483. {
  5484. if (undoitem.AgentData.SessionID != SessionId ||
  5485. undoitem.AgentData.AgentID != AgentId)
  5486. break;
  5487. }
  5488. #endregion
  5489. if (undoitem.ObjectData.Length > 0)
  5490. {
  5491. for (int i = 0; i < undoitem.ObjectData.Length; i++)
  5492. {
  5493. UUID objiD = undoitem.ObjectData[i].ObjectID;
  5494. handlerOnUndo = OnUndo;
  5495. if (handlerOnUndo != null)
  5496. {
  5497. handlerOnUndo(this, objiD);
  5498. }
  5499. }
  5500. }
  5501. break;
  5502. case PacketType.ObjectDuplicateOnRay:
  5503. ObjectDuplicateOnRayPacket dupeOnRay = (ObjectDuplicateOnRayPacket)Pack;
  5504. #region Packet Session and User Check
  5505. if (m_checkPackets)
  5506. {
  5507. if (dupeOnRay.AgentData.SessionID != SessionId ||
  5508. dupeOnRay.AgentData.AgentID != AgentId)
  5509. break;
  5510. }
  5511. #endregion
  5512. handlerObjectDuplicateOnRay = null;
  5513. for (int i = 0; i < dupeOnRay.ObjectData.Length; i++)
  5514. {
  5515. handlerObjectDuplicateOnRay = OnObjectDuplicateOnRay;
  5516. if (handlerObjectDuplicateOnRay != null)
  5517. {
  5518. handlerObjectDuplicateOnRay(dupeOnRay.ObjectData[i].ObjectLocalID, dupeOnRay.AgentData.DuplicateFlags,
  5519. dupeOnRay.AgentData.AgentID, dupeOnRay.AgentData.GroupID, dupeOnRay.AgentData.RayTargetID, dupeOnRay.AgentData.RayEnd,
  5520. dupeOnRay.AgentData.RayStart, dupeOnRay.AgentData.BypassRaycast, dupeOnRay.AgentData.RayEndIsIntersection,
  5521. dupeOnRay.AgentData.CopyCenters, dupeOnRay.AgentData.CopyRotates);
  5522. }
  5523. }
  5524. break;
  5525. case PacketType.RequestObjectPropertiesFamily:
  5526. //This powers the little tooltip that appears when you move your mouse over an object
  5527. RequestObjectPropertiesFamilyPacket packToolTip = (RequestObjectPropertiesFamilyPacket)Pack;
  5528. #region Packet Session and User Check
  5529. if (m_checkPackets)
  5530. {
  5531. if (packToolTip.AgentData.SessionID != SessionId ||
  5532. packToolTip.AgentData.AgentID != AgentId)
  5533. break;
  5534. }
  5535. #endregion
  5536. RequestObjectPropertiesFamilyPacket.ObjectDataBlock packObjBlock = packToolTip.ObjectData;
  5537. handlerRequestObjectPropertiesFamily = OnRequestObjectPropertiesFamily;
  5538. if (handlerRequestObjectPropertiesFamily != null)
  5539. {
  5540. handlerRequestObjectPropertiesFamily(this, m_agentId, packObjBlock.RequestFlags,
  5541. packObjBlock.ObjectID);
  5542. }
  5543. break;
  5544. case PacketType.ObjectIncludeInSearch:
  5545. //This lets us set objects to appear in search (stuff like DataSnapshot, etc)
  5546. ObjectIncludeInSearchPacket packInSearch = (ObjectIncludeInSearchPacket)Pack;
  5547. handlerObjectIncludeInSearch = null;
  5548. #region Packet Session and User Check
  5549. if (m_checkPackets)
  5550. {
  5551. if (packInSearch.AgentData.SessionID != SessionId ||
  5552. packInSearch.AgentData.AgentID != AgentId)
  5553. break;
  5554. }
  5555. #endregion
  5556. foreach (ObjectIncludeInSearchPacket.ObjectDataBlock objData in packInSearch.ObjectData)
  5557. {
  5558. bool inSearch = objData.IncludeInSearch;
  5559. uint localID = objData.ObjectLocalID;
  5560. handlerObjectIncludeInSearch = OnObjectIncludeInSearch;
  5561. if (handlerObjectIncludeInSearch != null)
  5562. {
  5563. handlerObjectIncludeInSearch(this, inSearch, localID);
  5564. }
  5565. }
  5566. break;
  5567. case PacketType.ScriptAnswerYes:
  5568. ScriptAnswerYesPacket scriptAnswer = (ScriptAnswerYesPacket)Pack;
  5569. #region Packet Session and User Check
  5570. if (m_checkPackets)
  5571. {
  5572. if (scriptAnswer.AgentData.SessionID != SessionId ||
  5573. scriptAnswer.AgentData.AgentID != AgentId)
  5574. break;
  5575. }
  5576. #endregion
  5577. handlerScriptAnswer = OnScriptAnswer;
  5578. if (handlerScriptAnswer != null)
  5579. {
  5580. handlerScriptAnswer(this, scriptAnswer.Data.TaskID, scriptAnswer.Data.ItemID, scriptAnswer.Data.Questions);
  5581. }
  5582. break;
  5583. case PacketType.ObjectClickAction:
  5584. ObjectClickActionPacket ocpacket = (ObjectClickActionPacket)Pack;
  5585. #region Packet Session and User Check
  5586. if (m_checkPackets)
  5587. {
  5588. if (ocpacket.AgentData.SessionID != SessionId ||
  5589. ocpacket.AgentData.AgentID != AgentId)
  5590. break;
  5591. }
  5592. #endregion
  5593. handlerObjectClickAction = OnObjectClickAction;
  5594. if (handlerObjectClickAction != null)
  5595. {
  5596. foreach (ObjectClickActionPacket.ObjectDataBlock odata in ocpacket.ObjectData)
  5597. {
  5598. byte action = odata.ClickAction;
  5599. uint localID = odata.ObjectLocalID;
  5600. handlerObjectClickAction(this, localID, action.ToString());
  5601. }
  5602. }
  5603. break;
  5604. case PacketType.ObjectMaterial:
  5605. ObjectMaterialPacket ompacket = (ObjectMaterialPacket)Pack;
  5606. #region Packet Session and User Check
  5607. if (m_checkPackets)
  5608. {
  5609. if (ompacket.AgentData.SessionID != SessionId ||
  5610. ompacket.AgentData.AgentID != AgentId)
  5611. break;
  5612. }
  5613. #endregion
  5614. handlerObjectMaterial = OnObjectMaterial;
  5615. if (handlerObjectMaterial != null)
  5616. {
  5617. foreach (ObjectMaterialPacket.ObjectDataBlock odata in ompacket.ObjectData)
  5618. {
  5619. byte material = odata.Material;
  5620. uint localID = odata.ObjectLocalID;
  5621. handlerObjectMaterial(this, localID, material.ToString());
  5622. }
  5623. }
  5624. break;
  5625. #endregion
  5626. #region Inventory/Asset/Other related packets
  5627. case PacketType.RequestImage:
  5628. RequestImagePacket imageRequest = (RequestImagePacket)Pack;
  5629. //m_log.Debug("image request: " + Pack.ToString());
  5630. #region Packet Session and User Check
  5631. if (m_checkPackets)
  5632. {
  5633. if (imageRequest.AgentData.SessionID != SessionId ||
  5634. imageRequest.AgentData.AgentID != AgentId)
  5635. break;
  5636. }
  5637. #endregion
  5638. //handlerTextureRequest = null;
  5639. for (int i = 0; i < imageRequest.RequestImage.Length; i++)
  5640. {
  5641. if (OnRequestTexture != null)
  5642. {
  5643. TextureRequestArgs args = new TextureRequestArgs();
  5644. args.RequestedAssetID = imageRequest.RequestImage[i].Image;
  5645. args.DiscardLevel = imageRequest.RequestImage[i].DiscardLevel;
  5646. args.PacketNumber = imageRequest.RequestImage[i].Packet;
  5647. args.Priority = imageRequest.RequestImage[i].DownloadPriority;
  5648. args.requestSequence = imageRequest.Header.Sequence;
  5649. //handlerTextureRequest = OnRequestTexture;
  5650. //if (handlerTextureRequest != null)
  5651. //OnRequestTexture(this, args);
  5652. // in the end, we null this, so we have to check if it's null
  5653. if (m_imageManager != null)
  5654. {
  5655. m_imageManager.EnqueueReq(args);
  5656. m_textureRequestTimer.Start();
  5657. }
  5658. }
  5659. }
  5660. break;
  5661. case PacketType.TransferRequest:
  5662. //m_log.Debug("ClientView.ProcessPackets.cs:ProcessInPacket() - Got transfer request");
  5663. TransferRequestPacket transfer = (TransferRequestPacket)Pack;
  5664. //m_log.Debug("Transfer Request: " + transfer.ToString());
  5665. // Validate inventory transfers
  5666. // Has to be done here, because AssetCache can't do it
  5667. //
  5668. if (transfer.TransferInfo.SourceType == 3)
  5669. {
  5670. UUID taskID = new UUID(transfer.TransferInfo.Params, 48);
  5671. UUID itemID = new UUID(transfer.TransferInfo.Params, 64);
  5672. UUID requestID = new UUID(transfer.TransferInfo.Params, 80);
  5673. if (!(((Scene)m_scene).Permissions.BypassPermissions()))
  5674. {
  5675. if (taskID != UUID.Zero) // Prim
  5676. {
  5677. SceneObjectPart part = ((Scene)m_scene).GetSceneObjectPart(taskID);
  5678. if (part == null)
  5679. break;
  5680. if (part.OwnerID != AgentId)
  5681. break;
  5682. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  5683. break;
  5684. TaskInventoryItem ti = part.Inventory.GetInventoryItem(itemID);
  5685. if (ti == null)
  5686. break;
  5687. if (ti.OwnerID != AgentId)
  5688. break;
  5689. if ((ti.CurrentPermissions & ((uint)PermissionMask.Modify| (uint)PermissionMask.Copy | (uint)PermissionMask.Transfer)) != ((uint)PermissionMask.Modify| (uint)PermissionMask.Copy | (uint)PermissionMask.Transfer))
  5690. break;
  5691. if (ti.AssetID != requestID)
  5692. break;
  5693. }
  5694. else // Agent
  5695. {
  5696. CachedUserInfo userInfo = ((Scene)m_scene).CommsManager.UserProfileCacheService.GetUserDetails(AgentId);
  5697. if (userInfo == null)
  5698. {
  5699. m_log.ErrorFormat(
  5700. "[CLIENT]: Could not resolve user {0} for caps inventory update",
  5701. AgentId);
  5702. break;
  5703. }
  5704. if (userInfo.RootFolder == null)
  5705. break;
  5706. InventoryItemBase assetRequestItem = userInfo.RootFolder.FindItem(itemID);
  5707. if (assetRequestItem == null)
  5708. {
  5709. assetRequestItem = ((Scene)m_scene).CommsManager.UserProfileCacheService.LibraryRoot.FindItem(itemID);
  5710. if (assetRequestItem == null)
  5711. return;
  5712. }
  5713. // At this point, we need to apply perms
  5714. // only to notecards and scripts. All
  5715. // other asset types are always available
  5716. //
  5717. if (assetRequestItem.AssetType == 10)
  5718. {
  5719. if (!((Scene)m_scene).Permissions.CanViewScript(itemID, UUID.Zero, AgentId))
  5720. {
  5721. SendAgentAlertMessage("Insufficient permissions to view script", false);
  5722. break;
  5723. }
  5724. }
  5725. else if (assetRequestItem.AssetType == 7)
  5726. {
  5727. if (!((Scene)m_scene).Permissions.CanViewNotecard(itemID, UUID.Zero, AgentId))
  5728. {
  5729. SendAgentAlertMessage("Insufficient permissions to view notecard", false);
  5730. break;
  5731. }
  5732. }
  5733. if (assetRequestItem.AssetID != requestID)
  5734. break;
  5735. }
  5736. }
  5737. }
  5738. //m_assetCache.AddAssetRequest(this, transfer);
  5739. MakeAssetRequest(transfer);
  5740. /* RequestAsset = OnRequestAsset;
  5741. if (RequestAsset != null)
  5742. {
  5743. RequestAsset(this, transfer);
  5744. }*/
  5745. break;
  5746. case PacketType.AssetUploadRequest:
  5747. AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
  5748. // m_log.Debug("upload request " + request.ToString());
  5749. // m_log.Debug("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToString());
  5750. UUID temp = UUID.Combine(request.AssetBlock.TransactionID, SecureSessionId);
  5751. handlerAssetUploadRequest = OnAssetUploadRequest;
  5752. if (handlerAssetUploadRequest != null)
  5753. {
  5754. handlerAssetUploadRequest(this, temp,
  5755. request.AssetBlock.TransactionID, request.AssetBlock.Type,
  5756. request.AssetBlock.AssetData, request.AssetBlock.StoreLocal,
  5757. request.AssetBlock.Tempfile);
  5758. }
  5759. break;
  5760. case PacketType.RequestXfer:
  5761. RequestXferPacket xferReq = (RequestXferPacket)Pack;
  5762. handlerRequestXfer = OnRequestXfer;
  5763. if (handlerRequestXfer != null)
  5764. {
  5765. handlerRequestXfer(this, xferReq.XferID.ID, Util.FieldToString(xferReq.XferID.Filename));
  5766. }
  5767. break;
  5768. case PacketType.SendXferPacket:
  5769. SendXferPacketPacket xferRec = (SendXferPacketPacket)Pack;
  5770. handlerXferReceive = OnXferReceive;
  5771. if (handlerXferReceive != null)
  5772. {
  5773. handlerXferReceive(this, xferRec.XferID.ID, xferRec.XferID.Packet, xferRec.DataPacket.Data);
  5774. }
  5775. break;
  5776. case PacketType.ConfirmXferPacket:
  5777. ConfirmXferPacketPacket confirmXfer = (ConfirmXferPacketPacket)Pack;
  5778. handlerConfirmXfer = OnConfirmXfer;
  5779. if (handlerConfirmXfer != null)
  5780. {
  5781. handlerConfirmXfer(this, confirmXfer.XferID.ID, confirmXfer.XferID.Packet);
  5782. }
  5783. break;
  5784. case PacketType.AbortXfer:
  5785. AbortXferPacket abortXfer = (AbortXferPacket)Pack;
  5786. handlerAbortXfer = OnAbortXfer;
  5787. if (handlerAbortXfer != null)
  5788. {
  5789. handlerAbortXfer(this, abortXfer.XferID.ID);
  5790. }
  5791. break;
  5792. case PacketType.CreateInventoryFolder:
  5793. CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack;
  5794. #region Packet Session and User Check
  5795. if (m_checkPackets)
  5796. {
  5797. if (invFolder.AgentData.SessionID != SessionId ||
  5798. invFolder.AgentData.AgentID != AgentId)
  5799. break;
  5800. }
  5801. #endregion
  5802. handlerCreateInventoryFolder = OnCreateNewInventoryFolder;
  5803. if (handlerCreateInventoryFolder != null)
  5804. {
  5805. handlerCreateInventoryFolder(this, invFolder.FolderData.FolderID,
  5806. (ushort)invFolder.FolderData.Type,
  5807. Util.FieldToString(invFolder.FolderData.Name),
  5808. invFolder.FolderData.ParentID);
  5809. }
  5810. break;
  5811. case PacketType.UpdateInventoryFolder:
  5812. if (OnUpdateInventoryFolder != null)
  5813. {
  5814. UpdateInventoryFolderPacket invFolderx = (UpdateInventoryFolderPacket)Pack;
  5815. #region Packet Session and User Check
  5816. if (m_checkPackets)
  5817. {
  5818. if (invFolderx.AgentData.SessionID != SessionId ||
  5819. invFolderx.AgentData.AgentID != AgentId)
  5820. break;
  5821. }
  5822. #endregion
  5823. handlerUpdateInventoryFolder = null;
  5824. for (int i = 0; i < invFolderx.FolderData.Length; i++)
  5825. {
  5826. handlerUpdateInventoryFolder = OnUpdateInventoryFolder;
  5827. if (handlerUpdateInventoryFolder != null)
  5828. {
  5829. OnUpdateInventoryFolder(this, invFolderx.FolderData[i].FolderID,
  5830. (ushort)invFolderx.FolderData[i].Type,
  5831. Util.FieldToString(invFolderx.FolderData[i].Name),
  5832. invFolderx.FolderData[i].ParentID);
  5833. }
  5834. }
  5835. }
  5836. break;
  5837. case PacketType.MoveInventoryFolder:
  5838. if (OnMoveInventoryFolder != null)
  5839. {
  5840. MoveInventoryFolderPacket invFoldery = (MoveInventoryFolderPacket)Pack;
  5841. #region Packet Session and User Check
  5842. if (m_checkPackets)
  5843. {
  5844. if (invFoldery.AgentData.SessionID != SessionId ||
  5845. invFoldery.AgentData.AgentID != AgentId)
  5846. break;
  5847. }
  5848. #endregion
  5849. handlerMoveInventoryFolder = null;
  5850. for (int i = 0; i < invFoldery.InventoryData.Length; i++)
  5851. {
  5852. handlerMoveInventoryFolder = OnMoveInventoryFolder;
  5853. if (handlerMoveInventoryFolder != null)
  5854. {
  5855. OnMoveInventoryFolder(this, invFoldery.InventoryData[i].FolderID,
  5856. invFoldery.InventoryData[i].ParentID);
  5857. }
  5858. }
  5859. }
  5860. break;
  5861. case PacketType.CreateInventoryItem:
  5862. CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack;
  5863. #region Packet Session and User Check
  5864. if (m_checkPackets)
  5865. {
  5866. if (createItem.AgentData.SessionID != SessionId ||
  5867. createItem.AgentData.AgentID != AgentId)
  5868. break;
  5869. }
  5870. #endregion
  5871. handlerCreateNewInventoryItem = OnCreateNewInventoryItem;
  5872. if (handlerCreateNewInventoryItem != null)
  5873. {
  5874. handlerCreateNewInventoryItem(this, createItem.InventoryBlock.TransactionID,
  5875. createItem.InventoryBlock.FolderID,
  5876. createItem.InventoryBlock.CallbackID,
  5877. Util.FieldToString(createItem.InventoryBlock.Description),
  5878. Util.FieldToString(createItem.InventoryBlock.Name),
  5879. createItem.InventoryBlock.InvType,
  5880. createItem.InventoryBlock.Type,
  5881. createItem.InventoryBlock.WearableType,
  5882. createItem.InventoryBlock.NextOwnerMask,
  5883. Util.UnixTimeSinceEpoch());
  5884. }
  5885. break;
  5886. case PacketType.FetchInventory:
  5887. if (OnFetchInventory != null)
  5888. {
  5889. FetchInventoryPacket FetchInventoryx = (FetchInventoryPacket)Pack;
  5890. #region Packet Session and User Check
  5891. if (m_checkPackets)
  5892. {
  5893. if (FetchInventoryx.AgentData.SessionID != SessionId ||
  5894. FetchInventoryx.AgentData.AgentID != AgentId)
  5895. break;
  5896. }
  5897. #endregion
  5898. handlerFetchInventory = null;
  5899. for (int i = 0; i < FetchInventoryx.InventoryData.Length; i++)
  5900. {
  5901. handlerFetchInventory = OnFetchInventory;
  5902. if (handlerFetchInventory != null)
  5903. {
  5904. OnFetchInventory(this, FetchInventoryx.InventoryData[i].ItemID,
  5905. FetchInventoryx.InventoryData[i].OwnerID);
  5906. }
  5907. }
  5908. }
  5909. break;
  5910. case PacketType.FetchInventoryDescendents:
  5911. FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack;
  5912. #region Packet Session and User Check
  5913. if (m_checkPackets)
  5914. {
  5915. if (Fetch.AgentData.SessionID != SessionId ||
  5916. Fetch.AgentData.AgentID != AgentId)
  5917. break;
  5918. }
  5919. #endregion
  5920. handlerFetchInventoryDescendents = OnFetchInventoryDescendents;
  5921. if (handlerFetchInventoryDescendents != null)
  5922. {
  5923. handlerFetchInventoryDescendents(this, Fetch.InventoryData.FolderID, Fetch.InventoryData.OwnerID,
  5924. Fetch.InventoryData.FetchFolders, Fetch.InventoryData.FetchItems,
  5925. Fetch.InventoryData.SortOrder);
  5926. }
  5927. break;
  5928. case PacketType.PurgeInventoryDescendents:
  5929. PurgeInventoryDescendentsPacket Purge = (PurgeInventoryDescendentsPacket)Pack;
  5930. #region Packet Session and User Check
  5931. if (m_checkPackets)
  5932. {
  5933. if (Purge.AgentData.SessionID != SessionId ||
  5934. Purge.AgentData.AgentID != AgentId)
  5935. break;
  5936. }
  5937. #endregion
  5938. handlerPurgeInventoryDescendents = OnPurgeInventoryDescendents;
  5939. if (handlerPurgeInventoryDescendents != null)
  5940. {
  5941. handlerPurgeInventoryDescendents(this, Purge.InventoryData.FolderID);
  5942. }
  5943. break;
  5944. case PacketType.UpdateInventoryItem:
  5945. UpdateInventoryItemPacket inventoryItemUpdate = (UpdateInventoryItemPacket)Pack;
  5946. #region Packet Session and User Check
  5947. if (m_checkPackets)
  5948. {
  5949. if (inventoryItemUpdate.AgentData.SessionID != SessionId ||
  5950. inventoryItemUpdate.AgentData.AgentID != AgentId)
  5951. break;
  5952. }
  5953. #endregion
  5954. if (OnUpdateInventoryItem != null)
  5955. {
  5956. handlerUpdateInventoryItem = null;
  5957. for (int i = 0; i < inventoryItemUpdate.InventoryData.Length; i++)
  5958. {
  5959. handlerUpdateInventoryItem = OnUpdateInventoryItem;
  5960. if (handlerUpdateInventoryItem != null)
  5961. {
  5962. InventoryItemBase itemUpd = new InventoryItemBase();
  5963. itemUpd.ID = inventoryItemUpdate.InventoryData[i].ItemID;
  5964. itemUpd.Name = Util.FieldToString(inventoryItemUpdate.InventoryData[i].Name);
  5965. itemUpd.Description = Util.FieldToString(inventoryItemUpdate.InventoryData[i].Description);
  5966. itemUpd.GroupID = inventoryItemUpdate.InventoryData[i].GroupID;
  5967. itemUpd.GroupOwned = inventoryItemUpdate.InventoryData[i].GroupOwned;
  5968. itemUpd.GroupPermissions = inventoryItemUpdate.InventoryData[i].GroupMask;
  5969. itemUpd.NextPermissions = inventoryItemUpdate.InventoryData[i].NextOwnerMask;
  5970. itemUpd.EveryOnePermissions = inventoryItemUpdate.InventoryData[i].EveryoneMask;
  5971. itemUpd.CreationDate = inventoryItemUpdate.InventoryData[i].CreationDate;
  5972. itemUpd.Folder = inventoryItemUpdate.InventoryData[i].FolderID;
  5973. itemUpd.InvType = inventoryItemUpdate.InventoryData[i].InvType;
  5974. itemUpd.SalePrice = inventoryItemUpdate.InventoryData[i].SalePrice;
  5975. itemUpd.SaleType = inventoryItemUpdate.InventoryData[i].SaleType;
  5976. itemUpd.Flags = inventoryItemUpdate.InventoryData[i].Flags;
  5977. /*
  5978. OnUpdateInventoryItem(this, inventoryItemUpdate.InventoryData[i].TransactionID,
  5979. inventoryItemUpdate.InventoryData[i].ItemID,
  5980. Util.FieldToString(inventoryItemUpdate.InventoryData[i].Name),
  5981. Util.FieldToString(inventoryItemUpdate.InventoryData[i].Description),
  5982. inventoryItemUpdate.InventoryData[i].NextOwnerMask);
  5983. */
  5984. OnUpdateInventoryItem(this, inventoryItemUpdate.InventoryData[i].TransactionID,
  5985. inventoryItemUpdate.InventoryData[i].ItemID,
  5986. itemUpd);
  5987. }
  5988. }
  5989. }
  5990. //m_log.Debug(Pack.ToString());
  5991. /*for (int i = 0; i < inventoryItemUpdate.InventoryData.Length; i++)
  5992. {
  5993. if (inventoryItemUpdate.InventoryData[i].TransactionID != UUID.Zero)
  5994. {
  5995. AssetBase asset = m_assetCache.GetAsset(inventoryItemUpdate.InventoryData[i].TransactionID.Combine(this.SecureSessionId));
  5996. if (asset != null)
  5997. {
  5998. // m_log.Debug("updating inventory item, found asset" + asset.FullID.ToString() + " already in cache");
  5999. m_inventoryCache.UpdateInventoryItemAsset(this, inventoryItemUpdate.InventoryData[i].ItemID, asset);
  6000. }
  6001. else
  6002. {
  6003. asset = this.UploadAssets.AddUploadToAssetCache(inventoryItemUpdate.InventoryData[i].TransactionID);
  6004. if (asset != null)
  6005. {
  6006. //m_log.Debug("updating inventory item, adding asset" + asset.FullID.ToString() + " to cache");
  6007. m_inventoryCache.UpdateInventoryItemAsset(this, inventoryItemUpdate.InventoryData[i].ItemID, asset);
  6008. }
  6009. else
  6010. {
  6011. //m_log.Debug("trying to update inventory item, but asset is null");
  6012. }
  6013. }
  6014. }
  6015. else
  6016. {
  6017. m_inventoryCache.UpdateInventoryItemDetails(this, inventoryItemUpdate.InventoryData[i].ItemID, inventoryItemUpdate.InventoryData[i]); ;
  6018. }
  6019. }*/
  6020. break;
  6021. case PacketType.CopyInventoryItem:
  6022. CopyInventoryItemPacket copyitem = (CopyInventoryItemPacket)Pack;
  6023. #region Packet Session and User Check
  6024. if (m_checkPackets)
  6025. {
  6026. if (copyitem.AgentData.SessionID != SessionId ||
  6027. copyitem.AgentData.AgentID != AgentId)
  6028. break;
  6029. }
  6030. #endregion
  6031. handlerCopyInventoryItem = null;
  6032. if (OnCopyInventoryItem != null)
  6033. {
  6034. foreach (CopyInventoryItemPacket.InventoryDataBlock datablock in copyitem.InventoryData)
  6035. {
  6036. handlerCopyInventoryItem = OnCopyInventoryItem;
  6037. if (handlerCopyInventoryItem != null)
  6038. {
  6039. handlerCopyInventoryItem(this, datablock.CallbackID, datablock.OldAgentID,
  6040. datablock.OldItemID, datablock.NewFolderID,
  6041. Util.FieldToString(datablock.NewName));
  6042. }
  6043. }
  6044. }
  6045. break;
  6046. case PacketType.MoveInventoryItem:
  6047. MoveInventoryItemPacket moveitem = (MoveInventoryItemPacket)Pack;
  6048. #region Packet Session and User Check
  6049. if (m_checkPackets)
  6050. {
  6051. if (moveitem.AgentData.SessionID != SessionId ||
  6052. moveitem.AgentData.AgentID != AgentId)
  6053. break;
  6054. }
  6055. #endregion
  6056. if (OnMoveInventoryItem != null)
  6057. {
  6058. handlerMoveInventoryItem = null;
  6059. foreach (MoveInventoryItemPacket.InventoryDataBlock datablock in moveitem.InventoryData)
  6060. {
  6061. handlerMoveInventoryItem = OnMoveInventoryItem;
  6062. if (handlerMoveInventoryItem != null)
  6063. {
  6064. handlerMoveInventoryItem(this, datablock.FolderID, datablock.ItemID, datablock.Length,
  6065. Util.FieldToString(datablock.NewName));
  6066. }
  6067. }
  6068. }
  6069. break;
  6070. case PacketType.RemoveInventoryItem:
  6071. RemoveInventoryItemPacket removeItem = (RemoveInventoryItemPacket)Pack;
  6072. #region Packet Session and User Check
  6073. if (m_checkPackets)
  6074. {
  6075. if (removeItem.AgentData.SessionID != SessionId ||
  6076. removeItem.AgentData.AgentID != AgentId)
  6077. break;
  6078. }
  6079. #endregion
  6080. if (OnRemoveInventoryItem != null)
  6081. {
  6082. handlerRemoveInventoryItem = null;
  6083. foreach (RemoveInventoryItemPacket.InventoryDataBlock datablock in removeItem.InventoryData)
  6084. {
  6085. handlerRemoveInventoryItem = OnRemoveInventoryItem;
  6086. if (handlerRemoveInventoryItem != null)
  6087. {
  6088. handlerRemoveInventoryItem(this, datablock.ItemID);
  6089. }
  6090. }
  6091. }
  6092. break;
  6093. case PacketType.RemoveInventoryFolder:
  6094. RemoveInventoryFolderPacket removeFolder = (RemoveInventoryFolderPacket)Pack;
  6095. #region Packet Session and User Check
  6096. if (m_checkPackets)
  6097. {
  6098. if (removeFolder.AgentData.SessionID != SessionId ||
  6099. removeFolder.AgentData.AgentID != AgentId)
  6100. break;
  6101. }
  6102. #endregion
  6103. if (OnRemoveInventoryFolder != null)
  6104. {
  6105. handlerRemoveInventoryFolder = null;
  6106. foreach (RemoveInventoryFolderPacket.FolderDataBlock datablock in removeFolder.FolderData)
  6107. {
  6108. handlerRemoveInventoryFolder = OnRemoveInventoryFolder;
  6109. if (handlerRemoveInventoryFolder != null)
  6110. {
  6111. handlerRemoveInventoryFolder(this, datablock.FolderID);
  6112. }
  6113. }
  6114. }
  6115. break;
  6116. case PacketType.RemoveInventoryObjects:
  6117. RemoveInventoryObjectsPacket removeObject = (RemoveInventoryObjectsPacket)Pack;
  6118. #region Packet Session and User Check
  6119. if (m_checkPackets)
  6120. {
  6121. if (removeObject.AgentData.SessionID != SessionId ||
  6122. removeObject.AgentData.AgentID != AgentId)
  6123. break;
  6124. }
  6125. #endregion
  6126. if (OnRemoveInventoryFolder != null)
  6127. {
  6128. handlerRemoveInventoryFolder = null;
  6129. foreach (RemoveInventoryObjectsPacket.FolderDataBlock datablock in removeObject.FolderData)
  6130. {
  6131. handlerRemoveInventoryFolder = OnRemoveInventoryFolder;
  6132. if (handlerRemoveInventoryFolder != null)
  6133. {
  6134. handlerRemoveInventoryFolder(this, datablock.FolderID);
  6135. }
  6136. }
  6137. }
  6138. if (OnRemoveInventoryItem != null)
  6139. {
  6140. handlerRemoveInventoryItem = null;
  6141. foreach (RemoveInventoryObjectsPacket.ItemDataBlock datablock in removeObject.ItemData)
  6142. {
  6143. handlerRemoveInventoryItem = OnRemoveInventoryItem;
  6144. if (handlerRemoveInventoryItem != null)
  6145. {
  6146. handlerRemoveInventoryItem(this, datablock.ItemID);
  6147. }
  6148. }
  6149. }
  6150. break;
  6151. case PacketType.RequestTaskInventory:
  6152. RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
  6153. #region Packet Session and User Check
  6154. if (m_checkPackets)
  6155. {
  6156. if (requesttask.AgentData.SessionID != SessionId ||
  6157. requesttask.AgentData.AgentID != AgentId)
  6158. break;
  6159. }
  6160. #endregion
  6161. handlerRequestTaskInventory = OnRequestTaskInventory;
  6162. if (handlerRequestTaskInventory != null)
  6163. {
  6164. handlerRequestTaskInventory(this, requesttask.InventoryData.LocalID);
  6165. }
  6166. break;
  6167. case PacketType.UpdateTaskInventory:
  6168. UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
  6169. #region Packet Session and User Check
  6170. if (m_checkPackets)
  6171. {
  6172. if (updatetask.AgentData.SessionID != SessionId ||
  6173. updatetask.AgentData.AgentID != AgentId)
  6174. break;
  6175. }
  6176. #endregion
  6177. if (OnUpdateTaskInventory != null)
  6178. {
  6179. if (updatetask.UpdateData.Key == 0)
  6180. {
  6181. handlerUpdateTaskInventory = OnUpdateTaskInventory;
  6182. if (handlerUpdateTaskInventory != null)
  6183. {
  6184. TaskInventoryItem newTaskItem = new TaskInventoryItem();
  6185. newTaskItem.ItemID = updatetask.InventoryData.ItemID;
  6186. newTaskItem.ParentID = updatetask.InventoryData.FolderID;
  6187. newTaskItem.CreatorID = updatetask.InventoryData.CreatorID;
  6188. newTaskItem.OwnerID = updatetask.InventoryData.OwnerID;
  6189. newTaskItem.GroupID = updatetask.InventoryData.GroupID;
  6190. newTaskItem.BasePermissions = updatetask.InventoryData.BaseMask;
  6191. newTaskItem.CurrentPermissions = updatetask.InventoryData.OwnerMask;
  6192. newTaskItem.GroupPermissions = updatetask.InventoryData.GroupMask;
  6193. newTaskItem.EveryonePermissions = updatetask.InventoryData.EveryoneMask;
  6194. newTaskItem.NextPermissions = updatetask.InventoryData.NextOwnerMask;
  6195. //newTaskItem.GroupOwned=updatetask.InventoryData.GroupOwned;
  6196. newTaskItem.Type = updatetask.InventoryData.Type;
  6197. newTaskItem.InvType = updatetask.InventoryData.InvType;
  6198. newTaskItem.Flags = updatetask.InventoryData.Flags;
  6199. //newTaskItem.SaleType=updatetask.InventoryData.SaleType;
  6200. //newTaskItem.SalePrice=updatetask.InventoryData.SalePrice;;
  6201. newTaskItem.Name = Util.FieldToString(updatetask.InventoryData.Name);
  6202. newTaskItem.Description = Util.FieldToString(updatetask.InventoryData.Description);
  6203. newTaskItem.CreationDate = (uint)updatetask.InventoryData.CreationDate;
  6204. handlerUpdateTaskInventory(this, updatetask.InventoryData.TransactionID,
  6205. newTaskItem, updatetask.UpdateData.LocalID);
  6206. }
  6207. }
  6208. }
  6209. break;
  6210. case PacketType.RemoveTaskInventory:
  6211. RemoveTaskInventoryPacket removeTask = (RemoveTaskInventoryPacket)Pack;
  6212. #region Packet Session and User Check
  6213. if (m_checkPackets)
  6214. {
  6215. if (removeTask.AgentData.SessionID != SessionId ||
  6216. removeTask.AgentData.AgentID != AgentId)
  6217. break;
  6218. }
  6219. #endregion
  6220. handlerRemoveTaskItem = OnRemoveTaskItem;
  6221. if (handlerRemoveTaskItem != null)
  6222. {
  6223. handlerRemoveTaskItem(this, removeTask.InventoryData.ItemID, removeTask.InventoryData.LocalID);
  6224. }
  6225. break;
  6226. case PacketType.MoveTaskInventory:
  6227. MoveTaskInventoryPacket moveTaskInventoryPacket = (MoveTaskInventoryPacket)Pack;
  6228. #region Packet Session and User Check
  6229. if (m_checkPackets)
  6230. {
  6231. if (moveTaskInventoryPacket.AgentData.SessionID != SessionId ||
  6232. moveTaskInventoryPacket.AgentData.AgentID != AgentId)
  6233. break;
  6234. }
  6235. #endregion
  6236. handlerMoveTaskItem = OnMoveTaskItem;
  6237. if (handlerMoveTaskItem != null)
  6238. {
  6239. handlerMoveTaskItem(
  6240. this, moveTaskInventoryPacket.AgentData.FolderID,
  6241. moveTaskInventoryPacket.InventoryData.LocalID,
  6242. moveTaskInventoryPacket.InventoryData.ItemID);
  6243. }
  6244. break;
  6245. case PacketType.RezScript:
  6246. //m_log.Debug(Pack.ToString());
  6247. RezScriptPacket rezScriptx = (RezScriptPacket)Pack;
  6248. #region Packet Session and User Check
  6249. if (m_checkPackets)
  6250. {
  6251. if (rezScriptx.AgentData.SessionID != SessionId ||
  6252. rezScriptx.AgentData.AgentID != AgentId)
  6253. break;
  6254. }
  6255. #endregion
  6256. handlerRezScript = OnRezScript;
  6257. InventoryItemBase item = new InventoryItemBase();
  6258. item.ID = rezScriptx.InventoryBlock.ItemID;
  6259. item.Folder = rezScriptx.InventoryBlock.FolderID;
  6260. item.CreatorId = rezScriptx.InventoryBlock.CreatorID.ToString();
  6261. item.Owner = rezScriptx.InventoryBlock.OwnerID;
  6262. item.BasePermissions = rezScriptx.InventoryBlock.BaseMask;
  6263. item.CurrentPermissions = rezScriptx.InventoryBlock.OwnerMask;
  6264. item.EveryOnePermissions = rezScriptx.InventoryBlock.EveryoneMask;
  6265. item.NextPermissions = rezScriptx.InventoryBlock.NextOwnerMask;
  6266. item.GroupPermissions = rezScriptx.InventoryBlock.GroupMask;
  6267. item.GroupOwned = rezScriptx.InventoryBlock.GroupOwned;
  6268. item.GroupID = rezScriptx.InventoryBlock.GroupID;
  6269. item.AssetType = rezScriptx.InventoryBlock.Type;
  6270. item.InvType = rezScriptx.InventoryBlock.InvType;
  6271. item.Flags = rezScriptx.InventoryBlock.Flags;
  6272. item.SaleType = rezScriptx.InventoryBlock.SaleType;
  6273. item.SalePrice = rezScriptx.InventoryBlock.SalePrice;
  6274. item.Name = Util.FieldToString(rezScriptx.InventoryBlock.Name);
  6275. item.Description = Util.FieldToString(rezScriptx.InventoryBlock.Description);
  6276. item.CreationDate = rezScriptx.InventoryBlock.CreationDate;
  6277. if (handlerRezScript != null)
  6278. {
  6279. handlerRezScript(this, item, rezScriptx.InventoryBlock.TransactionID, rezScriptx.UpdateBlock.ObjectLocalID);
  6280. }
  6281. break;
  6282. case PacketType.MapLayerRequest:
  6283. RequestMapLayer();
  6284. break;
  6285. case PacketType.MapBlockRequest:
  6286. MapBlockRequestPacket MapRequest = (MapBlockRequestPacket)Pack;
  6287. #region Packet Session and User Check
  6288. if (m_checkPackets)
  6289. {
  6290. if (MapRequest.AgentData.SessionID != SessionId ||
  6291. MapRequest.AgentData.AgentID != AgentId)
  6292. break;
  6293. }
  6294. #endregion
  6295. handlerRequestMapBlocks = OnRequestMapBlocks;
  6296. if (handlerRequestMapBlocks != null)
  6297. {
  6298. handlerRequestMapBlocks(this, MapRequest.PositionData.MinX, MapRequest.PositionData.MinY,
  6299. MapRequest.PositionData.MaxX, MapRequest.PositionData.MaxY, MapRequest.AgentData.Flags);
  6300. }
  6301. break;
  6302. case PacketType.MapNameRequest:
  6303. MapNameRequestPacket map = (MapNameRequestPacket)Pack;
  6304. #region Packet Session and User Check
  6305. if (m_checkPackets)
  6306. {
  6307. if (map.AgentData.SessionID != SessionId ||
  6308. map.AgentData.AgentID != AgentId)
  6309. break;
  6310. }
  6311. #endregion
  6312. string mapName = Encoding.UTF8.GetString(map.NameData.Name, 0,
  6313. map.NameData.Name.Length - 1);
  6314. handlerMapNameRequest = OnMapNameRequest;
  6315. if (handlerMapNameRequest != null)
  6316. {
  6317. handlerMapNameRequest(this, mapName);
  6318. }
  6319. break;
  6320. case PacketType.TeleportLandmarkRequest:
  6321. TeleportLandmarkRequestPacket tpReq = (TeleportLandmarkRequestPacket)Pack;
  6322. #region Packet Session and User Check
  6323. if (m_checkPackets)
  6324. {
  6325. if (tpReq.Info.SessionID != SessionId ||
  6326. tpReq.Info.AgentID != AgentId)
  6327. break;
  6328. }
  6329. #endregion
  6330. UUID lmid = tpReq.Info.LandmarkID;
  6331. AssetLandmark lm;
  6332. if (lmid != UUID.Zero)
  6333. {
  6334. //AssetBase lma = m_assetCache.GetAsset(lmid, false);
  6335. AssetBase lma = m_assetService.Get(lmid.ToString());
  6336. if (lma == null)
  6337. {
  6338. // Failed to find landmark
  6339. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  6340. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  6341. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  6342. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  6343. }
  6344. try
  6345. {
  6346. lm = new AssetLandmark(lma);
  6347. }
  6348. catch (NullReferenceException)
  6349. {
  6350. // asset not found generates null ref inside the assetlandmark constructor.
  6351. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  6352. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  6353. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  6354. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  6355. break;
  6356. }
  6357. }
  6358. else
  6359. {
  6360. // Teleport home request
  6361. handlerTeleportHomeRequest = OnTeleportHomeRequest;
  6362. if (handlerTeleportHomeRequest != null)
  6363. {
  6364. handlerTeleportHomeRequest(AgentId, this);
  6365. }
  6366. break;
  6367. }
  6368. handlerTeleportLandmarkRequest = OnTeleportLandmarkRequest;
  6369. if (handlerTeleportLandmarkRequest != null)
  6370. {
  6371. handlerTeleportLandmarkRequest(this, lm.RegionID, lm.Position);
  6372. }
  6373. else
  6374. {
  6375. //no event handler so cancel request
  6376. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  6377. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  6378. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  6379. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  6380. }
  6381. break;
  6382. case PacketType.TeleportLocationRequest:
  6383. TeleportLocationRequestPacket tpLocReq = (TeleportLocationRequestPacket)Pack;
  6384. // m_log.Debug(tpLocReq.ToString());
  6385. #region Packet Session and User Check
  6386. if (m_checkPackets)
  6387. {
  6388. if (tpLocReq.AgentData.SessionID != SessionId ||
  6389. tpLocReq.AgentData.AgentID != AgentId)
  6390. break;
  6391. }
  6392. #endregion
  6393. handlerTeleportLocationRequest = OnTeleportLocationRequest;
  6394. if (handlerTeleportLocationRequest != null)
  6395. {
  6396. handlerTeleportLocationRequest(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position,
  6397. tpLocReq.Info.LookAt, 16);
  6398. }
  6399. else
  6400. {
  6401. //no event handler so cancel request
  6402. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  6403. tpCancel.Info.SessionID = tpLocReq.AgentData.SessionID;
  6404. tpCancel.Info.AgentID = tpLocReq.AgentData.AgentID;
  6405. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  6406. }
  6407. break;
  6408. #endregion
  6409. case PacketType.UUIDNameRequest:
  6410. UUIDNameRequestPacket incoming = (UUIDNameRequestPacket)Pack;
  6411. foreach (UUIDNameRequestPacket.UUIDNameBlockBlock UUIDBlock in incoming.UUIDNameBlock)
  6412. {
  6413. handlerNameRequest = OnNameFromUUIDRequest;
  6414. if (handlerNameRequest != null)
  6415. {
  6416. handlerNameRequest(UUIDBlock.ID, this);
  6417. }
  6418. }
  6419. break;
  6420. #region Parcel related packets
  6421. case PacketType.RegionHandleRequest:
  6422. RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack;
  6423. handlerRegionHandleRequest = OnRegionHandleRequest;
  6424. if (handlerRegionHandleRequest != null)
  6425. {
  6426. handlerRegionHandleRequest(this, rhrPack.RequestBlock.RegionID);
  6427. }
  6428. break;
  6429. case PacketType.ParcelInfoRequest:
  6430. ParcelInfoRequestPacket pirPack = (ParcelInfoRequestPacket)Pack;
  6431. #region Packet Session and User Check
  6432. if (m_checkPackets)
  6433. {
  6434. if (pirPack.AgentData.SessionID != SessionId ||
  6435. pirPack.AgentData.AgentID != AgentId)
  6436. break;
  6437. }
  6438. #endregion
  6439. handlerParcelInfoRequest = OnParcelInfoRequest;
  6440. if (handlerParcelInfoRequest != null)
  6441. {
  6442. handlerParcelInfoRequest(this, pirPack.Data.ParcelID);
  6443. }
  6444. break;
  6445. case PacketType.ParcelAccessListRequest:
  6446. ParcelAccessListRequestPacket requestPacket = (ParcelAccessListRequestPacket)Pack;
  6447. #region Packet Session and User Check
  6448. if (m_checkPackets)
  6449. {
  6450. if (requestPacket.AgentData.SessionID != SessionId ||
  6451. requestPacket.AgentData.AgentID != AgentId)
  6452. break;
  6453. }
  6454. #endregion
  6455. handlerParcelAccessListRequest = OnParcelAccessListRequest;
  6456. if (handlerParcelAccessListRequest != null)
  6457. {
  6458. handlerParcelAccessListRequest(requestPacket.AgentData.AgentID, requestPacket.AgentData.SessionID,
  6459. requestPacket.Data.Flags, requestPacket.Data.SequenceID,
  6460. requestPacket.Data.LocalID, this);
  6461. }
  6462. break;
  6463. case PacketType.ParcelAccessListUpdate:
  6464. ParcelAccessListUpdatePacket updatePacket = (ParcelAccessListUpdatePacket)Pack;
  6465. #region Packet Session and User Check
  6466. if (m_checkPackets)
  6467. {
  6468. if (updatePacket.AgentData.SessionID != SessionId ||
  6469. updatePacket.AgentData.AgentID != AgentId)
  6470. break;
  6471. }
  6472. #endregion
  6473. List<ParcelManager.ParcelAccessEntry> entries = new List<ParcelManager.ParcelAccessEntry>();
  6474. foreach (ParcelAccessListUpdatePacket.ListBlock block in updatePacket.List)
  6475. {
  6476. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  6477. entry.AgentID = block.ID;
  6478. entry.Flags = (AccessList)block.Flags;
  6479. entry.Time = new DateTime();
  6480. entries.Add(entry);
  6481. }
  6482. handlerParcelAccessListUpdateRequest = OnParcelAccessListUpdateRequest;
  6483. if (handlerParcelAccessListUpdateRequest != null)
  6484. {
  6485. handlerParcelAccessListUpdateRequest(updatePacket.AgentData.AgentID,
  6486. updatePacket.AgentData.SessionID, updatePacket.Data.Flags,
  6487. updatePacket.Data.LocalID, entries, this);
  6488. }
  6489. break;
  6490. case PacketType.ParcelPropertiesRequest:
  6491. ParcelPropertiesRequestPacket propertiesRequest = (ParcelPropertiesRequestPacket)Pack;
  6492. #region Packet Session and User Check
  6493. if (m_checkPackets)
  6494. {
  6495. if (propertiesRequest.AgentData.SessionID != SessionId ||
  6496. propertiesRequest.AgentData.AgentID != AgentId)
  6497. break;
  6498. }
  6499. #endregion
  6500. handlerParcelPropertiesRequest = OnParcelPropertiesRequest;
  6501. if (handlerParcelPropertiesRequest != null)
  6502. {
  6503. handlerParcelPropertiesRequest((int)Math.Round(propertiesRequest.ParcelData.West),
  6504. (int)Math.Round(propertiesRequest.ParcelData.South),
  6505. (int)Math.Round(propertiesRequest.ParcelData.East),
  6506. (int)Math.Round(propertiesRequest.ParcelData.North),
  6507. propertiesRequest.ParcelData.SequenceID,
  6508. propertiesRequest.ParcelData.SnapSelection, this);
  6509. }
  6510. break;
  6511. case PacketType.ParcelDivide:
  6512. ParcelDividePacket landDivide = (ParcelDividePacket)Pack;
  6513. #region Packet Session and User Check
  6514. if (m_checkPackets)
  6515. {
  6516. if (landDivide.AgentData.SessionID != SessionId ||
  6517. landDivide.AgentData.AgentID != AgentId)
  6518. break;
  6519. }
  6520. #endregion
  6521. handlerParcelDivideRequest = OnParcelDivideRequest;
  6522. if (handlerParcelDivideRequest != null)
  6523. {
  6524. handlerParcelDivideRequest((int)Math.Round(landDivide.ParcelData.West),
  6525. (int)Math.Round(landDivide.ParcelData.South),
  6526. (int)Math.Round(landDivide.ParcelData.East),
  6527. (int)Math.Round(landDivide.ParcelData.North), this);
  6528. }
  6529. break;
  6530. case PacketType.ParcelJoin:
  6531. ParcelJoinPacket landJoin = (ParcelJoinPacket)Pack;
  6532. #region Packet Session and User Check
  6533. if (m_checkPackets)
  6534. {
  6535. if (landJoin.AgentData.SessionID != SessionId ||
  6536. landJoin.AgentData.AgentID != AgentId)
  6537. break;
  6538. }
  6539. #endregion
  6540. handlerParcelJoinRequest = OnParcelJoinRequest;
  6541. if (handlerParcelJoinRequest != null)
  6542. {
  6543. handlerParcelJoinRequest((int)Math.Round(landJoin.ParcelData.West),
  6544. (int)Math.Round(landJoin.ParcelData.South),
  6545. (int)Math.Round(landJoin.ParcelData.East),
  6546. (int)Math.Round(landJoin.ParcelData.North), this);
  6547. }
  6548. break;
  6549. case PacketType.ParcelPropertiesUpdate:
  6550. ParcelPropertiesUpdatePacket parcelPropertiesPacket = (ParcelPropertiesUpdatePacket)Pack;
  6551. #region Packet Session and User Check
  6552. if (m_checkPackets)
  6553. {
  6554. if (parcelPropertiesPacket.AgentData.SessionID != SessionId ||
  6555. parcelPropertiesPacket.AgentData.AgentID != AgentId)
  6556. break;
  6557. }
  6558. #endregion
  6559. handlerParcelPropertiesUpdateRequest = OnParcelPropertiesUpdateRequest;
  6560. if (handlerParcelPropertiesUpdateRequest != null)
  6561. {
  6562. LandUpdateArgs args = new LandUpdateArgs();
  6563. args.AuthBuyerID = parcelPropertiesPacket.ParcelData.AuthBuyerID;
  6564. args.Category = (ParcelCategory)parcelPropertiesPacket.ParcelData.Category;
  6565. args.Desc = Utils.BytesToString(parcelPropertiesPacket.ParcelData.Desc);
  6566. args.GroupID = parcelPropertiesPacket.ParcelData.GroupID;
  6567. args.LandingType = parcelPropertiesPacket.ParcelData.LandingType;
  6568. args.MediaAutoScale = parcelPropertiesPacket.ParcelData.MediaAutoScale;
  6569. args.MediaID = parcelPropertiesPacket.ParcelData.MediaID;
  6570. args.MediaURL = Utils.BytesToString(parcelPropertiesPacket.ParcelData.MediaURL);
  6571. args.MusicURL = Utils.BytesToString(parcelPropertiesPacket.ParcelData.MusicURL);
  6572. args.Name = Utils.BytesToString(parcelPropertiesPacket.ParcelData.Name);
  6573. args.ParcelFlags = parcelPropertiesPacket.ParcelData.ParcelFlags;
  6574. args.PassHours = parcelPropertiesPacket.ParcelData.PassHours;
  6575. args.PassPrice = parcelPropertiesPacket.ParcelData.PassPrice;
  6576. args.SalePrice = parcelPropertiesPacket.ParcelData.SalePrice;
  6577. args.SnapshotID = parcelPropertiesPacket.ParcelData.SnapshotID;
  6578. args.UserLocation = parcelPropertiesPacket.ParcelData.UserLocation;
  6579. args.UserLookAt = parcelPropertiesPacket.ParcelData.UserLookAt;
  6580. handlerParcelPropertiesUpdateRequest(args, parcelPropertiesPacket.ParcelData.LocalID, this);
  6581. }
  6582. break;
  6583. case PacketType.ParcelSelectObjects:
  6584. ParcelSelectObjectsPacket selectPacket = (ParcelSelectObjectsPacket)Pack;
  6585. #region Packet Session and User Check
  6586. if (m_checkPackets)
  6587. {
  6588. if (selectPacket.AgentData.SessionID != SessionId ||
  6589. selectPacket.AgentData.AgentID != AgentId)
  6590. break;
  6591. }
  6592. #endregion
  6593. List<UUID> returnIDs = new List<UUID>();
  6594. foreach (ParcelSelectObjectsPacket.ReturnIDsBlock rb in
  6595. selectPacket.ReturnIDs)
  6596. {
  6597. returnIDs.Add(rb.ReturnID);
  6598. }
  6599. handlerParcelSelectObjects = OnParcelSelectObjects;
  6600. if (handlerParcelSelectObjects != null)
  6601. {
  6602. handlerParcelSelectObjects(selectPacket.ParcelData.LocalID,
  6603. Convert.ToInt32(selectPacket.ParcelData.ReturnType), returnIDs, this);
  6604. }
  6605. break;
  6606. case PacketType.ParcelObjectOwnersRequest:
  6607. //m_log.Debug(Pack.ToString());
  6608. ParcelObjectOwnersRequestPacket reqPacket = (ParcelObjectOwnersRequestPacket)Pack;
  6609. #region Packet Session and User Check
  6610. if (m_checkPackets)
  6611. {
  6612. if (reqPacket.AgentData.SessionID != SessionId ||
  6613. reqPacket.AgentData.AgentID != AgentId)
  6614. break;
  6615. }
  6616. #endregion
  6617. handlerParcelObjectOwnerRequest = OnParcelObjectOwnerRequest;
  6618. if (handlerParcelObjectOwnerRequest != null)
  6619. {
  6620. handlerParcelObjectOwnerRequest(reqPacket.ParcelData.LocalID, this);
  6621. }
  6622. break;
  6623. case PacketType.ParcelGodForceOwner:
  6624. ParcelGodForceOwnerPacket godForceOwnerPacket = (ParcelGodForceOwnerPacket)Pack;
  6625. #region Packet Session and User Check
  6626. if (m_checkPackets)
  6627. {
  6628. if (godForceOwnerPacket.AgentData.SessionID != SessionId ||
  6629. godForceOwnerPacket.AgentData.AgentID != AgentId)
  6630. break;
  6631. }
  6632. #endregion
  6633. handlerParcelGodForceOwner = OnParcelGodForceOwner;
  6634. if (handlerParcelGodForceOwner != null)
  6635. {
  6636. handlerParcelGodForceOwner(godForceOwnerPacket.Data.LocalID, godForceOwnerPacket.Data.OwnerID, this);
  6637. }
  6638. break;
  6639. case PacketType.ParcelRelease:
  6640. ParcelReleasePacket releasePacket = (ParcelReleasePacket)Pack;
  6641. #region Packet Session and User Check
  6642. if (m_checkPackets)
  6643. {
  6644. if (releasePacket.AgentData.SessionID != SessionId ||
  6645. releasePacket.AgentData.AgentID != AgentId)
  6646. break;
  6647. }
  6648. #endregion
  6649. handlerParcelAbandonRequest = OnParcelAbandonRequest;
  6650. if (handlerParcelAbandonRequest != null)
  6651. {
  6652. handlerParcelAbandonRequest(releasePacket.Data.LocalID, this);
  6653. }
  6654. break;
  6655. case PacketType.ParcelReclaim:
  6656. ParcelReclaimPacket reclaimPacket = (ParcelReclaimPacket)Pack;
  6657. #region Packet Session and User Check
  6658. if (m_checkPackets)
  6659. {
  6660. if (reclaimPacket.AgentData.SessionID != SessionId ||
  6661. reclaimPacket.AgentData.AgentID != AgentId)
  6662. break;
  6663. }
  6664. #endregion
  6665. handlerParcelReclaim = OnParcelReclaim;
  6666. if (handlerParcelReclaim != null)
  6667. {
  6668. handlerParcelReclaim(reclaimPacket.Data.LocalID, this);
  6669. }
  6670. break;
  6671. case PacketType.ParcelReturnObjects:
  6672. ParcelReturnObjectsPacket parcelReturnObjects = (ParcelReturnObjectsPacket)Pack;
  6673. #region Packet Session and User Check
  6674. if (m_checkPackets)
  6675. {
  6676. if (parcelReturnObjects.AgentData.SessionID != SessionId ||
  6677. parcelReturnObjects.AgentData.AgentID != AgentId)
  6678. break;
  6679. }
  6680. #endregion
  6681. UUID[] puserselectedOwnerIDs = new UUID[parcelReturnObjects.OwnerIDs.Length];
  6682. for (int parceliterator = 0; parceliterator < parcelReturnObjects.OwnerIDs.Length; parceliterator++)
  6683. puserselectedOwnerIDs[parceliterator] = parcelReturnObjects.OwnerIDs[parceliterator].OwnerID;
  6684. UUID[] puserselectedTaskIDs = new UUID[parcelReturnObjects.TaskIDs.Length];
  6685. for (int parceliterator = 0; parceliterator < parcelReturnObjects.TaskIDs.Length; parceliterator++)
  6686. puserselectedTaskIDs[parceliterator] = parcelReturnObjects.TaskIDs[parceliterator].TaskID;
  6687. handlerParcelReturnObjectsRequest = OnParcelReturnObjectsRequest;
  6688. if (handlerParcelReturnObjectsRequest != null)
  6689. {
  6690. handlerParcelReturnObjectsRequest(parcelReturnObjects.ParcelData.LocalID, parcelReturnObjects.ParcelData.ReturnType, puserselectedOwnerIDs, puserselectedTaskIDs, this);
  6691. }
  6692. break;
  6693. case PacketType.ParcelSetOtherCleanTime:
  6694. ParcelSetOtherCleanTimePacket parcelSetOtherCleanTimePacket = (ParcelSetOtherCleanTimePacket)Pack;
  6695. #region Packet Session and User Check
  6696. if (m_checkPackets)
  6697. {
  6698. if (parcelSetOtherCleanTimePacket.AgentData.SessionID != SessionId ||
  6699. parcelSetOtherCleanTimePacket.AgentData.AgentID != AgentId)
  6700. break;
  6701. }
  6702. #endregion
  6703. handlerParcelSetOtherCleanTime = OnParcelSetOtherCleanTime;
  6704. if (handlerParcelSetOtherCleanTime != null)
  6705. {
  6706. handlerParcelSetOtherCleanTime(this,
  6707. parcelSetOtherCleanTimePacket.ParcelData.LocalID,
  6708. parcelSetOtherCleanTimePacket.ParcelData.OtherCleanTime);
  6709. }
  6710. break;
  6711. case PacketType.LandStatRequest:
  6712. LandStatRequestPacket lsrp = (LandStatRequestPacket)Pack;
  6713. #region Packet Session and User Check
  6714. if (m_checkPackets)
  6715. {
  6716. if (lsrp.AgentData.SessionID != SessionId ||
  6717. lsrp.AgentData.AgentID != AgentId)
  6718. break;
  6719. }
  6720. #endregion
  6721. handlerLandStatRequest = OnLandStatRequest;
  6722. if (handlerLandStatRequest != null)
  6723. {
  6724. handlerLandStatRequest(lsrp.RequestData.ParcelLocalID, lsrp.RequestData.ReportType, lsrp.RequestData.RequestFlags, Utils.BytesToString(lsrp.RequestData.Filter), this);
  6725. }
  6726. break;
  6727. case PacketType.ParcelDwellRequest:
  6728. ParcelDwellRequestPacket dwellrq =
  6729. (ParcelDwellRequestPacket)Pack;
  6730. #region Packet Session and User Check
  6731. if (m_checkPackets)
  6732. {
  6733. if (dwellrq.AgentData.SessionID != SessionId ||
  6734. dwellrq.AgentData.AgentID != AgentId)
  6735. break;
  6736. }
  6737. #endregion
  6738. handlerParcelDwellRequest = OnParcelDwellRequest;
  6739. if (handlerParcelDwellRequest != null)
  6740. {
  6741. handlerParcelDwellRequest(dwellrq.Data.LocalID, this);
  6742. }
  6743. break;
  6744. #endregion
  6745. #region Estate Packets
  6746. case PacketType.EstateOwnerMessage:
  6747. EstateOwnerMessagePacket messagePacket = (EstateOwnerMessagePacket)Pack;
  6748. //m_log.Debug(messagePacket.ToString());
  6749. #region Packet Session and User Check
  6750. if (m_checkPackets)
  6751. {
  6752. if (messagePacket.AgentData.SessionID != SessionId ||
  6753. messagePacket.AgentData.AgentID != AgentId)
  6754. break;
  6755. }
  6756. #endregion
  6757. switch (Utils.BytesToString(messagePacket.MethodData.Method))
  6758. {
  6759. case "getinfo":
  6760. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6761. {
  6762. OnDetailedEstateDataRequest(this, messagePacket.MethodData.Invoice);
  6763. }
  6764. break;
  6765. case "setregioninfo":
  6766. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6767. {
  6768. OnSetEstateFlagsRequest(convertParamStringToBool(messagePacket.ParamList[0].Parameter), convertParamStringToBool(messagePacket.ParamList[1].Parameter),
  6769. convertParamStringToBool(messagePacket.ParamList[2].Parameter), !convertParamStringToBool(messagePacket.ParamList[3].Parameter),
  6770. Convert.ToInt16(Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[4].Parameter))),
  6771. (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[5].Parameter)),
  6772. Convert.ToInt16(Utils.BytesToString(messagePacket.ParamList[6].Parameter)),
  6773. convertParamStringToBool(messagePacket.ParamList[7].Parameter), convertParamStringToBool(messagePacket.ParamList[8].Parameter));
  6774. }
  6775. break;
  6776. // case "texturebase":
  6777. // if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6778. // {
  6779. // foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  6780. // {
  6781. // string s = Utils.BytesToString(block.Parameter);
  6782. // string[] splitField = s.Split(' ');
  6783. // if (splitField.Length == 2)
  6784. // {
  6785. // UUID tempUUID = new UUID(splitField[1]);
  6786. // OnSetEstateTerrainBaseTexture(this, Convert.ToInt16(splitField[0]), tempUUID);
  6787. // }
  6788. // }
  6789. // }
  6790. // break;
  6791. case "texturedetail":
  6792. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6793. {
  6794. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  6795. {
  6796. string s = Utils.BytesToString(block.Parameter);
  6797. string[] splitField = s.Split(' ');
  6798. if (splitField.Length == 2)
  6799. {
  6800. Int16 corner = Convert.ToInt16(splitField[0]);
  6801. UUID textureUUID = new UUID(splitField[1]);
  6802. OnSetEstateTerrainDetailTexture(this, corner, textureUUID);
  6803. }
  6804. }
  6805. }
  6806. break;
  6807. case "textureheights":
  6808. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6809. {
  6810. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  6811. {
  6812. string s = Utils.BytesToString(block.Parameter);
  6813. string[] splitField = s.Split(' ');
  6814. if (splitField.Length == 3)
  6815. {
  6816. Int16 corner = Convert.ToInt16(splitField[0]);
  6817. float lowValue = (float)Convert.ToDecimal(splitField[1]);
  6818. float highValue = (float)Convert.ToDecimal(splitField[2]);
  6819. OnSetEstateTerrainTextureHeights(this, corner, lowValue, highValue);
  6820. }
  6821. }
  6822. }
  6823. break;
  6824. case "texturecommit":
  6825. OnCommitEstateTerrainTextureRequest(this);
  6826. break;
  6827. case "setregionterrain":
  6828. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6829. {
  6830. if (messagePacket.ParamList.Length != 9)
  6831. {
  6832. m_log.Error("EstateOwnerMessage: SetRegionTerrain method has a ParamList of invalid length");
  6833. }
  6834. else
  6835. {
  6836. try
  6837. {
  6838. string tmp = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
  6839. if (!tmp.Contains(".")) tmp += ".00";
  6840. float WaterHeight = (float)Convert.ToDecimal(tmp);
  6841. tmp = Utils.BytesToString(messagePacket.ParamList[1].Parameter);
  6842. if (!tmp.Contains(".")) tmp += ".00";
  6843. float TerrainRaiseLimit = (float)Convert.ToDecimal(tmp);
  6844. tmp = Utils.BytesToString(messagePacket.ParamList[2].Parameter);
  6845. if (!tmp.Contains(".")) tmp += ".00";
  6846. float TerrainLowerLimit = (float)Convert.ToDecimal(tmp);
  6847. bool UseEstateSun = convertParamStringToBool(messagePacket.ParamList[3].Parameter);
  6848. bool UseFixedSun = convertParamStringToBool(messagePacket.ParamList[4].Parameter);
  6849. float SunHour = (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[5].Parameter));
  6850. bool UseGlobal = convertParamStringToBool(messagePacket.ParamList[6].Parameter);
  6851. bool EstateFixedSun = convertParamStringToBool(messagePacket.ParamList[7].Parameter);
  6852. float EstateSunHour = (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[8].Parameter));
  6853. OnSetRegionTerrainSettings(WaterHeight, TerrainRaiseLimit, TerrainLowerLimit, UseEstateSun, UseFixedSun, SunHour, UseGlobal, EstateFixedSun, EstateSunHour);
  6854. }
  6855. catch (Exception ex)
  6856. {
  6857. m_log.Error("EstateOwnerMessage: Exception while setting terrain settings: \n" + messagePacket + "\n" + ex);
  6858. }
  6859. }
  6860. }
  6861. break;
  6862. case "restart":
  6863. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6864. {
  6865. // There's only 1 block in the estateResetSim.. and that's the number of seconds till restart.
  6866. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  6867. {
  6868. float timeSeconds;
  6869. Utils.TryParseSingle(Utils.BytesToString(block.Parameter), out timeSeconds);
  6870. timeSeconds = (int)timeSeconds;
  6871. OnEstateRestartSimRequest(this, (int)timeSeconds);
  6872. }
  6873. }
  6874. break;
  6875. case "estatechangecovenantid":
  6876. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6877. {
  6878. foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
  6879. {
  6880. UUID newCovenantID = new UUID(Utils.BytesToString(block.Parameter));
  6881. OnEstateChangeCovenantRequest(this, newCovenantID);
  6882. }
  6883. }
  6884. break;
  6885. case "estateaccessdelta": // Estate access delta manages the banlist and allow list too.
  6886. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6887. {
  6888. int estateAccessType = Convert.ToInt16(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  6889. OnUpdateEstateAccessDeltaRequest(this, messagePacket.MethodData.Invoice, estateAccessType, new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter)));
  6890. }
  6891. break;
  6892. case "simulatormessage":
  6893. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6894. {
  6895. UUID invoice = messagePacket.MethodData.Invoice;
  6896. UUID SenderID = new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  6897. string SenderName = Utils.BytesToString(messagePacket.ParamList[3].Parameter);
  6898. string Message = Utils.BytesToString(messagePacket.ParamList[4].Parameter);
  6899. UUID sessionID = messagePacket.AgentData.SessionID;
  6900. OnSimulatorBlueBoxMessageRequest(this, invoice, SenderID, sessionID, SenderName, Message);
  6901. }
  6902. break;
  6903. case "instantmessage":
  6904. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6905. {
  6906. if (messagePacket.ParamList.Length < 5)
  6907. break;
  6908. UUID invoice = messagePacket.MethodData.Invoice;
  6909. UUID SenderID = new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  6910. string SenderName = Utils.BytesToString(messagePacket.ParamList[3].Parameter);
  6911. string Message = Utils.BytesToString(messagePacket.ParamList[4].Parameter);
  6912. UUID sessionID = messagePacket.AgentData.SessionID;
  6913. OnEstateBlueBoxMessageRequest(this, invoice, SenderID, sessionID, SenderName, Message);
  6914. }
  6915. break;
  6916. case "setregiondebug":
  6917. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6918. {
  6919. UUID invoice = messagePacket.MethodData.Invoice;
  6920. UUID SenderID = messagePacket.AgentData.AgentID;
  6921. bool scripted = convertParamStringToBool(messagePacket.ParamList[0].Parameter);
  6922. bool collisionEvents = convertParamStringToBool(messagePacket.ParamList[1].Parameter);
  6923. bool physics = convertParamStringToBool(messagePacket.ParamList[2].Parameter);
  6924. OnEstateDebugRegionRequest(this, invoice, SenderID, scripted, collisionEvents, physics);
  6925. }
  6926. break;
  6927. case "teleporthomeuser":
  6928. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6929. {
  6930. UUID invoice = messagePacket.MethodData.Invoice;
  6931. UUID SenderID = messagePacket.AgentData.AgentID;
  6932. UUID Prey;
  6933. UUID.TryParse(Utils.BytesToString(messagePacket.ParamList[1].Parameter), out Prey);
  6934. OnEstateTeleportOneUserHomeRequest(this, invoice, SenderID, Prey);
  6935. }
  6936. break;
  6937. case "teleporthomeallusers":
  6938. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6939. {
  6940. UUID invoice = messagePacket.MethodData.Invoice;
  6941. UUID SenderID = messagePacket.AgentData.AgentID;
  6942. OnEstateTeleportAllUsersHomeRequest(this, invoice, SenderID);
  6943. }
  6944. break;
  6945. case "colliders":
  6946. handlerLandStatRequest = OnLandStatRequest;
  6947. if (handlerLandStatRequest != null)
  6948. {
  6949. handlerLandStatRequest(0, 1, 0, "", this);
  6950. }
  6951. break;
  6952. case "scripts":
  6953. handlerLandStatRequest = OnLandStatRequest;
  6954. if (handlerLandStatRequest != null)
  6955. {
  6956. handlerLandStatRequest(0, 0, 0, "", this);
  6957. }
  6958. break;
  6959. case "terrain":
  6960. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6961. {
  6962. if (messagePacket.ParamList.Length > 0)
  6963. {
  6964. if (Utils.BytesToString(messagePacket.ParamList[0].Parameter) == "bake")
  6965. {
  6966. handlerBakeTerrain = OnBakeTerrain;
  6967. if (handlerBakeTerrain != null)
  6968. {
  6969. handlerBakeTerrain(this);
  6970. }
  6971. }
  6972. if (Utils.BytesToString(messagePacket.ParamList[0].Parameter) == "download filename")
  6973. {
  6974. if (messagePacket.ParamList.Length > 1)
  6975. {
  6976. handlerRequestTerrain = OnRequestTerrain;
  6977. if (handlerRequestTerrain != null)
  6978. {
  6979. handlerRequestTerrain(this, Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  6980. }
  6981. }
  6982. }
  6983. if (Utils.BytesToString(messagePacket.ParamList[0].Parameter) == "upload filename")
  6984. {
  6985. if (messagePacket.ParamList.Length > 1)
  6986. {
  6987. handlerUploadTerrain = OnUploadTerrain;
  6988. if (handlerUploadTerrain != null)
  6989. {
  6990. handlerUploadTerrain(this, Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  6991. }
  6992. }
  6993. }
  6994. }
  6995. }
  6996. break;
  6997. case "estatechangeinfo":
  6998. if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
  6999. {
  7000. UUID invoice = messagePacket.MethodData.Invoice;
  7001. UUID SenderID = messagePacket.AgentData.AgentID;
  7002. UInt32 param1 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
  7003. UInt32 param2 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
  7004. handlerEstateChangeInfo = OnEstateChangeInfo;
  7005. if (handlerEstateChangeInfo != null)
  7006. {
  7007. handlerEstateChangeInfo(this, invoice, SenderID, param1, param2);
  7008. }
  7009. }
  7010. break;
  7011. default:
  7012. m_log.Error("EstateOwnerMessage: Unknown method requested\n" + messagePacket);
  7013. break;
  7014. }
  7015. //int parcelID, uint reportType, uint requestflags, string filter
  7016. //lsrp.RequestData.ParcelLocalID;
  7017. //lsrp.RequestData.ReportType; // 1 = colliders, 0 = scripts
  7018. //lsrp.RequestData.RequestFlags;
  7019. //lsrp.RequestData.Filter;
  7020. break;
  7021. case PacketType.RequestRegionInfo:
  7022. RequestRegionInfoPacket.AgentDataBlock mPacket = ((RequestRegionInfoPacket)Pack).AgentData;
  7023. #region Packet Session and User Check
  7024. if (m_checkPackets)
  7025. {
  7026. if (mPacket.SessionID != SessionId ||
  7027. mPacket.AgentID != AgentId)
  7028. break;
  7029. }
  7030. #endregion
  7031. handlerRegionInfoRequest = OnRegionInfoRequest;
  7032. if (handlerRegionInfoRequest != null)
  7033. {
  7034. handlerRegionInfoRequest(this);
  7035. }
  7036. break;
  7037. case PacketType.EstateCovenantRequest:
  7038. //EstateCovenantRequestPacket.AgentDataBlock epack =
  7039. // ((EstateCovenantRequestPacket)Pack).AgentData;
  7040. handlerEstateCovenantRequest = OnEstateCovenantRequest;
  7041. if (handlerEstateCovenantRequest != null)
  7042. {
  7043. handlerEstateCovenantRequest(this);
  7044. }
  7045. break;
  7046. #endregion
  7047. #region GodPackets
  7048. case PacketType.RequestGodlikePowers:
  7049. RequestGodlikePowersPacket rglpPack = (RequestGodlikePowersPacket)Pack;
  7050. RequestGodlikePowersPacket.RequestBlockBlock rblock = rglpPack.RequestBlock;
  7051. UUID token = rblock.Token;
  7052. RequestGodlikePowersPacket.AgentDataBlock ablock = rglpPack.AgentData;
  7053. handlerReqGodlikePowers = OnRequestGodlikePowers;
  7054. if (handlerReqGodlikePowers != null)
  7055. {
  7056. handlerReqGodlikePowers(ablock.AgentID, ablock.SessionID, token, rblock.Godlike, this);
  7057. }
  7058. break;
  7059. case PacketType.GodKickUser:
  7060. GodKickUserPacket gkupack = (GodKickUserPacket)Pack;
  7061. if (gkupack.UserInfo.GodSessionID == SessionId && AgentId == gkupack.UserInfo.GodID)
  7062. {
  7063. handlerGodKickUser = OnGodKickUser;
  7064. if (handlerGodKickUser != null)
  7065. {
  7066. handlerGodKickUser(gkupack.UserInfo.GodID, gkupack.UserInfo.GodSessionID,
  7067. gkupack.UserInfo.AgentID, (uint)0, gkupack.UserInfo.Reason);
  7068. }
  7069. }
  7070. else
  7071. {
  7072. SendAgentAlertMessage("Kick request denied", false);
  7073. }
  7074. //KickUserPacket kupack = new KickUserPacket();
  7075. //KickUserPacket.UserInfoBlock kupackib = kupack.UserInfo;
  7076. //kupack.UserInfo.AgentID = gkupack.UserInfo.AgentID;
  7077. //kupack.UserInfo.SessionID = gkupack.UserInfo.GodSessionID;
  7078. //kupack.TargetBlock.TargetIP = (uint)0;
  7079. //kupack.TargetBlock.TargetPort = (ushort)0;
  7080. //kupack.UserInfo.Reason = gkupack.UserInfo.Reason;
  7081. //OutPacket(kupack, ThrottleOutPacketType.Task);
  7082. break;
  7083. #endregion
  7084. #region Economy/Transaction Packets
  7085. case PacketType.MoneyBalanceRequest:
  7086. MoneyBalanceRequestPacket moneybalancerequestpacket = (MoneyBalanceRequestPacket)Pack;
  7087. #region Packet Session and User Check
  7088. if (m_checkPackets)
  7089. {
  7090. if (moneybalancerequestpacket.AgentData.SessionID != SessionId ||
  7091. moneybalancerequestpacket.AgentData.AgentID != AgentId)
  7092. break;
  7093. }
  7094. #endregion
  7095. handlerMoneyBalanceRequest = OnMoneyBalanceRequest;
  7096. if (handlerMoneyBalanceRequest != null)
  7097. {
  7098. handlerMoneyBalanceRequest(this, moneybalancerequestpacket.AgentData.AgentID, moneybalancerequestpacket.AgentData.SessionID, moneybalancerequestpacket.MoneyData.TransactionID);
  7099. }
  7100. break;
  7101. case PacketType.EconomyDataRequest:
  7102. handlerEconomoyDataRequest = OnEconomyDataRequest;
  7103. if (handlerEconomoyDataRequest != null)
  7104. {
  7105. handlerEconomoyDataRequest(AgentId);
  7106. }
  7107. break;
  7108. case PacketType.RequestPayPrice:
  7109. RequestPayPricePacket requestPayPricePacket = (RequestPayPricePacket)Pack;
  7110. handlerRequestPayPrice = OnRequestPayPrice;
  7111. if (handlerRequestPayPrice != null)
  7112. {
  7113. handlerRequestPayPrice(this, requestPayPricePacket.ObjectData.ObjectID);
  7114. }
  7115. break;
  7116. case PacketType.ObjectSaleInfo:
  7117. ObjectSaleInfoPacket objectSaleInfoPacket = (ObjectSaleInfoPacket)Pack;
  7118. #region Packet Session and User Check
  7119. if (m_checkPackets)
  7120. {
  7121. if (objectSaleInfoPacket.AgentData.SessionID != SessionId ||
  7122. objectSaleInfoPacket.AgentData.AgentID != AgentId)
  7123. break;
  7124. }
  7125. #endregion
  7126. handlerObjectSaleInfo = OnObjectSaleInfo;
  7127. if (handlerObjectSaleInfo != null)
  7128. {
  7129. foreach (ObjectSaleInfoPacket.ObjectDataBlock d
  7130. in objectSaleInfoPacket.ObjectData)
  7131. {
  7132. handlerObjectSaleInfo(this,
  7133. objectSaleInfoPacket.AgentData.AgentID,
  7134. objectSaleInfoPacket.AgentData.SessionID,
  7135. d.LocalID,
  7136. d.SaleType,
  7137. d.SalePrice);
  7138. }
  7139. }
  7140. break;
  7141. case PacketType.ObjectBuy:
  7142. ObjectBuyPacket objectBuyPacket = (ObjectBuyPacket)Pack;
  7143. #region Packet Session and User Check
  7144. if (m_checkPackets)
  7145. {
  7146. if (objectBuyPacket.AgentData.SessionID != SessionId ||
  7147. objectBuyPacket.AgentData.AgentID != AgentId)
  7148. break;
  7149. }
  7150. #endregion
  7151. handlerObjectBuy = OnObjectBuy;
  7152. if (handlerObjectBuy != null)
  7153. {
  7154. foreach (ObjectBuyPacket.ObjectDataBlock d
  7155. in objectBuyPacket.ObjectData)
  7156. {
  7157. handlerObjectBuy(this,
  7158. objectBuyPacket.AgentData.AgentID,
  7159. objectBuyPacket.AgentData.SessionID,
  7160. objectBuyPacket.AgentData.GroupID,
  7161. objectBuyPacket.AgentData.CategoryID,
  7162. d.ObjectLocalID,
  7163. d.SaleType,
  7164. d.SalePrice);
  7165. }
  7166. }
  7167. break;
  7168. #endregion
  7169. #region Script Packets
  7170. case PacketType.GetScriptRunning:
  7171. GetScriptRunningPacket scriptRunning = (GetScriptRunningPacket)Pack;
  7172. handlerGetScriptRunning = OnGetScriptRunning;
  7173. if (handlerGetScriptRunning != null)
  7174. {
  7175. handlerGetScriptRunning(this, scriptRunning.Script.ObjectID, scriptRunning.Script.ItemID);
  7176. }
  7177. break;
  7178. case PacketType.SetScriptRunning:
  7179. SetScriptRunningPacket setScriptRunning = (SetScriptRunningPacket)Pack;
  7180. #region Packet Session and User Check
  7181. if (m_checkPackets)
  7182. {
  7183. if (setScriptRunning.AgentData.SessionID != SessionId ||
  7184. setScriptRunning.AgentData.AgentID != AgentId)
  7185. break;
  7186. }
  7187. #endregion
  7188. handlerSetScriptRunning = OnSetScriptRunning;
  7189. if (handlerSetScriptRunning != null)
  7190. {
  7191. handlerSetScriptRunning(this, setScriptRunning.Script.ObjectID, setScriptRunning.Script.ItemID, setScriptRunning.Script.Running);
  7192. }
  7193. break;
  7194. case PacketType.ScriptReset:
  7195. ScriptResetPacket scriptResetPacket = (ScriptResetPacket)Pack;
  7196. #region Packet Session and User Check
  7197. if (m_checkPackets)
  7198. {
  7199. if (scriptResetPacket.AgentData.SessionID != SessionId ||
  7200. scriptResetPacket.AgentData.AgentID != AgentId)
  7201. break;
  7202. }
  7203. #endregion
  7204. handlerScriptReset = OnScriptReset;
  7205. if (handlerScriptReset != null)
  7206. {
  7207. handlerScriptReset(this, scriptResetPacket.Script.ObjectID, scriptResetPacket.Script.ItemID);
  7208. }
  7209. break;
  7210. #endregion
  7211. #region Gesture Managment
  7212. case PacketType.ActivateGestures:
  7213. ActivateGesturesPacket activateGesturePacket = (ActivateGesturesPacket)Pack;
  7214. #region Packet Session and User Check
  7215. if (m_checkPackets)
  7216. {
  7217. if (activateGesturePacket.AgentData.SessionID != SessionId ||
  7218. activateGesturePacket.AgentData.AgentID != AgentId)
  7219. break;
  7220. }
  7221. #endregion
  7222. handlerActivateGesture = OnActivateGesture;
  7223. if (handlerActivateGesture != null)
  7224. {
  7225. handlerActivateGesture(this,
  7226. activateGesturePacket.Data[0].AssetID,
  7227. activateGesturePacket.Data[0].ItemID);
  7228. }
  7229. else m_log.Error("Null pointer for activateGesture");
  7230. break;
  7231. case PacketType.DeactivateGestures:
  7232. DeactivateGesturesPacket deactivateGesturePacket = (DeactivateGesturesPacket)Pack;
  7233. #region Packet Session and User Check
  7234. if (m_checkPackets)
  7235. {
  7236. if (deactivateGesturePacket.AgentData.SessionID != SessionId ||
  7237. deactivateGesturePacket.AgentData.AgentID != AgentId)
  7238. break;
  7239. }
  7240. #endregion
  7241. handlerDeactivateGesture = OnDeactivateGesture;
  7242. if (handlerDeactivateGesture != null)
  7243. {
  7244. handlerDeactivateGesture(this, deactivateGesturePacket.Data[0].ItemID);
  7245. }
  7246. break;
  7247. case PacketType.ObjectOwner:
  7248. ObjectOwnerPacket objectOwnerPacket = (ObjectOwnerPacket)Pack;
  7249. #region Packet Session and User Check
  7250. if (m_checkPackets)
  7251. {
  7252. if (objectOwnerPacket.AgentData.SessionID != SessionId ||
  7253. objectOwnerPacket.AgentData.AgentID != AgentId)
  7254. break;
  7255. }
  7256. #endregion
  7257. List<uint> localIDs = new List<uint>();
  7258. foreach (ObjectOwnerPacket.ObjectDataBlock d in objectOwnerPacket.ObjectData)
  7259. localIDs.Add(d.ObjectLocalID);
  7260. handlerObjectOwner = OnObjectOwner;
  7261. if (handlerObjectOwner != null)
  7262. {
  7263. handlerObjectOwner(this, objectOwnerPacket.HeaderData.OwnerID, objectOwnerPacket.HeaderData.GroupID, localIDs);
  7264. }
  7265. break;
  7266. #endregion
  7267. #region unimplemented handlers
  7268. case PacketType.StartPingCheck:
  7269. // Send the client the ping response back
  7270. // Pass the same PingID in the matching packet
  7271. // Handled In the packet processing
  7272. //m_log.Debug("[CLIENT]: possibly unhandled StartPingCheck packet");
  7273. break;
  7274. case PacketType.CompletePingCheck:
  7275. // TODO: Perhaps this should be processed on the Sim to determine whether or not to drop a dead client
  7276. //m_log.Warn("[CLIENT]: unhandled CompletePingCheck packet");
  7277. break;
  7278. case PacketType.ViewerStats:
  7279. // TODO: handle this packet
  7280. //m_log.Warn("[CLIENT]: unhandled ViewerStats packet");
  7281. break;
  7282. case PacketType.MapItemRequest:
  7283. MapItemRequestPacket mirpk = (MapItemRequestPacket)Pack;
  7284. #region Packet Session and User Check
  7285. if (m_checkPackets)
  7286. {
  7287. if (mirpk.AgentData.SessionID != SessionId ||
  7288. mirpk.AgentData.AgentID != AgentId)
  7289. break;
  7290. }
  7291. #endregion
  7292. //m_log.Debug(mirpk.ToString());
  7293. handlerMapItemRequest = OnMapItemRequest;
  7294. if (handlerMapItemRequest != null)
  7295. {
  7296. handlerMapItemRequest(this,mirpk.AgentData.Flags, mirpk.AgentData.EstateID,
  7297. mirpk.AgentData.Godlike,mirpk.RequestData.ItemType,
  7298. mirpk.RequestData.RegionHandle);
  7299. }
  7300. break;
  7301. case PacketType.TransferAbort:
  7302. // TODO: handle this packet
  7303. //m_log.Warn("[CLIENT]: unhandled TransferAbort packet");
  7304. break;
  7305. case PacketType.MuteListRequest:
  7306. MuteListRequestPacket muteListRequest =
  7307. (MuteListRequestPacket)Pack;
  7308. #region Packet Session and User Check
  7309. if (m_checkPackets)
  7310. {
  7311. if (muteListRequest.AgentData.SessionID != SessionId ||
  7312. muteListRequest.AgentData.AgentID != AgentId)
  7313. break;
  7314. }
  7315. #endregion
  7316. handlerMuteListRequest = OnMuteListRequest;
  7317. if (handlerMuteListRequest != null)
  7318. {
  7319. handlerMuteListRequest(this, muteListRequest.MuteData.MuteCRC);
  7320. }
  7321. else
  7322. {
  7323. SendUseCachedMuteList();
  7324. }
  7325. break;
  7326. case PacketType.UseCircuitCode:
  7327. // Don't display this one, we handle it at a lower level
  7328. break;
  7329. case PacketType.AgentHeightWidth:
  7330. // TODO: handle this packet
  7331. //m_log.Warn("[CLIENT]: unhandled AgentHeightWidth packet");
  7332. break;
  7333. case PacketType.InventoryDescendents:
  7334. // TODO: handle this packet
  7335. //m_log.Warn("[CLIENT]: unhandled InventoryDescent packet");
  7336. break;
  7337. case PacketType.DirPlacesQuery:
  7338. DirPlacesQueryPacket dirPlacesQueryPacket = (DirPlacesQueryPacket)Pack;
  7339. //m_log.Debug(dirPlacesQueryPacket.ToString());
  7340. #region Packet Session and User Check
  7341. if (m_checkPackets)
  7342. {
  7343. if (dirPlacesQueryPacket.AgentData.SessionID != SessionId ||
  7344. dirPlacesQueryPacket.AgentData.AgentID != AgentId)
  7345. break;
  7346. }
  7347. #endregion
  7348. handlerDirPlacesQuery = OnDirPlacesQuery;
  7349. if (handlerDirPlacesQuery != null)
  7350. {
  7351. handlerDirPlacesQuery(this,
  7352. dirPlacesQueryPacket.QueryData.QueryID,
  7353. Utils.BytesToString(
  7354. dirPlacesQueryPacket.QueryData.QueryText),
  7355. (int)dirPlacesQueryPacket.QueryData.QueryFlags,
  7356. (int)dirPlacesQueryPacket.QueryData.Category,
  7357. Utils.BytesToString(
  7358. dirPlacesQueryPacket.QueryData.SimName),
  7359. dirPlacesQueryPacket.QueryData.QueryStart);
  7360. }
  7361. break;
  7362. case PacketType.DirFindQuery:
  7363. DirFindQueryPacket dirFindQueryPacket = (DirFindQueryPacket)Pack;
  7364. #region Packet Session and User Check
  7365. if (m_checkPackets)
  7366. {
  7367. if (dirFindQueryPacket.AgentData.SessionID != SessionId ||
  7368. dirFindQueryPacket.AgentData.AgentID != AgentId)
  7369. break;
  7370. }
  7371. #endregion
  7372. handlerDirFindQuery = OnDirFindQuery;
  7373. if (handlerDirFindQuery != null)
  7374. {
  7375. handlerDirFindQuery(this,
  7376. dirFindQueryPacket.QueryData.QueryID,
  7377. Utils.BytesToString(
  7378. dirFindQueryPacket.QueryData.QueryText),
  7379. dirFindQueryPacket.QueryData.QueryFlags,
  7380. dirFindQueryPacket.QueryData.QueryStart);
  7381. }
  7382. break;
  7383. case PacketType.DirLandQuery:
  7384. DirLandQueryPacket dirLandQueryPacket = (DirLandQueryPacket)Pack;
  7385. #region Packet Session and User Check
  7386. if (m_checkPackets)
  7387. {
  7388. if (dirLandQueryPacket.AgentData.SessionID != SessionId ||
  7389. dirLandQueryPacket.AgentData.AgentID != AgentId)
  7390. break;
  7391. }
  7392. #endregion
  7393. handlerDirLandQuery = OnDirLandQuery;
  7394. if (handlerDirLandQuery != null)
  7395. {
  7396. handlerDirLandQuery(this,
  7397. dirLandQueryPacket.QueryData.QueryID,
  7398. dirLandQueryPacket.QueryData.QueryFlags,
  7399. dirLandQueryPacket.QueryData.SearchType,
  7400. dirLandQueryPacket.QueryData.Price,
  7401. dirLandQueryPacket.QueryData.Area,
  7402. dirLandQueryPacket.QueryData.QueryStart);
  7403. }
  7404. break;
  7405. case PacketType.DirPopularQuery:
  7406. DirPopularQueryPacket dirPopularQueryPacket = (DirPopularQueryPacket)Pack;
  7407. #region Packet Session and User Check
  7408. if (m_checkPackets)
  7409. {
  7410. if (dirPopularQueryPacket.AgentData.SessionID != SessionId ||
  7411. dirPopularQueryPacket.AgentData.AgentID != AgentId)
  7412. break;
  7413. }
  7414. #endregion
  7415. handlerDirPopularQuery = OnDirPopularQuery;
  7416. if (handlerDirPopularQuery != null)
  7417. {
  7418. handlerDirPopularQuery(this,
  7419. dirPopularQueryPacket.QueryData.QueryID,
  7420. dirPopularQueryPacket.QueryData.QueryFlags);
  7421. }
  7422. break;
  7423. case PacketType.DirClassifiedQuery:
  7424. DirClassifiedQueryPacket dirClassifiedQueryPacket = (DirClassifiedQueryPacket)Pack;
  7425. #region Packet Session and User Check
  7426. if (m_checkPackets)
  7427. {
  7428. if (dirClassifiedQueryPacket.AgentData.SessionID != SessionId ||
  7429. dirClassifiedQueryPacket.AgentData.AgentID != AgentId)
  7430. break;
  7431. }
  7432. #endregion
  7433. handlerDirClassifiedQuery = OnDirClassifiedQuery;
  7434. if (handlerDirClassifiedQuery != null)
  7435. {
  7436. handlerDirClassifiedQuery(this,
  7437. dirClassifiedQueryPacket.QueryData.QueryID,
  7438. Utils.BytesToString(
  7439. dirClassifiedQueryPacket.QueryData.QueryText),
  7440. dirClassifiedQueryPacket.QueryData.QueryFlags,
  7441. dirClassifiedQueryPacket.QueryData.Category,
  7442. dirClassifiedQueryPacket.QueryData.QueryStart);
  7443. }
  7444. break;
  7445. case PacketType.EventInfoRequest:
  7446. EventInfoRequestPacket eventInfoRequestPacket = (EventInfoRequestPacket)Pack;
  7447. #region Packet Session and User Check
  7448. if (m_checkPackets)
  7449. {
  7450. if (eventInfoRequestPacket.AgentData.SessionID != SessionId ||
  7451. eventInfoRequestPacket.AgentData.AgentID != AgentId)
  7452. break;
  7453. }
  7454. #endregion
  7455. if (OnEventInfoRequest != null)
  7456. {
  7457. OnEventInfoRequest(this, eventInfoRequestPacket.EventData.EventID);
  7458. }
  7459. break;
  7460. #region Calling Card
  7461. case PacketType.OfferCallingCard:
  7462. OfferCallingCardPacket offerCallingCardPacket = (OfferCallingCardPacket)Pack;
  7463. #region Packet Session and User Check
  7464. if (m_checkPackets)
  7465. {
  7466. if (offerCallingCardPacket.AgentData.SessionID != SessionId ||
  7467. offerCallingCardPacket.AgentData.AgentID != AgentId)
  7468. break;
  7469. }
  7470. #endregion
  7471. if (OnOfferCallingCard != null)
  7472. {
  7473. OnOfferCallingCard(this,
  7474. offerCallingCardPacket.AgentBlock.DestID,
  7475. offerCallingCardPacket.AgentBlock.TransactionID);
  7476. }
  7477. break;
  7478. case PacketType.AcceptCallingCard:
  7479. AcceptCallingCardPacket acceptCallingCardPacket = (AcceptCallingCardPacket)Pack;
  7480. #region Packet Session and User Check
  7481. if (m_checkPackets)
  7482. {
  7483. if (acceptCallingCardPacket.AgentData.SessionID != SessionId ||
  7484. acceptCallingCardPacket.AgentData.AgentID != AgentId)
  7485. break;
  7486. }
  7487. #endregion
  7488. // according to http://wiki.secondlife.com/wiki/AcceptCallingCard FolderData should
  7489. // contain exactly one entry
  7490. if (OnAcceptCallingCard != null && acceptCallingCardPacket.FolderData.Length > 0)
  7491. {
  7492. OnAcceptCallingCard(this,
  7493. acceptCallingCardPacket.TransactionBlock.TransactionID,
  7494. acceptCallingCardPacket.FolderData[0].FolderID);
  7495. }
  7496. break;
  7497. case PacketType.DeclineCallingCard:
  7498. DeclineCallingCardPacket declineCallingCardPacket = (DeclineCallingCardPacket)Pack;
  7499. #region Packet Session and User Check
  7500. if (m_checkPackets)
  7501. {
  7502. if (declineCallingCardPacket.AgentData.SessionID != SessionId ||
  7503. declineCallingCardPacket.AgentData.AgentID != AgentId)
  7504. break;
  7505. }
  7506. #endregion
  7507. if (OnDeclineCallingCard != null)
  7508. {
  7509. OnDeclineCallingCard(this,
  7510. declineCallingCardPacket.TransactionBlock.TransactionID);
  7511. }
  7512. break;
  7513. #endregion
  7514. #region Groups
  7515. case PacketType.ActivateGroup:
  7516. ActivateGroupPacket activateGroupPacket = (ActivateGroupPacket)Pack;
  7517. #region Packet Session and User Check
  7518. if (m_checkPackets)
  7519. {
  7520. if (activateGroupPacket.AgentData.SessionID != SessionId ||
  7521. activateGroupPacket.AgentData.AgentID != AgentId)
  7522. break;
  7523. }
  7524. #endregion
  7525. if (m_GroupsModule != null)
  7526. {
  7527. m_GroupsModule.ActivateGroup(this, activateGroupPacket.AgentData.GroupID);
  7528. m_GroupsModule.SendAgentGroupDataUpdate(this);
  7529. }
  7530. break;
  7531. case PacketType.GroupTitlesRequest:
  7532. GroupTitlesRequestPacket groupTitlesRequest =
  7533. (GroupTitlesRequestPacket)Pack;
  7534. #region Packet Session and User Check
  7535. if (m_checkPackets)
  7536. {
  7537. if (groupTitlesRequest.AgentData.SessionID != SessionId ||
  7538. groupTitlesRequest.AgentData.AgentID != AgentId)
  7539. break;
  7540. }
  7541. #endregion
  7542. if (m_GroupsModule != null)
  7543. {
  7544. GroupTitlesReplyPacket groupTitlesReply = (GroupTitlesReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupTitlesReply);
  7545. groupTitlesReply.AgentData =
  7546. new GroupTitlesReplyPacket.AgentDataBlock();
  7547. groupTitlesReply.AgentData.AgentID = AgentId;
  7548. groupTitlesReply.AgentData.GroupID =
  7549. groupTitlesRequest.AgentData.GroupID;
  7550. groupTitlesReply.AgentData.RequestID =
  7551. groupTitlesRequest.AgentData.RequestID;
  7552. List<GroupTitlesData> titles =
  7553. m_GroupsModule.GroupTitlesRequest(this,
  7554. groupTitlesRequest.AgentData.GroupID);
  7555. groupTitlesReply.GroupData =
  7556. new GroupTitlesReplyPacket.GroupDataBlock[titles.Count];
  7557. int i = 0;
  7558. foreach (GroupTitlesData d in titles)
  7559. {
  7560. groupTitlesReply.GroupData[i] =
  7561. new GroupTitlesReplyPacket.GroupDataBlock();
  7562. groupTitlesReply.GroupData[i].Title =
  7563. Utils.StringToBytes(d.Name);
  7564. groupTitlesReply.GroupData[i].RoleID =
  7565. d.UUID;
  7566. groupTitlesReply.GroupData[i].Selected =
  7567. d.Selected;
  7568. i++;
  7569. }
  7570. OutPacket(groupTitlesReply, ThrottleOutPacketType.Task);
  7571. }
  7572. break;
  7573. case PacketType.GroupProfileRequest:
  7574. GroupProfileRequestPacket groupProfileRequest =
  7575. (GroupProfileRequestPacket)Pack;
  7576. #region Packet Session and User Check
  7577. if (m_checkPackets)
  7578. {
  7579. if (groupProfileRequest.AgentData.SessionID != SessionId ||
  7580. groupProfileRequest.AgentData.AgentID != AgentId)
  7581. break;
  7582. }
  7583. #endregion
  7584. if (m_GroupsModule != null)
  7585. {
  7586. GroupProfileReplyPacket groupProfileReply = (GroupProfileReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupProfileReply);
  7587. groupProfileReply.AgentData = new GroupProfileReplyPacket.AgentDataBlock();
  7588. groupProfileReply.GroupData = new GroupProfileReplyPacket.GroupDataBlock();
  7589. groupProfileReply.AgentData.AgentID = AgentId;
  7590. GroupProfileData d = m_GroupsModule.GroupProfileRequest(this,
  7591. groupProfileRequest.GroupData.GroupID);
  7592. groupProfileReply.GroupData.GroupID = d.GroupID;
  7593. groupProfileReply.GroupData.Name = Utils.StringToBytes(d.Name);
  7594. groupProfileReply.GroupData.Charter = Utils.StringToBytes(d.Charter);
  7595. groupProfileReply.GroupData.ShowInList = d.ShowInList;
  7596. groupProfileReply.GroupData.MemberTitle = Utils.StringToBytes(d.MemberTitle);
  7597. groupProfileReply.GroupData.PowersMask = d.PowersMask;
  7598. groupProfileReply.GroupData.InsigniaID = d.InsigniaID;
  7599. groupProfileReply.GroupData.FounderID = d.FounderID;
  7600. groupProfileReply.GroupData.MembershipFee = d.MembershipFee;
  7601. groupProfileReply.GroupData.OpenEnrollment = d.OpenEnrollment;
  7602. groupProfileReply.GroupData.Money = d.Money;
  7603. groupProfileReply.GroupData.GroupMembershipCount = d.GroupMembershipCount;
  7604. groupProfileReply.GroupData.GroupRolesCount = d.GroupRolesCount;
  7605. groupProfileReply.GroupData.AllowPublish = d.AllowPublish;
  7606. groupProfileReply.GroupData.MaturePublish = d.MaturePublish;
  7607. groupProfileReply.GroupData.OwnerRole = d.OwnerRole;
  7608. OutPacket(groupProfileReply, ThrottleOutPacketType.Task);
  7609. }
  7610. break;
  7611. case PacketType.GroupMembersRequest:
  7612. GroupMembersRequestPacket groupMembersRequestPacket =
  7613. (GroupMembersRequestPacket)Pack;
  7614. #region Packet Session and User Check
  7615. if (m_checkPackets)
  7616. {
  7617. if (groupMembersRequestPacket.AgentData.SessionID != SessionId ||
  7618. groupMembersRequestPacket.AgentData.AgentID != AgentId)
  7619. break;
  7620. }
  7621. #endregion
  7622. if (m_GroupsModule != null)
  7623. {
  7624. List<GroupMembersData> members =
  7625. m_GroupsModule.GroupMembersRequest(this, groupMembersRequestPacket.GroupData.GroupID);
  7626. int memberCount = members.Count;
  7627. while (true)
  7628. {
  7629. int blockCount = members.Count;
  7630. if (blockCount > 40)
  7631. blockCount = 40;
  7632. GroupMembersReplyPacket groupMembersReply = (GroupMembersReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupMembersReply);
  7633. groupMembersReply.AgentData =
  7634. new GroupMembersReplyPacket.AgentDataBlock();
  7635. groupMembersReply.GroupData =
  7636. new GroupMembersReplyPacket.GroupDataBlock();
  7637. groupMembersReply.MemberData =
  7638. new GroupMembersReplyPacket.MemberDataBlock[
  7639. blockCount];
  7640. groupMembersReply.AgentData.AgentID = AgentId;
  7641. groupMembersReply.GroupData.GroupID =
  7642. groupMembersRequestPacket.GroupData.GroupID;
  7643. groupMembersReply.GroupData.RequestID =
  7644. groupMembersRequestPacket.GroupData.RequestID;
  7645. groupMembersReply.GroupData.MemberCount = memberCount;
  7646. for (int i = 0 ; i < blockCount ; i++)
  7647. {
  7648. GroupMembersData m = members[0];
  7649. members.RemoveAt(0);
  7650. groupMembersReply.MemberData[i] =
  7651. new GroupMembersReplyPacket.MemberDataBlock();
  7652. groupMembersReply.MemberData[i].AgentID =
  7653. m.AgentID;
  7654. groupMembersReply.MemberData[i].Contribution =
  7655. m.Contribution;
  7656. groupMembersReply.MemberData[i].OnlineStatus =
  7657. Utils.StringToBytes(m.OnlineStatus);
  7658. groupMembersReply.MemberData[i].AgentPowers =
  7659. m.AgentPowers;
  7660. groupMembersReply.MemberData[i].Title =
  7661. Utils.StringToBytes(m.Title);
  7662. groupMembersReply.MemberData[i].IsOwner =
  7663. m.IsOwner;
  7664. }
  7665. OutPacket(groupMembersReply, ThrottleOutPacketType.Task);
  7666. if (members.Count == 0)
  7667. break;
  7668. }
  7669. }
  7670. break;
  7671. case PacketType.GroupRoleDataRequest:
  7672. GroupRoleDataRequestPacket groupRolesRequest =
  7673. (GroupRoleDataRequestPacket)Pack;
  7674. #region Packet Session and User Check
  7675. if (m_checkPackets)
  7676. {
  7677. if (groupRolesRequest.AgentData.SessionID != SessionId ||
  7678. groupRolesRequest.AgentData.AgentID != AgentId)
  7679. break;
  7680. }
  7681. #endregion
  7682. if (m_GroupsModule != null)
  7683. {
  7684. GroupRoleDataReplyPacket groupRolesReply = (GroupRoleDataReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupRoleDataReply);
  7685. groupRolesReply.AgentData =
  7686. new GroupRoleDataReplyPacket.AgentDataBlock();
  7687. groupRolesReply.AgentData.AgentID = AgentId;
  7688. groupRolesReply.GroupData =
  7689. new GroupRoleDataReplyPacket.GroupDataBlock();
  7690. groupRolesReply.GroupData.GroupID =
  7691. groupRolesRequest.GroupData.GroupID;
  7692. groupRolesReply.GroupData.RequestID =
  7693. groupRolesRequest.GroupData.RequestID;
  7694. List<GroupRolesData> titles =
  7695. m_GroupsModule.GroupRoleDataRequest(this,
  7696. groupRolesRequest.GroupData.GroupID);
  7697. groupRolesReply.GroupData.RoleCount =
  7698. titles.Count;
  7699. groupRolesReply.RoleData =
  7700. new GroupRoleDataReplyPacket.RoleDataBlock[titles.Count];
  7701. int i = 0;
  7702. foreach (GroupRolesData d in titles)
  7703. {
  7704. groupRolesReply.RoleData[i] =
  7705. new GroupRoleDataReplyPacket.RoleDataBlock();
  7706. groupRolesReply.RoleData[i].RoleID =
  7707. d.RoleID;
  7708. groupRolesReply.RoleData[i].Name =
  7709. Utils.StringToBytes(d.Name);
  7710. groupRolesReply.RoleData[i].Title =
  7711. Utils.StringToBytes(d.Title);
  7712. groupRolesReply.RoleData[i].Description =
  7713. Utils.StringToBytes(d.Description);
  7714. groupRolesReply.RoleData[i].Powers =
  7715. d.Powers;
  7716. groupRolesReply.RoleData[i].Members =
  7717. (uint)d.Members;
  7718. i++;
  7719. }
  7720. OutPacket(groupRolesReply, ThrottleOutPacketType.Task);
  7721. }
  7722. break;
  7723. case PacketType.GroupRoleMembersRequest:
  7724. GroupRoleMembersRequestPacket groupRoleMembersRequest =
  7725. (GroupRoleMembersRequestPacket)Pack;
  7726. #region Packet Session and User Check
  7727. if (m_checkPackets)
  7728. {
  7729. if (groupRoleMembersRequest.AgentData.SessionID != SessionId ||
  7730. groupRoleMembersRequest.AgentData.AgentID != AgentId)
  7731. break;
  7732. }
  7733. #endregion
  7734. if (m_GroupsModule != null)
  7735. {
  7736. List<GroupRoleMembersData> mappings =
  7737. m_GroupsModule.GroupRoleMembersRequest(this,
  7738. groupRoleMembersRequest.GroupData.GroupID);
  7739. int mappingsCount = mappings.Count;
  7740. while (mappings.Count > 0)
  7741. {
  7742. int pairs = mappings.Count;
  7743. if (pairs > 32)
  7744. pairs = 32;
  7745. GroupRoleMembersReplyPacket groupRoleMembersReply = (GroupRoleMembersReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupRoleMembersReply);
  7746. groupRoleMembersReply.AgentData =
  7747. new GroupRoleMembersReplyPacket.AgentDataBlock();
  7748. groupRoleMembersReply.AgentData.AgentID =
  7749. AgentId;
  7750. groupRoleMembersReply.AgentData.GroupID =
  7751. groupRoleMembersRequest.GroupData.GroupID;
  7752. groupRoleMembersReply.AgentData.RequestID =
  7753. groupRoleMembersRequest.GroupData.RequestID;
  7754. groupRoleMembersReply.AgentData.TotalPairs =
  7755. (uint)mappingsCount;
  7756. groupRoleMembersReply.MemberData =
  7757. new GroupRoleMembersReplyPacket.MemberDataBlock[pairs];
  7758. for (int i = 0 ; i < pairs ; i++)
  7759. {
  7760. GroupRoleMembersData d = mappings[0];
  7761. mappings.RemoveAt(0);
  7762. groupRoleMembersReply.MemberData[i] =
  7763. new GroupRoleMembersReplyPacket.MemberDataBlock();
  7764. groupRoleMembersReply.MemberData[i].RoleID =
  7765. d.RoleID;
  7766. groupRoleMembersReply.MemberData[i].MemberID =
  7767. d.MemberID;
  7768. }
  7769. OutPacket(groupRoleMembersReply, ThrottleOutPacketType.Task);
  7770. }
  7771. }
  7772. break;
  7773. case PacketType.CreateGroupRequest:
  7774. CreateGroupRequestPacket createGroupRequest =
  7775. (CreateGroupRequestPacket)Pack;
  7776. #region Packet Session and User Check
  7777. if (m_checkPackets)
  7778. {
  7779. if (createGroupRequest.AgentData.SessionID != SessionId ||
  7780. createGroupRequest.AgentData.AgentID != AgentId)
  7781. break;
  7782. }
  7783. #endregion
  7784. if (m_GroupsModule != null)
  7785. {
  7786. m_GroupsModule.CreateGroup(this,
  7787. Utils.BytesToString(createGroupRequest.GroupData.Name),
  7788. Utils.BytesToString(createGroupRequest.GroupData.Charter),
  7789. createGroupRequest.GroupData.ShowInList,
  7790. createGroupRequest.GroupData.InsigniaID,
  7791. createGroupRequest.GroupData.MembershipFee,
  7792. createGroupRequest.GroupData.OpenEnrollment,
  7793. createGroupRequest.GroupData.AllowPublish,
  7794. createGroupRequest.GroupData.MaturePublish);
  7795. }
  7796. break;
  7797. case PacketType.UpdateGroupInfo:
  7798. UpdateGroupInfoPacket updateGroupInfo =
  7799. (UpdateGroupInfoPacket)Pack;
  7800. #region Packet Session and User Check
  7801. if (m_checkPackets)
  7802. {
  7803. if (updateGroupInfo.AgentData.SessionID != SessionId ||
  7804. updateGroupInfo.AgentData.AgentID != AgentId)
  7805. break;
  7806. }
  7807. #endregion
  7808. if (m_GroupsModule != null)
  7809. {
  7810. m_GroupsModule.UpdateGroupInfo(this,
  7811. updateGroupInfo.GroupData.GroupID,
  7812. Utils.BytesToString(updateGroupInfo.GroupData.Charter),
  7813. updateGroupInfo.GroupData.ShowInList,
  7814. updateGroupInfo.GroupData.InsigniaID,
  7815. updateGroupInfo.GroupData.MembershipFee,
  7816. updateGroupInfo.GroupData.OpenEnrollment,
  7817. updateGroupInfo.GroupData.AllowPublish,
  7818. updateGroupInfo.GroupData.MaturePublish);
  7819. }
  7820. break;
  7821. case PacketType.SetGroupAcceptNotices:
  7822. SetGroupAcceptNoticesPacket setGroupAcceptNotices =
  7823. (SetGroupAcceptNoticesPacket)Pack;
  7824. #region Packet Session and User Check
  7825. if (m_checkPackets)
  7826. {
  7827. if (setGroupAcceptNotices.AgentData.SessionID != SessionId ||
  7828. setGroupAcceptNotices.AgentData.AgentID != AgentId)
  7829. break;
  7830. }
  7831. #endregion
  7832. if (m_GroupsModule != null)
  7833. {
  7834. m_GroupsModule.SetGroupAcceptNotices(this,
  7835. setGroupAcceptNotices.Data.GroupID,
  7836. setGroupAcceptNotices.Data.AcceptNotices,
  7837. setGroupAcceptNotices.NewData.ListInProfile);
  7838. }
  7839. break;
  7840. case PacketType.GroupTitleUpdate:
  7841. GroupTitleUpdatePacket groupTitleUpdate =
  7842. (GroupTitleUpdatePacket)Pack;
  7843. #region Packet Session and User Check
  7844. if (m_checkPackets)
  7845. {
  7846. if (groupTitleUpdate.AgentData.SessionID != SessionId ||
  7847. groupTitleUpdate.AgentData.AgentID != AgentId)
  7848. break;
  7849. }
  7850. #endregion
  7851. if (m_GroupsModule != null)
  7852. {
  7853. m_GroupsModule.GroupTitleUpdate(this,
  7854. groupTitleUpdate.AgentData.GroupID,
  7855. groupTitleUpdate.AgentData.TitleRoleID);
  7856. }
  7857. break;
  7858. case PacketType.ParcelDeedToGroup:
  7859. ParcelDeedToGroupPacket parcelDeedToGroup = (ParcelDeedToGroupPacket)Pack;
  7860. if (m_GroupsModule != null)
  7861. {
  7862. handlerParcelDeedToGroup = OnParcelDeedToGroup;
  7863. if (handlerParcelDeedToGroup != null)
  7864. {
  7865. handlerParcelDeedToGroup(parcelDeedToGroup.Data.LocalID, parcelDeedToGroup.Data.GroupID,this);
  7866. }
  7867. }
  7868. break;
  7869. case PacketType.GroupNoticesListRequest:
  7870. GroupNoticesListRequestPacket groupNoticesListRequest =
  7871. (GroupNoticesListRequestPacket)Pack;
  7872. #region Packet Session and User Check
  7873. if (m_checkPackets)
  7874. {
  7875. if (groupNoticesListRequest.AgentData.SessionID != SessionId ||
  7876. groupNoticesListRequest.AgentData.AgentID != AgentId)
  7877. break;
  7878. }
  7879. #endregion
  7880. if (m_GroupsModule != null)
  7881. {
  7882. GroupNoticeData[] gn =
  7883. m_GroupsModule.GroupNoticesListRequest(this,
  7884. groupNoticesListRequest.Data.GroupID);
  7885. GroupNoticesListReplyPacket groupNoticesListReply = (GroupNoticesListReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupNoticesListReply);
  7886. groupNoticesListReply.AgentData =
  7887. new GroupNoticesListReplyPacket.AgentDataBlock();
  7888. groupNoticesListReply.AgentData.AgentID = AgentId;
  7889. groupNoticesListReply.AgentData.GroupID = groupNoticesListRequest.Data.GroupID;
  7890. groupNoticesListReply.Data = new GroupNoticesListReplyPacket.DataBlock[gn.Length];
  7891. int i = 0;
  7892. foreach (GroupNoticeData g in gn)
  7893. {
  7894. groupNoticesListReply.Data[i] = new GroupNoticesListReplyPacket.DataBlock();
  7895. groupNoticesListReply.Data[i].NoticeID =
  7896. g.NoticeID;
  7897. groupNoticesListReply.Data[i].Timestamp =
  7898. g.Timestamp;
  7899. groupNoticesListReply.Data[i].FromName =
  7900. Utils.StringToBytes(g.FromName);
  7901. groupNoticesListReply.Data[i].Subject =
  7902. Utils.StringToBytes(g.Subject);
  7903. groupNoticesListReply.Data[i].HasAttachment =
  7904. g.HasAttachment;
  7905. groupNoticesListReply.Data[i].AssetType =
  7906. g.AssetType;
  7907. i++;
  7908. }
  7909. OutPacket(groupNoticesListReply, ThrottleOutPacketType.Task);
  7910. }
  7911. break;
  7912. case PacketType.GroupNoticeRequest:
  7913. GroupNoticeRequestPacket groupNoticeRequest =
  7914. (GroupNoticeRequestPacket)Pack;
  7915. #region Packet Session and User Check
  7916. if (m_checkPackets)
  7917. {
  7918. if (groupNoticeRequest.AgentData.SessionID != SessionId ||
  7919. groupNoticeRequest.AgentData.AgentID != AgentId)
  7920. break;
  7921. }
  7922. #endregion
  7923. if (m_GroupsModule != null)
  7924. {
  7925. m_GroupsModule.GroupNoticeRequest(this,
  7926. groupNoticeRequest.Data.GroupNoticeID);
  7927. }
  7928. break;
  7929. case PacketType.GroupRoleUpdate:
  7930. GroupRoleUpdatePacket groupRoleUpdate =
  7931. (GroupRoleUpdatePacket)Pack;
  7932. #region Packet Session and User Check
  7933. if (m_checkPackets)
  7934. {
  7935. if (groupRoleUpdate.AgentData.SessionID != SessionId ||
  7936. groupRoleUpdate.AgentData.AgentID != AgentId)
  7937. break;
  7938. }
  7939. #endregion
  7940. if (m_GroupsModule != null)
  7941. {
  7942. foreach (GroupRoleUpdatePacket.RoleDataBlock d in
  7943. groupRoleUpdate.RoleData)
  7944. {
  7945. m_GroupsModule.GroupRoleUpdate(this,
  7946. groupRoleUpdate.AgentData.GroupID,
  7947. d.RoleID,
  7948. Utils.BytesToString(d.Name),
  7949. Utils.BytesToString(d.Description),
  7950. Utils.BytesToString(d.Title),
  7951. d.Powers,
  7952. d.UpdateType);
  7953. }
  7954. m_GroupsModule.NotifyChange(groupRoleUpdate.AgentData.GroupID);
  7955. }
  7956. break;
  7957. case PacketType.GroupRoleChanges:
  7958. GroupRoleChangesPacket groupRoleChanges =
  7959. (GroupRoleChangesPacket)Pack;
  7960. #region Packet Session and User Check
  7961. if (m_checkPackets)
  7962. {
  7963. if (groupRoleChanges.AgentData.SessionID != SessionId ||
  7964. groupRoleChanges.AgentData.AgentID != AgentId)
  7965. break;
  7966. }
  7967. #endregion
  7968. if (m_GroupsModule != null)
  7969. {
  7970. foreach (GroupRoleChangesPacket.RoleChangeBlock d in
  7971. groupRoleChanges.RoleChange)
  7972. {
  7973. m_GroupsModule.GroupRoleChanges(this,
  7974. groupRoleChanges.AgentData.GroupID,
  7975. d.RoleID,
  7976. d.MemberID,
  7977. d.Change);
  7978. }
  7979. m_GroupsModule.NotifyChange(groupRoleChanges.AgentData.GroupID);
  7980. }
  7981. break;
  7982. case PacketType.JoinGroupRequest:
  7983. JoinGroupRequestPacket joinGroupRequest =
  7984. (JoinGroupRequestPacket)Pack;
  7985. #region Packet Session and User Check
  7986. if (m_checkPackets)
  7987. {
  7988. if (joinGroupRequest.AgentData.SessionID != SessionId ||
  7989. joinGroupRequest.AgentData.AgentID != AgentId)
  7990. break;
  7991. }
  7992. #endregion
  7993. if (m_GroupsModule != null)
  7994. {
  7995. m_GroupsModule.JoinGroupRequest(this,
  7996. joinGroupRequest.GroupData.GroupID);
  7997. }
  7998. break;
  7999. case PacketType.LeaveGroupRequest:
  8000. LeaveGroupRequestPacket leaveGroupRequest =
  8001. (LeaveGroupRequestPacket)Pack;
  8002. #region Packet Session and User Check
  8003. if (m_checkPackets)
  8004. {
  8005. if (leaveGroupRequest.AgentData.SessionID != SessionId ||
  8006. leaveGroupRequest.AgentData.AgentID != AgentId)
  8007. break;
  8008. }
  8009. #endregion
  8010. if (m_GroupsModule != null)
  8011. {
  8012. m_GroupsModule.LeaveGroupRequest(this,
  8013. leaveGroupRequest.GroupData.GroupID);
  8014. }
  8015. break;
  8016. case PacketType.EjectGroupMemberRequest:
  8017. EjectGroupMemberRequestPacket ejectGroupMemberRequest =
  8018. (EjectGroupMemberRequestPacket)Pack;
  8019. #region Packet Session and User Check
  8020. if (m_checkPackets)
  8021. {
  8022. if (ejectGroupMemberRequest.AgentData.SessionID != SessionId ||
  8023. ejectGroupMemberRequest.AgentData.AgentID != AgentId)
  8024. break;
  8025. }
  8026. #endregion
  8027. if (m_GroupsModule != null)
  8028. {
  8029. foreach (EjectGroupMemberRequestPacket.EjectDataBlock e
  8030. in ejectGroupMemberRequest.EjectData)
  8031. {
  8032. m_GroupsModule.EjectGroupMemberRequest(this,
  8033. ejectGroupMemberRequest.GroupData.GroupID,
  8034. e.EjecteeID);
  8035. }
  8036. }
  8037. break;
  8038. case PacketType.InviteGroupRequest:
  8039. InviteGroupRequestPacket inviteGroupRequest =
  8040. (InviteGroupRequestPacket)Pack;
  8041. #region Packet Session and User Check
  8042. if (m_checkPackets)
  8043. {
  8044. if (inviteGroupRequest.AgentData.SessionID != SessionId ||
  8045. inviteGroupRequest.AgentData.AgentID != AgentId)
  8046. break;
  8047. }
  8048. #endregion
  8049. if (m_GroupsModule != null)
  8050. {
  8051. foreach (InviteGroupRequestPacket.InviteDataBlock b in
  8052. inviteGroupRequest.InviteData)
  8053. {
  8054. m_GroupsModule.InviteGroupRequest(this,
  8055. inviteGroupRequest.GroupData.GroupID,
  8056. b.InviteeID,
  8057. b.RoleID);
  8058. }
  8059. }
  8060. break;
  8061. #endregion
  8062. case PacketType.StartLure:
  8063. StartLurePacket startLureRequest = (StartLurePacket)Pack;
  8064. #region Packet Session and User Check
  8065. if (m_checkPackets)
  8066. {
  8067. if (startLureRequest.AgentData.SessionID != SessionId ||
  8068. startLureRequest.AgentData.AgentID != AgentId)
  8069. break;
  8070. }
  8071. #endregion
  8072. handlerStartLure = OnStartLure;
  8073. if (handlerStartLure != null)
  8074. handlerStartLure(startLureRequest.Info.LureType,
  8075. Utils.BytesToString(
  8076. startLureRequest.Info.Message),
  8077. startLureRequest.TargetData[0].TargetID,
  8078. this);
  8079. break;
  8080. case PacketType.TeleportLureRequest:
  8081. TeleportLureRequestPacket teleportLureRequest =
  8082. (TeleportLureRequestPacket)Pack;
  8083. #region Packet Session and User Check
  8084. if (m_checkPackets)
  8085. {
  8086. if (teleportLureRequest.Info.SessionID != SessionId ||
  8087. teleportLureRequest.Info.AgentID != AgentId)
  8088. break;
  8089. }
  8090. #endregion
  8091. handlerTeleportLureRequest = OnTeleportLureRequest;
  8092. if (handlerTeleportLureRequest != null)
  8093. handlerTeleportLureRequest(
  8094. teleportLureRequest.Info.LureID,
  8095. teleportLureRequest.Info.TeleportFlags,
  8096. this);
  8097. break;
  8098. case PacketType.ClassifiedInfoRequest:
  8099. ClassifiedInfoRequestPacket classifiedInfoRequest =
  8100. (ClassifiedInfoRequestPacket)Pack;
  8101. #region Packet Session and User Check
  8102. if (m_checkPackets)
  8103. {
  8104. if (classifiedInfoRequest.AgentData.SessionID != SessionId ||
  8105. classifiedInfoRequest.AgentData.AgentID != AgentId)
  8106. break;
  8107. }
  8108. #endregion
  8109. handlerClassifiedInfoRequest = OnClassifiedInfoRequest;
  8110. if (handlerClassifiedInfoRequest != null)
  8111. handlerClassifiedInfoRequest(
  8112. classifiedInfoRequest.Data.ClassifiedID,
  8113. this);
  8114. break;
  8115. case PacketType.ClassifiedInfoUpdate:
  8116. ClassifiedInfoUpdatePacket classifiedInfoUpdate =
  8117. (ClassifiedInfoUpdatePacket)Pack;
  8118. #region Packet Session and User Check
  8119. if (m_checkPackets)
  8120. {
  8121. if (classifiedInfoUpdate.AgentData.SessionID != SessionId ||
  8122. classifiedInfoUpdate.AgentData.AgentID != AgentId)
  8123. break;
  8124. }
  8125. #endregion
  8126. handlerClassifiedInfoUpdate = OnClassifiedInfoUpdate;
  8127. if (handlerClassifiedInfoUpdate != null)
  8128. handlerClassifiedInfoUpdate(
  8129. classifiedInfoUpdate.Data.ClassifiedID,
  8130. classifiedInfoUpdate.Data.Category,
  8131. Utils.BytesToString(
  8132. classifiedInfoUpdate.Data.Name),
  8133. Utils.BytesToString(
  8134. classifiedInfoUpdate.Data.Desc),
  8135. classifiedInfoUpdate.Data.ParcelID,
  8136. classifiedInfoUpdate.Data.ParentEstate,
  8137. classifiedInfoUpdate.Data.SnapshotID,
  8138. new Vector3(
  8139. classifiedInfoUpdate.Data.PosGlobal),
  8140. classifiedInfoUpdate.Data.ClassifiedFlags,
  8141. classifiedInfoUpdate.Data.PriceForListing,
  8142. this);
  8143. break;
  8144. case PacketType.ClassifiedDelete:
  8145. ClassifiedDeletePacket classifiedDelete =
  8146. (ClassifiedDeletePacket)Pack;
  8147. #region Packet Session and User Check
  8148. if (m_checkPackets)
  8149. {
  8150. if (classifiedDelete.AgentData.SessionID != SessionId ||
  8151. classifiedDelete.AgentData.AgentID != AgentId)
  8152. break;
  8153. }
  8154. #endregion
  8155. handlerClassifiedDelete = OnClassifiedDelete;
  8156. if (handlerClassifiedDelete != null)
  8157. handlerClassifiedDelete(
  8158. classifiedDelete.Data.ClassifiedID,
  8159. this);
  8160. break;
  8161. case PacketType.ClassifiedGodDelete:
  8162. ClassifiedGodDeletePacket classifiedGodDelete =
  8163. (ClassifiedGodDeletePacket)Pack;
  8164. #region Packet Session and User Check
  8165. if (m_checkPackets)
  8166. {
  8167. if (classifiedGodDelete.AgentData.SessionID != SessionId ||
  8168. classifiedGodDelete.AgentData.AgentID != AgentId)
  8169. break;
  8170. }
  8171. #endregion
  8172. handlerClassifiedGodDelete = OnClassifiedGodDelete;
  8173. if (handlerClassifiedGodDelete != null)
  8174. handlerClassifiedGodDelete(
  8175. classifiedGodDelete.Data.ClassifiedID,
  8176. this);
  8177. break;
  8178. case PacketType.EventGodDelete:
  8179. EventGodDeletePacket eventGodDelete =
  8180. (EventGodDeletePacket)Pack;
  8181. #region Packet Session and User Check
  8182. if (m_checkPackets)
  8183. {
  8184. if (eventGodDelete.AgentData.SessionID != SessionId ||
  8185. eventGodDelete.AgentData.AgentID != AgentId)
  8186. break;
  8187. }
  8188. #endregion
  8189. handlerEventGodDelete = OnEventGodDelete;
  8190. if (handlerEventGodDelete != null)
  8191. handlerEventGodDelete(
  8192. eventGodDelete.EventData.EventID,
  8193. eventGodDelete.QueryData.QueryID,
  8194. Utils.BytesToString(
  8195. eventGodDelete.QueryData.QueryText),
  8196. eventGodDelete.QueryData.QueryFlags,
  8197. eventGodDelete.QueryData.QueryStart,
  8198. this);
  8199. break;
  8200. case PacketType.EventNotificationAddRequest:
  8201. EventNotificationAddRequestPacket eventNotificationAdd =
  8202. (EventNotificationAddRequestPacket)Pack;
  8203. #region Packet Session and User Check
  8204. if (m_checkPackets)
  8205. {
  8206. if (eventNotificationAdd.AgentData.SessionID != SessionId ||
  8207. eventNotificationAdd.AgentData.AgentID != AgentId)
  8208. break;
  8209. }
  8210. #endregion
  8211. handlerEventNotificationAddRequest = OnEventNotificationAddRequest;
  8212. if (handlerEventNotificationAddRequest != null)
  8213. handlerEventNotificationAddRequest(
  8214. eventNotificationAdd.EventData.EventID, this);
  8215. break;
  8216. case PacketType.EventNotificationRemoveRequest:
  8217. EventNotificationRemoveRequestPacket eventNotificationRemove =
  8218. (EventNotificationRemoveRequestPacket)Pack;
  8219. #region Packet Session and User Check
  8220. if (m_checkPackets)
  8221. {
  8222. if (eventNotificationRemove.AgentData.SessionID != SessionId ||
  8223. eventNotificationRemove.AgentData.AgentID != AgentId)
  8224. break;
  8225. }
  8226. #endregion
  8227. handlerEventNotificationRemoveRequest = OnEventNotificationRemoveRequest;
  8228. if (handlerEventNotificationRemoveRequest != null)
  8229. handlerEventNotificationRemoveRequest(
  8230. eventNotificationRemove.EventData.EventID, this);
  8231. break;
  8232. case PacketType.RetrieveInstantMessages:
  8233. RetrieveInstantMessagesPacket rimpInstantMessagePack = (RetrieveInstantMessagesPacket)Pack;
  8234. #region Packet Session and User Check
  8235. if (m_checkPackets)
  8236. {
  8237. if (rimpInstantMessagePack.AgentData.SessionID != SessionId ||
  8238. rimpInstantMessagePack.AgentData.AgentID != AgentId)
  8239. break;
  8240. }
  8241. #endregion
  8242. handlerRetrieveInstantMessages = OnRetrieveInstantMessages;
  8243. if (handlerRetrieveInstantMessages != null)
  8244. handlerRetrieveInstantMessages(this);
  8245. break;
  8246. case PacketType.PickDelete:
  8247. PickDeletePacket pickDelete =
  8248. (PickDeletePacket)Pack;
  8249. #region Packet Session and User Check
  8250. if (m_checkPackets)
  8251. {
  8252. if (pickDelete.AgentData.SessionID != SessionId ||
  8253. pickDelete.AgentData.AgentID != AgentId)
  8254. break;
  8255. }
  8256. #endregion
  8257. handlerPickDelete = OnPickDelete;
  8258. if (handlerPickDelete != null)
  8259. handlerPickDelete(this, pickDelete.Data.PickID);
  8260. break;
  8261. case PacketType.PickGodDelete:
  8262. PickGodDeletePacket pickGodDelete =
  8263. (PickGodDeletePacket)Pack;
  8264. #region Packet Session and User Check
  8265. if (m_checkPackets)
  8266. {
  8267. if (pickGodDelete.AgentData.SessionID != SessionId ||
  8268. pickGodDelete.AgentData.AgentID != AgentId)
  8269. break;
  8270. }
  8271. #endregion
  8272. handlerPickGodDelete = OnPickGodDelete;
  8273. if (handlerPickGodDelete != null)
  8274. handlerPickGodDelete(this,
  8275. pickGodDelete.AgentData.AgentID,
  8276. pickGodDelete.Data.PickID,
  8277. pickGodDelete.Data.QueryID);
  8278. break;
  8279. case PacketType.PickInfoUpdate:
  8280. PickInfoUpdatePacket pickInfoUpdate =
  8281. (PickInfoUpdatePacket)Pack;
  8282. #region Packet Session and User Check
  8283. if (m_checkPackets)
  8284. {
  8285. if (pickInfoUpdate.AgentData.SessionID != SessionId ||
  8286. pickInfoUpdate.AgentData.AgentID != AgentId)
  8287. break;
  8288. }
  8289. #endregion
  8290. handlerPickInfoUpdate = OnPickInfoUpdate;
  8291. if (handlerPickInfoUpdate != null)
  8292. handlerPickInfoUpdate(this,
  8293. pickInfoUpdate.Data.PickID,
  8294. pickInfoUpdate.Data.CreatorID,
  8295. pickInfoUpdate.Data.TopPick,
  8296. Utils.BytesToString(pickInfoUpdate.Data.Name),
  8297. Utils.BytesToString(pickInfoUpdate.Data.Desc),
  8298. pickInfoUpdate.Data.SnapshotID,
  8299. pickInfoUpdate.Data.SortOrder,
  8300. pickInfoUpdate.Data.Enabled);
  8301. break;
  8302. case PacketType.AvatarNotesUpdate:
  8303. AvatarNotesUpdatePacket avatarNotesUpdate =
  8304. (AvatarNotesUpdatePacket)Pack;
  8305. #region Packet Session and User Check
  8306. if (m_checkPackets)
  8307. {
  8308. if (avatarNotesUpdate.AgentData.SessionID != SessionId ||
  8309. avatarNotesUpdate.AgentData.AgentID != AgentId)
  8310. break;
  8311. }
  8312. #endregion
  8313. handlerAvatarNotesUpdate = OnAvatarNotesUpdate;
  8314. if (handlerAvatarNotesUpdate != null)
  8315. handlerAvatarNotesUpdate(this,
  8316. avatarNotesUpdate.Data.TargetID,
  8317. Utils.BytesToString(avatarNotesUpdate.Data.Notes));
  8318. break;
  8319. // case PacketType.AvatarInterestsUpdate:
  8320. // AvatarInterestsUpdatePacket avatarInterestUpdate =
  8321. // (AvatarInterestsUpdatePacket)Pack;
  8322. //
  8323. // break;
  8324. case PacketType.PlacesQuery:
  8325. PlacesQueryPacket placesQueryPacket =
  8326. (PlacesQueryPacket)Pack;
  8327. handlerPlacesQuery = OnPlacesQuery;
  8328. if (handlerPlacesQuery != null)
  8329. handlerPlacesQuery(placesQueryPacket.AgentData.QueryID,
  8330. placesQueryPacket.TransactionData.TransactionID,
  8331. Utils.BytesToString(
  8332. placesQueryPacket.QueryData.QueryText),
  8333. placesQueryPacket.QueryData.QueryFlags,
  8334. (byte)placesQueryPacket.QueryData.Category,
  8335. Utils.BytesToString(
  8336. placesQueryPacket.QueryData.SimName),
  8337. this);
  8338. break;
  8339. default:
  8340. m_log.Warn("[CLIENT]: unhandled packet " + Pack);
  8341. break;
  8342. #endregion
  8343. }
  8344. PacketPool.Instance.ReturnPacket(Pack);
  8345. }
  8346. private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)
  8347. {
  8348. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  8349. shape.PCode = addPacket.ObjectData.PCode;
  8350. shape.State = addPacket.ObjectData.State;
  8351. shape.PathBegin = addPacket.ObjectData.PathBegin;
  8352. shape.PathEnd = addPacket.ObjectData.PathEnd;
  8353. shape.PathScaleX = addPacket.ObjectData.PathScaleX;
  8354. shape.PathScaleY = addPacket.ObjectData.PathScaleY;
  8355. shape.PathShearX = addPacket.ObjectData.PathShearX;
  8356. shape.PathShearY = addPacket.ObjectData.PathShearY;
  8357. shape.PathSkew = addPacket.ObjectData.PathSkew;
  8358. shape.ProfileBegin = addPacket.ObjectData.ProfileBegin;
  8359. shape.ProfileEnd = addPacket.ObjectData.ProfileEnd;
  8360. shape.Scale = addPacket.ObjectData.Scale;
  8361. shape.PathCurve = addPacket.ObjectData.PathCurve;
  8362. shape.ProfileCurve = addPacket.ObjectData.ProfileCurve;
  8363. shape.ProfileHollow = addPacket.ObjectData.ProfileHollow;
  8364. shape.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
  8365. shape.PathRevolutions = addPacket.ObjectData.PathRevolutions;
  8366. shape.PathTaperX = addPacket.ObjectData.PathTaperX;
  8367. shape.PathTaperY = addPacket.ObjectData.PathTaperY;
  8368. shape.PathTwist = addPacket.ObjectData.PathTwist;
  8369. shape.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
  8370. Primitive.TextureEntry ntex = new Primitive.TextureEntry(new UUID("89556747-24cb-43ed-920b-47caed15465f"));
  8371. shape.TextureEntry = ntex.GetBytes();
  8372. //shape.Textures = ntex;
  8373. return shape;
  8374. }
  8375. /// <summary>
  8376. /// Send the client an Estate message blue box pop-down with a single OK button
  8377. /// </summary>
  8378. /// <param name="FromAvatarID"></param>
  8379. /// <param name="fromSessionID"></param>
  8380. /// <param name="FromAvatarName"></param>
  8381. /// <param name="Message"></param>
  8382. public void SendBlueBoxMessage(UUID FromAvatarID, String FromAvatarName, String Message)
  8383. {
  8384. if (!ChildAgentStatus())
  8385. SendInstantMessage(new GridInstantMessage(null, FromAvatarID, FromAvatarName, AgentId, 1, Message, false, new Vector3()));
  8386. //SendInstantMessage(FromAvatarID, fromSessionID, Message, AgentId, SessionId, FromAvatarName, (byte)21,(uint) Util.UnixTimeSinceEpoch());
  8387. }
  8388. public void SendLogoutPacket()
  8389. {
  8390. // I know this is a bit of a hack, however there are times when you don't
  8391. // want to send this, but still need to do the rest of the shutdown process
  8392. // this method gets called from the packet server.. which makes it practically
  8393. // impossible to do any other way.
  8394. if (m_SendLogoutPacketWhenClosing)
  8395. {
  8396. LogoutReplyPacket logReply = (LogoutReplyPacket)PacketPool.Instance.GetPacket(PacketType.LogoutReply);
  8397. // TODO: don't create new blocks if recycling an old packet
  8398. logReply.AgentData.AgentID = AgentId;
  8399. logReply.AgentData.SessionID = SessionId;
  8400. logReply.InventoryData = new LogoutReplyPacket.InventoryDataBlock[1];
  8401. logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock();
  8402. logReply.InventoryData[0].ItemID = UUID.Zero;
  8403. OutPacket(logReply, ThrottleOutPacketType.Task);
  8404. }
  8405. }
  8406. public void SendHealth(float health)
  8407. {
  8408. HealthMessagePacket healthpacket = (HealthMessagePacket)PacketPool.Instance.GetPacket(PacketType.HealthMessage);
  8409. healthpacket.HealthData.Health = health;
  8410. OutPacket(healthpacket, ThrottleOutPacketType.Task);
  8411. }
  8412. public void SendAgentOnline(UUID[] agentIDs)
  8413. {
  8414. OnlineNotificationPacket onp = new OnlineNotificationPacket();
  8415. OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[agentIDs.Length];
  8416. for (int i = 0; i < agentIDs.Length; i++)
  8417. {
  8418. OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock();
  8419. onpbl.AgentID = agentIDs[i];
  8420. onpb[i] = onpbl;
  8421. }
  8422. onp.AgentBlock = onpb;
  8423. onp.Header.Reliable = true;
  8424. OutPacket(onp, ThrottleOutPacketType.Task);
  8425. }
  8426. public void SendAgentOffline(UUID[] agentIDs)
  8427. {
  8428. OfflineNotificationPacket offp = new OfflineNotificationPacket();
  8429. OfflineNotificationPacket.AgentBlockBlock[] offpb = new OfflineNotificationPacket.AgentBlockBlock[agentIDs.Length];
  8430. for (int i = 0; i < agentIDs.Length; i++)
  8431. {
  8432. OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock();
  8433. onpbl.AgentID = agentIDs[i];
  8434. offpb[i] = onpbl;
  8435. }
  8436. offp.AgentBlock = offpb;
  8437. offp.Header.Reliable = true;
  8438. OutPacket(offp, ThrottleOutPacketType.Task);
  8439. }
  8440. public void SendSitResponse(UUID TargetID, Vector3 OffsetPos, Quaternion SitOrientation, bool autopilot,
  8441. Vector3 CameraAtOffset, Vector3 CameraEyeOffset, bool ForceMouseLook)
  8442. {
  8443. AvatarSitResponsePacket avatarSitResponse = new AvatarSitResponsePacket();
  8444. avatarSitResponse.SitObject.ID = TargetID;
  8445. if (CameraAtOffset != Vector3.Zero)
  8446. {
  8447. avatarSitResponse.SitTransform.CameraAtOffset = CameraAtOffset;
  8448. avatarSitResponse.SitTransform.CameraEyeOffset = CameraEyeOffset;
  8449. }
  8450. avatarSitResponse.SitTransform.ForceMouselook = ForceMouseLook;
  8451. avatarSitResponse.SitTransform.AutoPilot = autopilot;
  8452. avatarSitResponse.SitTransform.SitPosition = OffsetPos;
  8453. avatarSitResponse.SitTransform.SitRotation = SitOrientation;
  8454. OutPacket(avatarSitResponse, ThrottleOutPacketType.Task);
  8455. }
  8456. public void SendAdminResponse(UUID Token, uint AdminLevel)
  8457. {
  8458. GrantGodlikePowersPacket respondPacket = new GrantGodlikePowersPacket();
  8459. GrantGodlikePowersPacket.GrantDataBlock gdb = new GrantGodlikePowersPacket.GrantDataBlock();
  8460. GrantGodlikePowersPacket.AgentDataBlock adb = new GrantGodlikePowersPacket.AgentDataBlock();
  8461. adb.AgentID = AgentId;
  8462. adb.SessionID = SessionId; // More security
  8463. gdb.GodLevel = (byte)AdminLevel;
  8464. gdb.Token = Token;
  8465. //respondPacket.AgentData = (GrantGodlikePowersPacket.AgentDataBlock)ablock;
  8466. respondPacket.GrantData = gdb;
  8467. respondPacket.AgentData = adb;
  8468. OutPacket(respondPacket, ThrottleOutPacketType.Task);
  8469. }
  8470. public void SendGroupMembership(GroupMembershipData[] GroupMembership)
  8471. {
  8472. m_groupPowers.Clear();
  8473. AgentGroupDataUpdatePacket Groupupdate = new AgentGroupDataUpdatePacket();
  8474. AgentGroupDataUpdatePacket.GroupDataBlock[] Groups = new AgentGroupDataUpdatePacket.GroupDataBlock[GroupMembership.Length];
  8475. for (int i = 0; i < GroupMembership.Length; i++)
  8476. {
  8477. m_groupPowers[GroupMembership[i].GroupID] = GroupMembership[i].GroupPowers;
  8478. AgentGroupDataUpdatePacket.GroupDataBlock Group = new AgentGroupDataUpdatePacket.GroupDataBlock();
  8479. Group.AcceptNotices = GroupMembership[i].AcceptNotices;
  8480. Group.Contribution = GroupMembership[i].Contribution;
  8481. Group.GroupID = GroupMembership[i].GroupID;
  8482. Group.GroupInsigniaID = GroupMembership[i].GroupPicture;
  8483. Group.GroupName = Utils.StringToBytes(GroupMembership[i].GroupName);
  8484. Group.GroupPowers = GroupMembership[i].GroupPowers;
  8485. Groups[i] = Group;
  8486. }
  8487. Groupupdate.GroupData = Groups;
  8488. Groupupdate.AgentData = new AgentGroupDataUpdatePacket.AgentDataBlock();
  8489. Groupupdate.AgentData.AgentID = AgentId;
  8490. OutPacket(Groupupdate, ThrottleOutPacketType.Task);
  8491. try
  8492. {
  8493. IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
  8494. if (eq != null)
  8495. {
  8496. eq.GroupMembership(Groupupdate, this.AgentId);
  8497. }
  8498. }
  8499. catch (Exception ex)
  8500. {
  8501. m_log.Error("Unable to send group membership data via eventqueue - exception: " + ex.ToString());
  8502. m_log.Warn("sending group membership data via UDP");
  8503. OutPacket(Groupupdate, ThrottleOutPacketType.Task);
  8504. }
  8505. }
  8506. public void SendGroupNameReply(UUID groupLLUID, string GroupName)
  8507. {
  8508. UUIDGroupNameReplyPacket pack = new UUIDGroupNameReplyPacket();
  8509. UUIDGroupNameReplyPacket.UUIDNameBlockBlock[] uidnameblock = new UUIDGroupNameReplyPacket.UUIDNameBlockBlock[1];
  8510. UUIDGroupNameReplyPacket.UUIDNameBlockBlock uidnamebloc = new UUIDGroupNameReplyPacket.UUIDNameBlockBlock();
  8511. uidnamebloc.ID = groupLLUID;
  8512. uidnamebloc.GroupName = Utils.StringToBytes(GroupName);
  8513. uidnameblock[0] = uidnamebloc;
  8514. pack.UUIDNameBlock = uidnameblock;
  8515. OutPacket(pack, ThrottleOutPacketType.Task);
  8516. }
  8517. public void SendLandStatReply(uint reportType, uint requestFlags, uint resultCount, LandStatReportItem[] lsrpia)
  8518. {
  8519. LandStatReplyPacket lsrp = new LandStatReplyPacket();
  8520. // LandStatReplyPacket.RequestDataBlock lsreqdpb = new LandStatReplyPacket.RequestDataBlock();
  8521. LandStatReplyPacket.ReportDataBlock[] lsrepdba = new LandStatReplyPacket.ReportDataBlock[lsrpia.Length];
  8522. //LandStatReplyPacket.ReportDataBlock lsrepdb = new LandStatReplyPacket.ReportDataBlock();
  8523. // lsrepdb.
  8524. lsrp.RequestData.ReportType = reportType;
  8525. lsrp.RequestData.RequestFlags = requestFlags;
  8526. lsrp.RequestData.TotalObjectCount = resultCount;
  8527. for (int i = 0; i < lsrpia.Length; i++)
  8528. {
  8529. LandStatReplyPacket.ReportDataBlock lsrepdb = new LandStatReplyPacket.ReportDataBlock();
  8530. lsrepdb.LocationX = lsrpia[i].LocationX;
  8531. lsrepdb.LocationY = lsrpia[i].LocationY;
  8532. lsrepdb.LocationZ = lsrpia[i].LocationZ;
  8533. lsrepdb.Score = lsrpia[i].Score;
  8534. lsrepdb.TaskID = lsrpia[i].TaskID;
  8535. lsrepdb.TaskLocalID = lsrpia[i].TaskLocalID;
  8536. lsrepdb.TaskName = Utils.StringToBytes(lsrpia[i].TaskName);
  8537. lsrepdb.OwnerName = Utils.StringToBytes(lsrpia[i].OwnerName);
  8538. lsrepdba[i] = lsrepdb;
  8539. }
  8540. lsrp.ReportData = lsrepdba;
  8541. OutPacket(lsrp, ThrottleOutPacketType.Task);
  8542. }
  8543. public void SendScriptRunningReply(UUID objectID, UUID itemID, bool running)
  8544. {
  8545. ScriptRunningReplyPacket scriptRunningReply = new ScriptRunningReplyPacket();
  8546. scriptRunningReply.Script.ObjectID = objectID;
  8547. scriptRunningReply.Script.ItemID = itemID;
  8548. scriptRunningReply.Script.Running = running;
  8549. OutPacket(scriptRunningReply, ThrottleOutPacketType.Task);
  8550. }
  8551. public void SendAsset(AssetRequestToClient req)
  8552. {
  8553. //m_log.Debug("sending asset " + req.RequestAssetID);
  8554. TransferInfoPacket Transfer = new TransferInfoPacket();
  8555. Transfer.TransferInfo.ChannelType = 2;
  8556. Transfer.TransferInfo.Status = 0;
  8557. Transfer.TransferInfo.TargetType = 0;
  8558. if (req.AssetRequestSource == 2)
  8559. {
  8560. Transfer.TransferInfo.Params = new byte[20];
  8561. Array.Copy(req.RequestAssetID.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
  8562. int assType = req.AssetInf.Type;
  8563. Array.Copy(Utils.IntToBytes(assType), 0, Transfer.TransferInfo.Params, 16, 4);
  8564. }
  8565. else if (req.AssetRequestSource == 3)
  8566. {
  8567. Transfer.TransferInfo.Params = req.Params;
  8568. // Transfer.TransferInfo.Params = new byte[100];
  8569. //Array.Copy(req.RequestUser.AgentId.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
  8570. //Array.Copy(req.RequestUser.SessionId.GetBytes(), 0, Transfer.TransferInfo.Params, 16, 16);
  8571. }
  8572. Transfer.TransferInfo.Size = req.AssetInf.Data.Length;
  8573. Transfer.TransferInfo.TransferID = req.TransferRequestID;
  8574. Transfer.Header.Zerocoded = true;
  8575. OutPacket(Transfer, ThrottleOutPacketType.Asset);
  8576. if (req.NumPackets == 1)
  8577. {
  8578. TransferPacketPacket TransferPacket = new TransferPacketPacket();
  8579. TransferPacket.TransferData.Packet = 0;
  8580. TransferPacket.TransferData.ChannelType = 2;
  8581. TransferPacket.TransferData.TransferID = req.TransferRequestID;
  8582. TransferPacket.TransferData.Data = req.AssetInf.Data;
  8583. TransferPacket.TransferData.Status = 1;
  8584. TransferPacket.Header.Zerocoded = true;
  8585. OutPacket(TransferPacket, ThrottleOutPacketType.Asset);
  8586. }
  8587. else
  8588. {
  8589. int processedLength = 0;
  8590. int maxChunkSize = Settings.MAX_PACKET_SIZE - 100;
  8591. int packetNumber = 0;
  8592. while (processedLength < req.AssetInf.Data.Length)
  8593. {
  8594. TransferPacketPacket TransferPacket = new TransferPacketPacket();
  8595. TransferPacket.TransferData.Packet = packetNumber;
  8596. TransferPacket.TransferData.ChannelType = 2;
  8597. TransferPacket.TransferData.TransferID = req.TransferRequestID;
  8598. int chunkSize = Math.Min(req.AssetInf.Data.Length - processedLength, maxChunkSize);
  8599. byte[] chunk = new byte[chunkSize];
  8600. Array.Copy(req.AssetInf.Data, processedLength, chunk, 0, chunk.Length);
  8601. TransferPacket.TransferData.Data = chunk;
  8602. // 0 indicates more packets to come, 1 indicates last packet
  8603. if (req.AssetInf.Data.Length - processedLength > maxChunkSize)
  8604. {
  8605. TransferPacket.TransferData.Status = 0;
  8606. }
  8607. else
  8608. {
  8609. TransferPacket.TransferData.Status = 1;
  8610. }
  8611. TransferPacket.Header.Zerocoded = true;
  8612. OutPacket(TransferPacket, ThrottleOutPacketType.Asset);
  8613. processedLength += chunkSize;
  8614. packetNumber++;
  8615. }
  8616. }
  8617. }
  8618. public void SendTexture(AssetBase TextureAsset)
  8619. {
  8620. }
  8621. public ClientInfo GetClientInfo()
  8622. {
  8623. ClientInfo info = m_PacketHandler.GetClientInfo();
  8624. info.userEP = m_userEndPoint;
  8625. info.proxyEP = m_proxyEndPoint;
  8626. info.agentcircuit = new sAgentCircuitData(RequestClientInfo());
  8627. return info;
  8628. }
  8629. public EndPoint GetClientEP()
  8630. {
  8631. return m_userEndPoint;
  8632. }
  8633. public void SetClientInfo(ClientInfo info)
  8634. {
  8635. m_PacketHandler.SetClientInfo(info);
  8636. }
  8637. #region Media Parcel Members
  8638. public void SendParcelMediaCommand(uint flags, ParcelMediaCommandEnum command, float time)
  8639. {
  8640. ParcelMediaCommandMessagePacket commandMessagePacket = new ParcelMediaCommandMessagePacket();
  8641. commandMessagePacket.CommandBlock.Flags = flags;
  8642. commandMessagePacket.CommandBlock.Command =(uint) command;
  8643. commandMessagePacket.CommandBlock.Time = time;
  8644. OutPacket(commandMessagePacket, ThrottleOutPacketType.Unknown);
  8645. }
  8646. public void SendParcelMediaUpdate(string mediaUrl, UUID mediaTextureID,
  8647. byte autoScale, string mediaType, string mediaDesc, int mediaWidth, int mediaHeight,
  8648. byte mediaLoop)
  8649. {
  8650. ParcelMediaUpdatePacket updatePacket = new ParcelMediaUpdatePacket();
  8651. updatePacket.DataBlock.MediaURL = Utils.StringToBytes(mediaUrl);
  8652. updatePacket.DataBlock.MediaID = mediaTextureID;
  8653. updatePacket.DataBlock.MediaAutoScale = autoScale;
  8654. updatePacket.DataBlockExtended.MediaType = Utils.StringToBytes(mediaType);
  8655. updatePacket.DataBlockExtended.MediaDesc = Utils.StringToBytes(mediaDesc);
  8656. updatePacket.DataBlockExtended.MediaWidth = mediaWidth;
  8657. updatePacket.DataBlockExtended.MediaHeight = mediaHeight;
  8658. updatePacket.DataBlockExtended.MediaLoop = mediaLoop;
  8659. OutPacket(updatePacket, ThrottleOutPacketType.Unknown);
  8660. }
  8661. #endregion
  8662. #region Camera
  8663. public void SendSetFollowCamProperties (UUID objectID, SortedDictionary<int, float> parameters)
  8664. {
  8665. SetFollowCamPropertiesPacket packet = (SetFollowCamPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.SetFollowCamProperties);
  8666. packet.ObjectData.ObjectID = objectID;
  8667. SetFollowCamPropertiesPacket.CameraPropertyBlock[] camPropBlock = new SetFollowCamPropertiesPacket.CameraPropertyBlock[parameters.Count];
  8668. uint idx = 0;
  8669. foreach (KeyValuePair<int, float> pair in parameters)
  8670. {
  8671. SetFollowCamPropertiesPacket.CameraPropertyBlock block = new SetFollowCamPropertiesPacket.CameraPropertyBlock();
  8672. block.Type = pair.Key;
  8673. block.Value = pair.Value;
  8674. camPropBlock[idx++] = block;
  8675. }
  8676. packet.CameraProperty = camPropBlock;
  8677. OutPacket(packet, ThrottleOutPacketType.Task);
  8678. }
  8679. public void SendClearFollowCamProperties (UUID objectID)
  8680. {
  8681. ClearFollowCamPropertiesPacket packet = (ClearFollowCamPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ClearFollowCamProperties);
  8682. packet.ObjectData.ObjectID = objectID;
  8683. OutPacket(packet, ThrottleOutPacketType.Task);
  8684. }
  8685. #endregion
  8686. public void SendRegionHandle(UUID regionID, ulong handle) {
  8687. RegionIDAndHandleReplyPacket reply = (RegionIDAndHandleReplyPacket)PacketPool.Instance.GetPacket(PacketType.RegionIDAndHandleReply);
  8688. reply.ReplyBlock.RegionID = regionID;
  8689. reply.ReplyBlock.RegionHandle = handle;
  8690. OutPacket(reply, ThrottleOutPacketType.Land);
  8691. }
  8692. public void SendParcelInfo(RegionInfo info, LandData land, UUID parcelID, uint x, uint y)
  8693. {
  8694. ParcelInfoReplyPacket reply = (ParcelInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelInfoReply);
  8695. reply.AgentData.AgentID = m_agentId;
  8696. reply.Data.ParcelID = parcelID;
  8697. reply.Data.OwnerID = land.OwnerID;
  8698. reply.Data.Name = Utils.StringToBytes(land.Name);
  8699. reply.Data.Desc = Utils.StringToBytes(land.Description);
  8700. reply.Data.ActualArea = land.Area;
  8701. reply.Data.BillableArea = land.Area; // TODO: what is this?
  8702. // Bit 0: Mature, bit 7: on sale, other bits: no idea
  8703. reply.Data.Flags = (byte)(
  8704. ((land.Flags & (uint)ParcelFlags.MaturePublish) != 0 ? (1 << 0) : 0) +
  8705. ((land.Flags & (uint)ParcelFlags.ForSale) != 0 ? (1 << 7) : 0));
  8706. Vector3 pos = land.UserLocation;
  8707. if (pos.Equals(Vector3.Zero))
  8708. {
  8709. pos = (land.AABBMax + land.AABBMin) * 0.5f;
  8710. }
  8711. reply.Data.GlobalX = info.RegionLocX * Constants.RegionSize + x;
  8712. reply.Data.GlobalY = info.RegionLocY * Constants.RegionSize + y;
  8713. reply.Data.GlobalZ = pos.Z;
  8714. reply.Data.SimName = Utils.StringToBytes(info.RegionName);
  8715. reply.Data.SnapshotID = land.SnapshotID;
  8716. reply.Data.Dwell = land.Dwell;
  8717. reply.Data.SalePrice = land.SalePrice;
  8718. reply.Data.AuctionID = (int)land.AuctionID;
  8719. OutPacket(reply, ThrottleOutPacketType.Land);
  8720. }
  8721. public void SendScriptTeleportRequest(string objName, string simName, Vector3 pos, Vector3 lookAt)
  8722. {
  8723. ScriptTeleportRequestPacket packet = (ScriptTeleportRequestPacket)PacketPool.Instance.GetPacket(PacketType.ScriptTeleportRequest);
  8724. packet.Data.ObjectName = Utils.StringToBytes(objName);
  8725. packet.Data.SimName = Utils.StringToBytes(simName);
  8726. packet.Data.SimPosition = pos;
  8727. packet.Data.LookAt = lookAt;
  8728. OutPacket(packet, ThrottleOutPacketType.Task);
  8729. }
  8730. public void SetClientOption(string option, string value)
  8731. {
  8732. switch (option)
  8733. {
  8734. case "ReliableIsImportant":
  8735. bool val;
  8736. if (bool.TryParse(value, out val))
  8737. m_PacketHandler.ReliableIsImportant = val;
  8738. break;
  8739. default:
  8740. break;
  8741. }
  8742. }
  8743. public string GetClientOption(string option)
  8744. {
  8745. switch (option)
  8746. {
  8747. case "ReliableIsImportant":
  8748. return m_PacketHandler.ReliableIsImportant.ToString();
  8749. default:
  8750. break;
  8751. }
  8752. return string.Empty;
  8753. }
  8754. public void SendDirPlacesReply(UUID queryID, DirPlacesReplyData[] data)
  8755. {
  8756. DirPlacesReplyPacket packet = (DirPlacesReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPlacesReply);
  8757. packet.AgentData = new DirPlacesReplyPacket.AgentDataBlock();
  8758. packet.QueryData = new DirPlacesReplyPacket.QueryDataBlock[1];
  8759. packet.QueryData[0] = new DirPlacesReplyPacket.QueryDataBlock();
  8760. packet.QueryReplies =
  8761. new DirPlacesReplyPacket.QueryRepliesBlock[data.Length];
  8762. packet.StatusData = new DirPlacesReplyPacket.StatusDataBlock[
  8763. data.Length];
  8764. packet.AgentData.AgentID = AgentId;
  8765. packet.QueryData[0].QueryID = queryID;
  8766. int i = 0;
  8767. foreach (DirPlacesReplyData d in data)
  8768. {
  8769. packet.QueryReplies[i] =
  8770. new DirPlacesReplyPacket.QueryRepliesBlock();
  8771. packet.StatusData[i] = new DirPlacesReplyPacket.StatusDataBlock();
  8772. packet.QueryReplies[i].ParcelID = d.parcelID;
  8773. packet.QueryReplies[i].Name = Utils.StringToBytes(d.name);
  8774. packet.QueryReplies[i].ForSale = d.forSale;
  8775. packet.QueryReplies[i].Auction = d.auction;
  8776. packet.QueryReplies[i].Dwell = d.dwell;
  8777. packet.StatusData[i].Status = d.Status;
  8778. i++;
  8779. }
  8780. OutPacket(packet, ThrottleOutPacketType.Task);
  8781. }
  8782. public void SendDirPeopleReply(UUID queryID, DirPeopleReplyData[] data)
  8783. {
  8784. DirPeopleReplyPacket packet = (DirPeopleReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPeopleReply);
  8785. packet.AgentData = new DirPeopleReplyPacket.AgentDataBlock();
  8786. packet.AgentData.AgentID = AgentId;
  8787. packet.QueryData = new DirPeopleReplyPacket.QueryDataBlock();
  8788. packet.QueryData.QueryID = queryID;
  8789. packet.QueryReplies = new DirPeopleReplyPacket.QueryRepliesBlock[
  8790. data.Length];
  8791. int i = 0;
  8792. foreach (DirPeopleReplyData d in data)
  8793. {
  8794. packet.QueryReplies[i] = new DirPeopleReplyPacket.QueryRepliesBlock();
  8795. packet.QueryReplies[i].AgentID = d.agentID;
  8796. packet.QueryReplies[i].FirstName =
  8797. Utils.StringToBytes(d.firstName);
  8798. packet.QueryReplies[i].LastName =
  8799. Utils.StringToBytes(d.lastName);
  8800. packet.QueryReplies[i].Group =
  8801. Utils.StringToBytes(d.group);
  8802. packet.QueryReplies[i].Online = d.online;
  8803. packet.QueryReplies[i].Reputation = d.reputation;
  8804. i++;
  8805. }
  8806. OutPacket(packet, ThrottleOutPacketType.Task);
  8807. }
  8808. public void SendDirEventsReply(UUID queryID, DirEventsReplyData[] data)
  8809. {
  8810. DirEventsReplyPacket packet = (DirEventsReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirEventsReply);
  8811. packet.AgentData = new DirEventsReplyPacket.AgentDataBlock();
  8812. packet.AgentData.AgentID = AgentId;
  8813. packet.QueryData = new DirEventsReplyPacket.QueryDataBlock();
  8814. packet.QueryData.QueryID = queryID;
  8815. packet.QueryReplies = new DirEventsReplyPacket.QueryRepliesBlock[
  8816. data.Length];
  8817. packet.StatusData = new DirEventsReplyPacket.StatusDataBlock[
  8818. data.Length];
  8819. int i = 0;
  8820. foreach (DirEventsReplyData d in data)
  8821. {
  8822. packet.QueryReplies[i] = new DirEventsReplyPacket.QueryRepliesBlock();
  8823. packet.StatusData[i] = new DirEventsReplyPacket.StatusDataBlock();
  8824. packet.QueryReplies[i].OwnerID = d.ownerID;
  8825. packet.QueryReplies[i].Name =
  8826. Utils.StringToBytes(d.name);
  8827. packet.QueryReplies[i].EventID = d.eventID;
  8828. packet.QueryReplies[i].Date =
  8829. Utils.StringToBytes(d.date);
  8830. packet.QueryReplies[i].UnixTime = d.unixTime;
  8831. packet.QueryReplies[i].EventFlags = d.eventFlags;
  8832. packet.StatusData[i].Status = d.Status;
  8833. i++;
  8834. }
  8835. OutPacket(packet, ThrottleOutPacketType.Task);
  8836. }
  8837. public void SendDirGroupsReply(UUID queryID, DirGroupsReplyData[] data)
  8838. {
  8839. DirGroupsReplyPacket packet = (DirGroupsReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirGroupsReply);
  8840. packet.AgentData = new DirGroupsReplyPacket.AgentDataBlock();
  8841. packet.AgentData.AgentID = AgentId;
  8842. packet.QueryData = new DirGroupsReplyPacket.QueryDataBlock();
  8843. packet.QueryData.QueryID = queryID;
  8844. packet.QueryReplies = new DirGroupsReplyPacket.QueryRepliesBlock[
  8845. data.Length];
  8846. int i = 0;
  8847. foreach (DirGroupsReplyData d in data)
  8848. {
  8849. packet.QueryReplies[i] = new DirGroupsReplyPacket.QueryRepliesBlock();
  8850. packet.QueryReplies[i].GroupID = d.groupID;
  8851. packet.QueryReplies[i].GroupName =
  8852. Utils.StringToBytes(d.groupName);
  8853. packet.QueryReplies[i].Members = d.members;
  8854. packet.QueryReplies[i].SearchOrder = d.searchOrder;
  8855. i++;
  8856. }
  8857. OutPacket(packet, ThrottleOutPacketType.Task);
  8858. }
  8859. public void SendDirClassifiedReply(UUID queryID, DirClassifiedReplyData[] data)
  8860. {
  8861. DirClassifiedReplyPacket packet = (DirClassifiedReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirClassifiedReply);
  8862. packet.AgentData = new DirClassifiedReplyPacket.AgentDataBlock();
  8863. packet.AgentData.AgentID = AgentId;
  8864. packet.QueryData = new DirClassifiedReplyPacket.QueryDataBlock();
  8865. packet.QueryData.QueryID = queryID;
  8866. packet.QueryReplies = new DirClassifiedReplyPacket.QueryRepliesBlock[
  8867. data.Length];
  8868. packet.StatusData = new DirClassifiedReplyPacket.StatusDataBlock[
  8869. data.Length];
  8870. int i = 0;
  8871. foreach (DirClassifiedReplyData d in data)
  8872. {
  8873. packet.QueryReplies[i] = new DirClassifiedReplyPacket.QueryRepliesBlock();
  8874. packet.StatusData[i] = new DirClassifiedReplyPacket.StatusDataBlock();
  8875. packet.QueryReplies[i].ClassifiedID = d.classifiedID;
  8876. packet.QueryReplies[i].Name =
  8877. Utils.StringToBytes(d.name);
  8878. packet.QueryReplies[i].ClassifiedFlags = d.classifiedFlags;
  8879. packet.QueryReplies[i].CreationDate = d.creationDate;
  8880. packet.QueryReplies[i].ExpirationDate = d.expirationDate;
  8881. packet.QueryReplies[i].PriceForListing = d.price;
  8882. packet.StatusData[i].Status = d.Status;
  8883. i++;
  8884. }
  8885. OutPacket(packet, ThrottleOutPacketType.Task);
  8886. }
  8887. public void SendDirLandReply(UUID queryID, DirLandReplyData[] data)
  8888. {
  8889. DirLandReplyPacket packet = (DirLandReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirLandReply);
  8890. packet.AgentData = new DirLandReplyPacket.AgentDataBlock();
  8891. packet.AgentData.AgentID = AgentId;
  8892. packet.QueryData = new DirLandReplyPacket.QueryDataBlock();
  8893. packet.QueryData.QueryID = queryID;
  8894. packet.QueryReplies = new DirLandReplyPacket.QueryRepliesBlock[
  8895. data.Length];
  8896. int i = 0;
  8897. foreach (DirLandReplyData d in data)
  8898. {
  8899. packet.QueryReplies[i] = new DirLandReplyPacket.QueryRepliesBlock();
  8900. packet.QueryReplies[i].ParcelID = d.parcelID;
  8901. packet.QueryReplies[i].Name =
  8902. Utils.StringToBytes(d.name);
  8903. packet.QueryReplies[i].Auction = d.auction;
  8904. packet.QueryReplies[i].ForSale = d.forSale;
  8905. packet.QueryReplies[i].SalePrice = d.salePrice;
  8906. packet.QueryReplies[i].ActualArea = d.actualArea;
  8907. i++;
  8908. }
  8909. OutPacket(packet, ThrottleOutPacketType.Task);
  8910. }
  8911. public void SendDirPopularReply(UUID queryID, DirPopularReplyData[] data)
  8912. {
  8913. DirPopularReplyPacket packet = (DirPopularReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPopularReply);
  8914. packet.AgentData = new DirPopularReplyPacket.AgentDataBlock();
  8915. packet.AgentData.AgentID = AgentId;
  8916. packet.QueryData = new DirPopularReplyPacket.QueryDataBlock();
  8917. packet.QueryData.QueryID = queryID;
  8918. packet.QueryReplies = new DirPopularReplyPacket.QueryRepliesBlock[
  8919. data.Length];
  8920. int i = 0;
  8921. foreach (DirPopularReplyData d in data)
  8922. {
  8923. packet.QueryReplies[i] = new DirPopularReplyPacket.QueryRepliesBlock();
  8924. packet.QueryReplies[i].ParcelID = d.parcelID;
  8925. packet.QueryReplies[i].Name =
  8926. Utils.StringToBytes(d.name);
  8927. packet.QueryReplies[i].Dwell = d.dwell;
  8928. i++;
  8929. }
  8930. OutPacket(packet, ThrottleOutPacketType.Task);
  8931. }
  8932. public void SendEventInfoReply(EventData data)
  8933. {
  8934. EventInfoReplyPacket packet = (EventInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.EventInfoReply);
  8935. packet.AgentData = new EventInfoReplyPacket.AgentDataBlock();
  8936. packet.AgentData.AgentID = AgentId;
  8937. packet.EventData = new EventInfoReplyPacket.EventDataBlock();
  8938. packet.EventData.EventID = data.eventID;
  8939. packet.EventData.Creator = Utils.StringToBytes(data.creator);
  8940. packet.EventData.Name = Utils.StringToBytes(data.name);
  8941. packet.EventData.Category = Utils.StringToBytes(data.category);
  8942. packet.EventData.Desc = Utils.StringToBytes(data.description);
  8943. packet.EventData.Date = Utils.StringToBytes(data.date);
  8944. packet.EventData.DateUTC = data.dateUTC;
  8945. packet.EventData.Duration = data.duration;
  8946. packet.EventData.Cover = data.cover;
  8947. packet.EventData.Amount = data.amount;
  8948. packet.EventData.SimName = Utils.StringToBytes(data.simName);
  8949. packet.EventData.GlobalPos = new Vector3d(data.globalPos);
  8950. packet.EventData.EventFlags = data.eventFlags;
  8951. OutPacket(packet, ThrottleOutPacketType.Task);
  8952. }
  8953. public void SendMapItemReply(mapItemReply[] replies, uint mapitemtype, uint flags)
  8954. {
  8955. MapItemReplyPacket mirplk = new MapItemReplyPacket();
  8956. mirplk.AgentData.AgentID = AgentId;
  8957. mirplk.RequestData.ItemType = mapitemtype;
  8958. mirplk.Data = new MapItemReplyPacket.DataBlock[replies.Length];
  8959. for (int i = 0; i < replies.Length; i++)
  8960. {
  8961. MapItemReplyPacket.DataBlock mrdata = new MapItemReplyPacket.DataBlock();
  8962. mrdata.X = replies[i].x;
  8963. mrdata.Y = replies[i].y;
  8964. mrdata.ID = replies[i].id;
  8965. mrdata.Extra = replies[i].Extra;
  8966. mrdata.Extra2 = replies[i].Extra2;
  8967. mrdata.Name = Utils.StringToBytes(replies[i].name);
  8968. mirplk.Data[i] = mrdata;
  8969. }
  8970. //m_log.Debug(mirplk.ToString());
  8971. OutPacket(mirplk, ThrottleOutPacketType.Task);
  8972. }
  8973. public void SendOfferCallingCard(UUID srcID, UUID transactionID)
  8974. {
  8975. // a bit special, as this uses AgentID to store the source instead
  8976. // of the destination. The destination (the receiver) goes into destID
  8977. OfferCallingCardPacket p = (OfferCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.OfferCallingCard);
  8978. p.AgentData.AgentID = srcID;
  8979. p.AgentData.SessionID = UUID.Zero;
  8980. p.AgentBlock.DestID = AgentId;
  8981. p.AgentBlock.TransactionID = transactionID;
  8982. OutPacket(p, ThrottleOutPacketType.Task);
  8983. }
  8984. public void SendAcceptCallingCard(UUID transactionID)
  8985. {
  8986. AcceptCallingCardPacket p = (AcceptCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.AcceptCallingCard);
  8987. p.AgentData.AgentID = AgentId;
  8988. p.AgentData.SessionID = UUID.Zero;
  8989. p.FolderData = new AcceptCallingCardPacket.FolderDataBlock[1];
  8990. p.FolderData[0] = new AcceptCallingCardPacket.FolderDataBlock();
  8991. p.FolderData[0].FolderID = UUID.Zero;
  8992. OutPacket(p, ThrottleOutPacketType.Task);
  8993. }
  8994. public void SendDeclineCallingCard(UUID transactionID)
  8995. {
  8996. DeclineCallingCardPacket p = (DeclineCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.DeclineCallingCard);
  8997. p.AgentData.AgentID = AgentId;
  8998. p.AgentData.SessionID = UUID.Zero;
  8999. p.TransactionBlock.TransactionID = transactionID;
  9000. OutPacket(p, ThrottleOutPacketType.Task);
  9001. }
  9002. public void SendTerminateFriend(UUID exFriendID)
  9003. {
  9004. TerminateFriendshipPacket p = (TerminateFriendshipPacket)PacketPool.Instance.GetPacket(PacketType.TerminateFriendship);
  9005. p.AgentData.AgentID = AgentId;
  9006. p.AgentData.SessionID = SessionId;
  9007. p.ExBlock.OtherID = exFriendID;
  9008. OutPacket(p, ThrottleOutPacketType.Task);
  9009. }
  9010. public void SendAvatarGroupsReply(UUID avatarID, GroupMembershipData[] data)
  9011. {
  9012. AvatarGroupsReplyPacket p = (AvatarGroupsReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarGroupsReply);
  9013. p.AgentData = new AvatarGroupsReplyPacket.AgentDataBlock();
  9014. p.AgentData.AgentID = AgentId;
  9015. p.AgentData.AvatarID = avatarID;
  9016. p.GroupData = new AvatarGroupsReplyPacket.GroupDataBlock[data.Length];
  9017. int i = 0;
  9018. foreach (GroupMembershipData m in data)
  9019. {
  9020. p.GroupData[i] = new AvatarGroupsReplyPacket.GroupDataBlock();
  9021. p.GroupData[i].GroupPowers = m.GroupPowers;
  9022. p.GroupData[i].AcceptNotices = m.AcceptNotices;
  9023. p.GroupData[i].GroupTitle = Utils.StringToBytes(m.GroupTitle);
  9024. p.GroupData[i].GroupID = m.GroupID;
  9025. p.GroupData[i].GroupName = Utils.StringToBytes(m.GroupName);
  9026. p.GroupData[i].GroupInsigniaID = m.GroupPicture;
  9027. i++;
  9028. }
  9029. p.NewGroupData = new AvatarGroupsReplyPacket.NewGroupDataBlock();
  9030. p.NewGroupData.ListInProfile = true;
  9031. OutPacket(p, ThrottleOutPacketType.Task);
  9032. }
  9033. public void SendJoinGroupReply(UUID groupID, bool success)
  9034. {
  9035. JoinGroupReplyPacket p = (JoinGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.JoinGroupReply);
  9036. p.AgentData = new JoinGroupReplyPacket.AgentDataBlock();
  9037. p.AgentData.AgentID = AgentId;
  9038. p.GroupData = new JoinGroupReplyPacket.GroupDataBlock();
  9039. p.GroupData.GroupID = groupID;
  9040. p.GroupData.Success = success;
  9041. OutPacket(p, ThrottleOutPacketType.Task);
  9042. }
  9043. public void SendEjectGroupMemberReply(UUID agentID, UUID groupID, bool success)
  9044. {
  9045. EjectGroupMemberReplyPacket p = (EjectGroupMemberReplyPacket)PacketPool.Instance.GetPacket(PacketType.EjectGroupMemberReply);
  9046. p.AgentData = new EjectGroupMemberReplyPacket.AgentDataBlock();
  9047. p.AgentData.AgentID = agentID;
  9048. p.GroupData = new EjectGroupMemberReplyPacket.GroupDataBlock();
  9049. p.GroupData.GroupID = groupID;
  9050. p.EjectData = new EjectGroupMemberReplyPacket.EjectDataBlock();
  9051. p.EjectData.Success = success;
  9052. OutPacket(p, ThrottleOutPacketType.Task);
  9053. }
  9054. public void SendLeaveGroupReply(UUID groupID, bool success)
  9055. {
  9056. LeaveGroupReplyPacket p = (LeaveGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.LeaveGroupReply);
  9057. p.AgentData = new LeaveGroupReplyPacket.AgentDataBlock();
  9058. p.AgentData.AgentID = AgentId;
  9059. p.GroupData = new LeaveGroupReplyPacket.GroupDataBlock();
  9060. p.GroupData.GroupID = groupID;
  9061. p.GroupData.Success = success;
  9062. OutPacket(p, ThrottleOutPacketType.Task);
  9063. }
  9064. public void SendAvatarClassifiedReply(UUID targetID, UUID[] classifiedID, string[] name)
  9065. {
  9066. if (classifiedID.Length != name.Length)
  9067. return;
  9068. AvatarClassifiedReplyPacket ac =
  9069. (AvatarClassifiedReplyPacket)PacketPool.Instance.GetPacket(
  9070. PacketType.AvatarClassifiedReply);
  9071. ac.AgentData = new AvatarClassifiedReplyPacket.AgentDataBlock();
  9072. ac.AgentData.AgentID = AgentId;
  9073. ac.AgentData.TargetID = targetID;
  9074. ac.Data = new AvatarClassifiedReplyPacket.DataBlock[classifiedID.Length];
  9075. int i;
  9076. for (i = 0 ; i < classifiedID.Length ; i++)
  9077. {
  9078. ac.Data[i].ClassifiedID = classifiedID[i];
  9079. ac.Data[i].Name = Utils.StringToBytes(name[i]);
  9080. }
  9081. OutPacket(ac, ThrottleOutPacketType.Task);
  9082. }
  9083. public void SendClassifiedInfoReply(UUID classifiedID, UUID creatorID, uint creationDate, uint expirationDate, uint category, string name, string description, UUID parcelID, uint parentEstate, UUID snapshotID, string simName, Vector3 globalPos, string parcelName, byte classifiedFlags, int price)
  9084. {
  9085. ClassifiedInfoReplyPacket cr =
  9086. (ClassifiedInfoReplyPacket)PacketPool.Instance.GetPacket(
  9087. PacketType.ClassifiedInfoReply);
  9088. cr.AgentData = new ClassifiedInfoReplyPacket.AgentDataBlock();
  9089. cr.AgentData.AgentID = AgentId;
  9090. cr.Data = new ClassifiedInfoReplyPacket.DataBlock();
  9091. cr.Data.ClassifiedID = classifiedID;
  9092. cr.Data.CreatorID = creatorID;
  9093. cr.Data.CreationDate = creationDate;
  9094. cr.Data.ExpirationDate = expirationDate;
  9095. cr.Data.Category = category;
  9096. cr.Data.Name = Utils.StringToBytes(name);
  9097. cr.Data.Desc = Utils.StringToBytes(description);
  9098. cr.Data.ParcelID = parcelID;
  9099. cr.Data.ParentEstate = parentEstate;
  9100. cr.Data.SnapshotID = snapshotID;
  9101. cr.Data.SimName = Utils.StringToBytes(simName);
  9102. cr.Data.PosGlobal = new Vector3d(globalPos);
  9103. cr.Data.ParcelName = Utils.StringToBytes(parcelName);
  9104. cr.Data.ClassifiedFlags = classifiedFlags;
  9105. cr.Data.PriceForListing = price;
  9106. OutPacket(cr, ThrottleOutPacketType.Task);
  9107. }
  9108. public void SendAgentDropGroup(UUID groupID)
  9109. {
  9110. AgentDropGroupPacket dg =
  9111. (AgentDropGroupPacket)PacketPool.Instance.GetPacket(
  9112. PacketType.AgentDropGroup);
  9113. dg.AgentData = new AgentDropGroupPacket.AgentDataBlock();
  9114. dg.AgentData.AgentID = AgentId;
  9115. dg.AgentData.GroupID = groupID;
  9116. OutPacket(dg, ThrottleOutPacketType.Task);
  9117. }
  9118. public void SendAvatarNotesReply(UUID targetID, string text)
  9119. {
  9120. AvatarNotesReplyPacket an =
  9121. (AvatarNotesReplyPacket)PacketPool.Instance.GetPacket(
  9122. PacketType.AvatarNotesReply);
  9123. an.AgentData = new AvatarNotesReplyPacket.AgentDataBlock();
  9124. an.AgentData.AgentID = AgentId;
  9125. an.Data = new AvatarNotesReplyPacket.DataBlock();
  9126. an.Data.TargetID = targetID;
  9127. an.Data.Notes = Utils.StringToBytes(text);
  9128. OutPacket(an, ThrottleOutPacketType.Task);
  9129. }
  9130. public void SendAvatarPicksReply(UUID targetID, Dictionary<UUID, string> picks)
  9131. {
  9132. AvatarPicksReplyPacket ap =
  9133. (AvatarPicksReplyPacket)PacketPool.Instance.GetPacket(
  9134. PacketType.AvatarPicksReply);
  9135. ap.AgentData = new AvatarPicksReplyPacket.AgentDataBlock();
  9136. ap.AgentData.AgentID = AgentId;
  9137. ap.AgentData.TargetID = targetID;
  9138. ap.Data = new AvatarPicksReplyPacket.DataBlock[picks.Count];
  9139. int i = 0;
  9140. foreach (KeyValuePair<UUID, string> pick in picks)
  9141. {
  9142. ap.Data[i] = new AvatarPicksReplyPacket.DataBlock();
  9143. ap.Data[i].PickID = pick.Key;
  9144. ap.Data[i].PickName = Utils.StringToBytes(pick.Value);
  9145. i++;
  9146. }
  9147. OutPacket(ap, ThrottleOutPacketType.Task);
  9148. }
  9149. public void SendAvatarClassifiedReply(UUID targetID, Dictionary<UUID, string> classifieds)
  9150. {
  9151. AvatarClassifiedReplyPacket ac =
  9152. (AvatarClassifiedReplyPacket)PacketPool.Instance.GetPacket(
  9153. PacketType.AvatarClassifiedReply);
  9154. ac.AgentData = new AvatarClassifiedReplyPacket.AgentDataBlock();
  9155. ac.AgentData.AgentID = AgentId;
  9156. ac.AgentData.TargetID = targetID;
  9157. ac.Data = new AvatarClassifiedReplyPacket.DataBlock[classifieds.Count];
  9158. int i = 0;
  9159. foreach (KeyValuePair<UUID, string> classified in classifieds)
  9160. {
  9161. ac.Data[i] = new AvatarClassifiedReplyPacket.DataBlock();
  9162. ac.Data[i].ClassifiedID = classified.Key;
  9163. ac.Data[i].Name = Utils.StringToBytes(classified.Value);
  9164. i++;
  9165. }
  9166. OutPacket(ac, ThrottleOutPacketType.Task);
  9167. }
  9168. public void SendParcelDwellReply(int localID, UUID parcelID, float dwell)
  9169. {
  9170. ParcelDwellReplyPacket pd =
  9171. (ParcelDwellReplyPacket)PacketPool.Instance.GetPacket(
  9172. PacketType.ParcelDwellReply);
  9173. pd.AgentData = new ParcelDwellReplyPacket.AgentDataBlock();
  9174. pd.AgentData.AgentID = AgentId;
  9175. pd.Data = new ParcelDwellReplyPacket.DataBlock();
  9176. pd.Data.LocalID = localID;
  9177. pd.Data.ParcelID = parcelID;
  9178. pd.Data.Dwell = dwell;
  9179. OutPacket(pd, ThrottleOutPacketType.Land);
  9180. }
  9181. public void SendUserInfoReply(bool imViaEmail, bool visible, string email)
  9182. {
  9183. UserInfoReplyPacket ur =
  9184. (UserInfoReplyPacket)PacketPool.Instance.GetPacket(
  9185. PacketType.UserInfoReply);
  9186. string Visible = "hidden";
  9187. if (visible)
  9188. Visible = "default";
  9189. ur.AgentData = new UserInfoReplyPacket.AgentDataBlock();
  9190. ur.AgentData.AgentID = AgentId;
  9191. ur.UserData = new UserInfoReplyPacket.UserDataBlock();
  9192. ur.UserData.IMViaEMail = imViaEmail;
  9193. ur.UserData.DirectoryVisibility = Utils.StringToBytes(Visible);
  9194. ur.UserData.EMail = Utils.StringToBytes(email);
  9195. OutPacket(ur, ThrottleOutPacketType.Task);
  9196. }
  9197. public void KillEndDone()
  9198. {
  9199. KillPacket kp = new KillPacket();
  9200. OutPacket(kp, ThrottleOutPacketType.Task | ThrottleOutPacketType.LowPriority);
  9201. }
  9202. #region IClientCore
  9203. private readonly Dictionary<Type, object> m_clientInterfaces = new Dictionary<Type, object>();
  9204. /// <summary>
  9205. /// Register an interface on this client, should only be called in the constructor.
  9206. /// </summary>
  9207. /// <typeparam name="T"></typeparam>
  9208. /// <param name="iface"></param>
  9209. protected void RegisterInterface<T>(T iface)
  9210. {
  9211. lock (m_clientInterfaces)
  9212. {
  9213. if (!m_clientInterfaces.ContainsKey(typeof(T)))
  9214. {
  9215. m_clientInterfaces.Add(typeof(T), iface);
  9216. }
  9217. }
  9218. }
  9219. protected virtual void RegisterInterfaces()
  9220. {
  9221. RegisterInterface<IClientIM>(this);
  9222. RegisterInterface<IClientChat>(this);
  9223. RegisterInterface<IClientIPEndpoint>(this);
  9224. }
  9225. public bool TryGet<T>(out T iface)
  9226. {
  9227. if (m_clientInterfaces.ContainsKey(typeof(T)))
  9228. {
  9229. iface = (T)m_clientInterfaces[typeof(T)];
  9230. return true;
  9231. }
  9232. iface = default(T);
  9233. return false;
  9234. }
  9235. public T Get<T>()
  9236. {
  9237. return (T)m_clientInterfaces[typeof(T)];
  9238. }
  9239. public void Disconnect(string reason)
  9240. {
  9241. Kick(reason);
  9242. Thread.Sleep(1000);
  9243. Close(true);
  9244. }
  9245. public void Disconnect()
  9246. {
  9247. Close(true);
  9248. }
  9249. #endregion
  9250. public void RefreshGroupMembership()
  9251. {
  9252. if (m_GroupsModule != null)
  9253. {
  9254. GroupMembershipData[] GroupMembership =
  9255. m_GroupsModule.GetMembershipData(AgentId);
  9256. m_groupPowers.Clear();
  9257. for (int i = 0; i < GroupMembership.Length; i++)
  9258. {
  9259. m_groupPowers[GroupMembership[i].GroupID] = GroupMembership[i].GroupPowers;
  9260. }
  9261. }
  9262. }
  9263. public void SendCreateGroupReply(UUID groupID, bool success, string message)
  9264. {
  9265. CreateGroupReplyPacket createGroupReply = (CreateGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.CreateGroupReply);
  9266. createGroupReply.AgentData =
  9267. new CreateGroupReplyPacket.AgentDataBlock();
  9268. createGroupReply.ReplyData =
  9269. new CreateGroupReplyPacket.ReplyDataBlock();
  9270. createGroupReply.AgentData.AgentID = AgentId;
  9271. createGroupReply.ReplyData.GroupID = groupID;
  9272. createGroupReply.ReplyData.Success = success;
  9273. createGroupReply.ReplyData.Message = Utils.StringToBytes(message);
  9274. OutPacket(createGroupReply, ThrottleOutPacketType.Task);
  9275. }
  9276. public void SendUseCachedMuteList()
  9277. {
  9278. UseCachedMuteListPacket useCachedMuteList = (UseCachedMuteListPacket)PacketPool.Instance.GetPacket(PacketType.UseCachedMuteList);
  9279. useCachedMuteList.AgentData = new UseCachedMuteListPacket.AgentDataBlock();
  9280. useCachedMuteList.AgentData.AgentID = AgentId;
  9281. OutPacket(useCachedMuteList, ThrottleOutPacketType.Task);
  9282. }
  9283. public void SendMuteListUpdate(string filename)
  9284. {
  9285. MuteListUpdatePacket muteListUpdate = (MuteListUpdatePacket)PacketPool.Instance.GetPacket(PacketType.MuteListUpdate);
  9286. muteListUpdate.MuteData = new MuteListUpdatePacket.MuteDataBlock();
  9287. muteListUpdate.MuteData.AgentID = AgentId;
  9288. muteListUpdate.MuteData.Filename = Utils.StringToBytes(filename);
  9289. OutPacket(muteListUpdate, ThrottleOutPacketType.Task);
  9290. }
  9291. public void SendPickInfoReply(UUID pickID,UUID creatorID, bool topPick, UUID parcelID, string name, string desc, UUID snapshotID, string user, string originalName, string simName, Vector3 posGlobal, int sortOrder, bool enabled)
  9292. {
  9293. PickInfoReplyPacket pickInfoReply = (PickInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.PickInfoReply);
  9294. pickInfoReply.AgentData = new PickInfoReplyPacket.AgentDataBlock();
  9295. pickInfoReply.AgentData.AgentID = AgentId;
  9296. pickInfoReply.Data = new PickInfoReplyPacket.DataBlock();
  9297. pickInfoReply.Data.PickID = pickID;
  9298. pickInfoReply.Data.CreatorID = creatorID;
  9299. pickInfoReply.Data.TopPick = topPick;
  9300. pickInfoReply.Data.ParcelID = parcelID;
  9301. pickInfoReply.Data.Name = Utils.StringToBytes(name);
  9302. pickInfoReply.Data.Desc = Utils.StringToBytes(desc);
  9303. pickInfoReply.Data.SnapshotID = snapshotID;
  9304. pickInfoReply.Data.User = Utils.StringToBytes(user);
  9305. pickInfoReply.Data.OriginalName = Utils.StringToBytes(originalName);
  9306. pickInfoReply.Data.SimName = Utils.StringToBytes(simName);
  9307. pickInfoReply.Data.PosGlobal = new Vector3d(posGlobal);
  9308. pickInfoReply.Data.SortOrder = sortOrder;
  9309. pickInfoReply.Data.Enabled = enabled;
  9310. OutPacket(pickInfoReply, ThrottleOutPacketType.Task);
  9311. }
  9312. public string Report()
  9313. {
  9314. LLPacketHandler handler = (LLPacketHandler) m_PacketHandler;
  9315. return handler.PacketQueue.GetStats();
  9316. }
  9317. public string XReport(string uptime, string version)
  9318. {
  9319. return "";
  9320. }
  9321. public void MakeAssetRequest(TransferRequestPacket transferRequest)
  9322. {
  9323. UUID requestID = UUID.Zero;
  9324. if (transferRequest.TransferInfo.SourceType == 2)
  9325. {
  9326. //direct asset request
  9327. requestID = new UUID(transferRequest.TransferInfo.Params, 0);
  9328. }
  9329. else if (transferRequest.TransferInfo.SourceType == 3)
  9330. {
  9331. //inventory asset request
  9332. requestID = new UUID(transferRequest.TransferInfo.Params, 80);
  9333. //m_log.Debug("asset request " + requestID);
  9334. }
  9335. //check to see if asset is in local cache, if not we need to request it from asset server.
  9336. //m_log.Debug("asset request " + requestID);
  9337. m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived);
  9338. }
  9339. protected void AssetReceived(string id, Object sender, AssetBase asset)
  9340. {
  9341. TransferRequestPacket transferRequest = (TransferRequestPacket)sender;
  9342. UUID requestID = UUID.Zero;
  9343. byte source = 2;
  9344. if (transferRequest.TransferInfo.SourceType == 2)
  9345. {
  9346. //direct asset request
  9347. requestID = new UUID(transferRequest.TransferInfo.Params, 0);
  9348. }
  9349. else if (transferRequest.TransferInfo.SourceType == 3)
  9350. {
  9351. //inventory asset request
  9352. requestID = new UUID(transferRequest.TransferInfo.Params, 80);
  9353. source = 3;
  9354. //m_log.Debug("asset request " + requestID);
  9355. }
  9356. // FIXME: We never tell the client about assets which do not exist when requested by this transfer mechanism, which can't be right.
  9357. if (null == asset)
  9358. {
  9359. //m_log.DebugFormat("[ASSET CACHE]: Asset transfer request for asset which is {0} already known to be missing. Dropping", requestID);
  9360. return;
  9361. }
  9362. // Scripts cannot be retrieved by direct request
  9363. if (transferRequest.TransferInfo.SourceType == 2 && asset.Type == 10)
  9364. return;
  9365. // The asset is known to exist and is in our cache, so add it to the AssetRequests list
  9366. AssetRequestToClient req = new AssetRequestToClient();
  9367. req.AssetInf = asset;
  9368. req.AssetRequestSource = source;
  9369. req.IsTextureRequest = false;
  9370. req.NumPackets = CalculateNumPackets(asset.Data);
  9371. req.Params = transferRequest.TransferInfo.Params;
  9372. req.RequestAssetID = requestID;
  9373. req.TransferRequestID = transferRequest.TransferInfo.TransferID;
  9374. SendAsset(req);
  9375. }
  9376. /// <summary>
  9377. /// Calculate the number of packets required to send the asset to the client.
  9378. /// </summary>
  9379. /// <param name="data"></param>
  9380. /// <returns></returns>
  9381. private static int CalculateNumPackets(byte[] data)
  9382. {
  9383. const uint m_maxPacketSize = 600;
  9384. int numPackets = 1;
  9385. if (data.LongLength > m_maxPacketSize)
  9386. {
  9387. // over max number of bytes so split up file
  9388. long restData = data.LongLength - m_maxPacketSize;
  9389. int restPackets = (int)((restData + m_maxPacketSize - 1) / m_maxPacketSize);
  9390. numPackets += restPackets;
  9391. }
  9392. return numPackets;
  9393. }
  9394. #region IClientIPEndpoint Members
  9395. public IPAddress EndPoint
  9396. {
  9397. get
  9398. {
  9399. if (m_userEndPoint is IPEndPoint)
  9400. {
  9401. IPEndPoint ep = (IPEndPoint)m_userEndPoint;
  9402. return ep.Address;
  9403. }
  9404. return null;
  9405. }
  9406. }
  9407. #endregion
  9408. }
  9409. }