1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130 |
- /*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- using log4net;
- using Nini.Config;
- using OpenMetaverse;
- using OpenMetaverse.StructuredData;
- using OpenSim.Framework;
- using OpenSim.Region.Framework.Interfaces;
- using OpenSim.Region.Framework.Scenes;
- using OpenSim.Region.Framework.Scenes.Scripting;
- using OpenSim.Region.ScriptEngine.Interfaces;
- using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
- using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
- using OpenSim.Services.Connectors.Hypergrid;
- using OpenSim.Services.Interfaces;
- using System;
- using System.Collections;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Runtime.Remoting.Lifetime;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Security.Cryptography;
- using GridRegion = OpenSim.Services.Interfaces.GridRegion;
- using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
- using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
- using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
- using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
- using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
- using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
- using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
- using PermissionMask = OpenSim.Framework.PermissionMask;
- using TPFlags = OpenSim.Framework.Constants.TeleportFlags;
- namespace OpenSim.Region.ScriptEngine.Shared.Api
- {
- //////////////////////////////////////////////////////////////
- //
- // Level description
- //
- // None - Function is no threat at all. It doesn't constitute
- // an threat to either users or the system and has no
- // known side effects
- //
- // Nuisance - Abuse of this command can cause a nuisance to the
- // region operator, such as log message spew
- //
- // VeryLow - Extreme levels ob abuse of this function can cause
- // impaired functioning of the region, or very gullible
- // users can be tricked into experiencing harmless effects
- //
- // Low - Intentional abuse can cause crashes or malfunction
- // under certain circumstances, which can easily be rectified,
- // or certain users can be tricked into certain situations
- // in an avoidable manner.
- //
- // Moderate - Intentional abuse can cause denial of service and crashes
- // with potential of data or state loss, or trusting users
- // can be tricked into embarrassing or uncomfortable
- // situationsa.
- //
- // High - Casual abuse can cause impaired functionality or temporary
- // denial of service conditions. Intentional abuse can easily
- // cause crashes with potential data loss, or can be used to
- // trick experienced and cautious users into unwanted situations,
- // or changes global data permanently and without undo ability
- // Malicious scripting can allow theft of content
- //
- // VeryHigh - Even normal use may, depending on the number of instances,
- // or frequency of use, result in severe service impairment
- // or crash with loss of data, or can be used to cause
- // unwanted or harmful effects on users without giving the
- // user a means to avoid it.
- //
- // Severe - Even casual use is a danger to region stability, or function
- // allows console or OS command execution, or function allows
- // taking money without consent, or allows deletion or
- // modification of user data, or allows the compromise of
- // sensitive data by design.
- // flags functions threat control
- public enum AllowedControlFlags : int
- {
- NONE = 0,
- PARCEL_OWNER = 1,
- PARCEL_GROUP_MEMBER = 1 << 1,
- ESTATE_MANAGER = 1 << 2,
- ESTATE_OWNER = 1 << 3,
- ACTIVE_GOD = 1 << 4,
- GOD = 1 << 5,
- GRID_GOD = 1 << 6,
- // internal
- THREATLEVEL = 1 << 28,
- OWNERUUID = 1 << 29,
- CREATORUUID = 1 << 30,
- //int thingie = 1 << 31,
- ALL = 0x0FFFFFFF
- }
- class FunctionPerms
- {
- public List<UUID> AllowedCreators;
- public List<UUID> AllowedOwners;
- public AllowedControlFlags AllowedControl = AllowedControlFlags.NONE;
- }
- [Serializable]
- public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
- {
- public const string GridInfoServiceConfigSectionName = "GridInfoService";
- // shared things
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- private static readonly object m_OSSLLock = new object();
- private static bool m_doneSharedInit = false;
- internal static bool m_OSFunctionsEnabled = false;
- internal static TimeZoneInfo PSTTimeZone = null;
- internal static bool m_PermissionErrortoOwner = false;
- internal static ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
- internal static float m_ScriptDelayFactor = 1.0f;
- internal static float m_ScriptDistanceFactor = 1.0f;
- internal static IConfig m_osslconfig;
- internal static ConcurrentDictionary<string, FunctionPerms> m_FunctionPerms = new ConcurrentDictionary<string, FunctionPerms>();
- internal IScriptEngine m_ScriptEngine;
- internal LSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there
- internal SceneObjectPart m_host;
- internal TaskInventoryItem m_item;
- protected IUrlModule m_UrlModule = null;
- protected ISoundModule m_SoundModule = null;
- protected IEnvironmentModule m_envModule = null;
- protected IGroupsModule m_groupsModule = null;
- public void Initialize(IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
- {
- //private init
- m_ScriptEngine = scriptEngine;
- m_host = host;
- m_item = item;
- m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
- m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>();
- m_envModule = m_ScriptEngine.World.RequestModuleInterface<IEnvironmentModule>();
- m_groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
- //private init
- lock (m_OSSLLock)
- {
- if(m_doneSharedInit)
- return;
- m_osslconfig = m_ScriptEngine.ConfigSource.Configs["OSSL"];
- if(m_osslconfig == null)
- m_osslconfig = m_ScriptEngine.Config;
- if (m_osslconfig.GetBoolean("AllowOSFunctions", true))
- {
- m_OSFunctionsEnabled = true;
- // m_log.Warn("[OSSL] OSSL FUNCTIONS ENABLED");
- }
- m_PermissionErrortoOwner = m_osslconfig.GetBoolean("PermissionErrorToOwner", m_PermissionErrortoOwner);
- m_ScriptDelayFactor = m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
- m_ScriptDistanceFactor = m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
- string risk = m_osslconfig.GetString("OSFunctionThreatLevel", "VeryLow");
- switch (risk)
- {
- case "NoAccess":
- m_MaxThreatLevel = ThreatLevel.NoAccess;
- break;
- case "None":
- m_MaxThreatLevel = ThreatLevel.None;
- break;
- case "VeryLow":
- m_MaxThreatLevel = ThreatLevel.VeryLow;
- break;
- case "Low":
- m_MaxThreatLevel = ThreatLevel.Low;
- break;
- case "Moderate":
- m_MaxThreatLevel = ThreatLevel.Moderate;
- break;
- case "High":
- m_MaxThreatLevel = ThreatLevel.High;
- break;
- case "VeryHigh":
- m_MaxThreatLevel = ThreatLevel.VeryHigh;
- break;
- case "Severe":
- m_MaxThreatLevel = ThreatLevel.Severe;
- break;
- default:
- break;
- }
- try
- {
- PSTTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
- }
- catch
- {
- PSTTimeZone = null;
- }
- if(PSTTimeZone == null)
- {
- try
- {
- PSTTimeZone = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
- }
- catch
- {
- PSTTimeZone = null;
- }
- }
- m_doneSharedInit = true;
- }
- }
- public override Object InitializeLifetimeService()
- {
- ILease lease = (ILease)base.InitializeLifetimeService();
- if (lease.CurrentState == LeaseState.Initial)
- {
- lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
- // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
- // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
- }
- return lease;
- }
- public Scene World
- {
- get { return m_ScriptEngine.World; }
- }
- internal void OSSLError(string msg)
- {
- throw new ScriptException("OSSL Runtime Error: " + msg);
- }
- /// <summary>
- /// Initialize the LSL interface.
- /// </summary>
- /// <remarks>
- /// FIXME: This is an abomination. We should be able to set this up earlier but currently we have no
- /// guarantee the interface is present on Initialize(). There needs to be another post initialize call from
- /// ScriptInstance.
- /// </remarks>
- private void InitLSL()
- {
- if (m_LSL_Api != null)
- return;
- m_LSL_Api = (LSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "LSL");
- }
- //
- //Dumps an error message on the debug console.
- //
- internal void OSSLShoutError(string message)
- {
- if (message.Length > 1023)
- message = message.Substring(0, 1023);
- World.SimChat(Utils.StringToBytes(message),
- ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
- IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
- if(wComm != null)
- wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
- if (m_item != null)
- m_ScriptEngine.SleepScript(m_item.ItemID, 1000);
- else
- Thread.Sleep(1000);
- }
- // Returns if OSSL is enabled. Throws a script exception if OSSL is not allowed..
- // for safe funtions always active
- public void CheckThreatLevel()
- {
- m_host.AddScriptLPS(1);
- if (!m_OSFunctionsEnabled)
- OSSLError("permission denied. All unsafe OSSL funtions disabled"); // throws
- }
- // Returns if the function is allowed. Throws a script exception if not allowed.
- public void CheckThreatLevel(ThreatLevel level, string function)
- {
- m_host.AddScriptLPS(1);
- if (!m_OSFunctionsEnabled)
- {
- if (m_PermissionErrortoOwner)
- throw new ScriptException("(OWNER)OSSL Permission Error: All unsafe OSSL funtions disabled");
- else
- throw new ScriptException("OSSL Permission Error: All unsafe OSSL funtions disabled");
- }
- string reasonWhyNot = CheckThreatLevelTest(level, function);
- if (!String.IsNullOrEmpty(reasonWhyNot))
- {
- if (m_PermissionErrortoOwner)
- throw new ScriptException("(OWNER)OSSL Permission Error: " + reasonWhyNot);
- else
- throw new ScriptException("OSSL Permission Error: " + reasonWhyNot);
- }
- }
- // Check to see if function is allowed. Returns an empty string if function permitted
- // or a string explaining why this function can't be used.
- private string CheckThreatLevelTest(ThreatLevel level, string function)
- {
- if (!m_FunctionPerms.TryGetValue(function, out FunctionPerms perms))
- {
- perms = new FunctionPerms();
- string ownerPerm = m_osslconfig.GetString("Allow_" + function, "");
- string creatorPerm = m_osslconfig.GetString("Creators_" + function, "");
- if (string.IsNullOrWhiteSpace(ownerPerm) && string.IsNullOrWhiteSpace(creatorPerm))
- {
- // Default Threat level check
- perms.AllowedControl = AllowedControlFlags.THREATLEVEL;
- }
- else
- {
- if (bool.TryParse(ownerPerm, out bool allowed))
- {
- // Boolean given
- if (allowed)
- {
- // Allow globally
- perms.AllowedControl = AllowedControlFlags.ALL;
- }
- // false is fallback
- }
- else
- {
- string[] ids;
- bool error = false;
- if (!string.IsNullOrWhiteSpace(ownerPerm))
- {
- ids = ownerPerm.Split(new char[] {','});
- foreach (string id in ids)
- {
- string current = id.Trim();
- current = current.ToUpper();
- switch(current)
- {
- case "":
- break;
- case "PARCEL_OWNER":
- perms.AllowedControl |= AllowedControlFlags.PARCEL_OWNER;
- break;
- case "PARCEL_GROUP_MEMBER":
- perms.AllowedControl |= AllowedControlFlags.PARCEL_GROUP_MEMBER;
- break;
- case "ESTATE_MANAGER":
- perms.AllowedControl |= AllowedControlFlags.ESTATE_MANAGER;
- break;
- case "ESTATE_OWNER":
- perms.AllowedControl |= AllowedControlFlags.ESTATE_OWNER;
- break;
- case "ACTIVE_GOD":
- perms.AllowedControl |= AllowedControlFlags.ACTIVE_GOD;
- break;
- case "GOD":
- perms.AllowedControl |= AllowedControlFlags.GOD;
- break;
- case "GRID_GOD":
- perms.AllowedControl |= AllowedControlFlags.GRID_GOD;
- break;
- default:
- {
- if (UUID.TryParse(current, out UUID uuid))
- {
- if (uuid != UUID.Zero)
- {
- if (perms.AllowedOwners == null)
- perms.AllowedOwners = new List<UUID>();
- perms.AllowedControl |= AllowedControlFlags.OWNERUUID;
- perms.AllowedOwners.Add(uuid);
- }
- }
- else
- {
- error = true;
- }
- break;
- }
- }
- }
- if (error)
- m_log.WarnFormat("[OSSLENABLE]: error parsing line Allow_{0} = {1}", function, ownerPerm);
- }
- error = false;
- if (!string.IsNullOrWhiteSpace(creatorPerm))
- {
- ids = creatorPerm.Split(new char[] {','});
- foreach (string id in ids)
- {
- string current = id.Trim();
- if (UUID.TryParse(current, out UUID uuid))
- {
- if (uuid != UUID.Zero)
- {
- if (perms.AllowedCreators == null)
- perms.AllowedCreators = new List<UUID>();
- perms.AllowedControl |= AllowedControlFlags.CREATORUUID;
- perms.AllowedCreators.Add(uuid);
- }
- }
- else
- {
- error = true;
- }
- }
- if (error)
- m_log.WarnFormat("[OSSLENABLE]: error parsing line Creators_{0} = {1}", function, creatorPerm);
- }
- // both empty fallback as disabled
- }
- }
- m_FunctionPerms.TryAdd(function,perms);
- }
- AllowedControlFlags functionControl = perms.AllowedControl;
- if (functionControl == AllowedControlFlags.THREATLEVEL)
- {
- // Allow / disallow by threat level
- if (level <= m_MaxThreatLevel)
- return String.Empty;
- return String.Format(
- "{0} permission denied. Allowed threat level is {1} but function threat level is {2}.",
- function, m_MaxThreatLevel, level);
- }
- if (functionControl == 0)
- return String.Format("{0} disabled in region configuration", function);
- if (functionControl == AllowedControlFlags.ALL)
- return String.Empty;
- if (((functionControl & AllowedControlFlags.OWNERUUID) != 0) && perms.AllowedOwners.Contains(m_host.OwnerID))
- {
- // prim owner is in the list of allowed owners
- return String.Empty;
- }
- UUID ownerID = m_item.OwnerID;
- if ((functionControl & AllowedControlFlags.PARCEL_OWNER) != 0)
- {
- ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
- if (land.LandData.OwnerID == ownerID)
- {
- return String.Empty;
- }
- }
- //OSSL only may be used if object is in the same group as the parcel
- if ((functionControl & AllowedControlFlags.PARCEL_GROUP_MEMBER) != 0)
- {
- ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
- if (land.LandData.GroupID == m_item.GroupID && land.LandData.GroupID != UUID.Zero)
- {
- return String.Empty;
- }
- }
- //Only Estate Managers may use the function
- if ((functionControl & AllowedControlFlags.ESTATE_MANAGER) != 0)
- {
- //Only Estate Managers may use the function
- if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID)
- {
- return String.Empty;
- }
- }
- //Only regionowners may use the function
- if ((functionControl & AllowedControlFlags.ESTATE_OWNER) != 0)
- {
- if (World.RegionInfo.EstateSettings.EstateOwner == ownerID)
- {
- return String.Empty;
- }
- }
- //Only grid gods may use the function
- if ((functionControl & AllowedControlFlags.GRID_GOD) != 0)
- {
- if (World.Permissions.IsGridGod(ownerID))
- {
- return String.Empty;
- }
- }
- //Any god may use the function
- if ((functionControl & AllowedControlFlags.GOD) != 0)
- {
- if (World.Permissions.IsAdministrator(ownerID))
- {
- return String.Empty;
- }
- }
- //Only active gods may use the function
- if ((functionControl & AllowedControlFlags.ACTIVE_GOD) != 0)
- {
- ScenePresence sp = World.GetScenePresence(ownerID);
- if (sp != null && !sp.IsDeleted && sp.IsGod)
- {
- return String.Empty;
- }
- }
- // else if no creators its denied
- if((functionControl & AllowedControlFlags.CREATORUUID) == 0)
- return String.Format("{0} permission denied.", function);
- if (!perms.AllowedCreators.Contains(m_item.CreatorID))
- return(
- 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.",
- function));
- if (m_item.CreatorID != ownerID)
- {
- if ((m_item.CurrentPermissions & (uint)PermissionMask.Modify) != 0)
- return String.Format("{0} permission denied. Script creator is not prim owner.", function);
- }
- return String.Empty;
- }
- internal void OSSLDeprecated(string function, string replacement)
- {
- OSSLShoutError(string.Format("Use of function {0} is deprecated. Use {1} instead.", function, replacement));
- }
- protected void ScriptSleep(int delay)
- {
- delay = (int)(delay * m_ScriptDelayFactor);
- if (delay < 10)
- return;
- if(m_item != null)
- m_ScriptEngine.SleepScript(m_item.ItemID, delay);
- else
- Thread.Sleep(delay);
- }
- public LSL_Integer osSetTerrainHeight(int x, int y, double val)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight");
- return SetTerrainHeight(x, y, val);
- }
- public LSL_Integer osTerrainSetHeight(int x, int y, double val)
- {
- CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight");
- OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight");
- return SetTerrainHeight(x, y, val);
- }
- private LSL_Integer SetTerrainHeight(int x, int y, double val)
- {
- if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
- OSSLError("osSetTerrainHeight: Coordinate out of bounds");
- if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0)))
- {
- World.Heightmap[x, y] = (float)val;
- return 1;
- }
- else
- {
- return 0;
- }
- }
- public LSL_Float osGetTerrainHeight(int x, int y)
- {
- CheckThreatLevel();
- return GetTerrainHeight(x, y);
- }
- public LSL_Float osTerrainGetHeight(int x, int y)
- {
- CheckThreatLevel();
- OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight");
- return GetTerrainHeight(x, y);
- }
- private LSL_Float GetTerrainHeight(int x, int y)
- {
- if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
- OSSLError("osGetTerrainHeight: Coordinate out of bounds");
- return World.Heightmap[x, y];
- }
- public void osTerrainFlush()
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush");
- ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
- if (terrainModule != null) terrainModule.TaintTerrain();
- }
- public int osRegionRestart(double seconds)
- {
- // This is High here because region restart is not reliable
- // it may result in the region staying down or becoming
- // unstable. This should be changed to Low or VeryLow once
- // The underlying functionality is fixed, since the security
- // as such is sound
- //
- CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
- IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
- if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
- {
- if (seconds < 15)
- {
- restartModule.AbortRestart("Region restart has been aborted\n");
- return 1;
- }
- RegionRestart(seconds, String.Empty);
- return 1;
- }
- else
- {
- return 0;
- }
- }
- public int osRegionRestart(double seconds, string msg)
- {
- CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
- IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
- if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
- {
- if (seconds < 15)
- {
- restartModule.AbortRestart("Region restart has been aborted\n");
- return 1;
- }
- RegionRestart(seconds, msg);
- return 1;
- }
- else
- {
- return 0;
- }
- }
- private void RegionRestart(double seconds, string msg)
- {
- IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
- List<int> times = new List<int>();
- while (seconds > 0)
- {
- times.Add((int)seconds);
- if (seconds > 300)
- seconds -= 120;
- else if (seconds > 120)
- seconds -= 60;
- else if (seconds > 60)
- seconds -= 30;
- else
- seconds -= 15;
- }
- if (msg == String.Empty)
- 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);
- else
- restartModule.ScheduleRestart(UUID.Zero, msg + "\n\nTime remaining: {0}.\n", times.ToArray(), true);
- }
- public void osRegionNotice(string msg)
- {
- CheckThreatLevel(ThreatLevel.High, "osRegionNotice");
- IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
- if (dm == null)
- return;
- if (!World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false))
- return;
- dm.SendGeneralAlert(msg + "\n");
- }
- public void osRegionNotice(LSL_Key agentID, string msg)
- {
- CheckThreatLevel(ThreatLevel.High, "osRegionNotice");
- if (!World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false))
- return;
- IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
- if (dm == null)
- return;
- if (!UUID.TryParse(agentID, out UUID avatarID))
- return;
- if (!World.TryGetScenePresence(avatarID, out ScenePresence sp))
- return;
- if (sp == null || sp.IsChildAgent || sp.IsDeleted || sp.IsInTransit || sp.IsNPC)
- return;
- dm.SendAlertToUser(sp.ControllingClient, msg + "\n", false);
- }
- public void osSetRot(UUID target, Quaternion rotation)
- {
- // if enabled It can be used to destroy
- // arbitrary builds the user would normally have no rights to
- //
- CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot");
- if (World.Entities.ContainsKey(target))
- {
- if (World.Entities.TryGetValue(target, out EntityBase entity))
- {
- if (entity is SceneObjectGroup)
- ((SceneObjectGroup)entity).UpdateGroupRotationR(rotation);
- else if (entity is ScenePresence)
- ((ScenePresence)entity).Rotation = rotation;
- }
- }
- else
- {
- OSSLError("osSetRot: Invalid target");
- }
- }
- public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
- int timer)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osSetDynamicTextureURL");
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- UUID createdTexture =
- textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
- extraParams);
- return createdTexture.ToString();
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return ScriptBaseClass.NULL_KEY;
- }
- public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
- int timer, int alpha)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osSetDynamicTextureURLBlend");
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- UUID createdTexture =
- textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
- extraParams, true, (byte) alpha);
- return createdTexture.ToString();
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return ScriptBaseClass.NULL_KEY;
- }
- public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams,
- bool blend, int disp, int timer, int alpha, int face)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osSetDynamicTextureURLBlendFace");
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- UUID createdTexture =
- textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
- extraParams, blend, disp, (byte) alpha, face);
- return createdTexture.ToString();
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return ScriptBaseClass.NULL_KEY;
- }
- public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
- int timer)
- {
- return osSetDynamicTextureDataFace(dynamicID, contentType, data, extraParams, timer, -1);
- }
- public string osSetDynamicTextureDataFace(string dynamicID, string contentType, string data, string extraParams,
- int timer, int face)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureData");
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- if (textureManager != null)
- {
- if (extraParams == String.Empty)
- {
- extraParams = "256";
- }
- UUID createdTexture =
- textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
- extraParams, false, 3, 255, face);
- return createdTexture.ToString();
- }
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return ScriptBaseClass.NULL_KEY;
- }
- public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
- int timer, int alpha)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlend");
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- if (textureManager != null)
- {
- if (extraParams == String.Empty)
- {
- extraParams = "256";
- }
- UUID createdTexture =
- textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
- extraParams, true, (byte) alpha);
- return createdTexture.ToString();
- }
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return ScriptBaseClass.NULL_KEY;
- }
- public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams,
- bool blend, int disp, int timer, int alpha, int face)
- {
- CheckThreatLevel(ThreatLevel.VeryLow , "osSetDynamicTextureDataBlendFace");
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- if (textureManager != null)
- {
- if (extraParams == String.Empty)
- {
- extraParams = "256";
- }
- UUID createdTexture =
- textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
- extraParams, blend, disp, (byte) alpha, face);
- return createdTexture.ToString();
- }
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return ScriptBaseClass.NULL_KEY;
- }
- public bool osConsoleCommand(string command)
- {
- CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand");
- // For safety, we add another permission check here, and don't rely only on the standard OSSL permissions
- if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
- {
- MainConsole.Instance.RunCommand(command);
- return true;
- }
- return false;
- }
- public void osSetPrimFloatOnWater(int floatYN)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater");
- m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
- }
- private bool checkAllowAgentTPbyLandOwner(UUID agentId, Vector3 pos)
- {
- UUID hostOwner = m_host.OwnerID;
- if(hostOwner == agentId)
- return true;
- if (m_item.PermsGranter == agentId)
- {
- if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
- return true;
- }
- ILandObject land = World.LandChannel.GetLandObject(pos);
- if(land == null)
- return true;
- LandData landdata = land.LandData;
- if(landdata == null)
- return true;
- if(landdata.OwnerID == hostOwner)
- return true;
- EstateSettings es = World.RegionInfo.EstateSettings;
- if(es != null && es.IsEstateManagerOrOwner(hostOwner))
- return true;
- if(!landdata.IsGroupOwned)
- return false;
- UUID landGroup = landdata.GroupID;
- if(landGroup == UUID.Zero)
- return false;
- if(landGroup == m_host.GroupID)
- return true;
- return false;
- }
- // Teleport functions
- public void osLocalTeleportAgent(LSL_Key agent, LSL_Types.Vector3 position, LSL_Types.Vector3 velocity, LSL_Types.Vector3 lookat, LSL_Integer flags)
- {
- if (!UUID.TryParse(agent, out UUID agentId))
- return;
- ScenePresence presence = World.GetScenePresence(agentId);
- if (presence == null || presence.IsDeleted || presence.IsInTransit)
- return;
- Vector3 pos = presence.AbsolutePosition;
- if (!checkAllowAgentTPbyLandOwner(agentId, pos))
- return;
- World.RequestLocalTeleport(presence, position, velocity, lookat, flags);
- }
- public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- // High because there is no security check. High griefer potential
- //
- CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
- TeleportAgent(agent, regionName, position, lookat);
- }
- private void TeleportAgent(string agent, string regionName,
- LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- if(String.IsNullOrEmpty(regionName))
- regionName = World.RegionInfo.RegionName;
- if (UUID.TryParse(agent, out UUID agentId))
- {
- ScenePresence presence = World.GetScenePresence(agentId);
- if (presence == null || presence.IsDeleted || presence.IsInTransit)
- return;
- Vector3 pos = presence.AbsolutePosition;
- if (!checkAllowAgentTPbyLandOwner(agentId, pos))
- {
- ScriptSleep(500);
- return;
- }
- if (regionName == World.RegionInfo.RegionName)
- {
- // should be faster than going to threadpool
- World.RequestTeleportLocation(presence.ControllingClient, regionName, position,
- lookat, (uint)TPFlags.ViaLocation);
- ScriptSleep(500);
- }
- else
- {
- // We will launch the teleport on a new thread so that when the script threads are terminated
- // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
- Util.FireAndForget(
- o => World.RequestTeleportLocation(
- presence.ControllingClient, regionName, position,
- lookat, (uint)TPFlags.ViaLocation),
- null, "OSSL_Api.TeleportAgentByRegionCoords");
- ScriptSleep(5000);
- }
- }
- }
- public void osTeleportAgent(string agent, int regionGridX, int regionGridY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- // High because there is no security check. High griefer potential
- //
- CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
- TeleportAgent(agent, regionGridX, regionGridY, position, lookat);
- }
- private void TeleportAgent(string agent, int regionGridX, int regionGridY,
- LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- ulong regionHandle = Util.RegionGridLocToHandle((uint)regionGridX, (uint)regionGridY);
- if (UUID.TryParse(agent, out UUID agentId))
- {
- ScenePresence presence = World.GetScenePresence(agentId);
- if (presence == null || presence.IsDeleted || presence.IsInTransit)
- return;
- Vector3 pos = presence.AbsolutePosition;
- if (!checkAllowAgentTPbyLandOwner(agentId, pos))
- {
- ScriptSleep(500);
- return;
- }
- Util.FireAndForget(
- o => World.RequestTeleportLocation(
- presence.ControllingClient, regionHandle,
- position, lookat, (uint)TPFlags.ViaLocation),
- null, "OSSL_Api.TeleportAgentByRegionName");
- ScriptSleep(5000);
- }
- }
- public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- if (UUID.TryParse(agent, out UUID agentId))
- {
- ScenePresence presence = World.GetScenePresence(agentId);
- if (presence == null || presence.IsDeleted || presence.IsInTransit)
- return;
- Vector3 pos = presence.AbsolutePosition;
- if (!checkAllowAgentTPbyLandOwner(agentId, pos))
- {
- ScriptSleep(500);
- return;
- }
- World.RequestTeleportLocation(presence.ControllingClient, World.RegionInfo.RegionName, position,
- lookat, (uint)TPFlags.ViaLocation);
- ScriptSleep(500);
- }
- }
- public void osTeleportOwner(string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- // Threat level None because this is what can already be done with the World Map in the viewer
- CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
- TeleportAgent(m_host.OwnerID.ToString(), regionName, position, lookat);
- }
- public void osTeleportOwner(int regionGridX, int regionGridY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
- TeleportAgent(m_host.OwnerID.ToString(), regionGridX, regionGridY, position, lookat);
- }
- public void osTeleportOwner(LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
- osTeleportAgent(m_host.OwnerID.ToString(), position, lookat);
- }
- ///<summary>
- /// Allows a script IN the target prim to force an avatar to sit on it using normal methods
- /// as if called by the client.
- /// Silent fail if agent (or target if overloaded) not found.
- /// Does work if passed key (or keys if overloaded).
- /// </summary>
- /// <param name="avatar"></param>
- public void osForceOtherSit(string avatar)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
- ForceSit(avatar, m_host.UUID);
- }
- /// <summary>
- /// Overload method of osForceOtherSit(string avatar) to allow a script NOT in the target prim to force
- /// an avatar to sit on the target prim using normal methods as if called by the client.
- /// </summary>
- /// <param name="avatar"></param>
- /// <param name="target"></param>
- public void osForceOtherSit(string avatar, string target)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
- UUID targetID = new UUID(target);
- ForceSit(avatar, targetID);
- }
- public void ForceSit(string avatar, UUID targetID)
- {
- if (!UUID.TryParse(avatar, out UUID agentID))
- return;
- ScenePresence presence = World.GetScenePresence(agentID);
- SceneObjectPart part = World.GetSceneObjectPart(targetID);
- if (presence != null &&
- part != null &&
- part.SitTargetAvatar == UUID.Zero)
- presence.HandleAgentRequestSit(presence.ControllingClient,
- agentID,
- targetID,
- part.SitTargetPosition);
- }
- // Get a list of all the avatars/agents in the region
- public LSL_List osGetAgents()
- {
- // threat level is None as we could get this information with an
- // in-world script as well, just not as efficient
- CheckThreatLevel(ThreatLevel.None, "osGetAgents");
- LSL_List result = new LSL_List();
- World.ForEachRootScenePresence(delegate(ScenePresence sp)
- {
- result.Add(new LSL_String(sp.Name));
- });
- return result;
- }
- public string osGetAgentIP(string agent)
- {
- CheckThreatLevel(ThreatLevel.Severe, "osGetAgentIP");
- if(!(World.Permissions.IsGod(m_host.OwnerID))) // user god always needed
- return "";
- UUID avatarID = (UUID)agent;
- if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence)
- {
- ScenePresence target = (ScenePresence)World.Entities[avatarID];
- return target.ControllingClient.RemoteEndPoint.Address.ToString();
- }
- // fall through case, just return nothing
- return "";
- }
- // Adam's super super custom animation functions
- public void osAvatarPlayAnimation(LSL_Key avatar, string animation)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation");
- if (!UUID.TryParse(avatar, out UUID avatarID))
- return;
- ScenePresence target = World.GetScenePresence(avatarID);
- if (target == null)
- return;
- UUID animID = UUID.Zero;
- m_host.TaskInventory.LockItemsForRead(true);
- foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
- {
- if (inv.Value.Type == (int)AssetType.Animation)
- {
- if (inv.Value.Name == animation)
- {
- animID = inv.Value.AssetID;
- break;
- }
- }
- }
- m_host.TaskInventory.LockItemsForRead(false);
- if (animID == UUID.Zero)
- target.Animator.AddAnimation(animation, m_host.UUID);
- else
- target.Animator.AddAnimation(animID, m_host.UUID);
- }
- public void osAvatarStopAnimation(LSL_Key avatar, string animation)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation");
- if (!UUID.TryParse(avatar, out UUID avatarID))
- return;
- ScenePresence target = World.GetScenePresence(avatarID);
- if (target == null)
- return;
- if (!UUID.TryParse(animation, out UUID animID))
- {
- TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation);
- if (item != null && item.Type == (int)AssetType.Animation)
- animID = item.AssetID;
- else
- animID = UUID.Zero;
- }
- if (animID == UUID.Zero)
- target.Animator.RemoveAnimation(animation);
- else
- target.Animator.RemoveAnimation(animID, true);
- }
- //Texture draw functions
- public string osDrawResetTransform(string drawList)
- {
- CheckThreatLevel();
- drawList += "ResetTransf;";
- return drawList;
- }
- public string osDrawRotationTransform(string drawList, LSL_Float x)
- {
- CheckThreatLevel();
- drawList += "RotTransf " + x + ";";
- return drawList;
- }
- public string osDrawScaleTransform(string drawList, LSL_Float x, LSL_Float y)
- {
- CheckThreatLevel();
- drawList += "ScaleTransf " + x + "," + y + ";";
- return drawList;
- }
- public string osDrawTranslationTransform(string drawList, LSL_Float x, LSL_Float y)
- {
- CheckThreatLevel();
- drawList += "TransTransf " + x + "," + y + ";";
- return drawList;
- }
- public string osMovePen(string drawList, int x, int y)
- {
- CheckThreatLevel();
- drawList += "MoveTo " + x + "," + y + ";";
- return drawList;
- }
- public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
- {
- CheckThreatLevel();
- drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
- return drawList;
- }
- public string osDrawLine(string drawList, int endX, int endY)
- {
- CheckThreatLevel();
- drawList += "LineTo " + endX + "," + endY + "; ";
- return drawList;
- }
- public string osDrawText(string drawList, string text)
- {
- CheckThreatLevel(ThreatLevel.None, "osDrawText");
- drawList += "Text " + text + "; ";
- return drawList;
- }
- public string osDrawEllipse(string drawList, int width, int height)
- {
- CheckThreatLevel();
- drawList += "Ellipse " + width + "," + height + "; ";
- return drawList;
- }
- public string osDrawFilledEllipse(string drawList, int width, int height)
- {
- CheckThreatLevel();
- drawList += "FillEllipse " + width + "," + height + "; ";
- return drawList;
- }
- public string osDrawRectangle(string drawList, int width, int height)
- {
- CheckThreatLevel();
- drawList += "Rectangle " + width + "," + height + "; ";
- return drawList;
- }
- public string osDrawFilledRectangle(string drawList, int width, int height)
- {
- CheckThreatLevel();
- drawList += "FillRectangle " + width + "," + height + "; ";
- return drawList;
- }
- public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
- {
- CheckThreatLevel();
- if (x.Length != y.Length || x.Length < 3)
- {
- return "";
- }
- drawList += "FillPolygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
- for (int i = 1; i < x.Length; i++)
- {
- drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
- }
- drawList += "; ";
- return drawList;
- }
- public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
- {
- CheckThreatLevel();
- if (x.Length != y.Length || x.Length < 3)
- {
- return "";
- }
- drawList += "Polygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
- for (int i = 1; i < x.Length; i++)
- {
- drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
- }
- drawList += "; ";
- return drawList;
- }
- public string osSetFontSize(string drawList, int fontSize)
- {
- CheckThreatLevel();
- drawList += "FontSize "+ fontSize +"; ";
- return drawList;
- }
- public string osSetFontName(string drawList, string fontName)
- {
- CheckThreatLevel();
- drawList += "FontName "+ fontName +"; ";
- return drawList;
- }
- public string osSetPenSize(string drawList, int penSize)
- {
- CheckThreatLevel();
- drawList += "PenSize " + penSize + "; ";
- return drawList;
- }
- public string osSetPenColor(string drawList, string color)
- {
- CheckThreatLevel();
- drawList += "PenColor " + color + "; ";
- return drawList;
- }
- // Deprecated
- public string osSetPenColour(string drawList, string colour)
- {
- CheckThreatLevel();
- OSSLDeprecated("osSetPenColour", "osSetPenColor");
- drawList += "PenColour " + colour + "; ";
- return drawList;
- }
- public string osSetPenCap(string drawList, string direction, string type)
- {
- CheckThreatLevel();
- drawList += "PenCap " + direction + "," + type + "; ";
- return drawList;
- }
- public string osDrawImage(string drawList, int width, int height, string imageUrl)
- {
- CheckThreatLevel();
- drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
- return drawList;
- }
- public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
- {
- CheckThreatLevel();
- LSL_Vector vec = new LSL_Vector(0,0,0);
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- if (textureManager != null)
- {
- textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
- out double xSize, out double ySize);
- vec.x = xSize;
- vec.y = ySize;
- }
- return vec;
- }
- public void osSetRegionWaterHeight(double height)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
- World.EventManager.TriggerRequestChangeWaterHeight((float)height);
- }
- /// <summary>
- /// Changes the Region Sun Settings, then Triggers a Sun Update
- /// </summary>
- /// <param name="useEstateSun">True to use Estate Sun instead of Region Sun</param>
- /// <param name="sunFixed">True to keep the sun stationary</param>
- /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
- public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetRegionSunSettings");
- while (sunHour > 24.0)
- sunHour -= 24.0;
- while (sunHour < 0)
- sunHour += 24.0;
- World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
- World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
- World.RegionInfo.RegionSettings.FixedSun = sunFixed;
- World.RegionInfo.RegionSettings.Save();
- World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
- }
- /// <summary>
- /// Changes the Estate Sun Settings, then Triggers a Sun Update
- /// </summary>
- /// <param name="sunFixed">True to keep the sun stationary, false to use global time</param>
- /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
- public void osSetEstateSunSettings(bool sunFixed, double sunHour)
- {
- /*
- CheckThreatLevel(ThreatLevel.High, "osSetEstateSunSettings");
-
- while (sunHour > 24.0)
- sunHour -= 24.0;
- while (sunHour < 0)
- sunHour += 24.0;
- World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
- World.RegionInfo.EstateSettings.SunPosition = sunHour;
- World.RegionInfo.EstateSettings.FixedSun = sunFixed;
- World.EstateDataService.StoreEstateSettings(World.RegionInfo.EstateSettings);
- World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
- */
- }
- /// <summary>
- /// Return the current Sun Hour 0...24, with 0 being roughly sun-rise
- /// </summary>
- /// <returns></returns>
- public LSL_Float osGetCurrentSunHour()
- {
- CheckThreatLevel();
- if (m_envModule == null)
- return 0;
- float frac = m_envModule.GetRegionDayFractionTime();
- return 24 * frac;
- }
- public LSL_Float osGetApparentTime()
- {
- CheckThreatLevel();
- if (m_envModule == null)
- return 0;
- float frac = m_envModule.GetRegionDayFractionTime();
- return 86400 * frac;
- }
- private string timeToString(float frac, bool format24)
- {
- int h = (int)frac;
- frac -= h;
- frac *= 60;
- int m = (int)frac;
- frac -= m;
- frac *= 60;
- int s = (int)frac;
- if (format24)
- {
- return string.Format("{0:00}:{1:00}:{2:00}", h, m, s);
- }
- if (h > 12)
- return string.Format("{0}:{1:00}:{2:00} PM", h - 12, m, s);
- if (h == 12)
- return string.Format("{0}:{1:00}:{2:00} PM", h, m, s);
- return string.Format("{0}:{1:00}:{2:00} AM", h, m, s);
- }
- public LSL_String osGetApparentTimeString(LSL_Integer format24)
- {
- CheckThreatLevel();
- if (m_envModule == null)
- {
- if (format24 != 0)
- return "00:00:00";
- return "0:00:00 AM";
- }
- float frac = 24 * m_envModule.GetRegionDayFractionTime();
- return timeToString(frac, format24 != 0);
- }
- public LSL_Float osGetApparentRegionTime()
- {
- CheckThreatLevel();
- if (m_envModule == null)
- return 0;
- float frac = m_envModule.GetRegionDayFractionTime();
- return 86400 * frac;
- }
- public LSL_String osGetApparentRegionTimeString(LSL_Integer format24)
- {
- CheckThreatLevel();
- if (m_envModule == null)
- {
- if (format24 != 0)
- return "00:00:00";
- return "0:00:00 AM";
- }
- float frac = 24 * m_envModule.GetRegionDayFractionTime();
- return timeToString(frac, format24 != 0);
- }
- public double osSunGetParam(string param)
- {
- CheckThreatLevel(ThreatLevel.None, "osSunGetParam");
- OSSLDeprecated("osSunGetParam", "osGetSunParam");
- return GetSunParam(param);
- }
- public LSL_Float osGetSunParam(LSL_String param)
- {
- CheckThreatLevel();
- return GetSunParam(param);
- }
- private double GetSunParam(string param)
- {
- param = param.ToLower();
- switch(param)
- {
- case "day_length":
- if (m_envModule == null)
- return 14400;
- return m_envModule.GetDayLength(m_host.AbsolutePosition);
- case "year_length":
- return 365;
- case "day_night_offset":
- return 0;
- case "update_interval":
- return 0.1;
- case "day_time_sun_hour_scale":
- return 1;
- default:
- break;
- }
- return 0;
- }
- public void osSunSetParam(string param, double value)
- {
- CheckThreatLevel(ThreatLevel.None, "osSunSetParam");
- OSSLDeprecated("osSunSetParam", "osSetSunParam");
- SetSunParam(param, value);
- }
- public void osSetSunParam(string param, double value)
- {
- CheckThreatLevel(ThreatLevel.None, "osSetSunParam");
- SetSunParam(param, value);
- }
- private void SetSunParam(string param, double value)
- {
- ISunModule module = World.RequestModuleInterface<ISunModule>();
- if (module != null)
- {
- module.SetSunParameter(param, value);
- }
- }
- public string osWindActiveModelPluginName()
- {
- CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
- IWindModule module = World.RequestModuleInterface<IWindModule>();
- if (module != null)
- {
- return module.WindActiveModelPluginName;
- }
- return String.Empty;
- }
- public void osSetWindParam(string plugin, string param, LSL_Float value)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetWindParam");
- IWindModule module = World.RequestModuleInterface<IWindModule>();
- if (module != null)
- {
- try
- {
- module.WindParamSet(plugin, param, (float)value);
- }
- catch (Exception) { }
- }
- }
- public LSL_Float osGetWindParam(string plugin, string param)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osGetWindParam");
- IWindModule module = World.RequestModuleInterface<IWindModule>();
- if (module != null)
- {
- return module.WindParamGet(plugin, param);
- }
- return 0.0f;
- }
- public LSL_Integer osGetParcelDwell(LSL_Vector pos)
- {
- LandData land = World.GetLandData(pos);
- if (land != null)
- {
- return (int)land.Dwell;
- }
- return 0;
- }
- // Routines for creating and managing parcels programmatically
- public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
- {
- CheckThreatLevel(ThreatLevel.High, "osParcelJoin");
- int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
- int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
- int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
- int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
- World.LandChannel.Join(startx,starty,endx,endy,m_host.OwnerID);
- }
- public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
- {
- CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide");
- int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
- int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
- int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
- int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
- World.LandChannel.Subdivide(startx,starty,endx,endy,m_host.OwnerID);
- }
- public void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
- {
- const string functionName = "osParcelSetDetails";
- CheckThreatLevel(ThreatLevel.High, functionName);
- OSSLDeprecated(functionName, "osSetParcelDetails");
- SetParcelDetails(pos, rules, functionName);
- }
- public void osSetParcelDetails(LSL_Vector pos, LSL_List rules)
- {
- const string functionName = "osSetParcelDetails";
- CheckThreatLevel(ThreatLevel.High, functionName);
- SetParcelDetails(pos, rules, functionName);
- }
- private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName)
- {
- // Get a reference to the land data and make sure the owner of the script
- // can modify it
- ILandObject startLandObject = World.LandChannel.GetLandObject((int)pos.x, (int)pos.y);
- if (startLandObject == null)
- {
- OSSLShoutError("There is no land at that location");
- return;
- }
- if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions, false))
- {
- OSSLShoutError("script owner does not have permission to modify the parcel");
- return;
- }
- // Create a new land data object we can modify
- LandData newLand = startLandObject.LandData.Copy();
- UUID uuid;
- EstateSettings es = World.RegionInfo.EstateSettings;
- bool changed = false;
- bool changedSeeAvs = false;
- bool changedoverlay = false;
- bool changedneedupdate = false;
- // Process the rules, not sure what the impact would be of changing owner or group
- for (int idx = 0; idx < rules.Length;)
- {
- int code = rules.GetLSLIntegerItem(idx++);
- string arg = rules.GetLSLStringItem(idx++);
- switch (code)
- {
- case ScriptBaseClass.PARCEL_DETAILS_NAME:
- if(newLand.Name != arg)
- {
- newLand.Name = arg;
- changed = true;
- }
- break;
- case ScriptBaseClass.PARCEL_DETAILS_DESC:
- if(newLand.Description != arg)
- {
- newLand.Description = arg;
- changed = true;
- }
- break;
- case ScriptBaseClass.PARCEL_DETAILS_OWNER:
- if(es != null && !es.IsEstateManagerOrOwner(m_host.OwnerID))
- {
- OSSLShoutError("script owner does not have permission to modify the parcel owner");
- }
- else
- {
- if (UUID.TryParse(arg, out uuid))
- {
- if(newLand.OwnerID != uuid)
- {
- changed = true;
- newLand.OwnerID = uuid;
- newLand.GroupID = UUID.Zero;
- }
- }
- }
- break;
- case ScriptBaseClass.PARCEL_DETAILS_GROUP:
- if(m_host.OwnerID == newLand.OwnerID || es == null || es.IsEstateManagerOrOwner(m_host.OwnerID))
- {
- if (UUID.TryParse(arg, out uuid))
- {
- if(newLand.GroupID != uuid)
- {
- if(uuid == UUID.Zero)
- {
- changed = true;
- newLand.GroupID = uuid;
- }
- else
- {
- GroupMembershipData member = null;
- if (m_groupsModule != null)
- member = m_groupsModule.GetMembershipData(uuid, newLand.OwnerID);
- if (member == null)
- OSSLShoutError(string.Format("land owner is not member of the new group for parcel"));
- else
- {
- changed = true;
- newLand.GroupID = uuid;
- }
- }
- }
- }
- }
- else
- {
- OSSLShoutError("script owner does not have permission to modify the parcel group");
- }
- break;
- case ScriptBaseClass.PARCEL_DETAILS_CLAIMDATE:
- if(es != null && !es.IsEstateManagerOrOwner(m_host.OwnerID))
- {
- OSSLShoutError("script owner does not have permission to modify the parcel CLAIM DATE");
- }
- else
- {
- int date = Convert.ToInt32(arg);
- if (date == 0)
- date = Util.UnixTimeSinceEpoch();
- if(newLand.ClaimDate != date)
- {
- changed = true;
- newLand.ClaimDate = date;
- }
- }
- break;
- case ScriptBaseClass.PARCEL_DETAILS_SEE_AVATARS:
- bool newavs = (Convert.ToInt32(arg) != 0);
- if(newLand.SeeAVs != newavs)
- {
- changed = true;
- changedSeeAvs = true;
- changedoverlay = true;
- changedneedupdate = true;
- newLand.SeeAVs = newavs;
- }
- break;
- case ScriptBaseClass.PARCEL_DETAILS_ANY_AVATAR_SOUNDS:
- bool newavsounds = (Convert.ToInt32(arg) != 0);
- if(newLand.AnyAVSounds != newavsounds)
- {
- changed = true;
- newLand.AnyAVSounds = newavsounds;
- }
- break;
- case ScriptBaseClass.PARCEL_DETAILS_GROUP_SOUNDS:
- bool newgrpsounds = (Convert.ToInt32(arg) != 0);
- if(newLand.GroupAVSounds != newgrpsounds)
- {
- changed = true;
- newLand.GroupAVSounds = newgrpsounds;
- }
- break;
- }
- }
- if(changed)
- {
- World.LandChannel.UpdateLandObject(newLand.LocalID, newLand);
- if(changedneedupdate)
- {
- UUID parcelID= newLand.GlobalID;
- World.ForEachRootScenePresence(delegate (ScenePresence avatar)
- {
- if (avatar == null || avatar.IsDeleted || avatar.IsInTransit)
- return;
- if(changedSeeAvs && avatar.currentParcelUUID == parcelID )
- avatar.currentParcelUUID = parcelID; // force parcel flags review
- if(avatar.ControllingClient == null)
- return;
- // this will be needed for some things like damage etc
- // if(avatar.currentParcelUUID == parcelID)
- // startLandObject.SendLandUpdateToClient(avatar.ControllingClient);
- if(changedoverlay && !avatar.IsNPC)
- World.LandChannel.SendParcelsOverlay(avatar.ControllingClient);
- });
- }
- }
- }
- public void osSetParcelMusicURL(LSL_String url)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMusicURL");
- ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
- if (land != null)
- land.SetMusicUrl(url);
- }
- public void osSetParcelMediaURL(LSL_String url)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
- ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
- if (land != null)
- land.SetMediaUrl(url);
- }
- public void osSetParcelSIPAddress(string SIPAddress)
- {
- // What actually is the difference to the LL function?
- //
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelSIPAddress");
- ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
- if (land.LandData.OwnerID != m_host.OwnerID)
- {
- OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function");
- return;
- }
- // get the voice module
- IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>();
- if (voiceModule != null)
- voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID);
- else
- OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
- }
- public string osGetScriptEngineName()
- {
- // This gets a "high" because knowing the engine may be used
- // to exploit engine-specific bugs or induce usage patterns
- // that trigger engine-specific failures.
- // Besides, public grid users aren't supposed to know.
- //
- CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName");
- int scriptEngineNameIndex = 0;
- if (!String.IsNullOrEmpty(m_ScriptEngine.ScriptEngineName))
- {
- // parse off the "ScriptEngine."
- scriptEngineNameIndex = m_ScriptEngine.ScriptEngineName.IndexOf(".", scriptEngineNameIndex);
- scriptEngineNameIndex++; // get past delimiter
- int scriptEngineNameLength = m_ScriptEngine.ScriptEngineName.Length - scriptEngineNameIndex;
- // create char array then a string that is only the script engine name
- Char[] scriptEngineNameCharArray = m_ScriptEngine.ScriptEngineName.ToCharArray(scriptEngineNameIndex, scriptEngineNameLength);
- String scriptEngineName = new String(scriptEngineNameCharArray);
- return scriptEngineName;
- }
- else
- {
- return String.Empty;
- }
- }
- public LSL_Integer osCheckODE()
- {
- CheckThreatLevel();
- LSL_Integer ret = 0; // false
- if (m_ScriptEngine.World.PhysicsScene != null)
- {
- string physEngine = m_ScriptEngine.World.PhysicsScene.EngineType;
- if (physEngine == "OpenDynamicsEngine")
- {
- ret = 1; // true
- }
- }
- return ret;
- }
- public string osGetPhysicsEngineType()
- {
- // High because it can be used to target attacks to known weaknesses
- // This would allow a new class of griefer scripts that don't even
- // require their user to know what they are doing (see script
- // kiddie)
- // Because it would be nice if scripts didn't blow up if the information
- // about the physics engine, this function returns an empty string if
- // the user does not have permission to see it. This as opposed to
- // throwing an exception.
- m_host.AddScriptLPS(1);
- string ret = String.Empty;
- if (String.IsNullOrEmpty(CheckThreatLevelTest(ThreatLevel.High, "osGetPhysicsEngineType")))
- {
- if (m_ScriptEngine.World.PhysicsScene != null)
- {
- ret = m_ScriptEngine.World.PhysicsScene.EngineType;
- // An old physics engine might have an uninitialized engine type
- if (ret == null)
- ret = "unknown";
- }
- }
- return ret;
- }
- public string osGetPhysicsEngineName()
- {
- CheckThreatLevel();
- string ret = "NoEngine";
- if (m_ScriptEngine.World.PhysicsScene != null)
- {
- ret = m_ScriptEngine.World.PhysicsScene.EngineName;
- // An old physics engine might have an uninitialized engine type
- if (ret == null)
- ret = "UnknownEngine";
- }
- return ret;
- }
- public string osGetSimulatorVersion()
- {
- // High because it can be used to target attacks to known weaknesses
- // This would allow a new class of griefer scripts that don't even
- // require their user to know what they are doing (see script
- // kiddie)
- //
- CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion");
- return m_ScriptEngine.World.GetSimulatorVersion();
- }
- /// <summary>
- /// Send a message to to object identified by the given UUID
- /// </summary>
- /// <remarks>
- /// A script in the object must implement the dataserver function
- /// the dataserver function is passed the ID of the calling function and a string message
- /// </remarks>
- /// <param name="objectUUID"></param>
- /// <param name="message"></param>
- public void osMessageObject(LSL_Key objectUUID, string message)
- {
- CheckThreatLevel(ThreatLevel.Low, "osMessageObject");
- if (!UUID.TryParse(objectUUID, out UUID objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead.
- {
- OSSLShoutError("osMessageObject() cannot send messages to objects with invalid UUIDs");
- return;
- }
- MessageObject(objUUID, message);
- }
- private void MessageObject(UUID objUUID, string message)
- {
- object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) };
- SceneObjectPart sceneOP = World.GetSceneObjectPart(objUUID);
- if (sceneOP == null) // prior to patching, PostObjectEvent() would cause a throw exception to be shouted instead.
- {
- OSSLShoutError("osMessageObject() cannot send message to " + objUUID.ToString() + ", object was not found in scene.");
- return;
- }
- m_ScriptEngine.PostObjectEvent(
- sceneOP.LocalId, new EventParams(
- "dataserver", resobj, new DetectParams[0]));
- }
- /// <summary>
- /// Similar to llDie but given an object UUID
- /// </summary>
- /// <param name="objectUUID"></param>
- public void osDie(LSL_Key objectUUID)
- {
- // CheckThreatLevel(ThreatLevel.VeryHigh, "osDie");
- // if this is restricted to objects rezzed by this host level can be reduced
- CheckThreatLevel(ThreatLevel.Low, "osDie");
- if (!UUID.TryParse(objectUUID, out UUID objUUID))
- {
- OSSLShoutError("osDie() cannot delete objects with invalid UUIDs");
- return;
- }
- InitLSL();
- // harakiri check
- if(objUUID == UUID.Zero)
- {
- if (!m_host.ParentGroup.IsAttachment)
- m_LSL_Api.llDie();
- return;
- }
- SceneObjectGroup sceneOG = World.GetSceneObjectGroup(objUUID);
- if (sceneOG == null || sceneOG.IsDeleted)
- return;
- if(sceneOG.IsAttachment)
- return;
- if (sceneOG.OwnerID != m_host.OwnerID)
- return;
- // harakiri check
- if(sceneOG.UUID == m_host.ParentGroup.UUID)
- {
- m_LSL_Api.llDie();
- return;
- }
- // restrict to objects rezzed by host
- if(sceneOG.RezzerID == m_host.ParentGroup.UUID)
- World.DeleteSceneObject(sceneOG, false);
- }
- /// <summary>
- /// Write a notecard directly to the prim's inventory.
- /// </summary>
- /// <remarks>
- /// This needs ThreatLevel high. It is an excellent griefer tool,
- /// In a loop, it can cause asset bloat and DOS levels of asset
- /// writes.
- /// </remarks>
- /// <param name="notecardName">The name of the notecard to write.</param>
- /// <param name="contents">The contents of the notecard.</param>
- public void osMakeNotecard(string notecardName, LSL_Types.list contents)
- {
- CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
- StringBuilder notecardData = new StringBuilder();
- for (int i = 0; i < contents.Length; i++)
- notecardData.Append((string)(contents.GetLSLStringItem(i) + "\n"));
- SaveNotecard(notecardName, "Script generated notecard", notecardData.ToString(), false);
- }
- /// <summary>
- /// Save a notecard to prim inventory.
- /// </summary>
- /// <param name="name"></param>
- /// <param name="description">Description of notecard</param>
- /// <param name="notecardData"></param>
- /// <param name="forceSameName">
- /// If true, then if an item exists with the same name, it is replaced.
- /// If false, then a new item is created witha slightly different name (e.g. name 1)
- /// </param>
- /// <returns>Prim inventory item created.</returns>
- protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName)
- {
- // Create new asset
- AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString())
- {
- Description = description
- };
- byte[] a;
- byte[] b;
- byte[] c;
- b = Util.UTF8.GetBytes(data);
- a = Util.UTF8.GetBytes(
- "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " + b.Length.ToString() + "\n");
- c = Util.UTF8.GetBytes("}");
- byte[] d = new byte[a.Length + b.Length + c.Length];
- Buffer.BlockCopy(a, 0, d, 0, a.Length);
- Buffer.BlockCopy(b, 0, d, a.Length, b.Length);
- Buffer.BlockCopy(c, 0, d, a.Length + b.Length, c.Length);
- asset.Data = d;
- World.AssetService.Store(asset);
- // Create Task Entry
- TaskInventoryItem taskItem = new TaskInventoryItem();
- taskItem.ResetIDs(m_host.UUID);
- taskItem.ParentID = m_host.UUID;
- taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
- taskItem.Name = name;
- taskItem.Description = description;
- taskItem.Type = (int)AssetType.Notecard;
- taskItem.InvType = (int)InventoryType.Notecard;
- taskItem.OwnerID = m_host.OwnerID;
- taskItem.CreatorID = m_host.OwnerID;
- taskItem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
- taskItem.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
- taskItem.EveryonePermissions = 0;
- taskItem.NextPermissions = (uint)PermissionMask.All;
- taskItem.GroupID = m_host.GroupID;
- taskItem.GroupPermissions = 0;
- taskItem.Flags = 0;
- taskItem.PermsGranter = UUID.Zero;
- taskItem.PermsMask = 0;
- taskItem.AssetID = asset.FullID;
- if (forceSameName)
- m_host.Inventory.AddInventoryItemExclusive(taskItem, false);
- else
- m_host.Inventory.AddInventoryItem(taskItem, false);
- m_host.ParentGroup.InvalidateDeepEffectivePerms();
- return taskItem;
- }
- /// <summary>
- /// Load the notecard data found at the given prim inventory item name or asset uuid.
- /// </summary>
- /// <param name="notecardNameOrUuid"></param>
- /// <returns>The text loaded. Null if no notecard was found.</returns>
- protected string LoadNotecard(string notecardNameOrUuid)
- {
- UUID assetID = CacheNotecard(notecardNameOrUuid);
- if (assetID != UUID.Zero)
- {
- StringBuilder notecardData = new StringBuilder();
- for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
- {
- string line = NotecardCache.GetLine(assetID, count) + "\n";
- // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
- notecardData.Append(line);
- }
- return notecardData.ToString();
- }
- return null;
- }
- /// <summary>
- /// Cache a notecard's contents.
- /// </summary>
- /// <param name="notecardNameOrUuid"></param>
- /// <returns>
- /// The asset id of the notecard, which is used for retrieving the cached data.
- /// UUID.Zero if no asset could be found.
- /// </returns>
- protected UUID CacheNotecard(string notecardNameOrUuid)
- {
- UUID assetID = UUID.Zero;
- bool notecardNameIsUUID = UUID.TryParse(notecardNameOrUuid, out assetID);
- if (!notecardNameIsUUID)
- {
- assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
- }
- if (assetID == UUID.Zero)
- return UUID.Zero;
- if (!NotecardCache.IsCached(assetID))
- {
- AssetBase a = World.AssetService.Get(assetID.ToString());
- if (a == null)
- {
- // Whoops, it's still possible here that the notecard name was properly
- // formatted like a UUID but isn't an asset UUID so lets look it up by name after all
- assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
- if (assetID == UUID.Zero)
- return UUID.Zero;
- if (!NotecardCache.IsCached(assetID))
- {
- a = World.AssetService.Get(assetID.ToString());
- if (a == null)
- {
- return UUID.Zero;
- }
- }
- }
- NotecardCache.Cache(assetID, a.Data);
- };
- return assetID;
- }
- protected UUID SearchTaskInventoryForAssetId(string name)
- {
- UUID assetId = UUID.Zero;
- m_host.TaskInventory.LockItemsForRead(true);
- foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
- {
- if (item.Type == 7 && item.Name == name)
- {
- assetId = item.AssetID;
- }
- }
- m_host.TaskInventory.LockItemsForRead(false);
- return assetId;
- }
- /// <summary>
- /// Directly get an entire notecard at once.
- /// </summary>
- /// <remarks>
- /// Instead of using the LSL Dataserver event to pull notecard data
- /// this will simply read the entire notecard and return its data as a string.
- ///
- /// Warning - due to the synchronous method this function uses to fetch assets, its use
- /// may be dangerous and unreliable while running in grid mode.
- /// </remarks>
- /// <param name="name">Name of the notecard or its asset id</param>
- /// <param name="line">The line number to read. The first line is line 0</param>
- /// <returns>Notecard line</returns>
- public string osGetNotecardLine(string name, int line)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
- UUID assetID = CacheNotecard(name);
- if (assetID == UUID.Zero)
- {
- OSSLShoutError("Notecard '" + name + "' could not be found.");
- return "ERROR!";
- }
- return NotecardCache.GetLine(assetID, line);
- }
- /// <summary>
- /// Get an entire notecard at once.
- /// </summary>
- /// <remarks>
- /// Instead of using the LSL Dataserver event to pull notecard data line by line,
- /// this will simply read the entire notecard and return its data as a string.
- ///
- /// Warning - due to the synchronous method this function uses to fetch assets, its use
- /// may be dangerous and unreliable while running in grid mode.
- /// </remarks>
- /// <param name="name">Name of the notecard or its asset id</param>
- /// <returns>Notecard text</returns>
- public string osGetNotecard(string name)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
- string text = LoadNotecard(name);
- if (text == null)
- {
- OSSLShoutError("Notecard '" + name + "' could not be found.");
- return "ERROR!";
- }
- else
- {
- return text;
- }
- }
- /// <summary>
- /// Get the number of lines in the given notecard.
- /// </summary>
- /// <remarks>
- /// Instead of using the LSL Dataserver event to pull notecard data,
- /// this will simply read the number of note card lines and return this data as an integer.
- ///
- /// Warning - due to the synchronous method this function uses to fetch assets, its use
- /// may be dangerous and unreliable while running in grid mode.
- /// </remarks>
- /// <param name="name">Name of the notecard or its asset id</param>
- /// <returns></returns>
- public int osGetNumberOfNotecardLines(string name)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
- UUID assetID = CacheNotecard(name);
- if (assetID == UUID.Zero)
- {
- OSSLShoutError("Notecard '" + name + "' could not be found.");
- return -1;
- }
- return NotecardCache.GetLines(assetID);
- }
- public string osAvatarName2Key(string firstname, string lastname)
- {
- CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");
- IUserManagement userManager = World.RequestModuleInterface<IUserManagement>();
- if (userManager == null)
- {
- OSSLShoutError("osAvatarName2Key: UserManagement module not available");
- return string.Empty;
- }
- // Check local grid
- UUID userID = userManager.GetUserIdByName(firstname, lastname);
- if (userID != UUID.Zero)
- return userID.ToString();
- // HG ?
- if (Util.ParseForeignAvatarName(firstname, lastname, out string realFirstName, out string realLastName, out string serverURI))
- {
- try
- {
- UserAgentServiceConnector userConnection = new UserAgentServiceConnector(serverURI);
- if (userConnection != null)
- {
- userID = userConnection.GetUUID(realFirstName, realLastName);
- if (userID != UUID.Zero)
- {
- userManager.AddUser(userID, realFirstName, realLastName, serverURI);
- return userID.ToString();
- }
- }
- }
- catch (Exception /*e*/)
- {
- // m_log.Warn("[osAvatarName2Key] UserAgentServiceConnector - Unable to connect to destination grid ", e);
- }
- }
- return ScriptBaseClass.NULL_KEY;
- }
- public string osKey2Name(string id)
- {
- CheckThreatLevel(ThreatLevel.Low, "osKey2Name");
- UUID key = new UUID();
- if (UUID.TryParse(id, out key))
- {
- UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
- if (account != null)
- return account.Name;
- if (m_ScriptEngine.World.GridUserService != null)
- {
- GridUserInfo uInfo = m_ScriptEngine.World.GridUserService.GetGridUserInfo(key.ToString());
- if (uInfo != null)
- {
- if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out UUID userUUID,
- out string gridURL, out string firstName,
- out string lastName, out string tmp))
- {
- string grid = new Uri(gridURL).Authority;
- return firstName + "." + lastName + " @" + grid;
- }
- }
- }
- }
- return "";
- }
- private enum InfoType
- {
- Nick,
- Name,
- Login,
- Home,
- Custom
- };
- private string GridUserInfo(InfoType type)
- {
- return GridUserInfo(type, "");
- }
- private string GridUserInfo(InfoType type, string key)
- {
- string retval = String.Empty;
- IConfigSource config = m_ScriptEngine.ConfigSource;
- string url = null;
- IConfig gridInfoConfig = config.Configs["GridInfo"];
- if (gridInfoConfig != null)
- url = gridInfoConfig.GetString("GridInfoURI", String.Empty);
- if (String.IsNullOrEmpty(url))
- return "Configuration Error!";
- string verb ="/json_grid_info";
- OSDMap json = new OSDMap();
- OSDMap info = WebUtil.GetFromService(String.Format("{0}{1}",url,verb), 3000);
- if (info["Success"] != true)
- return "Get GridInfo Failed!";
- json = (OSDMap)OSDParser.DeserializeJson(info["_RawResult"].AsString());
- switch (type)
- {
- case InfoType.Nick:
- retval = json["gridnick"];
- break;
- case InfoType.Name:
- retval = json["gridname"];
- break;
- case InfoType.Login:
- retval = json["login"];
- break;
- case InfoType.Home:
- retval = json["home"];
- break;
- case InfoType.Custom:
- retval = json[key];
- break;
- default:
- retval = "error";
- break;
- }
- return retval;
- }
- public string osSHA256(string input)
- {
- // Create a SHA256
- using (SHA256 sha256Hash = SHA256.Create())
- {
- // ComputeHash - returns byte array
- byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
- return Util.bytesToHexString(bytes, true);
- }
- }
- /// <summary>
- /// Get the nickname of this grid, as set in the [GridInfo] config section.
- /// </summary>
- /// <remarks>
- /// Threat level is Moderate because intentional abuse, for instance
- /// scripts that are written to be malicious only on one grid,
- /// for instance in a HG scenario, are a distinct possibility.
- /// </remarks>
- /// <returns></returns>
- public string osGetGridNick()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
- string nick = String.Empty;
- IConfigSource config = m_ScriptEngine.ConfigSource;
- if (config.Configs[GridInfoServiceConfigSectionName] != null)
- nick = config.Configs[GridInfoServiceConfigSectionName].GetString("gridnick", nick);
- if (String.IsNullOrEmpty(nick))
- nick = GridUserInfo(InfoType.Nick);
- return nick;
- }
- public string osGetGridName()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName");
- if(World.SceneGridInfo == null)
- return string.Empty;
- return World.SceneGridInfo.GridName;
- }
- public string osGetGridLoginURI()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI");
- string loginURI = String.Empty;
- IConfigSource config = m_ScriptEngine.ConfigSource;
- if (config.Configs[GridInfoServiceConfigSectionName] != null)
- loginURI = config.Configs[GridInfoServiceConfigSectionName].GetString("login", loginURI);
- if (String.IsNullOrEmpty(loginURI))
- loginURI = GridUserInfo(InfoType.Login);
- return loginURI;
- }
- public string osGetGridHomeURI()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI");
- return World.SceneGridInfo.HomeURLNoEndSlash;
- }
- public string osGetGridGatekeeperURI()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI");
- return World.SceneGridInfo.GateKeeperURLNoEndSlash;
- }
- public string osGetGridCustom(string key)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridCustom");
- string retval = String.Empty;
- IConfigSource config = m_ScriptEngine.ConfigSource;
- if (config.Configs[GridInfoServiceConfigSectionName] != null)
- retval = config.Configs[GridInfoServiceConfigSectionName].GetString(key, retval);
- if (String.IsNullOrEmpty(retval))
- retval = GridUserInfo(InfoType.Custom, key);
- return retval;
- }
- public string osGetAvatarHomeURI(string uuid)
- {
- CheckThreatLevel(ThreatLevel.Low, "osGetAvatarHomeURI");
- IUserManagement userManager = m_ScriptEngine.World.RequestModuleInterface<IUserManagement>();
- string returnValue = "";
- if (userManager != null)
- {
- returnValue = userManager.GetUserServerURL(new UUID(uuid), "HomeURI");
- }
- if (returnValue == "")
- return World.SceneGridInfo.HomeURLNoEndSlash;
- return returnValue;
- }
- public LSL_String osFormatString(string str, LSL_List strings)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osFormatString");
- return String.Format(str, strings.Data);
- }
- public LSL_List osMatchString(string src, string pattern, int start)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osMatchString");
- LSL_List result = new LSL_List();
- // Normalize indices (if negative).
- // After normlaization they may still be
- // negative, but that is now relative to
- // the start, rather than the end, of the
- // sequence.
- if (start < 0)
- {
- start = src.Length + start;
- }
- if (start < 0 || start >= src.Length)
- {
- return result; // empty list
- }
- // Find matches beginning at start position
- Regex matcher = new Regex(pattern);
- Match match = matcher.Match(src, start);
- while (match.Success)
- {
- foreach (System.Text.RegularExpressions.Group g in match.Groups)
- {
- if (g.Success)
- {
- result.Add(new LSL_String(g.Value));
- result.Add(new LSL_Integer(g.Index));
- }
- }
- match = match.NextMatch();
- }
- return result;
- }
- public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osReplaceString");
- // Normalize indices (if negative).
- // After normlaization they may still be
- // negative, but that is now relative to
- // the start, rather than the end, of the
- // sequence.
- if (start < 0)
- {
- start = src.Length + start;
- }
- if (start < 0 || start >= src.Length)
- {
- return src;
- }
- // Find matches beginning at start position
- Regex matcher = new Regex(pattern);
- return matcher.Replace(src,replace,count,start);
- }
- public string osLoadedCreationDate()
- {
- CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
- return World.RegionInfo.RegionSettings.LoadedCreationDate;
- }
- public string osLoadedCreationTime()
- {
- CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime");
- return World.RegionInfo.RegionSettings.LoadedCreationTime;
- }
- public string osLoadedCreationID()
- {
- CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID");
- return World.RegionInfo.RegionSettings.LoadedCreationID;
- }
- /// <summary>
- /// Get the primitive parameters of a linked prim.
- /// </summary>
- /// <remarks>
- /// Threat level is 'Low' because certain users could possibly be tricked into
- /// dropping an unverified script into one of their own objects, which could
- /// then gather the physical construction details of the object and transmit it
- /// to an unscrupulous third party, thus permitting unauthorized duplication of
- /// the object's form.
- /// </remarks>
- /// <param name="linknumber"></param>
- /// <param name="rules"></param>
- /// <returns></returns>
- public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
- {
- CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
- InitLSL();
- // One needs to cast m_LSL_Api because we're using functions not
- // on the ILSL_Api interface.
- LSL_List retVal = new LSL_List();
- LSL_List remaining = new LSL_List();
- List<SceneObjectPart> parts = m_LSL_Api.GetLinkParts(linknumber);
- foreach (SceneObjectPart part in parts)
- {
- remaining = m_LSL_Api.GetPrimParams(part, rules, ref retVal);
- }
- while (remaining.Length > 1)
- {
- linknumber = remaining.GetLSLIntegerItem(0);
- parts = m_LSL_Api.GetLinkParts(linknumber);
- if(parts.Count == 0)
- break;
- rules = remaining.GetSublist(1, -1);
- foreach (SceneObjectPart part in parts)
- remaining = m_LSL_Api.GetPrimParams(part, rules, ref retVal);
- }
- return retVal;
- }
- public void osForceCreateLink(string target, int parent)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osForceCreateLink");
- InitLSL();
- m_LSL_Api.CreateLink(target, parent);
- }
- public void osForceBreakLink(int linknum)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakLink");
- InitLSL();
- m_LSL_Api.BreakLink(linknum);
- }
- public void osForceBreakAllLinks()
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakAllLinks");
- InitLSL();
- m_LSL_Api.BreakAllLinks();
- }
- public LSL_Integer osIsNpc(LSL_Key npc)
- {
- CheckThreatLevel();
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- if (UUID.TryParse(npc.m_string, out UUID npcId))
- if (module.IsNPC(npcId, World))
- return ScriptBaseClass.TRUE;
- }
- return ScriptBaseClass.FALSE;
- }
- public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
- // have to get the npc module also here to set the default Not Owned
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if(module == null)
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- bool owned = (module.NPCOptionFlags & NPCOptionsFlags.AllowNotOwned) == 0;
- return NpcCreate(firstname, lastname, position, notecard, owned, false, false);
- }
- public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
- return NpcCreate(
- firstname, lastname, position, notecard,
- (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0,
- (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0,
- (options & ScriptBaseClass.OS_NPC_OBJECT_GROUP) != 0);
- }
- private LSL_Key NpcCreate(
- string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent, bool hostGroupID)
- {
- if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z)))
- {
- OSSLError("no permission to rez NPC at requested location");
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- }
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if(module == null)
- {
- OSSLError("NPC module not enabled");
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- }
- string groupTitle = String.Empty;
- UUID groupID = UUID.Zero;
- AvatarAppearance appearance = null;
- // check creation options
- NPCOptionsFlags createFlags = module.NPCOptionFlags;
- if((createFlags & NPCOptionsFlags.AllowNotOwned) == 0 && !owned)
- {
- OSSLError("Not owned NPCs disabled");
- owned = true; // we should get here...
- }
- if((createFlags & NPCOptionsFlags.AllowSenseAsAvatar) == 0 && senseAsAgent)
- {
- OSSLError("NPC allow sense as Avatar disabled");
- senseAsAgent = false;
- }
- if(hostGroupID && m_host.GroupID != UUID.Zero)
- {
- if (m_groupsModule != null)
- {
- GroupMembershipData member = m_groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
- if (member == null)
- {
- OSSLError(string.Format("osNpcCreate: the object owner is not member of the object group"));
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- }
- groupID = m_host.GroupID;
- if((createFlags & NPCOptionsFlags.NoNPCGroup) != 0)
- {
- GroupRecord grprec = m_groupsModule.GetGroupRecord(m_host.GroupID);
- if(grprec != null && grprec.GroupName != "")
- groupTitle = grprec.GroupName;
- }
- }
- }
- if((createFlags & NPCOptionsFlags.NoNPCGroup) == 0)
- {
- if (firstname != String.Empty || lastname != String.Empty)
- {
- if (firstname != "Shown outfit:")
- groupTitle = "- NPC -";
- }
- }
- if((createFlags & NPCOptionsFlags.AllowCloneOtherAvatars) != 0)
- {
- if (UUID.TryParse(notecard, out UUID id))
- {
- ScenePresence clonePresence = World.GetScenePresence(id);
- if (clonePresence != null)
- appearance = clonePresence.Appearance;
- }
- }
- if (appearance == null)
- {
- if(!string.IsNullOrWhiteSpace(notecard))
- {
- string appearanceSerialized = LoadNotecard(notecard);
- if (appearanceSerialized == null)
- {
- OSSLError(string.Format("osNpcCreate: Notecard '{0}' not found.", notecard));
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- }
- try
- {
- OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
- appearance = new AvatarAppearance();
- appearance.Unpack(appearanceOsd);
- }
- catch
- {
- OSSLError(string.Format("osNpcCreate: Error processing notecard '{0}'", notecard));
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- }
- }
- }
- UUID ownerID = UUID.Zero;
- if (owned)
- ownerID = m_host.OwnerID;
- UUID x = module.CreateNPC(firstname,
- lastname,
- position,
- UUID.Random(),
- ownerID,
- groupTitle,
- groupID,
- senseAsAgent,
- World,
- appearance);
- if (World.TryGetScenePresence(x, out ScenePresence sp))
- {
- sp.SendAvatarDataToAllAgents();
- }
- return new LSL_Key(x.ToString());
- }
- /// <summary>
- /// Save the current appearance of the NPC permanently to the named notecard.
- /// </summary>
- /// <param name="avatar"></param>
- /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
- /// <returns>The asset ID of the notecard saved.</returns>
- public LSL_Key osNpcSaveAppearance(LSL_Key npc, LSL_String notecard)
- {
- return NpcSaveAppearance(npc, notecard, false);
- }
- public LSL_Key osNpcSaveAppearance(LSL_Key npc, LSL_String notecard, LSL_Integer includeHuds)
- {
- return NpcSaveAppearance(npc, notecard, includeHuds == 0);
- }
- protected LSL_Key NpcSaveAppearance(LSL_Key npc, string notecard, bool NoHUds)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance");
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- if (!UUID.TryParse(npc.m_string, out UUID npcId))
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- return SaveAppearanceToNotecard(npcId, notecard, NoHUds);
- }
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- }
- public void osNpcLoadAppearance(LSL_Key npc, string notecard)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance");
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- if (!UUID.TryParse(npc.m_string, out UUID npcId))
- return;
- if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
- return;
- string appearanceSerialized = LoadNotecard(notecard);
- if (appearanceSerialized == null)
- OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
- OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
- // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
- // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
- // Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a);
- AvatarAppearance appearance = new AvatarAppearance();
- appearance.Unpack(appearanceOsd);
- npcModule.SetNPCAppearance(npcId, appearance, m_host.ParentGroup.Scene);
- }
- }
- public LSL_Key osNpcGetOwner(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.None, "osNpcGetOwner");
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- if (UUID.TryParse(npc.m_string, out UUID npcId))
- {
- UUID owner = npcModule.GetOwner(npcId);
- if (owner != UUID.Zero)
- return new LSL_Key(owner.ToString());
- else
- return npc;
- }
- }
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- }
- public LSL_Vector osNpcGetPos(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcGetPos");
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- if (!UUID.TryParse(npc.m_string, out UUID npcId))
- return new LSL_Vector(0, 0, 0);
- if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
- return new LSL_Vector(0, 0, 0);
- ScenePresence sp = World.GetScenePresence(npcId);
- if (sp != null)
- return new LSL_Vector(sp.AbsolutePosition);
- }
- return Vector3.Zero;
- }
- public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- if (!UUID.TryParse(npc.m_string, out UUID npcId))
- return;
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.MoveToTarget(npcId, World, pos, false, true, false);
- }
- }
- public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- if (!UUID.TryParse(npc.m_string, out UUID npcId))
- return;
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.MoveToTarget(
- new UUID(npc.m_string),
- World,
- target,
- (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
- (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0,
- (options & ScriptBaseClass.OS_NPC_RUNNING) != 0);
- }
- }
- public LSL_Rotation osNpcGetRot(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcGetRot");
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- if (!UUID.TryParse(npc.m_string, out UUID npcId))
- return new LSL_Rotation(Quaternion.Identity);
- if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
- return new LSL_Rotation(Quaternion.Identity);
- ScenePresence sp = World.GetScenePresence(npcId);
- if (sp != null)
- return new LSL_Rotation(sp.GetWorldRotation());
- }
- return Quaternion.Identity;
- }
- public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcSetRot");
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- if (!UUID.TryParse(npc.m_string, out UUID npcId))
- return;
- if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
- return;
- ScenePresence sp = World.GetScenePresence(npcId);
- if (sp != null)
- sp.Rotation = rotation;
- }
- }
- public void osNpcStopMoveToTarget(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.StopMoveToTarget(npcId, World);
- }
- }
- public void osNpcSetProfileAbout(LSL_Key npc, string about)
- {
- CheckThreatLevel(ThreatLevel.Low, "osNpcSetProfileAbout");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- ScenePresence sp = World.GetScenePresence(npcId);
- if (sp != null)
- ((INPC)(sp.ControllingClient)).profileAbout = about;
- }
- }
- public void osNpcSetProfileImage(LSL_Key npc, string image)
- {
- CheckThreatLevel(ThreatLevel.Low, "osNpcSetProfileImage");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- UUID ImageID = new UUID();
- ImageID = ScriptUtils.GetAssetIdFromItemName(m_host, image, (int)AssetType.Texture);
- if (ImageID == null || ImageID == UUID.Zero)
- {
- if (!UUID.TryParse(image, out ImageID))
- return;
- }
- ScenePresence sp = World.GetScenePresence(npcId);
- if (sp != null)
- ((INPC)(sp.ControllingClient)).profileImage = ImageID;
- }
- }
- public void osNpcSay(LSL_Key npc, string message)
- {
- osNpcSay(npc, 0, message);
- }
- public void osNpcSay(LSL_Key npc, int channel, string message)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcSay");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.Say(npcId, World, message, channel);
- }
- }
- public void osNpcSayTo(LSL_Key npc, LSL_Key target, int channel, string msg)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcSayTo");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module == null)
- return;
- if (!UUID.TryParse(npc.m_string, out UUID npcId))
- return;
- if (!UUID.TryParse(target.m_string, out UUID TargetID))
- return;
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- ScenePresence NPCpresence = World.GetScenePresence(npcId);
- if (NPCpresence == null || NPCpresence.IsDeleted || !NPCpresence.IsNPC)
- return;
- Vector3 npcPOS = NPCpresence.AbsolutePosition;
- string npcNAME = NPCpresence.Name;
- IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
- if (wComm != null)
- wComm.DeliverMessageTo(TargetID, channel, npcPOS, npcNAME, npcId, msg);
- }
- public void osNpcShout(LSL_Key npc, int channel, string message)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcShout");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.Shout(npcId, World, message, channel);
- }
- }
- public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcSit");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.Sit(npcId, new UUID(target.m_string), World);
- }
- }
- public void osNpcStand(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcStand");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.Stand(npcId, World);
- }
- }
- public void osNpcRemove(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
- try
- {
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.DeleteNPC(npcId, World);
- }
- }
- catch { }
- }
- public void osNpcPlayAnimation(LSL_Key npc, string animation)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcPlayAnimation");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module == null)
- return;
- if (!UUID.TryParse(npc.m_string, out UUID npcID))
- return;
- ScenePresence target = World.GetScenePresence(npcID);
- if (target == null || !target.IsNPC)
- return;
- if (!module.CheckPermissions(npcID, m_host.OwnerID))
- return;
- UUID animID = UUID.Zero;
- m_host.TaskInventory.LockItemsForRead(true);
- foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
- {
- if (inv.Value.Type == (int)AssetType.Animation)
- {
- if (inv.Value.Name == animation)
- {
- animID = inv.Value.AssetID;
- break;
- }
- }
- }
- m_host.TaskInventory.LockItemsForRead(false);
- if (animID == UUID.Zero)
- target.Animator.AddAnimation(animation, m_host.UUID);
- else
- target.Animator.AddAnimation(animID, m_host.UUID);
- }
- public void osNpcStopAnimation(LSL_Key npc, string animation)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcStopAnimation");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module == null)
- return;
- if (!UUID.TryParse(npc.m_string, out UUID npcID))
- return;
- ScenePresence target = World.GetScenePresence(npcID);
- if (target == null || !target.IsNPC)
- return;
- if (!module.CheckPermissions(npcID, m_host.OwnerID))
- return;
- if (!UUID.TryParse(animation, out UUID animID))
- {
- TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation);
- if (item != null && item.Type == (int)AssetType.Animation)
- animID = item.AssetID;
- else
- animID = UUID.Zero;
- }
- if (animID == UUID.Zero)
- target.Animator.RemoveAnimation(animation);
- else
- target.Animator.RemoveAnimation(animID, true);
- }
- public void osNpcWhisper(LSL_Key npc, int channel, string message)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcWhisper");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.Whisper(npcId, World, message, channel);
- }
- }
- public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcTouch");
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- int linkNum = link_num.value;
- if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS))
- {
- if (!UUID.TryParse(npcLSL_Key, out UUID npcId) || !module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- SceneObjectPart part = null;
- if (UUID.TryParse(LSL_String.ToString(object_key), out UUID objectId))
- part = World.GetSceneObjectPart(objectId);
- if (part == null)
- return;
- if (linkNum != ScriptBaseClass.LINK_THIS)
- {
- if (linkNum == 0 || linkNum == ScriptBaseClass.LINK_ROOT)
- { // 0 and 1 are treated as root, find the root if the current part isnt it
- if (!part.IsRoot)
- part = part.ParentGroup.RootPart;
- }
- else
- { // Find the prim with the given link number if not found then fail silently
- part = part.ParentGroup.GetLinkNumPart(linkNum);
- if (part == null)
- return;
- }
- }
- module.Touch(npcId, part.UUID);
- }
- }
- /// <summary>
- /// Save the current appearance of the script owner permanently to the named notecard.
- /// </summary>
- /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
- /// <returns>The asset ID of the notecard saved.</returns>
- public LSL_Key osOwnerSaveAppearance(LSL_String notecard)
- {
- CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance");
- return SaveAppearanceToNotecard(m_host.OwnerID, notecard, false);
- }
- public LSL_Key osOwnerSaveAppearance(LSL_String notecard, LSL_Integer includeHuds)
- {
- CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance");
- return SaveAppearanceToNotecard(m_host.OwnerID, notecard, includeHuds == 0);
- }
- public LSL_Key osAgentSaveAppearance(LSL_Key avatarKey, LSL_String notecard)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance");
- if (!UUID.TryParse(avatarKey, out UUID avatarId))
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- return SaveAppearanceToNotecard(avatarId, notecard, false);
- }
- public LSL_Key osAgentSaveAppearance(LSL_Key avatarKey, LSL_String notecard, LSL_Integer includeHuds)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance");
- if (!UUID.TryParse(avatarKey, out UUID avatarId))
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- return SaveAppearanceToNotecard(avatarId, notecard, includeHuds == 0);
- }
- protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecard, bool NoHuds)
- {
- ScenePresence sp = World.GetScenePresence(avatarId);
- if (sp == null || sp.IsChildAgent)
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- return SaveAppearanceToNotecard(sp, notecard, NoHuds);
- }
- protected LSL_Key SaveAppearanceToNotecard(ScenePresence sp, string notecard, bool NoHuds)
- {
- IAvatarFactoryModule appearanceModule = World.RequestModuleInterface<IAvatarFactoryModule>();
- if (appearanceModule != null)
- {
- appearanceModule.SaveBakedTextures(sp.UUID);
- OSDMap appearancePacked = sp.Appearance.PackForNotecard(NoHuds);
- TaskInventoryItem item
- = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true);
- return new LSL_Key(item.AssetID.ToString());
- }
- else
- {
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- }
- }
- /// <summary>
- /// Get the gender as specified in avatar appearance for a given avatar key
- /// </summary>
- /// <param name="rawAvatarId"></param>
- /// <returns>"male" or "female" or "unknown"</returns>
- public LSL_String osGetGender(LSL_Key rawAvatarId)
- {
- CheckThreatLevel(ThreatLevel.None, "osGetGender");
- if (!UUID.TryParse(rawAvatarId, out UUID avatarId))
- return new LSL_String("unknown");
- ScenePresence sp = World.GetScenePresence(avatarId);
- if (sp == null || sp.IsChildAgent || sp.Appearance == null || sp.Appearance.VisualParams == null)
- return new LSL_String("unknown");
- // find the index of "shape" parameter "male"
- int vpShapeMaleIndex = 0;
- bool indexFound = false;
- VisualParam param = new VisualParam();
- foreach(var vpEntry in VisualParams.Params)
- {
- param = vpEntry.Value;
- if (param.Name == "male" && param.Wearable == "shape")
- {
- indexFound = true;
- break;
- }
- if (param.Group == 0)
- vpShapeMaleIndex++;
- }
- if (!indexFound)
- return new LSL_String("unknown");
- float vpShapeMale = Utils.ByteToFloat(sp.Appearance.VisualParams[vpShapeMaleIndex], param.MinValue, param.MaxValue);
- bool isMale = vpShapeMale > 0.5f;
- return new LSL_String(isMale ? "male" : "female");
- }
- /// <summary>
- /// Get current region's map texture UUID
- /// </summary>
- /// <returns></returns>
- public LSL_Key osGetMapTexture()
- {
- CheckThreatLevel();
- return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
- }
- /// <summary>
- /// Get a region's map texture UUID by region UUID or name.
- /// </summary>
- /// <param name="regionName"></param>
- /// <returns></returns>
- public LSL_Key osGetRegionMapTexture(string regionNameOrID)
- {
- CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture");
- Scene scene = m_ScriptEngine.World;
- UUID key = UUID.Zero;
- GridRegion region;
- if(string.IsNullOrWhiteSpace(regionNameOrID))
- {
- return scene.RegionInfo.RegionSettings.TerrainImageID.ToString();
- }
- //If string is a key, use it. Otherwise, try to locate region by name.
- if (UUID.TryParse(regionNameOrID, out key))
- region = scene.GridService.GetRegionByUUID(UUID.Zero, key);
- else
- region = scene.GridService.GetRegionByName(UUID.Zero, regionNameOrID);
- // If region was found, return the regions map texture key.
- if (region != null)
- key = region.TerrainImage;
- ScriptSleep(1000);
- return key.ToString();
- }
- /// <summary>
- /// Return information regarding various simulator statistics (sim fps, physics fps, time
- /// dilation, total number of prims, total number of active scripts, script lps, various
- /// timing data, packets in/out, etc. Basically much the information that's shown in the
- /// client's Statistics Bar (Ctrl-Shift-1)
- /// </summary>
- /// <returns>List of floats</returns>
- public LSL_List osGetRegionStats()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
- LSL_List ret = new LSL_List();
- float[] stats = World.StatsReporter.LastReportedSimStats;
- for (int i = 0; i < 21; i++)
- {
- ret.Add(new LSL_Float(stats[i]));
- }
- return ret;
- }
- public LSL_Vector osGetRegionSize()
- {
- CheckThreatLevel();
- Scene scene = m_ScriptEngine.World;
- RegionInfo reg = World.RegionInfo;
- // GridRegion region = scene.GridService.GetRegionByUUID(UUID.Zero, World.RegionInfo.RegionID);
- // return new LSL_Vector((float)region.RegionSizeX, (float)region.RegionSizeY, (float)Constants.RegionHeight);
- return new LSL_Vector((float)reg.RegionSizeX, (float)reg.RegionSizeY, 0.0f);
- }
- public int osGetSimulatorMemory()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory");
- long pws = Util.GetPhysicalMemUse();
- if (pws > Int32.MaxValue)
- return Int32.MaxValue;
- if (pws < 0)
- return 0;
- return (int)pws;
- }
- public int osGetSimulatorMemoryKB()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemoryKB");
- long pws = Util.GetPhysicalMemUse();
- if ((pws & 0x3FFL) != 0)
- pws += 0x400L;
- pws >>= 10;
- if (pws > Int32.MaxValue)
- return Int32.MaxValue;
- return (int)pws;
- }
- public void osSetSpeed(string ID, LSL_Float SpeedModifier)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed");
- if (!UUID.TryParse(ID, out UUID avid))
- return;
- ScenePresence avatar = World.GetScenePresence(avid);
- if (avatar != null)
- avatar.SpeedModifier = (float)SpeedModifier;
- }
- public void osSetOwnerSpeed(LSL_Float SpeedModifier)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osSetOwnerSpeed");
- if(SpeedModifier > 4)
- SpeedModifier = 4;
- ScenePresence avatar = World.GetScenePresence(m_host.OwnerID);
- if (avatar != null)
- avatar.SpeedModifier = (float)SpeedModifier;
- }
- public void osKickAvatar(string FirstName, string SurName, string alert)
- {
- CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
- World.ForEachRootScenePresence(delegate (ScenePresence sp)
- {
- if (sp.Firstname == FirstName && sp.Lastname == SurName)
- {
- // kick client...
- if (alert != null)
- sp.ControllingClient.Kick(alert);
- // ...and close on our side
- sp.Scene.CloseAgent(sp.UUID, false);
- }
- });
- }
- public void osKickAvatar(LSL_Key agentKey, string alert)
- {
- CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
- if (!UUID.TryParse(agentKey, out UUID id) || id == UUID.Zero)
- return;
- ScenePresence sp = World.GetScenePresence(id);
- if(sp == null)
- return;
- // kick client...
- if (alert != null)
- sp.ControllingClient.Kick(alert);
- // ...and close on our side
- sp.Scene.CloseAgent(id, false);
- }
- public LSL_Float osGetHealth(LSL_Key agentKey)
- {
- CheckThreatLevel(ThreatLevel.None, "osGetHealth");
- LSL_Float health = new LSL_Float(-1);
- if (!UUID.TryParse(agentKey, out UUID id) || id == UUID.Zero)
- return health;
- ScenePresence presence = World.GetScenePresence(id);
- if (presence != null)
- health = presence.Health;
- return health;
- }
- public void osCauseDamage(LSL_Key avatar, LSL_Float damage)
- {
- CheckThreatLevel(ThreatLevel.High, "osCauseDamage");
- if (!UUID.TryParse(avatar, out UUID avatarId))
- return;
- ScenePresence presence = World.GetScenePresence(avatarId);
- if (presence == null)
- return;
- Vector3 pos = m_host.GetWorldPosition();
- LandData land = World.GetLandData(pos);
- if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage)
- {
- float health = presence.Health;
- health -= (float)damage;
- presence.setHealthWithUpdate(health);
- if (health <= 0)
- {
- float healthliveagain = 100;
- presence.ControllingClient.SendAgentAlertMessage("You died!", true);
- presence.setHealthWithUpdate(healthliveagain);
- presence.Scene.TeleportClientHome(presence.UUID, presence.ControllingClient);
- }
- }
- }
- public void osCauseHealing(LSL_Key avatar, LSL_Float healing)
- {
- CheckThreatLevel(ThreatLevel.High, "osCauseHealing");
- if (!UUID.TryParse(avatar, out UUID avatarId))
- return;
- ScenePresence presence = World.GetScenePresence(avatarId);
- if (presence == null)
- return;
- float health = presence.Health;
- health += (float)healing;
- if (health >= 100)
- health = 100;
- presence.setHealthWithUpdate(health);
- }
- public void osSetHealth(LSL_Key avatar, LSL_Float health)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetHealth");
- UUID avatarId = new UUID(avatar);
- ScenePresence presence = World.GetScenePresence(avatarId);
- if (presence != null)
- {
- if (health > 100.0)
- health = 100.0;
- else if (health < 1.0)
- health = 1.0;
- presence.setHealthWithUpdate((float)health);
- }
- }
- public void osSetHealRate(LSL_Key avatar, LSL_Float healrate)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetHealRate");
- if (!UUID.TryParse(avatar, out UUID avatarId))
- return;
- ScenePresence presence = World.GetScenePresence(avatarId);
- if (presence == null)
- return;
- presence.HealRate = (float)healrate;
- }
- public LSL_Float osGetHealRate(LSL_Key avatar)
- {
- CheckThreatLevel(ThreatLevel.None, "osGetHealRate");
- LSL_Float rate = new LSL_Float(0);
- if (!UUID.TryParse(avatar, out UUID avatarId))
- return rate;
- ScenePresence presence = World.GetScenePresence(avatarId);
- if (presence != null)
- rate = presence.HealRate;
- return rate;
- }
- public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
- {
- CheckThreatLevel();
- InitLSL();
- return m_LSL_Api.GetPrimitiveParamsEx(prim, rules);
- }
- public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
- {
- CheckThreatLevel();
- InitLSL();
- m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams");
- }
- /// <summary>
- /// Set parameters for light projection in host prim
- /// </summary>
- public void osSetProjectionParams(LSL_Integer projection, LSL_Key texture, LSL_Float fov, LSL_Float focus, LSL_Float amb)
- {
- SetProjectionParams(m_host, projection, texture, fov, focus, amb);
- }
- /// <summary>
- /// Set parameters for light projection of a linkset prim
- /// </summary>
- public void osSetProjectionParams(LSL_Integer linknum, LSL_Integer projection, LSL_Key texture, LSL_Float fov, LSL_Float focus, LSL_Float amb)
- {
- if (linknum == ScriptBaseClass.LINK_THIS || linknum == m_host.LinkNum)
- {
- SetProjectionParams(m_host, projection, texture, fov, focus, amb);
- return;
- }
- if (linknum < 0 || linknum > m_host.ParentGroup.PrimCount)
- return;
- if(linknum < 2 && m_host.LinkNum < 2)
- {
- SetProjectionParams(m_host, projection, texture, fov, focus, amb);
- return;
- }
- SceneObjectPart obj = m_host.ParentGroup.GetLinkNumPart(linknum);
- if(obj != null)
- SetProjectionParams(obj, projection, texture, fov, focus, amb);
- }
- /// <summary>
- /// Set parameters for light projection with uuid of target prim
- /// </summary>
- public void osSetProjectionParams(LSL_Key prim, LSL_Integer llprojection, LSL_Key texture, LSL_Float fov, LSL_Float focus, LSL_Float amb)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
- SceneObjectPart obj = null;
- if (prim == ScriptBaseClass.NULL_KEY)
- {
- obj = m_host;
- }
- else
- {
- obj = World.GetSceneObjectPart(new UUID(prim));
- if (obj == null)
- return;
- }
- SetProjectionParams(obj, llprojection, texture, fov, focus, amb);
- }
- private void SetProjectionParams(SceneObjectPart obj, LSL_Integer llprojection, LSL_Key texture, LSL_Float fov, LSL_Float focus, LSL_Float amb)
- {
- bool projection = llprojection != 0;
- obj.Shape.ProjectionEntry = projection;
- obj.Shape.ProjectionTextureUUID = new UUID(texture);
- obj.Shape.ProjectionFOV = (float)fov;
- obj.Shape.ProjectionFocus = (float)focus;
- obj.Shape.ProjectionAmbiance = (float)amb;
- obj.ParentGroup.HasGroupChanged = true;
- obj.ScheduleFullUpdate();
- }
- /// <summary>
- /// Like osGetAgents but returns enough info for a radar
- /// </summary>
- /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
- public LSL_List osGetAvatarList()
- {
- CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");
- LSL_List result = new LSL_List();
- World.ForEachRootScenePresence(delegate (ScenePresence avatar)
- {
- if (avatar != null && !avatar.IsDeleted && avatar.UUID != m_host.OwnerID )
- {
- result.Add(new LSL_String(avatar.UUID.ToString()));
- result.Add(new LSL_Vector(avatar.AbsolutePosition));
- result.Add(new LSL_String(avatar.Name));
- }
- });
- return result;
- }
- public LSL_List osGetNPCList()
- {
- CheckThreatLevel(ThreatLevel.None, "osGetNPCList");
- LSL_List result = new LSL_List();
- World.ForEachRootScenePresence(delegate (ScenePresence avatar)
- {
- // npcs are not childagents but that is now.
- if (avatar != null && avatar.IsNPC && !avatar.IsDeleted && !avatar.IsChildAgent && !avatar.IsInTransit)
- {
- result.Add(new LSL_String(avatar.UUID.ToString()));
- result.Add(new LSL_Vector(avatar.AbsolutePosition));
- result.Add(new LSL_String(avatar.Name));
- }
- });
- return result;
- }
- /// <summary>
- /// Convert a unix time to a llGetTimestamp() like string
- /// </summary>
- /// <param name="unixTime"></param>
- /// <returns></returns>
- public LSL_String osUnixTimeToTimestamp(LSL_Integer time)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osUnixTimeToTimestamp");
- long baseTicks = 621355968000000000;
- long tickResolution = 10000000;
- long epochTicks = (time * tickResolution) + baseTicks;
- DateTime date = new DateTime(epochTicks);
- return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
- }
- /// <summary>
- /// Invite user to the group this object is set to
- /// </summary>
- /// <param name="agentId"></param>
- /// <returns></returns>
- public LSL_Integer osInviteToGroup(LSL_Key agentId)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup");
- // groups module is required
- if (m_groupsModule == null)
- return ScriptBaseClass.FALSE;
- UUID agent;
- if (!UUID.TryParse(agentId, out agent))
- return ScriptBaseClass.FALSE;
- // object has to be set to a group, but not group owned
- if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID)
- return ScriptBaseClass.FALSE;
- // invited agent has to be present in this scene
- ScenePresence sp = World.GetScenePresence(agent);
- if (sp == null || sp.IsNPC || sp.IsChildAgent || !sp.ControllingClient.IsActive)
- return ScriptBaseClass.FALSE;
- if (sp.ControllingClient.IsGroupMember(m_host.GroupID))
- return 2;
- // object owner needs invite power
- ulong ownerPowers = m_groupsModule.GetFullGroupPowers(m_host.OwnerID, m_host.GroupID);
- if ((ownerPowers & (ulong)GroupPowers.Invite) == 0)
- return ScriptBaseClass.FALSE;
- m_groupsModule.InviteGroup(null, m_host.OwnerID, m_host.GroupID, agent, UUID.Zero);
- return ScriptBaseClass.TRUE;
- }
- /// <summary>
- /// Eject user from the group this object is set to
- /// </summary>
- /// <param name="agentId"></param>
- /// <returns></returns>
- public LSL_Integer osEjectFromGroup(LSL_Key agentId)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osEjectFromGroup");
- // groups module is required
- if (m_groupsModule == null)
- return ScriptBaseClass.FALSE;
- UUID agent;
- if (!UUID.TryParse(agentId, out agent))
- return ScriptBaseClass.FALSE;
- // object has to be set to a group, but not group owned
- if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID)
- return ScriptBaseClass.FALSE;
- // object owner needs eject power
- ulong ownerPowers = m_groupsModule.GetFullGroupPowers(m_host.OwnerID, m_host.GroupID);
- if ((ownerPowers & (ulong)GroupPowers.Eject) == 0)
- return ScriptBaseClass.FALSE;
- m_groupsModule.EjectGroupMember(null, m_host.OwnerID, m_host.GroupID, agent);
- return ScriptBaseClass.TRUE;
- }
- /// <summary>
- /// Sets terrain estate texture
- /// </summary>
- /// <param name="level"></param>
- /// <param name="texture"></param>
- /// <returns></returns>
- public void osSetTerrainTexture(int level, LSL_Key texture)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
- //Check to make sure that the script's owner is the estate manager/master
- //World.Permissions.GenericEstatePermission(
- if (World.Permissions.IsGod(m_host.OwnerID))
- {
- if (level < 0 || level > 3)
- return;
- UUID textureID = new UUID();
- if (!UUID.TryParse(texture, out textureID))
- return;
- // estate module is required
- IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
- if (estate != null)
- estate.setEstateTerrainBaseTexture(level, textureID);
- }
- }
- /// <summary>
- /// Sets terrain heights of estate
- /// </summary>
- /// <param name="corner"></param>
- /// <param name="low"></param>
- /// <param name="high"></param>
- /// <returns></returns>
- public void osSetTerrainTextureHeight(int corner, double low, double high)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
- //Check to make sure that the script's owner is the estate manager/master
- //World.Permissions.GenericEstatePermission(
- if (World.Permissions.IsGod(m_host.OwnerID))
- {
- if (corner < 0 || corner > 3)
- return;
- // estate module is required
- IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
- if (estate != null)
- estate.setEstateTerrainTextureHeights(corner, (float)low, (float)high);
- }
- }
- #region Attachment commands
- public void osForceAttachToAvatar(int attachmentPoint)
- {
- CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
- InitLSL();
- m_LSL_Api.AttachToAvatar(attachmentPoint);
- }
- public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
- {
- CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory");
- ForceAttachToAvatarFromInventory(m_host.OwnerID, itemName, attachmentPoint);
- }
- public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osForceAttachToOtherAvatarFromInventory");
- if (!UUID.TryParse(rawAvatarId, out UUID avatarId))
- return;
- ForceAttachToAvatarFromInventory(avatarId, itemName, attachmentPoint);
- }
- public void ForceAttachToAvatarFromInventory(UUID avatarId, string itemName, int attachmentPoint)
- {
- IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
- if (attachmentsModule == null)
- return;
- InitLSL();
- TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
- if (item == null)
- {
- m_LSL_Api.llSay(0, string.Format("Could not find object '{0}'", itemName));
- throw new Exception(String.Format("The inventory item '{0}' could not be found", itemName));
- }
- if (item.InvType != (int)InventoryType.Object)
- {
- // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
- // up the api reference.
- if (m_LSL_Api != null)
- m_LSL_Api.llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
- throw new Exception(String.Format("The inventory item '{0}' is not an object", itemName));
- }
- ScenePresence sp = World.GetScenePresence(avatarId);
- if (sp == null)
- return;
- InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID, out string message);
- if (newItem == null)
- {
- m_log.ErrorFormat(
- "[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}: {4}",
- itemName, m_host.Name, attachmentPoint, World.Name, message);
- m_LSL_Api.llSay(0, message);
- return;
- }
- attachmentsModule.RezSingleAttachmentFromInventory(sp, newItem.ID, (uint)attachmentPoint);
- }
- public void osForceDetachFromAvatar()
- {
- CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
- InitLSL();
- m_LSL_Api.DetachFromAvatar();
- }
- private bool listObjToInt(object p, out int i)
- {
- try
- {
- if (p is LSL_Integer)
- i = (LSL_Integer)p;
- else if (p is int)
- i = (int)p;
- else if (p is uint)
- i = (int)(uint)p;
- else if (p is string)
- return int.TryParse((string)p, out i);
- else if (p is LSL_String)
- return int.TryParse((string)(LSL_String)p, out i);
- else
- {
- i = 0;
- return false;
- }
- return true;
- }
- catch
- {
- i = 0;
- return false;
- }
- }
- public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments");
- LSL_List resp = new LSL_List();
- if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out UUID targetUUID) && World.TryGetScenePresence(targetUUID, out ScenePresence target))
- {
- foreach (object point in attachmentPoints.Data)
- {
- listObjToInt(point, out int ipoint);
- resp.Add(new LSL_Integer(ipoint));
- if (ipoint == 0)
- {
- // indicates zero attachments
- resp.Add(new LSL_Integer(0));
- }
- else
- {
- // gets the number of attachments on the attachment point
- resp.Add(new LSL_Integer(target.GetAttachments((uint)ipoint).Count));
- }
- }
- }
- return resp;
- }
- public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments");
- if (!UUID.TryParse(avatar.ToString(), out UUID targetUUID))
- return;
- if (targetUUID == UUID.Zero)
- return;
- if (!World.TryGetScenePresence(targetUUID, out ScenePresence target))
- return;
- if (target.IsDeleted || target.IsInTransit)
- return;
- List<int> aps = new List<int>();
- if(attachmentPoints.Length != 0)
- {
- foreach (object point in attachmentPoints.Data)
- {
- if (int.TryParse(point.ToString(), out int ipoint))
- {
- aps.Add(ipoint);
- }
- }
- // parsing failed
- if(aps.Count != attachmentPoints.Length)
- return;
- }
- List<SceneObjectGroup> attachments = new List<SceneObjectGroup>();
- bool msgAll;
- bool invertPoints = (options & ScriptBaseClass.OS_ATTACH_MSG_INVERT_POINTS) != 0;
- if(aps.Count == 0)
- {
- if(!invertPoints)
- return;
- msgAll = true;
- invertPoints = false;
- }
- else
- msgAll = aps.Contains(ScriptBaseClass.OS_ATTACH_MSG_ALL);
- if (msgAll && invertPoints)
- return;
- if (msgAll || invertPoints)
- {
- attachments = target.GetAttachments();
- }
- else
- {
- foreach (int point in aps)
- {
- if (point > 0)
- {
- attachments.AddRange(target.GetAttachments((uint)point));
- }
- }
- }
- // if we have no attachments at this point, exit now
- if (attachments.Count == 0)
- {
- return;
- }
- bool optionObjCreator = (options &
- ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0;
- bool optionScriptCreator = (options &
- ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0;
- UUID hostCreatorID = m_host.CreatorID;
- UUID itemCreatorID = m_item.CreatorID;
- foreach (SceneObjectGroup sog in attachments)
- {
- if(sog.IsDeleted || sog.inTransit)
- continue;
- if (invertPoints && aps.Contains((int)sog.AttachmentPoint))
- continue;
- UUID CreatorID = sog.RootPart.CreatorID;
- if (optionObjCreator && CreatorID != hostCreatorID)
- continue;
- if (optionScriptCreator && CreatorID != itemCreatorID)
- continue;
- SceneObjectPart[] parts = sog.Parts;
- foreach(SceneObjectPart p in parts)
- MessageObject(p.UUID, message);
- }
- }
- #endregion
- /// <summary>
- /// Checks if thing is a UUID.
- /// </summary>
- /// <param name="thing"></param>
- /// <returns>1 if thing is a valid UUID, 0 otherwise</returns>
- public LSL_Integer osIsUUID(string thing)
- {
- CheckThreatLevel();
- return UUID.TryParse(thing, out UUID test) ? 1 : 0;
- }
- /// <summary>
- /// Wraps to Math.Min()
- /// </summary>
- /// <param name="a"></param>
- /// <param name="b"></param>
- /// <returns></returns>
- public LSL_Float osMin(double a, double b)
- {
- CheckThreatLevel();
- return Math.Min(a, b);
- }
- /// <summary>
- /// Wraps to Math.max()
- /// </summary>
- /// <param name="a"></param>
- /// <param name="b"></param>
- /// <returns></returns>
- public LSL_Float osMax(double a, double b)
- {
- CheckThreatLevel();
- return Math.Max(a, b);
- }
- public LSL_Key osGetRezzingObject()
- {
- CheckThreatLevel(ThreatLevel.None, "osGetRezzingObject");
- UUID rezID = m_host.ParentGroup.RezzerID;
- if(rezID == UUID.Zero || m_host.ParentGroup.Scene.GetScenePresence(rezID) != null)
- return new LSL_Key(ScriptBaseClass.NULL_KEY);
- return new LSL_Key(rezID.ToString());
- }
- /// <summary>
- /// Sets the response type for an HTTP request/response
- /// </summary>
- /// <returns></returns>
- public void osSetContentType(LSL_Key id, string type)
- {
- CheckThreatLevel(ThreatLevel.Severe, "osSetContentType");
- if (m_UrlModule != null)
- m_UrlModule.HttpContentType(new UUID(id),type);
- }
- /// Shout an error if the object owner did not grant the script the specified permissions.
- /// </summary>
- /// <param name="perms"></param>
- /// <returns>boolean indicating whether an error was shouted.</returns>
- protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix)
- {
- bool fail = false;
- if (m_item.PermsGranter != m_host.OwnerID)
- {
- fail = true;
- OSSLShoutError(string.Format("{0}. Permissions not granted to owner.", errorPrefix));
- }
- else if ((m_item.PermsMask & perms) == 0)
- {
- fail = true;
- OSSLShoutError(string.Format("{0}. Permissions not granted.", errorPrefix));
- }
- return fail;
- }
- protected void DropAttachment(bool checkPerms)
- {
- if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
- {
- return;
- }
- IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
- ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
- if (attachmentsModule != null && sp != null)
- {
- attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId);
- }
- }
- protected void DropAttachmentAt(bool checkPerms, LSL_Vector pos, LSL_Rotation rot)
- {
- if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
- {
- return;
- }
- IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
- ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
- if (attachmentsModule != null && sp != null)
- {
- attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId, pos, rot);
- }
- }
- public void osDropAttachment()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment");
- DropAttachment(true);
- }
- public void osForceDropAttachment()
- {
- CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment");
- DropAttachment(false);
- }
- public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt");
- DropAttachmentAt(true, pos, rot);
- }
- public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
- {
- CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt");
- DropAttachmentAt(false, pos, rot);
- }
- public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
- {
- CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
- UUID.TryParse(ID, out UUID keyID);
- // if we want the name to be used as a regular expression, ensure it is valid first.
- if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
- {
- try
- {
- Regex.IsMatch("", name);
- }
- catch (Exception)
- {
- OSSLShoutError("Name regex is invalid.");
- return -1;
- }
- }
- // if we want the msg to be used as a regular expression, ensure it is valid first.
- if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE)
- {
- try
- {
- Regex.IsMatch("", msg);
- }
- catch (Exception)
- {
- OSSLShoutError("Message regex is invalid.");
- return -1;
- }
- }
- IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
- return (wComm == null) ? -1 : wComm.Listen(
- m_host.LocalId,
- m_item.ItemID,
- m_host.UUID,
- channelID,
- name,
- keyID,
- msg,
- regexBitfield
- );
- }
- public LSL_Integer osRegexIsMatch(string input, string pattern)
- {
- CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
- try
- {
- return Regex.IsMatch(input, pattern) ? 1 : 0;
- }
- catch (Exception)
- {
- OSSLShoutError("Possible invalid regular expression detected.");
- return 0;
- }
- }
- public LSL_String osRequestURL(LSL_List options)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osRequestSecureURL");
- Hashtable opts = new Hashtable();
- for (int i = 0 ; i < options.Length ; i++)
- {
- object opt = options.Data[i];
- if (opt.ToString() == "allowXss")
- opts["allowXss"] = true;
- }
- if (m_UrlModule != null)
- return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString();
- return ScriptBaseClass.NULL_KEY;
- }
- public LSL_String osRequestSecureURL(LSL_List options)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osRequestSecureURL");
- Hashtable opts = new Hashtable();
- for (int i = 0 ; i < options.Length ; i++)
- {
- object opt = options.Data[i];
- if (opt.ToString() == "allowXss")
- opts["allowXss"] = true;
- }
- if (m_UrlModule != null)
- return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString();
- return ScriptBaseClass.NULL_KEY;
- }
- public void osCollisionSound(string impact_sound, double impact_volume)
- {
- CheckThreatLevel();
- if(impact_sound == "")
- {
- m_host.CollisionSoundVolume = (float)impact_volume;
- m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
- if(impact_volume == 0.0)
- m_host.CollisionSoundType = -1; // disable all sounds
- else if(impact_volume == 1.0f)
- m_host.CollisionSoundType = 0; // full return to default sounds
- else
- m_host.CollisionSoundType = 2; // default sounds with volume
- m_host.aggregateScriptEvents();
- return;
- }
- // TODO: Parameter check logic required.
- UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
- if(soundId != UUID.Zero)
- {
- m_host.CollisionSound = soundId;
- m_host.CollisionSoundVolume = (float)impact_volume;
- m_host.CollisionSoundType = 1;
- }
- else
- m_host.CollisionSoundType = -1;
- m_host.aggregateScriptEvents();
- }
- // still not very usefull, detector is lost on rez, restarts, etc
- public void osVolumeDetect(int detect)
- {
- CheckThreatLevel();
- if (m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted || m_host.ParentGroup.IsAttachment)
- return;
- m_host.ScriptSetVolumeDetect(detect != 0);
- }
- /// <summary>
- /// Get inertial data
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <returns>
- /// a LSL list with contents:
- /// LSL_Float mass, the total mass of a linkset
- /// LSL_Vector CenterOfMass, center mass relative to root prim
- /// LSL_Vector Inertia, elements of diagonal of inertia Ixx,Iyy,Izz divided by total mass
- /// LSL_Vector aux, elements of upper triagle of inertia Ixy (= Iyx), Ixz (= Izx), Iyz(= Izy) divided by total mass
- /// </returns>
- public LSL_List osGetInertiaData()
- {
- CheckThreatLevel();
- LSL_List result = new LSL_List();
- SceneObjectGroup sog = m_host.ParentGroup;
- if (sog== null || sog.IsDeleted)
- return result;
- sog.GetInertiaData(out float TotalMass, out Vector3 CenterOfMass, out Vector3 Inertia, out Vector4 aux );
- if(TotalMass > 0)
- {
- float t = 1.0f/TotalMass;
- Inertia.X *= t;
- Inertia.Y *= t;
- Inertia.Z *= t;
- aux.X *= t;
- aux.Y *= t;
- aux.Z *= t;
- }
- result.Add(new LSL_Float(TotalMass));
- result.Add(new LSL_Vector(CenterOfMass.X, CenterOfMass.Y, CenterOfMass.Z));
- result.Add(new LSL_Vector(Inertia.X, Inertia.Y, Inertia.Z));
- result.Add(new LSL_Vector(aux.X, aux.Y, aux.Z));
- return result;
- }
- /// <summary>
- /// set inertial data
- /// replaces the automatic calculation of mass, center of mass and inertia
- ///
- /// </summary>
- /// <param name="Mass">total mass of linkset</param>
- /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
- /// <param name="principalInertiaScaled">moment of inertia relative to principal axis and center of mass,Ixx, Iyy, Izz divided by mass</param>
- /// <param name="lslrot">rotation of the inertia, relative to local axis</param>
- /// <remarks>
- /// the inertia argument is is inertia divided by mass, so corresponds only to the geometric distribution of mass and both can be changed independently.
- /// </remarks>
- public void osSetInertia(LSL_Float mass, LSL_Vector centerOfMass, LSL_Vector principalInertiaScaled, LSL_Rotation lslrot)
- {
- CheckThreatLevel();
- SceneObjectGroup sog = m_host.ParentGroup;
- if(sog== null || sog.IsDeleted)
- return;
- if(mass < 0 || principalInertiaScaled.x < 0 || principalInertiaScaled.y < 0 || principalInertiaScaled.z < 0)
- return;
- // need more checks
- Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
- Vector3 Inertia;
- float m = (float)mass;
- Inertia.X = m * (float)principalInertiaScaled.x;
- Inertia.Y = m * (float)principalInertiaScaled.y;
- Inertia.Z = m * (float)principalInertiaScaled.z;
- Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.y, (float)lslrot.s);
- rot.Normalize();
- sog.SetInertiaData(m, CenterOfMass, Inertia, rot );
- }
- /// <summary>
- /// set inertial data as a sphere
- /// replaces the automatic calculation of mass, center of mass and inertia
- ///
- /// </summary>
- /// <param name="Mass">total mass of linkset</param>
- /// <param name="boxsize">size of the Box</param>
- /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
- /// <param name="lslrot">rotation of the box, and so inertia, relative to local axis</param>
- /// <remarks>
- /// </remarks>
- public void osSetInertiaAsBox(LSL_Float mass, LSL_Vector boxSize, LSL_Vector centerOfMass, LSL_Rotation lslrot)
- {
- CheckThreatLevel();
- SceneObjectGroup sog = m_host.ParentGroup;
- if(sog== null || sog.IsDeleted)
- return;
- if(mass < 0)
- return;
- // need more checks
- Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
- Vector3 Inertia;
- float lx = (float)boxSize.x;
- float ly = (float)boxSize.y;
- float lz = (float)boxSize.z;
- float m = (float)mass;
- float t = m / 12.0f;
- Inertia.X = t * (ly*ly + lz*lz);
- Inertia.Y = t * (lx*lx + lz*lz);
- Inertia.Z = t * (lx*lx + ly*ly);
- Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.z, (float)lslrot.s);
- rot.Normalize();
- sog.SetInertiaData(m, CenterOfMass, Inertia, rot );
- }
- /// <summary>
- /// set inertial data as a sphere
- /// replaces the automatic calculation of mass, center of mass and inertia
- ///
- /// </summary>
- /// <param name="Mass">total mass of linkset</param>
- /// <param name="radius">radius of the sphere</param>
- /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
- /// <remarks>
- /// </remarks>
- public void osSetInertiaAsSphere(LSL_Float mass, LSL_Float radius, LSL_Vector centerOfMass)
- {
- CheckThreatLevel();
- SceneObjectGroup sog = m_host.ParentGroup;
- if(sog== null || sog.IsDeleted)
- return;
- if(mass < 0)
- return;
- // need more checks
- Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
- Vector3 Inertia;
- float r = (float)radius;
- float m = (float)mass;
- float t = 0.4f * m * r * r;
- Inertia.X = t;
- Inertia.Y = t;
- Inertia.Z = t;
- sog.SetInertiaData(m, CenterOfMass, Inertia, new Vector4(0f, 0f, 0f,1.0f));
- }
- /// <summary>
- /// set inertial data as a cylinder
- /// replaces the automatic calculation of mass, center of mass and inertia
- ///
- /// </summary>
- /// <param name="Mass">total mass of linkset</param>
- /// <param name="radius">radius of the cylinder</param>
- /// <param name="lenght">lenght of the cylinder</param>
- /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
- /// <param name="lslrot">rotation of the cylinder, and so inertia, relative to local axis</param>
- /// <remarks>
- /// cylinder axis aligned with Z axis. For other orientations provide the rotation.
- /// </remarks>
- public void osSetInertiaAsCylinder(LSL_Float mass, LSL_Float radius, LSL_Float lenght, LSL_Vector centerOfMass, LSL_Rotation lslrot)
- {
- CheckThreatLevel();
- SceneObjectGroup sog = m_host.ParentGroup;
- if(sog== null || sog.IsDeleted)
- return;
- if(mass < 0)
- return;
- // need more checks
- Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
- Vector3 Inertia;
- float m = (float)mass;
- float r = (float)radius;
- r *= r;
- Inertia.Z = 0.5f * m * r;
- float t = (float)lenght;
- t *= t;
- t += 3.0f * r;
- t *= 8.333333e-2f * m;
- Inertia.X = t;
- Inertia.Y = t;
- Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.z, (float)lslrot.s);
- rot.Normalize();
- sog.SetInertiaData(m, CenterOfMass, Inertia, rot);
- }
- /// <summary>
- /// removes inertial data manual override
- /// default automatic calculation is used again
- ///
- /// </summary>
- public void osClearInertia()
- {
- CheckThreatLevel();
- SceneObjectGroup sog = m_host.ParentGroup;
- if(sog== null || sog.IsDeleted)
- return;
- sog.SetInertiaData(-1, Vector3.Zero, Vector3.Zero, Vector4.Zero );
- }
- private bool checkAllowObjectTPbyLandOwner(Vector3 pos)
- {
- ILandObject land = World.LandChannel.GetLandObject(pos);
- if(land == null)
- return true;
- LandData landdata = land.LandData;
- if(landdata == null)
- return true;
- UUID hostOwner = m_host.OwnerID;
- if(landdata.OwnerID == hostOwner)
- return true;
- EstateSettings es = World.RegionInfo.EstateSettings;
- if(es != null && es.IsEstateManagerOrOwner(hostOwner))
- return true;
- if(!landdata.IsGroupOwned)
- return false;
- UUID landGroup = landdata.GroupID;
- if(landGroup == UUID.Zero)
- return false;
- if(landGroup == m_host.GroupID)
- return true;
- return false;
- }
- /// <summary>
- /// teleports a object (full linkset)
- /// </summary>
- /// <param name="objectUUID">the id of the linkset to teleport</param>
- /// <param name="targetPos">target position</param>
- /// <param name="rotation"> a rotation to apply</param>
- /// <param name="flags">several flags/param>
- /// <remarks>
- /// only does teleport local to region
- /// if object has scripts, owner must have rights to run scripts on target location
- /// object owner must have rights to enter ojects on target location
- /// target location parcel must have enought free prims capacity for the linkset prims
- /// all avatars siting on the object must have access to target location
- /// has a cool down time. retries before expire reset it
- /// fail conditions are silent ignored
- /// </remarks>
- public LSL_Integer osTeleportObject(LSL_Key objectUUID, LSL_Vector targetPos, LSL_Rotation rotation, LSL_Integer flags)
- {
- CheckThreatLevel(ThreatLevel.Severe, "osTeleportObject");
- if (!UUID.TryParse(objectUUID, out UUID objUUID))
- {
- OSSLShoutError("osTeleportObject() invalid object Key");
- return -1;
- }
- SceneObjectGroup sog = World.GetSceneObjectGroup(objUUID);
- if(sog== null || sog.IsDeleted || sog.inTransit)
- return -1;
- if(sog.OwnerID != m_host.OwnerID)
- {
- Vector3 pos = sog.AbsolutePosition;
- if(!checkAllowObjectTPbyLandOwner(pos))
- return -1;
- }
- UUID myid = m_host.ParentGroup.UUID;
- return sog.TeleportObject(myid, targetPos, rotation, flags);
- // a delay here may break vehicles
- }
- public LSL_Integer osGetLinkNumber(LSL_String name)
- {
- CheckThreatLevel();
- SceneObjectGroup sog = m_host.ParentGroup;
- if(sog== null || sog.IsDeleted)
- return -1;
- return sog.GetLinkNumber(name);
- }
- // rounds to the nearest number with provided number of decimal places
- public LSL_Float osRound(LSL_Float value, LSL_Integer ndigits)
- {
- if(ndigits <= 0)
- return Math.Round(value, MidpointRounding.AwayFromZero);
- if(ndigits > 15)
- ndigits = 15;
- return Math.Round(value, ndigits, MidpointRounding.AwayFromZero);
- }
- public LSL_Float osVecMagSquare(LSL_Vector a)
- {
- return LSL_Vector.MagSquare(a);
- }
- public LSL_Float osVecDistSquare(LSL_Vector a, LSL_Vector b)
- {
- return LSL_Vector.MagSquare(a - b);
- }
- // returns the angle between 2 vectors 0 to pi
- public LSL_Float osAngleBetween(LSL_Vector a, LSL_Vector b)
- {
- double dot = LSL_Vector.Dot(a,b);
- double mcross = LSL_Vector.Mag(LSL_Vector.Cross(a,b));
- return Math.Atan2(mcross, dot);
- }
- public void osAdjustSoundVolume(LSL_Integer linknum, LSL_Float volume)
- {
- m_host.AddScriptLPS(1);
- SceneObjectPart sop = GetSingleLinkPart(linknum);
- if(sop == null)
- return;
- sop.AdjustSoundGain(volume);
- }
- public void osSetSoundRadius(LSL_Integer linknum, LSL_Float radius)
- {
- m_host.AddScriptLPS(1);
- SceneObjectPart sop = GetSingleLinkPart(linknum);
- if(sop == null)
- return;
- sop.SoundRadius = radius;
- }
- public void osPlaySound(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
- {
- m_host.AddScriptLPS(1);
- if (m_SoundModule == null)
- return;
- SceneObjectPart sop = GetSingleLinkPart(linknum);
- if(sop == null)
- return;
- UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
- if (soundID == UUID.Zero)
- return;
- // send the sound, once, to all clients in range
- m_SoundModule.SendSound(sop.UUID, soundID, volume, false, 0, false, false);
- }
- public void osLoopSound(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
- {
- m_host.AddScriptLPS(1);
- if (m_SoundModule == null)
- return;
- SceneObjectPart sop = GetSingleLinkPart(linknum);
- if(sop == null)
- return;
- UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
- if (soundID == UUID.Zero)
- return;
- m_SoundModule.LoopSound(sop.UUID, soundID, volume, false,false);
- }
- public void osLoopSoundMaster(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
- {
- m_host.AddScriptLPS(1);
- if (m_SoundModule == null)
- return;
- SceneObjectPart sop = GetSingleLinkPart(linknum);
- if(sop == null)
- return;
- UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
- if (soundID == UUID.Zero)
- return;
- m_SoundModule.LoopSound(sop.UUID, soundID, volume, true, false);
- }
- public void osLoopSoundSlave(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
- {
- m_host.AddScriptLPS(1);
- if (m_SoundModule == null)
- return;
- SceneObjectPart sop = GetSingleLinkPart(linknum);
- if(sop == null)
- return;
- UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
- if (soundID == UUID.Zero)
- return;
- m_SoundModule.LoopSound(sop.UUID, soundID, volume, false, true);
- }
- public void osPlaySoundSlave(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
- {
- m_host.AddScriptLPS(1);
- if (m_SoundModule == null)
- return;
- SceneObjectPart sop = GetSingleLinkPart(linknum);
- if(sop == null)
- return;
- UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
- if (soundID == UUID.Zero)
- return;
- // send the sound, once, to all clients in range
- m_SoundModule.SendSound(sop.UUID, soundID, volume, false, 0, true, false);
- }
- public void osTriggerSound(LSL_Integer linknum, LSL_String sound, LSL_Float volume)
- {
- m_host.AddScriptLPS(1);
- if (m_SoundModule == null)
- return;
- SceneObjectPart sop = GetSingleLinkPart(linknum);
- if(sop == null)
- return;
- UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
- if (soundID == UUID.Zero)
- return;
- // send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory.
- m_SoundModule.SendSound(sop.UUID, soundID, volume, true, 0, false, false);
- }
- public void osTriggerSoundLimited(LSL_Integer linknum, LSL_String sound, LSL_Float volume,
- LSL_Vector top_north_east, LSL_Vector bottom_south_west)
- {
- m_host.AddScriptLPS(1);
- if (m_SoundModule == null)
- return;
- SceneObjectPart sop = GetSingleLinkPart(linknum);
- if(sop == null)
- return;
- UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
- if (soundID == UUID.Zero)
- return;
- m_SoundModule.TriggerSoundLimited(sop.UUID, soundID, volume,
- bottom_south_west, top_north_east);
- }
- public void osStopSound(LSL_Integer linknum)
- {
- m_host.AddScriptLPS(1);
- if (m_SoundModule == null)
- return;
- InitLSL();
- if(m_LSL_Api == null)
- return;
- List<SceneObjectPart> sops = m_LSL_Api.GetLinkParts(linknum);
- if(sops == null || sops.Count == 0)
- return;
- for(int i = 0; i < sops.Count; ++i)
- m_SoundModule.StopSound(sops[i].UUID);
- }
- public void osPreloadSound(LSL_Integer linknum, LSL_String sound)
- {
- m_host.AddScriptLPS(1);
- if (m_SoundModule == null)
- return;
- SceneObjectPart sop = GetSingleLinkPart(linknum);
- if(sop == null)
- return;
- UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(sop, m_host, sound, AssetType.Sound);
- if (soundID == UUID.Zero)
- return;
- m_SoundModule.PreloadSound(sop.UUID, soundID);
- ScriptSleep(1000);
- }
- // get only one part
- private SceneObjectPart GetSingleLinkPart(int linkType)
- {
- if (m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
- return null;
- switch (linkType)
- {
- case ScriptBaseClass.LINK_SET:
- case ScriptBaseClass.LINK_ALL_OTHERS:
- case ScriptBaseClass.LINK_ALL_CHILDREN:
- return null;
- case 0:
- case ScriptBaseClass.LINK_ROOT:
- return m_host.ParentGroup.RootPart;
- case ScriptBaseClass.LINK_THIS:
- return m_host;
- default:
- if(linkType < 0)
- return null;
- return m_host.ParentGroup.GetLinkNumPart(linkType);
- }
- }
- // funtions to retrieve user country
- // adaptation cm* counter parts from Avination Careminster extensions API
- // included in Avination code contribution
- // for now users country can only be set directly on DB
- public LSL_String osDetectedCountry(LSL_Integer number)
- {
- m_host.AddScriptLPS(1);
- CheckThreatLevel(ThreatLevel.Moderate, "osDetectedCountry");
- if (World.UserAccountService == null)
- return String.Empty;
- DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
- if (detectedParams == null)
- return String.Empty;
- UUID key = detectedParams.Key;
- if (key == UUID.Zero)
- return String.Empty;
- UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
- return account.UserCountry;
- }
- public LSL_String osGetAgentCountry(LSL_Key id)
- {
- m_host.AddScriptLPS(1);
- CheckThreatLevel(ThreatLevel.Moderate, "osGetAgentCountry");
- if (World.UserAccountService == null)
- return String.Empty;
- if (!UUID.TryParse(id, out UUID key))
- return String.Empty;
- if (key == UUID.Zero)
- return String.Empty;
- //if owner is not god, target must be in region, or nearby regions
- if (!World.Permissions.IsGod(m_host.OwnerID))
- {
- ScenePresence sp = World.GetScenePresence(key);
- if(sp == null)
- return String.Empty;
- }
- UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
- return account.UserCountry;
- }
- public LSL_String osStringSubString(LSL_String src, LSL_Integer offset)
- {
- m_host.AddScriptLPS(1);
- CheckThreatLevel();
- if (string.IsNullOrEmpty(src))
- return "";
- if (offset >= src.Length)
- return "";
- if (offset <= 0)
- return src;
- return ((string)src).Substring(offset);
- }
- public LSL_String osStringSubString(LSL_String src, LSL_Integer offset, LSL_Integer length)
- {
- m_host.AddScriptLPS(1);
- CheckThreatLevel();
- if (string.IsNullOrEmpty(src))
- return "";
- if (length <= 0 || offset >= src.Length)
- return "";
- if (offset <= 0)
- {
- if(length == src.Length)
- return src;
- offset = 0;
- }
- if (length > src.Length - offset)
- length = src.Length - offset;
- return ((string)src).Substring(offset, length);
- }
- public LSL_Integer osStringStartsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase)
- {
- m_host.AddScriptLPS(1);
- CheckThreatLevel();
- if (string.IsNullOrEmpty(src))
- return 0;
- if (string.IsNullOrEmpty(value))
- return 0;
- bool ign = (ignorecase != 0);
- return ((string)src).StartsWith(value, ignorecase, Culture.GetDefaultCurrentCulture()) ? 1 : 0;
- }
- public LSL_Integer osStringEndsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase)
- {
- m_host.AddScriptLPS(1);
- CheckThreatLevel();
- if (string.IsNullOrEmpty(src))
- return 0;
- if (string.IsNullOrEmpty(value))
- return 0;
- bool ign = (ignorecase != 0);
- return ((string)src).EndsWith(value, ign, Culture.GetDefaultCurrentCulture()) ? 1 : 0;
- }
- public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase)
- {
- m_host.AddScriptLPS(1);
- CheckThreatLevel();
- if (string.IsNullOrEmpty(src))
- return -1;
- if (string.IsNullOrEmpty(value))
- return -1;
- if (ignorecase == 0)
- return ((string)src).IndexOf(value, StringComparison.CurrentCulture);
- return ((string)src).IndexOf(value, StringComparison.CurrentCultureIgnoreCase);
- }
- public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value,
- LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase)
- {
- m_host.AddScriptLPS(1);
- CheckThreatLevel();
- if (string.IsNullOrEmpty(src))
- return -1;
- if (string.IsNullOrEmpty(value))
- return -1;
- if (offset >= src.Length)
- return -1;
- else if (offset < 0)
- offset = 0;
- if (count <= 0)
- count = src.Length - offset;
- else if (count > src.Length - offset)
- count = src.Length - offset;
- if (ignorecase == 0)
- return ((string)src).IndexOf(value, offset, count, StringComparison.CurrentCulture);
- return ((string)src).IndexOf(value, offset, count, StringComparison.CurrentCultureIgnoreCase);
- }
- public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase)
- {
- m_host.AddScriptLPS(1);
- CheckThreatLevel();
- if (string.IsNullOrEmpty(src))
- return -1;
- if (string.IsNullOrEmpty(value))
- return -1;
- if (ignorecase == 0)
- return ((string)src).LastIndexOf(value, StringComparison.CurrentCulture);
- return ((string)src).LastIndexOf(value, StringComparison.CurrentCultureIgnoreCase);
- }
- public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value,
- LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase)
- {
- m_host.AddScriptLPS(1);
- CheckThreatLevel();
- if (string.IsNullOrEmpty(src))
- return -1;
- if (string.IsNullOrEmpty(value))
- return -1;
- if (offset >= src.Length)
- return -1;
- if (offset < 0)
- offset = 0;
- if (count <= 0)
- count = src.Length - offset;
- else if (count > src.Length - offset)
- count = src.Length - offset;
- if (ignorecase == 0)
- return ((string)src).LastIndexOf(value, offset, count, StringComparison.CurrentCulture);
- return ((string)src).LastIndexOf(value, offset, count, StringComparison.CurrentCultureIgnoreCase);
- }
- public LSL_String osStringRemove(LSL_String src, LSL_Integer offset, LSL_Integer count)
- {
- if (string.IsNullOrEmpty(src))
- return "";
- if (offset >= src.Length)
- return "";
- if (offset < 0)
- offset = 0;
- if (count <= 0)
- count = src.Length - offset;
- else if (count > src.Length - offset)
- count = src.Length - offset;
- if (count >= src.Length)
- return "";
- return ((string)src).Remove(offset, count);
- }
- public LSL_String osStringReplace(LSL_String src, LSL_String oldvalue, LSL_String newvalue)
- {
- if (string.IsNullOrEmpty(src))
- return "";
- if (string.IsNullOrEmpty(oldvalue))
- return "";
- if (string.IsNullOrEmpty(newvalue))
- newvalue = null;
- return ((string)src).Replace(oldvalue, newvalue);
- }
- public LSL_Integer osApproxEquals(LSL_Float a, LSL_Float b)
- {
- if (a > b + 1.0e-6 || a < b - 1.0e-6)
- return 0;
- return 1;
- }
- public LSL_Integer osApproxEquals(LSL_Float a, LSL_Float b, LSL_Float margin)
- {
- double e = Math.Abs(margin);
- if (a > b + e || a < b - e)
- return 0;
- return 1;
- }
- public LSL_Integer osApproxEquals(LSL_Vector va, LSL_Vector vb)
- {
- double a = va.x;
- double b = vb.x;
- if (a > b + 1.0e-6 || a < b - 1.0e-6)
- return 0;
- a = va.y;
- b = vb.y;
- if (a > b + 1.0e-6 || a < b - 1.0e-6)
- return 0;
- a = va.z;
- b = vb.z;
- if (a > b + 1.0e-6 || a < b - 1.0e-6)
- return 0;
- return 1;
- }
- public LSL_Integer osApproxEquals(LSL_Vector va, LSL_Vector vb, LSL_Float margin)
- {
- double e = Math.Abs(margin);
- double a = va.x;
- double b = vb.x;
- if (a > b + e || a < b - e)
- return 0;
- a = va.y;
- b = vb.y;
- if (a > b + e || a < b - e)
- return 0;
- a = va.z;
- b = vb.z;
- if (a > b + e || a < b - e)
- return 0;
- return 1;
- }
- public LSL_Integer osApproxEquals(LSL_Rotation ra, LSL_Rotation rb)
- {
- double a = ra.x;
- double b = rb.x;
- if (a > b + 1.0e-6 || a < b - 1.0e-6)
- return 0;
- a = ra.y;
- b = rb.y;
- if (a > b + 1.0e-6 || a < b - 1.0e-6)
- return 0;
- a = ra.z;
- b = rb.z;
- if (a > b + 1.0e-6 || a < b - 1.0e-6)
- return 0;
- a = ra.s;
- b = rb.s;
- if (a > b + 1.0e-6 || a < b - 1.0e-6)
- return 0;
- return 1;
- }
- public LSL_Integer osApproxEquals(LSL_Rotation ra, LSL_Rotation rb, LSL_Float margin)
- {
- double e = Math.Abs(margin);
- double a = ra.x;
- double b = rb.x;
- if (a > b + e || a < b - e)
- return 0;
- a = ra.y;
- b = rb.y;
- if (a > b + e || a < b - e)
- return 0;
- a = ra.z;
- b = rb.z;
- if (a > b + e || a < b - e)
- return 0;
- a = ra.s;
- b = rb.s;
- if (a > b + e || a < b - e)
- return 0;
- return 1;
- }
- public LSL_Key osGetInventoryLastOwner(LSL_String itemNameorid)
- {
- m_host.AddScriptLPS(1);
- TaskInventoryItem item = null;
- if (UUID.TryParse(itemNameorid, out UUID itemID))
- item = m_host.Inventory.GetInventoryItem(itemID);
- else
- item = m_host.Inventory.GetInventoryItem(itemNameorid);
- if (item == null)
- return ScriptBaseClass.NULL_KEY;
- UUID id = item.LastOwnerID;
- if(id == UUID.Zero)
- id= item.OwnerID;
- return id.ToString();
- }
- public LSL_Key osGetInventoryItemKey(LSL_String name)
- {
- m_host.AddScriptLPS(1);
- TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
- if (item == null)
- return ScriptBaseClass.NULL_KEY;
- if ((item.CurrentPermissions
- & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
- == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
- {
- return item.ItemID.ToString();
- }
- return ScriptBaseClass.NULL_KEY;
- }
- public LSL_String osGetInventoryName(LSL_Key itemId)
- {
- m_host.AddScriptLPS(1);
- TaskInventoryItem item = null;
- if (UUID.TryParse(itemId, out UUID itemID))
- item = m_host.Inventory.GetInventoryItem(itemID);
- if (item == null)
- return String.Empty;
- return item.Name;
- }
- public LSL_String osGetInventoryDesc(LSL_String itemNameorid)
- {
- m_host.AddScriptLPS(1);
- TaskInventoryItem item = null;
- if (UUID.TryParse(itemNameorid, out UUID itemID))
- item = m_host.Inventory.GetInventoryItem(itemID);
- else
- item = m_host.Inventory.GetInventoryItem(itemNameorid);
- if (item == null)
- return String.Empty;
- return item.Description;
- }
- public LSL_Key osGetLastChangedEventKey()
- {
- m_host.AddScriptLPS(1);
- DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
- if (detectedParams == null)
- return String.Empty;
- return detectedParams.Key.ToString();
- }
- // returns PST or PDT wall clock
- public LSL_Float osGetPSTWallclock()
- {
- m_host.AddScriptLPS(1);
- if(PSTTimeZone == null)
- return DateTime.Now.TimeOfDay.TotalSeconds;
- DateTime time = TimeZoneInfo.ConvertTime(DateTime.UtcNow, PSTTimeZone);
- return time.TimeOfDay.TotalSeconds;
- }
- public LSL_Rotation osSlerp(LSL_Rotation a, LSL_Rotation b, LSL_Float amount)
- {
- if(amount < 0)
- amount= 0;
- else if(amount > 1.0)
- amount = 1.0;
- a.Normalize();
- b.Normalize();
- return LSL_Rotation.Slerp(a, b, amount);
- }
- public LSL_Vector osSlerp(LSL_Vector a, LSL_Vector b, LSL_Float amount)
- {
- if (amount < 0)
- amount = 0;
- else if (amount > 1.0)
- amount = 1.0;
- return LSL_Vector.Slerp(a, b, amount);
- }
- public void osResetAllScripts(LSL_Integer linkset)
- {
- UUID me = m_item.ItemID;
- List<TaskInventoryItem> scripts = new List<TaskInventoryItem>();
- if(linkset != 0)
- {
- SceneObjectGroup sog = m_host.ParentGroup;
- if(sog.inTransit || sog.IsDeleted)
- return;
- SceneObjectPart[] parts = sog.Parts;
- for (int i = 0; i < parts.Length; i++)
- {
- scripts.AddRange(parts[i].Inventory.GetInventoryItems(InventoryType.LSL));
- }
- }
- else
- scripts.AddRange(m_host.Inventory.GetInventoryItems(InventoryType.LSL));
- foreach(TaskInventoryItem script in scripts)
- {
- if(script.ItemID == me)
- continue;
- m_ScriptEngine.ResetScript(script.ItemID);
- }
- if (m_UrlModule != null)
- m_UrlModule.ScriptRemoved(me);
- m_ScriptEngine.ApiResetScript(me);
- }
- public LSL_Integer osIsNotValidNumber(LSL_Float v)
- {
- double d = v;
- if (double.IsNaN(d))
- return 1;
- if (double.IsNegativeInfinity(d))
- return 2;
- if (double.IsPositiveInfinity(d))
- return 3;
- return 0;
- }
- public void osSetSitActiveRange(LSL_Float v)
- {
- if (v > 128f)
- v = 128f;
- float old = m_host.SitActiveRange;
- m_host.SitActiveRange = (float)v;
- if(old != (float)v)
- m_host.ParentGroup.HasGroupChanged = true;
- }
- public void osSetLinkSitActiveRange(LSL_Integer linkNumber, LSL_Float v)
- {
- if (v > 128f)
- v = 128f;
- bool changed = false;
- InitLSL();
- List<SceneObjectPart> parts = m_LSL_Api.GetLinkParts(linkNumber);
- for(int i = 0; i < parts.Count; ++i)
- {
- SceneObjectPart sop = parts[i];
- float old = sop.SitActiveRange;
- sop.SitActiveRange = (float)v;
- if (old != (float)v)
- changed = true;
- }
- if (changed)
- m_host.ParentGroup.HasGroupChanged = true;
- }
- public LSL_Float osGetSitActiveRange()
- {
- return m_host.SitActiveRange;
- }
- public LSL_Float osGetLinkSitActiveRange(LSL_Integer linkNumber)
- {
- if (linkNumber == ScriptBaseClass.LINK_THIS)
- return m_host.SitActiveRange;
- if (linkNumber < 0)
- return int.MinValue;
- if (linkNumber < 2)
- return m_host.ParentGroup.RootPart.SitActiveRange;
- SceneObjectPart target = m_host.ParentGroup.GetLinkNumPart(linkNumber);
- if (target == null)
- return int.MinValue;
- return target.SitActiveRange;
- }
- public void osSetStandTarget(LSL_Vector v)
- {
- // todo add limits ?
- Vector3 old = m_host.StandOffset;
- m_host.StandOffset = v;
- if(!old.ApproxEquals(v))
- m_host.ParentGroup.HasGroupChanged = true;
- }
- public void osSetLinkStandTarget(LSL_Integer linkNumber, LSL_Vector v)
- {
- // todo add limits ?
- SceneObjectPart target = null;
- if (linkNumber == ScriptBaseClass.LINK_THIS)
- target = m_host;
- else if (linkNumber < 0)
- return;
- else if (linkNumber < 2)
- target = m_host.ParentGroup.RootPart;
- else
- target = m_host.ParentGroup.GetLinkNumPart(linkNumber);
- if (target == null)
- return;
- Vector3 old = target.StandOffset;
- target.StandOffset = v;
- if (!old.ApproxEquals(v))
- m_host.ParentGroup.HasGroupChanged = true;
- }
- public LSL_Vector osGetStandTarget()
- {
- return m_host.StandOffset;
- }
- public LSL_Vector osGetLinkStandTarget(LSL_Integer linkNumber)
- {
- if (linkNumber == ScriptBaseClass.LINK_THIS)
- return m_host.StandOffset;
- if (linkNumber < 0)
- return Vector3.Zero;
- if (linkNumber < 2)
- return m_host.ParentGroup.RootPart.StandOffset;
- SceneObjectPart target = m_host.ParentGroup.GetLinkNumPart(linkNumber);
- if (target == null)
- return Vector3.Zero;
- return target.StandOffset;
- }
- public LSL_Integer osClearObjectAnimations()
- {
- return m_host.ClearObjectAnimations();
- }
- public LSL_Integer osReplaceAgentEnvironment(LSL_Key agentkey, LSL_Integer transition, LSL_String daycycle)
- {
- m_host.AddScriptLPS(1);
- if(!string.IsNullOrEmpty(CheckThreatLevelTest(ThreatLevel.Moderate, "osReplaceAgentEnvironment")))
- return -2;
- if (!UUID.TryParse(agentkey, out UUID agentid))
- return -4;
- ScenePresence sp = World.GetScenePresence(agentid);
- if(sp == null || sp.IsChildAgent || sp.IsNPC || sp.IsInTransit)
- return -4;
- if(string.IsNullOrEmpty(daycycle) || daycycle == ScriptBaseClass.NULL_KEY)
- {
- sp.Environment = null;
- m_envModule.WindlightRefreshForced(sp, transition);
- return 1;
- }
- UUID envID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, daycycle);
- if (envID == UUID.Zero)
- return -3;
- AssetBase asset = World.AssetService.Get(envID.ToString());
- if(asset == null || asset.Type != (byte)AssetType.Settings)
- return -3;
- // cant use stupid broken asset flags for subtype
- try
- {
- OSD oenv = OSDParser.Deserialize(asset.Data);
- ViewerEnvironment VEnv = m_envModule.GetRegionEnvironment().Clone();
- if(!VEnv.CycleFromOSD(oenv))
- return -3;
- sp.Environment = VEnv;
- m_envModule.WindlightRefreshForced(sp, transition);
- }
- catch
- {
- sp.Environment = null;
- m_envModule.WindlightRefreshForced(sp, transition);
- return -5;
- }
- return 1;
- }
- public LSL_Integer osReplaceParcelEnvironment(LSL_Integer transition, LSL_String daycycle)
- {
- m_host.AddScriptLPS(1);
- if (!World.RegionInfo.EstateSettings.AllowEnvironmentOverride)
- return -1;
- ILandObject parcel = World.LandChannel.GetLandObject(m_host.GetWorldPosition().X, m_host.GetWorldPosition().Y);
- if (parcel == null)
- return -2;
- if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, parcel, (GroupPowers.AllowEnvironment), true))
- return -3;
- ViewerEnvironment VEnv;
- if (parcel.LandData.Environment == null)
- VEnv = m_envModule.GetRegionEnvironment().Clone();
- else
- VEnv = parcel.LandData.Environment;
- bool changed = false;
- if (!string.IsNullOrEmpty(daycycle) && (daycycle != ScriptBaseClass.NULL_KEY))
- {
- UUID envID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, daycycle);
- if (envID == UUID.Zero)
- return -4;
- AssetBase asset = World.AssetService.Get(envID.ToString());
- if (asset == null || asset.Type != (byte)AssetType.Settings)
- return -4;
- // cant use stupid broken asset flags for subtype
- try
- {
- OSD oenv = OSDParser.Deserialize(asset.Data);
- if (!VEnv.CycleFromOSD(oenv))
- return -5;
- changed = true;
- }
- catch
- {
- return -5;
- }
- }
- if (changed)
- {
- parcel.StoreEnvironment(VEnv);
- m_envModule.WindlightRefresh(transition, false);
- }
- return 1;
- }
- public LSL_Integer osReplaceRegionEnvironment(LSL_Integer transition, LSL_String daycycle,
- LSL_Float daylen, LSL_Float dayoffset,
- LSL_Float altitude1, LSL_Float altitude2, LSL_Float altitude3)
- {
- m_host.AddScriptLPS(1);
- if (!World.Permissions.CanIssueEstateCommand(m_host.OwnerID, true))
- return -3;
- ViewerEnvironment VEnv = m_envModule.GetRegionEnvironment().Clone();
- bool changed = false;
- if (!string.IsNullOrEmpty(daycycle) && (daycycle != ScriptBaseClass.NULL_KEY))
- {
- UUID envID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, daycycle);
- if (envID == UUID.Zero)
- return -4;
- AssetBase asset = World.AssetService.Get(envID.ToString());
- if (asset == null || asset.Type != (byte)AssetType.Settings)
- return -4;
- // cant use stupid broken asset flags for subtype
- try
- {
- OSD oenv = OSDParser.Deserialize(asset.Data);
- if (!VEnv.CycleFromOSD(oenv))
- return -5;
- changed = true;
- }
- catch
- {
- return -5;
- }
- }
- if (daylen >= 4 && daylen <= 24 * 7)
- {
- int ll = VEnv.DayLength;
- VEnv.DayLength = (int)(daylen * 3600f);
- changed |= ll != VEnv.DayLength;
- }
- if (dayoffset >= -11.5 && dayoffset <= 11.5)
- {
- int lo = VEnv.DayLength;
- if (dayoffset <= 0)
- dayoffset+= 24;
- VEnv.DayOffset = (int)(dayoffset * 3600f);
- changed |= lo != VEnv.DayOffset;
- }
- bool needSort = false;
- if (altitude1 > 0 && altitude1 < 4000 && VEnv.Altitudes[0] != (float)altitude1)
- {
- VEnv.Altitudes[0] = (float)altitude1;
- needSort = true;
- }
- if (altitude2 > 0 && altitude2 < 4000 && VEnv.Altitudes[1] != (float)altitude2)
- {
- VEnv.Altitudes[1] = (float)altitude2;
- needSort = true;
- }
- if (altitude3 > 0 && altitude2 < 4000 && VEnv.Altitudes[2] != (float)altitude3)
- {
- VEnv.Altitudes[2] = (float)altitude3;
- needSort = true;
- }
- if(needSort)
- {
- VEnv.SortAltitudes();
- changed = true;
- }
- if(changed)
- {
- m_envModule.StoreOnRegion(VEnv);
- m_envModule.WindlightRefresh(transition);
- }
- return 1;
- }
- public LSL_Integer osResetEnvironment(LSL_Integer parcelOrRegion, LSL_Integer transition)
- {
- m_host.AddScriptLPS(1);
- if (parcelOrRegion > 0)
- {
- if (!World.RegionInfo.EstateSettings.AllowEnvironmentOverride)
- return -1;
- ILandObject parcel = World.LandChannel.GetLandObject(m_host.GetWorldPosition().X, m_host.GetWorldPosition().Y);
- if (parcel == null)
- return -2;
- if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, parcel, (GroupPowers.AllowEnvironment), true))
- return -3;
- if (parcel.LandData.Environment == null)
- return 1;
- parcel.StoreEnvironment(null);
- m_envModule.WindlightRefresh(transition, false);
- return 1;
- }
- if (!World.Permissions.CanIssueEstateCommand(m_host.OwnerID, true))
- return -3;
- m_envModule.StoreOnRegion(null);
- m_envModule.WindlightRefresh(transition);
- return 1;
- }
- public void osParticleSystem(LSL_List rules)
- {
- m_host.AddScriptLPS(1);
- InitLSL();
- if (m_LSL_Api != null)
- m_LSL_Api.SetParticleSystem(m_host, rules, "osParticleSystem", true);
- }
- public void osLinkParticleSystem(LSL_Integer linknumber, LSL_List rules)
- {
- InitLSL();
- if (m_LSL_Api != null)
- {
- List<SceneObjectPart> parts = m_LSL_Api.GetLinkParts(linknumber);
- foreach (SceneObjectPart part in parts)
- {
- m_LSL_Api.SetParticleSystem(part, rules, "osLinkParticleSystem", true);
- }
- }
- }
- public LSL_Integer osNpcLookAt(LSL_Key npckey, LSL_Integer ltype, LSL_Key objkey, LSL_Vector offset)
- {
- if (World.GetNumberOfClients() == 0)
- return 0;
- if (ltype < 0 || ltype > ScriptBaseClass.NPCLOOKAT_CLEAR)
- return -1;
- if (!UUID.TryParse(npckey, out UUID npc))
- return -2;
- ScenePresence npcSP = World.GetScenePresence(npc);
- if((npcSP == null) || !npcSP.IsNPC)
- return -3;
- if (!UUID.TryParse(objkey, out UUID obj))
- return -4;
- if(obj != UUID.Zero)
- {
- ScenePresence objSP = World.GetScenePresence(obj);
- if(objSP == null)
- {
- SceneObjectPart objSOP = World.GetSceneObjectPart(obj);
- if(objSOP == null)
- return -5;
- }
- }
- byte[] data = new byte[57];
- npc.ToBytes(data, 0);
- obj.ToBytes(data, 16);
- Vector3d vd = new Vector3d(offset.x, offset.y, offset.z);
- vd.ToBytes(data, 32);
- data[56] = (byte)(int)ltype;
- OpenMetaverse.Packets.ViewerEffectPacket.EffectBlock effect = new OpenMetaverse.Packets.ViewerEffectPacket.EffectBlock();
- effect.AgentID = npc;
- effect.Color = new byte[4];
- effect.Duration = 0;
- effect.ID = UUID.Random();
- effect.Type = 14;
- effect.TypeData = data;
- OpenMetaverse.Packets.ViewerEffectPacket.EffectBlock[] effectblock = new OpenMetaverse.Packets.ViewerEffectPacket.EffectBlock[1];
- effectblock[0] = effect;
- World.ForEachScenePresence(
- sp =>
- {
- if(!sp.IsNPC && !sp.IsDeleted)
- {
- sp.ControllingClient.SendViewerEffect(effectblock);
- }
- });
- return 0;
- }
- }
- }
|