OSSL_Api.cs 213 KB

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