OSSL_Api.cs 214 KB

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