OSSL_Api.cs 194 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Reflection;
  32. using System.Runtime.Remoting.Lifetime;
  33. using System.Text;
  34. using System.Net;
  35. using System.Threading;
  36. using System.Xml;
  37. using log4net;
  38. using OpenMetaverse;
  39. using OpenMetaverse.StructuredData;
  40. using Nini.Config;
  41. using OpenSim;
  42. using OpenSim.Framework;
  43. using OpenSim.Framework.Console;
  44. using OpenSim.Region.Framework.Interfaces;
  45. using OpenSim.Region.Framework.Scenes;
  46. using OpenSim.Region.Framework.Scenes.Scripting;
  47. using OpenSim.Region.ScriptEngine.Shared;
  48. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  49. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  50. using OpenSim.Region.ScriptEngine.Interfaces;
  51. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  52. using TPFlags = OpenSim.Framework.Constants.TeleportFlags;
  53. using OpenSim.Services.Interfaces;
  54. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  55. using System.Text.RegularExpressions;
  56. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  57. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  58. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  59. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  60. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  61. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  62. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  63. using PermissionMask = OpenSim.Framework.PermissionMask;
  64. using OpenSim.Services.Connectors.Hypergrid;
  65. namespace OpenSim.Region.ScriptEngine.Shared.Api
  66. {
  67. //////////////////////////////////////////////////////////////
  68. //
  69. // Level description
  70. //
  71. // None - Function is no threat at all. It doesn't constitute
  72. // an threat to either users or the system and has no
  73. // known side effects
  74. //
  75. // Nuisance - Abuse of this command can cause a nuisance to the
  76. // region operator, such as log message spew
  77. //
  78. // VeryLow - Extreme levels ob abuse of this function can cause
  79. // impaired functioning of the region, or very gullible
  80. // users can be tricked into experiencing harmless effects
  81. //
  82. // Low - Intentional abuse can cause crashes or malfunction
  83. // under certain circumstances, which can easily be rectified,
  84. // or certain users can be tricked into certain situations
  85. // in an avoidable manner.
  86. //
  87. // Moderate - Intentional abuse can cause denial of service and crashes
  88. // with potential of data or state loss, or trusting users
  89. // can be tricked into embarrassing or uncomfortable
  90. // situationsa.
  91. //
  92. // High - Casual abuse can cause impaired functionality or temporary
  93. // denial of service conditions. Intentional abuse can easily
  94. // cause crashes with potential data loss, or can be used to
  95. // trick experienced and cautious users into unwanted situations,
  96. // or changes global data permanently and without undo ability
  97. // Malicious scripting can allow theft of content
  98. //
  99. // VeryHigh - Even normal use may, depending on the number of instances,
  100. // or frequency of use, result in severe service impairment
  101. // or crash with loss of data, or can be used to cause
  102. // unwanted or harmful effects on users without giving the
  103. // user a means to avoid it.
  104. //
  105. // Severe - Even casual use is a danger to region stability, or function
  106. // allows console or OS command execution, or function allows
  107. // taking money without consent, or allows deletion or
  108. // modification of user data, or allows the compromise of
  109. // sensitive data by design.
  110. class FunctionPerms
  111. {
  112. public List<UUID> AllowedCreators;
  113. public List<UUID> AllowedOwners;
  114. public List<string> AllowedOwnerClasses;
  115. public FunctionPerms()
  116. {
  117. AllowedCreators = new List<UUID>();
  118. AllowedOwners = new List<UUID>();
  119. AllowedOwnerClasses = new List<string>();
  120. }
  121. }
  122. [Serializable]
  123. public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
  124. {
  125. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  126. public const string GridInfoServiceConfigSectionName = "GridInfoService";
  127. internal IScriptEngine m_ScriptEngine;
  128. internal LSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there
  129. internal SceneObjectPart m_host;
  130. internal TaskInventoryItem m_item;
  131. internal bool m_OSFunctionsEnabled = false;
  132. internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
  133. internal float m_ScriptDelayFactor = 1.0f;
  134. internal float m_ScriptDistanceFactor = 1.0f;
  135. internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
  136. protected IUrlModule m_UrlModule = null;
  137. protected ISoundModule m_SoundModule = null;
  138. internal IConfig m_osslconfig;
  139. public void Initialize(
  140. IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
  141. {
  142. m_ScriptEngine = scriptEngine;
  143. m_host = host;
  144. m_item = item;
  145. m_osslconfig = m_ScriptEngine.ConfigSource.Configs["OSSL"];
  146. if(m_osslconfig == null)
  147. m_osslconfig = m_ScriptEngine.Config;
  148. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  149. m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>();
  150. if (m_osslconfig.GetBoolean("AllowOSFunctions", false))
  151. {
  152. m_OSFunctionsEnabled = true;
  153. // m_log.Warn("[OSSL] OSSL FUNCTIONS ENABLED");
  154. }
  155. m_ScriptDelayFactor =
  156. m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
  157. m_ScriptDistanceFactor =
  158. m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
  159. string risk = m_osslconfig.GetString("OSFunctionThreatLevel", "VeryLow");
  160. switch (risk)
  161. {
  162. case "NoAccess":
  163. m_MaxThreatLevel = ThreatLevel.NoAccess;
  164. break;
  165. case "None":
  166. m_MaxThreatLevel = ThreatLevel.None;
  167. break;
  168. case "VeryLow":
  169. m_MaxThreatLevel = ThreatLevel.VeryLow;
  170. break;
  171. case "Low":
  172. m_MaxThreatLevel = ThreatLevel.Low;
  173. break;
  174. case "Moderate":
  175. m_MaxThreatLevel = ThreatLevel.Moderate;
  176. break;
  177. case "High":
  178. m_MaxThreatLevel = ThreatLevel.High;
  179. break;
  180. case "VeryHigh":
  181. m_MaxThreatLevel = ThreatLevel.VeryHigh;
  182. break;
  183. case "Severe":
  184. m_MaxThreatLevel = ThreatLevel.Severe;
  185. break;
  186. default:
  187. break;
  188. }
  189. }
  190. public override Object InitializeLifetimeService()
  191. {
  192. ILease lease = (ILease)base.InitializeLifetimeService();
  193. if (lease.CurrentState == LeaseState.Initial)
  194. {
  195. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  196. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  197. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  198. }
  199. return lease;
  200. }
  201. public Scene World
  202. {
  203. get { return m_ScriptEngine.World; }
  204. }
  205. internal void OSSLError(string msg)
  206. {
  207. throw new ScriptException("OSSL Runtime Error: " + msg);
  208. }
  209. /// <summary>
  210. /// Initialize the LSL interface.
  211. /// </summary>
  212. /// <remarks>
  213. /// FIXME: This is an abomination. We should be able to set this up earlier but currently we have no
  214. /// guarantee the interface is present on Initialize(). There needs to be another post initialize call from
  215. /// ScriptInstance.
  216. /// </remarks>
  217. private void InitLSL()
  218. {
  219. if (m_LSL_Api != null)
  220. return;
  221. m_LSL_Api = (LSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "LSL");
  222. }
  223. //
  224. //Dumps an error message on the debug console.
  225. //
  226. internal void OSSLShoutError(string message)
  227. {
  228. if (message.Length > 1023)
  229. message = message.Substring(0, 1023);
  230. World.SimChat(Utils.StringToBytes(message),
  231. ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  232. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  233. if(wComm != null)
  234. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
  235. }
  236. // Returns if OSSL is enabled. Throws a script exception if OSSL is not allowed..
  237. // for safe funtions always active
  238. public void CheckThreatLevel()
  239. {
  240. m_host.AddScriptLPS(1);
  241. if (!m_OSFunctionsEnabled)
  242. OSSLError("permission denied. All OS functions are disabled."); // throws
  243. }
  244. // Returns if the function is allowed. Throws a script exception if not allowed.
  245. public void CheckThreatLevel(ThreatLevel level, string function)
  246. {
  247. m_host.AddScriptLPS(1);
  248. if (!m_OSFunctionsEnabled)
  249. OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); // throws
  250. string reasonWhyNot = CheckThreatLevelTest(level, function);
  251. if (!String.IsNullOrEmpty(reasonWhyNot))
  252. {
  253. OSSLError(reasonWhyNot);
  254. }
  255. }
  256. // Check to see if function is allowed. Returns an empty string if function permitted
  257. // or a string explaining why this function can't be used.
  258. private string CheckThreatLevelTest(ThreatLevel level, string function)
  259. {
  260. if (!m_FunctionPerms.ContainsKey(function))
  261. {
  262. FunctionPerms perms = new FunctionPerms();
  263. m_FunctionPerms[function] = perms;
  264. string ownerPerm = m_osslconfig.GetString("Allow_" + function, "");
  265. string creatorPerm = m_osslconfig.GetString("Creators_" + function, "");
  266. if (ownerPerm == "" && creatorPerm == "")
  267. {
  268. // Default behavior
  269. perms.AllowedOwners = null;
  270. perms.AllowedCreators = null;
  271. perms.AllowedOwnerClasses = null;
  272. }
  273. else
  274. {
  275. bool allowed;
  276. if (bool.TryParse(ownerPerm, out allowed))
  277. {
  278. // Boolean given
  279. if (allowed)
  280. {
  281. // Allow globally
  282. perms.AllowedOwners.Add(UUID.Zero);
  283. }
  284. }
  285. else
  286. {
  287. string[] ids = ownerPerm.Split(new char[] {','});
  288. foreach (string id in ids)
  289. {
  290. string current = id.Trim();
  291. if (current.ToUpper() == "PARCEL_GROUP_MEMBER" || current.ToUpper() == "PARCEL_OWNER" || current.ToUpper() == "ESTATE_MANAGER" || current.ToUpper() == "ESTATE_OWNER" || current.ToUpper() == "ACTIVE_GOD" || current.ToUpper() == "GRID_GOD" || current.ToUpper() == "GOD")
  292. {
  293. if (!perms.AllowedOwnerClasses.Contains(current))
  294. perms.AllowedOwnerClasses.Add(current.ToUpper());
  295. }
  296. else
  297. {
  298. UUID uuid;
  299. if (UUID.TryParse(current, out uuid))
  300. {
  301. if (uuid != UUID.Zero)
  302. perms.AllowedOwners.Add(uuid);
  303. }
  304. }
  305. }
  306. ids = creatorPerm.Split(new char[] {','});
  307. foreach (string id in ids)
  308. {
  309. string current = id.Trim();
  310. UUID uuid;
  311. if (UUID.TryParse(current, out uuid))
  312. {
  313. if (uuid != UUID.Zero)
  314. perms.AllowedCreators.Add(uuid);
  315. }
  316. }
  317. }
  318. }
  319. }
  320. // If the list is null, then the value was true / undefined
  321. // Threat level governs permissions in this case
  322. //
  323. // If the list is non-null, then it is a list of UUIDs allowed
  324. // to use that particular function. False causes an empty
  325. // list and therefore means "no one"
  326. //
  327. // To allow use by anyone, the list contains UUID.Zero
  328. //
  329. if (m_FunctionPerms[function].AllowedOwners == null)
  330. {
  331. // Allow / disallow by threat level
  332. if (level > m_MaxThreatLevel)
  333. return
  334. String.Format(
  335. "{0} permission denied. Allowed threat level is {1} but function threat level is {2}.",
  336. function, m_MaxThreatLevel, level);
  337. }
  338. else
  339. {
  340. if (!m_FunctionPerms[function].AllowedOwners.Contains(UUID.Zero))
  341. {
  342. // Not anyone. Do detailed checks
  343. if (m_FunctionPerms[function].AllowedOwners.Contains(m_host.OwnerID))
  344. {
  345. // prim owner is in the list of allowed owners
  346. return String.Empty;
  347. }
  348. UUID ownerID = m_item.OwnerID;
  349. //OSSL only may be used if object is in the same group as the parcel
  350. if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_GROUP_MEMBER"))
  351. {
  352. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  353. if (land.LandData.GroupID == m_item.GroupID && land.LandData.GroupID != UUID.Zero)
  354. {
  355. return String.Empty;
  356. }
  357. }
  358. //Only Parcelowners may use the function
  359. if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_OWNER"))
  360. {
  361. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  362. if (land.LandData.OwnerID == ownerID)
  363. {
  364. return String.Empty;
  365. }
  366. }
  367. //Only Estate Managers may use the function
  368. if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_MANAGER"))
  369. {
  370. //Only Estate Managers may use the function
  371. if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID)
  372. {
  373. return String.Empty;
  374. }
  375. }
  376. //Only regionowners may use the function
  377. if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_OWNER"))
  378. {
  379. if (World.RegionInfo.EstateSettings.EstateOwner == ownerID)
  380. {
  381. return String.Empty;
  382. }
  383. }
  384. //Only grid gods may use the function
  385. if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("GRID_GOD"))
  386. {
  387. if (World.Permissions.IsGridGod(ownerID))
  388. {
  389. return String.Empty;
  390. }
  391. }
  392. //Any god may use the function
  393. if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("GOD"))
  394. {
  395. if (World.Permissions.IsAdministrator(ownerID))
  396. {
  397. return String.Empty;
  398. }
  399. }
  400. //Only active gods may use the function
  401. if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ACTIVE_GOD"))
  402. {
  403. ScenePresence sp = World.GetScenePresence(ownerID);
  404. if (sp != null && !sp.IsDeleted && sp.IsGod)
  405. {
  406. return String.Empty;
  407. }
  408. }
  409. if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID))
  410. return(
  411. String.Format("{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission.",
  412. function));
  413. if (m_item.CreatorID != ownerID)
  414. {
  415. if ((m_item.CurrentPermissions & (uint)PermissionMask.Modify) != 0)
  416. return String.Format("{0} permission denied. Script permissions error.", function);
  417. }
  418. }
  419. }
  420. return String.Empty;
  421. }
  422. internal void OSSLDeprecated(string function, string replacement)
  423. {
  424. OSSLShoutError(string.Format("Use of function {0} is deprecated. Use {1} instead.", function, replacement));
  425. }
  426. protected void ScriptSleep(int delay)
  427. {
  428. delay = (int)(delay * m_ScriptDelayFactor);
  429. if (delay < 10)
  430. return;
  431. if(m_item != null)
  432. m_ScriptEngine.SleepScript(m_item.ItemID, delay);
  433. else
  434. Thread.Sleep(delay);
  435. }
  436. public LSL_Integer osSetTerrainHeight(int x, int y, double val)
  437. {
  438. CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight");
  439. return SetTerrainHeight(x, y, val);
  440. }
  441. public LSL_Integer osTerrainSetHeight(int x, int y, double val)
  442. {
  443. CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight");
  444. OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight");
  445. return SetTerrainHeight(x, y, val);
  446. }
  447. private LSL_Integer SetTerrainHeight(int x, int y, double val)
  448. {
  449. if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
  450. OSSLError("osSetTerrainHeight: Coordinate out of bounds");
  451. if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0)))
  452. {
  453. World.Heightmap[x, y] = val;
  454. return 1;
  455. }
  456. else
  457. {
  458. return 0;
  459. }
  460. }
  461. public LSL_Float osGetTerrainHeight(int x, int y)
  462. {
  463. CheckThreatLevel();
  464. return GetTerrainHeight(x, y);
  465. }
  466. public LSL_Float osTerrainGetHeight(int x, int y)
  467. {
  468. CheckThreatLevel();
  469. OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight");
  470. return GetTerrainHeight(x, y);
  471. }
  472. private LSL_Float GetTerrainHeight(int x, int y)
  473. {
  474. if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
  475. OSSLError("osGetTerrainHeight: Coordinate out of bounds");
  476. return World.Heightmap[x, y];
  477. }
  478. public void osTerrainFlush()
  479. {
  480. CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush");
  481. ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
  482. if (terrainModule != null) terrainModule.TaintTerrain();
  483. }
  484. public int osRegionRestart(double seconds)
  485. {
  486. // This is High here because region restart is not reliable
  487. // it may result in the region staying down or becoming
  488. // unstable. This should be changed to Low or VeryLow once
  489. // The underlying functionality is fixed, since the security
  490. // as such is sound
  491. //
  492. CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
  493. IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
  494. if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
  495. {
  496. if (seconds < 15)
  497. {
  498. restartModule.AbortRestart("Region restart has been aborted\n");
  499. return 1;
  500. }
  501. RegionRestart(seconds, String.Empty);
  502. return 1;
  503. }
  504. else
  505. {
  506. return 0;
  507. }
  508. }
  509. public int osRegionRestart(double seconds, string msg)
  510. {
  511. CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
  512. IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
  513. if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
  514. {
  515. if (seconds < 15)
  516. {
  517. restartModule.AbortRestart("Region restart has been aborted\n");
  518. return 1;
  519. }
  520. RegionRestart(seconds, msg);
  521. return 1;
  522. }
  523. else
  524. {
  525. return 0;
  526. }
  527. }
  528. private void RegionRestart(double seconds, string msg)
  529. {
  530. IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
  531. List<int> times = new List<int>();
  532. while (seconds > 0)
  533. {
  534. times.Add((int)seconds);
  535. if (seconds > 300)
  536. seconds -= 120;
  537. else if (seconds > 120)
  538. seconds -= 60;
  539. else if (seconds > 60)
  540. seconds -= 30;
  541. else
  542. seconds -= 15;
  543. }
  544. if (msg == String.Empty)
  545. restartModule.ScheduleRestart(UUID.Zero, "Region: " + World.RegionInfo.RegionName + " is about to restart.\n\nIf you stay here you will be logged out.\n\n\nTime remaining: {0}.\n", times.ToArray(), true);
  546. else
  547. restartModule.ScheduleRestart(UUID.Zero, msg + "\n\nTime remaining: {0}.\n", times.ToArray(), true);
  548. }
  549. public void osRegionNotice(string msg)
  550. {
  551. CheckThreatLevel(ThreatLevel.High, "osRegionNotice");
  552. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  553. if (dm == null)
  554. return;
  555. if (!World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false))
  556. return;
  557. dm.SendGeneralAlert(msg + "\n");
  558. }
  559. public void osRegionNotice(LSL_Key agentID, string msg)
  560. {
  561. CheckThreatLevel(ThreatLevel.High, "osRegionNotice");
  562. if (!World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false))
  563. return;
  564. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  565. if (dm == null)
  566. return;
  567. UUID avatarID;
  568. if (!UUID.TryParse(agentID, out avatarID))
  569. return;
  570. ScenePresence sp = null;
  571. if (!World.TryGetScenePresence(avatarID, out sp))
  572. return;
  573. if (sp == null || sp.IsChildAgent || sp.IsDeleted || sp.IsInTransit || sp.IsNPC)
  574. return;
  575. dm.SendAlertToUser(sp.ControllingClient, msg + "\n", false);
  576. }
  577. public void osSetRot(UUID target, Quaternion rotation)
  578. {
  579. // This function has no security. It can be used to destroy
  580. // arbitrary builds the user would normally have no rights to
  581. //
  582. CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot");
  583. if (World.Entities.ContainsKey(target))
  584. {
  585. EntityBase entity;
  586. if (World.Entities.TryGetValue(target, out entity))
  587. {
  588. if (entity is SceneObjectGroup)
  589. ((SceneObjectGroup)entity).UpdateGroupRotationR(rotation);
  590. else if (entity is ScenePresence)
  591. ((ScenePresence)entity).Rotation = rotation;
  592. }
  593. }
  594. else
  595. {
  596. OSSLError("osSetRot: Invalid target");
  597. }
  598. }
  599. public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
  600. int timer)
  601. {
  602. // This may be upgraded depending on the griefing or DOS
  603. // potential, or guarded with a delay
  604. //
  605. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURL");
  606. if (dynamicID == String.Empty)
  607. {
  608. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  609. UUID createdTexture =
  610. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  611. extraParams);
  612. return createdTexture.ToString();
  613. }
  614. else
  615. {
  616. //TODO update existing dynamic textures
  617. }
  618. return UUID.Zero.ToString();
  619. }
  620. public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
  621. int timer, int alpha)
  622. {
  623. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlend");
  624. if (dynamicID == String.Empty)
  625. {
  626. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  627. UUID createdTexture =
  628. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  629. extraParams, true, (byte) alpha);
  630. return createdTexture.ToString();
  631. }
  632. else
  633. {
  634. //TODO update existing dynamic textures
  635. }
  636. return UUID.Zero.ToString();
  637. }
  638. public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams,
  639. bool blend, int disp, int timer, int alpha, int face)
  640. {
  641. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlendFace");
  642. if (dynamicID == String.Empty)
  643. {
  644. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  645. UUID createdTexture =
  646. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  647. extraParams, blend, disp, (byte) alpha, face);
  648. return createdTexture.ToString();
  649. }
  650. else
  651. {
  652. //TODO update existing dynamic textures
  653. }
  654. return UUID.Zero.ToString();
  655. }
  656. public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
  657. int timer)
  658. {
  659. return osSetDynamicTextureDataFace(dynamicID, contentType, data, extraParams, timer, -1);
  660. }
  661. public string osSetDynamicTextureDataFace(string dynamicID, string contentType, string data, string extraParams,
  662. int timer, int face)
  663. {
  664. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureData");
  665. if (dynamicID == String.Empty)
  666. {
  667. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  668. if (textureManager != null)
  669. {
  670. if (extraParams == String.Empty)
  671. {
  672. extraParams = "256";
  673. }
  674. UUID createdTexture =
  675. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  676. extraParams, false, 3, 255, face);
  677. return createdTexture.ToString();
  678. }
  679. }
  680. else
  681. {
  682. //TODO update existing dynamic textures
  683. }
  684. return UUID.Zero.ToString();
  685. }
  686. public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
  687. int timer, int alpha)
  688. {
  689. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlend");
  690. if (dynamicID == String.Empty)
  691. {
  692. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  693. if (textureManager != null)
  694. {
  695. if (extraParams == String.Empty)
  696. {
  697. extraParams = "256";
  698. }
  699. UUID createdTexture =
  700. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  701. extraParams, true, (byte) alpha);
  702. return createdTexture.ToString();
  703. }
  704. }
  705. else
  706. {
  707. //TODO update existing dynamic textures
  708. }
  709. return UUID.Zero.ToString();
  710. }
  711. public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams,
  712. bool blend, int disp, int timer, int alpha, int face)
  713. {
  714. CheckThreatLevel(ThreatLevel.VeryLow , "osSetDynamicTextureDataBlendFace");
  715. if (dynamicID == String.Empty)
  716. {
  717. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  718. if (textureManager != null)
  719. {
  720. if (extraParams == String.Empty)
  721. {
  722. extraParams = "256";
  723. }
  724. UUID createdTexture =
  725. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  726. extraParams, blend, disp, (byte) alpha, face);
  727. return createdTexture.ToString();
  728. }
  729. }
  730. else
  731. {
  732. //TODO update existing dynamic textures
  733. }
  734. return UUID.Zero.ToString();
  735. }
  736. public bool osConsoleCommand(string command)
  737. {
  738. CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand");
  739. // For safety, we add another permission check here, and don't rely only on the standard OSSL permissions
  740. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  741. {
  742. MainConsole.Instance.RunCommand(command);
  743. return true;
  744. }
  745. return false;
  746. }
  747. public void osSetPrimFloatOnWater(int floatYN)
  748. {
  749. CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater");
  750. m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
  751. }
  752. private bool checkAllowAgentTPbyLandOwner(UUID agentId, Vector3 pos)
  753. {
  754. UUID hostOwner = m_host.OwnerID;
  755. if(hostOwner == agentId)
  756. return true;
  757. if (m_item.PermsGranter == agentId)
  758. {
  759. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  760. return true;
  761. }
  762. ILandObject land = World.LandChannel.GetLandObject(pos);
  763. if(land == null)
  764. return true;
  765. LandData landdata = land.LandData;
  766. if(landdata == null)
  767. return true;
  768. if(landdata.OwnerID == hostOwner)
  769. return true;
  770. EstateSettings es = World.RegionInfo.EstateSettings;
  771. if(es != null && es.IsEstateManagerOrOwner(hostOwner))
  772. return true;
  773. if(!landdata.IsGroupOwned)
  774. return false;
  775. UUID landGroup = landdata.GroupID;
  776. if(landGroup == UUID.Zero)
  777. return false;
  778. if(landGroup == m_host.GroupID)
  779. return true;
  780. return false;
  781. }
  782. // Teleport functions
  783. public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  784. {
  785. // High because there is no security check. High griefer potential
  786. //
  787. CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
  788. TeleportAgent(agent, regionName, position, lookat);
  789. }
  790. private void TeleportAgent(string agent, string regionName,
  791. LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  792. {
  793. if(String.IsNullOrEmpty(regionName))
  794. regionName = World.RegionInfo.RegionName;
  795. UUID agentId;
  796. if (UUID.TryParse(agent, out agentId))
  797. {
  798. ScenePresence presence = World.GetScenePresence(agentId);
  799. if (presence == null || presence.IsDeleted || presence.IsInTransit)
  800. return;
  801. Vector3 pos = presence.AbsolutePosition;
  802. if(!checkAllowAgentTPbyLandOwner(agentId, pos))
  803. {
  804. ScriptSleep(500);
  805. return;
  806. }
  807. if(regionName == World.RegionInfo.RegionName)
  808. {
  809. // should be faster than going to threadpool
  810. World.RequestTeleportLocation(presence.ControllingClient, regionName, position,
  811. lookat, (uint)TPFlags.ViaLocation);
  812. ScriptSleep(500);
  813. }
  814. else
  815. {
  816. // We will launch the teleport on a new thread so that when the script threads are terminated
  817. // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
  818. Util.FireAndForget(
  819. o => World.RequestTeleportLocation(
  820. presence.ControllingClient, regionName, position,
  821. lookat, (uint)TPFlags.ViaLocation),
  822. null, "OSSL_Api.TeleportAgentByRegionCoords");
  823. ScriptSleep(5000);
  824. }
  825. }
  826. }
  827. public void osTeleportAgent(string agent, int regionGridX, int regionGridY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  828. {
  829. // High because there is no security check. High griefer potential
  830. //
  831. CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
  832. TeleportAgent(agent, regionGridX, regionGridY, position, lookat);
  833. }
  834. private void TeleportAgent(string agent, int regionGridX, int regionGridY,
  835. LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  836. {
  837. ulong regionHandle = Util.RegionGridLocToHandle((uint)regionGridX, (uint)regionGridY);
  838. UUID agentId;
  839. if (UUID.TryParse(agent, out agentId))
  840. {
  841. ScenePresence presence = World.GetScenePresence(agentId);
  842. if (presence == null || presence.IsDeleted || presence.IsInTransit)
  843. return;
  844. Vector3 pos = presence.AbsolutePosition;
  845. if(!checkAllowAgentTPbyLandOwner(agentId, pos))
  846. {
  847. ScriptSleep(500);
  848. return;
  849. }
  850. Util.FireAndForget(
  851. o => World.RequestTeleportLocation(
  852. presence.ControllingClient, regionHandle,
  853. position, lookat, (uint)TPFlags.ViaLocation),
  854. null, "OSSL_Api.TeleportAgentByRegionName");
  855. ScriptSleep(5000);
  856. }
  857. }
  858. public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  859. {
  860. UUID agentId;
  861. if (UUID.TryParse(agent, out agentId))
  862. {
  863. ScenePresence presence = World.GetScenePresence(agentId);
  864. if (presence == null || presence.IsDeleted || presence.IsInTransit)
  865. return;
  866. Vector3 pos = presence.AbsolutePosition;
  867. if(!checkAllowAgentTPbyLandOwner(agentId, pos))
  868. {
  869. ScriptSleep(500);
  870. return;
  871. }
  872. World.RequestTeleportLocation(presence.ControllingClient, World.RegionInfo.RegionName, position,
  873. lookat, (uint)TPFlags.ViaLocation);
  874. ScriptSleep(500);
  875. }
  876. }
  877. public void osTeleportOwner(string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  878. {
  879. // Threat level None because this is what can already be done with the World Map in the viewer
  880. CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
  881. TeleportAgent(m_host.OwnerID.ToString(), regionName, position, lookat);
  882. }
  883. public void osTeleportOwner(int regionGridX, int regionGridY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  884. {
  885. CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
  886. TeleportAgent(m_host.OwnerID.ToString(), regionGridX, regionGridY, position, lookat);
  887. }
  888. public void osTeleportOwner(LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  889. {
  890. CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
  891. osTeleportAgent(m_host.OwnerID.ToString(), position, lookat);
  892. }
  893. ///<summary>
  894. /// Allows a script IN the target prim to force an avatar to sit on it using normal methods
  895. /// as if called by the client.
  896. /// Silent fail if agent (or target if overloaded) not found.
  897. /// Does work if passed key (or keys if overloaded).
  898. /// </summary>
  899. /// <param name="avatar"></param>
  900. public void osForceOtherSit(string avatar)
  901. {
  902. CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
  903. ForceSit(avatar, m_host.UUID);
  904. }
  905. /// <summary>
  906. /// Overload method of osForceOtherSit(string avatar) to allow a script NOT in the target prim to force
  907. /// an avatar to sit on the target prim using normal methods as if called by the client.
  908. /// </summary>
  909. /// <param name="avatar"></param>
  910. /// <param name="target"></param>
  911. public void osForceOtherSit(string avatar, string target)
  912. {
  913. CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
  914. UUID targetID = new UUID(target);
  915. ForceSit(avatar, targetID);
  916. }
  917. public void ForceSit(string avatar, UUID targetID)
  918. {
  919. UUID agentID;
  920. if (!UUID.TryParse(avatar, out agentID))
  921. return;
  922. ScenePresence presence = World.GetScenePresence(agentID);
  923. SceneObjectPart part = World.GetSceneObjectPart(targetID);
  924. if (presence != null &&
  925. part != null &&
  926. part.SitTargetAvatar == UUID.Zero)
  927. presence.HandleAgentRequestSit(presence.ControllingClient,
  928. agentID,
  929. targetID,
  930. part.SitTargetPosition);
  931. }
  932. // Get a list of all the avatars/agents in the region
  933. public LSL_List osGetAgents()
  934. {
  935. // threat level is None as we could get this information with an
  936. // in-world script as well, just not as efficient
  937. CheckThreatLevel(ThreatLevel.None, "osGetAgents");
  938. LSL_List result = new LSL_List();
  939. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  940. {
  941. result.Add(new LSL_String(sp.Name));
  942. });
  943. return result;
  944. }
  945. public string osGetAgentIP(string agent)
  946. {
  947. CheckThreatLevel(ThreatLevel.Severe, "osGetAgentIP");
  948. if(!(World.Permissions.IsGod(m_host.OwnerID))) // user god always needed
  949. return "";
  950. UUID avatarID = (UUID)agent;
  951. if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence)
  952. {
  953. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  954. return target.ControllingClient.RemoteEndPoint.Address.ToString();
  955. }
  956. // fall through case, just return nothing
  957. return "";
  958. }
  959. // Adam's super super custom animation functions
  960. public void osAvatarPlayAnimation(LSL_Key avatar, string animation)
  961. {
  962. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation");
  963. UUID avatarID;
  964. if(!UUID.TryParse(avatar, out avatarID))
  965. return;
  966. ScenePresence target = World.GetScenePresence(avatarID);
  967. if (target == null)
  968. return;
  969. UUID animID = UUID.Zero;
  970. m_host.TaskInventory.LockItemsForRead(true);
  971. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  972. {
  973. if (inv.Value.Type == (int)AssetType.Animation)
  974. {
  975. if (inv.Value.Name == animation)
  976. {
  977. animID = inv.Value.AssetID;
  978. break;
  979. }
  980. }
  981. }
  982. m_host.TaskInventory.LockItemsForRead(false);
  983. if (animID == UUID.Zero)
  984. target.Animator.AddAnimation(animation, m_host.UUID);
  985. else
  986. target.Animator.AddAnimation(animID, m_host.UUID);
  987. }
  988. public void osAvatarStopAnimation(LSL_Key avatar, string animation)
  989. {
  990. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation");
  991. UUID avatarID;
  992. if(!UUID.TryParse(avatar, out avatarID))
  993. return;
  994. ScenePresence target = World.GetScenePresence(avatarID);
  995. if (target == null)
  996. return;
  997. UUID animID;
  998. if (!UUID.TryParse(animation, out animID))
  999. {
  1000. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation);
  1001. if (item != null && item.Type == (int)AssetType.Animation)
  1002. animID = item.AssetID;
  1003. else
  1004. animID = UUID.Zero;
  1005. }
  1006. if (animID == UUID.Zero)
  1007. target.Animator.RemoveAnimation(animation);
  1008. else
  1009. target.Animator.RemoveAnimation(animID, true);
  1010. }
  1011. //Texture draw functions
  1012. public string osDrawResetTransform(string drawList)
  1013. {
  1014. CheckThreatLevel();
  1015. drawList += "ResetTransf;";
  1016. return drawList;
  1017. }
  1018. public string osDrawRotationTransform(string drawList, LSL_Float x)
  1019. {
  1020. CheckThreatLevel();
  1021. drawList += "RotTransf " + x + ";";
  1022. return drawList;
  1023. }
  1024. public string osDrawScaleTransform(string drawList, LSL_Float x, LSL_Float y)
  1025. {
  1026. CheckThreatLevel();
  1027. drawList += "ScaleTransf " + x + "," + y + ";";
  1028. return drawList;
  1029. }
  1030. public string osDrawTranslationTransform(string drawList, LSL_Float x, LSL_Float y)
  1031. {
  1032. CheckThreatLevel();
  1033. drawList += "TransTransf " + x + "," + y + ";";
  1034. return drawList;
  1035. }
  1036. public string osMovePen(string drawList, int x, int y)
  1037. {
  1038. CheckThreatLevel();
  1039. drawList += "MoveTo " + x + "," + y + ";";
  1040. return drawList;
  1041. }
  1042. public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
  1043. {
  1044. CheckThreatLevel();
  1045. drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
  1046. return drawList;
  1047. }
  1048. public string osDrawLine(string drawList, int endX, int endY)
  1049. {
  1050. CheckThreatLevel();
  1051. drawList += "LineTo " + endX + "," + endY + "; ";
  1052. return drawList;
  1053. }
  1054. public string osDrawText(string drawList, string text)
  1055. {
  1056. CheckThreatLevel(ThreatLevel.None, "osDrawText");
  1057. drawList += "Text " + text + "; ";
  1058. return drawList;
  1059. }
  1060. public string osDrawEllipse(string drawList, int width, int height)
  1061. {
  1062. CheckThreatLevel();
  1063. drawList += "Ellipse " + width + "," + height + "; ";
  1064. return drawList;
  1065. }
  1066. public string osDrawFilledEllipse(string drawList, int width, int height)
  1067. {
  1068. CheckThreatLevel();
  1069. drawList += "FillEllipse " + width + "," + height + "; ";
  1070. return drawList;
  1071. }
  1072. public string osDrawRectangle(string drawList, int width, int height)
  1073. {
  1074. CheckThreatLevel();
  1075. drawList += "Rectangle " + width + "," + height + "; ";
  1076. return drawList;
  1077. }
  1078. public string osDrawFilledRectangle(string drawList, int width, int height)
  1079. {
  1080. CheckThreatLevel();
  1081. drawList += "FillRectangle " + width + "," + height + "; ";
  1082. return drawList;
  1083. }
  1084. public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
  1085. {
  1086. CheckThreatLevel();
  1087. if (x.Length != y.Length || x.Length < 3)
  1088. {
  1089. return "";
  1090. }
  1091. drawList += "FillPolygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  1092. for (int i = 1; i < x.Length; i++)
  1093. {
  1094. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  1095. }
  1096. drawList += "; ";
  1097. return drawList;
  1098. }
  1099. public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
  1100. {
  1101. CheckThreatLevel();
  1102. if (x.Length != y.Length || x.Length < 3)
  1103. {
  1104. return "";
  1105. }
  1106. drawList += "Polygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  1107. for (int i = 1; i < x.Length; i++)
  1108. {
  1109. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  1110. }
  1111. drawList += "; ";
  1112. return drawList;
  1113. }
  1114. public string osSetFontSize(string drawList, int fontSize)
  1115. {
  1116. CheckThreatLevel();
  1117. drawList += "FontSize "+ fontSize +"; ";
  1118. return drawList;
  1119. }
  1120. public string osSetFontName(string drawList, string fontName)
  1121. {
  1122. CheckThreatLevel();
  1123. drawList += "FontName "+ fontName +"; ";
  1124. return drawList;
  1125. }
  1126. public string osSetPenSize(string drawList, int penSize)
  1127. {
  1128. CheckThreatLevel();
  1129. drawList += "PenSize " + penSize + "; ";
  1130. return drawList;
  1131. }
  1132. public string osSetPenColor(string drawList, string color)
  1133. {
  1134. CheckThreatLevel();
  1135. drawList += "PenColor " + color + "; ";
  1136. return drawList;
  1137. }
  1138. // Deprecated
  1139. public string osSetPenColour(string drawList, string colour)
  1140. {
  1141. CheckThreatLevel();
  1142. OSSLDeprecated("osSetPenColour", "osSetPenColor");
  1143. drawList += "PenColour " + colour + "; ";
  1144. return drawList;
  1145. }
  1146. public string osSetPenCap(string drawList, string direction, string type)
  1147. {
  1148. CheckThreatLevel();
  1149. drawList += "PenCap " + direction + "," + type + "; ";
  1150. return drawList;
  1151. }
  1152. public string osDrawImage(string drawList, int width, int height, string imageUrl)
  1153. {
  1154. CheckThreatLevel();
  1155. drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
  1156. return drawList;
  1157. }
  1158. public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
  1159. {
  1160. CheckThreatLevel();
  1161. LSL_Vector vec = new LSL_Vector(0,0,0);
  1162. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  1163. if (textureManager != null)
  1164. {
  1165. double xSize, ySize;
  1166. textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
  1167. out xSize, out ySize);
  1168. vec.x = xSize;
  1169. vec.y = ySize;
  1170. }
  1171. return vec;
  1172. }
  1173. public void osSetStateEvents(int events)
  1174. {
  1175. // This function is a hack. There is no reason for it's existence
  1176. // anymore, since state events now work properly.
  1177. // It was probably added as a crutch or debugging aid, and
  1178. // should be removed
  1179. //
  1180. CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
  1181. m_host.SetScriptEvents(m_item.ItemID, events);
  1182. }
  1183. public void osSetRegionWaterHeight(double height)
  1184. {
  1185. CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
  1186. World.EventManager.TriggerRequestChangeWaterHeight((float)height);
  1187. }
  1188. /// <summary>
  1189. /// Changes the Region Sun Settings, then Triggers a Sun Update
  1190. /// </summary>
  1191. /// <param name="useEstateSun">True to use Estate Sun instead of Region Sun</param>
  1192. /// <param name="sunFixed">True to keep the sun stationary</param>
  1193. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  1194. public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
  1195. {
  1196. CheckThreatLevel(ThreatLevel.High, "osSetRegionSunSettings");
  1197. while (sunHour > 24.0)
  1198. sunHour -= 24.0;
  1199. while (sunHour < 0)
  1200. sunHour += 24.0;
  1201. World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
  1202. World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
  1203. World.RegionInfo.RegionSettings.FixedSun = sunFixed;
  1204. World.RegionInfo.RegionSettings.Save();
  1205. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
  1206. }
  1207. /// <summary>
  1208. /// Changes the Estate Sun Settings, then Triggers a Sun Update
  1209. /// </summary>
  1210. /// <param name="sunFixed">True to keep the sun stationary, false to use global time</param>
  1211. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  1212. public void osSetEstateSunSettings(bool sunFixed, double sunHour)
  1213. {
  1214. CheckThreatLevel(ThreatLevel.High, "osSetEstateSunSettings");
  1215. while (sunHour > 24.0)
  1216. sunHour -= 24.0;
  1217. while (sunHour < 0)
  1218. sunHour += 24.0;
  1219. World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
  1220. World.RegionInfo.EstateSettings.SunPosition = sunHour;
  1221. World.RegionInfo.EstateSettings.FixedSun = sunFixed;
  1222. World.EstateDataService.StoreEstateSettings(World.RegionInfo.EstateSettings);
  1223. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
  1224. }
  1225. /// <summary>
  1226. /// Return the current Sun Hour 0...24, with 0 being roughly sun-rise
  1227. /// </summary>
  1228. /// <returns></returns>
  1229. public double osGetCurrentSunHour()
  1230. {
  1231. CheckThreatLevel();
  1232. // Must adjust for the fact that Region Sun Settings are still LL offset
  1233. double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6;
  1234. // See if the sun module has registered itself, if so it's authoritative
  1235. ISunModule module = World.RequestModuleInterface<ISunModule>();
  1236. if (module != null)
  1237. {
  1238. sunHour = module.GetCurrentSunHour();
  1239. }
  1240. return sunHour;
  1241. }
  1242. public double osSunGetParam(string param)
  1243. {
  1244. CheckThreatLevel(ThreatLevel.None, "osSunGetParam");
  1245. OSSLDeprecated("osSunGetParam", "osGetSunParam");
  1246. return GetSunParam(param);
  1247. }
  1248. public double osGetSunParam(string param)
  1249. {
  1250. CheckThreatLevel();
  1251. return GetSunParam(param);
  1252. }
  1253. private double GetSunParam(string param)
  1254. {
  1255. double value = 0.0;
  1256. ISunModule module = World.RequestModuleInterface<ISunModule>();
  1257. if (module != null)
  1258. {
  1259. value = module.GetSunParameter(param);
  1260. }
  1261. return value;
  1262. }
  1263. public void osSunSetParam(string param, double value)
  1264. {
  1265. CheckThreatLevel(ThreatLevel.None, "osSunSetParam");
  1266. OSSLDeprecated("osSunSetParam", "osSetSunParam");
  1267. SetSunParam(param, value);
  1268. }
  1269. public void osSetSunParam(string param, double value)
  1270. {
  1271. CheckThreatLevel(ThreatLevel.None, "osSetSunParam");
  1272. SetSunParam(param, value);
  1273. }
  1274. private void SetSunParam(string param, double value)
  1275. {
  1276. ISunModule module = World.RequestModuleInterface<ISunModule>();
  1277. if (module != null)
  1278. {
  1279. module.SetSunParameter(param, value);
  1280. }
  1281. }
  1282. public string osWindActiveModelPluginName()
  1283. {
  1284. CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
  1285. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1286. if (module != null)
  1287. {
  1288. return module.WindActiveModelPluginName;
  1289. }
  1290. return String.Empty;
  1291. }
  1292. public void osSetWindParam(string plugin, string param, LSL_Float value)
  1293. {
  1294. CheckThreatLevel(ThreatLevel.VeryLow, "osSetWindParam");
  1295. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1296. if (module != null)
  1297. {
  1298. try
  1299. {
  1300. module.WindParamSet(plugin, param, (float)value);
  1301. }
  1302. catch (Exception) { }
  1303. }
  1304. }
  1305. public LSL_Float osGetWindParam(string plugin, string param)
  1306. {
  1307. CheckThreatLevel(ThreatLevel.VeryLow, "osGetWindParam");
  1308. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1309. if (module != null)
  1310. {
  1311. return module.WindParamGet(plugin, param);
  1312. }
  1313. return 0.0f;
  1314. }
  1315. // Routines for creating and managing parcels programmatically
  1316. public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
  1317. {
  1318. CheckThreatLevel(ThreatLevel.High, "osParcelJoin");
  1319. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1320. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1321. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1322. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1323. World.LandChannel.Join(startx,starty,endx,endy,m_host.OwnerID);
  1324. }
  1325. public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
  1326. {
  1327. CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide");
  1328. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1329. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1330. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1331. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1332. World.LandChannel.Subdivide(startx,starty,endx,endy,m_host.OwnerID);
  1333. }
  1334. public void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
  1335. {
  1336. const string functionName = "osParcelSetDetails";
  1337. CheckThreatLevel(ThreatLevel.High, functionName);
  1338. OSSLDeprecated(functionName, "osSetParcelDetails");
  1339. SetParcelDetails(pos, rules, functionName);
  1340. }
  1341. public void osSetParcelDetails(LSL_Vector pos, LSL_List rules)
  1342. {
  1343. const string functionName = "osSetParcelDetails";
  1344. CheckThreatLevel(ThreatLevel.High, functionName);
  1345. SetParcelDetails(pos, rules, functionName);
  1346. }
  1347. private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName)
  1348. {
  1349. // Get a reference to the land data and make sure the owner of the script
  1350. // can modify it
  1351. ILandObject startLandObject = World.LandChannel.GetLandObject((int)pos.x, (int)pos.y);
  1352. if (startLandObject == null)
  1353. {
  1354. OSSLShoutError("There is no land at that location");
  1355. return;
  1356. }
  1357. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions, false))
  1358. {
  1359. OSSLShoutError("script owner does not have permission to modify the parcel");
  1360. return;
  1361. }
  1362. // Create a new land data object we can modify
  1363. LandData newLand = startLandObject.LandData.Copy();
  1364. UUID uuid;
  1365. EstateSettings es = World.RegionInfo.EstateSettings;
  1366. bool changed = false;
  1367. bool changedSeeAvs = false;
  1368. bool changedoverlay = false;
  1369. bool changedneedupdate = false;
  1370. // Process the rules, not sure what the impact would be of changing owner or group
  1371. for (int idx = 0; idx < rules.Length;)
  1372. {
  1373. int code = rules.GetLSLIntegerItem(idx++);
  1374. string arg = rules.GetLSLStringItem(idx++);
  1375. switch (code)
  1376. {
  1377. case ScriptBaseClass.PARCEL_DETAILS_NAME:
  1378. if(newLand.Name != arg)
  1379. {
  1380. newLand.Name = arg;
  1381. changed = true;
  1382. }
  1383. break;
  1384. case ScriptBaseClass.PARCEL_DETAILS_DESC:
  1385. if(newLand.Description != arg)
  1386. {
  1387. newLand.Description = arg;
  1388. changed = true;
  1389. }
  1390. break;
  1391. case ScriptBaseClass.PARCEL_DETAILS_OWNER:
  1392. if(es != null && !es.IsEstateManagerOrOwner(m_host.OwnerID))
  1393. {
  1394. OSSLShoutError("script owner does not have permission to modify the parcel owner");
  1395. }
  1396. else
  1397. {
  1398. if (UUID.TryParse(arg, out uuid))
  1399. {
  1400. if(newLand.OwnerID != uuid)
  1401. {
  1402. changed = true;
  1403. newLand.OwnerID = uuid;
  1404. newLand.GroupID = UUID.Zero;
  1405. }
  1406. }
  1407. }
  1408. break;
  1409. case ScriptBaseClass.PARCEL_DETAILS_GROUP:
  1410. if(m_host.OwnerID == newLand.OwnerID || es == null || es.IsEstateManagerOrOwner(m_host.OwnerID))
  1411. {
  1412. if (UUID.TryParse(arg, out uuid))
  1413. {
  1414. if(newLand.GroupID != uuid)
  1415. {
  1416. if(uuid == UUID.Zero)
  1417. {
  1418. changed = true;
  1419. newLand.GroupID = uuid;
  1420. }
  1421. else
  1422. {
  1423. IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
  1424. GroupMembershipData member = null;
  1425. if (groupsModule != null)
  1426. member = groupsModule.GetMembershipData(uuid, newLand.OwnerID);
  1427. if (member == null)
  1428. OSSLShoutError(string.Format("land owner is not member of the new group for parcel"));
  1429. else
  1430. {
  1431. changed = true;
  1432. newLand.GroupID = uuid;
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. else
  1439. {
  1440. OSSLShoutError("script owner does not have permission to modify the parcel group");
  1441. }
  1442. break;
  1443. case ScriptBaseClass.PARCEL_DETAILS_CLAIMDATE:
  1444. if(es != null && !es.IsEstateManagerOrOwner(m_host.OwnerID))
  1445. {
  1446. OSSLShoutError("script owner does not have permission to modify the parcel CLAIM DATE");
  1447. }
  1448. else
  1449. {
  1450. int date = Convert.ToInt32(arg);
  1451. if (date == 0)
  1452. date = Util.UnixTimeSinceEpoch();
  1453. if(newLand.ClaimDate != date)
  1454. {
  1455. changed = true;
  1456. newLand.ClaimDate = date;
  1457. }
  1458. }
  1459. break;
  1460. case ScriptBaseClass.PARCEL_DETAILS_SEE_AVATARS:
  1461. bool newavs = (Convert.ToInt32(arg) != 0);
  1462. if(newLand.SeeAVs != newavs)
  1463. {
  1464. changed = true;
  1465. changedSeeAvs = true;
  1466. changedoverlay = true;
  1467. changedneedupdate = true;
  1468. newLand.SeeAVs = newavs;
  1469. }
  1470. break;
  1471. case ScriptBaseClass.PARCEL_DETAILS_ANY_AVATAR_SOUNDS:
  1472. bool newavsounds = (Convert.ToInt32(arg) != 0);
  1473. if(newLand.AnyAVSounds != newavsounds)
  1474. {
  1475. changed = true;
  1476. newLand.AnyAVSounds = newavsounds;
  1477. }
  1478. break;
  1479. case ScriptBaseClass.PARCEL_DETAILS_GROUP_SOUNDS:
  1480. bool newgrpsounds = (Convert.ToInt32(arg) != 0);
  1481. if(newLand.GroupAVSounds != newgrpsounds)
  1482. {
  1483. changed = true;
  1484. newLand.GroupAVSounds = newgrpsounds;
  1485. }
  1486. break;
  1487. }
  1488. }
  1489. if(changed)
  1490. {
  1491. World.LandChannel.UpdateLandObject(newLand.LocalID, newLand);
  1492. if(changedneedupdate)
  1493. {
  1494. UUID parcelID= newLand.GlobalID;
  1495. World.ForEachRootScenePresence(delegate (ScenePresence avatar)
  1496. {
  1497. if (avatar == null || avatar.IsDeleted || avatar.IsInTransit)
  1498. return;
  1499. if(changedSeeAvs && avatar.currentParcelUUID == parcelID )
  1500. avatar.currentParcelUUID = parcelID; // force parcel flags review
  1501. if(avatar.ControllingClient == null)
  1502. return;
  1503. // this will be needed for some things like damage etc
  1504. // if(avatar.currentParcelUUID == parcelID)
  1505. // startLandObject.SendLandUpdateToClient(avatar.ControllingClient);
  1506. if(changedoverlay && !avatar.IsNPC)
  1507. World.LandChannel.SendParcelsOverlay(avatar.ControllingClient);
  1508. });
  1509. }
  1510. }
  1511. }
  1512. public void osSetParcelMediaURL(string url)
  1513. {
  1514. // What actually is the difference to the LL function?
  1515. //
  1516. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
  1517. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  1518. if (land.LandData.OwnerID != m_host.OwnerID)
  1519. return;
  1520. land.SetMediaUrl(url);
  1521. }
  1522. public void osSetParcelSIPAddress(string SIPAddress)
  1523. {
  1524. // What actually is the difference to the LL function?
  1525. //
  1526. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelSIPAddress");
  1527. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  1528. if (land.LandData.OwnerID != m_host.OwnerID)
  1529. {
  1530. OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function");
  1531. return;
  1532. }
  1533. // get the voice module
  1534. IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>();
  1535. if (voiceModule != null)
  1536. voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID);
  1537. else
  1538. OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
  1539. }
  1540. public string osGetScriptEngineName()
  1541. {
  1542. // This gets a "high" because knowing the engine may be used
  1543. // to exploit engine-specific bugs or induce usage patterns
  1544. // that trigger engine-specific failures.
  1545. // Besides, public grid users aren't supposed to know.
  1546. //
  1547. CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName");
  1548. int scriptEngineNameIndex = 0;
  1549. if (!String.IsNullOrEmpty(m_ScriptEngine.ScriptEngineName))
  1550. {
  1551. // parse off the "ScriptEngine."
  1552. scriptEngineNameIndex = m_ScriptEngine.ScriptEngineName.IndexOf(".", scriptEngineNameIndex);
  1553. scriptEngineNameIndex++; // get past delimiter
  1554. int scriptEngineNameLength = m_ScriptEngine.ScriptEngineName.Length - scriptEngineNameIndex;
  1555. // create char array then a string that is only the script engine name
  1556. Char[] scriptEngineNameCharArray = m_ScriptEngine.ScriptEngineName.ToCharArray(scriptEngineNameIndex, scriptEngineNameLength);
  1557. String scriptEngineName = new String(scriptEngineNameCharArray);
  1558. return scriptEngineName;
  1559. }
  1560. else
  1561. {
  1562. return String.Empty;
  1563. }
  1564. }
  1565. public LSL_Integer osCheckODE()
  1566. {
  1567. CheckThreatLevel();
  1568. LSL_Integer ret = 0; // false
  1569. if (m_ScriptEngine.World.PhysicsScene != null)
  1570. {
  1571. string physEngine = m_ScriptEngine.World.PhysicsScene.EngineType;
  1572. if (physEngine == "OpenDynamicsEngine")
  1573. {
  1574. ret = 1; // true
  1575. }
  1576. }
  1577. return ret;
  1578. }
  1579. public string osGetPhysicsEngineType()
  1580. {
  1581. // High because it can be used to target attacks to known weaknesses
  1582. // This would allow a new class of griefer scripts that don't even
  1583. // require their user to know what they are doing (see script
  1584. // kiddie)
  1585. // Because it would be nice if scripts didn't blow up if the information
  1586. // about the physics engine, this function returns an empty string if
  1587. // the user does not have permission to see it. This as opposed to
  1588. // throwing an exception.
  1589. m_host.AddScriptLPS(1);
  1590. string ret = String.Empty;
  1591. if (String.IsNullOrEmpty(CheckThreatLevelTest(ThreatLevel.High, "osGetPhysicsEngineType")))
  1592. {
  1593. if (m_ScriptEngine.World.PhysicsScene != null)
  1594. {
  1595. ret = m_ScriptEngine.World.PhysicsScene.EngineType;
  1596. // An old physics engine might have an uninitialized engine type
  1597. if (ret == null)
  1598. ret = "unknown";
  1599. }
  1600. }
  1601. return ret;
  1602. }
  1603. public string osGetPhysicsEngineName()
  1604. {
  1605. CheckThreatLevel();
  1606. string ret = "NoEngine";
  1607. if (m_ScriptEngine.World.PhysicsScene != null)
  1608. {
  1609. ret = m_ScriptEngine.World.PhysicsScene.EngineName;
  1610. // An old physics engine might have an uninitialized engine type
  1611. if (ret == null)
  1612. ret = "UnknownEngine";
  1613. }
  1614. return ret;
  1615. }
  1616. public string osGetSimulatorVersion()
  1617. {
  1618. // High because it can be used to target attacks to known weaknesses
  1619. // This would allow a new class of griefer scripts that don't even
  1620. // require their user to know what they are doing (see script
  1621. // kiddie)
  1622. //
  1623. CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion");
  1624. return m_ScriptEngine.World.GetSimulatorVersion();
  1625. }
  1626. /// <summary>
  1627. /// Send a message to to object identified by the given UUID
  1628. /// </summary>
  1629. /// <remarks>
  1630. /// A script in the object must implement the dataserver function
  1631. /// the dataserver function is passed the ID of the calling function and a string message
  1632. /// </remarks>
  1633. /// <param name="objectUUID"></param>
  1634. /// <param name="message"></param>
  1635. public void osMessageObject(LSL_Key objectUUID, string message)
  1636. {
  1637. CheckThreatLevel(ThreatLevel.Low, "osMessageObject");
  1638. UUID objUUID;
  1639. if (!UUID.TryParse(objectUUID, out objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead.
  1640. {
  1641. OSSLShoutError("osMessageObject() cannot send messages to objects with invalid UUIDs");
  1642. return;
  1643. }
  1644. MessageObject(objUUID, message);
  1645. }
  1646. private void MessageObject(UUID objUUID, string message)
  1647. {
  1648. object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) };
  1649. SceneObjectPart sceneOP = World.GetSceneObjectPart(objUUID);
  1650. if (sceneOP == null) // prior to patching, PostObjectEvent() would cause a throw exception to be shouted instead.
  1651. {
  1652. OSSLShoutError("osMessageObject() cannot send message to " + objUUID.ToString() + ", object was not found in scene.");
  1653. return;
  1654. }
  1655. m_ScriptEngine.PostObjectEvent(
  1656. sceneOP.LocalId, new EventParams(
  1657. "dataserver", resobj, new DetectParams[0]));
  1658. }
  1659. /// <summary>
  1660. /// Similar to llDie but given an object UUID
  1661. /// </summary>
  1662. /// <param name="objectUUID"></param>
  1663. public void osDie(LSL_Key objectUUID)
  1664. {
  1665. // CheckThreatLevel(ThreatLevel.VeryHigh, "osDie");
  1666. // if this is restricted to objects rezzed by this host level can be reduced
  1667. CheckThreatLevel(ThreatLevel.Low, "osDie");
  1668. UUID objUUID;
  1669. if (!UUID.TryParse(objectUUID, out objUUID))
  1670. {
  1671. OSSLShoutError("osDie() cannot delete objects with invalid UUIDs");
  1672. return;
  1673. }
  1674. InitLSL();
  1675. // harakiri check
  1676. if(objUUID == UUID.Zero)
  1677. {
  1678. if (!m_host.ParentGroup.IsAttachment)
  1679. m_LSL_Api.llDie();
  1680. return;
  1681. }
  1682. SceneObjectGroup sceneOG = World.GetSceneObjectGroup(objUUID);
  1683. if (sceneOG == null || sceneOG.IsDeleted)
  1684. return;
  1685. if(sceneOG.IsAttachment)
  1686. return;
  1687. if (sceneOG.OwnerID != m_host.OwnerID)
  1688. return;
  1689. // harakiri check
  1690. if(sceneOG.UUID == m_host.ParentGroup.UUID)
  1691. {
  1692. m_LSL_Api.llDie();
  1693. return;
  1694. }
  1695. // restrict to objects rezzed by host
  1696. if(sceneOG.RezzerID == m_host.ParentGroup.UUID)
  1697. World.DeleteSceneObject(sceneOG, false);
  1698. }
  1699. /// <summary>
  1700. /// Write a notecard directly to the prim's inventory.
  1701. /// </summary>
  1702. /// <remarks>
  1703. /// This needs ThreatLevel high. It is an excellent griefer tool,
  1704. /// In a loop, it can cause asset bloat and DOS levels of asset
  1705. /// writes.
  1706. /// </remarks>
  1707. /// <param name="notecardName">The name of the notecard to write.</param>
  1708. /// <param name="contents">The contents of the notecard.</param>
  1709. public void osMakeNotecard(string notecardName, LSL_Types.list contents)
  1710. {
  1711. CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
  1712. StringBuilder notecardData = new StringBuilder();
  1713. for (int i = 0; i < contents.Length; i++)
  1714. notecardData.Append((string)(contents.GetLSLStringItem(i) + "\n"));
  1715. SaveNotecard(notecardName, "Script generated notecard", notecardData.ToString(), false);
  1716. }
  1717. /// <summary>
  1718. /// Save a notecard to prim inventory.
  1719. /// </summary>
  1720. /// <param name="name"></param>
  1721. /// <param name="description">Description of notecard</param>
  1722. /// <param name="notecardData"></param>
  1723. /// <param name="forceSameName">
  1724. /// If true, then if an item exists with the same name, it is replaced.
  1725. /// If false, then a new item is created witha slightly different name (e.g. name 1)
  1726. /// </param>
  1727. /// <returns>Prim inventory item created.</returns>
  1728. protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName)
  1729. {
  1730. // Create new asset
  1731. AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
  1732. asset.Description = description;
  1733. byte[] a;
  1734. byte[] b;
  1735. byte[] c;
  1736. b = Util.UTF8.GetBytes(data);
  1737. a = Util.UTF8.GetBytes(
  1738. "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " + b.Length.ToString() + "\n");
  1739. c = Util.UTF8.GetBytes("}");
  1740. byte[] d = new byte[a.Length + b.Length + c.Length];
  1741. Buffer.BlockCopy(a, 0, d, 0, a.Length);
  1742. Buffer.BlockCopy(b, 0, d, a.Length, b.Length);
  1743. Buffer.BlockCopy(c, 0, d, a.Length + b.Length, c.Length);
  1744. asset.Data = d;
  1745. World.AssetService.Store(asset);
  1746. // Create Task Entry
  1747. TaskInventoryItem taskItem = new TaskInventoryItem();
  1748. taskItem.ResetIDs(m_host.UUID);
  1749. taskItem.ParentID = m_host.UUID;
  1750. taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
  1751. taskItem.Name = name;
  1752. taskItem.Description = description;
  1753. taskItem.Type = (int)AssetType.Notecard;
  1754. taskItem.InvType = (int)InventoryType.Notecard;
  1755. taskItem.OwnerID = m_host.OwnerID;
  1756. taskItem.CreatorID = m_host.OwnerID;
  1757. taskItem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
  1758. taskItem.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
  1759. taskItem.EveryonePermissions = 0;
  1760. taskItem.NextPermissions = (uint)PermissionMask.All;
  1761. taskItem.GroupID = m_host.GroupID;
  1762. taskItem.GroupPermissions = 0;
  1763. taskItem.Flags = 0;
  1764. taskItem.PermsGranter = UUID.Zero;
  1765. taskItem.PermsMask = 0;
  1766. taskItem.AssetID = asset.FullID;
  1767. if (forceSameName)
  1768. m_host.Inventory.AddInventoryItemExclusive(taskItem, false);
  1769. else
  1770. m_host.Inventory.AddInventoryItem(taskItem, false);
  1771. m_host.ParentGroup.InvalidateDeepEffectivePerms();
  1772. return taskItem;
  1773. }
  1774. /// <summary>
  1775. /// Load the notecard data found at the given prim inventory item name or asset uuid.
  1776. /// </summary>
  1777. /// <param name="notecardNameOrUuid"></param>
  1778. /// <returns>The text loaded. Null if no notecard was found.</returns>
  1779. protected string LoadNotecard(string notecardNameOrUuid)
  1780. {
  1781. UUID assetID = CacheNotecard(notecardNameOrUuid);
  1782. if (assetID != UUID.Zero)
  1783. {
  1784. StringBuilder notecardData = new StringBuilder();
  1785. for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
  1786. {
  1787. string line = NotecardCache.GetLine(assetID, count) + "\n";
  1788. // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
  1789. notecardData.Append(line);
  1790. }
  1791. return notecardData.ToString();
  1792. }
  1793. return null;
  1794. }
  1795. /// <summary>
  1796. /// Cache a notecard's contents.
  1797. /// </summary>
  1798. /// <param name="notecardNameOrUuid"></param>
  1799. /// <returns>
  1800. /// The asset id of the notecard, which is used for retrieving the cached data.
  1801. /// UUID.Zero if no asset could be found.
  1802. /// </returns>
  1803. protected UUID CacheNotecard(string notecardNameOrUuid)
  1804. {
  1805. UUID assetID = UUID.Zero;
  1806. bool notecardNameIsUUID = UUID.TryParse(notecardNameOrUuid, out assetID);
  1807. if (!notecardNameIsUUID)
  1808. {
  1809. assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
  1810. }
  1811. if (assetID == UUID.Zero)
  1812. return UUID.Zero;
  1813. if (!NotecardCache.IsCached(assetID))
  1814. {
  1815. AssetBase a = World.AssetService.Get(assetID.ToString());
  1816. if (a == null)
  1817. {
  1818. // Whoops, it's still possible here that the notecard name was properly
  1819. // formatted like a UUID but isn't an asset UUID so lets look it up by name after all
  1820. assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
  1821. if (assetID == UUID.Zero)
  1822. return UUID.Zero;
  1823. if (!NotecardCache.IsCached(assetID))
  1824. {
  1825. a = World.AssetService.Get(assetID.ToString());
  1826. if (a == null)
  1827. {
  1828. return UUID.Zero;
  1829. }
  1830. }
  1831. }
  1832. NotecardCache.Cache(assetID, a.Data);
  1833. };
  1834. return assetID;
  1835. }
  1836. protected UUID SearchTaskInventoryForAssetId(string name)
  1837. {
  1838. UUID assetId = UUID.Zero;
  1839. m_host.TaskInventory.LockItemsForRead(true);
  1840. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1841. {
  1842. if (item.Type == 7 && item.Name == name)
  1843. {
  1844. assetId = item.AssetID;
  1845. }
  1846. }
  1847. m_host.TaskInventory.LockItemsForRead(false);
  1848. return assetId;
  1849. }
  1850. /// <summary>
  1851. /// Directly get an entire notecard at once.
  1852. /// </summary>
  1853. /// <remarks>
  1854. /// Instead of using the LSL Dataserver event to pull notecard data
  1855. /// this will simply read the entire notecard and return its data as a string.
  1856. ///
  1857. /// Warning - due to the synchronous method this function uses to fetch assets, its use
  1858. /// may be dangerous and unreliable while running in grid mode.
  1859. /// </remarks>
  1860. /// <param name="name">Name of the notecard or its asset id</param>
  1861. /// <param name="line">The line number to read. The first line is line 0</param>
  1862. /// <returns>Notecard line</returns>
  1863. public string osGetNotecardLine(string name, int line)
  1864. {
  1865. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
  1866. UUID assetID = CacheNotecard(name);
  1867. if (assetID == UUID.Zero)
  1868. {
  1869. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1870. return "ERROR!";
  1871. }
  1872. return NotecardCache.GetLine(assetID, line);
  1873. }
  1874. /// <summary>
  1875. /// Get an entire notecard at once.
  1876. /// </summary>
  1877. /// <remarks>
  1878. /// Instead of using the LSL Dataserver event to pull notecard data line by line,
  1879. /// this will simply read the entire notecard and return its data as a string.
  1880. ///
  1881. /// Warning - due to the synchronous method this function uses to fetch assets, its use
  1882. /// may be dangerous and unreliable while running in grid mode.
  1883. /// </remarks>
  1884. /// <param name="name">Name of the notecard or its asset id</param>
  1885. /// <returns>Notecard text</returns>
  1886. public string osGetNotecard(string name)
  1887. {
  1888. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
  1889. string text = LoadNotecard(name);
  1890. if (text == null)
  1891. {
  1892. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1893. return "ERROR!";
  1894. }
  1895. else
  1896. {
  1897. return text;
  1898. }
  1899. }
  1900. /// <summary>
  1901. /// Get the number of lines in the given notecard.
  1902. /// </summary>
  1903. /// <remarks>
  1904. /// Instead of using the LSL Dataserver event to pull notecard data,
  1905. /// this will simply read the number of note card lines and return this data as an integer.
  1906. ///
  1907. /// Warning - due to the synchronous method this function uses to fetch assets, its use
  1908. /// may be dangerous and unreliable while running in grid mode.
  1909. /// </remarks>
  1910. /// <param name="name">Name of the notecard or its asset id</param>
  1911. /// <returns></returns>
  1912. public int osGetNumberOfNotecardLines(string name)
  1913. {
  1914. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
  1915. UUID assetID = CacheNotecard(name);
  1916. if (assetID == UUID.Zero)
  1917. {
  1918. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1919. return -1;
  1920. }
  1921. return NotecardCache.GetLines(assetID);
  1922. }
  1923. public string osAvatarName2Key(string firstname, string lastname)
  1924. {
  1925. CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");
  1926. IUserManagement userManager = World.RequestModuleInterface<IUserManagement>();
  1927. if (userManager == null)
  1928. {
  1929. OSSLShoutError("osAvatarName2Key: UserManagement module not available");
  1930. return string.Empty;
  1931. }
  1932. // Check local grid
  1933. UUID userID = userManager.GetUserIdByName(firstname, lastname);
  1934. if (userID != UUID.Zero)
  1935. return userID.ToString();
  1936. // HG ?
  1937. string realFirstName;
  1938. string realLastName;
  1939. string serverURI;
  1940. if (Util.ParseForeignAvatarName(firstname, lastname, out realFirstName, out realLastName, out serverURI))
  1941. {
  1942. try
  1943. {
  1944. UserAgentServiceConnector userConnection = new UserAgentServiceConnector(serverURI, true);
  1945. if (userConnection != null)
  1946. {
  1947. userID = userConnection.GetUUID(realFirstName, realLastName);
  1948. if (userID != UUID.Zero)
  1949. {
  1950. userManager.AddUser(userID, realFirstName, realLastName, serverURI);
  1951. return userID.ToString();
  1952. }
  1953. }
  1954. }
  1955. catch (Exception /*e*/)
  1956. {
  1957. // m_log.Warn("[osAvatarName2Key] UserAgentServiceConnector - Unable to connect to destination grid ", e);
  1958. }
  1959. }
  1960. return UUID.Zero.ToString();
  1961. }
  1962. public string osKey2Name(string id)
  1963. {
  1964. CheckThreatLevel(ThreatLevel.Low, "osKey2Name");
  1965. UUID key = new UUID();
  1966. if (UUID.TryParse(id, out key))
  1967. {
  1968. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
  1969. if (account != null)
  1970. return account.Name;
  1971. if (m_ScriptEngine.World.GridUserService != null)
  1972. {
  1973. GridUserInfo uInfo = m_ScriptEngine.World.GridUserService.GetGridUserInfo(key.ToString());
  1974. if (uInfo != null)
  1975. {
  1976. UUID userUUID; String gridURL; String firstName; String lastName; String tmp;
  1977. if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out userUUID, out gridURL, out firstName, out lastName, out tmp))
  1978. {
  1979. string grid = new Uri(gridURL).Authority;
  1980. return firstName + "." + lastName + " @" + grid;
  1981. }
  1982. }
  1983. }
  1984. }
  1985. return "";
  1986. }
  1987. private enum InfoType
  1988. {
  1989. Nick,
  1990. Name,
  1991. Login,
  1992. Home,
  1993. Custom
  1994. };
  1995. private string GridUserInfo(InfoType type)
  1996. {
  1997. return GridUserInfo(type, "");
  1998. }
  1999. private string GridUserInfo(InfoType type, string key)
  2000. {
  2001. string retval = String.Empty;
  2002. IConfigSource config = m_ScriptEngine.ConfigSource;
  2003. string url = null;
  2004. IConfig gridInfoConfig = config.Configs["GridInfo"];
  2005. if (gridInfoConfig != null)
  2006. url = gridInfoConfig.GetString("GridInfoURI", String.Empty);
  2007. if (String.IsNullOrEmpty(url))
  2008. return "Configuration Error!";
  2009. string verb ="/json_grid_info";
  2010. OSDMap json = new OSDMap();
  2011. OSDMap info = WebUtil.GetFromService(String.Format("{0}{1}",url,verb), 3000);
  2012. if (info["Success"] != true)
  2013. return "Get GridInfo Failed!";
  2014. json = (OSDMap)OSDParser.DeserializeJson(info["_RawResult"].AsString());
  2015. switch (type)
  2016. {
  2017. case InfoType.Nick:
  2018. retval = json["gridnick"];
  2019. break;
  2020. case InfoType.Name:
  2021. retval = json["gridname"];
  2022. break;
  2023. case InfoType.Login:
  2024. retval = json["login"];
  2025. break;
  2026. case InfoType.Home:
  2027. retval = json["home"];
  2028. break;
  2029. case InfoType.Custom:
  2030. retval = json[key];
  2031. break;
  2032. default:
  2033. retval = "error";
  2034. break;
  2035. }
  2036. return retval;
  2037. }
  2038. /// <summary>
  2039. /// Get the nickname of this grid, as set in the [GridInfo] config section.
  2040. /// </summary>
  2041. /// <remarks>
  2042. /// Threat level is Moderate because intentional abuse, for instance
  2043. /// scripts that are written to be malicious only on one grid,
  2044. /// for instance in a HG scenario, are a distinct possibility.
  2045. /// </remarks>
  2046. /// <returns></returns>
  2047. public string osGetGridNick()
  2048. {
  2049. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
  2050. string nick = String.Empty;
  2051. IConfigSource config = m_ScriptEngine.ConfigSource;
  2052. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  2053. nick = config.Configs[GridInfoServiceConfigSectionName].GetString("gridnick", nick);
  2054. if (String.IsNullOrEmpty(nick))
  2055. nick = GridUserInfo(InfoType.Nick);
  2056. return nick;
  2057. }
  2058. public string osGetGridName()
  2059. {
  2060. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName");
  2061. string name = String.Empty;
  2062. IConfigSource config = m_ScriptEngine.ConfigSource;
  2063. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  2064. name = config.Configs[GridInfoServiceConfigSectionName].GetString("gridname", name);
  2065. if (String.IsNullOrEmpty(name))
  2066. name = GridUserInfo(InfoType.Name);
  2067. return name;
  2068. }
  2069. public string osGetGridLoginURI()
  2070. {
  2071. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI");
  2072. string loginURI = String.Empty;
  2073. IConfigSource config = m_ScriptEngine.ConfigSource;
  2074. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  2075. loginURI = config.Configs[GridInfoServiceConfigSectionName].GetString("login", loginURI);
  2076. if (String.IsNullOrEmpty(loginURI))
  2077. loginURI = GridUserInfo(InfoType.Login);
  2078. return loginURI;
  2079. }
  2080. public string osGetGridHomeURI()
  2081. {
  2082. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI");
  2083. IConfigSource config = m_ScriptEngine.ConfigSource;
  2084. string HomeURI = Util.GetConfigVarFromSections<string>(config, "HomeURI",
  2085. new string[] { "Startup", "Hypergrid" }, String.Empty);
  2086. if (!string.IsNullOrEmpty(HomeURI))
  2087. return HomeURI;
  2088. // Legacy. Remove soon!
  2089. if (config.Configs["LoginService"] != null)
  2090. HomeURI = config.Configs["LoginService"].GetString("SRV_HomeURI", HomeURI);
  2091. if (String.IsNullOrEmpty(HomeURI))
  2092. HomeURI = GridUserInfo(InfoType.Home);
  2093. return HomeURI;
  2094. }
  2095. public string osGetGridGatekeeperURI()
  2096. {
  2097. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI");
  2098. IConfigSource config = m_ScriptEngine.ConfigSource;
  2099. string gatekeeperURI = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
  2100. new string[] { "Startup", "Hypergrid" }, String.Empty);
  2101. if (!string.IsNullOrEmpty(gatekeeperURI))
  2102. return gatekeeperURI;
  2103. // Legacy. Remove soon!
  2104. if (config.Configs["GridService"] != null)
  2105. gatekeeperURI = config.Configs["GridService"].GetString("Gatekeeper", gatekeeperURI);
  2106. return gatekeeperURI;
  2107. }
  2108. public string osGetGridCustom(string key)
  2109. {
  2110. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridCustom");
  2111. string retval = String.Empty;
  2112. IConfigSource config = m_ScriptEngine.ConfigSource;
  2113. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  2114. retval = config.Configs[GridInfoServiceConfigSectionName].GetString(key, retval);
  2115. if (String.IsNullOrEmpty(retval))
  2116. retval = GridUserInfo(InfoType.Custom, key);
  2117. return retval;
  2118. }
  2119. public string osGetAvatarHomeURI(string uuid)
  2120. {
  2121. CheckThreatLevel(ThreatLevel.Low, "osGetAvatarHomeURI");
  2122. IUserManagement userManager = m_ScriptEngine.World.RequestModuleInterface<IUserManagement>();
  2123. string returnValue = "";
  2124. if (userManager != null)
  2125. {
  2126. returnValue = userManager.GetUserServerURL(new UUID(uuid), "HomeURI");
  2127. }
  2128. if (returnValue == "")
  2129. {
  2130. IConfigSource config = m_ScriptEngine.ConfigSource;
  2131. returnValue = Util.GetConfigVarFromSections<string>(config, "HomeURI",
  2132. new string[] { "Startup", "Hypergrid" }, String.Empty);
  2133. if (!string.IsNullOrEmpty(returnValue))
  2134. return returnValue;
  2135. // Legacy. Remove soon!
  2136. if (config.Configs["LoginService"] != null)
  2137. returnValue = config.Configs["LoginService"].GetString("SRV_HomeURI", returnValue);
  2138. if (String.IsNullOrEmpty(returnValue))
  2139. returnValue = GridUserInfo(InfoType.Home);
  2140. }
  2141. return returnValue;
  2142. }
  2143. public LSL_String osFormatString(string str, LSL_List strings)
  2144. {
  2145. CheckThreatLevel(ThreatLevel.VeryLow, "osFormatString");
  2146. return String.Format(str, strings.Data);
  2147. }
  2148. public LSL_List osMatchString(string src, string pattern, int start)
  2149. {
  2150. CheckThreatLevel(ThreatLevel.VeryLow, "osMatchString");
  2151. LSL_List result = new LSL_List();
  2152. // Normalize indices (if negative).
  2153. // After normlaization they may still be
  2154. // negative, but that is now relative to
  2155. // the start, rather than the end, of the
  2156. // sequence.
  2157. if (start < 0)
  2158. {
  2159. start = src.Length + start;
  2160. }
  2161. if (start < 0 || start >= src.Length)
  2162. {
  2163. return result; // empty list
  2164. }
  2165. // Find matches beginning at start position
  2166. Regex matcher = new Regex(pattern);
  2167. Match match = matcher.Match(src, start);
  2168. while (match.Success)
  2169. {
  2170. foreach (System.Text.RegularExpressions.Group g in match.Groups)
  2171. {
  2172. if (g.Success)
  2173. {
  2174. result.Add(new LSL_String(g.Value));
  2175. result.Add(new LSL_Integer(g.Index));
  2176. }
  2177. }
  2178. match = match.NextMatch();
  2179. }
  2180. return result;
  2181. }
  2182. public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start)
  2183. {
  2184. CheckThreatLevel(ThreatLevel.VeryLow, "osReplaceString");
  2185. // Normalize indices (if negative).
  2186. // After normlaization they may still be
  2187. // negative, but that is now relative to
  2188. // the start, rather than the end, of the
  2189. // sequence.
  2190. if (start < 0)
  2191. {
  2192. start = src.Length + start;
  2193. }
  2194. if (start < 0 || start >= src.Length)
  2195. {
  2196. return src;
  2197. }
  2198. // Find matches beginning at start position
  2199. Regex matcher = new Regex(pattern);
  2200. return matcher.Replace(src,replace,count,start);
  2201. }
  2202. public string osLoadedCreationDate()
  2203. {
  2204. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
  2205. return World.RegionInfo.RegionSettings.LoadedCreationDate;
  2206. }
  2207. public string osLoadedCreationTime()
  2208. {
  2209. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime");
  2210. return World.RegionInfo.RegionSettings.LoadedCreationTime;
  2211. }
  2212. public string osLoadedCreationID()
  2213. {
  2214. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID");
  2215. return World.RegionInfo.RegionSettings.LoadedCreationID;
  2216. }
  2217. /// <summary>
  2218. /// Get the primitive parameters of a linked prim.
  2219. /// </summary>
  2220. /// <remarks>
  2221. /// Threat level is 'Low' because certain users could possibly be tricked into
  2222. /// dropping an unverified script into one of their own objects, which could
  2223. /// then gather the physical construction details of the object and transmit it
  2224. /// to an unscrupulous third party, thus permitting unauthorized duplication of
  2225. /// the object's form.
  2226. /// </remarks>
  2227. /// <param name="linknumber"></param>
  2228. /// <param name="rules"></param>
  2229. /// <returns></returns>
  2230. public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  2231. {
  2232. CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
  2233. InitLSL();
  2234. // One needs to cast m_LSL_Api because we're using functions not
  2235. // on the ILSL_Api interface.
  2236. LSL_List retVal = new LSL_List();
  2237. LSL_List remaining = new LSL_List();
  2238. List<SceneObjectPart> parts = m_LSL_Api.GetLinkParts(linknumber);
  2239. foreach (SceneObjectPart part in parts)
  2240. {
  2241. remaining = m_LSL_Api.GetPrimParams(part, rules, ref retVal);
  2242. }
  2243. while (remaining.Length > 1)
  2244. {
  2245. linknumber = remaining.GetLSLIntegerItem(0);
  2246. parts = m_LSL_Api.GetLinkParts(linknumber);
  2247. if(parts.Count == 0)
  2248. break;
  2249. rules = remaining.GetSublist(1, -1);
  2250. foreach (SceneObjectPart part in parts)
  2251. remaining = m_LSL_Api.GetPrimParams(part, rules, ref retVal);
  2252. }
  2253. return retVal;
  2254. }
  2255. public void osForceCreateLink(string target, int parent)
  2256. {
  2257. CheckThreatLevel(ThreatLevel.VeryLow, "osForceCreateLink");
  2258. InitLSL();
  2259. m_LSL_Api.CreateLink(target, parent);
  2260. }
  2261. public void osForceBreakLink(int linknum)
  2262. {
  2263. CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakLink");
  2264. InitLSL();
  2265. m_LSL_Api.BreakLink(linknum);
  2266. }
  2267. public void osForceBreakAllLinks()
  2268. {
  2269. CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakAllLinks");
  2270. InitLSL();
  2271. m_LSL_Api.BreakAllLinks();
  2272. }
  2273. public LSL_Integer osIsNpc(LSL_Key npc)
  2274. {
  2275. CheckThreatLevel();
  2276. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2277. if (module != null)
  2278. {
  2279. UUID npcId;
  2280. if (UUID.TryParse(npc.m_string, out npcId))
  2281. if (module.IsNPC(npcId, World))
  2282. return ScriptBaseClass.TRUE;
  2283. }
  2284. return ScriptBaseClass.FALSE;
  2285. }
  2286. public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
  2287. {
  2288. CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
  2289. // have to get the npc module also here to set the default Not Owned
  2290. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2291. if(module == null)
  2292. return new LSL_Key(UUID.Zero.ToString());
  2293. bool owned = (module.NPCOptionFlags & NPCOptionsFlags.AllowNotOwned) == 0;
  2294. return NpcCreate(firstname, lastname, position, notecard, owned, false, false);
  2295. }
  2296. public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
  2297. {
  2298. CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
  2299. return NpcCreate(
  2300. firstname, lastname, position, notecard,
  2301. (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0,
  2302. (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0,
  2303. (options & ScriptBaseClass.OS_NPC_OBJECT_GROUP) != 0);
  2304. }
  2305. private LSL_Key NpcCreate(
  2306. string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent, bool hostGroupID)
  2307. {
  2308. if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z)))
  2309. {
  2310. OSSLError("no permission to rez NPC at requested location");
  2311. return new LSL_Key(UUID.Zero.ToString());
  2312. }
  2313. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2314. if(module == null)
  2315. {
  2316. OSSLError("NPC module not enabled");
  2317. return new LSL_Key(UUID.Zero.ToString());
  2318. }
  2319. string groupTitle = String.Empty;
  2320. UUID groupID = UUID.Zero;
  2321. AvatarAppearance appearance = null;
  2322. // check creation options
  2323. NPCOptionsFlags createFlags = module.NPCOptionFlags;
  2324. if((createFlags & NPCOptionsFlags.AllowNotOwned) == 0 && !owned)
  2325. {
  2326. OSSLError("Not owned NPCs disabled");
  2327. owned = true; // we should get here...
  2328. }
  2329. if((createFlags & NPCOptionsFlags.AllowSenseAsAvatar) == 0 && senseAsAgent)
  2330. {
  2331. OSSLError("NPC allow sense as Avatar disabled");
  2332. senseAsAgent = false;
  2333. }
  2334. if(hostGroupID && m_host.GroupID != UUID.Zero)
  2335. {
  2336. IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
  2337. if (groupsModule != null)
  2338. {
  2339. GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
  2340. if (member == null)
  2341. {
  2342. OSSLError(string.Format("osNpcCreate: the object owner is not member of the object group"));
  2343. return new LSL_Key(UUID.Zero.ToString());
  2344. }
  2345. groupID = m_host.GroupID;
  2346. if((createFlags & NPCOptionsFlags.NoNPCGroup) != 0)
  2347. {
  2348. GroupRecord grprec = groupsModule.GetGroupRecord(m_host.GroupID);
  2349. if(grprec != null && grprec.GroupName != "")
  2350. groupTitle = grprec.GroupName;
  2351. }
  2352. }
  2353. }
  2354. if((createFlags & NPCOptionsFlags.NoNPCGroup) == 0)
  2355. {
  2356. if (firstname != String.Empty || lastname != String.Empty)
  2357. {
  2358. if (firstname != "Shown outfit:")
  2359. groupTitle = "- NPC -";
  2360. }
  2361. }
  2362. if((createFlags & NPCOptionsFlags.AllowCloneOtherAvatars) != 0)
  2363. {
  2364. UUID id;
  2365. if (UUID.TryParse(notecard, out id))
  2366. {
  2367. ScenePresence clonePresence = World.GetScenePresence(id);
  2368. if (clonePresence != null)
  2369. appearance = clonePresence.Appearance;
  2370. }
  2371. }
  2372. if (appearance == null)
  2373. {
  2374. if(!string.IsNullOrWhiteSpace(notecard))
  2375. {
  2376. string appearanceSerialized = LoadNotecard(notecard);
  2377. if (appearanceSerialized == null)
  2378. {
  2379. OSSLError(string.Format("osNpcCreate: Notecard '{0}' not found.", notecard));
  2380. return new LSL_Key(UUID.Zero.ToString());
  2381. }
  2382. try
  2383. {
  2384. OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
  2385. appearance = new AvatarAppearance();
  2386. appearance.Unpack(appearanceOsd);
  2387. }
  2388. catch
  2389. {
  2390. OSSLError(string.Format("osNpcCreate: Error processing notecard '{0}'", notecard));
  2391. return new LSL_Key(UUID.Zero.ToString());
  2392. }
  2393. }
  2394. }
  2395. UUID ownerID = UUID.Zero;
  2396. if (owned)
  2397. ownerID = m_host.OwnerID;
  2398. UUID x = module.CreateNPC(firstname,
  2399. lastname,
  2400. position,
  2401. UUID.Random(),
  2402. ownerID,
  2403. groupTitle,
  2404. groupID,
  2405. senseAsAgent,
  2406. World,
  2407. appearance);
  2408. ScenePresence sp;
  2409. if (World.TryGetScenePresence(x, out sp))
  2410. {
  2411. sp.SendAvatarDataToAllAgents();
  2412. }
  2413. return new LSL_Key(x.ToString());
  2414. }
  2415. /// <summary>
  2416. /// Save the current appearance of the NPC permanently to the named notecard.
  2417. /// </summary>
  2418. /// <param name="avatar"></param>
  2419. /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
  2420. /// <returns>The asset ID of the notecard saved.</returns>
  2421. public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard)
  2422. {
  2423. CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance");
  2424. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2425. if (npcModule != null)
  2426. {
  2427. UUID npcId;
  2428. if (!UUID.TryParse(npc.m_string, out npcId))
  2429. return new LSL_Key(UUID.Zero.ToString());
  2430. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2431. return new LSL_Key(UUID.Zero.ToString());
  2432. return SaveAppearanceToNotecard(npcId, notecard);
  2433. }
  2434. return new LSL_Key(UUID.Zero.ToString());
  2435. }
  2436. public void osNpcLoadAppearance(LSL_Key npc, string notecard)
  2437. {
  2438. CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance");
  2439. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2440. if (npcModule != null)
  2441. {
  2442. UUID npcId;
  2443. if (!UUID.TryParse(npc.m_string, out npcId))
  2444. return;
  2445. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2446. return;
  2447. string appearanceSerialized = LoadNotecard(notecard);
  2448. if (appearanceSerialized == null)
  2449. OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
  2450. OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
  2451. // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
  2452. // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
  2453. // Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a);
  2454. AvatarAppearance appearance = new AvatarAppearance();
  2455. appearance.Unpack(appearanceOsd);
  2456. npcModule.SetNPCAppearance(npcId, appearance, m_host.ParentGroup.Scene);
  2457. }
  2458. }
  2459. public LSL_Key osNpcGetOwner(LSL_Key npc)
  2460. {
  2461. CheckThreatLevel(ThreatLevel.None, "osNpcGetOwner");
  2462. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2463. if (npcModule != null)
  2464. {
  2465. UUID npcId;
  2466. if (UUID.TryParse(npc.m_string, out npcId))
  2467. {
  2468. UUID owner = npcModule.GetOwner(npcId);
  2469. if (owner != UUID.Zero)
  2470. return new LSL_Key(owner.ToString());
  2471. else
  2472. return npc;
  2473. }
  2474. }
  2475. return new LSL_Key(UUID.Zero.ToString());
  2476. }
  2477. public LSL_Vector osNpcGetPos(LSL_Key npc)
  2478. {
  2479. CheckThreatLevel(ThreatLevel.High, "osNpcGetPos");
  2480. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2481. if (npcModule != null)
  2482. {
  2483. UUID npcId;
  2484. if (!UUID.TryParse(npc.m_string, out npcId))
  2485. return new LSL_Vector(0, 0, 0);
  2486. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2487. return new LSL_Vector(0, 0, 0);
  2488. ScenePresence sp = World.GetScenePresence(npcId);
  2489. if (sp != null)
  2490. return new LSL_Vector(sp.AbsolutePosition);
  2491. }
  2492. return Vector3.Zero;
  2493. }
  2494. public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos)
  2495. {
  2496. CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
  2497. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2498. if (module != null)
  2499. {
  2500. UUID npcId;
  2501. if (!UUID.TryParse(npc.m_string, out npcId))
  2502. return;
  2503. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2504. return;
  2505. module.MoveToTarget(npcId, World, pos, false, true, false);
  2506. }
  2507. }
  2508. public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options)
  2509. {
  2510. CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget");
  2511. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2512. if (module != null)
  2513. {
  2514. UUID npcId;
  2515. if (!UUID.TryParse(npc.m_string, out npcId))
  2516. return;
  2517. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2518. return;
  2519. module.MoveToTarget(
  2520. new UUID(npc.m_string),
  2521. World,
  2522. target,
  2523. (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
  2524. (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0,
  2525. (options & ScriptBaseClass.OS_NPC_RUNNING) != 0);
  2526. }
  2527. }
  2528. public LSL_Rotation osNpcGetRot(LSL_Key npc)
  2529. {
  2530. CheckThreatLevel(ThreatLevel.High, "osNpcGetRot");
  2531. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2532. if (npcModule != null)
  2533. {
  2534. UUID npcId;
  2535. if (!UUID.TryParse(npc.m_string, out npcId))
  2536. return new LSL_Rotation(Quaternion.Identity);
  2537. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2538. return new LSL_Rotation(Quaternion.Identity);
  2539. ScenePresence sp = World.GetScenePresence(npcId);
  2540. if (sp != null)
  2541. return new LSL_Rotation(sp.GetWorldRotation());
  2542. }
  2543. return Quaternion.Identity;
  2544. }
  2545. public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation)
  2546. {
  2547. CheckThreatLevel(ThreatLevel.High, "osNpcSetRot");
  2548. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2549. if (npcModule != null)
  2550. {
  2551. UUID npcId;
  2552. if (!UUID.TryParse(npc.m_string, out npcId))
  2553. return;
  2554. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2555. return;
  2556. ScenePresence sp = World.GetScenePresence(npcId);
  2557. if (sp != null)
  2558. sp.Rotation = rotation;
  2559. }
  2560. }
  2561. public void osNpcStopMoveToTarget(LSL_Key npc)
  2562. {
  2563. CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget");
  2564. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2565. if (module != null)
  2566. {
  2567. UUID npcId = new UUID(npc.m_string);
  2568. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2569. return;
  2570. module.StopMoveToTarget(npcId, World);
  2571. }
  2572. }
  2573. public void osNpcSetProfileAbout(LSL_Key npc, string about)
  2574. {
  2575. CheckThreatLevel(ThreatLevel.Low, "osNpcSetProfileAbout");
  2576. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2577. if (module != null)
  2578. {
  2579. UUID npcId = new UUID(npc.m_string);
  2580. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2581. return;
  2582. ScenePresence sp = World.GetScenePresence(npcId);
  2583. if (sp != null)
  2584. ((INPC)(sp.ControllingClient)).profileAbout = about;
  2585. }
  2586. }
  2587. public void osNpcSetProfileImage(LSL_Key npc, string image)
  2588. {
  2589. CheckThreatLevel(ThreatLevel.Low, "osNpcSetProfileImage");
  2590. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2591. if (module != null)
  2592. {
  2593. UUID npcId = new UUID(npc.m_string);
  2594. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2595. return;
  2596. UUID ImageID = new UUID();
  2597. ImageID = ScriptUtils.GetAssetIdFromItemName(m_host, image, (int)AssetType.Texture);
  2598. if (ImageID == null || ImageID == UUID.Zero)
  2599. {
  2600. if (!UUID.TryParse(image, out ImageID))
  2601. return;
  2602. }
  2603. ScenePresence sp = World.GetScenePresence(npcId);
  2604. if (sp != null)
  2605. ((INPC)(sp.ControllingClient)).profileImage = ImageID;
  2606. }
  2607. }
  2608. public void osNpcSay(LSL_Key npc, string message)
  2609. {
  2610. osNpcSay(npc, 0, message);
  2611. }
  2612. public void osNpcSay(LSL_Key npc, int channel, string message)
  2613. {
  2614. CheckThreatLevel(ThreatLevel.High, "osNpcSay");
  2615. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2616. if (module != null)
  2617. {
  2618. UUID npcId = new UUID(npc.m_string);
  2619. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2620. return;
  2621. module.Say(npcId, World, message, channel);
  2622. }
  2623. }
  2624. public void osNpcSayTo(LSL_Key npc, LSL_Key target, int channel, string msg)
  2625. {
  2626. CheckThreatLevel(ThreatLevel.High, "osNpcSayTo");
  2627. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2628. if (module == null)
  2629. return;
  2630. UUID npcId;
  2631. if (!UUID.TryParse(npc.m_string, out npcId))
  2632. return;
  2633. UUID TargetID;
  2634. if (!UUID.TryParse(target.m_string, out TargetID))
  2635. return;
  2636. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2637. return;
  2638. ScenePresence NPCpresence = World.GetScenePresence(npcId);
  2639. if (NPCpresence == null || NPCpresence.IsDeleted || !NPCpresence.IsNPC)
  2640. return;
  2641. Vector3 npcPOS = NPCpresence.AbsolutePosition;
  2642. string npcNAME = NPCpresence.Name;
  2643. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  2644. if (wComm != null)
  2645. wComm.DeliverMessageTo(TargetID, channel, npcPOS, npcNAME, npcId, msg);
  2646. }
  2647. public void osNpcShout(LSL_Key npc, int channel, string message)
  2648. {
  2649. CheckThreatLevel(ThreatLevel.High, "osNpcShout");
  2650. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2651. if (module != null)
  2652. {
  2653. UUID npcId = new UUID(npc.m_string);
  2654. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2655. return;
  2656. module.Shout(npcId, World, message, channel);
  2657. }
  2658. }
  2659. public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
  2660. {
  2661. CheckThreatLevel(ThreatLevel.High, "osNpcSit");
  2662. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2663. if (module != null)
  2664. {
  2665. UUID npcId = new UUID(npc.m_string);
  2666. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2667. return;
  2668. module.Sit(npcId, new UUID(target.m_string), World);
  2669. }
  2670. }
  2671. public void osNpcStand(LSL_Key npc)
  2672. {
  2673. CheckThreatLevel(ThreatLevel.High, "osNpcStand");
  2674. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2675. if (module != null)
  2676. {
  2677. UUID npcId = new UUID(npc.m_string);
  2678. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2679. return;
  2680. module.Stand(npcId, World);
  2681. }
  2682. }
  2683. public void osNpcRemove(LSL_Key npc)
  2684. {
  2685. CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
  2686. try
  2687. {
  2688. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2689. if (module != null)
  2690. {
  2691. UUID npcId = new UUID(npc.m_string);
  2692. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2693. return;
  2694. module.DeleteNPC(npcId, World);
  2695. }
  2696. }
  2697. catch { }
  2698. }
  2699. public void osNpcPlayAnimation(LSL_Key npc, string animation)
  2700. {
  2701. CheckThreatLevel(ThreatLevel.High, "osNpcPlayAnimation");
  2702. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2703. if (module == null)
  2704. return;
  2705. UUID npcID;
  2706. if(!UUID.TryParse(npc.m_string, out npcID))
  2707. return;
  2708. ScenePresence target = World.GetScenePresence(npcID);
  2709. if (target == null || !target.IsNPC)
  2710. return;
  2711. if (!module.CheckPermissions(npcID, m_host.OwnerID))
  2712. return;
  2713. UUID animID = UUID.Zero;
  2714. m_host.TaskInventory.LockItemsForRead(true);
  2715. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2716. {
  2717. if (inv.Value.Type == (int)AssetType.Animation)
  2718. {
  2719. if (inv.Value.Name == animation)
  2720. {
  2721. animID = inv.Value.AssetID;
  2722. break;
  2723. }
  2724. }
  2725. }
  2726. m_host.TaskInventory.LockItemsForRead(false);
  2727. if (animID == UUID.Zero)
  2728. target.Animator.AddAnimation(animation, m_host.UUID);
  2729. else
  2730. target.Animator.AddAnimation(animID, m_host.UUID);
  2731. }
  2732. public void osNpcStopAnimation(LSL_Key npc, string animation)
  2733. {
  2734. CheckThreatLevel(ThreatLevel.High, "osNpcStopAnimation");
  2735. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2736. if (module == null)
  2737. return;
  2738. UUID npcID;
  2739. if (!UUID.TryParse(npc.m_string, out npcID))
  2740. return;
  2741. ScenePresence target = World.GetScenePresence(npcID);
  2742. if (target == null || !target.IsNPC)
  2743. return;
  2744. if (!module.CheckPermissions(npcID, m_host.OwnerID))
  2745. return;
  2746. UUID animID;
  2747. if (!UUID.TryParse(animation, out animID))
  2748. {
  2749. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation);
  2750. if (item != null && item.Type == (int)AssetType.Animation)
  2751. animID = item.AssetID;
  2752. else
  2753. animID = UUID.Zero;
  2754. }
  2755. if (animID == UUID.Zero)
  2756. target.Animator.RemoveAnimation(animation);
  2757. else
  2758. target.Animator.RemoveAnimation(animID, true);
  2759. }
  2760. public void osNpcWhisper(LSL_Key npc, int channel, string message)
  2761. {
  2762. CheckThreatLevel(ThreatLevel.High, "osNpcWhisper");
  2763. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2764. if (module != null)
  2765. {
  2766. UUID npcId = new UUID(npc.m_string);
  2767. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2768. return;
  2769. module.Whisper(npcId, World, message, channel);
  2770. }
  2771. }
  2772. public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
  2773. {
  2774. CheckThreatLevel(ThreatLevel.High, "osNpcTouch");
  2775. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2776. int linkNum = link_num.value;
  2777. if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS))
  2778. {
  2779. UUID npcId;
  2780. if (!UUID.TryParse(npcLSL_Key, out npcId) || !module.CheckPermissions(npcId, m_host.OwnerID))
  2781. return;
  2782. SceneObjectPart part = null;
  2783. UUID objectId;
  2784. if (UUID.TryParse(LSL_String.ToString(object_key), out objectId))
  2785. part = World.GetSceneObjectPart(objectId);
  2786. if (part == null)
  2787. return;
  2788. if (linkNum != ScriptBaseClass.LINK_THIS)
  2789. {
  2790. if (linkNum == 0 || linkNum == ScriptBaseClass.LINK_ROOT)
  2791. { // 0 and 1 are treated as root, find the root if the current part isnt it
  2792. if (!part.IsRoot)
  2793. part = part.ParentGroup.RootPart;
  2794. }
  2795. else
  2796. { // Find the prim with the given link number if not found then fail silently
  2797. part = part.ParentGroup.GetLinkNumPart(linkNum);
  2798. if (part == null)
  2799. return;
  2800. }
  2801. }
  2802. module.Touch(npcId, part.UUID);
  2803. }
  2804. }
  2805. /// <summary>
  2806. /// Save the current appearance of the script owner permanently to the named notecard.
  2807. /// </summary>
  2808. /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
  2809. /// <returns>The asset ID of the notecard saved.</returns>
  2810. public LSL_Key osOwnerSaveAppearance(string notecard)
  2811. {
  2812. CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance");
  2813. return SaveAppearanceToNotecard(m_host.OwnerID, notecard);
  2814. }
  2815. public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard)
  2816. {
  2817. CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance");
  2818. return SaveAppearanceToNotecard(avatarId, notecard);
  2819. }
  2820. protected LSL_Key SaveAppearanceToNotecard(ScenePresence sp, string notecard)
  2821. {
  2822. IAvatarFactoryModule appearanceModule = World.RequestModuleInterface<IAvatarFactoryModule>();
  2823. if (appearanceModule != null)
  2824. {
  2825. appearanceModule.SaveBakedTextures(sp.UUID);
  2826. EntityTransferContext ctx = new EntityTransferContext();
  2827. OSDMap appearancePacked = sp.Appearance.Pack(ctx);
  2828. TaskInventoryItem item
  2829. = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true);
  2830. return new LSL_Key(item.AssetID.ToString());
  2831. }
  2832. else
  2833. {
  2834. return new LSL_Key(UUID.Zero.ToString());
  2835. }
  2836. }
  2837. protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecard)
  2838. {
  2839. ScenePresence sp = World.GetScenePresence(avatarId);
  2840. if (sp == null || sp.IsChildAgent)
  2841. return new LSL_Key(UUID.Zero.ToString());
  2842. return SaveAppearanceToNotecard(sp, notecard);
  2843. }
  2844. protected LSL_Key SaveAppearanceToNotecard(LSL_Key rawAvatarId, string notecard)
  2845. {
  2846. UUID avatarId;
  2847. if (!UUID.TryParse(rawAvatarId, out avatarId))
  2848. return new LSL_Key(UUID.Zero.ToString());
  2849. return SaveAppearanceToNotecard(avatarId, notecard);
  2850. }
  2851. /// <summary>
  2852. /// Get the gender as specified in avatar appearance for a given avatar key
  2853. /// </summary>
  2854. /// <param name="rawAvatarId"></param>
  2855. /// <returns>"male" or "female" or "unknown"</returns>
  2856. public LSL_String osGetGender(LSL_Key rawAvatarId)
  2857. {
  2858. CheckThreatLevel(ThreatLevel.None, "osGetGender");
  2859. UUID avatarId;
  2860. if (!UUID.TryParse(rawAvatarId, out avatarId))
  2861. return new LSL_String("unknown");
  2862. ScenePresence sp = World.GetScenePresence(avatarId);
  2863. if (sp == null || sp.IsChildAgent || sp.Appearance == null || sp.Appearance.VisualParams == null)
  2864. return new LSL_String("unknown");
  2865. // find the index of "shape" parameter "male"
  2866. int vpShapeMaleIndex = 0;
  2867. bool indexFound = false;
  2868. VisualParam param = new VisualParam();
  2869. foreach(var vpEntry in VisualParams.Params)
  2870. {
  2871. param = vpEntry.Value;
  2872. if (param.Name == "male" && param.Wearable == "shape")
  2873. {
  2874. indexFound = true;
  2875. break;
  2876. }
  2877. if (param.Group == 0)
  2878. vpShapeMaleIndex++;
  2879. }
  2880. if (!indexFound)
  2881. return new LSL_String("unknown");
  2882. float vpShapeMale = Utils.ByteToFloat(sp.Appearance.VisualParams[vpShapeMaleIndex], param.MinValue, param.MaxValue);
  2883. bool isMale = vpShapeMale > 0.5f;
  2884. return new LSL_String(isMale ? "male" : "female");
  2885. }
  2886. /// <summary>
  2887. /// Get current region's map texture UUID
  2888. /// </summary>
  2889. /// <returns></returns>
  2890. public LSL_Key osGetMapTexture()
  2891. {
  2892. CheckThreatLevel();
  2893. return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
  2894. }
  2895. /// <summary>
  2896. /// Get a region's map texture UUID by region UUID or name.
  2897. /// </summary>
  2898. /// <param name="regionName"></param>
  2899. /// <returns></returns>
  2900. public LSL_Key osGetRegionMapTexture(string regionName)
  2901. {
  2902. CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture");
  2903. Scene scene = m_ScriptEngine.World;
  2904. UUID key = UUID.Zero;
  2905. GridRegion region;
  2906. //If string is a key, use it. Otherwise, try to locate region by name.
  2907. if (UUID.TryParse(regionName, out key))
  2908. region = scene.GridService.GetRegionByUUID(UUID.Zero, key);
  2909. else
  2910. region = scene.GridService.GetRegionByName(UUID.Zero, regionName);
  2911. // If region was found, return the regions map texture key.
  2912. if (region != null)
  2913. key = region.TerrainImage;
  2914. ScriptSleep(1000);
  2915. return key.ToString();
  2916. }
  2917. /// <summary>
  2918. /// Return information regarding various simulator statistics (sim fps, physics fps, time
  2919. /// dilation, total number of prims, total number of active scripts, script lps, various
  2920. /// timing data, packets in/out, etc. Basically much the information that's shown in the
  2921. /// client's Statistics Bar (Ctrl-Shift-1)
  2922. /// </summary>
  2923. /// <returns>List of floats</returns>
  2924. public LSL_List osGetRegionStats()
  2925. {
  2926. CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
  2927. LSL_List ret = new LSL_List();
  2928. float[] stats = World.StatsReporter.LastReportedSimStats;
  2929. for (int i = 0; i < 21; i++)
  2930. {
  2931. ret.Add(new LSL_Float(stats[i]));
  2932. }
  2933. return ret;
  2934. }
  2935. public LSL_Vector osGetRegionSize()
  2936. {
  2937. CheckThreatLevel();
  2938. Scene scene = m_ScriptEngine.World;
  2939. RegionInfo reg = World.RegionInfo;
  2940. // GridRegion region = scene.GridService.GetRegionByUUID(UUID.Zero, World.RegionInfo.RegionID);
  2941. // return new LSL_Vector((float)region.RegionSizeX, (float)region.RegionSizeY, (float)Constants.RegionHeight);
  2942. return new LSL_Vector((float)reg.RegionSizeX, (float)reg.RegionSizeY, 0.0f);
  2943. }
  2944. public int osGetSimulatorMemory()
  2945. {
  2946. CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory");
  2947. long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
  2948. if (pws > Int32.MaxValue)
  2949. return Int32.MaxValue;
  2950. if (pws < 0)
  2951. return 0;
  2952. return (int)pws;
  2953. }
  2954. public int osGetSimulatorMemoryKB()
  2955. {
  2956. CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemoryKB");
  2957. long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
  2958. if((pws & 0x3FFL) != 0)
  2959. pws += 0x400L;
  2960. pws >>= 10;
  2961. if (pws > Int32.MaxValue)
  2962. return Int32.MaxValue;
  2963. return (int)pws;
  2964. }
  2965. public void osSetSpeed(string ID, LSL_Float SpeedModifier)
  2966. {
  2967. CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed");
  2968. UUID avid;
  2969. if(!UUID.TryParse(ID, out avid))
  2970. return;
  2971. ScenePresence avatar = World.GetScenePresence(avid);
  2972. if (avatar != null)
  2973. avatar.SpeedModifier = (float)SpeedModifier;
  2974. }
  2975. public void osSetOwnerSpeed(LSL_Float SpeedModifier)
  2976. {
  2977. CheckThreatLevel(ThreatLevel.Moderate, "osSetOwnerSpeed");
  2978. if(SpeedModifier > 4)
  2979. SpeedModifier = 4;
  2980. ScenePresence avatar = World.GetScenePresence(m_host.OwnerID);
  2981. if (avatar != null)
  2982. avatar.SpeedModifier = (float)SpeedModifier;
  2983. }
  2984. public void osKickAvatar(string FirstName, string SurName, string alert)
  2985. {
  2986. CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
  2987. World.ForEachRootScenePresence(delegate (ScenePresence sp)
  2988. {
  2989. if (sp.Firstname == FirstName && sp.Lastname == SurName)
  2990. {
  2991. // kick client...
  2992. if (alert != null)
  2993. sp.ControllingClient.Kick(alert);
  2994. // ...and close on our side
  2995. sp.Scene.CloseAgent(sp.UUID, false);
  2996. }
  2997. });
  2998. }
  2999. public void osKickAvatar(LSL_Key agentKey, string alert)
  3000. {
  3001. CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
  3002. UUID id;
  3003. if (!UUID.TryParse(agentKey, out id) || id == UUID.Zero)
  3004. return;
  3005. ScenePresence sp = World.GetScenePresence(id);
  3006. if(sp == null)
  3007. return;
  3008. // kick client...
  3009. if (alert != null)
  3010. sp.ControllingClient.Kick(alert);
  3011. // ...and close on our side
  3012. sp.Scene.CloseAgent(id, false);
  3013. }
  3014. public LSL_Float osGetHealth(LSL_Key agentKey)
  3015. {
  3016. CheckThreatLevel(ThreatLevel.None, "osGetHealth");
  3017. LSL_Float health = new LSL_Float(-1);
  3018. UUID id;
  3019. if (!UUID.TryParse(agentKey, out id) || id == UUID.Zero)
  3020. return health;
  3021. ScenePresence presence = World.GetScenePresence(id);
  3022. if (presence != null)
  3023. health = presence.Health;
  3024. return health;
  3025. }
  3026. public void osCauseDamage(LSL_Key avatar, LSL_Float damage)
  3027. {
  3028. CheckThreatLevel(ThreatLevel.High, "osCauseDamage");
  3029. UUID avatarId;
  3030. if (!UUID.TryParse(avatar, out avatarId))
  3031. return;
  3032. ScenePresence presence = World.GetScenePresence(avatarId);
  3033. if (presence == null)
  3034. return;
  3035. Vector3 pos = m_host.GetWorldPosition();
  3036. LandData land = World.GetLandData(pos);
  3037. if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage)
  3038. {
  3039. float health = presence.Health;
  3040. health -= (float)damage;
  3041. presence.setHealthWithUpdate(health);
  3042. if (health <= 0)
  3043. {
  3044. float healthliveagain = 100;
  3045. presence.ControllingClient.SendAgentAlertMessage("You died!", true);
  3046. presence.setHealthWithUpdate(healthliveagain);
  3047. presence.Scene.TeleportClientHome(presence.UUID, presence.ControllingClient);
  3048. }
  3049. }
  3050. }
  3051. public void osCauseHealing(LSL_Key avatar, LSL_Float healing)
  3052. {
  3053. CheckThreatLevel(ThreatLevel.High, "osCauseHealing");
  3054. UUID avatarId;
  3055. if (!UUID.TryParse(avatar, out avatarId))
  3056. return;
  3057. ScenePresence presence = World.GetScenePresence(avatarId);
  3058. if (presence == null)
  3059. return;
  3060. float health = presence.Health;
  3061. health += (float)healing;
  3062. if (health >= 100)
  3063. health = 100;
  3064. presence.setHealthWithUpdate(health);
  3065. }
  3066. public void osSetHealth(LSL_Key avatar, LSL_Float health)
  3067. {
  3068. CheckThreatLevel(ThreatLevel.High, "osSetHealth");
  3069. UUID avatarId = new UUID(avatar);
  3070. ScenePresence presence = World.GetScenePresence(avatarId);
  3071. if (presence != null)
  3072. {
  3073. if (health > 100.0)
  3074. health = 100.0;
  3075. else if (health < 1.0)
  3076. health = 1.0;
  3077. presence.setHealthWithUpdate((float)health);
  3078. }
  3079. }
  3080. public void osSetHealRate(LSL_Key avatar, LSL_Float healrate)
  3081. {
  3082. CheckThreatLevel(ThreatLevel.High, "osSetHealRate");
  3083. UUID avatarId;
  3084. if (!UUID.TryParse(avatar, out avatarId))
  3085. return;
  3086. ScenePresence presence = World.GetScenePresence(avatarId);
  3087. if (presence == null)
  3088. return;
  3089. presence.HealRate = (float)healrate;
  3090. }
  3091. public LSL_Float osGetHealRate(LSL_Key avatar)
  3092. {
  3093. CheckThreatLevel(ThreatLevel.None, "osGetHealRate");
  3094. LSL_Float rate = new LSL_Float(0);
  3095. UUID avatarId;
  3096. if (!UUID.TryParse(avatar, out avatarId))
  3097. return rate;
  3098. ScenePresence presence = World.GetScenePresence(avatarId);
  3099. if (presence != null)
  3100. rate = presence.HealRate;
  3101. return rate;
  3102. }
  3103. public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
  3104. {
  3105. CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
  3106. InitLSL();
  3107. return m_LSL_Api.GetPrimitiveParamsEx(prim, rules);
  3108. }
  3109. public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
  3110. {
  3111. CheckThreatLevel(ThreatLevel.High, "osSetPrimitiveParams");
  3112. InitLSL();
  3113. m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams");
  3114. }
  3115. /// <summary>
  3116. /// Set parameters for light projection in host prim
  3117. /// </summary>
  3118. public void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb)
  3119. {
  3120. osSetProjectionParams(UUID.Zero.ToString(), projection, texture, fov, focus, amb);
  3121. }
  3122. /// <summary>
  3123. /// Set parameters for light projection with uuid of target prim
  3124. /// </summary>
  3125. public void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus, double amb)
  3126. {
  3127. CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
  3128. SceneObjectPart obj = null;
  3129. if (prim == UUID.Zero.ToString())
  3130. {
  3131. obj = m_host;
  3132. }
  3133. else
  3134. {
  3135. obj = World.GetSceneObjectPart(new UUID(prim));
  3136. if (obj == null)
  3137. return;
  3138. }
  3139. obj.Shape.ProjectionEntry = projection;
  3140. obj.Shape.ProjectionTextureUUID = new UUID(texture);
  3141. obj.Shape.ProjectionFOV = (float)fov;
  3142. obj.Shape.ProjectionFocus = (float)focus;
  3143. obj.Shape.ProjectionAmbiance = (float)amb;
  3144. obj.ParentGroup.HasGroupChanged = true;
  3145. obj.ScheduleFullUpdate();
  3146. }
  3147. /// <summary>
  3148. /// Like osGetAgents but returns enough info for a radar
  3149. /// </summary>
  3150. /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
  3151. public LSL_List osGetAvatarList()
  3152. {
  3153. CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");
  3154. LSL_List result = new LSL_List();
  3155. World.ForEachRootScenePresence(delegate (ScenePresence avatar)
  3156. {
  3157. if (avatar != null && !avatar.IsDeleted && avatar.UUID != m_host.OwnerID )
  3158. {
  3159. result.Add(new LSL_String(avatar.UUID.ToString()));
  3160. result.Add(new LSL_Vector(avatar.AbsolutePosition));
  3161. result.Add(new LSL_String(avatar.Name));
  3162. }
  3163. });
  3164. return result;
  3165. }
  3166. public LSL_List osGetNPCList()
  3167. {
  3168. CheckThreatLevel(ThreatLevel.None, "osGetNPCList");
  3169. LSL_List result = new LSL_List();
  3170. World.ForEachRootScenePresence(delegate (ScenePresence avatar)
  3171. {
  3172. // npcs are not childagents but that is now.
  3173. if (avatar != null && avatar.IsNPC && !avatar.IsDeleted && !avatar.IsChildAgent && !avatar.IsInTransit)
  3174. {
  3175. result.Add(new LSL_String(avatar.UUID.ToString()));
  3176. result.Add(new LSL_Vector(avatar.AbsolutePosition));
  3177. result.Add(new LSL_String(avatar.Name));
  3178. }
  3179. });
  3180. return result;
  3181. }
  3182. /// <summary>
  3183. /// Convert a unix time to a llGetTimestamp() like string
  3184. /// </summary>
  3185. /// <param name="unixTime"></param>
  3186. /// <returns></returns>
  3187. public LSL_String osUnixTimeToTimestamp(LSL_Integer time)
  3188. {
  3189. CheckThreatLevel(ThreatLevel.VeryLow, "osUnixTimeToTimestamp");
  3190. long baseTicks = 621355968000000000;
  3191. long tickResolution = 10000000;
  3192. long epochTicks = (time * tickResolution) + baseTicks;
  3193. DateTime date = new DateTime(epochTicks);
  3194. return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  3195. }
  3196. /// <summary>
  3197. /// Invite user to the group this object is set to
  3198. /// </summary>
  3199. /// <param name="agentId"></param>
  3200. /// <returns></returns>
  3201. public LSL_Integer osInviteToGroup(LSL_Key agentId)
  3202. {
  3203. CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup");
  3204. UUID agent = new UUID(agentId);
  3205. // groups module is required
  3206. IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
  3207. if (groupsModule == null) return ScriptBaseClass.FALSE;
  3208. // object has to be set to a group, but not group owned
  3209. if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
  3210. // object owner has to be in that group and required permissions
  3211. GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
  3212. if (member == null || (member.GroupPowers & (ulong)GroupPowers.Invite) == 0) return ScriptBaseClass.FALSE;
  3213. // check if agent is in that group already
  3214. //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
  3215. //if (member != null) return ScriptBaseClass.FALSE;
  3216. // invited agent has to be present in this scene
  3217. if (World.GetScenePresence(agent) == null) return ScriptBaseClass.FALSE;
  3218. groupsModule.InviteGroup(null, m_host.OwnerID, m_host.GroupID, agent, UUID.Zero);
  3219. return ScriptBaseClass.TRUE;
  3220. }
  3221. /// <summary>
  3222. /// Eject user from the group this object is set to
  3223. /// </summary>
  3224. /// <param name="agentId"></param>
  3225. /// <returns></returns>
  3226. public LSL_Integer osEjectFromGroup(LSL_Key agentId)
  3227. {
  3228. CheckThreatLevel(ThreatLevel.VeryLow, "osEjectFromGroup");
  3229. UUID agent = new UUID(agentId);
  3230. // groups module is required
  3231. IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
  3232. if (groupsModule == null) return ScriptBaseClass.FALSE;
  3233. // object has to be set to a group, but not group owned
  3234. if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
  3235. // object owner has to be in that group and required permissions
  3236. GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
  3237. if (member == null || (member.GroupPowers & (ulong)GroupPowers.Eject) == 0) return ScriptBaseClass.FALSE;
  3238. // agent has to be in that group
  3239. //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
  3240. //if (member == null) return ScriptBaseClass.FALSE;
  3241. // ejectee can be offline
  3242. groupsModule.EjectGroupMember(null, m_host.OwnerID, m_host.GroupID, agent);
  3243. return ScriptBaseClass.TRUE;
  3244. }
  3245. /// <summary>
  3246. /// Sets terrain estate texture
  3247. /// </summary>
  3248. /// <param name="level"></param>
  3249. /// <param name="texture"></param>
  3250. /// <returns></returns>
  3251. public void osSetTerrainTexture(int level, LSL_Key texture)
  3252. {
  3253. CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
  3254. //Check to make sure that the script's owner is the estate manager/master
  3255. //World.Permissions.GenericEstatePermission(
  3256. if (World.Permissions.IsGod(m_host.OwnerID))
  3257. {
  3258. if (level < 0 || level > 3)
  3259. return;
  3260. UUID textureID = new UUID();
  3261. if (!UUID.TryParse(texture, out textureID))
  3262. return;
  3263. // estate module is required
  3264. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  3265. if (estate != null)
  3266. estate.setEstateTerrainBaseTexture(level, textureID);
  3267. }
  3268. }
  3269. /// <summary>
  3270. /// Sets terrain heights of estate
  3271. /// </summary>
  3272. /// <param name="corner"></param>
  3273. /// <param name="low"></param>
  3274. /// <param name="high"></param>
  3275. /// <returns></returns>
  3276. public void osSetTerrainTextureHeight(int corner, double low, double high)
  3277. {
  3278. CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
  3279. //Check to make sure that the script's owner is the estate manager/master
  3280. //World.Permissions.GenericEstatePermission(
  3281. if (World.Permissions.IsGod(m_host.OwnerID))
  3282. {
  3283. if (corner < 0 || corner > 3)
  3284. return;
  3285. // estate module is required
  3286. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  3287. if (estate != null)
  3288. estate.setEstateTerrainTextureHeights(corner, (float)low, (float)high);
  3289. }
  3290. }
  3291. #region Attachment commands
  3292. public void osForceAttachToAvatar(int attachmentPoint)
  3293. {
  3294. CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
  3295. InitLSL();
  3296. m_LSL_Api.AttachToAvatar(attachmentPoint);
  3297. }
  3298. public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
  3299. {
  3300. CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory");
  3301. ForceAttachToAvatarFromInventory(m_host.OwnerID, itemName, attachmentPoint);
  3302. }
  3303. public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint)
  3304. {
  3305. CheckThreatLevel(ThreatLevel.VeryHigh, "osForceAttachToOtherAvatarFromInventory");
  3306. UUID avatarId;
  3307. if (!UUID.TryParse(rawAvatarId, out avatarId))
  3308. return;
  3309. ForceAttachToAvatarFromInventory(avatarId, itemName, attachmentPoint);
  3310. }
  3311. public void ForceAttachToAvatarFromInventory(UUID avatarId, string itemName, int attachmentPoint)
  3312. {
  3313. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3314. if (attachmentsModule == null)
  3315. return;
  3316. InitLSL();
  3317. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  3318. if (item == null)
  3319. {
  3320. m_LSL_Api.llSay(0, string.Format("Could not find object '{0}'", itemName));
  3321. throw new Exception(String.Format("The inventory item '{0}' could not be found", itemName));
  3322. }
  3323. if (item.InvType != (int)InventoryType.Object)
  3324. {
  3325. // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
  3326. // up the api reference.
  3327. if (m_LSL_Api != null)
  3328. m_LSL_Api.llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
  3329. throw new Exception(String.Format("The inventory item '{0}' is not an object", itemName));
  3330. }
  3331. ScenePresence sp = World.GetScenePresence(avatarId);
  3332. if (sp == null)
  3333. return;
  3334. string message;
  3335. InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID, out message);
  3336. if (newItem == null)
  3337. {
  3338. m_log.ErrorFormat(
  3339. "[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}: {4}",
  3340. itemName, m_host.Name, attachmentPoint, World.Name, message);
  3341. m_LSL_Api.llSay(0, message);
  3342. return;
  3343. }
  3344. attachmentsModule.RezSingleAttachmentFromInventory(sp, newItem.ID, (uint)attachmentPoint);
  3345. }
  3346. public void osForceDetachFromAvatar()
  3347. {
  3348. CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
  3349. InitLSL();
  3350. m_LSL_Api.DetachFromAvatar();
  3351. }
  3352. public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
  3353. {
  3354. CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments");
  3355. UUID targetUUID;
  3356. ScenePresence target;
  3357. LSL_List resp = new LSL_List();
  3358. if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
  3359. {
  3360. foreach (object point in attachmentPoints.Data)
  3361. {
  3362. LSL_Integer ipoint = new LSL_Integer(
  3363. (point is LSL_Integer || point is int || point is uint) ?
  3364. (int)point :
  3365. 0
  3366. );
  3367. resp.Add(ipoint);
  3368. if (ipoint == 0)
  3369. {
  3370. // indicates zero attachments
  3371. resp.Add(new LSL_Integer(0));
  3372. }
  3373. else
  3374. {
  3375. // gets the number of attachments on the attachment point
  3376. resp.Add(new LSL_Integer(target.GetAttachments((uint)ipoint).Count));
  3377. }
  3378. }
  3379. }
  3380. return resp;
  3381. }
  3382. public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options)
  3383. {
  3384. CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments");
  3385. UUID targetUUID;
  3386. if(!UUID.TryParse(avatar.ToString(), out targetUUID))
  3387. return;
  3388. if(targetUUID == UUID.Zero)
  3389. return;
  3390. ScenePresence target;
  3391. if(!World.TryGetScenePresence(targetUUID, out target))
  3392. return;
  3393. if(target.IsDeleted || target.IsInTransit)
  3394. return;
  3395. List<int> aps = new List<int>();
  3396. if(attachmentPoints.Length != 0)
  3397. {
  3398. foreach (object point in attachmentPoints.Data)
  3399. {
  3400. int ipoint;
  3401. if (int.TryParse(point.ToString(), out ipoint))
  3402. {
  3403. aps.Add(ipoint);
  3404. }
  3405. }
  3406. // parsing failed
  3407. if(aps.Count != attachmentPoints.Length)
  3408. return;
  3409. }
  3410. List<SceneObjectGroup> attachments = new List<SceneObjectGroup>();
  3411. bool msgAll;
  3412. bool invertPoints = (options & ScriptBaseClass.OS_ATTACH_MSG_INVERT_POINTS) != 0;
  3413. if(aps.Count == 0)
  3414. {
  3415. if(!invertPoints)
  3416. return;
  3417. msgAll = true;
  3418. invertPoints = false;
  3419. }
  3420. else
  3421. msgAll = aps.Contains(ScriptBaseClass.OS_ATTACH_MSG_ALL);
  3422. if (msgAll && invertPoints)
  3423. return;
  3424. if (msgAll || invertPoints)
  3425. {
  3426. attachments = target.GetAttachments();
  3427. }
  3428. else
  3429. {
  3430. foreach (int point in aps)
  3431. {
  3432. if (point > 0)
  3433. {
  3434. attachments.AddRange(target.GetAttachments((uint)point));
  3435. }
  3436. }
  3437. }
  3438. // if we have no attachments at this point, exit now
  3439. if (attachments.Count == 0)
  3440. {
  3441. return;
  3442. }
  3443. bool optionObjCreator = (options &
  3444. ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0;
  3445. bool optionScriptCreator = (options &
  3446. ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0;
  3447. UUID hostCreatorID = m_host.CreatorID;
  3448. UUID itemCreatorID = m_item.CreatorID;
  3449. foreach (SceneObjectGroup sog in attachments)
  3450. {
  3451. if(sog.IsDeleted || sog.inTransit)
  3452. continue;
  3453. if (invertPoints && aps.Contains((int)sog.AttachmentPoint))
  3454. continue;
  3455. UUID CreatorID = sog.RootPart.CreatorID;
  3456. if (optionObjCreator && CreatorID != hostCreatorID)
  3457. continue;
  3458. if (optionScriptCreator && CreatorID != itemCreatorID)
  3459. continue;
  3460. SceneObjectPart[] parts = sog.Parts;
  3461. foreach(SceneObjectPart p in parts)
  3462. MessageObject(p.UUID, message);
  3463. }
  3464. }
  3465. #endregion
  3466. /// <summary>
  3467. /// Checks if thing is a UUID.
  3468. /// </summary>
  3469. /// <param name="thing"></param>
  3470. /// <returns>1 if thing is a valid UUID, 0 otherwise</returns>
  3471. public LSL_Integer osIsUUID(string thing)
  3472. {
  3473. CheckThreatLevel();
  3474. UUID test;
  3475. return UUID.TryParse(thing, out test) ? 1 : 0;
  3476. }
  3477. /// <summary>
  3478. /// Wraps to Math.Min()
  3479. /// </summary>
  3480. /// <param name="a"></param>
  3481. /// <param name="b"></param>
  3482. /// <returns></returns>
  3483. public LSL_Float osMin(double a, double b)
  3484. {
  3485. CheckThreatLevel();
  3486. return Math.Min(a, b);
  3487. }
  3488. /// <summary>
  3489. /// Wraps to Math.max()
  3490. /// </summary>
  3491. /// <param name="a"></param>
  3492. /// <param name="b"></param>
  3493. /// <returns></returns>
  3494. public LSL_Float osMax(double a, double b)
  3495. {
  3496. CheckThreatLevel();
  3497. return Math.Max(a, b);
  3498. }
  3499. public LSL_Key osGetRezzingObject()
  3500. {
  3501. CheckThreatLevel(ThreatLevel.None, "osGetRezzingObject");
  3502. UUID rezID = m_host.ParentGroup.RezzerID;
  3503. if(rezID == UUID.Zero || m_host.ParentGroup.Scene.GetScenePresence(rezID) != null)
  3504. return new LSL_Key(UUID.Zero.ToString());
  3505. return new LSL_Key(rezID.ToString());
  3506. }
  3507. /// <summary>
  3508. /// Sets the response type for an HTTP request/response
  3509. /// </summary>
  3510. /// <returns></returns>
  3511. public void osSetContentType(LSL_Key id, string type)
  3512. {
  3513. CheckThreatLevel(ThreatLevel.Severe, "osSetContentType");
  3514. if (m_UrlModule != null)
  3515. m_UrlModule.HttpContentType(new UUID(id),type);
  3516. }
  3517. /// Shout an error if the object owner did not grant the script the specified permissions.
  3518. /// </summary>
  3519. /// <param name="perms"></param>
  3520. /// <returns>boolean indicating whether an error was shouted.</returns>
  3521. protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix)
  3522. {
  3523. bool fail = false;
  3524. if (m_item.PermsGranter != m_host.OwnerID)
  3525. {
  3526. fail = true;
  3527. OSSLShoutError(string.Format("{0}. Permissions not granted to owner.", errorPrefix));
  3528. }
  3529. else if ((m_item.PermsMask & perms) == 0)
  3530. {
  3531. fail = true;
  3532. OSSLShoutError(string.Format("{0}. Permissions not granted.", errorPrefix));
  3533. }
  3534. return fail;
  3535. }
  3536. protected void DropAttachment(bool checkPerms)
  3537. {
  3538. if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
  3539. {
  3540. return;
  3541. }
  3542. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3543. ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
  3544. if (attachmentsModule != null && sp != null)
  3545. {
  3546. attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId);
  3547. }
  3548. }
  3549. protected void DropAttachmentAt(bool checkPerms, LSL_Vector pos, LSL_Rotation rot)
  3550. {
  3551. if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
  3552. {
  3553. return;
  3554. }
  3555. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3556. ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
  3557. if (attachmentsModule != null && sp != null)
  3558. {
  3559. attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId, pos, rot);
  3560. }
  3561. }
  3562. public void osDropAttachment()
  3563. {
  3564. CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment");
  3565. DropAttachment(true);
  3566. }
  3567. public void osForceDropAttachment()
  3568. {
  3569. CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment");
  3570. DropAttachment(false);
  3571. }
  3572. public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
  3573. {
  3574. CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt");
  3575. DropAttachmentAt(true, pos, rot);
  3576. }
  3577. public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
  3578. {
  3579. CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt");
  3580. DropAttachmentAt(false, pos, rot);
  3581. }
  3582. public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
  3583. {
  3584. CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
  3585. UUID keyID;
  3586. UUID.TryParse(ID, out keyID);
  3587. // if we want the name to be used as a regular expression, ensure it is valid first.
  3588. if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
  3589. {
  3590. try
  3591. {
  3592. Regex.IsMatch("", name);
  3593. }
  3594. catch (Exception)
  3595. {
  3596. OSSLShoutError("Name regex is invalid.");
  3597. return -1;
  3598. }
  3599. }
  3600. // if we want the msg to be used as a regular expression, ensure it is valid first.
  3601. if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE)
  3602. {
  3603. try
  3604. {
  3605. Regex.IsMatch("", msg);
  3606. }
  3607. catch (Exception)
  3608. {
  3609. OSSLShoutError("Message regex is invalid.");
  3610. return -1;
  3611. }
  3612. }
  3613. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  3614. return (wComm == null) ? -1 : wComm.Listen(
  3615. m_host.LocalId,
  3616. m_item.ItemID,
  3617. m_host.UUID,
  3618. channelID,
  3619. name,
  3620. keyID,
  3621. msg,
  3622. regexBitfield
  3623. );
  3624. }
  3625. public LSL_Integer osRegexIsMatch(string input, string pattern)
  3626. {
  3627. CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
  3628. try
  3629. {
  3630. return Regex.IsMatch(input, pattern) ? 1 : 0;
  3631. }
  3632. catch (Exception)
  3633. {
  3634. OSSLShoutError("Possible invalid regular expression detected.");
  3635. return 0;
  3636. }
  3637. }
  3638. public LSL_String osRequestURL(LSL_List options)
  3639. {
  3640. CheckThreatLevel(ThreatLevel.Moderate, "osRequestSecureURL");
  3641. Hashtable opts = new Hashtable();
  3642. for (int i = 0 ; i < options.Length ; i++)
  3643. {
  3644. object opt = options.Data[i];
  3645. if (opt.ToString() == "allowXss")
  3646. opts["allowXss"] = true;
  3647. }
  3648. if (m_UrlModule != null)
  3649. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString();
  3650. return UUID.Zero.ToString();
  3651. }
  3652. public LSL_String osRequestSecureURL(LSL_List options)
  3653. {
  3654. CheckThreatLevel(ThreatLevel.Moderate, "osRequestSecureURL");
  3655. Hashtable opts = new Hashtable();
  3656. for (int i = 0 ; i < options.Length ; i++)
  3657. {
  3658. object opt = options.Data[i];
  3659. if (opt.ToString() == "allowXss")
  3660. opts["allowXss"] = true;
  3661. }
  3662. if (m_UrlModule != null)
  3663. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString();
  3664. return UUID.Zero.ToString();
  3665. }
  3666. public void osCollisionSound(string impact_sound, double impact_volume)
  3667. {
  3668. CheckThreatLevel();
  3669. if(impact_sound == "")
  3670. {
  3671. m_host.CollisionSoundVolume = (float)impact_volume;
  3672. m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
  3673. if(impact_volume == 0.0)
  3674. m_host.CollisionSoundType = -1; // disable all sounds
  3675. else if(impact_volume == 1.0f)
  3676. m_host.CollisionSoundType = 0; // full return to default sounds
  3677. else
  3678. m_host.CollisionSoundType = 2; // default sounds with volume
  3679. m_host.aggregateScriptEvents();
  3680. return;
  3681. }
  3682. // TODO: Parameter check logic required.
  3683. UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
  3684. if(soundId != UUID.Zero)
  3685. {
  3686. m_host.CollisionSound = soundId;
  3687. m_host.CollisionSoundVolume = (float)impact_volume;
  3688. m_host.CollisionSoundType = 1;
  3689. }
  3690. else
  3691. m_host.CollisionSoundType = -1;
  3692. m_host.aggregateScriptEvents();
  3693. }
  3694. // still not very usefull, detector is lost on rez, restarts, etc
  3695. public void osVolumeDetect(int detect)
  3696. {
  3697. CheckThreatLevel();
  3698. if (m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted || m_host.ParentGroup.IsAttachment)
  3699. return;
  3700. m_host.ScriptSetVolumeDetect(detect != 0);
  3701. }
  3702. /// <summary>
  3703. /// Get inertial data
  3704. /// </summary>
  3705. /// <remarks>
  3706. /// </remarks>
  3707. /// <returns>
  3708. /// a LSL list with contents:
  3709. /// LSL_Float mass, the total mass of a linkset
  3710. /// LSL_Vector CenterOfMass, center mass relative to root prim
  3711. /// LSL_Vector Inertia, elements of diagonal of inertia Ixx,Iyy,Izz divided by total mass
  3712. /// LSL_Vector aux, elements of upper triagle of inertia Ixy (= Iyx), Ixz (= Izx), Iyz(= Izy) divided by total mass
  3713. /// </returns>
  3714. public LSL_List osGetInertiaData()
  3715. {
  3716. CheckThreatLevel();
  3717. LSL_List result = new LSL_List();
  3718. float TotalMass;
  3719. Vector3 CenterOfMass;
  3720. Vector3 Inertia;
  3721. Vector4 aux;
  3722. SceneObjectGroup sog = m_host.ParentGroup;
  3723. if(sog== null || sog.IsDeleted)
  3724. return result;
  3725. sog.GetInertiaData(out TotalMass, out CenterOfMass, out Inertia, out aux );
  3726. if(TotalMass > 0)
  3727. {
  3728. float t = 1.0f/TotalMass;
  3729. Inertia.X *= t;
  3730. Inertia.Y *= t;
  3731. Inertia.Z *= t;
  3732. aux.X *= t;
  3733. aux.Y *= t;
  3734. aux.Z *= t;
  3735. }
  3736. result.Add(new LSL_Float(TotalMass));
  3737. result.Add(new LSL_Vector(CenterOfMass.X, CenterOfMass.Y, CenterOfMass.Z));
  3738. result.Add(new LSL_Vector(Inertia.X, Inertia.Y, Inertia.Z));
  3739. result.Add(new LSL_Vector(aux.X, aux.Y, aux.Z));
  3740. return result;
  3741. }
  3742. /// <summary>
  3743. /// set inertial data
  3744. /// replaces the automatic calculation of mass, center of mass and inertia
  3745. ///
  3746. /// </summary>
  3747. /// <param name="Mass">total mass of linkset</param>
  3748. /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
  3749. /// <param name="principalInertiaScaled">moment of inertia relative to principal axis and center of mass,Ixx, Iyy, Izz divided by mass</param>
  3750. /// <param name="lslrot">rotation of the inertia, relative to local axis</param>
  3751. /// <remarks>
  3752. /// the inertia argument is is inertia divided by mass, so corresponds only to the geometric distribution of mass and both can be changed independently.
  3753. /// </remarks>
  3754. public void osSetInertia(LSL_Float mass, LSL_Vector centerOfMass, LSL_Vector principalInertiaScaled, LSL_Rotation lslrot)
  3755. {
  3756. CheckThreatLevel();
  3757. SceneObjectGroup sog = m_host.ParentGroup;
  3758. if(sog== null || sog.IsDeleted)
  3759. return;
  3760. if(mass < 0 || principalInertiaScaled.x < 0 || principalInertiaScaled.y < 0 || principalInertiaScaled.z < 0)
  3761. return;
  3762. // need more checks
  3763. Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
  3764. Vector3 Inertia;
  3765. float m = (float)mass;
  3766. Inertia.X = m * (float)principalInertiaScaled.x;
  3767. Inertia.Y = m * (float)principalInertiaScaled.y;
  3768. Inertia.Z = m * (float)principalInertiaScaled.z;
  3769. Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.y, (float)lslrot.s);
  3770. rot.Normalize();
  3771. sog.SetInertiaData(m, CenterOfMass, Inertia, rot );
  3772. }
  3773. /// <summary>
  3774. /// set inertial data as a sphere
  3775. /// replaces the automatic calculation of mass, center of mass and inertia
  3776. ///
  3777. /// </summary>
  3778. /// <param name="Mass">total mass of linkset</param>
  3779. /// <param name="boxsize">size of the Box</param>
  3780. /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
  3781. /// <param name="lslrot">rotation of the box, and so inertia, relative to local axis</param>
  3782. /// <remarks>
  3783. /// </remarks>
  3784. public void osSetInertiaAsBox(LSL_Float mass, LSL_Vector boxSize, LSL_Vector centerOfMass, LSL_Rotation lslrot)
  3785. {
  3786. CheckThreatLevel();
  3787. SceneObjectGroup sog = m_host.ParentGroup;
  3788. if(sog== null || sog.IsDeleted)
  3789. return;
  3790. if(mass < 0)
  3791. return;
  3792. // need more checks
  3793. Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
  3794. Vector3 Inertia;
  3795. float lx = (float)boxSize.x;
  3796. float ly = (float)boxSize.y;
  3797. float lz = (float)boxSize.z;
  3798. float m = (float)mass;
  3799. float t = m / 12.0f;
  3800. Inertia.X = t * (ly*ly + lz*lz);
  3801. Inertia.Y = t * (lx*lx + lz*lz);
  3802. Inertia.Z = t * (lx*lx + ly*ly);
  3803. Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.z, (float)lslrot.s);
  3804. rot.Normalize();
  3805. sog.SetInertiaData(m, CenterOfMass, Inertia, rot );
  3806. }
  3807. /// <summary>
  3808. /// set inertial data as a sphere
  3809. /// replaces the automatic calculation of mass, center of mass and inertia
  3810. ///
  3811. /// </summary>
  3812. /// <param name="Mass">total mass of linkset</param>
  3813. /// <param name="radius">radius of the sphere</param>
  3814. /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
  3815. /// <remarks>
  3816. /// </remarks>
  3817. public void osSetInertiaAsSphere(LSL_Float mass, LSL_Float radius, LSL_Vector centerOfMass)
  3818. {
  3819. CheckThreatLevel();
  3820. SceneObjectGroup sog = m_host.ParentGroup;
  3821. if(sog== null || sog.IsDeleted)
  3822. return;
  3823. if(mass < 0)
  3824. return;
  3825. // need more checks
  3826. Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
  3827. Vector3 Inertia;
  3828. float r = (float)radius;
  3829. float m = (float)mass;
  3830. float t = 0.4f * m * r * r;
  3831. Inertia.X = t;
  3832. Inertia.Y = t;
  3833. Inertia.Z = t;
  3834. sog.SetInertiaData(m, CenterOfMass, Inertia, new Vector4(0f, 0f, 0f,1.0f));
  3835. }
  3836. /// <summary>
  3837. /// set inertial data as a cylinder
  3838. /// replaces the automatic calculation of mass, center of mass and inertia
  3839. ///
  3840. /// </summary>
  3841. /// <param name="Mass">total mass of linkset</param>
  3842. /// <param name="radius">radius of the cylinder</param>
  3843. /// <param name="lenght">lenght of the cylinder</param>
  3844. /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
  3845. /// <param name="lslrot">rotation of the cylinder, and so inertia, relative to local axis</param>
  3846. /// <remarks>
  3847. /// cylinder axis aligned with Z axis. For other orientations provide the rotation.
  3848. /// </remarks>
  3849. public void osSetInertiaAsCylinder(LSL_Float mass, LSL_Float radius, LSL_Float lenght, LSL_Vector centerOfMass, LSL_Rotation lslrot)
  3850. {
  3851. CheckThreatLevel();
  3852. SceneObjectGroup sog = m_host.ParentGroup;
  3853. if(sog== null || sog.IsDeleted)
  3854. return;
  3855. if(mass < 0)
  3856. return;
  3857. // need more checks
  3858. Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
  3859. Vector3 Inertia;
  3860. float m = (float)mass;
  3861. float r = (float)radius;
  3862. r *= r;
  3863. Inertia.Z = 0.5f * m * r;
  3864. float t = (float)lenght;
  3865. t *= t;
  3866. t += 3.0f * r;
  3867. t *= 8.333333e-2f * m;
  3868. Inertia.X = t;
  3869. Inertia.Y = t;
  3870. Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.z, (float)lslrot.s);
  3871. rot.Normalize();
  3872. sog.SetInertiaData(m, CenterOfMass, Inertia, rot);
  3873. }
  3874. /// <summary>
  3875. /// removes inertial data manual override
  3876. /// default automatic calculation is used again
  3877. ///
  3878. /// </summary>
  3879. public void osClearInertia()
  3880. {
  3881. CheckThreatLevel();
  3882. SceneObjectGroup sog = m_host.ParentGroup;
  3883. if(sog== null || sog.IsDeleted)
  3884. return;
  3885. sog.SetInertiaData(-1, Vector3.Zero, Vector3.Zero, Vector4.Zero );
  3886. }
  3887. private bool checkAllowObjectTPbyLandOwner(Vector3 pos)
  3888. {
  3889. ILandObject land = World.LandChannel.GetLandObject(pos);
  3890. if(land == null)
  3891. return true;
  3892. LandData landdata = land.LandData;
  3893. if(landdata == null)
  3894. return true;
  3895. UUID hostOwner = m_host.OwnerID;
  3896. if(landdata.OwnerID == hostOwner)
  3897. return true;
  3898. EstateSettings es = World.RegionInfo.EstateSettings;
  3899. if(es != null && es.IsEstateManagerOrOwner(hostOwner))
  3900. return true;
  3901. if(!landdata.IsGroupOwned)
  3902. return false;
  3903. UUID landGroup = landdata.GroupID;
  3904. if(landGroup == UUID.Zero)
  3905. return false;
  3906. if(landGroup == m_host.GroupID)
  3907. return true;
  3908. return false;
  3909. }
  3910. /// <summary>
  3911. /// teleports a object (full linkset)
  3912. /// </summary>
  3913. /// <param name="objectUUID">the id of the linkset to teleport</param>
  3914. /// <param name="targetPos">target position</param>
  3915. /// <param name="rotation"> a rotation to apply</param>
  3916. /// <param name="flags">several flags/param>
  3917. /// <remarks>
  3918. /// only does teleport local to region
  3919. /// if object has scripts, owner must have rights to run scripts on target location
  3920. /// object owner must have rights to enter ojects on target location
  3921. /// target location parcel must have enought free prims capacity for the linkset prims
  3922. /// all avatars siting on the object must have access to target location
  3923. /// has a cool down time. retries before expire reset it
  3924. /// fail conditions are silent ignored
  3925. /// </remarks>
  3926. public LSL_Integer osTeleportObject(LSL_Key objectUUID, LSL_Vector targetPos, LSL_Rotation rotation, LSL_Integer flags)
  3927. {
  3928. CheckThreatLevel(ThreatLevel.Severe, "osTeleportObject");
  3929. UUID objUUID;
  3930. if (!UUID.TryParse(objectUUID, out objUUID))
  3931. {
  3932. OSSLShoutError("osTeleportObject() invalid object Key");
  3933. return -1;
  3934. }
  3935. SceneObjectGroup sog = World.GetSceneObjectGroup(objUUID);
  3936. if(sog== null || sog.IsDeleted || sog.inTransit)
  3937. return -1;
  3938. if(sog.OwnerID != m_host.OwnerID)
  3939. {
  3940. Vector3 pos = sog.AbsolutePosition;
  3941. if(!checkAllowObjectTPbyLandOwner(pos))
  3942. return -1;
  3943. }
  3944. UUID myid = m_host.ParentGroup.UUID;
  3945. return sog.TeleportObject(myid, targetPos, rotation, flags);
  3946. // a delay here may break vehicles
  3947. }
  3948. public LSL_Integer osGetLinkNumber(LSL_String name)
  3949. {
  3950. CheckThreatLevel();
  3951. SceneObjectGroup sog = m_host.ParentGroup;
  3952. if(sog== null || sog.IsDeleted)
  3953. return -1;
  3954. return sog.GetLinkNumber(name);
  3955. }
  3956. // rounds to the nearest number with provided number of decimal places
  3957. public LSL_Float osRound(LSL_Float value, LSL_Integer ndigits)
  3958. {
  3959. if(ndigits <= 0)
  3960. return Math.Round(value, MidpointRounding.AwayFromZero);
  3961. if(ndigits > 15)
  3962. ndigits = 15;
  3963. return Math.Round(value, ndigits, MidpointRounding.AwayFromZero);
  3964. }
  3965. public LSL_Float osVecMagSquare(LSL_Vector a)
  3966. {
  3967. return LSL_Vector.MagSquare(a);
  3968. }
  3969. public LSL_Float osVecDistSquare(LSL_Vector a, LSL_Vector b)
  3970. {
  3971. return LSL_Vector.MagSquare(a - b);
  3972. }
  3973. // returns the angle between 2 vectors 0 to pi
  3974. public LSL_Float osAngleBetween(LSL_Vector a, LSL_Vector b)
  3975. {
  3976. double dot = LSL_Vector.Dot(a,b);
  3977. double mcross = LSL_Vector.Mag(LSL_Vector.Cross(a,b));
  3978. return Math.Atan2(mcross, dot);
  3979. }
  3980. public void osAdjustSoundVolume(LSL_Integer linknum, LSL_Float volume)
  3981. {
  3982. m_host.AddScriptLPS(1);
  3983. SceneObjectPart sop = GetSingleLinkPart(linknum);
  3984. if(sop == null)
  3985. return;
  3986. sop.AdjustSoundGain(volume);
  3987. }
  3988. public void osSetSoundRadius(LSL_Integer linknum, LSL_Float radius)
  3989. {
  3990. m_host.AddScriptLPS(1);
  3991. SceneObjectPart sop = GetSingleLinkPart(linknum);
  3992. if(sop == null)
  3993. return;
  3994. sop.SoundRadius = radius;
  3995. }
  3996. public void osPlaySound(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
  3997. {
  3998. m_host.AddScriptLPS(1);
  3999. if (m_SoundModule == null)
  4000. return;
  4001. SceneObjectPart sop = GetSingleLinkPart(linknum);
  4002. if(sop == null)
  4003. return;
  4004. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
  4005. if (soundID == UUID.Zero)
  4006. return;
  4007. // send the sound, once, to all clients in range
  4008. m_SoundModule.SendSound(sop.UUID, soundID, volume, false, 0, false, false);
  4009. }
  4010. public void osLoopSound(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
  4011. {
  4012. m_host.AddScriptLPS(1);
  4013. if (m_SoundModule == null)
  4014. return;
  4015. SceneObjectPart sop = GetSingleLinkPart(linknum);
  4016. if(sop == null)
  4017. return;
  4018. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
  4019. if (soundID == UUID.Zero)
  4020. return;
  4021. m_SoundModule.LoopSound(sop.UUID, soundID, volume, false,false);
  4022. }
  4023. public void osLoopSoundMaster(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
  4024. {
  4025. m_host.AddScriptLPS(1);
  4026. if (m_SoundModule == null)
  4027. return;
  4028. SceneObjectPart sop = GetSingleLinkPart(linknum);
  4029. if(sop == null)
  4030. return;
  4031. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
  4032. if (soundID == UUID.Zero)
  4033. return;
  4034. m_SoundModule.LoopSound(sop.UUID, soundID, volume, true, false);
  4035. }
  4036. public void osLoopSoundSlave(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
  4037. {
  4038. m_host.AddScriptLPS(1);
  4039. if (m_SoundModule == null)
  4040. return;
  4041. SceneObjectPart sop = GetSingleLinkPart(linknum);
  4042. if(sop == null)
  4043. return;
  4044. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
  4045. if (soundID == UUID.Zero)
  4046. return;
  4047. m_SoundModule.LoopSound(sop.UUID, soundID, volume, false, true);
  4048. }
  4049. public void osPlaySoundSlave(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
  4050. {
  4051. m_host.AddScriptLPS(1);
  4052. if (m_SoundModule == null)
  4053. return;
  4054. SceneObjectPart sop = GetSingleLinkPart(linknum);
  4055. if(sop == null)
  4056. return;
  4057. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
  4058. if (soundID == UUID.Zero)
  4059. return;
  4060. // send the sound, once, to all clients in range
  4061. m_SoundModule.SendSound(sop.UUID, soundID, volume, false, 0, true, false);
  4062. }
  4063. public void osTriggerSound(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
  4064. {
  4065. m_host.AddScriptLPS(1);
  4066. if (m_SoundModule == null)
  4067. return;
  4068. SceneObjectPart sop = GetSingleLinkPart(linknum);
  4069. if(sop == null)
  4070. return;
  4071. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
  4072. if (soundID == UUID.Zero)
  4073. return;
  4074. // send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory.
  4075. m_SoundModule.SendSound(sop.UUID, soundID, volume, true, 0, false, false);
  4076. }
  4077. public void osTriggerSoundLimited(LSL_Integer linknum, LSL_String sound, LSL_Float volume,
  4078. LSL_Vector top_north_east, LSL_Vector bottom_south_west)
  4079. {
  4080. m_host.AddScriptLPS(1);
  4081. if (m_SoundModule == null)
  4082. return;
  4083. SceneObjectPart sop = GetSingleLinkPart(linknum);
  4084. if(sop == null)
  4085. return;
  4086. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
  4087. if (soundID == UUID.Zero)
  4088. return;
  4089. m_SoundModule.TriggerSoundLimited(sop.UUID, soundID, volume,
  4090. bottom_south_west, top_north_east);
  4091. }
  4092. public void osStopSound(LSL_Integer linknum)
  4093. {
  4094. m_host.AddScriptLPS(1);
  4095. if (m_SoundModule == null)
  4096. return;
  4097. SceneObjectPart sop = GetSingleLinkPart(linknum);
  4098. if(sop == null)
  4099. return;
  4100. m_SoundModule.StopSound(sop.UUID);
  4101. }
  4102. public void osPreloadSound(LSL_Integer linknum, LSL_String sound)
  4103. {
  4104. m_host.AddScriptLPS(1);
  4105. if (m_SoundModule == null)
  4106. return;
  4107. SceneObjectPart sop = GetSingleLinkPart(linknum);
  4108. if(sop == null)
  4109. return;
  4110. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
  4111. if (soundID == UUID.Zero)
  4112. return;
  4113. m_SoundModule.PreloadSound(sop.UUID, soundID);
  4114. ScriptSleep(1000);
  4115. }
  4116. // get only one part
  4117. private SceneObjectPart GetSingleLinkPart(int linkType)
  4118. {
  4119. if (m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  4120. return null;
  4121. switch (linkType)
  4122. {
  4123. case ScriptBaseClass.LINK_SET:
  4124. case ScriptBaseClass.LINK_ALL_OTHERS:
  4125. case ScriptBaseClass.LINK_ALL_CHILDREN:
  4126. return null;
  4127. case 0:
  4128. case ScriptBaseClass.LINK_ROOT:
  4129. return m_host.ParentGroup.RootPart;
  4130. case ScriptBaseClass.LINK_THIS:
  4131. return m_host;
  4132. default:
  4133. if(linkType < 0)
  4134. return null;
  4135. return m_host.ParentGroup.GetLinkNumPart(linkType);
  4136. }
  4137. }
  4138. // funtions to retrieve user country
  4139. // adaptation cm* counter parts from Avination Careminster extensions API
  4140. // included in Avination code contribution
  4141. // for now users country can only be set directly on DB
  4142. public LSL_String osDetectedCountry(LSL_Integer number)
  4143. {
  4144. m_host.AddScriptLPS(1);
  4145. CheckThreatLevel(ThreatLevel.Moderate, "osDetectedCountry");
  4146. if (World.UserAccountService == null)
  4147. return String.Empty;
  4148. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  4149. if (detectedParams == null)
  4150. return String.Empty;
  4151. UUID key = detectedParams.Key;
  4152. if (key == UUID.Zero)
  4153. return String.Empty;
  4154. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
  4155. return account.UserCountry;
  4156. }
  4157. public LSL_String osGetAgentCountry(LSL_Key id)
  4158. {
  4159. m_host.AddScriptLPS(1);
  4160. CheckThreatLevel(ThreatLevel.Moderate, "osGetAgentCountry");
  4161. if (World.UserAccountService == null)
  4162. return String.Empty;
  4163. UUID key;
  4164. if (!UUID.TryParse(id, out key))
  4165. return String.Empty;
  4166. if (key == UUID.Zero)
  4167. return String.Empty;
  4168. //if owner is not god, target must be in region, or nearby regions
  4169. if (!World.Permissions.IsGod(m_host.OwnerID))
  4170. {
  4171. ScenePresence sp = World.GetScenePresence(key);
  4172. if(sp == null)
  4173. return String.Empty;
  4174. }
  4175. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
  4176. return account.UserCountry;
  4177. }
  4178. public LSL_String osStringSubString(LSL_String src, LSL_Integer offset)
  4179. {
  4180. m_host.AddScriptLPS(1);
  4181. CheckThreatLevel();
  4182. if (string.IsNullOrEmpty(src))
  4183. return "";
  4184. if (offset >= src.Length)
  4185. return "";
  4186. if (offset <= 0)
  4187. return src;
  4188. return ((string)src).Substring(offset);
  4189. }
  4190. public LSL_String osStringSubString(LSL_String src, LSL_Integer offset, LSL_Integer length)
  4191. {
  4192. m_host.AddScriptLPS(1);
  4193. CheckThreatLevel();
  4194. if (string.IsNullOrEmpty(src))
  4195. return "";
  4196. if (length <= 0 || offset >= src.Length)
  4197. return "";
  4198. if (offset <= 0)
  4199. {
  4200. if(length == src.Length)
  4201. return src;
  4202. offset = 0;
  4203. }
  4204. if (length > src.Length - offset)
  4205. length = src.Length - offset;
  4206. return ((string)src).Substring(offset, length);
  4207. }
  4208. public LSL_Integer osStringStartsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase)
  4209. {
  4210. m_host.AddScriptLPS(1);
  4211. CheckThreatLevel();
  4212. if (string.IsNullOrEmpty(src))
  4213. return 0;
  4214. if (string.IsNullOrEmpty(value))
  4215. return 0;
  4216. bool ign = (ignorecase != 0);
  4217. return ((string)src).StartsWith(value, ignorecase, Culture.GetDefaultCurrentCulture()) ? 1 : 0;
  4218. }
  4219. public LSL_Integer osStringEndsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase)
  4220. {
  4221. m_host.AddScriptLPS(1);
  4222. CheckThreatLevel();
  4223. if (string.IsNullOrEmpty(src))
  4224. return 0;
  4225. if (string.IsNullOrEmpty(value))
  4226. return 0;
  4227. bool ign = (ignorecase != 0);
  4228. return ((string)src).EndsWith(value, ign, Culture.GetDefaultCurrentCulture()) ? 1 : 0;
  4229. }
  4230. public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase)
  4231. {
  4232. m_host.AddScriptLPS(1);
  4233. CheckThreatLevel();
  4234. if (string.IsNullOrEmpty(src))
  4235. return -1;
  4236. if (string.IsNullOrEmpty(value))
  4237. return -1;
  4238. if (ignorecase == 0)
  4239. return ((string)src).IndexOf(value, StringComparison.CurrentCulture);
  4240. return ((string)src).IndexOf(value, StringComparison.CurrentCultureIgnoreCase);
  4241. }
  4242. public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value,
  4243. LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase)
  4244. {
  4245. m_host.AddScriptLPS(1);
  4246. CheckThreatLevel();
  4247. if (string.IsNullOrEmpty(src))
  4248. return -1;
  4249. if (string.IsNullOrEmpty(value))
  4250. return -1;
  4251. if (offset >= src.Length)
  4252. return -1;
  4253. else if (offset < 0)
  4254. offset = 0;
  4255. if (count <= 0)
  4256. count = src.Length - offset;
  4257. else if (count > src.Length - offset)
  4258. count = src.Length - offset;
  4259. if (ignorecase == 0)
  4260. return ((string)src).IndexOf(value, offset, count, StringComparison.CurrentCulture);
  4261. return ((string)src).IndexOf(value, offset, count, StringComparison.CurrentCultureIgnoreCase);
  4262. }
  4263. public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase)
  4264. {
  4265. m_host.AddScriptLPS(1);
  4266. CheckThreatLevel();
  4267. if (string.IsNullOrEmpty(src))
  4268. return -1;
  4269. if (string.IsNullOrEmpty(value))
  4270. return -1;
  4271. if (ignorecase == 0)
  4272. return ((string)src).LastIndexOf(value, StringComparison.CurrentCulture);
  4273. return ((string)src).LastIndexOf(value, StringComparison.CurrentCultureIgnoreCase);
  4274. }
  4275. public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value,
  4276. LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase)
  4277. {
  4278. m_host.AddScriptLPS(1);
  4279. CheckThreatLevel();
  4280. if (string.IsNullOrEmpty(src))
  4281. return -1;
  4282. if (string.IsNullOrEmpty(value))
  4283. return -1;
  4284. if (offset >= src.Length)
  4285. return -1;
  4286. if (offset < 0)
  4287. offset = 0;
  4288. if (count <= 0)
  4289. count = src.Length - offset;
  4290. else if (count > src.Length - offset)
  4291. count = src.Length - offset;
  4292. if (ignorecase == 0)
  4293. return ((string)src).LastIndexOf(value, offset, count, StringComparison.CurrentCulture);
  4294. return ((string)src).LastIndexOf(value, offset, count, StringComparison.CurrentCultureIgnoreCase);
  4295. }
  4296. public LSL_String osStringRemove(LSL_String src, LSL_Integer offset, LSL_Integer count)
  4297. {
  4298. if (string.IsNullOrEmpty(src))
  4299. return "";
  4300. if (offset >= src.Length)
  4301. return "";
  4302. if (offset < 0)
  4303. offset = 0;
  4304. if (count <= 0)
  4305. count = src.Length - offset;
  4306. else if (count > src.Length - offset)
  4307. count = src.Length - offset;
  4308. if (count >= src.Length)
  4309. return "";
  4310. return ((string)src).Remove(offset, count);
  4311. }
  4312. public LSL_String osStringReplace(LSL_String src, LSL_String oldvalue, LSL_String newvalue)
  4313. {
  4314. if (string.IsNullOrEmpty(src))
  4315. return "";
  4316. if (string.IsNullOrEmpty(oldvalue))
  4317. return "";
  4318. if (string.IsNullOrEmpty(newvalue))
  4319. newvalue = null;
  4320. return ((string)src).Replace(oldvalue, newvalue);
  4321. }
  4322. public LSL_Integer osApproxEquals(LSL_Float a, LSL_Float b)
  4323. {
  4324. if (a > b + 1.0e-6 || a < b - 1.0e-6)
  4325. return 0;
  4326. return 1;
  4327. }
  4328. public LSL_Integer osApproxEquals(LSL_Float a, LSL_Float b, LSL_Float margin)
  4329. {
  4330. double e = Math.Abs(margin);
  4331. if (a > b + e || a < b - e)
  4332. return 0;
  4333. return 1;
  4334. }
  4335. public LSL_Integer osApproxEquals(LSL_Vector va, LSL_Vector vb)
  4336. {
  4337. double a = va.x;
  4338. double b = vb.x;
  4339. if (a > b + 1.0e-6 || a < b - 1.0e-6)
  4340. return 0;
  4341. a = va.y;
  4342. b = vb.y;
  4343. if (a > b + 1.0e-6 || a < b - 1.0e-6)
  4344. return 0;
  4345. a = va.z;
  4346. b = vb.z;
  4347. if (a > b + 1.0e-6 || a < b - 1.0e-6)
  4348. return 0;
  4349. return 1;
  4350. }
  4351. public LSL_Integer osApproxEquals(LSL_Vector va, LSL_Vector vb, LSL_Float margin)
  4352. {
  4353. double e = Math.Abs(margin);
  4354. double a = va.x;
  4355. double b = vb.x;
  4356. if (a > b + e || a < b - e)
  4357. return 0;
  4358. a = va.y;
  4359. b = vb.y;
  4360. if (a > b + e || a < b - e)
  4361. return 0;
  4362. a = va.z;
  4363. b = vb.z;
  4364. if (a > b + e || a < b - e)
  4365. return 0;
  4366. return 1;
  4367. }
  4368. public LSL_Integer osApproxEquals(LSL_Rotation ra, LSL_Rotation rb)
  4369. {
  4370. double a = ra.x;
  4371. double b = rb.x;
  4372. if (a > b + 1.0e-6 || a < b - 1.0e-6)
  4373. return 0;
  4374. a = ra.y;
  4375. b = rb.y;
  4376. if (a > b + 1.0e-6 || a < b - 1.0e-6)
  4377. return 0;
  4378. a = ra.z;
  4379. b = rb.z;
  4380. if (a > b + 1.0e-6 || a < b - 1.0e-6)
  4381. return 0;
  4382. a = ra.s;
  4383. b = rb.s;
  4384. if (a > b + 1.0e-6 || a < b - 1.0e-6)
  4385. return 0;
  4386. return 1;
  4387. }
  4388. public LSL_Integer osApproxEquals(LSL_Rotation ra, LSL_Rotation rb, LSL_Float margin)
  4389. {
  4390. double e = Math.Abs(margin);
  4391. double a = ra.x;
  4392. double b = rb.x;
  4393. if (a > b + e || a < b - e)
  4394. return 0;
  4395. a = ra.y;
  4396. b = rb.y;
  4397. if (a > b + e || a < b - e)
  4398. return 0;
  4399. a = ra.z;
  4400. b = rb.z;
  4401. if (a > b + e || a < b - e)
  4402. return 0;
  4403. a = ra.s;
  4404. b = rb.s;
  4405. if (a > b + e || a < b - e)
  4406. return 0;
  4407. return 1;
  4408. }
  4409. public LSL_Key osGetInventoryLastOwner(LSL_String itemNameorid)
  4410. {
  4411. m_host.AddScriptLPS(1);
  4412. TaskInventoryItem item = null;
  4413. UUID itemID;
  4414. if (UUID.TryParse(itemNameorid, out itemID))
  4415. item = m_host.Inventory.GetInventoryItem(itemID);
  4416. else
  4417. item = m_host.Inventory.GetInventoryItem(itemNameorid);
  4418. if (item == null)
  4419. return UUID.Zero.ToString();
  4420. UUID id = item.LastOwnerID;
  4421. if(id == UUID.Zero)
  4422. id= item.OwnerID;
  4423. return id.ToString();
  4424. }
  4425. public LSL_String osGetInventoryName(LSL_Key itemId)
  4426. {
  4427. m_host.AddScriptLPS(1);
  4428. TaskInventoryItem item = null;
  4429. UUID itemID;
  4430. if (UUID.TryParse(itemId, out itemID))
  4431. item = m_host.Inventory.GetInventoryItem(itemID);
  4432. if (item == null)
  4433. return String.Empty;
  4434. return item.Name;
  4435. }
  4436. public LSL_String osGetInventoryDesc(LSL_String itemNameorid)
  4437. {
  4438. m_host.AddScriptLPS(1);
  4439. TaskInventoryItem item = null;
  4440. UUID itemID;
  4441. if (UUID.TryParse(itemNameorid, out itemID))
  4442. item = m_host.Inventory.GetInventoryItem(itemID);
  4443. else
  4444. item = m_host.Inventory.GetInventoryItem(itemNameorid);
  4445. if (item == null)
  4446. return String.Empty;
  4447. return item.Description;
  4448. }
  4449. public LSL_Key osGetLastChangedEventKey()
  4450. {
  4451. m_host.AddScriptLPS(1);
  4452. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
  4453. if (detectedParams == null)
  4454. return String.Empty;
  4455. return detectedParams.Key.ToString();
  4456. }
  4457. }
  4458. }