LSL_Api.cs 721 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Collections.Specialized;
  31. using System.Diagnostics;
  32. using System.Drawing;
  33. using System.Drawing.Imaging;
  34. using System.Globalization;
  35. using System.Runtime.Remoting.Lifetime;
  36. using System.Text;
  37. using System.Threading;
  38. using System.Text.RegularExpressions;
  39. using System.Timers;
  40. using Nini.Config;
  41. using log4net;
  42. using OpenMetaverse;
  43. using OpenMetaverse.Assets;
  44. using OpenMetaverse.StructuredData; // LitJson is hidden on this
  45. using OpenMetaverse.Packets;
  46. using OpenMetaverse.Rendering;
  47. using OpenSim;
  48. using OpenSim.Framework;
  49. using OpenSim.Region.CoreModules;
  50. using OpenSim.Region.CoreModules.World.Land;
  51. using OpenSim.Region.CoreModules.World.Terrain;
  52. using OpenSim.Region.Framework.Interfaces;
  53. using OpenSim.Region.Framework.Scenes;
  54. using OpenSim.Region.Framework.Scenes.Serialization;
  55. using OpenSim.Region.Framework.Scenes.Animation;
  56. using OpenSim.Region.Framework.Scenes.Scripting;
  57. using OpenSim.Region.PhysicsModules.SharedBase;
  58. using OpenSim.Region.ScriptEngine.Shared;
  59. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  60. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  61. using OpenSim.Region.ScriptEngine.Interfaces;
  62. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  63. using OpenSim.Services.Interfaces;
  64. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  65. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  66. using PrimType = OpenSim.Region.Framework.Scenes.PrimType;
  67. using AssetLandmark = OpenSim.Framework.AssetLandmark;
  68. using RegionFlags = OpenSim.Framework.RegionFlags;
  69. using RegionInfo = OpenSim.Framework.RegionInfo;
  70. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  71. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  72. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  73. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  74. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  75. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  76. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  77. using System.Reflection;
  78. using Timer = System.Timers.Timer;
  79. using System.Linq;
  80. using PermissionMask = OpenSim.Framework.PermissionMask;
  81. namespace OpenSim.Region.ScriptEngine.Shared.Api
  82. {
  83. // MUST be a ref type
  84. public class UserInfoCacheEntry
  85. {
  86. public int time;
  87. public UserAccount account;
  88. public PresenceInfo pinfo;
  89. }
  90. /// <summary>
  91. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  92. /// </summary>
  93. public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
  94. {
  95. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  96. public int LlRequestAgentDataCacheTimeoutMs { get; set; }
  97. protected IScriptEngine m_ScriptEngine;
  98. protected SceneObjectPart m_host;
  99. /// <summary>
  100. /// The item that hosts this script
  101. /// </summary>
  102. protected TaskInventoryItem m_item;
  103. protected bool throwErrorOnNotImplemented = false;
  104. protected AsyncCommandManager AsyncCommands = null;
  105. protected float m_ScriptDelayFactor = 1.0f;
  106. protected float m_ScriptDistanceFactor = 1.0f;
  107. protected float m_MinTimerInterval = 0.5f;
  108. protected float m_recoilScaleFactor = 0.0f;
  109. protected double m_timer = Util.GetTimeStampMS();
  110. protected bool m_waitingForScriptAnswer = false;
  111. protected bool m_automaticLinkPermission = false;
  112. protected IMessageTransferModule m_TransferModule = null;
  113. protected int m_notecardLineReadCharsMax = 255;
  114. protected int m_scriptConsoleChannel = 0;
  115. protected bool m_scriptConsoleChannelEnabled = false;
  116. protected bool m_debuggerSafe = false;
  117. protected IUrlModule m_UrlModule = null;
  118. protected IMaterialsModule m_materialsModule = null;
  119. protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>();
  120. protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
  121. protected int m_sleepMsOnSetTexture = 200;
  122. protected int m_sleepMsOnSetLinkTexture = 200;
  123. protected int m_sleepMsOnScaleTexture = 200;
  124. protected int m_sleepMsOnOffsetTexture = 200;
  125. protected int m_sleepMsOnRotateTexture = 200;
  126. protected int m_sleepMsOnSetPos = 200;
  127. protected int m_sleepMsOnSetRot = 200;
  128. protected int m_sleepMsOnSetLocalRot = 200;
  129. protected int m_sleepMsOnPreloadSound = 1000;
  130. protected int m_sleepMsOnMakeExplosion = 100;
  131. protected int m_sleepMsOnMakeFountain = 100;
  132. protected int m_sleepMsOnMakeSmoke = 100;
  133. protected int m_sleepMsOnMakeFire = 100;
  134. protected int m_sleepMsOnRezAtRoot = 100;
  135. protected int m_sleepMsOnInstantMessage = 2000;
  136. protected int m_sleepMsOnEmail = 20000;
  137. protected int m_sleepMsOnCreateLink = 1000;
  138. protected int m_sleepMsOnGiveInventory = 3000;
  139. protected int m_sleepMsOnRequestAgentData = 100;
  140. protected int m_sleepMsOnRequestInventoryData = 1000;
  141. protected int m_sleepMsOnSetDamage = 5000;
  142. protected int m_sleepMsOnTextBox = 1000;
  143. protected int m_sleepMsOnAdjustSoundVolume = 100;
  144. protected int m_sleepMsOnEjectFromLand = 1000;
  145. protected int m_sleepMsOnAddToLandPassList = 100;
  146. protected int m_sleepMsOnDialog = 1000;
  147. protected int m_sleepMsOnRemoteLoadScript = 3000;
  148. protected int m_sleepMsOnRemoteLoadScriptPin = 3000;
  149. protected int m_sleepMsOnOpenRemoteDataChannel = 1000;
  150. protected int m_sleepMsOnSendRemoteData = 3000;
  151. protected int m_sleepMsOnRemoteDataReply = 3000;
  152. protected int m_sleepMsOnCloseRemoteDataChannel = 1000;
  153. protected int m_sleepMsOnSetPrimitiveParams = 200;
  154. protected int m_sleepMsOnSetLinkPrimitiveParams = 200;
  155. protected int m_sleepMsOnXorBase64Strings = 300;
  156. protected int m_sleepMsOnSetParcelMusicURL = 2000;
  157. protected int m_sleepMsOnGetPrimMediaParams = 1000;
  158. protected int m_sleepMsOnGetLinkMedia = 1000;
  159. protected int m_sleepMsOnSetPrimMediaParams = 1000;
  160. protected int m_sleepMsOnSetLinkMedia = 1000;
  161. protected int m_sleepMsOnClearPrimMedia = 1000;
  162. protected int m_sleepMsOnClearLinkMedia = 1000;
  163. protected int m_sleepMsOnRequestSimulatorData = 1000;
  164. protected int m_sleepMsOnLoadURL = 10000;
  165. protected int m_sleepMsOnParcelMediaCommandList = 2000;
  166. protected int m_sleepMsOnParcelMediaQuery = 2000;
  167. protected int m_sleepMsOnModPow = 1000;
  168. protected int m_sleepMsOnSetPrimURL = 2000;
  169. protected int m_sleepMsOnRefreshPrimURL = 20000;
  170. protected int m_sleepMsOnMapDestination = 1000;
  171. protected int m_sleepMsOnAddToLandBanList = 100;
  172. protected int m_sleepMsOnRemoveFromLandPassList = 100;
  173. protected int m_sleepMsOnRemoveFromLandBanList = 100;
  174. protected int m_sleepMsOnResetLandBanList = 100;
  175. protected int m_sleepMsOnResetLandPassList = 100;
  176. protected int m_sleepMsOnGetParcelPrimOwners = 2000;
  177. protected int m_sleepMsOnGetNumberOfNotecardLines = 100;
  178. protected int m_sleepMsOnGetNotecardLine = 100;
  179. protected string m_internalObjectHost = "lsl.opensim.local";
  180. protected bool m_restrictEmail = false;
  181. protected ISoundModule m_SoundModule = null;
  182. protected float m_avatarHeightCorrection = 0.2f;
  183. protected bool m_useSimpleBoxesInGetBoundingBox = false;
  184. protected bool m_addStatsInGetBoundingBox = false;
  185. //LSL Avatar Bounding Box (lABB), lower (1) and upper (2),
  186. //standing (Std), Groundsitting (Grs), Sitting (Sit),
  187. //along X, Y and Z axes, constants (0) and coefficients (1)
  188. protected float m_lABB1StdX0 = -0.275f;
  189. protected float m_lABB2StdX0 = 0.275f;
  190. protected float m_lABB1StdY0 = -0.35f;
  191. protected float m_lABB2StdY0 = 0.35f;
  192. protected float m_lABB1StdZ0 = -0.1f;
  193. protected float m_lABB1StdZ1 = -0.5f;
  194. protected float m_lABB2StdZ0 = 0.1f;
  195. protected float m_lABB2StdZ1 = 0.5f;
  196. protected float m_lABB1GrsX0 = -0.3875f;
  197. protected float m_lABB2GrsX0 = 0.3875f;
  198. protected float m_lABB1GrsY0 = -0.5f;
  199. protected float m_lABB2GrsY0 = 0.5f;
  200. protected float m_lABB1GrsZ0 = -0.05f;
  201. protected float m_lABB1GrsZ1 = -0.375f;
  202. protected float m_lABB2GrsZ0 = 0.5f;
  203. protected float m_lABB2GrsZ1 = 0.0f;
  204. protected float m_lABB1SitX0 = -0.5875f;
  205. protected float m_lABB2SitX0 = 0.1875f;
  206. protected float m_lABB1SitY0 = -0.35f;
  207. protected float m_lABB2SitY0 = 0.35f;
  208. protected float m_lABB1SitZ0 = -0.35f;
  209. protected float m_lABB1SitZ1 = -0.375f;
  210. protected float m_lABB2SitZ0 = -0.25f;
  211. protected float m_lABB2SitZ1 = 0.25f;
  212. protected float m_primSafetyCoeffX = 2.414214f;
  213. protected float m_primSafetyCoeffY = 2.414214f;
  214. protected float m_primSafetyCoeffZ = 1.618034f;
  215. protected bool m_useCastRayV3 = false;
  216. protected float m_floatToleranceInCastRay = 0.00001f;
  217. protected float m_floatTolerance2InCastRay = 0.001f;
  218. protected DetailLevel m_primLodInCastRay = DetailLevel.Medium;
  219. protected DetailLevel m_sculptLodInCastRay = DetailLevel.Medium;
  220. protected DetailLevel m_meshLodInCastRay = DetailLevel.Highest;
  221. protected DetailLevel m_avatarLodInCastRay = DetailLevel.Medium;
  222. protected int m_maxHitsInCastRay = 16;
  223. protected int m_maxHitsPerPrimInCastRay = 16;
  224. protected int m_maxHitsPerObjectInCastRay = 16;
  225. protected bool m_detectExitsInCastRay = false;
  226. protected bool m_doAttachmentsInCastRay = false;
  227. protected int m_msThrottleInCastRay = 200;
  228. protected int m_msPerRegionInCastRay = 40;
  229. protected int m_msPerAvatarInCastRay = 10;
  230. protected int m_msMinInCastRay = 2;
  231. protected int m_msMaxInCastRay = 40;
  232. protected static List<CastRayCall> m_castRayCalls = new List<CastRayCall>();
  233. protected bool m_useMeshCacheInCastRay = true;
  234. protected static Dictionary<ulong, FacetedMesh> m_cachedMeshes = new Dictionary<ulong, FacetedMesh>();
  235. // protected Timer m_ShoutSayTimer;
  236. protected int m_SayShoutCount = 0;
  237. DateTime m_lastSayShoutCheck;
  238. private Dictionary<string, string> MovementAnimationsForLSL =
  239. new Dictionary<string, string> {
  240. {"CROUCH", "Crouching"},
  241. {"CROUCHWALK", "CrouchWalking"},
  242. {"FALLDOWN", "Falling Down"},
  243. {"FLY", "Flying"},
  244. {"FLYSLOW", "FlyingSlow"},
  245. {"HOVER", "Hovering"},
  246. {"HOVER_UP", "Hovering Up"},
  247. {"HOVER_DOWN", "Hovering Down"},
  248. {"JUMP", "Jumping"},
  249. {"LAND", "Landing"},
  250. {"PREJUMP", "PreJumping"},
  251. {"RUN", "Running"},
  252. {"SIT","Sitting"},
  253. {"SITGROUND","Sitting on Ground"},
  254. {"STAND", "Standing"},
  255. {"STANDUP", "Standing Up"},
  256. {"STRIDE","Striding"},
  257. {"SOFT_LAND", "Soft Landing"},
  258. {"TURNLEFT", "Turning Left"},
  259. {"TURNRIGHT", "Turning Right"},
  260. {"WALK", "Walking"}
  261. };
  262. //An array of HTTP/1.1 headers that are not allowed to be used
  263. //as custom headers by llHTTPRequest.
  264. private string[] HttpStandardHeaders =
  265. {
  266. "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language",
  267. "Accept-Ranges", "Age", "Allow", "Authorization", "Cache-Control",
  268. "Connection", "Content-Encoding", "Content-Language",
  269. "Content-Length", "Content-Location", "Content-MD5",
  270. "Content-Range", "Content-Type", "Date", "ETag", "Expect",
  271. "Expires", "From", "Host", "If-Match", "If-Modified-Since",
  272. "If-None-Match", "If-Range", "If-Unmodified-Since", "Last-Modified",
  273. "Location", "Max-Forwards", "Pragma", "Proxy-Authenticate",
  274. "Proxy-Authorization", "Range", "Referer", "Retry-After", "Server",
  275. "TE", "Trailer", "Transfer-Encoding", "Upgrade", "User-Agent",
  276. "Vary", "Via", "Warning", "WWW-Authenticate"
  277. };
  278. public void Initialize(
  279. IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
  280. {
  281. m_lastSayShoutCheck = DateTime.UtcNow;
  282. m_ScriptEngine = scriptEngine;
  283. m_host = host;
  284. m_item = item;
  285. m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
  286. LoadConfig();
  287. m_TransferModule =
  288. m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
  289. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  290. m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>();
  291. m_materialsModule = m_ScriptEngine.World.RequestModuleInterface<IMaterialsModule>();
  292. AsyncCommands = new AsyncCommandManager(m_ScriptEngine);
  293. }
  294. /// <summary>
  295. /// Load configuration items that affect script, object and run-time behavior. */
  296. /// </summary>
  297. private void LoadConfig()
  298. {
  299. LlRequestAgentDataCacheTimeoutMs = 20000;
  300. IConfig seConfig = m_ScriptEngine.Config;
  301. if (seConfig != null)
  302. {
  303. m_ScriptDelayFactor =
  304. seConfig.GetFloat("ScriptDelayFactor", m_ScriptDelayFactor);
  305. m_ScriptDistanceFactor =
  306. seConfig.GetFloat("ScriptDistanceLimitFactor", m_ScriptDistanceFactor);
  307. m_MinTimerInterval =
  308. seConfig.GetFloat("MinTimerInterval", m_MinTimerInterval);
  309. m_automaticLinkPermission =
  310. seConfig.GetBoolean("AutomaticLinkPermission", m_automaticLinkPermission);
  311. m_notecardLineReadCharsMax =
  312. seConfig.GetInt("NotecardLineReadCharsMax", m_notecardLineReadCharsMax);
  313. // Rezzing an object with a velocity can create recoil. This feature seems to have been
  314. // removed from recent versions of SL. The code computes recoil (vel*mass) and scales
  315. // it by this factor. May be zero to turn off recoil all together.
  316. m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor);
  317. }
  318. if (m_notecardLineReadCharsMax > 65535)
  319. m_notecardLineReadCharsMax = 65535;
  320. // load limits for particular subsystems.
  321. IConfigSource seConfigSource = m_ScriptEngine.ConfigSource;
  322. if (seConfigSource != null)
  323. {
  324. IConfig lslConfig = seConfigSource.Configs["LL-Functions"];
  325. if (lslConfig != null)
  326. {
  327. m_restrictEmail = lslConfig.GetBoolean("RestrictEmail", m_restrictEmail);
  328. m_avatarHeightCorrection = lslConfig.GetFloat("AvatarHeightCorrection", m_avatarHeightCorrection);
  329. m_useSimpleBoxesInGetBoundingBox = lslConfig.GetBoolean("UseSimpleBoxesInGetBoundingBox", m_useSimpleBoxesInGetBoundingBox);
  330. m_addStatsInGetBoundingBox = lslConfig.GetBoolean("AddStatsInGetBoundingBox", m_addStatsInGetBoundingBox);
  331. m_lABB1StdX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingXconst", m_lABB1StdX0);
  332. m_lABB2StdX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingXconst", m_lABB2StdX0);
  333. m_lABB1StdY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingYconst", m_lABB1StdY0);
  334. m_lABB2StdY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingYconst", m_lABB2StdY0);
  335. m_lABB1StdZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZconst", m_lABB1StdZ0);
  336. m_lABB1StdZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZcoeff", m_lABB1StdZ1);
  337. m_lABB2StdZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZconst", m_lABB2StdZ0);
  338. m_lABB2StdZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZcoeff", m_lABB2StdZ1);
  339. m_lABB1GrsX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingXconst", m_lABB1GrsX0);
  340. m_lABB2GrsX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingXconst", m_lABB2GrsX0);
  341. m_lABB1GrsY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingYconst", m_lABB1GrsY0);
  342. m_lABB2GrsY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingYconst", m_lABB2GrsY0);
  343. m_lABB1GrsZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZconst", m_lABB1GrsZ0);
  344. m_lABB1GrsZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZcoeff", m_lABB1GrsZ1);
  345. m_lABB2GrsZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZconst", m_lABB2GrsZ0);
  346. m_lABB2GrsZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZcoeff", m_lABB2GrsZ1);
  347. m_lABB1SitX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingXconst", m_lABB1SitX0);
  348. m_lABB2SitX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingXconst", m_lABB2SitX0);
  349. m_lABB1SitY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingYconst", m_lABB1SitY0);
  350. m_lABB2SitY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingYconst", m_lABB2SitY0);
  351. m_lABB1SitZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZconst", m_lABB1SitZ0);
  352. m_lABB1SitZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZcoeff", m_lABB1SitZ1);
  353. m_lABB2SitZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZconst", m_lABB2SitZ0);
  354. m_lABB2SitZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZcoeff", m_lABB2SitZ1);
  355. m_primSafetyCoeffX = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientX", m_primSafetyCoeffX);
  356. m_primSafetyCoeffY = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientY", m_primSafetyCoeffY);
  357. m_primSafetyCoeffZ = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientZ", m_primSafetyCoeffZ);
  358. m_useCastRayV3 = lslConfig.GetBoolean("UseLlCastRayV3", m_useCastRayV3);
  359. m_floatToleranceInCastRay = lslConfig.GetFloat("FloatToleranceInLlCastRay", m_floatToleranceInCastRay);
  360. m_floatTolerance2InCastRay = lslConfig.GetFloat("FloatTolerance2InLlCastRay", m_floatTolerance2InCastRay);
  361. m_primLodInCastRay = (DetailLevel)lslConfig.GetInt("PrimDetailLevelInLlCastRay", (int)m_primLodInCastRay);
  362. m_sculptLodInCastRay = (DetailLevel)lslConfig.GetInt("SculptDetailLevelInLlCastRay", (int)m_sculptLodInCastRay);
  363. m_meshLodInCastRay = (DetailLevel)lslConfig.GetInt("MeshDetailLevelInLlCastRay", (int)m_meshLodInCastRay);
  364. m_avatarLodInCastRay = (DetailLevel)lslConfig.GetInt("AvatarDetailLevelInLlCastRay", (int)m_avatarLodInCastRay);
  365. m_maxHitsInCastRay = lslConfig.GetInt("MaxHitsInLlCastRay", m_maxHitsInCastRay);
  366. m_maxHitsPerPrimInCastRay = lslConfig.GetInt("MaxHitsPerPrimInLlCastRay", m_maxHitsPerPrimInCastRay);
  367. m_maxHitsPerObjectInCastRay = lslConfig.GetInt("MaxHitsPerObjectInLlCastRay", m_maxHitsPerObjectInCastRay);
  368. m_detectExitsInCastRay = lslConfig.GetBoolean("DetectExitHitsInLlCastRay", m_detectExitsInCastRay);
  369. m_doAttachmentsInCastRay = lslConfig.GetBoolean("DoAttachmentsInLlCastRay", m_doAttachmentsInCastRay);
  370. m_msThrottleInCastRay = lslConfig.GetInt("ThrottleTimeInMsInLlCastRay", m_msThrottleInCastRay);
  371. m_msPerRegionInCastRay = lslConfig.GetInt("AvailableTimeInMsPerRegionInLlCastRay", m_msPerRegionInCastRay);
  372. m_msPerAvatarInCastRay = lslConfig.GetInt("AvailableTimeInMsPerAvatarInLlCastRay", m_msPerAvatarInCastRay);
  373. m_msMinInCastRay = lslConfig.GetInt("RequiredAvailableTimeInMsInLlCastRay", m_msMinInCastRay);
  374. m_msMaxInCastRay = lslConfig.GetInt("MaximumAvailableTimeInMsInLlCastRay", m_msMaxInCastRay);
  375. m_useMeshCacheInCastRay = lslConfig.GetBoolean("UseMeshCacheInLlCastRay", m_useMeshCacheInCastRay);
  376. }
  377. IConfig smtpConfig = seConfigSource.Configs["SMTP"];
  378. if (smtpConfig != null)
  379. {
  380. // there's an smtp config, so load in the snooze time.
  381. EMAIL_PAUSE_TIME = smtpConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
  382. m_internalObjectHost = smtpConfig.GetString("internal_object_host", m_internalObjectHost);
  383. }
  384. }
  385. m_sleepMsOnEmail = EMAIL_PAUSE_TIME * 1000;
  386. }
  387. public override Object InitializeLifetimeService()
  388. {
  389. ILease lease = (ILease)base.InitializeLifetimeService();
  390. if (lease.CurrentState == LeaseState.Initial)
  391. {
  392. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  393. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  394. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  395. }
  396. return lease;
  397. }
  398. protected SceneObjectPart MonitoringObject()
  399. {
  400. UUID m = m_host.ParentGroup.MonitoringObject;
  401. if (m == UUID.Zero)
  402. return null;
  403. SceneObjectPart p = m_ScriptEngine.World.GetSceneObjectPart(m);
  404. if (p == null)
  405. m_host.ParentGroup.MonitoringObject = UUID.Zero;
  406. return p;
  407. }
  408. protected virtual void ScriptSleep(int delay)
  409. {
  410. delay = (int)(delay * m_ScriptDelayFactor);
  411. if (delay < 10)
  412. return;
  413. Sleep(delay);
  414. }
  415. protected virtual void Sleep(int delay)
  416. {
  417. if (m_item == null) // Some unit tests don't set this
  418. Thread.Sleep(delay);
  419. else
  420. m_ScriptEngine.SleepScript(m_item.ItemID, delay);
  421. }
  422. /// <summary>
  423. /// Check for co-operative termination.
  424. /// </summary>
  425. /// <param name='delay'>If called with 0, then just the check is performed with no wait.</param>
  426. public Scene World
  427. {
  428. get { return m_ScriptEngine.World; }
  429. }
  430. [DebuggerNonUserCode]
  431. public void state(string newState)
  432. {
  433. m_ScriptEngine.SetState(m_item.ItemID, newState);
  434. }
  435. /// <summary>
  436. /// Reset the named script. The script must be present
  437. /// in the same prim.
  438. /// </summary>
  439. [DebuggerNonUserCode]
  440. public void llResetScript()
  441. {
  442. m_host.AddScriptLPS(1);
  443. // We need to tell the URL module, if we hav one, to release
  444. // the allocated URLs
  445. if (m_UrlModule != null)
  446. m_UrlModule.ScriptRemoved(m_item.ItemID);
  447. m_ScriptEngine.ApiResetScript(m_item.ItemID);
  448. }
  449. public void llResetOtherScript(string name)
  450. {
  451. UUID item;
  452. if ((item = GetScriptByName(name)) == UUID.Zero)
  453. {
  454. m_host.AddScriptLPS(1);
  455. Error("llResetOtherScript", "Can't find script '" + name + "'");
  456. return;
  457. }
  458. if(item == m_item.ItemID)
  459. llResetScript();
  460. else
  461. {
  462. m_host.AddScriptLPS(1);
  463. m_ScriptEngine.ResetScript(item);
  464. }
  465. }
  466. public LSL_Integer llGetScriptState(string name)
  467. {
  468. UUID item;
  469. m_host.AddScriptLPS(1);
  470. if ((item = GetScriptByName(name)) != UUID.Zero)
  471. {
  472. return m_ScriptEngine.GetScriptState(item) ?1:0;
  473. }
  474. Error("llGetScriptState", "Can't find script '" + name + "'");
  475. // If we didn't find it, then it's safe to
  476. // assume it is not running.
  477. return 0;
  478. }
  479. public void llSetScriptState(string name, int run)
  480. {
  481. UUID item;
  482. m_host.AddScriptLPS(1);
  483. // These functions are supposed to be robust,
  484. // so get the state one step at a time.
  485. if ((item = GetScriptByName(name)) != UUID.Zero)
  486. {
  487. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true, item == m_item.ItemID);
  488. }
  489. else
  490. {
  491. Error("llSetScriptState", "Can't find script '" + name + "'");
  492. }
  493. }
  494. public List<ScenePresence> GetLinkAvatars(int linkType)
  495. {
  496. List<ScenePresence> ret = new List<ScenePresence>();
  497. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  498. return ret;
  499. // List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
  500. // this needs check
  501. List<ScenePresence> avs = m_host.ParentGroup.GetSittingAvatars();
  502. switch (linkType)
  503. {
  504. case ScriptBaseClass.LINK_SET:
  505. return avs;
  506. case ScriptBaseClass.LINK_ROOT:
  507. return ret;
  508. case ScriptBaseClass.LINK_ALL_OTHERS:
  509. return avs;
  510. case ScriptBaseClass.LINK_ALL_CHILDREN:
  511. return avs;
  512. case ScriptBaseClass.LINK_THIS:
  513. return ret;
  514. default:
  515. if (linkType < 0)
  516. return ret;
  517. int partCount = m_host.ParentGroup.GetPartCount();
  518. if (linkType <= partCount)
  519. {
  520. return ret;
  521. }
  522. else
  523. {
  524. linkType = linkType - partCount;
  525. if (linkType > avs.Count)
  526. {
  527. return ret;
  528. }
  529. else
  530. {
  531. ret.Add(avs[linkType-1]);
  532. return ret;
  533. }
  534. }
  535. }
  536. }
  537. /// <summary>
  538. /// Get a given link entity from a linkset (linked objects and any sitting avatars).
  539. /// </summary>
  540. /// <remarks>
  541. /// If there are any ScenePresence's in the linkset (i.e. because they are sat upon one of the prims), then
  542. /// these are counted as extra entities that correspond to linknums beyond the number of prims in the linkset.
  543. /// The ScenePresences receive linknums in the order in which they sat.
  544. /// </remarks>
  545. /// <returns>
  546. /// The link entity. null if not found.
  547. /// </returns>
  548. /// <param name='part'></param>
  549. /// <param name='linknum'>
  550. /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4).
  551. /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned.
  552. /// If the linkset has one entity and a linknum of zero is given, then the single entity is returned. If any
  553. /// positive integer is given in this case then null is returned.
  554. /// If the linkset has more than one entity and a linknum greater than zero but equal to or less than the number
  555. /// of entities, then the entity which corresponds to that linknum is returned.
  556. /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then
  557. /// null is returned.
  558. /// </param>
  559. public ISceneEntity GetLinkEntity(SceneObjectPart part, int linknum)
  560. {
  561. if (linknum < 0)
  562. {
  563. if (linknum == ScriptBaseClass.LINK_THIS)
  564. return part;
  565. else
  566. return null;
  567. }
  568. int actualPrimCount = part.ParentGroup.PrimCount;
  569. List<ScenePresence> sittingAvatars = part.ParentGroup.GetSittingAvatars();
  570. int adjustedPrimCount = actualPrimCount + sittingAvatars.Count;
  571. // Special case for a single prim. In this case the linknum is zero. However, this will not match a single
  572. // prim that has any avatars sat upon it (in which case the root prim is link 1).
  573. if (linknum == 0)
  574. {
  575. if (actualPrimCount == 1 && sittingAvatars.Count == 0)
  576. return part;
  577. return null;
  578. }
  579. // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but
  580. // here we must match 1 (ScriptBaseClass.LINK_ROOT).
  581. else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1)
  582. {
  583. if (sittingAvatars.Count > 0)
  584. return part.ParentGroup.RootPart;
  585. else
  586. return null;
  587. }
  588. else if (linknum <= adjustedPrimCount)
  589. {
  590. if (linknum <= actualPrimCount)
  591. {
  592. return part.ParentGroup.GetLinkNumPart(linknum);
  593. }
  594. else
  595. {
  596. return sittingAvatars[linknum - actualPrimCount - 1];
  597. }
  598. }
  599. else
  600. {
  601. return null;
  602. }
  603. }
  604. public List<SceneObjectPart> GetLinkParts(int linkType)
  605. {
  606. return GetLinkParts(m_host, linkType);
  607. }
  608. public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
  609. {
  610. List<SceneObjectPart> ret = new List<SceneObjectPart>();
  611. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  612. return ret;
  613. switch (linkType)
  614. {
  615. case ScriptBaseClass.LINK_SET:
  616. return new List<SceneObjectPart>(part.ParentGroup.Parts);
  617. case ScriptBaseClass.LINK_ROOT:
  618. ret.Add(part.ParentGroup.RootPart);
  619. return ret;
  620. case ScriptBaseClass.LINK_ALL_OTHERS:
  621. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  622. if (ret.Contains(part))
  623. ret.Remove(part);
  624. return ret;
  625. case ScriptBaseClass.LINK_ALL_CHILDREN:
  626. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  627. if (ret.Contains(part.ParentGroup.RootPart))
  628. ret.Remove(part.ParentGroup.RootPart);
  629. return ret;
  630. case ScriptBaseClass.LINK_THIS:
  631. ret.Add(part);
  632. return ret;
  633. default:
  634. if (linkType < 0)
  635. return ret;
  636. SceneObjectPart target = part.ParentGroup.GetLinkNumPart(linkType);
  637. if (target == null)
  638. return ret;
  639. ret.Add(target);
  640. return ret;
  641. }
  642. }
  643. public List<ISceneEntity> GetLinkEntities(int linkType)
  644. {
  645. return GetLinkEntities(m_host, linkType);
  646. }
  647. public List<ISceneEntity> GetLinkEntities(SceneObjectPart part, int linkType)
  648. {
  649. List<ISceneEntity> ret;
  650. switch (linkType)
  651. {
  652. case ScriptBaseClass.LINK_SET:
  653. return new List<ISceneEntity>(part.ParentGroup.Parts);
  654. case ScriptBaseClass.LINK_ROOT:
  655. return new List<ISceneEntity>() { part.ParentGroup.RootPart };
  656. case ScriptBaseClass.LINK_ALL_OTHERS:
  657. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  658. if (ret.Contains(part))
  659. ret.Remove(part);
  660. return ret;
  661. case ScriptBaseClass.LINK_ALL_CHILDREN:
  662. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  663. if (ret.Contains(part.ParentGroup.RootPart))
  664. ret.Remove(part.ParentGroup.RootPart);
  665. List<ScenePresence> avs = part.ParentGroup.GetSittingAvatars();
  666. if(avs!= null && avs.Count > 0)
  667. ret.AddRange(avs);
  668. return ret;
  669. case ScriptBaseClass.LINK_THIS:
  670. return new List<ISceneEntity>() { part };
  671. default:
  672. if (linkType < 0)
  673. return new List<ISceneEntity>();
  674. ISceneEntity target = GetLinkEntity(part, linkType);
  675. if (target == null)
  676. return new List<ISceneEntity>();
  677. return new List<ISceneEntity>() { target };
  678. }
  679. }
  680. //These are the implementations of the various ll-functions used by the LSL scripts.
  681. public LSL_Float llSin(double f)
  682. {
  683. m_host.AddScriptLPS(1);
  684. return (double)Math.Sin(f);
  685. }
  686. public LSL_Float llCos(double f)
  687. {
  688. m_host.AddScriptLPS(1);
  689. return Math.Cos(f);
  690. }
  691. public LSL_Float llTan(double f)
  692. {
  693. m_host.AddScriptLPS(1);
  694. return Math.Tan(f);
  695. }
  696. public LSL_Float llAtan2(LSL_Float x, LSL_Float y)
  697. {
  698. m_host.AddScriptLPS(1);
  699. return Math.Atan2(x, y);
  700. }
  701. public LSL_Float llSqrt(double f)
  702. {
  703. m_host.AddScriptLPS(1);
  704. return Math.Sqrt(f);
  705. }
  706. public LSL_Float llPow(double fbase, double fexponent)
  707. {
  708. m_host.AddScriptLPS(1);
  709. return (double)Math.Pow(fbase, fexponent);
  710. }
  711. public LSL_Integer llAbs(LSL_Integer i)
  712. {
  713. // changed to replicate LSL behaviour whereby minimum int value is returned untouched.
  714. m_host.AddScriptLPS(1);
  715. if (i == Int32.MinValue)
  716. return i;
  717. else
  718. return (int)Math.Abs(i);
  719. }
  720. public LSL_Float llFabs(double f)
  721. {
  722. m_host.AddScriptLPS(1);
  723. return (double)Math.Abs(f);
  724. }
  725. public LSL_Float llFrand(double mag)
  726. {
  727. m_host.AddScriptLPS(1);
  728. lock (Util.RandomClass)
  729. {
  730. return Util.RandomClass.NextDouble() * mag;
  731. }
  732. }
  733. public LSL_Integer llFloor(double f)
  734. {
  735. m_host.AddScriptLPS(1);
  736. return (int)Math.Floor(f);
  737. }
  738. public LSL_Integer llCeil(double f)
  739. {
  740. m_host.AddScriptLPS(1);
  741. return (int)Math.Ceiling(f);
  742. }
  743. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  744. public LSL_Integer llRound(double f)
  745. {
  746. m_host.AddScriptLPS(1);
  747. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  748. }
  749. //This next group are vector operations involving squaring and square root. ckrinke
  750. public LSL_Float llVecMag(LSL_Vector v)
  751. {
  752. m_host.AddScriptLPS(1);
  753. return LSL_Vector.Mag(v);
  754. }
  755. public LSL_Vector llVecNorm(LSL_Vector v)
  756. {
  757. m_host.AddScriptLPS(1);
  758. return LSL_Vector.Norm(v);
  759. }
  760. private double VecDist(LSL_Vector a, LSL_Vector b)
  761. {
  762. double dx = a.x - b.x;
  763. double dy = a.y - b.y;
  764. double dz = a.z - b.z;
  765. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  766. }
  767. public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
  768. {
  769. m_host.AddScriptLPS(1);
  770. return VecDist(a, b);
  771. }
  772. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  773. // Utility function for llRot2Euler
  774. public LSL_Vector llRot2Euler(LSL_Rotation q1)
  775. {
  776. m_host.AddScriptLPS(1);
  777. LSL_Vector eul = new LSL_Vector();
  778. double sqw = q1.s*q1.s;
  779. double sqx = q1.x*q1.x;
  780. double sqy = q1.z*q1.z;
  781. double sqz = q1.y*q1.y;
  782. double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
  783. double test = q1.x*q1.z + q1.y*q1.s;
  784. if (test > 0.4999*unit) { // singularity at north pole
  785. eul.z = 2 * Math.Atan2(q1.x,q1.s);
  786. eul.y = Math.PI/2;
  787. eul.x = 0;
  788. return eul;
  789. }
  790. if (test < -0.4999*unit) { // singularity at south pole
  791. eul.z = -2 * Math.Atan2(q1.x,q1.s);
  792. eul.y = -Math.PI/2;
  793. eul.x = 0;
  794. return eul;
  795. }
  796. eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
  797. eul.y = Math.Asin(2*test/unit);
  798. eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
  799. return eul;
  800. }
  801. /* From wiki:
  802. The Euler angle vector (in radians) is converted to a rotation by doing the rotations around the 3 axes
  803. in Z, Y, X order. So llEuler2Rot(<1.0, 2.0, 3.0> * DEG_TO_RAD) generates a rotation by taking the zero rotation,
  804. a vector pointing along the X axis, first rotating it 3 degrees around the global Z axis, then rotating the resulting
  805. vector 2 degrees around the global Y axis, and finally rotating that 1 degree around the global X axis.
  806. */
  807. /* How we arrived at this llEuler2Rot
  808. *
  809. * Experiment in SL to determine conventions:
  810. * llEuler2Rot(<PI,0,0>)=<1,0,0,0>
  811. * llEuler2Rot(<0,PI,0>)=<0,1,0,0>
  812. * llEuler2Rot(<0,0,PI>)=<0,0,1,0>
  813. *
  814. * Important facts about Quaternions
  815. * - multiplication is non-commutative (a*b != b*a)
  816. * - http://en.wikipedia.org/wiki/Quaternion#Basis_multiplication
  817. *
  818. * Above SL experiment gives (c1,c2,c3,s1,s2,s3 as defined in our llEuler2Rot):
  819. * Qx = c1+i*s1
  820. * Qy = c2+j*s2;
  821. * Qz = c3+k*s3;
  822. *
  823. * Rotations applied in order (from above) Z, Y, X
  824. * Q = (Qz * Qy) * Qx
  825. * ((c1+i*s1)*(c2+j*s2))*(c3+k*s3)
  826. * (c1*c2+i*s1*c2+j*c1*s2+ij*s1*s2)*(c3+k*s3)
  827. * (c1*c2+i*s1*c2+j*c1*s2+k*s1*s2)*(c3+k*s3)
  828. * c1*c2*c3+i*s1*c2*c3+j*c1*s2*c3+k*s1*s2*c3+k*c1*c2*s3+ik*s1*c2*s3+jk*c1*s2*s3+kk*s1*s2*s3
  829. * c1*c2*c3+i*s1*c2*c3+j*c1*s2*c3+k*s1*s2*c3+k*c1*c2*s3 -j*s1*c2*s3 +i*c1*s2*s3 -s1*s2*s3
  830. * regroup: x=i*(s1*c2*c3+c1*s2*s3)
  831. * y=j*(c1*s2*c3-s1*c2*s3)
  832. * z=k*(s1*s2*c3+c1*c2*s3)
  833. * s= c1*c2*c3-s1*s2*s3
  834. *
  835. * This implementation agrees with the functions found here:
  836. * http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions
  837. * And with the results in SL.
  838. *
  839. * It's also possible to calculate llEuler2Rot by direct multiplication of
  840. * the Qz, Qy, and Qx vectors (as above - and done in the "accurate" function
  841. * from the wiki).
  842. * Apparently in some cases this is better from a numerical precision perspective?
  843. */
  844. public LSL_Rotation llEuler2Rot(LSL_Vector v)
  845. {
  846. m_host.AddScriptLPS(1);
  847. double x,y,z,s;
  848. v.x *= 0.5;
  849. v.y *= 0.5;
  850. v.z *= 0.5;
  851. double c1 = Math.Cos(v.x);
  852. double c2 = Math.Cos(v.y);
  853. double c1c2 = c1 * c2;
  854. double s1 = Math.Sin(v.x);
  855. double s2 = Math.Sin(v.y);
  856. double s1s2 = s1 * s2;
  857. double c1s2 = c1 * s2;
  858. double s1c2 = s1 * c2;
  859. double c3 = Math.Cos(v.z);
  860. double s3 = Math.Sin(v.z);
  861. x = s1c2 * c3 + c1s2 * s3;
  862. y = c1s2 * c3 - s1c2 * s3;
  863. z = s1s2 * c3 + c1c2 * s3;
  864. s = c1c2 * c3 - s1s2 * s3;
  865. return new LSL_Rotation(x, y, z, s);
  866. }
  867. public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
  868. {
  869. m_host.AddScriptLPS(1);
  870. double s;
  871. double tr = fwd.x + left.y + up.z + 1.0;
  872. if (tr >= 1.0)
  873. {
  874. s = 0.5 / Math.Sqrt(tr);
  875. return new LSL_Rotation(
  876. (left.z - up.y) * s,
  877. (up.x - fwd.z) * s,
  878. (fwd.y - left.x) * s,
  879. 0.25 / s);
  880. }
  881. else
  882. {
  883. double max = (left.y > up.z) ? left.y : up.z;
  884. if (max < fwd.x)
  885. {
  886. s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
  887. double x = s * 0.5;
  888. s = 0.5 / s;
  889. return new LSL_Rotation(
  890. x,
  891. (fwd.y + left.x) * s,
  892. (up.x + fwd.z) * s,
  893. (left.z - up.y) * s);
  894. }
  895. else if (max == left.y)
  896. {
  897. s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
  898. double y = s * 0.5;
  899. s = 0.5 / s;
  900. return new LSL_Rotation(
  901. (fwd.y + left.x) * s,
  902. y,
  903. (left.z + up.y) * s,
  904. (up.x - fwd.z) * s);
  905. }
  906. else
  907. {
  908. s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
  909. double z = s * 0.5;
  910. s = 0.5 / s;
  911. return new LSL_Rotation(
  912. (up.x + fwd.z) * s,
  913. (left.z + up.y) * s,
  914. z,
  915. (fwd.y - left.x) * s);
  916. }
  917. }
  918. }
  919. public LSL_Vector llRot2Fwd(LSL_Rotation r)
  920. {
  921. m_host.AddScriptLPS(1);
  922. double x, y, z, m;
  923. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  924. // m is always greater than zero
  925. // if m is not equal to 1 then Rotation needs to be normalized
  926. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  927. {
  928. m = 1.0 / Math.Sqrt(m);
  929. r.x *= m;
  930. r.y *= m;
  931. r.z *= m;
  932. r.s *= m;
  933. }
  934. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  935. x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
  936. y = 2 * (r.x * r.y + r.z * r.s);
  937. z = 2 * (r.x * r.z - r.y * r.s);
  938. return (new LSL_Vector(x, y, z));
  939. }
  940. public LSL_Vector llRot2Left(LSL_Rotation r)
  941. {
  942. m_host.AddScriptLPS(1);
  943. double x, y, z, m;
  944. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  945. // m is always greater than zero
  946. // if m is not equal to 1 then Rotation needs to be normalized
  947. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  948. {
  949. m = 1.0 / Math.Sqrt(m);
  950. r.x *= m;
  951. r.y *= m;
  952. r.z *= m;
  953. r.s *= m;
  954. }
  955. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  956. x = 2 * (r.x * r.y - r.z * r.s);
  957. y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
  958. z = 2 * (r.x * r.s + r.y * r.z);
  959. return (new LSL_Vector(x, y, z));
  960. }
  961. public LSL_Vector llRot2Up(LSL_Rotation r)
  962. {
  963. m_host.AddScriptLPS(1);
  964. double x, y, z, m;
  965. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  966. // m is always greater than zero
  967. // if m is not equal to 1 then Rotation needs to be normalized
  968. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  969. {
  970. m = 1.0 / Math.Sqrt(m);
  971. r.x *= m;
  972. r.y *= m;
  973. r.z *= m;
  974. r.s *= m;
  975. }
  976. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  977. x = 2 * (r.x * r.z + r.y * r.s);
  978. y = 2 * (-r.x * r.s + r.y * r.z);
  979. z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
  980. return (new LSL_Vector(x, y, z));
  981. }
  982. public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b)
  983. {
  984. //A and B should both be normalized
  985. m_host.AddScriptLPS(1);
  986. /* This method is more accurate than the SL one, and thus causes problems
  987. for scripts that deal with the SL inaccuracy around 180-degrees -.- .._.
  988. double dotProduct = LSL_Vector.Dot(a, b);
  989. LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
  990. double magProduct = LSL_Vector.Mag(a) * LSL_Vector.Mag(b);
  991. double angle = Math.Acos(dotProduct / magProduct);
  992. LSL_Vector axis = LSL_Vector.Norm(crossProduct);
  993. double s = Math.Sin(angle / 2);
  994. double x = axis.x * s;
  995. double y = axis.y * s;
  996. double z = axis.z * s;
  997. double w = Math.Cos(angle / 2);
  998. if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w))
  999. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  1000. return new LSL_Rotation((float)x, (float)y, (float)z, (float)w);
  1001. */
  1002. // This method mimics the 180 errors found in SL
  1003. // See www.euclideanspace.com... angleBetween
  1004. LSL_Vector vec_a = a;
  1005. LSL_Vector vec_b = b;
  1006. // Eliminate zero length
  1007. LSL_Float vec_a_mag = LSL_Vector.Mag(vec_a);
  1008. LSL_Float vec_b_mag = LSL_Vector.Mag(vec_b);
  1009. if (vec_a_mag < 0.00001 ||
  1010. vec_b_mag < 0.00001)
  1011. {
  1012. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  1013. }
  1014. // Normalize
  1015. vec_a = llVecNorm(vec_a);
  1016. vec_b = llVecNorm(vec_b);
  1017. // Calculate axis and rotation angle
  1018. LSL_Vector axis = vec_a % vec_b;
  1019. LSL_Float cos_theta = vec_a * vec_b;
  1020. // Check if parallel
  1021. if (cos_theta > 0.99999)
  1022. {
  1023. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  1024. }
  1025. // Check if anti-parallel
  1026. else if (cos_theta < -0.99999)
  1027. {
  1028. LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (vec_a.x / (vec_a * vec_a) * vec_a);
  1029. if (LSL_Vector.Mag(orthog_axis) < 0.000001) orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
  1030. return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
  1031. }
  1032. else // other rotation
  1033. {
  1034. LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
  1035. axis = llVecNorm(axis);
  1036. double x, y, z, s, t;
  1037. s = Math.Cos(theta);
  1038. t = Math.Sin(theta);
  1039. x = axis.x * t;
  1040. y = axis.y * t;
  1041. z = axis.z * t;
  1042. return new LSL_Rotation(x,y,z,s);
  1043. }
  1044. }
  1045. public void llWhisper(int channelID, string text)
  1046. {
  1047. m_host.AddScriptLPS(1);
  1048. if (text.Length > 1023)
  1049. text = text.Substring(0, 1023);
  1050. World.SimChat(Utils.StringToBytes(text),
  1051. ChatTypeEnum.Whisper, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  1052. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1053. if (wComm != null)
  1054. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text);
  1055. }
  1056. private void CheckSayShoutTime()
  1057. {
  1058. DateTime now = DateTime.UtcNow;
  1059. if ((now - m_lastSayShoutCheck).Ticks > 10000000) // 1sec
  1060. {
  1061. m_lastSayShoutCheck = now;
  1062. m_SayShoutCount = 0;
  1063. }
  1064. else
  1065. m_SayShoutCount++;
  1066. }
  1067. public void llSay(int channelID, string text)
  1068. {
  1069. m_host.AddScriptLPS(1);
  1070. if (channelID == 0)
  1071. // m_SayShoutCount++;
  1072. CheckSayShoutTime();
  1073. if (m_SayShoutCount >= 11)
  1074. ScriptSleep(2000);
  1075. if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
  1076. {
  1077. Console.WriteLine(text);
  1078. }
  1079. else
  1080. {
  1081. if (text.Length > 1023)
  1082. text = text.Substring(0, 1023);
  1083. World.SimChat(Utils.StringToBytes(text),
  1084. ChatTypeEnum.Say, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  1085. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1086. if (wComm != null)
  1087. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, text);
  1088. }
  1089. }
  1090. public void llShout(int channelID, string text)
  1091. {
  1092. m_host.AddScriptLPS(1);
  1093. if (channelID == 0)
  1094. // m_SayShoutCount++;
  1095. CheckSayShoutTime();
  1096. if (m_SayShoutCount >= 11)
  1097. ScriptSleep(2000);
  1098. if (text.Length > 1023)
  1099. text = text.Substring(0, 1023);
  1100. World.SimChat(Utils.StringToBytes(text),
  1101. ChatTypeEnum.Shout, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1102. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1103. if (wComm != null)
  1104. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, text);
  1105. }
  1106. public void llRegionSay(int channelID, string text)
  1107. {
  1108. if (channelID == 0)
  1109. {
  1110. Error("llRegionSay", "Cannot use on channel 0");
  1111. return;
  1112. }
  1113. if (text.Length > 1023)
  1114. text = text.Substring(0, 1023);
  1115. m_host.AddScriptLPS(1);
  1116. // debug channel is also sent to avatars
  1117. if (channelID == ScriptBaseClass.DEBUG_CHANNEL)
  1118. {
  1119. World.SimChat(Utils.StringToBytes(text),
  1120. ChatTypeEnum.Shout, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1121. }
  1122. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1123. if (wComm != null)
  1124. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text);
  1125. }
  1126. public void llRegionSayTo(string target, int channel, string msg)
  1127. {
  1128. if (msg.Length > 1023)
  1129. msg = msg.Substring(0, 1023);
  1130. m_host.AddScriptLPS(1);
  1131. if (channel == ScriptBaseClass.DEBUG_CHANNEL)
  1132. return;
  1133. UUID TargetID;
  1134. UUID.TryParse(target, out TargetID);
  1135. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1136. if (wComm != null)
  1137. wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
  1138. }
  1139. public LSL_Integer llListen(int channelID, string name, string ID, string msg)
  1140. {
  1141. m_host.AddScriptLPS(1);
  1142. UUID keyID;
  1143. UUID.TryParse(ID, out keyID);
  1144. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1145. if (wComm != null)
  1146. return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
  1147. else
  1148. return -1;
  1149. }
  1150. public void llListenControl(int number, int active)
  1151. {
  1152. m_host.AddScriptLPS(1);
  1153. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1154. if (wComm != null)
  1155. wComm.ListenControl(m_item.ItemID, number, active);
  1156. }
  1157. public void llListenRemove(int number)
  1158. {
  1159. m_host.AddScriptLPS(1);
  1160. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1161. if (wComm != null)
  1162. wComm.ListenRemove(m_item.ItemID, number);
  1163. }
  1164. public void llSensor(string name, string id, int type, double range, double arc)
  1165. {
  1166. m_host.AddScriptLPS(1);
  1167. UUID keyID = UUID.Zero;
  1168. UUID.TryParse(id, out keyID);
  1169. AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
  1170. }
  1171. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  1172. {
  1173. m_host.AddScriptLPS(1);
  1174. UUID keyID = UUID.Zero;
  1175. UUID.TryParse(id, out keyID);
  1176. AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
  1177. }
  1178. public void llSensorRemove()
  1179. {
  1180. m_host.AddScriptLPS(1);
  1181. AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
  1182. }
  1183. public string resolveName(UUID objecUUID)
  1184. {
  1185. // try avatar username surname
  1186. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, objecUUID);
  1187. if (account != null)
  1188. {
  1189. string avatarname = account.Name;
  1190. return avatarname;
  1191. }
  1192. // try an scene object
  1193. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  1194. if (SOP != null)
  1195. {
  1196. string objectname = SOP.Name;
  1197. return objectname;
  1198. }
  1199. EntityBase SensedObject;
  1200. World.Entities.TryGetValue(objecUUID, out SensedObject);
  1201. if (SensedObject == null)
  1202. {
  1203. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  1204. if (groups != null)
  1205. {
  1206. GroupRecord gr = groups.GetGroupRecord(objecUUID);
  1207. if (gr != null)
  1208. return gr.GroupName;
  1209. }
  1210. return String.Empty;
  1211. }
  1212. return SensedObject.Name;
  1213. }
  1214. public LSL_String llDetectedName(int number)
  1215. {
  1216. m_host.AddScriptLPS(1);
  1217. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1218. if (detectedParams == null)
  1219. return String.Empty;
  1220. return detectedParams.Name;
  1221. }
  1222. public LSL_Key llDetectedKey(int number)
  1223. {
  1224. m_host.AddScriptLPS(1);
  1225. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1226. if (detectedParams == null)
  1227. return String.Empty;
  1228. return detectedParams.Key.ToString();
  1229. }
  1230. public LSL_Key llDetectedOwner(int number)
  1231. {
  1232. m_host.AddScriptLPS(1);
  1233. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1234. if (detectedParams == null)
  1235. return String.Empty;
  1236. return detectedParams.Owner.ToString();
  1237. }
  1238. public LSL_Integer llDetectedType(int number)
  1239. {
  1240. m_host.AddScriptLPS(1);
  1241. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1242. if (detectedParams == null)
  1243. return 0;
  1244. return new LSL_Integer(detectedParams.Type);
  1245. }
  1246. public LSL_Vector llDetectedPos(int number)
  1247. {
  1248. m_host.AddScriptLPS(1);
  1249. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1250. if (detectedParams == null)
  1251. return new LSL_Vector();
  1252. return detectedParams.Position;
  1253. }
  1254. public LSL_Vector llDetectedVel(int number)
  1255. {
  1256. m_host.AddScriptLPS(1);
  1257. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1258. if (detectedParams == null)
  1259. return new LSL_Vector();
  1260. return detectedParams.Velocity;
  1261. }
  1262. public LSL_Vector llDetectedGrab(int number)
  1263. {
  1264. m_host.AddScriptLPS(1);
  1265. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1266. if (parms == null)
  1267. return new LSL_Vector(0, 0, 0);
  1268. return parms.OffsetPos;
  1269. }
  1270. public LSL_Rotation llDetectedRot(int number)
  1271. {
  1272. m_host.AddScriptLPS(1);
  1273. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1274. if (detectedParams == null)
  1275. return new LSL_Rotation();
  1276. return detectedParams.Rotation;
  1277. }
  1278. public LSL_Integer llDetectedGroup(int number)
  1279. {
  1280. m_host.AddScriptLPS(1);
  1281. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1282. if (detectedParams == null)
  1283. return new LSL_Integer(0);
  1284. if (m_host.GroupID == detectedParams.Group)
  1285. return new LSL_Integer(1);
  1286. return new LSL_Integer(0);
  1287. }
  1288. public LSL_Integer llDetectedLinkNumber(int number)
  1289. {
  1290. m_host.AddScriptLPS(1);
  1291. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1292. if (parms == null)
  1293. return new LSL_Integer(0);
  1294. return new LSL_Integer(parms.LinkNum);
  1295. }
  1296. /// <summary>
  1297. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchBinormal for details
  1298. /// </summary>
  1299. public LSL_Vector llDetectedTouchBinormal(int index)
  1300. {
  1301. m_host.AddScriptLPS(1);
  1302. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1303. if (detectedParams == null)
  1304. return new LSL_Vector();
  1305. return detectedParams.TouchBinormal;
  1306. }
  1307. /// <summary>
  1308. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchFace for details
  1309. /// </summary>
  1310. public LSL_Integer llDetectedTouchFace(int index)
  1311. {
  1312. m_host.AddScriptLPS(1);
  1313. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1314. if (detectedParams == null)
  1315. return new LSL_Integer(-1);
  1316. return new LSL_Integer(detectedParams.TouchFace);
  1317. }
  1318. /// <summary>
  1319. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchNormal for details
  1320. /// </summary>
  1321. public LSL_Vector llDetectedTouchNormal(int index)
  1322. {
  1323. m_host.AddScriptLPS(1);
  1324. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1325. if (detectedParams == null)
  1326. return new LSL_Vector();
  1327. return detectedParams.TouchNormal;
  1328. }
  1329. /// <summary>
  1330. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchPos for details
  1331. /// </summary>
  1332. public LSL_Vector llDetectedTouchPos(int index)
  1333. {
  1334. m_host.AddScriptLPS(1);
  1335. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1336. if (detectedParams == null)
  1337. return new LSL_Vector();
  1338. return detectedParams.TouchPos;
  1339. }
  1340. /// <summary>
  1341. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchST for details
  1342. /// </summary>
  1343. public LSL_Vector llDetectedTouchST(int index)
  1344. {
  1345. m_host.AddScriptLPS(1);
  1346. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1347. if (detectedParams == null)
  1348. return new LSL_Vector(-1.0, -1.0, 0.0);
  1349. return detectedParams.TouchST;
  1350. }
  1351. /// <summary>
  1352. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchUV for details
  1353. /// </summary>
  1354. public LSL_Vector llDetectedTouchUV(int index)
  1355. {
  1356. m_host.AddScriptLPS(1);
  1357. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1358. if (detectedParams == null)
  1359. return new LSL_Vector(-1.0, -1.0, 0.0);
  1360. return detectedParams.TouchUV;
  1361. }
  1362. [DebuggerNonUserCode]
  1363. public virtual void llDie()
  1364. {
  1365. m_host.AddScriptLPS(1);
  1366. if (!m_host.ParentGroup.IsAttachment) throw new SelfDeleteException();
  1367. }
  1368. public LSL_Float llGround(LSL_Vector offset)
  1369. {
  1370. m_host.AddScriptLPS(1);
  1371. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  1372. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  1373. LSL_Vector vsn = llGroundNormal(offset);
  1374. // Clamp to valid position
  1375. if (pos.X < 0)
  1376. pos.X = 0;
  1377. else if (pos.X >= World.Heightmap.Width)
  1378. pos.X = World.Heightmap.Width - 1;
  1379. if (pos.Y < 0)
  1380. pos.Y = 0;
  1381. else if (pos.Y >= World.Heightmap.Height)
  1382. pos.Y = World.Heightmap.Height - 1;
  1383. //Get the height for the integer coordinates from the Heightmap
  1384. float baseheight = (float)World.Heightmap[(int)pos.X, (int)pos.Y];
  1385. //Calculate the difference between the actual coordinates and the integer coordinates
  1386. float xdiff = pos.X - (float)((int)pos.X);
  1387. float ydiff = pos.Y - (float)((int)pos.Y);
  1388. //Use the equation of the tangent plane to adjust the height to account for slope
  1389. return (((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight;
  1390. }
  1391. public LSL_Float llCloud(LSL_Vector offset)
  1392. {
  1393. m_host.AddScriptLPS(1);
  1394. float cloudCover = 0f;
  1395. ICloudModule module = World.RequestModuleInterface<ICloudModule>();
  1396. if (module != null)
  1397. {
  1398. Vector3 pos = m_host.GetWorldPosition();
  1399. int x = (int)(pos.X + offset.x);
  1400. int y = (int)(pos.Y + offset.y);
  1401. cloudCover = module.CloudCover(x, y, 0);
  1402. }
  1403. return cloudCover;
  1404. }
  1405. public LSL_Vector llWind(LSL_Vector offset)
  1406. {
  1407. m_host.AddScriptLPS(1);
  1408. LSL_Vector wind = new LSL_Vector(0, 0, 0);
  1409. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1410. if (module != null)
  1411. {
  1412. Vector3 pos = m_host.GetWorldPosition();
  1413. int x = (int)(pos.X + offset.x);
  1414. int y = (int)(pos.Y + offset.y);
  1415. Vector3 windSpeed = module.WindSpeed(x, y, 0);
  1416. wind.x = windSpeed.X;
  1417. wind.y = windSpeed.Y;
  1418. }
  1419. return wind;
  1420. }
  1421. public void llSetStatus(int status, int value)
  1422. {
  1423. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  1424. return;
  1425. m_host.AddScriptLPS(1);
  1426. int statusrotationaxis = 0;
  1427. if ((status & ScriptBaseClass.STATUS_PHYSICS) == ScriptBaseClass.STATUS_PHYSICS)
  1428. {
  1429. if (value != 0)
  1430. {
  1431. SceneObjectGroup group = m_host.ParentGroup;
  1432. bool allow = true;
  1433. int maxprims = World.m_linksetPhysCapacity;
  1434. bool checkShape = (maxprims > 0 && group.PrimCount > maxprims);
  1435. foreach (SceneObjectPart part in group.Parts)
  1436. {
  1437. if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  1438. continue;
  1439. if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys)
  1440. {
  1441. allow = false;
  1442. break;
  1443. }
  1444. if (checkShape)
  1445. {
  1446. if (--maxprims < 0)
  1447. {
  1448. allow = false;
  1449. break;
  1450. }
  1451. }
  1452. }
  1453. if (!allow)
  1454. return;
  1455. if (m_host.ParentGroup.RootPart.PhysActor != null &&
  1456. m_host.ParentGroup.RootPart.PhysActor.IsPhysical)
  1457. return;
  1458. m_host.ScriptSetPhysicsStatus(true);
  1459. }
  1460. else
  1461. {
  1462. m_host.ScriptSetPhysicsStatus(false);
  1463. }
  1464. }
  1465. if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
  1466. {
  1467. m_host.ParentGroup.ScriptSetPhantomStatus(value != 0);
  1468. }
  1469. if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
  1470. {
  1471. m_host.AddFlag(PrimFlags.CastShadows);
  1472. }
  1473. if ((status & ScriptBaseClass.STATUS_ROTATE_X) == ScriptBaseClass.STATUS_ROTATE_X)
  1474. {
  1475. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_X;
  1476. }
  1477. if ((status & ScriptBaseClass.STATUS_ROTATE_Y) == ScriptBaseClass.STATUS_ROTATE_Y)
  1478. {
  1479. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Y;
  1480. }
  1481. if ((status & ScriptBaseClass.STATUS_ROTATE_Z) == ScriptBaseClass.STATUS_ROTATE_Z)
  1482. {
  1483. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Z;
  1484. }
  1485. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB)
  1486. m_host.BlockGrab = value != 0;
  1487. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT) == ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT)
  1488. m_host.ParentGroup.BlockGrabOverride = value != 0;
  1489. if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE)
  1490. {
  1491. if (value != 0)
  1492. m_host.SetDieAtEdge(true);
  1493. else
  1494. m_host.SetDieAtEdge(false);
  1495. }
  1496. if ((status & ScriptBaseClass.STATUS_RETURN_AT_EDGE) == ScriptBaseClass.STATUS_RETURN_AT_EDGE)
  1497. {
  1498. if (value != 0)
  1499. m_host.SetReturnAtEdge(true);
  1500. else
  1501. m_host.SetReturnAtEdge(false);
  1502. }
  1503. if ((status & ScriptBaseClass.STATUS_SANDBOX) == ScriptBaseClass.STATUS_SANDBOX)
  1504. {
  1505. if (value != 0)
  1506. m_host.SetStatusSandbox(true);
  1507. else
  1508. m_host.SetStatusSandbox(false);
  1509. }
  1510. if (statusrotationaxis != 0)
  1511. {
  1512. m_host.SetAxisRotation(statusrotationaxis, value);
  1513. }
  1514. }
  1515. private bool IsPhysical()
  1516. {
  1517. return ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) == (uint)PrimFlags.Physics);
  1518. }
  1519. public LSL_Integer llGetStatus(int status)
  1520. {
  1521. m_host.AddScriptLPS(1);
  1522. // m_log.Debug(m_host.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  1523. switch (status)
  1524. {
  1525. case ScriptBaseClass.STATUS_PHYSICS:
  1526. return IsPhysical() ? 1 : 0;
  1527. case ScriptBaseClass.STATUS_PHANTOM:
  1528. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) == (uint)PrimFlags.Phantom)
  1529. {
  1530. return 1;
  1531. }
  1532. return 0;
  1533. case ScriptBaseClass.STATUS_CAST_SHADOWS:
  1534. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.CastShadows) == (uint)PrimFlags.CastShadows)
  1535. {
  1536. return 1;
  1537. }
  1538. return 0;
  1539. case ScriptBaseClass.STATUS_BLOCK_GRAB:
  1540. return m_host.BlockGrab ? 1 : 0;
  1541. case ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT:
  1542. return m_host.ParentGroup.BlockGrabOverride ? 1 : 0;
  1543. case ScriptBaseClass.STATUS_DIE_AT_EDGE:
  1544. if (m_host.GetDieAtEdge())
  1545. return 1;
  1546. else
  1547. return 0;
  1548. case ScriptBaseClass.STATUS_RETURN_AT_EDGE:
  1549. if (m_host.GetReturnAtEdge())
  1550. return 1;
  1551. else
  1552. return 0;
  1553. case ScriptBaseClass.STATUS_ROTATE_X:
  1554. // if (m_host.GetAxisRotation(2) != 0)
  1555. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0)
  1556. return 1;
  1557. else
  1558. return 0;
  1559. case ScriptBaseClass.STATUS_ROTATE_Y:
  1560. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0)
  1561. return 1;
  1562. else
  1563. return 0;
  1564. case ScriptBaseClass.STATUS_ROTATE_Z:
  1565. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0)
  1566. return 1;
  1567. else
  1568. return 0;
  1569. case ScriptBaseClass.STATUS_SANDBOX:
  1570. if (m_host.GetStatusSandbox())
  1571. return 1;
  1572. else
  1573. return 0;
  1574. }
  1575. return 0;
  1576. }
  1577. public LSL_Integer llScaleByFactor(double scaling_factor)
  1578. {
  1579. m_host.AddScriptLPS(1);
  1580. SceneObjectGroup group = m_host.ParentGroup;
  1581. if(scaling_factor < 1e-6)
  1582. return ScriptBaseClass.FALSE;
  1583. if(scaling_factor > 1e6)
  1584. return ScriptBaseClass.FALSE;
  1585. if (group == null || group.IsDeleted || group.inTransit)
  1586. return ScriptBaseClass.FALSE;
  1587. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  1588. return ScriptBaseClass.FALSE;
  1589. if (group.RootPart.KeyframeMotion != null)
  1590. return ScriptBaseClass.FALSE;
  1591. if(group.GroupResize(scaling_factor))
  1592. return ScriptBaseClass.TRUE;
  1593. else
  1594. return ScriptBaseClass.FALSE;
  1595. }
  1596. public LSL_Float llGetMaxScaleFactor()
  1597. {
  1598. m_host.AddScriptLPS(1);
  1599. SceneObjectGroup group = m_host.ParentGroup;
  1600. if (group == null || group.IsDeleted || group.inTransit)
  1601. return 1.0f;
  1602. return (LSL_Float)group.GetMaxGroupResizeScale();
  1603. }
  1604. public LSL_Float llGetMinScaleFactor()
  1605. {
  1606. m_host.AddScriptLPS(1);
  1607. SceneObjectGroup group = m_host.ParentGroup;
  1608. if (group == null || group.IsDeleted || group.inTransit)
  1609. return 1.0f;
  1610. return (LSL_Float)group.GetMinGroupResizeScale();
  1611. }
  1612. public void llSetScale(LSL_Vector scale)
  1613. {
  1614. m_host.AddScriptLPS(1);
  1615. SetScale(m_host, scale);
  1616. }
  1617. protected void SetScale(SceneObjectPart part, LSL_Vector scale)
  1618. {
  1619. // TODO: this needs to trigger a persistance save as well
  1620. if (part == null || part.ParentGroup.IsDeleted)
  1621. return;
  1622. // First we need to check whether or not we need to clamp the size of a physics-enabled prim
  1623. PhysicsActor pa = part.ParentGroup.RootPart.PhysActor;
  1624. if (pa != null && pa.IsPhysical)
  1625. {
  1626. scale.x = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.x));
  1627. scale.y = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.y));
  1628. scale.z = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.z));
  1629. }
  1630. else
  1631. {
  1632. // If not physical, then we clamp the scale to the non-physical min/max
  1633. scale.x = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.x));
  1634. scale.y = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.y));
  1635. scale.z = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.z));
  1636. }
  1637. Vector3 tmp = part.Scale;
  1638. tmp.X = (float)scale.x;
  1639. tmp.Y = (float)scale.y;
  1640. tmp.Z = (float)scale.z;
  1641. part.Scale = tmp;
  1642. part.SendFullUpdateToAllClients();
  1643. }
  1644. public LSL_Vector llGetScale()
  1645. {
  1646. m_host.AddScriptLPS(1);
  1647. return new LSL_Vector(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  1648. }
  1649. public void llSetClickAction(int action)
  1650. {
  1651. m_host.AddScriptLPS(1);
  1652. m_host.ClickAction = (byte)action;
  1653. m_host.ParentGroup.HasGroupChanged = true;
  1654. m_host.ScheduleFullUpdate();
  1655. return;
  1656. }
  1657. public void llSetColor(LSL_Vector color, int face)
  1658. {
  1659. m_host.AddScriptLPS(1);
  1660. SetColor(m_host, color, face);
  1661. }
  1662. protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
  1663. {
  1664. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1665. return;
  1666. m_host.SetFaceColorAlpha(face, color, null);
  1667. }
  1668. public void llSetContentType(LSL_Key reqid, LSL_Integer type)
  1669. {
  1670. m_host.AddScriptLPS(1);
  1671. if (m_UrlModule == null)
  1672. return;
  1673. UUID id;
  1674. if(!UUID.TryParse(reqid, out id))
  1675. return;
  1676. // Make sure the content type is text/plain to start with
  1677. m_UrlModule.HttpContentType(id, "text/plain");
  1678. // Is the object owner online and in the region
  1679. ScenePresence agent = World.GetScenePresence(m_host.ParentGroup.OwnerID);
  1680. if (agent == null || agent.IsChildAgent || agent.IsDeleted)
  1681. return; // Fail if the owner is not in the same region
  1682. // Is it the embeded browser?
  1683. string userAgent = m_UrlModule.GetHttpHeader(id, "user-agent");
  1684. if (userAgent.IndexOf("SecondLife") < 0)
  1685. return; // Not the embedded browser. Is this check good enough?
  1686. // Use the IP address of the client and check against the request
  1687. // seperate logins from the same IP will allow all of them to get non-text/plain as long
  1688. // as the owner is in the region. Same as SL!
  1689. string logonFromIPAddress = agent.ControllingClient.RemoteEndPoint.Address.ToString();
  1690. if (string.IsNullOrEmpty(logonFromIPAddress))
  1691. return;
  1692. string requestFromIPAddress = m_UrlModule.GetHttpHeader(id, "x-remote-ip");
  1693. //m_log.Debug("IP from header='" + requestFromIPAddress + "' IP from endpoint='" + logonFromIPAddress + "'");
  1694. if (requestFromIPAddress == null)
  1695. return;
  1696. requestFromIPAddress = requestFromIPAddress.Trim();
  1697. // If the request isnt from the same IP address then the request cannot be from the owner
  1698. if (!requestFromIPAddress.Equals(logonFromIPAddress))
  1699. return;
  1700. switch (type)
  1701. {
  1702. case ScriptBaseClass.CONTENT_TYPE_HTML:
  1703. m_UrlModule.HttpContentType(new UUID(id), "text/html");
  1704. break;
  1705. case ScriptBaseClass.CONTENT_TYPE_XML:
  1706. m_UrlModule.HttpContentType(new UUID(id), "application/xml");
  1707. break;
  1708. case ScriptBaseClass.CONTENT_TYPE_XHTML:
  1709. m_UrlModule.HttpContentType(new UUID(id), "application/xhtml+xml");
  1710. break;
  1711. case ScriptBaseClass.CONTENT_TYPE_ATOM:
  1712. m_UrlModule.HttpContentType(new UUID(id), "application/atom+xml");
  1713. break;
  1714. case ScriptBaseClass.CONTENT_TYPE_JSON:
  1715. m_UrlModule.HttpContentType(new UUID(id), "application/json");
  1716. break;
  1717. case ScriptBaseClass.CONTENT_TYPE_LLSD:
  1718. m_UrlModule.HttpContentType(new UUID(id), "application/llsd+xml");
  1719. break;
  1720. case ScriptBaseClass.CONTENT_TYPE_FORM:
  1721. m_UrlModule.HttpContentType(new UUID(id), "application/x-www-form-urlencoded");
  1722. break;
  1723. case ScriptBaseClass.CONTENT_TYPE_RSS:
  1724. m_UrlModule.HttpContentType(new UUID(id), "application/rss+xml");
  1725. break;
  1726. default:
  1727. m_UrlModule.HttpContentType(new UUID(id), "text/plain");
  1728. break;
  1729. }
  1730. }
  1731. public void SetTexGen(SceneObjectPart part, int face,int style)
  1732. {
  1733. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1734. return;
  1735. Primitive.TextureEntry tex = part.Shape.Textures;
  1736. MappingType textype;
  1737. textype = MappingType.Default;
  1738. if (style == (int)ScriptBaseClass.PRIM_TEXGEN_PLANAR)
  1739. textype = MappingType.Planar;
  1740. int nsides = GetNumberOfSides(part);
  1741. if (face >= 0 && face < nsides)
  1742. {
  1743. tex.CreateFace((uint) face);
  1744. tex.FaceTextures[face].TexMapType = textype;
  1745. part.UpdateTextureEntry(tex);
  1746. return;
  1747. }
  1748. else if (face == ScriptBaseClass.ALL_SIDES)
  1749. {
  1750. for (uint i = 0; i < nsides; i++)
  1751. {
  1752. if (tex.FaceTextures[i] != null)
  1753. {
  1754. tex.FaceTextures[i].TexMapType = textype;
  1755. }
  1756. }
  1757. tex.DefaultTexture.TexMapType = textype;
  1758. part.UpdateTextureEntry(tex);
  1759. return;
  1760. }
  1761. }
  1762. public void SetGlow(SceneObjectPart part, int face, float glow)
  1763. {
  1764. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1765. return;
  1766. Primitive.TextureEntry tex = part.Shape.Textures;
  1767. int nsides = GetNumberOfSides(part);
  1768. if (face >= 0 && face < nsides)
  1769. {
  1770. tex.CreateFace((uint) face);
  1771. tex.FaceTextures[face].Glow = glow;
  1772. part.UpdateTextureEntry(tex);
  1773. return;
  1774. }
  1775. else if (face == ScriptBaseClass.ALL_SIDES)
  1776. {
  1777. for (uint i = 0; i < nsides; i++)
  1778. {
  1779. if (tex.FaceTextures[i] != null)
  1780. {
  1781. tex.FaceTextures[i].Glow = glow;
  1782. }
  1783. }
  1784. tex.DefaultTexture.Glow = glow;
  1785. part.UpdateTextureEntry(tex);
  1786. return;
  1787. }
  1788. }
  1789. public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
  1790. {
  1791. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1792. return;
  1793. Shininess sval = new Shininess();
  1794. switch (shiny)
  1795. {
  1796. case 0:
  1797. sval = Shininess.None;
  1798. break;
  1799. case 1:
  1800. sval = Shininess.Low;
  1801. break;
  1802. case 2:
  1803. sval = Shininess.Medium;
  1804. break;
  1805. case 3:
  1806. sval = Shininess.High;
  1807. break;
  1808. default:
  1809. sval = Shininess.None;
  1810. break;
  1811. }
  1812. int nsides = GetNumberOfSides(part);
  1813. Primitive.TextureEntry tex = part.Shape.Textures;
  1814. if (face >= 0 && face < nsides)
  1815. {
  1816. tex.CreateFace((uint) face);
  1817. tex.FaceTextures[face].Shiny = sval;
  1818. tex.FaceTextures[face].Bump = bump;
  1819. part.UpdateTextureEntry(tex);
  1820. return;
  1821. }
  1822. else if (face == ScriptBaseClass.ALL_SIDES)
  1823. {
  1824. for (uint i = 0; i < nsides; i++)
  1825. {
  1826. if (tex.FaceTextures[i] != null)
  1827. {
  1828. tex.FaceTextures[i].Shiny = sval;
  1829. tex.FaceTextures[i].Bump = bump;
  1830. }
  1831. }
  1832. tex.DefaultTexture.Shiny = sval;
  1833. tex.DefaultTexture.Bump = bump;
  1834. part.UpdateTextureEntry(tex);
  1835. return;
  1836. }
  1837. }
  1838. public void SetFullBright(SceneObjectPart part, int face, bool bright)
  1839. {
  1840. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1841. return;
  1842. int nsides = GetNumberOfSides(part);
  1843. Primitive.TextureEntry tex = part.Shape.Textures;
  1844. if (face >= 0 && face < nsides)
  1845. {
  1846. tex.CreateFace((uint) face);
  1847. tex.FaceTextures[face].Fullbright = bright;
  1848. part.UpdateTextureEntry(tex);
  1849. return;
  1850. }
  1851. else if (face == ScriptBaseClass.ALL_SIDES)
  1852. {
  1853. for (uint i = 0; i < nsides; i++)
  1854. {
  1855. if (tex.FaceTextures[i] != null)
  1856. {
  1857. tex.FaceTextures[i].Fullbright = bright;
  1858. }
  1859. }
  1860. tex.DefaultTexture.Fullbright = bright;
  1861. part.UpdateTextureEntry(tex);
  1862. return;
  1863. }
  1864. }
  1865. public LSL_Float llGetAlpha(int face)
  1866. {
  1867. m_host.AddScriptLPS(1);
  1868. return GetAlpha(m_host, face);
  1869. }
  1870. protected LSL_Float GetAlpha(SceneObjectPart part, int face)
  1871. {
  1872. Primitive.TextureEntry tex = part.Shape.Textures;
  1873. int nsides = GetNumberOfSides(part);
  1874. if (face == ScriptBaseClass.ALL_SIDES)
  1875. {
  1876. int i;
  1877. double sum = 0.0;
  1878. for (i = 0 ; i < nsides; i++)
  1879. sum += (double)tex.GetFace((uint)i).RGBA.A;
  1880. return sum;
  1881. }
  1882. if (face >= 0 && face < nsides)
  1883. {
  1884. return (double)tex.GetFace((uint)face).RGBA.A;
  1885. }
  1886. return 0.0;
  1887. }
  1888. public void llSetAlpha(double alpha, int face)
  1889. {
  1890. m_host.AddScriptLPS(1);
  1891. SetAlpha(m_host, alpha, face);
  1892. }
  1893. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  1894. {
  1895. m_host.AddScriptLPS(1);
  1896. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1897. if (parts.Count > 0)
  1898. {
  1899. try
  1900. {
  1901. foreach (SceneObjectPart part in parts)
  1902. SetAlpha(part, alpha, face);
  1903. }
  1904. finally { }
  1905. }
  1906. }
  1907. protected void SetAlpha(SceneObjectPart part, double alpha, int face)
  1908. {
  1909. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1910. return;
  1911. Primitive.TextureEntry tex = part.Shape.Textures;
  1912. int nsides = GetNumberOfSides(part);
  1913. Color4 texcolor;
  1914. if (face >= 0 && face < nsides)
  1915. {
  1916. texcolor = tex.CreateFace((uint)face).RGBA;
  1917. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1918. tex.FaceTextures[face].RGBA = texcolor;
  1919. part.UpdateTextureEntry(tex);
  1920. return;
  1921. }
  1922. else if (face == ScriptBaseClass.ALL_SIDES)
  1923. {
  1924. for (int i = 0; i < nsides; i++)
  1925. {
  1926. if (tex.FaceTextures[i] != null)
  1927. {
  1928. texcolor = tex.FaceTextures[i].RGBA;
  1929. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1930. tex.FaceTextures[i].RGBA = texcolor;
  1931. }
  1932. }
  1933. // In some cases, the default texture can be null, eg when every face
  1934. // has a unique texture
  1935. if (tex.DefaultTexture != null)
  1936. {
  1937. texcolor = tex.DefaultTexture.RGBA;
  1938. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1939. tex.DefaultTexture.RGBA = texcolor;
  1940. }
  1941. part.UpdateTextureEntry(tex);
  1942. return;
  1943. }
  1944. }
  1945. /// <summary>
  1946. /// Set flexi parameters of a part.
  1947. ///
  1948. /// FIXME: Much of this code should probably be within the part itself.
  1949. /// </summary>
  1950. /// <param name="part"></param>
  1951. /// <param name="flexi"></param>
  1952. /// <param name="softness"></param>
  1953. /// <param name="gravity"></param>
  1954. /// <param name="friction"></param>
  1955. /// <param name="wind"></param>
  1956. /// <param name="tension"></param>
  1957. /// <param name="Force"></param>
  1958. protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
  1959. float wind, float tension, LSL_Vector Force)
  1960. {
  1961. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1962. return;
  1963. if (flexi)
  1964. {
  1965. part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do
  1966. // work once the prim is already flexi
  1967. part.Shape.FlexiSoftness = softness;
  1968. part.Shape.FlexiGravity = gravity;
  1969. part.Shape.FlexiDrag = friction;
  1970. part.Shape.FlexiWind = wind;
  1971. part.Shape.FlexiTension = tension;
  1972. part.Shape.FlexiForceX = (float)Force.x;
  1973. part.Shape.FlexiForceY = (float)Force.y;
  1974. part.Shape.FlexiForceZ = (float)Force.z;
  1975. part.Shape.PathCurve = (byte)Extrusion.Flexible;
  1976. }
  1977. else
  1978. {
  1979. // Other values not set, they do not seem to be sent to the viewer
  1980. // Setting PathCurve appears to be what actually toggles the check box and turns Flexi on and off
  1981. part.Shape.PathCurve = (byte)Extrusion.Straight;
  1982. part.Shape.FlexiEntry = false;
  1983. }
  1984. part.ParentGroup.HasGroupChanged = true;
  1985. part.ScheduleFullUpdate();
  1986. }
  1987. /// <summary>
  1988. /// Set a light point on a part
  1989. /// </summary>
  1990. /// FIXME: Much of this code should probably be in SceneObjectGroup
  1991. ///
  1992. /// <param name="part"></param>
  1993. /// <param name="light"></param>
  1994. /// <param name="color"></param>
  1995. /// <param name="intensity"></param>
  1996. /// <param name="radius"></param>
  1997. /// <param name="falloff"></param>
  1998. protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
  1999. {
  2000. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2001. return;
  2002. if (light)
  2003. {
  2004. part.Shape.LightEntry = true;
  2005. part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f);
  2006. part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f);
  2007. part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f);
  2008. part.Shape.LightIntensity = Util.Clip((float)intensity, 0.0f, 1.0f);
  2009. part.Shape.LightRadius = Util.Clip((float)radius, 0.1f, 20.0f);
  2010. part.Shape.LightFalloff = Util.Clip((float)falloff, 0.01f, 2.0f);
  2011. }
  2012. else
  2013. {
  2014. part.Shape.LightEntry = false;
  2015. }
  2016. part.ParentGroup.HasGroupChanged = true;
  2017. part.ScheduleFullUpdate();
  2018. }
  2019. public LSL_Vector llGetColor(int face)
  2020. {
  2021. m_host.AddScriptLPS(1);
  2022. return GetColor(m_host, face);
  2023. }
  2024. protected LSL_Vector GetColor(SceneObjectPart part, int face)
  2025. {
  2026. Primitive.TextureEntry tex = part.Shape.Textures;
  2027. Color4 texcolor;
  2028. LSL_Vector rgb = new LSL_Vector();
  2029. int nsides = GetNumberOfSides(part);
  2030. if (face == ScriptBaseClass.ALL_SIDES)
  2031. {
  2032. int i;
  2033. for (i = 0; i < nsides; i++)
  2034. {
  2035. texcolor = tex.GetFace((uint)i).RGBA;
  2036. rgb.x += texcolor.R;
  2037. rgb.y += texcolor.G;
  2038. rgb.z += texcolor.B;
  2039. }
  2040. float invnsides = 1.0f / (float)nsides;
  2041. rgb.x *= invnsides;
  2042. rgb.y *= invnsides;
  2043. rgb.z *= invnsides;
  2044. return rgb;
  2045. }
  2046. if (face >= 0 && face < nsides)
  2047. {
  2048. texcolor = tex.GetFace((uint)face).RGBA;
  2049. rgb.x = texcolor.R;
  2050. rgb.y = texcolor.G;
  2051. rgb.z = texcolor.B;
  2052. return rgb;
  2053. }
  2054. else
  2055. {
  2056. return new LSL_Vector();
  2057. }
  2058. }
  2059. public void llSetTexture(string texture, int face)
  2060. {
  2061. m_host.AddScriptLPS(1);
  2062. SetTexture(m_host, texture, face);
  2063. ScriptSleep(m_sleepMsOnSetTexture);
  2064. }
  2065. public void llSetLinkTexture(int linknumber, string texture, int face)
  2066. {
  2067. m_host.AddScriptLPS(1);
  2068. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  2069. if (parts.Count > 0)
  2070. {
  2071. try
  2072. {
  2073. foreach (SceneObjectPart part in parts)
  2074. SetTexture(part, texture, face);
  2075. }
  2076. finally { }
  2077. }
  2078. ScriptSleep(m_sleepMsOnSetLinkTexture);
  2079. }
  2080. protected void SetTextureParams(SceneObjectPart part, string texture, double scaleU, double ScaleV,
  2081. double offsetU, double offsetV, double rotation, int face)
  2082. {
  2083. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2084. return;
  2085. UUID textureID = new UUID();
  2086. bool dotexture = true;
  2087. if(String.IsNullOrEmpty(texture) || texture == ScriptBaseClass.NULL_KEY)
  2088. dotexture = false;
  2089. else
  2090. {
  2091. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  2092. if (textureID == UUID.Zero)
  2093. {
  2094. if (!UUID.TryParse(texture, out textureID))
  2095. dotexture = false;
  2096. }
  2097. }
  2098. Primitive.TextureEntry tex = part.Shape.Textures;
  2099. int nsides = GetNumberOfSides(part);
  2100. if (face >= 0 && face < nsides)
  2101. {
  2102. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2103. if (dotexture)
  2104. texface.TextureID = textureID;
  2105. texface.RepeatU = (float)scaleU;
  2106. texface.RepeatV = (float)ScaleV;
  2107. texface.OffsetU = (float)offsetU;
  2108. texface.OffsetV = (float)offsetV;
  2109. texface.Rotation = (float)rotation;
  2110. tex.FaceTextures[face] = texface;
  2111. part.UpdateTextureEntry(tex);
  2112. return;
  2113. }
  2114. else if (face == ScriptBaseClass.ALL_SIDES)
  2115. {
  2116. for (uint i = 0; i < nsides; i++)
  2117. {
  2118. if (tex.FaceTextures[i] != null)
  2119. {
  2120. if (dotexture)
  2121. tex.FaceTextures[i].TextureID = textureID;
  2122. tex.FaceTextures[i].RepeatU = (float)scaleU;
  2123. tex.FaceTextures[i].RepeatV = (float)ScaleV;
  2124. tex.FaceTextures[i].OffsetU = (float)offsetU;
  2125. tex.FaceTextures[i].OffsetV = (float)offsetV;
  2126. tex.FaceTextures[i].Rotation = (float)rotation;
  2127. }
  2128. }
  2129. if (dotexture)
  2130. tex.DefaultTexture.TextureID = textureID;
  2131. tex.DefaultTexture.RepeatU = (float)scaleU;
  2132. tex.DefaultTexture.RepeatV = (float)ScaleV;
  2133. tex.DefaultTexture.OffsetU = (float)offsetU;
  2134. tex.DefaultTexture.OffsetV = (float)offsetV;
  2135. tex.DefaultTexture.Rotation = (float)rotation;
  2136. part.UpdateTextureEntry(tex);
  2137. return;
  2138. }
  2139. }
  2140. protected void SetTexture(SceneObjectPart part, string texture, int face)
  2141. {
  2142. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2143. return;
  2144. UUID textureID = new UUID();
  2145. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  2146. if (textureID == UUID.Zero)
  2147. {
  2148. if (!UUID.TryParse(texture, out textureID))
  2149. return;
  2150. }
  2151. Primitive.TextureEntry tex = part.Shape.Textures;
  2152. int nsides = GetNumberOfSides(part);
  2153. if (face >= 0 && face < nsides)
  2154. {
  2155. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2156. texface.TextureID = textureID;
  2157. tex.FaceTextures[face] = texface;
  2158. part.UpdateTextureEntry(tex);
  2159. return;
  2160. }
  2161. else if (face == ScriptBaseClass.ALL_SIDES)
  2162. {
  2163. for (uint i = 0; i < nsides; i++)
  2164. {
  2165. if (tex.FaceTextures[i] != null)
  2166. {
  2167. tex.FaceTextures[i].TextureID = textureID;
  2168. }
  2169. }
  2170. tex.DefaultTexture.TextureID = textureID;
  2171. part.UpdateTextureEntry(tex);
  2172. return;
  2173. }
  2174. }
  2175. public void llScaleTexture(double u, double v, int face)
  2176. {
  2177. m_host.AddScriptLPS(1);
  2178. ScaleTexture(m_host, u, v, face);
  2179. ScriptSleep(m_sleepMsOnScaleTexture);
  2180. }
  2181. protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  2182. {
  2183. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2184. return;
  2185. Primitive.TextureEntry tex = part.Shape.Textures;
  2186. int nsides = GetNumberOfSides(part);
  2187. if (face >= 0 && face < nsides)
  2188. {
  2189. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2190. texface.RepeatU = (float)u;
  2191. texface.RepeatV = (float)v;
  2192. tex.FaceTextures[face] = texface;
  2193. part.UpdateTextureEntry(tex);
  2194. return;
  2195. }
  2196. if (face == ScriptBaseClass.ALL_SIDES)
  2197. {
  2198. for (int i = 0; i < nsides; i++)
  2199. {
  2200. if (tex.FaceTextures[i] != null)
  2201. {
  2202. tex.FaceTextures[i].RepeatU = (float)u;
  2203. tex.FaceTextures[i].RepeatV = (float)v;
  2204. }
  2205. }
  2206. tex.DefaultTexture.RepeatU = (float)u;
  2207. tex.DefaultTexture.RepeatV = (float)v;
  2208. part.UpdateTextureEntry(tex);
  2209. return;
  2210. }
  2211. }
  2212. public void llOffsetTexture(double u, double v, int face)
  2213. {
  2214. m_host.AddScriptLPS(1);
  2215. OffsetTexture(m_host, u, v, face);
  2216. ScriptSleep(m_sleepMsOnOffsetTexture);
  2217. }
  2218. protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  2219. {
  2220. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2221. return;
  2222. Primitive.TextureEntry tex = part.Shape.Textures;
  2223. int nsides = GetNumberOfSides(part);
  2224. if (face >= 0 && face < nsides)
  2225. {
  2226. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2227. texface.OffsetU = (float)u;
  2228. texface.OffsetV = (float)v;
  2229. tex.FaceTextures[face] = texface;
  2230. part.UpdateTextureEntry(tex);
  2231. return;
  2232. }
  2233. if (face == ScriptBaseClass.ALL_SIDES)
  2234. {
  2235. for (int i = 0; i < nsides; i++)
  2236. {
  2237. if (tex.FaceTextures[i] != null)
  2238. {
  2239. tex.FaceTextures[i].OffsetU = (float)u;
  2240. tex.FaceTextures[i].OffsetV = (float)v;
  2241. }
  2242. }
  2243. tex.DefaultTexture.OffsetU = (float)u;
  2244. tex.DefaultTexture.OffsetV = (float)v;
  2245. part.UpdateTextureEntry(tex);
  2246. return;
  2247. }
  2248. }
  2249. public void llRotateTexture(double rotation, int face)
  2250. {
  2251. m_host.AddScriptLPS(1);
  2252. RotateTexture(m_host, rotation, face);
  2253. ScriptSleep(m_sleepMsOnRotateTexture);
  2254. }
  2255. protected void RotateTexture(SceneObjectPart part, double rotation, int face)
  2256. {
  2257. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2258. return;
  2259. Primitive.TextureEntry tex = part.Shape.Textures;
  2260. int nsides = GetNumberOfSides(part);
  2261. if (face >= 0 && face < nsides)
  2262. {
  2263. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2264. texface.Rotation = (float)rotation;
  2265. tex.FaceTextures[face] = texface;
  2266. part.UpdateTextureEntry(tex);
  2267. return;
  2268. }
  2269. if (face == ScriptBaseClass.ALL_SIDES)
  2270. {
  2271. for (int i = 0; i < nsides; i++)
  2272. {
  2273. if (tex.FaceTextures[i] != null)
  2274. {
  2275. tex.FaceTextures[i].Rotation = (float)rotation;
  2276. }
  2277. }
  2278. tex.DefaultTexture.Rotation = (float)rotation;
  2279. part.UpdateTextureEntry(tex);
  2280. return;
  2281. }
  2282. }
  2283. public LSL_String llGetTexture(int face)
  2284. {
  2285. m_host.AddScriptLPS(1);
  2286. return GetTexture(m_host, face);
  2287. }
  2288. protected LSL_String GetTexture(SceneObjectPart part, int face)
  2289. {
  2290. Primitive.TextureEntry tex = part.Shape.Textures;
  2291. int nsides = GetNumberOfSides(part);
  2292. if (face == ScriptBaseClass.ALL_SIDES)
  2293. {
  2294. face = 0;
  2295. }
  2296. if (face >= 0 && face < nsides)
  2297. {
  2298. Primitive.TextureEntryFace texface;
  2299. texface = tex.GetFace((uint)face);
  2300. string texture = texface.TextureID.ToString();
  2301. lock (part.TaskInventory)
  2302. {
  2303. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  2304. {
  2305. if (inv.Value.AssetID == texface.TextureID)
  2306. {
  2307. texture = inv.Value.Name.ToString();
  2308. break;
  2309. }
  2310. }
  2311. }
  2312. return texture;
  2313. }
  2314. else
  2315. {
  2316. return UUID.Zero.ToString();
  2317. }
  2318. }
  2319. public void llSetPos(LSL_Vector pos)
  2320. {
  2321. m_host.AddScriptLPS(1);
  2322. SetPos(m_host, pos, true);
  2323. ScriptSleep(m_sleepMsOnSetPos);
  2324. }
  2325. /// <summary>
  2326. /// Tries to move the entire object so that the root prim is within 0.1m of position. http://wiki.secondlife.com/wiki/LlSetRegionPos
  2327. /// Documentation indicates that the use of x/y coordinates up to 10 meters outside the bounds of a region will work but do not specify what happens if there is no adjacent region for the object to move into.
  2328. /// Uses the RegionSize constant here rather than hard-coding 266.0 to alert any developer modifying OpenSim to support variable-sized regions that this method will need tweaking.
  2329. /// </summary>
  2330. /// <param name="pos"></param>
  2331. /// <returns>1 if successful, 0 otherwise.</returns>
  2332. public LSL_Integer llSetRegionPos(LSL_Vector pos)
  2333. {
  2334. m_host.AddScriptLPS(1);
  2335. // BEGIN WORKAROUND
  2336. // IF YOU GET REGION CROSSINGS WORKING WITH THIS FUNCTION, REPLACE THE WORKAROUND.
  2337. //
  2338. // This workaround is to prevent silent failure of this function.
  2339. // According to the specification on the SL Wiki, providing a position outside of the
  2340. if (pos.x < 0 || pos.x > World.RegionInfo.RegionSizeX || pos.y < 0 || pos.y > World.RegionInfo.RegionSizeY)
  2341. {
  2342. return 0;
  2343. }
  2344. // END WORK AROUND
  2345. else if ( // this is not part of the workaround if-block because it's not related to the workaround.
  2346. IsPhysical() ||
  2347. m_host.ParentGroup.IsAttachment || // return FALSE if attachment
  2348. (
  2349. pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region.
  2350. pos.x > (World.RegionInfo.RegionSizeX + 10) || // return FALSE if more than 10 meters into a east-adjacent region.
  2351. pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region.
  2352. pos.y > (World.RegionInfo.RegionSizeY + 10) || // return FALSE if more than 10 meters into a north-adjacent region.
  2353. pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m
  2354. )
  2355. )
  2356. {
  2357. return 0;
  2358. }
  2359. // if we reach this point, then the object is not physical, it's not an attachment, and the destination is within the valid range.
  2360. // this could possibly be done in the above else-if block, but we're doing the check here to keep the code easier to read.
  2361. Vector3 objectPos = m_host.ParentGroup.RootPart.AbsolutePosition;
  2362. LandData here = World.GetLandData(objectPos);
  2363. LandData there = World.GetLandData(pos);
  2364. // we're only checking prim limits if it's moving to a different parcel under the assumption that if the object got onto the parcel without exceeding the prim limits.
  2365. bool sameParcel = here.GlobalID == there.GlobalID;
  2366. if (!sameParcel && !World.Permissions.CanRezObject(
  2367. m_host.ParentGroup.PrimCount, m_host.ParentGroup.OwnerID, pos))
  2368. {
  2369. return 0;
  2370. }
  2371. SetPos(m_host.ParentGroup.RootPart, pos, false);
  2372. return VecDist(pos, llGetRootPosition()) <= 0.1 ? 1 : 0;
  2373. }
  2374. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2375. // note linked setpos is capped "differently"
  2376. private LSL_Vector SetPosAdjust(LSL_Vector start, LSL_Vector end)
  2377. {
  2378. if (llVecDist(start, end) > 10.0f * m_ScriptDistanceFactor)
  2379. return start + m_ScriptDistanceFactor * 10.0f * llVecNorm(end - start);
  2380. else
  2381. return end;
  2382. }
  2383. protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos, bool adjust)
  2384. {
  2385. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2386. return fromPos;
  2387. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2388. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  2389. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  2390. if (part.ParentGroup.RootPart == part)
  2391. {
  2392. if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
  2393. targetPos.z = ground;
  2394. }
  2395. if (adjust)
  2396. return SetPosAdjust(fromPos, targetPos);
  2397. return targetPos;
  2398. }
  2399. /// <summary>
  2400. /// set object position, optionally capping the distance.
  2401. /// </summary>
  2402. /// <param name="part"></param>
  2403. /// <param name="targetPos"></param>
  2404. /// <param name="adjust">if TRUE, will cap the distance to 10m.</param>
  2405. protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust)
  2406. {
  2407. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted || part.ParentGroup.inTransit)
  2408. return;
  2409. LSL_Vector currentPos = GetPartLocalPos(part);
  2410. LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos, adjust);
  2411. if (part.ParentGroup.RootPart == part)
  2412. {
  2413. SceneObjectGroup parent = part.ParentGroup;
  2414. if (!parent.IsAttachment && !World.Permissions.CanObjectEntry(parent, false, (Vector3)toPos))
  2415. return;
  2416. parent.UpdateGroupPosition((Vector3)toPos);
  2417. }
  2418. else
  2419. {
  2420. part.OffsetPosition = (Vector3)toPos;
  2421. // SceneObjectGroup parent = part.ParentGroup;
  2422. // parent.HasGroupChanged = true;
  2423. // parent.ScheduleGroupForTerseUpdate();
  2424. part.ScheduleTerseUpdate();
  2425. }
  2426. }
  2427. public LSL_Vector llGetPos()
  2428. {
  2429. m_host.AddScriptLPS(1);
  2430. return m_host.GetWorldPosition();
  2431. }
  2432. public LSL_Vector llGetLocalPos()
  2433. {
  2434. m_host.AddScriptLPS(1);
  2435. return GetPartLocalPos(m_host);
  2436. }
  2437. protected LSL_Vector GetPartLocalPos(SceneObjectPart part)
  2438. {
  2439. m_host.AddScriptLPS(1);
  2440. Vector3 pos;
  2441. if (!part.IsRoot)
  2442. {
  2443. pos = part.OffsetPosition;
  2444. }
  2445. else
  2446. {
  2447. if (part.ParentGroup.IsAttachment)
  2448. pos = part.AttachedPos;
  2449. else
  2450. pos = part.AbsolutePosition;
  2451. }
  2452. // m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
  2453. return new LSL_Vector(pos);
  2454. }
  2455. public void llSetRot(LSL_Rotation rot)
  2456. {
  2457. m_host.AddScriptLPS(1);
  2458. // try to let this work as in SL...
  2459. if (m_host.ParentID == 0 || (m_host.ParentGroup != null && m_host == m_host.ParentGroup.RootPart))
  2460. {
  2461. // special case: If we are root, rotate complete SOG to new rotation
  2462. SetRot(m_host, rot);
  2463. }
  2464. else
  2465. {
  2466. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  2467. SceneObjectPart rootPart = m_host.ParentGroup.RootPart;
  2468. if (rootPart != null) // better safe than sorry
  2469. {
  2470. SetRot(m_host, rootPart.RotationOffset * (Quaternion)rot);
  2471. }
  2472. }
  2473. ScriptSleep(m_sleepMsOnSetRot);
  2474. }
  2475. public void llSetLocalRot(LSL_Rotation rot)
  2476. {
  2477. m_host.AddScriptLPS(1);
  2478. SetRot(m_host, rot);
  2479. ScriptSleep(m_sleepMsOnSetLocalRot);
  2480. }
  2481. protected void SetRot(SceneObjectPart part, Quaternion rot)
  2482. {
  2483. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2484. return;
  2485. bool isroot = (part == part.ParentGroup.RootPart);
  2486. bool isphys;
  2487. PhysicsActor pa = part.PhysActor;
  2488. // keep using physactor ideia of isphysical
  2489. // it should be SOP ideia of that
  2490. // not much of a issue with ubOde
  2491. if (pa != null && pa.IsPhysical)
  2492. isphys = true;
  2493. else
  2494. isphys = false;
  2495. // SL doesn't let scripts rotate root of physical linksets
  2496. if (isroot && isphys)
  2497. return;
  2498. part.UpdateRotation(rot);
  2499. // Update rotation does not move the object in the physics engine if it's a non physical linkset
  2500. // so do a nasty update of parts positions if is a root part rotation
  2501. if (isroot && pa != null) // with if above implies non physical root part
  2502. {
  2503. part.ParentGroup.ResetChildPrimPhysicsPositions();
  2504. }
  2505. else // fix sitting avatars. This is only needed bc of how we link avas to child parts, not root part
  2506. {
  2507. // List<ScenePresence> sittingavas = part.ParentGroup.GetLinkedAvatars();
  2508. List<ScenePresence> sittingavas = part.ParentGroup.GetSittingAvatars();
  2509. if (sittingavas.Count > 0)
  2510. {
  2511. foreach (ScenePresence av in sittingavas)
  2512. {
  2513. if (isroot || part.LocalId == av.ParentID)
  2514. av.SendTerseUpdateToAllClients();
  2515. }
  2516. }
  2517. }
  2518. }
  2519. /// <summary>
  2520. /// See http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  2521. /// </summary>
  2522. public LSL_Rotation llGetRot()
  2523. {
  2524. // unlinked or root prim then use llRootRotation
  2525. // see llRootRotaion for references.
  2526. if (m_host.LinkNum == 0 || m_host.LinkNum == 1)
  2527. {
  2528. return llGetRootRotation();
  2529. }
  2530. m_host.AddScriptLPS(1);
  2531. Quaternion q = m_host.GetWorldRotation();
  2532. if (m_host.ParentGroup != null && m_host.ParentGroup.AttachmentPoint != 0)
  2533. {
  2534. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2535. if (avatar != null)
  2536. {
  2537. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2538. q = avatar.CameraRotation * q; // Mouselook
  2539. else
  2540. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2541. }
  2542. }
  2543. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2544. }
  2545. private LSL_Rotation GetPartRot(SceneObjectPart part)
  2546. {
  2547. Quaternion q;
  2548. if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim
  2549. {
  2550. if (part.ParentGroup.AttachmentPoint != 0)
  2551. {
  2552. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2553. if (avatar != null)
  2554. {
  2555. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2556. q = avatar.CameraRotation; // Mouselook
  2557. else
  2558. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  2559. }
  2560. else
  2561. q = part.ParentGroup.GroupRotation; // Likely never get here but just in case
  2562. }
  2563. else
  2564. q = part.ParentGroup.GroupRotation; // just the group rotation
  2565. return new LSL_Rotation(q);
  2566. }
  2567. q = part.GetWorldRotation();
  2568. if (part.ParentGroup.AttachmentPoint != 0)
  2569. {
  2570. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2571. if (avatar != null)
  2572. {
  2573. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2574. q = avatar.CameraRotation * q; // Mouselook
  2575. else
  2576. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2577. }
  2578. }
  2579. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2580. }
  2581. public LSL_Rotation llGetLocalRot()
  2582. {
  2583. return GetPartLocalRot(m_host);
  2584. }
  2585. private LSL_Rotation GetPartLocalRot(SceneObjectPart part)
  2586. {
  2587. m_host.AddScriptLPS(1);
  2588. Quaternion rot = part.RotationOffset;
  2589. return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W);
  2590. }
  2591. public void llSetForce(LSL_Vector force, int local)
  2592. {
  2593. m_host.AddScriptLPS(1);
  2594. if (!m_host.ParentGroup.IsDeleted)
  2595. {
  2596. if (local != 0)
  2597. force *= llGetRot();
  2598. m_host.ParentGroup.RootPart.SetForce(force);
  2599. }
  2600. }
  2601. public LSL_Vector llGetForce()
  2602. {
  2603. LSL_Vector force = new LSL_Vector(0.0, 0.0, 0.0);
  2604. m_host.AddScriptLPS(1);
  2605. if (!m_host.ParentGroup.IsDeleted)
  2606. {
  2607. force = m_host.ParentGroup.RootPart.GetForce();
  2608. }
  2609. return force;
  2610. }
  2611. public void llSetVelocity(LSL_Vector vel, int local)
  2612. {
  2613. m_host.AddScriptLPS(1);
  2614. m_host.SetVelocity(new Vector3((float)vel.x, (float)vel.y, (float)vel.z), local != 0);
  2615. }
  2616. public void llSetAngularVelocity(LSL_Vector avel, int local)
  2617. {
  2618. m_host.AddScriptLPS(1);
  2619. m_host.SetAngularVelocity(new Vector3((float)avel.x, (float)avel.y, (float)avel.z), local != 0);
  2620. }
  2621. public LSL_Integer llTarget(LSL_Vector position, double range)
  2622. {
  2623. m_host.AddScriptLPS(1);
  2624. return m_host.ParentGroup.registerTargetWaypoint(position,
  2625. (float)range);
  2626. }
  2627. public void llTargetRemove(int number)
  2628. {
  2629. m_host.AddScriptLPS(1);
  2630. m_host.ParentGroup.unregisterTargetWaypoint(number);
  2631. }
  2632. public LSL_Integer llRotTarget(LSL_Rotation rot, double error)
  2633. {
  2634. m_host.AddScriptLPS(1);
  2635. return m_host.ParentGroup.registerRotTargetWaypoint(rot, (float)error);
  2636. }
  2637. public void llRotTargetRemove(int number)
  2638. {
  2639. m_host.AddScriptLPS(1);
  2640. m_host.ParentGroup.unregisterRotTargetWaypoint(number);
  2641. }
  2642. public void llMoveToTarget(LSL_Vector target, double tau)
  2643. {
  2644. m_host.AddScriptLPS(1);
  2645. m_host.ParentGroup.MoveToTarget(target, (float)tau);
  2646. }
  2647. public void llStopMoveToTarget()
  2648. {
  2649. m_host.AddScriptLPS(1);
  2650. m_host.ParentGroup.StopMoveToTarget();
  2651. }
  2652. public void llApplyImpulse(LSL_Vector force, LSL_Integer local)
  2653. {
  2654. m_host.AddScriptLPS(1);
  2655. //No energy force yet
  2656. Vector3 v = force;
  2657. if (v.Length() > 20000.0f)
  2658. {
  2659. v.Normalize();
  2660. v = v * 20000.0f;
  2661. }
  2662. m_host.ApplyImpulse(v, local != 0);
  2663. }
  2664. public void llApplyRotationalImpulse(LSL_Vector force, int local)
  2665. {
  2666. m_host.AddScriptLPS(1);
  2667. m_host.ParentGroup.RootPart.ApplyAngularImpulse(force, local != 0);
  2668. }
  2669. public void llSetTorque(LSL_Vector torque, int local)
  2670. {
  2671. m_host.AddScriptLPS(1);
  2672. m_host.ParentGroup.RootPart.SetAngularImpulse(torque, local != 0);
  2673. }
  2674. public LSL_Vector llGetTorque()
  2675. {
  2676. m_host.AddScriptLPS(1);
  2677. return new LSL_Vector(m_host.ParentGroup.GetTorque());
  2678. }
  2679. public void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local)
  2680. {
  2681. m_host.AddScriptLPS(1);
  2682. llSetForce(force, local);
  2683. llSetTorque(torque, local);
  2684. }
  2685. public LSL_Vector llGetVel()
  2686. {
  2687. m_host.AddScriptLPS(1);
  2688. Vector3 vel = Vector3.Zero;
  2689. if (m_host.ParentGroup.IsAttachment)
  2690. {
  2691. ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2692. if (avatar != null)
  2693. vel = avatar.GetWorldVelocity();
  2694. }
  2695. else
  2696. {
  2697. vel = m_host.ParentGroup.RootPart.Velocity;
  2698. }
  2699. return new LSL_Vector(vel);
  2700. }
  2701. public LSL_Vector llGetAccel()
  2702. {
  2703. m_host.AddScriptLPS(1);
  2704. return new LSL_Vector(m_host.Acceleration);
  2705. }
  2706. public LSL_Vector llGetOmega()
  2707. {
  2708. m_host.AddScriptLPS(1);
  2709. Vector3 avel = m_host.AngularVelocity;
  2710. return new LSL_Vector(avel.X, avel.Y, avel.Z);
  2711. }
  2712. public LSL_Float llGetTimeOfDay()
  2713. {
  2714. m_host.AddScriptLPS(1);
  2715. return (double)((DateTime.Now.TimeOfDay.TotalMilliseconds / 1000) % (3600 * 4));
  2716. }
  2717. public LSL_Float llGetWallclock()
  2718. {
  2719. m_host.AddScriptLPS(1);
  2720. return DateTime.Now.TimeOfDay.TotalSeconds;
  2721. }
  2722. public LSL_Float llGetTime()
  2723. {
  2724. m_host.AddScriptLPS(1);
  2725. double ScriptTime = Util.GetTimeStampMS() - m_timer;
  2726. return (float)Math.Round((ScriptTime / 1000.0), 3);
  2727. }
  2728. public void llResetTime()
  2729. {
  2730. m_host.AddScriptLPS(1);
  2731. m_timer = Util.GetTimeStampMS();
  2732. }
  2733. public LSL_Float llGetAndResetTime()
  2734. {
  2735. m_host.AddScriptLPS(1);
  2736. double now = Util.GetTimeStampMS();
  2737. double ScriptTime = now - m_timer;
  2738. m_timer = now;
  2739. return (float)Math.Round((ScriptTime / 1000.0), 3);
  2740. }
  2741. public void llSound(string sound, double volume, int queue, int loop)
  2742. {
  2743. m_host.AddScriptLPS(1);
  2744. Deprecated("llSound", "Use llPlaySound instead");
  2745. }
  2746. // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound
  2747. // 20080530 Updated to remove code duplication
  2748. public void llPlaySound(string sound, double volume)
  2749. {
  2750. m_host.AddScriptLPS(1);
  2751. if (m_SoundModule == null)
  2752. return;
  2753. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2754. if(soundID == UUID.Zero)
  2755. return;
  2756. // send the sound, once, to all clients in range
  2757. m_SoundModule.SendSound(m_host.UUID, soundID, volume, false, 0, false, false);
  2758. }
  2759. public void llLoopSound(string sound, double volume)
  2760. {
  2761. m_host.AddScriptLPS(1);
  2762. if (m_SoundModule == null)
  2763. return;
  2764. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2765. if(soundID == UUID.Zero)
  2766. return;
  2767. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, false,false);
  2768. }
  2769. public void llLoopSoundMaster(string sound, double volume)
  2770. {
  2771. m_host.AddScriptLPS(1);
  2772. if (m_SoundModule == null)
  2773. return;
  2774. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2775. if(soundID == UUID.Zero)
  2776. return;
  2777. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, true, false);
  2778. }
  2779. public void llLoopSoundSlave(string sound, double volume)
  2780. {
  2781. m_host.AddScriptLPS(1);
  2782. if (m_SoundModule == null)
  2783. return;
  2784. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2785. if(soundID == UUID.Zero)
  2786. return;
  2787. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, false, true);
  2788. }
  2789. public void llPlaySoundSlave(string sound, double volume)
  2790. {
  2791. m_host.AddScriptLPS(1);
  2792. if (m_SoundModule == null)
  2793. return;
  2794. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2795. if(soundID == UUID.Zero)
  2796. return;
  2797. // send the sound, once, to all clients in range
  2798. m_SoundModule.SendSound(m_host.UUID, soundID, volume, false, 0, true, false);
  2799. }
  2800. public void llTriggerSound(string sound, double volume)
  2801. {
  2802. m_host.AddScriptLPS(1);
  2803. if (m_SoundModule == null)
  2804. return;
  2805. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2806. if(soundID == UUID.Zero)
  2807. return;
  2808. // send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory.
  2809. m_SoundModule.SendSound(m_host.UUID, soundID, volume, true, 0, false, false);
  2810. }
  2811. public void llStopSound()
  2812. {
  2813. m_host.AddScriptLPS(1);
  2814. if (m_SoundModule != null)
  2815. m_SoundModule.StopSound(m_host.UUID);
  2816. }
  2817. public void llPreloadSound(string sound)
  2818. {
  2819. m_host.AddScriptLPS(1);
  2820. if (m_SoundModule == null)
  2821. return;
  2822. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2823. if(soundID == UUID.Zero)
  2824. return;
  2825. m_SoundModule.PreloadSound(m_host.UUID, soundID);
  2826. ScriptSleep(m_sleepMsOnPreloadSound);
  2827. }
  2828. /// <summary>
  2829. /// Return a portion of the designated string bounded by
  2830. /// inclusive indices (start and end). As usual, the negative
  2831. /// indices, and the tolerance for out-of-bound values, makes
  2832. /// this more complicated than it might otherwise seem.
  2833. /// </summary>
  2834. public LSL_String llGetSubString(string src, int start, int end)
  2835. {
  2836. m_host.AddScriptLPS(1);
  2837. // Normalize indices (if negative).
  2838. // After normlaization they may still be
  2839. // negative, but that is now relative to
  2840. // the start, rather than the end, of the
  2841. // sequence.
  2842. if (start < 0)
  2843. {
  2844. start = src.Length+start;
  2845. }
  2846. if (end < 0)
  2847. {
  2848. end = src.Length+end;
  2849. }
  2850. // Conventional substring
  2851. if (start <= end)
  2852. {
  2853. // Implies both bounds are out-of-range.
  2854. if (end < 0 || start >= src.Length)
  2855. {
  2856. return String.Empty;
  2857. }
  2858. // If end is positive, then it directly
  2859. // corresponds to the lengt of the substring
  2860. // needed (plus one of course). BUT, it
  2861. // must be within bounds.
  2862. if (end >= src.Length)
  2863. {
  2864. end = src.Length-1;
  2865. }
  2866. if (start < 0)
  2867. {
  2868. return src.Substring(0,end+1);
  2869. }
  2870. // Both indices are positive
  2871. return src.Substring(start, (end+1) - start);
  2872. }
  2873. // Inverted substring (end < start)
  2874. else
  2875. {
  2876. // Implies both indices are below the
  2877. // lower bound. In the inverted case, that
  2878. // means the entire string will be returned
  2879. // unchanged.
  2880. if (start < 0)
  2881. {
  2882. return src;
  2883. }
  2884. // If both indices are greater than the upper
  2885. // bound the result may seem initially counter
  2886. // intuitive.
  2887. if (end >= src.Length)
  2888. {
  2889. return src;
  2890. }
  2891. if (end < 0)
  2892. {
  2893. if (start < src.Length)
  2894. {
  2895. return src.Substring(start);
  2896. }
  2897. else
  2898. {
  2899. return String.Empty;
  2900. }
  2901. }
  2902. else
  2903. {
  2904. if (start < src.Length)
  2905. {
  2906. return src.Substring(0,end+1) + src.Substring(start);
  2907. }
  2908. else
  2909. {
  2910. return src.Substring(0,end+1);
  2911. }
  2912. }
  2913. }
  2914. }
  2915. /// <summary>
  2916. /// Delete substring removes the specified substring bounded
  2917. /// by the inclusive indices start and end. Indices may be
  2918. /// negative (indicating end-relative) and may be inverted,
  2919. /// i.e. end < start.
  2920. /// </summary>
  2921. public LSL_String llDeleteSubString(string src, int start, int end)
  2922. {
  2923. m_host.AddScriptLPS(1);
  2924. // Normalize indices (if negative).
  2925. // After normlaization they may still be
  2926. // negative, but that is now relative to
  2927. // the start, rather than the end, of the
  2928. // sequence.
  2929. if (start < 0)
  2930. {
  2931. start = src.Length+start;
  2932. }
  2933. if (end < 0)
  2934. {
  2935. end = src.Length+end;
  2936. }
  2937. // Conventionally delimited substring
  2938. if (start <= end)
  2939. {
  2940. // If both bounds are outside of the existing
  2941. // string, then return unchanges.
  2942. if (end < 0 || start >= src.Length)
  2943. {
  2944. return src;
  2945. }
  2946. // At least one bound is in-range, so we
  2947. // need to clip the out-of-bound argument.
  2948. if (start < 0)
  2949. {
  2950. start = 0;
  2951. }
  2952. if (end >= src.Length)
  2953. {
  2954. end = src.Length-1;
  2955. }
  2956. return src.Remove(start,end-start+1);
  2957. }
  2958. // Inverted substring
  2959. else
  2960. {
  2961. // In this case, out of bounds means that
  2962. // the existing string is part of the cut.
  2963. if (start < 0 || end >= src.Length)
  2964. {
  2965. return String.Empty;
  2966. }
  2967. if (end > 0)
  2968. {
  2969. if (start < src.Length)
  2970. {
  2971. return src.Remove(start).Remove(0,end+1);
  2972. }
  2973. else
  2974. {
  2975. return src.Remove(0,end+1);
  2976. }
  2977. }
  2978. else
  2979. {
  2980. if (start < src.Length)
  2981. {
  2982. return src.Remove(start);
  2983. }
  2984. else
  2985. {
  2986. return src;
  2987. }
  2988. }
  2989. }
  2990. }
  2991. /// <summary>
  2992. /// Insert string inserts the specified string identified by src
  2993. /// at the index indicated by index. Index may be negative, in
  2994. /// which case it is end-relative. The index may exceed either
  2995. /// string bound, with the result being a concatenation.
  2996. /// </summary>
  2997. public LSL_String llInsertString(string dest, int index, string src)
  2998. {
  2999. m_host.AddScriptLPS(1);
  3000. // Normalize indices (if negative).
  3001. // After normlaization they may still be
  3002. // negative, but that is now relative to
  3003. // the start, rather than the end, of the
  3004. // sequence.
  3005. if (index < 0)
  3006. {
  3007. index = dest.Length+index;
  3008. // Negative now means it is less than the lower
  3009. // bound of the string.
  3010. if (index < 0)
  3011. {
  3012. return src+dest;
  3013. }
  3014. }
  3015. if (index >= dest.Length)
  3016. {
  3017. return dest+src;
  3018. }
  3019. // The index is in bounds.
  3020. // In this case the index refers to the index that will
  3021. // be assigned to the first character of the inserted string.
  3022. // So unlike the other string operations, we do not add one
  3023. // to get the correct string length.
  3024. return dest.Substring(0,index)+src+dest.Substring(index);
  3025. }
  3026. public LSL_String llToUpper(string src)
  3027. {
  3028. m_host.AddScriptLPS(1);
  3029. return src.ToUpper();
  3030. }
  3031. public LSL_String llToLower(string src)
  3032. {
  3033. m_host.AddScriptLPS(1);
  3034. return src.ToLower();
  3035. }
  3036. public LSL_Integer llGiveMoney(LSL_Key destination, LSL_Integer amount)
  3037. {
  3038. Util.FireAndForget(x =>
  3039. {
  3040. m_host.AddScriptLPS(1);
  3041. if (m_item.PermsGranter == UUID.Zero)
  3042. return;
  3043. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  3044. {
  3045. Error("llGiveMoney", "No permissions to give money");
  3046. return;
  3047. }
  3048. UUID toID = new UUID();
  3049. if (!UUID.TryParse(destination, out toID))
  3050. {
  3051. Error("llGiveMoney", "Bad key in llGiveMoney");
  3052. return;
  3053. }
  3054. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  3055. if (money == null)
  3056. {
  3057. NotImplemented("llGiveMoney");
  3058. return;
  3059. }
  3060. string reason;
  3061. money.ObjectGiveMoney(
  3062. m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount,UUID.Zero, out reason);
  3063. }, null, "LSL_Api.llGiveMoney");
  3064. return 0;
  3065. }
  3066. public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3067. {
  3068. m_host.AddScriptLPS(1);
  3069. Deprecated("llMakeExplosion", "Use llParticleSystem instead");
  3070. ScriptSleep(m_sleepMsOnMakeExplosion);
  3071. }
  3072. public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset)
  3073. {
  3074. m_host.AddScriptLPS(1);
  3075. Deprecated("llMakeFountain", "Use llParticleSystem instead");
  3076. ScriptSleep(m_sleepMsOnMakeFountain);
  3077. }
  3078. public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3079. {
  3080. m_host.AddScriptLPS(1);
  3081. Deprecated("llMakeSmoke", "Use llParticleSystem instead");
  3082. ScriptSleep(m_sleepMsOnMakeSmoke);
  3083. }
  3084. public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3085. {
  3086. m_host.AddScriptLPS(1);
  3087. Deprecated("llMakeFire", "Use llParticleSystem instead");
  3088. ScriptSleep(m_sleepMsOnMakeFire);
  3089. }
  3090. public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  3091. {
  3092. doObjectRez(inventory, pos, vel, rot, param, true);
  3093. }
  3094. public void doObjectRez(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param, bool atRoot)
  3095. {
  3096. m_host.AddScriptLPS(1);
  3097. if (string.IsNullOrEmpty(inventory) || Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
  3098. return;
  3099. float dist = (float)llVecDist(llGetPos(), pos);
  3100. if (dist > m_ScriptDistanceFactor * 10.0f)
  3101. return;
  3102. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  3103. if (item == null)
  3104. {
  3105. Error("llRez(AtRoot/Object)", "Can't find object '" + inventory + "'");
  3106. return;
  3107. }
  3108. if (item.InvType != (int)InventoryType.Object)
  3109. {
  3110. Error("llRez(AtRoot/Object)", "Can't create requested object; object is missing from database");
  3111. return;
  3112. }
  3113. Util.FireAndForget(x =>
  3114. {
  3115. Quaternion wrot = rot;
  3116. wrot.Normalize();
  3117. List<SceneObjectGroup> new_groups = World.RezObject(m_host, item, pos, wrot, vel, param, atRoot);
  3118. // If either of these are null, then there was an unknown error.
  3119. if (new_groups == null)
  3120. return;
  3121. bool notAttachment = !m_host.ParentGroup.IsAttachment;
  3122. foreach (SceneObjectGroup group in new_groups)
  3123. {
  3124. // objects rezzed with this method are die_at_edge by default.
  3125. group.RootPart.SetDieAtEdge(true);
  3126. group.ResumeScripts();
  3127. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  3128. "object_rez", new Object[] {
  3129. new LSL_String(
  3130. group.RootPart.UUID.ToString()) },
  3131. new DetectParams[0]));
  3132. if (notAttachment)
  3133. {
  3134. float groupmass = group.GetMass();
  3135. PhysicsActor pa = group.RootPart.PhysActor;
  3136. //Recoil.
  3137. if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
  3138. {
  3139. Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
  3140. if (recoil != Vector3.Zero)
  3141. {
  3142. llApplyImpulse(recoil, 0);
  3143. }
  3144. }
  3145. }
  3146. }
  3147. }, null, "LSL_Api.doObjectRez");
  3148. //ScriptSleep((int)((groupmass * velmag) / 10));
  3149. ScriptSleep(m_sleepMsOnRezAtRoot);
  3150. }
  3151. public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  3152. {
  3153. doObjectRez(inventory, pos, vel, rot, param, false);
  3154. }
  3155. public void llLookAt(LSL_Vector target, double strength, double damping)
  3156. {
  3157. m_host.AddScriptLPS(1);
  3158. // Get the normalized vector to the target
  3159. LSL_Vector from = llGetPos();
  3160. // normalized direction to target
  3161. LSL_Vector dir = llVecNorm(target - from);
  3162. // use vertical to help compute left axis
  3163. // LSL_Vector up = new LSL_Vector(0.0, 0.0, 1.0);
  3164. // find normalized left axis parallel to horizon
  3165. // LSL_Vector left = llVecNorm(LSL_Vector.Cross(up, dir));
  3166. LSL_Vector left = new LSL_Vector(-dir.y, dir.x, 0.0f);
  3167. left = llVecNorm(left);
  3168. // make up orthogonal to left and dir
  3169. LSL_Vector up = LSL_Vector.Cross(dir, left);
  3170. // compute rotation based on orthogonal axes
  3171. // and rotate so Z points to target with X below horizont
  3172. LSL_Rotation rot = new LSL_Rotation(0.0, 0.707107, 0.0, 0.707107) * llAxes2Rot(dir, left, up);
  3173. SceneObjectGroup sog = m_host.ParentGroup;
  3174. if(sog == null || sog.IsDeleted)
  3175. return;
  3176. if (!sog.UsesPhysics || sog.IsAttachment)
  3177. {
  3178. // Do nothing if either value is 0 (this has been checked in SL)
  3179. if (strength <= 0.0 || damping <= 0.0)
  3180. return;
  3181. llSetLocalRot(rot);
  3182. }
  3183. else
  3184. {
  3185. if (strength == 0)
  3186. {
  3187. llSetLocalRot(rot);
  3188. return;
  3189. }
  3190. sog.StartLookAt(rot, (float)strength, (float)damping);
  3191. }
  3192. }
  3193. public void llStopLookAt()
  3194. {
  3195. m_host.AddScriptLPS(1);
  3196. m_host.StopLookAt();
  3197. }
  3198. public void llSetTimerEvent(double sec)
  3199. {
  3200. if (sec != 0.0 && sec < m_MinTimerInterval)
  3201. sec = m_MinTimerInterval;
  3202. m_host.AddScriptLPS(1);
  3203. // Setting timer repeat
  3204. AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
  3205. }
  3206. public virtual void llSleep(double sec)
  3207. {
  3208. // m_log.Info("llSleep snoozing " + sec + "s.");
  3209. m_host.AddScriptLPS(1);
  3210. Sleep((int)(sec * 1000));
  3211. }
  3212. public LSL_Float llGetMass()
  3213. {
  3214. m_host.AddScriptLPS(1);
  3215. if (m_host.ParentGroup.IsAttachment)
  3216. {
  3217. ScenePresence attachedAvatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  3218. if (attachedAvatar != null)
  3219. {
  3220. return attachedAvatar.GetMass();
  3221. }
  3222. else
  3223. {
  3224. return 0;
  3225. }
  3226. }
  3227. else
  3228. {
  3229. // new SL always returns object mass
  3230. // if (m_host.IsRoot)
  3231. // {
  3232. return m_host.ParentGroup.GetMass();
  3233. // }
  3234. // else
  3235. // {
  3236. // return m_host.GetMass();
  3237. // }
  3238. }
  3239. }
  3240. public LSL_Float llGetMassMKS()
  3241. {
  3242. return 100f * llGetMass();
  3243. }
  3244. public void llCollisionFilter(LSL_String name, LSL_Key id, LSL_Integer accept)
  3245. {
  3246. m_host.AddScriptLPS(1);
  3247. m_host.CollisionFilter.Clear();
  3248. UUID objectID;
  3249. if (!UUID.TryParse(id, out objectID))
  3250. objectID = UUID.Zero;
  3251. if (objectID == UUID.Zero && name == "")
  3252. return;
  3253. m_host.CollisionFilter.Add(accept,objectID.ToString() + name);
  3254. }
  3255. public void llTakeControls(int controls, int accept, int pass_on)
  3256. {
  3257. if (m_item.PermsGranter != UUID.Zero)
  3258. {
  3259. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3260. if (presence != null)
  3261. {
  3262. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3263. {
  3264. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
  3265. }
  3266. }
  3267. }
  3268. m_host.AddScriptLPS(1);
  3269. }
  3270. public void llReleaseControls()
  3271. {
  3272. m_host.AddScriptLPS(1);
  3273. if (m_item.PermsGranter != UUID.Zero)
  3274. {
  3275. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3276. if (presence != null)
  3277. {
  3278. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3279. {
  3280. // Unregister controls from Presence
  3281. presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
  3282. // Remove Take Control permission.
  3283. m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3284. }
  3285. }
  3286. }
  3287. }
  3288. public void llReleaseURL(string url)
  3289. {
  3290. m_host.AddScriptLPS(1);
  3291. if (m_UrlModule != null)
  3292. m_UrlModule.ReleaseURL(url);
  3293. }
  3294. /// <summary>
  3295. /// Attach the object containing this script to the avatar that owns it.
  3296. /// </summary>
  3297. /// <param name='attachmentPoint'>
  3298. /// The attachment point (e.g. <see cref="OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass.ATTACH_CHEST">ATTACH_CHEST</see>)
  3299. /// </param>
  3300. /// <returns>true if the attach suceeded, false if it did not</returns>
  3301. public bool AttachToAvatar(int attachmentPoint)
  3302. {
  3303. SceneObjectGroup grp = m_host.ParentGroup;
  3304. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  3305. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3306. if (attachmentsModule != null)
  3307. return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true);
  3308. else
  3309. return false;
  3310. }
  3311. /// <summary>
  3312. /// Detach the object containing this script from the avatar it is attached to.
  3313. /// </summary>
  3314. /// <remarks>
  3315. /// Nothing happens if the object is not attached.
  3316. /// </remarks>
  3317. public void DetachFromAvatar()
  3318. {
  3319. Util.FireAndForget(DetachWrapper, m_host, "LSL_Api.DetachFromAvatar");
  3320. }
  3321. private void DetachWrapper(object o)
  3322. {
  3323. if (World.AttachmentsModule != null)
  3324. {
  3325. SceneObjectPart host = (SceneObjectPart)o;
  3326. ScenePresence presence = World.GetScenePresence(host.OwnerID);
  3327. World.AttachmentsModule.DetachSingleAttachmentToInv(presence, host.ParentGroup);
  3328. }
  3329. }
  3330. public void llAttachToAvatar(LSL_Integer attachmentPoint)
  3331. {
  3332. m_host.AddScriptLPS(1);
  3333. if (m_item.PermsGranter != m_host.OwnerID)
  3334. return;
  3335. SceneObjectGroup grp = m_host.ParentGroup;
  3336. if (grp == null || grp.IsDeleted || grp.IsAttachment)
  3337. return;
  3338. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3339. AttachToAvatar(attachmentPoint);
  3340. }
  3341. public void llAttachToAvatarTemp(LSL_Integer attachmentPoint)
  3342. {
  3343. IAttachmentsModule attachmentsModule = World.RequestModuleInterface<IAttachmentsModule>();
  3344. if (attachmentsModule == null)
  3345. return;
  3346. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) == 0)
  3347. return;
  3348. SceneObjectGroup grp = m_host.ParentGroup;
  3349. if (grp == null || grp.IsDeleted || grp.IsAttachment)
  3350. return;
  3351. ScenePresence target;
  3352. if (!World.TryGetScenePresence(m_item.PermsGranter, out target))
  3353. return;
  3354. if (target.UUID != grp.OwnerID)
  3355. {
  3356. uint effectivePerms = grp.EffectiveOwnerPerms;
  3357. if ((effectivePerms & (uint)PermissionMask.Transfer) == 0)
  3358. return;
  3359. grp.SetOwner(target.UUID, target.ControllingClient.ActiveGroupId);
  3360. if (World.Permissions.PropagatePermissions())
  3361. {
  3362. foreach (SceneObjectPart child in grp.Parts)
  3363. {
  3364. child.Inventory.ChangeInventoryOwner(target.UUID);
  3365. child.TriggerScriptChangedEvent(Changed.OWNER);
  3366. child.ApplyNextOwnerPermissions();
  3367. }
  3368. grp.InvalidateEffectivePerms();
  3369. }
  3370. grp.RootPart.ObjectSaleType = 0;
  3371. grp.RootPart.SalePrice = 10;
  3372. grp.HasGroupChanged = true;
  3373. grp.RootPart.SendPropertiesToClient(target.ControllingClient);
  3374. grp.RootPart.ScheduleFullUpdate();
  3375. }
  3376. attachmentsModule.AttachObject(target, grp, (uint)attachmentPoint, false, false, true);
  3377. }
  3378. public void llDetachFromAvatar()
  3379. {
  3380. m_host.AddScriptLPS(1);
  3381. if (m_host.ParentGroup.AttachmentPoint == 0)
  3382. return;
  3383. if (m_item.PermsGranter != m_host.OwnerID)
  3384. return;
  3385. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3386. DetachFromAvatar();
  3387. }
  3388. public void llTakeCamera(string avatar)
  3389. {
  3390. m_host.AddScriptLPS(1);
  3391. Deprecated("llTakeCamera", "Use llSetCameraParams instead");
  3392. }
  3393. public void llReleaseCamera(string avatar)
  3394. {
  3395. m_host.AddScriptLPS(1);
  3396. Deprecated("llReleaseCamera", "Use llClearCameraParams instead");
  3397. }
  3398. public LSL_Key llGetOwner()
  3399. {
  3400. m_host.AddScriptLPS(1);
  3401. return m_host.OwnerID.ToString();
  3402. }
  3403. public void llInstantMessage(string user, string message)
  3404. {
  3405. m_host.AddScriptLPS(1);
  3406. UUID result;
  3407. if (!UUID.TryParse(user, out result) || result == UUID.Zero)
  3408. {
  3409. Error("llInstantMessage","An invalid key was passed to llInstantMessage");
  3410. ScriptSleep(2000);
  3411. return;
  3412. }
  3413. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  3414. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  3415. // but I don't think we have a list of scenes available from here.
  3416. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  3417. // user is a UUID
  3418. // TODO: figure out values for client, fromSession, and imSessionID
  3419. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  3420. UUID friendTransactionID = UUID.Random();
  3421. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  3422. GridInstantMessage msg = new GridInstantMessage();
  3423. msg.fromAgentID = new Guid(m_host.OwnerID.ToString()); // fromAgentID.Guid;
  3424. msg.toAgentID = new Guid(user); // toAgentID.Guid;
  3425. msg.imSessionID = new Guid(m_host.UUID.ToString()); // This is the item we're mucking with here
  3426. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  3427. msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
  3428. if (message != null && message.Length > 1024)
  3429. msg.message = message.Substring(0, 1024);
  3430. else
  3431. msg.message = message;
  3432. msg.dialog = (byte)19; // MessageFromObject
  3433. msg.fromGroup = false;// fromGroup;
  3434. msg.offline = (byte)0; //offline;
  3435. msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
  3436. msg.Position = new Vector3(m_host.AbsolutePosition);
  3437. msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
  3438. Vector3 pos = m_host.AbsolutePosition;
  3439. msg.binaryBucket
  3440. = Util.StringToBytes256(
  3441. "{0}/{1}/{2}/{3}",
  3442. World.RegionInfo.RegionName,
  3443. (int)Math.Floor(pos.X),
  3444. (int)Math.Floor(pos.Y),
  3445. (int)Math.Floor(pos.Z));
  3446. if (m_TransferModule != null)
  3447. {
  3448. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3449. }
  3450. ScriptSleep(m_sleepMsOnInstantMessage);
  3451. }
  3452. public void llEmail(string address, string subject, string message)
  3453. {
  3454. m_host.AddScriptLPS(1);
  3455. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  3456. if (emailModule == null)
  3457. {
  3458. Error("llEmail", "Email module not configured");
  3459. return;
  3460. }
  3461. //Restrict email destination to the avatars registered email address?
  3462. //The restriction only applies if the destination address is not local.
  3463. if (m_restrictEmail == true && address.Contains(m_internalObjectHost) == false)
  3464. {
  3465. UserAccount account =
  3466. World.UserAccountService.GetUserAccount(
  3467. World.RegionInfo.ScopeID,
  3468. m_host.OwnerID);
  3469. if (account == null)
  3470. {
  3471. Error("llEmail", "Can't find user account for '" + m_host.OwnerID.ToString() + "'");
  3472. return;
  3473. }
  3474. if (String.IsNullOrEmpty(account.Email))
  3475. {
  3476. Error("llEmail", "User account has not registered an email address.");
  3477. return;
  3478. }
  3479. address = account.Email;
  3480. }
  3481. emailModule.SendEmail(m_host.UUID, address, subject, message);
  3482. ScriptSleep(m_sleepMsOnEmail);
  3483. }
  3484. public void llGetNextEmail(string address, string subject)
  3485. {
  3486. m_host.AddScriptLPS(1);
  3487. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  3488. if (emailModule == null)
  3489. {
  3490. Error("llGetNextEmail", "Email module not configured");
  3491. return;
  3492. }
  3493. Email email;
  3494. email = emailModule.GetNextEmail(m_host.UUID, address, subject);
  3495. if (email == null)
  3496. return;
  3497. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  3498. new EventParams("email",
  3499. new Object[] {
  3500. new LSL_String(email.time),
  3501. new LSL_String(email.sender),
  3502. new LSL_String(email.subject),
  3503. new LSL_String(email.message),
  3504. new LSL_Integer(email.numLeft)},
  3505. new DetectParams[0]));
  3506. }
  3507. public LSL_Key llGetKey()
  3508. {
  3509. m_host.AddScriptLPS(1);
  3510. return m_host.UUID.ToString();
  3511. }
  3512. public LSL_Key llGenerateKey()
  3513. {
  3514. m_host.AddScriptLPS(1);
  3515. return UUID.Random().ToString();
  3516. }
  3517. public void llSetBuoyancy(double buoyancy)
  3518. {
  3519. m_host.AddScriptLPS(1);
  3520. if (!m_host.ParentGroup.IsDeleted)
  3521. {
  3522. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  3523. }
  3524. }
  3525. /// <summary>
  3526. /// Attempt to clamp the object on the Z axis at the given height over tau seconds.
  3527. /// </summary>
  3528. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  3529. /// <param name="water">False if height is calculated just from ground, otherwise uses ground or water depending on whichever is higher</param>
  3530. /// <param name="tau">Number of seconds over which to reach target</param>
  3531. public void llSetHoverHeight(double height, int water, double tau)
  3532. {
  3533. m_host.AddScriptLPS(1);
  3534. PIDHoverType hoverType = PIDHoverType.Ground;
  3535. if (water != 0)
  3536. {
  3537. hoverType = PIDHoverType.GroundAndWater;
  3538. }
  3539. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  3540. }
  3541. public void llStopHover()
  3542. {
  3543. m_host.AddScriptLPS(1);
  3544. m_host.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  3545. }
  3546. public void llMinEventDelay(double delay)
  3547. {
  3548. m_host.AddScriptLPS(1);
  3549. try
  3550. {
  3551. m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
  3552. }
  3553. catch (NotImplementedException)
  3554. {
  3555. // Currently not implemented in DotNetEngine only XEngine
  3556. NotImplemented("llMinEventDelay", "In DotNetEngine");
  3557. }
  3558. }
  3559. public void llSoundPreload(string sound)
  3560. {
  3561. m_host.AddScriptLPS(1);
  3562. Deprecated("llSoundPreload", "Use llPreloadSound instead");
  3563. }
  3564. public void llRotLookAt(LSL_Rotation target, double strength, double damping)
  3565. {
  3566. m_host.AddScriptLPS(1);
  3567. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  3568. // set the rotation of the object, copy that behavior
  3569. SceneObjectGroup sog = m_host.ParentGroup;
  3570. if(sog == null || sog.IsDeleted)
  3571. return;
  3572. if (strength == 0 || !sog.UsesPhysics || sog.IsAttachment)
  3573. {
  3574. llSetLocalRot(target);
  3575. }
  3576. else
  3577. {
  3578. sog.RotLookAt(target, (float)strength, (float)damping);
  3579. }
  3580. }
  3581. public LSL_Integer llStringLength(string str)
  3582. {
  3583. m_host.AddScriptLPS(1);
  3584. if (str.Length > 0)
  3585. {
  3586. return str.Length;
  3587. }
  3588. else
  3589. {
  3590. return 0;
  3591. }
  3592. }
  3593. public void llStartAnimation(string anim)
  3594. {
  3595. m_host.AddScriptLPS(1);
  3596. if (m_item.PermsGranter == UUID.Zero)
  3597. return;
  3598. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3599. {
  3600. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3601. if (presence != null)
  3602. {
  3603. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3604. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3605. if (animID == UUID.Zero)
  3606. presence.Animator.AddAnimation(anim, m_host.UUID);
  3607. else
  3608. presence.Animator.AddAnimation(animID, m_host.UUID);
  3609. }
  3610. }
  3611. }
  3612. public void llStopAnimation(string anim)
  3613. {
  3614. m_host.AddScriptLPS(1);
  3615. if (m_item.PermsGranter == UUID.Zero)
  3616. return;
  3617. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3618. {
  3619. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3620. if (presence != null)
  3621. {
  3622. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim);
  3623. if (animID == UUID.Zero)
  3624. presence.Animator.RemoveAnimation(anim);
  3625. else
  3626. presence.Animator.RemoveAnimation(animID, true);
  3627. }
  3628. }
  3629. }
  3630. public void llStartObjectAnimation(string anim)
  3631. {
  3632. m_host.AddScriptLPS(1);
  3633. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3634. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3635. if (animID == UUID.Zero)
  3636. return;
  3637. m_host.AddAnimation(animID, anim);
  3638. }
  3639. public void llStopObjectAnimation(string anim)
  3640. {
  3641. m_host.AddScriptLPS(1);
  3642. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim, AssetType.Animation);
  3643. if (animID != UUID.Zero)
  3644. m_host.RemoveAnimation(animID);
  3645. }
  3646. public LSL_List llGetObjectAnimationNames()
  3647. {
  3648. m_host.AddScriptLPS(1);
  3649. LSL_List ret = new LSL_List();
  3650. if(m_host.AnimationsNames == null || m_host.AnimationsNames.Count == 0)
  3651. return ret;
  3652. foreach (string name in m_host.AnimationsNames.Values)
  3653. ret.Add(new LSL_String(name));
  3654. return ret;
  3655. }
  3656. public void llPointAt(LSL_Vector pos)
  3657. {
  3658. m_host.AddScriptLPS(1);
  3659. }
  3660. public void llStopPointAt()
  3661. {
  3662. m_host.AddScriptLPS(1);
  3663. }
  3664. public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
  3665. {
  3666. m_host.AddScriptLPS(1);
  3667. TargetOmega(m_host, axis, spinrate, gain);
  3668. }
  3669. protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain)
  3670. {
  3671. PhysicsActor pa = part.PhysActor;
  3672. if ( ( pa == null || !pa.IsPhysical ) && gain == 0.0d )
  3673. spinrate = 0.0d;
  3674. part.UpdateAngularVelocity(axis * spinrate);
  3675. }
  3676. public LSL_Integer llGetStartParameter()
  3677. {
  3678. m_host.AddScriptLPS(1);
  3679. return m_ScriptEngine.GetStartParameter(m_item.ItemID);
  3680. }
  3681. public void llRequestPermissions(string agent, int perm)
  3682. {
  3683. UUID agentID;
  3684. if (!UUID.TryParse(agent, out agentID))
  3685. return;
  3686. if (agentID == UUID.Zero || perm == 0) // Releasing permissions
  3687. {
  3688. llReleaseControls();
  3689. m_item.PermsGranter = UUID.Zero;
  3690. m_item.PermsMask = 0;
  3691. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3692. "run_time_permissions", new Object[] {
  3693. new LSL_Integer(0) },
  3694. new DetectParams[0]));
  3695. return;
  3696. }
  3697. if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3698. llReleaseControls();
  3699. m_host.AddScriptLPS(1);
  3700. int implicitPerms = 0;
  3701. if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar)
  3702. {
  3703. // When attached, certain permissions are implicit if requested from owner
  3704. implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  3705. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3706. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3707. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3708. ScriptBaseClass.PERMISSION_ATTACH |
  3709. ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS;
  3710. }
  3711. else
  3712. {
  3713. if (m_host.ParentGroup.GetSittingAvatars().SingleOrDefault(sp => sp.UUID == agentID) != null)
  3714. {
  3715. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  3716. implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3717. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3718. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3719. ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3720. }
  3721. else
  3722. {
  3723. if (World.GetExtraSetting("auto_grant_attach_perms") == "true")
  3724. implicitPerms = ScriptBaseClass.PERMISSION_ATTACH;
  3725. }
  3726. if (World.GetExtraSetting("auto_grant_all_perms") == "true")
  3727. {
  3728. implicitPerms = perm;
  3729. }
  3730. }
  3731. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  3732. {
  3733. m_host.TaskInventory.LockItemsForWrite(true);
  3734. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3735. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3736. m_host.TaskInventory.LockItemsForWrite(false);
  3737. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3738. "run_time_permissions", new Object[] {
  3739. new LSL_Integer(perm) },
  3740. new DetectParams[0]));
  3741. return;
  3742. }
  3743. ScenePresence presence = World.GetScenePresence(agentID);
  3744. if (presence != null)
  3745. {
  3746. // If permissions are being requested from an NPC and were not implicitly granted above then
  3747. // auto grant all requested permissions if the script is owned by the NPC or the NPCs owner
  3748. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  3749. if (npcModule != null && npcModule.IsNPC(agentID, World))
  3750. {
  3751. if (npcModule.CheckPermissions(agentID, m_host.OwnerID))
  3752. {
  3753. lock (m_host.TaskInventory)
  3754. {
  3755. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3756. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3757. }
  3758. m_ScriptEngine.PostScriptEvent(
  3759. m_item.ItemID,
  3760. new EventParams(
  3761. "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
  3762. }
  3763. // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
  3764. // the question!
  3765. return;
  3766. }
  3767. string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
  3768. if (ownerName == String.Empty)
  3769. ownerName = "(hippos)";
  3770. if (!m_waitingForScriptAnswer)
  3771. {
  3772. m_host.TaskInventory.LockItemsForWrite(true);
  3773. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3774. m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
  3775. m_host.TaskInventory.LockItemsForWrite(false);
  3776. presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
  3777. m_waitingForScriptAnswer=true;
  3778. }
  3779. presence.ControllingClient.SendScriptQuestion(
  3780. m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
  3781. return;
  3782. }
  3783. // Requested agent is not in range, refuse perms
  3784. m_ScriptEngine.PostScriptEvent(
  3785. m_item.ItemID,
  3786. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
  3787. }
  3788. void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
  3789. {
  3790. if (taskID != m_host.UUID)
  3791. return;
  3792. client.OnScriptAnswer -= handleScriptAnswer;
  3793. m_waitingForScriptAnswer = false;
  3794. if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3795. llReleaseControls();
  3796. m_host.TaskInventory.LockItemsForWrite(true);
  3797. m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
  3798. m_host.TaskInventory.LockItemsForWrite(false);
  3799. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3800. "run_time_permissions", new Object[] {
  3801. new LSL_Integer(answer) },
  3802. new DetectParams[0]));
  3803. }
  3804. public LSL_Key llGetPermissionsKey()
  3805. {
  3806. m_host.AddScriptLPS(1);
  3807. return m_item.PermsGranter.ToString();
  3808. }
  3809. public LSL_Integer llGetPermissions()
  3810. {
  3811. m_host.AddScriptLPS(1);
  3812. int perms = m_item.PermsMask;
  3813. if (m_automaticLinkPermission)
  3814. perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  3815. return perms;
  3816. }
  3817. public LSL_Integer llGetLinkNumber()
  3818. {
  3819. m_host.AddScriptLPS(1);
  3820. if (m_host.ParentGroup.PrimCount > 1)
  3821. {
  3822. return m_host.LinkNum;
  3823. }
  3824. else
  3825. {
  3826. return 0;
  3827. }
  3828. }
  3829. public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
  3830. {
  3831. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3832. if (parts.Count > 0)
  3833. {
  3834. try
  3835. {
  3836. foreach (SceneObjectPart part in parts)
  3837. part.SetFaceColorAlpha(face, color, null);
  3838. }
  3839. finally { }
  3840. }
  3841. }
  3842. public void llCreateLink(LSL_Key target, LSL_Integer parent)
  3843. {
  3844. m_host.AddScriptLPS(1);
  3845. UUID targetID;
  3846. if (!UUID.TryParse(target, out targetID))
  3847. return;
  3848. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3849. && !m_automaticLinkPermission)
  3850. {
  3851. Error("llCreateLink", "PERMISSION_CHANGE_LINKS permission not set");
  3852. return;
  3853. }
  3854. CreateLink(target, parent);
  3855. }
  3856. public void CreateLink(string target, int parent)
  3857. {
  3858. UUID targetID;
  3859. if (!UUID.TryParse(target, out targetID))
  3860. return;
  3861. SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID);
  3862. if (targetPart == null)
  3863. return;
  3864. if (targetPart.ParentGroup.AttachmentPoint != 0)
  3865. return; // Fail silently if attached
  3866. if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
  3867. return;
  3868. SceneObjectGroup parentPrim = null, childPrim = null;
  3869. if (parent != 0)
  3870. {
  3871. parentPrim = m_host.ParentGroup;
  3872. childPrim = targetPart.ParentGroup;
  3873. }
  3874. else
  3875. {
  3876. parentPrim = targetPart.ParentGroup;
  3877. childPrim = m_host.ParentGroup;
  3878. }
  3879. // Required for linking
  3880. childPrim.RootPart.ClearUpdateSchedule();
  3881. parentPrim.LinkToGroup(childPrim, true);
  3882. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3883. parentPrim.RootPart.CreateSelected = true;
  3884. parentPrim.HasGroupChanged = true;
  3885. parentPrim.ScheduleGroupForFullUpdate();
  3886. IClientAPI client = null;
  3887. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  3888. if (sp != null)
  3889. client = sp.ControllingClient;
  3890. if (client != null)
  3891. parentPrim.SendPropertiesToClient(client);
  3892. ScriptSleep(m_sleepMsOnCreateLink);
  3893. }
  3894. public void llBreakLink(int linknum)
  3895. {
  3896. m_host.AddScriptLPS(1);
  3897. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3898. && !m_automaticLinkPermission)
  3899. {
  3900. Error("llBreakLink", "PERMISSION_CHANGE_LINKS permission not set");
  3901. return;
  3902. }
  3903. BreakLink(linknum);
  3904. }
  3905. public void BreakLink(int linknum)
  3906. {
  3907. if (linknum < ScriptBaseClass.LINK_THIS)
  3908. return;
  3909. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3910. if (parentPrim.AttachmentPoint != 0)
  3911. return; // Fail silently if attached
  3912. SceneObjectPart childPrim = null;
  3913. switch (linknum)
  3914. {
  3915. case ScriptBaseClass.LINK_ROOT:
  3916. break;
  3917. case ScriptBaseClass.LINK_SET:
  3918. case ScriptBaseClass.LINK_ALL_OTHERS:
  3919. case ScriptBaseClass.LINK_ALL_CHILDREN:
  3920. case ScriptBaseClass.LINK_THIS:
  3921. foreach (SceneObjectPart part in parentPrim.Parts)
  3922. {
  3923. if (part.UUID != m_host.UUID)
  3924. {
  3925. childPrim = part;
  3926. break;
  3927. }
  3928. }
  3929. break;
  3930. default:
  3931. childPrim = parentPrim.GetLinkNumPart(linknum);
  3932. if (childPrim.UUID == m_host.UUID)
  3933. childPrim = null;
  3934. break;
  3935. }
  3936. if (linknum == ScriptBaseClass.LINK_ROOT)
  3937. {
  3938. // Restructuring Multiple Prims.
  3939. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3940. parts.Remove(parentPrim.RootPart);
  3941. if (parts.Count > 0)
  3942. {
  3943. try
  3944. {
  3945. foreach (SceneObjectPart part in parts)
  3946. {
  3947. parentPrim.DelinkFromGroup(part.LocalId, true);
  3948. }
  3949. }
  3950. finally { }
  3951. }
  3952. parentPrim.HasGroupChanged = true;
  3953. parentPrim.ScheduleGroupForFullUpdate();
  3954. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3955. if (parts.Count > 0)
  3956. {
  3957. SceneObjectPart newRoot = parts[0];
  3958. parts.Remove(newRoot);
  3959. try
  3960. {
  3961. foreach (SceneObjectPart part in parts)
  3962. {
  3963. part.ClearUpdateSchedule();
  3964. newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
  3965. }
  3966. }
  3967. finally { }
  3968. newRoot.ParentGroup.HasGroupChanged = true;
  3969. newRoot.ParentGroup.ScheduleGroupForFullUpdate();
  3970. }
  3971. }
  3972. else
  3973. {
  3974. if (childPrim == null)
  3975. return;
  3976. parentPrim.DelinkFromGroup(childPrim.LocalId, true);
  3977. parentPrim.HasGroupChanged = true;
  3978. parentPrim.ScheduleGroupForFullUpdate();
  3979. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3980. }
  3981. }
  3982. public void llBreakAllLinks()
  3983. {
  3984. m_host.AddScriptLPS(1);
  3985. TaskInventoryItem item = m_item;
  3986. if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3987. && !m_automaticLinkPermission)
  3988. {
  3989. Error("llBreakAllLinks","Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
  3990. return;
  3991. }
  3992. BreakAllLinks();
  3993. }
  3994. public void BreakAllLinks()
  3995. {
  3996. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3997. if (parentPrim.AttachmentPoint != 0)
  3998. return; // Fail silently if attached
  3999. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  4000. parts.Remove(parentPrim.RootPart);
  4001. foreach (SceneObjectPart part in parts)
  4002. {
  4003. parentPrim.DelinkFromGroup(part.LocalId, true);
  4004. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  4005. }
  4006. parentPrim.HasGroupChanged = true;
  4007. parentPrim.ScheduleGroupForFullUpdate();
  4008. }
  4009. public LSL_Key llGetLinkKey(int linknum)
  4010. {
  4011. m_host.AddScriptLPS(1);
  4012. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  4013. if (part != null)
  4014. {
  4015. return part.UUID.ToString();
  4016. }
  4017. else
  4018. {
  4019. if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
  4020. {
  4021. linknum -= (m_host.ParentGroup.PrimCount) + 1;
  4022. if (linknum < 0)
  4023. return UUID.Zero.ToString();
  4024. List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
  4025. if (avatars.Count > linknum)
  4026. {
  4027. return avatars[linknum].UUID.ToString();
  4028. }
  4029. }
  4030. return UUID.Zero.ToString();
  4031. }
  4032. }
  4033. /// <summary>
  4034. /// Returns the name of the child prim or seated avatar matching the
  4035. /// specified link number.
  4036. /// </summary>
  4037. /// <param name="linknum">
  4038. /// The number of a link in the linkset or a link-related constant.
  4039. /// </param>
  4040. /// <returns>
  4041. /// The name determined to match the specified link number.
  4042. /// </returns>
  4043. /// <remarks>
  4044. /// The rules governing the returned name are not simple. The only
  4045. /// time a blank name is returned is if the target prim has a blank
  4046. /// name. If no prim with the given link number can be found then
  4047. /// usually NULL_KEY is returned but there are exceptions.
  4048. ///
  4049. /// In a single unlinked prim, A call with 0 returns the name, all
  4050. /// other values for link number return NULL_KEY
  4051. ///
  4052. /// In link sets it is more complicated.
  4053. ///
  4054. /// If the script is in the root prim:-
  4055. /// A zero link number returns NULL_KEY.
  4056. /// Positive link numbers return the name of the prim, or NULL_KEY
  4057. /// if a prim does not exist at that position.
  4058. /// Negative link numbers return the name of the first child prim.
  4059. ///
  4060. /// If the script is in a child prim:-
  4061. /// Link numbers 0 or 1 return the name of the root prim.
  4062. /// Positive link numbers return the name of the prim or NULL_KEY
  4063. /// if a prim does not exist at that position.
  4064. /// Negative numbers return the name of the root prim.
  4065. ///
  4066. /// References
  4067. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetLinkName
  4068. /// Mentions NULL_KEY being returned
  4069. /// http://wiki.secondlife.com/wiki/LlGetLinkName
  4070. /// Mentions using the LINK_* constants, some of which are negative
  4071. /// </remarks>
  4072. public LSL_String llGetLinkName(int linknum)
  4073. {
  4074. m_host.AddScriptLPS(1);
  4075. ISceneEntity entity = GetLinkEntity(m_host, linknum);
  4076. if (entity != null)
  4077. return entity.Name;
  4078. else
  4079. return ScriptBaseClass.NULL_KEY;
  4080. }
  4081. public LSL_Integer llGetInventoryNumber(int type)
  4082. {
  4083. m_host.AddScriptLPS(1);
  4084. int count = 0;
  4085. m_host.TaskInventory.LockItemsForRead(true);
  4086. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4087. {
  4088. if (inv.Value.Type == type || type == -1)
  4089. {
  4090. count = count + 1;
  4091. }
  4092. }
  4093. m_host.TaskInventory.LockItemsForRead(false);
  4094. return count;
  4095. }
  4096. public LSL_String llGetInventoryName(int type, int number)
  4097. {
  4098. m_host.AddScriptLPS(1);
  4099. ArrayList keys = new ArrayList();
  4100. m_host.TaskInventory.LockItemsForRead(true);
  4101. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4102. {
  4103. if (inv.Value.Type == type || type == -1)
  4104. {
  4105. keys.Add(inv.Value.Name);
  4106. }
  4107. }
  4108. m_host.TaskInventory.LockItemsForRead(false);
  4109. if (keys.Count == 0)
  4110. {
  4111. return String.Empty;
  4112. }
  4113. keys.Sort();
  4114. if (keys.Count > number)
  4115. {
  4116. return (string)keys[number];
  4117. }
  4118. return String.Empty;
  4119. }
  4120. public LSL_Float llGetEnergy()
  4121. {
  4122. m_host.AddScriptLPS(1);
  4123. // TODO: figure out real energy value
  4124. return 1.0f;
  4125. }
  4126. public void llGiveInventory(LSL_Key destination, LSL_String inventory)
  4127. {
  4128. m_host.AddScriptLPS(1);
  4129. UUID destId = UUID.Zero;
  4130. if (!UUID.TryParse(destination, out destId))
  4131. {
  4132. Error("llGiveInventory", "Can't parse destination key '" + destination + "'");
  4133. return;
  4134. }
  4135. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  4136. if (item == null)
  4137. {
  4138. Error("llGiveInventory", "Can't find inventory object '" + inventory + "'");
  4139. return;
  4140. }
  4141. UUID objId = item.ItemID;
  4142. // check if destination is an object
  4143. if (World.GetSceneObjectPart(destId) != null)
  4144. {
  4145. // destination is an object
  4146. World.MoveTaskInventoryItem(destId, m_host, objId);
  4147. }
  4148. else
  4149. {
  4150. ScenePresence presence = World.GetScenePresence(destId);
  4151. if (presence == null)
  4152. {
  4153. UserAccount account =
  4154. World.UserAccountService.GetUserAccount(
  4155. World.RegionInfo.ScopeID,
  4156. destId);
  4157. if (account == null)
  4158. {
  4159. GridUserInfo info = World.GridUserService.GetGridUserInfo(destId.ToString());
  4160. if(info == null || info.Online == false)
  4161. {
  4162. Error("llGiveInventory", "Can't find destination '" + destId.ToString() + "'");
  4163. return;
  4164. }
  4165. }
  4166. }
  4167. // destination is an avatar
  4168. string message;
  4169. InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out message);
  4170. if (agentItem == null)
  4171. {
  4172. llSay(0, message);
  4173. return;
  4174. }
  4175. byte[] bucket = new byte[1];
  4176. bucket[0] = (byte)item.Type;
  4177. //byte[] objBytes = agentItem.ID.GetBytes();
  4178. //Array.Copy(objBytes, 0, bucket, 1, 16);
  4179. GridInstantMessage msg = new GridInstantMessage(World,
  4180. m_host.OwnerID, m_host.Name, destId,
  4181. (byte)InstantMessageDialog.TaskInventoryOffered,
  4182. false, item.Name+". "+m_host.Name+" is located at "+
  4183. World.RegionInfo.RegionName+" "+
  4184. m_host.AbsolutePosition.ToString(),
  4185. agentItem.ID, true, m_host.AbsolutePosition,
  4186. bucket, true);
  4187. ScenePresence sp;
  4188. if (World.TryGetScenePresence(destId, out sp))
  4189. {
  4190. sp.ControllingClient.SendInstantMessage(msg);
  4191. }
  4192. else
  4193. {
  4194. if (m_TransferModule != null)
  4195. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  4196. }
  4197. //This delay should only occur when giving inventory to avatars.
  4198. ScriptSleep(m_sleepMsOnGiveInventory);
  4199. }
  4200. }
  4201. [DebuggerNonUserCode]
  4202. public void llRemoveInventory(string name)
  4203. {
  4204. m_host.AddScriptLPS(1);
  4205. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4206. if (item == null)
  4207. return;
  4208. if (item.ItemID == m_item.ItemID)
  4209. throw new ScriptDeleteException();
  4210. else
  4211. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  4212. }
  4213. public void llSetText(string text, LSL_Vector color, double alpha)
  4214. {
  4215. m_host.AddScriptLPS(1);
  4216. Vector3 av3 = Util.Clip(color, 0.0f, 1.0f);
  4217. byte[] data;
  4218. data = Util.StringToBytes256(text);
  4219. text = Util.UTF8.GetString(data);
  4220. m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
  4221. }
  4222. public LSL_Float llWater(LSL_Vector offset)
  4223. {
  4224. m_host.AddScriptLPS(1);
  4225. return World.RegionInfo.RegionSettings.WaterHeight;
  4226. }
  4227. public void llPassTouches(int pass)
  4228. {
  4229. m_host.AddScriptLPS(1);
  4230. if (pass != 0)
  4231. m_host.PassTouches = true;
  4232. else
  4233. m_host.PassTouches = false;
  4234. }
  4235. public LSL_Key llRequestAgentData(string id, int data)
  4236. {
  4237. m_host.AddScriptLPS(1);
  4238. UUID uuid;
  4239. if (UUID.TryParse(id, out uuid))
  4240. {
  4241. PresenceInfo pinfo = null;
  4242. UserAccount account;
  4243. UserInfoCacheEntry ce;
  4244. if (!m_userInfoCache.TryGetValue(uuid, out ce))
  4245. {
  4246. account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
  4247. if (account == null)
  4248. {
  4249. m_userInfoCache[uuid] = null; // Cache negative
  4250. return UUID.Zero.ToString();
  4251. }
  4252. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  4253. if (pinfos != null && pinfos.Length > 0)
  4254. {
  4255. foreach (PresenceInfo p in pinfos)
  4256. {
  4257. if (p.RegionID != UUID.Zero)
  4258. {
  4259. pinfo = p;
  4260. }
  4261. }
  4262. }
  4263. ce = new UserInfoCacheEntry();
  4264. ce.time = Util.EnvironmentTickCount();
  4265. ce.account = account;
  4266. ce.pinfo = pinfo;
  4267. m_userInfoCache[uuid] = ce;
  4268. }
  4269. else
  4270. {
  4271. if (ce == null)
  4272. return UUID.Zero.ToString();
  4273. account = ce.account;
  4274. pinfo = ce.pinfo;
  4275. }
  4276. if (Util.EnvironmentTickCount() < ce.time ||
  4277. (Util.EnvironmentTickCount() - ce.time) >= LlRequestAgentDataCacheTimeoutMs)
  4278. {
  4279. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  4280. if (pinfos != null && pinfos.Length > 0)
  4281. {
  4282. foreach (PresenceInfo p in pinfos)
  4283. {
  4284. if (p.RegionID != UUID.Zero)
  4285. {
  4286. pinfo = p;
  4287. }
  4288. }
  4289. }
  4290. else
  4291. pinfo = null;
  4292. ce.time = Util.EnvironmentTickCount();
  4293. ce.pinfo = pinfo;
  4294. }
  4295. string reply = String.Empty;
  4296. switch (data)
  4297. {
  4298. case ScriptBaseClass.DATA_ONLINE: // DATA_ONLINE (0|1)
  4299. if (pinfo != null && pinfo.RegionID != UUID.Zero)
  4300. reply = "1";
  4301. else
  4302. reply = "0";
  4303. break;
  4304. case ScriptBaseClass.DATA_NAME: // DATA_NAME (First Last)
  4305. reply = account.FirstName + " " + account.LastName;
  4306. break;
  4307. case ScriptBaseClass.DATA_BORN: // DATA_BORN (YYYY-MM-DD)
  4308. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  4309. born = born.AddSeconds(account.Created);
  4310. reply = born.ToString("yyyy-MM-dd");
  4311. break;
  4312. case ScriptBaseClass.DATA_RATING: // DATA_RATING (0,0,0,0,0,0)
  4313. reply = "0,0,0,0,0,0";
  4314. break;
  4315. case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant.
  4316. reply = account.UserLevel.ToString();
  4317. break;
  4318. case ScriptBaseClass.DATA_PAYINFO: // DATA_PAYINFO (0|1|2|3)
  4319. reply = "0";
  4320. break;
  4321. default:
  4322. return UUID.Zero.ToString(); // Raise no event
  4323. }
  4324. UUID rq = UUID.Random();
  4325. UUID tid = AsyncCommands.
  4326. DataserverPlugin.RegisterRequest(m_host.LocalId,
  4327. m_item.ItemID, rq.ToString());
  4328. AsyncCommands.
  4329. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  4330. ScriptSleep(m_sleepMsOnRequestAgentData);
  4331. return tid.ToString();
  4332. }
  4333. else
  4334. {
  4335. Error("llRequestAgentData","Invalid UUID passed to llRequestAgentData.");
  4336. }
  4337. return "";
  4338. }
  4339. public LSL_Key llRequestInventoryData(string name)
  4340. {
  4341. m_host.AddScriptLPS(1);
  4342. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  4343. {
  4344. if (item.Type == 3 && item.Name == name)
  4345. {
  4346. UUID tid = AsyncCommands.
  4347. DataserverPlugin.RegisterRequest(m_host.LocalId,
  4348. m_item.ItemID, item.AssetID.ToString());
  4349. Vector3 region = new Vector3(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  4350. World.AssetService.Get(item.AssetID.ToString(), this,
  4351. delegate(string i, object sender, AssetBase a)
  4352. {
  4353. AssetLandmark lm = new AssetLandmark(a);
  4354. float rx = (uint)(lm.RegionHandle >> 32);
  4355. float ry = (uint)lm.RegionHandle;
  4356. region = lm.Position + new Vector3(rx, ry, 0) - region;
  4357. string reply = region.ToString();
  4358. AsyncCommands.
  4359. DataserverPlugin.DataserverReply(i.ToString(),
  4360. reply);
  4361. });
  4362. ScriptSleep(m_sleepMsOnRequestInventoryData);
  4363. return tid.ToString();
  4364. }
  4365. }
  4366. ScriptSleep(m_sleepMsOnRequestInventoryData);
  4367. return String.Empty;
  4368. }
  4369. public void llSetDamage(double damage)
  4370. {
  4371. m_host.AddScriptLPS(1);
  4372. m_host.ParentGroup.Damage = (float)damage;
  4373. }
  4374. public void llTeleportAgentHome(string agent)
  4375. {
  4376. m_host.AddScriptLPS(1);
  4377. UUID agentId = new UUID();
  4378. if (UUID.TryParse(agent, out agentId))
  4379. {
  4380. ScenePresence presence = World.GetScenePresence(agentId);
  4381. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4382. {
  4383. // agent must not be a god
  4384. if (presence.GodController.UserLevel >= 200) return;
  4385. // agent must be over the owners land
  4386. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  4387. {
  4388. if (!World.TeleportClientHome(agentId, presence.ControllingClient))
  4389. {
  4390. // They can't be teleported home for some reason
  4391. GridRegion regionInfo = World.GridService.GetRegionByUUID(UUID.Zero, new UUID("2b02daac-e298-42fa-9a75-f488d37896e6"));
  4392. if (regionInfo != null)
  4393. {
  4394. World.RequestTeleportLocation(
  4395. presence.ControllingClient, regionInfo.RegionHandle, new Vector3(128, 128, 23), Vector3.Zero,
  4396. (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
  4397. }
  4398. }
  4399. }
  4400. }
  4401. }
  4402. ScriptSleep(m_sleepMsOnSetDamage);
  4403. }
  4404. public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4405. {
  4406. m_host.AddScriptLPS(1);
  4407. UUID agentId = new UUID();
  4408. if (UUID.TryParse(agent, out agentId))
  4409. {
  4410. ScenePresence presence = World.GetScenePresence(agentId);
  4411. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4412. {
  4413. if (destination == String.Empty)
  4414. destination = World.RegionInfo.RegionName;
  4415. if (m_item.PermsGranter == agentId)
  4416. {
  4417. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4418. {
  4419. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4420. }
  4421. }
  4422. // agent must be wearing the object
  4423. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  4424. {
  4425. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4426. }
  4427. else
  4428. {
  4429. // agent must not be a god
  4430. if (presence.IsViewerUIGod) return;
  4431. // agent must be over the owners land
  4432. ILandObject agentLand = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  4433. ILandObject objectLand = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  4434. if (m_host.OwnerID == objectLand.LandData.OwnerID && m_host.OwnerID == agentLand.LandData.OwnerID)
  4435. {
  4436. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4437. }
  4438. }
  4439. }
  4440. }
  4441. }
  4442. public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4443. {
  4444. m_host.AddScriptLPS(1);
  4445. UUID agentId = new UUID();
  4446. ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y);
  4447. if (UUID.TryParse(agent, out agentId))
  4448. {
  4449. // This function is owner only!
  4450. if (m_host.OwnerID != agentId)
  4451. return;
  4452. ScenePresence presence = World.GetScenePresence(agentId);
  4453. if (presence == null || presence.PresenceType == PresenceType.Npc)
  4454. return;
  4455. // Can't TP sitting avatars
  4456. if (presence.ParentID != 0) // Sitting
  4457. return;
  4458. if (m_item.PermsGranter == agentId)
  4459. {
  4460. // If attached using llAttachToAvatarTemp, cowardly refuse
  4461. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.ParentGroup.FromItemID == UUID.Zero)
  4462. return;
  4463. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4464. {
  4465. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4466. }
  4467. }
  4468. }
  4469. }
  4470. private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt)
  4471. {
  4472. UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination);
  4473. // The destinaion is not an asset ID and also doesn't name a landmark.
  4474. // Use it as a sim name
  4475. if (assetID == UUID.Zero)
  4476. {
  4477. World.RequestTeleportLocation(sp.ControllingClient, destination, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4478. return;
  4479. }
  4480. AssetBase lma = World.AssetService.Get(assetID.ToString());
  4481. if (lma == null)
  4482. return;
  4483. if (lma.Type != (sbyte)AssetType.Landmark)
  4484. return;
  4485. AssetLandmark lm = new AssetLandmark(lma);
  4486. World.RequestTeleportLocation(sp.ControllingClient, lm.RegionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4487. }
  4488. public void llTextBox(string agent, string message, int chatChannel)
  4489. {
  4490. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  4491. if (dm == null)
  4492. return;
  4493. m_host.AddScriptLPS(1);
  4494. UUID av = new UUID();
  4495. if (!UUID.TryParse(agent,out av))
  4496. {
  4497. Error("llTextBox", "First parameter must be a key");
  4498. return;
  4499. }
  4500. if (message == string.Empty)
  4501. {
  4502. Error("llTextBox", "Empty message");
  4503. }
  4504. else if (Encoding.UTF8.GetByteCount(message) > 512)
  4505. {
  4506. Error("llTextBox", "Message longer than 512 bytes");
  4507. }
  4508. else
  4509. {
  4510. dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID);
  4511. ScriptSleep(m_sleepMsOnTextBox);
  4512. }
  4513. }
  4514. public void llModifyLand(int action, int brush)
  4515. {
  4516. m_host.AddScriptLPS(1);
  4517. ITerrainModule tm = m_ScriptEngine.World.RequestModuleInterface<ITerrainModule>();
  4518. if (tm != null)
  4519. {
  4520. tm.ModifyTerrain(m_host.OwnerID, m_host.AbsolutePosition, (byte) brush, (byte) action);
  4521. }
  4522. }
  4523. public void llCollisionSound(LSL_String impact_sound, LSL_Float impact_volume)
  4524. {
  4525. m_host.AddScriptLPS(1);
  4526. if(impact_sound == "")
  4527. {
  4528. m_host.CollisionSoundVolume = (float)impact_volume;
  4529. m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
  4530. m_host.CollisionSoundType = -1; // disable all sounds
  4531. m_host.aggregateScriptEvents();
  4532. return;
  4533. }
  4534. // TODO: Parameter check logic required.
  4535. UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
  4536. if(soundId != UUID.Zero)
  4537. {
  4538. m_host.CollisionSound = soundId;
  4539. m_host.CollisionSoundVolume = (float)impact_volume;
  4540. m_host.CollisionSoundType = 1;
  4541. }
  4542. else
  4543. m_host.CollisionSoundType = -1;
  4544. m_host.aggregateScriptEvents();
  4545. }
  4546. public LSL_String llGetAnimation(LSL_Key id)
  4547. {
  4548. // This should only return a value if the avatar is in the same region
  4549. m_host.AddScriptLPS(1);
  4550. UUID avatar;
  4551. if(!UUID.TryParse(id, out avatar))
  4552. return "";
  4553. ScenePresence presence = World.GetScenePresence(avatar);
  4554. if (presence == null)
  4555. return "";
  4556. if (m_host.RegionHandle == presence.RegionHandle)
  4557. {
  4558. if (presence != null)
  4559. {
  4560. // if (presence.SitGround)
  4561. // return "Sitting on Ground";
  4562. // if (presence.ParentID != 0 || presence.ParentUUID != UUID.Zero)
  4563. // return "Sitting";
  4564. string movementAnimation = presence.Animator.CurrentMovementAnimation;
  4565. string lslMovementAnimation;
  4566. if (MovementAnimationsForLSL.TryGetValue(movementAnimation, out lslMovementAnimation))
  4567. return lslMovementAnimation;
  4568. }
  4569. }
  4570. return String.Empty;
  4571. }
  4572. public void llMessageLinked(int linknumber, int num, string msg, string id)
  4573. {
  4574. m_host.AddScriptLPS(1);
  4575. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  4576. UUID partItemID;
  4577. foreach (SceneObjectPart part in parts)
  4578. {
  4579. foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems())
  4580. {
  4581. if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
  4582. {
  4583. partItemID = item.ItemID;
  4584. int linkNumber = m_host.LinkNum;
  4585. if (m_host.ParentGroup.PrimCount == 1)
  4586. linkNumber = 0;
  4587. object[] resobj = new object[]
  4588. {
  4589. new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
  4590. };
  4591. m_ScriptEngine.PostScriptEvent(partItemID,
  4592. new EventParams("link_message",
  4593. resobj, new DetectParams[0]));
  4594. }
  4595. }
  4596. }
  4597. }
  4598. public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
  4599. {
  4600. m_host.AddScriptLPS(1);
  4601. bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
  4602. bool pushAllowed = false;
  4603. bool pusheeIsAvatar = false;
  4604. UUID targetID = UUID.Zero;
  4605. if (!UUID.TryParse(target,out targetID))
  4606. return;
  4607. ScenePresence pusheeav = null;
  4608. Vector3 PusheePos = Vector3.Zero;
  4609. SceneObjectPart pusheeob = null;
  4610. ScenePresence avatar = World.GetScenePresence(targetID);
  4611. if (avatar != null)
  4612. {
  4613. pusheeIsAvatar = true;
  4614. // Pushee doesn't have a physics actor
  4615. if (avatar.PhysicsActor == null)
  4616. return;
  4617. // Pushee is in GodMode this pushing object isn't owned by them
  4618. if (avatar.IsViewerUIGod && m_host.OwnerID != targetID)
  4619. return;
  4620. pusheeav = avatar;
  4621. // Find pushee position
  4622. // Pushee Linked?
  4623. SceneObjectPart sitPart = pusheeav.ParentPart;
  4624. if (sitPart != null)
  4625. PusheePos = sitPart.AbsolutePosition;
  4626. else
  4627. PusheePos = pusheeav.AbsolutePosition;
  4628. }
  4629. if (!pusheeIsAvatar)
  4630. {
  4631. // not an avatar so push is not affected by parcel flags
  4632. pusheeob = World.GetSceneObjectPart((UUID)target);
  4633. // We can't find object
  4634. if (pusheeob == null)
  4635. return;
  4636. // Object not pushable. Not an attachment and has no physics component
  4637. if (!pusheeob.ParentGroup.IsAttachment && pusheeob.PhysActor == null)
  4638. return;
  4639. PusheePos = pusheeob.AbsolutePosition;
  4640. pushAllowed = true;
  4641. }
  4642. else
  4643. {
  4644. if (pushrestricted)
  4645. {
  4646. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4647. // We didn't find the parcel but region is push restricted so assume it is NOT ok
  4648. if (targetlandObj == null)
  4649. return;
  4650. // Need provisions for Group Owned here
  4651. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4652. targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
  4653. {
  4654. pushAllowed = true;
  4655. }
  4656. }
  4657. else
  4658. {
  4659. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4660. if (targetlandObj == null)
  4661. {
  4662. // We didn't find the parcel but region isn't push restricted so assume it's ok
  4663. pushAllowed = true;
  4664. }
  4665. else
  4666. {
  4667. // Parcel push restriction
  4668. if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
  4669. {
  4670. // Need provisions for Group Owned here
  4671. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4672. targetlandObj.LandData.IsGroupOwned ||
  4673. m_host.OwnerID == targetID)
  4674. {
  4675. pushAllowed = true;
  4676. }
  4677. //ParcelFlags.RestrictPushObject
  4678. //pushAllowed = true;
  4679. }
  4680. else
  4681. {
  4682. // Parcel isn't push restricted
  4683. pushAllowed = true;
  4684. }
  4685. }
  4686. }
  4687. }
  4688. if (pushAllowed)
  4689. {
  4690. float distance = (PusheePos - m_host.AbsolutePosition).Length();
  4691. float distance_term = distance * distance * distance; // Script Energy
  4692. // use total object mass and not part
  4693. float pusher_mass = m_host.ParentGroup.GetMass();
  4694. float PUSH_ATTENUATION_DISTANCE = 17f;
  4695. float PUSH_ATTENUATION_SCALE = 5f;
  4696. float distance_attenuation = 1f;
  4697. if (distance > PUSH_ATTENUATION_DISTANCE)
  4698. {
  4699. float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
  4700. distance_attenuation = 1f / normalized_units;
  4701. }
  4702. Vector3 applied_linear_impulse = impulse;
  4703. {
  4704. float impulse_length = applied_linear_impulse.Length();
  4705. float desired_energy = impulse_length * pusher_mass;
  4706. if (desired_energy > 0f)
  4707. desired_energy += distance_term;
  4708. float scaling_factor = 1f;
  4709. scaling_factor *= distance_attenuation;
  4710. applied_linear_impulse *= scaling_factor;
  4711. }
  4712. if (pusheeIsAvatar)
  4713. {
  4714. if (pusheeav != null)
  4715. {
  4716. PhysicsActor pa = pusheeav.PhysicsActor;
  4717. if (pa != null)
  4718. {
  4719. if (local != 0)
  4720. {
  4721. // applied_linear_impulse *= m_host.GetWorldRotation();
  4722. applied_linear_impulse *= pusheeav.GetWorldRotation();
  4723. }
  4724. pa.AddForce(applied_linear_impulse, true);
  4725. }
  4726. }
  4727. }
  4728. else
  4729. {
  4730. if (pusheeob != null)
  4731. {
  4732. if (pusheeob.PhysActor != null)
  4733. {
  4734. pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
  4735. }
  4736. }
  4737. }
  4738. }
  4739. }
  4740. public void llPassCollisions(int pass)
  4741. {
  4742. m_host.AddScriptLPS(1);
  4743. if (pass == 0)
  4744. {
  4745. m_host.PassCollisions = false;
  4746. }
  4747. else
  4748. {
  4749. m_host.PassCollisions = true;
  4750. }
  4751. }
  4752. public LSL_String llGetScriptName()
  4753. {
  4754. m_host.AddScriptLPS(1);
  4755. return m_item.Name != null ? m_item.Name : String.Empty;
  4756. }
  4757. public LSL_Integer llGetLinkNumberOfSides(int link)
  4758. {
  4759. m_host.AddScriptLPS(1);
  4760. SceneObjectPart linkedPart;
  4761. if (link == ScriptBaseClass.LINK_ROOT)
  4762. linkedPart = m_host.ParentGroup.RootPart;
  4763. else if (link == ScriptBaseClass.LINK_THIS)
  4764. linkedPart = m_host;
  4765. else
  4766. linkedPart = m_host.ParentGroup.GetLinkNumPart(link);
  4767. return GetNumberOfSides(linkedPart);
  4768. }
  4769. public LSL_Integer llGetNumberOfSides()
  4770. {
  4771. m_host.AddScriptLPS(1);
  4772. return m_host.GetNumberOfSides();
  4773. }
  4774. protected int GetNumberOfSides(SceneObjectPart part)
  4775. {
  4776. return part.GetNumberOfSides();
  4777. }
  4778. /* The new / changed functions were tested with the following LSL script:
  4779. default
  4780. {
  4781. state_entry()
  4782. {
  4783. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  4784. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  4785. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  4786. // convert back and forth between quaternion <-> vector and angle
  4787. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  4788. llOwnerSay("Old rotation was: "+(string) rot);
  4789. llOwnerSay("re-converted rotation is: "+(string) newrot);
  4790. llSetRot(rot); // to check the parameters in the prim
  4791. }
  4792. }
  4793. */
  4794. // Xantor 29/apr/2008
  4795. // Returns rotation described by rotating angle radians about axis.
  4796. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  4797. public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
  4798. {
  4799. m_host.AddScriptLPS(1);
  4800. double x, y, z, s, t;
  4801. s = Math.Cos(angle * 0.5);
  4802. t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
  4803. axis = LSL_Vector.Norm(axis);
  4804. x = axis.x * t;
  4805. y = axis.y * t;
  4806. z = axis.z * t;
  4807. return new LSL_Rotation(x,y,z,s);
  4808. }
  4809. /// <summary>
  4810. /// Returns the axis of rotation for a quaternion
  4811. /// </summary>
  4812. /// <returns></returns>
  4813. /// <param name='rot'></param>
  4814. public LSL_Vector llRot2Axis(LSL_Rotation rot)
  4815. {
  4816. m_host.AddScriptLPS(1);
  4817. rot.Normalize();
  4818. double s = Math.Sqrt(1 - rot.s * rot.s);
  4819. if (s < 1e-8)
  4820. return new LSL_Vector(0, 0, 0);
  4821. double invS = 1.0 / s;
  4822. if (rot.s < 0)
  4823. invS = -invS;
  4824. return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS);
  4825. }
  4826. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  4827. public LSL_Float llRot2Angle(LSL_Rotation rot)
  4828. {
  4829. m_host.AddScriptLPS(1);
  4830. rot.Normalize();
  4831. double angle = 2 * Math.Acos(rot.s);
  4832. if (angle > Math.PI)
  4833. angle = 2 * Math.PI - angle;
  4834. return angle;
  4835. }
  4836. public LSL_Float llAcos(LSL_Float val)
  4837. {
  4838. m_host.AddScriptLPS(1);
  4839. return (double)Math.Acos(val);
  4840. }
  4841. public LSL_Float llAsin(LSL_Float val)
  4842. {
  4843. m_host.AddScriptLPS(1);
  4844. return (double)Math.Asin(val);
  4845. }
  4846. // jcochran 5/jan/2012
  4847. public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
  4848. {
  4849. m_host.AddScriptLPS(1);
  4850. double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s);
  4851. double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s);
  4852. double aa_bb = aa * bb;
  4853. if (aa_bb == 0) return 0.0;
  4854. double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s);
  4855. double quotient = (ab * ab) / aa_bb;
  4856. if (quotient >= 1.0) return 0.0;
  4857. return Math.Acos(2 * quotient - 1);
  4858. }
  4859. public LSL_Key llGetInventoryKey(string name)
  4860. {
  4861. m_host.AddScriptLPS(1);
  4862. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4863. if (item == null)
  4864. return UUID.Zero.ToString();
  4865. if ((item.CurrentPermissions
  4866. & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4867. == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4868. {
  4869. return item.AssetID.ToString();
  4870. }
  4871. return UUID.Zero.ToString();
  4872. }
  4873. public void llAllowInventoryDrop(LSL_Integer add)
  4874. {
  4875. m_host.AddScriptLPS(1);
  4876. if (add != 0)
  4877. m_host.ParentGroup.RootPart.AllowedDrop = true;
  4878. else
  4879. m_host.ParentGroup.RootPart.AllowedDrop = false;
  4880. // Update the object flags
  4881. m_host.ParentGroup.RootPart.aggregateScriptEvents();
  4882. }
  4883. public LSL_Vector llGetSunDirection()
  4884. {
  4885. m_host.AddScriptLPS(1);
  4886. Vector3 sun = World.RegionInfo.RegionSettings.SunVector;
  4887. return new LSL_Vector(sun);
  4888. }
  4889. public LSL_Vector llGetTextureOffset(int face)
  4890. {
  4891. m_host.AddScriptLPS(1);
  4892. return GetTextureOffset(m_host, face);
  4893. }
  4894. protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
  4895. {
  4896. Primitive.TextureEntry tex = part.Shape.Textures;
  4897. LSL_Vector offset = new LSL_Vector();
  4898. if (face == ScriptBaseClass.ALL_SIDES)
  4899. {
  4900. face = 0;
  4901. }
  4902. if (face >= 0 && face < GetNumberOfSides(part))
  4903. {
  4904. offset.x = tex.GetFace((uint)face).OffsetU;
  4905. offset.y = tex.GetFace((uint)face).OffsetV;
  4906. offset.z = 0.0;
  4907. return offset;
  4908. }
  4909. else
  4910. {
  4911. return offset;
  4912. }
  4913. }
  4914. public LSL_Vector llGetTextureScale(int side)
  4915. {
  4916. m_host.AddScriptLPS(1);
  4917. Primitive.TextureEntry tex = m_host.Shape.Textures;
  4918. LSL_Vector scale;
  4919. if (side == -1)
  4920. {
  4921. side = 0;
  4922. }
  4923. scale.x = tex.GetFace((uint)side).RepeatU;
  4924. scale.y = tex.GetFace((uint)side).RepeatV;
  4925. scale.z = 0.0;
  4926. return scale;
  4927. }
  4928. public LSL_Float llGetTextureRot(int face)
  4929. {
  4930. m_host.AddScriptLPS(1);
  4931. return GetTextureRot(m_host, face);
  4932. }
  4933. protected LSL_Float GetTextureRot(SceneObjectPart part, int face)
  4934. {
  4935. Primitive.TextureEntry tex = part.Shape.Textures;
  4936. if (face == -1)
  4937. {
  4938. face = 0;
  4939. }
  4940. if (face >= 0 && face < GetNumberOfSides(part))
  4941. {
  4942. return tex.GetFace((uint)face).Rotation;
  4943. }
  4944. else
  4945. {
  4946. return 0.0;
  4947. }
  4948. }
  4949. public LSL_Integer llSubStringIndex(string source, string pattern)
  4950. {
  4951. m_host.AddScriptLPS(1);
  4952. if (string.IsNullOrEmpty(source))
  4953. return -1;
  4954. if (string.IsNullOrEmpty(pattern))
  4955. return 0;
  4956. return source.IndexOf(pattern);
  4957. }
  4958. public LSL_Key llGetOwnerKey(string id)
  4959. {
  4960. m_host.AddScriptLPS(1);
  4961. UUID key = new UUID();
  4962. if (UUID.TryParse(id, out key))
  4963. {
  4964. try
  4965. {
  4966. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4967. if (obj == null)
  4968. return id; // the key is for an agent so just return the key
  4969. else
  4970. return obj.OwnerID.ToString();
  4971. }
  4972. catch (KeyNotFoundException)
  4973. {
  4974. return id; // The Object/Agent not in the region so just return the key
  4975. }
  4976. }
  4977. else
  4978. {
  4979. return UUID.Zero.ToString();
  4980. }
  4981. }
  4982. public LSL_Vector llGetCenterOfMass()
  4983. {
  4984. m_host.AddScriptLPS(1);
  4985. return new LSL_Vector(m_host.GetCenterOfMass());
  4986. }
  4987. public LSL_List llListSort(LSL_List src, int stride, int ascending)
  4988. {
  4989. m_host.AddScriptLPS(1);
  4990. if (stride <= 0)
  4991. {
  4992. stride = 1;
  4993. }
  4994. return src.Sort(stride, ascending);
  4995. }
  4996. public LSL_Integer llGetListLength(LSL_List src)
  4997. {
  4998. m_host.AddScriptLPS(1);
  4999. return src.Length;
  5000. }
  5001. public LSL_Integer llList2Integer(LSL_List src, int index)
  5002. {
  5003. m_host.AddScriptLPS(1);
  5004. if (index < 0)
  5005. index = src.Length + index;
  5006. if (index >= src.Length || index < 0)
  5007. return 0;
  5008. object item = src.Data[index];
  5009. // Vectors & Rotations always return zero in SL, but
  5010. // keys don't always return zero, it seems to be a bit complex.
  5011. if (item is LSL_Vector || item is LSL_Rotation)
  5012. return 0;
  5013. try
  5014. {
  5015. if (item is LSL_Integer)
  5016. return (LSL_Integer)item;
  5017. else if (item is LSL_Float)
  5018. return Convert.ToInt32(((LSL_Float)item).value);;
  5019. return new LSL_Integer(item.ToString());
  5020. }
  5021. catch (FormatException)
  5022. {
  5023. return 0;
  5024. }
  5025. }
  5026. public LSL_Float llList2Float(LSL_List src, int index)
  5027. {
  5028. m_host.AddScriptLPS(1);
  5029. if (index < 0)
  5030. index = src.Length + index;
  5031. if (index >= src.Length || index < 0)
  5032. return 0;
  5033. object item = src.Data[index];
  5034. // Vectors & Rotations always return zero in SL
  5035. if(item is LSL_Vector || item is LSL_Rotation)
  5036. return 0;
  5037. // valid keys seem to get parsed as integers then converted to floats
  5038. if (item is LSL_Key)
  5039. {
  5040. UUID uuidt;
  5041. string s = item.ToString();
  5042. if(UUID.TryParse(s, out uuidt))
  5043. return Convert.ToDouble(new LSL_Integer(s).value);
  5044. // we can't do this because a string is also a LSL_Key for now :(
  5045. // else
  5046. // return 0;
  5047. }
  5048. try
  5049. {
  5050. if (item is LSL_Integer)
  5051. return Convert.ToDouble(((LSL_Integer)item).value);
  5052. else if (item is LSL_Float)
  5053. return Convert.ToDouble(((LSL_Float)item).value);
  5054. else if (item is LSL_String)
  5055. {
  5056. string str = ((LSL_String)item).m_string;
  5057. Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
  5058. if (m != Match.Empty)
  5059. {
  5060. str = m.Value;
  5061. double d = 0.0;
  5062. if (!Double.TryParse(str, out d))
  5063. return 0.0;
  5064. return d;
  5065. }
  5066. return 0.0;
  5067. }
  5068. return Convert.ToDouble(item);
  5069. }
  5070. catch (FormatException)
  5071. {
  5072. return 0.0;
  5073. }
  5074. }
  5075. public LSL_String llList2String(LSL_List src, int index)
  5076. {
  5077. m_host.AddScriptLPS(1);
  5078. if (index < 0)
  5079. index = src.Length + index;
  5080. if (index >= src.Length || index < 0)
  5081. return String.Empty;
  5082. return src.Data[index].ToString();
  5083. }
  5084. public LSL_Key llList2Key(LSL_List src, int index)
  5085. {
  5086. m_host.AddScriptLPS(1);
  5087. if (index < 0)
  5088. index = src.Length + index;
  5089. if (index >= src.Length || index < 0)
  5090. return String.Empty;
  5091. object item = src.Data[index];
  5092. // SL spits out an empty string for types other than key & string
  5093. // At the time of patching, LSL_Key is currently LSL_String,
  5094. // so the OR check may be a little redundant, but it's being done
  5095. // for completion and should LSL_Key ever be implemented
  5096. // as it's own struct
  5097. // NOTE: 3rd case is needed because a NULL_KEY comes through as
  5098. // type 'obj' and wrongly returns ""
  5099. if (!(item is LSL_String ||
  5100. item is LSL_Key ||
  5101. item.ToString() == "00000000-0000-0000-0000-000000000000"))
  5102. {
  5103. return String.Empty;
  5104. }
  5105. return item.ToString();
  5106. }
  5107. public LSL_Vector llList2Vector(LSL_List src, int index)
  5108. {
  5109. m_host.AddScriptLPS(1);
  5110. if (index < 0)
  5111. index = src.Length + index;
  5112. if (index >= src.Length || index < 0)
  5113. return new LSL_Vector(0, 0, 0);
  5114. object item = src.Data[index];
  5115. if (item.GetType() == typeof(LSL_Vector))
  5116. return (LSL_Vector)item;
  5117. // SL spits always out ZERO_VECTOR for anything other than
  5118. // strings or vectors. Although keys always return ZERO_VECTOR,
  5119. // it is currently difficult to make the distinction between
  5120. // a string, a key as string and a string that by coincidence
  5121. // is a string, so we're going to leave that up to the
  5122. // LSL_Vector constructor.
  5123. if(item is LSL_Vector)
  5124. return (LSL_Vector) item;
  5125. if (item is LSL_String)
  5126. return new LSL_Vector(item.ToString());
  5127. return new LSL_Vector(0, 0, 0);
  5128. }
  5129. public LSL_Rotation llList2Rot(LSL_List src, int index)
  5130. {
  5131. m_host.AddScriptLPS(1);
  5132. if (index < 0)
  5133. index = src.Length + index;
  5134. if (index >= src.Length || index < 0)
  5135. return new LSL_Rotation(0, 0, 0, 1);
  5136. object item = src.Data[index];
  5137. // SL spits always out ZERO_ROTATION for anything other than
  5138. // strings or vectors. Although keys always return ZERO_ROTATION,
  5139. // it is currently difficult to make the distinction between
  5140. // a string, a key as string and a string that by coincidence
  5141. // is a string, so we're going to leave that up to the
  5142. // LSL_Rotation constructor.
  5143. if (item.GetType() == typeof(LSL_Rotation))
  5144. return (LSL_Rotation)item;
  5145. if (item is LSL_String)
  5146. return new LSL_Rotation(src.Data[index].ToString());
  5147. return new LSL_Rotation(0, 0, 0, 1);
  5148. }
  5149. public LSL_List llList2List(LSL_List src, int start, int end)
  5150. {
  5151. m_host.AddScriptLPS(1);
  5152. return src.GetSublist(start, end);
  5153. }
  5154. public LSL_List llDeleteSubList(LSL_List src, int start, int end)
  5155. {
  5156. return src.DeleteSublist(start, end);
  5157. }
  5158. public LSL_Integer llGetListEntryType(LSL_List src, int index)
  5159. {
  5160. m_host.AddScriptLPS(1);
  5161. if (index < 0)
  5162. {
  5163. index = src.Length + index;
  5164. }
  5165. if (index >= src.Length)
  5166. {
  5167. return 0;
  5168. }
  5169. if (src.Data[index] is LSL_Integer || src.Data[index] is Int32)
  5170. return 1;
  5171. if (src.Data[index] is LSL_Float || src.Data[index] is Single || src.Data[index] is Double)
  5172. return 2;
  5173. if (src.Data[index] is LSL_String || src.Data[index] is String)
  5174. {
  5175. UUID tuuid;
  5176. if (UUID.TryParse(src.Data[index].ToString(), out tuuid))
  5177. {
  5178. return 4;
  5179. }
  5180. else
  5181. {
  5182. return 3;
  5183. }
  5184. }
  5185. if (src.Data[index] is LSL_Vector)
  5186. return 5;
  5187. if (src.Data[index] is LSL_Rotation)
  5188. return 6;
  5189. if (src.Data[index] is LSL_List)
  5190. return 7;
  5191. return 0;
  5192. }
  5193. /// <summary>
  5194. /// Process the supplied list and return the
  5195. /// content of the list formatted as a comma
  5196. /// separated list. There is a space after
  5197. /// each comma.
  5198. /// </summary>
  5199. public LSL_String llList2CSV(LSL_List src)
  5200. {
  5201. m_host.AddScriptLPS(1);
  5202. return string.Join(", ",
  5203. (new List<object>(src.Data)).ConvertAll<string>(o =>
  5204. {
  5205. return o.ToString();
  5206. }).ToArray());
  5207. }
  5208. /// <summary>
  5209. /// The supplied string is scanned for commas
  5210. /// and converted into a list. Commas are only
  5211. /// effective if they are encountered outside
  5212. /// of '<' '>' delimiters. Any whitespace
  5213. /// before or after an element is trimmed.
  5214. /// </summary>
  5215. public LSL_List llCSV2List(string src)
  5216. {
  5217. LSL_List result = new LSL_List();
  5218. int parens = 0;
  5219. int start = 0;
  5220. int length = 0;
  5221. m_host.AddScriptLPS(1);
  5222. for (int i = 0; i < src.Length; i++)
  5223. {
  5224. switch (src[i])
  5225. {
  5226. case '<':
  5227. parens++;
  5228. length++;
  5229. break;
  5230. case '>':
  5231. if (parens > 0)
  5232. parens--;
  5233. length++;
  5234. break;
  5235. case ',':
  5236. if (parens == 0)
  5237. {
  5238. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5239. start += length+1;
  5240. length = 0;
  5241. }
  5242. else
  5243. {
  5244. length++;
  5245. }
  5246. break;
  5247. default:
  5248. length++;
  5249. break;
  5250. }
  5251. }
  5252. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5253. return result;
  5254. }
  5255. /// <summary>
  5256. /// Randomizes the list, be arbitrarily reordering
  5257. /// sublists of stride elements. As the stride approaches
  5258. /// the size of the list, the options become very
  5259. /// limited.
  5260. /// </summary>
  5261. /// <remarks>
  5262. /// This could take a while for very large list
  5263. /// sizes.
  5264. /// </remarks>
  5265. public LSL_List llListRandomize(LSL_List src, int stride)
  5266. {
  5267. LSL_List result;
  5268. BetterRandom rand = new BetterRandom();
  5269. int chunkk;
  5270. int[] chunks;
  5271. m_host.AddScriptLPS(1);
  5272. if (stride <= 0)
  5273. {
  5274. stride = 1;
  5275. }
  5276. // Stride MUST be a factor of the list length
  5277. // If not, then return the src list. This also
  5278. // traps those cases where stride > length.
  5279. if (src.Length != stride && src.Length % stride == 0)
  5280. {
  5281. chunkk = src.Length/stride;
  5282. chunks = new int[chunkk];
  5283. for (int i = 0; i < chunkk; i++)
  5284. {
  5285. chunks[i] = i;
  5286. }
  5287. // Knuth shuffle the chunkk index
  5288. for (int i = chunkk - 1; i > 0; i--)
  5289. {
  5290. // Elect an unrandomized chunk to swap
  5291. int index = rand.Next(i + 1);
  5292. // and swap position with first unrandomized chunk
  5293. int tmp = chunks[i];
  5294. chunks[i] = chunks[index];
  5295. chunks[index] = tmp;
  5296. }
  5297. // Construct the randomized list
  5298. result = new LSL_List();
  5299. for (int i = 0; i < chunkk; i++)
  5300. {
  5301. for (int j = 0; j < stride; j++)
  5302. {
  5303. result.Add(src.Data[chunks[i] * stride + j]);
  5304. }
  5305. }
  5306. }
  5307. else
  5308. {
  5309. object[] array = new object[src.Length];
  5310. Array.Copy(src.Data, 0, array, 0, src.Length);
  5311. result = new LSL_List(array);
  5312. }
  5313. return result;
  5314. }
  5315. /// <summary>
  5316. /// Elements in the source list starting with 0 and then
  5317. /// every i+stride. If the stride is negative then the scan
  5318. /// is backwards producing an inverted result.
  5319. /// Only those elements that are also in the specified
  5320. /// range are included in the result.
  5321. /// </summary>
  5322. public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
  5323. {
  5324. LSL_List result = new LSL_List();
  5325. int[] si = new int[2];
  5326. int[] ei = new int[2];
  5327. bool twopass = false;
  5328. m_host.AddScriptLPS(1);
  5329. // First step is always to deal with negative indices
  5330. if (start < 0)
  5331. start = src.Length+start;
  5332. if (end < 0)
  5333. end = src.Length+end;
  5334. // Out of bounds indices are OK, just trim them
  5335. // accordingly
  5336. if (start > src.Length)
  5337. start = src.Length;
  5338. if (end > src.Length)
  5339. end = src.Length;
  5340. if (stride == 0)
  5341. stride = 1;
  5342. // There may be one or two ranges to be considered
  5343. if (start != end)
  5344. {
  5345. if (start <= end)
  5346. {
  5347. si[0] = start;
  5348. ei[0] = end;
  5349. }
  5350. else
  5351. {
  5352. si[1] = start;
  5353. ei[1] = src.Length;
  5354. si[0] = 0;
  5355. ei[0] = end;
  5356. twopass = true;
  5357. }
  5358. // The scan always starts from the beginning of the
  5359. // source list, but members are only selected if they
  5360. // fall within the specified sub-range. The specified
  5361. // range values are inclusive.
  5362. // A negative stride reverses the direction of the
  5363. // scan producing an inverted list as a result.
  5364. if (stride > 0)
  5365. {
  5366. for (int i = 0; i < src.Length; i += stride)
  5367. {
  5368. if (i<=ei[0] && i>=si[0])
  5369. result.Add(src.Data[i]);
  5370. if (twopass && i>=si[1] && i<=ei[1])
  5371. result.Add(src.Data[i]);
  5372. }
  5373. }
  5374. else if (stride < 0)
  5375. {
  5376. for (int i = src.Length - 1; i >= 0; i += stride)
  5377. {
  5378. if (i <= ei[0] && i >= si[0])
  5379. result.Add(src.Data[i]);
  5380. if (twopass && i >= si[1] && i <= ei[1])
  5381. result.Add(src.Data[i]);
  5382. }
  5383. }
  5384. }
  5385. else
  5386. {
  5387. if (start%stride == 0)
  5388. {
  5389. result.Add(src.Data[start]);
  5390. }
  5391. }
  5392. return result;
  5393. }
  5394. public LSL_Integer llGetRegionAgentCount()
  5395. {
  5396. m_host.AddScriptLPS(1);
  5397. int count = 0;
  5398. World.ForEachRootScenePresence(delegate(ScenePresence sp) {
  5399. count++;
  5400. });
  5401. return new LSL_Integer(count);
  5402. }
  5403. public LSL_Vector llGetRegionCorner()
  5404. {
  5405. m_host.AddScriptLPS(1);
  5406. return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  5407. }
  5408. public LSL_String llGetEnv(LSL_String name)
  5409. {
  5410. m_host.AddScriptLPS(1);
  5411. switch(name)
  5412. {
  5413. case "agent_limit":
  5414. return World.RegionInfo.RegionSettings.AgentLimit.ToString();
  5415. case "dynamic_pathfinding":
  5416. return "0";
  5417. case "estate_id":
  5418. return World.RegionInfo.EstateSettings.EstateID.ToString();
  5419. case "estate_name":
  5420. return World.RegionInfo.EstateSettings.EstateName;
  5421. case "frame_number":
  5422. return World.Frame.ToString();
  5423. case "region_cpu_ratio":
  5424. return "1";
  5425. case "region_idle":
  5426. return "0";
  5427. case "region_product_name":
  5428. if (World.RegionInfo.RegionType != String.Empty)
  5429. return World.RegionInfo.RegionType;
  5430. else
  5431. return "";
  5432. case "region_product_sku":
  5433. return "OpenSim";
  5434. case "region_start_time":
  5435. return World.UnixStartTime.ToString();
  5436. case "region_up_time":
  5437. int time = Util.UnixTimeSinceEpoch() - World.UnixStartTime;
  5438. return time.ToString();
  5439. case "sim_channel":
  5440. return "OpenSim";
  5441. case "sim_version":
  5442. return World.GetSimulatorVersion();
  5443. case "simulator_hostname":
  5444. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  5445. return UrlModule.ExternalHostNameForLSL;
  5446. case "region_max_prims":
  5447. return World.RegionInfo.ObjectCapacity.ToString();
  5448. case "region_object_bonus":
  5449. return World.RegionInfo.RegionSettings.ObjectBonus.ToString();
  5450. default:
  5451. return "";
  5452. }
  5453. }
  5454. /// <summary>
  5455. /// Insert the list identified by <paramref name="src"/> into the
  5456. /// list designated by <paramref name="dest"/> such that the first
  5457. /// new element has the index specified by <paramref name="index"/>
  5458. /// </summary>
  5459. public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
  5460. {
  5461. LSL_List pref;
  5462. LSL_List suff;
  5463. m_host.AddScriptLPS(1);
  5464. if (index < 0)
  5465. {
  5466. index = index+dest.Length;
  5467. if (index < 0)
  5468. {
  5469. index = 0;
  5470. }
  5471. }
  5472. if (index != 0)
  5473. {
  5474. pref = dest.GetSublist(0,index-1);
  5475. if (index < dest.Length)
  5476. {
  5477. suff = dest.GetSublist(index,-1);
  5478. return pref + src + suff;
  5479. }
  5480. else
  5481. {
  5482. return pref + src;
  5483. }
  5484. }
  5485. else
  5486. {
  5487. if (index < dest.Length)
  5488. {
  5489. suff = dest.GetSublist(index,-1);
  5490. return src + suff;
  5491. }
  5492. else
  5493. {
  5494. return src;
  5495. }
  5496. }
  5497. }
  5498. /// <summary>
  5499. /// Returns the index of the first occurrence of test
  5500. /// in src.
  5501. /// </summary>
  5502. /// <param name="src">Source list</param>
  5503. /// <param name="test">List to search for</param>
  5504. /// <returns>
  5505. /// The index number of the point in src where test was found if it was found.
  5506. /// Otherwise returns -1
  5507. /// </returns>
  5508. public LSL_Integer llListFindList(LSL_List src, LSL_List test)
  5509. {
  5510. int index = -1;
  5511. int length = src.Length - test.Length + 1;
  5512. m_host.AddScriptLPS(1);
  5513. // If either list is empty, do not match
  5514. if (src.Length != 0 && test.Length != 0)
  5515. {
  5516. for (int i = 0; i < length; i++)
  5517. {
  5518. int needle = llGetListEntryType(test, 0).value;
  5519. int haystack = llGetListEntryType(src, i).value;
  5520. // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
  5521. // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
  5522. // and so the comparison fails even if the LSL_Integer conceptually has the same value.
  5523. // Therefore, here we test Equals on both the source and destination objects.
  5524. // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
  5525. if ((needle == haystack) && (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i])))
  5526. {
  5527. int j;
  5528. for (j = 1; j < test.Length; j++)
  5529. {
  5530. needle = llGetListEntryType(test, j).value;
  5531. haystack = llGetListEntryType(src, i+j).value;
  5532. if ((needle != haystack) || (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j]))))
  5533. break;
  5534. }
  5535. if (j == test.Length)
  5536. {
  5537. index = i;
  5538. break;
  5539. }
  5540. }
  5541. }
  5542. }
  5543. return index;
  5544. }
  5545. public LSL_String llGetObjectName()
  5546. {
  5547. m_host.AddScriptLPS(1);
  5548. return m_host.Name !=null ? m_host.Name : String.Empty;
  5549. }
  5550. public void llSetObjectName(string name)
  5551. {
  5552. m_host.AddScriptLPS(1);
  5553. m_host.Name = name != null ? name : String.Empty;
  5554. }
  5555. public LSL_String llGetDate()
  5556. {
  5557. m_host.AddScriptLPS(1);
  5558. DateTime date = DateTime.Now.ToUniversalTime();
  5559. string result = date.ToString("yyyy-MM-dd");
  5560. return result;
  5561. }
  5562. public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
  5563. {
  5564. m_host.AddScriptLPS(1);
  5565. if(dir.x == 0 && dir.y == 0)
  5566. return 1; // SL wiki
  5567. float rsx = World.RegionInfo.RegionSizeX;
  5568. float rsy = World.RegionInfo.RegionSizeY;
  5569. // can understand what sl does if position is not in region, so do something :)
  5570. float px = (float)Util.Clamp(pos.x, 0.5, rsx - 0.5);
  5571. float py = (float)Util.Clamp(pos.y, 0.5, rsy - 0.5);
  5572. float ex, ey;
  5573. if (dir.x == 0)
  5574. {
  5575. ex = px;
  5576. ey = dir.y > 0 ? rsy + 1.0f : -1.0f;
  5577. }
  5578. else if(dir.y == 0)
  5579. {
  5580. ex = dir.x > 0 ? rsx + 1.0f : -1.0f;
  5581. ey = py;
  5582. }
  5583. else
  5584. {
  5585. float dx = (float) dir.x;
  5586. float dy = (float) dir.y;
  5587. float t1 = dx * dx + dy * dy;
  5588. t1 = (float)Math.Sqrt(t1);
  5589. dx /= t1;
  5590. dy /= t1;
  5591. if(dx > 0)
  5592. t1 = (rsx + 1f - px)/dx;
  5593. else
  5594. t1 = -(px + 1f)/dx;
  5595. float t2;
  5596. if(dy > 0)
  5597. t2 = (rsy + 1f - py)/dy;
  5598. else
  5599. t2 = -(py + 1f)/dy;
  5600. if(t1 > t2)
  5601. t1 = t2;
  5602. ex = px + t1 * dx;
  5603. ey = py + t1 * dy;
  5604. }
  5605. ex += World.RegionInfo.WorldLocX;
  5606. ey += World.RegionInfo.WorldLocY;
  5607. if(World.GridService.GetRegionByPosition(World.RegionInfo.ScopeID, (int)ex, (int)ey) != null)
  5608. return 0;
  5609. return 1;
  5610. }
  5611. /// <summary>
  5612. /// Not fully implemented yet. Still to do:-
  5613. /// AGENT_BUSY
  5614. /// Remove as they are done
  5615. /// </summary>
  5616. public LSL_Integer llGetAgentInfo(LSL_Key id)
  5617. {
  5618. m_host.AddScriptLPS(1);
  5619. UUID key = new UUID();
  5620. if (!UUID.TryParse(id, out key))
  5621. {
  5622. return 0;
  5623. }
  5624. int flags = 0;
  5625. ScenePresence agent = World.GetScenePresence(key);
  5626. if (agent == null)
  5627. {
  5628. return 0;
  5629. }
  5630. if (agent.IsChildAgent)
  5631. return 0; // Fail if they are not in the same region
  5632. // note: in OpenSim, sitting seems to cancel AGENT_ALWAYS_RUN, unlike SL
  5633. if (agent.SetAlwaysRun)
  5634. {
  5635. flags |= ScriptBaseClass.AGENT_ALWAYS_RUN;
  5636. }
  5637. if (agent.HasAttachments())
  5638. {
  5639. flags |= ScriptBaseClass.AGENT_ATTACHMENTS;
  5640. if (agent.HasScriptedAttachments())
  5641. flags |= ScriptBaseClass.AGENT_SCRIPTED;
  5642. }
  5643. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
  5644. {
  5645. flags |= ScriptBaseClass.AGENT_FLYING;
  5646. flags |= ScriptBaseClass.AGENT_IN_AIR; // flying always implies in-air, even if colliding with e.g. a wall
  5647. }
  5648. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AWAY) != 0)
  5649. {
  5650. flags |= ScriptBaseClass.AGENT_AWAY;
  5651. }
  5652. UUID busy = new UUID("efcf670c-2d18-8128-973a-034ebc806b67");
  5653. UUID[] anims = agent.Animator.GetAnimationArray();
  5654. if (Array.Exists<UUID>(anims, a => { return a == busy; }))
  5655. {
  5656. flags |= ScriptBaseClass.AGENT_BUSY;
  5657. }
  5658. // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
  5659. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  5660. {
  5661. flags |= ScriptBaseClass.AGENT_MOUSELOOK;
  5662. }
  5663. if ((agent.State & (byte)AgentState.Typing) != (byte)0)
  5664. {
  5665. flags |= ScriptBaseClass.AGENT_TYPING;
  5666. }
  5667. string agentMovementAnimation = agent.Animator.CurrentMovementAnimation;
  5668. if (agentMovementAnimation == "CROUCH")
  5669. {
  5670. flags |= ScriptBaseClass.AGENT_CROUCHING;
  5671. }
  5672. if (agentMovementAnimation == "WALK" || agentMovementAnimation == "CROUCHWALK")
  5673. {
  5674. flags |= ScriptBaseClass.AGENT_WALKING;
  5675. }
  5676. // not colliding implies in air. Note: flying also implies in-air, even if colliding (see above)
  5677. // note: AGENT_IN_AIR and AGENT_WALKING seem to be mutually exclusive states in SL.
  5678. // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
  5679. // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
  5680. // there be some minimum non-collision threshold time before claiming the avatar is in-air?
  5681. if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding )
  5682. {
  5683. flags |= ScriptBaseClass.AGENT_IN_AIR;
  5684. }
  5685. if (agent.ParentPart != null)
  5686. {
  5687. flags |= ScriptBaseClass.AGENT_ON_OBJECT;
  5688. flags |= ScriptBaseClass.AGENT_SITTING;
  5689. }
  5690. if (agent.Animator.Animations.ImplicitDefaultAnimation.AnimID
  5691. == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  5692. {
  5693. flags |= ScriptBaseClass.AGENT_SITTING;
  5694. }
  5695. if (agent.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] > 0)
  5696. {
  5697. flags |= ScriptBaseClass.AGENT_MALE;
  5698. }
  5699. return flags;
  5700. }
  5701. public LSL_String llGetAgentLanguage(LSL_Key id)
  5702. {
  5703. // This should only return a value if the avatar is in the same region, but eh. idc.
  5704. m_host.AddScriptLPS(1);
  5705. if (World.AgentPreferencesService == null)
  5706. {
  5707. Error("llGetAgentLanguage", "No AgentPreferencesService present");
  5708. }
  5709. else
  5710. {
  5711. UUID key = new UUID();
  5712. if (UUID.TryParse(id, out key))
  5713. {
  5714. return new LSL_String(World.AgentPreferencesService.GetLang(key));
  5715. }
  5716. }
  5717. return new LSL_String("en-us");
  5718. }
  5719. /// <summary>
  5720. /// http://wiki.secondlife.com/wiki/LlGetAgentList
  5721. /// The list of options is currently not used in SL
  5722. /// scope is one of:-
  5723. /// AGENT_LIST_REGION - all in the region
  5724. /// AGENT_LIST_PARCEL - all in the same parcel as the scripted object
  5725. /// AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the
  5726. /// current parcel.
  5727. /// AGENT_LIST_EXCLUDENPC ignore NPCs (bit mask)
  5728. /// </summary>
  5729. public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options)
  5730. {
  5731. m_host.AddScriptLPS(1);
  5732. // do our bit masks part
  5733. bool noNPC = (scope & ScriptBaseClass.AGENT_LIST_EXCLUDENPC) !=0;
  5734. // remove bit masks part
  5735. scope &= ~ ScriptBaseClass.AGENT_LIST_EXCLUDENPC;
  5736. // the constants are 1, 2 and 4 so bits are being set, but you
  5737. // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4
  5738. bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION;
  5739. bool parcelOwned = scope == ScriptBaseClass.AGENT_LIST_PARCEL_OWNER;
  5740. bool parcel = scope == ScriptBaseClass.AGENT_LIST_PARCEL;
  5741. LSL_List result = new LSL_List();
  5742. if (!regionWide && !parcelOwned && !parcel)
  5743. {
  5744. result.Add("INVALID_SCOPE");
  5745. return result;
  5746. }
  5747. ILandObject land;
  5748. UUID id = UUID.Zero;
  5749. if (parcel || parcelOwned)
  5750. {
  5751. land = World.LandChannel.GetLandObject(m_host.ParentGroup.RootPart.GetWorldPosition());
  5752. if (land == null)
  5753. {
  5754. id = UUID.Zero;
  5755. }
  5756. else
  5757. {
  5758. if (parcelOwned)
  5759. {
  5760. id = land.LandData.OwnerID;
  5761. }
  5762. else
  5763. {
  5764. id = land.LandData.GlobalID;
  5765. }
  5766. }
  5767. }
  5768. World.ForEachRootScenePresence(
  5769. delegate (ScenePresence ssp)
  5770. {
  5771. if(noNPC && ssp.IsNPC)
  5772. return;
  5773. // Gods are not listed in SL
  5774. if (!ssp.IsDeleted && !ssp.IsViewerUIGod && !ssp.IsChildAgent)
  5775. {
  5776. if (!regionWide)
  5777. {
  5778. land = World.LandChannel.GetLandObject(ssp.AbsolutePosition);
  5779. if (land != null)
  5780. {
  5781. if (parcelOwned && land.LandData.OwnerID == id ||
  5782. parcel && land.LandData.GlobalID == id)
  5783. {
  5784. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5785. }
  5786. }
  5787. }
  5788. else
  5789. {
  5790. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5791. }
  5792. }
  5793. // Maximum of 100 results
  5794. if (result.Length > 99)
  5795. {
  5796. return;
  5797. }
  5798. }
  5799. );
  5800. return result;
  5801. }
  5802. public void llAdjustSoundVolume(LSL_Float volume)
  5803. {
  5804. m_host.AddScriptLPS(1);
  5805. m_host.AdjustSoundGain(volume);
  5806. ScriptSleep(m_sleepMsOnAdjustSoundVolume);
  5807. }
  5808. public void llSetSoundRadius(double radius)
  5809. {
  5810. m_host.AddScriptLPS(1);
  5811. m_host.SoundRadius = radius;
  5812. }
  5813. public LSL_String llKey2Name(LSL_Key id)
  5814. {
  5815. m_host.AddScriptLPS(1);
  5816. UUID key = new UUID();
  5817. if (UUID.TryParse(id,out key))
  5818. {
  5819. ScenePresence presence = World.GetScenePresence(key);
  5820. if (presence != null)
  5821. {
  5822. return presence.ControllingClient.Name;
  5823. //return presence.Name;
  5824. }
  5825. if (World.GetSceneObjectPart(key) != null)
  5826. {
  5827. return World.GetSceneObjectPart(key).Name;
  5828. }
  5829. }
  5830. return String.Empty;
  5831. }
  5832. public LSL_Key llName2Key(LSL_String name)
  5833. {
  5834. m_host.AddScriptLPS(1);
  5835. foreach (ScenePresence sp in World.GetScenePresences())
  5836. {
  5837. if (sp.IsDeleted || sp.IsChildAgent)
  5838. continue;
  5839. string test = sp.ControllingClient.Name;
  5840. if (!name.Contains(" "))
  5841. test = test.Replace(" ", ".");
  5842. if (String.Compare(name, test, true) == 0)
  5843. return sp.UUID.ToString();
  5844. }
  5845. return UUID.Zero.ToString();
  5846. }
  5847. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5848. {
  5849. m_host.AddScriptLPS(1);
  5850. SetTextureAnim(m_host, mode, face, sizex, sizey, start, length, rate);
  5851. }
  5852. public void llSetLinkTextureAnim(int linknumber, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5853. {
  5854. m_host.AddScriptLPS(1);
  5855. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5856. try
  5857. {
  5858. foreach (SceneObjectPart part in parts)
  5859. {
  5860. SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
  5861. }
  5862. }
  5863. finally
  5864. {
  5865. }
  5866. }
  5867. private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5868. {
  5869. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation();
  5870. pTexAnim.Flags = (Primitive.TextureAnimMode)mode;
  5871. //ALL_SIDES
  5872. if (face == ScriptBaseClass.ALL_SIDES)
  5873. face = 255;
  5874. pTexAnim.Face = (uint)face;
  5875. pTexAnim.Length = (float)length;
  5876. pTexAnim.Rate = (float)rate;
  5877. pTexAnim.SizeX = (uint)sizex;
  5878. pTexAnim.SizeY = (uint)sizey;
  5879. pTexAnim.Start = (float)start;
  5880. part.AddTextureAnimation(pTexAnim);
  5881. part.SendFullUpdateToAllClients();
  5882. part.ParentGroup.HasGroupChanged = true;
  5883. }
  5884. public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
  5885. LSL_Vector bottom_south_west)
  5886. {
  5887. m_host.AddScriptLPS(1);
  5888. if (m_SoundModule != null)
  5889. {
  5890. m_SoundModule.TriggerSoundLimited(m_host.UUID,
  5891. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume,
  5892. bottom_south_west, top_north_east);
  5893. }
  5894. }
  5895. public void llEjectFromLand(LSL_Key pest)
  5896. {
  5897. m_host.AddScriptLPS(1);
  5898. UUID agentID = new UUID();
  5899. if (UUID.TryParse(pest, out agentID))
  5900. {
  5901. ScenePresence presence = World.GetScenePresence(agentID);
  5902. if (presence != null)
  5903. {
  5904. // agent must be over the owners land
  5905. ILandObject land = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  5906. if (land == null)
  5907. return;
  5908. if (m_host.OwnerID == land.LandData.OwnerID)
  5909. {
  5910. Vector3 p = World.GetNearestAllowedPosition(presence, land);
  5911. presence.TeleportOnEject(p);
  5912. presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
  5913. }
  5914. }
  5915. }
  5916. ScriptSleep(m_sleepMsOnEjectFromLand);
  5917. }
  5918. public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
  5919. {
  5920. return ParseString2List(str, separators, in_spacers, false);
  5921. }
  5922. public LSL_Integer llOverMyLand(string id)
  5923. {
  5924. m_host.AddScriptLPS(1);
  5925. UUID key = new UUID();
  5926. if (UUID.TryParse(id, out key))
  5927. {
  5928. try
  5929. {
  5930. ScenePresence presence = World.GetScenePresence(key);
  5931. if (presence != null) // object is an avatar
  5932. {
  5933. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  5934. return 1;
  5935. }
  5936. else // object is not an avatar
  5937. {
  5938. SceneObjectPart obj = World.GetSceneObjectPart(key);
  5939. if (obj != null &&
  5940. m_host.OwnerID == World.LandChannel.GetLandObject(obj.AbsolutePosition).LandData.OwnerID)
  5941. return 1;
  5942. }
  5943. }
  5944. catch { }
  5945. }
  5946. return 0;
  5947. }
  5948. public LSL_Key llGetLandOwnerAt(LSL_Vector pos)
  5949. {
  5950. m_host.AddScriptLPS(1);
  5951. ILandObject land = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  5952. if (land == null)
  5953. return UUID.Zero.ToString();
  5954. return land.LandData.OwnerID.ToString();
  5955. }
  5956. /// <summary>
  5957. /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
  5958. /// only the height of avatars vary and that says:
  5959. /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
  5960. /// </summary>
  5961. public LSL_Vector llGetAgentSize(LSL_Key id)
  5962. {
  5963. m_host.AddScriptLPS(1);
  5964. UUID avID;
  5965. if(!UUID.TryParse(id, out avID))
  5966. return ScriptBaseClass.ZERO_VECTOR;
  5967. ScenePresence avatar = World.GetScenePresence(avID);
  5968. if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
  5969. return ScriptBaseClass.ZERO_VECTOR;
  5970. // agentSize = new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight);
  5971. Vector3 s = avatar.Appearance.AvatarSize;
  5972. return new LSL_Vector(s.X, s.Y, s.Z);
  5973. }
  5974. public LSL_Integer llSameGroup(string id)
  5975. {
  5976. m_host.AddScriptLPS(1);
  5977. UUID uuid = new UUID();
  5978. if (!UUID.TryParse(id, out uuid))
  5979. return new LSL_Integer(0);
  5980. // Check if it's a group key
  5981. if (uuid == m_host.ParentGroup.RootPart.GroupID)
  5982. return new LSL_Integer(1);
  5983. // Handle object case
  5984. SceneObjectPart part = World.GetSceneObjectPart(uuid);
  5985. if (part != null)
  5986. {
  5987. if(part.ParentGroup.IsAttachment)
  5988. {
  5989. uuid = part.ParentGroup.AttachedAvatar;
  5990. }
  5991. else
  5992. {
  5993. // This will handle both deed and non-deed and also the no
  5994. // group case
  5995. if (part.ParentGroup.RootPart.GroupID == m_host.ParentGroup.RootPart.GroupID)
  5996. return new LSL_Integer(1);
  5997. return new LSL_Integer(0);
  5998. }
  5999. }
  6000. // Handle the case where id names an avatar
  6001. ScenePresence presence = World.GetScenePresence(uuid);
  6002. if (presence != null)
  6003. {
  6004. if (presence.IsChildAgent)
  6005. return new LSL_Integer(0);
  6006. IClientAPI client = presence.ControllingClient;
  6007. if (m_host.ParentGroup.RootPart.GroupID == client.ActiveGroupId)
  6008. return new LSL_Integer(1);
  6009. return new LSL_Integer(0);
  6010. }
  6011. return new LSL_Integer(0);
  6012. }
  6013. public void llUnSit(string id)
  6014. {
  6015. m_host.AddScriptLPS(1);
  6016. UUID key = new UUID();
  6017. if (UUID.TryParse(id, out key))
  6018. {
  6019. ScenePresence av = World.GetScenePresence(key);
  6020. List<ScenePresence> sittingAvatars = m_host.ParentGroup.GetSittingAvatars();
  6021. if (av != null)
  6022. {
  6023. if (sittingAvatars.Contains(av))
  6024. {
  6025. // if the avatar is sitting on this object, then
  6026. // we can unsit them. We don't want random scripts unsitting random people
  6027. // Lets avoid the popcorn avatar scenario.
  6028. av.StandUp();
  6029. }
  6030. else
  6031. {
  6032. // If the object owner also owns the parcel
  6033. // or
  6034. // if the land is group owned and the object is group owned by the same group
  6035. // or
  6036. // if the object is owned by a person with estate access.
  6037. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition);
  6038. if (parcel != null)
  6039. {
  6040. if (m_host.OwnerID == parcel.LandData.OwnerID ||
  6041. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.LandData.GroupID
  6042. && parcel.LandData.IsGroupOwned) || World.Permissions.IsGod(m_host.OwnerID))
  6043. {
  6044. av.StandUp();
  6045. }
  6046. }
  6047. }
  6048. }
  6049. }
  6050. }
  6051. public LSL_Vector llGroundSlope(LSL_Vector offset)
  6052. {
  6053. m_host.AddScriptLPS(1);
  6054. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  6055. LSL_Vector vsn = llGroundNormal(offset);
  6056. //Plug the x,y coordinates of the slope normal into the equation of the plane to get
  6057. //the height of that point on the plane. The resulting vector gives the slope.
  6058. Vector3 vsl = vsn;
  6059. vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
  6060. vsl.Normalize();
  6061. //Normalization might be overkill here
  6062. vsn.x = vsl.X;
  6063. vsn.y = vsl.Y;
  6064. vsn.z = vsl.Z;
  6065. return vsn;
  6066. }
  6067. public LSL_Vector llGroundNormal(LSL_Vector offset)
  6068. {
  6069. m_host.AddScriptLPS(1);
  6070. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  6071. // Clamp to valid position
  6072. if (pos.X < 0)
  6073. pos.X = 0;
  6074. else if (pos.X >= World.Heightmap.Width)
  6075. pos.X = World.Heightmap.Width - 1;
  6076. if (pos.Y < 0)
  6077. pos.Y = 0;
  6078. else if (pos.Y >= World.Heightmap.Height)
  6079. pos.Y = World.Heightmap.Height - 1;
  6080. //Find two points in addition to the position to define a plane
  6081. Vector3 p0 = new Vector3(pos.X, pos.Y,
  6082. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6083. Vector3 p1 = new Vector3();
  6084. Vector3 p2 = new Vector3();
  6085. if ((pos.X + 1.0f) >= World.Heightmap.Width)
  6086. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6087. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6088. else
  6089. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6090. (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
  6091. if ((pos.Y + 1.0f) >= World.Heightmap.Height)
  6092. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6093. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6094. else
  6095. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6096. (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);
  6097. //Find normalized vectors from p0 to p1 and p0 to p2
  6098. Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
  6099. Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
  6100. v0.Normalize();
  6101. v1.Normalize();
  6102. //Find the cross product of the vectors (the slope normal).
  6103. Vector3 vsn = new Vector3();
  6104. vsn.X = (v0.Y * v1.Z) - (v0.Z * v1.Y);
  6105. vsn.Y = (v0.Z * v1.X) - (v0.X * v1.Z);
  6106. vsn.Z = (v0.X * v1.Y) - (v0.Y * v1.X);
  6107. vsn.Normalize();
  6108. //I believe the crossproduct of two normalized vectors is a normalized vector so
  6109. //this normalization may be overkill
  6110. return new LSL_Vector(vsn);
  6111. }
  6112. public LSL_Vector llGroundContour(LSL_Vector offset)
  6113. {
  6114. m_host.AddScriptLPS(1);
  6115. LSL_Vector x = llGroundSlope(offset);
  6116. return new LSL_Vector(-x.y, x.x, 0.0);
  6117. }
  6118. public LSL_Integer llGetAttached()
  6119. {
  6120. m_host.AddScriptLPS(1);
  6121. return m_host.ParentGroup.AttachmentPoint;
  6122. }
  6123. public LSL_List llGetAttachedList(LSL_Key id)
  6124. {
  6125. m_host.AddScriptLPS(1);
  6126. UUID avID;
  6127. if(!UUID.TryParse(id, out avID))
  6128. return new LSL_List("NOT_FOUND");
  6129. ScenePresence av = World.GetScenePresence(avID);
  6130. if (av == null || av.IsDeleted)
  6131. return new LSL_List("NOT_FOUND");
  6132. if (av.IsChildAgent || av.IsInTransit)
  6133. return new LSL_List("NOT_ON_REGION");
  6134. LSL_List AttachmentsList = new LSL_List();
  6135. List<SceneObjectGroup> Attachments;
  6136. Attachments = av.GetAttachments();
  6137. foreach (SceneObjectGroup Attachment in Attachments)
  6138. {
  6139. if(Attachment.HasPrivateAttachmentPoint)
  6140. continue;
  6141. AttachmentsList.Add(new LSL_Key(Attachment.UUID.ToString()));
  6142. }
  6143. return AttachmentsList;
  6144. }
  6145. public virtual LSL_Integer llGetFreeMemory()
  6146. {
  6147. m_host.AddScriptLPS(1);
  6148. // Make scripts designed for Mono happy
  6149. return 65536;
  6150. }
  6151. public LSL_Integer llGetFreeURLs()
  6152. {
  6153. m_host.AddScriptLPS(1);
  6154. if (m_UrlModule != null)
  6155. return new LSL_Integer(m_UrlModule.GetFreeUrls());
  6156. return new LSL_Integer(0);
  6157. }
  6158. public LSL_String llGetRegionName()
  6159. {
  6160. m_host.AddScriptLPS(1);
  6161. return World.RegionInfo.RegionName;
  6162. }
  6163. public LSL_Float llGetRegionTimeDilation()
  6164. {
  6165. m_host.AddScriptLPS(1);
  6166. return (double)World.TimeDilation;
  6167. }
  6168. /// <summary>
  6169. /// Returns the value reported in the client Statistics window
  6170. /// </summary>
  6171. public LSL_Float llGetRegionFPS()
  6172. {
  6173. m_host.AddScriptLPS(1);
  6174. return World.StatsReporter.LastReportedSimFPS;
  6175. }
  6176. /* particle system rules should be coming into this routine as doubles, that is
  6177. rule[0] should be an integer from this list and rule[1] should be the arg
  6178. for the same integer. wiki.secondlife.com has most of this mapping, but some
  6179. came from http://www.caligari-designs.com/p4u2
  6180. We iterate through the list for 'Count' elements, incrementing by two for each
  6181. iteration and set the members of Primitive.ParticleSystem, one at a time.
  6182. */
  6183. public enum PrimitiveRule : int
  6184. {
  6185. PSYS_PART_FLAGS = 0,
  6186. PSYS_PART_START_COLOR = 1,
  6187. PSYS_PART_START_ALPHA = 2,
  6188. PSYS_PART_END_COLOR = 3,
  6189. PSYS_PART_END_ALPHA = 4,
  6190. PSYS_PART_START_SCALE = 5,
  6191. PSYS_PART_END_SCALE = 6,
  6192. PSYS_PART_MAX_AGE = 7,
  6193. PSYS_SRC_ACCEL = 8,
  6194. PSYS_SRC_PATTERN = 9,
  6195. PSYS_SRC_INNERANGLE = 10,
  6196. PSYS_SRC_OUTERANGLE = 11,
  6197. PSYS_SRC_TEXTURE = 12,
  6198. PSYS_SRC_BURST_RATE = 13,
  6199. PSYS_SRC_BURST_PART_COUNT = 15,
  6200. PSYS_SRC_BURST_RADIUS = 16,
  6201. PSYS_SRC_BURST_SPEED_MIN = 17,
  6202. PSYS_SRC_BURST_SPEED_MAX = 18,
  6203. PSYS_SRC_MAX_AGE = 19,
  6204. PSYS_SRC_TARGET_KEY = 20,
  6205. PSYS_SRC_OMEGA = 21,
  6206. PSYS_SRC_ANGLE_BEGIN = 22,
  6207. PSYS_SRC_ANGLE_END = 23,
  6208. PSYS_PART_BLEND_FUNC_SOURCE = 24,
  6209. PSYS_PART_BLEND_FUNC_DEST = 25,
  6210. PSYS_PART_START_GLOW = 26,
  6211. PSYS_PART_END_GLOW = 27
  6212. }
  6213. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  6214. {
  6215. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  6216. return returnval;
  6217. }
  6218. protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues()
  6219. {
  6220. Primitive.ParticleSystem ps = new Primitive.ParticleSystem();
  6221. // TODO find out about the other defaults and add them here
  6222. ps.PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  6223. ps.PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  6224. ps.PartStartScaleX = 1.0f;
  6225. ps.PartStartScaleY = 1.0f;
  6226. ps.PartEndScaleX = 1.0f;
  6227. ps.PartEndScaleY = 1.0f;
  6228. ps.BurstSpeedMin = 1.0f;
  6229. ps.BurstSpeedMax = 1.0f;
  6230. ps.BurstRate = 0.1f;
  6231. ps.PartMaxAge = 10.0f;
  6232. ps.BurstPartCount = 1;
  6233. ps.BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA;
  6234. ps.BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA;
  6235. ps.PartStartGlow = 0.0f;
  6236. ps.PartEndGlow = 0.0f;
  6237. return ps;
  6238. }
  6239. public void llLinkParticleSystem(int linknumber, LSL_List rules)
  6240. {
  6241. m_host.AddScriptLPS(1);
  6242. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  6243. foreach (SceneObjectPart part in parts)
  6244. {
  6245. SetParticleSystem(part, rules, "llLinkParticleSystem");
  6246. }
  6247. }
  6248. public void llParticleSystem(LSL_List rules)
  6249. {
  6250. m_host.AddScriptLPS(1);
  6251. SetParticleSystem(m_host, rules, "llParticleSystem");
  6252. }
  6253. private void SetParticleSystem(SceneObjectPart part, LSL_List rules, string originFunc)
  6254. {
  6255. if (rules.Length == 0)
  6256. {
  6257. part.RemoveParticleSystem();
  6258. part.ParentGroup.HasGroupChanged = true;
  6259. }
  6260. else
  6261. {
  6262. Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
  6263. LSL_Vector tempv = new LSL_Vector();
  6264. float tempf = 0;
  6265. int tmpi = 0;
  6266. for (int i = 0; i < rules.Length; i += 2)
  6267. {
  6268. int psystype;
  6269. try
  6270. {
  6271. psystype = rules.GetLSLIntegerItem(i);
  6272. }
  6273. catch (InvalidCastException)
  6274. {
  6275. Error(originFunc, string.Format("Error running particle system params index #{0}: particle system parameter type must be integer", i));
  6276. return;
  6277. }
  6278. switch (psystype)
  6279. {
  6280. case (int)ScriptBaseClass.PSYS_PART_FLAGS:
  6281. try
  6282. {
  6283. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
  6284. }
  6285. catch(InvalidCastException)
  6286. {
  6287. Error(originFunc, string.Format("Error running rule PSYS_PART_FLAGS: arg #{0} - parameter 1 must be integer", i + 1));
  6288. return;
  6289. }
  6290. break;
  6291. case (int)ScriptBaseClass.PSYS_PART_START_COLOR:
  6292. try
  6293. {
  6294. tempv = rules.GetVector3Item(i + 1);
  6295. }
  6296. catch(InvalidCastException)
  6297. {
  6298. Error(originFunc, string.Format("Error running rule PSYS_PART_START_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6299. return;
  6300. }
  6301. prules.PartStartColor.R = (float)tempv.x;
  6302. prules.PartStartColor.G = (float)tempv.y;
  6303. prules.PartStartColor.B = (float)tempv.z;
  6304. break;
  6305. case (int)ScriptBaseClass.PSYS_PART_START_ALPHA:
  6306. try
  6307. {
  6308. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6309. }
  6310. catch(InvalidCastException)
  6311. {
  6312. Error(originFunc, string.Format("Error running rule PSYS_PART_START_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6313. return;
  6314. }
  6315. prules.PartStartColor.A = tempf;
  6316. break;
  6317. case (int)ScriptBaseClass.PSYS_PART_END_COLOR:
  6318. try
  6319. {
  6320. tempv = rules.GetVector3Item(i + 1);
  6321. }
  6322. catch(InvalidCastException)
  6323. {
  6324. Error(originFunc, string.Format("Error running rule PSYS_PART_END_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6325. return;
  6326. }
  6327. prules.PartEndColor.R = (float)tempv.x;
  6328. prules.PartEndColor.G = (float)tempv.y;
  6329. prules.PartEndColor.B = (float)tempv.z;
  6330. break;
  6331. case (int)ScriptBaseClass.PSYS_PART_END_ALPHA:
  6332. try
  6333. {
  6334. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6335. }
  6336. catch(InvalidCastException)
  6337. {
  6338. Error(originFunc, string.Format("Error running rule PSYS_PART_END_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6339. return;
  6340. }
  6341. prules.PartEndColor.A = tempf;
  6342. break;
  6343. case (int)ScriptBaseClass.PSYS_PART_START_SCALE:
  6344. try
  6345. {
  6346. tempv = rules.GetVector3Item(i + 1);
  6347. }
  6348. catch(InvalidCastException)
  6349. {
  6350. Error(originFunc, string.Format("Error running rule PSYS_PART_START_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6351. return;
  6352. }
  6353. prules.PartStartScaleX = validParticleScale((float)tempv.x);
  6354. prules.PartStartScaleY = validParticleScale((float)tempv.y);
  6355. break;
  6356. case (int)ScriptBaseClass.PSYS_PART_END_SCALE:
  6357. try
  6358. {
  6359. tempv = rules.GetVector3Item(i + 1);
  6360. }
  6361. catch(InvalidCastException)
  6362. {
  6363. Error(originFunc, string.Format("Error running rule PSYS_PART_END_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6364. return;
  6365. }
  6366. prules.PartEndScaleX = validParticleScale((float)tempv.x);
  6367. prules.PartEndScaleY = validParticleScale((float)tempv.y);
  6368. break;
  6369. case (int)ScriptBaseClass.PSYS_PART_MAX_AGE:
  6370. try
  6371. {
  6372. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6373. }
  6374. catch(InvalidCastException)
  6375. {
  6376. Error(originFunc, string.Format("Error running rule PSYS_PART_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6377. return;
  6378. }
  6379. prules.PartMaxAge = tempf;
  6380. break;
  6381. case (int)ScriptBaseClass.PSYS_SRC_ACCEL:
  6382. try
  6383. {
  6384. tempv = rules.GetVector3Item(i + 1);
  6385. }
  6386. catch(InvalidCastException)
  6387. {
  6388. Error(originFunc, string.Format("Error running rule PSYS_SRC_ACCEL: arg #{0} - parameter 1 must be vector", i + 1));
  6389. return;
  6390. }
  6391. prules.PartAcceleration.X = (float)tempv.x;
  6392. prules.PartAcceleration.Y = (float)tempv.y;
  6393. prules.PartAcceleration.Z = (float)tempv.z;
  6394. break;
  6395. case (int)ScriptBaseClass.PSYS_SRC_PATTERN:
  6396. try
  6397. {
  6398. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6399. }
  6400. catch(InvalidCastException)
  6401. {
  6402. Error(originFunc, string.Format("Error running rule PSYS_SRC_PATTERN: arg #{0} - parameter 1 must be integer", i + 1));
  6403. return;
  6404. }
  6405. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  6406. break;
  6407. // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
  6408. // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
  6409. // client tells the difference between the two by looking at the 0x02 bit in
  6410. // the PartFlags variable.
  6411. case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
  6412. try
  6413. {
  6414. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6415. }
  6416. catch(InvalidCastException)
  6417. {
  6418. Error(originFunc, string.Format("Error running rule PSYS_SRC_INNERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6419. return;
  6420. }
  6421. prules.InnerAngle = (float)tempf;
  6422. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6423. break;
  6424. case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
  6425. try
  6426. {
  6427. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6428. }
  6429. catch(InvalidCastException)
  6430. {
  6431. Error(originFunc, string.Format("Error running rule PSYS_SRC_OUTERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6432. return;
  6433. }
  6434. prules.OuterAngle = (float)tempf;
  6435. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6436. break;
  6437. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_SOURCE:
  6438. try
  6439. {
  6440. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6441. }
  6442. catch(InvalidCastException)
  6443. {
  6444. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_SOURCE: arg #{0} - parameter 1 must be integer", i + 1));
  6445. return;
  6446. }
  6447. prules.BlendFuncSource = (byte)tmpi;
  6448. break;
  6449. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_DEST:
  6450. try
  6451. {
  6452. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6453. }
  6454. catch(InvalidCastException)
  6455. {
  6456. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_DEST: arg #{0} - parameter 1 must be integer", i + 1));
  6457. return;
  6458. }
  6459. prules.BlendFuncDest = (byte)tmpi;
  6460. break;
  6461. case (int)ScriptBaseClass.PSYS_PART_START_GLOW:
  6462. try
  6463. {
  6464. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6465. }
  6466. catch(InvalidCastException)
  6467. {
  6468. Error(originFunc, string.Format("Error running rule PSYS_PART_START_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6469. return;
  6470. }
  6471. prules.PartStartGlow = (float)tempf;
  6472. break;
  6473. case (int)ScriptBaseClass.PSYS_PART_END_GLOW:
  6474. try
  6475. {
  6476. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6477. }
  6478. catch(InvalidCastException)
  6479. {
  6480. Error(originFunc, string.Format("Error running rule PSYS_PART_END_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6481. return;
  6482. }
  6483. prules.PartEndGlow = (float)tempf;
  6484. break;
  6485. case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
  6486. try
  6487. {
  6488. prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1));
  6489. }
  6490. catch(InvalidCastException)
  6491. {
  6492. Error(originFunc, string.Format("Error running rule PSYS_SRC_TEXTURE: arg #{0} - parameter 1 must be string or key", i + 1));
  6493. return;
  6494. }
  6495. break;
  6496. case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
  6497. try
  6498. {
  6499. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6500. }
  6501. catch(InvalidCastException)
  6502. {
  6503. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RATE: arg #{0} - parameter 1 must be float", i + 1));
  6504. return;
  6505. }
  6506. prules.BurstRate = (float)tempf;
  6507. break;
  6508. case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  6509. try
  6510. {
  6511. prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
  6512. }
  6513. catch(InvalidCastException)
  6514. {
  6515. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_PART_COUNT: arg #{0} - parameter 1 must be integer", i + 1));
  6516. return;
  6517. }
  6518. break;
  6519. case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  6520. try
  6521. {
  6522. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6523. }
  6524. catch(InvalidCastException)
  6525. {
  6526. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RADIUS: arg #{0} - parameter 1 must be float", i + 1));
  6527. return;
  6528. }
  6529. prules.BurstRadius = (float)tempf;
  6530. break;
  6531. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  6532. try
  6533. {
  6534. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6535. }
  6536. catch(InvalidCastException)
  6537. {
  6538. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MIN: arg #{0} - parameter 1 must be float", i + 1));
  6539. return;
  6540. }
  6541. prules.BurstSpeedMin = (float)tempf;
  6542. break;
  6543. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  6544. try
  6545. {
  6546. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6547. }
  6548. catch(InvalidCastException)
  6549. {
  6550. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MAX: arg #{0} - parameter 1 must be float", i + 1));
  6551. return;
  6552. }
  6553. prules.BurstSpeedMax = (float)tempf;
  6554. break;
  6555. case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE:
  6556. try
  6557. {
  6558. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6559. }
  6560. catch(InvalidCastException)
  6561. {
  6562. Error(originFunc, string.Format("Error running rule PSYS_SRC_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6563. return;
  6564. }
  6565. prules.MaxAge = (float)tempf;
  6566. break;
  6567. case (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  6568. UUID key = UUID.Zero;
  6569. if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
  6570. {
  6571. prules.Target = key;
  6572. }
  6573. else
  6574. {
  6575. prules.Target = part.UUID;
  6576. }
  6577. break;
  6578. case (int)ScriptBaseClass.PSYS_SRC_OMEGA:
  6579. // AL: This is an assumption, since it is the only thing that would match.
  6580. try
  6581. {
  6582. tempv = rules.GetVector3Item(i + 1);
  6583. }
  6584. catch(InvalidCastException)
  6585. {
  6586. Error(originFunc, string.Format("Error running rule PSYS_SRC_OMEGA: arg #{0} - parameter 1 must be vector", i + 1));
  6587. return;
  6588. }
  6589. prules.AngularVelocity.X = (float)tempv.x;
  6590. prules.AngularVelocity.Y = (float)tempv.y;
  6591. prules.AngularVelocity.Z = (float)tempv.z;
  6592. break;
  6593. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  6594. try
  6595. {
  6596. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6597. }
  6598. catch(InvalidCastException)
  6599. {
  6600. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_BEGIN: arg #{0} - parameter 1 must be float", i + 1));
  6601. return;
  6602. }
  6603. prules.InnerAngle = (float)tempf;
  6604. prules.PartFlags |= 0x02; // Set new angle format.
  6605. break;
  6606. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
  6607. try
  6608. {
  6609. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6610. }
  6611. catch (InvalidCastException)
  6612. {
  6613. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_END: arg #{0} - parameter 1 must be float", i + 1));
  6614. return;
  6615. }
  6616. prules.OuterAngle = (float)tempf;
  6617. prules.PartFlags |= 0x02; // Set new angle format.
  6618. break;
  6619. }
  6620. }
  6621. prules.CRC = 1;
  6622. part.AddNewParticleSystem(prules);
  6623. part.ParentGroup.HasGroupChanged = true;
  6624. }
  6625. part.SendFullUpdateToAllClients();
  6626. }
  6627. private float validParticleScale(float value)
  6628. {
  6629. if (value > 7.96f) return 7.96f;
  6630. return value;
  6631. }
  6632. public void llGroundRepel(double height, int water, double tau)
  6633. {
  6634. m_host.AddScriptLPS(1);
  6635. if (m_host.PhysActor != null)
  6636. {
  6637. float ground = (float)llGround(new LSL_Types.Vector3(0, 0, 0));
  6638. float waterLevel = (float)llWater(new LSL_Types.Vector3(0, 0, 0));
  6639. PIDHoverType hoverType = PIDHoverType.Ground;
  6640. if (water != 0)
  6641. {
  6642. hoverType = PIDHoverType.GroundAndWater;
  6643. if (ground < waterLevel)
  6644. height += waterLevel;
  6645. else
  6646. height += ground;
  6647. }
  6648. else
  6649. {
  6650. height += ground;
  6651. }
  6652. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  6653. }
  6654. }
  6655. public void llGiveInventoryList(LSL_Key destination, LSL_String category, LSL_List inventory)
  6656. {
  6657. m_host.AddScriptLPS(1);
  6658. UUID destID;
  6659. if (!UUID.TryParse(destination, out destID))
  6660. return;
  6661. List<UUID> itemList = new List<UUID>();
  6662. foreach (Object item in inventory.Data)
  6663. {
  6664. string rawItemString = item.ToString();
  6665. UUID itemID;
  6666. if (UUID.TryParse(rawItemString, out itemID))
  6667. {
  6668. itemList.Add(itemID);
  6669. }
  6670. else
  6671. {
  6672. TaskInventoryItem taskItem = m_host.Inventory.GetInventoryItem(rawItemString);
  6673. if (taskItem != null)
  6674. itemList.Add(taskItem.ItemID);
  6675. }
  6676. }
  6677. if (itemList.Count == 0)
  6678. return;
  6679. UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList);
  6680. if (folderID == UUID.Zero)
  6681. return;
  6682. if (m_TransferModule != null)
  6683. {
  6684. byte[] bucket = new byte[] { (byte)AssetType.Folder };
  6685. Vector3 pos = m_host.AbsolutePosition;
  6686. GridInstantMessage msg = new GridInstantMessage(World,
  6687. m_host.OwnerID, m_host.Name, destID,
  6688. (byte)InstantMessageDialog.TaskInventoryOffered,
  6689. false, string.Format("'{0}'", category),
  6690. // We won't go so far as to add a SLURL, but this is the format used by LL as of 2012-10-06
  6691. // false, string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z),
  6692. folderID, false, pos,
  6693. bucket, false);
  6694. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  6695. }
  6696. }
  6697. public void llSetVehicleType(int type)
  6698. {
  6699. m_host.AddScriptLPS(1);
  6700. if (!m_host.ParentGroup.IsDeleted)
  6701. {
  6702. m_host.ParentGroup.RootPart.SetVehicleType(type);
  6703. }
  6704. }
  6705. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6706. //CFK 9/28: so these are not complete yet.
  6707. public void llSetVehicleFloatParam(int param, LSL_Float value)
  6708. {
  6709. m_host.AddScriptLPS(1);
  6710. if (!m_host.ParentGroup.IsDeleted)
  6711. {
  6712. m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
  6713. }
  6714. }
  6715. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6716. //CFK 9/28: so these are not complete yet.
  6717. public void llSetVehicleVectorParam(int param, LSL_Vector vec)
  6718. {
  6719. m_host.AddScriptLPS(1);
  6720. if (!m_host.ParentGroup.IsDeleted)
  6721. {
  6722. m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, vec);
  6723. }
  6724. }
  6725. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6726. //CFK 9/28: so these are not complete yet.
  6727. public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
  6728. {
  6729. m_host.AddScriptLPS(1);
  6730. if (!m_host.ParentGroup.IsDeleted)
  6731. {
  6732. m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, rot);
  6733. }
  6734. }
  6735. public void llSetVehicleFlags(int flags)
  6736. {
  6737. m_host.AddScriptLPS(1);
  6738. if (!m_host.ParentGroup.IsDeleted)
  6739. {
  6740. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
  6741. }
  6742. }
  6743. public void llRemoveVehicleFlags(int flags)
  6744. {
  6745. m_host.AddScriptLPS(1);
  6746. if (!m_host.ParentGroup.IsDeleted)
  6747. {
  6748. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
  6749. }
  6750. }
  6751. protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot)
  6752. {
  6753. // LSL quaternions can normalize to 0, normal Quaternions can't.
  6754. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
  6755. rot.s = 1; // ZERO_ROTATION = 0,0,0,1
  6756. part.SitTargetPosition = offset;
  6757. part.SitTargetOrientation = rot;
  6758. part.ParentGroup.HasGroupChanged = true;
  6759. }
  6760. public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
  6761. {
  6762. m_host.AddScriptLPS(1);
  6763. SitTarget(m_host, offset, rot);
  6764. }
  6765. public void llLinkSitTarget(LSL_Integer link, LSL_Vector offset, LSL_Rotation rot)
  6766. {
  6767. m_host.AddScriptLPS(1);
  6768. if (link == ScriptBaseClass.LINK_ROOT)
  6769. SitTarget(m_host.ParentGroup.RootPart, offset, rot);
  6770. else if (link == ScriptBaseClass.LINK_THIS)
  6771. SitTarget(m_host, offset, rot);
  6772. else
  6773. {
  6774. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  6775. if (null != part)
  6776. {
  6777. SitTarget(part, offset, rot);
  6778. }
  6779. }
  6780. }
  6781. public LSL_Key llAvatarOnSitTarget()
  6782. {
  6783. m_host.AddScriptLPS(1);
  6784. return m_host.SitTargetAvatar.ToString();
  6785. }
  6786. // http://wiki.secondlife.com/wiki/LlAvatarOnLinkSitTarget
  6787. public LSL_Key llAvatarOnLinkSitTarget(LSL_Integer linknum)
  6788. {
  6789. m_host.AddScriptLPS(1);
  6790. if(linknum == ScriptBaseClass.LINK_SET ||
  6791. linknum == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6792. linknum == ScriptBaseClass.LINK_ALL_OTHERS ||
  6793. linknum == 0)
  6794. return UUID.Zero.ToString();
  6795. List<SceneObjectPart> parts = GetLinkParts(linknum);
  6796. if (parts.Count == 0)
  6797. return UUID.Zero.ToString();
  6798. return parts[0].SitTargetAvatar.ToString();
  6799. }
  6800. public void llAddToLandPassList(LSL_Key avatar, LSL_Float hours)
  6801. {
  6802. m_host.AddScriptLPS(1);
  6803. UUID key;
  6804. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  6805. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  6806. {
  6807. int expires = 0;
  6808. if (hours != 0)
  6809. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  6810. if (UUID.TryParse(avatar, out key))
  6811. {
  6812. int idx = land.LandData.ParcelAccessList.FindIndex(
  6813. delegate(LandAccessEntry e)
  6814. {
  6815. if (e.AgentID == key && e.Flags == AccessList.Access)
  6816. return true;
  6817. return false;
  6818. });
  6819. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  6820. return;
  6821. if (idx != -1)
  6822. land.LandData.ParcelAccessList.RemoveAt(idx);
  6823. LandAccessEntry entry = new LandAccessEntry();
  6824. entry.AgentID = key;
  6825. entry.Flags = AccessList.Access;
  6826. entry.Expires = expires;
  6827. land.LandData.ParcelAccessList.Add(entry);
  6828. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  6829. }
  6830. }
  6831. ScriptSleep(m_sleepMsOnAddToLandPassList);
  6832. }
  6833. public void llSetTouchText(string text)
  6834. {
  6835. m_host.AddScriptLPS(1);
  6836. if(text.Length <= 9)
  6837. m_host.TouchName = text;
  6838. else
  6839. m_host.TouchName = text.Substring(0, 9);
  6840. }
  6841. public void llSetSitText(string text)
  6842. {
  6843. m_host.AddScriptLPS(1);
  6844. if (text.Length <= 9)
  6845. m_host.SitName = text;
  6846. else
  6847. m_host.SitName = text.Substring(0, 9);
  6848. }
  6849. public void llSetCameraEyeOffset(LSL_Vector offset)
  6850. {
  6851. m_host.AddScriptLPS(1);
  6852. m_host.SetCameraEyeOffset(offset);
  6853. if (m_host.ParentGroup.RootPart.GetCameraEyeOffset() == Vector3.Zero)
  6854. m_host.ParentGroup.RootPart.SetCameraEyeOffset(offset);
  6855. }
  6856. public void llSetCameraAtOffset(LSL_Vector offset)
  6857. {
  6858. m_host.AddScriptLPS(1);
  6859. m_host.SetCameraAtOffset(offset);
  6860. if (m_host.ParentGroup.RootPart.GetCameraAtOffset() == Vector3.Zero)
  6861. m_host.ParentGroup.RootPart.SetCameraAtOffset(offset);
  6862. }
  6863. public void llSetLinkCamera(LSL_Integer link, LSL_Vector eye, LSL_Vector at)
  6864. {
  6865. m_host.AddScriptLPS(1);
  6866. if (link == ScriptBaseClass.LINK_SET ||
  6867. link == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6868. link == ScriptBaseClass.LINK_ALL_OTHERS) return;
  6869. SceneObjectPart part = null;
  6870. switch (link)
  6871. {
  6872. case ScriptBaseClass.LINK_ROOT:
  6873. part = m_host.ParentGroup.RootPart;
  6874. break;
  6875. case ScriptBaseClass.LINK_THIS:
  6876. part = m_host;
  6877. break;
  6878. default:
  6879. part = m_host.ParentGroup.GetLinkNumPart(link);
  6880. break;
  6881. }
  6882. if (null != part)
  6883. {
  6884. part.SetCameraEyeOffset(eye);
  6885. part.SetCameraAtOffset(at);
  6886. }
  6887. }
  6888. public LSL_String llDumpList2String(LSL_List src, string seperator)
  6889. {
  6890. m_host.AddScriptLPS(1);
  6891. if (src.Length == 0)
  6892. {
  6893. return String.Empty;
  6894. }
  6895. string ret = String.Empty;
  6896. foreach (object o in src.Data)
  6897. {
  6898. ret = ret + o.ToString() + seperator;
  6899. }
  6900. ret = ret.Substring(0, ret.Length - seperator.Length);
  6901. return ret;
  6902. }
  6903. public LSL_Integer llScriptDanger(LSL_Vector pos)
  6904. {
  6905. m_host.AddScriptLPS(1);
  6906. bool result = World.LSLScriptDanger(m_host, pos);
  6907. if (result)
  6908. {
  6909. return 1;
  6910. }
  6911. else
  6912. {
  6913. return 0;
  6914. }
  6915. }
  6916. public void llDialog(LSL_Key avatar, LSL_String message, LSL_List buttons, int chat_channel)
  6917. {
  6918. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  6919. if (dm == null)
  6920. return;
  6921. m_host.AddScriptLPS(1);
  6922. UUID av = new UUID();
  6923. if (!UUID.TryParse(avatar,out av))
  6924. {
  6925. Error("llDialog", "First parameter must be a key");
  6926. return;
  6927. }
  6928. int length = buttons.Length;
  6929. if (length < 1)
  6930. {
  6931. buttons.Add(new LSL_String("Ok"));
  6932. length = 1;
  6933. }
  6934. else if (length > 12)
  6935. {
  6936. Error("llDialog", "No more than 12 buttons can be shown");
  6937. return;
  6938. }
  6939. if (message == string.Empty)
  6940. {
  6941. Error("llDialog", "Empty message");
  6942. }
  6943. else if (Encoding.UTF8.GetByteCount(message) > 512)
  6944. {
  6945. Error("llDialog", "Message longer than 512 bytes");
  6946. }
  6947. string[] buts = new string[length];
  6948. for (int i = 0; i < length; i++)
  6949. {
  6950. if (buttons.Data[i].ToString() == String.Empty)
  6951. {
  6952. Error("llDialog", "Button label cannot be blank");
  6953. return;
  6954. }
  6955. /*
  6956. if (buttons.Data[i].ToString().Length > 24)
  6957. {
  6958. Error("llDialog", "Button label cannot be longer than 24 characters");
  6959. return;
  6960. }
  6961. */
  6962. buts[i] = buttons.Data[i].ToString();
  6963. }
  6964. dm.SendDialogToUser(
  6965. av, m_host.Name, m_host.UUID, m_host.OwnerID,
  6966. message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  6967. ScriptSleep(m_sleepMsOnDialog);
  6968. }
  6969. public void llVolumeDetect(int detect)
  6970. {
  6971. m_host.AddScriptLPS(1);
  6972. if (!m_host.ParentGroup.IsDeleted)
  6973. m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0);
  6974. }
  6975. public void llRemoteLoadScript(string target, string name, int running, int start_param)
  6976. {
  6977. m_host.AddScriptLPS(1);
  6978. Deprecated("llRemoteLoadScript", "Use llRemoteLoadScriptPin instead");
  6979. ScriptSleep(m_sleepMsOnRemoteLoadScript);
  6980. }
  6981. public void llSetRemoteScriptAccessPin(int pin)
  6982. {
  6983. m_host.AddScriptLPS(1);
  6984. m_host.ScriptAccessPin = pin;
  6985. }
  6986. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  6987. {
  6988. m_host.AddScriptLPS(1);
  6989. UUID destId = UUID.Zero;
  6990. if (!UUID.TryParse(target, out destId))
  6991. {
  6992. Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'");
  6993. return;
  6994. }
  6995. // target must be a different prim than the one containing the script
  6996. if (m_host.UUID == destId)
  6997. {
  6998. return;
  6999. }
  7000. // copy the first script found with this inventory name
  7001. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  7002. // make sure the object is a script
  7003. if (item == null || item.Type != 10)
  7004. {
  7005. Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'");
  7006. return;
  7007. }
  7008. SceneObjectPart dest = World.GetSceneObjectPart(destId);
  7009. if (dest != null)
  7010. {
  7011. if ((item.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
  7012. {
  7013. // the rest of the permission checks are done in RezScript, so check the pin there as well
  7014. World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
  7015. if ((item.BasePermissions & (uint)PermissionMask.Copy) == 0)
  7016. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  7017. }
  7018. }
  7019. // this will cause the delay even if the script pin or permissions were wrong - seems ok
  7020. ScriptSleep(m_sleepMsOnRemoteLoadScriptPin);
  7021. }
  7022. public void llOpenRemoteDataChannel()
  7023. {
  7024. m_host.AddScriptLPS(1);
  7025. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7026. if (xmlrpcMod != null && xmlrpcMod.IsEnabled())
  7027. {
  7028. UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
  7029. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  7030. if (xmlRpcRouter != null)
  7031. {
  7032. string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
  7033. xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
  7034. m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
  7035. xmlrpcMod.Port.ToString()));
  7036. }
  7037. object[] resobj = new object[]
  7038. {
  7039. new LSL_Integer(1),
  7040. new LSL_String(channelID.ToString()),
  7041. new LSL_String(UUID.Zero.ToString()),
  7042. new LSL_String(String.Empty),
  7043. new LSL_Integer(0),
  7044. new LSL_String(String.Empty)
  7045. };
  7046. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
  7047. new DetectParams[0]));
  7048. }
  7049. ScriptSleep(m_sleepMsOnOpenRemoteDataChannel);
  7050. }
  7051. public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata)
  7052. {
  7053. m_host.AddScriptLPS(1);
  7054. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7055. ScriptSleep(m_sleepMsOnSendRemoteData);
  7056. if (xmlrpcMod == null)
  7057. return "";
  7058. return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
  7059. }
  7060. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  7061. {
  7062. m_host.AddScriptLPS(1);
  7063. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7064. if (xmlrpcMod != null)
  7065. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  7066. ScriptSleep(m_sleepMsOnRemoteDataReply);
  7067. }
  7068. public void llCloseRemoteDataChannel(string channel)
  7069. {
  7070. m_host.AddScriptLPS(1);
  7071. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  7072. if (xmlRpcRouter != null)
  7073. {
  7074. xmlRpcRouter.UnRegisterReceiver(channel, m_item.ItemID);
  7075. }
  7076. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7077. if (xmlrpcMod != null)
  7078. xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
  7079. ScriptSleep(m_sleepMsOnCloseRemoteDataChannel);
  7080. }
  7081. public LSL_String llMD5String(string src, int nonce)
  7082. {
  7083. m_host.AddScriptLPS(1);
  7084. return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
  7085. }
  7086. public LSL_String llSHA1String(string src)
  7087. {
  7088. m_host.AddScriptLPS(1);
  7089. return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
  7090. }
  7091. protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
  7092. {
  7093. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7094. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7095. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7096. return shapeBlock;
  7097. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  7098. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  7099. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  7100. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  7101. {
  7102. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  7103. }
  7104. shapeBlock.PathCurve = pathcurve;
  7105. shapeBlock.ProfileCurve = (byte)holeshape; // Set the hole shape.
  7106. shapeBlock.ProfileCurve += profileshape; // Add in the profile shape.
  7107. if (cut.x < 0f)
  7108. {
  7109. cut.x = 0f;
  7110. }
  7111. else if (cut.x > 1f)
  7112. {
  7113. cut.x = 1f;
  7114. }
  7115. if (cut.y < 0f)
  7116. {
  7117. cut.y = 0f;
  7118. }
  7119. else if (cut.y > 1f)
  7120. {
  7121. cut.y = 1f;
  7122. }
  7123. if (cut.y - cut.x < 0.02f)
  7124. {
  7125. cut.x = cut.y - 0.02f;
  7126. if (cut.x < 0.0f)
  7127. {
  7128. cut.x = 0.0f;
  7129. cut.y = 0.02f;
  7130. }
  7131. }
  7132. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  7133. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  7134. if (hollow < 0f)
  7135. {
  7136. hollow = 0f;
  7137. }
  7138. // If the prim is a Cylinder, Prism, Sphere, Torus or Ring (or not a
  7139. // Box or Tube) and the hole shape is a square, hollow is limited to
  7140. // a max of 70%. The viewer performs its own check on this value but
  7141. // we need to do it here also so llGetPrimitiveParams can have access
  7142. // to the correct value.
  7143. if (profileshape != (byte)ProfileCurve.Square &&
  7144. holeshape == (int)ScriptBaseClass.PRIM_HOLE_SQUARE)
  7145. {
  7146. if (hollow > 0.70f)
  7147. {
  7148. hollow = 0.70f;
  7149. }
  7150. }
  7151. // Otherwise, hollow is limited to 99%.
  7152. else
  7153. {
  7154. if (hollow > 0.99f)
  7155. {
  7156. hollow = 0.99f;
  7157. }
  7158. }
  7159. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  7160. if (twist.x < -1.0f)
  7161. {
  7162. twist.x = -1.0f;
  7163. }
  7164. else if (twist.x > 1.0f)
  7165. {
  7166. twist.x = 1.0f;
  7167. }
  7168. if (twist.y < -1.0f)
  7169. {
  7170. twist.y = -1.0f;
  7171. }
  7172. else if (twist.y > 1.0f)
  7173. {
  7174. twist.y = 1.0f;
  7175. }
  7176. tempFloat = 100.0f * (float)twist.x;
  7177. if (tempFloat >= 0)
  7178. tempFloat += 0.5f;
  7179. else
  7180. tempFloat -= 0.5f;
  7181. shapeBlock.PathTwistBegin = (sbyte)tempFloat;
  7182. tempFloat = 100.0f * (float)twist.y;
  7183. if (tempFloat >= 0)
  7184. tempFloat += 0.5f;
  7185. else
  7186. tempFloat -= 0.5f;
  7187. shapeBlock.PathTwist = (sbyte)tempFloat;
  7188. shapeBlock.ObjectLocalID = part.LocalId;
  7189. part.Shape.SculptEntry = false;
  7190. return shapeBlock;
  7191. }
  7192. // Prim type box, cylinder and prism.
  7193. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte profileshape, byte pathcurve)
  7194. {
  7195. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7196. return;
  7197. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7198. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7199. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7200. if (taper_b.x < 0f)
  7201. {
  7202. taper_b.x = 0f;
  7203. }
  7204. else if (taper_b.x > 2f)
  7205. {
  7206. taper_b.x = 2f;
  7207. }
  7208. if (taper_b.y < 0f)
  7209. {
  7210. taper_b.y = 0f;
  7211. }
  7212. else if (taper_b.y > 2f)
  7213. {
  7214. taper_b.y = 2f;
  7215. }
  7216. tempFloat = 100.0f * (2.0f - (float)taper_b.x);
  7217. if (tempFloat >= 0)
  7218. tempFloat += 0.5f;
  7219. else
  7220. tempFloat -= 0.5f;
  7221. shapeBlock.PathScaleX = (byte)tempFloat;
  7222. tempFloat = 100.0f * (2.0f - (float)taper_b.y);
  7223. if (tempFloat >= 0)
  7224. tempFloat += 0.5f;
  7225. else
  7226. tempFloat -= 0.5f;
  7227. shapeBlock.PathScaleY = (byte)tempFloat;
  7228. if (topshear.x < -0.5f)
  7229. {
  7230. topshear.x = -0.5f;
  7231. }
  7232. else if (topshear.x > 0.5f)
  7233. {
  7234. topshear.x = 0.5f;
  7235. }
  7236. if (topshear.y < -0.5f)
  7237. {
  7238. topshear.y = -0.5f;
  7239. }
  7240. else if (topshear.y > 0.5f)
  7241. {
  7242. topshear.y = 0.5f;
  7243. }
  7244. tempFloat = 100.0f * (float)topshear.x;
  7245. if (tempFloat >= 0)
  7246. tempFloat += 0.5f;
  7247. else
  7248. tempFloat -= 0.5f;
  7249. shapeBlock.PathShearX = (byte)tempFloat;
  7250. tempFloat = 100.0f * (float)topshear.y;
  7251. if (tempFloat >= 0)
  7252. tempFloat += 0.5f;
  7253. else
  7254. tempFloat -= 0.5f;
  7255. shapeBlock.PathShearY = (byte)tempFloat;
  7256. part.Shape.SculptEntry = false;
  7257. part.UpdateShape(shapeBlock);
  7258. }
  7259. // Prim type sphere.
  7260. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
  7261. {
  7262. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7263. return;
  7264. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7265. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7266. // profile/path swapped for a sphere
  7267. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7268. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7269. shapeBlock.PathScaleX = 100;
  7270. shapeBlock.PathScaleY = 100;
  7271. if (dimple.x < 0f)
  7272. {
  7273. dimple.x = 0f;
  7274. }
  7275. else if (dimple.x > 1f)
  7276. {
  7277. dimple.x = 1f;
  7278. }
  7279. if (dimple.y < 0f)
  7280. {
  7281. dimple.y = 0f;
  7282. }
  7283. else if (dimple.y > 1f)
  7284. {
  7285. dimple.y = 1f;
  7286. }
  7287. if (dimple.y - dimple.x < 0.02f)
  7288. {
  7289. dimple.x = dimple.y - 0.02f;
  7290. if (dimple.x < 0.0f)
  7291. {
  7292. dimple.x = 0.0f;
  7293. dimple.y = 0.02f;
  7294. }
  7295. }
  7296. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  7297. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  7298. part.Shape.SculptEntry = false;
  7299. part.UpdateShape(shapeBlock);
  7300. }
  7301. // Prim type torus, tube and ring.
  7302. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector holesize, LSL_Vector topshear, LSL_Vector profilecut, LSL_Vector taper_a, float revolutions, float radiusoffset, float skew, byte profileshape, byte pathcurve)
  7303. {
  7304. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7305. return;
  7306. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7307. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7308. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7309. // profile/path swapped for a torrus, tube, ring
  7310. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7311. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7312. if (holesize.x < 0.01f)
  7313. {
  7314. holesize.x = 0.01f;
  7315. }
  7316. else if (holesize.x > 1f)
  7317. {
  7318. holesize.x = 1f;
  7319. }
  7320. tempFloat = 100.0f * (2.0f - (float)holesize.x) + 0.5f;
  7321. shapeBlock.PathScaleX = (byte)tempFloat;
  7322. if (holesize.y < 0.01f)
  7323. {
  7324. holesize.y = 0.01f;
  7325. }
  7326. else if (holesize.y > 0.5f)
  7327. {
  7328. holesize.y = 0.5f;
  7329. }
  7330. tempFloat = 100.0f * (2.0f - (float)holesize.y) + 0.5f;
  7331. shapeBlock.PathScaleY = (byte)tempFloat;
  7332. if (topshear.x < -0.5f)
  7333. {
  7334. topshear.x = -0.5f;
  7335. }
  7336. else if (topshear.x > 0.5f)
  7337. {
  7338. topshear.x = 0.5f;
  7339. }
  7340. tempFloat = (float)(100.0d * topshear.x);
  7341. if (tempFloat >= 0)
  7342. tempFloat += 0.5f;
  7343. else
  7344. tempFloat -= 0.5f;
  7345. shapeBlock.PathShearX = (byte)tempFloat;
  7346. if (topshear.y < -0.5f)
  7347. {
  7348. topshear.y = -0.5f;
  7349. }
  7350. else if (topshear.y > 0.5f)
  7351. {
  7352. topshear.y = 0.5f;
  7353. }
  7354. tempFloat = (float)(100.0d * topshear.y);
  7355. if (tempFloat >= 0)
  7356. tempFloat += 0.5f;
  7357. else
  7358. tempFloat -= 0.5f;
  7359. shapeBlock.PathShearY = (byte)tempFloat;
  7360. if (profilecut.x < 0f)
  7361. {
  7362. profilecut.x = 0f;
  7363. }
  7364. else if (profilecut.x > 1f)
  7365. {
  7366. profilecut.x = 1f;
  7367. }
  7368. if (profilecut.y < 0f)
  7369. {
  7370. profilecut.y = 0f;
  7371. }
  7372. else if (profilecut.y > 1f)
  7373. {
  7374. profilecut.y = 1f;
  7375. }
  7376. if (profilecut.y - profilecut.x < 0.02f)
  7377. {
  7378. profilecut.x = profilecut.y - 0.02f;
  7379. if (profilecut.x < 0.0f)
  7380. {
  7381. profilecut.x = 0.0f;
  7382. profilecut.y = 0.02f;
  7383. }
  7384. }
  7385. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  7386. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  7387. if (taper_a.x < -1f)
  7388. {
  7389. taper_a.x = -1f;
  7390. }
  7391. if (taper_a.x > 1f)
  7392. {
  7393. taper_a.x = 1f;
  7394. }
  7395. tempFloat = 100.0f * (float)taper_a.x;
  7396. if (tempFloat >= 0)
  7397. tempFloat += 0.5f;
  7398. else
  7399. tempFloat -= 0.5f;
  7400. shapeBlock.PathTaperX = (sbyte)tempFloat;
  7401. if (taper_a.y < -1f)
  7402. {
  7403. taper_a.y = -1f;
  7404. }
  7405. else if (taper_a.y > 1f)
  7406. {
  7407. taper_a.y = 1f;
  7408. }
  7409. tempFloat = 100.0f * (float)taper_a.y;
  7410. if (tempFloat >= 0)
  7411. tempFloat += 0.5f;
  7412. else
  7413. tempFloat -= 0.5f;
  7414. shapeBlock.PathTaperY = (sbyte)tempFloat;
  7415. if (revolutions < 1f)
  7416. {
  7417. revolutions = 1f;
  7418. }
  7419. if (revolutions > 4f)
  7420. {
  7421. revolutions = 4f;
  7422. }
  7423. tempFloat = 66.66667f * (revolutions - 1.0f) + 0.5f;
  7424. shapeBlock.PathRevolutions = (byte)tempFloat;
  7425. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  7426. if (radiusoffset < 0f)
  7427. {
  7428. radiusoffset = 0f;
  7429. }
  7430. if (radiusoffset > 1f)
  7431. {
  7432. radiusoffset = 1f;
  7433. }
  7434. tempFloat = 100.0f * radiusoffset + 0.5f;
  7435. shapeBlock.PathRadiusOffset = (sbyte)tempFloat;
  7436. if (skew < -0.95f)
  7437. {
  7438. skew = -0.95f;
  7439. }
  7440. if (skew > 0.95f)
  7441. {
  7442. skew = 0.95f;
  7443. }
  7444. tempFloat = 100.0f * skew;
  7445. if (tempFloat >= 0)
  7446. tempFloat += 0.5f;
  7447. else
  7448. tempFloat -= 0.5f;
  7449. shapeBlock.PathSkew = (sbyte)tempFloat;
  7450. part.Shape.SculptEntry = false;
  7451. part.UpdateShape(shapeBlock);
  7452. }
  7453. // Prim type sculpt.
  7454. protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
  7455. {
  7456. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7457. return;
  7458. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7459. UUID sculptId;
  7460. if (!UUID.TryParse(map, out sculptId))
  7461. sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture);
  7462. if (sculptId == UUID.Zero)
  7463. return;
  7464. shapeBlock.PathCurve = pathcurve;
  7465. shapeBlock.ObjectLocalID = part.LocalId;
  7466. shapeBlock.PathScaleX = 100;
  7467. shapeBlock.PathScaleY = 150;
  7468. int flag = type & (ScriptBaseClass.PRIM_SCULPT_FLAG_INVERT | ScriptBaseClass.PRIM_SCULPT_FLAG_MIRROR);
  7469. if (type != (ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER | flag) &&
  7470. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE | flag) &&
  7471. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE | flag) &&
  7472. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
  7473. {
  7474. // default
  7475. type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  7476. }
  7477. part.Shape.SetSculptProperties((byte)type, sculptId);
  7478. part.Shape.SculptEntry = true;
  7479. part.UpdateShape(shapeBlock);
  7480. }
  7481. public void llSetPrimitiveParams(LSL_List rules)
  7482. {
  7483. m_host.AddScriptLPS(1);
  7484. SetLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams");
  7485. ScriptSleep(m_sleepMsOnSetPrimitiveParams);
  7486. }
  7487. public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
  7488. {
  7489. m_host.AddScriptLPS(1);
  7490. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
  7491. ScriptSleep(m_sleepMsOnSetLinkPrimitiveParams);
  7492. }
  7493. public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
  7494. {
  7495. m_host.AddScriptLPS(1);
  7496. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
  7497. }
  7498. private void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
  7499. {
  7500. List<object> parts = new List<object>();
  7501. List<SceneObjectPart> prims = GetLinkParts(linknumber);
  7502. List<ScenePresence> avatars = GetLinkAvatars(linknumber);
  7503. foreach (SceneObjectPart p in prims)
  7504. parts.Add(p);
  7505. foreach (ScenePresence p in avatars)
  7506. parts.Add(p);
  7507. LSL_List remaining = new LSL_List();
  7508. uint rulesParsed = 0;
  7509. if (parts.Count > 0)
  7510. {
  7511. foreach (object part in parts)
  7512. {
  7513. if (part is SceneObjectPart)
  7514. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7515. else
  7516. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7517. }
  7518. while (remaining.Length > 2)
  7519. {
  7520. linknumber = remaining.GetLSLIntegerItem(0);
  7521. rules = remaining.GetSublist(1, -1);
  7522. parts.Clear();
  7523. prims = GetLinkParts(linknumber);
  7524. avatars = GetLinkAvatars(linknumber);
  7525. foreach (SceneObjectPart p in prims)
  7526. parts.Add(p);
  7527. foreach (ScenePresence p in avatars)
  7528. parts.Add(p);
  7529. remaining = new LSL_List();
  7530. foreach (object part in parts)
  7531. {
  7532. if (part is SceneObjectPart)
  7533. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7534. else
  7535. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7536. }
  7537. }
  7538. }
  7539. }
  7540. public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
  7541. {
  7542. SceneObjectGroup group = m_host.ParentGroup;
  7543. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  7544. return;
  7545. if (group.IsAttachment)
  7546. return;
  7547. if (frames.Data.Length > 0) // We are getting a new motion
  7548. {
  7549. if (group.RootPart.KeyframeMotion != null)
  7550. group.RootPart.KeyframeMotion.Delete();
  7551. group.RootPart.KeyframeMotion = null;
  7552. int idx = 0;
  7553. KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
  7554. KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
  7555. while (idx < options.Data.Length)
  7556. {
  7557. int option = (int)options.GetLSLIntegerItem(idx++);
  7558. int remain = options.Data.Length - idx;
  7559. switch (option)
  7560. {
  7561. case ScriptBaseClass.KFM_MODE:
  7562. if (remain < 1)
  7563. break;
  7564. int modeval = (int)options.GetLSLIntegerItem(idx++);
  7565. switch(modeval)
  7566. {
  7567. case ScriptBaseClass.KFM_FORWARD:
  7568. mode = KeyframeMotion.PlayMode.Forward;
  7569. break;
  7570. case ScriptBaseClass.KFM_REVERSE:
  7571. mode = KeyframeMotion.PlayMode.Reverse;
  7572. break;
  7573. case ScriptBaseClass.KFM_LOOP:
  7574. mode = KeyframeMotion.PlayMode.Loop;
  7575. break;
  7576. case ScriptBaseClass.KFM_PING_PONG:
  7577. mode = KeyframeMotion.PlayMode.PingPong;
  7578. break;
  7579. }
  7580. break;
  7581. case ScriptBaseClass.KFM_DATA:
  7582. if (remain < 1)
  7583. break;
  7584. int dataval = (int)options.GetLSLIntegerItem(idx++);
  7585. data = (KeyframeMotion.DataFormat)dataval;
  7586. break;
  7587. }
  7588. }
  7589. group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
  7590. idx = 0;
  7591. int elemLength = 2;
  7592. if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
  7593. elemLength = 3;
  7594. List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
  7595. while (idx < frames.Data.Length)
  7596. {
  7597. int remain = frames.Data.Length - idx;
  7598. if (remain < elemLength)
  7599. break;
  7600. KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe();
  7601. frame.Position = null;
  7602. frame.Rotation = null;
  7603. if ((data & KeyframeMotion.DataFormat.Translation) != 0)
  7604. {
  7605. LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
  7606. frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
  7607. }
  7608. if ((data & KeyframeMotion.DataFormat.Rotation) != 0)
  7609. {
  7610. LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
  7611. Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
  7612. q.Normalize();
  7613. frame.Rotation = q;
  7614. }
  7615. float tempf = (float)frames.GetLSLFloatItem(idx++);
  7616. frame.TimeMS = (int)(tempf * 1000.0f);
  7617. keyframes.Add(frame);
  7618. }
  7619. group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
  7620. group.RootPart.KeyframeMotion.Start();
  7621. }
  7622. else
  7623. {
  7624. if (group.RootPart.KeyframeMotion == null)
  7625. return;
  7626. if (options.Data.Length == 0)
  7627. {
  7628. group.RootPart.KeyframeMotion.Stop();
  7629. return;
  7630. }
  7631. int idx = 0;
  7632. while (idx < options.Data.Length)
  7633. {
  7634. int option = (int)options.GetLSLIntegerItem(idx++);
  7635. switch (option)
  7636. {
  7637. case ScriptBaseClass.KFM_COMMAND:
  7638. int cmd = (int)options.GetLSLIntegerItem(idx++);
  7639. switch (cmd)
  7640. {
  7641. case ScriptBaseClass.KFM_CMD_PLAY:
  7642. group.RootPart.KeyframeMotion.Start();
  7643. break;
  7644. case ScriptBaseClass.KFM_CMD_STOP:
  7645. group.RootPart.KeyframeMotion.Stop();
  7646. break;
  7647. case ScriptBaseClass.KFM_CMD_PAUSE:
  7648. group.RootPart.KeyframeMotion.Pause();
  7649. break;
  7650. }
  7651. break;
  7652. }
  7653. }
  7654. }
  7655. }
  7656. public LSL_List llGetPhysicsMaterial()
  7657. {
  7658. LSL_List result = new LSL_List();
  7659. result.Add(new LSL_Float(m_host.GravityModifier));
  7660. result.Add(new LSL_Float(m_host.Restitution));
  7661. result.Add(new LSL_Float(m_host.Friction));
  7662. result.Add(new LSL_Float(m_host.Density));
  7663. return result;
  7664. }
  7665. private void SetPhysicsMaterial(SceneObjectPart part, int material_bits,
  7666. float material_density, float material_friction,
  7667. float material_restitution, float material_gravity_modifier)
  7668. {
  7669. ExtraPhysicsData physdata = new ExtraPhysicsData();
  7670. physdata.PhysShapeType = (PhysShapeType)part.PhysicsShapeType;
  7671. physdata.Density = part.Density;
  7672. physdata.Friction = part.Friction;
  7673. physdata.Bounce = part.Restitution;
  7674. physdata.GravitationModifier = part.GravityModifier;
  7675. if ((material_bits & (int)ScriptBaseClass.DENSITY) != 0)
  7676. physdata.Density = material_density;
  7677. if ((material_bits & (int)ScriptBaseClass.FRICTION) != 0)
  7678. physdata.Friction = material_friction;
  7679. if ((material_bits & (int)ScriptBaseClass.RESTITUTION) != 0)
  7680. physdata.Bounce = material_restitution;
  7681. if ((material_bits & (int)ScriptBaseClass.GRAVITY_MULTIPLIER) != 0)
  7682. physdata.GravitationModifier = material_gravity_modifier;
  7683. part.UpdateExtraPhysics(physdata);
  7684. }
  7685. public void llSetPhysicsMaterial(int material_bits,
  7686. LSL_Float material_gravity_modifier, LSL_Float material_restitution,
  7687. LSL_Float material_friction, LSL_Float material_density)
  7688. {
  7689. SetPhysicsMaterial(m_host, material_bits, (float)material_density, (float)material_friction, (float)material_restitution, (float)material_gravity_modifier);
  7690. }
  7691. // vector up using libomv (c&p from sop )
  7692. // vector up rotated by r
  7693. private Vector3 Zrot(Quaternion r)
  7694. {
  7695. double x, y, z, m;
  7696. m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7697. if (Math.Abs(1.0 - m) > 0.000001)
  7698. {
  7699. m = 1.0 / Math.Sqrt(m);
  7700. r.X *= (float)m;
  7701. r.Y *= (float)m;
  7702. r.Z *= (float)m;
  7703. r.W *= (float)m;
  7704. }
  7705. x = 2 * (r.X * r.Z + r.Y * r.W);
  7706. y = 2 * (-r.X * r.W + r.Y * r.Z);
  7707. z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7708. return new Vector3((float)x, (float)y, (float)z);
  7709. }
  7710. protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
  7711. {
  7712. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7713. return new LSL_List();
  7714. int idx = 0;
  7715. int idxStart = 0;
  7716. SceneObjectGroup parentgrp = part.ParentGroup;
  7717. bool positionChanged = false;
  7718. bool materialChanged = false;
  7719. LSL_Vector currentPosition = GetPartLocalPos(part);
  7720. try
  7721. {
  7722. while (idx < rules.Length)
  7723. {
  7724. ++rulesParsed;
  7725. int code = rules.GetLSLIntegerItem(idx++);
  7726. int remain = rules.Length - idx;
  7727. idxStart = idx;
  7728. int face;
  7729. LSL_Vector v;
  7730. switch (code)
  7731. {
  7732. case ScriptBaseClass.PRIM_POSITION:
  7733. case ScriptBaseClass.PRIM_POS_LOCAL:
  7734. if (remain < 1)
  7735. return new LSL_List();
  7736. try
  7737. {
  7738. v = rules.GetVector3Item(idx++);
  7739. }
  7740. catch(InvalidCastException)
  7741. {
  7742. if(code == ScriptBaseClass.PRIM_POSITION)
  7743. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7744. else
  7745. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7746. return new LSL_List();
  7747. }
  7748. if (part.IsRoot && !part.ParentGroup.IsAttachment)
  7749. currentPosition = GetSetPosTarget(part, v, currentPosition, true);
  7750. else
  7751. currentPosition = GetSetPosTarget(part, v, currentPosition, false);
  7752. positionChanged = true;
  7753. break;
  7754. case ScriptBaseClass.PRIM_SIZE:
  7755. if (remain < 1)
  7756. return new LSL_List();
  7757. v=rules.GetVector3Item(idx++);
  7758. SetScale(part, v);
  7759. break;
  7760. case ScriptBaseClass.PRIM_ROTATION:
  7761. if (remain < 1)
  7762. return new LSL_List();
  7763. LSL_Rotation q;
  7764. try
  7765. {
  7766. q = rules.GetQuaternionItem(idx++);
  7767. }
  7768. catch(InvalidCastException)
  7769. {
  7770. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 1 must be rotation", rulesParsed, idx - idxStart - 1));
  7771. return new LSL_List();
  7772. }
  7773. // try to let this work as in SL...
  7774. if (part.ParentID == 0 || (part.ParentGroup != null && part == part.ParentGroup.RootPart))
  7775. {
  7776. // special case: If we are root, rotate complete SOG to new rotation
  7777. SetRot(part, q);
  7778. }
  7779. else
  7780. {
  7781. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  7782. SceneObjectPart rootPart = part.ParentGroup.RootPart;
  7783. SetRot(part, rootPart.RotationOffset * (Quaternion)q);
  7784. }
  7785. break;
  7786. case ScriptBaseClass.PRIM_TYPE:
  7787. if (remain < 3)
  7788. return new LSL_List();
  7789. try
  7790. {
  7791. code = (int)rules.GetLSLIntegerItem(idx++);
  7792. }
  7793. catch(InvalidCastException)
  7794. {
  7795. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  7796. return new LSL_List();
  7797. }
  7798. remain = rules.Length - idx;
  7799. float hollow;
  7800. LSL_Vector twist;
  7801. LSL_Vector taper_b;
  7802. LSL_Vector topshear;
  7803. float revolutions;
  7804. float radiusoffset;
  7805. float skew;
  7806. LSL_Vector holesize;
  7807. LSL_Vector profilecut;
  7808. switch (code)
  7809. {
  7810. case ScriptBaseClass.PRIM_TYPE_BOX:
  7811. if (remain < 6)
  7812. return new LSL_List();
  7813. try
  7814. {
  7815. face = (int)rules.GetLSLIntegerItem(idx++);
  7816. }
  7817. catch(InvalidCastException)
  7818. {
  7819. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7820. return new LSL_List();
  7821. }
  7822. try
  7823. {
  7824. v = rules.GetVector3Item(idx++); // cut
  7825. }
  7826. catch(InvalidCastException)
  7827. {
  7828. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  7829. return new LSL_List();
  7830. }
  7831. try
  7832. {
  7833. hollow = (float)rules.GetLSLFloatItem(idx++);
  7834. }
  7835. catch(InvalidCastException)
  7836. {
  7837. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  7838. return new LSL_List();
  7839. }
  7840. try
  7841. {
  7842. twist = rules.GetVector3Item(idx++);
  7843. }
  7844. catch(InvalidCastException)
  7845. {
  7846. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 5 must be vector", rulesParsed, idx - idxStart - 1));
  7847. return new LSL_List();
  7848. }
  7849. try
  7850. {
  7851. taper_b = rules.GetVector3Item(idx++);
  7852. }
  7853. catch(InvalidCastException)
  7854. {
  7855. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7856. return new LSL_List();
  7857. }
  7858. try
  7859. {
  7860. topshear = rules.GetVector3Item(idx++);
  7861. }
  7862. catch(InvalidCastException)
  7863. {
  7864. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7865. return new LSL_List();
  7866. }
  7867. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7868. (byte)ProfileShape.Square, (byte)Extrusion.Straight);
  7869. break;
  7870. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  7871. if (remain < 6)
  7872. return new LSL_List();
  7873. try
  7874. {
  7875. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7876. }
  7877. catch(InvalidCastException)
  7878. {
  7879. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7880. return new LSL_List();
  7881. }
  7882. try
  7883. {
  7884. v = rules.GetVector3Item(idx++); // cut
  7885. }
  7886. catch(InvalidCastException)
  7887. {
  7888. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7889. return new LSL_List();
  7890. }
  7891. try
  7892. {
  7893. hollow = (float)rules.GetLSLFloatItem(idx++);
  7894. }
  7895. catch(InvalidCastException)
  7896. {
  7897. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7898. return new LSL_List();
  7899. }
  7900. try
  7901. {
  7902. twist = rules.GetVector3Item(idx++);
  7903. }
  7904. catch(InvalidCastException)
  7905. {
  7906. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7907. return new LSL_List();
  7908. }
  7909. try
  7910. {
  7911. taper_b = rules.GetVector3Item(idx++);
  7912. }
  7913. catch(InvalidCastException)
  7914. {
  7915. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7916. return new LSL_List();
  7917. }
  7918. try
  7919. {
  7920. topshear = rules.GetVector3Item(idx++);
  7921. }
  7922. catch(InvalidCastException)
  7923. {
  7924. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7925. return new LSL_List();
  7926. }
  7927. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7928. (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
  7929. break;
  7930. case ScriptBaseClass.PRIM_TYPE_PRISM:
  7931. if (remain < 6)
  7932. return new LSL_List();
  7933. try
  7934. {
  7935. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7936. }
  7937. catch(InvalidCastException)
  7938. {
  7939. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7940. return new LSL_List();
  7941. }
  7942. try
  7943. {
  7944. v = rules.GetVector3Item(idx++); //cut
  7945. }
  7946. catch(InvalidCastException)
  7947. {
  7948. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7949. return new LSL_List();
  7950. }
  7951. try
  7952. {
  7953. hollow = (float)rules.GetLSLFloatItem(idx++);
  7954. }
  7955. catch(InvalidCastException)
  7956. {
  7957. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7958. return new LSL_List();
  7959. }
  7960. try
  7961. {
  7962. twist = rules.GetVector3Item(idx++);
  7963. }
  7964. catch(InvalidCastException)
  7965. {
  7966. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7967. return new LSL_List();
  7968. }
  7969. try
  7970. {
  7971. taper_b = rules.GetVector3Item(idx++);
  7972. }
  7973. catch(InvalidCastException)
  7974. {
  7975. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7976. return new LSL_List();
  7977. }
  7978. try
  7979. {
  7980. topshear = rules.GetVector3Item(idx++);
  7981. }
  7982. catch(InvalidCastException)
  7983. {
  7984. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7985. return new LSL_List();
  7986. }
  7987. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7988. (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
  7989. break;
  7990. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  7991. if (remain < 5)
  7992. return new LSL_List();
  7993. try
  7994. {
  7995. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7996. }
  7997. catch(InvalidCastException)
  7998. {
  7999. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8000. return new LSL_List();
  8001. }
  8002. try
  8003. {
  8004. v = rules.GetVector3Item(idx++); // cut
  8005. }
  8006. catch(InvalidCastException)
  8007. {
  8008. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8009. return new LSL_List();
  8010. }
  8011. try
  8012. {
  8013. hollow = (float)rules.GetLSLFloatItem(idx++);
  8014. }
  8015. catch(InvalidCastException)
  8016. {
  8017. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8018. return new LSL_List();
  8019. }
  8020. try
  8021. {
  8022. twist = rules.GetVector3Item(idx++);
  8023. }
  8024. catch(InvalidCastException)
  8025. {
  8026. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8027. return new LSL_List();
  8028. }
  8029. try
  8030. {
  8031. taper_b = rules.GetVector3Item(idx++); // dimple
  8032. }
  8033. catch(InvalidCastException)
  8034. {
  8035. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8036. return new LSL_List();
  8037. }
  8038. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
  8039. (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
  8040. break;
  8041. case ScriptBaseClass.PRIM_TYPE_TORUS:
  8042. if (remain < 11)
  8043. return new LSL_List();
  8044. try
  8045. {
  8046. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8047. }
  8048. catch(InvalidCastException)
  8049. {
  8050. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8051. return new LSL_List();
  8052. }
  8053. try
  8054. {
  8055. v = rules.GetVector3Item(idx++); //cut
  8056. }
  8057. catch(InvalidCastException)
  8058. {
  8059. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8060. return new LSL_List();
  8061. }
  8062. try
  8063. {
  8064. hollow = (float)rules.GetLSLFloatItem(idx++);
  8065. }
  8066. catch(InvalidCastException)
  8067. {
  8068. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8069. return new LSL_List();
  8070. }
  8071. try
  8072. {
  8073. twist = rules.GetVector3Item(idx++);
  8074. }
  8075. catch(InvalidCastException)
  8076. {
  8077. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8078. return new LSL_List();
  8079. }
  8080. try
  8081. {
  8082. holesize = rules.GetVector3Item(idx++);
  8083. }
  8084. catch(InvalidCastException)
  8085. {
  8086. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8087. return new LSL_List();
  8088. }
  8089. try
  8090. {
  8091. topshear = rules.GetVector3Item(idx++);
  8092. }
  8093. catch(InvalidCastException)
  8094. {
  8095. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8096. return new LSL_List();
  8097. }
  8098. try
  8099. {
  8100. profilecut = rules.GetVector3Item(idx++);
  8101. }
  8102. catch(InvalidCastException)
  8103. {
  8104. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8105. return new LSL_List();
  8106. }
  8107. try
  8108. {
  8109. taper_b = rules.GetVector3Item(idx++); // taper_a
  8110. }
  8111. catch(InvalidCastException)
  8112. {
  8113. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8114. return new LSL_List();
  8115. }
  8116. try
  8117. {
  8118. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8119. }
  8120. catch(InvalidCastException)
  8121. {
  8122. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8123. return new LSL_List();
  8124. }
  8125. try
  8126. {
  8127. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8128. }
  8129. catch(InvalidCastException)
  8130. {
  8131. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8132. return new LSL_List();
  8133. }
  8134. try
  8135. {
  8136. skew = (float)rules.GetLSLFloatItem(idx++);
  8137. }
  8138. catch(InvalidCastException)
  8139. {
  8140. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 13 must be vector", rulesParsed, idx - idxStart - 1));
  8141. return new LSL_List();
  8142. }
  8143. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8144. revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
  8145. break;
  8146. case ScriptBaseClass.PRIM_TYPE_TUBE:
  8147. if (remain < 11)
  8148. return new LSL_List();
  8149. try
  8150. {
  8151. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8152. }
  8153. catch(InvalidCastException)
  8154. {
  8155. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8156. return new LSL_List();
  8157. }
  8158. try
  8159. {
  8160. v = rules.GetVector3Item(idx++); //cut
  8161. }
  8162. catch(InvalidCastException)
  8163. {
  8164. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8165. return new LSL_List();
  8166. }
  8167. try
  8168. {
  8169. hollow = (float)rules.GetLSLFloatItem(idx++);
  8170. }
  8171. catch(InvalidCastException)
  8172. {
  8173. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8174. return new LSL_List();
  8175. }
  8176. try
  8177. {
  8178. twist = rules.GetVector3Item(idx++);
  8179. }
  8180. catch(InvalidCastException)
  8181. {
  8182. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8183. return new LSL_List();
  8184. }
  8185. try
  8186. {
  8187. holesize = rules.GetVector3Item(idx++);
  8188. }
  8189. catch(InvalidCastException)
  8190. {
  8191. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8192. return new LSL_List();
  8193. }
  8194. try
  8195. {
  8196. topshear = rules.GetVector3Item(idx++);
  8197. }
  8198. catch(InvalidCastException)
  8199. {
  8200. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8201. return new LSL_List();
  8202. }
  8203. try
  8204. {
  8205. profilecut = rules.GetVector3Item(idx++);
  8206. }
  8207. catch(InvalidCastException)
  8208. {
  8209. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8210. return new LSL_List();
  8211. }
  8212. try
  8213. {
  8214. taper_b = rules.GetVector3Item(idx++); // taper_a
  8215. }
  8216. catch(InvalidCastException)
  8217. {
  8218. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8219. return new LSL_List();
  8220. }
  8221. try
  8222. {
  8223. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8224. }
  8225. catch(InvalidCastException)
  8226. {
  8227. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8228. return new LSL_List();
  8229. }
  8230. try
  8231. {
  8232. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8233. }
  8234. catch(InvalidCastException)
  8235. {
  8236. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8237. return new LSL_List();
  8238. }
  8239. try
  8240. {
  8241. skew = (float)rules.GetLSLFloatItem(idx++);
  8242. }
  8243. catch(InvalidCastException)
  8244. {
  8245. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8246. return new LSL_List();
  8247. }
  8248. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8249. revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
  8250. break;
  8251. case ScriptBaseClass.PRIM_TYPE_RING:
  8252. if (remain < 11)
  8253. return new LSL_List();
  8254. try
  8255. {
  8256. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8257. }
  8258. catch(InvalidCastException)
  8259. {
  8260. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8261. return new LSL_List();
  8262. }
  8263. try
  8264. {
  8265. v = rules.GetVector3Item(idx++); //cut
  8266. }
  8267. catch(InvalidCastException)
  8268. {
  8269. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8270. return new LSL_List();
  8271. }
  8272. try
  8273. {
  8274. hollow = (float)rules.GetLSLFloatItem(idx++);
  8275. }
  8276. catch(InvalidCastException)
  8277. {
  8278. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8279. return new LSL_List();
  8280. }
  8281. try
  8282. {
  8283. twist = rules.GetVector3Item(idx++);
  8284. }
  8285. catch(InvalidCastException)
  8286. {
  8287. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8288. return new LSL_List();
  8289. }
  8290. try
  8291. {
  8292. holesize = rules.GetVector3Item(idx++);
  8293. }
  8294. catch(InvalidCastException)
  8295. {
  8296. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8297. return new LSL_List();
  8298. }
  8299. try
  8300. {
  8301. topshear = rules.GetVector3Item(idx++);
  8302. }
  8303. catch(InvalidCastException)
  8304. {
  8305. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8306. return new LSL_List();
  8307. }
  8308. try
  8309. {
  8310. profilecut = rules.GetVector3Item(idx++);
  8311. }
  8312. catch(InvalidCastException)
  8313. {
  8314. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8315. return new LSL_List();
  8316. }
  8317. try
  8318. {
  8319. taper_b = rules.GetVector3Item(idx++); // taper_a
  8320. }
  8321. catch(InvalidCastException)
  8322. {
  8323. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8324. return new LSL_List();
  8325. }
  8326. try
  8327. {
  8328. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8329. }
  8330. catch(InvalidCastException)
  8331. {
  8332. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8333. return new LSL_List();
  8334. }
  8335. try
  8336. {
  8337. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8338. }
  8339. catch(InvalidCastException)
  8340. {
  8341. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8342. return new LSL_List();
  8343. }
  8344. try
  8345. {
  8346. skew = (float)rules.GetLSLFloatItem(idx++);
  8347. }
  8348. catch(InvalidCastException)
  8349. {
  8350. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8351. return new LSL_List();
  8352. }
  8353. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8354. revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
  8355. break;
  8356. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  8357. if (remain < 2)
  8358. return new LSL_List();
  8359. string map = rules.Data[idx++].ToString();
  8360. try
  8361. {
  8362. face = (int)rules.GetLSLIntegerItem(idx++); // type
  8363. }
  8364. catch(InvalidCastException)
  8365. {
  8366. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SCULPT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8367. return new LSL_List();
  8368. }
  8369. SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
  8370. break;
  8371. }
  8372. break;
  8373. case ScriptBaseClass.PRIM_TEXTURE:
  8374. if (remain < 5)
  8375. return new LSL_List();
  8376. face=(int)rules.GetLSLIntegerItem(idx++);
  8377. string tex;
  8378. LSL_Vector repeats;
  8379. LSL_Vector offsets;
  8380. double rotation;
  8381. tex = rules.Data[idx++].ToString();
  8382. try
  8383. {
  8384. repeats = rules.GetVector3Item(idx++);
  8385. }
  8386. catch(InvalidCastException)
  8387. {
  8388. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8389. return new LSL_List();
  8390. }
  8391. try
  8392. {
  8393. offsets = rules.GetVector3Item(idx++);
  8394. }
  8395. catch(InvalidCastException)
  8396. {
  8397. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8398. return new LSL_List();
  8399. }
  8400. try
  8401. {
  8402. rotation = (double)rules.GetLSLFloatItem(idx++);
  8403. }
  8404. catch(InvalidCastException)
  8405. {
  8406. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8407. return new LSL_List();
  8408. }
  8409. SetTextureParams(part, tex, repeats.x, repeats.y, offsets.x, offsets.y, rotation, face);
  8410. break;
  8411. case ScriptBaseClass.PRIM_COLOR:
  8412. if (remain < 3)
  8413. return new LSL_List();
  8414. LSL_Vector color;
  8415. double alpha;
  8416. try
  8417. {
  8418. face = (int)rules.GetLSLIntegerItem(idx++);
  8419. }
  8420. catch(InvalidCastException)
  8421. {
  8422. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8423. return new LSL_List();
  8424. }
  8425. try
  8426. {
  8427. color = rules.GetVector3Item(idx++);
  8428. }
  8429. catch(InvalidCastException)
  8430. {
  8431. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8432. return new LSL_List();
  8433. }
  8434. try
  8435. {
  8436. alpha = (double)rules.GetLSLFloatItem(idx++);
  8437. }
  8438. catch(InvalidCastException)
  8439. {
  8440. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8441. return new LSL_List();
  8442. }
  8443. part.SetFaceColorAlpha(face, color, alpha);
  8444. break;
  8445. case ScriptBaseClass.PRIM_FLEXIBLE:
  8446. if (remain < 7)
  8447. return new LSL_List();
  8448. bool flexi;
  8449. int softness;
  8450. float gravity;
  8451. float friction;
  8452. float wind;
  8453. float tension;
  8454. LSL_Vector force;
  8455. try
  8456. {
  8457. flexi = rules.GetLSLIntegerItem(idx++);
  8458. }
  8459. catch(InvalidCastException)
  8460. {
  8461. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8462. return new LSL_List();
  8463. }
  8464. try
  8465. {
  8466. softness = rules.GetLSLIntegerItem(idx++);
  8467. }
  8468. catch(InvalidCastException)
  8469. {
  8470. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8471. return new LSL_List();
  8472. }
  8473. try
  8474. {
  8475. gravity = (float)rules.GetLSLFloatItem(idx++);
  8476. }
  8477. catch(InvalidCastException)
  8478. {
  8479. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8480. return new LSL_List();
  8481. }
  8482. try
  8483. {
  8484. friction = (float)rules.GetLSLFloatItem(idx++);
  8485. }
  8486. catch(InvalidCastException)
  8487. {
  8488. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8489. return new LSL_List();
  8490. }
  8491. try
  8492. {
  8493. wind = (float)rules.GetLSLFloatItem(idx++);
  8494. }
  8495. catch(InvalidCastException)
  8496. {
  8497. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8498. return new LSL_List();
  8499. }
  8500. try
  8501. {
  8502. tension = (float)rules.GetLSLFloatItem(idx++);
  8503. }
  8504. catch(InvalidCastException)
  8505. {
  8506. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 7 must be float", rulesParsed, idx - idxStart - 1));
  8507. return new LSL_List();
  8508. }
  8509. try
  8510. {
  8511. force = rules.GetVector3Item(idx++);
  8512. }
  8513. catch(InvalidCastException)
  8514. {
  8515. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8516. return new LSL_List();
  8517. }
  8518. SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);
  8519. break;
  8520. case ScriptBaseClass.PRIM_POINT_LIGHT:
  8521. if (remain < 5)
  8522. return new LSL_List();
  8523. bool light;
  8524. LSL_Vector lightcolor;
  8525. float intensity;
  8526. float radius;
  8527. float falloff;
  8528. try
  8529. {
  8530. light = rules.GetLSLIntegerItem(idx++);
  8531. }
  8532. catch(InvalidCastException)
  8533. {
  8534. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8535. return new LSL_List();
  8536. }
  8537. try
  8538. {
  8539. lightcolor = rules.GetVector3Item(idx++);
  8540. }
  8541. catch(InvalidCastException)
  8542. {
  8543. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8544. return new LSL_List();
  8545. }
  8546. try
  8547. {
  8548. intensity = (float)rules.GetLSLFloatItem(idx++);
  8549. }
  8550. catch(InvalidCastException)
  8551. {
  8552. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8553. return new LSL_List();
  8554. }
  8555. try
  8556. {
  8557. radius = (float)rules.GetLSLFloatItem(idx++);
  8558. }
  8559. catch(InvalidCastException)
  8560. {
  8561. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8562. return new LSL_List();
  8563. }
  8564. try
  8565. {
  8566. falloff = (float)rules.GetLSLFloatItem(idx++);
  8567. }
  8568. catch(InvalidCastException)
  8569. {
  8570. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8571. return new LSL_List();
  8572. }
  8573. SetPointLight(part, light, lightcolor, intensity, radius, falloff);
  8574. break;
  8575. case ScriptBaseClass.PRIM_GLOW:
  8576. if (remain < 2)
  8577. return new LSL_List();
  8578. float glow;
  8579. try
  8580. {
  8581. face = rules.GetLSLIntegerItem(idx++);
  8582. }
  8583. catch(InvalidCastException)
  8584. {
  8585. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8586. return new LSL_List();
  8587. }
  8588. try
  8589. {
  8590. glow = (float)rules.GetLSLFloatItem(idx++);
  8591. }
  8592. catch(InvalidCastException)
  8593. {
  8594. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8595. return new LSL_List();
  8596. }
  8597. SetGlow(part, face, glow);
  8598. break;
  8599. case ScriptBaseClass.PRIM_BUMP_SHINY:
  8600. if (remain < 3)
  8601. return new LSL_List();
  8602. int shiny;
  8603. Bumpiness bump;
  8604. try
  8605. {
  8606. face = (int)rules.GetLSLIntegerItem(idx++);
  8607. }
  8608. catch(InvalidCastException)
  8609. {
  8610. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8611. return new LSL_List();
  8612. }
  8613. try
  8614. {
  8615. shiny = (int)rules.GetLSLIntegerItem(idx++);
  8616. }
  8617. catch(InvalidCastException)
  8618. {
  8619. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8620. return new LSL_List();
  8621. }
  8622. try
  8623. {
  8624. bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
  8625. }
  8626. catch(InvalidCastException)
  8627. {
  8628. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8629. return new LSL_List();
  8630. }
  8631. SetShiny(part, face, shiny, bump);
  8632. break;
  8633. case ScriptBaseClass.PRIM_FULLBRIGHT:
  8634. if (remain < 2)
  8635. return new LSL_List();
  8636. bool st;
  8637. try
  8638. {
  8639. face = rules.GetLSLIntegerItem(idx++);
  8640. }
  8641. catch(InvalidCastException)
  8642. {
  8643. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8644. return new LSL_List();
  8645. }
  8646. try
  8647. {
  8648. st = rules.GetLSLIntegerItem(idx++);
  8649. }
  8650. catch(InvalidCastException)
  8651. {
  8652. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8653. return new LSL_List();
  8654. }
  8655. SetFullBright(part, face , st);
  8656. break;
  8657. case ScriptBaseClass.PRIM_MATERIAL:
  8658. if (remain < 1)
  8659. return new LSL_List();
  8660. int mat;
  8661. try
  8662. {
  8663. mat = rules.GetLSLIntegerItem(idx++);
  8664. }
  8665. catch(InvalidCastException)
  8666. {
  8667. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_MATERIAL: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8668. return new LSL_List();
  8669. }
  8670. if (mat < 0 || mat > 7)
  8671. return new LSL_List();
  8672. part.Material = Convert.ToByte(mat);
  8673. break;
  8674. case ScriptBaseClass.PRIM_PHANTOM:
  8675. if (remain < 1)
  8676. return new LSL_List();
  8677. string ph = rules.Data[idx++].ToString();
  8678. part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));
  8679. break;
  8680. case ScriptBaseClass.PRIM_PHYSICS:
  8681. if (remain < 1)
  8682. return new LSL_List();
  8683. string phy = rules.Data[idx++].ToString();
  8684. part.ScriptSetPhysicsStatus(phy.Equals("1"));
  8685. break;
  8686. case ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  8687. if (remain < 1)
  8688. return new LSL_List();
  8689. int shape_type;
  8690. try
  8691. {
  8692. shape_type = rules.GetLSLIntegerItem(idx++);
  8693. }
  8694. catch(InvalidCastException)
  8695. {
  8696. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_PHYSICS_SHAPE_TYPE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8697. return new LSL_List();
  8698. }
  8699. ExtraPhysicsData physdata = new ExtraPhysicsData();
  8700. physdata.Density = part.Density;
  8701. physdata.Bounce = part.Restitution;
  8702. physdata.GravitationModifier = part.GravityModifier;
  8703. physdata.PhysShapeType = (PhysShapeType)shape_type;
  8704. part.UpdateExtraPhysics(physdata);
  8705. break;
  8706. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  8707. if (remain < 5)
  8708. return new LSL_List();
  8709. int material_bits = rules.GetLSLIntegerItem(idx++);
  8710. float material_density = (float)rules.GetLSLFloatItem(idx++);
  8711. float material_friction = (float)rules.GetLSLFloatItem(idx++);
  8712. float material_restitution = (float)rules.GetLSLFloatItem(idx++);
  8713. float material_gravity_modifier = (float)rules.GetLSLFloatItem(idx++);
  8714. SetPhysicsMaterial(part, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
  8715. break;
  8716. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  8717. if (remain < 1)
  8718. return new LSL_List();
  8719. string temp = rules.Data[idx++].ToString();
  8720. part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));
  8721. break;
  8722. case ScriptBaseClass.PRIM_TEXGEN:
  8723. if (remain < 2)
  8724. return new LSL_List();
  8725. //face,type
  8726. int style;
  8727. try
  8728. {
  8729. face = rules.GetLSLIntegerItem(idx++);
  8730. }
  8731. catch(InvalidCastException)
  8732. {
  8733. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8734. return new LSL_List();
  8735. }
  8736. try
  8737. {
  8738. style = rules.GetLSLIntegerItem(idx++);
  8739. }
  8740. catch(InvalidCastException)
  8741. {
  8742. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8743. return new LSL_List();
  8744. }
  8745. SetTexGen(part, face, style);
  8746. break;
  8747. case ScriptBaseClass.PRIM_TEXT:
  8748. if (remain < 3)
  8749. return new LSL_List();
  8750. string primText;
  8751. LSL_Vector primTextColor;
  8752. LSL_Float primTextAlpha;
  8753. try
  8754. {
  8755. primText = rules.GetLSLStringItem(idx++);
  8756. }
  8757. catch(InvalidCastException)
  8758. {
  8759. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8760. return new LSL_List();
  8761. }
  8762. try
  8763. {
  8764. primTextColor = rules.GetVector3Item(idx++);
  8765. }
  8766. catch(InvalidCastException)
  8767. {
  8768. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8769. return new LSL_List();
  8770. }
  8771. try
  8772. {
  8773. primTextAlpha = rules.GetLSLFloatItem(idx++);
  8774. }
  8775. catch(InvalidCastException)
  8776. {
  8777. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8778. return new LSL_List();
  8779. }
  8780. Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
  8781. part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
  8782. break;
  8783. case ScriptBaseClass.PRIM_NAME:
  8784. if (remain < 1)
  8785. return new LSL_List();
  8786. try
  8787. {
  8788. string primName = rules.GetLSLStringItem(idx++);
  8789. part.Name = primName;
  8790. }
  8791. catch(InvalidCastException)
  8792. {
  8793. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NAME: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8794. return new LSL_List();
  8795. }
  8796. break;
  8797. case ScriptBaseClass.PRIM_DESC:
  8798. if (remain < 1)
  8799. return new LSL_List();
  8800. try
  8801. {
  8802. string primDesc = rules.GetLSLStringItem(idx++);
  8803. part.Description = primDesc;
  8804. }
  8805. catch(InvalidCastException)
  8806. {
  8807. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_DESC: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8808. return new LSL_List();
  8809. }
  8810. break;
  8811. case ScriptBaseClass.PRIM_ROT_LOCAL:
  8812. if (remain < 1)
  8813. return new LSL_List();
  8814. LSL_Rotation rot;
  8815. try
  8816. {
  8817. rot = rules.GetQuaternionItem(idx++);
  8818. }
  8819. catch(InvalidCastException)
  8820. {
  8821. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  8822. return new LSL_List();
  8823. }
  8824. SetRot(part, rot);
  8825. break;
  8826. case ScriptBaseClass.PRIM_OMEGA:
  8827. if (remain < 3)
  8828. return new LSL_List();
  8829. LSL_Vector axis;
  8830. LSL_Float spinrate;
  8831. LSL_Float gain;
  8832. try
  8833. {
  8834. axis = rules.GetVector3Item(idx++);
  8835. }
  8836. catch(InvalidCastException)
  8837. {
  8838. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8839. return new LSL_List();
  8840. }
  8841. try
  8842. {
  8843. spinrate = rules.GetLSLFloatItem(idx++);
  8844. }
  8845. catch(InvalidCastException)
  8846. {
  8847. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8848. return new LSL_List();
  8849. }
  8850. try
  8851. {
  8852. gain = rules.GetLSLFloatItem(idx++);
  8853. }
  8854. catch(InvalidCastException)
  8855. {
  8856. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8857. return new LSL_List();
  8858. }
  8859. TargetOmega(part, axis, (double)spinrate, (double)gain);
  8860. break;
  8861. case ScriptBaseClass.PRIM_SLICE:
  8862. if (remain < 1)
  8863. return new LSL_List();
  8864. LSL_Vector slice;
  8865. try
  8866. {
  8867. slice = rules.GetVector3Item(idx++);
  8868. }
  8869. catch(InvalidCastException)
  8870. {
  8871. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SLICE: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8872. return new LSL_List();
  8873. }
  8874. part.UpdateSlice((float)slice.x, (float)slice.y);
  8875. break;
  8876. case ScriptBaseClass.PRIM_SIT_TARGET:
  8877. if (remain < 3)
  8878. return new LSL_List();
  8879. int active;
  8880. try
  8881. {
  8882. active = rules.GetLSLIntegerItem(idx++);
  8883. }
  8884. catch(InvalidCastException)
  8885. {
  8886. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  8887. return new LSL_List();
  8888. }
  8889. LSL_Vector offset;
  8890. try
  8891. {
  8892. offset = rules.GetVector3Item(idx++);
  8893. }
  8894. catch(InvalidCastException)
  8895. {
  8896. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8897. return new LSL_List();
  8898. }
  8899. LSL_Rotation sitrot;
  8900. try
  8901. {
  8902. sitrot = rules.GetQuaternionItem(idx++);
  8903. }
  8904. catch(InvalidCastException)
  8905. {
  8906. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 3 must be rotation", rulesParsed, idx - idxStart - 1));
  8907. return new LSL_List();
  8908. }
  8909. // not SL compatible since we don't have a independent flag to control active target but use the values of offset and rotation
  8910. if(active == 1)
  8911. {
  8912. if(offset.x == 0 && offset.y == 0 && offset.z == 0 && sitrot.s == 1.0)
  8913. offset.z = 1e-5f; // hack
  8914. SitTarget(part,offset,sitrot);
  8915. }
  8916. else if(active == 0)
  8917. SitTarget(part, Vector3.Zero , Quaternion.Identity);
  8918. break;
  8919. case ScriptBaseClass.PRIM_ALPHA_MODE:
  8920. if (remain < 3)
  8921. return new LSL_List();
  8922. try
  8923. {
  8924. face = rules.GetLSLIntegerItem(idx++);
  8925. }
  8926. catch(InvalidCastException)
  8927. {
  8928. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8929. return new LSL_List();
  8930. }
  8931. int materialAlphaMode;
  8932. try
  8933. {
  8934. materialAlphaMode = rules.GetLSLIntegerItem(idx++);
  8935. }
  8936. catch(InvalidCastException)
  8937. {
  8938. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8939. return new LSL_List();
  8940. }
  8941. if(materialAlphaMode < 0 || materialAlphaMode > 3)
  8942. {
  8943. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 3", rulesParsed, idx - idxStart - 1));
  8944. return new LSL_List();
  8945. }
  8946. int materialMaskCutoff;
  8947. try
  8948. {
  8949. materialMaskCutoff = rules.GetLSLIntegerItem(idx++);
  8950. }
  8951. catch(InvalidCastException)
  8952. {
  8953. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8954. return new LSL_List();
  8955. }
  8956. if(materialMaskCutoff < 0 || materialMaskCutoff > 255)
  8957. {
  8958. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 255", rulesParsed, idx - idxStart - 1));
  8959. return new LSL_List();
  8960. }
  8961. materialChanged |= SetMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  8962. break;
  8963. case ScriptBaseClass.PRIM_NORMAL:
  8964. if (remain < 5)
  8965. return new LSL_List();
  8966. try
  8967. {
  8968. face = rules.GetLSLIntegerItem(idx++);
  8969. }
  8970. catch(InvalidCastException)
  8971. {
  8972. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8973. return new LSL_List();
  8974. }
  8975. string mapname = rules.Data[idx++].ToString();
  8976. UUID mapID = UUID.Zero;
  8977. if (!string.IsNullOrEmpty(mapname))
  8978. {
  8979. mapID = ScriptUtils.GetAssetIdFromItemName(m_host, mapname, (int)AssetType.Texture);
  8980. if (mapID == UUID.Zero)
  8981. {
  8982. if (!UUID.TryParse(mapname, out mapID))
  8983. {
  8984. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be a UUID or a texture name on object inventory", rulesParsed, idx - idxStart - 1));
  8985. return new LSL_List();
  8986. }
  8987. }
  8988. }
  8989. LSL_Vector mnrepeat;
  8990. try
  8991. {
  8992. mnrepeat = rules.GetVector3Item(idx++);
  8993. }
  8994. catch(InvalidCastException)
  8995. {
  8996. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  8997. return new LSL_List();
  8998. }
  8999. LSL_Vector mnoffset;
  9000. try
  9001. {
  9002. mnoffset = rules.GetVector3Item(idx++);
  9003. }
  9004. catch(InvalidCastException)
  9005. {
  9006. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9007. return new LSL_List();
  9008. }
  9009. LSL_Float mnrot;
  9010. try
  9011. {
  9012. mnrot = rules.GetLSLFloatItem(idx++);
  9013. }
  9014. catch(InvalidCastException)
  9015. {
  9016. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  9017. return new LSL_List();
  9018. }
  9019. float repeatX = (float)Util.Clamp(mnrepeat.x,-100.0, 100.0);
  9020. float repeatY = (float)Util.Clamp(mnrepeat.y,-100.0, 100.0);
  9021. float offsetX = (float)Util.Clamp(mnoffset.x, 0, 1.0);
  9022. float offsetY = (float)Util.Clamp(mnoffset.y, 0, 1.0);
  9023. materialChanged |= SetMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, (float)mnrot);
  9024. break;
  9025. case ScriptBaseClass.PRIM_SPECULAR:
  9026. if (remain < 8)
  9027. return new LSL_List();
  9028. try
  9029. {
  9030. face = rules.GetLSLIntegerItem(idx++);
  9031. }
  9032. catch(InvalidCastException)
  9033. {
  9034. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9035. return new LSL_List();
  9036. }
  9037. string smapname = rules.Data[idx++].ToString();
  9038. UUID smapID = UUID.Zero;
  9039. if(!string.IsNullOrEmpty(smapname))
  9040. {
  9041. smapID = ScriptUtils.GetAssetIdFromItemName(m_host, smapname, (int)AssetType.Texture);
  9042. if (smapID == UUID.Zero)
  9043. {
  9044. if (!UUID.TryParse(smapname, out smapID))
  9045. {
  9046. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be a UUID or a texture name on object inventory", rulesParsed, idx - idxStart - 1));
  9047. return new LSL_List();
  9048. }
  9049. }
  9050. }
  9051. LSL_Vector msrepeat;
  9052. try
  9053. {
  9054. msrepeat = rules.GetVector3Item(idx++);
  9055. }
  9056. catch(InvalidCastException)
  9057. {
  9058. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9059. return new LSL_List();
  9060. }
  9061. LSL_Vector msoffset;
  9062. try
  9063. {
  9064. msoffset = rules.GetVector3Item(idx++);
  9065. }
  9066. catch(InvalidCastException)
  9067. {
  9068. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9069. return new LSL_List();
  9070. }
  9071. LSL_Float msrot;
  9072. try
  9073. {
  9074. msrot = rules.GetLSLFloatItem(idx++);
  9075. }
  9076. catch(InvalidCastException)
  9077. {
  9078. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  9079. return new LSL_List();
  9080. }
  9081. LSL_Vector mscolor;
  9082. try
  9083. {
  9084. mscolor = rules.GetVector3Item(idx++);
  9085. }
  9086. catch(InvalidCastException)
  9087. {
  9088. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9089. return new LSL_List();
  9090. }
  9091. LSL_Integer msgloss;
  9092. try
  9093. {
  9094. msgloss = rules.GetLSLIntegerItem(idx++);
  9095. }
  9096. catch(InvalidCastException)
  9097. {
  9098. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9099. return new LSL_List();
  9100. }
  9101. LSL_Integer msenv;
  9102. try
  9103. {
  9104. msenv = rules.GetLSLIntegerItem(idx++);
  9105. }
  9106. catch(InvalidCastException)
  9107. {
  9108. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9109. return new LSL_List();
  9110. }
  9111. float srepeatX = (float)Util.Clamp(msrepeat.x, -100.0, 100.0);
  9112. float srepeatY = (float)Util.Clamp(msrepeat.y, -100.0, 100.0);
  9113. float soffsetX = (float)Util.Clamp(msoffset.x, -1.0, 1.0);
  9114. float soffsetY = (float)Util.Clamp(msoffset.y, -1.0, 1.0);
  9115. byte colorR = (byte)(255.0 * Util.Clamp(mscolor.x, 0, 1.0) + 0.5);
  9116. byte colorG = (byte)(255.0 * Util.Clamp(mscolor.y, 0, 1.0) + 0.5);
  9117. byte colorB = (byte)(255.0 * Util.Clamp(mscolor.z, 0, 1.0) + 0.5);
  9118. byte gloss = (byte)Util.Clamp((int)msgloss, 0, 255);
  9119. byte env = (byte)Util.Clamp((int)msenv, 0, 255);
  9120. materialChanged |= SetMaterialSpecMap(part, face, smapID, srepeatX, srepeatY, soffsetX, soffsetY,
  9121. (float)msrot, colorR, colorG, colorB, gloss, env);
  9122. break;
  9123. case ScriptBaseClass.PRIM_LINK_TARGET:
  9124. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9125. return new LSL_List();
  9126. return rules.GetSublist(idx, -1);
  9127. default:
  9128. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - unsupported parameter", rulesParsed, idx - idxStart));
  9129. return new LSL_List();
  9130. }
  9131. }
  9132. }
  9133. catch (InvalidCastException e)
  9134. {
  9135. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9136. }
  9137. finally
  9138. {
  9139. if (positionChanged)
  9140. {
  9141. if (part.ParentGroup.RootPart == part)
  9142. {
  9143. SceneObjectGroup parent = part.ParentGroup;
  9144. // Util.FireAndForget(delegate(object x) {
  9145. parent.UpdateGroupPosition(currentPosition);
  9146. // });
  9147. }
  9148. else
  9149. {
  9150. part.OffsetPosition = currentPosition;
  9151. // SceneObjectGroup parent = part.ParentGroup;
  9152. // parent.HasGroupChanged = true;
  9153. // parent.ScheduleGroupForTerseUpdate();
  9154. part.ScheduleTerseUpdate();
  9155. }
  9156. }
  9157. if(materialChanged)
  9158. {
  9159. if (part.ParentGroup != null && !part.ParentGroup.IsDeleted)
  9160. {
  9161. part.TriggerScriptChangedEvent(Changed.TEXTURE);
  9162. part.ScheduleFullUpdate();
  9163. part.ParentGroup.HasGroupChanged = true;
  9164. }
  9165. }
  9166. }
  9167. return new LSL_List();
  9168. }
  9169. protected bool SetMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9170. {
  9171. if(m_materialsModule == null)
  9172. return false;
  9173. int nsides = part.GetNumberOfSides();
  9174. if(face == ScriptBaseClass.ALL_SIDES)
  9175. {
  9176. bool changed = false;
  9177. for(int i = 0; i < nsides; i++)
  9178. changed |= SetFaceMaterialAlphaMode(part, i, materialAlphaMode, materialMaskCutoff);
  9179. return changed;
  9180. }
  9181. if( face >= 0 && face < nsides)
  9182. return SetFaceMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  9183. return false;
  9184. }
  9185. protected bool SetFaceMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9186. {
  9187. Primitive.TextureEntry tex = part.Shape.Textures;
  9188. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9189. if(texface == null)
  9190. return false;
  9191. FaceMaterial mat = null;
  9192. UUID oldid = texface.MaterialID;
  9193. if(oldid != UUID.Zero)
  9194. mat = m_materialsModule.GetMaterialCopy(oldid);
  9195. if(mat == null)
  9196. mat = new FaceMaterial();
  9197. mat.DiffuseAlphaMode = (byte)materialAlphaMode;
  9198. mat.AlphaMaskCutoff = (byte)materialMaskCutoff;
  9199. UUID id = m_materialsModule.AddNewMaterial(mat);
  9200. if(oldid == id)
  9201. return false;
  9202. texface.MaterialID = id;
  9203. part.Shape.TextureEntry = tex.GetBytes(9);
  9204. m_materialsModule.RemoveMaterial(oldid);
  9205. return true;
  9206. }
  9207. protected bool SetMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9208. float offsetX, float offsetY, float rot)
  9209. {
  9210. if(m_materialsModule == null)
  9211. return false;
  9212. int nsides = part.GetNumberOfSides();
  9213. if(face == ScriptBaseClass.ALL_SIDES)
  9214. {
  9215. bool changed = false;
  9216. for(int i = 0; i < nsides; i++)
  9217. changed |= SetFaceMaterialNormalMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9218. return changed;
  9219. }
  9220. if( face >= 0 && face < nsides)
  9221. return SetFaceMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9222. return false;
  9223. }
  9224. protected bool SetFaceMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9225. float offsetX, float offsetY, float rot)
  9226. {
  9227. Primitive.TextureEntry tex = part.Shape.Textures;
  9228. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9229. if(texface == null)
  9230. return false;
  9231. FaceMaterial mat = null;
  9232. UUID oldid = texface.MaterialID;
  9233. if(mapID != UUID.Zero)
  9234. {
  9235. if(oldid != UUID.Zero)
  9236. mat = m_materialsModule.GetMaterialCopy(oldid);
  9237. if(mat == null)
  9238. mat = new FaceMaterial();
  9239. mat.NormalMapID = mapID;
  9240. mat.NormalOffsetX = offsetX;
  9241. mat.NormalOffsetY = offsetY;
  9242. mat.NormalRepeatX = repeatX;
  9243. mat.NormalRepeatY = repeatY;
  9244. mat.NormalRotation = rot;
  9245. mapID = m_materialsModule.AddNewMaterial(mat);
  9246. }
  9247. if(oldid == mapID)
  9248. return false;
  9249. texface.MaterialID = mapID;
  9250. part.Shape.TextureEntry = tex.GetBytes(9);
  9251. m_materialsModule.RemoveMaterial(oldid);
  9252. return true;
  9253. }
  9254. protected bool SetMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9255. float offsetX, float offsetY, float rot,
  9256. byte colorR, byte colorG, byte colorB,
  9257. byte gloss, byte env)
  9258. {
  9259. if(m_materialsModule == null)
  9260. return false;
  9261. int nsides = part.GetNumberOfSides();
  9262. if(face == ScriptBaseClass.ALL_SIDES)
  9263. {
  9264. bool changed = false;
  9265. for(int i = 0; i < nsides; i++)
  9266. changed |= SetFaceMaterialSpecMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9267. colorR, colorG, colorB, gloss, env);
  9268. return changed;
  9269. }
  9270. if( face >= 0 && face < nsides)
  9271. return SetFaceMaterialSpecMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9272. colorR, colorG, colorB, gloss, env);
  9273. return false;
  9274. }
  9275. protected bool SetFaceMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9276. float offsetX, float offsetY, float rot,
  9277. byte colorR, byte colorG, byte colorB,
  9278. byte gloss, byte env)
  9279. {
  9280. Primitive.TextureEntry tex = part.Shape.Textures;
  9281. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9282. if(texface == null)
  9283. return false;
  9284. FaceMaterial mat = null;
  9285. UUID oldid = texface.MaterialID;
  9286. if (mapID != UUID.Zero)
  9287. {
  9288. if (oldid != UUID.Zero)
  9289. mat = m_materialsModule.GetMaterialCopy(oldid);
  9290. if (mat == null)
  9291. mat = new FaceMaterial();
  9292. mat.SpecularMapID = mapID;
  9293. mat.SpecularOffsetX = offsetX;
  9294. mat.SpecularOffsetY = offsetY;
  9295. mat.SpecularRepeatX = repeatX;
  9296. mat.SpecularRepeatY = repeatY;
  9297. mat.SpecularRotation = rot;
  9298. mat.SpecularLightColorR = colorR;
  9299. mat.SpecularLightColorG = colorG;
  9300. mat.SpecularLightColorB = colorB;
  9301. mat.SpecularLightExponent = gloss;
  9302. mat.EnvironmentIntensity = env;
  9303. mapID = m_materialsModule.AddNewMaterial(mat);
  9304. }
  9305. if(oldid == mapID)
  9306. return false;
  9307. texface.MaterialID = mapID;
  9308. part.Shape.TextureEntry = tex.GetBytes(9);
  9309. m_materialsModule.RemoveMaterial(oldid);
  9310. return true;
  9311. }
  9312. protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed)
  9313. {
  9314. int idx = 0;
  9315. int idxStart = 0;
  9316. try
  9317. {
  9318. while (idx < rules.Length)
  9319. {
  9320. ++rulesParsed;
  9321. int code = rules.GetLSLIntegerItem(idx++);
  9322. int remain = rules.Length - idx;
  9323. idxStart = idx;
  9324. switch (code)
  9325. {
  9326. case ScriptBaseClass.PRIM_POSITION:
  9327. case ScriptBaseClass.PRIM_POS_LOCAL:
  9328. if (remain < 1)
  9329. return new LSL_List();
  9330. try
  9331. {
  9332. sp.OffsetPosition = rules.GetVector3Item(idx++);
  9333. }
  9334. catch(InvalidCastException)
  9335. {
  9336. if (code == ScriptBaseClass.PRIM_POSITION)
  9337. {
  9338. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9339. }
  9340. else
  9341. {
  9342. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9343. }
  9344. return new LSL_List();
  9345. }
  9346. break;
  9347. case ScriptBaseClass.PRIM_ROTATION:
  9348. if (remain < 1)
  9349. return new LSL_List();
  9350. Quaternion inRot;
  9351. try
  9352. {
  9353. inRot = rules.GetQuaternionItem(idx++);
  9354. }
  9355. catch(InvalidCastException)
  9356. {
  9357. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9358. return new LSL_List();
  9359. }
  9360. SceneObjectPart parentPart = sp.ParentPart;
  9361. if (parentPart != null)
  9362. sp.Rotation = m_host.GetWorldRotation() * inRot;
  9363. break;
  9364. case ScriptBaseClass.PRIM_ROT_LOCAL:
  9365. if (remain < 1)
  9366. return new LSL_List();
  9367. try
  9368. {
  9369. sp.Rotation = rules.GetQuaternionItem(idx++);
  9370. }
  9371. catch(InvalidCastException)
  9372. {
  9373. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9374. return new LSL_List();
  9375. }
  9376. break;
  9377. case ScriptBaseClass.PRIM_TYPE:
  9378. Error(originFunc, "PRIM_TYPE disallowed on agent");
  9379. return new LSL_List();
  9380. case ScriptBaseClass.PRIM_OMEGA:
  9381. Error(originFunc, "PRIM_OMEGA disallowed on agent");
  9382. return new LSL_List();
  9383. case ScriptBaseClass.PRIM_LINK_TARGET:
  9384. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9385. return new LSL_List();
  9386. return rules.GetSublist(idx, -1);
  9387. default:
  9388. Error(originFunc,
  9389. string.Format("Error running rule #{0} on agent: arg #{1} - disallowed on agent", rulesParsed, idx - idxStart));
  9390. return new LSL_List();
  9391. }
  9392. }
  9393. }
  9394. catch (InvalidCastException e)
  9395. {
  9396. Error(
  9397. originFunc,
  9398. string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9399. }
  9400. return new LSL_List();
  9401. }
  9402. public LSL_String llStringToBase64(string str)
  9403. {
  9404. m_host.AddScriptLPS(1);
  9405. try
  9406. {
  9407. byte[] encData_byte;
  9408. encData_byte = Util.UTF8.GetBytes(str);
  9409. string encodedData = Convert.ToBase64String(encData_byte);
  9410. return encodedData;
  9411. }
  9412. catch
  9413. {
  9414. Error("llBase64ToString", "Error encoding string");
  9415. return String.Empty;
  9416. }
  9417. }
  9418. public LSL_String llBase64ToString(string str)
  9419. {
  9420. m_host.AddScriptLPS(1);
  9421. try
  9422. {
  9423. byte[] b = Convert.FromBase64String(str);
  9424. return Encoding.UTF8.GetString(b);
  9425. }
  9426. catch
  9427. {
  9428. Error("llBase64ToString", "Error decoding string");
  9429. return String.Empty;
  9430. }
  9431. }
  9432. public LSL_String llXorBase64Strings(string str1, string str2)
  9433. {
  9434. int padding = 0;
  9435. string b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  9436. ScriptSleep(300);
  9437. m_host.AddScriptLPS(1);
  9438. if (str1 == String.Empty)
  9439. return String.Empty;
  9440. if (str2 == String.Empty)
  9441. return str1;
  9442. int len = str2.Length;
  9443. if ((len % 4) != 0) // LL is EVIL!!!!
  9444. {
  9445. while (str2.EndsWith("="))
  9446. str2 = str2.Substring(0, str2.Length - 1);
  9447. len = str2.Length;
  9448. int mod = len % 4;
  9449. if (mod == 1)
  9450. str2 = str2.Substring(0, str2.Length - 1);
  9451. else if (mod == 2)
  9452. str2 += "==";
  9453. else if (mod == 3)
  9454. str2 += "=";
  9455. }
  9456. byte[] data1;
  9457. byte[] data2;
  9458. try
  9459. {
  9460. data1 = Convert.FromBase64String(str1);
  9461. data2 = Convert.FromBase64String(str2);
  9462. }
  9463. catch (Exception)
  9464. {
  9465. return new LSL_String(String.Empty);
  9466. }
  9467. // For cases where the decoded length of s2 is greater
  9468. // than the decoded length of s1, simply perform a normal
  9469. // decode and XOR
  9470. //
  9471. /*
  9472. if (data2.Length >= data1.Length)
  9473. {
  9474. for (int pos = 0 ; pos < data1.Length ; pos++ )
  9475. data1[pos] ^= data2[pos];
  9476. return Convert.ToBase64String(data1);
  9477. }
  9478. */
  9479. // Remove padding
  9480. while (str1.EndsWith("="))
  9481. {
  9482. str1 = str1.Substring(0, str1.Length - 1);
  9483. padding++;
  9484. }
  9485. while (str2.EndsWith("="))
  9486. str2 = str2.Substring(0, str2.Length - 1);
  9487. byte[] d1 = new byte[str1.Length];
  9488. byte[] d2 = new byte[str2.Length];
  9489. for (int i = 0 ; i < str1.Length ; i++)
  9490. {
  9491. int idx = b64.IndexOf(str1.Substring(i, 1));
  9492. if (idx == -1)
  9493. idx = 0;
  9494. d1[i] = (byte)idx;
  9495. }
  9496. for (int i = 0 ; i < str2.Length ; i++)
  9497. {
  9498. int idx = b64.IndexOf(str2.Substring(i, 1));
  9499. if (idx == -1)
  9500. idx = 0;
  9501. d2[i] = (byte)idx;
  9502. }
  9503. string output = String.Empty;
  9504. for (int pos = 0 ; pos < d1.Length ; pos++)
  9505. output += b64[d1[pos] ^ d2[pos % d2.Length]];
  9506. // Here's a funny thing: LL blithely violate the base64
  9507. // standard pretty much everywhere. Here, padding is
  9508. // added only if the first input string had it, rather
  9509. // than when the data actually needs it. This can result
  9510. // in invalid base64 being returned. Go figure.
  9511. while (padding-- > 0)
  9512. output += "=";
  9513. return output;
  9514. }
  9515. public void llRemoteDataSetRegion()
  9516. {
  9517. m_host.AddScriptLPS(1);
  9518. Deprecated("llRemoteDataSetRegion", "Use llOpenRemoteDataChannel instead");
  9519. }
  9520. public LSL_Float llLog10(double val)
  9521. {
  9522. m_host.AddScriptLPS(1);
  9523. return (double)Math.Log10(val);
  9524. }
  9525. public LSL_Float llLog(double val)
  9526. {
  9527. m_host.AddScriptLPS(1);
  9528. return (double)Math.Log(val);
  9529. }
  9530. public LSL_List llGetAnimationList(LSL_Key id)
  9531. {
  9532. m_host.AddScriptLPS(1);
  9533. UUID avID;
  9534. if(!UUID.TryParse(id, out avID))
  9535. return new LSL_List();
  9536. ScenePresence av = World.GetScenePresence(avID);
  9537. if (av == null || av.IsChildAgent) // only if in the region
  9538. return new LSL_List();
  9539. UUID[] anims;
  9540. anims = av.Animator.GetAnimationArray();
  9541. LSL_List l = new LSL_List();
  9542. foreach (UUID foo in anims)
  9543. l.Add(new LSL_Key(foo.ToString()));
  9544. return l;
  9545. }
  9546. public void llSetParcelMusicURL(string url)
  9547. {
  9548. m_host.AddScriptLPS(1);
  9549. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9550. if (land.LandData.OwnerID != m_host.OwnerID)
  9551. return;
  9552. land.SetMusicUrl(url);
  9553. ScriptSleep(m_sleepMsOnSetParcelMusicURL);
  9554. }
  9555. public LSL_String llGetParcelMusicURL()
  9556. {
  9557. m_host.AddScriptLPS(1);
  9558. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9559. if (land.LandData.OwnerID != m_host.OwnerID)
  9560. return String.Empty;
  9561. return land.GetMusicUrl();
  9562. }
  9563. public LSL_Vector llGetRootPosition()
  9564. {
  9565. m_host.AddScriptLPS(1);
  9566. return new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  9567. }
  9568. /// <summary>
  9569. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetRot
  9570. /// http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  9571. /// Also tested in sl in regards to the behaviour in attachments/mouselook
  9572. /// In the root prim:-
  9573. /// Returns the object rotation if not attached
  9574. /// Returns the avatars rotation if attached
  9575. /// Returns the camera rotation if attached and the avatar is in mouselook
  9576. /// </summary>
  9577. public LSL_Rotation llGetRootRotation()
  9578. {
  9579. m_host.AddScriptLPS(1);
  9580. Quaternion q;
  9581. if (m_host.ParentGroup.AttachmentPoint != 0)
  9582. {
  9583. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  9584. if (avatar != null)
  9585. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  9586. q = avatar.CameraRotation; // Mouselook
  9587. else
  9588. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  9589. else
  9590. q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case
  9591. }
  9592. else
  9593. q = m_host.ParentGroup.GroupRotation; // just the group rotation
  9594. return new LSL_Rotation(q);
  9595. }
  9596. public LSL_String llGetObjectDesc()
  9597. {
  9598. return m_host.Description!=null?m_host.Description:String.Empty;
  9599. }
  9600. public void llSetObjectDesc(string desc)
  9601. {
  9602. m_host.AddScriptLPS(1);
  9603. m_host.Description = desc!=null?desc:String.Empty;
  9604. }
  9605. public LSL_Key llGetCreator()
  9606. {
  9607. m_host.AddScriptLPS(1);
  9608. return m_host.CreatorID.ToString();
  9609. }
  9610. public LSL_String llGetTimestamp()
  9611. {
  9612. m_host.AddScriptLPS(1);
  9613. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  9614. }
  9615. public LSL_Integer llGetNumberOfPrims()
  9616. {
  9617. m_host.AddScriptLPS(1);
  9618. return m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount();
  9619. }
  9620. /// <summary>
  9621. /// Full implementation of llGetBoundingBox according to SL 2015-04-15.
  9622. /// http://wiki.secondlife.com/wiki/LlGetBoundingBox
  9623. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
  9624. /// Returns local bounding box of avatar without attachments
  9625. /// if target is non-seated avatar or prim/mesh in avatar attachment.
  9626. /// Returns local bounding box of object including seated avatars
  9627. /// if target is seated avatar or prim/mesh in object.
  9628. /// Uses meshing of prims for high accuracy
  9629. /// or less accurate box models for speed.
  9630. /// </summary>
  9631. public LSL_List llGetBoundingBox(string obj)
  9632. {
  9633. m_host.AddScriptLPS(1);
  9634. UUID objID = UUID.Zero;
  9635. LSL_List result = new LSL_List();
  9636. // If the ID is not valid, return null result
  9637. if (!UUID.TryParse(obj, out objID))
  9638. {
  9639. result.Add(new LSL_Vector());
  9640. result.Add(new LSL_Vector());
  9641. return result;
  9642. }
  9643. // Check if this is an attached prim. If so, replace
  9644. // the UUID with the avatar UUID and report it's bounding box
  9645. SceneObjectPart part = World.GetSceneObjectPart(objID);
  9646. if (part != null && part.ParentGroup.IsAttachment)
  9647. objID = part.ParentGroup.AttachedAvatar;
  9648. // Find out if this is an avatar ID. If so, return it's box
  9649. ScenePresence presence = World.GetScenePresence(objID);
  9650. if (presence != null)
  9651. {
  9652. // As per LSL Wiki, there is no difference between sitting
  9653. // and standing avatar since server 1.36
  9654. LSL_Vector lower;
  9655. LSL_Vector upper;
  9656. Vector3 box = presence.Appearance.AvatarBoxSize * 0.5f;
  9657. if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
  9658. == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  9659. /*
  9660. {
  9661. // This is for ground sitting avatars
  9662. float height = presence.Appearance.AvatarHeight / 2.66666667f;
  9663. lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
  9664. upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
  9665. }
  9666. else
  9667. {
  9668. // This is for standing/flying avatars
  9669. float height = presence.Appearance.AvatarHeight / 2.0f;
  9670. lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
  9671. upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
  9672. }
  9673. // Adjust to the documented error offsets (see LSL Wiki)
  9674. lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
  9675. upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
  9676. */
  9677. {
  9678. // This is for ground sitting avatars TODO!
  9679. lower = new LSL_Vector(-box.X - 0.1125, -box.Y, box.Z * -1.0f);
  9680. upper = new LSL_Vector(box.X + 0.1125, box.Y, box.Z * -1.0f);
  9681. }
  9682. else
  9683. {
  9684. // This is for standing/flying avatars
  9685. lower = new LSL_Vector(-box.X, -box.Y, -box.Z);
  9686. upper = new LSL_Vector(box.X, box.Y, box.Z);
  9687. }
  9688. if (lower.x > upper.x)
  9689. lower.x = upper.x;
  9690. if (lower.y > upper.y)
  9691. lower.y = upper.y;
  9692. if (lower.z > upper.z)
  9693. lower.z = upper.z;
  9694. result.Add(lower);
  9695. result.Add(upper);
  9696. return result;
  9697. }
  9698. part = World.GetSceneObjectPart(objID);
  9699. // Currently only works for single prims without a sitting avatar
  9700. if (part == null)
  9701. {
  9702. result.Add(new LSL_Vector());
  9703. result.Add(new LSL_Vector());
  9704. return result;
  9705. }
  9706. SceneObjectGroup sog = part.ParentGroup;
  9707. if(sog.IsDeleted)
  9708. {
  9709. result.Add(new LSL_Vector());
  9710. result.Add(new LSL_Vector());
  9711. return result;
  9712. }
  9713. float minX;
  9714. float maxX;
  9715. float minY;
  9716. float maxY;
  9717. float minZ;
  9718. float maxZ;
  9719. sog.GetBoundingBox(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  9720. result.Add(new LSL_Vector(minX, minY, minZ));
  9721. result.Add(new LSL_Vector(maxX, maxY, maxZ));
  9722. return result;
  9723. }
  9724. /// <summary>
  9725. /// Helper to calculate bounding box of an avatar.
  9726. /// </summary>
  9727. private void BoundingBoxOfScenePresence(ScenePresence sp, out Vector3 lower, out Vector3 upper)
  9728. {
  9729. // Adjust from OS model
  9730. // avatar height = visual height - 0.2, bounding box height = visual height
  9731. // to SL model
  9732. // avatar height = visual height, bounding box height = visual height + 0.2
  9733. float height = sp.Appearance.AvatarHeight + m_avatarHeightCorrection;
  9734. // According to avatar bounding box in SL 2015-04-18:
  9735. // standing = <-0.275,-0.35,-0.1-0.5*h> : <0.275,0.35,0.1+0.5*h>
  9736. // groundsitting = <-0.3875,-0.5,-0.05-0.375*h> : <0.3875,0.5,0.5>
  9737. // sitting = <-0.5875,-0.35,-0.35-0.375*h> : <0.1875,0.35,-0.25+0.25*h>
  9738. // When avatar is sitting
  9739. if (sp.ParentPart != null)
  9740. {
  9741. lower = new Vector3(m_lABB1SitX0, m_lABB1SitY0, m_lABB1SitZ0 + m_lABB1SitZ1 * height);
  9742. upper = new Vector3(m_lABB2SitX0, m_lABB2SitY0, m_lABB2SitZ0 + m_lABB2SitZ1 * height);
  9743. }
  9744. // When avatar is groundsitting
  9745. else if (sp.Animator.Animations.ImplicitDefaultAnimation.AnimID == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  9746. {
  9747. lower = new Vector3(m_lABB1GrsX0, m_lABB1GrsY0, m_lABB1GrsZ0 + m_lABB1GrsZ1 * height);
  9748. upper = new Vector3(m_lABB2GrsX0, m_lABB2GrsY0, m_lABB2GrsZ0 + m_lABB2GrsZ1 * height);
  9749. }
  9750. // When avatar is standing or flying
  9751. else
  9752. {
  9753. lower = new Vector3(m_lABB1StdX0, m_lABB1StdY0, m_lABB1StdZ0 + m_lABB1StdZ1 * height);
  9754. upper = new Vector3(m_lABB2StdX0, m_lABB2StdY0, m_lABB2StdZ0 + m_lABB2StdZ1 * height);
  9755. }
  9756. }
  9757. public LSL_Vector llGetGeometricCenter()
  9758. {
  9759. return new LSL_Vector(m_host.GetGeometricCenter());
  9760. }
  9761. public LSL_List llGetPrimitiveParams(LSL_List rules)
  9762. {
  9763. m_host.AddScriptLPS(1);
  9764. LSL_List result = new LSL_List();
  9765. LSL_List remaining = GetPrimParams(m_host, rules, ref result);
  9766. while ((object)remaining != null && remaining.Length > 1)
  9767. {
  9768. int linknumber = remaining.GetLSLIntegerItem(0);
  9769. rules = remaining.GetSublist(1, -1);
  9770. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  9771. if(parts.Count == 0)
  9772. break;
  9773. foreach (SceneObjectPart part in parts)
  9774. remaining = GetPrimParams(part, rules, ref result);
  9775. }
  9776. return result;
  9777. }
  9778. public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  9779. {
  9780. m_host.AddScriptLPS(1);
  9781. // acording to SL wiki this must indicate a single link number or link_root or link_this.
  9782. // keep other options as before
  9783. List<SceneObjectPart> parts;
  9784. List<ScenePresence> avatars;
  9785. LSL_List res = new LSL_List();
  9786. LSL_List remaining = new LSL_List();
  9787. while (rules.Length > 0)
  9788. {
  9789. parts = GetLinkParts(linknumber);
  9790. avatars = GetLinkAvatars(linknumber);
  9791. remaining = new LSL_List();
  9792. foreach (SceneObjectPart part in parts)
  9793. {
  9794. remaining = GetPrimParams(part, rules, ref res);
  9795. }
  9796. foreach (ScenePresence avatar in avatars)
  9797. {
  9798. remaining = GetPrimParams(avatar, rules, ref res);
  9799. }
  9800. if (remaining.Length > 0)
  9801. {
  9802. linknumber = remaining.GetLSLIntegerItem(0);
  9803. rules = remaining.GetSublist(1, -1);
  9804. }
  9805. else
  9806. break;
  9807. }
  9808. return res;
  9809. }
  9810. public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
  9811. {
  9812. int idx = 0;
  9813. int face;
  9814. Primitive.TextureEntry tex;
  9815. int nsides = GetNumberOfSides(part);
  9816. while (idx < rules.Length)
  9817. {
  9818. int code = (int)rules.GetLSLIntegerItem(idx++);
  9819. int remain = rules.Length - idx;
  9820. switch (code)
  9821. {
  9822. case (int)ScriptBaseClass.PRIM_MATERIAL:
  9823. res.Add(new LSL_Integer(part.Material));
  9824. break;
  9825. case (int)ScriptBaseClass.PRIM_PHYSICS:
  9826. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
  9827. res.Add(new LSL_Integer(1));
  9828. else
  9829. res.Add(new LSL_Integer(0));
  9830. break;
  9831. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  9832. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
  9833. res.Add(new LSL_Integer(1));
  9834. else
  9835. res.Add(new LSL_Integer(0));
  9836. break;
  9837. case (int)ScriptBaseClass.PRIM_PHANTOM:
  9838. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  9839. res.Add(new LSL_Integer(1));
  9840. else
  9841. res.Add(new LSL_Integer(0));
  9842. break;
  9843. case (int)ScriptBaseClass.PRIM_POSITION:
  9844. LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
  9845. part.AbsolutePosition.Y,
  9846. part.AbsolutePosition.Z);
  9847. res.Add(v);
  9848. break;
  9849. case (int)ScriptBaseClass.PRIM_SIZE:
  9850. res.Add(new LSL_Vector(part.Scale));
  9851. break;
  9852. case (int)ScriptBaseClass.PRIM_ROTATION:
  9853. res.Add(GetPartRot(part));
  9854. break;
  9855. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  9856. res.Add(new LSL_Integer((int)part.PhysicsShapeType));
  9857. break;
  9858. case (int)ScriptBaseClass.PRIM_TYPE:
  9859. // implementing box
  9860. PrimitiveBaseShape Shape = part.Shape;
  9861. int primType = (int)part.GetPrimType();
  9862. res.Add(new LSL_Integer(primType));
  9863. double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
  9864. double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
  9865. switch (primType)
  9866. {
  9867. case ScriptBaseClass.PRIM_TYPE_BOX:
  9868. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  9869. case ScriptBaseClass.PRIM_TYPE_PRISM:
  9870. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9871. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9872. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9873. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9874. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9875. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9876. break;
  9877. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  9878. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9879. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9880. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9881. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9882. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9883. break;
  9884. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  9885. res.Add(new LSL_String(Shape.SculptTexture.ToString()));
  9886. res.Add(new LSL_Integer(Shape.SculptType));
  9887. break;
  9888. case ScriptBaseClass.PRIM_TYPE_RING:
  9889. case ScriptBaseClass.PRIM_TYPE_TUBE:
  9890. case ScriptBaseClass.PRIM_TYPE_TORUS:
  9891. // holeshape
  9892. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9893. // cut
  9894. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9895. // hollow
  9896. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9897. // twist
  9898. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9899. // vector holesize
  9900. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9901. // vector topshear
  9902. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9903. // vector profilecut
  9904. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9905. // vector tapera
  9906. res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));
  9907. // float revolutions
  9908. res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d);
  9909. // Slightly inaccurate, because an unsigned byte is being used to represent
  9910. // the entire range of floating-point values from 1.0 through 4.0 (which is how
  9911. // SL does it).
  9912. //
  9913. // Using these formulas to store and retrieve PathRevolutions, it is not
  9914. // possible to use all values between 1.00 and 4.00. For instance, you can't
  9915. // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you
  9916. // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them
  9917. // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar
  9918. // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11.
  9919. // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value
  9920. // such as 1.10. So, SL must store and retreive the actual user input rather
  9921. // than only storing the encoded value.
  9922. // float radiusoffset
  9923. res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));
  9924. // float skew
  9925. res.Add(new LSL_Float(Shape.PathSkew / 100.0));
  9926. break;
  9927. }
  9928. break;
  9929. case (int)ScriptBaseClass.PRIM_TEXTURE:
  9930. if (remain < 1)
  9931. return new LSL_List();
  9932. face = (int)rules.GetLSLIntegerItem(idx++);
  9933. tex = part.Shape.Textures;
  9934. if (face == ScriptBaseClass.ALL_SIDES)
  9935. {
  9936. for (face = 0; face < nsides; face++)
  9937. {
  9938. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9939. res.Add(new LSL_String(texface.TextureID.ToString()));
  9940. res.Add(new LSL_Vector(texface.RepeatU,
  9941. texface.RepeatV,
  9942. 0));
  9943. res.Add(new LSL_Vector(texface.OffsetU,
  9944. texface.OffsetV,
  9945. 0));
  9946. res.Add(new LSL_Float(texface.Rotation));
  9947. }
  9948. }
  9949. else
  9950. {
  9951. if (face >= 0 && face < nsides)
  9952. {
  9953. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9954. res.Add(new LSL_String(texface.TextureID.ToString()));
  9955. res.Add(new LSL_Vector(texface.RepeatU,
  9956. texface.RepeatV,
  9957. 0));
  9958. res.Add(new LSL_Vector(texface.OffsetU,
  9959. texface.OffsetV,
  9960. 0));
  9961. res.Add(new LSL_Float(texface.Rotation));
  9962. }
  9963. }
  9964. break;
  9965. case (int)ScriptBaseClass.PRIM_COLOR:
  9966. if (remain < 1)
  9967. return new LSL_List();
  9968. face = (int)rules.GetLSLIntegerItem(idx++);
  9969. tex = part.Shape.Textures;
  9970. Color4 texcolor;
  9971. if (face == ScriptBaseClass.ALL_SIDES)
  9972. {
  9973. for (face = 0; face < nsides; face++)
  9974. {
  9975. texcolor = tex.GetFace((uint)face).RGBA;
  9976. res.Add(new LSL_Vector(texcolor.R,
  9977. texcolor.G,
  9978. texcolor.B));
  9979. res.Add(new LSL_Float(texcolor.A));
  9980. }
  9981. }
  9982. else
  9983. {
  9984. texcolor = tex.GetFace((uint)face).RGBA;
  9985. res.Add(new LSL_Vector(texcolor.R,
  9986. texcolor.G,
  9987. texcolor.B));
  9988. res.Add(new LSL_Float(texcolor.A));
  9989. }
  9990. break;
  9991. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  9992. {
  9993. if (remain < 1)
  9994. return new LSL_List();
  9995. face = (int)rules.GetLSLIntegerItem(idx++);
  9996. tex = part.Shape.Textures;
  9997. int shiny;
  9998. if (face == ScriptBaseClass.ALL_SIDES)
  9999. {
  10000. for (face = 0; face < nsides; face++)
  10001. {
  10002. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  10003. if (shinyness == Shininess.High)
  10004. {
  10005. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  10006. }
  10007. else if (shinyness == Shininess.Medium)
  10008. {
  10009. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  10010. }
  10011. else if (shinyness == Shininess.Low)
  10012. {
  10013. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  10014. }
  10015. else
  10016. {
  10017. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  10018. }
  10019. res.Add(new LSL_Integer(shiny));
  10020. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  10021. }
  10022. }
  10023. else
  10024. {
  10025. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  10026. if (shinyness == Shininess.High)
  10027. {
  10028. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  10029. }
  10030. else if (shinyness == Shininess.Medium)
  10031. {
  10032. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  10033. }
  10034. else if (shinyness == Shininess.Low)
  10035. {
  10036. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  10037. }
  10038. else
  10039. {
  10040. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  10041. }
  10042. res.Add(new LSL_Integer(shiny));
  10043. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  10044. }
  10045. break;
  10046. }
  10047. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  10048. {
  10049. if (remain < 1)
  10050. return new LSL_List();
  10051. face = (int)rules.GetLSLIntegerItem(idx++);
  10052. tex = part.Shape.Textures;
  10053. int fullbright;
  10054. if (face == ScriptBaseClass.ALL_SIDES)
  10055. {
  10056. for (face = 0; face < nsides; face++)
  10057. {
  10058. if (tex.GetFace((uint)face).Fullbright == true)
  10059. {
  10060. fullbright = ScriptBaseClass.TRUE;
  10061. }
  10062. else
  10063. {
  10064. fullbright = ScriptBaseClass.FALSE;
  10065. }
  10066. res.Add(new LSL_Integer(fullbright));
  10067. }
  10068. }
  10069. else
  10070. {
  10071. if (tex.GetFace((uint)face).Fullbright == true)
  10072. {
  10073. fullbright = ScriptBaseClass.TRUE;
  10074. }
  10075. else
  10076. {
  10077. fullbright = ScriptBaseClass.FALSE;
  10078. }
  10079. res.Add(new LSL_Integer(fullbright));
  10080. }
  10081. break;
  10082. }
  10083. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  10084. PrimitiveBaseShape shape = part.Shape;
  10085. if (shape.FlexiEntry)
  10086. res.Add(new LSL_Integer(1)); // active
  10087. else
  10088. res.Add(new LSL_Integer(0));
  10089. res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
  10090. res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
  10091. res.Add(new LSL_Float(shape.FlexiDrag)); // friction
  10092. res.Add(new LSL_Float(shape.FlexiWind)); // wind
  10093. res.Add(new LSL_Float(shape.FlexiTension)); // tension
  10094. res.Add(new LSL_Vector(shape.FlexiForceX, // force
  10095. shape.FlexiForceY,
  10096. shape.FlexiForceZ));
  10097. break;
  10098. case (int)ScriptBaseClass.PRIM_TEXGEN:
  10099. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  10100. if (remain < 1)
  10101. return new LSL_List();
  10102. face = (int)rules.GetLSLIntegerItem(idx++);
  10103. tex = part.Shape.Textures;
  10104. if (face == ScriptBaseClass.ALL_SIDES)
  10105. {
  10106. for (face = 0; face < nsides; face++)
  10107. {
  10108. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10109. {
  10110. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10111. }
  10112. else
  10113. {
  10114. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10115. }
  10116. }
  10117. }
  10118. else
  10119. {
  10120. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10121. {
  10122. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10123. }
  10124. else
  10125. {
  10126. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10127. }
  10128. }
  10129. break;
  10130. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  10131. shape = part.Shape;
  10132. if (shape.LightEntry)
  10133. res.Add(new LSL_Integer(1)); // active
  10134. else
  10135. res.Add(new LSL_Integer(0));
  10136. res.Add(new LSL_Vector(shape.LightColorR, // color
  10137. shape.LightColorG,
  10138. shape.LightColorB));
  10139. res.Add(new LSL_Float(shape.LightIntensity)); // intensity
  10140. res.Add(new LSL_Float(shape.LightRadius)); // radius
  10141. res.Add(new LSL_Float(shape.LightFalloff)); // falloff
  10142. break;
  10143. case (int)ScriptBaseClass.PRIM_GLOW:
  10144. if (remain < 1)
  10145. return new LSL_List();
  10146. face = (int)rules.GetLSLIntegerItem(idx++);
  10147. tex = part.Shape.Textures;
  10148. float primglow;
  10149. if (face == ScriptBaseClass.ALL_SIDES)
  10150. {
  10151. for (face = 0; face < nsides; face++)
  10152. {
  10153. primglow = tex.GetFace((uint)face).Glow;
  10154. res.Add(new LSL_Float(primglow));
  10155. }
  10156. }
  10157. else
  10158. {
  10159. primglow = tex.GetFace((uint)face).Glow;
  10160. res.Add(new LSL_Float(primglow));
  10161. }
  10162. break;
  10163. case (int)ScriptBaseClass.PRIM_TEXT:
  10164. Color4 textColor = part.GetTextColor();
  10165. res.Add(new LSL_String(part.Text));
  10166. res.Add(new LSL_Vector(textColor.R,
  10167. textColor.G,
  10168. textColor.B));
  10169. res.Add(new LSL_Float(textColor.A));
  10170. break;
  10171. case (int)ScriptBaseClass.PRIM_NAME:
  10172. res.Add(new LSL_String(part.Name));
  10173. break;
  10174. case (int)ScriptBaseClass.PRIM_DESC:
  10175. res.Add(new LSL_String(part.Description));
  10176. break;
  10177. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  10178. res.Add(new LSL_Rotation(part.RotationOffset));
  10179. break;
  10180. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  10181. res.Add(new LSL_Vector(GetPartLocalPos(part)));
  10182. break;
  10183. case (int)ScriptBaseClass.PRIM_SLICE:
  10184. PrimType prim_type = part.GetPrimType();
  10185. bool useProfileBeginEnd = (prim_type == PrimType.SPHERE || prim_type == PrimType.TORUS || prim_type == PrimType.TUBE || prim_type == PrimType.RING);
  10186. res.Add(new LSL_Vector(
  10187. (useProfileBeginEnd ? part.Shape.ProfileBegin : part.Shape.PathBegin) / 50000.0,
  10188. 1 - (useProfileBeginEnd ? part.Shape.ProfileEnd : part.Shape.PathEnd) / 50000.0,
  10189. 0
  10190. ));
  10191. break;
  10192. case (int)ScriptBaseClass.PRIM_OMEGA:
  10193. // this may return values diferent from SL since we don't handle set the same way
  10194. float gain = 1.0f; // we don't use gain and don't store it
  10195. Vector3 axis = part.AngularVelocity;
  10196. float spin = axis.Length();
  10197. if(spin < 1.0e-6)
  10198. {
  10199. axis = Vector3.Zero;
  10200. gain = 0.0f;
  10201. spin = 0.0f;
  10202. }
  10203. else
  10204. {
  10205. axis = axis * (1.0f/spin);
  10206. }
  10207. res.Add(new LSL_Vector(axis.X,
  10208. axis.Y,
  10209. axis.Z));
  10210. res.Add(new LSL_Float(spin));
  10211. res.Add(new LSL_Float(gain));
  10212. break;
  10213. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  10214. if(part.IsSitTargetSet)
  10215. {
  10216. res.Add(new LSL_Integer(1));
  10217. res.Add(new LSL_Vector(part.SitTargetPosition));
  10218. res.Add(new LSL_Rotation(part.SitTargetOrientation));
  10219. }
  10220. else
  10221. {
  10222. res.Add(new LSL_Integer(0));
  10223. res.Add(new LSL_Vector(Vector3.Zero));
  10224. res.Add(new LSL_Rotation(Quaternion.Identity));
  10225. }
  10226. break;
  10227. case (int)ScriptBaseClass.PRIM_NORMAL:
  10228. case (int)ScriptBaseClass.PRIM_SPECULAR:
  10229. case (int)ScriptBaseClass.PRIM_ALPHA_MODE:
  10230. if (remain < 1)
  10231. return new LSL_List();
  10232. face = (int)rules.GetLSLIntegerItem(idx++);
  10233. tex = part.Shape.Textures;
  10234. if (face == ScriptBaseClass.ALL_SIDES)
  10235. {
  10236. for (face = 0; face < nsides; face++)
  10237. {
  10238. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10239. getLSLFaceMaterial(ref res, code, part, texface);
  10240. }
  10241. }
  10242. else
  10243. {
  10244. if (face >= 0 && face < nsides)
  10245. {
  10246. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10247. getLSLFaceMaterial(ref res, code, part, texface);
  10248. }
  10249. }
  10250. break;
  10251. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  10252. // TODO: Should be issuing a runtime script warning in this case.
  10253. if (remain < 2)
  10254. return new LSL_List();
  10255. return rules.GetSublist(idx, -1);
  10256. }
  10257. }
  10258. return new LSL_List();
  10259. }
  10260. private string GetMaterialTextureUUIDbyRights(UUID origID, SceneObjectPart part)
  10261. {
  10262. if(World.Permissions.CanEditObject(m_host.ParentGroup.UUID, m_host.ParentGroup.RootPart.OwnerID))
  10263. return origID.ToString();
  10264. lock(part.TaskInventory)
  10265. {
  10266. foreach(KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  10267. {
  10268. if(inv.Value.InvType == (int)InventoryType.Texture && inv.Value.AssetID == origID)
  10269. return origID.ToString();
  10270. }
  10271. }
  10272. return UUID.Zero.ToString();
  10273. }
  10274. private void getLSLFaceMaterial(ref LSL_List res, int code, SceneObjectPart part, Primitive.TextureEntryFace texface)
  10275. {
  10276. UUID matID = UUID.Zero;
  10277. if(m_materialsModule != null)
  10278. matID = texface.MaterialID;
  10279. if(matID != UUID.Zero)
  10280. {
  10281. FaceMaterial mat = m_materialsModule.GetMaterial(matID);
  10282. if(mat != null)
  10283. {
  10284. if(code == ScriptBaseClass.PRIM_NORMAL)
  10285. {
  10286. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.NormalMapID, part)));
  10287. res.Add(new LSL_Vector(mat.NormalRepeatX, mat.NormalRepeatY, 0));
  10288. res.Add(new LSL_Vector(mat.NormalOffsetX, mat.NormalOffsetY, 0));
  10289. res.Add(new LSL_Float(mat.NormalRotation));
  10290. }
  10291. else if(code == ScriptBaseClass.PRIM_SPECULAR)
  10292. {
  10293. const float colorScale = 1.0f / 255f;
  10294. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.SpecularMapID, part)));
  10295. res.Add(new LSL_Vector(mat.SpecularRepeatX, mat.SpecularRepeatY, 0));
  10296. res.Add(new LSL_Vector(mat.SpecularOffsetX, mat.SpecularOffsetY, 0));
  10297. res.Add(new LSL_Float(mat.SpecularRotation));
  10298. res.Add(new LSL_Vector(mat.SpecularLightColorR * colorScale,
  10299. mat.SpecularLightColorG * colorScale,
  10300. mat.SpecularLightColorB * colorScale));
  10301. res.Add(new LSL_Integer(mat.SpecularLightExponent));
  10302. res.Add(new LSL_Integer(mat.EnvironmentIntensity));
  10303. }
  10304. else if(code == ScriptBaseClass.PRIM_ALPHA_MODE)
  10305. {
  10306. res.Add(new LSL_Integer(mat.DiffuseAlphaMode));
  10307. res.Add(new LSL_Integer(mat.AlphaMaskCutoff));
  10308. }
  10309. return;
  10310. }
  10311. }
  10312. // material not found
  10313. if(code == (int)ScriptBaseClass.PRIM_NORMAL || code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10314. {
  10315. res.Add(new LSL_String(UUID.Zero.ToString()));
  10316. res.Add(new LSL_Vector(1.0, 1.0, 0));
  10317. res.Add(new LSL_Vector(0, 0, 0));
  10318. res.Add(new LSL_Float(0));
  10319. if(code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10320. {
  10321. res.Add(new LSL_Vector(1.0, 1.0, 1.0));
  10322. res.Add(new LSL_Integer(51));
  10323. res.Add(new LSL_Integer(0));
  10324. }
  10325. }
  10326. else if(code == (int)ScriptBaseClass.PRIM_ALPHA_MODE)
  10327. {
  10328. res.Add(new LSL_Integer(1));
  10329. res.Add(new LSL_Integer(0));
  10330. }
  10331. }
  10332. public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
  10333. {
  10334. m_host.AddScriptLPS(1);
  10335. ScriptSleep(m_sleepMsOnGetPrimMediaParams);
  10336. return GetPrimMediaParams(m_host, face, rules);
  10337. }
  10338. public LSL_List llGetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10339. {
  10340. m_host.AddScriptLPS(1);
  10341. ScriptSleep(m_sleepMsOnGetLinkMedia);
  10342. if (link == ScriptBaseClass.LINK_ROOT)
  10343. return GetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10344. else if (link == ScriptBaseClass.LINK_THIS)
  10345. return GetPrimMediaParams(m_host, face, rules);
  10346. else
  10347. {
  10348. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10349. if (null != part)
  10350. return GetPrimMediaParams(part, face, rules);
  10351. }
  10352. return new LSL_List();
  10353. }
  10354. private LSL_List GetPrimMediaParams(SceneObjectPart part, int face, LSL_List rules)
  10355. {
  10356. // LSL Spec http://wiki.secondlife.com/wiki/LlGetPrimMediaParams says to fail silently if face is invalid
  10357. // TODO: Need to correctly handle case where a face has no media (which gives back an empty list).
  10358. // Assuming silently fail means give back an empty list. Ideally, need to check this.
  10359. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10360. return new LSL_List();
  10361. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10362. if (null == module)
  10363. return new LSL_List();
  10364. MediaEntry me = module.GetMediaEntry(part, face);
  10365. // As per http://wiki.secondlife.com/wiki/LlGetPrimMediaParams
  10366. if (null == me)
  10367. return new LSL_List();
  10368. LSL_List res = new LSL_List();
  10369. for (int i = 0; i < rules.Length; i++)
  10370. {
  10371. int code = (int)rules.GetLSLIntegerItem(i);
  10372. switch (code)
  10373. {
  10374. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10375. // Not implemented
  10376. res.Add(new LSL_Integer(0));
  10377. break;
  10378. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10379. if (me.Controls == MediaControls.Standard)
  10380. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD));
  10381. else
  10382. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_MINI));
  10383. break;
  10384. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10385. res.Add(new LSL_String(me.CurrentURL));
  10386. break;
  10387. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10388. res.Add(new LSL_String(me.HomeURL));
  10389. break;
  10390. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10391. res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10392. break;
  10393. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10394. res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10395. break;
  10396. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10397. res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10398. break;
  10399. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10400. res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10401. break;
  10402. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10403. res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10404. break;
  10405. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10406. res.Add(new LSL_Integer(me.Width));
  10407. break;
  10408. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10409. res.Add(new LSL_Integer(me.Height));
  10410. break;
  10411. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10412. res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10413. break;
  10414. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10415. string[] urls = (string[])me.WhiteList.Clone();
  10416. for (int j = 0; j < urls.Length; j++)
  10417. urls[j] = Uri.EscapeDataString(urls[j]);
  10418. res.Add(new LSL_String(string.Join(", ", urls)));
  10419. break;
  10420. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10421. res.Add(new LSL_Integer((int)me.InteractPermissions));
  10422. break;
  10423. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10424. res.Add(new LSL_Integer((int)me.ControlPermissions));
  10425. break;
  10426. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10427. }
  10428. }
  10429. return res;
  10430. }
  10431. public LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules)
  10432. {
  10433. m_host.AddScriptLPS(1);
  10434. ScriptSleep(m_sleepMsOnSetPrimMediaParams);
  10435. return SetPrimMediaParams(m_host, face, rules);
  10436. }
  10437. public LSL_Integer llSetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10438. {
  10439. m_host.AddScriptLPS(1);
  10440. ScriptSleep(m_sleepMsOnSetLinkMedia);
  10441. if (link == ScriptBaseClass.LINK_ROOT)
  10442. return SetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10443. else if (link == ScriptBaseClass.LINK_THIS)
  10444. return SetPrimMediaParams(m_host, face, rules);
  10445. else
  10446. {
  10447. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10448. if (null != part)
  10449. return SetPrimMediaParams(part, face, rules);
  10450. }
  10451. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10452. }
  10453. private LSL_Integer SetPrimMediaParams(SceneObjectPart part, LSL_Integer face, LSL_List rules)
  10454. {
  10455. // LSL Spec http://wiki.secondlife.com/wiki/LlSetPrimMediaParams says to fail silently if face is invalid
  10456. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10457. // Don't perform the media check directly
  10458. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10459. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10460. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10461. if (null == module)
  10462. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10463. MediaEntry me = module.GetMediaEntry(part, face);
  10464. if (null == me)
  10465. me = new MediaEntry();
  10466. int i = 0;
  10467. while (i < rules.Length - 1)
  10468. {
  10469. int code = rules.GetLSLIntegerItem(i++);
  10470. switch (code)
  10471. {
  10472. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10473. me.EnableAlterntiveImage = (rules.GetLSLIntegerItem(i++) != 0 ? true : false);
  10474. break;
  10475. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10476. int v = rules.GetLSLIntegerItem(i++);
  10477. if (ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD == v)
  10478. me.Controls = MediaControls.Standard;
  10479. else
  10480. me.Controls = MediaControls.Mini;
  10481. break;
  10482. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10483. me.CurrentURL = rules.GetLSLStringItem(i++);
  10484. break;
  10485. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10486. me.HomeURL = rules.GetLSLStringItem(i++);
  10487. break;
  10488. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10489. me.AutoLoop = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10490. break;
  10491. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10492. me.AutoPlay = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10493. break;
  10494. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10495. me.AutoScale = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10496. break;
  10497. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10498. me.AutoZoom = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10499. break;
  10500. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10501. me.InteractOnFirstClick = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10502. break;
  10503. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10504. me.Width = (int)rules.GetLSLIntegerItem(i++);
  10505. break;
  10506. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10507. me.Height = (int)rules.GetLSLIntegerItem(i++);
  10508. break;
  10509. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10510. me.EnableWhiteList = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10511. break;
  10512. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10513. string[] rawWhiteListUrls = rules.GetLSLStringItem(i++).ToString().Split(new char[] { ',' });
  10514. List<string> whiteListUrls = new List<string>();
  10515. Array.ForEach(
  10516. rawWhiteListUrls, delegate(string rawUrl) { whiteListUrls.Add(rawUrl.Trim()); });
  10517. me.WhiteList = whiteListUrls.ToArray();
  10518. break;
  10519. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10520. me.InteractPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10521. break;
  10522. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10523. me.ControlPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10524. break;
  10525. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10526. }
  10527. }
  10528. module.SetMediaEntry(part, face, me);
  10529. return ScriptBaseClass.LSL_STATUS_OK;
  10530. }
  10531. public LSL_Integer llClearPrimMedia(LSL_Integer face)
  10532. {
  10533. m_host.AddScriptLPS(1);
  10534. ScriptSleep(m_sleepMsOnClearPrimMedia);
  10535. return ClearPrimMedia(m_host, face);
  10536. }
  10537. public LSL_Integer llClearLinkMedia(LSL_Integer link, LSL_Integer face)
  10538. {
  10539. m_host.AddScriptLPS(1);
  10540. ScriptSleep(m_sleepMsOnClearLinkMedia);
  10541. if (link == ScriptBaseClass.LINK_ROOT)
  10542. return ClearPrimMedia(m_host.ParentGroup.RootPart, face);
  10543. else if (link == ScriptBaseClass.LINK_THIS)
  10544. return ClearPrimMedia(m_host, face);
  10545. else
  10546. {
  10547. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10548. if (null != part)
  10549. return ClearPrimMedia(part, face);
  10550. }
  10551. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10552. }
  10553. private LSL_Integer ClearPrimMedia(SceneObjectPart part, LSL_Integer face)
  10554. {
  10555. // LSL Spec http://wiki.secondlife.com/wiki/LlClearPrimMedia says to fail silently if face is invalid
  10556. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10557. // FIXME: Don't perform the media check directly
  10558. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10559. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10560. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10561. if (null == module)
  10562. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10563. module.ClearMediaEntry(part, face);
  10564. return ScriptBaseClass.LSL_STATUS_OK;
  10565. }
  10566. // <remarks>
  10567. // <para>
  10568. // The .NET definition of base 64 is:
  10569. // <list>
  10570. // <item>
  10571. // Significant: A-Z a-z 0-9 + -
  10572. // </item>
  10573. // <item>
  10574. // Whitespace: \t \n \r ' '
  10575. // </item>
  10576. // <item>
  10577. // Valueless: =
  10578. // </item>
  10579. // <item>
  10580. // End-of-string: \0 or '=='
  10581. // </item>
  10582. // </list>
  10583. // </para>
  10584. // <para>
  10585. // Each point in a base-64 string represents
  10586. // a 6 bit value. A 32-bit integer can be
  10587. // represented using 6 characters (with some
  10588. // redundancy).
  10589. // </para>
  10590. // <para>
  10591. // LSL requires a base64 string to be 8
  10592. // characters in length. LSL also uses '/'
  10593. // rather than '-' (MIME compliant).
  10594. // </para>
  10595. // <para>
  10596. // RFC 1341 used as a reference (as specified
  10597. // by the SecondLife Wiki).
  10598. // </para>
  10599. // <para>
  10600. // SL do not record any kind of exception for
  10601. // these functions, so the string to integer
  10602. // conversion returns '0' if an invalid
  10603. // character is encountered during conversion.
  10604. // </para>
  10605. // <para>
  10606. // References
  10607. // <list>
  10608. // <item>
  10609. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  10610. // </item>
  10611. // <item>
  10612. // </item>
  10613. // </list>
  10614. // </para>
  10615. // </remarks>
  10616. // <summary>
  10617. // Table for converting 6-bit integers into
  10618. // base-64 characters
  10619. // </summary>
  10620. protected static readonly char[] i2ctable =
  10621. {
  10622. 'A','B','C','D','E','F','G','H',
  10623. 'I','J','K','L','M','N','O','P',
  10624. 'Q','R','S','T','U','V','W','X',
  10625. 'Y','Z',
  10626. 'a','b','c','d','e','f','g','h',
  10627. 'i','j','k','l','m','n','o','p',
  10628. 'q','r','s','t','u','v','w','x',
  10629. 'y','z',
  10630. '0','1','2','3','4','5','6','7',
  10631. '8','9',
  10632. '+','/'
  10633. };
  10634. // <summary>
  10635. // Table for converting base-64 characters
  10636. // into 6-bit integers.
  10637. // </summary>
  10638. protected static readonly int[] c2itable =
  10639. {
  10640. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  10641. -1,-1,-1,-1,-1,-1,-1,-1,
  10642. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  10643. -1,-1,-1,-1,-1,-1,-1,-1,
  10644. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  10645. -1,-1,-1,63,-1,-1,-1,64,
  10646. 53,54,55,56,57,58,59,60, // 3x
  10647. 61,62,-1,-1,-1,0,-1,-1,
  10648. -1,1,2,3,4,5,6,7, // 4x
  10649. 8,9,10,11,12,13,14,15,
  10650. 16,17,18,19,20,21,22,23, // 5x
  10651. 24,25,26,-1,-1,-1,-1,-1,
  10652. -1,27,28,29,30,31,32,33, // 6x
  10653. 34,35,36,37,38,39,40,41,
  10654. 42,43,44,45,46,47,48,49, // 7x
  10655. 50,51,52,-1,-1,-1,-1,-1,
  10656. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  10657. -1,-1,-1,-1,-1,-1,-1,-1,
  10658. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  10659. -1,-1,-1,-1,-1,-1,-1,-1,
  10660. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  10661. -1,-1,-1,-1,-1,-1,-1,-1,
  10662. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  10663. -1,-1,-1,-1,-1,-1,-1,-1,
  10664. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  10665. -1,-1,-1,-1,-1,-1,-1,-1,
  10666. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  10667. -1,-1,-1,-1,-1,-1,-1,-1,
  10668. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  10669. -1,-1,-1,-1,-1,-1,-1,-1,
  10670. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  10671. -1,-1,-1,-1,-1,-1,-1,-1
  10672. };
  10673. // <summary>
  10674. // Converts a 32-bit integer into a Base64
  10675. // character string. Base64 character strings
  10676. // are always 8 characters long. All iinteger
  10677. // values are acceptable.
  10678. // </summary>
  10679. // <param name="number">
  10680. // 32-bit integer to be converted.
  10681. // </param>
  10682. // <returns>
  10683. // 8 character string. The 1st six characters
  10684. // contain the encoded number, the last two
  10685. // characters are padded with "=".
  10686. // </returns>
  10687. public LSL_String llIntegerToBase64(int number)
  10688. {
  10689. // uninitialized string
  10690. char[] imdt = new char[8];
  10691. m_host.AddScriptLPS(1);
  10692. // Manually unroll the loop
  10693. imdt[7] = '=';
  10694. imdt[6] = '=';
  10695. imdt[5] = i2ctable[number<<4 & 0x3F];
  10696. imdt[4] = i2ctable[number>>2 & 0x3F];
  10697. imdt[3] = i2ctable[number>>8 & 0x3F];
  10698. imdt[2] = i2ctable[number>>14 & 0x3F];
  10699. imdt[1] = i2ctable[number>>20 & 0x3F];
  10700. imdt[0] = i2ctable[number>>26 & 0x3F];
  10701. return new string(imdt);
  10702. }
  10703. // <summary>
  10704. // Converts an eight character base-64 string
  10705. // into a 32-bit integer.
  10706. // </summary>
  10707. // <param name="str">
  10708. // 8 characters string to be converted. Other
  10709. // length strings return zero.
  10710. // </param>
  10711. // <returns>
  10712. // Returns an integer representing the
  10713. // encoded value providedint he 1st 6
  10714. // characters of the string.
  10715. // </returns>
  10716. // <remarks>
  10717. // This is coded to behave like LSL's
  10718. // implementation (I think), based upon the
  10719. // information available at the Wiki.
  10720. // If more than 8 characters are supplied,
  10721. // zero is returned.
  10722. // If a NULL string is supplied, zero will
  10723. // be returned.
  10724. // If fewer than 6 characters are supplied, then
  10725. // the answer will reflect a partial
  10726. // accumulation.
  10727. // <para>
  10728. // The 6-bit segments are
  10729. // extracted left-to-right in big-endian mode,
  10730. // which means that segment 6 only contains the
  10731. // two low-order bits of the 32 bit integer as
  10732. // its high order 2 bits. A short string therefore
  10733. // means loss of low-order information. E.g.
  10734. //
  10735. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  10736. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  10737. // |3|3|2|2|2|2|2|2|2|2|2|2|1|1|1|1|1|1|1|1|1|1| | | | | | | | | | |P|P|P|P|
  10738. // |1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|P|P|P|P|
  10739. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  10740. //
  10741. // </para>
  10742. // </remarks>
  10743. public LSL_Integer llBase64ToInteger(string str)
  10744. {
  10745. int number = 0;
  10746. int digit;
  10747. m_host.AddScriptLPS(1);
  10748. // Require a well-fromed base64 string
  10749. if (str.Length > 8)
  10750. return 0;
  10751. // The loop is unrolled in the interests
  10752. // of performance and simple necessity.
  10753. //
  10754. // MUST find 6 digits to be well formed
  10755. // -1 == invalid
  10756. // 0 == padding
  10757. if ((digit = c2itable[str[0]]) <= 0)
  10758. {
  10759. return digit < 0 ? (int)0 : number;
  10760. }
  10761. number += --digit<<26;
  10762. if ((digit = c2itable[str[1]]) <= 0)
  10763. {
  10764. return digit < 0 ? (int)0 : number;
  10765. }
  10766. number += --digit<<20;
  10767. if ((digit = c2itable[str[2]]) <= 0)
  10768. {
  10769. return digit < 0 ? (int)0 : number;
  10770. }
  10771. number += --digit<<14;
  10772. if ((digit = c2itable[str[3]]) <= 0)
  10773. {
  10774. return digit < 0 ? (int)0 : number;
  10775. }
  10776. number += --digit<<8;
  10777. if ((digit = c2itable[str[4]]) <= 0)
  10778. {
  10779. return digit < 0 ? (int)0 : number;
  10780. }
  10781. number += --digit<<2;
  10782. if ((digit = c2itable[str[5]]) <= 0)
  10783. {
  10784. return digit < 0 ? (int)0 : number;
  10785. }
  10786. number += --digit>>4;
  10787. // ignore trailing padding
  10788. return number;
  10789. }
  10790. public LSL_Float llGetGMTclock()
  10791. {
  10792. m_host.AddScriptLPS(1);
  10793. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  10794. }
  10795. public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
  10796. {
  10797. m_host.AddScriptLPS(1);
  10798. if (m_UrlModule != null)
  10799. return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
  10800. return String.Empty;
  10801. }
  10802. public LSL_String llGetSimulatorHostname()
  10803. {
  10804. m_host.AddScriptLPS(1);
  10805. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  10806. return UrlModule.ExternalHostNameForLSL;
  10807. }
  10808. // <summary>
  10809. // Scan the string supplied in 'src' and
  10810. // tokenize it based upon two sets of
  10811. // tokenizers provided in two lists,
  10812. // separators and spacers.
  10813. // </summary>
  10814. //
  10815. // <remarks>
  10816. // Separators demarcate tokens and are
  10817. // elided as they are encountered. Spacers
  10818. // also demarcate tokens, but are themselves
  10819. // retained as tokens.
  10820. //
  10821. // Both separators and spacers may be arbitrarily
  10822. // long strings. i.e. ":::".
  10823. //
  10824. // The function returns an ordered list
  10825. // representing the tokens found in the supplied
  10826. // sources string. If two successive tokenizers
  10827. // are encountered, then a null-string entry is
  10828. // added to the list.
  10829. //
  10830. // It is a precondition that the source and
  10831. // toekizer lisst are non-null. If they are null,
  10832. // then a null pointer exception will be thrown
  10833. // while their lengths are being determined.
  10834. //
  10835. // A small amount of working memoryis required
  10836. // of approximately 8*#tokenizers + 8*srcstrlen.
  10837. //
  10838. // There are many ways in which this function
  10839. // can be implemented, this implementation is
  10840. // fairly naive and assumes that when the
  10841. // function is invooked with a short source
  10842. // string and/or short lists of tokenizers, then
  10843. // performance will not be an issue.
  10844. //
  10845. // In order to minimize the perofrmance
  10846. // effects of long strings, or large numbers
  10847. // of tokeizers, the function skips as far as
  10848. // possible whenever a toekenizer is found,
  10849. // and eliminates redundant tokenizers as soon
  10850. // as is possible.
  10851. //
  10852. // The implementation tries to minimize temporary
  10853. // garbage generation.
  10854. // </remarks>
  10855. public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
  10856. {
  10857. return ParseString2List(src, separators, spacers, true);
  10858. }
  10859. private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
  10860. {
  10861. int srclen = src.Length;
  10862. int seplen = separators.Length;
  10863. object[] separray = separators.Data;
  10864. int spclen = spacers.Length;
  10865. object[] spcarray = spacers.Data;
  10866. int dellen = 0;
  10867. string[] delarray = new string[seplen+spclen];
  10868. int outlen = 0;
  10869. string[] outarray = new string[srclen*2+1];
  10870. int i, j;
  10871. string d;
  10872. m_host.AddScriptLPS(1);
  10873. /*
  10874. * Convert separator and spacer lists to C# strings.
  10875. * Also filter out null strings so we don't hang.
  10876. */
  10877. for (i = 0; i < seplen; i ++)
  10878. {
  10879. d = separray[i].ToString();
  10880. if (d.Length > 0)
  10881. {
  10882. delarray[dellen++] = d;
  10883. }
  10884. }
  10885. seplen = dellen;
  10886. for (i = 0; i < spclen; i ++)
  10887. {
  10888. d = spcarray[i].ToString();
  10889. if (d.Length > 0)
  10890. {
  10891. delarray[dellen++] = d;
  10892. }
  10893. }
  10894. /*
  10895. * Scan through source string from beginning to end.
  10896. */
  10897. for (i = 0;;)
  10898. {
  10899. /*
  10900. * Find earliest delimeter in src starting at i (if any).
  10901. */
  10902. int earliestDel = -1;
  10903. int earliestSrc = srclen;
  10904. string earliestStr = null;
  10905. for (j = 0; j < dellen; j ++)
  10906. {
  10907. d = delarray[j];
  10908. if (d != null)
  10909. {
  10910. int index = src.IndexOf(d, i);
  10911. if (index < 0)
  10912. {
  10913. delarray[j] = null; // delim nowhere in src, don't check it anymore
  10914. }
  10915. else if (index < earliestSrc)
  10916. {
  10917. earliestSrc = index; // where delimeter starts in source string
  10918. earliestDel = j; // where delimeter is in delarray[]
  10919. earliestStr = d; // the delimeter string from delarray[]
  10920. if (index == i) break; // can't do any better than found at beg of string
  10921. }
  10922. }
  10923. }
  10924. /*
  10925. * Output source string starting at i through start of earliest delimeter.
  10926. */
  10927. if (keepNulls || (earliestSrc > i))
  10928. {
  10929. outarray[outlen++] = src.Substring(i, earliestSrc - i);
  10930. }
  10931. /*
  10932. * If no delimeter found at or after i, we're done scanning.
  10933. */
  10934. if (earliestDel < 0) break;
  10935. /*
  10936. * If delimeter was a spacer, output the spacer.
  10937. */
  10938. if (earliestDel >= seplen)
  10939. {
  10940. outarray[outlen++] = earliestStr;
  10941. }
  10942. /*
  10943. * Look at rest of src string following delimeter.
  10944. */
  10945. i = earliestSrc + earliestStr.Length;
  10946. }
  10947. /*
  10948. * Make up an exact-sized output array suitable for an LSL_List object.
  10949. */
  10950. object[] outlist = new object[outlen];
  10951. for (i = 0; i < outlen; i ++)
  10952. {
  10953. outlist[i] = new LSL_String(outarray[i]);
  10954. }
  10955. return new LSL_List(outlist);
  10956. }
  10957. public LSL_Integer llGetObjectPermMask(int mask)
  10958. {
  10959. m_host.AddScriptLPS(1);
  10960. int permmask = 0;
  10961. if (mask == ScriptBaseClass.MASK_BASE)//0
  10962. {
  10963. permmask = (int)m_host.BaseMask;
  10964. }
  10965. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  10966. {
  10967. permmask = (int)m_host.OwnerMask;
  10968. }
  10969. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  10970. {
  10971. permmask = (int)m_host.GroupMask;
  10972. }
  10973. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  10974. {
  10975. permmask = (int)m_host.EveryoneMask;
  10976. }
  10977. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  10978. {
  10979. permmask = (int)m_host.NextOwnerMask;
  10980. }
  10981. return permmask;
  10982. }
  10983. public void llSetObjectPermMask(int mask, int value)
  10984. {
  10985. m_host.AddScriptLPS(1);
  10986. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  10987. {
  10988. if (World.Permissions.IsAdministrator(m_host.OwnerID))
  10989. {
  10990. if (mask == ScriptBaseClass.MASK_BASE)//0
  10991. {
  10992. m_host.BaseMask = (uint)value;
  10993. }
  10994. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  10995. {
  10996. m_host.OwnerMask = (uint)value;
  10997. }
  10998. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  10999. {
  11000. m_host.GroupMask = (uint)value;
  11001. }
  11002. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  11003. {
  11004. m_host.EveryoneMask = (uint)value;
  11005. }
  11006. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  11007. {
  11008. m_host.NextOwnerMask = (uint)value;
  11009. }
  11010. }
  11011. }
  11012. }
  11013. public LSL_Integer llGetInventoryPermMask(string itemName, int mask)
  11014. {
  11015. m_host.AddScriptLPS(1);
  11016. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11017. if (item == null)
  11018. return -1;
  11019. switch (mask)
  11020. {
  11021. case 0:
  11022. return (int)item.BasePermissions;
  11023. case 1:
  11024. return (int)item.CurrentPermissions;
  11025. case 2:
  11026. return (int)item.GroupPermissions;
  11027. case 3:
  11028. return (int)item.EveryonePermissions;
  11029. case 4:
  11030. return (int)item.NextPermissions;
  11031. }
  11032. return -1;
  11033. }
  11034. public void llSetInventoryPermMask(string itemName, int mask, int value)
  11035. {
  11036. m_host.AddScriptLPS(1);
  11037. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  11038. {
  11039. if (World.Permissions.IsAdministrator(m_host.OwnerID))
  11040. {
  11041. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11042. if (item != null)
  11043. {
  11044. switch (mask)
  11045. {
  11046. case 0:
  11047. item.BasePermissions = (uint)value;
  11048. break;
  11049. case 1:
  11050. item.CurrentPermissions = (uint)value;
  11051. break;
  11052. case 2:
  11053. item.GroupPermissions = (uint)value;
  11054. break;
  11055. case 3:
  11056. item.EveryonePermissions = (uint)value;
  11057. break;
  11058. case 4:
  11059. item.NextPermissions = (uint)value;
  11060. break;
  11061. }
  11062. }
  11063. }
  11064. }
  11065. }
  11066. public LSL_Key llGetInventoryCreator(string itemName)
  11067. {
  11068. m_host.AddScriptLPS(1);
  11069. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11070. if (item == null)
  11071. {
  11072. Error("llGetInventoryCreator", "Can't find item '" + item + "'");
  11073. return String.Empty;
  11074. }
  11075. return item.CreatorID.ToString();
  11076. }
  11077. public void llOwnerSay(string msg)
  11078. {
  11079. m_host.AddScriptLPS(1);
  11080. World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0,
  11081. m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  11082. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  11083. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  11084. }
  11085. public LSL_Key llRequestSecureURL()
  11086. {
  11087. m_host.AddScriptLPS(1);
  11088. if (m_UrlModule != null)
  11089. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11090. return UUID.Zero.ToString();
  11091. }
  11092. public LSL_Key llRequestSimulatorData(string simulator, int data)
  11093. {
  11094. try
  11095. {
  11096. m_host.AddScriptLPS(1);
  11097. string reply = String.Empty;
  11098. GridRegion info;
  11099. if (World.RegionInfo.RegionName == simulator)
  11100. info = new GridRegion(World.RegionInfo);
  11101. else
  11102. info = World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
  11103. switch (data)
  11104. {
  11105. case ScriptBaseClass.DATA_SIM_POS:
  11106. if (info == null)
  11107. {
  11108. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11109. return UUID.Zero.ToString();
  11110. }
  11111. bool isHypergridRegion = false;
  11112. if (World.RegionInfo.RegionName != simulator && info.RegionSecret != "")
  11113. {
  11114. // Hypergrid is currently placing real destination region co-ords into RegionSecret.
  11115. // But other code can also use this field for a genuine RegionSecret! Therefore, if
  11116. // anything is present we need to disambiguate.
  11117. //
  11118. // FIXME: Hypergrid should be storing this data in a different field.
  11119. RegionFlags regionFlags
  11120. = (RegionFlags)m_ScriptEngine.World.GridService.GetRegionFlags(
  11121. info.ScopeID, info.RegionID);
  11122. isHypergridRegion = (regionFlags & RegionFlags.Hyperlink) != 0;
  11123. }
  11124. if (isHypergridRegion)
  11125. {
  11126. uint rx = 0, ry = 0;
  11127. Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
  11128. reply = new LSL_Vector(
  11129. rx,
  11130. ry,
  11131. 0).ToString();
  11132. }
  11133. else
  11134. {
  11135. // Local grid co-oridnates
  11136. reply = new LSL_Vector(
  11137. info.RegionLocX,
  11138. info.RegionLocY,
  11139. 0).ToString();
  11140. }
  11141. break;
  11142. case ScriptBaseClass.DATA_SIM_STATUS:
  11143. if (info != null)
  11144. reply = "up"; // Duh!
  11145. else
  11146. reply = "unknown";
  11147. break;
  11148. case ScriptBaseClass.DATA_SIM_RATING:
  11149. if (info == null)
  11150. {
  11151. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11152. return UUID.Zero.ToString();
  11153. }
  11154. int access = info.Maturity;
  11155. if (access == 0)
  11156. reply = "PG";
  11157. else if (access == 1)
  11158. reply = "MATURE";
  11159. else if (access == 2)
  11160. reply = "ADULT";
  11161. else
  11162. reply = "UNKNOWN";
  11163. break;
  11164. case ScriptBaseClass.DATA_SIM_RELEASE:
  11165. reply = "OpenSim";
  11166. break;
  11167. default:
  11168. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11169. return UUID.Zero.ToString(); // Raise no event
  11170. }
  11171. UUID rq = UUID.Random();
  11172. UUID tid = AsyncCommands.
  11173. DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  11174. AsyncCommands.
  11175. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  11176. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11177. return tid.ToString();
  11178. }
  11179. catch(Exception)
  11180. {
  11181. //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
  11182. return UUID.Zero.ToString();
  11183. }
  11184. }
  11185. public LSL_Key llRequestURL()
  11186. {
  11187. m_host.AddScriptLPS(1);
  11188. if (m_UrlModule != null)
  11189. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11190. return UUID.Zero.ToString();
  11191. }
  11192. public void llForceMouselook(int mouselook)
  11193. {
  11194. m_host.AddScriptLPS(1);
  11195. m_host.SetForceMouselook(mouselook != 0);
  11196. }
  11197. public LSL_Float llGetObjectMass(LSL_Key id)
  11198. {
  11199. m_host.AddScriptLPS(1);
  11200. UUID key = new UUID();
  11201. if (!UUID.TryParse(id, out key))
  11202. return 0;
  11203. // return total object mass
  11204. SceneObjectPart part = World.GetSceneObjectPart(key);
  11205. if (part != null)
  11206. return part.ParentGroup.GetMass();
  11207. // the object is null so the key is for an avatar
  11208. ScenePresence avatar = World.GetScenePresence(key);
  11209. if (avatar != null)
  11210. {
  11211. if (avatar.IsChildAgent)
  11212. {
  11213. // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
  11214. // child agents have a mass of 1.0
  11215. return 1;
  11216. }
  11217. else
  11218. {
  11219. return avatar.GetMass();
  11220. }
  11221. }
  11222. return 0;
  11223. }
  11224. /// <summary>
  11225. /// llListReplaceList removes the sub-list defined by the inclusive indices
  11226. /// start and end and inserts the src list in its place. The inclusive
  11227. /// nature of the indices means that at least one element must be deleted
  11228. /// if the indices are within the bounds of the existing list. I.e. 2,2
  11229. /// will remove the element at index 2 and replace it with the source
  11230. /// list. Both indices may be negative, with the usual interpretation. An
  11231. /// interesting case is where end is lower than start. As these indices
  11232. /// bound the list to be removed, then 0->end, and start->lim are removed
  11233. /// and the source list is added as a suffix.
  11234. /// </summary>
  11235. public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
  11236. {
  11237. LSL_List pref;
  11238. m_host.AddScriptLPS(1);
  11239. // Note that although we have normalized, both
  11240. // indices could still be negative.
  11241. if (start < 0)
  11242. {
  11243. start = start+dest.Length;
  11244. }
  11245. if (end < 0)
  11246. {
  11247. end = end+dest.Length;
  11248. }
  11249. // The comventional case, remove a sequence starting with
  11250. // start and ending with end. And then insert the source
  11251. // list.
  11252. if (start <= end)
  11253. {
  11254. // If greater than zero, then there is going to be a
  11255. // surviving prefix. Otherwise the inclusive nature
  11256. // of the indices mean that we're going to add the
  11257. // source list as a prefix.
  11258. if (start > 0)
  11259. {
  11260. pref = dest.GetSublist(0,start-1);
  11261. // Only add a suffix if there is something
  11262. // beyond the end index (it's inclusive too).
  11263. if (end + 1 < dest.Length)
  11264. {
  11265. return pref + src + dest.GetSublist(end + 1, -1);
  11266. }
  11267. else
  11268. {
  11269. return pref + src;
  11270. }
  11271. }
  11272. // If start is less than or equal to zero, then
  11273. // the new list is simply a prefix. We still need to
  11274. // figure out any necessary surgery to the destination
  11275. // based upon end. Note that if end exceeds the upper
  11276. // bound in this case, the entire destination list
  11277. // is removed.
  11278. else if (start == 0)
  11279. {
  11280. if (end + 1 < dest.Length)
  11281. return src + dest.GetSublist(end + 1, -1);
  11282. else
  11283. return src;
  11284. }
  11285. else // Start < 0
  11286. {
  11287. if (end + 1 < dest.Length)
  11288. return dest.GetSublist(end + 1, -1);
  11289. else
  11290. return new LSL_List();
  11291. }
  11292. }
  11293. // Finally, if start > end, we strip away a prefix and
  11294. // a suffix, to leave the list that sits <between> ens
  11295. // and start, and then tag on the src list. AT least
  11296. // that's my interpretation. We can get sublist to do
  11297. // this for us. Note that one, or both of the indices
  11298. // might have been negative.
  11299. else
  11300. {
  11301. return dest.GetSublist(end + 1, start - 1) + src;
  11302. }
  11303. }
  11304. public void llLoadURL(string avatar_id, string message, string url)
  11305. {
  11306. m_host.AddScriptLPS(1);
  11307. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  11308. if (null != dm)
  11309. dm.SendUrlToUser(
  11310. new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
  11311. ScriptSleep(m_sleepMsOnLoadURL);
  11312. }
  11313. public void llParcelMediaCommandList(LSL_List commandList)
  11314. {
  11315. // TODO: Not implemented yet (missing in libomv?):
  11316. // PARCEL_MEDIA_COMMAND_LOOP_SET float loop Use this to get or set the parcel's media loop duration. (1.19.1 RC0 or later)
  11317. m_host.AddScriptLPS(1);
  11318. // according to the docs, this command only works if script owner and land owner are the same
  11319. // lets add estate owners and gods, too, and use the generic permission check.
  11320. ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11321. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false)) return;
  11322. bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
  11323. byte loop = 0;
  11324. LandData landData = landObject.LandData;
  11325. string url = landData.MediaURL;
  11326. string texture = landData.MediaID.ToString();
  11327. bool autoAlign = landData.MediaAutoScale != 0;
  11328. string mediaType = ""; // TODO these have to be added as soon as LandData supports it
  11329. string description = "";
  11330. int width = 0;
  11331. int height = 0;
  11332. ParcelMediaCommandEnum? commandToSend = null;
  11333. float time = 0.0f; // default is from start
  11334. uint cmndFlags = 0;
  11335. ScenePresence presence = null;
  11336. int cmd;
  11337. for (int i = 0; i < commandList.Data.Length; i++)
  11338. {
  11339. if(commandList.Data[i] is LSL_Integer)
  11340. cmd = (LSL_Integer)commandList.Data[i];
  11341. else
  11342. cmd = (int)commandList.Data[i];
  11343. ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)cmd;
  11344. switch (command)
  11345. {
  11346. case ParcelMediaCommandEnum.Agent:
  11347. // we send only to one agent
  11348. if ((i + 1) < commandList.Length)
  11349. {
  11350. if (commandList.Data[i + 1] is LSL_String)
  11351. {
  11352. UUID agentID;
  11353. if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out agentID))
  11354. {
  11355. presence = World.GetScenePresence(agentID);
  11356. }
  11357. }
  11358. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key");
  11359. ++i;
  11360. }
  11361. break;
  11362. case ParcelMediaCommandEnum.Loop:
  11363. loop = 1;
  11364. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_LOOP);
  11365. commandToSend = command;
  11366. update = true; //need to send the media update packet to set looping
  11367. break;
  11368. case ParcelMediaCommandEnum.Play:
  11369. loop = 0;
  11370. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PLAY);
  11371. commandToSend = command;
  11372. update = true; //need to send the media update packet to make sure it doesn't loop
  11373. break;
  11374. case ParcelMediaCommandEnum.Pause:
  11375. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PAUSE);
  11376. commandToSend = command;
  11377. break;
  11378. case ParcelMediaCommandEnum.Stop:
  11379. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_STOP);
  11380. commandToSend = command;
  11381. break;
  11382. case ParcelMediaCommandEnum.Unload:
  11383. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_UNLOAD);
  11384. commandToSend = command;
  11385. break;
  11386. case ParcelMediaCommandEnum.Url:
  11387. if ((i + 1) < commandList.Length)
  11388. {
  11389. if (commandList.Data[i + 1] is LSL_String)
  11390. {
  11391. url = (LSL_String)commandList.Data[i + 1];
  11392. update = true;
  11393. }
  11394. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_URL must be a string");
  11395. ++i;
  11396. }
  11397. break;
  11398. case ParcelMediaCommandEnum.Texture:
  11399. if ((i + 1) < commandList.Length)
  11400. {
  11401. if (commandList.Data[i + 1] is LSL_String)
  11402. {
  11403. texture = (LSL_String)commandList.Data[i + 1];
  11404. update = true;
  11405. }
  11406. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or a key");
  11407. ++i;
  11408. }
  11409. break;
  11410. case ParcelMediaCommandEnum.Time:
  11411. if ((i + 1) < commandList.Length)
  11412. {
  11413. if (commandList.Data[i + 1] is LSL_Float)
  11414. {
  11415. time = (float)(LSL_Float)commandList.Data[i + 1];
  11416. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_TIME);
  11417. }
  11418. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TIME must be a float");
  11419. ++i;
  11420. }
  11421. break;
  11422. case ParcelMediaCommandEnum.AutoAlign:
  11423. if ((i + 1) < commandList.Length)
  11424. {
  11425. if (commandList.Data[i + 1] is LSL_Integer)
  11426. {
  11427. autoAlign = (LSL_Integer)commandList.Data[i + 1];
  11428. update = true;
  11429. }
  11430. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer");
  11431. ++i;
  11432. }
  11433. break;
  11434. case ParcelMediaCommandEnum.Type:
  11435. if ((i + 1) < commandList.Length)
  11436. {
  11437. if (commandList.Data[i + 1] is LSL_String)
  11438. {
  11439. mediaType = (LSL_String)commandList.Data[i + 1];
  11440. update = true;
  11441. }
  11442. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string");
  11443. ++i;
  11444. }
  11445. break;
  11446. case ParcelMediaCommandEnum.Desc:
  11447. if ((i + 1) < commandList.Length)
  11448. {
  11449. if (commandList.Data[i + 1] is LSL_String)
  11450. {
  11451. description = (LSL_String)commandList.Data[i + 1];
  11452. update = true;
  11453. }
  11454. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_DESC must be a string");
  11455. ++i;
  11456. }
  11457. break;
  11458. case ParcelMediaCommandEnum.Size:
  11459. if ((i + 2) < commandList.Length)
  11460. {
  11461. if (commandList.Data[i + 1] is LSL_Integer)
  11462. {
  11463. if (commandList.Data[i + 2] is LSL_Integer)
  11464. {
  11465. width = (LSL_Integer)commandList.Data[i + 1];
  11466. height = (LSL_Integer)commandList.Data[i + 2];
  11467. update = true;
  11468. }
  11469. else Error("llParcelMediaCommandList", "The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11470. }
  11471. else Error("llParcelMediaCommandList", "The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11472. i += 2;
  11473. }
  11474. break;
  11475. default:
  11476. NotImplemented("llParcelMediaCommandList", "Parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString());
  11477. break;
  11478. }//end switch
  11479. }//end for
  11480. // if we didn't get a presence, we send to all and change the url
  11481. // if we did get a presence, we only send to the agent specified, and *don't change the land settings*!
  11482. // did something important change or do we only start/stop/pause?
  11483. if (update)
  11484. {
  11485. if (presence == null)
  11486. {
  11487. // we send to all
  11488. landData.MediaID = new UUID(texture);
  11489. landData.MediaAutoScale = autoAlign ? (byte)1 : (byte)0;
  11490. landData.MediaWidth = width;
  11491. landData.MediaHeight = height;
  11492. landData.MediaType = mediaType;
  11493. // do that one last, it will cause a ParcelPropertiesUpdate
  11494. landObject.SetMediaUrl(url);
  11495. // now send to all (non-child) agents in the parcel
  11496. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11497. {
  11498. if (sp.currentParcelUUID == landData.GlobalID)
  11499. {
  11500. sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL,
  11501. landData.MediaID,
  11502. landData.MediaAutoScale,
  11503. mediaType,
  11504. description,
  11505. width, height,
  11506. loop);
  11507. }
  11508. });
  11509. }
  11510. else if (!presence.IsChildAgent)
  11511. {
  11512. // we only send to one (root) agent
  11513. presence.ControllingClient.SendParcelMediaUpdate(url,
  11514. new UUID(texture),
  11515. autoAlign ? (byte)1 : (byte)0,
  11516. mediaType,
  11517. description,
  11518. width, height,
  11519. loop);
  11520. }
  11521. }
  11522. if (commandToSend != null)
  11523. {
  11524. // the commandList contained a start/stop/... command, too
  11525. if (presence == null)
  11526. {
  11527. // send to all (non-child) agents in the parcel
  11528. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11529. {
  11530. if (sp.currentParcelUUID == landData.GlobalID)
  11531. {
  11532. sp.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11533. commandToSend.Value, time);
  11534. }
  11535. });
  11536. }
  11537. else if (!presence.IsChildAgent)
  11538. {
  11539. presence.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11540. commandToSend.Value, time);
  11541. }
  11542. }
  11543. ScriptSleep(m_sleepMsOnParcelMediaCommandList);
  11544. }
  11545. public LSL_List llParcelMediaQuery(LSL_List aList)
  11546. {
  11547. m_host.AddScriptLPS(1);
  11548. LSL_List list = new LSL_List();
  11549. Vector3 pos = m_host.AbsolutePosition;
  11550. ILandObject landObject = World.LandChannel.GetLandObject(pos);
  11551. if(landObject == null)
  11552. return list;
  11553. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false))
  11554. return list;
  11555. LandData land = landObject.LandData;
  11556. if(land == null)
  11557. return list;
  11558. //TO DO: make the implementation for the missing commands
  11559. //PARCEL_MEDIA_COMMAND_LOOP_SET float loop Use this to get or set the parcel's media loop duration. (1.19.1 RC0 or later)
  11560. for (int i = 0; i < aList.Data.Length; i++)
  11561. {
  11562. if (aList.Data[i] != null)
  11563. {
  11564. switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
  11565. {
  11566. case ParcelMediaCommandEnum.Url:
  11567. list.Add(new LSL_String(land.MediaURL));
  11568. break;
  11569. case ParcelMediaCommandEnum.Desc:
  11570. list.Add(new LSL_String(land.MediaDescription));
  11571. break;
  11572. case ParcelMediaCommandEnum.Texture:
  11573. list.Add(new LSL_String(land.MediaID.ToString()));
  11574. break;
  11575. case ParcelMediaCommandEnum.Type:
  11576. list.Add(new LSL_String(land.MediaType));
  11577. break;
  11578. case ParcelMediaCommandEnum.Size:
  11579. list.Add(new LSL_String(land.MediaWidth));
  11580. list.Add(new LSL_String(land.MediaHeight));
  11581. break;
  11582. default:
  11583. ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
  11584. NotImplemented("llParcelMediaQuery", "Parameter not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
  11585. break;
  11586. }
  11587. }
  11588. }
  11589. ScriptSleep(m_sleepMsOnParcelMediaQuery);
  11590. return list;
  11591. }
  11592. public LSL_Integer llModPow(int a, int b, int c)
  11593. {
  11594. m_host.AddScriptLPS(1);
  11595. Int64 tmp = 0;
  11596. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
  11597. ScriptSleep(m_sleepMsOnModPow);
  11598. return Convert.ToInt32(tmp);
  11599. }
  11600. public LSL_Integer llGetInventoryType(string name)
  11601. {
  11602. m_host.AddScriptLPS(1);
  11603. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  11604. if (item == null)
  11605. return -1;
  11606. return item.Type;
  11607. }
  11608. public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
  11609. {
  11610. m_host.AddScriptLPS(1);
  11611. if (quick_pay_buttons.Data.Length < 4)
  11612. {
  11613. int x;
  11614. for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
  11615. {
  11616. quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
  11617. }
  11618. }
  11619. int[] nPrice = new int[5];
  11620. nPrice[0] = price;
  11621. nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
  11622. nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
  11623. nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
  11624. nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
  11625. m_host.ParentGroup.RootPart.PayPrice = nPrice;
  11626. m_host.ParentGroup.HasGroupChanged = true;
  11627. }
  11628. public LSL_Vector llGetCameraPos()
  11629. {
  11630. m_host.AddScriptLPS(1);
  11631. if (m_item.PermsGranter == UUID.Zero)
  11632. return Vector3.Zero;
  11633. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11634. {
  11635. Error("llGetCameraPos", "No permissions to track the camera");
  11636. return Vector3.Zero;
  11637. }
  11638. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11639. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11640. if (presence != null)
  11641. {
  11642. LSL_Vector pos = new LSL_Vector(presence.CameraPosition);
  11643. return pos;
  11644. }
  11645. return Vector3.Zero;
  11646. }
  11647. public LSL_Rotation llGetCameraRot()
  11648. {
  11649. m_host.AddScriptLPS(1);
  11650. if (m_item.PermsGranter == UUID.Zero)
  11651. return Quaternion.Identity;
  11652. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11653. {
  11654. Error("llGetCameraRot", "No permissions to track the camera");
  11655. return Quaternion.Identity;
  11656. }
  11657. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11658. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11659. if (presence != null)
  11660. {
  11661. return new LSL_Rotation(presence.CameraRotation);
  11662. }
  11663. return Quaternion.Identity;
  11664. }
  11665. public void llSetPrimURL(string url)
  11666. {
  11667. m_host.AddScriptLPS(1);
  11668. Deprecated("llSetPrimURL", "Use llSetPrimMediaParams instead");
  11669. ScriptSleep(m_sleepMsOnSetPrimURL);
  11670. }
  11671. public void llRefreshPrimURL()
  11672. {
  11673. m_host.AddScriptLPS(1);
  11674. Deprecated("llRefreshPrimURL");
  11675. ScriptSleep(m_sleepMsOnRefreshPrimURL);
  11676. }
  11677. public LSL_String llEscapeURL(string url)
  11678. {
  11679. m_host.AddScriptLPS(1);
  11680. try
  11681. {
  11682. return Uri.EscapeDataString(url);
  11683. }
  11684. catch (Exception ex)
  11685. {
  11686. return "llEscapeURL: " + ex.ToString();
  11687. }
  11688. }
  11689. public LSL_String llUnescapeURL(string url)
  11690. {
  11691. m_host.AddScriptLPS(1);
  11692. try
  11693. {
  11694. return Uri.UnescapeDataString(url);
  11695. }
  11696. catch (Exception ex)
  11697. {
  11698. return "llUnescapeURL: " + ex.ToString();
  11699. }
  11700. }
  11701. public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
  11702. {
  11703. m_host.AddScriptLPS(1);
  11704. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
  11705. if (detectedParams == null)
  11706. {
  11707. if (m_host.ParentGroup.IsAttachment == true)
  11708. {
  11709. detectedParams = new DetectParams();
  11710. detectedParams.Key = m_host.OwnerID;
  11711. }
  11712. else
  11713. {
  11714. return;
  11715. }
  11716. }
  11717. ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
  11718. if (avatar != null)
  11719. {
  11720. avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
  11721. simname, pos, lookAt);
  11722. }
  11723. ScriptSleep(m_sleepMsOnMapDestination);
  11724. }
  11725. public void llAddToLandBanList(LSL_Key avatar, LSL_Float hours)
  11726. {
  11727. m_host.AddScriptLPS(1);
  11728. UUID key;
  11729. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11730. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11731. {
  11732. int expires = 0;
  11733. if (hours != 0)
  11734. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  11735. if (UUID.TryParse(avatar, out key))
  11736. {
  11737. int idx = land.LandData.ParcelAccessList.FindIndex(
  11738. delegate(LandAccessEntry e)
  11739. {
  11740. if (e.AgentID == key && e.Flags == AccessList.Ban)
  11741. return true;
  11742. return false;
  11743. });
  11744. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  11745. return;
  11746. if (idx != -1)
  11747. land.LandData.ParcelAccessList.RemoveAt(idx);
  11748. LandAccessEntry entry = new LandAccessEntry();
  11749. entry.AgentID = key;
  11750. entry.Flags = AccessList.Ban;
  11751. entry.Expires = expires;
  11752. land.LandData.ParcelAccessList.Add(entry);
  11753. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11754. }
  11755. }
  11756. ScriptSleep(m_sleepMsOnAddToLandBanList);
  11757. }
  11758. public void llRemoveFromLandPassList(string avatar)
  11759. {
  11760. m_host.AddScriptLPS(1);
  11761. UUID key;
  11762. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11763. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  11764. {
  11765. if (UUID.TryParse(avatar, out key))
  11766. {
  11767. int idx = land.LandData.ParcelAccessList.FindIndex(
  11768. delegate(LandAccessEntry e)
  11769. {
  11770. if (e.AgentID == key && e.Flags == AccessList.Access)
  11771. return true;
  11772. return false;
  11773. });
  11774. if (idx != -1)
  11775. {
  11776. land.LandData.ParcelAccessList.RemoveAt(idx);
  11777. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11778. }
  11779. }
  11780. }
  11781. ScriptSleep(m_sleepMsOnRemoveFromLandPassList);
  11782. }
  11783. public void llRemoveFromLandBanList(string avatar)
  11784. {
  11785. m_host.AddScriptLPS(1);
  11786. UUID key;
  11787. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11788. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11789. {
  11790. if (UUID.TryParse(avatar, out key))
  11791. {
  11792. int idx = land.LandData.ParcelAccessList.FindIndex(
  11793. delegate(LandAccessEntry e)
  11794. {
  11795. if (e.AgentID == key && e.Flags == AccessList.Ban)
  11796. return true;
  11797. return false;
  11798. });
  11799. if (idx != -1)
  11800. {
  11801. land.LandData.ParcelAccessList.RemoveAt(idx);
  11802. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11803. }
  11804. }
  11805. }
  11806. ScriptSleep(m_sleepMsOnRemoveFromLandBanList);
  11807. }
  11808. public void llSetCameraParams(LSL_List rules)
  11809. {
  11810. m_host.AddScriptLPS(1);
  11811. // the object we are in
  11812. UUID objectID = m_host.ParentUUID;
  11813. if (objectID == UUID.Zero)
  11814. return;
  11815. // we need the permission first, to know which avatar we want to set the camera for
  11816. UUID agentID = m_item.PermsGranter;
  11817. if (agentID == UUID.Zero)
  11818. return;
  11819. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  11820. return;
  11821. ScenePresence presence = World.GetScenePresence(agentID);
  11822. // we are not interested in child-agents
  11823. if (presence.IsChildAgent) return;
  11824. SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
  11825. object[] data = rules.Data;
  11826. for (int i = 0; i < data.Length; ++i)
  11827. {
  11828. int type;
  11829. try
  11830. {
  11831. type = Convert.ToInt32(data[i++].ToString());
  11832. }
  11833. catch
  11834. {
  11835. Error("llSetCameraParams", string.Format("Invalid camera param type {0}", data[i - 1]));
  11836. return;
  11837. }
  11838. if (i >= data.Length) break; // odd number of entries => ignore the last
  11839. // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
  11840. switch (type)
  11841. {
  11842. case ScriptBaseClass.CAMERA_FOCUS:
  11843. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11844. case ScriptBaseClass.CAMERA_POSITION:
  11845. LSL_Vector v = (LSL_Vector)data[i];
  11846. try
  11847. {
  11848. parameters.Add(type + 1, (float)v.x);
  11849. }
  11850. catch
  11851. {
  11852. switch(type)
  11853. {
  11854. case ScriptBaseClass.CAMERA_FOCUS:
  11855. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter x is invalid");
  11856. return;
  11857. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11858. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter x is invalid");
  11859. return;
  11860. case ScriptBaseClass.CAMERA_POSITION:
  11861. Error("llSetCameraParams", "CAMERA_POSITION: Parameter x is invalid");
  11862. return;
  11863. }
  11864. }
  11865. try
  11866. {
  11867. parameters.Add(type + 2, (float)v.y);
  11868. }
  11869. catch
  11870. {
  11871. switch(type)
  11872. {
  11873. case ScriptBaseClass.CAMERA_FOCUS:
  11874. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter y is invalid");
  11875. return;
  11876. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11877. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter y is invalid");
  11878. return;
  11879. case ScriptBaseClass.CAMERA_POSITION:
  11880. Error("llSetCameraParams", "CAMERA_POSITION: Parameter y is invalid");
  11881. return;
  11882. }
  11883. }
  11884. try
  11885. {
  11886. parameters.Add(type + 3, (float)v.z);
  11887. }
  11888. catch
  11889. {
  11890. switch(type)
  11891. {
  11892. case ScriptBaseClass.CAMERA_FOCUS:
  11893. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter z is invalid");
  11894. return;
  11895. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11896. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter z is invalid");
  11897. return;
  11898. case ScriptBaseClass.CAMERA_POSITION:
  11899. Error("llSetCameraParams", "CAMERA_POSITION: Parameter z is invalid");
  11900. return;
  11901. }
  11902. }
  11903. break;
  11904. default:
  11905. // TODO: clean that up as soon as the implicit casts are in
  11906. if (data[i] is LSL_Float)
  11907. parameters.Add(type, (float)((LSL_Float)data[i]).value);
  11908. else if (data[i] is LSL_Integer)
  11909. parameters.Add(type, (float)((LSL_Integer)data[i]).value);
  11910. else
  11911. {
  11912. try
  11913. {
  11914. parameters.Add(type, Convert.ToSingle(data[i]));
  11915. }
  11916. catch
  11917. {
  11918. Error("llSetCameraParams", string.Format("{0}: Parameter is invalid", type));
  11919. }
  11920. }
  11921. break;
  11922. }
  11923. }
  11924. if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
  11925. }
  11926. public void llClearCameraParams()
  11927. {
  11928. m_host.AddScriptLPS(1);
  11929. // the object we are in
  11930. UUID objectID = m_host.ParentUUID;
  11931. if (objectID == UUID.Zero)
  11932. return;
  11933. // we need the permission first, to know which avatar we want to clear the camera for
  11934. UUID agentID = m_item.PermsGranter;
  11935. if (agentID == UUID.Zero)
  11936. return;
  11937. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  11938. return;
  11939. ScenePresence presence = World.GetScenePresence(agentID);
  11940. // we are not interested in child-agents
  11941. if (presence.IsChildAgent)
  11942. return;
  11943. presence.ControllingClient.SendClearFollowCamProperties(objectID);
  11944. }
  11945. public LSL_Float llListStatistics(int operation, LSL_List src)
  11946. {
  11947. m_host.AddScriptLPS(1);
  11948. switch (operation)
  11949. {
  11950. case ScriptBaseClass.LIST_STAT_RANGE:
  11951. return src.Range();
  11952. case ScriptBaseClass.LIST_STAT_MIN:
  11953. return src.Min();
  11954. case ScriptBaseClass.LIST_STAT_MAX:
  11955. return src.Max();
  11956. case ScriptBaseClass.LIST_STAT_MEAN:
  11957. return src.Mean();
  11958. case ScriptBaseClass.LIST_STAT_MEDIAN:
  11959. return LSL_List.ToDoubleList(src).Median();
  11960. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  11961. return src.NumericLength();
  11962. case ScriptBaseClass.LIST_STAT_STD_DEV:
  11963. return src.StdDev();
  11964. case ScriptBaseClass.LIST_STAT_SUM:
  11965. return src.Sum();
  11966. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  11967. return src.SumSqrs();
  11968. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  11969. return src.GeometricMean();
  11970. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  11971. return src.HarmonicMean();
  11972. default:
  11973. return 0.0;
  11974. }
  11975. }
  11976. public LSL_Integer llGetUnixTime()
  11977. {
  11978. m_host.AddScriptLPS(1);
  11979. return Util.UnixTimeSinceEpoch();
  11980. }
  11981. public LSL_Integer llGetParcelFlags(LSL_Vector pos)
  11982. {
  11983. m_host.AddScriptLPS(1);
  11984. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).LandData.Flags;
  11985. }
  11986. public LSL_Integer llGetRegionFlags()
  11987. {
  11988. m_host.AddScriptLPS(1);
  11989. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  11990. if (estate == null)
  11991. return 67108864;
  11992. return (int)estate.GetRegionFlags();
  11993. }
  11994. public LSL_String llXorBase64StringsCorrect(string str1, string str2)
  11995. {
  11996. m_host.AddScriptLPS(1);
  11997. if (str1 == String.Empty)
  11998. return String.Empty;
  11999. if (str2 == String.Empty)
  12000. return str1;
  12001. int len = str2.Length;
  12002. if ((len % 4) != 0) // LL is EVIL!!!!
  12003. {
  12004. while (str2.EndsWith("="))
  12005. str2 = str2.Substring(0, str2.Length - 1);
  12006. len = str2.Length;
  12007. int mod = len % 4;
  12008. if (mod == 1)
  12009. str2 = str2.Substring(0, str2.Length - 1);
  12010. else if (mod == 2)
  12011. str2 += "==";
  12012. else if (mod == 3)
  12013. str2 += "=";
  12014. }
  12015. byte[] data1;
  12016. byte[] data2;
  12017. try
  12018. {
  12019. data1 = Convert.FromBase64String(str1);
  12020. data2 = Convert.FromBase64String(str2);
  12021. }
  12022. catch (Exception)
  12023. {
  12024. return new LSL_String(String.Empty);
  12025. }
  12026. byte[] d2 = new Byte[data1.Length];
  12027. int pos = 0;
  12028. if (data1.Length <= data2.Length)
  12029. {
  12030. Array.Copy(data2, 0, d2, 0, data1.Length);
  12031. }
  12032. else
  12033. {
  12034. while (pos < data1.Length)
  12035. {
  12036. len = data1.Length - pos;
  12037. if (len > data2.Length)
  12038. len = data2.Length;
  12039. Array.Copy(data2, 0, d2, pos, len);
  12040. pos += len;
  12041. }
  12042. }
  12043. for (pos = 0 ; pos < data1.Length ; pos++ )
  12044. data1[pos] ^= d2[pos];
  12045. return Convert.ToBase64String(data1);
  12046. }
  12047. public LSL_Key llHTTPRequest(string url, LSL_List parameters, string body)
  12048. {
  12049. m_host.AddScriptLPS(1);
  12050. IHttpRequestModule httpScriptMod = m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>();
  12051. if(httpScriptMod == null)
  12052. return "";
  12053. if(!httpScriptMod.CheckThrottle(m_host.LocalId, m_host.OwnerID))
  12054. return UUID.Zero.ToString();
  12055. List<string> param = new List<string>();
  12056. bool ok;
  12057. Int32 flag;
  12058. int nCustomHeaders = 0;
  12059. for (int i = 0; i < parameters.Data.Length; i += 2)
  12060. {
  12061. ok = Int32.TryParse(parameters.Data[i].ToString(), out flag);
  12062. if (!ok || flag < 0 ||
  12063. flag > (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE)
  12064. {
  12065. Error("llHTTPRequest", "Parameter " + i.ToString() + " is an invalid flag");
  12066. }
  12067. param.Add(parameters.Data[i].ToString()); //Add parameter flag
  12068. if (flag != (int)HttpRequestConstants.HTTP_CUSTOM_HEADER)
  12069. {
  12070. param.Add(parameters.Data[i+1].ToString()); //Add parameter value
  12071. }
  12072. else
  12073. {
  12074. //Parameters are in pairs and custom header takes
  12075. //arguments in pairs so adjust for header marker.
  12076. ++i;
  12077. //Maximum of 8 headers are allowed based on the
  12078. //Second Life documentation for llHTTPRequest.
  12079. for (int count = 1; count <= 8; ++count)
  12080. {
  12081. if(nCustomHeaders >= 8)
  12082. {
  12083. Error("llHTTPRequest", "Max number of custom headers is 8, excess ignored");
  12084. break;
  12085. }
  12086. //Enough parameters remaining for (another) header?
  12087. if (parameters.Data.Length - i < 2)
  12088. {
  12089. //There must be at least one name/value pair for custom header
  12090. if (count == 1)
  12091. Error("llHTTPRequest", "Missing name/value for custom header at parameter " + i.ToString());
  12092. break;
  12093. }
  12094. if (HttpStandardHeaders.Contains(parameters.Data[i].ToString(), StringComparer.OrdinalIgnoreCase))
  12095. Error("llHTTPRequest", "Name is invalid as a custom header at parameter " + i.ToString());
  12096. param.Add(parameters.Data[i].ToString());
  12097. param.Add(parameters.Data[i+1].ToString());
  12098. nCustomHeaders++;
  12099. //Have we reached the end of the list of headers?
  12100. //End is marked by a string with a single digit.
  12101. if (i + 2 >= parameters.Data.Length ||
  12102. Char.IsDigit(parameters.Data[i + 2].ToString()[0]))
  12103. {
  12104. break;
  12105. }
  12106. i += 2;
  12107. }
  12108. }
  12109. }
  12110. Vector3 position = m_host.AbsolutePosition;
  12111. Vector3 velocity = m_host.Velocity;
  12112. Quaternion rotation = m_host.RotationOffset;
  12113. string ownerName = String.Empty;
  12114. ScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
  12115. if (scenePresence == null)
  12116. ownerName = resolveName(m_host.OwnerID);
  12117. else
  12118. ownerName = scenePresence.Name;
  12119. RegionInfo regionInfo = World.RegionInfo;
  12120. Dictionary<string, string> httpHeaders = new Dictionary<string, string>();
  12121. string shard = "OpenSim";
  12122. IConfigSource config = m_ScriptEngine.ConfigSource;
  12123. if (config.Configs["Network"] != null)
  12124. {
  12125. shard = config.Configs["Network"].GetString("shard", shard);
  12126. }
  12127. httpHeaders["X-SecondLife-Shard"] = shard;
  12128. httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
  12129. httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
  12130. httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY);
  12131. httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
  12132. httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
  12133. httpHeaders["X-SecondLife-Local-Rotation"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000})", rotation.X, rotation.Y, rotation.Z, rotation.W);
  12134. httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
  12135. httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
  12136. string userAgent = config.Configs["Network"].GetString("user_agent", null);
  12137. if (userAgent != null)
  12138. httpHeaders["User-Agent"] = userAgent;
  12139. // See if the URL contains any header hacks
  12140. string[] urlParts = url.Split(new char[] {'\n'});
  12141. if (urlParts.Length > 1)
  12142. {
  12143. // Iterate the passed headers and parse them
  12144. for (int i = 1 ; i < urlParts.Length ; i++ )
  12145. {
  12146. // The rest of those would be added to the body in SL.
  12147. // Let's not do that.
  12148. if (urlParts[i] == String.Empty)
  12149. break;
  12150. // See if this could be a valid header
  12151. string[] headerParts = urlParts[i].Split(new char[] {':'}, 2);
  12152. if (headerParts.Length != 2)
  12153. continue;
  12154. string headerName = headerParts[0].Trim();
  12155. string headerValue = headerParts[1].Trim();
  12156. // Filter out headers that could be used to abuse
  12157. // another system or cloak the request
  12158. if (headerName.ToLower() == "x-secondlife-shard" ||
  12159. headerName.ToLower() == "x-secondlife-object-name" ||
  12160. headerName.ToLower() == "x-secondlife-object-key" ||
  12161. headerName.ToLower() == "x-secondlife-region" ||
  12162. headerName.ToLower() == "x-secondlife-local-position" ||
  12163. headerName.ToLower() == "x-secondlife-local-velocity" ||
  12164. headerName.ToLower() == "x-secondlife-local-rotation" ||
  12165. headerName.ToLower() == "x-secondlife-owner-name" ||
  12166. headerName.ToLower() == "x-secondlife-owner-key" ||
  12167. headerName.ToLower() == "connection" ||
  12168. headerName.ToLower() == "content-length" ||
  12169. headerName.ToLower() == "from" ||
  12170. headerName.ToLower() == "host" ||
  12171. headerName.ToLower() == "proxy-authorization" ||
  12172. headerName.ToLower() == "referer" ||
  12173. headerName.ToLower() == "trailer" ||
  12174. headerName.ToLower() == "transfer-encoding" ||
  12175. headerName.ToLower() == "via" ||
  12176. headerName.ToLower() == "authorization")
  12177. continue;
  12178. httpHeaders[headerName] = headerValue;
  12179. }
  12180. // Finally, strip any protocol specifier from the URL
  12181. url = urlParts[0].Trim();
  12182. int idx = url.IndexOf(" HTTP/");
  12183. if (idx != -1)
  12184. url = url.Substring(0, idx);
  12185. }
  12186. string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
  12187. Regex r = new Regex(authregex);
  12188. int[] gnums = r.GetGroupNumbers();
  12189. Match m = r.Match(url);
  12190. if (m.Success)
  12191. {
  12192. for (int i = 1; i < gnums.Length; i++)
  12193. {
  12194. //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
  12195. //CaptureCollection cc = g.Captures;
  12196. }
  12197. if (m.Groups.Count == 5)
  12198. {
  12199. httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
  12200. url = m.Groups[1].ToString() + m.Groups[4].ToString();
  12201. }
  12202. }
  12203. HttpInitialRequestStatus status;
  12204. UUID reqID = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body, out status);
  12205. if (status == HttpInitialRequestStatus.DISALLOWED_BY_FILTER)
  12206. Error("llHttpRequest", string.Format("Request to {0} disallowed by filter", url));
  12207. if (reqID != UUID.Zero)
  12208. return reqID.ToString();
  12209. else
  12210. return "";
  12211. }
  12212. public void llHTTPResponse(LSL_Key id, int status, string body)
  12213. {
  12214. // Partial implementation: support for parameter flags needed
  12215. // see http://wiki.secondlife.com/wiki/llHTTPResponse
  12216. m_host.AddScriptLPS(1);
  12217. if (m_UrlModule != null)
  12218. m_UrlModule.HttpResponse(new UUID(id), status,body);
  12219. }
  12220. public void llResetLandBanList()
  12221. {
  12222. m_host.AddScriptLPS(1);
  12223. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12224. if (land.OwnerID == m_host.OwnerID && land.ParcelAccessList.Count > 0)
  12225. {
  12226. var todelete = new List<LandAccessEntry>();
  12227. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12228. {
  12229. if (entry.Flags == AccessList.Ban)
  12230. todelete.Add(entry);
  12231. }
  12232. foreach (LandAccessEntry entry in todelete)
  12233. land.ParcelAccessList.Remove(entry);
  12234. }
  12235. ScriptSleep(m_sleepMsOnResetLandBanList);
  12236. }
  12237. public void llResetLandPassList()
  12238. {
  12239. m_host.AddScriptLPS(1);
  12240. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12241. if (land.OwnerID == m_host.OwnerID && land.ParcelAccessList.Count > 0)
  12242. {
  12243. var todelete = new List<LandAccessEntry>();
  12244. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12245. {
  12246. if (entry.Flags == AccessList.Access)
  12247. todelete.Add(entry);
  12248. }
  12249. foreach (LandAccessEntry entry in todelete)
  12250. land.ParcelAccessList.Remove(entry);
  12251. }
  12252. ScriptSleep(m_sleepMsOnResetLandPassList);
  12253. }
  12254. public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
  12255. {
  12256. m_host.AddScriptLPS(1);
  12257. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12258. if (lo == null)
  12259. return 0;
  12260. IPrimCounts pc = lo.PrimCounts;
  12261. if (sim_wide != ScriptBaseClass.FALSE)
  12262. {
  12263. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12264. {
  12265. return pc.Simulator;
  12266. }
  12267. else
  12268. {
  12269. // counts not implemented yet
  12270. return 0;
  12271. }
  12272. }
  12273. else
  12274. {
  12275. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12276. return pc.Total;
  12277. else if (category == ScriptBaseClass.PARCEL_COUNT_OWNER)
  12278. return pc.Owner;
  12279. else if (category == ScriptBaseClass.PARCEL_COUNT_GROUP)
  12280. return pc.Group;
  12281. else if (category == ScriptBaseClass.PARCEL_COUNT_OTHER)
  12282. return pc.Others;
  12283. else if (category == ScriptBaseClass.PARCEL_COUNT_SELECTED)
  12284. return pc.Selected;
  12285. else if (category == ScriptBaseClass.PARCEL_COUNT_TEMP)
  12286. return 0; // counts not implemented yet
  12287. }
  12288. return 0;
  12289. }
  12290. public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
  12291. {
  12292. m_host.AddScriptLPS(1);
  12293. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12294. LSL_List ret = new LSL_List();
  12295. if (land != null)
  12296. {
  12297. foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
  12298. {
  12299. ret.Add(new LSL_String(detectedParams.Key.ToString()));
  12300. ret.Add(new LSL_Integer(detectedParams.Value));
  12301. }
  12302. }
  12303. ScriptSleep(m_sleepMsOnGetParcelPrimOwners);
  12304. return ret;
  12305. }
  12306. public LSL_Integer llGetObjectPrimCount(LSL_Key object_id)
  12307. {
  12308. m_host.AddScriptLPS(1);
  12309. UUID id;
  12310. if(!UUID.TryParse(object_id, out id))
  12311. return 0;
  12312. SceneObjectPart part = World.GetSceneObjectPart(id);
  12313. if (part == null)
  12314. return 0;
  12315. return part.ParentGroup.PrimCount;
  12316. }
  12317. public LSL_Integer llGetParcelMaxPrims(LSL_Vector pos, int sim_wide)
  12318. {
  12319. m_host.AddScriptLPS(1);
  12320. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12321. if (lo == null)
  12322. return 0;
  12323. if (sim_wide != 0)
  12324. return lo.GetSimulatorMaxPrimCount();
  12325. else
  12326. return lo.GetParcelMaxPrimCount();
  12327. }
  12328. public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
  12329. {
  12330. m_host.AddScriptLPS(1);
  12331. LandData land = World.GetLandData(pos);
  12332. if (land == null)
  12333. {
  12334. return new LSL_List(0);
  12335. }
  12336. LSL_List ret = new LSL_List();
  12337. foreach (object o in param.Data)
  12338. {
  12339. switch (o.ToString())
  12340. {
  12341. case "0":
  12342. ret.Add(new LSL_String(land.Name));
  12343. break;
  12344. case "1":
  12345. ret.Add(new LSL_String(land.Description));
  12346. break;
  12347. case "2":
  12348. ret.Add(new LSL_Key(land.OwnerID.ToString()));
  12349. break;
  12350. case "3":
  12351. ret.Add(new LSL_Key(land.GroupID.ToString()));
  12352. break;
  12353. case "4":
  12354. ret.Add(new LSL_Integer(land.Area));
  12355. break;
  12356. case "5":
  12357. ret.Add(new LSL_Key(land.GlobalID.ToString()));
  12358. break;
  12359. case "64":
  12360. ret.Add(new LSL_Integer(land.Dwell));
  12361. break;
  12362. default:
  12363. ret.Add(new LSL_Integer(0));
  12364. break;
  12365. }
  12366. }
  12367. return ret;
  12368. }
  12369. public LSL_String llStringTrim(LSL_String src, LSL_Integer type)
  12370. {
  12371. m_host.AddScriptLPS(1);
  12372. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return ((string)src).TrimStart(); }
  12373. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return ((string)src).TrimEnd(); }
  12374. if (type == (int)ScriptBaseClass.STRING_TRIM) { return ((string)src).Trim(); }
  12375. return src;
  12376. }
  12377. public LSL_List llGetObjectDetails(LSL_Key id, LSL_List args)
  12378. {
  12379. m_host.AddScriptLPS(1);
  12380. LSL_List ret = new LSL_List();
  12381. UUID key = new UUID();
  12382. if (!UUID.TryParse(id, out key))
  12383. return ret;
  12384. int count = 0;
  12385. ScenePresence av = World.GetScenePresence(key);
  12386. if (av != null)
  12387. {
  12388. List<SceneObjectGroup> Attachments = null;
  12389. int? nAnimated = null;
  12390. foreach (object o in args.Data)
  12391. {
  12392. switch (int.Parse(o.ToString()))
  12393. {
  12394. case ScriptBaseClass.OBJECT_NAME:
  12395. ret.Add(new LSL_String(av.Firstname + " " + av.Lastname));
  12396. break;
  12397. case ScriptBaseClass.OBJECT_DESC:
  12398. ret.Add(new LSL_String(""));
  12399. break;
  12400. case ScriptBaseClass.OBJECT_POS:
  12401. Vector3 avpos;
  12402. if (av.ParentID != 0 && av.ParentPart != null &&
  12403. av.ParentPart.ParentGroup != null && av.ParentPart.ParentGroup.RootPart != null )
  12404. {
  12405. avpos = av.OffsetPosition;
  12406. if(!av.LegacySitOffsets)
  12407. {
  12408. Vector3 sitOffset = (Zrot(av.Rotation)) * (av.Appearance.AvatarHeight * 0.02638f *2.0f);
  12409. avpos -= sitOffset;
  12410. }
  12411. SceneObjectPart sitRoot = av.ParentPart.ParentGroup.RootPart;
  12412. avpos = sitRoot.GetWorldPosition() + avpos * sitRoot.GetWorldRotation();
  12413. }
  12414. else
  12415. avpos = av.AbsolutePosition;
  12416. ret.Add(new LSL_Vector((double)avpos.X, (double)avpos.Y, (double)avpos.Z));
  12417. break;
  12418. case ScriptBaseClass.OBJECT_ROT:
  12419. Quaternion avrot = av.GetWorldRotation();
  12420. ret.Add(new LSL_Rotation(avrot));
  12421. break;
  12422. case ScriptBaseClass.OBJECT_VELOCITY:
  12423. Vector3 avvel = av.GetWorldVelocity();
  12424. ret.Add(new LSL_Vector((double)avvel.X, (double)avvel.Y, (double)avvel.Z));
  12425. break;
  12426. case ScriptBaseClass.OBJECT_OWNER:
  12427. ret.Add(new LSL_Key((string)id));
  12428. break;
  12429. case ScriptBaseClass.OBJECT_GROUP:
  12430. ret.Add(new LSL_String(UUID.Zero.ToString()));
  12431. break;
  12432. case ScriptBaseClass.OBJECT_CREATOR:
  12433. ret.Add(new LSL_Key(UUID.Zero.ToString()));
  12434. break;
  12435. // For the following 8 see the Object version below
  12436. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12437. ret.Add(new LSL_Integer(av.RunningScriptCount()));
  12438. break;
  12439. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12440. ret.Add(new LSL_Integer(av.ScriptCount()));
  12441. break;
  12442. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12443. ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
  12444. break;
  12445. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12446. ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
  12447. break;
  12448. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12449. ret.Add(new LSL_Integer(1));
  12450. break;
  12451. case ScriptBaseClass.OBJECT_SERVER_COST:
  12452. ret.Add(new LSL_Float(0));
  12453. break;
  12454. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12455. ret.Add(new LSL_Float(0));
  12456. break;
  12457. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12458. ret.Add(new LSL_Float(0));
  12459. break;
  12460. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12461. ret.Add(new LSL_Float(0));
  12462. break;
  12463. case ScriptBaseClass.OBJECT_ROOT:
  12464. SceneObjectPart p = av.ParentPart;
  12465. if (p != null)
  12466. {
  12467. ret.Add(new LSL_String(p.ParentGroup.RootPart.UUID.ToString()));
  12468. }
  12469. else
  12470. {
  12471. ret.Add(new LSL_Key((string)id));
  12472. }
  12473. break;
  12474. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12475. ret.Add(new LSL_Integer(0));
  12476. break;
  12477. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE: // Pathfinding
  12478. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_AVATAR));
  12479. break;
  12480. case ScriptBaseClass.OBJECT_PHYSICS:
  12481. ret.Add(new LSL_Integer(0));
  12482. break;
  12483. case ScriptBaseClass.OBJECT_PHANTOM:
  12484. ret.Add(new LSL_Integer(0));
  12485. break;
  12486. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  12487. ret.Add(new LSL_Integer(0));
  12488. break;
  12489. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  12490. ret.Add(new LSL_Integer(-1));
  12491. break;
  12492. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  12493. ret.Add(new LSL_Float(0));
  12494. break;
  12495. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  12496. LSL_Float shapeType;
  12497. if (av.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] != 0)
  12498. shapeType = new LSL_Float(1);
  12499. else
  12500. shapeType = new LSL_Float(0);
  12501. ret.Add(shapeType);
  12502. break;
  12503. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  12504. ret.Add(new LSL_Key(ScriptBaseClass.NULL_KEY));
  12505. break;
  12506. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  12507. ret.Add(new LSL_Integer(0));
  12508. break;
  12509. case ScriptBaseClass.OBJECT_OMEGA:
  12510. ret.Add(new LSL_Vector(Vector3.Zero));
  12511. break;
  12512. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  12513. if (Attachments == null)
  12514. Attachments = av.GetAttachments();
  12515. count = 0;
  12516. try
  12517. {
  12518. foreach (SceneObjectGroup Attachment in Attachments)
  12519. count += Attachment.PrimCount;
  12520. }
  12521. catch { };
  12522. ret.Add(new LSL_Integer(count));
  12523. break;
  12524. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  12525. if (Attachments == null)
  12526. Attachments = av.GetAttachments();
  12527. count = 0;
  12528. try
  12529. {
  12530. foreach (SceneObjectGroup Attachment in Attachments)
  12531. {
  12532. SceneObjectPart[] parts = Attachment.Parts;
  12533. int nparts = parts.Count();
  12534. for(int i = 0; i < nparts; i++)
  12535. count += parts[i].Inventory.Count;
  12536. }
  12537. } catch { };
  12538. ret.Add(new LSL_Integer(count));
  12539. break;
  12540. case ScriptBaseClass.OBJECT_REZZER_KEY:
  12541. ret.Add(new LSL_Key((string)id));
  12542. break;
  12543. case ScriptBaseClass.OBJECT_GROUP_TAG:
  12544. ret.Add(new LSL_String(av.Grouptitle));
  12545. break;
  12546. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  12547. ret.Add(new LSL_Integer(0));
  12548. break;
  12549. case ScriptBaseClass.OBJECT_ATTACHED_SLOTS_AVAILABLE:
  12550. ret.Add(new LSL_Integer(Constants.MaxAgentAttachments - av.GetAttachmentsCount()));
  12551. break;
  12552. case ScriptBaseClass.OBJECT_CREATION_TIME:
  12553. ret.Add(new LSL_String(""));
  12554. break;
  12555. case ScriptBaseClass.OBJECT_SELECT_COUNT:
  12556. ret.Add(new LSL_Integer(0));
  12557. break;
  12558. case ScriptBaseClass.OBJECT_SIT_COUNT:
  12559. ret.Add(new LSL_Integer(0));
  12560. break;
  12561. case ScriptBaseClass.OBJECT_ANIMATED_COUNT:
  12562. count = 0;
  12563. if (nAnimated.HasValue)
  12564. count = nAnimated.Value;
  12565. else
  12566. {
  12567. if (Attachments == null)
  12568. Attachments = av.GetAttachments();
  12569. try
  12570. {
  12571. for(int i = 0; i < Attachments.Count;++i)
  12572. {
  12573. if(Attachments[i].RootPart.Shape.MeshFlagEntry)
  12574. ++count;
  12575. }
  12576. }
  12577. catch { };
  12578. nAnimated = count;
  12579. }
  12580. ret.Add(new LSL_Integer(count));
  12581. break;
  12582. case ScriptBaseClass.OBJECT_ANIMATED_SLOTS_AVAILABLE:
  12583. count = 0;
  12584. if (nAnimated.HasValue)
  12585. count = nAnimated.Value;
  12586. else
  12587. {
  12588. if (Attachments == null)
  12589. Attachments = av.GetAttachments();
  12590. count = 0;
  12591. try
  12592. {
  12593. for (int i = 0; i < Attachments.Count; ++i)
  12594. {
  12595. if (Attachments[i].RootPart.Shape.MeshFlagEntry)
  12596. ++count;
  12597. }
  12598. }
  12599. catch { };
  12600. nAnimated = count;
  12601. }
  12602. count = 2 - count; // for now hardcoded max (simulator features, viewers settings, etc)
  12603. if(count < 0)
  12604. count = 0;
  12605. ret.Add(new LSL_Integer(count));
  12606. break;
  12607. default:
  12608. // Invalid or unhandled constant.
  12609. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  12610. break;
  12611. }
  12612. }
  12613. return ret;
  12614. }
  12615. SceneObjectPart obj = World.GetSceneObjectPart(key);
  12616. if (obj != null)
  12617. {
  12618. foreach (object o in args.Data)
  12619. {
  12620. switch (int.Parse(o.ToString()))
  12621. {
  12622. case ScriptBaseClass.OBJECT_NAME:
  12623. ret.Add(new LSL_String(obj.Name));
  12624. break;
  12625. case ScriptBaseClass.OBJECT_DESC:
  12626. ret.Add(new LSL_String(obj.Description));
  12627. break;
  12628. case ScriptBaseClass.OBJECT_POS:
  12629. Vector3 opos = obj.AbsolutePosition;
  12630. ret.Add(new LSL_Vector(opos.X, opos.Y, opos.Z));
  12631. break;
  12632. case ScriptBaseClass.OBJECT_ROT:
  12633. Quaternion rot = Quaternion.Identity;
  12634. if (obj.ParentGroup.IsAttachment)
  12635. {
  12636. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12637. if (sp != null)
  12638. rot = sp.GetWorldRotation();
  12639. }
  12640. else
  12641. {
  12642. if (obj.ParentGroup.RootPart == obj)
  12643. rot = obj.ParentGroup.GroupRotation;
  12644. else
  12645. rot = obj.GetWorldRotation();
  12646. }
  12647. LSL_Rotation objrot = new LSL_Rotation(rot);
  12648. ret.Add(objrot);
  12649. break;
  12650. case ScriptBaseClass.OBJECT_VELOCITY:
  12651. Vector3 vel = Vector3.Zero;
  12652. if (obj.ParentGroup.IsAttachment)
  12653. {
  12654. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12655. if (sp != null)
  12656. vel = sp.GetWorldVelocity();
  12657. }
  12658. else
  12659. {
  12660. vel = obj.Velocity;
  12661. }
  12662. ret.Add(vel);
  12663. break;
  12664. case ScriptBaseClass.OBJECT_OWNER:
  12665. ret.Add(new LSL_String(obj.OwnerID.ToString()));
  12666. break;
  12667. case ScriptBaseClass.OBJECT_GROUP:
  12668. ret.Add(new LSL_String(obj.GroupID.ToString()));
  12669. break;
  12670. case ScriptBaseClass.OBJECT_CREATOR:
  12671. ret.Add(new LSL_String(obj.CreatorID.ToString()));
  12672. break;
  12673. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12674. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
  12675. break;
  12676. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12677. ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
  12678. break;
  12679. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12680. // The value returned in SL for mono scripts is 65536 * number of active scripts
  12681. // and 16384 * number of active scripts for LSO. since llGetFreememory
  12682. // is coded to give the LSO value use it here
  12683. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
  12684. break;
  12685. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12686. // Average cpu time in seconds per simulator frame expended on all scripts in the object
  12687. ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
  12688. break;
  12689. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12690. // according to the SL wiki A prim or linkset will have prim
  12691. // equivalent of the number of prims in a linkset if it does not
  12692. // contain a mesh anywhere in the link set or is not a normal prim
  12693. // The value returned in SL for normal prims is prim count
  12694. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  12695. break;
  12696. // costs below may need to be diferent for root parts, need to check
  12697. case ScriptBaseClass.OBJECT_SERVER_COST:
  12698. // The linden calculation is here
  12699. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
  12700. // The value returned in SL for normal prims looks like the prim count
  12701. ret.Add(new LSL_Float(0));
  12702. break;
  12703. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12704. // The value returned in SL for normal prims is prim count * 0.06
  12705. ret.Add(new LSL_Float(obj.StreamingCost));
  12706. break;
  12707. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12708. // The value returned in SL for normal prims is prim count
  12709. ret.Add(new LSL_Float(obj.PhysicsCost));
  12710. break;
  12711. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12712. ret.Add(new LSL_Float(0));
  12713. break;
  12714. case ScriptBaseClass.OBJECT_ROOT:
  12715. ret.Add(new LSL_String(obj.ParentGroup.RootPart.UUID.ToString()));
  12716. break;
  12717. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12718. ret.Add(new LSL_Integer(obj.ParentGroup.AttachmentPoint));
  12719. break;
  12720. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE:
  12721. byte pcode = obj.Shape.PCode;
  12722. if (obj.ParentGroup.AttachmentPoint != 0
  12723. || pcode == (byte)PCode.Grass
  12724. || pcode == (byte)PCode.Tree
  12725. || pcode == (byte)PCode.NewTree)
  12726. {
  12727. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_OTHER));
  12728. }
  12729. else
  12730. {
  12731. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_LEGACY_LINKSET));
  12732. }
  12733. break;
  12734. case ScriptBaseClass.OBJECT_PHYSICS:
  12735. if (obj.ParentGroup.AttachmentPoint != 0)
  12736. {
  12737. ret.Add(new LSL_Integer(0)); // Always false if attached
  12738. }
  12739. else
  12740. {
  12741. ret.Add(new LSL_Integer(obj.ParentGroup.UsesPhysics ? 1 : 0));
  12742. }
  12743. break;
  12744. case ScriptBaseClass.OBJECT_PHANTOM:
  12745. if (obj.ParentGroup.AttachmentPoint != 0)
  12746. {
  12747. ret.Add(new LSL_Integer(0)); // Always false if attached
  12748. }
  12749. else
  12750. {
  12751. ret.Add(new LSL_Integer(obj.ParentGroup.IsPhantom ? 1 : 0));
  12752. }
  12753. break;
  12754. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  12755. ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0));
  12756. break;
  12757. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  12758. ret.Add(new LSL_Integer(0));
  12759. break;
  12760. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  12761. ret.Add(new LSL_Float(0));
  12762. break;
  12763. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  12764. ret.Add(new LSL_Float(-1));
  12765. break;
  12766. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  12767. ret.Add(new LSL_Key(obj.ParentGroup.LastOwnerID.ToString()));
  12768. break;
  12769. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  12770. ret.Add(new LSL_Integer(obj.ClickAction));
  12771. break;
  12772. case ScriptBaseClass.OBJECT_OMEGA:
  12773. ret.Add(new LSL_Vector(obj.AngularVelocity));
  12774. break;
  12775. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  12776. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  12777. break;
  12778. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  12779. SceneObjectPart[] parts = obj.ParentGroup.Parts;
  12780. count = 0;
  12781. for(int i = 0; i < parts.Count(); i++)
  12782. count += parts[i].Inventory.Count;
  12783. ret.Add(new LSL_Integer(count));
  12784. break;
  12785. case ScriptBaseClass.OBJECT_REZZER_KEY:
  12786. ret.Add(new LSL_Key(obj.ParentGroup.RezzerID.ToString()));
  12787. break;
  12788. case ScriptBaseClass.OBJECT_GROUP_TAG:
  12789. ret.Add(new LSL_String(String.Empty));
  12790. break;
  12791. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  12792. if (obj.ParentGroup.AttachmentPoint != 0 && obj.ParentGroup.FromItemID == UUID.Zero)
  12793. {
  12794. ret.Add(new LSL_Integer(1));
  12795. }
  12796. else
  12797. {
  12798. ret.Add(new LSL_Integer(0));
  12799. }
  12800. break;
  12801. case ScriptBaseClass.OBJECT_ATTACHED_SLOTS_AVAILABLE:
  12802. ret.Add(new LSL_Integer(0));
  12803. break;
  12804. case ScriptBaseClass.OBJECT_CREATION_TIME:
  12805. DateTime date = Util.ToDateTime(m_host.ParentGroup.RootPart.CreationDate);
  12806. ret.Add(new LSL_String(date.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture)));
  12807. break;
  12808. case ScriptBaseClass.OBJECT_SELECT_COUNT:
  12809. ret.Add(new LSL_Integer(0));
  12810. break;
  12811. case ScriptBaseClass.OBJECT_SIT_COUNT:
  12812. ret.Add(new LSL_Integer(m_host.ParentGroup.GetSittingAvatarsCount()));
  12813. break;
  12814. case ScriptBaseClass.OBJECT_ANIMATED_COUNT:
  12815. if(m_host.ParentGroup.RootPart.Shape.MeshFlagEntry)
  12816. ret.Add(new LSL_Integer(1));
  12817. else
  12818. ret.Add(new LSL_Integer(0));
  12819. break;
  12820. case ScriptBaseClass.OBJECT_ANIMATED_SLOTS_AVAILABLE:
  12821. ret.Add(new LSL_Integer(0));
  12822. break;
  12823. default:
  12824. // Invalid or unhandled constant.
  12825. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  12826. break;
  12827. }
  12828. }
  12829. }
  12830. return ret;
  12831. }
  12832. internal UUID GetScriptByName(string name)
  12833. {
  12834. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  12835. if (item == null || item.Type != 10)
  12836. return UUID.Zero;
  12837. return item.ItemID;
  12838. }
  12839. /// <summary>
  12840. /// Reports the script error in the viewer's Script Warning/Error dialog and shouts it on the debug channel.
  12841. /// </summary>
  12842. /// <param name="command">The name of the command that generated the error.</param>
  12843. /// <param name="message">The error message to report to the user.</param>
  12844. internal void Error(string command, string message)
  12845. {
  12846. string text = command + ": " + message;
  12847. if (text.Length > 1023)
  12848. {
  12849. text = text.Substring(0, 1023);
  12850. }
  12851. World.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, ScriptBaseClass.DEBUG_CHANNEL,
  12852. m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  12853. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  12854. if (wComm != null)
  12855. {
  12856. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, text);
  12857. }
  12858. }
  12859. /// <summary>
  12860. /// Reports that the command is not implemented as a script error.
  12861. /// </summary>
  12862. /// <param name="command">The name of the command that is not implemented.</param>
  12863. /// <param name="message">Additional information to report to the user. (Optional)</param>
  12864. internal void NotImplemented(string command, string message = "")
  12865. {
  12866. if (throwErrorOnNotImplemented)
  12867. {
  12868. if (message != "")
  12869. {
  12870. message = " - " + message;
  12871. }
  12872. throw new NotImplementedException("Command not implemented: " + command + message);
  12873. }
  12874. else
  12875. {
  12876. string text = "Command not implemented";
  12877. if (message != "")
  12878. {
  12879. text = text + " - " + message;
  12880. }
  12881. Error(command, text);
  12882. }
  12883. }
  12884. /// <summary>
  12885. /// Reports that the command is deprecated as a script error.
  12886. /// </summary>
  12887. /// <param name="command">The name of the command that is deprecated.</param>
  12888. /// <param name="message">Additional information to report to the user. (Optional)</param>
  12889. internal void Deprecated(string command, string message = "")
  12890. {
  12891. string text = "Command deprecated";
  12892. if (message != "")
  12893. {
  12894. text = text + " - " + message;
  12895. }
  12896. Error(command, text);
  12897. }
  12898. public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  12899. protected void WithNotecard(UUID assetID, AssetRequestCallback cb)
  12900. {
  12901. World.AssetService.Get(assetID.ToString(), this,
  12902. delegate(string i, object sender, AssetBase a)
  12903. {
  12904. UUID uuid = UUID.Zero;
  12905. UUID.TryParse(i, out uuid);
  12906. cb(uuid, a);
  12907. });
  12908. }
  12909. public LSL_Key llGetNumberOfNotecardLines(string name)
  12910. {
  12911. m_host.AddScriptLPS(1);
  12912. UUID assetID = UUID.Zero;
  12913. if (!UUID.TryParse(name, out assetID))
  12914. {
  12915. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  12916. if (item != null && item.Type == 7)
  12917. assetID = item.AssetID;
  12918. }
  12919. if (assetID == UUID.Zero)
  12920. {
  12921. // => complain loudly, as specified by the LSL docs
  12922. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  12923. return UUID.Zero.ToString();
  12924. }
  12925. string reqIdentifier = UUID.Random().ToString();
  12926. // was: UUID tid = tid = AsyncCommands.
  12927. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  12928. if (NotecardCache.IsCached(assetID))
  12929. {
  12930. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(assetID).ToString());
  12931. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  12932. return tid.ToString();
  12933. }
  12934. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  12935. {
  12936. if (a == null || a.Type != 7)
  12937. {
  12938. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  12939. return;
  12940. }
  12941. NotecardCache.Cache(id, a.Data);
  12942. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(id).ToString());
  12943. });
  12944. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  12945. return tid.ToString();
  12946. }
  12947. public LSL_Key llGetNotecardLine(string name, int line)
  12948. {
  12949. m_host.AddScriptLPS(1);
  12950. UUID assetID = UUID.Zero;
  12951. if (!UUID.TryParse(name, out assetID))
  12952. {
  12953. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  12954. if (item != null && item.Type == 7)
  12955. assetID = item.AssetID;
  12956. }
  12957. if (assetID == UUID.Zero)
  12958. {
  12959. // => complain loudly, as specified by the LSL docs
  12960. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  12961. return UUID.Zero.ToString();
  12962. }
  12963. string reqIdentifier = UUID.Random().ToString();
  12964. // was: UUID tid = tid = AsyncCommands.
  12965. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  12966. if (NotecardCache.IsCached(assetID))
  12967. {
  12968. AsyncCommands.DataserverPlugin.DataserverReply(
  12969. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  12970. ScriptSleep(m_sleepMsOnGetNotecardLine);
  12971. return tid.ToString();
  12972. }
  12973. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  12974. {
  12975. if (a == null || a.Type != 7)
  12976. {
  12977. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  12978. return;
  12979. }
  12980. //string data = Encoding.UTF8.GetString(a.Data);
  12981. //m_log.Debug(data);
  12982. NotecardCache.Cache(id, a.Data);
  12983. AsyncCommands.DataserverPlugin.DataserverReply(
  12984. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  12985. });
  12986. ScriptSleep(m_sleepMsOnGetNotecardLine);
  12987. return tid.ToString();
  12988. }
  12989. public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc)
  12990. {
  12991. UUID id;
  12992. if (!UUID.TryParse(prim, out id))
  12993. return;
  12994. SceneObjectPart obj = World.GetSceneObjectPart(id);
  12995. if (obj == null || obj.OwnerID != m_host.OwnerID)
  12996. return;
  12997. uint rulesParsed = 0;
  12998. LSL_List remaining = SetPrimParams(obj, rules, originFunc, ref rulesParsed);
  12999. while (remaining.Length > 2)
  13000. {
  13001. int linknumber;
  13002. try
  13003. {
  13004. linknumber = remaining.GetLSLIntegerItem(0);
  13005. }
  13006. catch (InvalidCastException)
  13007. {
  13008. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_LINK_TARGET parameter must be integer", rulesParsed));
  13009. return;
  13010. }
  13011. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  13012. if (entities.Count == 0)
  13013. break;
  13014. rules = remaining.GetSublist(1, -1);
  13015. foreach (ISceneEntity entity in entities)
  13016. {
  13017. if (entity is SceneObjectPart)
  13018. remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
  13019. else
  13020. remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
  13021. }
  13022. }
  13023. }
  13024. public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  13025. {
  13026. LSL_List result = new LSL_List();
  13027. UUID id;
  13028. if (!UUID.TryParse(prim, out id))
  13029. return result;
  13030. SceneObjectPart obj = World.GetSceneObjectPart(id);
  13031. if (obj == null || obj.OwnerID != m_host.OwnerID)
  13032. return result;
  13033. LSL_List remaining = GetPrimParams(obj, rules, ref result);
  13034. while (remaining.Length > 1)
  13035. {
  13036. int linknumber;
  13037. try
  13038. {
  13039. linknumber = remaining.GetLSLIntegerItem(0);
  13040. }
  13041. catch (InvalidCastException)
  13042. {
  13043. Error("", string.Format("Error PRIM_LINK_TARGET: parameter must be integer"));
  13044. return result;
  13045. }
  13046. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  13047. if (entities.Count == 0)
  13048. break;
  13049. rules = remaining.GetSublist(1, -1);
  13050. foreach (ISceneEntity entity in entities)
  13051. {
  13052. if (entity is SceneObjectPart)
  13053. remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
  13054. else
  13055. remaining = GetPrimParams((ScenePresence)entity, rules, ref result);
  13056. }
  13057. }
  13058. return result;
  13059. }
  13060. public void print(string str)
  13061. {
  13062. // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print
  13063. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  13064. if (ossl != null)
  13065. {
  13066. ossl.CheckThreatLevel(ThreatLevel.High, "print");
  13067. m_log.Info("LSL print():" + str);
  13068. }
  13069. }
  13070. public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
  13071. {
  13072. List<SceneObjectPart> parts = GetLinkParts(link);
  13073. if (parts.Count < 1)
  13074. return 0;
  13075. return GetNumberOfSides(parts[0]);
  13076. }
  13077. private string Name2Username(string name)
  13078. {
  13079. string[] parts = name.Split(new char[] {' '});
  13080. if (parts.Length < 2)
  13081. return name.ToLower();
  13082. if (parts[1] == "Resident")
  13083. return parts[0].ToLower();
  13084. return name.Replace(" ", ".").ToLower();
  13085. }
  13086. public LSL_String llGetUsername(LSL_Key id)
  13087. {
  13088. return Name2Username(llKey2Name(id));
  13089. }
  13090. public LSL_Key llRequestUsername(string id)
  13091. {
  13092. UUID rq = UUID.Random();
  13093. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  13094. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
  13095. return rq.ToString();
  13096. }
  13097. public LSL_String llGetDisplayName(string id)
  13098. {
  13099. return llKey2Name(id);
  13100. }
  13101. public LSL_Key llRequestDisplayName(string id)
  13102. {
  13103. UUID rq = UUID.Random();
  13104. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  13105. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
  13106. return rq.ToString();
  13107. }
  13108. /*
  13109. private void SayShoutTimerElapsed(Object sender, ElapsedEventArgs args)
  13110. {
  13111. m_SayShoutCount = 0;
  13112. }
  13113. */
  13114. private struct Tri
  13115. {
  13116. public Vector3 p1;
  13117. public Vector3 p2;
  13118. public Vector3 p3;
  13119. }
  13120. private bool InBoundingBox(ScenePresence avatar, Vector3 point)
  13121. {
  13122. float height = avatar.Appearance.AvatarHeight;
  13123. Vector3 b1 = avatar.AbsolutePosition + new Vector3(-0.22f, -0.22f, -height/2);
  13124. Vector3 b2 = avatar.AbsolutePosition + new Vector3(0.22f, 0.22f, height/2);
  13125. if (point.X > b1.X && point.X < b2.X &&
  13126. point.Y > b1.Y && point.Y < b2.Y &&
  13127. point.Z > b1.Z && point.Z < b2.Z)
  13128. return true;
  13129. return false;
  13130. }
  13131. private ContactResult[] AvatarIntersection(Vector3 rayStart, Vector3 rayEnd, bool skipPhys)
  13132. {
  13133. List<ContactResult> contacts = new List<ContactResult>();
  13134. Vector3 ab = rayEnd - rayStart;
  13135. float ablen = ab.Length();
  13136. World.ForEachScenePresence(delegate(ScenePresence sp)
  13137. {
  13138. if(skipPhys && sp.PhysicsActor != null)
  13139. return;
  13140. Vector3 ac = sp.AbsolutePosition - rayStart;
  13141. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / ablen);
  13142. if (d > 1.5)
  13143. return;
  13144. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13145. if (d2 > 0)
  13146. return;
  13147. double dp = Math.Sqrt(Vector3.Mag(ac) * Vector3.Mag(ac) - d * d);
  13148. Vector3 p = rayStart + Vector3.Divide(Vector3.Multiply(ab, (float)dp), (float)Vector3.Mag(ab));
  13149. if (!InBoundingBox(sp, p))
  13150. return;
  13151. ContactResult result = new ContactResult ();
  13152. result.ConsumerID = sp.LocalId;
  13153. result.Depth = Vector3.Distance(rayStart, p);
  13154. result.Normal = Vector3.Zero;
  13155. result.Pos = p;
  13156. contacts.Add(result);
  13157. });
  13158. return contacts.ToArray();
  13159. }
  13160. private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom)
  13161. {
  13162. Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13163. List<ContactResult> contacts = new List<ContactResult>();
  13164. Vector3 ab = rayEnd - rayStart;
  13165. World.ForEachSOG(delegate(SceneObjectGroup group)
  13166. {
  13167. if (m_host.ParentGroup == group)
  13168. return;
  13169. if (group.IsAttachment)
  13170. return;
  13171. if (group.RootPart.PhysActor == null)
  13172. {
  13173. if (!includePhantom)
  13174. return;
  13175. }
  13176. else
  13177. {
  13178. if (group.RootPart.PhysActor.IsPhysical)
  13179. {
  13180. if (!includePhysical)
  13181. return;
  13182. }
  13183. else
  13184. {
  13185. if (!includeNonPhysical)
  13186. return;
  13187. }
  13188. }
  13189. // Find the radius ouside of which we don't even need to hit test
  13190. float minX;
  13191. float maxX;
  13192. float minY;
  13193. float maxY;
  13194. float minZ;
  13195. float maxZ;
  13196. float radius = 0.0f;
  13197. group.GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  13198. if (Math.Abs(minX) > radius)
  13199. radius = Math.Abs(minX);
  13200. if (Math.Abs(minY) > radius)
  13201. radius = Math.Abs(minY);
  13202. if (Math.Abs(minZ) > radius)
  13203. radius = Math.Abs(minZ);
  13204. if (Math.Abs(maxX) > radius)
  13205. radius = Math.Abs(maxX);
  13206. if (Math.Abs(maxY) > radius)
  13207. radius = Math.Abs(maxY);
  13208. if (Math.Abs(maxZ) > radius)
  13209. radius = Math.Abs(maxZ);
  13210. radius = radius*1.413f;
  13211. Vector3 ac = group.AbsolutePosition - rayStart;
  13212. // Vector3 bc = group.AbsolutePosition - rayEnd;
  13213. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  13214. // Too far off ray, don't bother
  13215. if (d > radius)
  13216. return;
  13217. // Behind ray, drop
  13218. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13219. if (d2 > 0)
  13220. return;
  13221. ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13222. EntityIntersection intersection = group.TestIntersection(ray, true, false);
  13223. // Miss.
  13224. if (!intersection.HitTF)
  13225. return;
  13226. Vector3 b1 = group.AbsolutePosition + new Vector3(minX, minY, minZ);
  13227. Vector3 b2 = group.AbsolutePosition + new Vector3(maxX, maxY, maxZ);
  13228. //m_log.DebugFormat("[LLCASTRAY]: min<{0},{1},{2}>, max<{3},{4},{5}> = hitp<{6},{7},{8}>", b1.X,b1.Y,b1.Z,b2.X,b2.Y,b2.Z,intersection.ipoint.X,intersection.ipoint.Y,intersection.ipoint.Z);
  13229. if (!(intersection.ipoint.X >= b1.X && intersection.ipoint.X <= b2.X &&
  13230. intersection.ipoint.Y >= b1.Y && intersection.ipoint.Y <= b2.Y &&
  13231. intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z))
  13232. return;
  13233. ContactResult result = new ContactResult ();
  13234. result.ConsumerID = group.LocalId;
  13235. // result.Depth = intersection.distance;
  13236. result.Normal = intersection.normal;
  13237. result.Pos = intersection.ipoint;
  13238. result.Depth = Vector3.Mag(rayStart - result.Pos);
  13239. contacts.Add(result);
  13240. });
  13241. return contacts.ToArray();
  13242. }
  13243. private ContactResult? GroundIntersection(Vector3 rayStart, Vector3 rayEnd)
  13244. {
  13245. double[,] heightfield = World.Heightmap.GetDoubles();
  13246. List<ContactResult> contacts = new List<ContactResult>();
  13247. double min = 2048.0;
  13248. double max = 0.0;
  13249. // Find the min and max of the heightfield
  13250. for (int x = 0 ; x < World.Heightmap.Width ; x++)
  13251. {
  13252. for (int y = 0 ; y < World.Heightmap.Height ; y++)
  13253. {
  13254. if (heightfield[x, y] > max)
  13255. max = heightfield[x, y];
  13256. if (heightfield[x, y] < min)
  13257. min = heightfield[x, y];
  13258. }
  13259. }
  13260. // A ray extends past rayEnd, but doesn't go back before
  13261. // rayStart. If the start is above the highest point of the ground
  13262. // and the ray goes up, we can't hit the ground. Ever.
  13263. if (rayStart.Z > max && rayEnd.Z >= rayStart.Z)
  13264. return null;
  13265. // Same for going down
  13266. if (rayStart.Z < min && rayEnd.Z <= rayStart.Z)
  13267. return null;
  13268. List<Tri> trilist = new List<Tri>();
  13269. // Create our triangle list
  13270. for (int x = 1 ; x < World.Heightmap.Width ; x++)
  13271. {
  13272. for (int y = 1 ; y < World.Heightmap.Height ; y++)
  13273. {
  13274. Tri t1 = new Tri();
  13275. Tri t2 = new Tri();
  13276. Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
  13277. Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
  13278. Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
  13279. Vector3 p4 = new Vector3(x-1, y, (float)heightfield[x-1, y]);
  13280. t1.p1 = p1;
  13281. t1.p2 = p2;
  13282. t1.p3 = p3;
  13283. t2.p1 = p3;
  13284. t2.p2 = p4;
  13285. t2.p3 = p1;
  13286. trilist.Add(t1);
  13287. trilist.Add(t2);
  13288. }
  13289. }
  13290. // Ray direction
  13291. Vector3 rayDirection = rayEnd - rayStart;
  13292. foreach (Tri t in trilist)
  13293. {
  13294. // Compute triangle plane normal and edges
  13295. Vector3 u = t.p2 - t.p1;
  13296. Vector3 v = t.p3 - t.p1;
  13297. Vector3 n = Vector3.Cross(u, v);
  13298. if (n == Vector3.Zero)
  13299. continue;
  13300. Vector3 w0 = rayStart - t.p1;
  13301. double a = -Vector3.Dot(n, w0);
  13302. double b = Vector3.Dot(n, rayDirection);
  13303. // Not intersecting the plane, or in plane (same thing)
  13304. // Ignoring this MAY cause the ground to not be detected
  13305. // sometimes
  13306. if (Math.Abs(b) < 0.000001)
  13307. continue;
  13308. double r = a / b;
  13309. // ray points away from plane
  13310. if (r < 0.0)
  13311. continue;
  13312. Vector3 ip = rayStart + Vector3.Multiply(rayDirection, (float)r);
  13313. float uu = Vector3.Dot(u, u);
  13314. float uv = Vector3.Dot(u, v);
  13315. float vv = Vector3.Dot(v, v);
  13316. Vector3 w = ip - t.p1;
  13317. float wu = Vector3.Dot(w, u);
  13318. float wv = Vector3.Dot(w, v);
  13319. float d = uv * uv - uu * vv;
  13320. float cs = (uv * wv - vv * wu) / d;
  13321. if (cs < 0 || cs > 1.0)
  13322. continue;
  13323. float ct = (uv * wu - uu * wv) / d;
  13324. if (ct < 0 || (cs + ct) > 1.0)
  13325. continue;
  13326. // Add contact point
  13327. ContactResult result = new ContactResult ();
  13328. result.ConsumerID = 0;
  13329. result.Depth = Vector3.Distance(rayStart, ip);
  13330. result.Normal = n;
  13331. result.Pos = ip;
  13332. contacts.Add(result);
  13333. }
  13334. if (contacts.Count == 0)
  13335. return null;
  13336. contacts.Sort(delegate(ContactResult a, ContactResult b)
  13337. {
  13338. return (int)(a.Depth - b.Depth);
  13339. });
  13340. return contacts[0];
  13341. }
  13342. /*
  13343. // not done:
  13344. private ContactResult[] testRay2NonPhysicalPhantom(Vector3 rayStart, Vector3 raydir, float raylenght)
  13345. {
  13346. ContactResult[] contacts = null;
  13347. World.ForEachSOG(delegate(SceneObjectGroup group)
  13348. {
  13349. if (m_host.ParentGroup == group)
  13350. return;
  13351. if (group.IsAttachment)
  13352. return;
  13353. if(group.RootPart.PhysActor != null)
  13354. return;
  13355. contacts = group.RayCastGroupPartsOBBNonPhysicalPhantom(rayStart, raydir, raylenght);
  13356. });
  13357. return contacts;
  13358. }
  13359. */
  13360. public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
  13361. {
  13362. // Use llCastRay V3 if configured
  13363. if (m_useCastRayV3)
  13364. return llCastRayV3(start, end, options);
  13365. LSL_List list = new LSL_List();
  13366. m_host.AddScriptLPS(1);
  13367. Vector3 rayStart = start;
  13368. Vector3 rayEnd = end;
  13369. Vector3 dir = rayEnd - rayStart;
  13370. float dist = dir.Length();
  13371. int count = 1;
  13372. bool detectPhantom = false;
  13373. int dataFlags = 0;
  13374. int rejectTypes = 0;
  13375. for (int i = 0; i < options.Length; i += 2)
  13376. {
  13377. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13378. count = options.GetLSLIntegerItem(i + 1);
  13379. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13380. detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
  13381. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13382. dataFlags = options.GetLSLIntegerItem(i + 1);
  13383. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13384. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13385. }
  13386. if (count > 16)
  13387. count = 16;
  13388. List<ContactResult> results = new List<ContactResult>();
  13389. bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
  13390. bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
  13391. bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
  13392. bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
  13393. bool rejectHost = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOST) != 0);
  13394. bool rejectHostGroup = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOSTGROUP) != 0);
  13395. if (World.SupportsRayCastFiltered())
  13396. {
  13397. if (dist == 0)
  13398. return list;
  13399. RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull;
  13400. if (checkTerrain)
  13401. rayfilter |= RayFilterFlags.land;
  13402. if (checkAgents)
  13403. rayfilter |= RayFilterFlags.agent;
  13404. if (checkPhysical)
  13405. rayfilter |= RayFilterFlags.physical;
  13406. if (checkNonPhysical)
  13407. rayfilter |= RayFilterFlags.nonphysical;
  13408. if (detectPhantom)
  13409. rayfilter |= RayFilterFlags.LSLPhantom;
  13410. Vector3 direction = dir * ( 1/dist);
  13411. if(rayfilter == 0)
  13412. {
  13413. list.Add(new LSL_Integer(0));
  13414. return list;
  13415. }
  13416. // get some more contacts to sort ???
  13417. int physcount = 4 * count;
  13418. if (physcount > 20)
  13419. physcount = 20;
  13420. object physresults;
  13421. physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter);
  13422. if (physresults == null)
  13423. {
  13424. // list.Add(new LSL_Integer(-3)); // timeout error
  13425. // return list;
  13426. results = new List<ContactResult>();
  13427. }
  13428. else
  13429. results = (List<ContactResult>)physresults;
  13430. // for now physics doesn't detect sitted avatars so do it outside physics
  13431. if (checkAgents)
  13432. {
  13433. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, true);
  13434. foreach (ContactResult r in agentHits)
  13435. results.Add(r);
  13436. }
  13437. // TODO: Replace this with a better solution. ObjectIntersection can only
  13438. // detect nonphysical phantoms. They are detected by virtue of being
  13439. // nonphysical (e.g. no PhysActor) so will not conflict with detecting
  13440. // physicsl phantoms as done by the physics scene
  13441. // We don't want anything else but phantoms here.
  13442. if (detectPhantom)
  13443. {
  13444. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, false, false, true);
  13445. foreach (ContactResult r in objectHits)
  13446. results.Add(r);
  13447. }
  13448. // Double check this because of current ODE distance problems
  13449. if (checkTerrain && dist > 60)
  13450. {
  13451. bool skipGroundCheck = false;
  13452. foreach (ContactResult c in results)
  13453. {
  13454. if (c.ConsumerID == 0) // Physics gave us a ground collision
  13455. skipGroundCheck = true;
  13456. }
  13457. if (!skipGroundCheck)
  13458. {
  13459. float tmp = dir.X * dir.X + dir.Y * dir.Y;
  13460. if(tmp > 2500)
  13461. {
  13462. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13463. if (groundContact != null)
  13464. results.Add((ContactResult)groundContact);
  13465. }
  13466. }
  13467. }
  13468. }
  13469. else
  13470. {
  13471. if (checkAgents)
  13472. {
  13473. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, false);
  13474. foreach (ContactResult r in agentHits)
  13475. results.Add(r);
  13476. }
  13477. if (checkPhysical || checkNonPhysical || detectPhantom)
  13478. {
  13479. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom);
  13480. for (int iter = 0; iter < objectHits.Length; iter++)
  13481. {
  13482. // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler.
  13483. objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart);
  13484. results.Add(objectHits[iter]);
  13485. }
  13486. }
  13487. if (checkTerrain)
  13488. {
  13489. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13490. if (groundContact != null)
  13491. results.Add((ContactResult)groundContact);
  13492. }
  13493. }
  13494. results.Sort(delegate(ContactResult a, ContactResult b)
  13495. {
  13496. return a.Depth.CompareTo(b.Depth);
  13497. });
  13498. int values = 0;
  13499. SceneObjectGroup thisgrp = m_host.ParentGroup;
  13500. foreach (ContactResult result in results)
  13501. {
  13502. if (result.Depth > dist)
  13503. continue;
  13504. // physics ray can return colisions with host prim
  13505. if (rejectHost && m_host.LocalId == result.ConsumerID)
  13506. continue;
  13507. UUID itemID = UUID.Zero;
  13508. int linkNum = 0;
  13509. SceneObjectPart part = World.GetSceneObjectPart(result.ConsumerID);
  13510. // It's a prim!
  13511. if (part != null)
  13512. {
  13513. if (rejectHostGroup && part.ParentGroup == thisgrp)
  13514. continue;
  13515. if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
  13516. itemID = part.ParentGroup.UUID;
  13517. else
  13518. itemID = part.UUID;
  13519. linkNum = part.LinkNum;
  13520. }
  13521. else
  13522. {
  13523. ScenePresence sp = World.GetScenePresence(result.ConsumerID);
  13524. /// It it a boy? a girl?
  13525. if (sp != null)
  13526. itemID = sp.UUID;
  13527. }
  13528. list.Add(new LSL_String(itemID.ToString()));
  13529. list.Add(new LSL_String(result.Pos.ToString()));
  13530. if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
  13531. list.Add(new LSL_Integer(linkNum));
  13532. if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
  13533. list.Add(new LSL_Vector(result.Normal));
  13534. values++;
  13535. if (values >= count)
  13536. break;
  13537. }
  13538. list.Add(new LSL_Integer(values));
  13539. return list;
  13540. }
  13541. /// <summary>
  13542. /// Implementation of llCastRay similar to SL 2015-04-21.
  13543. /// http://wiki.secondlife.com/wiki/LlCastRay
  13544. /// Uses pure geometry, bounding shapes, meshing and no physics
  13545. /// for prims, sculpts, meshes, avatars and terrain.
  13546. /// Implements all flags, reject types and data flags.
  13547. /// Can handle both objects/groups and prims/parts, by config.
  13548. /// May sometimes be inaccurate owing to calculation precision,
  13549. /// meshing detail level and a bug in libopenmetaverse PrimMesher.
  13550. /// </summary>
  13551. public LSL_List llCastRayV3(LSL_Vector start, LSL_Vector end, LSL_List options)
  13552. {
  13553. m_host.AddScriptLPS(1);
  13554. LSL_List result = new LSL_List();
  13555. // Prepare throttle data
  13556. int calledMs = Environment.TickCount;
  13557. Stopwatch stopWatch = new Stopwatch();
  13558. stopWatch.Start();
  13559. UUID regionId = World.RegionInfo.RegionID;
  13560. UUID userId = UUID.Zero;
  13561. int msAvailable = 0;
  13562. // Throttle per owner when attachment or "vehicle" (sat upon)
  13563. if (m_host.ParentGroup.IsAttachment || m_host.ParentGroup.GetSittingAvatarsCount() > 0)
  13564. {
  13565. userId = m_host.OwnerID;
  13566. msAvailable = m_msPerAvatarInCastRay;
  13567. }
  13568. // Throttle per parcel when not attachment or vehicle
  13569. else
  13570. {
  13571. LandData land = World.GetLandData(m_host.GetWorldPosition());
  13572. if (land != null)
  13573. msAvailable = m_msPerRegionInCastRay * land.Area / 65536;
  13574. }
  13575. // Clamp for "oversized" parcels on varregions
  13576. if (msAvailable > m_msMaxInCastRay)
  13577. msAvailable = m_msMaxInCastRay;
  13578. // Check throttle data
  13579. int fromCalledMs = calledMs - m_msThrottleInCastRay;
  13580. lock (m_castRayCalls)
  13581. {
  13582. for (int i = m_castRayCalls.Count - 1; i >= 0; i--)
  13583. {
  13584. // Delete old calls from throttle data
  13585. if (m_castRayCalls[i].CalledMs < fromCalledMs)
  13586. m_castRayCalls.RemoveAt(i);
  13587. // Use current region (in multi-region sims)
  13588. else if (m_castRayCalls[i].RegionId == regionId)
  13589. {
  13590. // Reduce available time with recent calls
  13591. if (m_castRayCalls[i].UserId == userId)
  13592. msAvailable -= m_castRayCalls[i].UsedMs;
  13593. }
  13594. }
  13595. // Return failure if not enough available time
  13596. if (msAvailable < m_msMinInCastRay)
  13597. {
  13598. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_CAST_TIME_EXCEEDED));
  13599. return result;
  13600. }
  13601. }
  13602. // Initialize
  13603. List<RayHit> rayHits = new List<RayHit>();
  13604. float tol = m_floatToleranceInCastRay;
  13605. Vector3 pos1Ray = start;
  13606. Vector3 pos2Ray = end;
  13607. // Get input options
  13608. int rejectTypes = 0;
  13609. int dataFlags = 0;
  13610. int maxHits = 1;
  13611. bool notdetectPhantom = true;
  13612. for (int i = 0; i < options.Length; i += 2)
  13613. {
  13614. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13615. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13616. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13617. dataFlags = options.GetLSLIntegerItem(i + 1);
  13618. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13619. maxHits = options.GetLSLIntegerItem(i + 1);
  13620. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13621. notdetectPhantom = (options.GetLSLIntegerItem(i + 1) == 0);
  13622. }
  13623. if (maxHits > m_maxHitsInCastRay)
  13624. maxHits = m_maxHitsInCastRay;
  13625. bool rejectAgents = ((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != 0);
  13626. bool rejectPhysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) != 0);
  13627. bool rejectNonphysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) != 0);
  13628. bool rejectLand = ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) != 0);
  13629. bool getNormal = ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) != 0);
  13630. bool getRootKey = ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) != 0);
  13631. bool getLinkNum = ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) != 0);
  13632. // Calculate some basic parameters
  13633. Vector3 vecRay = pos2Ray - pos1Ray;
  13634. float rayLength = vecRay.Length();
  13635. // Try to get a mesher and return failure if none, degenerate ray, or max 0 hits
  13636. IRendering primMesher = null;
  13637. List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
  13638. if (renderers.Count < 1 || rayLength < tol || m_maxHitsInCastRay < 1)
  13639. {
  13640. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_UNKNOWN));
  13641. return result;
  13642. }
  13643. primMesher = RenderingLoader.LoadRenderer(renderers[0]);
  13644. // Iterate over all objects/groups and prims/parts in region
  13645. World.ForEachSOG(
  13646. delegate(SceneObjectGroup group)
  13647. {
  13648. if(group.IsDeleted || group.RootPart == null)
  13649. return;
  13650. // Check group filters unless part filters are configured
  13651. bool isPhysical = (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical);
  13652. bool isNonphysical = !isPhysical;
  13653. bool isPhantom = group.IsPhantom || group.IsVolumeDetect;
  13654. bool isAttachment = group.IsAttachment;
  13655. if (isPhysical && rejectPhysical)
  13656. return;
  13657. if (isNonphysical && rejectNonphysical)
  13658. return;
  13659. if (isPhantom && notdetectPhantom)
  13660. return;
  13661. if (isAttachment && !m_doAttachmentsInCastRay)
  13662. return;
  13663. // Parse object/group if passed filters
  13664. // Iterate over all prims/parts in object/group
  13665. foreach(SceneObjectPart part in group.Parts)
  13666. {
  13667. // ignore PhysicsShapeType.None as physics engines do
  13668. // or we will get into trouble in future
  13669. if(part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  13670. continue;
  13671. isPhysical = (part.PhysActor != null && part.PhysActor.IsPhysical);
  13672. isNonphysical = !isPhysical;
  13673. isPhantom = ((part.Flags & PrimFlags.Phantom) != 0) ||
  13674. (part.VolumeDetectActive);
  13675. if (isPhysical && rejectPhysical)
  13676. continue;
  13677. if (isNonphysical && rejectNonphysical)
  13678. continue;
  13679. if (isPhantom && notdetectPhantom)
  13680. continue;
  13681. // Parse prim/part and project ray if passed filters
  13682. Vector3 scalePart = part.Scale;
  13683. Vector3 posPart = part.GetWorldPosition();
  13684. Quaternion rotPart = part.GetWorldRotation();
  13685. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  13686. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  13687. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  13688. // Filter parts by shape bounding boxes
  13689. Vector3 shapeBoxMax = new Vector3(0.5f, 0.5f, 0.5f);
  13690. if (!part.Shape.SculptEntry)
  13691. shapeBoxMax = shapeBoxMax * (new Vector3(m_primSafetyCoeffX, m_primSafetyCoeffY, m_primSafetyCoeffZ));
  13692. shapeBoxMax = shapeBoxMax + (new Vector3(tol, tol, tol));
  13693. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  13694. {
  13695. // Prepare data needed to check for ray hits
  13696. RayTrans rayTrans = new RayTrans();
  13697. rayTrans.PartId = part.UUID;
  13698. rayTrans.GroupId = part.ParentGroup.UUID;
  13699. rayTrans.Link = group.PrimCount > 1 ? part.LinkNum : 0;
  13700. rayTrans.ScalePart = scalePart;
  13701. rayTrans.PositionPart = posPart;
  13702. rayTrans.RotationPart = rotPart;
  13703. rayTrans.ShapeNeedsEnds = true;
  13704. rayTrans.Position1Ray = pos1Ray;
  13705. rayTrans.Position1RayProj = pos1RayProj;
  13706. rayTrans.VectorRayProj = pos2RayProj - pos1RayProj;
  13707. // Get detail level depending on type
  13708. int lod = 0;
  13709. // Mesh detail level
  13710. if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  13711. lod = (int)m_meshLodInCastRay;
  13712. // Sculpt detail level
  13713. else if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  13714. lod = (int)m_sculptLodInCastRay;
  13715. // Shape detail level
  13716. else if (!part.Shape.SculptEntry)
  13717. lod = (int)m_primLodInCastRay;
  13718. // Try to get cached mesh if configured
  13719. ulong meshKey = 0;
  13720. FacetedMesh mesh = null;
  13721. if (m_useMeshCacheInCastRay)
  13722. {
  13723. meshKey = part.Shape.GetMeshKey(Vector3.One, (float)(4 << lod));
  13724. lock (m_cachedMeshes)
  13725. {
  13726. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  13727. }
  13728. }
  13729. // Create mesh if no cached mesh
  13730. if (mesh == null)
  13731. {
  13732. // Make an OMV prim to be able to mesh part
  13733. Primitive omvPrim = part.Shape.ToOmvPrimitive(posPart, rotPart);
  13734. byte[] sculptAsset = null;
  13735. if (omvPrim.Sculpt != null)
  13736. sculptAsset = World.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString());
  13737. // When part is mesh, get mesh
  13738. if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type == SculptType.Mesh && sculptAsset != null)
  13739. {
  13740. AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset);
  13741. FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, m_meshLodInCastRay, out mesh);
  13742. meshAsset = null;
  13743. }
  13744. // When part is sculpt, create mesh
  13745. // Quirk: Generated sculpt mesh is about 2.8% smaller in X and Y than visual sculpt.
  13746. else if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type != SculptType.Mesh && sculptAsset != null)
  13747. {
  13748. IJ2KDecoder imgDecoder = World.RequestModuleInterface<IJ2KDecoder>();
  13749. if (imgDecoder != null)
  13750. {
  13751. Image sculpt = imgDecoder.DecodeToImage(sculptAsset);
  13752. if (sculpt != null)
  13753. {
  13754. mesh = primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, m_sculptLodInCastRay);
  13755. sculpt.Dispose();
  13756. }
  13757. }
  13758. }
  13759. // When part is shape, create mesh
  13760. else if (omvPrim.Sculpt == null)
  13761. {
  13762. if (
  13763. omvPrim.PrimData.PathBegin == 0.0 && omvPrim.PrimData.PathEnd == 1.0 &&
  13764. omvPrim.PrimData.PathTaperX == 0.0 && omvPrim.PrimData.PathTaperY == 0.0 &&
  13765. omvPrim.PrimData.PathSkew == 0.0 &&
  13766. omvPrim.PrimData.PathTwist - omvPrim.PrimData.PathTwistBegin == 0.0
  13767. )
  13768. rayTrans.ShapeNeedsEnds = false;
  13769. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_primLodInCastRay);
  13770. }
  13771. // Cache mesh if configured
  13772. if (m_useMeshCacheInCastRay && mesh != null)
  13773. {
  13774. lock(m_cachedMeshes)
  13775. {
  13776. if (!m_cachedMeshes.ContainsKey(meshKey))
  13777. m_cachedMeshes.Add(meshKey, mesh);
  13778. }
  13779. }
  13780. }
  13781. // Check mesh for ray hits
  13782. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  13783. mesh = null;
  13784. }
  13785. }
  13786. }
  13787. );
  13788. // Check avatar filter
  13789. if (!rejectAgents)
  13790. {
  13791. // Iterate over all avatars in region
  13792. World.ForEachRootScenePresence(
  13793. delegate (ScenePresence sp)
  13794. {
  13795. // Get bounding box
  13796. Vector3 lower;
  13797. Vector3 upper;
  13798. BoundingBoxOfScenePresence(sp, out lower, out upper);
  13799. // Parse avatar
  13800. Vector3 scalePart = upper - lower;
  13801. Vector3 posPart = sp.AbsolutePosition;
  13802. Quaternion rotPart = sp.GetWorldRotation();
  13803. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  13804. posPart = posPart + (lower + upper) * 0.5f * rotPart;
  13805. // Project ray
  13806. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  13807. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  13808. // Filter avatars by shape bounding boxes
  13809. Vector3 shapeBoxMax = new Vector3(0.5f + tol, 0.5f + tol, 0.5f + tol);
  13810. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  13811. {
  13812. // Prepare data needed to check for ray hits
  13813. RayTrans rayTrans = new RayTrans();
  13814. rayTrans.PartId = sp.UUID;
  13815. rayTrans.GroupId = sp.ParentPart != null ? sp.ParentPart.ParentGroup.UUID : sp.UUID;
  13816. rayTrans.Link = sp.ParentPart != null ? UUID2LinkNumber(sp.ParentPart, sp.UUID) : 0;
  13817. rayTrans.ScalePart = scalePart;
  13818. rayTrans.PositionPart = posPart;
  13819. rayTrans.RotationPart = rotPart;
  13820. rayTrans.ShapeNeedsEnds = false;
  13821. rayTrans.Position1Ray = pos1Ray;
  13822. rayTrans.Position1RayProj = pos1RayProj;
  13823. rayTrans.VectorRayProj = pos2RayProj - pos1RayProj;
  13824. // Try to get cached mesh if configured
  13825. PrimitiveBaseShape prim = PrimitiveBaseShape.CreateSphere();
  13826. int lod = (int)m_avatarLodInCastRay;
  13827. ulong meshKey = prim.GetMeshKey(Vector3.One, (float)(4 << lod));
  13828. FacetedMesh mesh = null;
  13829. if (m_useMeshCacheInCastRay)
  13830. {
  13831. lock (m_cachedMeshes)
  13832. {
  13833. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  13834. }
  13835. }
  13836. // Create mesh if no cached mesh
  13837. if (mesh == null)
  13838. {
  13839. // Make OMV prim and create mesh
  13840. prim.Scale = scalePart;
  13841. Primitive omvPrim = prim.ToOmvPrimitive(posPart, rotPart);
  13842. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_avatarLodInCastRay);
  13843. // Cache mesh if configured
  13844. if (m_useMeshCacheInCastRay && mesh != null)
  13845. {
  13846. lock(m_cachedMeshes)
  13847. {
  13848. if (!m_cachedMeshes.ContainsKey(meshKey))
  13849. m_cachedMeshes.Add(meshKey, mesh);
  13850. }
  13851. }
  13852. }
  13853. // Check mesh for ray hits
  13854. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  13855. mesh = null;
  13856. }
  13857. }
  13858. );
  13859. }
  13860. // Check terrain filter
  13861. if (!rejectLand)
  13862. {
  13863. // Parse terrain
  13864. // Mesh terrain and check bounding box
  13865. Vector3 lower;
  13866. Vector3 upper;
  13867. List<Tri> triangles = TrisFromHeightmapUnderRay(pos1Ray, pos2Ray, out lower, out upper);
  13868. lower.Z -= tol;
  13869. upper.Z += tol;
  13870. if ((pos1Ray.Z >= lower.Z || pos2Ray.Z >= lower.Z) && (pos1Ray.Z <= upper.Z || pos2Ray.Z <= upper.Z))
  13871. {
  13872. // Prepare data needed to check for ray hits
  13873. RayTrans rayTrans = new RayTrans();
  13874. rayTrans.PartId = UUID.Zero;
  13875. rayTrans.GroupId = UUID.Zero;
  13876. rayTrans.Link = 0;
  13877. rayTrans.ScalePart = new Vector3 (1.0f, 1.0f, 1.0f);
  13878. rayTrans.PositionPart = Vector3.Zero;
  13879. rayTrans.RotationPart = Quaternion.Identity;
  13880. rayTrans.ShapeNeedsEnds = true;
  13881. rayTrans.Position1Ray = pos1Ray;
  13882. rayTrans.Position1RayProj = pos1Ray;
  13883. rayTrans.VectorRayProj = vecRay;
  13884. // Check mesh
  13885. AddRayInTris(triangles, rayTrans, ref rayHits);
  13886. triangles = null;
  13887. }
  13888. }
  13889. // Sort hits by ascending distance
  13890. rayHits.Sort((s1, s2) => s1.Distance.CompareTo(s2.Distance));
  13891. // Check excess hits per part and group
  13892. for (int t = 0; t < 2; t++)
  13893. {
  13894. int maxHitsPerType = 0;
  13895. UUID id = UUID.Zero;
  13896. if (t == 0)
  13897. maxHitsPerType = m_maxHitsPerPrimInCastRay;
  13898. else
  13899. maxHitsPerType = m_maxHitsPerObjectInCastRay;
  13900. // Handle excess hits only when needed
  13901. if (maxHitsPerType < m_maxHitsInCastRay)
  13902. {
  13903. // Find excess hits
  13904. Hashtable hits = new Hashtable();
  13905. for (int i = rayHits.Count - 1; i >= 0; i--)
  13906. {
  13907. if (t == 0)
  13908. id = rayHits[i].PartId;
  13909. else
  13910. id = rayHits[i].GroupId;
  13911. if (hits.ContainsKey(id))
  13912. hits[id] = (int)hits[id] + 1;
  13913. else
  13914. hits[id] = 1;
  13915. }
  13916. // Remove excess hits
  13917. for (int i = rayHits.Count - 1; i >= 0; i--)
  13918. {
  13919. if (t == 0)
  13920. id = rayHits[i].PartId;
  13921. else
  13922. id = rayHits[i].GroupId;
  13923. int hit = (int)hits[id];
  13924. if (hit > m_maxHitsPerPrimInCastRay)
  13925. {
  13926. rayHits.RemoveAt(i);
  13927. hit--;
  13928. hits[id] = hit;
  13929. }
  13930. }
  13931. }
  13932. }
  13933. // Parse hits into result list according to data flags
  13934. int hitCount = rayHits.Count;
  13935. if (hitCount > maxHits)
  13936. hitCount = maxHits;
  13937. for (int i = 0; i < hitCount; i++)
  13938. {
  13939. RayHit rayHit = rayHits[i];
  13940. if (getRootKey)
  13941. result.Add(new LSL_Key(rayHit.GroupId.ToString()));
  13942. else
  13943. result.Add(new LSL_Key(rayHit.PartId.ToString()));
  13944. result.Add(new LSL_Vector(rayHit.Position));
  13945. if (getLinkNum)
  13946. result.Add(new LSL_Integer(rayHit.Link));
  13947. if (getNormal)
  13948. result.Add(new LSL_Vector(rayHit.Normal));
  13949. }
  13950. result.Add(new LSL_Integer(hitCount));
  13951. // Add to throttle data
  13952. stopWatch.Stop();
  13953. lock (m_castRayCalls)
  13954. {
  13955. CastRayCall castRayCall = new CastRayCall();
  13956. castRayCall.RegionId = regionId;
  13957. castRayCall.UserId = userId;
  13958. castRayCall.CalledMs = calledMs;
  13959. castRayCall.UsedMs = (int)stopWatch.ElapsedMilliseconds;
  13960. m_castRayCalls.Add(castRayCall);
  13961. }
  13962. // Return hits
  13963. return result;
  13964. }
  13965. /// <summary>
  13966. /// Struct for transmitting parameters required for finding llCastRay ray hits.
  13967. /// </summary>
  13968. public struct RayTrans
  13969. {
  13970. public UUID PartId;
  13971. public UUID GroupId;
  13972. public int Link;
  13973. public Vector3 ScalePart;
  13974. public Vector3 PositionPart;
  13975. public Quaternion RotationPart;
  13976. public bool ShapeNeedsEnds;
  13977. public Vector3 Position1Ray;
  13978. public Vector3 Position1RayProj;
  13979. public Vector3 VectorRayProj;
  13980. }
  13981. /// <summary>
  13982. /// Struct for llCastRay ray hits.
  13983. /// </summary>
  13984. public struct RayHit
  13985. {
  13986. public UUID PartId;
  13987. public UUID GroupId;
  13988. public int Link;
  13989. public Vector3 Position;
  13990. public Vector3 Normal;
  13991. public float Distance;
  13992. }
  13993. /// <summary>
  13994. /// Struct for llCastRay throttle data.
  13995. /// </summary>
  13996. public struct CastRayCall
  13997. {
  13998. public UUID RegionId;
  13999. public UUID UserId;
  14000. public int CalledMs;
  14001. public int UsedMs;
  14002. }
  14003. /// <summary>
  14004. /// Helper to check if a ray intersects a shape bounding box.
  14005. /// </summary>
  14006. private bool RayIntersectsShapeBox(Vector3 pos1RayProj, Vector3 pos2RayProj, Vector3 shapeBoxMax)
  14007. {
  14008. // Skip if ray can't intersect bounding box;
  14009. Vector3 rayBoxProjMin = Vector3.Min(pos1RayProj, pos2RayProj);
  14010. Vector3 rayBoxProjMax = Vector3.Max(pos1RayProj, pos2RayProj);
  14011. if (
  14012. rayBoxProjMin.X > shapeBoxMax.X || rayBoxProjMin.Y > shapeBoxMax.Y || rayBoxProjMin.Z > shapeBoxMax.Z ||
  14013. rayBoxProjMax.X < -shapeBoxMax.X || rayBoxProjMax.Y < -shapeBoxMax.Y || rayBoxProjMax.Z < -shapeBoxMax.Z
  14014. )
  14015. return false;
  14016. // Check if ray intersect any bounding box side
  14017. int sign = 0;
  14018. float dist = 0.0f;
  14019. Vector3 posProj = Vector3.Zero;
  14020. Vector3 vecRayProj = pos2RayProj - pos1RayProj;
  14021. // Check both X sides unless ray is parallell to them
  14022. if (Math.Abs(vecRayProj.X) > m_floatToleranceInCastRay)
  14023. {
  14024. for (sign = -1; sign <= 1; sign += 2)
  14025. {
  14026. dist = ((float)sign * shapeBoxMax.X - pos1RayProj.X) / vecRayProj.X;
  14027. posProj = pos1RayProj + vecRayProj * dist;
  14028. if (Math.Abs(posProj.Y) <= shapeBoxMax.Y && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  14029. return true;
  14030. }
  14031. }
  14032. // Check both Y sides unless ray is parallell to them
  14033. if (Math.Abs(vecRayProj.Y) > m_floatToleranceInCastRay)
  14034. {
  14035. for (sign = -1; sign <= 1; sign += 2)
  14036. {
  14037. dist = ((float)sign * shapeBoxMax.Y - pos1RayProj.Y) / vecRayProj.Y;
  14038. posProj = pos1RayProj + vecRayProj * dist;
  14039. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  14040. return true;
  14041. }
  14042. }
  14043. // Check both Z sides unless ray is parallell to them
  14044. if (Math.Abs(vecRayProj.Z) > m_floatToleranceInCastRay)
  14045. {
  14046. for (sign = -1; sign <= 1; sign += 2)
  14047. {
  14048. dist = ((float)sign * shapeBoxMax.Z - pos1RayProj.Z) / vecRayProj.Z;
  14049. posProj = pos1RayProj + vecRayProj * dist;
  14050. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Y) <= shapeBoxMax.Y)
  14051. return true;
  14052. }
  14053. }
  14054. // No hits on bounding box so return false
  14055. return false;
  14056. }
  14057. /// <summary>
  14058. /// Helper to parse FacetedMesh for ray hits.
  14059. /// </summary>
  14060. private void AddRayInFacetedMesh(FacetedMesh mesh, RayTrans rayTrans, ref List<RayHit> rayHits)
  14061. {
  14062. if (mesh != null)
  14063. {
  14064. foreach (Face face in mesh.Faces)
  14065. {
  14066. for (int i = 0; i < face.Indices.Count; i += 3)
  14067. {
  14068. Tri triangle = new Tri();
  14069. triangle.p1 = face.Vertices[face.Indices[i]].Position;
  14070. triangle.p2 = face.Vertices[face.Indices[i + 1]].Position;
  14071. triangle.p3 = face.Vertices[face.Indices[i + 2]].Position;
  14072. AddRayInTri(triangle, rayTrans, ref rayHits);
  14073. }
  14074. }
  14075. }
  14076. }
  14077. /// <summary>
  14078. /// Helper to parse Tri (triangle) List for ray hits.
  14079. /// </summary>
  14080. private void AddRayInTris(List<Tri> triangles, RayTrans rayTrans, ref List<RayHit> rayHits)
  14081. {
  14082. foreach (Tri triangle in triangles)
  14083. {
  14084. AddRayInTri(triangle, rayTrans, ref rayHits);
  14085. }
  14086. }
  14087. /// <summary>
  14088. /// Helper to add ray hit in a Tri (triangle).
  14089. /// </summary>
  14090. private void AddRayInTri(Tri triProj, RayTrans rayTrans, ref List<RayHit> rayHits)
  14091. {
  14092. // Check for hit in triangle
  14093. Vector3 posHitProj;
  14094. Vector3 normalProj;
  14095. if (HitRayInTri(triProj, rayTrans.Position1RayProj, rayTrans.VectorRayProj, out posHitProj, out normalProj))
  14096. {
  14097. // Hack to circumvent ghost face bug in PrimMesher by removing hits in (ghost) face plane through shape center
  14098. if (Math.Abs(Vector3.Dot(posHitProj, normalProj)) < m_floatToleranceInCastRay && !rayTrans.ShapeNeedsEnds)
  14099. return;
  14100. // Transform hit and normal to region coordinate system
  14101. Vector3 posHit = rayTrans.PositionPart + (posHitProj * rayTrans.ScalePart) * rayTrans.RotationPart;
  14102. Vector3 normal = Vector3.Normalize((normalProj * rayTrans.ScalePart) * rayTrans.RotationPart);
  14103. // Remove duplicate hits at triangle intersections
  14104. float distance = Vector3.Distance(rayTrans.Position1Ray, posHit);
  14105. for (int i = rayHits.Count - 1; i >= 0; i--)
  14106. {
  14107. if (rayHits[i].PartId != rayTrans.PartId)
  14108. break;
  14109. if (Math.Abs(rayHits[i].Distance - distance) < m_floatTolerance2InCastRay)
  14110. return;
  14111. }
  14112. // Build result data set
  14113. RayHit rayHit = new RayHit();
  14114. rayHit.PartId = rayTrans.PartId;
  14115. rayHit.GroupId = rayTrans.GroupId;
  14116. rayHit.Link = rayTrans.Link;
  14117. rayHit.Position = posHit;
  14118. rayHit.Normal = normal;
  14119. rayHit.Distance = distance;
  14120. rayHits.Add(rayHit);
  14121. }
  14122. }
  14123. /// <summary>
  14124. /// Helper to find ray hit in triangle
  14125. /// </summary>
  14126. bool HitRayInTri(Tri triProj, Vector3 pos1RayProj, Vector3 vecRayProj, out Vector3 posHitProj, out Vector3 normalProj)
  14127. {
  14128. float tol = m_floatToleranceInCastRay;
  14129. posHitProj = Vector3.Zero;
  14130. // Calculate triangle edge vectors
  14131. Vector3 vec1Proj = triProj.p2 - triProj.p1;
  14132. Vector3 vec2Proj = triProj.p3 - triProj.p2;
  14133. Vector3 vec3Proj = triProj.p1 - triProj.p3;
  14134. // Calculate triangle normal
  14135. normalProj = Vector3.Cross(vec1Proj, vec2Proj);
  14136. // Skip if degenerate triangle or ray parallell with triangle plane
  14137. float divisor = Vector3.Dot(vecRayProj, normalProj);
  14138. if (Math.Abs(divisor) < tol)
  14139. return false;
  14140. // Skip if exit and not configured to detect
  14141. if (divisor > tol && !m_detectExitsInCastRay)
  14142. return false;
  14143. // Skip if outside ray ends
  14144. float distanceProj = Vector3.Dot(triProj.p1 - pos1RayProj, normalProj) / divisor;
  14145. if (distanceProj < -tol || distanceProj > 1 + tol)
  14146. return false;
  14147. // Calculate hit position in triangle
  14148. posHitProj = pos1RayProj + vecRayProj * distanceProj;
  14149. // Skip if outside triangle bounding box
  14150. Vector3 triProjMin = Vector3.Min(Vector3.Min(triProj.p1, triProj.p2), triProj.p3);
  14151. Vector3 triProjMax = Vector3.Max(Vector3.Max(triProj.p1, triProj.p2), triProj.p3);
  14152. if (
  14153. posHitProj.X < triProjMin.X - tol || posHitProj.Y < triProjMin.Y - tol || posHitProj.Z < triProjMin.Z - tol ||
  14154. posHitProj.X > triProjMax.X + tol || posHitProj.Y > triProjMax.Y + tol || posHitProj.Z > triProjMax.Z + tol
  14155. )
  14156. return false;
  14157. // Skip if outside triangle
  14158. if (
  14159. Vector3.Dot(Vector3.Cross(vec1Proj, normalProj), posHitProj - triProj.p1) > tol ||
  14160. Vector3.Dot(Vector3.Cross(vec2Proj, normalProj), posHitProj - triProj.p2) > tol ||
  14161. Vector3.Dot(Vector3.Cross(vec3Proj, normalProj), posHitProj - triProj.p3) > tol
  14162. )
  14163. return false;
  14164. // Return hit
  14165. return true;
  14166. }
  14167. /// <summary>
  14168. /// Helper to parse selected parts of HeightMap into a Tri (triangle) List and calculate bounding box.
  14169. /// </summary>
  14170. private List<Tri> TrisFromHeightmapUnderRay(Vector3 posStart, Vector3 posEnd, out Vector3 lower, out Vector3 upper)
  14171. {
  14172. // Get bounding X-Y rectangle of terrain under ray
  14173. lower = Vector3.Min(posStart, posEnd);
  14174. upper = Vector3.Max(posStart, posEnd);
  14175. lower.X = (float)Math.Floor(lower.X);
  14176. lower.Y = (float)Math.Floor(lower.Y);
  14177. float zLower = float.MaxValue;
  14178. upper.X = (float)Math.Ceiling(upper.X);
  14179. upper.Y = (float)Math.Ceiling(upper.Y);
  14180. float zUpper = float.MinValue;
  14181. // Initialize Tri (triangle) List
  14182. List<Tri> triangles = new List<Tri>();
  14183. // Set parsing lane direction to major ray X-Y axis
  14184. Vector3 vec = posEnd - posStart;
  14185. float xAbs = Math.Abs(vec.X);
  14186. float yAbs = Math.Abs(vec.Y);
  14187. bool bigX = true;
  14188. if (yAbs > xAbs)
  14189. {
  14190. bigX = false;
  14191. vec = vec / yAbs;
  14192. }
  14193. else if (xAbs > yAbs || xAbs > 0.0f)
  14194. vec = vec / xAbs;
  14195. else
  14196. vec = new Vector3(1.0f, 1.0f, 0.0f);
  14197. // Simplify by start parsing in lower end of lane
  14198. if ((bigX && vec.X < 0.0f) || (!bigX && vec.Y < 0.0f))
  14199. {
  14200. Vector3 posTemp = posStart;
  14201. posStart = posEnd;
  14202. posEnd = posTemp;
  14203. vec = vec * -1.0f;
  14204. }
  14205. // First 1x1 rectangle under ray
  14206. float xFloorOld = 0.0f;
  14207. float yFloorOld = 0.0f;
  14208. Vector3 pos = posStart;
  14209. float xFloor = (float)Math.Floor(pos.X);
  14210. float yFloor = (float)Math.Floor(pos.Y);
  14211. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14212. // Parse every remaining 1x1 rectangle under ray
  14213. while (pos != posEnd)
  14214. {
  14215. // Next 1x1 rectangle under ray
  14216. xFloorOld = xFloor;
  14217. yFloorOld = yFloor;
  14218. pos = pos + vec;
  14219. // Clip position to 1x1 rectangle border
  14220. xFloor = (float)Math.Floor(pos.X);
  14221. yFloor = (float)Math.Floor(pos.Y);
  14222. if (bigX && pos.X > xFloor)
  14223. {
  14224. pos.Y -= vec.Y * (pos.X - xFloor);
  14225. pos.X = xFloor;
  14226. }
  14227. else if (!bigX && pos.Y > yFloor)
  14228. {
  14229. pos.X -= vec.X * (pos.Y - yFloor);
  14230. pos.Y = yFloor;
  14231. }
  14232. // Last 1x1 rectangle under ray
  14233. if ((bigX && pos.X >= posEnd.X) || (!bigX && pos.Y >= posEnd.Y))
  14234. {
  14235. pos = posEnd;
  14236. xFloor = (float)Math.Floor(pos.X);
  14237. yFloor = (float)Math.Floor(pos.Y);
  14238. }
  14239. // Add new 1x1 rectangle in lane
  14240. if ((bigX && xFloor != xFloorOld) || (!bigX && yFloor != yFloorOld))
  14241. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14242. // Add last 1x1 rectangle in old lane at lane shift
  14243. if (bigX && yFloor != yFloorOld)
  14244. AddTrisFromHeightmap(xFloor, yFloorOld, ref triangles, ref zLower, ref zUpper);
  14245. if (!bigX && xFloor != xFloorOld)
  14246. AddTrisFromHeightmap(xFloorOld, yFloor, ref triangles, ref zLower, ref zUpper);
  14247. }
  14248. // Finalize bounding box Z
  14249. lower.Z = zLower;
  14250. upper.Z = zUpper;
  14251. // Done and returning Tri (triangle)List
  14252. return triangles;
  14253. }
  14254. /// <summary>
  14255. /// Helper to add HeightMap squares into Tri (triangle) List and adjust bounding box.
  14256. /// </summary>
  14257. private void AddTrisFromHeightmap(float xPos, float yPos, ref List<Tri> triangles, ref float zLower, ref float zUpper)
  14258. {
  14259. int xInt = (int)xPos;
  14260. int yInt = (int)yPos;
  14261. // Corner 1 of 1x1 rectangle
  14262. int x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14263. int y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14264. Vector3 pos1 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14265. // Adjust bounding box
  14266. zLower = Math.Min(zLower, pos1.Z);
  14267. zUpper = Math.Max(zUpper, pos1.Z);
  14268. // Corner 2 of 1x1 rectangle
  14269. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14270. y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14271. Vector3 pos2 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14272. // Adjust bounding box
  14273. zLower = Math.Min(zLower, pos2.Z);
  14274. zUpper = Math.Max(zUpper, pos2.Z);
  14275. // Corner 3 of 1x1 rectangle
  14276. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14277. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14278. Vector3 pos3 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14279. // Adjust bounding box
  14280. zLower = Math.Min(zLower, pos3.Z);
  14281. zUpper = Math.Max(zUpper, pos3.Z);
  14282. // Corner 4 of 1x1 rectangle
  14283. x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14284. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14285. Vector3 pos4 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14286. // Adjust bounding box
  14287. zLower = Math.Min(zLower, pos4.Z);
  14288. zUpper = Math.Max(zUpper, pos4.Z);
  14289. // Add triangle 1
  14290. Tri triangle1 = new Tri();
  14291. triangle1.p1 = pos1;
  14292. triangle1.p2 = pos2;
  14293. triangle1.p3 = pos3;
  14294. triangles.Add(triangle1);
  14295. // Add triangle 2
  14296. Tri triangle2 = new Tri();
  14297. triangle2.p1 = pos3;
  14298. triangle2.p2 = pos4;
  14299. triangle2.p3 = pos1;
  14300. triangles.Add(triangle2);
  14301. }
  14302. /// <summary>
  14303. /// Helper to get link number for a UUID.
  14304. /// </summary>
  14305. private int UUID2LinkNumber(SceneObjectPart part, UUID id)
  14306. {
  14307. SceneObjectGroup group = part.ParentGroup;
  14308. if (group != null)
  14309. {
  14310. // Parse every link for UUID
  14311. int linkCount = group.PrimCount + group.GetSittingAvatarsCount();
  14312. for (int link = linkCount; link > 0; link--)
  14313. {
  14314. ISceneEntity entity = GetLinkEntity(part, link);
  14315. // Return link number if UUID match
  14316. if (entity != null && entity.UUID == id)
  14317. return link;
  14318. }
  14319. }
  14320. // Return link number 0 if no links or UUID matches
  14321. return 0;
  14322. }
  14323. public LSL_Integer llManageEstateAccess(int action, string avatar)
  14324. {
  14325. m_host.AddScriptLPS(1);
  14326. EstateSettings estate = World.RegionInfo.EstateSettings;
  14327. bool isAccount = false;
  14328. bool isGroup = false;
  14329. if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
  14330. return 0;
  14331. UUID id = new UUID();
  14332. if (!UUID.TryParse(avatar, out id))
  14333. return 0;
  14334. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, id);
  14335. isAccount = account != null ? true : false;
  14336. if (!isAccount)
  14337. {
  14338. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  14339. if (groups != null)
  14340. {
  14341. GroupRecord group = groups.GetGroupRecord(id);
  14342. isGroup = group != null ? true : false;
  14343. if (!isGroup)
  14344. return 0;
  14345. }
  14346. else
  14347. return 0;
  14348. }
  14349. switch (action)
  14350. {
  14351. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
  14352. if (!isAccount) return 0;
  14353. if (estate.HasAccess(id)) return 1;
  14354. if (estate.IsBanned(id, World.GetUserFlags(id)))
  14355. estate.RemoveBan(id);
  14356. estate.AddEstateUser(id);
  14357. break;
  14358. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_REMOVE:
  14359. if (!isAccount || !estate.HasAccess(id)) return 0;
  14360. estate.RemoveEstateUser(id);
  14361. break;
  14362. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_ADD:
  14363. if (!isGroup) return 0;
  14364. if (estate.GroupAccess(id)) return 1;
  14365. estate.AddEstateGroup(id);
  14366. break;
  14367. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_REMOVE:
  14368. if (!isGroup || !estate.GroupAccess(id)) return 0;
  14369. estate.RemoveEstateGroup(id);
  14370. break;
  14371. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
  14372. if (!isAccount) return 0;
  14373. if (estate.IsBanned(id, World.GetUserFlags(id))) return 1;
  14374. EstateBan ban = new EstateBan();
  14375. ban.EstateID = estate.EstateID;
  14376. ban.BannedUserID = id;
  14377. estate.AddBan(ban);
  14378. break;
  14379. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
  14380. if (!isAccount || !estate.IsBanned(id, World.GetUserFlags(id))) return 0;
  14381. estate.RemoveBan(id);
  14382. break;
  14383. default: return 0;
  14384. }
  14385. return 1;
  14386. }
  14387. public LSL_Integer llGetMemoryLimit()
  14388. {
  14389. m_host.AddScriptLPS(1);
  14390. // The value returned for Mono scripts in SL
  14391. return 65536;
  14392. }
  14393. public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
  14394. {
  14395. m_host.AddScriptLPS(1);
  14396. // Treat as an LSO script
  14397. return ScriptBaseClass.FALSE;
  14398. }
  14399. public LSL_Integer llGetSPMaxMemory()
  14400. {
  14401. m_host.AddScriptLPS(1);
  14402. // The value returned for Mono scripts in SL
  14403. return 65536;
  14404. }
  14405. public virtual LSL_Integer llGetUsedMemory()
  14406. {
  14407. m_host.AddScriptLPS(1);
  14408. // The value returned for Mono scripts in SL
  14409. return 65536;
  14410. }
  14411. public void llScriptProfiler(LSL_Integer flags)
  14412. {
  14413. m_host.AddScriptLPS(1);
  14414. // This does nothing for LSO scripts in SL
  14415. }
  14416. #region Not Implemented
  14417. //
  14418. // Listing the unimplemented lsl functions here, please move
  14419. // them from this region as they are completed
  14420. //
  14421. public void llSetSoundQueueing(int queue)
  14422. {
  14423. m_host.AddScriptLPS(1);
  14424. if (m_SoundModule != null)
  14425. m_SoundModule.SetSoundQueueing(m_host.UUID, queue == ScriptBaseClass.TRUE.value);
  14426. }
  14427. public void llCollisionSprite(LSL_String impact_sprite)
  14428. {
  14429. m_host.AddScriptLPS(1);
  14430. // Viewer 2.0 broke this and it's likely LL has no intention
  14431. // of fixing it. Therefore, letting this be a NOP seems appropriate.
  14432. }
  14433. public void llGodLikeRezObject(string inventory, LSL_Vector pos)
  14434. {
  14435. m_host.AddScriptLPS(1);
  14436. if (!World.Permissions.IsGod(m_host.OwnerID))
  14437. NotImplemented("llGodLikeRezObject");
  14438. AssetBase rezAsset = World.AssetService.Get(inventory);
  14439. if (rezAsset == null)
  14440. {
  14441. llSay(0, "Asset not found");
  14442. return;
  14443. }
  14444. SceneObjectGroup group = null;
  14445. try
  14446. {
  14447. string xmlData = Utils.BytesToString(rezAsset.Data);
  14448. group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
  14449. }
  14450. catch
  14451. {
  14452. llSay(0, "Asset not found");
  14453. return;
  14454. }
  14455. if (group == null)
  14456. {
  14457. llSay(0, "Asset not found");
  14458. return;
  14459. }
  14460. group.RootPart.AttachedPos = group.AbsolutePosition;
  14461. group.ResetIDs();
  14462. Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
  14463. World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero);
  14464. group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3);
  14465. group.ScheduleGroupForFullUpdate();
  14466. // objects rezzed with this method are die_at_edge by default.
  14467. group.RootPart.SetDieAtEdge(true);
  14468. group.ResumeScripts();
  14469. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  14470. "object_rez", new Object[] {
  14471. new LSL_String(
  14472. group.RootPart.UUID.ToString()) },
  14473. new DetectParams[0]));
  14474. }
  14475. public LSL_Key llTransferLindenDollars(LSL_Key destination, LSL_Integer amount)
  14476. {
  14477. UUID txn = UUID.Random();
  14478. Util.FireAndForget(delegate(object x)
  14479. {
  14480. int replycode = 0;
  14481. string replydata = destination + "," + amount.ToString();
  14482. try
  14483. {
  14484. if (amount <= 0)
  14485. {
  14486. replydata = "INVALID_AMOUNT";
  14487. return;
  14488. }
  14489. TaskInventoryItem item = m_item;
  14490. if (item == null)
  14491. {
  14492. replydata = "SERVICE_ERROR";
  14493. return;
  14494. }
  14495. if (m_host.OwnerID == m_host.GroupID)
  14496. {
  14497. replydata = "GROUP_OWNED";
  14498. return;
  14499. }
  14500. m_host.AddScriptLPS(1);
  14501. if (item.PermsGranter == UUID.Zero)
  14502. {
  14503. replydata = "MISSING_PERMISSION_DEBIT";
  14504. return;
  14505. }
  14506. if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  14507. {
  14508. replydata = "MISSING_PERMISSION_DEBIT";
  14509. return;
  14510. }
  14511. UUID toID = new UUID();
  14512. if (!UUID.TryParse(destination, out toID))
  14513. {
  14514. replydata = "INVALID_AGENT";
  14515. return;
  14516. }
  14517. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, toID);
  14518. if (account == null)
  14519. {
  14520. replydata = "LINDENDOLLAR_ENTITYDOESNOTEXIST";
  14521. return;
  14522. }
  14523. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  14524. if (money == null)
  14525. {
  14526. replydata = "TRANSFERS_DISABLED";
  14527. return;
  14528. }
  14529. string reason;
  14530. bool result = money.ObjectGiveMoney( m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount, txn, out reason);
  14531. if (result)
  14532. {
  14533. replycode = 1;
  14534. return;
  14535. }
  14536. replydata = reason;
  14537. }
  14538. finally
  14539. {
  14540. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  14541. "transaction_result", new Object[] {
  14542. new LSL_String(txn.ToString()),
  14543. new LSL_Integer(replycode),
  14544. new LSL_String(replydata) },
  14545. new DetectParams[0]));
  14546. }
  14547. }, null, "LSL_Api.llTransferLindenDollars");
  14548. return txn.ToString();
  14549. }
  14550. #endregion
  14551. protected LSL_List SetPrimParams(ScenePresence av, LSL_List rules, string originFunc, ref uint rulesParsed)
  14552. {
  14553. //This is a special version of SetPrimParams to deal with avatars which are sitting on the linkset.
  14554. int idx = 0;
  14555. int idxStart = 0;
  14556. bool positionChanged = false;
  14557. try
  14558. {
  14559. while (idx < rules.Length)
  14560. {
  14561. ++rulesParsed;
  14562. int code = rules.GetLSLIntegerItem(idx++);
  14563. int remain = rules.Length - idx;
  14564. idxStart = idx;
  14565. switch (code)
  14566. {
  14567. case (int)ScriptBaseClass.PRIM_POSITION:
  14568. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  14569. {
  14570. if (remain < 1)
  14571. return new LSL_List();
  14572. LSL_Vector v;
  14573. v = rules.GetVector3Item(idx++);
  14574. if(!av.LegacySitOffsets)
  14575. {
  14576. LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
  14577. v = v + 2 * sitOffset;
  14578. }
  14579. av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
  14580. positionChanged = true;
  14581. }
  14582. break;
  14583. case (int)ScriptBaseClass.PRIM_ROTATION:
  14584. {
  14585. if (remain < 1)
  14586. return new LSL_List();
  14587. Quaternion r;
  14588. r = rules.GetQuaternionItem(idx++);
  14589. av.Rotation = m_host.GetWorldRotation() * r;
  14590. positionChanged = true;
  14591. }
  14592. break;
  14593. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  14594. {
  14595. if (remain < 1)
  14596. return new LSL_List();
  14597. LSL_Rotation r;
  14598. r = rules.GetQuaternionItem(idx++);
  14599. av.Rotation = r;
  14600. positionChanged = true;
  14601. }
  14602. break;
  14603. // parse rest doing nothing but number of parameters error check
  14604. case (int)ScriptBaseClass.PRIM_SIZE:
  14605. case (int)ScriptBaseClass.PRIM_MATERIAL:
  14606. case (int)ScriptBaseClass.PRIM_PHANTOM:
  14607. case (int)ScriptBaseClass.PRIM_PHYSICS:
  14608. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  14609. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  14610. case (int)ScriptBaseClass.PRIM_NAME:
  14611. case (int)ScriptBaseClass.PRIM_DESC:
  14612. if (remain < 1)
  14613. return new LSL_List();
  14614. idx++;
  14615. break;
  14616. case (int)ScriptBaseClass.PRIM_GLOW:
  14617. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  14618. case (int)ScriptBaseClass.PRIM_TEXGEN:
  14619. if (remain < 2)
  14620. return new LSL_List();
  14621. idx += 2;
  14622. break;
  14623. case (int)ScriptBaseClass.PRIM_TYPE:
  14624. if (remain < 3)
  14625. return new LSL_List();
  14626. code = (int)rules.GetLSLIntegerItem(idx++);
  14627. remain = rules.Length - idx;
  14628. switch (code)
  14629. {
  14630. case (int)ScriptBaseClass.PRIM_TYPE_BOX:
  14631. case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
  14632. case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
  14633. if (remain < 6)
  14634. return new LSL_List();
  14635. idx += 6;
  14636. break;
  14637. case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
  14638. if (remain < 5)
  14639. return new LSL_List();
  14640. idx += 5;
  14641. break;
  14642. case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
  14643. case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
  14644. case (int)ScriptBaseClass.PRIM_TYPE_RING:
  14645. if (remain < 11)
  14646. return new LSL_List();
  14647. idx += 11;
  14648. break;
  14649. case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
  14650. if (remain < 2)
  14651. return new LSL_List();
  14652. idx += 2;
  14653. break;
  14654. }
  14655. break;
  14656. case (int)ScriptBaseClass.PRIM_COLOR:
  14657. case (int)ScriptBaseClass.PRIM_TEXT:
  14658. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  14659. case (int)ScriptBaseClass.PRIM_OMEGA:
  14660. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  14661. if (remain < 3)
  14662. return new LSL_List();
  14663. idx += 3;
  14664. break;
  14665. case (int)ScriptBaseClass.PRIM_TEXTURE:
  14666. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  14667. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  14668. if (remain < 5)
  14669. return new LSL_List();
  14670. idx += 5;
  14671. break;
  14672. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  14673. if (remain < 7)
  14674. return new LSL_List();
  14675. idx += 7;
  14676. break;
  14677. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  14678. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  14679. return new LSL_List();
  14680. return rules.GetSublist(idx, -1);
  14681. }
  14682. }
  14683. }
  14684. catch (InvalidCastException e)
  14685. {
  14686. Error(originFunc,string.Format(
  14687. " error running rule #{0}: arg #{1} {2}",
  14688. rulesParsed, idx - idxStart, e.Message));
  14689. }
  14690. finally
  14691. {
  14692. if (positionChanged)
  14693. av.SendTerseUpdateToAllClients();
  14694. }
  14695. return new LSL_List();
  14696. }
  14697. public LSL_List GetPrimParams(ScenePresence avatar, LSL_List rules, ref LSL_List res)
  14698. {
  14699. // avatars case
  14700. // replies as SL wiki
  14701. // SceneObjectPart sitPart = avatar.ParentPart; // most likelly it will be needed
  14702. SceneObjectPart sitPart = World.GetSceneObjectPart(avatar.ParentID); // maybe better do this expensive search for it in case it's gone??
  14703. int idx = 0;
  14704. while (idx < rules.Length)
  14705. {
  14706. int code = (int)rules.GetLSLIntegerItem(idx++);
  14707. int remain = rules.Length - idx;
  14708. switch (code)
  14709. {
  14710. case (int)ScriptBaseClass.PRIM_MATERIAL:
  14711. res.Add(new LSL_Integer((int)SOPMaterialData.SopMaterial.Flesh));
  14712. break;
  14713. case (int)ScriptBaseClass.PRIM_PHYSICS:
  14714. res.Add(new LSL_Integer(0));
  14715. break;
  14716. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  14717. res.Add(new LSL_Integer(0));
  14718. break;
  14719. case (int)ScriptBaseClass.PRIM_PHANTOM:
  14720. res.Add(new LSL_Integer(0));
  14721. break;
  14722. case (int)ScriptBaseClass.PRIM_POSITION:
  14723. Vector3 pos;
  14724. if (sitPart.ParentGroup.RootPart != null)
  14725. {
  14726. pos = avatar.OffsetPosition;
  14727. if(!avatar.LegacySitOffsets)
  14728. {
  14729. Vector3 sitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f *2.0f);
  14730. pos -= sitOffset;
  14731. }
  14732. SceneObjectPart sitroot = sitPart.ParentGroup.RootPart;
  14733. pos = sitroot.AbsolutePosition + pos * sitroot.GetWorldRotation();
  14734. }
  14735. else
  14736. pos = avatar.AbsolutePosition;
  14737. res.Add(new LSL_Vector(pos.X,pos.Y,pos.Z));
  14738. break;
  14739. case (int)ScriptBaseClass.PRIM_SIZE:
  14740. Vector3 s = avatar.Appearance.AvatarSize;
  14741. res.Add(new LSL_Vector(s.X, s.Y, s.Z));
  14742. break;
  14743. case (int)ScriptBaseClass.PRIM_ROTATION:
  14744. res.Add(new LSL_Rotation(avatar.GetWorldRotation()));
  14745. break;
  14746. case (int)ScriptBaseClass.PRIM_TYPE:
  14747. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
  14748. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
  14749. res.Add(new LSL_Vector(0f,1.0f,0f));
  14750. res.Add(new LSL_Float(0.0f));
  14751. res.Add(new LSL_Vector(0, 0, 0));
  14752. res.Add(new LSL_Vector(1.0f,1.0f,0f));
  14753. res.Add(new LSL_Vector(0, 0, 0));
  14754. break;
  14755. case (int)ScriptBaseClass.PRIM_TEXTURE:
  14756. if (remain < 1)
  14757. return new LSL_List();
  14758. int face = (int)rules.GetLSLIntegerItem(idx++);
  14759. if (face == ScriptBaseClass.ALL_SIDES)
  14760. {
  14761. for (face = 0; face < 21; face++)
  14762. {
  14763. res.Add(new LSL_String(""));
  14764. res.Add(new LSL_Vector(0,0,0));
  14765. res.Add(new LSL_Vector(0,0,0));
  14766. res.Add(new LSL_Float(0.0));
  14767. }
  14768. }
  14769. else
  14770. {
  14771. if (face >= 0 && face < 21)
  14772. {
  14773. res.Add(new LSL_String(""));
  14774. res.Add(new LSL_Vector(0,0,0));
  14775. res.Add(new LSL_Vector(0,0,0));
  14776. res.Add(new LSL_Float(0.0));
  14777. }
  14778. }
  14779. break;
  14780. case (int)ScriptBaseClass.PRIM_COLOR:
  14781. if (remain < 1)
  14782. return new LSL_List();
  14783. face = (int)rules.GetLSLIntegerItem(idx++);
  14784. if (face == ScriptBaseClass.ALL_SIDES)
  14785. {
  14786. for (face = 0; face < 21; face++)
  14787. {
  14788. res.Add(new LSL_Vector(0,0,0));
  14789. res.Add(new LSL_Float(0));
  14790. }
  14791. }
  14792. else
  14793. {
  14794. res.Add(new LSL_Vector(0,0,0));
  14795. res.Add(new LSL_Float(0));
  14796. }
  14797. break;
  14798. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  14799. if (remain < 1)
  14800. return new LSL_List();
  14801. face = (int)rules.GetLSLIntegerItem(idx++);
  14802. if (face == ScriptBaseClass.ALL_SIDES)
  14803. {
  14804. for (face = 0; face < 21; face++)
  14805. {
  14806. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  14807. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  14808. }
  14809. }
  14810. else
  14811. {
  14812. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  14813. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  14814. }
  14815. break;
  14816. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  14817. if (remain < 1)
  14818. return new LSL_List();
  14819. face = (int)rules.GetLSLIntegerItem(idx++);
  14820. if (face == ScriptBaseClass.ALL_SIDES)
  14821. {
  14822. for (face = 0; face < 21; face++)
  14823. {
  14824. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  14825. }
  14826. }
  14827. else
  14828. {
  14829. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  14830. }
  14831. break;
  14832. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  14833. res.Add(new LSL_Integer(0));
  14834. res.Add(new LSL_Integer(0));// softness
  14835. res.Add(new LSL_Float(0.0f)); // gravity
  14836. res.Add(new LSL_Float(0.0f)); // friction
  14837. res.Add(new LSL_Float(0.0f)); // wind
  14838. res.Add(new LSL_Float(0.0f)); // tension
  14839. res.Add(new LSL_Vector(0f,0f,0f));
  14840. break;
  14841. case (int)ScriptBaseClass.PRIM_TEXGEN:
  14842. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  14843. if (remain < 1)
  14844. return new LSL_List();
  14845. face = (int)rules.GetLSLIntegerItem(idx++);
  14846. if (face == ScriptBaseClass.ALL_SIDES)
  14847. {
  14848. for (face = 0; face < 21; face++)
  14849. {
  14850. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  14851. }
  14852. }
  14853. else
  14854. {
  14855. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  14856. }
  14857. break;
  14858. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  14859. res.Add(new LSL_Integer(0));
  14860. res.Add(new LSL_Vector(0f,0f,0f));
  14861. res.Add(new LSL_Float(0f)); // intensity
  14862. res.Add(new LSL_Float(0f)); // radius
  14863. res.Add(new LSL_Float(0f)); // falloff
  14864. break;
  14865. case (int)ScriptBaseClass.PRIM_GLOW:
  14866. if (remain < 1)
  14867. return new LSL_List();
  14868. face = (int)rules.GetLSLIntegerItem(idx++);
  14869. if (face == ScriptBaseClass.ALL_SIDES)
  14870. {
  14871. for (face = 0; face < 21; face++)
  14872. {
  14873. res.Add(new LSL_Float(0f));
  14874. }
  14875. }
  14876. else
  14877. {
  14878. res.Add(new LSL_Float(0f));
  14879. }
  14880. break;
  14881. case (int)ScriptBaseClass.PRIM_TEXT:
  14882. res.Add(new LSL_String(""));
  14883. res.Add(new LSL_Vector(0f,0f,0f));
  14884. res.Add(new LSL_Float(1.0f));
  14885. break;
  14886. case (int)ScriptBaseClass.PRIM_NAME:
  14887. res.Add(new LSL_String(avatar.Name));
  14888. break;
  14889. case (int)ScriptBaseClass.PRIM_DESC:
  14890. res.Add(new LSL_String(""));
  14891. break;
  14892. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  14893. Quaternion lrot = avatar.Rotation;
  14894. res.Add(new LSL_Rotation(lrot.X, lrot.Y, lrot.Z, lrot.W));
  14895. break;
  14896. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  14897. Vector3 lpos = avatar.OffsetPosition;
  14898. if(!avatar.LegacySitOffsets)
  14899. {
  14900. Vector3 lsitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f * 2.0f);
  14901. lpos -= lsitOffset;
  14902. }
  14903. res.Add(new LSL_Vector(lpos.X,lpos.Y,lpos.Z));
  14904. break;
  14905. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  14906. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  14907. return new LSL_List();
  14908. return rules.GetSublist(idx, -1);
  14909. }
  14910. }
  14911. return new LSL_List();
  14912. }
  14913. public void llSetAnimationOverride(LSL_String animState, LSL_String anim)
  14914. {
  14915. string state = String.Empty;
  14916. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  14917. {
  14918. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  14919. {
  14920. state = kvp.Key;
  14921. break;
  14922. }
  14923. }
  14924. if (state == String.Empty)
  14925. {
  14926. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Invalid animation state " + animState);
  14927. return;
  14928. }
  14929. if (m_item.PermsGranter == UUID.Zero)
  14930. {
  14931. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14932. return;
  14933. }
  14934. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  14935. {
  14936. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14937. return;
  14938. }
  14939. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  14940. if (presence == null)
  14941. return;
  14942. UUID animID;
  14943. animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  14944. if (animID == UUID.Zero)
  14945. {
  14946. String animupper = ((string)anim).ToUpperInvariant();
  14947. DefaultAvatarAnimations.AnimsUUID.TryGetValue(animupper, out animID);
  14948. }
  14949. if (animID == UUID.Zero)
  14950. {
  14951. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Animation not found");
  14952. return;
  14953. }
  14954. presence.SetAnimationOverride(state, animID);
  14955. }
  14956. public void llResetAnimationOverride(LSL_String animState)
  14957. {
  14958. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  14959. if (presence == null)
  14960. return;
  14961. if (m_item.PermsGranter == UUID.Zero)
  14962. {
  14963. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14964. return;
  14965. }
  14966. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  14967. {
  14968. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14969. return;
  14970. }
  14971. if (animState == "ALL")
  14972. {
  14973. presence.SetAnimationOverride("ALL", UUID.Zero);
  14974. return;
  14975. }
  14976. string state = String.Empty;
  14977. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  14978. {
  14979. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  14980. {
  14981. state = kvp.Key;
  14982. break;
  14983. }
  14984. }
  14985. if (state == String.Empty)
  14986. {
  14987. return;
  14988. }
  14989. presence.SetAnimationOverride(state, UUID.Zero);
  14990. }
  14991. public LSL_String llGetAnimationOverride(LSL_String animState)
  14992. {
  14993. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  14994. if (presence == null)
  14995. return String.Empty;
  14996. if (m_item.PermsGranter == UUID.Zero)
  14997. {
  14998. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14999. return String.Empty;
  15000. }
  15001. if ((m_item.PermsMask & (ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION)) == 0)
  15002. {
  15003. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15004. return String.Empty;
  15005. }
  15006. string state = String.Empty;
  15007. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  15008. {
  15009. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  15010. {
  15011. state = kvp.Key;
  15012. break;
  15013. }
  15014. }
  15015. if (state == String.Empty)
  15016. {
  15017. return String.Empty;
  15018. }
  15019. UUID animID = presence.GetAnimationOverride(state);
  15020. if (animID == UUID.Zero)
  15021. return animState;
  15022. foreach (KeyValuePair<string, UUID> kvp in DefaultAvatarAnimations.AnimsUUID)
  15023. {
  15024. if (kvp.Value == animID)
  15025. return kvp.Key.ToLower();
  15026. }
  15027. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  15028. {
  15029. if (item.AssetID == animID)
  15030. return item.Name;
  15031. }
  15032. return String.Empty;
  15033. }
  15034. public LSL_List llJson2List(LSL_String json)
  15035. {
  15036. if(String.IsNullOrEmpty(json))
  15037. return new LSL_List();
  15038. if(json == "[]")
  15039. return new LSL_List();
  15040. if(json == "{}")
  15041. return new LSL_List();
  15042. char first = ((string)json)[0];
  15043. if(first != '[' && first !='{')
  15044. {
  15045. // we already have a single element
  15046. LSL_List l = new LSL_List();
  15047. l.Add(json);
  15048. return l;
  15049. }
  15050. LitJson.JsonData jsdata;
  15051. try
  15052. {
  15053. jsdata = LitJson.JsonMapper.ToObject(json);
  15054. }
  15055. catch (Exception e)
  15056. {
  15057. string m = e.Message; // debug point
  15058. return json;
  15059. }
  15060. try
  15061. {
  15062. return JsonParseTop(jsdata);
  15063. }
  15064. catch (Exception e)
  15065. {
  15066. string m = e.Message; // debug point
  15067. return (LSL_String)ScriptBaseClass.JSON_INVALID;
  15068. }
  15069. }
  15070. private LSL_List JsonParseTop(LitJson.JsonData elem)
  15071. {
  15072. LSL_List retl = new LSL_List();
  15073. if(elem == null)
  15074. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  15075. LitJson.JsonType elemType = elem.GetJsonType();
  15076. switch (elemType)
  15077. {
  15078. case LitJson.JsonType.Int:
  15079. retl.Add(new LSL_Integer((int)elem));
  15080. return retl;
  15081. case LitJson.JsonType.Boolean:
  15082. retl.Add((LSL_String)((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE));
  15083. return retl;
  15084. case LitJson.JsonType.Double:
  15085. retl.Add(new LSL_Float((double)elem));
  15086. return retl;
  15087. case LitJson.JsonType.None:
  15088. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  15089. return retl;
  15090. case LitJson.JsonType.String:
  15091. retl.Add(new LSL_String((string)elem));
  15092. return retl;
  15093. case LitJson.JsonType.Array:
  15094. foreach (LitJson.JsonData subelem in elem)
  15095. retl.Add(JsonParseTopNodes(subelem));
  15096. return retl;
  15097. case LitJson.JsonType.Object:
  15098. IDictionaryEnumerator e = ((IOrderedDictionary)elem).GetEnumerator();
  15099. while (e.MoveNext())
  15100. {
  15101. retl.Add(new LSL_String((string)e.Key));
  15102. retl.Add(JsonParseTopNodes((LitJson.JsonData)e.Value));
  15103. }
  15104. return retl;
  15105. default:
  15106. throw new Exception(ScriptBaseClass.JSON_INVALID);
  15107. }
  15108. }
  15109. private object JsonParseTopNodes(LitJson.JsonData elem)
  15110. {
  15111. if(elem == null)
  15112. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  15113. LitJson.JsonType elemType = elem.GetJsonType();
  15114. switch (elemType)
  15115. {
  15116. case LitJson.JsonType.Int:
  15117. return (new LSL_Integer((int)elem));
  15118. case LitJson.JsonType.Boolean:
  15119. return ((bool)elem ? (LSL_String)ScriptBaseClass.JSON_TRUE : (LSL_String)ScriptBaseClass.JSON_FALSE);
  15120. case LitJson.JsonType.Double:
  15121. return (new LSL_Float((double)elem));
  15122. case LitJson.JsonType.None:
  15123. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  15124. case LitJson.JsonType.String:
  15125. return (new LSL_String((string)elem));
  15126. case LitJson.JsonType.Array:
  15127. case LitJson.JsonType.Object:
  15128. string s = LitJson.JsonMapper.ToJson(elem);
  15129. return (LSL_String)s;
  15130. default:
  15131. throw new Exception(ScriptBaseClass.JSON_INVALID);
  15132. }
  15133. }
  15134. public LSL_String llList2Json(LSL_String type, LSL_List values)
  15135. {
  15136. try
  15137. {
  15138. StringBuilder sb = new StringBuilder();
  15139. if (type == ScriptBaseClass.JSON_ARRAY)
  15140. {
  15141. sb.Append("[");
  15142. int i= 0;
  15143. foreach (object o in values.Data)
  15144. {
  15145. sb.Append(ListToJson(o));
  15146. if((i++) < values.Data.Length - 1)
  15147. sb.Append(",");
  15148. }
  15149. sb.Append("]");
  15150. return (LSL_String)sb.ToString();;
  15151. }
  15152. else if (type == ScriptBaseClass.JSON_OBJECT)
  15153. {
  15154. sb.Append("{");
  15155. for (int i = 0; i < values.Data.Length; i += 2)
  15156. {
  15157. if (!(values.Data[i] is LSL_String))
  15158. return ScriptBaseClass.JSON_INVALID;
  15159. string key = ((LSL_String)values.Data[i]).m_string;
  15160. key = EscapeForJSON(key, true);
  15161. sb.Append(key);
  15162. sb.Append(":");
  15163. sb.Append(ListToJson(values.Data[i+1]));
  15164. if(i < values.Data.Length - 2)
  15165. sb.Append(",");
  15166. }
  15167. sb.Append("}");
  15168. return (LSL_String)sb.ToString();
  15169. }
  15170. return ScriptBaseClass.JSON_INVALID;
  15171. }
  15172. catch
  15173. {
  15174. return ScriptBaseClass.JSON_INVALID;
  15175. }
  15176. }
  15177. private string ListToJson(object o)
  15178. {
  15179. if (o is LSL_Float || o is double)
  15180. {
  15181. double float_val;
  15182. if (o is double)
  15183. float_val = ((double)o);
  15184. else
  15185. float_val = ((LSL_Float)o).value;
  15186. if(double.IsInfinity(float_val))
  15187. return "\"Inf\"";
  15188. if(double.IsNaN(float_val))
  15189. return "\"NaN\"";
  15190. return ((LSL_Float)float_val).ToString();
  15191. }
  15192. if (o is LSL_Integer || o is int)
  15193. {
  15194. int i;
  15195. if (o is int)
  15196. i = ((int)o);
  15197. else
  15198. i = ((LSL_Integer)o).value;
  15199. return i.ToString();
  15200. }
  15201. if (o is LSL_Rotation)
  15202. {
  15203. StringBuilder sb = new StringBuilder(128);
  15204. sb.Append("\"");
  15205. LSL_Rotation r = (LSL_Rotation)o;
  15206. sb.Append(r.ToString());
  15207. sb.Append("\"");
  15208. return sb.ToString();
  15209. }
  15210. if (o is LSL_Vector)
  15211. {
  15212. StringBuilder sb = new StringBuilder(128);
  15213. sb.Append("\"");
  15214. LSL_Vector v = (LSL_Vector)o;
  15215. sb.Append(v.ToString());
  15216. sb.Append("\"");
  15217. return sb.ToString();
  15218. }
  15219. if (o is LSL_String || o is string)
  15220. {
  15221. string str;
  15222. if (o is string)
  15223. str = ((string)o);
  15224. else
  15225. str = ((LSL_String)o).m_string;
  15226. if(str == ScriptBaseClass.JSON_TRUE || str == "true")
  15227. return "true";
  15228. if(str == ScriptBaseClass.JSON_FALSE ||str == "false")
  15229. return "false";
  15230. if(str == ScriptBaseClass.JSON_NULL || str == "null")
  15231. return "null";
  15232. str.Trim();
  15233. if (str[0] == '{')
  15234. return str;
  15235. if (str[0] == '[')
  15236. return str;
  15237. return EscapeForJSON(str, true);
  15238. }
  15239. throw new IndexOutOfRangeException();
  15240. }
  15241. private string EscapeForJSON(string s, bool AddOuter)
  15242. {
  15243. int i;
  15244. char c;
  15245. String t;
  15246. int len = s.Length;
  15247. StringBuilder sb = new StringBuilder(len + 64);
  15248. if(AddOuter)
  15249. sb.Append("\"");
  15250. for (i = 0; i < len; i++)
  15251. {
  15252. c = s[i];
  15253. switch (c)
  15254. {
  15255. case '\\':
  15256. case '"':
  15257. case '/':
  15258. sb.Append('\\');
  15259. sb.Append(c);
  15260. break;
  15261. case '\b':
  15262. sb.Append("\\b");
  15263. break;
  15264. case '\t':
  15265. sb.Append("\\t");
  15266. break;
  15267. case '\n':
  15268. sb.Append("\\n");
  15269. break;
  15270. case '\f':
  15271. sb.Append("\\f");
  15272. break;
  15273. case '\r':
  15274. sb.Append("\\r");
  15275. break;
  15276. default:
  15277. if (c < ' ')
  15278. {
  15279. t = "000" + String.Format("{0:X}", c);
  15280. sb.Append("\\u" + t.Substring(t.Length - 4));
  15281. }
  15282. else
  15283. {
  15284. sb.Append(c);
  15285. }
  15286. break;
  15287. }
  15288. }
  15289. if(AddOuter)
  15290. sb.Append("\"");
  15291. return sb.ToString();
  15292. }
  15293. public LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value)
  15294. {
  15295. bool noSpecifiers = specifiers.Length == 0;
  15296. LitJson.JsonData workData;
  15297. try
  15298. {
  15299. if(noSpecifiers)
  15300. specifiers.Add(new LSL_Integer(0));
  15301. if(!String.IsNullOrEmpty(json))
  15302. workData = LitJson.JsonMapper.ToObject(json);
  15303. else
  15304. {
  15305. workData = new LitJson.JsonData();
  15306. workData.SetJsonType(LitJson.JsonType.Array);
  15307. }
  15308. }
  15309. catch (Exception e)
  15310. {
  15311. string m = e.Message; // debug point
  15312. return ScriptBaseClass.JSON_INVALID;
  15313. }
  15314. try
  15315. {
  15316. LitJson.JsonData replace = JsonSetSpecific(workData, specifiers, 0, value);
  15317. if(replace != null)
  15318. workData = replace;
  15319. }
  15320. catch (Exception e)
  15321. {
  15322. string m = e.Message; // debug point
  15323. return ScriptBaseClass.JSON_INVALID;
  15324. }
  15325. try
  15326. {
  15327. string r = LitJson.JsonMapper.ToJson(workData);
  15328. if(noSpecifiers)
  15329. r = r.Substring(1,r.Length -2); // strip leading and trailing brakets
  15330. return r;
  15331. }
  15332. catch (Exception e)
  15333. {
  15334. string m = e.Message; // debug point
  15335. }
  15336. return ScriptBaseClass.JSON_INVALID;
  15337. }
  15338. private LitJson.JsonData JsonSetSpecific(LitJson.JsonData elem, LSL_List specifiers, int level, LSL_String val)
  15339. {
  15340. object spec = specifiers.Data[level];
  15341. if(spec is LSL_String)
  15342. spec = ((LSL_String)spec).m_string;
  15343. else if (spec is LSL_Integer)
  15344. spec = ((LSL_Integer)spec).value;
  15345. if(!(spec is string || spec is int))
  15346. throw new IndexOutOfRangeException();
  15347. int speclen = specifiers.Data.Length - 1;
  15348. bool hasvalue = false;
  15349. LitJson.JsonData value = null;
  15350. LitJson.JsonType elemType = elem.GetJsonType();
  15351. if (elemType == LitJson.JsonType.Array)
  15352. {
  15353. if (spec is int)
  15354. {
  15355. int v = (int)spec;
  15356. int c = elem.Count;
  15357. if(v < 0 || (v != 0 && v > c))
  15358. throw new IndexOutOfRangeException();
  15359. if(v == c)
  15360. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15361. else
  15362. {
  15363. hasvalue = true;
  15364. value = elem[v];
  15365. }
  15366. }
  15367. else if (spec is string)
  15368. {
  15369. if((string)spec == ScriptBaseClass.JSON_APPEND)
  15370. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15371. else if(elem.Count < 2)
  15372. {
  15373. // our initial guess of array was wrong
  15374. LitJson.JsonData newdata = new LitJson.JsonData();
  15375. newdata.SetJsonType(LitJson.JsonType.Object);
  15376. IOrderedDictionary no = newdata as IOrderedDictionary;
  15377. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  15378. return newdata;
  15379. }
  15380. }
  15381. }
  15382. else if (elemType == LitJson.JsonType.Object)
  15383. {
  15384. if (spec is string)
  15385. {
  15386. IOrderedDictionary e = elem as IOrderedDictionary;
  15387. string key = (string)spec;
  15388. if(e.Contains(key))
  15389. {
  15390. hasvalue = true;
  15391. value = (LitJson.JsonData)e[key];
  15392. }
  15393. else
  15394. e.Add(key, JsonBuildRestOfSpec(specifiers, level + 1, val));
  15395. }
  15396. else if(spec is int && (int)spec == 0)
  15397. {
  15398. //we are replacing a object by a array
  15399. LitJson.JsonData newData = new LitJson.JsonData();
  15400. newData.SetJsonType(LitJson.JsonType.Array);
  15401. newData.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15402. return newData;
  15403. }
  15404. }
  15405. else
  15406. {
  15407. LitJson.JsonData newData = JsonBuildRestOfSpec(specifiers, level, val);
  15408. return newData;
  15409. }
  15410. if (hasvalue)
  15411. {
  15412. if (level < speclen)
  15413. {
  15414. LitJson.JsonData replace = JsonSetSpecific(value, specifiers, level + 1, val);
  15415. if(replace != null)
  15416. {
  15417. if(elemType == LitJson.JsonType.Array)
  15418. {
  15419. if(spec is int)
  15420. elem[(int)spec] = replace;
  15421. else if( spec is string)
  15422. {
  15423. LitJson.JsonData newdata = new LitJson.JsonData();
  15424. newdata.SetJsonType(LitJson.JsonType.Object);
  15425. IOrderedDictionary no = newdata as IOrderedDictionary;
  15426. no.Add((string)spec, replace);
  15427. return newdata;
  15428. }
  15429. }
  15430. else if(elemType == LitJson.JsonType.Object)
  15431. {
  15432. if(spec is string)
  15433. elem[(string)spec] = replace;
  15434. else if(spec is int && (int)spec == 0)
  15435. {
  15436. LitJson.JsonData newdata = new LitJson.JsonData();
  15437. newdata.SetJsonType(LitJson.JsonType.Array);
  15438. newdata.Add(replace);
  15439. return newdata;
  15440. }
  15441. }
  15442. }
  15443. return null;
  15444. }
  15445. else if(speclen == level)
  15446. {
  15447. if(val == ScriptBaseClass.JSON_DELETE)
  15448. {
  15449. if(elemType == LitJson.JsonType.Array)
  15450. {
  15451. if(spec is int)
  15452. {
  15453. IList el = elem as IList;
  15454. el.RemoveAt((int)spec);
  15455. }
  15456. }
  15457. else if(elemType == LitJson.JsonType.Object)
  15458. {
  15459. if(spec is string)
  15460. {
  15461. IOrderedDictionary eo = elem as IOrderedDictionary;
  15462. eo.Remove((string) spec);
  15463. }
  15464. }
  15465. return null;
  15466. }
  15467. LitJson.JsonData newval = null;
  15468. float num;
  15469. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15470. newval = null;
  15471. else if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15472. newval = new LitJson.JsonData(true);
  15473. else if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15474. newval = new LitJson.JsonData(false);
  15475. else if(float.TryParse(val, out num))
  15476. {
  15477. // assuming we are at en.us already
  15478. if(num - (int)num == 0.0f && !val.Contains("."))
  15479. newval = new LitJson.JsonData((int)num);
  15480. else
  15481. {
  15482. num = (float)Math.Round(num,6);
  15483. newval = new LitJson.JsonData((double)num);
  15484. }
  15485. }
  15486. else
  15487. {
  15488. string str = val.m_string;
  15489. newval = new LitJson.JsonData(str);
  15490. }
  15491. if(elemType == LitJson.JsonType.Array)
  15492. {
  15493. if(spec is int)
  15494. elem[(int)spec] = newval;
  15495. else if( spec is string)
  15496. {
  15497. LitJson.JsonData newdata = new LitJson.JsonData();
  15498. newdata.SetJsonType(LitJson.JsonType.Object);
  15499. IOrderedDictionary no = newdata as IOrderedDictionary;
  15500. no.Add((string)spec,newval);
  15501. return newdata;
  15502. }
  15503. }
  15504. else if(elemType == LitJson.JsonType.Object)
  15505. {
  15506. if(spec is string)
  15507. elem[(string)spec] = newval;
  15508. else if(spec is int && (int)spec == 0)
  15509. {
  15510. LitJson.JsonData newdata = new LitJson.JsonData();
  15511. newdata.SetJsonType(LitJson.JsonType.Array);
  15512. newdata.Add(newval);
  15513. return newdata;
  15514. }
  15515. }
  15516. }
  15517. }
  15518. if(val == ScriptBaseClass.JSON_DELETE)
  15519. throw new IndexOutOfRangeException();
  15520. return null;
  15521. }
  15522. private LitJson.JsonData JsonBuildRestOfSpec(LSL_List specifiers, int level, LSL_String val)
  15523. {
  15524. object spec = level >= specifiers.Data.Length ? null : specifiers.Data[level];
  15525. // 20131224 not used object specNext = i+1 >= specifiers.Data.Length ? null : specifiers.Data[i+1];
  15526. float num;
  15527. if (spec == null)
  15528. {
  15529. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15530. return null;
  15531. if(val == ScriptBaseClass.JSON_DELETE)
  15532. throw new IndexOutOfRangeException();
  15533. if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15534. return new LitJson.JsonData(true);
  15535. if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15536. return new LitJson.JsonData(false);
  15537. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15538. return null;
  15539. if(float.TryParse(val, out num))
  15540. {
  15541. // assuming we are at en.us already
  15542. if(num - (int)num == 0.0f && !val.Contains("."))
  15543. return new LitJson.JsonData((int)num);
  15544. else
  15545. {
  15546. num = (float)Math.Round(num,6);
  15547. return new LitJson.JsonData(num);
  15548. }
  15549. }
  15550. else
  15551. {
  15552. string str = val.m_string;
  15553. return new LitJson.JsonData(str);
  15554. }
  15555. throw new IndexOutOfRangeException();
  15556. }
  15557. if(spec is LSL_String)
  15558. spec = ((LSL_String)spec).m_string;
  15559. else if (spec is LSL_Integer)
  15560. spec = ((LSL_Integer)spec).value;
  15561. if (spec is int ||
  15562. (spec is string && ((string)spec) == ScriptBaseClass.JSON_APPEND) )
  15563. {
  15564. if(spec is int && (int)spec != 0)
  15565. throw new IndexOutOfRangeException();
  15566. LitJson.JsonData newdata = new LitJson.JsonData();
  15567. newdata.SetJsonType(LitJson.JsonType.Array);
  15568. newdata.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15569. return newdata;
  15570. }
  15571. else if (spec is string)
  15572. {
  15573. LitJson.JsonData newdata = new LitJson.JsonData();
  15574. newdata.SetJsonType(LitJson.JsonType.Object);
  15575. IOrderedDictionary no = newdata as IOrderedDictionary;
  15576. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  15577. return newdata;
  15578. }
  15579. throw new IndexOutOfRangeException();
  15580. }
  15581. private bool JsonFind(LitJson.JsonData elem, LSL_List specifiers, int level, out LitJson.JsonData value)
  15582. {
  15583. value = null;
  15584. if(elem == null)
  15585. return false;
  15586. object spec;
  15587. spec = specifiers.Data[level];
  15588. bool haveVal = false;
  15589. LitJson.JsonData next = null;
  15590. if (elem.GetJsonType() == LitJson.JsonType.Array)
  15591. {
  15592. if (spec is LSL_Integer)
  15593. {
  15594. int indx = (LSL_Integer)spec;
  15595. if(indx >= 0 && indx < elem.Count)
  15596. {
  15597. haveVal = true;
  15598. next = (LitJson.JsonData)elem[indx];
  15599. }
  15600. }
  15601. }
  15602. else if (elem.GetJsonType() == LitJson.JsonType.Object)
  15603. {
  15604. if (spec is LSL_String)
  15605. {
  15606. IOrderedDictionary e = elem as IOrderedDictionary;
  15607. string key = (LSL_String)spec;
  15608. if(e.Contains(key))
  15609. {
  15610. haveVal = true;
  15611. next = (LitJson.JsonData)e[key];
  15612. }
  15613. }
  15614. }
  15615. if (haveVal)
  15616. {
  15617. if(level == specifiers.Data.Length - 1)
  15618. {
  15619. value = next;
  15620. return true;
  15621. }
  15622. level++;
  15623. if(next == null)
  15624. return false;
  15625. LitJson.JsonType nextType = next.GetJsonType();
  15626. if(nextType != LitJson.JsonType.Object && nextType != LitJson.JsonType.Array)
  15627. return false;
  15628. return JsonFind(next, specifiers, level, out value);
  15629. }
  15630. return false;
  15631. }
  15632. public LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers)
  15633. {
  15634. if(String.IsNullOrWhiteSpace(json))
  15635. return ScriptBaseClass.JSON_INVALID;
  15636. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  15637. return ScriptBaseClass.JSON_INVALID;
  15638. char first = ((string)json)[0];
  15639. if((first != '[' && first !='{'))
  15640. {
  15641. if(specifiers.Length > 0)
  15642. return ScriptBaseClass.JSON_INVALID;
  15643. json = "[" + json + "]"; // could handle single element case.. but easier like this
  15644. specifiers.Add((LSL_Integer)0);
  15645. }
  15646. LitJson.JsonData jsonData;
  15647. try
  15648. {
  15649. jsonData = LitJson.JsonMapper.ToObject(json);
  15650. }
  15651. catch (Exception e)
  15652. {
  15653. string m = e.Message; // debug point
  15654. return ScriptBaseClass.JSON_INVALID;
  15655. }
  15656. LitJson.JsonData elem = null;
  15657. if(specifiers.Length == 0)
  15658. elem = jsonData;
  15659. else
  15660. {
  15661. if(!JsonFind(jsonData, specifiers, 0, out elem))
  15662. return ScriptBaseClass.JSON_INVALID;
  15663. }
  15664. return JsonElementToString(elem);
  15665. }
  15666. private LSL_String JsonElementToString(LitJson.JsonData elem)
  15667. {
  15668. if(elem == null)
  15669. return ScriptBaseClass.JSON_NULL;
  15670. LitJson.JsonType elemType = elem.GetJsonType();
  15671. switch(elemType)
  15672. {
  15673. case LitJson.JsonType.Array:
  15674. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  15675. case LitJson.JsonType.Boolean:
  15676. return new LSL_String((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE);
  15677. case LitJson.JsonType.Double:
  15678. double d= (double)elem;
  15679. string sd = String.Format(Culture.FormatProvider, "{0:0.0#####}",d);
  15680. return new LSL_String(sd);
  15681. case LitJson.JsonType.Int:
  15682. int i = (int)elem;
  15683. return new LSL_String(i.ToString());
  15684. case LitJson.JsonType.Long:
  15685. long l = (long)elem;
  15686. return new LSL_String(l.ToString());
  15687. case LitJson.JsonType.Object:
  15688. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  15689. case LitJson.JsonType.String:
  15690. string s = (string)elem;
  15691. return new LSL_String(s);
  15692. case LitJson.JsonType.None:
  15693. return ScriptBaseClass.JSON_NULL;
  15694. default:
  15695. return ScriptBaseClass.JSON_INVALID;
  15696. }
  15697. }
  15698. public LSL_String llJsonValueType(LSL_String json, LSL_List specifiers)
  15699. {
  15700. if(String.IsNullOrWhiteSpace(json))
  15701. return ScriptBaseClass.JSON_INVALID;
  15702. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  15703. return ScriptBaseClass.JSON_INVALID;
  15704. char first = ((string)json)[0];
  15705. if((first != '[' && first !='{'))
  15706. {
  15707. if(specifiers.Length > 0)
  15708. return ScriptBaseClass.JSON_INVALID;
  15709. json = "[" + json + "]"; // could handle single element case.. but easier like this
  15710. specifiers.Add((LSL_Integer)0);
  15711. }
  15712. LitJson.JsonData jsonData;
  15713. try
  15714. {
  15715. jsonData = LitJson.JsonMapper.ToObject(json);
  15716. }
  15717. catch (Exception e)
  15718. {
  15719. string m = e.Message; // debug point
  15720. return ScriptBaseClass.JSON_INVALID;
  15721. }
  15722. LitJson.JsonData elem = null;
  15723. if(specifiers.Length == 0)
  15724. elem = jsonData;
  15725. else
  15726. {
  15727. if(!JsonFind(jsonData, specifiers, 0, out elem))
  15728. return ScriptBaseClass.JSON_INVALID;
  15729. }
  15730. if(elem == null)
  15731. return ScriptBaseClass.JSON_NULL;
  15732. LitJson.JsonType elemType = elem.GetJsonType();
  15733. switch(elemType)
  15734. {
  15735. case LitJson.JsonType.Array:
  15736. return ScriptBaseClass.JSON_ARRAY;
  15737. case LitJson.JsonType.Boolean:
  15738. return (bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE;
  15739. case LitJson.JsonType.Double:
  15740. case LitJson.JsonType.Int:
  15741. case LitJson.JsonType.Long:
  15742. return ScriptBaseClass.JSON_NUMBER;
  15743. case LitJson.JsonType.Object:
  15744. return ScriptBaseClass.JSON_OBJECT;
  15745. case LitJson.JsonType.String:
  15746. string s = (string)elem;
  15747. if(s == ScriptBaseClass.JSON_NULL)
  15748. return ScriptBaseClass.JSON_NULL;
  15749. if(s == ScriptBaseClass.JSON_TRUE)
  15750. return ScriptBaseClass.JSON_TRUE;
  15751. if(s == ScriptBaseClass.JSON_FALSE)
  15752. return ScriptBaseClass.JSON_FALSE;
  15753. return ScriptBaseClass.JSON_STRING;
  15754. case LitJson.JsonType.None:
  15755. return ScriptBaseClass.JSON_NULL;
  15756. default:
  15757. return ScriptBaseClass.JSON_INVALID;
  15758. }
  15759. }
  15760. }
  15761. public class NotecardCache
  15762. {
  15763. protected class Notecard
  15764. {
  15765. public string[] text;
  15766. public DateTime lastRef;
  15767. }
  15768. private static Dictionary<UUID, Notecard> m_Notecards =
  15769. new Dictionary<UUID, Notecard>();
  15770. public static void Cache(UUID assetID, byte[] text)
  15771. {
  15772. CheckCache();
  15773. lock (m_Notecards)
  15774. {
  15775. if (m_Notecards.ContainsKey(assetID))
  15776. return;
  15777. Notecard nc = new Notecard();
  15778. nc.lastRef = DateTime.Now;
  15779. try
  15780. {
  15781. nc.text = SLUtil.ParseNotecardToArray(text);
  15782. }
  15783. catch(SLUtil.NotANotecardFormatException)
  15784. {
  15785. nc.text = new string[0];
  15786. }
  15787. m_Notecards[assetID] = nc;
  15788. }
  15789. }
  15790. public static bool IsCached(UUID assetID)
  15791. {
  15792. lock (m_Notecards)
  15793. {
  15794. return m_Notecards.ContainsKey(assetID);
  15795. }
  15796. }
  15797. public static int GetLines(UUID assetID)
  15798. {
  15799. if (!IsCached(assetID))
  15800. return -1;
  15801. lock (m_Notecards)
  15802. {
  15803. m_Notecards[assetID].lastRef = DateTime.Now;
  15804. return m_Notecards[assetID].text.Length;
  15805. }
  15806. }
  15807. /// <summary>
  15808. /// Get a notecard line.
  15809. /// </summary>
  15810. /// <param name="assetID"></param>
  15811. /// <param name="lineNumber">Lines start at index 0</param>
  15812. /// <returns></returns>
  15813. public static string GetLine(UUID assetID, int lineNumber)
  15814. {
  15815. if (lineNumber < 0)
  15816. return "";
  15817. string data;
  15818. if (!IsCached(assetID))
  15819. return "";
  15820. lock (m_Notecards)
  15821. {
  15822. m_Notecards[assetID].lastRef = DateTime.Now;
  15823. if (lineNumber >= m_Notecards[assetID].text.Length)
  15824. return "\n\n\n";
  15825. data = m_Notecards[assetID].text[lineNumber];
  15826. return data;
  15827. }
  15828. }
  15829. /// <summary>
  15830. /// Get a notecard line.
  15831. /// </summary>
  15832. /// <param name="assetID"></param>
  15833. /// <param name="lineNumber">Lines start at index 0</param>
  15834. /// <param name="maxLength">
  15835. /// Maximum length of the returned line.
  15836. /// </param>
  15837. /// <returns>
  15838. /// If the line length is longer than <paramref name="maxLength"/>,
  15839. /// the return string will be truncated.
  15840. /// </returns>
  15841. public static string GetLine(UUID assetID, int lineNumber, int maxLength)
  15842. {
  15843. string line = GetLine(assetID, lineNumber);
  15844. if (line.Length > maxLength)
  15845. line = line.Substring(0, maxLength);
  15846. return line;
  15847. }
  15848. public static void CheckCache()
  15849. {
  15850. lock (m_Notecards)
  15851. {
  15852. foreach (UUID key in new List<UUID>(m_Notecards.Keys))
  15853. {
  15854. Notecard nc = m_Notecards[key];
  15855. if (nc.lastRef.AddSeconds(30) < DateTime.Now)
  15856. m_Notecards.Remove(key);
  15857. }
  15858. }
  15859. }
  15860. }
  15861. }