LLClientView.cs 405 KB

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