LSL_BuiltIn_Commands.cs 175 KB

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