LSL_BuiltIn_Commands.cs 200 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Runtime.Remoting.Lifetime;
  31. using System.Text;
  32. using System.Threading;
  33. using Axiom.Math;
  34. using libsecondlife;
  35. using OpenSim.Framework;
  36. using OpenSim.Region.Environment;
  37. using OpenSim.Region.Environment.Interfaces;
  38. using OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney;
  39. using OpenSim.Region.Environment.Modules.World.Land;
  40. using OpenSim.Region.Environment.Scenes;
  41. using OpenSim.Region.ScriptEngine.Common.ScriptEngineBase;
  42. //using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL;
  43. namespace OpenSim.Region.ScriptEngine.Common
  44. {
  45. /// <summary>
  46. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  47. /// </summary>
  48. public class LSL_BuiltIn_Commands : MarshalByRefObject, LSL_BuiltIn_Commands_Interface
  49. {
  50. // private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  51. internal ScriptEngineBase.ScriptEngine m_ScriptEngine;
  52. internal SceneObjectPart m_host;
  53. internal uint m_localID;
  54. internal LLUUID m_itemID;
  55. internal bool throwErrorOnNotImplemented = true;
  56. public LSL_BuiltIn_Commands(ScriptEngineBase.ScriptEngine ScriptEngine, SceneObjectPart host, uint localID, LLUUID itemID)
  57. {
  58. m_ScriptEngine = ScriptEngine;
  59. m_host = host;
  60. m_localID = localID;
  61. m_itemID = itemID;
  62. //m_log.Info(ScriptEngineName, "LSL_BaseClass.Start() called. Hosted by [" + m_host.Name + ":" + m_host.UUID + "@" + m_host.AbsolutePosition + "]");
  63. }
  64. private DateTime m_timer = DateTime.Now;
  65. private string m_state = "default";
  66. private bool m_waitingForScriptAnswer=false;
  67. public string State
  68. {
  69. get { return m_state; }
  70. set {
  71. // Set it if it changed
  72. if (m_state != value)
  73. {
  74. try
  75. {
  76. m_ScriptEngine.m_EventManager.state_exit(m_localID);
  77. }
  78. catch (AppDomainUnloadedException)
  79. {
  80. Console.WriteLine("[SCRIPT]: state change called when script was unloaded. Nothing to worry about, but noting the occurance");
  81. }
  82. m_state = value;
  83. try
  84. {
  85. int eventFlags = m_ScriptEngine.m_ScriptManager.GetStateEventFlags(m_localID, m_itemID);
  86. m_host.SetScriptEvents(m_itemID, eventFlags);
  87. m_ScriptEngine.m_EventManager.state_entry(m_localID);
  88. }
  89. catch (AppDomainUnloadedException)
  90. {
  91. Console.WriteLine("[SCRIPT]: state change called when script was unloaded. Nothing to worry about, but noting the occurance");
  92. }
  93. }
  94. }
  95. }
  96. // Object never expires
  97. public override Object InitializeLifetimeService()
  98. {
  99. //Console.WriteLine("LSL_BuiltIn_Commands: InitializeLifetimeService()");
  100. // return null;
  101. ILease lease = (ILease)base.InitializeLifetimeService();
  102. if (lease.CurrentState == LeaseState.Initial)
  103. {
  104. lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1);
  105. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
  106. // lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
  107. }
  108. return lease;
  109. }
  110. public Scene World
  111. {
  112. get { return m_ScriptEngine.World; }
  113. }
  114. // Extension commands use this:
  115. public ICommander GetCommander(string name)
  116. {
  117. return World.GetCommander(name);
  118. }
  119. private LLUUID InventorySelf()
  120. {
  121. LLUUID invItemID=new LLUUID();
  122. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  123. {
  124. if(inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
  125. {
  126. invItemID=inv.Key;
  127. break;
  128. }
  129. }
  130. return invItemID;
  131. }
  132. private LLUUID InventoryKey(string name, int type)
  133. {
  134. m_host.AddScriptLPS(1);
  135. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  136. {
  137. if(inv.Value.Name == name)
  138. {
  139. if(inv.Value.Type != type)
  140. return LLUUID.Zero;
  141. return inv.Value.AssetID.ToString();
  142. }
  143. }
  144. return LLUUID.Zero;
  145. }
  146. private LLUUID InventoryKey(string name)
  147. {
  148. m_host.AddScriptLPS(1);
  149. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  150. {
  151. if(inv.Value.Name == name)
  152. {
  153. return inv.Value.AssetID.ToString();
  154. }
  155. }
  156. return LLUUID.Zero;
  157. }
  158. public void osSetRegionWaterHeight(double height)
  159. {
  160. m_host.AddScriptLPS(1);
  161. //Check to make sure that the script's owner is the estate manager/master
  162. //World.PermissionsMngr.GenericEstatePermission(
  163. if (World.PermissionsMngr.GenericEstatePermission(m_host.OwnerID))
  164. {
  165. World.EstateManager.setRegionSettings((float)height, 0f, 0f, false, 0.5f);
  166. World.EstateManager.sendRegionInfoPacketToAll();
  167. }
  168. }
  169. //These are the implementations of the various ll-functions used by the LSL scripts.
  170. //starting out, we use the System.Math library for trig functions. - ckrinke 8-14-07
  171. public double llSin(double f)
  172. {
  173. m_host.AddScriptLPS(1);
  174. return (double)Math.Sin(f);
  175. }
  176. public double llCos(double f)
  177. {
  178. m_host.AddScriptLPS(1);
  179. return (double)Math.Cos(f);
  180. }
  181. public double llTan(double f)
  182. {
  183. m_host.AddScriptLPS(1);
  184. return (double)Math.Tan(f);
  185. }
  186. public double llAtan2(double x, double y)
  187. {
  188. m_host.AddScriptLPS(1);
  189. return (double)Math.Atan2(y, x);
  190. }
  191. public double llSqrt(double f)
  192. {
  193. m_host.AddScriptLPS(1);
  194. return (double)Math.Sqrt(f);
  195. }
  196. public double llPow(double fbase, double fexponent)
  197. {
  198. m_host.AddScriptLPS(1);
  199. return (double)Math.Pow(fbase, fexponent);
  200. }
  201. public int llAbs(int i)
  202. {
  203. m_host.AddScriptLPS(1);
  204. return (int)Math.Abs(i);
  205. }
  206. public double llFabs(double f)
  207. {
  208. m_host.AddScriptLPS(1);
  209. return (double)Math.Abs(f);
  210. }
  211. public double llFrand(double mag)
  212. {
  213. m_host.AddScriptLPS(1);
  214. lock (Util.RandomClass)
  215. {
  216. return Util.RandomClass.NextDouble() * mag;
  217. }
  218. }
  219. public int llFloor(double f)
  220. {
  221. m_host.AddScriptLPS(1);
  222. return (int)Math.Floor(f);
  223. }
  224. public int llCeil(double f)
  225. {
  226. m_host.AddScriptLPS(1);
  227. return (int)Math.Ceiling(f);
  228. }
  229. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  230. public int llRound(double f)
  231. {
  232. m_host.AddScriptLPS(1);
  233. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  234. }
  235. //This next group are vector operations involving squaring and square root. ckrinke
  236. public double llVecMag(LSL_Types.Vector3 v)
  237. {
  238. m_host.AddScriptLPS(1);
  239. return LSL_Types.Vector3.Mag(v);
  240. }
  241. public LSL_Types.Vector3 llVecNorm(LSL_Types.Vector3 v)
  242. {
  243. m_host.AddScriptLPS(1);
  244. double mag = LSL_Types.Vector3.Mag(v);
  245. LSL_Types.Vector3 nor = new LSL_Types.Vector3();
  246. nor.x = v.x / mag;
  247. nor.y = v.y / mag;
  248. nor.z = v.z / mag;
  249. return nor;
  250. }
  251. public double llVecDist(LSL_Types.Vector3 a, LSL_Types.Vector3 b)
  252. {
  253. m_host.AddScriptLPS(1);
  254. double dx = a.x - b.x;
  255. double dy = a.y - b.y;
  256. double dz = a.z - b.z;
  257. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  258. }
  259. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  260. // Xantor's new llRot2Euler
  261. public LSL_Types.Vector3 llRot2Euler(LSL_Types.Quaternion r)
  262. {
  263. m_host.AddScriptLPS(1);
  264. double x, y, z;
  265. double sqw = r.s*r.s;
  266. double sqx = r.x*r.x;
  267. double sqy = r.y*r.y;
  268. double sqz = r.z*r.z;
  269. double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
  270. double test = r.x*r.y + r.z*r.s;
  271. if (test > 0.499 * unit) // singularity at north pole
  272. {
  273. x = 0;
  274. y = 2 * Math.Atan2(r.x, r.s);
  275. z = Math.PI/2;
  276. return new LSL_Types.Vector3(x, y, z);
  277. }
  278. if (test < -0.499 * unit) // singularity at south pole
  279. {
  280. x = 0;
  281. y = -2 * Math.Atan2(r.x,r.s);
  282. z = -Math.PI/2;
  283. return new LSL_Types.Vector3(x, y, z);
  284. }
  285. x = Math.Atan2(2 * r.x * r.s - 2 * r.y * r.z, -sqx + sqy - sqz + sqw);
  286. y = Math.Atan2(2*r.y*r.s-2*r.x*r.z , sqx - sqy - sqz + sqw);
  287. z = Math.Asin(2*test/unit);
  288. return new LSL_Types.Vector3(x, y, z);
  289. }
  290. // Old implementation of llRot2Euler
  291. /*
  292. public LSL_Types.Vector3 llRot2Euler(LSL_Types.Quaternion r)
  293. {
  294. m_host.AddScriptLPS(1);
  295. //This implementation is from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions. ckrinke
  296. LSL_Types.Quaternion t = new LSL_Types.Quaternion(r.x * r.x, r.y * r.y, r.z * r.z, r.s * r.s);
  297. double m = (t.x + t.y + t.z + t.s);
  298. if (m == 0) return new LSL_Types.Vector3();
  299. double n = 2 * (r.y * r.s + r.x * r.z);
  300. double p = m * m - n * n;
  301. if (p > 0)
  302. return new LSL_Types.Vector3(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s)),
  303. Math.Atan2(n, Math.Sqrt(p)),
  304. Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s)));
  305. else if (n > 0)
  306. return new LSL_Types.Vector3(0.0, Math.PI / 2, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
  307. else
  308. return new LSL_Types.Vector3(0.0, -Math.PI / 2, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
  309. }
  310. */
  311. // Xantor's new llEuler2Rot()
  312. /* From wiki:
  313. The Euler angle vector (in radians) is converted to a rotation by doing the rotations around the 3 axes
  314. in Z, Y, X order. So llEuler2Rot(<1.0, 2.0, 3.0> * DEG_TO_RAD) generates a rotation by taking the zero rotation,
  315. a vector pointing along the X axis, first rotating it 3 degrees around the global Z axis, then rotating the resulting
  316. vector 2 degrees around the global Y axis, and finally rotating that 1 degree around the global X axis.
  317. */
  318. public LSL_Types.Quaternion llEuler2Rot(LSL_Types.Vector3 v)
  319. {
  320. m_host.AddScriptLPS(1);
  321. double x,y,z,s;
  322. double c1 = Math.Cos(v.y / 2);
  323. double s1 = Math.Sin(v.y / 2 );
  324. double c2 = Math.Cos(v.z / 2 );
  325. double s2 = Math.Sin(v.z / 2 );
  326. double c3 = Math.Cos(v.x / 2 );
  327. double s3 = Math.Sin(v.x / 2 );
  328. double c1c2 = c1 * c2;
  329. double s1s2 = s1 * s2;
  330. s = c1c2 * c3 - s1s2 * s3;
  331. x = c1c2 * s3 + s1s2 * c3;
  332. y = s1 * c2 * c3 + c1 * s2 * s3;
  333. z = c1 * s2 * c3 - s1 * c2 * s3;
  334. return new LSL_Types.Quaternion(x, y, z, s);
  335. }
  336. /*
  337. // Old implementation
  338. public LSL_Types.Quaternion llEuler2Rot(LSL_Types.Vector3 v)
  339. {
  340. m_host.AddScriptLPS(1);
  341. //this comes from from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions but is incomplete as of 8/19/07
  342. float err = 0.00001f;
  343. double ax = Math.Sin(v.x / 2);
  344. double aw = Math.Cos(v.x / 2);
  345. double by = Math.Sin(v.y / 2);
  346. double bw = Math.Cos(v.y / 2);
  347. double cz = Math.Sin(v.z / 2);
  348. double cw = Math.Cos(v.z / 2);
  349. LSL_Types.Quaternion a1 = new LSL_Types.Quaternion(0.0, 0.0, cz, cw);
  350. LSL_Types.Quaternion a2 = new LSL_Types.Quaternion(0.0, by, 0.0, bw);
  351. LSL_Types.Quaternion a3 = new LSL_Types.Quaternion(ax, 0.0, 0.0, aw);
  352. LSL_Types.Quaternion a = (a1 * a2) * a3;
  353. //This multiplication doesnt compile, yet. a = a1 * a2 * a3;
  354. LSL_Types.Quaternion b = new LSL_Types.Quaternion(ax * bw * cw + aw * by * cz,
  355. aw * by * cw - ax * bw * cz, aw * bw * cz + ax * by * cw,
  356. aw * bw * cw - ax * by * cz);
  357. LSL_Types.Quaternion c = new LSL_Types.Quaternion();
  358. //This addition doesnt compile yet c = a + b;
  359. LSL_Types.Quaternion d = new LSL_Types.Quaternion();
  360. //This addition doesnt compile yet d = a - b;
  361. if ((Math.Abs(c.x) > err && Math.Abs(d.x) > err) ||
  362. (Math.Abs(c.y) > err && Math.Abs(d.y) > err) ||
  363. (Math.Abs(c.z) > err && Math.Abs(d.z) > err) ||
  364. (Math.Abs(c.s) > err && Math.Abs(d.s) > err))
  365. {
  366. return b;
  367. //return a new Quaternion that is null until I figure this out
  368. // return b;
  369. // return a;
  370. }
  371. return a;
  372. }
  373. */
  374. public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up)
  375. {
  376. m_host.AddScriptLPS(1);
  377. return new LSL_Types.Quaternion();
  378. }
  379. public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
  380. {
  381. m_host.AddScriptLPS(1);
  382. return (new LSL_Types.Vector3(1,0,0) * r);
  383. }
  384. public LSL_Types.Vector3 llRot2Left(LSL_Types.Quaternion r)
  385. {
  386. m_host.AddScriptLPS(1);
  387. return (new LSL_Types.Vector3(0, 1, 0) * r);
  388. }
  389. public LSL_Types.Vector3 llRot2Up(LSL_Types.Quaternion r)
  390. {
  391. m_host.AddScriptLPS(1);
  392. return (new LSL_Types.Vector3(0, 0, 1) * r);
  393. }
  394. public LSL_Types.Quaternion llRotBetween(LSL_Types.Vector3 a, LSL_Types.Vector3 b)
  395. {
  396. //A and B should both be normalized
  397. m_host.AddScriptLPS(1);
  398. double dotProduct = LSL_Types.Vector3.Dot(a, b);
  399. LSL_Types.Vector3 crossProduct = LSL_Types.Vector3.Cross(a, b);
  400. double magProduct = LSL_Types.Vector3.Mag(a) * LSL_Types.Vector3.Mag(b);
  401. double angle = Math.Acos(dotProduct / magProduct);
  402. LSL_Types.Vector3 axis = LSL_Types.Vector3.Norm(crossProduct);
  403. double s = Math.Sin(angle / 2);
  404. return new LSL_Types.Quaternion(axis.x * s, axis.y * s, axis.z * s, (float)Math.Cos(angle / 2));
  405. }
  406. public void llWhisper(int channelID, string text)
  407. {
  408. m_host.AddScriptLPS(1);
  409. World.SimChat(Helpers.StringToField(text),
  410. ChatTypeEnum.Whisper, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID);
  411. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  412. wComm.DeliverMessage(m_host.UUID.ToString(), ChatTypeEnum.Whisper, channelID, m_host.Name, text);
  413. }
  414. public void llSay(int channelID, string text)
  415. {
  416. m_host.AddScriptLPS(1);
  417. World.SimChat(Helpers.StringToField(text),
  418. ChatTypeEnum.Say, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID);
  419. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  420. wComm.DeliverMessage(m_host.UUID.ToString(), ChatTypeEnum.Say, channelID, m_host.Name, text);
  421. }
  422. public void llShout(int channelID, string text)
  423. {
  424. m_host.AddScriptLPS(1);
  425. World.SimChat(Helpers.StringToField(text),
  426. ChatTypeEnum.Shout, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID);
  427. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  428. wComm.DeliverMessage(m_host.UUID.ToString(), ChatTypeEnum.Shout, channelID, m_host.Name, text);
  429. }
  430. public void llRegionSay(int channelID, string text)
  431. {
  432. if(channelID == 0)
  433. {
  434. LSLError("Cannot use llRegionSay() on channel 0");
  435. return;
  436. }
  437. m_host.AddScriptLPS(1);
  438. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  439. wComm.DeliverMessage(m_host.UUID.ToString(), ChatTypeEnum.Broadcast, channelID, m_host.Name, text);
  440. }
  441. public int llListen(int channelID, string name, string ID, string msg)
  442. {
  443. m_host.AddScriptLPS(1);
  444. if (ID == String.Empty)
  445. {
  446. ID = LLUUID.Zero.ToString();
  447. }
  448. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  449. return wComm.Listen(m_localID, m_itemID, m_host.UUID, channelID, name, ID, msg);
  450. }
  451. public void llListenControl(int number, int active)
  452. {
  453. m_host.AddScriptLPS(1);
  454. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  455. wComm.ListenControl(number, active);
  456. }
  457. public void llListenRemove(int number)
  458. {
  459. m_host.AddScriptLPS(1);
  460. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  461. wComm.ListenRemove(number);
  462. }
  463. public void llSensor(string name, string id, int type, double range, double arc)
  464. {
  465. m_host.AddScriptLPS(1);
  466. LLUUID keyID = LLUUID.Zero;
  467. try
  468. {
  469. if (id.Length > 0) keyID = new LLUUID(id);
  470. }
  471. catch
  472. {
  473. }
  474. m_ScriptEngine.m_ASYNCLSLCommandManager.m_SensorRepeat.SenseOnce(m_localID, m_itemID, name, keyID, type, range, arc, m_host);
  475. return;
  476. }
  477. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  478. {
  479. m_host.AddScriptLPS(1);
  480. LLUUID keyID = LLUUID.Zero;
  481. try
  482. {
  483. if (id.Length > 0) keyID = new LLUUID(id);
  484. }
  485. catch
  486. {
  487. }
  488. m_ScriptEngine.m_ASYNCLSLCommandManager.m_SensorRepeat.SetSenseRepeatEvent(m_localID, m_itemID, name, keyID, type, range, arc, rate, m_host);
  489. return;
  490. }
  491. public void llSensorRemove()
  492. {
  493. m_host.AddScriptLPS(1);
  494. m_ScriptEngine.m_ASYNCLSLCommandManager.m_SensorRepeat.UnSetSenseRepeaterEvents(m_localID, m_itemID);
  495. return;
  496. }
  497. public string resolveName(LLUUID objecUUID)
  498. {
  499. // try avatar username surname
  500. UserProfileData profile = World.CommsManager.UserService.GetUserProfile(objecUUID);
  501. if (profile != null)
  502. {
  503. string avatarname = profile.FirstName + " " + profile.SurName;
  504. return avatarname;
  505. }
  506. // try an scene object
  507. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  508. if (SOP != null)
  509. {
  510. string objectname = SOP.Name;
  511. return objectname;
  512. }
  513. EntityBase SensedObject = null;
  514. lock (World.Entities)
  515. {
  516. World.Entities.TryGetValue(objecUUID, out SensedObject);
  517. }
  518. if (SensedObject == null)
  519. return String.Empty;
  520. return SensedObject.Name;
  521. }
  522. public string llDetectedName(int number)
  523. {
  524. m_host.AddScriptLPS(1);
  525. LSL_Types.list SenseList = m_ScriptEngine.m_ASYNCLSLCommandManager.m_SensorRepeat.GetSensorList(m_localID, m_itemID);
  526. if (SenseList != null)
  527. {
  528. if ((number >= 0) && (number <= SenseList.Length))
  529. {
  530. LLUUID SensedUUID = (LLUUID)SenseList.Data[number];
  531. return resolveName(SensedUUID);
  532. }
  533. }
  534. return String.Empty;
  535. }
  536. public LLUUID uuidDetectedKey(int number)
  537. {
  538. LSL_Types.list SenseList = m_ScriptEngine.m_ASYNCLSLCommandManager.m_SensorRepeat.GetSensorList(m_localID, m_itemID);
  539. if (SenseList != null)
  540. {
  541. if ((number >= 0) && (number < SenseList.Length))
  542. {
  543. LLUUID SensedUUID = (LLUUID)SenseList.Data[number];
  544. return SensedUUID;
  545. }
  546. }
  547. else
  548. {
  549. ScriptManager sm;
  550. IScript script = null;
  551. if ((sm = m_ScriptEngine.m_ScriptManager) != null)
  552. {
  553. if (sm.Scripts.ContainsKey(m_localID))
  554. {
  555. if ((script = sm.GetScript(m_localID, m_itemID)) != null)
  556. {
  557. if (script.llDetectParams._key[0] != null)
  558. {
  559. return new LLUUID(script.llDetectParams._key[0]);
  560. }
  561. }
  562. }
  563. }
  564. }
  565. return LLUUID.Zero;
  566. }
  567. public EntityBase entityDetectedKey(int number)
  568. {
  569. LSL_Types.list SenseList = m_ScriptEngine.m_ASYNCLSLCommandManager.m_SensorRepeat.GetSensorList(m_localID, m_itemID);
  570. if (SenseList != null)
  571. {
  572. if ((number >= 0) && (number < SenseList.Length))
  573. {
  574. LLUUID SensedUUID = (LLUUID)SenseList.Data[number];
  575. EntityBase SensedObject = null;
  576. lock (World.Entities)
  577. {
  578. World.Entities.TryGetValue(SensedUUID, out SensedObject);
  579. }
  580. return SensedObject;
  581. }
  582. }
  583. return null;
  584. }
  585. public string llDetectedKey(int number)
  586. {
  587. m_host.AddScriptLPS(1);
  588. LLUUID SensedUUID = uuidDetectedKey(number);
  589. if (SensedUUID == LLUUID.Zero)
  590. return String.Empty;
  591. return SensedUUID.ToString();
  592. }
  593. public string llDetectedOwner(int number)
  594. {
  595. // returns UUID of owner of object detected
  596. m_host.AddScriptLPS(1);
  597. EntityBase SensedObject = entityDetectedKey(number);
  598. if (SensedObject ==null)
  599. return String.Empty;
  600. LLUUID SensedUUID = uuidDetectedKey(number);
  601. if (World.GetScenePresence(SensedUUID) == null)
  602. {
  603. // sensed object is not an avatar
  604. // so get the owner of the sensed object
  605. SceneObjectPart SOP = World.GetSceneObjectPart(SensedUUID);
  606. if (SOP != null) { return SOP.ObjectOwner.ToString(); }
  607. }
  608. else
  609. {
  610. // sensed object is an avatar, and so must be its own owner
  611. return SensedUUID.ToString();
  612. }
  613. return String.Empty;
  614. }
  615. public int llDetectedType(int number)
  616. {
  617. m_host.AddScriptLPS(1);
  618. EntityBase SensedObject = entityDetectedKey(number);
  619. if (SensedObject == null)
  620. return 0;
  621. int mask = 0;
  622. LLUUID SensedUUID = uuidDetectedKey(number);
  623. LSL_Types.Vector3 ZeroVector = new LSL_Types.Vector3(0, 0, 0);
  624. if (World.GetScenePresence(SensedUUID) != null) mask |= 0x01; // actor
  625. if (SensedObject.Velocity.Equals(ZeroVector))
  626. mask |= 0x04; // passive non-moving
  627. else
  628. mask |= 0x02; // active moving
  629. if (SensedObject is IScript) mask |= 0x08; // Scripted. It COULD have one hidden ...
  630. return mask;
  631. }
  632. public LSL_Types.Vector3 llDetectedPos(int number)
  633. {
  634. m_host.AddScriptLPS(1);
  635. EntityBase SensedObject = entityDetectedKey(number);
  636. if (SensedObject == null)
  637. return new LSL_Types.Vector3(0, 0, 0);
  638. return new LSL_Types.Vector3(SensedObject.AbsolutePosition.X,SensedObject.AbsolutePosition.Y,SensedObject.AbsolutePosition.Z);
  639. }
  640. public LSL_Types.Vector3 llDetectedVel(int number)
  641. {
  642. m_host.AddScriptLPS(1);
  643. EntityBase SensedObject = entityDetectedKey(number);
  644. if (SensedObject == null)
  645. return new LSL_Types.Vector3(0, 0, 0);
  646. return new LSL_Types.Vector3(SensedObject.Velocity.X, SensedObject.Velocity.Y, SensedObject.Velocity.Z);
  647. // return new LSL_Types.Vector3();
  648. }
  649. public LSL_Types.Vector3 llDetectedGrab(int number)
  650. {
  651. m_host.AddScriptLPS(1);
  652. NotImplemented("llDetectedGrab");
  653. return new LSL_Types.Vector3();
  654. }
  655. public LSL_Types.Quaternion llDetectedRot(int number)
  656. {
  657. m_host.AddScriptLPS(1);
  658. EntityBase SensedObject = entityDetectedKey(number);
  659. if (SensedObject == null)
  660. return new LSL_Types.Quaternion();
  661. return new LSL_Types.Quaternion(SensedObject.Rotation.x, SensedObject.Rotation.y, SensedObject.Rotation.z, SensedObject.Rotation.w);
  662. }
  663. public int llDetectedGroup(int number)
  664. {
  665. m_host.AddScriptLPS(1);
  666. NotImplemented("llDetectedGroup");
  667. return 0;
  668. }
  669. public int llDetectedLinkNumber(int number)
  670. {
  671. m_host.AddScriptLPS(1);
  672. NotImplemented("llDetectedLinkNumber");
  673. return 0;
  674. }
  675. public void llDie()
  676. {
  677. m_host.AddScriptLPS(1);
  678. World.DeleteSceneObjectGroup(m_host.ParentGroup);
  679. return;
  680. }
  681. public double llGround(LSL_Types.Vector3 offset)
  682. {
  683. m_host.AddScriptLPS(1);
  684. int x = (int)(m_host.AbsolutePosition.X + offset.x);
  685. int y = (int)(m_host.AbsolutePosition.Y + offset.y);
  686. return World.GetLandHeight(x, y);
  687. }
  688. public double llCloud(LSL_Types.Vector3 offset)
  689. {
  690. m_host.AddScriptLPS(1);
  691. NotImplemented("llCloud");
  692. return 0;
  693. }
  694. public LSL_Types.Vector3 llWind(LSL_Types.Vector3 offset)
  695. {
  696. m_host.AddScriptLPS(1);
  697. NotImplemented("llWind");
  698. return new LSL_Types.Vector3();
  699. }
  700. public void llSetStatus(int status, int value)
  701. {
  702. m_host.AddScriptLPS(1);
  703. int statusrotationaxis = 0;
  704. if ((status & BuiltIn_Commands_BaseClass.STATUS_PHYSICS) == BuiltIn_Commands_BaseClass.STATUS_PHYSICS)
  705. {
  706. if (value == 1)
  707. m_host.ScriptSetPhysicsStatus(true);
  708. else
  709. m_host.ScriptSetPhysicsStatus(false);
  710. }
  711. if ((status & BuiltIn_Commands_BaseClass.STATUS_PHANTOM) == BuiltIn_Commands_BaseClass.STATUS_PHANTOM)
  712. {
  713. if (value == 1)
  714. m_host.ScriptSetPhantomStatus(true);
  715. else
  716. m_host.ScriptSetPhantomStatus(false);
  717. }
  718. if ((status & BuiltIn_Commands_BaseClass.STATUS_CAST_SHADOWS) == BuiltIn_Commands_BaseClass.STATUS_CAST_SHADOWS)
  719. {
  720. m_host.AddFlag(LLObject.ObjectFlags.CastShadows);
  721. }
  722. if ((status & BuiltIn_Commands_BaseClass.STATUS_ROTATE_X) == BuiltIn_Commands_BaseClass.STATUS_ROTATE_X)
  723. {
  724. statusrotationaxis |= BuiltIn_Commands_BaseClass.STATUS_ROTATE_X;
  725. }
  726. if ((status & BuiltIn_Commands_BaseClass.STATUS_ROTATE_Y) == BuiltIn_Commands_BaseClass.STATUS_ROTATE_Y)
  727. {
  728. statusrotationaxis |= BuiltIn_Commands_BaseClass.STATUS_ROTATE_Y;
  729. }
  730. if ((status & BuiltIn_Commands_BaseClass.STATUS_ROTATE_Z) == BuiltIn_Commands_BaseClass.STATUS_ROTATE_Z)
  731. {
  732. statusrotationaxis |= BuiltIn_Commands_BaseClass.STATUS_ROTATE_Z;
  733. }
  734. if ((status & BuiltIn_Commands_BaseClass.STATUS_BLOCK_GRAB) == BuiltIn_Commands_BaseClass.STATUS_BLOCK_GRAB)
  735. {
  736. NotImplemented("llSetStatus - STATUS_BLOCK_GRAB");
  737. }
  738. if ((status & BuiltIn_Commands_BaseClass.STATUS_DIE_AT_EDGE) == BuiltIn_Commands_BaseClass.STATUS_DIE_AT_EDGE)
  739. {
  740. NotImplemented("llSetStatus - STATUS_DIE_AT_EDGE");
  741. }
  742. if ((status & BuiltIn_Commands_BaseClass.STATUS_RETURN_AT_EDGE) == BuiltIn_Commands_BaseClass.STATUS_RETURN_AT_EDGE)
  743. {
  744. NotImplemented("llSetStatus - STATUS_RETURN_AT_EDGE");
  745. }
  746. if ((status & BuiltIn_Commands_BaseClass.STATUS_SANDBOX) == BuiltIn_Commands_BaseClass.STATUS_SANDBOX)
  747. {
  748. NotImplemented("llSetStatus - STATUS_SANDBOX");
  749. }
  750. if (statusrotationaxis != 0)
  751. {
  752. m_host.SetAxisRotation(statusrotationaxis, value);
  753. }
  754. return;
  755. }
  756. public int llGetStatus(int status)
  757. {
  758. m_host.AddScriptLPS(1);
  759. Console.WriteLine(m_host.UUID.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  760. switch (status)
  761. {
  762. case BuiltIn_Commands_BaseClass.STATUS_PHYSICS:
  763. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Physics) == (uint)LLObject.ObjectFlags.Physics)
  764. {
  765. return 1;
  766. }
  767. return 0;
  768. case BuiltIn_Commands_BaseClass.STATUS_PHANTOM:
  769. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Phantom) == (uint)LLObject.ObjectFlags.Phantom)
  770. {
  771. return 1;
  772. }
  773. return 0;
  774. case BuiltIn_Commands_BaseClass.STATUS_CAST_SHADOWS:
  775. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.CastShadows) == (uint)LLObject.ObjectFlags.CastShadows)
  776. {
  777. return 1;
  778. }
  779. return 0;
  780. case BuiltIn_Commands_BaseClass.STATUS_BLOCK_GRAB:
  781. NotImplemented("llGetStatus - STATUS_BLOCK_GRAB");
  782. return 0;
  783. case BuiltIn_Commands_BaseClass.STATUS_DIE_AT_EDGE:
  784. NotImplemented("llGetStatus - STATUS_DIE_AT_EDGE");
  785. return 0;
  786. case BuiltIn_Commands_BaseClass.STATUS_RETURN_AT_EDGE:
  787. NotImplemented("llGetStatus - STATUS_RETURN_AT_EDGE");
  788. return 0;
  789. case BuiltIn_Commands_BaseClass.STATUS_ROTATE_X:
  790. NotImplemented("llGetStatus - STATUS_ROTATE_X");
  791. return 0;
  792. case BuiltIn_Commands_BaseClass.STATUS_ROTATE_Y:
  793. NotImplemented("llGetStatus - STATUS_ROTATE_Y");
  794. return 0;
  795. case BuiltIn_Commands_BaseClass.STATUS_ROTATE_Z:
  796. NotImplemented("llGetStatus - STATUS_ROTATE_Z");
  797. return 0;
  798. case BuiltIn_Commands_BaseClass.STATUS_SANDBOX:
  799. NotImplemented("llGetStatus - STATUS_SANDBOX");
  800. return 0;
  801. }
  802. NotImplemented("llGetStatus - Unknown Status parameter");
  803. return 0;
  804. }
  805. public void llSetScale(LSL_Types.Vector3 scale)
  806. {
  807. m_host.AddScriptLPS(1);
  808. SetScale(m_host, scale);
  809. }
  810. private void SetScale(SceneObjectPart part, LSL_Types.Vector3 scale)
  811. {
  812. // TODO: this needs to trigger a persistance save as well
  813. LLVector3 tmp = part.Scale;
  814. tmp.X = (float)scale.x;
  815. tmp.Y = (float)scale.y;
  816. tmp.Z = (float)scale.z;
  817. part.Scale = tmp;
  818. part.SendFullUpdateToAllClients();
  819. return;
  820. }
  821. public LSL_Types.Vector3 llGetScale()
  822. {
  823. m_host.AddScriptLPS(1);
  824. return new LSL_Types.Vector3(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  825. }
  826. public void llSetColor(LSL_Types.Vector3 color, int face)
  827. {
  828. m_host.AddScriptLPS(1);
  829. SetColor(m_host, color, face);
  830. }
  831. private void SetColor(SceneObjectPart part, LSL_Types.Vector3 color, int face)
  832. {
  833. LLObject.TextureEntry tex = part.Shape.Textures;
  834. LLColor texcolor;
  835. if (face > -1)
  836. {
  837. texcolor = tex.CreateFace((uint)face).RGBA;
  838. texcolor.R = (float)Math.Abs(color.x - 1);
  839. texcolor.G = (float)Math.Abs(color.y - 1);
  840. texcolor.B = (float)Math.Abs(color.z - 1);
  841. tex.FaceTextures[face].RGBA = texcolor;
  842. part.UpdateTexture(tex);
  843. return;
  844. }
  845. else if (face == -1)
  846. {
  847. for (uint i = 0; i < 32; i++)
  848. {
  849. if (tex.FaceTextures[i] != null)
  850. {
  851. texcolor = tex.FaceTextures[i].RGBA;
  852. texcolor.R = (float)Math.Abs(color.x - 1);
  853. texcolor.G = (float)Math.Abs(color.y - 1);
  854. texcolor.B = (float)Math.Abs(color.z - 1);
  855. tex.FaceTextures[i].RGBA = texcolor;
  856. }
  857. texcolor = tex.DefaultTexture.RGBA;
  858. texcolor.R = (float)Math.Abs(color.x - 1);
  859. texcolor.G = (float)Math.Abs(color.y - 1);
  860. texcolor.B = (float)Math.Abs(color.z - 1);
  861. tex.DefaultTexture.RGBA = texcolor;
  862. }
  863. part.UpdateTexture(tex);
  864. return;
  865. }
  866. else
  867. {
  868. NotImplemented("llSetColor");
  869. }
  870. }
  871. public double llGetAlpha(int face)
  872. {
  873. m_host.AddScriptLPS(1);
  874. LLObject.TextureEntry tex = m_host.Shape.Textures;
  875. if (face == -1) // TMP: Until we can determine number of sides, ALL_SIDES (-1) will return default color
  876. {
  877. return (double)((tex.DefaultTexture.RGBA.A * 255) / 255);
  878. }
  879. if (face > -1)
  880. {
  881. return (double)((tex.GetFace((uint)face).RGBA.A * 255) / 255);
  882. }
  883. return 0;
  884. }
  885. public void llSetAlpha(double alpha, int face)
  886. {
  887. m_host.AddScriptLPS(1);
  888. SetAlpha(m_host, alpha, face);
  889. }
  890. private void SetAlpha(SceneObjectPart part, double alpha, int face)
  891. {
  892. LLObject.TextureEntry tex = part.Shape.Textures;
  893. LLColor texcolor;
  894. if (face > -1)
  895. {
  896. texcolor = tex.CreateFace((uint)face).RGBA;
  897. texcolor.A = (float)Math.Abs(alpha - 1);
  898. tex.FaceTextures[face].RGBA = texcolor;
  899. part.UpdateTexture(tex);
  900. return;
  901. }
  902. else if (face == -1)
  903. {
  904. for (int i = 0; i < 32; i++)
  905. {
  906. if (tex.FaceTextures[i] != null)
  907. {
  908. texcolor = tex.FaceTextures[i].RGBA;
  909. texcolor.A = (float)Math.Abs(alpha - 1);
  910. tex.FaceTextures[i].RGBA = texcolor;
  911. }
  912. }
  913. texcolor = tex.DefaultTexture.RGBA;
  914. texcolor.A = (float)Math.Abs(alpha - 1);
  915. tex.DefaultTexture.RGBA = texcolor;
  916. part.UpdateTexture(tex);
  917. return;
  918. }
  919. else
  920. {
  921. NotImplemented("llSetAlpha");
  922. }
  923. }
  924. public LSL_Types.Vector3 llGetColor(int face)
  925. {
  926. m_host.AddScriptLPS(1);
  927. LLObject.TextureEntry tex = m_host.Shape.Textures;
  928. LLColor texcolor;
  929. LSL_Types.Vector3 rgb;
  930. if (face == -1) // TMP: Until we can determine number of sides, ALL_SIDES (-1) will return default color
  931. {
  932. texcolor = tex.DefaultTexture.RGBA;
  933. rgb.x = (255 - (texcolor.R * 255)) / 255;
  934. rgb.y = (255 - (texcolor.G * 255)) / 255;
  935. rgb.z = (255 - (texcolor.B * 255)) / 255;
  936. return rgb;
  937. }
  938. if (face > -1)
  939. {
  940. texcolor = tex.GetFace((uint)face).RGBA;
  941. rgb.x = (255 - (texcolor.R * 255)) / 255;
  942. rgb.y = (255 - (texcolor.G * 255)) / 255;
  943. rgb.z = (255 - (texcolor.B * 255)) / 255;
  944. return rgb;
  945. }
  946. else
  947. {
  948. NotImplemented("llGetColor");
  949. return new LSL_Types.Vector3();
  950. }
  951. }
  952. public void llSetTexture(string texture, int face)
  953. {
  954. m_host.AddScriptLPS(1);
  955. SetTexture(m_host, texture, face);
  956. }
  957. private void SetTexture(SceneObjectPart part, string texture, int face)
  958. {
  959. LLUUID textureID=new LLUUID();
  960. if(!LLUUID.TryParse(texture, out textureID))
  961. {
  962. textureID=InventoryKey(texture, (int)AssetType.Texture);
  963. }
  964. if(textureID == LLUUID.Zero)
  965. return;
  966. LLObject.TextureEntry tex = part.Shape.Textures;
  967. if (face > -1)
  968. {
  969. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  970. texface.TextureID = textureID;
  971. tex.FaceTextures[face] = texface;
  972. part.UpdateTexture(tex);
  973. return;
  974. }
  975. else if (face == -1)
  976. {
  977. for (uint i = 0; i < 32; i++)
  978. {
  979. if (tex.FaceTextures[i] != null)
  980. {
  981. tex.FaceTextures[i].TextureID = textureID;
  982. }
  983. }
  984. tex.DefaultTexture.TextureID = textureID;
  985. part.UpdateTexture(tex);
  986. return;
  987. }
  988. else
  989. {
  990. NotImplemented("llSetTexture");
  991. }
  992. }
  993. public void llScaleTexture(double u, double v, int face)
  994. {
  995. m_host.AddScriptLPS(1);
  996. ScaleTexture(m_host, u, v, face);
  997. }
  998. private void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  999. {
  1000. LLObject.TextureEntry tex = part.Shape.Textures;
  1001. if (face > -1)
  1002. {
  1003. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  1004. texface.RepeatU = (float)u;
  1005. texface.RepeatV = (float)v;
  1006. tex.FaceTextures[face] = texface;
  1007. part.UpdateTexture(tex);
  1008. return;
  1009. }
  1010. if (face == -1)
  1011. {
  1012. for (int i = 0; i < 32; i++)
  1013. {
  1014. if (tex.FaceTextures[i] != null)
  1015. {
  1016. tex.FaceTextures[i].RepeatU = (float)u;
  1017. tex.FaceTextures[i].RepeatV = (float)v;
  1018. }
  1019. }
  1020. tex.DefaultTexture.RepeatU = (float)u;
  1021. tex.DefaultTexture.RepeatV = (float)v;
  1022. part.UpdateTexture(tex);
  1023. return;
  1024. }
  1025. else
  1026. {
  1027. NotImplemented("llScaleTexture");
  1028. }
  1029. }
  1030. public void llOffsetTexture(double u, double v, int face)
  1031. {
  1032. m_host.AddScriptLPS(1);
  1033. OffsetTexture(m_host, u, v, face);
  1034. }
  1035. private void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  1036. {
  1037. LLObject.TextureEntry tex = part.Shape.Textures;
  1038. if (face > -1)
  1039. {
  1040. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  1041. texface.OffsetU = (float)u;
  1042. texface.OffsetV = (float)v;
  1043. tex.FaceTextures[face] = texface;
  1044. part.UpdateTexture(tex);
  1045. return;
  1046. }
  1047. if (face == -1)
  1048. {
  1049. for (int i = 0; i < 32; i++)
  1050. {
  1051. if (tex.FaceTextures[i] != null)
  1052. {
  1053. tex.FaceTextures[i].OffsetU = (float)u;
  1054. tex.FaceTextures[i].OffsetV = (float)v;
  1055. }
  1056. }
  1057. tex.DefaultTexture.OffsetU = (float)u;
  1058. tex.DefaultTexture.OffsetV = (float)v;
  1059. part.UpdateTexture(tex);
  1060. return;
  1061. }
  1062. else
  1063. {
  1064. NotImplemented("llOffsetTexture");
  1065. }
  1066. }
  1067. public void llRotateTexture(double rotation, int face)
  1068. {
  1069. m_host.AddScriptLPS(1);
  1070. RotateTexture(m_host, rotation, face);
  1071. }
  1072. private void RotateTexture(SceneObjectPart part, double rotation, int face)
  1073. {
  1074. LLObject.TextureEntry tex = part.Shape.Textures;
  1075. if (face > -1)
  1076. {
  1077. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  1078. texface.Rotation = (float)rotation;
  1079. tex.FaceTextures[face] = texface;
  1080. part.UpdateTexture(tex);
  1081. return;
  1082. }
  1083. if (face == -1)
  1084. {
  1085. for (int i = 0; i < 32; i++)
  1086. {
  1087. if (tex.FaceTextures[i] != null)
  1088. {
  1089. tex.FaceTextures[i].Rotation = (float)rotation;
  1090. }
  1091. }
  1092. tex.DefaultTexture.Rotation = (float)rotation;
  1093. part.UpdateTexture(tex);
  1094. return;
  1095. }
  1096. else
  1097. {
  1098. NotImplemented("llRotateTexture");
  1099. }
  1100. }
  1101. public string llGetTexture(int face)
  1102. {
  1103. m_host.AddScriptLPS(1);
  1104. LLObject.TextureEntry tex = m_host.Shape.Textures;
  1105. if (face == -1)
  1106. {
  1107. face = 0;
  1108. }
  1109. if (face > -1)
  1110. {
  1111. LLObject.TextureEntryFace texface;
  1112. texface = tex.GetFace((uint)face);
  1113. return texface.TextureID.ToString();
  1114. }
  1115. else
  1116. {
  1117. NotImplemented("llGetTexture");
  1118. return String.Empty;
  1119. }
  1120. }
  1121. public void llSetPos(LSL_Types.Vector3 pos)
  1122. {
  1123. m_host.AddScriptLPS(1);
  1124. SetPos(m_host, pos);
  1125. }
  1126. private void SetPos(SceneObjectPart part, LSL_Types.Vector3 pos)
  1127. {
  1128. if (part.ParentID != 0)
  1129. {
  1130. part.UpdateOffSet(new LLVector3((float)pos.x, (float)pos.y, (float)pos.z));
  1131. }
  1132. else
  1133. {
  1134. part.UpdateGroupPosition(new LLVector3((float)pos.x, (float)pos.y, (float)pos.z));
  1135. }
  1136. }
  1137. public LSL_Types.Vector3 llGetPos()
  1138. {
  1139. m_host.AddScriptLPS(1);
  1140. return new LSL_Types.Vector3(m_host.AbsolutePosition.X,
  1141. m_host.AbsolutePosition.Y,
  1142. m_host.AbsolutePosition.Z);
  1143. }
  1144. public LSL_Types.Vector3 llGetLocalPos()
  1145. {
  1146. m_host.AddScriptLPS(1);
  1147. if (m_host.ParentID != 0)
  1148. {
  1149. return new LSL_Types.Vector3(m_host.OffsetPosition.X,
  1150. m_host.OffsetPosition.Y,
  1151. m_host.OffsetPosition.Z);
  1152. }
  1153. else
  1154. {
  1155. return new LSL_Types.Vector3(m_host.AbsolutePosition.X,
  1156. m_host.AbsolutePosition.Y,
  1157. m_host.AbsolutePosition.Z);
  1158. }
  1159. }
  1160. public void llSetRot(LSL_Types.Quaternion rot)
  1161. {
  1162. m_host.AddScriptLPS(1);
  1163. SetRot(m_host, rot);
  1164. }
  1165. private void SetRot(SceneObjectPart part, LSL_Types.Quaternion rot)
  1166. {
  1167. part.UpdateRotation(new LLQuaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s));
  1168. // Update rotation does not move the object in the physics scene if it's a linkset.
  1169. part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition;
  1170. }
  1171. public LSL_Types.Quaternion llGetRot()
  1172. {
  1173. m_host.AddScriptLPS(1);
  1174. LLQuaternion q = m_host.RotationOffset;
  1175. return new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
  1176. }
  1177. public LSL_Types.Quaternion llGetLocalRot()
  1178. {
  1179. m_host.AddScriptLPS(1);
  1180. return new LSL_Types.Quaternion(m_host.RotationOffset.X, m_host.RotationOffset.Y, m_host.RotationOffset.Z, m_host.RotationOffset.W);
  1181. }
  1182. public void llSetForce(LSL_Types.Vector3 force, int local)
  1183. {
  1184. m_host.AddScriptLPS(1);
  1185. NotImplemented("llSetForce");
  1186. }
  1187. public LSL_Types.Vector3 llGetForce()
  1188. {
  1189. m_host.AddScriptLPS(1);
  1190. NotImplemented("llGetForce");
  1191. return new LSL_Types.Vector3();
  1192. }
  1193. public int llTarget(LSL_Types.Vector3 position, double range)
  1194. {
  1195. m_host.AddScriptLPS(1);
  1196. return m_host.registerTargetWaypoint(new LLVector3((float)position.x, (float)position.y, (float)position.z), (float)range);
  1197. }
  1198. public void llTargetRemove(int number)
  1199. {
  1200. m_host.AddScriptLPS(1);
  1201. m_host.unregisterTargetWaypoint(number);
  1202. }
  1203. public int llRotTarget(LSL_Types.Quaternion rot, double error)
  1204. {
  1205. m_host.AddScriptLPS(1);
  1206. NotImplemented("llRotTarget");
  1207. return 0;
  1208. }
  1209. public void llRotTargetRemove(int number)
  1210. {
  1211. m_host.AddScriptLPS(1);
  1212. NotImplemented("llRotTargetRemove");
  1213. }
  1214. public void llMoveToTarget(LSL_Types.Vector3 target, double tau)
  1215. {
  1216. m_host.AddScriptLPS(1);
  1217. m_host.MoveToTarget(new LLVector3((float)target.x, (float)target.y, (float)target.z), (float)tau);
  1218. }
  1219. public void llStopMoveToTarget()
  1220. {
  1221. m_host.AddScriptLPS(1);
  1222. m_host.StopMoveToTarget();
  1223. }
  1224. public void llApplyImpulse(LSL_Types.Vector3 force, int local)
  1225. {
  1226. m_host.AddScriptLPS(1);
  1227. //No energy force yet
  1228. if (force.x > 20000)
  1229. force.x = 20000;
  1230. if (force.y > 20000)
  1231. force.y = 20000;
  1232. if (force.z > 20000)
  1233. force.z = 20000;
  1234. if (local == 1)
  1235. {
  1236. m_host.ApplyImpulse(new LLVector3((float)force.x, (float)force.y, (float)force.z), true);
  1237. }
  1238. else
  1239. {
  1240. m_host.ApplyImpulse(new LLVector3((float)force.x,(float)force.y,(float)force.z), false);
  1241. }
  1242. }
  1243. public void llApplyRotationalImpulse(LSL_Types.Vector3 force, int local)
  1244. {
  1245. m_host.AddScriptLPS(1);
  1246. NotImplemented("llApplyRotationalImpulse");
  1247. }
  1248. public void llSetTorque(LSL_Types.Vector3 torque, int local)
  1249. {
  1250. m_host.AddScriptLPS(1);
  1251. NotImplemented("llSetTorque");
  1252. }
  1253. public LSL_Types.Vector3 llGetTorque()
  1254. {
  1255. m_host.AddScriptLPS(1);
  1256. NotImplemented("llGetTorque");
  1257. return new LSL_Types.Vector3();
  1258. }
  1259. public void llSetForceAndTorque(LSL_Types.Vector3 force, LSL_Types.Vector3 torque, int local)
  1260. {
  1261. m_host.AddScriptLPS(1);
  1262. NotImplemented("llSetForceAndTorque");
  1263. }
  1264. public LSL_Types.Vector3 llGetVel()
  1265. {
  1266. m_host.AddScriptLPS(1);
  1267. return new LSL_Types.Vector3(m_host.Velocity.X, m_host.Velocity.Y, m_host.Velocity.Z);
  1268. }
  1269. public LSL_Types.Vector3 llGetAccel()
  1270. {
  1271. m_host.AddScriptLPS(1);
  1272. return new LSL_Types.Vector3(m_host.Acceleration.X, m_host.Acceleration.Y, m_host.Acceleration.Z);
  1273. }
  1274. public LSL_Types.Vector3 llGetOmega()
  1275. {
  1276. m_host.AddScriptLPS(1);
  1277. return new LSL_Types.Vector3(m_host.RotationalVelocity.X, m_host.RotationalVelocity.Y, m_host.RotationalVelocity.Z);
  1278. }
  1279. public double llGetTimeOfDay()
  1280. {
  1281. m_host.AddScriptLPS(1);
  1282. NotImplemented("llGetTimeOfDay");
  1283. return 0;
  1284. }
  1285. public double llGetWallclock()
  1286. {
  1287. m_host.AddScriptLPS(1);
  1288. return DateTime.Now.TimeOfDay.TotalSeconds;
  1289. }
  1290. public double llGetTime()
  1291. {
  1292. m_host.AddScriptLPS(1);
  1293. TimeSpan ScriptTime = DateTime.Now - m_timer;
  1294. return (double)(ScriptTime.TotalMilliseconds / 1000);
  1295. }
  1296. public void llResetTime()
  1297. {
  1298. m_host.AddScriptLPS(1);
  1299. m_timer = DateTime.Now;
  1300. }
  1301. public double llGetAndResetTime()
  1302. {
  1303. m_host.AddScriptLPS(1);
  1304. TimeSpan ScriptTime = DateTime.Now - m_timer;
  1305. m_timer = DateTime.Now;
  1306. return (double)(ScriptTime.TotalMilliseconds / 1000);
  1307. }
  1308. public void llSound()
  1309. {
  1310. m_host.AddScriptLPS(1);
  1311. // This function has been deprecated
  1312. // see http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSound
  1313. Deprecated("llSound");
  1314. }
  1315. public void llPlaySound(string sound, double volume)
  1316. {
  1317. m_host.AddScriptLPS(1);
  1318. m_host.SendSound(sound, volume, false, 0);
  1319. }
  1320. public void llLoopSound(string sound, double volume)
  1321. {
  1322. m_host.AddScriptLPS(1);
  1323. m_host.SendSound(sound, volume, false, 1);
  1324. }
  1325. public void llLoopSoundMaster(string sound, double volume)
  1326. {
  1327. m_host.AddScriptLPS(1);
  1328. NotImplemented("llLoopSoundMaster");
  1329. }
  1330. public void llLoopSoundSlave(string sound, double volume)
  1331. {
  1332. m_host.AddScriptLPS(1);
  1333. NotImplemented("llLoopSoundSlave");
  1334. }
  1335. public void llPlaySoundSlave(string sound, double volume)
  1336. {
  1337. m_host.AddScriptLPS(1);
  1338. NotImplemented("llPlaySoundSlave");
  1339. }
  1340. public void llTriggerSound(string sound, double volume)
  1341. {
  1342. m_host.AddScriptLPS(1);
  1343. m_host.SendSound(sound, volume, true, 0);
  1344. }
  1345. public void llStopSound()
  1346. {
  1347. m_host.AddScriptLPS(1);
  1348. m_host.SendSound(LLUUID.Zero.ToString(), 1.0, false, 2);
  1349. }
  1350. public void llPreloadSound(string sound)
  1351. {
  1352. m_host.AddScriptLPS(1);
  1353. m_host.PreloadSound(sound);
  1354. }
  1355. /// <summary>
  1356. /// Return a portion of the designated string bounded by
  1357. /// inclusive indices (start and end). As usual, the negative
  1358. /// indices, and the tolerance for out-of-bound values, makes
  1359. /// this more complicated than it might otherwise seem.
  1360. /// </summary>
  1361. public string llGetSubString(string src, int start, int end)
  1362. {
  1363. m_host.AddScriptLPS(1);
  1364. // Normalize indices (if negative).
  1365. // After normlaization they may still be
  1366. // negative, but that is now relative to
  1367. // the start, rather than the end, of the
  1368. // sequence.
  1369. if (start < 0)
  1370. {
  1371. start = src.Length+start;
  1372. }
  1373. if (end < 0)
  1374. {
  1375. end = src.Length+end;
  1376. }
  1377. // Conventional substring
  1378. if (start <= end)
  1379. {
  1380. // Implies both bounds are out-of-range.
  1381. if(end < 0 || start >= src.Length)
  1382. {
  1383. return String.Empty;
  1384. }
  1385. // If end is positive, then it directly
  1386. // corresponds to the lengt of the substring
  1387. // needed (plus one of course). BUT, it
  1388. // must be within bounds.
  1389. if(end >= src.Length)
  1390. {
  1391. end = src.Length-1;
  1392. }
  1393. if(start < 0)
  1394. {
  1395. return src.Substring(0,end+1);
  1396. }
  1397. // Both indices are positive
  1398. return src.Substring(start, (end+1) - start);
  1399. }
  1400. // Inverted substring (end < start)
  1401. else
  1402. {
  1403. // Implies both indices are below the
  1404. // lower bound. In the inverted case, that
  1405. // means the entire string will be returned
  1406. // unchanged.
  1407. if(start < 0)
  1408. {
  1409. return src;
  1410. }
  1411. // If both indices are greater than the upper
  1412. // bound the result may seem initially counter
  1413. // intuitive.
  1414. if(end >= src.Length)
  1415. {
  1416. return src;
  1417. }
  1418. if(end < 0)
  1419. {
  1420. if(start < src.Length)
  1421. {
  1422. return src.Substring(start);
  1423. }
  1424. else
  1425. {
  1426. return String.Empty;
  1427. }
  1428. }
  1429. else
  1430. {
  1431. if(start < src.Length)
  1432. {
  1433. return src.Substring(0,end+1) + src.Substring(start);
  1434. }
  1435. else
  1436. {
  1437. return src.Substring(0,end+1);
  1438. }
  1439. }
  1440. }
  1441. }
  1442. /// <summary>
  1443. /// Delete substring removes the specified substring bounded
  1444. /// by the inclusive indices start and end. Indices may be
  1445. /// negative (indicating end-relative) and may be inverted,
  1446. /// i.e. end < start.
  1447. /// </summary>
  1448. public string llDeleteSubString(string src, int start, int end)
  1449. {
  1450. m_host.AddScriptLPS(1);
  1451. // Normalize indices (if negative).
  1452. // After normlaization they may still be
  1453. // negative, but that is now relative to
  1454. // the start, rather than the end, of the
  1455. // sequence.
  1456. if (start < 0)
  1457. {
  1458. start = src.Length+start;
  1459. }
  1460. if (end < 0)
  1461. {
  1462. end = src.Length+end;
  1463. }
  1464. // Conventionally delimited substring
  1465. if (start <= end)
  1466. {
  1467. // If both bounds are outside of the existing
  1468. // string, then return unchanges.
  1469. if(end < 0 || start >= src.Length)
  1470. {
  1471. return src;
  1472. }
  1473. // At least one bound is in-range, so we
  1474. // need to clip the out-of-bound argument.
  1475. if(start < 0)
  1476. {
  1477. start = 0;
  1478. }
  1479. if(end >= src.Length)
  1480. {
  1481. end = src.Length-1;
  1482. }
  1483. return src.Remove(start,end-start+1);
  1484. }
  1485. // Inverted substring
  1486. else
  1487. {
  1488. // In this case, out of bounds means that
  1489. // the existing string is part of the cut.
  1490. if(start < 0 || end >= src.Length)
  1491. {
  1492. return String.Empty;
  1493. }
  1494. if(end > 0)
  1495. {
  1496. if(start < src.Length)
  1497. {
  1498. return src.Remove(start).Remove(0,end+1);
  1499. }
  1500. else
  1501. {
  1502. return src.Remove(0,end+1);
  1503. }
  1504. }
  1505. else
  1506. {
  1507. if(start < src.Length)
  1508. {
  1509. return src.Remove(start);
  1510. }
  1511. else
  1512. {
  1513. return src;
  1514. }
  1515. }
  1516. }
  1517. }
  1518. /// <summary>
  1519. /// Insert string inserts the specified string identified by src
  1520. /// at the index indicated by index. Index may be negative, in
  1521. /// which case it is end-relative. The index may exceed either
  1522. /// string bound, with the result being a concatenation.
  1523. /// </summary>
  1524. public string llInsertString(string dest, int index, string src)
  1525. {
  1526. m_host.AddScriptLPS(1);
  1527. // Normalize indices (if negative).
  1528. // After normlaization they may still be
  1529. // negative, but that is now relative to
  1530. // the start, rather than the end, of the
  1531. // sequence.
  1532. if (index < 0)
  1533. {
  1534. index = dest.Length+index;
  1535. // Negative now means it is less than the lower
  1536. // bound of the string.
  1537. if(index < 0)
  1538. {
  1539. return src+dest;
  1540. }
  1541. }
  1542. if(index >= dest.Length)
  1543. {
  1544. return dest+src;
  1545. }
  1546. // The index is in bounds.
  1547. // In this case the index refers to the index that will
  1548. // be assigned to the first character of the inserted string.
  1549. // So unlike the other string operations, we do not add one
  1550. // to get the correct string length.
  1551. return dest.Substring(0,index)+src+dest.Substring(index);
  1552. }
  1553. public string llToUpper(string src)
  1554. {
  1555. m_host.AddScriptLPS(1);
  1556. return src.ToUpper();
  1557. }
  1558. public string llToLower(string src)
  1559. {
  1560. m_host.AddScriptLPS(1);
  1561. return src.ToLower();
  1562. }
  1563. public int llGiveMoney(string destination, int amount)
  1564. {
  1565. LLUUID invItemID=InventorySelf();
  1566. if(invItemID == LLUUID.Zero)
  1567. return 0;
  1568. m_host.AddScriptLPS(1);
  1569. if(m_host.TaskInventory[invItemID].PermsGranter == LLUUID.Zero)
  1570. return 0;
  1571. if((m_host.TaskInventory[invItemID].PermsMask & BuiltIn_Commands_BaseClass.PERMISSION_DEBIT) == 0)
  1572. {
  1573. LSLError("No permissions to give money");
  1574. return 0;
  1575. }
  1576. LLUUID toID=new LLUUID();
  1577. if(!LLUUID.TryParse(destination, out toID))
  1578. {
  1579. LSLError("Bad key in llGiveMoney");
  1580. return 0;
  1581. }
  1582. IMoneyModule money=World.RequestModuleInterface<IMoneyModule>();
  1583. if(money == null)
  1584. {
  1585. NotImplemented("llGiveMoney");
  1586. return 0;
  1587. }
  1588. bool result=money.ObjectGiveMoney(m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
  1589. if(result)
  1590. return 1;
  1591. return 0;
  1592. }
  1593. public void llMakeExplosion()
  1594. {
  1595. m_host.AddScriptLPS(1);
  1596. NotImplemented("llMakeExplosion");
  1597. }
  1598. public void llMakeFountain()
  1599. {
  1600. m_host.AddScriptLPS(1);
  1601. NotImplemented("llMakeFountain");
  1602. }
  1603. public void llMakeSmoke()
  1604. {
  1605. m_host.AddScriptLPS(1);
  1606. NotImplemented("llMakeSmoke");
  1607. }
  1608. public void llMakeFire()
  1609. {
  1610. m_host.AddScriptLPS(1);
  1611. NotImplemented("llMakeFire");
  1612. }
  1613. public void llRezObject(string inventory, LSL_Types.Vector3 pos, LSL_Types.Quaternion rot, int param)
  1614. {
  1615. m_host.AddScriptLPS(1);
  1616. NotImplemented("llRezObject");
  1617. }
  1618. public void llLookAt(LSL_Types.Vector3 target, double strength, double damping)
  1619. {
  1620. m_host.AddScriptLPS(1);
  1621. NotImplemented("llLookAt");
  1622. }
  1623. public void llStopLookAt()
  1624. {
  1625. m_host.AddScriptLPS(1);
  1626. NotImplemented("llStopLookAt");
  1627. }
  1628. public void llSetTimerEvent(double sec)
  1629. {
  1630. m_host.AddScriptLPS(1);
  1631. // Setting timer repeat
  1632. m_ScriptEngine.m_ASYNCLSLCommandManager.m_Timer.SetTimerEvent(m_localID, m_itemID, sec);
  1633. }
  1634. public void llSleep(double sec)
  1635. {
  1636. m_host.AddScriptLPS(1);
  1637. Thread.Sleep((int)(sec * 1000));
  1638. }
  1639. public double llGetMass()
  1640. {
  1641. m_host.AddScriptLPS(1);
  1642. return m_host.GetMass();
  1643. }
  1644. public void llCollisionFilter(string name, string id, int accept)
  1645. {
  1646. m_host.AddScriptLPS(1);
  1647. NotImplemented("llCollisionFilter");
  1648. }
  1649. public void llTakeControls(int controls, int accept, int pass_on)
  1650. {
  1651. m_host.AddScriptLPS(1);
  1652. NotImplemented("llTakeControls");
  1653. }
  1654. public void llReleaseControls()
  1655. {
  1656. m_host.AddScriptLPS(1);
  1657. NotImplemented("llReleaseControls");
  1658. }
  1659. public void llAttachToAvatar(int attachment)
  1660. {
  1661. m_host.AddScriptLPS(1);
  1662. NotImplemented("llAttachToAvatar");
  1663. }
  1664. public void llDetachFromAvatar()
  1665. {
  1666. m_host.AddScriptLPS(1);
  1667. NotImplemented("llDetachFromAvatar");
  1668. }
  1669. public void llTakeCamera()
  1670. {
  1671. m_host.AddScriptLPS(1);
  1672. NotImplemented("llTakeCamera");
  1673. }
  1674. public void llReleaseCamera()
  1675. {
  1676. m_host.AddScriptLPS(1);
  1677. NotImplemented("llReleaseCamera");
  1678. }
  1679. public string llGetOwner()
  1680. {
  1681. m_host.AddScriptLPS(1);
  1682. return m_host.ObjectOwner.ToString();
  1683. }
  1684. public void llInstantMessage(string user, string message)
  1685. {
  1686. m_host.AddScriptLPS(1);
  1687. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  1688. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  1689. // but I don't think we have a list of scenes available from here.
  1690. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  1691. // user is a UUID
  1692. // TODO: figure out values for client, fromSession, and imSessionID
  1693. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  1694. LLUUID friendTransactionID = LLUUID.Random();
  1695. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  1696. GridInstantMessage msg = new GridInstantMessage();
  1697. msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.UUID;
  1698. msg.fromAgentSession = new Guid(friendTransactionID.ToString());// fromAgentSession.UUID;
  1699. msg.toAgentID = new Guid(user); // toAgentID.UUID;
  1700. msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
  1701. Console.WriteLine("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
  1702. Console.WriteLine("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
  1703. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp;
  1704. //if (client != null)
  1705. //{
  1706. msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
  1707. //}
  1708. //else
  1709. //{
  1710. // msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it
  1711. //}
  1712. msg.message = message;
  1713. msg.dialog = (byte)19; // messgage from script ??? // dialog;
  1714. msg.fromGroup = false;// fromGroup;
  1715. msg.offline = (byte)0; //offline;
  1716. msg.ParentEstateID = 0; //ParentEstateID;
  1717. msg.Position = new sLLVector3();// new sLLVector3(m_host.AbsolutePosition);
  1718. msg.RegionID = World.RegionInfo.RegionID.UUID;//RegionID.UUID;
  1719. msg.binaryBucket = new byte[0];// binaryBucket;
  1720. World.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
  1721. // NotImplemented("llInstantMessage");
  1722. }
  1723. public void llEmail(string address, string subject, string message)
  1724. {
  1725. m_host.AddScriptLPS(1);
  1726. NotImplemented("llEmail");
  1727. }
  1728. public void llGetNextEmail(string address, string subject)
  1729. {
  1730. m_host.AddScriptLPS(1);
  1731. NotImplemented("llGetNextEmail");
  1732. }
  1733. public string llGetKey()
  1734. {
  1735. m_host.AddScriptLPS(1);
  1736. return m_host.UUID.ToString();
  1737. }
  1738. public void llSetBuoyancy(double buoyancy)
  1739. {
  1740. m_host.AddScriptLPS(1);
  1741. if (m_host.ParentGroup != null)
  1742. {
  1743. if (m_host.ParentGroup.RootPart != null)
  1744. {
  1745. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  1746. }
  1747. }
  1748. }
  1749. public void llSetHoverHeight(double height, int water, double tau)
  1750. {
  1751. m_host.AddScriptLPS(1);
  1752. NotImplemented("llSetHoverHeight");
  1753. }
  1754. public void llStopHover()
  1755. {
  1756. m_host.AddScriptLPS(1);
  1757. NotImplemented("llStopHover");
  1758. }
  1759. public void llMinEventDelay(double delay)
  1760. {
  1761. m_host.AddScriptLPS(1);
  1762. NotImplemented("llMinEventDelay");
  1763. }
  1764. public void llSoundPreload()
  1765. {
  1766. m_host.AddScriptLPS(1);
  1767. NotImplemented("llSoundPreload");
  1768. }
  1769. public void llRotLookAt(LSL_Types.Quaternion target, double strength, double damping)
  1770. {
  1771. m_host.AddScriptLPS(1);
  1772. NotImplemented("llRotLookAt");
  1773. }
  1774. public int llStringLength(string str)
  1775. {
  1776. m_host.AddScriptLPS(1);
  1777. if (str.Length > 0)
  1778. {
  1779. return str.Length;
  1780. }
  1781. else
  1782. {
  1783. return 0;
  1784. }
  1785. }
  1786. public void llStartAnimation(string anim)
  1787. {
  1788. m_host.AddScriptLPS(1);
  1789. LLUUID invItemID=InventorySelf();
  1790. if(invItemID == LLUUID.Zero)
  1791. return;
  1792. if(m_host.TaskInventory[invItemID].PermsGranter == LLUUID.Zero)
  1793. return;
  1794. if((m_host.TaskInventory[invItemID].PermsMask & BuiltIn_Commands_BaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  1795. {
  1796. // Do NOT try to parse LLUUID, animations cannot be triggered by ID
  1797. LLUUID animID=InventoryKey(anim, (int)AssetType.Animation);
  1798. if(animID == LLUUID.Zero)
  1799. return;
  1800. if (World.m_innerScene.ScenePresences.ContainsKey(m_host.TaskInventory[invItemID].PermsGranter))
  1801. {
  1802. ScenePresence presence = World.m_innerScene.ScenePresences[m_host.TaskInventory[invItemID].PermsGranter];
  1803. presence.AddAnimation(animID);
  1804. }
  1805. }
  1806. }
  1807. public void llStopAnimation(string anim)
  1808. {
  1809. m_host.AddScriptLPS(1);
  1810. LLUUID invItemID=InventorySelf();
  1811. if(invItemID == LLUUID.Zero)
  1812. return;
  1813. if(m_host.TaskInventory[invItemID].PermsGranter == LLUUID.Zero)
  1814. return;
  1815. if((m_host.TaskInventory[invItemID].PermsMask & BuiltIn_Commands_BaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  1816. {
  1817. LLUUID animID = new LLUUID();
  1818. if(!LLUUID.TryParse(anim, out animID))
  1819. {
  1820. animID=InventoryKey(anim);
  1821. }
  1822. if(animID == LLUUID.Zero)
  1823. return;
  1824. if (World.m_innerScene.ScenePresences.ContainsKey(m_host.TaskInventory[invItemID].PermsGranter))
  1825. {
  1826. ScenePresence presence = World.m_innerScene.ScenePresences[m_host.TaskInventory[invItemID].PermsGranter];
  1827. presence.RemoveAnimation(animID);
  1828. }
  1829. }
  1830. }
  1831. public void llPointAt()
  1832. {
  1833. m_host.AddScriptLPS(1);
  1834. NotImplemented("llPointAt");
  1835. }
  1836. public void llStopPointAt()
  1837. {
  1838. m_host.AddScriptLPS(1);
  1839. NotImplemented("llStopPointAt");
  1840. }
  1841. public void llTargetOmega(LSL_Types.Vector3 axis, double spinrate, double gain)
  1842. {
  1843. m_host.AddScriptLPS(1);
  1844. m_host.RotationalVelocity = new LLVector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate));
  1845. m_host.AngularVelocity = new LLVector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate));
  1846. m_host.ScheduleTerseUpdate();
  1847. m_host.SendTerseUpdateToAllClients();
  1848. }
  1849. public int llGetStartParameter()
  1850. {
  1851. m_host.AddScriptLPS(1);
  1852. NotImplemented("llGetStartParameter");
  1853. return 0;
  1854. }
  1855. public void llGodLikeRezObject(string inventory, LSL_Types.Vector3 pos)
  1856. {
  1857. m_host.AddScriptLPS(1);
  1858. NotImplemented("llGodLikeRezObject");
  1859. }
  1860. public void llRequestPermissions(string agent, int perm)
  1861. {
  1862. LLUUID agentID=new LLUUID();
  1863. if(!LLUUID.TryParse(agent, out agentID))
  1864. return;
  1865. LLUUID invItemID=InventorySelf();
  1866. if(invItemID == LLUUID.Zero)
  1867. return; // Not in a prim? How??
  1868. if(agentID == LLUUID.Zero || perm == 0) // Releasing permissions
  1869. {
  1870. m_host.TaskInventory[invItemID].PermsGranter=LLUUID.Zero;
  1871. m_host.TaskInventory[invItemID].PermsMask=0;
  1872. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
  1873. m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(0)});
  1874. return;
  1875. }
  1876. m_host.AddScriptLPS(1);
  1877. bool attachment=false; // Attachments not implemented yet. TODO: reflect real attachemnt state
  1878. if(m_host.ParentGroup.RootPart.m_IsAttachment && agent == m_host.ParentGroup.RootPart.m_attachedAvatar)
  1879. {
  1880. // When attached, certain permissions are implicit if requested from owner
  1881. int implicitPerms = BuiltIn_Commands_BaseClass.PERMISSION_TAKE_CONTROLS |
  1882. BuiltIn_Commands_BaseClass.PERMISSION_TRIGGER_ANIMATION |
  1883. BuiltIn_Commands_BaseClass.PERMISSION_ATTACH;
  1884. if((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  1885. {
  1886. m_host.TaskInventory[invItemID].PermsGranter=agentID;
  1887. m_host.TaskInventory[invItemID].PermsMask=perm;
  1888. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
  1889. m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(perm)});
  1890. return;
  1891. }
  1892. }
  1893. else if(m_host.m_sitTargetAvatar == agentID) // Sitting avatar
  1894. {
  1895. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  1896. int implicitPerms = BuiltIn_Commands_BaseClass.PERMISSION_TRIGGER_ANIMATION |
  1897. BuiltIn_Commands_BaseClass.PERMISSION_TRACK_CAMERA;
  1898. if((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  1899. {
  1900. m_host.TaskInventory[invItemID].PermsGranter=agentID;
  1901. m_host.TaskInventory[invItemID].PermsMask=perm;
  1902. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
  1903. m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(perm)});
  1904. return;
  1905. }
  1906. }
  1907. if (World.m_innerScene.ScenePresences.ContainsKey(agentID))
  1908. {
  1909. string ownerName=resolveName(m_host.ParentGroup.RootPart.OwnerID);
  1910. if(ownerName == String.Empty)
  1911. ownerName="(hippos)";
  1912. ScenePresence presence = World.m_innerScene.ScenePresences[agentID];
  1913. if(!m_waitingForScriptAnswer)
  1914. {
  1915. m_host.TaskInventory[invItemID].PermsGranter=agentID;
  1916. m_host.TaskInventory[invItemID].PermsMask=0;
  1917. presence.ControllingClient.OnScriptAnswer+=handleScriptAnswer;
  1918. m_waitingForScriptAnswer=true;
  1919. }
  1920. presence.ControllingClient.SendScriptQuestion(m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm);
  1921. return;
  1922. }
  1923. // Requested agent is not in range, refuse perms
  1924. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
  1925. m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(0)});
  1926. }
  1927. void handleScriptAnswer(IClientAPI client, LLUUID taskID, LLUUID itemID, int answer)
  1928. {
  1929. if(taskID != m_host.UUID)
  1930. return;
  1931. LLUUID invItemID=InventorySelf();
  1932. if(invItemID == LLUUID.Zero)
  1933. return;
  1934. client.OnScriptAnswer-=handleScriptAnswer;
  1935. m_waitingForScriptAnswer=false;
  1936. m_host.TaskInventory[invItemID].PermsMask=answer;
  1937. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
  1938. m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(answer)});
  1939. }
  1940. public string llGetPermissionsKey()
  1941. {
  1942. m_host.AddScriptLPS(1);
  1943. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1944. {
  1945. if(item.Type == 10 && item.ItemID == m_itemID)
  1946. {
  1947. return item.PermsGranter.ToString();
  1948. }
  1949. }
  1950. return LLUUID.Zero.ToString();
  1951. }
  1952. public int llGetPermissions()
  1953. {
  1954. m_host.AddScriptLPS(1);
  1955. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1956. {
  1957. if(item.Type == 10 && item.ItemID == m_itemID)
  1958. {
  1959. return item.PermsMask;
  1960. }
  1961. }
  1962. return 0;
  1963. }
  1964. public int llGetLinkNumber()
  1965. {
  1966. m_host.AddScriptLPS(1);
  1967. if (m_host.ParentGroup.Children.Count > 0)
  1968. {
  1969. return m_host.LinkNum + 1;
  1970. }
  1971. else
  1972. {
  1973. return 0;
  1974. }
  1975. }
  1976. public void llSetLinkColor(int linknumber, LSL_Types.Vector3 color, int face)
  1977. {
  1978. m_host.AddScriptLPS(1);
  1979. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  1980. if (linknumber > -1)
  1981. {
  1982. LLObject.TextureEntry tex = part.Shape.Textures;
  1983. LLColor texcolor;
  1984. if (face > -1)
  1985. {
  1986. texcolor = tex.CreateFace((uint)face).RGBA;
  1987. texcolor.R = (float)Math.Abs(color.x - 1);
  1988. texcolor.G = (float)Math.Abs(color.y - 1);
  1989. texcolor.B = (float)Math.Abs(color.z - 1);
  1990. tex.FaceTextures[face].RGBA = texcolor;
  1991. part.UpdateTexture(tex);
  1992. return;
  1993. }
  1994. else if (face == -1)
  1995. {
  1996. texcolor = tex.DefaultTexture.RGBA;
  1997. texcolor.R = (float)Math.Abs(color.x - 1);
  1998. texcolor.G = (float)Math.Abs(color.y - 1);
  1999. texcolor.B = (float)Math.Abs(color.z - 1);
  2000. tex.DefaultTexture.RGBA = texcolor;
  2001. for (uint i = 0; i < 32; i++)
  2002. {
  2003. if (tex.FaceTextures[i] != null)
  2004. {
  2005. texcolor = tex.FaceTextures[i].RGBA;
  2006. texcolor.R = (float)Math.Abs(color.x - 1);
  2007. texcolor.G = (float)Math.Abs(color.y - 1);
  2008. texcolor.B = (float)Math.Abs(color.z - 1);
  2009. tex.FaceTextures[i].RGBA = texcolor;
  2010. }
  2011. }
  2012. texcolor = tex.DefaultTexture.RGBA;
  2013. texcolor.R = (float)Math.Abs(color.x - 1);
  2014. texcolor.G = (float)Math.Abs(color.y - 1);
  2015. texcolor.B = (float)Math.Abs(color.z - 1);
  2016. tex.DefaultTexture.RGBA = texcolor;
  2017. part.UpdateTexture(tex);
  2018. return;
  2019. }
  2020. return;
  2021. }
  2022. else if (linknumber == -1)
  2023. {
  2024. int num = m_host.ParentGroup.PrimCount;
  2025. for (int w = 0; w < num; w++)
  2026. {
  2027. linknumber = w;
  2028. part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  2029. LLObject.TextureEntry tex = part.Shape.Textures;
  2030. LLColor texcolor;
  2031. if (face > -1)
  2032. {
  2033. texcolor = tex.CreateFace((uint)face).RGBA;
  2034. texcolor.R = (float)Math.Abs(color.x - 1);
  2035. texcolor.G = (float)Math.Abs(color.y - 1);
  2036. texcolor.B = (float)Math.Abs(color.z - 1);
  2037. tex.FaceTextures[face].RGBA = texcolor;
  2038. part.UpdateTexture(tex);
  2039. }
  2040. else if (face == -1)
  2041. {
  2042. texcolor = tex.DefaultTexture.RGBA;
  2043. texcolor.R = (float)Math.Abs(color.x - 1);
  2044. texcolor.G = (float)Math.Abs(color.y - 1);
  2045. texcolor.B = (float)Math.Abs(color.z - 1);
  2046. tex.DefaultTexture.RGBA = texcolor;
  2047. for (uint i = 0; i < 32; i++)
  2048. {
  2049. if (tex.FaceTextures[i] != null)
  2050. {
  2051. texcolor = tex.FaceTextures[i].RGBA;
  2052. texcolor.R = (float)Math.Abs(color.x - 1);
  2053. texcolor.G = (float)Math.Abs(color.y - 1);
  2054. texcolor.B = (float)Math.Abs(color.z - 1);
  2055. tex.FaceTextures[i].RGBA = texcolor;
  2056. }
  2057. }
  2058. texcolor = tex.DefaultTexture.RGBA;
  2059. texcolor.R = (float)Math.Abs(color.x - 1);
  2060. texcolor.G = (float)Math.Abs(color.y - 1);
  2061. texcolor.B = (float)Math.Abs(color.z - 1);
  2062. tex.DefaultTexture.RGBA = texcolor;
  2063. part.UpdateTexture(tex);
  2064. }
  2065. }
  2066. return;
  2067. }
  2068. else
  2069. {
  2070. NotImplemented("llSetLinkColor");
  2071. }
  2072. }
  2073. public void llCreateLink(string target, int parent)
  2074. {
  2075. m_host.AddScriptLPS(1);
  2076. NotImplemented("llCreateLink");
  2077. }
  2078. public void llBreakLink(int linknum)
  2079. {
  2080. m_host.AddScriptLPS(1);
  2081. NotImplemented("llBreakLink");
  2082. }
  2083. public void llBreakAllLinks()
  2084. {
  2085. m_host.AddScriptLPS(1);
  2086. NotImplemented("llBreakAllLinks");
  2087. }
  2088. public string llGetLinkKey(int linknum)
  2089. {
  2090. m_host.AddScriptLPS(1);
  2091. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  2092. if (part != null)
  2093. {
  2094. return part.UUID.ToString();
  2095. }
  2096. else
  2097. {
  2098. return "00000000-0000-0000-0000-000000000000";
  2099. }
  2100. }
  2101. public string llGetLinkName(int linknum)
  2102. {
  2103. m_host.AddScriptLPS(1);
  2104. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  2105. if (part != null)
  2106. {
  2107. return part.Name;
  2108. }
  2109. else
  2110. {
  2111. return "00000000-0000-0000-0000-000000000000";
  2112. }
  2113. }
  2114. public int llGetInventoryNumber(int type)
  2115. {
  2116. m_host.AddScriptLPS(1);
  2117. int count = 0;
  2118. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2119. {
  2120. if (inv.Value.Type == type || type == -1)
  2121. {
  2122. count = count + 1;
  2123. }
  2124. }
  2125. return count;
  2126. }
  2127. public string llGetInventoryName(int type, int number)
  2128. {
  2129. m_host.AddScriptLPS(1);
  2130. ArrayList keys = new ArrayList();
  2131. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2132. {
  2133. if (inv.Value.Type == type || type == -1)
  2134. {
  2135. keys.Add(inv.Value.Name);
  2136. }
  2137. }
  2138. if (keys.Count == 0)
  2139. {
  2140. return String.Empty;
  2141. }
  2142. keys.Sort();
  2143. if (keys.Count > number)
  2144. {
  2145. return (string)keys[number];
  2146. }
  2147. return String.Empty;
  2148. }
  2149. public void llSetScriptState(string name, int run)
  2150. {
  2151. LLUUID item;
  2152. ScriptManager sm;
  2153. IScript script = null;
  2154. m_host.AddScriptLPS(1);
  2155. // These functions are supposed to be robust,
  2156. // so get the state one step at a time.
  2157. if((item = ScriptByName(name)) != LLUUID.Zero)
  2158. if((sm = m_ScriptEngine.m_ScriptManager) != null)
  2159. if(sm.Scripts.ContainsKey(m_localID))
  2160. if((script = sm.GetScript(m_localID, item)) != null)
  2161. script.Exec.Running = (run==0) ? false : true;
  2162. // Required by SL
  2163. if(script == null)
  2164. ShoutError("llSetScriptState: script "+name+" not found");
  2165. // If we didn;t find it, then it's safe to
  2166. // assume it is not running.
  2167. return;
  2168. }
  2169. public double llGetEnergy()
  2170. {
  2171. m_host.AddScriptLPS(1);
  2172. return 1.0f;
  2173. }
  2174. public void llGiveInventory(string destination, string inventory)
  2175. {
  2176. m_host.AddScriptLPS(1);
  2177. NotImplemented("llGiveInventory");
  2178. }
  2179. public void llRemoveInventory(string item)
  2180. {
  2181. m_host.AddScriptLPS(1);
  2182. NotImplemented("llRemoveInventory");
  2183. }
  2184. public void llSetText(string text, LSL_Types.Vector3 color, double alpha)
  2185. {
  2186. m_host.AddScriptLPS(1);
  2187. Vector3 av3 = new Vector3((float)color.x, (float)color.y, (float)color.z);
  2188. m_host.SetText(text, av3, alpha);
  2189. }
  2190. public double llWater(LSL_Types.Vector3 offset)
  2191. {
  2192. m_host.AddScriptLPS(1);
  2193. return World.RegionInfo.EstateSettings.waterHeight;
  2194. }
  2195. public void llPassTouches(int pass)
  2196. {
  2197. m_host.AddScriptLPS(1);
  2198. NotImplemented("llPassTouches");
  2199. }
  2200. public string llRequestAgentData(string id, int data)
  2201. {
  2202. m_host.AddScriptLPS(1);
  2203. NotImplemented("llRequestAgentData");
  2204. return String.Empty;
  2205. }
  2206. public string llRequestInventoryData(string name)
  2207. {
  2208. m_host.AddScriptLPS(1);
  2209. NotImplemented("llRequestInventoryData");
  2210. return String.Empty;
  2211. }
  2212. public void llSetDamage(double damage)
  2213. {
  2214. m_host.AddScriptLPS(1);
  2215. NotImplemented("llSetDamage");
  2216. }
  2217. public void llTeleportAgentHome(string agent)
  2218. {
  2219. m_host.AddScriptLPS(1);
  2220. NotImplemented("llTeleportAgentHome");
  2221. }
  2222. public void llModifyLand(int action, int brush)
  2223. {
  2224. m_host.AddScriptLPS(1);
  2225. if (World.PermissionsMngr.CanTerraform(m_host.OwnerID, new LLVector3(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, 0)))
  2226. {
  2227. NotImplemented("llModifyLand");
  2228. }
  2229. }
  2230. public void llCollisionSound(string impact_sound, double impact_volume)
  2231. {
  2232. m_host.AddScriptLPS(1);
  2233. NotImplemented("llCollisionSound");
  2234. }
  2235. public void llCollisionSprite(string impact_sprite)
  2236. {
  2237. m_host.AddScriptLPS(1);
  2238. NotImplemented("llCollisionSprite");
  2239. }
  2240. public string llGetAnimation(string id)
  2241. {
  2242. m_host.AddScriptLPS(1);
  2243. NotImplemented("llGetAnimation");
  2244. return String.Empty;
  2245. }
  2246. public void llResetScript()
  2247. {
  2248. m_host.AddScriptLPS(1);
  2249. m_ScriptEngine.m_ScriptManager.ResetScript(m_localID, m_itemID);
  2250. }
  2251. public void llMessageLinked(int linknum, int num, string msg, string id)
  2252. {
  2253. m_host.AddScriptLPS(1);
  2254. uint partLocalID;
  2255. LLUUID partItemID;
  2256. switch ((int)linknum)
  2257. {
  2258. case (int)BuiltIn_Commands_BaseClass.LINK_ROOT:
  2259. SceneObjectPart part = m_host.ParentGroup.RootPart;
  2260. foreach (TaskInventoryItem item in part.TaskInventory.Values)
  2261. {
  2262. if (item.Type == 10)
  2263. {
  2264. partLocalID = part.LocalId;
  2265. partItemID = item.ItemID;
  2266. object[] resobj = new object[]
  2267. {
  2268. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2269. };
  2270. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
  2271. partLocalID, partItemID, "link_message", EventQueueManager.llDetectNull, resobj
  2272. );
  2273. }
  2274. }
  2275. break;
  2276. case (int)BuiltIn_Commands_BaseClass.LINK_SET:
  2277. Console.WriteLine("LINK_SET");
  2278. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2279. {
  2280. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2281. {
  2282. if (item.Type == 10)
  2283. {
  2284. partLocalID = partInst.LocalId;
  2285. partItemID = item.ItemID;
  2286. Object[] resobj = new object[]
  2287. {
  2288. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2289. };
  2290. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
  2291. partLocalID, partItemID, "link_message", EventQueueManager.llDetectNull, resobj
  2292. );
  2293. }
  2294. }
  2295. }
  2296. break;
  2297. case (int)BuiltIn_Commands_BaseClass.LINK_ALL_OTHERS:
  2298. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2299. {
  2300. if (partInst.LocalId != m_host.LocalId)
  2301. {
  2302. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2303. {
  2304. if (item.Type == 10)
  2305. {
  2306. partLocalID = partInst.LocalId;
  2307. partItemID = item.ItemID;
  2308. Object[] resobj = new object[]
  2309. {
  2310. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2311. };
  2312. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
  2313. partLocalID, partItemID, "link_message", EventQueueManager.llDetectNull, resobj
  2314. );
  2315. }
  2316. }
  2317. }
  2318. }
  2319. break;
  2320. case (int)BuiltIn_Commands_BaseClass.LINK_ALL_CHILDREN:
  2321. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2322. {
  2323. if (partInst.LocalId != m_host.ParentGroup.RootPart.LocalId)
  2324. {
  2325. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2326. {
  2327. if (item.Type == 10)
  2328. {
  2329. partLocalID = partInst.LocalId;
  2330. partItemID = item.ItemID;
  2331. Object[] resobj = new object[]
  2332. {
  2333. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2334. };
  2335. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
  2336. partLocalID, partItemID, "link_message", EventQueueManager.llDetectNull, resobj
  2337. );
  2338. }
  2339. }
  2340. }
  2341. }
  2342. break;
  2343. case (int)BuiltIn_Commands_BaseClass.LINK_THIS:
  2344. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2345. {
  2346. if (item.Type == 10)
  2347. {
  2348. partItemID = item.ItemID;
  2349. object[] resobj = new object[]
  2350. {
  2351. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2352. };
  2353. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
  2354. m_localID, partItemID, "link_message", EventQueueManager.llDetectNull, resobj
  2355. );
  2356. }
  2357. }
  2358. break;
  2359. default:
  2360. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2361. {
  2362. if ((partInst.LinkNum + 1) == linknum)
  2363. {
  2364. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2365. {
  2366. if (item.Type == 10)
  2367. {
  2368. partLocalID = partInst.LocalId;
  2369. partItemID = item.ItemID;
  2370. Object[] resObjDef = new object[]
  2371. {
  2372. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2373. };
  2374. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
  2375. partLocalID, partItemID, "link_message", EventQueueManager.llDetectNull, resObjDef
  2376. );
  2377. }
  2378. }
  2379. }
  2380. }
  2381. break;
  2382. }
  2383. }
  2384. public void llPushObject(string target, LSL_Types.Vector3 impulse, LSL_Types.Vector3 ang_impulse, int local)
  2385. {
  2386. m_host.AddScriptLPS(1);
  2387. NotImplemented("llPushObject");
  2388. }
  2389. public void llPassCollisions(int pass)
  2390. {
  2391. m_host.AddScriptLPS(1);
  2392. NotImplemented("llPassCollisions");
  2393. }
  2394. public string llGetScriptName()
  2395. {
  2396. string result = String.Empty;
  2397. m_host.AddScriptLPS(1);
  2398. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2399. {
  2400. if(item.Type == 10 && item.ItemID == m_itemID)
  2401. {
  2402. result = item.Name!=null?item.Name:String.Empty;
  2403. break;
  2404. }
  2405. }
  2406. return result;
  2407. }
  2408. public int llGetNumberOfSides()
  2409. {
  2410. m_host.AddScriptLPS(1);
  2411. NotImplemented("llGetNumberOfSides");
  2412. return 0;
  2413. }
  2414. /* The new / changed functions were tested with the following LSL script:
  2415. default
  2416. {
  2417. state_entry()
  2418. {
  2419. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  2420. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot) );
  2421. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  2422. // convert back and forth between quaternion <-> vector and angle
  2423. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  2424. llOwnerSay("Old rotation was: "+(string) rot);
  2425. llOwnerSay("re-converted rotation is: "+(string) newrot);
  2426. llSetRot(rot); // to check the parameters in the prim
  2427. }
  2428. }
  2429. */
  2430. // Xantor 29/apr/2008
  2431. // Returns rotation described by rotating angle radians about axis.
  2432. // q = cos(a/2) + i ( x * sin(a/2)) + j (y * sin(a/2)) + k ( z * sin(a/2))
  2433. public LSL_Types.Quaternion llAxisAngle2Rot(LSL_Types.Vector3 axis, double angle)
  2434. {
  2435. m_host.AddScriptLPS(1);
  2436. double x, y, z, s, t;
  2437. s = Math.Cos(angle / 2);
  2438. t = Math.Sin(angle / 2); // temp value to avoid 2 more sin() calcs
  2439. x = axis.x * t;
  2440. y = axis.y * t;
  2441. z = axis.z * t;
  2442. return new LSL_Types.Quaternion(x,y,z,s);
  2443. // NotImplemented("llAxisAngle2Rot");
  2444. }
  2445. // Xantor 29/apr/2008
  2446. // converts a Quaternion to X,Y,Z axis rotations
  2447. public LSL_Types.Vector3 llRot2Axis(LSL_Types.Quaternion rot)
  2448. {
  2449. m_host.AddScriptLPS(1);
  2450. double x,y,z;
  2451. if (rot.s > 1) // normalization needed
  2452. {
  2453. double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y +
  2454. rot.z * rot.z + rot.s * rot.s);
  2455. rot.x /= length;
  2456. rot.y /= length;
  2457. rot.z /= length;
  2458. rot.s /= length;
  2459. }
  2460. double angle = 2 * Math.Acos(rot.s);
  2461. double s = Math.Sqrt(1 - rot.s * rot.s);
  2462. if (s < 0.001)
  2463. {
  2464. x = 1;
  2465. y = z = 0;
  2466. }
  2467. else
  2468. {
  2469. x = rot.x / s; // normalise axis
  2470. y = rot.y / s;
  2471. z = rot.z / s;
  2472. }
  2473. return new LSL_Types.Vector3(x,y,z);
  2474. // NotImplemented("llRot2Axis");
  2475. }
  2476. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  2477. public double llRot2Angle(LSL_Types.Quaternion rot)
  2478. {
  2479. m_host.AddScriptLPS(1);
  2480. if (rot.s > 1) // normalization needed
  2481. {
  2482. double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y +
  2483. rot.z * rot.z + rot.s * rot.s);
  2484. rot.x /= length;
  2485. rot.y /= length;
  2486. rot.z /= length;
  2487. rot.s /= length;
  2488. }
  2489. double angle = 2 * Math.Acos(rot.s);
  2490. return angle;
  2491. // NotImplemented("llRot2Angle");
  2492. }
  2493. public double llAcos(double val)
  2494. {
  2495. m_host.AddScriptLPS(1);
  2496. return (double)Math.Acos(val);
  2497. }
  2498. public double llAsin(double val)
  2499. {
  2500. m_host.AddScriptLPS(1);
  2501. return (double)Math.Asin(val);
  2502. }
  2503. // Xantor 30/apr/2008
  2504. public double llAngleBetween(LSL_Types.Quaternion a, LSL_Types.Quaternion b)
  2505. {
  2506. m_host.AddScriptLPS(1);
  2507. return (double) Math.Acos(a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s) * 2;
  2508. // NotImplemented("llAngleBetween");
  2509. }
  2510. public string llGetInventoryKey(string name)
  2511. {
  2512. m_host.AddScriptLPS(1);
  2513. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2514. {
  2515. if(inv.Value.Name == name)
  2516. {
  2517. if((inv.Value.OwnerMask & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  2518. {
  2519. return inv.Value.AssetID.ToString();
  2520. }
  2521. else
  2522. {
  2523. return LLUUID.Zero.ToString();
  2524. }
  2525. }
  2526. }
  2527. return LLUUID.Zero.ToString();
  2528. }
  2529. public void llAllowInventoryDrop(int add)
  2530. {
  2531. m_host.AddScriptLPS(1);
  2532. NotImplemented("llAllowInventoryDrop");
  2533. }
  2534. public LSL_Types.Vector3 llGetSunDirection()
  2535. {
  2536. m_host.AddScriptLPS(1);
  2537. LSL_Types.Vector3 SunDoubleVector3;
  2538. LLVector3 SunFloatVector3;
  2539. // sunPosition estate setting is set in OpenSim.Region.Environment.Modules.SunModule
  2540. // have to convert from LLVector3 (float) to LSL_Types.Vector3 (double)
  2541. SunFloatVector3 = World.RegionInfo.EstateSettings.sunPosition;
  2542. SunDoubleVector3.x = (double)SunFloatVector3.X;
  2543. SunDoubleVector3.y = (double)SunFloatVector3.Y;
  2544. SunDoubleVector3.z = (double)SunFloatVector3.Z;
  2545. return SunDoubleVector3;
  2546. }
  2547. public LSL_Types.Vector3 llGetTextureOffset(int face)
  2548. {
  2549. m_host.AddScriptLPS(1);
  2550. LLObject.TextureEntry tex = m_host.Shape.Textures;
  2551. LSL_Types.Vector3 offset;
  2552. if (face == -1)
  2553. {
  2554. face = 0;
  2555. }
  2556. offset.x = tex.GetFace((uint)face).OffsetU;
  2557. offset.y = tex.GetFace((uint)face).OffsetV;
  2558. offset.z = 0.0;
  2559. return offset;
  2560. }
  2561. public LSL_Types.Vector3 llGetTextureScale(int side)
  2562. {
  2563. m_host.AddScriptLPS(1);
  2564. LLObject.TextureEntry tex = m_host.Shape.Textures;
  2565. LSL_Types.Vector3 scale;
  2566. if (side == -1)
  2567. {
  2568. side = 0;
  2569. }
  2570. scale.x = tex.GetFace((uint)side).RepeatU;
  2571. scale.y = tex.GetFace((uint)side).RepeatV;
  2572. scale.z = 0.0;
  2573. return scale;
  2574. }
  2575. public double llGetTextureRot(int face)
  2576. {
  2577. m_host.AddScriptLPS(1);
  2578. LLObject.TextureEntry tex = m_host.Shape.Textures;
  2579. if (face == -1)
  2580. {
  2581. face = 0;
  2582. }
  2583. return tex.GetFace((uint)face).Rotation;
  2584. }
  2585. public int llSubStringIndex(string source, string pattern)
  2586. {
  2587. m_host.AddScriptLPS(1);
  2588. return source.IndexOf(pattern);
  2589. }
  2590. public string llGetOwnerKey(string id)
  2591. {
  2592. m_host.AddScriptLPS(1);
  2593. LLUUID key = new LLUUID();
  2594. if (LLUUID.TryParse(id, out key))
  2595. {
  2596. return World.GetSceneObjectPart(World.Entities[key].LocalId).OwnerID.ToString();
  2597. }
  2598. else
  2599. {
  2600. return LLUUID.Zero.ToString();
  2601. }
  2602. }
  2603. public LSL_Types.Vector3 llGetCenterOfMass()
  2604. {
  2605. m_host.AddScriptLPS(1);
  2606. NotImplemented("llGetCenterOfMass");
  2607. return new LSL_Types.Vector3();
  2608. }
  2609. public LSL_Types.list llListSort(LSL_Types.list src, int stride, int ascending)
  2610. {
  2611. m_host.AddScriptLPS(1);
  2612. return src.Sort(stride, ascending);
  2613. }
  2614. public int llGetListLength(LSL_Types.list src)
  2615. {
  2616. m_host.AddScriptLPS(1);
  2617. return src.Length;
  2618. }
  2619. public int llList2Integer(LSL_Types.list src, int index)
  2620. {
  2621. m_host.AddScriptLPS(1);
  2622. if (index < 0)
  2623. {
  2624. index = src.Length + index;
  2625. }
  2626. if (index >= src.Length)
  2627. {
  2628. return 0;
  2629. }
  2630. try
  2631. {
  2632. return Convert.ToInt32(src.Data[index]);
  2633. }
  2634. catch (FormatException e)
  2635. {
  2636. return 0;
  2637. }
  2638. }
  2639. public double osList2Double(LSL_Types.list src, int index)
  2640. {
  2641. m_host.AddScriptLPS(1);
  2642. if (index < 0)
  2643. {
  2644. index = src.Length + index;
  2645. }
  2646. if (index >= src.Length)
  2647. {
  2648. return 0.0;
  2649. }
  2650. return Convert.ToDouble(src.Data[index]);
  2651. }
  2652. public double llList2Float(LSL_Types.list src, int index)
  2653. {
  2654. m_host.AddScriptLPS(1);
  2655. if (index < 0)
  2656. {
  2657. index = src.Length + index;
  2658. }
  2659. if (index >= src.Length)
  2660. {
  2661. return 0.0;
  2662. }
  2663. try
  2664. {
  2665. return Convert.ToDouble(src.Data[index]);
  2666. }
  2667. catch (FormatException e)
  2668. {
  2669. return 0.0;
  2670. }
  2671. }
  2672. public string llList2String(LSL_Types.list src, int index)
  2673. {
  2674. m_host.AddScriptLPS(1);
  2675. if (index < 0)
  2676. {
  2677. index = src.Length + index;
  2678. }
  2679. if (index >= src.Length)
  2680. {
  2681. return String.Empty;
  2682. }
  2683. return src.Data[index].ToString();
  2684. }
  2685. public string llList2Key(LSL_Types.list src, int index)
  2686. {
  2687. m_host.AddScriptLPS(1);
  2688. if (index < 0)
  2689. {
  2690. index = src.Length + index;
  2691. }
  2692. if (index >= src.Length)
  2693. {
  2694. return "";
  2695. }
  2696. return src.Data[index].ToString();
  2697. }
  2698. public LSL_Types.Vector3 llList2Vector(LSL_Types.list src, int index)
  2699. {
  2700. m_host.AddScriptLPS(1);
  2701. if (index < 0)
  2702. {
  2703. index = src.Length + index;
  2704. }
  2705. if (index >= src.Length)
  2706. {
  2707. return new LSL_Types.Vector3(0, 0, 0);
  2708. }
  2709. if (src.Data[index].GetType() == typeof(LSL_Types.Vector3))
  2710. {
  2711. return (LSL_Types.Vector3)src.Data[index];
  2712. }
  2713. else
  2714. {
  2715. return new LSL_Types.Vector3(src.Data[index].ToString());
  2716. }
  2717. }
  2718. public LSL_Types.Quaternion llList2Rot(LSL_Types.list src, int index)
  2719. {
  2720. m_host.AddScriptLPS(1);
  2721. if (index < 0)
  2722. {
  2723. index = src.Length + index;
  2724. }
  2725. if (index >= src.Length)
  2726. {
  2727. return new LSL_Types.Quaternion(0, 0, 0, 1);
  2728. }
  2729. if (src.Data[index].GetType() == typeof(LSL_Types.Quaternion))
  2730. {
  2731. return (LSL_Types.Quaternion)src.Data[index];
  2732. }
  2733. else
  2734. {
  2735. return new LSL_Types.Quaternion(src.Data[index].ToString());
  2736. }
  2737. }
  2738. public LSL_Types.list llList2List(LSL_Types.list src, int start, int end)
  2739. {
  2740. m_host.AddScriptLPS(1);
  2741. return src.GetSublist(start, end);
  2742. }
  2743. public LSL_Types.list llDeleteSubList(LSL_Types.list src, int start, int end)
  2744. {
  2745. return src.DeleteSublist(end, start);
  2746. }
  2747. public int llGetListEntryType(LSL_Types.list src, int index)
  2748. {
  2749. m_host.AddScriptLPS(1);
  2750. if (index < 0)
  2751. {
  2752. index = src.Length + index;
  2753. }
  2754. if (index >= src.Length)
  2755. {
  2756. return 0;
  2757. }
  2758. if (src.Data[index] is Int32)
  2759. return 1;
  2760. if (src.Data[index] is Double)
  2761. return 2;
  2762. if (src.Data[index] is String)
  2763. {
  2764. LLUUID tuuid;
  2765. if (LLUUID.TryParse(src.Data[index].ToString(), out tuuid))
  2766. {
  2767. return 3;
  2768. }
  2769. else
  2770. {
  2771. return 4;
  2772. }
  2773. }
  2774. if (src.Data[index] is LSL_Types.Vector3)
  2775. return 5;
  2776. if (src.Data[index] is LSL_Types.Quaternion)
  2777. return 6;
  2778. if (src.Data[index] is LSL_Types.list)
  2779. return 7;
  2780. return 0;
  2781. }
  2782. /// <summary>
  2783. /// Process the supplied list and return the
  2784. /// content of the list formatted as a comma
  2785. /// separated list. There is a space after
  2786. /// each comma.
  2787. /// </summary>
  2788. public string llList2CSV(LSL_Types.list src)
  2789. {
  2790. string ret = String.Empty;
  2791. int x = 0;
  2792. m_host.AddScriptLPS(1);
  2793. if(src.Data.Length > 0)
  2794. {
  2795. ret = src.Data[x++].ToString();
  2796. for(;x<src.Data.Length;x++)
  2797. {
  2798. ret += ", "+src.Data[x].ToString();
  2799. }
  2800. }
  2801. return ret;
  2802. }
  2803. /// <summary>
  2804. /// The supplied string is scanned for commas
  2805. /// and converted into a list. Commas are only
  2806. /// effective if they are encountered outside
  2807. /// of '<' '>' delimiters. Any whitespace
  2808. /// before or after an element is trimmed.
  2809. /// </summary>
  2810. public LSL_Types.list llCSV2List(string src)
  2811. {
  2812. LSL_Types.list result = new LSL_Types.list();
  2813. int parens = 0;
  2814. int start = 0;
  2815. int length = 0;
  2816. m_host.AddScriptLPS(1);
  2817. for(int i=0; i<src.Length; i++)
  2818. {
  2819. switch(src[i])
  2820. {
  2821. case '<' :
  2822. parens++;
  2823. length++;
  2824. break;
  2825. case '>' :
  2826. if(parens > 0)
  2827. parens--;
  2828. length++;
  2829. break;
  2830. case ',' :
  2831. if(parens == 0)
  2832. {
  2833. result.Add(src.Substring(start,length).Trim());
  2834. start += length+1;
  2835. length = 0;
  2836. } else
  2837. length++;
  2838. break;
  2839. default :
  2840. length++;
  2841. break;
  2842. }
  2843. }
  2844. result.Add(src.Substring(start,length).Trim());
  2845. return result;
  2846. }
  2847. /// <summary>
  2848. /// Randomizes the list, be arbitrarily reordering
  2849. /// sublists of stride elements. As the stride approaches
  2850. /// the size of the list, the options become very
  2851. /// limited.
  2852. /// </summary>
  2853. /// <remarks>
  2854. /// This could take a while for very large list
  2855. /// sizes.
  2856. /// </remarks>
  2857. public LSL_Types.list llListRandomize(LSL_Types.list src, int stride)
  2858. {
  2859. LSL_Types.list result;
  2860. Random rand = new Random();
  2861. int chunkk;
  2862. int[] chunks;
  2863. int index1;
  2864. int index2;
  2865. int tmp;
  2866. m_host.AddScriptLPS(1);
  2867. if(stride == 0)
  2868. stride = 1;
  2869. // Stride MUST be a factor of the list length
  2870. // If not, then return the src list. This also
  2871. // traps those cases where stride > length.
  2872. if(src.Length != stride && src.Length%stride == 0)
  2873. {
  2874. chunkk = src.Length/stride;
  2875. chunks = new int[chunkk];
  2876. for(int i=0;i<chunkk;i++)
  2877. chunks[i] = i;
  2878. for(int i=0; i<chunkk-1; i++)
  2879. {
  2880. // randomly select 2 chunks
  2881. index1 = rand.Next(rand.Next(65536));
  2882. index1 = index1%chunkk;
  2883. index2 = rand.Next(rand.Next(65536));
  2884. index2 = index2%chunkk;
  2885. // and swap their relative positions
  2886. tmp = chunks[index1];
  2887. chunks[index1] = chunks[index2];
  2888. chunks[index2] = tmp;
  2889. }
  2890. // Construct the randomized list
  2891. result = new LSL_Types.list();
  2892. for(int i=0; i<chunkk; i++)
  2893. for(int j=0;j<stride;j++)
  2894. result.Add(src.Data[chunks[i]*stride+j]);
  2895. }
  2896. else {
  2897. object[] array = new object[src.Length];
  2898. Array.Copy(src.Data, 0, array, 0, src.Length);
  2899. result = new LSL_Types.list(array);
  2900. }
  2901. return result;
  2902. }
  2903. /// <summary>
  2904. /// Elements in the source list starting with 0 and then
  2905. /// every i+stride. If the stride is negative then the scan
  2906. /// is backwards producing an inverted result.
  2907. /// Only those elements that are also in the specified
  2908. /// range are included in the result.
  2909. /// </summary>
  2910. public LSL_Types.list llList2ListStrided(LSL_Types.list src, int start, int end, int stride)
  2911. {
  2912. LSL_Types.list result = new LSL_Types.list();
  2913. int[] si = new int[2];
  2914. int[] ei = new int[2];
  2915. bool twopass = false;
  2916. m_host.AddScriptLPS(1);
  2917. // First step is always to deal with negative indices
  2918. if(start < 0)
  2919. start = src.Length+start;
  2920. if(end < 0)
  2921. end = src.Length+end;
  2922. // Out of bounds indices are OK, just trim them
  2923. // accordingly
  2924. if(start > src.Length)
  2925. start = src.Length;
  2926. if(end > src.Length)
  2927. end = src.Length;
  2928. // There may be one or two ranges to be considered
  2929. if(start != end)
  2930. {
  2931. if(start <= end)
  2932. {
  2933. si[0] = start;
  2934. ei[0] = end;
  2935. }
  2936. else
  2937. {
  2938. si[1] = start;
  2939. ei[1] = src.Length;
  2940. si[0] = 0;
  2941. ei[0] = end;
  2942. twopass = true;
  2943. }
  2944. // The scan always starts from the beginning of the
  2945. // source list, but members are only selected if they
  2946. // fall within the specified sub-range. The specified
  2947. // range values are inclusive.
  2948. // A negative stride reverses the direction of the
  2949. // scan producing an inverted list as a result.
  2950. if(stride == 0)
  2951. stride = 1;
  2952. if(stride > 0)
  2953. for(int i=0;i<src.Length;i+=stride)
  2954. {
  2955. if(i<=ei[0] && i>=si[0])
  2956. result.Add(src.Data[i]);
  2957. if(twopass && i>=si[1] && i<=ei[1])
  2958. result.Add(src.Data[i]);
  2959. }
  2960. else if(stride < 0)
  2961. for(int i=src.Length-1;i>=0;i+=stride)
  2962. {
  2963. if(i<=ei[0] && i>=si[0])
  2964. result.Add(src.Data[i]);
  2965. if(twopass && i>=si[1] && i<=ei[1])
  2966. result.Add(src.Data[i]);
  2967. }
  2968. }
  2969. return result;
  2970. }
  2971. public LSL_Types.Vector3 llGetRegionCorner()
  2972. {
  2973. m_host.AddScriptLPS(1);
  2974. return new LSL_Types.Vector3(World.RegionInfo.RegionLocX * Constants.RegionSize, World.RegionInfo.RegionLocY * Constants.RegionSize, 0);
  2975. }
  2976. /// <summary>
  2977. /// Insert the list identified by <src> into the
  2978. /// list designated by <dest> such that the first
  2979. /// new element has the index specified by <index>
  2980. /// </summary>
  2981. public LSL_Types.list llListInsertList(LSL_Types.list dest, LSL_Types.list src, int index)
  2982. {
  2983. LSL_Types.list pref = null;
  2984. LSL_Types.list suff = null;
  2985. m_host.AddScriptLPS(1);
  2986. if(index < 0)
  2987. {
  2988. index = index+dest.Length;
  2989. if(index < 0)
  2990. {
  2991. index = 0;
  2992. }
  2993. }
  2994. if(index != 0)
  2995. {
  2996. pref = dest.GetSublist(0,index-1);
  2997. if(index < dest.Length)
  2998. {
  2999. suff = dest.GetSublist(index,-1);
  3000. return pref + src + suff;
  3001. }
  3002. else
  3003. {
  3004. return pref + src;
  3005. }
  3006. }
  3007. else
  3008. {
  3009. if(index < dest.Length)
  3010. {
  3011. suff = dest.GetSublist(index,-1);
  3012. return src + suff;
  3013. }
  3014. else
  3015. {
  3016. return src;
  3017. }
  3018. }
  3019. }
  3020. /// <summary>
  3021. /// Returns the index of the first occurrence of test
  3022. /// in src.
  3023. /// </summary>
  3024. public int llListFindList(LSL_Types.list src, LSL_Types.list test)
  3025. {
  3026. int index = -1;
  3027. int length = src.Length - test.Length + 1;
  3028. m_host.AddScriptLPS(1);
  3029. // If either list is empty, do not match
  3030. if(src.Length != 0 && test.Length != 0)
  3031. {
  3032. for(int i=0; i< length; i++)
  3033. {
  3034. if(src.Data[i].Equals(test.Data[0]))
  3035. {
  3036. int j;
  3037. for(j=1;j<test.Length;j++)
  3038. if(!src.Data[i+j].Equals(test.Data[j]))
  3039. break;
  3040. if(j == test.Length)
  3041. {
  3042. index = i;
  3043. break;
  3044. }
  3045. }
  3046. }
  3047. }
  3048. return index;
  3049. }
  3050. public string llGetObjectName()
  3051. {
  3052. m_host.AddScriptLPS(1);
  3053. return m_host.Name!=null?m_host.Name:String.Empty;
  3054. }
  3055. public void llSetObjectName(string name)
  3056. {
  3057. m_host.AddScriptLPS(1);
  3058. m_host.Name = name!=null?name:String.Empty;
  3059. }
  3060. public string llGetDate()
  3061. {
  3062. m_host.AddScriptLPS(1);
  3063. DateTime date = DateTime.Now.ToUniversalTime();
  3064. string result = date.ToString("yyyy-MM-dd");
  3065. return result;
  3066. }
  3067. public int llEdgeOfWorld(LSL_Types.Vector3 pos, LSL_Types.Vector3 dir)
  3068. {
  3069. m_host.AddScriptLPS(1);
  3070. NotImplemented("llEdgeOfWorld");
  3071. return 0;
  3072. }
  3073. public int llGetAgentInfo(string id)
  3074. {
  3075. m_host.AddScriptLPS(1);
  3076. NotImplemented("llGetAgentInfo");
  3077. return 0;
  3078. }
  3079. public void llAdjustSoundVolume(double volume)
  3080. {
  3081. m_host.AddScriptLPS(1);
  3082. m_host.AdjustSoundGain(volume);
  3083. }
  3084. public void llSetSoundQueueing(int queue)
  3085. {
  3086. m_host.AddScriptLPS(1);
  3087. NotImplemented("llSetSoundQueueing");
  3088. }
  3089. public void llSetSoundRadius(double radius)
  3090. {
  3091. m_host.AddScriptLPS(1);
  3092. NotImplemented("llSetSoundRadius");
  3093. }
  3094. public string llKey2Name(string id)
  3095. {
  3096. m_host.AddScriptLPS(1);
  3097. LLUUID key = new LLUUID();
  3098. if (LLUUID.TryParse(id,out key))
  3099. {
  3100. if (World.m_innerScene.ScenePresences.ContainsKey(key))
  3101. {
  3102. return World.m_innerScene.ScenePresences[key].Firstname + " " + World.m_innerScene.ScenePresences[key].Lastname;
  3103. }
  3104. if (World.GetSceneObjectPart(key) != null)
  3105. {
  3106. return World.GetSceneObjectPart(key).Name;
  3107. }
  3108. }
  3109. return String.Empty;
  3110. }
  3111. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  3112. {
  3113. m_host.AddScriptLPS(1);
  3114. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation();
  3115. pTexAnim.Flags =(uint) mode;
  3116. //ALL_SIDES
  3117. if (face == -1)
  3118. face = 255;
  3119. pTexAnim.Face = (uint)face;
  3120. pTexAnim.Length = (float)length;
  3121. pTexAnim.Rate = (float)rate;
  3122. pTexAnim.SizeX = (uint)sizex;
  3123. pTexAnim.SizeY = (uint)sizey;
  3124. pTexAnim.Start = (float)start;
  3125. m_host.AddTextureAnimation(pTexAnim);
  3126. m_host.SendFullUpdateToAllClients();
  3127. }
  3128. public void llTriggerSoundLimited(string sound, double volume, LSL_Types.Vector3 top_north_east,
  3129. LSL_Types.Vector3 bottom_south_west)
  3130. {
  3131. m_host.AddScriptLPS(1);
  3132. NotImplemented("llTriggerSoundLimited");
  3133. }
  3134. public void llEjectFromLand(string pest)
  3135. {
  3136. m_host.AddScriptLPS(1);
  3137. NotImplemented("llEjectFromLand");
  3138. }
  3139. public LSL_Types.list llParseString2List(string str, LSL_Types.list separators, LSL_Types.list spacers)
  3140. {
  3141. m_host.AddScriptLPS(1);
  3142. LSL_Types.list ret = new LSL_Types.list();
  3143. object[] delimiters = new object[separators.Length + spacers.Length];
  3144. separators.Data.CopyTo(delimiters, 0);
  3145. spacers.Data.CopyTo(delimiters, separators.Length);
  3146. bool dfound = false;
  3147. do
  3148. {
  3149. dfound = false;
  3150. int cindex = -1;
  3151. string cdeli = "";
  3152. for (int i = 0; i < delimiters.Length; i++)
  3153. {
  3154. int index = str.IndexOf(delimiters[i].ToString());
  3155. bool found = index != -1;
  3156. if (found)
  3157. {
  3158. if ((cindex > index) || (cindex == -1))
  3159. {
  3160. cindex = index;
  3161. cdeli = (string)delimiters[i];
  3162. }
  3163. dfound = dfound || found;
  3164. }
  3165. }
  3166. if (cindex != -1)
  3167. {
  3168. if (cindex > 0)
  3169. {
  3170. ret.Add(str.Substring(0, cindex));
  3171. if (spacers.Contains(cdeli))
  3172. {
  3173. ret.Add(cdeli);
  3174. }
  3175. }
  3176. if (cindex == 0 && spacers.Contains(cdeli))
  3177. {
  3178. ret.Add(cdeli);
  3179. }
  3180. str = str.Substring(cindex + cdeli.Length);
  3181. }
  3182. } while (dfound);
  3183. if (str != "")
  3184. {
  3185. ret.Add(str);
  3186. }
  3187. return ret;
  3188. }
  3189. public int llOverMyLand(string id)
  3190. {
  3191. m_host.AddScriptLPS(1);
  3192. LLUUID key = new LLUUID();
  3193. if (LLUUID.TryParse(id,out key))
  3194. {
  3195. SceneObjectPart obj = new SceneObjectPart();
  3196. obj = World.GetSceneObjectPart(World.Entities[key].LocalId);
  3197. if (obj.OwnerID == World.GetLandOwner(obj.AbsolutePosition.X, obj.AbsolutePosition.Y))
  3198. {
  3199. return 1;
  3200. }
  3201. else
  3202. {
  3203. return 0;
  3204. }
  3205. }
  3206. else
  3207. {
  3208. return 0;
  3209. }
  3210. }
  3211. public string llGetLandOwnerAt(LSL_Types.Vector3 pos)
  3212. {
  3213. m_host.AddScriptLPS(1);
  3214. return World.GetLandOwner((float)pos.x, (float)pos.y).ToString();
  3215. }
  3216. public string llGetNotecardLine(string name, int line)
  3217. {
  3218. m_host.AddScriptLPS(1);
  3219. NotImplemented("llGetNotecardLine");
  3220. return String.Empty;
  3221. }
  3222. public LSL_Types.Vector3 llGetAgentSize(string id)
  3223. {
  3224. m_host.AddScriptLPS(1);
  3225. NotImplemented("llGetAgentSize");
  3226. return new LSL_Types.Vector3();
  3227. }
  3228. public int llSameGroup(string agent)
  3229. {
  3230. m_host.AddScriptLPS(1);
  3231. NotImplemented("llSameGroup");
  3232. return 0;
  3233. }
  3234. public void llUnSit(string id)
  3235. {
  3236. m_host.AddScriptLPS(1);
  3237. LLUUID key = new LLUUID();
  3238. if (LLUUID.TryParse(id, out key))
  3239. {
  3240. ScenePresence av = World.GetScenePresence(key);
  3241. if (av != null)
  3242. {
  3243. if (llAvatarOnSitTarget() == id)
  3244. {
  3245. // if the avatar is sitting on this object, then
  3246. // we can unsit them. We don't want random scripts unsitting random people
  3247. // Lets avoid the popcorn avatar scenario.
  3248. av.StandUp();
  3249. }
  3250. else
  3251. {
  3252. // If the object owner also owns the parcel
  3253. // or
  3254. // if the land is group owned and the object is group owned by the same group
  3255. // or
  3256. // if the object is owned by a person with estate access.
  3257. ILandObject parcel = World.LandChannel.getLandObject(av.AbsolutePosition.X, av.AbsolutePosition.Y);
  3258. if (parcel != null)
  3259. {
  3260. if (m_host.ObjectOwner == parcel.landData.ownerID ||
  3261. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.landData.groupID
  3262. && parcel.landData.isGroupOwned) || World.PermissionsMngr.GenericEstatePermission(m_host.OwnerID))
  3263. {
  3264. av.StandUp();
  3265. }
  3266. }
  3267. }
  3268. }
  3269. }
  3270. }
  3271. public LSL_Types.Vector3 llGroundSlope(LSL_Types.Vector3 offset)
  3272. {
  3273. m_host.AddScriptLPS(1);
  3274. NotImplemented("llGroundSlope");
  3275. return new LSL_Types.Vector3();
  3276. }
  3277. public LSL_Types.Vector3 llGroundNormal(LSL_Types.Vector3 offset)
  3278. {
  3279. m_host.AddScriptLPS(1);
  3280. NotImplemented("llGroundNormal");
  3281. return new LSL_Types.Vector3();
  3282. }
  3283. public LSL_Types.Vector3 llGroundContour(LSL_Types.Vector3 offset)
  3284. {
  3285. m_host.AddScriptLPS(1);
  3286. NotImplemented("llGroundContour");
  3287. return new LSL_Types.Vector3();
  3288. }
  3289. public int llGetAttached()
  3290. {
  3291. m_host.AddScriptLPS(1);
  3292. NotImplemented("llGetAttached");
  3293. return 0;
  3294. }
  3295. public int llGetFreeMemory()
  3296. {
  3297. m_host.AddScriptLPS(1);
  3298. NotImplemented("llGetFreeMemory");
  3299. return 0;
  3300. }
  3301. public string llGetRegionName()
  3302. {
  3303. m_host.AddScriptLPS(1);
  3304. return World.RegionInfo.RegionName;
  3305. }
  3306. public double llGetRegionTimeDilation()
  3307. {
  3308. m_host.AddScriptLPS(1);
  3309. return (double)World.TimeDilation;
  3310. }
  3311. public double llGetRegionFPS()
  3312. {
  3313. m_host.AddScriptLPS(1);
  3314. return 10.0f;
  3315. }
  3316. /* particle system rules should be coming into this routine as doubles, that is
  3317. rule[0] should be an integer from this list and rule[1] should be the arg
  3318. for the same integer. wiki.secondlife.com has most of this mapping, but some
  3319. came from http://www.caligari-designs.com/p4u2
  3320. We iterate through the list for 'Count' elements, incrementing by two for each
  3321. iteration and set the members of Primitive.ParticleSystem, one at a time.
  3322. */
  3323. public enum PrimitiveRule : int
  3324. {
  3325. PSYS_PART_FLAGS = 0,
  3326. PSYS_PART_START_COLOR = 1,
  3327. PSYS_PART_START_ALPHA = 2,
  3328. PSYS_PART_END_COLOR = 3,
  3329. PSYS_PART_END_ALPHA = 4,
  3330. PSYS_PART_START_SCALE = 5,
  3331. PSYS_PART_END_SCALE = 6,
  3332. PSYS_PART_MAX_AGE = 7,
  3333. PSYS_SRC_ACCEL = 8,
  3334. PSYS_SRC_PATTERN = 9,
  3335. PSYS_SRC_TEXTURE = 12,
  3336. PSYS_SRC_BURST_RATE = 13,
  3337. PSYS_SRC_BURST_PART_COUNT = 15,
  3338. PSYS_SRC_BURST_RADIUS = 16,
  3339. PSYS_SRC_BURST_SPEED_MIN = 17,
  3340. PSYS_SRC_BURST_SPEED_MAX = 18,
  3341. PSYS_SRC_MAX_AGE = 19,
  3342. PSYS_SRC_TARGET_KEY = 20,
  3343. PSYS_SRC_OMEGA = 21,
  3344. PSYS_SRC_ANGLE_BEGIN = 22,
  3345. PSYS_SRC_ANGLE_END = 23
  3346. }
  3347. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  3348. {
  3349. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  3350. return returnval;
  3351. }
  3352. // AL: This does not actually do anything yet. There are issues within Libsecondlife revolving around PSYS_PART_FLAGS
  3353. // (need to OR the values, but currently stores this within an enum) as well as discovery of how the CRC works and the
  3354. // actual packet.
  3355. public void llParticleSystem(LSL_Types.list rules)
  3356. {
  3357. m_host.AddScriptLPS(1);
  3358. Primitive.ParticleSystem prules = new Primitive.ParticleSystem();
  3359. LSL_Types.Vector3 tempv = new LSL_Types.Vector3();
  3360. float tempf = 0;
  3361. for (int i = 0; i < rules.Length; i += 2)
  3362. {
  3363. switch ((int)rules.Data[i])
  3364. {
  3365. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_FLAGS:
  3366. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)((uint)Convert.ToInt32(rules.Data[i + 1].ToString()));
  3367. break;
  3368. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_START_COLOR:
  3369. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3370. prules.PartStartColor.R = (float)tempv.x;
  3371. prules.PartStartColor.G = (float)tempv.y;
  3372. prules.PartStartColor.B = (float)tempv.z;
  3373. break;
  3374. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_START_ALPHA:
  3375. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3376. prules.PartStartColor.A = (float)tempf;
  3377. break;
  3378. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_END_COLOR:
  3379. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3380. //prules.PartEndColor = new LLColor(tempv.x,tempv.y,tempv.z,1);
  3381. prules.PartEndColor.R = (float)tempv.x;
  3382. prules.PartEndColor.G = (float)tempv.y;
  3383. prules.PartEndColor.B = (float)tempv.z;
  3384. break;
  3385. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_END_ALPHA:
  3386. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3387. prules.PartEndColor.A = (float)tempf;
  3388. break;
  3389. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_START_SCALE:
  3390. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3391. prules.PartStartScaleX = (float)tempv.x;
  3392. prules.PartStartScaleY = (float)tempv.y;
  3393. break;
  3394. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_END_SCALE:
  3395. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3396. prules.PartEndScaleX = (float)tempv.x;
  3397. prules.PartEndScaleY = (float)tempv.y;
  3398. break;
  3399. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_MAX_AGE:
  3400. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3401. prules.PartMaxAge = (float)tempf;
  3402. break;
  3403. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_ACCEL:
  3404. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3405. prules.PartAcceleration.X = (float)tempv.x;
  3406. prules.PartAcceleration.Y = (float)tempv.y;
  3407. prules.PartAcceleration.Z = (float)tempv.z;
  3408. break;
  3409. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_PATTERN:
  3410. int tmpi = (int)rules.Data[i + 1];
  3411. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  3412. break;
  3413. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_TEXTURE:
  3414. prules.Texture = new LLUUID(rules.Data[i + 1].ToString());
  3415. break;
  3416. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_BURST_RATE:
  3417. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3418. prules.BurstRate = (float)tempf;
  3419. break;
  3420. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_BURST_PART_COUNT:
  3421. prules.BurstPartCount = (byte)Convert.ToByte(rules.Data[i + 1].ToString());
  3422. break;
  3423. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_BURST_RADIUS:
  3424. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3425. prules.BurstRadius = (float)tempf;
  3426. break;
  3427. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_BURST_SPEED_MIN:
  3428. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3429. prules.BurstSpeedMin = (float)tempf;
  3430. break;
  3431. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_BURST_SPEED_MAX:
  3432. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3433. prules.BurstSpeedMax = (float)tempf;
  3434. break;
  3435. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_MAX_AGE:
  3436. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3437. prules.MaxAge = (float)tempf;
  3438. break;
  3439. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_TARGET_KEY:
  3440. LLUUID key = LLUUID.Zero;
  3441. if (LLUUID.TryParse(rules.Data[i + 1].ToString(), out key))
  3442. {
  3443. prules.Target = key;
  3444. }
  3445. else
  3446. {
  3447. prules.Target = m_host.UUID;
  3448. }
  3449. break;
  3450. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_OMEGA:
  3451. // AL: This is an assumption, since it is the only thing that would match.
  3452. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3453. prules.AngularVelocity.X = (float)tempv.x;
  3454. prules.AngularVelocity.Y = (float)tempv.y;
  3455. prules.AngularVelocity.Z = (float)tempv.z;
  3456. //cast?? prules.MaxAge = (float)rules[i + 1];
  3457. break;
  3458. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_ANGLE_BEGIN:
  3459. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3460. prules.InnerAngle = (float)tempf;
  3461. break;
  3462. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_ANGLE_END:
  3463. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3464. prules.OuterAngle = (float)tempf;
  3465. break;
  3466. }
  3467. }
  3468. prules.CRC = 1;
  3469. m_host.AddNewParticleSystem(prules);
  3470. m_host.SendFullUpdateToAllClients();
  3471. }
  3472. public void llGroundRepel(double height, int water, double tau)
  3473. {
  3474. m_host.AddScriptLPS(1);
  3475. NotImplemented("llGroundRepel");
  3476. }
  3477. public void llGiveInventoryList()
  3478. {
  3479. m_host.AddScriptLPS(1);
  3480. NotImplemented("llGiveInventoryList");
  3481. }
  3482. public void llSetVehicleType(int type)
  3483. {
  3484. m_host.AddScriptLPS(1);
  3485. NotImplemented("llSetVehicleType");
  3486. }
  3487. public void llSetVehicledoubleParam(int param, double value)
  3488. {
  3489. m_host.AddScriptLPS(1);
  3490. NotImplemented("llSetVehicledoubleParam");
  3491. }
  3492. public void llSetVehicleVectorParam(int param, LSL_Types.Vector3 vec)
  3493. {
  3494. m_host.AddScriptLPS(1);
  3495. NotImplemented("llSetVehicleVectorParam");
  3496. }
  3497. public void llSetVehicleRotationParam(int param, LSL_Types.Quaternion rot)
  3498. {
  3499. m_host.AddScriptLPS(1);
  3500. NotImplemented("llSetVehicleRotationParam");
  3501. }
  3502. public void llSetVehicleFlags(int flags)
  3503. {
  3504. m_host.AddScriptLPS(1);
  3505. NotImplemented("llSetVehicleFlags");
  3506. }
  3507. public void llRemoveVehicleFlags(int flags)
  3508. {
  3509. m_host.AddScriptLPS(1);
  3510. NotImplemented("llRemoveVehicleFlags");
  3511. }
  3512. public void llSitTarget(LSL_Types.Vector3 offset, LSL_Types.Quaternion rot)
  3513. {
  3514. m_host.AddScriptLPS(1);
  3515. // LSL quaternions can normalize to 0, normal Quaternions can't.
  3516. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
  3517. rot.z = 1; // ZERO_ROTATION = 0,0,0,1
  3518. m_host.SetSitTarget(new Vector3((float)offset.x, (float)offset.y, (float)offset.z), new Quaternion((float)rot.s, (float)rot.x, (float)rot.y, (float)rot.z));
  3519. }
  3520. public string llAvatarOnSitTarget()
  3521. {
  3522. m_host.AddScriptLPS(1);
  3523. return m_host.GetAvatarOnSitTarget().ToString();
  3524. //LLUUID AVID = m_host.GetAvatarOnSitTarget();
  3525. //if (AVID != LLUUID.Zero)
  3526. // return AVID.ToString();
  3527. //else
  3528. // return String.Empty;
  3529. }
  3530. public void llAddToLandPassList(string avatar, double hours)
  3531. {
  3532. m_host.AddScriptLPS(1);
  3533. LLUUID key;
  3534. LandData land = World.LandChannel.getLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  3535. if (land.ownerID == m_host.OwnerID)
  3536. {
  3537. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  3538. if (LLUUID.TryParse(avatar, out key))
  3539. {
  3540. entry.AgentID = key;
  3541. entry.Flags = ParcelManager.AccessList.Access;
  3542. entry.Time = DateTime.Now.AddHours(hours);
  3543. land.parcelAccessList.Add(entry);
  3544. }
  3545. }
  3546. }
  3547. public void llSetTouchText(string text)
  3548. {
  3549. m_host.AddScriptLPS(1);
  3550. m_host.TouchName = text;
  3551. }
  3552. public void llSetSitText(string text)
  3553. {
  3554. m_host.AddScriptLPS(1);
  3555. m_host.SitName = text;
  3556. }
  3557. public void llSetCameraEyeOffset(LSL_Types.Vector3 offset)
  3558. {
  3559. m_host.AddScriptLPS(1);
  3560. NotImplemented("llSetCameraEyeOffset");
  3561. }
  3562. public void llSetCameraAtOffset(LSL_Types.Vector3 offset)
  3563. {
  3564. m_host.AddScriptLPS(1);
  3565. NotImplemented("llSetCameraAtOffset");
  3566. }
  3567. public string llDumpList2String(LSL_Types.list src, string seperator)
  3568. {
  3569. m_host.AddScriptLPS(1);
  3570. if (src.Length == 0)
  3571. {
  3572. return String.Empty;
  3573. }
  3574. string ret = String.Empty;
  3575. foreach (object o in src.Data)
  3576. {
  3577. ret = ret + o.ToString() + seperator;
  3578. }
  3579. ret = ret.Substring(0, ret.Length - seperator.Length);
  3580. return ret;
  3581. }
  3582. public int llScriptDanger(LSL_Types.Vector3 pos)
  3583. {
  3584. m_host.AddScriptLPS(1);
  3585. bool result = World.scriptDanger(m_host.LocalId, new LLVector3((float)pos.x, (float)pos.y, (float)pos.z));
  3586. if (result)
  3587. {
  3588. return 1;
  3589. }
  3590. else
  3591. {
  3592. return 0;
  3593. }
  3594. }
  3595. public void llDialog(string avatar, string message, LSL_Types.list buttons, int chat_channel)
  3596. {
  3597. m_host.AddScriptLPS(1);
  3598. LLUUID av = new LLUUID();
  3599. if (!LLUUID.TryParse(avatar,out av))
  3600. {
  3601. LSLError("First parameter to llDialog needs to be a key");
  3602. return;
  3603. }
  3604. if(buttons.Length > 12)
  3605. {
  3606. LSLError("No more than 12 buttons can be shown");
  3607. return;
  3608. }
  3609. string[] buts = new string[buttons.Length];
  3610. for(int i = 0; i < buttons.Length; i++)
  3611. {
  3612. if(buttons.Data[i].ToString() == String.Empty)
  3613. {
  3614. LSLError("button label cannot be blank");
  3615. return;
  3616. }
  3617. if(buttons.Data[i].ToString().Length > 24)
  3618. {
  3619. LSLError("button label cannot be longer than 24 characters");
  3620. return;
  3621. }
  3622. buts[i] = buttons.Data[i].ToString();
  3623. }
  3624. World.SendDialogToUser(av, m_host.Name, m_host.UUID, m_host.OwnerID, message, new LLUUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  3625. }
  3626. public void llVolumeDetect(int detect)
  3627. {
  3628. m_host.AddScriptLPS(1);
  3629. NotImplemented("llVolumeDetect");
  3630. }
  3631. /// <summary>
  3632. /// Reset the named script. The script must be present
  3633. /// in the same prim.
  3634. /// </summary>
  3635. public void llResetOtherScript(string name)
  3636. {
  3637. LLUUID item;
  3638. ScriptManager sm;
  3639. IScript script = null;
  3640. m_host.AddScriptLPS(1);
  3641. // These functions are supposed to be robust,
  3642. // so get the state one step at a time.
  3643. if((item = ScriptByName(name)) != LLUUID.Zero)
  3644. if((sm = m_ScriptEngine.m_ScriptManager) != null)
  3645. sm.ResetScript(m_localID, item);
  3646. // Required by SL
  3647. if(script == null)
  3648. ShoutError("llResetOtherScript: script "+name+" not found");
  3649. // If we didn;t find it, then it's safe to
  3650. // assume it is not running.
  3651. return;
  3652. }
  3653. public int llGetScriptState(string name)
  3654. {
  3655. LLUUID item;
  3656. ScriptManager sm;
  3657. IScript script = null;
  3658. m_host.AddScriptLPS(1);
  3659. // These functions are supposed to be robust,
  3660. // so get the state one step at a time.
  3661. if((item = ScriptByName(name)) != LLUUID.Zero)
  3662. if((sm = m_ScriptEngine.m_ScriptManager) != null)
  3663. if((script = sm.GetScript(m_localID, item)) != null)
  3664. return script.Exec.Running?1:0;
  3665. // Required by SL
  3666. if(script == null)
  3667. ShoutError("llGetScriptState: script "+name+" not found");
  3668. // If we didn;t find it, then it's safe to
  3669. // assume it is not running.
  3670. return 0;
  3671. }
  3672. public void llRemoteLoadScript()
  3673. {
  3674. m_host.AddScriptLPS(1);
  3675. Deprecated("llRemoteLoadScript");
  3676. }
  3677. public void llSetRemoteScriptAccessPin(int pin)
  3678. {
  3679. m_host.AddScriptLPS(1);
  3680. NotImplemented("llSetRemoteScriptAccessPin");
  3681. }
  3682. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  3683. {
  3684. m_host.AddScriptLPS(1);
  3685. NotImplemented("llRemoteLoadScriptPin");
  3686. }
  3687. // remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval)
  3688. // Not sure where these constants should live:
  3689. // REMOTE_DATA_CHANNEL = 1
  3690. // REMOTE_DATA_REQUEST = 2
  3691. // REMOTE_DATA_REPLY = 3
  3692. public void llOpenRemoteDataChannel()
  3693. {
  3694. m_host.AddScriptLPS(1);
  3695. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3696. if (xmlrpcMod.IsEnabled())
  3697. {
  3698. LLUUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID);
  3699. object[] resobj = new object[] { new LSL_Types.LSLInteger(1), new LSL_Types.LSLString(channelID.ToString()), new LSL_Types.LSLString(LLUUID.Zero.ToString()), new LSL_Types.LSLString(String.Empty), new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(String.Empty) };
  3700. m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(m_localID, m_itemID, "remote_data", EventQueueManager.llDetectNull, resobj);
  3701. }
  3702. }
  3703. public string llSendRemoteData(string channel, string dest, int idata, string sdata)
  3704. {
  3705. m_host.AddScriptLPS(1);
  3706. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3707. return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString();
  3708. }
  3709. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  3710. {
  3711. m_host.AddScriptLPS(1);
  3712. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3713. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  3714. }
  3715. public void llCloseRemoteDataChannel(string channel)
  3716. {
  3717. m_host.AddScriptLPS(1);
  3718. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3719. xmlrpcMod.CloseXMLRPCChannel(channel);
  3720. }
  3721. public string llMD5String(string src, int nonce)
  3722. {
  3723. m_host.AddScriptLPS(1);
  3724. return Util.Md5Hash(src + ":" + nonce.ToString());
  3725. }
  3726. public void llSetPrimitiveParams(LSL_Types.list rules)
  3727. {
  3728. llSetLinkPrimitiveParams(m_host.LinkNum+1, rules);
  3729. }
  3730. public void llSetLinkPrimitiveParams(int linknumber, LSL_Types.list rules)
  3731. {
  3732. m_host.AddScriptLPS(1);
  3733. SceneObjectPart part=null;
  3734. if(m_host.LinkNum+1 != linknumber)
  3735. {
  3736. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  3737. {
  3738. if ((partInst.LinkNum + 1) == linknumber)
  3739. {
  3740. part=partInst;
  3741. break;
  3742. }
  3743. }
  3744. }
  3745. else
  3746. {
  3747. part=m_host;
  3748. }
  3749. if(part == null)
  3750. return;
  3751. int idx=0;
  3752. while(idx < rules.Length)
  3753. {
  3754. int code=Convert.ToInt32(rules.Data[idx++]);
  3755. int remain=rules.Length-idx;
  3756. int face;
  3757. LSL_Types.Vector3 v;
  3758. switch(code)
  3759. {
  3760. case 6: // PRIM_POSITION
  3761. if(remain < 1)
  3762. return;
  3763. v=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  3764. SetPos(part, v);
  3765. break;
  3766. case 8: // PRIM_ROTATION
  3767. if(remain < 1)
  3768. return;
  3769. LSL_Types.Quaternion q = new LSL_Types.Quaternion(rules.Data[idx++].ToString());
  3770. SetRot(part, q);
  3771. break;
  3772. case 17: // PRIM_TEXTURE
  3773. if(remain < 5)
  3774. return;
  3775. face=Convert.ToInt32(rules.Data[idx++]);
  3776. string tex=rules.Data[idx++].ToString();
  3777. LSL_Types.Vector3 repeats=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  3778. LSL_Types.Vector3 offsets=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  3779. double rotation=Convert.ToDouble(rules.Data[idx++]);
  3780. SetTexture(part, tex, face);
  3781. ScaleTexture(part, repeats.x, repeats.y, face);
  3782. OffsetTexture(part, offsets.x, offsets.y, face);
  3783. RotateTexture(part, rotation, face);
  3784. break;
  3785. case 18: // PRIM_COLOR
  3786. if(remain < 3)
  3787. return;
  3788. face=Convert.ToInt32(rules.Data[idx++]);
  3789. LSL_Types.Vector3 color=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  3790. double alpha=Convert.ToDouble(rules.Data[idx++]);
  3791. SetColor(part, color, face);
  3792. SetAlpha(part, alpha, face);
  3793. break;
  3794. case 7: // PRIM_SIZE
  3795. if(remain < 1)
  3796. return;
  3797. v=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  3798. SetScale(part, v);
  3799. break;
  3800. }
  3801. }
  3802. }
  3803. public string llStringToBase64(string str)
  3804. {
  3805. m_host.AddScriptLPS(1);
  3806. try
  3807. {
  3808. byte[] encData_byte = new byte[str.Length];
  3809. encData_byte = Encoding.UTF8.GetBytes(str);
  3810. string encodedData = Convert.ToBase64String(encData_byte);
  3811. return encodedData;
  3812. }
  3813. catch (Exception e)
  3814. {
  3815. throw new Exception("Error in base64Encode" + e.Message);
  3816. }
  3817. }
  3818. public string llBase64ToString(string str)
  3819. {
  3820. m_host.AddScriptLPS(1);
  3821. UTF8Encoding encoder = new UTF8Encoding();
  3822. Decoder utf8Decode = encoder.GetDecoder();
  3823. try
  3824. {
  3825. byte[] todecode_byte = Convert.FromBase64String(str);
  3826. int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
  3827. char[] decoded_char = new char[charCount];
  3828. utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
  3829. string result = new String(decoded_char);
  3830. return result;
  3831. }
  3832. catch (Exception e)
  3833. {
  3834. throw new Exception("Error in base64Decode" + e.Message);
  3835. }
  3836. }
  3837. public void llXorBase64Strings()
  3838. {
  3839. m_host.AddScriptLPS(1);
  3840. Deprecated("llXorBase64Strings");
  3841. }
  3842. public void llRemoteDataSetRegion()
  3843. {
  3844. m_host.AddScriptLPS(1);
  3845. NotImplemented("llRemoteDataSetRegion");
  3846. }
  3847. public double llLog10(double val)
  3848. {
  3849. m_host.AddScriptLPS(1);
  3850. return (double)Math.Log10(val);
  3851. }
  3852. public double llLog(double val)
  3853. {
  3854. m_host.AddScriptLPS(1);
  3855. return (double)Math.Log(val);
  3856. }
  3857. public LSL_Types.list llGetAnimationList(string id)
  3858. {
  3859. m_host.AddScriptLPS(1);
  3860. NotImplemented("llGetAnimationList");
  3861. return new LSL_Types.list();
  3862. }
  3863. public void llSetParcelMusicURL(string url)
  3864. {
  3865. m_host.AddScriptLPS(1);
  3866. LLUUID landowner = World.GetLandOwner(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  3867. if (landowner == LLUUID.Zero)
  3868. {
  3869. return;
  3870. }
  3871. if (landowner != m_host.ObjectOwner)
  3872. {
  3873. return;
  3874. }
  3875. World.SetLandMusicURL(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, url);
  3876. }
  3877. public void osSetParcelMediaURL(string url)
  3878. {
  3879. m_host.AddScriptLPS(1);
  3880. LLUUID landowner = World.GetLandOwner(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  3881. if(landowner == LLUUID.Zero)
  3882. {
  3883. return;
  3884. }
  3885. if(landowner != m_host.ObjectOwner)
  3886. {
  3887. return;
  3888. }
  3889. World.SetLandMediaURL(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, url);
  3890. }
  3891. public LSL_Types.Vector3 llGetRootPosition()
  3892. {
  3893. m_host.AddScriptLPS(1);
  3894. return new LSL_Types.Vector3(m_host.ParentGroup.AbsolutePosition.X, m_host.ParentGroup.AbsolutePosition.Y, m_host.ParentGroup.AbsolutePosition.Z);
  3895. }
  3896. public LSL_Types.Quaternion llGetRootRotation()
  3897. {
  3898. m_host.AddScriptLPS(1);
  3899. return new LSL_Types.Quaternion(m_host.ParentGroup.GroupRotation.X, m_host.ParentGroup.GroupRotation.Y, m_host.ParentGroup.GroupRotation.Z, m_host.ParentGroup.GroupRotation.W);
  3900. }
  3901. public string llGetObjectDesc()
  3902. {
  3903. return m_host.Description!=null?m_host.Description:String.Empty;
  3904. }
  3905. public void llSetObjectDesc(string desc)
  3906. {
  3907. m_host.AddScriptLPS(1);
  3908. m_host.Description = desc!=null?desc:String.Empty;
  3909. }
  3910. public string llGetCreator()
  3911. {
  3912. m_host.AddScriptLPS(1);
  3913. return m_host.ObjectCreator.ToString();
  3914. }
  3915. public string llGetTimestamp()
  3916. {
  3917. m_host.AddScriptLPS(1);
  3918. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  3919. }
  3920. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  3921. {
  3922. m_host.AddScriptLPS(1);
  3923. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  3924. if (linknumber > -1)
  3925. {
  3926. LLObject.TextureEntry tex = part.Shape.Textures;
  3927. LLColor texcolor;
  3928. if (face > -1)
  3929. {
  3930. texcolor = tex.CreateFace((uint)face).RGBA;
  3931. texcolor.A = (float)Math.Abs(alpha - 1);
  3932. tex.FaceTextures[face].RGBA = texcolor;
  3933. part.UpdateTexture(tex);
  3934. return;
  3935. }
  3936. else if (face == -1)
  3937. {
  3938. texcolor = tex.DefaultTexture.RGBA;
  3939. texcolor.A = (float)Math.Abs(alpha - 1);
  3940. tex.DefaultTexture.RGBA = texcolor;
  3941. for (uint i = 0; i < 32; i++)
  3942. {
  3943. if (tex.FaceTextures[i] != null)
  3944. {
  3945. texcolor = tex.FaceTextures[i].RGBA;
  3946. texcolor.A = (float)Math.Abs(alpha - 1);
  3947. tex.FaceTextures[i].RGBA = texcolor;
  3948. }
  3949. }
  3950. texcolor = tex.DefaultTexture.RGBA;
  3951. texcolor.A = (float)Math.Abs(alpha - 1);
  3952. tex.DefaultTexture.RGBA = texcolor;
  3953. part.UpdateTexture(tex);
  3954. return;
  3955. }
  3956. return;
  3957. }
  3958. else if (linknumber == -1)
  3959. {
  3960. int num = m_host.ParentGroup.PrimCount;
  3961. for (int w = 0; w < num; w++)
  3962. {
  3963. linknumber = w;
  3964. part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  3965. LLObject.TextureEntry tex = part.Shape.Textures;
  3966. LLColor texcolor;
  3967. if (face > -1)
  3968. {
  3969. texcolor = tex.CreateFace((uint)face).RGBA;
  3970. texcolor.A = (float)Math.Abs(alpha - 1);
  3971. tex.FaceTextures[face].RGBA = texcolor;
  3972. part.UpdateTexture(tex);
  3973. }
  3974. else if (face == -1)
  3975. {
  3976. texcolor = tex.DefaultTexture.RGBA;
  3977. texcolor.A = (float)Math.Abs(alpha - 1);
  3978. tex.DefaultTexture.RGBA = texcolor;
  3979. for (uint i = 0; i < 32; i++)
  3980. {
  3981. if (tex.FaceTextures[i] != null)
  3982. {
  3983. texcolor = tex.FaceTextures[i].RGBA;
  3984. texcolor.A = (float)Math.Abs(alpha - 1);
  3985. tex.FaceTextures[i].RGBA = texcolor;
  3986. }
  3987. }
  3988. texcolor = tex.DefaultTexture.RGBA;
  3989. texcolor.A = (float)Math.Abs(alpha - 1);
  3990. tex.DefaultTexture.RGBA = texcolor;
  3991. part.UpdateTexture(tex);
  3992. }
  3993. }
  3994. return;
  3995. }
  3996. else
  3997. {
  3998. NotImplemented("llSetLinkAlpha");
  3999. }
  4000. }
  4001. public int llGetNumberOfPrims()
  4002. {
  4003. m_host.AddScriptLPS(1);
  4004. return m_host.ParentGroup.PrimCount;
  4005. }
  4006. public string llGetNumberOfNotecardLines(string name)
  4007. {
  4008. m_host.AddScriptLPS(1);
  4009. NotImplemented("llGetNumberOfNotecardLines");
  4010. return String.Empty;
  4011. }
  4012. public LSL_Types.list llGetBoundingBox(string obj)
  4013. {
  4014. m_host.AddScriptLPS(1);
  4015. NotImplemented("llGetBoundingBox");
  4016. return new LSL_Types.list();
  4017. }
  4018. public LSL_Types.Vector3 llGetGeometricCenter()
  4019. {
  4020. return new LSL_Types.Vector3(m_host.GetGeometricCenter().X, m_host.GetGeometricCenter().Y, m_host.GetGeometricCenter().Z);
  4021. }
  4022. public void llGetPrimitiveParams()
  4023. {
  4024. m_host.AddScriptLPS(1);
  4025. NotImplemented("llGetPrimitiveParams");
  4026. }
  4027. // <remarks>
  4028. // <para>
  4029. // The .NET definition of base 64 is:
  4030. // <list>
  4031. // <item>
  4032. // Significant: A-Z a-z 0-9 + -
  4033. // </item>
  4034. // <item>
  4035. // Whitespace: \t \n \r ' '
  4036. // </item>
  4037. // <item>
  4038. // Valueless: =
  4039. // </item>
  4040. // <item>
  4041. // End-of-string: \0 or '=='
  4042. // </item>
  4043. // </list>
  4044. // </para>
  4045. // <para>
  4046. // Each point in a base-64 string represents
  4047. // a 6 bit value. A 32-bit integer can be
  4048. // represented using 6 characters (with some
  4049. // redundancy).
  4050. // </para>
  4051. // <para>
  4052. // LSL requires a base64 string to be 8
  4053. // characters in length. LSL also uses '/'
  4054. // rather than '-' (MIME compliant).
  4055. // </para>
  4056. // <para>
  4057. // RFC 1341 used as a reference (as specified
  4058. // by the SecondLife Wiki).
  4059. // </para>
  4060. // <para>
  4061. // SL do not record any kind of exception for
  4062. // these functions, so the string to integer
  4063. // conversion returns '0' if an invalid
  4064. // character is encountered during conversion.
  4065. // </para>
  4066. // <para>
  4067. // References
  4068. // <list>
  4069. // <item>
  4070. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  4071. // </item>
  4072. // <item>
  4073. // </item>
  4074. // </list>
  4075. // </para>
  4076. // </remarks>
  4077. // <summary>
  4078. // Table for converting 6-bit integers into
  4079. // base-64 characters
  4080. // </summary>
  4081. private static readonly char[] i2ctable =
  4082. {
  4083. 'A','B','C','D','E','F','G','H',
  4084. 'I','J','K','L','M','N','O','P',
  4085. 'Q','R','S','T','U','V','W','X',
  4086. 'Y','Z',
  4087. 'a','b','c','d','e','f','g','h',
  4088. 'i','j','k','l','m','n','o','p',
  4089. 'q','r','s','t','u','v','w','x',
  4090. 'y','z',
  4091. '0','1','2','3','4','5','6','7',
  4092. '8','9',
  4093. '+','/'
  4094. };
  4095. // <summary>
  4096. // Table for converting base-64 characters
  4097. // into 6-bit integers.
  4098. // </summary>
  4099. private static readonly int[] c2itable =
  4100. {
  4101. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  4102. -1,-1,-1,-1,-1,-1,-1,-1,
  4103. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  4104. -1,-1,-1,-1,-1,-1,-1,-1,
  4105. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  4106. -1,-1,-1,63,-1,-1,-1,64,
  4107. 53,54,55,56,57,58,59,60, // 3x
  4108. 61,62,-1,-1,-1,0,-1,-1,
  4109. -1,1,2,3,4,5,6,7, // 4x
  4110. 8,9,10,11,12,13,14,15,
  4111. 16,17,18,19,20,21,22,23, // 5x
  4112. 24,25,26,-1,-1,-1,-1,-1,
  4113. -1,27,28,29,30,31,32,33, // 6x
  4114. 34,35,36,37,38,39,40,41,
  4115. 42,43,44,45,46,47,48,49, // 7x
  4116. 50,51,52,-1,-1,-1,-1,-1,
  4117. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  4118. -1,-1,-1,-1,-1,-1,-1,-1,
  4119. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  4120. -1,-1,-1,-1,-1,-1,-1,-1,
  4121. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  4122. -1,-1,-1,-1,-1,-1,-1,-1,
  4123. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  4124. -1,-1,-1,-1,-1,-1,-1,-1,
  4125. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  4126. -1,-1,-1,-1,-1,-1,-1,-1,
  4127. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  4128. -1,-1,-1,-1,-1,-1,-1,-1,
  4129. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  4130. -1,-1,-1,-1,-1,-1,-1,-1,
  4131. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  4132. -1,-1,-1,-1,-1,-1,-1,-1
  4133. };
  4134. // <summary>
  4135. // Converts a 32-bit integer into a Base64
  4136. // character string. Base64 character strings
  4137. // are always 8 characters long. All iinteger
  4138. // values are acceptable.
  4139. // </summary>
  4140. // <param name="number">
  4141. // 32-bit integer to be converted.
  4142. // </param>
  4143. // <returns>
  4144. // 8 character string. The 1st six characters
  4145. // contain the encoded number, the last two
  4146. // characters are padded with "=".
  4147. // </returns>
  4148. public string llIntegerToBase64(int number)
  4149. {
  4150. // uninitialized string
  4151. char[] imdt = new char[8];
  4152. m_host.AddScriptLPS(1);
  4153. // Manually unroll the loop
  4154. imdt[7] = '=';
  4155. imdt[6] = '=';
  4156. imdt[5] = i2ctable[number<<4 & 0x3F];
  4157. imdt[4] = i2ctable[number>>2 & 0x3F];
  4158. imdt[3] = i2ctable[number>>8 & 0x3F];
  4159. imdt[2] = i2ctable[number>>14 & 0x3F];
  4160. imdt[1] = i2ctable[number>>20 & 0x3F];
  4161. imdt[0] = i2ctable[number>>26 & 0x3F];
  4162. return new string(imdt);
  4163. }
  4164. // <summary>
  4165. // Converts an eight character base-64 string
  4166. // into a 32-bit integer.
  4167. // </summary>
  4168. // <param name="str">
  4169. // 8 characters string to be converted. Other
  4170. // length strings return zero.
  4171. // </param>
  4172. // <returns>
  4173. // Returns an integer representing the
  4174. // encoded value providedint he 1st 6
  4175. // characters of the string.
  4176. // </returns>
  4177. // <remarks>
  4178. // This is coded to behave like LSL's
  4179. // implementation (I think), based upon the
  4180. // information available at the Wiki.
  4181. // If more than 8 characters are supplied,
  4182. // zero is returned.
  4183. // If a NULL string is supplied, zero will
  4184. // be returned.
  4185. // If fewer than 6 characters are supplied, then
  4186. // the answer will reflect a partial
  4187. // accumulation.
  4188. // <para>
  4189. // The 6-bit segments are
  4190. // extracted left-to-right in big-endian mode,
  4191. // which means that segment 6 only contains the
  4192. // two low-order bits of the 32 bit integer as
  4193. // its high order 2 bits. A short string therefore
  4194. // means loss of low-order information. E.g.
  4195. //
  4196. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  4197. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  4198. // |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|
  4199. // |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|
  4200. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  4201. //
  4202. // </para>
  4203. // </remarks>
  4204. public int llBase64ToInteger(string str)
  4205. {
  4206. int number = 0;
  4207. int digit;
  4208. m_host.AddScriptLPS(1);
  4209. // Require a well-fromed base64 string
  4210. if(str.Length > 8)
  4211. return 0;
  4212. // The loop is unrolled in the interests
  4213. // of performance and simple necessity.
  4214. //
  4215. // MUST find 6 digits to be well formed
  4216. // -1 == invalid
  4217. // 0 == padding
  4218. if((digit=c2itable[str[0]])<=0)
  4219. {
  4220. return digit<0?(int)0:number;
  4221. }
  4222. number += --digit<<26;
  4223. if((digit=c2itable[str[1]])<=0)
  4224. {
  4225. return digit<0?(int)0:number;
  4226. }
  4227. number += --digit<<20;
  4228. if((digit=c2itable[str[2]])<=0)
  4229. {
  4230. return digit<0?(int)0:number;
  4231. }
  4232. number += --digit<<14;
  4233. if((digit=c2itable[str[3]])<=0)
  4234. {
  4235. return digit<0?(int)0:number;
  4236. }
  4237. number += --digit<<8;
  4238. if((digit=c2itable[str[4]])<=0)
  4239. {
  4240. return digit<0?(int)0:number;
  4241. }
  4242. number += --digit<<2;
  4243. if((digit=c2itable[str[5]])<=0)
  4244. {
  4245. return digit<0?(int)0:number;
  4246. }
  4247. number += --digit>>4;
  4248. // ignore trailing padding
  4249. return number;
  4250. }
  4251. public double llGetGMTclock()
  4252. {
  4253. m_host.AddScriptLPS(1);
  4254. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  4255. }
  4256. public string llGetSimulatorHostname()
  4257. {
  4258. m_host.AddScriptLPS(1);
  4259. return System.Environment.MachineName;
  4260. }
  4261. public void llSetLocalRot(LSL_Types.Quaternion rot)
  4262. {
  4263. m_host.AddScriptLPS(1);
  4264. m_host.RotationOffset = new LLQuaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
  4265. }
  4266. // <summary>
  4267. // Scan the string supplied in 'src' and
  4268. // tokenize it based upon two sets of
  4269. // tokenizers provided in two lists,
  4270. // separators and spacers.
  4271. // </summary>
  4272. //
  4273. // <remarks>
  4274. // Separators demarcate tokens and are
  4275. // elided as they are encountered. Spacers
  4276. // also demarcate tokens, but are themselves
  4277. // retained as tokens.
  4278. //
  4279. // Both separators and spacers may be arbitrarily
  4280. // long strings. i.e. ":::".
  4281. //
  4282. // The function returns an ordered list
  4283. // representing the tokens found in the supplied
  4284. // sources string. If two successive tokenizers
  4285. // are encountered, then a NULL entry is added
  4286. // to the list.
  4287. //
  4288. // It is a precondition that the source and
  4289. // toekizer lisst are non-null. If they are null,
  4290. // then a null pointer exception will be thrown
  4291. // while their lengths are being determined.
  4292. //
  4293. // A small amount of working memoryis required
  4294. // of approximately 8*#tokenizers.
  4295. //
  4296. // There are many ways in which this function
  4297. // can be implemented, this implementation is
  4298. // fairly naive and assumes that when the
  4299. // function is invooked with a short source
  4300. // string and/or short lists of tokenizers, then
  4301. // performance will not be an issue.
  4302. //
  4303. // In order to minimize the perofrmance
  4304. // effects of long strings, or large numbers
  4305. // of tokeizers, the function skips as far as
  4306. // possible whenever a toekenizer is found,
  4307. // and eliminates redundant tokenizers as soon
  4308. // as is possible.
  4309. //
  4310. // The implementation tries to avoid any copying
  4311. // of arrays or other objects.
  4312. // </remarks>
  4313. public LSL_Types.list llParseStringKeepNulls(string src, LSL_Types.list separators, LSL_Types.list spacers)
  4314. {
  4315. int beginning = 0;
  4316. int srclen = src.Length;
  4317. int seplen = separators.Length;
  4318. object[] separray = separators.Data;
  4319. int spclen = spacers.Length;
  4320. object[] spcarray = spacers.Data;
  4321. int mlen = seplen+spclen;
  4322. int[] offset = new int[mlen+1];
  4323. bool[] active = new bool[mlen];
  4324. int best;
  4325. int j;
  4326. // Initial capacity reduces resize cost
  4327. LSL_Types.list tokens = new LSL_Types.list();
  4328. m_host.AddScriptLPS(1);
  4329. // All entries are initially valid
  4330. for(int i=0; i<mlen; i++) active[i] = true;
  4331. offset[mlen] = srclen;
  4332. while(beginning<srclen)
  4333. {
  4334. best = mlen; // as bad as it gets
  4335. // Scan for separators
  4336. for(j=0; j<seplen; j++)
  4337. {
  4338. if(active[j])
  4339. {
  4340. // scan all of the markers
  4341. if((offset[j] = src.IndexOf((string)separray[j],beginning)) == -1)
  4342. {
  4343. // not present at all
  4344. active[j] = false;
  4345. } else
  4346. {
  4347. // present and correct
  4348. if(offset[j] < offset[best])
  4349. {
  4350. // closest so far
  4351. best = j;
  4352. if(offset[best] == beginning)
  4353. break;
  4354. }
  4355. }
  4356. }
  4357. }
  4358. // Scan for spacers
  4359. if(offset[best] != beginning)
  4360. {
  4361. for(j=seplen; (j<mlen) && (offset[best] > beginning); j++)
  4362. {
  4363. if(active[j])
  4364. {
  4365. // scan all of the markers
  4366. if((offset[j] = src.IndexOf((string)spcarray[j-seplen],beginning)) == -1)
  4367. {
  4368. // not present at all
  4369. active[j] = false;
  4370. } else
  4371. {
  4372. // present and correct
  4373. if(offset[j] < offset[best])
  4374. {
  4375. // closest so far
  4376. best = j;
  4377. }
  4378. }
  4379. }
  4380. }
  4381. }
  4382. // This is the normal exit from the scanning loop
  4383. if(best == mlen)
  4384. {
  4385. // no markers were found on this pass
  4386. // so we're pretty much done
  4387. tokens.Add(src.Substring(beginning, srclen-beginning));
  4388. break;
  4389. }
  4390. // Otherwise we just add the newly delimited token
  4391. // and recalculate where the search should continue.
  4392. tokens.Add(src.Substring(beginning,offset[best]-beginning));
  4393. if(best<seplen)
  4394. {
  4395. beginning = offset[best]+((string)separray[best]).Length;
  4396. } else
  4397. {
  4398. beginning = offset[best]+((string)spcarray[best-seplen]).Length;
  4399. tokens.Add(spcarray[best-seplen]);
  4400. }
  4401. }
  4402. // This an awkward an not very intuitive boundary case. If the
  4403. // last substring is a tokenizer, then there is an implied trailing
  4404. // null list entry. Hopefully the single comparison will not be too
  4405. // arduous. Alternatively the 'break' could be replced with a return
  4406. // but that's shabby programming.
  4407. if(beginning == srclen)
  4408. {
  4409. if(srclen != 0)
  4410. tokens.Add("");
  4411. }
  4412. return tokens;
  4413. }
  4414. public void llRezAtRoot(string inventory, LSL_Types.Vector3 position, LSL_Types.Vector3 velocity,
  4415. LSL_Types.Quaternion rot, int param)
  4416. {
  4417. m_host.AddScriptLPS(1);
  4418. NotImplemented("llRezAtRoot");
  4419. }
  4420. public int llGetObjectPermMask(int mask)
  4421. {
  4422. m_host.AddScriptLPS(1);
  4423. int permmask = 0;
  4424. if (mask == BuiltIn_Commands_BaseClass.MASK_BASE)//0
  4425. {
  4426. permmask = (int)m_host.BaseMask;
  4427. }
  4428. else if (mask == BuiltIn_Commands_BaseClass.MASK_OWNER)//1
  4429. {
  4430. permmask = (int)m_host.OwnerMask;
  4431. }
  4432. else if (mask == BuiltIn_Commands_BaseClass.MASK_GROUP)//2
  4433. {
  4434. permmask = (int)m_host.GroupMask;
  4435. }
  4436. else if (mask == BuiltIn_Commands_BaseClass.MASK_EVERYONE)//3
  4437. {
  4438. permmask = (int)m_host.EveryoneMask;
  4439. }
  4440. else if (mask == BuiltIn_Commands_BaseClass.MASK_NEXT)//4
  4441. {
  4442. permmask = (int)m_host.NextOwnerMask;
  4443. }
  4444. return permmask;
  4445. }
  4446. public void llSetObjectPermMask(int mask, int value)
  4447. {
  4448. m_host.AddScriptLPS(1);
  4449. if (mask == BuiltIn_Commands_BaseClass.MASK_BASE)//0
  4450. {
  4451. m_host.BaseMask = (uint)value;
  4452. }
  4453. else if (mask == BuiltIn_Commands_BaseClass.MASK_OWNER)//1
  4454. {
  4455. m_host.OwnerMask = (uint)value;
  4456. }
  4457. else if (mask == BuiltIn_Commands_BaseClass.MASK_GROUP)//2
  4458. {
  4459. m_host.GroupMask = (uint)value;
  4460. }
  4461. else if (mask == BuiltIn_Commands_BaseClass.MASK_EVERYONE)//3
  4462. {
  4463. m_host.EveryoneMask = (uint)value;
  4464. }
  4465. else if (mask == BuiltIn_Commands_BaseClass.MASK_NEXT)//4
  4466. {
  4467. m_host.NextOwnerMask = (uint)value;
  4468. }
  4469. }
  4470. public int llGetInventoryPermMask(string item, int mask)
  4471. {
  4472. m_host.AddScriptLPS(1);
  4473. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4474. {
  4475. if (inv.Value.Name == item)
  4476. {
  4477. switch (mask)
  4478. {
  4479. case 0:
  4480. return (int)inv.Value.BaseMask;
  4481. case 1:
  4482. return (int)inv.Value.OwnerMask;
  4483. case 2:
  4484. return (int)inv.Value.GroupMask;
  4485. case 3:
  4486. return (int)inv.Value.EveryoneMask;
  4487. case 4:
  4488. return (int)inv.Value.NextOwnerMask;
  4489. }
  4490. }
  4491. }
  4492. return -1;
  4493. }
  4494. public void llSetInventoryPermMask(string item, int mask, int value)
  4495. {
  4496. m_host.AddScriptLPS(1);
  4497. NotImplemented("llSetInventoryPermMask");
  4498. }
  4499. public string llGetInventoryCreator(string item)
  4500. {
  4501. m_host.AddScriptLPS(1);
  4502. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4503. {
  4504. if (inv.Value.Name == item)
  4505. {
  4506. return inv.Value.CreatorID.ToString();
  4507. }
  4508. }
  4509. llSay(0, "No item name '" + item + "'");
  4510. return String.Empty;
  4511. }
  4512. public void llOwnerSay(string msg)
  4513. {
  4514. //m_host.AddScriptLPS(1); // since we reuse llInstantMessage
  4515. //temp fix so that lsl wiki examples aren't annoying to use to test other functions
  4516. //should be similar to : llInstantMessage(llGetOwner(),msg)
  4517. // llGetOwner ==> m_host.ObjectOwner.ToString()
  4518. llInstantMessage(m_host.ObjectOwner.ToString(),msg);
  4519. //World.SimChat(Helpers.StringToField(msg), ChatTypeEnum.Say, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID);
  4520. //IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  4521. //wComm.DeliverMessage(m_host.UUID.ToString(), ChatTypeEnum.Say, 0, m_host.Name, msg);
  4522. }
  4523. public void llRequestSimulatorData(string simulator, int data)
  4524. {
  4525. m_host.AddScriptLPS(1);
  4526. NotImplemented("llRequestSimulatorData");
  4527. }
  4528. public void llForceMouselook(int mouselook)
  4529. {
  4530. m_host.AddScriptLPS(1);
  4531. NotImplemented("llForceMouselook");
  4532. }
  4533. public double llGetObjectMass(string id)
  4534. {
  4535. m_host.AddScriptLPS(1);
  4536. LLUUID key = new LLUUID();
  4537. if (LLUUID.TryParse(id,out key))
  4538. {
  4539. return (double)World.GetSceneObjectPart(World.Entities[key].LocalId).GetMass();
  4540. }
  4541. return 0;
  4542. }
  4543. /// <summary>
  4544. /// illListReplaceList removes the sub-list defined by the inclusive indices
  4545. /// start and end and inserts the src list in its place. The inclusive
  4546. /// nature of the indices means that at least one element must be deleted
  4547. /// if the indices are within the bounds of the existing list. I.e. 2,2
  4548. /// will remove the element at index 2 and replace it with the source
  4549. /// list. Both indices may be negative, with the usual interpretation. An
  4550. /// interesting case is where end is lower than start. As these indices
  4551. /// bound the list to be removed, then 0->end, and start->lim are removed
  4552. /// and the source list is added as a suffix.
  4553. /// </summary>
  4554. public LSL_Types.list llListReplaceList(LSL_Types.list dest, LSL_Types.list src, int start, int end)
  4555. {
  4556. LSL_Types.list pref = null;
  4557. m_host.AddScriptLPS(1);
  4558. // Note that although we have normalized, both
  4559. // indices could still be negative.
  4560. if(start < 0)
  4561. {
  4562. start = start+dest.Length;
  4563. }
  4564. if(end < 0)
  4565. {
  4566. end = end+dest.Length;
  4567. }
  4568. // The comventional case, remove a sequence starting with
  4569. // start and ending with end. And then insert the source
  4570. // list.
  4571. if(start <= end)
  4572. {
  4573. // If greater than zero, then there is going to be a
  4574. // surviving prefix. Otherwise the inclusive nature
  4575. // of the indices mean that we're going to add the
  4576. // source list as a prefix.
  4577. if(start > 0)
  4578. {
  4579. pref = dest.GetSublist(0,start-1);
  4580. // Only add a suffix if there is something
  4581. // beyond the end index (it's inclusive too).
  4582. if(end+1 < dest.Length)
  4583. {
  4584. return pref + src + dest.GetSublist(end+1,-1);
  4585. }
  4586. else
  4587. {
  4588. return pref + src;
  4589. }
  4590. }
  4591. // If start is less than or equal to zero, then
  4592. // the new list is simply a prefix. We still need to
  4593. // figure out any necessary surgery to the destination
  4594. // based upon end. Note that if end exceeds the upper
  4595. // bound in this case, the entire destination list
  4596. // is removed.
  4597. else
  4598. {
  4599. if(end+1 < dest.Length)
  4600. {
  4601. return src + dest.GetSublist(end+1,-1);
  4602. }
  4603. else
  4604. {
  4605. return src;
  4606. }
  4607. }
  4608. }
  4609. // Finally, if start > end, we strip away a prefix and
  4610. // a suffix, to leave the list that sits <between> ens
  4611. // and start, and then tag on the src list. AT least
  4612. // that's my interpretation. We can get sublist to do
  4613. // this for us. Note that one, or both of the indices
  4614. // might have been negative.
  4615. else
  4616. {
  4617. return dest.GetSublist(end+1,start-1)+src;
  4618. }
  4619. }
  4620. public void llLoadURL(string avatar_id, string message, string url)
  4621. {
  4622. m_host.AddScriptLPS(1);
  4623. LLUUID avatarId = new LLUUID(avatar_id);
  4624. m_ScriptEngine.World.SendUrlToUser(avatarId, m_host.Name, m_host.UUID, m_host.ObjectOwner, false, message,
  4625. url);
  4626. }
  4627. public void llParcelMediaCommandList(LSL_Types.list commandList)
  4628. {
  4629. m_host.AddScriptLPS(1);
  4630. NotImplemented("llParcelMediaCommandList");
  4631. }
  4632. public void llParcelMediaQuery()
  4633. {
  4634. m_host.AddScriptLPS(1);
  4635. NotImplemented("llParcelMediaQuery");
  4636. }
  4637. public int llModPow(int a, int b, int c)
  4638. {
  4639. m_host.AddScriptLPS(1);
  4640. Int64 tmp = 0;
  4641. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
  4642. return Convert.ToInt32(tmp);
  4643. }
  4644. public int llGetInventoryType(string name)
  4645. {
  4646. m_host.AddScriptLPS(1);
  4647. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4648. {
  4649. if (inv.Value.Name == name)
  4650. {
  4651. return inv.Value.InvType;
  4652. }
  4653. }
  4654. return -1;
  4655. }
  4656. public void llSetPayPrice(int price, LSL_Types.list quick_pay_buttons)
  4657. {
  4658. m_host.AddScriptLPS(1);
  4659. if(quick_pay_buttons.Data.Length != 4)
  4660. {
  4661. LSLError("List must have 4 elements");
  4662. return;
  4663. }
  4664. m_host.ParentGroup.RootPart.PayPrice[0]=price;
  4665. m_host.ParentGroup.RootPart.PayPrice[1]=(int)quick_pay_buttons.Data[0];
  4666. m_host.ParentGroup.RootPart.PayPrice[2]=(int)quick_pay_buttons.Data[1];
  4667. m_host.ParentGroup.RootPart.PayPrice[3]=(int)quick_pay_buttons.Data[2];
  4668. m_host.ParentGroup.RootPart.PayPrice[4]=(int)quick_pay_buttons.Data[3];
  4669. }
  4670. public LSL_Types.Vector3 llGetCameraPos()
  4671. {
  4672. m_host.AddScriptLPS(1);
  4673. NotImplemented("llGetCameraPos");
  4674. return new LSL_Types.Vector3();
  4675. }
  4676. public LSL_Types.Quaternion llGetCameraRot()
  4677. {
  4678. m_host.AddScriptLPS(1);
  4679. NotImplemented("llGetCameraRot");
  4680. return new LSL_Types.Quaternion();
  4681. }
  4682. public void llSetPrimURL()
  4683. {
  4684. m_host.AddScriptLPS(1);
  4685. NotImplemented("llSetPrimURL");
  4686. }
  4687. public void llRefreshPrimURL()
  4688. {
  4689. m_host.AddScriptLPS(1);
  4690. NotImplemented("llRefreshPrimURL");
  4691. }
  4692. public string llEscapeURL(string url)
  4693. {
  4694. m_host.AddScriptLPS(1);
  4695. try
  4696. {
  4697. return Uri.EscapeUriString(url);
  4698. }
  4699. catch (Exception ex)
  4700. {
  4701. return "llEscapeURL: " + ex.ToString();
  4702. }
  4703. }
  4704. public string llUnescapeURL(string url)
  4705. {
  4706. m_host.AddScriptLPS(1);
  4707. try
  4708. {
  4709. return Uri.UnescapeDataString(url);
  4710. }
  4711. catch (Exception ex)
  4712. {
  4713. return "llUnescapeURL: " + ex.ToString();
  4714. }
  4715. }
  4716. public void llMapDestination(string simname, LSL_Types.Vector3 pos, LSL_Types.Vector3 look_at)
  4717. {
  4718. m_host.AddScriptLPS(1);
  4719. NotImplemented("llMapDestination");
  4720. }
  4721. public void llAddToLandBanList(string avatar, double hours)
  4722. {
  4723. m_host.AddScriptLPS(1);
  4724. LLUUID key;
  4725. LandData land = World.LandChannel.getLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  4726. if (land.ownerID == m_host.OwnerID)
  4727. {
  4728. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  4729. if (LLUUID.TryParse(avatar, out key))
  4730. {
  4731. entry.AgentID = key;
  4732. entry.Flags = ParcelManager.AccessList.Ban;
  4733. entry.Time = DateTime.Now.AddHours(hours);
  4734. land.parcelAccessList.Add(entry);
  4735. }
  4736. }
  4737. }
  4738. public void llRemoveFromLandPassList(string avatar)
  4739. {
  4740. m_host.AddScriptLPS(1);
  4741. LLUUID key;
  4742. LandData land = World.LandChannel.getLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  4743. if (land.ownerID == m_host.OwnerID)
  4744. {
  4745. if (LLUUID.TryParse(avatar, out key))
  4746. {
  4747. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  4748. {
  4749. if (entry.AgentID == key && entry.Flags == ParcelManager.AccessList.Access)
  4750. {
  4751. land.parcelAccessList.Remove(entry);
  4752. break;
  4753. }
  4754. }
  4755. }
  4756. }
  4757. }
  4758. public void llRemoveFromLandBanList(string avatar)
  4759. {
  4760. m_host.AddScriptLPS(1);
  4761. LLUUID key;
  4762. LandData land = World.LandChannel.getLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  4763. if (land.ownerID == m_host.OwnerID)
  4764. {
  4765. if (LLUUID.TryParse(avatar, out key))
  4766. {
  4767. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  4768. {
  4769. if (entry.AgentID == key && entry.Flags == ParcelManager.AccessList.Ban)
  4770. {
  4771. land.parcelAccessList.Remove(entry);
  4772. break;
  4773. }
  4774. }
  4775. }
  4776. }
  4777. }
  4778. public void llSetCameraParams(LSL_Types.list rules)
  4779. {
  4780. m_host.AddScriptLPS(1);
  4781. NotImplemented("llSetCameraParams");
  4782. }
  4783. public void llClearCameraParams()
  4784. {
  4785. m_host.AddScriptLPS(1);
  4786. NotImplemented("llClearCameraParams");
  4787. }
  4788. public double llListStatistics(int operation, LSL_Types.list src)
  4789. {
  4790. m_host.AddScriptLPS(1);
  4791. LSL_Types.list nums = LSL_Types.list.ToDoubleList(src);
  4792. switch (operation)
  4793. {
  4794. case BuiltIn_Commands_BaseClass.LIST_STAT_RANGE:
  4795. return nums.Range();
  4796. case BuiltIn_Commands_BaseClass.LIST_STAT_MIN:
  4797. return nums.Min();
  4798. case BuiltIn_Commands_BaseClass.LIST_STAT_MAX:
  4799. return nums.Max();
  4800. case BuiltIn_Commands_BaseClass.LIST_STAT_MEAN:
  4801. return nums.Mean();
  4802. case BuiltIn_Commands_BaseClass.LIST_STAT_MEDIAN:
  4803. return nums.Median();
  4804. case BuiltIn_Commands_BaseClass.LIST_STAT_NUM_COUNT:
  4805. return nums.NumericLength();
  4806. case BuiltIn_Commands_BaseClass.LIST_STAT_STD_DEV:
  4807. return nums.StdDev();
  4808. case BuiltIn_Commands_BaseClass.LIST_STAT_SUM:
  4809. return nums.Sum();
  4810. case BuiltIn_Commands_BaseClass.LIST_STAT_SUM_SQUARES:
  4811. return nums.SumSqrs();
  4812. case BuiltIn_Commands_BaseClass.LIST_STAT_GEOMETRIC_MEAN:
  4813. return nums.GeometricMean();
  4814. case BuiltIn_Commands_BaseClass.LIST_STAT_HARMONIC_MEAN:
  4815. return nums.HarmonicMean();
  4816. default:
  4817. return 0.0;
  4818. }
  4819. }
  4820. public int llGetUnixTime()
  4821. {
  4822. m_host.AddScriptLPS(1);
  4823. return Util.UnixTimeSinceEpoch();
  4824. }
  4825. public int llGetParcelFlags(LSL_Types.Vector3 pos)
  4826. {
  4827. m_host.AddScriptLPS(1);
  4828. return (int)World.LandChannel.getLandObject((float)pos.x, (float)pos.y).landData.landFlags;
  4829. }
  4830. public int llGetRegionFlags()
  4831. {
  4832. m_host.AddScriptLPS(1);
  4833. return (int)World.RegionInfo.EstateSettings.regionFlags;
  4834. }
  4835. public string llXorBase64StringsCorrect(string str1, string str2)
  4836. {
  4837. m_host.AddScriptLPS(1);
  4838. string ret = String.Empty;
  4839. string src1 = llBase64ToString(str1);
  4840. string src2 = llBase64ToString(str2);
  4841. int c = 0;
  4842. for (int i = 0; i < src1.Length; i++)
  4843. {
  4844. ret += src1[i] ^ src2[c];
  4845. c++;
  4846. if (c > src2.Length)
  4847. c = 0;
  4848. }
  4849. return llStringToBase64(ret);
  4850. }
  4851. public string llHTTPRequest(string url, LSL_Types.list parameters, string body)
  4852. {
  4853. // Partial implementation: support for parameter flags needed
  4854. // see http://wiki.secondlife.com/wiki/LlHTTPRequest
  4855. // parameter flags support are implemented in ScriptsHttpRequests.cs
  4856. // in StartHttpRequest
  4857. m_host.AddScriptLPS(1);
  4858. IHttpRequests httpScriptMod =
  4859. m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>();
  4860. List<string> param = new List<string>();
  4861. foreach (object o in parameters.Data)
  4862. {
  4863. param.Add(o.ToString());
  4864. }
  4865. LLUUID reqID = httpScriptMod.
  4866. StartHttpRequest(m_localID, m_itemID, url, param, body);
  4867. if (reqID != LLUUID.Zero)
  4868. return reqID.ToString();
  4869. else
  4870. return null;
  4871. }
  4872. public void llResetLandBanList()
  4873. {
  4874. m_host.AddScriptLPS(1);
  4875. LandData land = World.LandChannel.getLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  4876. if (land.ownerID == m_host.OwnerID)
  4877. {
  4878. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  4879. {
  4880. if (entry.Flags == ParcelManager.AccessList.Ban)
  4881. {
  4882. land.parcelAccessList.Remove(entry);
  4883. }
  4884. }
  4885. }
  4886. }
  4887. public void llResetLandPassList()
  4888. {
  4889. m_host.AddScriptLPS(1);
  4890. LandData land = World.LandChannel.getLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  4891. if (land.ownerID == m_host.OwnerID)
  4892. {
  4893. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  4894. {
  4895. if (entry.Flags == ParcelManager.AccessList.Access)
  4896. {
  4897. land.parcelAccessList.Remove(entry);
  4898. }
  4899. }
  4900. }
  4901. }
  4902. public int llGetParcelPrimCount(LSL_Types.Vector3 pos, int category, int sim_wide)
  4903. {
  4904. m_host.AddScriptLPS(1);
  4905. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  4906. if(land == null)
  4907. {
  4908. return 0;
  4909. }
  4910. else
  4911. {
  4912. if(sim_wide == 1)
  4913. {
  4914. if (category == 0)
  4915. {
  4916. return land.simwidePrims;
  4917. }
  4918. else
  4919. {
  4920. //public int simwideArea = 0;
  4921. return 0;
  4922. }
  4923. }
  4924. else
  4925. {
  4926. if(category == 0)//Total Prims
  4927. {
  4928. return 0;//land.
  4929. }
  4930. else if(category == 1)//Owner Prims
  4931. {
  4932. return land.ownerPrims;
  4933. }
  4934. else if(category == 2)//Group Prims
  4935. {
  4936. return land.groupPrims;
  4937. }
  4938. else if(category == 3)//Other Prims
  4939. {
  4940. return land.otherPrims;
  4941. }
  4942. else if(category == 4)//Selected
  4943. {
  4944. return land.selectedPrims;
  4945. }
  4946. else if(category == 5)//Temp
  4947. {
  4948. return 0;//land.
  4949. }
  4950. }
  4951. }
  4952. return 0;
  4953. }
  4954. public LSL_Types.list llGetParcelPrimOwners(LSL_Types.Vector3 pos)
  4955. {
  4956. m_host.AddScriptLPS(1);
  4957. LandObject land = (LandObject)World.LandChannel.getLandObject((float)pos.x, (float)pos.y);
  4958. LSL_Types.list ret = new LSL_Types.list();
  4959. if (land != null)
  4960. {
  4961. foreach (KeyValuePair<LLUUID, int> d in land.getLandObjectOwners())
  4962. {
  4963. ret.Add(d.Key.ToString());
  4964. ret.Add(d.Value);
  4965. }
  4966. }
  4967. return ret;
  4968. }
  4969. public int llGetObjectPrimCount(string object_id)
  4970. {
  4971. m_host.AddScriptLPS(1);
  4972. SceneObjectPart part = World.GetSceneObjectPart(new LLUUID(object_id));
  4973. if (part == null)
  4974. {
  4975. return 0;
  4976. }
  4977. else
  4978. {
  4979. return part.ParentGroup.Children.Count;
  4980. }
  4981. }
  4982. public int llGetParcelMaxPrims(LSL_Types.Vector3 pos, int sim_wide)
  4983. {
  4984. m_host.AddScriptLPS(1);
  4985. // Alondria: This currently just is utilizing the normal grid's 0.22 prims/m2 calculation
  4986. // Which probably will be irrelevent in OpenSim....
  4987. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  4988. float bonusfactor = World.RegionInfo.EstateSettings.objectBonusFactor;
  4989. if (land == null)
  4990. {
  4991. return 0;
  4992. }
  4993. if (sim_wide == 1)
  4994. {
  4995. decimal v = land.simwideArea * (decimal)(0.22) * (decimal)bonusfactor;
  4996. return (int)v;
  4997. }
  4998. else
  4999. {
  5000. decimal v = land.area * (decimal)(0.22) * (decimal)bonusfactor;
  5001. return (int)v;
  5002. }
  5003. }
  5004. public LSL_Types.list llGetParcelDetails(LSL_Types.Vector3 pos, LSL_Types.list param)
  5005. {
  5006. m_host.AddScriptLPS(1);
  5007. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  5008. if (land == null)
  5009. {
  5010. return new LSL_Types.list(0);
  5011. }
  5012. LSL_Types.list ret = new LSL_Types.list();
  5013. foreach (object o in param.Data)
  5014. {
  5015. switch (o.ToString())
  5016. {
  5017. case "0":
  5018. ret = ret + new LSL_Types.list(land.landName);
  5019. break;
  5020. case "1":
  5021. ret = ret + new LSL_Types.list(land.landDesc);
  5022. break;
  5023. case "2":
  5024. ret = ret + new LSL_Types.list(land.ownerID.ToString());
  5025. break;
  5026. case "3":
  5027. ret = ret + new LSL_Types.list(land.groupID.ToString());
  5028. break;
  5029. case "4":
  5030. ret = ret + new LSL_Types.list(land.area);
  5031. break;
  5032. default:
  5033. ret = ret + new LSL_Types.list(0);
  5034. break;
  5035. }
  5036. }
  5037. return ret;
  5038. }
  5039. public string llStringTrim(string src, int type)
  5040. {
  5041. m_host.AddScriptLPS(1);
  5042. if (type == (int)BuiltIn_Commands_BaseClass.STRING_TRIM_HEAD) { return src.TrimStart(); }
  5043. if (type == (int)BuiltIn_Commands_BaseClass.STRING_TRIM_TAIL) { return src.TrimEnd(); }
  5044. if (type == (int)BuiltIn_Commands_BaseClass.STRING_TRIM) { return src.Trim(); }
  5045. return src;
  5046. }
  5047. public LSL_Types.list llGetObjectDetails(string id, LSL_Types.list args)
  5048. {
  5049. m_host.AddScriptLPS(1);
  5050. LSL_Types.list ret = new LSL_Types.list();
  5051. LLUUID key = new LLUUID();
  5052. if (LLUUID.TryParse(id, out key))
  5053. {
  5054. if (World.m_innerScene.ScenePresences.ContainsKey(key))
  5055. {
  5056. ScenePresence av = World.m_innerScene.ScenePresences[key];
  5057. foreach(object o in args.Data)
  5058. {
  5059. switch(o.ToString())
  5060. {
  5061. case "1":
  5062. ret.Add(av.Firstname + " " + av.Lastname);
  5063. break;
  5064. case "2":
  5065. ret.Add("");
  5066. break;
  5067. case "3":
  5068. ret.Add(new LSL_Types.Vector3((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z));
  5069. break;
  5070. case "4":
  5071. ret.Add(new LSL_Types.Quaternion((double)av.Rotation.x, (double)av.Rotation.y, (double)av.Rotation.z, (double)av.Rotation.w));
  5072. break;
  5073. case "5":
  5074. ret.Add(new LSL_Types.Vector3(av.Velocity.X,av.Velocity.Y,av.Velocity.Z));
  5075. break;
  5076. case "6":
  5077. ret.Add(id);
  5078. break;
  5079. case "7":
  5080. ret.Add(LLUUID.Zero.ToString());
  5081. break;
  5082. case "8":
  5083. ret.Add(LLUUID.Zero.ToString());
  5084. break;
  5085. }
  5086. }
  5087. return ret;
  5088. }
  5089. SceneObjectPart obj = World.GetSceneObjectPart(key);
  5090. if (obj != null)
  5091. {
  5092. foreach(object o in args.Data)
  5093. {
  5094. switch(o.ToString())
  5095. {
  5096. case "1":
  5097. ret.Add(obj.Name);
  5098. break;
  5099. case "2":
  5100. ret.Add(obj.Description);
  5101. break;
  5102. case "3":
  5103. ret.Add(new LSL_Types.Vector3(obj.AbsolutePosition.X,obj.AbsolutePosition.Y,obj.AbsolutePosition.Z));
  5104. break;
  5105. case "4":
  5106. ret.Add(new LSL_Types.Quaternion(obj.RotationOffset.X, obj.RotationOffset.Y, obj.RotationOffset.Z, obj.RotationOffset.W));
  5107. break;
  5108. case "5":
  5109. ret.Add(new LSL_Types.Vector3(obj.Velocity.X, obj.Velocity.Y, obj.Velocity.Z));
  5110. break;
  5111. case "6":
  5112. ret.Add(obj.OwnerID.ToString());
  5113. break;
  5114. case "7":
  5115. ret.Add(obj.GroupID.ToString());
  5116. break;
  5117. case "8":
  5118. ret.Add(obj.CreatorID.ToString());
  5119. break;
  5120. }
  5121. }
  5122. return ret;
  5123. }
  5124. }
  5125. return new LSL_Types.list();
  5126. }
  5127. internal LLUUID ScriptByName(string name)
  5128. {
  5129. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  5130. {
  5131. if (item.Type == 10 && item.Name == name)
  5132. return item.ItemID;
  5133. }
  5134. return LLUUID.Zero;
  5135. }
  5136. internal void ShoutError(string msg)
  5137. {
  5138. llShout(BuiltIn_Commands_BaseClass.DEBUG_CHANNEL, msg);
  5139. }
  5140. internal void NotImplemented(string command)
  5141. {
  5142. if (throwErrorOnNotImplemented)
  5143. throw new NotImplementedException("Command not implemented: " + command);
  5144. }
  5145. internal void Deprecated(string command)
  5146. {
  5147. throw new Exception("Command deprecated: " + command);
  5148. }
  5149. internal void LSLError(string msg)
  5150. {
  5151. throw new Exception("LSL Runtime Error: " + msg);
  5152. }
  5153. }
  5154. }