OSSL_Api.cs 214 KB

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