OSSL_Api.cs 217 KB

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